2 * Scarlett Driver for ALSA
4 * Copyright (c) 2013 by Tobias Hoffmann
5 * Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
6 * Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
7 * Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
9 * Many codes borrowed from audio.c by
10 * Alan Cox (alan at lxorguk.ukuu.org.uk)
11 * Thomas Sailer (sailer at ife.ee.ethz.ch)
14 * David Henningsson <david.henningsson at canonical.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
29 * Rewritten and extended to support more models, e.g. Scarlett 18i8.
31 * Auto-detection via UAC2 is not feasible to properly discover the vast
32 * majority of features. It's related to both Linux/ALSA's UAC2 as well as
33 * Focusrite's implementation of it. Eventually quirks may be sufficient but
34 * right now it's a major headache to work arount these things.
36 * NB. Neither the OSX nor the win driver provided by Focusrite performs
37 * discovery, they seem to operate the same as this driver.
40 /* Mixer Interface for the Focusrite Scarlett 18i6 audio interface.
42 * The protocol was reverse engineered by looking at communication between
43 * Scarlett MixControl (v 1.2.128.0) and the Focusrite(R) Scarlett 18i6
44 * (firmware v305) using wireshark and usbmon in January 2013.
45 * Extended in July 2013.
47 * this mixer gives complete access to all features of the device:
48 * - change Impedance of inputs (Line-in, Mic / Instrument, Hi-Z)
49 * - select clock source
50 * - dynamic input to mixer-matrix assignment
51 * - 18 x 6 mixer-matrix gain stages
52 * - bus routing & volume control
53 * - automatic re-initialization on connect if device was power-cycled
55 * USB URB commands overview (bRequest = 0x01 = UAC2_CS_CUR)
57 * 0x01 Analog Input line/instrument impedance switch, wValue=0x0901 +
58 * channel, data=Line/Inst (2bytes)
59 * pad (-10dB) switch, wValue=0x0b01 + channel, data=Off/On (2bytes)
60 * ?? wValue=0x0803/04, ?? (2bytes)
61 * 0x0a Master Volume, wValue=0x0200+bus[0:all + only 1..4?] data(2bytes)
62 * Bus Mute/Unmute wValue=0x0100+bus[0:all + only 1..4?], data(2bytes)
63 * 0x28 Clock source, wValue=0x0100, data={1:int,2:spdif,3:adat} (1byte)
64 * 0x29 Set Sample-rate, wValue=0x0100, data=sample-rate(4bytes)
65 * 0x32 Mixer mux, wValue=0x0600 + mixer-channel, data=input-to-connect(2bytes)
66 * 0x33 Output mux, wValue=bus, data=input-to-connect(2bytes)
67 * 0x34 Capture mux, wValue=0...18, data=input-to-connect(2bytes)
68 * 0x3c Matrix Mixer gains, wValue=mixer-node data=gain(2bytes)
69 * ?? [sometimes](4bytes, e.g 0x000003be 0x000003bf ...03ff)
71 * USB reads: (i.e. actually issued by original software)
72 * 0x01 wValue=0x0901+channel (1byte!!), wValue=0x0b01+channed (1byte!!)
73 * 0x29 wValue=0x0100 sample-rate(4bytes)
74 * wValue=0x0200 ?? 1byte (only once)
75 * 0x2a wValue=0x0100 ?? 4bytes, sample-rate2 ??
77 * USB reads with bRequest = 0x03 = UAC2_CS_MEM
78 * 0x3c wValue=0x0002 1byte: sync status (locked=1)
79 * wValue=0x0000 18*2byte: peak meter (inputs)
80 * wValue=0x0001 8(?)*2byte: peak meter (mix)
81 * wValue=0x0003 6*2byte: peak meter (pcm/daw)
83 * USB write with bRequest = 0x03
84 * 0x3c Save settings to hardware: wValue=0x005a, data=0xa5
88 * /--------------\ 18chn 6chn /--------------\
89 * | Hardware in +--+-------\ /------+--+ ALSA PCM out |
90 * \--------------/ | | | | \--------------/
93 * | +---------------+ |
108 * | 18chn | 6chn | 6chn
110 * =========================
111 * +---------------+ +--—------------+
112 * \ Output Mux / \ Capture Mux /
113 * +-----+-----+ +-----+-----+
122 * | (3 stereo pairs) |
123 * /--------------\ | | /--------------\
124 * | Hardware out |<--/ \-->| ALSA PCM in |
125 * \--------------/ \--------------/
130 #include <linux/slab.h>
131 #include <linux/usb.h>
132 #include <linux/usb/audio-v2.h>
134 #include <sound/core.h>
135 #include <sound/control.h>
136 #include <sound/tlv.h>
138 #include "usbaudio.h"
143 #include "mixer_scarlett.h"
145 /* some gui mixers can't handle negative ctl values */
146 #define SND_SCARLETT_LEVEL_BIAS 128
147 #define SND_SCARLETT_MATRIX_IN_MAX 18
148 #define SND_SCARLETT_CONTROLS_MAX 10
149 #define SND_SCARLETT_OFFSETS_MAX 5
153 SCARLETT_SWITCH_IMPEDANCE
,
158 SCARLETT_OFFSET_PCM
= 0,
159 SCARLETT_OFFSET_ANALOG
= 1,
160 SCARLETT_OFFSET_SPDIF
= 2,
161 SCARLETT_OFFSET_ADAT
= 3,
162 SCARLETT_OFFSET_MIX
= 4,
165 struct scarlett_mixer_elem_enum_info
{
168 int offsets
[SND_SCARLETT_OFFSETS_MAX
];
169 char const * const *names
;
172 struct scarlett_mixer_control
{
178 struct scarlett_device_info
{
184 struct scarlett_mixer_elem_enum_info opt_master
;
185 struct scarlett_mixer_elem_enum_info opt_matrix
;
187 /* initial values for matrix mux */
188 int matrix_mux_init
[SND_SCARLETT_MATRIX_IN_MAX
];
190 int num_controls
; /* number of items in controls */
191 const struct scarlett_mixer_control controls
[SND_SCARLETT_CONTROLS_MAX
];
194 /********************** Enum Strings *************************/
196 static const struct scarlett_mixer_elem_enum_info opt_pad
= {
200 .names
= (char const * const []){
205 static const struct scarlett_mixer_elem_enum_info opt_impedance
= {
209 .names
= (char const * const []){
214 static const struct scarlett_mixer_elem_enum_info opt_clock
= {
218 .names
= (char const * const []){
219 "Internal", "SPDIF", "ADAT"
223 static const struct scarlett_mixer_elem_enum_info opt_sync
= {
227 .names
= (char const * const []){
232 static int scarlett_ctl_switch_info(struct snd_kcontrol
*kctl
,
233 struct snd_ctl_elem_info
*uinfo
)
235 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
237 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_BOOLEAN
;
238 uinfo
->count
= elem
->channels
;
239 uinfo
->value
.integer
.min
= 0;
240 uinfo
->value
.integer
.max
= 1;
244 static int scarlett_ctl_switch_get(struct snd_kcontrol
*kctl
,
245 struct snd_ctl_elem_value
*ucontrol
)
247 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
250 for (i
= 0; i
< elem
->channels
; i
++) {
251 err
= snd_usb_get_cur_mix_value(elem
, i
, i
, &val
);
255 val
= !val
; /* invert mute logic for mixer */
256 ucontrol
->value
.integer
.value
[i
] = val
;
262 static int scarlett_ctl_switch_put(struct snd_kcontrol
*kctl
,
263 struct snd_ctl_elem_value
*ucontrol
)
265 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
269 for (i
= 0; i
< elem
->channels
; i
++) {
270 err
= snd_usb_get_cur_mix_value(elem
, i
, i
, &oval
);
274 val
= ucontrol
->value
.integer
.value
[i
];
277 err
= snd_usb_set_cur_mix_value(elem
, i
, i
, val
);
288 static int scarlett_ctl_resume(struct usb_mixer_elem_list
*list
)
290 struct usb_mixer_elem_info
*elem
= mixer_elem_list_to_info(list
);
293 for (i
= 0; i
< elem
->channels
; i
++)
294 if (elem
->cached
& (1 << i
))
295 snd_usb_set_cur_mix_value(elem
, i
, i
,
300 static int scarlett_ctl_info(struct snd_kcontrol
*kctl
,
301 struct snd_ctl_elem_info
*uinfo
)
303 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
305 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
306 uinfo
->count
= elem
->channels
;
307 uinfo
->value
.integer
.min
= 0;
308 uinfo
->value
.integer
.max
= (int)kctl
->private_value
+
309 SND_SCARLETT_LEVEL_BIAS
;
310 uinfo
->value
.integer
.step
= 1;
314 static int scarlett_ctl_get(struct snd_kcontrol
*kctl
,
315 struct snd_ctl_elem_value
*ucontrol
)
317 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
320 for (i
= 0; i
< elem
->channels
; i
++) {
321 err
= snd_usb_get_cur_mix_value(elem
, i
, i
, &val
);
325 val
= clamp(val
/ 256, -128, (int)kctl
->private_value
) +
326 SND_SCARLETT_LEVEL_BIAS
;
327 ucontrol
->value
.integer
.value
[i
] = val
;
333 static int scarlett_ctl_put(struct snd_kcontrol
*kctl
,
334 struct snd_ctl_elem_value
*ucontrol
)
336 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
340 for (i
= 0; i
< elem
->channels
; i
++) {
341 err
= snd_usb_get_cur_mix_value(elem
, i
, i
, &oval
);
345 val
= ucontrol
->value
.integer
.value
[i
] -
346 SND_SCARLETT_LEVEL_BIAS
;
349 err
= snd_usb_set_cur_mix_value(elem
, i
, i
, val
);
360 static void scarlett_generate_name(int i
, char *dst
, int offsets
[])
362 if (i
> offsets
[SCARLETT_OFFSET_MIX
])
363 sprintf(dst
, "Mix %c",
364 'A'+(i
- offsets
[SCARLETT_OFFSET_MIX
] - 1));
365 else if (i
> offsets
[SCARLETT_OFFSET_ADAT
])
366 sprintf(dst
, "ADAT %d", i
- offsets
[SCARLETT_OFFSET_ADAT
]);
367 else if (i
> offsets
[SCARLETT_OFFSET_SPDIF
])
368 sprintf(dst
, "SPDIF %d", i
- offsets
[SCARLETT_OFFSET_SPDIF
]);
369 else if (i
> offsets
[SCARLETT_OFFSET_ANALOG
])
370 sprintf(dst
, "Analog %d", i
- offsets
[SCARLETT_OFFSET_ANALOG
]);
371 else if (i
> offsets
[SCARLETT_OFFSET_PCM
])
372 sprintf(dst
, "PCM %d", i
- offsets
[SCARLETT_OFFSET_PCM
]);
377 static int scarlett_ctl_enum_dynamic_info(struct snd_kcontrol
*kctl
,
378 struct snd_ctl_elem_info
*uinfo
)
380 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
381 struct scarlett_mixer_elem_enum_info
*opt
= elem
->private_data
;
382 unsigned int items
= opt
->len
;
384 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
385 uinfo
->count
= elem
->channels
;
386 uinfo
->value
.enumerated
.items
= items
;
388 if (uinfo
->value
.enumerated
.item
>= items
)
389 uinfo
->value
.enumerated
.item
= items
- 1;
391 /* generate name dynamically based on item number and offset info */
392 scarlett_generate_name(uinfo
->value
.enumerated
.item
,
393 uinfo
->value
.enumerated
.name
,
399 static int scarlett_ctl_enum_info(struct snd_kcontrol
*kctl
,
400 struct snd_ctl_elem_info
*uinfo
)
402 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
403 struct scarlett_mixer_elem_enum_info
*opt
= elem
->private_data
;
405 return snd_ctl_enum_info(uinfo
, elem
->channels
, opt
->len
,
406 (const char * const *)opt
->names
);
409 static int scarlett_ctl_enum_get(struct snd_kcontrol
*kctl
,
410 struct snd_ctl_elem_value
*ucontrol
)
412 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
413 struct scarlett_mixer_elem_enum_info
*opt
= elem
->private_data
;
416 err
= snd_usb_get_cur_mix_value(elem
, 0, 0, &val
);
420 val
= clamp(val
- opt
->start
, 0, opt
->len
-1);
422 ucontrol
->value
.enumerated
.item
[0] = val
;
427 static int scarlett_ctl_enum_put(struct snd_kcontrol
*kctl
,
428 struct snd_ctl_elem_value
*ucontrol
)
430 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
431 struct scarlett_mixer_elem_enum_info
*opt
= elem
->private_data
;
434 err
= snd_usb_get_cur_mix_value(elem
, 0, 0, &oval
);
438 val
= ucontrol
->value
.integer
.value
[0];
439 val
= val
+ opt
->start
;
441 snd_usb_set_cur_mix_value(elem
, 0, 0, val
);
447 static int scarlett_ctl_enum_resume(struct usb_mixer_elem_list
*list
)
449 struct usb_mixer_elem_info
*elem
= mixer_elem_list_to_info(list
);
452 snd_usb_set_cur_mix_value(elem
, 0, 0, *elem
->cache_val
);
456 static int scarlett_ctl_meter_get(struct snd_kcontrol
*kctl
,
457 struct snd_ctl_elem_value
*ucontrol
)
459 struct usb_mixer_elem_info
*elem
= kctl
->private_data
;
460 struct snd_usb_audio
*chip
= elem
->head
.mixer
->chip
;
461 unsigned char buf
[2 * MAX_CHANNELS
] = {0, };
462 int wValue
= (elem
->control
<< 8) | elem
->idx_off
;
463 int idx
= snd_usb_ctrl_intf(chip
) | (elem
->head
.id
<< 8);
466 err
= snd_usb_ctl_msg(chip
->dev
,
467 usb_rcvctrlpipe(chip
->dev
, 0),
469 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
|
470 USB_DIR_IN
, wValue
, idx
, buf
, elem
->channels
);
474 ucontrol
->value
.enumerated
.item
[0] = clamp((int)buf
[0], 0, 1);
478 static const struct snd_kcontrol_new usb_scarlett_ctl_switch
= {
479 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
481 .info
= scarlett_ctl_switch_info
,
482 .get
= scarlett_ctl_switch_get
,
483 .put
= scarlett_ctl_switch_put
,
486 static const DECLARE_TLV_DB_SCALE(db_scale_scarlett_gain
, -12800, 100, 0);
488 static const struct snd_kcontrol_new usb_scarlett_ctl
= {
489 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
490 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
491 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
493 .info
= scarlett_ctl_info
,
494 .get
= scarlett_ctl_get
,
495 .put
= scarlett_ctl_put
,
496 .private_value
= 6, /* max value */
497 .tlv
= { .p
= db_scale_scarlett_gain
}
500 static const struct snd_kcontrol_new usb_scarlett_ctl_master
= {
501 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
502 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
|
503 SNDRV_CTL_ELEM_ACCESS_TLV_READ
,
505 .info
= scarlett_ctl_info
,
506 .get
= scarlett_ctl_get
,
507 .put
= scarlett_ctl_put
,
508 .private_value
= 6, /* max value */
509 .tlv
= { .p
= db_scale_scarlett_gain
}
512 static const struct snd_kcontrol_new usb_scarlett_ctl_enum
= {
513 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
515 .info
= scarlett_ctl_enum_info
,
516 .get
= scarlett_ctl_enum_get
,
517 .put
= scarlett_ctl_enum_put
,
520 static const struct snd_kcontrol_new usb_scarlett_ctl_dynamic_enum
= {
521 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
523 .info
= scarlett_ctl_enum_dynamic_info
,
524 .get
= scarlett_ctl_enum_get
,
525 .put
= scarlett_ctl_enum_put
,
528 static const struct snd_kcontrol_new usb_scarlett_ctl_sync
= {
529 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
530 .access
= SNDRV_CTL_ELEM_ACCESS_READ
| SNDRV_CTL_ELEM_ACCESS_VOLATILE
,
532 .info
= scarlett_ctl_enum_info
,
533 .get
= scarlett_ctl_meter_get
,
536 static int add_new_ctl(struct usb_mixer_interface
*mixer
,
537 const struct snd_kcontrol_new
*ncontrol
,
538 usb_mixer_elem_resume_func_t resume
,
539 int index
, int offset
, int num
,
540 int val_type
, int channels
, const char *name
,
541 const struct scarlett_mixer_elem_enum_info
*opt
,
542 struct usb_mixer_elem_info
**elem_ret
545 struct snd_kcontrol
*kctl
;
546 struct usb_mixer_elem_info
*elem
;
549 elem
= kzalloc(sizeof(*elem
), GFP_KERNEL
);
553 elem
->head
.mixer
= mixer
;
554 elem
->head
.resume
= resume
;
555 elem
->control
= offset
;
557 elem
->head
.id
= index
;
558 elem
->val_type
= val_type
;
560 elem
->channels
= channels
;
562 /* add scarlett_mixer_elem_enum_info struct */
563 elem
->private_data
= (void *)opt
;
565 kctl
= snd_ctl_new1(ncontrol
, elem
);
570 kctl
->private_free
= snd_usb_mixer_elem_free
;
572 strlcpy(kctl
->id
.name
, name
, sizeof(kctl
->id
.name
));
574 err
= snd_usb_mixer_add_control(&elem
->head
, kctl
);
584 static int add_output_ctls(struct usb_mixer_interface
*mixer
,
585 int index
, const char *name
,
586 const struct scarlett_device_info
*info
)
589 char mx
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
590 struct usb_mixer_elem_info
*elem
;
592 /* Add mute switch */
593 snprintf(mx
, sizeof(mx
), "Master %d (%s) Playback Switch",
595 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_switch
,
596 scarlett_ctl_resume
, 0x0a, 0x01,
597 2*index
+1, USB_MIXER_S16
, 2, mx
, NULL
, &elem
);
601 /* Add volume control and initialize to 0 */
602 snprintf(mx
, sizeof(mx
), "Master %d (%s) Playback Volume",
604 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_master
,
605 scarlett_ctl_resume
, 0x0a, 0x02,
606 2*index
+1, USB_MIXER_S16
, 2, mx
, NULL
, &elem
);
610 /* Add L channel source playback enumeration */
611 snprintf(mx
, sizeof(mx
), "Master %dL (%s) Source Playback Enum",
613 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_dynamic_enum
,
614 scarlett_ctl_enum_resume
, 0x33, 0x00,
615 2*index
, USB_MIXER_S16
, 1, mx
, &info
->opt_master
,
620 /* Add R channel source playback enumeration */
621 snprintf(mx
, sizeof(mx
), "Master %dR (%s) Source Playback Enum",
623 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_dynamic_enum
,
624 scarlett_ctl_enum_resume
, 0x33, 0x00,
625 2*index
+1, USB_MIXER_S16
, 1, mx
, &info
->opt_master
,
633 /********************** device-specific config *************************/
636 static struct scarlett_device_info s6i6_info
= {
645 .offsets
= {0, 12, 16, 18, 18},
652 .offsets
= {0, 12, 16, 18, 18},
658 { .num
= 0, .type
= SCARLETT_OUTPUTS
, .name
= "Monitor" },
659 { .num
= 1, .type
= SCARLETT_OUTPUTS
, .name
= "Headphone" },
660 { .num
= 2, .type
= SCARLETT_OUTPUTS
, .name
= "SPDIF" },
661 { .num
= 1, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
662 { .num
= 1, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
663 { .num
= 2, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
664 { .num
= 2, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
665 { .num
= 3, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
666 { .num
= 4, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
670 12, 13, 14, 15, /* Analog -> 1..4 */
671 16, 17, /* SPDIF -> 5,6 */
672 0, 1, 2, 3, 4, 5, 6, 7, /* PCM[1..12] -> 7..18 */
678 static struct scarlett_device_info s8i6_info
= {
687 .offsets
= {0, 12, 16, 18, 18},
694 .offsets
= {0, 12, 16, 18, 18},
700 { .num
= 0, .type
= SCARLETT_OUTPUTS
, .name
= "Monitor" },
701 { .num
= 1, .type
= SCARLETT_OUTPUTS
, .name
= "Headphone" },
702 { .num
= 2, .type
= SCARLETT_OUTPUTS
, .name
= "SPDIF" },
703 { .num
= 1, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
704 { .num
= 2, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
705 { .num
= 3, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
706 { .num
= 4, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
710 12, 13, 14, 15, /* Analog -> 1..4 */
711 16, 17, /* SPDIF -> 5,6 */
712 0, 1, 2, 3, 4, 5, 6, 7, /* PCM[1..12] -> 7..18 */
717 static struct scarlett_device_info s18i6_info
= {
726 .offsets
= {0, 6, 14, 16, 24},
733 .offsets
= {0, 6, 14, 16, 24},
739 { .num
= 0, .type
= SCARLETT_OUTPUTS
, .name
= "Monitor" },
740 { .num
= 1, .type
= SCARLETT_OUTPUTS
, .name
= "Headphone" },
741 { .num
= 2, .type
= SCARLETT_OUTPUTS
, .name
= "SPDIF" },
742 { .num
= 1, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
743 { .num
= 2, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
747 6, 7, 8, 9, 10, 11, 12, 13, /* Analog -> 1..8 */
748 16, 17, 18, 19, 20, 21, /* ADAT[1..6] -> 9..14 */
749 14, 15, /* SPDIF -> 15,16 */
750 0, 1 /* PCM[1,2] -> 17,18 */
754 static struct scarlett_device_info s18i8_info
= {
763 .offsets
= {0, 8, 16, 18, 26},
770 .offsets
= {0, 8, 16, 18, 26},
776 { .num
= 0, .type
= SCARLETT_OUTPUTS
, .name
= "Monitor" },
777 { .num
= 1, .type
= SCARLETT_OUTPUTS
, .name
= "Headphone 1" },
778 { .num
= 2, .type
= SCARLETT_OUTPUTS
, .name
= "Headphone 2" },
779 { .num
= 3, .type
= SCARLETT_OUTPUTS
, .name
= "SPDIF" },
780 { .num
= 1, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
781 { .num
= 1, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
782 { .num
= 2, .type
= SCARLETT_SWITCH_IMPEDANCE
, .name
= NULL
},
783 { .num
= 2, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
784 { .num
= 3, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
785 { .num
= 4, .type
= SCARLETT_SWITCH_PAD
, .name
= NULL
},
789 8, 9, 10, 11, 12, 13, 14, 15, /* Analog -> 1..8 */
790 18, 19, 20, 21, 22, 23, /* ADAT[1..6] -> 9..14 */
791 16, 17, /* SPDIF -> 15,16 */
792 0, 1 /* PCM[1,2] -> 17,18 */
796 static struct scarlett_device_info s18i20_info
= {
805 .offsets
= {0, 20, 28, 30, 38},
812 .offsets
= {0, 20, 28, 30, 38},
818 { .num
= 0, .type
= SCARLETT_OUTPUTS
, .name
= "Monitor" },
819 { .num
= 1, .type
= SCARLETT_OUTPUTS
, .name
= "Line 3/4" },
820 { .num
= 2, .type
= SCARLETT_OUTPUTS
, .name
= "Line 5/6" },
821 { .num
= 3, .type
= SCARLETT_OUTPUTS
, .name
= "Line 7/8" },
822 { .num
= 4, .type
= SCARLETT_OUTPUTS
, .name
= "Line 9/10" },
823 { .num
= 5, .type
= SCARLETT_OUTPUTS
, .name
= "SPDIF" },
824 { .num
= 6, .type
= SCARLETT_OUTPUTS
, .name
= "ADAT 1/2" },
825 { .num
= 7, .type
= SCARLETT_OUTPUTS
, .name
= "ADAT 3/4" },
826 { .num
= 8, .type
= SCARLETT_OUTPUTS
, .name
= "ADAT 5/6" },
827 { .num
= 9, .type
= SCARLETT_OUTPUTS
, .name
= "ADAT 7/8" },
828 /*{ .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
829 { .num = 1, .type = SCARLETT_SWITCH_PAD, .name = NULL},
830 { .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
831 { .num = 2, .type = SCARLETT_SWITCH_PAD, .name = NULL},
832 { .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
833 { .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},*/
837 20, 21, 22, 23, 24, 25, 26, 27, /* Analog -> 1..8 */
838 30, 31, 32, 33, 34, 35, /* ADAT[1..6] -> 9..14 */
839 28, 29, /* SPDIF -> 15,16 */
840 0, 1 /* PCM[1,2] -> 17,18 */
845 static int scarlett_controls_create_generic(struct usb_mixer_interface
*mixer
,
846 struct scarlett_device_info
*info
)
849 char mx
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
850 const struct scarlett_mixer_control
*ctl
;
851 struct usb_mixer_elem_info
*elem
;
853 /* create master switch and playback volume */
854 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_switch
,
855 scarlett_ctl_resume
, 0x0a, 0x01, 0,
856 USB_MIXER_S16
, 1, "Master Playback Switch", NULL
,
861 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_master
,
862 scarlett_ctl_resume
, 0x0a, 0x02, 0,
863 USB_MIXER_S16
, 1, "Master Playback Volume", NULL
,
868 /* iterate through controls in info struct and create each one */
869 for (i
= 0; i
< info
->num_controls
; i
++) {
870 ctl
= &info
->controls
[i
];
873 case SCARLETT_OUTPUTS
:
874 err
= add_output_ctls(mixer
, ctl
->num
, ctl
->name
, info
);
878 case SCARLETT_SWITCH_IMPEDANCE
:
879 sprintf(mx
, "Input %d Impedance Switch", ctl
->num
);
880 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_enum
,
881 scarlett_ctl_enum_resume
, 0x01,
882 0x09, ctl
->num
, USB_MIXER_S16
, 1, mx
,
883 &opt_impedance
, &elem
);
887 case SCARLETT_SWITCH_PAD
:
888 sprintf(mx
, "Input %d Pad Switch", ctl
->num
);
889 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_enum
,
890 scarlett_ctl_enum_resume
, 0x01,
891 0x0b, ctl
->num
, USB_MIXER_S16
, 1, mx
,
903 * Create and initialize a mixer for the Focusrite(R) Scarlett
905 int snd_scarlett_controls_create(struct usb_mixer_interface
*mixer
)
908 char mx
[SNDRV_CTL_ELEM_ID_NAME_MAXLEN
];
909 struct scarlett_device_info
*info
;
910 struct usb_mixer_elem_info
*elem
;
911 static char sample_rate_buffer
[4] = { '\x80', '\xbb', '\x00', '\x00' };
913 /* only use UAC_VERSION_2 */
914 if (!mixer
->protocol
)
917 switch (mixer
->chip
->usb_id
) {
918 case USB_ID(0x1235, 0x8012):
921 case USB_ID(0x1235, 0x8002):
924 case USB_ID(0x1235, 0x8004):
927 case USB_ID(0x1235, 0x8014):
930 case USB_ID(0x1235, 0x800c):
933 default: /* device not (yet) supported */
937 /* generic function to create controls */
938 err
= scarlett_controls_create_generic(mixer
, info
);
942 /* setup matrix controls */
943 for (i
= 0; i
< info
->matrix_in
; i
++) {
944 snprintf(mx
, sizeof(mx
), "Matrix %02d Input Playback Route",
946 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_dynamic_enum
,
947 scarlett_ctl_enum_resume
, 0x32,
948 0x06, i
, USB_MIXER_S16
, 1, mx
,
949 &info
->opt_matrix
, &elem
);
953 for (o
= 0; o
< info
->matrix_out
; o
++) {
954 sprintf(mx
, "Matrix %02d Mix %c Playback Volume", i
+1,
956 err
= add_new_ctl(mixer
, &usb_scarlett_ctl
,
957 scarlett_ctl_resume
, 0x3c, 0x00,
958 (i
<< 3) + (o
& 0x07), USB_MIXER_S16
,
966 for (i
= 0; i
< info
->input_len
; i
++) {
967 snprintf(mx
, sizeof(mx
), "Input Source %02d Capture Route",
969 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_dynamic_enum
,
970 scarlett_ctl_enum_resume
, 0x34,
971 0x00, i
, USB_MIXER_S16
, 1, mx
,
972 &info
->opt_master
, &elem
);
977 /* val_len == 1 needed here */
978 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_enum
,
979 scarlett_ctl_enum_resume
, 0x28, 0x01, 0,
980 USB_MIXER_U8
, 1, "Sample Clock Source",
985 /* val_len == 1 and UAC2_CS_MEM */
986 err
= add_new_ctl(mixer
, &usb_scarlett_ctl_sync
, NULL
, 0x3c, 0x00, 2,
987 USB_MIXER_U8
, 1, "Sample Clock Sync Status",
992 /* initialize sampling rate to 48000 */
993 err
= snd_usb_ctl_msg(mixer
->chip
->dev
,
994 usb_sndctrlpipe(mixer
->chip
->dev
, 0), UAC2_CS_CUR
,
995 USB_RECIP_INTERFACE
| USB_TYPE_CLASS
|
996 USB_DIR_OUT
, 0x0100, snd_usb_ctrl_intf(mixer
->chip
) |
997 (0x29 << 8), sample_rate_buffer
, 4);