blob: 8f914b37bf8998eaa261127b9dc53901e6b2d8b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for Gravis UltraSound Classic soundcard
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02003 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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 Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010023#include <linux/err.h>
Rene Herman93f02c62007-02-19 13:05:02 +010024#include <linux/isa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/delay.h>
26#include <linux/time.h>
27#include <linux/moduleparam.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010028#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <sound/core.h>
30#include <sound/gus.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#define SNDRV_LEGACY_FIND_FREE_IRQ
32#define SNDRV_LEGACY_FIND_FREE_DMA
33#include <sound/initval.h>
34
Rene Herman93f02c62007-02-19 13:05:02 +010035#define CRD_NAME "Gravis UltraSound Classic"
36#define DEV_NAME "gusclassic"
37
38MODULE_DESCRIPTION(CRD_NAME);
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020039MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070040MODULE_LICENSE("GPL");
41MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}");
42
43static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
44static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
45static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
46static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
47static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
48static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
49static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
50static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
51 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
52static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
53static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
54
55module_param_array(index, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010056MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057module_param_array(id, charp, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010058MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070059module_param_array(enable, bool, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010060MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070061module_param_array(port, long, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010062MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070063module_param_array(irq, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010064MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070065module_param_array(dma1, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010066MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067module_param_array(dma2, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010068MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070069module_param_array(joystick_dac, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010070MODULE_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 -070071module_param_array(channels, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010072MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070073module_param_array(pcm_channels, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010074MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Rene Herman93f02c62007-02-19 13:05:02 +010076static int __devinit snd_gusclassic_match(struct device *dev, unsigned int n)
77{
78 return enable[n];
79}
Clemens Ladischf7a92752005-12-07 09:13:42 +010080
Rene Herman93f02c62007-02-19 13:05:02 +010081static int __devinit snd_gusclassic_create(struct snd_card *card,
82 struct device *dev, unsigned int n, struct snd_gus_card **rgus)
83{
84 static long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260};
85 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
86 static int possible_dmas[] = {5, 6, 7, 1, 3, -1};
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Rene Herman93f02c62007-02-19 13:05:02 +010088 int i, error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Rene Herman93f02c62007-02-19 13:05:02 +010090 if (irq[n] == SNDRV_AUTO_IRQ) {
91 irq[n] = snd_legacy_find_free_irq(possible_irqs);
92 if (irq[n] < 0) {
93 snd_printk(KERN_ERR "%s: unable to find a free IRQ\n",
94 dev->bus_id);
95 return -EBUSY;
96 }
97 }
98 if (dma1[n] == SNDRV_AUTO_DMA) {
99 dma1[n] = snd_legacy_find_free_dma(possible_dmas);
100 if (dma1[n] < 0) {
101 snd_printk(KERN_ERR "%s: unable to find a free DMA1\n",
102 dev->bus_id);
103 return -EBUSY;
104 }
105 }
106 if (dma2[n] == SNDRV_AUTO_DMA) {
107 dma2[n] = snd_legacy_find_free_dma(possible_dmas);
108 if (dma2[n] < 0) {
109 snd_printk(KERN_ERR "%s: unable to find a free DMA2\n",
110 dev->bus_id);
111 return -EBUSY;
112 }
113 }
114
115 if (port[n] != SNDRV_AUTO_PORT)
116 return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
117 0, channels[n], pcm_channels[n], 0, rgus);
118
119 i = 0;
120 do {
121 port[n] = possible_ports[i];
122 error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
123 0, channels[n], pcm_channels[n], 0, rgus);
124 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
125
126 return error;
127}
128
129static int __devinit snd_gusclassic_detect(struct snd_gus_card *gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Takashi Iwai43bcd972005-09-05 17:19:20 +0200131 unsigned char d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Takashi Iwai43bcd972005-09-05 17:19:20 +0200133 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
134 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
135 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 udelay(160);
139 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
140 udelay(160);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200141 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
142 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 return 0;
146}
147
Rene Herman93f02c62007-02-19 13:05:02 +0100148static int __devinit snd_gusclassic_probe(struct device *dev, unsigned int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100150 struct snd_card *card;
Rene Herman93f02c62007-02-19 13:05:02 +0100151 struct snd_gus_card *gus;
152 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Rene Herman93f02c62007-02-19 13:05:02 +0100154 card = snd_card_new(index[n], id[n], THIS_MODULE, 0);
155 if (!card)
156 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Rene Herman93f02c62007-02-19 13:05:02 +0100158 if (pcm_channels[n] < 2)
159 pcm_channels[n] = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Rene Herman93f02c62007-02-19 13:05:02 +0100161 error = snd_gusclassic_create(card, dev, n, &gus);
162 if (error < 0)
163 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200164
Rene Herman93f02c62007-02-19 13:05:02 +0100165 error = snd_gusclassic_detect(gus);
166 if (error < 0)
167 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200168
Rene Herman93f02c62007-02-19 13:05:02 +0100169 gus->joystick_dac = joystick_dac[n];
Takashi Iwai43bcd972005-09-05 17:19:20 +0200170
Rene Herman93f02c62007-02-19 13:05:02 +0100171 error = snd_gus_initialize(gus);
172 if (error < 0)
173 goto out;
174
175 error = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (gus->max_flag || gus->ess_flag) {
Rene Herman93f02c62007-02-19 13:05:02 +0100177 snd_printk(KERN_ERR "%s: GUS Classic or ACE soundcard was "
178 "not detected at 0x%lx\n", dev->bus_id, gus->gf1.port);
179 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200181
Rene Herman93f02c62007-02-19 13:05:02 +0100182 error = snd_gf1_new_mixer(gus);
183 if (error < 0)
184 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200185
Rene Herman93f02c62007-02-19 13:05:02 +0100186 error = snd_gf1_pcm_new(gus, 0, 0, NULL);
187 if (error < 0)
188 goto out;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (!gus->ace_flag) {
Rene Herman93f02c62007-02-19 13:05:02 +0100191 error = snd_gf1_rawmidi_new(gus, 0, NULL);
192 if (error < 0)
193 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200195
Rene Herman93f02c62007-02-19 13:05:02 +0100196 sprintf(card->longname + strlen(card->longname),
197 " at 0x%lx, irq %d, dma %d",
198 gus->gf1.port, gus->gf1.irq, gus->gf1.dma1);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200199
Rene Herman93f02c62007-02-19 13:05:02 +0100200 if (gus->gf1.dma2 >= 0)
201 sprintf(card->longname + strlen(card->longname),
202 "&%d", gus->gf1.dma2);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200203
Rene Herman93f02c62007-02-19 13:05:02 +0100204 snd_card_set_dev(card, dev);
205
206 error = snd_card_register(card);
207 if (error < 0)
208 goto out;
209
210 dev_set_drvdata(dev, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return 0;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200212
Rene Herman93f02c62007-02-19 13:05:02 +0100213out: snd_card_free(card);
214 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
Rene Herman93f02c62007-02-19 13:05:02 +0100217static int __devexit snd_gusclassic_remove(struct device *dev, unsigned int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Rene Herman93f02c62007-02-19 13:05:02 +0100219 snd_card_free(dev_get_drvdata(dev));
220 dev_set_drvdata(dev, NULL);
Takashi Iwai654aa662005-11-17 17:13:43 +0100221 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
Rene Herman93f02c62007-02-19 13:05:02 +0100224static struct isa_driver snd_gusclassic_driver = {
225 .match = snd_gusclassic_match,
Takashi Iwai654aa662005-11-17 17:13:43 +0100226 .probe = snd_gusclassic_probe,
Prarit Bhargava788c6042007-02-13 13:11:11 +0100227 .remove = __devexit_p(snd_gusclassic_remove),
Rene Herman93f02c62007-02-19 13:05:02 +0100228#if 0 /* FIXME */
229 .suspend = snd_gusclassic_suspend,
230 .remove = snd_gusclassic_remove,
231#endif
Takashi Iwai654aa662005-11-17 17:13:43 +0100232 .driver = {
Rene Herman93f02c62007-02-19 13:05:02 +0100233 .name = DEV_NAME
234 }
Takashi Iwai654aa662005-11-17 17:13:43 +0100235};
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237static int __init alsa_card_gusclassic_init(void)
238{
Rene Herman93f02c62007-02-19 13:05:02 +0100239 return isa_register_driver(&snd_gusclassic_driver, SNDRV_CARDS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
242static void __exit alsa_card_gusclassic_exit(void)
243{
Rene Herman93f02c62007-02-19 13:05:02 +0100244 isa_unregister_driver(&snd_gusclassic_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
Rene Herman93f02c62007-02-19 13:05:02 +0100247module_init(alsa_card_gusclassic_init);
248module_exit(alsa_card_gusclassic_exit);