Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # For instructions look at:
- # https://lists.freebsd.org/pipermail/freebsd-current/2015-April/055563.html
- #set -xu
- declare -r USB_REQ_SET_CONFIGURATION=0x09
- declare -r USB_DIR_OUT=0 # to device
- declare -r USB_DIR_IN=0x80 # to host
- declare -r USB_TYPE_CLASS=2#100000 # (0x01<<5)
- declare -r USB_RECIP_ENDPOINT=0x02
- ##################################################################
- # Purpose:
- # C-Media CM106/CM106+ have four 16-bit internal registers that
- # are nicely documented in the device's data sheet.
- # Arguments:
- # $1 -> USB device in the X.Y form
- # $2 -> register number
- # $3 -> register value
- # Return: usbconfig status
- ##################################################################
- snd_usb_cm106_write_int_reg(){
- local usb_dev="$1"
- local int_reg="$2"
- local u16_value="$3"
- local p1=$(($USB_DIR_OUT | $USB_TYPE_CLASS | $USB_RECIP_ENDPOINT))
- local p2=$(($u16_value & 0xFF))
- local p3=$((($u16_value >> 8) & 0xff))
- usbconfig -d "$usb_dev" do_request "$p1" \
- "$USB_REQ_SET_CONFIGURATION" 0 0 4 0x20 "$p2" "$p3" "$int_reg"
- }
- ##################################################################
- # Purpose:
- # Enable line-out driver mode, set headphone source to front
- # channels, enable stereo mic.
- # Arguments:
- # $1 -> USB device in the X.Y form
- # Return: usbconfig status
- ##################################################################
- snd_usb_cm106_boot_quirk() {
- local usb_dev="$1"
- snd_usb_cm106_write_int_reg "$usb_dev" 2 0x8004
- }
- ##################################################################
- # Purpose:
- # C-Media CM6206 is based on CM106 with two additional
- # registers that are not documented in the data sheet.
- # Values here are chosen based on sniffing USB traffic
- # under Windows.
- # Arguments:
- # $1 -> USB device in the <unit>.<addr> form
- # Return: usbconfig status
- ##################################################################
- snd_usb_cm6206_boot_quirk() {
- local usb_dev="$1"
- local val=(0x2004 0x3000 0xf800 0x143f 0x0000 0x3000)
- for ((reg = 0 ; reg < ${#val[@]} ; reg++)); do
- echo "Writing register $reg"
- snd_usb_cm106_write_int_reg $usb_dev $reg ${val[$reg]}
- done
- }
- if [ $# -ne 1 ] ; then
- echo "Usage: $0 X.Y"
- echo "Argument:"
- echo "X.Y: USB device in the <unit>.<addr> form"
- exit 1
- fi
- snd_usb_cm6206_boot_quirk "$1"
- #set +xu
Add Comment
Please, Sign In to add comment