als100.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 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. sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
  196. card->shortname, chip->name, chip->port,
  197. irq[dev], dma8[dev]);
  198. } else {
  199. strcpy(card->driver, "ALS100");
  200. strcpy(card->shortname, "Avance Logic ALS100");
  201. sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
  202. card->shortname, chip->name, chip->port,
  203. irq[dev], dma8[dev], dma16[dev]);
  204. }
  205. if ((error = snd_sb16dsp_pcm(chip, 0)) < 0) {
  206. snd_card_free(card);
  207. return error;
  208. }
  209. if ((error = snd_sbmixer_new(chip)) < 0) {
  210. snd_card_free(card);
  211. return error;
  212. }
  213. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  214. int mpu_type = MPU401_HW_ALS100;
  215. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  216. mpu_irq[dev] = -1;
  217. if (pid->driver_data == SB_HW_DT019X)
  218. mpu_type = MPU401_HW_MPU401;
  219. if (snd_mpu401_uart_new(card, 0,
  220. mpu_type,
  221. mpu_port[dev], 0,
  222. mpu_irq[dev],
  223. NULL) < 0)
  224. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
  225. }
  226. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  227. if (snd_opl3_create(card,
  228. fm_port[dev], fm_port[dev] + 2,
  229. OPL3_HW_AUTO, 0, &opl3) < 0) {
  230. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
  231. fm_port[dev], fm_port[dev] + 2);
  232. } else {
  233. if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
  234. snd_card_free(card);
  235. return error;
  236. }
  237. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  238. snd_card_free(card);
  239. return error;
  240. }
  241. }
  242. }
  243. if ((error = snd_card_register(card)) < 0) {
  244. snd_card_free(card);
  245. return error;
  246. }
  247. pnp_set_card_drvdata(pcard, card);
  248. return 0;
  249. }
  250. static unsigned int als100_devices;
  251. static int snd_als100_pnp_detect(struct pnp_card_link *card,
  252. const struct pnp_card_device_id *id)
  253. {
  254. static int dev;
  255. int res;
  256. for ( ; dev < SNDRV_CARDS; dev++) {
  257. if (!enable[dev])
  258. continue;
  259. res = snd_card_als100_probe(dev, card, id);
  260. if (res < 0)
  261. return res;
  262. dev++;
  263. als100_devices++;
  264. return 0;
  265. }
  266. return -ENODEV;
  267. }
  268. static void snd_als100_pnp_remove(struct pnp_card_link *pcard)
  269. {
  270. snd_card_free(pnp_get_card_drvdata(pcard));
  271. pnp_set_card_drvdata(pcard, NULL);
  272. }
  273. #ifdef CONFIG_PM
  274. static int snd_als100_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  275. {
  276. struct snd_card *card = pnp_get_card_drvdata(pcard);
  277. struct snd_card_als100 *acard = card->private_data;
  278. struct snd_sb *chip = acard->chip;
  279. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  280. snd_pcm_suspend_all(chip->pcm);
  281. snd_sbmixer_suspend(chip);
  282. return 0;
  283. }
  284. static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
  285. {
  286. struct snd_card *card = pnp_get_card_drvdata(pcard);
  287. struct snd_card_als100 *acard = card->private_data;
  288. struct snd_sb *chip = acard->chip;
  289. snd_sbdsp_reset(chip);
  290. snd_sbmixer_resume(chip);
  291. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  292. return 0;
  293. }
  294. #endif
  295. static struct pnp_card_driver als100_pnpc_driver = {
  296. .flags = PNP_DRIVER_RES_DISABLE,
  297. .name = "als100",
  298. .id_table = snd_als100_pnpids,
  299. .probe = snd_als100_pnp_detect,
  300. .remove = snd_als100_pnp_remove,
  301. #ifdef CONFIG_PM
  302. .suspend = snd_als100_pnp_suspend,
  303. .resume = snd_als100_pnp_resume,
  304. #endif
  305. };
  306. static int __init alsa_card_als100_init(void)
  307. {
  308. int err;
  309. err = pnp_register_card_driver(&als100_pnpc_driver);
  310. if (err)
  311. return err;
  312. if (!als100_devices) {
  313. pnp_unregister_card_driver(&als100_pnpc_driver);
  314. #ifdef MODULE
  315. snd_printk(KERN_ERR "no Avance Logic based soundcards found\n");
  316. #endif
  317. return -ENODEV;
  318. }
  319. return 0;
  320. }
  321. static void __exit alsa_card_als100_exit(void)
  322. {
  323. pnp_unregister_card_driver(&als100_pnpc_driver);
  324. }
  325. module_init(alsa_card_als100_init)
  326. module_exit(alsa_card_als100_exit)