diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2006-01-07 14:40:05 +0000 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2006-01-07 14:40:05 +0000 |
commit | 123656d4cc8c946f578ebd18c2050f5251720428 (patch) | |
tree | 3d5432eff034a3b9cfdc98b37e245abe5695342d /sound/drivers/mpu401/mpu401.c | |
parent | a62c80e559809e6c7851ec04d30575e85ad6f6ed (diff) | |
parent | 0aec63e67c69545ca757a73a66f5dcf05fa484bf (diff) | |
download | op-kernel-dev-123656d4cc8c946f578ebd18c2050f5251720428.zip op-kernel-dev-123656d4cc8c946f578ebd18c2050f5251720428.tar.gz |
Merge with Linus' kernel.
Diffstat (limited to 'sound/drivers/mpu401/mpu401.c')
-rw-r--r-- | sound/drivers/mpu401/mpu401.c | 108 |
1 files changed, 78 insertions, 30 deletions
diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c index 54e2ff9..915589a 100644 --- a/sound/drivers/mpu401/mpu401.c +++ b/sound/drivers/mpu401/mpu401.c @@ -23,6 +23,8 @@ #include <sound/driver.h> #include <linux/init.h> #include <linux/pnp.h> +#include <linux/err.h> +#include <linux/platform_device.h> #include <linux/moduleparam.h> #include <sound/core.h> #include <sound/mpu401.h> @@ -56,12 +58,12 @@ MODULE_PARM_DESC(port, "Port # for MPU-401 device."); module_param_array(irq, int, NULL, 0444); MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device."); -static snd_card_t *snd_mpu401_legacy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; +static struct platform_device *platform_devices[SNDRV_CARDS]; static int pnp_registered = 0; -static int snd_mpu401_create(int dev, snd_card_t **rcard) +static int snd_mpu401_create(int dev, struct snd_card **rcard) { - snd_card_t *card; + struct snd_card *card; int err; *rcard = NULL; @@ -85,12 +87,6 @@ static int snd_mpu401_create(int dev, snd_card_t **rcard) goto _err; } - if ((err = snd_card_set_generic_dev(card)) < 0) - goto _err; - - if ((err = snd_card_register(card)) < 0) - goto _err; - *rcard = card; return 0; @@ -99,8 +95,12 @@ static int snd_mpu401_create(int dev, snd_card_t **rcard) 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) { snd_printk(KERN_ERR "specify port\n"); return -EINVAL; @@ -109,9 +109,36 @@ static int __devinit snd_mpu401_probe(int dev) snd_printk(KERN_ERR "specify or disable IRQ\n"); 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 #define IO_EXTENT 2 @@ -152,7 +179,7 @@ static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, const struct pnp_device_id *id) { static int dev; - snd_card_t *card; + struct snd_card *card; int err; for ( ; dev < SNDRV_CARDS; ++dev) { @@ -164,6 +191,10 @@ static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, err = snd_mpu401_create(dev, &card); if (err < 0) return err; + if ((err = snd_card_register(card)) < 0) { + snd_card_free(card); + return err; + } snd_card_set_dev(card, &pnp_dev->dev); pnp_set_drvdata(pnp_dev, card); ++dev; @@ -174,7 +205,7 @@ static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, static void __devexit snd_mpu401_pnp_remove(struct pnp_dev *dev) { - snd_card_t *card = (snd_card_t *) pnp_get_drvdata(dev); + struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev); snd_card_disconnect(card); snd_card_free_in_thread(card); @@ -190,20 +221,39 @@ static struct pnp_driver snd_mpu401_pnp_driver = { static struct pnp_driver snd_mpu401_pnp_driver; #endif +static void __init_or_module snd_mpu401_unregister_all(void) +{ + int i; + + if (pnp_registered) + pnp_unregister_driver(&snd_mpu401_pnp_driver); + for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) + platform_device_unregister(platform_devices[i]); + platform_driver_unregister(&snd_mpu401_driver); +} + static int __init alsa_card_mpu401_init(void) { - int dev, devices = 0; - int err; + int i, err, devices; - for (dev = 0; dev < SNDRV_CARDS; dev++) { - if (!enable[dev]) - continue; + if ((err = platform_driver_register(&snd_mpu401_driver)) < 0) + return err; + + devices = 0; + for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { + struct platform_device *device; #ifdef CONFIG_PNP - if (pnp[dev]) + if (pnp[i]) continue; #endif - if (snd_mpu401_probe(dev) >= 0) - devices++; + device = platform_device_register_simple(SND_MPU401_DRIVER, + i, NULL, 0); + if (IS_ERR(device)) { + err = PTR_ERR(device); + goto errout; + } + platform_devices[i] = device; + devices++; } if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) { pnp_registered = 1; @@ -214,21 +264,19 @@ static int __init alsa_card_mpu401_init(void) #ifdef MODULE printk(KERN_ERR "MPU-401 device not found or device busy\n"); #endif - if (pnp_registered) - pnp_unregister_driver(&snd_mpu401_pnp_driver); - return -ENODEV; + err = -ENODEV; + goto errout; } return 0; + + errout: + snd_mpu401_unregister_all(); + return err; } static void __exit alsa_card_mpu401_exit(void) { - int idx; - - if (pnp_registered) - pnp_unregister_driver(&snd_mpu401_pnp_driver); - for (idx = 0; idx < SNDRV_CARDS; idx++) - snd_card_free(snd_mpu401_legacy_cards[idx]); + snd_mpu401_unregister_all(); } module_init(alsa_card_mpu401_init) |