summaryrefslogtreecommitdiff
path: root/sound/drivers/virmidi.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2005-11-17 16:03:26 +0100
committerJaroslav Kysela <perex@suse.cz>2006-01-03 12:27:13 +0100
commit3564fbb880f9a62ddbb81b7440c32e0e6619c52d (patch)
tree87689136136d719d0ada90638ee696a2679f6a53 /sound/drivers/virmidi.c
parent9caf6b5908e1e3b10478e9201ca1be809145253f (diff)
[ALSA] virmidi - Use platform_device
Modules: Generic drivers Rewrite the probe/remove code using platform_device. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/drivers/virmidi.c')
-rw-r--r--sound/drivers/virmidi.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c
index 0d2cc6ea73ee..a7b9241fff3c 100644
--- a/sound/drivers/virmidi.c
+++ b/sound/drivers/virmidi.c
@@ -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 __init alsa_card_virmidi_init(void)
+static int snd_virmidi_remove(struct platform_device *devptr)
{
- int dev, cards;
+ snd_card_free(platform_get_drvdata(devptr));
+ platform_set_drvdata(devptr, NULL);
+ return 0;
+}
- 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;
+#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 i, cards, err;
+
+ 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)