Skip to content

Commit 132fcb4

Browse files
JassiBrarFelipe Balbi
authored and
Felipe Balbi
committed
usb: gadget: Add Audio Class 2.0 Driver
This is a flexible USB Audio Class 2.0 compliant gadget driver that implements a simple topology with a virtual sound card exposed at the function side. The driver doesn't expect any real audio codec to be present on the function - the audio streams are simply sinked to and sourced from a virtual ALSA sound card created. The user-space application 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. Capture(USB-Out) and Playback(USB-In) can be run at independent configurations specified via module parameters while loading the driver. Make this new version as the default selection by a new Kconfig choice. Signed-off-by: Yadi Brar <[email protected]> Signed-off-by: Jassi Brar <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent d747a91 commit 132fcb4

File tree

3 files changed

+1485
-9
lines changed

3 files changed

+1485
-9
lines changed

drivers/usb/gadget/Kconfig

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,29 @@ config USB_AUDIO
599599
depends on SND
600600
select SND_PCM
601601
help
602-
Gadget Audio is compatible with USB Audio Class specification 1.0.
603-
It will include at least one AudioControl interface, zero or more
604-
AudioStream interface and zero or more MIDIStream interface.
605-
606-
Gadget Audio will use on-board ALSA (CONFIG_SND) audio card to
607-
playback or capture audio stream.
602+
This Gadget Audio driver is compatible with USB Audio Class
603+
specification 2.0. It implements 1 AudioControl interface,
604+
1 AudioStreaming Interface each for USB-OUT and USB-IN.
605+
Number of channels, sample rate and sample size can be
606+
specified as module parameters.
607+
This driver doesn't expect any real Audio codec to be present
608+
on the device - the audio streams are simply sinked to and
609+
sourced from a virtual ALSA sound card created. The user-space
610+
application may choose to do whatever it wants with the data
611+
received from the USB Host and choose to provide whatever it
612+
wants as audio data to the USB Host.
608613

609614
Say "y" to link the driver statically, or "m" to build a
610615
dynamically linked module called "g_audio".
611616

617+
config GADGET_UAC1
618+
bool "UAC 1.0 (Legacy)"
619+
depends on USB_AUDIO
620+
help
621+
If you instead want older UAC Spec-1.0 driver that also has audio
622+
paths hardwired to the Audio codec chip on-board and doesn't work
623+
without one.
624+
612625
config USB_ETH
613626
tristate "Ethernet Gadget (with CDC Ethernet support)"
614627
depends on NET

drivers/usb/gadget/audio.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
#include <linux/kernel.h>
1515
#include <linux/utsname.h>
1616

17-
#include "u_uac1.h"
18-
1917
#define DRIVER_DESC "Linux USB Audio Gadget"
20-
#define DRIVER_VERSION "Dec 18, 2008"
18+
#define DRIVER_VERSION "Feb 2, 2012"
2119

2220
/*-------------------------------------------------------------------------*/
2321

@@ -56,8 +54,13 @@ static struct usb_gadget_strings *audio_strings[] = {
5654
NULL,
5755
};
5856

57+
#ifdef CONFIG_GADGET_UAC1
58+
#include "u_uac1.h"
5959
#include "u_uac1.c"
6060
#include "f_uac1.c"
61+
#else
62+
#include "f_uac2.c"
63+
#endif
6164

6265
/*-------------------------------------------------------------------------*/
6366

@@ -77,9 +80,15 @@ static struct usb_device_descriptor device_desc = {
7780

7881
.bcdUSB = __constant_cpu_to_le16(0x200),
7982

83+
#ifdef CONFIG_GADGET_UAC1
8084
.bDeviceClass = USB_CLASS_PER_INTERFACE,
8185
.bDeviceSubClass = 0,
8286
.bDeviceProtocol = 0,
87+
#else
88+
.bDeviceClass = USB_CLASS_MISC,
89+
.bDeviceSubClass = 0x02,
90+
.bDeviceProtocol = 0x01,
91+
#endif
8392
/* .bMaxPacketSize0 = f(hardware) */
8493

8594
/* Vendor and product id defaults change according to what configs
@@ -131,6 +140,9 @@ static struct usb_configuration audio_config_driver = {
131140
.bConfigurationValue = 1,
132141
/* .iConfiguration = DYNAMIC */
133142
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
143+
#ifndef CONFIG_GADGET_UAC1
144+
.unbind = uac2_unbind_config,
145+
#endif
134146
};
135147

136148
/*-------------------------------------------------------------------------*/
@@ -180,7 +192,9 @@ static int __init audio_bind(struct usb_composite_dev *cdev)
180192

181193
static int __exit audio_unbind(struct usb_composite_dev *cdev)
182194
{
195+
#ifdef CONFIG_GADGET_UAC1
183196
gaudio_cleanup();
197+
#endif
184198
return 0;
185199
}
186200

0 commit comments

Comments
 (0)