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