blob: 3cb75bc9769927a303974783c7667b728eed798b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*
3 card-ad1816a.c - driver for ADI SoundPort AD1816A based soundcards.
4 Copyright (C) 2000 by Massimo Piccioni <dafastidio@libero.it>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/init.h>
22#include <linux/time.h>
23#include <linux/wait.h>
24#include <linux/pnp.h>
25#include <linux/moduleparam.h>
26#include <sound/core.h>
27#include <sound/initval.h>
28#include <sound/ad1816a.h>
29#include <sound/mpu401.h>
30#include <sound/opl3.h>
31
32#define PFX "ad1816a: "
33
34MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
35MODULE_DESCRIPTION("AD1816A, AD1815");
36MODULE_LICENSE("GPL");
37MODULE_SUPPORTED_DEVICE("{{Highscreen,Sound-Boostar 16 3D},"
38 "{Analog Devices,AD1815},"
39 "{Analog Devices,AD1816A},"
40 "{TerraTec,Base 64},"
41 "{TerraTec,AudioSystem EWS64S},"
42 "{Aztech/Newcom SC-16 3D},"
43 "{Shark Predator ISA}}");
44
45static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */
46static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
47static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
48static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
49static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
50static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
51static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
52static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
53static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
54static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
Takashi Iwai5b8f7f72005-08-03 14:02:47 +020055static int clockfreq[SNDRV_CARDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57module_param_array(index, int, NULL, 0444);
58MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard.");
59module_param_array(id, charp, NULL, 0444);
60MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard.");
61module_param_array(enable, bool, NULL, 0444);
62MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard.");
Takashi Iwai5b8f7f72005-08-03 14:02:47 +020063module_param_array(clockfreq, int, NULL, 0444);
64MODULE_PARM_DESC(clockfreq, "Clock frequency for ad1816a driver (default = 0).");
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66struct snd_card_ad1816a {
67 struct pnp_dev *dev;
68 struct pnp_dev *devmpu;
69};
70
71static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
72 /* Analog Devices AD1815 */
73 { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
Takashi Iwai92bb0102005-05-15 14:41:20 +020074 /* Analog Device AD1816? */
75 { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
77 { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
78 /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
79 { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
80 /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
81 { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
82 /* Highscreen Sound-Boostar 16 3D */
83 { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
84 /* Shark Predator ISA - added by Ken Arromdee */
85 { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Rene Herman36463a92008-08-21 23:07:43 +020086 /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Rene Herman36463a92008-08-21 23:07:43 +020088 /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
89 { .id = "TER1112", .devs = { { .id = "TER1100" }, { .id = "TER1101" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* Analog Devices AD1816A - Terratec Base 64 */
91 { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
92 /* end */
93 { .id = "" }
94};
95
96MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
97
98
99#define DRIVER_NAME "snd-card-ad1816a"
100
101
102static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard,
103 struct pnp_card_link *card,
104 const struct pnp_card_device_id *id)
105{
106 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 int err;
108
109 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +0100110 if (acard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return -EBUSY;
Rene Herman109c53f842007-11-30 17:59:25 +0100112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
114 if (acard->devmpu == NULL) {
Rask Ingemann Lambertsen29442752007-03-19 11:38:11 +0100115 mpu_port[dev] = -1;
116 snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
119 pdev = acard->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 err = pnp_activate_dev(pdev);
122 if (err < 0) {
123 printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 return -EBUSY;
125 }
126
127 port[dev] = pnp_port_start(pdev, 2);
128 fm_port[dev] = pnp_port_start(pdev, 1);
129 dma1[dev] = pnp_dma(pdev, 0);
130 dma2[dev] = pnp_dma(pdev, 1);
131 irq[dev] = pnp_irq(pdev, 0);
132
Rene Herman109c53f842007-11-30 17:59:25 +0100133 if (acard->devmpu == NULL)
Rask Ingemann Lambertsen29442752007-03-19 11:38:11 +0100134 return 0;
Rene Herman109c53f842007-11-30 17:59:25 +0100135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 pdev = acard->devmpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 err = pnp_activate_dev(pdev);
139 if (err < 0) {
140 printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
141 mpu_port[dev] = -1;
142 acard->devmpu = NULL;
143 } else {
144 mpu_port[dev] = pnp_port_start(pdev, 0);
145 mpu_irq[dev] = pnp_irq(pdev, 0);
146 }
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return 0;
149}
150
151static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
152 const struct pnp_card_device_id *pid)
153{
154 int error;
Takashi Iwaicbdd0dd2005-11-17 14:28:35 +0100155 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 struct snd_card_ad1816a *acard;
Takashi Iwaicbdd0dd2005-11-17 14:28:35 +0100157 struct snd_ad1816a *chip;
158 struct snd_opl3 *opl3;
Krzysztof Helta17ac452009-01-21 15:14:09 +0100159 struct snd_timer *timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100161 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
162 sizeof(struct snd_card_ad1816a), &card);
163 if (error < 0)
164 return error;
Joe Perches9fe856e2010-09-04 18:52:54 -0700165 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
168 snd_card_free(card);
169 return error;
170 }
171 snd_card_set_dev(card, &pcard->card->dev);
172
173 if ((error = snd_ad1816a_create(card, port[dev],
174 irq[dev],
175 dma1[dev],
176 dma2[dev],
177 &chip)) < 0) {
178 snd_card_free(card);
179 return error;
180 }
Takashi Iwai5b8f7f72005-08-03 14:02:47 +0200181 if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
182 chip->clock_freq = clockfreq[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 strcpy(card->driver, "AD1816A");
185 strcpy(card->shortname, "ADI SoundPort AD1816A");
186 sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
187 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
188
189 if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
190 snd_card_free(card);
191 return error;
192 }
193
194 if ((error = snd_ad1816a_mixer(chip)) < 0) {
195 snd_card_free(card);
196 return error;
197 }
198
Krzysztof Helta17ac452009-01-21 15:14:09 +0100199 error = snd_ad1816a_timer(chip, 0, &timer);
200 if (error < 0) {
201 snd_card_free(card);
202 return error;
203 }
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 if (mpu_port[dev] > 0) {
206 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700207 mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 NULL) < 0)
209 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
210 }
211
212 if (fm_port[dev] > 0) {
213 if (snd_opl3_create(card,
214 fm_port[dev], fm_port[dev] + 2,
215 OPL3_HW_AUTO, 0, &opl3) < 0) {
216 printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
217 } else {
Krzysztof Heltaa9c2932009-01-21 15:08:03 +0100218 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
219 if (error < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 snd_card_free(card);
221 return error;
222 }
223 }
224 }
225
226 if ((error = snd_card_register(card)) < 0) {
227 snd_card_free(card);
228 return error;
229 }
230 pnp_set_card_drvdata(pcard, card);
231 return 0;
232}
233
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800234static unsigned int __devinitdata ad1816a_devices;
235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
237 const struct pnp_card_device_id *id)
238{
239 static int dev;
240 int res;
241
242 for ( ; dev < SNDRV_CARDS; dev++) {
243 if (!enable[dev])
244 continue;
245 res = snd_card_ad1816a_probe(dev, card, id);
246 if (res < 0)
247 return res;
248 dev++;
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800249 ad1816a_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 return 0;
251 }
252 return -ENODEV;
253}
254
255static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
256{
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100257 snd_card_free(pnp_get_card_drvdata(pcard));
258 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
261static struct pnp_card_driver ad1816a_pnpc_driver = {
262 .flags = PNP_DRIVER_RES_DISABLE,
263 .name = "ad1816a",
264 .id_table = snd_ad1816a_pnpids,
265 .probe = snd_ad1816a_pnp_detect,
266 .remove = __devexit_p(snd_ad1816a_pnp_remove),
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100267 /* FIXME: suspend/resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268};
269
270static int __init alsa_card_ad1816a_init(void)
271{
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800272 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800274 err = pnp_register_card_driver(&ad1816a_pnpc_driver);
275 if (err)
276 return err;
277
278 if (!ad1816a_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100280#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 printk(KERN_ERR "no AD1816A based soundcards found.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#endif /* MODULE */
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100283 return -ENODEV;
284 }
285 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
288static void __exit alsa_card_ad1816a_exit(void)
289{
290 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
291}
292
293module_init(alsa_card_ad1816a_init)
294module_exit(alsa_card_ad1816a_exit)