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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/wait.h> |
| 26 | #include <linux/pnp.h> |
| 27 | #include <linux/moduleparam.h> |
| 28 | #include <sound/core.h> |
| 29 | #include <sound/initval.h> |
| 30 | #include <sound/mpu401.h> |
| 31 | #include <sound/opl3.h> |
| 32 | #include <sound/sb.h> |
| 33 | |
| 34 | #define PFX "dt019x: " |
| 35 | |
| 36 | MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); |
| 37 | MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007"); |
| 38 | MODULE_LICENSE("GPL"); |
| 39 | MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X}," |
| 40 | "{Avance Logic ALS-007}}"); |
| 41 | |
| 42 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 43 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 44 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
| 45 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 46 | static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 47 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ |
| 48 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */ |
| 49 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */ |
| 50 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */ |
| 51 | |
| 52 | module_param_array(index, int, NULL, 0444); |
| 53 | MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard."); |
| 54 | module_param_array(id, charp, NULL, 0444); |
| 55 | MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard."); |
| 56 | module_param_array(enable, bool, NULL, 0444); |
| 57 | MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | struct snd_card_dt019x { |
| 60 | struct pnp_dev *dev; |
| 61 | struct pnp_dev *devmpu; |
| 62 | struct pnp_dev *devopl; |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 63 | struct snd_sb *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static struct pnp_card_device_id snd_dt019x_pnpids[] = { |
| 67 | /* DT197A30 */ |
| 68 | { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } }, |
| 69 | /* DT0196 / ALS-007 */ |
| 70 | { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } }, |
| 71 | { .id = "", } |
| 72 | }; |
| 73 | |
| 74 | MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids); |
| 75 | |
| 76 | |
| 77 | #define DRIVER_NAME "snd-card-dt019x" |
| 78 | |
| 79 | |
| 80 | static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard, |
| 81 | struct pnp_card_link *card, |
| 82 | const struct pnp_card_device_id *pid) |
| 83 | { |
| 84 | struct pnp_dev *pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | int err; |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL); |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 88 | if (acard->dev == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return -ENODEV; |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); |
| 92 | acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL); |
| 93 | |
| 94 | pdev = acard->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | err = pnp_activate_dev(pdev); |
| 97 | if (err < 0) { |
| 98 | snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | return err; |
| 100 | } |
| 101 | |
| 102 | port[dev] = pnp_port_start(pdev, 0); |
| 103 | dma8[dev] = pnp_dma(pdev, 0); |
| 104 | irq[dev] = pnp_irq(pdev, 0); |
| 105 | snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n", |
| 106 | port[dev],irq[dev],dma8[dev]); |
| 107 | |
| 108 | pdev = acard->devmpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (pdev != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | err = pnp_activate_dev(pdev); |
| 111 | if (err < 0) { |
| 112 | pnp_release_card_device(pdev); |
| 113 | snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n"); |
| 114 | goto __mpu_error; |
| 115 | } |
| 116 | mpu_port[dev] = pnp_port_start(pdev, 0); |
| 117 | mpu_irq[dev] = pnp_irq(pdev, 0); |
| 118 | snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n", |
| 119 | mpu_port[dev],mpu_irq[dev]); |
| 120 | } else { |
| 121 | __mpu_error: |
| 122 | acard->devmpu = NULL; |
| 123 | mpu_port[dev] = -1; |
| 124 | } |
| 125 | |
| 126 | pdev = acard->devopl; |
| 127 | if (pdev != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | err = pnp_activate_dev(pdev); |
| 129 | if (err < 0) { |
| 130 | pnp_release_card_device(pdev); |
| 131 | snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n"); |
| 132 | goto __fm_error; |
| 133 | } |
| 134 | fm_port[dev] = pnp_port_start(pdev, 0); |
| 135 | snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]); |
| 136 | } else { |
| 137 | __fm_error: |
| 138 | acard->devopl = NULL; |
| 139 | fm_port[dev] = -1; |
| 140 | } |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid) |
| 146 | { |
| 147 | int error; |
Takashi Iwai | 11ff5c6 | 2005-11-17 14:42:36 +0100 | [diff] [blame] | 148 | struct snd_sb *chip; |
| 149 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | struct snd_card_dt019x *acard; |
Takashi Iwai | 11ff5c6 | 2005-11-17 14:42:36 +0100 | [diff] [blame] | 151 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 154 | sizeof(struct snd_card_dt019x))) == NULL) |
| 155 | return -ENOMEM; |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 156 | acard = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | snd_card_set_dev(card, &pcard->card->dev); |
| 159 | if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) { |
| 160 | snd_card_free(card); |
| 161 | return error; |
| 162 | } |
| 163 | |
| 164 | if ((error = snd_sbdsp_create(card, port[dev], |
| 165 | irq[dev], |
| 166 | snd_sb16dsp_interrupt, |
| 167 | dma8[dev], |
| 168 | -1, |
| 169 | SB_HW_DT019X, |
| 170 | &chip)) < 0) { |
| 171 | snd_card_free(card); |
| 172 | return error; |
| 173 | } |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 174 | acard->chip = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | strcpy(card->driver, "DT-019X"); |
| 177 | strcpy(card->shortname, "Diamond Tech. DT-019X"); |
| 178 | sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", |
| 179 | card->shortname, chip->name, chip->port, |
| 180 | irq[dev], dma8[dev]); |
| 181 | |
| 182 | if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) { |
| 183 | snd_card_free(card); |
| 184 | return error; |
| 185 | } |
| 186 | if ((error = snd_sbmixer_new(chip)) < 0) { |
| 187 | snd_card_free(card); |
| 188 | return error; |
| 189 | } |
| 190 | |
| 191 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
| 192 | if (mpu_irq[dev] == SNDRV_AUTO_IRQ) |
| 193 | mpu_irq[dev] = -1; |
| 194 | if (snd_mpu401_uart_new(card, 0, |
| 195 | /* MPU401_HW_SB,*/ |
| 196 | MPU401_HW_MPU401, |
| 197 | mpu_port[dev], 0, |
| 198 | mpu_irq[dev], |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 199 | mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | NULL) < 0) |
| 201 | snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]); |
| 202 | } |
| 203 | |
| 204 | if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { |
| 205 | if (snd_opl3_create(card, |
| 206 | fm_port[dev], |
| 207 | fm_port[dev] + 2, |
| 208 | OPL3_HW_AUTO, 0, &opl3) < 0) { |
| 209 | snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n", |
| 210 | fm_port[dev], fm_port[dev] + 2); |
| 211 | } else { |
| 212 | if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) { |
| 213 | snd_card_free(card); |
| 214 | return error; |
| 215 | } |
| 216 | if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { |
| 217 | snd_card_free(card); |
| 218 | return error; |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | if ((error = snd_card_register(card)) < 0) { |
| 224 | snd_card_free(card); |
| 225 | return error; |
| 226 | } |
| 227 | pnp_set_card_drvdata(pcard, card); |
| 228 | return 0; |
| 229 | } |
| 230 | |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 231 | static unsigned int __devinitdata dt019x_devices; |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card, |
| 234 | const struct pnp_card_device_id *pid) |
| 235 | { |
| 236 | static int dev; |
| 237 | int res; |
| 238 | |
| 239 | for ( ; dev < SNDRV_CARDS; dev++) { |
| 240 | if (!enable[dev]) |
| 241 | continue; |
| 242 | res = snd_card_dt019x_probe(dev, card, pid); |
| 243 | if (res < 0) |
| 244 | return res; |
| 245 | dev++; |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 246 | dt019x_devices++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return 0; |
| 248 | } |
| 249 | return -ENODEV; |
| 250 | } |
| 251 | |
| 252 | static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard) |
| 253 | { |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 254 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 255 | pnp_set_card_drvdata(pcard, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 258 | #ifdef CONFIG_PM |
| 259 | static int snd_dt019x_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state) |
| 260 | { |
| 261 | struct snd_card *card = pnp_get_card_drvdata(pcard); |
| 262 | struct snd_card_dt019x *acard = card->private_data; |
| 263 | struct snd_sb *chip = acard->chip; |
| 264 | |
| 265 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
| 266 | snd_pcm_suspend_all(chip->pcm); |
| 267 | snd_sbmixer_suspend(chip); |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | static int snd_dt019x_pnp_resume(struct pnp_card_link *pcard) |
| 272 | { |
| 273 | struct snd_card *card = pnp_get_card_drvdata(pcard); |
| 274 | struct snd_card_dt019x *acard = card->private_data; |
| 275 | struct snd_sb *chip = acard->chip; |
| 276 | |
| 277 | snd_sbdsp_reset(chip); |
| 278 | snd_sbmixer_resume(chip); |
| 279 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
| 280 | return 0; |
| 281 | } |
| 282 | #endif |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | static struct pnp_card_driver dt019x_pnpc_driver = { |
| 285 | .flags = PNP_DRIVER_RES_DISABLE, |
| 286 | .name = "dt019x", |
| 287 | .id_table = snd_dt019x_pnpids, |
| 288 | .probe = snd_dt019x_pnp_probe, |
| 289 | .remove = __devexit_p(snd_dt019x_pnp_remove), |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 290 | #ifdef CONFIG_PM |
| 291 | .suspend = snd_dt019x_pnp_suspend, |
| 292 | .resume = snd_dt019x_pnp_resume, |
| 293 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | }; |
| 295 | |
| 296 | static int __init alsa_card_dt019x_init(void) |
| 297 | { |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 298 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Bjorn Helgaas | 6736a65 | 2006-03-27 01:17:12 -0800 | [diff] [blame] | 300 | err = pnp_register_card_driver(&dt019x_pnpc_driver); |
| 301 | if (err) |
| 302 | return err; |
| 303 | |
| 304 | if (!dt019x_devices) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | pnp_unregister_card_driver(&dt019x_pnpc_driver); |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 306 | #ifdef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | 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] | 308 | #endif |
Takashi Iwai | e2fa213 | 2005-11-17 17:04:35 +0100 | [diff] [blame] | 309 | return -ENODEV; |
| 310 | } |
| 311 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static void __exit alsa_card_dt019x_exit(void) |
| 315 | { |
| 316 | pnp_unregister_card_driver(&dt019x_pnpc_driver); |
| 317 | } |
| 318 | |
| 319 | module_init(alsa_card_dt019x_init) |
| 320 | module_exit(alsa_card_dt019x_exit) |