From: Takashi Iwai Date: Thu, 17 Nov 2005 15:03:26 +0000 (+0100) Subject: [ALSA] virmidi - Use platform_device X-Git-Tag: v2.6.16-rc1~474^2~22^2~3^2~144 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3564fbb880f9a62ddbb81b7440c32e0e6619c52d;p=linux-2.6 [ALSA] virmidi - Use platform_device Modules: Generic drivers Rewrite the probe/remove code using platform_device. Signed-off-by: Takashi Iwai --- diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c index 0d2cc6ea73..a7b9241fff 100644 --- a/sound/drivers/virmidi.c +++ b/sound/drivers/virmidi.c @@ -45,6 +45,8 @@ #include #include #include +#include +#include #include #include #include @@ -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)