dt019x.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. struct snd_sb *chip;
  67. };
  68. static struct pnp_card_device_id snd_dt019x_pnpids[] = {
  69. /* DT197A30 */
  70. { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
  71. /* DT0196 / ALS-007 */
  72. { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
  73. { .id = "", }
  74. };
  75. MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
  76. #define DRIVER_NAME "snd-card-dt019x"
  77. static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
  78. struct pnp_card_link *card,
  79. const struct pnp_card_device_id *pid)
  80. {
  81. struct pnp_dev *pdev;
  82. struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
  83. int err;
  84. if (!cfg)
  85. return -ENOMEM;
  86. acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
  87. if (acard->dev == NULL) {
  88. kfree (cfg);
  89. return -ENODEV;
  90. }
  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. pdev = acard->dev;
  94. pnp_init_resource_table(cfg);
  95. if (port[dev] != SNDRV_AUTO_PORT)
  96. pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
  97. if (dma8[dev] != SNDRV_AUTO_DMA)
  98. pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
  99. if (irq[dev] != SNDRV_AUTO_IRQ)
  100. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  101. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  102. snd_printk(KERN_ERR PFX "DT-019X AUDIO the requested resources are invalid, using auto config\n");
  103. err = pnp_activate_dev(pdev);
  104. if (err < 0) {
  105. snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
  106. kfree(cfg);
  107. return err;
  108. }
  109. port[dev] = pnp_port_start(pdev, 0);
  110. dma8[dev] = pnp_dma(pdev, 0);
  111. irq[dev] = pnp_irq(pdev, 0);
  112. snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
  113. port[dev],irq[dev],dma8[dev]);
  114. pdev = acard->devmpu;
  115. if (pdev != NULL) {
  116. pnp_init_resource_table(cfg);
  117. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  118. pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
  119. if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
  120. pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
  121. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  122. snd_printk(KERN_ERR PFX "DT-019X MPU401 the requested resources are invalid, using auto config\n");
  123. err = pnp_activate_dev(pdev);
  124. if (err < 0) {
  125. pnp_release_card_device(pdev);
  126. snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
  127. goto __mpu_error;
  128. }
  129. mpu_port[dev] = pnp_port_start(pdev, 0);
  130. mpu_irq[dev] = pnp_irq(pdev, 0);
  131. snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
  132. mpu_port[dev],mpu_irq[dev]);
  133. } else {
  134. __mpu_error:
  135. acard->devmpu = NULL;
  136. mpu_port[dev] = -1;
  137. }
  138. pdev = acard->devopl;
  139. if (pdev != NULL) {
  140. pnp_init_resource_table(cfg);
  141. if (fm_port[dev] != SNDRV_AUTO_PORT)
  142. pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
  143. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  144. snd_printk(KERN_ERR PFX "DT-019X OPL3 the requested resources are invalid, using auto config\n");
  145. err = pnp_activate_dev(pdev);
  146. if (err < 0) {
  147. pnp_release_card_device(pdev);
  148. snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
  149. goto __fm_error;
  150. }
  151. fm_port[dev] = pnp_port_start(pdev, 0);
  152. snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
  153. } else {
  154. __fm_error:
  155. acard->devopl = NULL;
  156. fm_port[dev] = -1;
  157. }
  158. kfree(cfg);
  159. return 0;
  160. }
  161. static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
  162. {
  163. int error;
  164. struct snd_sb *chip;
  165. struct snd_card *card;
  166. struct snd_card_dt019x *acard;
  167. struct snd_opl3 *opl3;
  168. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  169. sizeof(struct snd_card_dt019x))) == NULL)
  170. return -ENOMEM;
  171. acard = card->private_data;
  172. snd_card_set_dev(card, &pcard->card->dev);
  173. if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
  174. snd_card_free(card);
  175. return error;
  176. }
  177. if ((error = snd_sbdsp_create(card, port[dev],
  178. irq[dev],
  179. snd_sb16dsp_interrupt,
  180. dma8[dev],
  181. -1,
  182. SB_HW_DT019X,
  183. &chip)) < 0) {
  184. snd_card_free(card);
  185. return error;
  186. }
  187. acard->chip = chip;
  188. strcpy(card->driver, "DT-019X");
  189. strcpy(card->shortname, "Diamond Tech. DT-019X");
  190. sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
  191. card->shortname, chip->name, chip->port,
  192. irq[dev], dma8[dev]);
  193. if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
  194. snd_card_free(card);
  195. return error;
  196. }
  197. if ((error = snd_sbmixer_new(chip)) < 0) {
  198. snd_card_free(card);
  199. return error;
  200. }
  201. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  202. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  203. mpu_irq[dev] = -1;
  204. if (snd_mpu401_uart_new(card, 0,
  205. /* MPU401_HW_SB,*/
  206. MPU401_HW_MPU401,
  207. mpu_port[dev], 0,
  208. mpu_irq[dev],
  209. mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0,
  210. NULL) < 0)
  211. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
  212. }
  213. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  214. if (snd_opl3_create(card,
  215. fm_port[dev],
  216. fm_port[dev] + 2,
  217. OPL3_HW_AUTO, 0, &opl3) < 0) {
  218. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
  219. fm_port[dev], fm_port[dev] + 2);
  220. } else {
  221. if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
  222. snd_card_free(card);
  223. return error;
  224. }
  225. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  226. snd_card_free(card);
  227. return error;
  228. }
  229. }
  230. }
  231. if ((error = snd_card_register(card)) < 0) {
  232. snd_card_free(card);
  233. return error;
  234. }
  235. pnp_set_card_drvdata(pcard, card);
  236. return 0;
  237. }
  238. static unsigned int __devinitdata dt019x_devices;
  239. static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
  240. const struct pnp_card_device_id *pid)
  241. {
  242. static int dev;
  243. int res;
  244. for ( ; dev < SNDRV_CARDS; dev++) {
  245. if (!enable[dev])
  246. continue;
  247. res = snd_card_dt019x_probe(dev, card, pid);
  248. if (res < 0)
  249. return res;
  250. dev++;
  251. dt019x_devices++;
  252. return 0;
  253. }
  254. return -ENODEV;
  255. }
  256. static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
  257. {
  258. snd_card_free(pnp_get_card_drvdata(pcard));
  259. pnp_set_card_drvdata(pcard, NULL);
  260. }
  261. #ifdef CONFIG_PM
  262. static int snd_dt019x_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  263. {
  264. struct snd_card *card = pnp_get_card_drvdata(pcard);
  265. struct snd_card_dt019x *acard = card->private_data;
  266. struct snd_sb *chip = acard->chip;
  267. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  268. snd_pcm_suspend_all(chip->pcm);
  269. snd_sbmixer_suspend(chip);
  270. return 0;
  271. }
  272. static int snd_dt019x_pnp_resume(struct pnp_card_link *pcard)
  273. {
  274. struct snd_card *card = pnp_get_card_drvdata(pcard);
  275. struct snd_card_dt019x *acard = card->private_data;
  276. struct snd_sb *chip = acard->chip;
  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. static struct pnp_card_driver dt019x_pnpc_driver = {
  284. .flags = PNP_DRIVER_RES_DISABLE,
  285. .name = "dt019x",
  286. .id_table = snd_dt019x_pnpids,
  287. .probe = snd_dt019x_pnp_probe,
  288. .remove = __devexit_p(snd_dt019x_pnp_remove),
  289. #ifdef CONFIG_PM
  290. .suspend = snd_dt019x_pnp_suspend,
  291. .resume = snd_dt019x_pnp_resume,
  292. #endif
  293. };
  294. static int __init alsa_card_dt019x_init(void)
  295. {
  296. int err;
  297. err = pnp_register_card_driver(&dt019x_pnpc_driver);
  298. if (err)
  299. return err;
  300. if (!dt019x_devices) {
  301. pnp_unregister_card_driver(&dt019x_pnpc_driver);
  302. #ifdef MODULE
  303. snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
  304. #endif
  305. return -ENODEV;
  306. }
  307. return 0;
  308. }
  309. static void __exit alsa_card_dt019x_exit(void)
  310. {
  311. pnp_unregister_card_driver(&dt019x_pnpc_driver);
  312. }
  313. module_init(alsa_card_dt019x_init)
  314. module_exit(alsa_card_dt019x_exit)