25 #include <linux/slab.h>
27 #include <linux/module.h>
38 static int snd_gus_init_dma_irq(
struct snd_gus_card * gus,
int latches);
42 if (!try_module_get(gus->
card->module))
49 module_put(gus->
card->module);
76 nval = ucontrol->
value.integer.value[0] & 31;
81 spin_unlock_irqrestore(&gus->
reg_lock, flags);
87 .name =
"Joystick Speed",
88 .info = snd_gus_joystick_info,
89 .get = snd_gus_joystick_get,
90 .put = snd_gus_joystick_put
93 static void snd_gus_init_control(
struct snd_gus_card *gus)
105 if (gus->
gf1.res_port2 ==
NULL)
108 snd_gus_init_dma_irq(gus, 0);
112 if (gus->
gf1.irq >= 0)
114 if (gus->
gf1.dma1 >= 0) {
129 return snd_gus_free(gus);
134 int irq,
int dma1,
int dma2,
165 gus->
gf1.reg_page =
GUSP(gus, GF1PAGE);
166 gus->
gf1.reg_regsel =
GUSP(gus, GF1REGSEL);
167 gus->
gf1.reg_data8 =
GUSP(gus, GF1DATAHIGH);
168 gus->
gf1.reg_data16 =
GUSP(gus, GF1DATALOW);
171 gus->
gf1.reg_timerctrl =
GUSP(gus, TIMERCNTRL);
172 gus->
gf1.reg_timerdata =
GUSP(gus, TIMERDATA);
195 gus->
gf1.dma1 = dma1;
196 if (dma2 >= 0 && dma1 != dma2) {
202 gus->
gf1.dma2 = dma2;
204 gus->
gf1.dma2 = gus->
gf1.dma1;
212 if (pcm_channels < 0)
214 if (pcm_channels > 8)
218 gus->
gf1.effect = effect ? 1 : 0;
219 gus->
gf1.active_voices = voices;
220 gus->
gf1.pcm_channels = pcm_channels;
221 gus->
gf1.volume_ramp = 25;
222 gus->
gf1.smooth_pan = 1;
235 static int snd_gus_detect_memory(
struct snd_gus_card * gus)
246 for (idx = 1, d = 0xab; idx < 4; idx++, d++) {
256 gus->
gf1.memory = idx << 18;
258 gus->
gf1.memory = 256 * 1024;
260 for (l = 0, local = gus->
gf1.memory; l < 4; l++, local -= 256 * 1024) {
261 gus->
gf1.mem_alloc.banks_8[
l].address =
262 gus->
gf1.mem_alloc.banks_8[
l].size = 0;
263 gus->
gf1.mem_alloc.banks_16[
l].address = l << 18;
264 gus->
gf1.mem_alloc.banks_16[
l].size = local > 0 ? 256 * 1024 : 0;
266 gus->
gf1.mem_alloc.banks_8[0].size = gus->
gf1.memory;
270 static int snd_gus_init_dma_irq(
struct snd_gus_card * gus,
int latches)
275 static unsigned char irqs[16] =
276 {0, 0, 1, 3, 0, 2, 0, 4, 0, 1, 0, 5, 6, 0, 0, 7};
277 static unsigned char dmas[8] =
278 {6, 1, 0, 2, 0, 3, 4, 5};
292 dma1 = gus->
gf1.dma1;
294 dma1 = dmas[dma1 & 7];
295 dma2 = gus->
gf1.dma2;
297 dma2 = dmas[dma2 & 7];
298 dma1 |= gus->
equal_dma ? 0x40 : (dma2 << 3);
300 if ((dma1 & 7) == 0 || (dma2 & 7) == 0) {
306 irq = irqs[irq & 0x0f];
313 card->mixer.mix_ctrl_reg |= 0x10;
319 outb(0x00,
GUSP(gus, IRQDMACNTRLREG));
321 spin_unlock_irqrestore(&gus->
reg_lock, flags);
327 outb(dma1,
GUSP(gus, IRQDMACNTRLREG));
330 outb(irq,
GUSP(gus, IRQDMACNTRLREG));
332 spin_unlock_irqrestore(&gus->
reg_lock, flags);
338 outb(dma1,
GUSP(gus, IRQDMACNTRLREG));
341 outb(irq,
GUSP(gus, IRQDMACNTRLREG));
343 spin_unlock_irqrestore(&gus->
reg_lock, flags);
354 spin_unlock_irqrestore(&gus->
reg_lock, flags);
359 static int snd_gus_check_version(
struct snd_gus_card * gus)
368 val =
inb(
GUSP(gus, REGCNTRLS));
369 rev =
inb(
GUSP(gus, BOARDVERSION));
370 spin_unlock_irqrestore(&gus->
reg_lock, flags);
371 snd_printdd(
"GF1 [0x%lx] init - val = 0x%x, rev = 0x%x\n", gus->
gf1.port, val, rev);
374 if ((val != 255 && (val & 0x06)) || (rev >= 5 && rev != 255)) {
375 if (rev >= 5 && rev <= 9) {
380 card->
longname[29] = rev == 5 ?
'5' :
'7';
382 if (rev >= 10 && rev != 255) {
383 if (rev >= 10 && rev <= 11) {
387 }
else if (rev == 0x30) {
391 }
else if (rev == 0x50) {
396 snd_printk(
KERN_ERR "unknown GF1 revision number at 0x%lx - 0x%x (0x%x)\n", gus->
gf1.port, rev, val);
403 snd_gus_init_control(gus);
412 if ((err = snd_gus_check_version(gus)) < 0) {
416 if ((err = snd_gus_detect_memory(gus)) < 0)
419 if ((err = snd_gus_init_dma_irq(gus, 1)) < 0)
473 static int __init alsa_gus_init(
void)
478 static void __exit alsa_gus_exit(
void)