3 * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * This file contains the USB template for an USB Audio Device.
31 #ifdef USB_GLOBAL_INCLUDE_FILE
32 #include USB_GLOBAL_INCLUDE_FILE
34 #include <sys/stdint.h>
35 #include <sys/stddef.h>
36 #include <sys/param.h>
37 #include <sys/queue.h>
38 #include <sys/types.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
42 #include <sys/module.h>
44 #include <sys/mutex.h>
45 #include <sys/condvar.h>
46 #include <sys/sysctl.h>
48 #include <sys/unistd.h>
49 #include <sys/callout.h>
50 #include <sys/malloc.h>
53 #include <dev/usb/usb.h>
54 #include <dev/usb/usbdi.h>
55 #include <dev/usb/usb_core.h>
56 #include <dev/usb/usb_cdc.h>
58 #include <dev/usb/template/usb_template.h>
59 #endif /* USB_GLOBAL_INCLUDE_FILE */
70 #define STRING_AUDIO_PRODUCT \
71 "A\0u\0d\0i\0o\0 \0T\0e\0s\0t\0 \0D\0e\0v\0i\0c\0e"
73 #define STRING_AUDIO_MIXER \
74 "M\0i\0x\0e\0r\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e"
76 #define STRING_AUDIO_RECORD \
77 "R\0e\0c\0o\0r\0d\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e"
79 #define STRING_AUDIO_PLAYBACK \
80 "P\0l\0a\0y\0b\0a\0c\0k\0 \0i\0n\0t\0e\0r\0f\0a\0c\0e"
83 /* make the real string descriptors */
85 USB_MAKE_STRING_DESC(STRING_AUDIO_MIXER, string_audio_mixer);
86 USB_MAKE_STRING_DESC(STRING_AUDIO_RECORD, string_audio_record);
87 USB_MAKE_STRING_DESC(STRING_AUDIO_PLAYBACK, string_audio_playback);
88 USB_MAKE_STRING_DESC(STRING_AUDIO_PRODUCT, string_audio_product);
93 * Audio Mixer description structures
95 * Some of the audio descriptors were dumped
96 * from a Creative Labs USB audio device.
99 static const uint8_t audio_raw_desc_0[] = {
100 0x0a, 0x24, 0x01, 0x00, 0x01, 0xa9, 0x00, 0x02,
104 static const uint8_t audio_raw_desc_1[] = {
105 0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
106 0x03, 0x00, 0x00, 0x00
109 static const uint8_t audio_raw_desc_2[] = {
110 0x0c, 0x24, 0x02, 0x02, 0x01, 0x02, 0x00, 0x02,
111 0x03, 0x00, 0x00, 0x00
114 static const uint8_t audio_raw_desc_3[] = {
115 0x0c, 0x24, 0x02, 0x03, 0x03, 0x06, 0x00, 0x02,
116 0x03, 0x00, 0x00, 0x00
119 static const uint8_t audio_raw_desc_4[] = {
120 0x0c, 0x24, 0x02, 0x04, 0x05, 0x06, 0x00, 0x02,
121 0x03, 0x00, 0x00, 0x00
124 static const uint8_t audio_raw_desc_5[] = {
125 0x09, 0x24, 0x03, 0x05, 0x05, 0x06, 0x00, 0x01,
129 static const uint8_t audio_raw_desc_6[] = {
130 0x09, 0x24, 0x03, 0x06, 0x01, 0x03, 0x00, 0x09,
134 static const uint8_t audio_raw_desc_7[] = {
135 0x09, 0x24, 0x03, 0x07, 0x01, 0x01, 0x00, 0x08,
139 static const uint8_t audio_raw_desc_8[] = {
140 0x09, 0x24, 0x05, 0x08, 0x03, 0x0a, 0x0b, 0x0c,
144 static const uint8_t audio_raw_desc_9[] = {
145 0x0a, 0x24, 0x06, 0x09, 0x0f, 0x01, 0x01, 0x02,
149 static const uint8_t audio_raw_desc_10[] = {
150 0x0a, 0x24, 0x06, 0x0a, 0x02, 0x01, 0x43, 0x00,
154 static const uint8_t audio_raw_desc_11[] = {
155 0x0a, 0x24, 0x06, 0x0b, 0x03, 0x01, 0x01, 0x02,
159 static const uint8_t audio_raw_desc_12[] = {
160 0x0a, 0x24, 0x06, 0x0c, 0x04, 0x01, 0x01, 0x00,
164 static const uint8_t audio_raw_desc_13[] = {
165 0x0a, 0x24, 0x06, 0x0d, 0x02, 0x01, 0x03, 0x00,
169 static const uint8_t audio_raw_desc_14[] = {
170 0x0a, 0x24, 0x06, 0x0e, 0x03, 0x01, 0x01, 0x02,
174 static const uint8_t audio_raw_desc_15[] = {
175 0x0f, 0x24, 0x04, 0x0f, 0x03, 0x01, 0x0d, 0x0e,
176 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00
179 static const void *audio_raw_iface_0_desc[] = {
199 static const struct usb_temp_interface_desc audio_iface_0 = {
200 .ppEndpoints = NULL, /* no endpoints */
201 .ppRawDesc = audio_raw_iface_0_desc,
202 .bInterfaceClass = 1,
203 .bInterfaceSubClass = 1,
204 .bInterfaceProtocol = 0,
205 .iInterface = INDEX_AUDIO_MIXER,
208 static const uint8_t audio_raw_desc_20[] = {
209 0x07, 0x24, 0x01, 0x01, 0x03, 0x01, 0x00
213 static const uint8_t audio_raw_desc_21[] = {
214 0x0b, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x01,
219 static const uint8_t audio_raw_desc_22[] = {
220 0x07, 0x25, 0x01, 0x00, 0x01, 0x04, 0x00
223 static const void *audio_raw_iface_1_desc[] = {
229 static const void *audio_raw_ep_1_desc[] = {
234 static const struct usb_temp_packet_size audio_isoc_mps = {
235 .mps[USB_SPEED_FULL] = 0xC8,
236 .mps[USB_SPEED_HIGH] = 0xC8,
239 static const struct usb_temp_interval audio_isoc_interval = {
240 .bInterval[USB_SPEED_FULL] = 1, /* 1:1 */
241 .bInterval[USB_SPEED_HIGH] = 4, /* 1:8 */
244 static const struct usb_temp_endpoint_desc audio_isoc_out_ep = {
245 .ppRawDesc = audio_raw_ep_1_desc,
246 .pPacketSize = &audio_isoc_mps,
247 .pIntervals = &audio_isoc_interval,
248 .bEndpointAddress = UE_DIR_OUT,
249 .bmAttributes = UE_ISOCHRONOUS | UE_ISO_ADAPT,
252 static const struct usb_temp_endpoint_desc *audio_iface_1_ep[] = {
257 static const struct usb_temp_interface_desc audio_iface_1_alt_0 = {
258 .ppEndpoints = NULL, /* no endpoints */
259 .ppRawDesc = NULL, /* no raw descriptors */
260 .bInterfaceClass = 1,
261 .bInterfaceSubClass = 2,
262 .bInterfaceProtocol = 0,
263 .iInterface = INDEX_AUDIO_PLAYBACK,
266 static const struct usb_temp_interface_desc audio_iface_1_alt_1 = {
267 .ppEndpoints = audio_iface_1_ep,
268 .ppRawDesc = audio_raw_iface_1_desc,
269 .bInterfaceClass = 1,
270 .bInterfaceSubClass = 2,
271 .bInterfaceProtocol = 0,
272 .iInterface = INDEX_AUDIO_PLAYBACK,
273 .isAltInterface = 1, /* this is an alternate setting */
276 static const uint8_t audio_raw_desc_30[] = {
277 0x07, 0x24, 0x01, 0x07, 0x01, 0x01, 0x00
281 static const uint8_t audio_raw_desc_31[] = {
282 0x0b, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x01,
287 static const uint8_t audio_raw_desc_32[] = {
288 0x07, 0x25, 0x01, 0x01, 0x00, 0x00, 0x00
291 static const void *audio_raw_iface_2_desc[] = {
297 static const void *audio_raw_ep_2_desc[] = {
302 static const struct usb_temp_endpoint_desc audio_isoc_in_ep = {
303 .ppRawDesc = audio_raw_ep_2_desc,
304 .pPacketSize = &audio_isoc_mps,
305 .pIntervals = &audio_isoc_interval,
306 .bEndpointAddress = UE_DIR_IN,
307 .bmAttributes = UE_ISOCHRONOUS | UE_ISO_ADAPT,
310 static const struct usb_temp_endpoint_desc *audio_iface_2_ep[] = {
315 static const struct usb_temp_interface_desc audio_iface_2_alt_0 = {
316 .ppEndpoints = NULL, /* no endpoints */
317 .ppRawDesc = NULL, /* no raw descriptors */
318 .bInterfaceClass = 1,
319 .bInterfaceSubClass = 2,
320 .bInterfaceProtocol = 0,
321 .iInterface = INDEX_AUDIO_RECORD,
324 static const struct usb_temp_interface_desc audio_iface_2_alt_1 = {
325 .ppEndpoints = audio_iface_2_ep,
326 .ppRawDesc = audio_raw_iface_2_desc,
327 .bInterfaceClass = 1,
328 .bInterfaceSubClass = 2,
329 .bInterfaceProtocol = 0,
330 .iInterface = INDEX_AUDIO_RECORD,
331 .isAltInterface = 1, /* this is an alternate setting */
334 static const struct usb_temp_interface_desc *audio_interfaces[] = {
336 &audio_iface_1_alt_0,
337 &audio_iface_1_alt_1,
338 &audio_iface_2_alt_0,
339 &audio_iface_2_alt_1,
343 static const struct usb_temp_config_desc audio_config_desc = {
344 .ppIfaceDesc = audio_interfaces,
345 .bmAttributes = UC_BUS_POWERED,
346 .bMaxPower = 25, /* 50 mA */
347 .iConfiguration = INDEX_AUDIO_PRODUCT,
350 static const struct usb_temp_config_desc *audio_configs[] = {
355 static usb_temp_get_string_desc_t audio_get_string_desc;
357 const struct usb_temp_device_desc usb_template_audio = {
358 .getStringDesc = &audio_get_string_desc,
359 .ppConfigDesc = audio_configs,
360 .idVendor = USB_TEMPLATE_VENDOR,
363 .bDeviceClass = UDCLASS_COMM,
364 .bDeviceSubClass = 0,
365 .bDeviceProtocol = 0,
367 .iProduct = INDEX_AUDIO_PRODUCT,
371 /*------------------------------------------------------------------------*
372 * audio_get_string_desc
375 * NULL: Failure. No such string.
376 * Else: Success. Pointer to string descriptor is returned.
377 *------------------------------------------------------------------------*/
379 audio_get_string_desc(uint16_t lang_id, uint8_t string_index)
381 static const void *ptr[INDEX_AUDIO_MAX] = {
382 [INDEX_AUDIO_LANG] = &usb_string_lang_en,
383 [INDEX_AUDIO_MIXER] = &string_audio_mixer,
384 [INDEX_AUDIO_RECORD] = &string_audio_record,
385 [INDEX_AUDIO_PLAYBACK] = &string_audio_playback,
386 [INDEX_AUDIO_PRODUCT] = &string_audio_product,
389 if (string_index == 0) {
390 return (&usb_string_lang_en);
392 if (lang_id != 0x0409) {
395 if (string_index < INDEX_AUDIO_MAX) {
396 return (ptr[string_index]);