Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for AMD InterWave 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 | * 1999/07/22 Erik Inge Bolso <knan@mo.himolde.no> |
| 21 | * * mixer group handlers |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <sound/driver.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 27 | #include <linux/err.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/slab.h> |
| 31 | #include <linux/pnp.h> |
| 32 | #include <linux/moduleparam.h> |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 33 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <sound/core.h> |
| 35 | #include <sound/gus.h> |
| 36 | #include <sound/cs4231.h> |
| 37 | #ifdef SNDRV_STB |
| 38 | #include <sound/tea6330t.h> |
| 39 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 41 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 42 | #include <sound/initval.h> |
| 43 | |
| 44 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | #ifndef SNDRV_STB |
| 47 | MODULE_DESCRIPTION("AMD InterWave"); |
| 48 | MODULE_SUPPORTED_DEVICE("{{Gravis,UltraSound Plug & Play}," |
| 49 | "{STB,SoundRage32}," |
| 50 | "{MED,MED3210}," |
| 51 | "{Dynasonix,Dynasonix Pro}," |
| 52 | "{Panasonic,PCA761AW}}"); |
| 53 | #else |
| 54 | MODULE_DESCRIPTION("AMD InterWave STB with TEA6330T"); |
| 55 | MODULE_SUPPORTED_DEVICE("{{AMD,InterWave STB with TEA6330T}}"); |
| 56 | #endif |
| 57 | |
| 58 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 59 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 60 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ |
| 61 | #ifdef CONFIG_PNP |
| 62 | static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; |
| 63 | #endif |
| 64 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x210,0x220,0x230,0x240,0x250,0x260 */ |
| 65 | #ifdef SNDRV_STB |
| 66 | static long port_tc[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x350,0x360,0x370,0x380 */ |
| 67 | #endif |
| 68 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,3,5,9,11,12,15 */ |
| 69 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ |
| 70 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */ |
| 71 | static int joystick_dac[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 29}; |
| 72 | /* 0 to 31, (0.59V-4.52V or 0.389V-2.98V) */ |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 73 | static int midi[SNDRV_CARDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 2}; |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 75 | static int effect[SNDRV_CARDS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 77 | #ifdef SNDRV_STB |
| 78 | #define PFX "interwave-stb: " |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 79 | #define INTERWAVE_DRIVER "snd_interwave_stb" |
| 80 | #define INTERWAVE_PNP_DRIVER "interwave-stb" |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 81 | #else |
| 82 | #define PFX "interwave: " |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 83 | #define INTERWAVE_DRIVER "snd_interwave" |
| 84 | #define INTERWAVE_PNP_DRIVER "interwave" |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 85 | #endif |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | module_param_array(index, int, NULL, 0444); |
| 88 | MODULE_PARM_DESC(index, "Index value for InterWave soundcard."); |
| 89 | module_param_array(id, charp, NULL, 0444); |
| 90 | MODULE_PARM_DESC(id, "ID string for InterWave soundcard."); |
| 91 | module_param_array(enable, bool, NULL, 0444); |
| 92 | MODULE_PARM_DESC(enable, "Enable InterWave soundcard."); |
| 93 | #ifdef CONFIG_PNP |
| 94 | module_param_array(isapnp, bool, NULL, 0444); |
| 95 | MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard."); |
| 96 | #endif |
| 97 | module_param_array(port, long, NULL, 0444); |
| 98 | MODULE_PARM_DESC(port, "Port # for InterWave driver."); |
| 99 | #ifdef SNDRV_STB |
| 100 | module_param_array(port_tc, long, NULL, 0444); |
| 101 | MODULE_PARM_DESC(port_tc, "Tone control (TEA6330T - i2c bus) port # for InterWave driver."); |
| 102 | #endif |
| 103 | module_param_array(irq, int, NULL, 0444); |
| 104 | MODULE_PARM_DESC(irq, "IRQ # for InterWave driver."); |
| 105 | module_param_array(dma1, int, NULL, 0444); |
| 106 | MODULE_PARM_DESC(dma1, "DMA1 # for InterWave driver."); |
| 107 | module_param_array(dma2, int, NULL, 0444); |
| 108 | MODULE_PARM_DESC(dma2, "DMA2 # for InterWave driver."); |
| 109 | module_param_array(joystick_dac, int, NULL, 0444); |
| 110 | MODULE_PARM_DESC(joystick_dac, "Joystick DAC level 0.59V-4.52V or 0.389V-2.98V for InterWave driver."); |
| 111 | module_param_array(midi, int, NULL, 0444); |
| 112 | MODULE_PARM_DESC(midi, "MIDI UART enable for InterWave driver."); |
| 113 | module_param_array(pcm_channels, int, NULL, 0444); |
| 114 | MODULE_PARM_DESC(pcm_channels, "Reserved PCM channels for InterWave driver."); |
| 115 | module_param_array(effect, int, NULL, 0444); |
| 116 | MODULE_PARM_DESC(effect, "Effects enable for InterWave driver."); |
| 117 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 118 | static struct platform_device *platform_devices[SNDRV_CARDS]; |
| 119 | static int pnp_registered; |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | struct snd_interwave { |
| 122 | int irq; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 123 | struct snd_card *card; |
| 124 | struct snd_gus_card *gus; |
| 125 | struct snd_cs4231 *cs4231; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | #ifdef SNDRV_STB |
| 127 | struct resource *i2c_res; |
| 128 | #endif |
| 129 | unsigned short gus_status_reg; |
| 130 | unsigned short pcm_status_reg; |
| 131 | #ifdef CONFIG_PNP |
| 132 | struct pnp_dev *dev; |
| 133 | #ifdef SNDRV_STB |
| 134 | struct pnp_dev *devtc; |
| 135 | #endif |
| 136 | #endif |
| 137 | }; |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | #ifdef CONFIG_PNP |
| 141 | |
| 142 | static struct pnp_card_device_id snd_interwave_pnpids[] = { |
| 143 | #ifndef SNDRV_STB |
| 144 | /* Gravis UltraSound Plug & Play */ |
| 145 | { .id = "GRV0001", .devs = { { .id = "GRV0000" } } }, |
| 146 | /* STB SoundRage32 */ |
| 147 | { .id = "STB011a", .devs = { { .id = "STB0010" } } }, |
| 148 | /* MED3210 */ |
| 149 | { .id = "DXP3201", .devs = { { .id = "DXP0010" } } }, |
| 150 | /* Dynasonic Pro */ |
| 151 | /* This device also have CDC1117:DynaSonix Pro Audio Effects Processor */ |
| 152 | { .id = "CDC1111", .devs = { { .id = "CDC1112" } } }, |
| 153 | /* Panasonic PCA761AW Audio Card */ |
| 154 | { .id = "ADV55ff", .devs = { { .id = "ADV0010" } } }, |
| 155 | /* InterWave STB without TEA6330T */ |
| 156 | { .id = "ADV550a", .devs = { { .id = "ADV0010" } } }, |
| 157 | #else |
| 158 | /* InterWave STB with TEA6330T */ |
| 159 | { .id = "ADV550a", .devs = { { .id = "ADV0010" }, { .id = "ADV0015" } } }, |
| 160 | #endif |
| 161 | { .id = "" } |
| 162 | }; |
| 163 | |
| 164 | MODULE_DEVICE_TABLE(pnp_card, snd_interwave_pnpids); |
| 165 | |
| 166 | #endif /* CONFIG_PNP */ |
| 167 | |
| 168 | |
| 169 | #ifdef SNDRV_STB |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 170 | static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | unsigned long port = bus->private_value; |
| 173 | |
| 174 | #if 0 |
| 175 | printk("i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data); |
| 176 | #endif |
| 177 | outb((data << 1) | ctrl, port); |
| 178 | udelay(10); |
| 179 | } |
| 180 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 181 | static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
| 183 | unsigned long port = bus->private_value; |
| 184 | unsigned char res; |
| 185 | |
| 186 | res = inb(port) & 1; |
| 187 | #if 0 |
| 188 | printk("i2c_getclockline - 0x%lx -> %i\n", port, res); |
| 189 | #endif |
| 190 | return res; |
| 191 | } |
| 192 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 193 | static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | unsigned long port = bus->private_value; |
| 196 | unsigned char res; |
| 197 | |
| 198 | if (ack) |
| 199 | udelay(10); |
| 200 | res = (inb(port) & 2) >> 1; |
| 201 | #if 0 |
| 202 | printk("i2c_getdataline - 0x%lx -> %i\n", port, res); |
| 203 | #endif |
| 204 | return res; |
| 205 | } |
| 206 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 207 | static struct snd_i2c_bit_ops snd_interwave_i2c_bit_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | .setlines = snd_interwave_i2c_setlines, |
| 209 | .getclock = snd_interwave_i2c_getclockline, |
| 210 | .getdata = snd_interwave_i2c_getdataline, |
| 211 | }; |
| 212 | |
| 213 | static int __devinit snd_interwave_detect_stb(struct snd_interwave *iwcard, |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 214 | struct snd_gus_card * gus, int dev, |
| 215 | struct snd_i2c_bus **rbus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
| 217 | unsigned long port; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 218 | struct snd_i2c_bus *bus; |
| 219 | struct snd_card *card = iwcard->card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | char name[32]; |
| 221 | int err; |
| 222 | |
| 223 | *rbus = NULL; |
| 224 | port = port_tc[dev]; |
| 225 | if (port == SNDRV_AUTO_PORT) { |
| 226 | port = 0x350; |
| 227 | if (gus->gf1.port == 0x250) { |
| 228 | port = 0x360; |
| 229 | } |
| 230 | while (port <= 0x380) { |
| 231 | if ((iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)")) != NULL) |
| 232 | break; |
| 233 | port += 0x10; |
| 234 | } |
| 235 | } else { |
| 236 | iwcard->i2c_res = request_region(port, 1, "InterWave (I2C bus)"); |
| 237 | } |
| 238 | if (iwcard->i2c_res == NULL) { |
| 239 | snd_printk(KERN_ERR "interwave: can't grab i2c bus port\n"); |
| 240 | return -ENODEV; |
| 241 | } |
| 242 | |
| 243 | sprintf(name, "InterWave-%i", card->number); |
| 244 | if ((err = snd_i2c_bus_create(card, name, NULL, &bus)) < 0) |
| 245 | return err; |
| 246 | bus->private_value = port; |
| 247 | bus->hw_ops.bit = &snd_interwave_i2c_bit_ops; |
| 248 | if ((err = snd_tea6330t_detect(bus, 0)) < 0) |
| 249 | return err; |
| 250 | *rbus = bus; |
| 251 | return 0; |
| 252 | } |
| 253 | #endif |
| 254 | |
| 255 | static int __devinit snd_interwave_detect(struct snd_interwave *iwcard, |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 256 | struct snd_gus_card * gus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | int dev |
| 258 | #ifdef SNDRV_STB |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 259 | , struct snd_i2c_bus **rbus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | #endif |
| 261 | ) |
| 262 | { |
| 263 | unsigned long flags; |
| 264 | unsigned char rev1, rev2; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 265 | int d; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 0); /* reset GF1 */ |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 268 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 0) { |
| 269 | 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] | 270 | return -ENODEV; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | udelay(160); |
| 273 | snd_gf1_i_write8(gus, SNDRV_GF1_GB_RESET, 1); /* release reset */ |
| 274 | udelay(160); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 275 | if (((d = snd_gf1_i_look8(gus, SNDRV_GF1_GB_RESET)) & 0x07) != 1) { |
| 276 | 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] | 277 | return -ENODEV; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | spin_lock_irqsave(&gus->reg_lock, flags); |
| 280 | rev1 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER); |
| 281 | snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, ~rev1); |
| 282 | rev2 = snd_gf1_look8(gus, SNDRV_GF1_GB_VERSION_NUMBER); |
| 283 | snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, rev1); |
| 284 | spin_unlock_irqrestore(&gus->reg_lock, flags); |
| 285 | snd_printdd("[0x%lx] InterWave check - rev1=0x%x, rev2=0x%x\n", gus->gf1.port, rev1, rev2); |
| 286 | if ((rev1 & 0xf0) == (rev2 & 0xf0) && |
| 287 | (rev1 & 0x0f) != (rev2 & 0x0f)) { |
| 288 | snd_printdd("[0x%lx] InterWave check - passed\n", gus->gf1.port); |
| 289 | gus->interwave = 1; |
| 290 | strcpy(gus->card->shortname, "AMD InterWave"); |
| 291 | gus->revision = rev1 >> 4; |
| 292 | #ifndef SNDRV_STB |
| 293 | return 0; /* ok.. We have an InterWave board */ |
| 294 | #else |
| 295 | return snd_interwave_detect_stb(iwcard, gus, dev, rbus); |
| 296 | #endif |
| 297 | } |
| 298 | snd_printdd("[0x%lx] InterWave check - failed\n", gus->gf1.port); |
| 299 | return -ENODEV; |
| 300 | } |
| 301 | |
| 302 | static irqreturn_t snd_interwave_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 303 | { |
| 304 | struct snd_interwave *iwcard = (struct snd_interwave *) dev_id; |
| 305 | int loop, max = 5; |
| 306 | int handled = 0; |
| 307 | |
| 308 | do { |
| 309 | loop = 0; |
| 310 | if (inb(iwcard->gus_status_reg)) { |
| 311 | handled = 1; |
| 312 | snd_gus_interrupt(irq, iwcard->gus, regs); |
| 313 | loop++; |
| 314 | } |
| 315 | if (inb(iwcard->pcm_status_reg) & 0x01) { /* IRQ bit is set? */ |
| 316 | handled = 1; |
| 317 | snd_cs4231_interrupt(irq, iwcard->cs4231, regs); |
| 318 | loop++; |
| 319 | } |
| 320 | } while (loop && --max > 0); |
| 321 | return IRQ_RETVAL(handled); |
| 322 | } |
| 323 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 324 | static void __devinit snd_interwave_reset(struct snd_gus_card * gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x00); |
| 327 | udelay(160); |
| 328 | snd_gf1_write8(gus, SNDRV_GF1_GB_RESET, 0x01); |
| 329 | udelay(160); |
| 330 | } |
| 331 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 332 | static void __devinit snd_interwave_bank_sizes(struct snd_gus_card * gus, int *sizes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | { |
| 334 | unsigned int idx; |
| 335 | unsigned int local; |
| 336 | unsigned char d; |
| 337 | |
| 338 | for (idx = 0; idx < 4; idx++) { |
| 339 | sizes[idx] = 0; |
| 340 | d = 0x55; |
| 341 | for (local = idx << 22; |
| 342 | local < (idx << 22) + 0x400000; |
| 343 | local += 0x40000, d++) { |
| 344 | snd_gf1_poke(gus, local, d); |
| 345 | snd_gf1_poke(gus, local + 1, d + 1); |
| 346 | #if 0 |
| 347 | printk("d = 0x%x, local = 0x%x, local + 1 = 0x%x, idx << 22 = 0x%x\n", |
| 348 | d, |
| 349 | snd_gf1_peek(gus, local), |
| 350 | snd_gf1_peek(gus, local + 1), |
| 351 | snd_gf1_peek(gus, idx << 22)); |
| 352 | #endif |
| 353 | if (snd_gf1_peek(gus, local) != d || |
| 354 | snd_gf1_peek(gus, local + 1) != d + 1 || |
| 355 | snd_gf1_peek(gus, idx << 22) != 0x55) |
| 356 | break; |
| 357 | sizes[idx]++; |
| 358 | } |
| 359 | } |
| 360 | #if 0 |
| 361 | printk("sizes: %i %i %i %i\n", sizes[0], sizes[1], sizes[2], sizes[3]); |
| 362 | #endif |
| 363 | } |
| 364 | |
| 365 | struct rom_hdr { |
| 366 | /* 000 */ unsigned char iwave[8]; |
| 367 | /* 008 */ unsigned char rom_hdr_revision; |
| 368 | /* 009 */ unsigned char series_number; |
| 369 | /* 010 */ unsigned char series_name[16]; |
| 370 | /* 026 */ unsigned char date[10]; |
| 371 | /* 036 */ unsigned short vendor_revision_major; |
| 372 | /* 038 */ unsigned short vendor_revision_minor; |
| 373 | /* 040 */ unsigned int rom_size; |
| 374 | /* 044 */ unsigned char copyright[128]; |
| 375 | /* 172 */ unsigned char vendor_name[64]; |
| 376 | /* 236 */ unsigned char rom_description[128]; |
| 377 | /* 364 */ unsigned char pad[147]; |
| 378 | /* 511 */ unsigned char csum; |
| 379 | }; |
| 380 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 381 | static void __devinit snd_interwave_detect_memory(struct snd_gus_card * gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
| 383 | static unsigned int lmc[13] = |
| 384 | { |
| 385 | 0x00000001, 0x00000101, 0x01010101, 0x00000401, |
| 386 | 0x04040401, 0x00040101, 0x04040101, 0x00000004, |
| 387 | 0x00000404, 0x04040404, 0x00000010, 0x00001010, |
| 388 | 0x10101010 |
| 389 | }; |
| 390 | |
| 391 | int bank_pos, pages; |
| 392 | unsigned int i, lmct; |
| 393 | int psizes[4]; |
| 394 | unsigned char iwave[8]; |
| 395 | unsigned char csum; |
| 396 | |
| 397 | snd_interwave_reset(gus); |
| 398 | snd_gf1_write8(gus, SNDRV_GF1_GB_GLOBAL_MODE, snd_gf1_read8(gus, SNDRV_GF1_GB_GLOBAL_MODE) | 0x01); /* enhanced mode */ |
| 399 | snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x01); /* DRAM I/O cycles selected */ |
| 400 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff10) | 0x004c); |
| 401 | /* ok.. simple test of memory size */ |
| 402 | pages = 0; |
| 403 | snd_gf1_poke(gus, 0, 0x55); |
| 404 | snd_gf1_poke(gus, 1, 0xaa); |
| 405 | #if 1 |
| 406 | if (snd_gf1_peek(gus, 0) == 0x55 && snd_gf1_peek(gus, 1) == 0xaa) |
| 407 | #else |
| 408 | if (0) /* ok.. for testing of 0k RAM */ |
| 409 | #endif |
| 410 | { |
| 411 | snd_interwave_bank_sizes(gus, psizes); |
| 412 | lmct = (psizes[3] << 24) | (psizes[2] << 16) | |
| 413 | (psizes[1] << 8) | psizes[0]; |
| 414 | #if 0 |
| 415 | printk("lmct = 0x%08x\n", lmct); |
| 416 | #endif |
| 417 | for (i = 0; i < ARRAY_SIZE(lmc); i++) |
| 418 | if (lmct == lmc[i]) { |
| 419 | #if 0 |
| 420 | printk("found !!! %i\n", i); |
| 421 | #endif |
| 422 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i); |
| 423 | snd_interwave_bank_sizes(gus, psizes); |
| 424 | break; |
| 425 | } |
| 426 | if (i >= ARRAY_SIZE(lmc) && !gus->gf1.enh_mode) |
| 427 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | 2); |
| 428 | for (i = 0; i < 4; i++) { |
| 429 | gus->gf1.mem_alloc.banks_8[i].address = |
| 430 | gus->gf1.mem_alloc.banks_16[i].address = i << 22; |
| 431 | gus->gf1.mem_alloc.banks_8[i].size = |
| 432 | gus->gf1.mem_alloc.banks_16[i].size = psizes[i] << 18; |
| 433 | pages += psizes[i]; |
| 434 | } |
| 435 | } |
| 436 | pages <<= 18; |
| 437 | gus->gf1.memory = pages; |
| 438 | |
| 439 | snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x03); /* select ROM */ |
| 440 | snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xff1f) | (4 << 5)); |
| 441 | gus->gf1.rom_banks = 0; |
| 442 | gus->gf1.rom_memory = 0; |
| 443 | for (bank_pos = 0; bank_pos < 16L * 1024L * 1024L; bank_pos += 4L * 1024L * 1024L) { |
| 444 | for (i = 0; i < 8; ++i) |
| 445 | iwave[i] = snd_gf1_peek(gus, bank_pos + i); |
| 446 | #ifdef CONFIG_SND_DEBUG_ROM |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 447 | printk(KERN_DEBUG "ROM at 0x%06x = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", bank_pos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | iwave[0], iwave[1], iwave[2], iwave[3], |
| 449 | iwave[4], iwave[5], iwave[6], iwave[7]); |
| 450 | #endif |
| 451 | if (strncmp(iwave, "INTRWAVE", 8)) |
| 452 | continue; /* first check */ |
| 453 | csum = 0; |
| 454 | for (i = 0; i < sizeof(struct rom_hdr); i++) |
| 455 | csum += snd_gf1_peek(gus, bank_pos + i); |
| 456 | #ifdef CONFIG_SND_DEBUG_ROM |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 457 | printk(KERN_DEBUG "ROM checksum = 0x%x (computed)\n", csum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | #endif |
| 459 | if (csum != 0) |
| 460 | continue; /* not valid rom */ |
| 461 | gus->gf1.rom_banks++; |
| 462 | gus->gf1.rom_present |= 1 << (bank_pos >> 22); |
| 463 | gus->gf1.rom_memory = snd_gf1_peek(gus, bank_pos + 40) | |
| 464 | (snd_gf1_peek(gus, bank_pos + 41) << 8) | |
| 465 | (snd_gf1_peek(gus, bank_pos + 42) << 16) | |
| 466 | (snd_gf1_peek(gus, bank_pos + 43) << 24); |
| 467 | } |
| 468 | #if 0 |
| 469 | if (gus->gf1.rom_memory > 0) { |
| 470 | if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8) |
| 471 | gus->card->type = SNDRV_CARD_TYPE_IW_DYNASONIC; |
| 472 | } |
| 473 | #endif |
| 474 | snd_gf1_write8(gus, SNDRV_GF1_GB_MEMORY_CONTROL, 0x00); /* select RAM */ |
| 475 | |
| 476 | if (!gus->gf1.enh_mode) |
| 477 | snd_interwave_reset(gus); |
| 478 | } |
| 479 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 480 | static void __devinit snd_interwave_init(int dev, struct snd_gus_card * gus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
| 482 | unsigned long flags; |
| 483 | |
| 484 | /* ok.. some InterWave specific initialization */ |
| 485 | spin_lock_irqsave(&gus->reg_lock, flags); |
| 486 | snd_gf1_write8(gus, SNDRV_GF1_GB_SOUND_BLASTER_CONTROL, 0x00); |
| 487 | snd_gf1_write8(gus, SNDRV_GF1_GB_COMPATIBILITY, 0x1f); |
| 488 | snd_gf1_write8(gus, SNDRV_GF1_GB_DECODE_CONTROL, 0x49); |
| 489 | snd_gf1_write8(gus, SNDRV_GF1_GB_VERSION_NUMBER, 0x11); |
| 490 | snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_A, 0x00); |
| 491 | snd_gf1_write8(gus, SNDRV_GF1_GB_MPU401_CONTROL_B, 0x30); |
| 492 | snd_gf1_write8(gus, SNDRV_GF1_GB_EMULATION_IRQ, 0x00); |
| 493 | spin_unlock_irqrestore(&gus->reg_lock, flags); |
| 494 | gus->equal_irq = 1; |
| 495 | gus->codec_flag = 1; |
| 496 | gus->interwave = 1; |
| 497 | gus->max_flag = 1; |
| 498 | gus->joystick_dac = joystick_dac[dev]; |
| 499 | |
| 500 | } |
| 501 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 502 | static struct snd_kcontrol_new snd_interwave_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | CS4231_DOUBLE("Master Playback Switch", 0, CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 7, 7, 1, 1), |
| 504 | CS4231_DOUBLE("Master Playback Volume", 0, CS4231_LINE_LEFT_OUTPUT, CS4231_LINE_RIGHT_OUTPUT, 0, 0, 31, 1), |
| 505 | CS4231_DOUBLE("Mic Playback Switch", 0, CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 7, 7, 1, 1), |
| 506 | CS4231_DOUBLE("Mic Playback Volume", 0, CS4231_LEFT_MIC_INPUT, CS4231_RIGHT_MIC_INPUT, 0, 0, 31, 1) |
| 507 | }; |
| 508 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 509 | static int __devinit snd_interwave_mixer(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 511 | struct snd_card *card = chip->card; |
| 512 | struct snd_ctl_elem_id id1, id2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | unsigned int idx; |
| 514 | int err; |
| 515 | |
| 516 | memset(&id1, 0, sizeof(id1)); |
| 517 | memset(&id2, 0, sizeof(id2)); |
| 518 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 519 | #if 0 |
| 520 | /* remove mono microphone controls */ |
| 521 | strcpy(id1.name, "Mic Playback Switch"); |
| 522 | if ((err = snd_ctl_remove_id(card, &id1)) < 0) |
| 523 | return err; |
| 524 | strcpy(id1.name, "Mic Playback Volume"); |
| 525 | if ((err = snd_ctl_remove_id(card, &id1)) < 0) |
| 526 | return err; |
| 527 | #endif |
| 528 | /* add new master and mic controls */ |
| 529 | for (idx = 0; idx < ARRAY_SIZE(snd_interwave_controls); idx++) |
| 530 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_interwave_controls[idx], chip))) < 0) |
| 531 | return err; |
| 532 | snd_cs4231_out(chip, CS4231_LINE_LEFT_OUTPUT, 0x9f); |
| 533 | snd_cs4231_out(chip, CS4231_LINE_RIGHT_OUTPUT, 0x9f); |
| 534 | snd_cs4231_out(chip, CS4231_LEFT_MIC_INPUT, 0x9f); |
| 535 | snd_cs4231_out(chip, CS4231_RIGHT_MIC_INPUT, 0x9f); |
| 536 | /* reassign AUXA to SYNTHESIZER */ |
| 537 | strcpy(id1.name, "Aux Playback Switch"); |
| 538 | strcpy(id2.name, "Synth Playback Switch"); |
| 539 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 540 | return err; |
| 541 | strcpy(id1.name, "Aux Playback Volume"); |
| 542 | strcpy(id2.name, "Synth Playback Volume"); |
| 543 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 544 | return err; |
| 545 | /* reassign AUXB to CD */ |
| 546 | strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; |
| 547 | strcpy(id2.name, "CD Playback Switch"); |
| 548 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 549 | return err; |
| 550 | strcpy(id1.name, "Aux Playback Volume"); |
| 551 | strcpy(id2.name, "CD Playback Volume"); |
| 552 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
| 553 | return err; |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | #ifdef CONFIG_PNP |
| 558 | |
| 559 | static int __devinit snd_interwave_pnp(int dev, struct snd_interwave *iwcard, |
| 560 | struct pnp_card_link *card, |
| 561 | const struct pnp_card_device_id *id) |
| 562 | { |
| 563 | struct pnp_dev *pdev; |
| 564 | struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); |
| 565 | int err; |
| 566 | |
| 567 | iwcard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); |
| 568 | if (iwcard->dev == NULL) { |
| 569 | kfree(cfg); |
| 570 | return -EBUSY; |
| 571 | } |
| 572 | #ifdef SNDRV_STB |
| 573 | iwcard->devtc = pnp_request_card_device(card, id->devs[1].id, NULL); |
| 574 | if (iwcard->devtc == NULL) { |
| 575 | kfree(cfg); |
| 576 | return -EBUSY; |
| 577 | } |
| 578 | #endif |
| 579 | /* Synth & Codec initialization */ |
| 580 | pdev = iwcard->dev; |
| 581 | pnp_init_resource_table(cfg); |
| 582 | if (port[dev] != SNDRV_AUTO_PORT) { |
| 583 | pnp_resource_change(&cfg->port_resource[0], port[dev], 16); |
| 584 | pnp_resource_change(&cfg->port_resource[1], port[dev] + 0x100, 12); |
| 585 | pnp_resource_change(&cfg->port_resource[2], port[dev] + 0x10c, 4); |
| 586 | } |
| 587 | if (dma1[dev] != SNDRV_AUTO_DMA) |
| 588 | pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1); |
| 589 | if (dma2[dev] != SNDRV_AUTO_DMA) |
| 590 | pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1); |
| 591 | if (dma2[dev] < 0) |
| 592 | pnp_resource_change(&cfg->dma_resource[1], 4, 1); |
| 593 | if (irq[dev] != SNDRV_AUTO_IRQ) |
| 594 | pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); |
| 595 | if (pnp_manual_config_dev(pdev, cfg, 0) < 0) |
| 596 | snd_printk(KERN_ERR "InterWave - Synth - the requested resources are invalid, using auto config\n"); |
| 597 | err = pnp_activate_dev(pdev); |
| 598 | if (err < 0) { |
| 599 | kfree(cfg); |
| 600 | snd_printk(KERN_ERR "InterWave PnP configure failure (out of resources?)\n"); |
| 601 | return err; |
| 602 | } |
| 603 | if (pnp_port_start(pdev, 0) + 0x100 != pnp_port_start(pdev, 1) || |
| 604 | pnp_port_start(pdev, 0) + 0x10c != pnp_port_start(pdev, 2)) { |
| 605 | kfree(cfg); |
| 606 | snd_printk(KERN_ERR "PnP configure failure (wrong ports)\n"); |
| 607 | return -ENOENT; |
| 608 | } |
| 609 | port[dev] = pnp_port_start(pdev, 0); |
| 610 | dma1[dev] = pnp_dma(pdev, 0); |
| 611 | if (dma2[dev] >= 0) |
| 612 | dma2[dev] = pnp_dma(pdev, 1); |
| 613 | irq[dev] = pnp_irq(pdev, 0); |
Greg Kroah-Hartman | aa0a2dd | 2006-06-12 14:50:27 -0700 | [diff] [blame] | 614 | snd_printdd("isapnp IW: sb port=0x%llx, gf1 port=0x%llx, codec port=0x%llx\n", |
| 615 | (unsigned long long)pnp_port_start(pdev, 0), |
| 616 | (unsigned long long)pnp_port_start(pdev, 1), |
| 617 | (unsigned long long)pnp_port_start(pdev, 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | snd_printdd("isapnp IW: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]); |
| 619 | #ifdef SNDRV_STB |
| 620 | /* Tone Control initialization */ |
| 621 | pdev = iwcard->devtc; |
| 622 | pnp_init_resource_table(cfg); |
| 623 | if (port_tc[dev] != SNDRV_AUTO_PORT) |
| 624 | pnp_resource_change(&cfg->port_resource[0], port_tc[dev], 1); |
| 625 | if (pnp_manual_config_dev(pdev, cfg, 0) < 0) |
| 626 | snd_printk(KERN_ERR "InterWave - ToneControl - the requested resources are invalid, using auto config\n"); |
| 627 | err = pnp_activate_dev(pdev); |
| 628 | if (err < 0) { |
| 629 | kfree(cfg); |
| 630 | snd_printk(KERN_ERR "InterWave ToneControl PnP configure failure (out of resources?)\n"); |
| 631 | return err; |
| 632 | } |
| 633 | port_tc[dev] = pnp_port_start(pdev, 0); |
| 634 | snd_printdd("isapnp IW: tone control port=0x%lx\n", port_tc[dev]); |
| 635 | #endif |
| 636 | kfree(cfg); |
| 637 | return 0; |
| 638 | } |
| 639 | #endif /* CONFIG_PNP */ |
| 640 | |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 641 | static void snd_interwave_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 643 | struct snd_interwave *iwcard = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | if (iwcard == NULL) |
| 646 | return; |
| 647 | #ifdef SNDRV_STB |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 648 | release_and_free_resource(iwcard->i2c_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | #endif |
| 650 | if (iwcard->irq >= 0) |
| 651 | free_irq(iwcard->irq, (void *)iwcard); |
| 652 | } |
| 653 | |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 654 | static struct snd_card *snd_interwave_card_new(int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 656 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | struct snd_interwave *iwcard; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 658 | |
| 659 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 660 | sizeof(struct snd_interwave)); |
| 661 | if (card == NULL) |
| 662 | return NULL; |
| 663 | iwcard = card->private_data; |
| 664 | iwcard->card = card; |
| 665 | iwcard->irq = -1; |
| 666 | card->private_free = snd_interwave_free; |
| 667 | return card; |
| 668 | } |
| 669 | |
| 670 | static int __devinit snd_interwave_probe(struct snd_card *card, int dev) |
| 671 | { |
| 672 | int xirq, xdma1, xdma2; |
| 673 | struct snd_interwave *iwcard = card->private_data; |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 674 | struct snd_cs4231 *cs4231; |
| 675 | struct snd_gus_card *gus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | #ifdef SNDRV_STB |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 677 | struct snd_i2c_bus *i2c_bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | #endif |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 679 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | char *str; |
| 681 | int err; |
| 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | xirq = irq[dev]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | xdma1 = dma1[dev]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | xdma2 = dma2[dev]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
| 687 | if ((err = snd_gus_create(card, |
| 688 | port[dev], |
| 689 | -xirq, xdma1, xdma2, |
| 690 | 0, 32, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 691 | pcm_channels[dev], effect[dev], &gus)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 692 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if ((err = snd_interwave_detect(iwcard, gus, dev |
| 695 | #ifdef SNDRV_STB |
| 696 | , &i2c_bus |
| 697 | #endif |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 698 | )) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 699 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 700 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | iwcard->gus_status_reg = gus->gf1.reg_irqstat; |
| 702 | iwcard->pcm_status_reg = gus->gf1.port + 0x10c + 2; |
| 703 | |
| 704 | snd_interwave_init(dev, gus); |
| 705 | snd_interwave_detect_memory(gus); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 706 | if ((err = snd_gus_initialize(gus)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 707 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame^] | 709 | if (request_irq(xirq, snd_interwave_interrupt, IRQF_DISABLED, |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 710 | "InterWave", iwcard)) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 711 | snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 712 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
| 714 | iwcard->irq = xirq; |
| 715 | |
| 716 | if ((err = snd_cs4231_create(card, |
| 717 | gus->gf1.port + 0x10c, -1, xirq, |
| 718 | xdma2 < 0 ? xdma1 : xdma2, xdma1, |
| 719 | CS4231_HW_INTERWAVE, |
| 720 | CS4231_HWSHARE_IRQ | |
| 721 | CS4231_HWSHARE_DMA1 | |
| 722 | CS4231_HWSHARE_DMA2, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 723 | &cs4231)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 724 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 725 | |
| 726 | if ((err = snd_cs4231_pcm(cs4231, 0, &pcm)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 727 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | sprintf(pcm->name + strlen(pcm->name), " rev %c", gus->revision + 'A'); |
| 730 | strcat(pcm->name, " (codec)"); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 731 | |
| 732 | if ((err = snd_cs4231_timer(cs4231, 2, NULL)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 733 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 734 | |
| 735 | if ((err = snd_cs4231_mixer(cs4231)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 736 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | if (pcm_channels[dev] > 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 739 | if ((err = snd_gf1_pcm_new(gus, 1, 1, NULL)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 740 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | } |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 742 | if ((err = snd_interwave_mixer(cs4231)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 743 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | #ifdef SNDRV_STB |
| 746 | { |
Takashi Iwai | 5e2da20 | 2005-11-17 14:36:44 +0100 | [diff] [blame] | 747 | struct snd_ctl_elem_id id1, id2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | memset(&id1, 0, sizeof(id1)); |
| 749 | memset(&id2, 0, sizeof(id2)); |
| 750 | id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 751 | strcpy(id1.name, "Master Playback Switch"); |
| 752 | strcpy(id2.name, id1.name); |
| 753 | id2.index = 1; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 754 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 755 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | strcpy(id1.name, "Master Playback Volume"); |
| 757 | strcpy(id2.name, id1.name); |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 758 | if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 759 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 760 | if ((err = snd_tea6330t_update_mixer(card, i2c_bus, 0, 1)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 761 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | #endif |
| 764 | |
| 765 | gus->uart_enable = midi[dev]; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 766 | if ((err = snd_gf1_rawmidi_new(gus, 0, NULL)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 767 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
| 769 | #ifndef SNDRV_STB |
| 770 | str = "AMD InterWave"; |
| 771 | if (gus->gf1.rom_banks == 1 && gus->gf1.rom_present == 8) |
| 772 | str = "Dynasonic 3-D"; |
| 773 | #else |
| 774 | str = "InterWave STB"; |
| 775 | #endif |
| 776 | strcpy(card->driver, str); |
| 777 | strcpy(card->shortname, str); |
| 778 | sprintf(card->longname, "%s at 0x%lx, irq %i, dma %d", |
| 779 | str, |
| 780 | gus->gf1.port, |
| 781 | xirq, |
| 782 | xdma1); |
| 783 | if (xdma2 >= 0) |
| 784 | sprintf(card->longname + strlen(card->longname), "&%d", xdma2); |
| 785 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 786 | if ((err = snd_card_register(card)) < 0) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 787 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
| 789 | iwcard->cs4231 = cs4231; |
| 790 | iwcard->gus = gus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Bjorn Helgaas | ebdb71e | 2006-03-27 01:17:14 -0800 | [diff] [blame] | 794 | static int __devinit snd_interwave_nonpnp_probe1(int dev, struct platform_device *devptr) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 795 | { |
| 796 | struct snd_card *card; |
| 797 | int err; |
| 798 | |
| 799 | card = snd_interwave_card_new(dev); |
| 800 | if (! card) |
| 801 | return -ENOMEM; |
| 802 | |
| 803 | snd_card_set_dev(card, &devptr->dev); |
| 804 | if ((err = snd_interwave_probe(card, dev)) < 0) { |
| 805 | snd_card_free(card); |
| 806 | return err; |
| 807 | } |
| 808 | platform_set_drvdata(devptr, card); |
| 809 | return 0; |
| 810 | } |
| 811 | |
Bjorn Helgaas | ebdb71e | 2006-03-27 01:17:14 -0800 | [diff] [blame] | 812 | static int __devinit snd_interwave_nonpnp_probe(struct platform_device *pdev) |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 813 | { |
| 814 | int dev = pdev->id; |
| 815 | int err; |
| 816 | static int possible_irqs[] = {5, 11, 12, 9, 7, 15, 3, -1}; |
| 817 | static int possible_dmas[] = {0, 1, 3, 5, 6, 7, -1}; |
| 818 | |
| 819 | if (irq[dev] == SNDRV_AUTO_IRQ) { |
| 820 | if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) { |
| 821 | snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); |
| 822 | return -EBUSY; |
| 823 | } |
| 824 | } |
| 825 | if (dma1[dev] == SNDRV_AUTO_DMA) { |
| 826 | if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { |
| 827 | snd_printk(KERN_ERR PFX "unable to find a free DMA1\n"); |
| 828 | return -EBUSY; |
| 829 | } |
| 830 | } |
| 831 | if (dma2[dev] == SNDRV_AUTO_DMA) { |
| 832 | if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { |
| 833 | snd_printk(KERN_ERR PFX "unable to find a free DMA2\n"); |
| 834 | return -EBUSY; |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | if (port[dev] != SNDRV_AUTO_PORT) |
| 839 | return snd_interwave_nonpnp_probe1(dev, pdev); |
| 840 | else { |
| 841 | static long possible_ports[] = {0x210, 0x220, 0x230, 0x240, 0x250, 0x260}; |
| 842 | int i; |
| 843 | for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { |
| 844 | port[dev] = possible_ports[i]; |
| 845 | err = snd_interwave_nonpnp_probe1(dev, pdev); |
| 846 | if (! err) |
| 847 | return 0; |
| 848 | } |
| 849 | return err; |
| 850 | } |
| 851 | } |
| 852 | |
| 853 | static int __devexit snd_interwave_nonpnp_remove(struct platform_device *devptr) |
| 854 | { |
| 855 | snd_card_free(platform_get_drvdata(devptr)); |
| 856 | platform_set_drvdata(devptr, NULL); |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static struct platform_driver snd_interwave_driver = { |
| 861 | .probe = snd_interwave_nonpnp_probe, |
| 862 | .remove = __devexit_p(snd_interwave_nonpnp_remove), |
| 863 | /* FIXME: suspend,resume */ |
| 864 | .driver = { |
| 865 | .name = INTERWAVE_DRIVER |
| 866 | }, |
| 867 | }; |
| 868 | |
| 869 | #ifdef CONFIG_PNP |
Bjorn Helgaas | ebdb71e | 2006-03-27 01:17:14 -0800 | [diff] [blame] | 870 | static unsigned int __devinitdata interwave_pnp_devices; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 871 | |
| 872 | static int __devinit snd_interwave_pnp_detect(struct pnp_card_link *pcard, |
| 873 | const struct pnp_card_device_id *pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | { |
| 875 | static int dev; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 876 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | int res; |
| 878 | |
| 879 | for ( ; dev < SNDRV_CARDS; dev++) { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 880 | if (enable[dev] && isapnp[dev]) |
| 881 | break; |
| 882 | } |
| 883 | if (dev >= SNDRV_CARDS) |
| 884 | return -ENODEV; |
| 885 | |
| 886 | card = snd_interwave_card_new(dev); |
| 887 | if (! card) |
| 888 | return -ENOMEM; |
| 889 | |
| 890 | if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) { |
| 891 | snd_card_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | return res; |
| 893 | } |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 894 | snd_card_set_dev(card, &pcard->card->dev); |
| 895 | if ((res = snd_interwave_probe(card, dev)) < 0) { |
| 896 | snd_card_free(card); |
| 897 | return res; |
| 898 | } |
| 899 | pnp_set_card_drvdata(pcard, card); |
| 900 | dev++; |
Bjorn Helgaas | ebdb71e | 2006-03-27 01:17:14 -0800 | [diff] [blame] | 901 | interwave_pnp_devices++; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 902 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static void __devexit snd_interwave_pnp_remove(struct pnp_card_link * pcard) |
| 906 | { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 907 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 908 | pnp_set_card_drvdata(pcard, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static struct pnp_card_driver interwave_pnpc_driver = { |
| 912 | .flags = PNP_DRIVER_RES_DISABLE, |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 913 | .name = INTERWAVE_PNP_DRIVER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | .id_table = snd_interwave_pnpids, |
| 915 | .probe = snd_interwave_pnp_detect, |
| 916 | .remove = __devexit_p(snd_interwave_pnp_remove), |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 917 | /* FIXME: suspend,resume */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | }; |
| 919 | |
| 920 | #endif /* CONFIG_PNP */ |
| 921 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 922 | static void __init_or_module snd_interwave_unregister_all(void) |
| 923 | { |
| 924 | int i; |
| 925 | |
| 926 | if (pnp_registered) |
| 927 | pnp_unregister_card_driver(&interwave_pnpc_driver); |
| 928 | for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) |
| 929 | platform_device_unregister(platform_devices[i]); |
| 930 | platform_driver_unregister(&snd_interwave_driver); |
| 931 | } |
| 932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | static int __init alsa_card_interwave_init(void) |
| 934 | { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 935 | int i, err, cards = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 937 | if ((err = platform_driver_register(&snd_interwave_driver)) < 0) |
| 938 | return err; |
| 939 | |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 940 | for (i = 0; i < SNDRV_CARDS; i++) { |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 941 | struct platform_device *device; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 942 | if (! enable[i]) |
| 943 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | #ifdef CONFIG_PNP |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 945 | if (isapnp[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | continue; |
| 947 | #endif |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 948 | device = platform_device_register_simple(INTERWAVE_DRIVER, |
| 949 | i, NULL, 0); |
Rene Herman | d0ac642 | 2006-04-11 14:08:33 +0200 | [diff] [blame] | 950 | if (IS_ERR(device)) |
| 951 | continue; |
Rene Herman | dcccdd9 | 2006-04-11 14:09:37 +0200 | [diff] [blame] | 952 | if (!platform_get_drvdata(device)) { |
| 953 | platform_device_unregister(device); |
| 954 | continue; |
| 955 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 956 | platform_devices[i] = device; |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 957 | cards++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | } |
Takashi Iwai | 654aa66 | 2005-11-17 17:13:43 +0100 | [diff] [blame] | 959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | /* ISA PnP cards */ |
Bjorn Helgaas | ebdb71e | 2006-03-27 01:17:14 -0800 | [diff] [blame] | 961 | err = pnp_register_card_driver(&interwave_pnpc_driver); |
| 962 | if (!err) { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 963 | pnp_registered = 1; |
Bjorn Helgaas | ebdb71e | 2006-03-27 01:17:14 -0800 | [diff] [blame] | 964 | cards += interwave_pnp_devices;; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 965 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
| 967 | if (!cards) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | #ifdef MODULE |
| 969 | printk(KERN_ERR "InterWave soundcard not found or device busy\n"); |
| 970 | #endif |
Rene Herman | d0ac642 | 2006-04-11 14:08:33 +0200 | [diff] [blame] | 971 | snd_interwave_unregister_all(); |
| 972 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } |
| 974 | return 0; |
| 975 | } |
| 976 | |
| 977 | static void __exit alsa_card_interwave_exit(void) |
| 978 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 979 | snd_interwave_unregister_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | module_init(alsa_card_interwave_init) |
| 983 | module_exit(alsa_card_interwave_exit) |