]>
Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 LT |
2 | /* |
3 | * Driver for Gravis UltraSound Extreme soundcards | |
c1017a4c | 4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
1da177e4 LT |
5 | */ |
6 | ||
1da177e4 | 7 | #include <linux/init.h> |
654aa661 | 8 | #include <linux/err.h> |
b44dfe1a | 9 | #include <linux/isa.h> |
1da177e4 LT |
10 | #include <linux/delay.h> |
11 | #include <linux/time.h> | |
65a77217 | 12 | #include <linux/module.h> |
654aa661 | 13 | #include <asm/dma.h> |
1da177e4 LT |
14 | #include <sound/core.h> |
15 | #include <sound/gus.h> | |
16 | #include <sound/es1688.h> | |
17 | #include <sound/mpu401.h> | |
18 | #include <sound/opl3.h> | |
19 | #define SNDRV_LEGACY_AUTO_PROBE | |
20 | #define SNDRV_LEGACY_FIND_FREE_IRQ | |
21 | #define SNDRV_LEGACY_FIND_FREE_DMA | |
22 | #include <sound/initval.h> | |
23 | ||
b44dfe1a RH |
24 | #define CRD_NAME "Gravis UltraSound Extreme" |
25 | #define DEV_NAME "gusextreme" | |
26 | ||
27 | MODULE_DESCRIPTION(CRD_NAME); | |
c1017a4c | 28 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
1da177e4 LT |
29 | MODULE_LICENSE("GPL"); |
30 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Extreme}}"); | |
31 | ||
32 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | |
33 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ | |
a67ff6a5 | 34 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
1da177e4 LT |
35 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ |
36 | static long gf1_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x210,0x220,0x230,0x240,0x250,0x260,0x270 */ | |
37 | static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x300,0x310,0x320 */ | |
38 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ | |
39 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ | |
40 | static int gf1_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */ | |
41 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ | |
42 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; | |
43 | static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; | |
44 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ | |
45 | static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24}; | |
46 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; | |
47 | ||
48 | module_param_array(index, int, NULL, 0444); | |
b44dfe1a | 49 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
1da177e4 | 50 | module_param_array(id, charp, NULL, 0444); |
b44dfe1a | 51 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
1da177e4 | 52 | module_param_array(enable, bool, NULL, 0444); |
b44dfe1a | 53 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
e992ef57 | 54 | module_param_hw_array(port, long, ioport, NULL, 0444); |
b44dfe1a | 55 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
e992ef57 | 56 | module_param_hw_array(gf1_port, long, ioport, NULL, 0444); |
b44dfe1a | 57 | MODULE_PARM_DESC(gf1_port, "GF1 port # for " CRD_NAME " driver (optional)."); |
e992ef57 | 58 | module_param_hw_array(mpu_port, long, ioport, NULL, 0444); |
b44dfe1a | 59 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver."); |
e992ef57 | 60 | module_param_hw_array(irq, int, irq, NULL, 0444); |
b44dfe1a | 61 | MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); |
e992ef57 | 62 | module_param_hw_array(mpu_irq, int, irq, NULL, 0444); |
b44dfe1a | 63 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver."); |
e992ef57 | 64 | module_param_hw_array(gf1_irq, int, irq, NULL, 0444); |
b44dfe1a | 65 | MODULE_PARM_DESC(gf1_irq, "GF1 IRQ # for " CRD_NAME " driver."); |
e992ef57 | 66 | module_param_hw_array(dma8, int, dma, NULL, 0444); |
b44dfe1a | 67 | MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver."); |
e992ef57 | 68 | module_param_hw_array(dma1, int, dma, NULL, 0444); |
b44dfe1a | 69 | MODULE_PARM_DESC(dma1, "GF1 DMA # for " CRD_NAME " driver."); |
1da177e4 | 70 | module_param_array(joystick_dac, int, NULL, 0444); |
b44dfe1a | 71 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver."); |
1da177e4 | 72 | module_param_array(channels, int, NULL, 0444); |
b44dfe1a | 73 | MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver."); |
1da177e4 | 74 | module_param_array(pcm_channels, int, NULL, 0444); |
b44dfe1a RH |
75 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver."); |
76 | ||
1bff292e | 77 | static int snd_gusextreme_match(struct device *dev, unsigned int n) |
b44dfe1a RH |
78 | { |
79 | return enable[n]; | |
80 | } | |
81 | ||
1bff292e BP |
82 | static int snd_gusextreme_es1688_create(struct snd_card *card, |
83 | struct snd_es1688 *chip, | |
84 | struct device *dev, unsigned int n) | |
b44dfe1a RH |
85 | { |
86 | static long possible_ports[] = {0x220, 0x240, 0x260}; | |
87 | static int possible_irqs[] = {5, 9, 10, 7, -1}; | |
88 | static int possible_dmas[] = {1, 3, 0, -1}; | |
89 | ||
90 | int i, error; | |
91 | ||
92 | if (irq[n] == SNDRV_AUTO_IRQ) { | |
93 | irq[n] = snd_legacy_find_free_irq(possible_irqs); | |
94 | if (irq[n] < 0) { | |
0418ff0c | 95 | dev_err(dev, "unable to find a free IRQ for ES1688\n"); |
b44dfe1a RH |
96 | return -EBUSY; |
97 | } | |
98 | } | |
99 | if (dma8[n] == SNDRV_AUTO_DMA) { | |
100 | dma8[n] = snd_legacy_find_free_dma(possible_dmas); | |
101 | if (dma8[n] < 0) { | |
0418ff0c | 102 | dev_err(dev, "unable to find a free DMA for ES1688\n"); |
b44dfe1a RH |
103 | return -EBUSY; |
104 | } | |
105 | } | |
1da177e4 | 106 | |
b44dfe1a | 107 | if (port[n] != SNDRV_AUTO_PORT) |
396fa827 KH |
108 | return snd_es1688_create(card, chip, port[n], mpu_port[n], |
109 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688); | |
f7a9275d | 110 | |
b44dfe1a RH |
111 | i = 0; |
112 | do { | |
113 | port[n] = possible_ports[i]; | |
396fa827 KH |
114 | error = snd_es1688_create(card, chip, port[n], mpu_port[n], |
115 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688); | |
b44dfe1a | 116 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); |
1da177e4 | 117 | |
b44dfe1a RH |
118 | return error; |
119 | } | |
1da177e4 | 120 | |
1bff292e BP |
121 | static int snd_gusextreme_gus_card_create(struct snd_card *card, |
122 | struct device *dev, unsigned int n, | |
123 | struct snd_gus_card **rgus) | |
b44dfe1a RH |
124 | { |
125 | static int possible_irqs[] = {11, 12, 15, 9, 5, 7, 3, -1}; | |
126 | static int possible_dmas[] = {5, 6, 7, 3, 1, -1}; | |
127 | ||
128 | if (gf1_irq[n] == SNDRV_AUTO_IRQ) { | |
129 | gf1_irq[n] = snd_legacy_find_free_irq(possible_irqs); | |
130 | if (gf1_irq[n] < 0) { | |
0418ff0c | 131 | dev_err(dev, "unable to find a free IRQ for GF1\n"); |
b44dfe1a RH |
132 | return -EBUSY; |
133 | } | |
134 | } | |
135 | if (dma1[n] == SNDRV_AUTO_DMA) { | |
136 | dma1[n] = snd_legacy_find_free_dma(possible_dmas); | |
137 | if (dma1[n] < 0) { | |
0418ff0c | 138 | dev_err(dev, "unable to find a free DMA for GF1\n"); |
b44dfe1a RH |
139 | return -EBUSY; |
140 | } | |
141 | } | |
142 | return snd_gus_create(card, gf1_port[n], gf1_irq[n], dma1[n], -1, | |
143 | 0, channels[n], pcm_channels[n], 0, rgus); | |
144 | } | |
145 | ||
1bff292e BP |
146 | static int snd_gusextreme_detect(struct snd_gus_card *gus, |
147 | struct snd_es1688 *es1688) | |
1da177e4 LT |
148 | { |
149 | unsigned long flags; | |
43bcd973 | 150 | unsigned char d; |
1da177e4 LT |
151 | |
152 | /* | |
153 | * This is main stuff - enable access to GF1 chip... | |
154 | * I'm not sure, if this will work for card which have | |
155 | * ES1688 chip in another place than 0x220. | |
156 | * | |
157 | * I used reverse-engineering in DOSEMU. [--jk] | |
158 | * | |
159 | * ULTRINIT.EXE: | |
160 | * 0x230 = 0,2,3 | |
161 | * 0x240 = 2,0,1 | |
162 | * 0x250 = 2,0,3 | |
163 | * 0x260 = 2,2,1 | |
164 | */ | |
165 | ||
166 | spin_lock_irqsave(&es1688->mixer_lock, flags); | |
167 | snd_es1688_mixer_write(es1688, 0x40, 0x0b); /* don't change!!! */ | |
168 | spin_unlock_irqrestore(&es1688->mixer_lock, flags); | |
b44dfe1a | 169 | |
1da177e4 | 170 | spin_lock_irqsave(&es1688->reg_lock, flags); |
b44dfe1a | 171 | outb(gus->gf1.port & 0x040 ? 2 : 0, ES1688P(es1688, INIT1)); |
1da177e4 | 172 | outb(0, 0x201); |
b44dfe1a | 173 | outb(gus->gf1.port & 0x020 ? 2 : 0, ES1688P(es1688, INIT1)); |
1da177e4 | 174 | outb(0, 0x201); |
b44dfe1a | 175 | outb(gus->gf1.port & 0x010 ? 3 : 1, ES1688P(es1688, INIT1)); |
1da177e4 LT |
176 | spin_unlock_irqrestore(&es1688->reg_lock, flags); |
177 | ||
178 | udelay(100); | |
179 | ||
180 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */ | |
43bcd973 TI |
181 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) { |
182 | snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d); | |
1da177e4 | 183 | return -EIO; |
43bcd973 | 184 | } |
1da177e4 LT |
185 | udelay(160); |
186 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */ | |
187 | udelay(160); | |
43bcd973 TI |
188 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) { |
189 | snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d); | |
1da177e4 | 190 | return -EIO; |
43bcd973 | 191 | } |
1da177e4 | 192 | |
b44dfe1a | 193 | return 0; |
1da177e4 LT |
194 | } |
195 | ||
1bff292e | 196 | static int snd_gusextreme_mixer(struct snd_card *card) |
1da177e4 | 197 | { |
5e2da206 | 198 | struct snd_ctl_elem_id id1, id2; |
b44dfe1a | 199 | int error; |
1da177e4 LT |
200 | |
201 | memset(&id1, 0, sizeof(id1)); | |
202 | memset(&id2, 0, sizeof(id2)); | |
203 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
b44dfe1a | 204 | |
1da177e4 LT |
205 | /* reassign AUX to SYNTHESIZER */ |
206 | strcpy(id1.name, "Aux Playback Volume"); | |
207 | strcpy(id2.name, "Synth Playback Volume"); | |
b44dfe1a RH |
208 | error = snd_ctl_rename_id(card, &id1, &id2); |
209 | if (error < 0) | |
210 | return error; | |
211 | ||
1da177e4 LT |
212 | /* reassign Master Playback Switch to Synth Playback Switch */ |
213 | strcpy(id1.name, "Master Playback Switch"); | |
214 | strcpy(id2.name, "Synth Playback Switch"); | |
b44dfe1a RH |
215 | error = snd_ctl_rename_id(card, &id1, &id2); |
216 | if (error < 0) | |
217 | return error; | |
218 | ||
1da177e4 LT |
219 | return 0; |
220 | } | |
221 | ||
1bff292e | 222 | static int snd_gusextreme_probe(struct device *dev, unsigned int n) |
1da177e4 | 223 | { |
5e2da206 | 224 | struct snd_card *card; |
5e2da206 TI |
225 | struct snd_gus_card *gus; |
226 | struct snd_es1688 *es1688; | |
227 | struct snd_opl3 *opl3; | |
b44dfe1a | 228 | int error; |
1da177e4 | 229 | |
4323cc4d TI |
230 | error = snd_card_new(dev, index[n], id[n], THIS_MODULE, |
231 | sizeof(struct snd_es1688), &card); | |
c95eadd2 TI |
232 | if (error < 0) |
233 | return error; | |
1da177e4 | 234 | |
396fa827 KH |
235 | es1688 = card->private_data; |
236 | ||
b44dfe1a RH |
237 | if (mpu_port[n] == SNDRV_AUTO_PORT) |
238 | mpu_port[n] = 0; | |
1da177e4 | 239 | |
b44dfe1a RH |
240 | if (mpu_irq[n] > 15) |
241 | mpu_irq[n] = -1; | |
242 | ||
396fa827 | 243 | error = snd_gusextreme_es1688_create(card, es1688, dev, n); |
b44dfe1a | 244 | if (error < 0) |
1da177e4 | 245 | goto out; |
654aa661 | 246 | |
b44dfe1a RH |
247 | if (gf1_port[n] < 0) |
248 | gf1_port[n] = es1688->port + 0x20; | |
249 | ||
250 | error = snd_gusextreme_gus_card_create(card, dev, n, &gus); | |
251 | if (error < 0) | |
1da177e4 LT |
252 | goto out; |
253 | ||
b44dfe1a RH |
254 | error = snd_gusextreme_detect(gus, es1688); |
255 | if (error < 0) | |
1da177e4 LT |
256 | goto out; |
257 | ||
b44dfe1a RH |
258 | gus->joystick_dac = joystick_dac[n]; |
259 | ||
260 | error = snd_gus_initialize(gus); | |
261 | if (error < 0) | |
1da177e4 LT |
262 | goto out; |
263 | ||
b44dfe1a | 264 | error = -ENODEV; |
1da177e4 | 265 | if (!gus->ess_flag) { |
0418ff0c TI |
266 | dev_err(dev, "GUS Extreme soundcard was not " |
267 | "detected at 0x%lx\n", gus->gf1.port); | |
1da177e4 LT |
268 | goto out; |
269 | } | |
442f4f36 | 270 | gus->codec_flag = 1; |
b44dfe1a | 271 | |
4b8ab885 | 272 | error = snd_es1688_pcm(card, es1688, 0); |
b44dfe1a | 273 | if (error < 0) |
1da177e4 LT |
274 | goto out; |
275 | ||
396fa827 | 276 | error = snd_es1688_mixer(card, es1688); |
b44dfe1a | 277 | if (error < 0) |
1da177e4 LT |
278 | goto out; |
279 | ||
280 | snd_component_add(card, "ES1688"); | |
b44dfe1a RH |
281 | |
282 | if (pcm_channels[n] > 0) { | |
db5abb3c | 283 | error = snd_gf1_pcm_new(gus, 1, 1); |
b44dfe1a | 284 | if (error < 0) |
1da177e4 LT |
285 | goto out; |
286 | } | |
b44dfe1a RH |
287 | |
288 | error = snd_gf1_new_mixer(gus); | |
289 | if (error < 0) | |
1da177e4 LT |
290 | goto out; |
291 | ||
396fa827 | 292 | error = snd_gusextreme_mixer(card); |
b44dfe1a | 293 | if (error < 0) |
1da177e4 LT |
294 | goto out; |
295 | ||
296 | if (snd_opl3_create(card, es1688->port, es1688->port + 2, | |
b44dfe1a | 297 | OPL3_HW_OPL3, 0, &opl3) < 0) |
0418ff0c | 298 | dev_warn(dev, "opl3 not detected at 0x%lx\n", es1688->port); |
b44dfe1a RH |
299 | else { |
300 | error = snd_opl3_hwdep_new(opl3, 0, 2, NULL); | |
301 | if (error < 0) | |
1da177e4 LT |
302 | goto out; |
303 | } | |
304 | ||
b44dfe1a RH |
305 | if (es1688->mpu_port >= 0x300) { |
306 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, | |
dba8b469 | 307 | es1688->mpu_port, 0, mpu_irq[n], NULL); |
b44dfe1a RH |
308 | if (error < 0) |
309 | goto out; | |
310 | } | |
1da177e4 | 311 | |
b44dfe1a RH |
312 | sprintf(card->longname, "Gravis UltraSound Extreme at 0x%lx, " |
313 | "irq %i&%i, dma %i&%i", es1688->port, | |
314 | gus->gf1.irq, es1688->irq, gus->gf1.dma1, es1688->dma8); | |
43bcd973 | 315 | |
b44dfe1a RH |
316 | error = snd_card_register(card); |
317 | if (error < 0) | |
1da177e4 LT |
318 | goto out; |
319 | ||
b44dfe1a | 320 | dev_set_drvdata(dev, card); |
1da177e4 LT |
321 | return 0; |
322 | ||
b44dfe1a RH |
323 | out: snd_card_free(card); |
324 | return error; | |
1da177e4 LT |
325 | } |
326 | ||
1bff292e | 327 | static int snd_gusextreme_remove(struct device *dev, unsigned int n) |
1da177e4 | 328 | { |
b44dfe1a | 329 | snd_card_free(dev_get_drvdata(dev)); |
654aa661 | 330 | return 0; |
1da177e4 LT |
331 | } |
332 | ||
b44dfe1a RH |
333 | static struct isa_driver snd_gusextreme_driver = { |
334 | .match = snd_gusextreme_match, | |
654aa661 | 335 | .probe = snd_gusextreme_probe, |
1bff292e | 336 | .remove = snd_gusextreme_remove, |
b44dfe1a RH |
337 | #if 0 /* FIXME */ |
338 | .suspend = snd_gusextreme_suspend, | |
339 | .resume = snd_gusextreme_resume, | |
340 | #endif | |
654aa661 | 341 | .driver = { |
b44dfe1a RH |
342 | .name = DEV_NAME |
343 | } | |
654aa661 TI |
344 | }; |
345 | ||
bfc7e0ff | 346 | module_isa_driver(snd_gusextreme_driver, SNDRV_CARDS); |