blob: 761cd198df2b0e434a9680d8f870c741b9c18db5 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 card-azt2320.c - driver for Aztech Systems AZT2320 based soundcards.
4 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
5
Linus Torvalds1da177e2005-04-16 15:20:36 -07006*/
7
8/*
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.
12
13 No docs available for us at Aztech headquarters !!! Unbelievable ...
14 No other help obtained.
15
16 Thanks to Rainer Wiesner <rainer.wiesner@01019freenet.de> for the WSS
17 activation method (full-duplex audio!).
18*/
19
Takashi Iwai6cbbfe12015-01-28 16:49:33 +010020#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/delay.h>
22#include <linux/init.h>
23#include <linux/time.h>
24#include <linux/wait.h>
25#include <linux/pnp.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040026#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <sound/core.h>
28#include <sound/initval.h>
Krzysztof Helt61ef19d2008-07-31 21:02:42 +020029#include <sound/wss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <sound/mpu401.h>
31#include <sound/opl3.h>
32
33#define PFX "azt2320: "
34
35MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
36MODULE_DESCRIPTION("Aztech Systems AZT2320");
37MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
40static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103041static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
43static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
44static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
45static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
46static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
47static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
48static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
49static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
50
51module_param_array(index, int, NULL, 0444);
52MODULE_PARM_DESC(index, "Index value for azt2320 based soundcard.");
53module_param_array(id, charp, NULL, 0444);
54MODULE_PARM_DESC(id, "ID string for azt2320 based soundcard.");
55module_param_array(enable, bool, NULL, 0444);
56MODULE_PARM_DESC(enable, "Enable azt2320 based soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58struct snd_card_azt2320 {
59 int dev_no;
60 struct pnp_dev *dev;
61 struct pnp_dev *devmpu;
Krzysztof Helt7779f752008-07-31 21:03:41 +020062 struct snd_wss *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
Arvind Yadav1d906e82017-08-17 15:36:21 +053065static const struct pnp_card_device_id snd_azt2320_pnpids[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 /* PRO16V */
67 { .id = "AZT1008", .devs = { { "AZT1008" }, { "AZT2001" }, } },
68 /* Aztech Sound Galaxy 16 */
69 { .id = "AZT2320", .devs = { { "AZT0001" }, { "AZT0002" }, } },
70 /* Packard Bell Sound III 336 AM/SP */
71 { .id = "AZT3000", .devs = { { "AZT1003" }, { "AZT2001" }, } },
72 /* AT3300 */
73 { .id = "AZT3002", .devs = { { "AZT1004" }, { "AZT2001" }, } },
74 /* --- */
75 { .id = "AZT3005", .devs = { { "AZT1003" }, { "AZT2001" }, } },
76 /* --- */
77 { .id = "AZT3011", .devs = { { "AZT1003" }, { "AZT2001" }, } },
78 { .id = "" } /* end */
79};
80
81MODULE_DEVICE_TABLE(pnp_card, snd_azt2320_pnpids);
82
83#define DRIVER_NAME "snd-card-azt2320"
84
Bill Pemberton1bff2922012-12-06 12:35:21 -050085static int snd_card_azt2320_pnp(int dev, struct snd_card_azt2320 *acard,
86 struct pnp_card_link *card,
87 const struct pnp_card_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 int err;
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +010093 if (acard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
97
98 pdev = acard->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 err = pnp_activate_dev(pdev);
101 if (err < 0) {
102 snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return err;
104 }
105 port[dev] = pnp_port_start(pdev, 0);
106 fm_port[dev] = pnp_port_start(pdev, 1);
107 wss_port[dev] = pnp_port_start(pdev, 2);
108 dma1[dev] = pnp_dma(pdev, 0);
109 dma2[dev] = pnp_dma(pdev, 1);
110 irq[dev] = pnp_irq(pdev, 0);
111
112 pdev = acard->devmpu;
113 if (pdev != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 err = pnp_activate_dev(pdev);
115 if (err < 0)
116 goto __mpu_error;
117 mpu_port[dev] = pnp_port_start(pdev, 0);
118 mpu_irq[dev] = pnp_irq(pdev, 0);
119 } else {
120 __mpu_error:
121 if (pdev) {
122 pnp_release_card_device(pdev);
123 snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
124 }
125 acard->devmpu = NULL;
126 mpu_port[dev] = -1;
127 }
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
130}
131
132/* same of snd_sbdsp_command by Jaroslav Kysela */
Bill Pemberton1bff2922012-12-06 12:35:21 -0500133static int snd_card_azt2320_command(unsigned long port, unsigned char val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
135 int i;
136 unsigned long limit;
137
138 limit = jiffies + HZ / 10;
139 for (i = 50000; i && time_after(limit, jiffies); i--)
140 if (!(inb(port + 0x0c) & 0x80)) {
141 outb(val, port + 0x0c);
142 return 0;
143 }
144 return -EBUSY;
145}
146
Bill Pemberton1bff2922012-12-06 12:35:21 -0500147static int snd_card_azt2320_enable_wss(unsigned long port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 int error;
150
Takashi Iwai115c4552021-06-08 16:04:47 +0200151 error = snd_card_azt2320_command(port, 0x09);
152 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return error;
Takashi Iwai115c4552021-06-08 16:04:47 +0200154 error = snd_card_azt2320_command(port, 0x00);
155 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return error;
157
158 mdelay(5);
159 return 0;
160}
161
Bill Pemberton1bff2922012-12-06 12:35:21 -0500162static int snd_card_azt2320_probe(int dev,
163 struct pnp_card_link *pcard,
164 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
166 int error;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100167 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 struct snd_card_azt2320 *acard;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200169 struct snd_wss *chip;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100170 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200172 error = snd_devm_card_new(&pcard->card->dev,
173 index[dev], id[dev], THIS_MODULE,
174 sizeof(struct snd_card_azt2320), &card);
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100175 if (error < 0)
176 return error;
Joe Perches9fe856e2010-09-04 18:52:54 -0700177 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Takashi Iwai115c4552021-06-08 16:04:47 +0200179 error = snd_card_azt2320_pnp(dev, acard, pcard, pid);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200180 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Takashi Iwai115c4552021-06-08 16:04:47 +0200183 error = snd_card_azt2320_enable_wss(port[dev]);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200184 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Krzysztof Helt7779f752008-07-31 21:03:41 +0200187 error = snd_wss_create(card, wss_port[dev], -1,
188 irq[dev],
189 dma1[dev], dma2[dev],
190 WSS_HW_DETECT, 0, &chip);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200191 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 strcpy(card->driver, "AZT2320");
195 strcpy(card->shortname, "Aztech AZT2320");
196 sprintf(card->longname, "%s, WSS at 0x%lx, irq %i, dma %i&%i",
197 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
198
Lars-Peter Clausenfa60c062015-01-02 12:24:43 +0100199 error = snd_wss_pcm(chip, 0);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200200 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return error;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200202 error = snd_wss_mixer(chip);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200203 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return error;
Lars-Peter Clausenfa60c062015-01-02 12:24:43 +0100205 error = snd_wss_timer(chip, 0);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200206 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
210 if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320,
211 mpu_port[dev], 0,
Clemens Ladischdba8b462011-09-13 11:24:41 +0200212 mpu_irq[dev], NULL) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
214 }
215
216 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
217 if (snd_opl3_create(card,
218 fm_port[dev], fm_port[dev] + 2,
219 OPL3_HW_AUTO, 0, &opl3) < 0) {
220 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
221 fm_port[dev], fm_port[dev] + 2);
222 } else {
Takashi Iwai115c4552021-06-08 16:04:47 +0200223 error = snd_opl3_timer_new(opl3, 1, 2);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200224 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return error;
Takashi Iwai115c4552021-06-08 16:04:47 +0200226 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200227 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
230 }
231
Takashi Iwai115c4552021-06-08 16:04:47 +0200232 error = snd_card_register(card);
Takashi Iwai39c4f9a2021-07-15 09:59:20 +0200233 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 pnp_set_card_drvdata(pcard, card);
236 return 0;
237}
238
Bill Pemberton1bff2922012-12-06 12:35:21 -0500239static unsigned int azt2320_devices;
Bjorn Helgaasdb2735e2006-03-27 01:17:10 -0800240
Bill Pemberton1bff2922012-12-06 12:35:21 -0500241static int snd_azt2320_pnp_detect(struct pnp_card_link *card,
242 const struct pnp_card_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 static int dev;
245 int res;
246
247 for ( ; dev < SNDRV_CARDS; dev++) {
248 if (!enable[dev])
249 continue;
250 res = snd_card_azt2320_probe(dev, card, id);
251 if (res < 0)
252 return res;
253 dev++;
Bjorn Helgaasdb2735e2006-03-27 01:17:10 -0800254 azt2320_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256 }
257 return -ENODEV;
258}
259
Takashi Iwaib6cc25c2005-11-17 17:04:12 +0100260#ifdef CONFIG_PM
261static int snd_azt2320_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
262{
263 struct snd_card *card = pnp_get_card_drvdata(pcard);
264 struct snd_card_azt2320 *acard = card->private_data;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200265 struct snd_wss *chip = acard->chip;
Takashi Iwaib6cc25c2005-11-17 17:04:12 +0100266
267 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
268 chip->suspend(chip);
269 return 0;
270}
271
272static int snd_azt2320_pnp_resume(struct pnp_card_link *pcard)
273{
274 struct snd_card *card = pnp_get_card_drvdata(pcard);
275 struct snd_card_azt2320 *acard = card->private_data;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200276 struct snd_wss *chip = acard->chip;
Takashi Iwaib6cc25c2005-11-17 17:04:12 +0100277
278 chip->resume(chip);
279 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
280 return 0;
281}
282#endif
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284static struct pnp_card_driver azt2320_pnpc_driver = {
285 .flags = PNP_DRIVER_RES_DISABLE,
286 .name = "azt2320",
287 .id_table = snd_azt2320_pnpids,
288 .probe = snd_azt2320_pnp_detect,
Takashi Iwaib6cc25c2005-11-17 17:04:12 +0100289#ifdef CONFIG_PM
290 .suspend = snd_azt2320_pnp_suspend,
291 .resume = snd_azt2320_pnp_resume,
292#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293};
294
295static int __init alsa_card_azt2320_init(void)
296{
Bjorn Helgaasdb2735e2006-03-27 01:17:10 -0800297 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Bjorn Helgaasdb2735e2006-03-27 01:17:10 -0800299 err = pnp_register_card_driver(&azt2320_pnpc_driver);
300 if (err)
301 return err;
302
303 if (!azt2320_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 pnp_unregister_card_driver(&azt2320_pnpc_driver);
Takashi Iwaib6cc25c2005-11-17 17:04:12 +0100305#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 snd_printk(KERN_ERR "no AZT2320 based soundcards found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307#endif
Takashi Iwaib6cc25c2005-11-17 17:04:12 +0100308 return -ENODEV;
309 }
310 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
313static void __exit alsa_card_azt2320_exit(void)
314{
315 pnp_unregister_card_driver(&azt2320_pnpc_driver);
316}
317
318module_init(alsa_card_azt2320_init)
319module_exit(alsa_card_azt2320_exit)