blob: 8f23f433d491a9086c51a0005b9b6f3eb1677c01 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/init.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010024#include <linux/err.h>
Rene Herman93f02c62007-02-19 13:05:02 +010025#include <linux/isa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/delay.h>
27#include <linux/time.h>
28#include <linux/moduleparam.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010029#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <sound/core.h>
31#include <sound/gus.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define SNDRV_LEGACY_FIND_FREE_IRQ
33#define SNDRV_LEGACY_FIND_FREE_DMA
34#include <sound/initval.h>
35
Rene Herman93f02c62007-02-19 13:05:02 +010036#define CRD_NAME "Gravis UltraSound Classic"
37#define DEV_NAME "gusclassic"
38
39MODULE_DESCRIPTION(CRD_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070041MODULE_LICENSE("GPL");
42MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}");
43
44static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
45static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
46static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
47static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
48static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
49static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
50static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
51static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
52 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
53static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
54static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
55
56module_param_array(index, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010057MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070058module_param_array(id, charp, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010059MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070060module_param_array(enable, bool, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010061MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070062module_param_array(port, long, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010063MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064module_param_array(irq, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010065MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070066module_param_array(dma1, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010067MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070068module_param_array(dma2, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010069MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070070module_param_array(joystick_dac, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010071MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070072module_param_array(channels, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010073MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074module_param_array(pcm_channels, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010075MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Rene Herman93f02c62007-02-19 13:05:02 +010077static int __devinit snd_gusclassic_match(struct device *dev, unsigned int n)
78{
79 return enable[n];
80}
Clemens Ladischf7a92752005-12-07 09:13:42 +010081
Rene Herman93f02c62007-02-19 13:05:02 +010082static int __devinit snd_gusclassic_create(struct snd_card *card,
83 struct device *dev, unsigned int n, struct snd_gus_card **rgus)
84{
85 static long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260};
86 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
87 static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Rene Herman93f02c62007-02-19 13:05:02 +010089 int i, error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Rene Herman93f02c62007-02-19 13:05:02 +010091 if (irq[n] == SNDRV_AUTO_IRQ) {
92 irq[n] = snd_legacy_find_free_irq(possible_irqs);
93 if (irq[n] < 0) {
94 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n",
95 dev->bus_id);
96 return -EBUSY;
97 }
98 }
99 if (dma1[n] == SNDRV_AUTO_DMA) {
100 dma1[n] = snd_legacy_find_free_dma(possible_dmas);
101 if (dma1[n] < 0) {
102 snd_printk(KERN_ERR "%s: unable to find a free DMA1\n",
103 dev->bus_id);
104 return -EBUSY;
105 }
106 }
107 if (dma2[n] == SNDRV_AUTO_DMA) {
108 dma2[n] = snd_legacy_find_free_dma(possible_dmas);
109 if (dma2[n] < 0) {
110 snd_printk(KERN_ERR "%s: unable to find a free DMA2\n",
111 dev->bus_id);
112 return -EBUSY;
113 }
114 }
115
116 if (port[n] != SNDRV_AUTO_PORT)
117 return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
118 0, channels[n], pcm_channels[n], 0, rgus);
119
120 i = 0;
121 do {
122 port[n] = possible_ports[i];
123 error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
124 0, channels[n], pcm_channels[n], 0, rgus);
125 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
126
127 return error;
128}
129
130static int __devinit snd_gusclassic_detect(struct snd_gus_card *gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Takashi Iwai43bcd972005-09-05 17:19:20 +0200132 unsigned char d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Takashi Iwai43bcd972005-09-05 17:19:20 +0200134 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
135 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
136 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 udelay(160);
140 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
141 udelay(160);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200142 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
143 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 return 0;
147}
148
Rene Herman93f02c62007-02-19 13:05:02 +0100149static int __devinit snd_gusclassic_probe(struct device *dev, unsigned int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100151 struct snd_card *card;
Rene Herman93f02c62007-02-19 13:05:02 +0100152 struct snd_gus_card *gus;
153 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Rene Herman93f02c62007-02-19 13:05:02 +0100155 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
156 if (!card)
157 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Rene Herman93f02c62007-02-19 13:05:02 +0100159 if (pcm_channels[n] < 2)
160 pcm_channels[n] = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Rene Herman93f02c62007-02-19 13:05:02 +0100162 error = snd_gusclassic_create(card, dev, n, &gus);
163 if (error < 0)
164 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200165
Rene Herman93f02c62007-02-19 13:05:02 +0100166 error = snd_gusclassic_detect(gus);
167 if (error < 0)
168 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200169
Rene Herman93f02c62007-02-19 13:05:02 +0100170 gus->joystick_dac = joystick_dac[n];
Takashi Iwai43bcd972005-09-05 17:19:20 +0200171
Rene Herman93f02c62007-02-19 13:05:02 +0100172 error = snd_gus_initialize(gus);
173 if (error < 0)
174 goto out;
175
176 error = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (gus->max_flag || gus->ess_flag) {
Rene Herman93f02c62007-02-19 13:05:02 +0100178 snd_printk(KERN_ERR "%s: GUS Classic or ACE soundcard was "
179 "not detected at 0x%lx\n", dev->bus_id, gus->gf1.port);
180 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200182
Rene Herman93f02c62007-02-19 13:05:02 +0100183 error = snd_gf1_new_mixer(gus);
184 if (error < 0)
185 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200186
Rene Herman93f02c62007-02-19 13:05:02 +0100187 error = snd_gf1_pcm_new(gus, 0, 0, NULL);
188 if (error < 0)
189 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 if (!gus->ace_flag) {
Rene Herman93f02c62007-02-19 13:05:02 +0100192 error = snd_gf1_rawmidi_new(gus, 0, NULL);
193 if (error < 0)
194 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200196
Rene Herman93f02c62007-02-19 13:05:02 +0100197 sprintf(card->longname + strlen(card->longname),
198 " at 0x%lx, irq %d, dma %d",
199 gus->gf1.port, gus->gf1.irq, gus->gf1.dma1);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200200
Rene Herman93f02c62007-02-19 13:05:02 +0100201 if (gus->gf1.dma2 >= 0)
202 sprintf(card->longname + strlen(card->longname),
203 "&%d", gus->gf1.dma2);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200204
Rene Herman93f02c62007-02-19 13:05:02 +0100205 snd_card_set_dev(card, dev);
206
207 error = snd_card_register(card);
208 if (error < 0)
209 goto out;
210
211 dev_set_drvdata(dev, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 return 0;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200213
Rene Herman93f02c62007-02-19 13:05:02 +0100214out: snd_card_free(card);
215 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Rene Herman93f02c62007-02-19 13:05:02 +0100218static int __devexit snd_gusclassic_remove(struct device *dev, unsigned int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
Rene Herman93f02c62007-02-19 13:05:02 +0100220 snd_card_free(dev_get_drvdata(dev));
221 dev_set_drvdata(dev, NULL);
Takashi Iwai654aa662005-11-17 17:13:43 +0100222 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
Rene Herman93f02c62007-02-19 13:05:02 +0100225static struct isa_driver snd_gusclassic_driver = {
226 .match = snd_gusclassic_match,
Takashi Iwai654aa662005-11-17 17:13:43 +0100227 .probe = snd_gusclassic_probe,
Prarit Bhargava788c6042007-02-13 13:11:11 +0100228 .remove = __devexit_p(snd_gusclassic_remove),
Rene Herman93f02c62007-02-19 13:05:02 +0100229#if 0 /* FIXME */
230 .suspend = snd_gusclassic_suspend,
231 .remove = snd_gusclassic_remove,
232#endif
Takashi Iwai654aa662005-11-17 17:13:43 +0100233 .driver = {
Rene Herman93f02c62007-02-19 13:05:02 +0100234 .name = DEV_NAME
235 }
Takashi Iwai654aa662005-11-17 17:13:43 +0100236};
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238static int __init alsa_card_gusclassic_init(void)
239{
Rene Herman93f02c62007-02-19 13:05:02 +0100240 return isa_register_driver(&snd_gusclassic_driver, SNDRV_CARDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
243static void __exit alsa_card_gusclassic_exit(void)
244{
Rene Herman93f02c62007-02-19 13:05:02 +0100245 isa_unregister_driver(&snd_gusclassic_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246}
247
Rene Herman93f02c62007-02-19 13:05:02 +0100248module_init(alsa_card_gusclassic_init);
249module_exit(alsa_card_gusclassic_exit);