diff options
author | Geoffrey D. Bennett <g@b4.vu> | 2021-06-22 03:39:37 +0930 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2021-06-22 21:36:04 +0200 |
commit | 06250c89d47cefb51d13fa27e1d6f3032831c8c8 (patch) | |
tree | 7c9bee48bc6dfd93f4637dc4161e0064c4d039e0 /sound/usb/mixer_scarlett_gen2.c | |
parent | 904e6da1fd725245269cedb4d9b4be74a2b22818 (diff) |
ALSA: usb-audio: scarlett2: Add scarlett2_vol_ctl_write() helper
Add helper function for setting the read/write status of a volume
control. This will simplify the upcoming mute control support.
Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Link: https://lore.kernel.org/r/00dd57e1abb3fa379fb51d4ac8537dbddc09f0ea.1624294591.git.g@b4.vu
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb/mixer_scarlett_gen2.c')
-rw-r--r-- | sound/usb/mixer_scarlett_gen2.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c index ded99baa92de..e156119a21e8 100644 --- a/sound/usb/mixer_scarlett_gen2.c +++ b/sound/usb/mixer_scarlett_gen2.c @@ -1344,6 +1344,24 @@ static int scarlett2_sw_hw_enum_ctl_get(struct snd_kcontrol *kctl, return 0; } +static void scarlett2_vol_ctl_set_writable(struct usb_mixer_interface *mixer, + int index, int value) +{ + struct scarlett2_data *private = mixer->private_data; + + /* Set/Clear write bit */ + if (value) + private->vol_ctls[index]->vd[0].access |= + SNDRV_CTL_ELEM_ACCESS_WRITE; + else + private->vol_ctls[index]->vd[0].access &= + ~SNDRV_CTL_ELEM_ACCESS_WRITE; + + /* Notify of write bit change */ + snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_INFO, + &private->vol_ctls[index]->id); +} + static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol) { @@ -1367,12 +1385,7 @@ static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl, /* Change access mode to RO (hardware controlled volume) * or RW (software controlled volume) */ - if (val) - private->vol_ctls[index]->vd[0].access &= - ~SNDRV_CTL_ELEM_ACCESS_WRITE; - else - private->vol_ctls[index]->vd[0].access |= - SNDRV_CTL_ELEM_ACCESS_WRITE; + scarlett2_vol_ctl_set_writable(mixer, index, !val); /* Reset volume to master volume */ private->vol[index] = private->master_vol; @@ -1384,10 +1397,6 @@ static int scarlett2_sw_hw_enum_ctl_put(struct snd_kcontrol *kctl, if (err < 0) goto unlock; - /* Notify of RO/RW change */ - snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_INFO, - &private->vol_ctls[index]->id); - /* Send SW/HW switch change to the device */ err = scarlett2_usb_set_config(mixer, SCARLETT2_CONFIG_SW_HW_SWITCH, index, val); @@ -1620,8 +1629,7 @@ static int scarlett2_add_line_out_ctls(struct usb_mixer_interface *mixer) /* Make the fader read-only if the SW/HW switch is set to HW */ if (private->vol_sw_hw_switch[i]) - private->vol_ctls[i]->vd[0].access &= - ~SNDRV_CTL_ELEM_ACCESS_WRITE; + scarlett2_vol_ctl_set_writable(mixer, i, 0); /* SW/HW Switch */ if (info->line_out_hw_vol) { |