Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8
@ 2024-03-10 10:34 Geoffrey D. Bennett
  2024-03-10 10:34 ` [PATCH 1/3] ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection Geoffrey D. Bennett
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Geoffrey D. Bennett @ 2024-03-10 10:34 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Takashi Iwai, linux-sound

Hi Takashi,

I have three minor fixes for the Scarlett 4th Gen driver in 6.8:
- The low-voltage indication is now being read from the correct offset
- The autogain status values are now all correctly interpreted
- The input gain range is now correct

Regards,
Geoffrey.

Geoffrey D. Bennett (3):
  ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection
  ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
  ALSA: scarlett2: Fix Scarlett 4th Gen input gain range

 sound/usb/mixer_scarlett2.c | 85 ++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 39 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection
  2024-03-10 10:34 [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Geoffrey D. Bennett
@ 2024-03-10 10:34 ` Geoffrey D. Bennett
  2024-03-10 10:34 ` [PATCH 2/3] ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values Geoffrey D. Bennett
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Geoffrey D. Bennett @ 2024-03-10 10:34 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Takashi Iwai, linux-sound

The value currently being read to determine the low-voltage state is
actually the front panel state. Fix the code to use the correct offset
for the low-voltage state.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: d7cfa2fdfc8a ("ALSA: scarlett2: Add power status control")
---
 sound/usb/mixer_scarlett2.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index 6de605a601e5..bce69a78c505 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -415,7 +415,7 @@ enum {
 	SCARLETT2_CONFIG_INPUT_SELECT_SWITCH,
 	SCARLETT2_CONFIG_INPUT_LINK_SWITCH,
 	SCARLETT2_CONFIG_POWER_EXT,
-	SCARLETT2_CONFIG_POWER_STATUS,
+	SCARLETT2_CONFIG_POWER_LOW,
 	SCARLETT2_CONFIG_PCM_INPUT_SWITCH,
 	SCARLETT2_CONFIG_DIRECT_MONITOR_GAIN,
 	SCARLETT2_CONFIG_COUNT
@@ -723,8 +723,8 @@ static const struct scarlett2_config_set scarlett2_config_set_gen4_4i4 = {
 		[SCARLETT2_CONFIG_POWER_EXT] = {
 			.offset = 0x168 },
 
-		[SCARLETT2_CONFIG_POWER_STATUS] = {
-			.offset = 0x66 }
+		[SCARLETT2_CONFIG_POWER_LOW] = {
+			.offset = 0x16d }
 	}
 };
 
@@ -6294,8 +6294,7 @@ static int scarlett2_update_power_status(struct usb_mixer_interface *mixer)
 {
 	struct scarlett2_data *private = mixer->private_data;
 	int err;
-	u8 power_ext;
-	u8 power_status;
+	u8 power_ext, power_low;
 
 	private->power_status_updated = 0;
 
@@ -6304,12 +6303,12 @@ static int scarlett2_update_power_status(struct usb_mixer_interface *mixer)
 	if (err < 0)
 		return err;
 
-	err = scarlett2_usb_get_config(mixer, SCARLETT2_CONFIG_POWER_STATUS,
-				       1, &power_status);
+	err = scarlett2_usb_get_config(mixer, SCARLETT2_CONFIG_POWER_LOW,
+				       1, &power_low);
 	if (err < 0)
 		return err;
 
-	if (power_status > 1)
+	if (power_low)
 		private->power_status = SCARLETT2_POWER_STATUS_FAIL;
 	else if (power_ext)
 		private->power_status = SCARLETT2_POWER_STATUS_EXT;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
  2024-03-10 10:34 [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Geoffrey D. Bennett
  2024-03-10 10:34 ` [PATCH 1/3] ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection Geoffrey D. Bennett
@ 2024-03-10 10:34 ` Geoffrey D. Bennett
  2024-03-10 10:34 ` [PATCH 3/3] ALSA: scarlett2: Fix Scarlett 4th Gen input gain range Geoffrey D. Bennett
  2024-03-11  8:16 ` [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Takashi Iwai
  3 siblings, 0 replies; 8+ messages in thread
From: Geoffrey D. Bennett @ 2024-03-10 10:34 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Takashi Iwai, linux-sound

The meanings of the raw_auto_gain_status values were originally
guessed through experimentation, but the official names have now been
discovered. Update the autogain status control strings accordingly.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: 0a995e38dc44 ("ALSA: scarlett2: Add support for software-controllable input gain")
---
 sound/usb/mixer_scarlett2.c | 62 ++++++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 28 deletions(-)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index bce69a78c505..3815ce1d216e 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -284,14 +284,22 @@ 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
+/* The autogain_status is set based on the autogain_switch and
+ * raw_autogain_status values.
+ *
+ * If autogain_switch is set, autogain_status is set to 0 (Running).
+ * The other status values are from the raw_autogain_status value + 1.
+ */
+static const char *const scarlett2_autogain_status_texts[] = {
+	"Running",
+	"Success",
+	"SuccessDRover",
+	"WarnMinGainLimit",
+	"FailDRunder",
+	"FailMaxGainLimit",
+	"FailClipped",
+	"Cancelled",
+	"Invalid"
 };
 
 /* Power Status Values */
@@ -2835,9 +2843,9 @@ static int scarlett2_autogain_is_running(struct scarlett2_data *private)
 {
 	int i;
 
+	/* autogain_status[] is 0 if autogain is running */
 	for (i = 0; i < private->info->gain_input_count; i++)
-		if (private->autogain_status[i] ==
-		    SCARLETT2_AUTOGAIN_STATUS_RUNNING)
+		if (!private->autogain_status[i])
 			return 1;
 
 	return 0;
@@ -2867,25 +2875,25 @@ static int scarlett2_update_autogain(struct usb_mixer_interface *mixer)
 		return err;
 
 	/* Translate autogain_switch and raw_autogain_status into
-	 * autogain_status
+	 * autogain_status.
+	 *
+	 * When autogain_switch[] is set, the status is the first
+	 * element in scarlett2_autogain_status_texts[] (Running). The
+	 * subsequent elements correspond to the status value from the
+	 * device (raw_autogain_status[]) + 1. The last element is
+	 * "Invalid", in case the device reports a status outside the
+	 * range of scarlett2_autogain_status_texts[].
 	 */
 	for (i = 0; i < info->gain_input_count; i++)
 		if (private->autogain_switch[i])
+			private->autogain_status[i] = 0;
+		else if (raw_autogain_status[i] <
+				ARRAY_SIZE(scarlett2_autogain_status_texts) - 1)
 			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;
+				raw_autogain_status[i] + 1;
 		else
 			private->autogain_status[i] =
-				SCARLETT2_AUTOGAIN_STATUS_UNKNOWN;
+				ARRAY_SIZE(scarlett2_autogain_status_texts) - 1;
 
 	return 0;
 }
@@ -3111,12 +3119,10 @@ static int scarlett2_autogain_switch_ctl_put(
 static int scarlett2_autogain_status_ctl_info(
 	struct snd_kcontrol *kctl, struct snd_ctl_elem_info *uinfo)
 {
-	static const char *const values[SCARLETT2_AUTOGAIN_STATUS_COUNT] = {
-		"Stopped", "Running", "Failed", "Cancelled", "Unknown"
-	};
-
 	return snd_ctl_enum_info(
-		uinfo, 1, SCARLETT2_AUTOGAIN_STATUS_COUNT, values);
+		uinfo, 1,
+		ARRAY_SIZE(scarlett2_autogain_status_texts),
+		scarlett2_autogain_status_texts);
 }
 
 static const struct snd_kcontrol_new scarlett2_autogain_switch_ctl = {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] ALSA: scarlett2: Fix Scarlett 4th Gen input gain range
  2024-03-10 10:34 [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Geoffrey D. Bennett
  2024-03-10 10:34 ` [PATCH 1/3] ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection Geoffrey D. Bennett
  2024-03-10 10:34 ` [PATCH 2/3] ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values Geoffrey D. Bennett
@ 2024-03-10 10:34 ` Geoffrey D. Bennett
  2024-03-11  8:16 ` [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Takashi Iwai
  3 siblings, 0 replies; 8+ messages in thread
From: Geoffrey D. Bennett @ 2024-03-10 10:34 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Takashi Iwai, linux-sound

The input gain range TLV was declared as -70dB to 0dB, but the preamp
gain range is actually 0dB to +70dB. Rename SCARLETT2_GAIN_BIAS to
SCARLETT2_MAX_GAIN and update the TLV to fix.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: 0a995e38dc44 ("ALSA: scarlett2: Add support for software-controllable input gain")
---
 sound/usb/mixer_scarlett2.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index 3815ce1d216e..ffb8bcebf9ad 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -173,7 +173,9 @@
 
 /* some gui mixers can't handle negative ctl values */
 #define SCARLETT2_VOLUME_BIAS 127
-#define SCARLETT2_GAIN_BIAS 70
+
+/* maximum preamp input gain */
+#define SCARLETT2_MAX_GAIN 70
 
 /* mixer range from -80dB to +6dB in 0.5dB steps */
 #define SCARLETT2_MIXER_MIN_DB -80
@@ -3464,7 +3466,7 @@ static int scarlett2_input_gain_ctl_info(struct snd_kcontrol *kctl,
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 	uinfo->count = elem->channels;
 	uinfo->value.integer.min = 0;
-	uinfo->value.integer.max = SCARLETT2_GAIN_BIAS;
+	uinfo->value.integer.max = SCARLETT2_MAX_GAIN;
 	uinfo->value.integer.step = 1;
 
 unlock:
@@ -3541,7 +3543,7 @@ static int scarlett2_input_gain_ctl_put(struct snd_kcontrol *kctl,
 }
 
 static const DECLARE_TLV_DB_MINMAX(
-	db_scale_scarlett2_gain, -SCARLETT2_GAIN_BIAS * 100, 0
+	db_scale_scarlett2_gain, 0, SCARLETT2_MAX_GAIN * 100
 );
 
 static const struct snd_kcontrol_new scarlett2_input_gain_ctl = {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8
  2024-03-10 10:34 [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Geoffrey D. Bennett
                   ` (2 preceding siblings ...)
  2024-03-10 10:34 ` [PATCH 3/3] ALSA: scarlett2: Fix Scarlett 4th Gen input gain range Geoffrey D. Bennett
@ 2024-03-11  8:16 ` Takashi Iwai
  2024-03-11  8:42   ` Geoffrey D. Bennett
  3 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2024-03-11  8:16 UTC (permalink / raw)
  To: Geoffrey D. Bennett; +Cc: Takashi Iwai, Takashi Iwai, linux-sound

On Sun, 10 Mar 2024 11:34:09 +0100,
Geoffrey D. Bennett wrote:
> 
> Hi Takashi,
> 
> I have three minor fixes for the Scarlett 4th Gen driver in 6.8:
> - The low-voltage indication is now being read from the correct offset
> - The autogain status values are now all correctly interpreted
> - The input gain range is now correct
> 
> Regards,
> Geoffrey.
> 
> Geoffrey D. Bennett (3):
>   ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection
>   ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
>   ALSA: scarlett2: Fix Scarlett 4th Gen input gain range

Applied all patches now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8
  2024-03-11  8:16 ` [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Takashi Iwai
@ 2024-03-11  8:42   ` Geoffrey D. Bennett
  2024-03-11  8:44     ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Geoffrey D. Bennett @ 2024-03-11  8:42 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Takashi Iwai, linux-sound

On Mon, Mar 11, 2024 at 09:16:04AM +0100, Takashi Iwai wrote:
> On Sun, 10 Mar 2024 11:34:09 +0100,
> Geoffrey D. Bennett wrote:
> > 
> > Hi Takashi,
> > 
> > I have three minor fixes for the Scarlett 4th Gen driver in 6.8:
> > - The low-voltage indication is now being read from the correct offset
> > - The autogain status values are now all correctly interpreted
> > - The input gain range is now correct
> > 
> > Regards,
> > Geoffrey.
> > 
> > Geoffrey D. Bennett (3):
> >   ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection
> >   ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
> >   ALSA: scarlett2: Fix Scarlett 4th Gen input gain range
> 
> Applied all patches now.  Thanks.

Hi Takashi,

Sorry for the inconvience, I have a v2 of the 3rd patch "Fix Scarlett
4th Gen input gain range" which I will send in a moment. Please let me
know if you prefer a patch on top of the above rather than a
replacement patch.

Thanks,
Geoffrey.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8
  2024-03-11  8:42   ` Geoffrey D. Bennett
@ 2024-03-11  8:44     ` Takashi Iwai
  2024-03-11  9:27       ` Geoffrey D. Bennett
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2024-03-11  8:44 UTC (permalink / raw)
  To: Geoffrey D. Bennett; +Cc: Takashi Iwai, Takashi Iwai, linux-sound

On Mon, 11 Mar 2024 09:42:34 +0100,
Geoffrey D. Bennett wrote:
> 
> On Mon, Mar 11, 2024 at 09:16:04AM +0100, Takashi Iwai wrote:
> > On Sun, 10 Mar 2024 11:34:09 +0100,
> > Geoffrey D. Bennett wrote:
> > > 
> > > Hi Takashi,
> > > 
> > > I have three minor fixes for the Scarlett 4th Gen driver in 6.8:
> > > - The low-voltage indication is now being read from the correct offset
> > > - The autogain status values are now all correctly interpreted
> > > - The input gain range is now correct
> > > 
> > > Regards,
> > > Geoffrey.
> > > 
> > > Geoffrey D. Bennett (3):
> > >   ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection
> > >   ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
> > >   ALSA: scarlett2: Fix Scarlett 4th Gen input gain range
> > 
> > Applied all patches now.  Thanks.
> 
> Hi Takashi,
> 
> Sorry for the inconvience, I have a v2 of the 3rd patch "Fix Scarlett
> 4th Gen input gain range" which I will send in a moment. Please let me
> know if you prefer a patch on top of the above rather than a
> replacement patch.

Yes, please send an incremental fix.
You can get the commits in for-linus branch of sound.git tree.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8
  2024-03-11  8:44     ` Takashi Iwai
@ 2024-03-11  9:27       ` Geoffrey D. Bennett
  0 siblings, 0 replies; 8+ messages in thread
From: Geoffrey D. Bennett @ 2024-03-11  9:27 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Takashi Iwai, linux-sound

On Mon, Mar 11, 2024 at 09:44:51AM +0100, Takashi Iwai wrote:
> On Mon, 11 Mar 2024 09:42:34 +0100,
> Geoffrey D. Bennett wrote:
> > 
> > On Mon, Mar 11, 2024 at 09:16:04AM +0100, Takashi Iwai wrote:
> > > On Sun, 10 Mar 2024 11:34:09 +0100,
> > > Geoffrey D. Bennett wrote:
> > > > 
> > > > Hi Takashi,
> > > > 
> > > > I have three minor fixes for the Scarlett 4th Gen driver in 6.8:
> > > > - The low-voltage indication is now being read from the correct offset
> > > > - The autogain status values are now all correctly interpreted
> > > > - The input gain range is now correct
> > > > 
> > > > Regards,
> > > > Geoffrey.
> > > > 
> > > > Geoffrey D. Bennett (3):
> > > >   ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection
> > > >   ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values
> > > >   ALSA: scarlett2: Fix Scarlett 4th Gen input gain range
> > > 
> > > Applied all patches now.  Thanks.
> > 
> > Hi Takashi,
> > 
> > Sorry for the inconvience, I have a v2 of the 3rd patch "Fix Scarlett
> > 4th Gen input gain range" which I will send in a moment. Please let me
> > know if you prefer a patch on top of the above rather than a
> > replacement patch.
> 
> Yes, please send an incremental fix.
> You can get the commits in for-linus branch of sound.git tree.

Thanks for your patience. I have submitted an incremental fix,
hopefully correct this time!

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-03-11  9:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-10 10:34 [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Geoffrey D. Bennett
2024-03-10 10:34 ` [PATCH 1/3] ALSA: scarlett2: Fix Scarlett 4th Gen 4i4 low-voltage detection Geoffrey D. Bennett
2024-03-10 10:34 ` [PATCH 2/3] ALSA: scarlett2: Fix Scarlett 4th Gen autogain status values Geoffrey D. Bennett
2024-03-10 10:34 ` [PATCH 3/3] ALSA: scarlett2: Fix Scarlett 4th Gen input gain range Geoffrey D. Bennett
2024-03-11  8:16 ` [PATCH 0/3] ALSA: scarlett2: Scarlett 4th Gen fixes for 6.8 Takashi Iwai
2024-03-11  8:42   ` Geoffrey D. Bennett
2024-03-11  8:44     ` Takashi Iwai
2024-03-11  9:27       ` Geoffrey D. Bennett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox