1 // SPDX-License-Identifier: GPL-2.0-or-later << 2 /* 1 /* 3 * Driver for Gravis UltraSound Classic sound 2 * Driver for Gravis UltraSound Classic soundcard 4 * Copyright (c) by Jaroslav Kysela <perex@pe 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 * 5 */ 20 */ 6 21 7 #include <linux/init.h> 22 #include <linux/init.h> 8 #include <linux/err.h> 23 #include <linux/err.h> 9 #include <linux/isa.h> 24 #include <linux/isa.h> 10 #include <linux/delay.h> 25 #include <linux/delay.h> 11 #include <linux/time.h> 26 #include <linux/time.h> 12 #include <linux/module.h> 27 #include <linux/module.h> 13 #include <asm/dma.h> 28 #include <asm/dma.h> 14 #include <sound/core.h> 29 #include <sound/core.h> 15 #include <sound/gus.h> 30 #include <sound/gus.h> 16 #define SNDRV_LEGACY_FIND_FREE_IRQ 31 #define SNDRV_LEGACY_FIND_FREE_IRQ 17 #define SNDRV_LEGACY_FIND_FREE_DMA 32 #define SNDRV_LEGACY_FIND_FREE_DMA 18 #include <sound/initval.h> 33 #include <sound/initval.h> 19 34 20 #define CRD_NAME "Gravis UltraSound Classic" 35 #define CRD_NAME "Gravis UltraSound Classic" 21 #define DEV_NAME "gusclassic" 36 #define DEV_NAME "gusclassic" 22 37 23 MODULE_DESCRIPTION(CRD_NAME); 38 MODULE_DESCRIPTION(CRD_NAME); 24 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz 39 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 25 MODULE_LICENSE("GPL"); 40 MODULE_LICENSE("GPL"); >> 41 MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Classic}}"); 26 42 27 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_ 43 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 28 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_S 44 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 29 static bool enable[SNDRV_CARDS] = SNDRV_DEFAUL 45 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ 30 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_ 46 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */ 31 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IR 47 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */ 32 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_D 48 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ 33 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_D 49 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ 34 static int joystick_dac[SNDRV_CARDS] = {[0 ... 50 static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; 35 /* 0 to 31, (0 51 /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ 36 static int channels[SNDRV_CARDS] = {[0 ... (SN 52 static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24}; 37 static int pcm_channels[SNDRV_CARDS] = {[0 ... 53 static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; 38 54 39 module_param_array(index, int, NULL, 0444); 55 module_param_array(index, int, NULL, 0444); 40 MODULE_PARM_DESC(index, "Index value for " CRD 56 MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); 41 module_param_array(id, charp, NULL, 0444); 57 module_param_array(id, charp, NULL, 0444); 42 MODULE_PARM_DESC(id, "ID string for " CRD_NAME 58 MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); 43 module_param_array(enable, bool, NULL, 0444); 59 module_param_array(enable, bool, NULL, 0444); 44 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " 60 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); 45 module_param_hw_array(port, long, ioport, NULL 61 module_param_hw_array(port, long, ioport, NULL, 0444); 46 MODULE_PARM_DESC(port, "Port # for " CRD_NAME 62 MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); 47 module_param_hw_array(irq, int, irq, NULL, 044 63 module_param_hw_array(irq, int, irq, NULL, 0444); 48 MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " 64 MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); 49 module_param_hw_array(dma1, int, dma, NULL, 04 65 module_param_hw_array(dma1, int, dma, NULL, 0444); 50 MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME 66 MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver."); 51 module_param_hw_array(dma2, int, dma, NULL, 04 67 module_param_hw_array(dma2, int, dma, NULL, 0444); 52 MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME 68 MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver."); 53 module_param_array(joystick_dac, int, NULL, 04 69 module_param_array(joystick_dac, int, NULL, 0444); 54 MODULE_PARM_DESC(joystick_dac, "Joystick DAC l 70 MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver."); 55 module_param_array(channels, int, NULL, 0444); 71 module_param_array(channels, int, NULL, 0444); 56 MODULE_PARM_DESC(channels, "GF1 channels for " 72 MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver."); 57 module_param_array(pcm_channels, int, NULL, 04 73 module_param_array(pcm_channels, int, NULL, 0444); 58 MODULE_PARM_DESC(pcm_channels, "Reserved PCM c 74 MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver."); 59 75 60 static int snd_gusclassic_match(struct device 76 static int snd_gusclassic_match(struct device *dev, unsigned int n) 61 { 77 { 62 return enable[n]; 78 return enable[n]; 63 } 79 } 64 80 65 static int snd_gusclassic_create(struct snd_ca 81 static int snd_gusclassic_create(struct snd_card *card, 66 struct device 82 struct device *dev, unsigned int n, 67 struct snd_gu 83 struct snd_gus_card **rgus) 68 { 84 { 69 static const long possible_ports[] = { !! 85 static long possible_ports[] = {0x220, 0x230, 0x240, 0x250, 0x260}; 70 static const int possible_irqs[] = {5, !! 86 static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, 4, -1}; 71 static const int possible_dmas[] = {5, !! 87 static int possible_dmas[] = {5, 6, 7, 1, 3, -1}; 72 88 73 int i, error; 89 int i, error; 74 90 75 if (irq[n] == SNDRV_AUTO_IRQ) { 91 if (irq[n] == SNDRV_AUTO_IRQ) { 76 irq[n] = snd_legacy_find_free_ 92 irq[n] = snd_legacy_find_free_irq(possible_irqs); 77 if (irq[n] < 0) { 93 if (irq[n] < 0) { 78 dev_err(dev, "unable t 94 dev_err(dev, "unable to find a free IRQ\n"); 79 return -EBUSY; 95 return -EBUSY; 80 } 96 } 81 } 97 } 82 if (dma1[n] == SNDRV_AUTO_DMA) { 98 if (dma1[n] == SNDRV_AUTO_DMA) { 83 dma1[n] = snd_legacy_find_free 99 dma1[n] = snd_legacy_find_free_dma(possible_dmas); 84 if (dma1[n] < 0) { 100 if (dma1[n] < 0) { 85 dev_err(dev, "unable t 101 dev_err(dev, "unable to find a free DMA1\n"); 86 return -EBUSY; 102 return -EBUSY; 87 } 103 } 88 } 104 } 89 if (dma2[n] == SNDRV_AUTO_DMA) { 105 if (dma2[n] == SNDRV_AUTO_DMA) { 90 dma2[n] = snd_legacy_find_free 106 dma2[n] = snd_legacy_find_free_dma(possible_dmas); 91 if (dma2[n] < 0) { 107 if (dma2[n] < 0) { 92 dev_err(dev, "unable t 108 dev_err(dev, "unable to find a free DMA2\n"); 93 return -EBUSY; 109 return -EBUSY; 94 } 110 } 95 } 111 } 96 112 97 if (port[n] != SNDRV_AUTO_PORT) 113 if (port[n] != SNDRV_AUTO_PORT) 98 return snd_gus_create(card, po 114 return snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n], 99 0, channels[n] 115 0, channels[n], pcm_channels[n], 0, rgus); 100 116 101 i = 0; 117 i = 0; 102 do { 118 do { 103 port[n] = possible_ports[i]; 119 port[n] = possible_ports[i]; 104 error = snd_gus_create(card, p 120 error = snd_gus_create(card, port[n], irq[n], dma1[n], dma2[n], 105 0, channels[n] 121 0, channels[n], pcm_channels[n], 0, rgus); 106 } while (error < 0 && ++i < ARRAY_SIZE 122 } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); 107 123 108 return error; 124 return error; 109 } 125 } 110 126 111 static int snd_gusclassic_detect(struct snd_gu 127 static int snd_gusclassic_detect(struct snd_gus_card *gus) 112 { 128 { 113 unsigned char d; 129 unsigned char d; 114 130 115 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RES 131 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */ 116 d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_ !! 132 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) { 117 if ((d & 0x07) != 0) { !! 133 snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d); 118 dev_dbg(gus->card->dev, "[0x%l << 119 return -ENODEV; 134 return -ENODEV; 120 } 135 } 121 udelay(160); 136 udelay(160); 122 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RES 137 snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */ 123 udelay(160); 138 udelay(160); 124 d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_ !! 139 if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) { 125 if ((d & 0x07) != 1) { !! 140 snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d); 126 dev_dbg(gus->card->dev, "[0x%l << 127 return -ENODEV; 141 return -ENODEV; 128 } 142 } 129 return 0; 143 return 0; 130 } 144 } 131 145 132 static int snd_gusclassic_probe(struct device 146 static int snd_gusclassic_probe(struct device *dev, unsigned int n) 133 { 147 { 134 struct snd_card *card; 148 struct snd_card *card; 135 struct snd_gus_card *gus; 149 struct snd_gus_card *gus; 136 int error; 150 int error; 137 151 138 error = snd_devm_card_new(dev, index[n !! 152 error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); 139 if (error < 0) 153 if (error < 0) 140 return error; 154 return error; 141 155 142 if (pcm_channels[n] < 2) 156 if (pcm_channels[n] < 2) 143 pcm_channels[n] = 2; 157 pcm_channels[n] = 2; 144 158 145 error = snd_gusclassic_create(card, de 159 error = snd_gusclassic_create(card, dev, n, &gus); 146 if (error < 0) 160 if (error < 0) 147 return error; !! 161 goto out; 148 162 149 error = snd_gusclassic_detect(gus); 163 error = snd_gusclassic_detect(gus); 150 if (error < 0) 164 if (error < 0) 151 return error; !! 165 goto out; 152 166 153 gus->joystick_dac = joystick_dac[n]; 167 gus->joystick_dac = joystick_dac[n]; 154 168 155 error = snd_gus_initialize(gus); 169 error = snd_gus_initialize(gus); 156 if (error < 0) 170 if (error < 0) 157 return error; !! 171 goto out; 158 172 159 error = -ENODEV; 173 error = -ENODEV; 160 if (gus->max_flag || gus->ess_flag) { 174 if (gus->max_flag || gus->ess_flag) { 161 dev_err(dev, "GUS Classic or A 175 dev_err(dev, "GUS Classic or ACE soundcard was " 162 "not detected at 0x%lx 176 "not detected at 0x%lx\n", gus->gf1.port); 163 return error; !! 177 goto out; 164 } 178 } 165 179 166 error = snd_gf1_new_mixer(gus); 180 error = snd_gf1_new_mixer(gus); 167 if (error < 0) 181 if (error < 0) 168 return error; !! 182 goto out; 169 183 170 error = snd_gf1_pcm_new(gus, 0, 0); 184 error = snd_gf1_pcm_new(gus, 0, 0); 171 if (error < 0) 185 if (error < 0) 172 return error; !! 186 goto out; 173 187 174 if (!gus->ace_flag) { 188 if (!gus->ace_flag) { 175 error = snd_gf1_rawmidi_new(gu 189 error = snd_gf1_rawmidi_new(gus, 0); 176 if (error < 0) 190 if (error < 0) 177 return error; !! 191 goto out; 178 } 192 } 179 193 180 sprintf(card->longname + strlen(card-> 194 sprintf(card->longname + strlen(card->longname), 181 " at 0x%lx, irq %d, dma %d", 195 " at 0x%lx, irq %d, dma %d", 182 gus->gf1.port, gus->gf1.irq, g 196 gus->gf1.port, gus->gf1.irq, gus->gf1.dma1); 183 197 184 if (gus->gf1.dma2 >= 0) 198 if (gus->gf1.dma2 >= 0) 185 sprintf(card->longname + strle 199 sprintf(card->longname + strlen(card->longname), 186 "&%d", gus->gf1.dma2); 200 "&%d", gus->gf1.dma2); 187 201 188 error = snd_card_register(card); 202 error = snd_card_register(card); 189 if (error < 0) 203 if (error < 0) 190 return error; !! 204 goto out; 191 205 192 dev_set_drvdata(dev, card); 206 dev_set_drvdata(dev, card); 193 return 0; 207 return 0; >> 208 >> 209 out: snd_card_free(card); >> 210 return error; >> 211 } >> 212 >> 213 static int snd_gusclassic_remove(struct device *dev, unsigned int n) >> 214 { >> 215 snd_card_free(dev_get_drvdata(dev)); >> 216 return 0; 194 } 217 } 195 218 196 static struct isa_driver snd_gusclassic_driver 219 static struct isa_driver snd_gusclassic_driver = { 197 .match = snd_gusclassic_match 220 .match = snd_gusclassic_match, 198 .probe = snd_gusclassic_probe 221 .probe = snd_gusclassic_probe, >> 222 .remove = snd_gusclassic_remove, 199 #if 0 /* FIXME */ 223 #if 0 /* FIXME */ 200 .suspend = snd_gusclassic_suspe 224 .suspend = snd_gusclassic_suspend, >> 225 .remove = snd_gusclassic_remove, 201 #endif 226 #endif 202 .driver = { 227 .driver = { 203 .name = DEV_NAME 228 .name = DEV_NAME 204 } 229 } 205 }; 230 }; 206 231 207 module_isa_driver(snd_gusclassic_driver, SNDRV 232 module_isa_driver(snd_gusclassic_driver, SNDRV_CARDS); 208 233
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.