2 * audio.c -- Audio gadget driver
4 * Copyright (C) 2008 Bryan Wu <cooloney@kernel.org>
5 * Copyright (C) 2008 Analog Devices, Inc
7 * Enter bugs at http://blackfin.uclinux.org/
9 * Licensed under the GPL-2 or later.
12 /* #define VERBOSE_DEBUG */
14 #include <linux/kernel.h>
15 #include <linux/utsname.h>
17 #include "gadget_chips.h"
18 #define DRIVER_DESC "Linux USB Audio Gadget"
19 #define DRIVER_VERSION "Feb 2, 2012"
21 /*-------------------------------------------------------------------------*/
24 * Kbuild is not very cooperative with respect to linking separately
25 * compiled library objects into one module. So for now we won't use
26 * separate compilation ... ensuring init/exit sections work to shrink
27 * the runtime footprint, and giving us at least some parts of what
28 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
30 #include "composite.c"
32 /* string IDs are assigned dynamically */
34 #define STRING_MANUFACTURER_IDX 0
35 #define STRING_PRODUCT_IDX 1
37 static char manufacturer
[50];
39 static struct usb_string strings_dev
[] = {
40 [STRING_MANUFACTURER_IDX
].s
= manufacturer
,
41 [STRING_PRODUCT_IDX
].s
= DRIVER_DESC
,
45 static struct usb_gadget_strings stringtab_dev
= {
46 .language
= 0x0409, /* en-us */
47 .strings
= strings_dev
,
50 static struct usb_gadget_strings
*audio_strings
[] = {
55 #ifdef CONFIG_GADGET_UAC1
63 /*-------------------------------------------------------------------------*/
65 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
66 * Instead: allocate your own, using normal USB-IF procedures.
69 /* Thanks to Linux Foundation for donating this product ID. */
70 #define AUDIO_VENDOR_NUM 0x1d6b /* Linux Foundation */
71 #define AUDIO_PRODUCT_NUM 0x0101 /* Linux-USB Audio Gadget */
73 /*-------------------------------------------------------------------------*/
75 static struct usb_device_descriptor device_desc
= {
76 .bLength
= sizeof device_desc
,
77 .bDescriptorType
= USB_DT_DEVICE
,
79 .bcdUSB
= __constant_cpu_to_le16(0x200),
81 #ifdef CONFIG_GADGET_UAC1
82 .bDeviceClass
= USB_CLASS_PER_INTERFACE
,
86 .bDeviceClass
= USB_CLASS_MISC
,
87 .bDeviceSubClass
= 0x02,
88 .bDeviceProtocol
= 0x01,
90 /* .bMaxPacketSize0 = f(hardware) */
92 /* Vendor and product id defaults change according to what configs
93 * we support. (As does bNumConfigurations.) These values can
94 * also be overridden by module parameters.
96 .idVendor
= __constant_cpu_to_le16(AUDIO_VENDOR_NUM
),
97 .idProduct
= __constant_cpu_to_le16(AUDIO_PRODUCT_NUM
),
98 /* .bcdDevice = f(hardware) */
99 /* .iManufacturer = DYNAMIC */
100 /* .iProduct = DYNAMIC */
101 /* NO SERIAL NUMBER */
102 .bNumConfigurations
= 1,
105 static struct usb_otg_descriptor otg_descriptor
= {
106 .bLength
= sizeof otg_descriptor
,
107 .bDescriptorType
= USB_DT_OTG
,
109 /* REVISIT SRP-only hardware is possible, although
110 * it would not be called "OTG" ...
112 .bmAttributes
= USB_OTG_SRP
| USB_OTG_HNP
,
115 static const struct usb_descriptor_header
*otg_desc
[] = {
116 (struct usb_descriptor_header
*) &otg_descriptor
,
120 /*-------------------------------------------------------------------------*/
122 static int __init
audio_do_config(struct usb_configuration
*c
)
124 /* FIXME alloc iConfiguration string, set it in c->strings */
126 if (gadget_is_otg(c
->cdev
->gadget
)) {
127 c
->descriptors
= otg_desc
;
128 c
->bmAttributes
|= USB_CONFIG_ATT_WAKEUP
;
131 audio_bind_config(c
);
136 static struct usb_configuration audio_config_driver
= {
137 .label
= DRIVER_DESC
,
138 .bConfigurationValue
= 1,
139 /* .iConfiguration = DYNAMIC */
140 .bmAttributes
= USB_CONFIG_ATT_SELFPOWER
,
141 #ifndef CONFIG_GADGET_UAC1
142 .unbind
= uac2_unbind_config
,
146 /*-------------------------------------------------------------------------*/
148 static int __init
audio_bind(struct usb_composite_dev
*cdev
)
153 gcnum
= usb_gadget_controller_number(cdev
->gadget
);
155 device_desc
.bcdDevice
= cpu_to_le16(0x0300 | gcnum
);
157 ERROR(cdev
, "controller '%s' not recognized; trying %s\n",
159 audio_config_driver
.label
);
160 device_desc
.bcdDevice
=
161 __constant_cpu_to_le16(0x0300 | 0x0099);
164 /* device descriptor strings: manufacturer, product */
165 snprintf(manufacturer
, sizeof manufacturer
, "%s %s with %s",
166 init_utsname()->sysname
, init_utsname()->release
,
168 status
= usb_string_ids_tab(cdev
, strings_dev
);
171 device_desc
.iManufacturer
= strings_dev
[STRING_MANUFACTURER_IDX
].id
;
172 device_desc
.iProduct
= strings_dev
[STRING_PRODUCT_IDX
].id
;
174 status
= usb_add_config(cdev
, &audio_config_driver
, audio_do_config
);
178 INFO(cdev
, "%s, version: %s\n", DRIVER_DESC
, DRIVER_VERSION
);
185 static int __exit
audio_unbind(struct usb_composite_dev
*cdev
)
187 #ifdef CONFIG_GADGET_UAC1
193 static __refdata
struct usb_composite_driver audio_driver
= {
196 .strings
= audio_strings
,
197 .max_speed
= USB_SPEED_HIGH
,
199 .unbind
= __exit_p(audio_unbind
),
202 static int __init
init(void)
204 return usb_composite_probe(&audio_driver
);
208 static void __exit
cleanup(void)
210 usb_composite_unregister(&audio_driver
);
212 module_exit(cleanup
);
214 MODULE_DESCRIPTION(DRIVER_DESC
);
215 MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>");
216 MODULE_LICENSE("GPL");