3 dt019x.c - driver for Diamond Technologies DT-0197H based soundcards.
4 Copyright (C) 1999, 2002 by Massimo Piccioni <dafastidio@libero.it>
6 Generalised for soundcards based on DT-0196 and ALS-007 chips
7 by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
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.
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.
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
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/sched.h>
27 #include <linux/wait.h>
28 #include <linux/pnp.h>
29 #include <sound/core.h>
31 #include <sound/initval.h>
32 #include <sound/mpu401.h>
33 #include <sound/opl3.h>
38 #define PFX "dt019x: "
40 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
41 MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
42 MODULE_LICENSE("GPL");
43 MODULE_CLASSES("{sound}");
44 MODULE_DEVICES("{{Diamond Technologies DT-019X},"
45 "{Avance Logic ALS-007}}");
47 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
48 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
49 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
50 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
51 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
52 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
53 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
54 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
55 static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
57 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
58 MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
59 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
60 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
61 MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
62 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
63 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
64 MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
65 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
66 MODULE_PARM(port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
67 MODULE_PARM_DESC(port, "Port # for dt019x driver.");
68 MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC);
69 MODULE_PARM(mpu_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
70 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for dt019x driver.");
71 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT12_DESC);
72 MODULE_PARM(fm_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
73 MODULE_PARM_DESC(fm_port, "FM port # for dt019x driver.");
74 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT12_DESC);
75 MODULE_PARM(irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
76 MODULE_PARM_DESC(irq, "IRQ # for dt019x driver.");
77 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
78 MODULE_PARM(mpu_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
79 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for dt019x driver.");
80 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
81 MODULE_PARM(dma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
82 MODULE_PARM_DESC(dma8, "8-bit DMA # for dt019x driver.");
83 MODULE_PARM_SYNTAX(dma8, SNDRV_DMA8_DESC);
85 struct snd_card_dt019x {
87 struct pnp_dev *devmpu;
88 struct pnp_dev *devopl;
91 static struct pnp_card_device_id snd_dt019x_pnpids[] = {
93 { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
94 /* DT0196 / ALS-007 */
95 { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
99 MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
102 #define DRIVER_NAME "snd-card-dt019x"
105 static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
106 struct pnp_card_link *card,
107 const struct pnp_card_device_id *pid)
109 struct pnp_dev *pdev;
110 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
116 acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
117 if (acard->dev == NULL) {
121 acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
122 acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
125 pnp_init_resource_table(cfg);
127 if (port[dev] != SNDRV_AUTO_PORT)
128 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
129 if (dma8[dev] != SNDRV_AUTO_DMA)
130 pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
131 if (irq[dev] != SNDRV_AUTO_IRQ)
132 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
134 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
135 snd_printk(KERN_ERR PFX "DT-019X AUDIO the requested resources are invalid, using auto config\n");
136 err = pnp_activate_dev(pdev);
138 snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
143 port[dev] = pnp_port_start(pdev, 0);
144 dma8[dev] = pnp_dma(pdev, 0);
145 irq[dev] = pnp_irq(pdev, 0);
146 snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
147 port[dev],irq[dev],dma8[dev]);
149 pdev = acard->devmpu;
152 pnp_init_resource_table(cfg);
153 if (mpu_port[dev] != SNDRV_AUTO_PORT)
154 pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
155 if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
156 pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
157 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
158 snd_printk(KERN_ERR PFX "DT-019X MPU401 the requested resources are invalid, using auto config\n");
159 err = pnp_activate_dev(pdev);
161 pnp_release_card_device(pdev);
162 snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
165 mpu_port[dev] = pnp_port_start(pdev, 0);
166 mpu_irq[dev] = pnp_irq(pdev, 0);
167 snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
168 mpu_port[dev],mpu_irq[dev]);
171 acard->devmpu = NULL;
175 pdev = acard->devopl;
177 pnp_init_resource_table(cfg);
178 if (fm_port[dev] != SNDRV_AUTO_PORT)
179 pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
180 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
181 snd_printk(KERN_ERR PFX "DT-019X OPL3 the requested resources are invalid, using auto config\n");
182 err = pnp_activate_dev(pdev);
184 pnp_release_card_device(pdev);
185 snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
188 fm_port[dev] = pnp_port_start(pdev, 0);
189 snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
192 acard->devopl = NULL;
200 static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
205 struct snd_card_dt019x *acard;
208 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
209 sizeof(struct snd_card_dt019x))) == NULL)
211 acard = (struct snd_card_dt019x *)card->private_data;
213 snd_card_set_dev(card, &pcard->card->dev);
214 if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
219 if ((error = snd_sbdsp_create(card, port[dev],
221 snd_sb16dsp_interrupt,
230 strcpy(card->driver, "DT-019X");
231 strcpy(card->shortname, "Diamond Tech. DT-019X");
232 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
233 card->shortname, chip->name, chip->port,
234 irq[dev], dma8[dev]);
236 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
240 if ((error = snd_sbmixer_new(chip)) < 0) {
245 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
246 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
248 if (snd_mpu401_uart_new(card, 0,
253 mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
255 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
258 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
259 if (snd_opl3_create(card,
262 OPL3_HW_AUTO, 0, &opl3) < 0) {
263 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
264 fm_port[dev], fm_port[dev] + 2);
266 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
270 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
277 if ((error = snd_card_register(card)) < 0) {
281 pnp_set_card_drvdata(pcard, card);
285 static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
286 const struct pnp_card_device_id *pid)
291 for ( ; dev < SNDRV_CARDS; dev++) {
294 res = snd_card_dt019x_probe(dev, card, pid);
303 static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
305 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
306 snd_card_disconnect(card);
307 snd_card_free_in_thread(card);
310 static struct pnp_card_driver dt019x_pnpc_driver = {
311 .flags = PNP_DRIVER_RES_DISABLE,
313 .id_table = snd_dt019x_pnpids,
314 .probe = snd_dt019x_pnp_probe,
315 .remove = __devexit_p(snd_dt019x_pnp_remove),
318 static int __init alsa_card_dt019x_init(void)
322 cards += pnp_register_card_driver(&dt019x_pnpc_driver);
326 pnp_unregister_card_driver(&dt019x_pnpc_driver);
327 snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
330 return cards ? 0 : -ENODEV;
333 static void __exit alsa_card_dt019x_exit(void)
335 pnp_unregister_card_driver(&dt019x_pnpc_driver);
338 module_init(alsa_card_dt019x_init)
339 module_exit(alsa_card_dt019x_exit)
343 /* format is: snd-dt019x=enable,index,id,
344 port,mpu_port,fm_port,
345 irq,mpu_irq,dma8,dma8_size */
347 static int __init alsa_card_dt019x_setup(char *str)
349 static unsigned __initdata nr_dev = 0;
351 if (nr_dev >= SNDRV_CARDS)
353 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
354 get_option(&str,&index[nr_dev]) == 2 &&
355 get_id(&str,&id[nr_dev]) == 2 &&
356 get_option_long(&str,&port[nr_dev]) == 2 &&
357 get_option_long(&str,&mpu_port[nr_dev]) == 2 &&
358 get_option_long(&str,&fm_port[nr_dev]) == 2 &&
359 get_option(&str,&irq[nr_dev]) == 2 &&
360 get_option(&str,&mpu_irq[nr_dev]) == 2 &&
361 get_option(&str,&dma8[nr_dev]) == 2);
366 __setup("snd-dt019x=", alsa_card_dt019x_setup);
368 #endif /* ifndef MODULE */