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