Merge branches 'core/debug', 'core/futexes', 'core/locking', 'core/rcu', 'core/signal...
[linux-2.6] / sound / isa / ad1816a / ad1816a.c
1
2 /*
3     card-ad1816a.c - driver for ADI SoundPort AD1816A based soundcards.
4     Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 */
20
21 #include <linux/init.h>
22 #include <linux/time.h>
23 #include <linux/wait.h>
24 #include <linux/pnp.h>
25 #include <linux/moduleparam.h>
26 #include <sound/core.h>
27 #include <sound/initval.h>
28 #include <sound/ad1816a.h>
29 #include <sound/mpu401.h>
30 #include <sound/opl3.h>
31
32 #define PFX "ad1816a: "
33
34 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
35 MODULE_DESCRIPTION("AD1816A, AD1815");
36 MODULE_LICENSE("GPL");
37 MODULE_SUPPORTED_DEVICE("{{Highscreen,Sound-Boostar 16 3D},"
38                 "{Analog Devices,AD1815},"
39                 "{Analog Devices,AD1816A},"
40                 "{TerraTec,Base 64},"
41                 "{TerraTec,AudioSystem EWS64S},"
42                 "{Aztech/Newcom SC-16 3D},"
43                 "{Shark Predator ISA}}");
44
45 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 1-MAX */
46 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
47 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;   /* Enable this card */
48 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;     /* PnP setup */
49 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
50 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;  /* PnP setup */
51 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;        /* Pnp setup */
52 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;    /* Pnp setup */
53 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* PnP setup */
54 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* PnP setup */
55 static int clockfreq[SNDRV_CARDS];
56
57 module_param_array(index, int, NULL, 0444);
58 MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard.");
59 module_param_array(id, charp, NULL, 0444);
60 MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard.");
61 module_param_array(enable, bool, NULL, 0444);
62 MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard.");
63 module_param_array(clockfreq, int, NULL, 0444);
64 MODULE_PARM_DESC(clockfreq, "Clock frequency for ad1816a driver (default = 0).");
65
66 struct snd_card_ad1816a {
67         struct pnp_dev *dev;
68         struct pnp_dev *devmpu;
69 };
70
71 static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
72         /* Analog Devices AD1815 */
73         { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
74         /* Analog Device AD1816? */
75         { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
76         /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
77         { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
78         /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
79         { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
80         /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
81         { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
82         /* Highscreen Sound-Boostar 16 3D */
83         { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
84         /* Shark Predator ISA - added by Ken Arromdee */
85         { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
86         /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
87         { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
88         /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
89         { .id = "TER1112", .devs = { { .id = "TER1100" }, { .id = "TER1101" } } },
90         /* Analog Devices AD1816A - Terratec Base 64 */
91         { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
92         /* end */
93         { .id = "" }
94 };
95
96 MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
97
98
99 #define DRIVER_NAME     "snd-card-ad1816a"
100
101
102 static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard,
103                                           struct pnp_card_link *card,
104                                           const struct pnp_card_device_id *id)
105 {
106         struct pnp_dev *pdev;
107         int err;
108
109         acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
110         if (acard->dev == NULL)
111                 return -EBUSY;
112
113         acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
114         if (acard->devmpu == NULL) {
115                 mpu_port[dev] = -1;
116                 snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n");
117         }
118
119         pdev = acard->dev;
120
121         err = pnp_activate_dev(pdev);
122         if (err < 0) {
123                 printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
124                 return -EBUSY;
125         }
126
127         port[dev] = pnp_port_start(pdev, 2);
128         fm_port[dev] = pnp_port_start(pdev, 1);
129         dma1[dev] = pnp_dma(pdev, 0);
130         dma2[dev] = pnp_dma(pdev, 1);
131         irq[dev] = pnp_irq(pdev, 0);
132
133         if (acard->devmpu == NULL)
134                 return 0;
135
136         pdev = acard->devmpu;
137
138         err = pnp_activate_dev(pdev);
139         if (err < 0) {
140                 printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
141                 mpu_port[dev] = -1;
142                 acard->devmpu = NULL;
143         } else {
144                 mpu_port[dev] = pnp_port_start(pdev, 0);
145                 mpu_irq[dev] = pnp_irq(pdev, 0);
146         }
147
148         return 0;
149 }
150
151 static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
152                                             const struct pnp_card_device_id *pid)
153 {
154         int error;
155         struct snd_card *card;
156         struct snd_card_ad1816a *acard;
157         struct snd_ad1816a *chip;
158         struct snd_opl3 *opl3;
159
160         if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
161                                  sizeof(struct snd_card_ad1816a))) == NULL)
162                 return -ENOMEM;
163         acard = (struct snd_card_ad1816a *)card->private_data;
164
165         if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
166                 snd_card_free(card);
167                 return error;
168         }
169         snd_card_set_dev(card, &pcard->card->dev);
170
171         if ((error = snd_ad1816a_create(card, port[dev],
172                                         irq[dev],
173                                         dma1[dev],
174                                         dma2[dev],
175                                         &chip)) < 0) {
176                 snd_card_free(card);
177                 return error;
178         }
179         if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
180                 chip->clock_freq = clockfreq[dev];
181
182         strcpy(card->driver, "AD1816A");
183         strcpy(card->shortname, "ADI SoundPort AD1816A");
184         sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
185                 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
186
187         if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
188                 snd_card_free(card);
189                 return error;
190         }
191
192         if ((error = snd_ad1816a_mixer(chip)) < 0) {
193                 snd_card_free(card);
194                 return error;
195         }
196
197         if (mpu_port[dev] > 0) {
198                 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
199                                         mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED,
200                                         NULL) < 0)
201                         printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
202         }
203
204         if (fm_port[dev] > 0) {
205                 if (snd_opl3_create(card,
206                                     fm_port[dev], fm_port[dev] + 2,
207                                     OPL3_HW_AUTO, 0, &opl3) < 0) {
208                         printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
209                 } else {
210                         if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
211                                 snd_card_free(card);
212                                 return error;
213                         }
214                         if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
215                                 snd_card_free(card);
216                                 return error;
217                         }
218                 }
219         }
220
221         if ((error = snd_card_register(card)) < 0) {
222                 snd_card_free(card);
223                 return error;
224         }
225         pnp_set_card_drvdata(pcard, card);
226         return 0;
227 }
228
229 static unsigned int __devinitdata ad1816a_devices;
230
231 static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
232                                             const struct pnp_card_device_id *id)
233 {
234         static int dev;
235         int res;
236
237         for ( ; dev < SNDRV_CARDS; dev++) {
238                 if (!enable[dev])
239                         continue;
240                 res = snd_card_ad1816a_probe(dev, card, id);
241                 if (res < 0)
242                         return res;
243                 dev++;
244                 ad1816a_devices++;
245                 return 0;
246         }
247         return -ENODEV;
248 }
249
250 static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
251 {
252         snd_card_free(pnp_get_card_drvdata(pcard));
253         pnp_set_card_drvdata(pcard, NULL);
254 }
255
256 static struct pnp_card_driver ad1816a_pnpc_driver = {
257         .flags          = PNP_DRIVER_RES_DISABLE,
258         .name           = "ad1816a",
259         .id_table       = snd_ad1816a_pnpids,
260         .probe          = snd_ad1816a_pnp_detect,
261         .remove         = __devexit_p(snd_ad1816a_pnp_remove),
262         /* FIXME: suspend/resume */
263 };
264
265 static int __init alsa_card_ad1816a_init(void)
266 {
267         int err;
268
269         err = pnp_register_card_driver(&ad1816a_pnpc_driver);
270         if (err)
271                 return err;
272
273         if (!ad1816a_devices) {
274                 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
275 #ifdef MODULE
276                 printk(KERN_ERR "no AD1816A based soundcards found.\n");
277 #endif  /* MODULE */
278                 return -ENODEV;
279         }
280         return 0;
281 }
282
283 static void __exit alsa_card_ad1816a_exit(void)
284 {
285         pnp_unregister_card_driver(&ad1816a_pnpc_driver);
286 }
287
288 module_init(alsa_card_ad1816a_init)
289 module_exit(alsa_card_ad1816a_exit)