From 843fae1eb6de16d2f7a7ad47dd3f7c23136938ec Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Sun, 12 Apr 2015 16:28:12 -0400 Subject: [PATCH] Reorganized files, deleted Arch specific files, added Makefile for tarball --- Makefile | 15 ++ PKGBUILD | 31 ---- README.md | 2 +- init-headphone.install | 11 -- src/Makefile | 7 + src/init-headphone | 149 ++++++++++++++++++ src/init-headphone.modules | 5 + .../init-headphone.service | 0 8 files changed, 177 insertions(+), 43 deletions(-) create mode 100644 Makefile delete mode 100644 PKGBUILD delete mode 100644 init-headphone.install create mode 100644 src/Makefile create mode 100644 src/init-headphone create mode 100644 src/init-headphone.modules rename init-headphone.service => src/init-headphone.service (100%) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ed57d0c --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +PROG=init-headphone +VERSION=0.2.0 +SRCDIR=src +TARBALL=${PROG}-${VERSION}.tar.gz + +all: pkg + +pkg: ${TARBALL} + +${TARBALL}: ${SRCDIR}/* + tar -czf $@ $^ + +clean: + rm -rf ${TARBALL} + diff --git a/PKGBUILD b/PKGBUILD deleted file mode 100644 index 77e07d8..0000000 --- a/PKGBUILD +++ /dev/null @@ -1,31 +0,0 @@ -# Maintainer: Ettore Chimenti -pkgname="init-headphone" -pkgver="0.2.0" -pkgrel=3 -epoch= -pkgdesc="Re-enables headphone jack after sleep/suspend resume on Clevo W230SS" -arch=("any") -url="https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904/" -license=('GPL') -depends=("dmidecode" "python2-smbus" "python") -install=init-headphone.install -source=("https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904/+attachment/4361090/+files/${pkgname}_${pkgver}_all.deb" - "init-headphone.service" - "init-headphone.install") -noextract=() -md5sums=('37c830340c4ca077271a04b4436ea8fc' - 'ad3ad6f4c9157035fd7a9dd2e82184c2' - '81b2f5e44cd18753e64a084eaff563b5') -validpgpkeys=() - -package() { - tar -xf data.tar.xz - - install -Dm 755 usr/sbin/init-headphone $pkgdir/usr/bin/init-headphone - - install -Dm 755 {,$pkgdir/}etc/modules-load.d/init-headphone.conf - - install -Dm 755 init-headphone.service $pkgdir/usr/lib/systemd/system/init-headphone.service -} - - diff --git a/README.md b/README.md index 0b393ac..b680dfa 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # init-headphone -PKGBUILD for init-headphone +Fedora package for init-headphone Re-enables headphone jack after sleep/suspend resume on Clevo W230SS diff --git a/init-headphone.install b/init-headphone.install deleted file mode 100644 index 35dd243..0000000 --- a/init-headphone.install +++ /dev/null @@ -1,11 +0,0 @@ -post_install() { - echo ">>> Please enable the service unit via 'systemctl enable init-headphone.service' " - echo ">>> Also add 'acpi_enforce_resources=lax' to kernel bootargs and reboot" -} -post_upgrade() { - post_install -} -post_remove() { - systemctl disable init-headphone.service -} - diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..654969b --- /dev/null +++ b/src/Makefile @@ -0,0 +1,7 @@ +all: + +install: + install -Dm 755 init-headphone ${DESTDIR}/usr/sbin/init-headphone + install -Dm 755 init-headphone.modules ${DESTDIR}/etc/sysconfig/modules/init-headphone.modules + install -Dm 755 init-headphone.service ${DESTDIR}/usr/lib/systemd/system/init-headphone.service + diff --git a/src/init-headphone b/src/init-headphone new file mode 100644 index 0000000..9af63f1 --- /dev/null +++ b/src/init-headphone @@ -0,0 +1,149 @@ +#!/usr/bin/env python2 + +from __future__ import print_function +import subprocess +import os +import sys + +SUPPORTED_SYSTEM_PRODUCT_NAMES = ["W230SS"] +SUPPORTED_I2C_BUS_NAMES = ["SMBus I801 adapter at f040"] +I2C_CLASS_PATH = "/sys/class/i2c-dev" +CMDLINE_PATH = "/proc/cmdline" +KERNEL_PARAMETER = "acpi_enforce_resources=lax" +MODULES_PATH = "/proc/modules" +DEVICE_ADDRESS = 0x73 +DATA = [ +# CMD Data0 + [0x0A, 0x41], + [0x04, 0xEE], + [0x09, 0xFF], + [0x00, 0x86], + [0x04, 0xEE], + [0x05, 0x03], + [0x07, 0x40], + [0x08, 0x84], + [0x09, 0xFF], + [0x00, 0x82], +] + +def get_system_product_name(): + try: + return subprocess.check_output(["dmidecode", "-s", "system-product-name"] + ).strip() + except OSError: + print("Error: dmidecode is not installed", file=sys.stderr) + return False + except subprocess.CalledProcessError: + print("Error: dmidecode returned non-zero exit status", file=sys.stderr) + return False + +def get_i2c_busses(): + busses = [] + try: + i2c_directories = os.listdir(I2C_CLASS_PATH) + except OSError: + print("Error: Can't list directory I2C_CLASS_PATH (%s)" % I2C_CLASS_PATH, + file=sys.stderr) + return False + for i2c_dev in i2c_directories: + with open(os.path.join(I2C_CLASS_PATH, i2c_dev, "name")) as name_file: + i2c_dev_name = name_file.read().strip() + with open(os.path.join(I2C_CLASS_PATH, i2c_dev, "dev")) as dev_file: + i2c_dev_major, i2c_dev_minor = dev_file.read().strip().split(":") + i2c_dev_major = int(i2c_dev_major) + i2c_dev_minor = int(i2c_dev_minor) + busses.append((i2c_dev_name, i2c_dev_minor)) + return busses + +def check_root(): + if os.geteuid() != 0: + print("Warning: This program needs root privileges", file=sys.stderr) + return True + +def check_cmdline(): + try: + cmdline_file = open(CMDLINE_PATH, "r") + except IOError: + print("Warning: Can't open file CMDLINE_PATH (%s)" % CMDLINE_PATH, + file=sys.stderr) + return True + cmdline_parameters = cmdline_file.read().split() + cmdline_file.close() + if KERNEL_PARAMETER not in cmdline_parameters: + print("Warning: Kernel parameter %s is missing" % KERNEL_PARAMETER, + file=sys.stderr) + return True + +def check_modules(): + try: + modules_file = open(MODULES_PATH, "r") + except IOError: + print("Warning: Can't open file MODULES_PATH (%s)" % MODULES_PATH, + file=sys.stderr) + return True + module_i2c_dev_found = False + module_i2c_i801_found = False + for line in modules_file.readlines(): + if "i2c_dev" == line.split()[0]: + module_i2c_dev_found = True + if "i2c_i801" == line.split()[0]: + module_i2c_i801_found = True + if not module_i2c_dev_found: + print("Warning: Module i2c_dev is not loaded", file=sys.stderr) + if not module_i2c_i801_found: + print("Warning: Module i2c_i801 is not loaded", file=sys.stderr) + return True + +def init_headphone(): + try: + import smbus + except ImportError: + print("Error: Python module smbus not installed", file=sys.stderr) + return False + if check_root() == False: + return False + system_product_name = get_system_product_name() + if system_product_name == False: + return False + if system_product_name not in SUPPORTED_SYSTEM_PRODUCT_NAMES: + print("Error: Unsupported system: %s" % system_product_name, + file=sys.stderr) + print("Supported systems:\n%s" % "".join(map(lambda e: " %s\n" % e, + SUPPORTED_SYSTEM_PRODUCT_NAMES)), + end="") + return False + if check_cmdline() == False: + return False + if check_modules() == False: + return False + i2c_busses = get_i2c_busses() + if i2c_busses == False: + return False + selected_i2c_bus_minor = None + selected_i2c_bus_name = None + for i2c_bus_name, i2c_bus_minor in i2c_busses: + if i2c_bus_name in SUPPORTED_I2C_BUS_NAMES: + selected_i2c_bus_minor = i2c_bus_minor + selected_i2c_bus_name = i2c_bus_name + if selected_i2c_bus_minor == None: + print("Error: Can't find i2c bus", file=sys.stderr) + print("Found:\n%s" % "".join(map(lambda e: " %s\n" % e[0], + i2c_busses)), end="") + print("Looked for:\n%s" % "".join(map(lambda e: " %s\n" % e, + SUPPORTED_I2C_BUS_NAMES)), end="") + return False + + try: + i2c_bus = smbus.SMBus(selected_i2c_bus_minor) + except IOError: + print("Error: Can't access i2c bus (%s)" % selected_i2c_bus_name, + file=sys.stderr) + return False + for device_cmd, device_data in DATA: + i2c_bus.write_byte_data(DEVICE_ADDRESS, device_cmd, device_data) + i2c_bus.close() + return True + +if __name__ == "__main__": + success = init_headphone() + exit(0 if success else 1) diff --git a/src/init-headphone.modules b/src/init-headphone.modules new file mode 100644 index 0000000..7227433 --- /dev/null +++ b/src/init-headphone.modules @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ ! -d /sys/class/i2c-dev ] ; then + exec /sbin/modprobe i2c_dev >/dev/null 2>&1 +fi diff --git a/init-headphone.service b/src/init-headphone.service similarity index 100% rename from init-headphone.service rename to src/init-headphone.service