From owner-freebsd-current@FreeBSD.ORG Thu Apr 23 07:48:22 2015 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 20F3998C for ; Thu, 23 Apr 2015 07:48:22 +0000 (UTC) Received: from mail-ig0-x22e.google.com (mail-ig0-x22e.google.com [IPv6:2607:f8b0:4001:c05::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id DD4891761 for ; Thu, 23 Apr 2015 07:48:21 +0000 (UTC) Received: by iget9 with SMTP id t9so5685472ige.1 for ; Thu, 23 Apr 2015 00:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=sFzJ6KvT6/x3d+5VM94P1t5eBUniKQGunc//4fELKcM=; b=qnF3ZOklWDiy7p4YhgGS6KxhAGEWMRrB7XdvDpyU5a3VN0aXzukVGp6DsoWyUGFX1t qtfp25XK/FdwbK2TKLVJrEC7CTMOl7Ka6ib+pbbUXgxDsyAz7wTS89E/h/d3Mupay5ZB Pnps9UmQKrEH1OV3fnVdr46cJp/O6eu6zx2xyKg95P79rE/j5saJTtb/hK3xUt494CVr F/RLfPHzvsXwWVV+sXvyRtPb1/ow/p9TWbKda/Gwxq8CpX+bva8pDIG/F0+pTD5USyXB VXta1QZ0qp2KAsFSIis2M7eCwBUK+ocn4hcedzRUEvMitT6JyYkQwSi7JHSxZGFFuiUe SVIA== MIME-Version: 1.0 X-Received: by 10.107.138.96 with SMTP id m93mr2111672iod.14.1429775301236; Thu, 23 Apr 2015 00:48:21 -0700 (PDT) Received: by 10.36.51.129 with HTTP; Thu, 23 Apr 2015 00:48:21 -0700 (PDT) In-Reply-To: <55375060.2060705@selasky.org> References: <55375060.2060705@selasky.org> Date: Thu, 23 Apr 2015 09:48:21 +0200 Message-ID: Subject: Re: CM6206 USB Audio is mute. From: "Ranjan1018 ." <214748mv@gmail.com> To: Hans Petter Selasky Cc: FreeBSD CURRENT Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Apr 2015 07:48:22 -0000 2015-04-22 9:40 GMT+02:00 Hans Petter Selasky : > On 04/21/15 21:30, Ranjan1018 . wrote: > >> Connecting the USB cable the item is recognized: >> ugen0.5: at usbus0 >> uaudio0: > 5> >> on usbus0 >> uaudio0: Play: 48000 Hz, 4 ch, 16-bit S-LE PCM format, 2x8ms buffer. >> uaudio0: Play: 44100 Hz, 4 ch, 16-bit S-LE PCM format, 2x8ms buffer. >> uaudio0: Record: 48000 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer. >> uaudio0: Record: 44100 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer. >> uaudio0: No MIDI sequencer. >> pcm1: on uaudio0 >> uaudio0: HID volume keys found. >> >> > Hi, > > Did you check: > > mixer -f /dev/mixerX > > that sound volume is OK? > > Setting it as default unit >> # sysctl hw.snd.default_unit=1 >> and playing a song the interrupts count increase: >> > > Some volume knobs might be hidden. Try to get all: > > sysctl -a | grep pcm > > > But the output is mute. >> >> In Debian Linux it works: >> # lsusb >> Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub >> Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub >> Bus 002 Device 014: ID 0d8c:0102 C-Media Electronics, Inc. CM106 Like >> Sound >> Device >> # aplay -l >> **** List of PLAYBACK Hardware Devices **** >> card 1: Device [USB Sound Device], device 0: USB Audio [USB Audio] >> Subdevices: 0/1 >> Subdevice #0: subdevice #0 >> >> Looking at http://lxr.free-electrons.com/source/sound/usb/quirks.c I have >> found this code: >> /* >> 632 * C-Media CM106/CM106+ have four 16-bit internal registers that are >> nicely >> 633 * documented in the device's data sheet. >> 634 */ >> 635 static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int >> reg, >> u16 value) >> 636 { >> 637 u8 buf[4]; >> 638 buf[0] = 0x20; >> 639 buf[1] = value & 0xff; >> 640 buf[2] = (value >> 8) & 0xff; >> 641 buf[3] = reg; >> 642 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), >> USB_REQ_SET_CONFIGURATION, >> 643 USB_DIR_OUT | USB_TYPE_CLASS | >> USB_RECIP_ENDPOINT, >> 644 0, 0, &buf, 4); >> 645 } >> > > This USB control request can be issued from userspace like this (you need > to convert all variables below into constants): > > usbconfig -d X.Y do_request "USB_DIR_OUT | USB_TYPE_CLASS | > > USB_RECIP_ENDPOINT" "USB_REQ_SET_CONFIGURATION" 0 0 4 0x20 "(value & > 0xff)" "(value >> 8) & 0xff" "reg" > > Such a command can easily be added like a devd script to run automatically > during device attach. > > > 646 >> 647 static int snd_usb_cm106_boot_quirk(struct usb_device *dev) >> 648 { >> 649 /* >> 650 * Enable line-out driver mode, set headphone source to front >> 651 * channels, enable stereo mic. >> 652 */ >> 653 return snd_usb_cm106_write_int_reg(dev, 2, 0x8004); >> 654 } >> 655 >> 656 /* >> 657 * C-Media CM6206 is based on CM106 with two additional >> 658 * registers that are not documented in the data sheet. >> 659 * Values here are chosen based on sniffing USB traffic >> 660 * under Windows. >> 661 */ >> 662 static int snd_usb_cm6206_boot_quirk(struct usb_device *dev) >> 663 { >> 664 int err = 0, reg; >> 665 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000}; >> 666 >> 667 for (reg = 0; reg < ARRAY_SIZE(val); reg++) { >> 668 err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]); >> 669 if (err < 0) >> 670 return err; >> 671 } >> 672 >> 673 return err; >> 674 } >> 675 >> >> How can I test this code in FreeBSD ? >> >> > See answer above. > > Please also use -stable or -current when testing. > > --HPS > > Thank you Hans, it works !!! This is only the first step in supporting the C-Media CM6206 in FreeBSD, but works. I have converted the C code in a bash script: snd-cm6206.sh available at http://pastebin.com/dLtJAqE7 Instructions: - Connect the USB cable of the CM6206 - With the command # dmesg | tail look at the the line : ugenX.Y: at usbus and the line : pcmZ: on uaudio - Run the script: # snd-cm6206.sh X.Y - Run the command: # sysctl hw.snd.default_unit=Z - Reduce the volume ;-) : # mixer -f /dev/mixerZ 10 On my laptop running 11-CURRENT, after connecting the CM6206, I have : # dmesg | tail pcm3: detached ugen1.4: at usbus1 uaudio0: on usbus1 uaudio0: Play: 48000 Hz, 4 ch, 16-bit S-LE PCM format, 2x8ms buffer. uaudio0: Play: 44100 Hz, 4 ch, 16-bit S-LE PCM format, 2x8ms buffer. uaudio0: Record: 48000 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer. uaudio0: Record: 44100 Hz, 2 ch, 16-bit S-LE PCM format, 2x8ms buffer. uaudio0: No MIDI sequencer. pcm3: on uaudio0 uaudio0: HID volume keys found. # snd-cm6206.sh 1.4 Writing register 0 REQUEST = Writing register 1 REQUEST = Writing register 2 REQUEST = Writing register 3 REQUEST = Writing register 4 REQUEST = Writing register 5 REQUEST = # sysctl hw.snd.default_unit=3 hw.snd.default_unit: 0 -> 3 # mixer -f /dev/mixer3 10 Setting the mixer vol from 75:75 to 10:10. Regards, Maurizio