blob: 6de605a601e5f89ff7a9c12b36db81eed6d876c3 [file] [log] [blame]
// SPDX-License-Identifier: GPL-2.0
/*
* Focusrite Scarlett 2 Protocol Driver for ALSA
* (including Scarlett 2nd Gen, 3rd Gen, 4th Gen, Clarett USB, and
* Clarett+ series products)
*
* Supported models:
* - 6i6/18i8/18i20 Gen 2
* - Solo/2i2/4i4/8i6/18i8/18i20 Gen 3
* - Solo/2i2/4i4 Gen 4
* - Clarett 2Pre/4Pre/8Pre USB
* - Clarett+ 2Pre/4Pre/8Pre
*
* Copyright (c) 2018-2023 by Geoffrey D. Bennett <g at b4.vu>
* Copyright (c) 2020-2021 by Vladimir Sadovnikov <sadko4u@gmail.com>
* Copyright (c) 2022 by Christian Colglazier <christian@cacolglazier.com>
*
* Based on the Scarlett (Gen 1) Driver for ALSA:
*
* Copyright (c) 2013 by Tobias Hoffmann
* Copyright (c) 2013 by Robin Gareus <robin at gareus.org>
* Copyright (c) 2002 by Takashi Iwai <tiwai at suse.de>
* Copyright (c) 2014 by Chris J Arges <chris.j.arges at canonical.com>
*
* Many codes borrowed from audio.c by
* Alan Cox (alan at lxorguk.ukuu.org.uk)
* Thomas Sailer (sailer at ife.ee.ethz.ch)
*
* Code cleanup:
* David Henningsson <david.henningsson at canonical.com>
*/
/* The protocol was reverse engineered by looking at the communication
* between Focusrite Control 2.3.4 and the Focusrite(R) Scarlett 18i20
* (firmware 1083) using usbmon in July-August 2018.
*
* Scarlett 18i8 support added in April 2019.
*
* Scarlett 6i6 support added in June 2019 (thanks to Martin Wittmann
* for providing usbmon output and testing).
*
* Scarlett 4i4/8i6 Gen 3 support added in May 2020 (thanks to Laurent
* Debricon for donating a 4i4 and to Fredrik Unger for providing 8i6
* usbmon output and testing).
*
* Scarlett 18i8/18i20 Gen 3 support added in June 2020 (thanks to
* Darren Jaeckel, Alex Sedlack, and Clovis Lunel for providing usbmon
* output, protocol traces and testing).
*
* Support for loading mixer volume and mux configuration from the
* interface during driver initialisation added in May 2021 (thanks to
* Vladimir Sadovnikov for figuring out how).
*
* Support for Solo/2i2 Gen 3 added in May 2021 (thanks to Alexander
* Vorona for 2i2 protocol traces).
*
* Support for phantom power, direct monitoring, speaker switching,
* and talkback added in May-June 2021.
*
* Support for Clarett+ 8Pre added in Aug 2022 by Christian
* Colglazier.
*
* Support for Clarett 8Pre USB added in Sep 2023 (thanks to Philippe
* Perrot for confirmation).
*
* Support for Clarett+ 4Pre and 2Pre added in Sep 2023 (thanks to
* Gregory Rozzo for donating a 4Pre, and David Sherwood and Patrice
* Peterson for usbmon output).
*
* Support for Clarett 2Pre and 4Pre USB added in Oct 2023.
*
* Support for firmware updates added in Dec 2023.
*
* Support for Scarlett Solo/2i2/4i4 Gen 4 added in Dec 2023 (thanks
* to many LinuxMusicians people and to Focusrite for hardware
* donations).
*
* This ALSA mixer gives access to (model-dependent):
* - input, output, mixer-matrix muxes
* - mixer-matrix gain stages
* - gain/volume/mute controls
* - level meters
* - line/inst level, pad, and air controls
* - phantom power, direct monitor, speaker switching, and talkback
* controls
* - disable/enable MSD mode
* - disable/enable standalone mode
* - input gain, autogain, safe mode
* - direct monitor mixes
*
* <ditaa>
* /--------------\ 18chn 20chn /--------------\
* | Hardware in +--+------\ /-------------+--+ ALSA PCM out |
* \--------------/ | | | | \--------------/
* | | | /-----\ |
* | | | | | |
* | v v v | |
* | +---------------+ | |
* | \ Matrix Mux / | |
* | +-----+-----+ | |
* | | | |
* | |18chn | |
* | | | |
* | | 10chn| |
* | v | |
* | +------------+ | |
* | | Mixer | | |
* | | Matrix | | |
* | | | | |
* | | 18x10 Gain | | |
* | | stages | | |
* | +-----+------+ | |
* | | | |
* |18chn |10chn | |20chn
* | | | |
* | +----------/ |
* | | |
* v v v
* ===========================
* +---------------+ +--—------------+
* \ Output Mux / \ Capture Mux /
* +---+---+---+ +-----+-----+
* | | |
* 10chn| | |18chn
* | | |
* /--------------\ | | | /--------------\
* | S/PDIF, ADAT |<--/ |10chn \-->| ALSA PCM in |
* | Hardware out | | \--------------/
* \--------------/ |
* v
* +-------------+ Software gain per channel.
* | Master Gain |<-- 18i20 only: Switch per channel
* +------+------+ to select HW or SW gain control.
* |
* |10chn
* /--------------\ |
* | Analogue |<------/
* | Hardware out |
* \--------------/
* </ditaa>
*
* Gen 3/4 devices have a Mass Storage Device (MSD) mode where a small
* disk with registration and driver download information is presented
* to the host. To access the full functionality of the device without
* proprietary software, MSD mode can be disabled by:
* - holding down the 48V button for five seconds while powering on
* the device, or
* - using this driver and alsamixer to change the "MSD Mode" setting
* to Off and power-cycling the device
*/
#include <linux/slab.h>
#include <linux/usb.h>
#include <linux/moduleparam.h>
#include <sound/control.h>
#include <sound/tlv.h>
#include <sound/hwdep.h>
#include <uapi/sound/scarlett2.h>
#include "usbaudio.h"
#include "mixer.h"
#include "helper.h"
#include "mixer_scarlett2.h"
/* device_setup value to allow turning MSD mode back on */
#define SCARLETT2_MSD_ENABLE 0x02
/* device_setup value to disable this mixer driver */
#define SCARLETT2_DISABLE 0x04
/* some gui mixers can't handle negative ctl values */
#define SCARLETT2_VOLUME_BIAS 127
#define SCARLETT2_GAIN_BIAS 70
/* mixer range from -80dB to +6dB in 0.5dB steps */
#define SCARLETT2_MIXER_MIN_DB -80
#define SCARLETT2_MIXER_BIAS (-SCARLETT2_MIXER_MIN_DB * 2)
#define SCARLETT2_MIXER_MAX_DB 6
#define SCARLETT2_MIXER_MAX_VALUE \
((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2)
#define SCARLETT2_MIXER_VALUE_COUNT (SCARLETT2_MIXER_MAX_VALUE + 1)
/* map from (dB + 80) * 2 to mixer value
* for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20)))
*/
static const u16 scarlett2_mixer_values[SCARLETT2_MIXER_VALUE_COUNT] = {
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
23, 24, 25, 27, 29, 30, 32, 34, 36, 38, 41, 43, 46, 48, 51,
54, 57, 61, 65, 68, 73, 77, 81, 86, 91, 97, 103, 109, 115,
122, 129, 137, 145, 154, 163, 173, 183, 194, 205, 217, 230,
244, 259, 274, 290, 307, 326, 345, 365, 387, 410, 434, 460,
487, 516, 547, 579, 614, 650, 689, 730, 773, 819, 867, 919,
973, 1031, 1092, 1157, 1225, 1298, 1375, 1456, 1543, 1634,
1731, 1833, 1942, 2057, 2179, 2308, 2445, 2590, 2744, 2906,
3078, 3261, 3454, 3659, 3876, 4105, 4349, 4606, 4879, 5168,
5475, 5799, 6143, 6507, 6892, 7301, 7733, 8192, 8677, 9191,
9736, 10313, 10924, 11571, 12257, 12983, 13752, 14567, 15430,
16345
};
/* Maximum number of analogue outputs */
#define SCARLETT2_ANALOGUE_MAX 10
/* Maximum number of various input controls */
#define SCARLETT2_LEVEL_SWITCH_MAX 2
#define SCARLETT2_PAD_SWITCH_MAX 8
#define SCARLETT2_AIR_SWITCH_MAX 8
#define SCARLETT2_PHANTOM_SWITCH_MAX 2
#define SCARLETT2_INPUT_GAIN_MAX 2
/* Maximum number of inputs to the mixer */
#define SCARLETT2_INPUT_MIX_MAX 25
/* Maximum number of outputs from the mixer */
#define SCARLETT2_OUTPUT_MIX_MAX 12
/* Maximum number of mixer gain controls */
#define SCARLETT2_MIX_MAX (SCARLETT2_INPUT_MIX_MAX * SCARLETT2_OUTPUT_MIX_MAX)
/* Maximum number of direct monitor mixer gain controls
* 1 (Solo) or 2 (2i2) direct monitor selections (Mono & Stereo)
* 2 Mix outputs (A/Left & B/Right)
* 4 Mix inputs
*/
#define SCARLETT2_MONITOR_MIX_MAX (2 * 2 * 4)
/* Maximum size of the data in the USB mux assignment message:
* 20 inputs, 20 outputs, 25 matrix inputs, 12 spare
*/
#define SCARLETT2_MUX_MAX 77
/* Maximum number of sources (sum of input port counts) */
#define SCARLETT2_MAX_SRCS 52
/* Maximum number of meters (sum of output port counts) */
#define SCARLETT2_MAX_METERS 65
/* Hardware port types:
* - None (no input to mux)
* - Analogue I/O
* - S/PDIF I/O
* - ADAT I/O
* - Mixer I/O
* - PCM I/O
*/
enum {
SCARLETT2_PORT_TYPE_NONE,
SCARLETT2_PORT_TYPE_ANALOGUE,
SCARLETT2_PORT_TYPE_SPDIF,
SCARLETT2_PORT_TYPE_ADAT,
SCARLETT2_PORT_TYPE_MIX,
SCARLETT2_PORT_TYPE_PCM,
SCARLETT2_PORT_TYPE_COUNT
};
/* I/O count of each port type kept in struct scarlett2_ports */
enum {
SCARLETT2_PORT_IN,
SCARLETT2_PORT_OUT,
SCARLETT2_PORT_DIRNS
};
/* Dim/Mute buttons on the 18i20 */
enum {
SCARLETT2_BUTTON_MUTE,
SCARLETT2_BUTTON_DIM,
SCARLETT2_DIM_MUTE_COUNT
};
/* Flash Write State */
enum {
SCARLETT2_FLASH_WRITE_STATE_IDLE,
SCARLETT2_FLASH_WRITE_STATE_SELECTED,
SCARLETT2_FLASH_WRITE_STATE_ERASING,
SCARLETT2_FLASH_WRITE_STATE_WRITE
};
static const char *const scarlett2_dim_mute_names[SCARLETT2_DIM_MUTE_COUNT] = {
"Mute Playback Switch", "Dim Playback Switch"
};
/* Autogain Status Values */
enum {
SCARLETT2_AUTOGAIN_STATUS_STOPPED,
SCARLETT2_AUTOGAIN_STATUS_RUNNING,
SCARLETT2_AUTOGAIN_STATUS_FAILED,
SCARLETT2_AUTOGAIN_STATUS_CANCELLED,
SCARLETT2_AUTOGAIN_STATUS_UNKNOWN,
SCARLETT2_AUTOGAIN_STATUS_COUNT
};
/* Power Status Values */
enum {
SCARLETT2_POWER_STATUS_EXT,
SCARLETT2_POWER_STATUS_BUS,
SCARLETT2_POWER_STATUS_FAIL,
SCARLETT2_POWER_STATUS_COUNT
};
/* Notification callback functions */
struct scarlett2_notification {
u32 mask;
void (*func)(struct usb_mixer_interface *mixer);
};
static void scarlett2_notify_sync(struct usb_mixer_interface *mixer);
static void scarlett2_notify_dim_mute(struct usb_mixer_interface *mixer);
static void scarlett2_notify_monitor(struct usb_mixer_interface *mixer);
static void scarlett2_notify_volume(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_level(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_pad(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_air(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_phantom(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_other(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_select(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_gain(struct usb_mixer_interface *mixer);
static void scarlett2_notify_autogain(struct usb_mixer_interface *mixer);
static void scarlett2_notify_input_safe(struct usb_mixer_interface *mixer);
static void scarlett2_notify_monitor_other(struct usb_mixer_interface *mixer);
static void scarlett2_notify_direct_monitor(struct usb_mixer_interface *mixer);
static void scarlett2_notify_power_status(struct usb_mixer_interface *mixer);
static void scarlett2_notify_pcm_input_switch(
struct usb_mixer_interface *mixer);
/* Arrays of notification callback functions */
static const struct scarlett2_notification scarlett2_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_dim_mute },
{ 0x00400000, scarlett2_notify_monitor },
{ 0x00800000, scarlett2_notify_input_other },
{ 0x01000000, scarlett2_notify_monitor_other },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett3a_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00800000, scarlett2_notify_input_other },
{ 0x01000000, scarlett2_notify_direct_monitor },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_solo_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00400000, scarlett2_notify_input_air },
{ 0x00800000, scarlett2_notify_direct_monitor },
{ 0x01000000, scarlett2_notify_input_level },
{ 0x02000000, scarlett2_notify_input_phantom },
{ 0x04000000, scarlett2_notify_pcm_input_switch },
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_2i2_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_input_safe },
{ 0x00400000, scarlett2_notify_autogain },
{ 0x00800000, scarlett2_notify_input_air },
{ 0x01000000, scarlett2_notify_direct_monitor },
{ 0x02000000, scarlett2_notify_input_select },
{ 0x04000000, scarlett2_notify_input_level },
{ 0x08000000, scarlett2_notify_input_phantom },
{ 0x10000000, NULL }, /* power status, ignored */
{ 0x40000000, scarlett2_notify_input_gain },
{ 0x80000000, NULL }, /* power status, ignored */
{ 0, NULL }
};
static const struct scarlett2_notification scarlett4_4i4_notifications[] = {
{ 0x00000001, NULL }, /* ack, gets ignored */
{ 0x00000008, scarlett2_notify_sync },
{ 0x00200000, scarlett2_notify_input_safe },
{ 0x00400000, scarlett2_notify_autogain },
{ 0x00800000, scarlett2_notify_input_air },
{ 0x01000000, scarlett2_notify_input_select },
{ 0x02000000, scarlett2_notify_input_level },
{ 0x04000000, scarlett2_notify_input_phantom },
{ 0x08000000, scarlett2_notify_power_status }, /* power external */
{ 0x20000000, scarlett2_notify_input_gain },
{ 0x40000000, scarlett2_notify_power_status }, /* power status */
{ 0x80000000, scarlett2_notify_volume },
{ 0, NULL }
};
/* Configuration parameters that can be read and written */
enum {
SCARLETT2_CONFIG_DIM_MUTE,
SCARLETT2_CONFIG_LINE_OUT_VOLUME,
SCARLETT2_CONFIG_MUTE_SWITCH,
SCARLETT2_CONFIG_SW_HW_SWITCH,
SCARLETT2_CONFIG_MASTER_VOLUME,
SCARLETT2_CONFIG_HEADPHONE_VOLUME,
SCARLETT2_CONFIG_LEVEL_SWITCH,
SCARLETT2_CONFIG_PAD_SWITCH,
SCARLETT2_CONFIG_MSD_SWITCH,
SCARLETT2_CONFIG_AIR_SWITCH,
SCARLETT2_CONFIG_STANDALONE_SWITCH,
SCARLETT2_CONFIG_PHANTOM_SWITCH,
SCARLETT2_CONFIG_PHANTOM_PERSISTENCE,
SCARLETT2_CONFIG_DIRECT_MONITOR,
SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH,
SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE,
SCARLETT2_CONFIG_TALKBACK_MAP,
SCARLETT2_CONFIG_AUTOGAIN_SWITCH,
SCARLETT2_CONFIG_AUTOGAIN_STATUS,
SCARLETT2_CONFIG_INPUT_GAIN,
SCARLETT2_CONFIG_SAFE_SWITCH,
SCARLETT2_CONFIG_INPUT_SELECT_SWITCH,
SCARLETT2_CONFIG_INPUT_LINK_SWITCH,
SCARLETT2_CONFIG_POWER_EXT,
SCARLETT2_CONFIG_POWER_STATUS,
SCARLETT2_CONFIG_PCM_INPUT_SWITCH,
SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN,
SCARLETT2_CONFIG_COUNT
};
/* Location, size, and activation command number for the configuration
* parameters. Size is in bits and may be 0, 1, 8, or 16.
*
* A size of 0 indicates that the parameter is a byte-sized Scarlett
* Gen 4 configuration which is written through the gen4_write_addr
* location (but still read through the given offset location).
*
* Some Gen 4 configuration parameters are written with 0x02 for a
* desired value of 0x01, and 0x03 for 0x00. These are indicated with
* mute set to 1. 0x02 and 0x03 are temporary values while the device
* makes the change and the channel and/or corresponding DSP channel
* output is muted.
*/
struct scarlett2_config {
u16 offset;
u8 size;
u8 activate;
u8 mute;
};
struct scarlett2_config_set {
const struct scarlett2_notification *notifications;
u16 gen4_write_addr;
const struct scarlett2_config items[SCARLETT2_CONFIG_COUNT];
};
/* Gen 2 devices without SW/HW volume switch: 6i6, 18i8 */
static const struct scarlett2_config_set scarlett2_config_set_gen2a = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
/* Gen 2 devices with SW/HW volume switch: 18i20 */
static const struct scarlett2_config_set scarlett2_config_set_gen2b = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
/* Gen 3 devices without a mixer (Solo and 2i2) */
static const struct scarlett2_config_set scarlett2_config_set_gen3a = {
.notifications = scarlett3a_notifications,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x04, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x05, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x06, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x07, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x08, .size = 1, .activate = 7 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x09, .size = 1, .activate = 8 },
}
};
/* Gen 3 devices without SW/HW volume switch: 4i4, 8i6 */
static const struct scarlett2_config_set scarlett2_config_set_gen3b = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x8c, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x9c, .size = 1, .activate = 8 },
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x9d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x9e, .size = 8, .activate = 6 },
}
};
/* Gen 3 devices with SW/HW volume switch: 18i8, 18i20 */
static const struct scarlett2_config_set scarlett2_config_set_gen3c = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_PAD_SWITCH] = {
.offset = 0x84, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x8c, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x9c, .size = 1, .activate = 8 },
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x9d, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_PHANTOM_PERSISTENCE] = {
.offset = 0x9e, .size = 8, .activate = 6 },
[SCARLETT2_CONFIG_MONITOR_OTHER_SWITCH] = {
.offset = 0x9f, .size = 1, .activate = 10 },
[SCARLETT2_CONFIG_MONITOR_OTHER_ENABLE] = {
.offset = 0xa0, .size = 1, .activate = 10 },
[SCARLETT2_CONFIG_TALKBACK_MAP] = {
.offset = 0xb0, .size = 16, .activate = 10 },
}
};
/* Solo Gen 4 */
static const struct scarlett2_config_set scarlett2_config_set_gen4_solo = {
.notifications = scarlett4_solo_notifications,
.gen4_write_addr = 0xd8,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x47, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x108, .activate = 12 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x46, .activate = 9, .mute = 1 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3d, .activate = 10, .mute = 1 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .activate = 11 },
[SCARLETT2_CONFIG_PCM_INPUT_SWITCH] = {
.offset = 0x206, .activate = 25 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x232, .size = 16, .activate = 26 }
}
};
/* 2i2 Gen 4 */
static const struct scarlett2_config_set scarlett2_config_set_gen4_2i2 = {
.notifications = scarlett4_2i2_notifications,
.gen4_write_addr = 0xfc,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x49, .size = 8, .activate = 4 }, // 0x41 ??
[SCARLETT2_CONFIG_DIRECT_MONITOR] = {
.offset = 0x14a, .activate = 16 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x135, .activate = 10 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x137 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x48, .activate = 11, .mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x4b, .activate = 12 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x3c, .activate = 13, .mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x147, .activate = 14 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x3e, .activate = 15 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x14b, .activate = 17 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x14e, .activate = 18 },
[SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN] = {
.offset = 0x2a0, .size = 16, .activate = 36 }
}
};
/* 4i4 Gen 4 */
static const struct scarlett2_config_set scarlett2_config_set_gen4_4i4 = {
.notifications = scarlett4_4i4_notifications,
.gen4_write_addr = 0x130,
.items = {
[SCARLETT2_CONFIG_MSD_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 4 },
[SCARLETT2_CONFIG_AUTOGAIN_SWITCH] = {
.offset = 0x13e, .activate = 10 },
[SCARLETT2_CONFIG_AUTOGAIN_STATUS] = {
.offset = 0x140 },
[SCARLETT2_CONFIG_PHANTOM_SWITCH] = {
.offset = 0x5a, .activate = 11, .mute = 1 },
[SCARLETT2_CONFIG_INPUT_GAIN] = {
.offset = 0x5e, .activate = 12 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x4e, .activate = 13, .mute = 1 },
[SCARLETT2_CONFIG_SAFE_SWITCH] = {
.offset = 0x150, .activate = 14 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x50, .activate = 15 },
[SCARLETT2_CONFIG_INPUT_SELECT_SWITCH] = {
.offset = 0x153, .activate = 16 },
[SCARLETT2_CONFIG_INPUT_LINK_SWITCH] = {
.offset = 0x156, .activate = 17 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x32, .size = 16 },
[SCARLETT2_CONFIG_HEADPHONE_VOLUME] = {
.offset = 0x3a, .size = 16 },
[SCARLETT2_CONFIG_POWER_EXT] = {
.offset = 0x168 },
[SCARLETT2_CONFIG_POWER_STATUS] = {
.offset = 0x66 }
}
};
/* Clarett USB and Clarett+ devices: 2Pre, 4Pre, 8Pre */
static const struct scarlett2_config_set scarlett2_config_set_clarett = {
.notifications = scarlett2_notifications,
.items = {
[SCARLETT2_CONFIG_DIM_MUTE] = {
.offset = 0x31, .size = 8, .activate = 2 },
[SCARLETT2_CONFIG_LINE_OUT_VOLUME] = {
.offset = 0x34, .size = 16, .activate = 1 },
[SCARLETT2_CONFIG_MUTE_SWITCH] = {
.offset = 0x5c, .size = 8, .activate = 1 },
[SCARLETT2_CONFIG_SW_HW_SWITCH] = {
.offset = 0x66, .size = 8, .activate = 3 },
[SCARLETT2_CONFIG_MASTER_VOLUME] = {
.offset = 0x76, .size = 16 },
[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
.offset = 0x7c, .size = 8, .activate = 7 },
[SCARLETT2_CONFIG_AIR_SWITCH] = {
.offset = 0x95, .size = 8, .activate = 8 },
[SCARLETT2_CONFIG_STANDALONE_SWITCH] = {
.offset = 0x8d, .size = 8, .activate = 6 },
}
};
/* Description of each hardware port type:
* - id: hardware ID of this port type
* - src_descr: printf format string for mux input selections
* - src_num_offset: added to channel number for the fprintf
* - dst_descr: printf format string for mixer controls
*/
struct scarlett2_port {
u16 id;
const char * const src_descr;
int src_num_offset;
const char * const dst_descr;
const char * const dsp_src_descr;
const char * const dsp_dst_descr;
};
static const struct scarlett2_port scarlett2_ports[SCARLETT2_PORT_TYPE_COUNT] = {
[SCARLETT2_PORT_TYPE_NONE] = {
.id = 0x000,
.src_descr = "Off"
},
[SCARLETT2_PORT_TYPE_ANALOGUE] = {
.id = 0x080,
.src_descr = "Analogue %d",
.src_num_offset = 1,
.dst_descr = "Analogue Output %02d Playback"
},
[SCARLETT2_PORT_TYPE_SPDIF] = {
.id = 0x180,
.src_descr = "S/PDIF %d",
.src_num_offset = 1,
.dst_descr = "S/PDIF Output %d Playback"
},
[SCARLETT2_PORT_TYPE_ADAT] = {
.id = 0x200,
.src_descr = "ADAT %d",
.src_num_offset = 1,
.dst_descr = "ADAT Output %d Playback"
},
[SCARLETT2_PORT_TYPE_MIX] = {
.id = 0x300,
.src_descr = "Mix %c",
.src_num_offset = 'A',
.dst_descr = "Mixer Input %02d Capture",
.dsp_src_descr = "DSP %d",
.dsp_dst_descr = "DSP Input %d Capture"
},
[SCARLETT2_PORT_TYPE_PCM] = {
.id = 0x600,
.src_descr = "PCM %d",
.src_num_offset = 1,
.dst_descr = "PCM %02d Capture"
},
};
/* Number of mux tables: one for each band of sample rates
* (44.1/48kHz, 88.2/96kHz, and 176.4/176kHz)
*/
#define SCARLETT2_MUX_TABLES 3
/* Maximum number of entries in a mux table */
#define SCARLETT2_MAX_MUX_ENTRIES 10
/* One entry within mux_assignment defines the port type and range of
* ports to add to the set_mux message. The end of the list is marked
* with count == 0.
*/
struct scarlett2_mux_entry {
u8 port_type;
u8 start;
u8 count;
};
/* Maximum number of entries in a mux table */
#define SCARLETT2_MAX_METER_ENTRIES 9
/* One entry within meter_assignment defines the range of mux outputs
* that consecutive meter entries are mapped to. The end of the list
* is marked with count == 0.
*/
struct scarlett2_meter_entry {
u8 start;
u8 count;
};
struct scarlett2_device_info {
/* which set of configuration parameters the device uses */
const struct scarlett2_config_set *config_set;
/* minimum firmware version required */
u16 min_firmware_version;
/* support for main/alt speaker switching */
u8 has_speaker_switching;
/* support for talkback microphone */
u8 has_talkback;
/* the number of analogue inputs with a software switchable
* level control that can be set to line or instrument
*/
u8 level_input_count;
/* the first input with a level control (0-based) */
u8 level_input_first;
/* the number of analogue inputs with a software switchable
* 10dB pad control
*/
u8 pad_input_count;
/* the number of analogue inputs with a software switchable
* "air" control
*/
u8 air_input_count;
/* the first input with an air control (0-based) */
u8 air_input_first;
/* number of additional air options
* 0 for air presence only (Gen 3)
* 1 for air presence+drive (Gen 4)
*/
u8 air_option;
/* the number of phantom (48V) software switchable controls */
u8 phantom_count;
/* the first input with phantom power control (0-based) */
u8 phantom_first;
/* the number of inputs each phantom switch controls */
u8 inputs_per_phantom;
/* the number of inputs with software-controllable gain */
u8 gain_input_count;
/* the number of direct monitor options
* (0 = none, 1 = mono only, 2 = mono/stereo)
*/
u8 direct_monitor;
/* the number of DSP channels */
u8 dsp_count;
/* remap analogue outputs; 18i8 Gen 3 has "line 3/4" connected
* internally to the analogue 7/8 outputs
*/
u8 line_out_remap_enable;
u8 line_out_remap[SCARLETT2_ANALOGUE_MAX];
u8 line_out_unmap[SCARLETT2_ANALOGUE_MAX];
/* additional description for the line out volume controls */
const char * const line_out_descrs[SCARLETT2_ANALOGUE_MAX];
/* number of sources/destinations of each port type */
const int port_count[SCARLETT2_PORT_TYPE_COUNT][SCARLETT2_PORT_DIRNS];
/* layout/order of the entries in the set_mux message */
struct scarlett2_mux_entry mux_assignment[SCARLETT2_MUX_TABLES]
[SCARLETT2_MAX_MUX_ENTRIES];
/* map from meter level order returned by
* SCARLETT2_USB_GET_METER to index into mux[] entries (same
* as the order returned by scarlett2_meter_ctl_get())
*/
struct scarlett2_meter_entry meter_map[SCARLETT2_MAX_METER_ENTRIES];
};
struct scarlett2_data {
struct usb_mixer_interface *mixer;
struct mutex usb_mutex; /* prevent sending concurrent USB requests */
struct mutex data_mutex; /* lock access to this data */
u8 hwdep_in_use;
u8 selected_flash_segment_id;
u8 flash_write_state;
struct delayed_work work;
const struct scarlett2_device_info *info;
const struct scarlett2_config_set *config_set;
const char *series_name;
__u8 bInterfaceNumber;
__u8 bEndpointAddress;
__u16 wMaxPacketSize;
__u8 bInterval;
u8 num_mux_srcs;
u8 num_mux_dsts;
u8 num_mix_in;
u8 num_mix_out;
u8 num_line_out;
u8 num_monitor_mix_ctls;
u32 firmware_version;
u8 flash_segment_nums[SCARLETT2_SEGMENT_ID_COUNT];
u8 flash_segment_blocks[SCARLETT2_SEGMENT_ID_COUNT];
u16 scarlett2_seq;
u8 sync_updated;
u8 vol_updated;
u8 dim_mute_updated;
u8 input_level_updated;
u8 input_pad_updated;
u8 input_air_updated;
u8 input_phantom_updated;
u8 input_select_updated;
u8 input_gain_updated;
u8 autogain_updated;
u8 input_safe_updated;
u8 pcm_input_switch_updated;
u8 monitor_other_updated;
u8 direct_monitor_updated;
u8 mux_updated;
u8 mix_updated;
u8 speaker_switching_switched;
u8 power_status_updated;
u8 sync;
u8 master_vol;
u8 headphone_vol;
u8 vol[SCARLETT2_ANALOGUE_MAX];
u8 vol_sw_hw_switch[SCARLETT2_ANALOGUE_MAX];
u8 mute_switch[SCARLETT2_ANALOGUE_MAX];
u8 level_switch[SCARLETT2_LEVEL_SWITCH_MAX];
u8 pad_switch[SCARLETT2_PAD_SWITCH_MAX];
u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
u8 air_switch[SCARLETT2_AIR_SWITCH_MAX];
u8 phantom_switch[SCARLETT2_PHANTOM_SWITCH_MAX];
u8 phantom_persistence;
u8 input_select_switch;
u8 input_link_switch[SCARLETT2_INPUT_GAIN_MAX / 2];
u8 gain[SCARLETT2_INPUT_GAIN_MAX];
u8 autogain_switch[SCARLETT2_INPUT_GAIN_MAX];
u8 autogain_status[SCARLETT2_INPUT_GAIN_MAX];
u8 safe_switch[SCARLETT2_INPUT_GAIN_MAX];
u8 pcm_input_switch;
u8 direct_monitor_switch;
u8 speaker_switching_switch;
u8 talkback_switch;
u8 talkback_map[SCARLETT2_OUTPUT_MIX_MAX];
u8 msd_switch;
u8 standalone_switch;
u8 power_status;
u8 meter_level_map[SCARLETT2_MAX_METERS];
struct snd_kcontrol *sync_ctl;
struct snd_kcontrol *master_vol_ctl;
struct snd_kcontrol *headphone_vol_ctl;
struct snd_kcontrol *vol_ctls[SCARLETT2_ANALOGUE_MAX];
struct snd_kcontrol *sw_hw_ctls[SCARLETT2_ANALOGUE_MAX];
struct snd_kcontrol *mute_ctls[SCARLETT2_ANALOGUE_MAX];
struct snd_kcontrol *dim_mute_ctls[SCARLETT2_DIM_MUTE_COUNT];
struct snd_kcontrol *level_ctls[SCARLETT2_LEVEL_SWITCH_MAX];
struct snd_kcontrol *pad_ctls[SCARLETT2_PAD_SWITCH_MAX];
struct snd_kcontrol *air_ctls[SCARLETT2_AIR_SWITCH_MAX];
struct snd_kcontrol *phantom_ctls[SCARLETT2_PHANTOM_SWITCH_MAX];
struct snd_kcontrol *input_select_ctl;
struct snd_kcontrol *input_link_ctls[SCARLETT2_INPUT_GAIN_MAX / 2];
struct snd_kcontrol *input_gain_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *autogain_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *autogain_status_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *safe_ctls[SCARLETT2_INPUT_GAIN_MAX];
struct snd_kcontrol *pcm_input_switch_ctl;
struct snd_kcontrol *mux_ctls[SCARLETT2_MUX_MAX];
struct snd_kcontrol *mix_ctls[SCARLETT2_MIX_MAX];
struct snd_kcontrol *direct_monitor_ctl;
struct snd_kcontrol *speaker_switching_ctl;
struct snd_kcontrol *talkback_ctl;
struct snd_kcontrol *power_status_ctl;
u8 mux[SCARLETT2_MUX_MAX];
u8 mix[SCARLETT2_MIX_MAX];
u8 monitor_mix[SCARLETT2_MONITOR_MIX_MAX];
};
/*** Model-specific data ***/
static const struct scarlett2_device_info s6i6_gen2_info = {
.config_set = &scarlett2_config_set_gen2a,
.level_input_count = 2,
.pad_input_count = 2,
.line_out_descrs = {
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 6, 6 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 24, 6 },
{ 0, 24 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info s18i8_gen2_info = {
.config_set = &scarlett2_config_set_gen2a,
.level_input_count = 2,
.pad_input_count = 4,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 4 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 26, 18 },
{ 0, 26 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info s18i20_gen2_info = {
.config_set = &scarlett2_config_set_gen2b,
.line_out_descrs = {
"Monitor L",
"Monitor R",
NULL,
NULL,
NULL,
NULL,
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 6 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 38, 18 },
{ 0, 38 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info solo_gen3_info = {
.config_set = &scarlett2_config_set_gen3a,
.level_input_count = 1,
.level_input_first = 1,
.air_input_count = 1,
.phantom_count = 1,
.inputs_per_phantom = 1,
.direct_monitor = 1,
};
static const struct scarlett2_device_info s2i2_gen3_info = {
.config_set = &scarlett2_config_set_gen3a,
.level_input_count = 2,
.air_input_count = 2,
.phantom_count = 1,
.inputs_per_phantom = 2,
.direct_monitor = 2,
};
static const struct scarlett2_device_info s4i4_gen3_info = {
.config_set = &scarlett2_config_set_gen3b,
.level_input_count = 2,
.pad_input_count = 2,
.air_input_count = 2,
.phantom_count = 1,
.inputs_per_phantom = 2,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones L",
"Headphones R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 4 },
[SCARLETT2_PORT_TYPE_MIX] = { 6, 8 },
[SCARLETT2_PORT_TYPE_PCM] = { 4, 6 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 16 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 16 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 16 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 12, 6 },
{ 0, 12 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info s8i6_gen3_info = {
.config_set = &scarlett2_config_set_gen3b,
.level_input_count = 2,
.pad_input_count = 2,
.air_input_count = 2,
.phantom_count = 1,
.inputs_per_phantom = 2,
.line_out_descrs = {
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 6, 4 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 8, 8 },
[SCARLETT2_PORT_TYPE_PCM] = { 6, 10 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 18 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 18 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 8 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 18 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 14, 8 },
{ 0, 6 },
{ 22, 2 },
{ 6, 8 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info s18i8_gen3_info = {
.config_set = &scarlett2_config_set_gen3c,
.has_speaker_switching = 1,
.level_input_count = 2,
.pad_input_count = 4,
.air_input_count = 4,
.phantom_count = 2,
.inputs_per_phantom = 2,
.line_out_remap_enable = 1,
.line_out_remap = { 0, 1, 6, 7, 2, 3, 4, 5 },
.line_out_unmap = { 0, 1, 4, 5, 6, 7, 2, 3 },
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Alt Monitor L",
"Alt Monitor R",
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 8 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 20 },
[SCARLETT2_PORT_TYPE_PCM] = { 8, 20 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_PCM, 12, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 20 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_PCM, 12, 4 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 20 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 6, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 2, 4 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 20 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 30, 10 },
{ 42, 8 },
{ 0, 2 },
{ 6, 2 },
{ 2, 4 },
{ 8, 2 },
{ 40, 2 },
{ 10, 20 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info s18i20_gen3_info = {
.config_set = &scarlett2_config_set_gen3c,
.has_speaker_switching = 1,
.has_talkback = 1,
.level_input_count = 2,
.pad_input_count = 8,
.air_input_count = 8,
.phantom_count = 2,
.inputs_per_phantom = 4,
.line_out_descrs = {
"Monitor 1 L",
"Monitor 1 R",
"Monitor 2 L",
"Monitor 2 R",
NULL,
NULL,
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 9, 10 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
[SCARLETT2_PORT_TYPE_MIX] = { 12, 25 },
[SCARLETT2_PORT_TYPE_PCM] = { 20, 20 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 25 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 12 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 10, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_PCM, 8, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 25 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 10 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 24 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 45, 8 },
{ 55, 10 },
{ 0, 20 },
{ 53, 2 },
{ 20, 25 },
{ 0, 0 },
}
};
static const struct scarlett2_device_info solo_gen4_info = {
.config_set = &scarlett2_config_set_gen4_solo,
.min_firmware_version = 2115,
.level_input_count = 1,
.air_input_count = 1,
.air_input_first = 1,
.air_option = 1,
.phantom_count = 1,
.phantom_first = 1,
.inputs_per_phantom = 1,
.direct_monitor = 1,
.dsp_count = 2,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 8, 6 },
[SCARLETT2_PORT_TYPE_PCM] = { 2, 4 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 6, 2 },
{ 4, 2 },
{ 8, 4 },
{ 2, 2 },
{ 0, 2 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info s2i2_gen4_info = {
.config_set = &scarlett2_config_set_gen4_2i2,
.min_firmware_version = 2115,
.level_input_count = 2,
.air_input_count = 2,
.air_option = 1,
.phantom_count = 1,
.inputs_per_phantom = 2,
.gain_input_count = 2,
.direct_monitor = 2,
.dsp_count = 2,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 2 },
[SCARLETT2_PORT_TYPE_MIX] = { 6, 6 },
[SCARLETT2_PORT_TYPE_PCM] = { 2, 4 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 4, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 2, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 2 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 6, 2 },
{ 4, 2 },
{ 8, 4 },
{ 2, 2 },
{ 0, 2 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info s4i4_gen4_info = {
.config_set = &scarlett2_config_set_gen4_4i4,
.min_firmware_version = 2089,
.level_input_count = 2,
.air_input_count = 2,
.air_option = 1,
.phantom_count = 2,
.inputs_per_phantom = 1,
.gain_input_count = 2,
.dsp_count = 2,
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 4, 6 },
[SCARLETT2_PORT_TYPE_MIX] = { 8, 12 },
[SCARLETT2_PORT_TYPE_PCM] = { 6, 6 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_MIX, 10, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 10, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_MIX, 10, 2 },
{ SCARLETT2_PORT_TYPE_PCM, 0, 6 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 10 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 16, 8 },
{ 6, 10 },
{ 0, 6 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info clarett_2pre_info = {
.config_set = &scarlett2_config_set_clarett,
.level_input_count = 2,
.air_input_count = 2,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones L",
"Headphones R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 2, 4 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 0 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 4, 12 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 12 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 8 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 2 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 4 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 26 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 22, 12 },
{ 0, 22 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info clarett_4pre_info = {
.config_set = &scarlett2_config_set_clarett,
.level_input_count = 2,
.air_input_count = 4,
.line_out_descrs = {
"Monitor L",
"Monitor R",
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 6 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 0 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 8, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 12 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 6 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 24 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 26, 18 },
{ 0, 26 },
{ 0, 0 }
}
};
static const struct scarlett2_device_info clarett_8pre_info = {
.config_set = &scarlett2_config_set_clarett,
.level_input_count = 2,
.air_input_count = 8,
.line_out_descrs = {
"Monitor L",
"Monitor R",
NULL,
NULL,
NULL,
NULL,
"Headphones 1 L",
"Headphones 1 R",
"Headphones 2 L",
"Headphones 2 R",
},
.port_count = {
[SCARLETT2_PORT_TYPE_NONE] = { 1, 0 },
[SCARLETT2_PORT_TYPE_ANALOGUE] = { 8, 10 },
[SCARLETT2_PORT_TYPE_SPDIF] = { 2, 2 },
[SCARLETT2_PORT_TYPE_ADAT] = { 8, 8 },
[SCARLETT2_PORT_TYPE_MIX] = { 10, 18 },
[SCARLETT2_PORT_TYPE_PCM] = { 20, 18 },
},
.mux_assignment = { {
{ SCARLETT2_PORT_TYPE_PCM, 0, 18 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 8 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 14 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_ADAT, 0, 4 },
{ SCARLETT2_PORT_TYPE_MIX, 0, 18 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 8 },
{ 0, 0, 0 },
}, {
{ SCARLETT2_PORT_TYPE_PCM, 0, 12 },
{ SCARLETT2_PORT_TYPE_ANALOGUE, 0, 10 },
{ SCARLETT2_PORT_TYPE_SPDIF, 0, 2 },
{ SCARLETT2_PORT_TYPE_NONE, 0, 22 },
{ 0, 0, 0 },
} },
.meter_map = {
{ 38, 18 },
{ 0, 38 },
{ 0, 0 }
}
};
struct scarlett2_device_entry {
const u32 usb_id; /* USB device identifier */
const struct scarlett2_device_info *info;
const char *series_name;
};
static const struct scarlett2_device_entry scarlett2_devices[] = {
/* Supported Gen 2 devices */
{ USB_ID(0x1235, 0x8203), &s6i6_gen2_info, "Scarlett Gen 2" },
{ USB_ID(0x1235, 0x8204), &s18i8_gen2_info, "Scarlett Gen 2" },
{ USB_ID(0x1235, 0x8201), &s18i20_gen2_info, "Scarlett Gen 2" },
/* Supported Gen 3 devices */
{ USB_ID(0x1235, 0x8211), &solo_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8210), &s2i2_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8212), &s4i4_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8213), &s8i6_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8214), &s18i8_gen3_info, "Scarlett Gen 3" },
{ USB_ID(0x1235, 0x8215), &s18i20_gen3_info, "Scarlett Gen 3" },
/* Supported Gen 4 devices */
{ USB_ID(0x1235, 0x8218), &solo_gen4_info, "Scarlett Gen 4" },
{ USB_ID(0x1235, 0x8219), &s2i2_gen4_info, "Scarlett Gen 4" },
{ USB_ID(0x1235, 0x821a), &s4i4_gen4_info, "Scarlett Gen 4" },
/* Supported Clarett USB/Clarett+ devices */
{ USB_ID(0x1235, 0x8206), &clarett_2pre_info, "Clarett USB" },
{ USB_ID(0x1235, 0x8207), &clarett_4pre_info, "Clarett USB" },
{ USB_ID(0x1235, 0x8208), &clarett_8pre_info, "Clarett USB" },
{ USB_ID(0x1235, 0x820a), &clarett_2pre_info, "Clarett+" },
{ USB_ID(0x1235, 0x820b), &clarett_4pre_info, "Clarett+" },
{ USB_ID(0x1235, 0x820c), &clarett_8pre_info, "Clarett+" },
/* End of list */
{ 0, NULL },
};
/* get the starting port index number for a given port type/direction */
static int scarlett2_get_port_start_num(
const int port_count[][SCARLETT2_PORT_DIRNS],
int direction, int port_type)
{
int i, num = 0;
for (i = 0; i < port_type; i++)
num += port_count[i][direction];
return num;
}
/*** USB Interactions ***/
/* Commands for sending/receiving requests/responses */
#define SCARLETT2_USB_CMD_INIT 0
#define SCARLETT2_USB_CMD_REQ 2
#define SCARLETT2_USB_CMD_RESP 3
#define SCARLETT2_USB_INIT_1 0x00000000
#define SCARLETT2_USB_INIT_2 0x00000002
#define SCARLETT2_USB_REBOOT 0x00000003
#define SCARLETT2_USB_GET_METER 0x00001001
#define SCARLETT2_USB_GET_MIX 0x00002001
#define SCARLETT2_USB_SET_MIX 0x00002002
#define SCARLETT2_USB_GET_MUX 0x00003001
#define SCARLETT2_USB_SET_MUX 0x00003002
#define SCARLETT2_USB_INFO_FLASH 0x00004000
#define SCARLETT2_USB_INFO_SEGMENT 0x00004001
#define SCARLETT2_USB_ERASE_SEGMENT 0x00004002
#define SCARLETT2_USB_GET_ERASE 0x00004003
#define SCARLETT2_USB_WRITE_SEGMENT 0x00004004
#define SCARLETT2_USB_GET_SYNC 0x00006004
#define SCARLETT2_USB_GET_DATA 0x00800000
#define SCARLETT2_USB_SET_DATA 0x00800001
#define SCARLETT2_USB_DATA_CMD 0x00800002
#define SCARLETT2_USB_CONFIG_SAVE 6
#define SCARLETT2_USB_METER_LEVELS_GET_MAGIC 1
#define SCARLETT2_FLASH_BLOCK_SIZE 4096
#define SCARLETT2_FLASH_WRITE_MAX 1024
#define SCARLETT2_SEGMENT_NUM_MIN 1
#define SCARLETT2_SEGMENT_NUM_MAX 4
#define SCARLETT2_SEGMENT_SETTINGS_NAME "App_Settings"
#define SCARLETT2_SEGMENT_FIRMWARE_NAME "App_Upgrade"
/* proprietary request/response format */
struct scarlett2_usb_packet {
__le32 cmd;
__le16 size;
__le16 seq;
__le32 error;
__le32 pad;
u8 data[];
};
static void scarlett2_fill_request_header(struct scarlett2_data *private,
struct scarlett2_usb_packet *req,
u32 cmd, u16 req_size)
{
/* sequence must go up by 1 for each request */
u16 seq = private->scarlett2_seq++;
req->cmd = cpu_to_le32(cmd);
req->size = cpu_to_le16(req_size);
req->seq = cpu_to_le16(seq);
req->error = 0;
req->pad = 0;
}
static int scarlett2_usb_tx(struct usb_device *dev, int interface,
void *buf, u16 size)
{
return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0),
SCARLETT2_USB_CMD_REQ,
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
0, interface, buf, size);
}
static int scarlett2_usb_rx(struct usb_device *dev, int interface,
u32 usb_req, void *buf, u16 size)
{
return snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0),
usb_req,
USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
0, interface, buf, size);
}
/* Send a proprietary format request to the Scarlett interface */
static int scarlett2_usb(
struct usb_mixer_interface *mixer, u32 cmd,
void *req_data, u16 req_size, void *resp_data, u16 resp_size)
{
struct scarlett2_data *private = mixer->private_data;
struct usb_device *dev = mixer->chip->dev;
struct scarlett2_usb_packet *req, *resp = NULL;
size_t req_buf_size = struct_size(req, data, req_size);
size_t resp_buf_size = struct_size(resp, data, resp_size);
int err;
req = kmalloc(req_buf_size, GFP_KERNEL);
if (!req) {
err = -ENOMEM;
goto error;
}
resp = kmalloc(resp_buf_size, GFP_KERNEL);
if (!resp) {
err = -ENOMEM;
goto error;
}
mutex_lock(&private->usb_mutex);
/* build request message and send it */
scarlett2_fill_request_header(private, req, cmd, req_size);
if (req_size)
memcpy(req->data, req_data, req_size);
err = scarlett2_usb_tx(dev, private->bInterfaceNumber,
req, req_buf_size);
if (err != req_buf_size) {
usb_audio_err(
mixer->chip,
"%s USB request result cmd %x was %d\n",
private->series_name, cmd, err);
err = -EINVAL;
goto unlock;
}
/* send a second message to get the response */
err = scarlett2_usb_rx(dev, private->bInterfaceNumber,
SCARLETT2_USB_CMD_RESP,
resp, resp_buf_size);
/* validate the response */
if (err != resp_buf_size) {
/* ESHUTDOWN and EPROTO are valid responses to a
* reboot request
*/
if (cmd == SCARLETT2_USB_REBOOT &&
(err == -ESHUTDOWN || err == -EPROTO)) {
err = 0;
goto unlock;
}
usb_audio_err(
mixer->chip,
"%s USB response result cmd %x was %d expected %zu\n",
private->series_name, cmd, err, resp_buf_size);
err = -EINVAL;
goto unlock;
}
/* cmd/seq/size should match except when initialising
* seq sent = 1, response = 0
*/
if (resp->cmd != req->cmd ||
(resp->seq != req->seq &&
(le16_to_cpu(req->seq) != 1 || resp->seq != 0)) ||
resp_size != le16_to_cpu(resp->size) ||
resp->error ||
resp->pad) {
usb_audio_err(
mixer->chip,
"%s USB invalid response; "
"cmd tx/rx %d/%d seq %d/%d size %d/%d "
"error %d pad %d\n",
private->series_name,
le32_to_cpu(req->cmd), le32_to_cpu(resp->cmd),
le16_to_cpu(req->seq), le16_to_cpu(resp->seq),
resp_size, le16_to_cpu(resp->size),
le32_to_cpu(resp->error),
le32_to_cpu(resp->pad));
err = -EINVAL;
goto unlock;
}
if (resp_data && resp_size > 0)
memcpy(resp_data, resp->data, resp_size);
unlock:
mutex_unlock(&private->usb_mutex);
error:
kfree(req);
kfree(resp);
return err;
}
/* Send a USB message to get data; result placed in *buf */
static int scarlett2_usb_get(
struct usb_mixer_interface *mixer,
int offset, void *buf, int size)
{
struct {
__le32 offset;
__le32 size;
} __packed req;
req.offset = cpu_to_le32(offset);
req.size = cpu_to_le32(size);
return scarlett2_usb(mixer, SCARLETT2_USB_GET_DATA,
&req, sizeof(req), buf, size);
}
/* Return true if the given configuration item is present in the
* configuration set used by this device.
*/
static int scarlett2_has_config_item(
struct scarlett2_data *private, int config_item_num)
{
return !!private->config_set->items[config_item_num].offset;
}
/* Send a USB message to get configuration parameters; result placed in *buf */
static int scarlett2_usb_get_config(
struct usb_mixer_interface *mixer,
int config_item_num, int count, void *buf)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_config *config_item =
&private->config_set->items[config_item_num];
int size, err, i;
u8 *buf_8;
u8 value;
/* Check that the configuration item is present in the
* configuration set used by this device
*/
if (!config_item->offset)
return -EFAULT;
/* Gen 4 style parameters are always 1 byte */
size = config_item->size ? config_item->size : 8;
/* For byte-sized parameters, retrieve directly into buf */
if (size >= 8) {
size = size / 8 * count;
err = scarlett2_usb_get(mixer, config_item->offset, buf, size);
if (err < 0)
return err;
if (size == 2) {
u16 *buf_16 = buf;
for (i = 0; i < count; i++, buf_16++)
*buf_16 = le16_to_cpu(*(__le16 *)buf_16);
}
return 0;
}
/* For bit-sized parameters, retrieve into value */
err = scarlett2_usb_get(mixer, config_item->offset, &value, 1);
if (err < 0)
return err;
/* then unpack from value into buf[] */
buf_8 = buf;
for (i = 0; i < 8 && i < count; i++, value >>= 1)
*buf_8++ = value & 1;
return 0;
}
/* Send a SCARLETT2_USB_SET_DATA command.
* offset: location in the device's data space
* size: size in bytes of the value (1, 2, 4)
*/
static int scarlett2_usb_set_data(
struct usb_mixer_interface *mixer,
int offset, int size, int value)
{
struct scarlett2_data *private = mixer->private_data;
struct {
__le32 offset;
__le32 size;
__le32 value;
} __packed req;
req.offset = cpu_to_le32(offset);
req.size = cpu_to_le32(size);
req.value = cpu_to_le32(value);
return scarlett2_usb(private->mixer, SCARLETT2_USB_SET_DATA,
&req, sizeof(u32) * 2 + size, NULL, 0);
}
/* Send a SCARLETT2_USB_DATA_CMD command.
* Configuration changes require activation with this after they have
* been uploaded by a previous SCARLETT2_USB_SET_DATA.
* The value for activate needed is determined by the configuration
* item.
*/
static int scarlett2_usb_activate_config(
struct usb_mixer_interface *mixer, int activate)
{
__le32 req;
req = cpu_to_le32(activate);
return scarlett2_usb(mixer, SCARLETT2_USB_DATA_CMD,
&req, sizeof(req), NULL, 0);
}
/* Send USB messages to set a SCARLETT2_CONFIG_* parameter */
static int scarlett2_usb_set_config(
struct usb_mixer_interface *mixer,
int config_item_num, int index, int value)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_config_set *config_set = private->config_set;
const struct scarlett2_config *config_item =
&config_set->items[config_item_num];
int offset, size;
int err;
/* Check that the configuration item is present in the
* configuration set used by this device
*/
if (!config_item->offset)
return -EFAULT;
/* Gen 4 style writes are selected with size = 0;
* these are only byte-sized values written through a shared
* location, different to the read address
*/
if (!config_item->size) {
if (!config_set->gen4_write_addr)
return -EFAULT;
/* Place index in gen4_write_addr + 1 */
err = scarlett2_usb_set_data(
mixer, config_set->gen4_write_addr + 1, 1, index);
if (err < 0)
return err;
/* Place value in gen4_write_addr */
err = scarlett2_usb_set_data(
mixer, config_set->gen4_write_addr, 1, value);
if (err < 0)
return err;
/* Request the interface do the write */
return scarlett2_usb_activate_config(
mixer, config_item->activate);
}
/* Not-Gen 4 style needs NVRAM save, supports
* bit-modification, and writing is done to the same place
* that the value can be read from
*/
/* Cancel any pending NVRAM save */
cancel_delayed_work_sync(&private->work);
/* Convert config_item->size in bits to size in bytes and
* calculate offset
*/
if (config_item->size >= 8) {
size = config_item->size / 8;
offset = config_item->offset + index * size;
/* If updating a bit, retrieve the old value, set/clear the
* bit as needed, and update value
*/
} else {
u8 tmp;
size = 1;
offset = config_item->offset;
err = scarlett2_usb_get(mixer, offset, &tmp, 1);
if (err < 0)
return err;
if (value)
tmp |= (1 << index);
else
tmp &= ~(1 << index);
value = tmp;
}
/* Send the configuration parameter data */
err = scarlett2_usb_set_data(mixer, offset, size, value);
if (err < 0)
return err;
/* Activate the change */
err = scarlett2_usb_activate_config(mixer, config_item->activate);
if (err < 0)
return err;
/* Gen 2 style writes to Gen 4 devices don't need saving */
if (config_set->gen4_write_addr)
return 0;
/* Schedule the change to be written to NVRAM */
if (config_item->activate != SCARLETT2_USB_CONFIG_SAVE)
schedule_delayed_work(&private->work, msecs_to_jiffies(2000));
return 0;
}
/* Send SCARLETT2_USB_DATA_CMD SCARLETT2_USB_CONFIG_SAVE */
static void scarlett2_config_save(struct usb_mixer_interface *mixer)
{
int err;
err = scarlett2_usb_activate_config(mixer, SCARLETT2_USB_CONFIG_SAVE);
if (err < 0)
usb_audio_err(mixer->chip, "config save failed: %d\n", err);
}
/* Delayed work to save config */
static void scarlett2_config_save_work(struct work_struct *work)
{
struct scarlett2_data *private =
container_of(work, struct scarlett2_data, work.work);
scarlett2_config_save(private->mixer);
}
/* Send a USB message to get sync status; result placed in *sync */
static int scarlett2_usb_get_sync_status(
struct usb_mixer_interface *mixer,
u8 *sync)
{
__le32 data;
int err;
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_SYNC,
NULL, 0, &data, sizeof(data));
if (err < 0)
return err;
*sync = !!data;
return 0;
}
/* Return true if the device has a mixer that we can control */
static int scarlett2_has_mixer(struct scarlett2_data *private)
{
return !!private->info->mux_assignment[0][0].count;
}
/* Map from mixer value to (db + 80) * 2
* (reverse of scarlett2_mixer_values[])
*/
static int scarlett2_mixer_value_to_db(int value)
{
int i;
for (i = 0; i < SCARLETT2_MIXER_VALUE_COUNT; i++)
if (scarlett2_mixer_values[i] >= value)
return i;
return SCARLETT2_MIXER_MAX_VALUE;
}
/* Send a USB message to get the volumes for all inputs of one mix
* and put the values into private->mix[]
*/
static int scarlett2_usb_get_mix(struct usb_mixer_interface *mixer,
int mix_num)
{
struct scarlett2_data *private = mixer->private_data;
int num_mixer_in = private->num_mix_in;
int err, i, j;
struct {
__le16 mix_num;
__le16 count;
} __packed req;
__le16 data[SCARLETT2_INPUT_MIX_MAX];
req.mix_num = cpu_to_le16(mix_num);
req.count = cpu_to_le16(num_mixer_in);
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MIX,
&req, sizeof(req),
data, num_mixer_in * sizeof(u16));
if (err < 0)
return err;
for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
private->mix[j] = scarlett2_mixer_value_to_db(
le16_to_cpu(data[i]));
return 0;
}
/* Send a USB message to set the volumes for all inputs of one mix
* (values obtained from private->mix[])
*/
static int scarlett2_usb_set_mix(struct usb_mixer_interface *mixer,
int mix_num)
{
struct scarlett2_data *private = mixer->private_data;
struct {
__le16 mix_num;
__le16 data[SCARLETT2_INPUT_MIX_MAX];
} __packed req;
int i, j;
int num_mixer_in = private->num_mix_in;
req.mix_num = cpu_to_le16(mix_num);
for (i = 0, j = mix_num * num_mixer_in; i < num_mixer_in; i++, j++)
req.data[i] = cpu_to_le16(
scarlett2_mixer_values[private->mix[j]]
);
return scarlett2_usb(mixer, SCARLETT2_USB_SET_MIX,
&req, (num_mixer_in + 1) * sizeof(u16),
NULL, 0);
}
/* Convert a port number index (per info->port_count) to a hardware ID */
static u32 scarlett2_mux_src_num_to_id(
const int port_count[][SCARLETT2_PORT_DIRNS], int num)
{
int port_type;
for (port_type = 0;
port_type < SCARLETT2_PORT_TYPE_COUNT;
port_type++) {
if (num < port_count[port_type][SCARLETT2_PORT_IN])
return scarlett2_ports[port_type].id | num;
num -= port_count[port_type][SCARLETT2_PORT_IN];
}
/* Oops */
return 0;
}
/* Convert a hardware ID to a port number index */
static u32 scarlett2_mux_id_to_num(
const int port_count[][SCARLETT2_PORT_DIRNS], int direction, u32 id)
{
int port_type;
int port_num = 0;
for (port_type = 0;
port_type < SCARLETT2_PORT_TYPE_COUNT;
port_type++) {
int base = scarlett2_ports[port_type].id;
int count = port_count[port_type][direction];
if (id >= base && id < base + count)
return port_num + id - base;
port_num += count;
}
/* Oops */
return -1;
}
/* Convert one mux entry from the interface and load into private->mux[] */
static void scarlett2_usb_populate_mux(struct scarlett2_data *private,
u32 mux_entry)
{
const struct scarlett2_device_info *info = private->info;
const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
int dst_idx, src_idx;
dst_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_OUT,
mux_entry & 0xFFF);
if (dst_idx < 0)
return;
if (dst_idx >= private->num_mux_dsts) {
usb_audio_err(private->mixer->chip,
"BUG: scarlett2_mux_id_to_num(%06x, OUT): %d >= %d",
mux_entry, dst_idx, private->num_mux_dsts);
return;
}
src_idx = scarlett2_mux_id_to_num(port_count, SCARLETT2_PORT_IN,
mux_entry >> 12);
if (src_idx < 0)
return;
if (src_idx >= private->num_mux_srcs) {
usb_audio_err(private->mixer->chip,
"BUG: scarlett2_mux_id_to_num(%06x, IN): %d >= %d",
mux_entry, src_idx, private->num_mux_srcs);
return;
}
private->mux[dst_idx] = src_idx;
}
/* Update the meter level map
*
* The meter level data from the interface (SCARLETT2_USB_GET_METER
* request) is returned in mux_assignment order, but to avoid exposing
* that to userspace, scarlett2_meter_ctl_get() rearranges the data
* into scarlett2_ports order using the meter_level_map[] array which
* is set up by this function.
*
* In addition, the meter level data values returned from the
* interface are invalid for destinations where:
*
* - the source is "Off"; therefore we set those values to zero (map
* value of 255)
*
* - the source is assigned to a previous (with respect to the
* mux_assignment order) destination; therefore we set those values
* to the value previously reported for that source
*/
static void scarlett2_update_meter_level_map(struct scarlett2_data *private)
{
const struct scarlett2_device_info *info = private->info;
const struct scarlett2_meter_entry *entry;
/* sources already assigned to a destination
* value is 255 for None, otherwise the value of i
* (index into array returned by
* scarlett2_usb_get_meter_levels())
*/
u8 seen_src[SCARLETT2_MAX_SRCS] = { 1 };
u8 seen_src_value[SCARLETT2_MAX_SRCS] = { 255 };
/* index in meter_map[] order */
int i = 0;
/* go through the meter_map[] entries */
for (entry = info->meter_map;
entry->count;
entry++) {
/* fill in each meter_level_map[] entry */
int j, mux_idx;
for (j = 0, mux_idx = entry->start;
j < entry->count;
i++, j++, mux_idx++) {
/* convert mux_idx using line_out_unmap[] */
int map_mux_idx = (
info->line_out_remap_enable &&
mux_idx < private->num_line_out
) ? info->line_out_unmap[mux_idx]
: mux_idx;
/* check which source is connected, and if
* that source is already connected elsewhere,
* use that existing connection's destination
* for this meter entry instead
*/
int mux_src = private->mux[mux_idx];
if (!seen_src[mux_src]) {
seen_src[mux_src] = 1;
seen_src_value[mux_src] = i;
}
private->meter_level_map[map_mux_idx] =
seen_src_value[mux_src];
}
}
}
/* Send USB message to get mux inputs and then populate private->mux[] */
static int scarlett2_usb_get_mux(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
int count = private->num_mux_dsts;
int err, i;
struct {
__le16 num;
__le16 count;
} __packed req;
__le32 data[SCARLETT2_MUX_MAX];
private->mux_updated = 0;
req.num = 0;
req.count = cpu_to_le16(count);
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_MUX,
&req, sizeof(req),
data, count * sizeof(u32));
if (err < 0)
return err;
for (i = 0; i < count; i++)
scarlett2_usb_populate_mux(private, le32_to_cpu(data[i]));
scarlett2_update_meter_level_map(private);
return 0;
}
/* Send USB messages to set mux inputs */
static int scarlett2_usb_set_mux(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
const int (*port_count)[SCARLETT2_PORT_DIRNS] = info->port_count;
int table;
struct {
__le16 pad;
__le16 num;
__le32 data[SCARLETT2_MUX_MAX];
} __packed req;
req.pad = 0;
/* set mux settings for each rate */
for (table = 0; table < SCARLETT2_MUX_TABLES; table++) {
const struct scarlett2_mux_entry *entry;
/* i counts over the output array */
int i = 0, err;
req.num = cpu_to_le16(table);
/* loop through each entry */
for (entry = info->mux_assignment[table];
entry->count;
entry++) {
int j;
int port_type = entry->port_type;
int port_idx = entry->start;
int mux_idx = scarlett2_get_port_start_num(port_count,
SCARLETT2_PORT_OUT, port_type) + port_idx;
int dst_id = scarlett2_ports[port_type].id + port_idx;
/* Empty slots */
if (!dst_id) {
for (j = 0; j < entry->count; j++)
req.data[i++] = 0;
continue;
}
/* Non-empty mux slots use the lower 12 bits
* for the destination and next 12 bits for
* the source
*/
for (j = 0; j < entry->count; j++) {
int src_id = scarlett2_mux_src_num_to_id(
port_count, private->mux[mux_idx++]);
req.data[i++] = cpu_to_le32(dst_id |
src_id << 12);
dst_id++;
}
}
err = scarlett2_usb(mixer, SCARLETT2_USB_SET_MUX,
&req, (i + 1) * sizeof(u32),
NULL, 0);
if (err < 0)
return err;
}
scarlett2_update_meter_level_map(private);
return 0;
}
/* Send USB message to get meter levels */
static int scarlett2_usb_get_meter_levels(struct usb_mixer_interface *mixer,
u16 num_meters, u16 *levels)
{
struct {
__le16 pad;
__le16 num_meters;
__le32 magic;
} __packed req;
__le32 resp[SCARLETT2_MAX_METERS];
int i, err;
req.pad = 0;
req.num_meters = cpu_to_le16(num_meters);
req.magic = cpu_to_le32(SCARLETT2_USB_METER_LEVELS_GET_MAGIC);
err = scarlett2_usb(mixer, SCARLETT2_USB_GET_METER,
&req, sizeof(req), resp, num_meters * sizeof(u32));
if (err < 0)
return err;
/* copy, convert to u16 */
for (i = 0; i < num_meters; i++)
levels[i] = le32_to_cpu(resp[i]);
return 0;
}
/* For config items with mute=1, xor bits 0 & 1 together to get the
* current/next state. This won't have any effect on values which are
* only ever 0/1.
*/
static uint8_t scarlett2_decode_muteable(uint8_t v)
{
return (v ^ (v >> 1)) & 1;
}
/*** Control Functions ***/
/* helper function to create a new control */
static int scarlett2_add_new_ctl(struct usb_mixer_interface *mixer,
const struct snd_kcontrol_new *ncontrol,
int index, int channels, const char *name,
struct snd_kcontrol **kctl_return)
{
struct snd_kcontrol *kctl;
struct usb_mixer_elem_info *elem;
int err;
elem = kzalloc(sizeof(*elem), GFP_KERNEL);
if (!elem)
return -ENOMEM;
/* We set USB_MIXER_BESPOKEN type, so that the core USB mixer code
* ignores them for resume and other operations.
* Also, the head.id field is set to 0, as we don't use this field.
*/
elem->head.mixer = mixer;
elem->control = index;
elem->head.id = 0;
elem->channels = channels;
elem->val_type = USB_MIXER_BESPOKEN;
kctl = snd_ctl_new1(ncontrol, elem);
if (!kctl) {
kfree(elem);
return -ENOMEM;
}
kctl->private_free = snd_usb_mixer_elem_free;
strscpy(kctl->id.name, name, sizeof(kctl->id.name));
err = snd_usb_mixer_add_control(&elem->head, kctl);
if (err < 0)
return err;
if (kctl_return)
*kctl_return = kctl;
return 0;
}
/*** Firmware Version Control ***/
static int scarlett2_firmware_version_ctl_get(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->firmware_version;
return 0;
}
static int scarlett2_firmware_version_ctl_info(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
return 0;
}
static const struct snd_kcontrol_new scarlett2_firmware_version_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_firmware_version_ctl_info,
.get = scarlett2_firmware_version_ctl_get
};
static int scarlett2_add_firmware_version_ctl(
struct usb_mixer_interface *mixer)
{
return scarlett2_add_new_ctl(mixer, &scarlett2_firmware_version_ctl,
0, 0, "Firmware Version", NULL);
}
/*** Minimum Firmware Version Control ***/
static int scarlett2_min_firmware_version_ctl_get(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct scarlett2_data *private = elem->head.mixer->private_data;
ucontrol->value.integer.value[0] = private->info->min_firmware_version;
return 0;
}
static int scarlett2_min_firmware_version_ctl_info(
struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
uinfo->count = 1;
return 0;
}
static const struct snd_kcontrol_new scarlett2_min_firmware_version_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_CARD,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_min_firmware_version_ctl_info,
.get = scarlett2_min_firmware_version_ctl_get
};
static int scarlett2_add_min_firmware_version_ctl(
struct usb_mixer_interface *mixer)
{
return scarlett2_add_new_ctl(mixer, &scarlett2_min_firmware_version_ctl,
0, 0, "Minimum Firmware Version", NULL);
}
/*** Sync Control ***/
/* Update sync control after receiving notification that the status
* has changed
*/
static int scarlett2_update_sync(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
private->sync_updated = 0;
return scarlett2_usb_get_sync_status(mixer, &private->sync);
}
static int scarlett2_sync_ctl_info(struct snd_kcontrol *kctl,
struct snd_ctl_elem_info *uinfo)
{
static const char *texts[2] = {
"Unlocked", "Locked"
};
return snd_ctl_enum_info(uinfo, 1, 2, texts);
}
static int scarlett2_sync_ctl_get(struct snd_kcontrol *kctl,
struct snd_ctl_elem_value *ucontrol)
{
struct usb_mixer_elem_info *elem = kctl->private_data;
struct usb_mixer_interface *mixer = elem->head.mixer;
struct scarlett2_data *private = mixer->private_data;
int err = 0;
mutex_lock(&private->data_mutex);
if (private->hwdep_in_use) {
err = -EBUSY;
goto unlock;
}
if (private->sync_updated) {
err = scarlett2_update_sync(mixer);
if (err < 0)
goto unlock;
}
ucontrol->value.enumerated.item[0] = private->sync;
unlock:
mutex_unlock(&private->data_mutex);
return err;
}
static const struct snd_kcontrol_new scarlett2_sync_ctl = {
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
.access = SNDRV_CTL_ELEM_ACCESS_READ,
.name = "",
.info = scarlett2_sync_ctl_info,
.get = scarlett2_sync_ctl_get
};
static int scarlett2_add_sync_ctl(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
/* devices without a mixer also don't support reporting sync status */
if (!scarlett2_has_mixer(private))
return 0;
return scarlett2_add_new_ctl(mixer, &scarlett2_sync_ctl,
0, 1, "Sync Status", &private->sync_ctl);
}
/*** Autogain Switch and Status Controls ***/
/* Forward declarations as phantom power and autogain can disable each other */
static int scarlett2_check_input_phantom_updated(struct usb_mixer_interface *);
static int scarlett2_phantom_is_switching(struct scarlett2_data *, int);
/* Set the access mode of a control to read-only (val = 0) or
* read-write (val = 1).
*/
static void scarlett2_set_ctl_access(struct snd_kcontrol *kctl, int val)
{
if (val)
kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
else
kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
}
/* Check if autogain is running on any input */
static int scarlett2_autogain_is_running(struct scarlett2_data *private)
{
int i;
for (i = 0; i < private->info->gain_input_count; i++)
if (private->autogain_status[i] ==
SCARLETT2_AUTOGAIN_STATUS_RUNNING)
return 1;
return 0;
}
static int scarlett2_update_autogain(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int err, i;
u8 raw_autogain_status[SCARLETT2_INPUT_GAIN_MAX];
private->autogain_updated = 0;
if (!info->gain_input_count)
return 0;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_AUTOGAIN_SWITCH,
info->gain_input_count, private->autogain_switch);
if (err < 0)
return err;
err = scarlett2_usb_get_config(
mixer, SCARLETT2_CONFIG_AUTOGAIN_STATUS,
info->gain_input_count, raw_autogain_status);
if (err < 0)
return err;
/* Translate autogain_switch and raw_autogain_status into
* autogain_status
*/
for (i = 0; i < info->gain_input_count; i++)
if (private->autogain_switch[i])
private->autogain_status[i] =
SCARLETT2_AUTOGAIN_STATUS_RUNNING;
else if (raw_autogain_status[i] == 0)
private->autogain_status[i] =
SCARLETT2_AUTOGAIN_STATUS_STOPPED;
else if (raw_autogain_status[i] >= 2 &&
raw_autogain_status[i] <= 5)
private->autogain_status[i] =
SCARLETT2_AUTOGAIN_STATUS_FAILED;
else if (raw_autogain_status[i] == 6)
private->autogain_status[i] =
SCARLETT2_AUTOGAIN_STATUS_CANCELLED;
else
private->autogain_status[i] =
SCARLETT2_AUTOGAIN_STATUS_UNKNOWN;
return 0;
}
/* Update access mode for controls affected by autogain */
static void scarlett2_autogain_update_access(struct usb_mixer_interface *mixer)
{
struct scarlett2_data *private = mixer->private_data;
const struct scarlett2_device_info *info = private->info;
int val = !scarlett2_autogain_is_running(private);
int i;
scarlett2_set_ctl_access(private->input_select_ctl, val);
for (i = 0; i < info->gain_input_count / 2; i++)
scarlett2_set_ctl_access(private->input_link_ctls[i], val);
for (i = 0; i < info->gain_input_count; i++) {
scarlett2_set_ctl_access(private->input_gain_ctls[i], val);
scarlett2_set_ctl_access(private->safe_ctls[i], val);
}
for (i = 0; i < info->level_input_count; i++)
scarlett2_set_ctl_access(private->level_ctls[i], val);
for (i = 0; i < info->air_input_count; i++)
scarlett2_set_ctl_access(private->air_ctls[i], val);
for (i = 0; i < info->phantom_count; i++)
scarlett2_set_ctl_access(private->phantom_ctls[i], val);
}
/* Notify of access mode change for all controls read-only while
* autogain runs.
*/
static void scarlett2_autogain_notify_access(struct usb_mixer_interface *mixer)