es1688.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Driver for generic ESS AudioDrive ESx688 soundcards
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  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. */
  21. #include <linux/init.h>
  22. #include <linux/err.h>
  23. #include <linux/isa.h>
  24. #include <linux/time.h>
  25. #include <linux/wait.h>
  26. #include <linux/moduleparam.h>
  27. #include <asm/dma.h>
  28. #include <sound/core.h>
  29. #include <sound/es1688.h>
  30. #include <sound/mpu401.h>
  31. #include <sound/opl3.h>
  32. #define SNDRV_LEGACY_FIND_FREE_IRQ
  33. #define SNDRV_LEGACY_FIND_FREE_DMA
  34. #include <sound/initval.h>
  35. #define CRD_NAME "Generic ESS ES1688/ES688 AudioDrive"
  36. #define DEV_NAME "es1688"
  37. MODULE_DESCRIPTION(CRD_NAME);
  38. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  39. MODULE_LICENSE("GPL");
  40. MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
  41. "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102},"
  42. "{ESS,ES688 AudioDrive,pnp:ESS6881},"
  43. "{ESS,ES1688 AudioDrive,pnp:ESS1681}}");
  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 int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  47. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
  48. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Usually 0x388 */
  49. static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
  50. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
  51. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
  52. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
  53. module_param_array(index, int, NULL, 0444);
  54. MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
  55. module_param_array(id, charp, NULL, 0444);
  56. MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
  57. module_param_array(enable, bool, NULL, 0444);
  58. MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
  59. module_param_array(port, long, NULL, 0444);
  60. MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
  61. module_param_array(mpu_port, long, NULL, 0444);
  62. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
  63. module_param_array(irq, int, NULL, 0444);
  64. module_param_array(fm_port, long, NULL, 0444);
  65. MODULE_PARM_DESC(fm_port, "FM port # for ES1688 driver.");
  66. MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
  67. module_param_array(mpu_irq, int, NULL, 0444);
  68. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
  69. module_param_array(dma8, int, NULL, 0444);
  70. MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver.");
  71. static int __devinit snd_es1688_match(struct device *dev, unsigned int n)
  72. {
  73. return enable[n];
  74. }
  75. static int __devinit snd_es1688_legacy_create(struct snd_card *card,
  76. struct device *dev, unsigned int n, struct snd_es1688 **rchip)
  77. {
  78. static long possible_ports[] = {0x220, 0x240, 0x260};
  79. static int possible_irqs[] = {5, 9, 10, 7, -1};
  80. static int possible_dmas[] = {1, 3, 0, -1};
  81. int i, error;
  82. if (irq[n] == SNDRV_AUTO_IRQ) {
  83. irq[n] = snd_legacy_find_free_irq(possible_irqs);
  84. if (irq[n] < 0) {
  85. dev_err(dev, "unable to find a free IRQ\n");
  86. return -EBUSY;
  87. }
  88. }
  89. if (dma8[n] == SNDRV_AUTO_DMA) {
  90. dma8[n] = snd_legacy_find_free_dma(possible_dmas);
  91. if (dma8[n] < 0) {
  92. dev_err(dev, "unable to find a free DMA\n");
  93. return -EBUSY;
  94. }
  95. }
  96. if (port[n] != SNDRV_AUTO_PORT)
  97. return snd_es1688_create(card, port[n], mpu_port[n], irq[n],
  98. mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
  99. i = 0;
  100. do {
  101. port[n] = possible_ports[i];
  102. error = snd_es1688_create(card, port[n], mpu_port[n], irq[n],
  103. mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
  104. } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
  105. return error;
  106. }
  107. static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
  108. {
  109. struct snd_card *card;
  110. struct snd_es1688 *chip;
  111. struct snd_opl3 *opl3;
  112. struct snd_pcm *pcm;
  113. int error;
  114. error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
  115. if (error < 0)
  116. return error;
  117. error = snd_es1688_legacy_create(card, dev, n, &chip);
  118. if (error < 0)
  119. goto out;
  120. error = snd_es1688_pcm(chip, 0, &pcm);
  121. if (error < 0)
  122. goto out;
  123. error = snd_es1688_mixer(chip);
  124. if (error < 0)
  125. goto out;
  126. strcpy(card->driver, "ES1688");
  127. strcpy(card->shortname, pcm->name);
  128. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
  129. chip->port, chip->irq, chip->dma8);
  130. if (fm_port[n] == SNDRV_AUTO_PORT)
  131. fm_port[n] = port[n]; /* share the same port */
  132. if (fm_port[n] > 0) {
  133. if (snd_opl3_create(card, fm_port[n], fm_port[n] + 2,
  134. OPL3_HW_OPL3, 0, &opl3) < 0)
  135. dev_warn(dev,
  136. "opl3 not detected at 0x%lx\n", fm_port[n]);
  137. else {
  138. error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
  139. if (error < 0)
  140. goto out;
  141. }
  142. }
  143. if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ &&
  144. chip->mpu_port > 0) {
  145. error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
  146. chip->mpu_port, 0,
  147. mpu_irq[n], IRQF_DISABLED, NULL);
  148. if (error < 0)
  149. goto out;
  150. }
  151. snd_card_set_dev(card, dev);
  152. error = snd_card_register(card);
  153. if (error < 0)
  154. goto out;
  155. dev_set_drvdata(dev, card);
  156. return 0;
  157. out: snd_card_free(card);
  158. return error;
  159. }
  160. static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
  161. {
  162. snd_card_free(dev_get_drvdata(dev));
  163. dev_set_drvdata(dev, NULL);
  164. return 0;
  165. }
  166. static struct isa_driver snd_es1688_driver = {
  167. .match = snd_es1688_match,
  168. .probe = snd_es1688_probe,
  169. .remove = __devexit_p(snd_es1688_remove),
  170. #if 0 /* FIXME */
  171. .suspend = snd_es1688_suspend,
  172. .resume = snd_es1688_resume,
  173. #endif
  174. .driver = {
  175. .name = DEV_NAME
  176. }
  177. };
  178. static int __init alsa_card_es1688_init(void)
  179. {
  180. return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS);
  181. }
  182. static void __exit alsa_card_es1688_exit(void)
  183. {
  184. isa_unregister_driver(&snd_es1688_driver);
  185. }
  186. module_init(alsa_card_es1688_init);
  187. module_exit(alsa_card_es1688_exit);