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>
19 #define DRIVER_DESC "Linux USB Audio Gadget"
20 #define DRIVER_VERSION "Dec 18, 2008"
22 /*-------------------------------------------------------------------------*/
25 * Kbuild is not very cooperative with respect to linking separately
26 * compiled library objects into one module. So for now we won't use
27 * separate compilation ... ensuring init/exit sections work to shrink
28 * the runtime footprint, and giving us at least some parts of what
29 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
31 #include "composite.c"
32 #include "usbstring.c"
34 #include "epautoconf.c"
39 /*-------------------------------------------------------------------------*/
41 /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
42 * Instead: allocate your own, using normal USB-IF procedures.
45 /* Thanks to Linux Foundation for donating this product ID. */
46 #define AUDIO_VENDOR_NUM 0x1d6b /* Linux Foundation */
47 #define AUDIO_PRODUCT_NUM 0x0101 /* Linux-USB Audio Gadget */
49 /*-------------------------------------------------------------------------*/
51 static struct usb_device_descriptor device_desc
= {
52 .bLength
= sizeof device_desc
,
53 .bDescriptorType
= USB_DT_DEVICE
,
55 .bcdUSB
= __constant_cpu_to_le16(0x200),
57 .bDeviceClass
= USB_CLASS_PER_INTERFACE
,
60 /* .bMaxPacketSize0 = f(hardware) */
62 /* Vendor and product id defaults change according to what configs
63 * we support. (As does bNumConfigurations.) These values can
64 * also be overridden by module parameters.
66 .idVendor
= __constant_cpu_to_le16(AUDIO_VENDOR_NUM
),
67 .idProduct
= __constant_cpu_to_le16(AUDIO_PRODUCT_NUM
),
68 /* .bcdDevice = f(hardware) */
69 /* .iManufacturer = DYNAMIC */
70 /* .iProduct = DYNAMIC */
71 /* NO SERIAL NUMBER */
72 .bNumConfigurations
= 1,
75 static struct usb_otg_descriptor otg_descriptor
= {
76 .bLength
= sizeof otg_descriptor
,
77 .bDescriptorType
= USB_DT_OTG
,
79 /* REVISIT SRP-only hardware is possible, although
80 * it would not be called "OTG" ...
82 .bmAttributes
= USB_OTG_SRP
| USB_OTG_HNP
,
85 static const struct usb_descriptor_header
*otg_desc
[] = {
86 (struct usb_descriptor_header
*) &otg_descriptor
,
90 /*-------------------------------------------------------------------------*/
92 static int __init
audio_do_config(struct usb_configuration
*c
)
94 /* FIXME alloc iConfiguration string, set it in c->strings */
96 if (gadget_is_otg(c
->cdev
->gadget
)) {
97 c
->descriptors
= otg_desc
;
98 c
->bmAttributes
|= USB_CONFIG_ATT_WAKEUP
;
101 audio_bind_config(c
);
106 static struct usb_configuration audio_config_driver
= {
107 .label
= DRIVER_DESC
,
108 .bind
= audio_do_config
,
109 .bConfigurationValue
= 1,
110 /* .iConfiguration = DYNAMIC */
111 .bmAttributes
= USB_CONFIG_ATT_SELFPOWER
,
114 /*-------------------------------------------------------------------------*/
116 static int __init
audio_bind(struct usb_composite_dev
*cdev
)
121 gcnum
= usb_gadget_controller_number(cdev
->gadget
);
123 device_desc
.bcdDevice
= cpu_to_le16(0x0300 | gcnum
);
125 ERROR(cdev
, "controller '%s' not recognized; trying %s\n",
127 audio_config_driver
.label
);
128 device_desc
.bcdDevice
=
129 __constant_cpu_to_le16(0x0300 | 0x0099);
132 /* device descriptor strings: manufacturer, product */
133 snprintf(manufacturer
, sizeof manufacturer
, "%s %s with %s",
134 init_utsname()->sysname
, init_utsname()->release
,
136 status
= usb_string_id(cdev
);
139 strings_dev
[STRING_MANUFACTURER_IDX
].id
= status
;
140 device_desc
.iManufacturer
= status
;
142 status
= usb_string_id(cdev
);
145 strings_dev
[STRING_PRODUCT_IDX
].id
= status
;
146 device_desc
.iProduct
= status
;
148 status
= usb_add_config(cdev
, &audio_config_driver
);
152 INFO(cdev
, "%s, version: %s\n", DRIVER_DESC
, DRIVER_VERSION
);
159 static int __exit
audio_unbind(struct usb_composite_dev
*cdev
)
165 static struct usb_composite_driver audio_driver
= {
168 .strings
= audio_strings
,
170 .unbind
= __exit_p(audio_unbind
),
173 static int __init
init(void)
175 return usb_composite_register(&audio_driver
);
179 static void __exit
cleanup(void)
181 usb_composite_unregister(&audio_driver
);
183 module_exit(cleanup
);
185 MODULE_DESCRIPTION(DRIVER_DESC
);
186 MODULE_AUTHOR("Bryan Wu <cooloney@kernel.org>");
187 MODULE_LICENSE("GPL");