forked from freebsd/freebsd-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uaudio.c
6263 lines (5231 loc) · 153 KB
/
uaudio.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $NetBSD: uaudio.c,v 1.91 2004/11/05 17:46:14 kent Exp $ */
/* $FreeBSD$ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-NetBSD
*
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Lennart Augustsson (lennart@augustsson.net) at
* Carlstedt Research & Technology.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* USB audio specs: http://www.usb.org/developers/devclass_docs/audio10.pdf
* http://www.usb.org/developers/devclass_docs/frmts10.pdf
* http://www.usb.org/developers/devclass_docs/termt10.pdf
*/
/*
* Also merged:
* $NetBSD: uaudio.c,v 1.94 2005/01/15 15:19:53 kent Exp $
* $NetBSD: uaudio.c,v 1.95 2005/01/16 06:02:19 dsainty Exp $
* $NetBSD: uaudio.c,v 1.96 2005/01/16 12:46:00 kent Exp $
* $NetBSD: uaudio.c,v 1.97 2005/02/24 08:19:38 martin Exp $
*/
#include <sys/stdint.h>
#include <sys/stddef.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/bus.h>
#include <sys/module.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/condvar.h>
#include <sys/sysctl.h>
#include <sys/sx.h>
#include <sys/unistd.h>
#include <sys/callout.h>
#include <sys/malloc.h>
#include <sys/priv.h>
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbhid.h>
#include <dev/usb/usb_request.h>
#include <dev/usb/usb_process.h>
#define USB_DEBUG_VAR uaudio_debug
#include <dev/usb/usb_debug.h>
#include <dev/usb/quirk/usb_quirk.h>
#include <sys/reboot.h> /* for bootverbose */
#ifdef HAVE_KERNEL_OPTION_HEADERS
#include "opt_snd.h"
#endif
#include <dev/sound/pcm/sound.h>
#include <dev/sound/usb/uaudioreg.h>
#include <dev/sound/usb/uaudio.h>
#include <dev/sound/chip.h>
#include "feeder_if.h"
static int uaudio_default_rate = 0; /* use rate list */
static int uaudio_default_bits = 32;
static int uaudio_default_channels = 0; /* use default */
static int uaudio_buffer_ms = 8;
static bool uaudio_handle_hid = true;
static SYSCTL_NODE(_hw_usb, OID_AUTO, uaudio, CTLFLAG_RW, 0, "USB uaudio");
SYSCTL_BOOL(_hw_usb_uaudio, OID_AUTO, handle_hid, CTLFLAG_RWTUN,
&uaudio_handle_hid, 0, "uaudio handles any HID volume/mute keys, if set");
SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_rate, CTLFLAG_RWTUN,
&uaudio_default_rate, 0, "uaudio default sample rate");
SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_bits, CTLFLAG_RWTUN,
&uaudio_default_bits, 0, "uaudio default sample bits");
SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, default_channels, CTLFLAG_RWTUN,
&uaudio_default_channels, 0, "uaudio default sample channels");
static int
uaudio_buffer_ms_sysctl(SYSCTL_HANDLER_ARGS)
{
int err, val;
val = uaudio_buffer_ms;
err = sysctl_handle_int(oidp, &val, 0, req);
if (err != 0 || req->newptr == NULL || val == uaudio_buffer_ms)
return (err);
if (val > 8)
val = 8;
else if (val < 2)
val = 2;
uaudio_buffer_ms = val;
return (0);
}
SYSCTL_PROC(_hw_usb_uaudio, OID_AUTO, buffer_ms, CTLTYPE_INT | CTLFLAG_RWTUN,
0, sizeof(int), uaudio_buffer_ms_sysctl, "I",
"uaudio buffering delay from 2ms to 8ms");
#ifdef USB_DEBUG
static int uaudio_debug;
SYSCTL_INT(_hw_usb_uaudio, OID_AUTO, debug, CTLFLAG_RWTUN,
&uaudio_debug, 0, "uaudio debug level");
#else
#define uaudio_debug 0
#endif
#define UAUDIO_NFRAMES 64 /* must be factor of 8 due HS-USB */
#define UAUDIO_NCHANBUFS 2 /* number of outstanding request */
#define UAUDIO_RECURSE_LIMIT 255 /* rounds */
#define UAUDIO_CHANNELS_MAX MIN(64, AFMT_CHANNEL_MAX)
#define UAUDIO_MATRIX_MAX 8 /* channels */
#define MAKE_WORD(h,l) (((h) << 8) | (l))
#define BIT_TEST(bm,bno) (((bm)[(bno) / 8] >> (7 - ((bno) % 8))) & 1)
#define UAUDIO_MAX_CHAN(x) (x)
#define MIX(sc) ((sc)->sc_mixer_node)
union uaudio_asid {
const struct usb_audio_streaming_interface_descriptor *v1;
const struct usb_audio20_streaming_interface_descriptor *v2;
};
union uaudio_asf1d {
const struct usb_audio_streaming_type1_descriptor *v1;
const struct usb_audio20_streaming_type1_descriptor *v2;
};
union uaudio_sed {
const struct usb_audio_streaming_endpoint_descriptor *v1;
const struct usb_audio20_streaming_endpoint_descriptor *v2;
};
struct uaudio_mixer_node {
const char *name;
int32_t minval;
int32_t maxval;
#define MIX_MAX_CHAN 16
int32_t wValue[MIX_MAX_CHAN]; /* using nchan */
uint32_t mul;
uint32_t ctl;
int wData[MIX_MAX_CHAN]; /* using nchan */
uint16_t wIndex;
uint8_t update[(MIX_MAX_CHAN + 7) / 8];
uint8_t nchan;
uint8_t type;
#define MIX_ON_OFF 1
#define MIX_SIGNED_16 2
#define MIX_UNSIGNED_16 3
#define MIX_SIGNED_8 4
#define MIX_SELECTOR 5
#define MIX_UNKNOWN 6
#define MIX_SIZE(n) ((((n) == MIX_SIGNED_16) || \
((n) == MIX_UNSIGNED_16)) ? 2 : 1)
#define MIX_UNSIGNED(n) ((n) == MIX_UNSIGNED_16)
#define MAX_SELECTOR_INPUT_PIN 256
uint8_t slctrtype[MAX_SELECTOR_INPUT_PIN];
uint8_t val_default;
uint8_t desc[64];
struct uaudio_mixer_node *next;
};
struct uaudio_configure_msg {
struct usb_proc_msg hdr;
struct uaudio_softc *sc;
};
#define CHAN_MAX_ALT 24
struct uaudio_chan_alt {
union uaudio_asf1d p_asf1d;
union uaudio_sed p_sed;
const usb_endpoint_descriptor_audio_t *p_ed1;
const struct uaudio_format *p_fmt;
const struct usb_config *usb_cfg;
uint32_t sample_rate; /* in Hz */
uint16_t sample_size;
uint8_t iface_index;
uint8_t iface_alt_index;
uint8_t channels;
};
struct uaudio_chan {
struct pcmchan_caps pcm_cap; /* capabilities */
struct uaudio_chan_alt usb_alt[CHAN_MAX_ALT];
struct snd_dbuf *pcm_buf;
struct mtx *pcm_mtx; /* lock protecting this structure */
struct uaudio_softc *priv_sc;
struct pcm_channel *pcm_ch;
struct usb_xfer *xfer[UAUDIO_NCHANBUFS + 1];
uint8_t *buf; /* pointer to buffer */
uint8_t *start; /* upper layer buffer start */
uint8_t *end; /* upper layer buffer end */
uint8_t *cur; /* current position in upper layer
* buffer */
uint32_t intr_frames; /* in units */
uint32_t frames_per_second;
uint32_t sample_rem;
uint32_t sample_curr;
uint32_t max_buf;
int32_t jitter_rem;
int32_t jitter_curr;
int feedback_rate;
uint32_t pcm_format[2];
uint16_t bytes_per_frame[2];
uint32_t intr_counter;
uint32_t running;
uint32_t num_alt;
uint32_t cur_alt;
uint32_t set_alt;
uint32_t operation;
#define CHAN_OP_NONE 0
#define CHAN_OP_START 1
#define CHAN_OP_STOP 2
#define CHAN_OP_DRAIN 3
uint8_t iface_index;
};
#define UMIDI_EMB_JACK_MAX 16 /* units */
#define UMIDI_TX_FRAMES 256 /* units */
#define UMIDI_TX_BUFFER (UMIDI_TX_FRAMES * 4) /* bytes */
enum {
UMIDI_TX_TRANSFER,
UMIDI_RX_TRANSFER,
UMIDI_N_TRANSFER,
};
struct umidi_sub_chan {
struct usb_fifo_sc fifo;
uint8_t *temp_cmd;
uint8_t temp_0[4];
uint8_t temp_1[4];
uint8_t state;
#define UMIDI_ST_UNKNOWN 0 /* scan for command */
#define UMIDI_ST_1PARAM 1
#define UMIDI_ST_2PARAM_1 2
#define UMIDI_ST_2PARAM_2 3
#define UMIDI_ST_SYSEX_0 4
#define UMIDI_ST_SYSEX_1 5
#define UMIDI_ST_SYSEX_2 6
uint8_t read_open:1;
uint8_t write_open:1;
uint8_t unused:6;
};
struct umidi_chan {
struct umidi_sub_chan sub[UMIDI_EMB_JACK_MAX];
struct mtx mtx;
struct usb_xfer *xfer[UMIDI_N_TRANSFER];
uint8_t iface_index;
uint8_t iface_alt_index;
uint8_t read_open_refcount;
uint8_t write_open_refcount;
uint8_t curr_cable;
uint8_t max_emb_jack;
uint8_t valid;
uint8_t single_command;
};
struct uaudio_search_result {
uint8_t bit_input[(256 + 7) / 8];
uint8_t bit_output[(256 + 7) / 8];
uint8_t recurse_level;
uint8_t id_max;
uint8_t is_input;
};
enum {
UAUDIO_HID_RX_TRANSFER,
UAUDIO_HID_N_TRANSFER,
};
struct uaudio_hid {
struct usb_xfer *xfer[UAUDIO_HID_N_TRANSFER];
struct hid_location volume_up_loc;
struct hid_location volume_down_loc;
struct hid_location mute_loc;
uint32_t flags;
#define UAUDIO_HID_VALID 0x0001
#define UAUDIO_HID_HAS_ID 0x0002
#define UAUDIO_HID_HAS_VOLUME_UP 0x0004
#define UAUDIO_HID_HAS_VOLUME_DOWN 0x0008
#define UAUDIO_HID_HAS_MUTE 0x0010
uint8_t iface_index;
uint8_t volume_up_id;
uint8_t volume_down_id;
uint8_t mute_id;
};
#define UAUDIO_SPDIF_OUT 0x01 /* Enable S/PDIF output */
#define UAUDIO_SPDIF_OUT_48K 0x02 /* Out sample rate = 48K */
#define UAUDIO_SPDIF_OUT_96K 0x04 /* Out sample rate = 96K */
#define UAUDIO_SPDIF_IN_MIX 0x10 /* Input mix enable */
#define UAUDIO_MAX_CHILD 2
struct uaudio_softc_child {
device_t pcm_device;
struct mtx *mixer_lock;
struct snd_mixer *mixer_dev;
uint32_t mix_info;
uint32_t recsrc_info;
uint8_t pcm_registered:1;
uint8_t mixer_init:1;
};
struct uaudio_softc {
struct sbuf sc_sndstat;
struct sndcard_func sc_sndcard_func;
struct uaudio_chan sc_rec_chan[UAUDIO_MAX_CHILD];
struct uaudio_chan sc_play_chan[UAUDIO_MAX_CHILD];
struct umidi_chan sc_midi_chan;
struct uaudio_hid sc_hid;
struct uaudio_search_result sc_mixer_clocks;
struct uaudio_mixer_node sc_mixer_node;
struct uaudio_configure_msg sc_config_msg[2];
struct uaudio_softc_child sc_child[UAUDIO_MAX_CHILD];
struct usb_device *sc_udev;
struct usb_xfer *sc_mixer_xfer[1];
struct uaudio_mixer_node *sc_mixer_root;
struct uaudio_mixer_node *sc_mixer_curr;
int (*sc_set_spdif_fn) (struct uaudio_softc *, int);
uint16_t sc_audio_rev;
uint16_t sc_mixer_count;
uint8_t sc_mixer_iface_index;
uint8_t sc_mixer_iface_no;
uint8_t sc_mixer_chan;
uint8_t sc_sndstat_valid:1;
uint8_t sc_uq_audio_swap_lr:1;
uint8_t sc_uq_au_inp_async:1;
uint8_t sc_uq_au_no_xu:1;
uint8_t sc_uq_bad_adc:1;
uint8_t sc_uq_au_vendor_class:1;
uint8_t sc_pcm_bitperfect:1;
};
struct uaudio_terminal_node {
union {
const struct usb_descriptor *desc;
const struct usb_audio_input_terminal *it_v1;
const struct usb_audio_output_terminal *ot_v1;
const struct usb_audio_mixer_unit_0 *mu_v1;
const struct usb_audio_selector_unit *su_v1;
const struct usb_audio_feature_unit *fu_v1;
const struct usb_audio_processing_unit_0 *pu_v1;
const struct usb_audio_extension_unit_0 *eu_v1;
const struct usb_audio20_clock_source_unit *csrc_v2;
const struct usb_audio20_clock_selector_unit_0 *csel_v2;
const struct usb_audio20_clock_multiplier_unit *cmul_v2;
const struct usb_audio20_input_terminal *it_v2;
const struct usb_audio20_output_terminal *ot_v2;
const struct usb_audio20_mixer_unit_0 *mu_v2;
const struct usb_audio20_selector_unit *su_v2;
const struct usb_audio20_feature_unit *fu_v2;
const struct usb_audio20_sample_rate_unit *ru_v2;
const struct usb_audio20_processing_unit_0 *pu_v2;
const struct usb_audio20_extension_unit_0 *eu_v2;
const struct usb_audio20_effect_unit *ef_v2;
} u;
struct uaudio_search_result usr;
struct uaudio_terminal_node *root;
};
struct uaudio_format {
uint16_t wFormat;
uint8_t bPrecision;
uint32_t freebsd_fmt;
const char *description;
};
static const struct uaudio_format uaudio10_formats[] = {
{UA_FMT_PCM8, 8, AFMT_U8, "8-bit U-LE PCM"},
{UA_FMT_PCM8, 16, AFMT_U16_LE, "16-bit U-LE PCM"},
{UA_FMT_PCM8, 24, AFMT_U24_LE, "24-bit U-LE PCM"},
{UA_FMT_PCM8, 32, AFMT_U32_LE, "32-bit U-LE PCM"},
{UA_FMT_PCM, 8, AFMT_S8, "8-bit S-LE PCM"},
{UA_FMT_PCM, 16, AFMT_S16_LE, "16-bit S-LE PCM"},
{UA_FMT_PCM, 24, AFMT_S24_LE, "24-bit S-LE PCM"},
{UA_FMT_PCM, 32, AFMT_S32_LE, "32-bit S-LE PCM"},
{UA_FMT_ALAW, 8, AFMT_A_LAW, "8-bit A-Law"},
{UA_FMT_MULAW, 8, AFMT_MU_LAW, "8-bit mu-Law"},
{0, 0, 0, NULL}
};
static const struct uaudio_format uaudio20_formats[] = {
{UA20_FMT_PCM, 8, AFMT_S8, "8-bit S-LE PCM"},
{UA20_FMT_PCM, 16, AFMT_S16_LE, "16-bit S-LE PCM"},
{UA20_FMT_PCM, 24, AFMT_S24_LE, "24-bit S-LE PCM"},
{UA20_FMT_PCM, 32, AFMT_S32_LE, "32-bit S-LE PCM"},
{UA20_FMT_PCM8, 8, AFMT_U8, "8-bit U-LE PCM"},
{UA20_FMT_PCM8, 16, AFMT_U16_LE, "16-bit U-LE PCM"},
{UA20_FMT_PCM8, 24, AFMT_U24_LE, "24-bit U-LE PCM"},
{UA20_FMT_PCM8, 32, AFMT_U32_LE, "32-bit U-LE PCM"},
{UA20_FMT_ALAW, 8, AFMT_A_LAW, "8-bit A-Law"},
{UA20_FMT_MULAW, 8, AFMT_MU_LAW, "8-bit mu-Law"},
{0, 0, 0, NULL}
};
/* prototypes */
static device_probe_t uaudio_probe;
static device_attach_t uaudio_attach;
static device_detach_t uaudio_detach;
static usb_callback_t uaudio_chan_play_callback;
static usb_callback_t uaudio_chan_play_sync_callback;
static usb_callback_t uaudio_chan_record_callback;
static usb_callback_t uaudio_chan_record_sync_callback;
static usb_callback_t uaudio_mixer_write_cfg_callback;
static usb_callback_t umidi_bulk_read_callback;
static usb_callback_t umidi_bulk_write_callback;
static usb_callback_t uaudio_hid_rx_callback;
static usb_proc_callback_t uaudio_configure_msg;
/* ==== USB mixer ==== */
static int uaudio_mixer_sysctl_handler(SYSCTL_HANDLER_ARGS);
static void uaudio_mixer_ctl_free(struct uaudio_softc *);
static void uaudio_mixer_register_sysctl(struct uaudio_softc *, device_t, unsigned);
static void uaudio_mixer_reload_all(struct uaudio_softc *);
static void uaudio_mixer_controls_create_ftu(struct uaudio_softc *);
/* ==== USB audio v1.0 ==== */
static void uaudio_mixer_add_mixer(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static void uaudio_mixer_add_selector(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static uint32_t uaudio_mixer_feature_get_bmaControls(
const struct usb_audio_feature_unit *, uint8_t);
static void uaudio_mixer_add_feature(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static void uaudio_mixer_add_processing_updown(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static void uaudio_mixer_add_processing(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static void uaudio_mixer_add_extension(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static struct usb_audio_cluster uaudio_mixer_get_cluster(uint8_t,
const struct uaudio_terminal_node *);
static uint16_t uaudio_mixer_determine_class(const struct uaudio_terminal_node *);
static void uaudio_mixer_find_inputs_sub(struct uaudio_terminal_node *,
const uint8_t *, uint8_t, struct uaudio_search_result *);
static const void *uaudio_mixer_verify_desc(const void *, uint32_t);
static usb_error_t uaudio_set_speed(struct usb_device *, uint8_t, uint32_t);
static int uaudio_mixer_get(struct usb_device *, uint16_t, uint8_t,
struct uaudio_mixer_node *);
/* ==== USB audio v2.0 ==== */
static void uaudio20_mixer_add_mixer(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static void uaudio20_mixer_add_selector(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static void uaudio20_mixer_add_feature(struct uaudio_softc *,
const struct uaudio_terminal_node *, int);
static struct usb_audio20_cluster uaudio20_mixer_get_cluster(uint8_t,
const struct uaudio_terminal_node *);
static uint16_t uaudio20_mixer_determine_class(const struct uaudio_terminal_node *);
static void uaudio20_mixer_find_inputs_sub(struct uaudio_terminal_node *,
const uint8_t *, uint8_t, struct uaudio_search_result *);
static const void *uaudio20_mixer_verify_desc(const void *, uint32_t);
static usb_error_t uaudio20_set_speed(struct usb_device *, uint8_t,
uint8_t, uint32_t);
/* USB audio v1.0 and v2.0 */
static void uaudio_chan_fill_info_sub(struct uaudio_softc *,
struct usb_device *, uint32_t, uint8_t, uint8_t);
static void uaudio_chan_fill_info(struct uaudio_softc *,
struct usb_device *);
static void uaudio_mixer_add_ctl_sub(struct uaudio_softc *,
struct uaudio_mixer_node *);
static void uaudio_mixer_add_ctl(struct uaudio_softc *,
struct uaudio_mixer_node *);
static void uaudio_mixer_fill_info(struct uaudio_softc *,
struct usb_device *, void *);
static int uaudio_mixer_signext(uint8_t, int);
static void uaudio_mixer_init(struct uaudio_softc *, unsigned);
static uint8_t umidi_convert_to_usb(struct umidi_sub_chan *, uint8_t, uint8_t);
static struct umidi_sub_chan *umidi_sub_by_fifo(struct usb_fifo *);
static void umidi_start_read(struct usb_fifo *);
static void umidi_stop_read(struct usb_fifo *);
static void umidi_start_write(struct usb_fifo *);
static void umidi_stop_write(struct usb_fifo *);
static int umidi_open(struct usb_fifo *, int);
static int umidi_ioctl(struct usb_fifo *, u_long cmd, void *, int);
static void umidi_close(struct usb_fifo *, int);
static void umidi_init(device_t dev);
static int umidi_probe(device_t dev);
static int umidi_detach(device_t dev);
static int uaudio_hid_probe(struct uaudio_softc *sc,
struct usb_attach_arg *uaa);
static void uaudio_hid_detach(struct uaudio_softc *sc);
#ifdef USB_DEBUG
static void uaudio_chan_dump_ep_desc(
const usb_endpoint_descriptor_audio_t *);
#endif
static const struct usb_config
uaudio_cfg_record[UAUDIO_NCHANBUFS + 1] = {
[0] = {
.type = UE_ISOCHRONOUS,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.bufsize = 0, /* use "wMaxPacketSize * frames" */
.frames = UAUDIO_NFRAMES,
.flags = {.short_xfer_ok = 1,},
.callback = &uaudio_chan_record_callback,
},
[1] = {
.type = UE_ISOCHRONOUS,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.bufsize = 0, /* use "wMaxPacketSize * frames" */
.frames = UAUDIO_NFRAMES,
.flags = {.short_xfer_ok = 1,},
.callback = &uaudio_chan_record_callback,
},
[2] = {
.type = UE_ISOCHRONOUS,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_OUT,
.bufsize = 0, /* use "wMaxPacketSize * frames" */
.frames = 1,
.flags = {.no_pipe_ok = 1,.short_xfer_ok = 1,},
.callback = &uaudio_chan_record_sync_callback,
},
};
static const struct usb_config
uaudio_cfg_play[UAUDIO_NCHANBUFS + 1] = {
[0] = {
.type = UE_ISOCHRONOUS,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_OUT,
.bufsize = 0, /* use "wMaxPacketSize * frames" */
.frames = UAUDIO_NFRAMES,
.flags = {.short_xfer_ok = 1,},
.callback = &uaudio_chan_play_callback,
},
[1] = {
.type = UE_ISOCHRONOUS,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_OUT,
.bufsize = 0, /* use "wMaxPacketSize * frames" */
.frames = UAUDIO_NFRAMES,
.flags = {.short_xfer_ok = 1,},
.callback = &uaudio_chan_play_callback,
},
[2] = {
.type = UE_ISOCHRONOUS,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.bufsize = 0, /* use "wMaxPacketSize * frames" */
.frames = 1,
.flags = {.no_pipe_ok = 1,.short_xfer_ok = 1,},
.callback = &uaudio_chan_play_sync_callback,
},
};
static const struct usb_config
uaudio_mixer_config[1] = {
[0] = {
.type = UE_CONTROL,
.endpoint = 0x00, /* Control pipe */
.direction = UE_DIR_ANY,
.bufsize = (sizeof(struct usb_device_request) + 4),
.callback = &uaudio_mixer_write_cfg_callback,
.timeout = 1000, /* 1 second */
},
};
static const
uint8_t umidi_cmd_to_len[16] = {
[0x0] = 0, /* reserved */
[0x1] = 0, /* reserved */
[0x2] = 2, /* bytes */
[0x3] = 3, /* bytes */
[0x4] = 3, /* bytes */
[0x5] = 1, /* bytes */
[0x6] = 2, /* bytes */
[0x7] = 3, /* bytes */
[0x8] = 3, /* bytes */
[0x9] = 3, /* bytes */
[0xA] = 3, /* bytes */
[0xB] = 3, /* bytes */
[0xC] = 2, /* bytes */
[0xD] = 2, /* bytes */
[0xE] = 3, /* bytes */
[0xF] = 1, /* bytes */
};
static const struct usb_config
umidi_config[UMIDI_N_TRANSFER] = {
[UMIDI_TX_TRANSFER] = {
.type = UE_BULK,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_OUT,
.bufsize = UMIDI_TX_BUFFER,
.flags = {.no_pipe_ok = 1},
.callback = &umidi_bulk_write_callback,
},
[UMIDI_RX_TRANSFER] = {
.type = UE_BULK,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.bufsize = 4, /* bytes */
.flags = {.short_xfer_ok = 1,.proxy_buffer = 1,.no_pipe_ok = 1},
.callback = &umidi_bulk_read_callback,
},
};
static const struct usb_config
uaudio_hid_config[UAUDIO_HID_N_TRANSFER] = {
[UAUDIO_HID_RX_TRANSFER] = {
.type = UE_INTERRUPT,
.endpoint = UE_ADDR_ANY,
.direction = UE_DIR_IN,
.bufsize = 0, /* use wMaxPacketSize */
.flags = {.short_xfer_ok = 1,},
.callback = &uaudio_hid_rx_callback,
},
};
static devclass_t uaudio_devclass;
static device_method_t uaudio_methods[] = {
DEVMETHOD(device_probe, uaudio_probe),
DEVMETHOD(device_attach, uaudio_attach),
DEVMETHOD(device_detach, uaudio_detach),
DEVMETHOD(device_suspend, bus_generic_suspend),
DEVMETHOD(device_resume, bus_generic_resume),
DEVMETHOD(device_shutdown, bus_generic_shutdown),
DEVMETHOD_END
};
static driver_t uaudio_driver = {
.name = "uaudio",
.methods = uaudio_methods,
.size = sizeof(struct uaudio_softc),
};
/* The following table is derived from Linux's quirks-table.h */
static const STRUCT_USB_HOST_ID uaudio_vendor_midi[] = {
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1000, 0) }, /* UX256 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1001, 0) }, /* MU1000 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1002, 0) }, /* MU2000 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1003, 0) }, /* MU500 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1004, 3) }, /* UW500 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1005, 0) }, /* MOTIF6 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1006, 0) }, /* MOTIF7 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1007, 0) }, /* MOTIF8 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1008, 0) }, /* UX96 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1009, 0) }, /* UX16 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x100a, 3) }, /* EOS BX */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x100c, 0) }, /* UC-MX */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x100d, 0) }, /* UC-KX */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x100e, 0) }, /* S08 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x100f, 0) }, /* CLP-150 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1010, 0) }, /* CLP-170 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1011, 0) }, /* P-250 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1012, 0) }, /* TYROS */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1013, 0) }, /* PF-500 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1014, 0) }, /* S90 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1015, 0) }, /* MOTIF-R */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1016, 0) }, /* MDP-5 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1017, 0) }, /* CVP-204 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1018, 0) }, /* CVP-206 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1019, 0) }, /* CVP-208 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x101a, 0) }, /* CVP-210 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x101b, 0) }, /* PSR-1100 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x101c, 0) }, /* PSR-2100 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x101d, 0) }, /* CLP-175 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x101e, 0) }, /* PSR-K1 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x101f, 0) }, /* EZ-J24 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1020, 0) }, /* EZ-250i */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1021, 0) }, /* MOTIF ES 6 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1022, 0) }, /* MOTIF ES 7 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1023, 0) }, /* MOTIF ES 8 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1024, 0) }, /* CVP-301 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1025, 0) }, /* CVP-303 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1026, 0) }, /* CVP-305 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1027, 0) }, /* CVP-307 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1028, 0) }, /* CVP-309 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1029, 0) }, /* CVP-309GP */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x102a, 0) }, /* PSR-1500 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x102b, 0) }, /* PSR-3000 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x102e, 0) }, /* ELS-01/01C */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1030, 0) }, /* PSR-295/293 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1031, 0) }, /* DGX-205/203 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1032, 0) }, /* DGX-305 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1033, 0) }, /* DGX-505 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1034, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1035, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1036, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1037, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1038, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1039, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x103a, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x103b, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x103c, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x103d, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x103e, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x103f, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1040, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1041, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1042, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1043, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1044, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1045, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x104e, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x104f, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1050, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1051, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1052, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1053, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1054, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1055, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1056, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1057, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1058, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1059, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x105a, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x105b, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x105c, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x105d, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x1503, 3) }, /* MOX6/MOX8 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x2000, 0) }, /* DGP-7 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x2001, 0) }, /* DGP-5 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x2002, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x2003, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5000, 0) }, /* CS1D */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5001, 0) }, /* DSP1D */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5002, 0) }, /* DME32 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5003, 0) }, /* DM2000 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5004, 0) }, /* 02R96 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5005, 0) }, /* ACU16-C */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5006, 0) }, /* NHB32-C */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5007, 0) }, /* DM1000 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5008, 0) }, /* 01V96 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x5009, 0) }, /* SPX2000 */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x500a, 0) }, /* PM5D */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x500b, 0) }, /* DME64N */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x500c, 0) }, /* DME24N */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x500d, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x500e, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x500f, 0) }, /* NULL */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x7000, 0) }, /* DTX */
{ USB_VPI(USB_VENDOR_YAMAHA, 0x7010, 0) }, /* UB99 */
};
static const STRUCT_USB_HOST_ID __used uaudio_devs[] = {
/* Generic USB audio class match */
{USB_IFACE_CLASS(UICLASS_AUDIO),
USB_IFACE_SUBCLASS(UISUBCLASS_AUDIOCONTROL),},
/* Generic USB MIDI class match */
{USB_IFACE_CLASS(UICLASS_AUDIO),
USB_IFACE_SUBCLASS(UISUBCLASS_MIDISTREAM),},
};
static unsigned
uaudio_get_child_index_by_dev(struct uaudio_softc *sc, device_t dev)
{
unsigned i;
for (i = 0; i != UAUDIO_MAX_CHILD; i++) {
if (dev == sc->sc_child[i].pcm_device)
return (i);
}
panic("uaudio_get_child_index_dev: Invalid device: %p\n", dev);
return (0);
}
static unsigned
uaudio_get_child_index_by_chan(struct uaudio_softc *sc, struct uaudio_chan *ch)
{
unsigned i;
for (i = 0; i != UAUDIO_MAX_CHILD; i++) {
if ((sc->sc_play_chan + i) == ch ||
(sc->sc_rec_chan + i) == ch)
return (i);
}
panic("uaudio_get_child_index_by_chan: Invalid chan: %p\n", ch);
return (0);
}
static int
uaudio_probe(device_t dev)
{
struct usb_attach_arg *uaa = device_get_ivars(dev);
if (uaa->usb_mode != USB_MODE_HOST)
return (ENXIO);
/* lookup non-standard device(s) */
if (usbd_lookup_id_by_uaa(uaudio_vendor_midi,
sizeof(uaudio_vendor_midi), uaa) == 0) {
return (BUS_PROBE_SPECIFIC);
}
if (uaa->info.bInterfaceClass != UICLASS_AUDIO) {
if (uaa->info.bInterfaceClass != UICLASS_VENDOR ||
usb_test_quirk(uaa, UQ_AU_VENDOR_CLASS) == 0)
return (ENXIO);
}
/* check for AUDIO control interface */
if (uaa->info.bInterfaceSubClass == UISUBCLASS_AUDIOCONTROL) {
if (usb_test_quirk(uaa, UQ_BAD_AUDIO))
return (ENXIO);
else
return (BUS_PROBE_GENERIC);
}
/* check for MIDI stream */
if (uaa->info.bInterfaceSubClass == UISUBCLASS_MIDISTREAM) {
if (usb_test_quirk(uaa, UQ_BAD_MIDI))
return (ENXIO);
else
return (BUS_PROBE_GENERIC);
}
return (ENXIO);
}
/*
* Set Cmedia CM6206 S/PDIF settings
* Source: CM6206 Datasheet v2.3.
*/
static int
uaudio_set_spdif_cm6206(struct uaudio_softc *sc, int flags)
{
uint8_t cmd[2][4] = {
{0x20, 0x20, 0x00, 0},
{0x20, 0x30, 0x02, 1}
};
int i;
if (flags & UAUDIO_SPDIF_OUT)
cmd[1][1] = 0x00;
else
cmd[1][1] = 0x02;
if (flags & UAUDIO_SPDIF_OUT_96K)
cmd[0][1] = 0x60; /* 96K: 3'b110 */
if (flags & UAUDIO_SPDIF_IN_MIX)
cmd[1][1] = 0x03; /* SPDIFMIX */
for (i = 0; i < 2; i++) {
if (usbd_req_set_report(sc->sc_udev, NULL,
cmd[i], sizeof(cmd[0]),
sc->sc_mixer_iface_index, UHID_OUTPUT_REPORT, 0) != 0) {
return (ENXIO);
}
}
return (0);
}
static int
uaudio_set_spdif_dummy(struct uaudio_softc *sc, int flags)
{
return (0);
}
static int
uaudio_attach(device_t dev)
{
struct usb_attach_arg *uaa = device_get_ivars(dev);
struct uaudio_softc *sc = device_get_softc(dev);
struct usb_interface_descriptor *id;
usb_error_t err;
unsigned i;
sc->sc_udev = uaa->device;
sc->sc_mixer_iface_index = uaa->info.bIfaceIndex;
sc->sc_mixer_iface_no = uaa->info.bIfaceNum;
sc->sc_config_msg[0].hdr.pm_callback = &uaudio_configure_msg;
sc->sc_config_msg[0].sc = sc;
sc->sc_config_msg[1].hdr.pm_callback = &uaudio_configure_msg;
sc->sc_config_msg[1].sc = sc;
if (usb_test_quirk(uaa, UQ_AUDIO_SWAP_LR))
sc->sc_uq_audio_swap_lr = 1;
if (usb_test_quirk(uaa, UQ_AU_INP_ASYNC))
sc->sc_uq_au_inp_async = 1;
if (usb_test_quirk(uaa, UQ_AU_NO_XU))
sc->sc_uq_au_no_xu = 1;
if (usb_test_quirk(uaa, UQ_BAD_ADC))
sc->sc_uq_bad_adc = 1;
if (usb_test_quirk(uaa, UQ_AU_VENDOR_CLASS))
sc->sc_uq_au_vendor_class = 1;
/* set S/PDIF function */
if (usb_test_quirk(uaa, UQ_AU_SET_SPDIF_CM6206))
sc->sc_set_spdif_fn = uaudio_set_spdif_cm6206;
else
sc->sc_set_spdif_fn = uaudio_set_spdif_dummy;
umidi_init(dev);
device_set_usb_desc(dev);
id = usbd_get_interface_descriptor(uaa->iface);
/* must fill mixer info before channel info */
uaudio_mixer_fill_info(sc, uaa->device, id);
/* fill channel info */
uaudio_chan_fill_info(sc, uaa->device);
DPRINTF("audio rev %d.%02x\n",
sc->sc_audio_rev >> 8,