]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[ALSA] powermac - Use platform_device
authorTakashi Iwai <tiwai@suse.de>
Thu, 17 Nov 2005 16:17:08 +0000 (17:17 +0100)
committerJaroslav Kysela <perex@suse.cz>
Tue, 3 Jan 2006 11:28:44 +0000 (12:28 +0100)
Modules: PPC,PPC PMAC driver,PPC PowerMac driver

Rewrite the probe/remove with platform_device.
Move the PM support to platform_device's callbacks.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/ppc/Kconfig
sound/ppc/pmac.c
sound/ppc/pmac.h
sound/ppc/powermac.c

index 206b9333f91f437d442d8f254aba311d782fadb0..a3fb1496e4dc797609d0186af5d4ba5ae2b696ef 100644 (file)
@@ -13,7 +13,6 @@ config SND_POWERMAC
        tristate "PowerMac (AWACS, DACA, Burgundy, Tumbler, Keywest)"
        depends on SND && I2C && INPUT && PPC_PMAC
        select SND_PCM
-       select SND_GENERIC_DRIVER
        help
          Say Y here to include support for the integrated sound device.
 
index 222765fd0dc56412031696519d862ed695a5dadb..4f0a4204516d6d7d87befcd5d90bd62bf64a5ef2 100644 (file)
 #include <asm/pci-bridge.h>
 
 
-#ifdef CONFIG_PM
-static int snd_pmac_register_sleep_notifier(struct snd_pmac *chip);
-static int snd_pmac_unregister_sleep_notifier(struct snd_pmac *chip);
-static int snd_pmac_suspend(struct snd_card *card, pm_message_t state);
-static int snd_pmac_resume(struct snd_card *card);
-#endif
-
-
 /* fixed frequency table for awacs, screamer, burgundy, DACA (44100 max) */
 static int awacs_freqs[8] = {
        44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
@@ -784,9 +776,6 @@ static int snd_pmac_free(struct snd_pmac *chip)
        }
 
        snd_pmac_sound_feature(chip, 0);
-#ifdef CONFIG_PM
-       snd_pmac_unregister_sleep_notifier(chip);
-#endif
 
        /* clean up mixer if any */
        if (chip->mixer_free)
@@ -1298,12 +1287,6 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
        /* Reset dbdma channels */
        snd_pmac_dbdma_reset(chip);
 
-#ifdef CONFIG_PM
-       /* add sleep notifier */
-       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)
                goto __error;
 
@@ -1328,11 +1311,11 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
  * Save state when going to sleep, restore it afterwards.
  */
 
-static int snd_pmac_suspend(struct snd_card *card, pm_message_t state)
+void snd_pmac_suspend(struct snd_pmac *chip)
 {
-       struct snd_pmac *chip = card->pm_private_data;
        unsigned long flags;
 
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
        if (chip->suspend)
                chip->suspend(chip);
        snd_pcm_suspend_all(chip->pcm);
@@ -1346,22 +1329,18 @@ static int snd_pmac_suspend(struct snd_card *card, pm_message_t state)
        if (chip->rx_irq >= 0)
                disable_irq(chip->rx_irq);
        snd_pmac_sound_feature(chip, 0);
-       return 0;
 }
 
-static int snd_pmac_resume(struct snd_card *card)
+void snd_pmac_resume(struct snd_pmac *chip)
 {
-       struct snd_pmac *chip = card->pm_private_data;
-
        snd_pmac_sound_feature(chip, 1);
        if (chip->resume)
                chip->resume(chip);
        /* enable CD sound input */
-       if (chip->macio_base && chip->is_pbook_G3) {
+       if (chip->macio_base && chip->is_pbook_G3)
                out_8(chip->macio_base + 0x37, 3);
-       } else if (chip->is_pbook_3400) {
+       else if (chip->is_pbook_3400)
                in_8(chip->latch_base + 0x190);
-       }
 
        snd_pmac_pcm_set_format(chip);
 
@@ -1372,53 +1351,7 @@ static int snd_pmac_resume(struct snd_card *card)
        if (chip->rx_irq >= 0)
                enable_irq(chip->rx_irq);
 
-       return 0;
-}
-
-/* the chip is stored statically by snd_pmac_register_sleep_notifier
- * because we can't have any private data for notify callback.
- */
-static struct snd_pmac *sleeping_pmac = NULL;
-
-static int snd_pmac_sleep_notify(struct pmu_sleep_notifier *self, int when)
-{
-       struct snd_pmac *chip;
-
-       chip = sleeping_pmac;
-       if (! chip)
-               return 0;
-
-       switch (when) {
-       case PBOOK_SLEEP_NOW:
-               snd_pmac_suspend(chip->card, PMSG_SUSPEND);
-               break;
-       case PBOOK_WAKE:
-               snd_pmac_resume(chip->card);
-               break;
-       }
-       return PBOOK_SLEEP_OK;
-}
-
-static struct pmu_sleep_notifier snd_pmac_sleep_notifier = {
-       snd_pmac_sleep_notify, SLEEP_LEVEL_SOUND,
-};
-
-static int __init snd_pmac_register_sleep_notifier(struct snd_pmac *chip)
-{
-       /* should be protected here.. */
-       snd_assert(! sleeping_pmac, return -EBUSY);
-       sleeping_pmac = chip;
-       pmu_register_sleep_notifier(&snd_pmac_sleep_notifier);
-       return 0;
-}
-                                                   
-static int snd_pmac_unregister_sleep_notifier(struct snd_pmac *chip)
-{
-       /* should be protected here.. */
-       snd_assert(sleeping_pmac == chip, return -ENODEV);
-       pmu_unregister_sleep_notifier(&snd_pmac_sleep_notifier);
-       sleeping_pmac = NULL;
-       return 0;
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
 }
 
 #endif /* CONFIG_PM */
index e223884ccb20133938ebe34c71eb06d558a47931..086da7a1890902edded8becc605895baf92562f4 100644 (file)
@@ -176,6 +176,11 @@ unsigned int snd_pmac_rate_index(struct snd_pmac *chip, struct pmac_stream *rec,
 void snd_pmac_beep_dma_start(struct snd_pmac *chip, int bytes, unsigned long addr, int speed);
 void snd_pmac_beep_dma_stop(struct snd_pmac *chip);
 
+#ifdef CONFIG_PM
+void snd_pmac_suspend(struct snd_pmac *chip);
+void snd_pmac_resume(struct snd_pmac *chip);
+#endif
+
 /* initialize mixer */
 int snd_pmac_awacs_init(struct snd_pmac *chip);
 int snd_pmac_burgundy_init(struct snd_pmac *chip);
index db139cdee28b25b1740ef5ae95649c5dd458899f..efa06fe5f01b78e9ecbca908a7fbc30a79d7376f 100644 (file)
@@ -20,6 +20,8 @@
 
 #include <sound/driver.h>
 #include <linux/init.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
 #include <linux/moduleparam.h>
 #include <sound/core.h>
 #include <sound/initval.h>
@@ -46,15 +48,9 @@ MODULE_PARM_DESC(enable_beep, "Enable beep using PCM.");
 
 
 /*
- * card entry
  */
 
-static struct snd_card *snd_pmac_card = NULL;
-
-/*
- */
-
-static int __init snd_pmac_probe(void)
+static int __init snd_pmac_probe(struct platform_device *devptr)
 {
        struct snd_card *card;
        struct snd_pmac *chip;
@@ -67,6 +63,7 @@ static int __init snd_pmac_probe(void)
 
        if ((err = snd_pmac_new(card, &chip)) < 0)
                goto __error;
+       card->private_data = chip;
 
        switch (chip->model) {
        case PMAC_BURGUNDY:
@@ -131,13 +128,12 @@ static int __init snd_pmac_probe(void)
        if (enable_beep)
                snd_pmac_attach_beep(chip);
 
-       if ((err = snd_card_set_generic_dev(card)) < 0)
-               goto __error;
+       snd_card_set_dev(card, &devptr->dev);
 
        if ((err = snd_card_register(card)) < 0)
                goto __error;
 
-       snd_pmac_card = card;
+       platform_set_drvdata(devptr, card);
        return 0;
 
 __error:
@@ -146,23 +142,62 @@ __error:
 }
 
 
-/*
- * MODULE stuff
- */
+static int __devexit snd_pmac_remove(struct platform_device *devptr)
+{
+       snd_card_free(platform_get_drvdata(devptr));
+       platform_set_drvdata(devptr, NULL);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int snd_pmac_driver_suspend(struct platform_device *devptr, pm_message_t state)
+{
+       struct snd_card *card = platform_get_drvdata(devptr);
+       snd_pmac_suspend(card->private_data);
+       return 0;
+}
+
+static int snd_pmac_driver_resume(struct platform_device *devptr)
+{
+       struct snd_card *card = platform_get_drvdata(devptr);
+       snd_pmac_resume(card->private_data);
+       return 0;
+}
+#endif
+
+#define SND_PMAC_DRIVER                "snd_powermac"
+
+static struct platform_driver snd_pmac_driver = {
+       .probe          = snd_pmac_probe,
+       .remove         = __devexit_p(snd_pmac_remove),
+#ifdef CONFIG_PM
+       .suspend        = snd_pmac_driver_suspend,
+       .resume         = snd_pmac_driver_resume,
+#endif
+       .driver         = {
+               .name   = SND_PMAC_DRIVER
+       },
+};
 
 static int __init alsa_card_pmac_init(void)
 {
        int err;
-       if ((err = snd_pmac_probe()) < 0)
+       struct platform_device *device;
+
+       if ((err = platform_driver_register(&snd_pmac_driver)) < 0)
                return err;
+       device = platform_device_register_simple(SND_PMAC_DRIVER, -1, NULL, 0);
+       if (IS_ERR(device)) {
+               platform_driver_unregister(&snd_pmac_driver);
+               return PTR_ERR(device);
+       }
        return 0;
 
 }
 
 static void __exit alsa_card_pmac_exit(void)
 {
-       if (snd_pmac_card)
-               snd_card_free(snd_pmac_card);
+       platform_driver_unregister(&snd_pmac_driver);
 }
 
 module_init(alsa_card_pmac_init)