gusclassic.c 7.3 KB

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