echoaudio, suspend/resume
RFC 1/1 echoaudio, suspend/resume
The following patch is not to be merged yet. It adds suspend/resume support to the echoaudio driver. It's ready for testing if someone wants to give it a try. Maybe some detail is missing, but it should work on all cards.
The problem is that the DSP "dies" if the driver tries to send it a command (for example, set the output volume) after is has been shut down and a reboot is required to resurrect it. ALSA doesn't automatically prevent the user from accessing the card when it's suspended. Is there a simple way to to it ?
For who want to try:
# lspci ... 0001:10:14.0 Multimedia controller: Motorola DSP56361 Digital Signal Processor (rev 01) ... (this is the Gina3G)
suspend:
# echo -n 3 > /sys/devices/pci0001\:10/0001\:10\:14.0/power/state
resume:
# echo -n 0 > /sys/devices/pci0001\:10/0001\:10\:14.0/power/state
pci/echoaudio/echoaudio.c +77 -0
@@ -654,6 +654,8 @@ static int pcm_trigger(struct snd_pcm_suspin_lock (&chip->lock);switch (cmd) { +case SNDRV_PCM_TRIGGER_RESUME : +snd_printk ("tri res1\n" );case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_PAUSE_RELEASE :DE_ACT (("pcm_trigger start\n" ));
@@ -676,6 +678,8 @@ static int pcm_trigger(struct snd_pcm_su } err =start_transport (chip, channelmask, chip->pipe_cyclic_mask);break ; +case SNDRV_PCM_TRIGGER_SUSPEND : +snd_printk ("tri sus1\n" );case SNDRV_PCM_TRIGGER_STOP :DE_ACT (("pcm_trigger stop\n" ));for (i =0 ; i <DSP_MAXPIPES ; i++) {
@@ -692,6 +696,7 @@ static int pcm_trigger(struct snd_pcm_suif (channelmask & (1 << i)) { pipe = chip->substream[i]->runtime->private_data; pipe->state =PIPE_STATE_PAUSED ; +snd_printk ("tri sus2 %d\n" , i); } } err =pause_transport (chip, channelmask);
@@ -2016,6 +2021,74 @@ ctl_error: +#ifdef CONFIG_PM + +static int snd_echo_suspend (struct pci_dev *pci,pm_message_t state) +{ +struct echoaudio *chip =pci_get_drvdata (pci); + +snd_printk ("sus sus1\n" ); +snd_power_change_state (chip->card, SNDRV_CTL_POWER_D3cold); +snd_pcm_suspend_all (chip->analog_pcm); +snd_pcm_suspend_all (chip->digital_pcm); + +if (chip->meters_enabled) +send_vector (chip,DSP_VC_METERS_OFF ); +#ifdef ECHOCARD_HAS_MIDI +enable_midi_input (chip, FALSE); +#endif + chip->dsp_code =NULL ; +send_vector (chip,DSP_VC_GO_COMATOSE ); +pci_set_power_state (pci, PCI_D3cold); +pci_disable_device (pci); +pci_save_state (pci); +snd_printk ("sus sus2\n" ); +return 0 ; +} + + + +static int snd_echo_resume (struct pci_dev *pci) +{ +struct echoaudio *chip =pci_get_drvdata (pci); +int err; + +pci_restore_state (pci); +pci_enable_device (pci); +pci_set_power_state (pci,PCI_D0 ); +pci_set_master (pci); + +snd_printk ("res res1\n" ); +if ((err =load_firmware (chip)) <0 ) +return err; +snd_printk ("res res2\n" ); + chip->bad_board = FALSE; + +#ifdef ECHOCARD_HAS_DIGITAL_MODE_SWITCH +if ((err =set_digital_mode (chip, chip->digital_mode)) <0 ) +return err; +#endif /* ECHOCARD_HAS_DIGITAL_MODE_SWITCH */ + +#ifdef ECHOCARD_HAS_DIGITAL_IO +if ((err =set_professional_spdif (chip, chip->professional_spdif)) <0 ) +return err; +#endif /* ECHOCARD_HAS_DIGITAL_IO */ + +#ifdef ECHOCARD_HAS_PHANTOM_POWER +if (chip->has_phantom_power && chip->phantom_power) +if ((err =set_phantom_power (chip, TRUE)) <0 ) +return err; +#endif /* ECHOCARD_HAS_PHANTOM_POWER */ + +snd_printk ("res res3 %d\n" , chip->meters_enabled); +snd_power_change_state (chip->card,SNDRV_CTL_POWER_D0 ); +return 0 ; +} + +#endif /* CONFIG_PM */ + + + static void __devexit snd_echo_remove(struct pci_dev *pci) {struct echoaudio *chip;
@@ -2037,6 +2110,10 @@ static struct pci_driver driver = { .name = "Echoaudio " ECHOCARD_NAME, .id_table = snd_echo_ids, .probe = snd_echo_probe, +#ifdef CONFIG_PM + .suspend = snd_echo_suspend, + .resume = snd_echo_resume, +#endif /* CONFIG_PM */ .remove = __devexit_p(snd_echo_remove), };
pci/echoaudio/echoaudio_3g.c +1 -1
@@ -100,7 +100,7 @@ static int set_digital_mode(struct echoaint err, i, o;/* All audio channels must be closed before changing the digital mode */ -snd_assert (!chip->pipe_alloc_mask, return -EAGAIN ); +// snd_assert(!chip->pipe_alloc_mask, return -EAGAIN); snd_assert (chip->digital_modes & (1 << mode), return -EINVAL );
pci/echoaudio/echoaudio_gml.c +1 -1
@@ -110,7 +110,7 @@ static int set_digital_mode(struct echoareturn -EIO ;/* All audio channels must be closed before changing the digital mode */ -snd_assert (!chip->pipe_alloc_mask, return -EAGAIN ); +// snd_assert(!chip->pipe_alloc_mask, return -EAGAIN); snd_assert (chip->digital_modes & (1 << mode), return -EINVAL );
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
At Sat, 25 Feb 2006 17:41:17 +0100,
Quoted 10 lines · Giuliano Pochini
The following patch is not to be merged yet. It adds suspend/resume support to the echoaudio driver. It's ready for testing if someone wants to give it a try. Maybe some detail is missing, but it should work on all cards.
The problem is that the DSP "dies" if the driver tries to send it a command (for example, set the output volume) after is has been shut down and a reboot is required to resurrect it. ALSA doesn't automatically prevent the user from accessing the card when it's suspended. Is there a simple way to to it ?
In which timing does it occur?
If it occurs before calling resume callback (not meaning before completing resume callack), we should handle it better in the sound core to prevent it.
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Quoted 7 lines · Takashi Iwai
At Sat, 25 Feb 2006 17:41:17 +0100,
Quoted 5 lines · Giuliano Pochini
The following patch is not to be merged yet. It adds suspend/resume support to the echoaudio driver. It's ready for testing if someone wants to give it a try. Maybe some detail is missing, but it should work on all cards.
Quoted 7 lines
Quoted 5 lines
The problem is that the DSP "dies" if the driver tries to send it a command (for example, set the output volume) after is has been shut down and a reboot is required to resurrect it. ALSA doesn't automatically prevent the user from accessing the card when it's suspended. Is there a simple way to to it ?
In which timing does it occur?
echo -n 3 >/sys/.../power/state
--> power down ok
amixer cset xyz
--> DSP dead
Quoted 3 lines
If it occurs before calling resume callback (not meaning before completing resume callack), we should handle it better in the sound core to prevent it.
The resume callback has to reinit the card from scratch. It involves loading 2 to 5 firmare images which takes several ms. I didn't check after which phase the DSP begins behaving nicely when it receives an unexpected command.
Of cource I can put an "if (suspended) return -EBUSY;" in each .put() and trigger function, but if the middle layer already provides some sort of global switch it's better IMHO. Other proposals are welcome.
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
At Mon, 27 Feb 2006 15:13:52 +0100 (CET),
Quoted 31 lines · Giuliano Pochini
Quoted 7 lines · Takashi Iwai
At Sat, 25 Feb 2006 17:41:17 +0100,
Quoted 5 lines · Giuliano Pochini
The following patch is not to be merged yet. It adds suspend/resume support to the echoaudio driver. It's ready for testing if someone wants to give it a try. Maybe some detail is missing, but it should work on all cards.
Quoted 7 lines
Quoted 5 lines
The problem is that the DSP "dies" if the driver tries to send it a command (for example, set the output volume) after is has been shut down and a reboot is required to resurrect it. ALSA doesn't automatically prevent the user from accessing the card when it's suspended. Is there a simple way to to it ?
In which timing does it occur?
echo -n 3 >/sys/.../power/state
--> power down okamixer cset xyz
--> DSP deadQuoted 3 lines
If it occurs before calling resume callback (not meaning before completing resume callack), we should handle it better in the sound core to prevent it.
Quoted 7 lines
The resume callback has to reinit the card from scratch. It involves loading 2 to 5 firmare images which takes several ms. I didn't check after which phase the DSP begins behaving nicely when it receives an unexpected command.
Of cource I can put an "if (suspended) return-EBUSY;" in each .put() and trigger function, but if the middle layer already provides some sort of global switch it's better IMHO. Other proposals are welcome.
Hm, strange, prepare or trigger callback shouldn't be called at least unless snd_power_change_state(D0) is called. The power status is checked in the middle layer.
The other interfaces have no power-state check so far. It'd be nice to have, yes.
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
Quoted 21 lines · On Mon, 27 Feb 2006 15:23:34 +0100 Takashi Iwai <[email protected]> wrote:
Quoted 13 lines
Quoted 1 line
In which timing does it occur?
echo -n 3 >/sys/.../power/state
--> power down okamixer cset xyz
--> DSP deadQuoted 3 lines
If it occurs before calling resume callback (not meaning before completing resume callack), we should handle it better in the sound core to prevent it.
Quoted 7 lines
The resume callback has to reinit the card from scratch. It involves loading 2 to 5 firmare images which takes several ms. I didn't check after which phase the DSP begins behaving nicely when it receives an unexpected command.
Of cource I can put an "if (suspended) return-EBUSY;" in each .put() and trigger function, but if the middle layer already provides some sort of global switch it's better IMHO. Other proposals are welcome.
Quoted 3 lines
Hm, strange, prepare or trigger callback shouldn't be called at least unless
snd_power_change_state(D0)is called. The power status is checked in the middle layer.
Yes, PCM trigger works as desired indeed, but MIDI trigger doesn't.
--
Giuliano.
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
At Mon, 27 Feb 2006 22:18:31 +0100,
Quoted 25 lines · Giuliano Pochini
Quoted 21 lines · On Mon, 27 Feb 2006 15:23:34 +0100 Takashi Iwai <[email protected]> wrote:
Quoted 20 lines
Quoted 1 line
In which timing does it occur?
echo -n 3 >/sys/.../power/state
--> power down okamixer cset xyz
--> DSP deadQuoted 3 lines
If it occurs before calling resume callback (not meaning before completing resume callack), we should handle it better in the sound core to prevent it.
The resume callback has to reinit the card from scratch. It involves loading 2 to 5 firmare images which takes several ms. I didn't check after which phase the DSP begins behaving nicely when it receives an unexpected command.
Of cource I can put an "if (suspended) return-EBUSY;" in each .put() and trigger function, but if the middle layer already provides some sort of global switch it's better IMHO. Other proposals are welcome.
Quoted 5 lines
Quoted 3 lines
Hm, strange, prepare or trigger callback shouldn't be called at least unless
snd_power_change_state(D0)is called. The power status is checked in the middle layer.Yes, PCM trigger works as desired indeed, but MIDI trigger doesn't.
Ah, that makese sense. The functions except PCM haven't been tested much for PM.
Takashi
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642