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

[ALSA] mpu401 - Use platform_device

Modules: MPU401 UART

Rewrite the probe/remove code using platform_device.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 3564fbb8
...@@ -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/pnp.h> #include <linux/pnp.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/mpu401.h> #include <sound/mpu401.h>
...@@ -56,7 +58,6 @@ MODULE_PARM_DESC(port, "Port # for MPU-401 device."); ...@@ -56,7 +58,6 @@ MODULE_PARM_DESC(port, "Port # for MPU-401 device.");
module_param_array(irq, int, NULL, 0444); module_param_array(irq, int, NULL, 0444);
MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device."); MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device.");
static struct snd_card *snd_mpu401_legacy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
static int pnp_registered = 0; static int pnp_registered = 0;
static int snd_mpu401_create(int dev, struct snd_card **rcard) static int snd_mpu401_create(int dev, struct snd_card **rcard)
...@@ -85,12 +86,6 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard) ...@@ -85,12 +86,6 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard)
goto _err; goto _err;
} }
if ((err = snd_card_set_generic_dev(card)) < 0)
goto _err;
if ((err = snd_card_register(card)) < 0)
goto _err;
*rcard = card; *rcard = card;
return 0; return 0;
...@@ -99,8 +94,12 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard) ...@@ -99,8 +94,12 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard)
return err; return err;
} }
static int __devinit snd_mpu401_probe(int dev) static int __devinit snd_mpu401_probe(struct platform_device *devptr)
{ {
int dev = devptr->id;
int err;
struct snd_card *card;
if (port[dev] == SNDRV_AUTO_PORT) { if (port[dev] == SNDRV_AUTO_PORT) {
snd_printk(KERN_ERR "specify port\n"); snd_printk(KERN_ERR "specify port\n");
return -EINVAL; return -EINVAL;
...@@ -109,9 +108,36 @@ static int __devinit snd_mpu401_probe(int dev) ...@@ -109,9 +108,36 @@ static int __devinit snd_mpu401_probe(int dev)
snd_printk(KERN_ERR "specify or disable IRQ\n"); snd_printk(KERN_ERR "specify or disable IRQ\n");
return -EINVAL; return -EINVAL;
} }
return snd_mpu401_create(dev, &snd_mpu401_legacy_cards[dev]); err = snd_mpu401_create(dev, &card);
if (err < 0)
return err;
snd_card_set_dev(card, &devptr->dev);
if ((err = snd_card_register(card)) < 0) {
snd_card_free(card);
return err;
}
platform_set_drvdata(devptr, card);
return 0;
} }
static int __devexit snd_mpu401_remove(struct platform_device *devptr)
{
snd_card_free(platform_get_drvdata(devptr));
platform_set_drvdata(devptr, NULL);
return 0;
}
#define SND_MPU401_DRIVER "snd_mpu401"
static struct platform_driver snd_mpu401_driver = {
.probe = snd_mpu401_probe,
.remove = __devexit_p(snd_mpu401_remove),
.driver = {
.name = SND_MPU401_DRIVER
},
};
#ifdef CONFIG_PNP #ifdef CONFIG_PNP
#define IO_EXTENT 2 #define IO_EXTENT 2
...@@ -164,6 +190,10 @@ static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, ...@@ -164,6 +190,10 @@ static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
err = snd_mpu401_create(dev, &card); err = snd_mpu401_create(dev, &card);
if (err < 0) if (err < 0)
return err; return err;
if ((err = snd_card_register(card)) < 0) {
snd_card_free(card);
return err;
}
snd_card_set_dev(card, &pnp_dev->dev); snd_card_set_dev(card, &pnp_dev->dev);
pnp_set_drvdata(pnp_dev, card); pnp_set_drvdata(pnp_dev, card);
++dev; ++dev;
...@@ -192,18 +222,25 @@ static struct pnp_driver snd_mpu401_pnp_driver; ...@@ -192,18 +222,25 @@ static struct pnp_driver snd_mpu401_pnp_driver;
static int __init alsa_card_mpu401_init(void) static int __init alsa_card_mpu401_init(void)
{ {
int dev, devices = 0; int i, err, devices;
int err;
for (dev = 0; dev < SNDRV_CARDS; dev++) { if ((err = platform_driver_register(&snd_mpu401_driver)) < 0)
if (!enable[dev]) return err;
continue;
devices = 0;
for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
struct platform_device *device;
#ifdef CONFIG_PNP #ifdef CONFIG_PNP
if (pnp[dev]) if (pnp[i])
continue; continue;
#endif #endif
if (snd_mpu401_probe(dev) >= 0) device = platform_device_register_simple(SND_MPU401_DRIVER,
devices++; i, NULL, 0);
if (IS_ERR(device)) {
err = PTR_ERR(device);
goto errout;
}
devices++;
} }
if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) { if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) {
pnp_registered = 1; pnp_registered = 1;
...@@ -214,21 +251,23 @@ static int __init alsa_card_mpu401_init(void) ...@@ -214,21 +251,23 @@ static int __init alsa_card_mpu401_init(void)
#ifdef MODULE #ifdef MODULE
printk(KERN_ERR "MPU-401 device not found or device busy\n"); printk(KERN_ERR "MPU-401 device not found or device busy\n");
#endif #endif
if (pnp_registered) err = -ENODEV;
pnp_unregister_driver(&snd_mpu401_pnp_driver); goto errout;
return -ENODEV;
} }
return 0; return 0;
errout:
if (pnp_registered)
pnp_unregister_driver(&snd_mpu401_pnp_driver);
platform_driver_unregister(&snd_mpu401_driver);
return err;
} }
static void __exit alsa_card_mpu401_exit(void) static void __exit alsa_card_mpu401_exit(void)
{ {
int idx;
if (pnp_registered) if (pnp_registered)
pnp_unregister_driver(&snd_mpu401_pnp_driver); pnp_unregister_driver(&snd_mpu401_pnp_driver);
for (idx = 0; idx < SNDRV_CARDS; idx++) platform_driver_unregister(&snd_mpu401_driver);
snd_card_free(snd_mpu401_legacy_cards[idx]);
} }
module_init(alsa_card_mpu401_init) module_init(alsa_card_mpu401_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