Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 35 | MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); |
| 36 | MODULE_DESCRIPTION("AD1816A, AD1815"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | MODULE_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 | |
| 46 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 1-MAX */ |
| 47 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 48 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ |
| 49 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 50 | static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 51 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 52 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */ |
| 53 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* Pnp setup */ |
| 54 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */ |
| 55 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */ |
Takashi Iwai | 5b8f7f7 | 2005-08-03 14:02:47 +0200 | [diff] [blame] | 56 | static int clockfreq[SNDRV_CARDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | module_param_array(index, int, NULL, 0444); |
| 59 | MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard."); |
| 60 | module_param_array(id, charp, NULL, 0444); |
| 61 | MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard."); |
| 62 | module_param_array(enable, bool, NULL, 0444); |
| 63 | MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard."); |
| 64 | module_param_array(port, long, NULL, 0444); |
| 65 | MODULE_PARM_DESC(port, "Port # for ad1816a driver."); |
| 66 | module_param_array(mpu_port, long, NULL, 0444); |
| 67 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ad1816a driver."); |
| 68 | module_param_array(fm_port, long, NULL, 0444); |
| 69 | MODULE_PARM_DESC(fm_port, "FM port # for ad1816a driver."); |
| 70 | module_param_array(irq, int, NULL, 0444); |
| 71 | MODULE_PARM_DESC(irq, "IRQ # for ad1816a driver."); |
| 72 | module_param_array(mpu_irq, int, NULL, 0444); |
| 73 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ad1816a driver."); |
| 74 | module_param_array(dma1, int, NULL, 0444); |
| 75 | MODULE_PARM_DESC(dma1, "1st DMA # for ad1816a driver."); |
| 76 | module_param_array(dma2, int, NULL, 0444); |
| 77 | MODULE_PARM_DESC(dma2, "2nd DMA # for ad1816a driver."); |
Takashi Iwai | 5b8f7f7 | 2005-08-03 14:02:47 +0200 | [diff] [blame] | 78 | module_param_array(clockfreq, int, NULL, 0444); |
| 79 | MODULE_PARM_DESC(clockfreq, "Clock frequency for ad1816a driver (default = 0)."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | struct snd_card_ad1816a { |
| 82 | struct pnp_dev *dev; |
| 83 | struct pnp_dev *devmpu; |
| 84 | }; |
| 85 | |
| 86 | static struct pnp_card_device_id snd_ad1816a_pnpids[] = { |
| 87 | /* Analog Devices AD1815 */ |
| 88 | { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } }, |
Takashi Iwai | 92bb010 | 2005-05-15 14:41:20 +0200 | [diff] [blame] | 89 | /* Analog Device AD1816? */ |
| 90 | { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */ |
| 92 | { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, |
| 93 | /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */ |
| 94 | { .id = "AZT1022", .devs = { { .id = "AZT1018" }, { .id = "AZT2002" } } }, |
| 95 | /* Highscreen Sound-Boostar 16 3D - added by Stefan Behnel */ |
| 96 | { .id = "LWC1061", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, |
| 97 | /* Highscreen Sound-Boostar 16 3D */ |
| 98 | { .id = "MDK1605", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, |
| 99 | /* Shark Predator ISA - added by Ken Arromdee */ |
| 100 | { .id = "SMM7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, |
| 101 | /* Analog Devices AD1816A - Terratec AudioSystem EWS64S */ |
| 102 | { .id = "TER1112", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, |
| 103 | /* Analog Devices AD1816A - Terratec Base 64 */ |
| 104 | { .id = "TER1411", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } }, |
| 105 | /* end */ |
| 106 | { .id = "" } |
| 107 | }; |
| 108 | |
| 109 | MODULE_DEVICE_TABLE(pnp_card, snd_ad1816a_pnpids); |
| 110 | |
| 111 | |
| 112 | #define DRIVER_NAME "snd-card-ad1816a" |
| 113 | |
| 114 | |
| 115 | static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acard, |
| 116 | struct pnp_card_link *card, |
| 117 | const struct pnp_card_device_id *id) |
| 118 | { |
| 119 | struct pnp_dev *pdev; |
| 120 | struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL); |
| 121 | int err; |
| 122 | |
Amit Choudhary | b1e8a79 | 2006-10-09 16:03:52 +0200 | [diff] [blame] | 123 | if (!cfg) |
| 124 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); |
| 126 | if (acard->dev == NULL) { |
| 127 | kfree(cfg); |
| 128 | return -EBUSY; |
| 129 | } |
| 130 | acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL); |
| 131 | if (acard->devmpu == NULL) { |
Rask Ingemann Lambertsen | 2944275 | 2007-03-19 11:38:11 +0100 | [diff] [blame^] | 132 | mpu_port[dev] = -1; |
| 133 | snd_printk(KERN_WARNING PFX "MPU401 device busy, skipping.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | pdev = acard->dev; |
| 137 | pnp_init_resource_table(cfg); |
| 138 | |
| 139 | if (port[dev] != SNDRV_AUTO_PORT) |
| 140 | pnp_resource_change(&cfg->port_resource[2], port[dev], 16); |
| 141 | if (fm_port[dev] != SNDRV_AUTO_PORT) |
| 142 | pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4); |
| 143 | if (dma1[dev] != SNDRV_AUTO_DMA) |
| 144 | pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1); |
| 145 | if (dma2[dev] != SNDRV_AUTO_DMA) |
| 146 | pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1); |
| 147 | if (irq[dev] != SNDRV_AUTO_IRQ) |
| 148 | pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); |
| 149 | |
| 150 | if (pnp_manual_config_dev(pdev, cfg, 0) < 0) |
| 151 | snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n"); |
| 152 | err = pnp_activate_dev(pdev); |
| 153 | if (err < 0) { |
| 154 | printk(KERN_ERR PFX "AUDIO PnP configure failure\n"); |
| 155 | kfree(cfg); |
| 156 | return -EBUSY; |
| 157 | } |
| 158 | |
| 159 | port[dev] = pnp_port_start(pdev, 2); |
| 160 | fm_port[dev] = pnp_port_start(pdev, 1); |
| 161 | dma1[dev] = pnp_dma(pdev, 0); |
| 162 | dma2[dev] = pnp_dma(pdev, 1); |
| 163 | irq[dev] = pnp_irq(pdev, 0); |
| 164 | |
Rask Ingemann Lambertsen | 2944275 | 2007-03-19 11:38:11 +0100 | [diff] [blame^] | 165 | if (acard->devmpu == NULL) { |
| 166 | kfree(cfg); |
| 167 | return 0; |
| 168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | pdev = acard->devmpu; |
| 170 | pnp_init_resource_table(cfg); |
| 171 | |
| 172 | if (mpu_port[dev] != SNDRV_AUTO_PORT) |
| 173 | pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2); |
| 174 | if (mpu_irq[dev] != SNDRV_AUTO_IRQ) |
| 175 | pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1); |
| 176 | |
| 177 | if (pnp_manual_config_dev(pdev, cfg, 0) < 0) |
| 178 | snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n"); |
| 179 | err = pnp_activate_dev(pdev); |
| 180 | if (err < 0) { |
| 181 | printk(KERN_ERR PFX "MPU401 PnP configure failure\n"); |
| 182 | mpu_port[dev] = -1; |
| 183 | acard->devmpu = NULL; |
| 184 | } else { |
| 185 | mpu_port[dev] = pnp_port_start(pdev, 0); |
| 186 | mpu_irq[dev] = pnp_irq(pdev, 0); |
| 187 | } |
| 188 | |
| 189 | kfree(cfg); |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard, |
| 194 | const struct pnp_card_device_id *pid) |
| 195 | { |
| 196 | int error; |
Takashi Iwai | cbdd0dd | 2005-11-17 14:28:35 +0100 | [diff] [blame] | 197 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | struct snd_card_ad1816a *acard; |
Takashi Iwai | cbdd0dd | 2005-11-17 14:28:35 +0100 | [diff] [blame] | 199 | struct snd_ad1816a *chip; |
| 200 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 203 | sizeof(struct snd_card_ad1816a))) == NULL) |
| 204 | return -ENOMEM; |
| 205 | acard = (struct snd_card_ad1816a *)card->private_data; |
| 206 | |
| 207 | if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) { |
| 208 | snd_card_free(card); |
| 209 | return error; |
| 210 | } |
| 211 | snd_card_set_dev(card, &pcard->card->dev); |
| 212 | |
| 213 | if ((error = snd_ad1816a_create(card, port[dev], |
| 214 | irq[dev], |
| 215 | dma1[dev], |
| 216 | dma2[dev], |
| 217 | &chip)) < 0) { |
| 218 | snd_card_free(card); |
| 219 | return error; |
| 220 | } |
Takashi Iwai | 5b8f7f7 | 2005-08-03 14:02:47 +0200 | [diff] [blame] | 221 | if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000) |
| 222 | chip->clock_freq = clockfreq[dev]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | strcpy(card->driver, "AD1816A"); |
| 225 | strcpy(card->shortname, "ADI SoundPort AD1816A"); |
| 226 | sprintf(card->longname, "%s, SS at 0x%lx, irq %d, dma %d&%d", |
| 227 | card->shortname, chip->port, irq[dev], dma1[dev], dma2[dev]); |
| 228 | |
| 229 | if ((error = snd_ad1816a_pcm(chip, 0, NULL)) < 0) { |
| 230 | snd_card_free(card); |
| 231 | return error; |
| 232 | } |
| 233 | |
| 234 | if ((error = snd_ad1816a_mixer(chip)) < 0) { |
| 235 | snd_card_free(card); |
| 236 | return error; |
| 237 | } |
| 238 | |
| 239 | if (mpu_port[dev] > 0) { |
| 240 | if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 241 | mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | NULL) < 0) |
| 243 | printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]); |
| 244 | } |
| 245 | |
| 246 | if (fm_port[dev] > 0) { |
| 247 | if (snd_opl3_create(card, |
| 248 | fm_port[dev], fm_port[dev] + 2, |
| 249 | OPL3_HW_AUTO, 0, &opl3) < 0) { |
| 250 | printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2); |
| 251 | } else { |
| 252 | if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) { |
| 253 | snd_card_free(card); |
| 254 | return error; |
| 255 | } |
| 256 | if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { |
| 257 | snd_card_free(card); |
| 258 | return error; |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | if ((error = snd_card_register(card)) < 0) { |
| 264 | snd_card_free(card); |
| 265 | return error; |
| 266 | } |
| 267 | pnp_set_card_drvdata(pcard, card); |
| 268 | return 0; |
| 269 | } |
| 270 | |
Bjorn Helgaas | 5f53f4e | 2006-03-27 01:17:08 -0800 | [diff] [blame] | 271 | static unsigned int __devinitdata ad1816a_devices; |
| 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card, |
| 274 | const struct pnp_card_device_id *id) |
| 275 | { |
| 276 | static int dev; |
| 277 | int res; |
| 278 | |
| 279 | for ( ; dev < SNDRV_CARDS; dev++) { |
| 280 | if (!enable[dev]) |
| 281 | continue; |
| 282 | res = snd_card_ad1816a_probe(dev, card, id); |
| 283 | if (res < 0) |
| 284 | return res; |
| 285 | dev++; |
Bjorn Helgaas | 5f53f4e | 2006-03-27 01:17:08 -0800 | [diff] [blame] | 286 | ad1816a_devices++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | return -ENODEV; |
| 290 | } |
| 291 | |
| 292 | static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard) |
| 293 | { |
Takashi Iwai | 175cdcf | 2005-11-17 17:05:02 +0100 | [diff] [blame] | 294 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 295 | pnp_set_card_drvdata(pcard, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static struct pnp_card_driver ad1816a_pnpc_driver = { |
| 299 | .flags = PNP_DRIVER_RES_DISABLE, |
| 300 | .name = "ad1816a", |
| 301 | .id_table = snd_ad1816a_pnpids, |
| 302 | .probe = snd_ad1816a_pnp_detect, |
| 303 | .remove = __devexit_p(snd_ad1816a_pnp_remove), |
Takashi Iwai | 175cdcf | 2005-11-17 17:05:02 +0100 | [diff] [blame] | 304 | /* FIXME: suspend/resume */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | static int __init alsa_card_ad1816a_init(void) |
| 308 | { |
Bjorn Helgaas | 5f53f4e | 2006-03-27 01:17:08 -0800 | [diff] [blame] | 309 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Bjorn Helgaas | 5f53f4e | 2006-03-27 01:17:08 -0800 | [diff] [blame] | 311 | err = pnp_register_card_driver(&ad1816a_pnpc_driver); |
| 312 | if (err) |
| 313 | return err; |
| 314 | |
| 315 | if (!ad1816a_devices) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | pnp_unregister_card_driver(&ad1816a_pnpc_driver); |
Takashi Iwai | 175cdcf | 2005-11-17 17:05:02 +0100 | [diff] [blame] | 317 | #ifdef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | printk(KERN_ERR "no AD1816A based soundcards found.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | #endif /* MODULE */ |
Takashi Iwai | 175cdcf | 2005-11-17 17:05:02 +0100 | [diff] [blame] | 320 | return -ENODEV; |
| 321 | } |
| 322 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static void __exit alsa_card_ad1816a_exit(void) |
| 326 | { |
| 327 | pnp_unregister_card_driver(&ad1816a_pnpc_driver); |
| 328 | } |
| 329 | |
| 330 | module_init(alsa_card_ad1816a_init) |
| 331 | module_exit(alsa_card_ad1816a_exit) |