als100.c 10 KB

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