Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Gravis UltraSound Extreme soundcards |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 23 | #include <linux/err.h> |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 24 | #include <linux/isa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <linux/delay.h> |
| 26 | #include <linux/time.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 28 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <sound/core.h> |
| 30 | #include <sound/gus.h> |
| 31 | #include <sound/es1688.h> |
| 32 | #include <sound/mpu401.h> |
| 33 | #include <sound/opl3.h> |
| 34 | #define SNDRV_LEGACY_AUTO_PROBE |
| 35 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 36 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 37 | #include <sound/initval.h> |
| 38 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 39 | #define CRD_NAME "Gravis UltraSound Extreme" |
| 40 | #define DEV_NAME "gusextreme" |
| 41 | |
| 42 | MODULE_DESCRIPTION(CRD_NAME); |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 43 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | MODULE_LICENSE("GPL"); |
| 45 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Extreme}}"); |
| 46 | |
| 47 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 48 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 49 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ |
| 51 | static long gf1_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x210,0x220,0x230,0x240,0x250,0x260,0x270 */ |
| 52 | static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS) - 1] = -1}; /* 0x300,0x310,0x320 */ |
| 53 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 54 | static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 55 | static int gf1_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */ |
| 56 | static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 57 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; |
| 58 | static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; |
| 59 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ |
| 60 | static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24}; |
| 61 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; |
| 62 | |
| 63 | module_param_array(index, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 64 | MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | module_param_array(id, charp, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 66 | MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | module_param_array(enable, bool, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 68 | MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | module_param_array(port, long, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 70 | MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | module_param_array(gf1_port, long, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 72 | MODULE_PARM_DESC(gf1_port, "GF1 port # for " CRD_NAME " driver (optional)."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | module_param_array(mpu_port, long, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 74 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | module_param_array(irq, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 76 | MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | module_param_array(mpu_irq, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 78 | MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | module_param_array(gf1_irq, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 80 | MODULE_PARM_DESC(gf1_irq, "GF1 IRQ # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | module_param_array(dma8, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 82 | MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | module_param_array(dma1, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 84 | MODULE_PARM_DESC(dma1, "GF1 DMA # for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | module_param_array(joystick_dac, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 86 | 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] | 87 | module_param_array(channels, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 88 | MODULE_PARM_DESC(channels, "GF1 channels for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | module_param_array(pcm_channels, int, NULL, 0444); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 90 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for " CRD_NAME " driver."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 92 | static int snd_gusextreme_match(struct device *dev, unsigned int n) |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 93 | { |
| 94 | return enable[n]; |
| 95 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 96 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 97 | static int snd_gusextreme_es1688_create(struct snd_card *card, |
| 98 | struct snd_es1688 *chip, |
| 99 | struct device *dev, unsigned int n) |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 100 | { |
| 101 | static long possible_ports[] = {0x220, 0x240, 0x260}; |
| 102 | static int possible_irqs[] = {5, 9, 10, 7, -1}; |
| 103 | static int possible_dmas[] = {1, 3, 0, -1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 105 | int i, error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 107 | if (irq[n] == SNDRV_AUTO_IRQ) { |
| 108 | irq[n] = snd_legacy_find_free_irq(possible_irqs); |
| 109 | if (irq[n] < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 110 | dev_err(dev, "unable to find a free IRQ for ES1688\n"); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 111 | return -EBUSY; |
| 112 | } |
| 113 | } |
| 114 | if (dma8[n] == SNDRV_AUTO_DMA) { |
| 115 | dma8[n] = snd_legacy_find_free_dma(possible_dmas); |
| 116 | if (dma8[n] < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 117 | dev_err(dev, "unable to find a free DMA for ES1688\n"); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 118 | return -EBUSY; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | if (port[n] != SNDRV_AUTO_PORT) |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 123 | return snd_es1688_create(card, chip, port[n], mpu_port[n], |
| 124 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 125 | |
| 126 | i = 0; |
| 127 | do { |
| 128 | port[n] = possible_ports[i]; |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 129 | error = snd_es1688_create(card, chip, port[n], mpu_port[n], |
| 130 | irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 131 | } while (error < 0 && ++i < ARRAY_SIZE(possible_ports)); |
| 132 | |
| 133 | return error; |
| 134 | } |
| 135 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 136 | static int snd_gusextreme_gus_card_create(struct snd_card *card, |
| 137 | struct device *dev, unsigned int n, |
| 138 | struct snd_gus_card **rgus) |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 139 | { |
| 140 | static int possible_irqs[] = {11, 12, 15, 9, 5, 7, 3, -1}; |
| 141 | static int possible_dmas[] = {5, 6, 7, 3, 1, -1}; |
| 142 | |
| 143 | if (gf1_irq[n] == SNDRV_AUTO_IRQ) { |
| 144 | gf1_irq[n] = snd_legacy_find_free_irq(possible_irqs); |
| 145 | if (gf1_irq[n] < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 146 | dev_err(dev, "unable to find a free IRQ for GF1\n"); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 147 | return -EBUSY; |
| 148 | } |
| 149 | } |
| 150 | if (dma1[n] == SNDRV_AUTO_DMA) { |
| 151 | dma1[n] = snd_legacy_find_free_dma(possible_dmas); |
| 152 | if (dma1[n] < 0) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 153 | dev_err(dev, "unable to find a free DMA for GF1\n"); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 154 | return -EBUSY; |
| 155 | } |
| 156 | } |
| 157 | return snd_gus_create(card, gf1_port[n], gf1_irq[n], dma1[n], -1, |
| 158 | 0, channels[n], pcm_channels[n], 0, rgus); |
| 159 | } |
| 160 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 161 | static int snd_gusextreme_detect(struct snd_gus_card *gus, |
| 162 | struct snd_es1688 *es1688) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | { |
| 164 | unsigned long flags; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 165 | unsigned char d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * This is main stuff - enable access to GF1 chip... |
| 169 | * I'm not sure, if this will work for card which have |
| 170 | * ES1688 chip in another place than 0x220. |
| 171 | * |
| 172 | * I used reverse-engineering in DOSEMU. [--jk] |
| 173 | * |
| 174 | * ULTRINIT.EXE: |
| 175 | * 0x230 = 0,2,3 |
| 176 | * 0x240 = 2,0,1 |
| 177 | * 0x250 = 2,0,3 |
| 178 | * 0x260 = 2,2,1 |
| 179 | */ |
| 180 | |
| 181 | spin_lock_irqsave(&es1688->mixer_lock, flags); |
| 182 | snd_es1688_mixer_write(es1688, 0x40, 0x0b); /* don't change!!! */ |
| 183 | spin_unlock_irqrestore(&es1688->mixer_lock, flags); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | spin_lock_irqsave(&es1688->reg_lock, flags); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 186 | outb(gus->gf1.port & 0x040 ? 2 : 0, ES1688P(es1688, INIT1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | outb(0, 0x201); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 188 | outb(gus->gf1.port & 0x020 ? 2 : 0, ES1688P(es1688, INIT1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | outb(0, 0x201); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 190 | outb(gus->gf1.port & 0x010 ? 3 : 1, ES1688P(es1688, INIT1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | spin_unlock_irqrestore(&es1688->reg_lock, flags); |
| 192 | |
| 193 | udelay(100); |
| 194 | |
| 195 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */ |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 196 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) { |
| 197 | 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] | 198 | return -EIO; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 199 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | udelay(160); |
| 201 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */ |
| 202 | udelay(160); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 203 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) { |
| 204 | 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] | 205 | return -EIO; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 208 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 211 | static int snd_gusextreme_mixer(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 213 | struct snd_ctl_elem_id id1, id2; |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 214 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | memset(&id1, 0, sizeof(id1)); |
| 217 | memset(&id2, 0, sizeof(id2)); |
| 218 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | /* reassign AUX to SYNTHESIZER */ |
| 221 | strcpy(id1.name, "Aux Playback Volume"); |
| 222 | strcpy(id2.name, "Synth Playback Volume"); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 223 | error = snd_ctl_rename_id(card, &id1, &id2); |
| 224 | if (error < 0) |
| 225 | return error; |
| 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* reassign Master Playback Switch to Synth Playback Switch */ |
| 228 | strcpy(id1.name, "Master Playback Switch"); |
| 229 | strcpy(id2.name, "Synth Playback Switch"); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 230 | error = snd_ctl_rename_id(card, &id1, &id2); |
| 231 | if (error < 0) |
| 232 | return error; |
| 233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return 0; |
| 235 | } |
| 236 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 237 | static int snd_gusextreme_probe(struct device *dev, unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 239 | struct snd_card *card; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 240 | struct snd_gus_card *gus; |
| 241 | struct snd_es1688 *es1688; |
| 242 | struct snd_opl3 *opl3; |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 243 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Takashi Iwai | 4323cc4 | 2014-01-29 13:03:56 +0100 | [diff] [blame] | 245 | error = snd_card_new(dev, index[n], id[n], THIS_MODULE, |
| 246 | sizeof(struct snd_es1688), &card); |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 247 | if (error < 0) |
| 248 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 250 | es1688 = card->private_data; |
| 251 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 252 | if (mpu_port[n] == SNDRV_AUTO_PORT) |
| 253 | mpu_port[n] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 255 | if (mpu_irq[n] > 15) |
| 256 | mpu_irq[n] = -1; |
| 257 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 258 | error = snd_gusextreme_es1688_create(card, es1688, dev, n); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 259 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | goto out; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 261 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 262 | if (gf1_port[n] < 0) |
| 263 | gf1_port[n] = es1688->port + 0x20; |
| 264 | |
| 265 | error = snd_gusextreme_gus_card_create(card, dev, n, &gus); |
| 266 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | goto out; |
| 268 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 269 | error = snd_gusextreme_detect(gus, es1688); |
| 270 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | goto out; |
| 272 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 273 | gus->joystick_dac = joystick_dac[n]; |
| 274 | |
| 275 | error = snd_gus_initialize(gus); |
| 276 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | goto out; |
| 278 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 279 | error = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (!gus->ess_flag) { |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 281 | dev_err(dev, "GUS Extreme soundcard was not " |
| 282 | "detected at 0x%lx\n", gus->gf1.port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | goto out; |
| 284 | } |
Rene Herman | 442f4f3 | 2007-02-19 13:07:50 +0100 | [diff] [blame] | 285 | gus->codec_flag = 1; |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 286 | |
Lars-Peter Clausen | 4b8ab88 | 2015-01-02 12:24:37 +0100 | [diff] [blame] | 287 | error = snd_es1688_pcm(card, es1688, 0); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 288 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | goto out; |
| 290 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 291 | error = snd_es1688_mixer(card, es1688); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 292 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | goto out; |
| 294 | |
| 295 | snd_component_add(card, "ES1688"); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 296 | |
| 297 | if (pcm_channels[n] > 0) { |
Lars-Peter Clausen | db5abb3 | 2015-01-02 12:24:39 +0100 | [diff] [blame] | 298 | error = snd_gf1_pcm_new(gus, 1, 1); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 299 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | goto out; |
| 301 | } |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 302 | |
| 303 | error = snd_gf1_new_mixer(gus); |
| 304 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | goto out; |
| 306 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 307 | error = snd_gusextreme_mixer(card); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 308 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | goto out; |
| 310 | |
| 311 | if (snd_opl3_create(card, es1688->port, es1688->port + 2, |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 312 | OPL3_HW_OPL3, 0, &opl3) < 0) |
Takashi Iwai | 0418ff0 | 2008-11-03 08:51:33 +0100 | [diff] [blame] | 313 | dev_warn(dev, "opl3 not detected at 0x%lx\n", es1688->port); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 314 | else { |
| 315 | error = snd_opl3_hwdep_new(opl3, 0, 2, NULL); |
| 316 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | goto out; |
| 318 | } |
| 319 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 320 | if (es1688->mpu_port >= 0x300) { |
| 321 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, |
Clemens Ladisch | dba8b46 | 2011-09-13 11:24:41 +0200 | [diff] [blame] | 322 | es1688->mpu_port, 0, mpu_irq[n], NULL); |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 323 | if (error < 0) |
| 324 | goto out; |
| 325 | } |
| 326 | |
| 327 | sprintf(card->longname, "Gravis UltraSound Extreme at 0x%lx, " |
| 328 | "irq %i&%i, dma %i&%i", es1688->port, |
| 329 | gus->gf1.irq, es1688->irq, gus->gf1.dma1, es1688->dma8); |
| 330 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 331 | error = snd_card_register(card); |
| 332 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | goto out; |
| 334 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 335 | dev_set_drvdata(dev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | return 0; |
| 337 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 338 | out: snd_card_free(card); |
| 339 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 342 | static int snd_gusextreme_remove(struct device *dev, unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | { |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 344 | snd_card_free(dev_get_drvdata(dev)); |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 345 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 348 | static struct isa_driver snd_gusextreme_driver = { |
| 349 | .match = snd_gusextreme_match, |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 350 | .probe = snd_gusextreme_probe, |
Bill Pemberton | 1bff292 | 2012-12-06 12:35:21 -0500 | [diff] [blame] | 351 | .remove = snd_gusextreme_remove, |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 352 | #if 0 /* FIXME */ |
| 353 | .suspend = snd_gusextreme_suspend, |
| 354 | .resume = snd_gusextreme_resume, |
| 355 | #endif |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 356 | .driver = { |
Rene Herman | b44dfe1 | 2007-02-19 13:07:17 +0100 | [diff] [blame] | 357 | .name = DEV_NAME |
| 358 | } |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 359 | }; |
| 360 | |
William Breathitt Gray | bfc7e0f | 2016-05-31 11:55:58 -0400 | [diff] [blame] | 361 | module_isa_driver(snd_gusextreme_driver, SNDRV_CARDS); |