blob: bacb7a1b930c0bd15d4bb52425a89fc2672c427a [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/*
4 card-als100.c - driver for Avance Logic ALS100 based soundcards.
5 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
Krzysztof Helt14ff3e72009-12-10 20:39:28 +01006 Copyright (C) 1999-2002 by Massimo Piccioni <dafastidio@libero.it>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8 Thanks to Pierfrancesco 'qM2' Passerini.
9
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010010 Generalised for soundcards based on DT-0196 and ALS-007 chips
Jonathan Woithe409a3e92012-03-27 13:01:01 +103011 by Jonathan Woithe <jwoithe@just42.net>: June 2002.
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013*/
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/init.h>
16#include <linux/wait.h>
17#include <linux/time.h>
18#include <linux/pnp.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040019#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <sound/core.h>
21#include <sound/initval.h>
22#include <sound/mpu401.h>
23#include <sound/opl3.h>
24#include <sound/sb.h>
25
26#define PFX "als100: "
27
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010028MODULE_DESCRIPTION("Avance Logic ALS007/ALS1X0");
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010029MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
30MODULE_LICENSE("GPL");
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
33static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103034static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
36static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
37static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
38static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
39static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
40static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
41static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
42
43module_param_array(index, int, NULL, 0444);
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010044MODULE_PARM_DESC(index, "Index value for Avance Logic based soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070045module_param_array(id, charp, NULL, 0444);
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010046MODULE_PARM_DESC(id, "ID string for Avance Logic based soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070047module_param_array(enable, bool, NULL, 0444);
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010048MODULE_PARM_DESC(enable, "Enable Avance Logic based soundcard.");
49
50MODULE_ALIAS("snd-dt019x");
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52struct snd_card_als100 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 struct pnp_dev *dev;
54 struct pnp_dev *devmpu;
55 struct pnp_dev *devopl;
Takashi Iwai480615f2005-11-17 17:03:53 +010056 struct snd_sb *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057};
58
Arvind Yadav815cfec2017-08-17 15:36:20 +053059static const struct pnp_card_device_id snd_als100_pnpids[] = {
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010060 /* DT197A30 */
61 { .id = "RWB1688",
62 .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
63 .driver_data = SB_HW_DT019X },
64 /* DT0196 / ALS-007 */
65 { .id = "ALS0007",
66 .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
67 .driver_data = SB_HW_DT019X },
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 /* ALS100 - PRO16PNP */
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010069 { .id = "ALS0001",
70 .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
71 .driver_data = SB_HW_ALS100 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 /* ALS110 - MF1000 - Digimate 3D Sound */
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010073 { .id = "ALS0110",
74 .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } },
75 .driver_data = SB_HW_ALS100 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 /* ALS120 */
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010077 { .id = "ALS0120",
78 .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
79 .driver_data = SB_HW_ALS100 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 /* ALS200 */
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010081 { .id = "ALS0200",
82 .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } },
83 .driver_data = SB_HW_ALS100 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 /* ALS200 OEM */
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010085 { .id = "ALS0200",
86 .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } },
87 .driver_data = SB_HW_ALS100 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 /* RTL3000 */
Krzysztof Helt14ff3e72009-12-10 20:39:28 +010089 { .id = "RTL3000",
90 .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
91 .driver_data = SB_HW_ALS100 },
92 { .id = "" } /* end */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
95MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
96
Bill Pemberton1bff2922012-12-06 12:35:21 -050097static int snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
98 struct pnp_card_link *card,
99 const struct pnp_card_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100{
101 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 int err;
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +0100105 if (acard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 return -ENODEV;
Rene Herman109c53f842007-11-30 17:59:25 +0100107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
109 acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->dev);
110
111 pdev = acard->dev;
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 err = pnp_activate_dev(pdev);
114 if (err < 0) {
115 snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return err;
117 }
118 port[dev] = pnp_port_start(pdev, 0);
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100119 if (id->driver_data == SB_HW_DT019X)
120 dma8[dev] = pnp_dma(pdev, 0);
121 else {
122 dma8[dev] = pnp_dma(pdev, 1);
123 dma16[dev] = pnp_dma(pdev, 0);
124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 irq[dev] = pnp_irq(pdev, 0);
126
127 pdev = acard->devmpu;
128 if (pdev != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 err = pnp_activate_dev(pdev);
130 if (err < 0)
131 goto __mpu_error;
132 mpu_port[dev] = pnp_port_start(pdev, 0);
133 mpu_irq[dev] = pnp_irq(pdev, 0);
134 } else {
135 __mpu_error:
136 if (pdev) {
137 pnp_release_card_device(pdev);
138 snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
139 }
140 acard->devmpu = NULL;
141 mpu_port[dev] = -1;
142 }
143
144 pdev = acard->devopl;
145 if (pdev != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 err = pnp_activate_dev(pdev);
147 if (err < 0)
148 goto __fm_error;
149 fm_port[dev] = pnp_port_start(pdev, 0);
150 } else {
151 __fm_error:
152 if (pdev) {
153 pnp_release_card_device(pdev);
154 snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
155 }
156 acard->devopl = NULL;
157 fm_port[dev] = -1;
158 }
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 return 0;
161}
162
Bill Pemberton1bff2922012-12-06 12:35:21 -0500163static int snd_card_als100_probe(int dev,
164 struct pnp_card_link *pcard,
165 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
167 int error;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100168 struct snd_sb *chip;
169 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct snd_card_als100 *acard;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100171 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Takashi Iwai4323cc42014-01-29 13:03:56 +0100173 error = snd_card_new(&pcard->card->dev,
174 index[dev], id[dev], THIS_MODULE,
175 sizeof(struct snd_card_als100), &card);
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100176 if (error < 0)
177 return error;
Takashi Iwai480615f2005-11-17 17:03:53 +0100178 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
181 snd_card_free(card);
182 return error;
183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100185 if (pid->driver_data == SB_HW_DT019X)
186 dma16[dev] = -1;
187
188 error = snd_sbdsp_create(card, port[dev], irq[dev],
189 snd_sb16dsp_interrupt,
190 dma8[dev], dma16[dev],
191 pid->driver_data,
192 &chip);
193 if (error < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 snd_card_free(card);
195 return error;
196 }
Takashi Iwai480615f2005-11-17 17:03:53 +0100197 acard->chip = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100199 if (pid->driver_data == SB_HW_DT019X) {
200 strcpy(card->driver, "DT-019X");
201 strcpy(card->shortname, "Diamond Tech. DT-019X");
Arnd Bergmann8a463632017-07-18 13:48:04 +0200202 snprintf(card->longname, sizeof(card->longname),
203 "Diamond Tech. DT-019X, %s at 0x%lx, irq %d, dma %d",
204 chip->name, chip->port, irq[dev], dma8[dev]);
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100205 } else {
206 strcpy(card->driver, "ALS100");
207 strcpy(card->shortname, "Avance Logic ALS100");
Arnd Bergmann8a463632017-07-18 13:48:04 +0200208 snprintf(card->longname, sizeof(card->longname),
209 "Avance Logic ALS100, %s at 0x%lx, irq %d, dma %d&%d",
210 chip->name, chip->port, irq[dev], dma8[dev],
211 dma16[dev]);
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Lars-Peter Clausen92533f12015-01-02 12:24:42 +0100214 if ((error = snd_sb16dsp_pcm(chip, 0)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 snd_card_free(card);
216 return error;
217 }
218
219 if ((error = snd_sbmixer_new(chip)) < 0) {
220 snd_card_free(card);
221 return error;
222 }
223
224 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100225 int mpu_type = MPU401_HW_ALS100;
226
227 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
228 mpu_irq[dev] = -1;
229
230 if (pid->driver_data == SB_HW_DT019X)
231 mpu_type = MPU401_HW_MPU401;
232
233 if (snd_mpu401_uart_new(card, 0,
234 mpu_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 mpu_port[dev], 0,
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100236 mpu_irq[dev],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 NULL) < 0)
238 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
239 }
240
241 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
242 if (snd_opl3_create(card,
243 fm_port[dev], fm_port[dev] + 2,
244 OPL3_HW_AUTO, 0, &opl3) < 0) {
245 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
246 fm_port[dev], fm_port[dev] + 2);
247 } else {
248 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
249 snd_card_free(card);
250 return error;
251 }
252 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
253 snd_card_free(card);
254 return error;
255 }
256 }
257 }
258
259 if ((error = snd_card_register(card)) < 0) {
260 snd_card_free(card);
261 return error;
262 }
263 pnp_set_card_drvdata(pcard, card);
264 return 0;
265}
266
Bill Pemberton1bff2922012-12-06 12:35:21 -0500267static unsigned int als100_devices;
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800268
Bill Pemberton1bff2922012-12-06 12:35:21 -0500269static int snd_als100_pnp_detect(struct pnp_card_link *card,
270 const struct pnp_card_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 static int dev;
273 int res;
274
275 for ( ; dev < SNDRV_CARDS; dev++) {
276 if (!enable[dev])
277 continue;
278 res = snd_card_als100_probe(dev, card, id);
279 if (res < 0)
280 return res;
281 dev++;
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800282 als100_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 return 0;
284 }
285 return -ENODEV;
286}
287
Bill Pemberton1bff2922012-12-06 12:35:21 -0500288static void snd_als100_pnp_remove(struct pnp_card_link *pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Takashi Iwai480615f2005-11-17 17:03:53 +0100290 snd_card_free(pnp_get_card_drvdata(pcard));
291 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
293
Takashi Iwai480615f2005-11-17 17:03:53 +0100294#ifdef CONFIG_PM
295static int snd_als100_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
296{
297 struct snd_card *card = pnp_get_card_drvdata(pcard);
298 struct snd_card_als100 *acard = card->private_data;
299 struct snd_sb *chip = acard->chip;
300
301 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
Takashi Iwai480615f2005-11-17 17:03:53 +0100302 snd_sbmixer_suspend(chip);
303 return 0;
304}
305
306static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
307{
308 struct snd_card *card = pnp_get_card_drvdata(pcard);
309 struct snd_card_als100 *acard = card->private_data;
310 struct snd_sb *chip = acard->chip;
311
312 snd_sbdsp_reset(chip);
313 snd_sbmixer_resume(chip);
314 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
315 return 0;
316}
317#endif
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319static struct pnp_card_driver als100_pnpc_driver = {
320 .flags = PNP_DRIVER_RES_DISABLE,
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100321 .name = "als100",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 .id_table = snd_als100_pnpids,
323 .probe = snd_als100_pnp_detect,
Bill Pemberton1bff2922012-12-06 12:35:21 -0500324 .remove = snd_als100_pnp_remove,
Takashi Iwai480615f2005-11-17 17:03:53 +0100325#ifdef CONFIG_PM
326 .suspend = snd_als100_pnp_suspend,
327 .resume = snd_als100_pnp_resume,
328#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329};
330
331static int __init alsa_card_als100_init(void)
332{
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800333 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800335 err = pnp_register_card_driver(&als100_pnpc_driver);
336 if (err)
337 return err;
338
339 if (!als100_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 pnp_unregister_card_driver(&als100_pnpc_driver);
Takashi Iwai480615f2005-11-17 17:03:53 +0100341#ifdef MODULE
Krzysztof Helt14ff3e72009-12-10 20:39:28 +0100342 snd_printk(KERN_ERR "no Avance Logic based soundcards found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343#endif
Takashi Iwai480615f2005-11-17 17:03:53 +0100344 return -ENODEV;
345 }
346 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
349static void __exit alsa_card_als100_exit(void)
350{
351 pnp_unregister_card_driver(&als100_pnpc_driver);
352}
353
354module_init(alsa_card_als100_init)
355module_exit(alsa_card_als100_exit)