gusclassic.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Driver for Gravis UltraSound Classic soundcard
  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/delay.h>
  25. #include <linux/time.h>
  26. #include <linux/module.h>
  27. #include <asm/dma.h>
  28. #include <sound/core.h>
  29. #include <sound/gus.h>
  30. #define SNDRV_LEGACY_FIND_FREE_IRQ
  31. #define SNDRV_LEGACY_FIND_FREE_DMA
  32. #include <sound/initval.h>
  33. #define CRD_NAME "Gravis UltraSound Classic"
  34. #define DEV_NAME "gusclassic"
  35. MODULE_DESCRIPTION(CRD_NAME);
  36. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  37. MODULE_LICENSE("GPL");
  38. MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}");
  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 bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  42. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
  43. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
  44. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
  45. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
  46. static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
  47. /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
  48. static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
  49. static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
  50. module_param_array(index, int, NULL, 0444);
  51. MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
  52. module_param_array(id, charp, NULL, 0444);
  53. MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
  54. module_param_array(enable, bool, NULL, 0444);
  55. MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
  56. module_param_array(port, long, NULL, 0444);
  57. MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
  58. module_param_array(irq, int, NULL, 0444);
  59. MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
  60. module_param_array(dma1, int, NULL, 0444);
  61. MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
  62. module_param_array(dma2, int, NULL, 0444);
  63. MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
  64. module_param_array(joystick_dac, int, NULL, 0444);
  65. MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver.");
  66. module_param_array(channels, int, NULL, 0444);
  67. MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver.");
  68. module_param_array(pcm_channels, int, NULL, 0444);
  69. MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver.");
  70. static int snd_gusclassic_match(struct device *dev, unsigned int n)
  71. {
  72. return enable[n];
  73. }
  74. static int snd_gusclassic_create(struct snd_card *card,
  75. struct device *dev, unsigned int n,
  76. struct snd_gus_card **rgus)
  77. {
  78. static long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260};
  79. static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
  80. static int possible_dmas[] = {5, 6, 7, 1, 3, -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 (dma1[n] == SNDRV_AUTO_DMA) {
  90. dma1[n] = snd_legacy_find_free_dma(possible_dmas);
  91. if (dma1[n] < 0) {
  92. dev_err(dev, "unable to find a free DMA1\n");
  93. return -EBUSY;
  94. }
  95. }
  96. if (dma2[n] == SNDRV_AUTO_DMA) {
  97. dma2[n] = snd_legacy_find_free_dma(possible_dmas);
  98. if (dma2[n] < 0) {
  99. dev_err(dev, "unable to find a free DMA2\n");
  100. return -EBUSY;
  101. }
  102. }
  103. if (port[n] != SNDRV_AUTO_PORT)
  104. return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
  105. 0, channels[n], pcm_channels[n], 0, rgus);
  106. i = 0;
  107. do {
  108. port[n] = possible_ports[i];
  109. error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
  110. 0, channels[n], pcm_channels[n], 0, rgus);
  111. } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
  112. return error;
  113. }
  114. static int snd_gusclassic_detect(struct snd_gus_card *gus)
  115. {
  116. unsigned char d;
  117. snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
  118. if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
  119. snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
  120. return -ENODEV;
  121. }
  122. udelay(160);
  123. snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
  124. udelay(160);
  125. if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
  126. snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
  127. return -ENODEV;
  128. }
  129. return 0;
  130. }
  131. static int snd_gusclassic_probe(struct device *dev, unsigned int n)
  132. {
  133. struct snd_card *card;
  134. struct snd_gus_card *gus;
  135. int error;
  136. error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
  137. if (error < 0)
  138. return error;
  139. if (pcm_channels[n] < 2)
  140. pcm_channels[n] = 2;
  141. error = snd_gusclassic_create(card, dev, n, &gus);
  142. if (error < 0)
  143. goto out;
  144. error = snd_gusclassic_detect(gus);
  145. if (error < 0)
  146. goto out;
  147. gus->joystick_dac = joystick_dac[n];
  148. error = snd_gus_initialize(gus);
  149. if (error < 0)
  150. goto out;
  151. error = -ENODEV;
  152. if (gus->max_flag || gus->ess_flag) {
  153. dev_err(dev, "GUS Classic or ACE soundcard was "
  154. "not detected at 0x%lx\n", gus->gf1.port);
  155. goto out;
  156. }
  157. error = snd_gf1_new_mixer(gus);
  158. if (error < 0)
  159. goto out;
  160. error = snd_gf1_pcm_new(gus, 0, 0);
  161. if (error < 0)
  162. goto out;
  163. if (!gus->ace_flag) {
  164. error = snd_gf1_rawmidi_new(gus, 0);
  165. if (error < 0)
  166. goto out;
  167. }
  168. sprintf(card->longname + strlen(card->longname),
  169. " at 0x%lx, irq %d, dma %d",
  170. gus->gf1.port, gus->gf1.irq, gus->gf1.dma1);
  171. if (gus->gf1.dma2 >= 0)
  172. sprintf(card->longname + strlen(card->longname),
  173. "&%d", gus->gf1.dma2);
  174. error = snd_card_register(card);
  175. if (error < 0)
  176. goto out;
  177. dev_set_drvdata(dev, card);
  178. return 0;
  179. out: snd_card_free(card);
  180. return error;
  181. }
  182. static int snd_gusclassic_remove(struct device *dev, unsigned int n)
  183. {
  184. snd_card_free(dev_get_drvdata(dev));
  185. return 0;
  186. }
  187. static struct isa_driver snd_gusclassic_driver = {
  188. .match = snd_gusclassic_match,
  189. .probe = snd_gusclassic_probe,
  190. .remove = snd_gusclassic_remove,
  191. #if 0 /* FIXME */
  192. .suspend = snd_gusclassic_suspend,
  193. .remove = snd_gusclassic_remove,
  194. #endif
  195. .driver = {
  196. .name = DEV_NAME
  197. }
  198. };
  199. static int __init alsa_card_gusclassic_init(void)
  200. {
  201. return isa_register_driver(&snd_gusclassic_driver, SNDRV_CARDS);
  202. }
  203. static void __exit alsa_card_gusclassic_exit(void)
  204. {
  205. isa_unregister_driver(&snd_gusclassic_driver);
  206. }
  207. module_init(alsa_card_gusclassic_init);
  208. module_exit(alsa_card_gusclassic_exit);