blob: f481a41e027eb132a2acfd1632f8351fe4daa8b6 [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>
Paul Gortmaker65a77212011-07-15 13:13:37 -040025#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#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 */
Rusty Russella67ff6a2011-12-15 13:49:36 +103047static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
67 /* Analog Devices AD1815 */
68 { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
Takashi Iwai92bb0102005-05-15 14:41:20 +020069 /* Analog Device AD1816? */
70 { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
72 { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
73 /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
74 { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } },
75 /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */
76 { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
77 /* Highscreen Sound-Boostar 16 3D */
78 { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
79 /* Shark Predator ISA - added by Ken Arromdee */
80 { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Rene Herman36463a92008-08-21 23:07:43 +020081 /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
Rene Herman36463a92008-08-21 23:07:43 +020083 /* Analog Devices AD1816A - Terratec AudioSystem EWS64 S */
84 { .id = "TER1112", .devs = { { .id = "TER1100" }, { .id = "TER1101" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 /* Analog Devices AD1816A - Terratec Base 64 */
86 { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
87 /* end */
88 { .id = "" }
89};
90
91MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids);
92
93
94#define DRIVER_NAME "snd-card-ad1816a"
95
96
Bill Pemberton1bff2922012-12-06 12:35:21 -050097static int snd_card_ad1816a_pnp(int dev, struct pnp_card_link *card,
98 const struct pnp_card_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
100 struct pnp_dev *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 int err;
102
Ondrej Zaryc86b6b42012-08-19 23:27:19 +0200103 pdev = pnp_request_card_device(card, id->devs[0].id, NULL);
104 if (pdev == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 return -EBUSY;
Rene Herman109c53f842007-11-30 17:59:25 +0100106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 err = pnp_activate_dev(pdev);
108 if (err < 0) {
109 printk(KERN_ERR PFX "AUDIO PnP configure failure\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return -EBUSY;
111 }
112
113 port[dev] = pnp_port_start(pdev, 2);
114 fm_port[dev] = pnp_port_start(pdev, 1);
115 dma1[dev] = pnp_dma(pdev, 0);
116 dma2[dev] = pnp_dma(pdev, 1);
117 irq[dev] = pnp_irq(pdev, 0);
118
Ondrej Zaryc86b6b42012-08-19 23:27:19 +0200119 pdev = pnp_request_card_device(card, id->devs[1].id, NULL);
120 if (pdev == NULL) {
121 mpu_port[dev] = -1;
122 snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n");
Rask Ingemann Lambertsen29442752007-03-19 11:38:11 +0100123 return 0;
Ondrej Zaryc86b6b42012-08-19 23:27:19 +0200124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 err = pnp_activate_dev(pdev);
127 if (err < 0) {
128 printk(KERN_ERR PFX "MPU401 PnP configure failure\n");
129 mpu_port[dev] = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 } else {
131 mpu_port[dev] = pnp_port_start(pdev, 0);
132 mpu_irq[dev] = pnp_irq(pdev, 0);
133 }
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 return 0;
136}
137
Bill Pemberton1bff2922012-12-06 12:35:21 -0500138static int snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard,
139 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 int error;
Takashi Iwaicbdd0dd2005-11-17 14:28:35 +0100142 struct snd_card *card;
Takashi Iwaicbdd0dd2005-11-17 14:28:35 +0100143 struct snd_ad1816a *chip;
144 struct snd_opl3 *opl3;
Krzysztof Helta17ac452009-01-21 15:14:09 +0100145 struct snd_timer *timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Takashi Iwai4323cc42014-01-29 13:03:56 +0100147 error = snd_card_new(&pcard->card->dev,
148 index[dev], id[dev], THIS_MODULE,
149 sizeof(struct snd_ad1816a), &card);
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100150 if (error < 0)
151 return error;
Ondrej Zaryc86b6b42012-08-19 23:27:19 +0200152 chip = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Ondrej Zaryc86b6b42012-08-19 23:27:19 +0200154 if ((error = snd_card_ad1816a_pnp(dev, pcard, pid))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 snd_card_free(card);
156 return error;
157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 if ((error = snd_ad1816a_create(card, port[dev],
160 irq[dev],
161 dma1[dev],
162 dma2[dev],
Ondrej Zaryc86b6b42012-08-19 23:27:19 +0200163 chip)) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 snd_card_free(card);
165 return error;
166 }
Takashi Iwai5b8f7f72005-08-03 14:02:47 +0200167 if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
168 chip->clock_freq = clockfreq[dev];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 strcpy(card->driver, "AD1816A");
171 strcpy(card->shortname, "ADI SoundPort AD1816A");
172 sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d",
173 card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]);
174
175 if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) {
176 snd_card_free(card);
177 return error;
178 }
179
180 if ((error = snd_ad1816a_mixer(chip)) < 0) {
181 snd_card_free(card);
182 return error;
183 }
184
Krzysztof Helta17ac452009-01-21 15:14:09 +0100185 error = snd_ad1816a_timer(chip, 0, &timer);
186 if (error < 0) {
187 snd_card_free(card);
188 return error;
189 }
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if (mpu_port[dev] > 0) {
192 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
Clemens Ladischdba8b462011-09-13 11:24:41 +0200193 mpu_port[dev], 0, mpu_irq[dev],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 NULL) < 0)
195 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
196 }
197
198 if (fm_port[dev] > 0) {
199 if (snd_opl3_create(card,
200 fm_port[dev], fm_port[dev] + 2,
201 OPL3_HW_AUTO, 0, &opl3) < 0) {
202 printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
203 } else {
Krzysztof Heltaa9c2932009-01-21 15:08:03 +0100204 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
205 if (error < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 snd_card_free(card);
207 return error;
208 }
209 }
210 }
211
212 if ((error = snd_card_register(card)) < 0) {
213 snd_card_free(card);
214 return error;
215 }
216 pnp_set_card_drvdata(pcard, card);
217 return 0;
218}
219
Bill Pemberton1bff2922012-12-06 12:35:21 -0500220static unsigned int ad1816a_devices;
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800221
Bill Pemberton1bff2922012-12-06 12:35:21 -0500222static int snd_ad1816a_pnp_detect(struct pnp_card_link *card,
223 const struct pnp_card_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
225 static int dev;
226 int res;
227
228 for ( ; dev < SNDRV_CARDS; dev++) {
229 if (!enable[dev])
230 continue;
231 res = snd_card_ad1816a_probe(dev, card, id);
232 if (res < 0)
233 return res;
234 dev++;
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800235 ad1816a_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return 0;
237 }
238 return -ENODEV;
239}
240
Bill Pemberton1bff2922012-12-06 12:35:21 -0500241static void snd_ad1816a_pnp_remove(struct pnp_card_link *pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100243 snd_card_free(pnp_get_card_drvdata(pcard));
244 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Ondrej Zary6f0fa662012-08-19 23:27:26 +0200247#ifdef CONFIG_PM
248static int snd_ad1816a_pnp_suspend(struct pnp_card_link *pcard,
249 pm_message_t state)
250{
251 struct snd_card *card = pnp_get_card_drvdata(pcard);
252
253 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
254 snd_ad1816a_suspend(card->private_data);
255 return 0;
256}
257
258static int snd_ad1816a_pnp_resume(struct pnp_card_link *pcard)
259{
260 struct snd_card *card = pnp_get_card_drvdata(pcard);
261
262 snd_ad1816a_resume(card->private_data);
263 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
264 return 0;
265}
266#endif
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268static struct pnp_card_driver ad1816a_pnpc_driver = {
269 .flags = PNP_DRIVER_RES_DISABLE,
270 .name = "ad1816a",
271 .id_table = snd_ad1816a_pnpids,
272 .probe = snd_ad1816a_pnp_detect,
Bill Pemberton1bff2922012-12-06 12:35:21 -0500273 .remove = snd_ad1816a_pnp_remove,
Ondrej Zary6f0fa662012-08-19 23:27:26 +0200274#ifdef CONFIG_PM
275 .suspend = snd_ad1816a_pnp_suspend,
276 .resume = snd_ad1816a_pnp_resume,
277#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278};
279
280static int __init alsa_card_ad1816a_init(void)
281{
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800282 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Bjorn Helgaas5f53f4e2006-03-27 01:17:08 -0800284 err = pnp_register_card_driver(&ad1816a_pnpc_driver);
285 if (err)
286 return err;
287
288 if (!ad1816a_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100290#ifdef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 printk(KERN_ERR "no AD1816A based soundcards found.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292#endif /* MODULE */
Takashi Iwai175cdcf2005-11-17 17:05:02 +0100293 return -ENODEV;
294 }
295 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
298static void __exit alsa_card_ad1816a_exit(void)
299{
300 pnp_unregister_card_driver(&ad1816a_pnpc_driver);
301}
302
303module_init(alsa_card_ad1816a_init)
304module_exit(alsa_card_ad1816a_exit)