[ALSA] vx-driver - Fix PM support
authorTakashi Iwai <tiwai@suse.de>
Thu, 17 Nov 2005 15:06:05 +0000 (16:06 +0100)
committerJaroslav Kysela <perex@suse.cz>
Tue, 3 Jan 2006 11:27:22 +0000 (12:27 +0100)
Fix PM support on VX drivers (vxpocket and vx222).

Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/vx_core.h
sound/drivers/vx/vx_core.c
sound/pci/vx222/vx222.c
sound/pcmcia/vx/vxpocket.c

index 0a85c37d1bc7288da471d03156271e39b8315185..5fd6f3305e0d38de164bc9621a50d5c0c58a8ff1 100644 (file)
@@ -346,6 +346,12 @@ void vx_set_internal_clock(struct vx_core *chip, unsigned int freq);
 int vx_change_frequency(struct vx_core *chip);
 
 
+/*
+ * PM
+ */
+int snd_vx_suspend(struct vx_core *card, pm_message_t state);
+int snd_vx_resume(struct vx_core *card);
+
 /*
  * hardware constants
  */
index 5abf4235177200c491e4ed9fac48c7b4288a0540..43f615d7a545ca4be36757157a091fbddc769003 100644 (file)
@@ -709,13 +709,11 @@ int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp)
 /*
  * suspend
  */
-static int snd_vx_suspend(struct snd_card *card, pm_message_t state)
+int snd_vx_suspend(struct vx_core *chip, pm_message_t state)
 {
-       struct vx_core *chip = card->pm_private_data;
        unsigned int i;
 
-       snd_assert(chip, return -EINVAL);
-
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
        chip->chip_status |= VX_STAT_IN_SUSPEND;
        for (i = 0; i < chip->hw->num_codecs; i++)
                snd_pcm_suspend_all(chip->pcm[i]);
@@ -726,13 +724,10 @@ static int snd_vx_suspend(struct snd_card *card, pm_message_t state)
 /*
  * resume
  */
-static int snd_vx_resume(struct snd_card *card)
+int snd_vx_resume(struct vx_core *chip)
 {
-       struct vx_core *chip = card->pm_private_data;
        int i, err;
 
-       snd_assert(chip, return -EINVAL);
-
        chip->chip_status &= ~VX_STAT_CHIP_INIT;
 
        for (i = 0; i < 4; i++) {
@@ -748,6 +743,7 @@ static int snd_vx_resume(struct snd_card *card)
        chip->chip_status |= VX_STAT_CHIP_INIT;
        chip->chip_status &= ~VX_STAT_IN_SUSPEND;
 
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
        return 0;
 }
 
@@ -789,8 +785,6 @@ struct vx_core *snd_vx_create(struct snd_card *card, struct snd_vx_hardware *hw,
        strcpy(card->driver, hw->name);
        sprintf(card->shortname, "Digigram %s", hw->name);
 
-       snd_card_set_pm_callback(card, snd_vx_suspend, snd_vx_resume, chip);
-
        vx_proc_init(chip);
 
        return chip;
@@ -822,3 +816,7 @@ EXPORT_SYMBOL(snd_vx_irq_handler);
 EXPORT_SYMBOL(snd_vx_dsp_boot);
 EXPORT_SYMBOL(snd_vx_dsp_load);
 EXPORT_SYMBOL(snd_vx_load_boot_image);
+#ifdef CONFIG_PM
+EXPORT_SYMBOL(snd_vx_suspend);
+EXPORT_SYMBOL(snd_vx_resume);
+#endif
index 4ebbabedb3c36d99cc0da271fa4035ce4c7da303..c816ddf1b215d5ec3c61d06f1127c025b9260a20 100644 (file)
@@ -218,6 +218,7 @@ static int __devinit snd_vx222_probe(struct pci_dev *pci,
                snd_card_free(card);
                return err;
        }
+       card->private_data = vx;
        vx->core.ibl.size = ibl[dev];
 
        sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
@@ -250,12 +251,42 @@ static void __devexit snd_vx222_remove(struct pci_dev *pci)
        pci_set_drvdata(pci, NULL);
 }
 
+#ifdef CONFIG_PM
+static int snd_vx222_suspend(struct pci_dev *pci, pm_message_t state)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct snd_vx222 *vx = card->private_data;
+       int err;
+
+       err = snd_vx_suspend(&vx->core, state);
+       pci_set_power_state(pci, PCI_D3hot);
+       pci_disable_device(pci);
+       pci_save_state(pci);
+       return err;
+}
+
+static int snd_vx222_resume(struct pci_dev *pci)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct snd_vx222 *vx = card->private_data;
+
+       pci_restore_state(pci);
+       pci_enable_device(pci);
+       pci_set_power_state(pci, PCI_D0);
+       pci_set_master(pci);
+       return snd_vx_resume(&vx->core);
+}
+#endif
+
 static struct pci_driver driver = {
        .name = "Digigram VX222",
        .id_table = snd_vx222_ids,
        .probe = snd_vx222_probe,
        .remove = __devexit_p(snd_vx222_remove),
-       SND_PCI_PM_CALLBACKS
+#ifdef CONFIG_PM
+       .suspend = snd_vx222_suspend,
+       .resume = snd_vx222_resume,
+#endif
 };
 
 static int __init alsa_card_vx222_init(void)
index 009629714140ed6cc60f9cd98dcd04c6cf5aac04..5bb079d1795948d8aa23a76e86a5e7cac0c27bce 100644 (file)
@@ -342,9 +342,9 @@ static int vxpocket_event(event_t event, int priority, event_callback_args_t *ar
        case CS_EVENT_PM_SUSPEND:
                snd_printdd(KERN_DEBUG "SUSPEND\n");
                link->state |= DEV_SUSPEND;
-               if (chip && chip->card->pm_suspend) {
+               if (chip) {
                        snd_printdd(KERN_DEBUG "snd_vx_suspend calling\n");
-                       chip->card->pm_suspend(chip->card, PMSG_SUSPEND);
+                       snd_vx_suspend(chip, PMSG_SUSPEND);
                }
                /* Fall through... */
        case CS_EVENT_RESET_PHYSICAL:
@@ -362,9 +362,9 @@ static int vxpocket_event(event_t event, int priority, event_callback_args_t *ar
                        //struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
                        snd_printdd(KERN_DEBUG "requestconfig...\n");
                        pcmcia_request_configuration(link->handle, &link->conf);
-                       if (chip && chip->card->pm_resume) {
+                       if (chip) {
                                snd_printdd(KERN_DEBUG "calling snd_vx_resume\n");
-                               chip->card->pm_resume(chip->card);
+                               snd_vx_resume(chip);
                        }
                }
                snd_printdd(KERN_DEBUG "resume done!\n");
@@ -407,6 +407,7 @@ static dev_link_t *vxpocket_attach(void)
                snd_card_free(card);
                return NULL;
        }
+       card->private_data = vxp;
 
        vxp->index = i;
        card_alloc |= 1 << i;