Maurizio4pastebin

Enable sound on C-Media CM6206 in FreeBSD

Apr 22nd, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.34 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # For instructions look at:
  3. # https://lists.freebsd.org/pipermail/freebsd-current/2015-April/055563.html
  4. #set -xu
  5. declare -r USB_REQ_SET_CONFIGURATION=0x09
  6. declare -r USB_DIR_OUT=0    # to device
  7. declare -r USB_DIR_IN=0x80  # to host
  8. declare -r USB_TYPE_CLASS=2#100000  # (0x01<<5)
  9. declare -r USB_RECIP_ENDPOINT=0x02
  10.  
  11. ##################################################################
  12. # Purpose:
  13. #       C-Media CM106/CM106+ have four 16-bit internal registers that
  14. #       are nicely documented in the device's data sheet.
  15. # Arguments:
  16. #       $1 -> USB device in the X.Y form
  17. #       $2 -> register number
  18. #       $3 -> register value
  19. # Return: usbconfig status
  20. ##################################################################
  21. snd_usb_cm106_write_int_reg(){
  22.     local usb_dev="$1"
  23.     local int_reg="$2"
  24.     local u16_value="$3"
  25.     local p1=$(($USB_DIR_OUT | $USB_TYPE_CLASS | $USB_RECIP_ENDPOINT))
  26.     local p2=$(($u16_value & 0xFF))
  27.     local p3=$((($u16_value >> 8) & 0xff))
  28.     usbconfig -d "$usb_dev" do_request "$p1" \
  29.         "$USB_REQ_SET_CONFIGURATION" 0 0 4 0x20 "$p2" "$p3" "$int_reg"
  30. }
  31.  
  32. ##################################################################
  33. # Purpose:
  34. #       Enable line-out driver mode, set headphone source to front
  35. #       channels, enable stereo mic.
  36. # Arguments:
  37. #       $1 -> USB device in the X.Y form
  38. # Return: usbconfig status
  39. ##################################################################
  40. snd_usb_cm106_boot_quirk() {
  41.     local usb_dev="$1"
  42.     snd_usb_cm106_write_int_reg "$usb_dev" 2 0x8004
  43. }
  44.  
  45. ##################################################################
  46. # Purpose:
  47. #       C-Media CM6206 is based on CM106 with two additional
  48. #       registers that are not documented in the data sheet.
  49. #       Values here are chosen based on sniffing USB traffic
  50. #       under Windows.
  51. # Arguments:
  52. #       $1 -> USB device in the <unit>.<addr> form
  53. # Return: usbconfig status
  54. ##################################################################
  55. snd_usb_cm6206_boot_quirk() {
  56.     local usb_dev="$1"
  57.     local val=(0x2004 0x3000 0xf800 0x143f 0x0000 0x3000)
  58.     for ((reg = 0 ; reg < ${#val[@]} ; reg++)); do
  59.         echo "Writing register $reg"
  60.         snd_usb_cm106_write_int_reg $usb_dev $reg ${val[$reg]}
  61.     done
  62. }
  63.  
  64. if [ $# -ne 1 ] ; then
  65.     echo "Usage: $0 X.Y"
  66.     echo "Argument:"
  67.     echo "X.Y: USB device in the <unit>.<addr> form"
  68.     exit 1
  69. fi
  70. snd_usb_cm6206_boot_quirk "$1"
  71. #set +xu
Add Comment
Please, Sign In to add comment