1 // SPDX-License-Identifier: GPL-2.0-or-later
3 card-azt2320.c - driver for Aztech Systems AZT2320 based soundcards.
4 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
9 This driver should provide support for most Aztech AZT2320 based cards.
10 Several AZT2316 chips are also supported/tested, but autoprobe doesn't
11 work: all module option have to be set.
13 No docs available for us at Aztech headquarters !!! Unbelievable ...
14 No other help obtained.
16 Thanks to Rainer Wiesner <rainer.wiesner@01019freenet.de> for the WSS
17 activation method (full-duplex audio!).
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/time.h>
24 #include <linux/wait.h>
25 #include <linux/pnp.h>
26 #include <linux/module.h>
27 #include <sound/core.h>
28 #include <sound/initval.h>
29 #include <sound/wss.h>
30 #include <sound/mpu401.h>
31 #include <sound/opl3.h>
33 #define PFX "azt2320: "
35 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
36 MODULE_DESCRIPTION("Aztech Systems AZT2320");
37 MODULE_LICENSE("GPL");
38 MODULE_SUPPORTED_DEVICE("{{Aztech Systems,PRO16V},"
39 "{Aztech Systems,AZT2320},"
40 "{Aztech Systems,AZT3300},"
41 "{Aztech Systems,AZT2320},"
42 "{Aztech Systems,AZT3000}}");
44 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
45 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
46 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_ISAPNP
; /* Enable this card */
47 static long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* PnP setup */
48 static long wss_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* PnP setup */
49 static long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* PnP setup */
50 static long fm_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
; /* PnP setup */
51 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* Pnp setup */
52 static int mpu_irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
; /* Pnp setup */
53 static int dma1
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* PnP setup */
54 static int dma2
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
; /* PnP setup */
56 module_param_array(index
, int, NULL
, 0444);
57 MODULE_PARM_DESC(index
, "Index value for azt2320 based soundcard.");
58 module_param_array(id
, charp
, NULL
, 0444);
59 MODULE_PARM_DESC(id
, "ID string for azt2320 based soundcard.");
60 module_param_array(enable
, bool, NULL
, 0444);
61 MODULE_PARM_DESC(enable
, "Enable azt2320 based soundcard.");
63 struct snd_card_azt2320
{
66 struct pnp_dev
*devmpu
;
70 static const struct pnp_card_device_id snd_azt2320_pnpids
[] = {
72 { .id
= "AZT1008", .devs
= { { "AZT1008" }, { "AZT2001" }, } },
73 /* Aztech Sound Galaxy 16 */
74 { .id
= "AZT2320", .devs
= { { "AZT0001" }, { "AZT0002" }, } },
75 /* Packard Bell Sound III 336 AM/SP */
76 { .id
= "AZT3000", .devs
= { { "AZT1003" }, { "AZT2001" }, } },
78 { .id
= "AZT3002", .devs
= { { "AZT1004" }, { "AZT2001" }, } },
80 { .id
= "AZT3005", .devs
= { { "AZT1003" }, { "AZT2001" }, } },
82 { .id
= "AZT3011", .devs
= { { "AZT1003" }, { "AZT2001" }, } },
83 { .id
= "" } /* end */
86 MODULE_DEVICE_TABLE(pnp_card
, snd_azt2320_pnpids
);
88 #define DRIVER_NAME "snd-card-azt2320"
90 static int snd_card_azt2320_pnp(int dev
, struct snd_card_azt2320
*acard
,
91 struct pnp_card_link
*card
,
92 const struct pnp_card_device_id
*id
)
97 acard
->dev
= pnp_request_card_device(card
, id
->devs
[0].id
, NULL
);
98 if (acard
->dev
== NULL
)
101 acard
->devmpu
= pnp_request_card_device(card
, id
->devs
[1].id
, NULL
);
105 err
= pnp_activate_dev(pdev
);
107 snd_printk(KERN_ERR PFX
"AUDIO pnp configure failure\n");
110 port
[dev
] = pnp_port_start(pdev
, 0);
111 fm_port
[dev
] = pnp_port_start(pdev
, 1);
112 wss_port
[dev
] = pnp_port_start(pdev
, 2);
113 dma1
[dev
] = pnp_dma(pdev
, 0);
114 dma2
[dev
] = pnp_dma(pdev
, 1);
115 irq
[dev
] = pnp_irq(pdev
, 0);
117 pdev
= acard
->devmpu
;
119 err
= pnp_activate_dev(pdev
);
122 mpu_port
[dev
] = pnp_port_start(pdev
, 0);
123 mpu_irq
[dev
] = pnp_irq(pdev
, 0);
127 pnp_release_card_device(pdev
);
128 snd_printk(KERN_ERR PFX
"MPU401 pnp configure failure, skipping\n");
130 acard
->devmpu
= NULL
;
137 /* same of snd_sbdsp_command by Jaroslav Kysela */
138 static int snd_card_azt2320_command(unsigned long port
, unsigned char val
)
143 limit
= jiffies
+ HZ
/ 10;
144 for (i
= 50000; i
&& time_after(limit
, jiffies
); i
--)
145 if (!(inb(port
+ 0x0c) & 0x80)) {
146 outb(val
, port
+ 0x0c);
152 static int snd_card_azt2320_enable_wss(unsigned long port
)
156 if ((error
= snd_card_azt2320_command(port
, 0x09)))
158 if ((error
= snd_card_azt2320_command(port
, 0x00)))
165 static int snd_card_azt2320_probe(int dev
,
166 struct pnp_card_link
*pcard
,
167 const struct pnp_card_device_id
*pid
)
170 struct snd_card
*card
;
171 struct snd_card_azt2320
*acard
;
172 struct snd_wss
*chip
;
173 struct snd_opl3
*opl3
;
175 error
= snd_card_new(&pcard
->card
->dev
,
176 index
[dev
], id
[dev
], THIS_MODULE
,
177 sizeof(struct snd_card_azt2320
), &card
);
180 acard
= card
->private_data
;
182 if ((error
= snd_card_azt2320_pnp(dev
, acard
, pcard
, pid
))) {
187 if ((error
= snd_card_azt2320_enable_wss(port
[dev
]))) {
192 error
= snd_wss_create(card
, wss_port
[dev
], -1,
194 dma1
[dev
], dma2
[dev
],
195 WSS_HW_DETECT
, 0, &chip
);
201 strcpy(card
->driver
, "AZT2320");
202 strcpy(card
->shortname
, "Aztech AZT2320");
203 sprintf(card
->longname
, "%s, WSS at 0x%lx, irq %i, dma %i&%i",
204 card
->shortname
, chip
->port
, irq
[dev
], dma1
[dev
], dma2
[dev
]);
206 error
= snd_wss_pcm(chip
, 0);
211 error
= snd_wss_mixer(chip
);
216 error
= snd_wss_timer(chip
, 0);
222 if (mpu_port
[dev
] > 0 && mpu_port
[dev
] != SNDRV_AUTO_PORT
) {
223 if (snd_mpu401_uart_new(card
, 0, MPU401_HW_AZT2320
,
225 mpu_irq
[dev
], NULL
) < 0)
226 snd_printk(KERN_ERR PFX
"no MPU-401 device at 0x%lx\n", mpu_port
[dev
]);
229 if (fm_port
[dev
] > 0 && fm_port
[dev
] != SNDRV_AUTO_PORT
) {
230 if (snd_opl3_create(card
,
231 fm_port
[dev
], fm_port
[dev
] + 2,
232 OPL3_HW_AUTO
, 0, &opl3
) < 0) {
233 snd_printk(KERN_ERR PFX
"no OPL device at 0x%lx-0x%lx\n",
234 fm_port
[dev
], fm_port
[dev
] + 2);
236 if ((error
= snd_opl3_timer_new(opl3
, 1, 2)) < 0) {
240 if ((error
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
)) < 0) {
247 if ((error
= snd_card_register(card
)) < 0) {
251 pnp_set_card_drvdata(pcard
, card
);
255 static unsigned int azt2320_devices
;
257 static int snd_azt2320_pnp_detect(struct pnp_card_link
*card
,
258 const struct pnp_card_device_id
*id
)
263 for ( ; dev
< SNDRV_CARDS
; dev
++) {
266 res
= snd_card_azt2320_probe(dev
, card
, id
);
276 static void snd_azt2320_pnp_remove(struct pnp_card_link
*pcard
)
278 snd_card_free(pnp_get_card_drvdata(pcard
));
279 pnp_set_card_drvdata(pcard
, NULL
);
283 static int snd_azt2320_pnp_suspend(struct pnp_card_link
*pcard
, pm_message_t state
)
285 struct snd_card
*card
= pnp_get_card_drvdata(pcard
);
286 struct snd_card_azt2320
*acard
= card
->private_data
;
287 struct snd_wss
*chip
= acard
->chip
;
289 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
294 static int snd_azt2320_pnp_resume(struct pnp_card_link
*pcard
)
296 struct snd_card
*card
= pnp_get_card_drvdata(pcard
);
297 struct snd_card_azt2320
*acard
= card
->private_data
;
298 struct snd_wss
*chip
= acard
->chip
;
301 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
306 static struct pnp_card_driver azt2320_pnpc_driver
= {
307 .flags
= PNP_DRIVER_RES_DISABLE
,
309 .id_table
= snd_azt2320_pnpids
,
310 .probe
= snd_azt2320_pnp_detect
,
311 .remove
= snd_azt2320_pnp_remove
,
313 .suspend
= snd_azt2320_pnp_suspend
,
314 .resume
= snd_azt2320_pnp_resume
,
318 static int __init
alsa_card_azt2320_init(void)
322 err
= pnp_register_card_driver(&azt2320_pnpc_driver
);
326 if (!azt2320_devices
) {
327 pnp_unregister_card_driver(&azt2320_pnpc_driver
);
329 snd_printk(KERN_ERR
"no AZT2320 based soundcards found\n");
336 static void __exit
alsa_card_azt2320_exit(void)
338 pnp_unregister_card_driver(&azt2320_pnpc_driver
);
341 module_init(alsa_card_azt2320_init
)
342 module_exit(alsa_card_azt2320_exit
)