Version:  2.0.40 2.2.26 2.4.37 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17

Linux/sound/drivers/mpu401/mpu401.c

  1 /*
  2  *  Driver for generic MPU-401 boards (UART mode only)
  3  *  Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/init.h>
 24 #include <linux/pnp.h>
 25 #include <linux/err.h>
 26 #include <linux/platform_device.h>
 27 #include <linux/module.h>
 28 #include <sound/core.h>
 29 #include <sound/mpu401.h>
 30 #include <sound/initval.h>
 31 
 32 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 33 MODULE_DESCRIPTION("MPU-401 UART");
 34 MODULE_LICENSE("GPL");
 35 
 36 static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* exclude the first card */
 37 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
 38 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
 39 #ifdef CONFIG_PNP
 40 static bool pnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
 41 #endif
 42 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;     /* MPU-401 port number */
 43 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;        /* MPU-401 IRQ */
 44 static bool uart_enter[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
 45 
 46 module_param_array(index, int, NULL, 0444);
 47 MODULE_PARM_DESC(index, "Index value for MPU-401 device.");
 48 module_param_array(id, charp, NULL, 0444);
 49 MODULE_PARM_DESC(id, "ID string for MPU-401 device.");
 50 module_param_array(enable, bool, NULL, 0444);
 51 MODULE_PARM_DESC(enable, "Enable MPU-401 device.");
 52 #ifdef CONFIG_PNP
 53 module_param_array(pnp, bool, NULL, 0444);
 54 MODULE_PARM_DESC(pnp, "PnP detection for MPU-401 device.");
 55 #endif
 56 module_param_array(port, long, NULL, 0444);
 57 MODULE_PARM_DESC(port, "Port # for MPU-401 device.");
 58 module_param_array(irq, int, NULL, 0444);
 59 MODULE_PARM_DESC(irq, "IRQ # for MPU-401 device.");
 60 module_param_array(uart_enter, bool, NULL, 0444);
 61 MODULE_PARM_DESC(uart_enter, "Issue UART_ENTER command at open.");
 62 
 63 static struct platform_device *platform_devices[SNDRV_CARDS];
 64 static int pnp_registered;
 65 static unsigned int snd_mpu401_devices;
 66 
 67 static int snd_mpu401_create(struct device *devptr, int dev,
 68                              struct snd_card **rcard)
 69 {
 70         struct snd_card *card;
 71         int err;
 72 
 73         if (!uart_enter[dev])
 74                 snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n");
 75 
 76         *rcard = NULL;
 77         err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
 78                            0, &card);
 79         if (err < 0)
 80                 return err;
 81         strcpy(card->driver, "MPU-401 UART");
 82         strcpy(card->shortname, card->driver);
 83         sprintf(card->longname, "%s at %#lx, ", card->shortname, port[dev]);
 84         if (irq[dev] >= 0) {
 85                 sprintf(card->longname + strlen(card->longname), "irq %d", irq[dev]);
 86         } else {
 87                 strcat(card->longname, "polled");
 88         }
 89 
 90         err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0,
 91                                   irq[dev], NULL);
 92         if (err < 0) {
 93                 printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
 94                 goto _err;
 95         }
 96 
 97         *rcard = card;
 98         return 0;
 99 
100  _err:
101         snd_card_free(card);
102         return err;
103 }
104 
105 static int snd_mpu401_probe(struct platform_device *devptr)
106 {
107         int dev = devptr->id;
108         int err;
109         struct snd_card *card;
110 
111         if (port[dev] == SNDRV_AUTO_PORT) {
112                 snd_printk(KERN_ERR "specify port\n");
113                 return -EINVAL;
114         }
115         if (irq[dev] == SNDRV_AUTO_IRQ) {
116                 snd_printk(KERN_ERR "specify or disable IRQ\n");
117                 return -EINVAL;
118         }
119         err = snd_mpu401_create(&devptr->dev, dev, &card);
120         if (err < 0)
121                 return err;
122         if ((err = snd_card_register(card)) < 0) {
123                 snd_card_free(card);
124                 return err;
125         }
126         platform_set_drvdata(devptr, card);
127         return 0;
128 }
129 
130 static int snd_mpu401_remove(struct platform_device *devptr)
131 {
132         snd_card_free(platform_get_drvdata(devptr));
133         return 0;
134 }
135 
136 #define SND_MPU401_DRIVER       "snd_mpu401"
137 
138 static struct platform_driver snd_mpu401_driver = {
139         .probe          = snd_mpu401_probe,
140         .remove         = snd_mpu401_remove,
141         .driver         = {
142                 .name   = SND_MPU401_DRIVER,
143                 .owner  = THIS_MODULE,
144         },
145 };
146 
147 
148 #ifdef CONFIG_PNP
149 
150 #define IO_EXTENT 2
151 
152 static struct pnp_device_id snd_mpu401_pnpids[] = {
153         { .id = "PNPb006" },
154         { .id = "" }
155 };
156 
157 MODULE_DEVICE_TABLE(pnp, snd_mpu401_pnpids);
158 
159 static int snd_mpu401_pnp(int dev, struct pnp_dev *device,
160                           const struct pnp_device_id *id)
161 {
162         if (!pnp_port_valid(device, 0) ||
163             pnp_port_flags(device, 0) & IORESOURCE_DISABLED) {
164                 snd_printk(KERN_ERR "no PnP port\n");
165                 return -ENODEV;
166         }
167         if (pnp_port_len(device, 0) < IO_EXTENT) {
168                 snd_printk(KERN_ERR "PnP port length is %llu, expected %d\n",
169                            (unsigned long long)pnp_port_len(device, 0),
170                            IO_EXTENT);
171                 return -ENODEV;
172         }
173         port[dev] = pnp_port_start(device, 0);
174 
175         if (!pnp_irq_valid(device, 0) ||
176             pnp_irq_flags(device, 0) & IORESOURCE_DISABLED) {
177                 snd_printk(KERN_WARNING "no PnP irq, using polling\n");
178                 irq[dev] = -1;
179         } else {
180                 irq[dev] = pnp_irq(device, 0);
181         }
182         return 0;
183 }
184 
185 static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
186                                 const struct pnp_device_id *id)
187 {
188         static int dev;
189         struct snd_card *card;
190         int err;
191 
192         for ( ; dev < SNDRV_CARDS; ++dev) {
193                 if (!enable[dev] || !pnp[dev])
194                         continue;
195                 err = snd_mpu401_pnp(dev, pnp_dev, id);
196                 if (err < 0)
197                         return err;
198                 err = snd_mpu401_create(&pnp_dev->dev, dev, &card);
199                 if (err < 0)
200                         return err;
201                 if ((err = snd_card_register(card)) < 0) {
202                         snd_card_free(card);
203                         return err;
204                 }
205                 pnp_set_drvdata(pnp_dev, card);
206                 snd_mpu401_devices++;
207                 ++dev;
208                 return 0;
209         }
210         return -ENODEV;
211 }
212 
213 static void snd_mpu401_pnp_remove(struct pnp_dev *dev)
214 {
215         struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev);
216 
217         snd_card_disconnect(card);
218         snd_card_free_when_closed(card);
219 }
220 
221 static struct pnp_driver snd_mpu401_pnp_driver = {
222         .name = "mpu401",
223         .id_table = snd_mpu401_pnpids,
224         .probe = snd_mpu401_pnp_probe,
225         .remove = snd_mpu401_pnp_remove,
226 };
227 #else
228 static struct pnp_driver snd_mpu401_pnp_driver;
229 #endif
230 
231 static void 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 
242 static int __init alsa_card_mpu401_init(void)
243 {
244         int i, err;
245 
246         if ((err = platform_driver_register(&snd_mpu401_driver)) < 0)
247                 return err;
248 
249         for (i = 0; i < SNDRV_CARDS; i++) {
250                 struct platform_device *device;
251                 if (! enable[i])
252                         continue;
253 #ifdef CONFIG_PNP
254                 if (pnp[i])
255                         continue;
256 #endif
257                 device = platform_device_register_simple(SND_MPU401_DRIVER,
258                                                          i, NULL, 0);
259                 if (IS_ERR(device))
260                         continue;
261                 if (!platform_get_drvdata(device)) {
262                         platform_device_unregister(device);
263                         continue;
264                 }
265                 platform_devices[i] = device;
266                 snd_mpu401_devices++;
267         }
268         err = pnp_register_driver(&snd_mpu401_pnp_driver);
269         if (!err)
270                 pnp_registered = 1;
271 
272         if (!snd_mpu401_devices) {
273 #ifdef MODULE
274                 printk(KERN_ERR "MPU-401 device not found or device busy\n");
275 #endif
276                 snd_mpu401_unregister_all();
277                 return -ENODEV;
278         }
279         return 0;
280 }
281 
282 static void __exit alsa_card_mpu401_exit(void)
283 {
284         snd_mpu401_unregister_all();
285 }
286 
287 module_init(alsa_card_mpu401_init)
288 module_exit(alsa_card_mpu401_exit)
289 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us