[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / sound / isa / gus / gusclassic.c
bloba99fa5040b46c8b5d575b53cb889207fccdb335b
1 /*
2 * Driver for Gravis UltraSound Classic soundcard
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
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.
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.
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
22 #include <sound/driver.h>
23 #include <asm/dma.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/time.h>
27 #include <linux/moduleparam.h>
28 #include <sound/core.h>
29 #include <sound/gus.h>
30 #define SNDRV_LEGACY_AUTO_PROBE
31 #define SNDRV_LEGACY_FIND_FREE_IRQ
32 #define SNDRV_LEGACY_FIND_FREE_DMA
33 #include <sound/initval.h>
35 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
36 MODULE_DESCRIPTION("Gravis UltraSound Classic");
37 MODULE_LICENSE("GPL");
38 MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}");
40 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
41 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
42 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
43 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
44 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
45 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
46 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
47 static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
48 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
49 static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
50 static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
52 module_param_array(index, int, NULL, 0444);
53 MODULE_PARM_DESC(index, "Index value for GUS Classic soundcard.");
54 module_param_array(id, charp, NULL, 0444);
55 MODULE_PARM_DESC(id, "ID string for GUS Classic soundcard.");
56 module_param_array(enable, bool, NULL, 0444);
57 MODULE_PARM_DESC(enable, "Enable GUS Classic soundcard.");
58 module_param_array(port, long, NULL, 0444);
59 MODULE_PARM_DESC(port, "Port # for GUS Classic driver.");
60 module_param_array(irq, int, NULL, 0444);
61 MODULE_PARM_DESC(irq, "IRQ # for GUS Classic driver.");
62 module_param_array(dma1, int, NULL, 0444);
63 MODULE_PARM_DESC(dma1, "DMA1 # for GUS Classic driver.");
64 module_param_array(dma2, int, NULL, 0444);
65 MODULE_PARM_DESC(dma2, "DMA2 # for GUS Classic driver.");
66 module_param_array(joystick_dac, int, NULL, 0444);
67 MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS Classic driver.");
68 module_param_array(channels, int, NULL, 0444);
69 MODULE_PARM_DESC(channels, "GF1 channels for GUS Classic driver.");
70 module_param_array(pcm_channels, int, NULL, 0444);
71 MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS Classic driver.");
73 static snd_card_t *snd_gusclassic_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
76 static int __init snd_gusclassic_detect(snd_gus_card_t * gus)
78 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
79 #ifdef CONFIG_SND_DEBUG_DETECT
81 unsigned char d;
83 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
84 snd_printk("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
85 return -ENODEV;
88 #else
89 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 0)
90 return -ENODEV;
91 #endif
92 udelay(160);
93 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
94 udelay(160);
95 #ifdef CONFIG_SND_DEBUG_DETECT
97 unsigned char d;
99 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
100 snd_printk("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
101 return -ENODEV;
104 #else
105 if ((snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET) & 0x07) != 1)
106 return -ENODEV;
107 #endif
109 return 0;
112 static void __init snd_gusclassic_init(int dev, snd_gus_card_t * gus)
114 gus->equal_irq = 0;
115 gus->codec_flag = 0;
116 gus->max_flag = 0;
117 gus->joystick_dac = joystick_dac[dev];
120 static int __init snd_gusclassic_probe(int dev)
122 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
123 static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
124 int xirq, xdma1, xdma2;
125 snd_card_t *card;
126 struct snd_gusclassic *guscard;
127 snd_gus_card_t *gus = NULL;
128 int err;
130 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
131 if (card == NULL)
132 return -ENOMEM;
133 guscard = (struct snd_gusclassic *)card->private_data;
134 if (pcm_channels[dev] < 2)
135 pcm_channels[dev] = 2;
137 xirq = irq[dev];
138 if (xirq == SNDRV_AUTO_IRQ) {
139 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
140 snd_card_free(card);
141 snd_printk("unable to find a free IRQ\n");
142 return -EBUSY;
145 xdma1 = dma1[dev];
146 if (xdma1 == SNDRV_AUTO_DMA) {
147 if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
148 snd_card_free(card);
149 snd_printk("unable to find a free DMA1\n");
150 return -EBUSY;
153 xdma2 = dma2[dev];
154 if (xdma2 == SNDRV_AUTO_DMA) {
155 if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
156 snd_card_free(card);
157 snd_printk("unable to find a free DMA2\n");
158 return -EBUSY;
163 if ((err = snd_gus_create(card,
164 port[dev],
165 xirq, xdma1, xdma2,
166 0, channels[dev], pcm_channels[dev],
167 0, &gus)) < 0) {
168 snd_card_free(card);
169 return err;
171 if ((err = snd_gusclassic_detect(gus)) < 0) {
172 snd_card_free(card);
173 return err;
175 snd_gusclassic_init(dev, gus);
176 if ((err = snd_gus_initialize(gus)) < 0) {
177 snd_card_free(card);
178 return err;
180 if (gus->max_flag || gus->ess_flag) {
181 snd_printdd("GUS Classic or ACE soundcard was not detected at 0x%lx\n", gus->gf1.port);
182 snd_card_free(card);
183 return -ENODEV;
185 if ((err = snd_gf1_new_mixer(gus)) < 0) {
186 snd_card_free(card);
187 return err;
189 if ((err = snd_gf1_pcm_new(gus, 0, 0, NULL)) < 0) {
190 snd_card_free(card);
191 return err;
193 if (!gus->ace_flag) {
194 if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) {
195 snd_card_free(card);
196 return err;
199 sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %d, dma %d", gus->gf1.port, xirq, xdma1);
200 if (dma2 >= 0)
201 sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
202 if ((err = snd_card_register(card)) < 0) {
203 snd_card_free(card);
204 return err;
206 snd_gusclassic_cards[dev] = card;
207 return 0;
210 static int __init snd_gusclassic_legacy_auto_probe(unsigned long xport)
212 static int dev;
213 int res;
215 for ( ; dev < SNDRV_CARDS; dev++) {
216 if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
217 continue;
218 port[dev] = xport;
219 res = snd_gusclassic_probe(dev);
220 if (res < 0)
221 port[dev] = SNDRV_AUTO_PORT;
222 return res;
224 return -ENODEV;
227 static int __init alsa_card_gusclassic_init(void)
229 static unsigned long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260, -1};
230 int dev, cards, i;
232 for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
233 if (port[dev] == SNDRV_AUTO_PORT)
234 continue;
235 if (snd_gusclassic_probe(dev) >= 0)
236 cards++;
238 i = snd_legacy_auto_probe(possible_ports, snd_gusclassic_legacy_auto_probe);
239 if (i > 0)
240 cards += i;
242 if (!cards) {
243 #ifdef MODULE
244 printk(KERN_ERR "GUS Classic soundcard not found or device busy\n");
245 #endif
246 return -ENODEV;
248 return 0;
251 static void __exit alsa_card_gusclassic_exit(void)
253 int idx;
255 for (idx = 0; idx < SNDRV_CARDS; idx++)
256 snd_card_free(snd_gusclassic_cards[idx]);
259 module_init(alsa_card_gusclassic_init)
260 module_exit(alsa_card_gusclassic_exit)