^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Focusrite Scarlett 6i6/18i8/18i20 Gen 2 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) 2018-2019 by Geoffrey D. Bennett <g at b4.vu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Based on the Scarlett (Gen 1) Driver for ALSA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (c) 2013 by Tobias Hoffmann
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Many codes borrowed from audio.c by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Alan Cox (alan at lxorguk.ukuu.org.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Thomas Sailer (sailer at ife.ee.ethz.ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Code cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * David Henningsson <david.henningsson at canonical.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* Mixer Interface for the Focusrite Scarlett 6i6/18i8/18i20 Gen 2 audio
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * interface. Based on the Gen 1 driver and rewritten.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* The protocol was reverse engineered by looking at the communication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * between Focusrite Control 2.3.4 and the Focusrite(R) Scarlett 18i20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * (firmware 1083) using usbmon in July-August 2018.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Scarlett 18i8 support added in April 2019.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Scarlett 6i6 support added in June 2019 (thanks to Martin Wittmann
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * for providing usbmon output and testing).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * This ALSA mixer gives access to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * - input, output, mixer-matrix muxes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * - 18x10 mixer-matrix gain stages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * - gain/volume controls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * - level meters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * - line/inst level and pad controls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * <ditaa>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * /--------------\ 18chn 20chn /--------------\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * | Hardware in +--+------\ /-------------+--+ ALSA PCM out |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * \--------------/ | | | | \--------------/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * | | | /-----\ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * | | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * | v v v | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * | +---------------+ | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * | \ Matrix Mux / | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * | +-----+-----+ | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * | |18chn | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * | | 10chn| |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * | v | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * | +------------+ | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * | | Mixer | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * | | Matrix | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * | | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * | | 18x10 Gain | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * | | stages | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * | +-----+------+ | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * |18chn |10chn | |20chn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * | | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * | +----------/ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * v v v
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * ===========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * +---------------+ +--—------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * \ Output Mux / \ Capture Mux /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * +---+---+---+ +-----+-----+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * 10chn| | |18chn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * | | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * /--------------\ | | | /--------------\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * | S/PDIF, ADAT |<--/ |10chn \-->| ALSA PCM in |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * | Hardware out | | \--------------/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * \--------------/ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * v
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * +-------------+ Software gain per channel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * | Master Gain |<-- 18i20 only: Switch per channel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * +------+------+ to select HW or SW gain control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * |10chn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * /--------------\ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * | Analogue |<------/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * | Hardware out |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * \--------------/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * </ditaa>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #include <sound/tlv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #include "usbaudio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #include "mixer.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #include "helper.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #include "mixer_scarlett_gen2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* device_setup value to enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define SCARLETT2_ENABLE 0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) /* some gui mixers can't handle negative ctl values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define SCARLETT2_VOLUME_BIAS 127
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* mixer range from -80dB to +6dB in 0.5dB steps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define SCARLETT2_MIXER_MIN_DB -80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define SCARLETT2_MIXER_MAX_DB 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define SCARLETT2_MIXER_MAX_VALUE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) ((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* map from (dB + 80) * 2 to mixer value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static const u16 scarlett2_mixer_values[173] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 23, 24, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 46, 48, 51,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 54, 57, 61, 65, 68, 73, 77, 81, 86, 91, 97, 103, 109, 115,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 122, 129, 137, 145, 154, 163, 173, 183, 194, 205, 217, 230,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 244, 259, 274, 290, 307, 326, 345, 365, 387, 410, 434, 460,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 487, 516, 547, 579, 614, 650, 689, 730, 773, 819, 867, 919,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 973, 1031, 1092, 1157, 1225, 1298, 1375, 1456, 1543, 1634,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 1731, 1833, 1942, 2057, 2179, 2308, 2445, 2590, 2744, 2906,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 3078, 3261, 3454, 3659, 3876, 4105, 4349, 4606, 4879, 5168,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 5475, 5799, 6143, 6507, 6892, 7301, 7733, 8192, 8677, 9191,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 9736, 10313, 10924, 11571, 12257, 12983, 13752, 14567, 15430,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 16345
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* Maximum number of analogue outputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define SCARLETT2_ANALOGUE_MAX 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Maximum number of level and pad switches */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #define SCARLETT2_LEVEL_SWITCH_MAX 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define SCARLETT2_PAD_SWITCH_MAX 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /* Maximum number of inputs to the mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define SCARLETT2_INPUT_MIX_MAX 18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* Maximum number of outputs from the mixer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #define SCARLETT2_OUTPUT_MIX_MAX 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* Maximum size of the data in the USB mux assignment message:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * 18 inputs, 20 outputs, 18 matrix inputs, 8 spare
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #define SCARLETT2_MUX_MAX 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* Number of meters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * 18 inputs, 20 outputs, 18 matrix inputs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #define SCARLETT2_NUM_METERS 56
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* Hardware port types:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * - None (no input to mux)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * - Analogue I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * - S/PDIF I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * - ADAT I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * - Mixer I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * - PCM I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) SCARLETT2_PORT_TYPE_NONE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) SCARLETT2_PORT_TYPE_ANALOGUE = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) SCARLETT2_PORT_TYPE_SPDIF = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) SCARLETT2_PORT_TYPE_ADAT = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) SCARLETT2_PORT_TYPE_MIX = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) SCARLETT2_PORT_TYPE_PCM = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) SCARLETT2_PORT_TYPE_COUNT = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Count of total I/O and number available at each sample rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) SCARLETT2_PORT_IN = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) SCARLETT2_PORT_OUT = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) SCARLETT2_PORT_OUT_44 = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) SCARLETT2_PORT_OUT_88 = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) SCARLETT2_PORT_OUT_176 = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) SCARLETT2_PORT_DIRECTIONS = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Hardware buttons on the 18i20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) #define SCARLETT2_BUTTON_MAX 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static const char *const scarlett2_button_names[SCARLETT2_BUTTON_MAX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) "Mute", "Dim"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* Description of each hardware port type:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * - id: hardware ID for this port type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * - num: number of sources/destinations of this port type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * - src_descr: printf format string for mux input selections
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * - src_num_offset: added to channel number for the fprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * - dst_descr: printf format string for mixer controls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct scarlett2_ports {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) u16 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int num[SCARLETT2_PORT_DIRECTIONS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) const char * const src_descr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int src_num_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) const char * const dst_descr;
^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) struct scarlett2_device_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u8 line_out_hw_vol; /* line out hw volume is sw controlled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) u8 button_count; /* number of buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) u8 level_input_count; /* inputs with level selectable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) u8 pad_input_count; /* inputs with pad selectable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) const char * const line_out_descrs[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct scarlett2_ports ports[SCARLETT2_PORT_TYPE_COUNT];
^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) struct scarlett2_mixer_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct usb_mixer_interface *mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct mutex usb_mutex; /* prevent sending concurrent USB requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct mutex data_mutex; /* lock access to this data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct delayed_work work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) const struct scarlett2_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int num_mux_srcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) u16 scarlett2_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) u8 vol_updated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) u8 master_vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) u8 vol[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) u8 vol_sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) u8 level_switch[SCARLETT2_LEVEL_SWITCH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) u8 pad_switch[SCARLETT2_PAD_SWITCH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) u8 buttons[SCARLETT2_BUTTON_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct snd_kcontrol *master_vol_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct snd_kcontrol *vol_ctls[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct snd_kcontrol *button_ctls[SCARLETT2_BUTTON_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) u8 mux[SCARLETT2_MUX_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) u8 mix[SCARLETT2_INPUT_MIX_MAX * SCARLETT2_OUTPUT_MIX_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) /*** Model-specific data ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static const struct scarlett2_device_info s6i6_gen2_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /* The first two analogue inputs can be switched between line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * and instrument levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .level_input_count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* The first two analogue inputs have an optional pad. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .pad_input_count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .line_out_descrs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) "Headphones 1 L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) "Headphones 1 R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) "Headphones 2 L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) "Headphones 2 R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .ports = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) [SCARLETT2_PORT_TYPE_NONE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .id = 0x000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .num = { 1, 0, 8, 8, 8 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .src_descr = "Off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .src_num_offset = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) [SCARLETT2_PORT_TYPE_ANALOGUE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .id = 0x080,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) .num = { 4, 4, 4, 4, 4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) .src_descr = "Analogue %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .dst_descr = "Analogue Output %02d Playback"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) [SCARLETT2_PORT_TYPE_SPDIF] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .id = 0x180,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .num = { 2, 2, 2, 2, 2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .src_descr = "S/PDIF %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .dst_descr = "S/PDIF Output %d Playback"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) [SCARLETT2_PORT_TYPE_MIX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .id = 0x300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .num = { 10, 18, 18, 18, 18 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .src_descr = "Mix %c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .src_num_offset = 65,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .dst_descr = "Mixer Input %02d Capture"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) [SCARLETT2_PORT_TYPE_PCM] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .id = 0x600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .num = { 6, 6, 6, 6, 6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .src_descr = "PCM %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .dst_descr = "PCM %02d Capture"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) },
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static const struct scarlett2_device_info s18i8_gen2_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /* The first two analogue inputs can be switched between line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * and instrument levels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) .level_input_count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) /* The first four analogue inputs have an optional pad. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .pad_input_count = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .line_out_descrs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) "Monitor L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) "Monitor R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) "Headphones 1 L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) "Headphones 1 R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) "Headphones 2 L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) "Headphones 2 R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .ports = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) [SCARLETT2_PORT_TYPE_NONE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .id = 0x000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .num = { 1, 0, 8, 8, 4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .src_descr = "Off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .src_num_offset = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) [SCARLETT2_PORT_TYPE_ANALOGUE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .id = 0x080,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .num = { 8, 6, 6, 6, 6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .src_descr = "Analogue %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) .dst_descr = "Analogue Output %02d Playback"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) [SCARLETT2_PORT_TYPE_SPDIF] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .id = 0x180,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* S/PDIF outputs aren't available at 192kHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * but are included in the USB mux I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) * assignment message anyway
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) .num = { 2, 2, 2, 2, 2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) .src_descr = "S/PDIF %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .dst_descr = "S/PDIF Output %d Playback"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) [SCARLETT2_PORT_TYPE_ADAT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .id = 0x200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .num = { 8, 0, 0, 0, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .src_descr = "ADAT %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) [SCARLETT2_PORT_TYPE_MIX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) .id = 0x300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) .num = { 10, 18, 18, 18, 18 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .src_descr = "Mix %c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) .src_num_offset = 65,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) .dst_descr = "Mixer Input %02d Capture"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) [SCARLETT2_PORT_TYPE_PCM] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) .id = 0x600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) .num = { 8, 18, 18, 14, 10 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) .src_descr = "PCM %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) .dst_descr = "PCM %02d Capture"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static const struct scarlett2_device_info s18i20_gen2_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) /* The analogue line outputs on the 18i20 can be switched
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * between software and hardware volume control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) .line_out_hw_vol = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* Mute and dim buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) .button_count = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) .line_out_descrs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) "Monitor L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) "Monitor R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) "Headphones 1 L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) "Headphones 1 R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) "Headphones 2 L",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) "Headphones 2 R",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .ports = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) [SCARLETT2_PORT_TYPE_NONE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .id = 0x000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .num = { 1, 0, 8, 8, 6 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) .src_descr = "Off",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .src_num_offset = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) [SCARLETT2_PORT_TYPE_ANALOGUE] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) .id = 0x080,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) .num = { 8, 10, 10, 10, 10 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .src_descr = "Analogue %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) .dst_descr = "Analogue Output %02d Playback"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) [SCARLETT2_PORT_TYPE_SPDIF] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* S/PDIF outputs aren't available at 192kHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * but are included in the USB mux I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * assignment message anyway
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) .id = 0x180,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .num = { 2, 2, 2, 2, 2 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) .src_descr = "S/PDIF %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .dst_descr = "S/PDIF Output %d Playback"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) [SCARLETT2_PORT_TYPE_ADAT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) .id = 0x200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) .num = { 8, 8, 8, 4, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) .src_descr = "ADAT %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) .dst_descr = "ADAT Output %d Playback"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) [SCARLETT2_PORT_TYPE_MIX] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) .id = 0x300,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .num = { 10, 18, 18, 18, 18 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) .src_descr = "Mix %c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) .src_num_offset = 65,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) .dst_descr = "Mixer Input %02d Capture"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) [SCARLETT2_PORT_TYPE_PCM] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) .id = 0x600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) .num = { 20, 18, 18, 14, 10 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) .src_descr = "PCM %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) .src_num_offset = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) .dst_descr = "PCM %02d Capture"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /* get the starting port index number for a given port type/direction */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static int scarlett2_get_port_start_num(const struct scarlett2_ports *ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) int direction, int port_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int i, num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) for (i = 0; i < port_type; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) num += ports[i].num[direction];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /*** USB Interactions ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* Vendor-Specific Interface, Endpoint, MaxPacketSize, Interval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) #define SCARLETT2_USB_VENDOR_SPECIFIC_INTERFACE 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #define SCARLETT2_USB_INTERRUPT_ENDPOINT 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) #define SCARLETT2_USB_INTERRUPT_MAX_DATA 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) #define SCARLETT2_USB_INTERRUPT_INTERVAL 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* Interrupt flags for volume and mute/dim button changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #define SCARLETT2_USB_INTERRUPT_VOL_CHANGE 0x400000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) #define SCARLETT2_USB_INTERRUPT_BUTTON_CHANGE 0x200000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /* Commands for sending/receiving requests/responses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) #define SCARLETT2_USB_VENDOR_SPECIFIC_CMD_REQ 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #define SCARLETT2_USB_VENDOR_SPECIFIC_CMD_RESP 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) #define SCARLETT2_USB_INIT_SEQ 0x00000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #define SCARLETT2_USB_GET_METER_LEVELS 0x00001001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #define SCARLETT2_USB_SET_MIX 0x00002002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) #define SCARLETT2_USB_SET_MUX 0x00003002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #define SCARLETT2_USB_GET_DATA 0x00800000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #define SCARLETT2_USB_SET_DATA 0x00800001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) #define SCARLETT2_USB_DATA_CMD 0x00800002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) #define SCARLETT2_USB_CONFIG_SAVE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #define SCARLETT2_USB_VOLUME_STATUS_OFFSET 0x31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) #define SCARLETT2_USB_METER_LEVELS_GET_MAGIC 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* volume status is read together (matches scarlett2_config_items[]) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct scarlett2_usb_volume_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* mute & dim buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) u8 buttons[SCARLETT2_BUTTON_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) u8 pad1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) /* software volume setting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) s16 sw_vol[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) /* actual volume of output inc. dim (-18dB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) s16 hw_vol[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) u8 pad2[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /* sw (0) or hw (1) controlled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) u8 sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) u8 pad3[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /* front panel volume knob */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) s16 master_vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) } __packed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /* Configuration parameters that can be read and written */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) SCARLETT2_CONFIG_BUTTONS = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) SCARLETT2_CONFIG_LINE_OUT_VOLUME = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) SCARLETT2_CONFIG_SW_HW_SWITCH = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) SCARLETT2_CONFIG_LEVEL_SWITCH = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) SCARLETT2_CONFIG_PAD_SWITCH = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) SCARLETT2_CONFIG_COUNT = 5
^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) /* Location, size, and activation command number for the configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct scarlett2_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) u8 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) u8 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) u8 activate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) static const struct scarlett2_config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) scarlett2_config_items[SCARLETT2_CONFIG_COUNT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) /* Mute/Dim Buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) .offset = 0x31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) .size = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) .activate = 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /* Line Out Volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) .offset = 0x34,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) .size = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) .activate = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) /* SW/HW Volume Switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) .offset = 0x66,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) .size = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) .activate = 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /* Level Switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .offset = 0x7c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) .size = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) .activate = 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* Pad Switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) .offset = 0x84,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) .size = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) .activate = 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) /* proprietary request/response format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct scarlett2_usb_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) __le32 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) __le16 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) __le16 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) __le32 error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) __le32 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) u8 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) #define SCARLETT2_USB_PACKET_LEN (sizeof(struct scarlett2_usb_packet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static void scarlett2_fill_request_header(struct scarlett2_mixer_data *private,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct scarlett2_usb_packet *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) u32 cmd, u16 req_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /* sequence must go up by 1 for each request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) u16 seq = private->scarlett2_seq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) req->cmd = cpu_to_le32(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) req->size = cpu_to_le16(req_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) req->seq = cpu_to_le16(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) req->error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) req->pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /* Send a proprietary format request to the Scarlett interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static int scarlett2_usb(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) struct usb_mixer_interface *mixer, u32 cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) void *req_data, u16 req_size, void *resp_data, u16 resp_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) u16 req_buf_size = sizeof(struct scarlett2_usb_packet) + req_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) u16 resp_buf_size = sizeof(struct scarlett2_usb_packet) + resp_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct scarlett2_usb_packet *req = NULL, *resp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) req = kmalloc(req_buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (!req) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) resp = kmalloc(resp_buf_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (!resp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) mutex_lock(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* build request message and send it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) scarlett2_fill_request_header(private, req, cmd, req_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (req_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) memcpy(req->data, req_data, req_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) err = snd_usb_ctl_msg(mixer->chip->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) usb_sndctrlpipe(mixer->chip->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) SCARLETT2_USB_VENDOR_SPECIFIC_CMD_REQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) SCARLETT2_USB_VENDOR_SPECIFIC_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) req_buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (err != req_buf_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) usb_audio_err(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) mixer->chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) "Scarlett Gen 2 USB request result cmd %x was %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) cmd, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* send a second message to get the response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) err = snd_usb_ctl_msg(mixer->chip->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) usb_rcvctrlpipe(mixer->chip->dev, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) SCARLETT2_USB_VENDOR_SPECIFIC_CMD_RESP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) SCARLETT2_USB_VENDOR_SPECIFIC_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) resp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) resp_buf_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* validate the response */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (err != resp_buf_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) usb_audio_err(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) mixer->chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) "Scarlett Gen 2 USB response result cmd %x was %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) cmd, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) if (resp->cmd != req->cmd ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) resp->seq != req->seq ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) resp_size != le16_to_cpu(resp->size) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) resp->error ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) resp->pad) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) usb_audio_err(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) mixer->chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) "Scarlett Gen 2 USB invalid response; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) "cmd tx/rx %d/%d seq %d/%d size %d/%d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) "error %d pad %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) resp_size, le16_to_cpu(resp->size),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) le32_to_cpu(resp->error),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) le32_to_cpu(resp->pad));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) goto unlock;
^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) if (resp_size > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) memcpy(resp_data, resp->data, resp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) mutex_unlock(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) kfree(req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) kfree(resp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* Send SCARLETT2_USB_DATA_CMD SCARLETT2_USB_CONFIG_SAVE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) static void scarlett2_config_save(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) __le32 req = cpu_to_le32(SCARLETT2_USB_CONFIG_SAVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) &req, sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /* Delayed work to save config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static void scarlett2_config_save_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct scarlett2_mixer_data *private =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) container_of(work, struct scarlett2_mixer_data, work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) scarlett2_config_save(private->mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) /* Send a USB message to set a configuration parameter (volume level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * sw/hw volume switch, line/inst level switch, or pad switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static int scarlett2_usb_set_config(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) int config_item_num, int index, int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) const struct scarlett2_config config_item =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) scarlett2_config_items[config_item_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) __le32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) __le32 bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) __le32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) } __packed req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) __le32 req2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) /* Cancel any pending NVRAM save */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) cancel_delayed_work_sync(&private->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) /* Send the configuration parameter data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) req.offset = cpu_to_le32(config_item.offset + index * config_item.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) req.bytes = cpu_to_le32(config_item.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) req.value = cpu_to_le32(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) err = scarlett2_usb(mixer, SCARLETT2_USB_SET_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) &req, sizeof(u32) * 2 + config_item.size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) /* Activate the change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) req2 = cpu_to_le32(config_item.activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) err = scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) &req2, sizeof(req2), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) /* Schedule the change to be written to NVRAM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) schedule_delayed_work(&private->work, msecs_to_jiffies(2000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) /* Send a USB message to get data; result placed in *buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) static int scarlett2_usb_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) int offset, void *buf, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) __le32 offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) __le32 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) } __packed req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) req.offset = cpu_to_le32(offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) req.size = cpu_to_le32(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return scarlett2_usb(mixer, SCARLETT2_USB_GET_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) &req, sizeof(req), buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /* Send a USB message to get configuration parameters; result placed in *buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) static int scarlett2_usb_get_config(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) int config_item_num, int count, void *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) const struct scarlett2_config config_item =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) scarlett2_config_items[config_item_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) int size = config_item.size * count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) return scarlett2_usb_get(mixer, config_item.offset, buf, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) /* Send a USB message to get volume status; result placed in *buf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) static int scarlett2_usb_get_volume_status(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) struct scarlett2_usb_volume_status *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) return scarlett2_usb_get(mixer, SCARLETT2_USB_VOLUME_STATUS_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) buf, sizeof(*buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) /* Send a USB message to set the volumes for all inputs of one mix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) * (values obtained from private->mix[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) static int scarlett2_usb_set_mix(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int mix_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) const struct scarlett2_device_info *info = private->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) __le16 mix_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) __le16 data[SCARLETT2_INPUT_MIX_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) } __packed req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) int num_mixer_in =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) info->ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) req.mix_num = cpu_to_le16(mix_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) req.data[i] = cpu_to_le16(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) scarlett2_mixer_values[private->mix[j]]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) return scarlett2_usb(mixer, SCARLETT2_USB_SET_MIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) &req, (num_mixer_in + 1) * sizeof(u16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) /* Convert a port number index (per info->ports) to a hardware ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) static u32 scarlett2_mux_src_num_to_id(const struct scarlett2_ports *ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) int port_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) for (port_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) port_type < SCARLETT2_PORT_TYPE_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) port_type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (num < ports[port_type].num[SCARLETT2_PORT_IN])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return ports[port_type].id | num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) num -= ports[port_type].num[SCARLETT2_PORT_IN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /* Oops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) /* Send USB messages to set mux inputs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) static int scarlett2_usb_set_mux(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) const struct scarlett2_device_info *info = private->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) const struct scarlett2_ports *ports = info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) int rate, port_dir_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) static const int assignment_order[SCARLETT2_PORT_TYPE_COUNT] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) SCARLETT2_PORT_TYPE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) SCARLETT2_PORT_TYPE_ANALOGUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) SCARLETT2_PORT_TYPE_SPDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) SCARLETT2_PORT_TYPE_ADAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) SCARLETT2_PORT_TYPE_MIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) SCARLETT2_PORT_TYPE_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) __le16 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) __le16 num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) __le32 data[SCARLETT2_MUX_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) } __packed req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) req.pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) /* mux settings for each rate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) for (rate = 0, port_dir_rate = SCARLETT2_PORT_OUT_44;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) port_dir_rate <= SCARLETT2_PORT_OUT_176;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) rate++, port_dir_rate++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) int order_num, i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) req.num = cpu_to_le16(rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) for (order_num = 0, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) order_num < SCARLETT2_PORT_TYPE_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) order_num++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) int port_type = assignment_order[order_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) int j = scarlett2_get_port_start_num(ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) SCARLETT2_PORT_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) port_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) int port_id = ports[port_type].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) int channel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) for (channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) channel < ports[port_type].num[port_dir_rate];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) channel++, i++, j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) /* lower 12 bits for the destination and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) * next 12 bits for the source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) req.data[i] = !port_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) ? 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) : cpu_to_le32(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) port_id |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) channel |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) scarlett2_mux_src_num_to_id(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) ports, private->mux[j]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) ) << 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) /* skip private->mux[j] entries not output */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) j += ports[port_type].num[SCARLETT2_PORT_OUT] -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) ports[port_type].num[port_dir_rate];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) err = scarlett2_usb(mixer, SCARLETT2_USB_SET_MUX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) &req, (i + 1) * sizeof(u32),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) NULL, 0);
^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) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /* Send USB message to get meter levels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) static int scarlett2_usb_get_meter_levels(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) u16 *levels)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) __le16 pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) __le16 num_meters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) __le32 magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) } __packed req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) u32 resp[SCARLETT2_NUM_METERS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) req.pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) req.num_meters = cpu_to_le16(SCARLETT2_NUM_METERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) req.magic = cpu_to_le32(SCARLETT2_USB_METER_LEVELS_GET_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) err = scarlett2_usb(mixer, SCARLETT2_USB_GET_METER_LEVELS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) &req, sizeof(req), resp, sizeof(resp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) /* copy, convert to u16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) for (i = 0; i < SCARLETT2_NUM_METERS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) levels[i] = resp[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) /*** Control Functions ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) /* helper function to create a new control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) const struct snd_kcontrol_new *ncontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) int index, int channels, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) struct snd_kcontrol **kctl_return)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) struct snd_kcontrol *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) struct usb_mixer_elem_info *elem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) elem = kzalloc(sizeof(*elem), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) if (!elem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) /* We set USB_MIXER_BESPOKEN type, so that the core USB mixer code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) * ignores them for resume and other operations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) * Also, the head.id field is set to 0, as we don't use this field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) elem->head.mixer = mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) elem->control = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) elem->head.id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) elem->channels = channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) elem->val_type = USB_MIXER_BESPOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) kctl = snd_ctl_new1(ncontrol, elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) if (!kctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) kfree(elem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) kctl->private_free = snd_usb_mixer_elem_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) err = snd_usb_mixer_add_control(&elem->head, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) if (kctl_return)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) *kctl_return = kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) /*** Analogue Line Out Volume Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) /* Update hardware volume controls after receiving notification that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * they have changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) static int scarlett2_update_volumes(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) const struct scarlett2_ports *ports = private->info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) struct scarlett2_usb_volume_status volume_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) int num_line_out =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) private->vol_updated = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) err = scarlett2_usb_get_volume_status(mixer, &volume_status);
^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) private->master_vol = clamp(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) volume_status.master_vol + SCARLETT2_VOLUME_BIAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 0, SCARLETT2_VOLUME_BIAS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) for (i = 0; i < num_line_out; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) if (private->vol_sw_hw_switch[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) private->vol[i] = private->master_vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) for (i = 0; i < private->info->button_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) private->buttons[i] = !!volume_status.buttons[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) static int scarlett2_volume_ctl_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) uinfo->count = elem->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) uinfo->value.integer.max = SCARLETT2_VOLUME_BIAS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) uinfo->value.integer.step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) static int scarlett2_master_volume_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (private->vol_updated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) scarlett2_update_volumes(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) ucontrol->value.integer.value[0] = private->master_vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) static int scarlett2_volume_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) int index = elem->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) if (private->vol_updated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) scarlett2_update_volumes(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) ucontrol->value.integer.value[0] = private->vol[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) static int scarlett2_volume_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) int index = elem->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) int oval, val, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) oval = private->vol[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) val = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (oval == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) private->vol[index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) index, val - SCARLETT2_VOLUME_BIAS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) static const DECLARE_TLV_DB_MINMAX(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) db_scale_scarlett2_gain, -SCARLETT2_VOLUME_BIAS * 100, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) static const struct snd_kcontrol_new scarlett2_master_volume_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) .access = SNDRV_CTL_ELEM_ACCESS_READ |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) .info = scarlett2_volume_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) .get = scarlett2_master_volume_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) .private_value = 0, /* max value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) .tlv = { .p = db_scale_scarlett2_gain }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) static const struct snd_kcontrol_new scarlett2_line_out_volume_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) .info = scarlett2_volume_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) .get = scarlett2_volume_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) .put = scarlett2_volume_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) .private_value = 0, /* max value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) .tlv = { .p = db_scale_scarlett2_gain }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) /*** HW/SW Volume Switch Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) static int scarlett2_sw_hw_enum_ctl_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) static const char *const values[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) "SW", "HW"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) return snd_ctl_enum_info(uinfo, 1, 2, values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) static int scarlett2_sw_hw_enum_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) struct scarlett2_mixer_data *private = elem->head.mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) ucontrol->value.enumerated.item[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) private->vol_sw_hw_switch[elem->control];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) int index = elem->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) int oval, val, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) oval = private->vol_sw_hw_switch[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) val = !!ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) if (oval == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) private->vol_sw_hw_switch[index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) /* Change access mode to RO (hardware controlled volume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) * or RW (software controlled volume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) private->vol_ctls[index]->vd[0].access &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) ~SNDRV_CTL_ELEM_ACCESS_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) private->vol_ctls[index]->vd[0].access |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) SNDRV_CTL_ELEM_ACCESS_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) /* Reset volume to master volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) private->vol[index] = private->master_vol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) /* Set SW volume to current HW volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) err = scarlett2_usb_set_config(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) index, private->master_vol - SCARLETT2_VOLUME_BIAS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) /* Notify of RO/RW change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) &private->vol_ctls[index]->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) /* Send SW/HW switch change to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) index, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) static const struct snd_kcontrol_new scarlett2_sw_hw_enum_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) .info = scarlett2_sw_hw_enum_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) .get = scarlett2_sw_hw_enum_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) .put = scarlett2_sw_hw_enum_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) /*** Line Level/Instrument Level Switch Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) static int scarlett2_level_enum_ctl_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) static const char *const values[2] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) "Line", "Inst"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) return snd_ctl_enum_info(uinfo, 1, 2, values);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) static int scarlett2_level_enum_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) struct scarlett2_mixer_data *private = elem->head.mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) ucontrol->value.enumerated.item[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) private->level_switch[elem->control];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) static int scarlett2_level_enum_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) int index = elem->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) int oval, val, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) oval = private->level_switch[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) val = !!ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) if (oval == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) private->level_switch[index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) /* Send switch change to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) index, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) static const struct snd_kcontrol_new scarlett2_level_enum_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) .info = scarlett2_level_enum_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) .get = scarlett2_level_enum_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) .put = scarlett2_level_enum_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) /*** Pad Switch Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) static int scarlett2_pad_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) struct scarlett2_mixer_data *private = elem->head.mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) ucontrol->value.enumerated.item[0] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) private->pad_switch[elem->control];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) static int scarlett2_pad_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) int index = elem->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) int oval, val, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) oval = private->pad_switch[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) val = !!ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) if (oval == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) private->pad_switch[index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) /* Send switch change to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_PAD_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) index, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) static const struct snd_kcontrol_new scarlett2_pad_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) .info = snd_ctl_boolean_mono_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) .get = scarlett2_pad_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) .put = scarlett2_pad_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) /*** Mute/Dim Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) static int scarlett2_button_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) if (private->vol_updated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) scarlett2_update_volumes(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) ucontrol->value.enumerated.item[0] = private->buttons[elem->control];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) static int scarlett2_button_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) int index = elem->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) int oval, val, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) oval = private->buttons[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) val = !!ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (oval == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) private->buttons[index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) /* Send switch change to the device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_BUTTONS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) index, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) static const struct snd_kcontrol_new scarlett2_button_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) .info = snd_ctl_boolean_mono_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) .get = scarlett2_button_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) .put = scarlett2_button_ctl_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) /*** Create the analogue output controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) static int scarlett2_add_line_out_ctls(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) const struct scarlett2_device_info *info = private->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) const struct scarlett2_ports *ports = info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) int num_line_out =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) /* Add R/O HW volume control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) if (info->line_out_hw_vol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) snprintf(s, sizeof(s), "Master HW Playback Volume");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) err = scarlett2_add_new_ctl(mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) &scarlett2_master_volume_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 0, 1, s, &private->master_vol_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) /* Add volume controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) for (i = 0; i < num_line_out; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) /* Fader */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) if (info->line_out_descrs[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) snprintf(s, sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) "Line %02d (%s) Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) i + 1, info->line_out_descrs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) snprintf(s, sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) "Line %02d Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) err = scarlett2_add_new_ctl(mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) &scarlett2_line_out_volume_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) i, 1, s, &private->vol_ctls[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) /* Make the fader read-only if the SW/HW switch is set to HW */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (private->vol_sw_hw_switch[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) private->vol_ctls[i]->vd[0].access &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) ~SNDRV_CTL_ELEM_ACCESS_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) /* SW/HW Switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (info->line_out_hw_vol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) snprintf(s, sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) "Line Out %02d Volume Control Playback Enum",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) err = scarlett2_add_new_ctl(mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) &scarlett2_sw_hw_enum_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) i, 1, s, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) /* Add HW button controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) for (i = 0; i < private->info->button_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) err = scarlett2_add_new_ctl(mixer, &scarlett2_button_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) i, 1, scarlett2_button_names[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) &private->button_ctls[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) /*** Create the analogue input controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) static int scarlett2_add_line_in_ctls(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) const struct scarlett2_device_info *info = private->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) /* Add input level (line/inst) controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) for (i = 0; i < info->level_input_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) snprintf(s, sizeof(s), "Line In %d Level Capture Enum", i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) err = scarlett2_add_new_ctl(mixer, &scarlett2_level_enum_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) i, 1, s, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) /* Add input pad controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) for (i = 0; i < info->pad_input_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) snprintf(s, sizeof(s), "Line In %d Pad Capture Switch", i + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) err = scarlett2_add_new_ctl(mixer, &scarlett2_pad_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) i, 1, s, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) /*** Mixer Volume Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) static int scarlett2_mixer_ctl_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) uinfo->count = elem->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) uinfo->value.integer.max = SCARLETT2_MIXER_MAX_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) uinfo->value.integer.step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) static int scarlett2_mixer_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) struct scarlett2_mixer_data *private = elem->head.mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) ucontrol->value.integer.value[0] = private->mix[elem->control];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) static int scarlett2_mixer_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) const struct scarlett2_device_info *info = private->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) const struct scarlett2_ports *ports = info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) int oval, val, num_mixer_in, mix_num, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) oval = private->mix[elem->control];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) val = ucontrol->value.integer.value[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) num_mixer_in = ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) mix_num = elem->control / num_mixer_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) if (oval == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) private->mix[elem->control] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) err = scarlett2_usb_set_mix(mixer, mix_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) static const DECLARE_TLV_DB_MINMAX(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) db_scale_scarlett2_mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) SCARLETT2_MIXER_MIN_DB * 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) SCARLETT2_MIXER_MAX_DB * 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) static const struct snd_kcontrol_new scarlett2_mixer_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) SNDRV_CTL_ELEM_ACCESS_TLV_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) .info = scarlett2_mixer_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) .get = scarlett2_mixer_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) .put = scarlett2_mixer_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) .private_value = SCARLETT2_MIXER_MAX_DB, /* max value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) .tlv = { .p = db_scale_scarlett2_mixer }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) static int scarlett2_add_mixer_ctls(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) const struct scarlett2_ports *ports = private->info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) int err, i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) int num_inputs = ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) int num_outputs = ports[SCARLETT2_PORT_TYPE_MIX].num[SCARLETT2_PORT_IN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) for (i = 0, index = 0; i < num_outputs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) for (j = 0; j < num_inputs; j++, index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) snprintf(s, sizeof(s),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) "Mix %c Input %02d Playback Volume",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 'A' + i, j + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) err = scarlett2_add_new_ctl(mixer, &scarlett2_mixer_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) index, 1, s, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) /*** Mux Source Selection Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) static int scarlett2_mux_src_enum_ctl_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) struct scarlett2_mixer_data *private = elem->head.mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) const struct scarlett2_ports *ports = private->info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) unsigned int item = uinfo->value.enumerated.item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) int items = private->num_mux_srcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) int port_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) uinfo->count = elem->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) uinfo->value.enumerated.items = items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) if (item >= items)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) item = uinfo->value.enumerated.item = items - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) for (port_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) port_type < SCARLETT2_PORT_TYPE_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) port_type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) if (item < ports[port_type].num[SCARLETT2_PORT_IN]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) sprintf(uinfo->value.enumerated.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) ports[port_type].src_descr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) item + ports[port_type].src_num_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) item -= ports[port_type].num[SCARLETT2_PORT_IN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) static int scarlett2_mux_src_enum_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) struct scarlett2_mixer_data *private = elem->head.mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) ucontrol->value.enumerated.item[0] = private->mux[elem->control];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) static int scarlett2_mux_src_enum_ctl_put(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) struct usb_mixer_interface *mixer = elem->head.mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) int index = elem->control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) int oval, val, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) mutex_lock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) oval = private->mux[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) val = clamp(ucontrol->value.integer.value[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 0L, private->num_mux_srcs - 1L);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) if (oval == val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) private->mux[index] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) err = scarlett2_usb_set_mux(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) if (err == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) err = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) mutex_unlock(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) static const struct snd_kcontrol_new scarlett2_mux_src_enum_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) .info = scarlett2_mux_src_enum_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) .get = scarlett2_mux_src_enum_ctl_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) .put = scarlett2_mux_src_enum_ctl_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) static int scarlett2_add_mux_enums(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) const struct scarlett2_ports *ports = private->info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) int port_type, channel, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) for (i = 0, port_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) port_type < SCARLETT2_PORT_TYPE_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) port_type++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) for (channel = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) channel < ports[port_type].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) channel++, i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) char s[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) const char *const descr = ports[port_type].dst_descr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) snprintf(s, sizeof(s) - 5, descr, channel + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) strcat(s, " Enum");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) err = scarlett2_add_new_ctl(mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) &scarlett2_mux_src_enum_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) i, 1, s, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) /*** Meter Controls ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) static int scarlett2_meter_ctl_info(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) uinfo->count = elem->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) uinfo->value.integer.max = 4095;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) uinfo->value.integer.step = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) static int scarlett2_meter_ctl_get(struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) struct usb_mixer_elem_info *elem = kctl->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) u16 meter_levels[SCARLETT2_NUM_METERS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) err = scarlett2_usb_get_meter_levels(elem->head.mixer, meter_levels);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) for (i = 0; i < elem->channels; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) ucontrol->value.integer.value[i] = meter_levels[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) static const struct snd_kcontrol_new scarlett2_meter_ctl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) .iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) .name = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) .info = scarlett2_meter_ctl_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) .get = scarlett2_meter_ctl_get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) static int scarlett2_add_meter_ctl(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) return scarlett2_add_new_ctl(mixer, &scarlett2_meter_ctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 0, SCARLETT2_NUM_METERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) "Level Meter", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) /*** Cleanup/Suspend Callbacks ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) static void scarlett2_private_free(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) cancel_delayed_work_sync(&private->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) kfree(private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) mixer->private_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) static void scarlett2_private_suspend(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) if (cancel_delayed_work_sync(&private->work))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) scarlett2_config_save(private->mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) /*** Initialisation ***/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) static int scarlett2_count_mux_srcs(const struct scarlett2_ports *ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) int port_type, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) for (port_type = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) port_type < SCARLETT2_PORT_TYPE_COUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) port_type++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) count += ports[port_type].num[SCARLETT2_PORT_IN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) /* Default routing connects PCM outputs and inputs to Analogue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) * S/PDIF, then ADAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) static void scarlett2_init_routing(u8 *mux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) const struct scarlett2_ports *ports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) int i, input_num, input_count, port_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) int output_num, output_count, port_type_connect_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) static const int connect_order[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) SCARLETT2_PORT_TYPE_ANALOGUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) SCARLETT2_PORT_TYPE_SPDIF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) SCARLETT2_PORT_TYPE_ADAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) /* Assign PCM inputs (routing outputs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) output_num = scarlett2_get_port_start_num(ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) SCARLETT2_PORT_OUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) SCARLETT2_PORT_TYPE_PCM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) output_count = ports[SCARLETT2_PORT_TYPE_PCM].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) for (port_type = connect_order[port_type_connect_num = 0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) port_type >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) port_type = connect_order[++port_type_connect_num]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) input_num = scarlett2_get_port_start_num(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) ports, SCARLETT2_PORT_IN, port_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) input_count = ports[port_type].num[SCARLETT2_PORT_IN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) for (i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) i < input_count && output_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) i++, output_count--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) mux[output_num++] = input_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) /* Assign PCM outputs (routing inputs) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) input_num = scarlett2_get_port_start_num(ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) SCARLETT2_PORT_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) SCARLETT2_PORT_TYPE_PCM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) input_count = ports[SCARLETT2_PORT_TYPE_PCM].num[SCARLETT2_PORT_IN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) for (port_type = connect_order[port_type_connect_num = 0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) port_type >= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) port_type = connect_order[++port_type_connect_num]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) output_num = scarlett2_get_port_start_num(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) ports, SCARLETT2_PORT_OUT, port_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) output_count = ports[port_type].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) for (i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) i < output_count && input_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) i++, input_count--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) mux[output_num++] = input_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) /* Initialise private data, routing, sequence number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) static int scarlett2_init_private(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) const struct scarlett2_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) struct scarlett2_mixer_data *private =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) kzalloc(sizeof(struct scarlett2_mixer_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) if (!private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) mutex_init(&private->usb_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) mutex_init(&private->data_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) INIT_DELAYED_WORK(&private->work, scarlett2_config_save_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) private->info = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) private->num_mux_srcs = scarlett2_count_mux_srcs(info->ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) private->scarlett2_seq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) private->mixer = mixer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) mixer->private_data = private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) mixer->private_free = scarlett2_private_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) mixer->private_suspend = scarlett2_private_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) /* Setup default routing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) scarlett2_init_routing(private->mux, info->ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) /* Initialise the sequence number used for the proprietary commands */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) return scarlett2_usb(mixer, SCARLETT2_USB_INIT_SEQ, NULL, 0, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) /* Read line-in config and line-out volume settings on start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) const struct scarlett2_device_info *info = private->info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) const struct scarlett2_ports *ports = info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) int num_line_out =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) u8 level_switches[SCARLETT2_LEVEL_SWITCH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) u8 pad_switches[SCARLETT2_PAD_SWITCH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) struct scarlett2_usb_volume_status volume_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) if (info->level_input_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) err = scarlett2_usb_get_config(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) SCARLETT2_CONFIG_LEVEL_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) info->level_input_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) level_switches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) for (i = 0; i < info->level_input_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) private->level_switch[i] = level_switches[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) if (info->pad_input_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) err = scarlett2_usb_get_config(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) SCARLETT2_CONFIG_PAD_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) info->pad_input_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) pad_switches);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) for (i = 0; i < info->pad_input_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) private->pad_switch[i] = pad_switches[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) err = scarlett2_usb_get_volume_status(mixer, &volume_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) private->master_vol = clamp(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) volume_status.master_vol + SCARLETT2_VOLUME_BIAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 0, SCARLETT2_VOLUME_BIAS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) for (i = 0; i < num_line_out; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) int volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) private->vol_sw_hw_switch[i] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) info->line_out_hw_vol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) && volume_status.sw_hw_switch[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) volume = private->vol_sw_hw_switch[i]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) ? volume_status.master_vol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) : volume_status.sw_vol[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) volume = clamp(volume + SCARLETT2_VOLUME_BIAS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 0, SCARLETT2_VOLUME_BIAS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) private->vol[i] = volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) for (i = 0; i < info->button_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) private->buttons[i] = !!volume_status.buttons[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) /* Notify on volume change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) static void scarlett2_mixer_interrupt_vol_change(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) const struct scarlett2_ports *ports = private->info->ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) int num_line_out =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) ports[SCARLETT2_PORT_TYPE_ANALOGUE].num[SCARLETT2_PORT_OUT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) private->vol_updated = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) &private->master_vol_ctl->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) for (i = 0; i < num_line_out; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) if (!private->vol_sw_hw_switch[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) &private->vol_ctls[i]->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) /* Notify on button change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) static void scarlett2_mixer_interrupt_button_change(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) struct scarlett2_mixer_data *private = mixer->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) private->vol_updated = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) for (i = 0; i < private->info->button_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) &private->button_ctls[i]->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) /* Interrupt callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) static void scarlett2_mixer_interrupt(struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) struct usb_mixer_interface *mixer = urb->context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) int len = urb->actual_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) int ustatus = urb->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) u32 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) if (ustatus != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) goto requeue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) if (len == 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) data = le32_to_cpu(*(__le32 *)urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) if (data & SCARLETT2_USB_INTERRUPT_VOL_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) scarlett2_mixer_interrupt_vol_change(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) if (data & SCARLETT2_USB_INTERRUPT_BUTTON_CHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) scarlett2_mixer_interrupt_button_change(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) usb_audio_err(mixer->chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) "scarlett mixer interrupt length %d\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) requeue:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (ustatus != -ENOENT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) ustatus != -ECONNRESET &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) ustatus != -ESHUTDOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) urb->dev = mixer->chip->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) usb_submit_urb(urb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) static int scarlett2_mixer_status_create(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) struct usb_device *dev = mixer->chip->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) unsigned int pipe = usb_rcvintpipe(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) SCARLETT2_USB_INTERRUPT_ENDPOINT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) void *transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) if (mixer->urb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) usb_audio_err(mixer->chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) "%s: mixer urb already in use!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) if (usb_pipe_type_check(dev, pipe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) mixer->urb = usb_alloc_urb(0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) if (!mixer->urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) transfer_buffer = kmalloc(SCARLETT2_USB_INTERRUPT_MAX_DATA, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) if (!transfer_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) usb_fill_int_urb(mixer->urb, dev, pipe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) transfer_buffer, SCARLETT2_USB_INTERRUPT_MAX_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) scarlett2_mixer_interrupt, mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) SCARLETT2_USB_INTERRUPT_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) return usb_submit_urb(mixer->urb, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) static int snd_scarlett_gen2_controls_create(struct usb_mixer_interface *mixer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) const struct scarlett2_device_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) /* Initialise private data, routing, sequence number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) err = scarlett2_init_private(mixer, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) /* Read volume levels and controls from the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) err = scarlett2_read_configs(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) /* Create the analogue output controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) err = scarlett2_add_line_out_ctls(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) /* Create the analogue input controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) err = scarlett2_add_line_in_ctls(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) /* Create the input, output, and mixer mux input selections */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) err = scarlett2_add_mux_enums(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) /* Create the matrix mixer controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) err = scarlett2_add_mixer_ctls(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) /* Create the level meter controls */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) err = scarlett2_add_meter_ctl(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) /* Set up the interrupt polling if there are hardware buttons */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) if (info->button_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) err = scarlett2_mixer_status_create(mixer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) int snd_scarlett_gen2_init(struct usb_mixer_interface *mixer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) struct snd_usb_audio *chip = mixer->chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) const struct scarlett2_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) /* only use UAC_VERSION_2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) if (!mixer->protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) switch (chip->usb_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) case USB_ID(0x1235, 0x8203):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) info = &s6i6_gen2_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) case USB_ID(0x1235, 0x8204):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) info = &s18i8_gen2_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) case USB_ID(0x1235, 0x8201):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) info = &s18i20_gen2_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) default: /* device not (yet) supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) if (!(chip->setup & SCARLETT2_ENABLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) usb_audio_info(chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) "Focusrite Scarlett Gen 2 Mixer Driver disabled; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) "use options snd_usb_audio vid=0x%04x pid=0x%04x "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) "device_setup=1 to enable and report any issues "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) "to g@b4.vu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) USB_ID_VENDOR(chip->usb_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) USB_ID_PRODUCT(chip->usb_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) usb_audio_info(chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) "Focusrite Scarlett Gen 2 Mixer Driver enabled pid=0x%04x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) USB_ID_PRODUCT(chip->usb_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) err = snd_scarlett_gen2_controls_create(mixer, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) usb_audio_err(mixer->chip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) "Error initialising Scarlett Mixer Driver: %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) }