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