1 /* $NetBSD: uaudio.c,v 1.91 2004/11/05 17:46:14 kent Exp $ */
5 * Copyright (c) 1999 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 * USB audio specs: http://www.usb.org/developers/devclass_docs/audio10.pdf
39 * http://www.usb.org/developers/devclass_docs/frmts10.pdf
40 * http://www.usb.org/developers/devclass_docs/termt10.pdf
45 * $NetBSD: uaudio.c,v 1.94 2005/01/15 15:19:53 kent Exp $
46 * $NetBSD: uaudio.c,v 1.95 2005/01/16 06:02:19 dsainty Exp $
47 * $NetBSD: uaudio.c,v 1.96 2005/01/16 12:46:00 kent Exp $
48 * $NetBSD: uaudio.c,v 1.97 2005/02/24 08:19:38 martin Exp $
51 #include <sys/stdint.h>
52 #include <sys/stddef.h>
53 #include <sys/param.h>
54 #include <sys/queue.h>
55 #include <sys/types.h>
56 #include <sys/systm.h>
57 #include <sys/kernel.h>
59 #include <sys/module.h>
61 #include <sys/mutex.h>
62 #include <sys/condvar.h>
63 #include <sys/sysctl.h>
65 #include <sys/unistd.h>
66 #include <sys/callout.h>
67 #include <sys/malloc.h>
71 #include <dev/usb/usb.h>
72 #include <dev/usb/usbdi.h>
73 #include <dev/usb/usbdi_util.h>
74 #include <dev/usb/usbhid.h>
75 #include <dev/usb/usb_request.h>
76 #include <dev/usb/usb_process.h>
78 #define USB_DEBUG_VAR uaudio_debug
79 #include <dev/usb/usb_debug.h>
81 #include <dev/usb/quirk/usb_quirk.h>
83 #include <sys/reboot.h> /* for bootverbose */
85 #ifdef HAVE_KERNEL_OPTION_HEADERS
89 #include <dev/sound/pcm/sound.h>
90 #include <dev/sound/usb/uaudioreg.h>
91 #include <dev/sound/usb/uaudio.h>
92 #include <dev/sound/chip.h>
93 #include "feeder_if.h"
95 static int uaudio_default_rate = 0; /* use rate list */
96 static int uaudio_default_bits = 32;
97 static int uaudio_default_channels = 0; /* use default */
100 static int uaudio_debug = 0;
102 static SYSCTL_NODE(_hw_usb, OID_AUTO, uaudio, CTLFLAG_RW, 0, "USB uaudio");
104 SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, debug, CTLFLAG_RWTUN,
105 &uaudio_debug, 0, "uaudio debug level");
106 SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_rate, CTLFLAG_RWTUN,
107 &uaudio_default_rate, 0, "uaudio default sample rate");
108 SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_bits, CTLFLAG_RWTUN,
109 &uaudio_default_bits, 0, "uaudio default sample bits");
110 SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_channels, CTLFLAG_RWTUN,
111 &uaudio_default_channels, 0, "uaudio default sample channels");
114 #define UAUDIO_IRQS (8000 / UAUDIO_NFRAMES) /* interrupts per second */
115 #define UAUDIO_NFRAMES 64 /* must be factor of 8 due HS-USB */
116 #define UAUDIO_NCHANBUFS 2 /* number of outstanding request */
117 #define UAUDIO_RECURSE_LIMIT 255 /* rounds */
118 #define UAUDIO_CHANNELS_MAX MIN(64, AFMT_CHANNEL_MAX)
119 #define UAUDIO_MATRIX_MAX 8 /* channels */
121 #define MAKE_WORD(h,l) (((h) << 8) | (l))
122 #define BIT_TEST(bm,bno) (((bm)[(bno) / 8] >> (7 - ((bno) % 8))) & 1)
123 #define UAUDIO_MAX_CHAN(x) (x)
124 #define MIX(sc) ((sc)->sc_mixer_node)
127 const struct usb_audio_streaming_interface_descriptor *v1;
128 const struct usb_audio20_streaming_interface_descriptor *v2;
132 const struct usb_audio_streaming_type1_descriptor *v1;
133 const struct usb_audio20_streaming_type1_descriptor *v2;
137 const struct usb_audio_streaming_endpoint_descriptor *v1;
138 const struct usb_audio20_streaming_endpoint_descriptor *v2;
141 struct uaudio_mixer_node {
146 #define MIX_MAX_CHAN 16
147 int32_t wValue[MIX_MAX_CHAN]; /* using nchan */
151 int wData[MIX_MAX_CHAN]; /* using nchan */
154 uint8_t update[(MIX_MAX_CHAN + 7) / 8];
158 #define MIX_SIGNED_16 2
159 #define MIX_UNSIGNED_16 3
160 #define MIX_SIGNED_8 4
161 #define MIX_SELECTOR 5
162 #define MIX_UNKNOWN 6
163 #define MIX_SIZE(n) ((((n) == MIX_SIGNED_16) || \
164 ((n) == MIX_UNSIGNED_16)) ? 2 : 1)
165 #define MIX_UNSIGNED(n) ((n) == MIX_UNSIGNED_16)
167 #define MAX_SELECTOR_INPUT_PIN 256
168 uint8_t slctrtype[MAX_SELECTOR_INPUT_PIN];
174 struct uaudio_mixer_node *next;
177 struct uaudio_configure_msg {
178 struct usb_proc_msg hdr;
179 struct uaudio_softc *sc;
182 #define CHAN_MAX_ALT 24
184 struct uaudio_chan_alt {
185 union uaudio_asf1d p_asf1d;
186 union uaudio_sed p_sed;
187 const usb_endpoint_descriptor_audio_t *p_ed1;
188 const struct uaudio_format *p_fmt;
189 const struct usb_config *usb_cfg;
190 uint32_t sample_rate; /* in Hz */
191 uint16_t sample_size;
193 uint8_t iface_alt_index;
198 struct pcmchan_caps pcm_cap; /* capabilities */
199 struct uaudio_chan_alt usb_alt[CHAN_MAX_ALT];
200 struct snd_dbuf *pcm_buf;
201 struct mtx *pcm_mtx; /* lock protecting this structure */
202 struct uaudio_softc *priv_sc;
203 struct pcm_channel *pcm_ch;
204 struct usb_xfer *xfer[UAUDIO_NCHANBUFS + 1];
206 uint8_t *buf; /* pointer to buffer */
207 uint8_t *start; /* upper layer buffer start */
208 uint8_t *end; /* upper layer buffer end */
209 uint8_t *cur; /* current position in upper layer
212 uint32_t intr_frames; /* in units */
213 uint32_t frames_per_second;
215 uint32_t sample_curr;
222 uint32_t pcm_format[2];
224 uint16_t bytes_per_frame[2];
226 uint32_t intr_counter;
232 #define CHAN_OP_NONE 0
233 #define CHAN_OP_START 1
234 #define CHAN_OP_STOP 2
235 #define CHAN_OP_DRAIN 3
238 #define UMIDI_EMB_JACK_MAX 16 /* units */
239 #define UMIDI_TX_FRAMES 256 /* units */
240 #define UMIDI_TX_BUFFER (UMIDI_TX_FRAMES * 4) /* bytes */
248 struct umidi_sub_chan {
249 struct usb_fifo_sc fifo;
254 #define UMIDI_ST_UNKNOWN 0 /* scan for command */
255 #define UMIDI_ST_1PARAM 1
256 #define UMIDI_ST_2PARAM_1 2
257 #define UMIDI_ST_2PARAM_2 3
258 #define UMIDI_ST_SYSEX_0 4
259 #define UMIDI_ST_SYSEX_1 5
260 #define UMIDI_ST_SYSEX_2 6
263 uint8_t write_open:1;
269 struct umidi_sub_chan sub[UMIDI_EMB_JACK_MAX];
272 struct usb_xfer *xfer[UMIDI_N_TRANSFER];
275 uint8_t iface_alt_index;
277 uint8_t read_open_refcount;
278 uint8_t write_open_refcount;
281 uint8_t max_emb_jack;
283 uint8_t single_command;
286 struct uaudio_search_result {
287 uint8_t bit_input[(256 + 7) / 8];
288 uint8_t bit_output[(256 + 7) / 8];
289 uint8_t recurse_level;
295 UAUDIO_HID_RX_TRANSFER,
296 UAUDIO_HID_N_TRANSFER,
300 struct usb_xfer *xfer[UAUDIO_HID_N_TRANSFER];
301 struct hid_location volume_up_loc;
302 struct hid_location volume_down_loc;
303 struct hid_location mute_loc;
305 #define UAUDIO_HID_VALID 0x0001
306 #define UAUDIO_HID_HAS_ID 0x0002
307 #define UAUDIO_HID_HAS_VOLUME_UP 0x0004
308 #define UAUDIO_HID_HAS_VOLUME_DOWN 0x0008
309 #define UAUDIO_HID_HAS_MUTE 0x0010
311 uint8_t volume_up_id;
312 uint8_t volume_down_id;
316 struct uaudio_softc {
317 struct sbuf sc_sndstat;
318 struct sndcard_func sc_sndcard_func;
319 struct uaudio_chan sc_rec_chan;
320 struct uaudio_chan sc_play_chan;
321 struct umidi_chan sc_midi_chan;
322 struct uaudio_hid sc_hid;
323 struct uaudio_search_result sc_mixer_clocks;
324 struct uaudio_mixer_node sc_mixer_node;
325 struct uaudio_configure_msg sc_config_msg[2];
327 struct mtx *sc_mixer_lock;
328 struct snd_mixer *sc_mixer_dev;
329 struct usb_device *sc_udev;
330 struct usb_xfer *sc_mixer_xfer[1];
331 struct uaudio_mixer_node *sc_mixer_root;
332 struct uaudio_mixer_node *sc_mixer_curr;
334 uint32_t sc_mix_info;
335 uint32_t sc_recsrc_info;
337 uint16_t sc_audio_rev;
338 uint16_t sc_mixer_count;
340 uint8_t sc_sndstat_valid;
341 uint8_t sc_mixer_iface_index;
342 uint8_t sc_mixer_iface_no;
343 uint8_t sc_mixer_chan;
344 uint8_t sc_pcm_registered:1;
345 uint8_t sc_mixer_init:1;
346 uint8_t sc_uq_audio_swap_lr:1;
347 uint8_t sc_uq_au_inp_async:1;
348 uint8_t sc_uq_au_no_xu:1;
349 uint8_t sc_uq_bad_adc:1;
350 uint8_t sc_uq_au_vendor_class:1;
351 uint8_t sc_pcm_bitperfect:1;
354 struct uaudio_terminal_node {
356 const struct usb_descriptor *desc;
357 const struct usb_audio_input_terminal *it_v1;
358 const struct usb_audio_output_terminal *ot_v1;
359 const struct usb_audio_mixer_unit_0 *mu_v1;
360 const struct usb_audio_selector_unit *su_v1;
361 const struct usb_audio_feature_unit *fu_v1;
362 const struct usb_audio_processing_unit_0 *pu_v1;
363 const struct usb_audio_extension_unit_0 *eu_v1;
364 const struct usb_audio20_clock_source_unit *csrc_v2;
365 const struct usb_audio20_clock_selector_unit_0 *csel_v2;
366 const struct usb_audio20_clock_multiplier_unit *cmul_v2;
367 const struct usb_audio20_input_terminal *it_v2;
368 const struct usb_audio20_output_terminal *ot_v2;
369 const struct usb_audio20_mixer_unit_0 *mu_v2;
370 const struct usb_audio20_selector_unit *su_v2;
371 const struct usb_audio20_feature_unit *fu_v2;
372 const struct usb_audio20_sample_rate_unit *ru_v2;
373 const struct usb_audio20_processing_unit_0 *pu_v2;
374 const struct usb_audio20_extension_unit_0 *eu_v2;
375 const struct usb_audio20_effect_unit *ef_v2;
377 struct uaudio_search_result usr;
378 struct uaudio_terminal_node *root;
381 struct uaudio_format {
384 uint32_t freebsd_fmt;
385 const char *description;
388 static const struct uaudio_format uaudio10_formats[] = {
390 {UA_FMT_PCM8, 8, AFMT_U8, "8-bit U-LE PCM"},
391 {UA_FMT_PCM8, 16, AFMT_U16_LE, "16-bit U-LE PCM"},
392 {UA_FMT_PCM8, 24, AFMT_U24_LE, "24-bit U-LE PCM"},
393 {UA_FMT_PCM8, 32, AFMT_U32_LE, "32-bit U-LE PCM"},
395 {UA_FMT_PCM, 8, AFMT_S8, "8-bit S-LE PCM"},
396 {UA_FMT_PCM, 16, AFMT_S16_LE, "16-bit S-LE PCM"},
397 {UA_FMT_PCM, 24, AFMT_S24_LE, "24-bit S-LE PCM"},
398 {UA_FMT_PCM, 32, AFMT_S32_LE, "32-bit S-LE PCM"},
400 {UA_FMT_ALAW, 8, AFMT_A_LAW, "8-bit A-Law"},
401 {UA_FMT_MULAW, 8, AFMT_MU_LAW, "8-bit mu-Law"},
406 static const struct uaudio_format uaudio20_formats[] = {
408 {UA20_FMT_PCM, 8, AFMT_S8, "8-bit S-LE PCM"},
409 {UA20_FMT_PCM, 16, AFMT_S16_LE, "16-bit S-LE PCM"},
410 {UA20_FMT_PCM, 24, AFMT_S24_LE, "24-bit S-LE PCM"},
411 {UA20_FMT_PCM, 32, AFMT_S32_LE, "32-bit S-LE PCM"},
413 {UA20_FMT_PCM8, 8, AFMT_U8, "8-bit U-LE PCM"},
414 {UA20_FMT_PCM8, 16, AFMT_U16_LE, "16-bit U-LE PCM"},
415 {UA20_FMT_PCM8, 24, AFMT_U24_LE, "24-bit U-LE PCM"},
416 {UA20_FMT_PCM8, 32, AFMT_U32_LE, "32-bit U-LE PCM"},
418 {UA20_FMT_ALAW, 8, AFMT_A_LAW, "8-bit A-Law"},
419 {UA20_FMT_MULAW, 8, AFMT_MU_LAW, "8-bit mu-Law"},
428 #define UAC_NCLASSES 4
431 static const char *uac_names[] = {
432 "outputs", "inputs", "equalization", "record"
439 static device_probe_t uaudio_probe;
440 static device_attach_t uaudio_attach;
441 static device_detach_t uaudio_detach;
443 static usb_callback_t uaudio_chan_play_callback;
444 static usb_callback_t uaudio_chan_play_sync_callback;
445 static usb_callback_t uaudio_chan_record_callback;
446 static usb_callback_t uaudio_chan_record_sync_callback;
447 static usb_callback_t uaudio_mixer_write_cfg_callback;
448 static usb_callback_t umidi_bulk_read_callback;
449 static usb_callback_t umidi_bulk_write_callback;
450 static usb_callback_t uaudio_hid_rx_callback;
452 static usb_proc_callback_t uaudio_configure_msg;
454 /* ==== USB mixer ==== */
456 static int uaudio_mixer_sysctl_handler(SYSCTL_HANDLER_ARGS);
457 static void uaudio_mixer_ctl_free(struct uaudio_softc *);
458 static void uaudio_mixer_register_sysctl(struct uaudio_softc *, device_t);
459 static void uaudio_mixer_reload_all(struct uaudio_softc *);
460 static void uaudio_mixer_controls_create_ftu(struct uaudio_softc *);
462 /* ==== USB audio v1.0 ==== */
464 static void uaudio_mixer_add_mixer(struct uaudio_softc *,
465 const struct uaudio_terminal_node *, int);
466 static void uaudio_mixer_add_selector(struct uaudio_softc *,
467 const struct uaudio_terminal_node *, int);
468 static uint32_t uaudio_mixer_feature_get_bmaControls(
469 const struct usb_audio_feature_unit *, uint8_t);
470 static void uaudio_mixer_add_feature(struct uaudio_softc *,
471 const struct uaudio_terminal_node *, int);
472 static void uaudio_mixer_add_processing_updown(struct uaudio_softc *,
473 const struct uaudio_terminal_node *, int);
474 static void uaudio_mixer_add_processing(struct uaudio_softc *,
475 const struct uaudio_terminal_node *, int);
476 static void uaudio_mixer_add_extension(struct uaudio_softc *,
477 const struct uaudio_terminal_node *, int);
478 static struct usb_audio_cluster uaudio_mixer_get_cluster(uint8_t,
479 const struct uaudio_terminal_node *);
480 static uint16_t uaudio_mixer_determine_class(const struct uaudio_terminal_node *,
481 struct uaudio_mixer_node *);
482 static uint16_t uaudio_mixer_feature_name(const struct uaudio_terminal_node *,
483 struct uaudio_mixer_node *);
484 static void uaudio_mixer_find_inputs_sub(struct uaudio_terminal_node *,
485 const uint8_t *, uint8_t, struct uaudio_search_result *);
486 static const void *uaudio_mixer_verify_desc(const void *, uint32_t);
487 static usb_error_t uaudio_set_speed(struct usb_device *, uint8_t, uint32_t);
488 static int uaudio_mixer_get(struct usb_device *, uint16_t, uint8_t,
489 struct uaudio_mixer_node *);
491 /* ==== USB audio v2.0 ==== */
493 static void uaudio20_mixer_add_mixer(struct uaudio_softc *,
494 const struct uaudio_terminal_node *, int);
495 static void uaudio20_mixer_add_selector(struct uaudio_softc *,
496 const struct uaudio_terminal_node *, int);
497 static void uaudio20_mixer_add_feature(struct uaudio_softc *,
498 const struct uaudio_terminal_node *, int);
499 static struct usb_audio20_cluster uaudio20_mixer_get_cluster(uint8_t,
500 const struct uaudio_terminal_node *);
501 static uint16_t uaudio20_mixer_determine_class(const struct uaudio_terminal_node *,
502 struct uaudio_mixer_node *);
503 static uint16_t uaudio20_mixer_feature_name(const struct uaudio_terminal_node *,
504 struct uaudio_mixer_node *);
505 static void uaudio20_mixer_find_inputs_sub(struct uaudio_terminal_node *,
506 const uint8_t *, uint8_t, struct uaudio_search_result *);
507 static const void *uaudio20_mixer_verify_desc(const void *, uint32_t);
508 static usb_error_t uaudio20_set_speed(struct usb_device *, uint8_t,
511 /* USB audio v1.0 and v2.0 */
513 static void uaudio_chan_fill_info_sub(struct uaudio_softc *,
514 struct usb_device *, uint32_t, uint8_t, uint8_t);
515 static void uaudio_chan_fill_info(struct uaudio_softc *,
516 struct usb_device *);
517 static void uaudio_mixer_add_ctl_sub(struct uaudio_softc *,
518 struct uaudio_mixer_node *);
519 static void uaudio_mixer_add_ctl(struct uaudio_softc *,
520 struct uaudio_mixer_node *);
521 static void uaudio_mixer_fill_info(struct uaudio_softc *,
522 struct usb_device *, void *);
523 static void uaudio_mixer_ctl_set(struct uaudio_softc *,
524 struct uaudio_mixer_node *, uint8_t, int32_t val);
525 static int uaudio_mixer_signext(uint8_t, int);
526 static int uaudio_mixer_bsd2value(struct uaudio_mixer_node *, int32_t val);
527 static void uaudio_mixer_init(struct uaudio_softc *);
528 static const struct uaudio_terminal_node *uaudio_mixer_get_input(
529 const struct uaudio_terminal_node *, uint8_t);
530 static const struct uaudio_terminal_node *uaudio_mixer_get_output(
531 const struct uaudio_terminal_node *, uint8_t);
532 static void uaudio_mixer_find_outputs_sub(struct uaudio_terminal_node *,
533 uint8_t, uint8_t, struct uaudio_search_result *);
534 static uint8_t umidi_convert_to_usb(struct umidi_sub_chan *, uint8_t, uint8_t);
535 static struct umidi_sub_chan *umidi_sub_by_fifo(struct usb_fifo *);
536 static void umidi_start_read(struct usb_fifo *);
537 static void umidi_stop_read(struct usb_fifo *);
538 static void umidi_start_write(struct usb_fifo *);
539 static void umidi_stop_write(struct usb_fifo *);
540 static int umidi_open(struct usb_fifo *, int);
541 static int umidi_ioctl(struct usb_fifo *, u_long cmd, void *, int);
542 static void umidi_close(struct usb_fifo *, int);
543 static void umidi_init(device_t dev);
544 static int umidi_probe(device_t dev);
545 static int umidi_detach(device_t dev);
546 static int uaudio_hid_probe(struct uaudio_softc *sc,
547 struct usb_attach_arg *uaa);
548 static void uaudio_hid_detach(struct uaudio_softc *sc);
551 static void uaudio_chan_dump_ep_desc(
552 const usb_endpoint_descriptor_audio_t *);
555 static const struct usb_config
556 uaudio_cfg_record[UAUDIO_NCHANBUFS + 1] = {
558 .type = UE_ISOCHRONOUS,
559 .endpoint = UE_ADDR_ANY,
560 .direction = UE_DIR_IN,
561 .bufsize = 0, /* use "wMaxPacketSize * frames" */
562 .frames = UAUDIO_NFRAMES,
563 .flags = {.short_xfer_ok = 1,},
564 .callback = &uaudio_chan_record_callback,
568 .type = UE_ISOCHRONOUS,
569 .endpoint = UE_ADDR_ANY,
570 .direction = UE_DIR_IN,
571 .bufsize = 0, /* use "wMaxPacketSize * frames" */
572 .frames = UAUDIO_NFRAMES,
573 .flags = {.short_xfer_ok = 1,},
574 .callback = &uaudio_chan_record_callback,
578 .type = UE_ISOCHRONOUS,
579 .endpoint = UE_ADDR_ANY,
580 .direction = UE_DIR_OUT,
581 .bufsize = 0, /* use "wMaxPacketSize * frames" */
583 .flags = {.no_pipe_ok = 1,.short_xfer_ok = 1,},
584 .callback = &uaudio_chan_record_sync_callback,
588 static const struct usb_config
589 uaudio_cfg_play[UAUDIO_NCHANBUFS + 1] = {
591 .type = UE_ISOCHRONOUS,
592 .endpoint = UE_ADDR_ANY,
593 .direction = UE_DIR_OUT,
594 .bufsize = 0, /* use "wMaxPacketSize * frames" */
595 .frames = UAUDIO_NFRAMES,
596 .flags = {.short_xfer_ok = 1,},
597 .callback = &uaudio_chan_play_callback,
601 .type = UE_ISOCHRONOUS,
602 .endpoint = UE_ADDR_ANY,
603 .direction = UE_DIR_OUT,
604 .bufsize = 0, /* use "wMaxPacketSize * frames" */
605 .frames = UAUDIO_NFRAMES,
606 .flags = {.short_xfer_ok = 1,},
607 .callback = &uaudio_chan_play_callback,
611 .type = UE_ISOCHRONOUS,
612 .endpoint = UE_ADDR_ANY,
613 .direction = UE_DIR_IN,
614 .bufsize = 0, /* use "wMaxPacketSize * frames" */
616 .flags = {.no_pipe_ok = 1,.short_xfer_ok = 1,},
617 .callback = &uaudio_chan_play_sync_callback,
621 static const struct usb_config
622 uaudio_mixer_config[1] = {
625 .endpoint = 0x00, /* Control pipe */
626 .direction = UE_DIR_ANY,
627 .bufsize = (sizeof(struct usb_device_request) + 4),
628 .callback = &uaudio_mixer_write_cfg_callback,
629 .timeout = 1000, /* 1 second */
634 uint8_t umidi_cmd_to_len[16] = {
635 [0x0] = 0, /* reserved */
636 [0x1] = 0, /* reserved */
637 [0x2] = 2, /* bytes */
638 [0x3] = 3, /* bytes */
639 [0x4] = 3, /* bytes */
640 [0x5] = 1, /* bytes */
641 [0x6] = 2, /* bytes */
642 [0x7] = 3, /* bytes */
643 [0x8] = 3, /* bytes */
644 [0x9] = 3, /* bytes */
645 [0xA] = 3, /* bytes */
646 [0xB] = 3, /* bytes */
647 [0xC] = 2, /* bytes */
648 [0xD] = 2, /* bytes */
649 [0xE] = 3, /* bytes */
650 [0xF] = 1, /* bytes */
653 static const struct usb_config
654 umidi_config[UMIDI_N_TRANSFER] = {
655 [UMIDI_TX_TRANSFER] = {
657 .endpoint = UE_ADDR_ANY,
658 .direction = UE_DIR_OUT,
659 .bufsize = UMIDI_TX_BUFFER,
660 .flags = {.no_pipe_ok = 1},
661 .callback = &umidi_bulk_write_callback,
664 [UMIDI_RX_TRANSFER] = {
666 .endpoint = UE_ADDR_ANY,
667 .direction = UE_DIR_IN,
668 .bufsize = 4, /* bytes */
669 .flags = {.short_xfer_ok = 1,.proxy_buffer = 1,.no_pipe_ok = 1},
670 .callback = &umidi_bulk_read_callback,
674 static const struct usb_config
675 uaudio_hid_config[UAUDIO_HID_N_TRANSFER] = {
676 [UAUDIO_HID_RX_TRANSFER] = {
677 .type = UE_INTERRUPT,
678 .endpoint = UE_ADDR_ANY,
679 .direction = UE_DIR_IN,
680 .bufsize = 0, /* use wMaxPacketSize */
681 .flags = {.short_xfer_ok = 1,},
682 .callback = &uaudio_hid_rx_callback,
686 static devclass_t uaudio_devclass;
688 static device_method_t uaudio_methods[] = {
689 DEVMETHOD(device_probe, uaudio_probe),
690 DEVMETHOD(device_attach, uaudio_attach),
691 DEVMETHOD(device_detach, uaudio_detach),
692 DEVMETHOD(device_suspend, bus_generic_suspend),
693 DEVMETHOD(device_resume, bus_generic_resume),
694 DEVMETHOD(device_shutdown, bus_generic_shutdown),
699 static driver_t uaudio_driver = {
701 .methods = uaudio_methods,
702 .size = sizeof(struct uaudio_softc),
705 /* The following table is derived from Linux's quirks-table.h */
706 static const STRUCT_USB_HOST_ID uaudio_vendor_midi[] = {
707 { USB_VPI(USB_VENDOR_YAMAHA, 0x1000, 0) }, /* UX256 */
708 { USB_VPI(USB_VENDOR_YAMAHA, 0x1001, 0) }, /* MU1000 */
709 { USB_VPI(USB_VENDOR_YAMAHA, 0x1002, 0) }, /* MU2000 */
710 { USB_VPI(USB_VENDOR_YAMAHA, 0x1003, 0) }, /* MU500 */
711 { USB_VPI(USB_VENDOR_YAMAHA, 0x1004, 3) }, /* UW500 */
712 { USB_VPI(USB_VENDOR_YAMAHA, 0x1005, 0) }, /* MOTIF6 */
713 { USB_VPI(USB_VENDOR_YAMAHA, 0x1006, 0) }, /* MOTIF7 */
714 { USB_VPI(USB_VENDOR_YAMAHA, 0x1007, 0) }, /* MOTIF8 */
715 { USB_VPI(USB_VENDOR_YAMAHA, 0x1008, 0) }, /* UX96 */
716 { USB_VPI(USB_VENDOR_YAMAHA, 0x1009, 0) }, /* UX16 */
717 { USB_VPI(USB_VENDOR_YAMAHA, 0x100a, 3) }, /* EOS BX */
718 { USB_VPI(USB_VENDOR_YAMAHA, 0x100c, 0) }, /* UC-MX */
719 { USB_VPI(USB_VENDOR_YAMAHA, 0x100d, 0) }, /* UC-KX */
720 { USB_VPI(USB_VENDOR_YAMAHA, 0x100e, 0) }, /* S08 */
721 { USB_VPI(USB_VENDOR_YAMAHA, 0x100f, 0) }, /* CLP-150 */
722 { USB_VPI(USB_VENDOR_YAMAHA, 0x1010, 0) }, /* CLP-170 */
723 { USB_VPI(USB_VENDOR_YAMAHA, 0x1011, 0) }, /* P-250 */
724 { USB_VPI(USB_VENDOR_YAMAHA, 0x1012, 0) }, /* TYROS */
725 { USB_VPI(USB_VENDOR_YAMAHA, 0x1013, 0) }, /* PF-500 */
726 { USB_VPI(USB_VENDOR_YAMAHA, 0x1014, 0) }, /* S90 */
727 { USB_VPI(USB_VENDOR_YAMAHA, 0x1015, 0) }, /* MOTIF-R */
728 { USB_VPI(USB_VENDOR_YAMAHA, 0x1016, 0) }, /* MDP-5 */
729 { USB_VPI(USB_VENDOR_YAMAHA, 0x1017, 0) }, /* CVP-204 */
730 { USB_VPI(USB_VENDOR_YAMAHA, 0x1018, 0) }, /* CVP-206 */
731 { USB_VPI(USB_VENDOR_YAMAHA, 0x1019, 0) }, /* CVP-208 */
732 { USB_VPI(USB_VENDOR_YAMAHA, 0x101a, 0) }, /* CVP-210 */
733 { USB_VPI(USB_VENDOR_YAMAHA, 0x101b, 0) }, /* PSR-1100 */
734 { USB_VPI(USB_VENDOR_YAMAHA, 0x101c, 0) }, /* PSR-2100 */
735 { USB_VPI(USB_VENDOR_YAMAHA, 0x101d, 0) }, /* CLP-175 */
736 { USB_VPI(USB_VENDOR_YAMAHA, 0x101e, 0) }, /* PSR-K1 */
737 { USB_VPI(USB_VENDOR_YAMAHA, 0x101f, 0) }, /* EZ-J24 */
738 { USB_VPI(USB_VENDOR_YAMAHA, 0x1020, 0) }, /* EZ-250i */
739 { USB_VPI(USB_VENDOR_YAMAHA, 0x1021, 0) }, /* MOTIF ES 6 */
740 { USB_VPI(USB_VENDOR_YAMAHA, 0x1022, 0) }, /* MOTIF ES 7 */
741 { USB_VPI(USB_VENDOR_YAMAHA, 0x1023, 0) }, /* MOTIF ES 8 */
742 { USB_VPI(USB_VENDOR_YAMAHA, 0x1024, 0) }, /* CVP-301 */
743 { USB_VPI(USB_VENDOR_YAMAHA, 0x1025, 0) }, /* CVP-303 */
744 { USB_VPI(USB_VENDOR_YAMAHA, 0x1026, 0) }, /* CVP-305 */
745 { USB_VPI(USB_VENDOR_YAMAHA, 0x1027, 0) }, /* CVP-307 */
746 { USB_VPI(USB_VENDOR_YAMAHA, 0x1028, 0) }, /* CVP-309 */
747 { USB_VPI(USB_VENDOR_YAMAHA, 0x1029, 0) }, /* CVP-309GP */
748 { USB_VPI(USB_VENDOR_YAMAHA, 0x102a, 0) }, /* PSR-1500 */
749 { USB_VPI(USB_VENDOR_YAMAHA, 0x102b, 0) }, /* PSR-3000 */
750 { USB_VPI(USB_VENDOR_YAMAHA, 0x102e, 0) }, /* ELS-01/01C */
751 { USB_VPI(USB_VENDOR_YAMAHA, 0x1030, 0) }, /* PSR-295/293 */
752 { USB_VPI(USB_VENDOR_YAMAHA, 0x1031, 0) }, /* DGX-205/203 */
753 { USB_VPI(USB_VENDOR_YAMAHA, 0x1032, 0) }, /* DGX-305 */
754 { USB_VPI(USB_VENDOR_YAMAHA, 0x1033, 0) }, /* DGX-505 */
755 { USB_VPI(USB_VENDOR_YAMAHA, 0x1034, 0) }, /* NULL */
756 { USB_VPI(USB_VENDOR_YAMAHA, 0x1035, 0) }, /* NULL */
757 { USB_VPI(USB_VENDOR_YAMAHA, 0x1036, 0) }, /* NULL */
758 { USB_VPI(USB_VENDOR_YAMAHA, 0x1037, 0) }, /* NULL */
759 { USB_VPI(USB_VENDOR_YAMAHA, 0x1038, 0) }, /* NULL */
760 { USB_VPI(USB_VENDOR_YAMAHA, 0x1039, 0) }, /* NULL */
761 { USB_VPI(USB_VENDOR_YAMAHA, 0x103a, 0) }, /* NULL */
762 { USB_VPI(USB_VENDOR_YAMAHA, 0x103b, 0) }, /* NULL */
763 { USB_VPI(USB_VENDOR_YAMAHA, 0x103c, 0) }, /* NULL */
764 { USB_VPI(USB_VENDOR_YAMAHA, 0x103d, 0) }, /* NULL */
765 { USB_VPI(USB_VENDOR_YAMAHA, 0x103e, 0) }, /* NULL */
766 { USB_VPI(USB_VENDOR_YAMAHA, 0x103f, 0) }, /* NULL */
767 { USB_VPI(USB_VENDOR_YAMAHA, 0x1040, 0) }, /* NULL */
768 { USB_VPI(USB_VENDOR_YAMAHA, 0x1041, 0) }, /* NULL */
769 { USB_VPI(USB_VENDOR_YAMAHA, 0x1042, 0) }, /* NULL */
770 { USB_VPI(USB_VENDOR_YAMAHA, 0x1043, 0) }, /* NULL */
771 { USB_VPI(USB_VENDOR_YAMAHA, 0x1044, 0) }, /* NULL */
772 { USB_VPI(USB_VENDOR_YAMAHA, 0x1045, 0) }, /* NULL */
773 { USB_VPI(USB_VENDOR_YAMAHA, 0x104e, 0) }, /* NULL */
774 { USB_VPI(USB_VENDOR_YAMAHA, 0x104f, 0) }, /* NULL */
775 { USB_VPI(USB_VENDOR_YAMAHA, 0x1050, 0) }, /* NULL */
776 { USB_VPI(USB_VENDOR_YAMAHA, 0x1051, 0) }, /* NULL */
777 { USB_VPI(USB_VENDOR_YAMAHA, 0x1052, 0) }, /* NULL */
778 { USB_VPI(USB_VENDOR_YAMAHA, 0x1053, 0) }, /* NULL */
779 { USB_VPI(USB_VENDOR_YAMAHA, 0x1054, 0) }, /* NULL */
780 { USB_VPI(USB_VENDOR_YAMAHA, 0x1055, 0) }, /* NULL */
781 { USB_VPI(USB_VENDOR_YAMAHA, 0x1056, 0) }, /* NULL */
782 { USB_VPI(USB_VENDOR_YAMAHA, 0x1057, 0) }, /* NULL */
783 { USB_VPI(USB_VENDOR_YAMAHA, 0x1058, 0) }, /* NULL */
784 { USB_VPI(USB_VENDOR_YAMAHA, 0x1059, 0) }, /* NULL */
785 { USB_VPI(USB_VENDOR_YAMAHA, 0x105a, 0) }, /* NULL */
786 { USB_VPI(USB_VENDOR_YAMAHA, 0x105b, 0) }, /* NULL */
787 { USB_VPI(USB_VENDOR_YAMAHA, 0x105c, 0) }, /* NULL */
788 { USB_VPI(USB_VENDOR_YAMAHA, 0x105d, 0) }, /* NULL */
789 { USB_VPI(USB_VENDOR_YAMAHA, 0x1503, 3) }, /* MOX6/MOX8 */
790 { USB_VPI(USB_VENDOR_YAMAHA, 0x2000, 0) }, /* DGP-7 */
791 { USB_VPI(USB_VENDOR_YAMAHA, 0x2001, 0) }, /* DGP-5 */
792 { USB_VPI(USB_VENDOR_YAMAHA, 0x2002, 0) }, /* NULL */
793 { USB_VPI(USB_VENDOR_YAMAHA, 0x2003, 0) }, /* NULL */
794 { USB_VPI(USB_VENDOR_YAMAHA, 0x5000, 0) }, /* CS1D */
795 { USB_VPI(USB_VENDOR_YAMAHA, 0x5001, 0) }, /* DSP1D */
796 { USB_VPI(USB_VENDOR_YAMAHA, 0x5002, 0) }, /* DME32 */
797 { USB_VPI(USB_VENDOR_YAMAHA, 0x5003, 0) }, /* DM2000 */
798 { USB_VPI(USB_VENDOR_YAMAHA, 0x5004, 0) }, /* 02R96 */
799 { USB_VPI(USB_VENDOR_YAMAHA, 0x5005, 0) }, /* ACU16-C */
800 { USB_VPI(USB_VENDOR_YAMAHA, 0x5006, 0) }, /* NHB32-C */
801 { USB_VPI(USB_VENDOR_YAMAHA, 0x5007, 0) }, /* DM1000 */
802 { USB_VPI(USB_VENDOR_YAMAHA, 0x5008, 0) }, /* 01V96 */
803 { USB_VPI(USB_VENDOR_YAMAHA, 0x5009, 0) }, /* SPX2000 */
804 { USB_VPI(USB_VENDOR_YAMAHA, 0x500a, 0) }, /* PM5D */
805 { USB_VPI(USB_VENDOR_YAMAHA, 0x500b, 0) }, /* DME64N */
806 { USB_VPI(USB_VENDOR_YAMAHA, 0x500c, 0) }, /* DME24N */
807 { USB_VPI(USB_VENDOR_YAMAHA, 0x500d, 0) }, /* NULL */
808 { USB_VPI(USB_VENDOR_YAMAHA, 0x500e, 0) }, /* NULL */
809 { USB_VPI(USB_VENDOR_YAMAHA, 0x500f, 0) }, /* NULL */
810 { USB_VPI(USB_VENDOR_YAMAHA, 0x7000, 0) }, /* DTX */
811 { USB_VPI(USB_VENDOR_YAMAHA, 0x7010, 0) }, /* UB99 */
814 static const STRUCT_USB_HOST_ID __used uaudio_devs[] = {
815 /* Generic USB audio class match */
816 {USB_IFACE_CLASS(UICLASS_AUDIO),
817 USB_IFACE_SUBCLASS(UISUBCLASS_AUDIOCONTROL),},
818 /* Generic USB MIDI class match */
819 {USB_IFACE_CLASS(UICLASS_AUDIO),
820 USB_IFACE_SUBCLASS(UISUBCLASS_MIDISTREAM),},
824 uaudio_probe(device_t dev)
826 struct usb_attach_arg *uaa = device_get_ivars(dev);
828 if (uaa->usb_mode != USB_MODE_HOST)
831 /* lookup non-standard device(s) */
833 if (usbd_lookup_id_by_uaa(uaudio_vendor_midi,
834 sizeof(uaudio_vendor_midi), uaa) == 0) {
835 return (BUS_PROBE_SPECIFIC);
838 if (uaa->info.bInterfaceClass != UICLASS_AUDIO) {
839 if (uaa->info.bInterfaceClass != UICLASS_VENDOR ||
840 usb_test_quirk(uaa, UQ_AU_VENDOR_CLASS) == 0)
844 /* check for AUDIO control interface */
846 if (uaa->info.bInterfaceSubClass == UISUBCLASS_AUDIOCONTROL) {
847 if (usb_test_quirk(uaa, UQ_BAD_AUDIO))
850 return (BUS_PROBE_GENERIC);
853 /* check for MIDI stream */
855 if (uaa->info.bInterfaceSubClass == UISUBCLASS_MIDISTREAM) {
856 if (usb_test_quirk(uaa, UQ_BAD_MIDI))
859 return (BUS_PROBE_GENERIC);
865 uaudio_attach(device_t dev)
867 struct usb_attach_arg *uaa = device_get_ivars(dev);
868 struct uaudio_softc *sc = device_get_softc(dev);
869 struct usb_interface_descriptor *id;
873 sc->sc_play_chan.priv_sc = sc;
874 sc->sc_rec_chan.priv_sc = sc;
875 sc->sc_udev = uaa->device;
876 sc->sc_mixer_iface_index = uaa->info.bIfaceIndex;
877 sc->sc_mixer_iface_no = uaa->info.bIfaceNum;
878 sc->sc_config_msg[0].hdr.pm_callback = &uaudio_configure_msg;
879 sc->sc_config_msg[0].sc = sc;
880 sc->sc_config_msg[1].hdr.pm_callback = &uaudio_configure_msg;
881 sc->sc_config_msg[1].sc = sc;
883 if (usb_test_quirk(uaa, UQ_AUDIO_SWAP_LR))
884 sc->sc_uq_audio_swap_lr = 1;
886 if (usb_test_quirk(uaa, UQ_AU_INP_ASYNC))
887 sc->sc_uq_au_inp_async = 1;
889 if (usb_test_quirk(uaa, UQ_AU_NO_XU))
890 sc->sc_uq_au_no_xu = 1;
892 if (usb_test_quirk(uaa, UQ_BAD_ADC))
893 sc->sc_uq_bad_adc = 1;
895 if (usb_test_quirk(uaa, UQ_AU_VENDOR_CLASS))
896 sc->sc_uq_au_vendor_class = 1;
900 device_set_usb_desc(dev);
902 id = usbd_get_interface_descriptor(uaa->iface);
904 /* must fill mixer info before channel info */
905 uaudio_mixer_fill_info(sc, uaa->device, id);
907 /* fill channel info */
908 uaudio_chan_fill_info(sc, uaa->device);
910 DPRINTF("audio rev %d.%02x\n",
911 sc->sc_audio_rev >> 8,
912 sc->sc_audio_rev & 0xff);
914 if (sc->sc_mixer_count == 0) {
915 if (uaa->info.idVendor == USB_VENDOR_MAUDIO &&
916 (uaa->info.idProduct == USB_PRODUCT_MAUDIO_FASTTRACKULTRA ||
917 uaa->info.idProduct == USB_PRODUCT_MAUDIO_FASTTRACKULTRA8R)) {
918 DPRINTF("Generating mixer descriptors\n");
919 uaudio_mixer_controls_create_ftu(sc);
923 DPRINTF("%d mixer controls\n",
926 if (sc->sc_play_chan.num_alt > 0) {
930 * Need to set a default alternate interface, else
931 * some USB audio devices might go into an infinte
932 * re-enumeration loop:
934 err = usbd_set_alt_interface_index(sc->sc_udev,
935 sc->sc_play_chan.usb_alt[0].iface_index,
936 sc->sc_play_chan.usb_alt[0].iface_alt_index);
938 DPRINTF("setting of alternate index failed: %s!\n",
941 for (x = 0; x != sc->sc_play_chan.num_alt; x++) {
942 device_printf(dev, "Play: %d Hz, %d ch, %s format, "
944 sc->sc_play_chan.usb_alt[x].sample_rate,
945 sc->sc_play_chan.usb_alt[x].channels,
946 sc->sc_play_chan.usb_alt[x].p_fmt->description);
949 device_printf(dev, "No playback.\n");
952 if (sc->sc_rec_chan.num_alt > 0) {
956 * Need to set a default alternate interface, else
957 * some USB audio devices might go into an infinte
958 * re-enumeration loop:
960 err = usbd_set_alt_interface_index(sc->sc_udev,
961 sc->sc_rec_chan.usb_alt[0].iface_index,
962 sc->sc_rec_chan.usb_alt[0].iface_alt_index);
964 DPRINTF("setting of alternate index failed: %s!\n",
967 for (x = 0; x != sc->sc_rec_chan.num_alt; x++) {
968 device_printf(dev, "Record: %d Hz, %d ch, %s format, "
970 sc->sc_rec_chan.usb_alt[x].sample_rate,
971 sc->sc_rec_chan.usb_alt[x].channels,
972 sc->sc_rec_chan.usb_alt[x].p_fmt->description);
975 device_printf(dev, "No recording.\n");
978 if (sc->sc_midi_chan.valid == 0) {
979 if (usbd_lookup_id_by_uaa(uaudio_vendor_midi,
980 sizeof(uaudio_vendor_midi), uaa) == 0) {
981 sc->sc_midi_chan.iface_index =
982 (uint8_t)uaa->driver_info;
983 sc->sc_midi_chan.iface_alt_index = 0;
984 sc->sc_midi_chan.valid = 1;
988 if (sc->sc_midi_chan.valid) {
990 if (umidi_probe(dev)) {
993 device_printf(dev, "MIDI sequencer.\n");
995 device_printf(dev, "No MIDI sequencer.\n");
998 DPRINTF("doing child attach\n");
1000 /* attach the children */
1002 sc->sc_sndcard_func.func = SCF_PCM;
1005 * Only attach a PCM device if we have a playback, recording
1006 * or mixer device present:
1008 if (sc->sc_play_chan.num_alt > 0 ||
1009 sc->sc_rec_chan.num_alt > 0 ||
1011 child = device_add_child(dev, "pcm", -1);
1013 if (child == NULL) {
1014 DPRINTF("out of memory\n");
1017 device_set_ivars(child, &sc->sc_sndcard_func);
1020 if (bus_generic_attach(dev)) {
1021 DPRINTF("child attach failed\n");
1025 if (uaudio_hid_probe(sc, uaa) == 0) {
1026 device_printf(dev, "HID volume keys found.\n");
1028 device_printf(dev, "No HID volume keys found.\n");
1031 /* reload all mixer settings */
1032 uaudio_mixer_reload_all(sc);
1034 return (0); /* success */
1042 uaudio_pcm_setflags(device_t dev, uint32_t flags)
1044 pcm_setflags(dev, pcm_getflags(dev) | flags);
1048 uaudio_attach_sub(device_t dev, kobj_class_t mixer_class, kobj_class_t chan_class)
1050 struct uaudio_softc *sc = device_get_softc(device_get_parent(dev));
1051 char status[SND_STATUSLEN];
1053 uaudio_mixer_init(sc);
1055 if (sc->sc_uq_audio_swap_lr) {
1056 DPRINTF("hardware has swapped left and right\n");
1057 /* uaudio_pcm_setflags(dev, SD_F_PSWAPLR); */
1059 if (!(sc->sc_mix_info & SOUND_MASK_PCM)) {
1061 DPRINTF("emulating master volume\n");
1064 * Emulate missing pcm mixer controller
1065 * through FEEDER_VOLUME
1067 uaudio_pcm_setflags(dev, SD_F_SOFTPCMVOL);
1069 if (sc->sc_pcm_bitperfect) {
1070 DPRINTF("device needs bitperfect by default\n");
1071 uaudio_pcm_setflags(dev, SD_F_BITPERFECT);
1073 if (mixer_init(dev, mixer_class, sc))
1075 sc->sc_mixer_init = 1;
1077 mixer_hwvol_init(dev);
1079 snprintf(status, sizeof(status), "at ? %s", PCM_KLDSTRING(snd_uaudio));
1081 if (pcm_register(dev, sc,
1082 (sc->sc_play_chan.num_alt > 0) ? 1 : 0,
1083 (sc->sc_rec_chan.num_alt > 0) ? 1 : 0)) {
1087 uaudio_pcm_setflags(dev, SD_F_MPSAFE);
1088 sc->sc_pcm_registered = 1;
1090 if (sc->sc_play_chan.num_alt > 0) {
1091 pcm_addchan(dev, PCMDIR_PLAY, chan_class, sc);
1093 if (sc->sc_rec_chan.num_alt > 0) {
1094 pcm_addchan(dev, PCMDIR_REC, chan_class, sc);
1096 pcm_setstatus(dev, status);
1098 uaudio_mixer_register_sysctl(sc, dev);
1100 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
1101 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1102 "feedback_rate", CTLFLAG_RD, &sc->sc_play_chan.feedback_rate,
1103 0, "Feedback sample rate in Hz");
1105 return (0); /* success */
1108 uaudio_detach_sub(dev);
1113 uaudio_detach_sub(device_t dev)
1115 struct uaudio_softc *sc = device_get_softc(device_get_parent(dev));
1119 if (sc->sc_pcm_registered) {
1120 error = pcm_unregister(dev);
1122 if (sc->sc_mixer_init) {
1123 error = mixer_uninit(dev);
1128 device_printf(dev, "Waiting for sound application to exit!\n");
1129 usb_pause_mtx(NULL, 2 * hz);
1130 goto repeat; /* try again */
1132 return (0); /* success */
1136 uaudio_detach(device_t dev)
1138 struct uaudio_softc *sc = device_get_softc(dev);
1141 * Stop USB transfers early so that any audio applications
1142 * will time out and close opened /dev/dspX.Y device(s), if
1145 usb_proc_explore_lock(sc->sc_udev);
1146 sc->sc_play_chan.operation = CHAN_OP_DRAIN;
1147 sc->sc_rec_chan.operation = CHAN_OP_DRAIN;
1148 usb_proc_explore_mwait(sc->sc_udev,
1149 &sc->sc_config_msg[0], &sc->sc_config_msg[1]);
1150 usb_proc_explore_unlock(sc->sc_udev);
1152 usbd_transfer_unsetup(sc->sc_play_chan.xfer, UAUDIO_NCHANBUFS + 1);
1153 usbd_transfer_unsetup(sc->sc_rec_chan.xfer, UAUDIO_NCHANBUFS + 1);
1155 uaudio_hid_detach(sc);
1157 if (bus_generic_detach(dev) != 0) {
1158 DPRINTF("detach failed!\n");
1160 sbuf_delete(&sc->sc_sndstat);
1161 sc->sc_sndstat_valid = 0;
1165 /* free mixer data */
1167 uaudio_mixer_ctl_free(sc);
1173 uaudio_get_buffer_size(struct uaudio_chan *ch, uint8_t alt)
1175 struct uaudio_chan_alt *chan_alt = &ch->usb_alt[alt];
1176 /* We use 2 times 8ms of buffer */
1177 uint32_t buf_size = chan_alt->sample_size *
1178 howmany(chan_alt->sample_rate * (UAUDIO_NFRAMES / 8), 1000);
1183 uaudio_configure_msg_sub(struct uaudio_softc *sc,
1184 struct uaudio_chan *chan, int dir)
1186 struct uaudio_chan_alt *chan_alt;
1195 if (chan->num_alt <= 0)
1200 usb_proc_explore_lock(sc->sc_udev);
1201 operation = chan->operation;
1202 chan->operation = CHAN_OP_NONE;
1203 usb_proc_explore_unlock(sc->sc_udev);
1205 mtx_lock(chan->pcm_mtx);
1206 if (chan->cur_alt != chan->set_alt)
1207 set_alt = chan->set_alt;
1209 set_alt = CHAN_MAX_ALT;
1210 mtx_unlock(chan->pcm_mtx);
1212 if (set_alt >= chan->num_alt)
1215 chan_alt = chan->usb_alt + set_alt;
1217 usbd_transfer_unsetup(chan->xfer, UAUDIO_NCHANBUFS + 1);
1219 err = usbd_set_alt_interface_index(sc->sc_udev,
1220 chan_alt->iface_index, chan_alt->iface_alt_index);
1222 DPRINTF("setting of alternate index failed: %s!\n",
1228 * Only set the sample rate if the channel reports that it
1229 * supports the frequency control.
1232 if (sc->sc_audio_rev >= UAUDIO_VERSION_30) {
1234 } else if (sc->sc_audio_rev >= UAUDIO_VERSION_20) {
1237 for (x = 0; x != 256; x++) {
1238 if (dir == PCMDIR_PLAY) {
1239 if (!(sc->sc_mixer_clocks.bit_output[x / 8] &
1244 if (!(sc->sc_mixer_clocks.bit_input[x / 8] &
1250 if (uaudio20_set_speed(sc->sc_udev,
1251 sc->sc_mixer_iface_no, x, chan_alt->sample_rate)) {
1253 * If the endpoint is adaptive setting
1254 * the speed may fail.
1256 DPRINTF("setting of sample rate failed! "
1257 "(continuing anyway)\n");
1260 } else if (chan_alt->p_sed.v1->bmAttributes & UA_SED_FREQ_CONTROL) {
1261 if (uaudio_set_speed(sc->sc_udev,
1262 chan_alt->p_ed1->bEndpointAddress, chan_alt->sample_rate)) {
1264 * If the endpoint is adaptive setting the
1267 DPRINTF("setting of sample rate failed! "
1268 "(continuing anyway)\n");
1271 if (usbd_transfer_setup(sc->sc_udev, &chan_alt->iface_index, chan->xfer,
1272 chan_alt->usb_cfg, UAUDIO_NCHANBUFS + 1, chan, chan->pcm_mtx)) {
1273 DPRINTF("could not allocate USB transfers!\n");
1277 fps = usbd_get_isoc_fps(sc->sc_udev);
1280 /* FULL speed USB */
1283 /* HIGH speed USB */
1284 frames = UAUDIO_NFRAMES;
1287 fps_shift = usbd_xfer_get_fps_shift(chan->xfer[0]);
1289 /* down shift number of frames per second, if any */
1291 frames >>= fps_shift;
1293 /* bytes per frame should not be zero */
1294 chan->bytes_per_frame[0] =
1295 ((chan_alt->sample_rate / fps) * chan_alt->sample_size);
1296 chan->bytes_per_frame[1] = howmany(chan_alt->sample_rate, fps) *
1297 chan_alt->sample_size;
1299 /* setup data rate dithering, if any */
1300 chan->frames_per_second = fps;
1301 chan->sample_rem = chan_alt->sample_rate % fps;
1302 chan->sample_curr = 0;
1304 /* compute required buffer size */
1305 buf_size = (chan->bytes_per_frame[1] * frames);
1307 if (buf_size > (chan->end - chan->start)) {
1308 DPRINTF("buffer size is too big\n");
1312 chan->intr_frames = frames;
1314 DPRINTF("fps=%d sample_rem=%d\n", (int)fps, (int)chan->sample_rem);
1316 if (chan->intr_frames == 0) {
1317 DPRINTF("frame shift is too high!\n");
1321 mtx_lock(chan->pcm_mtx);
1322 chan->cur_alt = set_alt;
1323 mtx_unlock(chan->pcm_mtx);
1326 #if (UAUDIO_NCHANBUFS != 2)
1327 #error "please update code"
1329 switch (operation) {
1331 mtx_lock(chan->pcm_mtx);
1332 usbd_transfer_start(chan->xfer[0]);
1333 usbd_transfer_start(chan->xfer[1]);
1334 mtx_unlock(chan->pcm_mtx);
1337 mtx_lock(chan->pcm_mtx);
1338 usbd_transfer_stop(chan->xfer[0]);
1339 usbd_transfer_stop(chan->xfer[1]);
1340 mtx_unlock(chan->pcm_mtx);
1348 usbd_transfer_unsetup(chan->xfer, UAUDIO_NCHANBUFS + 1);
1350 mtx_lock(chan->pcm_mtx);
1351 chan->cur_alt = CHAN_MAX_ALT;
1352 mtx_unlock(chan->pcm_mtx);
1356 uaudio_configure_msg(struct usb_proc_msg *pm)
1358 struct uaudio_softc *sc = ((struct uaudio_configure_msg *)pm)->sc;
1360 usb_proc_explore_unlock(sc->sc_udev);
1361 uaudio_configure_msg_sub(sc, &sc->sc_play_chan, PCMDIR_PLAY);
1362 uaudio_configure_msg_sub(sc, &sc->sc_rec_chan, PCMDIR_REC);
1363 usb_proc_explore_lock(sc->sc_udev);
1366 /*========================================================================*
1367 * AS - Audio Stream - routines
1368 *========================================================================*/
1372 uaudio_chan_dump_ep_desc(const usb_endpoint_descriptor_audio_t *ed)
1375 DPRINTF("endpoint=%p bLength=%d bDescriptorType=%d \n"
1376 "bEndpointAddress=%d bmAttributes=0x%x \n"
1377 "wMaxPacketSize=%d bInterval=%d \n"
1378 "bRefresh=%d bSynchAddress=%d\n",
1379 ed, ed->bLength, ed->bDescriptorType,
1380 ed->bEndpointAddress, ed->bmAttributes,
1381 UGETW(ed->wMaxPacketSize), ed->bInterval,
1382 UEP_HAS_REFRESH(ed) ? ed->bRefresh : 0,
1383 UEP_HAS_SYNCADDR(ed) ? ed->bSynchAddress : 0);
1390 * The following is a workaround for broken no-name USB audio devices
1391 * sold by dealextreme called "3D sound". The problem is that the
1392 * manufacturer computed wMaxPacketSize is too small to hold the
1393 * actual data sent. In other words the device sometimes sends more
1394 * data than it actually reports it can send in a single isochronous
1398 uaudio_record_fix_fs(usb_endpoint_descriptor_audio_t *ep,
1399 uint32_t xps, uint32_t add)
1403 mps = UGETW(ep->wMaxPacketSize);
1406 * If the device indicates it can send more data than what the
1407 * sample rate indicates, we apply the workaround.
1411 /* allow additional data */
1414 /* check against the maximum USB 1.x length */
1418 /* check if we should do an update */
1420 /* simply update the wMaxPacketSize field */
1421 USETW(ep->wMaxPacketSize, xps);
1422 DPRINTF("Workaround: Updated wMaxPacketSize "
1423 "from %d to %d bytes.\n",
1424 (int)mps, (int)xps);
1430 uaudio20_check_rate(struct usb_device *udev, uint8_t iface_no,
1431 uint8_t clockid, uint32_t rate)
1433 struct usb_device_request req;
1440 DPRINTFN(6, "ifaceno=%d clockid=%d rate=%u\n",
1441 iface_no, clockid, rate);
1443 req.bmRequestType = UT_READ_CLASS_INTERFACE;
1444 req.bRequest = UA20_CS_RANGE;
1445 USETW2(req.wValue, UA20_CS_SAM_FREQ_CONTROL, 0);
1446 USETW2(req.wIndex, clockid, iface_no);
1447 USETW(req.wLength, 255);
1449 error = usbd_do_request_flags(udev, NULL, &req, data,
1450 USB_SHORT_XFER_OK, &actlen, USB_DEFAULT_TIMEOUT);
1452 if (error != 0 || actlen < 2)
1453 return (USB_ERR_INVAL);
1455 rates = data[0] | (data[1] << 8);
1456 actlen = (actlen - 2) / 12;
1458 if (rates > actlen) {
1459 DPRINTF("Too many rates\n");
1463 for (x = 0; x != rates; x++) {
1464 uint32_t min = UGETDW(data + 2 + (12 * x));
1465 uint32_t max = UGETDW(data + 6 + (12 * x));
1466 uint32_t res = UGETDW(data + 10 + (12 * x));
1469 DPRINTF("Zero residue\n");
1474 DPRINTF("Swapped max and min\n");
1481 if (rate >= min && rate <= max &&
1482 (((rate - min) % res) == 0)) {
1486 return (USB_ERR_INVAL);
1490 uaudio_chan_fill_info_sub(struct uaudio_softc *sc, struct usb_device *udev,
1491 uint32_t rate, uint8_t channels, uint8_t bit_resolution)
1493 struct usb_descriptor *desc = NULL;
1494 union uaudio_asid asid = { NULL };
1495 union uaudio_asf1d asf1d = { NULL };
1496 union uaudio_sed sed = { NULL };
1497 struct usb_midi_streaming_endpoint_descriptor *msid = NULL;
1498 usb_endpoint_descriptor_audio_t *ed1 = NULL;
1499 const struct usb_audio_control_descriptor *acdp = NULL;
1500 struct usb_config_descriptor *cd = usbd_get_config_descriptor(udev);
1501 struct usb_interface_descriptor *id;
1502 const struct uaudio_format *p_fmt = NULL;
1503 struct uaudio_chan *chan;
1504 struct uaudio_chan_alt *chan_alt;
1506 uint16_t curidx = 0xFFFF;
1507 uint16_t lastidx = 0xFFFF;
1508 uint16_t alt_index = 0;
1509 uint16_t audio_rev = 0;
1513 uint8_t bBitResolution;
1514 uint8_t audio_if = 0;
1515 uint8_t midi_if = 0;
1516 uint8_t uma_if_class;
1518 while ((desc = usb_desc_foreach(cd, desc))) {
1520 if ((desc->bDescriptorType == UDESC_INTERFACE) &&
1521 (desc->bLength >= sizeof(*id))) {
1525 if (id->bInterfaceNumber != lastidx) {
1526 lastidx = id->bInterfaceNumber;
1534 if ((!(sc->sc_hid.flags & UAUDIO_HID_VALID)) &&
1535 (id->bInterfaceClass == UICLASS_HID) &&
1536 (id->bInterfaceSubClass == 0) &&
1537 (id->bInterfaceProtocol == 0) &&
1539 usbd_get_iface(udev, curidx) != NULL) {
1540 DPRINTF("Found HID interface at %d\n",
1542 sc->sc_hid.flags |= UAUDIO_HID_VALID;
1543 sc->sc_hid.iface_index = curidx;
1547 ((id->bInterfaceClass == UICLASS_AUDIO) ||
1548 ((id->bInterfaceClass == UICLASS_VENDOR) &&
1549 (sc->sc_uq_au_vendor_class != 0)));
1551 if ((uma_if_class != 0) &&
1552 (id->bInterfaceSubClass == UISUBCLASS_AUDIOSTREAM)) {
1558 if ((uma_if_class != 0) &&
1559 (id->bInterfaceSubClass == UISUBCLASS_MIDISTREAM)) {
1562 * XXX could allow multiple MIDI interfaces
1566 if ((sc->sc_midi_chan.valid == 0) &&
1567 (usbd_get_iface(udev, curidx) != NULL)) {
1568 sc->sc_midi_chan.iface_index = curidx;
1569 sc->sc_midi_chan.iface_alt_index = alt_index;
1570 sc->sc_midi_chan.valid = 1;
1581 * There can only be one USB audio instance
1582 * per USB device. Grab all USB audio
1583 * interfaces on this USB device so that we
1584 * don't attach USB audio twice:
1586 if (alt_index == 0 && curidx != sc->sc_mixer_iface_index &&
1587 (id->bInterfaceClass == UICLASS_AUDIO || audio_if != 0 ||
1589 usbd_set_parent_iface(sc->sc_udev, curidx,
1590 sc->sc_mixer_iface_index);
1594 if (audio_if == 0) {
1596 if ((acdp == NULL) &&
1597 (desc->bDescriptorType == UDESC_CS_INTERFACE) &&
1598 (desc->bDescriptorSubtype == UDESCSUB_AC_HEADER) &&
1599 (desc->bLength >= sizeof(*acdp))) {
1600 acdp = (void *)desc;
1601 audio_rev = UGETW(acdp->bcdADC);
1604 msid = (void *)desc;
1606 /* get the maximum number of embedded jacks in use, if any */
1607 if (msid->bLength >= sizeof(*msid) &&
1608 msid->bDescriptorType == UDESC_CS_ENDPOINT &&
1609 msid->bDescriptorSubtype == MS_GENERAL &&
1610 msid->bNumEmbMIDIJack > sc->sc_midi_chan.max_emb_jack) {
1611 sc->sc_midi_chan.max_emb_jack = msid->bNumEmbMIDIJack;
1615 * Don't collect any USB audio descriptors if
1616 * this is not an USB audio stream interface.
1621 if ((acdp != NULL) &&
1622 (desc->bDescriptorType == UDESC_CS_INTERFACE) &&
1623 (desc->bDescriptorSubtype == AS_GENERAL) &&
1624 (asid.v1 == NULL)) {
1625 if (audio_rev >= UAUDIO_VERSION_30) {
1627 } else if (audio_rev >= UAUDIO_VERSION_20) {
1628 if (desc->bLength >= sizeof(*asid.v2)) {
1629 asid.v2 = (void *)desc;
1632 if (desc->bLength >= sizeof(*asid.v1)) {
1633 asid.v1 = (void *)desc;
1637 if ((acdp != NULL) &&
1638 (desc->bDescriptorType == UDESC_CS_INTERFACE) &&
1639 (desc->bDescriptorSubtype == FORMAT_TYPE) &&
1640 (asf1d.v1 == NULL)) {
1641 if (audio_rev >= UAUDIO_VERSION_30) {
1643 } else if (audio_rev >= UAUDIO_VERSION_20) {
1644 if (desc->bLength >= sizeof(*asf1d.v2))
1645 asf1d.v2 = (void *)desc;
1647 if (desc->bLength >= sizeof(*asf1d.v1)) {
1648 asf1d.v1 = (void *)desc;
1650 if (asf1d.v1->bFormatType != FORMAT_TYPE_I) {
1651 DPRINTFN(11, "ignored bFormatType = %d\n",
1652 asf1d.v1->bFormatType);
1656 if (desc->bLength < (sizeof(*asf1d.v1) +
1657 ((asf1d.v1->bSamFreqType == 0) ? 6 :
1658 (asf1d.v1->bSamFreqType * 3)))) {
1659 DPRINTFN(11, "invalid descriptor, "
1667 if ((desc->bDescriptorType == UDESC_ENDPOINT) &&
1668 (desc->bLength >= UEP_MINSIZE) &&
1671 if (UE_GET_XFERTYPE(ed1->bmAttributes) != UE_ISOCHRONOUS) {
1676 if ((acdp != NULL) &&
1677 (desc->bDescriptorType == UDESC_CS_ENDPOINT) &&
1678 (desc->bDescriptorSubtype == AS_GENERAL) &&
1680 if (audio_rev >= UAUDIO_VERSION_30) {
1682 } else if (audio_rev >= UAUDIO_VERSION_20) {
1683 if (desc->bLength >= sizeof(*sed.v2))
1684 sed.v2 = (void *)desc;
1686 if (desc->bLength >= sizeof(*sed.v1))
1687 sed.v1 = (void *)desc;
1690 if (asid.v1 == NULL || asf1d.v1 == NULL ||
1691 ed1 == NULL || sed.v1 == NULL) {
1692 /* need more descriptors */
1696 ep_dir = UE_GET_DIR(ed1->bEndpointAddress);
1698 /* We ignore sync endpoint information until further. */
1700 if (audio_rev >= UAUDIO_VERSION_30) {
1702 } else if (audio_rev >= UAUDIO_VERSION_20) {
1706 dwFormat = UGETDW(asid.v2->bmFormats);
1707 bChannels = asid.v2->bNrChannels;
1708 bBitResolution = asf1d.v2->bSubslotSize * 8;
1710 if ((bChannels != channels) ||
1711 (bBitResolution != bit_resolution)) {
1712 DPRINTF("Wrong number of channels\n");
1716 for (p_fmt = uaudio20_formats;
1717 p_fmt->wFormat != 0; p_fmt++) {
1718 if ((p_fmt->wFormat & dwFormat) &&
1719 (p_fmt->bPrecision == bBitResolution))
1723 if (p_fmt->wFormat == 0) {
1724 DPRINTF("Unsupported audio format\n");
1728 for (x = 0; x != 256; x++) {
1729 if (ep_dir == UE_DIR_OUT) {
1730 if (!(sc->sc_mixer_clocks.bit_output[x / 8] &
1735 if (!(sc->sc_mixer_clocks.bit_input[x / 8] &
1741 DPRINTF("Checking clock ID=%d\n", x);
1743 if (uaudio20_check_rate(udev,
1744 sc->sc_mixer_iface_no, x, rate)) {
1745 DPRINTF("Unsupported sampling "
1746 "rate, id=%d\n", x);
1753 wFormat = UGETW(asid.v1->wFormatTag);
1754 bChannels = UAUDIO_MAX_CHAN(asf1d.v1->bNrChannels);
1755 bBitResolution = asf1d.v1->bSubFrameSize * 8;
1757 if (asf1d.v1->bSamFreqType == 0) {
1758 DPRINTFN(16, "Sample rate: %d-%dHz\n",
1759 UA_SAMP_LO(asf1d.v1),
1760 UA_SAMP_HI(asf1d.v1));
1762 if ((rate >= UA_SAMP_LO(asf1d.v1)) &&
1763 (rate <= UA_SAMP_HI(asf1d.v1)))
1767 for (x = 0; x < asf1d.v1->bSamFreqType; x++) {
1768 DPRINTFN(16, "Sample rate = %dHz\n",
1769 UA_GETSAMP(asf1d.v1, x));
1771 if (rate == UA_GETSAMP(asf1d.v1, x))
1778 for (p_fmt = uaudio10_formats;
1779 p_fmt->wFormat != 0; p_fmt++) {
1780 if ((p_fmt->wFormat == wFormat) &&
1781 (p_fmt->bPrecision == bBitResolution))
1784 if (p_fmt->wFormat == 0) {
1785 DPRINTF("Unsupported audio format\n");
1789 if ((bChannels != channels) ||
1790 (bBitResolution != bit_resolution)) {
1791 DPRINTF("Wrong number of channels\n");
1796 chan = (ep_dir == UE_DIR_IN) ?
1797 &sc->sc_rec_chan : &sc->sc_play_chan;
1799 if (usbd_get_iface(udev, curidx) == NULL) {
1800 DPRINTF("Interface is not valid\n");
1803 if (chan->num_alt == CHAN_MAX_ALT) {
1804 DPRINTF("Too many alternate settings\n");
1808 chan->cur_alt = CHAN_MAX_ALT;
1810 chan_alt = &chan->usb_alt[chan->num_alt++];
1813 uaudio_chan_dump_ep_desc(ed1);
1815 DPRINTF("Sample rate = %dHz, channels = %d, "
1816 "bits = %d, format = %s\n", rate, channels,
1817 bit_resolution, p_fmt->description);
1819 chan_alt->sample_rate = rate;
1820 chan_alt->p_asf1d = asf1d;
1821 chan_alt->p_ed1 = ed1;
1822 chan_alt->p_fmt = p_fmt;
1823 chan_alt->p_sed = sed;
1824 chan_alt->iface_index = curidx;
1825 chan_alt->iface_alt_index = alt_index;
1827 if (ep_dir == UE_DIR_IN)
1828 chan_alt->usb_cfg = uaudio_cfg_record;
1830 chan_alt->usb_cfg = uaudio_cfg_play;
1832 chan_alt->sample_size = (UAUDIO_MAX_CHAN(channels) *
1833 p_fmt->bPrecision) / 8;
1834 chan_alt->channels = channels;
1836 if (ep_dir == UE_DIR_IN &&
1837 usbd_get_speed(udev) == USB_SPEED_FULL) {
1838 uaudio_record_fix_fs(ed1,
1839 chan_alt->sample_size * (rate / 1000),
1840 chan_alt->sample_size * (rate / 4000));
1843 /* setup play/record format */
1845 format = chan_alt->p_fmt->freebsd_fmt;
1847 /* get default SND_FORMAT() */
1848 format = SND_FORMAT(format, chan_alt->channels, 0);
1850 switch (chan_alt->channels) {
1854 /* mono and stereo */
1857 /* surround and more */
1858 temp_fmt = feeder_matrix_default_format(format);
1859 /* if multichannel, then format can be zero */
1865 /* check if format is not supported */
1867 DPRINTF("The selected audio format is not supported\n");
1871 if (chan->num_alt > 1) {
1872 /* we only accumulate one format at different sample rates */
1873 if (chan->pcm_format[0] != format) {
1874 DPRINTF("Multiple formats is not supported\n");
1878 /* ignore if duplicate sample rate entry */
1879 if (rate == chan->usb_alt[chan->num_alt - 2].sample_rate) {
1880 DPRINTF("Duplicate sample rate detected\n");
1885 chan->pcm_cap.fmtlist = chan->pcm_format;
1886 chan->pcm_cap.fmtlist[0] = format;
1888 /* check if device needs bitperfect */
1889 if (chan_alt->channels > UAUDIO_MATRIX_MAX)
1890 sc->sc_pcm_bitperfect = 1;
1892 if (rate < chan->pcm_cap.minspeed || chan->pcm_cap.minspeed == 0)
1893 chan->pcm_cap.minspeed = rate;
1894 if (rate > chan->pcm_cap.maxspeed || chan->pcm_cap.maxspeed == 0)
1895 chan->pcm_cap.maxspeed = rate;
1897 if (sc->sc_sndstat_valid != 0) {
1898 sbuf_printf(&sc->sc_sndstat, "\n\t"
1899 "mode %d.%d:(%s) %dch, %dbit, %s, %dHz",
1901 (ep_dir == UE_DIR_IN) ? "input" : "output",
1902 channels, p_fmt->bPrecision,
1903 p_fmt->description, rate);
1912 /* This structure defines all the supported rates. */
1914 static const uint32_t uaudio_rate_list[CHAN_MAX_ALT] = {
1939 uaudio_chan_fill_info(struct uaudio_softc *sc, struct usb_device *udev)
1941 uint32_t rate = uaudio_default_rate;
1943 uint8_t bits = uaudio_default_bits;
1945 uint8_t channels = uaudio_default_channels;
1949 if ((bits == 0) || (bits > 32)) {
1950 /* set a valid value */
1953 if (channels == 0) {
1954 switch (usbd_get_speed(udev)) {
1956 case USB_SPEED_FULL:
1958 * Due to high bandwidth usage and problems
1959 * with HIGH-speed split transactions we
1960 * disable surround setups on FULL-speed USB
1966 channels = UAUDIO_CHANNELS_MAX;
1969 } else if (channels > UAUDIO_CHANNELS_MAX)
1970 channels = UAUDIO_CHANNELS_MAX;
1972 if (sbuf_new(&sc->sc_sndstat, NULL, 4096, SBUF_AUTOEXTEND))
1973 sc->sc_sndstat_valid = 1;
1975 /* try to search for a valid config */
1977 for (x = channels; x; x--) {
1978 for (y = bits; y; y -= 8) {
1980 /* try user defined rate, if any */
1982 uaudio_chan_fill_info_sub(sc, udev, rate, x, y);
1984 /* try find a matching rate, if any */
1985 for (z = 0; uaudio_rate_list[z]; z++)
1986 uaudio_chan_fill_info_sub(sc, udev, uaudio_rate_list[z], x, y);
1989 if (sc->sc_sndstat_valid)
1990 sbuf_finish(&sc->sc_sndstat);
1994 uaudio_chan_play_sync_callback(struct usb_xfer *xfer, usb_error_t error)
1996 struct uaudio_chan *ch = usbd_xfer_softc(xfer);
1997 struct usb_page_cache *pc;
1998 uint64_t sample_rate;
2005 usbd_xfer_status(xfer, &actlen, NULL, NULL, &nframes);
2007 switch (USB_GET_STATE(xfer)) {
2008 case USB_ST_TRANSFERRED:
2010 DPRINTFN(6, "transferred %d bytes\n", actlen);
2014 len = usbd_xfer_frame_len(xfer, 0);
2017 if (len > sizeof(buf))
2020 memset(buf, 0, sizeof(buf));
2022 pc = usbd_xfer_get_frame(xfer, 0);
2023 usbd_copy_out(pc, 0, buf, len);
2027 DPRINTF("Value = 0x%08x\n", (int)temp);
2029 /* auto-detect SYNC format */
2034 /* check for no data */
2041 sample_rate = ch->usb_alt[ch->cur_alt].sample_rate;
2044 while (temp < (sample_rate - (sample_rate / 4)))
2047 while (temp > (sample_rate + (sample_rate / 2)))
2050 DPRINTF("Comparing %d Hz :: %d Hz\n",
2051 (int)temp, (int)sample_rate);
2054 * Use feedback value as fallback when there is no
2055 * recording channel:
2057 if (ch->priv_sc->sc_rec_chan.num_alt == 0)
2058 ch->jitter_curr = temp - sample_rate;
2060 ch->feedback_rate = temp;
2064 usbd_xfer_set_frames(xfer, 1);
2065 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_framelen(xfer));
2066 usbd_transfer_submit(xfer);
2069 default: /* Error */
2075 uaudio_chan_is_async(struct uaudio_chan *ch, uint8_t alt)
2077 uint8_t attr = ch->usb_alt[alt].p_ed1->bmAttributes;
2078 return (UE_GET_ISO_TYPE(attr) == UE_ISO_ASYNC);
2082 uaudio_chan_play_callback(struct usb_xfer *xfer, usb_error_t error)
2084 struct uaudio_chan *ch = usbd_xfer_softc(xfer);
2085 struct uaudio_chan *ch_rec;
2086 struct usb_page_cache *pc;
2089 uint32_t blockcount;
2096 if (ch->running == 0 || ch->start == ch->end) {
2097 DPRINTF("not running or no buffer!\n");
2101 /* check if there is a record channel */
2102 if (ch->priv_sc->sc_rec_chan.num_alt > 0)
2103 ch_rec = &ch->priv_sc->sc_rec_chan;
2107 usbd_xfer_status(xfer, &actlen, &sumlen, NULL, NULL);
2109 switch (USB_GET_STATE(xfer)) {
2112 if (ch_rec != NULL) {
2113 /* reset receive jitter counters */
2114 mtx_lock(ch_rec->pcm_mtx);
2115 ch_rec->jitter_curr = 0;
2116 ch_rec->jitter_rem = 0;
2117 mtx_unlock(ch_rec->pcm_mtx);
2120 /* reset transmit jitter counters */
2121 ch->jitter_curr = 0;
2125 case USB_ST_TRANSFERRED:
2126 if (actlen < sumlen) {
2127 DPRINTF("short transfer, "
2128 "%d of %d bytes\n", actlen, sumlen);
2130 chn_intr(ch->pcm_ch);
2133 * Check for asynchronous playback endpoint and that
2134 * the playback endpoint is properly configured:
2136 if (ch_rec != NULL &&
2137 uaudio_chan_is_async(ch, ch->cur_alt) != 0) {
2138 mtx_lock(ch_rec->pcm_mtx);
2139 if (ch_rec->cur_alt < ch_rec->num_alt) {
2143 /* translate receive jitter into transmit jitter */
2144 tx_jitter = ch->usb_alt[ch->cur_alt].sample_rate;
2145 tx_jitter = (tx_jitter * ch_rec->jitter_curr) +
2148 /* reset receive jitter counters */
2149 ch_rec->jitter_curr = 0;
2150 ch_rec->jitter_rem = 0;
2152 /* compute exact number of transmit jitter samples */
2153 rx_rate = ch_rec->usb_alt[ch_rec->cur_alt].sample_rate;
2154 ch->jitter_curr += tx_jitter / rx_rate;
2155 ch->jitter_rem = tx_jitter % rx_rate;
2157 mtx_unlock(ch_rec->pcm_mtx);
2160 /* start the SYNC transfer one time per second, if any */
2161 if (++(ch->intr_counter) >= UAUDIO_IRQS) {
2162 ch->intr_counter = 0;
2163 usbd_transfer_start(ch->xfer[UAUDIO_NCHANBUFS]);
2166 mfl = usbd_xfer_max_framelen(xfer);
2168 if (ch->bytes_per_frame[1] > mfl) {
2169 DPRINTF("bytes per transfer, %d, "
2170 "exceeds maximum, %d!\n",
2171 ch->bytes_per_frame[1],
2176 blockcount = ch->intr_frames;
2178 /* setup number of frames */
2179 usbd_xfer_set_frames(xfer, blockcount);
2181 /* get sample size */
2182 sample_size = ch->usb_alt[ch->cur_alt].sample_size;
2184 /* reset total length */
2187 /* setup frame lengths */
2188 for (n = 0; n != blockcount; n++) {
2191 ch->sample_curr += ch->sample_rem;
2192 if (ch->sample_curr >= ch->frames_per_second) {
2193 ch->sample_curr -= ch->frames_per_second;
2194 frame_len = ch->bytes_per_frame[1];
2196 frame_len = ch->bytes_per_frame[0];
2199 /* handle free running clock case */
2200 if (ch->jitter_curr > 0 &&
2201 (frame_len + sample_size) <= mfl) {
2202 DPRINTFN(6, "sending one sample more\n");
2204 frame_len += sample_size;
2205 } else if (ch->jitter_curr < 0 &&
2206 frame_len >= sample_size) {
2207 DPRINTFN(6, "sending one sample less\n");
2209 frame_len -= sample_size;
2211 usbd_xfer_set_frame_len(xfer, n, frame_len);
2215 DPRINTFN(6, "transferring %d bytes\n", total);
2219 pc = usbd_xfer_get_frame(xfer, 0);
2222 n = (ch->end - ch->cur);
2226 usbd_copy_in(pc, offset, ch->cur, n);
2232 if (ch->cur >= ch->end)
2233 ch->cur = ch->start;
2235 usbd_transfer_submit(xfer);
2238 default: /* Error */
2239 if (error != USB_ERR_CANCELLED)
2246 uaudio_chan_record_sync_callback(struct usb_xfer *xfer, usb_error_t error)
2252 uaudio_chan_record_callback(struct usb_xfer *xfer, usb_error_t error)
2254 struct uaudio_chan *ch = usbd_xfer_softc(xfer);
2255 struct usb_page_cache *pc;
2266 if (ch->start == ch->end) {
2267 DPRINTF("no buffer!\n");
2271 usbd_xfer_status(xfer, &actlen, NULL, NULL, &nframes);
2272 mfl = usbd_xfer_max_framelen(xfer);
2274 switch (USB_GET_STATE(xfer)) {
2275 case USB_ST_TRANSFERRED:
2278 pc = usbd_xfer_get_frame(xfer, 0);
2280 /* try to compute the number of expected bytes */
2281 ch->sample_curr += (ch->sample_rem * ch->intr_frames);
2283 /* compute number of expected bytes */
2284 expected_bytes = (ch->intr_frames * ch->bytes_per_frame[0]) +
2285 ((ch->sample_curr / ch->frames_per_second) *
2286 (ch->bytes_per_frame[1] - ch->bytes_per_frame[0]));
2288 /* keep remainder */
2289 ch->sample_curr %= ch->frames_per_second;
2291 /* get current sample size */
2292 sample_size = ch->usb_alt[ch->cur_alt].sample_size;
2294 for (n = 0; n != nframes; n++) {
2295 uint32_t offset1 = offset0;
2297 len = usbd_xfer_frame_len(xfer, n);
2299 /* make sure we only receive complete samples */
2300 len = len - (len % sample_size);
2302 /* subtract bytes received from expected payload */
2303 expected_bytes -= len;
2305 /* don't receive data when not ready */
2306 if (ch->running == 0 || ch->cur_alt != ch->set_alt)
2309 /* fill ring buffer with samples, if any */
2312 m = (ch->end - ch->cur);
2317 usbd_copy_out(pc, offset1, ch->cur, m);
2323 if (ch->cur >= ch->end)
2324 ch->cur = ch->start;
2330 /* update current jitter */
2331 ch->jitter_curr -= (expected_bytes / sample_size);
2333 /* don't allow a huge amount of jitter to accumulate */
2334 nframes = 2 * ch->intr_frames;
2336 /* range check current jitter */
2337 if (ch->jitter_curr < -nframes)
2338 ch->jitter_curr = -nframes;
2339 else if (ch->jitter_curr > nframes)
2340 ch->jitter_curr = nframes;
2342 DPRINTFN(6, "transferred %d bytes, jitter %d samples\n",
2343 actlen, ch->jitter_curr);
2345 if (ch->running != 0)
2346 chn_intr(ch->pcm_ch);
2350 nframes = ch->intr_frames;
2352 usbd_xfer_set_frames(xfer, nframes);
2353 for (n = 0; n != nframes; n++)
2354 usbd_xfer_set_frame_len(xfer, n, mfl);
2356 usbd_transfer_submit(xfer);
2359 default: /* Error */
2360 if (error != USB_ERR_CANCELLED)
2367 uaudio_chan_init(struct uaudio_softc *sc, struct snd_dbuf *b,
2368 struct pcm_channel *c, int dir)
2370 struct uaudio_chan *ch = ((dir == PCMDIR_PLAY) ?
2371 &sc->sc_play_chan : &sc->sc_rec_chan);
2375 /* store mutex and PCM channel */
2378 ch->pcm_mtx = c->lock;
2380 /* compute worst case buffer */
2383 for (x = 0; x != ch->num_alt; x++) {
2384 uint32_t temp = uaudio_get_buffer_size(ch, x);
2385 if (temp > buf_size)
2389 /* allow double buffering */
2392 DPRINTF("Worst case buffer is %d bytes\n", (int)buf_size);
2394 ch->buf = malloc(buf_size, M_DEVBUF, M_WAITOK | M_ZERO);
2395 if (ch->buf == NULL)
2397 if (sndbuf_setup(b, ch->buf, buf_size) != 0)
2400 ch->start = ch->buf;
2401 ch->end = ch->buf + buf_size;
2404 ch->max_buf = buf_size;
2406 if (ch->pcm_mtx == NULL) {
2407 DPRINTF("ERROR: PCM channels does not have a mutex!\n");
2413 uaudio_chan_free(ch);
2418 uaudio_chan_free(struct uaudio_chan *ch)
2420 if (ch->buf != NULL) {
2421 free(ch->buf, M_DEVBUF);
2424 usbd_transfer_unsetup(ch->xfer, UAUDIO_NCHANBUFS + 1);
2432 uaudio_chan_set_param_blocksize(struct uaudio_chan *ch, uint32_t blocksize)
2434 uint32_t temp = 2 * uaudio_get_buffer_size(ch, ch->set_alt);
2435 sndbuf_setup(ch->pcm_buf, ch->buf, temp);
2440 uaudio_chan_set_param_fragments(struct uaudio_chan *ch, uint32_t blocksize,
2441 uint32_t blockcount)
2447 uaudio_chan_set_param_speed(struct uaudio_chan *ch, uint32_t speed)
2449 struct uaudio_softc *sc;
2454 for (x = 0; x < ch->num_alt; x++) {
2455 if (ch->usb_alt[x].sample_rate < speed) {
2456 /* sample rate is too low */
2464 usb_proc_explore_lock(sc->sc_udev);
2466 usb_proc_explore_unlock(sc->sc_udev);
2468 DPRINTF("Selecting alt %d\n", (int)x);
2470 return (ch->usb_alt[x].sample_rate);
2474 uaudio_chan_getptr(struct uaudio_chan *ch)
2476 return (ch->cur - ch->start);
2479 struct pcmchan_caps *
2480 uaudio_chan_getcaps(struct uaudio_chan *ch)
2482 return (&ch->pcm_cap);
2485 static struct pcmchan_matrix uaudio_chan_matrix_swap_2_0 = {
2486 .id = SND_CHN_MATRIX_DRV,
2492 .type = SND_CHN_T_FR,
2494 SND_CHN_T_MASK_FR | SND_CHN_T_MASK_FC |
2495 SND_CHN_T_MASK_LF | SND_CHN_T_MASK_BR |
2496 SND_CHN_T_MASK_BC | SND_CHN_T_MASK_SR
2500 .type = SND_CHN_T_FL,
2502 SND_CHN_T_MASK_FL | SND_CHN_T_MASK_FC |
2503 SND_CHN_T_MASK_LF | SND_CHN_T_MASK_BL |
2504 SND_CHN_T_MASK_BC | SND_CHN_T_MASK_SL
2507 .type = SND_CHN_T_MAX,
2511 .mask = SND_CHN_T_MASK_FR | SND_CHN_T_MASK_FL,
2512 .offset = { 1, 0, -1, -1, -1, -1, -1, -1, -1,
2513 -1, -1, -1, -1, -1, -1, -1, -1, -1 }
2516 struct pcmchan_matrix *
2517 uaudio_chan_getmatrix(struct uaudio_chan *ch, uint32_t format)
2519 struct uaudio_softc *sc;
2523 if (sc != NULL && sc->sc_uq_audio_swap_lr != 0 &&
2524 AFMT_CHANNEL(format) == 2)
2525 return (&uaudio_chan_matrix_swap_2_0);
2527 return (feeder_matrix_format_map(format));
2531 uaudio_chan_set_param_format(struct uaudio_chan *ch, uint32_t format)
2533 DPRINTF("Selecting format 0x%08x\n", (unsigned int)format);
2538 uaudio_chan_start_sub(struct uaudio_chan *ch)
2540 struct uaudio_softc *sc = ch->priv_sc;
2543 if (ch->operation != CHAN_OP_DRAIN) {
2544 if (ch->cur_alt == ch->set_alt &&
2545 ch->operation == CHAN_OP_NONE &&
2546 mtx_owned(ch->pcm_mtx) != 0) {
2547 /* save doing the explore task */
2550 ch->operation = CHAN_OP_START;
2551 (void)usb_proc_explore_msignal(sc->sc_udev,
2552 &sc->sc_config_msg[0], &sc->sc_config_msg[1]);
2556 usbd_transfer_start(ch->xfer[0]);
2557 usbd_transfer_start(ch->xfer[1]);
2562 uaudio_chan_need_both(struct uaudio_softc *sc)
2564 return (sc->sc_play_chan.num_alt > 0 &&
2565 sc->sc_play_chan.running != 0 &&
2566 uaudio_chan_is_async(&sc->sc_play_chan,
2567 sc->sc_play_chan.set_alt) != 0 &&
2568 sc->sc_rec_chan.num_alt > 0 &&
2569 sc->sc_rec_chan.running == 0);
2573 uaudio_chan_need_none(struct uaudio_softc *sc)
2575 return (sc->sc_play_chan.num_alt > 0 &&
2576 sc->sc_play_chan.running == 0 &&
2577 sc->sc_rec_chan.num_alt > 0 &&
2578 sc->sc_rec_chan.running == 0);
2582 uaudio_chan_start(struct uaudio_chan *ch)
2584 struct uaudio_softc *sc = ch->priv_sc;
2586 /* make operation atomic */
2587 usb_proc_explore_lock(sc->sc_udev);
2589 /* check if not running */
2590 if (ch->running == 0) {
2593 /* get current buffer size */
2594 temp = 2 * uaudio_get_buffer_size(ch, ch->set_alt);
2596 /* set running flag */
2599 /* ensure the hardware buffer is reset */
2600 ch->start = ch->buf;
2601 ch->end = ch->buf + temp;
2604 if (uaudio_chan_need_both(sc)) {
2606 * Start both endpoints because of need for
2607 * jitter information:
2609 uaudio_chan_start_sub(&sc->sc_rec_chan);
2610 uaudio_chan_start_sub(&sc->sc_play_chan);
2612 uaudio_chan_start_sub(ch);
2616 /* exit atomic operation */
2617 usb_proc_explore_unlock(sc->sc_udev);
2621 uaudio_chan_stop_sub(struct uaudio_chan *ch)
2623 struct uaudio_softc *sc = ch->priv_sc;
2626 if (ch->operation != CHAN_OP_DRAIN) {
2627 if (ch->cur_alt == ch->set_alt &&
2628 ch->operation == CHAN_OP_NONE &&
2629 mtx_owned(ch->pcm_mtx) != 0) {
2630 /* save doing the explore task */
2633 ch->operation = CHAN_OP_STOP;
2634 (void)usb_proc_explore_msignal(sc->sc_udev,
2635 &sc->sc_config_msg[0], &sc->sc_config_msg[1]);
2639 usbd_transfer_stop(ch->xfer[0]);
2640 usbd_transfer_stop(ch->xfer[1]);
2645 uaudio_chan_stop(struct uaudio_chan *ch)
2647 struct uaudio_softc *sc = ch->priv_sc;
2649 /* make operation atomic */
2650 usb_proc_explore_lock(sc->sc_udev);
2652 /* check if running */
2653 if (ch->running != 0) {
2654 /* clear running flag */
2657 if (uaudio_chan_need_both(sc)) {
2659 * Leave the endpoints running because we need
2660 * information about jitter!
2662 } else if (uaudio_chan_need_none(sc)) {
2664 * Stop both endpoints in case the one was used for
2665 * jitter information:
2667 uaudio_chan_stop_sub(&sc->sc_rec_chan);
2668 uaudio_chan_stop_sub(&sc->sc_play_chan);
2670 uaudio_chan_stop_sub(ch);
2674 /* exit atomic operation */
2675 usb_proc_explore_unlock(sc->sc_udev);
2678 /*========================================================================*
2679 * AC - Audio Controller - routines
2680 *========================================================================*/
2683 uaudio_mixer_sysctl_handler(SYSCTL_HANDLER_ARGS)
2685 struct uaudio_softc *sc;
2686 struct uaudio_mixer_node *pmc;
2692 sc = (struct uaudio_softc *)oidp->oid_arg1;
2693 hint = oidp->oid_arg2;
2695 if (sc->sc_mixer_lock == NULL)
2698 /* lookup mixer node */
2700 mtx_lock(sc->sc_mixer_lock);
2701 for (pmc = sc->sc_mixer_root; pmc != NULL; pmc = pmc->next) {
2702 for (chan = 0; chan != (int)pmc->nchan; chan++) {
2703 if (pmc->wValue[chan] != -1 &&
2704 pmc->wValue[chan] == hint) {
2705 temp = pmc->wData[chan];
2711 mtx_unlock(sc->sc_mixer_lock);
2713 error = sysctl_handle_int(oidp, &temp, 0, req);
2714 if (error != 0 || req->newptr == NULL)
2717 /* update mixer value */
2719 mtx_lock(sc->sc_mixer_lock);
2721 temp >= pmc->minval &&
2722 temp <= pmc->maxval) {
2724 pmc->wData[chan] = temp;
2725 pmc->update[(chan / 8)] |= (1 << (chan % 8));
2727 /* start the transfer, if not already started */
2728 usbd_transfer_start(sc->sc_mixer_xfer[0]);
2730 mtx_unlock(sc->sc_mixer_lock);
2736 uaudio_mixer_ctl_free(struct uaudio_softc *sc)
2738 struct uaudio_mixer_node *p_mc;
2740 while ((p_mc = sc->sc_mixer_root) != NULL) {
2741 sc->sc_mixer_root = p_mc->next;
2742 free(p_mc, M_USBDEV);
2747 uaudio_mixer_register_sysctl(struct uaudio_softc *sc, device_t dev)
2749 struct uaudio_mixer_node *pmc;
2750 struct sysctl_oid *mixer_tree;
2751 struct sysctl_oid *control_tree;
2756 mixer_tree = SYSCTL_ADD_NODE(device_get_sysctl_ctx(dev),
2757 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "mixer",
2758 CTLFLAG_RD, NULL, "");
2760 if (mixer_tree == NULL)
2763 for (n = 0, pmc = sc->sc_mixer_root; pmc != NULL;
2764 pmc = pmc->next, n++) {
2766 for (chan = 0; chan < pmc->nchan; chan++) {
2768 if (pmc->nchan > 1) {
2769 snprintf(buf, sizeof(buf), "%s_%d_%d",
2770 pmc->name, n, chan);
2772 snprintf(buf, sizeof(buf), "%s_%d",
2776 control_tree = SYSCTL_ADD_NODE(device_get_sysctl_ctx(dev),
2777 SYSCTL_CHILDREN(mixer_tree), OID_AUTO, buf,
2778 CTLFLAG_RD, NULL, "Mixer control nodes");
2780 if (control_tree == NULL)
2783 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
2784 SYSCTL_CHILDREN(control_tree),
2785 OID_AUTO, "val", CTLTYPE_INT | CTLFLAG_RWTUN, sc,
2787 uaudio_mixer_sysctl_handler, "I", "Current value");
2789 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
2790 SYSCTL_CHILDREN(control_tree),
2791 OID_AUTO, "min", CTLFLAG_RD, 0, pmc->minval,
2794 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
2795 SYSCTL_CHILDREN(control_tree),
2796 OID_AUTO, "max", CTLFLAG_RD, 0, pmc->maxval,
2799 SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev),
2800 SYSCTL_CHILDREN(control_tree),
2801 OID_AUTO, "desc", CTLFLAG_RD, pmc->desc, 0,
2807 /* M-Audio FastTrack Ultra Mixer Description */
2808 /* Origin: Linux USB Audio driver */
2810 uaudio_mixer_controls_create_ftu(struct uaudio_softc *sc)
2815 memset(&MIX(sc), 0, sizeof(MIX(sc)));
2816 MIX(sc).wIndex = MAKE_WORD(6, sc->sc_mixer_iface_no);
2817 MIX(sc).wValue[0] = MAKE_WORD(8, 0);
2818 MIX(sc).class = UAC_OUTPUT;
2819 MIX(sc).type = MIX_UNSIGNED_16;
2820 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2821 MIX(sc).name = "effect";
2826 MIX(sc).update[0] = 1;
2827 strlcpy(MIX(sc).desc, "Room1,2,3,Hall1,2,Plate,Delay,Echo", sizeof(MIX(sc).desc));
2828 uaudio_mixer_add_ctl_sub(sc, &MIX(sc));
2830 memset(&MIX(sc), 0, sizeof(MIX(sc)));
2831 MIX(sc).wIndex = MAKE_WORD(5, sc->sc_mixer_iface_no);
2833 for (chx = 0; chx != 8; chx++) {
2834 for (chy = 0; chy != 8; chy++) {
2836 MIX(sc).wValue[0] = MAKE_WORD(chx + 1, chy + 1);
2837 MIX(sc).type = MIX_SIGNED_16;
2838 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2839 MIX(sc).name = "mix_rec";
2841 MIX(sc).update[0] = 1;
2842 MIX(sc).val_default = 0;
2843 snprintf(MIX(sc).desc, sizeof(MIX(sc).desc),
2844 "AIn%d - Out%d Record Volume", chy + 1, chx + 1);
2846 uaudio_mixer_add_ctl(sc, &MIX(sc));
2848 MIX(sc).wValue[0] = MAKE_WORD(chx + 1, chy + 1 + 8);
2849 MIX(sc).type = MIX_SIGNED_16;
2850 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2851 MIX(sc).name = "mix_play";
2853 MIX(sc).update[0] = 1;
2854 MIX(sc).val_default = (chx == chy) ? 2 : 0;
2855 snprintf(MIX(sc).desc, sizeof(MIX(sc).desc),
2856 "DIn%d - Out%d Playback Volume", chy + 1, chx + 1);
2858 uaudio_mixer_add_ctl(sc, &MIX(sc));
2862 memset(&MIX(sc), 0, sizeof(MIX(sc)));
2863 MIX(sc).wIndex = MAKE_WORD(6, sc->sc_mixer_iface_no);
2864 MIX(sc).wValue[0] = MAKE_WORD(2, 0);
2865 MIX(sc).class = UAC_OUTPUT;
2866 MIX(sc).type = MIX_SIGNED_8;
2867 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2868 MIX(sc).name = "effect_vol";
2870 MIX(sc).update[0] = 1;
2872 MIX(sc).maxval = 0x7f;
2875 MIX(sc).update[0] = 1;
2876 strlcpy(MIX(sc).desc, "Effect Volume", sizeof(MIX(sc).desc));
2877 uaudio_mixer_add_ctl_sub(sc, &MIX(sc));
2879 memset(&MIX(sc), 0, sizeof(MIX(sc)));
2880 MIX(sc).wIndex = MAKE_WORD(6, sc->sc_mixer_iface_no);
2881 MIX(sc).wValue[0] = MAKE_WORD(3, 0);
2882 MIX(sc).class = UAC_OUTPUT;
2883 MIX(sc).type = MIX_SIGNED_16;
2884 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2885 MIX(sc).name = "effect_dur";
2887 MIX(sc).update[0] = 1;
2889 MIX(sc).maxval = 0x7f00;
2890 MIX(sc).mul = 0x7f00;
2892 MIX(sc).update[0] = 1;
2893 strlcpy(MIX(sc).desc, "Effect Duration", sizeof(MIX(sc).desc));
2894 uaudio_mixer_add_ctl_sub(sc, &MIX(sc));
2896 memset(&MIX(sc), 0, sizeof(MIX(sc)));
2897 MIX(sc).wIndex = MAKE_WORD(6, sc->sc_mixer_iface_no);
2898 MIX(sc).wValue[0] = MAKE_WORD(4, 0);
2899 MIX(sc).class = UAC_OUTPUT;
2900 MIX(sc).type = MIX_SIGNED_8;
2901 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2902 MIX(sc).name = "effect_fb";
2904 MIX(sc).update[0] = 1;
2906 MIX(sc).maxval = 0x7f;
2909 MIX(sc).update[0] = 1;
2910 strlcpy(MIX(sc).desc, "Effect Feedback Volume", sizeof(MIX(sc).desc));
2911 uaudio_mixer_add_ctl_sub(sc, &MIX(sc));
2913 memset(&MIX(sc), 0, sizeof(MIX(sc)));
2914 MIX(sc).wIndex = MAKE_WORD(7, sc->sc_mixer_iface_no);
2915 for (chy = 0; chy != 4; chy++) {
2917 MIX(sc).wValue[0] = MAKE_WORD(7, chy + 1);
2918 MIX(sc).type = MIX_SIGNED_16;
2919 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2920 MIX(sc).name = "effect_ret";
2922 MIX(sc).update[0] = 1;
2923 snprintf(MIX(sc).desc, sizeof(MIX(sc).desc),
2924 "Effect Return %d Volume", chy + 1);
2926 uaudio_mixer_add_ctl(sc, &MIX(sc));
2929 memset(&MIX(sc), 0, sizeof(MIX(sc)));
2930 MIX(sc).wIndex = MAKE_WORD(5, sc->sc_mixer_iface_no);
2932 for (chy = 0; chy != 8; chy++) {
2933 MIX(sc).wValue[0] = MAKE_WORD(9, chy + 1);
2934 MIX(sc).type = MIX_SIGNED_16;
2935 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2936 MIX(sc).name = "effect_send";
2938 MIX(sc).update[0] = 1;
2939 snprintf(MIX(sc).desc, sizeof(MIX(sc).desc),
2940 "Effect Send AIn%d Volume", chy + 1);
2942 uaudio_mixer_add_ctl(sc, &MIX(sc));
2944 MIX(sc).wValue[0] = MAKE_WORD(9, chy + 1 + 8);
2945 MIX(sc).type = MIX_SIGNED_16;
2946 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
2947 MIX(sc).name = "effect_send";
2949 MIX(sc).update[0] = 1;
2950 snprintf(MIX(sc).desc, sizeof(MIX(sc).desc),
2951 "Effect Send DIn%d Volume", chy + 1);
2953 uaudio_mixer_add_ctl(sc, &MIX(sc));
2958 uaudio_mixer_reload_all(struct uaudio_softc *sc)
2960 struct uaudio_mixer_node *pmc;
2963 if (sc->sc_mixer_lock == NULL)
2966 mtx_lock(sc->sc_mixer_lock);
2967 for (pmc = sc->sc_mixer_root; pmc != NULL; pmc = pmc->next) {
2968 /* use reset defaults for non-oss controlled settings */
2969 if (pmc->ctl == SOUND_MIXER_NRDEVICES)
2971 for (chan = 0; chan < pmc->nchan; chan++)
2972 pmc->update[chan / 8] |= (1 << (chan % 8));
2974 usbd_transfer_start(sc->sc_mixer_xfer[0]);
2976 /* start HID volume keys, if any */
2977 usbd_transfer_start(sc->sc_hid.xfer[0]);
2978 mtx_unlock(sc->sc_mixer_lock);
2982 uaudio_mixer_add_ctl_sub(struct uaudio_softc *sc, struct uaudio_mixer_node *mc)
2984 struct uaudio_mixer_node *p_mc_new =
2985 malloc(sizeof(*p_mc_new), M_USBDEV, M_WAITOK);
2988 if (p_mc_new != NULL) {
2989 memcpy(p_mc_new, mc, sizeof(*p_mc_new));
2990 p_mc_new->next = sc->sc_mixer_root;
2991 sc->sc_mixer_root = p_mc_new;
2992 sc->sc_mixer_count++;
2994 /* set default value for all channels */
2995 for (ch = 0; ch < p_mc_new->nchan; ch++) {
2996 switch (p_mc_new->val_default) {
2999 p_mc_new->wData[ch] = (p_mc_new->maxval + p_mc_new->minval) / 2;
3003 p_mc_new->wData[ch] = p_mc_new->maxval;
3007 p_mc_new->wData[ch] = p_mc_new->minval;
3012 DPRINTF("out of memory\n");
3017 uaudio_mixer_add_ctl(struct uaudio_softc *sc, struct uaudio_mixer_node *mc)
3021 if (mc->class < UAC_NCLASSES) {
3022 DPRINTF("adding %s.%d\n",
3023 uac_names[mc->class], mc->ctl);
3025 DPRINTF("adding %d\n", mc->ctl);
3028 if (mc->type == MIX_ON_OFF) {
3031 } else if (mc->type == MIX_SELECTOR) {
3034 /* determine min and max values */
3036 mc->minval = uaudio_mixer_get(sc->sc_udev,
3037 sc->sc_audio_rev, GET_MIN, mc);
3038 mc->maxval = uaudio_mixer_get(sc->sc_udev,
3039 sc->sc_audio_rev, GET_MAX, mc);
3041 /* check if max and min was swapped */
3043 if (mc->maxval < mc->minval) {
3045 mc->maxval = mc->minval;
3049 /* compute value range */
3050 mc->mul = mc->maxval - mc->minval;
3054 /* compute value alignment */
3055 res = uaudio_mixer_get(sc->sc_udev,
3056 sc->sc_audio_rev, GET_RES, mc);
3058 DPRINTF("Resolution = %d\n", (int)res);
3061 uaudio_mixer_add_ctl_sub(sc, mc);
3064 if (uaudio_debug > 2) {
3067 for (i = 0; i < mc->nchan; i++) {
3068 DPRINTF("[mix] wValue=%04x\n", mc->wValue[0]);
3070 DPRINTF("[mix] wIndex=%04x type=%d ctl='%d' "
3072 mc->wIndex, mc->type, mc->ctl,
3073 mc->minval, mc->maxval);
3079 uaudio_mixer_add_mixer(struct uaudio_softc *sc,
3080 const struct uaudio_terminal_node *iot, int id)
3082 const struct usb_audio_mixer_unit_0 *d0 = iot[id].u.mu_v1;
3083 const struct usb_audio_mixer_unit_1 *d1;
3085 uint32_t bno; /* bit number */
3086 uint32_t p; /* bit number accumulator */
3087 uint32_t mo; /* matching outputs */
3088 uint32_t mc; /* matching channels */
3089 uint32_t ichs; /* input channels */
3090 uint32_t ochs; /* output channels */
3092 uint32_t chs; /* channels */
3096 DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
3097 d0->bUnitId, d0->bNrInPins);
3099 /* compute the number of input channels */
3102 for (i = 0; i < d0->bNrInPins; i++) {
3103 ichs += uaudio_mixer_get_cluster(
3104 d0->baSourceId[i], iot).bNrChannels;
3107 d1 = (const void *)(d0->baSourceId + d0->bNrInPins);
3109 /* and the number of output channels */
3111 ochs = d1->bNrChannels;
3113 DPRINTFN(3, "ichs=%d ochs=%d\n", ichs, ochs);
3115 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3117 MIX(sc).wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
3118 uaudio_mixer_determine_class(&iot[id], &MIX(sc));
3119 MIX(sc).type = MIX_SIGNED_16;
3121 if (uaudio_mixer_verify_desc(d0, ((ichs * ochs) + 7) / 8) == NULL)
3124 for (p = i = 0; i < d0->bNrInPins; i++) {
3125 chs = uaudio_mixer_get_cluster(
3126 d0->baSourceId[i], iot).bNrChannels;
3128 for (c = 0; c < chs; c++) {
3130 for (o = 0; o < ochs; o++) {
3131 bno = ((p + c) * ochs) + o;
3132 if (BIT_TEST(d1->bmControls, bno))
3138 if ((mc == chs) && (chs <= MIX_MAX_CHAN)) {
3140 /* repeat bit-scan */
3143 for (c = 0; c < chs; c++) {
3144 for (o = 0; o < ochs; o++) {
3145 bno = ((p + c) * ochs) + o;
3146 if (BIT_TEST(d1->bmControls, bno))
3147 MIX(sc).wValue[mc++] = MAKE_WORD(p + c + 1, o + 1);
3150 MIX(sc).nchan = chs;
3151 uaudio_mixer_add_ctl(sc, &MIX(sc));
3158 uaudio20_mixer_add_mixer(struct uaudio_softc *sc,
3159 const struct uaudio_terminal_node *iot, int id)
3161 const struct usb_audio20_mixer_unit_0 *d0 = iot[id].u.mu_v2;
3162 const struct usb_audio20_mixer_unit_1 *d1;
3164 uint32_t bno; /* bit number */
3165 uint32_t p; /* bit number accumulator */
3166 uint32_t mo; /* matching outputs */
3167 uint32_t mc; /* matching channels */
3168 uint32_t ichs; /* input channels */
3169 uint32_t ochs; /* output channels */
3171 uint32_t chs; /* channels */
3175 DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
3176 d0->bUnitId, d0->bNrInPins);
3178 /* compute the number of input channels */
3181 for (i = 0; i < d0->bNrInPins; i++) {
3182 ichs += uaudio20_mixer_get_cluster(
3183 d0->baSourceId[i], iot).bNrChannels;
3186 d1 = (const void *)(d0->baSourceId + d0->bNrInPins);
3188 /* and the number of output channels */
3190 ochs = d1->bNrChannels;
3192 DPRINTFN(3, "ichs=%d ochs=%d\n", ichs, ochs);
3194 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3196 MIX(sc).wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
3197 uaudio20_mixer_determine_class(&iot[id], &MIX(sc));
3198 MIX(sc).type = MIX_SIGNED_16;
3200 if (uaudio20_mixer_verify_desc(d0, ((ichs * ochs) + 7) / 8) == NULL)
3203 for (p = i = 0; i < d0->bNrInPins; i++) {
3204 chs = uaudio20_mixer_get_cluster(
3205 d0->baSourceId[i], iot).bNrChannels;
3207 for (c = 0; c < chs; c++) {
3209 for (o = 0; o < ochs; o++) {
3210 bno = ((p + c) * ochs) + o;
3211 if (BIT_TEST(d1->bmControls, bno))
3217 if ((mc == chs) && (chs <= MIX_MAX_CHAN)) {
3219 /* repeat bit-scan */
3222 for (c = 0; c < chs; c++) {
3223 for (o = 0; o < ochs; o++) {
3224 bno = ((p + c) * ochs) + o;
3225 if (BIT_TEST(d1->bmControls, bno))
3226 MIX(sc).wValue[mc++] = MAKE_WORD(p + c + 1, o + 1);
3229 MIX(sc).nchan = chs;
3230 uaudio_mixer_add_ctl(sc, &MIX(sc));
3237 uaudio_mixer_add_selector(struct uaudio_softc *sc,
3238 const struct uaudio_terminal_node *iot, int id)
3240 const struct usb_audio_selector_unit *d = iot[id].u.su_v1;
3243 DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
3244 d->bUnitId, d->bNrInPins);
3246 if (d->bNrInPins == 0)
3249 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3251 MIX(sc).wIndex = MAKE_WORD(d->bUnitId, sc->sc_mixer_iface_no);
3252 MIX(sc).wValue[0] = MAKE_WORD(0, 0);
3253 uaudio_mixer_determine_class(&iot[id], &MIX(sc));
3255 MIX(sc).type = MIX_SELECTOR;
3256 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
3258 MIX(sc).maxval = d->bNrInPins;
3259 MIX(sc).name = "selector";
3261 i = d->baSourceId[d->bNrInPins];
3263 usbd_req_get_string_any(sc->sc_udev, NULL,
3264 MIX(sc).desc, sizeof(MIX(sc).desc), i) != 0) {
3265 MIX(sc).desc[0] = 0;
3268 if (MIX(sc).maxval > MAX_SELECTOR_INPUT_PIN) {
3269 MIX(sc).maxval = MAX_SELECTOR_INPUT_PIN;
3271 MIX(sc).mul = (MIX(sc).maxval - MIX(sc).minval);
3272 for (i = 0; i < MAX_SELECTOR_INPUT_PIN; i++) {
3273 MIX(sc).slctrtype[i] = SOUND_MIXER_NRDEVICES;
3276 for (i = 0; i < MIX(sc).maxval; i++) {
3277 MIX(sc).slctrtype[i] = uaudio_mixer_feature_name(
3278 &iot[d->baSourceId[i]], &MIX(sc));
3281 MIX(sc).class = 0; /* not used */
3283 uaudio_mixer_add_ctl(sc, &MIX(sc));
3287 uaudio20_mixer_add_selector(struct uaudio_softc *sc,
3288 const struct uaudio_terminal_node *iot, int id)
3290 const struct usb_audio20_selector_unit *d = iot[id].u.su_v2;
3293 DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
3294 d->bUnitId, d->bNrInPins);
3296 if (d->bNrInPins == 0)
3299 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3301 MIX(sc).wIndex = MAKE_WORD(d->bUnitId, sc->sc_mixer_iface_no);
3302 MIX(sc).wValue[0] = MAKE_WORD(0, 0);
3303 uaudio20_mixer_determine_class(&iot[id], &MIX(sc));
3305 MIX(sc).type = MIX_SELECTOR;
3306 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
3308 MIX(sc).maxval = d->bNrInPins;
3309 MIX(sc).name = "selector";
3311 i = d->baSourceId[d->bNrInPins];
3313 usbd_req_get_string_any(sc->sc_udev, NULL,
3314 MIX(sc).desc, sizeof(MIX(sc).desc), i) != 0) {
3315 MIX(sc).desc[0] = 0;
3318 if (MIX(sc).maxval > MAX_SELECTOR_INPUT_PIN)
3319 MIX(sc).maxval = MAX_SELECTOR_INPUT_PIN;
3321 MIX(sc).mul = (MIX(sc).maxval - MIX(sc).minval);
3322 for (i = 0; i < MAX_SELECTOR_INPUT_PIN; i++)
3323 MIX(sc).slctrtype[i] = SOUND_MIXER_NRDEVICES;
3325 for (i = 0; i < MIX(sc).maxval; i++) {
3326 MIX(sc).slctrtype[i] = uaudio20_mixer_feature_name(
3327 &iot[d->baSourceId[i]], &MIX(sc));
3330 MIX(sc).class = 0; /* not used */
3332 uaudio_mixer_add_ctl(sc, &MIX(sc));
3336 uaudio_mixer_feature_get_bmaControls(const struct usb_audio_feature_unit *d,
3340 uint32_t offset = (i * d->bControlSize);
3342 if (d->bControlSize > 0) {
3343 temp |= d->bmaControls[offset];
3344 if (d->bControlSize > 1) {
3345 temp |= d->bmaControls[offset + 1] << 8;
3346 if (d->bControlSize > 2) {
3347 temp |= d->bmaControls[offset + 2] << 16;
3348 if (d->bControlSize > 3) {
3349 temp |= d->bmaControls[offset + 3] << 24;
3358 uaudio_mixer_add_feature(struct uaudio_softc *sc,
3359 const struct uaudio_terminal_node *iot, int id)
3361 const struct usb_audio_feature_unit *d = iot[id].u.fu_v1;
3365 uint16_t mixernumber;
3371 if (d->bControlSize == 0)
3374 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3376 nchan = (d->bLength - 7) / d->bControlSize;
3377 mmask = uaudio_mixer_feature_get_bmaControls(d, 0);
3383 /* figure out what we can control */
3385 for (chan = 1; chan < nchan; chan++) {
3386 DPRINTFN(10, "chan=%d mask=%x\n",
3387 chan, uaudio_mixer_feature_get_bmaControls(d, chan));
3389 cmask |= uaudio_mixer_feature_get_bmaControls(d, chan);
3392 if (nchan > MIX_MAX_CHAN) {
3393 nchan = MIX_MAX_CHAN;
3395 MIX(sc).wIndex = MAKE_WORD(d->bUnitId, sc->sc_mixer_iface_no);
3397 i = d->bmaControls[d->bControlSize];
3399 usbd_req_get_string_any(sc->sc_udev, NULL,
3400 MIX(sc).desc, sizeof(MIX(sc).desc), i) != 0) {
3401 MIX(sc).desc[0] = 0;
3404 for (ctl = 1; ctl <= LOUDNESS_CONTROL; ctl++) {
3406 fumask = FU_MASK(ctl);
3408 DPRINTFN(5, "ctl=%d fumask=0x%04x\n",
3411 if (mmask & fumask) {
3413 MIX(sc).wValue[0] = MAKE_WORD(ctl, 0);
3414 } else if (cmask & fumask) {
3415 MIX(sc).nchan = nchan - 1;
3416 for (i = 1; i < nchan; i++) {
3417 if (uaudio_mixer_feature_get_bmaControls(d, i) & fumask)
3418 MIX(sc).wValue[i - 1] = MAKE_WORD(ctl, i);
3420 MIX(sc).wValue[i - 1] = -1;
3426 mixernumber = uaudio_mixer_feature_name(&iot[id], &MIX(sc));
3430 MIX(sc).type = MIX_ON_OFF;
3431 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
3432 MIX(sc).name = "mute";
3435 case VOLUME_CONTROL:
3436 MIX(sc).type = MIX_SIGNED_16;
3437 MIX(sc).ctl = mixernumber;
3438 MIX(sc).name = "vol";
3442 MIX(sc).type = MIX_SIGNED_8;
3443 MIX(sc).ctl = SOUND_MIXER_BASS;
3444 MIX(sc).name = "bass";
3448 MIX(sc).type = MIX_SIGNED_8;
3449 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3450 MIX(sc).name = "mid";
3453 case TREBLE_CONTROL:
3454 MIX(sc).type = MIX_SIGNED_8;
3455 MIX(sc).ctl = SOUND_MIXER_TREBLE;
3456 MIX(sc).name = "treble";
3459 case GRAPHIC_EQUALIZER_CONTROL:
3460 continue; /* XXX don't add anything */
3463 MIX(sc).type = MIX_ON_OFF;
3464 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3465 MIX(sc).name = "agc";
3469 MIX(sc).type = MIX_UNSIGNED_16;
3470 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3471 MIX(sc).name = "delay";
3474 case BASS_BOOST_CONTROL:
3475 MIX(sc).type = MIX_ON_OFF;
3476 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3477 MIX(sc).name = "boost";
3480 case LOUDNESS_CONTROL:
3481 MIX(sc).type = MIX_ON_OFF;
3482 MIX(sc).ctl = SOUND_MIXER_LOUD; /* Is this correct ? */
3483 MIX(sc).name = "loudness";
3487 MIX(sc).type = MIX_UNKNOWN;
3491 if (MIX(sc).type != MIX_UNKNOWN)
3492 uaudio_mixer_add_ctl(sc, &MIX(sc));
3497 uaudio20_mixer_add_feature(struct uaudio_softc *sc,
3498 const struct uaudio_terminal_node *iot, int id)
3500 const struct usb_audio20_feature_unit *d = iot[id].u.fu_v2;
3504 uint16_t mixernumber;
3510 if (UGETDW(d->bmaControls[0]) == 0)
3513 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3515 nchan = (d->bLength - 6) / 4;
3516 mmask = UGETDW(d->bmaControls[0]);
3522 /* figure out what we can control */
3524 for (chan = 1; chan < nchan; chan++)
3525 cmask |= UGETDW(d->bmaControls[chan]);
3527 if (nchan > MIX_MAX_CHAN)
3528 nchan = MIX_MAX_CHAN;
3530 MIX(sc).wIndex = MAKE_WORD(d->bUnitId, sc->sc_mixer_iface_no);
3532 i = d->bmaControls[nchan][0];
3534 usbd_req_get_string_any(sc->sc_udev, NULL,
3535 MIX(sc).desc, sizeof(MIX(sc).desc), i) != 0) {
3536 MIX(sc).desc[0] = 0;
3539 for (ctl = 3; ctl != 0; ctl <<= 2) {
3541 mixernumber = uaudio20_mixer_feature_name(&iot[id], &MIX(sc));
3545 MIX(sc).type = MIX_ON_OFF;
3546 MIX(sc).ctl = SOUND_MIXER_NRDEVICES;
3547 MIX(sc).name = "mute";
3548 what = MUTE_CONTROL;
3551 MIX(sc).type = MIX_SIGNED_16;
3552 MIX(sc).ctl = mixernumber;
3553 MIX(sc).name = "vol";
3554 what = VOLUME_CONTROL;
3557 MIX(sc).type = MIX_SIGNED_8;
3558 MIX(sc).ctl = SOUND_MIXER_BASS;
3559 MIX(sc).name = "bass";
3560 what = BASS_CONTROL;
3563 MIX(sc).type = MIX_SIGNED_8;
3564 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3565 MIX(sc).name = "mid";
3569 MIX(sc).type = MIX_SIGNED_8;
3570 MIX(sc).ctl = SOUND_MIXER_TREBLE;
3571 MIX(sc).name = "treble";
3572 what = TREBLE_CONTROL;
3575 MIX(sc).type = MIX_ON_OFF;
3576 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3577 MIX(sc).name = "agc";
3581 MIX(sc).type = MIX_UNSIGNED_16;
3582 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3583 MIX(sc).name = "delay";
3584 what = DELAY_CONTROL;
3587 MIX(sc).type = MIX_ON_OFF;
3588 MIX(sc).ctl = SOUND_MIXER_NRDEVICES; /* XXXXX */
3589 MIX(sc).name = "boost";
3590 what = BASS_BOOST_CONTROL;
3593 MIX(sc).type = MIX_ON_OFF;
3594 MIX(sc).ctl = SOUND_MIXER_LOUD; /* Is this correct ? */
3595 MIX(sc).name = "loudness";
3596 what = LOUDNESS_CONTROL;
3599 MIX(sc).type = MIX_SIGNED_16;
3600 MIX(sc).ctl = mixernumber;
3601 MIX(sc).name = "igain";
3602 what = INPUT_GAIN_CONTROL;
3605 MIX(sc).type = MIX_SIGNED_16;
3606 MIX(sc).ctl = mixernumber;
3607 MIX(sc).name = "igainpad";
3608 what = INPUT_GAIN_PAD_CONTROL;
3614 if ((mmask & ctl) == ctl) {
3616 MIX(sc).wValue[0] = MAKE_WORD(what, 0);
3617 } else if ((cmask & ctl) == ctl) {
3618 MIX(sc).nchan = nchan - 1;
3619 for (i = 1; i < nchan; i++) {
3620 if ((UGETDW(d->bmaControls[i]) & ctl) == ctl)
3621 MIX(sc).wValue[i - 1] = MAKE_WORD(what, i);
3623 MIX(sc).wValue[i - 1] = -1;
3629 if (MIX(sc).type != MIX_UNKNOWN)
3630 uaudio_mixer_add_ctl(sc, &MIX(sc));
3635 uaudio_mixer_add_processing_updown(struct uaudio_softc *sc,
3636 const struct uaudio_terminal_node *iot, int id)
3638 const struct usb_audio_processing_unit_0 *d0 = iot[id].u.pu_v1;
3639 const struct usb_audio_processing_unit_1 *d1 =
3640 (const void *)(d0->baSourceId + d0->bNrInPins);
3641 const struct usb_audio_processing_unit_updown *ud =
3642 (const void *)(d1->bmControls + d1->bControlSize);
3645 if (uaudio_mixer_verify_desc(d0, sizeof(*ud)) == NULL) {
3648 if (uaudio_mixer_verify_desc(d0, sizeof(*ud) + (2 * ud->bNrModes))
3652 DPRINTFN(3, "bUnitId=%d bNrModes=%d\n",
3653 d0->bUnitId, ud->bNrModes);
3655 if (!(d1->bmControls[0] & UA_PROC_MASK(UD_MODE_SELECT_CONTROL))) {
3656 DPRINTF("no mode select\n");
3659 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3661 MIX(sc).wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
3663 MIX(sc).wValue[0] = MAKE_WORD(UD_MODE_SELECT_CONTROL, 0);
3664 uaudio_mixer_determine_class(&iot[id], &MIX(sc));
3665 MIX(sc).type = MIX_ON_OFF; /* XXX */
3667 for (i = 0; i < ud->bNrModes; i++) {
3668 DPRINTFN(3, "i=%d bm=0x%x\n", i, UGETW(ud->waModes[i]));
3672 uaudio_mixer_add_ctl(sc, &MIX(sc));
3676 uaudio_mixer_add_processing(struct uaudio_softc *sc,
3677 const struct uaudio_terminal_node *iot, int id)
3679 const struct usb_audio_processing_unit_0 *d0 = iot[id].u.pu_v1;
3680 const struct usb_audio_processing_unit_1 *d1 =
3681 (const void *)(d0->baSourceId + d0->bNrInPins);
3684 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3686 ptype = UGETW(d0->wProcessType);
3688 DPRINTFN(3, "wProcessType=%d bUnitId=%d "
3689 "bNrInPins=%d\n", ptype, d0->bUnitId, d0->bNrInPins);
3691 if (d1->bControlSize == 0) {
3694 if (d1->bmControls[0] & UA_PROC_ENABLE_MASK) {
3695 MIX(sc).wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
3697 MIX(sc).wValue[0] = MAKE_WORD(XX_ENABLE_CONTROL, 0);
3698 uaudio_mixer_determine_class(&iot[id], &MIX(sc));
3699 MIX(sc).type = MIX_ON_OFF;
3700 uaudio_mixer_add_ctl(sc, &MIX(sc));
3703 case UPDOWNMIX_PROCESS:
3704 uaudio_mixer_add_processing_updown(sc, iot, id);
3707 case DOLBY_PROLOGIC_PROCESS:
3708 case P3D_STEREO_EXTENDER_PROCESS:
3709 case REVERBATION_PROCESS:
3710 case CHORUS_PROCESS:
3711 case DYN_RANGE_COMP_PROCESS:
3713 DPRINTF("unit %d, type=%d is not implemented\n",
3714 d0->bUnitId, ptype);
3720 uaudio_mixer_add_extension(struct uaudio_softc *sc,
3721 const struct uaudio_terminal_node *iot, int id)
3723 const struct usb_audio_extension_unit_0 *d0 = iot[id].u.eu_v1;
3724 const struct usb_audio_extension_unit_1 *d1 =
3725 (const void *)(d0->baSourceId + d0->bNrInPins);
3727 DPRINTFN(3, "bUnitId=%d bNrInPins=%d\n",
3728 d0->bUnitId, d0->bNrInPins);
3730 if (sc->sc_uq_au_no_xu) {
3733 if (d1->bControlSize == 0) {
3736 if (d1->bmControls[0] & UA_EXT_ENABLE_MASK) {
3738 memset(&MIX(sc), 0, sizeof(MIX(sc)));
3740 MIX(sc).wIndex = MAKE_WORD(d0->bUnitId, sc->sc_mixer_iface_no);
3742 MIX(sc).wValue[0] = MAKE_WORD(UA_EXT_ENABLE, 0);
3743 uaudio_mixer_determine_class(&iot[id], &MIX(sc));
3744 MIX(sc).type = MIX_ON_OFF;
3746 uaudio_mixer_add_ctl(sc, &MIX(sc));
3751 uaudio_mixer_verify_desc(const void *arg, uint32_t len)
3753 const struct usb_audio_mixer_unit_1 *d1;
3754 const struct usb_audio_extension_unit_1 *e1;
3755 const struct usb_audio_processing_unit_1 *u1;
3758 const struct usb_descriptor *desc;
3759 const struct usb_audio_input_terminal *it;
3760 const struct usb_audio_output_terminal *ot;
3761 const struct usb_audio_mixer_unit_0 *mu;
3762 const struct usb_audio_selector_unit *su;
3763 const struct usb_audio_feature_unit *fu;
3764 const struct usb_audio_processing_unit_0 *pu;
3765 const struct usb_audio_extension_unit_0 *eu;
3770 if (u.desc == NULL) {
3773 if (u.desc->bDescriptorType != UDESC_CS_INTERFACE) {
3776 switch (u.desc->bDescriptorSubtype) {
3777 case UDESCSUB_AC_INPUT:
3778 len += sizeof(*u.it);
3781 case UDESCSUB_AC_OUTPUT:
3782 len += sizeof(*u.ot);
3785 case UDESCSUB_AC_MIXER:
3786 len += sizeof(*u.mu);
3788 if (u.desc->bLength < len) {
3791 len += u.mu->bNrInPins;
3793 if (u.desc->bLength < len) {
3796 d1 = (const void *)(u.mu->baSourceId + u.mu->bNrInPins);
3801 case UDESCSUB_AC_SELECTOR:
3802 len += sizeof(*u.su);
3804 if (u.desc->bLength < len) {
3807 len += u.su->bNrInPins + 1;
3810 case UDESCSUB_AC_FEATURE:
3811 len += sizeof(*u.fu) + 1;
3813 if (u.desc->bLength < len)
3816 len += u.fu->bControlSize;
3819 case UDESCSUB_AC_PROCESSING:
3820 len += sizeof(*u.pu);
3822 if (u.desc->bLength < len) {
3825 len += u.pu->bNrInPins;
3827 if (u.desc->bLength < len) {
3830 u1 = (const void *)(u.pu->baSourceId + u.pu->bNrInPins);
3834 if (u.desc->bLength < len) {
3837 len += u1->bControlSize;
3841 case UDESCSUB_AC_EXTENSION:
3842 len += sizeof(*u.eu);
3844 if (u.desc->bLength < len) {
3847 len += u.eu->bNrInPins;
3849 if (u.desc->bLength < len) {
3852 e1 = (const void *)(u.eu->baSourceId + u.eu->bNrInPins);
3856 if (u.desc->bLength < len) {
3859 len += e1->bControlSize;
3866 if (u.desc->bLength < len) {
3873 DPRINTF("invalid descriptor, type=%d, "
3874 "sub_type=%d, len=%d of %d bytes\n",
3875 u.desc->bDescriptorType,
3876 u.desc->bDescriptorSubtype,
3877 u.desc->bLength, len);
3883 uaudio20_mixer_verify_desc(const void *arg, uint32_t len)
3885 const struct usb_audio20_mixer_unit_1 *d1;
3886 const struct usb_audio20_extension_unit_1 *e1;
3887 const struct usb_audio20_processing_unit_1 *u1;
3888 const struct usb_audio20_clock_selector_unit_1 *c1;
3891 const struct usb_descriptor *desc;
3892 const struct usb_audio20_clock_source_unit *csrc;
3893 const struct usb_audio20_clock_selector_unit_0 *csel;
3894 const struct usb_audio20_clock_multiplier_unit *cmul;
3895 const struct usb_audio20_input_terminal *it;
3896 const struct usb_audio20_output_terminal *ot;
3897 const struct usb_audio20_mixer_unit_0 *mu;
3898 const struct usb_audio20_selector_unit *su;
3899 const struct usb_audio20_feature_unit *fu;
3900 const struct usb_audio20_sample_rate_unit *ru;
3901 const struct usb_audio20_processing_unit_0 *pu;
3902 const struct usb_audio20_extension_unit_0 *eu;
3903 const struct usb_audio20_effect_unit *ef;
3911 if (u.desc->bDescriptorType != UDESC_CS_INTERFACE)
3914 switch (u.desc->bDescriptorSubtype) {
3915 case UDESCSUB_AC_INPUT:
3916 len += sizeof(*u.it);
3919 case UDESCSUB_AC_OUTPUT:
3920 len += sizeof(*u.ot);
3923 case UDESCSUB_AC_MIXER:
3924 len += sizeof(*u.mu);
3926 if (u.desc->bLength < len)
3928 len += u.mu->bNrInPins;
3930 if (u.desc->bLength < len)
3933 d1 = (const void *)(u.mu->baSourceId + u.mu->bNrInPins);
3935 len += sizeof(*d1) + d1->bNrChannels;
3938 case UDESCSUB_AC_SELECTOR:
3939 len += sizeof(*u.su);
3941 if (u.desc->bLength < len)
3944 len += u.su->bNrInPins + 1;
3947 case UDESCSUB_AC_FEATURE:
3948 len += sizeof(*u.fu) + 1;
3951 case UDESCSUB_AC_EFFECT:
3952 len += sizeof(*u.ef) + 4;
3955 case UDESCSUB_AC_PROCESSING_V2:
3956 len += sizeof(*u.pu);
3958 if (u.desc->bLength < len)
3961 len += u.pu->bNrInPins;
3963 if (u.desc->bLength < len)
3966 u1 = (const void *)(u.pu->baSourceId + u.pu->bNrInPins);
3971 case UDESCSUB_AC_EXTENSION_V2:
3972 len += sizeof(*u.eu);
3974 if (u.desc->bLength < len)
3977 len += u.eu->bNrInPins;
3979 if (u.desc->bLength < len)
3982 e1 = (const void *)(u.eu->baSourceId + u.eu->bNrInPins);
3987 case UDESCSUB_AC_CLOCK_SRC:
3988 len += sizeof(*u.csrc);
3991 case UDESCSUB_AC_CLOCK_SEL:
3992 len += sizeof(*u.csel);
3994 if (u.desc->bLength < len)
3997 len += u.csel->bNrInPins;
3999 if (u.desc->bLength < len)
4002 c1 = (const void *)(u.csel->baCSourceId + u.csel->bNrInPins);
4007 case UDESCSUB_AC_CLOCK_MUL:
4008 len += sizeof(*u.cmul);
4011 case UDESCSUB_AC_SAMPLE_RT:
4012 len += sizeof(*u.ru);
4019 if (u.desc->bLength < len)
4026 DPRINTF("invalid descriptor, type=%d, "
4027 "sub_type=%d, len=%d of %d bytes\n",
4028 u.desc->bDescriptorType,
4029 u.desc->bDescriptorSubtype,
4030 u.desc->bLength, len);
4035 static struct usb_audio_cluster
4036 uaudio_mixer_get_cluster(uint8_t id, const struct uaudio_terminal_node *iot)
4038 struct usb_audio_cluster r;
4039 const struct usb_descriptor *dp;
4042 for (i = 0; i < UAUDIO_RECURSE_LIMIT; i++) { /* avoid infinite loops */
4043 dp = iot[id].u.desc;
4047 switch (dp->bDescriptorSubtype) {
4048 case UDESCSUB_AC_INPUT:
4049 r.bNrChannels = iot[id].u.it_v1->bNrChannels;
4050 r.wChannelConfig[0] = iot[id].u.it_v1->wChannelConfig[0];
4051 r.wChannelConfig[1] = iot[id].u.it_v1->wChannelConfig[1];
4052 r.iChannelNames = iot[id].u.it_v1->iChannelNames;
4055 case UDESCSUB_AC_OUTPUT:
4056 id = iot[id].u.ot_v1->bSourceId;
4059 case UDESCSUB_AC_MIXER:
4060 r = *(const struct usb_audio_cluster *)
4061 &iot[id].u.mu_v1->baSourceId[
4062 iot[id].u.mu_v1->bNrInPins];
4065 case UDESCSUB_AC_SELECTOR:
4066 if (iot[id].u.su_v1->bNrInPins > 0) {
4067 /* XXX This is not really right */
4068 id = iot[id].u.su_v1->baSourceId[0];
4072 case UDESCSUB_AC_FEATURE:
4073 id = iot[id].u.fu_v1->bSourceId;
4076 case UDESCSUB_AC_PROCESSING:
4077 r = *((const struct usb_audio_cluster *)
4078 &iot[id].u.pu_v1->baSourceId[
4079 iot[id].u.pu_v1->bNrInPins]);
4082 case UDESCSUB_AC_EXTENSION:
4083 r = *((const struct usb_audio_cluster *)
4084 &iot[id].u.eu_v1->baSourceId[
4085 iot[id].u.eu_v1->bNrInPins]);
4093 DPRINTF("bad data\n");
4094 memset(&r, 0, sizeof(r));
4099 static struct usb_audio20_cluster
4100 uaudio20_mixer_get_cluster(uint8_t id, const struct uaudio_terminal_node *iot)
4102 struct usb_audio20_cluster r;
4103 const struct usb_descriptor *dp;
4106 for (i = 0; i < UAUDIO_RECURSE_LIMIT; i++) { /* avoid infinite loops */
4107 dp = iot[id].u.desc;
4111 switch (dp->bDescriptorSubtype) {
4112 case UDESCSUB_AC_INPUT:
4113 r.bNrChannels = iot[id].u.it_v2->bNrChannels;
4114 r.bmChannelConfig[0] = iot[id].u.it_v2->bmChannelConfig[0];
4115 r.bmChannelConfig[1] = iot[id].u.it_v2->bmChannelConfig[1];
4116 r.bmChannelConfig[2] = iot[id].u.it_v2->bmChannelConfig[2];
4117 r.bmChannelConfig[3] = iot[id].u.it_v2->bmChannelConfig[3];
4118 r.iChannelNames = iot[id].u.it_v2->iTerminal;
4121 case UDESCSUB_AC_OUTPUT:
4122 id = iot[id].u.ot_v2->bSourceId;
4125 case UDESCSUB_AC_MIXER:
4126 r = *(const struct usb_audio20_cluster *)
4127 &iot[id].u.mu_v2->baSourceId[
4128 iot[id].u.mu_v2->bNrInPins];
4131 case UDESCSUB_AC_SELECTOR:
4132 if (iot[id].u.su_v2->bNrInPins > 0) {
4133 /* XXX This is not really right */
4134 id = iot[id].u.su_v2->baSourceId[0];
4138 case UDESCSUB_AC_SAMPLE_RT:
4139 id = iot[id].u.ru_v2->bSourceId;
4142 case UDESCSUB_AC_EFFECT:
4143 id = iot[id].u.ef_v2->bSourceId;
4146 case UDESCSUB_AC_FEATURE:
4147 id = iot[id].u.fu_v2->bSourceId;
4150 case UDESCSUB_AC_PROCESSING_V2:
4151 r = *((const struct usb_audio20_cluster *)
4152 &iot[id].u.pu_v2->baSourceId[
4153 iot[id].u.pu_v2->bNrInPins]);
4156 case UDESCSUB_AC_EXTENSION_V2:
4157 r = *((const struct usb_audio20_cluster *)
4158 &iot[id].u.eu_v2->baSourceId[
4159 iot[id].u.eu_v2->bNrInPins]);
4167 DPRINTF("Bad data!\n");
4168 memset(&r, 0, sizeof(r));
4174 uaudio_mixer_determine_class(const struct uaudio_terminal_node *iot,
4175 struct uaudio_mixer_node *mix)
4177 uint16_t terminal_type = 0x0000;
4178 const struct uaudio_terminal_node *input[2];
4179 const struct uaudio_terminal_node *output[2];
4181 input[0] = uaudio_mixer_get_input(iot, 0);
4182 input[1] = uaudio_mixer_get_input(iot, 1);
4184 output[0] = uaudio_mixer_get_output(iot, 0);
4185 output[1] = uaudio_mixer_get_output(iot, 1);
4188 * check if there is only
4189 * one output terminal:
4191 if (output[0] && (!output[1])) {
4193 UGETW(output[0]->u.ot_v1->wTerminalType);
4196 * If the only output terminal is USB,
4197 * the class is UAC_RECORD.
4199 if ((terminal_type & 0xff00) == (UAT_UNDEFINED & 0xff00)) {
4201 mix->class = UAC_RECORD;
4202 if (input[0] && (!input[1])) {
4204 UGETW(input[0]->u.it_v1->wTerminalType);
4211 * if the unit is connected to just
4212 * one input terminal, the
4213 * class is UAC_INPUT:
4215 if (input[0] && (!input[1])) {
4216 mix->class = UAC_INPUT;
4218 UGETW(input[0]->u.it_v1->wTerminalType);
4222 * Otherwise, the class is UAC_OUTPUT.
4224 mix->class = UAC_OUTPUT;
4226 return (terminal_type);
4230 uaudio20_mixer_determine_class(const struct uaudio_terminal_node *iot,
4231 struct uaudio_mixer_node *mix)
4233 uint16_t terminal_type = 0x0000;
4234 const struct uaudio_terminal_node *input[2];
4235 const struct uaudio_terminal_node *output[2];
4237 input[0] = uaudio_mixer_get_input(iot, 0);
4238 input[1] = uaudio_mixer_get_input(iot, 1);
4240 output[0] = uaudio_mixer_get_output(iot, 0);
4241 output[1] = uaudio_mixer_get_output(iot, 1);
4244 * check if there is only
4245 * one output terminal:
4247 if (output[0] && (!output[1]))
4248 terminal_type = UGETW(output[0]->u.ot_v2->wTerminalType);
4250 * If the only output terminal is USB,
4251 * the class is UAC_RECORD.
4253 if ((terminal_type & 0xff00) == (UAT_UNDEFINED & 0xff00)) {
4255 mix->class = UAC_RECORD;
4256 if (input[0] && (!input[1])) {
4258 UGETW(input[0]->u.it_v2->wTerminalType);
4265 * if the unit is connected to just
4266 * one input terminal, the
4267 * class is UAC_INPUT:
4269 if (input[0] && (!input[1])) {
4270 mix->class = UAC_INPUT;
4272 UGETW(input[0]->u.it_v2->wTerminalType);
4276 * Otherwise, the class is UAC_OUTPUT.
4278 mix->class = UAC_OUTPUT;
4280 return (terminal_type);
4283 struct uaudio_tt_to_feature {
4284 uint16_t terminal_type;
4288 static const struct uaudio_tt_to_feature uaudio_tt_to_feature[] = {
4290 {UAT_STREAM, SOUND_MIXER_PCM},
4292 {UATI_MICROPHONE, SOUND_MIXER_MIC},
4293 {UATI_DESKMICROPHONE, SOUND_MIXER_MIC},
4294 {UATI_PERSONALMICROPHONE, SOUND_MIXER_MIC},
4295 {UATI_OMNIMICROPHONE, SOUND_MIXER_MIC},
4296 {UATI_MICROPHONEARRAY, SOUND_MIXER_MIC},
4297 {UATI_PROCMICROPHONEARR, SOUND_MIXER_MIC},
4299 {UATO_SPEAKER, SOUND_MIXER_SPEAKER},
4300 {UATO_DESKTOPSPEAKER, SOUND_MIXER_SPEAKER},
4301 {UATO_ROOMSPEAKER, SOUND_MIXER_SPEAKER},
4302 {UATO_COMMSPEAKER, SOUND_MIXER_SPEAKER},
4304 {UATE_ANALOGCONN, SOUND_MIXER_LINE},
4305 {UATE_LINECONN, SOUND_MIXER_LINE},
4306 {UATE_LEGACYCONN, SOUND_MIXER_LINE},
4308 {UATE_DIGITALAUIFC, SOUND_MIXER_ALTPCM},
4309 {UATE_SPDIF, SOUND_MIXER_ALTPCM},
4310 {UATE_1394DA, SOUND_MIXER_ALTPCM},
4311 {UATE_1394DV, SOUND_MIXER_ALTPCM},
4313 {UATF_CDPLAYER, SOUND_MIXER_CD},
4315 {UATF_SYNTHESIZER, SOUND_MIXER_SYNTH},
4317 {UATF_VIDEODISCAUDIO, SOUND_MIXER_VIDEO},
4318 {UATF_DVDAUDIO, SOUND_MIXER_VIDEO},
4319 {UATF_TVTUNERAUDIO, SOUND_MIXER_VIDEO},
4321 /* telephony terminal types */
4322 {UATT_UNDEFINED, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
4323 {UATT_PHONELINE, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
4324 {UATT_TELEPHONE, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
4325 {UATT_DOWNLINEPHONE, SOUND_MIXER_PHONEIN}, /* SOUND_MIXER_PHONEOUT */
4327 {UATF_RADIORECV, SOUND_MIXER_RADIO},
4328 {UATF_RADIOXMIT, SOUND_MIXER_RADIO},
4330 {UAT_UNDEFINED, SOUND_MIXER_VOLUME},
4331 {UAT_VENDOR, SOUND_MIXER_VOLUME},
4332 {UATI_UNDEFINED, SOUND_MIXER_VOLUME},
4334 /* output terminal types */
4335 {UATO_UNDEFINED, SOUND_MIXER_VOLUME},
4336 {UATO_DISPLAYAUDIO, SOUND_MIXER_VOLUME},
4337 {UATO_SUBWOOFER, SOUND_MIXER_VOLUME},
4338 {UATO_HEADPHONES, SOUND_MIXER_VOLUME},
4340 /* bidir terminal types */
4341 {UATB_UNDEFINED, SOUND_MIXER_VOLUME},
4342 {UATB_HANDSET, SOUND_MIXER_VOLUME},
4343 {UATB_HEADSET, SOUND_MIXER_VOLUME},
4344 {UATB_SPEAKERPHONE, SOUND_MIXER_VOLUME},
4345 {UATB_SPEAKERPHONEESUP, SOUND_MIXER_VOLUME},
4346 {UATB_SPEAKERPHONEECANC, SOUND_MIXER_VOLUME},
4348 /* external terminal types */
4349 {UATE_UNDEFINED, SOUND_MIXER_VOLUME},
4351 /* embedded function terminal types */
4352 {UATF_UNDEFINED, SOUND_MIXER_VOLUME},
4353 {UATF_CALIBNOISE, SOUND_MIXER_VOLUME},
4354 {UATF_EQUNOISE, SOUND_MIXER_VOLUME},
4355 {UATF_DAT, SOUND_MIXER_VOLUME},
4356 {UATF_DCC, SOUND_MIXER_VOLUME},
4357 {UATF_MINIDISK, SOUND_MIXER_VOLUME},
4358 {UATF_ANALOGTAPE, SOUND_MIXER_VOLUME},
4359 {UATF_PHONOGRAPH, SOUND_MIXER_VOLUME},
4360 {UATF_VCRAUDIO, SOUND_MIXER_VOLUME},
4361 {UATF_SATELLITE, SOUND_MIXER_VOLUME},
4362 {UATF_CABLETUNER, SOUND_MIXER_VOLUME},
4363 {UATF_DSS, SOUND_MIXER_VOLUME},
4364 {UATF_MULTITRACK, SOUND_MIXER_VOLUME},
4365 {0xffff, SOUND_MIXER_VOLUME},
4368 {0x0000, SOUND_MIXER_VOLUME},
4372 uaudio_mixer_feature_name(const struct uaudio_terminal_node *iot,
4373 struct uaudio_mixer_node *mix)
4375 const struct uaudio_tt_to_feature *uat = uaudio_tt_to_feature;
4376 uint16_t terminal_type = uaudio_mixer_determine_class(iot, mix);
4378 if ((mix->class == UAC_RECORD) && (terminal_type == 0)) {
4379 return (SOUND_MIXER_IMIX);
4381 while (uat->terminal_type) {
4382 if (uat->terminal_type == terminal_type) {
4388 DPRINTF("terminal_type=0x%04x -> %d\n",
4389 terminal_type, uat->feature);
4391 return (uat->feature);
4395 uaudio20_mixer_feature_name(const struct uaudio_terminal_node *iot,
4396 struct uaudio_mixer_node *mix)
4398 const struct uaudio_tt_to_feature *uat;
4399 uint16_t terminal_type = uaudio20_mixer_determine_class(iot, mix);
4401 if ((mix->class == UAC_RECORD) && (terminal_type == 0))
4402 return (SOUND_MIXER_IMIX);
4404 for (uat = uaudio_tt_to_feature; uat->terminal_type != 0; uat++) {
4405 if (uat->terminal_type == terminal_type)
4409 DPRINTF("terminal_type=0x%04x -> %d\n",
4410 terminal_type, uat->feature);
4412 return (uat->feature);
4415 static const struct uaudio_terminal_node *
4416 uaudio_mixer_get_input(const struct uaudio_terminal_node *iot, uint8_t i)
4418 struct uaudio_terminal_node *root = iot->root;
4421 n = iot->usr.id_max;
4423 if (iot->usr.bit_input[n / 8] & (1 << (n % 8))) {
4432 static const struct uaudio_terminal_node *
4433 uaudio_mixer_get_output(const struct uaudio_terminal_node *iot, uint8_t i)
4435 struct uaudio_terminal_node *root = iot->root;
4438 n = iot->usr.id_max;
4440 if (iot->usr.bit_output[n / 8] & (1 << (n % 8))) {
4450 uaudio_mixer_find_inputs_sub(struct uaudio_terminal_node *root,
4451 const uint8_t *p_id, uint8_t n_id,
4452 struct uaudio_search_result *info)
4454 struct uaudio_terminal_node *iot;
4460 for (n = 0; n < n_id; n++) {
4464 if (info->recurse_level == UAUDIO_RECURSE_LIMIT) {
4465 DPRINTF("avoided going into a circle at id=%d!\n", i);
4469 info->recurse_level++;
4473 if (iot->u.desc == NULL)
4476 is_last = ((n + 1) == n_id);
4478 switch (iot->u.desc->bDescriptorSubtype) {
4479 case UDESCSUB_AC_INPUT:
4480 info->bit_input[i / 8] |= (1 << (i % 8));
4483 case UDESCSUB_AC_FEATURE:
4485 p_id = &iot->u.fu_v1->bSourceId;
4489 uaudio_mixer_find_inputs_sub(
4490 root, &iot->u.fu_v1->bSourceId, 1, info);
4493 case UDESCSUB_AC_OUTPUT:
4495 p_id = &iot->u.ot_v1->bSourceId;
4499 uaudio_mixer_find_inputs_sub(
4500 root, &iot->u.ot_v1->bSourceId, 1, info);
4503 case UDESCSUB_AC_MIXER:
4505 p_id = iot->u.mu_v1->baSourceId;
4506 n_id = iot->u.mu_v1->bNrInPins;
4509 uaudio_mixer_find_inputs_sub(
4510 root, iot->u.mu_v1->baSourceId,
4511 iot->u.mu_v1->bNrInPins, info);
4514 case UDESCSUB_AC_SELECTOR:
4516 p_id = iot->u.su_v1->baSourceId;
4517 n_id = iot->u.su_v1->bNrInPins;
4520 uaudio_mixer_find_inputs_sub(
4521 root, iot->u.su_v1->baSourceId,
4522 iot->u.su_v1->bNrInPins, info);
4525 case UDESCSUB_AC_PROCESSING:
4527 p_id = iot->u.pu_v1->baSourceId;
4528 n_id = iot->u.pu_v1->bNrInPins;
4531 uaudio_mixer_find_inputs_sub(
4532 root, iot->u.pu_v1->baSourceId,
4533 iot->u.pu_v1->bNrInPins, info);
4536 case UDESCSUB_AC_EXTENSION:
4538 p_id = iot->u.eu_v1->baSourceId;
4539 n_id = iot->u.eu_v1->bNrInPins;
4542 uaudio_mixer_find_inputs_sub(
4543 root, iot->u.eu_v1->baSourceId,
4544 iot->u.eu_v1->bNrInPins, info);
4554 uaudio20_mixer_find_inputs_sub(struct uaudio_terminal_node *root,
4555 const uint8_t *p_id, uint8_t n_id,
4556 struct uaudio_search_result *info)
4558 struct uaudio_terminal_node *iot;
4564 for (n = 0; n < n_id; n++) {
4568 if (info->recurse_level == UAUDIO_RECURSE_LIMIT) {
4569 DPRINTF("avoided going into a circle at id=%d!\n", i);
4573 info->recurse_level++;
4577 if (iot->u.desc == NULL)
4580 is_last = ((n + 1) == n_id);
4582 switch (iot->u.desc->bDescriptorSubtype) {
4583 case UDESCSUB_AC_INPUT:
4584 info->bit_input[i / 8] |= (1 << (i % 8));
4587 case UDESCSUB_AC_OUTPUT:
4589 p_id = &iot->u.ot_v2->bSourceId;
4593 uaudio20_mixer_find_inputs_sub(
4594 root, &iot->u.ot_v2->bSourceId, 1, info);
4597 case UDESCSUB_AC_MIXER:
4599 p_id = iot->u.mu_v2->baSourceId;
4600 n_id = iot->u.mu_v2->bNrInPins;
4603 uaudio20_mixer_find_inputs_sub(
4604 root, iot->u.mu_v2->baSourceId,
4605 iot->u.mu_v2->bNrInPins, info);
4608 case UDESCSUB_AC_SELECTOR:
4610 p_id = iot->u.su_v2->baSourceId;
4611 n_id = iot->u.su_v2->bNrInPins;
4614 uaudio20_mixer_find_inputs_sub(
4615 root, iot->u.su_v2->baSourceId,
4616 iot->u.su_v2->bNrInPins, info);
4619 case UDESCSUB_AC_SAMPLE_RT:
4621 p_id = &iot->u.ru_v2->bSourceId;
4625 uaudio20_mixer_find_inputs_sub(
4626 root, &iot->u.ru_v2->bSourceId,
4630 case UDESCSUB_AC_EFFECT:
4632 p_id = &iot->u.ef_v2->bSourceId;
4636 uaudio20_mixer_find_inputs_sub(
4637 root, &iot->u.ef_v2->bSourceId,
4641 case UDESCSUB_AC_FEATURE:
4643 p_id = &iot->u.fu_v2->bSourceId;
4647 uaudio20_mixer_find_inputs_sub(
4648 root, &iot->u.fu_v2->bSourceId, 1, info);
4651 case UDESCSUB_AC_PROCESSING_V2:
4653 p_id = iot->u.pu_v2->baSourceId;
4654 n_id = iot->u.pu_v2->bNrInPins;
4657 uaudio20_mixer_find_inputs_sub(
4658 root, iot->u.pu_v2->baSourceId,
4659 iot->u.pu_v2->bNrInPins, info);
4662 case UDESCSUB_AC_EXTENSION_V2:
4664 p_id = iot->u.eu_v2->baSourceId;
4665 n_id = iot->u.eu_v2->bNrInPins;
4668 uaudio20_mixer_find_inputs_sub(
4669 root, iot->u.eu_v2->baSourceId,
4670 iot->u.eu_v2->bNrInPins, info);
4679 uaudio20_mixer_find_clocks_sub(struct uaudio_terminal_node *root,
4680 const uint8_t *p_id, uint8_t n_id,
4681 struct uaudio_search_result *info)
4683 struct uaudio_terminal_node *iot;
4690 for (n = 0; n < n_id; n++) {
4694 if (info->recurse_level == UAUDIO_RECURSE_LIMIT) {
4695 DPRINTF("avoided going into a circle at id=%d!\n", i);
4699 info->recurse_level++;
4703 if (iot->u.desc == NULL)
4706 is_last = ((n + 1) == n_id);
4708 switch (iot->u.desc->bDescriptorSubtype) {
4709 case UDESCSUB_AC_INPUT:
4712 p_id = &iot->u.it_v2->bCSourceId;
4716 uaudio20_mixer_find_clocks_sub(root,
4717 &iot->u.it_v2->bCSourceId, 1, info);
4720 case UDESCSUB_AC_OUTPUT:
4723 p_id = &iot->u.ot_v2->bCSourceId;
4727 uaudio20_mixer_find_clocks_sub(root,
4728 &iot->u.ot_v2->bCSourceId, 1, info);
4731 case UDESCSUB_AC_CLOCK_SEL:
4733 p_id = iot->u.csel_v2->baCSourceId;
4734 n_id = iot->u.csel_v2->bNrInPins;
4737 uaudio20_mixer_find_clocks_sub(root,
4738 iot->u.csel_v2->baCSourceId,
4739 iot->u.csel_v2->bNrInPins, info);
4742 case UDESCSUB_AC_CLOCK_MUL:
4744 p_id = &iot->u.cmul_v2->bCSourceId;
4748 uaudio20_mixer_find_clocks_sub(root,
4749 &iot->u.cmul_v2->bCSourceId,
4753 case UDESCSUB_AC_CLOCK_SRC:
4755 id = iot->u.csrc_v2->bClockId;
4757 switch (info->is_input) {
4759 info->bit_output[id / 8] |= (1 << (id % 8));
4762 info->bit_input[id / 8] |= (1 << (id % 8));
4776 uaudio_mixer_find_outputs_sub(struct uaudio_terminal_node *root, uint8_t id,
4777 uint8_t n_id, struct uaudio_search_result *info)
4779 struct uaudio_terminal_node *iot = (root + id);
4784 if ((j != id) && ((root + j)->u.desc) &&
4785 ((root + j)->u.desc->bDescriptorSubtype == UDESCSUB_AC_OUTPUT)) {
4788 * "j" (output) <--- virtual wire <--- "id" (input)
4790 * if "j" has "id" on the input, then "id" have "j" on
4791 * the output, because they are connected:
4793 if ((root + j)->usr.bit_input[id / 8] & (1 << (id % 8))) {
4794 iot->usr.bit_output[j / 8] |= (1 << (j % 8));
4801 uaudio_mixer_fill_info(struct uaudio_softc *sc,
4802 struct usb_device *udev, void *desc)
4804 const struct usb_audio_control_descriptor *acdp;
4805 struct usb_config_descriptor *cd = usbd_get_config_descriptor(udev);
4806 const struct usb_descriptor *dp;
4807 const struct usb_audio_unit *au;
4808 struct uaudio_terminal_node *iot = NULL;
4810 uint8_t ID_max = 0; /* inclusive */
4813 desc = usb_desc_foreach(cd, desc);
4816 DPRINTF("no Audio Control header\n");
4821 if ((acdp->bLength < sizeof(*acdp)) ||
4822 (acdp->bDescriptorType != UDESC_CS_INTERFACE) ||
4823 (acdp->bDescriptorSubtype != UDESCSUB_AC_HEADER)) {
4824 DPRINTF("invalid Audio Control header\n");
4827 /* "wTotalLen" is allowed to be corrupt */
4828 wTotalLen = UGETW(acdp->wTotalLength) - acdp->bLength;
4830 /* get USB audio revision */
4831 sc->sc_audio_rev = UGETW(acdp->bcdADC);
4833 DPRINTFN(3, "found AC header, vers=%03x, len=%d\n",
4834 sc->sc_audio_rev, wTotalLen);
4836 iot = malloc(sizeof(struct uaudio_terminal_node) * 256, M_TEMP,
4840 DPRINTF("no memory!\n");
4843 while ((desc = usb_desc_foreach(cd, desc))) {
4847 if (dp->bLength > wTotalLen) {
4850 wTotalLen -= dp->bLength;
4853 if (sc->sc_audio_rev >= UAUDIO_VERSION_30)
4855 else if (sc->sc_audio_rev >= UAUDIO_VERSION_20)
4856 au = uaudio20_mixer_verify_desc(dp, 0);
4858 au = uaudio_mixer_verify_desc(dp, 0);
4861 iot[au->bUnitId].u.desc = (const void *)au;
4862 if (au->bUnitId > ID_max)
4863 ID_max = au->bUnitId;
4867 DPRINTF("Maximum ID=%d\n", ID_max);
4870 * determine sourcing inputs for
4871 * all nodes in the tree:
4875 if (sc->sc_audio_rev >= UAUDIO_VERSION_30) {
4877 } else if (sc->sc_audio_rev >= UAUDIO_VERSION_20) {
4878 uaudio20_mixer_find_inputs_sub(iot,
4879 &i, 1, &((iot + i)->usr));
4881 sc->sc_mixer_clocks.is_input = 255;
4882 sc->sc_mixer_clocks.recurse_level = 0;
4884 uaudio20_mixer_find_clocks_sub(iot,
4885 &i, 1, &sc->sc_mixer_clocks);
4887 uaudio_mixer_find_inputs_sub(iot,
4888 &i, 1, &((iot + i)->usr));
4893 * determine outputs for
4894 * all nodes in the tree:
4898 uaudio_mixer_find_outputs_sub(iot,
4899 i, ID_max, &((iot + i)->usr));
4902 /* set "id_max" and "root" */
4906 (iot + i)->usr.id_max = ID_max;
4907 (iot + i)->root = iot;
4911 * Scan the config to create a linked list of "mixer" nodes:
4921 DPRINTFN(11, "id=%d subtype=%d\n",
4922 i, dp->bDescriptorSubtype);
4924 if (sc->sc_audio_rev >= UAUDIO_VERSION_30) {
4926 } else if (sc->sc_audio_rev >= UAUDIO_VERSION_20) {
4928 switch (dp->bDescriptorSubtype) {
4929 case UDESCSUB_AC_HEADER:
4930 DPRINTF("unexpected AC header\n");
4933 case UDESCSUB_AC_INPUT:
4934 case UDESCSUB_AC_OUTPUT:
4935 case UDESCSUB_AC_PROCESSING_V2:
4936 case UDESCSUB_AC_EXTENSION_V2:
4937 case UDESCSUB_AC_EFFECT:
4938 case UDESCSUB_AC_CLOCK_SRC:
4939 case UDESCSUB_AC_CLOCK_SEL:
4940 case UDESCSUB_AC_CLOCK_MUL:
4941 case UDESCSUB_AC_SAMPLE_RT:
4944 case UDESCSUB_AC_MIXER:
4945 uaudio20_mixer_add_mixer(sc, iot, i);
4948 case UDESCSUB_AC_SELECTOR:
4949 uaudio20_mixer_add_selector(sc, iot, i);
4952 case UDESCSUB_AC_FEATURE:
4953 uaudio20_mixer_add_feature(sc, iot, i);
4957 DPRINTF("bad AC desc subtype=0x%02x\n",
4958 dp->bDescriptorSubtype);
4964 switch (dp->bDescriptorSubtype) {
4965 case UDESCSUB_AC_HEADER:
4966 DPRINTF("unexpected AC header\n");
4969 case UDESCSUB_AC_INPUT:
4970 case UDESCSUB_AC_OUTPUT:
4973 case UDESCSUB_AC_MIXER:
4974 uaudio_mixer_add_mixer(sc, iot, i);
4977 case UDESCSUB_AC_SELECTOR:
4978 uaudio_mixer_add_selector(sc, iot, i);
4981 case UDESCSUB_AC_FEATURE:
4982 uaudio_mixer_add_feature(sc, iot, i);
4985 case UDESCSUB_AC_PROCESSING:
4986 uaudio_mixer_add_processing(sc, iot, i);
4989 case UDESCSUB_AC_EXTENSION:
4990 uaudio_mixer_add_extension(sc, iot, i);
4994 DPRINTF("bad AC desc subtype=0x%02x\n",
4995 dp->bDescriptorSubtype);
5006 uaudio_mixer_get(struct usb_device *udev, uint16_t audio_rev,
5007 uint8_t what, struct uaudio_mixer_node *mc)
5009 struct usb_device_request req;
5011 uint8_t data[2 + (2 * 3)];
5014 if (mc->wValue[0] == -1)
5017 if (audio_rev >= UAUDIO_VERSION_30)
5019 else if (audio_rev >= UAUDIO_VERSION_20) {
5020 if (what == GET_CUR) {
5021 req.bRequest = UA20_CS_CUR;
5022 USETW(req.wLength, 2);
5024 req.bRequest = UA20_CS_RANGE;
5025 USETW(req.wLength, 8);
5028 uint16_t len = MIX_SIZE(mc->type);
5030 req.bRequest = what;
5031 USETW(req.wLength, len);
5034 req.bmRequestType = UT_READ_CLASS_INTERFACE;
5035 USETW(req.wValue, mc->wValue[0]);
5036 USETW(req.wIndex, mc->wIndex);
5038 memset(data, 0, sizeof(data));
5040 err = usbd_do_request(udev, NULL, &req, data);
5042 DPRINTF("err=%s\n", usbd_errstr(err));
5046 if (audio_rev >= UAUDIO_VERSION_30) {
5048 } else if (audio_rev >= UAUDIO_VERSION_20) {
5051 val = (data[0] | (data[1] << 8));
5054 val = (data[2] | (data[3] << 8));
5057 val = (data[4] | (data[5] << 8));
5060 val = (data[6] | (data[7] << 8));
5067 val = (data[0] | (data[1] << 8));
5070 if (what == GET_CUR || what == GET_MIN || what == GET_MAX)
5071 val = uaudio_mixer_signext(mc->type, val);
5073 DPRINTFN(3, "val=%d\n", val);
5079 uaudio_mixer_write_cfg_callback(struct usb_xfer *xfer, usb_error_t error)
5081 struct usb_device_request req;
5082 struct uaudio_softc *sc = usbd_xfer_softc(xfer);
5083 struct uaudio_mixer_node *mc = sc->sc_mixer_curr;
5084 struct usb_page_cache *pc;
5093 switch (USB_GET_STATE(xfer)) {
5094 case USB_ST_TRANSFERRED:
5100 mc = sc->sc_mixer_root;
5101 sc->sc_mixer_curr = mc;
5102 sc->sc_mixer_chan = 0;
5106 while (sc->sc_mixer_chan < mc->nchan) {
5108 chan = sc->sc_mixer_chan;
5110 sc->sc_mixer_chan++;
5112 update = ((mc->update[chan / 8] & (1 << (chan % 8))) &&
5113 (mc->wValue[chan] != -1));
5115 mc->update[chan / 8] &= ~(1 << (chan % 8));
5119 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
5120 USETW(req.wValue, mc->wValue[chan]);
5121 USETW(req.wIndex, mc->wIndex);
5123 if (sc->sc_audio_rev >= UAUDIO_VERSION_30) {
5125 } else if (sc->sc_audio_rev >= UAUDIO_VERSION_20) {
5127 req.bRequest = UA20_CS_CUR;
5128 USETW(req.wLength, len);
5130 len = MIX_SIZE(mc->type);
5131 req.bRequest = SET_CUR;
5132 USETW(req.wLength, len);
5135 buf[0] = (mc->wData[chan] & 0xFF);
5136 buf[1] = (mc->wData[chan] >> 8) & 0xFF;
5138 pc = usbd_xfer_get_frame(xfer, 0);
5139 usbd_copy_in(pc, 0, &req, sizeof(req));
5140 pc = usbd_xfer_get_frame(xfer, 1);
5141 usbd_copy_in(pc, 0, buf, len);
5143 usbd_xfer_set_frame_len(xfer, 0, sizeof(req));
5144 usbd_xfer_set_frame_len(xfer, 1, len);
5145 usbd_xfer_set_frames(xfer, len ? 2 : 1);
5146 usbd_transfer_submit(xfer);
5152 sc->sc_mixer_curr = mc;
5153 sc->sc_mixer_chan = 0;
5161 default: /* Error */
5162 DPRINTF("error=%s\n", usbd_errstr(error));
5163 if (error == USB_ERR_CANCELLED) {
5164 /* do nothing - we are detaching */
5167 goto tr_transferred;
5172 uaudio_set_speed(struct usb_device *udev, uint8_t endpt, uint32_t speed)
5174 struct usb_device_request req;
5177 DPRINTFN(6, "endpt=%d speed=%u\n", endpt, speed);
5179 req.bmRequestType = UT_WRITE_CLASS_ENDPOINT;
5180 req.bRequest = SET_CUR;
5181 USETW2(req.wValue, SAMPLING_FREQ_CONTROL, 0);
5182 USETW(req.wIndex, endpt);
5183 USETW(req.wLength, 3);
5185 data[1] = speed >> 8;
5186 data[2] = speed >> 16;
5188 return (usbd_do_request(udev, NULL, &req, data));
5192 uaudio20_set_speed(struct usb_device *udev, uint8_t iface_no,
5193 uint8_t clockid, uint32_t speed)
5195 struct usb_device_request req;
5198 DPRINTFN(6, "ifaceno=%d clockid=%d speed=%u\n",
5199 iface_no, clockid, speed);
5201 req.bmRequestType = UT_WRITE_CLASS_INTERFACE;
5202 req.bRequest = UA20_CS_CUR;
5203 USETW2(req.wValue, UA20_CS_SAM_FREQ_CONTROL, 0);
5204 USETW2(req.wIndex, clockid, iface_no);
5205 USETW(req.wLength, 4);
5207 data[1] = speed >> 8;
5208 data[2] = speed >> 16;
5209 data[3] = speed >> 24;
5211 return (usbd_do_request(udev, NULL, &req, data));
5215 uaudio_mixer_signext(uint8_t type, int val)
5217 if (!MIX_UNSIGNED(type)) {
5218 if (MIX_SIZE(type) == 2) {
5228 uaudio_mixer_bsd2value(struct uaudio_mixer_node *mc, int32_t val)
5230 if (mc->type == MIX_ON_OFF) {
5232 } else if (mc->type == MIX_SELECTOR) {
5233 if ((val < mc->minval) ||
5234 (val > mc->maxval)) {
5239 /* compute actual volume */
5240 val = (val * mc->mul) / 255;
5242 /* add lower offset */
5243 val = val + mc->minval;
5245 /* make sure we don't write a value out of range */
5246 if (val > mc->maxval)
5248 else if (val < mc->minval)
5252 DPRINTFN(6, "type=0x%03x val=%d min=%d max=%d val=%d\n",
5253 mc->type, val, mc->minval, mc->maxval, val);
5258 uaudio_mixer_ctl_set(struct uaudio_softc *sc, struct uaudio_mixer_node *mc,
5259 uint8_t chan, int32_t val)
5261 val = uaudio_mixer_bsd2value(mc, val);
5263 mc->update[chan / 8] |= (1 << (chan % 8));
5264 mc->wData[chan] = val;
5266 /* start the transfer, if not already started */
5268 usbd_transfer_start(sc->sc_mixer_xfer[0]);
5272 uaudio_mixer_init(struct uaudio_softc *sc)
5274 struct uaudio_mixer_node *mc;
5277 for (mc = sc->sc_mixer_root; mc;
5280 if (mc->ctl != SOUND_MIXER_NRDEVICES) {
5282 * Set device mask bits. See
5283 * /usr/include/machine/soundcard.h
5285 sc->sc_mix_info |= (1 << mc->ctl);
5287 if ((mc->ctl == SOUND_MIXER_NRDEVICES) &&
5288 (mc->type == MIX_SELECTOR)) {
5290 for (i = mc->minval; (i > 0) && (i <= mc->maxval); i++) {
5291 if (mc->slctrtype[i - 1] == SOUND_MIXER_NRDEVICES) {
5294 sc->sc_recsrc_info |= 1 << mc->slctrtype[i - 1];
5301 uaudio_mixer_init_sub(struct uaudio_softc *sc, struct snd_mixer *m)
5305 sc->sc_mixer_lock = mixer_get_lock(m);
5306 sc->sc_mixer_dev = m;
5308 if (usbd_transfer_setup(sc->sc_udev, &sc->sc_mixer_iface_index,
5309 sc->sc_mixer_xfer, uaudio_mixer_config, 1, sc,
5310 sc->sc_mixer_lock)) {
5311 DPRINTFN(0, "could not allocate USB "
5312 "transfer for audio mixer!\n");
5315 if (!(sc->sc_mix_info & SOUND_MASK_VOLUME)) {
5316 mix_setparentchild(m, SOUND_MIXER_VOLUME, SOUND_MASK_PCM);
5317 mix_setrealdev(m, SOUND_MIXER_VOLUME, SOUND_MIXER_NONE);
5319 mix_setdevs(m, sc->sc_mix_info);
5320 mix_setrecdevs(m, sc->sc_recsrc_info);
5325 uaudio_mixer_uninit_sub(struct uaudio_softc *sc)
5329 usbd_transfer_unsetup(sc->sc_mixer_xfer, 1);
5331 sc->sc_mixer_lock = NULL;
5337 uaudio_mixer_set(struct uaudio_softc *sc, unsigned type,
5338 unsigned left, unsigned right)
5340 struct uaudio_mixer_node *mc;
5343 for (mc = sc->sc_mixer_root; mc != NULL; mc = mc->next) {
5345 if (mc->ctl == type) {
5346 for (chan = 0; chan < mc->nchan; chan++) {
5347 uaudio_mixer_ctl_set(sc, mc, chan,
5348 (int)((chan == 0 ? left : right) *
5356 uaudio_mixer_setrecsrc(struct uaudio_softc *sc, uint32_t src)
5358 struct uaudio_mixer_node *mc;
5363 for (mc = sc->sc_mixer_root; mc;
5366 if ((mc->ctl == SOUND_MIXER_NRDEVICES) &&
5367 (mc->type == MIX_SELECTOR)) {
5369 /* compute selector mask */
5372 for (i = mc->minval; (i > 0) && (i <= mc->maxval); i++) {
5373 mask |= (1 << mc->slctrtype[i - 1]);
5380 /* find the first set bit */
5381 temp = (-temp) & temp;
5387 for (i = mc->minval; (i > 0) && (i <= mc->maxval); i++) {
5388 if (temp != (1 << mc->slctrtype[i - 1])) {
5391 uaudio_mixer_ctl_set(sc, mc, 0, i);
5399 /*========================================================================*
5400 * MIDI support routines
5401 *========================================================================*/
5404 umidi_bulk_read_callback(struct usb_xfer *xfer, usb_error_t error)
5406 struct umidi_chan *chan = usbd_xfer_softc(xfer);
5407 struct umidi_sub_chan *sub;
5408 struct usb_page_cache *pc;
5415 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
5417 switch (USB_GET_STATE(xfer)) {
5418 case USB_ST_TRANSFERRED:
5420 DPRINTF("actlen=%d bytes\n", actlen);
5423 pc = usbd_xfer_get_frame(xfer, 0);
5425 while (actlen >= 4) {
5427 /* copy out the MIDI data */
5428 usbd_copy_out(pc, pos, buf, 4);
5429 /* command length */
5430 cmd_len = umidi_cmd_to_len[buf[0] & 0xF];
5434 * Lookup sub-channel. The index is range
5437 sub = &chan->sub[cn];
5439 if ((cmd_len != 0) && (cn < chan->max_emb_jack) &&
5440 (sub->read_open != 0)) {
5442 /* Send data to the application */
5443 usb_fifo_put_data_linear(
5444 sub->fifo.fp[USB_FIFO_RX],
5445 buf + 1, cmd_len, 1);
5454 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
5455 usbd_transfer_submit(xfer);
5459 DPRINTF("error=%s\n", usbd_errstr(error));
5461 if (error != USB_ERR_CANCELLED) {
5462 /* try to clear stall first */
5463 usbd_xfer_set_stall(xfer);
5471 * The following statemachine, that converts MIDI commands to
5472 * USB MIDI packets, derives from Linux's usbmidi.c, which
5473 * was written by "Clemens Ladisch":
5477 * Else: Command is complete
5480 umidi_convert_to_usb(struct umidi_sub_chan *sub, uint8_t cn, uint8_t b)
5482 uint8_t p0 = (cn << 4);
5485 sub->temp_0[0] = p0 | 0x0f;
5489 sub->temp_cmd = sub->temp_0;
5492 } else if (b >= 0xf0) {
5494 case 0xf0: /* system exclusive begin */
5496 sub->state = UMIDI_ST_SYSEX_1;
5498 case 0xf1: /* MIDI time code */
5499 case 0xf3: /* song select */
5501 sub->state = UMIDI_ST_1PARAM;
5503 case 0xf2: /* song position pointer */
5505 sub->state = UMIDI_ST_2PARAM_1;
5507 case 0xf4: /* unknown */
5508 case 0xf5: /* unknown */
5509 sub->state = UMIDI_ST_UNKNOWN;
5511 case 0xf6: /* tune request */
5512 sub->temp_1[0] = p0 | 0x05;
5513 sub->temp_1[1] = 0xf6;
5516 sub->temp_cmd = sub->temp_1;
5517 sub->state = UMIDI_ST_UNKNOWN;
5520 case 0xf7: /* system exclusive end */
5521 switch (sub->state) {
5522 case UMIDI_ST_SYSEX_0:
5523 sub->temp_1[0] = p0 | 0x05;
5524 sub->temp_1[1] = 0xf7;
5527 sub->temp_cmd = sub->temp_1;
5528 sub->state = UMIDI_ST_UNKNOWN;
5530 case UMIDI_ST_SYSEX_1:
5531 sub->temp_1[0] = p0 | 0x06;
5532 sub->temp_1[2] = 0xf7;
5534 sub->temp_cmd = sub->temp_1;
5535 sub->state = UMIDI_ST_UNKNOWN;
5537 case UMIDI_ST_SYSEX_2:
5538 sub->temp_1[0] = p0 | 0x07;
5539 sub->temp_1[3] = 0xf7;
5540 sub->temp_cmd = sub->temp_1;
5541 sub->state = UMIDI_ST_UNKNOWN;
5544 sub->state = UMIDI_ST_UNKNOWN;
5547 } else if (b >= 0x80) {
5549 if ((b >= 0xc0) && (b <= 0xdf)) {
5550 sub->state = UMIDI_ST_1PARAM;
5552 sub->state = UMIDI_ST_2PARAM_1;
5554 } else { /* b < 0x80 */
5555 switch (sub->state) {
5556 case UMIDI_ST_1PARAM:
5557 if (sub->temp_1[1] < 0xf0) {
5558 p0 |= sub->temp_1[1] >> 4;
5561 sub->state = UMIDI_ST_UNKNOWN;
5563 sub->temp_1[0] = p0;
5566 sub->temp_cmd = sub->temp_1;
5568 case UMIDI_ST_2PARAM_1:
5570 sub->state = UMIDI_ST_2PARAM_2;
5572 case UMIDI_ST_2PARAM_2:
5573 if (sub->temp_1[1] < 0xf0) {
5574 p0 |= sub->temp_1[1] >> 4;
5575 sub->state = UMIDI_ST_2PARAM_1;
5578 sub->state = UMIDI_ST_UNKNOWN;
5580 sub->temp_1[0] = p0;
5582 sub->temp_cmd = sub->temp_1;
5584 case UMIDI_ST_SYSEX_0:
5586 sub->state = UMIDI_ST_SYSEX_1;
5588 case UMIDI_ST_SYSEX_1:
5590 sub->state = UMIDI_ST_SYSEX_2;
5592 case UMIDI_ST_SYSEX_2:
5593 sub->temp_1[0] = p0 | 0x04;
5595 sub->temp_cmd = sub->temp_1;
5596 sub->state = UMIDI_ST_SYSEX_0;
5606 umidi_bulk_write_callback(struct usb_xfer *xfer, usb_error_t error)
5608 struct umidi_chan *chan = usbd_xfer_softc(xfer);
5609 struct umidi_sub_chan *sub;
5610 struct usb_page_cache *pc;
5614 uint8_t start_cable;
5618 usbd_xfer_status(xfer, &len, NULL, NULL, NULL);
5621 * NOTE: Some MIDI devices only accept 4 bytes of data per
5622 * short terminated USB transfer.
5624 switch (USB_GET_STATE(xfer)) {
5625 case USB_ST_TRANSFERRED:
5626 DPRINTF("actlen=%d bytes\n", len);
5632 nframes = 0; /* reset */
5633 start_cable = chan->curr_cable;
5635 pc = usbd_xfer_get_frame(xfer, 0);
5639 /* round robin de-queueing */
5641 sub = &chan->sub[chan->curr_cable];
5643 if (sub->write_open) {
5644 usb_fifo_get_data_linear(sub->fifo.fp[USB_FIFO_TX],
5645 &buf, 1, &actlen, 0);
5654 DPRINTF("byte=0x%02x from FIFO %u\n", buf,
5655 (unsigned int)chan->curr_cable);
5657 if (umidi_convert_to_usb(sub, chan->curr_cable, buf)) {
5659 DPRINTF("sub=0x%02x 0x%02x 0x%02x 0x%02x\n",
5660 sub->temp_cmd[0], sub->temp_cmd[1],
5661 sub->temp_cmd[2], sub->temp_cmd[3]);
5663 usbd_copy_in(pc, nframes * 4, sub->temp_cmd, 4);
5667 if ((nframes >= UMIDI_TX_FRAMES) || (chan->single_command != 0))
5675 if (chan->curr_cable >= chan->max_emb_jack)
5676 chan->curr_cable = 0;
5678 if (chan->curr_cable == start_cable) {
5686 DPRINTF("Transferring %d frames\n", (int)nframes);
5687 usbd_xfer_set_frame_len(xfer, 0, 4 * nframes);
5688 usbd_transfer_submit(xfer);
5692 default: /* Error */
5694 DPRINTF("error=%s\n", usbd_errstr(error));
5696 if (error != USB_ERR_CANCELLED) {
5697 /* try to clear stall first */
5698 usbd_xfer_set_stall(xfer);
5705 static struct umidi_sub_chan *
5706 umidi_sub_by_fifo(struct usb_fifo *fifo)
5708 struct umidi_chan *chan = usb_fifo_softc(fifo);
5709 struct umidi_sub_chan *sub;
5712 for (n = 0; n < UMIDI_EMB_JACK_MAX; n++) {
5713 sub = &chan->sub[n];
5714 if ((sub->fifo.fp[USB_FIFO_RX] == fifo) ||
5715 (sub->fifo.fp[USB_FIFO_TX] == fifo)) {
5720 panic("%s:%d cannot find usb_fifo!\n",
5721 __FILE__, __LINE__);
5727 umidi_start_read(struct usb_fifo *fifo)
5729 struct umidi_chan *chan = usb_fifo_softc(fifo);
5731 usbd_transfer_start(chan->xfer[UMIDI_RX_TRANSFER]);
5735 umidi_stop_read(struct usb_fifo *fifo)
5737 struct umidi_chan *chan = usb_fifo_softc(fifo);
5738 struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
5744 if (--(chan->read_open_refcount) == 0) {
5746 * XXX don't stop the read transfer here, hence that causes
5747 * problems with some MIDI adapters
5749 DPRINTF("(stopping read transfer)\n");
5754 umidi_start_write(struct usb_fifo *fifo)
5756 struct umidi_chan *chan = usb_fifo_softc(fifo);
5758 if (chan->xfer[UMIDI_TX_TRANSFER] == NULL) {
5763 usb_fifo_get_data_linear(fifo, buf, 1, &actlen, 0);
5764 } while (actlen > 0);
5766 usbd_transfer_start(chan->xfer[UMIDI_TX_TRANSFER]);
5771 umidi_stop_write(struct usb_fifo *fifo)
5773 struct umidi_chan *chan = usb_fifo_softc(fifo);
5774 struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
5778 sub->write_open = 0;
5780 if (--(chan->write_open_refcount) == 0) {
5781 DPRINTF("(stopping write transfer)\n");
5782 usbd_transfer_stop(chan->xfer[UMIDI_TX_TRANSFER]);
5787 umidi_open(struct usb_fifo *fifo, int fflags)
5789 struct umidi_chan *chan = usb_fifo_softc(fifo);
5790 struct umidi_sub_chan *sub = umidi_sub_by_fifo(fifo);
5792 if (fflags & FREAD) {
5793 if (usb_fifo_alloc_buffer(fifo, 4, (1024 / 4))) {
5796 mtx_lock(&chan->mtx);
5797 chan->read_open_refcount++;
5799 mtx_unlock(&chan->mtx);
5801 if (fflags & FWRITE) {
5802 if (usb_fifo_alloc_buffer(fifo, 32, (1024 / 32))) {
5805 /* clear stall first */
5806 mtx_lock(&chan->mtx);
5807 chan->write_open_refcount++;
5808 sub->write_open = 1;
5811 sub->state = UMIDI_ST_UNKNOWN;
5812 mtx_unlock(&chan->mtx);
5814 return (0); /* success */
5818 umidi_close(struct usb_fifo *fifo, int fflags)
5820 if (fflags & FREAD) {
5821 usb_fifo_free_buffer(fifo);
5823 if (fflags & FWRITE) {
5824 usb_fifo_free_buffer(fifo);
5830 umidi_ioctl(struct usb_fifo *fifo, u_long cmd, void *data,
5837 umidi_init(device_t dev)
5839 struct uaudio_softc *sc = device_get_softc(dev);
5840 struct umidi_chan *chan = &sc->sc_midi_chan;
5842 mtx_init(&chan->mtx, "umidi lock", NULL, MTX_DEF | MTX_RECURSE);
5845 static struct usb_fifo_methods umidi_fifo_methods = {
5846 .f_start_read = &umidi_start_read,
5847 .f_start_write = &umidi_start_write,
5848 .f_stop_read = &umidi_stop_read,
5849 .f_stop_write = &umidi_stop_write,
5850 .f_open = &umidi_open,
5851 .f_close = &umidi_close,
5852 .f_ioctl = &umidi_ioctl,
5853 .basename[0] = "umidi",
5857 umidi_probe(device_t dev)
5859 struct uaudio_softc *sc = device_get_softc(dev);
5860 struct usb_attach_arg *uaa = device_get_ivars(dev);
5861 struct umidi_chan *chan = &sc->sc_midi_chan;
5862 struct umidi_sub_chan *sub;
5863 int unit = device_get_unit(dev);
5867 if (usb_test_quirk(uaa, UQ_SINGLE_CMD_MIDI))
5868 chan->single_command = 1;
5870 if (usbd_set_alt_interface_index(sc->sc_udev, chan->iface_index,
5871 chan->iface_alt_index)) {
5872 DPRINTF("setting of alternate index failed!\n");
5875 usbd_set_parent_iface(sc->sc_udev, chan->iface_index,
5876 sc->sc_mixer_iface_index);
5878 error = usbd_transfer_setup(uaa->device, &chan->iface_index,
5879 chan->xfer, umidi_config, UMIDI_N_TRANSFER,
5882 DPRINTF("error=%s\n", usbd_errstr(error));
5885 if (chan->xfer[UMIDI_TX_TRANSFER] == NULL &&
5886 chan->xfer[UMIDI_RX_TRANSFER] == NULL) {
5887 DPRINTF("no BULK or INTERRUPT MIDI endpoint(s) found\n");
5892 * Some USB MIDI device makers couldn't resist using
5893 * wMaxPacketSize = 4 for RX and TX BULK endpoints, although
5894 * that size is an unsupported value for FULL speed BULK
5895 * endpoints. The same applies to some HIGH speed MIDI devices
5896 * which are using a wMaxPacketSize different from 512 bytes.
5898 * Refer to section 5.8.3 in USB 2.0 PDF: Cite: "All Host
5899 * Controllers are required to have support for 8-, 16-, 32-,
5900 * and 64-byte maximum packet sizes for full-speed bulk
5901 * endpoints and 512 bytes for high-speed bulk endpoints."
5903 if (chan->xfer[UMIDI_TX_TRANSFER] != NULL &&
5904 usbd_xfer_maxp_was_clamped(chan->xfer[UMIDI_TX_TRANSFER]))
5905 chan->single_command = 1;
5907 if (chan->single_command != 0)
5908 device_printf(dev, "Single command MIDI quirk enabled\n");
5910 if ((chan->max_emb_jack == 0) ||
5911 (chan->max_emb_jack > UMIDI_EMB_JACK_MAX)) {
5912 chan->max_emb_jack = UMIDI_EMB_JACK_MAX;
5915 for (n = 0; n < chan->max_emb_jack; n++) {
5917 sub = &chan->sub[n];
5919 error = usb_fifo_attach(sc->sc_udev, chan, &chan->mtx,
5920 &umidi_fifo_methods, &sub->fifo, unit, n,
5922 UID_ROOT, GID_OPERATOR, 0644);
5928 mtx_lock(&chan->mtx);
5931 * NOTE: At least one device will not work properly unless the
5932 * BULK IN pipe is open all the time. This might have to do
5933 * about that the internal queues of the device overflow if we
5934 * don't read them regularly.
5936 usbd_transfer_start(chan->xfer[UMIDI_RX_TRANSFER]);
5938 mtx_unlock(&chan->mtx);
5940 return (0); /* success */
5943 return (ENXIO); /* failure */
5947 umidi_detach(device_t dev)
5949 struct uaudio_softc *sc = device_get_softc(dev);
5950 struct umidi_chan *chan = &sc->sc_midi_chan;
5953 for (n = 0; n < UMIDI_EMB_JACK_MAX; n++)
5954 usb_fifo_detach(&chan->sub[n].fifo);
5956 mtx_lock(&chan->mtx);
5958 usbd_transfer_stop(chan->xfer[UMIDI_RX_TRANSFER]);
5960 mtx_unlock(&chan->mtx);
5962 usbd_transfer_unsetup(chan->xfer, UMIDI_N_TRANSFER);
5964 mtx_destroy(&chan->mtx);
5970 uaudio_hid_rx_callback(struct usb_xfer *xfer, usb_error_t error)
5972 struct uaudio_softc *sc = usbd_xfer_softc(xfer);
5973 const uint8_t *buffer = usbd_xfer_get_frame_buffer(xfer, 0);
5974 struct snd_mixer *m;
5978 usbd_xfer_status(xfer, &actlen, NULL, NULL, NULL);
5980 switch (USB_GET_STATE(xfer)) {
5981 case USB_ST_TRANSFERRED:
5982 DPRINTF("actlen=%d\n", actlen);
5985 (sc->sc_hid.flags & UAUDIO_HID_HAS_ID)) {
5993 m = sc->sc_mixer_dev;
5995 if ((sc->sc_hid.flags & UAUDIO_HID_HAS_MUTE) &&
5996 (sc->sc_hid.mute_id == id) &&
5997 hid_get_data(buffer, actlen,
5998 &sc->sc_hid.mute_loc)) {
6000 DPRINTF("Mute toggle\n");
6002 mixer_hwvol_mute_locked(m);
6005 if ((sc->sc_hid.flags & UAUDIO_HID_HAS_VOLUME_UP) &&
6006 (sc->sc_hid.volume_up_id == id) &&
6007 hid_get_data(buffer, actlen,
6008 &sc->sc_hid.volume_up_loc)) {
6010 DPRINTF("Volume Up\n");
6012 mixer_hwvol_step_locked(m, 1, 1);
6015 if ((sc->sc_hid.flags & UAUDIO_HID_HAS_VOLUME_DOWN) &&
6016 (sc->sc_hid.volume_down_id == id) &&
6017 hid_get_data(buffer, actlen,
6018 &sc->sc_hid.volume_down_loc)) {
6020 DPRINTF("Volume Down\n");
6022 mixer_hwvol_step_locked(m, -1, -1);
6027 /* check if we can put more data into the FIFO */
6028 usbd_xfer_set_frame_len(xfer, 0, usbd_xfer_max_len(xfer));
6029 usbd_transfer_submit(xfer);
6032 default: /* Error */
6034 DPRINTF("error=%s\n", usbd_errstr(error));
6036 if (error != USB_ERR_CANCELLED) {
6037 /* try to clear stall first */
6038 usbd_xfer_set_stall(xfer);
6046 uaudio_hid_probe(struct uaudio_softc *sc,
6047 struct usb_attach_arg *uaa)
6055 if (!(sc->sc_hid.flags & UAUDIO_HID_VALID))
6058 if (sc->sc_mixer_lock == NULL)
6061 /* Get HID descriptor */
6062 error = usbd_req_get_hid_desc(uaa->device, NULL, &d_ptr,
6063 &d_len, M_TEMP, sc->sc_hid.iface_index);
6066 DPRINTF("error reading report description\n");
6070 /* check if there is an ID byte */
6071 hid_report_size(d_ptr, d_len, hid_input, &id);
6074 sc->sc_hid.flags |= UAUDIO_HID_HAS_ID;
6076 if (hid_locate(d_ptr, d_len,
6077 HID_USAGE2(HUP_CONSUMER, 0xE9 /* Volume Increment */),
6078 hid_input, 0, &sc->sc_hid.volume_up_loc, &flags,
6079 &sc->sc_hid.volume_up_id)) {
6080 if (flags & HIO_VARIABLE)
6081 sc->sc_hid.flags |= UAUDIO_HID_HAS_VOLUME_UP;
6082 DPRINTFN(1, "Found Volume Up key\n");
6085 if (hid_locate(d_ptr, d_len,
6086 HID_USAGE2(HUP_CONSUMER, 0xEA /* Volume Decrement */),
6087 hid_input, 0, &sc->sc_hid.volume_down_loc, &flags,
6088 &sc->sc_hid.volume_down_id)) {
6089 if (flags & HIO_VARIABLE)
6090 sc->sc_hid.flags |= UAUDIO_HID_HAS_VOLUME_DOWN;
6091 DPRINTFN(1, "Found Volume Down key\n");
6094 if (hid_locate(d_ptr, d_len,
6095 HID_USAGE2(HUP_CONSUMER, 0xE2 /* Mute */),
6096 hid_input, 0, &sc->sc_hid.mute_loc, &flags,
6097 &sc->sc_hid.mute_id)) {
6098 if (flags & HIO_VARIABLE)
6099 sc->sc_hid.flags |= UAUDIO_HID_HAS_MUTE;
6100 DPRINTFN(1, "Found Mute key\n");
6103 free(d_ptr, M_TEMP);
6105 if (!(sc->sc_hid.flags & (UAUDIO_HID_HAS_VOLUME_UP |
6106 UAUDIO_HID_HAS_VOLUME_DOWN |
6107 UAUDIO_HID_HAS_MUTE))) {
6108 DPRINTFN(1, "Did not find any volume related keys\n");
6112 /* prevent the uhid driver from attaching */
6113 usbd_set_parent_iface(uaa->device, sc->sc_hid.iface_index,
6114 sc->sc_mixer_iface_index);
6116 /* allocate USB transfers */
6117 error = usbd_transfer_setup(uaa->device, &sc->sc_hid.iface_index,
6118 sc->sc_hid.xfer, uaudio_hid_config, UAUDIO_HID_N_TRANSFER,
6119 sc, sc->sc_mixer_lock);
6121 DPRINTF("error=%s\n", usbd_errstr(error));
6128 uaudio_hid_detach(struct uaudio_softc *sc)
6130 usbd_transfer_unsetup(sc->sc_hid.xfer, UAUDIO_HID_N_TRANSFER);
6133 DRIVER_MODULE_ORDERED(uaudio, uhub, uaudio_driver, uaudio_devclass, NULL, 0, SI_ORDER_ANY);
6134 MODULE_DEPEND(uaudio, usb, 1, 1, 1);
6135 MODULE_DEPEND(uaudio, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
6136 MODULE_VERSION(uaudio, 1);
6137 USB_PNP_HOST_INFO(uaudio_devs);