dt019x.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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/sched.h>
  21. #include <linux/wait.h>
  22. #include <linux/pnp.h>
  23. #include <linux/moduleparam.h>
  24. #include <sound/core.h>
  25. #include <sound/initval.h>
  26. #include <sound/mpu401.h>
  27. #include <sound/opl3.h>
  28. #include <sound/sb.h>
  29. #define PFX "dt019x: "
  30. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  31. MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
  32. MODULE_LICENSE("GPL");
  33. MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
  34. "{Avance Logic ALS-007}}");
  35. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  36. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  37. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  38. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  39. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  40. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  41. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
  42. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
  43. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  44. module_param_array(index, int, NULL, 0444);
  45. MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
  46. module_param_array(id, charp, NULL, 0444);
  47. MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
  48. module_param_array(enable, bool, NULL, 0444);
  49. MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
  50. module_param_array(port, long, NULL, 0444);
  51. MODULE_PARM_DESC(port, "Port # for dt019x driver.");
  52. module_param_array(mpu_port, long, NULL, 0444);
  53. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for dt019x driver.");
  54. module_param_array(fm_port, long, NULL, 0444);
  55. MODULE_PARM_DESC(fm_port, "FM port # for dt019x driver.");
  56. module_param_array(irq, int, NULL, 0444);
  57. MODULE_PARM_DESC(irq, "IRQ # for dt019x driver.");
  58. module_param_array(mpu_irq, int, NULL, 0444);
  59. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for dt019x driver.");
  60. module_param_array(dma8, int, NULL, 0444);
  61. MODULE_PARM_DESC(dma8, "8-bit DMA # for dt019x driver.");
  62. struct snd_card_dt019x {
  63. struct pnp_dev *dev;
  64. struct pnp_dev *devmpu;
  65. struct pnp_dev *devopl;
  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. sb_t *chip;
  164. snd_card_t *card;
  165. struct snd_card_dt019x *acard;
  166. opl3_t *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 = (struct snd_card_dt019x *)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. strcpy(card->driver, "DT-019X");
  187. strcpy(card->shortname, "Diamond Tech. DT-019X");
  188. sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
  189. card->shortname, chip->name, chip->port,
  190. irq[dev], dma8[dev]);
  191. if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
  192. snd_card_free(card);
  193. return error;
  194. }
  195. if ((error = snd_sbmixer_new(chip)) < 0) {
  196. snd_card_free(card);
  197. return error;
  198. }
  199. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  200. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  201. mpu_irq[dev] = -1;
  202. if (snd_mpu401_uart_new(card, 0,
  203. /* MPU401_HW_SB,*/
  204. MPU401_HW_MPU401,
  205. mpu_port[dev], 0,
  206. mpu_irq[dev],
  207. mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
  208. NULL) < 0)
  209. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
  210. }
  211. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  212. if (snd_opl3_create(card,
  213. fm_port[dev],
  214. fm_port[dev] + 2,
  215. OPL3_HW_AUTO, 0, &opl3) < 0) {
  216. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
  217. fm_port[dev], fm_port[dev] + 2);
  218. } else {
  219. if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
  220. snd_card_free(card);
  221. return error;
  222. }
  223. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  224. snd_card_free(card);
  225. return error;
  226. }
  227. }
  228. }
  229. if ((error = snd_card_register(card)) < 0) {
  230. snd_card_free(card);
  231. return error;
  232. }
  233. pnp_set_card_drvdata(pcard, card);
  234. return 0;
  235. }
  236. static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
  237. const struct pnp_card_device_id *pid)
  238. {
  239. static int dev;
  240. int res;
  241. for ( ; dev < SNDRV_CARDS; dev++) {
  242. if (!enable[dev])
  243. continue;
  244. res = snd_card_dt019x_probe(dev, card, pid);
  245. if (res < 0)
  246. return res;
  247. dev++;
  248. return 0;
  249. }
  250. return -ENODEV;
  251. }
  252. static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
  253. {
  254. snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
  255. snd_card_disconnect(card);
  256. snd_card_free_in_thread(card);
  257. }
  258. static struct pnp_card_driver dt019x_pnpc_driver = {
  259. .flags = PNP_DRIVER_RES_DISABLE,
  260. .name = "dt019x",
  261. .id_table = snd_dt019x_pnpids,
  262. .probe = snd_dt019x_pnp_probe,
  263. .remove = __devexit_p(snd_dt019x_pnp_remove),
  264. };
  265. static int __init alsa_card_dt019x_init(void)
  266. {
  267. int cards = 0;
  268. cards += pnp_register_card_driver(&dt019x_pnpc_driver);
  269. #ifdef MODULE
  270. if (!cards) {
  271. pnp_unregister_card_driver(&dt019x_pnpc_driver);
  272. snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
  273. }
  274. #endif
  275. return cards ? 0 : -ENODEV;
  276. }
  277. static void __exit alsa_card_dt019x_exit(void)
  278. {
  279. pnp_unregister_card_driver(&dt019x_pnpc_driver);
  280. }
  281. module_init(alsa_card_dt019x_init)
  282. module_exit(alsa_card_dt019x_exit)