aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2005-11-17 10:03:39 -0500
committerJaroslav Kysela <perex@suse.cz>2006-01-03 06:27:14 -0500
commitb3fe95123f0db79dd0345d249c312823178c11f5 (patch)
treec7c3b6c2270bbe4e4fe83a348e8603ae52df07c4
parent3564fbb880f9a62ddbb81b7440c32e0e6619c52d (diff)
[ALSA] mpu401 - Use platform_device
Modules: MPU401 UART Rewrite the probe/remove code using platform_device. Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/drivers/mpu401/mpu401.c87
1 files changed, 63 insertions, 24 deletions
diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c
index b1242ee937d9..ec817a86d3dd 100644
--- a/sound/drivers/mpu401/mpu401.c
+++ b/sound/drivers/mpu401/mpu401.c
@@ -23,6 +23,8 @@
23#include <sound/driver.h> 23#include <sound/driver.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/pnp.h> 25#include <linux/pnp.h>
26#include <linux/err.h>
27#include <linux/platform_device.h>
26#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
27#include <sound/core.h> 29#include <sound/core.h>
28#include <sound/mpu401.h> 30#include <sound/mpu401.h>
@@ -56,7 +58,6 @@ MODULE_PARM_DESC(port, "Port # for MPU-401 device.");
56module_param_array(irq, int, NULL, 0444); 58module_param_array(irq, int, NULL, 0444);
57MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device."); 59MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device.");
58 60
59static struct snd_card *snd_mpu401_legacy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
60static int pnp_registered = 0; 61static int pnp_registered = 0;
61 62
62static int snd_mpu401_create(int dev, struct snd_card **rcard) 63static int snd_mpu401_create(int dev, struct snd_card **rcard)
@@ -85,12 +86,6 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard)
85 goto _err; 86 goto _err;
86 } 87 }
87 88
88 if ((err = snd_card_set_generic_dev(card)) < 0)
89 goto _err;
90
91 if ((err = snd_card_register(card)) < 0)
92 goto _err;
93
94 *rcard = card; 89 *rcard = card;
95 return 0; 90 return 0;
96 91
@@ -99,8 +94,12 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard)
99 return err; 94 return err;
100} 95}
101 96
102static int __devinit snd_mpu401_probe(int dev) 97static int __devinit snd_mpu401_probe(struct platform_device *devptr)
103{ 98{
99 int dev = devptr->id;
100 int err;
101 struct snd_card *card;
102
104 if (port[dev] == SNDRV_AUTO_PORT) { 103 if (port[dev] == SNDRV_AUTO_PORT) {
105 snd_printk(KERN_ERR "specify port\n"); 104 snd_printk(KERN_ERR "specify port\n");
106 return -EINVAL; 105 return -EINVAL;
@@ -109,9 +108,36 @@ static int __devinit snd_mpu401_probe(int dev)
109 snd_printk(KERN_ERR "specify or disable IRQ\n"); 108 snd_printk(KERN_ERR "specify or disable IRQ\n");
110 return -EINVAL; 109 return -EINVAL;
111 } 110 }
112 return snd_mpu401_create(dev, &snd_mpu401_legacy_cards[dev]); 111 err = snd_mpu401_create(dev, &card);
112 if (err < 0)
113 return err;
114 snd_card_set_dev(card, &devptr->dev);
115 if ((err = snd_card_register(card)) < 0) {
116 snd_card_free(card);
117 return err;
118 }
119 platform_set_drvdata(devptr, card);
120 return 0;
113} 121}
114 122
123static int __devexit snd_mpu401_remove(struct platform_device *devptr)
124{
125 snd_card_free(platform_get_drvdata(devptr));
126 platform_set_drvdata(devptr, NULL);
127 return 0;
128}
129
130#define SND_MPU401_DRIVER "snd_mpu401"
131
132static struct platform_driver snd_mpu401_driver = {
133 .probe = snd_mpu401_probe,
134 .remove = __devexit_p(snd_mpu401_remove),
135 .driver = {
136 .name = SND_MPU401_DRIVER
137 },
138};
139
140
115#ifdef CONFIG_PNP 141#ifdef CONFIG_PNP
116 142
117#define IO_EXTENT 2 143#define IO_EXTENT 2
@@ -164,6 +190,10 @@ static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
164 err = snd_mpu401_create(dev, &card); 190 err = snd_mpu401_create(dev, &card);
165 if (err < 0) 191 if (err < 0)
166 return err; 192 return err;
193 if ((err = snd_card_register(card)) < 0) {
194 snd_card_free(card);
195 return err;
196 }
167 snd_card_set_dev(card, &pnp_dev->dev); 197 snd_card_set_dev(card, &pnp_dev->dev);
168 pnp_set_drvdata(pnp_dev, card); 198 pnp_set_drvdata(pnp_dev, card);
169 ++dev; 199 ++dev;
@@ -192,18 +222,25 @@ static struct pnp_driver snd_mpu401_pnp_driver;
192 222
193static int __init alsa_card_mpu401_init(void) 223static int __init alsa_card_mpu401_init(void)
194{ 224{
195 int dev, devices = 0; 225 int i, err, devices;
196 int err;
197 226
198 for (dev = 0; dev < SNDRV_CARDS; dev++) { 227 if ((err = platform_driver_register(&snd_mpu401_driver)) < 0)
199 if (!enable[dev]) 228 return err;
200 continue; 229
230 devices = 0;
231 for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
232 struct platform_device *device;
201#ifdef CONFIG_PNP 233#ifdef CONFIG_PNP
202 if (pnp[dev]) 234 if (pnp[i])
203 continue; 235 continue;
204#endif 236#endif
205 if (snd_mpu401_probe(dev) >= 0) 237 device = platform_device_register_simple(SND_MPU401_DRIVER,
206 devices++; 238 i, NULL, 0);
239 if (IS_ERR(device)) {
240 err = PTR_ERR(device);
241 goto errout;
242 }
243 devices++;
207 } 244 }
208 if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) { 245 if ((err = pnp_register_driver(&snd_mpu401_pnp_driver)) >= 0) {
209 pnp_registered = 1; 246 pnp_registered = 1;
@@ -214,21 +251,23 @@ static int __init alsa_card_mpu401_init(void)
214#ifdef MODULE 251#ifdef MODULE
215 printk(KERN_ERR "MPU-401 device not found or device busy\n"); 252 printk(KERN_ERR "MPU-401 device not found or device busy\n");
216#endif 253#endif
217 if (pnp_registered) 254 err = -ENODEV;
218 pnp_unregister_driver(&snd_mpu401_pnp_driver); 255 goto errout;
219 return -ENODEV;
220 } 256 }
221 return 0; 257 return 0;
258
259 errout:
260 if (pnp_registered)
261 pnp_unregister_driver(&snd_mpu401_pnp_driver);
262 platform_driver_unregister(&snd_mpu401_driver);
263 return err;
222} 264}
223 265
224static void __exit alsa_card_mpu401_exit(void) 266static void __exit alsa_card_mpu401_exit(void)
225{ 267{
226 int idx;
227
228 if (pnp_registered) 268 if (pnp_registered)
229 pnp_unregister_driver(&snd_mpu401_pnp_driver); 269 pnp_unregister_driver(&snd_mpu401_pnp_driver);
230 for (idx = 0; idx < SNDRV_CARDS; idx++) 270 platform_driver_unregister(&snd_mpu401_driver);
231 snd_card_free(snd_mpu401_legacy_cards[idx]);
232} 271}
233 272
234module_init(alsa_card_mpu401_init) 273module_init(alsa_card_mpu401_init)