blob: 35e25e5878e049356a2c2760fbca62796c831e3b [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
23#include <sound/driver.h>
24#include <linux/init.h>
25#include <linux/wait.h>
26#include <linux/time.h>
27#include <linux/pnp.h>
28#include <linux/moduleparam.h>
29#include <sound/core.h>
30#include <sound/initval.h>
31#include <sound/mpu401.h>
32#include <sound/opl3.h>
33#include <sound/sb.h>
34
35#define PFX "als100: "
36
37MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
38MODULE_DESCRIPTION("Avance Logic ALS1X0");
39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP},"
41 "{Avance Logic,ALS110},"
42 "{Avance Logic,ALS120},"
43 "{Avance Logic,ALS200},"
44 "{3D Melody,MF1000},"
45 "{Digimate,3D Sound},"
46 "{Avance Logic,ALS120},"
47 "{RTL,RTL3000}}");
48
49static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
50static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
51static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
52static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
53static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
54static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
55static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
56static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
57static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
58static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
59
60module_param_array(index, int, NULL, 0444);
61MODULE_PARM_DESC(index, "Index value for als100 based soundcard.");
62module_param_array(id, charp, NULL, 0444);
63MODULE_PARM_DESC(id, "ID string for als100 based soundcard.");
64module_param_array(enable, bool, NULL, 0444);
65MODULE_PARM_DESC(enable, "Enable als100 based soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67struct snd_card_als100 {
68 int dev_no;
69 struct pnp_dev *dev;
70 struct pnp_dev *devmpu;
71 struct pnp_dev *devopl;
Takashi Iwai480615f2005-11-17 17:03:53 +010072 struct snd_sb *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
75static struct pnp_card_device_id snd_als100_pnpids[] = {
76 /* ALS100 - PRO16PNP */
77 { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
78 /* ALS110 - MF1000 - Digimate 3D Sound */
79 { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } },
80 /* ALS120 */
81 { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
82 /* ALS200 */
83 { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } },
84 /* ALS200 OEM */
85 { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } } },
86 /* RTL3000 */
87 { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
88 { .id = "", } /* end */
89};
90
91MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
92
93#define DRIVER_NAME "snd-card-als100"
94
95static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
96 struct pnp_card_link *card,
97 const struct pnp_card_device_id *id)
98{
99 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 int err;
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +0100103 if (acard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 return -ENODEV;
Rene Herman109c53f842007-11-30 17:59:25 +0100105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
107 acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->dev);
108
109 pdev = acard->dev;
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 err = pnp_activate_dev(pdev);
112 if (err < 0) {
113 snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 return err;
115 }
116 port[dev] = pnp_port_start(pdev, 0);
117 dma8[dev] = pnp_dma(pdev, 1);
118 dma16[dev] = pnp_dma(pdev, 0);
119 irq[dev] = pnp_irq(pdev, 0);
120
121 pdev = acard->devmpu;
122 if (pdev != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 err = pnp_activate_dev(pdev);
124 if (err < 0)
125 goto __mpu_error;
126 mpu_port[dev] = pnp_port_start(pdev, 0);
127 mpu_irq[dev] = pnp_irq(pdev, 0);
128 } else {
129 __mpu_error:
130 if (pdev) {
131 pnp_release_card_device(pdev);
132 snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
133 }
134 acard->devmpu = NULL;
135 mpu_port[dev] = -1;
136 }
137
138 pdev = acard->devopl;
139 if (pdev != NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 err = pnp_activate_dev(pdev);
141 if (err < 0)
142 goto __fm_error;
143 fm_port[dev] = pnp_port_start(pdev, 0);
144 } else {
145 __fm_error:
146 if (pdev) {
147 pnp_release_card_device(pdev);
148 snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
149 }
150 acard->devopl = NULL;
151 fm_port[dev] = -1;
152 }
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 return 0;
155}
156
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800157static int __devinit snd_card_als100_probe(int dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 struct pnp_card_link *pcard,
159 const struct pnp_card_device_id *pid)
160{
161 int error;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100162 struct snd_sb *chip;
163 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 struct snd_card_als100 *acard;
Takashi Iwai11ff5c62005-11-17 14:42:36 +0100165 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
168 sizeof(struct snd_card_als100))) == NULL)
169 return -ENOMEM;
Takashi Iwai480615f2005-11-17 17:03:53 +0100170 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
173 snd_card_free(card);
174 return error;
175 }
176 snd_card_set_dev(card, &pcard->card->dev);
177
178 if ((error = snd_sbdsp_create(card, port[dev],
179 irq[dev],
180 snd_sb16dsp_interrupt,
181 dma8[dev],
182 dma16[dev],
183 SB_HW_ALS100, &chip)) < 0) {
184 snd_card_free(card);
185 return error;
186 }
Takashi Iwai480615f2005-11-17 17:03:53 +0100187 acard->chip = chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 strcpy(card->driver, "ALS100");
190 strcpy(card->shortname, "Avance Logic ALS100");
191 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
192 card->shortname, chip->name, chip->port,
193 irq[dev], dma8[dev], dma16[dev]);
194
195 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
196 snd_card_free(card);
197 return error;
198 }
199
200 if ((error = snd_sbmixer_new(chip)) < 0) {
201 snd_card_free(card);
202 return error;
203 }
204
205 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
206 if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100,
207 mpu_port[dev], 0,
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700208 mpu_irq[dev], IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 NULL) < 0)
210 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
211 }
212
213 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
214 if (snd_opl3_create(card,
215 fm_port[dev], fm_port[dev] + 2,
216 OPL3_HW_AUTO, 0, &opl3) < 0) {
217 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
218 fm_port[dev], fm_port[dev] + 2);
219 } else {
220 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
221 snd_card_free(card);
222 return error;
223 }
224 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
225 snd_card_free(card);
226 return error;
227 }
228 }
229 }
230
231 if ((error = snd_card_register(card)) < 0) {
232 snd_card_free(card);
233 return error;
234 }
235 pnp_set_card_drvdata(pcard, card);
236 return 0;
237}
238
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800239static unsigned int __devinitdata als100_devices;
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241static int __devinit snd_als100_pnp_detect(struct pnp_card_link *card,
242 const struct pnp_card_device_id *id)
243{
244 static int dev;
245 int res;
246
247 for ( ; dev < SNDRV_CARDS; dev++) {
248 if (!enable[dev])
249 continue;
250 res = snd_card_als100_probe(dev, card, id);
251 if (res < 0)
252 return res;
253 dev++;
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800254 als100_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return 0;
256 }
257 return -ENODEV;
258}
259
260static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
261{
Takashi Iwai480615f2005-11-17 17:03:53 +0100262 snd_card_free(pnp_get_card_drvdata(pcard));
263 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
Takashi Iwai480615f2005-11-17 17:03:53 +0100266#ifdef CONFIG_PM
267static int snd_als100_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
268{
269 struct snd_card *card = pnp_get_card_drvdata(pcard);
270 struct snd_card_als100 *acard = card->private_data;
271 struct snd_sb *chip = acard->chip;
272
273 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
274 snd_pcm_suspend_all(chip->pcm);
275 snd_sbmixer_suspend(chip);
276 return 0;
277}
278
279static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
280{
281 struct snd_card *card = pnp_get_card_drvdata(pcard);
282 struct snd_card_als100 *acard = card->private_data;
283 struct snd_sb *chip = acard->chip;
284
285 snd_sbdsp_reset(chip);
286 snd_sbmixer_resume(chip);
287 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
288 return 0;
289}
290#endif
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292static struct pnp_card_driver als100_pnpc_driver = {
293 .flags = PNP_DRIVER_RES_DISABLE,
294 .name = "als100",
295 .id_table = snd_als100_pnpids,
296 .probe = snd_als100_pnp_detect,
297 .remove = __devexit_p(snd_als100_pnp_remove),
Takashi Iwai480615f2005-11-17 17:03:53 +0100298#ifdef CONFIG_PM
299 .suspend = snd_als100_pnp_suspend,
300 .resume = snd_als100_pnp_resume,
301#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302};
303
304static int __init alsa_card_als100_init(void)
305{
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800306 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Bjorn Helgaas51427ec2006-03-27 01:17:09 -0800308 err = pnp_register_card_driver(&als100_pnpc_driver);
309 if (err)
310 return err;
311
312 if (!als100_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 pnp_unregister_card_driver(&als100_pnpc_driver);
Takashi Iwai480615f2005-11-17 17:03:53 +0100314#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316#endif
Takashi Iwai480615f2005-11-17 17:03:53 +0100317 return -ENODEV;
318 }
319 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320}
321
322static void __exit alsa_card_als100_exit(void)
323{
324 pnp_unregister_card_driver(&als100_pnpc_driver);
325}
326
327module_init(alsa_card_als100_init)
328module_exit(alsa_card_als100_exit)