forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmixer_scarlett2.c
7760 lines (6377 loc) · 203 KB
/
mixer_scarlett2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0
/*
* Focusrite Scarlett 2 Protocol Driver for ALSA
* (including Scarlett 2nd Gen, 3rd Gen, 4th Gen, Clarett USB, and
* Clarett+ series products)
*
* Supported models:
* - 6i6/18i8/18i20 Gen 2
* - Solo/2i2/4i4/8i6/18i8/18i20 Gen 3
* - Solo/2i2/4i4 Gen 4
* - Clarett 2Pre/4Pre/8Pre USB
* - Clarett+ 2Pre/4Pre/8Pre
*
* Copyright (c) 2018-2023 by Geoffrey D. Bennett <g at b4.vu>
* Copyright (c) 2020-2021 by Vladimir Sadovnikov <[email protected]>
* Copyright (c) 2022 by Christian Colglazier <[email protected]>
*
* Based on the Scarlett (Gen 1) Driver for ALSA:
*
* Copyright (c) 2013 by Tobias Hoffmann
* Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
* Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
* Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
*
* Many codes borrowed from audio.c by
* Alan Cox (alan at lxorguk.ukuu.org.uk)
* Thomas Sailer (sailer at ife.ee.ethz.ch)
*
* Code cleanup:
* David Henningsson <david.henningsson at canonical.com>
*/
/* The protocol was reverse engineered by looking at the communication
* between Focusrite Control 2.3.4 and the Focusrite(R) Scarlett 18i20
* (firmware 1083) using usbmon in July-August 2018.
*
* Scarlett 18i8 support added in April 2019.
*
* Scarlett 6i6 support added in June 2019 (thanks to Martin Wittmann
* for providing usbmon output and testing).
*
* Scarlett 4i4/8i6 Gen 3 support added in May 2020 (thanks to Laurent
* Debricon for donating a 4i4 and to Fredrik Unger for providing 8i6
* usbmon output and testing).
*
* Scarlett 18i8/18i20 Gen 3 support added in June 2020 (thanks to
* Darren Jaeckel, Alex Sedlack, and Clovis Lunel for providing usbmon
* output, protocol traces and testing).
*
* Support for loading mixer volume and mux configuration from the
* interface during driver initialisation added in May 2021 (thanks to
* Vladimir Sadovnikov for figuring out how).
*
* Support for Solo/2i2 Gen 3 added in May 2021 (thanks to Alexander
* Vorona for 2i2 protocol traces).
*
* Support for phantom power, direct monitoring, speaker switching,
* and talkback added in May-June 2021.
*
* Support for Clarett+ 8Pre added in Aug 2022 by Christian
* Colglazier.
*
* Support for Clarett 8Pre USB added in Sep 2023 (thanks to Philippe
* Perrot for confirmation).
*
* Support for Clarett+ 4Pre and 2Pre added in Sep 2023 (thanks to
* Gregory Rozzo for donating a 4Pre, and David Sherwood and Patrice
* Peterson for usbmon output).
*
* Support for Clarett 2Pre and 4Pre USB added in Oct 2023.
*
* Support for firmware updates added in Dec 2023.
*
* Support for Scarlett Solo/2i2/4i4 Gen 4 added in Dec 2023 (thanks
* to many LinuxMusicians people and to Focusrite for hardware
* donations).
*
* This ALSA mixer gives access to (model-dependent):
* - input, output, mixer-matrix muxes
* - mixer-matrix gain stages
* - gain/volume/mute controls
* - level meters
* - line/inst level, pad, and air controls
* - phantom power, direct monitor, speaker switching, and talkback
* controls
* - disable/enable MSD mode
* - disable/enable standalone mode
* - input gain, autogain, safe mode
* - direct monitor mixes
*
* <ditaa>
* /--------------\ 18chn 20chn /--------------\
* | Hardware in +--+------\ /-------------+--+ ALSA PCM out |
* \--------------/ | | | | \--------------/
* | | | /-----\ |
* | | | | | |
* | v v v | |
* | +---------------+ | |
* | \ Matrix Mux / | |
* | +-----+-----+ | |
* | | | |
* | |18chn | |
* | | | |
* | | 10chn| |
* | v | |
* | +------------+ | |
* | | Mixer | | |
* | | Matrix | | |
* | | | | |
* | | 18x10 Gain | | |
* | | stages | | |
* | +-----+------+ | |
* | | | |
* |18chn |10chn | |20chn
* | | | |
* | +----------/ |
* | | |
* v v v
* ===========================
* +---------------+ +--—------------+
* \ Output Mux / \ Capture Mux /
* +---+---+---+ +-----+-----+
* | | |
* 10chn| | |18chn
* | | |
* /--------------\ | | | /--------------\
* | S/PDIF, ADAT |<--/ |10chn \-->| ALSA PCM in |
* | Hardware out | | \--------------/
* \--------------/ |
* v
* +-------------+ Software gain per channel.
* | Master Gain |<-- 18i20 only: Switch per channel
* +------+------+ to select HW or SW gain control.
* |
* |10chn
* /--------------\ |
* | Analogue |<------/
* | Hardware out |
* \--------------/
* </ditaa>
*
* Gen 3/4 devices have a Mass Storage Device (MSD) mode where a small
* disk with registration and driver download information is presented
* to the host. To access the full functionality of the device without
* proprietary software, MSD mode can be disabled by:
* - holding down the 48V button for five seconds while powering on
* the device, or
* - using this driver and alsamixer to change the "MSD Mode" setting
* to Off and power-cycling the device
*/
#include <linux/slab.h>
#include <linux/usb.h>
#include <linux/moduleparam.h>
#include <sound/control.h>
#include <sound/tlv.h>
#include <sound/hwdep.h>
#include <uapi/sound/scarlett2.h>
#include "usbaudio.h"
#include "mixer.h"
#include "helper.h"
#include "mixer_scarlett2.h"
/* device_setup value to allow turning MSD mode back on */
#define SCARLETT2_MSD_ENABLE 0x02
/* device_setup value to disable this mixer driver */
#define SCARLETT2_DISABLE 0x04
/* some gui mixers can't handle negative ctl values */
#define SCARLETT2_VOLUME_BIAS 127
/* maximum preamp input gain and value
* values are from 0 to 70, preamp gain is from 0 to 69 dB
*/
#define SCARLETT2_MAX_GAIN_VALUE 70
#define SCARLETT2_MAX_GAIN_DB 69
/* mixer range from -80dB to +6dB in 0.5dB steps */
#define SCARLETT2_MIXER_MIN_DB -80
#define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
#define SCARLETT2_MIXER_MAX_DB 6
#define SCARLETT2_MIXER_MAX_VALUE \
((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
#define SCARLETT2_MIXER_VALUE_COUNT (SCARLETT2_MIXER_MAX_VALUE + 1)
/* map from (dB + 80) * 2 to mixer value
* for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20)))
*/
static const u16 scarlett2_mixer_values[SCARLETT2_MIXER_VALUE_COUNT] = {
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
23, 24, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 46, 48, 51,
54, 57, 61, 65, 68, 73, 77, 81, 86, 91, 97, 103, 109, 115,
122, 129, 137, 145, 154, 163, 173, 183, 194, 205, 217, 230,
244, 259, 274, 290, 307, 326, 345, 365, 387, 410, 434, 460,
487, 516, 547, 579, 614, 650, 689, 730, 773, 819, 867, 919,
973, 1031, 1092, 1157, 1225, 1298, 1375, 1456, 1543, 1634,
1731, 1833, 1942, 2057, 2179, 2308, 2445, 2590, 2744, 2906,
3078, 3261, 3454, 3659, 3876, 4105, 4349, 4606, 4879, 5168,
5475, 5799, 6143, 6507, 6892, 7301, 7733, 8192, 8677, 9191,
9736, 10313, 10924, 11571, 12257, 12983, 13752, 14567, 15430,
16345
};
/* Maximum number of analogue outputs */
#define SCARLETT2_ANALOGUE_MAX 10
/* Maximum number of various input controls */
#define SCARLETT2_LEVEL_SWITCH_MAX 2
#define SCARLETT2_PAD_SWITCH_MAX 8
#define SCARLETT2_AIR_SWITCH_MAX 8
#define SCARLETT2_PHANTOM_SWITCH_MAX 2
#define SCARLETT2_INPUT_GAIN_MAX 2
/* Maximum number of inputs to the mixer */
#define SCARLETT2_INPUT_MIX_MAX 25
/* Maximum number of outputs from the mixer */
#define SCARLETT2_OUTPUT_MIX_MAX 12
/* Maximum number of mixer gain controls */
#define SCARLETT2_MIX_MAX (SCARLETT2_INPUT_MIX_MAX * SCARLETT2_OUTPUT_MIX_MAX)
/* Maximum number of direct monitor mixer gain controls
* 1 (Solo) or 2 (2i2) direct monitor selections (Mono & Stereo)
* 2 Mix outputs (A/Left & B/Right)
* 4 Mix inputs
*/
#define SCARLETT2_MONITOR_MIX_MAX (2 * 2 * 4)
/* Maximum size of the data in the USB mux assignment message:
* 20 inputs, 20 outputs, 25 matrix inputs, 12 spare
*/
#define SCARLETT2_MUX_MAX 77
/* Maximum number of sources (sum of input port counts) */
#define SCARLETT2_MAX_SRCS 52
/* Maximum number of meters (sum of output port counts) */
#define SCARLETT2_MAX_METERS 65
/* Hardware port types:
* - None (no input to mux)
* - Analogue I/O
* - S/PDIF I/O
* - ADAT I/O
* - Mixer I/O
* - PCM I/O
*/
enum {
SCARLETT2_PORT_TYPE_NONE,
SCARLETT2_PORT_TYPE_ANALOGUE,
SCARLETT2_PORT_TYPE_SPDIF,
SCARLETT2_PORT_TYPE_ADAT,
SCARLETT2_PORT_TYPE_MIX,
SCARLETT2_PORT_TYPE_PCM,
SCARLETT2_PORT_TYPE_COUNT
};
/* I/O count of each port type kept in struct scarlett2_ports */
enum {
SCARLETT2_PORT_IN,
SCARLETT2_PORT_OUT,
SCARLETT2_PORT_DIRNS
};
/* Dim/Mute buttons on the 18i20 */
enum {
SCARLETT2_BUTTON_MUTE,
SCARLETT2_BUTTON_DIM,
SCARLETT2_DIM_MUTE_COUNT
};
/* Flash Write State */
enum {
SCARLETT2_FLASH_WRITE_STATE_IDLE,
SCARLETT2_FLASH_WRITE_STATE_SELECTED,
SCARLETT2_FLASH_WRITE_STATE_ERASING,
SCARLETT2_FLASH_WRITE_STATE_WRITE
};
static const char *const scarlett2_dim_mute_names[SCARLETT2_DIM_MUTE_COUNT] = {
"Mute Playback Switch", "Dim Playback Switch"
};
/* The autogain_status is set based on the autogain_switch and
* raw_autogain_status values.
*
* If autogain_switch is set, autogain_status is set to 0 (Running).
* The other status values are from the raw_autogain_status value + 1.
*/
static const char *const scarlett2_autogain_status_texts[] = {
"Running",
"Success",
"SuccessDRover",
"WarnMinGainLimit",
"FailDRunder",
"FailMaxGainLimit",
"FailClipped",
"Cancelled",
"Invalid"
};
/* Power Status Values */
enum {
SCARLETT2_POWER_STATUS_EXT,
SCARLETT2_POWER_STATUS_BUS,
SCARLETT2_POWER_STATUS_FAIL,
SCARLETT2_POWER_STATUS_COUNT
};
/* Notification callback functions */
struct scarlett2_notification {
u32 mask;
void (*func)(struct usb_mixer_interface *mixer);
};
static void scarlett2_notify_sync(struct usb_mixer_interface *mixer);
static void scarlett2_notify_dim_mute(struct usb_mixer_interface *mixer);
static void scarlett2_notify_monitor(struct usb_mixer_interface *mixer);
static void scarlett2_notify_volume(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_level(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_pad(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_air(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_phantom(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_select(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_gain(struct usb_mixer_interface *mixer);
static void scarlett2_notify_autogain(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_safe(struct usb_mixer_interface *mixer);
static void scarlett2_notify_monitor_other(struct usb_mixer_interface *mixer);
static void scarlett2_notify_direct_monitor(struct usb_mixer_interface *mixer);
static void scarlett2_notify_power_status(struct usb_mixer_interface *mixer);
static void scarlett2_notify_pcm_input_switch(
struct usb_mixer_interface *mixer);
/* Arrays of notification callback functions */
static const struct scarlett2_notification scarlett2_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_dim_mute },
{ 0x00400000, scarlett2_notify_monitor },
{ 0x00800000, scarlett2_notify_input_other },
{ 0x01000000, scarlett2_notify_monitor_other },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett3a_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00800000, scarlett2_notify_input_other },
{ 0x01000000, scarlett2_notify_direct_monitor },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_solo_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00400000, scarlett2_notify_input_air },
{ 0x00800000, scarlett2_notify_direct_monitor },
{ 0x01000000, scarlett2_notify_input_level },
{ 0x02000000, scarlett2_notify_input_phantom },
{ 0x04000000, scarlett2_notify_pcm_input_switch },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_2i2_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_input_safe },
{ 0x00400000, scarlett2_notify_autogain },
{ 0x00800000, scarlett2_notify_input_air },
{ 0x01000000, scarlett2_notify_direct_monitor },
{ 0x02000000, scarlett2_notify_input_select },
{ 0x04000000, scarlett2_notify_input_level },
{ 0x08000000, scarlett2_notify_input_phantom },
{ 0x10000000, NULL }, /* power status, ignored */
{ 0x40000000, scarlett2_notify_input_gain },
{ 0x80000000, NULL }, /* power status, ignored */
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_4i4_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_input_safe },
{ 0x00400000, scarlett2_notify_autogain },
{ 0x00800000, scarlett2_notify_input_air },
{ 0x01000000, scarlett2_notify_input_select },
{ 0x02000000, scarlett2_notify_input_level },
{ 0x04000000, scarlett2_notify_input_phantom },
{ 0x08000000, scarlett2_notify_power_status }, /* power external */
{ 0x20000000, scarlett2_notify_input_gain },
{ 0x40000000, scarlett2_notify_power_status }, /* power status */
{ 0x80000000, scarlett2_notify_volume },
{ 0, NULL }
};
/* Configuration parameters that can be read and written */
enum {
SCARLETT2_CONFIG_DIM_MUTE,
SCARLETT2_CONFIG_LINE_OUT_VOLUME,
SCARLETT2_CONFIG_MUTE_SWITCH,
SCARLETT2_CONFIG_SW_HW_SWITCH,
SCARLETT2_CONFIG_MASTER_VOLUME,
SCARLETT2_CONFIG_HEADPHONE_VOLUME,
SCARLETT2_CONFIG_LEVEL_SWITCH,
SCARLETT2_CONFIG_PAD_SWITCH,
SCARLETT2_CONFIG_MSD_SWITCH,
SCARLETT2_CONFIG_AIR_SWITCH,
SCARLETT2_CONFIG_STANDALONE_SWITCH,
SCARLETT2_CONFIG_PHANTOM_SWITCH,
SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
SCARLETT2_CONFIG_DIRECT_MONITOR,
SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
SCARLETT2_CONFIG_TALKBACK_MAP,
SCARLETT2_CONFIG_AUTOGAIN_SWITCH,
SCARLETT2_CONFIG_AUTOGAIN_STATUS,
SCARLETT2_CONFIG_INPUT_GAIN,
SCARLETT2_CONFIG_SAFE_SWITCH,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH,
SCARLETT2_CONFIG_INPUT_LINK_SWITCH,
SCARLETT2_CONFIG_POWER_EXT,
SCARLETT2_CONFIG_POWER_LOW,
SCARLETT2_CONFIG_PCM_INPUT_SWITCH,
SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN,
SCARLETT2_CONFIG_COUNT
};
/* Location, size, and activation command number for the configuration
* parameters. Size is in bits and may be 0, 1, 8, or 16.
*
* A size of 0 indicates that the parameter is a byte-sized Scarlett
* Gen 4 configuration which is written through the gen4_write_addr
* location (but still read through the given offset location).
*
* Some Gen 4 configuration parameters are written with 0x02 for a
* desired value of 0x01, and 0x03 for 0x00. These are indicated with
* mute set to 1. 0x02 and 0x03 are temporary values while the device
* makes the change and the channel and/or corresponding DSP channel
* output is muted.
*/
struct scarlett2_config {
u16 offset;
u8 size;
u8 activate;
u8 mute;
};
struct scarlett2_config_set {
const struct scarlett2_notification *notifications;
u16 gen4_write_addr;
const struct scarlett2_config items[SCARLETT2_CONFIG_COUNT];
};
/* Gen 2 devices without SW/HW volume switch: 6i6, 18i8 */
static const struct scarlett2_config_set scarlett2_config_set_gen2a = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
/* Gen 2 devices with SW/HW volume switch: 18i20 */
static const struct scarlett2_config_set scarlett2_config_set_gen2b = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
/* Gen 3 devices without a mixer (Solo and 2i2) */
static const struct scarlett2_config_set scarlett2_config_set_gen3a = {
.notifications = scarlett3a_notifications,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x04, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x05, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x06, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x07, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x08, .size = 1, .activate = 7 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x09, .size = 1, .activate = 8 },
}
};
/* Gen 3 devices without SW/HW volume switch: 4i4, 8i6 */
static const struct scarlett2_config_set scarlett2_config_set_gen3b = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x8c, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x9c, .size = 1, .activate = 8 },
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x9d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x9e, .size = 8, .activate = 6 },
}
};
/* Gen 3 devices with SW/HW volume switch: 18i8, 18i20 */
static const struct scarlett2_config_set scarlett2_config_set_gen3c = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x8c, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x9c, .size = 1, .activate = 8 },
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x9d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x9e, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH] = {
.offset = 0x9f, .size = 1, .activate = 10 },
[SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE] = {
.offset = 0xa0, .size = 1, .activate = 10 },
[SCARLETT2_CONFIG_TALKBACK_MAP] = {
.offset = 0xb0, .size = 16, .activate = 10 },
}
};
/* Solo Gen 4 */
static const struct scarlett2_config_set scarlett2_config_set_gen4_solo = {
.notifications = scarlett4_solo_notifications,
.gen4_write_addr = 0xd8,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x47, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x108, .activate = 12 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x46, .activate = 9, .mute = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3d, .activate = 10, .mute = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .activate = 11 },
[SCARLETT2_CONFIG_PCM_INPUT_SWITCH] = {
.offset = 0x206, .activate = 25 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x232, .size = 16, .activate = 26 }
}
};
/* 2i2 Gen 4 */
static const struct scarlett2_config_set scarlett2_config_set_gen4_2i2 = {
.notifications = scarlett4_2i2_notifications,
.gen4_write_addr = 0xfc,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x49, .size = 8, .activate = 4 }, // 0x41 ??
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x14a, .activate = 16 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x135, .activate = 10 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x137 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x48, .activate = 11, .mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x4b, .activate = 12 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3c, .activate = 13, .mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x147, .activate = 14 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .activate = 15 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x14b, .activate = 17 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x14e, .activate = 18 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x2a0, .size = 16, .activate = 36 }
}
};
/* 4i4 Gen 4 */
static const struct scarlett2_config_set scarlett2_config_set_gen4_4i4 = {
.notifications = scarlett4_4i4_notifications,
.gen4_write_addr = 0x130,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x13e, .activate = 10 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x140 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x5a, .activate = 11, .mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x5e, .activate = 12 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x4e, .activate = 13, .mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x150, .activate = 14 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x50, .activate = 15 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x153, .activate = 16 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x156, .activate = 17 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x32, .size = 16 },
[SCARLETT2_CONFIG_HEADPHONE_VOLUME] = {
.offset = 0x3a, .size = 16 },
[SCARLETT2_CONFIG_POWER_EXT] = {
.offset = 0x168 },
[SCARLETT2_CONFIG_POWER_LOW] = {
.offset = 0x16d }
}
};
/* Clarett USB and Clarett+ devices: 2Pre, 4Pre, 8Pre */
static const struct scarlett2_config_set scarlett2_config_set_clarett = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
/* Description of each hardware port type:
* - id: hardware ID of this port type
* - src_descr: printf format string for mux input selections
* - src_num_offset: added to channel number for the fprintf
* - dst_descr: printf format string for mixer controls
*/
struct scarlett2_port {
u16 id;
const char * const src_descr;
int src_num_offset;
const char * const dst_descr;
const char * const dsp_src_descr;
const char * const dsp_dst_descr;
};
static const struct scarlett2_port scarlett2_ports[SCARLETT2_PORT_TYPE_COUNT] = {
[SCARLETT2_PORT_TYPE_NONE] = {
.id = 0x000,
.src_descr = "Off"
},
[SCARLETT2_PORT_TYPE_ANALOGUE] = {
.id = 0x080,
.src_descr = "Analogue %d",
.src_num_offset = 1,
.dst_descr = "Analogue Output %02d Playback"
},
[SCARLETT2_PORT_TYPE_SPDIF] = {
.id = 0x180,
.src_descr = "S/PDIF %d",
.src_num_offset = 1,
.dst_descr = "S/PDIF Output %d Playback"
},
[SCARLETT2_PORT_TYPE_ADAT] = {
.id = 0x200,
.src_descr = "ADAT %d",
.src_num_offset = 1,
.dst_descr = "ADAT Output %d Playback"
},
[SCARLETT2_PORT_TYPE_MIX] = {
.id = 0x300,
.src_descr = "Mix %c",
.src_num_offset = 'A',
.dst_descr = "Mixer Input %02d Capture",
.dsp_src_descr = "DSP %d",
.dsp_dst_descr = "DSP Input %d Capture"
},
[SCARLETT2_PORT_TYPE_PCM] = {
.id = 0x600,
.src_descr = "PCM %d",
.src_num_offset = 1,
.dst_descr = "PCM %02d Capture"
},
};
/* Number of mux tables: one for each band of sample rates
* (44.1/48kHz, 88.2/96kHz, and 176.4/176kHz)
*/
#define SCARLETT2_MUX_TABLES 3
/* Maximum number of entries in a mux table */
#define SCARLETT2_MAX_MUX_ENTRIES 10
/* One entry within mux_assignment defines the port type and range of
* ports to add to the set_mux message. The end of the list is marked
* with count == 0.
*/
struct scarlett2_mux_entry {
u8 port_type;
u8 start;
u8 count;
};
/* Maximum number of entries in a mux table */
#define SCARLETT2_MAX_METER_ENTRIES 9
/* One entry within meter_assignment defines the range of mux outputs
* that consecutive meter entries are mapped to. The end of the list
* is marked with count == 0.
*/
struct scarlett2_meter_entry {
u8 start;
u8 count;
};
struct scarlett2_device_info {
/* which set of configuration parameters the device uses */
const struct scarlett2_config_set *config_set;
/* minimum firmware version required */
u16 min_firmware_version;
/* support for main/alt speaker switching */
u8 has_speaker_switching;
/* support for talkback microphone */
u8 has_talkback;
/* the number of analogue inputs with a software switchable
* level control that can be set to line or instrument
*/
u8 level_input_count;
/* the first input with a level control (0-based) */
u8 level_input_first;
/* the number of analogue inputs with a software switchable
* 10dB pad control
*/
u8 pad_input_count;
/* the number of analogue inputs with a software switchable
* "air" control
*/
u8 air_input_count;
/* the first input with an air control (0-based) */
u8 air_input_first;
/* number of additional air options
* 0 for air presence only (Gen 3)
* 1 for air presence+drive (Gen 4)
*/
u8 air_option;
/* the number of phantom (48V) software switchable controls */
u8 phantom_count;
/* the first input with phantom power control (0-based) */
u8 phantom_first;
/* the number of inputs each phantom switch controls */
u8 inputs_per_phantom;
/* the number of inputs with software-controllable gain */
u8 gain_input_count;
/* the number of direct monitor options
* (0 = none, 1 = mono only, 2 = mono/stereo)
*/
u8 direct_monitor;
/* the number of DSP channels */
u8 dsp_count;
/* remap analogue outputs; 18i8 Gen 3 has "line 3/4" connected
* internally to the analogue 7/8 outputs
*/
u8 line_out_remap_enable;
u8 line_out_remap[SCARLETT2_ANALOGUE_MAX];
u8 line_out_unmap[SCARLETT2_ANALOGUE_MAX];
/* additional description for the line out volume controls */
const char * const line_out_descrs[SCARLETT2_ANALOGUE_MAX];
/* number of sources/destinations of each port type */
const int port_count[SCARLETT2_PORT_TYPE_COUNT][SCARLETT2_PORT_DIRNS];
/* layout/order of the entries in the set_mux message */
struct scarlett2_mux_entry mux_assignment[SCARLETT2_MUX_TABLES]
[SCARLETT2_MAX_MUX_ENTRIES];
/* map from meter level order returned by
* SCARLETT2_USB_GET_METER to index into mux[] entries (same
* as the order returned by scarlett2_meter_ctl_get())
*/
struct scarlett2_meter_entry meter_map[SCARLETT2_MAX_METER_ENTRIES];
};
struct scarlett2_data {
struct usb_mixer_interface *mixer;
struct mutex usb_mutex; /* prevent sending concurrent USB requests */
struct mutex data_mutex; /* lock access to this data */
u8 hwdep_in_use;
u8 selected_flash_segment_id;
u8 flash_write_state;
struct delayed_work work;
const struct scarlett2_device_info *info;
const struct scarlett2_config_set *config_set;
const char *series_name;
__u8 bInterfaceNumber;
__u8 bEndpointAddress;
__u16 wMaxPacketSize;
__u8 bInterval;
u8 num_mux_srcs;
u8 num_mux_dsts;
u8 num_mix_in;
u8 num_mix_out;
u8 num_line_out;
u8 num_monitor_mix_ctls;
u32 firmware_version;
u8 flash_segment_nums[SCARLETT2_SEGMENT_ID_COUNT];
u8 flash_segment_blocks[SCARLETT2_SEGMENT_ID_COUNT];
u16 scarlett2_seq;
u8 sync_updated;
u8 vol_updated;
u8 dim_mute_updated;
u8 input_level_updated;
u8 input_pad_updated;
u8 input_air_updated;
u8 input_phantom_updated;
u8 input_select_updated;
u8 input_gain_updated;
u8 autogain_updated;
u8 input_safe_updated;
u8 pcm_input_switch_updated;
u8 monitor_other_updated;
u8 direct_monitor_updated;
u8 mux_updated;
u8 mix_updated;
u8 speaker_switching_switched;
u8 power_status_updated;
u8 sync;
u8 master_vol;
u8 headphone_vol;
u8 vol[SCARLETT2_ANALOGUE_MAX];
u8 vol_sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
u8 level_switch[SCARLETT2_LEVEL_SWITCH_MAX];
u8 pad_switch[SCARLETT2_PAD_SWITCH_MAX];
u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
u8 air_switch[SCARLETT2_AIR_SWITCH_MAX];
u8 phantom_switch[SCARLETT2_PHANTOM_SWITCH_MAX];
u8 phantom_persistence;
u8 input_select_switch;
u8 input_link_switch[SCARLETT2_INPUT_GAIN_MAX / 2];
u8 gain[SCARLETT2_INPUT_GAIN_MAX];
u8 autogain_switch[SCARLETT2_INPUT_GAIN_MAX];