als100.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 <sound/driver.h>
  18. #include <linux/init.h>
  19. #include <linux/wait.h>
  20. #include <linux/time.h>
  21. #include <linux/pnp.h>
  22. #include <linux/moduleparam.h>
  23. #include <sound/core.h>
  24. #include <sound/initval.h>
  25. #include <sound/mpu401.h>
  26. #include <sound/opl3.h>
  27. #include <sound/sb.h>
  28. #define PFX "als100: "
  29. MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
  30. MODULE_DESCRIPTION("Avance Logic ALS1X0");
  31. MODULE_LICENSE("GPL");
  32. MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP},"
  33. "{Avance Logic,ALS110},"
  34. "{Avance Logic,ALS120},"
  35. "{Avance Logic,ALS200},"
  36. "{3D Melody,MF1000},"
  37. "{Digimate,3D Sound},"
  38. "{Avance Logic,ALS120},"
  39. "{RTL,RTL3000}}");
  40. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  41. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  42. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  43. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  44. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  45. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  46. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
  47. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
  48. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  49. static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
  50. module_param_array(index, int, NULL, 0444);
  51. MODULE_PARM_DESC(index, "Index value for als100 based soundcard.");
  52. module_param_array(id, charp, NULL, 0444);
  53. MODULE_PARM_DESC(id, "ID string for als100 based soundcard.");
  54. module_param_array(enable, bool, NULL, 0444);
  55. MODULE_PARM_DESC(enable, "Enable als100 based soundcard.");
  56. module_param_array(port, long, NULL, 0444);
  57. MODULE_PARM_DESC(port, "Port # for als100 driver.");
  58. module_param_array(mpu_port, long, NULL, 0444);
  59. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for als100 driver.");
  60. module_param_array(fm_port, long, NULL, 0444);
  61. MODULE_PARM_DESC(fm_port, "FM port # for als100 driver.");
  62. module_param_array(irq, int, NULL, 0444);
  63. MODULE_PARM_DESC(irq, "IRQ # for als100 driver.");
  64. module_param_array(mpu_irq, int, NULL, 0444);
  65. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for als100 driver.");
  66. module_param_array(dma8, int, NULL, 0444);
  67. MODULE_PARM_DESC(dma8, "8-bit DMA # for als100 driver.");
  68. module_param_array(dma16, int, NULL, 0444);
  69. MODULE_PARM_DESC(dma16, "16-bit DMA # for als100 driver.");
  70. struct snd_card_als100 {
  71. int dev_no;
  72. struct pnp_dev *dev;
  73. struct pnp_dev *devmpu;
  74. struct pnp_dev *devopl;
  75. };
  76. static struct pnp_card_device_id snd_als100_pnpids[] = {
  77. /* ALS100 - PRO16PNP */
  78. { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
  79. /* ALS110 - MF1000 - Digimate 3D Sound */
  80. { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } },
  81. /* ALS120 */
  82. { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
  83. /* ALS200 */
  84. { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } },
  85. /* ALS200 OEM */
  86. { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } } },
  87. /* RTL3000 */
  88. { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
  89. { .id = "", } /* end */
  90. };
  91. MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
  92. #define DRIVER_NAME "snd-card-als100"
  93. static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
  94. struct pnp_card_link *card,
  95. const struct pnp_card_device_id *id)
  96. {
  97. struct pnp_dev *pdev;
  98. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  99. int err;
  100. if (!cfg)
  101. return -ENOMEM;
  102. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  103. if (acard->dev == NULL) {
  104. kfree(cfg);
  105. return -ENODEV;
  106. }
  107. acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
  108. acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->dev);
  109. pdev = acard->dev;
  110. pnp_init_resource_table(cfg);
  111. /* override resources */
  112. if (port[dev] != SNDRV_AUTO_PORT)
  113. pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
  114. if (dma8[dev] != SNDRV_AUTO_DMA)
  115. pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
  116. if (dma16[dev] != SNDRV_AUTO_DMA)
  117. pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
  118. if (irq[dev] != SNDRV_AUTO_IRQ)
  119. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  120. if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
  121. snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
  122. err = pnp_activate_dev(pdev);
  123. if (err < 0) {
  124. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  125. kfree(cfg);
  126. return err;
  127. }
  128. port[dev] = pnp_port_start(pdev, 0);
  129. dma8[dev] = pnp_dma(pdev, 1);
  130. dma16[dev] = pnp_dma(pdev, 0);
  131. irq[dev] = pnp_irq(pdev, 0);
  132. pdev = acard->devmpu;
  133. if (pdev != NULL) {
  134. pnp_init_resource_table(cfg);
  135. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  136. pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
  137. if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
  138. pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
  139. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  140. snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
  141. err = pnp_activate_dev(pdev);
  142. if (err < 0)
  143. goto __mpu_error;
  144. mpu_port[dev] = pnp_port_start(pdev, 0);
  145. mpu_irq[dev] = pnp_irq(pdev, 0);
  146. } else {
  147. __mpu_error:
  148. if (pdev) {
  149. pnp_release_card_device(pdev);
  150. snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
  151. }
  152. acard->devmpu = NULL;
  153. mpu_port[dev] = -1;
  154. }
  155. pdev = acard->devopl;
  156. if (pdev != NULL) {
  157. pnp_init_resource_table(cfg);
  158. if (fm_port[dev] != SNDRV_AUTO_PORT)
  159. pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
  160. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  161. snd_printk(KERN_ERR PFX "OPL3 the requested resources are invalid, using auto config\n");
  162. err = pnp_activate_dev(pdev);
  163. if (err < 0)
  164. goto __fm_error;
  165. fm_port[dev] = pnp_port_start(pdev, 0);
  166. } else {
  167. __fm_error:
  168. if (pdev) {
  169. pnp_release_card_device(pdev);
  170. snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
  171. }
  172. acard->devopl = NULL;
  173. fm_port[dev] = -1;
  174. }
  175. kfree(cfg);
  176. return 0;
  177. }
  178. static int __init snd_card_als100_probe(int dev,
  179. struct pnp_card_link *pcard,
  180. const struct pnp_card_device_id *pid)
  181. {
  182. int error;
  183. sb_t *chip;
  184. snd_card_t *card;
  185. struct snd_card_als100 *acard;
  186. opl3_t *opl3;
  187. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  188. sizeof(struct snd_card_als100))) == NULL)
  189. return -ENOMEM;
  190. acard = (struct snd_card_als100 *)card->private_data;
  191. if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
  192. snd_card_free(card);
  193. return error;
  194. }
  195. snd_card_set_dev(card, &pcard->card->dev);
  196. if ((error = snd_sbdsp_create(card, port[dev],
  197. irq[dev],
  198. snd_sb16dsp_interrupt,
  199. dma8[dev],
  200. dma16[dev],
  201. SB_HW_ALS100, &chip)) < 0) {
  202. snd_card_free(card);
  203. return error;
  204. }
  205. strcpy(card->driver, "ALS100");
  206. strcpy(card->shortname, "Avance Logic ALS100");
  207. sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
  208. card->shortname, chip->name, chip->port,
  209. irq[dev], dma8[dev], dma16[dev]);
  210. if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
  211. snd_card_free(card);
  212. return error;
  213. }
  214. if ((error = snd_sbmixer_new(chip)) < 0) {
  215. snd_card_free(card);
  216. return error;
  217. }
  218. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  219. if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100,
  220. mpu_port[dev], 0,
  221. mpu_irq[dev], SA_INTERRUPT,
  222. NULL) < 0)
  223. snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
  224. }
  225. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  226. if (snd_opl3_create(card,
  227. fm_port[dev], fm_port[dev] + 2,
  228. OPL3_HW_AUTO, 0, &opl3) < 0) {
  229. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
  230. fm_port[dev], fm_port[dev] + 2);
  231. } else {
  232. if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
  233. snd_card_free(card);
  234. return error;
  235. }
  236. if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  237. snd_card_free(card);
  238. return error;
  239. }
  240. }
  241. }
  242. if ((error = snd_card_register(card)) < 0) {
  243. snd_card_free(card);
  244. return error;
  245. }
  246. pnp_set_card_drvdata(pcard, card);
  247. return 0;
  248. }
  249. static int __devinit snd_als100_pnp_detect(struct pnp_card_link *card,
  250. const struct pnp_card_device_id *id)
  251. {
  252. static int dev;
  253. int res;
  254. for ( ; dev < SNDRV_CARDS; dev++) {
  255. if (!enable[dev])
  256. continue;
  257. res = snd_card_als100_probe(dev, card, id);
  258. if (res < 0)
  259. return res;
  260. dev++;
  261. return 0;
  262. }
  263. return -ENODEV;
  264. }
  265. static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
  266. {
  267. snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
  268. snd_card_disconnect(card);
  269. snd_card_free_in_thread(card);
  270. }
  271. static struct pnp_card_driver als100_pnpc_driver = {
  272. .flags = PNP_DRIVER_RES_DISABLE,
  273. .name = "als100",
  274. .id_table = snd_als100_pnpids,
  275. .probe = snd_als100_pnp_detect,
  276. .remove = __devexit_p(snd_als100_pnp_remove),
  277. };
  278. static int __init alsa_card_als100_init(void)
  279. {
  280. int cards = 0;
  281. cards += pnp_register_card_driver(&als100_pnpc_driver);
  282. #ifdef MODULE
  283. if (!cards) {
  284. pnp_unregister_card_driver(&als100_pnpc_driver);
  285. snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
  286. }
  287. #endif
  288. return cards ? 0 : -ENODEV;
  289. }
  290. static void __exit alsa_card_als100_exit(void)
  291. {
  292. pnp_unregister_card_driver(&als100_pnpc_driver);
  293. }
  294. module_init(alsa_card_als100_init)
  295. module_exit(alsa_card_als100_exit)