For my system, I got kanyo's method to work automatically on every boot
by reverse engineering the ioctl calls that come from HDA Analyzer when
you click on the widgets to adjust the settings.  Here is my pyhon
script:

#!/usr/bin/python
# Matt Damiano's script based on hda-analyzer
# to automatically enable onboard mic on Lenovo G560
#

import os
import struct
from fcntl import ioctl

def main():
    fd = get_fd_for_device(0, 1)
    modify_settings(fd)

def __ioctl_val(val):
    # copied directly from hda_codec.py
    # workaround for OverFlow bug in python 2.4
    if val & 0x80000000:
        return -((val^0xffffffff)+1)
    return val

IOCTL_INFO       = __ioctl_val(0x80dc4801)
IOCTL_VERB_WRITE = __ioctl_val(0xc0084811)

def modify_settings(fd):
    # set active connection for Node [0x14] AUD_IN to Audio Selector [0x18] 
    set_active_connection_verb = 336003329
    unmute_val2_verb = 335765760
    unmute_val3_verb = 335761664
    boost_val2_volume_verb = 335765840
    boost_val3_volume_verb = 335761744
    
    ioctl(fd, IOCTL_VERB_WRITE, struct.pack('II', set_active_connection_verb, 
0))
    ioctl(fd, IOCTL_VERB_WRITE, struct.pack('II', unmute_val2_verb, 0))
    ioctl(fd, IOCTL_VERB_WRITE, struct.pack('II', unmute_val3_verb, 0))
    ioctl(fd, IOCTL_VERB_WRITE, struct.pack('II', boost_val2_volume_verb, 0))
    ioctl(fd, IOCTL_VERB_WRITE, struct.pack('II', boost_val3_volume_verb, 0))
    
    return

def get_fd_for_device(card, device):
    fd = os.open("/dev/snd/hwC%sD%s" % (card, device), os.O_RDWR)
    
    ## just to prove his is the right file descriptor...
    info   = struct.pack('Ii64s80si64s', 0, 0, '', '', 0, '')
    result = ioctl(fd, IOCTL_INFO, info)
    name   = struct.unpack('Ii64s80si64s', result)[3]
    print name
    
    return fd

if __name__ == "__main__":
    main()

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/590756

Title:
  Lenovo G560 autoswitch headphone + mic not working

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to