Rockchip Developer Guide Linux4.4 USB Gadget UAC CN

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 35

RK3399 RK3368 RK3366 RK3328 RK3288 RK312X RK3188 RK30XX RK3308
RK3326 PX30 Linux4.4
2019-03-13 V1.0
Linux4.4 USB Gadget UAC
1.0
wulf@rock-chips.com
2019-03-13
Rockchip Linux4.4 USB Gadget UAC USB Audio Class Rockchip
UAC1 USB Audio Class specification 1.0 UAC2 USB Audio Class specification
2.0 Rockchip UAC1 Legacy
Audio Source 15
UAC
/ HID SDK
HID
Kernel/Documentation/usb/gadget-testing.txt 6. HID function
Kernel/Documentation/ABI/testing/configfs-usb-gadget-hid
Universal Serial Bus Audio Device Class Specification for Basic Audio Devices 8 HID Support in Basic
Audio Devices
Linux4.4 USB Gadget UAC
1 Kernel UAC CONFIG
1.1 Related Kernel Commits
1.2 Related CONFIGs
1.3 Related Documents
2 UAC1 Usage and Test
2.1 UAC1 Usage
2.2 UAC1 Test
2.2.1 UAC1 Test on Windows
2.2.2 UAC1 Test on Ubuntu
3 UAC2 Usage and Test
3.1 UAC2 Usage
3.2 UAC2 Test
3.2.1 UAC2 Test on Windows
3.2.2 UAC2 Test on Ubuntu
4 UAC1 Legacy Usage and Test
4.1 UAC1 Legacy Usage
4.2 UAC1 Legacy Test
5 Audio Source Usage and Test
5.1 Audio Source Usage
5.2 Audio Source Test
6 UAC1 Legacy and Audio Source Composite Usage and Test
6.1 UAC1 Legacy and Audio Source Composite Usage
6.2 UAC1 Legacy and Audio Source Composite Test
7 Composite with ADB
8 Reference Documentation
9 Appendix A UAC1 Device Descriptor
10 Appendix B UAC2 Device Descriptor
1 Kernel UAC CONFIG
1.1 Related Kernel Commits
Kernel-4.4 UAC1/UAC2
Rockchip Redmine
[1] Kernel 4.4 USB Gadget UAC1/UAC2
: Kernel-4.4 USB Gadget UAC1/UAC2 :
UAC1
UAC2 Windows
5e962a0 usb: gadget: f_uac2: fix some issues for Windows recognized
14e0a40 UPSTREAM: usb: gadget: f_uac2: disable IN/OUT ep if unused
a90af74 UPSTREAM: usb: gadget: u_audio: protect stream runtime fields with stream spinlock
7335245 UPSTREAM: usb: gadget: u_audio: remove cached period bytes value
deb045e UPSTREAM: usb: gadget: u_audio: remove caching of stream buffer parameters
6ec0a4d UPSTREAM: usb: gadget: u_audio: update hw_ptr in iso_complete after data copied
[2] Kernel USB Gadget UAC1
:
USB Gadget UAC1 PC USB USB
PC USB UAC1
:
1.2 Related CONFIGs
CONFIG_USB_CONFIGFS_F_UAC1 (enable UAC1 Function )
CONFIG_USB_CONFIGFS_F_UAC2 (enable UAC2 Function )
CONFIG_USB_CONFIGFS_F_UAC1_LEGACY (enable UAC1 Legacy Function )
CONFIG_USB_CONFIGFS_F_ACC Audio Source depends on it
CONFIG_USB_CONFIGFS_F_AUDIO_SRC (enable Audio Source Function)
1.3 Related Documents
Documentation/usb/gadget_configfs.txt
Documentation/usb/gadget-testing.txt
Documentation/ABI/testing/configfs-usb-gadget-uac1
Documentation/ABI/testing/configfs-usb-gadget-uac1_legacy
Documentation/ABI/testing/configfs-usb-gadget-uac2
2 UAC1 Usage and Test
2.1 UAC1 Usage
USB Audio Class 1 standard (1998)
f81ce6a UPSTREAM: usb: gadget: u_audio: fix pcm/card naming in g_audio_setup()
bbd7715 UPSTREAM: usb: gadget: f_uac2: fix error handling in afunc_bind (again)
1adbd21 UPSTREAM: usb: gadget: make snd_pcm_hardware const
de6e281 UPSTREAM: usb: gadget: f_uac2: constify snd_pcm_ops structures
0106bd0 UPSTREAM: usb: gadget: f_uac2: endianness fixes.
98492ac UPSTREAM: usb: gadget: f_uac1: endianness fixes.
45e29d4 UPSTREAM: usb: gadget: add f_uac1 variant based on a new u_audio api
55f51fc UPSTREAM: usb: gadget: function: make current f_uac1 implementation legacy
ef10d9e UPSTREAM: usb: gadget: f_uac2: split out audio core
dc16803 UPSTREAM: usb: gadget: f_uac2: remove platform driver/device creation
7d1ddce UPSTREAM: usb: gadget: f_uac2: calculate wMaxPacketSize before endpoint match
4f76843 UPSTREAM: usb: gadget: uac2: add req_number as parameter
2b9c1a8 UPSTREAM: usb: gadget: f_uac2: improve error handling
70f4537 UPSTREAM: usb: gadget: uac2: Drop unused device qualifier descriptor
cafb671 UPSTREAM: usb: dwc2: gadget: Disable enabled HW endpoint in dwc2_hsotg_ep_disable
9b54359 UPSTREAM: usb: dwc2: gadget: Correct dwc2_hsotg_ep_stop_xfr() function
This standard allows for 24 bits/96 kHz max.
The standard itself doesn't impose any limitation on sample rate.
Class 1 is tied to USB 1 Full Speed = 12 MHz
Every millisecond a package is send. Maximum package size is 1024 bytes. 2 channel x 24 bit x 96000 Hz
sample rate= 4608000 bits/s or 576 Byte/ms This fits in the 1024 byte limit. Any higher popular sample
rate e.g. 176 kHz needs 1056 bytes so in excess of the maximum package size.
All operating systems (Win, OSX, and Linux) support USB Audio Class 1 natively. This means you don’t
need to install drivers, it is plug&play. All support 2 channel audio with 24 bit words and 96 kHz sample
rate
The Well-Tempered Computer (An introduction to computer audio) - USB
Note
USB Audio 1.0 Specification USB 2.0 core Specification USB Audio 1.0 Specification
(High Speed) Audio 1.0
isochronous endpoint descriptor bInterval=4
Rockchip UAC1 USB Audio Class specification 1.0
UAC1 bInterval=4
High Speed
playback capture 48 KHz
playback capture 2 Channels
playback capture 16 bits
UAC1
CONFIG_USB_CONFIGFS_F_UAC1=y defconfig
3308 EVB
UAC1
mount -t configfs none /sys/kernel/config
mkdir /sys/kernel/config/usb_gadget/rockchip -m 0770
echo 0x2207 > /sys/kernel/config/usb_gadget/rockchip/idVendor
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0100 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
mkdir /sys/kernel/config/usb_gadget/rockchip/strings/0x409 -m 0770
echo "0123456789ABCDEF" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/serialnumber
echo "rockchip" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/manufacturer
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1 -m 0770
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409 -m 0770
echo 500 > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/MaxPower
echo "uac1" >
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
3308 ADB
UAC1 USB ADB UAC1
Note
“idProduct ” USB Function idProduct
“UDC” USB /sys/class/udc/
Windows Windows
USB PC PC USB Audio 2-1 Windows-USB-Audio-Class1
2-2 Ubuntu-USB-Audio-Class1-Output 2-3 Ubuntu-USB-Audio-Class1-Input
2-1 Windows-USB-Audio-Class1
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/uac1.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/uac1.gs0
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/uac1.gs0
echo ff400000.usb > /sys/kernel/config/usb_gadget/rockchip/UDC
rm -rf /sys/kernel/config/usb_gadget/rockchip/configs/b.1/ffs.adb
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/uac1.gs0
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0100 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
echo "uac1" >
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
cd /sys/kernel/config/usb_gadget/rockchip/configs/b.1
ln -s ../../functions/uac1.gs0
echo ff400000.usb > ../../UDC
2-2 Ubuntu-USB-Audio-Class1-Output
2-3 Ubuntu-USB-Audio-Class1-Input
3308 USB UAC1
UAC1
UAC
UAC1
UAC1 card2 UAC1Gadget playback - pcmC2D0p capture
- pcmC2D0c
dwc2 ff400000.usb: new device is high-speed
dwc2 ff400000.usb: new address 19
android_work: sent uevent USB_STATE=CONNECTED
configfs-gadget gadget: high-speed config #1: b
android_work: sent uevent USB_STATE=CONFIGURED
# ls -lh /sys/kernel/config/usb_gadget/rockchip/functions/uac1.gs0
-rw-r--r-- 1 root root 4.0K Dec 31 19:11 c_chmask
-rw-r--r-- 1 root root 4.0K Dec 31 19:11 c_srate
-rw-r--r-- 1 root root 4.0K Dec 31 19:11 c_ssize
-rw-r--r-- 1 root root 4.0K Dec 31 19:11 p_chmask
-rw-r--r-- 1 root root 4.0K Dec 31 19:11 p_srate
-rw-r--r-- 1 root root 4.0K Dec 31 19:11 p_ssize
-rw-r--r-- 1 root root 4.0K Dec 31 19:11 req_number
c_chmask - capture channel mask 3
c_srate - capture sampling rate 48000
c_ssize - capture sample size (bytes) 2
p_chmask - playback channel mask 3
p_srate - playback sampling rate 48000
p_ssize - playback sample size (bytes) 2
req_number - the number of pre-allocated request for both capture and playback
2
# cat /proc/asound/cards
0 [rockchiprk3308v]: rockchip_rk3308 - rockchip,rk3308-vad
rockchip,rk3308-vad
1 [rockchiprk3308p]: rockchip_rk3308 - rockchip,rk3308-pcm
rockchip,rk3308-pcm
2 [UAC1Gadget ]: UAC1_Gadget - UAC1_Gadget
UAC1_Gadget 0
7 [Loopback ]: Loopback - Loopback
Loopback 1
# ls -lh /proc/asound/card2
-r--r--r-- 1 root root 0 Dec 31 19:14 id
dr-xr-xr-x 3 root root 0 Dec 31 19:14 pcm0c
dr-xr-xr-x 3 root root 0 Dec 31 19:14 pcm0p
# ls /dev/snd/
controlC0 controlC7 pcmC1D0c pcmC2D0p pcmC7D1c
controlC1 pcmC0D0c pcmC1D0p pcmC7D0c pcmC7D1p
controlC2 pcmC0D0p pcmC2D0c pcmC7D0p timer
2.2 UAC1 Test
2.2.1 UAC1 Test on Windows
Windows 2-4 Windows-Audio-Setting USB-Audio
2-4 Windows-Audio-Setting
Windows UAC1
3308 UAC1
Card2 USB Audio Card0
Windows PC 3308
Windows UAC1
ADB push arecord
48KHz 2 channels 16 bits
3308 arecord test.wav
arecord -f dat -t wav -r 48000 -c 2 -D hw:2,0 /tmp/test.wav
test.wav UAC1
aplay /tmp/test.wav -c 2 -r 48000 -D hw:2,0
PC Windows “Voice Recorder 2-5 Windows-
Voice-Recorder
2-5 Windows-Voice-Recorder
Windows
” --> “ ” --> " " --> “ ” --> " "
2-6 Windows-Capture-Listen-1 2-7 Windows-Capture-Listen-2
arecord -f dat -t wav -r 48000 -c 2 -D hw:2,0 | aplay -f dat -r 48000 -c 2 -D hw:0,0
2-6 Windows-Capture-Listen-1
2-6 Windows-Capture-Listen-2
2.2.2 UAC1 Test on Ubuntu
Ubuntu 2-7 Ubuntu-Audio-Setting-Output 2-8 Ubuntu-Audio-Setting-Input
USB-Audio
2-7 Ubuntu-Audio-Setting-Output
2-8 Ubuntu-Audio-Setting-Input
Ubuntu UAC1
3308 UAC1
arecord -f dat -t wav -r 48000 -c 2 -D hw:2,0 | aplay -f dat -r 48000 -c 2 -D hw:0,0
Card2 USB Audio Card0
Ubuntu PC 3308
Ubuntu UAC1
ADB push arecord
48KHz 2 channels 16 bits
3308 arecord test.wav
arecord -f dat -t wav -r 48000 -c 2 -D hw:2,0 /tmp/test.wav
test.wav UAC1
aplay /tmp/test.wav -c 2 -r 48000 -D hw:2,0
Ubuntu “audacity
audacity
sudo apt install audacity
audacity 2-9
2-9 Ubuntu-audacity
3 UAC2 Usage and Test
3.1 UAC2 Usage
USB Audio Class 2 standard (2009)
USB Audio Class 2 additionally supports 32 bit and all common sample rates > 96 kHz Class 2 uses High
Speed (480 MHz). This requires USB 2 or 3. As the data rate of High Speed is 40 X Full speed, recording a
60 channel using 24 bits at 96 kHz (132 Mbit/s) is not a problem.
Using High Speed USB for playback there are no limits in resolution.
It is downwards compatible with class 1.
From mid-2010 on USB audio class 2 drivers are available in OSX 10.6.4 and Linux. Both support sample
rates up to 384 kHz.
Microsoft simply didn’t support UAC2.
In April 2017, an update of Win10 finally brought native mode drivers.
If you use older versions of Win, you still need a third party driver.
Note
Windows 10 1703 Windows UAC 2.0
Windows Linux Linux Android
Windows Windows
Rockchip UAC2 USB Audio Class specification 2.0
High Speed
playback 48K Hz capture 64 KHz
playback capture 2 Channels
playback capture 16 bits
UAC2
CONFIG_USB_CONFIGFS_F_UAC2=y defconfig
3308 EVB
UAC2
mount -t configfs none /sys/kernel/config
mkdir /sys/kernel/config/usb_gadget/rockchip -m 0770
echo 0x2207 > /sys/kernel/config/usb_gadget/rockchip/idVendor
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0200 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
mkdir /sys/kernel/config/usb_gadget/rockchip/strings/0x409 -m 0770
echo "0123456789ABCDEF" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/serialnumber
echo "rockchip" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/manufacturer
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1 -m 0770
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409 -m 0770
echo 500 > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/MaxPower
echo "uac2" > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/uac2.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/uac2.gs0
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/uac2.gs0
echo ff400000.usb > /sys/kernel/config/usb_gadget/rockchip/UDC
3308 ADB
UAC2 USB ADB UAC2
rm -rf /sys/kernel/config/usb_gadget/rockchip/configs/b.1/ffs.adb
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/uac2.gs0
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0200 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
echo "uac2" > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
cd /sys/kernel/config/usb_gadget/rockchip/configs/b.1
ln -s ../../functions/uac2.gs0
echo ff400000.usb > ../../UDC
Note
“idProduct ” USB Function idProduct
“UDC” USB /sys/class/udc/
Windows Windows
USB PC PC USB Audio 3-1 Windows-USB-Audio-Class2
3-2 Ubuntu-USB-Audio-Class2-Output 3-3 Ubuntu-USB-Audio-Class2-Input
3-1 Windows-USB-Audio-Class2
3-2 Ubuntu-USB-Audio-Class2-Output
3-3 Ubuntu-USB-Audio-Class2-Input
3308 USB UAC2
dwc2 ff400000.usb: new device is high-speed
dwc2 ff400000.usb: new address 21
android_work: sent uevent USB_STATE=CONNECTED
configfs-gadget gadget: high-speed config #1: b
android_work: sent uevent USB_STATE=CONFIGURED
UAC2
UAC
c_srate 48KHz
echo 48000 > /sys/kernel/config/usb_gadget/rockchip/functions/uac2.gs0/c_srate
# ls -lh /sys/kernel/config/usb_gadget/rockchip/functions/uac2.gs0
-rw-r--r-- 1 root root 4.0K Dec 31 19:01 c_chmask
-rw-r--r-- 1 root root 4.0K Dec 31 19:01 c_srate
-rw-r--r-- 1 root root 4.0K Dec 31 19:01 c_ssize
-rw-r--r-- 1 root root 4.0K Dec 31 19:01 p_chmask
-rw-r--r-- 1 root root 4.0K Dec 31 19:01 p_srate
-rw-r--r-- 1 root root 4.0K Dec 31 19:01 p_ssize
-rw-r--r-- 1 root root 4.0K Dec 31 19:01 req_number
c_chmask - capture channel mask 3
c_srate - capture sampling rate 64000
c_ssize - capture sample size (bytes) 2
p_chmask - playback channel mask 3
p_srate - playback sampling rate 48000
p_ssize - playback sample size (bytes) 2
req_number - the number of pre-allocated request for both capture and playback
2
UAC2
UAC2 card2 UAC2Gadget playback - pcmC2D0p capture
- pcmC2D0c
# cat /proc/asound/cards
0 [rockchiprk3308v]: rockchip_rk3308 - rockchip,rk3308-vad
rockchip,rk3308-vad
1 [rockchiprk3308p]: rockchip_rk3308 - rockchip,rk3308-pcm
rockchip,rk3308-pcm
2 [UAC2Gadget ]: UAC2_Gadget - UAC2_Gadget
UAC2_Gadget 0
7 [Loopback ]: Loopback - Loopback
Loopback 1
# ls -lh /proc/asound/card2
-r--r--r-- 1 root root 0 Dec 31 19:04 id
dr-xr-xr-x 3 root root 0 Dec 31 19:04 pcm0c
dr-xr-xr-x 3 root root 0 Dec 31 19:04 pcm0p
# ls /dev/snd/
controlC0 controlC7 pcmC1D0c pcmC2D0p pcmC7D1c
controlC1 pcmC0D0c pcmC1D0p pcmC7D0c pcmC7D1p
controlC2 pcmC0D0p pcmC2D0c pcmC7D0p timer
3.2 UAC2 Test
3.2.1 UAC2 Test on Windows
Windows PC 2.2.1 UAC1 Test on Windows
Windows UAC2
3308 UAC2
arecord -f dat -t wav -r 64000 -c 2 -D hw:2,0 | aplay -f dat -r 64000 -c 2 -D hw:0,0
Card2 USB Audio Card0 64KHz
UAC1 48KHz
arecord -f dat -t wav -r 48000 -c 2 -D hw:2,0 | aplay -f dat -r 48000 -c 2 -D hw:0,0
Windows PC 3308
Windows UAC2
ADB push arecord
48KHz 2 channels 16 bits
3308 arecord test.wav
48KHz
arecord -f dat -t wav -r 48000 -c 2 -D hw:2,0 /tmp/test.wav
test.wav UAC1
aplay /tmp/test.wav -c 2 -r 48000 -D hw:2,0
PC Windows “Voice Recorder 2.2.1 UAC1
Test on Windows
3.2.2 UAC2 Test on Ubuntu
Ubuntu PC 2.2.2 UAC1 Test on Ubuntu
Ubuntu PC 3308 UAC2 3.2.1 UAC2 Test on Windows
4 UAC1 Legacy Usage and Test
4.1 UAC1 Legacy Usage
Rockchip UAC1 Legacy USB Audio Class specification 1.0
/dev/snd/pcmC0D0p
High Speed
playback 48 KHz
playback 2 Channels
playback 16 bits
UAC1 Legacy
CONFIG_USB_CONFIGFS_F_UAC1_LEGACY=y defconfig
3308 EVB
UAC1 Legacy
mount -t configfs none /sys/kernel/config
mkdir /sys/kernel/config/usb_gadget/rockchip -m 0770
echo 0x2207 > /sys/kernel/config/usb_gadget/rockchip/idVendor
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0100 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
mkdir /sys/kernel/config/usb_gadget/rockchip/strings/0x409 -m 0770
echo "0123456789ABCDEF" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/serialnumber
echo "rockchip" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/manufacturer
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1 -m 0770
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409 -m 0770
echo 500 > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/MaxPower
echo "uac1" > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/uac1_legacy.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/uac1_legacy.gs0
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/uac1_legacy.gs0
echo ff400000.usb > /sys/kernel/config/usb_gadget/rockchip/UDC
3308 ADB
UAC1 Legacy USB ADB UAC1 Legacy
rm -rf /sys/kernel/config/usb_gadget/rockchip/configs/b.1/ffs.adb
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/uac1_legacy.gs0
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0100 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
echo "uac1" > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
cd /sys/kernel/config/usb_gadget/rockchip/configs/b.1
ln -s ../../functions/uac1_legacy.gs0
echo ff400000.usb > ../../UDC
Note
“idProduct ” USB Function idProduct
“UDC” USB /sys/class/udc/
Windows Windows
USB PC PC USB Audio 4-1
4-1 Windows-USB-Audio-Class1-Legacy
3308 USB UAC1 Legacy
configfs-gadget gadget: Hardware params: access 3, format 2, channels 2, rate 48000
dwc2 ff400000.usb: bound driver configfs-gadget
dwc2 ff400000.usb: new device is high-speed
dwc2 ff400000.usb: new address 25
android_work: sent uevent USB_STATE=CONNECTED
configfs-gadget gadget: high-speed config #1: b
android_work: sent uevent USB_STATE=CONFIGURED
UAC1 Legacy
UAC
# ls -lh /sys/kernel/config/usb_gadget/g1/functions/uac1_legacy.gs0/
-rw-r--r-- 1 root root 4.0K Dec 31 19:08 audio_buf_size
-rw-r--r-- 1 root root 4.0K Dec 31 19:08 fn_cap
-rw-r--r-- 1 root root 4.0K Dec 31 19:08 fn_cntl
-rw-r--r-- 1 root root 4.0K Dec 31 19:08 fn_play
-rw-r--r-- 1 root root 4.0K Dec 31 19:08 req_buf_size
-rw-r--r-- 1 root root 4.0K Dec 31 19:08 req_count
audio_buf_size - audio buffer size 48000
fn_cap - capture pcm device file name /dev/snd/pcmC0D0c
fn_cntl - control device file name /dev/snd/controlC0
fn_play - playback pcm device file name /dev/snd/pcmC0D0p
req_buf_size - ISO OUT endpoint request buffer size 200
req_count - ISO OUT endpoint request count 256
UAC1 Legacy 3308
4.2 UAC1 Legacy Test
Windows PC 2.2.1 UAC1 Test on Windows
Ubuntu PC 2.2.2 UAC1 Test on Ubuntu
3308 USB PC UAC1 Legacy 3308 Card0
5 Audio Source Usage and Test
5.1 Audio Source Usage
Rockchip Audio Source USB Audio Class specification 1.0
High Speed
playback 44.1KHz 15 PC
8000, 11025, 16000, 22050, 24000,
32000, 40000, 44100, 48000, 56000,
64000, 72000, 80000, 88200, 96000,
playback 2 Channels
playback 16 bits
Audio Source
CONFIG_USB_CONFIGFS_F_ACC=y Audio Source depends on it defconfig
CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y defconfig
3308 EVB
Audio Source
mount -t configfs none /sys/kernel/config
mkdir /sys/kernel/config/usb_gadget/rockchip -m 0770
echo 0x2207 > /sys/kernel/config/usb_gadget/rockchip/idVendor
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
mkdir /sys/kernel/config/usb_gadget/rockchip/strings/0x409 -m 0770
echo "0123456789ABCDEF" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/serialnumber
echo "rockchip" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/manufacturer
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1 -m 0770
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409 -m 0770
echo 500 > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/MaxPower
echo "audio" > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/audio_source.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/audio_source.gs0
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/audio_source.gs0
echo ff400000.usb > /sys/kernel/config/usb_gadget/rockchip/UDC
3308 ADB
Audio Source USB ADB Audio Source
rm -rf /sys/kernel/config/usb_gadget/rockchip/configs/b.1/ffs.adb
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/audio_source.gs0
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0100 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
echo "audio" > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
cd /sys/kernel/config/usb_gadget/rockchip/configs/b.1
ln -s ../../functions/audio_source.gs0
echo ff400000.usb > ../../UDC
Note
“idProduct ” USB Function idProduct
“UDC” USB /sys/class/udc/
Windows Windows
USB PC PC USB Audio 5-1 Windows-USB-Audio-Source
5-2 Ubuntu-USB-Audio-Source
5-1 Windows-USB-Audio-Source
5-2 Ubuntu-USB-Audio-Source
3308 USB Audio Source
dwc2 ff400000.usb: new device is high-speed
dwc2 ff400000.usb: new address 23
android_work: sent uevent USB_STATE=CONNECTED
configfs-gadget gadget: high-speed config #1: b
android_work: sent uevent USB_STATE=CONFIGURED
Audio Source
Audio Source
Audio Source card2 audiosource playback - pcmC2D0p
# cat /proc/asound/cards
0 [rockchiprk3308v]: rockchip_rk3308 - rockchip,rk3308-vad
rockchip,rk3308-vad
1 [rockchiprk3308p]: rockchip_rk3308 - rockchip,rk3308-pcm
rockchip,rk3308-pcm
2 [audiosource ]: audio_source - audio_source
USB accessory audio source
7 [Loopback ]: Loopback - Loopback
Loopback 1
# ls -lh /proc/asound/card2
-r--r--r-- 1 root root 0 Dec 31 19:06 id
dr-xr-xr-x 3 root root 0 Dec 31 19:06 pcm0p
# ls /dev/snd/
controlC0 controlC2 pcmC0D0c pcmC1D0c pcmC2D0p pcmC7D0p pcmC7D1p
controlC1 controlC7 pcmC0D0p pcmC1D0p pcmC7D0c pcmC7D1c timer
5.2 Audio Source Test
Audio Source
Windows PC 2.2.1 UAC1 Test on Windows
Ubuntu PC 2.2.2 UAC1 Test on Ubuntu
3308 44.1KHz
aplay /tmp/test.wav -r 44100 -c 2 -D hw:2,0
Note
test.wav
Audio Source 15 PC
” --> “ ” --> " " --> “ ” --> “
5-3
5-3 Windows-USB-Audio-Source-Setting
6 UAC1 Legacy and Audio Source Composite Usage and
Test
6.1 UAC1 Legacy and Audio Source Composite Usage
UAC1 Legacy + Audio Source
UAC1 Legacy Audio Source USB
CONFIG_USB_CONFIGFS_F_UAC1_LEGACY=y defconfig
CONFIG_USB_CONFIGFS_F_ACC=y Audio Source depends on it defconfig
CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y defconfig
support_uac1_legacy_and_audio_source.patch
3308 EVB
UAC1 Legacy + Audio Source
mount -t configfs none /sys/kernel/config
mkdir /sys/kernel/config/usb_gadget/rockchip -m 0770
echo 0x2207 > /sys/kernel/config/usb_gadget/rockchip/idVendor
echo 0x0019 > /sys/kernel/config/usb_gadget/rockchip/idProduct
echo 0x0100 > /sys/kernel/config/usb_gadget/rockchip/bcdDevice
mkdir /sys/kernel/config/usb_gadget/rockchip/strings/0x409 -m 0770
echo "0123456789ABCDEF" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/serialnumber
echo "rockchip" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/manufacturer
echo "USB Audio Device" > /sys/kernel/config/usb_gadget/rockchip/strings/0x409/product
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1 -m 0770
mkdir /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409 -m 0770
echo 500 > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/MaxPower
echo "uac1" > /sys/kernel/config/usb_gadget/rockchip/configs/b.1/strings/0x409/configuration
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/uac1_legacy.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/uac1_legacy.gs0
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/uac1_legacy.gs0
mkdir /sys/kernel/config/usb_gadget/rockchip/functions/audio_source.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/audio_source.gs0
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/audio_source.gs0
echo ff400000.usb > /sys/kernel/config/usb_gadget/rockchip/UDC
4.1 UAC1 Legacy Usage 5.1 Audio Source Usage
6.2 UAC1 Legacy and Audio Source Composite Test
4.2 UAC1 Legacy Test 5.2 Audio Source Test
7 Composite with ADB
UAC1 ADB UAC1 Windows UAC
UAC1 ADB link UAC1 ADB
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/uac1.gs0
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/uac1.gs0
ln -s /sys/kernel/config/usb_gadget/rockchip/functions/ffs.adb
/sys/kernel/config/usb_gadget/rockchip/configs/b.1/ffs.adb
8 Reference Documentation
USB Protocol (from USB Implementers Forum)
Universal Serial Bus Specification, Revision 2.0
Universal Serial Bus Audio Device Class Specification for Basic Audio Devices
Universal Serial Bus Device Class Definition for Audio Devices, Release 1.0
Universal Serial Bus Device Class Definition for Audio Devices, Release 2.0
Universal Serial Bus Device Class Definition for Audio Data Formats(referred to in this document as USB
Audio Data Formats)
Universal Serial Bus Device Class Definition for Terminal Types(referred to in this document as USB Audio
Terminal Types)
Others
The Well-Tempered Computer (An introduction to computer audio) - USB
Windows USB Audio 2.0 Drivers
9 Appendix A UAC1 Device Descriptor
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x2207
idProduct 0x0019
bcdDevice 1.00
iManufacturer 1 rockchip
iProduct 2 USB Audio Device
iSerial 3 0123456789ABCDEF
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 174
bNumInterfaces 3
bConfigurationValue 1
iConfiguration 4 audio
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 0
iInterface 5 AC Interface
AudioControl Interface Descriptor:
bLength 10
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 1.00
wTotalLength 52
bInCollection 2
baInterfaceNr( 0) 1
baInterfaceNr( 1) 2
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bNrChannels 2
wChannelConfig 0x0003
Left Front (L)
Right Front (R)
iChannelNames 7 Playback Channels
iTerminal 6 Playback Input terminal
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0301 Speaker
bAssocTerminal 0
bSourceID 1
iTerminal 8 Playback Output terminal
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 3
wTerminalType 0x0201 Microphone
bAssocTerminal 0
bNrChannels 2
wChannelConfig 0x0003
Left Front (L)
Right Front (R)
iChannelNames 10 Capture Channels
iTerminal 9 Capture Input terminal
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 4
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 3
iTerminal 11 Capture Output terminal
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 12 Playback Inactive
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 13 Playback Active
AudioStreaming Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 1
bDelay 1 frames
wFormatTag 1 PCM
AudioStreaming Interface Descriptor:
bLength 11
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize 2
bBitResolution 16
bSamFreqType 1 Discrete
tSamFreq[ 0] 48000
Endpoint Descriptor:
bLength 9
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 9
Transfer Type Isochronous
Synch Type Adaptive
Usage Type Data
wMaxPacketSize 0x00c8 1x 200 bytes
bInterval 4
bRefresh 0
bSynchAddress 0
AudioControl Endpoint Descriptor:
bLength 7
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x01
Sampling Frequency
bLockDelayUnits 1 Milliseconds
wLockDelay 1 Milliseconds
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 14 Capture Inactive
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 0
iInterface 15 Capture Active
AudioStreaming Interface Descriptor:
bLength 7
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 4
bDelay 1 frames
wFormatTag 1 PCM
AudioStreaming Interface Descriptor:
bLength 11
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize 2
bBitResolution 16
bSamFreqType 1 Discrete
tSamFreq[ 0] 48000
Endpoint Descriptor:
bLength 9
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 5
Transfer Type Isochronous
Synch Type Asynchronous
Usage Type Data
wMaxPacketSize 0x00c8 1x 200 bytes
bInterval 4
bRefresh 0
bSynchAddress 0
AudioControl Endpoint Descriptor:
bLength 7
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x01
Sampling Frequency
bLockDelayUnits 0 Undefined
wLockDelay 0 Undefined
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0000
(Bus Powered)
10 Appendix B UAC2 Device Descriptor
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x2207
idProduct 0x0019
bcdDevice 2.00
iManufacturer 1 rockchip
iProduct 2 USB Audio Device
iSerial 3 0123456789ABCDEF
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 219
bNumInterfaces 3
bConfigurationValue 1
iConfiguration 4 audio
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 0
bInterfaceCount 3
bFunctionClass 1 Audio
bFunctionSubClass 0
bFunctionProtocol 32
iFunction 5 Source/Sink
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 1 Control Device
bInterfaceProtocol 32
iInterface 6 Topology Control
AudioControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdADC 2.00
bCategory 8
wTotalLength 83
bmControl 0x00
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 10 (CLOCK_SOURCE)
bClockID 6
bmAttributes 0x01 Internal fixed Clock
bmControls 0x01
Clock Frequency Control (read-only)
bAssocTerminal 0
iClockSource 7 48000Hz
AudioControl Interface Descriptor:
bLength 8
bDescriptorType 36
bDescriptorSubtype 10 (CLOCK_SOURCE)
bClockID 5
bmAttributes 0x01 Internal fixed Clock
bmControls 0x01
Clock Frequency Control (read-only)
bAssocTerminal 0
iClockSource 8 64000Hz
AudioControl Interface Descriptor:
bLength 17
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bCSourceID 5
bNrChannels 2
bmChannelConfig 0x00000003
Front Left (FL)
Front Right (FR)
bmControls 0x0003
Copy Protect Control (read/write)
iChannelNames 0
iTerminal 9 USBH Out
AudioControl Interface Descriptor:
bLength 17
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0201 Microphone
bAssocTerminal 0
bCSourceID 6
bNrChannels 2
bmChannelConfig 0x00000003
Front Left (FL)
Front Right (FR)
bmControls 0x0003
Copy Protect Control (read/write)
iChannelNames 0
iTerminal 10 USBD Out
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 4
wTerminalType 0x0101 USB Streaming
bAssocTerminal 0
bSourceID 2
bCSourceID 6
bmControls 0x0003
Copy Protect Control (read/write)
iTerminal 11 USBH In
AudioControl Interface Descriptor:
bLength 12
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 3
wTerminalType 0x0301 Speaker
bAssocTerminal 0
bSourceID 1
bCSourceID 5
bmControls 0x0003
Copy Protect Control (read/write)
iTerminal 12 USBD In
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 13 Playback Inactive
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 14 Playback Active
AudioStreaming Interface Descriptor:
bLength 16
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 1
bmControls 0x00
bFormatType 1
bmFormats 0x00000001
PCM
bNrChannels 2
bmChannelConfig 0x00000003
Front Left (FL)
Front Right (FR)
iChannelNames 0
AudioStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bSubslotSize 2
bBitResolution 16
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 9
Transfer Type Isochronous
Synch Type Adaptive
Usage Type Data
wMaxPacketSize 0x0100 1x 256 bytes
bInterval 4
AudioControl Endpoint Descriptor:
bLength 8
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x00
bmControls 0x00
bLockDelayUnits 0 Undefined
wLockDelay 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 15 Capture Inactive
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 1
bNumEndpoints 1
bInterfaceClass 1 Audio
bInterfaceSubClass 2 Streaming
bInterfaceProtocol 32
iInterface 16 Capture Active
AudioStreaming Interface Descriptor:
bLength 16
bDescriptorType 36
bDescriptorSubtype 1 (AS_GENERAL)
bTerminalLink 4
bmControls 0x00
bFormatType 1
bmFormats 0x00000001
PCM
bNrChannels 2
bmChannelConfig 0x00000003
Front Left (FL)
Front Right (FR)
iChannelNames 0
AudioStreaming Interface Descriptor:
bLength 6
bDescriptorType 36
bDescriptorSubtype 2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bSubslotSize 2
bBitResolution 16
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 13
Transfer Type Isochronous
Synch Type Synchronous
Usage Type Data
wMaxPacketSize 0x00c0 1x 192 bytes
bInterval 4
AudioControl Endpoint Descriptor:
bLength 8
bDescriptorType 37
bDescriptorSubtype 1 (EP_GENERAL)
bmAttributes 0x00
bmControls 0x00
bLockDelayUnits 0 Undefined
wLockDelay 0
Device Qualifier (for other device speed):
bLength 10
bDescriptorType 6
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
bNumConfigurations 1
Device Status: 0x0000
(Bus Powered)

Navigation menu