dt019x.c 8.8 KB

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