diff mbox series

[18/23] ALSA: scarlett2: Allow for interfaces without per-channel volume

Message ID 30f68cb311e27f2cc1351cb846218f7248a90263.1703444932.git.g@b4.vu (mailing list archive)
State Accepted
Commit 90d8fef837a53e6b5c2c3c14c6063ee8d78277a9
Headers show
Series ALSA: scarlett2: Refactor in preparation for gen4 | expand

Commit Message

Geoffrey D. Bennett Dec. 24, 2023, 7:30 p.m. UTC
Currently-supported interfaces with a mixer have per-channel volume
controls, but this changes in Gen 4. Add a check so that the Playback
Volume and associated controls don't get created unless the
SCARLETT2_CONFIG_LINE_OUT_VOLUME config item is present.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
---
 sound/usb/mixer_scarlett2.c | 68 ++++++++++++++++++++++---------------
 1 file changed, 40 insertions(+), 28 deletions(-)
diff mbox series

Patch

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index e8a93fd339f7..24d7cc85cf04 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -3726,6 +3726,13 @@  static int scarlett2_add_line_out_ctls(struct usb_mixer_interface *mixer)
 			return err;
 	}
 
+	/* Remaining controls are only applicable if the device
+	 * has per-channel line-out volume controls.
+	 */
+	if (!scarlett2_has_config_item(private,
+				       SCARLETT2_CONFIG_LINE_OUT_VOLUME))
+		return 0;
+
 	/* Add volume controls */
 	for (i = 0; i < private->num_line_out; i++) {
 		int index = line_out_remap(private, i);
@@ -4569,7 +4576,6 @@  static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
 {
 	struct scarlett2_data *private = mixer->private_data;
 	int err, i;
-	s16 sw_vol[SCARLETT2_ANALOGUE_MAX];
 
 	if (scarlett2_has_config_item(private, SCARLETT2_CONFIG_MSD_SWITCH)) {
 		err = scarlett2_usb_get_config(
@@ -4608,41 +4614,47 @@  static int scarlett2_read_configs(struct usb_mixer_interface *mixer)
 	if (err < 0)
 		return err;
 
-	/* read SW line out volume */
-	err = scarlett2_usb_get_config(
-		mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
-		private->num_line_out, &sw_vol);
-	if (err < 0)
-		return err;
-
-	for (i = 0; i < private->num_line_out; i++)
-		private->vol[i] = clamp(
-			sw_vol[i] + SCARLETT2_VOLUME_BIAS,
-			0, SCARLETT2_VOLUME_BIAS);
+	if (scarlett2_has_config_item(private,
+				      SCARLETT2_CONFIG_LINE_OUT_VOLUME)) {
+		s16 sw_vol[SCARLETT2_ANALOGUE_MAX];
 
-	/* read SW mute */
-	err = scarlett2_usb_get_config(
-		mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
-		private->num_line_out, &private->mute_switch);
-	if (err < 0)
-		return err;
+		/* read SW line out volume */
+		err = scarlett2_usb_get_config(
+			mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
+			private->num_line_out, &sw_vol);
+		if (err < 0)
+			return err;
 
-	for (i = 0; i < private->num_line_out; i++)
-		private->mute_switch[i] =
-			!!private->mute_switch[i];
+		for (i = 0; i < private->num_line_out; i++)
+			private->vol[i] = clamp(
+				sw_vol[i] + SCARLETT2_VOLUME_BIAS,
+				0, SCARLETT2_VOLUME_BIAS);
 
-	/* read SW/HW switches */
-	if (scarlett2_has_config_item(private,
-				      SCARLETT2_CONFIG_SW_HW_SWITCH)) {
+		/* read SW mute */
 		err = scarlett2_usb_get_config(
-			mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
-			private->num_line_out, &private->vol_sw_hw_switch);
+			mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
+			private->num_line_out, &private->mute_switch);
 		if (err < 0)
 			return err;
 
 		for (i = 0; i < private->num_line_out; i++)
-			private->vol_sw_hw_switch[i] =
-				!!private->vol_sw_hw_switch[i];
+			private->mute_switch[i] =
+				!!private->mute_switch[i];
+
+		/* read SW/HW switches */
+		if (scarlett2_has_config_item(private,
+					      SCARLETT2_CONFIG_SW_HW_SWITCH)) {
+			err = scarlett2_usb_get_config(
+				mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
+				private->num_line_out,
+				&private->vol_sw_hw_switch);
+			if (err < 0)
+				return err;
+
+			for (i = 0; i < private->num_line_out; i++)
+				private->vol_sw_hw_switch[i] =
+					!!private->vol_sw_hw_switch[i];
+		}
 	}
 
 	err = scarlett2_update_volumes(mixer);