blob: 6db484f71367151e948eddda3f8728bc24012300 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for Gravis UltraSound Classic soundcard
3 * Copyright (c) by Jaroslav Kysela <perex@suse.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 <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>
34
35MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
36MODULE_DESCRIPTION("Gravis UltraSound Classic");
37MODULE_LICENSE("GPL");
38MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}");
39
40static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
41static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
42static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
43static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
44static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
45static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
46static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
47static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
48 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
49static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
50static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
51
52module_param_array(index, int, NULL, 0444);
53MODULE_PARM_DESC(index, "Index value for GUS Classic soundcard.");
54module_param_array(id, charp, NULL, 0444);
55MODULE_PARM_DESC(id, "ID string for GUS Classic soundcard.");
56module_param_array(enable, bool, NULL, 0444);
57MODULE_PARM_DESC(enable, "Enable GUS Classic soundcard.");
58module_param_array(port, long, NULL, 0444);
59MODULE_PARM_DESC(port, "Port # for GUS Classic driver.");
60module_param_array(irq, int, NULL, 0444);
61MODULE_PARM_DESC(irq, "IRQ # for GUS Classic driver.");
62module_param_array(dma1, int, NULL, 0444);
63MODULE_PARM_DESC(dma1, "DMA1 # for GUS Classic driver.");
64module_param_array(dma2, int, NULL, 0444);
65MODULE_PARM_DESC(dma2, "DMA2 # for GUS Classic driver.");
66module_param_array(joystick_dac, int, NULL, 0444);
67MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS Classic driver.");
68module_param_array(channels, int, NULL, 0444);
69MODULE_PARM_DESC(channels, "GF1 channels for GUS Classic driver.");
70module_param_array(pcm_channels, int, NULL, 0444);
71MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS Classic driver.");
72
Takashi Iwai5e2da202005-11-17 14:36:44 +010073static struct snd_card *snd_gusclassic_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Takashi Iwai43bcd972005-09-05 17:19:20 +020075#define PFX "gusclassic: "
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Takashi Iwai5e2da202005-11-17 14:36:44 +010077static int __init snd_gusclassic_detect(struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Takashi Iwai43bcd972005-09-05 17:19:20 +020079 unsigned char d;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Takashi Iwai43bcd972005-09-05 17:19:20 +020081 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
82 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
83 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +020085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 udelay(160);
87 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
88 udelay(160);
Takashi Iwai43bcd972005-09-05 17:19:20 +020089 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
90 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +020092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 return 0;
94}
95
Takashi Iwai5e2da202005-11-17 14:36:44 +010096static void __init snd_gusclassic_init(int dev, struct snd_gus_card * gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
98 gus->equal_irq = 0;
99 gus->codec_flag = 0;
100 gus->max_flag = 0;
101 gus->joystick_dac = joystick_dac[dev];
102}
103
104static int __init snd_gusclassic_probe(int dev)
105{
106 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
107 static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
108 int xirq, xdma1, xdma2;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100109 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 struct snd_gusclassic *guscard;
Takashi Iwai5e2da202005-11-17 14:36:44 +0100111 struct snd_gus_card *gus = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 int err;
113
114 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
115 if (card == NULL)
116 return -ENOMEM;
117 guscard = (struct snd_gusclassic *)card->private_data;
118 if (pcm_channels[dev] < 2)
119 pcm_channels[dev] = 2;
120
121 xirq = irq[dev];
122 if (xirq == SNDRV_AUTO_IRQ) {
123 if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200124 snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
125 err = -EBUSY;
126 goto _err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128 }
129 xdma1 = dma1[dev];
130 if (xdma1 == SNDRV_AUTO_DMA) {
131 if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200132 snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
133 err = -EBUSY;
134 goto _err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136 }
137 xdma2 = dma2[dev];
138 if (xdma2 == SNDRV_AUTO_DMA) {
139 if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200140 snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
141 err = -EBUSY;
142 goto _err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144 }
145
146
147 if ((err = snd_gus_create(card,
148 port[dev],
149 xirq, xdma1, xdma2,
150 0, channels[dev], pcm_channels[dev],
Takashi Iwai43bcd972005-09-05 17:19:20 +0200151 0, &gus)) < 0)
152 goto _err;
153
154 if ((err = snd_gusclassic_detect(gus)) < 0)
155 goto _err;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 snd_gusclassic_init(dev, gus);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200158 if ((err = snd_gus_initialize(gus)) < 0)
159 goto _err;
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 if (gus->max_flag || gus->ess_flag) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200162 snd_printk(KERN_ERR PFX "GUS Classic or ACE soundcard was not detected at 0x%lx\n", gus->gf1.port);
163 err = -ENODEV;
164 goto _err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200166
167 if ((err = snd_gf1_new_mixer(gus)) < 0)
168 goto _err;
169
170 if ((err = snd_gf1_pcm_new(gus, 0, 0, NULL)) < 0)
171 goto _err;
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 if (!gus->ace_flag) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200174 if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0)
175 goto _err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177 sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %d, dma %d", gus->gf1.port, xirq, xdma1);
178 if (dma2 >= 0)
179 sprintf(card->longname + strlen(card->longname), "&%d", xdma2);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200180
181 if ((err = snd_card_set_generic_dev(card)) < 0)
182 goto _err;
183
184 if ((err = snd_card_register(card)) < 0)
185 goto _err;
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 snd_gusclassic_cards[dev] = card;
188 return 0;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200189
190 _err:
191 snd_card_free(card);
192 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195static int __init snd_gusclassic_legacy_auto_probe(unsigned long xport)
196{
197 static int dev;
198 int res;
199
200 for ( ; dev < SNDRV_CARDS; dev++) {
201 if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
202 continue;
203 port[dev] = xport;
204 res = snd_gusclassic_probe(dev);
205 if (res < 0)
206 port[dev] = SNDRV_AUTO_PORT;
207 return res;
208 }
209 return -ENODEV;
210}
211
212static int __init alsa_card_gusclassic_init(void)
213{
214 static unsigned long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260, -1};
215 int dev, cards, i;
216
217 for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
218 if (port[dev] == SNDRV_AUTO_PORT)
219 continue;
220 if (snd_gusclassic_probe(dev) >= 0)
221 cards++;
222 }
223 i = snd_legacy_auto_probe(possible_ports, snd_gusclassic_legacy_auto_probe);
224 if (i > 0)
225 cards += i;
226
227 if (!cards) {
228#ifdef MODULE
229 printk(KERN_ERR "GUS Classic soundcard not found or device busy\n");
230#endif
231 return -ENODEV;
232 }
233 return 0;
234}
235
236static void __exit alsa_card_gusclassic_exit(void)
237{
238 int idx;
239
240 for (idx = 0; idx < SNDRV_CARDS; idx++)
241 snd_card_free(snd_gusclassic_cards[idx]);
242}
243
244module_init(alsa_card_gusclassic_init)
245module_exit(alsa_card_gusclassic_exit)