Commit fe902250 authored by Jaroslav Kysela's avatar Jaroslav Kysela

[ALSA] MPU-401 driver cleanup

MPU401 UART
Correctly check for error codes returned by pnp_register_driver,
use a common function for registering the sound card, and remove
many #ifdef's.
Signed-off-by: default avatarMatthieu Castet <castet.matthieu@free.fr>
Signed-off-by: default avatarClemens Ladisch <clemens@ladisch.de>
parent 6d92388b
...@@ -57,6 +57,54 @@ module_param_array(irq, int, NULL, 0444); ...@@ -57,6 +57,54 @@ 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 snd_card_t *snd_mpu401_legacy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; static snd_card_t *snd_mpu401_legacy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
static int pnp_registered = 0;
static int snd_mpu401_create(int dev, snd_card_t **rcard)
{
snd_card_t *card;
int err;
*rcard = NULL;
card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
if (card == NULL)
return -ENOMEM;
strcpy(card->driver, "MPU-401 UART");
strcpy(card->shortname, card->driver);
sprintf(card->longname, "%s at %#lx, ", card->shortname, port[dev]);
if (irq[dev] >= 0) {
sprintf(card->longname + strlen(card->longname), "irq %d", irq[dev]);
} else {
strcat(card->longname, "polled");
}
if (snd_mpu401_uart_new(card, 0,
MPU401_HW_MPU401,
port[dev], 0,
irq[dev], irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0) {
printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
snd_card_free(card);
return -ENODEV;
}
if ((err = snd_card_register(card)) < 0) {
snd_card_free(card);
return err;
}
*rcard = card;
return 0;
}
static int __devinit snd_mpu401_probe(int dev)
{
if (port[dev] == SNDRV_AUTO_PORT) {
snd_printk(KERN_ERR "specify port\n");
return -EINVAL;
}
if (irq[dev] == SNDRV_AUTO_IRQ) {
snd_printk(KERN_ERR "specify or disable IRQ\n");
return -EINVAL;
}
return snd_mpu401_create(dev, &snd_mpu401_legacy_cards[dev]);
}
#ifdef CONFIG_PNP #ifdef CONFIG_PNP
...@@ -93,82 +141,25 @@ static int __init snd_mpu401_pnp(int dev, struct pnp_dev *device, ...@@ -93,82 +141,25 @@ static int __init snd_mpu401_pnp(int dev, struct pnp_dev *device,
} }
return 0; return 0;
} }
#endif
static int __devinit snd_card_mpu401_probe(int dev, struct pnp_dev *device,
const struct pnp_device_id *pnp_id)
{
snd_card_t *card;
int err;
#ifdef CONFIG_PNP
if (!device) {
#endif
if (port[dev] == SNDRV_AUTO_PORT) {
snd_printk(KERN_ERR "specify port\n");
return -EINVAL;
}
if (irq[dev] == SNDRV_AUTO_IRQ) {
snd_printk(KERN_ERR "specify or disable IRQ\n");
return -EINVAL;
}
#ifdef CONFIG_PNP
} else {
if ((err = snd_mpu401_pnp(dev, device, pnp_id)) < 0)
return err;
}
#endif
card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
if (card == NULL)
return -ENOMEM;
strcpy(card->driver, "MPU-401 UART");
strcpy(card->shortname, card->driver);
sprintf(card->longname, "%s at %#lx, ", card->shortname, port[dev]);
if (irq[dev] >= 0) {
sprintf(card->longname + strlen(card->longname), "irq %d", irq[dev]);
} else {
strcat(card->longname, "polled");
}
#ifdef CONFIG_PNP
if (device) {
snd_card_set_dev(card, &device->dev);
}
#endif
if (snd_mpu401_uart_new(card, 0,
MPU401_HW_MPU401,
port[dev], 0,
irq[dev], irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0) {
printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
snd_card_free(card);
return -ENODEV;
}
if ((err = snd_card_register(card)) < 0) {
snd_card_free(card);
return err;
}
#ifdef CONFIG_PNP
if (device)
pnp_set_drvdata(device, card);
else
#endif
snd_mpu401_legacy_cards[dev] = card;
return 0;
}
#ifdef CONFIG_PNP
static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev, static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
const struct pnp_device_id *id) const struct pnp_device_id *id)
{ {
static int dev; static int dev;
snd_card_t *card;
int err; int err;
for ( ; dev < SNDRV_CARDS; ++dev) { for ( ; dev < SNDRV_CARDS; ++dev) {
if (!enable[dev] || !pnp[dev]) if (!enable[dev] || !pnp[dev])
continue; continue;
err = snd_card_mpu401_probe(dev, pnp_dev, id); err = snd_mpu401_pnp(dev, pnp_dev, id);
if (err < 0)
return err;
err = snd_mpu401_create(dev, &card);
if (err < 0) if (err < 0)
return err; return err;
snd_card_set_dev(card, &pnp_dev->dev);
pnp_set_drvdata(pnp_dev, card);
++dev; ++dev;
return 0; return 0;
} }
...@@ -189,11 +180,14 @@ static struct pnp_driver snd_mpu401_pnp_driver = { ...@@ -189,11 +180,14 @@ static struct pnp_driver snd_mpu401_pnp_driver = {
.probe = snd_mpu401_pnp_probe, .probe = snd_mpu401_pnp_probe,
.remove = __devexit_p(snd_mpu401_pnp_remove), .remove = __devexit_p(snd_mpu401_pnp_remove),
}; };
#else
static struct pnp_driver snd_mpu401_pnp_driver;
#endif #endif
static int __init alsa_card_mpu401_init(void) static int __init alsa_card_mpu401_init(void)
{ {
int dev, devices = 0; int dev, devices = 0;
int err;
for (dev = 0; dev < SNDRV_CARDS; dev++) { for (dev = 0; dev < SNDRV_CARDS; dev++) {
if (!enable[dev]) if (!enable[dev])
...@@ -202,19 +196,20 @@ static int __init alsa_card_mpu401_init(void) ...@@ -202,19 +196,20 @@ static int __init alsa_card_mpu401_init(void)
if (pnp[dev]) if (pnp[dev])
continue; continue;
#endif #endif
if (snd_card_mpu401_probe(dev, NULL, NULL) >= 0) if (snd_mpu401_probe(dev) >= 0)
devices++; devices++;
} }
#ifdef CONFIG_PNP if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) {
devices += pnp_register_driver(&snd_mpu401_pnp_driver); pnp_registered = 1;
#endif devices += err;
}
if (!devices) { if (!devices) {
#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
#ifdef CONFIG_PNP if (pnp_registered)
pnp_unregister_driver(&snd_mpu401_pnp_driver); pnp_unregister_driver(&snd_mpu401_pnp_driver);
#endif
return -ENODEV; return -ENODEV;
} }
return 0; return 0;
...@@ -224,9 +219,8 @@ static void __exit alsa_card_mpu401_exit(void) ...@@ -224,9 +219,8 @@ static void __exit alsa_card_mpu401_exit(void)
{ {
int idx; int idx;
#ifdef CONFIG_PNP if (pnp_registered)
pnp_unregister_driver(&snd_mpu401_pnp_driver); pnp_unregister_driver(&snd_mpu401_pnp_driver);
#endif
for (idx = 0; idx < SNDRV_CARDS; idx++) for (idx = 0; idx < SNDRV_CARDS; idx++)
snd_card_free(snd_mpu401_legacy_cards[idx]); snd_card_free(snd_mpu401_legacy_cards[idx]);
} }
......
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