gusclassic.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. static int __init snd_gusclassic_detect(snd_gus_card_t * gus)
  70. {
  71. snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
  72. #ifdef CONFIG_SND_DEBUG_DETECT
  73. {
  74. unsigned char d;
  75. if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
  76. snd_printk("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
  77. return -ENODEV;
  78. }
  79. }
  80. #else
  81. if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 0)
  82. return -ENODEV;
  83. #endif
  84. udelay(160);
  85. snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
  86. udelay(160);
  87. #ifdef CONFIG_SND_DEBUG_DETECT
  88. {
  89. unsigned char d;
  90. if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
  91. snd_printk("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
  92. return -ENODEV;
  93. }
  94. }
  95. #else
  96. if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 1)
  97. return -ENODEV;
  98. #endif
  99. return 0;
  100. }
  101. static void __init snd_gusclassic_init(int dev, snd_gus_card_t * gus)
  102. {
  103. gus->equal_irq = 0;
  104. gus->codec_flag = 0;
  105. gus->max_flag = 0;
  106. gus->joystick_dac = joystick_dac[dev];
  107. }
  108. static int __init snd_gusclassic_probe(int dev)
  109. {
  110. static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
  111. static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
  112. int xirq, xdma1, xdma2;
  113. snd_card_t *card;
  114. struct snd_gusclassic *guscard;
  115. snd_gus_card_t *gus = NULL;
  116. int err;
  117. card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
  118. if (card == NULL)
  119. return -ENOMEM;
  120. guscard = (struct snd_gusclassic *)card->private_data;
  121. if (pcm_channels[dev] < 2)
  122. pcm_channels[dev] = 2;
  123. xirq = irq[dev];
  124. if (xirq == SNDRV_AUTO_IRQ) {
  125. if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
  126. snd_card_free(card);
  127. snd_printk("unable to find a free IRQ\n");
  128. return -EBUSY;
  129. }
  130. }
  131. xdma1 = dma1[dev];
  132. if (xdma1 == SNDRV_AUTO_DMA) {
  133. if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
  134. snd_card_free(card);
  135. snd_printk("unable to find a free DMA1\n");
  136. return -EBUSY;
  137. }
  138. }
  139. xdma2 = dma2[dev];
  140. if (xdma2 == SNDRV_AUTO_DMA) {
  141. if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
  142. snd_card_free(card);
  143. snd_printk("unable to find a free DMA2\n");
  144. return -EBUSY;
  145. }
  146. }
  147. if ((err = snd_gus_create(card,
  148. port[dev],
  149. xirq, xdma1, xdma2,
  150. 0, channels[dev], pcm_channels[dev],
  151. 0, &gus)) < 0) {
  152. snd_card_free(card);
  153. return err;
  154. }
  155. if ((err = snd_gusclassic_detect(gus)) < 0) {
  156. snd_card_free(card);
  157. return err;
  158. }
  159. snd_gusclassic_init(dev, gus);
  160. if ((err = snd_gus_initialize(gus)) < 0) {
  161. snd_card_free(card);
  162. return err;
  163. }
  164. if (gus->max_flag || gus->ess_flag) {
  165. snd_printdd("GUS Classic or ACE soundcard was not detected at 0x%lx\n", gus->gf1.port);
  166. snd_card_free(card);
  167. return -ENODEV;
  168. }
  169. if ((err = snd_gf1_new_mixer(gus)) < 0) {
  170. snd_card_free(card);
  171. return err;
  172. }
  173. if ((err = snd_gf1_pcm_new(gus, 0, 0, NULL)) < 0) {
  174. snd_card_free(card);
  175. return err;
  176. }
  177. if (!gus->ace_flag) {
  178. if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) {
  179. snd_card_free(card);
  180. return err;
  181. }
  182. }
  183. sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %d, dma %d", gus->gf1.port, xirq, xdma1);
  184. if (dma2 >= 0)
  185. sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
  186. if ((err = snd_card_register(card)) < 0) {
  187. snd_card_free(card);
  188. return err;
  189. }
  190. snd_gusclassic_cards[dev] = card;
  191. return 0;
  192. }
  193. static int __init snd_gusclassic_legacy_auto_probe(unsigned long xport)
  194. {
  195. static int dev;
  196. int res;
  197. for ( ; dev < SNDRV_CARDS; dev++) {
  198. if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
  199. continue;
  200. port[dev] = xport;
  201. res = snd_gusclassic_probe(dev);
  202. if (res < 0)
  203. port[dev] = SNDRV_AUTO_PORT;
  204. return res;
  205. }
  206. return -ENODEV;
  207. }
  208. static int __init alsa_card_gusclassic_init(void)
  209. {
  210. static unsigned long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260, -1};
  211. int dev, cards, i;
  212. for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
  213. if (port[dev] == SNDRV_AUTO_PORT)
  214. continue;
  215. if (snd_gusclassic_probe(dev) >= 0)
  216. cards++;
  217. }
  218. i = snd_legacy_auto_probe(possible_ports, snd_gusclassic_legacy_auto_probe);
  219. if (i > 0)
  220. cards += i;
  221. if (!cards) {
  222. #ifdef MODULE
  223. printk(KERN_ERR "GUS Classic soundcard not found or device busy\n");
  224. #endif
  225. return -ENODEV;
  226. }
  227. return 0;
  228. }
  229. static void __exit alsa_card_gusclassic_exit(void)
  230. {
  231. int idx;
  232. for (idx = 0; idx < SNDRV_CARDS; idx++)
  233. snd_card_free(snd_gusclassic_cards[idx]);
  234. }
  235. module_init(alsa_card_gusclassic_init)
  236. module_exit(alsa_card_gusclassic_exit)