Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *   Scarlett Driver for ALSA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *   Copyright (c) 2013 by Tobias Hoffmann
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *   Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *   Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *   Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *   Many codes borrowed from audio.c by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *	    Alan Cox (alan at lxorguk.ukuu.org.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *	    Thomas Sailer (sailer at ife.ee.ethz.ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *   Code cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *   David Henningsson <david.henningsson at canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * Rewritten and extended to support more models, e.g. Scarlett 18i8.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * Auto-detection via UAC2 is not feasible to properly discover the vast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * majority of features. It's related to both Linux/ALSA's UAC2 as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * Focusrite's implementation of it. Eventually quirks may be sufficient but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * right now it's a major headache to work arount these things.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * NB. Neither the OSX nor the win driver provided by Focusrite performs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * discovery, they seem to operate the same as this driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) /* Mixer Interface for the Focusrite Scarlett 18i6 audio interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * The protocol was reverse engineered by looking at communication between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * Scarlett MixControl (v 1.2.128.0) and the Focusrite(R) Scarlett 18i6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  * (firmware v305) using wireshark and usbmon in January 2013.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * Extended in July 2013.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  * this mixer gives complete access to all features of the device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *  - change Impedance of inputs (Line-in, Mic / Instrument, Hi-Z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  *  - select clock source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *  - dynamic input to mixer-matrix assignment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  *  - 18 x 6 mixer-matrix gain stages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  *  - bus routing & volume control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  *  - automatic re-initialization on connect if device was power-cycled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  * USB URB commands overview (bRequest = 0x01 = UAC2_CS_CUR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  * wIndex
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  * 0x01 Analog Input line/instrument impedance switch, wValue=0x0901 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  *      channel, data=Line/Inst (2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  *      pad (-10dB) switch, wValue=0x0b01 + channel, data=Off/On (2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  *      ?? wValue=0x0803/04, ?? (2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  * 0x0a Master Volume, wValue=0x0200+bus[0:all + only 1..4?] data(2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  *      Bus Mute/Unmute wValue=0x0100+bus[0:all + only 1..4?], data(2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  * 0x28 Clock source, wValue=0x0100, data={1:int,2:spdif,3:adat} (1byte)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  * 0x29 Set Sample-rate, wValue=0x0100, data=sample-rate(4bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)  * 0x32 Mixer mux, wValue=0x0600 + mixer-channel, data=input-to-connect(2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)  * 0x33 Output mux, wValue=bus, data=input-to-connect(2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  * 0x34 Capture mux, wValue=0...18, data=input-to-connect(2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  * 0x3c Matrix Mixer gains, wValue=mixer-node  data=gain(2bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  *      ?? [sometimes](4bytes, e.g 0x000003be 0x000003bf ...03ff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  * USB reads: (i.e. actually issued by original software)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  * 0x01 wValue=0x0901+channel (1byte!!), wValue=0x0b01+channed (1byte!!)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  * 0x29 wValue=0x0100 sample-rate(4bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  *      wValue=0x0200 ?? 1byte (only once)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65)  * 0x2a wValue=0x0100 ?? 4bytes, sample-rate2 ??
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  * USB reads with bRequest = 0x03 = UAC2_CS_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  * 0x3c wValue=0x0002 1byte: sync status (locked=1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  *      wValue=0x0000 18*2byte: peak meter (inputs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  *      wValue=0x0001 8(?)*2byte: peak meter (mix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  *      wValue=0x0003 6*2byte: peak meter (pcm/daw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  * USB write with bRequest = 0x03
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  * 0x3c Save settings to hardware: wValue=0x005a, data=0xa5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * <ditaa>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  *  /--------------\    18chn            6chn    /--------------\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  *  | Hardware  in +--+-------\        /------+--+ ALSA PCM out |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)  *  \--------------/  |       |        |      |  \--------------/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  *                    |       |        |      |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  *                    |       v        v      |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  *                    |   +---------------+   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  *                    |    \ Matrix  Mux /    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  *                    |     +-----+-----+     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  *                    |           |           |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)  *                    |           | 18chn     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)  *                    |           v           |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  *                    |     +-----------+     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  *                    |     | Mixer     |     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  *                    |     |    Matrix |     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  *                    |     |           |     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  *                    |     | 18x6 Gain |     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  *                    |     |   stages  |     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  *                    |     +-----+-----+     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  *                    |           |           |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  *                    |           |           |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  *                    | 18chn     | 6chn      | 6chn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  *                    v           v           v
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  *                    =========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  *             +---------------+     +--—------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  *              \ Output  Mux /       \ Capture Mux /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  *               +-----+-----+         +-----+-----+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  *                     |                     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  *                     | 6chn                |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  *                     v                     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  *              +-------------+              |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  *              | Master Gain |              |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  *              +------+------+              |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  *                     |                     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  *                     | 6chn                | 18chn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  *                     | (3 stereo pairs)    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  *  /--------------\   |                     |   /--------------\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  *  | Hardware out |<--/                     \-->| ALSA PCM  in |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  *  \--------------/                             \--------------/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  * </ditaa>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) #include <linux/usb/audio-v2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) #include "usbaudio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #include "mixer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #include "helper.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) #include "power.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #include "mixer_scarlett.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) /* some gui mixers can't handle negative ctl values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) #define SND_SCARLETT_LEVEL_BIAS 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #define SND_SCARLETT_MATRIX_IN_MAX 18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #define SND_SCARLETT_CONTROLS_MAX 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #define SND_SCARLETT_OFFSETS_MAX 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	SCARLETT_OUTPUTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	SCARLETT_SWITCH_IMPEDANCE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	SCARLETT_SWITCH_PAD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	SCARLETT_SWITCH_GAIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	SCARLETT_OFFSET_PCM = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	SCARLETT_OFFSET_ANALOG = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	SCARLETT_OFFSET_SPDIF = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	SCARLETT_OFFSET_ADAT = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	SCARLETT_OFFSET_MIX = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) struct scarlett_mixer_elem_enum_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	int start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	int offsets[SND_SCARLETT_OFFSETS_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	char const * const *names;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) struct scarlett_mixer_control {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	unsigned char num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	unsigned char type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) struct scarlett_device_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	int matrix_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	int matrix_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	int input_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	int output_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	struct scarlett_mixer_elem_enum_info opt_master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	struct scarlett_mixer_elem_enum_info opt_matrix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	/* initial values for matrix mux */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	int matrix_mux_init[SND_SCARLETT_MATRIX_IN_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	int num_controls;	/* number of items in controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	const struct scarlett_mixer_control controls[SND_SCARLETT_CONTROLS_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) /********************** Enum Strings *************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) static const struct scarlett_mixer_elem_enum_info opt_pad = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	.start = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	.len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	.offsets = {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	.names = (char const * const []){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		"0dB", "-10dB"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) static const struct scarlett_mixer_elem_enum_info opt_gain = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	.start = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	.len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	.offsets = {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	.names = (char const * const []){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		"Lo", "Hi"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) static const struct scarlett_mixer_elem_enum_info opt_impedance = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	.start = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	.len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	.offsets = {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	.names = (char const * const []){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		"Line", "Hi-Z"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) static const struct scarlett_mixer_elem_enum_info opt_clock = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	.start = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	.len = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	.offsets = {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	.names = (char const * const []){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		"Internal", "SPDIF", "ADAT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) static const struct scarlett_mixer_elem_enum_info opt_sync = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	.start = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	.len = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	.offsets = {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	.names = (char const * const []){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		"No Lock", "Locked"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) static int scarlett_ctl_switch_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 		struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	uinfo->count = elem->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	uinfo->value.integer.max = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) static int scarlett_ctl_switch_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	int i, err, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	for (i = 0; i < elem->channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		err = snd_usb_get_cur_mix_value(elem, i, i, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		val = !val; /* invert mute logic for mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		ucontrol->value.integer.value[i] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) static int scarlett_ctl_switch_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	int i, changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	int err, oval, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	for (i = 0; i < elem->channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		err = snd_usb_get_cur_mix_value(elem, i, i, &oval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		val = ucontrol->value.integer.value[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		val = !val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		if (oval != val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 			err = snd_usb_set_cur_mix_value(elem, i, i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 			changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) static int scarlett_ctl_resume(struct usb_mixer_elem_list *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	struct usb_mixer_elem_info *elem = mixer_elem_list_to_info(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	for (i = 0; i < elem->channels; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		if (elem->cached & (1 << i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			snd_usb_set_cur_mix_value(elem, i, i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 						  elem->cache_val[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) static int scarlett_ctl_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			     struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	uinfo->count = elem->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	uinfo->value.integer.max = (int)kctl->private_value +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		SND_SCARLETT_LEVEL_BIAS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	uinfo->value.integer.step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) static int scarlett_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 			    struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	int i, err, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	for (i = 0; i < elem->channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		err = snd_usb_get_cur_mix_value(elem, i, i, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 		val = clamp(val / 256, -128, (int)kctl->private_value) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 				    SND_SCARLETT_LEVEL_BIAS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		ucontrol->value.integer.value[i] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) static int scarlett_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			    struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	int i, changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	int err, oval, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	for (i = 0; i < elem->channels; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		err = snd_usb_get_cur_mix_value(elem, i, i, &oval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		val = ucontrol->value.integer.value[i] -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 			SND_SCARLETT_LEVEL_BIAS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		val = val * 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 		if (oval != val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			err = snd_usb_set_cur_mix_value(elem, i, i, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	return changed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) static void scarlett_generate_name(int i, char *dst, int offsets[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	if (i > offsets[SCARLETT_OFFSET_MIX])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		sprintf(dst, "Mix %c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 			'A'+(i - offsets[SCARLETT_OFFSET_MIX] - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	else if (i > offsets[SCARLETT_OFFSET_ADAT])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		sprintf(dst, "ADAT %d", i - offsets[SCARLETT_OFFSET_ADAT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	else if (i > offsets[SCARLETT_OFFSET_SPDIF])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		sprintf(dst, "SPDIF %d", i - offsets[SCARLETT_OFFSET_SPDIF]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	else if (i > offsets[SCARLETT_OFFSET_ANALOG])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		sprintf(dst, "Analog %d", i - offsets[SCARLETT_OFFSET_ANALOG]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	else if (i > offsets[SCARLETT_OFFSET_PCM])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		sprintf(dst, "PCM %d", i - offsets[SCARLETT_OFFSET_PCM]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		sprintf(dst, "Off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) static int scarlett_ctl_enum_dynamic_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 					  struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	unsigned int items = opt->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	uinfo->count = elem->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	uinfo->value.enumerated.items = items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	if (uinfo->value.enumerated.item >= items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		uinfo->value.enumerated.item = items - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	/* generate name dynamically based on item number and offset info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	scarlett_generate_name(uinfo->value.enumerated.item,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			       uinfo->value.enumerated.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 			       opt->offsets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) static int scarlett_ctl_enum_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 				  struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	return snd_ctl_enum_info(uinfo, elem->channels, opt->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 				 (const char * const *)opt->names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) static int scarlett_ctl_enum_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 				 struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	int err, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	err = snd_usb_get_cur_mix_value(elem, 0, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	val = clamp(val - opt->start, 0, opt->len-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	ucontrol->value.enumerated.item[0] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) static int scarlett_ctl_enum_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 				 struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	struct scarlett_mixer_elem_enum_info *opt = elem->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	int err, oval, val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	err = snd_usb_get_cur_mix_value(elem, 0, 0, &oval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	val = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	val = val + opt->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	if (val != oval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		snd_usb_set_cur_mix_value(elem, 0, 0, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) static int scarlett_ctl_enum_resume(struct usb_mixer_elem_list *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	struct usb_mixer_elem_info *elem = mixer_elem_list_to_info(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	if (elem->cached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		snd_usb_set_cur_mix_value(elem, 0, 0, *elem->cache_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) static int scarlett_ctl_meter_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 				  struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	struct snd_usb_audio *chip = elem->head.mixer->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	unsigned char buf[2 * MAX_CHANNELS] = {0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	int wValue = (elem->control << 8) | elem->idx_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	int idx = snd_usb_ctrl_intf(chip) | (elem->head.id << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	err = snd_usb_ctl_msg(chip->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				usb_rcvctrlpipe(chip->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 				UAC2_CS_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 				USB_RECIP_INTERFACE | USB_TYPE_CLASS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 				USB_DIR_IN, wValue, idx, buf, elem->channels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	ucontrol->value.enumerated.item[0] = clamp((int)buf[0], 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) static const struct snd_kcontrol_new usb_scarlett_ctl_switch = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	.name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	.info = scarlett_ctl_switch_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	.get =  scarlett_ctl_switch_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	.put =  scarlett_ctl_switch_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) static const DECLARE_TLV_DB_SCALE(db_scale_scarlett_gain, -12800, 100, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) static const struct snd_kcontrol_new usb_scarlett_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	.name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	.info = scarlett_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	.get =  scarlett_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	.put =  scarlett_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	.private_value = 6,  /* max value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	.tlv = { .p = db_scale_scarlett_gain }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) static const struct snd_kcontrol_new usb_scarlett_ctl_master = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		  SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	.name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	.info = scarlett_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	.get =  scarlett_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	.put =  scarlett_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	.private_value = 6,  /* max value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	.tlv = { .p = db_scale_scarlett_gain }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) static const struct snd_kcontrol_new usb_scarlett_ctl_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	.name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	.info = scarlett_ctl_enum_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	.get =  scarlett_ctl_enum_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	.put =  scarlett_ctl_enum_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) static const struct snd_kcontrol_new usb_scarlett_ctl_dynamic_enum = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	.name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	.info = scarlett_ctl_enum_dynamic_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	.get =  scarlett_ctl_enum_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	.put =  scarlett_ctl_enum_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) static const struct snd_kcontrol_new usb_scarlett_ctl_sync = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	.name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	.info = scarlett_ctl_enum_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	.get =  scarlett_ctl_meter_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) static int add_new_ctl(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 		       const struct snd_kcontrol_new *ncontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 		       usb_mixer_elem_resume_func_t resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		       int index, int offset, int num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		       int val_type, int channels, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		       const struct scarlett_mixer_elem_enum_info *opt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		       struct usb_mixer_elem_info **elem_ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	struct snd_kcontrol *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	struct usb_mixer_elem_info *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	elem = kzalloc(sizeof(*elem), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	if (!elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	elem->head.mixer = mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	elem->head.resume = resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	elem->control = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	elem->idx_off = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	elem->head.id = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	elem->val_type = val_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	elem->channels = channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	/* add scarlett_mixer_elem_enum_info struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	elem->private_data = (void *)opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	kctl = snd_ctl_new1(ncontrol, elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	if (!kctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		kfree(elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	kctl->private_free = snd_usb_mixer_elem_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	err = snd_usb_mixer_add_control(&elem->head, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	if (elem_ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		*elem_ret = elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) static int add_output_ctls(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			   int index, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 			   const struct scarlett_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	char mx[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	struct usb_mixer_elem_info *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	/* Add mute switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	snprintf(mx, sizeof(mx), "Master %d (%s) Playback Switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		index + 1, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_switch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			  scarlett_ctl_resume, 0x0a, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			  2*index+1, USB_MIXER_S16, 2, mx, NULL, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	/* Add volume control and initialize to 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	snprintf(mx, sizeof(mx), "Master %d (%s) Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 		index + 1, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			  scarlett_ctl_resume, 0x0a, 0x02,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 			  2*index+1, USB_MIXER_S16, 2, mx, NULL, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	/* Add L channel source playback enumeration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	snprintf(mx, sizeof(mx), "Master %dL (%s) Source Playback Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		index + 1, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			  scarlett_ctl_enum_resume, 0x33, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			  2*index, USB_MIXER_S16, 1, mx, &info->opt_master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			  &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	/* Add R channel source playback enumeration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	snprintf(mx, sizeof(mx), "Master %dR (%s) Source Playback Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 		index + 1, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 			  scarlett_ctl_enum_resume, 0x33, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 			  2*index+1, USB_MIXER_S16, 1, mx, &info->opt_master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 			  &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) /********************** device-specific config *************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) /*  untested...  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) static const struct scarlett_device_info s6i6_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	.matrix_in = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	.matrix_out = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	.input_len = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	.output_len = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	.opt_master = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		.len = 27,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		.offsets = {0, 12, 16, 18, 18},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	.opt_matrix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		.len = 19,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		.offsets = {0, 12, 16, 18, 18},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	.num_controls = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	.controls = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		{ .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		{ .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		{ .num = 2, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		{ .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		{ .num = 1, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		{ .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		{ .num = 2, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		{ .num = 3, .type = SCARLETT_SWITCH_GAIN, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		{ .num = 4, .type = SCARLETT_SWITCH_GAIN, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	.matrix_mux_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		12, 13, 14, 15,                 /* Analog -> 1..4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		16, 17,                          /* SPDIF -> 5,6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		0, 1, 2, 3, 4, 5, 6, 7,     /* PCM[1..12] -> 7..18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		8, 9, 10, 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) /*  untested...  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) static const struct scarlett_device_info s8i6_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	.matrix_in = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	.matrix_out = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	.input_len = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	.output_len = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	.opt_master = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		.len = 25,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		.offsets = {0, 12, 16, 18, 18},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	.opt_matrix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		.len = 19,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		.offsets = {0, 12, 16, 18, 18},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	.num_controls = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	.controls = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		{ .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		{ .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 		{ .num = 2, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		{ .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		{ .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		{ .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		{ .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	.matrix_mux_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		12, 13, 14, 15,                 /* Analog -> 1..4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		16, 17,                          /* SPDIF -> 5,6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		0, 1, 2, 3, 4, 5, 6, 7,     /* PCM[1..12] -> 7..18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		8, 9, 10, 11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) static const struct scarlett_device_info s18i6_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	.matrix_in = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	.matrix_out = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	.input_len = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	.output_len = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	.opt_master = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		.len = 31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		.offsets = {0, 6, 14, 16, 24},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		.names = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	.opt_matrix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		.len = 25,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		.offsets = {0, 6, 14, 16, 24},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 		.names = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	.num_controls = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	.controls = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		{ .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		{ .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		{ .num = 2, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		{ .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		{ .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	.matrix_mux_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		 6,  7,  8,  9, 10, 11, 12, 13, /* Analog -> 1..8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		16, 17, 18, 19, 20, 21,     /* ADAT[1..6] -> 9..14 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		14, 15,                          /* SPDIF -> 15,16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 		0, 1                          /* PCM[1,2] -> 17,18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) static const struct scarlett_device_info s18i8_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	.matrix_in = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	.matrix_out = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	.input_len = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	.output_len = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	.opt_master = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		.len = 35,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		.offsets = {0, 8, 16, 18, 26},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	.opt_matrix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		.len = 27,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		.offsets = {0, 8, 16, 18, 26},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	.num_controls = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	.controls = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		{ .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		{ .num = 1, .type = SCARLETT_OUTPUTS, .name = "Headphone 1" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		{ .num = 2, .type = SCARLETT_OUTPUTS, .name = "Headphone 2" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		{ .num = 3, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		{ .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		{ .num = 1, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 		{ .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		{ .num = 2, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		{ .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		{ .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	.matrix_mux_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		 8,  9, 10, 11, 12, 13, 14, 15, /* Analog -> 1..8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		18, 19, 20, 21, 22, 23,     /* ADAT[1..6] -> 9..14 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		16, 17,                          /* SPDIF -> 15,16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		0, 1                          /* PCM[1,2] -> 17,18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) static const struct scarlett_device_info s18i20_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	.matrix_in = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	.matrix_out = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	.input_len = 18,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	.output_len = 20,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	.opt_master = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		.len = 47,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		.offsets = {0, 20, 28, 30, 38},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	.opt_matrix = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		.start = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		.len = 39,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		.offsets = {0, 20, 28, 30, 38},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		.names = NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	.num_controls = 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	.controls = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		{ .num = 0, .type = SCARLETT_OUTPUTS, .name = "Monitor" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		{ .num = 1, .type = SCARLETT_OUTPUTS, .name = "Line 3/4" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		{ .num = 2, .type = SCARLETT_OUTPUTS, .name = "Line 5/6" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		{ .num = 3, .type = SCARLETT_OUTPUTS, .name = "Line 7/8" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		{ .num = 4, .type = SCARLETT_OUTPUTS, .name = "Line 9/10" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		{ .num = 5, .type = SCARLETT_OUTPUTS, .name = "SPDIF" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		{ .num = 6, .type = SCARLETT_OUTPUTS, .name = "ADAT 1/2" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		{ .num = 7, .type = SCARLETT_OUTPUTS, .name = "ADAT 3/4" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		{ .num = 8, .type = SCARLETT_OUTPUTS, .name = "ADAT 5/6" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		{ .num = 9, .type = SCARLETT_OUTPUTS, .name = "ADAT 7/8" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		/*{ .num = 1, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		{ .num = 1, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		{ .num = 2, .type = SCARLETT_SWITCH_IMPEDANCE, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		{ .num = 2, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		{ .num = 3, .type = SCARLETT_SWITCH_PAD, .name = NULL},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		{ .num = 4, .type = SCARLETT_SWITCH_PAD, .name = NULL},*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	.matrix_mux_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		20, 21, 22, 23, 24, 25, 26, 27, /* Analog -> 1..8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 		30, 31, 32, 33, 34, 35,     /* ADAT[1..6] -> 9..14 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 		28, 29,                          /* SPDIF -> 15,16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		0, 1                          /* PCM[1,2] -> 17,18 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) static int scarlett_controls_create_generic(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	const struct scarlett_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	char mx[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	const struct scarlett_mixer_control *ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	struct usb_mixer_elem_info *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	/* create master switch and playback volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_switch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 			  scarlett_ctl_resume, 0x0a, 0x01, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			  USB_MIXER_S16, 1, "Master Playback Switch", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			  &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_master,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 			  scarlett_ctl_resume, 0x0a, 0x02, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 			  USB_MIXER_S16, 1, "Master Playback Volume", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			  &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	/* iterate through controls in info struct and create each one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	for (i = 0; i < info->num_controls; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 		ctl = &info->controls[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		switch (ctl->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		case SCARLETT_OUTPUTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 			err = add_output_ctls(mixer, ctl->num, ctl->name, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		case SCARLETT_SWITCH_IMPEDANCE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 			sprintf(mx, "Input %d Impedance Switch", ctl->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 			err = add_new_ctl(mixer, &usb_scarlett_ctl_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 					  scarlett_ctl_enum_resume, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 					  0x09, ctl->num, USB_MIXER_S16, 1, mx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 					  &opt_impedance, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		case SCARLETT_SWITCH_PAD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 			sprintf(mx, "Input %d Pad Switch", ctl->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 			err = add_new_ctl(mixer, &usb_scarlett_ctl_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 					  scarlett_ctl_enum_resume, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 					  0x0b, ctl->num, USB_MIXER_S16, 1, mx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 					  &opt_pad, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		case SCARLETT_SWITCH_GAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 			sprintf(mx, "Input %d Gain Switch", ctl->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 			err = add_new_ctl(mixer, &usb_scarlett_ctl_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 					  scarlett_ctl_enum_resume, 0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 					  0x08, ctl->num, USB_MIXER_S16, 1, mx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 					  &opt_gain, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912)  * Create and initialize a mixer for the Focusrite(R) Scarlett
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) int snd_scarlett_controls_create(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	int err, i, o;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	char mx[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	const struct scarlett_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	struct usb_mixer_elem_info *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	static char sample_rate_buffer[4] = { '\x80', '\xbb', '\x00', '\x00' };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	/* only use UAC_VERSION_2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	if (!mixer->protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	switch (mixer->chip->usb_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	case USB_ID(0x1235, 0x8012):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		info = &s6i6_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	case USB_ID(0x1235, 0x8002):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		info = &s8i6_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	case USB_ID(0x1235, 0x8004):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		info = &s18i6_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	case USB_ID(0x1235, 0x8014):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		info = &s18i8_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	case USB_ID(0x1235, 0x800c):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		info = &s18i20_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	default: /* device not (yet) supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	/* generic function to create controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	err = scarlett_controls_create_generic(mixer, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	/* setup matrix controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	for (i = 0; i < info->matrix_in; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		snprintf(mx, sizeof(mx), "Matrix %02d Input Playback Route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			 i+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 		err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 				  scarlett_ctl_enum_resume, 0x32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 				  0x06, i, USB_MIXER_S16, 1, mx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 				  &info->opt_matrix, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		for (o = 0; o < info->matrix_out; o++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			sprintf(mx, "Matrix %02d Mix %c Playback Volume", i+1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 				o+'A');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 			err = add_new_ctl(mixer, &usb_scarlett_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 					  scarlett_ctl_resume, 0x3c, 0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 					  (i << 3) + (o & 0x07), USB_MIXER_S16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 					  1, mx, NULL, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 			if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	for (i = 0; i < info->input_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		snprintf(mx, sizeof(mx), "Input Source %02d Capture Route",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			 i+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		err = add_new_ctl(mixer, &usb_scarlett_ctl_dynamic_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 				  scarlett_ctl_enum_resume, 0x34,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 				  0x00, i, USB_MIXER_S16, 1, mx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 				  &info->opt_master, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	/* val_len == 1 needed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			  scarlett_ctl_enum_resume, 0x28, 0x01, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			  USB_MIXER_U8, 1, "Sample Clock Source",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 			  &opt_clock, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	/* val_len == 1 and UAC2_CS_MEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	err = add_new_ctl(mixer, &usb_scarlett_ctl_sync, NULL, 0x3c, 0x00, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 			  USB_MIXER_U8, 1, "Sample Clock Sync Status",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			  &opt_sync, &elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	/* initialize sampling rate to 48000 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	err = snd_usb_ctl_msg(mixer->chip->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		usb_sndctrlpipe(mixer->chip->dev, 0), UAC2_CS_CUR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		USB_RECIP_INTERFACE | USB_TYPE_CLASS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		USB_DIR_OUT, 0x0100, snd_usb_ctrl_intf(mixer->chip) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 		(0x29 << 8), sample_rate_buffer, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }