blob: f1ce30f379c9d5fa06ef68b62b5643b08596871c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*
3 card-als100.c - driver for Avance Logic ALS100 based soundcards.
4 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
5
6 Thanks to Pierfrancesco 'qM2' Passerini.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/init.h>
24#include <linux/wait.h>
25#include <linux/time.h>
26#include <linux/pnp.h>
27#include <linux/moduleparam.h>
28#include <sound/core.h>
29#include <sound/initval.h>
30#include <sound/mpu401.h>
31#include <sound/opl3.h>
32#include <sound/sb.h>
33
34#define PFX "als100: "
35
36MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
37MODULE_DESCRIPTION("Avance Logic ALS1X0");
38MODULE_LICENSE("GPL");
39MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP},"
40 "{Avance Logic,ALS110},"
41 "{Avance Logic,ALS120},"
42 "{Avance Logic,ALS200},"
43 "{3D Melody,MF1000},"
44 "{Digimate,3D Sound},"
45 "{Avance Logic,ALS120},"
46 "{RTL,RTL3000}}");
47
48static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
49static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
50static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
51static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
52static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
53static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
54static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
55static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
56static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
57static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
58
59module_param_array(index, int, NULL, 0444);
60MODULE_PARM_DESC(index, "Index value for als100 based soundcard.");
61module_param_array(id, charp, NULL, 0444);
62MODULE_PARM_DESC(id, "ID string for als100 based soundcard.");
63module_param_array(enable, bool, NULL, 0444);
64MODULE_PARM_DESC(enable, "Enable als100 based soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66struct snd_card_als100 {
67 int dev_no;
68 struct pnp_dev *dev;
69 struct pnp_dev *devmpu;
70 struct pnp_dev *devopl;
Takashi Iwai480615f2005-11-17 17:03:53 +010071 struct snd_sb *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072};
73
74static struct pnp_card_device_id snd_als100_pnpids[] = {
75 /* ALS100 - PRO16PNP */
76 { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
77 /* ALS110 - MF1000 - Digimate 3D Sound */
78 { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } },
79 /* ALS120 */
80 { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
81 /* ALS200 */
82 { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } },
83 /* ALS200 OEM */
84 { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } } },
85 /* RTL3000 */
86 { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
87 { .id = "", } /* end */
88};
89
90MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
91
92#define DRIVER_NAME "snd-card-als100"
93
94static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
95 struct pnp_card_link *card,
96 const struct pnp_card_device_id *id)
97{
98 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 int err;
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +0100102 if (acard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 return -ENODEV;
Rene Herman109c53f842007-11-30 17:59:25 +0100104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
106 acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->dev);
107
108 pdev = acard->dev;
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 err = pnp_activate_dev(pdev);
111 if (err < 0) {
112 snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 return err;
114 }
115 port[dev] = pnp_port_start(pdev, 0);
116 dma8[dev] = pnp_dma(pdev, 1);
117 dma16[dev] = pnp_dma(pdev, 0);
118 irq[dev] = pnp_irq(pdev, 0);
119
120 pdev = acard->devmpu;
121 if (pdev != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 err = pnp_activate_dev(pdev);
123 if (err < 0)
124 goto __mpu_error;
125 mpu_port[dev] = pnp_port_start(pdev, 0);
126 mpu_irq[dev] = pnp_irq(pdev, 0);
127 } else {
128 __mpu_error:
129 if (pdev) {
130 pnp_release_card_device(pdev);
131 snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
132 }
133 acard->devmpu = NULL;
134 mpu_port[dev] = -1;
135 }
136
137 pdev = acard->devopl;
138 if (pdev != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 err = pnp_activate_dev(pdev);
140 if (err < 0)
141 goto __fm_error;
142 fm_port[dev] = pnp_port_start(pdev, 0);
143 } else {
144 __fm_error:
145 if (pdev) {
146 pnp_release_card_device(pdev);
147 snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
148 }
149 acard->devopl = NULL;
150 fm_port[dev] = -1;
151 }
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 return 0;
154}
155
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800156static int __devinit snd_card_als100_probe(int dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 struct pnp_card_link *pcard,
158 const struct pnp_card_device_id *pid)
159{
160 int error;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100161 struct snd_sb *chip;
162 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 struct snd_card_als100 *acard;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100164 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
167 sizeof(struct snd_card_als100))) == NULL)
168 return -ENOMEM;
Takashi Iwai480615f2005-11-17 17:03:53 +0100169 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
172 snd_card_free(card);
173 return error;
174 }
175 snd_card_set_dev(card, &pcard->card->dev);
176
177 if ((error = snd_sbdsp_create(card, port[dev],
178 irq[dev],
179 snd_sb16dsp_interrupt,
180 dma8[dev],
181 dma16[dev],
182 SB_HW_ALS100, &chip)) < 0) {
183 snd_card_free(card);
184 return error;
185 }
Takashi Iwai480615f2005-11-17 17:03:53 +0100186 acard->chip = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 strcpy(card->driver, "ALS100");
189 strcpy(card->shortname, "Avance Logic ALS100");
190 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
191 card->shortname, chip->name, chip->port,
192 irq[dev], dma8[dev], dma16[dev]);
193
194 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
195 snd_card_free(card);
196 return error;
197 }
198
199 if ((error = snd_sbmixer_new(chip)) < 0) {
200 snd_card_free(card);
201 return error;
202 }
203
204 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
205 if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100,
206 mpu_port[dev], 0,
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700207 mpu_irq[dev], IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 NULL) < 0)
209 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
210 }
211
212 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
213 if (snd_opl3_create(card,
214 fm_port[dev], fm_port[dev] + 2,
215 OPL3_HW_AUTO, 0, &opl3) < 0) {
216 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
217 fm_port[dev], fm_port[dev] + 2);
218 } else {
219 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
220 snd_card_free(card);
221 return error;
222 }
223 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
224 snd_card_free(card);
225 return error;
226 }
227 }
228 }
229
230 if ((error = snd_card_register(card)) < 0) {
231 snd_card_free(card);
232 return error;
233 }
234 pnp_set_card_drvdata(pcard, card);
235 return 0;
236}
237
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800238static unsigned int __devinitdata als100_devices;
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static int __devinit snd_als100_pnp_detect(struct pnp_card_link *card,
241 const struct pnp_card_device_id *id)
242{
243 static int dev;
244 int res;
245
246 for ( ; dev < SNDRV_CARDS; dev++) {
247 if (!enable[dev])
248 continue;
249 res = snd_card_als100_probe(dev, card, id);
250 if (res < 0)
251 return res;
252 dev++;
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800253 als100_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 return 0;
255 }
256 return -ENODEV;
257}
258
259static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
260{
Takashi Iwai480615f2005-11-17 17:03:53 +0100261 snd_card_free(pnp_get_card_drvdata(pcard));
262 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
Takashi Iwai480615f2005-11-17 17:03:53 +0100265#ifdef CONFIG_PM
266static int snd_als100_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
267{
268 struct snd_card *card = pnp_get_card_drvdata(pcard);
269 struct snd_card_als100 *acard = card->private_data;
270 struct snd_sb *chip = acard->chip;
271
272 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
273 snd_pcm_suspend_all(chip->pcm);
274 snd_sbmixer_suspend(chip);
275 return 0;
276}
277
278static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
279{
280 struct snd_card *card = pnp_get_card_drvdata(pcard);
281 struct snd_card_als100 *acard = card->private_data;
282 struct snd_sb *chip = acard->chip;
283
284 snd_sbdsp_reset(chip);
285 snd_sbmixer_resume(chip);
286 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
287 return 0;
288}
289#endif
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291static struct pnp_card_driver als100_pnpc_driver = {
292 .flags = PNP_DRIVER_RES_DISABLE,
293 .name = "als100",
294 .id_table = snd_als100_pnpids,
295 .probe = snd_als100_pnp_detect,
296 .remove = __devexit_p(snd_als100_pnp_remove),
Takashi Iwai480615f2005-11-17 17:03:53 +0100297#ifdef CONFIG_PM
298 .suspend = snd_als100_pnp_suspend,
299 .resume = snd_als100_pnp_resume,
300#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301};
302
303static int __init alsa_card_als100_init(void)
304{
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800305 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800307 err = pnp_register_card_driver(&als100_pnpc_driver);
308 if (err)
309 return err;
310
311 if (!als100_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 pnp_unregister_card_driver(&als100_pnpc_driver);
Takashi Iwai480615f2005-11-17 17:03:53 +0100313#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315#endif
Takashi Iwai480615f2005-11-17 17:03:53 +0100316 return -ENODEV;
317 }
318 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
321static void __exit alsa_card_als100_exit(void)
322{
323 pnp_unregister_card_driver(&als100_pnpc_driver);
324}
325
326module_init(alsa_card_als100_init)
327module_exit(alsa_card_als100_exit)