diff options
author | Takashi Iwai <tiwai@suse.de> | 2005-11-17 10:03:26 -0500 |
---|---|---|
committer | Jaroslav Kysela <perex@suse.cz> | 2006-01-03 06:27:13 -0500 |
commit | 3564fbb880f9a62ddbb81b7440c32e0e6619c52d (patch) | |
tree | 87689136136d719d0ada90638ee696a2679f6a53 | |
parent | 9caf6b5908e1e3b10478e9201ca1be809145253f (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>
-rw-r--r-- | sound/drivers/virmidi.c | 64 |
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 @@ | |||
45 | #include <linux/init.h> | 45 | #include <linux/init.h> |
46 | #include <linux/wait.h> | 46 | #include <linux/wait.h> |
47 | #include <linux/sched.h> | 47 | #include <linux/sched.h> |
48 | #include <linux/err.h> | ||
49 | #include <linux/platform_device.h> | ||
48 | #include <linux/moduleparam.h> | 50 | #include <linux/moduleparam.h> |
49 | #include <sound/core.h> | 51 | #include <sound/core.h> |
50 | #include <sound/seq_kernel.h> | 52 | #include <sound/seq_kernel.h> |
@@ -80,17 +82,14 @@ struct snd_card_virmidi { | |||
80 | struct snd_rawmidi *midi[MAX_MIDI_DEVICES]; | 82 | struct snd_rawmidi *midi[MAX_MIDI_DEVICES]; |
81 | }; | 83 | }; |
82 | 84 | ||
83 | static struct snd_card *snd_virmidi_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; | ||
84 | 85 | ||
85 | 86 | static int __init snd_virmidi_probe(struct platform_device *devptr) | |
86 | static int __init snd_card_virmidi_probe(int dev) | ||
87 | { | 87 | { |
88 | struct snd_card *card; | 88 | struct snd_card *card; |
89 | struct snd_card_virmidi *vmidi; | 89 | struct snd_card_virmidi *vmidi; |
90 | int idx, err; | 90 | int idx, err; |
91 | int dev = devptr->id; | ||
91 | 92 | ||
92 | if (!enable[dev]) | ||
93 | return -ENODEV; | ||
94 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, | 93 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
95 | sizeof(struct snd_card_virmidi)); | 94 | sizeof(struct snd_card_virmidi)); |
96 | if (card == NULL) | 95 | if (card == NULL) |
@@ -117,11 +116,10 @@ static int __init snd_card_virmidi_probe(int dev) | |||
117 | strcpy(card->shortname, "VirMIDI"); | 116 | strcpy(card->shortname, "VirMIDI"); |
118 | sprintf(card->longname, "Virtual MIDI Card %i", dev + 1); | 117 | sprintf(card->longname, "Virtual MIDI Card %i", dev + 1); |
119 | 118 | ||
120 | if ((err = snd_card_set_generic_dev(card)) < 0) | 119 | snd_card_set_dev(card, &devptr->dev); |
121 | goto __nodev; | ||
122 | 120 | ||
123 | if ((err = snd_card_register(card)) == 0) { | 121 | if ((err = snd_card_register(card)) == 0) { |
124 | snd_virmidi_cards[dev] = card; | 122 | platform_set_drvdata(devptr, card); |
125 | return 0; | 123 | return 0; |
126 | } | 124 | } |
127 | __nodev: | 125 | __nodev: |
@@ -129,16 +127,38 @@ static int __init snd_card_virmidi_probe(int dev) | |||
129 | return err; | 127 | return err; |
130 | } | 128 | } |
131 | 129 | ||
132 | static int __init alsa_card_virmidi_init(void) | 130 | static int snd_virmidi_remove(struct platform_device *devptr) |
133 | { | 131 | { |
134 | int dev, cards; | 132 | snd_card_free(platform_get_drvdata(devptr)); |
133 | platform_set_drvdata(devptr, NULL); | ||
134 | return 0; | ||
135 | } | ||
135 | 136 | ||
136 | for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) { | 137 | #define SND_VIRMIDI_DRIVER "snd_virmidi" |
137 | if (snd_card_virmidi_probe(dev) < 0) { | 138 | |
138 | #ifdef MODULE | 139 | static struct platform_driver snd_virmidi_driver = { |
139 | printk(KERN_ERR "Card-VirMIDI #%i not found or device busy\n", dev + 1); | 140 | .probe = snd_virmidi_probe, |
140 | #endif | 141 | .remove = snd_virmidi_remove, |
141 | break; | 142 | .driver = { |
143 | .name = SND_VIRMIDI_DRIVER | ||
144 | }, | ||
145 | }; | ||
146 | |||
147 | static int __init alsa_card_virmidi_init(void) | ||
148 | { | ||
149 | int i, cards, err; | ||
150 | |||
151 | if ((err = platform_driver_register(&snd_virmidi_driver)) < 0) | ||
152 | return err; | ||
153 | |||
154 | cards = 0; | ||
155 | for (i = 0; i < SNDRV_CARDS && enable[i]; i++) { | ||
156 | struct platform_device *device; | ||
157 | device = platform_device_register_simple(SND_VIRMIDI_DRIVER, | ||
158 | i, NULL, 0); | ||
159 | if (IS_ERR(device)) { | ||
160 | err = PTR_ERR(device); | ||
161 | goto errout; | ||
142 | } | 162 | } |
143 | cards++; | 163 | cards++; |
144 | } | 164 | } |
@@ -146,17 +166,19 @@ static int __init alsa_card_virmidi_init(void) | |||
146 | #ifdef MODULE | 166 | #ifdef MODULE |
147 | printk(KERN_ERR "Card-VirMIDI soundcard not found or device busy\n"); | 167 | printk(KERN_ERR "Card-VirMIDI soundcard not found or device busy\n"); |
148 | #endif | 168 | #endif |
149 | return -ENODEV; | 169 | err = -ENODEV; |
170 | goto errout; | ||
150 | } | 171 | } |
151 | return 0; | 172 | return 0; |
173 | |||
174 | errout: | ||
175 | platform_driver_unregister(&snd_virmidi_driver); | ||
176 | return err; | ||
152 | } | 177 | } |
153 | 178 | ||
154 | static void __exit alsa_card_virmidi_exit(void) | 179 | static void __exit alsa_card_virmidi_exit(void) |
155 | { | 180 | { |
156 | int dev; | 181 | platform_driver_unregister(&snd_virmidi_driver); |
157 | |||
158 | for (dev = 0; dev < SNDRV_CARDS; dev++) | ||
159 | snd_card_free(snd_virmidi_cards[dev]); | ||
160 | } | 182 | } |
161 | 183 | ||
162 | module_init(alsa_card_virmidi_init) | 184 | module_init(alsa_card_virmidi_init) |