als100.c 9.2 KB

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