Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards. |
| 3 | Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it> |
| 4 | |
| 5 | Part of this code was developed at the Italian Ministry of Air Defence, |
| 6 | Sixth Division (oh, che pace ...), Rome. |
| 7 | |
| 8 | Thanks to Maria Grazia Pollarini, Salvatore Vassallo. |
| 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/init.h> |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 27 | #include <linux/err.h> |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 28 | #include <linux/isa.h> |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 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 | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 33 | #include <asm/io.h> |
| 34 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <sound/core.h> |
Krzysztof Helt | 61ef19d | 2008-07-31 21:02:42 +0200 | [diff] [blame] | 36 | #include <sound/wss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <sound/mpu401.h> |
| 38 | #include <sound/opl3.h> |
| 39 | #ifndef OPTi93X |
| 40 | #include <sound/opl4.h> |
| 41 | #endif |
| 42 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 43 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 44 | #include <sound/initval.h> |
| 45 | |
| 46 | MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); |
| 47 | MODULE_LICENSE("GPL"); |
| 48 | #ifdef OPTi93X |
| 49 | MODULE_DESCRIPTION("OPTi93X"); |
| 50 | MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}"); |
| 51 | #else /* OPTi93X */ |
| 52 | #ifdef CS4231 |
| 53 | MODULE_DESCRIPTION("OPTi92X - CS4231"); |
| 54 | MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)}," |
| 55 | "{OPTi,82C925 (CS4231)}}"); |
| 56 | #else /* CS4231 */ |
| 57 | MODULE_DESCRIPTION("OPTi92X - AD1848"); |
| 58 | MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)}," |
| 59 | "{OPTi,82C925 (AD1848)}," |
| 60 | "{OAK,Mozart}}"); |
| 61 | #endif /* CS4231 */ |
| 62 | #endif /* OPTi93X */ |
| 63 | |
| 64 | static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ |
| 65 | static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ |
| 66 | //static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */ |
Rene Herman | 51f6baa | 2008-07-18 11:15:12 +0200 | [diff] [blame] | 67 | #ifdef CONFIG_PNP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | static int isapnp = 1; /* Enable ISA PnP detection */ |
Rene Herman | 51f6baa | 2008-07-18 11:15:12 +0200 | [diff] [blame] | 69 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */ |
| 71 | static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */ |
| 72 | static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */ |
| 73 | static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */ |
| 74 | static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */ |
| 75 | static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ |
| 76 | #if defined(CS4231) || defined(OPTi93X) |
| 77 | static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */ |
| 78 | #endif /* CS4231 || OPTi93X */ |
| 79 | |
| 80 | module_param(index, int, 0444); |
| 81 | MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard."); |
| 82 | module_param(id, charp, 0444); |
| 83 | MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard."); |
| 84 | //module_param(enable, bool, 0444); |
| 85 | //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard."); |
Rene Herman | 51f6baa | 2008-07-18 11:15:12 +0200 | [diff] [blame] | 86 | #ifdef CONFIG_PNP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | module_param(isapnp, bool, 0444); |
| 88 | MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard."); |
Rene Herman | 51f6baa | 2008-07-18 11:15:12 +0200 | [diff] [blame] | 89 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | module_param(port, long, 0444); |
| 91 | MODULE_PARM_DESC(port, "WSS port # for opti9xx driver."); |
| 92 | module_param(mpu_port, long, 0444); |
| 93 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver."); |
| 94 | module_param(fm_port, long, 0444); |
| 95 | MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver."); |
| 96 | module_param(irq, int, 0444); |
| 97 | MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver."); |
| 98 | module_param(mpu_irq, int, 0444); |
| 99 | MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver."); |
| 100 | module_param(dma1, int, 0444); |
| 101 | MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver."); |
| 102 | #if defined(CS4231) || defined(OPTi93X) |
| 103 | module_param(dma2, int, 0444); |
| 104 | MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver."); |
| 105 | #endif /* CS4231 || OPTi93X */ |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #define OPTi9XX_HW_82C928 1 |
| 108 | #define OPTi9XX_HW_82C929 2 |
| 109 | #define OPTi9XX_HW_82C924 3 |
| 110 | #define OPTi9XX_HW_82C925 4 |
| 111 | #define OPTi9XX_HW_82C930 5 |
| 112 | #define OPTi9XX_HW_82C931 6 |
| 113 | #define OPTi9XX_HW_82C933 7 |
| 114 | #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933 |
| 115 | |
| 116 | #define OPTi9XX_MC_REG(n) n |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #ifdef OPTi93X |
| 119 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | #define OPTi93X_STATUS 0x02 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r) |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | #define OPTi93X_IRQ_PLAYBACK 0x04 |
| 124 | #define OPTi93X_IRQ_CAPTURE 0x08 |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | #endif /* OPTi93X */ |
| 127 | |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 128 | struct snd_opti9xx { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | unsigned short hardware; |
| 130 | unsigned char password; |
| 131 | char name[7]; |
| 132 | |
| 133 | unsigned long mc_base; |
| 134 | struct resource *res_mc_base; |
| 135 | unsigned long mc_base_size; |
| 136 | #ifdef OPTi93X |
| 137 | unsigned long mc_indir_index; |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 138 | unsigned long mc_indir_size; |
| 139 | struct resource *res_mc_indir; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 140 | struct snd_wss *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | #endif /* OPTi93X */ |
| 142 | unsigned long pwd_reg; |
| 143 | |
| 144 | spinlock_t lock; |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
| 148 | #ifdef CONFIG_PNP |
| 149 | struct pnp_dev *dev; |
| 150 | struct pnp_dev *devmpu; |
| 151 | #endif /* CONFIG_PNP */ |
| 152 | }; |
| 153 | |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 154 | static int snd_opti9xx_pnp_is_probed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | #ifdef CONFIG_PNP |
| 157 | |
| 158 | static struct pnp_card_device_id snd_opti9xx_pnpids[] = { |
| 159 | #ifndef OPTi93X |
| 160 | /* OPTi 82C924 */ |
| 161 | { .id = "OPT0924", .devs = { { "OPT0000" }, { "OPT0002" } }, .driver_data = 0x0924 }, |
| 162 | /* OPTi 82C925 */ |
| 163 | { .id = "OPT0925", .devs = { { "OPT9250" }, { "OPT0002" } }, .driver_data = 0x0925 }, |
| 164 | #else |
| 165 | /* OPTi 82C931/3 */ |
| 166 | { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } }, .driver_data = 0x0931 }, |
| 167 | #endif /* OPTi93X */ |
| 168 | { .id = "" } |
| 169 | }; |
| 170 | |
| 171 | MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids); |
| 172 | |
| 173 | #endif /* CONFIG_PNP */ |
| 174 | |
| 175 | #ifdef OPTi93X |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 176 | #define DEV_NAME "opti93x" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | #else |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 178 | #define DEV_NAME "opti92x" |
| 179 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | static char * snd_opti9xx_names[] = { |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 182 | "unknown", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | "82C928", "82C929", |
| 184 | "82C924", "82C925", |
| 185 | "82C930", "82C931", "82C933" |
| 186 | }; |
| 187 | |
| 188 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 189 | static long __devinit snd_legacy_find_free_ioport(long *port_table, long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
| 191 | while (*port_table != -1) { |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 192 | if (request_region(*port_table, size, "ALSA test")) { |
| 193 | release_region(*port_table, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return *port_table; |
| 195 | } |
| 196 | port_table++; |
| 197 | } |
| 198 | return -1; |
| 199 | } |
| 200 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 201 | static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip, |
| 202 | unsigned short hardware) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2}; |
| 205 | |
| 206 | chip->hardware = hardware; |
| 207 | strcpy(chip->name, snd_opti9xx_names[hardware]); |
| 208 | |
| 209 | chip->mc_base_size = opti9xx_mc_size[hardware]; |
| 210 | |
| 211 | spin_lock_init(&chip->lock); |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | chip->irq = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | switch (hardware) { |
| 216 | #ifndef OPTi93X |
| 217 | case OPTi9XX_HW_82C928: |
| 218 | case OPTi9XX_HW_82C929: |
| 219 | chip->mc_base = 0xf8c; |
| 220 | chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3; |
| 221 | chip->pwd_reg = 3; |
| 222 | break; |
| 223 | |
| 224 | case OPTi9XX_HW_82C924: |
| 225 | case OPTi9XX_HW_82C925: |
| 226 | chip->mc_base = 0xf8c; |
| 227 | chip->password = 0xe5; |
| 228 | chip->pwd_reg = 3; |
| 229 | break; |
| 230 | #else /* OPTi93X */ |
| 231 | |
| 232 | case OPTi9XX_HW_82C930: |
| 233 | case OPTi9XX_HW_82C931: |
| 234 | case OPTi9XX_HW_82C933: |
| 235 | chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d; |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 236 | if (!chip->mc_indir_index) { |
| 237 | chip->mc_indir_index = 0xe0e; |
| 238 | chip->mc_indir_size = 2; |
| 239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | chip->password = 0xe4; |
| 241 | chip->pwd_reg = 0; |
| 242 | break; |
| 243 | #endif /* OPTi93X */ |
| 244 | |
| 245 | default: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 246 | snd_printk(KERN_ERR "chip %d not supported\n", hardware); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return -ENODEV; |
| 248 | } |
| 249 | return 0; |
| 250 | } |
| 251 | |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 252 | static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | unsigned char reg) |
| 254 | { |
| 255 | unsigned long flags; |
| 256 | unsigned char retval = 0xff; |
| 257 | |
| 258 | spin_lock_irqsave(&chip->lock, flags); |
| 259 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 260 | |
| 261 | switch (chip->hardware) { |
| 262 | #ifndef OPTi93X |
| 263 | case OPTi9XX_HW_82C924: |
| 264 | case OPTi9XX_HW_82C925: |
| 265 | if (reg > 7) { |
| 266 | outb(reg, chip->mc_base + 8); |
| 267 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 268 | retval = inb(chip->mc_base + 9); |
| 269 | break; |
| 270 | } |
| 271 | |
| 272 | case OPTi9XX_HW_82C928: |
| 273 | case OPTi9XX_HW_82C929: |
| 274 | retval = inb(chip->mc_base + reg); |
| 275 | break; |
| 276 | #else /* OPTi93X */ |
| 277 | |
| 278 | case OPTi9XX_HW_82C930: |
| 279 | case OPTi9XX_HW_82C931: |
| 280 | case OPTi9XX_HW_82C933: |
| 281 | outb(reg, chip->mc_indir_index); |
| 282 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 283 | retval = inb(chip->mc_indir_index + 1); |
| 284 | break; |
| 285 | #endif /* OPTi93X */ |
| 286 | |
| 287 | default: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 288 | snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | spin_unlock_irqrestore(&chip->lock, flags); |
| 292 | return retval; |
| 293 | } |
| 294 | |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 295 | static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | unsigned char value) |
| 297 | { |
| 298 | unsigned long flags; |
| 299 | |
| 300 | spin_lock_irqsave(&chip->lock, flags); |
| 301 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 302 | |
| 303 | switch (chip->hardware) { |
| 304 | #ifndef OPTi93X |
| 305 | case OPTi9XX_HW_82C924: |
| 306 | case OPTi9XX_HW_82C925: |
| 307 | if (reg > 7) { |
| 308 | outb(reg, chip->mc_base + 8); |
| 309 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 310 | outb(value, chip->mc_base + 9); |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | case OPTi9XX_HW_82C928: |
| 315 | case OPTi9XX_HW_82C929: |
| 316 | outb(value, chip->mc_base + reg); |
| 317 | break; |
| 318 | #else /* OPTi93X */ |
| 319 | |
| 320 | case OPTi9XX_HW_82C930: |
| 321 | case OPTi9XX_HW_82C931: |
| 322 | case OPTi9XX_HW_82C933: |
| 323 | outb(reg, chip->mc_indir_index); |
| 324 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 325 | outb(value, chip->mc_indir_index + 1); |
| 326 | break; |
| 327 | #endif /* OPTi93X */ |
| 328 | |
| 329 | default: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 330 | snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | spin_unlock_irqrestore(&chip->lock, flags); |
| 334 | } |
| 335 | |
| 336 | |
| 337 | #define snd_opti9xx_write_mask(chip, reg, value, mask) \ |
| 338 | snd_opti9xx_write(chip, reg, \ |
| 339 | (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask))) |
| 340 | |
| 341 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 342 | static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip, |
| 343 | long wss_base, |
| 344 | int irq, int dma1, int dma2, |
| 345 | long mpu_port, int mpu_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
| 347 | unsigned char wss_base_bits; |
| 348 | unsigned char irq_bits; |
| 349 | unsigned char dma_bits; |
| 350 | unsigned char mpu_port_bits = 0; |
| 351 | unsigned char mpu_irq_bits; |
| 352 | |
| 353 | switch (chip->hardware) { |
| 354 | #ifndef OPTi93X |
| 355 | case OPTi9XX_HW_82C924: |
| 356 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc); |
| 357 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02); |
| 358 | |
| 359 | case OPTi9XX_HW_82C925: |
| 360 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); |
| 361 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20); |
| 362 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff); |
| 363 | #ifdef CS4231 |
| 364 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); |
| 365 | #else |
| 366 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02); |
| 367 | #endif /* CS4231 */ |
| 368 | break; |
| 369 | |
| 370 | case OPTi9XX_HW_82C928: |
| 371 | case OPTi9XX_HW_82C929: |
| 372 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80); |
| 373 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20); |
| 374 | /* |
| 375 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae); |
| 376 | */ |
| 377 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c); |
| 378 | #ifdef CS4231 |
| 379 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02); |
| 380 | #else |
| 381 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02); |
| 382 | #endif /* CS4231 */ |
| 383 | break; |
| 384 | |
| 385 | #else /* OPTi93X */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | case OPTi9XX_HW_82C931: |
| 387 | case OPTi9XX_HW_82C933: |
Krzysztof Helt | 3ae5f36 | 2008-06-08 07:57:53 +0200 | [diff] [blame] | 388 | /* |
Krzysztof Helt | f81b953 | 2007-10-16 14:54:37 +0200 | [diff] [blame] | 389 | * The BTC 1817DW has QS1000 wavetable which is connected |
| 390 | * to the serial digital input of the OPTI931. |
| 391 | */ |
| 392 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff); |
| 393 | /* |
| 394 | * This bit sets OPTI931 to automaticaly select FM |
| 395 | * or digital input signal. |
| 396 | */ |
| 397 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01); |
Krzysztof Helt | 3ae5f36 | 2008-06-08 07:57:53 +0200 | [diff] [blame] | 398 | case OPTi9XX_HW_82C930: /* FALL THROUGH */ |
| 399 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03); |
| 400 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff); |
| 401 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 | |
| 402 | (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04), |
| 403 | 0x34); |
| 404 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | break; |
| 406 | #endif /* OPTi93X */ |
| 407 | |
| 408 | default: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 409 | snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return -EINVAL; |
| 411 | } |
| 412 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 413 | switch (wss_base) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | case 0x530: |
| 415 | wss_base_bits = 0x00; |
| 416 | break; |
| 417 | case 0x604: |
| 418 | wss_base_bits = 0x03; |
| 419 | break; |
| 420 | case 0xe80: |
| 421 | wss_base_bits = 0x01; |
| 422 | break; |
| 423 | case 0xf40: |
| 424 | wss_base_bits = 0x02; |
| 425 | break; |
| 426 | default: |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 427 | snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", wss_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | goto __skip_base; |
| 429 | } |
| 430 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); |
| 431 | |
| 432 | __skip_base: |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 433 | switch (irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | //#ifdef OPTi93X |
| 435 | case 5: |
| 436 | irq_bits = 0x05; |
| 437 | break; |
| 438 | //#endif /* OPTi93X */ |
| 439 | case 7: |
| 440 | irq_bits = 0x01; |
| 441 | break; |
| 442 | case 9: |
| 443 | irq_bits = 0x02; |
| 444 | break; |
| 445 | case 10: |
| 446 | irq_bits = 0x03; |
| 447 | break; |
| 448 | case 11: |
| 449 | irq_bits = 0x04; |
| 450 | break; |
| 451 | default: |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 452 | snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | goto __skip_resources; |
| 454 | } |
| 455 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 456 | switch (dma1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | case 0: |
| 458 | dma_bits = 0x01; |
| 459 | break; |
| 460 | case 1: |
| 461 | dma_bits = 0x02; |
| 462 | break; |
| 463 | case 3: |
| 464 | dma_bits = 0x03; |
| 465 | break; |
| 466 | default: |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 467 | snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | goto __skip_resources; |
| 469 | } |
| 470 | |
| 471 | #if defined(CS4231) || defined(OPTi93X) |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 472 | if (dma1 == dma2) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 473 | snd_printk(KERN_ERR "don't want to share dmas\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | return -EBUSY; |
| 475 | } |
| 476 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 477 | switch (dma2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | case 0: |
| 479 | case 1: |
| 480 | break; |
| 481 | default: |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 482 | snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | goto __skip_resources; |
| 484 | } |
| 485 | dma_bits |= 0x04; |
| 486 | #endif /* CS4231 || OPTi93X */ |
| 487 | |
| 488 | #ifndef OPTi93X |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 489 | outb(irq_bits << 3 | dma_bits, wss_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | #else /* OPTi93X */ |
| 491 | snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits)); |
| 492 | #endif /* OPTi93X */ |
| 493 | |
| 494 | __skip_resources: |
| 495 | if (chip->hardware > OPTi9XX_HW_82C928) { |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 496 | switch (mpu_port) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | case 0: |
| 498 | case -1: |
| 499 | break; |
| 500 | case 0x300: |
| 501 | mpu_port_bits = 0x03; |
| 502 | break; |
| 503 | case 0x310: |
| 504 | mpu_port_bits = 0x02; |
| 505 | break; |
| 506 | case 0x320: |
| 507 | mpu_port_bits = 0x01; |
| 508 | break; |
| 509 | case 0x330: |
| 510 | mpu_port_bits = 0x00; |
| 511 | break; |
| 512 | default: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 513 | snd_printk(KERN_WARNING |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 514 | "MPU-401 port 0x%lx not valid\n", mpu_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | goto __skip_mpu; |
| 516 | } |
| 517 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 518 | switch (mpu_irq) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | case 5: |
| 520 | mpu_irq_bits = 0x02; |
| 521 | break; |
| 522 | case 7: |
| 523 | mpu_irq_bits = 0x03; |
| 524 | break; |
| 525 | case 9: |
| 526 | mpu_irq_bits = 0x00; |
| 527 | break; |
| 528 | case 10: |
| 529 | mpu_irq_bits = 0x01; |
| 530 | break; |
| 531 | default: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 532 | snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n", |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 533 | mpu_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | goto __skip_mpu; |
| 535 | } |
| 536 | |
| 537 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 538 | (mpu_port <= 0) ? 0x00 : |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3, |
| 540 | 0xf8); |
| 541 | } |
| 542 | __skip_mpu: |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | #ifdef OPTi93X |
| 548 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 549 | static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Krzysztof Helt | 5f60e49 | 2009-12-09 20:12:43 +0100 | [diff] [blame] | 551 | struct snd_opti9xx *chip = dev_id; |
| 552 | struct snd_wss *codec = chip->codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | unsigned char status; |
| 554 | |
Krzysztof Helt | 5f60e49 | 2009-12-09 20:12:43 +0100 | [diff] [blame] | 555 | if (!codec) |
| 556 | return IRQ_HANDLED; |
| 557 | |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 558 | status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream) |
| 560 | snd_pcm_period_elapsed(codec->playback_substream); |
| 561 | if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 562 | snd_wss_overrange(codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | snd_pcm_period_elapsed(codec->capture_substream); |
| 564 | } |
| 565 | outb(0x00, OPTi93X_PORT(codec, STATUS)); |
| 566 | return IRQ_HANDLED; |
| 567 | } |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | #endif /* OPTi93X */ |
| 570 | |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 571 | static int __devinit snd_opti9xx_read_check(struct snd_opti9xx *chip) |
| 572 | { |
| 573 | unsigned char value; |
| 574 | #ifdef OPTi93X |
| 575 | unsigned long flags; |
| 576 | #endif |
| 577 | |
| 578 | chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, |
| 579 | "OPTi9xx MC"); |
| 580 | if (chip->res_mc_base == NULL) |
| 581 | return -EBUSY; |
| 582 | #ifndef OPTi93X |
| 583 | value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)); |
| 584 | if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1))) |
| 585 | if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1))) |
| 586 | return 0; |
| 587 | #else /* OPTi93X */ |
| 588 | chip->res_mc_indir = request_region(chip->mc_indir_index, |
| 589 | chip->mc_indir_size, |
| 590 | "OPTi93x MC"); |
| 591 | if (chip->res_mc_indir == NULL) |
| 592 | return -EBUSY; |
| 593 | |
| 594 | spin_lock_irqsave(&chip->lock, flags); |
| 595 | outb(chip->password, chip->mc_base + chip->pwd_reg); |
| 596 | outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base); |
| 597 | spin_unlock_irqrestore(&chip->lock, flags); |
| 598 | |
| 599 | value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)); |
| 600 | snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value); |
| 601 | if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value) |
| 602 | return 0; |
| 603 | |
| 604 | release_and_free_resource(chip->res_mc_indir); |
| 605 | chip->res_mc_indir = NULL; |
| 606 | #endif /* OPTi93X */ |
| 607 | release_and_free_resource(chip->res_mc_base); |
| 608 | chip->res_mc_base = NULL; |
| 609 | |
| 610 | return -ENODEV; |
| 611 | } |
| 612 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 613 | static int __devinit snd_card_opti9xx_detect(struct snd_card *card, |
| 614 | struct snd_opti9xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
| 616 | int i, err; |
| 617 | |
| 618 | #ifndef OPTi93X |
| 619 | for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) { |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 620 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) { |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 622 | #endif |
| 623 | err = snd_opti9xx_init(chip, i); |
| 624 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return err; |
| 626 | |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 627 | err = snd_opti9xx_read_check(chip); |
| 628 | if (err == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | return 1; |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 630 | #ifdef OPTi93X |
| 631 | chip->mc_indir_index = 0; |
| 632 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return -ENODEV; |
| 635 | } |
| 636 | |
| 637 | #ifdef CONFIG_PNP |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 638 | static int __devinit snd_card_opti9xx_pnp(struct snd_opti9xx *chip, |
| 639 | struct pnp_card_link *card, |
| 640 | const struct pnp_card_device_id *pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
| 642 | struct pnp_dev *pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | int err; |
| 644 | |
| 645 | chip->dev = pnp_request_card_device(card, pid->devs[0].id, NULL); |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 646 | if (chip->dev == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | return -EBUSY; |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | chip->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL); |
| 650 | |
| 651 | pdev = chip->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | err = pnp_activate_dev(pdev); |
| 654 | if (err < 0) { |
| 655 | snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | return err; |
| 657 | } |
| 658 | |
| 659 | #ifdef OPTi93X |
| 660 | port = pnp_port_start(pdev, 0) - 4; |
Takashi Iwai | 1ea7341 | 2007-09-17 16:44:06 +0200 | [diff] [blame] | 661 | fm_port = pnp_port_start(pdev, 1) + 8; |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 662 | chip->mc_indir_index = pnp_port_start(pdev, 3) + 2; |
| 663 | chip->mc_indir_size = pnp_port_len(pdev, 3) - 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | #else |
| 665 | if (pid->driver_data != 0x0924) |
| 666 | port = pnp_port_start(pdev, 1); |
Takashi Iwai | 1ea7341 | 2007-09-17 16:44:06 +0200 | [diff] [blame] | 667 | fm_port = pnp_port_start(pdev, 2) + 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | #endif /* OPTi93X */ |
| 669 | irq = pnp_irq(pdev, 0); |
| 670 | dma1 = pnp_dma(pdev, 0); |
| 671 | #if defined(CS4231) || defined(OPTi93X) |
| 672 | dma2 = pnp_dma(pdev, 1); |
| 673 | #endif /* CS4231 || OPTi93X */ |
| 674 | |
| 675 | pdev = chip->devmpu; |
| 676 | if (pdev && mpu_port > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | err = pnp_activate_dev(pdev); |
| 678 | if (err < 0) { |
| 679 | snd_printk(KERN_ERR "AUDIO pnp configure failure\n"); |
| 680 | mpu_port = -1; |
| 681 | chip->devmpu = NULL; |
| 682 | } else { |
| 683 | mpu_port = pnp_port_start(pdev, 0); |
| 684 | mpu_irq = pnp_irq(pdev, 0); |
| 685 | } |
| 686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return pid->driver_data; |
| 688 | } |
| 689 | #endif /* CONFIG_PNP */ |
| 690 | |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 691 | static void snd_card_opti9xx_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 693 | struct snd_opti9xx *chip = card->private_data; |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 694 | |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 695 | if (chip) { |
| 696 | #ifdef OPTi93X |
Krzysztof Helt | 5f60e49 | 2009-12-09 20:12:43 +0100 | [diff] [blame] | 697 | if (chip->irq > 0) { |
| 698 | disable_irq(chip->irq); |
| 699 | free_irq(chip->irq, chip); |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 700 | } |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 701 | release_and_free_resource(chip->res_mc_indir); |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 702 | #endif |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 703 | release_and_free_resource(chip->res_mc_base); |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 704 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 707 | static int __devinit snd_opti9xx_probe(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | { |
| 709 | static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | int error; |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 711 | int xdma2; |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 712 | struct snd_opti9xx *chip = card->private_data; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 713 | struct snd_wss *codec; |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 714 | #ifdef CS4231 |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 715 | struct snd_timer *timer; |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 716 | #endif |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 717 | struct snd_pcm *pcm; |
| 718 | struct snd_rawmidi *rmidi; |
| 719 | struct snd_hwdep *synth; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | #if defined(CS4231) || defined(OPTi93X) |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 722 | xdma2 = dma2; |
Rene Herman | a0d9274 | 2008-08-04 05:26:26 +0200 | [diff] [blame] | 723 | #else |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 724 | xdma2 = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | #endif |
| 726 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 727 | if (port == SNDRV_AUTO_PORT) { |
| 728 | port = snd_legacy_find_free_ioport(possible_ports, 4); |
| 729 | if (port < 0) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 730 | snd_printk(KERN_ERR "unable to find a free WSS port\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | return -EBUSY; |
| 732 | } |
| 733 | } |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 734 | error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2, |
| 735 | mpu_port, mpu_irq); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 736 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 739 | error = snd_wss_create(card, port + 4, -1, irq, dma1, xdma2, |
Rene Herman | a0d9274 | 2008-08-04 05:26:26 +0200 | [diff] [blame] | 740 | #ifdef OPTi93X |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 741 | WSS_HW_OPTI93X, WSS_HWSHARE_IRQ, |
Rene Herman | a0d9274 | 2008-08-04 05:26:26 +0200 | [diff] [blame] | 742 | #else |
| 743 | WSS_HW_DETECT, 0, |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 744 | #endif |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 745 | &codec); |
| 746 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | return error; |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 748 | #ifdef OPTi93X |
| 749 | chip->codec = codec; |
| 750 | #endif |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 751 | error = snd_wss_pcm(codec, 0, &pcm); |
Krzysztof Helt | 5664daa | 2008-07-31 21:08:32 +0200 | [diff] [blame] | 752 | if (error < 0) |
| 753 | return error; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 754 | error = snd_wss_mixer(codec); |
| 755 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | return error; |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 757 | #ifdef CS4231 |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 758 | error = snd_wss_timer(codec, 0, &timer); |
| 759 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | return error; |
Krzysztof Helt | 5664daa | 2008-07-31 21:08:32 +0200 | [diff] [blame] | 761 | #endif |
| 762 | #ifdef OPTi93X |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 763 | error = request_irq(irq, snd_opti93x_interrupt, |
Krzysztof Helt | 5f60e49 | 2009-12-09 20:12:43 +0100 | [diff] [blame] | 764 | IRQF_DISABLED, DEV_NAME" - WSS", chip); |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 765 | if (error < 0) { |
Krzysztof Helt | 5f60e49 | 2009-12-09 20:12:43 +0100 | [diff] [blame] | 766 | snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq); |
Krzysztof Helt | 9f240a5 | 2008-06-11 12:26:32 +0200 | [diff] [blame] | 767 | return error; |
| 768 | } |
| 769 | #endif |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 770 | chip->irq = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | strcpy(card->driver, chip->name); |
| 772 | sprintf(card->shortname, "OPTi %s", card->driver); |
| 773 | #if defined(CS4231) || defined(OPTi93X) |
| 774 | sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d", |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 775 | card->shortname, pcm->name, port + 4, irq, dma1, xdma2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | #else |
| 777 | sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d", |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 778 | card->shortname, pcm->name, port + 4, irq, dma1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | #endif /* CS4231 || OPTi93X */ |
| 780 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 781 | if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | rmidi = NULL; |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 783 | else { |
| 784 | error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, |
| 785 | mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi); |
| 786 | if (error) |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 787 | snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 788 | mpu_port); |
| 789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 791 | if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) { |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 792 | struct snd_opl3 *opl3 = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | #ifndef OPTi93X |
| 794 | if (chip->hardware == OPTi9XX_HW_82C928 || |
| 795 | chip->hardware == OPTi9XX_HW_82C929 || |
| 796 | chip->hardware == OPTi9XX_HW_82C924) { |
Takashi Iwai | 346c7a6 | 2005-11-17 14:37:56 +0100 | [diff] [blame] | 797 | struct snd_opl4 *opl4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | /* assume we have an OPL4 */ |
| 799 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), |
| 800 | 0x20, 0x20); |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 801 | if (snd_opl4_create(card, fm_port, fm_port - 8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | 2, &opl3, &opl4) < 0) { |
| 803 | /* no luck, use OPL3 instead */ |
| 804 | snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), |
| 805 | 0x00, 0x20); |
| 806 | } |
| 807 | } |
| 808 | #endif /* !OPTi93X */ |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 809 | if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | OPL3_HW_AUTO, 0, &opl3) < 0) { |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 811 | snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n", |
Krzysztof Helt | d8ea239 | 2009-12-02 23:27:12 +0100 | [diff] [blame] | 812 | fm_port, fm_port + 4 - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | if (opl3) { |
Krzysztof Helt | aa9c293 | 2009-01-21 15:08:03 +0100 | [diff] [blame] | 815 | error = snd_opl3_hwdep_new(opl3, 0, 1, &synth); |
| 816 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 821 | return snd_card_register(card); |
| 822 | } |
| 823 | |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 824 | static int snd_opti9xx_card_new(struct snd_card **cardp) |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 825 | { |
| 826 | struct snd_card *card; |
Takashi Iwai | b1a0aac | 2009-01-14 09:34:06 +0100 | [diff] [blame] | 827 | int err; |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 828 | |
Takashi Iwai | c95eadd | 2008-12-28 16:43:35 +0100 | [diff] [blame] | 829 | err = snd_card_create(index, id, THIS_MODULE, |
| 830 | sizeof(struct snd_opti9xx), &card); |
| 831 | if (err < 0) |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 832 | return err; |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 833 | card->private_free = snd_card_opti9xx_free; |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 834 | *cardp = card; |
| 835 | return 0; |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 836 | } |
| 837 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 838 | static int __devinit snd_opti9xx_isa_match(struct device *devptr, |
| 839 | unsigned int dev) |
| 840 | { |
Takashi Iwai | 101f6f4 | 2007-06-20 12:03:09 +0200 | [diff] [blame] | 841 | #ifdef CONFIG_PNP |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 842 | if (snd_opti9xx_pnp_is_probed) |
| 843 | return 0; |
| 844 | if (isapnp) |
| 845 | return 0; |
Takashi Iwai | 101f6f4 | 2007-06-20 12:03:09 +0200 | [diff] [blame] | 846 | #endif |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 847 | return 1; |
| 848 | } |
| 849 | |
| 850 | static int __devinit snd_opti9xx_isa_probe(struct device *devptr, |
| 851 | unsigned int dev) |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 852 | { |
| 853 | struct snd_card *card; |
| 854 | int error; |
| 855 | static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1}; |
| 856 | #ifdef OPTi93X |
| 857 | static int possible_irqs[] = {5, 9, 10, 11, 7, -1}; |
| 858 | #else |
| 859 | static int possible_irqs[] = {9, 10, 11, 7, -1}; |
| 860 | #endif /* OPTi93X */ |
| 861 | static int possible_mpu_irqs[] = {5, 9, 10, 7, -1}; |
| 862 | static int possible_dma1s[] = {3, 1, 0, -1}; |
| 863 | #if defined(CS4231) || defined(OPTi93X) |
| 864 | static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}}; |
| 865 | #endif /* CS4231 || OPTi93X */ |
| 866 | |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 867 | if (mpu_port == SNDRV_AUTO_PORT) { |
| 868 | if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) { |
| 869 | snd_printk(KERN_ERR "unable to find a free MPU401 port\n"); |
| 870 | return -EBUSY; |
| 871 | } |
| 872 | } |
| 873 | if (irq == SNDRV_AUTO_IRQ) { |
| 874 | if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) { |
| 875 | snd_printk(KERN_ERR "unable to find a free IRQ\n"); |
| 876 | return -EBUSY; |
| 877 | } |
| 878 | } |
| 879 | if (mpu_irq == SNDRV_AUTO_IRQ) { |
| 880 | if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) { |
| 881 | snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n"); |
| 882 | return -EBUSY; |
| 883 | } |
| 884 | } |
| 885 | if (dma1 == SNDRV_AUTO_DMA) { |
| 886 | if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) { |
| 887 | snd_printk(KERN_ERR "unable to find a free DMA1\n"); |
| 888 | return -EBUSY; |
| 889 | } |
| 890 | } |
| 891 | #if defined(CS4231) || defined(OPTi93X) |
| 892 | if (dma2 == SNDRV_AUTO_DMA) { |
| 893 | if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 894 | snd_printk(KERN_ERR "unable to find a free DMA2\n"); |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 895 | return -EBUSY; |
| 896 | } |
| 897 | } |
| 898 | #endif |
| 899 | |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 900 | error = snd_opti9xx_card_new(&card); |
| 901 | if (error < 0) |
| 902 | return error; |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 903 | |
| 904 | if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | snd_card_free(card); |
| 906 | return error; |
| 907 | } |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 908 | snd_card_set_dev(card, devptr); |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 909 | if ((error = snd_opti9xx_probe(card)) < 0) { |
| 910 | snd_card_free(card); |
| 911 | return error; |
| 912 | } |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 913 | dev_set_drvdata(devptr, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | return 0; |
| 915 | } |
| 916 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 917 | static int __devexit snd_opti9xx_isa_remove(struct device *devptr, |
| 918 | unsigned int dev) |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 919 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 920 | snd_card_free(dev_get_drvdata(devptr)); |
| 921 | dev_set_drvdata(devptr, NULL); |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 922 | return 0; |
| 923 | } |
| 924 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 925 | static struct isa_driver snd_opti9xx_driver = { |
| 926 | .match = snd_opti9xx_isa_match, |
| 927 | .probe = snd_opti9xx_isa_probe, |
| 928 | .remove = __devexit_p(snd_opti9xx_isa_remove), |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 929 | /* FIXME: suspend/resume */ |
| 930 | .driver = { |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 931 | .name = DEV_NAME |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 932 | }, |
| 933 | }; |
| 934 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | #ifdef CONFIG_PNP |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 936 | static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard, |
| 937 | const struct pnp_card_device_id *pid) |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 938 | { |
| 939 | struct snd_card *card; |
| 940 | int error, hw; |
| 941 | struct snd_opti9xx *chip; |
| 942 | |
| 943 | if (snd_opti9xx_pnp_is_probed) |
| 944 | return -EBUSY; |
| 945 | if (! isapnp) |
| 946 | return -ENODEV; |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 947 | error = snd_opti9xx_card_new(&card); |
| 948 | if (error < 0) |
| 949 | return error; |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 950 | chip = card->private_data; |
| 951 | |
| 952 | hw = snd_card_opti9xx_pnp(chip, pcard, pid); |
| 953 | switch (hw) { |
| 954 | case 0x0924: |
| 955 | hw = OPTi9XX_HW_82C924; |
| 956 | break; |
| 957 | case 0x0925: |
| 958 | hw = OPTi9XX_HW_82C925; |
| 959 | break; |
| 960 | case 0x0931: |
| 961 | hw = OPTi9XX_HW_82C931; |
| 962 | break; |
| 963 | default: |
| 964 | snd_card_free(card); |
| 965 | return -ENODEV; |
| 966 | } |
| 967 | |
| 968 | if ((error = snd_opti9xx_init(chip, hw))) { |
| 969 | snd_card_free(card); |
| 970 | return error; |
| 971 | } |
| 972 | if (hw <= OPTi9XX_HW_82C930) |
| 973 | chip->mc_base -= 0x80; |
Krzysztof Helt | e6960e1 | 2009-12-04 18:30:18 +0100 | [diff] [blame] | 974 | |
| 975 | error = snd_opti9xx_read_check(chip); |
| 976 | if (error) { |
| 977 | snd_printk(KERN_ERR "OPTI chip not found\n"); |
| 978 | snd_card_free(card); |
| 979 | return error; |
| 980 | } |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 981 | snd_card_set_dev(card, &pcard->card->dev); |
| 982 | if ((error = snd_opti9xx_probe(card)) < 0) { |
| 983 | snd_card_free(card); |
| 984 | return error; |
| 985 | } |
| 986 | pnp_set_card_drvdata(pcard, card); |
| 987 | snd_opti9xx_pnp_is_probed = 1; |
| 988 | return 0; |
| 989 | } |
| 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | static void __devexit snd_opti9xx_pnp_remove(struct pnp_card_link * pcard) |
| 992 | { |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 993 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 994 | pnp_set_card_drvdata(pcard, NULL); |
| 995 | snd_opti9xx_pnp_is_probed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static struct pnp_card_driver opti9xx_pnpc_driver = { |
| 999 | .flags = PNP_DRIVER_RES_DISABLE, |
| 1000 | .name = "opti9xx", |
| 1001 | .id_table = snd_opti9xx_pnpids, |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 1002 | .probe = snd_opti9xx_pnp_probe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | .remove = __devexit_p(snd_opti9xx_pnp_remove), |
| 1004 | }; |
| 1005 | #endif |
| 1006 | |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 1007 | #ifdef OPTi93X |
| 1008 | #define CHIP_NAME "82C93x" |
| 1009 | #else |
| 1010 | #define CHIP_NAME "82C92x" |
| 1011 | #endif |
| 1012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | static int __init alsa_card_opti9xx_init(void) |
| 1014 | { |
Takashi Iwai | 0bbbc4c | 2006-02-27 17:23:46 +0100 | [diff] [blame] | 1015 | #ifdef CONFIG_PNP |
Takashi Iwai | 99a0b76 | 2005-11-17 17:13:59 +0100 | [diff] [blame] | 1016 | pnp_register_card_driver(&opti9xx_pnpc_driver); |
| 1017 | if (snd_opti9xx_pnp_is_probed) |
| 1018 | return 0; |
Takashi Iwai | 101f6f4 | 2007-06-20 12:03:09 +0200 | [diff] [blame] | 1019 | pnp_unregister_card_driver(&opti9xx_pnpc_driver); |
Takashi Iwai | 0bbbc4c | 2006-02-27 17:23:46 +0100 | [diff] [blame] | 1020 | #endif |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1021 | return isa_register_driver(&snd_opti9xx_driver, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | static void __exit alsa_card_opti9xx_exit(void) |
| 1025 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 1026 | if (!snd_opti9xx_pnp_is_probed) { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 1027 | isa_unregister_driver(&snd_opti9xx_driver); |
| 1028 | return; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 1029 | } |
Takashi Iwai | 0bbbc4c | 2006-02-27 17:23:46 +0100 | [diff] [blame] | 1030 | #ifdef CONFIG_PNP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | pnp_unregister_card_driver(&opti9xx_pnpc_driver); |
Takashi Iwai | 0bbbc4c | 2006-02-27 17:23:46 +0100 | [diff] [blame] | 1032 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | module_init(alsa_card_opti9xx_init) |
| 1036 | module_exit(alsa_card_opti9xx_exit) |