Skip to content

Commit 0591bc2

Browse files
rbilovolFelipe Balbi
authored and
Felipe Balbi
committed
usb: gadget: add f_uac1 variant based on a new u_audio api
This patch adds a new function 'f_uac1' (f_uac1 with virtual "ALSA card") that uses recently created u_audio API. Comparing to legacy f_uac1 function implementation it doesn't require any real Audio codec to be present on the device. In f_uac1 audio streams are simply sinked to and sourced from a virtual ALSA sound card created using u_audio API. Legacy f_uac1 approach is to write audio samples directly to existing ALSA sound card f_uac1 approach is more generic/flexible one - create an ALSA sound card that represents USB Audio function and allows to be used by userspace application that may choose to do whatever it wants with the data received from the USB Host and choose to provide whatever it wants as audio data to the USB Host. f_uac1 also has capture support (gadget->host) thanks to easy implementation via u_audio. By default, capture interface has 48000kHz/2ch configuration, same as playback channel has. f_uac1 descriptors naming convention uses f_uac2 driver naming convention that makes it more common and meaningful. Comparing to f_uac1_legacy, the f_uac1 doesn't have volume/mute functionality. This is because the f_uac1 volume/mute feature unit was dummy implementation since that driver creation (2009) and never had any real volume control or mute functionality, so there is no any difference here. Since f_uac1 functionality, exposed interface to userspace (virtual ALSA card), input parameters are so different comparing to f_uac1_legacy, that there is no any reason to keep them in the same file/module, and separate function was created. g_audio can be built using one of existing UAC functions (f_uac1, f_uac1_legacy or f_uac2) Signed-off-by: Ruslan Bilovol <ruslan.bilovol@gmail.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
1 parent d355339 commit 0591bc2

File tree

8 files changed

+1000
-15
lines changed

8 files changed

+1000
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
What: /config/usb-gadget/gadget/functions/uac1.name
2+
Date: June 2017
3+
KernelVersion: 4.14
4+
Description:
5+
The attributes:
6+
7+
c_chmask - capture channel mask
8+
c_srate - capture sampling rate
9+
c_ssize - capture sample size (bytes)
10+
p_chmask - playback channel mask
11+
p_srate - playback sampling rate
12+
p_ssize - playback sample size (bytes)
13+
req_number - the number of pre-allocated request
14+
for both capture and playback

Documentation/usb/gadget-testing.txt

+44
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ provided by gadgets.
2020
17. UAC2 function
2121
18. UVC function
2222
19. PRINTER function
23+
20. UAC1 function (new API)
2324

2425

2526
1. ACM function
@@ -773,3 +774,46 @@ host:
773774

774775
More advanced testing can be done with the prn_example
775776
described in Documentation/usb/gadget-printer.txt.
777+
778+
779+
20. UAC1 function (virtual ALSA card, using u_audio API)
780+
=================
781+
782+
The function is provided by usb_f_uac1.ko module.
783+
It will create a virtual ALSA card and the audio streams are simply
784+
sinked to and sourced from it.
785+
786+
Function-specific configfs interface
787+
------------------------------------
788+
789+
The function name to use when creating the function directory is "uac1".
790+
The uac1 function provides these attributes in its function directory:
791+
792+
c_chmask - capture channel mask
793+
c_srate - capture sampling rate
794+
c_ssize - capture sample size (bytes)
795+
p_chmask - playback channel mask
796+
p_srate - playback sampling rate
797+
p_ssize - playback sample size (bytes)
798+
req_number - the number of pre-allocated request for both capture
799+
and playback
800+
801+
The attributes have sane default values.
802+
803+
Testing the UAC1 function
804+
-------------------------
805+
806+
device: run the gadget
807+
host: aplay -l # should list our USB Audio Gadget
808+
809+
This function does not require real hardware support, it just
810+
sends a stream of audio data to/from the host. In order to
811+
actually hear something at the device side, a command similar
812+
to this must be used at the device side:
813+
814+
$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
815+
816+
e.g.:
817+
818+
$ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
819+
aplay -D default:CARD=OdroidU3

drivers/usb/gadget/Kconfig

+23-2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ config USB_F_MASS_STORAGE
191191
config USB_F_FS
192192
tristate
193193

194+
config USB_F_UAC1
195+
tristate
196+
194197
config USB_F_UAC1_LEGACY
195198
tristate
196199

@@ -365,6 +368,24 @@ config USB_CONFIGFS_F_FS
365368
implemented in kernel space (for instance Ethernet, serial or
366369
mass storage) and other are implemented in user space.
367370

371+
config USB_CONFIGFS_F_UAC1
372+
bool "Audio Class 1.0"
373+
depends on USB_CONFIGFS
374+
depends on SND
375+
select USB_LIBCOMPOSITE
376+
select SND_PCM
377+
select USB_U_AUDIO
378+
select USB_F_UAC1
379+
help
380+
This Audio function implements 1 AudioControl interface,
381+
1 AudioStreaming Interface each for USB-OUT and USB-IN.
382+
This driver doesn't expect any real Audio codec to be present
383+
on the device - the audio streams are simply sinked to and
384+
sourced from a virtual ALSA sound card created. The user-space
385+
application may choose to do whatever it wants with the data
386+
received from the USB Host and choose to provide whatever it
387+
wants as audio data to the USB Host.
388+
368389
config USB_CONFIGFS_F_UAC1_LEGACY
369390
bool "Audio Class 1.0 (legacy implementation)"
370391
depends on USB_CONFIGFS
@@ -375,8 +396,8 @@ config USB_CONFIGFS_F_UAC1_LEGACY
375396
help
376397
This Audio function implements 1 AudioControl interface,
377398
1 AudioStreaming Interface each for USB-OUT and USB-IN.
378-
This driver requires a real Audio codec to be present
379-
on the device.
399+
This is a legacy driver and requires a real Audio codec
400+
to be present on the device.
380401

381402
config USB_CONFIGFS_F_UAC2
382403
bool "Audio Class 2.0"

drivers/usb/gadget/function/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
3333
usb_f_fs-y := f_fs.o
3434
obj-$(CONFIG_USB_F_FS) += usb_f_fs.o
3535
obj-$(CONFIG_USB_U_AUDIO) += u_audio.o
36+
usb_f_uac1-y := f_uac1.o
37+
obj-$(CONFIG_USB_F_UAC1) += usb_f_uac1.o
3638
usb_f_uac1_legacy-y := f_uac1_legacy.o u_uac1_legacy.o
3739
obj-$(CONFIG_USB_F_UAC1_LEGACY) += usb_f_uac1_legacy.o
3840
usb_f_uac2-y := f_uac2.o

0 commit comments

Comments
 (0)