blob: 563296d028941b53e211956fff89b54459640dce [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
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 <sound/driver.h>
22#include <linux/init.h>
23#include <linux/time.h>
24#include <linux/wait.h>
25#include <linux/pnp.h>
26#include <linux/moduleparam.h>
27#include <sound/core.h>
28#include <sound/initval.h>
29#include <sound/ad1816a.h>
30#include <sound/mpu401.h>
31#include <sound/opl3.h>
32
33#define PFX "ad1816a: "
34
35MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
36MODULE_DESCRIPTION("AD1816A, AD1815");
37MODULE_LICENSE("GPL");
38MODULE_SUPPORTED_DEVICE("{{Highscreen,Sound-Boostar 16 3D},"
39 "{Analog Devices,AD1815},"
40 "{Analog Devices,AD1816A},"
41 "{TerraTec,Base 64},"
42 "{TerraTec,AudioSystem EWS64S},"
43 "{Aztech/Newcom SC-16 3D},"
44 "{Shark Predator ISA}}");
45
46static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */
47static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
48static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
49static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
50static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
51static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
52static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
53static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
54static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
55static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
56
57module_param_array(index, int, NULL, 0444);
58MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard.");
59module_param_array(id, charp, NULL, 0444);
60MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard.");
61module_param_array(enable, bool, NULL, 0444);
62MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard.");
63module_param_array(port, long, NULL, 0444);
64MODULE_PARM_DESC(port, "Port # for ad1816a driver.");
65module_param_array(mpu_port, long, NULL, 0444);
66MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ad1816a driver.");
67module_param_array(fm_port, long, NULL, 0444);
68MODULE_PARM_DESC(fm_port, "FM port # for ad1816a driver.");
69module_param_array(irq, int, NULL, 0444);
70MODULE_PARM_DESC(irq, "IRQ # for ad1816a driver.");
71module_param_array(mpu_irq, int, NULL, 0444);
72MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ad1816a driver.");
73module_param_array(dma1, int, NULL, 0444);
74MODULE_PARM_DESC(dma1, "1st DMA # for ad1816a driver.");
75module_param_array(dma2, int, NULL, 0444);
76MODULE_PARM_DESC(dma2, "2nd DMA # for ad1816a driver.");
77
78struct snd_card_ad1816a {
79 struct pnp_dev *dev;
80 struct pnp_dev *devmpu;
81};
82
83static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
84 /* Analog Devices AD1815 */
85 { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
Takashi Iwai92bb0102005-05-15 14:41:20 +020086 /* Analog Device AD1816? */
87 { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
89 { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
90 /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
91 { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
92 /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
93 { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
94 /* Highscreen Sound-Boostar 16 3D */
95 { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
96 /* Shark Predator ISA - added by Ken Arromdee */
97 { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
98 /* Analog Devices AD1816A - Terratec AudioSystem EWS64S */
99 { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
100 /* Analog Devices AD1816A - Terratec Base 64 */
101 { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
102 /* end */
103 { .id = "" }
104};
105
106MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
107
108
109#define DRIVER_NAME "snd-card-ad1816a"
110
111
112static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard,
113 struct pnp_card_link *card,
114 const struct pnp_card_device_id *id)
115{
116 struct pnp_dev *pdev;
117 struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
118 int err;
119
120 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
121 if (acard->dev == NULL) {
122 kfree(cfg);
123 return -EBUSY;
124 }
125 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
126 if (acard->devmpu == NULL) {
127 kfree(cfg);
128 return -EBUSY;
129 }
130
131 pdev = acard->dev;
132 pnp_init_resource_table(cfg);
133
134 if (port[dev] != SNDRV_AUTO_PORT)
135 pnp_resource_change(&cfg->port_resource[2], port[dev], 16);
136 if (fm_port[dev] != SNDRV_AUTO_PORT)
137 pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
138 if (dma1[dev] != SNDRV_AUTO_DMA)
139 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
140 if (dma2[dev] != SNDRV_AUTO_DMA)
141 pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
142 if (irq[dev] != SNDRV_AUTO_IRQ)
143 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
144
145 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
146 snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
147 err = pnp_activate_dev(pdev);
148 if (err < 0) {
149 printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
150 kfree(cfg);
151 return -EBUSY;
152 }
153
154 port[dev] = pnp_port_start(pdev, 2);
155 fm_port[dev] = pnp_port_start(pdev, 1);
156 dma1[dev] = pnp_dma(pdev, 0);
157 dma2[dev] = pnp_dma(pdev, 1);
158 irq[dev] = pnp_irq(pdev, 0);
159
160 pdev = acard->devmpu;
161 pnp_init_resource_table(cfg);
162
163 if (mpu_port[dev] != SNDRV_AUTO_PORT)
164 pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
165 if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
166 pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
167
168 if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
169 snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
170 err = pnp_activate_dev(pdev);
171 if (err < 0) {
172 printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
173 mpu_port[dev] = -1;
174 acard->devmpu = NULL;
175 } else {
176 mpu_port[dev] = pnp_port_start(pdev, 0);
177 mpu_irq[dev] = pnp_irq(pdev, 0);
178 }
179
180 kfree(cfg);
181 return 0;
182}
183
184static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
185 const struct pnp_card_device_id *pid)
186{
187 int error;
188 snd_card_t *card;
189 struct snd_card_ad1816a *acard;
190 ad1816a_t *chip;
191 opl3_t *opl3;
192
193 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
194 sizeof(struct snd_card_ad1816a))) == NULL)
195 return -ENOMEM;
196 acard = (struct snd_card_ad1816a *)card->private_data;
197
198 if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
199 snd_card_free(card);
200 return error;
201 }
202 snd_card_set_dev(card, &pcard->card->dev);
203
204 if ((error = snd_ad1816a_create(card, port[dev],
205 irq[dev],
206 dma1[dev],
207 dma2[dev],
208 &chip)) < 0) {
209 snd_card_free(card);
210 return error;
211 }
212
213 strcpy(card->driver, "AD1816A");
214 strcpy(card->shortname, "ADI SoundPort AD1816A");
215 sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
216 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
217
218 if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
219 snd_card_free(card);
220 return error;
221 }
222
223 if ((error = snd_ad1816a_mixer(chip)) < 0) {
224 snd_card_free(card);
225 return error;
226 }
227
228 if (mpu_port[dev] > 0) {
229 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
230 mpu_port[dev], 0, mpu_irq[dev], SA_INTERRUPT,
231 NULL) < 0)
232 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
233 }
234
235 if (fm_port[dev] > 0) {
236 if (snd_opl3_create(card,
237 fm_port[dev], fm_port[dev] + 2,
238 OPL3_HW_AUTO, 0, &opl3) < 0) {
239 printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
240 } else {
241 if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
242 snd_card_free(card);
243 return error;
244 }
245 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
246 snd_card_free(card);
247 return error;
248 }
249 }
250 }
251
252 if ((error = snd_card_register(card)) < 0) {
253 snd_card_free(card);
254 return error;
255 }
256 pnp_set_card_drvdata(pcard, card);
257 return 0;
258}
259
260static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
261 const struct pnp_card_device_id *id)
262{
263 static int dev;
264 int res;
265
266 for ( ; dev < SNDRV_CARDS; dev++) {
267 if (!enable[dev])
268 continue;
269 res = snd_card_ad1816a_probe(dev, card, id);
270 if (res < 0)
271 return res;
272 dev++;
273 return 0;
274 }
275 return -ENODEV;
276}
277
278static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
279{
280 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
281
282 snd_card_disconnect(card);
283 snd_card_free_in_thread(card);
284}
285
286static struct pnp_card_driver ad1816a_pnpc_driver = {
287 .flags = PNP_DRIVER_RES_DISABLE,
288 .name = "ad1816a",
289 .id_table = snd_ad1816a_pnpids,
290 .probe = snd_ad1816a_pnp_detect,
291 .remove = __devexit_p(snd_ad1816a_pnp_remove),
292};
293
294static int __init alsa_card_ad1816a_init(void)
295{
296 int cards = 0;
297
298 cards += pnp_register_card_driver(&ad1816a_pnpc_driver);
299#ifdef MODULE
300 if (!cards) {
301 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
302 printk(KERN_ERR "no AD1816A based soundcards found.\n");
303 }
304#endif /* MODULE */
305 return cards ? 0 : -ENODEV;
306}
307
308static void __exit alsa_card_ad1816a_exit(void)
309{
310 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
311}
312
313module_init(alsa_card_ad1816a_init)
314module_exit(alsa_card_ad1816a_exit)