Commit 68668845 authored by Takashi Iwai's avatar Takashi Iwai Committed by Jaroslav Kysela

[ALSA] ad1848 - Use platform_device, add PM

Modules: AD1848 driver

Rewrite the probe/remove with platform_device.
Add the PM support, too.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c66d7f72
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include <sound/driver.h> #include <sound/driver.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
...@@ -60,11 +62,10 @@ MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver."); ...@@ -60,11 +62,10 @@ MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver.");
module_param_array(thinkpad, bool, NULL, 0444); module_param_array(thinkpad, bool, NULL, 0444);
MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series.");
static struct snd_card *snd_ad1848_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
static int __init snd_ad1848_probe(struct platform_device *pdev)
static int __init snd_card_ad1848_probe(int dev)
{ {
int dev = pdev->id;
struct snd_card *card; struct snd_card *card;
struct snd_ad1848 *chip; struct snd_ad1848 *chip;
struct snd_pcm *pcm; struct snd_pcm *pcm;
...@@ -93,6 +94,7 @@ static int __init snd_card_ad1848_probe(int dev) ...@@ -93,6 +94,7 @@ static int __init snd_card_ad1848_probe(int dev)
thinkpad[dev] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT, thinkpad[dev] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT,
&chip)) < 0) &chip)) < 0)
goto _err; goto _err;
card->private_data = chip;
if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0) if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0)
goto _err; goto _err;
...@@ -109,13 +111,12 @@ static int __init snd_card_ad1848_probe(int dev) ...@@ -109,13 +111,12 @@ static int __init snd_card_ad1848_probe(int dev)
if (thinkpad[dev]) if (thinkpad[dev])
strcat(card->longname, " [Thinkpad]"); strcat(card->longname, " [Thinkpad]");
if ((err = snd_card_set_generic_dev(card)) < 0) snd_card_set_dev(card, &pdev->dev);
goto _err;
if ((err = snd_card_register(card)) < 0) if ((err = snd_card_register(card)) < 0)
goto _err; goto _err;
snd_ad1848_cards[dev] = card; platform_set_drvdata(pdev, card);
return 0; return 0;
_err: _err:
...@@ -123,29 +124,85 @@ static int __init snd_card_ad1848_probe(int dev) ...@@ -123,29 +124,85 @@ static int __init snd_card_ad1848_probe(int dev)
return err; return err;
} }
static int __devexit snd_ad1848_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_ad1848_suspend(struct platform_device *pdev, pm_message_t state)
{
struct snd_card *card = platform_get_drvdata(pdev);
struct snd_ad1848 *chip = card->private_data;
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
chip->suspend(chip);
return 0;
}
static int snd_ad1848_resume(struct platform_device *pdev)
{
struct snd_card *card = platform_get_drvdata(pdev);
struct snd_ad1848 *chip = card->private_data;
chip->resume(chip);
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0;
}
#endif
#define SND_AD1848_DRIVER "snd_ad1848"
static struct platform_driver snd_ad1848_driver = {
.probe = snd_ad1848_probe,
.remove = __devexit_p(snd_ad1848_remove),
#ifdef CONFIG_PM
.suspend = snd_ad1848_suspend,
.resume = snd_ad1848_resume,
#endif
.driver = {
.name = SND_AD1848_DRIVER
},
};
static int __init alsa_card_ad1848_init(void) static int __init alsa_card_ad1848_init(void)
{ {
int dev, cards; int i, cards, err;
for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) err = platform_driver_register(&snd_ad1848_driver);
if (snd_card_ad1848_probe(dev) >= 0) if (err < 0)
cards++; return err;
cards = 0;
for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
struct platform_device *device;
device = platform_device_register_simple(SND_AD1848_DRIVER,
i, NULL, 0);
if (IS_ERR(device)) {
err = PTR_ERR(device);
goto errout;
}
cards++;
}
if (!cards) { if (!cards) {
#ifdef MODULE #ifdef MODULE
printk(KERN_ERR "AD1848 soundcard not found or device busy\n"); printk(KERN_ERR "AD1848 soundcard not found or device busy\n");
#endif #endif
return -ENODEV; err = -ENODEV;
goto errout;
} }
return 0; return 0;
errout:
platform_driver_unregister(&snd_ad1848_driver);
return err;
} }
static void __exit alsa_card_ad1848_exit(void) static void __exit alsa_card_ad1848_exit(void)
{ {
int idx; platform_driver_unregister(&snd_ad1848_driver);
for (idx = 0; idx < SNDRV_CARDS; idx++)
snd_card_free(snd_ad1848_cards[idx]);
} }
module_init(alsa_card_ad1848_init) module_init(alsa_card_ad1848_init)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment