als100.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. struct snd_sb *chip;
  76. };
  77. static struct pnp_card_device_id snd_als100_pnpids[] = {
  78. /* ALS100 - PRO16PNP */
  79. { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
  80. /* ALS110 - MF1000 - Digimate 3D Sound */
  81. { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } },
  82. /* ALS120 */
  83. { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
  84. /* ALS200 */
  85. { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } },
  86. /* ALS200 OEM */
  87. { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } } },
  88. /* RTL3000 */
  89. { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } },
  90. { .id = "", } /* end */
  91. };
  92. MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
  93. #define DRIVER_NAME "snd-card-als100"
  94. static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
  95. struct pnp_card_link *card,
  96. const struct pnp_card_device_id *id)
  97. {
  98. struct pnp_dev *pdev;
  99. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  100. int err;
  101. if (!cfg)
  102. return -ENOMEM;
  103. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  104. if (acard->dev == NULL) {
  105. kfree(cfg);
  106. return -ENODEV;
  107. }
  108. acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
  109. acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->dev);
  110. pdev = acard->dev;
  111. pnp_init_resource_table(cfg);
  112. /* override resources */
  113. if (port[dev] != SNDRV_AUTO_PORT)
  114. pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
  115. if (dma8[dev] != SNDRV_AUTO_DMA)
  116. pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
  117. if (dma16[dev] != SNDRV_AUTO_DMA)
  118. pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
  119. if (irq[dev] != SNDRV_AUTO_IRQ)
  120. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  121. if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
  122. snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
  123. err = pnp_activate_dev(pdev);
  124. if (err < 0) {
  125. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  126. kfree(cfg);
  127. return err;
  128. }
  129. port[dev] = pnp_port_start(pdev, 0);
  130. dma8[dev] = pnp_dma(pdev, 1);
  131. dma16[dev] = pnp_dma(pdev, 0);
  132. irq[dev] = pnp_irq(pdev, 0);
  133. pdev = acard->devmpu;
  134. if (pdev != NULL) {
  135. pnp_init_resource_table(cfg);
  136. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  137. pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
  138. if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
  139. pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
  140. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  141. snd_printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
  142. err = pnp_activate_dev(pdev);
  143. if (err < 0)
  144. goto __mpu_error;
  145. mpu_port[dev] = pnp_port_start(pdev, 0);
  146. mpu_irq[dev] = pnp_irq(pdev, 0);
  147. } else {
  148. __mpu_error:
  149. if (pdev) {
  150. pnp_release_card_device(pdev);
  151. snd_printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
  152. }
  153. acard->devmpu = NULL;
  154. mpu_port[dev] = -1;
  155. }
  156. pdev = acard->devopl;
  157. if (pdev != NULL) {
  158. pnp_init_resource_table(cfg);
  159. if (fm_port[dev] != SNDRV_AUTO_PORT)
  160. pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
  161. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  162. snd_printk(KERN_ERR PFX "OPL3 the requested resources are invalid, using auto config\n");
  163. err = pnp_activate_dev(pdev);
  164. if (err < 0)
  165. goto __fm_error;
  166. fm_port[dev] = pnp_port_start(pdev, 0);
  167. } else {
  168. __fm_error:
  169. if (pdev) {
  170. pnp_release_card_device(pdev);
  171. snd_printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
  172. }
  173. acard->devopl = NULL;
  174. fm_port[dev] = -1;
  175. }
  176. kfree(cfg);
  177. return 0;
  178. }
  179. static int __init snd_card_als100_probe(int dev,
  180. struct pnp_card_link *pcard,
  181. const struct pnp_card_device_id *pid)
  182. {
  183. int error;
  184. struct snd_sb *chip;
  185. struct snd_card *card;
  186. struct snd_card_als100 *acard;
  187. struct snd_opl3 *opl3;
  188. if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  189. sizeof(struct snd_card_als100))) == NULL)
  190. return -ENOMEM;
  191. acard = card->private_data;
  192. if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
  193. snd_card_free(card);
  194. return error;
  195. }
  196. snd_card_set_dev(card, &pcard->card->dev);
  197. if ((error = snd_sbdsp_create(card, port[dev],
  198. irq[dev],
  199. snd_sb16dsp_interrupt,
  200. dma8[dev],
  201. dma16[dev],
  202. SB_HW_ALS100, &chip)) < 0) {
  203. snd_card_free(card);
  204. return error;
  205. }
  206. acard->chip = chip;
  207. strcpy(card->driver, "ALS100");
  208. strcpy(card->shortname, "Avance Logic ALS100");
  209. sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
  210. card->shortname, chip->name, chip->port,
  211. irq[dev], dma8[dev], dma16[dev]);
  212. if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
  213. snd_card_free(card);
  214. return error;
  215. }
  216. if ((error = snd_sbmixer_new(chip)) < 0) {
  217. snd_card_free(card);
  218. return error;
  219. }
  220. if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
  221. if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100,
  222. mpu_port[dev], 0,
  223. mpu_irq[dev], SA_INTERRUPT,
  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 int __devinit 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. return 0;
  264. }
  265. return -ENODEV;
  266. }
  267. static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
  268. {
  269. snd_card_free(pnp_get_card_drvdata(pcard));
  270. pnp_set_card_drvdata(pcard, NULL);
  271. }
  272. #ifdef CONFIG_PM
  273. static int snd_als100_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
  274. {
  275. struct snd_card *card = pnp_get_card_drvdata(pcard);
  276. struct snd_card_als100 *acard = card->private_data;
  277. struct snd_sb *chip = acard->chip;
  278. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  279. snd_pcm_suspend_all(chip->pcm);
  280. snd_sbmixer_suspend(chip);
  281. return 0;
  282. }
  283. static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
  284. {
  285. struct snd_card *card = pnp_get_card_drvdata(pcard);
  286. struct snd_card_als100 *acard = card->private_data;
  287. struct snd_sb *chip = acard->chip;
  288. snd_sbdsp_reset(chip);
  289. snd_sbmixer_resume(chip);
  290. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  291. return 0;
  292. }
  293. #endif
  294. static struct pnp_card_driver als100_pnpc_driver = {
  295. .flags = PNP_DRIVER_RES_DISABLE,
  296. .name = "als100",
  297. .id_table = snd_als100_pnpids,
  298. .probe = snd_als100_pnp_detect,
  299. .remove = __devexit_p(snd_als100_pnp_remove),
  300. #ifdef CONFIG_PM
  301. .suspend = snd_als100_pnp_suspend,
  302. .resume = snd_als100_pnp_resume,
  303. #endif
  304. };
  305. static int __init alsa_card_als100_init(void)
  306. {
  307. int cards;
  308. cards = pnp_register_card_driver(&als100_pnpc_driver);
  309. if (cards <= 0) {
  310. pnp_unregister_card_driver(&als100_pnpc_driver);
  311. #ifdef MODULE
  312. snd_printk(KERN_ERR "no ALS100 based soundcards found\n");
  313. #endif
  314. return -ENODEV;
  315. }
  316. return 0;
  317. }
  318. static void __exit alsa_card_als100_exit(void)
  319. {
  320. pnp_unregister_card_driver(&als100_pnpc_driver);
  321. }
  322. module_init(alsa_card_als100_init)
  323. module_exit(alsa_card_als100_exit)