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