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 | /* |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Routines for control of ESS ES1688/688/488 chip |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/init.h> |
| 8 | #include <linux/interrupt.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/slab.h> |
| 11 | #include <linux/ioport.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 12 | #include <linux/module.h> |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 13 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <sound/core.h> |
| 15 | #include <sound/es1688.h> |
| 16 | #include <sound/initval.h> |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/dma.h> |
| 19 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 20 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | MODULE_DESCRIPTION("ESS ESx688 lowlevel module"); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 24 | static int snd_es1688_dsp_command(struct snd_es1688 *chip, unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
| 26 | int i; |
| 27 | |
| 28 | for (i = 10000; i; i--) |
| 29 | if ((inb(ES1688P(chip, STATUS)) & 0x80) == 0) { |
| 30 | outb(val, ES1688P(chip, COMMAND)); |
| 31 | return 1; |
| 32 | } |
| 33 | #ifdef CONFIG_SND_DEBUG |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 34 | printk(KERN_DEBUG "snd_es1688_dsp_command: timeout (0x%x)\n", val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #endif |
| 36 | return 0; |
| 37 | } |
| 38 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 39 | static int snd_es1688_dsp_get_byte(struct snd_es1688 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
| 41 | int i; |
| 42 | |
| 43 | for (i = 1000; i; i--) |
| 44 | if (inb(ES1688P(chip, DATA_AVAIL)) & 0x80) |
| 45 | return inb(ES1688P(chip, READ)); |
| 46 | snd_printd("es1688 get byte failed: 0x%lx = 0x%x!!!\n", ES1688P(chip, DATA_AVAIL), inb(ES1688P(chip, DATA_AVAIL))); |
| 47 | return -ENODEV; |
| 48 | } |
| 49 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 50 | static int snd_es1688_write(struct snd_es1688 *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | unsigned char reg, unsigned char data) |
| 52 | { |
| 53 | if (!snd_es1688_dsp_command(chip, reg)) |
| 54 | return 0; |
| 55 | return snd_es1688_dsp_command(chip, data); |
| 56 | } |
| 57 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 58 | static int snd_es1688_read(struct snd_es1688 *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | /* Read a byte from an extended mode register of ES1688 */ |
| 61 | if (!snd_es1688_dsp_command(chip, 0xc0)) |
| 62 | return -1; |
| 63 | if (!snd_es1688_dsp_command(chip, reg)) |
| 64 | return -1; |
| 65 | return snd_es1688_dsp_get_byte(chip); |
| 66 | } |
| 67 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 68 | void snd_es1688_mixer_write(struct snd_es1688 *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | unsigned char reg, unsigned char data) |
| 70 | { |
| 71 | outb(reg, ES1688P(chip, MIXER_ADDR)); |
| 72 | udelay(10); |
| 73 | outb(data, ES1688P(chip, MIXER_DATA)); |
| 74 | udelay(10); |
| 75 | } |
| 76 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 77 | static unsigned char snd_es1688_mixer_read(struct snd_es1688 *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | unsigned char result; |
| 80 | |
| 81 | outb(reg, ES1688P(chip, MIXER_ADDR)); |
| 82 | udelay(10); |
| 83 | result = inb(ES1688P(chip, MIXER_DATA)); |
| 84 | udelay(10); |
| 85 | return result; |
| 86 | } |
| 87 | |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 88 | int snd_es1688_reset(struct snd_es1688 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | int i; |
| 91 | |
| 92 | outb(3, ES1688P(chip, RESET)); /* valid only for ESS chips, SB -> 1 */ |
| 93 | udelay(10); |
| 94 | outb(0, ES1688P(chip, RESET)); |
| 95 | udelay(30); |
| 96 | for (i = 0; i < 1000 && !(inb(ES1688P(chip, DATA_AVAIL)) & 0x80); i++); |
| 97 | if (inb(ES1688P(chip, READ)) != 0xaa) { |
| 98 | snd_printd("ess_reset at 0x%lx: failed!!!\n", chip->port); |
| 99 | return -ENODEV; |
| 100 | } |
| 101 | snd_es1688_dsp_command(chip, 0xc6); /* enable extended mode */ |
| 102 | return 0; |
| 103 | } |
Krzysztof Helt | a20971b | 2010-05-10 09:47:32 +0200 | [diff] [blame] | 104 | EXPORT_SYMBOL(snd_es1688_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 106 | static int snd_es1688_probe(struct snd_es1688 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { |
| 108 | unsigned long flags; |
YueHaibing | a06702c | 2019-02-14 02:10:33 +0000 | [diff] [blame] | 109 | unsigned short major, minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | int i; |
| 111 | |
| 112 | /* |
| 113 | * initialization sequence |
| 114 | */ |
| 115 | |
| 116 | spin_lock_irqsave(&chip->reg_lock, flags); /* Some ESS1688 cards need this */ |
| 117 | inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */ |
| 118 | inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */ |
| 119 | inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */ |
| 120 | inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */ |
| 121 | inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */ |
| 122 | inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */ |
| 123 | inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */ |
| 124 | inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */ |
| 125 | inb(ES1688P(chip, ENABLE2)); /* ENABLE2 */ |
| 126 | inb(ES1688P(chip, ENABLE1)); /* ENABLE1 */ |
| 127 | inb(ES1688P(chip, ENABLE0)); /* ENABLE0 */ |
| 128 | |
| 129 | if (snd_es1688_reset(chip) < 0) { |
| 130 | snd_printdd("ESS: [0x%lx] reset failed... 0x%x\n", chip->port, inb(ES1688P(chip, READ))); |
| 131 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 132 | return -ENODEV; |
| 133 | } |
| 134 | snd_es1688_dsp_command(chip, 0xe7); /* return identification */ |
| 135 | |
| 136 | for (i = 1000, major = minor = 0; i; i--) { |
| 137 | if (inb(ES1688P(chip, DATA_AVAIL)) & 0x80) { |
| 138 | if (major == 0) { |
| 139 | major = inb(ES1688P(chip, READ)); |
| 140 | } else { |
| 141 | minor = inb(ES1688P(chip, READ)); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 147 | |
| 148 | snd_printdd("ESS: [0x%lx] found.. major = 0x%x, minor = 0x%x\n", chip->port, major, minor); |
| 149 | |
| 150 | chip->version = (major << 8) | minor; |
| 151 | if (!chip->version) |
| 152 | return -ENODEV; /* probably SB */ |
| 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | switch (chip->version & 0xfff0) { |
| 155 | case 0x4880: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 156 | snd_printk(KERN_ERR "[0x%lx] ESS: AudioDrive ES488 detected, " |
| 157 | "but driver is in another place\n", chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | return -ENODEV; |
| 159 | case 0x6880: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | break; |
| 161 | default: |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 162 | snd_printk(KERN_ERR "[0x%lx] ESS: unknown AudioDrive chip " |
| 163 | "with version 0x%x (Jazz16 soundcard?)\n", |
| 164 | chip->port, chip->version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | return -ENODEV; |
| 166 | } |
| 167 | |
| 168 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 169 | snd_es1688_write(chip, 0xb1, 0x10); /* disable IRQ */ |
| 170 | snd_es1688_write(chip, 0xb2, 0x00); /* disable DMA */ |
| 171 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 172 | |
| 173 | /* enable joystick, but disable OPL3 */ |
| 174 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 175 | snd_es1688_mixer_write(chip, 0x40, 0x01); |
| 176 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 181 | static int snd_es1688_init(struct snd_es1688 * chip, int enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | { |
Takashi Iwai | 748f518 | 2020-01-05 15:48:02 +0100 | [diff] [blame] | 183 | static const int irqs[16] = {-1, -1, 0, -1, -1, 1, -1, 2, -1, 0, 3, -1, -1, -1, -1, -1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | unsigned long flags; |
| 185 | int cfg, irq_bits, dma, dma_bits, tmp, tmp1; |
| 186 | |
| 187 | /* ok.. setup MPU-401 port and joystick and OPL3 */ |
| 188 | cfg = 0x01; /* enable joystick, but disable OPL3 */ |
| 189 | if (enable && chip->mpu_port >= 0x300 && chip->mpu_irq > 0 && chip->hardware != ES1688_HW_688) { |
| 190 | tmp = (chip->mpu_port & 0x0f0) >> 4; |
| 191 | if (tmp <= 3) { |
| 192 | switch (chip->mpu_irq) { |
| 193 | case 9: |
| 194 | tmp1 = 4; |
| 195 | break; |
| 196 | case 5: |
| 197 | tmp1 = 5; |
| 198 | break; |
| 199 | case 7: |
| 200 | tmp1 = 6; |
| 201 | break; |
| 202 | case 10: |
| 203 | tmp1 = 7; |
| 204 | break; |
| 205 | default: |
| 206 | tmp1 = 0; |
| 207 | } |
| 208 | if (tmp1) { |
| 209 | cfg |= (tmp << 3) | (tmp1 << 5); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | #if 0 |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 214 | snd_printk(KERN_DEBUG "mpu cfg = 0x%x\n", cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | #endif |
| 216 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 217 | snd_es1688_mixer_write(chip, 0x40, cfg); |
| 218 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 219 | /* --- */ |
| 220 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 221 | snd_es1688_read(chip, 0xb1); |
| 222 | snd_es1688_read(chip, 0xb2); |
| 223 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 224 | if (enable) { |
| 225 | cfg = 0xf0; /* enable only DMA counter interrupt */ |
| 226 | irq_bits = irqs[chip->irq & 0x0f]; |
| 227 | if (irq_bits < 0) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 228 | snd_printk(KERN_ERR "[0x%lx] ESS: bad IRQ %d " |
| 229 | "for ES1688 chip!!\n", |
| 230 | chip->port, chip->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #if 0 |
| 232 | irq_bits = 0; |
| 233 | cfg = 0x10; |
| 234 | #endif |
| 235 | return -EINVAL; |
| 236 | } |
| 237 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 238 | snd_es1688_write(chip, 0xb1, cfg | (irq_bits << 2)); |
| 239 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 240 | cfg = 0xf0; /* extended mode DMA enable */ |
| 241 | dma = chip->dma8; |
| 242 | if (dma > 3 || dma == 2) { |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 243 | snd_printk(KERN_ERR "[0x%lx] ESS: bad DMA channel %d " |
| 244 | "for ES1688 chip!!\n", chip->port, dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | #if 0 |
| 246 | dma_bits = 0; |
| 247 | cfg = 0x00; /* disable all DMA */ |
| 248 | #endif |
| 249 | return -EINVAL; |
| 250 | } else { |
| 251 | dma_bits = dma; |
| 252 | if (dma != 3) |
| 253 | dma_bits++; |
| 254 | } |
| 255 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 256 | snd_es1688_write(chip, 0xb2, cfg | (dma_bits << 2)); |
| 257 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 258 | } else { |
| 259 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 260 | snd_es1688_write(chip, 0xb1, 0x10); /* disable IRQ */ |
| 261 | snd_es1688_write(chip, 0xb2, 0x00); /* disable DMA */ |
| 262 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 263 | } |
| 264 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 265 | snd_es1688_read(chip, 0xb1); |
| 266 | snd_es1688_read(chip, 0xb2); |
| 267 | snd_es1688_reset(chip); |
| 268 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | |
| 274 | */ |
| 275 | |
Takashi Iwai | 4ea2bb7 | 2017-06-07 14:15:49 +0200 | [diff] [blame] | 276 | static const struct snd_ratnum clocks[2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | .num = 795444, |
| 279 | .den_min = 1, |
| 280 | .den_max = 128, |
| 281 | .den_step = 1, |
| 282 | }, |
| 283 | { |
| 284 | .num = 397722, |
| 285 | .den_min = 1, |
| 286 | .den_max = 128, |
| 287 | .den_step = 1, |
| 288 | } |
| 289 | }; |
| 290 | |
Takashi Iwai | 4ea2bb7 | 2017-06-07 14:15:49 +0200 | [diff] [blame] | 291 | static const struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | .nrats = 2, |
| 293 | .rats = clocks, |
| 294 | }; |
| 295 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 296 | static void snd_es1688_set_rate(struct snd_es1688 *chip, struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 298 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | unsigned int bits, divider; |
| 300 | |
| 301 | if (runtime->rate_num == clocks[0].num) |
| 302 | bits = 256 - runtime->rate_den; |
| 303 | else |
| 304 | bits = 128 - runtime->rate_den; |
| 305 | /* set filter register */ |
| 306 | divider = 256 - 7160000*20/(8*82*runtime->rate); |
| 307 | /* write result to hardware */ |
| 308 | snd_es1688_write(chip, 0xa1, bits); |
| 309 | snd_es1688_write(chip, 0xa2, divider); |
| 310 | } |
| 311 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 312 | static int snd_es1688_trigger(struct snd_es1688 *chip, int cmd, unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
| 314 | int val; |
| 315 | |
| 316 | if (cmd == SNDRV_PCM_TRIGGER_STOP) { |
| 317 | value = 0x00; |
| 318 | } else if (cmd != SNDRV_PCM_TRIGGER_START) { |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | spin_lock(&chip->reg_lock); |
| 322 | chip->trigger_value = value; |
| 323 | val = snd_es1688_read(chip, 0xb8); |
| 324 | if ((val < 0) || (val & 0x0f) == value) { |
| 325 | spin_unlock(&chip->reg_lock); |
| 326 | return -EINVAL; /* something is wrong */ |
| 327 | } |
| 328 | #if 0 |
Takashi Iwai | 4c9f1d3 | 2009-02-05 15:47:51 +0100 | [diff] [blame] | 329 | printk(KERN_DEBUG "trigger: val = 0x%x, value = 0x%x\n", val, value); |
| 330 | printk(KERN_DEBUG "trigger: pointer = 0x%x\n", |
| 331 | snd_dma_pointer(chip->dma8, chip->dma_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | #endif |
| 333 | snd_es1688_write(chip, 0xb8, (val & 0xf0) | value); |
| 334 | spin_unlock(&chip->reg_lock); |
| 335 | return 0; |
| 336 | } |
| 337 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 338 | static int snd_es1688_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
| 340 | unsigned long flags; |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 341 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
| 342 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 344 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 345 | |
| 346 | chip->dma_size = size; |
| 347 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 348 | snd_es1688_reset(chip); |
| 349 | snd_es1688_set_rate(chip, substream); |
| 350 | snd_es1688_write(chip, 0xb8, 4); /* auto init DMA mode */ |
| 351 | snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels)); |
| 352 | snd_es1688_write(chip, 0xb9, 2); /* demand mode (4 bytes/request) */ |
| 353 | if (runtime->channels == 1) { |
| 354 | if (snd_pcm_format_width(runtime->format) == 8) { |
| 355 | /* 8. bit mono */ |
| 356 | snd_es1688_write(chip, 0xb6, 0x80); |
| 357 | snd_es1688_write(chip, 0xb7, 0x51); |
| 358 | snd_es1688_write(chip, 0xb7, 0xd0); |
| 359 | } else { |
| 360 | /* 16. bit mono */ |
| 361 | snd_es1688_write(chip, 0xb6, 0x00); |
| 362 | snd_es1688_write(chip, 0xb7, 0x71); |
| 363 | snd_es1688_write(chip, 0xb7, 0xf4); |
| 364 | } |
| 365 | } else { |
| 366 | if (snd_pcm_format_width(runtime->format) == 8) { |
| 367 | /* 8. bit stereo */ |
| 368 | snd_es1688_write(chip, 0xb6, 0x80); |
| 369 | snd_es1688_write(chip, 0xb7, 0x51); |
| 370 | snd_es1688_write(chip, 0xb7, 0x98); |
| 371 | } else { |
| 372 | /* 16. bit stereo */ |
| 373 | snd_es1688_write(chip, 0xb6, 0x00); |
| 374 | snd_es1688_write(chip, 0xb7, 0x71); |
| 375 | snd_es1688_write(chip, 0xb7, 0xbc); |
| 376 | } |
| 377 | } |
| 378 | snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50); |
| 379 | snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50); |
| 380 | snd_es1688_dsp_command(chip, ES1688_DSP_CMD_SPKON); |
| 381 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 382 | /* --- */ |
| 383 | count = -count; |
| 384 | snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); |
| 385 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 386 | snd_es1688_write(chip, 0xa4, (unsigned char) count); |
| 387 | snd_es1688_write(chip, 0xa5, (unsigned char) (count >> 8)); |
| 388 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 389 | return 0; |
| 390 | } |
| 391 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 392 | static int snd_es1688_playback_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | int cmd) |
| 394 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 395 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | return snd_es1688_trigger(chip, cmd, 0x05); |
| 397 | } |
| 398 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 399 | static int snd_es1688_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
| 401 | unsigned long flags; |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 402 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
| 403 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 405 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 406 | |
| 407 | chip->dma_size = size; |
| 408 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 409 | snd_es1688_reset(chip); |
| 410 | snd_es1688_set_rate(chip, substream); |
| 411 | snd_es1688_dsp_command(chip, ES1688_DSP_CMD_SPKOFF); |
| 412 | snd_es1688_write(chip, 0xb8, 0x0e); /* auto init DMA mode */ |
| 413 | snd_es1688_write(chip, 0xa8, (snd_es1688_read(chip, 0xa8) & ~0x03) | (3 - runtime->channels)); |
| 414 | snd_es1688_write(chip, 0xb9, 2); /* demand mode (4 bytes/request) */ |
| 415 | if (runtime->channels == 1) { |
| 416 | if (snd_pcm_format_width(runtime->format) == 8) { |
| 417 | /* 8. bit mono */ |
| 418 | snd_es1688_write(chip, 0xb7, 0x51); |
| 419 | snd_es1688_write(chip, 0xb7, 0xd0); |
| 420 | } else { |
| 421 | /* 16. bit mono */ |
| 422 | snd_es1688_write(chip, 0xb7, 0x71); |
| 423 | snd_es1688_write(chip, 0xb7, 0xf4); |
| 424 | } |
| 425 | } else { |
| 426 | if (snd_pcm_format_width(runtime->format) == 8) { |
| 427 | /* 8. bit stereo */ |
| 428 | snd_es1688_write(chip, 0xb7, 0x51); |
| 429 | snd_es1688_write(chip, 0xb7, 0x98); |
| 430 | } else { |
| 431 | /* 16. bit stereo */ |
| 432 | snd_es1688_write(chip, 0xb7, 0x71); |
| 433 | snd_es1688_write(chip, 0xb7, 0xbc); |
| 434 | } |
| 435 | } |
| 436 | snd_es1688_write(chip, 0xb1, (snd_es1688_read(chip, 0xb1) & 0x0f) | 0x50); |
| 437 | snd_es1688_write(chip, 0xb2, (snd_es1688_read(chip, 0xb2) & 0x0f) | 0x50); |
| 438 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 439 | /* --- */ |
| 440 | count = -count; |
| 441 | snd_dma_program(chip->dma8, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT); |
| 442 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 443 | snd_es1688_write(chip, 0xa4, (unsigned char) count); |
| 444 | snd_es1688_write(chip, 0xa5, (unsigned char) (count >> 8)); |
| 445 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 446 | return 0; |
| 447 | } |
| 448 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 449 | static int snd_es1688_capture_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | int cmd) |
| 451 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 452 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | return snd_es1688_trigger(chip, cmd, 0x0f); |
| 454 | } |
| 455 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 456 | static irqreturn_t snd_es1688_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 458 | struct snd_es1688 *chip = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | if (chip->trigger_value == 0x05) /* ok.. playback is active */ |
| 461 | snd_pcm_period_elapsed(chip->playback_substream); |
| 462 | if (chip->trigger_value == 0x0f) /* ok.. capture is active */ |
| 463 | snd_pcm_period_elapsed(chip->capture_substream); |
| 464 | |
| 465 | inb(ES1688P(chip, DATA_AVAIL)); /* ack interrupt */ |
| 466 | return IRQ_HANDLED; |
| 467 | } |
| 468 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 469 | static snd_pcm_uframes_t snd_es1688_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 471 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | size_t ptr; |
| 473 | |
| 474 | if (chip->trigger_value != 0x05) |
| 475 | return 0; |
| 476 | ptr = snd_dma_pointer(chip->dma8, chip->dma_size); |
| 477 | return bytes_to_frames(substream->runtime, ptr); |
| 478 | } |
| 479 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 480 | static snd_pcm_uframes_t snd_es1688_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 482 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | size_t ptr; |
| 484 | |
| 485 | if (chip->trigger_value != 0x0f) |
| 486 | return 0; |
| 487 | ptr = snd_dma_pointer(chip->dma8, chip->dma_size); |
| 488 | return bytes_to_frames(substream->runtime, ptr); |
| 489 | } |
| 490 | |
| 491 | /* |
| 492 | |
| 493 | */ |
| 494 | |
Bhumika Goyal | aec5465 | 2017-08-17 14:45:52 +0530 | [diff] [blame] | 495 | static const struct snd_pcm_hardware snd_es1688_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | { |
| 497 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 498 | SNDRV_PCM_INFO_MMAP_VALID), |
| 499 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 500 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 501 | .rate_min = 4000, |
| 502 | .rate_max = 48000, |
| 503 | .channels_min = 1, |
| 504 | .channels_max = 2, |
| 505 | .buffer_bytes_max = 65536, |
| 506 | .period_bytes_min = 64, |
| 507 | .period_bytes_max = 65536, |
| 508 | .periods_min = 1, |
| 509 | .periods_max = 1024, |
| 510 | .fifo_size = 0, |
| 511 | }; |
| 512 | |
Bhumika Goyal | aec5465 | 2017-08-17 14:45:52 +0530 | [diff] [blame] | 513 | static const struct snd_pcm_hardware snd_es1688_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | { |
| 515 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 516 | SNDRV_PCM_INFO_MMAP_VALID), |
| 517 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 518 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 519 | .rate_min = 4000, |
| 520 | .rate_max = 48000, |
| 521 | .channels_min = 1, |
| 522 | .channels_max = 2, |
| 523 | .buffer_bytes_max = 65536, |
| 524 | .period_bytes_min = 64, |
| 525 | .period_bytes_max = 65536, |
| 526 | .periods_min = 1, |
| 527 | .periods_max = 1024, |
| 528 | .fifo_size = 0, |
| 529 | }; |
| 530 | |
| 531 | /* |
| 532 | |
| 533 | */ |
| 534 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 535 | static int snd_es1688_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 537 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
| 538 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | if (chip->capture_substream != NULL) |
| 541 | return -EAGAIN; |
| 542 | chip->playback_substream = substream; |
| 543 | runtime->hw = snd_es1688_playback; |
| 544 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 545 | &hw_constraints_clocks); |
| 546 | return 0; |
| 547 | } |
| 548 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 549 | static int snd_es1688_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 551 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
| 552 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
| 554 | if (chip->playback_substream != NULL) |
| 555 | return -EAGAIN; |
| 556 | chip->capture_substream = substream; |
| 557 | runtime->hw = snd_es1688_capture; |
| 558 | snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 559 | &hw_constraints_clocks); |
| 560 | return 0; |
| 561 | } |
| 562 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 563 | static int snd_es1688_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 565 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
| 567 | chip->playback_substream = NULL; |
| 568 | return 0; |
| 569 | } |
| 570 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 571 | static int snd_es1688_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 573 | struct snd_es1688 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | chip->capture_substream = NULL; |
| 576 | return 0; |
| 577 | } |
| 578 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 579 | static int snd_es1688_free(struct snd_es1688 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 581 | if (chip->hardware != ES1688_HW_UNDEF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | snd_es1688_init(chip, 0); |
Markus Elfring | 42d7721 | 2014-11-21 19:05:50 +0100 | [diff] [blame] | 583 | release_and_free_resource(chip->res_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | if (chip->irq >= 0) |
| 585 | free_irq(chip->irq, (void *) chip); |
| 586 | if (chip->dma8 >= 0) { |
| 587 | disable_dma(chip->dma8); |
| 588 | free_dma(chip->dma8); |
| 589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return 0; |
| 591 | } |
| 592 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 593 | static int snd_es1688_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 595 | struct snd_es1688 *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | return snd_es1688_free(chip); |
| 597 | } |
| 598 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 599 | static const char *snd_es1688_chip_id(struct snd_es1688 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | { |
| 601 | static char tmp[16]; |
| 602 | sprintf(tmp, "ES%s688 rev %i", chip->hardware == ES1688_HW_688 ? "" : "1", chip->version & 0x0f); |
| 603 | return tmp; |
| 604 | } |
| 605 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 606 | int snd_es1688_create(struct snd_card *card, |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 607 | struct snd_es1688 *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | unsigned long port, |
| 609 | unsigned long mpu_port, |
| 610 | int irq, |
| 611 | int mpu_irq, |
| 612 | int dma8, |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 613 | unsigned short hardware) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { |
Takashi Iwai | 99f664d | 2020-01-03 09:16:23 +0100 | [diff] [blame] | 615 | static const struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | .dev_free = snd_es1688_dev_free, |
| 617 | }; |
| 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | int err; |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | if (chip == NULL) |
| 622 | return -ENOMEM; |
| 623 | chip->irq = -1; |
| 624 | chip->dma8 = -1; |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 625 | chip->hardware = ES1688_HW_UNDEF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 627 | chip->res_port = request_region(port + 4, 12, "ES1688"); |
| 628 | if (chip->res_port == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4); |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 630 | err = -EBUSY; |
| 631 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 633 | |
| 634 | err = request_irq(irq, snd_es1688_interrupt, 0, "ES1688", (void *) chip); |
| 635 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq); |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 637 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | chip->irq = irq; |
Takashi Iwai | f5ac512 | 2019-12-10 07:34:39 +0100 | [diff] [blame] | 641 | card->sync_irq = chip->irq; |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 642 | err = request_dma(dma8, "ES1688"); |
| 643 | |
| 644 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | snd_printk(KERN_ERR "es1688: can't grab DMA8 %d\n", dma8); |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 646 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | chip->dma8 = dma8; |
| 649 | |
| 650 | spin_lock_init(&chip->reg_lock); |
| 651 | spin_lock_init(&chip->mixer_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | chip->port = port; |
| 653 | mpu_port &= ~0x000f; |
| 654 | if (mpu_port < 0x300 || mpu_port > 0x330) |
| 655 | mpu_port = 0; |
| 656 | chip->mpu_port = mpu_port; |
| 657 | chip->mpu_irq = mpu_irq; |
| 658 | chip->hardware = hardware; |
| 659 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 660 | err = snd_es1688_probe(chip); |
| 661 | if (err < 0) |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 662 | goto exit; |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 663 | |
| 664 | err = snd_es1688_init(chip, 1); |
| 665 | if (err < 0) |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 666 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | /* Register device */ |
Fengguang Wu | e5b3542 | 2012-07-29 19:39:09 +0800 | [diff] [blame] | 669 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
| 670 | exit: |
| 671 | if (err) |
| 672 | snd_es1688_free(chip); |
| 673 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Arvind Yadav | e79a560 | 2017-08-11 17:28:00 +0530 | [diff] [blame] | 676 | static const struct snd_pcm_ops snd_es1688_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | .open = snd_es1688_playback_open, |
| 678 | .close = snd_es1688_playback_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | .prepare = snd_es1688_playback_prepare, |
| 680 | .trigger = snd_es1688_playback_trigger, |
| 681 | .pointer = snd_es1688_playback_pointer, |
| 682 | }; |
| 683 | |
Arvind Yadav | e79a560 | 2017-08-11 17:28:00 +0530 | [diff] [blame] | 684 | static const struct snd_pcm_ops snd_es1688_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | .open = snd_es1688_capture_open, |
| 686 | .close = snd_es1688_capture_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | .prepare = snd_es1688_capture_prepare, |
| 688 | .trigger = snd_es1688_capture_trigger, |
| 689 | .pointer = snd_es1688_capture_pointer, |
| 690 | }; |
| 691 | |
Lars-Peter Clausen | 4b8ab88 | 2015-01-02 12:24:37 +0100 | [diff] [blame] | 692 | int snd_es1688_pcm(struct snd_card *card, struct snd_es1688 *chip, int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 694 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | int err; |
| 696 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 697 | err = snd_pcm_new(card, "ESx688", device, 1, 1, &pcm); |
| 698 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | return err; |
| 700 | |
| 701 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1688_playback_ops); |
| 702 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1688_capture_ops); |
| 703 | |
| 704 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX; |
Nicolas Iooss | cd7d1ea | 2017-03-13 20:22:50 +0100 | [diff] [blame] | 706 | strcpy(pcm->name, snd_es1688_chip_id(chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | chip->pcm = pcm; |
| 708 | |
Takashi Iwai | eb40b64 | 2019-12-09 10:48:44 +0100 | [diff] [blame] | 709 | snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, card->dev, |
| 710 | 64*1024, 64*1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | /* |
| 715 | * MIXER part |
| 716 | */ |
| 717 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 718 | static int snd_es1688_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Takashi Iwai | 69b0c76 | 2014-10-20 18:14:07 +0200 | [diff] [blame] | 720 | static const char * const texts[8] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | "Mic", "Mic Master", "CD", "AOUT", |
| 722 | "Mic1", "Mix", "Line", "Master" |
| 723 | }; |
| 724 | |
Takashi Iwai | 69b0c76 | 2014-10-20 18:14:07 +0200 | [diff] [blame] | 725 | return snd_ctl_enum_info(uinfo, 1, 8, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 728 | static int snd_es1688_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 730 | struct snd_es1688 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | ucontrol->value.enumerated.item[0] = snd_es1688_mixer_read(chip, ES1688_REC_DEV) & 7; |
| 732 | return 0; |
| 733 | } |
| 734 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 735 | static int snd_es1688_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 737 | struct snd_es1688 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | unsigned long flags; |
| 739 | unsigned char oval, nval; |
| 740 | int change; |
| 741 | |
| 742 | if (ucontrol->value.enumerated.item[0] > 8) |
| 743 | return -EINVAL; |
| 744 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 745 | oval = snd_es1688_mixer_read(chip, ES1688_REC_DEV); |
| 746 | nval = (ucontrol->value.enumerated.item[0] & 7) | (oval & ~15); |
| 747 | change = nval != oval; |
| 748 | if (change) |
| 749 | snd_es1688_mixer_write(chip, ES1688_REC_DEV, nval); |
| 750 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 751 | return change; |
| 752 | } |
| 753 | |
| 754 | #define ES1688_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
| 755 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 756 | .info = snd_es1688_info_single, \ |
| 757 | .get = snd_es1688_get_single, .put = snd_es1688_put_single, \ |
| 758 | .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } |
| 759 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 760 | static int snd_es1688_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | { |
| 762 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 763 | |
| 764 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 765 | uinfo->count = 1; |
| 766 | uinfo->value.integer.min = 0; |
| 767 | uinfo->value.integer.max = mask; |
| 768 | return 0; |
| 769 | } |
| 770 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 771 | static int snd_es1688_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 773 | struct snd_es1688 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | unsigned long flags; |
| 775 | int reg = kcontrol->private_value & 0xff; |
| 776 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 777 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 778 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 779 | |
| 780 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 781 | ucontrol->value.integer.value[0] = (snd_es1688_mixer_read(chip, reg) >> shift) & mask; |
| 782 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 783 | if (invert) |
| 784 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 785 | return 0; |
| 786 | } |
| 787 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 788 | static int snd_es1688_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 790 | struct snd_es1688 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | unsigned long flags; |
| 792 | int reg = kcontrol->private_value & 0xff; |
| 793 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 794 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 795 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 796 | int change; |
| 797 | unsigned char oval, nval; |
| 798 | |
| 799 | nval = (ucontrol->value.integer.value[0] & mask); |
| 800 | if (invert) |
| 801 | nval = mask - nval; |
| 802 | nval <<= shift; |
| 803 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 804 | oval = snd_es1688_mixer_read(chip, reg); |
| 805 | nval = (oval & ~(mask << shift)) | nval; |
| 806 | change = nval != oval; |
| 807 | if (change) |
| 808 | snd_es1688_mixer_write(chip, reg, nval); |
| 809 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 810 | return change; |
| 811 | } |
| 812 | |
| 813 | #define ES1688_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ |
| 814 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 815 | .info = snd_es1688_info_double, \ |
| 816 | .get = snd_es1688_get_double, .put = snd_es1688_put_double, \ |
| 817 | .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } |
| 818 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 819 | static int snd_es1688_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
| 821 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 822 | |
| 823 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 824 | uinfo->count = 2; |
| 825 | uinfo->value.integer.min = 0; |
| 826 | uinfo->value.integer.max = mask; |
| 827 | return 0; |
| 828 | } |
| 829 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 830 | static int snd_es1688_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 832 | struct snd_es1688 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | unsigned long flags; |
| 834 | int left_reg = kcontrol->private_value & 0xff; |
| 835 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 836 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 837 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 838 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 839 | int invert = (kcontrol->private_value >> 22) & 1; |
| 840 | unsigned char left, right; |
| 841 | |
| 842 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 843 | if (left_reg < 0xa0) |
| 844 | left = snd_es1688_mixer_read(chip, left_reg); |
| 845 | else |
| 846 | left = snd_es1688_read(chip, left_reg); |
| 847 | if (left_reg != right_reg) { |
| 848 | if (right_reg < 0xa0) |
| 849 | right = snd_es1688_mixer_read(chip, right_reg); |
| 850 | else |
| 851 | right = snd_es1688_read(chip, right_reg); |
| 852 | } else |
| 853 | right = left; |
| 854 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 855 | ucontrol->value.integer.value[0] = (left >> shift_left) & mask; |
| 856 | ucontrol->value.integer.value[1] = (right >> shift_right) & mask; |
| 857 | if (invert) { |
| 858 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 859 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 860 | } |
| 861 | return 0; |
| 862 | } |
| 863 | |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 864 | static int snd_es1688_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
Takashi Iwai | d3a7e47 | 2005-11-17 14:31:42 +0100 | [diff] [blame] | 866 | struct snd_es1688 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | unsigned long flags; |
| 868 | int left_reg = kcontrol->private_value & 0xff; |
| 869 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 870 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 871 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 872 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 873 | int invert = (kcontrol->private_value >> 22) & 1; |
| 874 | int change; |
| 875 | unsigned char val1, val2, oval1, oval2; |
| 876 | |
| 877 | val1 = ucontrol->value.integer.value[0] & mask; |
| 878 | val2 = ucontrol->value.integer.value[1] & mask; |
| 879 | if (invert) { |
| 880 | val1 = mask - val1; |
| 881 | val2 = mask - val2; |
| 882 | } |
| 883 | val1 <<= shift_left; |
| 884 | val2 <<= shift_right; |
| 885 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 886 | if (left_reg != right_reg) { |
| 887 | if (left_reg < 0xa0) |
| 888 | oval1 = snd_es1688_mixer_read(chip, left_reg); |
| 889 | else |
| 890 | oval1 = snd_es1688_read(chip, left_reg); |
| 891 | if (right_reg < 0xa0) |
| 892 | oval2 = snd_es1688_mixer_read(chip, right_reg); |
| 893 | else |
| 894 | oval2 = snd_es1688_read(chip, right_reg); |
| 895 | val1 = (oval1 & ~(mask << shift_left)) | val1; |
| 896 | val2 = (oval2 & ~(mask << shift_right)) | val2; |
| 897 | change = val1 != oval1 || val2 != oval2; |
| 898 | if (change) { |
| 899 | if (left_reg < 0xa0) |
| 900 | snd_es1688_mixer_write(chip, left_reg, val1); |
| 901 | else |
| 902 | snd_es1688_write(chip, left_reg, val1); |
| 903 | if (right_reg < 0xa0) |
| 904 | snd_es1688_mixer_write(chip, right_reg, val1); |
| 905 | else |
| 906 | snd_es1688_write(chip, right_reg, val1); |
| 907 | } |
| 908 | } else { |
| 909 | if (left_reg < 0xa0) |
| 910 | oval1 = snd_es1688_mixer_read(chip, left_reg); |
| 911 | else |
| 912 | oval1 = snd_es1688_read(chip, left_reg); |
| 913 | val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; |
| 914 | change = val1 != oval1; |
| 915 | if (change) { |
| 916 | if (left_reg < 0xa0) |
| 917 | snd_es1688_mixer_write(chip, left_reg, val1); |
| 918 | else |
| 919 | snd_es1688_write(chip, left_reg, val1); |
| 920 | } |
| 921 | |
| 922 | } |
| 923 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 924 | return change; |
| 925 | } |
| 926 | |
Takashi Iwai | fdd1f6f | 2020-01-03 09:16:51 +0100 | [diff] [blame] | 927 | static const struct snd_kcontrol_new snd_es1688_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | ES1688_DOUBLE("Master Playback Volume", 0, ES1688_MASTER_DEV, ES1688_MASTER_DEV, 4, 0, 15, 0), |
| 929 | ES1688_DOUBLE("PCM Playback Volume", 0, ES1688_PCM_DEV, ES1688_PCM_DEV, 4, 0, 15, 0), |
| 930 | ES1688_DOUBLE("Line Playback Volume", 0, ES1688_LINE_DEV, ES1688_LINE_DEV, 4, 0, 15, 0), |
| 931 | ES1688_DOUBLE("CD Playback Volume", 0, ES1688_CD_DEV, ES1688_CD_DEV, 4, 0, 15, 0), |
| 932 | ES1688_DOUBLE("FM Playback Volume", 0, ES1688_FM_DEV, ES1688_FM_DEV, 4, 0, 15, 0), |
| 933 | ES1688_DOUBLE("Mic Playback Volume", 0, ES1688_MIC_DEV, ES1688_MIC_DEV, 4, 0, 15, 0), |
| 934 | ES1688_DOUBLE("Aux Playback Volume", 0, ES1688_AUX_DEV, ES1688_AUX_DEV, 4, 0, 15, 0), |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 935 | ES1688_SINGLE("Beep Playback Volume", 0, ES1688_SPEAKER_DEV, 0, 7, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | ES1688_DOUBLE("Capture Volume", 0, ES1688_RECLEV_DEV, ES1688_RECLEV_DEV, 4, 0, 15, 0), |
| 937 | ES1688_SINGLE("Capture Switch", 0, ES1688_REC_DEV, 4, 1, 1), |
| 938 | { |
| 939 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 940 | .name = "Capture Source", |
| 941 | .info = snd_es1688_info_mux, |
| 942 | .get = snd_es1688_get_mux, |
| 943 | .put = snd_es1688_put_mux, |
| 944 | }, |
| 945 | }; |
| 946 | |
| 947 | #define ES1688_INIT_TABLE_SIZE (sizeof(snd_es1688_init_table)/2) |
| 948 | |
Takashi Iwai | 748f518 | 2020-01-05 15:48:02 +0100 | [diff] [blame] | 949 | static const unsigned char snd_es1688_init_table[][2] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | { ES1688_MASTER_DEV, 0 }, |
| 951 | { ES1688_PCM_DEV, 0 }, |
| 952 | { ES1688_LINE_DEV, 0 }, |
| 953 | { ES1688_CD_DEV, 0 }, |
| 954 | { ES1688_FM_DEV, 0 }, |
| 955 | { ES1688_MIC_DEV, 0 }, |
| 956 | { ES1688_AUX_DEV, 0 }, |
| 957 | { ES1688_SPEAKER_DEV, 0 }, |
| 958 | { ES1688_RECLEV_DEV, 0 }, |
| 959 | { ES1688_REC_DEV, 0x17 } |
| 960 | }; |
| 961 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 962 | int snd_es1688_mixer(struct snd_card *card, struct snd_es1688 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | unsigned int idx; |
| 965 | int err; |
| 966 | unsigned char reg, val; |
| 967 | |
Krzysztof Helt | 396fa82 | 2010-05-09 20:35:44 +0200 | [diff] [blame] | 968 | if (snd_BUG_ON(!chip || !card)) |
Takashi Iwai | 622207d | 2008-08-08 17:11:45 +0200 | [diff] [blame] | 969 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | strcpy(card->mixername, snd_es1688_chip_id(chip)); |
| 972 | |
| 973 | for (idx = 0; idx < ARRAY_SIZE(snd_es1688_controls); idx++) { |
| 974 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es1688_controls[idx], chip))) < 0) |
| 975 | return err; |
| 976 | } |
| 977 | for (idx = 0; idx < ES1688_INIT_TABLE_SIZE; idx++) { |
| 978 | reg = snd_es1688_init_table[idx][0]; |
| 979 | val = snd_es1688_init_table[idx][1]; |
| 980 | if (reg < 0xa0) |
| 981 | snd_es1688_mixer_write(chip, reg, val); |
| 982 | else |
| 983 | snd_es1688_write(chip, reg, val); |
| 984 | } |
| 985 | return 0; |
| 986 | } |
| 987 | |
| 988 | EXPORT_SYMBOL(snd_es1688_mixer_write); |
| 989 | EXPORT_SYMBOL(snd_es1688_create); |
| 990 | EXPORT_SYMBOL(snd_es1688_pcm); |
| 991 | EXPORT_SYMBOL(snd_es1688_mixer); |