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