als100.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. error = snd_card_create(index[dev], id[dev], THIS_MODULE,
  143. sizeof(struct snd_card_als100), &card);
  144. if (error < 0)
  145. return error;
  146. acard = card->private_data;
  147. if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
  148. snd_card_free(card);
  149. return error;
  150. }
  151. snd_card_set_dev(card, &pcard->card->dev);
  152. if ((error = snd_sbdsp_create(card, port[dev],
  153. irq[dev],
  154. snd_sb16dsp_interrupt,
  155. dma8[dev],
  156. dma16[dev],
  157. SB_HW_ALS100, &chip)) < 0) {
  158. snd_card_free(card);
  159. return error;
  160. }
  161. acard->chip = chip;
  162. strcpy(card->driver, "ALS100");
  163. strcpy(card->shortname, "Avance Logic ALS100");
  164. sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
  165. card->shortname, chip->name, chip->port,
  166. irq[dev], dma8[dev], dma16[dev]);
  167. if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
  168. snd_card_free(card);
  169. return error;
  170. }
  171. if ((error = snd_sbmixer_new(chip)) < 0) {
  172. snd_card_free(card);
  173. return error;
  174. }
  175. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  176. if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100,
  177. mpu_port[dev], 0,
  178. mpu_irq[dev], IRQF_DISABLED,
  179. NULL) < 0)
  180. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
  181. }
  182. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  183. if (snd_opl3_create(card,
  184. fm_port[dev], fm_port[dev] + 2,
  185. OPL3_HW_AUTO, 0, &opl3) < 0) {
  186. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
  187. fm_port[dev], fm_port[dev] + 2);
  188. } else {
  189. if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
  190. snd_card_free(card);
  191. return error;
  192. }
  193. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  194. snd_card_free(card);
  195. return error;
  196. }
  197. }
  198. }
  199. if ((error = snd_card_register(card)) < 0) {
  200. snd_card_free(card);
  201. return error;
  202. }
  203. pnp_set_card_drvdata(pcard, card);
  204. return 0;
  205. }
  206. static unsigned int __devinitdata als100_devices;
  207. static int __devinit snd_als100_pnp_detect(struct pnp_card_link *card,
  208. const struct pnp_card_device_id *id)
  209. {
  210. static int dev;
  211. int res;
  212. for ( ; dev < SNDRV_CARDS; dev++) {
  213. if (!enable[dev])
  214. continue;
  215. res = snd_card_als100_probe(dev, card, id);
  216. if (res < 0)
  217. return res;
  218. dev++;
  219. als100_devices++;
  220. return 0;
  221. }
  222. return -ENODEV;
  223. }
  224. static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
  225. {
  226. snd_card_free(pnp_get_card_drvdata(pcard));
  227. pnp_set_card_drvdata(pcard, NULL);
  228. }
  229. #ifdef CONFIG_PM
  230. static int snd_als100_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  231. {
  232. struct snd_card *card = pnp_get_card_drvdata(pcard);
  233. struct snd_card_als100 *acard = card->private_data;
  234. struct snd_sb *chip = acard->chip;
  235. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  236. snd_pcm_suspend_all(chip->pcm);
  237. snd_sbmixer_suspend(chip);
  238. return 0;
  239. }
  240. static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
  241. {
  242. struct snd_card *card = pnp_get_card_drvdata(pcard);
  243. struct snd_card_als100 *acard = card->private_data;
  244. struct snd_sb *chip = acard->chip;
  245. snd_sbdsp_reset(chip);
  246. snd_sbmixer_resume(chip);
  247. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  248. return 0;
  249. }
  250. #endif
  251. static struct pnp_card_driver als100_pnpc_driver = {
  252. .flags = PNP_DRIVER_RES_DISABLE,
  253. .name = "als100",
  254. .id_table = snd_als100_pnpids,
  255. .probe = snd_als100_pnp_detect,
  256. .remove = __devexit_p(snd_als100_pnp_remove),
  257. #ifdef CONFIG_PM
  258. .suspend = snd_als100_pnp_suspend,
  259. .resume = snd_als100_pnp_resume,
  260. #endif
  261. };
  262. static int __init alsa_card_als100_init(void)
  263. {
  264. int err;
  265. err = pnp_register_card_driver(&als100_pnpc_driver);
  266. if (err)
  267. return err;
  268. if (!als100_devices) {
  269. pnp_unregister_card_driver(&als100_pnpc_driver);
  270. #ifdef MODULE
  271. snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
  272. #endif
  273. return -ENODEV;
  274. }
  275. return 0;
  276. }
  277. static void __exit alsa_card_als100_exit(void)
  278. {
  279. pnp_unregister_card_driver(&als100_pnpc_driver);
  280. }
  281. module_init(alsa_card_als100_init)
  282. module_exit(alsa_card_als100_exit)