blob: 994bc85376c1660d6054e59ad5be8e5b31930eb1 [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
21#include <sound/driver.h>
22#include <linux/init.h>
23#include <linux/time.h>
24#include <linux/wait.h>
25#include <linux/pnp.h>
26#include <linux/moduleparam.h>
27#include <sound/core.h>
28#include <sound/initval.h>
29#include <sound/ad1816a.h>
30#include <sound/mpu401.h>
31#include <sound/opl3.h>
32
33#define PFX "ad1816a: "
34
35MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
36MODULE_DESCRIPTION("AD1816A, AD1815");
37MODULE_LICENSE("GPL");
38MODULE_SUPPORTED_DEVICE("{{Highscreen,Sound-Boostar 16 3D},"
39 "{Analog Devices,AD1815},"
40 "{Analog Devices,AD1816A},"
41 "{TerraTec,Base 64},"
42 "{TerraTec,AudioSystem EWS64S},"
43 "{Aztech/Newcom SC-16 3D},"
44 "{Shark Predator ISA}}");
45
46static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */
47static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
48static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
49static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
50static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
51static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
52static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
53static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */
54static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
55static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
Takashi Iwai5b8f7f72005-08-03 14:02:47 +020056static int clockfreq[SNDRV_CARDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58module_param_array(index, int, NULL, 0444);
59MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard.");
60module_param_array(id, charp, NULL, 0444);
61MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard.");
62module_param_array(enable, bool, NULL, 0444);
63MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard.");
Takashi Iwai5b8f7f72005-08-03 14:02:47 +020064module_param_array(clockfreq, int, NULL, 0444);
65MODULE_PARM_DESC(clockfreq, "Clock frequency for ad1816a driver (default = 0).");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67struct snd_card_ad1816a {
68 struct pnp_dev *dev;
69 struct pnp_dev *devmpu;
70};
71
72static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
73 /* Analog Devices AD1815 */
74 { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
Takashi Iwai92bb0102005-05-15 14:41:20 +020075 /* Analog Device AD1816? */
76 { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
78 { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
79 /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
80 { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
81 /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
82 { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
83 /* Highscreen Sound-Boostar 16 3D */
84 { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
85 /* Shark Predator ISA - added by Ken Arromdee */
86 { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
87 /* Analog Devices AD1816A - Terratec AudioSystem EWS64S */
88 { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
89 /* Analog Devices AD1816A - Terratec Base 64 */
90 { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
91 /* end */
92 { .id = "" }
93};
94
95MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
96
97
98#define DRIVER_NAME "snd-card-ad1816a"
99
100
101static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard,
102 struct pnp_card_link *card,
103 const struct pnp_card_device_id *id)
104{
105 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 int err;
107
108 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
Rene Herman109c53f842007-11-30 17:59:25 +0100109 if (acard->dev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return -EBUSY;
Rene Herman109c53f842007-11-30 17:59:25 +0100111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
113 if (acard->devmpu == NULL) {
Rask Ingemann Lambertsen29442752007-03-19 11:38:11 +0100114 mpu_port[dev] = -1;
115 snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117
118 pdev = acard->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 err = pnp_activate_dev(pdev);
121 if (err < 0) {
122 printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return -EBUSY;
124 }
125
126 port[dev] = pnp_port_start(pdev, 2);
127 fm_port[dev] = pnp_port_start(pdev, 1);
128 dma1[dev] = pnp_dma(pdev, 0);
129 dma2[dev] = pnp_dma(pdev, 1);
130 irq[dev] = pnp_irq(pdev, 0);
131
Rene Herman109c53f842007-11-30 17:59:25 +0100132 if (acard->devmpu == NULL)
Rask Ingemann Lambertsen29442752007-03-19 11:38:11 +0100133 return 0;
Rene Herman109c53f842007-11-30 17:59:25 +0100134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 pdev = acard->devmpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 err = pnp_activate_dev(pdev);
138 if (err < 0) {
139 printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
140 mpu_port[dev] = -1;
141 acard->devmpu = NULL;
142 } else {
143 mpu_port[dev] = pnp_port_start(pdev, 0);
144 mpu_irq[dev] = pnp_irq(pdev, 0);
145 }
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return 0;
148}
149
150static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
151 const struct pnp_card_device_id *pid)
152{
153 int error;
Takashi Iwaicbdd0dd2005-11-17 14:28:35 +0100154 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 struct snd_card_ad1816a *acard;
Takashi Iwaicbdd0dd2005-11-17 14:28:35 +0100156 struct snd_ad1816a *chip;
157 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
160 sizeof(struct snd_card_ad1816a))) == NULL)
161 return -ENOMEM;
162 acard = (struct snd_card_ad1816a *)card->private_data;
163
164 if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
165 snd_card_free(card);
166 return error;
167 }
168 snd_card_set_dev(card, &pcard->card->dev);
169
170 if ((error = snd_ad1816a_create(card, port[dev],
171 irq[dev],
172 dma1[dev],
173 dma2[dev],
174 &chip)) < 0) {
175 snd_card_free(card);
176 return error;
177 }
Takashi Iwai5b8f7f72005-08-03 14:02:47 +0200178 if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
179 chip->clock_freq = clockfreq[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 strcpy(card->driver, "AD1816A");
182 strcpy(card->shortname, "ADI SoundPort AD1816A");
183 sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
184 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
185
186 if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
187 snd_card_free(card);
188 return error;
189 }
190
191 if ((error = snd_ad1816a_mixer(chip)) < 0) {
192 snd_card_free(card);
193 return error;
194 }
195
196 if (mpu_port[dev] > 0) {
197 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700198 mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 NULL) < 0)
200 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
201 }
202
203 if (fm_port[dev] > 0) {
204 if (snd_opl3_create(card,
205 fm_port[dev], fm_port[dev] + 2,
206 OPL3_HW_AUTO, 0, &opl3) < 0) {
207 printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
208 } else {
209 if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) {
210 snd_card_free(card);
211 return error;
212 }
213 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
214 snd_card_free(card);
215 return error;
216 }
217 }
218 }
219
220 if ((error = snd_card_register(card)) < 0) {
221 snd_card_free(card);
222 return error;
223 }
224 pnp_set_card_drvdata(pcard, card);
225 return 0;
226}
227
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800228static unsigned int __devinitdata ad1816a_devices;
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
231 const struct pnp_card_device_id *id)
232{
233 static int dev;
234 int res;
235
236 for ( ; dev < SNDRV_CARDS; dev++) {
237 if (!enable[dev])
238 continue;
239 res = snd_card_ad1816a_probe(dev, card, id);
240 if (res < 0)
241 return res;
242 dev++;
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800243 ad1816a_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return 0;
245 }
246 return -ENODEV;
247}
248
249static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
250{
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100251 snd_card_free(pnp_get_card_drvdata(pcard));
252 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
255static struct pnp_card_driver ad1816a_pnpc_driver = {
256 .flags = PNP_DRIVER_RES_DISABLE,
257 .name = "ad1816a",
258 .id_table = snd_ad1816a_pnpids,
259 .probe = snd_ad1816a_pnp_detect,
260 .remove = __devexit_p(snd_ad1816a_pnp_remove),
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100261 /* FIXME: suspend/resume */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262};
263
264static int __init alsa_card_ad1816a_init(void)
265{
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800266 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800268 err = pnp_register_card_driver(&ad1816a_pnpc_driver);
269 if (err)
270 return err;
271
272 if (!ad1816a_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100274#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 printk(KERN_ERR "no AD1816A based soundcards found.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276#endif /* MODULE */
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100277 return -ENODEV;
278 }
279 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
282static void __exit alsa_card_ad1816a_exit(void)
283{
284 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
285}
286
287module_init(alsa_card_ad1816a_init)
288module_exit(alsa_card_ad1816a_exit)