Skip to content

Commit f7881e5

Browse files
agoodetiwai
authored andcommitted
ALSA: usb-audio: Respond to suspend and resume callbacks for MIDI input
sound/usb/card.c registers USB suspend and resume but did not previously kill the input URBs. This means that USB MIDI devices left open across suspend/resume had non-functional input (output still usually worked, but it looks like that is another issue). Before this change, we would get ESHUTDOWN for each of the input URBs at suspend time, killing input. Signed-off-by: Adam Goode <agoode@google.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 81cb6b6 commit f7881e5

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

‎sound/usb/card.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
680680
struct snd_usb_audio *chip = usb_get_intfdata(intf);
681681
struct snd_usb_stream *as;
682682
struct usb_mixer_interface *mixer;
683+
struct list_head *p;
683684

684685
if (chip == (void *)-1L)
685686
return 0;
@@ -692,6 +693,9 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
692693
as->substream[0].need_setup_ep =
693694
as->substream[1].need_setup_ep = true;
694695
}
696+
list_for_each(p, &chip->midi_list) {
697+
snd_usbmidi_suspend(p);
698+
}
695699
}
696700
} else {
697701
/*
@@ -713,6 +717,7 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
713717
{
714718
struct snd_usb_audio *chip = usb_get_intfdata(intf);
715719
struct usb_mixer_interface *mixer;
720+
struct list_head *p;
716721
int err = 0;
717722

718723
if (chip == (void *)-1L)
@@ -731,6 +736,10 @@ static int __usb_audio_resume(struct usb_interface *intf, bool reset_resume)
731736
goto err_out;
732737
}
733738

739+
list_for_each(p, &chip->midi_list) {
740+
snd_usbmidi_resume(p);
741+
}
742+
734743
if (!chip->autosuspended)
735744
snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
736745
chip->autosuspended = 0;

‎sound/usb/midi.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,34 @@ void snd_usbmidi_input_start(struct list_head* p)
21862186
}
21872187
EXPORT_SYMBOL(snd_usbmidi_input_start);
21882188

2189+
/*
2190+
* Prepare for suspend. Typically called from the USB suspend callback.
2191+
*/
2192+
void snd_usbmidi_suspend(struct list_head *p)
2193+
{
2194+
struct snd_usb_midi *umidi;
2195+
2196+
umidi = list_entry(p, struct snd_usb_midi, list);
2197+
mutex_lock(&umidi->mutex);
2198+
snd_usbmidi_input_stop(p);
2199+
mutex_unlock(&umidi->mutex);
2200+
}
2201+
EXPORT_SYMBOL(snd_usbmidi_suspend);
2202+
2203+
/*
2204+
* Resume. Typically called from the USB resume callback.
2205+
*/
2206+
void snd_usbmidi_resume(struct list_head *p)
2207+
{
2208+
struct snd_usb_midi *umidi;
2209+
2210+
umidi = list_entry(p, struct snd_usb_midi, list);
2211+
mutex_lock(&umidi->mutex);
2212+
snd_usbmidi_input_start(p);
2213+
mutex_unlock(&umidi->mutex);
2214+
}
2215+
EXPORT_SYMBOL(snd_usbmidi_resume);
2216+
21892217
/*
21902218
* Creates and registers everything needed for a MIDI streaming interface.
21912219
*/

‎sound/usb/midi.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ int snd_usbmidi_create(struct snd_card *card,
4646
void snd_usbmidi_input_stop(struct list_head* p);
4747
void snd_usbmidi_input_start(struct list_head* p);
4848
void snd_usbmidi_disconnect(struct list_head *p);
49+
void snd_usbmidi_suspend(struct list_head *p);
50+
void snd_usbmidi_resume(struct list_head *p);
4951

5052
#endif /* __USBMIDI_H */

0 commit comments

Comments
 (0)