Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | dt019x.c - driver for Diamond Technologies DT-0197H based soundcards. |
| 4 | Copyright (C) 1999, 2002 by Massimo Piccioni <dafastidio@libero.it> |
| 5 | |
| 6 | Generalised for soundcards based on DT-0196 and ALS-007 chips |
| 7 | by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002. |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <sound/driver.h> |
| 25 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/wait.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 "dt019x: " |
| 36 | |
| 37 | MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); |
| 38 | MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007"); |
| 39 | MODULE_LICENSE("GPL"); |
| 40 | MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X}," |
| 41 | "{Avance Logic ALS-007}}"); |
| 42 | |
| 43 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 44 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 45 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
| 46 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 47 | static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 48 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 49 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */ |
| 50 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */ |
| 51 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */ |
| 52 | |
| 53 | module_param_array(index, int, NULL, 0444); |
| 54 | MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard."); |
| 55 | module_param_array(id, charp, NULL, 0444); |
| 56 | MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard."); |
| 57 | module_param_array(enable, bool, NULL, 0444); |
| 58 | MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard."); |
| 59 | module_param_array(port, long, NULL, 0444); |
| 60 | MODULE_PARM_DESC(port, "Port # for dt019x driver."); |
| 61 | module_param_array(mpu_port, long, NULL, 0444); |
| 62 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for dt019x driver."); |
| 63 | module_param_array(fm_port, long, NULL, 0444); |
| 64 | MODULE_PARM_DESC(fm_port, "FM port # for dt019x driver."); |
| 65 | module_param_array(irq, int, NULL, 0444); |
| 66 | MODULE_PARM_DESC(irq, "IRQ # for dt019x driver."); |
| 67 | module_param_array(mpu_irq, int, NULL, 0444); |
| 68 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for dt019x driver."); |
| 69 | module_param_array(dma8, int, NULL, 0444); |
| 70 | MODULE_PARM_DESC(dma8, "8-bit DMA # for dt019x driver."); |
| 71 | |
| 72 | struct snd_card_dt019x { |
| 73 | struct pnp_dev *dev; |
| 74 | struct pnp_dev *devmpu; |
| 75 | struct pnp_dev *devopl; |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 76 | struct snd_sb *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static struct pnp_card_device_id snd_dt019x_pnpids[] = { |
| 80 | /* DT197A30 */ |
| 81 | { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } }, |
| 82 | /* DT0196 / ALS-007 */ |
| 83 | { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } }, |
| 84 | { .id = "", } |
| 85 | }; |
| 86 | |
| 87 | MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids); |
| 88 | |
| 89 | |
| 90 | #define DRIVER_NAME "snd-card-dt019x" |
| 91 | |
| 92 | |
| 93 | static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard, |
| 94 | struct pnp_card_link *card, |
| 95 | const struct pnp_card_device_id *pid) |
| 96 | { |
| 97 | struct pnp_dev *pdev; |
| 98 | struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); |
| 99 | int err; |
| 100 | |
| 101 | if (!cfg) |
| 102 | return -ENOMEM; |
| 103 | |
| 104 | acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL); |
| 105 | if (acard->dev == NULL) { |
| 106 | kfree (cfg); |
| 107 | return -ENODEV; |
| 108 | } |
| 109 | acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); |
| 110 | acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL); |
| 111 | |
| 112 | pdev = acard->dev; |
| 113 | pnp_init_resource_table(cfg); |
| 114 | |
| 115 | if (port[dev] != SNDRV_AUTO_PORT) |
| 116 | pnp_resource_change(&cfg->port_resource[0], port[dev], 16); |
| 117 | if (dma8[dev] != SNDRV_AUTO_DMA) |
| 118 | pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1); |
| 119 | if (irq[dev] != SNDRV_AUTO_IRQ) |
| 120 | pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); |
| 121 | |
| 122 | if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0) |
| 123 | snd_printk(KERN_ERR PFX "DT-019X AUDIO the requested resources are invalid, using auto config\n"); |
| 124 | err = pnp_activate_dev(pdev); |
| 125 | if (err < 0) { |
| 126 | snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n"); |
| 127 | kfree(cfg); |
| 128 | return err; |
| 129 | } |
| 130 | |
| 131 | port[dev] = pnp_port_start(pdev, 0); |
| 132 | dma8[dev] = pnp_dma(pdev, 0); |
| 133 | irq[dev] = pnp_irq(pdev, 0); |
| 134 | snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n", |
| 135 | port[dev],irq[dev],dma8[dev]); |
| 136 | |
| 137 | pdev = acard->devmpu; |
| 138 | |
| 139 | if (pdev != NULL) { |
| 140 | pnp_init_resource_table(cfg); |
| 141 | if (mpu_port[dev] != SNDRV_AUTO_PORT) |
| 142 | pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2); |
| 143 | if (mpu_irq[dev] != SNDRV_AUTO_IRQ) |
| 144 | pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1); |
| 145 | if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0) |
| 146 | snd_printk(KERN_ERR PFX "DT-019X MPU401 the requested resources are invalid, using auto config\n"); |
| 147 | err = pnp_activate_dev(pdev); |
| 148 | if (err < 0) { |
| 149 | pnp_release_card_device(pdev); |
| 150 | snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n"); |
| 151 | goto __mpu_error; |
| 152 | } |
| 153 | mpu_port[dev] = pnp_port_start(pdev, 0); |
| 154 | mpu_irq[dev] = pnp_irq(pdev, 0); |
| 155 | snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n", |
| 156 | mpu_port[dev],mpu_irq[dev]); |
| 157 | } else { |
| 158 | __mpu_error: |
| 159 | acard->devmpu = NULL; |
| 160 | mpu_port[dev] = -1; |
| 161 | } |
| 162 | |
| 163 | pdev = acard->devopl; |
| 164 | if (pdev != NULL) { |
| 165 | pnp_init_resource_table(cfg); |
| 166 | if (fm_port[dev] != SNDRV_AUTO_PORT) |
| 167 | pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4); |
| 168 | if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0) |
| 169 | snd_printk(KERN_ERR PFX "DT-019X OPL3 the requested resources are invalid, using auto config\n"); |
| 170 | err = pnp_activate_dev(pdev); |
| 171 | if (err < 0) { |
| 172 | pnp_release_card_device(pdev); |
| 173 | snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n"); |
| 174 | goto __fm_error; |
| 175 | } |
| 176 | fm_port[dev] = pnp_port_start(pdev, 0); |
| 177 | snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]); |
| 178 | } else { |
| 179 | __fm_error: |
| 180 | acard->devopl = NULL; |
| 181 | fm_port[dev] = -1; |
| 182 | } |
| 183 | |
| 184 | kfree(cfg); |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid) |
| 189 | { |
| 190 | int error; |
Takashi Iwai | 11ff5c6 | 2005-11-17 14:42:36 +0100 | [diff] [blame] | 191 | struct snd_sb *chip; |
| 192 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | struct snd_card_dt019x *acard; |
Takashi Iwai | 11ff5c6 | 2005-11-17 14:42:36 +0100 | [diff] [blame] | 194 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 197 | sizeof(struct snd_card_dt019x))) == NULL) |
| 198 | return -ENOMEM; |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 199 | acard = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
| 201 | snd_card_set_dev(card, &pcard->card->dev); |
| 202 | if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) { |
| 203 | snd_card_free(card); |
| 204 | return error; |
| 205 | } |
| 206 | |
| 207 | if ((error = snd_sbdsp_create(card, port[dev], |
| 208 | irq[dev], |
| 209 | snd_sb16dsp_interrupt, |
| 210 | dma8[dev], |
| 211 | -1, |
| 212 | SB_HW_DT019X, |
| 213 | &chip)) < 0) { |
| 214 | snd_card_free(card); |
| 215 | return error; |
| 216 | } |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 217 | acard->chip = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | strcpy(card->driver, "DT-019X"); |
| 220 | strcpy(card->shortname, "Diamond Tech. DT-019X"); |
| 221 | sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", |
| 222 | card->shortname, chip->name, chip->port, |
| 223 | irq[dev], dma8[dev]); |
| 224 | |
| 225 | if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) { |
| 226 | snd_card_free(card); |
| 227 | return error; |
| 228 | } |
| 229 | if ((error = snd_sbmixer_new(chip)) < 0) { |
| 230 | snd_card_free(card); |
| 231 | return error; |
| 232 | } |
| 233 | |
| 234 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
| 235 | if (mpu_irq[dev] == SNDRV_AUTO_IRQ) |
| 236 | mpu_irq[dev] = -1; |
| 237 | if (snd_mpu401_uart_new(card, 0, |
| 238 | /* MPU401_HW_SB,*/ |
| 239 | MPU401_HW_MPU401, |
| 240 | mpu_port[dev], 0, |
| 241 | mpu_irq[dev], |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 242 | mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | NULL) < 0) |
| 244 | snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]); |
| 245 | } |
| 246 | |
| 247 | if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { |
| 248 | if (snd_opl3_create(card, |
| 249 | fm_port[dev], |
| 250 | fm_port[dev] + 2, |
| 251 | OPL3_HW_AUTO, 0, &opl3) < 0) { |
| 252 | snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n", |
| 253 | fm_port[dev], fm_port[dev] + 2); |
| 254 | } else { |
| 255 | if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) { |
| 256 | snd_card_free(card); |
| 257 | return error; |
| 258 | } |
| 259 | if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { |
| 260 | snd_card_free(card); |
| 261 | return error; |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if ((error = snd_card_register(card)) < 0) { |
| 267 | snd_card_free(card); |
| 268 | return error; |
| 269 | } |
| 270 | pnp_set_card_drvdata(pcard, card); |
| 271 | return 0; |
| 272 | } |
| 273 | |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 274 | static unsigned int __devinitdata dt019x_devices; |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card, |
| 277 | const struct pnp_card_device_id *pid) |
| 278 | { |
| 279 | static int dev; |
| 280 | int res; |
| 281 | |
| 282 | for ( ; dev < SNDRV_CARDS; dev++) { |
| 283 | if (!enable[dev]) |
| 284 | continue; |
| 285 | res = snd_card_dt019x_probe(dev, card, pid); |
| 286 | if (res < 0) |
| 287 | return res; |
| 288 | dev++; |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 289 | dt019x_devices++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | return 0; |
| 291 | } |
| 292 | return -ENODEV; |
| 293 | } |
| 294 | |
| 295 | static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard) |
| 296 | { |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 297 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 298 | pnp_set_card_drvdata(pcard, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 301 | #ifdef CONFIG_PM |
| 302 | static int snd_dt019x_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state) |
| 303 | { |
| 304 | struct snd_card *card = pnp_get_card_drvdata(pcard); |
| 305 | struct snd_card_dt019x *acard = card->private_data; |
| 306 | struct snd_sb *chip = acard->chip; |
| 307 | |
| 308 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 309 | snd_pcm_suspend_all(chip->pcm); |
| 310 | snd_sbmixer_suspend(chip); |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static int snd_dt019x_pnp_resume(struct pnp_card_link *pcard) |
| 315 | { |
| 316 | struct snd_card *card = pnp_get_card_drvdata(pcard); |
| 317 | struct snd_card_dt019x *acard = card->private_data; |
| 318 | struct snd_sb *chip = acard->chip; |
| 319 | |
| 320 | snd_sbdsp_reset(chip); |
| 321 | snd_sbmixer_resume(chip); |
| 322 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
| 323 | return 0; |
| 324 | } |
| 325 | #endif |
| 326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | static struct pnp_card_driver dt019x_pnpc_driver = { |
| 328 | .flags = PNP_DRIVER_RES_DISABLE, |
| 329 | .name = "dt019x", |
| 330 | .id_table = snd_dt019x_pnpids, |
| 331 | .probe = snd_dt019x_pnp_probe, |
| 332 | .remove = __devexit_p(snd_dt019x_pnp_remove), |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 333 | #ifdef CONFIG_PM |
| 334 | .suspend = snd_dt019x_pnp_suspend, |
| 335 | .resume = snd_dt019x_pnp_resume, |
| 336 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | static int __init alsa_card_dt019x_init(void) |
| 340 | { |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 341 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 343 | err = pnp_register_card_driver(&dt019x_pnpc_driver); |
| 344 | if (err) |
| 345 | return err; |
| 346 | |
| 347 | if (!dt019x_devices) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | pnp_unregister_card_driver(&dt019x_pnpc_driver); |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 349 | #ifdef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | #endif |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 352 | return -ENODEV; |
| 353 | } |
| 354 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static void __exit alsa_card_dt019x_exit(void) |
| 358 | { |
| 359 | pnp_unregister_card_driver(&dt019x_pnpc_driver); |
| 360 | } |
| 361 | |
| 362 | module_init(alsa_card_dt019x_init) |
| 363 | module_exit(alsa_card_dt019x_exit) |