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 <sound/driver.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include <linux/init.h> |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 82 | #include <linux/err.h> |
| 83 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #include <linux/slab.h> |
| 85 | #include <linux/pnp.h> |
| 86 | #include <linux/isapnp.h> |
| 87 | #include <linux/moduleparam.h> |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 88 | #include <asm/io.h> |
| 89 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | #include <sound/core.h> |
| 91 | #include <sound/control.h> |
| 92 | #include <sound/pcm.h> |
| 93 | #include <sound/pcm_params.h> |
| 94 | #include <sound/mpu401.h> |
| 95 | #include <sound/opl3.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #define SNDRV_LEGACY_FIND_FREE_IRQ |
| 97 | #define SNDRV_LEGACY_FIND_FREE_DMA |
| 98 | #include <sound/initval.h> |
| 99 | |
| 100 | #define PFX "es18xx: " |
| 101 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 102 | struct snd_es18xx { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | unsigned long port; /* port of ESS chip */ |
| 104 | unsigned long mpu_port; /* MPU-401 port of ESS chip */ |
| 105 | unsigned long fm_port; /* FM port */ |
| 106 | unsigned long ctrl_port; /* Control port of ESS chip */ |
| 107 | struct resource *res_port; |
| 108 | struct resource *res_mpu_port; |
| 109 | struct resource *res_ctrl_port; |
| 110 | int irq; /* IRQ number of ESS chip */ |
| 111 | int dma1; /* DMA1 */ |
| 112 | int dma2; /* DMA2 */ |
| 113 | unsigned short version; /* version of ESS chip */ |
| 114 | int caps; /* Chip capabilities */ |
| 115 | unsigned short audio2_vol; /* volume level of audio2 */ |
| 116 | |
| 117 | unsigned short active; /* active channel mask */ |
| 118 | unsigned int dma1_size; |
| 119 | unsigned int dma2_size; |
| 120 | unsigned int dma1_shift; |
| 121 | unsigned int dma2_shift; |
| 122 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 123 | struct snd_card *card; |
| 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 */ |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 164 | #define ES18XX_HWV 0x0080 /* Has seperate 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 | |
| 624 | /* Set DMA controler */ |
| 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 | |
| 690 | /* Set DMA controler */ |
| 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 | |
| 755 | static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 756 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 757 | struct snd_es18xx *chip = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | unsigned char status; |
| 759 | |
| 760 | if (chip->caps & ES18XX_CONTROL) { |
| 761 | /* Read Interrupt status */ |
| 762 | status = inb(chip->ctrl_port + 6); |
| 763 | } else { |
| 764 | /* Read Interrupt status */ |
| 765 | status = snd_es18xx_mixer_read(chip, 0x7f) >> 4; |
| 766 | } |
| 767 | #if 0 |
| 768 | else { |
| 769 | status = 0; |
| 770 | if (inb(chip->port + 0x0C) & 0x01) |
| 771 | status |= AUDIO1_IRQ; |
| 772 | if (snd_es18xx_mixer_read(chip, 0x7A) & 0x80) |
| 773 | status |= AUDIO2_IRQ; |
| 774 | if ((chip->caps & ES18XX_HWV) && |
| 775 | snd_es18xx_mixer_read(chip, 0x64) & 0x10) |
| 776 | status |= HWV_IRQ; |
| 777 | } |
| 778 | #endif |
| 779 | |
| 780 | /* Audio 1 & Audio 2 */ |
| 781 | if (status & AUDIO2_IRQ) { |
| 782 | if (chip->active & DAC2) |
| 783 | snd_pcm_period_elapsed(chip->playback_a_substream); |
| 784 | /* ack interrupt */ |
| 785 | snd_es18xx_mixer_bits(chip, 0x7A, 0x80, 0x00); |
| 786 | } |
| 787 | if (status & AUDIO1_IRQ) { |
| 788 | /* ok.. capture is active */ |
| 789 | if (chip->active & ADC1) |
| 790 | snd_pcm_period_elapsed(chip->capture_a_substream); |
| 791 | /* ok.. playback2 is active */ |
| 792 | else if (chip->active & DAC1) |
| 793 | snd_pcm_period_elapsed(chip->playback_b_substream); |
| 794 | /* ack interrupt */ |
| 795 | inb(chip->port + 0x0E); |
| 796 | } |
| 797 | |
| 798 | /* MPU */ |
| 799 | if ((status & MPU_IRQ) && chip->rmidi) |
| 800 | snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs); |
| 801 | |
| 802 | /* Hardware volume */ |
| 803 | if (status & HWV_IRQ) { |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 804 | int split = 0; |
| 805 | if (chip->caps & ES18XX_HWV) { |
| 806 | split = snd_es18xx_mixer_read(chip, 0x64) & 0x80; |
| 807 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id); |
| 808 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id); |
| 809 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (!split) { |
| 811 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id); |
| 812 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id); |
| 813 | } |
| 814 | /* ack interrupt */ |
| 815 | snd_es18xx_mixer_write(chip, 0x66, 0x00); |
| 816 | } |
| 817 | return IRQ_HANDLED; |
| 818 | } |
| 819 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 820 | 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] | 821 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 822 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | int pos; |
| 824 | |
| 825 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 826 | if (!(chip->active & DAC2)) |
| 827 | return 0; |
| 828 | pos = snd_dma_pointer(chip->dma2, chip->dma2_size); |
| 829 | return pos >> chip->dma2_shift; |
| 830 | } else { |
| 831 | if (!(chip->active & DAC1)) |
| 832 | return 0; |
| 833 | pos = snd_dma_pointer(chip->dma1, chip->dma1_size); |
| 834 | return pos >> chip->dma1_shift; |
| 835 | } |
| 836 | } |
| 837 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 838 | 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] | 839 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 840 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | int pos; |
| 842 | |
| 843 | if (!(chip->active & ADC1)) |
| 844 | return 0; |
| 845 | pos = snd_dma_pointer(chip->dma1, chip->dma1_size); |
| 846 | return pos >> chip->dma1_shift; |
| 847 | } |
| 848 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 849 | static struct snd_pcm_hardware snd_es18xx_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | { |
| 851 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 852 | SNDRV_PCM_INFO_RESUME | |
| 853 | SNDRV_PCM_INFO_MMAP_VALID), |
| 854 | .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | |
| 855 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE), |
| 856 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 857 | .rate_min = 4000, |
| 858 | .rate_max = 48000, |
| 859 | .channels_min = 1, |
| 860 | .channels_max = 2, |
| 861 | .buffer_bytes_max = 65536, |
| 862 | .period_bytes_min = 64, |
| 863 | .period_bytes_max = 65536, |
| 864 | .periods_min = 1, |
| 865 | .periods_max = 1024, |
| 866 | .fifo_size = 0, |
| 867 | }; |
| 868 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 869 | static struct snd_pcm_hardware snd_es18xx_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
| 871 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 872 | SNDRV_PCM_INFO_RESUME | |
| 873 | SNDRV_PCM_INFO_MMAP_VALID), |
| 874 | .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 | |
| 875 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE), |
| 876 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 877 | .rate_min = 4000, |
| 878 | .rate_max = 48000, |
| 879 | .channels_min = 1, |
| 880 | .channels_max = 2, |
| 881 | .buffer_bytes_max = 65536, |
| 882 | .period_bytes_min = 64, |
| 883 | .period_bytes_max = 65536, |
| 884 | .periods_min = 1, |
| 885 | .periods_max = 1024, |
| 886 | .fifo_size = 0, |
| 887 | }; |
| 888 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 889 | static int snd_es18xx_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 891 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 892 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
| 894 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) { |
| 895 | if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 896 | chip->capture_a_substream && |
| 897 | chip->capture_a_substream->runtime->channels != 1) |
| 898 | return -EAGAIN; |
| 899 | chip->playback_a_substream = substream; |
| 900 | } else if (substream->number <= 1) { |
| 901 | if (chip->capture_a_substream) |
| 902 | return -EAGAIN; |
| 903 | chip->playback_b_substream = substream; |
| 904 | } else { |
| 905 | snd_BUG(); |
| 906 | return -EINVAL; |
| 907 | } |
| 908 | substream->runtime->hw = snd_es18xx_playback; |
| 909 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 910 | (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks); |
| 911 | return 0; |
| 912 | } |
| 913 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 914 | static int snd_es18xx_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 916 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 917 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | if (chip->playback_b_substream) |
| 920 | return -EAGAIN; |
| 921 | if ((chip->caps & ES18XX_DUPLEX_MONO) && |
| 922 | chip->playback_a_substream && |
| 923 | chip->playback_a_substream->runtime->channels != 1) |
| 924 | return -EAGAIN; |
| 925 | chip->capture_a_substream = substream; |
| 926 | substream->runtime->hw = snd_es18xx_capture; |
| 927 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 928 | (chip->caps & ES18XX_NEW_RATE) ? &new_hw_constraints_clocks : &old_hw_constraints_clocks); |
| 929 | return 0; |
| 930 | } |
| 931 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 932 | static int snd_es18xx_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 934 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| 936 | if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) |
| 937 | chip->playback_a_substream = NULL; |
| 938 | else |
| 939 | chip->playback_b_substream = NULL; |
| 940 | |
| 941 | snd_pcm_lib_free_pages(substream); |
| 942 | return 0; |
| 943 | } |
| 944 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 945 | static int snd_es18xx_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 947 | struct snd_es18xx *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
| 949 | chip->capture_a_substream = NULL; |
| 950 | snd_pcm_lib_free_pages(substream); |
| 951 | return 0; |
| 952 | } |
| 953 | |
| 954 | /* |
| 955 | * MIXER part |
| 956 | */ |
| 957 | |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 958 | /* Record source mux routines: |
| 959 | * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs. |
| 960 | * bit table for the 4/5 source mux: |
| 961 | * reg 1C: |
| 962 | * b2 b1 b0 muxSource |
| 963 | * x 0 x microphone |
| 964 | * 0 1 x CD |
| 965 | * 1 1 0 line |
| 966 | * 1 1 1 mixer |
| 967 | * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines |
| 968 | * either the play mixer or the capture mixer. |
| 969 | * |
| 970 | * "map4Source" translates from source number to reg bit pattern |
| 971 | * "invMap4Source" translates from reg bit pattern to source number |
| 972 | */ |
| 973 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 974 | 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] | 975 | { |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 976 | static char *texts4Source[4] = { |
| 977 | "Mic", "CD", "Line", "Master" |
| 978 | }; |
| 979 | static char *texts5Source[5] = { |
| 980 | "Mic", "CD", "Line", "Master", "Mix" |
| 981 | }; |
| 982 | static char *texts8Source[8] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | "Mic", "Mic Master", "CD", "AOUT", |
| 984 | "Mic1", "Mix", "Line", "Master" |
| 985 | }; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 986 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
| 988 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 989 | uinfo->count = 1; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 990 | switch (chip->version) { |
| 991 | case 0x1868: |
| 992 | case 0x1878: |
| 993 | uinfo->value.enumerated.items = 4; |
| 994 | if (uinfo->value.enumerated.item > 3) |
| 995 | uinfo->value.enumerated.item = 3; |
| 996 | strcpy(uinfo->value.enumerated.name, texts4Source[uinfo->value.enumerated.item]); |
| 997 | break; |
| 998 | case 0x1887: |
| 999 | case 0x1888: |
| 1000 | uinfo->value.enumerated.items = 5; |
| 1001 | if (uinfo->value.enumerated.item > 4) |
| 1002 | uinfo->value.enumerated.item = 4; |
| 1003 | strcpy(uinfo->value.enumerated.name, texts5Source[uinfo->value.enumerated.item]); |
| 1004 | break; |
| 1005 | case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */ |
| 1006 | case 0x1879: |
| 1007 | uinfo->value.enumerated.items = 8; |
| 1008 | if (uinfo->value.enumerated.item > 7) |
| 1009 | uinfo->value.enumerated.item = 7; |
| 1010 | strcpy(uinfo->value.enumerated.name, texts8Source[uinfo->value.enumerated.item]); |
| 1011 | break; |
| 1012 | default: |
| 1013 | return -EINVAL; |
| 1014 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | return 0; |
| 1016 | } |
| 1017 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1018 | 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] | 1019 | { |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1020 | 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] | 1021 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1022 | int muxSource = snd_es18xx_mixer_read(chip, 0x1c) & 0x07; |
| 1023 | if (!(chip->version == 0x1869 || chip->version == 0x1879)) { |
| 1024 | muxSource = invMap4Source[muxSource]; |
| 1025 | if (muxSource==3 && |
| 1026 | (chip->version == 0x1887 || chip->version == 0x1888) && |
| 1027 | (snd_es18xx_mixer_read(chip, 0x7a) & 0x08) |
| 1028 | ) |
| 1029 | muxSource = 4; |
| 1030 | } |
| 1031 | ucontrol->value.enumerated.item[0] = muxSource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | return 0; |
| 1033 | } |
| 1034 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1035 | 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] | 1036 | { |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1037 | static unsigned char map4Source[4] = {0, 2, 6, 7}; |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1038 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | unsigned char val = ucontrol->value.enumerated.item[0]; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1040 | unsigned char retVal = 0; |
| 1041 | |
| 1042 | switch (chip->version) { |
| 1043 | /* 5 source chips */ |
| 1044 | case 0x1887: |
| 1045 | case 0x1888: |
| 1046 | if (val > 4) |
| 1047 | return -EINVAL; |
| 1048 | if (val == 4) { |
| 1049 | retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x08) != 0x08; |
| 1050 | val = 3; |
| 1051 | } else |
| 1052 | retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x00) != 0x00; |
| 1053 | /* 4 source chips */ |
| 1054 | case 0x1868: |
| 1055 | case 0x1878: |
| 1056 | if (val > 3) |
| 1057 | return -EINVAL; |
| 1058 | val = map4Source[val]; |
| 1059 | break; |
| 1060 | /* 8 source chips */ |
| 1061 | case 0x1869: |
| 1062 | case 0x1879: |
| 1063 | if (val > 7) |
| 1064 | return -EINVAL; |
| 1065 | break; |
| 1066 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | return -EINVAL; |
Mark Salazar | f4df221 | 2006-01-16 11:31:14 +0100 | [diff] [blame] | 1068 | } |
| 1069 | return (snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val) || retVal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | } |
| 1071 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1072 | static int snd_es18xx_info_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | { |
| 1074 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1075 | uinfo->count = 1; |
| 1076 | uinfo->value.integer.min = 0; |
| 1077 | uinfo->value.integer.max = 1; |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1081 | 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] | 1082 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1083 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | unsigned char val = snd_es18xx_mixer_read(chip, 0x50); |
| 1085 | ucontrol->value.integer.value[0] = !!(val & 8); |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1089 | 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] | 1090 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1091 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | unsigned char oval, nval; |
| 1093 | int change; |
| 1094 | nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04; |
| 1095 | oval = snd_es18xx_mixer_read(chip, 0x50) & 0x0c; |
| 1096 | change = nval != oval; |
| 1097 | if (change) { |
| 1098 | snd_es18xx_mixer_write(chip, 0x50, nval & ~0x04); |
| 1099 | snd_es18xx_mixer_write(chip, 0x50, nval); |
| 1100 | } |
| 1101 | return change; |
| 1102 | } |
| 1103 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1104 | 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] | 1105 | { |
| 1106 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1107 | uinfo->count = 2; |
| 1108 | uinfo->value.integer.min = 0; |
| 1109 | uinfo->value.integer.max = 63; |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1113 | 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] | 1114 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1115 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f; |
| 1117 | ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f; |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1121 | static int snd_es18xx_info_hw_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | { |
| 1123 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1124 | uinfo->count = 2; |
| 1125 | uinfo->value.integer.min = 0; |
| 1126 | uinfo->value.integer.max = 1; |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1130 | 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] | 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 | ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40); |
| 1134 | ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40); |
| 1135 | return 0; |
| 1136 | } |
| 1137 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1138 | static void snd_es18xx_hwv_free(struct snd_kcontrol *kcontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1140 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | chip->master_volume = NULL; |
| 1142 | chip->master_switch = NULL; |
| 1143 | chip->hw_volume = NULL; |
| 1144 | chip->hw_switch = NULL; |
| 1145 | } |
| 1146 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1147 | 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] | 1148 | unsigned char mask, unsigned char val) |
| 1149 | { |
| 1150 | if (reg < 0xa0) |
| 1151 | return snd_es18xx_mixer_bits(chip, reg, mask, val); |
| 1152 | else |
| 1153 | return snd_es18xx_bits(chip, reg, mask, val); |
| 1154 | } |
| 1155 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1156 | 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] | 1157 | { |
| 1158 | if (reg < 0xa0) |
| 1159 | return snd_es18xx_mixer_read(chip, reg); |
| 1160 | else |
| 1161 | return snd_es18xx_read(chip, reg); |
| 1162 | } |
| 1163 | |
| 1164 | #define ES18XX_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
| 1165 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 1166 | .info = snd_es18xx_info_single, \ |
| 1167 | .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \ |
| 1168 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } |
| 1169 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1170 | 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] | 1171 | { |
| 1172 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1173 | |
| 1174 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1175 | uinfo->count = 1; |
| 1176 | uinfo->value.integer.min = 0; |
| 1177 | uinfo->value.integer.max = mask; |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1181 | 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] | 1182 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1183 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | int reg = kcontrol->private_value & 0xff; |
| 1185 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1186 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1187 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1188 | int val; |
| 1189 | |
| 1190 | val = snd_es18xx_reg_read(chip, reg); |
| 1191 | ucontrol->value.integer.value[0] = (val >> shift) & mask; |
| 1192 | if (invert) |
| 1193 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1197 | 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] | 1198 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1199 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | int reg = kcontrol->private_value & 0xff; |
| 1201 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1202 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1203 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1204 | unsigned char val; |
| 1205 | |
| 1206 | val = (ucontrol->value.integer.value[0] & mask); |
| 1207 | if (invert) |
| 1208 | val = mask - val; |
| 1209 | mask <<= shift; |
| 1210 | val <<= shift; |
| 1211 | return snd_es18xx_reg_bits(chip, reg, mask, val) != val; |
| 1212 | } |
| 1213 | |
| 1214 | #define ES18XX_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ |
| 1215 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 1216 | .info = snd_es18xx_info_double, \ |
| 1217 | .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \ |
| 1218 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } |
| 1219 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1220 | 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] | 1221 | { |
| 1222 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1223 | |
| 1224 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1225 | uinfo->count = 2; |
| 1226 | uinfo->value.integer.min = 0; |
| 1227 | uinfo->value.integer.max = mask; |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1231 | 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] | 1232 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1233 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | int left_reg = kcontrol->private_value & 0xff; |
| 1235 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1236 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1237 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1238 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1239 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1240 | unsigned char left, right; |
| 1241 | |
| 1242 | left = snd_es18xx_reg_read(chip, left_reg); |
| 1243 | if (left_reg != right_reg) |
| 1244 | right = snd_es18xx_reg_read(chip, right_reg); |
| 1245 | else |
| 1246 | right = left; |
| 1247 | ucontrol->value.integer.value[0] = (left >> shift_left) & mask; |
| 1248 | ucontrol->value.integer.value[1] = (right >> shift_right) & mask; |
| 1249 | if (invert) { |
| 1250 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1251 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 1252 | } |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1256 | 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] | 1257 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1258 | struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | int left_reg = kcontrol->private_value & 0xff; |
| 1260 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1261 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1262 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1263 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1264 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1265 | int change; |
| 1266 | unsigned char val1, val2, mask1, mask2; |
| 1267 | |
| 1268 | val1 = ucontrol->value.integer.value[0] & mask; |
| 1269 | val2 = ucontrol->value.integer.value[1] & mask; |
| 1270 | if (invert) { |
| 1271 | val1 = mask - val1; |
| 1272 | val2 = mask - val2; |
| 1273 | } |
| 1274 | val1 <<= shift_left; |
| 1275 | val2 <<= shift_right; |
| 1276 | mask1 = mask << shift_left; |
| 1277 | mask2 = mask << shift_right; |
| 1278 | if (left_reg != right_reg) { |
| 1279 | change = 0; |
| 1280 | if (snd_es18xx_reg_bits(chip, left_reg, mask1, val1) != val1) |
| 1281 | change = 1; |
| 1282 | if (snd_es18xx_reg_bits(chip, right_reg, mask2, val2) != val2) |
| 1283 | change = 1; |
| 1284 | } else { |
| 1285 | change = (snd_es18xx_reg_bits(chip, left_reg, mask1 | mask2, |
| 1286 | val1 | val2) != (val1 | val2)); |
| 1287 | } |
| 1288 | return change; |
| 1289 | } |
| 1290 | |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1291 | /* Mixer controls |
| 1292 | * These arrays contain setup data for mixer controls. |
| 1293 | * |
| 1294 | * The controls that are universal to all chipsets are fully initialized |
| 1295 | * here. |
| 1296 | */ |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1297 | static struct snd_kcontrol_new snd_es18xx_base_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0), |
| 1299 | ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1), |
| 1300 | ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0), |
| 1301 | ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0), |
| 1302 | ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0), |
| 1304 | ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0), |
| 1306 | ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | { |
| 1308 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1309 | .name = "Capture Source", |
| 1310 | .info = snd_es18xx_info_mux, |
| 1311 | .get = snd_es18xx_get_mux, |
| 1312 | .put = snd_es18xx_put_mux, |
| 1313 | } |
| 1314 | }; |
| 1315 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1316 | static struct snd_kcontrol_new snd_es18xx_recmix_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0), |
| 1318 | ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0), |
| 1319 | ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0), |
| 1320 | ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0), |
| 1322 | ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0) |
| 1323 | }; |
| 1324 | |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1325 | /* |
| 1326 | * The chipset specific mixer controls |
| 1327 | */ |
| 1328 | static struct snd_kcontrol_new snd_es18xx_opt_speaker = |
| 1329 | ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0); |
| 1330 | |
| 1331 | static struct snd_kcontrol_new snd_es18xx_opt_1869[] = { |
| 1332 | ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 1333 | ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0), |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1334 | ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), |
| 1335 | ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0) |
| 1336 | }; |
| 1337 | |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 1338 | static struct snd_kcontrol_new snd_es18xx_opt_1878 = |
| 1339 | ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0); |
| 1340 | |
| 1341 | static struct snd_kcontrol_new snd_es18xx_opt_1879[] = { |
| 1342 | ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0), |
| 1343 | ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), |
| 1344 | ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0) |
| 1345 | }; |
| 1346 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1347 | static struct snd_kcontrol_new snd_es18xx_pcm1_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0), |
| 1349 | }; |
| 1350 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1351 | static struct snd_kcontrol_new snd_es18xx_pcm2_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0), |
| 1353 | ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0) |
| 1354 | }; |
| 1355 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1356 | static struct snd_kcontrol_new snd_es18xx_spatializer_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0), |
| 1358 | { |
| 1359 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1360 | .name = "3D Control - Switch", |
| 1361 | .info = snd_es18xx_info_spatializer_enable, |
| 1362 | .get = snd_es18xx_get_spatializer_enable, |
| 1363 | .put = snd_es18xx_put_spatializer_enable, |
| 1364 | } |
| 1365 | }; |
| 1366 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1367 | static struct snd_kcontrol_new snd_es18xx_micpre1_control = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0); |
| 1369 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1370 | static struct snd_kcontrol_new snd_es18xx_micpre2_control = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0); |
| 1372 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1373 | static struct snd_kcontrol_new snd_es18xx_hw_volume_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | { |
| 1375 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1376 | .name = "Hardware Master Playback Volume", |
| 1377 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1378 | .info = snd_es18xx_info_hw_volume, |
| 1379 | .get = snd_es18xx_get_hw_volume, |
| 1380 | }, |
| 1381 | { |
| 1382 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1383 | .name = "Hardware Master Playback Switch", |
| 1384 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1385 | .info = snd_es18xx_info_hw_switch, |
| 1386 | .get = snd_es18xx_get_hw_switch, |
| 1387 | }, |
| 1388 | ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0), |
| 1389 | }; |
| 1390 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1391 | 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] | 1392 | { |
| 1393 | int data; |
| 1394 | unsigned long flags; |
| 1395 | spin_lock_irqsave(&chip->ctrl_lock, flags); |
| 1396 | outb(reg, chip->ctrl_port); |
| 1397 | data = inb(chip->ctrl_port + 1); |
| 1398 | spin_unlock_irqrestore(&chip->ctrl_lock, flags); |
| 1399 | return data; |
| 1400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1402 | static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | unsigned char reg, unsigned char data) |
| 1404 | { |
| 1405 | /* No need for spinlocks, this function is used only in |
| 1406 | otherwise protected init code */ |
| 1407 | outb(reg, chip->ctrl_port); |
| 1408 | outb(data, chip->ctrl_port + 1); |
| 1409 | #ifdef REG_DEBUG |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1410 | 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] | 1411 | #endif |
| 1412 | } |
| 1413 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1414 | static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | { |
| 1416 | int mask = 0; |
| 1417 | |
| 1418 | /* enable extended mode */ |
| 1419 | snd_es18xx_dsp_command(chip, 0xC6); |
| 1420 | /* Reset mixer registers */ |
| 1421 | snd_es18xx_mixer_write(chip, 0x00, 0x00); |
| 1422 | |
| 1423 | /* Audio 1 DMA demand mode (4 bytes/request) */ |
| 1424 | snd_es18xx_write(chip, 0xB9, 2); |
| 1425 | if (chip->caps & ES18XX_CONTROL) { |
| 1426 | /* Hardware volume IRQ */ |
| 1427 | snd_es18xx_config_write(chip, 0x27, chip->irq); |
| 1428 | if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) { |
| 1429 | /* FM I/O */ |
| 1430 | snd_es18xx_config_write(chip, 0x62, chip->fm_port >> 8); |
| 1431 | snd_es18xx_config_write(chip, 0x63, chip->fm_port & 0xff); |
| 1432 | } |
| 1433 | if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { |
| 1434 | /* MPU-401 I/O */ |
| 1435 | snd_es18xx_config_write(chip, 0x64, chip->mpu_port >> 8); |
| 1436 | snd_es18xx_config_write(chip, 0x65, chip->mpu_port & 0xff); |
| 1437 | /* MPU-401 IRQ */ |
| 1438 | snd_es18xx_config_write(chip, 0x28, chip->irq); |
| 1439 | } |
| 1440 | /* Audio1 IRQ */ |
| 1441 | snd_es18xx_config_write(chip, 0x70, chip->irq); |
| 1442 | /* Audio2 IRQ */ |
| 1443 | snd_es18xx_config_write(chip, 0x72, chip->irq); |
| 1444 | /* Audio1 DMA */ |
| 1445 | snd_es18xx_config_write(chip, 0x74, chip->dma1); |
| 1446 | /* Audio2 DMA */ |
| 1447 | snd_es18xx_config_write(chip, 0x75, chip->dma2); |
| 1448 | |
| 1449 | /* Enable Audio 1 IRQ */ |
| 1450 | snd_es18xx_write(chip, 0xB1, 0x50); |
| 1451 | /* Enable Audio 2 IRQ */ |
| 1452 | snd_es18xx_mixer_write(chip, 0x7A, 0x40); |
| 1453 | /* Enable Audio 1 DMA */ |
| 1454 | snd_es18xx_write(chip, 0xB2, 0x50); |
| 1455 | /* Enable MPU and hardware volume interrupt */ |
| 1456 | snd_es18xx_mixer_write(chip, 0x64, 0x42); |
| 1457 | } |
| 1458 | else { |
| 1459 | int irqmask, dma1mask, dma2mask; |
| 1460 | switch (chip->irq) { |
| 1461 | case 2: |
| 1462 | case 9: |
| 1463 | irqmask = 0; |
| 1464 | break; |
| 1465 | case 5: |
| 1466 | irqmask = 1; |
| 1467 | break; |
| 1468 | case 7: |
| 1469 | irqmask = 2; |
| 1470 | break; |
| 1471 | case 10: |
| 1472 | irqmask = 3; |
| 1473 | break; |
| 1474 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1475 | snd_printk(KERN_ERR "invalid irq %d\n", chip->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | return -ENODEV; |
| 1477 | } |
| 1478 | switch (chip->dma1) { |
| 1479 | case 0: |
| 1480 | dma1mask = 1; |
| 1481 | break; |
| 1482 | case 1: |
| 1483 | dma1mask = 2; |
| 1484 | break; |
| 1485 | case 3: |
| 1486 | dma1mask = 3; |
| 1487 | break; |
| 1488 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1489 | snd_printk(KERN_ERR "invalid dma1 %d\n", chip->dma1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | return -ENODEV; |
| 1491 | } |
| 1492 | switch (chip->dma2) { |
| 1493 | case 0: |
| 1494 | dma2mask = 0; |
| 1495 | break; |
| 1496 | case 1: |
| 1497 | dma2mask = 1; |
| 1498 | break; |
| 1499 | case 3: |
| 1500 | dma2mask = 2; |
| 1501 | break; |
| 1502 | case 5: |
| 1503 | dma2mask = 3; |
| 1504 | break; |
| 1505 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1506 | snd_printk(KERN_ERR "invalid dma2 %d\n", chip->dma2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | return -ENODEV; |
| 1508 | } |
| 1509 | |
| 1510 | /* Enable and set Audio 1 IRQ */ |
| 1511 | snd_es18xx_write(chip, 0xB1, 0x50 | (irqmask << 2)); |
| 1512 | /* Enable and set Audio 1 DMA */ |
| 1513 | snd_es18xx_write(chip, 0xB2, 0x50 | (dma1mask << 2)); |
| 1514 | /* Set Audio 2 DMA */ |
| 1515 | snd_es18xx_mixer_bits(chip, 0x7d, 0x07, 0x04 | dma2mask); |
| 1516 | /* Enable Audio 2 IRQ and DMA |
| 1517 | Set capture mixer input */ |
| 1518 | snd_es18xx_mixer_write(chip, 0x7A, 0x68); |
| 1519 | /* Enable and set hardware volume interrupt */ |
| 1520 | snd_es18xx_mixer_write(chip, 0x64, 0x06); |
| 1521 | if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { |
| 1522 | /* MPU401 share irq with audio |
| 1523 | Joystick enabled |
| 1524 | FM enabled */ |
| 1525 | snd_es18xx_mixer_write(chip, 0x40, 0x43 | (chip->mpu_port & 0xf0) >> 1); |
| 1526 | } |
| 1527 | snd_es18xx_mixer_write(chip, 0x7f, ((irqmask + 1) << 1) | 0x01); |
| 1528 | } |
| 1529 | if (chip->caps & ES18XX_NEW_RATE) { |
| 1530 | /* Change behaviour of register A1 |
| 1531 | 4x oversampling |
| 1532 | 2nd channel DAC asynchronous */ |
| 1533 | snd_es18xx_mixer_write(chip, 0x71, 0x32); |
| 1534 | } |
| 1535 | if (!(chip->caps & ES18XX_PCM2)) { |
| 1536 | /* Enable DMA FIFO */ |
| 1537 | snd_es18xx_write(chip, 0xB7, 0x80); |
| 1538 | } |
| 1539 | if (chip->caps & ES18XX_SPATIALIZER) { |
| 1540 | /* Set spatializer parameters to recommended values */ |
| 1541 | snd_es18xx_mixer_write(chip, 0x54, 0x8f); |
| 1542 | snd_es18xx_mixer_write(chip, 0x56, 0x95); |
| 1543 | snd_es18xx_mixer_write(chip, 0x58, 0x94); |
| 1544 | snd_es18xx_mixer_write(chip, 0x5a, 0x80); |
| 1545 | } |
Mark Salazar | 95b7129 | 2006-01-16 11:35:40 +0100 | [diff] [blame] | 1546 | /* Flip the "enable I2S" bits for those chipsets that need it */ |
| 1547 | switch (chip->version) { |
| 1548 | case 0x1879: |
| 1549 | //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow) |
| 1550 | //so a Switch control has been added to toggle this 0x71 bit on/off: |
| 1551 | //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40); |
| 1552 | /* Note: we fall through on purpose here. */ |
| 1553 | case 0x1878: |
| 1554 | snd_es18xx_config_write(chip, 0x29, snd_es18xx_config_read(chip, 0x29) | 0x40); |
| 1555 | break; |
| 1556 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | /* Mute input source */ |
| 1558 | if (chip->caps & ES18XX_MUTEREC) |
| 1559 | mask = 0x10; |
| 1560 | if (chip->caps & ES18XX_RECMIX) |
| 1561 | snd_es18xx_mixer_write(chip, 0x1c, 0x05 | mask); |
| 1562 | else { |
| 1563 | snd_es18xx_mixer_write(chip, 0x1c, 0x00 | mask); |
| 1564 | snd_es18xx_write(chip, 0xb4, 0x00); |
| 1565 | } |
| 1566 | #ifndef AVOID_POPS |
| 1567 | /* Enable PCM output */ |
| 1568 | snd_es18xx_dsp_command(chip, 0xD1); |
| 1569 | #endif |
| 1570 | |
| 1571 | return 0; |
| 1572 | } |
| 1573 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1574 | static int __devinit snd_es18xx_identify(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | { |
| 1576 | int hi,lo; |
| 1577 | |
| 1578 | /* reset */ |
| 1579 | if (snd_es18xx_reset(chip) < 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1580 | snd_printk(KERN_ERR "reset at 0x%lx failed!!!\n", chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | return -ENODEV; |
| 1582 | } |
| 1583 | |
| 1584 | snd_es18xx_dsp_command(chip, 0xe7); |
| 1585 | hi = snd_es18xx_dsp_get_byte(chip); |
| 1586 | if (hi < 0) { |
| 1587 | return hi; |
| 1588 | } |
| 1589 | lo = snd_es18xx_dsp_get_byte(chip); |
| 1590 | if ((lo & 0xf0) != 0x80) { |
| 1591 | return -ENODEV; |
| 1592 | } |
| 1593 | if (hi == 0x48) { |
| 1594 | chip->version = 0x488; |
| 1595 | return 0; |
| 1596 | } |
| 1597 | if (hi != 0x68) { |
| 1598 | return -ENODEV; |
| 1599 | } |
| 1600 | if ((lo & 0x0f) < 8) { |
| 1601 | chip->version = 0x688; |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | outb(0x40, chip->port + 0x04); |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1606 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | hi = inb(chip->port + 0x05); |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1608 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | lo = inb(chip->port + 0x05); |
| 1610 | if (hi != lo) { |
| 1611 | chip->version = hi << 8 | lo; |
| 1612 | chip->ctrl_port = inb(chip->port + 0x05) << 8; |
Mark Salazar | c1f6d41 | 2006-01-16 11:29:09 +0100 | [diff] [blame] | 1613 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | chip->ctrl_port += inb(chip->port + 0x05); |
| 1615 | |
| 1616 | if ((chip->res_ctrl_port = request_region(chip->ctrl_port, 8, "ES18xx - CTRL")) == NULL) { |
| 1617 | snd_printk(KERN_ERR PFX "unable go grab port 0x%lx\n", chip->ctrl_port); |
| 1618 | return -EBUSY; |
| 1619 | } |
| 1620 | |
| 1621 | return 0; |
| 1622 | } |
| 1623 | |
| 1624 | /* If has Hardware volume */ |
| 1625 | if (snd_es18xx_mixer_writable(chip, 0x64, 0x04)) { |
| 1626 | /* If has Audio2 */ |
| 1627 | if (snd_es18xx_mixer_writable(chip, 0x70, 0x7f)) { |
| 1628 | /* If has volume count */ |
| 1629 | if (snd_es18xx_mixer_writable(chip, 0x64, 0x20)) { |
| 1630 | chip->version = 0x1887; |
| 1631 | } else { |
| 1632 | chip->version = 0x1888; |
| 1633 | } |
| 1634 | } else { |
| 1635 | chip->version = 0x1788; |
| 1636 | } |
| 1637 | } |
| 1638 | else |
| 1639 | chip->version = 0x1688; |
| 1640 | return 0; |
| 1641 | } |
| 1642 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1643 | static int __devinit snd_es18xx_probe(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | { |
| 1645 | if (snd_es18xx_identify(chip) < 0) { |
| 1646 | snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port); |
| 1647 | return -ENODEV; |
| 1648 | } |
| 1649 | |
| 1650 | switch (chip->version) { |
| 1651 | case 0x1868: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1652 | chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | break; |
| 1654 | case 0x1869: |
| 1655 | chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV; |
| 1656 | break; |
| 1657 | case 0x1878: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1658 | chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | break; |
| 1660 | case 0x1879: |
| 1661 | chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV; |
| 1662 | break; |
| 1663 | case 0x1887: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1664 | chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | break; |
| 1666 | case 0x1888: |
Mark Salazar | 1408677 | 2006-01-16 11:33:52 +0100 | [diff] [blame] | 1667 | chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | break; |
| 1669 | default: |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1670 | snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | chip->port, chip->version); |
| 1672 | return -ENODEV; |
| 1673 | } |
| 1674 | |
| 1675 | snd_printd("[0x%lx] ESS%x chip found\n", chip->port, chip->version); |
| 1676 | |
| 1677 | if (chip->dma1 == chip->dma2) |
| 1678 | chip->caps &= ~(ES18XX_PCM2 | ES18XX_DUPLEX_SAME); |
| 1679 | |
| 1680 | return snd_es18xx_initialize(chip); |
| 1681 | } |
| 1682 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1683 | static struct snd_pcm_ops snd_es18xx_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | .open = snd_es18xx_playback_open, |
| 1685 | .close = snd_es18xx_playback_close, |
| 1686 | .ioctl = snd_pcm_lib_ioctl, |
| 1687 | .hw_params = snd_es18xx_playback_hw_params, |
| 1688 | .hw_free = snd_es18xx_pcm_hw_free, |
| 1689 | .prepare = snd_es18xx_playback_prepare, |
| 1690 | .trigger = snd_es18xx_playback_trigger, |
| 1691 | .pointer = snd_es18xx_playback_pointer, |
| 1692 | }; |
| 1693 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1694 | static struct snd_pcm_ops snd_es18xx_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | .open = snd_es18xx_capture_open, |
| 1696 | .close = snd_es18xx_capture_close, |
| 1697 | .ioctl = snd_pcm_lib_ioctl, |
| 1698 | .hw_params = snd_es18xx_capture_hw_params, |
| 1699 | .hw_free = snd_es18xx_pcm_hw_free, |
| 1700 | .prepare = snd_es18xx_capture_prepare, |
| 1701 | .trigger = snd_es18xx_capture_trigger, |
| 1702 | .pointer = snd_es18xx_capture_pointer, |
| 1703 | }; |
| 1704 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1705 | static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct snd_pcm ** rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1707 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | char str[16]; |
| 1709 | int err; |
| 1710 | |
| 1711 | if (rpcm) |
| 1712 | *rpcm = NULL; |
| 1713 | sprintf(str, "ES%x", chip->version); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1714 | if (chip->caps & ES18XX_PCM2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1716 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | if (err < 0) |
| 1719 | return err; |
| 1720 | |
| 1721 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es18xx_playback_ops); |
| 1722 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es18xx_capture_ops); |
| 1723 | |
| 1724 | /* global setup */ |
| 1725 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | pcm->info_flags = 0; |
| 1727 | if (chip->caps & ES18XX_DUPLEX_SAME) |
| 1728 | pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1729 | if (! (chip->caps & ES18XX_PCM2)) |
| 1730 | pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX; |
| 1731 | sprintf(pcm->name, "ESS AudioDrive ES%x", chip->version); |
| 1732 | chip->pcm = pcm; |
| 1733 | |
| 1734 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1735 | snd_dma_isa_data(), |
| 1736 | 64*1024, |
| 1737 | chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024); |
| 1738 | |
| 1739 | if (rpcm) |
| 1740 | *rpcm = pcm; |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | /* Power Management support functions */ |
| 1745 | #ifdef CONFIG_PM |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1746 | 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] | 1747 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1748 | struct snd_audiodrive *acard = card->private_data; |
| 1749 | struct snd_es18xx *chip = acard->chip; |
| 1750 | |
| 1751 | snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | |
| 1753 | snd_pcm_suspend_all(chip->pcm); |
| 1754 | |
| 1755 | /* power down */ |
| 1756 | chip->pm_reg = (unsigned char)snd_es18xx_read(chip, ES18XX_PM); |
| 1757 | chip->pm_reg |= (ES18XX_PM_FM | ES18XX_PM_SUS); |
| 1758 | snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg); |
| 1759 | snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_SUS); |
| 1760 | |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1764 | static int snd_es18xx_resume(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1766 | struct snd_audiodrive *acard = card->private_data; |
| 1767 | struct snd_es18xx *chip = acard->chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | |
| 1769 | /* restore PM register, we won't wake till (not 0x07) i/o activity though */ |
| 1770 | snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM); |
| 1771 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 1772 | snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | return 0; |
| 1774 | } |
| 1775 | #endif /* CONFIG_PM */ |
| 1776 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1777 | static int snd_es18xx_free(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
| 1783 | free_irq(chip->irq, (void *) chip); |
| 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 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1798 | struct snd_es18xx *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | return snd_es18xx_free(chip); |
| 1800 | } |
| 1801 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1802 | static int __devinit snd_es18xx_new_device(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | unsigned long port, |
| 1804 | unsigned long mpu_port, |
| 1805 | unsigned long fm_port, |
| 1806 | int irq, int dma1, int dma2, |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1807 | struct snd_es18xx ** rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1809 | struct snd_es18xx *chip; |
| 1810 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | .dev_free = snd_es18xx_dev_free, |
| 1812 | }; |
| 1813 | int err; |
| 1814 | |
| 1815 | *rchip = NULL; |
Takashi Iwai | 9e76a76 | 2005-09-09 14:21:17 +0200 | [diff] [blame] | 1816 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | if (chip == NULL) |
| 1818 | return -ENOMEM; |
| 1819 | spin_lock_init(&chip->reg_lock); |
| 1820 | spin_lock_init(&chip->mixer_lock); |
| 1821 | spin_lock_init(&chip->ctrl_lock); |
| 1822 | chip->card = card; |
| 1823 | chip->port = port; |
| 1824 | chip->mpu_port = mpu_port; |
| 1825 | chip->fm_port = fm_port; |
| 1826 | chip->irq = -1; |
| 1827 | chip->dma1 = -1; |
| 1828 | chip->dma2 = -1; |
| 1829 | chip->audio2_vol = 0x00; |
| 1830 | chip->active = 0; |
| 1831 | |
| 1832 | if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) { |
| 1833 | snd_es18xx_free(chip); |
| 1834 | snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1); |
| 1835 | return -EBUSY; |
| 1836 | } |
| 1837 | |
| 1838 | if (request_irq(irq, snd_es18xx_interrupt, SA_INTERRUPT, "ES18xx", (void *) chip)) { |
| 1839 | snd_es18xx_free(chip); |
| 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")) { |
| 1846 | snd_es18xx_free(chip); |
| 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")) { |
| 1853 | snd_es18xx_free(chip); |
| 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) { |
| 1860 | snd_es18xx_free(chip); |
| 1861 | return -ENODEV; |
| 1862 | } |
| 1863 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { |
| 1864 | snd_es18xx_free(chip); |
| 1865 | return err; |
| 1866 | } |
| 1867 | *rchip = chip; |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1871 | static int __devinit snd_es18xx_mixer(struct snd_es18xx *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 1873 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | int err; |
| 1875 | unsigned int idx; |
| 1876 | |
| 1877 | card = chip->card; |
| 1878 | |
| 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 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2036 | static struct platform_device *platform_devices[SNDRV_CARDS]; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2037 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | #ifdef CONFIG_PNP |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 2039 | static int pnp_registered; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | |
| 2041 | static struct pnp_card_device_id snd_audiodrive_pnpids[] = { |
| 2042 | /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */ |
| 2043 | { .id = "ESS1868", .devs = { { "ESS1868" }, { "ESS0000" } } }, |
| 2044 | /* ESS 1868 (integrated on Maxisound Cards) */ |
| 2045 | { .id = "ESS1868", .devs = { { "ESS8601" }, { "ESS8600" } } }, |
| 2046 | /* ESS 1868 (integrated on Maxisound Cards) */ |
| 2047 | { .id = "ESS1868", .devs = { { "ESS8611" }, { "ESS8610" } } }, |
| 2048 | /* ESS ES1869 Plug and Play AudioDrive */ |
| 2049 | { .id = "ESS0003", .devs = { { "ESS1869" }, { "ESS0006" } } }, |
| 2050 | /* ESS 1869 */ |
| 2051 | { .id = "ESS1869", .devs = { { "ESS1869" }, { "ESS0006" } } }, |
| 2052 | /* ESS 1878 */ |
| 2053 | { .id = "ESS1878", .devs = { { "ESS1878" }, { "ESS0004" } } }, |
| 2054 | /* ESS 1879 */ |
| 2055 | { .id = "ESS1879", .devs = { { "ESS1879" }, { "ESS0009" } } }, |
| 2056 | /* --- */ |
| 2057 | { .id = "" } /* end */ |
| 2058 | }; |
| 2059 | |
| 2060 | MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids); |
| 2061 | |
| 2062 | static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard, |
| 2063 | struct pnp_card_link *card, |
| 2064 | const struct pnp_card_device_id *id) |
| 2065 | { |
| 2066 | struct pnp_dev *pdev; |
| 2067 | struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); |
| 2068 | int err; |
| 2069 | |
| 2070 | if (!cfg) |
| 2071 | return -ENOMEM; |
| 2072 | acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); |
| 2073 | if (acard->dev == NULL) { |
| 2074 | kfree(cfg); |
| 2075 | return -EBUSY; |
| 2076 | } |
| 2077 | acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL); |
| 2078 | if (acard->devc == NULL) { |
| 2079 | kfree(cfg); |
| 2080 | return -EBUSY; |
| 2081 | } |
| 2082 | /* Control port initialization */ |
| 2083 | err = pnp_activate_dev(acard->devc); |
| 2084 | if (err < 0) { |
| 2085 | snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n"); |
Adrian Bunk | 202728d | 2006-03-14 09:44:19 +0100 | [diff] [blame] | 2086 | kfree(cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | return -EAGAIN; |
| 2088 | } |
| 2089 | snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard->devc, 0)); |
| 2090 | /* PnP initialization */ |
| 2091 | pdev = acard->dev; |
| 2092 | pnp_init_resource_table(cfg); |
| 2093 | if (port[dev] != SNDRV_AUTO_PORT) |
| 2094 | pnp_resource_change(&cfg->port_resource[0], port[dev], 16); |
| 2095 | if (fm_port[dev] != SNDRV_AUTO_PORT) |
| 2096 | pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4); |
| 2097 | if (mpu_port[dev] != SNDRV_AUTO_PORT) |
| 2098 | pnp_resource_change(&cfg->port_resource[2], mpu_port[dev], 2); |
| 2099 | if (dma1[dev] != SNDRV_AUTO_DMA) |
| 2100 | pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1); |
| 2101 | if (dma2[dev] != SNDRV_AUTO_DMA) |
| 2102 | pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1); |
| 2103 | if (irq[dev] != SNDRV_AUTO_IRQ) |
| 2104 | pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1); |
| 2105 | err = pnp_manual_config_dev(pdev, cfg, 0); |
| 2106 | if (err < 0) |
| 2107 | snd_printk(KERN_ERR PFX "PnP manual resources are invalid, using auto config\n"); |
| 2108 | err = pnp_activate_dev(pdev); |
| 2109 | if (err < 0) { |
| 2110 | snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n"); |
| 2111 | kfree(cfg); |
| 2112 | return -EBUSY; |
| 2113 | } |
| 2114 | /* ok. hack using Vendor-Defined Card-Level registers */ |
| 2115 | /* skip csn and logdev initialization - already done in isapnp_configure */ |
| 2116 | if (pnp_device_is_isapnp(pdev)) { |
| 2117 | isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev)); |
| 2118 | isapnp_write_byte(0x27, pnp_irq(pdev, 0)); /* Hardware Volume IRQ Number */ |
| 2119 | if (mpu_port[dev] != SNDRV_AUTO_PORT) |
| 2120 | isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */ |
| 2121 | isapnp_write_byte(0x72, pnp_irq(pdev, 0)); /* second IRQ */ |
| 2122 | isapnp_cfg_end(); |
| 2123 | } else { |
| 2124 | snd_printk(KERN_ERR PFX "unable to install ISA PnP hack, expect malfunction\n"); |
| 2125 | } |
| 2126 | port[dev] = pnp_port_start(pdev, 0); |
| 2127 | fm_port[dev] = pnp_port_start(pdev, 1); |
| 2128 | mpu_port[dev] = pnp_port_start(pdev, 2); |
| 2129 | dma1[dev] = pnp_dma(pdev, 0); |
| 2130 | dma2[dev] = pnp_dma(pdev, 1); |
| 2131 | irq[dev] = pnp_irq(pdev, 0); |
| 2132 | snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]); |
| 2133 | snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]); |
| 2134 | kfree(cfg); |
| 2135 | return 0; |
| 2136 | } |
| 2137 | #endif /* CONFIG_PNP */ |
| 2138 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2139 | #ifdef CONFIG_PNP |
| 2140 | #define is_isapnp_selected(dev) isapnp[dev] |
| 2141 | #else |
| 2142 | #define is_isapnp_selected(dev) 0 |
| 2143 | #endif |
| 2144 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2145 | static struct snd_card *snd_es18xx_card_new(int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2147 | return snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 2148 | sizeof(struct snd_audiodrive)); |
| 2149 | } |
| 2150 | |
| 2151 | static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev) |
| 2152 | { |
| 2153 | struct snd_audiodrive *acard = card->private_data; |
Takashi Iwai | 8047c91 | 2005-11-17 14:41:22 +0100 | [diff] [blame] | 2154 | struct snd_es18xx *chip; |
| 2155 | struct snd_opl3 *opl3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | int err; |
| 2157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | if ((err = snd_es18xx_new_device(card, |
| 2159 | port[dev], |
| 2160 | mpu_port[dev], |
| 2161 | fm_port[dev], |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2162 | irq[dev], dma1[dev], dma2[dev], |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2163 | &chip)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2164 | return err; |
| 2165 | acard->chip = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | |
| 2167 | sprintf(card->driver, "ES%x", chip->version); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version); |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2170 | if (dma1[dev] != dma2[dev]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d", |
| 2172 | card->shortname, |
| 2173 | chip->port, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2174 | irq[dev], dma1[dev], dma2[dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | else |
| 2176 | sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", |
| 2177 | card->shortname, |
| 2178 | chip->port, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2179 | irq[dev], dma1[dev]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2181 | if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2182 | return err; |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2183 | |
| 2184 | if ((err = snd_es18xx_mixer(chip)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2185 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | |
| 2187 | if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { |
| 2188 | 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] | 2189 | 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] | 2190 | } else { |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2191 | if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2192 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { |
| 2197 | if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, |
| 2198 | chip->mpu_port, 0, |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2199 | irq[dev], 0, |
Takashi Iwai | 43bcd97 | 2005-09-05 17:19:20 +0200 | [diff] [blame] | 2200 | &chip->rmidi)) < 0) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2201 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2204 | return snd_card_register(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Bjorn Helgaas | fea9739 | 2006-03-27 01:17:13 -0800 | [diff] [blame] | 2207 | static int __devinit snd_es18xx_nonpnp_probe1(int dev, struct platform_device *devptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2209 | struct snd_card *card; |
| 2210 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2212 | card = snd_es18xx_card_new(dev); |
| 2213 | if (! card) |
| 2214 | return -ENOMEM; |
| 2215 | snd_card_set_dev(card, &devptr->dev); |
| 2216 | if ((err = snd_audiodrive_probe(card, dev)) < 0) { |
| 2217 | snd_card_free(card); |
| 2218 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | } |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2220 | platform_set_drvdata(devptr, card); |
| 2221 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Bjorn Helgaas | fea9739 | 2006-03-27 01:17:13 -0800 | [diff] [blame] | 2224 | static int __devinit snd_es18xx_nonpnp_probe(struct platform_device *pdev) |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2225 | { |
| 2226 | int dev = pdev->id; |
| 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) { |
| 2251 | return snd_es18xx_nonpnp_probe1(dev, pdev); |
| 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]; |
| 2257 | err = snd_es18xx_nonpnp_probe1(dev, pdev); |
| 2258 | if (! err) |
| 2259 | return 0; |
| 2260 | } |
| 2261 | return err; |
| 2262 | } |
| 2263 | } |
| 2264 | |
| 2265 | static int __devexit snd_es18xx_nonpnp_remove(struct platform_device *devptr) |
| 2266 | { |
| 2267 | snd_card_free(platform_get_drvdata(devptr)); |
| 2268 | platform_set_drvdata(devptr, NULL); |
| 2269 | return 0; |
| 2270 | } |
| 2271 | |
| 2272 | #ifdef CONFIG_PM |
| 2273 | static int snd_es18xx_nonpnp_suspend(struct platform_device *dev, pm_message_t state) |
| 2274 | { |
| 2275 | return snd_es18xx_suspend(platform_get_drvdata(dev), state); |
| 2276 | } |
| 2277 | |
| 2278 | static int snd_es18xx_nonpnp_resume(struct platform_device *dev) |
| 2279 | { |
| 2280 | return snd_es18xx_resume(platform_get_drvdata(dev)); |
| 2281 | } |
| 2282 | #endif |
| 2283 | |
| 2284 | #define ES18XX_DRIVER "snd_es18xx" |
| 2285 | |
| 2286 | static struct platform_driver snd_es18xx_nonpnp_driver = { |
| 2287 | .probe = snd_es18xx_nonpnp_probe, |
| 2288 | .remove = __devexit_p(snd_es18xx_nonpnp_remove), |
| 2289 | #ifdef CONFIG_PM |
| 2290 | .suspend = snd_es18xx_nonpnp_suspend, |
| 2291 | .resume = snd_es18xx_nonpnp_resume, |
| 2292 | #endif |
| 2293 | .driver = { |
| 2294 | .name = ES18XX_DRIVER |
| 2295 | }, |
| 2296 | }; |
| 2297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | |
| 2299 | #ifdef CONFIG_PNP |
Bjorn Helgaas | fea9739 | 2006-03-27 01:17:13 -0800 | [diff] [blame] | 2300 | static unsigned int __devinitdata es18xx_pnp_devices; |
| 2301 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2302 | static int __devinit snd_audiodrive_pnp_detect(struct pnp_card_link *pcard, |
| 2303 | const struct pnp_card_device_id *pid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | { |
| 2305 | static int dev; |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2306 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | int res; |
| 2308 | |
| 2309 | for ( ; dev < SNDRV_CARDS; dev++) { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2310 | if (enable[dev] && isapnp[dev]) |
| 2311 | break; |
| 2312 | } |
| 2313 | if (dev >= SNDRV_CARDS) |
| 2314 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2316 | card = snd_es18xx_card_new(dev); |
| 2317 | if (! card) |
| 2318 | return -ENOMEM; |
| 2319 | |
| 2320 | if ((res = snd_audiodrive_pnp(dev, card->private_data, pcard, pid)) < 0) { |
| 2321 | snd_card_free(card); |
| 2322 | return res; |
| 2323 | } |
| 2324 | snd_card_set_dev(card, &pcard->card->dev); |
| 2325 | if ((res = snd_audiodrive_probe(card, dev)) < 0) { |
| 2326 | snd_card_free(card); |
| 2327 | return res; |
| 2328 | } |
| 2329 | |
| 2330 | pnp_set_card_drvdata(pcard, card); |
| 2331 | dev++; |
Bjorn Helgaas | fea9739 | 2006-03-27 01:17:13 -0800 | [diff] [blame] | 2332 | es18xx_pnp_devices++; |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2333 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | static void __devexit snd_audiodrive_pnp_remove(struct pnp_card_link * pcard) |
| 2337 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2338 | snd_card_free(pnp_get_card_drvdata(pcard)); |
| 2339 | pnp_set_card_drvdata(pcard, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | } |
| 2341 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2342 | #ifdef CONFIG_PM |
| 2343 | static int snd_audiodrive_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state) |
| 2344 | { |
| 2345 | return snd_es18xx_suspend(pnp_get_card_drvdata(pcard), state); |
| 2346 | } |
| 2347 | |
| 2348 | static int snd_audiodrive_pnp_resume(struct pnp_card_link *pcard) |
| 2349 | { |
| 2350 | return snd_es18xx_resume(pnp_get_card_drvdata(pcard)); |
| 2351 | } |
| 2352 | |
| 2353 | #endif |
| 2354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | static struct pnp_card_driver es18xx_pnpc_driver = { |
| 2356 | .flags = PNP_DRIVER_RES_DISABLE, |
| 2357 | .name = "es18xx", |
| 2358 | .id_table = snd_audiodrive_pnpids, |
| 2359 | .probe = snd_audiodrive_pnp_detect, |
| 2360 | .remove = __devexit_p(snd_audiodrive_pnp_remove), |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2361 | #ifdef CONFIG_PM |
| 2362 | .suspend = snd_audiodrive_pnp_suspend, |
| 2363 | .resume = snd_audiodrive_pnp_resume, |
| 2364 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | }; |
| 2366 | #endif /* CONFIG_PNP */ |
| 2367 | |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2368 | static void __init_or_module snd_es18xx_unregister_all(void) |
| 2369 | { |
| 2370 | int i; |
| 2371 | |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 2372 | #ifdef CONFIG_PNP |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2373 | if (pnp_registered) |
| 2374 | pnp_unregister_card_driver(&es18xx_pnpc_driver); |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 2375 | #endif |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2376 | for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) |
| 2377 | platform_device_unregister(platform_devices[i]); |
| 2378 | platform_driver_unregister(&snd_es18xx_nonpnp_driver); |
| 2379 | } |
| 2380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | static int __init alsa_card_es18xx_init(void) |
| 2382 | { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2383 | int i, err, cards = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2385 | if ((err = platform_driver_register(&snd_es18xx_nonpnp_driver)) < 0) |
| 2386 | return err; |
| 2387 | |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 2388 | for (i = 0; i < SNDRV_CARDS; i++) { |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2389 | struct platform_device *device; |
Takashi Iwai | 8278ca8 | 2006-02-20 11:57:34 +0100 | [diff] [blame] | 2390 | if (! enable[i] || is_isapnp_selected(i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | continue; |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2392 | device = platform_device_register_simple(ES18XX_DRIVER, |
| 2393 | i, NULL, 0); |
| 2394 | if (IS_ERR(device)) { |
| 2395 | err = PTR_ERR(device); |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2396 | goto errout; |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2397 | } |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2398 | platform_devices[i] = device; |
Takashi Iwai | f7e0ba3 | 2005-11-17 17:12:07 +0100 | [diff] [blame] | 2399 | cards++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 2402 | #ifdef CONFIG_PNP |
Bjorn Helgaas | fea9739 | 2006-03-27 01:17:13 -0800 | [diff] [blame] | 2403 | err = pnp_register_card_driver(&es18xx_pnpc_driver); |
| 2404 | if (!err) { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2405 | pnp_registered = 1; |
Bjorn Helgaas | fea9739 | 2006-03-27 01:17:13 -0800 | [diff] [blame] | 2406 | cards += es18xx_pnp_devices; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2407 | } |
Takashi Iwai | 59b1b34 | 2006-01-04 15:06:44 +0100 | [diff] [blame] | 2408 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | if(!cards) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | #ifdef MODULE |
| 2412 | snd_printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n"); |
| 2413 | #endif |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2414 | err = -ENODEV; |
| 2415 | goto errout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | } |
| 2417 | return 0; |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2418 | |
| 2419 | errout: |
| 2420 | snd_es18xx_unregister_all(); |
| 2421 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2422 | } |
| 2423 | |
| 2424 | static void __exit alsa_card_es18xx_exit(void) |
| 2425 | { |
Clemens Ladisch | f7a9275 | 2005-12-07 09:13:42 +0100 | [diff] [blame] | 2426 | snd_es18xx_unregister_all(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | module_init(alsa_card_es18xx_init) |
| 2430 | module_exit(alsa_card_es18xx_exit) |