2 card-azt2320.c - driver for Aztech Systems AZT2320 based soundcards.
3 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 This driver should provide support for most Aztech AZT2320 based cards.
22 Several AZT2316 chips are also supported/tested, but autoprobe doesn't
23 work: all module option have to be set.
25 No docs available for us at Aztech headquarters !!! Unbelievable ...
26 No other help obtained.
28 Thanks to Rainer Wiesner <rainer.wiesner@01019freenet.de> for the WSS
29 activation method (full-duplex audio!).
32 #include <sound/driver.h>
34 #include <linux/delay.h>
35 #include <linux/init.h>
36 #include <linux/time.h>
37 #include <linux/wait.h>
38 #include <linux/pnp.h>
39 #include <linux/moduleparam.h>
40 #include <sound/core.h>
41 #include <sound/initval.h>
42 #include <sound/cs4231.h>
43 #include <sound/mpu401.h>
44 #include <sound/opl3.h>
46 #define chip_t cs4231_t
48 #define PFX "azt2320: "
50 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
51 MODULE_DESCRIPTION("Aztech Systems AZT2320");
52 MODULE_LICENSE("GPL");
53 MODULE_CLASSES("{sound}");
54 MODULE_DEVICES("{{Aztech Systems,PRO16V},"
55 "{Aztech Systems,AZT2320},"
56 "{Aztech Systems,AZT3300},"
57 "{Aztech Systems,AZT2320},"
58 "{Aztech Systems,AZT3000}}");
60 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
61 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
62 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
63 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
64 static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
65 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
66 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
67 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
68 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
69 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
70 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
73 module_param_array(index, int, boot_devs, 0444);
74 MODULE_PARM_DESC(index, "Index value for azt2320 based soundcard.");
75 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
76 module_param_array(id, charp, boot_devs, 0444);
77 MODULE_PARM_DESC(id, "ID string for azt2320 based soundcard.");
78 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
79 module_param_array(enable, bool, boot_devs, 0444);
80 MODULE_PARM_DESC(enable, "Enable azt2320 based soundcard.");
81 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
82 module_param_array(port, long, boot_devs, 0444);
83 MODULE_PARM_DESC(port, "Port # for azt2320 driver.");
84 MODULE_PARM_SYNTAX(port, SNDRV_PORT12_DESC);
85 module_param_array(wss_port, long, boot_devs, 0444);
86 MODULE_PARM_DESC(wss_port, "WSS Port # for azt2320 driver.");
87 MODULE_PARM_SYNTAX(wss_port, SNDRV_PORT12_DESC);
88 module_param_array(mpu_port, long, boot_devs, 0444);
89 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for azt2320 driver.");
90 MODULE_PARM_SYNTAX(mpu_port, SNDRV_PORT12_DESC);
91 module_param_array(fm_port, long, boot_devs, 0444);
92 MODULE_PARM_DESC(fm_port, "FM port # for azt2320 driver.");
93 MODULE_PARM_SYNTAX(fm_port, SNDRV_PORT12_DESC);
94 module_param_array(irq, int, boot_devs, 0444);
95 MODULE_PARM_DESC(irq, "IRQ # for azt2320 driver.");
96 MODULE_PARM_SYNTAX(irq, SNDRV_IRQ_DESC);
97 module_param_array(mpu_irq, int, boot_devs, 0444);
98 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for azt2320 driver.");
99 MODULE_PARM_SYNTAX(mpu_irq, SNDRV_IRQ_DESC);
100 module_param_array(dma1, int, boot_devs, 0444);
101 MODULE_PARM_DESC(dma1, "1st DMA # for azt2320 driver.");
102 MODULE_PARM_SYNTAX(dma1, SNDRV_DMA_DESC);
103 module_param_array(dma2, int, boot_devs, 0444);
104 MODULE_PARM_DESC(dma2, "2nd DMA # for azt2320 driver.");
105 MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC);
107 struct snd_card_azt2320 {
110 struct pnp_dev *devmpu;
113 static struct pnp_card_device_id snd_azt2320_pnpids[] = {
115 { .id = "AZT1008", .devs = { { "AZT1008" }, { "AZT2001" }, } },
116 /* Aztech Sound Galaxy 16 */
117 { .id = "AZT2320", .devs = { { "AZT0001" }, { "AZT0002" }, } },
118 /* Packard Bell Sound III 336 AM/SP */
119 { .id = "AZT3000", .devs = { { "AZT1003" }, { "AZT2001" }, } },
121 { .id = "AZT3002", .devs = { { "AZT1004" }, { "AZT2001" }, } },
123 { .id = "AZT3005", .devs = { { "AZT1003" }, { "AZT2001" }, } },
125 { .id = "AZT3011", .devs = { { "AZT1003" }, { "AZT2001" }, } },
126 { .id = "" } /* end */
129 MODULE_DEVICE_TABLE(pnp_card, snd_azt2320_pnpids);
131 #define DRIVER_NAME "snd-card-azt2320"
133 static int __devinit snd_card_azt2320_pnp(int dev, struct snd_card_azt2320 *acard,
134 struct pnp_card_link *card,
135 const struct pnp_card_device_id *id)
137 struct pnp_dev *pdev;
138 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
144 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
145 if (acard->dev == NULL) {
150 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
153 pnp_init_resource_table(cfg);
155 /* override resources */
156 if (port[dev] != SNDRV_AUTO_PORT)
157 pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
158 if (fm_port[dev] != SNDRV_AUTO_PORT)
159 pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
160 if (wss_port[dev] != SNDRV_AUTO_PORT)
161 pnp_resource_change(&cfg->port_resource[2], wss_port[dev], 4);
162 if (dma1[dev] != SNDRV_AUTO_DMA)
163 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
164 if (dma2[dev] != SNDRV_AUTO_DMA)
165 pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
166 if (irq[dev] != SNDRV_AUTO_IRQ)
167 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
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");
171 err = pnp_activate_dev(pdev);
173 snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
177 port[dev] = pnp_port_start(pdev, 0);
178 fm_port[dev] = pnp_port_start(pdev, 1);
179 wss_port[dev] = pnp_port_start(pdev, 2);
180 dma1[dev] = pnp_dma(pdev, 0);
181 dma2[dev] = pnp_dma(pdev, 1);
182 irq[dev] = pnp_irq(pdev, 0);
184 pdev = acard->devmpu;
186 pnp_init_resource_table(cfg);
187 if (mpu_port[dev] != SNDRV_AUTO_PORT)
188 pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
189 if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
190 pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
191 if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
192 snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
193 err = pnp_activate_dev(pdev);
196 mpu_port[dev] = pnp_port_start(pdev, 0);
197 mpu_irq[dev] = pnp_irq(pdev, 0);
201 pnp_release_card_device(pdev);
202 snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
204 acard->devmpu = NULL;
212 /* same of snd_sbdsp_command by Jaroslav Kysela */
213 static int __devinit snd_card_azt2320_command(unsigned long port, unsigned char val)
218 limit = jiffies + HZ / 10;
219 for (i = 50000; i && time_after(limit, jiffies); i--)
220 if (!(inb(port + 0x0c) & 0x80)) {
221 outb(val, port + 0x0c);
227 static int __devinit snd_card_azt2320_enable_wss(unsigned long port)
231 if ((error = snd_card_azt2320_command(port, 0x09)))
233 if ((error = snd_card_azt2320_command(port, 0x00)))
240 static int __devinit snd_card_azt2320_probe(int dev,
241 struct pnp_card_link *pcard,
242 const struct pnp_card_device_id *pid)
246 struct snd_card_azt2320 *acard;
250 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
251 sizeof(struct snd_card_azt2320))) == NULL)
253 acard = (struct snd_card_azt2320 *)card->private_data;
255 if ((error = snd_card_azt2320_pnp(dev, acard, pcard, pid))) {
259 snd_card_set_dev(card, &pcard->card->dev);
261 if ((error = snd_card_azt2320_enable_wss(port[dev]))) {
266 if ((error = snd_cs4231_create(card, wss_port[dev], -1,
270 CS4231_HW_DETECT, 0, &chip)) < 0) {
275 strcpy(card->driver, "AZT2320");
276 strcpy(card->shortname, "Aztech AZT2320");
277 sprintf(card->longname, "%s, WSS at 0x%lx, irq %i, dma %i&%i",
278 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
280 if ((error = snd_cs4231_pcm(chip, 0, NULL)) < 0) {
284 if ((error = snd_cs4231_mixer(chip)) < 0) {
288 if ((error = snd_cs4231_timer(chip, 0, NULL)) < 0) {
293 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
294 if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320,
296 mpu_irq[dev], SA_INTERRUPT,
298 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
301 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
302 if (snd_opl3_create(card,
303 fm_port[dev], fm_port[dev] + 2,
304 OPL3_HW_AUTO, 0, &opl3) < 0) {
305 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
306 fm_port[dev], fm_port[dev] + 2);
308 if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
312 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
319 if ((error = snd_card_register(card)) < 0) {
323 pnp_set_card_drvdata(pcard, card);
327 static int __devinit snd_azt2320_pnp_detect(struct pnp_card_link *card,
328 const struct pnp_card_device_id *id)
333 for ( ; dev < SNDRV_CARDS; dev++) {
336 res = snd_card_azt2320_probe(dev, card, id);
345 static void __devexit snd_azt2320_pnp_remove(struct pnp_card_link * pcard)
347 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
349 snd_card_disconnect(card);
350 snd_card_free_in_thread(card);
353 static struct pnp_card_driver azt2320_pnpc_driver = {
354 .flags = PNP_DRIVER_RES_DISABLE,
356 .id_table = snd_azt2320_pnpids,
357 .probe = snd_azt2320_pnp_detect,
358 .remove = __devexit_p(snd_azt2320_pnp_remove),
361 static int __init alsa_card_azt2320_init(void)
365 cards += pnp_register_card_driver(&azt2320_pnpc_driver);
368 pnp_unregister_card_driver(&azt2320_pnpc_driver);
369 snd_printk(KERN_ERR "no AZT2320 based soundcards found\n");
372 return cards ? 0 : -ENODEV;
375 static void __exit alsa_card_azt2320_exit(void)
377 pnp_unregister_card_driver(&azt2320_pnpc_driver);
380 module_init(alsa_card_azt2320_init)
381 module_exit(alsa_card_azt2320_exit)