aureon.c 62.3 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 *   ALSA driver for ICEnsemble VT1724 (Envy24HT)
 *
 *   Lowlevel functions for Terratec Aureon cards
 *
 *	Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 *
 * NOTES:
 *
25
 * - we reuse the struct snd_akm4xxx record for storing the wm8770 codec data.
Linus Torvalds's avatar
Linus Torvalds committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
 *   both wm and akm codecs are pretty similar, so we can integrate
 *   both controls in the future, once if wm codecs are reused in
 *   many boards.
 *
 * - DAC digital volumes are not implemented in the mixer.
 *   if they show better response than DAC analog volumes, we can use them
 *   instead.
 *
 *   Lowlevel functions for AudioTrak Prodigy 7.1 (and possibly 192) cards
 *      Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
 *
 *   version 0.82: Stable / not all features work yet (no communication with AC97 secondary)
 *       added 64x/128x oversampling switch (should be 64x only for 96khz)
 *       fixed some recording labels (still need to check the rest)
 *       recording is working probably thanks to correct wm8770 initialization
 *
 *   version 0.5: Initial release:
 *           working: analog output, mixer, headphone amplifier switch
 *       not working: prety much everything else, at least i could verify that
 *                    we have no digital output, no capture, pretty bad clicks and poops
 *                    on mixer switch and other coll stuff.
47
 */
Linus Torvalds's avatar
Linus Torvalds committed
48

49
#include <linux/io.h>
Linus Torvalds's avatar
Linus Torvalds committed
50 51 52 53
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/slab.h>
54 55
#include <linux/mutex.h>

Linus Torvalds's avatar
Linus Torvalds committed
56 57 58 59 60
#include <sound/core.h>

#include "ice1712.h"
#include "envy24ht.h"
#include "aureon.h"
61
#include <sound/tlv.h>
Linus Torvalds's avatar
Linus Torvalds committed
62

63 64 65 66 67 68 69 70 71
/* AC97 register cache for Aureon */
struct aureon_spec {
	unsigned short stac9744[64];
	unsigned int cs8415_mux;
	unsigned short master[2];
	unsigned short vol[8];
	unsigned char pca9554_out;
};

Linus Torvalds's avatar
Linus Torvalds committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/* WM8770 registers */
#define WM_DAC_ATTEN		0x00	/* DAC1-8 analog attenuation */
#define WM_DAC_MASTER_ATTEN	0x08	/* DAC master analog attenuation */
#define WM_DAC_DIG_ATTEN	0x09	/* DAC1-8 digital attenuation */
#define WM_DAC_DIG_MASTER_ATTEN	0x11	/* DAC master digital attenuation */
#define WM_PHASE_SWAP		0x12	/* DAC phase */
#define WM_DAC_CTRL1		0x13	/* DAC control bits */
#define WM_MUTE			0x14	/* mute controls */
#define WM_DAC_CTRL2		0x15	/* de-emphasis and zefo-flag */
#define WM_INT_CTRL		0x16	/* interface control */
#define WM_MASTER		0x17	/* master clock and mode */
#define WM_POWERDOWN		0x18	/* power-down controls */
#define WM_ADC_GAIN		0x19	/* ADC gain L(19)/R(1a) */
#define WM_ADC_MUX		0x1b	/* input MUX */
#define WM_OUT_MUX1		0x1c	/* output MUX */
#define WM_OUT_MUX2		0x1e	/* output MUX */
#define WM_RESET		0x1f	/* software reset */

/* CS8415A registers */
#define CS8415_CTRL1	0x01
#define CS8415_CTRL2	0x02
#define CS8415_QSUB		0x14
#define CS8415_RATIO	0x1E
#define CS8415_C_BUFFER	0x20
#define CS8415_ID		0x7F

98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
/* PCA9554 registers */
#define PCA9554_DEV     0x40            /* I2C device address */
#define PCA9554_IN      0x00            /* input port */
#define PCA9554_OUT     0x01            /* output port */
#define PCA9554_INVERT  0x02            /* input invert */
#define PCA9554_DIR     0x03            /* port directions */

/*
 * Aureon Universe additional controls using PCA9554
 */

/*
 * Send data to pca9554
 */
static void aureon_pca9554_write(struct snd_ice1712 *ice, unsigned char reg,
				 unsigned char data)
{
	unsigned int tmp;
	int i, j;
	unsigned char dev = PCA9554_DEV;  /* ID 0100000, write */
	unsigned char val = 0;

	tmp = snd_ice1712_gpio_read(ice);

	snd_ice1712_gpio_set_mask(ice, ~(AUREON_SPI_MOSI|AUREON_SPI_CLK|
					 AUREON_WM_RW|AUREON_WM_CS|
					 AUREON_CS8415_CS));
	tmp |= AUREON_WM_RW;
	tmp |= AUREON_CS8415_CS | AUREON_WM_CS; /* disable SPI devices */

	tmp &= ~AUREON_SPI_MOSI;
	tmp &= ~AUREON_SPI_CLK;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(50);

133
	/*
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
	 * send i2c stop condition and start condition
	 * to obtain sane state
	 */
	tmp |= AUREON_SPI_CLK;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(50);
	tmp |= AUREON_SPI_MOSI;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(100);
	tmp &= ~AUREON_SPI_MOSI;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(50);
	tmp &= ~AUREON_SPI_CLK;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(100);
	/*
	 * send device address, command and value,
	 * skipping ack cycles inbetween
	 */
	for (j = 0; j < 3; j++) {
154 155 156 157 158 159 160 161 162 163
		switch (j) {
		case 0:
			val = dev;
			break;
		case 1:
			val = reg;
			break;
		case 2:
			val = data;
			break;
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
		}
		for (i = 7; i >= 0; i--) {
			tmp &= ~AUREON_SPI_CLK;
			snd_ice1712_gpio_write(ice, tmp);
			udelay(40);
			if (val & (1 << i))
				tmp |= AUREON_SPI_MOSI;
			else
				tmp &= ~AUREON_SPI_MOSI;
			snd_ice1712_gpio_write(ice, tmp);
			udelay(40);
			tmp |= AUREON_SPI_CLK;
			snd_ice1712_gpio_write(ice, tmp);
			udelay(40);
		}
179
		tmp &= ~AUREON_SPI_CLK;
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
		snd_ice1712_gpio_write(ice, tmp);
		udelay(40);
		tmp |= AUREON_SPI_CLK;
		snd_ice1712_gpio_write(ice, tmp);
		udelay(40);
		tmp &= ~AUREON_SPI_CLK;
		snd_ice1712_gpio_write(ice, tmp);
		udelay(40);
	}
	tmp &= ~AUREON_SPI_CLK;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(40);
	tmp &= ~AUREON_SPI_MOSI;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(40);
	tmp |= AUREON_SPI_CLK;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(50);
	tmp |= AUREON_SPI_MOSI;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(100);
}

static int aureon_universe_inmux_info(struct snd_kcontrol *kcontrol,
				      struct snd_ctl_elem_info *uinfo)
{
	char *texts[3] = {"Internal Aux", "Wavetable", "Rear Line-In"};

	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	uinfo->count = 1;
	uinfo->value.enumerated.items = 3;
211
	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
212 213 214 215 216 217 218 219 220
		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
	return 0;
}

static int aureon_universe_inmux_get(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
221 222
	struct aureon_spec *spec = ice->spec;
	ucontrol->value.enumerated.item[0] = spec->pca9554_out;
223 224 225 226 227 228 229
	return 0;
}

static int aureon_universe_inmux_put(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
230
	struct aureon_spec *spec = ice->spec;
231 232 233
	unsigned char oval, nval;
	int change;

234 235 236
	nval = ucontrol->value.enumerated.item[0];
	if (nval >= 3)
		return -EINVAL;
237
	snd_ice1712_save_gpio_status(ice);
238
	oval = spec->pca9554_out;
239 240
	change = (oval != nval);
	if (change) {
241
		aureon_pca9554_write(ice, PCA9554_OUT, nval);
242
		spec->pca9554_out = nval;
243 244 245 246 247 248 249 250 251
	}
	snd_ice1712_restore_gpio_status(ice);
	return change;
}


static void aureon_ac97_write(struct snd_ice1712 *ice, unsigned short reg,
			      unsigned short val)
{
252
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
253 254 255 256 257 258 259 260 261 262 263
	unsigned int tmp;

	/* Send address to XILINX chip */
	tmp = (snd_ice1712_gpio_read(ice) & ~0xFF) | (reg & 0x7F);
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
	tmp |= AUREON_AC97_ADDR;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
	tmp &= ~AUREON_AC97_ADDR;
	snd_ice1712_gpio_write(ice, tmp);
264
	udelay(10);
Linus Torvalds's avatar
Linus Torvalds committed
265 266 267 268 269 270 271 272 273 274 275 276

	/* Send low-order byte to XILINX chip */
	tmp &= ~AUREON_AC97_DATA_MASK;
	tmp |= val & AUREON_AC97_DATA_MASK;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
	tmp |= AUREON_AC97_DATA_LOW;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
	tmp &= ~AUREON_AC97_DATA_LOW;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
277

Linus Torvalds's avatar
Linus Torvalds committed
278 279 280 281 282 283 284 285 286 287 288 289
	/* Send high-order byte to XILINX chip */
	tmp &= ~AUREON_AC97_DATA_MASK;
	tmp |= (val >> 8) & AUREON_AC97_DATA_MASK;

	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
	tmp |= AUREON_AC97_DATA_HIGH;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
	tmp &= ~AUREON_AC97_DATA_HIGH;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
290

Linus Torvalds's avatar
Linus Torvalds committed
291 292 293 294 295 296 297
	/* Instruct XILINX chip to parse the data to the STAC9744 chip */
	tmp |= AUREON_AC97_COMMIT;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
	tmp &= ~AUREON_AC97_COMMIT;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(10);
298

Linus Torvalds's avatar
Linus Torvalds committed
299
	/* Store the data in out private buffer */
300
	spec->stac9744[(reg & 0x7F) >> 1] = val;
Linus Torvalds's avatar
Linus Torvalds committed
301 302
}

303
static unsigned short aureon_ac97_read(struct snd_ice1712 *ice, unsigned short reg)
Linus Torvalds's avatar
Linus Torvalds committed
304
{
305 306
	struct aureon_spec *spec = ice->spec;
	return spec->stac9744[(reg & 0x7F) >> 1];
Linus Torvalds's avatar
Linus Torvalds committed
307 308 309 310 311
}

/*
 * Initialize STAC9744 chip
 */
312
static int aureon_ac97_init(struct snd_ice1712 *ice)
313
{
314
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
315
	int i;
316
	static const unsigned short ac97_defaults[] = {
Linus Torvalds's avatar
Linus Torvalds committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
		0x00, 0x9640,
		0x02, 0x8000,
		0x04, 0x8000,
		0x06, 0x8000,
		0x0C, 0x8008,
		0x0E, 0x8008,
		0x10, 0x8808,
		0x12, 0x8808,
		0x14, 0x8808,
		0x16, 0x8808,
		0x18, 0x8808,
		0x1C, 0x8000,
		0x26, 0x000F,
		0x28, 0x0201,
		0x2C, 0xBB80,
		0x32, 0xBB80,
		0x7C, 0x8384,
		0x7E, 0x7644,
		(unsigned short)-1
	};
	unsigned int tmp;

	/* Cold reset */
	tmp = (snd_ice1712_gpio_read(ice) | AUREON_AC97_RESET) & ~AUREON_AC97_DATA_MASK;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(3);
343

Linus Torvalds's avatar
Linus Torvalds committed
344 345 346
	tmp &= ~AUREON_AC97_RESET;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(3);
347

Linus Torvalds's avatar
Linus Torvalds committed
348 349 350
	tmp |= AUREON_AC97_RESET;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(3);
351

352
	memset(&spec->stac9744, 0, sizeof(spec->stac9744));
353
	for (i = 0; ac97_defaults[i] != (unsigned short)-1; i += 2)
354
		spec->stac9744[(ac97_defaults[i]) >> 1] = ac97_defaults[i+1];
355 356 357

	/* Unmute AC'97 master volume permanently - muting is done by WM8770 */
	aureon_ac97_write(ice, AC97_MASTER, 0x0000);
Linus Torvalds's avatar
Linus Torvalds committed
358 359 360 361 362 363 364 365 366

	return 0;
}

#define AUREON_AC97_STEREO	0x80

/*
 * AC'97 volume controls
 */
367
static int aureon_ac97_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
368 369 370 371 372 373 374 375
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = kcontrol->private_value & AUREON_AC97_STEREO ? 2 : 1;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 31;
	return 0;
}

376
static int aureon_ac97_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
377
{
378
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
379 380
	unsigned short vol;

381
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
382 383 384 385 386 387

	vol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
	ucontrol->value.integer.value[0] = 0x1F - (vol & 0x1F);
	if (kcontrol->private_value & AUREON_AC97_STEREO)
		ucontrol->value.integer.value[1] = 0x1F - ((vol >> 8) & 0x1F);

388
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
389 390 391
	return 0;
}

392
static int aureon_ac97_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
393
{
394
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
395 396
	unsigned short ovol, nvol;
	int change;
397

Linus Torvalds's avatar
Linus Torvalds committed
398 399 400 401 402 403 404
	snd_ice1712_save_gpio_status(ice);

	ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
	nvol = (0x1F - ucontrol->value.integer.value[0]) & 0x001F;
	if (kcontrol->private_value & AUREON_AC97_STEREO)
		nvol |= ((0x1F - ucontrol->value.integer.value[1]) << 8) & 0x1F00;
	nvol |= ovol & ~0x1F1F;
405 406 407

	change = (ovol != nvol);
	if (change)
Linus Torvalds's avatar
Linus Torvalds committed
408 409 410 411
		aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);

	snd_ice1712_restore_gpio_status(ice);

412
	return change;
Linus Torvalds's avatar
Linus Torvalds committed
413 414 415 416 417
}

/*
 * AC'97 mute controls
 */
418
#define aureon_ac97_mute_info	snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
419

420
static int aureon_ac97_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
421
{
422
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
423

424
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
425

426 427
	ucontrol->value.integer.value[0] = aureon_ac97_read(ice,
			kcontrol->private_value & 0x7F) & 0x8000 ? 0 : 1;
Linus Torvalds's avatar
Linus Torvalds committed
428

429
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
430 431 432
	return 0;
}

433
static int aureon_ac97_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
434
{
435
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
436 437 438 439
	unsigned short ovol, nvol;
	int change;

	snd_ice1712_save_gpio_status(ice);
440

Linus Torvalds's avatar
Linus Torvalds committed
441
	ovol = aureon_ac97_read(ice, kcontrol->private_value & 0x7F);
442 443 444 445
	nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x8000) | (ovol & ~0x8000);

	change = (ovol != nvol);
	if (change)
Linus Torvalds's avatar
Linus Torvalds committed
446
		aureon_ac97_write(ice, kcontrol->private_value & 0x7F, nvol);
447

Linus Torvalds's avatar
Linus Torvalds committed
448 449 450 451 452 453 454 455
	snd_ice1712_restore_gpio_status(ice);

	return change;
}

/*
 * AC'97 mute controls
 */
456
#define aureon_ac97_micboost_info	snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
457

458
static int aureon_ac97_micboost_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
459
{
460
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
461

462
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
463 464 465

	ucontrol->value.integer.value[0] = aureon_ac97_read(ice, AC97_MIC) & 0x0020 ? 0 : 1;

466
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
467 468 469
	return 0;
}

470
static int aureon_ac97_micboost_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
471
{
472
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
473 474 475 476
	unsigned short ovol, nvol;
	int change;

	snd_ice1712_save_gpio_status(ice);
477

Linus Torvalds's avatar
Linus Torvalds committed
478 479
	ovol = aureon_ac97_read(ice, AC97_MIC);
	nvol = (ucontrol->value.integer.value[0] ? 0x0000 : 0x0020) | (ovol & ~0x0020);
480 481 482

	change = (ovol != nvol);
	if (change)
Linus Torvalds's avatar
Linus Torvalds committed
483
		aureon_ac97_write(ice, AC97_MIC, nvol);
484

Linus Torvalds's avatar
Linus Torvalds committed
485 486 487 488 489 490 491 492
	snd_ice1712_restore_gpio_status(ice);

	return change;
}

/*
 * write data in the SPI mode
 */
493
static void aureon_spi_write(struct snd_ice1712 *ice, unsigned int cs, unsigned int data, int bits)
Linus Torvalds's avatar
Linus Torvalds committed
494 495 496
{
	unsigned int tmp;
	int i;
497
	unsigned int mosi, clk;
Linus Torvalds's avatar
Linus Torvalds committed
498 499 500

	tmp = snd_ice1712_gpio_read(ice);

501 502
	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT ||
	    ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71XT) {
503 504 505
		snd_ice1712_gpio_set_mask(ice, ~(PRODIGY_SPI_MOSI|PRODIGY_SPI_CLK|PRODIGY_WM_CS));
		mosi = PRODIGY_SPI_MOSI;
		clk = PRODIGY_SPI_CLK;
506
	} else {
507 508 509 510
		snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RW|AUREON_SPI_MOSI|AUREON_SPI_CLK|
						 AUREON_WM_CS|AUREON_CS8415_CS));
		mosi = AUREON_SPI_MOSI;
		clk = AUREON_SPI_CLK;
511

512 513
		tmp |= AUREON_WM_RW;
	}
514

Linus Torvalds's avatar
Linus Torvalds committed
515 516 517 518 519
	tmp &= ~cs;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(1);

	for (i = bits - 1; i >= 0; i--) {
520
		tmp &= ~clk;
Linus Torvalds's avatar
Linus Torvalds committed
521 522 523
		snd_ice1712_gpio_write(ice, tmp);
		udelay(1);
		if (data & (1 << i))
524
			tmp |= mosi;
Linus Torvalds's avatar
Linus Torvalds committed
525
		else
526
			tmp &= ~mosi;
Linus Torvalds's avatar
Linus Torvalds committed
527 528
		snd_ice1712_gpio_write(ice, tmp);
		udelay(1);
529
		tmp |= clk;
Linus Torvalds's avatar
Linus Torvalds committed
530 531 532 533
		snd_ice1712_gpio_write(ice, tmp);
		udelay(1);
	}

534
	tmp &= ~clk;
Linus Torvalds's avatar
Linus Torvalds committed
535 536 537
	tmp |= cs;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(1);
538
	tmp |= clk;
Linus Torvalds's avatar
Linus Torvalds committed
539 540 541 542 543 544 545
	snd_ice1712_gpio_write(ice, tmp);
	udelay(1);
}

/*
 * Read data in SPI mode
 */
546 547 548
static void aureon_spi_read(struct snd_ice1712 *ice, unsigned int cs,
		unsigned int data, int bits, unsigned char *buffer, int size)
{
Linus Torvalds's avatar
Linus Torvalds committed
549 550 551 552 553 554 555 556 557
	int i, j;
	unsigned int tmp;

	tmp = (snd_ice1712_gpio_read(ice) & ~AUREON_SPI_CLK) | AUREON_CS8415_CS|AUREON_WM_CS;
	snd_ice1712_gpio_write(ice, tmp);
	tmp &= ~cs;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(1);

558
	for (i = bits-1; i >= 0; i--) {
Linus Torvalds's avatar
Linus Torvalds committed
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
		if (data & (1 << i))
			tmp |= AUREON_SPI_MOSI;
		else
			tmp &= ~AUREON_SPI_MOSI;
		snd_ice1712_gpio_write(ice, tmp);
		udelay(1);

		tmp |= AUREON_SPI_CLK;
		snd_ice1712_gpio_write(ice, tmp);
		udelay(1);

		tmp &= ~AUREON_SPI_CLK;
		snd_ice1712_gpio_write(ice, tmp);
		udelay(1);
	}

575
	for (j = 0; j < size; j++) {
Linus Torvalds's avatar
Linus Torvalds committed
576
		unsigned char outdata = 0;
577
		for (i = 7; i >= 0; i--) {
Linus Torvalds's avatar
Linus Torvalds committed
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597
			tmp = snd_ice1712_gpio_read(ice);
			outdata <<= 1;
			outdata |= (tmp & AUREON_SPI_MISO) ? 1 : 0;
			udelay(1);

			tmp |= AUREON_SPI_CLK;
			snd_ice1712_gpio_write(ice, tmp);
			udelay(1);

			tmp &= ~AUREON_SPI_CLK;
			snd_ice1712_gpio_write(ice, tmp);
			udelay(1);
		}
		buffer[j] = outdata;
	}

	tmp |= cs;
	snd_ice1712_gpio_write(ice, tmp);
}

598 599
static unsigned char aureon_cs8415_get(struct snd_ice1712 *ice, int reg)
{
Linus Torvalds's avatar
Linus Torvalds committed
600 601 602 603 604 605
	unsigned char val;
	aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16);
	aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, &val, 1);
	return val;
}

606 607 608
static void aureon_cs8415_read(struct snd_ice1712 *ice, int reg,
				unsigned char *buffer, int size)
{
Linus Torvalds's avatar
Linus Torvalds committed
609 610 611 612
	aureon_spi_write(ice, AUREON_CS8415_CS, 0x2000 | reg, 16);
	aureon_spi_read(ice, AUREON_CS8415_CS, 0x21, 8, buffer, size);
}

613 614 615
static void aureon_cs8415_put(struct snd_ice1712 *ice, int reg,
						unsigned char val)
{
Linus Torvalds's avatar
Linus Torvalds committed
616 617 618 619 620 621
	aureon_spi_write(ice, AUREON_CS8415_CS, 0x200000 | (reg << 8) | val, 24);
}

/*
 * get the current register value of WM codec
 */
622
static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
Linus Torvalds's avatar
Linus Torvalds committed
623 624 625 626 627 628 629 630 631
{
	reg <<= 1;
	return ((unsigned short)ice->akm[0].images[reg] << 8) |
		ice->akm[0].images[reg + 1];
}

/*
 * set the register value of WM codec
 */
632
static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
Linus Torvalds's avatar
Linus Torvalds committed
633
{
634
	aureon_spi_write(ice,
635 636 637
			 ((ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT ||
			   ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71XT) ?
			 PRODIGY_WM_CS : AUREON_WM_CS),
638
			(reg << 9) | (val & 0x1ff), 16);
Linus Torvalds's avatar
Linus Torvalds committed
639 640 641 642 643
}

/*
 * set the register value of WM codec and remember it
 */
644
static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
Linus Torvalds's avatar
Linus Torvalds committed
645 646 647 648 649 650 651 652 653
{
	wm_put_nocache(ice, reg, val);
	reg <<= 1;
	ice->akm[0].images[reg] = val >> 8;
	ice->akm[0].images[reg + 1] = val;
}

/*
 */
654
#define aureon_mono_bool_info		snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
655 656 657 658

/*
 * AC'97 master playback mute controls (Mute on WM8770 chip)
 */
659
#define aureon_ac97_mmute_info		snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
660

661
static int aureon_ac97_mmute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
662
{
663
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
664

665
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
666 667 668

	ucontrol->value.integer.value[0] = (wm_get(ice, WM_OUT_MUX1) >> 1) & 0x01;

669
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
670 671 672
	return 0;
}

673 674
static int aureon_ac97_mmute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
675
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
676 677
	unsigned short ovol, nvol;
	int change;
678

Linus Torvalds's avatar
Linus Torvalds committed
679
	snd_ice1712_save_gpio_status(ice);
680

Linus Torvalds's avatar
Linus Torvalds committed
681 682
	ovol = wm_get(ice, WM_OUT_MUX1);
	nvol = (ovol & ~0x02) | (ucontrol->value.integer.value[0] ? 0x02 : 0x00);
683 684
	change = (ovol != nvol);
	if (change)
Linus Torvalds's avatar
Linus Torvalds committed
685
		wm_put(ice, WM_OUT_MUX1, nvol);
686

Linus Torvalds's avatar
Linus Torvalds committed
687 688 689 690 691
	snd_ice1712_restore_gpio_status(ice);

	return change;
}

692
static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -10000, 100, 1);
693 694 695 696
static const DECLARE_TLV_DB_SCALE(db_scale_wm_pcm, -6400, 50, 1);
static const DECLARE_TLV_DB_SCALE(db_scale_wm_adc, -1200, 100, 0);
static const DECLARE_TLV_DB_SCALE(db_scale_ac97_master, -4650, 150, 0);
static const DECLARE_TLV_DB_SCALE(db_scale_ac97_gain, -3450, 150, 0);
697

698 699
#define WM_VOL_MAX	100
#define WM_VOL_CNT	101	/* 0dB .. -100dB */
Linus Torvalds's avatar
Linus Torvalds committed
700 701
#define WM_VOL_MUTE	0x8000

702
static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index, unsigned short vol, unsigned short master)
Linus Torvalds's avatar
Linus Torvalds committed
703 704
{
	unsigned char nvol;
705

706
	if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE)) {
Linus Torvalds's avatar
Linus Torvalds committed
707
		nvol = 0;
708
	} else {
709 710
		nvol = ((vol % WM_VOL_CNT) * (master % WM_VOL_CNT)) /
								WM_VOL_MAX;
711 712
		nvol += 0x1b;
	}
713

Linus Torvalds's avatar
Linus Torvalds committed
714 715 716 717 718 719 720
	wm_put(ice, index, nvol);
	wm_put_nocache(ice, index, 0x180 | nvol);
}

/*
 * DAC mute control
 */
721
#define wm_pcm_mute_info	snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
722

723
static int wm_pcm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
724
{
725
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
726

727
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
728
	ucontrol->value.integer.value[0] = (wm_get(ice, WM_MUTE) & 0x10) ? 0 : 1;
729
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
730 731 732
	return 0;
}

733
static int wm_pcm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
734
{
735
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
736 737 738 739 740 741
	unsigned short nval, oval;
	int change;

	snd_ice1712_save_gpio_status(ice);
	oval = wm_get(ice, WM_MUTE);
	nval = (oval & ~0x10) | (ucontrol->value.integer.value[0] ? 0 : 0x10);
742 743
	change = (oval != nval);
	if (change)
Linus Torvalds's avatar
Linus Torvalds committed
744 745 746 747 748 749 750 751 752
		wm_put(ice, WM_MUTE, nval);
	snd_ice1712_restore_gpio_status(ice);

	return change;
}

/*
 * Master volume attenuation mixer control
 */
753
static int wm_master_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
754 755 756 757 758 759 760 761
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = WM_VOL_MAX;
	return 0;
}

762
static int wm_master_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
763
{
764
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
765
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
766
	int i;
767
	for (i = 0; i < 2; i++)
768 769
		ucontrol->value.integer.value[i] =
			spec->master[i] & ~WM_VOL_MUTE;
Linus Torvalds's avatar
Linus Torvalds committed
770 771 772
	return 0;
}

773
static int wm_master_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
774
{
775
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
776
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
777 778 779 780
	int ch, change = 0;

	snd_ice1712_save_gpio_status(ice);
	for (ch = 0; ch < 2; ch++) {
781 782
		unsigned int vol = ucontrol->value.integer.value[ch];
		if (vol > WM_VOL_MAX)
783
			vol = WM_VOL_MAX;
784 785
		vol |= spec->master[ch] & WM_VOL_MUTE;
		if (vol != spec->master[ch]) {
Linus Torvalds's avatar
Linus Torvalds committed
786
			int dac;
787
			spec->master[ch] = vol;
Linus Torvalds's avatar
Linus Torvalds committed
788 789
			for (dac = 0; dac < ice->num_total_dacs; dac += 2)
				wm_set_vol(ice, WM_DAC_ATTEN + dac + ch,
790 791
					   spec->vol[dac + ch],
					   spec->master[ch]);
Linus Torvalds's avatar
Linus Torvalds committed
792 793 794 795 796 797 798 799 800 801
			change = 1;
		}
	}
	snd_ice1712_restore_gpio_status(ice);
	return change;
}

/*
 * DAC volume attenuation mixer control
 */
802
static int wm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
803 804 805 806 807
{
	int voices = kcontrol->private_value >> 8;
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = voices;
	uinfo->value.integer.min = 0;		/* mute (-101dB) */
808
	uinfo->value.integer.max = WM_VOL_MAX;	/* 0dB */
Linus Torvalds's avatar
Linus Torvalds committed
809 810 811
	return 0;
}

812
static int wm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
813
{
814
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
815
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
816 817 818 819 820
	int i, ofs, voices;

	voices = kcontrol->private_value >> 8;
	ofs = kcontrol->private_value & 0xff;
	for (i = 0; i < voices; i++)
821 822
		ucontrol->value.integer.value[i] =
			spec->vol[ofs+i] & ~WM_VOL_MUTE;
Linus Torvalds's avatar
Linus Torvalds committed
823 824 825
	return 0;
}

826
static int wm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
827
{
828
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
829
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
830 831 832 833 834 835 836
	int i, idx, ofs, voices;
	int change = 0;

	voices = kcontrol->private_value >> 8;
	ofs = kcontrol->private_value & 0xff;
	snd_ice1712_save_gpio_status(ice);
	for (i = 0; i < voices; i++) {
837
		unsigned int vol = ucontrol->value.integer.value[i];
838
		if (vol > WM_VOL_MAX)
839 840
			vol = WM_VOL_MAX;
		vol |= spec->vol[ofs+i] & WM_VOL_MUTE;
841 842
		if (vol != spec->vol[ofs+i]) {
			spec->vol[ofs+i] = vol;
843
			idx  = WM_DAC_ATTEN + ofs + i;
844 845
			wm_set_vol(ice, idx, spec->vol[ofs + i],
				   spec->master[i]);
Linus Torvalds's avatar
Linus Torvalds committed
846 847 848 849 850 851 852 853 854 855
			change = 1;
		}
	}
	snd_ice1712_restore_gpio_status(ice);
	return change;
}

/*
 * WM8770 mute control
 */
856 857
static int wm_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
Linus Torvalds's avatar
Linus Torvalds committed
858 859 860 861 862 863 864
	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
	uinfo->count = kcontrol->private_value >> 8;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 1;
	return 0;
}

865
static int wm_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
866
{
867
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
868
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
869
	int voices, ofs, i;
870

Linus Torvalds's avatar
Linus Torvalds committed
871 872 873 874
	voices = kcontrol->private_value >> 8;
	ofs = kcontrol->private_value & 0xFF;

	for (i = 0; i < voices; i++)
875 876
		ucontrol->value.integer.value[i] =
			(spec->vol[ofs + i] & WM_VOL_MUTE) ? 0 : 1;
Linus Torvalds's avatar
Linus Torvalds committed
877 878 879
	return 0;
}

880
static int wm_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
881
{
882
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
883
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
884 885 886 887 888 889 890
	int change = 0, voices, ofs, i;

	voices = kcontrol->private_value >> 8;
	ofs = kcontrol->private_value & 0xFF;

	snd_ice1712_save_gpio_status(ice);
	for (i = 0; i < voices; i++) {
891
		int val = (spec->vol[ofs + i] & WM_VOL_MUTE) ? 0 : 1;
Linus Torvalds's avatar
Linus Torvalds committed
892
		if (ucontrol->value.integer.value[i] != val) {
893 894
			spec->vol[ofs + i] &= ~WM_VOL_MUTE;
			spec->vol[ofs + i] |=
Linus Torvalds's avatar
Linus Torvalds committed
895
				ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
896 897
			wm_set_vol(ice, ofs + i, spec->vol[ofs + i],
				   spec->master[i]);
Linus Torvalds's avatar
Linus Torvalds committed
898 899 900 901 902 903 904 905 906 907 908
			change = 1;
		}
	}
	snd_ice1712_restore_gpio_status(ice);

	return change;
}

/*
 * WM8770 master mute control
 */
909
#define wm_master_mute_info		snd_ctl_boolean_stereo_info
Linus Torvalds's avatar
Linus Torvalds committed
910

911
static int wm_master_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
912
{
913
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
914
	struct aureon_spec *spec = ice->spec;
915

916 917 918 919
	ucontrol->value.integer.value[0] =
		(spec->master[0] & WM_VOL_MUTE) ? 0 : 1;
	ucontrol->value.integer.value[1] =
		(spec->master[1] & WM_VOL_MUTE) ? 0 : 1;
Linus Torvalds's avatar
Linus Torvalds committed
920 921 922
	return 0;
}

923
static int wm_master_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
924
{
925
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
926
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
927 928 929 930
	int change = 0, i;

	snd_ice1712_save_gpio_status(ice);
	for (i = 0; i < 2; i++) {
931
		int val = (spec->master[i] & WM_VOL_MUTE) ? 0 : 1;
Linus Torvalds's avatar
Linus Torvalds committed
932 933
		if (ucontrol->value.integer.value[i] != val) {
			int dac;
934 935
			spec->master[i] &= ~WM_VOL_MUTE;
			spec->master[i] |=
Linus Torvalds's avatar
Linus Torvalds committed
936 937 938
				ucontrol->value.integer.value[i] ? 0 : WM_VOL_MUTE;
			for (dac = 0; dac < ice->num_total_dacs; dac += 2)
				wm_set_vol(ice, WM_DAC_ATTEN + dac + i,
939 940
					   spec->vol[dac + i],
					   spec->master[i]);
Linus Torvalds's avatar
Linus Torvalds committed
941 942 943 944 945 946 947 948 949 950 951 952
			change = 1;
		}
	}
	snd_ice1712_restore_gpio_status(ice);

	return change;
}

/* digital master volume */
#define PCM_0dB 0xff
#define PCM_RES 128	/* -64dB */
#define PCM_MIN (PCM_0dB - PCM_RES)
953
static int wm_pcm_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
954 955 956 957 958 959 960 961
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 1;
	uinfo->value.integer.min = 0;		/* mute (-64dB) */
	uinfo->value.integer.max = PCM_RES;	/* 0dB */
	return 0;
}

962
static int wm_pcm_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
963
{
964
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
965 966
	unsigned short val;

967
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
968 969 970
	val = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
	val = val > PCM_MIN ? (val - PCM_MIN) : 0;
	ucontrol->value.integer.value[0] = val;
971
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
972 973 974
	return 0;
}

975
static int wm_pcm_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
976
{
977
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
978 979 980 981
	unsigned short ovol, nvol;
	int change = 0;

	nvol = ucontrol->value.integer.value[0];
982 983 984
	if (nvol > PCM_RES)
		return -EINVAL;
	snd_ice1712_save_gpio_status(ice);
Linus Torvalds's avatar
Linus Torvalds committed
985 986 987 988 989 990 991 992 993 994 995 996 997 998
	nvol = (nvol ? (nvol + PCM_MIN) : 0) & 0xff;
	ovol = wm_get(ice, WM_DAC_DIG_MASTER_ATTEN) & 0xff;
	if (ovol != nvol) {
		wm_put(ice, WM_DAC_DIG_MASTER_ATTEN, nvol); /* prelatch */
		wm_put_nocache(ice, WM_DAC_DIG_MASTER_ATTEN, nvol | 0x100); /* update */
		change = 1;
	}
	snd_ice1712_restore_gpio_status(ice);
	return change;
}

/*
 * ADC mute control
 */
999
#define wm_adc_mute_info		snd_ctl_boolean_stereo_info
Linus Torvalds's avatar
Linus Torvalds committed
1000

1001
static int wm_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1002
{
1003
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1004 1005 1006
	unsigned short val;
	int i;

1007
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
1008 1009 1010 1011
	for (i = 0; i < 2; i++) {
		val = wm_get(ice, WM_ADC_GAIN + i);
		ucontrol->value.integer.value[i] = ~val>>5 & 0x1;
	}
1012
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
1013 1014 1015
	return 0;
}

1016
static int wm_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1017
{
1018
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
	unsigned short new, old;
	int i, change = 0;

	snd_ice1712_save_gpio_status(ice);
	for (i = 0; i < 2; i++) {
		old = wm_get(ice, WM_ADC_GAIN + i);
		new = (~ucontrol->value.integer.value[i]<<5&0x20) | (old&~0x20);
		if (new != old) {
			wm_put(ice, WM_ADC_GAIN + i, new);
			change = 1;
		}
	}
	snd_ice1712_restore_gpio_status(ice);

	return change;
}

/*
 * ADC gain mixer control
 */
1039
static int wm_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
1040 1041 1042 1043 1044 1045 1046 1047
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;		/* -12dB */
	uinfo->value.integer.max = 0x1f;	/* 19dB */
	return 0;
}

1048
static int wm_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1049
{
1050
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1051 1052 1053
	int i, idx;
	unsigned short vol;

1054
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
1055 1056 1057 1058 1059
	for (i = 0; i < 2; i++) {
		idx = WM_ADC_GAIN + i;
		vol = wm_get(ice, idx) & 0x1f;
		ucontrol->value.integer.value[i] = vol;
	}
1060
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
1061 1062 1063
	return 0;
}

1064
static int wm_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1065
{
1066
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1067 1068 1069 1070 1071 1072 1073
	int i, idx;
	unsigned short ovol, nvol;
	int change = 0;

	snd_ice1712_save_gpio_status(ice);
	for (i = 0; i < 2; i++) {
		idx  = WM_ADC_GAIN + i;
1074
		nvol = ucontrol->value.integer.value[i] & 0x1f;
Linus Torvalds's avatar
Linus Torvalds committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
		ovol = wm_get(ice, idx);
		if ((ovol & 0x1f) != nvol) {
			wm_put(ice, idx, nvol | (ovol & ~0x1f));
			change = 1;
		}
	}
	snd_ice1712_restore_gpio_status(ice);
	return change;
}

/*
 * ADC input mux mixer control
 */
1088
static int wm_adc_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
1089
{
1090
	static const char * const texts[] = {
1091 1092 1093 1094 1095
		"CD",		/* AIN1 */
		"Aux",		/* AIN2 */
		"Line",		/* AIN3 */
		"Mic",		/* AIN4 */
		"AC97"		/* AIN5 */
Linus Torvalds's avatar
Linus Torvalds committed
1096
	};
1097
	static const char * const universe_texts[] = {
1098 1099 1100 1101 1102 1103 1104 1105
		"Aux1",		/* AIN1 */
		"CD",		/* AIN2 */
		"Phono",	/* AIN3 */
		"Line",		/* AIN4 */
		"Aux2",		/* AIN5 */
		"Mic",		/* AIN6 */
		"Aux3",		/* AIN7 */
		"AC97"		/* AIN8 */
Linus Torvalds's avatar
Linus Torvalds committed
1106
	};
1107
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1108 1109 1110 1111 1112 1113 1114 1115

	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	uinfo->count = 2;
	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) {
		uinfo->value.enumerated.items = 8;
		if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
			uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
		strcpy(uinfo->value.enumerated.name, universe_texts[uinfo->value.enumerated.item]);
1116
	} else {
Linus Torvalds's avatar
Linus Torvalds committed
1117 1118 1119 1120 1121 1122 1123 1124
		uinfo->value.enumerated.items = 5;
		if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
			uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
		strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
	}
	return 0;
}

1125
static int wm_adc_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1126
{
1127
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1128 1129
	unsigned short val;

1130
	mutex_lock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
1131
	val = wm_get(ice, WM_ADC_MUX);
1132 1133
	ucontrol->value.enumerated.item[0] = val & 7;
	ucontrol->value.enumerated.item[1] = (val >> 4) & 7;
1134
	mutex_unlock(&ice->gpio_mutex);
Linus Torvalds's avatar
Linus Torvalds committed
1135 1136 1137
	return 0;
}

1138
static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1139
{
1140
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1141 1142 1143 1144 1145 1146
	unsigned short oval, nval;
	int change;

	snd_ice1712_save_gpio_status(ice);
	oval = wm_get(ice, WM_ADC_MUX);
	nval = oval & ~0x77;
1147 1148
	nval |= ucontrol->value.enumerated.item[0] & 7;
	nval |= (ucontrol->value.enumerated.item[1] & 7) << 4;
Linus Torvalds's avatar
Linus Torvalds committed
1149 1150 1151 1152
	change = (oval != nval);
	if (change)
		wm_put(ice, WM_ADC_MUX, nval);
	snd_ice1712_restore_gpio_status(ice);
1153
	return change;
Linus Torvalds's avatar
Linus Torvalds committed
1154 1155 1156 1157 1158
}

/*
 * CS8415 Input mux
 */
1159
static int aureon_cs8415_mux_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
1160
{
1161
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1162
	static const char * const aureon_texts[] = {
1163 1164
		"CD",		/* RXP0 */
		"Optical"	/* RXP1 */
Linus Torvalds's avatar
Linus Torvalds committed
1165
	};
1166
	static const char * const prodigy_texts[] = {
Linus Torvalds's avatar
Linus Torvalds committed
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
		"CD",
		"Coax"
	};
	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	uinfo->count = 1;
	uinfo->value.enumerated.items = 2;
	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71)
		strcpy(uinfo->value.enumerated.name, prodigy_texts[uinfo->value.enumerated.item]);
	else
		strcpy(uinfo->value.enumerated.name, aureon_texts[uinfo->value.enumerated.item]);
	return 0;
}

1182
static int aureon_cs8415_mux_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1183
{
1184
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1185
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
1186

1187 1188
	/* snd_ice1712_save_gpio_status(ice); */
	/* val = aureon_cs8415_get(ice, CS8415_CTRL2); */
1189
	ucontrol->value.enumerated.item[0] = spec->cs8415_mux;
1190
	/* snd_ice1712_restore_gpio_status(ice); */
Linus Torvalds's avatar
Linus Torvalds committed
1191 1192 1193
	return 0;
}

1194
static int aureon_cs8415_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1195
{
1196
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1197
	struct aureon_spec *spec = ice->spec;
Linus Torvalds's avatar
Linus Torvalds committed
1198 1199 1200 1201 1202 1203
	unsigned short oval, nval;
	int change;

	snd_ice1712_save_gpio_status(ice);
	oval = aureon_cs8415_get(ice, CS8415_CTRL2);
	nval = oval & ~0x07;
1204
	nval |= ucontrol->value.enumerated.item[0] & 7;
Linus Torvalds's avatar
Linus Torvalds committed
1205 1206 1207 1208
	change = (oval != nval);
	if (change)
		aureon_cs8415_put(ice, CS8415_CTRL2, nval);
	snd_ice1712_restore_gpio_status(ice);
1209
	spec->cs8415_mux = ucontrol->value.enumerated.item[0];
Linus Torvalds's avatar
Linus Torvalds committed
1210 1211 1212
	return change;
}

1213
static int aureon_cs8415_rate_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
1214 1215 1216 1217 1218 1219 1220 1221
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 1;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 192000;
	return 0;
}

1222
static int aureon_cs8415_rate_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1223
{
1224
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1225 1226 1227 1228 1229 1230 1231 1232 1233
	unsigned char ratio;
	ratio = aureon_cs8415_get(ice, CS8415_RATIO);
	ucontrol->value.integer.value[0] = (int)((unsigned int)ratio * 750);
	return 0;
}

/*
 * CS8415A Mute
 */
1234
#define aureon_cs8415_mute_info		snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
1235

1236
static int aureon_cs8415_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1237
{
1238
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1239 1240 1241 1242 1243 1244
	snd_ice1712_save_gpio_status(ice);
	ucontrol->value.integer.value[0] = (aureon_cs8415_get(ice, CS8415_CTRL1) & 0x20) ? 0 : 1;
	snd_ice1712_restore_gpio_status(ice);
	return 0;
}

1245
static int aureon_cs8415_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1246
{
1247
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1248 1249 1250 1251 1252 1253 1254 1255
	unsigned char oval, nval;
	int change;
	snd_ice1712_save_gpio_status(ice);
	oval = aureon_cs8415_get(ice, CS8415_CTRL1);
	if (ucontrol->value.integer.value[0])
		nval = oval & ~0x20;
	else
		nval = oval | 0x20;
1256 1257
	change = (oval != nval);
	if (change)
Linus Torvalds's avatar
Linus Torvalds committed
1258 1259 1260 1261 1262 1263 1264 1265
		aureon_cs8415_put(ice, CS8415_CTRL1, nval);
	snd_ice1712_restore_gpio_status(ice);
	return change;
}

/*
 * CS8415A Q-Sub info
 */
1266 1267
static int aureon_cs8415_qsub_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
Linus Torvalds's avatar
Linus Torvalds committed
1268 1269 1270 1271 1272
	uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
	uinfo->count = 10;
	return 0;
}

1273 1274
static int aureon_cs8415_qsub_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
1275
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1276

Linus Torvalds's avatar
Linus Torvalds committed
1277 1278 1279 1280 1281 1282 1283
	snd_ice1712_save_gpio_status(ice);
	aureon_cs8415_read(ice, CS8415_QSUB, ucontrol->value.bytes.data, 10);
	snd_ice1712_restore_gpio_status(ice);

	return 0;
}

1284 1285
static int aureon_cs8415_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
{
Linus Torvalds's avatar
Linus Torvalds committed
1286 1287 1288 1289 1290
	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
	uinfo->count = 1;
	return 0;
}

1291 1292
static int aureon_cs8415_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
Linus Torvalds's avatar
Linus Torvalds committed
1293 1294 1295 1296
	memset(ucontrol->value.iec958.status, 0xFF, 24);
	return 0;
}

1297 1298
static int aureon_cs8415_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
1299
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309

	snd_ice1712_save_gpio_status(ice);
	aureon_cs8415_read(ice, CS8415_C_BUFFER, ucontrol->value.iec958.status, 24);
	snd_ice1712_restore_gpio_status(ice);
	return 0;
}

/*
 * Headphone Amplifier
 */
1310
static int aureon_set_headphone_amp(struct snd_ice1712 *ice, int enable)
Linus Torvalds's avatar
Linus Torvalds committed
1311 1312 1313 1314 1315
{
	unsigned int tmp, tmp2;

	tmp2 = tmp = snd_ice1712_gpio_read(ice);
	if (enable)
1316 1317
		if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
		    ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT)
1318 1319 1320
			tmp |= AUREON_HP_SEL;
		else
			tmp |= PRODIGY_HP_SEL;
Linus Torvalds's avatar
Linus Torvalds committed
1321
	else
1322 1323
		if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
		    ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT)
1324
			tmp &= ~AUREON_HP_SEL;
1325
		else
1326
			tmp &= ~PRODIGY_HP_SEL;
Linus Torvalds's avatar
Linus Torvalds committed
1327 1328 1329 1330 1331 1332 1333
	if (tmp != tmp2) {
		snd_ice1712_gpio_write(ice, tmp);
		return 1;
	}
	return 0;
}

1334
static int aureon_get_headphone_amp(struct snd_ice1712 *ice)
Linus Torvalds's avatar
Linus Torvalds committed
1335 1336 1337
{
	unsigned int tmp = snd_ice1712_gpio_read(ice);

1338
	return (tmp & AUREON_HP_SEL) != 0;
Linus Torvalds's avatar
Linus Torvalds committed
1339 1340
}

1341
#define aureon_hpamp_info	snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
1342

1343
static int aureon_hpamp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1344
{
1345
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1346 1347 1348 1349 1350 1351

	ucontrol->value.integer.value[0] = aureon_get_headphone_amp(ice);
	return 0;
}


1352
static int aureon_hpamp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1353
{
1354
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1355

1356
	return aureon_set_headphone_amp(ice, ucontrol->value.integer.value[0]);
Linus Torvalds's avatar
Linus Torvalds committed
1357 1358 1359 1360 1361 1362
}

/*
 * Deemphasis
 */

1363
#define aureon_deemp_info	snd_ctl_boolean_mono_info
Linus Torvalds's avatar
Linus Torvalds committed
1364

1365
static int aureon_deemp_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1366
{
1367
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1368 1369 1370 1371
	ucontrol->value.integer.value[0] = (wm_get(ice, WM_DAC_CTRL2) & 0xf) == 0xf;
	return 0;
}

1372
static int aureon_deemp_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1373
{
1374
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
	int temp, temp2;
	temp2 = temp = wm_get(ice, WM_DAC_CTRL2);
	if (ucontrol->value.integer.value[0])
		temp |= 0xf;
	else
		temp &= ~0xf;
	if (temp != temp2) {
		wm_put(ice, WM_DAC_CTRL2, temp);
		return 1;
	}
	return 0;
}

/*
 * ADC Oversampling
 */
1391
static int aureon_oversampling_info(struct snd_kcontrol *k, struct snd_ctl_elem_info *uinfo)
Linus Torvalds's avatar
Linus Torvalds committed
1392
{
1393
	static const char * const texts[2] = { "128x", "64x"	};
Linus Torvalds's avatar
Linus Torvalds committed
1394 1395 1396 1397 1398 1399 1400 1401 1402

	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
	uinfo->count = 1;
	uinfo->value.enumerated.items = 2;

	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);

1403
	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
1404 1405
}

1406
static int aureon_oversampling_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1407
{
1408
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1409 1410 1411 1412
	ucontrol->value.enumerated.item[0] = (wm_get(ice, WM_MASTER) & 0x8) == 0x8;
	return 0;
}

1413
static int aureon_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Linus Torvalds's avatar
Linus Torvalds committed
1414 1415
{
	int temp, temp2;
1416
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
Linus Torvalds's avatar
Linus Torvalds committed
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435

	temp2 = temp = wm_get(ice, WM_MASTER);

	if (ucontrol->value.enumerated.item[0])
		temp |= 0x8;
	else
		temp &= ~0x8;

	if (temp != temp2) {
		wm_put(ice, WM_MASTER, temp);
		return 1;
	}
	return 0;
}

/*
 * mixers
 */

1436
static struct snd_kcontrol_new aureon_dac_controls[] __devinitdata = {
Linus Torvalds's avatar
Linus Torvalds committed
1437 1438 1439 1440 1441 1442 1443 1444 1445
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Master Playback Switch",
		.info = wm_master_mute_info,
		.get = wm_master_mute_get,
		.put = wm_master_mute_put
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1446
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1447
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1448 1449 1450
		.name = "Master Playback Volume",
		.info = wm_master_vol_info,
		.get = wm_master_vol_get,
1451 1452
		.put = wm_master_vol_put,
		.tlv = { .p = db_scale_wm_dac }
Linus Torvalds's avatar
Linus Torvalds committed
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Front Playback Switch",
		.info = wm_mute_info,
		.get = wm_mute_get,
		.put = wm_mute_put,
		.private_value = (2 << 8) | 0
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1464
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1465
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1466 1467 1468 1469
		.name = "Front Playback Volume",
		.info = wm_vol_info,
		.get = wm_vol_get,
		.put = wm_vol_put,
1470 1471
		.private_value = (2 << 8) | 0,
		.tlv = { .p = db_scale_wm_dac }
Linus Torvalds's avatar
Linus Torvalds committed
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Rear Playback Switch",
		.info = wm_mute_info,
		.get = wm_mute_get,
		.put = wm_mute_put,
		.private_value = (2 << 8) | 2
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1483
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1484
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1485 1486 1487 1488
		.name = "Rear Playback Volume",
		.info = wm_vol_info,
		.get = wm_vol_get,
		.put = wm_vol_put,
1489 1490
		.private_value = (2 << 8) | 2,
		.tlv = { .p = db_scale_wm_dac }
Linus Torvalds's avatar
Linus Torvalds committed
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Center Playback Switch",
		.info = wm_mute_info,
		.get = wm_mute_get,
		.put = wm_mute_put,
		.private_value = (1 << 8) | 4
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1502
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1503
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1504 1505 1506 1507
		.name = "Center Playback Volume",
		.info = wm_vol_info,
		.get = wm_vol_get,
		.put = wm_vol_put,
1508 1509
		.private_value = (1 << 8) | 4,
		.tlv = { .p = db_scale_wm_dac }
Linus Torvalds's avatar
Linus Torvalds committed
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "LFE Playback Switch",
		.info = wm_mute_info,
		.get = wm_mute_get,
		.put = wm_mute_put,
		.private_value = (1 << 8) | 5
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1521
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1522
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1523 1524 1525 1526
		.name = "LFE Playback Volume",
		.info = wm_vol_info,
		.get = wm_vol_get,
		.put = wm_vol_put,
1527 1528
		.private_value = (1 << 8) | 5,
		.tlv = { .p = db_scale_wm_dac }
Linus Torvalds's avatar
Linus Torvalds committed
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Side Playback Switch",
		.info = wm_mute_info,
		.get = wm_mute_get,
		.put = wm_mute_put,
		.private_value = (2 << 8) | 6
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1540
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1541
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1542 1543 1544 1545
		.name = "Side Playback Volume",
		.info = wm_vol_info,
		.get = wm_vol_get,
		.put = wm_vol_put,
1546 1547
		.private_value = (2 << 8) | 6,
		.tlv = { .p = db_scale_wm_dac }
Linus Torvalds's avatar
Linus Torvalds committed
1548 1549 1550
	}
};

1551
static struct snd_kcontrol_new wm_controls[] __devinitdata = {
1552 1553
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Linus Torvalds's avatar
Linus Torvalds committed
1554 1555 1556 1557
		.name = "PCM Playback Switch",
		.info = wm_pcm_mute_info,
		.get = wm_pcm_mute_get,
		.put = wm_pcm_mute_put
1558 1559 1560
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1561
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1562
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1563 1564 1565
		.name = "PCM Playback Volume",
		.info = wm_pcm_vol_info,
		.get = wm_pcm_vol_get,
1566 1567
		.put = wm_pcm_vol_put,
		.tlv = { .p = db_scale_wm_pcm }
1568
	},
Linus Torvalds's avatar
Linus Torvalds committed
1569 1570 1571 1572 1573 1574 1575 1576 1577
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Capture Switch",
		.info = wm_adc_mute_info,
		.get = wm_adc_mute_get,
		.put = wm_adc_mute_put,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1578
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1579
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
Linus Torvalds's avatar
Linus Torvalds committed
1580 1581 1582
		.name = "Capture Volume",
		.info = wm_adc_vol_info,
		.get = wm_adc_vol_get,
1583 1584
		.put = wm_adc_vol_put,
		.tlv = { .p = db_scale_wm_adc }
Linus Torvalds's avatar
Linus Torvalds committed
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Capture Source",
		.info = wm_adc_mux_info,
		.get = wm_adc_mux_get,
		.put = wm_adc_mux_put,
		.private_value = 5
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "External Amplifier",
		.info = aureon_hpamp_info,
		.get = aureon_hpamp_get,
		.put = aureon_hpamp_put
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "DAC Deemphasis Switch",
		.info = aureon_deemp_info,
		.get = aureon_deemp_get,
		.put = aureon_deemp_put
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "ADC Oversampling",
		.info = aureon_oversampling_info,
		.get = aureon_oversampling_get,
		.put = aureon_oversampling_put
	}
};

1617
static struct snd_kcontrol_new ac97_controls[] __devinitdata = {
1618 1619
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Linus Torvalds's avatar
Linus Torvalds committed
1620 1621 1622 1623 1624
		.name = "AC97 Playback Switch",
		.info = aureon_ac97_mmute_info,
		.get = aureon_ac97_mmute_get,
		.put = aureon_ac97_mmute_put,
		.private_value = AC97_MASTER
1625 1626 1627
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1628
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1629 1630 1631 1632 1633 1634
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "AC97 Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_MASTER|AUREON_AC97_STEREO,
1635
		.tlv = { .p = db_scale_ac97_master }
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "CD Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_CD
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1647
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1648 1649 1650 1651 1652 1653
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "CD Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_CD|AUREON_AC97_STEREO,
1654
		.tlv = { .p = db_scale_ac97_gain }
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Aux Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_AUX,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1666
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1667 1668 1669 1670 1671 1672
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Aux Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_AUX|AUREON_AC97_STEREO,
1673
		.tlv = { .p = db_scale_ac97_gain }
1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Line Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_LINE
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1685
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1686 1687 1688 1689 1690 1691
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Line Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_LINE|AUREON_AC97_STEREO,
1692
		.tlv = { .p = db_scale_ac97_gain }
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Mic Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_MIC
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1704
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1705 1706 1707 1708 1709 1710
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Mic Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_MIC,
1711
		.tlv = { .p = db_scale_ac97_gain }
1712 1713 1714 1715 1716 1717 1718 1719
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Mic Boost (+20dB)",
		.info = aureon_ac97_micboost_info,
		.get = aureon_ac97_micboost_get,
		.put = aureon_ac97_micboost_put
	}
Linus Torvalds's avatar
Linus Torvalds committed
1720 1721
};

1722
static struct snd_kcontrol_new universe_ac97_controls[] __devinitdata = {
1723 1724
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Linus Torvalds's avatar
Linus Torvalds committed
1725 1726 1727 1728 1729
		.name = "AC97 Playback Switch",
		.info = aureon_ac97_mmute_info,
		.get = aureon_ac97_mmute_get,
		.put = aureon_ac97_mmute_put,
		.private_value = AC97_MASTER
1730 1731 1732
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1733
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1734 1735 1736 1737 1738 1739
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "AC97 Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_MASTER|AUREON_AC97_STEREO,
1740
		.tlv = { .p = db_scale_ac97_master }
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "CD Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_AUX
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1752
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1753 1754 1755 1756 1757 1758
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "CD Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_AUX|AUREON_AC97_STEREO,
1759
		.tlv = { .p = db_scale_ac97_gain }
1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Phono Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_CD
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1771
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1772 1773 1774 1775 1776 1777
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Phono Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_CD|AUREON_AC97_STEREO,
1778
		.tlv = { .p = db_scale_ac97_gain }
1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Line Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_LINE
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1790
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1791 1792 1793 1794 1795 1796
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Line Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_LINE|AUREON_AC97_STEREO,
1797
		.tlv = { .p = db_scale_ac97_gain }
1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Mic Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_MIC
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1809
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1810 1811 1812 1813 1814 1815
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Mic Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_MIC,
1816
		.tlv = { .p = db_scale_ac97_gain }
1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Mic Boost (+20dB)",
		.info = aureon_ac97_micboost_info,
		.get = aureon_ac97_micboost_get,
		.put = aureon_ac97_micboost_put
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Aux Playback Switch",
		.info = aureon_ac97_mute_info,
		.get = aureon_ac97_mute_get,
		.put = aureon_ac97_mute_put,
		.private_value = AC97_VIDEO,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1835
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
1836 1837 1838 1839 1840 1841
				SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Aux Playback Volume",
		.info = aureon_ac97_vol_info,
		.get = aureon_ac97_vol_get,
		.put = aureon_ac97_vol_put,
		.private_value = AC97_VIDEO|AUREON_AC97_STEREO,
1842
		.tlv = { .p = db_scale_ac97_gain }
1843
	},
1844 1845 1846 1847 1848 1849 1850 1851
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Aux Source",
		.info = aureon_universe_inmux_info,
		.get = aureon_universe_inmux_get,
		.put = aureon_universe_inmux_put
	}

Linus Torvalds's avatar
Linus Torvalds committed
1852 1853
};

1854
static struct snd_kcontrol_new cs8415_controls[] __devinitdata = {
Linus Torvalds's avatar
Linus Torvalds committed
1855 1856
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1857
		.name = SNDRV_CTL_NAME_IEC958("", CAPTURE, SWITCH),
Linus Torvalds's avatar
Linus Torvalds committed
1858 1859 1860 1861
		.info = aureon_cs8415_mute_info,
		.get = aureon_cs8415_mute_get,
		.put = aureon_cs8415_mute_put
	},
1862 1863 1864
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) "Source",
Linus Torvalds's avatar
Linus Torvalds committed
1865 1866 1867 1868 1869 1870
		.info = aureon_cs8415_mux_info,
		.get = aureon_cs8415_mux_get,
		.put = aureon_cs8415_mux_put,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1871
		.name = SNDRV_CTL_NAME_IEC958("Q-subcode ", CAPTURE, DEFAULT),
Linus Torvalds's avatar
Linus Torvalds committed
1872 1873 1874 1875 1876 1877
		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
		.info = aureon_cs8415_qsub_info,
		.get = aureon_cs8415_qsub_get,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1878
		.name = SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK),
Linus Torvalds's avatar
Linus Torvalds committed
1879 1880 1881 1882 1883 1884
		.access = SNDRV_CTL_ELEM_ACCESS_READ,
		.info = aureon_cs8415_spdif_info,
		.get = aureon_cs8415_mask_get
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1885
		.name = SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT),
Linus Torvalds's avatar
Linus Torvalds committed
1886 1887 1888 1889 1890 1891
		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
		.info = aureon_cs8415_spdif_info,
		.get = aureon_cs8415_spdif_get
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1892 1893
		.name = SNDRV_CTL_NAME_IEC958("", CAPTURE, NONE) "Rate",
		.access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
Linus Torvalds's avatar
Linus Torvalds committed
1894 1895 1896 1897 1898
		.info = aureon_cs8415_rate_info,
		.get = aureon_cs8415_rate_get
	}
};

1899
static int __devinit aureon_add_controls(struct snd_ice1712 *ice)
Linus Torvalds's avatar
Linus Torvalds committed
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917
{
	unsigned int i, counts;
	int err;

	counts = ARRAY_SIZE(aureon_dac_controls);
	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY)
		counts -= 2; /* no side */
	for (i = 0; i < counts; i++) {
		err = snd_ctl_add(ice->card, snd_ctl_new1(&aureon_dac_controls[i], ice));
		if (err < 0)
			return err;
	}

	for (i = 0; i < ARRAY_SIZE(wm_controls); i++) {
		err = snd_ctl_add(ice->card, snd_ctl_new1(&wm_controls[i], ice));
		if (err < 0)
			return err;
	}
1918

Linus Torvalds's avatar
Linus Torvalds committed
1919 1920 1921 1922 1923 1924
	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON71_UNIVERSE) {
		for (i = 0; i < ARRAY_SIZE(universe_ac97_controls); i++) {
			err = snd_ctl_add(ice->card, snd_ctl_new1(&universe_ac97_controls[i], ice));
			if (err < 0)
				return err;
		}
1925
	} else if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
1926
		 ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT) {
Linus Torvalds's avatar
Linus Torvalds committed
1927 1928 1929 1930 1931 1932 1933
		for (i = 0; i < ARRAY_SIZE(ac97_controls); i++) {
			err = snd_ctl_add(ice->card, snd_ctl_new1(&ac97_controls[i], ice));
			if (err < 0)
				return err;
		}
	}

1934 1935
	if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
	    ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT) {
Linus Torvalds's avatar
Linus Torvalds committed
1936 1937 1938 1939
		unsigned char id;
		snd_ice1712_save_gpio_status(ice);
		id = aureon_cs8415_get(ice, CS8415_ID);
		if (id != 0x41)
1940
			snd_printk(KERN_INFO "No CS8415 chip. Skipping CS8415 controls.\n");
Linus Torvalds's avatar
Linus Torvalds committed
1941
		else if ((id & 0x0F) != 0x01)
1942
			snd_printk(KERN_INFO "Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1));
Linus Torvalds's avatar
Linus Torvalds committed
1943
		else {
1944
			for (i = 0; i < ARRAY_SIZE(cs8415_controls); i++) {
1945
				struct snd_kcontrol *kctl;
Linus Torvalds's avatar
Linus Torvalds committed
1946 1947 1948 1949 1950 1951 1952 1953 1954
				err = snd_ctl_add(ice->card, (kctl = snd_ctl_new1(&cs8415_controls[i], ice)));
				if (err < 0)
					return err;
				if (i > 1)
					kctl->id.device = ice->pcm->device;
			}
		}
		snd_ice1712_restore_gpio_status(ice);
	}
1955

Linus Torvalds's avatar
Linus Torvalds committed
1956 1957 1958 1959
	return 0;
}

/*
1960
 * reset the chip
Linus Torvalds's avatar
Linus Torvalds committed
1961
 */
1962
static int aureon_reset(struct snd_ice1712 *ice)
Linus Torvalds's avatar
Linus Torvalds committed
1963
{
1964
	static const unsigned short wm_inits_aureon[] = {
Linus Torvalds's avatar
Linus Torvalds committed
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999
		/* These come first to reduce init pop noise */
		0x1b, 0x044,		/* ADC Mux (AC'97 source) */
		0x1c, 0x00B,		/* Out Mux1 (VOUT1 = DAC+AUX, VOUT2 = DAC) */
		0x1d, 0x009,		/* Out Mux2 (VOUT2 = DAC, VOUT3 = DAC) */

		0x18, 0x000,		/* All power-up */

		0x16, 0x122,		/* I2S, normal polarity, 24bit */
		0x17, 0x022,		/* 256fs, slave mode */
		0x00, 0,		/* DAC1 analog mute */
		0x01, 0,		/* DAC2 analog mute */
		0x02, 0,		/* DAC3 analog mute */
		0x03, 0,		/* DAC4 analog mute */
		0x04, 0,		/* DAC5 analog mute */
		0x05, 0,		/* DAC6 analog mute */
		0x06, 0,		/* DAC7 analog mute */
		0x07, 0,		/* DAC8 analog mute */
		0x08, 0x100,		/* master analog mute */
		0x09, 0xff,		/* DAC1 digital full */
		0x0a, 0xff,		/* DAC2 digital full */
		0x0b, 0xff,		/* DAC3 digital full */
		0x0c, 0xff,		/* DAC4 digital full */
		0x0d, 0xff,		/* DAC5 digital full */
		0x0e, 0xff,		/* DAC6 digital full */
		0x0f, 0xff,		/* DAC7 digital full */
		0x10, 0xff,		/* DAC8 digital full */
		0x11, 0x1ff,		/* master digital full */
		0x12, 0x000,		/* phase normal */
		0x13, 0x090,		/* unmute DAC L/R */
		0x14, 0x000,		/* all unmute */
		0x15, 0x000,		/* no deemphasis, no ZFLG */
		0x19, 0x000,		/* -12dB ADC/L */
		0x1a, 0x000,		/* -12dB ADC/R */
		(unsigned short)-1
	};
2000
	static const unsigned short wm_inits_prodigy[] = {
Linus Torvalds's avatar
Linus Torvalds committed
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041

		/* These come first to reduce init pop noise */
		0x1b, 0x000,		/* ADC Mux */
		0x1c, 0x009,		/* Out Mux1 */
		0x1d, 0x009,		/* Out Mux2 */

		0x18, 0x000,		/* All power-up */

		0x16, 0x022,		/* I2S, normal polarity, 24bit, high-pass on */
		0x17, 0x006,		/* 128fs, slave mode */

		0x00, 0,		/* DAC1 analog mute */
		0x01, 0,		/* DAC2 analog mute */
		0x02, 0,		/* DAC3 analog mute */
		0x03, 0,		/* DAC4 analog mute */
		0x04, 0,		/* DAC5 analog mute */
		0x05, 0,		/* DAC6 analog mute */
		0x06, 0,		/* DAC7 analog mute */
		0x07, 0,		/* DAC8 analog mute */
		0x08, 0x100,		/* master analog mute */

		0x09, 0x7f,		/* DAC1 digital full */
		0x0a, 0x7f,		/* DAC2 digital full */
		0x0b, 0x7f,		/* DAC3 digital full */
		0x0c, 0x7f,		/* DAC4 digital full */
		0x0d, 0x7f,		/* DAC5 digital full */
		0x0e, 0x7f,		/* DAC6 digital full */
		0x0f, 0x7f,		/* DAC7 digital full */
		0x10, 0x7f,		/* DAC8 digital full */
		0x11, 0x1FF,		/* master digital full */

		0x12, 0x000,		/* phase normal */
		0x13, 0x090,		/* unmute DAC L/R */
		0x14, 0x000,		/* all unmute */
		0x15, 0x000,		/* no deemphasis, no ZFLG */

		0x19, 0x000,		/* -12dB ADC/L */
		0x1a, 0x000,		/* -12dB ADC/R */
		(unsigned short)-1

	};
2042
	static const unsigned short cs_inits[] = {
Linus Torvalds's avatar
Linus Torvalds committed
2043 2044 2045 2046 2047 2048 2049
		0x0441, /* RUN */
		0x0180, /* no mute, OMCK output on RMCK pin */
		0x0201, /* S/PDIF source on RXP1 */
		0x0605, /* slave, 24bit, MSB on second OSCLK, SDOUT for right channel when OLRCK is high */
		(unsigned short)-1
	};
	unsigned int tmp;
2050
	const unsigned short *p;
2051 2052
	int err;
	struct aureon_spec *spec = ice->spec;
2053 2054 2055

	err = aureon_ac97_init(ice);
	if (err != 0)
Linus Torvalds's avatar
Linus Torvalds committed
2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075
		return err;

	snd_ice1712_gpio_set_dir(ice, 0x5fffff); /* fix this for the time being */

	/* reset the wm codec as the SPI mode */
	snd_ice1712_save_gpio_status(ice);
	snd_ice1712_gpio_set_mask(ice, ~(AUREON_WM_RESET|AUREON_WM_CS|AUREON_CS8415_CS|AUREON_HP_SEL));

	tmp = snd_ice1712_gpio_read(ice);
	tmp &= ~AUREON_WM_RESET;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(1);
	tmp |= AUREON_WM_CS | AUREON_CS8415_CS;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(1);
	tmp |= AUREON_WM_RESET;
	snd_ice1712_gpio_write(ice, tmp);
	udelay(1);

	/* initialize WM8770 codec */
2076
	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71 ||
2077
		ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71LT ||
2078
		ice->eeprom.subvendor == VT1724_SUBDEVICE_PRODIGY71XT)
Linus Torvalds's avatar
Linus Torvalds committed
2079 2080 2081 2082 2083 2084 2085
		p = wm_inits_prodigy;
	else
		p = wm_inits_aureon;
	for (; *p != (unsigned short)-1; p += 2)
		wm_put(ice, p[0], p[1]);

	/* initialize CS8415A codec */
2086 2087
	if (ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71LT &&
	    ice->eeprom.subvendor != VT1724_SUBDEVICE_PRODIGY71XT) {
2088 2089
		for (p = cs_inits; *p != (unsigned short)-1; p++)
			aureon_spi_write(ice, AUREON_CS8415_CS, *p | 0x200000, 24);
2090
		spec->cs8415_mux = 1;
Linus Torvalds's avatar
Linus Torvalds committed
2091

2092 2093
		aureon_set_headphone_amp(ice, 1);
	}
Linus Torvalds's avatar
Linus Torvalds committed
2094 2095

	snd_ice1712_restore_gpio_status(ice);
2096

2097
	/* initialize PCA9554 pin directions & set default input */
2098 2099
	aureon_pca9554_write(ice, PCA9554_DIR, 0x00);
	aureon_pca9554_write(ice, PCA9554_OUT, 0x00);   /* internal AUX */
2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154
	return 0;
}

/*
 * suspend/resume
 */
#ifdef CONFIG_PM
static int aureon_resume(struct snd_ice1712 *ice)
{
	struct aureon_spec *spec = ice->spec;
	int err, i;

	err = aureon_reset(ice);
	if (err != 0)
		return err;

	/* workaround for poking volume with alsamixer after resume:
	 * just set stored volume again */
	for (i = 0; i < ice->num_total_dacs; i++)
		wm_set_vol(ice, i, spec->vol[i], spec->master[i % 2]);
	return 0;
}
#endif

/*
 * initialize the chip
 */
static int __devinit aureon_init(struct snd_ice1712 *ice)
{
	struct aureon_spec *spec;
	int i, err;

	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (!spec)
		return -ENOMEM;
	ice->spec = spec;

	if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY) {
		ice->num_total_dacs = 6;
		ice->num_total_adcs = 2;
	} else {
		/* aureon 7.1 and prodigy 7.1 */
		ice->num_total_dacs = 8;
		ice->num_total_adcs = 2;
	}

	/* to remeber the register values of CS8415 */
	ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
	if (!ice->akm)
		return -ENOMEM;
	ice->akm_codecs = 1;

	err = aureon_reset(ice);
	if (err != 0)
		return err;
2155

2156 2157
	spec->master[0] = WM_VOL_MUTE;
	spec->master[1] = WM_VOL_MUTE;
Linus Torvalds's avatar
Linus Torvalds committed
2158
	for (i = 0; i < ice->num_total_dacs; i++) {
2159 2160
		spec->vol[i] = WM_VOL_MUTE;
		wm_set_vol(ice, i, spec->vol[i], spec->master[i % 2]);
Linus Torvalds's avatar
Linus Torvalds committed
2161 2162
	}

2163 2164 2165 2166 2167
#ifdef CONFIG_PM
	ice->pm_resume = aureon_resume;
	ice->pm_suspend_enabled = 1;
#endif

Linus Torvalds's avatar
Linus Torvalds committed
2168 2169 2170 2171 2172 2173 2174 2175 2176
	return 0;
}


/*
 * Aureon boards don't provide the EEPROM data except for the vendor IDs.
 * hence the driver needs to sets up it properly.
 */

2177
static unsigned char aureon51_eeprom[] __devinitdata = {
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190
	[ICE_EEP2_SYSCONF]     = 0x0a,	/* clock 512, spdif-in/ADC, 3DACs */
	[ICE_EEP2_ACLINK]      = 0x80,	/* I2S */
	[ICE_EEP2_I2S]         = 0xfc,	/* vol, 96k, 24bit, 192k */
	[ICE_EEP2_SPDIF]       = 0xc3,	/* out-en, out-int, spdif-in */
	[ICE_EEP2_GPIO_DIR]    = 0xff,
	[ICE_EEP2_GPIO_DIR1]   = 0xff,
	[ICE_EEP2_GPIO_DIR2]   = 0x5f,
	[ICE_EEP2_GPIO_MASK]   = 0x00,
	[ICE_EEP2_GPIO_MASK1]  = 0x00,
	[ICE_EEP2_GPIO_MASK2]  = 0x00,
	[ICE_EEP2_GPIO_STATE]  = 0x00,
	[ICE_EEP2_GPIO_STATE1] = 0x00,
	[ICE_EEP2_GPIO_STATE2] = 0x00,
Linus Torvalds's avatar
Linus Torvalds committed
2191 2192
};

2193
static unsigned char aureon71_eeprom[] __devinitdata = {
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206
	[ICE_EEP2_SYSCONF]     = 0x0b,	/* clock 512, spdif-in/ADC, 4DACs */
	[ICE_EEP2_ACLINK]      = 0x80,	/* I2S */
	[ICE_EEP2_I2S]         = 0xfc,	/* vol, 96k, 24bit, 192k */
	[ICE_EEP2_SPDIF]       = 0xc3,	/* out-en, out-int, spdif-in */
	[ICE_EEP2_GPIO_DIR]    = 0xff,
	[ICE_EEP2_GPIO_DIR1]   = 0xff,
	[ICE_EEP2_GPIO_DIR2]   = 0x5f,
	[ICE_EEP2_GPIO_MASK]   = 0x00,
	[ICE_EEP2_GPIO_MASK1]  = 0x00,
	[ICE_EEP2_GPIO_MASK2]  = 0x00,
	[ICE_EEP2_GPIO_STATE]  = 0x00,
	[ICE_EEP2_GPIO_STATE1] = 0x00,
	[ICE_EEP2_GPIO_STATE2] = 0x00,
Linus Torvalds's avatar
Linus Torvalds committed
2207
};
2208
#define prodigy71_eeprom aureon71_eeprom
Linus Torvalds's avatar
Linus Torvalds committed
2209

2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
static unsigned char aureon71_universe_eeprom[] __devinitdata = {
	[ICE_EEP2_SYSCONF]     = 0x2b,	/* clock 512, mpu401, spdif-in/ADC,
					 * 4DACs
					 */
	[ICE_EEP2_ACLINK]      = 0x80,	/* I2S */
	[ICE_EEP2_I2S]         = 0xfc,	/* vol, 96k, 24bit, 192k */
	[ICE_EEP2_SPDIF]       = 0xc3,	/* out-en, out-int, spdif-in */
	[ICE_EEP2_GPIO_DIR]    = 0xff,
	[ICE_EEP2_GPIO_DIR1]   = 0xff,
	[ICE_EEP2_GPIO_DIR2]   = 0x5f,
	[ICE_EEP2_GPIO_MASK]   = 0x00,
	[ICE_EEP2_GPIO_MASK1]  = 0x00,
	[ICE_EEP2_GPIO_MASK2]  = 0x00,
	[ICE_EEP2_GPIO_STATE]  = 0x00,
	[ICE_EEP2_GPIO_STATE1] = 0x00,
	[ICE_EEP2_GPIO_STATE2] = 0x00,
};

2228
static unsigned char prodigy71lt_eeprom[] __devinitdata = {
2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
	[ICE_EEP2_SYSCONF]     = 0x4b,	/* clock 384, spdif-in/ADC, 4DACs */
	[ICE_EEP2_ACLINK]      = 0x80,	/* I2S */
	[ICE_EEP2_I2S]         = 0xfc,	/* vol, 96k, 24bit, 192k */
	[ICE_EEP2_SPDIF]       = 0xc3,	/* out-en, out-int, spdif-in */
	[ICE_EEP2_GPIO_DIR]    = 0xff,
	[ICE_EEP2_GPIO_DIR1]   = 0xff,
	[ICE_EEP2_GPIO_DIR2]   = 0x5f,
	[ICE_EEP2_GPIO_MASK]   = 0x00,
	[ICE_EEP2_GPIO_MASK1]  = 0x00,
	[ICE_EEP2_GPIO_MASK2]  = 0x00,
	[ICE_EEP2_GPIO_STATE]  = 0x00,
	[ICE_EEP2_GPIO_STATE1] = 0x00,
	[ICE_EEP2_GPIO_STATE2] = 0x00,
2242
};
2243
#define prodigy71xt_eeprom prodigy71lt_eeprom
2244

Linus Torvalds's avatar
Linus Torvalds committed
2245
/* entry point */
2246
struct snd_ice1712_card_info snd_vt1724_aureon_cards[] __devinitdata = {
Linus Torvalds's avatar
Linus Torvalds committed
2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266
	{
		.subvendor = VT1724_SUBDEVICE_AUREON51_SKY,
		.name = "Terratec Aureon 5.1-Sky",
		.model = "aureon51",
		.chip_init = aureon_init,
		.build_controls = aureon_add_controls,
		.eeprom_size = sizeof(aureon51_eeprom),
		.eeprom_data = aureon51_eeprom,
		.driver = "Aureon51",
	},
	{
		.subvendor = VT1724_SUBDEVICE_AUREON71_SPACE,
		.name = "Terratec Aureon 7.1-Space",
		.model = "aureon71",
		.chip_init = aureon_init,
		.build_controls = aureon_add_controls,
		.eeprom_size = sizeof(aureon71_eeprom),
		.eeprom_data = aureon71_eeprom,
		.driver = "Aureon71",
	},
2267 2268 2269
	{
		.subvendor = VT1724_SUBDEVICE_AUREON71_UNIVERSE,
		.name = "Terratec Aureon 7.1-Universe",
Linus Torvalds's avatar
Linus Torvalds committed
2270
		.model = "universe",
2271 2272
		.chip_init = aureon_init,
		.build_controls = aureon_add_controls,
2273 2274
		.eeprom_size = sizeof(aureon71_universe_eeprom),
		.eeprom_data = aureon71_universe_eeprom,
2275
		.driver = "Aureon71Univ", /* keep in 15 letters */
Linus Torvalds's avatar
Linus Torvalds committed
2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286
	},
	{
		.subvendor = VT1724_SUBDEVICE_PRODIGY71,
		.name = "Audiotrak Prodigy 7.1",
		.model = "prodigy71",
		.chip_init = aureon_init,
		.build_controls = aureon_add_controls,
		.eeprom_size = sizeof(prodigy71_eeprom),
		.eeprom_data = prodigy71_eeprom,
		.driver = "Prodigy71", /* should be identical with Aureon71 */
	},
2287 2288 2289 2290 2291 2292 2293 2294 2295 2296
	{
		.subvendor = VT1724_SUBDEVICE_PRODIGY71LT,
		.name = "Audiotrak Prodigy 7.1 LT",
		.model = "prodigy71lt",
		.chip_init = aureon_init,
		.build_controls = aureon_add_controls,
		.eeprom_size = sizeof(prodigy71lt_eeprom),
		.eeprom_data = prodigy71lt_eeprom,
		.driver = "Prodigy71LT",
	},
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306
	{
		.subvendor = VT1724_SUBDEVICE_PRODIGY71XT,
		.name = "Audiotrak Prodigy 7.1 XT",
		.model = "prodigy71xt",
		.chip_init = aureon_init,
		.build_controls = aureon_add_controls,
		.eeprom_size = sizeof(prodigy71xt_eeprom),
		.eeprom_data = prodigy71xt_eeprom,
		.driver = "Prodigy71LT",
	},
Linus Torvalds's avatar
Linus Torvalds committed
2307 2308
	{ } /* terminator */
};