[ALSA] virmidi - Use platform_device

Modules: Generic drivers

Rewrite the probe/remove code using platform_device.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2005-11-17 16:03:26 +01:00 committed by Jaroslav Kysela
parent 9caf6b5908
commit 3564fbb880

View File

@ -45,6 +45,8 @@
#include <linux/init.h>
#include <linux/wait.h>
#include <linux/sched.h>
#include <linux/err.h>
#include <linux/platform_device.h>
#include <linux/moduleparam.h>
#include <sound/core.h>
#include <sound/seq_kernel.h>
@ -80,17 +82,14 @@ struct snd_card_virmidi {
struct snd_rawmidi *midi[MAX_MIDI_DEVICES];
};
static struct snd_card *snd_virmidi_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
static int __init snd_card_virmidi_probe(int dev)
static int __init snd_virmidi_probe(struct platform_device *devptr)
{
struct snd_card *card;
struct snd_card_virmidi *vmidi;
int idx, err;
int dev = devptr->id;
if (!enable[dev])
return -ENODEV;
card = snd_card_new(index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_card_virmidi));
if (card == NULL)
@ -117,11 +116,10 @@ static int __init snd_card_virmidi_probe(int dev)
strcpy(card->shortname, "VirMIDI");
sprintf(card->longname, "Virtual MIDI Card %i", dev + 1);
if ((err = snd_card_set_generic_dev(card)) < 0)
goto __nodev;
snd_card_set_dev(card, &devptr->dev);
if ((err = snd_card_register(card)) == 0) {
snd_virmidi_cards[dev] = card;
platform_set_drvdata(devptr, card);
return 0;
}
__nodev:
@ -129,16 +127,38 @@ static int __init snd_card_virmidi_probe(int dev)
return err;
}
static int snd_virmidi_remove(struct platform_device *devptr)
{
snd_card_free(platform_get_drvdata(devptr));
platform_set_drvdata(devptr, NULL);
return 0;
}
#define SND_VIRMIDI_DRIVER "snd_virmidi"
static struct platform_driver snd_virmidi_driver = {
.probe = snd_virmidi_probe,
.remove = snd_virmidi_remove,
.driver = {
.name = SND_VIRMIDI_DRIVER
},
};
static int __init alsa_card_virmidi_init(void)
{
int dev, cards;
int i, cards, err;
for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
if (snd_card_virmidi_probe(dev) < 0) {
#ifdef MODULE
printk(KERN_ERR "Card-VirMIDI #%i not found or device busy\n", dev + 1);
#endif
break;
if ((err = platform_driver_register(&snd_virmidi_driver)) < 0)
return err;
cards = 0;
for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
struct platform_device *device;
device = platform_device_register_simple(SND_VIRMIDI_DRIVER,
i, NULL, 0);
if (IS_ERR(device)) {
err = PTR_ERR(device);
goto errout;
}
cards++;
}
@ -146,17 +166,19 @@ static int __init alsa_card_virmidi_init(void)
#ifdef MODULE
printk(KERN_ERR "Card-VirMIDI soundcard not found or device busy\n");
#endif
return -ENODEV;
err = -ENODEV;
goto errout;
}
return 0;
errout:
platform_driver_unregister(&snd_virmidi_driver);
return err;
}
static void __exit alsa_card_virmidi_exit(void)
{
int dev;
for (dev = 0; dev < SNDRV_CARDS; dev++)
snd_card_free(snd_virmidi_cards[dev]);
platform_driver_unregister(&snd_virmidi_driver);
}
module_init(alsa_card_virmidi_init)