Skip to content

Commit

Permalink
ALSA: usb-audio: Unify mixer resume and reset_resume procedure
Browse files Browse the repository at this point in the history
USB-audio driver assumes that the normal resume would preserve the
device configuration while reset_resume wouldn't, and tries to restore
the mixer elements only at reset_resume callback.  However, this seems
too naive, and some devices do behave differently, resetting the
volume at the normal resume; this resulted in the inconsistent volume
that surprised users.

This patch changes the mixer resume code to handle both the normal and
reset resume in the same way, always restoring the original mixer
element values.  This allows us to unify the both callbacks as well as
dropping the no longer used reset_resume field, which ends up with a
good code reduction.

A slight behavior change by this patch is that now we assign
restore_mixer_value() as the default resume callback, and the function
is no longer called at reset-resume when the resume callback is
overridden by the quirk function.  That is, if needed, the quirk
resume function would have to handle similarly as
restore_mixer_value() by itself.

Reported-by: En-Shuo Hsu <[email protected]>
Cc: Yu-Hsuan Hsu <[email protected]>
Link: https://lore.kernel.org/r/CADDZ45UPsbpAAqP6=ZkTT8BE-yLii4Y7xSDnjK550G2DhQsMew@mail.gmail.com
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed Sep 13, 2021
1 parent 6f44578 commit 7b9cf90
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 39 deletions.
18 changes: 4 additions & 14 deletions sound/usb/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
return 0;
}

static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
static int usb_audio_resume(struct usb_interface *intf)
{
struct snd_usb_audio *chip = usb_get_intfdata(intf);
struct snd_usb_stream *as;
Expand All @@ -1080,7 +1080,7 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
* we just notify and restart the mixers
*/
list_for_each_entry(mixer, &chip->mixer_list, list) {
err = snd_usb_mixer_resume(mixer, reset_resume);
err = snd_usb_mixer_resume(mixer);
if (err < 0)
goto err_out;
}
Expand All @@ -1100,20 +1100,10 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
atomic_dec(&chip->active); /* allow autopm after this point */
return err;
}

static int usb_audio_resume(struct usb_interface *intf)
{
return __usb_audio_resume(intf, false);
}

static int usb_audio_reset_resume(struct usb_interface *intf)
{
return __usb_audio_resume(intf, true);
}
#else
#define usb_audio_suspend NULL
#define usb_audio_resume NULL
#define usb_audio_reset_resume NULL
#define usb_audio_resume NULL
#endif /* CONFIG_PM */

static const struct usb_device_id usb_audio_ids [] = {
Expand All @@ -1135,7 +1125,7 @@ static struct usb_driver usb_audio_driver = {
.disconnect = usb_audio_disconnect,
.suspend = usb_audio_suspend,
.resume = usb_audio_resume,
.reset_resume = usb_audio_reset_resume,
.reset_resume = usb_audio_resume,
.id_table = usb_audio_ids,
.supports_autosuspend = 1,
};
Expand Down
26 changes: 4 additions & 22 deletions sound/usb/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3653,33 +3653,16 @@ static int restore_mixer_value(struct usb_mixer_elem_list *list)
return 0;
}

static int default_mixer_reset_resume(struct usb_mixer_elem_list *list)
{
int err;

if (list->resume) {
err = list->resume(list);
if (err < 0)
return err;
}
return restore_mixer_value(list);
}

int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume)
int snd_usb_mixer_resume(struct usb_mixer_interface *mixer)
{
struct usb_mixer_elem_list *list;
usb_mixer_elem_resume_func_t f;
int id, err;

/* restore cached mixer values */
for (id = 0; id < MAX_ID_ELEMS; id++) {
for_each_mixer_elem(list, mixer, id) {
if (reset_resume)
f = list->reset_resume;
else
f = list->resume;
if (f) {
err = f(list);
if (list->resume) {
err = list->resume(list);
if (err < 0)
return err;
}
Expand All @@ -3700,7 +3683,6 @@ void snd_usb_mixer_elem_init_std(struct usb_mixer_elem_list *list,
list->id = unitid;
list->dump = snd_usb_mixer_dump_cval;
#ifdef CONFIG_PM
list->resume = NULL;
list->reset_resume = default_mixer_reset_resume;
list->resume = restore_mixer_value;
#endif
}
3 changes: 1 addition & 2 deletions sound/usb/mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct usb_mixer_elem_list {
bool is_std_info;
usb_mixer_elem_dump_func_t dump;
usb_mixer_elem_resume_func_t resume;
usb_mixer_elem_resume_func_t reset_resume;
};

/* iterate over mixer element list of the given unit id */
Expand Down Expand Up @@ -121,7 +120,7 @@ int snd_usb_mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,

#ifdef CONFIG_PM
int snd_usb_mixer_suspend(struct usb_mixer_interface *mixer);
int snd_usb_mixer_resume(struct usb_mixer_interface *mixer, bool reset_resume);
int snd_usb_mixer_resume(struct usb_mixer_interface *mixer);
#endif

int snd_usb_set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
Expand Down
2 changes: 1 addition & 1 deletion sound/usb/mixer_quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static int add_single_ctl_with_resume(struct usb_mixer_interface *mixer,
*listp = list;
list->mixer = mixer;
list->id = id;
list->reset_resume = resume;
list->resume = resume;
kctl = snd_ctl_new1(knew, list);
if (!kctl) {
kfree(list);
Expand Down

0 comments on commit 7b9cf90

Please sign in to comment.