diff options
author | Oliver Neukum <oneukum@suse.de> | 2007-12-14 08:42:41 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@perex.cz> | 2008-01-31 11:29:36 -0500 |
commit | f85bf29c9435baf927e1817e6b43c9429b84f822 (patch) | |
tree | 9a32fda61aafa0d87a8040c2657fe57dd1c59dcc | |
parent | 175859bf1602c7ee38d720daa14a287072cc2b72 (diff) |
[ALSA] usb audio suspend support
This patch implements suspend/resume support for USB audio devices.
It works with the microphone in my camera.
Signed-off-by: Oliver Neukum <oneukum@suse.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r-- | sound/usb/usbaudio.c | 41 | ||||
-rw-r--r-- | sound/usb/usbaudio.h | 1 |
2 files changed, 42 insertions, 0 deletions
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c index 967b823eace0..c52461d4a042 100644 --- a/sound/usb/usbaudio.c +++ b/sound/usb/usbaudio.c | |||
@@ -2077,6 +2077,8 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, | |||
2077 | static int usb_audio_probe(struct usb_interface *intf, | 2077 | static int usb_audio_probe(struct usb_interface *intf, |
2078 | const struct usb_device_id *id); | 2078 | const struct usb_device_id *id); |
2079 | static void usb_audio_disconnect(struct usb_interface *intf); | 2079 | static void usb_audio_disconnect(struct usb_interface *intf); |
2080 | static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message); | ||
2081 | static int usb_audio_resume(struct usb_interface *intf); | ||
2080 | 2082 | ||
2081 | static struct usb_device_id usb_audio_ids [] = { | 2083 | static struct usb_device_id usb_audio_ids [] = { |
2082 | #include "usbquirks.h" | 2084 | #include "usbquirks.h" |
@@ -2092,6 +2094,8 @@ static struct usb_driver usb_audio_driver = { | |||
2092 | .name = "snd-usb-audio", | 2094 | .name = "snd-usb-audio", |
2093 | .probe = usb_audio_probe, | 2095 | .probe = usb_audio_probe, |
2094 | .disconnect = usb_audio_disconnect, | 2096 | .disconnect = usb_audio_disconnect, |
2097 | .suspend = usb_audio_suspend, | ||
2098 | .resume = usb_audio_resume, | ||
2095 | .id_table = usb_audio_ids, | 2099 | .id_table = usb_audio_ids, |
2096 | }; | 2100 | }; |
2097 | 2101 | ||
@@ -3654,6 +3658,43 @@ static void usb_audio_disconnect(struct usb_interface *intf) | |||
3654 | dev_get_drvdata(&intf->dev)); | 3658 | dev_get_drvdata(&intf->dev)); |
3655 | } | 3659 | } |
3656 | 3660 | ||
3661 | static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) | ||
3662 | { | ||
3663 | struct snd_usb_audio *chip = dev_get_drvdata(&intf->dev); | ||
3664 | struct list_head *p; | ||
3665 | struct snd_usb_stream *as; | ||
3666 | |||
3667 | if (chip == (void *)-1L) | ||
3668 | return 0; | ||
3669 | |||
3670 | snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); | ||
3671 | if (!chip->num_suspended_intf++) { | ||
3672 | list_for_each(p, &chip->pcm_list) { | ||
3673 | as = list_entry(p, struct snd_usb_stream, list); | ||
3674 | snd_pcm_suspend_all(as->pcm); | ||
3675 | } | ||
3676 | } | ||
3677 | |||
3678 | return 0; | ||
3679 | } | ||
3680 | |||
3681 | static int usb_audio_resume(struct usb_interface *intf) | ||
3682 | { | ||
3683 | struct snd_usb_audio *chip = dev_get_drvdata(&intf->dev); | ||
3684 | |||
3685 | if (chip == (void *)-1L) | ||
3686 | return 0; | ||
3687 | if (--chip->num_suspended_intf) | ||
3688 | return 0; | ||
3689 | /* | ||
3690 | * ALSA leaves material resumption to user space | ||
3691 | * we just notify | ||
3692 | */ | ||
3693 | |||
3694 | snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); | ||
3695 | |||
3696 | return 0; | ||
3697 | } | ||
3657 | 3698 | ||
3658 | static int __init snd_usb_audio_init(void) | 3699 | static int __init snd_usb_audio_init(void) |
3659 | { | 3700 | { |
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h index 2272f45a1867..7cf18c38dc42 100644 --- a/sound/usb/usbaudio.h +++ b/sound/usb/usbaudio.h | |||
@@ -126,6 +126,7 @@ struct snd_usb_audio { | |||
126 | u32 usb_id; | 126 | u32 usb_id; |
127 | int shutdown; | 127 | int shutdown; |
128 | int num_interfaces; | 128 | int num_interfaces; |
129 | int num_suspended_intf; | ||
129 | 130 | ||
130 | struct list_head pcm_list; /* list of pcm streams */ | 131 | struct list_head pcm_list; /* list of pcm streams */ |
131 | int pcm_devs; | 132 | int pcm_devs; |