als100.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. card-als100.c - driver for Avance Logic ALS100 based soundcards.
  4. Copyright (C) 1999-2000 by Massimo Piccioni <[email protected]>
  5. Copyright (C) 1999-2002 by Massimo Piccioni <[email protected]>
  6. Thanks to Pierfrancesco 'qM2' Passerini.
  7. Generalised for soundcards based on DT-0196 and ALS-007 chips
  8. by Jonathan Woithe <[email protected]>: June 2002.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/wait.h>
  12. #include <linux/time.h>
  13. #include <linux/pnp.h>
  14. #include <linux/module.h>
  15. #include <sound/core.h>
  16. #include <sound/initval.h>
  17. #include <sound/mpu401.h>
  18. #include <sound/opl3.h>
  19. #include <sound/sb.h>
  20. #define PFX "als100: "
  21. MODULE_DESCRIPTION("Avance Logic ALS007/ALS1X0");
  22. MODULE_AUTHOR("Massimo Piccioni <[email protected]>");
  23. MODULE_LICENSE("GPL");
  24. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  25. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  26. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  27. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  28. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  29. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  30. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
  31. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
  32. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  33. static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  34. module_param_array(index, int, NULL, 0444);
  35. MODULE_PARM_DESC(index, "Index value for Avance Logic based soundcard.");
  36. module_param_array(id, charp, NULL, 0444);
  37. MODULE_PARM_DESC(id, "ID string for Avance Logic based soundcard.");
  38. module_param_array(enable, bool, NULL, 0444);
  39. MODULE_PARM_DESC(enable, "Enable Avance Logic based soundcard.");
  40. MODULE_ALIAS("snd-dt019x");
  41. struct snd_card_als100 {
  42. struct pnp_dev *dev;
  43. struct pnp_dev *devmpu;
  44. struct pnp_dev *devopl;
  45. struct snd_sb *chip;
  46. };
  47. static const struct pnp_card_device_id snd_als100_pnpids[] = {
  48. /* DT197A30 */
  49. { .id = "RWB1688",
  50. .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
  51. .driver_data = SB_HW_DT019X },
  52. /* DT0196 / ALS-007 */
  53. { .id = "ALS0007",
  54. .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
  55. .driver_data = SB_HW_DT019X },
  56. /* ALS100 - PRO16PNP */
  57. { .id = "ALS0001",
  58. .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
  59. .driver_data = SB_HW_ALS100 },
  60. /* ALS110 - MF1000 - Digimate 3D Sound */
  61. { .id = "ALS0110",
  62. .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } },
  63. .driver_data = SB_HW_ALS100 },
  64. /* ALS120 */
  65. { .id = "ALS0120",
  66. .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
  67. .driver_data = SB_HW_ALS100 },
  68. /* ALS200 */
  69. { .id = "ALS0200",
  70. .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } },
  71. .driver_data = SB_HW_ALS100 },
  72. /* ALS200 OEM */
  73. { .id = "ALS0200",
  74. .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } },
  75. .driver_data = SB_HW_ALS100 },
  76. /* RTL3000 */
  77. { .id = "RTL3000",
  78. .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
  79. .driver_data = SB_HW_ALS100 },
  80. { .id = "" } /* end */
  81. };
  82. MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
  83. static int snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
  84. struct pnp_card_link *card,
  85. const struct pnp_card_device_id *id)
  86. {
  87. struct pnp_dev *pdev;
  88. int err;
  89. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  90. if (acard->dev == NULL)
  91. return -ENODEV;
  92. acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
  93. acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->dev);
  94. pdev = acard->dev;
  95. err = pnp_activate_dev(pdev);
  96. if (err < 0) {
  97. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  98. return err;
  99. }
  100. port[dev] = pnp_port_start(pdev, 0);
  101. if (id->driver_data == SB_HW_DT019X)
  102. dma8[dev] = pnp_dma(pdev, 0);
  103. else {
  104. dma8[dev] = pnp_dma(pdev, 1);
  105. dma16[dev] = pnp_dma(pdev, 0);
  106. }
  107. irq[dev] = pnp_irq(pdev, 0);
  108. pdev = acard->devmpu;
  109. if (pdev != NULL) {
  110. err = pnp_activate_dev(pdev);
  111. if (err < 0)
  112. goto __mpu_error;
  113. mpu_port[dev] = pnp_port_start(pdev, 0);
  114. mpu_irq[dev] = pnp_irq(pdev, 0);
  115. } else {
  116. __mpu_error:
  117. if (pdev) {
  118. pnp_release_card_device(pdev);
  119. snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
  120. }
  121. acard->devmpu = NULL;
  122. mpu_port[dev] = -1;
  123. }
  124. pdev = acard->devopl;
  125. if (pdev != NULL) {
  126. err = pnp_activate_dev(pdev);
  127. if (err < 0)
  128. goto __fm_error;
  129. fm_port[dev] = pnp_port_start(pdev, 0);
  130. } else {
  131. __fm_error:
  132. if (pdev) {
  133. pnp_release_card_device(pdev);
  134. snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
  135. }
  136. acard->devopl = NULL;
  137. fm_port[dev] = -1;
  138. }
  139. return 0;
  140. }
  141. static int snd_card_als100_probe(int dev,
  142. struct pnp_card_link *pcard,
  143. const struct pnp_card_device_id *pid)
  144. {
  145. int error;
  146. struct snd_sb *chip;
  147. struct snd_card *card;
  148. struct snd_card_als100 *acard;
  149. struct snd_opl3 *opl3;
  150. error = snd_devm_card_new(&pcard->card->dev,
  151. index[dev], id[dev], THIS_MODULE,
  152. sizeof(struct snd_card_als100), &card);
  153. if (error < 0)
  154. return error;
  155. acard = card->private_data;
  156. error = snd_card_als100_pnp(dev, acard, pcard, pid);
  157. if (error)
  158. return error;
  159. if (pid->driver_data == SB_HW_DT019X)
  160. dma16[dev] = -1;
  161. error = snd_sbdsp_create(card, port[dev], irq[dev],
  162. snd_sb16dsp_interrupt,
  163. dma8[dev], dma16[dev],
  164. pid->driver_data,
  165. &chip);
  166. if (error < 0)
  167. return error;
  168. acard->chip = chip;
  169. if (pid->driver_data == SB_HW_DT019X) {
  170. strcpy(card->driver, "DT-019X");
  171. strcpy(card->shortname, "Diamond Tech. DT-019X");
  172. snprintf(card->longname, sizeof(card->longname),
  173. "Diamond Tech. DT-019X, %s at 0x%lx, irq %d, dma %d",
  174. chip->name, chip->port, irq[dev], dma8[dev]);
  175. } else {
  176. strcpy(card->driver, "ALS100");
  177. strcpy(card->shortname, "Avance Logic ALS100");
  178. snprintf(card->longname, sizeof(card->longname),
  179. "Avance Logic ALS100, %s at 0x%lx, irq %d, dma %d&%d",
  180. chip->name, chip->port, irq[dev], dma8[dev],
  181. dma16[dev]);
  182. }
  183. error = snd_sb16dsp_pcm(chip, 0);
  184. if (error < 0)
  185. return error;
  186. error = snd_sbmixer_new(chip);
  187. if (error < 0)
  188. return error;
  189. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  190. int mpu_type = MPU401_HW_ALS100;
  191. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  192. mpu_irq[dev] = -1;
  193. if (pid->driver_data == SB_HW_DT019X)
  194. mpu_type = MPU401_HW_MPU401;
  195. if (snd_mpu401_uart_new(card, 0,
  196. mpu_type,
  197. mpu_port[dev], 0,
  198. mpu_irq[dev],
  199. NULL) < 0)
  200. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
  201. }
  202. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  203. if (snd_opl3_create(card,
  204. fm_port[dev], fm_port[dev] + 2,
  205. OPL3_HW_AUTO, 0, &opl3) < 0) {
  206. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
  207. fm_port[dev], fm_port[dev] + 2);
  208. } else {
  209. error = snd_opl3_timer_new(opl3, 0, 1);
  210. if (error < 0)
  211. return error;
  212. error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
  213. if (error < 0)
  214. return error;
  215. }
  216. }
  217. error = snd_card_register(card);
  218. if (error < 0)
  219. return error;
  220. pnp_set_card_drvdata(pcard, card);
  221. return 0;
  222. }
  223. static unsigned int als100_devices;
  224. static int snd_als100_pnp_detect(struct pnp_card_link *card,
  225. const struct pnp_card_device_id *id)
  226. {
  227. static int dev;
  228. int res;
  229. for ( ; dev < SNDRV_CARDS; dev++) {
  230. if (!enable[dev])
  231. continue;
  232. res = snd_card_als100_probe(dev, card, id);
  233. if (res < 0)
  234. return res;
  235. dev++;
  236. als100_devices++;
  237. return 0;
  238. }
  239. return -ENODEV;
  240. }
  241. #ifdef CONFIG_PM
  242. static int snd_als100_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  243. {
  244. struct snd_card *card = pnp_get_card_drvdata(pcard);
  245. struct snd_card_als100 *acard = card->private_data;
  246. struct snd_sb *chip = acard->chip;
  247. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  248. snd_sbmixer_suspend(chip);
  249. return 0;
  250. }
  251. static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
  252. {
  253. struct snd_card *card = pnp_get_card_drvdata(pcard);
  254. struct snd_card_als100 *acard = card->private_data;
  255. struct snd_sb *chip = acard->chip;
  256. snd_sbdsp_reset(chip);
  257. snd_sbmixer_resume(chip);
  258. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  259. return 0;
  260. }
  261. #endif
  262. static struct pnp_card_driver als100_pnpc_driver = {
  263. .flags = PNP_DRIVER_RES_DISABLE,
  264. .name = "als100",
  265. .id_table = snd_als100_pnpids,
  266. .probe = snd_als100_pnp_detect,
  267. #ifdef CONFIG_PM
  268. .suspend = snd_als100_pnp_suspend,
  269. .resume = snd_als100_pnp_resume,
  270. #endif
  271. };
  272. static int __init alsa_card_als100_init(void)
  273. {
  274. int err;
  275. err = pnp_register_card_driver(&als100_pnpc_driver);
  276. if (err)
  277. return err;
  278. if (!als100_devices) {
  279. pnp_unregister_card_driver(&als100_pnpc_driver);
  280. #ifdef MODULE
  281. snd_printk(KERN_ERR "no Avance Logic based soundcards found\n");
  282. #endif
  283. return -ENODEV;
  284. }
  285. return 0;
  286. }
  287. static void __exit alsa_card_als100_exit(void)
  288. {
  289. pnp_unregister_card_driver(&als100_pnpc_driver);
  290. }
  291. module_init(alsa_card_als100_init)
  292. module_exit(alsa_card_als100_exit)