blob: 50e7bc5ef561edfb89efd8f33f8b29b868b45c3e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
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#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>
34#include <sound/sb.h>
35
36#define PFX "dt019x: "
37
38MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
39MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
40MODULE_LICENSE("GPL");
41MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
42 "{Avance Logic ALS-007}}");
43
44static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
45static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
46static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
47static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
48static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
49static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
50static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
51static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
52static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
53
54module_param_array(index, int, NULL, 0444);
55MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
56module_param_array(id, charp, NULL, 0444);
57MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
58module_param_array(enable, bool, NULL, 0444);
59MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
60module_param_array(port, long, NULL, 0444);
61MODULE_PARM_DESC(port, "Port # for dt019x driver.");
62module_param_array(mpu_port, long, NULL, 0444);
63MODULE_PARM_DESC(mpu_port, "MPU-401 port # for dt019x driver.");
64module_param_array(fm_port, long, NULL, 0444);
65MODULE_PARM_DESC(fm_port, "FM port # for dt019x driver.");
66module_param_array(irq, int, NULL, 0444);
67MODULE_PARM_DESC(irq, "IRQ # for dt019x driver.");
68module_param_array(mpu_irq, int, NULL, 0444);
69MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for dt019x driver.");
70module_param_array(dma8, int, NULL, 0444);
71MODULE_PARM_DESC(dma8, "8-bit DMA # for dt019x driver.");
72
73struct snd_card_dt019x {
74 struct pnp_dev *dev;
75 struct pnp_dev *devmpu;
76 struct pnp_dev *devopl;
Takashi Iwaie2fa2132005-11-17 17:04:35 +010077 struct snd_sb *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80static struct pnp_card_device_id snd_dt019x_pnpids[] = {
81 /* DT197A30 */
82 { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
83 /* DT0196 / ALS-007 */
84 { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
85 { .id = "", }
86};
87
88MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
89
90
91#define DRIVER_NAME "snd-card-dt019x"
92
93
94static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
95 struct pnp_card_link *card,
96 const struct pnp_card_device_id *pid)
97{
98 struct pnp_dev *pdev;
99 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
100 int err;
101
102 if (!cfg)
103 return -ENOMEM;
104
105 acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
106 if (acard->dev == NULL) {
107 kfree (cfg);
108 return -ENODEV;
109 }
110 acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
111 acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
112
113 pdev = acard->dev;
114 pnp_init_resource_table(cfg);
115
116 if (port[dev] != SNDRV_AUTO_PORT)
117 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
118 if (dma8[dev] != SNDRV_AUTO_DMA)
119 pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
120 if (irq[dev] != SNDRV_AUTO_IRQ)
121 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
122
123 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
124 snd_printk(KERN_ERR PFX "DT-019X AUDIO the requested resources are invalid, using auto config\n");
125 err = pnp_activate_dev(pdev);
126 if (err < 0) {
127 snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
128 kfree(cfg);
129 return err;
130 }
131
132 port[dev] = pnp_port_start(pdev, 0);
133 dma8[dev] = pnp_dma(pdev, 0);
134 irq[dev] = pnp_irq(pdev, 0);
135 snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
136 port[dev],irq[dev],dma8[dev]);
137
138 pdev = acard->devmpu;
139
140 if (pdev != NULL) {
141 pnp_init_resource_table(cfg);
142 if (mpu_port[dev] != SNDRV_AUTO_PORT)
143 pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
144 if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
145 pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
146 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
147 snd_printk(KERN_ERR PFX "DT-019X MPU401 the requested resources are invalid, using auto config\n");
148 err = pnp_activate_dev(pdev);
149 if (err < 0) {
150 pnp_release_card_device(pdev);
151 snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
152 goto __mpu_error;
153 }
154 mpu_port[dev] = pnp_port_start(pdev, 0);
155 mpu_irq[dev] = pnp_irq(pdev, 0);
156 snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
157 mpu_port[dev],mpu_irq[dev]);
158 } else {
159 __mpu_error:
160 acard->devmpu = NULL;
161 mpu_port[dev] = -1;
162 }
163
164 pdev = acard->devopl;
165 if (pdev != NULL) {
166 pnp_init_resource_table(cfg);
167 if (fm_port[dev] != SNDRV_AUTO_PORT)
168 pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
169 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
170 snd_printk(KERN_ERR PFX "DT-019X OPL3 the requested resources are invalid, using auto config\n");
171 err = pnp_activate_dev(pdev);
172 if (err < 0) {
173 pnp_release_card_device(pdev);
174 snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
175 goto __fm_error;
176 }
177 fm_port[dev] = pnp_port_start(pdev, 0);
178 snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
179 } else {
180 __fm_error:
181 acard->devopl = NULL;
182 fm_port[dev] = -1;
183 }
184
185 kfree(cfg);
186 return 0;
187}
188
189static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
190{
191 int error;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100192 struct snd_sb *chip;
193 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 struct snd_card_dt019x *acard;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100195 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
198 sizeof(struct snd_card_dt019x))) == NULL)
199 return -ENOMEM;
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100200 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 snd_card_set_dev(card, &pcard->card->dev);
203 if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
204 snd_card_free(card);
205 return error;
206 }
207
208 if ((error = snd_sbdsp_create(card, port[dev],
209 irq[dev],
210 snd_sb16dsp_interrupt,
211 dma8[dev],
212 -1,
213 SB_HW_DT019X,
214 &chip)) < 0) {
215 snd_card_free(card);
216 return error;
217 }
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100218 acard->chip = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 strcpy(card->driver, "DT-019X");
221 strcpy(card->shortname, "Diamond Tech. DT-019X");
222 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
223 card->shortname, chip->name, chip->port,
224 irq[dev], dma8[dev]);
225
226 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
227 snd_card_free(card);
228 return error;
229 }
230 if ((error = snd_sbmixer_new(chip)) < 0) {
231 snd_card_free(card);
232 return error;
233 }
234
235 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
236 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
237 mpu_irq[dev] = -1;
238 if (snd_mpu401_uart_new(card, 0,
239/* MPU401_HW_SB,*/
240 MPU401_HW_MPU401,
241 mpu_port[dev], 0,
242 mpu_irq[dev],
243 mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
244 NULL) < 0)
245 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
246 }
247
248 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
249 if (snd_opl3_create(card,
250 fm_port[dev],
251 fm_port[dev] + 2,
252 OPL3_HW_AUTO, 0, &opl3) < 0) {
253 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
254 fm_port[dev], fm_port[dev] + 2);
255 } else {
256 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
257 snd_card_free(card);
258 return error;
259 }
260 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
261 snd_card_free(card);
262 return error;
263 }
264 }
265 }
266
267 if ((error = snd_card_register(card)) < 0) {
268 snd_card_free(card);
269 return error;
270 }
271 pnp_set_card_drvdata(pcard, card);
272 return 0;
273}
274
275static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
276 const struct pnp_card_device_id *pid)
277{
278 static int dev;
279 int res;
280
281 for ( ; dev < SNDRV_CARDS; dev++) {
282 if (!enable[dev])
283 continue;
284 res = snd_card_dt019x_probe(dev, card, pid);
285 if (res < 0)
286 return res;
287 dev++;
288 return 0;
289 }
290 return -ENODEV;
291}
292
293static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
294{
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100295 snd_card_free(pnp_get_card_drvdata(pcard));
296 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100299#ifdef CONFIG_PM
300static int snd_dt019x_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
301{
302 struct snd_card *card = pnp_get_card_drvdata(pcard);
303 struct snd_card_dt019x *acard = card->private_data;
304 struct snd_sb *chip = acard->chip;
305
306 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
307 snd_pcm_suspend_all(chip->pcm);
308 snd_sbmixer_suspend(chip);
309 return 0;
310}
311
312static int snd_dt019x_pnp_resume(struct pnp_card_link *pcard)
313{
314 struct snd_card *card = pnp_get_card_drvdata(pcard);
315 struct snd_card_dt019x *acard = card->private_data;
316 struct snd_sb *chip = acard->chip;
317
318 snd_sbdsp_reset(chip);
319 snd_sbmixer_resume(chip);
320 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
321 return 0;
322}
323#endif
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325static struct pnp_card_driver dt019x_pnpc_driver = {
326 .flags = PNP_DRIVER_RES_DISABLE,
327 .name = "dt019x",
328 .id_table = snd_dt019x_pnpids,
329 .probe = snd_dt019x_pnp_probe,
330 .remove = __devexit_p(snd_dt019x_pnp_remove),
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100331#ifdef CONFIG_PM
332 .suspend = snd_dt019x_pnp_suspend,
333 .resume = snd_dt019x_pnp_resume,
334#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335};
336
337static int __init alsa_card_dt019x_init(void)
338{
339 int cards = 0;
340
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100341 cards = pnp_register_card_driver(&dt019x_pnpc_driver);
342 if (cards <= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 pnp_unregister_card_driver(&dt019x_pnpc_driver);
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100344#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346#endif
Takashi Iwaie2fa2132005-11-17 17:04:35 +0100347 return -ENODEV;
348 }
349 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
352static void __exit alsa_card_dt019x_exit(void)
353{
354 pnp_unregister_card_driver(&dt019x_pnpc_driver);
355}
356
357module_init(alsa_card_dt019x_init)
358module_exit(alsa_card_dt019x_exit)