dt019x.c 11 KB

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