Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Gravis UltraSound MAX soundcard |
| 3 | * Copyright (c) by Jaroslav Kysela <perex@suse.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 <sound/driver.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 24 | #include <linux/err.h> |
| 25 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include <linux/time.h> |
| 28 | #include <linux/moduleparam.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 29 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <sound/core.h> |
| 31 | #include <sound/gus.h> |
| 32 | #include <sound/cs4231.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 34 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 35 | #include <sound/initval.h> |
| 36 | |
| 37 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
| 38 | MODULE_DESCRIPTION("Gravis UltraSound MAX"); |
| 39 | MODULE_LICENSE("GPL"); |
| 40 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound MAX}}"); |
| 41 | |
| 42 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 43 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 44 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ |
| 45 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x230,0x240,0x250,0x260 */ |
| 46 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */ |
| 47 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ |
| 48 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ |
| 49 | static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; |
| 50 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ |
| 51 | static int channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 24}; |
| 52 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; |
| 53 | |
| 54 | module_param_array(index, int, NULL, 0444); |
| 55 | MODULE_PARM_DESC(index, "Index value for GUS MAX soundcard."); |
| 56 | module_param_array(id, charp, NULL, 0444); |
| 57 | MODULE_PARM_DESC(id, "ID string for GUS MAX soundcard."); |
| 58 | module_param_array(enable, bool, NULL, 0444); |
| 59 | MODULE_PARM_DESC(enable, "Enable GUS MAX soundcard."); |
| 60 | module_param_array(port, long, NULL, 0444); |
| 61 | MODULE_PARM_DESC(port, "Port # for GUS MAX driver."); |
| 62 | module_param_array(irq, int, NULL, 0444); |
| 63 | MODULE_PARM_DESC(irq, "IRQ # for GUS MAX driver."); |
| 64 | module_param_array(dma1, int, NULL, 0444); |
| 65 | MODULE_PARM_DESC(dma1, "DMA1 # for GUS MAX driver."); |
| 66 | module_param_array(dma2, int, NULL, 0444); |
| 67 | MODULE_PARM_DESC(dma2, "DMA2 # for GUS MAX driver."); |
| 68 | module_param_array(joystick_dac, int, NULL, 0444); |
| 69 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for GUS MAX driver."); |
| 70 | module_param_array(channels, int, NULL, 0444); |
| 71 | MODULE_PARM_DESC(channels, "Used GF1 channels for GUS MAX driver."); |
| 72 | module_param_array(pcm_channels, int, NULL, 0444); |
| 73 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for GUS MAX driver."); |
| 74 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 75 | static struct platform_device *devices[SNDRV_CARDS]; |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | struct snd_gusmax { |
| 78 | int irq; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 79 | struct snd_card *card; |
| 80 | struct snd_gus_card *gus; |
| 81 | struct snd_cs4231 *cs4231; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | unsigned short gus_status_reg; |
| 83 | unsigned short pcm_status_reg; |
| 84 | }; |
| 85 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 86 | #define PFX "gusmax: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 88 | static int __devinit snd_gusmax_detect(struct snd_gus_card * gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 90 | unsigned char d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 92 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */ |
| 93 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) { |
| 94 | 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] | 95 | return -ENODEV; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 96 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | udelay(160); |
| 98 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */ |
| 99 | udelay(160); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 100 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) { |
| 101 | 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] | 102 | return -ENODEV; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 103 | } |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 108 | static irqreturn_t snd_gusmax_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { |
Jeff Garzik | c7bec5a | 2006-10-06 15:00:58 -0400 | [diff] [blame] | 110 | struct snd_gusmax *maxcard = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int loop, max = 5; |
| 112 | int handled = 0; |
| 113 | |
| 114 | do { |
| 115 | loop = 0; |
| 116 | if (inb(maxcard->gus_status_reg)) { |
| 117 | handled = 1; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 118 | snd_gus_interrupt(irq, maxcard->gus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | loop++; |
| 120 | } |
| 121 | if (inb(maxcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */ |
| 122 | handled = 1; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 123 | snd_cs4231_interrupt(irq, maxcard->cs4231); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | loop++; |
| 125 | } |
| 126 | } while (loop && --max > 0); |
| 127 | return IRQ_RETVAL(handled); |
| 128 | } |
| 129 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 130 | static void __devinit snd_gusmax_init(int dev, struct snd_card *card, |
| 131 | struct snd_gus_card * gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
| 133 | gus->equal_irq = 1; |
| 134 | gus->codec_flag = 1; |
| 135 | gus->joystick_dac = joystick_dac[dev]; |
| 136 | /* init control register */ |
| 137 | gus->max_cntrl_val = (gus->gf1.port >> 4) & 0x0f; |
| 138 | if (gus->gf1.dma1 > 3) |
| 139 | gus->max_cntrl_val |= 0x10; |
| 140 | if (gus->gf1.dma2 > 3) |
| 141 | gus->max_cntrl_val |= 0x20; |
| 142 | gus->max_cntrl_val |= 0x40; |
| 143 | outb(gus->max_cntrl_val, GUSP(gus, MAXCNTRLPORT)); |
| 144 | } |
| 145 | |
| 146 | #define CS4231_PRIVATE( left, right, shift, mute ) \ |
| 147 | ((left << 24)|(right << 16)|(shift<<8)|mute) |
| 148 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 149 | static int __devinit snd_gusmax_mixer(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 151 | struct snd_card *card = chip->card; |
| 152 | struct snd_ctl_elem_id id1, id2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | int err; |
| 154 | |
| 155 | memset(&id1, 0, sizeof(id1)); |
| 156 | memset(&id2, 0, sizeof(id2)); |
| 157 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 158 | /* reassign AUXA to SYNTHESIZER */ |
| 159 | strcpy(id1.name, "Aux Playback Switch"); |
| 160 | strcpy(id2.name, "Synth Playback Switch"); |
| 161 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 162 | return err; |
| 163 | strcpy(id1.name, "Aux Playback Volume"); |
| 164 | strcpy(id2.name, "Synth Playback Volume"); |
| 165 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 166 | return err; |
| 167 | /* reassign AUXB to CD */ |
| 168 | strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; |
| 169 | strcpy(id2.name, "CD Playback Switch"); |
| 170 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 171 | return err; |
| 172 | strcpy(id1.name, "Aux Playback Volume"); |
| 173 | strcpy(id2.name, "CD Playback Volume"); |
| 174 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 175 | return err; |
| 176 | #if 0 |
| 177 | /* reassign Mono Input to MIC */ |
| 178 | if (snd_mixer_group_rename(mixer, |
| 179 | SNDRV_MIXER_IN_MONO, 0, |
| 180 | SNDRV_MIXER_IN_MIC, 0) < 0) |
| 181 | goto __error; |
| 182 | if (snd_mixer_elem_rename(mixer, |
| 183 | SNDRV_MIXER_IN_MONO, 0, SNDRV_MIXER_ETYPE_INPUT, |
| 184 | SNDRV_MIXER_IN_MIC, 0) < 0) |
| 185 | goto __error; |
| 186 | if (snd_mixer_elem_rename(mixer, |
| 187 | "Mono Capture Volume", 0, SNDRV_MIXER_ETYPE_VOLUME1, |
| 188 | "Mic Capture Volume", 0) < 0) |
| 189 | goto __error; |
| 190 | if (snd_mixer_elem_rename(mixer, |
| 191 | "Mono Capture Switch", 0, SNDRV_MIXER_ETYPE_SWITCH1, |
| 192 | "Mic Capture Switch", 0) < 0) |
| 193 | goto __error; |
| 194 | #endif |
| 195 | return 0; |
| 196 | } |
| 197 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 198 | static void snd_gusmax_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | struct snd_gusmax *maxcard = (struct snd_gusmax *)card->private_data; |
| 201 | |
| 202 | if (maxcard == NULL) |
| 203 | return; |
| 204 | if (maxcard->irq >= 0) |
| 205 | free_irq(maxcard->irq, (void *)maxcard); |
| 206 | } |
| 207 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 208 | static int __devinit snd_gusmax_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 210 | int dev = pdev->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1}; |
| 212 | static int possible_dmas[] = {5, 6, 7, 1, 3, -1}; |
| 213 | int xirq, xdma1, xdma2, err; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 214 | struct snd_card *card; |
| 215 | struct snd_gus_card *gus = NULL; |
| 216 | struct snd_cs4231 *cs4231; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | struct snd_gusmax *maxcard; |
| 218 | |
| 219 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 220 | sizeof(struct snd_gusmax)); |
| 221 | if (card == NULL) |
| 222 | return -ENOMEM; |
| 223 | card->private_free = snd_gusmax_free; |
| 224 | maxcard = (struct snd_gusmax *)card->private_data; |
| 225 | maxcard->card = card; |
| 226 | maxcard->irq = -1; |
| 227 | |
| 228 | xirq = irq[dev]; |
| 229 | if (xirq == SNDRV_AUTO_IRQ) { |
| 230 | if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 231 | snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); |
| 232 | err = -EBUSY; |
| 233 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | xdma1 = dma1[dev]; |
| 237 | if (xdma1 == SNDRV_AUTO_DMA) { |
| 238 | if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 239 | snd_printk(KERN_ERR PFX "unable to find a free DMA1\n"); |
| 240 | err = -EBUSY; |
| 241 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | xdma2 = dma2[dev]; |
| 245 | if (xdma2 == SNDRV_AUTO_DMA) { |
| 246 | if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 247 | snd_printk(KERN_ERR PFX "unable to find a free DMA2\n"); |
| 248 | err = -EBUSY; |
| 249 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 253 | if (port[dev] != SNDRV_AUTO_PORT) { |
| 254 | err = snd_gus_create(card, |
| 255 | port[dev], |
| 256 | -xirq, xdma1, xdma2, |
| 257 | 0, channels[dev], |
| 258 | pcm_channels[dev], |
| 259 | 0, &gus); |
| 260 | } else { |
| 261 | static unsigned long possible_ports[] = { |
| 262 | 0x220, 0x230, 0x240, 0x250, 0x260 |
| 263 | }; |
| 264 | int i; |
| 265 | for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { |
| 266 | err = snd_gus_create(card, |
| 267 | possible_ports[i], |
| 268 | -xirq, xdma1, xdma2, |
| 269 | 0, channels[dev], |
| 270 | pcm_channels[dev], |
| 271 | 0, &gus); |
| 272 | if (err >= 0) { |
| 273 | port[dev] = possible_ports[i]; |
| 274 | break; |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | if (err < 0) |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 279 | goto _err; |
| 280 | |
| 281 | if ((err = snd_gusmax_detect(gus)) < 0) |
| 282 | goto _err; |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | maxcard->gus_status_reg = gus->gf1.reg_irqstat; |
| 285 | maxcard->pcm_status_reg = gus->gf1.port + 0x10c + 2; |
| 286 | snd_gusmax_init(dev, card, gus); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 287 | if ((err = snd_gus_initialize(gus)) < 0) |
| 288 | goto _err; |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (!gus->max_flag) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 291 | snd_printk(KERN_ERR PFX "GUS MAX soundcard was not detected at 0x%lx\n", gus->gf1.port); |
| 292 | err = -ENODEV; |
| 293 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 296 | if (request_irq(xirq, snd_gusmax_interrupt, IRQF_DISABLED, "GUS MAX", (void *)maxcard)) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 297 | snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); |
| 298 | err = -EBUSY; |
| 299 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | maxcard->irq = xirq; |
| 302 | |
| 303 | if ((err = snd_cs4231_create(card, |
| 304 | gus->gf1.port + 0x10c, -1, xirq, |
| 305 | xdma2 < 0 ? xdma1 : xdma2, xdma1, |
| 306 | CS4231_HW_DETECT, |
| 307 | CS4231_HWSHARE_IRQ | |
| 308 | CS4231_HWSHARE_DMA1 | |
| 309 | CS4231_HWSHARE_DMA2, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 310 | &cs4231)) < 0) |
| 311 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 313 | if ((err = snd_cs4231_pcm(cs4231, 0, NULL)) < 0) |
| 314 | goto _err; |
| 315 | |
| 316 | if ((err = snd_cs4231_mixer(cs4231)) < 0) |
| 317 | goto _err; |
| 318 | |
| 319 | if ((err = snd_cs4231_timer(cs4231, 2, NULL)) < 0) |
| 320 | goto _err; |
| 321 | |
| 322 | if (pcm_channels[dev] > 0) { |
| 323 | if ((err = snd_gf1_pcm_new(gus, 1, 1, NULL)) < 0) |
| 324 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 326 | if ((err = snd_gusmax_mixer(cs4231)) < 0) |
| 327 | goto _err; |
| 328 | |
| 329 | if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) |
| 330 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | sprintf(card->longname + strlen(card->longname), " at 0x%lx, irq %i, dma %i", gus->gf1.port, xirq, xdma1); |
| 333 | if (xdma2 >= 0) |
| 334 | sprintf(card->longname + strlen(card->longname), "&%i", xdma2); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 335 | |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 336 | snd_card_set_dev(card, &pdev->dev); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 337 | |
| 338 | if ((err = snd_card_register(card)) < 0) |
| 339 | goto _err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | maxcard->gus = gus; |
| 342 | maxcard->cs4231 = cs4231; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 343 | |
| 344 | platform_set_drvdata(pdev, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return 0; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 346 | |
| 347 | _err: |
| 348 | snd_card_free(card); |
| 349 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 352 | static int __devexit snd_gusmax_remove(struct platform_device *devptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 354 | snd_card_free(platform_get_drvdata(devptr)); |
| 355 | platform_set_drvdata(devptr, NULL); |
| 356 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 359 | #define GUSMAX_DRIVER "snd_gusmax" |
| 360 | |
| 361 | static struct platform_driver snd_gusmax_driver = { |
| 362 | .probe = snd_gusmax_probe, |
Prarit Bhargava | 788c604 | 2007-02-13 13:11:11 +0100 | [diff] [blame] | 363 | .remove = __devexit_p(snd_gusmax_remove), |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 364 | /* FIXME: suspend/resume */ |
| 365 | .driver = { |
| 366 | .name = GUSMAX_DRIVER |
| 367 | }, |
| 368 | }; |
| 369 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 370 | static void __init_or_module snd_gusmax_unregister_all(void) |
| 371 | { |
| 372 | int i; |
| 373 | |
| 374 | for (i = 0; i < ARRAY_SIZE(devices); ++i) |
| 375 | platform_device_unregister(devices[i]); |
| 376 | platform_driver_unregister(&snd_gusmax_driver); |
| 377 | } |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | static int __init alsa_card_gusmax_init(void) |
| 380 | { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 381 | int i, cards, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 383 | err = platform_driver_register(&snd_gusmax_driver); |
| 384 | if (err < 0) |
| 385 | return err; |
| 386 | |
| 387 | cards = 0; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 388 | for (i = 0; i < SNDRV_CARDS; i++) { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 389 | struct platform_device *device; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 390 | if (! enable[i]) |
| 391 | continue; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 392 | device = platform_device_register_simple(GUSMAX_DRIVER, |
| 393 | i, NULL, 0); |
Rene Herman | d0ac642 | 2006-04-11 14:08:33 +0200 | [diff] [blame] | 394 | if (IS_ERR(device)) |
| 395 | continue; |
Rene Herman | dcccdd9 | 2006-04-11 14:09:37 +0200 | [diff] [blame] | 396 | if (!platform_get_drvdata(device)) { |
| 397 | platform_device_unregister(device); |
| 398 | continue; |
| 399 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 400 | devices[i] = device; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 401 | cards++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (!cards) { |
| 404 | #ifdef MODULE |
| 405 | printk(KERN_ERR "GUS MAX soundcard not found or device busy\n"); |
| 406 | #endif |
Rene Herman | d0ac642 | 2006-04-11 14:08:33 +0200 | [diff] [blame] | 407 | snd_gusmax_unregister_all(); |
| 408 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | static void __exit alsa_card_gusmax_exit(void) |
| 414 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 415 | snd_gusmax_unregister_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | module_init(alsa_card_gusmax_init) |
| 419 | module_exit(alsa_card_gusmax_exit) |