]> bbs.cooldavid.org Git - net-next-2.6.git/blame - sound/drivers/mpu401/mpu401.c
[ALSA] fix section mismatch
[net-next-2.6.git] / sound / drivers / mpu401 / mpu401.c
CommitLineData
1da177e4
LT
1/*
2 * Driver for generic MPU-401 boards (UART mode only)
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Copyright (c) 2004 by Castet Matthieu <castet.matthieu@free.fr>
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include <sound/driver.h>
24#include <linux/init.h>
25#include <linux/pnp.h>
b3fe9512
TI
26#include <linux/err.h>
27#include <linux/platform_device.h>
1da177e4
LT
28#include <linux/moduleparam.h>
29#include <sound/core.h>
30#include <sound/mpu401.h>
31#include <sound/initval.h>
32
33MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
34MODULE_DESCRIPTION("MPU-401 UART");
35MODULE_LICENSE("GPL");
36
37static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* exclude the first card */
38static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
39static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
40#ifdef CONFIG_PNP
41static int pnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
42#endif
43static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* MPU-401 port number */
44static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* MPU-401 IRQ */
8f7ba051 45static int uart_enter[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
1da177e4
LT
46
47module_param_array(index, int, NULL, 0444);
48MODULE_PARM_DESC(index, "Index value for MPU-401 device.");
49module_param_array(id, charp, NULL, 0444);
50MODULE_PARM_DESC(id, "ID string for MPU-401 device.");
51module_param_array(enable, bool, NULL, 0444);
52MODULE_PARM_DESC(enable, "Enable MPU-401 device.");
53#ifdef CONFIG_PNP
54module_param_array(pnp, bool, NULL, 0444);
55MODULE_PARM_DESC(pnp, "PnP detection for MPU-401 device.");
56#endif
57module_param_array(port, long, NULL, 0444);
58MODULE_PARM_DESC(port, "Port # for MPU-401 device.");
59module_param_array(irq, int, NULL, 0444);
60MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device.");
8f7ba051
TI
61module_param_array(uart_enter, bool, NULL, 0444);
62MODULE_PARM_DESC(uart_enter, "Issue UART_ENTER command at open.");
1da177e4 63
f7a9275d 64static struct platform_device *platform_devices[SNDRV_CARDS];
f301ae6a
BH
65static int pnp_registered;
66static unsigned int snd_mpu401_devices;
1da177e4 67
e1fad17b 68static int snd_mpu401_create(int dev, struct snd_card **rcard)
1da177e4 69{
e1fad17b 70 struct snd_card *card;
1da177e4
LT
71 int err;
72
73 *rcard = NULL;
74 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
75 if (card == NULL)
76 return -ENOMEM;
77 strcpy(card->driver, "MPU-401 UART");
78 strcpy(card->shortname, card->driver);
79 sprintf(card->longname, "%s at %#lx, ", card->shortname, port[dev]);
80 if (irq[dev] >= 0) {
81 sprintf(card->longname + strlen(card->longname), "irq %d", irq[dev]);
82 } else {
83 strcat(card->longname, "polled");
84 }
85
8f7ba051
TI
86 err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev],
87 uart_enter[dev] ? 0 : MPU401_INFO_UART_ONLY,
88 irq[dev], irq[dev] >= 0 ? IRQF_DISABLED : 0,
89 NULL);
90 if (err < 0) {
1da177e4 91 printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
16dab54b 92 goto _err;
1da177e4 93 }
16dab54b 94
1da177e4
LT
95 *rcard = card;
96 return 0;
16dab54b
TI
97
98 _err:
99 snd_card_free(card);
100 return err;
1da177e4
LT
101}
102
b3fe9512 103static int __devinit snd_mpu401_probe(struct platform_device *devptr)
1da177e4 104{
b3fe9512
TI
105 int dev = devptr->id;
106 int err;
107 struct snd_card *card;
108
1da177e4
LT
109 if (port[dev] == SNDRV_AUTO_PORT) {
110 snd_printk(KERN_ERR "specify port\n");
111 return -EINVAL;
112 }
113 if (irq[dev] == SNDRV_AUTO_IRQ) {
114 snd_printk(KERN_ERR "specify or disable IRQ\n");
115 return -EINVAL;
116 }
b3fe9512
TI
117 err = snd_mpu401_create(dev, &card);
118 if (err < 0)
119 return err;
120 snd_card_set_dev(card, &devptr->dev);
121 if ((err = snd_card_register(card)) < 0) {
122 snd_card_free(card);
123 return err;
124 }
125 platform_set_drvdata(devptr, card);
126 return 0;
1da177e4
LT
127}
128
b3fe9512
TI
129static int __devexit snd_mpu401_remove(struct platform_device *devptr)
130{
131 snd_card_free(platform_get_drvdata(devptr));
132 platform_set_drvdata(devptr, NULL);
133 return 0;
134}
135
136#define SND_MPU401_DRIVER "snd_mpu401"
137
138static struct platform_driver snd_mpu401_driver = {
139 .probe = snd_mpu401_probe,
140 .remove = __devexit_p(snd_mpu401_remove),
141 .driver = {
142 .name = SND_MPU401_DRIVER
143 },
144};
145
146
1da177e4
LT
147#ifdef CONFIG_PNP
148
149#define IO_EXTENT 2
150
151static struct pnp_device_id snd_mpu401_pnpids[] = {
152 { .id = "PNPb006" },
153 { .id = "" }
154};
155
156MODULE_DEVICE_TABLE(pnp, snd_mpu401_pnpids);
157
fad43488 158static int __devinit snd_mpu401_pnp(int dev, struct pnp_dev *device,
1da177e4
LT
159 const struct pnp_device_id *id)
160{
161 if (!pnp_port_valid(device, 0) ||
162 pnp_port_flags(device, 0) & IORESOURCE_DISABLED) {
163 snd_printk(KERN_ERR "no PnP port\n");
164 return -ENODEV;
165 }
166 if (pnp_port_len(device, 0) < IO_EXTENT) {
aa0a2ddc
GKH
167 snd_printk(KERN_ERR "PnP port length is %llu, expected %d\n",
168 (unsigned long long)pnp_port_len(device, 0),
169 IO_EXTENT);
1da177e4
LT
170 return -ENODEV;
171 }
172 port[dev] = pnp_port_start(device, 0);
173
174 if (!pnp_irq_valid(device, 0) ||
175 pnp_irq_flags(device, 0) & IORESOURCE_DISABLED) {
176 snd_printk(KERN_WARNING "no PnP irq, using polling\n");
177 irq[dev] = -1;
178 } else {
179 irq[dev] = pnp_irq(device, 0);
180 }
181 return 0;
182}
183
184static int __devinit snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
185 const struct pnp_device_id *id)
186{
187 static int dev;
e1fad17b 188 struct snd_card *card;
1da177e4
LT
189 int err;
190
191 for ( ; dev < SNDRV_CARDS; ++dev) {
192 if (!enable[dev] || !pnp[dev])
193 continue;
194 err = snd_mpu401_pnp(dev, pnp_dev, id);
195 if (err < 0)
196 return err;
197 err = snd_mpu401_create(dev, &card);
198 if (err < 0)
199 return err;
b3fe9512
TI
200 if ((err = snd_card_register(card)) < 0) {
201 snd_card_free(card);
202 return err;
203 }
1da177e4
LT
204 snd_card_set_dev(card, &pnp_dev->dev);
205 pnp_set_drvdata(pnp_dev, card);
f301ae6a 206 snd_mpu401_devices++;
1da177e4
LT
207 ++dev;
208 return 0;
209 }
210 return -ENODEV;
211}
212
213static void __devexit snd_mpu401_pnp_remove(struct pnp_dev *dev)
214{
e1fad17b 215 struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev);
1da177e4
LT
216
217 snd_card_disconnect(card);
2b29b13c 218 snd_card_free_when_closed(card);
1da177e4
LT
219}
220
221static struct pnp_driver snd_mpu401_pnp_driver = {
222 .name = "mpu401",
223 .id_table = snd_mpu401_pnpids,
224 .probe = snd_mpu401_pnp_probe,
225 .remove = __devexit_p(snd_mpu401_pnp_remove),
226};
227#else
228static struct pnp_driver snd_mpu401_pnp_driver;
229#endif
230
f7a9275d
CL
231static void __init_or_module snd_mpu401_unregister_all(void)
232{
233 int i;
234
235 if (pnp_registered)
236 pnp_unregister_driver(&snd_mpu401_pnp_driver);
237 for (i = 0; i < ARRAY_SIZE(platform_devices); ++i)
238 platform_device_unregister(platform_devices[i]);
239 platform_driver_unregister(&snd_mpu401_driver);
240}
241
1da177e4
LT
242static int __init alsa_card_mpu401_init(void)
243{
f301ae6a 244 int i, err;
1da177e4 245
b3fe9512
TI
246 if ((err = platform_driver_register(&snd_mpu401_driver)) < 0)
247 return err;
248
8278ca8f 249 for (i = 0; i < SNDRV_CARDS; i++) {
b3fe9512 250 struct platform_device *device;
8278ca8f
TI
251 if (! enable[i])
252 continue;
1da177e4 253#ifdef CONFIG_PNP
b3fe9512 254 if (pnp[i])
1da177e4
LT
255 continue;
256#endif
b3fe9512
TI
257 device = platform_device_register_simple(SND_MPU401_DRIVER,
258 i, NULL, 0);
a182ee98
RH
259 if (IS_ERR(device))
260 continue;
7152447d
RH
261 if (!platform_get_drvdata(device)) {
262 platform_device_unregister(device);
263 continue;
264 }
f7a9275d 265 platform_devices[i] = device;
f301ae6a 266 snd_mpu401_devices++;
1da177e4 267 }
f301ae6a
BH
268 err = pnp_register_driver(&snd_mpu401_pnp_driver);
269 if (!err)
1da177e4 270 pnp_registered = 1;
1da177e4 271
f301ae6a 272 if (!snd_mpu401_devices) {
1da177e4
LT
273#ifdef MODULE
274 printk(KERN_ERR "MPU-401 device not found or device busy\n");
275#endif
a182ee98
RH
276 snd_mpu401_unregister_all();
277 return -ENODEV;
1da177e4
LT
278 }
279 return 0;
280}
281
282static void __exit alsa_card_mpu401_exit(void)
283{
f7a9275d 284 snd_mpu401_unregister_all();
1da177e4
LT
285}
286
287module_init(alsa_card_mpu401_init)
288module_exit(alsa_card_mpu401_exit)