1 // SPDX-License-Identifier: GPL-2.0
3 * Focusrite Scarlett Gen 2/3 Driver for ALSA
6 * - 6i6/18i8/18i20 Gen 2
7 * - Solo/2i2/4i4/8i6/18i8/18i20 Gen 3
9 * Copyright (c) 2018-2021 by Geoffrey D. Bennett <g at b4.vu>
10 * Copyright (c) 2020-2021 by Vladimir Sadovnikov <sadko4u@gmail.com>
12 * Based on the Scarlett (Gen 1) Driver for ALSA:
14 * Copyright (c) 2013 by Tobias Hoffmann
15 * Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
16 * Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
17 * Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
19 * Many codes borrowed from audio.c by
20 * Alan Cox (alan at lxorguk.ukuu.org.uk)
21 * Thomas Sailer (sailer at ife.ee.ethz.ch)
24 * David Henningsson <david.henningsson at canonical.com>
27 /* The protocol was reverse engineered by looking at the communication
28 * between Focusrite Control 2.3.4 and the Focusrite(R) Scarlett 18i20
29 * (firmware 1083) using usbmon in July-August 2018.
31 * Scarlett 18i8 support added in April 2019.
33 * Scarlett 6i6 support added in June 2019 (thanks to Martin Wittmann
34 * for providing usbmon output and testing).
36 * Scarlett 4i4/8i6 Gen 3 support added in May 2020 (thanks to Laurent
37 * Debricon for donating a 4i4 and to Fredrik Unger for providing 8i6
38 * usbmon output and testing).
40 * Scarlett 18i8/18i20 Gen 3 support added in June 2020 (thanks to
41 * Darren Jaeckel, Alex Sedlack, and Clovis Lunel for providing usbmon
42 * output, protocol traces and testing).
44 * Support for loading mixer volume and mux configuration from the
45 * interface during driver initialisation added in May 2021 (thanks to
46 * Vladimir Sadovnikov for figuring out how).
48 * Support for Solo/2i2 Gen 3 added in May 2021 (thanks to Alexander
49 * Vorona for 2i2 protocol traces).
51 * Support for phantom power, direct monitoring, and speaker switching
52 * added in May-June 2021.
54 * This ALSA mixer gives access to (model-dependent):
55 * - input, output, mixer-matrix muxes
56 * - mixer-matrix gain stages
57 * - gain/volume/mute controls
59 * - line/inst level, pad, and air controls
60 * - phantom power, direct monitor, and speaker switching controls
61 * - disable/enable MSD mode
64 * /--------------\ 18chn 20chn /--------------\
65 * | Hardware in +--+------\ /-------------+--+ ALSA PCM out |
66 * \--------------/ | | | | \--------------/
70 * | +---------------+ | |
71 * | \ Matrix Mux / | |
78 * | +------------+ | |
82 * | | 18x10 Gain | | |
84 * | +-----+------+ | |
86 * |18chn |10chn | |20chn
91 * ===========================
92 * +---------------+ +--—------------+
93 * \ Output Mux / \ Capture Mux /
94 * +---+---+---+ +-----+-----+
98 * /--------------\ | | | /--------------\
99 * | S/PDIF, ADAT |<--/ |10chn \-->| ALSA PCM in |
100 * | Hardware out | | \--------------/
103 * +-------------+ Software gain per channel.
104 * | Master Gain |<-- 18i20 only: Switch per channel
105 * +------+------+ to select HW or SW gain control.
109 * | Analogue |<------/
114 * Gen 3 devices have a Mass Storage Device (MSD) mode where a small
115 * disk with registration and driver download information is presented
116 * to the host. To access the full functionality of the device without
117 * proprietary software, MSD mode can be disabled by:
118 * - holding down the 48V button for five seconds while powering on
120 * - using this driver and alsamixer to change the "MSD Mode" setting
121 * to Off and power-cycling the device
124 #include <linux/slab.h>
125 #include <linux/usb.h>
126 #include <linux/moduleparam.h>
128 #include <sound/control.h>
129 #include <sound/tlv.h>
131 #include "usbaudio.h"
135 #include "mixer_scarlett_gen2.h"
137 /* device_setup value to enable */
138 #define SCARLETT2_ENABLE 0x01
140 /* device_setup value to allow turning MSD mode back on */
141 #define SCARLETT2_MSD_ENABLE 0x02
143 /* some gui mixers can't handle negative ctl values */
144 #define SCARLETT2_VOLUME_BIAS 127
146 /* mixer range from -80dB to +6dB in 0.5dB steps */
147 #define SCARLETT2_MIXER_MIN_DB -80
148 #define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
149 #define SCARLETT2_MIXER_MAX_DB 6
150 #define SCARLETT2_MIXER_MAX_VALUE \
151 ((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
152 #define SCARLETT2_MIXER_VALUE_COUNT (SCARLETT2_MIXER_MAX_VALUE + 1)
154 /* map from (dB + 80) * 2 to mixer value
155 * for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20)))
157 static const u16 scarlett2_mixer_values[SCARLETT2_MIXER_VALUE_COUNT] = {
158 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
159 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
160 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
161 23, 24, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 46, 48, 51,
162 54, 57, 61, 65, 68, 73, 77, 81, 86, 91, 97, 103, 109, 115,
163 122, 129, 137, 145, 154, 163, 173, 183, 194, 205, 217, 230,
164 244, 259, 274, 290, 307, 326, 345, 365, 387, 410, 434, 460,
165 487, 516, 547, 579, 614, 650, 689, 730, 773, 819, 867, 919,
166 973, 1031, 1092, 1157, 1225, 1298, 1375, 1456, 1543, 1634,
167 1731, 1833, 1942, 2057, 2179, 2308, 2445, 2590, 2744, 2906,
168 3078, 3261, 3454, 3659, 3876, 4105, 4349, 4606, 4879, 5168,
169 5475, 5799, 6143, 6507, 6892, 7301, 7733, 8192, 8677, 9191,
170 9736, 10313, 10924, 11571, 12257, 12983, 13752, 14567, 15430,
174 /* Maximum number of analogue outputs */
175 #define SCARLETT2_ANALOGUE_MAX 10
177 /* Maximum number of level and pad switches */
178 #define SCARLETT2_LEVEL_SWITCH_MAX 2
179 #define SCARLETT2_PAD_SWITCH_MAX 8
180 #define SCARLETT2_AIR_SWITCH_MAX 8
181 #define SCARLETT2_PHANTOM_SWITCH_MAX 2
183 /* Maximum number of inputs to the mixer */
184 #define SCARLETT2_INPUT_MIX_MAX 25
186 /* Maximum number of outputs from the mixer */
187 #define SCARLETT2_OUTPUT_MIX_MAX 12
189 /* Maximum size of the data in the USB mux assignment message:
190 * 20 inputs, 20 outputs, 25 matrix inputs, 12 spare
192 #define SCARLETT2_MUX_MAX 77
194 /* Maximum number of meters (sum of output port counts) */
195 #define SCARLETT2_MAX_METERS 65
197 /* Hardware port types:
198 * - None (no input to mux)
206 SCARLETT2_PORT_TYPE_NONE = 0,
207 SCARLETT2_PORT_TYPE_ANALOGUE = 1,
208 SCARLETT2_PORT_TYPE_SPDIF = 2,
209 SCARLETT2_PORT_TYPE_ADAT = 3,
210 SCARLETT2_PORT_TYPE_MIX = 4,
211 SCARLETT2_PORT_TYPE_PCM = 5,
212 SCARLETT2_PORT_TYPE_COUNT = 6,
215 /* I/O count of each port type kept in struct scarlett2_ports */
217 SCARLETT2_PORT_IN = 0,
218 SCARLETT2_PORT_OUT = 1,
219 SCARLETT2_PORT_DIRNS = 2,
222 /* Dim/Mute buttons on the 18i20 */
224 SCARLETT2_BUTTON_MUTE = 0,
225 SCARLETT2_BUTTON_DIM = 1,
226 SCARLETT2_DIM_MUTE_COUNT = 2,
229 static const char *const scarlett2_dim_mute_names[SCARLETT2_DIM_MUTE_COUNT] = {
233 /* Description of each hardware port type:
234 * - id: hardware ID of this port type
235 * - src_descr: printf format string for mux input selections
236 * - src_num_offset: added to channel number for the fprintf
237 * - dst_descr: printf format string for mixer controls
239 struct scarlett2_port {
241 const char * const src_descr;
243 const char * const dst_descr;
246 static const struct scarlett2_port scarlett2_ports[SCARLETT2_PORT_TYPE_COUNT] = {
247 [SCARLETT2_PORT_TYPE_NONE] = {
251 [SCARLETT2_PORT_TYPE_ANALOGUE] = {
253 .src_descr = "Analogue %d",
255 .dst_descr = "Analogue Output %02d Playback"
257 [SCARLETT2_PORT_TYPE_SPDIF] = {
259 .src_descr = "S/PDIF %d",
261 .dst_descr = "S/PDIF Output %d Playback"
263 [SCARLETT2_PORT_TYPE_ADAT] = {
265 .src_descr = "ADAT %d",
267 .dst_descr = "ADAT Output %d Playback"
269 [SCARLETT2_PORT_TYPE_MIX] = {
271 .src_descr = "Mix %c",
272 .src_num_offset = 'A',
273 .dst_descr = "Mixer Input %02d Capture"
275 [SCARLETT2_PORT_TYPE_PCM] = {
277 .src_descr = "PCM %d",
279 .dst_descr = "PCM %02d Capture"
283 /* Number of mux tables: one for each band of sample rates
284 * (44.1/48kHz, 88.2/96kHz, and 176.4/176kHz)
286 #define SCARLETT2_MUX_TABLES 3
288 /* Maximum number of entries in a mux table */
289 #define SCARLETT2_MAX_MUX_ENTRIES 10
291 /* One entry within mux_assignment defines the port type and range of
292 * ports to add to the set_mux message. The end of the list is marked
295 struct scarlett2_mux_entry {
301 struct scarlett2_device_info {
302 u32 usb_id; /* USB device identifier */
304 /* Gen 3 devices have an internal MSD mode switch that needs
305 * to be disabled in order to access the full functionality of
310 /* Gen 3 devices without a mixer have a different
315 /* line out hw volume is sw controlled */
318 /* support for main/alt speaker switching */
319 u8 has_speaker_switching;
321 /* the number of analogue inputs with a software switchable
322 * level control that can be set to line or instrument
324 u8 level_input_count;
326 /* the first input with a level control (0-based) */
327 u8 level_input_first;
329 /* the number of analogue inputs with a software switchable
334 /* the number of analogue inputs with a software switchable
339 /* the number of phantom (48V) software switchable controls */
342 /* the number of inputs each phantom switch controls */
343 u8 inputs_per_phantom;
345 /* the number of direct monitor options
346 * (0 = none, 1 = mono only, 2 = mono/stereo)
350 /* remap analogue outputs; 18i8 Gen 3 has "line 3/4" connected
351 * internally to the analogue 7/8 outputs
353 u8 line_out_remap_enable;
354 u8 line_out_remap[SCARLETT2_ANALOGUE_MAX];
356 /* additional description for the line out volume controls */
357 const char * const line_out_descrs[SCARLETT2_ANALOGUE_MAX];
359 /* number of sources/destinations of each port type */
360 const int port_count[SCARLETT2_PORT_TYPE_COUNT][SCARLETT2_PORT_DIRNS];
362 /* layout/order of the entries in the set_mux message */
363 struct scarlett2_mux_entry mux_assignment[SCARLETT2_MUX_TABLES]
364 [SCARLETT2_MAX_MUX_ENTRIES];
367 struct scarlett2_data {
368 struct usb_mixer_interface *mixer;
369 struct mutex usb_mutex; /* prevent sending concurrent USB requests */
370 struct mutex data_mutex; /* lock access to this data */
371 struct delayed_work work;
372 const struct scarlett2_device_info *info;
373 __u8 bInterfaceNumber;
374 __u8 bEndpointAddress;
375 __u16 wMaxPacketSize;
382 u8 input_other_updated;
383 u8 monitor_other_updated;
385 u8 speaker_switching_switched;
388 u8 vol[SCARLETT2_ANALOGUE_MAX];
389 u8 vol_sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
390 u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
391 u8 level_switch[SCARLETT2_LEVEL_SWITCH_MAX];
392 u8 pad_switch[SCARLETT2_PAD_SWITCH_MAX];
393 u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
394 u8 air_switch[SCARLETT2_AIR_SWITCH_MAX];
395 u8 phantom_switch[SCARLETT2_PHANTOM_SWITCH_MAX];
396 u8 phantom_persistence;
397 u8 direct_monitor_switch;
398 u8 speaker_switching_switch;
400 struct snd_kcontrol *sync_ctl;
401 struct snd_kcontrol *master_vol_ctl;
402 struct snd_kcontrol *vol_ctls[SCARLETT2_ANALOGUE_MAX];
403 struct snd_kcontrol *sw_hw_ctls[SCARLETT2_ANALOGUE_MAX];
404 struct snd_kcontrol *mute_ctls[SCARLETT2_ANALOGUE_MAX];
405 struct snd_kcontrol *dim_mute_ctls[SCARLETT2_DIM_MUTE_COUNT];
406 struct snd_kcontrol *level_ctls[SCARLETT2_LEVEL_SWITCH_MAX];
407 struct snd_kcontrol *pad_ctls[SCARLETT2_PAD_SWITCH_MAX];
408 struct snd_kcontrol *air_ctls[SCARLETT2_AIR_SWITCH_MAX];
409 struct snd_kcontrol *phantom_ctls[SCARLETT2_PHANTOM_SWITCH_MAX];
410 struct snd_kcontrol *mux_ctls[SCARLETT2_MUX_MAX];
411 struct snd_kcontrol *direct_monitor_ctl;
412 struct snd_kcontrol *speaker_switching_ctl;
413 u8 mux[SCARLETT2_MUX_MAX];
414 u8 mix[SCARLETT2_INPUT_MIX_MAX * SCARLETT2_OUTPUT_MIX_MAX];
417 /*** Model-specific data ***/
419 static const struct scarlett2_device_info s6i6_gen2_info = {
420 .usb_id = USB_ID(0x1235, 0x8203),
423 .level_input_count = 2,
424 .pad_input_count = 2,
434 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
435 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
436 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
437 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
438 [SCARLETT2_PORT_TYPE_PCM] = { 6, 6 },
441 .mux_assignment = { {
442 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
443 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
444 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
445 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
446 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
449 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
450 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
451 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
452 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
453 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
456 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
457 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
458 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
459 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
460 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
465 static const struct scarlett2_device_info s18i8_gen2_info = {
466 .usb_id = USB_ID(0x1235, 0x8204),
469 .level_input_count = 2,
470 .pad_input_count = 4,
482 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
483 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
484 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
485 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
486 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
487 [SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
490 .mux_assignment = { {
491 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
492 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
493 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
494 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
495 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
498 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
499 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
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, 10 },
506 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
507 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
508 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
509 { SCARLETT2_PORT_TYPE_NONE, 0, 4 },
514 static const struct scarlett2_device_info s18i20_gen2_info = {
515 .usb_id = USB_ID(0x1235, 0x8201),
518 .line_out_hw_vol = 1,
534 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
535 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
536 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
537 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
538 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
539 [SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
542 .mux_assignment = { {
543 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
544 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
545 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
546 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
547 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
548 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
551 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
552 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
553 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
554 { SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
555 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
556 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
559 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
560 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
561 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
562 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
563 { SCARLETT2_PORT_TYPE_NONE, 0, 6 },
568 static const struct scarlett2_device_info solo_gen3_info = {
569 .usb_id = USB_ID(0x1235, 0x8211),
572 .level_input_count = 1,
573 .level_input_first = 1,
574 .air_input_count = 1,
576 .inputs_per_phantom = 1,
580 static const struct scarlett2_device_info s2i2_gen3_info = {
581 .usb_id = USB_ID(0x1235, 0x8210),
584 .level_input_count = 2,
585 .air_input_count = 2,
587 .inputs_per_phantom = 2,
591 static const struct scarlett2_device_info s4i4_gen3_info = {
592 .usb_id = USB_ID(0x1235, 0x8212),
596 .level_input_count = 2,
597 .pad_input_count = 2,
598 .air_input_count = 2,
600 .inputs_per_phantom = 2,
610 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
611 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
612 [SCARLETT2_PORT_TYPE_MIX] = { 6, 8 },
613 [SCARLETT2_PORT_TYPE_PCM] = { 4, 6 },
616 .mux_assignment = { {
617 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
618 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
619 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
620 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
623 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
624 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
625 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
626 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
629 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
630 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
631 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
632 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
637 static const struct scarlett2_device_info s8i6_gen3_info = {
638 .usb_id = USB_ID(0x1235, 0x8213),
642 .level_input_count = 2,
643 .pad_input_count = 2,
644 .air_input_count = 2,
646 .inputs_per_phantom = 2,
656 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
657 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 6, 4 },
658 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
659 [SCARLETT2_PORT_TYPE_MIX] = { 8, 8 },
660 [SCARLETT2_PORT_TYPE_PCM] = { 6, 10 },
663 .mux_assignment = { {
664 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
665 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
666 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
667 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
668 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
669 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
672 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
673 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
674 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
675 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
676 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
677 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
680 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
681 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
682 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
683 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
684 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
685 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
690 static const struct scarlett2_device_info s18i8_gen3_info = {
691 .usb_id = USB_ID(0x1235, 0x8214),
695 .line_out_hw_vol = 1,
696 .has_speaker_switching = 1,
697 .level_input_count = 2,
698 .pad_input_count = 2,
699 .air_input_count = 4,
701 .inputs_per_phantom = 2,
703 .line_out_remap_enable = 1,
704 .line_out_remap = { 0, 1, 6, 7, 2, 3, 4, 5 },
718 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
719 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 8 },
720 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
721 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
722 [SCARLETT2_PORT_TYPE_MIX] = { 10, 20 },
723 [SCARLETT2_PORT_TYPE_PCM] = { 8, 20 },
726 .mux_assignment = { {
727 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
728 { SCARLETT2_PORT_TYPE_PCM, 12, 8 },
729 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
730 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
731 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
732 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
733 { SCARLETT2_PORT_TYPE_PCM, 10, 2 },
734 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
735 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
738 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
739 { SCARLETT2_PORT_TYPE_PCM, 12, 4 },
740 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
741 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
742 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
743 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
744 { SCARLETT2_PORT_TYPE_PCM, 10, 2 },
745 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
746 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
749 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
750 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
751 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
752 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
753 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
754 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
755 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
760 static const struct scarlett2_device_info s18i20_gen3_info = {
761 .usb_id = USB_ID(0x1235, 0x8215),
765 .line_out_hw_vol = 1,
766 .has_speaker_switching = 1,
767 .level_input_count = 2,
768 .pad_input_count = 8,
769 .air_input_count = 8,
771 .inputs_per_phantom = 4,
787 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
788 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 9, 10 },
789 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
790 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
791 [SCARLETT2_PORT_TYPE_MIX] = { 12, 25 },
792 [SCARLETT2_PORT_TYPE_PCM] = { 20, 20 },
795 .mux_assignment = { {
796 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
797 { SCARLETT2_PORT_TYPE_PCM, 10, 10 },
798 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
799 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
800 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
801 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
802 { SCARLETT2_PORT_TYPE_MIX, 0, 25 },
803 { SCARLETT2_PORT_TYPE_NONE, 0, 12 },
806 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
807 { SCARLETT2_PORT_TYPE_PCM, 10, 8 },
808 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
809 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
810 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
811 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
812 { SCARLETT2_PORT_TYPE_MIX, 0, 25 },
813 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
816 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
817 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
818 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
819 { SCARLETT2_PORT_TYPE_NONE, 0, 24 },
824 static const struct scarlett2_device_info *scarlett2_devices[] = {
825 /* Supported Gen 2 devices */
830 /* Supported Gen 3 devices */
842 /* get the starting port index number for a given port type/direction */
843 static int scarlett2_get_port_start_num(
844 const int port_count[][SCARLETT2_PORT_DIRNS],
845 int direction, int port_type)
849 for (i = 0; i < port_type; i++)
850 num += port_count[i][direction];
855 /*** USB Interactions ***/
857 /* Notifications from the interface */
858 #define SCARLETT2_USB_NOTIFY_SYNC 0x00000008
859 #define SCARLETT2_USB_NOTIFY_DIM_MUTE 0x00200000
860 #define SCARLETT2_USB_NOTIFY_MONITOR 0x00400000
861 #define SCARLETT2_USB_NOTIFY_INPUT_OTHER 0x00800000
862 #define SCARLETT2_USB_NOTIFY_MONITOR_OTHER 0x01000000
864 /* Commands for sending/receiving requests/responses */
865 #define SCARLETT2_USB_CMD_INIT 0
866 #define SCARLETT2_USB_CMD_REQ 2
867 #define SCARLETT2_USB_CMD_RESP 3
869 #define SCARLETT2_USB_INIT_1 0x00000000
870 #define SCARLETT2_USB_INIT_2 0x00000002
871 #define SCARLETT2_USB_GET_METER 0x00001001
872 #define SCARLETT2_USB_GET_MIX 0x00002001
873 #define SCARLETT2_USB_SET_MIX 0x00002002
874 #define SCARLETT2_USB_GET_MUX 0x00003001
875 #define SCARLETT2_USB_SET_MUX 0x00003002
876 #define SCARLETT2_USB_GET_SYNC 0x00006004
877 #define SCARLETT2_USB_GET_DATA 0x00800000
878 #define SCARLETT2_USB_SET_DATA 0x00800001
879 #define SCARLETT2_USB_DATA_CMD 0x00800002
881 #define SCARLETT2_USB_CONFIG_SAVE 6
883 #define SCARLETT2_USB_VOLUME_STATUS_OFFSET 0x31
884 #define SCARLETT2_USB_METER_LEVELS_GET_MAGIC 1
886 /* volume status is read together (matches scarlett2_config_items[1]) */
887 struct scarlett2_usb_volume_status {
888 /* dim/mute buttons */
889 u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
893 /* software volume setting */
894 s16 sw_vol[SCARLETT2_ANALOGUE_MAX];
896 /* actual volume of output inc. dim (-18dB) */
897 s16 hw_vol[SCARLETT2_ANALOGUE_MAX];
899 /* internal mute buttons */
900 u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
902 /* sw (0) or hw (1) controlled */
903 u8 sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
907 /* front panel volume knob */
911 /* Configuration parameters that can be read and written */
913 SCARLETT2_CONFIG_DIM_MUTE = 0,
914 SCARLETT2_CONFIG_LINE_OUT_VOLUME = 1,
915 SCARLETT2_CONFIG_MUTE_SWITCH = 2,
916 SCARLETT2_CONFIG_SW_HW_SWITCH = 3,
917 SCARLETT2_CONFIG_LEVEL_SWITCH = 4,
918 SCARLETT2_CONFIG_PAD_SWITCH = 5,
919 SCARLETT2_CONFIG_MSD_SWITCH = 6,
920 SCARLETT2_CONFIG_AIR_SWITCH = 7,
921 SCARLETT2_CONFIG_PHANTOM_SWITCH = 8,
922 SCARLETT2_CONFIG_PHANTOM_PERSISTENCE = 9,
923 SCARLETT2_CONFIG_DIRECT_MONITOR = 10,
924 SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH = 11,
925 SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE = 12,
926 SCARLETT2_CONFIG_COUNT = 13
929 /* Location, size, and activation command number for the configuration
930 * parameters. Size is in bits and may be 1, 8, or 16.
932 struct scarlett2_config {
938 /* scarlett2_config_items[0] is for devices without a mixer
939 * scarlett2_config_items[1] is for devices with a mixer
941 static const struct scarlett2_config
942 scarlett2_config_items[2][SCARLETT2_CONFIG_COUNT] =
944 /* Devices without a mixer (Solo and 2i2 Gen 3) */
946 [SCARLETT2_CONFIG_MSD_SWITCH] = {
947 .offset = 0x04, .size = 8, .activate = 6 },
949 [SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
950 .offset = 0x05, .size = 8, .activate = 6 },
952 [SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
953 .offset = 0x06, .size = 8, .activate = 3 },
955 [SCARLETT2_CONFIG_DIRECT_MONITOR] = {
956 .offset = 0x07, .size = 8, .activate = 4 },
958 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
959 .offset = 0x08, .size = 1, .activate = 7 },
961 [SCARLETT2_CONFIG_AIR_SWITCH] = {
962 .offset = 0x09, .size = 1, .activate = 8 },
964 /* Devices with a mixer (Gen 2 and all other Gen 3) */
966 [SCARLETT2_CONFIG_DIM_MUTE] = {
967 .offset = 0x31, .size = 8, .activate = 2 },
969 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
970 .offset = 0x34, .size = 16, .activate = 1 },
972 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
973 .offset = 0x5c, .size = 8, .activate = 1 },
975 [SCARLETT2_CONFIG_SW_HW_SWITCH] = {
976 .offset = 0x66, .size = 8, .activate = 3 },
978 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
979 .offset = 0x7c, .size = 8, .activate = 7 },
981 [SCARLETT2_CONFIG_PAD_SWITCH] = {
982 .offset = 0x84, .size = 8, .activate = 8 },
984 [SCARLETT2_CONFIG_AIR_SWITCH] = {
985 .offset = 0x8c, .size = 8, .activate = 8 },
987 [SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
988 .offset = 0x9c, .size = 1, .activate = 8 },
990 [SCARLETT2_CONFIG_MSD_SWITCH] = {
991 .offset = 0x9d, .size = 8, .activate = 6 },
993 [SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
994 .offset = 0x9e, .size = 8, .activate = 6 },
996 [SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH] = {
997 .offset = 0x9f, .size = 1, .activate = 10 },
999 [SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE] = {
1000 .offset = 0xa0, .size = 1, .activate = 10 },
1003 /* proprietary request/response format */
1004 struct scarlett2_usb_packet {
1013 static void scarlett2_fill_request_header(struct scarlett2_data *private,
1014 struct scarlett2_usb_packet *req,
1015 u32 cmd, u16 req_size)
1017 /* sequence must go up by 1 for each request */
1018 u16 seq = private->scarlett2_seq++;
1020 req->cmd = cpu_to_le32(cmd);
1021 req->size = cpu_to_le16(req_size);
1022 req->seq = cpu_to_le16(seq);
1027 static int scarlett2_usb_tx(struct usb_device *dev, int interface,
1028 void *buf, u16 size)
1030 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1031 SCARLETT2_USB_CMD_REQ,
1032 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1033 0, interface, buf, size);
1036 static int scarlett2_usb_rx(struct usb_device *dev, int interface,
1037 u32 usb_req, void *buf, u16 size)
1039 return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1041 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1042 0, interface, buf, size);
1045 /* Send a proprietary format request to the Scarlett interface */
1046 static int scarlett2_usb(
1047 struct usb_mixer_interface *mixer, u32 cmd,
1048 void *req_data, u16 req_size, void *resp_data, u16 resp_size)
1050 struct scarlett2_data *private = mixer->private_data;
1051 struct usb_device *dev = mixer->chip->dev;
1052 u16 req_buf_size = sizeof(struct scarlett2_usb_packet) + req_size;
1053 u16 resp_buf_size = sizeof(struct scarlett2_usb_packet) + resp_size;
1054 struct scarlett2_usb_packet *req, *resp = NULL;
1057 req = kmalloc(req_buf_size, GFP_KERNEL);
1063 resp = kmalloc(resp_buf_size, GFP_KERNEL);
1069 mutex_lock(&private->usb_mutex);
1071 /* build request message and send it */
1073 scarlett2_fill_request_header(private, req, cmd, req_size);
1076 memcpy(req->data, req_data, req_size);
1078 err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
1081 if (err != req_buf_size) {
1084 "Scarlett Gen 2/3 USB request result cmd %x was %d\n",
1090 /* send a second message to get the response */
1092 err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
1093 SCARLETT2_USB_CMD_RESP,
1094 resp, resp_buf_size);
1096 /* validate the response */
1098 if (err != resp_buf_size) {
1101 "Scarlett Gen 2/3 USB response result cmd %x was %d "
1103 cmd, err, resp_buf_size);
1108 /* cmd/seq/size should match except when initialising
1109 * seq sent = 1, response = 0
1111 if (resp->cmd != req->cmd ||
1112 (resp->seq != req->seq &&
1113 (le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
1114 resp_size != le16_to_cpu(resp->size) ||
1119 "Scarlett Gen 2/3 USB invalid response; "
1120 "cmd tx/rx %d/%d seq %d/%d size %d/%d "
1121 "error %d pad %d\n",
1122 le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
1123 le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
1124 resp_size, le16_to_cpu(resp->size),
1125 le32_to_cpu(resp->error),
1126 le32_to_cpu(resp->pad));
1131 if (resp_data && resp_size > 0)
1132 memcpy(resp_data, resp->data, resp_size);
1135 mutex_unlock(&private->usb_mutex);
1142 /* Send a USB message to get data; result placed in *buf */
1143 static int scarlett2_usb_get(
1144 struct usb_mixer_interface *mixer,
1145 int offset, void *buf, int size)
1152 req.offset = cpu_to_le32(offset);
1153 req.size = cpu_to_le32(size);
1154 return scarlett2_usb(mixer, SCARLETT2_USB_GET_DATA,
1155 &req, sizeof(req), buf, size);
1158 /* Send a USB message to get configuration parameters; result placed in *buf */
1159 static int scarlett2_usb_get_config(
1160 struct usb_mixer_interface *mixer,
1161 int config_item_num, int count, void *buf)
1163 struct scarlett2_data *private = mixer->private_data;
1164 const struct scarlett2_device_info *info = private->info;
1165 const struct scarlett2_config *config_item =
1166 &scarlett2_config_items[info->has_mixer][config_item_num];
1170 /* For byte-sized parameters, retrieve directly into buf */
1171 if (config_item->size >= 8) {
1172 size = config_item->size / 8 * count;
1173 err = scarlett2_usb_get(mixer, config_item->offset, buf, size);
1177 for (i = 0; i < count; i++, (u16 *)buf++)
1178 *(u16 *)buf = le16_to_cpu(*(__le16 *)buf);
1182 /* For bit-sized parameters, retrieve into value */
1183 err = scarlett2_usb_get(mixer, config_item->offset, &value, 1);
1187 /* then unpack from value into buf[] */
1188 for (i = 0; i < 8 && i < count; i++, value >>= 1)
1189 *(u8 *)buf++ = value & 1;
1194 /* Send SCARLETT2_USB_DATA_CMD SCARLETT2_USB_CONFIG_SAVE */
1195 static void scarlett2_config_save(struct usb_mixer_interface *mixer)
1197 __le32 req = cpu_to_le32(SCARLETT2_USB_CONFIG_SAVE);
1199 scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
1204 /* Delayed work to save config */
1205 static void scarlett2_config_save_work(struct work_struct *work)
1207 struct scarlett2_data *private =
1208 container_of(work, struct scarlett2_data, work.work);
1210 scarlett2_config_save(private->mixer);
1213 /* Send a USB message to set a SCARLETT2_CONFIG_* parameter */
1214 static int scarlett2_usb_set_config(
1215 struct usb_mixer_interface *mixer,
1216 int config_item_num, int index, int value)
1218 struct scarlett2_data *private = mixer->private_data;
1219 const struct scarlett2_device_info *info = private->info;
1220 const struct scarlett2_config *config_item =
1221 &scarlett2_config_items[info->has_mixer][config_item_num];
1231 /* Cancel any pending NVRAM save */
1232 cancel_delayed_work_sync(&private->work);
1234 /* Convert config_item->size in bits to size in bytes and
1237 if (config_item->size >= 8) {
1238 size = config_item->size / 8;
1239 offset = config_item->offset + index * size;
1241 /* If updating a bit, retrieve the old value, set/clear the
1242 * bit as needed, and update value
1248 offset = config_item->offset;
1250 scarlett2_usb_get(mixer, offset, &tmp, 1);
1252 tmp |= (1 << index);
1254 tmp &= ~(1 << index);
1259 /* Send the configuration parameter data */
1260 req.offset = cpu_to_le32(offset);
1261 req.bytes = cpu_to_le32(size);
1262 req.value = cpu_to_le32(value);
1263 err = scarlett2_usb(mixer, SCARLETT2_USB_SET_DATA,
1264 &req, sizeof(u32) * 2 + size,
1269 /* Activate the change */
1270 req2 = cpu_to_le32(config_item->activate);
1271 err = scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
1272 &req2, sizeof(req2), NULL, 0);
1276 /* Schedule the change to be written to NVRAM */
1277 if (config_item->activate != SCARLETT2_USB_CONFIG_SAVE)
1278 schedule_delayed_work(&private->work, msecs_to_jiffies(2000));
1283 /* Send a USB message to get sync status; result placed in *sync */
1284 static int scarlett2_usb_get_sync_status(
1285 struct usb_mixer_interface *mixer,
1291 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_SYNC,
1292 NULL, 0, &data, sizeof(data));
1300 /* Send a USB message to get volume status; result placed in *buf */
1301 static int scarlett2_usb_get_volume_status(
1302 struct usb_mixer_interface *mixer,
1303 struct scarlett2_usb_volume_status *buf)
1305 return scarlett2_usb_get(mixer, SCARLETT2_USB_VOLUME_STATUS_OFFSET,
1309 /* Send a USB message to get the volumes for all inputs of one mix
1310 * and put the values into private->mix[]
1312 static int scarlett2_usb_get_mix(struct usb_mixer_interface *mixer,
1315 struct scarlett2_data *private = mixer->private_data;
1316 const struct scarlett2_device_info *info = private->info;
1319 info->port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
1327 __le16 data[SCARLETT2_INPUT_MIX_MAX];
1329 req.mix_num = cpu_to_le16(mix_num);
1330 req.count = cpu_to_le16(num_mixer_in);
1332 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MIX,
1334 data, num_mixer_in * sizeof(u16));
1338 for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++) {
1339 u16 mixer_value = le16_to_cpu(data[i]);
1341 for (k = 0; k < SCARLETT2_MIXER_VALUE_COUNT; k++)
1342 if (scarlett2_mixer_values[k] >= mixer_value)
1344 if (k == SCARLETT2_MIXER_VALUE_COUNT)
1345 k = SCARLETT2_MIXER_MAX_VALUE;
1346 private->mix[j] = k;
1352 /* Send a USB message to set the volumes for all inputs of one mix
1353 * (values obtained from private->mix[])
1355 static int scarlett2_usb_set_mix(struct usb_mixer_interface *mixer,
1358 struct scarlett2_data *private = mixer->private_data;
1359 const struct scarlett2_device_info *info = private->info;
1363 __le16 data[SCARLETT2_INPUT_MIX_MAX];
1368 info->port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
1370 req.mix_num = cpu_to_le16(mix_num);
1372 for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
1373 req.data[i] = cpu_to_le16(
1374 scarlett2_mixer_values[private->mix[j]]
1377 return scarlett2_usb(mixer, SCARLETT2_USB_SET_MIX,
1378 &req, (num_mixer_in + 1) * sizeof(u16),
1382 /* Convert a port number index (per info->port_count) to a hardware ID */
1383 static u32 scarlett2_mux_src_num_to_id(
1384 const int port_count[][SCARLETT2_PORT_DIRNS], int num)
1389 port_type < SCARLETT2_PORT_TYPE_COUNT;
1391 if (num < port_count[port_type][SCARLETT2_PORT_IN])
1392 return scarlett2_ports[port_type].id | num;
1393 num -= port_count[port_type][SCARLETT2_PORT_IN];
1400 /* Convert a hardware ID to a port number index */
1401 static u32 scarlett2_mux_id_to_num(
1402 const int port_count[][SCARLETT2_PORT_DIRNS], int direction, u32 id)
1408 port_type < SCARLETT2_PORT_TYPE_COUNT;
1410 int base = scarlett2_ports[port_type].id;
1411 int count = port_count[port_type][direction];
1413 if (id >= base && id < base + count)
1414 return port_num + id - base;
1422 /* Convert one mux entry from the interface and load into private->mux[] */
1423 static void scarlett2_usb_populate_mux(struct scarlett2_data *private,
1426 const struct scarlett2_device_info *info = private->info;
1427 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
1429 int dst_idx, src_idx;
1431 dst_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_OUT,
1436 if (dst_idx >= private->num_mux_dsts) {
1437 usb_audio_err(private->mixer->chip,
1438 "BUG: scarlett2_mux_id_to_num(%06x, OUT): %d >= %d",
1439 mux_entry, dst_idx, private->num_mux_dsts);
1443 src_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_IN,
1448 if (src_idx >= private->num_mux_srcs) {
1449 usb_audio_err(private->mixer->chip,
1450 "BUG: scarlett2_mux_id_to_num(%06x, IN): %d >= %d",
1451 mux_entry, src_idx, private->num_mux_srcs);
1455 private->mux[dst_idx] = src_idx;
1458 /* Send USB message to get mux inputs and then populate private->mux[] */
1459 static int scarlett2_usb_get_mux(struct usb_mixer_interface *mixer)
1461 struct scarlett2_data *private = mixer->private_data;
1462 int count = private->num_mux_dsts;
1470 __le32 data[SCARLETT2_MUX_MAX];
1472 private->mux_updated = 0;
1475 req.count = cpu_to_le16(count);
1477 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MUX,
1479 data, count * sizeof(u32));
1483 for (i = 0; i < count; i++)
1484 scarlett2_usb_populate_mux(private, le32_to_cpu(data[i]));
1489 /* Send USB messages to set mux inputs */
1490 static int scarlett2_usb_set_mux(struct usb_mixer_interface *mixer)
1492 struct scarlett2_data *private = mixer->private_data;
1493 const struct scarlett2_device_info *info = private->info;
1494 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
1500 __le32 data[SCARLETT2_MUX_MAX];
1505 /* set mux settings for each rate */
1506 for (table = 0; table < SCARLETT2_MUX_TABLES; table++) {
1507 const struct scarlett2_mux_entry *entry;
1509 /* i counts over the output array */
1512 req.num = cpu_to_le16(table);
1514 /* loop through each entry */
1515 for (entry = info->mux_assignment[table];
1519 int port_type = entry->port_type;
1520 int port_idx = entry->start;
1521 int mux_idx = scarlett2_get_port_start_num(port_count,
1522 SCARLETT2_PORT_OUT, port_type) + port_idx;
1523 int dst_id = scarlett2_ports[port_type].id + port_idx;
1527 for (j = 0; j < entry->count; j++)
1532 /* Non-empty mux slots use the lower 12 bits
1533 * for the destination and next 12 bits for
1536 for (j = 0; j < entry->count; j++) {
1537 int src_id = scarlett2_mux_src_num_to_id(
1538 port_count, private->mux[mux_idx++]);
1539 req.data[i++] = cpu_to_le32(dst_id |
1545 err = scarlett2_usb(mixer, SCARLETT2_USB_SET_MUX,
1546 &req, (i + 1) * sizeof(u32),
1555 /* Send USB message to get meter levels */
1556 static int scarlett2_usb_get_meter_levels(struct usb_mixer_interface *mixer,
1557 u16 num_meters, u16 *levels)
1564 u32 resp[SCARLETT2_MAX_METERS];
1568 req.num_meters = cpu_to_le16(num_meters);
1569 req.magic = cpu_to_le32(SCARLETT2_USB_METER_LEVELS_GET_MAGIC);
1570 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_METER,
1571 &req, sizeof(req), resp, num_meters * sizeof(u32));
1575 /* copy, convert to u16 */
1576 for (i = 0; i < num_meters; i++)
1577 levels[i] = resp[i];
1582 /*** Control Functions ***/
1584 /* helper function to create a new control */
1585 static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
1586 const struct snd_kcontrol_new *ncontrol,
1587 int index, int channels, const char *name,
1588 struct snd_kcontrol **kctl_return)
1590 struct snd_kcontrol *kctl;
1591 struct usb_mixer_elem_info *elem;
1594 elem = kzalloc(sizeof(*elem), GFP_KERNEL);
1598 /* We set USB_MIXER_BESPOKEN type, so that the core USB mixer code
1599 * ignores them for resume and other operations.
1600 * Also, the head.id field is set to 0, as we don't use this field.
1602 elem->head.mixer = mixer;
1603 elem->control = index;
1605 elem->channels = channels;
1606 elem->val_type = USB_MIXER_BESPOKEN;
1608 kctl = snd_ctl_new1(ncontrol, elem);
1613 kctl->private_free = snd_usb_mixer_elem_free;
1615 strscpy(kctl->id.name, name, sizeof(kctl->id.name));
1617 err = snd_usb_mixer_add_control(&elem->head, kctl);
1622 *kctl_return = kctl;
1627 /*** Sync Control ***/
1629 /* Update sync control after receiving notification that the status
1632 static int scarlett2_update_sync(struct usb_mixer_interface *mixer)
1634 struct scarlett2_data *private = mixer->private_data;
1636 private->sync_updated = 0;
1637 return scarlett2_usb_get_sync_status(mixer, &private->sync);
1640 static int scarlett2_sync_ctl_info(struct snd_kcontrol *kctl,
1641 struct snd_ctl_elem_info *uinfo)
1643 static const char *texts[2] = {
1644 "Unlocked", "Locked"
1646 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1649 static int scarlett2_sync_ctl_get(struct snd_kcontrol *kctl,
1650 struct snd_ctl_elem_value *ucontrol)
1652 struct usb_mixer_elem_info *elem = kctl->private_data;
1653 struct usb_mixer_interface *mixer = elem->head.mixer;
1654 struct scarlett2_data *private = mixer->private_data;
1656 mutex_lock(&private->data_mutex);
1657 if (private->sync_updated)
1658 scarlett2_update_sync(mixer);
1659 ucontrol->value.enumerated.item[0] = private->sync;
1660 mutex_unlock(&private->data_mutex);
1665 static const struct snd_kcontrol_new scarlett2_sync_ctl = {
1666 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1667 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1669 .info = scarlett2_sync_ctl_info,
1670 .get = scarlett2_sync_ctl_get
1673 static int scarlett2_add_sync_ctl(struct usb_mixer_interface *mixer)
1675 struct scarlett2_data *private = mixer->private_data;
1677 /* devices without a mixer also don't support reporting sync status */
1678 if (!private->info->has_mixer)
1681 return scarlett2_add_new_ctl(mixer, &scarlett2_sync_ctl,
1682 0, 1, "Sync Status", &private->sync_ctl);
1685 /*** Analogue Line Out Volume Controls ***/
1687 /* Update hardware volume controls after receiving notification that
1690 static int scarlett2_update_volumes(struct usb_mixer_interface *mixer)
1692 struct scarlett2_data *private = mixer->private_data;
1693 const struct scarlett2_device_info *info = private->info;
1694 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
1695 struct scarlett2_usb_volume_status volume_status;
1697 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
1701 private->vol_updated = 0;
1703 err = scarlett2_usb_get_volume_status(mixer, &volume_status);
1707 private->master_vol = clamp(
1708 volume_status.master_vol + SCARLETT2_VOLUME_BIAS,
1709 0, SCARLETT2_VOLUME_BIAS);
1711 if (info->line_out_hw_vol)
1712 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
1713 private->dim_mute[i] = !!volume_status.dim_mute[i];
1715 mute = private->dim_mute[SCARLETT2_BUTTON_MUTE];
1717 for (i = 0; i < num_line_out; i++)
1718 if (private->vol_sw_hw_switch[i]) {
1719 private->vol[i] = private->master_vol;
1720 private->mute_switch[i] = mute;
1726 static int scarlett2_volume_ctl_info(struct snd_kcontrol *kctl,
1727 struct snd_ctl_elem_info *uinfo)
1729 struct usb_mixer_elem_info *elem = kctl->private_data;
1731 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1732 uinfo->count = elem->channels;
1733 uinfo->value.integer.min = 0;
1734 uinfo->value.integer.max = SCARLETT2_VOLUME_BIAS;
1735 uinfo->value.integer.step = 1;
1739 static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl,
1740 struct snd_ctl_elem_value *ucontrol)
1742 struct usb_mixer_elem_info *elem = kctl->private_data;
1743 struct usb_mixer_interface *mixer = elem->head.mixer;
1744 struct scarlett2_data *private = mixer->private_data;
1746 mutex_lock(&private->data_mutex);
1747 if (private->vol_updated)
1748 scarlett2_update_volumes(mixer);
1749 mutex_unlock(&private->data_mutex);
1751 ucontrol->value.integer.value[0] = private->master_vol;
1755 static int line_out_remap(struct scarlett2_data *private, int index)
1757 const struct scarlett2_device_info *info = private->info;
1759 if (!info->line_out_remap_enable)
1761 return info->line_out_remap[index];
1764 static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl,
1765 struct snd_ctl_elem_value *ucontrol)
1767 struct usb_mixer_elem_info *elem = kctl->private_data;
1768 struct usb_mixer_interface *mixer = elem->head.mixer;
1769 struct scarlett2_data *private = mixer->private_data;
1770 int index = line_out_remap(private, elem->control);
1772 mutex_lock(&private->data_mutex);
1773 if (private->vol_updated)
1774 scarlett2_update_volumes(mixer);
1775 mutex_unlock(&private->data_mutex);
1777 ucontrol->value.integer.value[0] = private->vol[index];
1781 static int scarlett2_volume_ctl_put(struct snd_kcontrol *kctl,
1782 struct snd_ctl_elem_value *ucontrol)
1784 struct usb_mixer_elem_info *elem = kctl->private_data;
1785 struct usb_mixer_interface *mixer = elem->head.mixer;
1786 struct scarlett2_data *private = mixer->private_data;
1787 int index = line_out_remap(private, elem->control);
1788 int oval, val, err = 0;
1790 mutex_lock(&private->data_mutex);
1792 oval = private->vol[index];
1793 val = ucontrol->value.integer.value[0];
1798 private->vol[index] = val;
1799 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
1800 index, val - SCARLETT2_VOLUME_BIAS);
1805 mutex_unlock(&private->data_mutex);
1809 static const DECLARE_TLV_DB_MINMAX(
1810 db_scale_scarlett2_gain, -SCARLETT2_VOLUME_BIAS * 100, 0
1813 static const struct snd_kcontrol_new scarlett2_master_volume_ctl = {
1814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1815 .access = SNDRV_CTL_ELEM_ACCESS_READ |
1816 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1818 .info = scarlett2_volume_ctl_info,
1819 .get = scarlett2_master_volume_ctl_get,
1820 .private_value = 0, /* max value */
1821 .tlv = { .p = db_scale_scarlett2_gain }
1824 static const struct snd_kcontrol_new scarlett2_line_out_volume_ctl = {
1825 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1826 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1827 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1829 .info = scarlett2_volume_ctl_info,
1830 .get = scarlett2_volume_ctl_get,
1831 .put = scarlett2_volume_ctl_put,
1832 .private_value = 0, /* max value */
1833 .tlv = { .p = db_scale_scarlett2_gain }
1836 /*** Mute Switch Controls ***/
1838 static int scarlett2_mute_ctl_get(struct snd_kcontrol *kctl,
1839 struct snd_ctl_elem_value *ucontrol)
1841 struct usb_mixer_elem_info *elem = kctl->private_data;
1842 struct scarlett2_data *private = elem->head.mixer->private_data;
1843 int index = line_out_remap(private, elem->control);
1845 ucontrol->value.integer.value[0] = private->mute_switch[index];
1849 static int scarlett2_mute_ctl_put(struct snd_kcontrol *kctl,
1850 struct snd_ctl_elem_value *ucontrol)
1852 struct usb_mixer_elem_info *elem = kctl->private_data;
1853 struct usb_mixer_interface *mixer = elem->head.mixer;
1854 struct scarlett2_data *private = mixer->private_data;
1855 int index = line_out_remap(private, elem->control);
1856 int oval, val, err = 0;
1858 mutex_lock(&private->data_mutex);
1860 oval = private->mute_switch[index];
1861 val = !!ucontrol->value.integer.value[0];
1866 private->mute_switch[index] = val;
1868 /* Send mute change to the device */
1869 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
1873 mutex_unlock(&private->data_mutex);
1877 static const struct snd_kcontrol_new scarlett2_mute_ctl = {
1878 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1880 .info = snd_ctl_boolean_mono_info,
1881 .get = scarlett2_mute_ctl_get,
1882 .put = scarlett2_mute_ctl_put,
1885 /*** HW/SW Volume Switch Controls ***/
1887 static void scarlett2_sw_hw_ctl_ro(struct scarlett2_data *private, int index)
1889 private->sw_hw_ctls[index]->vd[0].access &=
1890 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
1893 static void scarlett2_sw_hw_ctl_rw(struct scarlett2_data *private, int index)
1895 private->sw_hw_ctls[index]->vd[0].access |=
1896 SNDRV_CTL_ELEM_ACCESS_WRITE;
1899 static int scarlett2_sw_hw_enum_ctl_info(struct snd_kcontrol *kctl,
1900 struct snd_ctl_elem_info *uinfo)
1902 static const char *const values[2] = {
1906 return snd_ctl_enum_info(uinfo, 1, 2, values);
1909 static int scarlett2_sw_hw_enum_ctl_get(struct snd_kcontrol *kctl,
1910 struct snd_ctl_elem_value *ucontrol)
1912 struct usb_mixer_elem_info *elem = kctl->private_data;
1913 struct scarlett2_data *private = elem->head.mixer->private_data;
1914 int index = line_out_remap(private, elem->control);
1916 ucontrol->value.enumerated.item[0] = private->vol_sw_hw_switch[index];
1920 static void scarlett2_vol_ctl_set_writable(struct usb_mixer_interface *mixer,
1921 int index, int value)
1923 struct scarlett2_data *private = mixer->private_data;
1924 struct snd_card *card = mixer->chip->card;
1926 /* Set/Clear write bits */
1928 private->vol_ctls[index]->vd[0].access |=
1929 SNDRV_CTL_ELEM_ACCESS_WRITE;
1930 private->mute_ctls[index]->vd[0].access |=
1931 SNDRV_CTL_ELEM_ACCESS_WRITE;
1933 private->vol_ctls[index]->vd[0].access &=
1934 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
1935 private->mute_ctls[index]->vd[0].access &=
1936 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
1939 /* Notify of write bit change */
1940 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
1941 &private->vol_ctls[index]->id);
1942 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
1943 &private->mute_ctls[index]->id);
1946 static int scarlett2_sw_hw_change(struct usb_mixer_interface *mixer,
1947 int ctl_index, int val)
1949 struct scarlett2_data *private = mixer->private_data;
1950 int index = line_out_remap(private, ctl_index);
1953 private->vol_sw_hw_switch[index] = val;
1955 /* Change access mode to RO (hardware controlled volume)
1956 * or RW (software controlled volume)
1958 scarlett2_vol_ctl_set_writable(mixer, ctl_index, !val);
1960 /* Reset volume/mute to master volume/mute */
1961 private->vol[index] = private->master_vol;
1962 private->mute_switch[index] = private->dim_mute[SCARLETT2_BUTTON_MUTE];
1964 /* Set SW volume to current HW volume */
1965 err = scarlett2_usb_set_config(
1966 mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
1967 index, private->master_vol - SCARLETT2_VOLUME_BIAS);
1971 /* Set SW mute to current HW mute */
1972 err = scarlett2_usb_set_config(
1973 mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
1974 index, private->dim_mute[SCARLETT2_BUTTON_MUTE]);
1978 /* Send SW/HW switch change to the device */
1979 return scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
1983 static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl,
1984 struct snd_ctl_elem_value *ucontrol)
1986 struct usb_mixer_elem_info *elem = kctl->private_data;
1987 struct usb_mixer_interface *mixer = elem->head.mixer;
1988 struct scarlett2_data *private = mixer->private_data;
1989 int ctl_index = elem->control;
1990 int index = line_out_remap(private, ctl_index);
1991 int oval, val, err = 0;
1993 mutex_lock(&private->data_mutex);
1995 oval = private->vol_sw_hw_switch[index];
1996 val = !!ucontrol->value.enumerated.item[0];
2001 err = scarlett2_sw_hw_change(mixer, ctl_index, val);
2006 mutex_unlock(&private->data_mutex);
2010 static const struct snd_kcontrol_new scarlett2_sw_hw_enum_ctl = {
2011 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2013 .info = scarlett2_sw_hw_enum_ctl_info,
2014 .get = scarlett2_sw_hw_enum_ctl_get,
2015 .put = scarlett2_sw_hw_enum_ctl_put,
2018 /*** Line Level/Instrument Level Switch Controls ***/
2020 static int scarlett2_update_input_other(struct usb_mixer_interface *mixer)
2022 struct scarlett2_data *private = mixer->private_data;
2023 const struct scarlett2_device_info *info = private->info;
2025 private->input_other_updated = 0;
2027 if (info->level_input_count) {
2028 int err = scarlett2_usb_get_config(
2029 mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
2030 info->level_input_count + info->level_input_first,
2031 private->level_switch);
2036 if (info->pad_input_count) {
2037 int err = scarlett2_usb_get_config(
2038 mixer, SCARLETT2_CONFIG_PAD_SWITCH,
2039 info->pad_input_count, private->pad_switch);
2044 if (info->air_input_count) {
2045 int err = scarlett2_usb_get_config(
2046 mixer, SCARLETT2_CONFIG_AIR_SWITCH,
2047 info->air_input_count, private->air_switch);
2052 if (info->phantom_count) {
2053 int err = scarlett2_usb_get_config(
2054 mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
2055 info->phantom_count, private->phantom_switch);
2059 err = scarlett2_usb_get_config(
2060 mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
2061 1, &private->phantom_persistence);
2069 static int scarlett2_level_enum_ctl_info(struct snd_kcontrol *kctl,
2070 struct snd_ctl_elem_info *uinfo)
2072 static const char *const values[2] = {
2076 return snd_ctl_enum_info(uinfo, 1, 2, values);
2079 static int scarlett2_level_enum_ctl_get(struct snd_kcontrol *kctl,
2080 struct snd_ctl_elem_value *ucontrol)
2082 struct usb_mixer_elem_info *elem = kctl->private_data;
2083 struct usb_mixer_interface *mixer = elem->head.mixer;
2084 struct scarlett2_data *private = mixer->private_data;
2085 const struct scarlett2_device_info *info = private->info;
2087 int index = elem->control + info->level_input_first;
2089 mutex_lock(&private->data_mutex);
2090 if (private->input_other_updated)
2091 scarlett2_update_input_other(mixer);
2092 ucontrol->value.enumerated.item[0] = private->level_switch[index];
2093 mutex_unlock(&private->data_mutex);
2098 static int scarlett2_level_enum_ctl_put(struct snd_kcontrol *kctl,
2099 struct snd_ctl_elem_value *ucontrol)
2101 struct usb_mixer_elem_info *elem = kctl->private_data;
2102 struct usb_mixer_interface *mixer = elem->head.mixer;
2103 struct scarlett2_data *private = mixer->private_data;
2104 const struct scarlett2_device_info *info = private->info;
2106 int index = elem->control + info->level_input_first;
2107 int oval, val, err = 0;
2109 mutex_lock(&private->data_mutex);
2111 oval = private->level_switch[index];
2112 val = !!ucontrol->value.enumerated.item[0];
2117 private->level_switch[index] = val;
2119 /* Send switch change to the device */
2120 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
2126 mutex_unlock(&private->data_mutex);
2130 static const struct snd_kcontrol_new scarlett2_level_enum_ctl = {
2131 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2133 .info = scarlett2_level_enum_ctl_info,
2134 .get = scarlett2_level_enum_ctl_get,
2135 .put = scarlett2_level_enum_ctl_put,
2138 /*** Pad Switch Controls ***/
2140 static int scarlett2_pad_ctl_get(struct snd_kcontrol *kctl,
2141 struct snd_ctl_elem_value *ucontrol)
2143 struct usb_mixer_elem_info *elem = kctl->private_data;
2144 struct usb_mixer_interface *mixer = elem->head.mixer;
2145 struct scarlett2_data *private = mixer->private_data;
2147 mutex_lock(&private->data_mutex);
2148 if (private->input_other_updated)
2149 scarlett2_update_input_other(mixer);
2150 ucontrol->value.integer.value[0] =
2151 private->pad_switch[elem->control];
2152 mutex_unlock(&private->data_mutex);
2157 static int scarlett2_pad_ctl_put(struct snd_kcontrol *kctl,
2158 struct snd_ctl_elem_value *ucontrol)
2160 struct usb_mixer_elem_info *elem = kctl->private_data;
2161 struct usb_mixer_interface *mixer = elem->head.mixer;
2162 struct scarlett2_data *private = mixer->private_data;
2164 int index = elem->control;
2165 int oval, val, err = 0;
2167 mutex_lock(&private->data_mutex);
2169 oval = private->pad_switch[index];
2170 val = !!ucontrol->value.integer.value[0];
2175 private->pad_switch[index] = val;
2177 /* Send switch change to the device */
2178 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PAD_SWITCH,
2184 mutex_unlock(&private->data_mutex);
2188 static const struct snd_kcontrol_new scarlett2_pad_ctl = {
2189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2191 .info = snd_ctl_boolean_mono_info,
2192 .get = scarlett2_pad_ctl_get,
2193 .put = scarlett2_pad_ctl_put,
2196 /*** Air Switch Controls ***/
2198 static int scarlett2_air_ctl_get(struct snd_kcontrol *kctl,
2199 struct snd_ctl_elem_value *ucontrol)
2201 struct usb_mixer_elem_info *elem = kctl->private_data;
2202 struct usb_mixer_interface *mixer = elem->head.mixer;
2203 struct scarlett2_data *private = mixer->private_data;
2205 mutex_lock(&private->data_mutex);
2206 if (private->input_other_updated)
2207 scarlett2_update_input_other(mixer);
2208 ucontrol->value.integer.value[0] = private->air_switch[elem->control];
2209 mutex_unlock(&private->data_mutex);
2214 static int scarlett2_air_ctl_put(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;
2221 int index = elem->control;
2222 int oval, val, err = 0;
2224 mutex_lock(&private->data_mutex);
2226 oval = private->air_switch[index];
2227 val = !!ucontrol->value.integer.value[0];
2232 private->air_switch[index] = val;
2234 /* Send switch change to the device */
2235 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_AIR_SWITCH,
2239 mutex_unlock(&private->data_mutex);
2243 static const struct snd_kcontrol_new scarlett2_air_ctl = {
2244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2246 .info = snd_ctl_boolean_mono_info,
2247 .get = scarlett2_air_ctl_get,
2248 .put = scarlett2_air_ctl_put,
2251 /*** Phantom Switch Controls ***/
2253 static int scarlett2_phantom_ctl_get(struct snd_kcontrol *kctl,
2254 struct snd_ctl_elem_value *ucontrol)
2256 struct usb_mixer_elem_info *elem = kctl->private_data;
2257 struct usb_mixer_interface *mixer = elem->head.mixer;
2258 struct scarlett2_data *private = mixer->private_data;
2260 mutex_lock(&private->data_mutex);
2261 if (private->input_other_updated)
2262 scarlett2_update_input_other(mixer);
2263 ucontrol->value.integer.value[0] =
2264 private->phantom_switch[elem->control];
2265 mutex_unlock(&private->data_mutex);
2270 static int scarlett2_phantom_ctl_put(struct snd_kcontrol *kctl,
2271 struct snd_ctl_elem_value *ucontrol)
2273 struct usb_mixer_elem_info *elem = kctl->private_data;
2274 struct usb_mixer_interface *mixer = elem->head.mixer;
2275 struct scarlett2_data *private = mixer->private_data;
2277 int index = elem->control;
2278 int oval, val, err = 0;
2280 mutex_lock(&private->data_mutex);
2282 oval = private->phantom_switch[index];
2283 val = !!ucontrol->value.integer.value[0];
2288 private->phantom_switch[index] = val;
2290 /* Send switch change to the device */
2291 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
2295 mutex_unlock(&private->data_mutex);
2299 static const struct snd_kcontrol_new scarlett2_phantom_ctl = {
2300 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2302 .info = snd_ctl_boolean_mono_info,
2303 .get = scarlett2_phantom_ctl_get,
2304 .put = scarlett2_phantom_ctl_put,
2307 /*** Phantom Persistence Control ***/
2309 static int scarlett2_phantom_persistence_ctl_get(
2310 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2312 struct usb_mixer_elem_info *elem = kctl->private_data;
2313 struct scarlett2_data *private = elem->head.mixer->private_data;
2315 ucontrol->value.integer.value[0] = private->phantom_persistence;
2319 static int scarlett2_phantom_persistence_ctl_put(
2320 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2322 struct usb_mixer_elem_info *elem = kctl->private_data;
2323 struct usb_mixer_interface *mixer = elem->head.mixer;
2324 struct scarlett2_data *private = mixer->private_data;
2326 int index = elem->control;
2327 int oval, val, err = 0;
2329 mutex_lock(&private->data_mutex);
2331 oval = private->phantom_persistence;
2332 val = !!ucontrol->value.integer.value[0];
2337 private->phantom_persistence = val;
2339 /* Send switch change to the device */
2340 err = scarlett2_usb_set_config(
2341 mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE, index, val);
2344 mutex_unlock(&private->data_mutex);
2348 static const struct snd_kcontrol_new scarlett2_phantom_persistence_ctl = {
2349 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2351 .info = snd_ctl_boolean_mono_info,
2352 .get = scarlett2_phantom_persistence_ctl_get,
2353 .put = scarlett2_phantom_persistence_ctl_put,
2356 /*** Direct Monitor Control ***/
2358 static int scarlett2_update_monitor_other(struct usb_mixer_interface *mixer)
2360 struct scarlett2_data *private = mixer->private_data;
2361 const struct scarlett2_device_info *info = private->info;
2364 /* monitor_other_enable[0] enables speaker switching */
2365 u8 monitor_other_enable[2];
2367 /* monitor_other_switch[0] activates the alternate speakers */
2368 u8 monitor_other_switch[2];
2370 private->monitor_other_updated = 0;
2372 if (info->direct_monitor)
2373 return scarlett2_usb_get_config(
2374 mixer, SCARLETT2_CONFIG_DIRECT_MONITOR,
2375 1, &private->direct_monitor_switch);
2377 if (!info->has_speaker_switching)
2380 err = scarlett2_usb_get_config(
2381 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
2382 2, monitor_other_enable);
2386 err = scarlett2_usb_get_config(
2387 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
2388 2, monitor_other_switch);
2392 if (!monitor_other_enable[0])
2393 private->speaker_switching_switch = 0;
2395 private->speaker_switching_switch = monitor_other_switch[0] + 1;
2400 static int scarlett2_direct_monitor_ctl_get(
2401 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2403 struct usb_mixer_elem_info *elem = kctl->private_data;
2404 struct usb_mixer_interface *mixer = elem->head.mixer;
2405 struct scarlett2_data *private = elem->head.mixer->private_data;
2407 mutex_lock(&private->data_mutex);
2408 if (private->monitor_other_updated)
2409 scarlett2_update_monitor_other(mixer);
2410 ucontrol->value.enumerated.item[0] = private->direct_monitor_switch;
2411 mutex_unlock(&private->data_mutex);
2416 static int scarlett2_direct_monitor_ctl_put(
2417 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2419 struct usb_mixer_elem_info *elem = kctl->private_data;
2420 struct usb_mixer_interface *mixer = elem->head.mixer;
2421 struct scarlett2_data *private = mixer->private_data;
2423 int index = elem->control;
2424 int oval, val, err = 0;
2426 mutex_lock(&private->data_mutex);
2428 oval = private->direct_monitor_switch;
2429 val = min(ucontrol->value.enumerated.item[0], 2U);
2434 private->direct_monitor_switch = val;
2436 /* Send switch change to the device */
2437 err = scarlett2_usb_set_config(
2438 mixer, SCARLETT2_CONFIG_DIRECT_MONITOR, index, val);
2441 mutex_unlock(&private->data_mutex);
2445 static int scarlett2_direct_monitor_stereo_enum_ctl_info(
2446 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
2448 static const char *const values[3] = {
2449 "Off", "Mono", "Stereo"
2452 return snd_ctl_enum_info(uinfo, 1, 3, values);
2455 /* Direct Monitor for Solo is mono-only and only needs a boolean control
2456 * Direct Monitor for 2i2 is selectable between Off/Mono/Stereo
2458 static const struct snd_kcontrol_new scarlett2_direct_monitor_ctl[2] = {
2460 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2462 .info = snd_ctl_boolean_mono_info,
2463 .get = scarlett2_direct_monitor_ctl_get,
2464 .put = scarlett2_direct_monitor_ctl_put,
2467 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2469 .info = scarlett2_direct_monitor_stereo_enum_ctl_info,
2470 .get = scarlett2_direct_monitor_ctl_get,
2471 .put = scarlett2_direct_monitor_ctl_put,
2475 static int scarlett2_add_direct_monitor_ctl(struct usb_mixer_interface *mixer)
2477 struct scarlett2_data *private = mixer->private_data;
2478 const struct scarlett2_device_info *info = private->info;
2480 if (!info->direct_monitor)
2483 return scarlett2_add_new_ctl(
2484 mixer, &scarlett2_direct_monitor_ctl[info->direct_monitor - 1],
2485 0, 1, "Direct Monitor Playback Switch",
2486 &private->direct_monitor_ctl);
2489 /*** Speaker Switching Control ***/
2491 static int scarlett2_speaker_switch_enum_ctl_info(
2492 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
2494 static const char *const values[3] = {
2495 "Off", "Main", "Alt"
2498 return snd_ctl_enum_info(uinfo, 1, 3, values);
2501 static int scarlett2_speaker_switch_enum_ctl_get(
2502 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2504 struct usb_mixer_elem_info *elem = kctl->private_data;
2505 struct usb_mixer_interface *mixer = elem->head.mixer;
2506 struct scarlett2_data *private = mixer->private_data;
2508 mutex_lock(&private->data_mutex);
2509 if (private->monitor_other_updated)
2510 scarlett2_update_monitor_other(mixer);
2511 ucontrol->value.enumerated.item[0] = private->speaker_switching_switch;
2512 mutex_unlock(&private->data_mutex);
2517 /* when speaker switching gets enabled, switch the main/alt speakers
2518 * to HW volume and disable those controls
2520 static void scarlett2_speaker_switch_enable(struct usb_mixer_interface *mixer)
2522 struct snd_card *card = mixer->chip->card;
2523 struct scarlett2_data *private = mixer->private_data;
2526 for (i = 0; i < 4; i++) {
2527 int index = line_out_remap(private, i);
2529 /* switch the main/alt speakers to HW volume */
2530 if (!private->vol_sw_hw_switch[index])
2531 scarlett2_sw_hw_change(private->mixer, i, 1);
2533 /* disable the line out SW/HW switch */
2534 scarlett2_sw_hw_ctl_ro(private, i);
2535 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
2536 &private->sw_hw_ctls[i]->id);
2539 /* when the next monitor-other notify comes in, update the mux
2542 private->speaker_switching_switched = 1;
2545 /* when speaker switching gets disabled, reenable the hw/sw controls
2546 * and invalidate the routing
2548 static void scarlett2_speaker_switch_disable(struct usb_mixer_interface *mixer)
2550 struct snd_card *card = mixer->chip->card;
2551 struct scarlett2_data *private = mixer->private_data;
2554 /* enable the line out SW/HW switch */
2555 for (i = 0; i < 4; i++) {
2556 scarlett2_sw_hw_ctl_rw(private, i);
2557 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
2558 &private->sw_hw_ctls[i]->id);
2561 /* when the next monitor-other notify comes in, update the mux
2564 private->speaker_switching_switched = 1;
2567 static int scarlett2_speaker_switch_enum_ctl_put(
2568 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
2570 struct usb_mixer_elem_info *elem = kctl->private_data;
2571 struct usb_mixer_interface *mixer = elem->head.mixer;
2572 struct scarlett2_data *private = mixer->private_data;
2574 int oval, val, err = 0;
2576 mutex_lock(&private->data_mutex);
2578 oval = private->speaker_switching_switch;
2579 val = min(ucontrol->value.enumerated.item[0], 2U);
2584 private->speaker_switching_switch = val;
2586 /* enable/disable speaker switching */
2587 err = scarlett2_usb_set_config(
2588 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
2593 /* if speaker switching is enabled, select main or alt */
2594 err = scarlett2_usb_set_config(
2595 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
2600 /* update controls if speaker switching gets enabled or disabled */
2602 scarlett2_speaker_switch_enable(mixer);
2603 else if (oval && !val)
2604 scarlett2_speaker_switch_disable(mixer);
2607 mutex_unlock(&private->data_mutex);
2611 static const struct snd_kcontrol_new scarlett2_speaker_switch_enum_ctl = {
2612 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2614 .info = scarlett2_speaker_switch_enum_ctl_info,
2615 .get = scarlett2_speaker_switch_enum_ctl_get,
2616 .put = scarlett2_speaker_switch_enum_ctl_put,
2619 static int scarlett2_add_speaker_switch_ctl(
2620 struct usb_mixer_interface *mixer)
2622 struct scarlett2_data *private = mixer->private_data;
2623 const struct scarlett2_device_info *info = private->info;
2625 if (!info->has_speaker_switching)
2628 return scarlett2_add_new_ctl(
2629 mixer, &scarlett2_speaker_switch_enum_ctl,
2630 0, 1, "Speaker Switching Playback Enum",
2631 &private->speaker_switching_ctl);
2634 /*** Dim/Mute Controls ***/
2636 static int scarlett2_dim_mute_ctl_get(struct snd_kcontrol *kctl,
2637 struct snd_ctl_elem_value *ucontrol)
2639 struct usb_mixer_elem_info *elem = kctl->private_data;
2640 struct usb_mixer_interface *mixer = elem->head.mixer;
2641 struct scarlett2_data *private = mixer->private_data;
2643 mutex_lock(&private->data_mutex);
2644 if (private->vol_updated)
2645 scarlett2_update_volumes(mixer);
2646 mutex_unlock(&private->data_mutex);
2648 ucontrol->value.integer.value[0] = private->dim_mute[elem->control];
2652 static int scarlett2_dim_mute_ctl_put(struct snd_kcontrol *kctl,
2653 struct snd_ctl_elem_value *ucontrol)
2655 struct usb_mixer_elem_info *elem = kctl->private_data;
2656 struct usb_mixer_interface *mixer = elem->head.mixer;
2657 struct scarlett2_data *private = mixer->private_data;
2658 const struct scarlett2_device_info *info = private->info;
2659 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2661 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
2663 int index = elem->control;
2664 int oval, val, err = 0, i;
2666 mutex_lock(&private->data_mutex);
2668 oval = private->dim_mute[index];
2669 val = !!ucontrol->value.integer.value[0];
2674 private->dim_mute[index] = val;
2676 /* Send switch change to the device */
2677 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_DIM_MUTE,
2682 if (index == SCARLETT2_BUTTON_MUTE)
2683 for (i = 0; i < num_line_out; i++) {
2684 int line_index = line_out_remap(private, i);
2686 if (private->vol_sw_hw_switch[line_index]) {
2687 private->mute_switch[line_index] = val;
2688 snd_ctl_notify(mixer->chip->card,
2689 SNDRV_CTL_EVENT_MASK_INFO,
2690 &private->mute_ctls[i]->id);
2695 mutex_unlock(&private->data_mutex);
2699 static const struct snd_kcontrol_new scarlett2_dim_mute_ctl = {
2700 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2702 .info = snd_ctl_boolean_mono_info,
2703 .get = scarlett2_dim_mute_ctl_get,
2704 .put = scarlett2_dim_mute_ctl_put
2707 /*** Create the analogue output controls ***/
2709 static int scarlett2_add_line_out_ctls(struct usb_mixer_interface *mixer)
2711 struct scarlett2_data *private = mixer->private_data;
2712 const struct scarlett2_device_info *info = private->info;
2713 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2715 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
2717 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2719 /* Add R/O HW volume control */
2720 if (info->line_out_hw_vol) {
2721 snprintf(s, sizeof(s), "Master HW Playback Volume");
2722 err = scarlett2_add_new_ctl(mixer,
2723 &scarlett2_master_volume_ctl,
2724 0, 1, s, &private->master_vol_ctl);
2729 /* Add volume controls */
2730 for (i = 0; i < num_line_out; i++) {
2731 int index = line_out_remap(private, i);
2734 if (info->line_out_descrs[i])
2735 snprintf(s, sizeof(s),
2736 "Line %02d (%s) Playback Volume",
2737 i + 1, info->line_out_descrs[i]);
2739 snprintf(s, sizeof(s),
2740 "Line %02d Playback Volume",
2742 err = scarlett2_add_new_ctl(mixer,
2743 &scarlett2_line_out_volume_ctl,
2744 i, 1, s, &private->vol_ctls[i]);
2749 snprintf(s, sizeof(s),
2750 "Line %02d Mute Playback Switch",
2752 err = scarlett2_add_new_ctl(mixer,
2753 &scarlett2_mute_ctl,
2755 &private->mute_ctls[i]);
2759 /* Make the fader and mute controls read-only if the
2760 * SW/HW switch is set to HW
2762 if (private->vol_sw_hw_switch[index])
2763 scarlett2_vol_ctl_set_writable(mixer, i, 0);
2766 if (info->line_out_hw_vol) {
2767 snprintf(s, sizeof(s),
2768 "Line Out %02d Volume Control Playback Enum",
2770 err = scarlett2_add_new_ctl(mixer,
2771 &scarlett2_sw_hw_enum_ctl,
2773 &private->sw_hw_ctls[i]);
2777 /* Make the switch read-only if the line is
2778 * involved in speaker switching
2780 if (private->speaker_switching_switch && i < 4)
2781 scarlett2_sw_hw_ctl_ro(private, i);
2785 /* Add dim/mute controls */
2786 if (info->line_out_hw_vol)
2787 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++) {
2788 err = scarlett2_add_new_ctl(
2789 mixer, &scarlett2_dim_mute_ctl,
2790 i, 1, scarlett2_dim_mute_names[i],
2791 &private->dim_mute_ctls[i]);
2799 /*** Create the analogue input controls ***/
2801 static int scarlett2_add_line_in_ctls(struct usb_mixer_interface *mixer)
2803 struct scarlett2_data *private = mixer->private_data;
2804 const struct scarlett2_device_info *info = private->info;
2806 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2807 const char *fmt = "Line In %d %s Capture %s";
2808 const char *fmt2 = "Line In %d-%d %s Capture %s";
2810 /* Add input level (line/inst) controls */
2811 for (i = 0; i < info->level_input_count; i++) {
2812 snprintf(s, sizeof(s), fmt, i + 1 + info->level_input_first,
2814 err = scarlett2_add_new_ctl(mixer, &scarlett2_level_enum_ctl,
2815 i, 1, s, &private->level_ctls[i]);
2820 /* Add input pad controls */
2821 for (i = 0; i < info->pad_input_count; i++) {
2822 snprintf(s, sizeof(s), fmt, i + 1, "Pad", "Switch");
2823 err = scarlett2_add_new_ctl(mixer, &scarlett2_pad_ctl,
2824 i, 1, s, &private->pad_ctls[i]);
2829 /* Add input air controls */
2830 for (i = 0; i < info->air_input_count; i++) {
2831 snprintf(s, sizeof(s), fmt, i + 1, "Air", "Switch");
2832 err = scarlett2_add_new_ctl(mixer, &scarlett2_air_ctl,
2833 i, 1, s, &private->air_ctls[i]);
2838 /* Add input phantom controls */
2839 if (info->inputs_per_phantom == 1) {
2840 for (i = 0; i < info->phantom_count; i++) {
2841 snprintf(s, sizeof(s), fmt, i + 1,
2842 "Phantom Power", "Switch");
2843 err = scarlett2_add_new_ctl(
2844 mixer, &scarlett2_phantom_ctl,
2845 i, 1, s, &private->phantom_ctls[i]);
2849 } else if (info->inputs_per_phantom > 1) {
2850 for (i = 0; i < info->phantom_count; i++) {
2851 int from = i * info->inputs_per_phantom + 1;
2852 int to = (i + 1) * info->inputs_per_phantom;
2854 snprintf(s, sizeof(s), fmt2, from, to,
2855 "Phantom Power", "Switch");
2856 err = scarlett2_add_new_ctl(
2857 mixer, &scarlett2_phantom_ctl,
2858 i, 1, s, &private->phantom_ctls[i]);
2863 if (info->phantom_count) {
2864 err = scarlett2_add_new_ctl(
2865 mixer, &scarlett2_phantom_persistence_ctl, 0, 1,
2866 "Phantom Power Persistence Capture Switch", NULL);
2874 /*** Mixer Volume Controls ***/
2876 static int scarlett2_mixer_ctl_info(struct snd_kcontrol *kctl,
2877 struct snd_ctl_elem_info *uinfo)
2879 struct usb_mixer_elem_info *elem = kctl->private_data;
2881 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2882 uinfo->count = elem->channels;
2883 uinfo->value.integer.min = 0;
2884 uinfo->value.integer.max = SCARLETT2_MIXER_MAX_VALUE;
2885 uinfo->value.integer.step = 1;
2889 static int scarlett2_mixer_ctl_get(struct snd_kcontrol *kctl,
2890 struct snd_ctl_elem_value *ucontrol)
2892 struct usb_mixer_elem_info *elem = kctl->private_data;
2893 struct scarlett2_data *private = elem->head.mixer->private_data;
2895 ucontrol->value.integer.value[0] = private->mix[elem->control];
2899 static int scarlett2_mixer_ctl_put(struct snd_kcontrol *kctl,
2900 struct snd_ctl_elem_value *ucontrol)
2902 struct usb_mixer_elem_info *elem = kctl->private_data;
2903 struct usb_mixer_interface *mixer = elem->head.mixer;
2904 struct scarlett2_data *private = mixer->private_data;
2905 const struct scarlett2_device_info *info = private->info;
2906 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2907 int oval, val, num_mixer_in, mix_num, err = 0;
2908 int index = elem->control;
2910 mutex_lock(&private->data_mutex);
2912 oval = private->mix[index];
2913 val = ucontrol->value.integer.value[0];
2914 num_mixer_in = port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
2915 mix_num = index / num_mixer_in;
2920 private->mix[index] = val;
2921 err = scarlett2_usb_set_mix(mixer, mix_num);
2926 mutex_unlock(&private->data_mutex);
2930 static const DECLARE_TLV_DB_MINMAX(
2931 db_scale_scarlett2_mixer,
2932 SCARLETT2_MIXER_MIN_DB * 100,
2933 SCARLETT2_MIXER_MAX_DB * 100
2936 static const struct snd_kcontrol_new scarlett2_mixer_ctl = {
2937 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2938 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2939 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
2941 .info = scarlett2_mixer_ctl_info,
2942 .get = scarlett2_mixer_ctl_get,
2943 .put = scarlett2_mixer_ctl_put,
2944 .private_value = SCARLETT2_MIXER_MAX_DB, /* max value */
2945 .tlv = { .p = db_scale_scarlett2_mixer }
2948 static int scarlett2_add_mixer_ctls(struct usb_mixer_interface *mixer)
2950 struct scarlett2_data *private = mixer->private_data;
2951 const struct scarlett2_device_info *info = private->info;
2952 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2955 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
2958 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
2960 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
2962 for (i = 0, index = 0; i < num_outputs; i++)
2963 for (j = 0; j < num_inputs; j++, index++) {
2964 snprintf(s, sizeof(s),
2965 "Mix %c Input %02d Playback Volume",
2967 err = scarlett2_add_new_ctl(mixer, &scarlett2_mixer_ctl,
2976 /*** Mux Source Selection Controls ***/
2978 static int scarlett2_mux_src_enum_ctl_info(struct snd_kcontrol *kctl,
2979 struct snd_ctl_elem_info *uinfo)
2981 struct usb_mixer_elem_info *elem = kctl->private_data;
2982 struct scarlett2_data *private = elem->head.mixer->private_data;
2983 const struct scarlett2_device_info *info = private->info;
2984 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2985 unsigned int item = uinfo->value.enumerated.item;
2986 int items = private->num_mux_srcs;
2989 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2990 uinfo->count = elem->channels;
2991 uinfo->value.enumerated.items = items;
2994 item = uinfo->value.enumerated.item = items - 1;
2997 port_type < SCARLETT2_PORT_TYPE_COUNT;
2999 if (item < port_count[port_type][SCARLETT2_PORT_IN]) {
3000 const struct scarlett2_port *port =
3001 &scarlett2_ports[port_type];
3003 sprintf(uinfo->value.enumerated.name,
3004 port->src_descr, item + port->src_num_offset);
3007 item -= port_count[port_type][SCARLETT2_PORT_IN];
3013 static int scarlett2_mux_src_enum_ctl_get(struct snd_kcontrol *kctl,
3014 struct snd_ctl_elem_value *ucontrol)
3016 struct usb_mixer_elem_info *elem = kctl->private_data;
3017 struct usb_mixer_interface *mixer = elem->head.mixer;
3018 struct scarlett2_data *private = mixer->private_data;
3019 const struct scarlett2_device_info *info = private->info;
3020 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3021 int line_out_count =
3022 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
3023 int index = elem->control;
3025 if (index < line_out_count)
3026 index = line_out_remap(private, index);
3028 mutex_lock(&private->data_mutex);
3029 if (private->mux_updated)
3030 scarlett2_usb_get_mux(mixer);
3031 ucontrol->value.enumerated.item[0] = private->mux[index];
3032 mutex_unlock(&private->data_mutex);
3037 static int scarlett2_mux_src_enum_ctl_put(struct snd_kcontrol *kctl,
3038 struct snd_ctl_elem_value *ucontrol)
3040 struct usb_mixer_elem_info *elem = kctl->private_data;
3041 struct usb_mixer_interface *mixer = elem->head.mixer;
3042 struct scarlett2_data *private = mixer->private_data;
3043 const struct scarlett2_device_info *info = private->info;
3044 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3045 int line_out_count =
3046 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
3047 int index = elem->control;
3048 int oval, val, err = 0;
3050 if (index < line_out_count)
3051 index = line_out_remap(private, index);
3053 mutex_lock(&private->data_mutex);
3055 oval = private->mux[index];
3056 val = min(ucontrol->value.enumerated.item[0],
3057 private->num_mux_srcs - 1U);
3062 private->mux[index] = val;
3063 err = scarlett2_usb_set_mux(mixer);
3068 mutex_unlock(&private->data_mutex);
3072 static const struct snd_kcontrol_new scarlett2_mux_src_enum_ctl = {
3073 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3075 .info = scarlett2_mux_src_enum_ctl_info,
3076 .get = scarlett2_mux_src_enum_ctl_get,
3077 .put = scarlett2_mux_src_enum_ctl_put,
3080 static int scarlett2_add_mux_enums(struct usb_mixer_interface *mixer)
3082 struct scarlett2_data *private = mixer->private_data;
3083 const struct scarlett2_device_info *info = private->info;
3084 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3085 int port_type, channel, i;
3087 for (i = 0, port_type = 0;
3088 port_type < SCARLETT2_PORT_TYPE_COUNT;
3091 channel < port_count[port_type][SCARLETT2_PORT_OUT];
3094 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3095 const char *const descr =
3096 scarlett2_ports[port_type].dst_descr;
3098 snprintf(s, sizeof(s) - 5, descr, channel + 1);
3101 err = scarlett2_add_new_ctl(mixer,
3102 &scarlett2_mux_src_enum_ctl,
3104 &private->mux_ctls[i]);
3113 /*** Meter Controls ***/
3115 static int scarlett2_meter_ctl_info(struct snd_kcontrol *kctl,
3116 struct snd_ctl_elem_info *uinfo)
3118 struct usb_mixer_elem_info *elem = kctl->private_data;
3120 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3121 uinfo->count = elem->channels;
3122 uinfo->value.integer.min = 0;
3123 uinfo->value.integer.max = 4095;
3124 uinfo->value.integer.step = 1;
3128 static int scarlett2_meter_ctl_get(struct snd_kcontrol *kctl,
3129 struct snd_ctl_elem_value *ucontrol)
3131 struct usb_mixer_elem_info *elem = kctl->private_data;
3132 u16 meter_levels[SCARLETT2_MAX_METERS];
3135 err = scarlett2_usb_get_meter_levels(elem->head.mixer, elem->channels,
3140 for (i = 0; i < elem->channels; i++)
3141 ucontrol->value.integer.value[i] = meter_levels[i];
3146 static const struct snd_kcontrol_new scarlett2_meter_ctl = {
3147 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3148 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
3150 .info = scarlett2_meter_ctl_info,
3151 .get = scarlett2_meter_ctl_get
3154 static int scarlett2_add_meter_ctl(struct usb_mixer_interface *mixer)
3156 struct scarlett2_data *private = mixer->private_data;
3158 /* devices without a mixer also don't support reporting levels */
3159 if (!private->info->has_mixer)
3162 return scarlett2_add_new_ctl(mixer, &scarlett2_meter_ctl,
3163 0, private->num_mux_dsts,
3164 "Level Meter", NULL);
3167 /*** MSD Controls ***/
3169 static int scarlett2_msd_ctl_get(struct snd_kcontrol *kctl,
3170 struct snd_ctl_elem_value *ucontrol)
3172 struct usb_mixer_elem_info *elem = kctl->private_data;
3173 struct scarlett2_data *private = elem->head.mixer->private_data;
3175 ucontrol->value.integer.value[0] = private->msd_switch;
3179 static int scarlett2_msd_ctl_put(struct snd_kcontrol *kctl,
3180 struct snd_ctl_elem_value *ucontrol)
3182 struct usb_mixer_elem_info *elem = kctl->private_data;
3183 struct usb_mixer_interface *mixer = elem->head.mixer;
3184 struct scarlett2_data *private = mixer->private_data;
3186 int oval, val, err = 0;
3188 mutex_lock(&private->data_mutex);
3190 oval = private->msd_switch;
3191 val = !!ucontrol->value.integer.value[0];
3196 private->msd_switch = val;
3198 /* Send switch change to the device */
3199 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MSD_SWITCH,
3203 mutex_unlock(&private->data_mutex);
3207 static const struct snd_kcontrol_new scarlett2_msd_ctl = {
3208 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3210 .info = snd_ctl_boolean_mono_info,
3211 .get = scarlett2_msd_ctl_get,
3212 .put = scarlett2_msd_ctl_put,
3215 static int scarlett2_add_msd_ctl(struct usb_mixer_interface *mixer)
3217 struct scarlett2_data *private = mixer->private_data;
3218 const struct scarlett2_device_info *info = private->info;
3220 if (!info->has_msd_mode)
3223 /* If MSD mode is off, hide the switch by default */
3224 if (!private->msd_switch && !(mixer->chip->setup & SCARLETT2_MSD_ENABLE))
3227 /* Add MSD control */
3228 return scarlett2_add_new_ctl(mixer, &scarlett2_msd_ctl,
3229 0, 1, "MSD Mode", NULL);
3232 /*** Cleanup/Suspend Callbacks ***/
3234 static void scarlett2_private_free(struct usb_mixer_interface *mixer)
3236 struct scarlett2_data *private = mixer->private_data;
3238 cancel_delayed_work_sync(&private->work);
3240 mixer->private_data = NULL;
3243 static void scarlett2_private_suspend(struct usb_mixer_interface *mixer)
3245 struct scarlett2_data *private = mixer->private_data;
3247 if (cancel_delayed_work_sync(&private->work))
3248 scarlett2_config_save(private->mixer);
3251 /*** Initialisation ***/
3253 static void scarlett2_count_mux_io(struct scarlett2_data *private)
3255 const struct scarlett2_device_info *info = private->info;
3256 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3257 int port_type, srcs = 0, dsts = 0;
3260 port_type < SCARLETT2_PORT_TYPE_COUNT;
3262 srcs += port_count[port_type][SCARLETT2_PORT_IN];
3263 dsts += port_count[port_type][SCARLETT2_PORT_OUT];
3266 private->num_mux_srcs = srcs;
3267 private->num_mux_dsts = dsts;
3270 /* Look through the interface descriptors for the Focusrite Control
3271 * interface (bInterfaceClass = 255 Vendor Specific Class) and set
3272 * bInterfaceNumber, bEndpointAddress, wMaxPacketSize, and bInterval
3275 static int scarlett2_find_fc_interface(struct usb_device *dev,
3276 struct scarlett2_data *private)
3278 struct usb_host_config *config = dev->actconfig;
3281 for (i = 0; i < config->desc.bNumInterfaces; i++) {
3282 struct usb_interface *intf = config->interface[i];
3283 struct usb_interface_descriptor *desc =
3284 &intf->altsetting[0].desc;
3285 struct usb_endpoint_descriptor *epd;
3287 if (desc->bInterfaceClass != 255)
3290 epd = get_endpoint(intf->altsetting, 0);
3291 private->bInterfaceNumber = desc->bInterfaceNumber;
3292 private->bEndpointAddress = epd->bEndpointAddress &
3293 USB_ENDPOINT_NUMBER_MASK;
3294 private->wMaxPacketSize = le16_to_cpu(epd->wMaxPacketSize);
3295 private->bInterval = epd->bInterval;
3302 /* Initialise private data */
3303 static int scarlett2_init_private(struct usb_mixer_interface *mixer,
3304 const struct scarlett2_device_info *info)
3306 struct scarlett2_data *private =
3307 kzalloc(sizeof(struct scarlett2_data), GFP_KERNEL);
3312 mutex_init(&private->usb_mutex);
3313 mutex_init(&private->data_mutex);
3314 INIT_DELAYED_WORK(&private->work, scarlett2_config_save_work);
3316 mixer->private_data = private;
3317 mixer->private_free = scarlett2_private_free;
3318 mixer->private_suspend = scarlett2_private_suspend;
3320 private->info = info;
3321 scarlett2_count_mux_io(private);
3322 private->scarlett2_seq = 0;
3323 private->mixer = mixer;
3325 return scarlett2_find_fc_interface(mixer->chip->dev, private);
3328 /* Cargo cult proprietary initialisation sequence */
3329 static int scarlett2_usb_init(struct usb_mixer_interface *mixer)
3331 struct usb_device *dev = mixer->chip->dev;
3332 struct scarlett2_data *private = mixer->private_data;
3336 if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
3340 err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
3341 SCARLETT2_USB_CMD_INIT, buf, sizeof(buf));
3346 private->scarlett2_seq = 1;
3347 err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_1, NULL, 0, NULL, 0);
3352 private->scarlett2_seq = 1;
3353 return scarlett2_usb(mixer, SCARLETT2_USB_INIT_2, NULL, 0, NULL, 84);
3356 /* Read configuration from the interface on start */
3357 static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
3359 struct scarlett2_data *private = mixer->private_data;
3360 const struct scarlett2_device_info *info = private->info;
3361 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3363 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
3365 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
3366 struct scarlett2_usb_volume_status volume_status;
3369 if (info->has_msd_mode) {
3370 err = scarlett2_usb_get_config(
3371 mixer, SCARLETT2_CONFIG_MSD_SWITCH,
3372 1, &private->msd_switch);
3376 /* no other controls are created if MSD mode is on */
3377 if (private->msd_switch)
3381 err = scarlett2_update_input_other(mixer);
3385 err = scarlett2_update_monitor_other(mixer);
3389 /* the rest of the configuration is for devices with a mixer */
3390 if (!info->has_mixer)
3393 err = scarlett2_update_sync(mixer);
3397 err = scarlett2_usb_get_volume_status(mixer, &volume_status);
3401 if (info->line_out_hw_vol)
3402 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
3403 private->dim_mute[i] = !!volume_status.dim_mute[i];
3405 private->master_vol = clamp(
3406 volume_status.master_vol + SCARLETT2_VOLUME_BIAS,
3407 0, SCARLETT2_VOLUME_BIAS);
3409 for (i = 0; i < num_line_out; i++) {
3412 private->vol_sw_hw_switch[i] =
3413 info->line_out_hw_vol
3414 && volume_status.sw_hw_switch[i];
3416 volume = private->vol_sw_hw_switch[i]
3417 ? volume_status.master_vol
3418 : volume_status.sw_vol[i];
3419 volume = clamp(volume + SCARLETT2_VOLUME_BIAS,
3420 0, SCARLETT2_VOLUME_BIAS);
3421 private->vol[i] = volume;
3423 mute = private->vol_sw_hw_switch[i]
3424 ? private->dim_mute[SCARLETT2_BUTTON_MUTE]
3425 : volume_status.mute_switch[i];
3426 private->mute_switch[i] = mute;
3429 for (i = 0; i < num_mixer_out; i++) {
3430 err = scarlett2_usb_get_mix(mixer, i);
3435 return scarlett2_usb_get_mux(mixer);
3438 /* Notify on sync change */
3439 static void scarlett2_notify_sync(
3440 struct usb_mixer_interface *mixer)
3442 struct scarlett2_data *private = mixer->private_data;
3444 private->sync_updated = 1;
3446 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
3447 &private->sync_ctl->id);
3450 /* Notify on monitor change */
3451 static void scarlett2_notify_monitor(
3452 struct usb_mixer_interface *mixer)
3454 struct snd_card *card = mixer->chip->card;
3455 struct scarlett2_data *private = mixer->private_data;
3456 const struct scarlett2_device_info *info = private->info;
3457 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3459 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
3462 /* if line_out_hw_vol is 0, there are no controls to update */
3463 if (!info->line_out_hw_vol)
3466 private->vol_updated = 1;
3468 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
3469 &private->master_vol_ctl->id);
3471 for (i = 0; i < num_line_out; i++)
3472 if (private->vol_sw_hw_switch[line_out_remap(private, i)])
3473 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3474 &private->vol_ctls[i]->id);
3477 /* Notify on dim/mute change */
3478 static void scarlett2_notify_dim_mute(
3479 struct usb_mixer_interface *mixer)
3481 struct snd_card *card = mixer->chip->card;
3482 struct scarlett2_data *private = mixer->private_data;
3483 const struct scarlett2_device_info *info = private->info;
3484 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
3486 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
3489 private->vol_updated = 1;
3491 if (!info->line_out_hw_vol)
3494 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
3495 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3496 &private->dim_mute_ctls[i]->id);
3498 for (i = 0; i < num_line_out; i++)
3499 if (private->vol_sw_hw_switch[line_out_remap(private, i)])
3500 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3501 &private->mute_ctls[i]->id);
3504 /* Notify on "input other" change (level/pad/air) */
3505 static void scarlett2_notify_input_other(
3506 struct usb_mixer_interface *mixer)
3508 struct snd_card *card = mixer->chip->card;
3509 struct scarlett2_data *private = mixer->private_data;
3510 const struct scarlett2_device_info *info = private->info;
3513 private->input_other_updated = 1;
3515 for (i = 0; i < info->level_input_count; i++)
3516 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3517 &private->level_ctls[i]->id);
3518 for (i = 0; i < info->pad_input_count; i++)
3519 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3520 &private->pad_ctls[i]->id);
3521 for (i = 0; i < info->air_input_count; i++)
3522 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3523 &private->air_ctls[i]->id);
3524 for (i = 0; i < info->phantom_count; i++)
3525 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3526 &private->phantom_ctls[i]->id);
3529 /* Notify on "monitor other" change (direct monitor, speaker switching) */
3530 static void scarlett2_notify_monitor_other(
3531 struct usb_mixer_interface *mixer)
3533 struct snd_card *card = mixer->chip->card;
3534 struct scarlett2_data *private = mixer->private_data;
3535 const struct scarlett2_device_info *info = private->info;
3537 private->monitor_other_updated = 1;
3539 if (info->direct_monitor) {
3540 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3541 &private->direct_monitor_ctl->id);
3545 if (info->has_speaker_switching)
3546 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3547 &private->speaker_switching_ctl->id);
3549 /* if speaker switching was recently enabled or disabled,
3550 * invalidate the dim/mute and mux enum controls
3552 if (private->speaker_switching_switched) {
3555 scarlett2_notify_dim_mute(mixer);
3557 private->speaker_switching_switched = 0;
3558 private->mux_updated = 1;
3560 for (i = 0; i < private->num_mux_dsts; i++)
3561 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
3562 &private->mux_ctls[i]->id);
3566 /* Interrupt callback */
3567 static void scarlett2_notify(struct urb *urb)
3569 struct usb_mixer_interface *mixer = urb->context;
3570 int len = urb->actual_length;
3571 int ustatus = urb->status;
3574 if (ustatus != 0 || len != 8)
3577 data = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
3578 if (data & SCARLETT2_USB_NOTIFY_SYNC)
3579 scarlett2_notify_sync(mixer);
3580 if (data & SCARLETT2_USB_NOTIFY_MONITOR)
3581 scarlett2_notify_monitor(mixer);
3582 if (data & SCARLETT2_USB_NOTIFY_DIM_MUTE)
3583 scarlett2_notify_dim_mute(mixer);
3584 if (data & SCARLETT2_USB_NOTIFY_INPUT_OTHER)
3585 scarlett2_notify_input_other(mixer);
3586 if (data & SCARLETT2_USB_NOTIFY_MONITOR_OTHER)
3587 scarlett2_notify_monitor_other(mixer);
3590 if (ustatus != -ENOENT &&
3591 ustatus != -ECONNRESET &&
3592 ustatus != -ESHUTDOWN) {
3593 urb->dev = mixer->chip->dev;
3594 usb_submit_urb(urb, GFP_ATOMIC);
3598 static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
3600 struct usb_device *dev = mixer->chip->dev;
3601 struct scarlett2_data *private = mixer->private_data;
3602 unsigned int pipe = usb_rcvintpipe(dev, private->bEndpointAddress);
3603 void *transfer_buffer;
3606 usb_audio_err(mixer->chip,
3607 "%s: mixer urb already in use!\n", __func__);
3611 if (usb_pipe_type_check(dev, pipe))
3614 mixer->urb = usb_alloc_urb(0, GFP_KERNEL);
3618 transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
3619 if (!transfer_buffer)
3622 usb_fill_int_urb(mixer->urb, dev, pipe,
3623 transfer_buffer, private->wMaxPacketSize,
3624 scarlett2_notify, mixer, private->bInterval);
3626 return usb_submit_urb(mixer->urb, GFP_KERNEL);
3629 static int snd_scarlett_gen2_controls_create(struct usb_mixer_interface *mixer)
3631 const struct scarlett2_device_info **info = scarlett2_devices;
3634 /* Find device in scarlett2_devices */
3635 while (*info && (*info)->usb_id != mixer->chip->usb_id)
3640 /* Initialise private data */
3641 err = scarlett2_init_private(mixer, *info);
3645 /* Send proprietary USB initialisation sequence */
3646 err = scarlett2_usb_init(mixer);
3650 /* Read volume levels and controls from the interface */
3651 err = scarlett2_read_configs(mixer);
3655 /* Create the MSD control */
3656 err = scarlett2_add_msd_ctl(mixer);
3660 /* If MSD mode is enabled, don't create any other controls */
3661 if (((struct scarlett2_data *)mixer->private_data)->msd_switch)
3664 /* Create the analogue output controls */
3665 err = scarlett2_add_line_out_ctls(mixer);
3669 /* Create the analogue input controls */
3670 err = scarlett2_add_line_in_ctls(mixer);
3674 /* Create the input, output, and mixer mux input selections */
3675 err = scarlett2_add_mux_enums(mixer);
3679 /* Create the matrix mixer controls */
3680 err = scarlett2_add_mixer_ctls(mixer);
3684 /* Create the level meter controls */
3685 err = scarlett2_add_meter_ctl(mixer);
3689 /* Create the sync control */
3690 err = scarlett2_add_sync_ctl(mixer);
3694 /* Create the direct monitor control */
3695 err = scarlett2_add_direct_monitor_ctl(mixer);
3699 /* Create the speaker switching control */
3700 err = scarlett2_add_speaker_switch_ctl(mixer);
3704 /* Set up the interrupt polling */
3705 err = scarlett2_init_notify(mixer);
3712 int snd_scarlett_gen2_init(struct usb_mixer_interface *mixer)
3714 struct snd_usb_audio *chip = mixer->chip;
3717 /* only use UAC_VERSION_2 */
3718 if (!mixer->protocol)
3721 if (!(chip->setup & SCARLETT2_ENABLE)) {
3722 usb_audio_info(chip,
3723 "Focusrite Scarlett Gen 2/3 Mixer Driver disabled; "
3724 "use options snd_usb_audio vid=0x%04x pid=0x%04x "
3725 "device_setup=1 to enable and report any issues "
3727 USB_ID_VENDOR(chip->usb_id),
3728 USB_ID_PRODUCT(chip->usb_id));
3732 usb_audio_info(chip,
3733 "Focusrite Scarlett Gen 2/3 Mixer Driver enabled pid=0x%04x",
3734 USB_ID_PRODUCT(chip->usb_id));
3736 err = snd_scarlett_gen2_controls_create(mixer);
3738 usb_audio_err(mixer->chip,
3739 "Error initialising Scarlett Mixer Driver: %d",