initial commit with v2.6.9
[linux-2.6.9-moxart.git] / sound / isa / gus / gusclassic.c
blob83b472da61bd7b2435fbeb7c063c707b0ae1e3d7
1 /*
2 * Driver for Gravis UltraSound Classic soundcard
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
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.
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.
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
22 #include <sound/driver.h>
23 #include <asm/dma.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/time.h>
27 #include <linux/moduleparam.h>
28 #include <sound/core.h>
29 #include <sound/gus.h>
30 #define SNDRV_LEGACY_AUTO_PROBE
31 #define SNDRV_LEGACY_FIND_FREE_IRQ
32 #define SNDRV_LEGACY_FIND_FREE_DMA
33 #include <sound/initval.h>
35 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
36 MODULE_DESCRIPTION("Gravis UltraSound Classic");
37 MODULE_LICENSE("GPL");
38 MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}");
40 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
41 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
42 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
43 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
44 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
45 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
46 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
47 static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
48 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
49 static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
50 static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
51 static int boot_devs;
53 module_param_array(index, int, boot_devs, 0444);
54 MODULE_PARM_DESC(index, "Index value for GUS Classic soundcard.");
55 module_param_array(id, charp, boot_devs, 0444);
56 MODULE_PARM_DESC(id, "ID string for GUS Classic soundcard.");
57 module_param_array(enable, bool, boot_devs, 0444);
58 MODULE_PARM_DESC(enable, "Enable GUS Classic soundcard.");
59 module_param_array(port, long, boot_devs, 0444);
60 MODULE_PARM_DESC(port, "Port # for GUS Classic driver.");
61 module_param_array(irq, int, boot_devs, 0444);
62 MODULE_PARM_DESC(irq, "IRQ # for GUS Classic driver.");
63 module_param_array(dma1, int, boot_devs, 0444);
64 MODULE_PARM_DESC(dma1, "DMA1 # for GUS Classic driver.");
65 module_param_array(dma2, int, boot_devs, 0444);
66 MODULE_PARM_DESC(dma2, "DMA2 # for GUS Classic driver.");
67 module_param_array(joystick_dac, int, boot_devs, 0444);
68 MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS Classic driver.");
69 module_param_array(channels, int, boot_devs, 0444);
70 MODULE_PARM_DESC(channels, "GF1 channels for GUS Classic driver.");
71 module_param_array(pcm_channels, int, boot_devs, 0444);
72 MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS Classic driver.");
74 static snd_card_t *snd_gusclassic_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
77 static int __init snd_gusclassic_detect(snd_gus_card_t * gus)
79 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
80 #ifdef CONFIG_SND_DEBUG_DETECT
82 unsigned char d;
84 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
85 snd_printk("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
86 return -ENODEV;
89 #else
90 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 0)
91 return -ENODEV;
92 #endif
93 udelay(160);
94 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
95 udelay(160);
96 #ifdef CONFIG_SND_DEBUG_DETECT
98 unsigned char d;
100 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
101 snd_printk("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
102 return -ENODEV;
105 #else
106 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 1)
107 return -ENODEV;
108 #endif
110 return 0;
113 static void __init snd_gusclassic_init(int dev, snd_gus_card_t * gus)
115 gus->equal_irq = 0;
116 gus->codec_flag = 0;
117 gus->max_flag = 0;
118 gus->joystick_dac = joystick_dac[dev];
121 static int __init snd_gusclassic_probe(int dev)
123 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
124 static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
125 int xirq, xdma1, xdma2;
126 snd_card_t *card;
127 struct snd_gusclassic *guscard;
128 snd_gus_card_t *gus = NULL;
129 int err;
131 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
132 if (card == NULL)
133 return -ENOMEM;
134 guscard = (struct snd_gusclassic *)card->private_data;
135 if (pcm_channels[dev] < 2)
136 pcm_channels[dev] = 2;
138 xirq = irq[dev];
139 if (xirq == SNDRV_AUTO_IRQ) {
140 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
141 snd_card_free(card);
142 snd_printk("unable to find a free IRQ\n");
143 return -EBUSY;
146 xdma1 = dma1[dev];
147 if (xdma1 == SNDRV_AUTO_DMA) {
148 if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
149 snd_card_free(card);
150 snd_printk("unable to find a free DMA1\n");
151 return -EBUSY;
154 xdma2 = dma2[dev];
155 if (xdma2 == SNDRV_AUTO_DMA) {
156 if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
157 snd_card_free(card);
158 snd_printk("unable to find a free DMA2\n");
159 return -EBUSY;
164 if ((err = snd_gus_create(card,
165 port[dev],
166 xirq, xdma1, xdma2,
167 0, channels[dev], pcm_channels[dev],
168 0, &gus)) < 0) {
169 snd_card_free(card);
170 return err;
172 if ((err = snd_gusclassic_detect(gus)) < 0) {
173 snd_card_free(card);
174 return err;
176 snd_gusclassic_init(dev, gus);
177 if ((err = snd_gus_initialize(gus)) < 0) {
178 snd_card_free(card);
179 return err;
181 if (gus->max_flag || gus->ess_flag) {
182 snd_printdd("GUS Classic or ACE soundcard was not detected at 0x%lx\n", gus->gf1.port);
183 snd_card_free(card);
184 return -ENODEV;
186 if ((err = snd_gf1_new_mixer(gus)) < 0) {
187 snd_card_free(card);
188 return err;
190 if ((err = snd_gf1_pcm_new(gus, 0, 0, NULL)) < 0) {
191 snd_card_free(card);
192 return err;
194 if (!gus->ace_flag) {
195 if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) {
196 snd_card_free(card);
197 return err;
200 sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %d, dma %d", gus->gf1.port, xirq, xdma1);
201 if (dma2 >= 0)
202 sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
203 if ((err = snd_card_register(card)) < 0) {
204 snd_card_free(card);
205 return err;
207 snd_gusclassic_cards[dev] = card;
208 return 0;
211 static int __init snd_gusclassic_legacy_auto_probe(unsigned long xport)
213 static int dev;
214 int res;
216 for ( ; dev < SNDRV_CARDS; dev++) {
217 if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
218 continue;
219 port[dev] = xport;
220 res = snd_gusclassic_probe(dev);
221 if (res < 0)
222 port[dev] = SNDRV_AUTO_PORT;
223 return res;
225 return -ENODEV;
228 static int __init alsa_card_gusclassic_init(void)
230 static unsigned long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260, -1};
231 int dev, cards, i;
233 for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
234 if (port[dev] == SNDRV_AUTO_PORT)
235 continue;
236 if (snd_gusclassic_probe(dev) >= 0)
237 cards++;
239 i = snd_legacy_auto_probe(possible_ports, snd_gusclassic_legacy_auto_probe);
240 if (i > 0)
241 cards += i;
243 if (!cards) {
244 #ifdef MODULE
245 printk(KERN_ERR "GUS Classic soundcard not found or device busy\n");
246 #endif
247 return -ENODEV;
249 return 0;
252 static void __exit alsa_card_gusclassic_exit(void)
254 int idx;
256 for (idx = 0; idx < SNDRV_CARDS; idx++)
257 snd_card_free(snd_gusclassic_cards[idx]);
260 module_init(alsa_card_gusclassic_init)
261 module_exit(alsa_card_gusclassic_exit)