1 // SPDX-License-Identifier: GPL-2.0
3 * Focusrite Scarlett 2 Protocol Driver for ALSA
4 * (including Scarlett 2nd Gen, 3rd Gen, Clarett USB, and Clarett+
8 * - 6i6/18i8/18i20 Gen 2
9 * - Solo/2i2/4i4/8i6/18i8/18i20 Gen 3
10 * - Clarett 2Pre/4Pre/8Pre USB
11 * - Clarett+ 2Pre/4Pre/8Pre
13 * Copyright (c) 2018-2023 by Geoffrey D. Bennett <g at b4.vu>
14 * Copyright (c) 2020-2021 by Vladimir Sadovnikov <sadko4u@gmail.com>
15 * Copyright (c) 2022 by Christian Colglazier <christian@cacolglazier.com>
17 * Based on the Scarlett (Gen 1) Driver for ALSA:
19 * Copyright (c) 2013 by Tobias Hoffmann
20 * Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
21 * Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
22 * Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
24 * Many codes borrowed from audio.c by
25 * Alan Cox (alan at lxorguk.ukuu.org.uk)
26 * Thomas Sailer (sailer at ife.ee.ethz.ch)
29 * David Henningsson <david.henningsson at canonical.com>
32 /* The protocol was reverse engineered by looking at the communication
33 * between Focusrite Control 2.3.4 and the Focusrite(R) Scarlett 18i20
34 * (firmware 1083) using usbmon in July-August 2018.
36 * Scarlett 18i8 support added in April 2019.
38 * Scarlett 6i6 support added in June 2019 (thanks to Martin Wittmann
39 * for providing usbmon output and testing).
41 * Scarlett 4i4/8i6 Gen 3 support added in May 2020 (thanks to Laurent
42 * Debricon for donating a 4i4 and to Fredrik Unger for providing 8i6
43 * usbmon output and testing).
45 * Scarlett 18i8/18i20 Gen 3 support added in June 2020 (thanks to
46 * Darren Jaeckel, Alex Sedlack, and Clovis Lunel for providing usbmon
47 * output, protocol traces and testing).
49 * Support for loading mixer volume and mux configuration from the
50 * interface during driver initialisation added in May 2021 (thanks to
51 * Vladimir Sadovnikov for figuring out how).
53 * Support for Solo/2i2 Gen 3 added in May 2021 (thanks to Alexander
54 * Vorona for 2i2 protocol traces).
56 * Support for phantom power, direct monitoring, speaker switching,
57 * and talkback added in May-June 2021.
59 * Support for Clarett+ 8Pre added in Aug 2022 by Christian
62 * Support for Clarett 8Pre USB added in Sep 2023 (thanks to Philippe
63 * Perrot for confirmation).
65 * Support for Clarett+ 4Pre and 2Pre added in Sep 2023 (thanks to
66 * Gregory Rozzo for donating a 4Pre, and David Sherwood and Patrice
67 * Peterson for usbmon output).
69 * Support for Clarett 2Pre and 4Pre USB added in Oct 2023.
71 * This ALSA mixer gives access to (model-dependent):
72 * - input, output, mixer-matrix muxes
73 * - mixer-matrix gain stages
74 * - gain/volume/mute controls
76 * - line/inst level, pad, and air controls
77 * - phantom power, direct monitor, speaker switching, and talkback
79 * - disable/enable MSD mode
80 * - disable/enable standalone mode
83 * /--------------\ 18chn 20chn /--------------\
84 * | Hardware in +--+------\ /-------------+--+ ALSA PCM out |
85 * \--------------/ | | | | \--------------/
89 * | +---------------+ | |
90 * | \ Matrix Mux / | |
97 * | +------------+ | |
101 * | | 18x10 Gain | | |
103 * | +-----+------+ | |
105 * |18chn |10chn | |20chn
110 * ===========================
111 * +---------------+ +--—------------+
112 * \ Output Mux / \ Capture Mux /
113 * +---+---+---+ +-----+-----+
117 * /--------------\ | | | /--------------\
118 * | S/PDIF, ADAT |<--/ |10chn \-->| ALSA PCM in |
119 * | Hardware out | | \--------------/
122 * +-------------+ Software gain per channel.
123 * | Master Gain |<-- 18i20 only: Switch per channel
124 * +------+------+ to select HW or SW gain control.
128 * | Analogue |<------/
133 * Gen 3 devices have a Mass Storage Device (MSD) mode where a small
134 * disk with registration and driver download information is presented
135 * to the host. To access the full functionality of the device without
136 * proprietary software, MSD mode can be disabled by:
137 * - holding down the 48V button for five seconds while powering on
139 * - using this driver and alsamixer to change the "MSD Mode" setting
140 * to Off and power-cycling the device
143 #include <linux/slab.h>
144 #include <linux/usb.h>
145 #include <linux/moduleparam.h>
147 #include <sound/control.h>
148 #include <sound/tlv.h>
149 #include <sound/hwdep.h>
151 #include <uapi/sound/scarlett2.h>
153 #include "usbaudio.h"
157 #include "mixer_scarlett2.h"
159 /* device_setup value to allow turning MSD mode back on */
160 #define SCARLETT2_MSD_ENABLE 0x02
162 /* device_setup value to disable this mixer driver */
163 #define SCARLETT2_DISABLE 0x04
165 /* some gui mixers can't handle negative ctl values */
166 #define SCARLETT2_VOLUME_BIAS 127
168 /* mixer range from -80dB to +6dB in 0.5dB steps */
169 #define SCARLETT2_MIXER_MIN_DB -80
170 #define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
171 #define SCARLETT2_MIXER_MAX_DB 6
172 #define SCARLETT2_MIXER_MAX_VALUE \
173 ((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
174 #define SCARLETT2_MIXER_VALUE_COUNT (SCARLETT2_MIXER_MAX_VALUE + 1)
176 /* map from (dB + 80) * 2 to mixer value
177 * for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20)))
179 static const u16 scarlett2_mixer_values[SCARLETT2_MIXER_VALUE_COUNT] = {
180 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
181 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
182 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
183 23, 24, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 46, 48, 51,
184 54, 57, 61, 65, 68, 73, 77, 81, 86, 91, 97, 103, 109, 115,
185 122, 129, 137, 145, 154, 163, 173, 183, 194, 205, 217, 230,
186 244, 259, 274, 290, 307, 326, 345, 365, 387, 410, 434, 460,
187 487, 516, 547, 579, 614, 650, 689, 730, 773, 819, 867, 919,
188 973, 1031, 1092, 1157, 1225, 1298, 1375, 1456, 1543, 1634,
189 1731, 1833, 1942, 2057, 2179, 2308, 2445, 2590, 2744, 2906,
190 3078, 3261, 3454, 3659, 3876, 4105, 4349, 4606, 4879, 5168,
191 5475, 5799, 6143, 6507, 6892, 7301, 7733, 8192, 8677, 9191,
192 9736, 10313, 10924, 11571, 12257, 12983, 13752, 14567, 15430,
196 /* Maximum number of analogue outputs */
197 #define SCARLETT2_ANALOGUE_MAX 10
199 /* Maximum number of level and pad switches */
200 #define SCARLETT2_LEVEL_SWITCH_MAX 2
201 #define SCARLETT2_PAD_SWITCH_MAX 8
202 #define SCARLETT2_AIR_SWITCH_MAX 8
203 #define SCARLETT2_PHANTOM_SWITCH_MAX 2
205 /* Maximum number of inputs to the mixer */
206 #define SCARLETT2_INPUT_MIX_MAX 25
208 /* Maximum number of outputs from the mixer */
209 #define SCARLETT2_OUTPUT_MIX_MAX 12
211 /* Maximum number of mixer gain controls */
212 #define SCARLETT2_MIX_MAX (SCARLETT2_INPUT_MIX_MAX * SCARLETT2_OUTPUT_MIX_MAX)
214 /* Maximum size of the data in the USB mux assignment message:
215 * 20 inputs, 20 outputs, 25 matrix inputs, 12 spare
217 #define SCARLETT2_MUX_MAX 77
219 /* Maximum number of sources (sum of input port counts) */
220 #define SCARLETT2_MAX_SRCS 52
222 /* Maximum number of meters (sum of output port counts) */
223 #define SCARLETT2_MAX_METERS 65
225 /* Hardware port types:
226 * - None (no input to mux)
234 SCARLETT2_PORT_TYPE_NONE,
235 SCARLETT2_PORT_TYPE_ANALOGUE,
236 SCARLETT2_PORT_TYPE_SPDIF,
237 SCARLETT2_PORT_TYPE_ADAT,
238 SCARLETT2_PORT_TYPE_MIX,
239 SCARLETT2_PORT_TYPE_PCM,
240 SCARLETT2_PORT_TYPE_COUNT
243 /* I/O count of each port type kept in struct scarlett2_ports */
250 /* Dim/Mute buttons on the 18i20 */
252 SCARLETT2_BUTTON_MUTE,
253 SCARLETT2_BUTTON_DIM,
254 SCARLETT2_DIM_MUTE_COUNT
257 /* Flash Write State */
259 SCARLETT2_FLASH_WRITE_STATE_IDLE,
260 SCARLETT2_FLASH_WRITE_STATE_SELECTED,
261 SCARLETT2_FLASH_WRITE_STATE_ERASING,
262 SCARLETT2_FLASH_WRITE_STATE_WRITE
265 static const char *const scarlett2_dim_mute_names[SCARLETT2_DIM_MUTE_COUNT] = {
266 "Mute Playback Switch", "Dim Playback Switch"
269 /* Notification callback functions */
270 struct scarlett2_notification {
272 void (*func)(struct usb_mixer_interface *mixer);
275 static void scarlett2_notify_sync(struct usb_mixer_interface *mixer);
276 static void scarlett2_notify_dim_mute(struct usb_mixer_interface *mixer);
277 static void scarlett2_notify_monitor(struct usb_mixer_interface *mixer);
278 static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer);
279 static void scarlett2_notify_monitor_other(struct usb_mixer_interface *mixer);
280 static void scarlett2_notify_direct_monitor(struct usb_mixer_interface *mixer);
282 /* Arrays of notification callback functions */
284 static const struct scarlett2_notification scarlett2_notifications[] = {
285 { 0x00000001, NULL }, /* ack, gets ignored */
286 { 0x00000008, scarlett2_notify_sync },
287 { 0x00200000, scarlett2_notify_dim_mute },
288 { 0x00400000, scarlett2_notify_monitor },
289 { 0x00800000, scarlett2_notify_input_other },
290 { 0x01000000, scarlett2_notify_monitor_other },
294 static const struct scarlett2_notification scarlett3a_notifications[] = {
295 { 0x00000001, NULL }, /* ack, gets ignored */
296 { 0x00800000, scarlett2_notify_input_other },
297 { 0x01000000, scarlett2_notify_direct_monitor },
301 /* Configuration parameters that can be read and written */
303 SCARLETT2_CONFIG_DIM_MUTE,
304 SCARLETT2_CONFIG_LINE_OUT_VOLUME,
305 SCARLETT2_CONFIG_MUTE_SWITCH,
306 SCARLETT2_CONFIG_SW_HW_SWITCH,
307 SCARLETT2_CONFIG_MASTER_VOLUME,
308 SCARLETT2_CONFIG_LEVEL_SWITCH,
309 SCARLETT2_CONFIG_PAD_SWITCH,
310 SCARLETT2_CONFIG_MSD_SWITCH,
311 SCARLETT2_CONFIG_AIR_SWITCH,
312 SCARLETT2_CONFIG_STANDALONE_SWITCH,
313 SCARLETT2_CONFIG_PHANTOM_SWITCH,
314 SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
315 SCARLETT2_CONFIG_DIRECT_MONITOR,
316 SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
317 SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
318 SCARLETT2_CONFIG_TALKBACK_MAP,
319 SCARLETT2_CONFIG_COUNT
322 /* Location, size, and activation command number for the configuration
323 * parameters. Size is in bits and may be 1, 8, or 16.
325 struct scarlett2_config {
331 struct scarlett2_config_set {
332 const struct scarlett2_notification *notifications;
333 const struct scarlett2_config items[SCARLETT2_CONFIG_COUNT];
336 /* Gen 2 devices without SW/HW volume switch: 6i6, 18i8 */
338 static const struct scarlett2_config_set scarlett2_config_set_gen2a = {
339 .notifications = scarlett2_notifications,
341 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
342 .offset = 0x34, .size = 16, .activate = 1 },
344 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
345 .offset = 0x5c, .size = 8, .activate = 1 },
347 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
348 .offset = 0x7c, .size = 8, .activate = 7 },
350 [SCARLETT2_CONFIG_PAD_SWITCH] = {
351 .offset = 0x84, .size = 8, .activate = 8 },
353 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
354 .offset = 0x8d, .size = 8, .activate = 6 },
358 /* Gen 2 devices with SW/HW volume switch: 18i20 */
360 static const struct scarlett2_config_set scarlett2_config_set_gen2b = {
361 .notifications = scarlett2_notifications,
363 [SCARLETT2_CONFIG_DIM_MUTE] = {
364 .offset = 0x31, .size = 8, .activate = 2 },
366 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
367 .offset = 0x34, .size = 16, .activate = 1 },
369 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
370 .offset = 0x5c, .size = 8, .activate = 1 },
372 [SCARLETT2_CONFIG_SW_HW_SWITCH] = {
373 .offset = 0x66, .size = 8, .activate = 3 },
375 [SCARLETT2_CONFIG_MASTER_VOLUME] = {
376 .offset = 0x76, .size = 16 },
378 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
379 .offset = 0x7c, .size = 8, .activate = 7 },
381 [SCARLETT2_CONFIG_PAD_SWITCH] = {
382 .offset = 0x84, .size = 8, .activate = 8 },
384 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
385 .offset = 0x8d, .size = 8, .activate = 6 },
389 /* Gen 3 devices without a mixer (Solo and 2i2) */
390 static const struct scarlett2_config_set scarlett2_config_set_gen3a = {
391 .notifications = scarlett3a_notifications,
393 [SCARLETT2_CONFIG_MSD_SWITCH] = {
394 .offset = 0x04, .size = 8, .activate = 6 },
396 [SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
397 .offset = 0x05, .size = 8, .activate = 6 },
399 [SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
400 .offset = 0x06, .size = 8, .activate = 3 },
402 [SCARLETT2_CONFIG_DIRECT_MONITOR] = {
403 .offset = 0x07, .size = 8, .activate = 4 },
405 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
406 .offset = 0x08, .size = 1, .activate = 7 },
408 [SCARLETT2_CONFIG_AIR_SWITCH] = {
409 .offset = 0x09, .size = 1, .activate = 8 },
413 /* Gen 3 devices without SW/HW volume switch: 4i4, 8i6 */
414 static const struct scarlett2_config_set scarlett2_config_set_gen3b = {
415 .notifications = scarlett2_notifications,
417 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
418 .offset = 0x34, .size = 16, .activate = 1 },
420 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
421 .offset = 0x5c, .size = 8, .activate = 1 },
423 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
424 .offset = 0x7c, .size = 8, .activate = 7 },
426 [SCARLETT2_CONFIG_PAD_SWITCH] = {
427 .offset = 0x84, .size = 8, .activate = 8 },
429 [SCARLETT2_CONFIG_AIR_SWITCH] = {
430 .offset = 0x8c, .size = 8, .activate = 8 },
432 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
433 .offset = 0x95, .size = 8, .activate = 6 },
435 [SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
436 .offset = 0x9c, .size = 1, .activate = 8 },
438 [SCARLETT2_CONFIG_MSD_SWITCH] = {
439 .offset = 0x9d, .size = 8, .activate = 6 },
441 [SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
442 .offset = 0x9e, .size = 8, .activate = 6 },
446 /* Gen 3 devices with SW/HW volume switch: 18i8, 18i20 */
447 static const struct scarlett2_config_set scarlett2_config_set_gen3c = {
448 .notifications = scarlett2_notifications,
450 [SCARLETT2_CONFIG_DIM_MUTE] = {
451 .offset = 0x31, .size = 8, .activate = 2 },
453 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
454 .offset = 0x34, .size = 16, .activate = 1 },
456 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
457 .offset = 0x5c, .size = 8, .activate = 1 },
459 [SCARLETT2_CONFIG_SW_HW_SWITCH] = {
460 .offset = 0x66, .size = 8, .activate = 3 },
462 [SCARLETT2_CONFIG_MASTER_VOLUME] = {
463 .offset = 0x76, .size = 16 },
465 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
466 .offset = 0x7c, .size = 8, .activate = 7 },
468 [SCARLETT2_CONFIG_PAD_SWITCH] = {
469 .offset = 0x84, .size = 8, .activate = 8 },
471 [SCARLETT2_CONFIG_AIR_SWITCH] = {
472 .offset = 0x8c, .size = 8, .activate = 8 },
474 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
475 .offset = 0x95, .size = 8, .activate = 6 },
477 [SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
478 .offset = 0x9c, .size = 1, .activate = 8 },
480 [SCARLETT2_CONFIG_MSD_SWITCH] = {
481 .offset = 0x9d, .size = 8, .activate = 6 },
483 [SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
484 .offset = 0x9e, .size = 8, .activate = 6 },
486 [SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH] = {
487 .offset = 0x9f, .size = 1, .activate = 10 },
489 [SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE] = {
490 .offset = 0xa0, .size = 1, .activate = 10 },
492 [SCARLETT2_CONFIG_TALKBACK_MAP] = {
493 .offset = 0xb0, .size = 16, .activate = 10 },
497 /* Clarett USB and Clarett+ devices: 2Pre, 4Pre, 8Pre */
498 static const struct scarlett2_config_set scarlett2_config_set_clarett = {
499 .notifications = scarlett2_notifications,
501 [SCARLETT2_CONFIG_DIM_MUTE] = {
502 .offset = 0x31, .size = 8, .activate = 2 },
504 [SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
505 .offset = 0x34, .size = 16, .activate = 1 },
507 [SCARLETT2_CONFIG_MUTE_SWITCH] = {
508 .offset = 0x5c, .size = 8, .activate = 1 },
510 [SCARLETT2_CONFIG_SW_HW_SWITCH] = {
511 .offset = 0x66, .size = 8, .activate = 3 },
513 [SCARLETT2_CONFIG_MASTER_VOLUME] = {
514 .offset = 0x76, .size = 16 },
516 [SCARLETT2_CONFIG_LEVEL_SWITCH] = {
517 .offset = 0x7c, .size = 8, .activate = 7 },
519 [SCARLETT2_CONFIG_AIR_SWITCH] = {
520 .offset = 0x95, .size = 8, .activate = 8 },
522 [SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
523 .offset = 0x8d, .size = 8, .activate = 6 },
527 /* Description of each hardware port type:
528 * - id: hardware ID of this port type
529 * - src_descr: printf format string for mux input selections
530 * - src_num_offset: added to channel number for the fprintf
531 * - dst_descr: printf format string for mixer controls
533 struct scarlett2_port {
535 const char * const src_descr;
537 const char * const dst_descr;
540 static const struct scarlett2_port scarlett2_ports[SCARLETT2_PORT_TYPE_COUNT] = {
541 [SCARLETT2_PORT_TYPE_NONE] = {
545 [SCARLETT2_PORT_TYPE_ANALOGUE] = {
547 .src_descr = "Analogue %d",
549 .dst_descr = "Analogue Output %02d Playback"
551 [SCARLETT2_PORT_TYPE_SPDIF] = {
553 .src_descr = "S/PDIF %d",
555 .dst_descr = "S/PDIF Output %d Playback"
557 [SCARLETT2_PORT_TYPE_ADAT] = {
559 .src_descr = "ADAT %d",
561 .dst_descr = "ADAT Output %d Playback"
563 [SCARLETT2_PORT_TYPE_MIX] = {
565 .src_descr = "Mix %c",
566 .src_num_offset = 'A',
567 .dst_descr = "Mixer Input %02d Capture"
569 [SCARLETT2_PORT_TYPE_PCM] = {
571 .src_descr = "PCM %d",
573 .dst_descr = "PCM %02d Capture"
577 /* Number of mux tables: one for each band of sample rates
578 * (44.1/48kHz, 88.2/96kHz, and 176.4/176kHz)
580 #define SCARLETT2_MUX_TABLES 3
582 /* Maximum number of entries in a mux table */
583 #define SCARLETT2_MAX_MUX_ENTRIES 10
585 /* One entry within mux_assignment defines the port type and range of
586 * ports to add to the set_mux message. The end of the list is marked
589 struct scarlett2_mux_entry {
595 /* Maximum number of entries in a mux table */
596 #define SCARLETT2_MAX_METER_ENTRIES 9
598 /* One entry within meter_assignment defines the range of mux outputs
599 * that consecutive meter entries are mapped to. The end of the list
600 * is marked with count == 0.
602 struct scarlett2_meter_entry {
607 struct scarlett2_device_info {
608 /* which set of configuration parameters the device uses */
609 const struct scarlett2_config_set *config_set;
611 /* support for main/alt speaker switching */
612 u8 has_speaker_switching;
614 /* support for talkback microphone */
617 /* the number of analogue inputs with a software switchable
618 * level control that can be set to line or instrument
620 u8 level_input_count;
622 /* the first input with a level control (0-based) */
623 u8 level_input_first;
625 /* the number of analogue inputs with a software switchable
630 /* the number of analogue inputs with a software switchable
635 /* the number of phantom (48V) software switchable controls */
638 /* the number of inputs each phantom switch controls */
639 u8 inputs_per_phantom;
641 /* the number of direct monitor options
642 * (0 = none, 1 = mono only, 2 = mono/stereo)
646 /* remap analogue outputs; 18i8 Gen 3 has "line 3/4" connected
647 * internally to the analogue 7/8 outputs
649 u8 line_out_remap_enable;
650 u8 line_out_remap[SCARLETT2_ANALOGUE_MAX];
651 u8 line_out_unmap[SCARLETT2_ANALOGUE_MAX];
653 /* additional description for the line out volume controls */
654 const char * const line_out_descrs[SCARLETT2_ANALOGUE_MAX];
656 /* number of sources/destinations of each port type */
657 const int port_count[SCARLETT2_PORT_TYPE_COUNT][SCARLETT2_PORT_DIRNS];
659 /* layout/order of the entries in the set_mux message */
660 struct scarlett2_mux_entry mux_assignment[SCARLETT2_MUX_TABLES]
661 [SCARLETT2_MAX_MUX_ENTRIES];
663 /* map from meter level order returned by
664 * SCARLETT2_USB_GET_METER to index into mux[] entries (same
665 * as the order returned by scarlett2_meter_ctl_get())
667 struct scarlett2_meter_entry meter_map[SCARLETT2_MAX_METER_ENTRIES];
670 struct scarlett2_data {
671 struct usb_mixer_interface *mixer;
672 struct mutex usb_mutex; /* prevent sending concurrent USB requests */
673 struct mutex data_mutex; /* lock access to this data */
675 u8 selected_flash_segment_id;
676 u8 flash_write_state;
677 struct delayed_work work;
678 const struct scarlett2_device_info *info;
679 const struct scarlett2_config_set *config_set;
680 const char *series_name;
681 __u8 bInterfaceNumber;
682 __u8 bEndpointAddress;
683 __u16 wMaxPacketSize;
690 u32 firmware_version;
691 u8 flash_segment_nums[SCARLETT2_SEGMENT_ID_COUNT];
692 u8 flash_segment_blocks[SCARLETT2_SEGMENT_ID_COUNT];
697 u8 input_level_updated;
698 u8 input_pad_updated;
699 u8 input_air_updated;
700 u8 input_phantom_updated;
701 u8 monitor_other_updated;
702 u8 direct_monitor_updated;
704 u8 speaker_switching_switched;
707 u8 vol[SCARLETT2_ANALOGUE_MAX];
708 u8 vol_sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
709 u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
710 u8 level_switch[SCARLETT2_LEVEL_SWITCH_MAX];
711 u8 pad_switch[SCARLETT2_PAD_SWITCH_MAX];
712 u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
713 u8 air_switch[SCARLETT2_AIR_SWITCH_MAX];
714 u8 phantom_switch[SCARLETT2_PHANTOM_SWITCH_MAX];
715 u8 phantom_persistence;
716 u8 direct_monitor_switch;
717 u8 speaker_switching_switch;
719 u8 talkback_map[SCARLETT2_OUTPUT_MIX_MAX];
721 u8 standalone_switch;
722 u8 meter_level_map[SCARLETT2_MAX_METERS];
723 struct snd_kcontrol *sync_ctl;
724 struct snd_kcontrol *master_vol_ctl;
725 struct snd_kcontrol *vol_ctls[SCARLETT2_ANALOGUE_MAX];
726 struct snd_kcontrol *sw_hw_ctls[SCARLETT2_ANALOGUE_MAX];
727 struct snd_kcontrol *mute_ctls[SCARLETT2_ANALOGUE_MAX];
728 struct snd_kcontrol *dim_mute_ctls[SCARLETT2_DIM_MUTE_COUNT];
729 struct snd_kcontrol *level_ctls[SCARLETT2_LEVEL_SWITCH_MAX];
730 struct snd_kcontrol *pad_ctls[SCARLETT2_PAD_SWITCH_MAX];
731 struct snd_kcontrol *air_ctls[SCARLETT2_AIR_SWITCH_MAX];
732 struct snd_kcontrol *phantom_ctls[SCARLETT2_PHANTOM_SWITCH_MAX];
733 struct snd_kcontrol *mux_ctls[SCARLETT2_MUX_MAX];
734 struct snd_kcontrol *direct_monitor_ctl;
735 struct snd_kcontrol *speaker_switching_ctl;
736 struct snd_kcontrol *talkback_ctl;
737 u8 mux[SCARLETT2_MUX_MAX];
738 u8 mix[SCARLETT2_MIX_MAX];
741 /*** Model-specific data ***/
743 static const struct scarlett2_device_info s6i6_gen2_info = {
744 .config_set = &scarlett2_config_set_gen2a,
745 .level_input_count = 2,
746 .pad_input_count = 2,
756 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
757 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
758 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
759 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
760 [SCARLETT2_PORT_TYPE_PCM] = { 6, 6 },
763 .mux_assignment = { {
764 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
765 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
766 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
767 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
768 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
771 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
772 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
773 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
774 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
775 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
778 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
779 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
780 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
781 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
782 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
793 static const struct scarlett2_device_info s18i8_gen2_info = {
794 .config_set = &scarlett2_config_set_gen2a,
795 .level_input_count = 2,
796 .pad_input_count = 4,
808 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
809 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
810 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
811 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
812 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
813 [SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
816 .mux_assignment = { {
817 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
818 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
819 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
820 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
821 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
824 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
825 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
826 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
827 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
828 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
831 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
832 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
833 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
834 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
835 { SCARLETT2_PORT_TYPE_NONE, 0, 4 },
846 static const struct scarlett2_device_info s18i20_gen2_info = {
847 .config_set = &scarlett2_config_set_gen2b,
863 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
864 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
865 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
866 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
867 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
868 [SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
871 .mux_assignment = { {
872 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
873 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
874 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
875 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
876 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
877 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
880 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
881 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
882 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
883 { SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
884 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
885 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
888 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
889 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
890 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
891 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
892 { SCARLETT2_PORT_TYPE_NONE, 0, 6 },
903 static const struct scarlett2_device_info solo_gen3_info = {
904 .config_set = &scarlett2_config_set_gen3a,
905 .level_input_count = 1,
906 .level_input_first = 1,
907 .air_input_count = 1,
909 .inputs_per_phantom = 1,
913 static const struct scarlett2_device_info s2i2_gen3_info = {
914 .config_set = &scarlett2_config_set_gen3a,
915 .level_input_count = 2,
916 .air_input_count = 2,
918 .inputs_per_phantom = 2,
922 static const struct scarlett2_device_info s4i4_gen3_info = {
923 .config_set = &scarlett2_config_set_gen3b,
924 .level_input_count = 2,
925 .pad_input_count = 2,
926 .air_input_count = 2,
928 .inputs_per_phantom = 2,
938 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
939 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
940 [SCARLETT2_PORT_TYPE_MIX] = { 6, 8 },
941 [SCARLETT2_PORT_TYPE_PCM] = { 4, 6 },
944 .mux_assignment = { {
945 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
946 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
947 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
948 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
951 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
952 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
953 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
954 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
957 { SCARLETT2_PORT_TYPE_PCM, 0, 6 },
958 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
959 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
960 { SCARLETT2_PORT_TYPE_NONE, 0, 16 },
971 static const struct scarlett2_device_info s8i6_gen3_info = {
972 .config_set = &scarlett2_config_set_gen3b,
973 .level_input_count = 2,
974 .pad_input_count = 2,
975 .air_input_count = 2,
977 .inputs_per_phantom = 2,
987 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
988 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 6, 4 },
989 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
990 [SCARLETT2_PORT_TYPE_MIX] = { 8, 8 },
991 [SCARLETT2_PORT_TYPE_PCM] = { 6, 10 },
994 .mux_assignment = { {
995 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
996 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
997 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
998 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
999 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
1000 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
1003 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
1004 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
1005 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1006 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
1007 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
1008 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
1011 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
1012 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
1013 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1014 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
1015 { SCARLETT2_PORT_TYPE_MIX, 0, 8 },
1016 { SCARLETT2_PORT_TYPE_NONE, 0, 18 },
1029 static const struct scarlett2_device_info s18i8_gen3_info = {
1030 .config_set = &scarlett2_config_set_gen3c,
1031 .has_speaker_switching = 1,
1032 .level_input_count = 2,
1033 .pad_input_count = 4,
1034 .air_input_count = 4,
1036 .inputs_per_phantom = 2,
1038 .line_out_remap_enable = 1,
1039 .line_out_remap = { 0, 1, 6, 7, 2, 3, 4, 5 },
1040 .line_out_unmap = { 0, 1, 4, 5, 6, 7, 2, 3 },
1042 .line_out_descrs = {
1054 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
1055 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 8 },
1056 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
1057 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
1058 [SCARLETT2_PORT_TYPE_MIX] = { 10, 20 },
1059 [SCARLETT2_PORT_TYPE_PCM] = { 8, 20 },
1062 .mux_assignment = { {
1063 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
1064 { SCARLETT2_PORT_TYPE_PCM, 12, 8 },
1065 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
1066 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
1067 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
1068 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1069 { SCARLETT2_PORT_TYPE_PCM, 10, 2 },
1070 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
1071 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
1074 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
1075 { SCARLETT2_PORT_TYPE_PCM, 12, 4 },
1076 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
1077 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
1078 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
1079 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1080 { SCARLETT2_PORT_TYPE_PCM, 10, 2 },
1081 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
1082 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
1085 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
1086 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
1087 { SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
1088 { SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
1089 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1090 { SCARLETT2_PORT_TYPE_MIX, 0, 20 },
1091 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
1108 static const struct scarlett2_device_info s18i20_gen3_info = {
1109 .config_set = &scarlett2_config_set_gen3c,
1110 .has_speaker_switching = 1,
1112 .level_input_count = 2,
1113 .pad_input_count = 8,
1114 .air_input_count = 8,
1116 .inputs_per_phantom = 4,
1118 .line_out_descrs = {
1132 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
1133 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 9, 10 },
1134 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
1135 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
1136 [SCARLETT2_PORT_TYPE_MIX] = { 12, 25 },
1137 [SCARLETT2_PORT_TYPE_PCM] = { 20, 20 },
1140 .mux_assignment = { {
1141 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
1142 { SCARLETT2_PORT_TYPE_PCM, 10, 10 },
1143 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1144 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1145 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
1146 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
1147 { SCARLETT2_PORT_TYPE_MIX, 0, 25 },
1148 { SCARLETT2_PORT_TYPE_NONE, 0, 12 },
1151 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
1152 { SCARLETT2_PORT_TYPE_PCM, 10, 8 },
1153 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1154 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1155 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
1156 { SCARLETT2_PORT_TYPE_PCM, 8, 2 },
1157 { SCARLETT2_PORT_TYPE_MIX, 0, 25 },
1158 { SCARLETT2_PORT_TYPE_NONE, 0, 10 },
1161 { SCARLETT2_PORT_TYPE_PCM, 0, 10 },
1162 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1163 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1164 { SCARLETT2_PORT_TYPE_NONE, 0, 24 },
1178 static const struct scarlett2_device_info clarett_2pre_info = {
1179 .config_set = &scarlett2_config_set_clarett,
1180 .level_input_count = 2,
1181 .air_input_count = 2,
1183 .line_out_descrs = {
1191 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
1192 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 4 },
1193 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 0 },
1194 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
1195 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
1196 [SCARLETT2_PORT_TYPE_PCM] = { 4, 12 },
1199 .mux_assignment = { {
1200 { SCARLETT2_PORT_TYPE_PCM, 0, 12 },
1201 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
1202 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1203 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1206 { SCARLETT2_PORT_TYPE_PCM, 0, 8 },
1207 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
1208 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1209 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1212 { SCARLETT2_PORT_TYPE_PCM, 0, 2 },
1213 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
1214 { SCARLETT2_PORT_TYPE_NONE, 0, 26 },
1225 static const struct scarlett2_device_info clarett_4pre_info = {
1226 .config_set = &scarlett2_config_set_clarett,
1227 .level_input_count = 2,
1228 .air_input_count = 4,
1230 .line_out_descrs = {
1240 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
1241 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
1242 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
1243 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
1244 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
1245 [SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
1248 .mux_assignment = { {
1249 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
1250 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
1251 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1252 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1253 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1256 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
1257 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
1258 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1259 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1260 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1263 { SCARLETT2_PORT_TYPE_PCM, 0, 12 },
1264 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
1265 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1266 { SCARLETT2_PORT_TYPE_NONE, 0, 24 },
1277 static const struct scarlett2_device_info clarett_8pre_info = {
1278 .config_set = &scarlett2_config_set_clarett,
1279 .level_input_count = 2,
1280 .air_input_count = 8,
1282 .line_out_descrs = {
1296 [SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
1297 [SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
1298 [SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
1299 [SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
1300 [SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
1301 [SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
1304 .mux_assignment = { {
1305 { SCARLETT2_PORT_TYPE_PCM, 0, 18 },
1306 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1307 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1308 { SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
1309 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1310 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1313 { SCARLETT2_PORT_TYPE_PCM, 0, 14 },
1314 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1315 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1316 { SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
1317 { SCARLETT2_PORT_TYPE_MIX, 0, 18 },
1318 { SCARLETT2_PORT_TYPE_NONE, 0, 8 },
1321 { SCARLETT2_PORT_TYPE_PCM, 0, 12 },
1322 { SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
1323 { SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
1324 { SCARLETT2_PORT_TYPE_NONE, 0, 22 },
1335 struct scarlett2_device_entry {
1336 const u32 usb_id; /* USB device identifier */
1337 const struct scarlett2_device_info *info;
1338 const char *series_name;
1341 static const struct scarlett2_device_entry scarlett2_devices[] = {
1342 /* Supported Gen 2 devices */
1343 { USB_ID(0x1235, 0x8203), &s6i6_gen2_info, "Scarlett Gen 2" },
1344 { USB_ID(0x1235, 0x8204), &s18i8_gen2_info, "Scarlett Gen 2" },
1345 { USB_ID(0x1235, 0x8201), &s18i20_gen2_info, "Scarlett Gen 2" },
1347 /* Supported Gen 3 devices */
1348 { USB_ID(0x1235, 0x8211), &solo_gen3_info, "Scarlett Gen 3" },
1349 { USB_ID(0x1235, 0x8210), &s2i2_gen3_info, "Scarlett Gen 3" },
1350 { USB_ID(0x1235, 0x8212), &s4i4_gen3_info, "Scarlett Gen 3" },
1351 { USB_ID(0x1235, 0x8213), &s8i6_gen3_info, "Scarlett Gen 3" },
1352 { USB_ID(0x1235, 0x8214), &s18i8_gen3_info, "Scarlett Gen 3" },
1353 { USB_ID(0x1235, 0x8215), &s18i20_gen3_info, "Scarlett Gen 3" },
1355 /* Supported Clarett USB/Clarett+ devices */
1356 { USB_ID(0x1235, 0x8206), &clarett_2pre_info, "Clarett USB" },
1357 { USB_ID(0x1235, 0x8207), &clarett_4pre_info, "Clarett USB" },
1358 { USB_ID(0x1235, 0x8208), &clarett_8pre_info, "Clarett USB" },
1359 { USB_ID(0x1235, 0x820a), &clarett_2pre_info, "Clarett+" },
1360 { USB_ID(0x1235, 0x820b), &clarett_4pre_info, "Clarett+" },
1361 { USB_ID(0x1235, 0x820c), &clarett_8pre_info, "Clarett+" },
1367 /* get the starting port index number for a given port type/direction */
1368 static int scarlett2_get_port_start_num(
1369 const int port_count[][SCARLETT2_PORT_DIRNS],
1370 int direction, int port_type)
1374 for (i = 0; i < port_type; i++)
1375 num += port_count[i][direction];
1380 /*** USB Interactions ***/
1382 /* Commands for sending/receiving requests/responses */
1383 #define SCARLETT2_USB_CMD_INIT 0
1384 #define SCARLETT2_USB_CMD_REQ 2
1385 #define SCARLETT2_USB_CMD_RESP 3
1387 #define SCARLETT2_USB_INIT_1 0x00000000
1388 #define SCARLETT2_USB_INIT_2 0x00000002
1389 #define SCARLETT2_USB_REBOOT 0x00000003
1390 #define SCARLETT2_USB_GET_METER 0x00001001
1391 #define SCARLETT2_USB_GET_MIX 0x00002001
1392 #define SCARLETT2_USB_SET_MIX 0x00002002
1393 #define SCARLETT2_USB_GET_MUX 0x00003001
1394 #define SCARLETT2_USB_SET_MUX 0x00003002
1395 #define SCARLETT2_USB_INFO_FLASH 0x00004000
1396 #define SCARLETT2_USB_INFO_SEGMENT 0x00004001
1397 #define SCARLETT2_USB_ERASE_SEGMENT 0x00004002
1398 #define SCARLETT2_USB_GET_ERASE 0x00004003
1399 #define SCARLETT2_USB_WRITE_SEGMENT 0x00004004
1400 #define SCARLETT2_USB_GET_SYNC 0x00006004
1401 #define SCARLETT2_USB_GET_DATA 0x00800000
1402 #define SCARLETT2_USB_SET_DATA 0x00800001
1403 #define SCARLETT2_USB_DATA_CMD 0x00800002
1405 #define SCARLETT2_USB_CONFIG_SAVE 6
1407 #define SCARLETT2_USB_METER_LEVELS_GET_MAGIC 1
1409 #define SCARLETT2_FLASH_BLOCK_SIZE 4096
1410 #define SCARLETT2_FLASH_WRITE_MAX 1024
1411 #define SCARLETT2_SEGMENT_NUM_MIN 1
1412 #define SCARLETT2_SEGMENT_NUM_MAX 4
1414 #define SCARLETT2_SEGMENT_SETTINGS_NAME "App_Settings"
1415 #define SCARLETT2_SEGMENT_FIRMWARE_NAME "App_Upgrade"
1417 /* proprietary request/response format */
1418 struct scarlett2_usb_packet {
1427 static void scarlett2_fill_request_header(struct scarlett2_data *private,
1428 struct scarlett2_usb_packet *req,
1429 u32 cmd, u16 req_size)
1431 /* sequence must go up by 1 for each request */
1432 u16 seq = private->scarlett2_seq++;
1434 req->cmd = cpu_to_le32(cmd);
1435 req->size = cpu_to_le16(req_size);
1436 req->seq = cpu_to_le16(seq);
1441 static int scarlett2_usb_tx(struct usb_device *dev, int interface,
1442 void *buf, u16 size)
1444 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
1445 SCARLETT2_USB_CMD_REQ,
1446 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
1447 0, interface, buf, size);
1450 static int scarlett2_usb_rx(struct usb_device *dev, int interface,
1451 u32 usb_req, void *buf, u16 size)
1453 return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
1455 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
1456 0, interface, buf, size);
1459 /* Send a proprietary format request to the Scarlett interface */
1460 static int scarlett2_usb(
1461 struct usb_mixer_interface *mixer, u32 cmd,
1462 void *req_data, u16 req_size, void *resp_data, u16 resp_size)
1464 struct scarlett2_data *private = mixer->private_data;
1465 struct usb_device *dev = mixer->chip->dev;
1466 struct scarlett2_usb_packet *req, *resp = NULL;
1467 size_t req_buf_size = struct_size(req, data, req_size);
1468 size_t resp_buf_size = struct_size(resp, data, resp_size);
1471 req = kmalloc(req_buf_size, GFP_KERNEL);
1477 resp = kmalloc(resp_buf_size, GFP_KERNEL);
1483 mutex_lock(&private->usb_mutex);
1485 /* build request message and send it */
1487 scarlett2_fill_request_header(private, req, cmd, req_size);
1490 memcpy(req->data, req_data, req_size);
1492 err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
1495 if (err != req_buf_size) {
1498 "%s USB request result cmd %x was %d\n",
1499 private->series_name, cmd, err);
1504 /* send a second message to get the response */
1506 err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
1507 SCARLETT2_USB_CMD_RESP,
1508 resp, resp_buf_size);
1510 /* validate the response */
1512 if (err != resp_buf_size) {
1514 /* ESHUTDOWN and EPROTO are valid responses to a
1517 if (cmd == SCARLETT2_USB_REBOOT &&
1518 (err == -ESHUTDOWN || err == -EPROTO)) {
1525 "%s USB response result cmd %x was %d expected %zu\n",
1526 private->series_name, cmd, err, resp_buf_size);
1531 /* cmd/seq/size should match except when initialising
1532 * seq sent = 1, response = 0
1534 if (resp->cmd != req->cmd ||
1535 (resp->seq != req->seq &&
1536 (le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
1537 resp_size != le16_to_cpu(resp->size) ||
1542 "%s USB invalid response; "
1543 "cmd tx/rx %d/%d seq %d/%d size %d/%d "
1544 "error %d pad %d\n",
1545 private->series_name,
1546 le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
1547 le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
1548 resp_size, le16_to_cpu(resp->size),
1549 le32_to_cpu(resp->error),
1550 le32_to_cpu(resp->pad));
1555 if (resp_data && resp_size > 0)
1556 memcpy(resp_data, resp->data, resp_size);
1559 mutex_unlock(&private->usb_mutex);
1566 /* Send a USB message to get data; result placed in *buf */
1567 static int scarlett2_usb_get(
1568 struct usb_mixer_interface *mixer,
1569 int offset, void *buf, int size)
1576 req.offset = cpu_to_le32(offset);
1577 req.size = cpu_to_le32(size);
1578 return scarlett2_usb(mixer, SCARLETT2_USB_GET_DATA,
1579 &req, sizeof(req), buf, size);
1582 /* Return true if the given configuration item is present in the
1583 * configuration set used by this device.
1585 static int scarlett2_has_config_item(
1586 struct scarlett2_data *private, int config_item_num)
1588 return !!private->config_set->items[config_item_num].offset;
1591 /* Send a USB message to get configuration parameters; result placed in *buf */
1592 static int scarlett2_usb_get_config(
1593 struct usb_mixer_interface *mixer,
1594 int config_item_num, int count, void *buf)
1596 struct scarlett2_data *private = mixer->private_data;
1597 const struct scarlett2_config *config_item =
1598 &private->config_set->items[config_item_num];
1603 /* Check that the configuration item is present in the
1604 * configuration set used by this device
1606 if (!config_item->offset)
1609 /* For byte-sized parameters, retrieve directly into buf */
1610 if (config_item->size >= 8) {
1611 size = config_item->size / 8 * count;
1612 err = scarlett2_usb_get(mixer, config_item->offset, buf, size);
1618 for (i = 0; i < count; i++, buf_16++)
1619 *buf_16 = le16_to_cpu(*(__le16 *)buf_16);
1624 /* For bit-sized parameters, retrieve into value */
1625 err = scarlett2_usb_get(mixer, config_item->offset, &value, 1);
1629 /* then unpack from value into buf[] */
1631 for (i = 0; i < 8 && i < count; i++, value >>= 1)
1632 *buf_8++ = value & 1;
1637 /* Send a SCARLETT2_USB_SET_DATA command.
1638 * offset: location in the device's data space
1639 * size: size in bytes of the value (1, 2, 4)
1641 static int scarlett2_usb_set_data(
1642 struct usb_mixer_interface *mixer,
1643 int offset, int size, int value)
1645 struct scarlett2_data *private = mixer->private_data;
1652 req.offset = cpu_to_le32(offset);
1653 req.size = cpu_to_le32(size);
1654 req.value = cpu_to_le32(value);
1655 return scarlett2_usb(private->mixer, SCARLETT2_USB_SET_DATA,
1656 &req, sizeof(u32) * 2 + size, NULL, 0);
1659 /* Send a SCARLETT2_USB_DATA_CMD command.
1660 * Configuration changes require activation with this after they have
1661 * been uploaded by a previous SCARLETT2_USB_SET_DATA.
1662 * The value for activate needed is determined by the configuration
1665 static int scarlett2_usb_activate_config(
1666 struct usb_mixer_interface *mixer, int activate)
1670 req = cpu_to_le32(activate);
1671 return scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
1672 &req, sizeof(req), NULL, 0);
1675 /* Send USB messages to set a SCARLETT2_CONFIG_* parameter */
1676 static int scarlett2_usb_set_config(
1677 struct usb_mixer_interface *mixer,
1678 int config_item_num, int index, int value)
1680 struct scarlett2_data *private = mixer->private_data;
1681 const struct scarlett2_config *config_item =
1682 &private->config_set->items[config_item_num];
1686 /* Check that the configuration item is present in the
1687 * configuration set used by this device
1689 if (!config_item->offset)
1692 /* Cancel any pending NVRAM save */
1693 cancel_delayed_work_sync(&private->work);
1695 /* Convert config_item->size in bits to size in bytes and
1698 if (config_item->size >= 8) {
1699 size = config_item->size / 8;
1700 offset = config_item->offset + index * size;
1702 /* If updating a bit, retrieve the old value, set/clear the
1703 * bit as needed, and update value
1709 offset = config_item->offset;
1711 err = scarlett2_usb_get(mixer, offset, &tmp, 1);
1716 tmp |= (1 << index);
1718 tmp &= ~(1 << index);
1723 /* Send the configuration parameter data */
1724 err = scarlett2_usb_set_data(mixer, offset, size, value);
1728 /* Activate the change */
1729 err = scarlett2_usb_activate_config(mixer, config_item->activate);
1733 /* Schedule the change to be written to NVRAM */
1734 if (config_item->activate != SCARLETT2_USB_CONFIG_SAVE)
1735 schedule_delayed_work(&private->work, msecs_to_jiffies(2000));
1740 /* Send SCARLETT2_USB_DATA_CMD SCARLETT2_USB_CONFIG_SAVE */
1741 static void scarlett2_config_save(struct usb_mixer_interface *mixer)
1745 err = scarlett2_usb_activate_config(mixer, SCARLETT2_USB_CONFIG_SAVE);
1747 usb_audio_err(mixer->chip, "config save failed: %d\n", err);
1750 /* Delayed work to save config */
1751 static void scarlett2_config_save_work(struct work_struct *work)
1753 struct scarlett2_data *private =
1754 container_of(work, struct scarlett2_data, work.work);
1756 scarlett2_config_save(private->mixer);
1759 /* Send a USB message to get sync status; result placed in *sync */
1760 static int scarlett2_usb_get_sync_status(
1761 struct usb_mixer_interface *mixer,
1767 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_SYNC,
1768 NULL, 0, &data, sizeof(data));
1776 /* Return true if the device has a mixer that we can control */
1777 static int scarlett2_has_mixer(struct scarlett2_data *private)
1779 return !!private->info->mux_assignment[0][0].count;
1782 /* Map from mixer value to (db + 80) * 2
1783 * (reverse of scarlett2_mixer_values[])
1785 static int scarlett2_mixer_value_to_db(int value)
1789 for (i = 0; i < SCARLETT2_MIXER_VALUE_COUNT; i++)
1790 if (scarlett2_mixer_values[i] >= value)
1792 return SCARLETT2_MIXER_MAX_VALUE;
1795 /* Send a USB message to get the volumes for all inputs of one mix
1796 * and put the values into private->mix[]
1798 static int scarlett2_usb_get_mix(struct usb_mixer_interface *mixer,
1801 struct scarlett2_data *private = mixer->private_data;
1803 int num_mixer_in = private->num_mix_in;
1811 __le16 data[SCARLETT2_INPUT_MIX_MAX];
1813 req.mix_num = cpu_to_le16(mix_num);
1814 req.count = cpu_to_le16(num_mixer_in);
1816 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MIX,
1818 data, num_mixer_in * sizeof(u16));
1822 for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
1823 private->mix[j] = scarlett2_mixer_value_to_db(
1824 le16_to_cpu(data[i]));
1829 /* Send a USB message to set the volumes for all inputs of one mix
1830 * (values obtained from private->mix[])
1832 static int scarlett2_usb_set_mix(struct usb_mixer_interface *mixer,
1835 struct scarlett2_data *private = mixer->private_data;
1839 __le16 data[SCARLETT2_INPUT_MIX_MAX];
1843 int num_mixer_in = private->num_mix_in;
1845 req.mix_num = cpu_to_le16(mix_num);
1847 for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
1848 req.data[i] = cpu_to_le16(
1849 scarlett2_mixer_values[private->mix[j]]
1852 return scarlett2_usb(mixer, SCARLETT2_USB_SET_MIX,
1853 &req, (num_mixer_in + 1) * sizeof(u16),
1857 /* Convert a port number index (per info->port_count) to a hardware ID */
1858 static u32 scarlett2_mux_src_num_to_id(
1859 const int port_count[][SCARLETT2_PORT_DIRNS], int num)
1864 port_type < SCARLETT2_PORT_TYPE_COUNT;
1866 if (num < port_count[port_type][SCARLETT2_PORT_IN])
1867 return scarlett2_ports[port_type].id | num;
1868 num -= port_count[port_type][SCARLETT2_PORT_IN];
1875 /* Convert a hardware ID to a port number index */
1876 static u32 scarlett2_mux_id_to_num(
1877 const int port_count[][SCARLETT2_PORT_DIRNS], int direction, u32 id)
1883 port_type < SCARLETT2_PORT_TYPE_COUNT;
1885 int base = scarlett2_ports[port_type].id;
1886 int count = port_count[port_type][direction];
1888 if (id >= base && id < base + count)
1889 return port_num + id - base;
1897 /* Convert one mux entry from the interface and load into private->mux[] */
1898 static void scarlett2_usb_populate_mux(struct scarlett2_data *private,
1901 const struct scarlett2_device_info *info = private->info;
1902 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
1904 int dst_idx, src_idx;
1906 dst_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_OUT,
1911 if (dst_idx >= private->num_mux_dsts) {
1912 usb_audio_err(private->mixer->chip,
1913 "BUG: scarlett2_mux_id_to_num(%06x, OUT): %d >= %d",
1914 mux_entry, dst_idx, private->num_mux_dsts);
1918 src_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_IN,
1923 if (src_idx >= private->num_mux_srcs) {
1924 usb_audio_err(private->mixer->chip,
1925 "BUG: scarlett2_mux_id_to_num(%06x, IN): %d >= %d",
1926 mux_entry, src_idx, private->num_mux_srcs);
1930 private->mux[dst_idx] = src_idx;
1933 /* Update the meter level map
1935 * The meter level data from the interface (SCARLETT2_USB_GET_METER
1936 * request) is returned in mux_assignment order, but to avoid exposing
1937 * that to userspace, scarlett2_meter_ctl_get() rearranges the data
1938 * into scarlett2_ports order using the meter_level_map[] array which
1939 * is set up by this function.
1941 * In addition, the meter level data values returned from the
1942 * interface are invalid for destinations where:
1944 * - the source is "Off"; therefore we set those values to zero (map
1947 * - the source is assigned to a previous (with respect to the
1948 * mux_assignment order) destination; therefore we set those values
1949 * to the value previously reported for that source
1951 static void scarlett2_update_meter_level_map(struct scarlett2_data *private)
1953 const struct scarlett2_device_info *info = private->info;
1954 const struct scarlett2_meter_entry *entry;
1956 /* sources already assigned to a destination
1957 * value is 255 for None, otherwise the value of i
1958 * (index into array returned by
1959 * scarlett2_usb_get_meter_levels())
1961 u8 seen_src[SCARLETT2_MAX_SRCS] = { 1 };
1962 u8 seen_src_value[SCARLETT2_MAX_SRCS] = { 255 };
1964 /* index in meter_map[] order */
1967 /* go through the meter_map[] entries */
1968 for (entry = info->meter_map;
1972 /* fill in each meter_level_map[] entry */
1975 for (j = 0, mux_idx = entry->start;
1977 i++, j++, mux_idx++) {
1979 /* convert mux_idx using line_out_unmap[] */
1981 info->line_out_remap_enable &&
1982 mux_idx < private->num_line_out
1983 ) ? info->line_out_unmap[mux_idx]
1986 /* check which source is connected, and if
1987 * that source is already connected elsewhere,
1988 * use that existing connection's destination
1989 * for this meter entry instead
1991 int mux_src = private->mux[mux_idx];
1993 if (!seen_src[mux_src]) {
1994 seen_src[mux_src] = 1;
1995 seen_src_value[mux_src] = i;
1997 private->meter_level_map[map_mux_idx] =
1998 seen_src_value[mux_src];
2003 /* Send USB message to get mux inputs and then populate private->mux[] */
2004 static int scarlett2_usb_get_mux(struct usb_mixer_interface *mixer)
2006 struct scarlett2_data *private = mixer->private_data;
2007 int count = private->num_mux_dsts;
2015 __le32 data[SCARLETT2_MUX_MAX];
2017 private->mux_updated = 0;
2020 req.count = cpu_to_le16(count);
2022 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MUX,
2024 data, count * sizeof(u32));
2028 for (i = 0; i < count; i++)
2029 scarlett2_usb_populate_mux(private, le32_to_cpu(data[i]));
2031 scarlett2_update_meter_level_map(private);
2036 /* Send USB messages to set mux inputs */
2037 static int scarlett2_usb_set_mux(struct usb_mixer_interface *mixer)
2039 struct scarlett2_data *private = mixer->private_data;
2040 const struct scarlett2_device_info *info = private->info;
2041 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
2047 __le32 data[SCARLETT2_MUX_MAX];
2052 /* set mux settings for each rate */
2053 for (table = 0; table < SCARLETT2_MUX_TABLES; table++) {
2054 const struct scarlett2_mux_entry *entry;
2056 /* i counts over the output array */
2059 req.num = cpu_to_le16(table);
2061 /* loop through each entry */
2062 for (entry = info->mux_assignment[table];
2066 int port_type = entry->port_type;
2067 int port_idx = entry->start;
2068 int mux_idx = scarlett2_get_port_start_num(port_count,
2069 SCARLETT2_PORT_OUT, port_type) + port_idx;
2070 int dst_id = scarlett2_ports[port_type].id + port_idx;
2074 for (j = 0; j < entry->count; j++)
2079 /* Non-empty mux slots use the lower 12 bits
2080 * for the destination and next 12 bits for
2083 for (j = 0; j < entry->count; j++) {
2084 int src_id = scarlett2_mux_src_num_to_id(
2085 port_count, private->mux[mux_idx++]);
2086 req.data[i++] = cpu_to_le32(dst_id |
2092 err = scarlett2_usb(mixer, SCARLETT2_USB_SET_MUX,
2093 &req, (i + 1) * sizeof(u32),
2099 scarlett2_update_meter_level_map(private);
2104 /* Send USB message to get meter levels */
2105 static int scarlett2_usb_get_meter_levels(struct usb_mixer_interface *mixer,
2106 u16 num_meters, u16 *levels)
2113 __le32 resp[SCARLETT2_MAX_METERS];
2117 req.num_meters = cpu_to_le16(num_meters);
2118 req.magic = cpu_to_le32(SCARLETT2_USB_METER_LEVELS_GET_MAGIC);
2119 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_METER,
2120 &req, sizeof(req), resp, num_meters * sizeof(u32));
2124 /* copy, convert to u16 */
2125 for (i = 0; i < num_meters; i++)
2126 levels[i] = le32_to_cpu(resp[i]);
2131 /*** Control Functions ***/
2133 /* helper function to create a new control */
2134 static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
2135 const struct snd_kcontrol_new *ncontrol,
2136 int index, int channels, const char *name,
2137 struct snd_kcontrol **kctl_return)
2139 struct snd_kcontrol *kctl;
2140 struct usb_mixer_elem_info *elem;
2143 elem = kzalloc(sizeof(*elem), GFP_KERNEL);
2147 /* We set USB_MIXER_BESPOKEN type, so that the core USB mixer code
2148 * ignores them for resume and other operations.
2149 * Also, the head.id field is set to 0, as we don't use this field.
2151 elem->head.mixer = mixer;
2152 elem->control = index;
2154 elem->channels = channels;
2155 elem->val_type = USB_MIXER_BESPOKEN;
2157 kctl = snd_ctl_new1(ncontrol, elem);
2162 kctl->private_free = snd_usb_mixer_elem_free;
2164 strscpy(kctl->id.name, name, sizeof(kctl->id.name));
2166 err = snd_usb_mixer_add_control(&elem->head, kctl);
2171 *kctl_return = kctl;
2176 /*** Firmware Version Control ***/
2178 static int scarlett2_firmware_version_ctl_get(
2179 struct snd_kcontrol *kctl,
2180 struct snd_ctl_elem_value *ucontrol)
2182 struct usb_mixer_elem_info *elem = kctl->private_data;
2183 struct scarlett2_data *private = elem->head.mixer->private_data;
2185 ucontrol->value.integer.value[0] = private->firmware_version;
2190 static int scarlett2_firmware_version_ctl_info(
2191 struct snd_kcontrol *kctl,
2192 struct snd_ctl_elem_info *uinfo)
2194 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2200 static const struct snd_kcontrol_new scarlett2_firmware_version_ctl = {
2201 .iface = SNDRV_CTL_ELEM_IFACE_CARD,
2202 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2204 .info = scarlett2_firmware_version_ctl_info,
2205 .get = scarlett2_firmware_version_ctl_get
2208 static int scarlett2_add_firmware_version_ctl(
2209 struct usb_mixer_interface *mixer)
2211 return scarlett2_add_new_ctl(mixer, &scarlett2_firmware_version_ctl,
2212 0, 0, "Firmware Version", NULL);
2215 /*** Sync Control ***/
2217 /* Update sync control after receiving notification that the status
2220 static int scarlett2_update_sync(struct usb_mixer_interface *mixer)
2222 struct scarlett2_data *private = mixer->private_data;
2224 private->sync_updated = 0;
2225 return scarlett2_usb_get_sync_status(mixer, &private->sync);
2228 static int scarlett2_sync_ctl_info(struct snd_kcontrol *kctl,
2229 struct snd_ctl_elem_info *uinfo)
2231 static const char *texts[2] = {
2232 "Unlocked", "Locked"
2234 return snd_ctl_enum_info(uinfo, 1, 2, texts);
2237 static int scarlett2_sync_ctl_get(struct snd_kcontrol *kctl,
2238 struct snd_ctl_elem_value *ucontrol)
2240 struct usb_mixer_elem_info *elem = kctl->private_data;
2241 struct usb_mixer_interface *mixer = elem->head.mixer;
2242 struct scarlett2_data *private = mixer->private_data;
2245 mutex_lock(&private->data_mutex);
2247 if (private->hwdep_in_use) {
2252 if (private->sync_updated) {
2253 err = scarlett2_update_sync(mixer);
2257 ucontrol->value.enumerated.item[0] = private->sync;
2260 mutex_unlock(&private->data_mutex);
2264 static const struct snd_kcontrol_new scarlett2_sync_ctl = {
2265 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2266 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2268 .info = scarlett2_sync_ctl_info,
2269 .get = scarlett2_sync_ctl_get
2272 static int scarlett2_add_sync_ctl(struct usb_mixer_interface *mixer)
2274 struct scarlett2_data *private = mixer->private_data;
2276 /* devices without a mixer also don't support reporting sync status */
2277 if (!scarlett2_has_mixer(private))
2280 return scarlett2_add_new_ctl(mixer, &scarlett2_sync_ctl,
2281 0, 1, "Sync Status", &private->sync_ctl);
2284 /*** Analogue Line Out Volume Controls ***/
2286 /* Update hardware volume controls after receiving notification that
2289 static int scarlett2_update_volumes(struct usb_mixer_interface *mixer)
2291 struct scarlett2_data *private = mixer->private_data;
2295 private->vol_updated = 0;
2297 if (scarlett2_has_config_item(private,
2298 SCARLETT2_CONFIG_MASTER_VOLUME)) {
2299 err = scarlett2_usb_get_config(
2300 mixer, SCARLETT2_CONFIG_MASTER_VOLUME,
2305 private->master_vol = clamp(vol + SCARLETT2_VOLUME_BIAS,
2306 0, SCARLETT2_VOLUME_BIAS);
2308 if (scarlett2_has_config_item(private,
2309 SCARLETT2_CONFIG_SW_HW_SWITCH))
2310 for (i = 0; i < private->num_line_out; i++)
2311 if (private->vol_sw_hw_switch[i])
2312 private->vol[i] = private->master_vol;
2318 static int scarlett2_volume_ctl_info(struct snd_kcontrol *kctl,
2319 struct snd_ctl_elem_info *uinfo)
2321 struct usb_mixer_elem_info *elem = kctl->private_data;
2323 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2324 uinfo->count = elem->channels;
2325 uinfo->value.integer.min = 0;
2326 uinfo->value.integer.max = SCARLETT2_VOLUME_BIAS;
2327 uinfo->value.integer.step = 1;
2331 static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl,
2332 struct snd_ctl_elem_value *ucontrol)
2334 struct usb_mixer_elem_info *elem = kctl->private_data;
2335 struct usb_mixer_interface *mixer = elem->head.mixer;
2336 struct scarlett2_data *private = mixer->private_data;
2339 mutex_lock(&private->data_mutex);
2341 if (private->hwdep_in_use) {
2346 if (private->vol_updated) {
2347 err = scarlett2_update_volumes(mixer);
2351 ucontrol->value.integer.value[0] = private->master_vol;
2354 mutex_unlock(&private->data_mutex);
2358 static int line_out_remap(struct scarlett2_data *private, int index)
2360 const struct scarlett2_device_info *info = private->info;
2362 if (!info->line_out_remap_enable)
2365 if (index >= private->num_line_out)
2368 return info->line_out_remap[index];
2371 static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl,
2372 struct snd_ctl_elem_value *ucontrol)
2374 struct usb_mixer_elem_info *elem = kctl->private_data;
2375 struct usb_mixer_interface *mixer = elem->head.mixer;
2376 struct scarlett2_data *private = mixer->private_data;
2377 int index = line_out_remap(private, elem->control);
2380 mutex_lock(&private->data_mutex);
2382 if (private->hwdep_in_use) {
2387 if (private->vol_updated) {
2388 err = scarlett2_update_volumes(mixer);
2392 ucontrol->value.integer.value[0] = private->vol[index];
2395 mutex_unlock(&private->data_mutex);
2399 static int scarlett2_volume_ctl_put(struct snd_kcontrol *kctl,
2400 struct snd_ctl_elem_value *ucontrol)
2402 struct usb_mixer_elem_info *elem = kctl->private_data;
2403 struct usb_mixer_interface *mixer = elem->head.mixer;
2404 struct scarlett2_data *private = mixer->private_data;
2405 int index = line_out_remap(private, elem->control);
2406 int oval, val, err = 0;
2408 mutex_lock(&private->data_mutex);
2410 if (private->hwdep_in_use) {
2415 oval = private->vol[index];
2416 val = ucontrol->value.integer.value[0];
2421 private->vol[index] = val;
2422 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
2423 index, val - SCARLETT2_VOLUME_BIAS);
2428 mutex_unlock(&private->data_mutex);
2432 static const DECLARE_TLV_DB_MINMAX(
2433 db_scale_scarlett2_volume, -SCARLETT2_VOLUME_BIAS * 100, 0
2436 static const struct snd_kcontrol_new scarlett2_master_volume_ctl = {
2437 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2438 .access = SNDRV_CTL_ELEM_ACCESS_READ |
2439 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
2441 .info = scarlett2_volume_ctl_info,
2442 .get = scarlett2_master_volume_ctl_get,
2443 .private_value = 0, /* max value */
2444 .tlv = { .p = db_scale_scarlett2_volume }
2447 static const struct snd_kcontrol_new scarlett2_line_out_volume_ctl = {
2448 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2449 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
2450 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
2452 .info = scarlett2_volume_ctl_info,
2453 .get = scarlett2_volume_ctl_get,
2454 .put = scarlett2_volume_ctl_put,
2455 .private_value = 0, /* max value */
2456 .tlv = { .p = db_scale_scarlett2_volume }
2459 /*** Mute Switch Controls ***/
2461 static int scarlett2_update_dim_mute(struct usb_mixer_interface *mixer)
2463 struct scarlett2_data *private = mixer->private_data;
2467 private->dim_mute_updated = 0;
2469 if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_SW_HW_SWITCH))
2472 err = scarlett2_usb_get_config(
2473 mixer, SCARLETT2_CONFIG_DIM_MUTE,
2474 SCARLETT2_DIM_MUTE_COUNT, private->dim_mute);
2478 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
2479 private->dim_mute[i] = !!private->dim_mute[i];
2481 mute = private->dim_mute[SCARLETT2_BUTTON_MUTE];
2483 for (i = 0; i < private->num_line_out; i++)
2484 if (private->vol_sw_hw_switch[i])
2485 private->mute_switch[i] = mute;
2490 static int scarlett2_mute_ctl_get(struct snd_kcontrol *kctl,
2491 struct snd_ctl_elem_value *ucontrol)
2493 struct usb_mixer_elem_info *elem = kctl->private_data;
2494 struct usb_mixer_interface *mixer = elem->head.mixer;
2495 struct scarlett2_data *private = mixer->private_data;
2496 int index = line_out_remap(private, elem->control);
2499 mutex_lock(&private->data_mutex);
2501 if (private->hwdep_in_use) {
2506 if (private->dim_mute_updated) {
2507 err = scarlett2_update_dim_mute(mixer);
2511 ucontrol->value.integer.value[0] = private->mute_switch[index];
2514 mutex_unlock(&private->data_mutex);
2518 static int scarlett2_mute_ctl_put(struct snd_kcontrol *kctl,
2519 struct snd_ctl_elem_value *ucontrol)
2521 struct usb_mixer_elem_info *elem = kctl->private_data;
2522 struct usb_mixer_interface *mixer = elem->head.mixer;
2523 struct scarlett2_data *private = mixer->private_data;
2524 int index = line_out_remap(private, elem->control);
2525 int oval, val, err = 0;
2527 mutex_lock(&private->data_mutex);
2529 if (private->hwdep_in_use) {
2534 oval = private->mute_switch[index];
2535 val = !!ucontrol->value.integer.value[0];
2540 private->mute_switch[index] = val;
2542 /* Send mute change to the device */
2543 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
2549 mutex_unlock(&private->data_mutex);
2553 static const struct snd_kcontrol_new scarlett2_mute_ctl = {
2554 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2556 .info = snd_ctl_boolean_mono_info,
2557 .get = scarlett2_mute_ctl_get,
2558 .put = scarlett2_mute_ctl_put,
2561 /*** HW/SW Volume Switch Controls ***/
2563 static void scarlett2_sw_hw_ctl_ro(struct scarlett2_data *private, int index)
2565 private->sw_hw_ctls[index]->vd[0].access &=
2566 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
2569 static void scarlett2_sw_hw_ctl_rw(struct scarlett2_data *private, int index)
2571 private->sw_hw_ctls[index]->vd[0].access |=
2572 SNDRV_CTL_ELEM_ACCESS_WRITE;
2575 static int scarlett2_sw_hw_enum_ctl_info(struct snd_kcontrol *kctl,
2576 struct snd_ctl_elem_info *uinfo)
2578 static const char *const values[2] = {
2582 return snd_ctl_enum_info(uinfo, 1, 2, values);
2585 static int scarlett2_sw_hw_enum_ctl_get(struct snd_kcontrol *kctl,
2586 struct snd_ctl_elem_value *ucontrol)
2588 struct usb_mixer_elem_info *elem = kctl->private_data;
2589 struct scarlett2_data *private = elem->head.mixer->private_data;
2590 int index = line_out_remap(private, elem->control);
2592 ucontrol->value.enumerated.item[0] = private->vol_sw_hw_switch[index];
2596 static void scarlett2_vol_ctl_set_writable(struct usb_mixer_interface *mixer,
2597 int index, int value)
2599 struct scarlett2_data *private = mixer->private_data;
2600 struct snd_card *card = mixer->chip->card;
2602 /* Set/Clear write bits */
2604 private->vol_ctls[index]->vd[0].access |=
2605 SNDRV_CTL_ELEM_ACCESS_WRITE;
2606 private->mute_ctls[index]->vd[0].access |=
2607 SNDRV_CTL_ELEM_ACCESS_WRITE;
2609 private->vol_ctls[index]->vd[0].access &=
2610 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
2611 private->mute_ctls[index]->vd[0].access &=
2612 ~SNDRV_CTL_ELEM_ACCESS_WRITE;
2615 /* Notify of write bit and possible value change */
2616 snd_ctl_notify(card,
2617 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
2618 &private->vol_ctls[index]->id);
2619 snd_ctl_notify(card,
2620 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
2621 &private->mute_ctls[index]->id);
2624 static int scarlett2_sw_hw_change(struct usb_mixer_interface *mixer,
2625 int ctl_index, int val)
2627 struct scarlett2_data *private = mixer->private_data;
2628 int index = line_out_remap(private, ctl_index);
2631 private->vol_sw_hw_switch[index] = val;
2633 /* Change access mode to RO (hardware controlled volume)
2634 * or RW (software controlled volume)
2636 scarlett2_vol_ctl_set_writable(mixer, ctl_index, !val);
2638 /* Reset volume/mute to master volume/mute */
2639 private->vol[index] = private->master_vol;
2640 private->mute_switch[index] = private->dim_mute[SCARLETT2_BUTTON_MUTE];
2642 /* Set SW volume to current HW volume */
2643 err = scarlett2_usb_set_config(
2644 mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
2645 index, private->master_vol - SCARLETT2_VOLUME_BIAS);
2649 /* Set SW mute to current HW mute */
2650 err = scarlett2_usb_set_config(
2651 mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
2652 index, private->dim_mute[SCARLETT2_BUTTON_MUTE]);
2656 /* Send SW/HW switch change to the device */
2657 return scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
2661 static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl,
2662 struct snd_ctl_elem_value *ucontrol)
2664 struct usb_mixer_elem_info *elem = kctl->private_data;
2665 struct usb_mixer_interface *mixer = elem->head.mixer;
2666 struct scarlett2_data *private = mixer->private_data;
2667 int ctl_index = elem->control;
2668 int index = line_out_remap(private, ctl_index);
2669 int oval, val, err = 0;
2671 mutex_lock(&private->data_mutex);
2673 if (private->hwdep_in_use) {
2678 oval = private->vol_sw_hw_switch[index];
2679 val = !!ucontrol->value.enumerated.item[0];
2684 err = scarlett2_sw_hw_change(mixer, ctl_index, val);
2689 mutex_unlock(&private->data_mutex);
2693 static const struct snd_kcontrol_new scarlett2_sw_hw_enum_ctl = {
2694 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2696 .info = scarlett2_sw_hw_enum_ctl_info,
2697 .get = scarlett2_sw_hw_enum_ctl_get,
2698 .put = scarlett2_sw_hw_enum_ctl_put,
2701 /*** Line Level/Instrument Level Switch Controls ***/
2703 static int scarlett2_update_input_level(struct usb_mixer_interface *mixer)
2705 struct scarlett2_data *private = mixer->private_data;
2706 const struct scarlett2_device_info *info = private->info;
2708 private->input_level_updated = 0;
2710 if (!info->level_input_count)
2713 return scarlett2_usb_get_config(
2714 mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
2715 info->level_input_count + info->level_input_first,
2716 private->level_switch);
2719 static int scarlett2_level_enum_ctl_info(struct snd_kcontrol *kctl,
2720 struct snd_ctl_elem_info *uinfo)
2722 static const char *const values[2] = {
2726 return snd_ctl_enum_info(uinfo, 1, 2, values);
2729 static int scarlett2_level_enum_ctl_get(struct snd_kcontrol *kctl,
2730 struct snd_ctl_elem_value *ucontrol)
2732 struct usb_mixer_elem_info *elem = kctl->private_data;
2733 struct usb_mixer_interface *mixer = elem->head.mixer;
2734 struct scarlett2_data *private = mixer->private_data;
2735 const struct scarlett2_device_info *info = private->info;
2737 int index = elem->control + info->level_input_first;
2740 mutex_lock(&private->data_mutex);
2742 if (private->hwdep_in_use) {
2747 if (private->input_level_updated) {
2748 err = scarlett2_update_input_level(mixer);
2752 ucontrol->value.enumerated.item[0] = private->level_switch[index];
2755 mutex_unlock(&private->data_mutex);
2759 static int scarlett2_level_enum_ctl_put(struct snd_kcontrol *kctl,
2760 struct snd_ctl_elem_value *ucontrol)
2762 struct usb_mixer_elem_info *elem = kctl->private_data;
2763 struct usb_mixer_interface *mixer = elem->head.mixer;
2764 struct scarlett2_data *private = mixer->private_data;
2765 const struct scarlett2_device_info *info = private->info;
2767 int index = elem->control + info->level_input_first;
2768 int oval, val, err = 0;
2770 mutex_lock(&private->data_mutex);
2772 if (private->hwdep_in_use) {
2777 oval = private->level_switch[index];
2778 val = !!ucontrol->value.enumerated.item[0];
2783 private->level_switch[index] = val;
2785 /* Send switch change to the device */
2786 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
2792 mutex_unlock(&private->data_mutex);
2796 static const struct snd_kcontrol_new scarlett2_level_enum_ctl = {
2797 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2799 .info = scarlett2_level_enum_ctl_info,
2800 .get = scarlett2_level_enum_ctl_get,
2801 .put = scarlett2_level_enum_ctl_put,
2804 /*** Pad Switch Controls ***/
2806 static int scarlett2_update_input_pad(struct usb_mixer_interface *mixer)
2808 struct scarlett2_data *private = mixer->private_data;
2809 const struct scarlett2_device_info *info = private->info;
2811 private->input_pad_updated = 0;
2813 if (!info->pad_input_count)
2816 return scarlett2_usb_get_config(
2817 mixer, SCARLETT2_CONFIG_PAD_SWITCH,
2818 info->pad_input_count, private->pad_switch);
2821 static int scarlett2_pad_ctl_get(struct snd_kcontrol *kctl,
2822 struct snd_ctl_elem_value *ucontrol)
2824 struct usb_mixer_elem_info *elem = kctl->private_data;
2825 struct usb_mixer_interface *mixer = elem->head.mixer;
2826 struct scarlett2_data *private = mixer->private_data;
2829 mutex_lock(&private->data_mutex);
2831 if (private->hwdep_in_use) {
2836 if (private->input_pad_updated) {
2837 err = scarlett2_update_input_pad(mixer);
2841 ucontrol->value.integer.value[0] =
2842 private->pad_switch[elem->control];
2845 mutex_unlock(&private->data_mutex);
2849 static int scarlett2_pad_ctl_put(struct snd_kcontrol *kctl,
2850 struct snd_ctl_elem_value *ucontrol)
2852 struct usb_mixer_elem_info *elem = kctl->private_data;
2853 struct usb_mixer_interface *mixer = elem->head.mixer;
2854 struct scarlett2_data *private = mixer->private_data;
2856 int index = elem->control;
2857 int oval, val, err = 0;
2859 mutex_lock(&private->data_mutex);
2861 if (private->hwdep_in_use) {
2866 oval = private->pad_switch[index];
2867 val = !!ucontrol->value.integer.value[0];
2872 private->pad_switch[index] = val;
2874 /* Send switch change to the device */
2875 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PAD_SWITCH,
2881 mutex_unlock(&private->data_mutex);
2885 static const struct snd_kcontrol_new scarlett2_pad_ctl = {
2886 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2888 .info = snd_ctl_boolean_mono_info,
2889 .get = scarlett2_pad_ctl_get,
2890 .put = scarlett2_pad_ctl_put,
2893 /*** Air Switch Controls ***/
2895 static int scarlett2_update_input_air(struct usb_mixer_interface *mixer)
2897 struct scarlett2_data *private = mixer->private_data;
2898 const struct scarlett2_device_info *info = private->info;
2900 private->input_air_updated = 0;
2902 if (!info->air_input_count)
2905 return scarlett2_usb_get_config(
2906 mixer, SCARLETT2_CONFIG_AIR_SWITCH,
2907 info->air_input_count, private->air_switch);
2910 static int scarlett2_air_ctl_get(struct snd_kcontrol *kctl,
2911 struct snd_ctl_elem_value *ucontrol)
2913 struct usb_mixer_elem_info *elem = kctl->private_data;
2914 struct usb_mixer_interface *mixer = elem->head.mixer;
2915 struct scarlett2_data *private = mixer->private_data;
2918 mutex_lock(&private->data_mutex);
2920 if (private->hwdep_in_use) {
2925 if (private->input_air_updated) {
2926 err = scarlett2_update_input_air(mixer);
2930 ucontrol->value.integer.value[0] = private->air_switch[elem->control];
2933 mutex_unlock(&private->data_mutex);
2937 static int scarlett2_air_ctl_put(struct snd_kcontrol *kctl,
2938 struct snd_ctl_elem_value *ucontrol)
2940 struct usb_mixer_elem_info *elem = kctl->private_data;
2941 struct usb_mixer_interface *mixer = elem->head.mixer;
2942 struct scarlett2_data *private = mixer->private_data;
2944 int index = elem->control;
2945 int oval, val, err = 0;
2947 mutex_lock(&private->data_mutex);
2949 if (private->hwdep_in_use) {
2954 oval = private->air_switch[index];
2955 val = !!ucontrol->value.integer.value[0];
2960 private->air_switch[index] = val;
2962 /* Send switch change to the device */
2963 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_AIR_SWITCH,
2969 mutex_unlock(&private->data_mutex);
2973 static const struct snd_kcontrol_new scarlett2_air_ctl = {
2974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2976 .info = snd_ctl_boolean_mono_info,
2977 .get = scarlett2_air_ctl_get,
2978 .put = scarlett2_air_ctl_put,
2981 /*** Phantom Switch Controls ***/
2983 static int scarlett2_update_input_phantom(struct usb_mixer_interface *mixer)
2985 struct scarlett2_data *private = mixer->private_data;
2986 const struct scarlett2_device_info *info = private->info;
2989 private->input_phantom_updated = 0;
2991 if (!info->phantom_count)
2994 err = scarlett2_usb_get_config(
2995 mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
2996 info->phantom_count, private->phantom_switch);
3000 if (scarlett2_has_config_item(private,
3001 SCARLETT2_CONFIG_PHANTOM_PERSISTENCE)) {
3002 err = scarlett2_usb_get_config(
3003 mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
3004 1, &private->phantom_persistence);
3012 static int scarlett2_phantom_ctl_get(struct snd_kcontrol *kctl,
3013 struct snd_ctl_elem_value *ucontrol)
3015 struct usb_mixer_elem_info *elem = kctl->private_data;
3016 struct usb_mixer_interface *mixer = elem->head.mixer;
3017 struct scarlett2_data *private = mixer->private_data;
3020 mutex_lock(&private->data_mutex);
3022 if (private->hwdep_in_use) {
3027 if (private->input_phantom_updated) {
3028 err = scarlett2_update_input_phantom(mixer);
3032 ucontrol->value.integer.value[0] =
3033 private->phantom_switch[elem->control];
3036 mutex_unlock(&private->data_mutex);
3040 static int scarlett2_phantom_ctl_put(struct snd_kcontrol *kctl,
3041 struct snd_ctl_elem_value *ucontrol)
3043 struct usb_mixer_elem_info *elem = kctl->private_data;
3044 struct usb_mixer_interface *mixer = elem->head.mixer;
3045 struct scarlett2_data *private = mixer->private_data;
3047 int index = elem->control;
3048 int oval, val, err = 0;
3050 mutex_lock(&private->data_mutex);
3052 if (private->hwdep_in_use) {
3057 oval = private->phantom_switch[index];
3058 val = !!ucontrol->value.integer.value[0];
3063 private->phantom_switch[index] = val;
3065 /* Send switch change to the device */
3066 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PHANTOM_SWITCH,
3072 mutex_unlock(&private->data_mutex);
3076 static const struct snd_kcontrol_new scarlett2_phantom_ctl = {
3077 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3079 .info = snd_ctl_boolean_mono_info,
3080 .get = scarlett2_phantom_ctl_get,
3081 .put = scarlett2_phantom_ctl_put,
3084 /*** Phantom Persistence Control ***/
3086 static int scarlett2_phantom_persistence_ctl_get(
3087 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3089 struct usb_mixer_elem_info *elem = kctl->private_data;
3090 struct scarlett2_data *private = elem->head.mixer->private_data;
3092 ucontrol->value.integer.value[0] = private->phantom_persistence;
3096 static int scarlett2_phantom_persistence_ctl_put(
3097 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3099 struct usb_mixer_elem_info *elem = kctl->private_data;
3100 struct usb_mixer_interface *mixer = elem->head.mixer;
3101 struct scarlett2_data *private = mixer->private_data;
3103 int index = elem->control;
3104 int oval, val, err = 0;
3106 mutex_lock(&private->data_mutex);
3108 if (private->hwdep_in_use) {
3113 oval = private->phantom_persistence;
3114 val = !!ucontrol->value.integer.value[0];
3119 private->phantom_persistence = val;
3121 /* Send switch change to the device */
3122 err = scarlett2_usb_set_config(
3123 mixer, SCARLETT2_CONFIG_PHANTOM_PERSISTENCE, index, val);
3128 mutex_unlock(&private->data_mutex);
3132 static const struct snd_kcontrol_new scarlett2_phantom_persistence_ctl = {
3133 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3135 .info = snd_ctl_boolean_mono_info,
3136 .get = scarlett2_phantom_persistence_ctl_get,
3137 .put = scarlett2_phantom_persistence_ctl_put,
3140 /*** Speaker Switching Control ***/
3142 static int scarlett2_update_monitor_other(struct usb_mixer_interface *mixer)
3144 struct scarlett2_data *private = mixer->private_data;
3145 const struct scarlett2_device_info *info = private->info;
3148 /* monitor_other_enable[0] enables speaker switching
3149 * monitor_other_enable[1] enables talkback
3151 u8 monitor_other_enable[2];
3153 /* monitor_other_switch[0] activates the alternate speakers
3154 * monitor_other_switch[1] activates talkback
3156 u8 monitor_other_switch[2];
3158 private->monitor_other_updated = 0;
3160 /* if it doesn't do speaker switching then it also doesn't do
3163 if (!info->has_speaker_switching)
3166 err = scarlett2_usb_get_config(
3167 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
3168 2, monitor_other_enable);
3172 err = scarlett2_usb_get_config(
3173 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
3174 2, monitor_other_switch);
3178 if (!monitor_other_enable[0])
3179 private->speaker_switching_switch = 0;
3181 private->speaker_switching_switch = monitor_other_switch[0] + 1;
3183 if (info->has_talkback) {
3187 if (!monitor_other_enable[1])
3188 private->talkback_switch = 0;
3190 private->talkback_switch = monitor_other_switch[1] + 1;
3192 err = scarlett2_usb_get_config(mixer,
3193 SCARLETT2_CONFIG_TALKBACK_MAP,
3197 for (i = 0; i < private->num_mix_out; i++, bitmap >>= 1)
3198 private->talkback_map[i] = bitmap & 1;
3204 static int scarlett2_speaker_switch_enum_ctl_info(
3205 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
3207 static const char *const values[3] = {
3208 "Off", "Main", "Alt"
3211 return snd_ctl_enum_info(uinfo, 1, 3, values);
3214 static int scarlett2_speaker_switch_enum_ctl_get(
3215 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3217 struct usb_mixer_elem_info *elem = kctl->private_data;
3218 struct usb_mixer_interface *mixer = elem->head.mixer;
3219 struct scarlett2_data *private = mixer->private_data;
3222 mutex_lock(&private->data_mutex);
3224 if (private->hwdep_in_use) {
3229 if (private->monitor_other_updated) {
3230 err = scarlett2_update_monitor_other(mixer);
3234 ucontrol->value.enumerated.item[0] = private->speaker_switching_switch;
3237 mutex_unlock(&private->data_mutex);
3241 /* when speaker switching gets enabled, switch the main/alt speakers
3242 * to HW volume and disable those controls
3244 static int scarlett2_speaker_switch_enable(struct usb_mixer_interface *mixer)
3246 struct snd_card *card = mixer->chip->card;
3247 struct scarlett2_data *private = mixer->private_data;
3250 for (i = 0; i < 4; i++) {
3251 int index = line_out_remap(private, i);
3253 /* switch the main/alt speakers to HW volume */
3254 if (!private->vol_sw_hw_switch[index]) {
3255 err = scarlett2_sw_hw_change(private->mixer, i, 1);
3260 /* disable the line out SW/HW switch */
3261 scarlett2_sw_hw_ctl_ro(private, i);
3262 snd_ctl_notify(card,
3263 SNDRV_CTL_EVENT_MASK_VALUE |
3264 SNDRV_CTL_EVENT_MASK_INFO,
3265 &private->sw_hw_ctls[i]->id);
3268 /* when the next monitor-other notify comes in, update the mux
3271 private->speaker_switching_switched = 1;
3276 /* when speaker switching gets disabled, reenable the hw/sw controls
3277 * and invalidate the routing
3279 static void scarlett2_speaker_switch_disable(struct usb_mixer_interface *mixer)
3281 struct snd_card *card = mixer->chip->card;
3282 struct scarlett2_data *private = mixer->private_data;
3285 /* enable the line out SW/HW switch */
3286 for (i = 0; i < 4; i++) {
3287 scarlett2_sw_hw_ctl_rw(private, i);
3288 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO,
3289 &private->sw_hw_ctls[i]->id);
3292 /* when the next monitor-other notify comes in, update the mux
3295 private->speaker_switching_switched = 1;
3298 static int scarlett2_speaker_switch_enum_ctl_put(
3299 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3301 struct usb_mixer_elem_info *elem = kctl->private_data;
3302 struct usb_mixer_interface *mixer = elem->head.mixer;
3303 struct scarlett2_data *private = mixer->private_data;
3305 int oval, val, err = 0;
3307 mutex_lock(&private->data_mutex);
3309 if (private->hwdep_in_use) {
3314 oval = private->speaker_switching_switch;
3315 val = min(ucontrol->value.enumerated.item[0], 2U);
3320 private->speaker_switching_switch = val;
3322 /* enable/disable speaker switching */
3323 err = scarlett2_usb_set_config(
3324 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
3329 /* if speaker switching is enabled, select main or alt */
3330 err = scarlett2_usb_set_config(
3331 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
3336 /* update controls if speaker switching gets enabled or disabled */
3338 err = scarlett2_speaker_switch_enable(mixer);
3339 else if (oval && !val)
3340 scarlett2_speaker_switch_disable(mixer);
3346 mutex_unlock(&private->data_mutex);
3350 static const struct snd_kcontrol_new scarlett2_speaker_switch_enum_ctl = {
3351 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3353 .info = scarlett2_speaker_switch_enum_ctl_info,
3354 .get = scarlett2_speaker_switch_enum_ctl_get,
3355 .put = scarlett2_speaker_switch_enum_ctl_put,
3358 static int scarlett2_add_speaker_switch_ctl(struct usb_mixer_interface *mixer)
3360 struct scarlett2_data *private = mixer->private_data;
3361 const struct scarlett2_device_info *info = private->info;
3363 if (!info->has_speaker_switching)
3366 return scarlett2_add_new_ctl(
3367 mixer, &scarlett2_speaker_switch_enum_ctl,
3368 0, 1, "Speaker Switching Playback Enum",
3369 &private->speaker_switching_ctl);
3372 /*** Talkback and Talkback Map Controls ***/
3374 static int scarlett2_talkback_enum_ctl_info(
3375 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
3377 static const char *const values[3] = {
3378 "Disabled", "Off", "On"
3381 return snd_ctl_enum_info(uinfo, 1, 3, values);
3384 static int scarlett2_talkback_enum_ctl_get(
3385 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3387 struct usb_mixer_elem_info *elem = kctl->private_data;
3388 struct usb_mixer_interface *mixer = elem->head.mixer;
3389 struct scarlett2_data *private = mixer->private_data;
3392 mutex_lock(&private->data_mutex);
3394 if (private->hwdep_in_use) {
3399 if (private->monitor_other_updated) {
3400 err = scarlett2_update_monitor_other(mixer);
3404 ucontrol->value.enumerated.item[0] = private->talkback_switch;
3407 mutex_unlock(&private->data_mutex);
3411 static int scarlett2_talkback_enum_ctl_put(
3412 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3414 struct usb_mixer_elem_info *elem = kctl->private_data;
3415 struct usb_mixer_interface *mixer = elem->head.mixer;
3416 struct scarlett2_data *private = mixer->private_data;
3418 int oval, val, err = 0;
3420 mutex_lock(&private->data_mutex);
3422 if (private->hwdep_in_use) {
3427 oval = private->talkback_switch;
3428 val = min(ucontrol->value.enumerated.item[0], 2U);
3433 private->talkback_switch = val;
3435 /* enable/disable talkback */
3436 err = scarlett2_usb_set_config(
3437 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
3442 /* if talkback is enabled, select main or alt */
3443 err = scarlett2_usb_set_config(
3444 mixer, SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
3450 mutex_unlock(&private->data_mutex);
3454 static const struct snd_kcontrol_new scarlett2_talkback_enum_ctl = {
3455 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3457 .info = scarlett2_talkback_enum_ctl_info,
3458 .get = scarlett2_talkback_enum_ctl_get,
3459 .put = scarlett2_talkback_enum_ctl_put,
3462 static int scarlett2_talkback_map_ctl_get(
3463 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3465 struct usb_mixer_elem_info *elem = kctl->private_data;
3466 struct usb_mixer_interface *mixer = elem->head.mixer;
3467 struct scarlett2_data *private = mixer->private_data;
3468 int index = elem->control;
3470 ucontrol->value.integer.value[0] = private->talkback_map[index];
3475 static int scarlett2_talkback_map_ctl_put(
3476 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3478 struct usb_mixer_elem_info *elem = kctl->private_data;
3479 struct usb_mixer_interface *mixer = elem->head.mixer;
3480 struct scarlett2_data *private = mixer->private_data;
3481 int index = elem->control;
3482 int oval, val, err = 0, i;
3485 mutex_lock(&private->data_mutex);
3487 if (private->hwdep_in_use) {
3492 oval = private->talkback_map[index];
3493 val = !!ucontrol->value.integer.value[0];
3498 private->talkback_map[index] = val;
3500 for (i = 0; i < private->num_mix_out; i++)
3501 bitmap |= private->talkback_map[i] << i;
3503 /* Send updated bitmap to the device */
3504 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_TALKBACK_MAP,
3510 mutex_unlock(&private->data_mutex);
3514 static const struct snd_kcontrol_new scarlett2_talkback_map_ctl = {
3515 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3517 .info = snd_ctl_boolean_mono_info,
3518 .get = scarlett2_talkback_map_ctl_get,
3519 .put = scarlett2_talkback_map_ctl_put,
3522 static int scarlett2_add_talkback_ctls(struct usb_mixer_interface *mixer)
3524 struct scarlett2_data *private = mixer->private_data;
3525 const struct scarlett2_device_info *info = private->info;
3527 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3529 if (!info->has_talkback)
3532 err = scarlett2_add_new_ctl(
3533 mixer, &scarlett2_talkback_enum_ctl,
3534 0, 1, "Talkback Playback Enum",
3535 &private->talkback_ctl);
3539 for (i = 0; i < private->num_mix_out; i++) {
3540 snprintf(s, sizeof(s),
3541 "Talkback Mix %c Playback Switch", i + 'A');
3542 err = scarlett2_add_new_ctl(mixer, &scarlett2_talkback_map_ctl,
3551 /*** Dim/Mute Controls ***/
3553 static int scarlett2_dim_mute_ctl_get(struct snd_kcontrol *kctl,
3554 struct snd_ctl_elem_value *ucontrol)
3556 struct usb_mixer_elem_info *elem = kctl->private_data;
3557 struct usb_mixer_interface *mixer = elem->head.mixer;
3558 struct scarlett2_data *private = mixer->private_data;
3561 mutex_lock(&private->data_mutex);
3563 if (private->hwdep_in_use) {
3568 if (private->dim_mute_updated) {
3569 err = scarlett2_update_dim_mute(mixer);
3573 ucontrol->value.integer.value[0] = private->dim_mute[elem->control];
3576 mutex_unlock(&private->data_mutex);
3580 static int scarlett2_dim_mute_ctl_put(struct snd_kcontrol *kctl,
3581 struct snd_ctl_elem_value *ucontrol)
3583 struct usb_mixer_elem_info *elem = kctl->private_data;
3584 struct usb_mixer_interface *mixer = elem->head.mixer;
3585 struct scarlett2_data *private = mixer->private_data;
3586 int index = elem->control;
3587 int oval, val, err = 0, i;
3589 mutex_lock(&private->data_mutex);
3591 if (private->hwdep_in_use) {
3596 oval = private->dim_mute[index];
3597 val = !!ucontrol->value.integer.value[0];
3602 private->dim_mute[index] = val;
3604 /* Send switch change to the device */
3605 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_DIM_MUTE,
3610 if (index == SCARLETT2_BUTTON_MUTE)
3611 for (i = 0; i < private->num_line_out; i++) {
3612 int line_index = line_out_remap(private, i);
3614 if (private->vol_sw_hw_switch[line_index]) {
3615 private->mute_switch[line_index] = val;
3616 snd_ctl_notify(mixer->chip->card,
3617 SNDRV_CTL_EVENT_MASK_VALUE,
3618 &private->mute_ctls[i]->id);
3623 mutex_unlock(&private->data_mutex);
3627 static const struct snd_kcontrol_new scarlett2_dim_mute_ctl = {
3628 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3630 .info = snd_ctl_boolean_mono_info,
3631 .get = scarlett2_dim_mute_ctl_get,
3632 .put = scarlett2_dim_mute_ctl_put
3635 /*** Create the analogue output controls ***/
3637 static int scarlett2_add_line_out_ctls(struct usb_mixer_interface *mixer)
3639 struct scarlett2_data *private = mixer->private_data;
3640 const struct scarlett2_device_info *info = private->info;
3642 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3644 /* Add R/O HW volume control */
3645 if (scarlett2_has_config_item(private,
3646 SCARLETT2_CONFIG_MASTER_VOLUME)) {
3647 snprintf(s, sizeof(s), "Master HW Playback Volume");
3648 err = scarlett2_add_new_ctl(mixer,
3649 &scarlett2_master_volume_ctl,
3650 0, 1, s, &private->master_vol_ctl);
3655 /* Remaining controls are only applicable if the device
3656 * has per-channel line-out volume controls.
3658 if (!scarlett2_has_config_item(private,
3659 SCARLETT2_CONFIG_LINE_OUT_VOLUME))
3662 /* Add volume controls */
3663 for (i = 0; i < private->num_line_out; i++) {
3664 int index = line_out_remap(private, i);
3667 if (info->line_out_descrs[i])
3668 snprintf(s, sizeof(s),
3669 "Line %02d (%s) Playback Volume",
3670 i + 1, info->line_out_descrs[i]);
3672 snprintf(s, sizeof(s),
3673 "Line %02d Playback Volume",
3675 err = scarlett2_add_new_ctl(mixer,
3676 &scarlett2_line_out_volume_ctl,
3677 i, 1, s, &private->vol_ctls[i]);
3682 snprintf(s, sizeof(s),
3683 "Line %02d Mute Playback Switch",
3685 err = scarlett2_add_new_ctl(mixer,
3686 &scarlett2_mute_ctl,
3688 &private->mute_ctls[i]);
3693 if (scarlett2_has_config_item(private,
3694 SCARLETT2_CONFIG_SW_HW_SWITCH)) {
3696 /* Make the fader and mute controls read-only if the
3697 * SW/HW switch is set to HW
3699 if (private->vol_sw_hw_switch[index])
3700 scarlett2_vol_ctl_set_writable(mixer, i, 0);
3702 snprintf(s, sizeof(s),
3703 "Line Out %02d Volume Control Playback Enum",
3705 err = scarlett2_add_new_ctl(mixer,
3706 &scarlett2_sw_hw_enum_ctl,
3708 &private->sw_hw_ctls[i]);
3712 /* Make the switch read-only if the line is
3713 * involved in speaker switching
3715 if (private->speaker_switching_switch && i < 4)
3716 scarlett2_sw_hw_ctl_ro(private, i);
3720 /* Add dim/mute controls */
3721 if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_DIM_MUTE))
3722 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++) {
3723 err = scarlett2_add_new_ctl(
3724 mixer, &scarlett2_dim_mute_ctl,
3725 i, 1, scarlett2_dim_mute_names[i],
3726 &private->dim_mute_ctls[i]);
3734 /*** Create the analogue input controls ***/
3736 static int scarlett2_add_line_in_ctls(struct usb_mixer_interface *mixer)
3738 struct scarlett2_data *private = mixer->private_data;
3739 const struct scarlett2_device_info *info = private->info;
3741 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3742 const char *fmt = "Line In %d %s Capture %s";
3743 const char *fmt2 = "Line In %d-%d %s Capture %s";
3745 /* Add input level (line/inst) controls */
3746 for (i = 0; i < info->level_input_count; i++) {
3747 snprintf(s, sizeof(s), fmt, i + 1 + info->level_input_first,
3749 err = scarlett2_add_new_ctl(mixer, &scarlett2_level_enum_ctl,
3750 i, 1, s, &private->level_ctls[i]);
3755 /* Add input pad controls */
3756 for (i = 0; i < info->pad_input_count; i++) {
3757 snprintf(s, sizeof(s), fmt, i + 1, "Pad", "Switch");
3758 err = scarlett2_add_new_ctl(mixer, &scarlett2_pad_ctl,
3759 i, 1, s, &private->pad_ctls[i]);
3764 /* Add input air controls */
3765 for (i = 0; i < info->air_input_count; i++) {
3766 snprintf(s, sizeof(s), fmt, i + 1, "Air", "Switch");
3767 err = scarlett2_add_new_ctl(mixer, &scarlett2_air_ctl,
3768 i, 1, s, &private->air_ctls[i]);
3773 /* Add input phantom controls */
3774 if (info->inputs_per_phantom == 1) {
3775 for (i = 0; i < info->phantom_count; i++) {
3776 scnprintf(s, sizeof(s), fmt, i + 1,
3777 "Phantom Power", "Switch");
3778 err = scarlett2_add_new_ctl(
3779 mixer, &scarlett2_phantom_ctl,
3780 i, 1, s, &private->phantom_ctls[i]);
3784 } else if (info->inputs_per_phantom > 1) {
3785 for (i = 0; i < info->phantom_count; i++) {
3786 int from = i * info->inputs_per_phantom + 1;
3787 int to = (i + 1) * info->inputs_per_phantom;
3789 scnprintf(s, sizeof(s), fmt2, from, to,
3790 "Phantom Power", "Switch");
3791 err = scarlett2_add_new_ctl(
3792 mixer, &scarlett2_phantom_ctl,
3793 i, 1, s, &private->phantom_ctls[i]);
3798 if (info->phantom_count &&
3799 scarlett2_has_config_item(private,
3800 SCARLETT2_CONFIG_PHANTOM_PERSISTENCE)) {
3801 err = scarlett2_add_new_ctl(
3802 mixer, &scarlett2_phantom_persistence_ctl, 0, 1,
3803 "Phantom Power Persistence Capture Switch", NULL);
3811 /*** Mixer Volume Controls ***/
3813 static int scarlett2_mixer_ctl_info(struct snd_kcontrol *kctl,
3814 struct snd_ctl_elem_info *uinfo)
3816 struct usb_mixer_elem_info *elem = kctl->private_data;
3818 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3819 uinfo->count = elem->channels;
3820 uinfo->value.integer.min = 0;
3821 uinfo->value.integer.max = SCARLETT2_MIXER_MAX_VALUE;
3822 uinfo->value.integer.step = 1;
3826 static int scarlett2_mixer_ctl_get(struct snd_kcontrol *kctl,
3827 struct snd_ctl_elem_value *ucontrol)
3829 struct usb_mixer_elem_info *elem = kctl->private_data;
3830 struct scarlett2_data *private = elem->head.mixer->private_data;
3832 ucontrol->value.integer.value[0] = private->mix[elem->control];
3836 static int scarlett2_mixer_ctl_put(struct snd_kcontrol *kctl,
3837 struct snd_ctl_elem_value *ucontrol)
3839 struct usb_mixer_elem_info *elem = kctl->private_data;
3840 struct usb_mixer_interface *mixer = elem->head.mixer;
3841 struct scarlett2_data *private = mixer->private_data;
3842 int oval, val, mix_num, err = 0;
3843 int index = elem->control;
3845 mutex_lock(&private->data_mutex);
3847 if (private->hwdep_in_use) {
3852 oval = private->mix[index];
3853 val = clamp(ucontrol->value.integer.value[0],
3854 0L, (long)SCARLETT2_MIXER_MAX_VALUE);
3855 mix_num = index / private->num_mix_in;
3860 private->mix[index] = val;
3861 err = scarlett2_usb_set_mix(mixer, mix_num);
3866 mutex_unlock(&private->data_mutex);
3870 static const DECLARE_TLV_DB_MINMAX(
3871 db_scale_scarlett2_mixer,
3872 SCARLETT2_MIXER_MIN_DB * 100,
3873 SCARLETT2_MIXER_MAX_DB * 100
3876 static const struct snd_kcontrol_new scarlett2_mixer_ctl = {
3877 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3878 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
3879 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
3881 .info = scarlett2_mixer_ctl_info,
3882 .get = scarlett2_mixer_ctl_get,
3883 .put = scarlett2_mixer_ctl_put,
3884 .private_value = SCARLETT2_MIXER_MAX_DB, /* max value */
3885 .tlv = { .p = db_scale_scarlett2_mixer }
3888 static int scarlett2_add_mixer_ctls(struct usb_mixer_interface *mixer)
3890 struct scarlett2_data *private = mixer->private_data;
3893 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
3895 for (i = 0, index = 0; i < private->num_mix_out; i++)
3896 for (j = 0; j < private->num_mix_in; j++, index++) {
3897 snprintf(s, sizeof(s),
3898 "Mix %c Input %02d Playback Volume",
3900 err = scarlett2_add_new_ctl(mixer, &scarlett2_mixer_ctl,
3909 /*** Direct Monitor Control ***/
3911 static int scarlett2_update_direct_monitor(struct usb_mixer_interface *mixer)
3913 struct scarlett2_data *private = mixer->private_data;
3915 private->direct_monitor_updated = 0;
3917 if (!private->info->direct_monitor)
3920 return scarlett2_usb_get_config(
3921 mixer, SCARLETT2_CONFIG_DIRECT_MONITOR,
3922 1, &private->direct_monitor_switch);
3925 static int scarlett2_direct_monitor_ctl_get(
3926 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3928 struct usb_mixer_elem_info *elem = kctl->private_data;
3929 struct usb_mixer_interface *mixer = elem->head.mixer;
3930 struct scarlett2_data *private = elem->head.mixer->private_data;
3933 mutex_lock(&private->data_mutex);
3935 if (private->hwdep_in_use) {
3940 if (private->direct_monitor_updated) {
3941 err = scarlett2_update_direct_monitor(mixer);
3945 ucontrol->value.enumerated.item[0] = private->direct_monitor_switch;
3948 mutex_unlock(&private->data_mutex);
3952 static int scarlett2_direct_monitor_ctl_put(
3953 struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
3955 struct usb_mixer_elem_info *elem = kctl->private_data;
3956 struct usb_mixer_interface *mixer = elem->head.mixer;
3957 struct scarlett2_data *private = mixer->private_data;
3959 int index = elem->control;
3960 int oval, val, err = 0;
3962 mutex_lock(&private->data_mutex);
3964 if (private->hwdep_in_use) {
3969 oval = private->direct_monitor_switch;
3970 val = min(ucontrol->value.enumerated.item[0], 2U);
3975 private->direct_monitor_switch = val;
3977 /* Send switch change to the device */
3978 err = scarlett2_usb_set_config(
3979 mixer, SCARLETT2_CONFIG_DIRECT_MONITOR, index, val);
3984 mutex_unlock(&private->data_mutex);
3988 static int scarlett2_direct_monitor_stereo_enum_ctl_info(
3989 struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
3991 static const char *const values[3] = {
3992 "Off", "Mono", "Stereo"
3995 return snd_ctl_enum_info(uinfo, 1, 3, values);
3998 /* Direct Monitor for Solo is mono-only and only needs a boolean control
3999 * Direct Monitor for 2i2 is selectable between Off/Mono/Stereo
4001 static const struct snd_kcontrol_new scarlett2_direct_monitor_ctl[2] = {
4003 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4005 .info = snd_ctl_boolean_mono_info,
4006 .get = scarlett2_direct_monitor_ctl_get,
4007 .put = scarlett2_direct_monitor_ctl_put,
4010 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4012 .info = scarlett2_direct_monitor_stereo_enum_ctl_info,
4013 .get = scarlett2_direct_monitor_ctl_get,
4014 .put = scarlett2_direct_monitor_ctl_put,
4018 static int scarlett2_add_direct_monitor_ctl(struct usb_mixer_interface *mixer)
4020 struct scarlett2_data *private = mixer->private_data;
4021 const struct scarlett2_device_info *info = private->info;
4024 if (!info->direct_monitor)
4027 s = info->direct_monitor == 1
4028 ? "Direct Monitor Playback Switch"
4029 : "Direct Monitor Playback Enum";
4031 return scarlett2_add_new_ctl(
4032 mixer, &scarlett2_direct_monitor_ctl[info->direct_monitor - 1],
4033 0, 1, s, &private->direct_monitor_ctl);
4036 /*** Mux Source Selection Controls ***/
4038 static int scarlett2_mux_src_enum_ctl_info(struct snd_kcontrol *kctl,
4039 struct snd_ctl_elem_info *uinfo)
4041 struct usb_mixer_elem_info *elem = kctl->private_data;
4042 struct scarlett2_data *private = elem->head.mixer->private_data;
4043 const struct scarlett2_device_info *info = private->info;
4044 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
4045 unsigned int item = uinfo->value.enumerated.item;
4046 int items = private->num_mux_srcs;
4049 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4050 uinfo->count = elem->channels;
4051 uinfo->value.enumerated.items = items;
4054 item = uinfo->value.enumerated.item = items - 1;
4057 port_type < SCARLETT2_PORT_TYPE_COUNT;
4059 if (item < port_count[port_type][SCARLETT2_PORT_IN]) {
4060 const struct scarlett2_port *port =
4061 &scarlett2_ports[port_type];
4063 sprintf(uinfo->value.enumerated.name,
4064 port->src_descr, item + port->src_num_offset);
4067 item -= port_count[port_type][SCARLETT2_PORT_IN];
4073 static int scarlett2_mux_src_enum_ctl_get(struct snd_kcontrol *kctl,
4074 struct snd_ctl_elem_value *ucontrol)
4076 struct usb_mixer_elem_info *elem = kctl->private_data;
4077 struct usb_mixer_interface *mixer = elem->head.mixer;
4078 struct scarlett2_data *private = mixer->private_data;
4079 int index = line_out_remap(private, elem->control);
4082 mutex_lock(&private->data_mutex);
4084 if (private->hwdep_in_use) {
4089 if (private->mux_updated) {
4090 err = scarlett2_usb_get_mux(mixer);
4094 ucontrol->value.enumerated.item[0] = private->mux[index];
4097 mutex_unlock(&private->data_mutex);
4101 static int scarlett2_mux_src_enum_ctl_put(struct snd_kcontrol *kctl,
4102 struct snd_ctl_elem_value *ucontrol)
4104 struct usb_mixer_elem_info *elem = kctl->private_data;
4105 struct usb_mixer_interface *mixer = elem->head.mixer;
4106 struct scarlett2_data *private = mixer->private_data;
4107 int index = line_out_remap(private, elem->control);
4108 int oval, val, err = 0;
4110 mutex_lock(&private->data_mutex);
4112 if (private->hwdep_in_use) {
4117 oval = private->mux[index];
4118 val = min(ucontrol->value.enumerated.item[0],
4119 private->num_mux_srcs - 1U);
4124 private->mux[index] = val;
4125 err = scarlett2_usb_set_mux(mixer);
4130 mutex_unlock(&private->data_mutex);
4134 static const struct snd_kcontrol_new scarlett2_mux_src_enum_ctl = {
4135 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4137 .info = scarlett2_mux_src_enum_ctl_info,
4138 .get = scarlett2_mux_src_enum_ctl_get,
4139 .put = scarlett2_mux_src_enum_ctl_put,
4142 static int scarlett2_add_mux_enums(struct usb_mixer_interface *mixer)
4144 struct scarlett2_data *private = mixer->private_data;
4145 const struct scarlett2_device_info *info = private->info;
4146 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
4147 int port_type, channel, i;
4149 for (i = 0, port_type = 0;
4150 port_type < SCARLETT2_PORT_TYPE_COUNT;
4153 channel < port_count[port_type][SCARLETT2_PORT_OUT];
4156 char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
4157 const char *const descr =
4158 scarlett2_ports[port_type].dst_descr;
4160 snprintf(s, sizeof(s) - 5, descr, channel + 1);
4163 err = scarlett2_add_new_ctl(mixer,
4164 &scarlett2_mux_src_enum_ctl,
4166 &private->mux_ctls[i]);
4175 /*** Meter Controls ***/
4177 static int scarlett2_meter_ctl_info(struct snd_kcontrol *kctl,
4178 struct snd_ctl_elem_info *uinfo)
4180 struct usb_mixer_elem_info *elem = kctl->private_data;
4182 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
4183 uinfo->count = elem->channels;
4184 uinfo->value.integer.min = 0;
4185 uinfo->value.integer.max = 4095;
4186 uinfo->value.integer.step = 1;
4190 static int scarlett2_meter_ctl_get(struct snd_kcontrol *kctl,
4191 struct snd_ctl_elem_value *ucontrol)
4193 struct usb_mixer_elem_info *elem = kctl->private_data;
4194 struct scarlett2_data *private = elem->head.mixer->private_data;
4195 u8 *meter_level_map = private->meter_level_map;
4196 u16 meter_levels[SCARLETT2_MAX_METERS];
4199 mutex_lock(&private->data_mutex);
4201 if (private->hwdep_in_use) {
4206 err = scarlett2_usb_get_meter_levels(elem->head.mixer, elem->channels,
4211 /* copy & translate from meter_levels[] using meter_level_map[] */
4212 for (i = 0; i < elem->channels; i++) {
4213 int idx = meter_level_map[i];
4219 value = meter_levels[idx];
4221 ucontrol->value.integer.value[i] = value;
4225 mutex_unlock(&private->data_mutex);
4230 static const struct snd_kcontrol_new scarlett2_meter_ctl = {
4231 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
4232 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
4234 .info = scarlett2_meter_ctl_info,
4235 .get = scarlett2_meter_ctl_get
4238 static int scarlett2_add_meter_ctl(struct usb_mixer_interface *mixer)
4240 struct scarlett2_data *private = mixer->private_data;
4242 /* devices without a mixer also don't support reporting levels */
4243 if (!scarlett2_has_mixer(private))
4246 return scarlett2_add_new_ctl(mixer, &scarlett2_meter_ctl,
4247 0, private->num_mux_dsts,
4248 "Level Meter", NULL);
4251 /*** MSD Controls ***/
4253 static int scarlett2_msd_ctl_get(struct snd_kcontrol *kctl,
4254 struct snd_ctl_elem_value *ucontrol)
4256 struct usb_mixer_elem_info *elem = kctl->private_data;
4257 struct scarlett2_data *private = elem->head.mixer->private_data;
4259 ucontrol->value.integer.value[0] = private->msd_switch;
4263 static int scarlett2_msd_ctl_put(struct snd_kcontrol *kctl,
4264 struct snd_ctl_elem_value *ucontrol)
4266 struct usb_mixer_elem_info *elem = kctl->private_data;
4267 struct usb_mixer_interface *mixer = elem->head.mixer;
4268 struct scarlett2_data *private = mixer->private_data;
4270 int oval, val, err = 0;
4272 mutex_lock(&private->data_mutex);
4274 if (private->hwdep_in_use) {
4279 oval = private->msd_switch;
4280 val = !!ucontrol->value.integer.value[0];
4285 private->msd_switch = val;
4287 /* Send switch change to the device */
4288 err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_MSD_SWITCH,
4294 mutex_unlock(&private->data_mutex);
4298 static const struct snd_kcontrol_new scarlett2_msd_ctl = {
4299 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4301 .info = snd_ctl_boolean_mono_info,
4302 .get = scarlett2_msd_ctl_get,
4303 .put = scarlett2_msd_ctl_put,
4306 static int scarlett2_add_msd_ctl(struct usb_mixer_interface *mixer)
4308 struct scarlett2_data *private = mixer->private_data;
4310 if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_MSD_SWITCH))
4313 /* If MSD mode is off, hide the switch by default */
4314 if (!private->msd_switch && !(mixer->chip->setup & SCARLETT2_MSD_ENABLE))
4317 /* Add MSD control */
4318 return scarlett2_add_new_ctl(mixer, &scarlett2_msd_ctl,
4319 0, 1, "MSD Mode Switch", NULL);
4322 /*** Standalone Control ***/
4324 static int scarlett2_standalone_ctl_get(struct snd_kcontrol *kctl,
4325 struct snd_ctl_elem_value *ucontrol)
4327 struct usb_mixer_elem_info *elem = kctl->private_data;
4328 struct scarlett2_data *private = elem->head.mixer->private_data;
4330 ucontrol->value.integer.value[0] = private->standalone_switch;
4334 static int scarlett2_standalone_ctl_put(struct snd_kcontrol *kctl,
4335 struct snd_ctl_elem_value *ucontrol)
4337 struct usb_mixer_elem_info *elem = kctl->private_data;
4338 struct usb_mixer_interface *mixer = elem->head.mixer;
4339 struct scarlett2_data *private = mixer->private_data;
4341 int oval, val, err = 0;
4343 mutex_lock(&private->data_mutex);
4345 if (private->hwdep_in_use) {
4350 oval = private->standalone_switch;
4351 val = !!ucontrol->value.integer.value[0];
4356 private->standalone_switch = val;
4358 /* Send switch change to the device */
4359 err = scarlett2_usb_set_config(mixer,
4360 SCARLETT2_CONFIG_STANDALONE_SWITCH,
4366 mutex_unlock(&private->data_mutex);
4370 static const struct snd_kcontrol_new scarlett2_standalone_ctl = {
4371 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4373 .info = snd_ctl_boolean_mono_info,
4374 .get = scarlett2_standalone_ctl_get,
4375 .put = scarlett2_standalone_ctl_put,
4378 static int scarlett2_add_standalone_ctl(struct usb_mixer_interface *mixer)
4380 struct scarlett2_data *private = mixer->private_data;
4382 if (!scarlett2_has_config_item(private,
4383 SCARLETT2_CONFIG_STANDALONE_SWITCH))
4386 /* Add standalone control */
4387 return scarlett2_add_new_ctl(mixer, &scarlett2_standalone_ctl,
4388 0, 1, "Standalone Switch", NULL);
4391 /*** Cleanup/Suspend Callbacks ***/
4393 static void scarlett2_private_free(struct usb_mixer_interface *mixer)
4395 struct scarlett2_data *private = mixer->private_data;
4397 cancel_delayed_work_sync(&private->work);
4399 mixer->private_data = NULL;
4402 static void scarlett2_private_suspend(struct usb_mixer_interface *mixer)
4404 struct scarlett2_data *private = mixer->private_data;
4406 if (cancel_delayed_work_sync(&private->work))
4407 scarlett2_config_save(private->mixer);
4410 /*** Initialisation ***/
4412 static void scarlett2_count_io(struct scarlett2_data *private)
4414 const struct scarlett2_device_info *info = private->info;
4415 const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
4416 int port_type, srcs = 0, dsts = 0;
4418 /* Count the number of mux sources and destinations */
4420 port_type < SCARLETT2_PORT_TYPE_COUNT;
4422 srcs += port_count[port_type][SCARLETT2_PORT_IN];
4423 dsts += port_count[port_type][SCARLETT2_PORT_OUT];
4426 private->num_mux_srcs = srcs;
4427 private->num_mux_dsts = dsts;
4429 /* Mixer inputs are mux outputs and vice versa */
4430 private->num_mix_in =
4431 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
4433 private->num_mix_out =
4434 port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_IN];
4436 /* Number of analogue line outputs */
4437 private->num_line_out =
4438 port_count[SCARLETT2_PORT_TYPE_ANALOGUE][SCARLETT2_PORT_OUT];
4441 /* Look through the interface descriptors for the Focusrite Control
4442 * interface (bInterfaceClass = 255 Vendor Specific Class) and set
4443 * bInterfaceNumber, bEndpointAddress, wMaxPacketSize, and bInterval
4446 static int scarlett2_find_fc_interface(struct usb_device *dev,
4447 struct scarlett2_data *private)
4449 struct usb_host_config *config = dev->actconfig;
4452 for (i = 0; i < config->desc.bNumInterfaces; i++) {
4453 struct usb_interface *intf = config->interface[i];
4454 struct usb_interface_descriptor *desc =
4455 &intf->altsetting[0].desc;
4456 struct usb_endpoint_descriptor *epd;
4458 if (desc->bInterfaceClass != 255)
4461 epd = get_endpoint(intf->altsetting, 0);
4462 private->bInterfaceNumber = desc->bInterfaceNumber;
4463 private->bEndpointAddress = epd->bEndpointAddress &
4464 USB_ENDPOINT_NUMBER_MASK;
4465 private->wMaxPacketSize = le16_to_cpu(epd->wMaxPacketSize);
4466 private->bInterval = epd->bInterval;
4473 /* Initialise private data */
4474 static int scarlett2_init_private(struct usb_mixer_interface *mixer,
4475 const struct scarlett2_device_entry *entry)
4477 struct scarlett2_data *private =
4478 kzalloc(sizeof(struct scarlett2_data), GFP_KERNEL);
4483 mutex_init(&private->usb_mutex);
4484 mutex_init(&private->data_mutex);
4485 INIT_DELAYED_WORK(&private->work, scarlett2_config_save_work);
4487 mixer->private_data = private;
4488 mixer->private_free = scarlett2_private_free;
4489 mixer->private_suspend = scarlett2_private_suspend;
4491 private->info = entry->info;
4492 private->config_set = entry->info->config_set;
4493 private->series_name = entry->series_name;
4494 scarlett2_count_io(private);
4495 private->scarlett2_seq = 0;
4496 private->mixer = mixer;
4498 return scarlett2_find_fc_interface(mixer->chip->dev, private);
4501 /* Cargo cult proprietary initialisation sequence */
4502 static int scarlett2_usb_init(struct usb_mixer_interface *mixer)
4504 struct usb_device *dev = mixer->chip->dev;
4505 struct scarlett2_data *private = mixer->private_data;
4510 if (usb_pipe_type_check(dev, usb_sndctrlpipe(dev, 0)))
4514 err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
4515 SCARLETT2_USB_CMD_INIT,
4516 step0_buf, sizeof(step0_buf));
4521 private->scarlett2_seq = 1;
4522 err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_1, NULL, 0, NULL, 0);
4527 private->scarlett2_seq = 1;
4528 err = scarlett2_usb(mixer, SCARLETT2_USB_INIT_2,
4530 step2_buf, sizeof(step2_buf));
4534 /* extract 4-byte firmware version from step2_buf[8] */
4535 private->firmware_version = le32_to_cpu(*(__le32 *)(step2_buf + 8));
4536 usb_audio_info(mixer->chip,
4537 "Firmware version %d\n",
4538 private->firmware_version);
4543 /* Get the flash segment numbers for the App_Settings and App_Upgrade
4544 * segments and put them in the private data
4546 static int scarlett2_get_flash_segment_nums(struct usb_mixer_interface *mixer)
4548 struct scarlett2_data *private = mixer->private_data;
4555 } __packed flash_info;
4561 } __packed segment_info;
4563 err = scarlett2_usb(mixer, SCARLETT2_USB_INFO_FLASH,
4565 &flash_info, sizeof(flash_info));
4569 count = le32_to_cpu(flash_info.count);
4571 /* sanity check count */
4572 if (count < SCARLETT2_SEGMENT_NUM_MIN ||
4573 count > SCARLETT2_SEGMENT_NUM_MAX + 1) {
4574 usb_audio_err(mixer->chip,
4575 "invalid flash segment count: %d\n", count);
4579 for (i = 0; i < count; i++) {
4580 __le32 segment_num_req = cpu_to_le32(i);
4581 int flash_segment_id;
4583 err = scarlett2_usb(mixer, SCARLETT2_USB_INFO_SEGMENT,
4584 &segment_num_req, sizeof(segment_num_req),
4585 &segment_info, sizeof(segment_info));
4587 usb_audio_err(mixer->chip,
4588 "failed to get flash segment info %d: %d\n",
4593 if (!strncmp(segment_info.name,
4594 SCARLETT2_SEGMENT_SETTINGS_NAME, 16))
4595 flash_segment_id = SCARLETT2_SEGMENT_ID_SETTINGS;
4596 else if (!strncmp(segment_info.name,
4597 SCARLETT2_SEGMENT_FIRMWARE_NAME, 16))
4598 flash_segment_id = SCARLETT2_SEGMENT_ID_FIRMWARE;
4602 private->flash_segment_nums[flash_segment_id] = i;
4603 private->flash_segment_blocks[flash_segment_id] =
4604 le32_to_cpu(segment_info.size) /
4605 SCARLETT2_FLASH_BLOCK_SIZE;
4608 /* segment 0 is App_Gold and we never want to touch that, so
4609 * use 0 as the "not-found" value
4611 if (!private->flash_segment_nums[SCARLETT2_SEGMENT_ID_SETTINGS]) {
4612 usb_audio_err(mixer->chip,
4613 "failed to find flash segment %s\n",
4614 SCARLETT2_SEGMENT_SETTINGS_NAME);
4617 if (!private->flash_segment_nums[SCARLETT2_SEGMENT_ID_FIRMWARE]) {
4618 usb_audio_err(mixer->chip,
4619 "failed to find flash segment %s\n",
4620 SCARLETT2_SEGMENT_FIRMWARE_NAME);
4627 /* Read configuration from the interface on start */
4628 static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
4630 struct scarlett2_data *private = mixer->private_data;
4633 if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_MSD_SWITCH)) {
4634 err = scarlett2_usb_get_config(
4635 mixer, SCARLETT2_CONFIG_MSD_SWITCH,
4636 1, &private->msd_switch);
4640 /* no other controls are created if MSD mode is on */
4641 if (private->msd_switch)
4645 err = scarlett2_update_input_level(mixer);
4649 err = scarlett2_update_input_pad(mixer);
4653 err = scarlett2_update_input_air(mixer);
4657 err = scarlett2_update_input_phantom(mixer);
4661 err = scarlett2_update_direct_monitor(mixer);
4665 /* the rest of the configuration is for devices with a mixer */
4666 if (!scarlett2_has_mixer(private))
4669 err = scarlett2_update_monitor_other(mixer);
4673 if (scarlett2_has_config_item(private,
4674 SCARLETT2_CONFIG_STANDALONE_SWITCH)) {
4675 err = scarlett2_usb_get_config(
4676 mixer, SCARLETT2_CONFIG_STANDALONE_SWITCH,
4677 1, &private->standalone_switch);
4682 err = scarlett2_update_sync(mixer);
4686 if (scarlett2_has_config_item(private,
4687 SCARLETT2_CONFIG_LINE_OUT_VOLUME)) {
4688 s16 sw_vol[SCARLETT2_ANALOGUE_MAX];
4690 /* read SW line out volume */
4691 err = scarlett2_usb_get_config(
4692 mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
4693 private->num_line_out, &sw_vol);
4697 for (i = 0; i < private->num_line_out; i++)
4698 private->vol[i] = clamp(
4699 sw_vol[i] + SCARLETT2_VOLUME_BIAS,
4700 0, SCARLETT2_VOLUME_BIAS);
4703 err = scarlett2_usb_get_config(
4704 mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
4705 private->num_line_out, &private->mute_switch);
4709 for (i = 0; i < private->num_line_out; i++)
4710 private->mute_switch[i] =
4711 !!private->mute_switch[i];
4713 /* read SW/HW switches */
4714 if (scarlett2_has_config_item(private,
4715 SCARLETT2_CONFIG_SW_HW_SWITCH)) {
4716 err = scarlett2_usb_get_config(
4717 mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
4718 private->num_line_out,
4719 &private->vol_sw_hw_switch);
4723 for (i = 0; i < private->num_line_out; i++)
4724 private->vol_sw_hw_switch[i] =
4725 !!private->vol_sw_hw_switch[i];
4729 err = scarlett2_update_volumes(mixer);
4733 err = scarlett2_update_dim_mute(mixer);
4737 for (i = 0; i < private->num_mix_out; i++) {
4738 err = scarlett2_usb_get_mix(mixer, i);
4743 return scarlett2_usb_get_mux(mixer);
4746 /* Notify on sync change */
4747 static void scarlett2_notify_sync(struct usb_mixer_interface *mixer)
4749 struct scarlett2_data *private = mixer->private_data;
4751 private->sync_updated = 1;
4753 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
4754 &private->sync_ctl->id);
4757 /* Notify on monitor change */
4758 static void scarlett2_notify_monitor(struct usb_mixer_interface *mixer)
4760 struct snd_card *card = mixer->chip->card;
4761 struct scarlett2_data *private = mixer->private_data;
4764 if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_SW_HW_SWITCH))
4767 private->vol_updated = 1;
4769 snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
4770 &private->master_vol_ctl->id);
4772 for (i = 0; i < private->num_line_out; i++)
4773 if (private->vol_sw_hw_switch[line_out_remap(private, i)])
4774 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4775 &private->vol_ctls[i]->id);
4778 /* Notify on dim/mute change */
4779 static void scarlett2_notify_dim_mute(struct usb_mixer_interface *mixer)
4781 struct snd_card *card = mixer->chip->card;
4782 struct scarlett2_data *private = mixer->private_data;
4785 if (!scarlett2_has_config_item(private, SCARLETT2_CONFIG_SW_HW_SWITCH))
4788 private->dim_mute_updated = 1;
4790 for (i = 0; i < SCARLETT2_DIM_MUTE_COUNT; i++)
4791 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4792 &private->dim_mute_ctls[i]->id);
4794 for (i = 0; i < private->num_line_out; i++)
4795 if (private->vol_sw_hw_switch[line_out_remap(private, i)])
4796 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4797 &private->mute_ctls[i]->id);
4800 /* Notify on input level switch change */
4801 static void scarlett2_notify_input_level(struct usb_mixer_interface *mixer)
4803 struct snd_card *card = mixer->chip->card;
4804 struct scarlett2_data *private = mixer->private_data;
4805 const struct scarlett2_device_info *info = private->info;
4808 private->input_level_updated = 1;
4810 for (i = 0; i < info->level_input_count; i++)
4811 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4812 &private->level_ctls[i]->id);
4815 /* Notify on input pad switch change */
4816 static void scarlett2_notify_input_pad(struct usb_mixer_interface *mixer)
4818 struct snd_card *card = mixer->chip->card;
4819 struct scarlett2_data *private = mixer->private_data;
4820 const struct scarlett2_device_info *info = private->info;
4823 private->input_pad_updated = 1;
4825 for (i = 0; i < info->pad_input_count; i++)
4826 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4827 &private->pad_ctls[i]->id);
4830 /* Notify on input air switch change */
4831 static void scarlett2_notify_input_air(struct usb_mixer_interface *mixer)
4833 struct snd_card *card = mixer->chip->card;
4834 struct scarlett2_data *private = mixer->private_data;
4835 const struct scarlett2_device_info *info = private->info;
4838 private->input_air_updated = 1;
4840 for (i = 0; i < info->air_input_count; i++)
4841 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4842 &private->air_ctls[i]->id);
4845 /* Notify on input phantom switch change */
4846 static void scarlett2_notify_input_phantom(struct usb_mixer_interface *mixer)
4848 struct snd_card *card = mixer->chip->card;
4849 struct scarlett2_data *private = mixer->private_data;
4850 const struct scarlett2_device_info *info = private->info;
4853 private->input_phantom_updated = 1;
4855 for (i = 0; i < info->phantom_count; i++)
4856 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4857 &private->phantom_ctls[i]->id);
4860 /* Notify on "input other" change (level/pad/air/phantom) */
4861 static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer)
4863 scarlett2_notify_input_level(mixer);
4864 scarlett2_notify_input_pad(mixer);
4865 scarlett2_notify_input_air(mixer);
4866 scarlett2_notify_input_phantom(mixer);
4869 /* Notify on "monitor other" change (speaker switching, talkback) */
4870 static void scarlett2_notify_monitor_other(struct usb_mixer_interface *mixer)
4872 struct snd_card *card = mixer->chip->card;
4873 struct scarlett2_data *private = mixer->private_data;
4874 const struct scarlett2_device_info *info = private->info;
4876 private->monitor_other_updated = 1;
4878 if (info->has_speaker_switching)
4879 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4880 &private->speaker_switching_ctl->id);
4882 if (info->has_talkback)
4883 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4884 &private->talkback_ctl->id);
4886 /* if speaker switching was recently enabled or disabled,
4887 * invalidate the dim/mute and mux enum controls
4889 if (private->speaker_switching_switched) {
4892 scarlett2_notify_dim_mute(mixer);
4894 private->speaker_switching_switched = 0;
4895 private->mux_updated = 1;
4897 for (i = 0; i < private->num_mux_dsts; i++)
4898 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4899 &private->mux_ctls[i]->id);
4903 /* Notify on direct monitor switch change */
4904 static void scarlett2_notify_direct_monitor(struct usb_mixer_interface *mixer)
4906 struct snd_card *card = mixer->chip->card;
4907 struct scarlett2_data *private = mixer->private_data;
4909 private->direct_monitor_updated = 1;
4911 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
4912 &private->direct_monitor_ctl->id);
4915 /* Interrupt callback */
4916 static void scarlett2_notify(struct urb *urb)
4918 struct usb_mixer_interface *mixer = urb->context;
4919 int len = urb->actual_length;
4920 int ustatus = urb->status;
4922 struct scarlett2_data *private = mixer->private_data;
4923 const struct scarlett2_notification *notifications =
4924 private->config_set->notifications;
4926 if (ustatus != 0 || len != 8)
4929 data = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
4931 while (data && notifications->mask) {
4932 if (data & notifications->mask) {
4933 data &= ~notifications->mask;
4934 if (notifications->func)
4935 notifications->func(mixer);
4941 usb_audio_warn(mixer->chip,
4942 "%s: Unhandled notification: 0x%08x\n",
4946 if (ustatus != -ENOENT &&
4947 ustatus != -ECONNRESET &&
4948 ustatus != -ESHUTDOWN) {
4949 urb->dev = mixer->chip->dev;
4950 usb_submit_urb(urb, GFP_ATOMIC);
4954 static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
4956 struct usb_device *dev = mixer->chip->dev;
4957 struct scarlett2_data *private = mixer->private_data;
4958 unsigned int pipe = usb_rcvintpipe(dev, private->bEndpointAddress);
4959 void *transfer_buffer;
4962 usb_audio_err(mixer->chip,
4963 "%s: mixer urb already in use!\n", __func__);
4967 if (usb_pipe_type_check(dev, pipe))
4970 mixer->urb = usb_alloc_urb(0, GFP_KERNEL);
4974 transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
4975 if (!transfer_buffer)
4978 usb_fill_int_urb(mixer->urb, dev, pipe,
4979 transfer_buffer, private->wMaxPacketSize,
4980 scarlett2_notify, mixer, private->bInterval);
4982 return usb_submit_urb(mixer->urb, GFP_KERNEL);
4985 static const struct scarlett2_device_entry *get_scarlett2_device_entry(
4986 struct usb_mixer_interface *mixer)
4988 const struct scarlett2_device_entry *entry = scarlett2_devices;
4990 /* Find entry in scarlett2_devices */
4991 while (entry->usb_id && entry->usb_id != mixer->chip->usb_id)
4999 static int snd_scarlett2_controls_create(
5000 struct usb_mixer_interface *mixer,
5001 const struct scarlett2_device_entry *entry)
5005 /* Initialise private data */
5006 err = scarlett2_init_private(mixer, entry);
5010 /* Send proprietary USB initialisation sequence */
5011 err = scarlett2_usb_init(mixer);
5015 /* Get the upgrade & settings flash segment numbers */
5016 err = scarlett2_get_flash_segment_nums(mixer);
5020 /* Add firmware version control */
5021 err = scarlett2_add_firmware_version_ctl(mixer);
5025 /* Read volume levels and controls from the interface */
5026 err = scarlett2_read_configs(mixer);
5030 /* Create the MSD control */
5031 err = scarlett2_add_msd_ctl(mixer);
5035 /* If MSD mode is enabled, don't create any other controls */
5036 if (((struct scarlett2_data *)mixer->private_data)->msd_switch)
5039 /* Create the analogue output controls */
5040 err = scarlett2_add_line_out_ctls(mixer);
5044 /* Create the analogue input controls */
5045 err = scarlett2_add_line_in_ctls(mixer);
5049 /* Create the input, output, and mixer mux input selections */
5050 err = scarlett2_add_mux_enums(mixer);
5054 /* Create the matrix mixer controls */
5055 err = scarlett2_add_mixer_ctls(mixer);
5059 /* Create the level meter controls */
5060 err = scarlett2_add_meter_ctl(mixer);
5064 /* Create the sync control */
5065 err = scarlett2_add_sync_ctl(mixer);
5069 /* Create the direct monitor control */
5070 err = scarlett2_add_direct_monitor_ctl(mixer);
5074 /* Create the speaker switching control */
5075 err = scarlett2_add_speaker_switch_ctl(mixer);
5079 /* Create the talkback controls */
5080 err = scarlett2_add_talkback_ctls(mixer);
5084 /* Create the standalone control */
5085 err = scarlett2_add_standalone_ctl(mixer);
5089 /* Set up the interrupt polling */
5090 err = scarlett2_init_notify(mixer);
5097 /*** hwdep interface ***/
5099 /* Set private->hwdep_in_use; prevents access to the ALSA controls
5100 * while doing a config erase/firmware upgrade.
5102 static void scarlett2_lock(struct scarlett2_data *private)
5104 mutex_lock(&private->data_mutex);
5105 private->hwdep_in_use = 1;
5106 mutex_unlock(&private->data_mutex);
5109 /* Call SCARLETT2_USB_GET_ERASE to get the erase progress */
5110 static int scarlett2_get_erase_progress(struct usb_mixer_interface *mixer)
5112 struct scarlett2_data *private = mixer->private_data;
5113 int segment_id, segment_num, err;
5119 } __packed erase_req;
5121 segment_id = private->selected_flash_segment_id;
5122 segment_num = private->flash_segment_nums[segment_id];
5124 if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
5125 segment_num > SCARLETT2_SEGMENT_NUM_MAX)
5128 /* Send the erase progress request */
5129 erase_req.segment_num = cpu_to_le32(segment_num);
5132 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_ERASE,
5133 &erase_req, sizeof(erase_req),
5134 &erase_resp, sizeof(erase_resp));
5141 /* Repeatedly call scarlett2_get_erase_progress() until it returns
5142 * 0xff (erase complete) or we've waited 10 seconds (it usually takes
5145 static int scarlett2_wait_for_erase(struct usb_mixer_interface *mixer)
5149 for (i = 0; i < 100; i++) {
5150 err = scarlett2_get_erase_progress(mixer);
5163 /* Reboot the device; wait for the erase to complete if one is in
5166 static int scarlett2_reboot(struct usb_mixer_interface *mixer)
5168 struct scarlett2_data *private = mixer->private_data;
5170 if (private->flash_write_state ==
5171 SCARLETT2_FLASH_WRITE_STATE_ERASING) {
5172 int err = scarlett2_wait_for_erase(mixer);
5178 return scarlett2_usb(mixer, SCARLETT2_USB_REBOOT, NULL, 0, NULL, 0);
5181 /* Select a flash segment for erasing (and possibly writing to) */
5182 static int scarlett2_ioctl_select_flash_segment(
5183 struct usb_mixer_interface *mixer,
5186 struct scarlett2_data *private = mixer->private_data;
5187 int segment_id, segment_num;
5189 if (get_user(segment_id, (int __user *)arg))
5192 /* Check the segment ID and segment number */
5193 if (segment_id < 0 || segment_id >= SCARLETT2_SEGMENT_ID_COUNT)
5196 segment_num = private->flash_segment_nums[segment_id];
5197 if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
5198 segment_num > SCARLETT2_SEGMENT_NUM_MAX) {
5199 usb_audio_err(mixer->chip,
5200 "%s: invalid segment number %d\n",
5201 __func__, segment_id);
5205 /* If erasing, wait for it to complete */
5206 if (private->flash_write_state == SCARLETT2_FLASH_WRITE_STATE_ERASING) {
5207 int err = scarlett2_wait_for_erase(mixer);
5213 /* Save the selected segment ID and set the state to SELECTED */
5214 private->selected_flash_segment_id = segment_id;
5215 private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_SELECTED;
5220 /* Erase the previously-selected flash segment */
5221 static int scarlett2_ioctl_erase_flash_segment(
5222 struct usb_mixer_interface *mixer)
5224 struct scarlett2_data *private = mixer->private_data;
5225 int segment_id, segment_num, err;
5230 } __packed erase_req;
5232 if (private->flash_write_state != SCARLETT2_FLASH_WRITE_STATE_SELECTED)
5235 segment_id = private->selected_flash_segment_id;
5236 segment_num = private->flash_segment_nums[segment_id];
5238 if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
5239 segment_num > SCARLETT2_SEGMENT_NUM_MAX)
5242 /* Prevent access to ALSA controls that access the device from
5245 scarlett2_lock(private);
5247 /* Send the erase request */
5248 erase_req.segment_num = cpu_to_le32(segment_num);
5251 err = scarlett2_usb(mixer, SCARLETT2_USB_ERASE_SEGMENT,
5252 &erase_req, sizeof(erase_req),
5257 /* On success, change the state from SELECTED to ERASING */
5258 private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_ERASING;
5263 /* Get the erase progress from the device */
5264 static int scarlett2_ioctl_get_erase_progress(
5265 struct usb_mixer_interface *mixer,
5268 struct scarlett2_data *private = mixer->private_data;
5269 struct scarlett2_flash_segment_erase_progress progress;
5270 int segment_id, segment_num, err;
5276 } __packed erase_req;
5278 /* Check that we're erasing */
5279 if (private->flash_write_state != SCARLETT2_FLASH_WRITE_STATE_ERASING)
5282 segment_id = private->selected_flash_segment_id;
5283 segment_num = private->flash_segment_nums[segment_id];
5285 if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
5286 segment_num > SCARLETT2_SEGMENT_NUM_MAX)
5289 /* Send the erase progress request */
5290 erase_req.segment_num = cpu_to_le32(segment_num);
5293 err = scarlett2_usb(mixer, SCARLETT2_USB_GET_ERASE,
5294 &erase_req, sizeof(erase_req),
5295 &erase_resp, sizeof(erase_resp));
5299 progress.progress = erase_resp;
5300 progress.num_blocks = private->flash_segment_blocks[segment_id];
5302 if (copy_to_user((void __user *)arg, &progress, sizeof(progress)))
5305 /* If the erase is complete, change the state from ERASING to
5308 if (progress.progress == 0xff)
5309 private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_WRITE;
5314 static int scarlett2_hwdep_open(struct snd_hwdep *hw, struct file *file)
5316 struct usb_mixer_interface *mixer = hw->private_data;
5317 struct scarlett2_data *private = mixer->private_data;
5319 /* If erasing, wait for it to complete */
5320 if (private->flash_write_state ==
5321 SCARLETT2_FLASH_WRITE_STATE_ERASING) {
5322 int err = scarlett2_wait_for_erase(mixer);
5328 /* Set the state to IDLE */
5329 private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_IDLE;
5334 static int scarlett2_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
5335 unsigned int cmd, unsigned long arg)
5337 struct usb_mixer_interface *mixer = hw->private_data;
5341 case SCARLETT2_IOCTL_PVERSION:
5342 return put_user(SCARLETT2_HWDEP_VERSION,
5343 (int __user *)arg) ? -EFAULT : 0;
5345 case SCARLETT2_IOCTL_REBOOT:
5346 return scarlett2_reboot(mixer);
5348 case SCARLETT2_IOCTL_SELECT_FLASH_SEGMENT:
5349 return scarlett2_ioctl_select_flash_segment(mixer, arg);
5351 case SCARLETT2_IOCTL_ERASE_FLASH_SEGMENT:
5352 return scarlett2_ioctl_erase_flash_segment(mixer);
5354 case SCARLETT2_IOCTL_GET_ERASE_PROGRESS:
5355 return scarlett2_ioctl_get_erase_progress(mixer, arg);
5358 return -ENOIOCTLCMD;
5362 static long scarlett2_hwdep_write(struct snd_hwdep *hw,
5363 const char __user *buf,
5364 long count, loff_t *offset)
5366 struct usb_mixer_interface *mixer = hw->private_data;
5367 struct scarlett2_data *private = mixer->private_data;
5368 int segment_id, segment_num, err, len;
5371 /* SCARLETT2_USB_WRITE_SEGMENT request data */
5379 /* Calculate the maximum permitted in data[] */
5380 const size_t max_data_size = SCARLETT2_FLASH_WRITE_MAX -
5381 offsetof(typeof(*req), data);
5383 /* If erasing, wait for it to complete */
5384 if (private->flash_write_state ==
5385 SCARLETT2_FLASH_WRITE_STATE_ERASING) {
5386 err = scarlett2_wait_for_erase(mixer);
5389 private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_WRITE;
5391 /* Check that an erase has been done & completed */
5392 } else if (private->flash_write_state !=
5393 SCARLETT2_FLASH_WRITE_STATE_WRITE) {
5397 /* Check that we're writing to the upgrade firmware */
5398 segment_id = private->selected_flash_segment_id;
5399 if (segment_id != SCARLETT2_SEGMENT_ID_FIRMWARE)
5402 segment_num = private->flash_segment_nums[segment_id];
5403 if (segment_num < SCARLETT2_SEGMENT_NUM_MIN ||
5404 segment_num > SCARLETT2_SEGMENT_NUM_MAX)
5407 /* Validate the offset and count */
5408 flash_size = private->flash_segment_blocks[segment_id] *
5409 SCARLETT2_FLASH_BLOCK_SIZE;
5411 if (count < 0 || *offset < 0 || *offset + count >= flash_size)
5417 /* Limit the *req size to SCARLETT2_FLASH_WRITE_MAX */
5418 if (count > max_data_size)
5419 count = max_data_size;
5421 /* Create and send the request */
5422 len = struct_size(req, data, count);
5423 req = kzalloc(len, GFP_KERNEL);
5427 req->segment_num = cpu_to_le32(segment_num);
5428 req->offset = cpu_to_le32(*offset);
5431 if (copy_from_user(req->data, buf, count)) {
5436 err = scarlett2_usb(mixer, SCARLETT2_USB_WRITE_SEGMENT,
5449 static int scarlett2_hwdep_release(struct snd_hwdep *hw, struct file *file)
5451 struct usb_mixer_interface *mixer = hw->private_data;
5452 struct scarlett2_data *private = mixer->private_data;
5454 /* Return from the SELECTED or WRITE state to IDLE.
5455 * The ERASING state is left as-is, and checked on next open.
5458 private->hwdep_in_use &&
5459 private->flash_write_state != SCARLETT2_FLASH_WRITE_STATE_ERASING)
5460 private->flash_write_state = SCARLETT2_FLASH_WRITE_STATE_IDLE;
5465 static int scarlett2_hwdep_init(struct usb_mixer_interface *mixer)
5467 struct snd_hwdep *hw;
5470 err = snd_hwdep_new(mixer->chip->card, "Focusrite Control", 0, &hw);
5474 hw->private_data = mixer;
5476 hw->ops.open = scarlett2_hwdep_open;
5477 hw->ops.ioctl = scarlett2_hwdep_ioctl;
5478 hw->ops.write = scarlett2_hwdep_write;
5479 hw->ops.release = scarlett2_hwdep_release;
5484 int snd_scarlett2_init(struct usb_mixer_interface *mixer)
5486 struct snd_usb_audio *chip = mixer->chip;
5487 const struct scarlett2_device_entry *entry;
5490 /* only use UAC_VERSION_2 */
5491 if (!mixer->protocol)
5494 /* find entry in scarlett2_devices */
5495 entry = get_scarlett2_device_entry(mixer);
5497 usb_audio_err(mixer->chip,
5498 "%s: missing device entry for %04x:%04x\n",
5500 USB_ID_VENDOR(chip->usb_id),
5501 USB_ID_PRODUCT(chip->usb_id));
5505 if (chip->setup & SCARLETT2_DISABLE) {
5506 usb_audio_info(chip,
5507 "Focusrite %s Mixer Driver disabled "
5508 "by modprobe options (snd_usb_audio "
5509 "vid=0x%04x pid=0x%04x device_setup=%d)\n",
5511 USB_ID_VENDOR(chip->usb_id),
5512 USB_ID_PRODUCT(chip->usb_id),
5517 usb_audio_info(chip,
5518 "Focusrite %s Mixer Driver enabled (pid=0x%04x); "
5519 "report any issues to "
5520 "https://github.com/geoffreybennett/scarlett-gen2/issues",
5522 USB_ID_PRODUCT(chip->usb_id));
5524 err = snd_scarlett2_controls_create(mixer, entry);
5526 usb_audio_err(mixer->chip,
5527 "Error initialising %s Mixer Driver: %d",
5533 err = scarlett2_hwdep_init(mixer);
5535 usb_audio_err(mixer->chip,
5536 "Error creating %s hwdep device: %d",