blob: 09cc53ceea2aeab12042295527a4e1ad0f915d73 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Driver for Gravis UltraSound Classic soundcard
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02004 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/init.h>
Takashi Iwai654aa662005-11-17 17:13:43 +01008#include <linux/err.h>
Rene Herman93f02c62007-02-19 13:05:02 +01009#include <linux/isa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/delay.h>
11#include <linux/time.h>
Paul Gortmaker65a77212011-07-15 13:13:37 -040012#include <linux/module.h>
Takashi Iwai654aa662005-11-17 17:13:43 +010013#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <sound/core.h>
15#include <sound/gus.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define SNDRV_LEGACY_FIND_FREE_IRQ
17#define SNDRV_LEGACY_FIND_FREE_DMA
18#include <sound/initval.h>
19
Rene Herman93f02c62007-02-19 13:05:02 +010020#define CRD_NAME "Gravis UltraSound Classic"
21#define DEV_NAME "gusclassic"
22
23MODULE_DESCRIPTION(CRD_NAME);
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020024MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070025MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
28static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
Rusty Russella67ff6a2011-12-15 13:49:36 +103029static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */
31static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */
32static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
33static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */
34static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29};
35 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */
36static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24};
37static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2};
38
39module_param_array(index, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010040MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070041module_param_array(id, charp, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010042MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070043module_param_array(enable, bool, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010044MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
David Howellse992ef52017-04-04 16:54:30 +010045module_param_hw_array(port, long, ioport, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010046MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
David Howellse992ef52017-04-04 16:54:30 +010047module_param_hw_array(irq, int, irq, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010048MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
David Howellse992ef52017-04-04 16:54:30 +010049module_param_hw_array(dma1, int, dma, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010050MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver.");
David Howellse992ef52017-04-04 16:54:30 +010051module_param_hw_array(dma2, int, dma, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010052MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070053module_param_array(joystick_dac, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010054MODULE_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 -070055module_param_array(channels, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010056MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070057module_param_array(pcm_channels, int, NULL, 0444);
Rene Herman93f02c62007-02-19 13:05:02 +010058MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Bill Pemberton1bff2922012-12-06 12:35:21 -050060static int snd_gusclassic_match(struct device *dev, unsigned int n)
Rene Herman93f02c62007-02-19 13:05:02 +010061{
62 return enable[n];
63}
Clemens Ladischf7a92752005-12-07 09:13:42 +010064
Bill Pemberton1bff2922012-12-06 12:35:21 -050065static int snd_gusclassic_create(struct snd_card *card,
66 struct device *dev, unsigned int n,
67 struct snd_gus_card **rgus)
Rene Herman93f02c62007-02-19 13:05:02 +010068{
Takashi Iwai15a1af952020-01-05 15:48:04 +010069 static const long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260};
70 static const int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1};
71 static const int possible_dmas[] = {5, 6, 7, 1, 3, -1};
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Rene Herman93f02c62007-02-19 13:05:02 +010073 int i, error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Rene Herman93f02c62007-02-19 13:05:02 +010075 if (irq[n] == SNDRV_AUTO_IRQ) {
76 irq[n] = snd_legacy_find_free_irq(possible_irqs);
77 if (irq[n] < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010078 dev_err(dev, "unable to find a free IRQ\n");
Rene Herman93f02c62007-02-19 13:05:02 +010079 return -EBUSY;
80 }
81 }
82 if (dma1[n] == SNDRV_AUTO_DMA) {
83 dma1[n] = snd_legacy_find_free_dma(possible_dmas);
84 if (dma1[n] < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010085 dev_err(dev, "unable to find a free DMA1\n");
Rene Herman93f02c62007-02-19 13:05:02 +010086 return -EBUSY;
87 }
88 }
89 if (dma2[n] == SNDRV_AUTO_DMA) {
90 dma2[n] = snd_legacy_find_free_dma(possible_dmas);
91 if (dma2[n] < 0) {
Takashi Iwai0418ff02008-11-03 08:51:33 +010092 dev_err(dev, "unable to find a free DMA2\n");
Rene Herman93f02c62007-02-19 13:05:02 +010093 return -EBUSY;
94 }
95 }
96
97 if (port[n] != SNDRV_AUTO_PORT)
98 return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
99 0, channels[n], pcm_channels[n], 0, rgus);
100
101 i = 0;
102 do {
103 port[n] = possible_ports[i];
104 error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n],
105 0, channels[n], pcm_channels[n], 0, rgus);
106 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
107
108 return error;
109}
110
Bill Pemberton1bff2922012-12-06 12:35:21 -0500111static int snd_gusclassic_detect(struct snd_gus_card *gus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Takashi Iwai43bcd972005-09-05 17:19:20 +0200113 unsigned char d;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Takashi Iwai43bcd972005-09-05 17:19:20 +0200115 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */
Takashi Iwai310efd32021-06-08 16:04:38 +0200116 d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET);
117 if ((d & 0x07) != 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200118 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 udelay(160);
122 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */
123 udelay(160);
Takashi Iwai310efd32021-06-08 16:04:38 +0200124 d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET);
125 if ((d & 0x07) != 1) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200126 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return -ENODEV;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 return 0;
130}
131
Bill Pemberton1bff2922012-12-06 12:35:21 -0500132static int snd_gusclassic_probe(struct device *dev, unsigned int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133{
Takashi Iwai5e2da202005-11-17 14:36:44 +0100134 struct snd_card *card;
Rene Herman93f02c62007-02-19 13:05:02 +0100135 struct snd_gus_card *gus;
136 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Takashi Iwai5b88da32021-07-15 09:59:27 +0200138 error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100139 if (error < 0)
140 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Rene Herman93f02c62007-02-19 13:05:02 +0100142 if (pcm_channels[n] < 2)
143 pcm_channels[n] = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Rene Herman93f02c62007-02-19 13:05:02 +0100145 error = snd_gusclassic_create(card, dev, n, &gus);
146 if (error < 0)
Takashi Iwai5b88da32021-07-15 09:59:27 +0200147 return error;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200148
Rene Herman93f02c62007-02-19 13:05:02 +0100149 error = snd_gusclassic_detect(gus);
150 if (error < 0)
Takashi Iwai5b88da32021-07-15 09:59:27 +0200151 return error;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200152
Rene Herman93f02c62007-02-19 13:05:02 +0100153 gus->joystick_dac = joystick_dac[n];
Takashi Iwai43bcd972005-09-05 17:19:20 +0200154
Rene Herman93f02c62007-02-19 13:05:02 +0100155 error = snd_gus_initialize(gus);
156 if (error < 0)
Takashi Iwai5b88da32021-07-15 09:59:27 +0200157 return error;
Rene Herman93f02c62007-02-19 13:05:02 +0100158
159 error = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 if (gus->max_flag || gus->ess_flag) {
Takashi Iwai0418ff02008-11-03 08:51:33 +0100161 dev_err(dev, "GUS Classic or ACE soundcard was "
162 "not detected at 0x%lx\n", gus->gf1.port);
Takashi Iwai5b88da32021-07-15 09:59:27 +0200163 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200165
Rene Herman93f02c62007-02-19 13:05:02 +0100166 error = snd_gf1_new_mixer(gus);
167 if (error < 0)
Takashi Iwai5b88da32021-07-15 09:59:27 +0200168 return error;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200169
Lars-Peter Clausendb5abb32015-01-02 12:24:39 +0100170 error = snd_gf1_pcm_new(gus, 0, 0);
Rene Herman93f02c62007-02-19 13:05:02 +0100171 if (error < 0)
Takashi Iwai5b88da32021-07-15 09:59:27 +0200172 return error;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (!gus->ace_flag) {
Lars-Peter Clausendb5abb32015-01-02 12:24:39 +0100175 error = snd_gf1_rawmidi_new(gus, 0);
Rene Herman93f02c62007-02-19 13:05:02 +0100176 if (error < 0)
Takashi Iwai5b88da32021-07-15 09:59:27 +0200177 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200179
Rene Herman93f02c62007-02-19 13:05:02 +0100180 sprintf(card->longname + strlen(card->longname),
181 " at 0x%lx, irq %d, dma %d",
182 gus->gf1.port, gus->gf1.irq, gus->gf1.dma1);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200183
Rene Herman93f02c62007-02-19 13:05:02 +0100184 if (gus->gf1.dma2 >= 0)
185 sprintf(card->longname + strlen(card->longname),
186 "&%d", gus->gf1.dma2);
Takashi Iwai43bcd972005-09-05 17:19:20 +0200187
Rene Herman93f02c62007-02-19 13:05:02 +0100188 error = snd_card_register(card);
189 if (error < 0)
Takashi Iwai5b88da32021-07-15 09:59:27 +0200190 return error;
Rene Herman93f02c62007-02-19 13:05:02 +0100191
192 dev_set_drvdata(dev, card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Rene Herman93f02c62007-02-19 13:05:02 +0100196static struct isa_driver snd_gusclassic_driver = {
197 .match = snd_gusclassic_match,
Takashi Iwai654aa662005-11-17 17:13:43 +0100198 .probe = snd_gusclassic_probe,
Rene Herman93f02c62007-02-19 13:05:02 +0100199#if 0 /* FIXME */
200 .suspend = snd_gusclassic_suspend,
Rene Herman93f02c62007-02-19 13:05:02 +0100201#endif
Takashi Iwai654aa662005-11-17 17:13:43 +0100202 .driver = {
Rene Herman93f02c62007-02-19 13:05:02 +0100203 .name = DEV_NAME
204 }
Takashi Iwai654aa662005-11-17 17:13:43 +0100205};
206
William Breathitt Graya04236e2016-05-31 11:56:09 -0400207module_isa_driver(snd_gusclassic_driver, SNDRV_CARDS);