Linux 3.11-rc2
[linux-2.6.git] / drivers / usb / gadget / audio.c
blob231b0efe8fdc12704f596e84c7fbab8f86e9aee7
1 /*
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/module.h>
16 #include <linux/usb/composite.h>
18 #include "gadget_chips.h"
19 #define DRIVER_DESC "Linux USB Audio Gadget"
20 #define DRIVER_VERSION "Feb 2, 2012"
22 USB_GADGET_COMPOSITE_OPTIONS();
24 /* string IDs are assigned dynamically */
26 static struct usb_string strings_dev[] = {
27 [USB_GADGET_MANUFACTURER_IDX].s = "",
28 [USB_GADGET_PRODUCT_IDX].s = DRIVER_DESC,
29 [USB_GADGET_SERIAL_IDX].s = "",
30 { } /* end of list */
33 static struct usb_gadget_strings stringtab_dev = {
34 .language = 0x0409, /* en-us */
35 .strings = strings_dev,
38 static struct usb_gadget_strings *audio_strings[] = {
39 &stringtab_dev,
40 NULL,
43 #ifdef CONFIG_GADGET_UAC1
44 #include "u_uac1.h"
45 #include "u_uac1.c"
46 #include "f_uac1.c"
47 #else
48 #include "f_uac2.c"
49 #endif
51 /*-------------------------------------------------------------------------*/
53 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
54 * Instead: allocate your own, using normal USB-IF procedures.
57 /* Thanks to Linux Foundation for donating this product ID. */
58 #define AUDIO_VENDOR_NUM 0x1d6b /* Linux Foundation */
59 #define AUDIO_PRODUCT_NUM 0x0101 /* Linux-USB Audio Gadget */
61 /*-------------------------------------------------------------------------*/
63 static struct usb_device_descriptor device_desc = {
64 .bLength = sizeof device_desc,
65 .bDescriptorType = USB_DT_DEVICE,
67 .bcdUSB = __constant_cpu_to_le16(0x200),
69 #ifdef CONFIG_GADGET_UAC1
70 .bDeviceClass = USB_CLASS_PER_INTERFACE,
71 .bDeviceSubClass = 0,
72 .bDeviceProtocol = 0,
73 #else
74 .bDeviceClass = USB_CLASS_MISC,
75 .bDeviceSubClass = 0x02,
76 .bDeviceProtocol = 0x01,
77 #endif
78 /* .bMaxPacketSize0 = f(hardware) */
80 /* Vendor and product id defaults change according to what configs
81 * we support. (As does bNumConfigurations.) These values can
82 * also be overridden by module parameters.
84 .idVendor = __constant_cpu_to_le16(AUDIO_VENDOR_NUM),
85 .idProduct = __constant_cpu_to_le16(AUDIO_PRODUCT_NUM),
86 /* .bcdDevice = f(hardware) */
87 /* .iManufacturer = DYNAMIC */
88 /* .iProduct = DYNAMIC */
89 /* NO SERIAL NUMBER */
90 .bNumConfigurations = 1,
93 static struct usb_otg_descriptor otg_descriptor = {
94 .bLength = sizeof otg_descriptor,
95 .bDescriptorType = USB_DT_OTG,
97 /* REVISIT SRP-only hardware is possible, although
98 * it would not be called "OTG" ...
100 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
103 static const struct usb_descriptor_header *otg_desc[] = {
104 (struct usb_descriptor_header *) &otg_descriptor,
105 NULL,
108 /*-------------------------------------------------------------------------*/
110 static int __init audio_do_config(struct usb_configuration *c)
112 /* FIXME alloc iConfiguration string, set it in c->strings */
114 if (gadget_is_otg(c->cdev->gadget)) {
115 c->descriptors = otg_desc;
116 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
119 audio_bind_config(c);
121 return 0;
124 static struct usb_configuration audio_config_driver = {
125 .label = DRIVER_DESC,
126 .bConfigurationValue = 1,
127 /* .iConfiguration = DYNAMIC */
128 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
129 #ifndef CONFIG_GADGET_UAC1
130 .unbind = uac2_unbind_config,
131 #endif
134 /*-------------------------------------------------------------------------*/
136 static int __init audio_bind(struct usb_composite_dev *cdev)
138 int status;
140 status = usb_string_ids_tab(cdev, strings_dev);
141 if (status < 0)
142 goto fail;
143 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
144 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
146 status = usb_add_config(cdev, &audio_config_driver, audio_do_config);
147 if (status < 0)
148 goto fail;
149 usb_composite_overwrite_options(cdev, &coverwrite);
151 INFO(cdev, "%s, version: %s\n", DRIVER_DESC, DRIVER_VERSION);
152 return 0;
154 fail:
155 return status;
158 static int __exit audio_unbind(struct usb_composite_dev *cdev)
160 #ifdef CONFIG_GADGET_UAC1
161 gaudio_cleanup();
162 #endif
163 return 0;
166 static __refdata struct usb_composite_driver audio_driver = {
167 .name = "g_audio",
168 .dev = &device_desc,
169 .strings = audio_strings,
170 .max_speed = USB_SPEED_HIGH,
171 .bind = audio_bind,
172 .unbind = __exit_p(audio_unbind),
175 static int __init init(void)
177 return usb_composite_probe(&audio_driver);
179 module_init(init);
181 static void __exit cleanup(void)
183 usb_composite_unregister(&audio_driver);
185 module_exit(cleanup);
187 MODULE_DESCRIPTION(DRIVER_DESC);
188 MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>");
189 MODULE_LICENSE("GPL");