es1688.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Driver for generic ESS AudioDrive ESx688 soundcards
  3. * Copyright (c) by Jaroslav Kysela <perex@suse.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 <sound/driver.h>
  22. #include <asm/dma.h>
  23. #include <linux/init.h>
  24. #include <linux/time.h>
  25. #include <linux/wait.h>
  26. #include <linux/moduleparam.h>
  27. #include <sound/core.h>
  28. #include <sound/es1688.h>
  29. #include <sound/mpu401.h>
  30. #include <sound/opl3.h>
  31. #define SNDRV_LEGACY_AUTO_PROBE
  32. #define SNDRV_LEGACY_FIND_FREE_IRQ
  33. #define SNDRV_LEGACY_FIND_FREE_DMA
  34. #include <sound/initval.h>
  35. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  36. MODULE_DESCRIPTION("ESS ESx688 AudioDrive");
  37. MODULE_LICENSE("GPL");
  38. MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
  39. "{ESS,ES1688 PnP AudioDrive,pnp:ESS0102},"
  40. "{ESS,ES688 AudioDrive,pnp:ESS6881},"
  41. "{ESS,ES1688 AudioDrive,pnp:ESS1681}}");
  42. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  43. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  44. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  45. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
  46. static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
  47. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
  48. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
  49. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
  50. module_param_array(index, int, NULL, 0444);
  51. MODULE_PARM_DESC(index, "Index value for ESx688 soundcard.");
  52. module_param_array(id, charp, NULL, 0444);
  53. MODULE_PARM_DESC(id, "ID string for ESx688 soundcard.");
  54. module_param_array(enable, bool, NULL, 0444);
  55. MODULE_PARM_DESC(enable, "Enable ESx688 soundcard.");
  56. module_param_array(port, long, NULL, 0444);
  57. MODULE_PARM_DESC(port, "Port # for ESx688 driver.");
  58. module_param_array(mpu_port, long, NULL, 0444);
  59. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ESx688 driver.");
  60. module_param_array(irq, int, NULL, 0444);
  61. MODULE_PARM_DESC(irq, "IRQ # for ESx688 driver.");
  62. module_param_array(mpu_irq, int, NULL, 0444);
  63. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ESx688 driver.");
  64. module_param_array(dma8, int, NULL, 0444);
  65. MODULE_PARM_DESC(dma8, "8-bit DMA # for ESx688 driver.");
  66. static snd_card_t *snd_audiodrive_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
  67. static int __init snd_audiodrive_probe(int dev)
  68. {
  69. static int possible_irqs[] = {5, 9, 10, 7, -1};
  70. static int possible_dmas[] = {1, 3, 0, -1};
  71. int xirq, xdma, xmpu_irq;
  72. snd_card_t *card;
  73. es1688_t *chip;
  74. opl3_t *opl3;
  75. snd_pcm_t *pcm;
  76. int err;
  77. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  78. if (card == NULL)
  79. return -ENOMEM;
  80. xirq = irq[dev];
  81. if (xirq == SNDRV_AUTO_IRQ) {
  82. if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
  83. snd_card_free(card);
  84. snd_printk("unable to find a free IRQ\n");
  85. return -EBUSY;
  86. }
  87. }
  88. xmpu_irq = mpu_irq[dev];
  89. xdma = dma8[dev];
  90. if (xdma == SNDRV_AUTO_DMA) {
  91. if ((xdma = snd_legacy_find_free_dma(possible_dmas)) < 0) {
  92. snd_card_free(card);
  93. snd_printk("unable to find a free DMA\n");
  94. return -EBUSY;
  95. }
  96. }
  97. if ((err = snd_es1688_create(card, port[dev], mpu_port[dev],
  98. xirq, xmpu_irq, xdma,
  99. ES1688_HW_AUTO, &chip)) < 0) {
  100. snd_card_free(card);
  101. return err;
  102. }
  103. if ((err = snd_es1688_pcm(chip, 0, &pcm)) < 0) {
  104. snd_card_free(card);
  105. return err;
  106. }
  107. if ((err = snd_es1688_mixer(chip)) < 0) {
  108. snd_card_free(card);
  109. return err;
  110. }
  111. strcpy(card->driver, "ES1688");
  112. strcpy(card->shortname, pcm->name);
  113. sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port, xirq, xdma);
  114. if ((snd_opl3_create(card, chip->port, chip->port + 2, OPL3_HW_OPL3, 0, &opl3)) < 0) {
  115. printk(KERN_ERR "es1688: opl3 not detected at 0x%lx\n", chip->port);
  116. } else {
  117. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  118. snd_card_free(card);
  119. return err;
  120. }
  121. }
  122. if (xmpu_irq >= 0 && xmpu_irq != SNDRV_AUTO_IRQ && chip->mpu_port > 0) {
  123. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
  124. chip->mpu_port, 0,
  125. xmpu_irq,
  126. SA_INTERRUPT,
  127. NULL)) < 0) {
  128. snd_card_free(card);
  129. return err;
  130. }
  131. }
  132. if ((err = snd_card_register(card)) < 0) {
  133. snd_card_free(card);
  134. return err;
  135. }
  136. snd_audiodrive_cards[dev] = card;
  137. return 0;
  138. }
  139. static int __init snd_audiodrive_legacy_auto_probe(unsigned long xport)
  140. {
  141. static int dev;
  142. int res;
  143. for ( ; dev < SNDRV_CARDS; dev++) {
  144. if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
  145. continue;
  146. port[dev] = xport;
  147. res = snd_audiodrive_probe(dev);
  148. if (res < 0)
  149. port[dev] = SNDRV_AUTO_PORT;
  150. return res;
  151. }
  152. return -ENODEV;
  153. }
  154. static int __init alsa_card_es1688_init(void)
  155. {
  156. static unsigned long possible_ports[] = {0x220, 0x240, 0x260, -1};
  157. int dev, cards = 0, i;
  158. for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
  159. if (port[dev] == SNDRV_AUTO_PORT)
  160. continue;
  161. if (snd_audiodrive_probe(dev) >= 0)
  162. cards++;
  163. }
  164. i = snd_legacy_auto_probe(possible_ports, snd_audiodrive_legacy_auto_probe);
  165. if (i > 0)
  166. cards += i;
  167. if (!cards) {
  168. #ifdef MODULE
  169. printk(KERN_ERR "ESS AudioDrive ES1688 soundcard not found or device busy\n");
  170. #endif
  171. return -ENODEV;
  172. }
  173. return 0;
  174. }
  175. static void __exit alsa_card_es1688_exit(void)
  176. {
  177. int idx;
  178. for (idx = 0; idx < SNDRV_CARDS; idx++)
  179. snd_card_free(snd_audiodrive_cards[idx]);
  180. }
  181. module_init(alsa_card_es1688_init)
  182. module_exit(alsa_card_es1688_exit)