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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | #define SNDRV_MAIN_OBJECT_FILE
|
---|
23 | #include <sound/driver.h>
|
---|
24 | #include <sound/gus.h>
|
---|
25 | #define SNDRV_LEGACY_AUTO_PROBE
|
---|
26 | #define SNDRV_LEGACY_FIND_FREE_IRQ
|
---|
27 | #define SNDRV_LEGACY_FIND_FREE_DMA
|
---|
28 | #define SNDRV_GET_ID
|
---|
29 | #include <sound/initval.h>
|
---|
30 |
|
---|
31 | EXPORT_NO_SYMBOLS;
|
---|
32 | MODULE_DESCRIPTION("Gravis UltraSound Classic");
|
---|
33 | MODULE_CLASSES("{sound}");
|
---|
34 | MODULE_DEVICES("{{Gravis,UltraSound Classic}}");
|
---|
35 |
|
---|
36 | static int snd_index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
---|
37 | static char *snd_id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
---|
38 | static int snd_enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
|
---|
39 | static long snd_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
|
---|
40 | static int snd_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
|
---|
41 | static int snd_dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
|
---|
42 | static int snd_dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
|
---|
43 | #ifdef TARGET_OS2
|
---|
44 | static int snd_joystick_dac[SNDRV_CARDS] = {REPEAT_SNDRV(29)};
|
---|
45 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
|
---|
46 | static int snd_channels[SNDRV_CARDS] = {REPEAT_SNDRV(24)};
|
---|
47 | static int snd_pcm_channels[SNDRV_CARDS] = {REPEAT_SNDRV(2)};
|
---|
48 | #else
|
---|
49 | static int snd_joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
|
---|
50 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
|
---|
51 | static int snd_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
|
---|
52 | static int snd_pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | MODULE_PARM(snd_index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
56 | MODULE_PARM_DESC(snd_index, "Index value for GUS Classic soundcard.");
|
---|
57 | MODULE_PARM_SYNTAX(snd_index, SNDRV_INDEX_DESC);
|
---|
58 | MODULE_PARM(snd_id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
|
---|
59 | MODULE_PARM_DESC(snd_id, "ID string for GUS Classic soundcard.");
|
---|
60 | MODULE_PARM_SYNTAX(snd_id, SNDRV_ID_DESC);
|
---|
61 | MODULE_PARM(snd_enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
62 | MODULE_PARM_DESC(snd_enable, "Enable GUS Classic soundcard.");
|
---|
63 | MODULE_PARM_SYNTAX(snd_enable, SNDRV_ENABLE_DESC);
|
---|
64 | MODULE_PARM(snd_port, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
|
---|
65 | MODULE_PARM_DESC(snd_port, "Port # for GUS Classic driver.");
|
---|
66 | MODULE_PARM_SYNTAX(snd_port, SNDRV_ENABLED ",allows:{{0x220,0x260,0x10}},dialog:list");
|
---|
67 | MODULE_PARM(snd_irq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
68 | MODULE_PARM_DESC(snd_irq, "IRQ # for GUS Classic driver.");
|
---|
69 | MODULE_PARM_SYNTAX(snd_irq, SNDRV_ENABLED ",allows:{{3},{5},{9},{11},{12},{15}},dialog:list");
|
---|
70 | MODULE_PARM(snd_dma1, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
71 | MODULE_PARM_DESC(snd_dma1, "DMA1 # for GUS Classic driver.");
|
---|
72 | MODULE_PARM_SYNTAX(snd_dma1, SNDRV_ENABLED ",allows:{{1},{3},{5},{6},{7}},dialog:list");
|
---|
73 | MODULE_PARM(snd_dma2, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
74 | MODULE_PARM_DESC(snd_dma2, "DMA2 # for GUS Classic driver.");
|
---|
75 | MODULE_PARM_SYNTAX(snd_dma2, SNDRV_ENABLED ",allows:{{1},{3},{5},{6},{7}},dialog:list");
|
---|
76 | MODULE_PARM(snd_joystick_dac, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
77 | MODULE_PARM_DESC(snd_joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS Classic driver.");
|
---|
78 | MODULE_PARM_SYNTAX(snd_joystick_dac, SNDRV_ENABLED ",allows:{{0,31}}");
|
---|
79 | MODULE_PARM(snd_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
80 | MODULE_PARM_DESC(snd_channels, "GF1 channels for GUS Classic driver.");
|
---|
81 | MODULE_PARM_SYNTAX(snd_channels, SNDRV_ENABLED ",allows:{{14,32}}");
|
---|
82 | MODULE_PARM(snd_pcm_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
|
---|
83 | MODULE_PARM_DESC(snd_pcm_channels, "Reserved PCM channels for GUS Classic driver.");
|
---|
84 | MODULE_PARM_SYNTAX(snd_pcm_channels, SNDRV_ENABLED ",allows:{{2,16}}");
|
---|
85 |
|
---|
86 | static snd_card_t *snd_gusclassic_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
|
---|
87 |
|
---|
88 |
|
---|
89 | static int __init snd_gusclassic_detect(snd_gus_card_t * gus)
|
---|
90 | {
|
---|
91 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
|
---|
92 | #ifdef CONFIG_SND_DEBUG_DETECT
|
---|
93 | {
|
---|
94 | unsigned char d;
|
---|
95 |
|
---|
96 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
|
---|
97 | snd_printk("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
|
---|
98 | return -ENODEV;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | #else
|
---|
102 | if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 0)
|
---|
103 | return -ENODEV;
|
---|
104 | #endif
|
---|
105 | udelay(160);
|
---|
106 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
|
---|
107 | udelay(160);
|
---|
108 | #ifdef CONFIG_SND_DEBUG_DETECT
|
---|
109 | {
|
---|
110 | unsigned char d;
|
---|
111 |
|
---|
112 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
|
---|
113 | snd_printk("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
|
---|
114 | return -ENODEV;
|
---|
115 | }
|
---|
116 | }
|
---|
117 | #else
|
---|
118 | if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 1)
|
---|
119 | return -ENODEV;
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | return 0;
|
---|
123 | }
|
---|
124 |
|
---|
125 | static void __init snd_gusclassic_init(int dev, snd_gus_card_t * gus)
|
---|
126 | {
|
---|
127 | gus->equal_irq = 0;
|
---|
128 | gus->codec_flag = 0;
|
---|
129 | gus->max_flag = 0;
|
---|
130 | gus->joystick_dac = snd_joystick_dac[dev];
|
---|
131 | }
|
---|
132 |
|
---|
133 | static int __init snd_gusclassic_probe(int dev)
|
---|
134 | {
|
---|
135 | static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
|
---|
136 | static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
|
---|
137 | int irq, dma1, dma2;
|
---|
138 | snd_card_t *card;
|
---|
139 | struct snd_gusclassic *guscard;
|
---|
140 | snd_gus_card_t *gus = NULL;
|
---|
141 | int err;
|
---|
142 |
|
---|
143 | card = snd_card_new(snd_index[dev], snd_id[dev], THIS_MODULE, 0);
|
---|
144 | if (card == NULL)
|
---|
145 | return -ENOMEM;
|
---|
146 | guscard = (struct snd_gusclassic *)card->private_data;
|
---|
147 | if (snd_pcm_channels[dev] < 2)
|
---|
148 | snd_pcm_channels[dev] = 2;
|
---|
149 |
|
---|
150 | irq = snd_irq[dev];
|
---|
151 | if (irq == SNDRV_AUTO_IRQ) {
|
---|
152 | if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
|
---|
153 | snd_card_free(card);
|
---|
154 | snd_printk("unable to find a free IRQ\n");
|
---|
155 | return -EBUSY;
|
---|
156 | }
|
---|
157 | }
|
---|
158 | dma1 = snd_dma1[dev];
|
---|
159 | if (dma1 == SNDRV_AUTO_DMA) {
|
---|
160 | if ((dma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
|
---|
161 | snd_card_free(card);
|
---|
162 | snd_printk("unable to find a free DMA1\n");
|
---|
163 | return -EBUSY;
|
---|
164 | }
|
---|
165 | }
|
---|
166 | dma2 = snd_dma2[dev];
|
---|
167 | if (dma2 == SNDRV_AUTO_DMA) {
|
---|
168 | if ((dma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
|
---|
169 | snd_card_free(card);
|
---|
170 | snd_printk("unable to find a free DMA2\n");
|
---|
171 | return -EBUSY;
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | if ((err = snd_gus_create(card,
|
---|
177 | snd_port[dev],
|
---|
178 | irq, dma1, dma2,
|
---|
179 | 0, snd_channels[dev], snd_pcm_channels[dev],
|
---|
180 | 0, &gus)) < 0) {
|
---|
181 | snd_card_free(card);
|
---|
182 | return err;
|
---|
183 | }
|
---|
184 | if ((err = snd_gusclassic_detect(gus)) < 0) {
|
---|
185 | snd_card_free(card);
|
---|
186 | return err;
|
---|
187 | }
|
---|
188 | snd_gusclassic_init(dev, gus);
|
---|
189 | if ((err = snd_gus_initialize(gus)) < 0) {
|
---|
190 | snd_card_free(card);
|
---|
191 | return err;
|
---|
192 | }
|
---|
193 | if (gus->max_flag || gus->ess_flag) {
|
---|
194 | snd_card_free(card);
|
---|
195 | snd_printdd("GUS Classic or ACE soundcard was not detected at 0x%lx\n", gus->gf1.port);
|
---|
196 | return -ENODEV;
|
---|
197 | }
|
---|
198 | if ((err = snd_gf1_new_mixer(gus)) < 0) {
|
---|
199 | snd_card_free(card);
|
---|
200 | return err;
|
---|
201 | }
|
---|
202 | if ((err = snd_gf1_pcm_new(gus, 0, 0, NULL)) < 0) {
|
---|
203 | snd_card_free(card);
|
---|
204 | return err;
|
---|
205 | }
|
---|
206 | if (!gus->ace_flag) {
|
---|
207 | if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) {
|
---|
208 | snd_card_free(card);
|
---|
209 | return err;
|
---|
210 | }
|
---|
211 | }
|
---|
212 | sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %d, dma %d", gus->gf1.port, irq, dma1);
|
---|
213 | if (dma2 >= 0)
|
---|
214 | sprintf(card->longname + strlen(card->longname), "&%d", dma2);
|
---|
215 | if ((err = snd_card_register(card)) < 0) {
|
---|
216 | snd_card_free(card);
|
---|
217 | return err;
|
---|
218 | }
|
---|
219 | snd_gusclassic_cards[dev] = card;
|
---|
220 | return 0;
|
---|
221 | }
|
---|
222 |
|
---|
223 | static int __init snd_gusclassic_legacy_auto_probe(unsigned long port)
|
---|
224 | {
|
---|
225 | static int dev = 0;
|
---|
226 | int res;
|
---|
227 |
|
---|
228 | for ( ; dev < SNDRV_CARDS; dev++) {
|
---|
229 | if (!snd_enable[dev] || snd_port[dev] != SNDRV_AUTO_PORT)
|
---|
230 | continue;
|
---|
231 | snd_port[dev] = port;
|
---|
232 | res = snd_gusclassic_probe(dev);
|
---|
233 | if (res < 0)
|
---|
234 | snd_port[dev] = SNDRV_AUTO_PORT;
|
---|
235 | return res;
|
---|
236 | }
|
---|
237 | return -ENODEV;
|
---|
238 | }
|
---|
239 |
|
---|
240 | static int __init alsa_card_gusclassic_init(void)
|
---|
241 | {
|
---|
242 | static unsigned long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260, -1};
|
---|
243 | int dev, cards;
|
---|
244 |
|
---|
245 | for (dev = cards = 0; dev < SNDRV_CARDS && snd_enable[dev]; dev++) {
|
---|
246 | if (snd_port[dev] == SNDRV_AUTO_PORT)
|
---|
247 | continue;
|
---|
248 | if (snd_gusclassic_probe(dev) >= 0)
|
---|
249 | cards++;
|
---|
250 | }
|
---|
251 | cards += snd_legacy_auto_probe(possible_ports, snd_gusclassic_legacy_auto_probe);
|
---|
252 | if (!cards) {
|
---|
253 | #ifdef MODULE
|
---|
254 | snd_printk("GUS Classic soundcard not found or device busy\n");
|
---|
255 | #endif
|
---|
256 | return -ENODEV;
|
---|
257 | }
|
---|
258 | return 0;
|
---|
259 | }
|
---|
260 |
|
---|
261 | static void __exit alsa_card_gusclassic_exit(void)
|
---|
262 | {
|
---|
263 | int idx;
|
---|
264 |
|
---|
265 | for (idx = 0; idx < SNDRV_CARDS; idx++)
|
---|
266 | snd_card_free(snd_gusclassic_cards[idx]);
|
---|
267 | }
|
---|
268 |
|
---|
269 | module_init(alsa_card_gusclassic_init)
|
---|
270 | module_exit(alsa_card_gusclassic_exit)
|
---|
271 |
|
---|
272 | #ifndef MODULE
|
---|
273 |
|
---|
274 | /* format is: snd-card-gusclassic=snd_enable,snd_index,snd_id,
|
---|
275 | snd_port,snd_irq,
|
---|
276 | snd_dma1,snd_dma2,
|
---|
277 | snd_joystick_dac,
|
---|
278 | snd_channels,snd_pcm_channels */
|
---|
279 |
|
---|
280 | static int __init alsa_card_gusclassic_setup(char *str)
|
---|
281 | {
|
---|
282 | static unsigned __initdata nr_dev = 0;
|
---|
283 |
|
---|
284 | if (nr_dev >= SNDRV_CARDS)
|
---|
285 | return 0;
|
---|
286 | (void)(get_option(&str,&snd_enable[nr_dev]) == 2 &&
|
---|
287 | get_option(&str,&snd_index[nr_dev]) == 2 &&
|
---|
288 | get_id(&str,&snd_id[nr_dev]) == 2 &&
|
---|
289 | get_option(&str,(int *)&snd_port[nr_dev]) == 2 &&
|
---|
290 | get_option(&str,&snd_irq[nr_dev]) == 2 &&
|
---|
291 | get_option(&str,&snd_dma1[nr_dev]) == 2 &&
|
---|
292 | get_option(&str,&snd_dma2[nr_dev]) == 2 &&
|
---|
293 | get_option(&str,&snd_joystick_dac[nr_dev]) == 2 &&
|
---|
294 | get_option(&str,&snd_channels[nr_dev]) == 2 &&
|
---|
295 | get_option(&str,&snd_pcm_channels[nr_dev]) == 2);
|
---|
296 | nr_dev++;
|
---|
297 | return 1;
|
---|
298 | }
|
---|
299 |
|
---|
300 | __setup("snd-card-gusclassic=", alsa_card_gusclassic_setup);
|
---|
301 |
|
---|
302 | #endif /* ifndef MODULE */
|
---|