| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  Routines for Gravis UltraSound soundcards | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 |  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> | 
 | 23 | #include <linux/interrupt.h> | 
 | 24 | #include <linux/delay.h> | 
 | 25 | #include <linux/slab.h> | 
 | 26 | #include <linux/ioport.h> | 
 | 27 | #include <sound/core.h> | 
 | 28 | #include <sound/gus.h> | 
 | 29 | #include <sound/control.h> | 
 | 30 |  | 
 | 31 | #include <asm/dma.h> | 
 | 32 |  | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 33 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | MODULE_DESCRIPTION("Routines for Gravis UltraSound soundcards"); | 
 | 35 | MODULE_LICENSE("GPL"); | 
 | 36 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 37 | static int snd_gus_init_dma_irq(struct snd_gus_card * gus, int latches); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 39 | int snd_gus_use_inc(struct snd_gus_card * gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { | 
 | 41 | 	if (!try_module_get(gus->card->module)) | 
 | 42 | 		return 0; | 
 | 43 | 	return 1; | 
 | 44 | } | 
 | 45 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 46 | void snd_gus_use_dec(struct snd_gus_card * gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { | 
 | 48 | 	module_put(gus->card->module); | 
 | 49 | } | 
 | 50 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 51 | static int snd_gus_joystick_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { | 
 | 53 | 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | 
 | 54 | 	uinfo->count = 1; | 
 | 55 | 	uinfo->value.integer.min = 0; | 
 | 56 | 	uinfo->value.integer.max = 31; | 
 | 57 | 	return 0; | 
 | 58 | } | 
 | 59 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 60 | static int snd_gus_joystick_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 62 | 	struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | 	 | 
 | 64 | 	ucontrol->value.integer.value[0] = gus->joystick_dac & 31; | 
 | 65 | 	return 0; | 
 | 66 | } | 
 | 67 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 68 | static int snd_gus_joystick_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 70 | 	struct snd_gus_card *gus = snd_kcontrol_chip(kcontrol); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | 	unsigned long flags; | 
 | 72 | 	int change; | 
 | 73 | 	unsigned char nval; | 
 | 74 | 	 | 
 | 75 | 	nval = ucontrol->value.integer.value[0] & 31; | 
 | 76 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 77 | 	change = gus->joystick_dac != nval; | 
 | 78 | 	gus->joystick_dac = nval; | 
 | 79 | 	snd_gf1_write8(gus, SNDRV_GF1_GB_JOYSTICK_DAC_LEVEL, gus->joystick_dac); | 
 | 80 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 81 | 	return change; | 
 | 82 | } | 
 | 83 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 84 | static struct snd_kcontrol_new snd_gus_joystick_control = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | 	.iface = SNDRV_CTL_ELEM_IFACE_CARD, | 
 | 86 | 	.name = "Joystick Speed", | 
 | 87 | 	.info = snd_gus_joystick_info, | 
 | 88 | 	.get = snd_gus_joystick_get, | 
 | 89 | 	.put = snd_gus_joystick_put | 
 | 90 | }; | 
 | 91 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 92 | static void snd_gus_init_control(struct snd_gus_card *gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { | 
 | 94 | 	if (!gus->ace_flag) | 
 | 95 | 		snd_ctl_add(gus->card, snd_ctl_new1(&snd_gus_joystick_control, gus)); | 
 | 96 | } | 
 | 97 |  | 
 | 98 | /* | 
 | 99 |  * | 
 | 100 |  */ | 
 | 101 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 102 | static int snd_gus_free(struct snd_gus_card *gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { | 
 | 104 | 	if (gus->gf1.res_port2 == NULL) | 
 | 105 | 		goto __hw_end; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | 	snd_gf1_stop(gus); | 
 | 107 | 	snd_gus_init_dma_irq(gus, 0); | 
 | 108 |       __hw_end: | 
| Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 109 | 	release_and_free_resource(gus->gf1.res_port1); | 
 | 110 | 	release_and_free_resource(gus->gf1.res_port2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | 	if (gus->gf1.irq >= 0) | 
 | 112 | 		free_irq(gus->gf1.irq, (void *) gus); | 
 | 113 | 	if (gus->gf1.dma1 >= 0) { | 
 | 114 | 		disable_dma(gus->gf1.dma1); | 
 | 115 | 		free_dma(gus->gf1.dma1); | 
 | 116 | 	} | 
 | 117 | 	if (!gus->equal_dma && gus->gf1.dma2 >= 0) { | 
 | 118 | 		disable_dma(gus->gf1.dma2); | 
 | 119 | 		free_dma(gus->gf1.dma2); | 
 | 120 | 	} | 
 | 121 | 	kfree(gus); | 
 | 122 | 	return 0; | 
 | 123 | } | 
 | 124 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 125 | static int snd_gus_dev_free(struct snd_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 127 | 	struct snd_gus_card *gus = device->device_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | 	return snd_gus_free(gus); | 
 | 129 | } | 
 | 130 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 131 | int snd_gus_create(struct snd_card *card, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | 		   unsigned long port, | 
 | 133 | 		   int irq, int dma1, int dma2, | 
 | 134 | 		   int timer_dev, | 
 | 135 | 		   int voices, | 
 | 136 | 		   int pcm_channels, | 
 | 137 | 		   int effect, | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 138 | 		   struct snd_gus_card **rgus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 140 | 	struct snd_gus_card *gus; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | 	int err; | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 142 | 	static struct snd_device_ops ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | 		.dev_free =	snd_gus_dev_free, | 
 | 144 | 	}; | 
 | 145 |  | 
 | 146 | 	*rgus = NULL; | 
| Takashi Iwai | 9e76a76 | 2005-09-09 14:21:17 +0200 | [diff] [blame] | 147 | 	gus = kzalloc(sizeof(*gus), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | 	if (gus == NULL) | 
 | 149 | 		return -ENOMEM; | 
| Ingo Molnar | c2cbdbb | 2007-10-16 14:42:30 +0200 | [diff] [blame] | 150 | 	spin_lock_init(&gus->reg_lock); | 
 | 151 | 	spin_lock_init(&gus->voice_alloc); | 
 | 152 | 	spin_lock_init(&gus->active_voice_lock); | 
 | 153 | 	spin_lock_init(&gus->event_lock); | 
 | 154 | 	spin_lock_init(&gus->dma_lock); | 
 | 155 | 	spin_lock_init(&gus->pcm_volume_level_lock); | 
 | 156 | 	spin_lock_init(&gus->uart_cmd_lock); | 
 | 157 | 	mutex_init(&gus->dma_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | 	gus->gf1.irq = -1; | 
 | 159 | 	gus->gf1.dma1 = -1; | 
 | 160 | 	gus->gf1.dma2 = -1; | 
 | 161 | 	gus->card = card; | 
 | 162 | 	gus->gf1.port = port; | 
 | 163 | 	/* fill register variables for speedup */ | 
 | 164 | 	gus->gf1.reg_page = GUSP(gus, GF1PAGE); | 
 | 165 | 	gus->gf1.reg_regsel = GUSP(gus, GF1REGSEL); | 
 | 166 | 	gus->gf1.reg_data8 = GUSP(gus, GF1DATAHIGH); | 
 | 167 | 	gus->gf1.reg_data16 = GUSP(gus, GF1DATALOW); | 
 | 168 | 	gus->gf1.reg_irqstat = GUSP(gus, IRQSTAT); | 
 | 169 | 	gus->gf1.reg_dram = GUSP(gus, DRAM); | 
 | 170 | 	gus->gf1.reg_timerctrl = GUSP(gus, TIMERCNTRL); | 
 | 171 | 	gus->gf1.reg_timerdata = GUSP(gus, TIMERDATA); | 
 | 172 | 	/* allocate resources */ | 
 | 173 | 	if ((gus->gf1.res_port1 = request_region(port, 16, "GUS GF1 (Adlib/SB)")) == NULL) { | 
 | 174 | 		snd_printk(KERN_ERR "gus: can't grab SB port 0x%lx\n", port); | 
 | 175 | 		snd_gus_free(gus); | 
 | 176 | 		return -EBUSY; | 
 | 177 | 	} | 
 | 178 | 	if ((gus->gf1.res_port2 = request_region(port + 0x100, 12, "GUS GF1 (Synth)")) == NULL) { | 
 | 179 | 		snd_printk(KERN_ERR "gus: can't grab synth port 0x%lx\n", port + 0x100); | 
 | 180 | 		snd_gus_free(gus); | 
 | 181 | 		return -EBUSY; | 
 | 182 | 	} | 
| Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 183 | 	if (irq >= 0 && request_irq(irq, snd_gus_interrupt, IRQF_DISABLED, "GUS GF1", (void *) gus)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | 		snd_printk(KERN_ERR "gus: can't grab irq %d\n", irq); | 
 | 185 | 		snd_gus_free(gus); | 
 | 186 | 		return -EBUSY; | 
 | 187 | 	} | 
 | 188 | 	gus->gf1.irq = irq; | 
 | 189 | 	if (request_dma(dma1, "GUS - 1")) { | 
 | 190 | 		snd_printk(KERN_ERR "gus: can't grab DMA1 %d\n", dma1); | 
 | 191 | 		snd_gus_free(gus); | 
 | 192 | 		return -EBUSY; | 
 | 193 | 	} | 
 | 194 | 	gus->gf1.dma1 = dma1; | 
 | 195 | 	if (dma2 >= 0 && dma1 != dma2) { | 
 | 196 | 		if (request_dma(dma2, "GUS - 2")) { | 
 | 197 | 			snd_printk(KERN_ERR "gus: can't grab DMA2 %d\n", dma2); | 
 | 198 | 			snd_gus_free(gus); | 
 | 199 | 			return -EBUSY; | 
 | 200 | 		} | 
 | 201 | 		gus->gf1.dma2 = dma2; | 
 | 202 | 	} else { | 
 | 203 | 		gus->gf1.dma2 = gus->gf1.dma1; | 
 | 204 | 		gus->equal_dma = 1; | 
 | 205 | 	} | 
 | 206 | 	gus->timer_dev = timer_dev; | 
 | 207 | 	if (voices < 14) | 
 | 208 | 		voices = 14; | 
 | 209 | 	if (voices > 32) | 
 | 210 | 		voices = 32; | 
 | 211 | 	if (pcm_channels < 0) | 
 | 212 | 		pcm_channels = 0; | 
 | 213 | 	if (pcm_channels > 8) | 
 | 214 | 		pcm_channels = 8; | 
 | 215 | 	pcm_channels++; | 
 | 216 | 	pcm_channels &= ~1; | 
 | 217 | 	gus->gf1.effect = effect ? 1 : 0; | 
 | 218 | 	gus->gf1.active_voices = voices; | 
 | 219 | 	gus->gf1.pcm_channels = pcm_channels; | 
 | 220 | 	gus->gf1.volume_ramp = 25; | 
 | 221 | 	gus->gf1.smooth_pan = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | 	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, gus, &ops)) < 0) { | 
 | 223 | 		snd_gus_free(gus); | 
 | 224 | 		return err; | 
 | 225 | 	} | 
 | 226 | 	*rgus = gus; | 
 | 227 | 	return 0; | 
 | 228 | } | 
 | 229 |  | 
 | 230 | /* | 
 | 231 |  *  Memory detection routine for plain GF1 soundcards | 
 | 232 |  */ | 
 | 233 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 234 | static int snd_gus_detect_memory(struct snd_gus_card * gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { | 
 | 236 | 	int l, idx, local; | 
 | 237 | 	unsigned char d; | 
 | 238 |  | 
 | 239 | 	snd_gf1_poke(gus, 0L, 0xaa); | 
 | 240 | 	snd_gf1_poke(gus, 1L, 0x55); | 
 | 241 | 	if (snd_gf1_peek(gus, 0L) != 0xaa || snd_gf1_peek(gus, 1L) != 0x55) { | 
| Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 242 | 		snd_printk(KERN_ERR "plain GF1 card at 0x%lx without onboard DRAM?\n", gus->gf1.port); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | 		return -ENOMEM; | 
 | 244 | 	} | 
 | 245 | 	for (idx = 1, d = 0xab; idx < 4; idx++, d++) { | 
 | 246 | 		local = idx << 18; | 
 | 247 | 		snd_gf1_poke(gus, local, d); | 
 | 248 | 		snd_gf1_poke(gus, local + 1, d + 1); | 
 | 249 | 		if (snd_gf1_peek(gus, local) != d || | 
 | 250 | 		    snd_gf1_peek(gus, local + 1) != d + 1 || | 
 | 251 | 		    snd_gf1_peek(gus, 0L) != 0xaa) | 
 | 252 | 			break; | 
 | 253 | 	} | 
 | 254 | #if 1 | 
 | 255 | 	gus->gf1.memory = idx << 18; | 
 | 256 | #else | 
 | 257 | 	gus->gf1.memory = 256 * 1024; | 
 | 258 | #endif | 
 | 259 | 	for (l = 0, local = gus->gf1.memory; l < 4; l++, local -= 256 * 1024) { | 
 | 260 | 		gus->gf1.mem_alloc.banks_8[l].address = | 
 | 261 | 		    gus->gf1.mem_alloc.banks_8[l].size = 0; | 
 | 262 | 		gus->gf1.mem_alloc.banks_16[l].address = l << 18; | 
 | 263 | 		gus->gf1.mem_alloc.banks_16[l].size = local > 0 ? 256 * 1024 : 0; | 
 | 264 | 	} | 
 | 265 | 	gus->gf1.mem_alloc.banks_8[0].size = gus->gf1.memory; | 
 | 266 | 	return 0;		/* some memory were detected */ | 
 | 267 | } | 
 | 268 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 269 | static int snd_gus_init_dma_irq(struct snd_gus_card * gus, int latches) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 271 | 	struct snd_card *card; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 	unsigned long flags; | 
 | 273 | 	int irq, dma1, dma2; | 
 | 274 | 	static unsigned char irqs[16] = | 
 | 275 | 		{0, 0, 1, 3, 0, 2, 0, 4, 0, 1, 0, 5, 6, 0, 0, 7}; | 
 | 276 | 	static unsigned char dmas[8] = | 
 | 277 | 		{6, 1, 0, 2, 0, 3, 4, 5}; | 
 | 278 |  | 
 | 279 | 	snd_assert(gus != NULL, return -EINVAL); | 
 | 280 | 	card = gus->card; | 
 | 281 | 	snd_assert(card != NULL, return -EINVAL); | 
 | 282 |  | 
 | 283 | 	gus->mix_cntrl_reg &= 0xf8; | 
 | 284 | 	gus->mix_cntrl_reg |= 0x01;	/* disable MIC, LINE IN, enable LINE OUT */ | 
 | 285 | 	if (gus->codec_flag || gus->ess_flag) { | 
 | 286 | 		gus->mix_cntrl_reg &= ~1;	/* enable LINE IN */ | 
 | 287 | 		gus->mix_cntrl_reg |= 4;	/* enable MIC */ | 
 | 288 | 	} | 
 | 289 | 	dma1 = gus->gf1.dma1; | 
| Peter Eriksen | 377a4f7e | 2007-01-29 14:45:53 +0100 | [diff] [blame] | 290 | 	dma1 = abs(dma1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | 	dma1 = dmas[dma1 & 7]; | 
 | 292 | 	dma2 = gus->gf1.dma2; | 
| Peter Eriksen | 377a4f7e | 2007-01-29 14:45:53 +0100 | [diff] [blame] | 293 | 	dma2 = abs(dma2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | 	dma2 = dmas[dma2 & 7]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | 	dma1 |= gus->equal_dma ? 0x40 : (dma2 << 3); | 
 | 296 |  | 
 | 297 | 	if ((dma1 & 7) == 0 || (dma2 & 7) == 0) { | 
| Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 298 | 		snd_printk(KERN_ERR "Error! DMA isn't defined.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | 		return -EINVAL; | 
 | 300 | 	} | 
 | 301 | 	irq = gus->gf1.irq; | 
| Peter Eriksen | 377a4f7e | 2007-01-29 14:45:53 +0100 | [diff] [blame] | 302 | 	irq = abs(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | 	irq = irqs[irq & 0x0f]; | 
 | 304 | 	if (irq == 0) { | 
| Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 305 | 		snd_printk(KERN_ERR "Error! IRQ isn't defined.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | 		return -EINVAL; | 
 | 307 | 	} | 
 | 308 | 	irq |= 0x40; | 
 | 309 | #if 0 | 
 | 310 | 	card->mixer.mix_ctrl_reg |= 0x10; | 
 | 311 | #endif | 
 | 312 |  | 
 | 313 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 314 | 	outb(5, GUSP(gus, REGCNTRLS)); | 
 | 315 | 	outb(gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG)); | 
 | 316 | 	outb(0x00, GUSP(gus, IRQDMACNTRLREG)); | 
 | 317 | 	outb(0, GUSP(gus, REGCNTRLS)); | 
 | 318 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 319 |  | 
 | 320 | 	udelay(100); | 
 | 321 |  | 
 | 322 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 323 | 	outb(0x00 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG)); | 
 | 324 | 	outb(dma1, GUSP(gus, IRQDMACNTRLREG)); | 
 | 325 | 	if (latches) { | 
 | 326 | 		outb(0x40 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG)); | 
 | 327 | 		outb(irq, GUSP(gus, IRQDMACNTRLREG)); | 
 | 328 | 	} | 
 | 329 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 330 |  | 
 | 331 | 	udelay(100); | 
 | 332 |  | 
 | 333 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 334 | 	outb(0x00 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG)); | 
 | 335 | 	outb(dma1, GUSP(gus, IRQDMACNTRLREG)); | 
 | 336 | 	if (latches) { | 
 | 337 | 		outb(0x40 | gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG)); | 
 | 338 | 		outb(irq, GUSP(gus, IRQDMACNTRLREG)); | 
 | 339 | 	} | 
 | 340 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 341 |  | 
 | 342 | 	snd_gf1_delay(gus); | 
 | 343 |  | 
 | 344 | 	if (latches) | 
 | 345 | 		gus->mix_cntrl_reg |= 0x08;	/* enable latches */ | 
 | 346 | 	else | 
 | 347 | 		gus->mix_cntrl_reg &= ~0x08;	/* disable latches */ | 
 | 348 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 349 | 	outb(gus->mix_cntrl_reg, GUSP(gus, MIXCNTRLREG)); | 
 | 350 | 	outb(0, GUSP(gus, GF1PAGE)); | 
 | 351 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 352 |  | 
 | 353 | 	return 0; | 
 | 354 | } | 
 | 355 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 356 | static int snd_gus_check_version(struct snd_gus_card * gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { | 
 | 358 | 	unsigned long flags; | 
 | 359 | 	unsigned char val, rev; | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 360 | 	struct snd_card *card; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 |  | 
 | 362 | 	card = gus->card; | 
 | 363 | 	spin_lock_irqsave(&gus->reg_lock, flags); | 
 | 364 | 	outb(0x20, GUSP(gus, REGCNTRLS)); | 
 | 365 | 	val = inb(GUSP(gus, REGCNTRLS)); | 
 | 366 | 	rev = inb(GUSP(gus, BOARDVERSION)); | 
 | 367 | 	spin_unlock_irqrestore(&gus->reg_lock, flags); | 
 | 368 | 	snd_printdd("GF1 [0x%lx] init - val = 0x%x, rev = 0x%x\n", gus->gf1.port, val, rev); | 
 | 369 | 	strcpy(card->driver, "GUS"); | 
 | 370 | 	strcpy(card->longname, "Gravis UltraSound Classic (2.4)"); | 
 | 371 | 	if ((val != 255 && (val & 0x06)) || (rev >= 5 && rev != 255)) { | 
 | 372 | 		if (rev >= 5 && rev <= 9) { | 
 | 373 | 			gus->ics_flag = 1; | 
 | 374 | 			if (rev == 5) | 
 | 375 | 				gus->ics_flipped = 1; | 
 | 376 | 			card->longname[27] = '3'; | 
 | 377 | 			card->longname[29] = rev == 5 ? '5' : '7'; | 
 | 378 | 		} | 
 | 379 | 		if (rev >= 10 && rev != 255) { | 
 | 380 | 			if (rev >= 10 && rev <= 11) { | 
 | 381 | 				strcpy(card->driver, "GUS MAX"); | 
 | 382 | 				strcpy(card->longname, "Gravis UltraSound MAX"); | 
 | 383 | 				gus->max_flag = 1; | 
 | 384 | 			} else if (rev == 0x30) { | 
 | 385 | 				strcpy(card->driver, "GUS ACE"); | 
 | 386 | 				strcpy(card->longname, "Gravis UltraSound Ace"); | 
 | 387 | 				gus->ace_flag = 1; | 
 | 388 | 			} else if (rev == 0x50) { | 
 | 389 | 				strcpy(card->driver, "GUS Extreme"); | 
 | 390 | 				strcpy(card->longname, "Gravis UltraSound Extreme"); | 
 | 391 | 				gus->ess_flag = 1; | 
 | 392 | 			} else { | 
| Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 393 | 				snd_printk(KERN_ERR "unknown GF1 revision number at 0x%lx - 0x%x (0x%x)\n", gus->gf1.port, rev, val); | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 394 | 				snd_printk(KERN_ERR "  please - report to <perex@perex.cz>\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | 			} | 
 | 396 | 		} | 
 | 397 | 	} | 
 | 398 | 	strcpy(card->shortname, card->longname); | 
 | 399 | 	gus->uart_enable = 1;	/* standard GUSes doesn't have midi uart trouble */ | 
 | 400 | 	snd_gus_init_control(gus); | 
 | 401 | 	return 0; | 
 | 402 | } | 
 | 403 |  | 
| Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 404 | int snd_gus_initialize(struct snd_gus_card *gus) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { | 
 | 406 | 	int err; | 
 | 407 |  | 
 | 408 | 	if (!gus->interwave) { | 
 | 409 | 		if ((err = snd_gus_check_version(gus)) < 0) { | 
| Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 410 | 			snd_printk(KERN_ERR "version check failed\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | 			return err; | 
 | 412 | 		} | 
 | 413 | 		if ((err = snd_gus_detect_memory(gus)) < 0) | 
 | 414 | 			return err; | 
 | 415 | 	} | 
 | 416 | 	if ((err = snd_gus_init_dma_irq(gus, 1)) < 0) | 
 | 417 | 		return err; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | 	snd_gf1_start(gus); | 
 | 419 | 	gus->initialized = 1; | 
 | 420 | 	return 0; | 
 | 421 | } | 
 | 422 |  | 
 | 423 |   /* gus_io.c */ | 
 | 424 | EXPORT_SYMBOL(snd_gf1_delay); | 
 | 425 | EXPORT_SYMBOL(snd_gf1_write8); | 
 | 426 | EXPORT_SYMBOL(snd_gf1_look8); | 
 | 427 | EXPORT_SYMBOL(snd_gf1_write16); | 
 | 428 | EXPORT_SYMBOL(snd_gf1_look16); | 
 | 429 | EXPORT_SYMBOL(snd_gf1_i_write8); | 
 | 430 | EXPORT_SYMBOL(snd_gf1_i_look8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | EXPORT_SYMBOL(snd_gf1_i_look16); | 
 | 432 | EXPORT_SYMBOL(snd_gf1_dram_addr); | 
 | 433 | EXPORT_SYMBOL(snd_gf1_write_addr); | 
 | 434 | EXPORT_SYMBOL(snd_gf1_poke); | 
 | 435 | EXPORT_SYMBOL(snd_gf1_peek); | 
 | 436 |   /* gus_reset.c */ | 
 | 437 | EXPORT_SYMBOL(snd_gf1_alloc_voice); | 
 | 438 | EXPORT_SYMBOL(snd_gf1_free_voice); | 
 | 439 | EXPORT_SYMBOL(snd_gf1_ctrl_stop); | 
 | 440 | EXPORT_SYMBOL(snd_gf1_stop_voice); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 |   /* gus_mixer.c */ | 
 | 442 | EXPORT_SYMBOL(snd_gf1_new_mixer); | 
 | 443 |   /* gus_pcm.c */ | 
 | 444 | EXPORT_SYMBOL(snd_gf1_pcm_new); | 
 | 445 |   /* gus.c */ | 
 | 446 | EXPORT_SYMBOL(snd_gus_use_inc); | 
 | 447 | EXPORT_SYMBOL(snd_gus_use_dec); | 
 | 448 | EXPORT_SYMBOL(snd_gus_create); | 
 | 449 | EXPORT_SYMBOL(snd_gus_initialize); | 
 | 450 |   /* gus_irq.c */ | 
 | 451 | EXPORT_SYMBOL(snd_gus_interrupt); | 
 | 452 |   /* gus_uart.c */ | 
 | 453 | EXPORT_SYMBOL(snd_gf1_rawmidi_new); | 
 | 454 |   /* gus_dram.c */ | 
 | 455 | EXPORT_SYMBOL(snd_gus_dram_write); | 
 | 456 | EXPORT_SYMBOL(snd_gus_dram_read); | 
 | 457 |   /* gus_volume.c */ | 
 | 458 | EXPORT_SYMBOL(snd_gf1_lvol_to_gvol_raw); | 
 | 459 | EXPORT_SYMBOL(snd_gf1_translate_freq); | 
 | 460 |   /* gus_mem.c */ | 
 | 461 | EXPORT_SYMBOL(snd_gf1_mem_alloc); | 
 | 462 | EXPORT_SYMBOL(snd_gf1_mem_xfree); | 
 | 463 | EXPORT_SYMBOL(snd_gf1_mem_free); | 
 | 464 | EXPORT_SYMBOL(snd_gf1_mem_lock); | 
 | 465 |  | 
 | 466 | /* | 
 | 467 |  *  INIT part | 
 | 468 |  */ | 
 | 469 |  | 
 | 470 | static int __init alsa_gus_init(void) | 
 | 471 | { | 
 | 472 | 	return 0; | 
 | 473 | } | 
 | 474 |  | 
 | 475 | static void __exit alsa_gus_exit(void) | 
 | 476 | { | 
 | 477 | } | 
 | 478 |  | 
 | 479 | module_init(alsa_gus_init) | 
 | 480 | module_exit(alsa_gus_exit) |