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 <linux/moduleparam.h>
30 #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 */
58 module_param_array(index, int, boot_devs, 0444);
59 MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
60 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
61 module_param_array(id, charp, boot_devs, 0444);
62 MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
63 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
64 module_param_array(enable, bool, boot_devs, 0444);
65 MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
66 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
67 module_param_array(port, long, boot_devs, 0444);
68 MODULE_PARM_DESC(port, "Port # for dt019x driver.");
69 MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC);
70 module_param_array(mpu_port, long, boot_devs, 0444);
71 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for dt019x driver.");
72 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT12_DESC);
73 module_param_array(fm_port, long, boot_devs, 0444);
74 MODULE_PARM_DESC(fm_port, "FM port # for dt019x driver.");
75 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT12_DESC);
76 module_param_array(irq, int, boot_devs, 0444);
77 MODULE_PARM_DESC(irq, "IRQ # for dt019x driver.");
78 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
79 module_param_array(mpu_irq, int, boot_devs, 0444);
80 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for dt019x driver.");
81 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
82 module_param_array(dma8, int, boot_devs, 0444);
83 MODULE_PARM_DESC(dma8, "8-bit DMA # for dt019x driver.");
84 MODULE_PARM_SYNTAX(dma8, SNDRV_DMA8_DESC);
86 struct snd_card_dt019x {
88 struct pnp_dev *devmpu;
89 struct pnp_dev *devopl;
92 static struct pnp_card_device_id snd_dt019x_pnpids[] = {
94 { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
95 /* DT0196 / ALS-007 */
96 { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
100 MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
103 #define DRIVER_NAME "snd-card-dt019x"
106 static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
107 struct pnp_card_link *card,
108 const struct pnp_card_device_id *pid)
110 struct pnp_dev *pdev;
111 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
117 acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
118 if (acard->dev == NULL) {
122 acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
123 acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
126 pnp_init_resource_table(cfg);
128 if (port[dev] != SNDRV_AUTO_PORT)
129 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
130 if (dma8[dev] != SNDRV_AUTO_DMA)
131 pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
132 if (irq[dev] != SNDRV_AUTO_IRQ)
133 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
135 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
136 snd_printk(KERN_ERR PFX "DT-019X AUDIO the requested resources are invalid, using auto config\n");
137 err = pnp_activate_dev(pdev);
139 snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
144 port[dev] = pnp_port_start(pdev, 0);
145 dma8[dev] = pnp_dma(pdev, 0);
146 irq[dev] = pnp_irq(pdev, 0);
147 snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
148 port[dev],irq[dev],dma8[dev]);
150 pdev = acard->devmpu;
153 pnp_init_resource_table(cfg);
154 if (mpu_port[dev] != SNDRV_AUTO_PORT)
155 pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
156 if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
157 pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
158 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
159 snd_printk(KERN_ERR PFX "DT-019X MPU401 the requested resources are invalid, using auto config\n");
160 err = pnp_activate_dev(pdev);
162 pnp_release_card_device(pdev);
163 snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
166 mpu_port[dev] = pnp_port_start(pdev, 0);
167 mpu_irq[dev] = pnp_irq(pdev, 0);
168 snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
169 mpu_port[dev],mpu_irq[dev]);
172 acard->devmpu = NULL;
176 pdev = acard->devopl;
178 pnp_init_resource_table(cfg);
179 if (fm_port[dev] != SNDRV_AUTO_PORT)
180 pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
181 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
182 snd_printk(KERN_ERR PFX "DT-019X OPL3 the requested resources are invalid, using auto config\n");
183 err = pnp_activate_dev(pdev);
185 pnp_release_card_device(pdev);
186 snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
189 fm_port[dev] = pnp_port_start(pdev, 0);
190 snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
193 acard->devopl = NULL;
201 static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
206 struct snd_card_dt019x *acard;
209 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
210 sizeof(struct snd_card_dt019x))) == NULL)
212 acard = (struct snd_card_dt019x *)card->private_data;
214 snd_card_set_dev(card, &pcard->card->dev);
215 if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
220 if ((error = snd_sbdsp_create(card, port[dev],
222 snd_sb16dsp_interrupt,
231 strcpy(card->driver, "DT-019X");
232 strcpy(card->shortname, "Diamond Tech. DT-019X");
233 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
234 card->shortname, chip->name, chip->port,
235 irq[dev], dma8[dev]);
237 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
241 if ((error = snd_sbmixer_new(chip)) < 0) {
246 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
247 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
249 if (snd_mpu401_uart_new(card, 0,
254 mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
256 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
259 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
260 if (snd_opl3_create(card,
263 OPL3_HW_AUTO, 0, &opl3) < 0) {
264 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
265 fm_port[dev], fm_port[dev] + 2);
267 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
271 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
278 if ((error = snd_card_register(card)) < 0) {
282 pnp_set_card_drvdata(pcard, card);
286 static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
287 const struct pnp_card_device_id *pid)
292 for ( ; dev < SNDRV_CARDS; dev++) {
295 res = snd_card_dt019x_probe(dev, card, pid);
304 static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
306 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
307 snd_card_disconnect(card);
308 snd_card_free_in_thread(card);
311 static struct pnp_card_driver dt019x_pnpc_driver = {
312 .flags = PNP_DRIVER_RES_DISABLE,
314 .id_table = snd_dt019x_pnpids,
315 .probe = snd_dt019x_pnp_probe,
316 .remove = __devexit_p(snd_dt019x_pnp_remove),
319 static int __init alsa_card_dt019x_init(void)
323 cards += pnp_register_card_driver(&dt019x_pnpc_driver);
327 pnp_unregister_card_driver(&dt019x_pnpc_driver);
328 snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
331 return cards ? 0 : -ENODEV;
334 static void __exit alsa_card_dt019x_exit(void)
336 pnp_unregister_card_driver(&dt019x_pnpc_driver);
339 module_init(alsa_card_dt019x_init)
340 module_exit(alsa_card_dt019x_exit)