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