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/usb/composite.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"
31 USB_GADGET_COMPOSITE_OPTIONS();
33 /* string IDs are assigned dynamically */
35 static struct usb_string strings_dev
[] = {
36 [USB_GADGET_MANUFACTURER_IDX
].s
= "",
37 [USB_GADGET_PRODUCT_IDX
].s
= DRIVER_DESC
,
38 [USB_GADGET_SERIAL_IDX
].s
= "",
42 static struct usb_gadget_strings stringtab_dev
= {
43 .language
= 0x0409, /* en-us */
44 .strings
= strings_dev
,
47 static struct usb_gadget_strings
*audio_strings
[] = {
52 #ifdef CONFIG_GADGET_UAC1
60 /*-------------------------------------------------------------------------*/
62 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
63 * Instead: allocate your own, using normal USB-IF procedures.
66 /* Thanks to Linux Foundation for donating this product ID. */
67 #define AUDIO_VENDOR_NUM 0x1d6b /* Linux Foundation */
68 #define AUDIO_PRODUCT_NUM 0x0101 /* Linux-USB Audio Gadget */
70 /*-------------------------------------------------------------------------*/
72 static struct usb_device_descriptor device_desc
= {
73 .bLength
= sizeof device_desc
,
74 .bDescriptorType
= USB_DT_DEVICE
,
76 .bcdUSB
= __constant_cpu_to_le16(0x200),
78 #ifdef CONFIG_GADGET_UAC1
79 .bDeviceClass
= USB_CLASS_PER_INTERFACE
,
83 .bDeviceClass
= USB_CLASS_MISC
,
84 .bDeviceSubClass
= 0x02,
85 .bDeviceProtocol
= 0x01,
87 /* .bMaxPacketSize0 = f(hardware) */
89 /* Vendor and product id defaults change according to what configs
90 * we support. (As does bNumConfigurations.) These values can
91 * also be overridden by module parameters.
93 .idVendor
= __constant_cpu_to_le16(AUDIO_VENDOR_NUM
),
94 .idProduct
= __constant_cpu_to_le16(AUDIO_PRODUCT_NUM
),
95 /* .bcdDevice = f(hardware) */
96 /* .iManufacturer = DYNAMIC */
97 /* .iProduct = DYNAMIC */
98 /* NO SERIAL NUMBER */
99 .bNumConfigurations
= 1,
102 static struct usb_otg_descriptor otg_descriptor
= {
103 .bLength
= sizeof otg_descriptor
,
104 .bDescriptorType
= USB_DT_OTG
,
106 /* REVISIT SRP-only hardware is possible, although
107 * it would not be called "OTG" ...
109 .bmAttributes
= USB_OTG_SRP
| USB_OTG_HNP
,
112 static const struct usb_descriptor_header
*otg_desc
[] = {
113 (struct usb_descriptor_header
*) &otg_descriptor
,
117 /*-------------------------------------------------------------------------*/
119 static int __init
audio_do_config(struct usb_configuration
*c
)
121 /* FIXME alloc iConfiguration string, set it in c->strings */
123 if (gadget_is_otg(c
->cdev
->gadget
)) {
124 c
->descriptors
= otg_desc
;
125 c
->bmAttributes
|= USB_CONFIG_ATT_WAKEUP
;
128 audio_bind_config(c
);
133 static struct usb_configuration audio_config_driver
= {
134 .label
= DRIVER_DESC
,
135 .bConfigurationValue
= 1,
136 /* .iConfiguration = DYNAMIC */
137 .bmAttributes
= USB_CONFIG_ATT_SELFPOWER
,
138 #ifndef CONFIG_GADGET_UAC1
139 .unbind
= uac2_unbind_config
,
143 /*-------------------------------------------------------------------------*/
145 static int __init
audio_bind(struct usb_composite_dev
*cdev
)
150 gcnum
= usb_gadget_controller_number(cdev
->gadget
);
152 device_desc
.bcdDevice
= cpu_to_le16(0x0300 | gcnum
);
154 ERROR(cdev
, "controller '%s' not recognized; trying %s\n",
156 audio_config_driver
.label
);
157 device_desc
.bcdDevice
=
158 __constant_cpu_to_le16(0x0300 | 0x0099);
161 status
= usb_string_ids_tab(cdev
, strings_dev
);
164 device_desc
.iManufacturer
= strings_dev
[USB_GADGET_MANUFACTURER_IDX
].id
;
165 device_desc
.iProduct
= strings_dev
[USB_GADGET_PRODUCT_IDX
].id
;
167 status
= usb_add_config(cdev
, &audio_config_driver
, audio_do_config
);
170 usb_composite_overwrite_options(cdev
, &coverwrite
);
172 INFO(cdev
, "%s, version: %s\n", DRIVER_DESC
, DRIVER_VERSION
);
179 static int __exit
audio_unbind(struct usb_composite_dev
*cdev
)
181 #ifdef CONFIG_GADGET_UAC1
187 static __refdata
struct usb_composite_driver audio_driver
= {
190 .strings
= audio_strings
,
191 .max_speed
= USB_SPEED_HIGH
,
193 .unbind
= __exit_p(audio_unbind
),
196 static int __init
init(void)
198 return usb_composite_probe(&audio_driver
);
202 static void __exit
cleanup(void)
204 usb_composite_unregister(&audio_driver
);
206 module_exit(cleanup
);
208 MODULE_DESCRIPTION(DRIVER_DESC
);
209 MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>");
210 MODULE_LICENSE("GPL");