1 // SPDX-License-Identifier: GPL-2.0
3 * Focusrite Scarlett 2 Protocol Driver for ALSA
4 * (including Scarlett 2nd Gen, 3rd Gen, Clarett USB, and Clarett+
8 * - 6i6/18i8/18i20 Gen 2
9 * - Solo/2i2/4i4/8i6/18i8/18i20 Gen 3
10 * - Clarett 2Pre/4Pre/8Pre USB
11 * - Clarett+ 2Pre/4Pre/8Pre
13 * Copyright (c) 2018-2023 by Geoffrey D. Bennett <g at b4.vu>
14 * Copyright (c) 2020-2021 by Vladimir Sadovnikov <sadko4u@gmail.com>
15 * Copyright (c) 2022 by Christian Colglazier <christian@cacolglazier.com>
17 * Based on the Scarlett (Gen 1) Driver for ALSA:
19 * Copyright (c) 2013 by Tobias Hoffmann
20 * Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
21 * Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
22 * Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
24 * Many codes borrowed from audio.c by
25 * Alan Cox (alan at lxorguk.ukuu.org.uk)
26 * Thomas Sailer (sailer at ife.ee.ethz.ch)
29 * David Henningsson <david.henningsson at canonical.com>
32 /* The protocol was reverse engineered by looking at the communication
33 * between Focusrite Control 2.3.4 and the Focusrite(R) Scarlett 18i20
34 * (firmware 1083) using usbmon in July-August 2018.
36 * Scarlett 18i8 support added in April 2019.
38 * Scarlett 6i6 support added in June 2019 (thanks to Martin Wittmann
39 * for providing usbmon output and testing).
41 * Scarlett 4i4/8i6 Gen 3 support added in May 2020 (thanks to Laurent
42 * Debricon for donating a 4i4 and to Fredrik Unger for providing 8i6
43 * usbmon output and testing).
45 * Scarlett 18i8/18i20 Gen 3 support added in June 2020 (thanks to
46 * Darren Jaeckel, Alex Sedlack, and Clovis Lunel for providing usbmon
47 * output, protocol traces and testing).
49 * Support for loading mixer volume and mux configuration from the
50 * interface during driver initialisation added in May 2021 (thanks to
51 * Vladimir Sadovnikov for figuring out how).
53 * Support for Solo/2i2 Gen 3 added in May 2021 (thanks to Alexander
54 * Vorona for 2i2 protocol traces).
56 * Support for phantom power, direct monitoring, speaker switching,
57 * and talkback added in May-June 2021.
59 * Support for Clarett+ 8Pre added in Aug 2022 by Christian
62 * Support for Clarett 8Pre USB added in Sep 2023 (thanks to Philippe
63 * Perrot for confirmation).
65 * Support for Clarett+ 4Pre and 2Pre added in Sep 2023 (thanks to
66 * Gregory Rozzo for donating a 4Pre, and David Sherwood and Patrice
67 * Peterson for usbmon output).
69 * Support for Clarett 2Pre and 4Pre USB added in Oct 2023.
71 * This ALSA mixer gives access to (model-dependent):
72 * - input, output, mixer-matrix muxes
73 * - mixer-matrix gain stages
74 * - gain/volume/mute controls
76 * - line/inst level, pad, and air controls
77 * - phantom power, direct monitor, speaker switching, and talkback
79 * - disable/enable MSD mode
80 * - disable/enable standalone mode
83 * /--------------\ 18chn 20chn /--------------\
84 * | Hardware in +--+------\ /-------------+--+ ALSA PCM out |
85 * \--------------/ | | | | \--------------/
89 * | +---------------+ | |
90 * | \ Matrix Mux / | |
97 * | +------------+ | |
101 * | | 18x10 Gain | | |
103 * | +-----+------+ | |
105 * |18chn |10chn | |20chn
110 * ===========================
111 * +---------------+ +--—------------+
112 * \ Output Mux / \ Capture Mux /
113 * +---+---+---+ +-----+-----+
117 * /--------------\ | | | /--------------\
118 * | S/PDIF, ADAT |<--/ |10chn \-->| ALSA PCM in |
119 * | Hardware out | | \--------------/
122 * +-------------+ Software gain per channel.
123 * | Master Gain |<-- 18i20 only: Switch per channel
124 * +------+------+ to select HW or SW gain control.
128 * | Analogue |<------/
133 * Gen 3 devices have a Mass Storage Device (MSD) mode where a small
134 * disk with registration and driver download information is presented
135 * to the host. To access the full functionality of the device without
136 * proprietary software, MSD mode can be disabled by:
137 * - holding down the 48V button for five seconds while powering on
139 * - using this driver and alsamixer to change the "MSD Mode" setting
140 * to Off and power-cycling the device
143 #include <linux/slab.h>
144 #include <linux/usb.h>
145 #include <linux/moduleparam.h>
147 #include <sound/control.h>
148 #include <sound/tlv.h>
150 #include "usbaudio.h"
154 #include "mixer_scarlett2.h"
156 /* device_setup value to allow turning MSD mode back on */
157 #define SCARLETT2_MSD_ENABLE 0x02
159 /* device_setup value to disable this mixer driver */
160 #define SCARLETT2_DISABLE 0x04
162 /* some gui mixers can't handle negative ctl values */
163 #define SCARLETT2_VOLUME_BIAS 127
165 /* mixer range from -80dB to +6dB in 0.5dB steps */
166 #define SCARLETT2_MIXER_MIN_DB -80
167 #define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
168 #define SCARLETT2_MIXER_MAX_DB 6
169 #define SCARLETT2_MIXER_MAX_VALUE \
170 ((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
171 #define SCARLETT2_MIXER_VALUE_COUNT (SCARLETT2_MIXER_MAX_VALUE + 1)
173 /* map from (dB + 80) * 2 to mixer value
174 * for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20)))
176 static const u16 scarlett2_mixer_values[SCARLETT2_MIXER_VALUE_COUNT] = {
177 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
178 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
179 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
180 23, 24, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 46, 48, 51,
181 54, 57, 61, 65, 68, 73, 77, 81, 86, 91, 97, 103, 109, 115,
182 122, 129, 137, 145, 154, 163, 173, 183, 194, 205, 217, 230,
183 244, 259, 274, 290, 307, 326, 345, 365, 387, 410, 434, 460,
184 487, 516, 547, 579, 614, 650, 689, 730, 773, 819, 867, 919,
185 973, 1031, 1092, 1157, 1225, 1298, 1375, 1456, 1543, 1634,
186 1731, 1833, 1942, 2057, 2179, 2308, 2445, 2590, 2744, 2906,
187 3078, 3261, 3454, 3659, 3876, 4105, 4349, 4606, 4879, 5168,
188 5475, 5799, 6143, 6507, 6892, 7301, 7733, 8192, 8677, 9191,
189 9736, 10313, 10924, 11571, 12257, 12983, 13752, 14567, 15430,
193 /* Maximum number of analogue outputs */
194 #define SCARLETT2_ANALOGUE_MAX 10
196 /* Maximum number of level and pad switches */
197 #define SCARLETT2_LEVEL_SWITCH_MAX 2
198 #define SCARLETT2_PAD_SWITCH_MAX 8
199 #define SCARLETT2_AIR_SWITCH_MAX 8
200 #define SCARLETT2_PHANTOM_SWITCH_MAX 2
202 /* Maximum number of inputs to the mixer */
203 #define SCARLETT2_INPUT_MIX_MAX 25
205 /* Maximum number of outputs from the mixer */
206 #define SCARLETT2_OUTPUT_MIX_MAX 12
208 /* Maximum size of the data in the USB mux assignment message:
209 * 20 inputs, 20 outputs, 25 matrix inputs, 12 spare
211 #define SCARLETT2_MUX_MAX 77
213 /* Maximum number of sources (sum of input port counts) */
214 #define SCARLETT2_MAX_SRCS 52
216 /* Maximum number of meters (sum of output port counts) */
217 #define SCARLETT2_MAX_METERS 65
219 /* There are different sets of configuration parameters across the
220 * devices, dependent on series and model.
223 SCARLETT2_CONFIG_SET_GEN_2 = 0,
224 SCARLETT2_CONFIG_SET_GEN_3A = 1,
225 SCARLETT2_CONFIG_SET_GEN_3B = 2,
226 SCARLETT2_CONFIG_SET_CLARETT = 3,
227 SCARLETT2_CONFIG_SET_COUNT = 4
230 /* Hardware port types:
231 * - None (no input to mux)
239 SCARLETT2_PORT_TYPE_NONE = 0,
240 SCARLETT2_PORT_TYPE_ANALOGUE = 1,
241 SCARLETT2_PORT_TYPE_SPDIF = 2,
242 SCARLETT2_PORT_TYPE_ADAT = 3,
243 SCARLETT2_PORT_TYPE_MIX = 4,
244 SCARLETT2_PORT_TYPE_PCM = 5,
245 SCARLETT2_PORT_TYPE_COUNT = 6,
248 /* I/O count of each port type kept in struct scarlett2_ports */
250 SCARLETT2_PORT_IN = 0,
251 SCARLETT2_PORT_OUT = 1,
252 SCARLETT2_PORT_DIRNS = 2,
255 /* Dim/Mute buttons on the 18i20 */
257 SCARLETT2_BUTTON_MUTE = 0,
258 SCARLETT2_BUTTON_DIM = 1,
259 SCARLETT2_DIM_MUTE_COUNT = 2,
262 static const char *const scarlett2_dim_mute_names[SCARLETT2_DIM_MUTE_COUNT] = {
263 "Mute Playback Switch", "Dim Playback Switch"
266 /* Description of each hardware port type:
267 * - id: hardware ID of this port type
268 * - src_descr: printf format string for mux input selections
269 * - src_num_offset: added to channel number for the fprintf
270 * - dst_descr: printf format string for mixer controls
272 struct scarlett2_port {
274 const char * const src_descr;
276 const char * const dst_descr;
279 static const struct scarlett2_port scarlett2_ports[SCARLETT2_PORT_TYPE_COUNT] = {
280 [SCARLETT2_PORT_TYPE_NONE] = {
284 [SCARLETT2_PORT_TYPE_ANALOGUE] = {
286 .src_descr = "Analogue %d",
288 .dst_descr = "Analogue Output %02d Playback"
290 [SCARLETT2_PORT_TYPE_SPDIF] = {
292 .src_descr = "S/PDIF %d",
294 .dst_descr = "S/PDIF Output %d Playback"
296 [SCARLETT2_PORT_TYPE_ADAT] = {
298 .src_descr = "ADAT %d",
300 .dst_descr = "ADAT Output %d Playback"
302 [SCARLETT2_PORT_TYPE_MIX] = {
304 .src_descr = "Mix %c",
305 .src_num_offset = 'A',
306 .dst_descr = "Mixer Input %02d Capture"
308 [SCARLETT2_PORT_TYPE_PCM] = {
310 .src_descr = "PCM %d",
312 .dst_descr = "PCM %02d Capture"
316 /* Number of mux tables: one for each band of sample rates
317 * (44.1/48kHz, 88.2/96kHz, and 176.4/176kHz)
319 #define SCARLETT2_MUX_TABLES 3
321 /* Maximum number of entries in a mux table */
322 #define SCARLETT2_MAX_MUX_ENTRIES 10
324 /* One entry within mux_assignment defines the port type and range of
325 * ports to add to the set_mux message. The end of the list is marked
328 struct scarlett2_mux_entry {
334 /* Maximum number of entries in a mux table */
335 #define SCARLETT2_MAX_METER_ENTRIES 9
337 /* One entry within meter_assignment defines the range of mux outputs
338 * that consecutive meter entries are mapped to. The end of the list
339 * is marked with count == 0.
341 struct scarlett2_meter_entry {
346 struct scarlett2_device_info {
347 /* Gen 3 devices have an internal MSD mode switch that needs
348 * to be disabled in order to access the full functionality of
353 /* which set of configuration parameters the device uses */
356 /* line out hw volume is sw controlled */
359 /* support for main/alt speaker switching */
360 u8 has_speaker_switching;
362 /* support for talkback microphone */
365 /* the number of analogue inputs with a software switchable
366 * level control that can be set to line or instrument
368 u8 level_input_count;
370 /* the first input with a level control (0-based) */
371 u8 level_input_first;
373 /* the number of analogue inputs with a software switchable
378 /* the number of analogue inputs with a software switchable
383 /* the number of phantom (48V) software switchable controls */
386 /* the number of inputs each phantom switch controls */
387 u8 inputs_per_phantom;
389 /* the number of direct monitor options
390 * (0 = none, 1 = mono only, 2 = mono/stereo)
394 /* remap analogue outputs; 18i8 Gen 3 has "line 3/4" connected
395 * internally to the analogue 7/8 outputs
397 u8 line_out_remap_enable;
398 u8 line_out_remap[SCARLETT2_ANALOGUE_MAX];
399 u8 line_out_unmap[SCARLETT2_ANALOGUE_MAX];
401 /* additional description for the line out volume controls */
402 const char * const line_out_descrs[SCARLETT2_ANALOGUE_MAX];
404 /* number of sources/destinations of each port type */
405 const int port_count[SCARLETT2_PORT_TYPE_COUNT][SCARLETT2_PORT_DIRNS];
407 /* layout/order of the entries in the set_mux message */
408 struct scarlett2_mux_entry mux_assignment[SCARLETT2_MUX_TABLES]
409 [SCARLETT2_MAX_MUX_ENTRIES];
411 /* map from meter level order returned by
412 * SCARLETT2_USB_GET_METER to index into mux[] entries (same
413 * as the order returned by scarlett2_meter_ctl_get())
415 struct scarlett2_meter_entry meter_map[SCARLETT2_MAX_METER_ENTRIES];
418 struct scarlett2_data {
419 struct usb_mixer_interface *mixer;
420 struct mutex usb_mutex; /* prevent sending concurrent USB requests */
421 struct mutex data_mutex; /* lock access to this data */
422 struct delayed_work work;
423 const struct scarlett2_device_info *info;
424 const char *series_name;
425 __u8 bInterfaceNumber;
426 __u8 bEndpointAddress;
427 __u16 wMaxPacketSize;
431 u32 firmware_version;
435 u8 input_other_updated;
436 u8 monitor_other_updated;
438 u8 speaker_switching_switched;
441 u8 vol[SCARLETT2_ANALOGUE_MAX];
442 u8 vol_sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
443 u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
444 u8 level_switch[SCARLETT2_LEVEL_SWITCH_MAX];
445 u8 pad_switch[SCARLETT2_PAD_SWITCH_MAX];
446 u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
447 u8 air_switch[SCARLETT2_AIR_SWITCH_MAX];
448 u8 phantom_switch[SCARLETT2_PHANTOM_SWITCH_MAX];
449 u8 phantom_persistence;
450 u8 direct_monitor_switch;
451 u8 speaker_switching_switch;
453 u8 talkback_map[SCARLETT2_OUTPUT_MIX_MAX];
455 u8 standalone_switch;
456 u8 meter_level_map[SCARLETT2_MAX_METERS];
457 struct snd_kcontrol *sync_ctl;
458 struct snd_kcontrol *master_vol_ctl;
459 struct snd_kcontrol *vol_ctls[SCARLETT2_ANALOGUE_MAX];
460 struct snd_kcontrol *sw_hw_ctls[SCARLETT2_ANALOGUE_MAX];
461 struct snd_kcontrol *mute_ctls[SCARLETT2_ANALOGUE_MAX];
462 struct snd_kcontrol *dim_mute_ctls[SCARLETT2_DIM_MUTE_COUNT];
463 struct snd_kcontrol *level_ctls[SCARLETT2_LEVEL_SWITCH_MAX];
464 struct snd_kcontrol *pad_ctls[SCARLETT2_PAD_SWITCH_MAX];
465 struct snd_kcontrol *air_ctls[SCARLETT2_AIR_SWITCH_MAX];
466 struct snd_kcontrol *phantom_ctls[SCARLETT2_PHANTOM_SWITCH_MAX];
467 struct snd_kcontrol *mux_ctls[SCARLETT2_MUX_MAX];
468 struct snd_kcontrol *direct_monitor_ctl;
469 struct snd_kcontrol *speaker_switching_ctl;
470 struct snd_kcontrol *talkback_ctl;
471 u8 mux[SCARLETT2_MUX_MAX];
472 u8 mix[SCARLETT2_INPUT_MIX_MAX * SCARLETT2_OUTPUT_MIX_MAX];
475 /*** Model-specific data ***/
477 static const struct scarlett2_device_info s6i6_gen2_info = {
478 .config_set = SCARLETT2_CONFIG_SET_GEN_2,
479 .level_input_count = 2,
480 .pad_input_count = 2,
490 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
491 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
492 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
493 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
494 [SCARLETT2_PORT_TYPE_PCM] = { 6, 6 },
497 .mux_assignment = { {
498 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
499 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
500 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
501 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
502 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
505 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
506 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
507 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
508 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
509 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
512 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
513 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
514 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
515 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
516 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
527 static const struct scarlett2_device_info s18i8_gen2_info = {
528 .config_set = SCARLETT2_CONFIG_SET_GEN_2,
529 .level_input_count = 2,
530 .pad_input_count = 4,
542 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
543 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
544 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
545 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
546 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
547 [SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
550 .mux_assignment = { {
551 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
552 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
553 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
554 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
555 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
558 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
559 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
560 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
561 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
562 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
565 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
566 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
567 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
568 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
569 { SCARLETT2_PORT_TYPE_NONE, 0, 4 },
580 static const struct scarlett2_device_info s18i20_gen2_info = {
581 .config_set = SCARLETT2_CONFIG_SET_GEN_2,
582 .line_out_hw_vol = 1,
598 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
599 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
600 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
601 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
602 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
603 [SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
606 .mux_assignment = { {
607 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
608 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
609 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
610 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
611 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
612 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
615 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
616 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
617 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
618 { SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
619 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
620 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
623 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
624 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
625 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
626 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
627 { SCARLETT2_PORT_TYPE_NONE, 0, 6 },
638 static const struct scarlett2_device_info solo_gen3_info = {
640 .config_set = SCARLETT2_CONFIG_SET_GEN_3A,
641 .level_input_count = 1,
642 .level_input_first = 1,
643 .air_input_count = 1,
645 .inputs_per_phantom = 1,
649 static const struct scarlett2_device_info s2i2_gen3_info = {
651 .config_set = SCARLETT2_CONFIG_SET_GEN_3A,
652 .level_input_count = 2,
653 .air_input_count = 2,
655 .inputs_per_phantom = 2,
659 static const struct scarlett2_device_info s4i4_gen3_info = {
661 .config_set = SCARLETT2_CONFIG_SET_GEN_3B,
662 .level_input_count = 2,
663 .pad_input_count = 2,
664 .air_input_count = 2,
666 .inputs_per_phantom = 2,
676 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
677 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
678 [SCARLETT2_PORT_TYPE_MIX] = { 6, 8 },
679 [SCARLETT2_PORT_TYPE_PCM] = { 4, 6 },
682 .mux_assignment = { {
683 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
684 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
685 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
686 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
689 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
690 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
691 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
692 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
695 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
696 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
697 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
698 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
709 static const struct scarlett2_device_info s8i6_gen3_info = {
711 .config_set = SCARLETT2_CONFIG_SET_GEN_3B,
712 .level_input_count = 2,
713 .pad_input_count = 2,
714 .air_input_count = 2,
716 .inputs_per_phantom = 2,
726 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
727 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 6, 4 },
728 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
729 [SCARLETT2_PORT_TYPE_MIX] = { 8, 8 },
730 [SCARLETT2_PORT_TYPE_PCM] = { 6, 10 },
733 .mux_assignment = { {
734 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
735 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
736 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
737 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
738 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
739 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
742 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
743 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
744 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
745 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
746 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
747 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
750 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
751 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
752 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
753 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
754 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
755 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
768 static const struct scarlett2_device_info s18i8_gen3_info = {
770 .config_set = SCARLETT2_CONFIG_SET_GEN_3B,
771 .line_out_hw_vol = 1,
772 .has_speaker_switching = 1,
773 .level_input_count = 2,
774 .pad_input_count = 4,
775 .air_input_count = 4,
777 .inputs_per_phantom = 2,
779 .line_out_remap_enable = 1,
780 .line_out_remap = { 0, 1, 6, 7, 2, 3, 4, 5 },
781 .line_out_unmap = { 0, 1, 4, 5, 6, 7, 2, 3 },
795 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
796 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 8 },
797 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
798 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
799 [SCARLETT2_PORT_TYPE_MIX] = { 10, 20 },
800 [SCARLETT2_PORT_TYPE_PCM] = { 8, 20 },
803 .mux_assignment = { {
804 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
805 { SCARLETT2_PORT_TYPE_PCM, 12, 8 },
806 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
807 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
808 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
809 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
810 { SCARLETT2_PORT_TYPE_PCM, 10, 2 },
811 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
812 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
815 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
816 { SCARLETT2_PORT_TYPE_PCM, 12, 4 },
817 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
818 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
819 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
820 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
821 { SCARLETT2_PORT_TYPE_PCM, 10, 2 },
822 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
823 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
826 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
827 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
828 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
829 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
830 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
831 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
832 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
849 static const struct scarlett2_device_info s18i20_gen3_info = {
851 .config_set = SCARLETT2_CONFIG_SET_GEN_3B,
852 .line_out_hw_vol = 1,
853 .has_speaker_switching = 1,
855 .level_input_count = 2,
856 .pad_input_count = 8,
857 .air_input_count = 8,
859 .inputs_per_phantom = 4,
875 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
876 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 9, 10 },
877 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
878 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
879 [SCARLETT2_PORT_TYPE_MIX] = { 12, 25 },
880 [SCARLETT2_PORT_TYPE_PCM] = { 20, 20 },
883 .mux_assignment = { {
884 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
885 { SCARLETT2_PORT_TYPE_PCM, 10, 10 },
886 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
887 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
888 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
889 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
890 { SCARLETT2_PORT_TYPE_MIX, 0, 25 },
891 { SCARLETT2_PORT_TYPE_NONE, 0, 12 },
894 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
895 { SCARLETT2_PORT_TYPE_PCM, 10, 8 },
896 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
897 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
898 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
899 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
900 { SCARLETT2_PORT_TYPE_MIX, 0, 25 },
901 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
904 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
905 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
906 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
907 { SCARLETT2_PORT_TYPE_NONE, 0, 24 },
921 static const struct scarlett2_device_info clarett_2pre_info = {
922 .config_set = SCARLETT2_CONFIG_SET_CLARETT,
923 .line_out_hw_vol = 1,
924 .level_input_count = 2,
925 .air_input_count = 2,
935 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
936 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 4 },
937 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 0 },
938 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
939 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
940 [SCARLETT2_PORT_TYPE_PCM] = { 4, 12 },
943 .mux_assignment = { {
944 { SCARLETT2_PORT_TYPE_PCM, 0, 12 },
945 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
946 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
947 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
950 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
951 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
952 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
953 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
956 { SCARLETT2_PORT_TYPE_PCM, 0, 2 },
957 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
958 { SCARLETT2_PORT_TYPE_NONE, 0, 26 },
969 static const struct scarlett2_device_info clarett_4pre_info = {
970 .config_set = SCARLETT2_CONFIG_SET_CLARETT,
971 .line_out_hw_vol = 1,
972 .level_input_count = 2,
973 .air_input_count = 4,
985 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
986 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
987 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
988 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
989 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
990 [SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
993 .mux_assignment = { {
994 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
995 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
996 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
997 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
998 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1001 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
1002 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
1003 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1004 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1005 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1008 { SCARLETT2_PORT_TYPE_PCM, 0, 12 },
1009 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
1010 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1011 { SCARLETT2_PORT_TYPE_NONE, 0, 24 },
1022 static const struct scarlett2_device_info clarett_8pre_info = {
1023 .config_set = SCARLETT2_CONFIG_SET_CLARETT,
1024 .line_out_hw_vol = 1,
1025 .level_input_count = 2,
1026 .air_input_count = 8,
1028 .line_out_descrs = {
1042 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
1043 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
1044 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
1045 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
1046 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
1047 [SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
1050 .mux_assignment = { {
1051 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
1052 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1053 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1054 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
1055 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1056 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1059 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
1060 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1061 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1062 { SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
1063 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1064 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1067 { SCARLETT2_PORT_TYPE_PCM, 0, 12 },
1068 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1069 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1070 { SCARLETT2_PORT_TYPE_NONE, 0, 22 },
1081 struct scarlett2_device_entry {
1082 const u32 usb_id; /* USB device identifier */
1083 const struct scarlett2_device_info *info;
1084 const char *series_name;
1087 static const struct scarlett2_device_entry scarlett2_devices[] = {
1088 /* Supported Gen 2 devices */
1089 { USB_ID(0x1235, 0x8203), &s6i6_gen2_info, "Scarlett Gen 2" },
1090 { USB_ID(0x1235, 0x8204), &s18i8_gen2_info, "Scarlett Gen 2" },
1091 { USB_ID(0x1235, 0x8201), &s18i20_gen2_info, "Scarlett Gen 2" },
1093 /* Supported Gen 3 devices */
1094 { USB_ID(0x1235, 0x8211), &solo_gen3_info, "Scarlett Gen 3" },
1095 { USB_ID(0x1235, 0x8210), &s2i2_gen3_info, "Scarlett Gen 3" },
1096 { USB_ID(0x1235, 0x8212), &s4i4_gen3_info, "Scarlett Gen 3" },
1097 { USB_ID(0x1235, 0x8213), &s8i6_gen3_info, "Scarlett Gen 3" },
1098 { USB_ID(0x1235, 0x8214), &s18i8_gen3_info, "Scarlett Gen 3" },
1099 { USB_ID(0x1235, 0x8215), &s18i20_gen3_info, "Scarlett Gen 3" },
1101 /* Supported Clarett USB/Clarett+ devices */
1102 { USB_ID(0x1235, 0x8206), &clarett_2pre_info, "Clarett USB" },
1103 { USB_ID(0x1235, 0x8207), &clarett_4pre_info, "Clarett USB" },
1104 { USB_ID(0x1235, 0x8208), &clarett_8pre_info, "Clarett USB" },
1105 { USB_ID(0x1235, 0x820a), &clarett_2pre_info, "Clarett+" },
1106 { USB_ID(0x1235, 0x820b), &clarett_4pre_info, "Clarett+" },
1107 { USB_ID(0x1235, 0x820c), &clarett_8pre_info, "Clarett+" },
1113 /* get the starting port index number for a given port type/direction */
1114 static int scarlett2_get_port_start_num(
1115 const int port_count[][SCARLETT2_PORT_DIRNS],
1116 int direction, int port_type)
1120 for (i = 0; i < port_type; i++)
1121 num += port_count[i][direction];
1126 /*** USB Interactions ***/
1128 /* Notifications from the interface */
1129 #define SCARLETT2_USB_NOTIFY_SYNC 0x00000008
1130 #define SCARLETT2_USB_NOTIFY_DIM_MUTE 0x00200000
1131 #define SCARLETT2_USB_NOTIFY_MONITOR 0x00400000
1132 #define SCARLETT2_USB_NOTIFY_INPUT_OTHER 0x00800000
1133 #define SCARLETT2_USB_NOTIFY_MONITOR_OTHER 0x01000000
1135 /* Commands for sending/receiving requests/responses */
1136 #define SCARLETT2_USB_CMD_INIT 0
1137 #define SCARLETT2_USB_CMD_REQ 2
1138 #define SCARLETT2_USB_CMD_RESP 3
1140 #define SCARLETT2_USB_INIT_1 0x00000000
1141 #define SCARLETT2_USB_INIT_2 0x00000002
1142 #define SCARLETT2_USB_GET_METER 0x00001001
1143 #define SCARLETT2_USB_GET_MIX 0x00002001
1144 #define SCARLETT2_USB_SET_MIX 0x00002002
1145 #define SCARLETT2_USB_GET_MUX 0x00003001
1146 #define SCARLETT2_USB_SET_MUX 0x00003002
1147 #define SCARLETT2_USB_GET_SYNC 0x00006004
1148 #define SCARLETT2_USB_GET_DATA 0x00800000
1149 #define SCARLETT2_USB_SET_DATA 0x00800001
1150 #define SCARLETT2_USB_DATA_CMD 0x00800002
1152 #define SCARLETT2_USB_CONFIG_SAVE 6
1154 #define SCARLETT2_USB_VOLUME_STATUS_OFFSET 0x31
1155 #define SCARLETT2_USB_METER_LEVELS_GET_MAGIC 1
1157 /* volume status is read together (matches scarlett2_config_items[1]) */
1158 struct scarlett2_usb_volume_status {
1159 /* dim/mute buttons */
1160 u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
1164 /* software volume setting */
1165 s16 sw_vol[SCARLETT2_ANALOGUE_MAX];
1167 /* actual volume of output inc. dim (-18dB) */
1168 s16 hw_vol[SCARLETT2_ANALOGUE_MAX];
1170 /* internal mute buttons */
1171 u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
1173 /* sw (0) or hw (1) controlled */
1174 u8 sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
1178 /* front panel volume knob */
1182 /* Configuration parameters that can be read and written */
1184 SCARLETT2_CONFIG_DIM_MUTE = 0,
1185 SCARLETT2_CONFIG_LINE_OUT_VOLUME = 1,
1186 SCARLETT2_CONFIG_MUTE_SWITCH = 2,
1187 SCARLETT2_CONFIG_SW_HW_SWITCH = 3,
1188 SCARLETT2_CONFIG_LEVEL_SWITCH = 4,
1189 SCARLETT2_CONFIG_PAD_SWITCH = 5,
1190 SCARLETT2_CONFIG_MSD_SWITCH = 6,
1191 SCARLETT2_CONFIG_AIR_SWITCH = 7,
1192 SCARLETT2_CONFIG_STANDALONE_SWITCH = 8,
1193 SCARLETT2_CONFIG_PHANTOM_SWITCH = 9,
1194 SCARLETT2_CONFIG_PHANTOM_PERSISTENCE = 10,
1195 SCARLETT2_CONFIG_DIRECT_MONITOR = 11,
1196 SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH = 12,
1197 SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE = 13,
1198 SCARLETT2_CONFIG_TALKBACK_MAP = 14,
1199 SCARLETT2_CONFIG_COUNT = 15
1202 /* Location, size, and activation command number for the configuration
1203 * parameters. Size is in bits and may be 1, 8, or 16.
1205 struct scarlett2_config {
1211 static const struct scarlett2_config
1212 scarlett2_config_items[SCARLETT2_CONFIG_SET_COUNT]
1213 [SCARLETT2_CONFIG_COUNT] =
1215 /* Gen 2 devices: 6i6, 18i8, 18i20 */
1217 [SCARLETT2_CONFIG_DIM_MUTE] = {
1218 .offset = 0x31, .size = 8, .activate = 2 },
1220 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
1221 .offset = 0x34, .size = 16, .activate = 1 },
1223 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
1224 .offset = 0x5c, .size = 8, .activate = 1 },
1226 [SCARLETT2_CONFIG_SW_HW_SWITCH] = {
1227 .offset = 0x66, .size = 8, .activate = 3 },
1229 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
1230 .offset = 0x7c, .size = 8, .activate = 7 },
1232 [SCARLETT2_CONFIG_PAD_SWITCH] = {
1233 .offset = 0x84, .size = 8, .activate = 8 },
1235 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
1236 .offset = 0x8d, .size = 8, .activate = 6 },
1238 /* Gen 3 devices without a mixer (Solo and 2i2) */
1240 [SCARLETT2_CONFIG_MSD_SWITCH] = {
1241 .offset = 0x04, .size = 8, .activate = 6 },
1243 [SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
1244 .offset = 0x05, .size = 8, .activate = 6 },
1246 [SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
1247 .offset = 0x06, .size = 8, .activate = 3 },
1249 [SCARLETT2_CONFIG_DIRECT_MONITOR] = {
1250 .offset = 0x07, .size = 8, .activate = 4 },
1252 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
1253 .offset = 0x08, .size = 1, .activate = 7 },
1255 [SCARLETT2_CONFIG_AIR_SWITCH] = {
1256 .offset = 0x09, .size = 1, .activate = 8 },
1258 /* Gen 3 devices: 4i4, 8i6, 18i8, 18i20 */
1260 [SCARLETT2_CONFIG_DIM_MUTE] = {
1261 .offset = 0x31, .size = 8, .activate = 2 },
1263 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
1264 .offset = 0x34, .size = 16, .activate = 1 },
1266 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
1267 .offset = 0x5c, .size = 8, .activate = 1 },
1269 [SCARLETT2_CONFIG_SW_HW_SWITCH] = {
1270 .offset = 0x66, .size = 8, .activate = 3 },
1272 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
1273 .offset = 0x7c, .size = 8, .activate = 7 },
1275 [SCARLETT2_CONFIG_PAD_SWITCH] = {
1276 .offset = 0x84, .size = 8, .activate = 8 },
1278 [SCARLETT2_CONFIG_AIR_SWITCH] = {
1279 .offset = 0x8c, .size = 8, .activate = 8 },
1281 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
1282 .offset = 0x95, .size = 8, .activate = 6 },
1284 [SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
1285 .offset = 0x9c, .size = 1, .activate = 8 },
1287 [SCARLETT2_CONFIG_MSD_SWITCH] = {
1288 .offset = 0x9d, .size = 8, .activate = 6 },
1290 [SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
1291 .offset = 0x9e, .size = 8, .activate = 6 },
1293 [SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH] = {
1294 .offset = 0x9f, .size = 1, .activate = 10 },
1296 [SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE] = {
1297 .offset = 0xa0, .size = 1, .activate = 10 },
1299 [SCARLETT2_CONFIG_TALKBACK_MAP] = {
1300 .offset = 0xb0, .size = 16, .activate = 10 },
1302 /* Clarett USB and Clarett+ devices: 2Pre, 4Pre, 8Pre */
1304 [SCARLETT2_CONFIG_DIM_MUTE] = {
1305 .offset = 0x31, .size = 8, .activate = 2 },
1307 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
1308 .offset = 0x34, .size = 16, .activate = 1 },
1310 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
1311 .offset = 0x5c, .size = 8, .activate = 1 },
1313 [SCARLETT2_CONFIG_SW_HW_SWITCH] = {
1314 .offset = 0x66, .size = 8, .activate = 3 },
1316 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
1317 .offset = 0x7c, .size = 8, .activate = 7 },
1319 [SCARLETT2_CONFIG_AIR_SWITCH] = {
1320 .offset = 0x95, .size = 8, .activate = 8 },
1322 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
1323 .offset = 0x8d, .size = 8, .activate = 6 },
1326 /* proprietary request/response format */
1327 struct scarlett2_usb_packet {
1336 static void scarlett2_fill_request_header(struct scarlett2_data *private,
1337 struct scarlett2_usb_packet *req,
1338 u32 cmd, u16 req_size)
1340 /* sequence must go up by 1 for each request */
1341 u16 seq = private->scarlett2_seq++;
1343 req->cmd = cpu_to_le32(cmd);
1344 req->size = cpu_to_le16(req_size);
1345 req->seq = cpu_to_le16(seq);
1350 static int scarlett2_usb_tx(struct usb_device *dev, int interface,
1351 void *buf, u16 size)
1353 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1354 SCARLETT2_USB_CMD_REQ,
1355 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1356 0, interface, buf, size);
1359 static int scarlett2_usb_rx(struct usb_device *dev, int interface,
1360 u32 usb_req, void *buf, u16 size)
1362 return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1364 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1365 0, interface, buf, size);
1368 /* Send a proprietary format request to the Scarlett interface */
1369 static int scarlett2_usb(
1370 struct usb_mixer_interface *mixer, u32 cmd,
1371 void *req_data, u16 req_size, void *resp_data, u16 resp_size)
1373 struct scarlett2_data *private = mixer->private_data;
1374 struct usb_device *dev = mixer->chip->dev;
1375 struct scarlett2_usb_packet *req, *resp = NULL;
1376 size_t req_buf_size = struct_size(req, data, req_size);
1377 size_t resp_buf_size = struct_size(resp, data, resp_size);
1380 req = kmalloc(req_buf_size, GFP_KERNEL);
1386 resp = kmalloc(resp_buf_size, GFP_KERNEL);
1392 mutex_lock(&private->usb_mutex);
1394 /* build request message and send it */
1396 scarlett2_fill_request_header(private, req, cmd, req_size);
1399 memcpy(req->data, req_data, req_size);
1401 err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
1404 if (err != req_buf_size) {
1407 "%s USB request result cmd %x was %d\n",
1408 private->series_name, cmd, err);
1413 /* send a second message to get the response */
1415 err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
1416 SCARLETT2_USB_CMD_RESP,
1417 resp, resp_buf_size);
1419 /* validate the response */
1421 if (err != resp_buf_size) {
1424 "%s USB response result cmd %x was %d expected %zu\n",
1425 private->series_name, cmd, err, resp_buf_size);
1430 /* cmd/seq/size should match except when initialising
1431 * seq sent = 1, response = 0
1433 if (resp->cmd != req->cmd ||
1434 (resp->seq != req->seq &&
1435 (le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
1436 resp_size != le16_to_cpu(resp->size) ||
1441 "%s USB invalid response; "
1442 "cmd tx/rx %d/%d seq %d/%d size %d/%d "
1443 "error %d pad %d\n",
1444 private->series_name,
1445 le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
1446 le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
1447 resp_size, le16_to_cpu(resp->size),
1448 le32_to_cpu(resp->error),
1449 le32_to_cpu(resp->pad));
1454 if (resp_data && resp_size > 0)
1455 memcpy(resp_data, resp->data, resp_size);
1458 mutex_unlock(&private->usb_mutex);
1465 /* Send a USB message to get data; result placed in *buf */
1466 static int scarlett2_usb_get(
1467 struct usb_mixer_interface *mixer,
1468 int offset, void *buf, int size)
1475 req.offset = cpu_to_le32(offset);
1476 req.size = cpu_to_le32(size);
1477 return scarlett2_usb(mixer, SCARLETT2_USB_GET_DATA,
1478 &req, sizeof(req), buf, size);
1481 /* Send a USB message to get configuration parameters; result placed in *buf */
1482 static int scarlett2_usb_get_config(
1483 struct usb_mixer_interface *mixer,
1484 int config_item_num, int count, void *buf)
1486 struct scarlett2_data *private = mixer->private_data;
1487 const struct scarlett2_device_info *info = private->info;
1488 const struct scarlett2_config *config_item =
1489 &scarlett2_config_items[info->config_set][config_item_num];
1494 /* For byte-sized parameters, retrieve directly into buf */
1495 if (config_item->size >= 8) {
1496 size = config_item->size / 8 * count;
1497 err = scarlett2_usb_get(mixer, config_item->offset, buf, size);
1503 for (i = 0; i < count; i++, buf_16++)
1504 *buf_16 = le16_to_cpu(*(__le16 *)buf_16);
1509 /* For bit-sized parameters, retrieve into value */
1510 err = scarlett2_usb_get(mixer, config_item->offset, &value, 1);
1514 /* then unpack from value into buf[] */
1516 for (i = 0; i < 8 && i < count; i++, value >>= 1)
1517 *buf_8++ = value & 1;
1522 /* Send SCARLETT2_USB_DATA_CMD SCARLETT2_USB_CONFIG_SAVE */
1523 static void scarlett2_config_save(struct usb_mixer_interface *mixer)
1525 __le32 req = cpu_to_le32(SCARLETT2_USB_CONFIG_SAVE);
1527 scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
1532 /* Delayed work to save config */
1533 static void scarlett2_config_save_work(struct work_struct *work)
1535 struct scarlett2_data *private =
1536 container_of(work, struct scarlett2_data, work.work);
1538 scarlett2_config_save(private->mixer);
1541 /* Send a USB message to set a SCARLETT2_CONFIG_* parameter */
1542 static int scarlett2_usb_set_config(
1543 struct usb_mixer_interface *mixer,
1544 int config_item_num, int index, int value)
1546 struct scarlett2_data *private = mixer->private_data;
1547 const struct scarlett2_device_info *info = private->info;
1548 const struct scarlett2_config *config_item =
1549 &scarlett2_config_items[info->config_set][config_item_num];
1559 /* Cancel any pending NVRAM save */
1560 cancel_delayed_work_sync(&private->work);
1562 /* Convert config_item->size in bits to size in bytes and
1565 if (config_item->size >= 8) {
1566 size = config_item->size / 8;
1567 offset = config_item->offset + index * size;
1569 /* If updating a bit, retrieve the old value, set/clear the
1570 * bit as needed, and update value
1576 offset = config_item->offset;
1578 scarlett2_usb_get(mixer, offset, &tmp, 1);
1580 tmp |= (1 << index);
1582 tmp &= ~(1 << index);
1587 /* Send the configuration parameter data */
1588 req.offset = cpu_to_le32(offset);
1589 req.bytes = cpu_to_le32(size);
1590 req.value = cpu_to_le32(value);
1591 err = scarlett2_usb(mixer, SCARLETT2_USB_SET_DATA,
1592 &req, sizeof(u32) * 2 + size,
1597 /* Activate the change */
1598 req2 = cpu_to_le32(config_item->activate);
1599 err = scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
1600 &req2, sizeof(req2), NULL, 0);
1604 /* Schedule the change to be written to NVRAM */
1605 if (config_item->activate != SCARLETT2_USB_CONFIG_SAVE)
1606 schedule_delayed_work(&private->work, msecs_to_jiffies(2000));
1611 /* Send a USB message to get sync status; result placed in *sync */
1612 static int scarlett2_usb_get_sync_status(
1613 struct usb_mixer_interface *mixer,
1619 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_SYNC,
1620 NULL, 0, &data, sizeof(data));
1628 /* Send a USB message to get volume status; result placed in *buf */
1629 static int scarlett2_usb_get_volume_status(
1630 struct usb_mixer_interface *mixer,
1631 struct scarlett2_usb_volume_status *buf)
1633 return scarlett2_usb_get(mixer, SCARLETT2_USB_VOLUME_STATUS_OFFSET,
1637 /* Send a USB message to get the volumes for all inputs of one mix
1638 * and put the values into private->mix[]
1640 static int scarlett2_usb_get_mix(struct usb_mixer_interface *mixer,
1643 struct scarlett2_data *private = mixer->private_data;
1644 const struct scarlett2_device_info *info = private->info;
1647 info->port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
1655 __le16 data[SCARLETT2_INPUT_MIX_MAX];
1657 req.mix_num = cpu_to_le16(mix_num);
1658 req.count = cpu_to_le16(num_mixer_in);
1660 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MIX,
1662 data, num_mixer_in * sizeof(u16));
1666 for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++) {
1667 u16 mixer_value = le16_to_cpu(data[i]);
1669 for (k = 0; k < SCARLETT2_MIXER_VALUE_COUNT; k++)
1670 if (scarlett2_mixer_values[k] >= mixer_value)
1672 if (k == SCARLETT2_MIXER_VALUE_COUNT)
1673 k = SCARLETT2_MIXER_MAX_VALUE;
1674 private->mix[j] = k;
1680 /* Send a USB message to set the volumes for all inputs of one mix
1681 * (values obtained from private->mix[])
1683 static int scarlett2_usb_set_mix(struct usb_mixer_interface *mixer,
1686 struct scarlett2_data *private = mixer->private_data;
1687 const struct scarlett2_device_info *info = private->info;
1691 __le16 data[SCARLETT2_INPUT_MIX_MAX];
1696 info->port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
1698 req.mix_num = cpu_to_le16(mix_num);
1700 for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
1701 req.data[i] = cpu_to_le16(
1702 scarlett2_mixer_values[private->mix[j]]
1705 return scarlett2_usb(mixer, SCARLETT2_USB_SET_MIX,
1706 &req, (num_mixer_in + 1) * sizeof(u16),
1710 /* Convert a port number index (per info->port_count) to a hardware ID */
1711 static u32 scarlett2_mux_src_num_to_id(
1712 const int port_count[][SCARLETT2_PORT_DIRNS], int num)
1717 port_type < SCARLETT2_PORT_TYPE_COUNT;
1719 if (num < port_count[port_type][SCARLETT2_PORT_IN])
1720 return scarlett2_ports[port_type].id | num;
1721 num -= port_count[port_type][SCARLETT2_PORT_IN];
1728 /* Convert a hardware ID to a port number index */
1729 static u32 scarlett2_mux_id_to_num(
1730 const int port_count[][SCARLETT2_PORT_DIRNS], int direction, u32 id)
1736 port_type < SCARLETT2_PORT_TYPE_COUNT;
1738 int base = scarlett2_ports[port_type].id;
1739 int count = port_count[port_type][direction];
1741 if (id >= base && id < base + count)
1742 return port_num + id - base;
1750 /* Convert one mux entry from the interface and load into private->mux[] */
1751 static void scarlett2_usb_populate_mux(struct scarlett2_data *private,
1754 const struct scarlett2_device_info *info = private->info;
1755 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
1757 int dst_idx, src_idx;
1759 dst_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_OUT,
1764 if (dst_idx >= private->num_mux_dsts) {
1765 usb_audio_err(private->mixer->chip,
1766 "BUG: scarlett2_mux_id_to_num(%06x, OUT): %d >= %d",
1767 mux_entry, dst_idx, private->num_mux_dsts);
1771 src_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_IN,
1776 if (src_idx >= private->num_mux_srcs) {
1777 usb_audio_err(private->mixer->chip,
1778 "BUG: scarlett2_mux_id_to_num(%06x, IN): %d >= %d",
1779 mux_entry, src_idx, private->num_mux_srcs);
1783 private->mux[dst_idx] = src_idx;
1786 /* Update the meter level map
1788 * The meter level data from the interface (SCARLETT2_USB_GET_METER
1789 * request) is returned in mux_assignment order, but to avoid exposing
1790 * that to userspace, scarlett2_meter_ctl_get() rearranges the data
1791 * into scarlett2_ports order using the meter_level_map[] array which
1792 * is set up by this function.
1794 * In addition, the meter level data values returned from the
1795 * interface are invalid for destinations where:
1797 * - the source is "Off"; therefore we set those values to zero (map
1800 * - the source is assigned to a previous (with respect to the
1801 * mux_assignment order) destination; therefore we set those values
1802 * to the value previously reported for that source
1804 static void scarlett2_update_meter_level_map(struct scarlett2_data *private)
1806 const struct scarlett2_device_info *info = private->info;
1807 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
1808 int line_out_count =
1809 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
1810 const struct scarlett2_meter_entry *entry;
1812 /* sources already assigned to a destination
1813 * value is 255 for None, otherwise the value of i
1814 * (index into array returned by
1815 * scarlett2_usb_get_meter_levels())
1817 u8 seen_src[SCARLETT2_MAX_SRCS] = { 1 };
1818 u8 seen_src_value[SCARLETT2_MAX_SRCS] = { 255 };
1820 /* index in meter_map[] order */
1823 /* go through the meter_map[] entries */
1824 for (entry = info->meter_map;
1828 /* fill in each meter_level_map[] entry */
1831 for (j = 0, mux_idx = entry->start;
1833 i++, j++, mux_idx++) {
1835 /* convert mux_idx using line_out_unmap[] */
1837 info->line_out_remap_enable &&
1838 mux_idx < line_out_count
1839 ) ? info->line_out_unmap[mux_idx]
1842 /* check which source is connected, and if
1843 * that source is already connected elsewhere,
1844 * use that existing connection's destination
1845 * for this meter entry instead
1847 int mux_src = private->mux[mux_idx];
1849 if (!seen_src[mux_src]) {
1850 seen_src[mux_src] = 1;
1851 seen_src_value[mux_src] = i;
1853 private->meter_level_map[map_mux_idx] =
1854 seen_src_value[mux_src];
1859 /* Send USB message to get mux inputs and then populate private->mux[] */
1860 static int scarlett2_usb_get_mux(struct usb_mixer_interface *mixer)
1862 struct scarlett2_data *private = mixer->private_data;
1863 int count = private->num_mux_dsts;
1871 __le32 data[SCARLETT2_MUX_MAX];
1873 private->mux_updated = 0;
1876 req.count = cpu_to_le16(count);
1878 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MUX,
1880 data, count * sizeof(u32));
1884 for (i = 0; i < count; i++)
1885 scarlett2_usb_populate_mux(private, le32_to_cpu(data[i]));
1887 scarlett2_update_meter_level_map(private);
1892 /* Send USB messages to set mux inputs */
1893 static int scarlett2_usb_set_mux(struct usb_mixer_interface *mixer)
1895 struct scarlett2_data *private = mixer->private_data;
1896 const struct scarlett2_device_info *info = private->info;
1897 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
1903 __le32 data[SCARLETT2_MUX_MAX];
1908 /* set mux settings for each rate */
1909 for (table = 0; table < SCARLETT2_MUX_TABLES; table++) {
1910 const struct scarlett2_mux_entry *entry;
1912 /* i counts over the output array */
1915 req.num = cpu_to_le16(table);
1917 /* loop through each entry */
1918 for (entry = info->mux_assignment[table];
1922 int port_type = entry->port_type;
1923 int port_idx = entry->start;
1924 int mux_idx = scarlett2_get_port_start_num(port_count,
1925 SCARLETT2_PORT_OUT, port_type) + port_idx;
1926 int dst_id = scarlett2_ports[port_type].id + port_idx;
1930 for (j = 0; j < entry->count; j++)
1935 /* Non-empty mux slots use the lower 12 bits
1936 * for the destination and next 12 bits for
1939 for (j = 0; j < entry->count; j++) {
1940 int src_id = scarlett2_mux_src_num_to_id(
1941 port_count, private->mux[mux_idx++]);
1942 req.data[i++] = cpu_to_le32(dst_id |
1948 err = scarlett2_usb(mixer, SCARLETT2_USB_SET_MUX,
1949 &req, (i + 1) * sizeof(u32),
1955 scarlett2_update_meter_level_map(private);
1960 /* Send USB message to get meter levels */
1961 static int scarlett2_usb_get_meter_levels(struct usb_mixer_interface *mixer,
1962 u16 num_meters, u16 *levels)
1969 __le32 resp[SCARLETT2_MAX_METERS];
1973 req.num_meters = cpu_to_le16(num_meters);
1974 req.magic = cpu_to_le32(SCARLETT2_USB_METER_LEVELS_GET_MAGIC);
1975 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_METER,
1976 &req, sizeof(req), resp, num_meters * sizeof(u32));
1980 /* copy, convert to u16 */
1981 for (i = 0; i < num_meters; i++)
1982 levels[i] = le32_to_cpu(resp[i]);
1987 /*** Control Functions ***/
1989 /* helper function to create a new control */
1990 static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
1991 const struct snd_kcontrol_new *ncontrol,
1992 int index, int channels, const char *name,
1993 struct snd_kcontrol **kctl_return)
1995 struct snd_kcontrol *kctl;
1996 struct usb_mixer_elem_info *elem;
1999 elem = kzalloc(sizeof(*elem), GFP_KERNEL);
2003 /* We set USB_MIXER_BESPOKEN type, so that the core USB mixer code
2004 * ignores them for resume and other operations.
2005 * Also, the head.id field is set to 0, as we don't use this field.
2007 elem->head.mixer = mixer;
2008 elem->control = index;
2010 elem->channels = channels;
2011 elem->val_type = USB_MIXER_BESPOKEN;
2013 kctl = snd_ctl_new1(ncontrol, elem);
2018 kctl->private_free = snd_usb_mixer_elem_free;
2020 strscpy(kctl->id.name, name, sizeof(kctl->id.name));
2022 err = snd_usb_mixer_add_control(&elem->head, kctl);
2027 *kctl_return = kctl;
2032 /*** Firmware Version Control ***/
2034 static int scarlett2_firmware_version_ctl_get(
2035 struct snd_kcontrol *kctl,
2036 struct snd_ctl_elem_value *ucontrol)
2038 struct usb_mixer_elem_info *elem = kctl->private_data;
2039 struct scarlett2_data *private = elem->head.mixer->private_data;
2041 ucontrol->value.integer.value[0] = private->firmware_version;
2046 static int scarlett2_firmware_version_ctl_info(
2047 struct snd_kcontrol *kctl,
2048 struct snd_ctl_elem_info *uinfo)
2050 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2056 static const struct snd_kcontrol_new scarlett2_firmware_version_ctl = {
2057 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
2058 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2060 .info = scarlett2_firmware_version_ctl_info,
2061 .get = scarlett2_firmware_version_ctl_get
2064 static int scarlett2_add_firmware_version_ctl(
2065 struct usb_mixer_interface *mixer)
2067 return scarlett2_add_new_ctl(mixer, &scarlett2_firmware_version_ctl,
2068 0, 0, "Firmware Version", NULL);
2070 /*** Sync Control ***/
2072 /* Update sync control after receiving notification that the status
2075 static int scarlett2_update_sync(struct usb_mixer_interface *mixer)
2077 struct scarlett2_data *private = mixer->private_data;
2079 private->sync_updated = 0;
2080 return scarlett2_usb_get_sync_status(mixer, &private->sync);
2083 static int scarlett2_sync_ctl_info(struct snd_kcontrol *kctl,
2084 struct snd_ctl_elem_info *uinfo)
2086 static const char *texts[2] = {
2087 "Unlocked", "Locked"
2089 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2092 static int scarlett2_sync_ctl_get(struct snd_kcontrol *kctl,
2093 struct snd_ctl_elem_value *ucontrol)
2095 struct usb_mixer_elem_info *elem = kctl->private_data;
2096 struct usb_mixer_interface *mixer = elem->head.mixer;
2097 struct scarlett2_data *private = mixer->private_data;
2099 mutex_lock(&private->data_mutex);
2100 if (private->sync_updated)
2101 scarlett2_update_sync(mixer);
2102 ucontrol->value.enumerated.item[0] = private->sync;
2103 mutex_unlock(&private->data_mutex);
2108 static const struct snd_kcontrol_new scarlett2_sync_ctl = {
2109 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2110 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2112 .info = scarlett2_sync_ctl_info,
2113 .get = scarlett2_sync_ctl_get
2116 static int scarlett2_add_sync_ctl(struct usb_mixer_interface *mixer)
2118 struct scarlett2_data *private = mixer->private_data;
2120 /* devices without a mixer also don't support reporting sync status */
2121 if (private->info->config_set == SCARLETT2_CONFIG_SET_GEN_3A)
2124 return scarlett2_add_new_ctl(mixer, &scarlett2_sync_ctl,
2125 0, 1, "Sync Status", &private->sync_ctl);
2128 /*** Analogue Line Out Volume Controls ***/
2130 /* Update hardware volume controls after receiving notification that
2133 static int scarlett2_update_volumes(struct usb_mixer_interface *mixer)
2135 struct scarlett2_data *private = mixer->private_data;
2136 const struct scarlett2_device_info *info = private->info;
2137 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2138 struct scarlett2_usb_volume_status volume_status;
2140 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
2144 private->vol_updated = 0;
2146 err = scarlett2_usb_get_volume_status(mixer, &volume_status);
2150 private->master_vol = clamp(
2151 volume_status.master_vol + SCARLETT2_VOLUME_BIAS,
2152 0, SCARLETT2_VOLUME_BIAS);
2154 if (info->line_out_hw_vol)
2155 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
2156 private->dim_mute[i] = !!volume_status.dim_mute[i];
2158 mute = private->dim_mute[SCARLETT2_BUTTON_MUTE];
2160 for (i = 0; i < num_line_out; i++)
2161 if (private->vol_sw_hw_switch[i]) {
2162 private->vol[i] = private->master_vol;
2163 private->mute_switch[i] = mute;
2169 static int scarlett2_volume_ctl_info(struct snd_kcontrol *kctl,
2170 struct snd_ctl_elem_info *uinfo)
2172 struct usb_mixer_elem_info *elem = kctl->private_data;
2174 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2175 uinfo->count = elem->channels;
2176 uinfo->value.integer.min = 0;
2177 uinfo->value.integer.max = SCARLETT2_VOLUME_BIAS;
2178 uinfo->value.integer.step = 1;
2182 static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl,
2183 struct snd_ctl_elem_value *ucontrol)
2185 struct usb_mixer_elem_info *elem = kctl->private_data;
2186 struct usb_mixer_interface *mixer = elem->head.mixer;
2187 struct scarlett2_data *private = mixer->private_data;
2189 mutex_lock(&private->data_mutex);
2190 if (private->vol_updated)
2191 scarlett2_update_volumes(mixer);
2192 mutex_unlock(&private->data_mutex);
2194 ucontrol->value.integer.value[0] = private->master_vol;
2198 static int line_out_remap(struct scarlett2_data *private, int index)
2200 const struct scarlett2_device_info *info = private->info;
2201 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2202 int line_out_count =
2203 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
2205 if (!info->line_out_remap_enable)
2208 if (index >= line_out_count)
2211 return info->line_out_remap[index];
2214 static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl,
2215 struct snd_ctl_elem_value *ucontrol)
2217 struct usb_mixer_elem_info *elem = kctl->private_data;
2218 struct usb_mixer_interface *mixer = elem->head.mixer;
2219 struct scarlett2_data *private = mixer->private_data;
2220 int index = line_out_remap(private, elem->control);
2222 mutex_lock(&private->data_mutex);
2223 if (private->vol_updated)
2224 scarlett2_update_volumes(mixer);
2225 mutex_unlock(&private->data_mutex);
2227 ucontrol->value.integer.value[0] = private->vol[index];
2231 static int scarlett2_volume_ctl_put(struct snd_kcontrol *kctl,
2232 struct snd_ctl_elem_value *ucontrol)
2234 struct usb_mixer_elem_info *elem = kctl->private_data;
2235 struct usb_mixer_interface *mixer = elem->head.mixer;
2236 struct scarlett2_data *private = mixer->private_data;
2237 int index = line_out_remap(private, elem->control);
2238 int oval, val, err = 0;
2240 mutex_lock(&private->data_mutex);
2242 oval = private->vol[index];
2243 val = ucontrol->value.integer.value[0];
2248 private->vol[index] = val;
2249 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
2250 index, val - SCARLETT2_VOLUME_BIAS);
2255 mutex_unlock(&private->data_mutex);
2259 static const DECLARE_TLV_DB_MINMAX(
2260 db_scale_scarlett2_gain, -SCARLETT2_VOLUME_BIAS * 100, 0
2263 static const struct snd_kcontrol_new scarlett2_master_volume_ctl = {
2264 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2265 .access = SNDRV_CTL_ELEM_ACCESS_READ |
2266 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
2268 .info = scarlett2_volume_ctl_info,
2269 .get = scarlett2_master_volume_ctl_get,
2270 .private_value = 0, /* max value */
2271 .tlv = { .p = db_scale_scarlett2_gain }
2274 static const struct snd_kcontrol_new scarlett2_line_out_volume_ctl = {
2275 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2276 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2277 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
2279 .info = scarlett2_volume_ctl_info,
2280 .get = scarlett2_volume_ctl_get,
2281 .put = scarlett2_volume_ctl_put,
2282 .private_value = 0, /* max value */
2283 .tlv = { .p = db_scale_scarlett2_gain }
2286 /*** Mute Switch Controls ***/
2288 static int scarlett2_mute_ctl_get(struct snd_kcontrol *kctl,
2289 struct snd_ctl_elem_value *ucontrol)
2291 struct usb_mixer_elem_info *elem = kctl->private_data;
2292 struct usb_mixer_interface *mixer = elem->head.mixer;
2293 struct scarlett2_data *private = mixer->private_data;
2294 int index = line_out_remap(private, elem->control);
2296 mutex_lock(&private->data_mutex);
2297 if (private->vol_updated)
2298 scarlett2_update_volumes(mixer);
2299 mutex_unlock(&private->data_mutex);
2301 ucontrol->value.integer.value[0] = private->mute_switch[index];
2305 static int scarlett2_mute_ctl_put(struct snd_kcontrol *kctl,
2306 struct snd_ctl_elem_value *ucontrol)
2308 struct usb_mixer_elem_info *elem = kctl->private_data;
2309 struct usb_mixer_interface *mixer = elem->head.mixer;
2310 struct scarlett2_data *private = mixer->private_data;
2311 int index = line_out_remap(private, elem->control);
2312 int oval, val, err = 0;
2314 mutex_lock(&private->data_mutex);
2316 oval = private->mute_switch[index];
2317 val = !!ucontrol->value.integer.value[0];
2322 private->mute_switch[index] = val;
2324 /* Send mute change to the device */
2325 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
2331 mutex_unlock(&private->data_mutex);
2335 static const struct snd_kcontrol_new scarlett2_mute_ctl = {
2336 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2338 .info = snd_ctl_boolean_mono_info,
2339 .get = scarlett2_mute_ctl_get,
2340 .put = scarlett2_mute_ctl_put,
2343 /*** HW/SW Volume Switch Controls ***/
2345 static void scarlett2_sw_hw_ctl_ro(struct scarlett2_data *private, int index)
2347 private->sw_hw_ctls[index]->vd[0].access &=
2348 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
2351 static void scarlett2_sw_hw_ctl_rw(struct scarlett2_data *private, int index)
2353 private->sw_hw_ctls[index]->vd[0].access |=
2354 SNDRV_CTL_ELEM_ACCESS_WRITE;
2357 static int scarlett2_sw_hw_enum_ctl_info(struct snd_kcontrol *kctl,
2358 struct snd_ctl_elem_info *uinfo)
2360 static const char *const values[2] = {
2364 return snd_ctl_enum_info(uinfo, 1, 2, values);
2367 static int scarlett2_sw_hw_enum_ctl_get(struct snd_kcontrol *kctl,
2368 struct snd_ctl_elem_value *ucontrol)
2370 struct usb_mixer_elem_info *elem = kctl->private_data;
2371 struct scarlett2_data *private = elem->head.mixer->private_data;
2372 int index = line_out_remap(private, elem->control);
2374 ucontrol->value.enumerated.item[0] = private->vol_sw_hw_switch[index];
2378 static void scarlett2_vol_ctl_set_writable(struct usb_mixer_interface *mixer,
2379 int index, int value)
2381 struct scarlett2_data *private = mixer->private_data;
2382 struct snd_card *card = mixer->chip->card;
2384 /* Set/Clear write bits */
2386 private->vol_ctls[index]->vd[0].access |=
2387 SNDRV_CTL_ELEM_ACCESS_WRITE;
2388 private->mute_ctls[index]->vd[0].access |=
2389 SNDRV_CTL_ELEM_ACCESS_WRITE;
2391 private->vol_ctls[index]->vd[0].access &=
2392 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
2393 private->mute_ctls[index]->vd[0].access &=
2394 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
2397 /* Notify of write bit and possible value change */
2398 snd_ctl_notify(card,
2399 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
2400 &private->vol_ctls[index]->id);
2401 snd_ctl_notify(card,
2402 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
2403 &private->mute_ctls[index]->id);
2406 static int scarlett2_sw_hw_change(struct usb_mixer_interface *mixer,
2407 int ctl_index, int val)
2409 struct scarlett2_data *private = mixer->private_data;
2410 int index = line_out_remap(private, ctl_index);
2413 private->vol_sw_hw_switch[index] = val;
2415 /* Change access mode to RO (hardware controlled volume)
2416 * or RW (software controlled volume)
2418 scarlett2_vol_ctl_set_writable(mixer, ctl_index, !val);
2420 /* Reset volume/mute to master volume/mute */
2421 private->vol[index] = private->master_vol;
2422 private->mute_switch[index] = private->dim_mute[SCARLETT2_BUTTON_MUTE];
2424 /* Set SW volume to current HW volume */
2425 err = scarlett2_usb_set_config(
2426 mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
2427 index, private->master_vol - SCARLETT2_VOLUME_BIAS);
2431 /* Set SW mute to current HW mute */
2432 err = scarlett2_usb_set_config(
2433 mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
2434 index, private->dim_mute[SCARLETT2_BUTTON_MUTE]);
2438 /* Send SW/HW switch change to the device */
2439 return scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
2443 static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl,
2444 struct snd_ctl_elem_value *ucontrol)
2446 struct usb_mixer_elem_info *elem = kctl->private_data;
2447 struct usb_mixer_interface *mixer = elem->head.mixer;
2448 struct scarlett2_data *private = mixer->private_data;
2449 int ctl_index = elem->control;
2450 int index = line_out_remap(private, ctl_index);
2451 int oval, val, err = 0;
2453 mutex_lock(&private->data_mutex);
2455 oval = private->vol_sw_hw_switch[index];
2456 val = !!ucontrol->value.enumerated.item[0];
2461 err = scarlett2_sw_hw_change(mixer, ctl_index, val);
2466 mutex_unlock(&private->data_mutex);
2470 static const struct snd_kcontrol_new scarlett2_sw_hw_enum_ctl = {
2471 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2473 .info = scarlett2_sw_hw_enum_ctl_info,
2474 .get = scarlett2_sw_hw_enum_ctl_get,
2475 .put = scarlett2_sw_hw_enum_ctl_put,
2478 /*** Line Level/Instrument Level Switch Controls ***/
2480 static int scarlett2_update_input_other(struct usb_mixer_interface *mixer)
2482 struct scarlett2_data *private = mixer->private_data;
2483 const struct scarlett2_device_info *info = private->info;
2485 private->input_other_updated = 0;
2487 if (info->level_input_count) {
2488 int err = scarlett2_usb_get_config(
2489 mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
2490 info->level_input_count + info->level_input_first,
2491 private->level_switch);
2496 if (info->pad_input_count) {
2497 int err = scarlett2_usb_get_config(
2498 mixer, SCARLETT2_CONFIG_PAD_SWITCH,
2499 info->pad_input_count, private->pad_switch);
2504 if (info->air_input_count) {
2505 int err = scarlett2_usb_get_config(
2506 mixer, SCARLETT2_CONFIG_AIR_SWITCH,
2507 info->air_input_count, private->air_switch);
2512 if (info->phantom_count) {
2513 int err = scarlett2_usb_get_config(
2514 mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
2515 info->phantom_count, private->phantom_switch);
2519 err = scarlett2_usb_get_config(
2520 mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
2521 1, &private->phantom_persistence);
2529 static int scarlett2_level_enum_ctl_info(struct snd_kcontrol *kctl,
2530 struct snd_ctl_elem_info *uinfo)
2532 static const char *const values[2] = {
2536 return snd_ctl_enum_info(uinfo, 1, 2, values);
2539 static int scarlett2_level_enum_ctl_get(struct snd_kcontrol *kctl,
2540 struct snd_ctl_elem_value *ucontrol)
2542 struct usb_mixer_elem_info *elem = kctl->private_data;
2543 struct usb_mixer_interface *mixer = elem->head.mixer;
2544 struct scarlett2_data *private = mixer->private_data;
2545 const struct scarlett2_device_info *info = private->info;
2547 int index = elem->control + info->level_input_first;
2549 mutex_lock(&private->data_mutex);
2550 if (private->input_other_updated)
2551 scarlett2_update_input_other(mixer);
2552 ucontrol->value.enumerated.item[0] = private->level_switch[index];
2553 mutex_unlock(&private->data_mutex);
2558 static int scarlett2_level_enum_ctl_put(struct snd_kcontrol *kctl,
2559 struct snd_ctl_elem_value *ucontrol)
2561 struct usb_mixer_elem_info *elem = kctl->private_data;
2562 struct usb_mixer_interface *mixer = elem->head.mixer;
2563 struct scarlett2_data *private = mixer->private_data;
2564 const struct scarlett2_device_info *info = private->info;
2566 int index = elem->control + info->level_input_first;
2567 int oval, val, err = 0;
2569 mutex_lock(&private->data_mutex);
2571 oval = private->level_switch[index];
2572 val = !!ucontrol->value.enumerated.item[0];
2577 private->level_switch[index] = val;
2579 /* Send switch change to the device */
2580 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
2586 mutex_unlock(&private->data_mutex);
2590 static const struct snd_kcontrol_new scarlett2_level_enum_ctl = {
2591 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2593 .info = scarlett2_level_enum_ctl_info,
2594 .get = scarlett2_level_enum_ctl_get,
2595 .put = scarlett2_level_enum_ctl_put,
2598 /*** Pad Switch Controls ***/
2600 static int scarlett2_pad_ctl_get(struct snd_kcontrol *kctl,
2601 struct snd_ctl_elem_value *ucontrol)
2603 struct usb_mixer_elem_info *elem = kctl->private_data;
2604 struct usb_mixer_interface *mixer = elem->head.mixer;
2605 struct scarlett2_data *private = mixer->private_data;
2607 mutex_lock(&private->data_mutex);
2608 if (private->input_other_updated)
2609 scarlett2_update_input_other(mixer);
2610 ucontrol->value.integer.value[0] =
2611 private->pad_switch[elem->control];
2612 mutex_unlock(&private->data_mutex);
2617 static int scarlett2_pad_ctl_put(struct snd_kcontrol *kctl,
2618 struct snd_ctl_elem_value *ucontrol)
2620 struct usb_mixer_elem_info *elem = kctl->private_data;
2621 struct usb_mixer_interface *mixer = elem->head.mixer;
2622 struct scarlett2_data *private = mixer->private_data;
2624 int index = elem->control;
2625 int oval, val, err = 0;
2627 mutex_lock(&private->data_mutex);
2629 oval = private->pad_switch[index];
2630 val = !!ucontrol->value.integer.value[0];
2635 private->pad_switch[index] = val;
2637 /* Send switch change to the device */
2638 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PAD_SWITCH,
2644 mutex_unlock(&private->data_mutex);
2648 static const struct snd_kcontrol_new scarlett2_pad_ctl = {
2649 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2651 .info = snd_ctl_boolean_mono_info,
2652 .get = scarlett2_pad_ctl_get,
2653 .put = scarlett2_pad_ctl_put,
2656 /*** Air Switch Controls ***/
2658 static int scarlett2_air_ctl_get(struct snd_kcontrol *kctl,
2659 struct snd_ctl_elem_value *ucontrol)
2661 struct usb_mixer_elem_info *elem = kctl->private_data;
2662 struct usb_mixer_interface *mixer = elem->head.mixer;
2663 struct scarlett2_data *private = mixer->private_data;
2665 mutex_lock(&private->data_mutex);
2666 if (private->input_other_updated)
2667 scarlett2_update_input_other(mixer);
2668 ucontrol->value.integer.value[0] = private->air_switch[elem->control];
2669 mutex_unlock(&private->data_mutex);
2674 static int scarlett2_air_ctl_put(struct snd_kcontrol *kctl,
2675 struct snd_ctl_elem_value *ucontrol)
2677 struct usb_mixer_elem_info *elem = kctl->private_data;
2678 struct usb_mixer_interface *mixer = elem->head.mixer;
2679 struct scarlett2_data *private = mixer->private_data;
2681 int index = elem->control;
2682 int oval, val, err = 0;
2684 mutex_lock(&private->data_mutex);
2686 oval = private->air_switch[index];
2687 val = !!ucontrol->value.integer.value[0];
2692 private->air_switch[index] = val;
2694 /* Send switch change to the device */
2695 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_AIR_SWITCH,
2701 mutex_unlock(&private->data_mutex);
2705 static const struct snd_kcontrol_new scarlett2_air_ctl = {
2706 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2708 .info = snd_ctl_boolean_mono_info,
2709 .get = scarlett2_air_ctl_get,
2710 .put = scarlett2_air_ctl_put,
2713 /*** Phantom Switch Controls ***/
2715 static int scarlett2_phantom_ctl_get(struct snd_kcontrol *kctl,
2716 struct snd_ctl_elem_value *ucontrol)
2718 struct usb_mixer_elem_info *elem = kctl->private_data;
2719 struct usb_mixer_interface *mixer = elem->head.mixer;
2720 struct scarlett2_data *private = mixer->private_data;
2722 mutex_lock(&private->data_mutex);
2723 if (private->input_other_updated)
2724 scarlett2_update_input_other(mixer);
2725 ucontrol->value.integer.value[0] =
2726 private->phantom_switch[elem->control];
2727 mutex_unlock(&private->data_mutex);
2732 static int scarlett2_phantom_ctl_put(struct snd_kcontrol *kctl,
2733 struct snd_ctl_elem_value *ucontrol)
2735 struct usb_mixer_elem_info *elem = kctl->private_data;
2736 struct usb_mixer_interface *mixer = elem->head.mixer;
2737 struct scarlett2_data *private = mixer->private_data;
2739 int index = elem->control;
2740 int oval, val, err = 0;
2742 mutex_lock(&private->data_mutex);
2744 oval = private->phantom_switch[index];
2745 val = !!ucontrol->value.integer.value[0];
2750 private->phantom_switch[index] = val;
2752 /* Send switch change to the device */
2753 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
2759 mutex_unlock(&private->data_mutex);
2763 static const struct snd_kcontrol_new scarlett2_phantom_ctl = {
2764 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2766 .info = snd_ctl_boolean_mono_info,
2767 .get = scarlett2_phantom_ctl_get,
2768 .put = scarlett2_phantom_ctl_put,
2771 /*** Phantom Persistence Control ***/
2773 static int scarlett2_phantom_persistence_ctl_get(
2774 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2776 struct usb_mixer_elem_info *elem = kctl->private_data;
2777 struct scarlett2_data *private = elem->head.mixer->private_data;
2779 ucontrol->value.integer.value[0] = private->phantom_persistence;
2783 static int scarlett2_phantom_persistence_ctl_put(
2784 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2786 struct usb_mixer_elem_info *elem = kctl->private_data;
2787 struct usb_mixer_interface *mixer = elem->head.mixer;
2788 struct scarlett2_data *private = mixer->private_data;
2790 int index = elem->control;
2791 int oval, val, err = 0;
2793 mutex_lock(&private->data_mutex);
2795 oval = private->phantom_persistence;
2796 val = !!ucontrol->value.integer.value[0];
2801 private->phantom_persistence = val;
2803 /* Send switch change to the device */
2804 err = scarlett2_usb_set_config(
2805 mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE, index, val);
2810 mutex_unlock(&private->data_mutex);
2814 static const struct snd_kcontrol_new scarlett2_phantom_persistence_ctl = {
2815 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2817 .info = snd_ctl_boolean_mono_info,
2818 .get = scarlett2_phantom_persistence_ctl_get,
2819 .put = scarlett2_phantom_persistence_ctl_put,
2822 /*** Direct Monitor Control ***/
2824 static int scarlett2_update_monitor_other(struct usb_mixer_interface *mixer)
2826 struct scarlett2_data *private = mixer->private_data;
2827 const struct scarlett2_device_info *info = private->info;
2830 /* monitor_other_enable[0] enables speaker switching
2831 * monitor_other_enable[1] enables talkback
2833 u8 monitor_other_enable[2];
2835 /* monitor_other_switch[0] activates the alternate speakers
2836 * monitor_other_switch[1] activates talkback
2838 u8 monitor_other_switch[2];
2840 private->monitor_other_updated = 0;
2842 if (info->direct_monitor)
2843 return scarlett2_usb_get_config(
2844 mixer, SCARLETT2_CONFIG_DIRECT_MONITOR,
2845 1, &private->direct_monitor_switch);
2847 /* if it doesn't do speaker switching then it also doesn't do
2850 if (!info->has_speaker_switching)
2853 err = scarlett2_usb_get_config(
2854 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
2855 2, monitor_other_enable);
2859 err = scarlett2_usb_get_config(
2860 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
2861 2, monitor_other_switch);
2865 if (!monitor_other_enable[0])
2866 private->speaker_switching_switch = 0;
2868 private->speaker_switching_switch = monitor_other_switch[0] + 1;
2870 if (info->has_talkback) {
2871 const int (*port_count)[SCARLETT2_PORT_DIRNS] =
2874 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
2878 if (!monitor_other_enable[1])
2879 private->talkback_switch = 0;
2881 private->talkback_switch = monitor_other_switch[1] + 1;
2883 err = scarlett2_usb_get_config(mixer,
2884 SCARLETT2_CONFIG_TALKBACK_MAP,
2888 for (i = 0; i < num_mixes; i++, bitmap >>= 1)
2889 private->talkback_map[i] = bitmap & 1;
2895 static int scarlett2_direct_monitor_ctl_get(
2896 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2898 struct usb_mixer_elem_info *elem = kctl->private_data;
2899 struct usb_mixer_interface *mixer = elem->head.mixer;
2900 struct scarlett2_data *private = elem->head.mixer->private_data;
2902 mutex_lock(&private->data_mutex);
2903 if (private->monitor_other_updated)
2904 scarlett2_update_monitor_other(mixer);
2905 ucontrol->value.enumerated.item[0] = private->direct_monitor_switch;
2906 mutex_unlock(&private->data_mutex);
2911 static int scarlett2_direct_monitor_ctl_put(
2912 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2914 struct usb_mixer_elem_info *elem = kctl->private_data;
2915 struct usb_mixer_interface *mixer = elem->head.mixer;
2916 struct scarlett2_data *private = mixer->private_data;
2918 int index = elem->control;
2919 int oval, val, err = 0;
2921 mutex_lock(&private->data_mutex);
2923 oval = private->direct_monitor_switch;
2924 val = min(ucontrol->value.enumerated.item[0], 2U);
2929 private->direct_monitor_switch = val;
2931 /* Send switch change to the device */
2932 err = scarlett2_usb_set_config(
2933 mixer, SCARLETT2_CONFIG_DIRECT_MONITOR, index, val);
2938 mutex_unlock(&private->data_mutex);
2942 static int scarlett2_direct_monitor_stereo_enum_ctl_info(
2943 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
2945 static const char *const values[3] = {
2946 "Off", "Mono", "Stereo"
2949 return snd_ctl_enum_info(uinfo, 1, 3, values);
2952 /* Direct Monitor for Solo is mono-only and only needs a boolean control
2953 * Direct Monitor for 2i2 is selectable between Off/Mono/Stereo
2955 static const struct snd_kcontrol_new scarlett2_direct_monitor_ctl[2] = {
2957 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2959 .info = snd_ctl_boolean_mono_info,
2960 .get = scarlett2_direct_monitor_ctl_get,
2961 .put = scarlett2_direct_monitor_ctl_put,
2964 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2966 .info = scarlett2_direct_monitor_stereo_enum_ctl_info,
2967 .get = scarlett2_direct_monitor_ctl_get,
2968 .put = scarlett2_direct_monitor_ctl_put,
2972 static int scarlett2_add_direct_monitor_ctl(struct usb_mixer_interface *mixer)
2974 struct scarlett2_data *private = mixer->private_data;
2975 const struct scarlett2_device_info *info = private->info;
2978 if (!info->direct_monitor)
2981 s = info->direct_monitor == 1
2982 ? "Direct Monitor Playback Switch"
2983 : "Direct Monitor Playback Enum";
2985 return scarlett2_add_new_ctl(
2986 mixer, &scarlett2_direct_monitor_ctl[info->direct_monitor - 1],
2987 0, 1, s, &private->direct_monitor_ctl);
2990 /*** Speaker Switching Control ***/
2992 static int scarlett2_speaker_switch_enum_ctl_info(
2993 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
2995 static const char *const values[3] = {
2996 "Off", "Main", "Alt"
2999 return snd_ctl_enum_info(uinfo, 1, 3, values);
3002 static int scarlett2_speaker_switch_enum_ctl_get(
3003 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3005 struct usb_mixer_elem_info *elem = kctl->private_data;
3006 struct usb_mixer_interface *mixer = elem->head.mixer;
3007 struct scarlett2_data *private = mixer->private_data;
3009 mutex_lock(&private->data_mutex);
3010 if (private->monitor_other_updated)
3011 scarlett2_update_monitor_other(mixer);
3012 ucontrol->value.enumerated.item[0] = private->speaker_switching_switch;
3013 mutex_unlock(&private->data_mutex);
3018 /* when speaker switching gets enabled, switch the main/alt speakers
3019 * to HW volume and disable those controls
3021 static int scarlett2_speaker_switch_enable(struct usb_mixer_interface *mixer)
3023 struct snd_card *card = mixer->chip->card;
3024 struct scarlett2_data *private = mixer->private_data;
3027 for (i = 0; i < 4; i++) {
3028 int index = line_out_remap(private, i);
3030 /* switch the main/alt speakers to HW volume */
3031 if (!private->vol_sw_hw_switch[index]) {
3032 err = scarlett2_sw_hw_change(private->mixer, i, 1);
3037 /* disable the line out SW/HW switch */
3038 scarlett2_sw_hw_ctl_ro(private, i);
3039 snd_ctl_notify(card,
3040 SNDRV_CTL_EVENT_MASK_VALUE |
3041 SNDRV_CTL_EVENT_MASK_INFO,
3042 &private->sw_hw_ctls[i]->id);
3045 /* when the next monitor-other notify comes in, update the mux
3048 private->speaker_switching_switched = 1;
3053 /* when speaker switching gets disabled, reenable the hw/sw controls
3054 * and invalidate the routing
3056 static void scarlett2_speaker_switch_disable(struct usb_mixer_interface *mixer)
3058 struct snd_card *card = mixer->chip->card;
3059 struct scarlett2_data *private = mixer->private_data;
3062 /* enable the line out SW/HW switch */
3063 for (i = 0; i < 4; i++) {
3064 scarlett2_sw_hw_ctl_rw(private, i);
3065 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
3066 &private->sw_hw_ctls[i]->id);
3069 /* when the next monitor-other notify comes in, update the mux
3072 private->speaker_switching_switched = 1;
3075 static int scarlett2_speaker_switch_enum_ctl_put(
3076 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3078 struct usb_mixer_elem_info *elem = kctl->private_data;
3079 struct usb_mixer_interface *mixer = elem->head.mixer;
3080 struct scarlett2_data *private = mixer->private_data;
3082 int oval, val, err = 0;
3084 mutex_lock(&private->data_mutex);
3086 oval = private->speaker_switching_switch;
3087 val = min(ucontrol->value.enumerated.item[0], 2U);
3092 private->speaker_switching_switch = val;
3094 /* enable/disable speaker switching */
3095 err = scarlett2_usb_set_config(
3096 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
3101 /* if speaker switching is enabled, select main or alt */
3102 err = scarlett2_usb_set_config(
3103 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
3108 /* update controls if speaker switching gets enabled or disabled */
3110 err = scarlett2_speaker_switch_enable(mixer);
3111 else if (oval && !val)
3112 scarlett2_speaker_switch_disable(mixer);
3118 mutex_unlock(&private->data_mutex);
3122 static const struct snd_kcontrol_new scarlett2_speaker_switch_enum_ctl = {
3123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3125 .info = scarlett2_speaker_switch_enum_ctl_info,
3126 .get = scarlett2_speaker_switch_enum_ctl_get,
3127 .put = scarlett2_speaker_switch_enum_ctl_put,
3130 static int scarlett2_add_speaker_switch_ctl(
3131 struct usb_mixer_interface *mixer)
3133 struct scarlett2_data *private = mixer->private_data;
3134 const struct scarlett2_device_info *info = private->info;
3136 if (!info->has_speaker_switching)
3139 return scarlett2_add_new_ctl(
3140 mixer, &scarlett2_speaker_switch_enum_ctl,
3141 0, 1, "Speaker Switching Playback Enum",
3142 &private->speaker_switching_ctl);
3145 /*** Talkback and Talkback Map Controls ***/
3147 static int scarlett2_talkback_enum_ctl_info(
3148 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
3150 static const char *const values[3] = {
3151 "Disabled", "Off", "On"
3154 return snd_ctl_enum_info(uinfo, 1, 3, values);
3157 static int scarlett2_talkback_enum_ctl_get(
3158 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3160 struct usb_mixer_elem_info *elem = kctl->private_data;
3161 struct usb_mixer_interface *mixer = elem->head.mixer;
3162 struct scarlett2_data *private = mixer->private_data;
3164 mutex_lock(&private->data_mutex);
3165 if (private->monitor_other_updated)
3166 scarlett2_update_monitor_other(mixer);
3167 ucontrol->value.enumerated.item[0] = private->talkback_switch;
3168 mutex_unlock(&private->data_mutex);
3173 static int scarlett2_talkback_enum_ctl_put(
3174 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3176 struct usb_mixer_elem_info *elem = kctl->private_data;
3177 struct usb_mixer_interface *mixer = elem->head.mixer;
3178 struct scarlett2_data *private = mixer->private_data;
3180 int oval, val, err = 0;
3182 mutex_lock(&private->data_mutex);
3184 oval = private->talkback_switch;
3185 val = min(ucontrol->value.enumerated.item[0], 2U);
3190 private->talkback_switch = val;
3192 /* enable/disable talkback */
3193 err = scarlett2_usb_set_config(
3194 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
3199 /* if talkback is enabled, select main or alt */
3200 err = scarlett2_usb_set_config(
3201 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
3207 mutex_unlock(&private->data_mutex);
3211 static const struct snd_kcontrol_new scarlett2_talkback_enum_ctl = {
3212 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3214 .info = scarlett2_talkback_enum_ctl_info,
3215 .get = scarlett2_talkback_enum_ctl_get,
3216 .put = scarlett2_talkback_enum_ctl_put,
3219 static int scarlett2_talkback_map_ctl_get(
3220 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3222 struct usb_mixer_elem_info *elem = kctl->private_data;
3223 struct usb_mixer_interface *mixer = elem->head.mixer;
3224 struct scarlett2_data *private = mixer->private_data;
3225 int index = elem->control;
3227 ucontrol->value.integer.value[0] = private->talkback_map[index];
3232 static int scarlett2_talkback_map_ctl_put(
3233 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3235 struct usb_mixer_elem_info *elem = kctl->private_data;
3236 struct usb_mixer_interface *mixer = elem->head.mixer;
3237 struct scarlett2_data *private = mixer->private_data;
3238 const int (*port_count)[SCARLETT2_PORT_DIRNS] =
3239 private->info->port_count;
3240 int num_mixes = port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
3242 int index = elem->control;
3243 int oval, val, err = 0, i;
3246 mutex_lock(&private->data_mutex);
3248 oval = private->talkback_map[index];
3249 val = !!ucontrol->value.integer.value[0];
3254 private->talkback_map[index] = val;
3256 for (i = 0; i < num_mixes; i++)
3257 bitmap |= private->talkback_map[i] << i;
3259 /* Send updated bitmap to the device */
3260 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_TALKBACK_MAP,
3266 mutex_unlock(&private->data_mutex);
3270 static const struct snd_kcontrol_new scarlett2_talkback_map_ctl = {
3271 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3273 .info = snd_ctl_boolean_mono_info,
3274 .get = scarlett2_talkback_map_ctl_get,
3275 .put = scarlett2_talkback_map_ctl_put,
3278 static int scarlett2_add_talkback_ctls(
3279 struct usb_mixer_interface *mixer)
3281 struct scarlett2_data *private = mixer->private_data;
3282 const struct scarlett2_device_info *info = private->info;
3283 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3284 int num_mixes = port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
3286 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3288 if (!info->has_talkback)
3291 err = scarlett2_add_new_ctl(
3292 mixer, &scarlett2_talkback_enum_ctl,
3293 0, 1, "Talkback Playback Enum",
3294 &private->talkback_ctl);
3298 for (i = 0; i < num_mixes; i++) {
3299 snprintf(s, sizeof(s),
3300 "Talkback Mix %c Playback Switch", i + 'A');
3301 err = scarlett2_add_new_ctl(mixer, &scarlett2_talkback_map_ctl,
3310 /*** Dim/Mute Controls ***/
3312 static int scarlett2_dim_mute_ctl_get(struct snd_kcontrol *kctl,
3313 struct snd_ctl_elem_value *ucontrol)
3315 struct usb_mixer_elem_info *elem = kctl->private_data;
3316 struct usb_mixer_interface *mixer = elem->head.mixer;
3317 struct scarlett2_data *private = mixer->private_data;
3319 mutex_lock(&private->data_mutex);
3320 if (private->vol_updated)
3321 scarlett2_update_volumes(mixer);
3322 mutex_unlock(&private->data_mutex);
3324 ucontrol->value.integer.value[0] = private->dim_mute[elem->control];
3328 static int scarlett2_dim_mute_ctl_put(struct snd_kcontrol *kctl,
3329 struct snd_ctl_elem_value *ucontrol)
3331 struct usb_mixer_elem_info *elem = kctl->private_data;
3332 struct usb_mixer_interface *mixer = elem->head.mixer;
3333 struct scarlett2_data *private = mixer->private_data;
3334 const struct scarlett2_device_info *info = private->info;
3335 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3337 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
3339 int index = elem->control;
3340 int oval, val, err = 0, i;
3342 mutex_lock(&private->data_mutex);
3344 oval = private->dim_mute[index];
3345 val = !!ucontrol->value.integer.value[0];
3350 private->dim_mute[index] = val;
3352 /* Send switch change to the device */
3353 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_DIM_MUTE,
3358 if (index == SCARLETT2_BUTTON_MUTE)
3359 for (i = 0; i < num_line_out; i++) {
3360 int line_index = line_out_remap(private, i);
3362 if (private->vol_sw_hw_switch[line_index]) {
3363 private->mute_switch[line_index] = val;
3364 snd_ctl_notify(mixer->chip->card,
3365 SNDRV_CTL_EVENT_MASK_VALUE,
3366 &private->mute_ctls[i]->id);
3371 mutex_unlock(&private->data_mutex);
3375 static const struct snd_kcontrol_new scarlett2_dim_mute_ctl = {
3376 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3378 .info = snd_ctl_boolean_mono_info,
3379 .get = scarlett2_dim_mute_ctl_get,
3380 .put = scarlett2_dim_mute_ctl_put
3383 /*** Create the analogue output controls ***/
3385 static int scarlett2_add_line_out_ctls(struct usb_mixer_interface *mixer)
3387 struct scarlett2_data *private = mixer->private_data;
3388 const struct scarlett2_device_info *info = private->info;
3389 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3391 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
3393 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3395 /* Add R/O HW volume control */
3396 if (info->line_out_hw_vol) {
3397 snprintf(s, sizeof(s), "Master HW Playback Volume");
3398 err = scarlett2_add_new_ctl(mixer,
3399 &scarlett2_master_volume_ctl,
3400 0, 1, s, &private->master_vol_ctl);
3405 /* Add volume controls */
3406 for (i = 0; i < num_line_out; i++) {
3407 int index = line_out_remap(private, i);
3410 if (info->line_out_descrs[i])
3411 snprintf(s, sizeof(s),
3412 "Line %02d (%s) Playback Volume",
3413 i + 1, info->line_out_descrs[i]);
3415 snprintf(s, sizeof(s),
3416 "Line %02d Playback Volume",
3418 err = scarlett2_add_new_ctl(mixer,
3419 &scarlett2_line_out_volume_ctl,
3420 i, 1, s, &private->vol_ctls[i]);
3425 snprintf(s, sizeof(s),
3426 "Line %02d Mute Playback Switch",
3428 err = scarlett2_add_new_ctl(mixer,
3429 &scarlett2_mute_ctl,
3431 &private->mute_ctls[i]);
3435 /* Make the fader and mute controls read-only if the
3436 * SW/HW switch is set to HW
3438 if (private->vol_sw_hw_switch[index])
3439 scarlett2_vol_ctl_set_writable(mixer, i, 0);
3442 if (info->line_out_hw_vol) {
3443 snprintf(s, sizeof(s),
3444 "Line Out %02d Volume Control Playback Enum",
3446 err = scarlett2_add_new_ctl(mixer,
3447 &scarlett2_sw_hw_enum_ctl,
3449 &private->sw_hw_ctls[i]);
3453 /* Make the switch read-only if the line is
3454 * involved in speaker switching
3456 if (private->speaker_switching_switch && i < 4)
3457 scarlett2_sw_hw_ctl_ro(private, i);
3461 /* Add dim/mute controls */
3462 if (info->line_out_hw_vol)
3463 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++) {
3464 err = scarlett2_add_new_ctl(
3465 mixer, &scarlett2_dim_mute_ctl,
3466 i, 1, scarlett2_dim_mute_names[i],
3467 &private->dim_mute_ctls[i]);
3475 /*** Create the analogue input controls ***/
3477 static int scarlett2_add_line_in_ctls(struct usb_mixer_interface *mixer)
3479 struct scarlett2_data *private = mixer->private_data;
3480 const struct scarlett2_device_info *info = private->info;
3482 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3483 const char *fmt = "Line In %d %s Capture %s";
3484 const char *fmt2 = "Line In %d-%d %s Capture %s";
3486 /* Add input level (line/inst) controls */
3487 for (i = 0; i < info->level_input_count; i++) {
3488 snprintf(s, sizeof(s), fmt, i + 1 + info->level_input_first,
3490 err = scarlett2_add_new_ctl(mixer, &scarlett2_level_enum_ctl,
3491 i, 1, s, &private->level_ctls[i]);
3496 /* Add input pad controls */
3497 for (i = 0; i < info->pad_input_count; i++) {
3498 snprintf(s, sizeof(s), fmt, i + 1, "Pad", "Switch");
3499 err = scarlett2_add_new_ctl(mixer, &scarlett2_pad_ctl,
3500 i, 1, s, &private->pad_ctls[i]);
3505 /* Add input air controls */
3506 for (i = 0; i < info->air_input_count; i++) {
3507 snprintf(s, sizeof(s), fmt, i + 1, "Air", "Switch");
3508 err = scarlett2_add_new_ctl(mixer, &scarlett2_air_ctl,
3509 i, 1, s, &private->air_ctls[i]);
3514 /* Add input phantom controls */
3515 if (info->inputs_per_phantom == 1) {
3516 for (i = 0; i < info->phantom_count; i++) {
3517 scnprintf(s, sizeof(s), fmt, i + 1,
3518 "Phantom Power", "Switch");
3519 err = scarlett2_add_new_ctl(
3520 mixer, &scarlett2_phantom_ctl,
3521 i, 1, s, &private->phantom_ctls[i]);
3525 } else if (info->inputs_per_phantom > 1) {
3526 for (i = 0; i < info->phantom_count; i++) {
3527 int from = i * info->inputs_per_phantom + 1;
3528 int to = (i + 1) * info->inputs_per_phantom;
3530 scnprintf(s, sizeof(s), fmt2, from, to,
3531 "Phantom Power", "Switch");
3532 err = scarlett2_add_new_ctl(
3533 mixer, &scarlett2_phantom_ctl,
3534 i, 1, s, &private->phantom_ctls[i]);
3539 if (info->phantom_count) {
3540 err = scarlett2_add_new_ctl(
3541 mixer, &scarlett2_phantom_persistence_ctl, 0, 1,
3542 "Phantom Power Persistence Capture Switch", NULL);
3550 /*** Mixer Volume Controls ***/
3552 static int scarlett2_mixer_ctl_info(struct snd_kcontrol *kctl,
3553 struct snd_ctl_elem_info *uinfo)
3555 struct usb_mixer_elem_info *elem = kctl->private_data;
3557 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3558 uinfo->count = elem->channels;
3559 uinfo->value.integer.min = 0;
3560 uinfo->value.integer.max = SCARLETT2_MIXER_MAX_VALUE;
3561 uinfo->value.integer.step = 1;
3565 static int scarlett2_mixer_ctl_get(struct snd_kcontrol *kctl,
3566 struct snd_ctl_elem_value *ucontrol)
3568 struct usb_mixer_elem_info *elem = kctl->private_data;
3569 struct scarlett2_data *private = elem->head.mixer->private_data;
3571 ucontrol->value.integer.value[0] = private->mix[elem->control];
3575 static int scarlett2_mixer_ctl_put(struct snd_kcontrol *kctl,
3576 struct snd_ctl_elem_value *ucontrol)
3578 struct usb_mixer_elem_info *elem = kctl->private_data;
3579 struct usb_mixer_interface *mixer = elem->head.mixer;
3580 struct scarlett2_data *private = mixer->private_data;
3581 const struct scarlett2_device_info *info = private->info;
3582 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3583 int oval, val, num_mixer_in, mix_num, err = 0;
3584 int index = elem->control;
3586 mutex_lock(&private->data_mutex);
3588 oval = private->mix[index];
3589 val = ucontrol->value.integer.value[0];
3590 num_mixer_in = port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
3591 mix_num = index / num_mixer_in;
3596 private->mix[index] = val;
3597 err = scarlett2_usb_set_mix(mixer, mix_num);
3602 mutex_unlock(&private->data_mutex);
3606 static const DECLARE_TLV_DB_MINMAX(
3607 db_scale_scarlett2_mixer,
3608 SCARLETT2_MIXER_MIN_DB * 100,
3609 SCARLETT2_MIXER_MAX_DB * 100
3612 static const struct snd_kcontrol_new scarlett2_mixer_ctl = {
3613 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3614 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3615 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
3617 .info = scarlett2_mixer_ctl_info,
3618 .get = scarlett2_mixer_ctl_get,
3619 .put = scarlett2_mixer_ctl_put,
3620 .private_value = SCARLETT2_MIXER_MAX_DB, /* max value */
3621 .tlv = { .p = db_scale_scarlett2_mixer }
3624 static int scarlett2_add_mixer_ctls(struct usb_mixer_interface *mixer)
3626 struct scarlett2_data *private = mixer->private_data;
3627 const struct scarlett2_device_info *info = private->info;
3628 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3631 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3634 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
3636 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
3638 for (i = 0, index = 0; i < num_outputs; i++)
3639 for (j = 0; j < num_inputs; j++, index++) {
3640 snprintf(s, sizeof(s),
3641 "Mix %c Input %02d Playback Volume",
3643 err = scarlett2_add_new_ctl(mixer, &scarlett2_mixer_ctl,
3652 /*** Mux Source Selection Controls ***/
3654 static int scarlett2_mux_src_enum_ctl_info(struct snd_kcontrol *kctl,
3655 struct snd_ctl_elem_info *uinfo)
3657 struct usb_mixer_elem_info *elem = kctl->private_data;
3658 struct scarlett2_data *private = elem->head.mixer->private_data;
3659 const struct scarlett2_device_info *info = private->info;
3660 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3661 unsigned int item = uinfo->value.enumerated.item;
3662 int items = private->num_mux_srcs;
3665 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3666 uinfo->count = elem->channels;
3667 uinfo->value.enumerated.items = items;
3670 item = uinfo->value.enumerated.item = items - 1;
3673 port_type < SCARLETT2_PORT_TYPE_COUNT;
3675 if (item < port_count[port_type][SCARLETT2_PORT_IN]) {
3676 const struct scarlett2_port *port =
3677 &scarlett2_ports[port_type];
3679 sprintf(uinfo->value.enumerated.name,
3680 port->src_descr, item + port->src_num_offset);
3683 item -= port_count[port_type][SCARLETT2_PORT_IN];
3689 static int scarlett2_mux_src_enum_ctl_get(struct snd_kcontrol *kctl,
3690 struct snd_ctl_elem_value *ucontrol)
3692 struct usb_mixer_elem_info *elem = kctl->private_data;
3693 struct usb_mixer_interface *mixer = elem->head.mixer;
3694 struct scarlett2_data *private = mixer->private_data;
3695 int index = line_out_remap(private, elem->control);
3697 mutex_lock(&private->data_mutex);
3698 if (private->mux_updated)
3699 scarlett2_usb_get_mux(mixer);
3700 ucontrol->value.enumerated.item[0] = private->mux[index];
3701 mutex_unlock(&private->data_mutex);
3706 static int scarlett2_mux_src_enum_ctl_put(struct snd_kcontrol *kctl,
3707 struct snd_ctl_elem_value *ucontrol)
3709 struct usb_mixer_elem_info *elem = kctl->private_data;
3710 struct usb_mixer_interface *mixer = elem->head.mixer;
3711 struct scarlett2_data *private = mixer->private_data;
3712 int index = line_out_remap(private, elem->control);
3713 int oval, val, err = 0;
3715 mutex_lock(&private->data_mutex);
3717 oval = private->mux[index];
3718 val = min(ucontrol->value.enumerated.item[0],
3719 private->num_mux_srcs - 1U);
3724 private->mux[index] = val;
3725 err = scarlett2_usb_set_mux(mixer);
3730 mutex_unlock(&private->data_mutex);
3734 static const struct snd_kcontrol_new scarlett2_mux_src_enum_ctl = {
3735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3737 .info = scarlett2_mux_src_enum_ctl_info,
3738 .get = scarlett2_mux_src_enum_ctl_get,
3739 .put = scarlett2_mux_src_enum_ctl_put,
3742 static int scarlett2_add_mux_enums(struct usb_mixer_interface *mixer)
3744 struct scarlett2_data *private = mixer->private_data;
3745 const struct scarlett2_device_info *info = private->info;
3746 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3747 int port_type, channel, i;
3749 for (i = 0, port_type = 0;
3750 port_type < SCARLETT2_PORT_TYPE_COUNT;
3753 channel < port_count[port_type][SCARLETT2_PORT_OUT];
3756 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3757 const char *const descr =
3758 scarlett2_ports[port_type].dst_descr;
3760 snprintf(s, sizeof(s) - 5, descr, channel + 1);
3763 err = scarlett2_add_new_ctl(mixer,
3764 &scarlett2_mux_src_enum_ctl,
3766 &private->mux_ctls[i]);
3775 /*** Meter Controls ***/
3777 static int scarlett2_meter_ctl_info(struct snd_kcontrol *kctl,
3778 struct snd_ctl_elem_info *uinfo)
3780 struct usb_mixer_elem_info *elem = kctl->private_data;
3782 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3783 uinfo->count = elem->channels;
3784 uinfo->value.integer.min = 0;
3785 uinfo->value.integer.max = 4095;
3786 uinfo->value.integer.step = 1;
3790 static int scarlett2_meter_ctl_get(struct snd_kcontrol *kctl,
3791 struct snd_ctl_elem_value *ucontrol)
3793 struct usb_mixer_elem_info *elem = kctl->private_data;
3794 struct scarlett2_data *private = elem->head.mixer->private_data;
3795 u8 *meter_level_map = private->meter_level_map;
3796 u16 meter_levels[SCARLETT2_MAX_METERS];
3799 err = scarlett2_usb_get_meter_levels(elem->head.mixer, elem->channels,
3804 /* copy & translate from meter_levels[] using meter_level_map[] */
3805 for (i = 0; i < elem->channels; i++) {
3806 int idx = meter_level_map[i];
3812 value = meter_levels[idx];
3814 ucontrol->value.integer.value[i] = value;
3820 static const struct snd_kcontrol_new scarlett2_meter_ctl = {
3821 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3822 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3824 .info = scarlett2_meter_ctl_info,
3825 .get = scarlett2_meter_ctl_get
3828 static int scarlett2_add_meter_ctl(struct usb_mixer_interface *mixer)
3830 struct scarlett2_data *private = mixer->private_data;
3832 /* devices without a mixer also don't support reporting levels */
3833 if (private->info->config_set == SCARLETT2_CONFIG_SET_GEN_3A)
3836 return scarlett2_add_new_ctl(mixer, &scarlett2_meter_ctl,
3837 0, private->num_mux_dsts,
3838 "Level Meter", NULL);
3841 /*** MSD Controls ***/
3843 static int scarlett2_msd_ctl_get(struct snd_kcontrol *kctl,
3844 struct snd_ctl_elem_value *ucontrol)
3846 struct usb_mixer_elem_info *elem = kctl->private_data;
3847 struct scarlett2_data *private = elem->head.mixer->private_data;
3849 ucontrol->value.integer.value[0] = private->msd_switch;
3853 static int scarlett2_msd_ctl_put(struct snd_kcontrol *kctl,
3854 struct snd_ctl_elem_value *ucontrol)
3856 struct usb_mixer_elem_info *elem = kctl->private_data;
3857 struct usb_mixer_interface *mixer = elem->head.mixer;
3858 struct scarlett2_data *private = mixer->private_data;
3860 int oval, val, err = 0;
3862 mutex_lock(&private->data_mutex);
3864 oval = private->msd_switch;
3865 val = !!ucontrol->value.integer.value[0];
3870 private->msd_switch = val;
3872 /* Send switch change to the device */
3873 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MSD_SWITCH,
3879 mutex_unlock(&private->data_mutex);
3883 static const struct snd_kcontrol_new scarlett2_msd_ctl = {
3884 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3886 .info = snd_ctl_boolean_mono_info,
3887 .get = scarlett2_msd_ctl_get,
3888 .put = scarlett2_msd_ctl_put,
3891 static int scarlett2_add_msd_ctl(struct usb_mixer_interface *mixer)
3893 struct scarlett2_data *private = mixer->private_data;
3894 const struct scarlett2_device_info *info = private->info;
3896 if (!info->has_msd_mode)
3899 /* If MSD mode is off, hide the switch by default */
3900 if (!private->msd_switch && !(mixer->chip->setup & SCARLETT2_MSD_ENABLE))
3903 /* Add MSD control */
3904 return scarlett2_add_new_ctl(mixer, &scarlett2_msd_ctl,
3905 0, 1, "MSD Mode Switch", NULL);
3908 /*** Standalone Control ***/
3910 static int scarlett2_standalone_ctl_get(struct snd_kcontrol *kctl,
3911 struct snd_ctl_elem_value *ucontrol)
3913 struct usb_mixer_elem_info *elem = kctl->private_data;
3914 struct scarlett2_data *private = elem->head.mixer->private_data;
3916 ucontrol->value.integer.value[0] = private->standalone_switch;
3920 static int scarlett2_standalone_ctl_put(struct snd_kcontrol *kctl,
3921 struct snd_ctl_elem_value *ucontrol)
3923 struct usb_mixer_elem_info *elem = kctl->private_data;
3924 struct usb_mixer_interface *mixer = elem->head.mixer;
3925 struct scarlett2_data *private = mixer->private_data;
3927 int oval, val, err = 0;
3929 mutex_lock(&private->data_mutex);
3931 oval = private->standalone_switch;
3932 val = !!ucontrol->value.integer.value[0];
3937 private->standalone_switch = val;
3939 /* Send switch change to the device */
3940 err = scarlett2_usb_set_config(mixer,
3941 SCARLETT2_CONFIG_STANDALONE_SWITCH,
3947 mutex_unlock(&private->data_mutex);
3951 static const struct snd_kcontrol_new scarlett2_standalone_ctl = {
3952 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3954 .info = snd_ctl_boolean_mono_info,
3955 .get = scarlett2_standalone_ctl_get,
3956 .put = scarlett2_standalone_ctl_put,
3959 static int scarlett2_add_standalone_ctl(struct usb_mixer_interface *mixer)
3961 struct scarlett2_data *private = mixer->private_data;
3963 if (private->info->config_set == SCARLETT2_CONFIG_SET_GEN_3A)
3966 /* Add standalone control */
3967 return scarlett2_add_new_ctl(mixer, &scarlett2_standalone_ctl,
3968 0, 1, "Standalone Switch", NULL);
3971 /*** Cleanup/Suspend Callbacks ***/
3973 static void scarlett2_private_free(struct usb_mixer_interface *mixer)
3975 struct scarlett2_data *private = mixer->private_data;
3977 cancel_delayed_work_sync(&private->work);
3979 mixer->private_data = NULL;
3982 static void scarlett2_private_suspend(struct usb_mixer_interface *mixer)
3984 struct scarlett2_data *private = mixer->private_data;
3986 if (cancel_delayed_work_sync(&private->work))
3987 scarlett2_config_save(private->mixer);
3990 /*** Initialisation ***/
3992 static void scarlett2_count_mux_io(struct scarlett2_data *private)
3994 const struct scarlett2_device_info *info = private->info;
3995 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3996 int port_type, srcs = 0, dsts = 0;
3999 port_type < SCARLETT2_PORT_TYPE_COUNT;
4001 srcs += port_count[port_type][SCARLETT2_PORT_IN];
4002 dsts += port_count[port_type][SCARLETT2_PORT_OUT];
4005 private->num_mux_srcs = srcs;
4006 private->num_mux_dsts = dsts;
4009 /* Look through the interface descriptors for the Focusrite Control
4010 * interface (bInterfaceClass = 255 Vendor Specific Class) and set
4011 * bInterfaceNumber, bEndpointAddress, wMaxPacketSize, and bInterval
4014 static int scarlett2_find_fc_interface(struct usb_device *dev,
4015 struct scarlett2_data *private)
4017 struct usb_host_config *config = dev->actconfig;
4020 for (i = 0; i < config->desc.bNumInterfaces; i++) {
4021 struct usb_interface *intf = config->interface[i];
4022 struct usb_interface_descriptor *desc =
4023 &intf->altsetting[0].desc;
4024 struct usb_endpoint_descriptor *epd;
4026 if (desc->bInterfaceClass != 255)
4029 epd = get_endpoint(intf->altsetting, 0);
4030 private->bInterfaceNumber = desc->bInterfaceNumber;
4031 private->bEndpointAddress = epd->bEndpointAddress &
4032 USB_ENDPOINT_NUMBER_MASK;
4033 private->wMaxPacketSize = le16_to_cpu(epd->wMaxPacketSize);
4034 private->bInterval = epd->bInterval;
4041 /* Initialise private data */
4042 static int scarlett2_init_private(struct usb_mixer_interface *mixer,
4043 const struct scarlett2_device_entry *entry)
4045 struct scarlett2_data *private =
4046 kzalloc(sizeof(struct scarlett2_data), GFP_KERNEL);
4051 mutex_init(&private->usb_mutex);
4052 mutex_init(&private->data_mutex);
4053 INIT_DELAYED_WORK(&private->work, scarlett2_config_save_work);
4055 mixer->private_data = private;
4056 mixer->private_free = scarlett2_private_free;
4057 mixer->private_suspend = scarlett2_private_suspend;
4059 private->info = entry->info;
4060 private->series_name = entry->series_name;
4061 scarlett2_count_mux_io(private);
4062 private->scarlett2_seq = 0;
4063 private->mixer = mixer;
4065 return scarlett2_find_fc_interface(mixer->chip->dev, private);
4068 /* Cargo cult proprietary initialisation sequence */
4069 static int scarlett2_usb_init(struct usb_mixer_interface *mixer)
4071 struct usb_device *dev = mixer->chip->dev;
4072 struct scarlett2_data *private = mixer->private_data;
4077 if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
4081 err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
4082 SCARLETT2_USB_CMD_INIT,
4083 step0_buf, sizeof(step0_buf));
4088 private->scarlett2_seq = 1;
4089 err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_1, NULL, 0, NULL, 0);
4094 private->scarlett2_seq = 1;
4095 err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_2,
4097 step2_buf, sizeof(step2_buf));
4101 /* extract 4-byte firmware version from step2_buf[8] */
4102 private->firmware_version = le32_to_cpu(*(__le32 *)(step2_buf + 8));
4103 usb_audio_info(mixer->chip,
4104 "Firmware version %d\n",
4105 private->firmware_version);
4110 /* Read configuration from the interface on start */
4111 static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
4113 struct scarlett2_data *private = mixer->private_data;
4114 const struct scarlett2_device_info *info = private->info;
4115 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
4117 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
4119 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
4120 struct scarlett2_usb_volume_status volume_status;
4123 if (info->has_msd_mode) {
4124 err = scarlett2_usb_get_config(
4125 mixer, SCARLETT2_CONFIG_MSD_SWITCH,
4126 1, &private->msd_switch);
4130 /* no other controls are created if MSD mode is on */
4131 if (private->msd_switch)
4135 err = scarlett2_update_input_other(mixer);
4139 err = scarlett2_update_monitor_other(mixer);
4143 /* the rest of the configuration is for devices with a mixer */
4144 if (info->config_set == SCARLETT2_CONFIG_SET_GEN_3A)
4147 err = scarlett2_usb_get_config(
4148 mixer, SCARLETT2_CONFIG_STANDALONE_SWITCH,
4149 1, &private->standalone_switch);
4153 err = scarlett2_update_sync(mixer);
4157 err = scarlett2_usb_get_volume_status(mixer, &volume_status);
4161 if (info->line_out_hw_vol)
4162 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
4163 private->dim_mute[i] = !!volume_status.dim_mute[i];
4165 private->master_vol = clamp(
4166 volume_status.master_vol + SCARLETT2_VOLUME_BIAS,
4167 0, SCARLETT2_VOLUME_BIAS);
4169 for (i = 0; i < num_line_out; i++) {
4172 private->vol_sw_hw_switch[i] =
4173 info->line_out_hw_vol
4174 && volume_status.sw_hw_switch[i];
4176 volume = private->vol_sw_hw_switch[i]
4177 ? volume_status.master_vol
4178 : volume_status.sw_vol[i];
4179 volume = clamp(volume + SCARLETT2_VOLUME_BIAS,
4180 0, SCARLETT2_VOLUME_BIAS);
4181 private->vol[i] = volume;
4183 mute = private->vol_sw_hw_switch[i]
4184 ? private->dim_mute[SCARLETT2_BUTTON_MUTE]
4185 : volume_status.mute_switch[i];
4186 private->mute_switch[i] = mute;
4189 for (i = 0; i < num_mixer_out; i++) {
4190 err = scarlett2_usb_get_mix(mixer, i);
4195 return scarlett2_usb_get_mux(mixer);
4198 /* Notify on sync change */
4199 static void scarlett2_notify_sync(
4200 struct usb_mixer_interface *mixer)
4202 struct scarlett2_data *private = mixer->private_data;
4204 private->sync_updated = 1;
4206 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
4207 &private->sync_ctl->id);
4210 /* Notify on monitor change */
4211 static void scarlett2_notify_monitor(
4212 struct usb_mixer_interface *mixer)
4214 struct snd_card *card = mixer->chip->card;
4215 struct scarlett2_data *private = mixer->private_data;
4216 const struct scarlett2_device_info *info = private->info;
4217 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
4219 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
4222 /* if line_out_hw_vol is 0, there are no controls to update */
4223 if (!info->line_out_hw_vol)
4226 private->vol_updated = 1;
4228 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
4229 &private->master_vol_ctl->id);
4231 for (i = 0; i < num_line_out; i++)
4232 if (private->vol_sw_hw_switch[line_out_remap(private, i)])
4233 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4234 &private->vol_ctls[i]->id);
4237 /* Notify on dim/mute change */
4238 static void scarlett2_notify_dim_mute(
4239 struct usb_mixer_interface *mixer)
4241 struct snd_card *card = mixer->chip->card;
4242 struct scarlett2_data *private = mixer->private_data;
4243 const struct scarlett2_device_info *info = private->info;
4244 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
4246 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
4249 private->vol_updated = 1;
4251 if (!info->line_out_hw_vol)
4254 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
4255 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4256 &private->dim_mute_ctls[i]->id);
4258 for (i = 0; i < num_line_out; i++)
4259 if (private->vol_sw_hw_switch[line_out_remap(private, i)])
4260 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4261 &private->mute_ctls[i]->id);
4264 /* Notify on "input other" change (level/pad/air) */
4265 static void scarlett2_notify_input_other(
4266 struct usb_mixer_interface *mixer)
4268 struct snd_card *card = mixer->chip->card;
4269 struct scarlett2_data *private = mixer->private_data;
4270 const struct scarlett2_device_info *info = private->info;
4273 private->input_other_updated = 1;
4275 for (i = 0; i < info->level_input_count; i++)
4276 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4277 &private->level_ctls[i]->id);
4278 for (i = 0; i < info->pad_input_count; i++)
4279 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4280 &private->pad_ctls[i]->id);
4281 for (i = 0; i < info->air_input_count; i++)
4282 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4283 &private->air_ctls[i]->id);
4284 for (i = 0; i < info->phantom_count; i++)
4285 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4286 &private->phantom_ctls[i]->id);
4289 /* Notify on "monitor other" change (direct monitor, speaker
4290 * switching, talkback)
4292 static void scarlett2_notify_monitor_other(
4293 struct usb_mixer_interface *mixer)
4295 struct snd_card *card = mixer->chip->card;
4296 struct scarlett2_data *private = mixer->private_data;
4297 const struct scarlett2_device_info *info = private->info;
4299 private->monitor_other_updated = 1;
4301 if (info->direct_monitor) {
4302 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4303 &private->direct_monitor_ctl->id);
4307 if (info->has_speaker_switching)
4308 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4309 &private->speaker_switching_ctl->id);
4311 if (info->has_talkback)
4312 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4313 &private->talkback_ctl->id);
4315 /* if speaker switching was recently enabled or disabled,
4316 * invalidate the dim/mute and mux enum controls
4318 if (private->speaker_switching_switched) {
4321 scarlett2_notify_dim_mute(mixer);
4323 private->speaker_switching_switched = 0;
4324 private->mux_updated = 1;
4326 for (i = 0; i < private->num_mux_dsts; i++)
4327 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4328 &private->mux_ctls[i]->id);
4332 /* Interrupt callback */
4333 static void scarlett2_notify(struct urb *urb)
4335 struct usb_mixer_interface *mixer = urb->context;
4336 int len = urb->actual_length;
4337 int ustatus = urb->status;
4340 if (ustatus != 0 || len != 8)
4343 data = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
4344 if (data & SCARLETT2_USB_NOTIFY_SYNC)
4345 scarlett2_notify_sync(mixer);
4346 if (data & SCARLETT2_USB_NOTIFY_MONITOR)
4347 scarlett2_notify_monitor(mixer);
4348 if (data & SCARLETT2_USB_NOTIFY_DIM_MUTE)
4349 scarlett2_notify_dim_mute(mixer);
4350 if (data & SCARLETT2_USB_NOTIFY_INPUT_OTHER)
4351 scarlett2_notify_input_other(mixer);
4352 if (data & SCARLETT2_USB_NOTIFY_MONITOR_OTHER)
4353 scarlett2_notify_monitor_other(mixer);
4356 if (ustatus != -ENOENT &&
4357 ustatus != -ECONNRESET &&
4358 ustatus != -ESHUTDOWN) {
4359 urb->dev = mixer->chip->dev;
4360 usb_submit_urb(urb, GFP_ATOMIC);
4364 static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
4366 struct usb_device *dev = mixer->chip->dev;
4367 struct scarlett2_data *private = mixer->private_data;
4368 unsigned int pipe = usb_rcvintpipe(dev, private->bEndpointAddress);
4369 void *transfer_buffer;
4372 usb_audio_err(mixer->chip,
4373 "%s: mixer urb already in use!\n", __func__);
4377 if (usb_pipe_type_check(dev, pipe))
4380 mixer->urb = usb_alloc_urb(0, GFP_KERNEL);
4384 transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
4385 if (!transfer_buffer)
4388 usb_fill_int_urb(mixer->urb, dev, pipe,
4389 transfer_buffer, private->wMaxPacketSize,
4390 scarlett2_notify, mixer, private->bInterval);
4392 return usb_submit_urb(mixer->urb, GFP_KERNEL);
4395 static const struct scarlett2_device_entry *get_scarlett2_device_entry(
4396 struct usb_mixer_interface *mixer)
4398 const struct scarlett2_device_entry *entry = scarlett2_devices;
4400 /* Find entry in scarlett2_devices */
4401 while (entry->usb_id && entry->usb_id != mixer->chip->usb_id)
4409 static int snd_scarlett2_controls_create(
4410 struct usb_mixer_interface *mixer,
4411 const struct scarlett2_device_entry *entry)
4415 /* Initialise private data */
4416 err = scarlett2_init_private(mixer, entry);
4420 /* Send proprietary USB initialisation sequence */
4421 err = scarlett2_usb_init(mixer);
4425 /* Add firmware version control */
4426 err = scarlett2_add_firmware_version_ctl(mixer);
4430 /* Read volume levels and controls from the interface */
4431 err = scarlett2_read_configs(mixer);
4435 /* Create the MSD control */
4436 err = scarlett2_add_msd_ctl(mixer);
4440 /* If MSD mode is enabled, don't create any other controls */
4441 if (((struct scarlett2_data *)mixer->private_data)->msd_switch)
4444 /* Create the analogue output controls */
4445 err = scarlett2_add_line_out_ctls(mixer);
4449 /* Create the analogue input controls */
4450 err = scarlett2_add_line_in_ctls(mixer);
4454 /* Create the input, output, and mixer mux input selections */
4455 err = scarlett2_add_mux_enums(mixer);
4459 /* Create the matrix mixer controls */
4460 err = scarlett2_add_mixer_ctls(mixer);
4464 /* Create the level meter controls */
4465 err = scarlett2_add_meter_ctl(mixer);
4469 /* Create the sync control */
4470 err = scarlett2_add_sync_ctl(mixer);
4474 /* Create the direct monitor control */
4475 err = scarlett2_add_direct_monitor_ctl(mixer);
4479 /* Create the speaker switching control */
4480 err = scarlett2_add_speaker_switch_ctl(mixer);
4484 /* Create the talkback controls */
4485 err = scarlett2_add_talkback_ctls(mixer);
4489 /* Create the standalone control */
4490 err = scarlett2_add_standalone_ctl(mixer);
4494 /* Set up the interrupt polling */
4495 err = scarlett2_init_notify(mixer);
4502 int snd_scarlett2_init(struct usb_mixer_interface *mixer)
4504 struct snd_usb_audio *chip = mixer->chip;
4505 const struct scarlett2_device_entry *entry;
4508 /* only use UAC_VERSION_2 */
4509 if (!mixer->protocol)
4512 /* find entry in scarlett2_devices */
4513 entry = get_scarlett2_device_entry(mixer);
4515 usb_audio_err(mixer->chip,
4516 "%s: missing device entry for %04x:%04x\n",
4518 USB_ID_VENDOR(chip->usb_id),
4519 USB_ID_PRODUCT(chip->usb_id));
4523 if (chip->setup & SCARLETT2_DISABLE) {
4524 usb_audio_info(chip,
4525 "Focusrite %s Mixer Driver disabled "
4526 "by modprobe options (snd_usb_audio "
4527 "vid=0x%04x pid=0x%04x device_setup=%d)\n",
4529 USB_ID_VENDOR(chip->usb_id),
4530 USB_ID_PRODUCT(chip->usb_id),
4535 usb_audio_info(chip,
4536 "Focusrite %s Mixer Driver enabled (pid=0x%04x); "
4537 "report any issues to g@b4.vu",
4539 USB_ID_PRODUCT(chip->usb_id));
4541 err = snd_scarlett2_controls_create(mixer, entry);
4543 usb_audio_err(mixer->chip,
4544 "Error initialising %s Mixer Driver: %d",