Linux Audio

Check our new training course

Loading...
v3.1
  1/*
  2 *  Driver for Gravis UltraSound Classic soundcard
  3 *  Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/init.h>
 23#include <linux/err.h>
 24#include <linux/isa.h>
 25#include <linux/delay.h>
 26#include <linux/time.h>
 27#include <linux/moduleparam.h>
 28#include <asm/dma.h>
 29#include <sound/core.h>
 30#include <sound/gus.h>
 31#define SNDRV_LEGACY_FIND_FREE_IRQ
 32#define SNDRV_LEGACY_FIND_FREE_DMA
 33#include <sound/initval.h>
 34
 35#define CRD_NAME "Gravis UltraSound Classic"
 36#define DEV_NAME "gusclassic"
 37
 38MODULE_DESCRIPTION(CRD_NAME);
 39MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 40MODULE_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);
 56MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
 57module_param_array(id, charp, NULL, 0444);
 58MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
 59module_param_array(enable, bool, NULL, 0444);
 60MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
 61module_param_array(port, long, NULL, 0444);
 62MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
 63module_param_array(irq, int, NULL, 0444);
 64MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
 65module_param_array(dma1, int, NULL, 0444);
 66MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
 67module_param_array(dma2, int, NULL, 0444);
 68MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
 69module_param_array(joystick_dac, int, NULL, 0444);
 70MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver.");
 71module_param_array(channels, int, NULL, 0444);
 72MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver.");
 73module_param_array(pcm_channels, int, NULL, 0444);
 74MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver.");
 75
 76static int __devinit snd_gusclassic_match(struct device *dev, unsigned int n)
 77{
 78	return enable[n];
 79}
 80
 81static 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};
 87
 88	int i, error;
 89
 90	if (irq[n] == SNDRV_AUTO_IRQ) {
 91		irq[n] = snd_legacy_find_free_irq(possible_irqs);
 92		if (irq[n] < 0) {
 93			dev_err(dev, "unable to find a free IRQ\n");
 94			return -EBUSY;
 95		}
 96	}
 97	if (dma1[n] == SNDRV_AUTO_DMA) {
 98		dma1[n] = snd_legacy_find_free_dma(possible_dmas);
 99		if (dma1[n] < 0) {
100			dev_err(dev, "unable to find a free DMA1\n");
101			return -EBUSY;
102		}
103	}
104	if (dma2[n] == SNDRV_AUTO_DMA) {
105		dma2[n] = snd_legacy_find_free_dma(possible_dmas);
106		if (dma2[n] < 0) {
107			dev_err(dev, "unable to find a free DMA2\n");
108			return -EBUSY;
109		}
110	}
111
112	if (port[n] != SNDRV_AUTO_PORT)
113		return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
114				0, channels[n], pcm_channels[n], 0, rgus);
115
116	i = 0;
117	do {
118		port[n] = possible_ports[i];
119		error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
120				0, channels[n], pcm_channels[n], 0, rgus);
121	} while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
122
123	return error;
124}
125
126static int __devinit snd_gusclassic_detect(struct snd_gus_card *gus)
127{
128	unsigned char d;
129
130	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0);	/* reset GF1 */
131	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
132		snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
133		return -ENODEV;
134	}
135	udelay(160);
136	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1);	/* release reset */
137	udelay(160);
138	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
139		snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
140		return -ENODEV;
141	}
142	return 0;
143}
144
145static int __devinit snd_gusclassic_probe(struct device *dev, unsigned int n)
146{
147	struct snd_card *card;
148	struct snd_gus_card *gus;
149	int error;
150
151	error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
152	if (error < 0)
153		return error;
154
155	if (pcm_channels[n] < 2)
156		pcm_channels[n] = 2;
157
158	error = snd_gusclassic_create(card, dev, n, &gus);
159	if (error < 0)
160		goto out;
161
162	error = snd_gusclassic_detect(gus);
163	if (error < 0)
164		goto out;
165
166	gus->joystick_dac = joystick_dac[n];
167
168	error = snd_gus_initialize(gus);
169	if (error < 0)
170		goto out;
171
172	error = -ENODEV;
173	if (gus->max_flag || gus->ess_flag) {
174		dev_err(dev, "GUS Classic or ACE soundcard was "
175			"not detected at 0x%lx\n", gus->gf1.port);
176		goto out;
177	}
178
179	error = snd_gf1_new_mixer(gus);
180	if (error < 0)
181		goto out;
182
183	error = snd_gf1_pcm_new(gus, 0, 0, NULL);
184	if (error < 0)
185		goto out;
186
187	if (!gus->ace_flag) {
188		error = snd_gf1_rawmidi_new(gus, 0, NULL);
189		if (error < 0)
190			goto out;
191	}
192
193	sprintf(card->longname + strlen(card->longname),
194		" at 0x%lx, irq %d, dma %d",
195		gus->gf1.port, gus->gf1.irq, gus->gf1.dma1);
196
197	if (gus->gf1.dma2 >= 0)
198		sprintf(card->longname + strlen(card->longname),
199			"&%d", gus->gf1.dma2);
200
201	snd_card_set_dev(card, dev);
202
203	error = snd_card_register(card);
204	if (error < 0)
205		goto out;
206
207	dev_set_drvdata(dev, card);
208	return 0;
209
210out:	snd_card_free(card);
211	return error;
212}
213
214static int __devexit snd_gusclassic_remove(struct device *dev, unsigned int n)
215{
216	snd_card_free(dev_get_drvdata(dev));
217	dev_set_drvdata(dev, NULL);
218	return 0;
219}
220
221static struct isa_driver snd_gusclassic_driver = {
222	.match		= snd_gusclassic_match,
223	.probe		= snd_gusclassic_probe,
224	.remove		= __devexit_p(snd_gusclassic_remove),
225#if 0	/* FIXME */
226	.suspend	= snd_gusclassic_suspend,
227	.remove		= snd_gusclassic_remove,
228#endif
229	.driver		= {
230		.name	= DEV_NAME
231	}
232};
233
234static int __init alsa_card_gusclassic_init(void)
235{
236	return isa_register_driver(&snd_gusclassic_driver, SNDRV_CARDS);
237}
238
239static void __exit alsa_card_gusclassic_exit(void)
240{
241	isa_unregister_driver(&snd_gusclassic_driver);
242}
243
244module_init(alsa_card_gusclassic_init);
245module_exit(alsa_card_gusclassic_exit);
v4.17
  1/*
  2 *  Driver for Gravis UltraSound Classic soundcard
  3 *  Copyright (c) by Jaroslav Kysela <perex@perex.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 <linux/init.h>
 23#include <linux/err.h>
 24#include <linux/isa.h>
 25#include <linux/delay.h>
 26#include <linux/time.h>
 27#include <linux/module.h>
 28#include <asm/dma.h>
 29#include <sound/core.h>
 30#include <sound/gus.h>
 31#define SNDRV_LEGACY_FIND_FREE_IRQ
 32#define SNDRV_LEGACY_FIND_FREE_DMA
 33#include <sound/initval.h>
 34
 35#define CRD_NAME "Gravis UltraSound Classic"
 36#define DEV_NAME "gusclassic"
 37
 38MODULE_DESCRIPTION(CRD_NAME);
 39MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 40MODULE_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 bool 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);
 56MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
 57module_param_array(id, charp, NULL, 0444);
 58MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
 59module_param_array(enable, bool, NULL, 0444);
 60MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
 61module_param_hw_array(port, long, ioport, NULL, 0444);
 62MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
 63module_param_hw_array(irq, int, irq, NULL, 0444);
 64MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
 65module_param_hw_array(dma1, int, dma, NULL, 0444);
 66MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
 67module_param_hw_array(dma2, int, dma, NULL, 0444);
 68MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
 69module_param_array(joystick_dac, int, NULL, 0444);
 70MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver.");
 71module_param_array(channels, int, NULL, 0444);
 72MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver.");
 73module_param_array(pcm_channels, int, NULL, 0444);
 74MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver.");
 75
 76static int snd_gusclassic_match(struct device *dev, unsigned int n)
 77{
 78	return enable[n];
 79}
 80
 81static int snd_gusclassic_create(struct snd_card *card,
 82				 struct device *dev, unsigned int n,
 83				 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};
 88
 89	int i, error;
 90
 91	if (irq[n] == SNDRV_AUTO_IRQ) {
 92		irq[n] = snd_legacy_find_free_irq(possible_irqs);
 93		if (irq[n] < 0) {
 94			dev_err(dev, "unable to find a free IRQ\n");
 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			dev_err(dev, "unable to find a free DMA1\n");
102			return -EBUSY;
103		}
104	}
105	if (dma2[n] == SNDRV_AUTO_DMA) {
106		dma2[n] = snd_legacy_find_free_dma(possible_dmas);
107		if (dma2[n] < 0) {
108			dev_err(dev, "unable to find a free DMA2\n");
109			return -EBUSY;
110		}
111	}
112
113	if (port[n] != SNDRV_AUTO_PORT)
114		return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
115				0, channels[n], pcm_channels[n], 0, rgus);
116
117	i = 0;
118	do {
119		port[n] = possible_ports[i];
120		error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
121				0, channels[n], pcm_channels[n], 0, rgus);
122	} while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
123
124	return error;
125}
126
127static int snd_gusclassic_detect(struct snd_gus_card *gus)
128{
129	unsigned char d;
130
131	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0);	/* reset GF1 */
132	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) {
133		snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
134		return -ENODEV;
135	}
136	udelay(160);
137	snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1);	/* release reset */
138	udelay(160);
139	if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) {
140		snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
141		return -ENODEV;
142	}
143	return 0;
144}
145
146static int snd_gusclassic_probe(struct device *dev, unsigned int n)
147{
148	struct snd_card *card;
149	struct snd_gus_card *gus;
150	int error;
151
152	error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
153	if (error < 0)
154		return error;
155
156	if (pcm_channels[n] < 2)
157		pcm_channels[n] = 2;
158
159	error = snd_gusclassic_create(card, dev, n, &gus);
160	if (error < 0)
161		goto out;
162
163	error = snd_gusclassic_detect(gus);
164	if (error < 0)
165		goto out;
166
167	gus->joystick_dac = joystick_dac[n];
168
169	error = snd_gus_initialize(gus);
170	if (error < 0)
171		goto out;
172
173	error = -ENODEV;
174	if (gus->max_flag || gus->ess_flag) {
175		dev_err(dev, "GUS Classic or ACE soundcard was "
176			"not detected at 0x%lx\n", gus->gf1.port);
177		goto out;
178	}
179
180	error = snd_gf1_new_mixer(gus);
181	if (error < 0)
182		goto out;
183
184	error = snd_gf1_pcm_new(gus, 0, 0);
185	if (error < 0)
186		goto out;
187
188	if (!gus->ace_flag) {
189		error = snd_gf1_rawmidi_new(gus, 0);
190		if (error < 0)
191			goto out;
192	}
193
194	sprintf(card->longname + strlen(card->longname),
195		" at 0x%lx, irq %d, dma %d",
196		gus->gf1.port, gus->gf1.irq, gus->gf1.dma1);
197
198	if (gus->gf1.dma2 >= 0)
199		sprintf(card->longname + strlen(card->longname),
200			"&%d", gus->gf1.dma2);
201
 
 
202	error = snd_card_register(card);
203	if (error < 0)
204		goto out;
205
206	dev_set_drvdata(dev, card);
207	return 0;
208
209out:	snd_card_free(card);
210	return error;
211}
212
213static int snd_gusclassic_remove(struct device *dev, unsigned int n)
214{
215	snd_card_free(dev_get_drvdata(dev));
 
216	return 0;
217}
218
219static struct isa_driver snd_gusclassic_driver = {
220	.match		= snd_gusclassic_match,
221	.probe		= snd_gusclassic_probe,
222	.remove		= snd_gusclassic_remove,
223#if 0	/* FIXME */
224	.suspend	= snd_gusclassic_suspend,
225	.remove		= snd_gusclassic_remove,
226#endif
227	.driver		= {
228		.name	= DEV_NAME
229	}
230};
231
232module_isa_driver(snd_gusclassic_driver, SNDRV_CARDS);