All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Geoffrey D. Bennett" <g@b4.vu>
To: alsa-devel@alsa-project.org, Takashi Iwai <tiwai@suse.de>
Cc: Hin-Tak Leung <htl10@users.sourceforge.net>,
	Vladimir Sadovnikov <sadko4u@gmail.com>
Subject: [PATCH 21/31] ALSA: usb-audio: scarlett2: Add support for Solo and 2i2 Gen 3
Date: Tue, 22 Jun 2021 03:39:58 +0930	[thread overview]
Message-ID: <67c4ef3ef9fff1f89a7de60fbeb0fceb2d0b3561.1624294591.git.g@b4.vu> (raw)
In-Reply-To: <cover.1624294591.git.g@b4.vu>

Add initial support for the Focusrite Scarlett Solo and 2i2 devices:
- They have no mixer
- They don't support reporting sync status or levels
- The configuration space is laid out differently to the other models
- There is no level (line/inst) switch on input 1 of the Solo

Co-developed-by: Vladimir Sadovnikov <sadko4u@gmail.com>
Signed-off-by: Vladimir Sadovnikov <sadko4u@gmail.com>
Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
---
 sound/usb/mixer_quirks.c        |  2 +
 sound/usb/mixer_scarlett_gen2.c | 94 ++++++++++++++++++++++++++++-----
 2 files changed, 84 insertions(+), 12 deletions(-)

diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index df7492594e91..0a3cb8fd7d00 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -3060,6 +3060,8 @@ int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
 	case USB_ID(0x1235, 0x8203): /* Focusrite Scarlett 6i6 2nd Gen */
 	case USB_ID(0x1235, 0x8204): /* Focusrite Scarlett 18i8 2nd Gen */
 	case USB_ID(0x1235, 0x8201): /* Focusrite Scarlett 18i20 2nd Gen */
+	case USB_ID(0x1235, 0x8211): /* Focusrite Scarlett Solo 3rd Gen */
+	case USB_ID(0x1235, 0x8210): /* Focusrite Scarlett 2i2 3rd Gen */
 	case USB_ID(0x1235, 0x8212): /* Focusrite Scarlett 4i4 3rd Gen */
 	case USB_ID(0x1235, 0x8213): /* Focusrite Scarlett 8i6 3rd Gen */
 	case USB_ID(0x1235, 0x8214): /* Focusrite Scarlett 18i8 3rd Gen */
diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
index 45b28585dacb..50a90693482f 100644
--- a/sound/usb/mixer_scarlett_gen2.c
+++ b/sound/usb/mixer_scarlett_gen2.c
@@ -4,9 +4,10 @@
  *
  *   Supported models:
  *   - 6i6/18i8/18i20 Gen 2
- *   - 4i4/8i6/18i8/18i20 Gen 3
+ *   - Solo/2i2/4i4/8i6/18i8/18i20 Gen 3
  *
  *   Copyright (c) 2018-2021 by Geoffrey D. Bennett <g at b4.vu>
+ *   Copyright (c) 2020-2021 by Vladimir Sadovnikov <sadko4u@gmail.com>
  *
  *   Based on the Scarlett (Gen 1) Driver for ALSA:
  *
@@ -44,6 +45,9 @@
  * 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).
+ *
  * This ALSA mixer gives access to (model-dependent):
  *  - input, output, mixer-matrix muxes
  *  - mixer-matrix gain stages
@@ -297,6 +301,11 @@ struct scarlett2_device_info {
 	 */
 	u8 has_msd_mode;
 
+	/* Gen 3 devices without a mixer have a different
+	 * configuration set
+	 */
+	u8 has_mixer;
+
 	/* line out hw volume is sw controlled */
 	u8 line_out_hw_vol;
 
@@ -305,6 +314,9 @@ struct scarlett2_device_info {
 	 */
 	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
 	 */
@@ -362,6 +374,7 @@ struct scarlett2_data {
 static const struct scarlett2_device_info s6i6_gen2_info = {
 	.usb_id = USB_ID(0x1235, 0x8203),
 
+	.has_mixer = 1,
 	.level_input_count = 2,
 	.pad_input_count = 2,
 
@@ -407,6 +420,7 @@ static const struct scarlett2_device_info s6i6_gen2_info = {
 static const struct scarlett2_device_info s18i8_gen2_info = {
 	.usb_id = USB_ID(0x1235, 0x8204),
 
+	.has_mixer = 1,
 	.level_input_count = 2,
 	.pad_input_count = 4,
 
@@ -455,6 +469,7 @@ static const struct scarlett2_device_info s18i8_gen2_info = {
 static const struct scarlett2_device_info s18i20_gen2_info = {
 	.usb_id = USB_ID(0x1235, 0x8201),
 
+	.has_mixer = 1,
 	.line_out_hw_vol = 1,
 
 	.line_out_descrs = {
@@ -505,10 +520,26 @@ static const struct scarlett2_device_info s18i20_gen2_info = {
 	} },
 };
 
+static const struct scarlett2_device_info solo_gen3_info = {
+	.usb_id = USB_ID(0x1235, 0x8211),
+
+	.has_msd_mode = 1,
+	.level_input_count = 1,
+	.level_input_first = 1,
+};
+
+static const struct scarlett2_device_info s2i2_gen3_info = {
+	.usb_id = USB_ID(0x1235, 0x8210),
+
+	.has_msd_mode = 1,
+	.level_input_count = 2,
+};
+
 static const struct scarlett2_device_info s4i4_gen3_info = {
 	.usb_id = USB_ID(0x1235, 0x8212),
 
 	.has_msd_mode = 1,
+	.has_mixer = 1,
 	.level_input_count = 2,
 	.pad_input_count = 2,
 
@@ -551,6 +582,7 @@ static const struct scarlett2_device_info s8i6_gen3_info = {
 	.usb_id = USB_ID(0x1235, 0x8213),
 
 	.has_msd_mode = 1,
+	.has_mixer = 1,
 	.level_input_count = 2,
 	.pad_input_count = 2,
 
@@ -600,6 +632,7 @@ static const struct scarlett2_device_info s18i8_gen3_info = {
 	.usb_id = USB_ID(0x1235, 0x8214),
 
 	.has_msd_mode = 1,
+	.has_mixer = 1,
 	.line_out_hw_vol = 1,
 	.level_input_count = 2,
 	.pad_input_count = 2,
@@ -662,6 +695,7 @@ static const struct scarlett2_device_info s18i20_gen3_info = {
 	.usb_id = USB_ID(0x1235, 0x8215),
 
 	.has_msd_mode = 1,
+	.has_mixer = 1,
 	.line_out_hw_vol = 1,
 	.level_input_count = 2,
 	.pad_input_count = 8,
@@ -724,6 +758,8 @@ static const struct scarlett2_device_info *scarlett2_devices[] = {
 	&s18i20_gen2_info,
 
 	/* Supported Gen 3 devices */
+	&solo_gen3_info,
+	&s2i2_gen3_info,
 	&s4i4_gen3_info,
 	&s8i6_gen3_info,
 	&s18i8_gen3_info,
@@ -776,7 +812,7 @@ static int scarlett2_get_port_start_num(
 #define SCARLETT2_USB_VOLUME_STATUS_OFFSET 0x31
 #define SCARLETT2_USB_METER_LEVELS_GET_MAGIC 1
 
-/* volume status is read together (matches scarlett2_config_items[]) */
+/* volume status is read together (matches scarlett2_config_items[1]) */
 struct scarlett2_usb_volume_status {
 	/* dim/mute buttons */
 	u8 dim_mute[SCARLETT2_DIM_MUTE_COUNT];
@@ -822,8 +858,22 @@ struct scarlett2_config {
 	u8 activate;
 };
 
+/* scarlett2_config_items[0] is for devices without a mixer
+ * scarlett2_config_items[1] is for devices with a mixer
+ */
 static const struct scarlett2_config
-		scarlett2_config_items[SCARLETT2_CONFIG_COUNT] = {
+	scarlett2_config_items[2][SCARLETT2_CONFIG_COUNT] =
+
+/* Devices without a mixer (Solo and 2i2 Gen 3) */
+{ {
+	[SCARLETT2_CONFIG_MSD_SWITCH] = {
+		.offset = 0x04, .size = 8, .activate = 6 },
+
+	[SCARLETT2_CONFIG_LEVEL_SWITCH] = {
+		.offset = 0x08, .size = 1, .activate = 7 },
+
+/* Devices with a mixer (Gen 2 and all other Gen 3) */
+}, {
 	[SCARLETT2_CONFIG_DIM_MUTE] = {
 		.offset = 0x31, .size = 8, .activate = 2 },
 
@@ -844,7 +894,7 @@ static const struct scarlett2_config
 
 	[SCARLETT2_CONFIG_MSD_SWITCH] = {
 		.offset = 0x9d, .size = 8, .activate = 6 },
-};
+} };
 
 /* proprietary request/response format */
 struct scarlett2_usb_packet {
@@ -1006,8 +1056,10 @@ 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_device_info *info = private->info;
 	const struct scarlett2_config *config_item =
-		&scarlett2_config_items[config_item_num];
+		&scarlett2_config_items[info->has_mixer][config_item_num];
 	int size, err, i;
 	u8 value;
 
@@ -1055,8 +1107,10 @@ 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_device_info *info = private->info;
 	const struct scarlett2_config *config_item =
-	       &scarlett2_config_items[config_item_num];
+	       &scarlett2_config_items[info->has_mixer][config_item_num];
 	struct {
 		__le32 offset;
 		__le32 bytes;
@@ -1065,7 +1119,6 @@ static int scarlett2_usb_set_config(
 	__le32 req2;
 	int offset, size;
 	int err;
-	struct scarlett2_data *private = mixer->private_data;
 
 	/* Cancel any pending NVRAM save */
 	cancel_delayed_work_sync(&private->work);
@@ -1506,6 +1559,10 @@ 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 (!private->info->has_mixer)
+		return 0;
+
 	return scarlett2_add_new_ctl(mixer, &scarlett2_sync_ctl,
 				     0, 1, "Sync Status", &private->sync_ctl);
 }
@@ -1824,7 +1881,8 @@ static int scarlett2_update_input_other(struct usb_mixer_interface *mixer)
 	if (info->level_input_count) {
 		int err = scarlett2_usb_get_config(
 			mixer, SCARLETT2_CONFIG_LEVEL_SWITCH,
-			info->level_input_count, private->level_switch);
+			info->level_input_count + info->level_input_first,
+			private->level_switch);
 		if (err < 0)
 			return err;
 	}
@@ -1856,12 +1914,14 @@ static int scarlett2_level_enum_ctl_get(struct snd_kcontrol *kctl,
 	struct usb_mixer_elem_info *elem = kctl->private_data;
 	struct usb_mixer_interface *mixer = elem->head.mixer;
 	struct scarlett2_data *private = mixer->private_data;
+	const struct scarlett2_device_info *info = private->info;
+
+	int index = elem->control + info->level_input_first;
 
 	mutex_lock(&private->data_mutex);
 	if (private->input_other_updated)
 		scarlett2_update_input_other(mixer);
-	ucontrol->value.enumerated.item[0] =
-		private->level_switch[elem->control];
+	ucontrol->value.enumerated.item[0] = private->level_switch[index];
 	mutex_unlock(&private->data_mutex);
 
 	return 0;
@@ -1873,8 +1933,9 @@ static int scarlett2_level_enum_ctl_put(struct snd_kcontrol *kctl,
 	struct usb_mixer_elem_info *elem = kctl->private_data;
 	struct usb_mixer_interface *mixer = elem->head.mixer;
 	struct scarlett2_data *private = mixer->private_data;
+	const struct scarlett2_device_info *info = private->info;
 
-	int index = elem->control;
+	int index = elem->control + info->level_input_first;
 	int oval, val, err = 0;
 
 	mutex_lock(&private->data_mutex);
@@ -2130,7 +2191,8 @@ static int scarlett2_add_line_in_ctls(struct usb_mixer_interface *mixer)
 
 	/* Add input level (line/inst) controls */
 	for (i = 0; i < info->level_input_count; i++) {
-		snprintf(s, sizeof(s), fmt, i + 1, "Level", "Enum");
+		snprintf(s, sizeof(s), fmt, i + 1 + info->level_input_first,
+			 "Level", "Enum");
 		err = scarlett2_add_new_ctl(mixer, &scarlett2_level_enum_ctl,
 					    i, 1, s, &private->level_ctls[i]);
 		if (err < 0)
@@ -2411,6 +2473,10 @@ static int scarlett2_add_meter_ctl(struct usb_mixer_interface *mixer)
 {
 	struct scarlett2_data *private = mixer->private_data;
 
+	/* devices without a mixer also don't support reporting levels */
+	if (!private->info->has_mixer)
+		return 0;
+
 	return scarlett2_add_new_ctl(mixer, &scarlett2_meter_ctl,
 				     0, private->num_mux_dsts,
 				     "Level Meter", NULL);
@@ -2634,6 +2700,10 @@ static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
 	if (err < 0)
 		return err;
 
+	/* the rest of the configuration is for devices with a mixer */
+	if (!info->has_mixer)
+		return 0;
+
 	err = scarlett2_update_sync(mixer);
 	if (err < 0)
 		return err;
-- 
2.31.1


  parent reply	other threads:[~2021-06-21 18:20 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 18:09 [PATCH 00/31] Refactor Scarlett Gen 2 support and add Scarlett Gen 3 support Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 01/31] ALSA: usb-audio: scarlett2: Add usb_tx/rx functions Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 02/31] ALSA: usb-audio: scarlett2: Update initialisation sequence Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 03/31] ALSA: usb-audio: scarlett2: Fix 6i6 Gen 2 line out descriptions Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 04/31] ALSA: usb-audio: scarlett2: Always enable interrupt polling Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 05/31] ALSA: usb-audio: scarlett2: Add "Sync Status" control Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 06/31] ALSA: usb-audio: scarlett2: Merge common line in capture strings Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 07/31] ALSA: usb-audio: scarlett2: Reformat scarlett2_config_items[] Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 08/31] ALSA: usb-audio: scarlett2: Improve device info lookup Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 09/31] ALSA: usb-audio: scarlett2: Move info lookup out of init function Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 10/31] ALSA: usb-audio: scarlett2: Remove repeated device info comments Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 11/31] ALSA: usb-audio: scarlett2: Add scarlett2_vol_ctl_write() helper Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 12/31] ALSA: usb-audio: scarlett2: Add mute support Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 13/31] ALSA: usb-audio: scarlett2: Allow arbitrary ordering of mux entries Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 14/31] ALSA: usb-audio: scarlett2: Split struct scarlett2_ports Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 15/31] ALSA: usb-audio: scarlett2: Fix Level Meter control Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 16/31] ALSA: usb-audio: scarlett2: Add Gen 3 mixer support Geoffrey D. Bennett
2021-06-22  7:00   ` Takashi Iwai
2021-06-22  7:07     ` Vladimir Sadovnikov
2021-06-22  7:25       ` [PATCH v2 " Geoffrey D. Bennett
2021-06-22  7:34       ` [PATCH " Takashi Iwai
2021-06-22  7:44         ` Geoffrey D. Bennett
2021-06-22  7:58           ` Takashi Iwai
2021-06-22  8:12             ` Takashi Iwai
2021-06-22  8:18             ` Geoffrey D. Bennett
2021-06-22  8:34               ` Takashi Iwai
2021-06-22  9:01                 ` Takashi Iwai
2021-06-22  7:24     ` Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 17/31] ALSA: usb-audio: scarlett2: Add support for "input-other" notify Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 18/31] ALSA: usb-audio: scarlett2: Add Gen 3 MSD mode switch Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 19/31] ALSA: usb-audio: scarlett2: Move get config above set config Geoffrey D. Bennett
2021-06-21 18:09 ` [PATCH 20/31] ALSA: usb-audio: scarlett2: Allow bit-level access to config Geoffrey D. Bennett
2021-06-21 18:09 ` Geoffrey D. Bennett [this message]
2021-06-21 18:10 ` [PATCH 22/31] ALSA: usb-audio: scarlett2: Add "air" switch support Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 23/31] ALSA: usb-audio: scarlett2: Add phantom power " Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 24/31] ALSA: usb-audio: scarlett2: Add direct monitor support Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 25/31] ALSA: usb-audio: scarlett2: Label 18i8 Gen 3 line outputs correctly Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 26/31] ALSA: usb-audio: scarlett2: Split up sw_hw_enum_ctl_put() Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 27/31] ALSA: usb-audio: scarlett2: Add sw_hw_ctls and mux_ctls Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 28/31] ALSA: usb-audio: scarlett2: Update mux controls to allow updates Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 29/31] ALSA: usb-audio: scarlett2: Add speaker switching support Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 30/31] ALSA: usb-audio: scarlett2: Update get_config to do endian conversion Geoffrey D. Bennett
2021-06-21 18:10 ` [PATCH 31/31] ALSA: usb-audio: scarlett2: Add support for the talkback feature Geoffrey D. Bennett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67c4ef3ef9fff1f89a7de60fbeb0fceb2d0b3561.1624294591.git.g@b4.vu \
    --to=g@b4.vu \
    --cc=alsa-devel@alsa-project.org \
    --cc=htl10@users.sourceforge.net \
    --cc=sadko4u@gmail.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.