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