source: GPL/branches/alsa-resync1/alsa-kernel/isa/dt019x.c@ 210

Last change on this file since 210 was 210, checked in by Brendan Oakley, 18 years ago

Merged to Alsa 0.9.0rc3

File size: 12.7 KB
Line 
1
2/*
3 dt019x.c - driver for Diamond Technologies DT-0197H based soundcards.
4 Copyright (C) 1999, 2002 by Massimo Piccioni <dafastidio@libero.it>
5
6 Generalised for soundcards based on DT-0196 and ALS-007 chips
7 by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22*/
23
24#include <sound/driver.h>
25#include <linux/init.h>
26#include <linux/sched.h>
27#include <linux/wait.h>
28#ifndef LINUX_ISAPNP_H
29#include <linux/isapnp.h>
30#define isapnp_card pci_bus
31#define isapnp_dev pci_dev
32#endif
33#include <sound/core.h>
34#define SNDRV_GET_ID
35#include <sound/initval.h>
36#include <sound/mpu401.h>
37#include <sound/opl3.h>
38#include <sound/sb.h>
39
40#define chip_t sb_t
41
42#define PFX "dt019x: "
43
44MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
45MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
46MODULE_LICENSE("GPL");
47MODULE_CLASSES("{sound}");
48MODULE_DEVICES("{{Diamond Technologies DT-019X},"
49 "{Avance Logic ALS-007}}");
50
51static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
52static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
53static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
54static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
55static long snd_mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
56static long snd_fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
57static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
58static int snd_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
59static int snd_dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
60
61MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
62MODULE_PARM_DESC(snd_index, "Index value for DT-019X based soundcard.");
63MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
64MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
65MODULE_PARM_DESC(snd_id, "ID string for DT-019X based soundcard.");
66MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
67MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
68MODULE_PARM_DESC(snd_enable, "Enable DT-019X based soundcard.");
69MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
70MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
71MODULE_PARM_DESC(snd_port, "Port # for dt019x driver.");
72MODULE_PARM_SYNTAX(snd_port, SNDRV_PORT12_DESC);
73MODULE_PARM(snd_mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
74MODULE_PARM_DESC(snd_mpu_port, "MPU-401 port # for dt019x driver.");
75MODULE_PARM_SYNTAX(snd_mpu_port, SNDRV_PORT12_DESC);
76MODULE_PARM(snd_fm_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
77MODULE_PARM_DESC(snd_fm_port, "FM port # for dt019x driver.");
78MODULE_PARM_SYNTAX(snd_fm_port, SNDRV_PORT12_DESC);
79MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
80MODULE_PARM_DESC(snd_irq, "IRQ # for dt019x driver.");
81MODULE_PARM_SYNTAX(snd_irq, SNDRV_IRQ_DESC);
82MODULE_PARM(snd_mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
83MODULE_PARM_DESC(snd_mpu_irq, "MPU-401 IRQ # for dt019x driver.");
84MODULE_PARM_SYNTAX(snd_mpu_irq, SNDRV_IRQ_DESC);
85MODULE_PARM(snd_dma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
86MODULE_PARM_DESC(snd_dma8, "8-bit DMA # for dt019x driver.");
87MODULE_PARM_SYNTAX(snd_dma8, SNDRV_DMA8_DESC);
88
89struct snd_card_dt019x {
90#ifdef __ISAPNP__
91 struct isapnp_dev *dev;
92 struct isapnp_dev *devmpu;
93 struct isapnp_dev *devopl;
94#endif /* __ISAPNP__ */
95};
96
97static snd_card_t *snd_dt019x_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
98
99#ifdef __ISAPNP__
100static struct isapnp_card *snd_dt019x_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
101static const struct isapnp_card_id *snd_dt019x_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
102
103static struct isapnp_card_id snd_dt019x_pnpids[] __devinitdata = {
104 /* DT197A30 */
105 {
106#ifdef TARGET_OS2
107 0, ISAPNP_CARD_ID('R','W','B',0x1688),
108 { ISAPNP_DEVICE_ID('@','@','@',0x1688),
109 ISAPNP_DEVICE_ID('@','X','@',0x0001),
110 ISAPNP_DEVICE_ID('@','H','@',0x0001) }
111#else
112 ISAPNP_CARD_ID('R','W','B',0x1688),
113 .devs = { ISAPNP_DEVICE_ID('@','@','@',0x0001),
114 ISAPNP_DEVICE_ID('@','X','@',0x0001),
115 ISAPNP_DEVICE_ID('@','H','@',0x0001) }
116 },
117 /* DT0196 / ALS-007 */
118 {
119 ISAPNP_CARD_ID('A','L','S',0x0007),
120 devs: { ISAPNP_DEVICE_ID('@','@','@',0x0001),
121 ISAPNP_DEVICE_ID('@','X','@',0x0001),
122 ISAPNP_DEVICE_ID('@','H','@',0x0001) }
123#endif
124 },
125 { ISAPNP_CARD_END, }
126};
127
128ISAPNP_CARD_TABLE(snd_dt019x_pnpids);
129
130#endif /* __ISAPNP__ */
131
132#define DRIVER_NAME "snd-card-dt019x"
133
134
135#ifdef __ISAPNP__
136static int __init snd_card_dt019x_isapnp(int dev, struct snd_card_dt019x *acard)
137{
138 const struct isapnp_card_id *id = snd_dt019x_isapnp_id[dev];
139 struct isapnp_card *card = snd_dt019x_isapnp_cards[dev];
140 struct isapnp_dev *pdev;
141
142 acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
143 if (acard->dev->active) {
144 acard->dev = NULL;
145 return -EBUSY;
146 }
147 acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
148 if (acard->devmpu->active) {
149 acard->dev = acard->devmpu = NULL;
150 return -EBUSY;
151 }
152 acard->devopl = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
153 if (acard->devopl->active) {
154 acard->dev = acard->devmpu = acard->devopl = NULL;
155 return -EBUSY;
156 }
157
158 pdev = acard->dev;
159 if (!pdev || pdev->prepare(pdev)<0)
160 return -EAGAIN;
161
162 if (snd_port[dev] != SNDRV_AUTO_PORT)
163 isapnp_resource_change(&pdev->resource[0], snd_port[dev], 16);
164 if (snd_dma8[dev] != SNDRV_AUTO_DMA)
165 isapnp_resource_change(&pdev->dma_resource[0], snd_dma8[dev],
166 1);
167 if (snd_irq[dev] != SNDRV_AUTO_IRQ)
168 isapnp_resource_change(&pdev->irq_resource[0], snd_irq[dev], 1);
169
170 if (pdev->activate(pdev)<0) {
171 printk(KERN_ERR PFX "DT-019X AUDIO isapnp configure failure\n");
172 return -EBUSY;
173 }
174 snd_port[dev] = pdev->resource[0].start;
175 snd_dma8[dev] = pdev->dma_resource[0].start;
176 snd_irq[dev] = pdev->irq_resource[0].start;
177 snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%lx, dma=0x%lx\n",
178 snd_port[dev],snd_irq[dev],snd_dma8[dev]);
179
180 pdev = acard->devmpu;
181 if (!pdev || pdev->prepare(pdev)<0)
182 return 0;
183
184 if (snd_mpu_port[dev] != SNDRV_AUTO_PORT)
185 isapnp_resource_change(&pdev->resource[0], snd_mpu_port[dev],
186 2);
187 if (snd_mpu_irq[dev] != SNDRV_AUTO_IRQ)
188 isapnp_resource_change(&pdev->irq_resource[0], snd_mpu_irq[dev],
189 1);
190
191 if (pdev->activate(pdev)<0) {
192 printk(KERN_ERR PFX "DT-019X MPU-401 isapnp configure failure\n");
193 snd_mpu_port[dev] = -1;
194 acard->devmpu = NULL;
195 } else {
196 snd_mpu_port[dev] = pdev->resource[0].start;
197 snd_mpu_irq[dev] = pdev->irq_resource[0].start;
198 snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%lx\n",
199 snd_mpu_port[dev],snd_mpu_irq[dev]);
200 }
201
202 pdev = acard->devopl;
203 if (!pdev || pdev->prepare(pdev)<0)
204 return 0;
205
206 if (snd_fm_port[dev] != SNDRV_AUTO_PORT)
207 isapnp_resource_change(&pdev->resource[0], snd_fm_port[dev], 4);
208
209 if (pdev->activate(pdev)<0) {
210 printk(KERN_ERR PFX "DT-019X OPL3 isapnp configure failure\n");
211 snd_fm_port[dev] = -1;
212 acard->devopl = NULL;
213 } else {
214 snd_fm_port[dev] = pdev->resource[0].start;
215 snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",snd_fm_port[dev]);
216 }
217
218 return 0;
219}
220
221static void snd_card_dt019x_deactivate(struct snd_card_dt019x *acard)
222{
223 if (acard->dev) {
224 acard->dev->deactivate(acard->dev);
225 acard->dev = NULL;
226 }
227 if (acard->devmpu) {
228 acard->devmpu->deactivate(acard->devmpu);
229 acard->devmpu = NULL;
230 }
231 if (acard->devopl) {
232 acard->devopl->deactivate(acard->devopl);
233 acard->devopl = NULL;
234 }
235}
236#endif /* __ISAPNP__ */
237
238static void snd_card_dt019x_free(snd_card_t *card)
239{
240 struct snd_card_dt019x *acard = (struct snd_card_dt019x *)card->private_data;
241
242 if (acard != NULL) {
243#ifdef __ISAPNP__
244 snd_card_dt019x_deactivate(acard);
245#endif /* __ISAPNP__ */
246 }
247}
248
249static int __init snd_card_dt019x_probe(int dev)
250{
251 int error;
252 sb_t *chip;
253 snd_card_t *card;
254 struct snd_card_dt019x *acard;
255 opl3_t *opl3;
256
257 if ((card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE,
258 sizeof(struct snd_card_dt019x))) == NULL)
259 return -ENOMEM;
260 acard = (struct snd_card_dt019x *)card->private_data;
261 card->private_free = snd_card_dt019x_free;
262
263#ifdef __ISAPNP__
264 if ((error = snd_card_dt019x_isapnp(dev, acard))) {
265 snd_card_free(card);
266 return error;
267 }
268#else
269 printk(KERN_ERR PFX "you have to enable PnP support ...\n");
270 snd_card_free(card);
271 return -ENOSYS;
272#endif /* __ISAPNP__ */
273
274 if ((error = snd_sbdsp_create(card, snd_port[dev],
275 snd_irq[dev],
276 snd_sb16dsp_interrupt,
277 snd_dma8[dev],
278 -1,
279 SB_HW_DT019X,
280 &chip)) < 0) {
281 snd_card_free(card);
282 return error;
283 }
284
285 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
286 snd_card_free(card);
287 return error;
288 }
289 if ((error = snd_sbmixer_new(chip)) < 0) {
290 snd_card_free(card);
291 return error;
292 }
293
294 if (snd_mpu_port[dev] > 0) {
295 if (snd_mpu401_uart_new(card, 0,
296/* MPU401_HW_SB,*/
297 MPU401_HW_MPU401,
298 snd_mpu_port[dev], 0,
299 snd_mpu_irq[dev],
300 SA_INTERRUPT,
301 NULL) < 0)
302 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n",
303 snd_mpu_port[dev]);
304 }
305
306 if (snd_fm_port[dev] > 0) {
307 if (snd_opl3_create(card,
308 snd_fm_port[dev],
309 snd_fm_port[dev] + 2,
310 OPL3_HW_AUTO, 0, &opl3) < 0) {
311 printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
312 snd_fm_port[dev], snd_fm_port[dev] + 2);
313 } else {
314 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
315 snd_card_free(card);
316 return error;
317 }
318 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
319 snd_card_free(card);
320 return error;
321 }
322 }
323 }
324
325 strcpy(card->driver, "DT-019X");
326 strcpy(card->shortname, "Diamond Tech. DT-019X");
327 sprintf(card->longname, "%s soundcard, %s at 0x%lx, irq %d, dma %d",
328 card->shortname, chip->name, chip->port,
329 snd_irq[dev], snd_dma8[dev]);
330 if ((error = snd_card_register(card)) < 0) {
331 snd_card_free(card);
332 return error;
333 }
334 snd_dt019x_cards[dev] = card;
335 return 0;
336}
337
338#ifdef __ISAPNP__
339static int __init snd_dt019x_isapnp_detect(struct isapnp_card *card,
340 const struct isapnp_card_id *id)
341{
342 static int dev;
343 int res;
344
345 for ( ; dev < SNDRV_CARDS; dev++) {
346 if (!snd_enable[dev])
347 continue;
348 snd_dt019x_isapnp_cards[dev] = card;
349 snd_dt019x_isapnp_id[dev] = id;
350 res = snd_card_dt019x_probe(dev);
351 if (res < 0)
352 return res;
353 dev++;
354 return 0;
355 }
356 return -ENODEV;
357}
358#endif /* __ISAPNP__ */
359
360static int __init alsa_card_dt019x_init(void)
361{
362 int cards = 0;
363
364#ifdef __ISAPNP__
365 cards += isapnp_probe_cards(snd_dt019x_pnpids, snd_dt019x_isapnp_detect);
366#else
367 printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
368#endif
369#ifdef MODULE
370 if (!cards)
371 printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
372#endif
373 return cards ? 0 : -ENODEV;
374}
375
376static void __exit alsa_card_dt019x_exit(void)
377{
378 int dev;
379
380 for (dev = 0; dev < SNDRV_CARDS; dev++)
381 snd_card_free(snd_dt019x_cards[dev]);
382}
383
384module_init(alsa_card_dt019x_init)
385module_exit(alsa_card_dt019x_exit)
386
387#ifndef MODULE
388
389/* format is: snd-dt019x=snd_enable,snd_index,snd_id,snd_isapnp,
390 snd_port,snd_mpu_port,snd_fm_port,
391 snd_irq,snd_mpu_irq,snd_dma8,snd_dma8_size */
392
393static int __init alsa_card_dt019x_setup(char *str)
394{
395 static unsigned __initdata nr_dev = 0;
396
397 if (nr_dev >= SNDRV_CARDS)
398 return 0;
399 (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
400 get_option(&str,&snd_index[nr_dev]) == 2 &&
401 get_id(&str,&snd_id[nr_dev]) == 2 &&
402 get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
403 get_option(&str,(int *)&snd_mpu_port[nr_dev]) == 2 &&
404 get_option(&str,(int *)&snd_fm_port[nr_dev]) == 2 &&
405 get_option(&str,&snd_irq[nr_dev]) == 2 &&
406 get_option(&str,&snd_mpu_irq[nr_dev]) == 2 &&
407 get_option(&str,&snd_dma8[nr_dev]) == 2);
408 nr_dev++;
409 return 1;
410}
411
412__setup("snd-dt019x=", alsa_card_dt019x_setup);
413
414#endif /* ifndef MODULE */
Note: See TracBrowser for help on using the repository browser.