I should add the solution:

I found a workaround on this site
https://bbs.archlinux.org/viewtopic.php?id=143744

It basically consists of a patch, installed as a service. I hope the
maintainers can use this to implement it into the main build so users
can achieve full sound support on Macbook 5,2 without the need to
manually add the patch.

Steps I did to fix the issue of no sound on headphones (following the
steps explained by helmuthdu in Post #7):

1. create a new service 
                        # nano /etc/systemd/system/alsa-fix.service
                        
with this input

[Unit]
Description=Fix headphone volume issue on MacBook5,2

[Service]
Type=oneshot
ExecStart=/bin/sh -c "python2 /etc/alsa_fix.py"

[Install]
WantedBy=multi-user.target

2. save the script from pezcurrel e.g. like /etc/alsa_fix.py

#!/usr/bin/env python2

import os
import struct
from fcntl import ioctl

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

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

def set(nid, verb, param):
  verb = (nid << 24) | (verb << 8) | param
  res = ioctl(FD, IOCTL_VERB_WRITE, struct.pack('II', verb, 0))

FD = os.open("/dev/snd/hwC0D0", os.O_RDONLY)
info = struct.pack('Ii64s80si64s', 0, 0, '', '', 0, '')
res = ioctl(FD, IOCTL_INFO, info)
name = struct.unpack('Ii64s80si64s', res)[3]
if not name.startswith('HDA Codec'):
  raise IOError, "unknown HDA hwdep interface"
res = ioctl(FD, IOCTL_PVERSION, struct.pack('I', 0))
version = struct.unpack('I', res)
if version < 0x00010000:        # 1.0.0
  raise IOError, "unknown HDA hwdep version"

# initialization sequence starts here...

set(0x15, 0x707,   0xc1) # 0x150707c1 (SET_PIN_WIDGET_CONTROL)

os.close(FD)

3. and the last thing (rebooted after this step for the changes to take
effect): 
                                # systemctl enable alsa-fix.service
#!/usr/bin/env python2

import os
import struct
from fcntl import ioctl

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

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

def set(nid, verb, param):
  verb = (nid << 24) | (verb << 8) | param
  res = ioctl(FD, IOCTL_VERB_WRITE, struct.pack('II', verb, 0))

FD = os.open("/dev/snd/hwC0D0", os.O_RDONLY)
info = struct.pack('Ii64s80si64s', 0, 0, '', '', 0, '')
res = ioctl(FD, IOCTL_INFO, info)
name = struct.unpack('Ii64s80si64s', res)[3]
if not name.startswith('HDA Codec'):
  raise IOError, "unknown HDA hwdep interface"
res = ioctl(FD, IOCTL_PVERSION, struct.pack('I', 0))
version = struct.unpack('I', res)
if version < 0x00010000:        # 1.0.0
  raise IOError, "unknown HDA hwdep version"

# initialization sequence starts here...

set(0x15, 0x707,   0xc1) # 0x150707c1 (SET_PIN_WIDGET_CONTROL)

os.close(FD)
[Unit]
Description=Fix headphone volume issue on MacBook5,2

[Service]
Type=oneshot
ExecStart=/bin/sh -c "python2 /etc/alsa_fix.py"

[Install]
WantedBy=multi-user.target

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to