Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for generic ESS AudioDrive ES18xx soundcards |
| 3 | * Copyright (c) by Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de> |
| 4 | * Copyright (c) by Abramo Bagnara <abramo@alsa-project.org> |
| 5 | * |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | */ |
| 22 | /* GENERAL NOTES: |
| 23 | * |
| 24 | * BUGS: |
| 25 | * - There are pops (we can't delay in trigger function, cause midlevel |
| 26 | * often need to trigger down and then up very quickly). |
| 27 | * Any ideas? |
| 28 | * - Support for 16 bit DMA seems to be broken. I've no hardware to tune it. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | * ES1868 NOTES: |
| 33 | * - The chip has one half duplex pcm (with very limited full duplex support). |
| 34 | * |
| 35 | * - Duplex stereophonic sound is impossible. |
| 36 | * - Record and playback must share the same frequency rate. |
| 37 | * |
| 38 | * - The driver use dma2 for playback and dma1 for capture. |
| 39 | */ |
| 40 | |
| 41 | /* |
| 42 | * ES1869 NOTES: |
| 43 | * |
| 44 | * - there are a first full duplex pcm and a second playback only pcm |
| 45 | * (incompatible with first pcm capture) |
| 46 | * |
| 47 | * - there is support for the capture volume and ESS Spatializer 3D effect. |
| 48 | * |
| 49 | * - contrarily to some pages in DS_1869.PDF the rates can be set |
| 50 | * independently. |
| 51 | * |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 52 | * - Zoom Video is implemented by sharing the FM DAC, thus the user can |
| 53 | * have either FM playback or Video playback but not both simultaneously. |
| 54 | * The Video Playback Switch mixer control toggles this choice. |
| 55 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | * BUGS: |
| 57 | * |
| 58 | * - There is a major trouble I noted: |
| 59 | * |
| 60 | * using both channel for playback stereo 16 bit samples at 44100 Hz |
| 61 | * the second pcm (Audio1) DMA slows down irregularly and sound is garbled. |
| 62 | * |
| 63 | * The same happens using Audio1 for captureing. |
| 64 | * |
| 65 | * The Windows driver does not suffer of this (although it use Audio1 |
| 66 | * only for captureing). I'm unable to discover why. |
| 67 | * |
| 68 | */ |
| 69 | |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 70 | /* |
| 71 | * ES1879 NOTES: |
| 72 | * - When Zoom Video is enabled (reg 0x71 bit 6 toggled on) the PCM playback |
| 73 | * seems to be effected (speaker_test plays a lower frequency). Can't find |
| 74 | * anything in the datasheet to account for this, so a Video Playback Switch |
| 75 | * control has been included to allow ZV to be enabled only when necessary. |
| 76 | * Then again on at least one test system the 0x71 bit 6 enable bit is not |
| 77 | * needed for ZV, so maybe the datasheet is entirely wrong here. |
| 78 | */ |
| 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #include <linux/init.h> |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 81 | #include <linux/err.h> |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 82 | #include <linux/isa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | #include <linux/slab.h> |
| 84 | #include <linux/pnp.h> |
| 85 | #include <linux/isapnp.h> |
| 86 | #include <linux/moduleparam.h> |
Andrew Morton | 1caef6a | 2006-05-20 15:00:35 -0700 | [diff] [blame] | 87 | #include <linux/delay.h> |
| 88 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 89 | #include <asm/io.h> |
| 90 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #include <sound/core.h> |
| 92 | #include <sound/control.h> |
| 93 | #include <sound/pcm.h> |
| 94 | #include <sound/pcm_params.h> |
| 95 | #include <sound/mpu401.h> |
| 96 | #include <sound/opl3.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 98 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 99 | #include <sound/initval.h> |
| 100 | |
| 101 | #define PFX "es18xx: " |
| 102 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 103 | struct snd_es18xx { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | unsigned long port; /* port of ESS chip */ |
| 105 | unsigned long mpu_port; /* MPU-401 port of ESS chip */ |
| 106 | unsigned long fm_port; /* FM port */ |
| 107 | unsigned long ctrl_port; /* Control port of ESS chip */ |
| 108 | struct resource *res_port; |
| 109 | struct resource *res_mpu_port; |
| 110 | struct resource *res_ctrl_port; |
| 111 | int irq; /* IRQ number of ESS chip */ |
| 112 | int dma1; /* DMA1 */ |
| 113 | int dma2; /* DMA2 */ |
| 114 | unsigned short version; /* version of ESS chip */ |
| 115 | int caps; /* Chip capabilities */ |
| 116 | unsigned short audio2_vol; /* volume level of audio2 */ |
| 117 | |
| 118 | unsigned short active; /* active channel mask */ |
| 119 | unsigned int dma1_size; |
| 120 | unsigned int dma2_size; |
| 121 | unsigned int dma1_shift; |
| 122 | unsigned int dma2_shift; |
| 123 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 124 | struct snd_pcm *pcm; |
| 125 | struct snd_pcm_substream *playback_a_substream; |
| 126 | struct snd_pcm_substream *capture_a_substream; |
| 127 | struct snd_pcm_substream *playback_b_substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 129 | struct snd_rawmidi *rmidi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 131 | struct snd_kcontrol *hw_volume; |
| 132 | struct snd_kcontrol *hw_switch; |
| 133 | struct snd_kcontrol *master_volume; |
| 134 | struct snd_kcontrol *master_switch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | spinlock_t reg_lock; |
| 137 | spinlock_t mixer_lock; |
| 138 | spinlock_t ctrl_lock; |
| 139 | #ifdef CONFIG_PM |
| 140 | unsigned char pm_reg; |
| 141 | #endif |
| 142 | }; |
| 143 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 144 | struct snd_audiodrive { |
| 145 | struct snd_es18xx *chip; |
| 146 | #ifdef CONFIG_PNP |
| 147 | struct pnp_dev *dev; |
| 148 | struct pnp_dev *devc; |
| 149 | #endif |
| 150 | }; |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | #define AUDIO1_IRQ 0x01 |
| 153 | #define AUDIO2_IRQ 0x02 |
| 154 | #define HWV_IRQ 0x04 |
| 155 | #define MPU_IRQ 0x08 |
| 156 | |
| 157 | #define ES18XX_PCM2 0x0001 /* Has two useable PCM */ |
| 158 | #define ES18XX_SPATIALIZER 0x0002 /* Has 3D Spatializer */ |
| 159 | #define ES18XX_RECMIX 0x0004 /* Has record mixer */ |
| 160 | #define ES18XX_DUPLEX_MONO 0x0008 /* Has mono duplex only */ |
| 161 | #define ES18XX_DUPLEX_SAME 0x0010 /* Playback and record must share the same rate */ |
| 162 | #define ES18XX_NEW_RATE 0x0020 /* More precise rate setting */ |
| 163 | #define ES18XX_AUXB 0x0040 /* AuxB mixer control */ |
Joe Perches | 561de31 | 2007-12-18 13:13:47 +0100 | [diff] [blame] | 164 | #define ES18XX_HWV 0x0080 /* Has separate hardware volume mixer controls*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | #define ES18XX_MONO 0x0100 /* Mono_in mixer control */ |
| 166 | #define ES18XX_I2S 0x0200 /* I2S mixer control */ |
| 167 | #define ES18XX_MUTEREC 0x0400 /* Record source can be muted */ |
| 168 | #define ES18XX_CONTROL 0x0800 /* Has control ports */ |
| 169 | |
| 170 | /* Power Management */ |
| 171 | #define ES18XX_PM 0x07 |
| 172 | #define ES18XX_PM_GPO0 0x01 |
| 173 | #define ES18XX_PM_GPO1 0x02 |
| 174 | #define ES18XX_PM_PDR 0x04 |
| 175 | #define ES18XX_PM_ANA 0x08 |
| 176 | #define ES18XX_PM_FM 0x020 |
| 177 | #define ES18XX_PM_SUS 0x080 |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* Lowlevel */ |
| 180 | |
| 181 | #define DAC1 0x01 |
| 182 | #define ADC1 0x02 |
| 183 | #define DAC2 0x04 |
| 184 | #define MILLISECOND 10000 |
| 185 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 186 | static int snd_es18xx_dsp_command(struct snd_es18xx *chip, unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | int i; |
| 189 | |
| 190 | for(i = MILLISECOND; i; i--) |
| 191 | if ((inb(chip->port + 0x0C) & 0x80) == 0) { |
| 192 | outb(val, chip->port + 0x0C); |
| 193 | return 0; |
| 194 | } |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 195 | snd_printk(KERN_ERR "dsp_command: timeout (0x%x)\n", val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | return -EINVAL; |
| 197 | } |
| 198 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 199 | static int snd_es18xx_dsp_get_byte(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
| 201 | int i; |
| 202 | |
| 203 | for(i = MILLISECOND/10; i; i--) |
| 204 | if (inb(chip->port + 0x0C) & 0x40) |
| 205 | return inb(chip->port + 0x0A); |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 206 | snd_printk(KERN_ERR "dsp_get_byte failed: 0x%lx = 0x%x!!!\n", |
| 207 | chip->port + 0x0A, inb(chip->port + 0x0A)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | return -ENODEV; |
| 209 | } |
| 210 | |
| 211 | #undef REG_DEBUG |
| 212 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 213 | static int snd_es18xx_write(struct snd_es18xx *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | unsigned char reg, unsigned char data) |
| 215 | { |
| 216 | unsigned long flags; |
| 217 | int ret; |
| 218 | |
| 219 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 220 | ret = snd_es18xx_dsp_command(chip, reg); |
| 221 | if (ret < 0) |
| 222 | goto end; |
| 223 | ret = snd_es18xx_dsp_command(chip, data); |
| 224 | end: |
| 225 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 226 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 227 | snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | #endif |
| 229 | return ret; |
| 230 | } |
| 231 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 232 | static int snd_es18xx_read(struct snd_es18xx *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
| 234 | unsigned long flags; |
| 235 | int ret, data; |
| 236 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 237 | ret = snd_es18xx_dsp_command(chip, 0xC0); |
| 238 | if (ret < 0) |
| 239 | goto end; |
| 240 | ret = snd_es18xx_dsp_command(chip, reg); |
| 241 | if (ret < 0) |
| 242 | goto end; |
| 243 | data = snd_es18xx_dsp_get_byte(chip); |
| 244 | ret = data; |
| 245 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 246 | snd_printk(KERN_DEBUG "Reg %02x now is %02x (%d)\n", reg, data, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | #endif |
| 248 | end: |
| 249 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 250 | return ret; |
| 251 | } |
| 252 | |
| 253 | /* Return old value */ |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 254 | static int snd_es18xx_bits(struct snd_es18xx *chip, unsigned char reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | unsigned char mask, unsigned char val) |
| 256 | { |
| 257 | int ret; |
| 258 | unsigned char old, new, oval; |
| 259 | unsigned long flags; |
| 260 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 261 | ret = snd_es18xx_dsp_command(chip, 0xC0); |
| 262 | if (ret < 0) |
| 263 | goto end; |
| 264 | ret = snd_es18xx_dsp_command(chip, reg); |
| 265 | if (ret < 0) |
| 266 | goto end; |
| 267 | ret = snd_es18xx_dsp_get_byte(chip); |
| 268 | if (ret < 0) { |
| 269 | goto end; |
| 270 | } |
| 271 | old = ret; |
| 272 | oval = old & mask; |
| 273 | if (val != oval) { |
| 274 | ret = snd_es18xx_dsp_command(chip, reg); |
| 275 | if (ret < 0) |
| 276 | goto end; |
| 277 | new = (old & ~mask) | (val & mask); |
| 278 | ret = snd_es18xx_dsp_command(chip, new); |
| 279 | if (ret < 0) |
| 280 | goto end; |
| 281 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 282 | snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x (%d)\n", |
| 283 | reg, old, new, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | #endif |
| 285 | } |
| 286 | ret = oval; |
| 287 | end: |
| 288 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 289 | return ret; |
| 290 | } |
| 291 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 292 | static inline void snd_es18xx_mixer_write(struct snd_es18xx *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | unsigned char reg, unsigned char data) |
| 294 | { |
| 295 | unsigned long flags; |
| 296 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 297 | outb(reg, chip->port + 0x04); |
| 298 | outb(data, chip->port + 0x05); |
| 299 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 300 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 301 | snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | #endif |
| 303 | } |
| 304 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 305 | static inline int snd_es18xx_mixer_read(struct snd_es18xx *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
| 307 | unsigned long flags; |
| 308 | int data; |
| 309 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 310 | outb(reg, chip->port + 0x04); |
| 311 | data = inb(chip->port + 0x05); |
| 312 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 313 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 314 | snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | #endif |
| 316 | return data; |
| 317 | } |
| 318 | |
| 319 | /* Return old value */ |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 320 | static inline int snd_es18xx_mixer_bits(struct snd_es18xx *chip, unsigned char reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | unsigned char mask, unsigned char val) |
| 322 | { |
| 323 | unsigned char old, new, oval; |
| 324 | unsigned long flags; |
| 325 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 326 | outb(reg, chip->port + 0x04); |
| 327 | old = inb(chip->port + 0x05); |
| 328 | oval = old & mask; |
| 329 | if (val != oval) { |
| 330 | new = (old & ~mask) | (val & mask); |
| 331 | outb(new, chip->port + 0x05); |
| 332 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 333 | snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n", |
| 334 | reg, old, new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | #endif |
| 336 | } |
| 337 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 338 | return oval; |
| 339 | } |
| 340 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 341 | static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned char reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | unsigned char mask) |
| 343 | { |
| 344 | int old, expected, new; |
| 345 | unsigned long flags; |
| 346 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 347 | outb(reg, chip->port + 0x04); |
| 348 | old = inb(chip->port + 0x05); |
| 349 | expected = old ^ mask; |
| 350 | outb(expected, chip->port + 0x05); |
| 351 | new = inb(chip->port + 0x05); |
| 352 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 353 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 354 | snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x, now is %02x\n", |
| 355 | reg, old, expected, new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | #endif |
| 357 | return expected == new; |
| 358 | } |
| 359 | |
| 360 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 361 | static int snd_es18xx_reset(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
| 363 | int i; |
| 364 | outb(0x03, chip->port + 0x06); |
| 365 | inb(chip->port + 0x06); |
| 366 | outb(0x00, chip->port + 0x06); |
| 367 | for(i = 0; i < MILLISECOND && !(inb(chip->port + 0x0E) & 0x80); i++); |
| 368 | if (inb(chip->port + 0x0A) != 0xAA) |
| 369 | return -1; |
| 370 | return 0; |
| 371 | } |
| 372 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 373 | static int snd_es18xx_reset_fifo(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
| 375 | outb(0x02, chip->port + 0x06); |
| 376 | inb(chip->port + 0x06); |
| 377 | outb(0x00, chip->port + 0x06); |
| 378 | return 0; |
| 379 | } |
| 380 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 381 | static struct snd_ratnum new_clocks[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
| 383 | .num = 793800, |
| 384 | .den_min = 1, |
| 385 | .den_max = 128, |
| 386 | .den_step = 1, |
| 387 | }, |
| 388 | { |
| 389 | .num = 768000, |
| 390 | .den_min = 1, |
| 391 | .den_max = 128, |
| 392 | .den_step = 1, |
| 393 | } |
| 394 | }; |
| 395 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 396 | static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | .nrats = 2, |
| 398 | .rats = new_clocks, |
| 399 | }; |
| 400 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 401 | static struct snd_ratnum old_clocks[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
| 403 | .num = 795444, |
| 404 | .den_min = 1, |
| 405 | .den_max = 128, |
| 406 | .den_step = 1, |
| 407 | }, |
| 408 | { |
| 409 | .num = 397722, |
| 410 | .den_min = 1, |
| 411 | .den_max = 128, |
| 412 | .den_step = 1, |
| 413 | } |
| 414 | }; |
| 415 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 416 | static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | .nrats = 2, |
| 418 | .rats = old_clocks, |
| 419 | }; |
| 420 | |
| 421 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 422 | static void snd_es18xx_rate_set(struct snd_es18xx *chip, |
| 423 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | int mode) |
| 425 | { |
| 426 | unsigned int bits, div0; |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 427 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if (chip->caps & ES18XX_NEW_RATE) { |
| 429 | if (runtime->rate_num == new_clocks[0].num) |
| 430 | bits = 128 - runtime->rate_den; |
| 431 | else |
| 432 | bits = 256 - runtime->rate_den; |
| 433 | } else { |
| 434 | if (runtime->rate_num == old_clocks[0].num) |
| 435 | bits = 256 - runtime->rate_den; |
| 436 | else |
| 437 | bits = 128 - runtime->rate_den; |
| 438 | } |
| 439 | |
| 440 | /* set filter register */ |
| 441 | div0 = 256 - 7160000*20/(8*82*runtime->rate); |
| 442 | |
| 443 | if ((chip->caps & ES18XX_PCM2) && mode == DAC2) { |
| 444 | snd_es18xx_mixer_write(chip, 0x70, bits); |
| 445 | /* |
| 446 | * Comment from kernel oss driver: |
| 447 | * FKS: fascinating: 0x72 doesn't seem to work. |
| 448 | */ |
| 449 | snd_es18xx_write(chip, 0xA2, div0); |
| 450 | snd_es18xx_mixer_write(chip, 0x72, div0); |
| 451 | } else { |
| 452 | snd_es18xx_write(chip, 0xA1, bits); |
| 453 | snd_es18xx_write(chip, 0xA2, div0); |
| 454 | } |
| 455 | } |
| 456 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 457 | static int snd_es18xx_playback_hw_params(struct snd_pcm_substream *substream, |
| 458 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 460 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | int shift, err; |
| 462 | |
| 463 | shift = 0; |
| 464 | if (params_channels(hw_params) == 2) |
| 465 | shift++; |
| 466 | if (snd_pcm_format_width(params_format(hw_params)) == 16) |
| 467 | shift++; |
| 468 | |
| 469 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 470 | if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 471 | (chip->capture_a_substream) && |
| 472 | params_channels(hw_params) != 1) { |
| 473 | _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 474 | return -EBUSY; |
| 475 | } |
| 476 | chip->dma2_shift = shift; |
| 477 | } else { |
| 478 | chip->dma1_shift = shift; |
| 479 | } |
| 480 | if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
| 481 | return err; |
| 482 | return 0; |
| 483 | } |
| 484 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 485 | static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
| 487 | return snd_pcm_lib_free_pages(substream); |
| 488 | } |
| 489 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 490 | static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip, |
| 491 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 493 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 495 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 496 | |
| 497 | chip->dma2_size = size; |
| 498 | |
| 499 | snd_es18xx_rate_set(chip, substream, DAC2); |
| 500 | |
| 501 | /* Transfer Count Reload */ |
| 502 | count = 0x10000 - count; |
| 503 | snd_es18xx_mixer_write(chip, 0x74, count & 0xff); |
| 504 | snd_es18xx_mixer_write(chip, 0x76, count >> 8); |
| 505 | |
| 506 | /* Set format */ |
| 507 | snd_es18xx_mixer_bits(chip, 0x7A, 0x07, |
| 508 | ((runtime->channels == 1) ? 0x00 : 0x02) | |
| 509 | (snd_pcm_format_width(runtime->format) == 16 ? 0x01 : 0x00) | |
| 510 | (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x04)); |
| 511 | |
| 512 | /* Set DMA controller */ |
| 513 | snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 518 | static int snd_es18xx_playback1_trigger(struct snd_es18xx *chip, |
| 519 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | int cmd) |
| 521 | { |
| 522 | switch (cmd) { |
| 523 | case SNDRV_PCM_TRIGGER_START: |
| 524 | case SNDRV_PCM_TRIGGER_RESUME: |
| 525 | if (chip->active & DAC2) |
| 526 | return 0; |
| 527 | chip->active |= DAC2; |
| 528 | /* Start DMA */ |
| 529 | if (chip->dma2 >= 4) |
| 530 | snd_es18xx_mixer_write(chip, 0x78, 0xb3); |
| 531 | else |
| 532 | snd_es18xx_mixer_write(chip, 0x78, 0x93); |
| 533 | #ifdef AVOID_POPS |
| 534 | /* Avoid pops */ |
| 535 | udelay(100000); |
| 536 | if (chip->caps & ES18XX_PCM2) |
| 537 | /* Restore Audio 2 volume */ |
| 538 | snd_es18xx_mixer_write(chip, 0x7C, chip->audio2_vol); |
| 539 | else |
| 540 | /* Enable PCM output */ |
| 541 | snd_es18xx_dsp_command(chip, 0xD1); |
| 542 | #endif |
| 543 | break; |
| 544 | case SNDRV_PCM_TRIGGER_STOP: |
| 545 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 546 | if (!(chip->active & DAC2)) |
| 547 | return 0; |
| 548 | chip->active &= ~DAC2; |
| 549 | /* Stop DMA */ |
| 550 | snd_es18xx_mixer_write(chip, 0x78, 0x00); |
| 551 | #ifdef AVOID_POPS |
| 552 | udelay(25000); |
| 553 | if (chip->caps & ES18XX_PCM2) |
| 554 | /* Set Audio 2 volume to 0 */ |
| 555 | snd_es18xx_mixer_write(chip, 0x7C, 0); |
| 556 | else |
| 557 | /* Disable PCM output */ |
| 558 | snd_es18xx_dsp_command(chip, 0xD3); |
| 559 | #endif |
| 560 | break; |
| 561 | default: |
| 562 | return -EINVAL; |
| 563 | } |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 568 | static int snd_es18xx_capture_hw_params(struct snd_pcm_substream *substream, |
| 569 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 571 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | int shift, err; |
| 573 | |
| 574 | shift = 0; |
| 575 | if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 576 | chip->playback_a_substream && |
| 577 | params_channels(hw_params) != 1) { |
| 578 | _snd_pcm_hw_param_setempty(hw_params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 579 | return -EBUSY; |
| 580 | } |
| 581 | if (params_channels(hw_params) == 2) |
| 582 | shift++; |
| 583 | if (snd_pcm_format_width(params_format(hw_params)) == 16) |
| 584 | shift++; |
| 585 | chip->dma1_shift = shift; |
| 586 | if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
| 587 | return err; |
| 588 | return 0; |
| 589 | } |
| 590 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 591 | static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 593 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
| 594 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 596 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 597 | |
| 598 | chip->dma1_size = size; |
| 599 | |
| 600 | snd_es18xx_reset_fifo(chip); |
| 601 | |
| 602 | /* Set stereo/mono */ |
| 603 | snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01); |
| 604 | |
| 605 | snd_es18xx_rate_set(chip, substream, ADC1); |
| 606 | |
| 607 | /* Transfer Count Reload */ |
| 608 | count = 0x10000 - count; |
| 609 | snd_es18xx_write(chip, 0xA4, count & 0xff); |
| 610 | snd_es18xx_write(chip, 0xA5, count >> 8); |
| 611 | |
| 612 | #ifdef AVOID_POPS |
| 613 | udelay(100000); |
| 614 | #endif |
| 615 | |
| 616 | /* Set format */ |
| 617 | snd_es18xx_write(chip, 0xB7, |
| 618 | snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71); |
| 619 | snd_es18xx_write(chip, 0xB7, 0x90 | |
| 620 | ((runtime->channels == 1) ? 0x40 : 0x08) | |
| 621 | (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) | |
| 622 | (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20)); |
| 623 | |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 624 | /* Set DMA controller */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT); |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 630 | static int snd_es18xx_capture_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | int cmd) |
| 632 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 633 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
| 635 | switch (cmd) { |
| 636 | case SNDRV_PCM_TRIGGER_START: |
| 637 | case SNDRV_PCM_TRIGGER_RESUME: |
| 638 | if (chip->active & ADC1) |
| 639 | return 0; |
| 640 | chip->active |= ADC1; |
| 641 | /* Start DMA */ |
| 642 | snd_es18xx_write(chip, 0xB8, 0x0f); |
| 643 | break; |
| 644 | case SNDRV_PCM_TRIGGER_STOP: |
| 645 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 646 | if (!(chip->active & ADC1)) |
| 647 | return 0; |
| 648 | chip->active &= ~ADC1; |
| 649 | /* Stop DMA */ |
| 650 | snd_es18xx_write(chip, 0xB8, 0x00); |
| 651 | break; |
| 652 | default: |
| 653 | return -EINVAL; |
| 654 | } |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 659 | static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip, |
| 660 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 662 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 664 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 665 | |
| 666 | chip->dma1_size = size; |
| 667 | |
| 668 | snd_es18xx_reset_fifo(chip); |
| 669 | |
| 670 | /* Set stereo/mono */ |
| 671 | snd_es18xx_bits(chip, 0xA8, 0x03, runtime->channels == 1 ? 0x02 : 0x01); |
| 672 | |
| 673 | snd_es18xx_rate_set(chip, substream, DAC1); |
| 674 | |
| 675 | /* Transfer Count Reload */ |
| 676 | count = 0x10000 - count; |
| 677 | snd_es18xx_write(chip, 0xA4, count & 0xff); |
| 678 | snd_es18xx_write(chip, 0xA5, count >> 8); |
| 679 | |
| 680 | /* Set format */ |
| 681 | snd_es18xx_write(chip, 0xB6, |
| 682 | snd_pcm_format_unsigned(runtime->format) ? 0x80 : 0x00); |
| 683 | snd_es18xx_write(chip, 0xB7, |
| 684 | snd_pcm_format_unsigned(runtime->format) ? 0x51 : 0x71); |
| 685 | snd_es18xx_write(chip, 0xB7, 0x90 | |
| 686 | (runtime->channels == 1 ? 0x40 : 0x08) | |
| 687 | (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) | |
| 688 | (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20)); |
| 689 | |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 690 | /* Set DMA controller */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 696 | static int snd_es18xx_playback2_trigger(struct snd_es18xx *chip, |
| 697 | struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | int cmd) |
| 699 | { |
| 700 | switch (cmd) { |
| 701 | case SNDRV_PCM_TRIGGER_START: |
| 702 | case SNDRV_PCM_TRIGGER_RESUME: |
| 703 | if (chip->active & DAC1) |
| 704 | return 0; |
| 705 | chip->active |= DAC1; |
| 706 | /* Start DMA */ |
| 707 | snd_es18xx_write(chip, 0xB8, 0x05); |
| 708 | #ifdef AVOID_POPS |
| 709 | /* Avoid pops */ |
| 710 | udelay(100000); |
| 711 | /* Enable Audio 1 */ |
| 712 | snd_es18xx_dsp_command(chip, 0xD1); |
| 713 | #endif |
| 714 | break; |
| 715 | case SNDRV_PCM_TRIGGER_STOP: |
| 716 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 717 | if (!(chip->active & DAC1)) |
| 718 | return 0; |
| 719 | chip->active &= ~DAC1; |
| 720 | /* Stop DMA */ |
| 721 | snd_es18xx_write(chip, 0xB8, 0x00); |
| 722 | #ifdef AVOID_POPS |
| 723 | /* Avoid pops */ |
| 724 | udelay(25000); |
| 725 | /* Disable Audio 1 */ |
| 726 | snd_es18xx_dsp_command(chip, 0xD3); |
| 727 | #endif |
| 728 | break; |
| 729 | default: |
| 730 | return -EINVAL; |
| 731 | } |
| 732 | |
| 733 | return 0; |
| 734 | } |
| 735 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 736 | static int snd_es18xx_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 738 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) |
| 740 | return snd_es18xx_playback1_prepare(chip, substream); |
| 741 | else |
| 742 | return snd_es18xx_playback2_prepare(chip, substream); |
| 743 | } |
| 744 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 745 | static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | int cmd) |
| 747 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 748 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) |
| 750 | return snd_es18xx_playback1_trigger(chip, substream, cmd); |
| 751 | else |
| 752 | return snd_es18xx_playback2_trigger(chip, substream, cmd); |
| 753 | } |
| 754 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 755 | static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 757 | struct snd_card *card = dev_id; |
| 758 | struct snd_audiodrive *acard = card->private_data; |
| 759 | struct snd_es18xx *chip = acard->chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | unsigned char status; |
| 761 | |
| 762 | if (chip->caps & ES18XX_CONTROL) { |
| 763 | /* Read Interrupt status */ |
| 764 | status = inb(chip->ctrl_port + 6); |
| 765 | } else { |
| 766 | /* Read Interrupt status */ |
| 767 | status = snd_es18xx_mixer_read(chip, 0x7f) >> 4; |
| 768 | } |
| 769 | #if 0 |
| 770 | else { |
| 771 | status = 0; |
| 772 | if (inb(chip->port + 0x0C) & 0x01) |
| 773 | status |= AUDIO1_IRQ; |
| 774 | if (snd_es18xx_mixer_read(chip, 0x7A) & 0x80) |
| 775 | status |= AUDIO2_IRQ; |
| 776 | if ((chip->caps & ES18XX_HWV) && |
| 777 | snd_es18xx_mixer_read(chip, 0x64) & 0x10) |
| 778 | status |= HWV_IRQ; |
| 779 | } |
| 780 | #endif |
| 781 | |
| 782 | /* Audio 1 & Audio 2 */ |
| 783 | if (status & AUDIO2_IRQ) { |
| 784 | if (chip->active & DAC2) |
| 785 | snd_pcm_period_elapsed(chip->playback_a_substream); |
| 786 | /* ack interrupt */ |
| 787 | snd_es18xx_mixer_bits(chip, 0x7A, 0x80, 0x00); |
| 788 | } |
| 789 | if (status & AUDIO1_IRQ) { |
| 790 | /* ok.. capture is active */ |
| 791 | if (chip->active & ADC1) |
| 792 | snd_pcm_period_elapsed(chip->capture_a_substream); |
| 793 | /* ok.. playback2 is active */ |
| 794 | else if (chip->active & DAC1) |
| 795 | snd_pcm_period_elapsed(chip->playback_b_substream); |
| 796 | /* ack interrupt */ |
| 797 | inb(chip->port + 0x0E); |
| 798 | } |
| 799 | |
| 800 | /* MPU */ |
| 801 | if ((status & MPU_IRQ) && chip->rmidi) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 802 | snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | /* Hardware volume */ |
| 805 | if (status & HWV_IRQ) { |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 806 | int split = 0; |
| 807 | if (chip->caps & ES18XX_HWV) { |
| 808 | split = snd_es18xx_mixer_read(chip, 0x64) & 0x80; |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 809 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 810 | &chip->hw_switch->id); |
| 811 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 812 | &chip->hw_volume->id); |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 813 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | if (!split) { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 815 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 816 | &chip->master_switch->id); |
| 817 | snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, |
| 818 | &chip->master_volume->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | } |
| 820 | /* ack interrupt */ |
| 821 | snd_es18xx_mixer_write(chip, 0x66, 0x00); |
| 822 | } |
| 823 | return IRQ_HANDLED; |
| 824 | } |
| 825 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 826 | static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 828 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | int pos; |
| 830 | |
| 831 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 832 | if (!(chip->active & DAC2)) |
| 833 | return 0; |
| 834 | pos = snd_dma_pointer(chip->dma2, chip->dma2_size); |
| 835 | return pos >> chip->dma2_shift; |
| 836 | } else { |
| 837 | if (!(chip->active & DAC1)) |
| 838 | return 0; |
| 839 | pos = snd_dma_pointer(chip->dma1, chip->dma1_size); |
| 840 | return pos >> chip->dma1_shift; |
| 841 | } |
| 842 | } |
| 843 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 844 | static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 846 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | int pos; |
| 848 | |
| 849 | if (!(chip->active & ADC1)) |
| 850 | return 0; |
| 851 | pos = snd_dma_pointer(chip->dma1, chip->dma1_size); |
| 852 | return pos >> chip->dma1_shift; |
| 853 | } |
| 854 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 855 | static struct snd_pcm_hardware snd_es18xx_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | { |
| 857 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 858 | SNDRV_PCM_INFO_RESUME | |
| 859 | SNDRV_PCM_INFO_MMAP_VALID), |
| 860 | .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | |
| 861 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE), |
| 862 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 863 | .rate_min = 4000, |
| 864 | .rate_max = 48000, |
| 865 | .channels_min = 1, |
| 866 | .channels_max = 2, |
| 867 | .buffer_bytes_max = 65536, |
| 868 | .period_bytes_min = 64, |
| 869 | .period_bytes_max = 65536, |
| 870 | .periods_min = 1, |
| 871 | .periods_max = 1024, |
| 872 | .fifo_size = 0, |
| 873 | }; |
| 874 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 875 | static struct snd_pcm_hardware snd_es18xx_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | { |
| 877 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 878 | SNDRV_PCM_INFO_RESUME | |
| 879 | SNDRV_PCM_INFO_MMAP_VALID), |
| 880 | .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | |
| 881 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE), |
| 882 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 883 | .rate_min = 4000, |
| 884 | .rate_max = 48000, |
| 885 | .channels_min = 1, |
| 886 | .channels_max = 2, |
| 887 | .buffer_bytes_max = 65536, |
| 888 | .period_bytes_min = 64, |
| 889 | .period_bytes_max = 65536, |
| 890 | .periods_min = 1, |
| 891 | .periods_max = 1024, |
| 892 | .fifo_size = 0, |
| 893 | }; |
| 894 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 895 | static int snd_es18xx_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 897 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 898 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 901 | if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 902 | chip->capture_a_substream && |
| 903 | chip->capture_a_substream->runtime->channels != 1) |
| 904 | return -EAGAIN; |
| 905 | chip->playback_a_substream = substream; |
| 906 | } else if (substream->number <= 1) { |
| 907 | if (chip->capture_a_substream) |
| 908 | return -EAGAIN; |
| 909 | chip->playback_b_substream = substream; |
| 910 | } else { |
| 911 | snd_BUG(); |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | substream->runtime->hw = snd_es18xx_playback; |
| 915 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 916 | (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks); |
| 917 | return 0; |
| 918 | } |
| 919 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 920 | static int snd_es18xx_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 922 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 923 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
| 925 | if (chip->playback_b_substream) |
| 926 | return -EAGAIN; |
| 927 | if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 928 | chip->playback_a_substream && |
| 929 | chip->playback_a_substream->runtime->channels != 1) |
| 930 | return -EAGAIN; |
| 931 | chip->capture_a_substream = substream; |
| 932 | substream->runtime->hw = snd_es18xx_capture; |
| 933 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 934 | (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks); |
| 935 | return 0; |
| 936 | } |
| 937 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 938 | static int snd_es18xx_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 940 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
| 942 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) |
| 943 | chip->playback_a_substream = NULL; |
| 944 | else |
| 945 | chip->playback_b_substream = NULL; |
| 946 | |
| 947 | snd_pcm_lib_free_pages(substream); |
| 948 | return 0; |
| 949 | } |
| 950 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 951 | static int snd_es18xx_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 953 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | chip->capture_a_substream = NULL; |
| 956 | snd_pcm_lib_free_pages(substream); |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | /* |
| 961 | * MIXER part |
| 962 | */ |
| 963 | |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 964 | /* Record source mux routines: |
| 965 | * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs. |
| 966 | * bit table for the 4/5 source mux: |
| 967 | * reg 1C: |
| 968 | * b2 b1 b0 muxSource |
| 969 | * x 0 x microphone |
| 970 | * 0 1 x CD |
| 971 | * 1 1 0 line |
| 972 | * 1 1 1 mixer |
| 973 | * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines |
| 974 | * either the play mixer or the capture mixer. |
| 975 | * |
| 976 | * "map4Source" translates from source number to reg bit pattern |
| 977 | * "invMap4Source" translates from reg bit pattern to source number |
| 978 | */ |
| 979 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 980 | static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | { |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 982 | static char *texts4Source[4] = { |
| 983 | "Mic", "CD", "Line", "Master" |
| 984 | }; |
| 985 | static char *texts5Source[5] = { |
| 986 | "Mic", "CD", "Line", "Master", "Mix" |
| 987 | }; |
| 988 | static char *texts8Source[8] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | "Mic", "Mic Master", "CD", "AOUT", |
| 990 | "Mic1", "Mix", "Line", "Master" |
| 991 | }; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 992 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
| 994 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 995 | uinfo->count = 1; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 996 | switch (chip->version) { |
| 997 | case 0x1868: |
| 998 | case 0x1878: |
| 999 | uinfo->value.enumerated.items = 4; |
| 1000 | if (uinfo->value.enumerated.item > 3) |
| 1001 | uinfo->value.enumerated.item = 3; |
| 1002 | strcpy(uinfo->value.enumerated.name, texts4Source[uinfo->value.enumerated.item]); |
| 1003 | break; |
| 1004 | case 0x1887: |
| 1005 | case 0x1888: |
| 1006 | uinfo->value.enumerated.items = 5; |
| 1007 | if (uinfo->value.enumerated.item > 4) |
| 1008 | uinfo->value.enumerated.item = 4; |
| 1009 | strcpy(uinfo->value.enumerated.name, texts5Source[uinfo->value.enumerated.item]); |
| 1010 | break; |
| 1011 | case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */ |
| 1012 | case 0x1879: |
| 1013 | uinfo->value.enumerated.items = 8; |
| 1014 | if (uinfo->value.enumerated.item > 7) |
| 1015 | uinfo->value.enumerated.item = 7; |
| 1016 | strcpy(uinfo->value.enumerated.name, texts8Source[uinfo->value.enumerated.item]); |
| 1017 | break; |
| 1018 | default: |
| 1019 | return -EINVAL; |
| 1020 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
| 1023 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1024 | static int snd_es18xx_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | { |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1026 | static unsigned char invMap4Source[8] = {0, 0, 1, 1, 0, 0, 2, 3}; |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1027 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1028 | int muxSource = snd_es18xx_mixer_read(chip, 0x1c) & 0x07; |
| 1029 | if (!(chip->version == 0x1869 || chip->version == 0x1879)) { |
| 1030 | muxSource = invMap4Source[muxSource]; |
| 1031 | if (muxSource==3 && |
| 1032 | (chip->version == 0x1887 || chip->version == 0x1888) && |
| 1033 | (snd_es18xx_mixer_read(chip, 0x7a) & 0x08) |
| 1034 | ) |
| 1035 | muxSource = 4; |
| 1036 | } |
| 1037 | ucontrol->value.enumerated.item[0] = muxSource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | return 0; |
| 1039 | } |
| 1040 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1041 | static int snd_es18xx_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1043 | static unsigned char map4Source[4] = {0, 2, 6, 7}; |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1044 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | unsigned char val = ucontrol->value.enumerated.item[0]; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1046 | unsigned char retVal = 0; |
| 1047 | |
| 1048 | switch (chip->version) { |
| 1049 | /* 5 source chips */ |
| 1050 | case 0x1887: |
| 1051 | case 0x1888: |
| 1052 | if (val > 4) |
| 1053 | return -EINVAL; |
| 1054 | if (val == 4) { |
| 1055 | retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x08) != 0x08; |
| 1056 | val = 3; |
| 1057 | } else |
| 1058 | retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x00) != 0x00; |
| 1059 | /* 4 source chips */ |
| 1060 | case 0x1868: |
| 1061 | case 0x1878: |
| 1062 | if (val > 3) |
| 1063 | return -EINVAL; |
| 1064 | val = map4Source[val]; |
| 1065 | break; |
| 1066 | /* 8 source chips */ |
| 1067 | case 0x1869: |
| 1068 | case 0x1879: |
| 1069 | if (val > 7) |
| 1070 | return -EINVAL; |
| 1071 | break; |
| 1072 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | return -EINVAL; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1074 | } |
| 1075 | return (snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val) || retVal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1078 | #define snd_es18xx_info_spatializer_enable snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1080 | static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1082 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | unsigned char val = snd_es18xx_mixer_read(chip, 0x50); |
| 1084 | ucontrol->value.integer.value[0] = !!(val & 8); |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1088 | static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1090 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | unsigned char oval, nval; |
| 1092 | int change; |
| 1093 | nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04; |
| 1094 | oval = snd_es18xx_mixer_read(chip, 0x50) & 0x0c; |
| 1095 | change = nval != oval; |
| 1096 | if (change) { |
| 1097 | snd_es18xx_mixer_write(chip, 0x50, nval & ~0x04); |
| 1098 | snd_es18xx_mixer_write(chip, 0x50, nval); |
| 1099 | } |
| 1100 | return change; |
| 1101 | } |
| 1102 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1103 | static int snd_es18xx_info_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | { |
| 1105 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1106 | uinfo->count = 2; |
| 1107 | uinfo->value.integer.min = 0; |
| 1108 | uinfo->value.integer.max = 63; |
| 1109 | return 0; |
| 1110 | } |
| 1111 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1112 | static int snd_es18xx_get_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1114 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f; |
| 1116 | ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f; |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1120 | #define snd_es18xx_info_hw_switch snd_ctl_boolean_stereo_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1122 | static int snd_es18xx_get_hw_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1124 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40); |
| 1126 | ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40); |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1130 | static void snd_es18xx_hwv_free(struct snd_kcontrol *kcontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1132 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | chip->master_volume = NULL; |
| 1134 | chip->master_switch = NULL; |
| 1135 | chip->hw_volume = NULL; |
| 1136 | chip->hw_switch = NULL; |
| 1137 | } |
| 1138 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1139 | static int snd_es18xx_reg_bits(struct snd_es18xx *chip, unsigned char reg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | unsigned char mask, unsigned char val) |
| 1141 | { |
| 1142 | if (reg < 0xa0) |
| 1143 | return snd_es18xx_mixer_bits(chip, reg, mask, val); |
| 1144 | else |
| 1145 | return snd_es18xx_bits(chip, reg, mask, val); |
| 1146 | } |
| 1147 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1148 | static int snd_es18xx_reg_read(struct snd_es18xx *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | { |
| 1150 | if (reg < 0xa0) |
| 1151 | return snd_es18xx_mixer_read(chip, reg); |
| 1152 | else |
| 1153 | return snd_es18xx_read(chip, reg); |
| 1154 | } |
| 1155 | |
| 1156 | #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
| 1157 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 1158 | .info = snd_es18xx_info_single, \ |
| 1159 | .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \ |
| 1160 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } |
| 1161 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1162 | static int snd_es18xx_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | { |
| 1164 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1165 | |
| 1166 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1167 | uinfo->count = 1; |
| 1168 | uinfo->value.integer.min = 0; |
| 1169 | uinfo->value.integer.max = mask; |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1173 | static int snd_es18xx_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1175 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | int reg = kcontrol->private_value & 0xff; |
| 1177 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1178 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1179 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1180 | int val; |
| 1181 | |
| 1182 | val = snd_es18xx_reg_read(chip, reg); |
| 1183 | ucontrol->value.integer.value[0] = (val >> shift) & mask; |
| 1184 | if (invert) |
| 1185 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1189 | static int snd_es18xx_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1191 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | int reg = kcontrol->private_value & 0xff; |
| 1193 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1194 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1195 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1196 | unsigned char val; |
| 1197 | |
| 1198 | val = (ucontrol->value.integer.value[0] & mask); |
| 1199 | if (invert) |
| 1200 | val = mask - val; |
| 1201 | mask <<= shift; |
| 1202 | val <<= shift; |
| 1203 | return snd_es18xx_reg_bits(chip, reg, mask, val) != val; |
| 1204 | } |
| 1205 | |
| 1206 | #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ |
| 1207 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 1208 | .info = snd_es18xx_info_double, \ |
| 1209 | .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \ |
| 1210 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } |
| 1211 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1212 | static int snd_es18xx_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | { |
| 1214 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1215 | |
| 1216 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1217 | uinfo->count = 2; |
| 1218 | uinfo->value.integer.min = 0; |
| 1219 | uinfo->value.integer.max = mask; |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1223 | static int snd_es18xx_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1225 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | int left_reg = kcontrol->private_value & 0xff; |
| 1227 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1228 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1229 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1230 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1231 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1232 | unsigned char left, right; |
| 1233 | |
| 1234 | left = snd_es18xx_reg_read(chip, left_reg); |
| 1235 | if (left_reg != right_reg) |
| 1236 | right = snd_es18xx_reg_read(chip, right_reg); |
| 1237 | else |
| 1238 | right = left; |
| 1239 | ucontrol->value.integer.value[0] = (left >> shift_left) & mask; |
| 1240 | ucontrol->value.integer.value[1] = (right >> shift_right) & mask; |
| 1241 | if (invert) { |
| 1242 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1243 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 1244 | } |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1248 | static int snd_es18xx_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1250 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | int left_reg = kcontrol->private_value & 0xff; |
| 1252 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1253 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1254 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1255 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1256 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1257 | int change; |
| 1258 | unsigned char val1, val2, mask1, mask2; |
| 1259 | |
| 1260 | val1 = ucontrol->value.integer.value[0] & mask; |
| 1261 | val2 = ucontrol->value.integer.value[1] & mask; |
| 1262 | if (invert) { |
| 1263 | val1 = mask - val1; |
| 1264 | val2 = mask - val2; |
| 1265 | } |
| 1266 | val1 <<= shift_left; |
| 1267 | val2 <<= shift_right; |
| 1268 | mask1 = mask << shift_left; |
| 1269 | mask2 = mask << shift_right; |
| 1270 | if (left_reg != right_reg) { |
| 1271 | change = 0; |
| 1272 | if (snd_es18xx_reg_bits(chip, left_reg, mask1, val1) != val1) |
| 1273 | change = 1; |
| 1274 | if (snd_es18xx_reg_bits(chip, right_reg, mask2, val2) != val2) |
| 1275 | change = 1; |
| 1276 | } else { |
| 1277 | change = (snd_es18xx_reg_bits(chip, left_reg, mask1 | mask2, |
| 1278 | val1 | val2) != (val1 | val2)); |
| 1279 | } |
| 1280 | return change; |
| 1281 | } |
| 1282 | |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1283 | /* Mixer controls |
| 1284 | * These arrays contain setup data for mixer controls. |
| 1285 | * |
| 1286 | * The controls that are universal to all chipsets are fully initialized |
| 1287 | * here. |
| 1288 | */ |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1289 | static struct snd_kcontrol_new snd_es18xx_base_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0), |
| 1291 | ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1), |
| 1292 | ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0), |
| 1293 | ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0), |
| 1294 | ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0), |
| 1296 | ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0), |
| 1298 | ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | { |
| 1300 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1301 | .name = "Capture Source", |
| 1302 | .info = snd_es18xx_info_mux, |
| 1303 | .get = snd_es18xx_get_mux, |
| 1304 | .put = snd_es18xx_put_mux, |
| 1305 | } |
| 1306 | }; |
| 1307 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1308 | static struct snd_kcontrol_new snd_es18xx_recmix_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0), |
| 1310 | ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0), |
| 1311 | ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0), |
| 1312 | ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0), |
| 1314 | ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0) |
| 1315 | }; |
| 1316 | |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1317 | /* |
| 1318 | * The chipset specific mixer controls |
| 1319 | */ |
| 1320 | static struct snd_kcontrol_new snd_es18xx_opt_speaker = |
| 1321 | ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0); |
| 1322 | |
| 1323 | static struct snd_kcontrol_new snd_es18xx_opt_1869[] = { |
| 1324 | ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 1325 | ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0), |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1326 | ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), |
| 1327 | ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0) |
| 1328 | }; |
| 1329 | |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 1330 | static struct snd_kcontrol_new snd_es18xx_opt_1878 = |
| 1331 | ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0); |
| 1332 | |
| 1333 | static struct snd_kcontrol_new snd_es18xx_opt_1879[] = { |
| 1334 | ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0), |
| 1335 | ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), |
| 1336 | ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0) |
| 1337 | }; |
| 1338 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1339 | static struct snd_kcontrol_new snd_es18xx_pcm1_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0), |
| 1341 | }; |
| 1342 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1343 | static struct snd_kcontrol_new snd_es18xx_pcm2_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0), |
| 1345 | ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0) |
| 1346 | }; |
| 1347 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1348 | static struct snd_kcontrol_new snd_es18xx_spatializer_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0), |
| 1350 | { |
| 1351 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1352 | .name = "3D Control - Switch", |
| 1353 | .info = snd_es18xx_info_spatializer_enable, |
| 1354 | .get = snd_es18xx_get_spatializer_enable, |
| 1355 | .put = snd_es18xx_put_spatializer_enable, |
| 1356 | } |
| 1357 | }; |
| 1358 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1359 | static struct snd_kcontrol_new snd_es18xx_micpre1_control = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0); |
| 1361 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1362 | static struct snd_kcontrol_new snd_es18xx_micpre2_control = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0); |
| 1364 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1365 | static struct snd_kcontrol_new snd_es18xx_hw_volume_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | { |
| 1367 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1368 | .name = "Hardware Master Playback Volume", |
| 1369 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1370 | .info = snd_es18xx_info_hw_volume, |
| 1371 | .get = snd_es18xx_get_hw_volume, |
| 1372 | }, |
| 1373 | { |
| 1374 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1375 | .name = "Hardware Master Playback Switch", |
| 1376 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1377 | .info = snd_es18xx_info_hw_switch, |
| 1378 | .get = snd_es18xx_get_hw_switch, |
| 1379 | }, |
| 1380 | ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0), |
| 1381 | }; |
| 1382 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1383 | static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | { |
| 1385 | int data; |
| 1386 | unsigned long flags; |
| 1387 | spin_lock_irqsave(&chip->ctrl_lock, flags); |
| 1388 | outb(reg, chip->ctrl_port); |
| 1389 | data = inb(chip->ctrl_port + 1); |
| 1390 | spin_unlock_irqrestore(&chip->ctrl_lock, flags); |
| 1391 | return data; |
| 1392 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1394 | static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | unsigned char reg, unsigned char data) |
| 1396 | { |
| 1397 | /* No need for spinlocks, this function is used only in |
| 1398 | otherwise protected init code */ |
| 1399 | outb(reg, chip->ctrl_port); |
| 1400 | outb(data, chip->ctrl_port + 1); |
| 1401 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1402 | snd_printk(KERN_DEBUG "Config reg %02x set to %02x\n", reg, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | #endif |
| 1404 | } |
| 1405 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1406 | static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | { |
| 1408 | int mask = 0; |
| 1409 | |
| 1410 | /* enable extended mode */ |
| 1411 | snd_es18xx_dsp_command(chip, 0xC6); |
| 1412 | /* Reset mixer registers */ |
| 1413 | snd_es18xx_mixer_write(chip, 0x00, 0x00); |
| 1414 | |
| 1415 | /* Audio 1 DMA demand mode (4 bytes/request) */ |
| 1416 | snd_es18xx_write(chip, 0xB9, 2); |
| 1417 | if (chip->caps & ES18XX_CONTROL) { |
| 1418 | /* Hardware volume IRQ */ |
| 1419 | snd_es18xx_config_write(chip, 0x27, chip->irq); |
| 1420 | if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { |
| 1421 | /* FM I/O */ |
| 1422 | snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8); |
| 1423 | snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff); |
| 1424 | } |
| 1425 | if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { |
| 1426 | /* MPU-401 I/O */ |
| 1427 | snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8); |
| 1428 | snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff); |
| 1429 | /* MPU-401 IRQ */ |
| 1430 | snd_es18xx_config_write(chip, 0x28, chip->irq); |
| 1431 | } |
| 1432 | /* Audio1 IRQ */ |
| 1433 | snd_es18xx_config_write(chip, 0x70, chip->irq); |
| 1434 | /* Audio2 IRQ */ |
| 1435 | snd_es18xx_config_write(chip, 0x72, chip->irq); |
| 1436 | /* Audio1 DMA */ |
| 1437 | snd_es18xx_config_write(chip, 0x74, chip->dma1); |
| 1438 | /* Audio2 DMA */ |
| 1439 | snd_es18xx_config_write(chip, 0x75, chip->dma2); |
| 1440 | |
| 1441 | /* Enable Audio 1 IRQ */ |
| 1442 | snd_es18xx_write(chip, 0xB1, 0x50); |
| 1443 | /* Enable Audio 2 IRQ */ |
| 1444 | snd_es18xx_mixer_write(chip, 0x7A, 0x40); |
| 1445 | /* Enable Audio 1 DMA */ |
| 1446 | snd_es18xx_write(chip, 0xB2, 0x50); |
| 1447 | /* Enable MPU and hardware volume interrupt */ |
| 1448 | snd_es18xx_mixer_write(chip, 0x64, 0x42); |
Krzysztof Helt | 1bc9eed | 2008-01-07 12:24:45 +0100 | [diff] [blame] | 1449 | /* Enable ESS wavetable input */ |
| 1450 | snd_es18xx_mixer_bits(chip, 0x48, 0x10, 0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } |
| 1452 | else { |
| 1453 | int irqmask, dma1mask, dma2mask; |
| 1454 | switch (chip->irq) { |
| 1455 | case 2: |
| 1456 | case 9: |
| 1457 | irqmask = 0; |
| 1458 | break; |
| 1459 | case 5: |
| 1460 | irqmask = 1; |
| 1461 | break; |
| 1462 | case 7: |
| 1463 | irqmask = 2; |
| 1464 | break; |
| 1465 | case 10: |
| 1466 | irqmask = 3; |
| 1467 | break; |
| 1468 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1469 | snd_printk(KERN_ERR "invalid irq %d\n", chip->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | return -ENODEV; |
| 1471 | } |
| 1472 | switch (chip->dma1) { |
| 1473 | case 0: |
| 1474 | dma1mask = 1; |
| 1475 | break; |
| 1476 | case 1: |
| 1477 | dma1mask = 2; |
| 1478 | break; |
| 1479 | case 3: |
| 1480 | dma1mask = 3; |
| 1481 | break; |
| 1482 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1483 | snd_printk(KERN_ERR "invalid dma1 %d\n", chip->dma1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | return -ENODEV; |
| 1485 | } |
| 1486 | switch (chip->dma2) { |
| 1487 | case 0: |
| 1488 | dma2mask = 0; |
| 1489 | break; |
| 1490 | case 1: |
| 1491 | dma2mask = 1; |
| 1492 | break; |
| 1493 | case 3: |
| 1494 | dma2mask = 2; |
| 1495 | break; |
| 1496 | case 5: |
| 1497 | dma2mask = 3; |
| 1498 | break; |
| 1499 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1500 | snd_printk(KERN_ERR "invalid dma2 %d\n", chip->dma2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | return -ENODEV; |
| 1502 | } |
| 1503 | |
| 1504 | /* Enable and set Audio 1 IRQ */ |
| 1505 | snd_es18xx_write(chip, 0xB1, 0x50 | (irqmask << 2)); |
| 1506 | /* Enable and set Audio 1 DMA */ |
| 1507 | snd_es18xx_write(chip, 0xB2, 0x50 | (dma1mask << 2)); |
| 1508 | /* Set Audio 2 DMA */ |
| 1509 | snd_es18xx_mixer_bits(chip, 0x7d, 0x07, 0x04 | dma2mask); |
| 1510 | /* Enable Audio 2 IRQ and DMA |
| 1511 | Set capture mixer input */ |
| 1512 | snd_es18xx_mixer_write(chip, 0x7A, 0x68); |
| 1513 | /* Enable and set hardware volume interrupt */ |
| 1514 | snd_es18xx_mixer_write(chip, 0x64, 0x06); |
| 1515 | if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { |
| 1516 | /* MPU401 share irq with audio |
| 1517 | Joystick enabled |
| 1518 | FM enabled */ |
| 1519 | snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1); |
| 1520 | } |
| 1521 | snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01); |
| 1522 | } |
| 1523 | if (chip->caps & ES18XX_NEW_RATE) { |
| 1524 | /* Change behaviour of register A1 |
| 1525 | 4x oversampling |
| 1526 | 2nd channel DAC asynchronous */ |
| 1527 | snd_es18xx_mixer_write(chip, 0x71, 0x32); |
| 1528 | } |
| 1529 | if (!(chip->caps & ES18XX_PCM2)) { |
| 1530 | /* Enable DMA FIFO */ |
| 1531 | snd_es18xx_write(chip, 0xB7, 0x80); |
| 1532 | } |
| 1533 | if (chip->caps & ES18XX_SPATIALIZER) { |
| 1534 | /* Set spatializer parameters to recommended values */ |
| 1535 | snd_es18xx_mixer_write(chip, 0x54, 0x8f); |
| 1536 | snd_es18xx_mixer_write(chip, 0x56, 0x95); |
| 1537 | snd_es18xx_mixer_write(chip, 0x58, 0x94); |
| 1538 | snd_es18xx_mixer_write(chip, 0x5a, 0x80); |
| 1539 | } |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 1540 | /* Flip the "enable I2S" bits for those chipsets that need it */ |
| 1541 | switch (chip->version) { |
| 1542 | case 0x1879: |
| 1543 | //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow) |
| 1544 | //so a Switch control has been added to toggle this 0x71 bit on/off: |
| 1545 | //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40); |
| 1546 | /* Note: we fall through on purpose here. */ |
| 1547 | case 0x1878: |
| 1548 | snd_es18xx_config_write(chip, 0x29, snd_es18xx_config_read(chip, 0x29) | 0x40); |
| 1549 | break; |
| 1550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | /* Mute input source */ |
| 1552 | if (chip->caps & ES18XX_MUTEREC) |
| 1553 | mask = 0x10; |
| 1554 | if (chip->caps & ES18XX_RECMIX) |
| 1555 | snd_es18xx_mixer_write(chip, 0x1c, 0x05 | mask); |
| 1556 | else { |
| 1557 | snd_es18xx_mixer_write(chip, 0x1c, 0x00 | mask); |
| 1558 | snd_es18xx_write(chip, 0xb4, 0x00); |
| 1559 | } |
| 1560 | #ifndef AVOID_POPS |
| 1561 | /* Enable PCM output */ |
| 1562 | snd_es18xx_dsp_command(chip, 0xD1); |
| 1563 | #endif |
| 1564 | |
| 1565 | return 0; |
| 1566 | } |
| 1567 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1568 | static int __devinit snd_es18xx_identify(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | { |
| 1570 | int hi,lo; |
| 1571 | |
| 1572 | /* reset */ |
| 1573 | if (snd_es18xx_reset(chip) < 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1574 | snd_printk(KERN_ERR "reset at 0x%lx failed!!!\n", chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | return -ENODEV; |
| 1576 | } |
| 1577 | |
| 1578 | snd_es18xx_dsp_command(chip, 0xe7); |
| 1579 | hi = snd_es18xx_dsp_get_byte(chip); |
| 1580 | if (hi < 0) { |
| 1581 | return hi; |
| 1582 | } |
| 1583 | lo = snd_es18xx_dsp_get_byte(chip); |
| 1584 | if ((lo & 0xf0) != 0x80) { |
| 1585 | return -ENODEV; |
| 1586 | } |
| 1587 | if (hi == 0x48) { |
| 1588 | chip->version = 0x488; |
| 1589 | return 0; |
| 1590 | } |
| 1591 | if (hi != 0x68) { |
| 1592 | return -ENODEV; |
| 1593 | } |
| 1594 | if ((lo & 0x0f) < 8) { |
| 1595 | chip->version = 0x688; |
| 1596 | return 0; |
| 1597 | } |
| 1598 | |
| 1599 | outb(0x40, chip->port + 0x04); |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1600 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | hi = inb(chip->port + 0x05); |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1602 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | lo = inb(chip->port + 0x05); |
| 1604 | if (hi != lo) { |
| 1605 | chip->version = hi << 8 | lo; |
| 1606 | chip->ctrl_port = inb(chip->port + 0x05) << 8; |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1607 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | chip->ctrl_port += inb(chip->port + 0x05); |
| 1609 | |
| 1610 | if ((chip->res_ctrl_port = request_region(chip->ctrl_port, 8, "ES18xx - CTRL")) == NULL) { |
| 1611 | snd_printk(KERN_ERR PFX "unable go grab port 0x%lx\n", chip->ctrl_port); |
| 1612 | return -EBUSY; |
| 1613 | } |
| 1614 | |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
| 1618 | /* If has Hardware volume */ |
| 1619 | if (snd_es18xx_mixer_writable(chip, 0x64, 0x04)) { |
| 1620 | /* If has Audio2 */ |
| 1621 | if (snd_es18xx_mixer_writable(chip, 0x70, 0x7f)) { |
| 1622 | /* If has volume count */ |
| 1623 | if (snd_es18xx_mixer_writable(chip, 0x64, 0x20)) { |
| 1624 | chip->version = 0x1887; |
| 1625 | } else { |
| 1626 | chip->version = 0x1888; |
| 1627 | } |
| 1628 | } else { |
| 1629 | chip->version = 0x1788; |
| 1630 | } |
| 1631 | } |
| 1632 | else |
| 1633 | chip->version = 0x1688; |
| 1634 | return 0; |
| 1635 | } |
| 1636 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1637 | static int __devinit snd_es18xx_probe(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | { |
| 1639 | if (snd_es18xx_identify(chip) < 0) { |
| 1640 | snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port); |
| 1641 | return -ENODEV; |
| 1642 | } |
| 1643 | |
| 1644 | switch (chip->version) { |
| 1645 | case 0x1868: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1646 | chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | break; |
| 1648 | case 0x1869: |
| 1649 | chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV; |
| 1650 | break; |
| 1651 | case 0x1878: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1652 | chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | break; |
| 1654 | case 0x1879: |
| 1655 | chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV; |
| 1656 | break; |
| 1657 | case 0x1887: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1658 | chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | break; |
| 1660 | case 0x1888: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1661 | chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | break; |
| 1663 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1664 | snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | chip->port, chip->version); |
| 1666 | return -ENODEV; |
| 1667 | } |
| 1668 | |
| 1669 | snd_printd("[0x%lx] ESS%x chip found\n", chip->port, chip->version); |
| 1670 | |
| 1671 | if (chip->dma1 == chip->dma2) |
| 1672 | chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME); |
| 1673 | |
| 1674 | return snd_es18xx_initialize(chip); |
| 1675 | } |
| 1676 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1677 | static struct snd_pcm_ops snd_es18xx_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | .open = snd_es18xx_playback_open, |
| 1679 | .close = snd_es18xx_playback_close, |
| 1680 | .ioctl = snd_pcm_lib_ioctl, |
| 1681 | .hw_params = snd_es18xx_playback_hw_params, |
| 1682 | .hw_free = snd_es18xx_pcm_hw_free, |
| 1683 | .prepare = snd_es18xx_playback_prepare, |
| 1684 | .trigger = snd_es18xx_playback_trigger, |
| 1685 | .pointer = snd_es18xx_playback_pointer, |
| 1686 | }; |
| 1687 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1688 | static struct snd_pcm_ops snd_es18xx_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | .open = snd_es18xx_capture_open, |
| 1690 | .close = snd_es18xx_capture_close, |
| 1691 | .ioctl = snd_pcm_lib_ioctl, |
| 1692 | .hw_params = snd_es18xx_capture_hw_params, |
| 1693 | .hw_free = snd_es18xx_pcm_hw_free, |
| 1694 | .prepare = snd_es18xx_capture_prepare, |
| 1695 | .trigger = snd_es18xx_capture_trigger, |
| 1696 | .pointer = snd_es18xx_capture_pointer, |
| 1697 | }; |
| 1698 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1699 | static int __devinit snd_es18xx_pcm(struct snd_card *card, int device, |
| 1700 | struct snd_pcm **rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1702 | struct snd_audiodrive *acard = card->private_data; |
| 1703 | struct snd_es18xx *chip = acard->chip; |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1704 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | char str[16]; |
| 1706 | int err; |
| 1707 | |
| 1708 | if (rpcm) |
| 1709 | *rpcm = NULL; |
| 1710 | sprintf(str, "ES%x", chip->version); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1711 | if (chip->caps & ES18XX_PCM2) |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1712 | err = snd_pcm_new(card, str, device, 2, 1, &pcm); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1713 | else |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1714 | err = snd_pcm_new(card, str, device, 1, 1, &pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | if (err < 0) |
| 1716 | return err; |
| 1717 | |
| 1718 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es18xx_playback_ops); |
| 1719 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es18xx_capture_ops); |
| 1720 | |
| 1721 | /* global setup */ |
| 1722 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | pcm->info_flags = 0; |
| 1724 | if (chip->caps & ES18XX_DUPLEX_SAME) |
| 1725 | pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1726 | if (! (chip->caps & ES18XX_PCM2)) |
| 1727 | pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX; |
| 1728 | sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version); |
| 1729 | chip->pcm = pcm; |
| 1730 | |
| 1731 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1732 | snd_dma_isa_data(), |
| 1733 | 64*1024, |
| 1734 | chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024); |
| 1735 | |
| 1736 | if (rpcm) |
| 1737 | *rpcm = pcm; |
| 1738 | return 0; |
| 1739 | } |
| 1740 | |
| 1741 | /* Power Management support functions */ |
| 1742 | #ifdef CONFIG_PM |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1743 | static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1745 | struct snd_audiodrive *acard = card->private_data; |
| 1746 | struct snd_es18xx *chip = acard->chip; |
| 1747 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1748 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
| 1750 | snd_pcm_suspend_all(chip->pcm); |
| 1751 | |
| 1752 | /* power down */ |
| 1753 | chip->pm_reg = (unsigned char)snd_es18xx_read(chip, ES18XX_PM); |
| 1754 | chip->pm_reg |= (ES18XX_PM_FM | ES18XX_PM_SUS); |
| 1755 | snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg); |
| 1756 | snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS); |
| 1757 | |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1761 | static int snd_es18xx_resume(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1763 | struct snd_audiodrive *acard = card->private_data; |
| 1764 | struct snd_es18xx *chip = acard->chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | |
| 1766 | /* restore PM register, we won't wake till (not 0x07) i/o activity though */ |
| 1767 | snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM); |
| 1768 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1769 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | return 0; |
| 1771 | } |
| 1772 | #endif /* CONFIG_PM */ |
| 1773 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1774 | static int snd_es18xx_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1776 | struct snd_audiodrive *acard = card->private_data; |
| 1777 | struct snd_es18xx *chip = acard->chip; |
| 1778 | |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 1779 | release_and_free_resource(chip->res_port); |
| 1780 | release_and_free_resource(chip->res_ctrl_port); |
| 1781 | release_and_free_resource(chip->res_mpu_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | if (chip->irq >= 0) |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1783 | free_irq(chip->irq, (void *) card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | if (chip->dma1 >= 0) { |
| 1785 | disable_dma(chip->dma1); |
| 1786 | free_dma(chip->dma1); |
| 1787 | } |
| 1788 | if (chip->dma2 >= 0 && chip->dma1 != chip->dma2) { |
| 1789 | disable_dma(chip->dma2); |
| 1790 | free_dma(chip->dma2); |
| 1791 | } |
| 1792 | kfree(chip); |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1796 | static int snd_es18xx_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1798 | return snd_es18xx_free(device->card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1801 | static int __devinit snd_es18xx_new_device(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | unsigned long port, |
| 1803 | unsigned long mpu_port, |
| 1804 | unsigned long fm_port, |
| 1805 | int irq, int dma1, int dma2, |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1806 | struct snd_es18xx ** rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1808 | struct snd_es18xx *chip; |
| 1809 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | .dev_free = snd_es18xx_dev_free, |
| 1811 | }; |
| 1812 | int err; |
| 1813 | |
| 1814 | *rchip = NULL; |
Takashi Iwai | 9e76a76 | 2005-09-09 14:21:17 +0200 | [diff] [blame] | 1815 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | if (chip == NULL) |
| 1817 | return -ENOMEM; |
| 1818 | spin_lock_init(&chip->reg_lock); |
| 1819 | spin_lock_init(&chip->mixer_lock); |
| 1820 | spin_lock_init(&chip->ctrl_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | chip->port = port; |
| 1822 | chip->mpu_port = mpu_port; |
| 1823 | chip->fm_port = fm_port; |
| 1824 | chip->irq = -1; |
| 1825 | chip->dma1 = -1; |
| 1826 | chip->dma2 = -1; |
| 1827 | chip->audio2_vol = 0x00; |
| 1828 | chip->active = 0; |
| 1829 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1830 | chip->res_port = request_region(port, 16, "ES18xx"); |
| 1831 | if (chip->res_port == NULL) { |
| 1832 | snd_es18xx_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1); |
| 1834 | return -EBUSY; |
| 1835 | } |
| 1836 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1837 | if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx", |
| 1838 | (void *) card)) { |
| 1839 | snd_es18xx_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq); |
| 1841 | return -EBUSY; |
| 1842 | } |
| 1843 | chip->irq = irq; |
| 1844 | |
| 1845 | if (request_dma(dma1, "ES18xx DMA 1")) { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1846 | snd_es18xx_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1); |
| 1848 | return -EBUSY; |
| 1849 | } |
| 1850 | chip->dma1 = dma1; |
| 1851 | |
| 1852 | if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1853 | snd_es18xx_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2); |
| 1855 | return -EBUSY; |
| 1856 | } |
| 1857 | chip->dma2 = dma2; |
| 1858 | |
| 1859 | if (snd_es18xx_probe(chip) < 0) { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1860 | snd_es18xx_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | return -ENODEV; |
| 1862 | } |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1863 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, NULL, &ops); |
| 1864 | if (err < 0) { |
| 1865 | snd_es18xx_free(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | return err; |
| 1867 | } |
| 1868 | *rchip = chip; |
| 1869 | return 0; |
| 1870 | } |
| 1871 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1872 | static int __devinit snd_es18xx_mixer(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | { |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 1874 | struct snd_audiodrive *acard = card->private_data; |
| 1875 | struct snd_es18xx *chip = acard->chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | int err; |
| 1877 | unsigned int idx; |
| 1878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | strcpy(card->mixername, chip->pcm->name); |
| 1880 | |
| 1881 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1882 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip); |
| 1884 | if (chip->caps & ES18XX_HWV) { |
| 1885 | switch (idx) { |
| 1886 | case 0: |
| 1887 | chip->master_volume = kctl; |
| 1888 | kctl->private_free = snd_es18xx_hwv_free; |
| 1889 | break; |
| 1890 | case 1: |
| 1891 | chip->master_switch = kctl; |
| 1892 | kctl->private_free = snd_es18xx_hwv_free; |
| 1893 | break; |
| 1894 | } |
| 1895 | } |
| 1896 | if ((err = snd_ctl_add(card, kctl)) < 0) |
| 1897 | return err; |
| 1898 | } |
| 1899 | if (chip->caps & ES18XX_PCM2) { |
| 1900 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm2_controls); idx++) { |
| 1901 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm2_controls[idx], chip))) < 0) |
| 1902 | return err; |
| 1903 | } |
| 1904 | } else { |
| 1905 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_pcm1_controls); idx++) { |
| 1906 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_pcm1_controls[idx], chip))) < 0) |
| 1907 | return err; |
| 1908 | } |
| 1909 | } |
| 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | if (chip->caps & ES18XX_RECMIX) { |
| 1912 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_recmix_controls); idx++) { |
| 1913 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_recmix_controls[idx], chip))) < 0) |
| 1914 | return err; |
| 1915 | } |
| 1916 | } |
| 1917 | switch (chip->version) { |
| 1918 | default: |
| 1919 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre1_control, chip))) < 0) |
| 1920 | return err; |
| 1921 | break; |
| 1922 | case 0x1869: |
| 1923 | case 0x1879: |
| 1924 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_micpre2_control, chip))) < 0) |
| 1925 | return err; |
| 1926 | break; |
| 1927 | } |
| 1928 | if (chip->caps & ES18XX_SPATIALIZER) { |
| 1929 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_spatializer_controls); idx++) { |
| 1930 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_spatializer_controls[idx], chip))) < 0) |
| 1931 | return err; |
| 1932 | } |
| 1933 | } |
| 1934 | if (chip->caps & ES18XX_HWV) { |
| 1935 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1936 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip); |
| 1938 | if (idx == 0) |
| 1939 | chip->hw_volume = kctl; |
| 1940 | else |
| 1941 | chip->hw_switch = kctl; |
| 1942 | kctl->private_free = snd_es18xx_hwv_free; |
| 1943 | if ((err = snd_ctl_add(card, kctl)) < 0) |
| 1944 | return err; |
| 1945 | |
| 1946 | } |
| 1947 | } |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1948 | /* finish initializing other chipset specific controls |
| 1949 | */ |
| 1950 | if (chip->version != 0x1868) { |
| 1951 | err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_speaker, |
| 1952 | chip)); |
| 1953 | if (err < 0) |
| 1954 | return err; |
| 1955 | } |
| 1956 | if (chip->version == 0x1869) { |
| 1957 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1869); idx++) { |
| 1958 | err = snd_ctl_add(card, |
| 1959 | snd_ctl_new1(&snd_es18xx_opt_1869[idx], |
| 1960 | chip)); |
| 1961 | if (err < 0) |
| 1962 | return err; |
| 1963 | } |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 1964 | } else if (chip->version == 0x1878) { |
| 1965 | err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_1878, |
| 1966 | chip)); |
| 1967 | if (err < 0) |
| 1968 | return err; |
| 1969 | } else if (chip->version == 0x1879) { |
| 1970 | for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1879); idx++) { |
| 1971 | err = snd_ctl_add(card, |
| 1972 | snd_ctl_new1(&snd_es18xx_opt_1879[idx], |
| 1973 | chip)); |
| 1974 | if (err < 0) |
| 1975 | return err; |
| 1976 | } |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | return 0; |
| 1979 | } |
| 1980 | |
| 1981 | |
| 1982 | /* Card level */ |
| 1983 | |
| 1984 | MODULE_AUTHOR("Christian Fischbach <fishbach@pool.informatik.rwth-aachen.de>, Abramo Bagnara <abramo@alsa-project.org>"); |
| 1985 | MODULE_DESCRIPTION("ESS ES18xx AudioDrive"); |
| 1986 | MODULE_LICENSE("GPL"); |
| 1987 | MODULE_SUPPORTED_DEVICE("{{ESS,ES1868 PnP AudioDrive}," |
| 1988 | "{ESS,ES1869 PnP AudioDrive}," |
| 1989 | "{ESS,ES1878 PnP AudioDrive}," |
| 1990 | "{ESS,ES1879 PnP AudioDrive}," |
| 1991 | "{ESS,ES1887 PnP AudioDrive}," |
| 1992 | "{ESS,ES1888 PnP AudioDrive}," |
| 1993 | "{ESS,ES1887 AudioDrive}," |
| 1994 | "{ESS,ES1888 AudioDrive}}"); |
| 1995 | |
| 1996 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 1997 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 1998 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ |
| 1999 | #ifdef CONFIG_PNP |
| 2000 | static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; |
| 2001 | #endif |
| 2002 | static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */ |
| 2003 | #ifndef CONFIG_PNP |
| 2004 | static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; |
| 2005 | #else |
| 2006 | static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; |
| 2007 | #endif |
| 2008 | static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; |
| 2009 | static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ |
| 2010 | static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 2011 | static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */ |
| 2012 | |
| 2013 | module_param_array(index, int, NULL, 0444); |
| 2014 | MODULE_PARM_DESC(index, "Index value for ES18xx soundcard."); |
| 2015 | module_param_array(id, charp, NULL, 0444); |
| 2016 | MODULE_PARM_DESC(id, "ID string for ES18xx soundcard."); |
| 2017 | module_param_array(enable, bool, NULL, 0444); |
| 2018 | MODULE_PARM_DESC(enable, "Enable ES18xx soundcard."); |
| 2019 | #ifdef CONFIG_PNP |
| 2020 | module_param_array(isapnp, bool, NULL, 0444); |
| 2021 | MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard."); |
| 2022 | #endif |
| 2023 | module_param_array(port, long, NULL, 0444); |
| 2024 | MODULE_PARM_DESC(port, "Port # for ES18xx driver."); |
| 2025 | module_param_array(mpu_port, long, NULL, 0444); |
| 2026 | MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ES18xx driver."); |
| 2027 | module_param_array(fm_port, long, NULL, 0444); |
| 2028 | MODULE_PARM_DESC(fm_port, "FM port # for ES18xx driver."); |
| 2029 | module_param_array(irq, int, NULL, 0444); |
| 2030 | MODULE_PARM_DESC(irq, "IRQ # for ES18xx driver."); |
| 2031 | module_param_array(dma1, int, NULL, 0444); |
| 2032 | MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver."); |
| 2033 | module_param_array(dma2, int, NULL, 0444); |
| 2034 | MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver."); |
| 2035 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | #ifdef CONFIG_PNP |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 2037 | static int isa_registered; |
| 2038 | static int pnp_registered; |
| 2039 | static int pnpc_registered; |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2040 | |
| 2041 | static struct pnp_device_id snd_audiodrive_pnpbiosids[] = { |
| 2042 | { .id = "ESS1869" }, |
Rene Herman | 4848ffe | 2007-08-01 23:50:21 +0200 | [diff] [blame] | 2043 | { .id = "ESS1879" }, |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2044 | { .id = "" } /* end */ |
| 2045 | }; |
| 2046 | |
| 2047 | MODULE_DEVICE_TABLE(pnp, snd_audiodrive_pnpbiosids); |
| 2048 | |
| 2049 | /* PnP main device initialization */ |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2050 | static int __devinit snd_audiodrive_pnp_init_main(int dev, struct pnp_dev *pdev) |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2051 | { |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2052 | if (pnp_activate_dev(pdev) < 0) { |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2053 | snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n"); |
| 2054 | return -EBUSY; |
| 2055 | } |
| 2056 | /* ok. hack using Vendor-Defined Card-Level registers */ |
| 2057 | /* skip csn and logdev initialization - already done in isapnp_configure */ |
| 2058 | if (pnp_device_is_isapnp(pdev)) { |
| 2059 | isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev)); |
| 2060 | isapnp_write_byte(0x27, pnp_irq(pdev, 0)); /* Hardware Volume IRQ Number */ |
| 2061 | if (mpu_port[dev] != SNDRV_AUTO_PORT) |
| 2062 | isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */ |
| 2063 | isapnp_write_byte(0x72, pnp_irq(pdev, 0)); /* second IRQ */ |
| 2064 | isapnp_cfg_end(); |
| 2065 | } |
| 2066 | port[dev] = pnp_port_start(pdev, 0); |
| 2067 | fm_port[dev] = pnp_port_start(pdev, 1); |
| 2068 | mpu_port[dev] = pnp_port_start(pdev, 2); |
| 2069 | dma1[dev] = pnp_dma(pdev, 0); |
| 2070 | dma2[dev] = pnp_dma(pdev, 1); |
| 2071 | irq[dev] = pnp_irq(pdev, 0); |
| 2072 | snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]); |
| 2073 | snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]); |
| 2074 | return 0; |
| 2075 | } |
| 2076 | |
| 2077 | static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard, |
| 2078 | struct pnp_dev *pdev) |
| 2079 | { |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2080 | acard->dev = pdev; |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2081 | if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2082 | return -EBUSY; |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2083 | return 0; |
| 2084 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | |
| 2086 | static struct pnp_card_device_id snd_audiodrive_pnpids[] = { |
| 2087 | /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */ |
| 2088 | { .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } }, |
| 2089 | /* ESS 1868 (integrated on Maxisound Cards) */ |
| 2090 | { .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } }, |
| 2091 | /* ESS 1868 (integrated on Maxisound Cards) */ |
| 2092 | { .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } }, |
| 2093 | /* ESS ES1869 Plug and Play AudioDrive */ |
| 2094 | { .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } }, |
| 2095 | /* ESS 1869 */ |
| 2096 | { .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } }, |
| 2097 | /* ESS 1878 */ |
| 2098 | { .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } }, |
| 2099 | /* ESS 1879 */ |
| 2100 | { .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } }, |
| 2101 | /* --- */ |
| 2102 | { .id = "" } /* end */ |
| 2103 | }; |
| 2104 | |
| 2105 | MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids); |
| 2106 | |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2107 | static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | struct pnp_card_link *card, |
| 2109 | const struct pnp_card_device_id *id) |
| 2110 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2111 | acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2112 | if (acard->dev == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | return -EBUSY; |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL); |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2116 | if (acard->devc == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | return -EBUSY; |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | /* Control port initialization */ |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2120 | if (pnp_activate_dev(acard->devc) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n"); |
| 2122 | return -EAGAIN; |
| 2123 | } |
Greg Kroah-Hartman | aa0a2dd | 2006-06-12 14:50:27 -0700 | [diff] [blame] | 2124 | snd_printdd("pnp: port=0x%llx\n", |
| 2125 | (unsigned long long)pnp_port_start(acard->devc, 0)); |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2126 | if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | return -EBUSY; |
Rene Herman | 109c53f84 | 2007-11-30 17:59:25 +0100 | [diff] [blame] | 2128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | return 0; |
| 2130 | } |
| 2131 | #endif /* CONFIG_PNP */ |
| 2132 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2133 | #ifdef CONFIG_PNP |
| 2134 | #define is_isapnp_selected(dev) isapnp[dev] |
| 2135 | #else |
| 2136 | #define is_isapnp_selected(dev) 0 |
| 2137 | #endif |
| 2138 | |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 2139 | static int snd_es18xx_card_new(int dev, struct snd_card **cardp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | { |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 2141 | return snd_card_create(index[dev], id[dev], THIS_MODULE, |
| 2142 | sizeof(struct snd_audiodrive), cardp); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev) |
| 2146 | { |
| 2147 | struct snd_audiodrive *acard = card->private_data; |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 2148 | struct snd_es18xx *chip; |
| 2149 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | int err; |
| 2151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | if ((err = snd_es18xx_new_device(card, |
| 2153 | port[dev], |
| 2154 | mpu_port[dev], |
| 2155 | fm_port[dev], |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2156 | irq[dev], dma1[dev], dma2[dev], |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2157 | &chip)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2158 | return err; |
| 2159 | acard->chip = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | |
| 2161 | sprintf(card->driver, "ES%x", chip->version); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2163 | sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2164 | if (dma1[dev] != dma2[dev]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d", |
| 2166 | card->shortname, |
| 2167 | chip->port, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2168 | irq[dev], dma1[dev], dma2[dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | else |
| 2170 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", |
| 2171 | card->shortname, |
| 2172 | chip->port, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2173 | irq[dev], dma1[dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 2175 | err = snd_es18xx_pcm(card, 0, NULL); |
| 2176 | if (err < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2177 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2178 | |
Krzysztof Helt | 3c76b4d | 2009-10-25 11:05:19 +0100 | [diff] [blame^] | 2179 | err = snd_es18xx_mixer(card); |
| 2180 | if (err < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2181 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
| 2183 | if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { |
| 2184 | if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2185 | snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | } else { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2187 | if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2188 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
| 2193 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, |
| 2194 | chip->mpu_port, 0, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2195 | irq[dev], 0, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2196 | &chip->rmidi)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2197 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | } |
| 2199 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2200 | return snd_card_register(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2203 | static int __devinit snd_es18xx_isa_match(struct device *pdev, unsigned int dev) |
| 2204 | { |
| 2205 | return enable[dev] && !is_isapnp_selected(dev); |
| 2206 | } |
| 2207 | |
| 2208 | static int __devinit snd_es18xx_isa_probe1(int dev, struct device *devptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2210 | struct snd_card *card; |
| 2211 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 2213 | err = snd_es18xx_card_new(dev, &card); |
| 2214 | if (err < 0) |
| 2215 | return err; |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2216 | snd_card_set_dev(card, devptr); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2217 | if ((err = snd_audiodrive_probe(card, dev)) < 0) { |
| 2218 | snd_card_free(card); |
| 2219 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | } |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2221 | dev_set_drvdata(devptr, card); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2222 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2225 | static int __devinit snd_es18xx_isa_probe(struct device *pdev, unsigned int dev) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2226 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2227 | int err; |
| 2228 | static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1}; |
| 2229 | static int possible_dmas[] = {1, 0, 3, 5, -1}; |
| 2230 | |
| 2231 | if (irq[dev] == SNDRV_AUTO_IRQ) { |
| 2232 | if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) { |
| 2233 | snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); |
| 2234 | return -EBUSY; |
| 2235 | } |
| 2236 | } |
| 2237 | if (dma1[dev] == SNDRV_AUTO_DMA) { |
| 2238 | if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { |
| 2239 | snd_printk(KERN_ERR PFX "unable to find a free DMA1\n"); |
| 2240 | return -EBUSY; |
| 2241 | } |
| 2242 | } |
| 2243 | if (dma2[dev] == SNDRV_AUTO_DMA) { |
| 2244 | if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) { |
| 2245 | snd_printk(KERN_ERR PFX "unable to find a free DMA2\n"); |
| 2246 | return -EBUSY; |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | if (port[dev] != SNDRV_AUTO_PORT) { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2251 | return snd_es18xx_isa_probe1(dev, pdev); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2252 | } else { |
| 2253 | static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280}; |
| 2254 | int i; |
| 2255 | for (i = 0; i < ARRAY_SIZE(possible_ports); i++) { |
| 2256 | port[dev] = possible_ports[i]; |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2257 | err = snd_es18xx_isa_probe1(dev, pdev); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2258 | if (! err) |
| 2259 | return 0; |
| 2260 | } |
| 2261 | return err; |
| 2262 | } |
| 2263 | } |
| 2264 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2265 | static int __devexit snd_es18xx_isa_remove(struct device *devptr, |
| 2266 | unsigned int dev) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2267 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2268 | snd_card_free(dev_get_drvdata(devptr)); |
| 2269 | dev_set_drvdata(devptr, NULL); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2270 | return 0; |
| 2271 | } |
| 2272 | |
| 2273 | #ifdef CONFIG_PM |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2274 | static int snd_es18xx_isa_suspend(struct device *dev, unsigned int n, |
| 2275 | pm_message_t state) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2276 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2277 | return snd_es18xx_suspend(dev_get_drvdata(dev), state); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2278 | } |
| 2279 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2280 | static int snd_es18xx_isa_resume(struct device *dev, unsigned int n) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2281 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2282 | return snd_es18xx_resume(dev_get_drvdata(dev)); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2283 | } |
| 2284 | #endif |
| 2285 | |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 2286 | #define DEV_NAME "es18xx" |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2287 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2288 | static struct isa_driver snd_es18xx_isa_driver = { |
| 2289 | .match = snd_es18xx_isa_match, |
| 2290 | .probe = snd_es18xx_isa_probe, |
| 2291 | .remove = __devexit_p(snd_es18xx_isa_remove), |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2292 | #ifdef CONFIG_PM |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2293 | .suspend = snd_es18xx_isa_suspend, |
| 2294 | .resume = snd_es18xx_isa_resume, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2295 | #endif |
| 2296 | .driver = { |
Rene Herman | 83c51c0 | 2007-03-20 11:33:46 +0100 | [diff] [blame] | 2297 | .name = DEV_NAME |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2298 | }, |
| 2299 | }; |
| 2300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | |
| 2302 | #ifdef CONFIG_PNP |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2303 | static int __devinit snd_audiodrive_pnp_detect(struct pnp_dev *pdev, |
| 2304 | const struct pnp_device_id *id) |
| 2305 | { |
| 2306 | static int dev; |
| 2307 | int err; |
| 2308 | struct snd_card *card; |
| 2309 | |
| 2310 | if (pnp_device_is_isapnp(pdev)) |
| 2311 | return -ENOENT; /* we have another procedure - card */ |
| 2312 | for (; dev < SNDRV_CARDS; dev++) { |
| 2313 | if (enable[dev] && isapnp[dev]) |
| 2314 | break; |
| 2315 | } |
| 2316 | if (dev >= SNDRV_CARDS) |
| 2317 | return -ENODEV; |
| 2318 | |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 2319 | err = snd_es18xx_card_new(dev, &card); |
| 2320 | if (err < 0) |
| 2321 | return err; |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2322 | if ((err = snd_audiodrive_pnp(dev, card->private_data, pdev)) < 0) { |
| 2323 | snd_card_free(card); |
| 2324 | return err; |
| 2325 | } |
| 2326 | snd_card_set_dev(card, &pdev->dev); |
| 2327 | if ((err = snd_audiodrive_probe(card, dev)) < 0) { |
| 2328 | snd_card_free(card); |
| 2329 | return err; |
| 2330 | } |
| 2331 | pnp_set_drvdata(pdev, card); |
| 2332 | dev++; |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2333 | return 0; |
| 2334 | } |
| 2335 | |
| 2336 | static void __devexit snd_audiodrive_pnp_remove(struct pnp_dev * pdev) |
| 2337 | { |
| 2338 | snd_card_free(pnp_get_drvdata(pdev)); |
| 2339 | pnp_set_drvdata(pdev, NULL); |
| 2340 | } |
| 2341 | |
| 2342 | #ifdef CONFIG_PM |
| 2343 | static int snd_audiodrive_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) |
| 2344 | { |
| 2345 | return snd_es18xx_suspend(pnp_get_drvdata(pdev), state); |
| 2346 | } |
| 2347 | static int snd_audiodrive_pnp_resume(struct pnp_dev *pdev) |
| 2348 | { |
| 2349 | return snd_es18xx_resume(pnp_get_drvdata(pdev)); |
| 2350 | } |
| 2351 | #endif |
| 2352 | |
| 2353 | static struct pnp_driver es18xx_pnp_driver = { |
| 2354 | .name = "es18xx-pnpbios", |
| 2355 | .id_table = snd_audiodrive_pnpbiosids, |
| 2356 | .probe = snd_audiodrive_pnp_detect, |
| 2357 | .remove = __devexit_p(snd_audiodrive_pnp_remove), |
| 2358 | #ifdef CONFIG_PM |
| 2359 | .suspend = snd_audiodrive_pnp_suspend, |
| 2360 | .resume = snd_audiodrive_pnp_resume, |
| 2361 | #endif |
| 2362 | }; |
| 2363 | |
| 2364 | static int __devinit snd_audiodrive_pnpc_detect(struct pnp_card_link *pcard, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2365 | const struct pnp_card_device_id *pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | { |
| 2367 | static int dev; |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2368 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2369 | int res; |
| 2370 | |
| 2371 | for ( ; dev < SNDRV_CARDS; dev++) { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2372 | if (enable[dev] && isapnp[dev]) |
| 2373 | break; |
| 2374 | } |
| 2375 | if (dev >= SNDRV_CARDS) |
| 2376 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | |
Takashi Iwai | 3e7fb9f | 2008-12-28 16:47:30 +0100 | [diff] [blame] | 2378 | res = snd_es18xx_card_new(dev, &card); |
| 2379 | if (res < 0) |
| 2380 | return res; |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2381 | |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2382 | if ((res = snd_audiodrive_pnpc(dev, card->private_data, pcard, pid)) < 0) { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2383 | snd_card_free(card); |
| 2384 | return res; |
| 2385 | } |
| 2386 | snd_card_set_dev(card, &pcard->card->dev); |
| 2387 | if ((res = snd_audiodrive_probe(card, dev)) < 0) { |
| 2388 | snd_card_free(card); |
| 2389 | return res; |
| 2390 | } |
| 2391 | |
| 2392 | pnp_set_card_drvdata(pcard, card); |
| 2393 | dev++; |
| 2394 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | } |
| 2396 | |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2397 | static void __devexit snd_audiodrive_pnpc_remove(struct pnp_card_link * pcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2399 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 2400 | pnp_set_card_drvdata(pcard, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | } |
| 2402 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2403 | #ifdef CONFIG_PM |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2404 | static int snd_audiodrive_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2405 | { |
| 2406 | return snd_es18xx_suspend(pnp_get_card_drvdata(pcard), state); |
| 2407 | } |
| 2408 | |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2409 | static int snd_audiodrive_pnpc_resume(struct pnp_card_link *pcard) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2410 | { |
| 2411 | return snd_es18xx_resume(pnp_get_card_drvdata(pcard)); |
| 2412 | } |
| 2413 | |
| 2414 | #endif |
| 2415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | static struct pnp_card_driver es18xx_pnpc_driver = { |
| 2417 | .flags = PNP_DRIVER_RES_DISABLE, |
| 2418 | .name = "es18xx", |
| 2419 | .id_table = snd_audiodrive_pnpids, |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2420 | .probe = snd_audiodrive_pnpc_detect, |
| 2421 | .remove = __devexit_p(snd_audiodrive_pnpc_remove), |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2422 | #ifdef CONFIG_PM |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2423 | .suspend = snd_audiodrive_pnpc_suspend, |
| 2424 | .resume = snd_audiodrive_pnpc_resume, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2425 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | }; |
| 2427 | #endif /* CONFIG_PNP */ |
| 2428 | |
| 2429 | static int __init alsa_card_es18xx_init(void) |
| 2430 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2431 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2433 | err = isa_register_driver(&snd_es18xx_isa_driver, SNDRV_CARDS); |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 2434 | #ifdef CONFIG_PNP |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 2435 | if (!err) |
| 2436 | isa_registered = 1; |
| 2437 | |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2438 | err = pnp_register_driver(&es18xx_pnp_driver); |
| 2439 | if (!err) |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2440 | pnp_registered = 1; |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 2441 | |
Ondrej Zary | 1c398558 | 2006-07-31 12:51:57 +0200 | [diff] [blame] | 2442 | err = pnp_register_card_driver(&es18xx_pnpc_driver); |
| 2443 | if (!err) |
| 2444 | pnpc_registered = 1; |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 2445 | |
| 2446 | if (isa_registered || pnp_registered) |
| 2447 | err = 0; |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 2448 | #endif |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 2449 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | static void __exit alsa_card_es18xx_exit(void) |
| 2453 | { |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2454 | #ifdef CONFIG_PNP |
| 2455 | if (pnpc_registered) |
| 2456 | pnp_unregister_card_driver(&es18xx_pnpc_driver); |
| 2457 | if (pnp_registered) |
| 2458 | pnp_unregister_driver(&es18xx_pnp_driver); |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 2459 | if (isa_registered) |
Takashi Iwai | 5e24c1c | 2007-02-22 12:50:54 +0100 | [diff] [blame] | 2460 | #endif |
Rene Herman | 609d769 | 2007-05-15 11:42:56 +0200 | [diff] [blame] | 2461 | isa_unregister_driver(&snd_es18xx_isa_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | module_init(alsa_card_es18xx_init) |
| 2465 | module_exit(alsa_card_es18xx_exit) |