Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for Gravis UltraSound Classic soundcard |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 4 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/init.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 8 | #include <linux/err.h> |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 9 | #include <linux/isa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/delay.h> |
| 11 | #include <linux/time.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 12 | #include <linux/module.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 13 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <sound/core.h> |
| 15 | #include <sound/gus.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 17 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 18 | #include <sound/initval.h> |
| 19 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 20 | #define CRD_NAME "Gravis UltraSound Classic" |
| 21 | #define DEV_NAME "gusclassic" |
| 22 | |
| 23 | MODULE_DESCRIPTION(CRD_NAME); |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 24 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 28 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 29 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */ |
| 31 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 3,5,9,11,12,15 */ |
| 32 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ |
| 33 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ |
| 34 | static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; |
| 35 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ |
| 36 | static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24}; |
| 37 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; |
| 38 | |
| 39 | module_param_array(index, int, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 40 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | module_param_array(id, charp, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 42 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | module_param_array(enable, bool, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 44 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 45 | module_param_hw_array(port, long, ioport, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 46 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 47 | module_param_hw_array(irq, int, irq, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 48 | MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 49 | module_param_hw_array(dma1, int, dma, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 50 | MODULE_PARM_DESC(dma1, "DMA1 # for " CRD_NAME " driver."); |
David Howells | e992ef5 | 2017-04-04 16:54:30 +0100 | [diff] [blame] | 51 | module_param_hw_array(dma2, int, dma, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 52 | MODULE_PARM_DESC(dma2, "DMA2 # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | module_param_array(joystick_dac, int, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 54 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | module_param_array(channels, int, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 56 | MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | module_param_array(pcm_channels, int, NULL, 0444); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 58 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 60 | static int snd_gusclassic_match(struct device *dev, unsigned int n) |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 61 | { |
| 62 | return enable[n]; |
| 63 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 64 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 65 | static int snd_gusclassic_create(struct snd_card *card, |
| 66 | struct device *dev, unsigned int n, |
| 67 | struct snd_gus_card **rgus) |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 68 | { |
Takashi Iwai | 15a1af95 | 2020-01-05 15:48:04 +0100 | [diff] [blame] | 69 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 73 | int i, error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 75 | if (irq[n] == SNDRV_AUTO_IRQ) { |
| 76 | irq[n] = snd_legacy_find_free_irq(possible_irqs); |
| 77 | if (irq[n] < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 78 | dev_err(dev, "unable to find a free IRQ\n"); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 79 | 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 Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 85 | dev_err(dev, "unable to find a free DMA1\n"); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 86 | 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 Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 92 | dev_err(dev, "unable to find a free DMA2\n"); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 93 | 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 Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 111 | static int snd_gusclassic_detect(struct snd_gus_card *gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 113 | unsigned char d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 115 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */ |
Takashi Iwai | 310efd3 | 2021-06-08 16:04:38 +0200 | [diff] [blame] | 116 | d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET); |
| 117 | if ((d & 0x07) != 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 118 | snd_printdd("[0x%lx] check 1 failed - 0x%x\n", gus->gf1.port, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return -ENODEV; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | udelay(160); |
| 122 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */ |
| 123 | udelay(160); |
Takashi Iwai | 310efd3 | 2021-06-08 16:04:38 +0200 | [diff] [blame] | 124 | d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET); |
| 125 | if ((d & 0x07) != 1) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 126 | snd_printdd("[0x%lx] check 2 failed - 0x%x\n", gus->gf1.port, d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return -ENODEV; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 128 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return 0; |
| 130 | } |
| 131 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 132 | static int snd_gusclassic_probe(struct device *dev, unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 134 | struct snd_card *card; |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 135 | struct snd_gus_card *gus; |
| 136 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 138 | error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 139 | if (error < 0) |
| 140 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 142 | if (pcm_channels[n] < 2) |
| 143 | pcm_channels[n] = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 145 | error = snd_gusclassic_create(card, dev, n, &gus); |
| 146 | if (error < 0) |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 147 | return error; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 148 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 149 | error = snd_gusclassic_detect(gus); |
| 150 | if (error < 0) |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 151 | return error; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 152 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 153 | gus->joystick_dac = joystick_dac[n]; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 154 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 155 | error = snd_gus_initialize(gus); |
| 156 | if (error < 0) |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 157 | return error; |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 158 | |
| 159 | error = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | if (gus->max_flag || gus->ess_flag) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 161 | dev_err(dev, "GUS Classic or ACE soundcard was " |
| 162 | "not detected at 0x%lx\n", gus->gf1.port); |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 163 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 165 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 166 | error = snd_gf1_new_mixer(gus); |
| 167 | if (error < 0) |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 168 | return error; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 169 | |
Lars-Peter Clausen | db5abb3 | 2015-01-02 12:24:39 +0100 | [diff] [blame] | 170 | error = snd_gf1_pcm_new(gus, 0, 0); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 171 | if (error < 0) |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 172 | return error; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (!gus->ace_flag) { |
Lars-Peter Clausen | db5abb3 | 2015-01-02 12:24:39 +0100 | [diff] [blame] | 175 | error = snd_gf1_rawmidi_new(gus, 0); |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 176 | if (error < 0) |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 177 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 179 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 180 | 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 Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 183 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 184 | if (gus->gf1.dma2 >= 0) |
| 185 | sprintf(card->longname + strlen(card->longname), |
| 186 | "&%d", gus->gf1.dma2); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 187 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 188 | error = snd_card_register(card); |
| 189 | if (error < 0) |
Takashi Iwai | 5b88da3 | 2021-07-15 09:59:27 +0200 | [diff] [blame] | 190 | return error; |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 191 | |
| 192 | dev_set_drvdata(dev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 196 | static struct isa_driver snd_gusclassic_driver = { |
| 197 | .match = snd_gusclassic_match, |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 198 | .probe = snd_gusclassic_probe, |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 199 | #if 0 /* FIXME */ |
| 200 | .suspend = snd_gusclassic_suspend, |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 201 | #endif |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 202 | .driver = { |
Rene Herman | 93f02c6 | 2007-02-19 13:05:02 +0100 | [diff] [blame] | 203 | .name = DEV_NAME |
| 204 | } |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 205 | }; |
| 206 | |
William Breathitt Gray | a04236e | 2016-05-31 11:56:09 -0400 | [diff] [blame] | 207 | module_isa_driver(snd_gusclassic_driver, SNDRV_CARDS); |