patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / sound / ppc / pmac.c
index 5f94c59..95dfeef 100644 (file)
@@ -42,7 +42,8 @@
 #if defined(CONFIG_PM) && defined(CONFIG_PMAC_PBOOK)
 static int snd_pmac_register_sleep_notifier(pmac_t *chip);
 static int snd_pmac_unregister_sleep_notifier(pmac_t *chip);
-static int snd_pmac_set_power_state(snd_card_t *card, unsigned int power_state);
+static int snd_pmac_suspend(snd_card_t *card, unsigned int state);
+static int snd_pmac_resume(snd_card_t *card, unsigned int state);
 #endif
 
 
@@ -687,7 +688,7 @@ static void snd_pmac_dbdma_reset(pmac_t *chip)
 static irqreturn_t
 snd_pmac_tx_intr(int irq, void *devid, struct pt_regs *regs)
 {
-       pmac_t *chip = snd_magic_cast(pmac_t, devid, return);
+       pmac_t *chip = snd_magic_cast(pmac_t, devid, return IRQ_NONE);
        snd_pmac_pcm_update(chip, &chip->playback);
        return IRQ_HANDLED;
 }
@@ -696,7 +697,7 @@ snd_pmac_tx_intr(int irq, void *devid, struct pt_regs *regs)
 static irqreturn_t
 snd_pmac_rx_intr(int irq, void *devid, struct pt_regs *regs)
 {
-       pmac_t *chip = snd_magic_cast(pmac_t, devid, return);
+       pmac_t *chip = snd_magic_cast(pmac_t, devid, return IRQ_NONE);
        snd_pmac_pcm_update(chip, &chip->capture);
        return IRQ_HANDLED;
 }
@@ -705,7 +706,7 @@ snd_pmac_rx_intr(int irq, void *devid, struct pt_regs *regs)
 static irqreturn_t
 snd_pmac_ctrl_intr(int irq, void *devid, struct pt_regs *regs)
 {
-       pmac_t *chip = snd_magic_cast(pmac_t, devid, return);
+       pmac_t *chip = snd_magic_cast(pmac_t, devid, return IRQ_NONE);
        int ctrl = in_le32(&chip->awacs->control);
 
        /*printk("pmac: control interrupt.. 0x%x\n", ctrl);*/
@@ -1170,9 +1171,8 @@ int __init snd_pmac_new(snd_card_t *card, pmac_t **chip_return)
 
 #if defined(CONFIG_PM) && defined(CONFIG_PMAC_PBOOK)
        /* add sleep notifier */
-       snd_pmac_register_sleep_notifier(chip);
-       card->set_power_state = snd_pmac_set_power_state;
-       card->power_state_private_data = chip;
+       if (! snd_pmac_register_sleep_notifier(chip))
+               snd_card_set_pm_callback(chip->card, snd_pmac_suspend, snd_pmac_resume, chip);
 #endif
 
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0)
@@ -1197,13 +1197,10 @@ int __init snd_pmac_new(snd_card_t *card, pmac_t **chip_return)
  * Save state when going to sleep, restore it afterwards.
  */
 
-static void snd_pmac_suspend(pmac_t *chip)
+static int snd_pmac_suspend(snd_card_t *card, unsigned int state)
 {
+       pmac_t *chip = snd_magic_cast(pmac_t, card->pm_private_data, return -EINVAL);
        unsigned long flags;
-       snd_card_t *card = chip->card;
-
-       if (card->power_state == SNDRV_CTL_POWER_D3hot)
-               return;
 
        if (chip->suspend)
                chip->suspend(chip);
@@ -1219,14 +1216,12 @@ static void snd_pmac_suspend(pmac_t *chip)
                disable_irq(chip->rx_irq);
        snd_pmac_sound_feature(chip, 0);
        snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       return 0;
 }
 
-static void snd_pmac_resume(pmac_t *chip)
+static int snd_pmac_resume(snd_card_t *card, unsigned int state)
 {
-       snd_card_t *card = chip->card;
-
-       if (card->power_state == SNDRV_CTL_POWER_D0)
-               return;
+       pmac_t *chip = snd_magic_cast(pmac_t, card->pm_private_data, return -EINVAL);
 
        snd_pmac_sound_feature(chip, 1);
        if (chip->resume)
@@ -1248,6 +1243,7 @@ static void snd_pmac_resume(pmac_t *chip)
                enable_irq(chip->rx_irq);
 
        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
 }
 
 /* the chip is stored statically by snd_pmac_register_sleep_notifier
@@ -1264,10 +1260,10 @@ static int snd_pmac_sleep_notify(struct pmu_sleep_notifier *self, int when)
 
        switch (when) {
        case PBOOK_SLEEP_NOW:
-               snd_pmac_suspend(chip);
+               snd_pmac_suspend(chip->card, 0);
                break;
        case PBOOK_WAKE:
-               snd_pmac_resume(chip);
+               snd_pmac_resume(chip->card, 0);
                break;
        }
        return PBOOK_SLEEP_OK;
@@ -1280,46 +1276,19 @@ static struct pmu_sleep_notifier snd_pmac_sleep_notifier = {
 static int __init snd_pmac_register_sleep_notifier(pmac_t *chip)
 {
        /* should be protected here.. */
-       if (sleeping_pmac) {
-               snd_printd("sleep notifier already reigistered\n");
-               return -EBUSY;
-       }
+       snd_assert(! sleeping_pmac, return -EBUSY);
        sleeping_pmac = chip;
        pmu_register_sleep_notifier(&snd_pmac_sleep_notifier);
-       chip->sleep_registered = 1;
        return 0;
 }
                                                    
 static int snd_pmac_unregister_sleep_notifier(pmac_t *chip)
 {
-       if (! chip->sleep_registered)
-               return 0;
        /* should be protected here.. */
-       if (sleeping_pmac != chip)
-               return -ENODEV;
+       snd_assert(sleeping_pmac == chip, return -ENODEV);
        pmu_unregister_sleep_notifier(&snd_pmac_sleep_notifier);
        sleeping_pmac = NULL;
        return 0;
 }
 
-/* callback */
-static int snd_pmac_set_power_state(snd_card_t *card, unsigned int power_state)
-{
-       pmac_t *chip = snd_magic_cast(pmac_t, card->power_state_private_data, return -ENXIO);
-       switch (power_state) {
-       case SNDRV_CTL_POWER_D0:
-       case SNDRV_CTL_POWER_D1:
-       case SNDRV_CTL_POWER_D2:
-               snd_pmac_resume(chip);
-               break;
-       case SNDRV_CTL_POWER_D3hot:
-       case SNDRV_CTL_POWER_D3cold:
-               snd_pmac_suspend(chip);
-               break;
-       default:
-               return -EINVAL;
-       }
-       return 0;
-}
-
 #endif /* CONFIG_PM && CONFIG_PMAC_PBOOK */