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 12/17] ALSA: usb-audio: scarlett2: Split up sw_hw_enum_ctl_put()
Date: Wed, 23 Jun 2021 02:33:36 +0930	[thread overview]
Message-ID: <f2cf91841ba067b490e7709bc4b14f4532b4ddd5.1624379707.git.g@b4.vu> (raw)
In-Reply-To: <cover.1624379707.git.g@b4.vu>

Split part of scarlett2_sw_hw_enum_ctl_put() out into
scarlett2_sw_hw_change() so that the code which actually makes the
change is available in its own function. This will be used by the
speaker switching support which needs to set the SW/HW switch to HW
when speaker switching is enabled.

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
---
 sound/usb/mixer_scarlett_gen2.c | 46 ++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
index 59c9147c5cb5..37e35016db12 100644
--- a/sound/usb/mixer_scarlett_gen2.c
+++ b/sound/usb/mixer_scarlett_gen2.c
@@ -1904,23 +1904,12 @@ static void scarlett2_vol_ctl_set_writable(struct usb_mixer_interface *mixer,
 		       &private->mute_ctls[index]->id);
 }
 
-static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl,
-					struct snd_ctl_elem_value *ucontrol)
+static int scarlett2_sw_hw_change(struct usb_mixer_interface *mixer,
+				  int ctl_index, int val)
 {
-	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 ctl_index = elem->control;
 	int index = line_out_remap(private, ctl_index);
-	int oval, val, err = 0;
-
-	mutex_lock(&private->data_mutex);
-
-	oval = private->vol_sw_hw_switch[index];
-	val = !!ucontrol->value.enumerated.item[0];
-
-	if (oval == val)
-		goto unlock;
+	int err;
 
 	private->vol_sw_hw_switch[index] = val;
 
@@ -1938,18 +1927,39 @@ static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl,
 		mixer, SCARLETT2_CONFIG_LINE_OUT_VOLUME,
 		index, private->master_vol - SCARLETT2_VOLUME_BIAS);
 	if (err < 0)
-		goto unlock;
+		return err;
 
 	/* Set SW mute to current HW mute */
 	err = scarlett2_usb_set_config(
 		mixer, SCARLETT2_CONFIG_MUTE_SWITCH,
 		index, private->dim_mute[SCARLETT2_BUTTON_MUTE]);
 	if (err < 0)
-		goto unlock;
+		return err;
 
 	/* Send SW/HW switch change to the device */
-	err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
-				       index, val);
+	return scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH,
+					index, val);
+}
+
+static int scarlett2_sw_hw_enum_ctl_put(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 ctl_index = elem->control;
+	int index = line_out_remap(private, ctl_index);
+	int oval, val, err = 0;
+
+	mutex_lock(&private->data_mutex);
+
+	oval = private->vol_sw_hw_switch[index];
+	val = !!ucontrol->value.enumerated.item[0];
+
+	if (oval == val)
+		goto unlock;
+
+	err = scarlett2_sw_hw_change(mixer, ctl_index, val);
 	if (err == 0)
 		err = 1;
 
-- 
2.31.1


  parent reply	other threads:[~2021-06-22 17:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 17:00 [PATCH V3 00/17] Add Scarlett Gen 3 support Geoffrey D. Bennett
2021-06-22 17:00 ` [PATCH 01/17] ALSA: usb-audio: scarlett2: Fix wrong resume call Geoffrey D. Bennett
2021-06-22 19:42   ` Takashi Iwai
2021-06-23  1:03     ` Geoffrey D. Bennett
2021-06-23  6:39       ` Takashi Iwai
2021-06-25  2:09         ` Hin-Tak Leung
2021-06-22 17:01 ` [PATCH 02/17] ALSA: usb-audio: scarlett2: Add Gen 3 mixer support Geoffrey D. Bennett
2021-06-22 17:01 ` [PATCH 03/17] ALSA: usb-audio: scarlett2: Add support for "input-other" notify Geoffrey D. Bennett
2021-06-22 17:01 ` [PATCH 04/17] ALSA: usb-audio: scarlett2: Add Gen 3 MSD mode switch Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 05/17] ALSA: usb-audio: scarlett2: Move get config above set config Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 06/17] ALSA: usb-audio: scarlett2: Allow bit-level access to config Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 07/17] ALSA: usb-audio: scarlett2: Add support for Solo and 2i2 Gen 3 Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 08/17] ALSA: usb-audio: scarlett2: Add "air" switch support Geoffrey D. Bennett
2021-06-22 17:02 ` [PATCH 09/17] ALSA: usb-audio: scarlett2: Add phantom power " Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 10/17] ALSA: usb-audio: scarlett2: Add direct monitor support Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 11/17] ALSA: usb-audio: scarlett2: Label 18i8 Gen 3 line outputs correctly Geoffrey D. Bennett
2021-06-22 17:03 ` Geoffrey D. Bennett [this message]
2021-06-22 17:03 ` [PATCH 13/17] ALSA: usb-audio: scarlett2: Add sw_hw_ctls and mux_ctls Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 14/17] ALSA: usb-audio: scarlett2: Update mux controls to allow updates Geoffrey D. Bennett
2021-06-22 17:03 ` [PATCH 15/17] ALSA: usb-audio: scarlett2: Add speaker switching support Geoffrey D. Bennett
2021-06-22 17:04 ` [PATCH 16/17] ALSA: usb-audio: scarlett2: Update get_config to do endian conversion Geoffrey D. Bennett
2021-06-22 17:04 ` [PATCH 17/17] 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=f2cf91841ba067b490e7709bc4b14f4532b4ddd5.1624379707.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.