prodigy_hifi.c 33.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/*
 *   ALSA driver for ICEnsemble VT1724 (Envy24HT)
 *
 *   Lowlevel functions for Audiotrak Prodigy 7.1 Hifi
 *   based on pontis.c
 *
 *      Copyright (c) 2007 Julian Scheel <julian@jusst.de>
 *      Copyright (c) 2007 allank
 *      Copyright (c) 2004 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
 *
 */


#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/mutex.h>

#include <sound/core.h>
#include <sound/info.h>
#include <sound/tlv.h>

#include "ice1712.h"
#include "envy24ht.h"
#include "prodigy_hifi.h"

42 43 44 45 46
struct prodigy_hifi_spec {
	unsigned short master[2];
	unsigned short vol[8];
};

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 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 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
/* I2C addresses */
#define WM_DEV		0x34

/* WM8776 registers */
#define WM_HP_ATTEN_L		0x00	/* headphone left attenuation */
#define WM_HP_ATTEN_R		0x01	/* headphone left attenuation */
#define WM_HP_MASTER		0x02	/* headphone master (both channels),
						override LLR */
#define WM_DAC_ATTEN_L		0x03	/* digital left attenuation */
#define WM_DAC_ATTEN_R		0x04
#define WM_DAC_MASTER		0x05
#define WM_PHASE_SWAP		0x06	/* DAC phase swap */
#define WM_DAC_CTRL1		0x07
#define WM_DAC_MUTE		0x08
#define WM_DAC_CTRL2		0x09
#define WM_DAC_INT		0x0a
#define WM_ADC_INT		0x0b
#define WM_MASTER_CTRL		0x0c
#define WM_POWERDOWN		0x0d
#define WM_ADC_ATTEN_L		0x0e
#define WM_ADC_ATTEN_R		0x0f
#define WM_ALC_CTRL1		0x10
#define WM_ALC_CTRL2		0x11
#define WM_ALC_CTRL3		0x12
#define WM_NOISE_GATE		0x13
#define WM_LIMITER		0x14
#define WM_ADC_MUX		0x15
#define WM_OUT_MUX		0x16
#define WM_RESET		0x17

/* Analog Recording Source :- Mic, LineIn, CD/Video, */

/* implement capture source select control for WM8776 */

#define WM_AIN1 "AIN1"
#define WM_AIN2 "AIN2"
#define WM_AIN3 "AIN3"
#define WM_AIN4 "AIN4"
#define WM_AIN5 "AIN5"

/* GPIO pins of envy24ht connected to wm8766 */
#define WM8766_SPI_CLK	 (1<<17) /* CLK, Pin97 on ICE1724 */
#define WM8766_SPI_MD	  (1<<16) /* DATA VT1724 -> WM8766, Pin96 */
#define WM8766_SPI_ML	  (1<<18) /* Latch, Pin98 */

/* WM8766 registers */
#define WM8766_DAC_CTRL	 0x02   /* DAC Control */
#define WM8766_INT_CTRL	 0x03   /* Interface Control */
#define WM8766_DAC_CTRL2	0x09
#define WM8766_DAC_CTRL3	0x0a
#define WM8766_RESET	    0x1f
#define WM8766_LDA1	     0x00
#define WM8766_LDA2	     0x04
#define WM8766_LDA3	     0x06
#define WM8766_RDA1	     0x01
#define WM8766_RDA2	     0x05
#define WM8766_RDA3	     0x07
#define WM8766_MUTE1	    0x0C
#define WM8766_MUTE2	    0x0F


/*
 * Prodigy HD2
 */
#define AK4396_ADDR    0x00
#define AK4396_CSN    (1 << 8)    /* CSN->GPIO8, pin 75 */
#define AK4396_CCLK   (1 << 9)    /* CCLK->GPIO9, pin 76 */
#define AK4396_CDTI   (1 << 10)   /* CDTI->GPIO10, pin 77 */

/* ak4396 registers */
#define AK4396_CTRL1	    0x00
#define AK4396_CTRL2	    0x01
#define AK4396_CTRL3	    0x02
#define AK4396_LCH_ATT	  0x03
#define AK4396_RCH_ATT	  0x04


/*
 * get the current register value of WM codec
 */
static unsigned short wm_get(struct snd_ice1712 *ice, int reg)
{
	reg <<= 1;
	return ((unsigned short)ice->akm[0].images[reg] << 8) |
		ice->akm[0].images[reg + 1];
}

/*
 * set the register value of WM codec and remember it
 */
static void wm_put_nocache(struct snd_ice1712 *ice, int reg, unsigned short val)
{
	unsigned short cval;
	cval = (reg << 9) | val;
	snd_vt1724_write_i2c(ice, WM_DEV, cval >> 8, cval & 0xff);
}

static void wm_put(struct snd_ice1712 *ice, int reg, unsigned short val)
{
	wm_put_nocache(ice, reg, val);
	reg <<= 1;
	ice->akm[0].images[reg] = val >> 8;
	ice->akm[0].images[reg + 1] = val;
}

/*
 * write data in the SPI mode
 */

static void set_gpio_bit(struct snd_ice1712 *ice, unsigned int bit, int val)
{
	unsigned int tmp = snd_ice1712_gpio_read(ice);
	if (val)
		tmp |= bit;
	else
		tmp &= ~bit;
	snd_ice1712_gpio_write(ice, tmp);
}

/*
 * SPI implementation for WM8766 codec - only writing supported, no readback
 */

static void wm8766_spi_send_word(struct snd_ice1712 *ice, unsigned int data)
{
	int i;
	for (i = 0; i < 16; i++) {
		set_gpio_bit(ice, WM8766_SPI_CLK, 0);
		udelay(1);
		set_gpio_bit(ice, WM8766_SPI_MD, data & 0x8000);
		udelay(1);
		set_gpio_bit(ice, WM8766_SPI_CLK, 1);
		udelay(1);
		data <<= 1;
	}
}

184 185
static void wm8766_spi_write(struct snd_ice1712 *ice, unsigned int reg,
			     unsigned int data)
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 211 212 213 214 215 216 217 218 219 220 221 222 223
{
	unsigned int block;

	snd_ice1712_gpio_set_dir(ice, WM8766_SPI_MD|
					WM8766_SPI_CLK|WM8766_SPI_ML);
	snd_ice1712_gpio_set_mask(ice, ~(WM8766_SPI_MD|
					WM8766_SPI_CLK|WM8766_SPI_ML));
	/* latch must be low when writing */
	set_gpio_bit(ice, WM8766_SPI_ML, 0);
	block = (reg << 9) | (data & 0x1ff);
	wm8766_spi_send_word(ice, block); /* REGISTER ADDRESS */
	/* release latch */
	set_gpio_bit(ice, WM8766_SPI_ML, 1);
	udelay(1);
	/* restore */
	snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
	snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
}


/*
 * serial interface for ak4396 - only writing supported, no readback
 */

static void ak4396_send_word(struct snd_ice1712 *ice, unsigned int data)
{
	int i;
	for (i = 0; i < 16; i++) {
		set_gpio_bit(ice, AK4396_CCLK, 0);
		udelay(1);
		set_gpio_bit(ice, AK4396_CDTI, data & 0x8000);
		udelay(1);
		set_gpio_bit(ice, AK4396_CCLK, 1);
		udelay(1);
		data <<= 1;
	}
}

224 225
static void ak4396_write(struct snd_ice1712 *ice, unsigned int reg,
			 unsigned int data)
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
{
	unsigned int block;

	snd_ice1712_gpio_set_dir(ice, AK4396_CSN|AK4396_CCLK|AK4396_CDTI);
	snd_ice1712_gpio_set_mask(ice, ~(AK4396_CSN|AK4396_CCLK|AK4396_CDTI));
	/* latch must be low when writing */
	set_gpio_bit(ice, AK4396_CSN, 0); 
	block =  ((AK4396_ADDR & 0x03) << 14) | (1 << 13) |
			((reg & 0x1f) << 8) | (data & 0xff);
	ak4396_send_word(ice, block); /* REGISTER ADDRESS */
	/* release latch */
	set_gpio_bit(ice, AK4396_CSN, 1);
	udelay(1);
	/* restore */
	snd_ice1712_gpio_set_mask(ice, ice->gpio.write_mask);
	snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
}


/*
 * ak4396 mixers
 */



/*
 * DAC volume attenuation mixer control (-64dB to 0dB)
 */

255 256
static int ak4396_dac_vol_info(struct snd_kcontrol *kcontrol,
			       struct snd_ctl_elem_info *uinfo)
257 258 259 260 261 262 263 264
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;   /* mute */
	uinfo->value.integer.max = 0xFF; /* linear */
	return 0;
}

265 266
static int ak4396_dac_vol_get(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
267 268
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
269
	struct prodigy_hifi_spec *spec = ice->spec;
270 271
	int i;
	
272 273 274
	for (i = 0; i < 2; i++)
		ucontrol->value.integer.value[i] = spec->vol[i];

275 276 277 278 279 280
	return 0;
}

static int ak4396_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
281
	struct prodigy_hifi_spec *spec = ice->spec;
282 283 284 285 286
	int i;
	int change = 0;
	
	mutex_lock(&ice->gpio_mutex);
	for (i = 0; i < 2; i++) {
287 288 289 290
		if (ucontrol->value.integer.value[i] != spec->vol[i]) {
			spec->vol[i] = ucontrol->value.integer.value[i];
			ak4396_write(ice, AK4396_LCH_ATT + i,
				     spec->vol[i] & 0xff);
291 292 293 294 295 296 297 298
			change = 1;
		}
	}
	mutex_unlock(&ice->gpio_mutex);
	return change;
}

static const DECLARE_TLV_DB_SCALE(db_scale_wm_dac, -12700, 100, 1);
299
static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
300

301
static struct snd_kcontrol_new prodigy_hd2_controls[] = {
302 303 304 305 306 307 308 309
    {
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
		SNDRV_CTL_ELEM_ACCESS_TLV_READ),
	.name = "Front Playback Volume",
	.info = ak4396_dac_vol_info,
	.get = ak4396_dac_vol_get,
	.put = ak4396_dac_vol_put,
310
	.tlv = { .p = ak4396_db_scale },
311 312 313 314 315 316 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 343 344
    },
};


/* --------------- */

/*
 * Logarithmic volume values for WM87*6
 * Computed as 20 * Log10(255 / x)
 */
static const unsigned char wm_vol[256] = {
	127, 48, 42, 39, 36, 34, 33, 31, 30, 29, 28, 27, 27, 26, 25, 25, 24, 24, 23,
	23, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17,
	17, 16, 16, 16, 16, 15, 15, 15, 15, 15, 15, 14, 14, 14, 14, 14, 13, 13, 13,
	13, 13, 13, 13, 12, 12, 12, 12, 12, 12, 12, 11, 11, 11, 11, 11, 11, 11, 11,
	11, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
	8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6,
	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
	5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3,
	3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
	0, 0
};

#define WM_VOL_MAX	(sizeof(wm_vol) - 1)
#define WM_VOL_MUTE	0x8000


#define DAC_0dB	0xff
#define DAC_RES	128
#define DAC_MIN	(DAC_0dB - DAC_RES)


345 346
static void wm_set_vol(struct snd_ice1712 *ice, unsigned int index,
		       unsigned short vol, unsigned short master)
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
{
	unsigned char nvol;
	
	if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
		nvol = 0;
	else {
		nvol = (((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 128)
				& WM_VOL_MAX;
		nvol = (nvol ? (nvol + DAC_MIN) : 0) & 0xff;
	}
	
	wm_put(ice, index, nvol);
	wm_put_nocache(ice, index, 0x100 | nvol);
}

362 363
static void wm8766_set_vol(struct snd_ice1712 *ice, unsigned int index,
			   unsigned short vol, unsigned short master)
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
{
	unsigned char nvol;
	
	if ((master & WM_VOL_MUTE) || (vol & WM_VOL_MUTE))
		nvol = 0;
	else {
		nvol = (((vol & ~WM_VOL_MUTE) * (master & ~WM_VOL_MUTE)) / 128)
				& WM_VOL_MAX;
		nvol = (nvol ? (nvol + DAC_MIN) : 0) & 0xff;
	}

	wm8766_spi_write(ice, index, (0x0100 | nvol));
}


/*
 * DAC volume attenuation mixer control (-64dB to 0dB)
 */

383 384
static int wm_dac_vol_info(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_info *uinfo)
385 386 387 388 389 390 391 392
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;	/* mute */
	uinfo->value.integer.max = DAC_RES;	/* 0dB, 0.5dB step */
	return 0;
}

393 394
static int wm_dac_vol_get(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
395 396
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
397
	struct prodigy_hifi_spec *spec = ice->spec;
398 399
	int i;

400
	for (i = 0; i < 2; i++)
401
		ucontrol->value.integer.value[i] =
402
			spec->vol[2 + i] & ~WM_VOL_MUTE;
403 404 405 406 407 408
	return 0;
}

static int wm_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
409
	struct prodigy_hifi_spec *spec = ice->spec;
410 411 412 413
	int i, idx, change = 0;

	mutex_lock(&ice->gpio_mutex);
	for (i = 0; i < 2; i++) {
414
		if (ucontrol->value.integer.value[i] != spec->vol[2 + i]) {
415
			idx = WM_DAC_ATTEN_L + i;
416 417 418
			spec->vol[2 + i] &= WM_VOL_MUTE;
			spec->vol[2 + i] |= ucontrol->value.integer.value[i];
			wm_set_vol(ice, idx, spec->vol[2 + i], spec->master[i]);
419 420 421 422 423 424 425 426 427 428 429
			change = 1;
		}
	}
	mutex_unlock(&ice->gpio_mutex);
	return change;
}


/*
 * WM8766 DAC volume attenuation mixer control
 */
430 431
static int wm8766_vol_info(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_info *uinfo)
432 433 434 435 436 437 438 439 440
{
	int voices = kcontrol->private_value >> 8;
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = voices;
	uinfo->value.integer.min = 0;		/* mute */
	uinfo->value.integer.max = DAC_RES;	/* 0dB */
	return 0;
}

441 442
static int wm8766_vol_get(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
443 444
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
445
	struct prodigy_hifi_spec *spec = ice->spec;
446 447 448 449 450
	int i, ofs, voices;

	voices = kcontrol->private_value >> 8;
	ofs = kcontrol->private_value & 0xff;
	for (i = 0; i < voices; i++)
451
		ucontrol->value.integer.value[i] = spec->vol[ofs + i];
452 453 454 455 456 457
	return 0;
}

static int wm8766_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
458
	struct prodigy_hifi_spec *spec = ice->spec;
459 460 461 462 463 464 465
	int i, idx, ofs, voices;
	int change = 0;

	voices = kcontrol->private_value >> 8;
	ofs = kcontrol->private_value & 0xff;
	mutex_lock(&ice->gpio_mutex);
	for (i = 0; i < voices; i++) {
466
		if (ucontrol->value.integer.value[i] != spec->vol[ofs + i]) {
467
			idx = WM8766_LDA1 + ofs + i;
468 469
			spec->vol[ofs + i] &= WM_VOL_MUTE;
			spec->vol[ofs + i] |= ucontrol->value.integer.value[i];
470
			wm8766_set_vol(ice, idx,
471
				       spec->vol[ofs + i], spec->master[i]);
472 473 474 475 476 477 478 479 480 481
			change = 1;
		}
	}
	mutex_unlock(&ice->gpio_mutex);
	return change;
}

/*
 * Master volume attenuation mixer control / applied to WM8776+WM8766
 */
482 483
static int wm_master_vol_info(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_info *uinfo)
484 485 486 487 488 489 490 491
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = DAC_RES;
	return 0;
}

492 493
static int wm_master_vol_get(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_value *ucontrol)
494 495
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
496
	struct prodigy_hifi_spec *spec = ice->spec;
497
	int i;
498 499
	for (i = 0; i < 2; i++)
		ucontrol->value.integer.value[i] = spec->master[i];
500 501 502
	return 0;
}

503 504
static int wm_master_vol_put(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_value *ucontrol)
505 506
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
507
	struct prodigy_hifi_spec *spec = ice->spec;
508 509 510 511
	int ch, change = 0;

	mutex_lock(&ice->gpio_mutex);
	for (ch = 0; ch < 2; ch++) {
512 513
		if (ucontrol->value.integer.value[ch] != spec->master[ch]) {
			spec->master[ch] = ucontrol->value.integer.value[ch];
514 515 516

			/* Apply to front DAC */
			wm_set_vol(ice, WM_DAC_ATTEN_L + ch,
517
				   spec->vol[2 + ch], spec->master[ch]);
518 519

			wm8766_set_vol(ice, WM8766_LDA1 + ch,
520
				       spec->vol[0 + ch], spec->master[ch]);
521 522

			wm8766_set_vol(ice, WM8766_LDA2 + ch,
523
				       spec->vol[4 + ch], spec->master[ch]);
524 525

			wm8766_set_vol(ice, WM8766_LDA3 + ch,
526
				       spec->vol[6 + ch], spec->master[ch]);
527 528 529 530 531 532 533 534 535 536
			change = 1;
		}
	}
	mutex_unlock(&ice->gpio_mutex);	
	return change;
}


/* KONSTI */

537 538
static int wm_adc_mux_enum_info(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_info *uinfo)
539
{
540
	static const char * const texts[32] = {
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
		"NULL", WM_AIN1, WM_AIN2, WM_AIN1 "+" WM_AIN2,
		WM_AIN3, WM_AIN1 "+" WM_AIN3, WM_AIN2 "+" WM_AIN3,
		WM_AIN1 "+" WM_AIN2 "+" WM_AIN3,
		WM_AIN4, WM_AIN1 "+" WM_AIN4, WM_AIN2 "+" WM_AIN4,
		WM_AIN1 "+" WM_AIN2 "+" WM_AIN4,
		WM_AIN3 "+" WM_AIN4, WM_AIN1 "+" WM_AIN3 "+" WM_AIN4,
		WM_AIN2 "+" WM_AIN3 "+" WM_AIN4,
		WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4,
		WM_AIN5, WM_AIN1 "+" WM_AIN5, WM_AIN2 "+" WM_AIN5,
		WM_AIN1 "+" WM_AIN2 "+" WM_AIN5,
		WM_AIN3 "+" WM_AIN5, WM_AIN1 "+" WM_AIN3 "+" WM_AIN5,
		WM_AIN2 "+" WM_AIN3 "+" WM_AIN5,
		WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN5,
		WM_AIN4 "+" WM_AIN5, WM_AIN1 "+" WM_AIN4 "+" WM_AIN5,
		WM_AIN2 "+" WM_AIN4 "+" WM_AIN5,
		WM_AIN1 "+" WM_AIN2 "+" WM_AIN4 "+" WM_AIN5,
		WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
		WM_AIN1 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
		WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5,
		WM_AIN1 "+" WM_AIN2 "+" WM_AIN3 "+" WM_AIN4 "+" WM_AIN5
	};
562

563
	return snd_ctl_enum_info(uinfo, 1, 32, texts);
564 565
}

566 567
static int wm_adc_mux_enum_get(struct snd_kcontrol *kcontrol,
			       struct snd_ctl_elem_value *ucontrol)
568 569 570 571
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);

	mutex_lock(&ice->gpio_mutex);
572
	ucontrol->value.integer.value[0] = wm_get(ice, WM_ADC_MUX) & 0x1f;
573 574 575 576
	mutex_unlock(&ice->gpio_mutex);
	return 0;
}

577 578
static int wm_adc_mux_enum_put(struct snd_kcontrol *kcontrol,
			       struct snd_ctl_elem_value *ucontrol)
579 580 581
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
	unsigned short oval, nval;
582
	int change = 0;
583 584 585

	mutex_lock(&ice->gpio_mutex);
	oval = wm_get(ice, WM_ADC_MUX);
586 587
	nval = (oval & 0xe0) | ucontrol->value.integer.value[0];
	if (nval != oval) {
588
		wm_put(ice, WM_ADC_MUX, nval);
589
		change = 1;
590 591
	}
	mutex_unlock(&ice->gpio_mutex);
592
	return change;
593 594 595 596 597 598 599 600 601 602 603 604
}

/* KONSTI */

/*
 * ADC gain mixer control (-64dB to 0dB)
 */

#define ADC_0dB	0xcf
#define ADC_RES	128
#define ADC_MIN	(ADC_0dB - ADC_RES)

605 606
static int wm_adc_vol_info(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_info *uinfo)
607 608 609 610 611 612 613 614
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
	uinfo->count = 2;
	uinfo->value.integer.min = 0;	/* mute (-64dB) */
	uinfo->value.integer.max = ADC_RES;	/* 0dB, 0.5dB step */
	return 0;
}

615 616
static int wm_adc_vol_get(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
	unsigned short val;
	int i;

	mutex_lock(&ice->gpio_mutex);
	for (i = 0; i < 2; i++) {
		val = wm_get(ice, WM_ADC_ATTEN_L + i) & 0xff;
		val = val > ADC_MIN ? (val - ADC_MIN) : 0;
		ucontrol->value.integer.value[i] = val;
	}
	mutex_unlock(&ice->gpio_mutex);
	return 0;
}

632 633
static int wm_adc_vol_put(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
	unsigned short ovol, nvol;
	int i, idx, change = 0;

	mutex_lock(&ice->gpio_mutex);
	for (i = 0; i < 2; i++) {
		nvol = ucontrol->value.integer.value[i];
		nvol = nvol ? (nvol + ADC_MIN) : 0;
		idx  = WM_ADC_ATTEN_L + i;
		ovol = wm_get(ice, idx) & 0xff;
		if (ovol != nvol) {
			wm_put(ice, idx, nvol);
			change = 1;
		}
	}
	mutex_unlock(&ice->gpio_mutex);
	return change;
}

/*
 * ADC input mux mixer control
 */
657
#define wm_adc_mux_info		snd_ctl_boolean_mono_info
658

659 660
static int wm_adc_mux_get(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
661 662 663 664 665
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
	int bit = kcontrol->private_value;

	mutex_lock(&ice->gpio_mutex);
666 667
	ucontrol->value.integer.value[0] =
		(wm_get(ice, WM_ADC_MUX) & (1 << bit)) ? 1 : 0;
668 669 670 671
	mutex_unlock(&ice->gpio_mutex);
	return 0;
}

672 673
static int wm_adc_mux_put(struct snd_kcontrol *kcontrol,
			  struct snd_ctl_elem_value *ucontrol)
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
	int bit = kcontrol->private_value;
	unsigned short oval, nval;
	int change;

	mutex_lock(&ice->gpio_mutex);
	nval = oval = wm_get(ice, WM_ADC_MUX);
	if (ucontrol->value.integer.value[0])
		nval |= (1 << bit);
	else
		nval &= ~(1 << bit);
	change = nval != oval;
	if (change) {
		wm_put(ice, WM_ADC_MUX, nval);
	}
	mutex_unlock(&ice->gpio_mutex);
	return 0;
}

/*
 * Analog bypass (In -> Out)
 */
697
#define wm_bypass_info		snd_ctl_boolean_mono_info
698

699 700
static int wm_bypass_get(struct snd_kcontrol *kcontrol,
			 struct snd_ctl_elem_value *ucontrol)
701 702 703 704
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);

	mutex_lock(&ice->gpio_mutex);
705 706
	ucontrol->value.integer.value[0] =
		(wm_get(ice, WM_OUT_MUX) & 0x04) ? 1 : 0;
707 708 709 710
	mutex_unlock(&ice->gpio_mutex);
	return 0;
}

711 712
static int wm_bypass_put(struct snd_kcontrol *kcontrol,
			 struct snd_ctl_elem_value *ucontrol)
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
	unsigned short val, oval;
	int change = 0;

	mutex_lock(&ice->gpio_mutex);
	val = oval = wm_get(ice, WM_OUT_MUX);
	if (ucontrol->value.integer.value[0])
		val |= 0x04;
	else
		val &= ~0x04;
	if (val != oval) {
		wm_put(ice, WM_OUT_MUX, val);
		change = 1;
	}
	mutex_unlock(&ice->gpio_mutex);
	return change;
}

/*
 * Left/Right swap
 */
735
#define wm_chswap_info		snd_ctl_boolean_mono_info
736

737 738
static int wm_chswap_get(struct snd_kcontrol *kcontrol,
			 struct snd_ctl_elem_value *ucontrol)
739 740 741 742 743 744 745 746 747 748
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);

	mutex_lock(&ice->gpio_mutex);
	ucontrol->value.integer.value[0] =
			(wm_get(ice, WM_DAC_CTRL1) & 0xf0) != 0x90;
	mutex_unlock(&ice->gpio_mutex);
	return 0;
}

749 750
static int wm_chswap_put(struct snd_kcontrol *kcontrol,
			 struct snd_ctl_elem_value *ucontrol)
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
{
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
	unsigned short val, oval;
	int change = 0;

	mutex_lock(&ice->gpio_mutex);
	oval = wm_get(ice, WM_DAC_CTRL1);
	val = oval & 0x0f;
	if (ucontrol->value.integer.value[0])
		val |= 0x60;
	else
		val |= 0x90;
	if (val != oval) {
		wm_put(ice, WM_DAC_CTRL1, val);
		wm_put_nocache(ice, WM_DAC_CTRL1, val);
		change = 1;
	}
	mutex_unlock(&ice->gpio_mutex);
	return change;
}


/*
 * mixers
 */

777
static struct snd_kcontrol_new prodigy_hifi_controls[] = {
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Master Playback Volume",
		.info = wm_master_vol_info,
		.get = wm_master_vol_get,
		.put = wm_master_vol_put,
		.tlv = { .p = db_scale_wm_dac }
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Front Playback Volume",
		.info = wm_dac_vol_info,
		.get = wm_dac_vol_get,
		.put = wm_dac_vol_put,
		.tlv = { .p = db_scale_wm_dac },
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Rear Playback Volume",
		.info = wm8766_vol_info,
		.get = wm8766_vol_get,
		.put = wm8766_vol_put,
		.private_value = (2 << 8) | 0,
		.tlv = { .p = db_scale_wm_dac },
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Center Playback Volume",
		.info = wm8766_vol_info,
		.get = wm8766_vol_get,
		.put = wm8766_vol_put,
		.private_value = (1 << 8) | 4,
		.tlv = { .p = db_scale_wm_dac }
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "LFE Playback Volume",
		.info = wm8766_vol_info,
		.get = wm8766_vol_get,
		.put = wm8766_vol_put,
		.private_value = (1 << 8) | 5,
		.tlv = { .p = db_scale_wm_dac }
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Side Playback Volume",
		.info = wm8766_vol_info,
		.get = wm8766_vol_get,
		.put = wm8766_vol_put,
		.private_value = (2 << 8) | 6,
		.tlv = { .p = db_scale_wm_dac },
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
			   SNDRV_CTL_ELEM_ACCESS_TLV_READ),
		.name = "Capture Volume",
		.info = wm_adc_vol_info,
		.get = wm_adc_vol_get,
		.put = wm_adc_vol_put,
		.tlv = { .p = db_scale_wm_dac },
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "CD Capture Switch",
		.info = wm_adc_mux_info,
		.get = wm_adc_mux_get,
		.put = wm_adc_mux_put,
		.private_value = 0,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Line Capture Switch",
		.info = wm_adc_mux_info,
		.get = wm_adc_mux_get,
		.put = wm_adc_mux_put,
		.private_value = 1,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Analog Bypass Switch",
		.info = wm_bypass_info,
		.get = wm_bypass_get,
		.put = wm_bypass_put,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Swap Output Channels",
		.info = wm_chswap_info,
		.get = wm_chswap_get,
		.put = wm_chswap_put,
	},
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Analog Capture Source",
		.info = wm_adc_mux_enum_info,
		.get = wm_adc_mux_enum_get,
		.put = wm_adc_mux_enum_put,
	},
};

/*
 * WM codec registers
 */
894 895
static void wm_proc_regs_write(struct snd_info_entry *entry,
			       struct snd_info_buffer *buffer)
896
{
897
	struct snd_ice1712 *ice = entry->private_data;
898 899 900 901 902 903 904 905 906 907 908 909
	char line[64];
	unsigned int reg, val;
	mutex_lock(&ice->gpio_mutex);
	while (!snd_info_get_line(buffer, line, sizeof(line))) {
		if (sscanf(line, "%x %x", &reg, &val) != 2)
			continue;
		if (reg <= 0x17 && val <= 0xffff)
			wm_put(ice, reg, val);
	}
	mutex_unlock(&ice->gpio_mutex);
}

910 911
static void wm_proc_regs_read(struct snd_info_entry *entry,
			      struct snd_info_buffer *buffer)
912
{
913
	struct snd_ice1712 *ice = entry->private_data;
914 915 916 917 918 919 920 921 922 923 924 925 926
	int reg, val;

	mutex_lock(&ice->gpio_mutex);
	for (reg = 0; reg <= 0x17; reg++) {
		val = wm_get(ice, reg);
		snd_iprintf(buffer, "%02x = %04x\n", reg, val);
	}
	mutex_unlock(&ice->gpio_mutex);
}

static void wm_proc_init(struct snd_ice1712 *ice)
{
	struct snd_info_entry *entry;
927
	if (!snd_card_proc_new(ice->card, "wm_codec", &entry)) {
928
		snd_info_set_text_ops(entry, ice, wm_proc_regs_read);
929
		entry->mode |= 0200;
930 931 932 933
		entry->c.text.write = wm_proc_regs_write;
	}
}

934
static int prodigy_hifi_add_controls(struct snd_ice1712 *ice)
935 936 937 938 939
{
	unsigned int i;
	int err;

	for (i = 0; i < ARRAY_SIZE(prodigy_hifi_controls); i++) {
940 941
		err = snd_ctl_add(ice->card,
				  snd_ctl_new1(&prodigy_hifi_controls[i], ice));
942 943 944 945 946 947 948 949 950
		if (err < 0)
			return err;
	}

	wm_proc_init(ice);

	return 0;
}

951
static int prodigy_hd2_add_controls(struct snd_ice1712 *ice)
952
{
953 954
	unsigned int i;
	int err;
955

956 957 958 959 960 961
	for (i = 0; i < ARRAY_SIZE(prodigy_hd2_controls); i++) {
		err = snd_ctl_add(ice->card,
				  snd_ctl_new1(&prodigy_hd2_controls[i], ice));
		if (err < 0)
			return err;
	}
962

963
	wm_proc_init(ice);
964

965
	return 0;
966 967
}

968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
static void wm8766_init(struct snd_ice1712 *ice)
{
	static unsigned short wm8766_inits[] = {
		WM8766_RESET,	   0x0000,
		WM8766_DAC_CTRL,	0x0120,
		WM8766_INT_CTRL,	0x0022, /* I2S Normal Mode, 24 bit */
		WM8766_DAC_CTRL2,       0x0001,
		WM8766_DAC_CTRL3,       0x0080,
		WM8766_LDA1,	    0x0100,
		WM8766_LDA2,	    0x0100,
		WM8766_LDA3,	    0x0100,
		WM8766_RDA1,	    0x0100,
		WM8766_RDA2,	    0x0100,
		WM8766_RDA3,	    0x0100,
		WM8766_MUTE1,	   0x0000,
		WM8766_MUTE2,	   0x0000,
	};
	unsigned int i;
986

987 988 989 990 991
	for (i = 0; i < ARRAY_SIZE(wm8766_inits); i += 2)
		wm8766_spi_write(ice, wm8766_inits[i], wm8766_inits[i + 1]);
}

static void wm8776_init(struct snd_ice1712 *ice)
992
{
993
	static unsigned short wm8776_inits[] = {
994 995 996 997 998 999 1000 1001 1002 1003
		/* These come first to reduce init pop noise */
		WM_ADC_MUX,	0x0003,	/* ADC mute */
		/* 0x00c0 replaced by 0x0003 */
		
		WM_DAC_MUTE,	0x0001,	/* DAC softmute */
		WM_DAC_CTRL1,	0x0000,	/* DAC mute */

		WM_POWERDOWN,	0x0008,	/* All power-up except HP */
		WM_RESET,	0x0000,	/* reset */
	};
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
	unsigned int i;

	for (i = 0; i < ARRAY_SIZE(wm8776_inits); i += 2)
		wm_put(ice, wm8776_inits[i], wm8776_inits[i + 1]);
}

#ifdef CONFIG_PM_SLEEP
static int prodigy_hifi_resume(struct snd_ice1712 *ice)
{
	static unsigned short wm8776_reinit_registers[] = {
		WM_MASTER_CTRL,
		WM_DAC_INT,
		WM_ADC_INT,
		WM_OUT_MUX,
		WM_HP_ATTEN_L,
		WM_HP_ATTEN_R,
		WM_PHASE_SWAP,
		WM_DAC_CTRL2,
		WM_ADC_ATTEN_L,
		WM_ADC_ATTEN_R,
		WM_ALC_CTRL1,
		WM_ALC_CTRL2,
		WM_ALC_CTRL3,
		WM_NOISE_GATE,
		WM_ADC_MUX,
		/* no DAC attenuation here */
	};
	struct prodigy_hifi_spec *spec = ice->spec;
	int i, ch;

	mutex_lock(&ice->gpio_mutex);

	/* reinitialize WM8776 and re-apply old register values */
	wm8776_init(ice);
	schedule_timeout_uninterruptible(1);
	for (i = 0; i < ARRAY_SIZE(wm8776_reinit_registers); i++)
		wm_put(ice, wm8776_reinit_registers[i],
		       wm_get(ice, wm8776_reinit_registers[i]));

	/* reinitialize WM8766 and re-apply volumes for all DACs */
	wm8766_init(ice);
	for (ch = 0; ch < 2; ch++) {
		wm_set_vol(ice, WM_DAC_ATTEN_L + ch,
			   spec->vol[2 + ch], spec->master[ch]);

		wm8766_set_vol(ice, WM8766_LDA1 + ch,
			       spec->vol[0 + ch], spec->master[ch]);

		wm8766_set_vol(ice, WM8766_LDA2 + ch,
			       spec->vol[4 + ch], spec->master[ch]);

		wm8766_set_vol(ice, WM8766_LDA3 + ch,
			       spec->vol[6 + ch], spec->master[ch]);
	}

	/* unmute WM8776 DAC */
	wm_put(ice, WM_DAC_MUTE, 0x00);
	wm_put(ice, WM_DAC_CTRL1, 0x90);

	mutex_unlock(&ice->gpio_mutex);
	return 0;
}
#endif

/*
 * initialize the chip
 */
static int prodigy_hifi_init(struct snd_ice1712 *ice)
{
	static unsigned short wm8776_defaults[] = {
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100
		WM_MASTER_CTRL,  0x0022, /* 256fs, slave mode */
		WM_DAC_INT,	0x0022,	/* I2S, normal polarity, 24bit */
		WM_ADC_INT,	0x0022,	/* I2S, normal polarity, 24bit */
		WM_DAC_CTRL1,	0x0090,	/* DAC L/R */
		WM_OUT_MUX,	0x0001,	/* OUT DAC */
		WM_HP_ATTEN_L,	0x0179,	/* HP 0dB */
		WM_HP_ATTEN_R,	0x0179,	/* HP 0dB */
		WM_DAC_ATTEN_L,	0x0000,	/* DAC 0dB */
		WM_DAC_ATTEN_L,	0x0100,	/* DAC 0dB */
		WM_DAC_ATTEN_R,	0x0000,	/* DAC 0dB */
		WM_DAC_ATTEN_R,	0x0100,	/* DAC 0dB */
		WM_PHASE_SWAP,	0x0000,	/* phase normal */
#if 0
		WM_DAC_MASTER,	0x0100,	/* DAC master muted */
#endif
		WM_DAC_CTRL2,	0x0000,	/* no deemphasis, no ZFLG */
		WM_ADC_ATTEN_L,	0x0000,	/* ADC muted */
		WM_ADC_ATTEN_R,	0x0000,	/* ADC muted */
#if 1
		WM_ALC_CTRL1,	0x007b,	/* */
		WM_ALC_CTRL2,	0x0000,	/* */
		WM_ALC_CTRL3,	0x0000,	/* */
		WM_NOISE_GATE,	0x0000,	/* */
#endif
		WM_DAC_MUTE,	0x0000,	/* DAC unmute */
		WM_ADC_MUX,	0x0003,	/* ADC unmute, both CD/Line On */
	};
1101
	struct prodigy_hifi_spec *spec;
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
	unsigned int i;

	ice->vt1720 = 0;
	ice->vt1724 = 1;

	ice->num_total_dacs = 8;
	ice->num_total_adcs = 1;

	/* HACK - use this as the SPDIF source.
	* don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
	*/
	ice->gpio.saved[0] = 0;
L
Lucas De Marchi 已提交
1114
	/* to remember the register values */
1115 1116 1117 1118

	ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
	if (! ice->akm)
		return -ENOMEM;
1119 1120 1121 1122 1123 1124
	ice->akm_codecs = 1;

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

	/* initialize WM8776 codec */
1127
	wm8776_init(ice);
1128
	schedule_timeout_uninterruptible(1);
1129 1130
	for (i = 0; i < ARRAY_SIZE(wm8776_defaults); i += 2)
		wm_put(ice, wm8776_defaults[i], wm8776_defaults[i + 1]);
1131

1132
	wm8766_init(ice);
1133

1134 1135 1136 1137
#ifdef CONFIG_PM_SLEEP
	ice->pm_resume = &prodigy_hifi_resume;
	ice->pm_suspend_enabled = 1;
#endif
1138 1139 1140 1141 1142 1143 1144 1145

	return 0;
}


/*
 * initialize the chip
 */
1146
static void ak4396_init(struct snd_ice1712 *ice)
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
{
	static unsigned short ak4396_inits[] = {
		AK4396_CTRL1,	   0x87,   /* I2S Normal Mode, 24 bit */
		AK4396_CTRL2,	   0x02,
		AK4396_CTRL3,	   0x00, 
		AK4396_LCH_ATT,	 0x00,
		AK4396_RCH_ATT,	 0x00,
	};

	unsigned int i;

1158 1159 1160 1161 1162 1163 1164 1165 1166 1167
	/* initialize ak4396 codec */
	/* reset codec */
	ak4396_write(ice, AK4396_CTRL1, 0x86);
	msleep(100);
	ak4396_write(ice, AK4396_CTRL1, 0x87);

	for (i = 0; i < ARRAY_SIZE(ak4396_inits); i += 2)
		ak4396_write(ice, ak4396_inits[i], ak4396_inits[i+1]);
}

1168
#ifdef CONFIG_PM_SLEEP
1169
static int prodigy_hd2_resume(struct snd_ice1712 *ice)
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
{
	/* initialize ak4396 codec and restore previous mixer volumes */
	struct prodigy_hifi_spec *spec = ice->spec;
	int i;
	mutex_lock(&ice->gpio_mutex);
	ak4396_init(ice);
	for (i = 0; i < 2; i++)
		ak4396_write(ice, AK4396_LCH_ATT + i, spec->vol[i] & 0xff);
	mutex_unlock(&ice->gpio_mutex);
	return 0;
}
#endif

1183
static int prodigy_hd2_init(struct snd_ice1712 *ice)
1184 1185 1186
{
	struct prodigy_hifi_spec *spec;

1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
	ice->vt1720 = 0;
	ice->vt1724 = 1;

	ice->num_total_dacs = 1;
	ice->num_total_adcs = 1;

	/* HACK - use this as the SPDIF source.
	* don't call snd_ice1712_gpio_get/put(), otherwise it's overwritten
	*/
	ice->gpio.saved[0] = 0;
L
Lucas De Marchi 已提交
1197
	/* to remember the register values */
1198 1199 1200 1201 1202 1203

	ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
	if (! ice->akm)
		return -ENOMEM;
	ice->akm_codecs = 1;

1204 1205 1206 1207 1208
	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (!spec)
		return -ENOMEM;
	ice->spec = spec;

1209
#ifdef CONFIG_PM_SLEEP
1210 1211 1212 1213 1214
	ice->pm_resume = &prodigy_hd2_resume;
	ice->pm_suspend_enabled = 1;
#endif

	ak4396_init(ice);
1215 1216 1217 1218 1219

	return 0;
}


1220
static unsigned char prodigy71hifi_eeprom[] = {
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
	0x4b,   /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
	0x80,   /* ACLINK: I2S */
	0xfc,   /* I2S: vol, 96k, 24bit, 192k */
	0xc3,   /* SPDIF: out-en, out-int, spdif-in */
	0xff,   /* GPIO_DIR */
	0xff,   /* GPIO_DIR1 */
	0x5f,   /* GPIO_DIR2 */
	0x00,   /* GPIO_MASK */
	0x00,   /* GPIO_MASK1 */
	0x00,   /* GPIO_MASK2 */
	0x00,   /* GPIO_STATE */
	0x00,   /* GPIO_STATE1 */
	0x00,   /* GPIO_STATE2 */
};

1236
static unsigned char prodigyhd2_eeprom[] = {
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
	0x4b,   /* SYSCONF: clock 512, spdif-in/ADC, 4DACs */
	0x80,   /* ACLINK: I2S */
	0xfc,   /* I2S: vol, 96k, 24bit, 192k */
	0xc3,   /* SPDIF: out-en, out-int, spdif-in */
	0xff,   /* GPIO_DIR */
	0xff,   /* GPIO_DIR1 */
	0x5f,   /* GPIO_DIR2 */
	0x00,   /* GPIO_MASK */
	0x00,   /* GPIO_MASK1 */
	0x00,   /* GPIO_MASK2 */
	0x00,   /* GPIO_STATE */
	0x00,   /* GPIO_STATE1 */
	0x00,   /* GPIO_STATE2 */
};

1252
static unsigned char fortissimo4_eeprom[] = {
1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
	0x43,   /* SYSCONF: clock 512, ADC, 4DACs */	
	0x80,   /* ACLINK: I2S */
	0xfc,   /* I2S: vol, 96k, 24bit, 192k */
	0xc1,   /* SPDIF: out-en, out-int */
	0xff,   /* GPIO_DIR */
	0xff,   /* GPIO_DIR1 */
	0x5f,   /* GPIO_DIR2 */
	0x00,   /* GPIO_MASK */
	0x00,   /* GPIO_MASK1 */
	0x00,   /* GPIO_MASK2 */
	0x00,   /* GPIO_STATE */
	0x00,   /* GPIO_STATE1 */
	0x00,   /* GPIO_STATE2 */
};

/* entry point */
1269
struct snd_ice1712_card_info snd_vt1724_prodigy_hifi_cards[] = {
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
	{
		.subvendor = VT1724_SUBDEVICE_PRODIGY_HIFI,
		.name = "Audiotrak Prodigy 7.1 HiFi",
		.model = "prodigy71hifi",
		.chip_init = prodigy_hifi_init,
		.build_controls = prodigy_hifi_add_controls,
		.eeprom_size = sizeof(prodigy71hifi_eeprom),
		.eeprom_data = prodigy71hifi_eeprom,
		.driver = "Prodigy71HIFI",
	},
	{
	.subvendor = VT1724_SUBDEVICE_PRODIGY_HD2,
	.name = "Audiotrak Prodigy HD2",
	.model = "prodigyhd2",
	.chip_init = prodigy_hd2_init,
	.build_controls = prodigy_hd2_add_controls,
	.eeprom_size = sizeof(prodigyhd2_eeprom),
	.eeprom_data = prodigyhd2_eeprom,
	.driver = "Prodigy71HD2",
	},
	{
		.subvendor = VT1724_SUBDEVICE_FORTISSIMO4,
		.name = "Hercules Fortissimo IV",
		.model = "fortissimo4",
		.chip_init = prodigy_hifi_init,
		.build_controls = prodigy_hifi_add_controls,
		.eeprom_size = sizeof(fortissimo4_eeprom),
		.eeprom_data = fortissimo4_eeprom,
		.driver = "Fortissimo4",
	},
	{ } /* terminator */
};