patch_via.c 50.7 KB
Newer Older
1 2 3
/*
 * Universal Interface for Intel High Definition Audio Codec
 *
4
 * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
5
 *
6 7
 *  (C) 2006-2009 VIA Technology, Inc.
 *  (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 *  This driver 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 driver 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
 */

/* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
L
Lydia Wang 已提交
25
/*									     */
26
/* 2006-03-03  Lydia Wang  Create the basic patch to support VT1708 codec    */
L
Lydia Wang 已提交
27 28
/* 2006-03-14  Lydia Wang  Modify hard code for some pin widget nid	     */
/* 2006-08-02  Lydia Wang  Add support to VT1709 codec			     */
29
/* 2006-09-08  Lydia Wang  Fix internal loopback recording source select bug */
L
Lydia Wang 已提交
30 31
/* 2007-09-12  Lydia Wang  Add EAPD enable during driver initialization	     */
/* 2007-09-17  Lydia Wang  Add VT1708B codec support			    */
32
/* 2007-11-14  Lydia Wang  Add VT1708A codec HP and CD pin connect config    */
33
/* 2008-02-03  Lydia Wang  Fix Rear channels and Back channels inverse issue */
L
Lydia Wang 已提交
34 35 36
/* 2008-03-06  Lydia Wang  Add VT1702 codec and VT1708S codec support	     */
/* 2008-04-09  Lydia Wang  Add mute front speaker when HP plugin	     */
/* 2008-04-09  Lydia Wang  Add Independent HP feature			     */
37
/* 2008-05-28  Lydia Wang  Add second S/PDIF Out support for VT1702	     */
L
Lydia Wang 已提交
38
/* 2008-09-15  Logan Li	   Add VT1708S Mic Boost workaround/backdoor	     */
39 40 41 42 43
/* 2009-02-16  Logan Li	   Add support for VT1718S			     */
/* 2009-03-13  Logan Li	   Add support for VT1716S			     */
/* 2009-04-14  Lydai Wang  Add support for VT1828S and VT2020		     */
/* 2009-07-08  Lydia Wang  Add support for VT2002P			     */
/* 2009-07-21  Lydia Wang  Add support for VT1812			     */
44
/* 2009-09-19  Lydia Wang  Add support for VT1818S			     */
L
Lydia Wang 已提交
45
/*									     */
46 47 48 49 50 51
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


#include <linux/init.h>
#include <linux/delay.h>
#include <linux/slab.h>
52
#include <linux/module.h>
53
#include <sound/core.h>
54
#include <sound/asoundef.h>
55 56
#include "hda_codec.h"
#include "hda_local.h"
57
#include "hda_auto_parser.h"
58
#include "hda_jack.h"
59
#include "hda_generic.h"
60 61

/* Pin Widget NID */
62 63
#define VT1708_HP_PIN_NID	0x20
#define VT1708_CD_PIN_NID	0x24
64

65 66 67 68 69 70 71 72
enum VIA_HDA_CODEC {
	UNKNOWN = -1,
	VT1708,
	VT1709_10CH,
	VT1709_6CH,
	VT1708B_8CH,
	VT1708B_4CH,
	VT1708S,
73
	VT1708BCE,
74
	VT1702,
L
Lydia Wang 已提交
75
	VT1718S,
L
Lydia Wang 已提交
76
	VT1716S,
L
Lydia Wang 已提交
77
	VT2002P,
L
Lydia Wang 已提交
78
	VT1812,
79
	VT1802,
80
	VT1705CF,
81
	VT1808,
82 83 84
	CODEC_TYPES,
};

85 86 87 88 89
#define VT2002P_COMPATIBLE(spec) \
	((spec)->codec_type == VT2002P ||\
	 (spec)->codec_type == VT1812 ||\
	 (spec)->codec_type == VT1802)

90
struct via_spec {
91 92
	struct hda_gen_spec gen;

93
	/* codec parameterization */
94
	const struct snd_kcontrol_new *mixers[6];
95 96
	unsigned int num_mixers;

97
	const struct hda_verb *init_verbs[5];
98 99 100
	unsigned int num_iverbs;

	/* HP mode source */
L
Lydia Wang 已提交
101
	unsigned int dmic_enabled;
102
	unsigned int no_pin_power_ctl;
103 104
	enum VIA_HDA_CODEC codec_type;

105 106 107
	/* analog low-power control */
	bool alc_mode;

108
	/* work to check hp jack state */
109
	int hp_work_active;
110
	int vt1708_jack_detect;
111 112

	void (*set_widgets_power_state)(struct hda_codec *codec);
113
	unsigned int dac_stream_tag[4];
114 115
};

116
static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
117 118 119 120 121 122
static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
				  struct hda_codec *codec,
				  struct snd_pcm_substream *substream,
				  int action);

static struct via_spec *via_new_spec(struct hda_codec *codec)
123 124 125 126 127 128 129 130
{
	struct via_spec *spec;

	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
	if (spec == NULL)
		return NULL;

	codec->spec = spec;
131
	snd_hda_gen_spec_init(&spec->gen);
132 133 134 135
	spec->codec_type = get_codec_type(codec);
	/* VT1708BCE & VT1708S are almost same */
	if (spec->codec_type == VT1708BCE)
		spec->codec_type = VT1708S;
136
	spec->no_pin_power_ctl = 1;
137
	spec->gen.indep_hp = 1;
138
	spec->gen.keep_eapd_on = 1;
139
	spec->gen.pcm_playback_hook = via_playback_pcm_hook;
140
	spec->gen.add_stereo_mix_input = HDA_HINT_STEREO_MIX_AUTO;
141 142 143
	return spec;
}

144
static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
145
{
146
	u32 vendor_id = codec->vendor_id;
147 148 149 150 151 152 153 154 155 156 157 158 159
	u16 ven_id = vendor_id >> 16;
	u16 dev_id = vendor_id & 0xffff;
	enum VIA_HDA_CODEC codec_type;

	/* get codec type */
	if (ven_id != 0x1106)
		codec_type = UNKNOWN;
	else if (dev_id >= 0x1708 && dev_id <= 0x170b)
		codec_type = VT1708;
	else if (dev_id >= 0xe710 && dev_id <= 0xe713)
		codec_type = VT1709_10CH;
	else if (dev_id >= 0xe714 && dev_id <= 0xe717)
		codec_type = VT1709_6CH;
160
	else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
161
		codec_type = VT1708B_8CH;
162 163 164
		if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
			codec_type = VT1708BCE;
	} else if (dev_id >= 0xe724 && dev_id <= 0xe727)
165 166 167 168 169 170 171
		codec_type = VT1708B_4CH;
	else if ((dev_id & 0xfff) == 0x397
		 && (dev_id >> 12) < 8)
		codec_type = VT1708S;
	else if ((dev_id & 0xfff) == 0x398
		 && (dev_id >> 12) < 8)
		codec_type = VT1702;
L
Lydia Wang 已提交
172 173 174
	else if ((dev_id & 0xfff) == 0x428
		 && (dev_id >> 12) < 8)
		codec_type = VT1718S;
L
Lydia Wang 已提交
175 176
	else if (dev_id == 0x0433 || dev_id == 0xa721)
		codec_type = VT1716S;
177 178
	else if (dev_id == 0x0441 || dev_id == 0x4441)
		codec_type = VT1718S;
L
Lydia Wang 已提交
179 180
	else if (dev_id == 0x0438 || dev_id == 0x4438)
		codec_type = VT2002P;
L
Lydia Wang 已提交
181 182
	else if (dev_id == 0x0448)
		codec_type = VT1812;
183 184
	else if (dev_id == 0x0440)
		codec_type = VT1708S;
185 186
	else if ((dev_id & 0xfff) == 0x446)
		codec_type = VT1802;
187 188
	else if (dev_id == 0x4760)
		codec_type = VT1705CF;
189 190
	else if (dev_id == 0x4761 || dev_id == 0x4762)
		codec_type = VT1808;
191 192 193 194 195
	else
		codec_type = UNKNOWN;
	return codec_type;
};

196 197
static void analog_low_current_mode(struct hda_codec *codec);
static bool is_aa_path_mute(struct hda_codec *codec);
198

199 200 201 202
#define hp_detect_with_aa(codec) \
	(snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
	 !is_aa_path_mute(codec))

203
static void vt1708_stop_hp_work(struct hda_codec *codec)
204
{
205 206
	struct via_spec *spec = codec->spec;
	if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
207
		return;
208
	if (spec->hp_work_active) {
209
		snd_hda_codec_write(codec, 0x1, 0, 0xf81, 1);
210
		codec->jackpoll_interval = 0;
211 212
		cancel_delayed_work_sync(&codec->jackpoll_work);
		spec->hp_work_active = false;
213
	}
214 215
}

216
static void vt1708_update_hp_work(struct hda_codec *codec)
217
{
218 219
	struct via_spec *spec = codec->spec;
	if (spec->codec_type != VT1708 || !spec->gen.autocfg.hp_outs)
220
		return;
221
	if (spec->vt1708_jack_detect) {
222
		if (!spec->hp_work_active) {
223 224
			codec->jackpoll_interval = msecs_to_jiffies(100);
			snd_hda_codec_write(codec, 0x1, 0, 0xf81, 0);
225
			schedule_delayed_work(&codec->jackpoll_work, 0);
226
			spec->hp_work_active = true;
227
		}
228 229
	} else if (!hp_detect_with_aa(codec))
		vt1708_stop_hp_work(codec);
230
}
231

232 233
static void set_widgets_power_state(struct hda_codec *codec)
{
234 235 236 237
#if 0 /* FIXME: the assumed connections don't match always with the
       * actual routes by the generic parser, so better to disable
       * the control for safety.
       */
238 239 240
	struct via_spec *spec = codec->spec;
	if (spec->set_widgets_power_state)
		spec->set_widgets_power_state(codec);
241
#endif
242
}
L
Lydia Wang 已提交
243

244 245 246
static void update_power_state(struct hda_codec *codec, hda_nid_t nid,
			       unsigned int parm)
{
247
	if (snd_hda_check_power_state(codec, nid, parm))
248 249 250 251
		return;
	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
}

252 253 254 255 256
static void update_conv_power_state(struct hda_codec *codec, hda_nid_t nid,
			       unsigned int parm, unsigned int index)
{
	struct via_spec *spec = codec->spec;
	unsigned int format;
257 258

	if (snd_hda_check_power_state(codec, nid, parm))
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
		return;
	format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
	if (format && (spec->dac_stream_tag[index] != format))
		spec->dac_stream_tag[index] = format;

	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
	if (parm == AC_PWRST_D0) {
		format = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONV, 0);
		if (!format && (spec->dac_stream_tag[index] != format))
			snd_hda_codec_write(codec, nid, 0,
						  AC_VERB_SET_CHANNEL_STREAMID,
						  spec->dac_stream_tag[index]);
	}
}

274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
static bool smart51_enabled(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	return spec->gen.ext_channel_count > 2;
}

static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
{
	struct via_spec *spec = codec->spec;
	int i;

	for (i = 0; i < spec->gen.multi_ios; i++)
		if (spec->gen.multi_io[i].pin == pin)
			return true;
	return false;
}

291 292 293 294 295 296 297 298
static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
				unsigned int *affected_parm)
{
	unsigned parm;
	unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
	unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
		>> AC_DEFCFG_MISC_SHIFT
		& AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
L
Lydia Wang 已提交
299
	struct via_spec *spec = codec->spec;
300 301 302 303 304
	unsigned present = 0;

	no_presence |= spec->no_pin_power_ctl;
	if (!no_presence)
		present = snd_hda_jack_detect(codec, nid);
305
	if ((smart51_enabled(codec) && is_smart51_pins(codec, nid))
L
Lydia Wang 已提交
306 307
	    || ((no_presence || present)
		&& get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
308 309 310 311 312
		*affected_parm = AC_PWRST_D0; /* if it's connected */
		parm = AC_PWRST_D0;
	} else
		parm = AC_PWRST_D3;

313
	update_power_state(codec, nid, parm);
314 315
}

316 317 318
static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
				  struct snd_ctl_elem_info *uinfo)
{
319
	return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
}

static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
				 struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct via_spec *spec = codec->spec;
	ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
	return 0;
}

static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
				 struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct via_spec *spec = codec->spec;
	unsigned int val = !ucontrol->value.enumerated.item[0];

	if (val == spec->no_pin_power_ctl)
		return 0;
	spec->no_pin_power_ctl = val;
	set_widgets_power_state(codec);
342
	analog_low_current_mode(codec);
343 344 345
	return 1;
}

346 347
static const struct snd_kcontrol_new via_pin_power_ctl_enum[] = {
	{
348 349 350 351 352
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	.name = "Dynamic Power-Control",
	.info = via_pin_power_ctl_info,
	.get = via_pin_power_ctl_get,
	.put = via_pin_power_ctl_put,
353 354
	},
	{} /* terminator */
355 356 357
};


358 359
/* check AA path's mute status */
static bool is_aa_path_mute(struct hda_codec *codec)
360
{
361
	struct via_spec *spec = codec->spec;
362
	const struct hda_amp_list *p;
363
	int ch, v;
364

365 366 367 368
	p = spec->gen.loopback.amplist;
	if (!p)
		return true;
	for (; p->nid; p++) {
369 370 371 372 373 374
		for (ch = 0; ch < 2; ch++) {
			v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
						   p->idx);
			if (!(v & HDA_AMP_MUTE) && v > 0)
				return false;
		}
375
	}
376
	return true;
377 378
}

379 380
/* enter/exit analog low-current mode */
static void __analog_low_current_mode(struct hda_codec *codec, bool force)
381 382
{
	struct via_spec *spec = codec->spec;
383 384
	bool enable;
	unsigned int verb, parm;
385

386 387 388 389 390
	if (spec->no_pin_power_ctl)
		enable = false;
	else
		enable = is_aa_path_mute(codec) && !spec->gen.active_streams;
	if (enable == spec->alc_mode && !force)
391
		return;
392
	spec->alc_mode = enable;
393

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
	/* decide low current mode's verb & parameter */
	switch (spec->codec_type) {
	case VT1708B_8CH:
	case VT1708B_4CH:
		verb = 0xf70;
		parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
		break;
	case VT1708S:
	case VT1718S:
	case VT1716S:
		verb = 0xf73;
		parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
		break;
	case VT1702:
		verb = 0xf73;
		parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
		break;
	case VT2002P:
	case VT1812:
	case VT1802:
		verb = 0xf93;
		parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
		break;
	case VT1705CF:
	case VT1808:
		verb = 0xf82;
		parm = enable ? 0x00 : 0xe0;  /* 0x00: 4/40x, 0xe0: 1x */
		break;
	default:
		return;		/* other codecs are not supported */
424 425
	}
	/* send verb */
426
	snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
427 428
}

429 430 431 432
static void analog_low_current_mode(struct hda_codec *codec)
{
	return __analog_low_current_mode(codec, false);
}
433

434
static int via_build_controls(struct hda_codec *codec)
435 436
{
	struct via_spec *spec = codec->spec;
437
	int err, i;
438

439
	err = snd_hda_gen_build_controls(codec);
440 441
	if (err < 0)
		return err;
442

443 444
	if (spec->set_widgets_power_state)
		spec->mixers[spec->num_mixers++] = via_pin_power_ctl_enum;
445

446 447 448 449 450
	for (i = 0; i < spec->num_mixers; i++) {
		err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
		if (err < 0)
			return err;
	}
451 452 453 454

	return 0;
}

455 456 457 458
static void via_playback_pcm_hook(struct hda_pcm_stream *hinfo,
				  struct hda_codec *codec,
				  struct snd_pcm_substream *substream,
				  int action)
459
{
460 461
	analog_low_current_mode(codec);
	vt1708_update_hp_work(codec);
462 463
}

464
static void via_free(struct hda_codec *codec)
465
{
466
	vt1708_stop_hp_work(codec);
467
	snd_hda_gen_free(codec);
468 469
}

470 471
#ifdef CONFIG_PM
static int via_suspend(struct hda_codec *codec)
472 473
{
	struct via_spec *spec = codec->spec;
474
	vt1708_stop_hp_work(codec);
475

476 477 478
	/* Fix pop noise on headphones */
	if (spec->codec_type == VT1802)
		snd_hda_shutup_pins(codec);
479

480 481
	return 0;
}
482
#endif
483

484 485
#ifdef CONFIG_PM
static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
486 487
{
	struct via_spec *spec = codec->spec;
488 489 490 491 492 493
	set_widgets_power_state(codec);
	analog_low_current_mode(codec);
	vt1708_update_hp_work(codec);
	return snd_hda_check_amp_list_power(codec, &spec->gen.loopback, nid);
}
#endif
494

495 496
/*
 */
497

498
static int via_init(struct hda_codec *codec);
499

500 501 502 503 504 505 506 507 508 509 510
static const struct hda_codec_ops via_patch_ops = {
	.build_controls = via_build_controls,
	.build_pcms = snd_hda_gen_build_pcms,
	.init = via_init,
	.free = via_free,
	.unsol_event = snd_hda_jack_unsol_event,
#ifdef CONFIG_PM
	.suspend = via_suspend,
	.check_power_status = via_check_power_status,
#endif
};
511

512

513 514 515 516 517
static const struct hda_verb vt1708_init_verbs[] = {
	/* power down jack detect function */
	{0x1, 0xf81, 0x1},
	{ }
};
518 519 520 521 522
static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
{
	unsigned int def_conf;
	unsigned char seqassoc;

523
	def_conf = snd_hda_codec_get_pincfg(codec, nid);
524 525
	seqassoc = (unsigned char) get_defcfg_association(def_conf);
	seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
526 527 528 529
	if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
	    && (seqassoc == 0xf0 || seqassoc == 0xff)) {
		def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
		snd_hda_codec_set_pincfg(codec, nid, def_conf);
530 531 532 533 534
	}

	return;
}

535
static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
536 537 538 539 540 541 542
				     struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct via_spec *spec = codec->spec;

	if (spec->codec_type != VT1708)
		return 0;
543
	ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
544 545 546
	return 0;
}

547
static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
548 549 550 551
				     struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct via_spec *spec = codec->spec;
552
	int val;
553 554 555

	if (spec->codec_type != VT1708)
		return 0;
556 557 558 559
	val = !!ucontrol->value.integer.value[0];
	if (spec->vt1708_jack_detect == val)
		return 0;
	spec->vt1708_jack_detect = val;
560
	vt1708_update_hp_work(codec);
561
	return 1;
562 563
}

564 565
static const struct snd_kcontrol_new vt1708_jack_detect_ctl[] = {
	{
566 567 568 569 570 571
	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	.name = "Jack Detect",
	.count = 1,
	.info = snd_ctl_boolean_mono_info,
	.get = vt1708_jack_detect_get,
	.put = vt1708_jack_detect_put,
572 573
	},
	{} /* terminator */
574 575
};

576 577
static void via_jack_powerstate_event(struct hda_codec *codec,
				      struct hda_jack_callback *tbl)
578 579 580 581
{
	set_widgets_power_state(codec);
}

582
static void via_set_jack_unsol_events(struct hda_codec *codec)
583 584
{
	struct via_spec *spec = codec->spec;
585 586
	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
	hda_nid_t pin;
587 588 589
	int i;

	for (i = 0; i < cfg->line_outs; i++) {
590
		pin = cfg->line_out_pins[i];
591
		if (pin && is_jack_detectable(codec, pin))
592 593
			snd_hda_jack_detect_enable_callback(codec, pin,
							    via_jack_powerstate_event);
594 595 596
	}

	for (i = 0; i < cfg->num_inputs; i++) {
597
		pin = cfg->line_out_pins[i];
598
		if (pin && is_jack_detectable(codec, pin))
599
			snd_hda_jack_detect_enable_callback(codec, pin,
600
							    via_jack_powerstate_event);
601 602 603
	}
}

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
static const struct badness_table via_main_out_badness = {
	.no_primary_dac = 0x10000,
	.no_dac = 0x4000,
	.shared_primary = 0x10000,
	.shared_surr = 0x20,
	.shared_clfe = 0x20,
	.shared_surr_main = 0x20,
};
static const struct badness_table via_extra_out_badness = {
	.no_primary_dac = 0x4000,
	.no_dac = 0x4000,
	.shared_primary = 0x12,
	.shared_surr = 0x20,
	.shared_clfe = 0x20,
	.shared_surr_main = 0x10,
};

621 622 623 624 625
static int via_parse_auto_config(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int err;

626 627 628
	spec->gen.main_out_badness = &via_main_out_badness;
	spec->gen.extra_out_badness = &via_extra_out_badness;

629 630 631 632 633 634 635 636 637 638 639 640
	err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL, 0);
	if (err < 0)
		return err;

	err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
	if (err < 0)
		return err;

	via_set_jack_unsol_events(codec);
	return 0;
}

641 642 643 644 645 646 647
static int via_init(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int i;

	for (i = 0; i < spec->num_iverbs; i++)
		snd_hda_sequence_write(codec, spec->init_verbs[i]);
L
Lydia Wang 已提交
648

649 650 651 652
	/* init power states */
	set_widgets_power_state(codec);
	__analog_low_current_mode(codec, true);

653
	snd_hda_gen_init(codec);
654

655
	vt1708_update_hp_work(codec);
L
Lydia Wang 已提交
656

657 658 659
	return 0;
}

660 661 662 663 664 665 666 667 668 669 670 671
static int vt1708_build_controls(struct hda_codec *codec)
{
	/* In order not to create "Phantom Jack" controls,
	   temporary enable jackpoll */
	int err;
	int old_interval = codec->jackpoll_interval;
	codec->jackpoll_interval = msecs_to_jiffies(100);
	err = via_build_controls(codec);
	codec->jackpoll_interval = old_interval;
	return err;
}

672
static int vt1708_build_pcms(struct hda_codec *codec)
673 674
{
	struct via_spec *spec = codec->spec;
675 676 677 678 679 680 681 682 683 684
	int i, err;

	err = snd_hda_gen_build_pcms(codec);
	if (err < 0 || codec->vendor_id != 0x11061708)
		return err;

	/* We got noisy outputs on the right channel on VT1708 when
	 * 24bit samples are used.  Until any workaround is found,
	 * disable the 24bit format, so far.
	 */
685 686 687 688
	for (i = 0; i < ARRAY_SIZE(spec->gen.pcm_rec); i++) {
		struct hda_pcm *info = spec->gen.pcm_rec[i];
		if (!info)
			continue;
689 690 691 692 693
		if (!info->stream[SNDRV_PCM_STREAM_PLAYBACK].substreams ||
		    info->pcm_type != HDA_PCM_TYPE_AUDIO)
			continue;
		info->stream[SNDRV_PCM_STREAM_PLAYBACK].formats =
			SNDRV_PCM_FMTBIT_S16_LE;
694
	}
695

696
	return 0;
697 698
}

699 700 701 702 703 704
static int patch_vt1708(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
705
	spec = via_new_spec(codec);
706 707 708
	if (spec == NULL)
		return -ENOMEM;

709 710 711 712 713 714 715 716 717
	spec->gen.mixer_nid = 0x17;

	/* set jackpoll_interval while parsing the codec */
	codec->jackpoll_interval = msecs_to_jiffies(100);
	spec->vt1708_jack_detect = 1;

	/* don't support the input jack switching due to lack of unsol event */
	/* (it may work with polling, though, but it needs testing) */
	spec->gen.suppress_auto_mic = 1;
718 719
	/* Some machines show the broken speaker mute */
	spec->gen.auto_mute_via_amp = 1;
720

721 722 723 724
	/* Add HP and CD pin config connect bit re-config action */
	vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
	vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);

725
	/* automatic parse from the BIOS config */
726
	err = via_parse_auto_config(codec);
727 728 729 730 731
	if (err < 0) {
		via_free(codec);
		return err;
	}

732
	/* add jack detect on/off control */
733
	spec->mixers[spec->num_mixers++] = vt1708_jack_detect_ctl;
734

735 736
	spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;

737
	codec->patch_ops = via_patch_ops;
738
	codec->patch_ops.build_controls = vt1708_build_controls;
739 740 741 742
	codec->patch_ops.build_pcms = vt1708_build_pcms;

	/* clear jackpoll_interval again; it's set dynamically */
	codec->jackpoll_interval = 0;
743 744 745 746

	return 0;
}

747
static int patch_vt1709(struct hda_codec *codec)
748 749 750 751 752
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
753
	spec = via_new_spec(codec);
754 755 756
	if (spec == NULL)
		return -ENOMEM;

757
	spec->gen.mixer_nid = 0x18;
758

759
	err = via_parse_auto_config(codec);
760 761 762 763 764 765 766
	if (err < 0) {
		via_free(codec);
		return err;
	}

	codec->patch_ops = via_patch_ops;

767 768 769
	return 0;
}

770 771 772 773 774 775
static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int imux_is_smixer;
	unsigned int parm;
	int is_8ch = 0;
776 777
	if ((spec->codec_type != VT1708B_4CH) &&
	    (codec->vendor_id != 0x11064397))
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
		is_8ch = 1;

	/* SW0 (17h) = stereo mixer */
	imux_is_smixer =
	(snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
	 == ((spec->codec_type == VT1708S) ? 5 : 0));
	/* inputs */
	/* PW 1/2/5 (1ah/1bh/1eh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x1a, &parm);
	set_pin_power_state(codec, 0x1b, &parm);
	set_pin_power_state(codec, 0x1e, &parm);
	if (imux_is_smixer)
		parm = AC_PWRST_D0;
	/* SW0 (17h), AIW 0/1 (13h/14h) */
793 794 795
	update_power_state(codec, 0x17, parm);
	update_power_state(codec, 0x13, parm);
	update_power_state(codec, 0x14, parm);
796 797 798 799 800

	/* outputs */
	/* PW0 (19h), SW1 (18h), AOW1 (11h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x19, &parm);
801
	if (smart51_enabled(codec))
802
		set_pin_power_state(codec, 0x1b, &parm);
803 804
	update_power_state(codec, 0x18, parm);
	update_power_state(codec, 0x11, parm);
805 806 807 808 809

	/* PW6 (22h), SW2 (26h), AOW2 (24h) */
	if (is_8ch) {
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x22, &parm);
810
		if (smart51_enabled(codec))
811
			set_pin_power_state(codec, 0x1a, &parm);
812 813
		update_power_state(codec, 0x26, parm);
		update_power_state(codec, 0x24, parm);
814 815 816 817
	} else if (codec->vendor_id == 0x11064397) {
		/* PW7(23h), SW2(27h), AOW2(25h) */
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x23, &parm);
818
		if (smart51_enabled(codec))
819
			set_pin_power_state(codec, 0x1a, &parm);
820 821
		update_power_state(codec, 0x27, parm);
		update_power_state(codec, 0x25, parm);
822 823 824 825 826 827 828 829 830 831 832
	}

	/* PW 3/4/7 (1ch/1dh/23h) */
	parm = AC_PWRST_D3;
	/* force to D0 for internal Speaker */
	set_pin_power_state(codec, 0x1c, &parm);
	set_pin_power_state(codec, 0x1d, &parm);
	if (is_8ch)
		set_pin_power_state(codec, 0x23, &parm);

	/* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
833 834
	update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
	update_power_state(codec, 0x10, parm);
835
	if (is_8ch) {
836 837
		update_power_state(codec, 0x25, parm);
		update_power_state(codec, 0x27, parm);
838
	} else if (codec->vendor_id == 0x11064397 && spec->gen.indep_hp_enabled)
839
		update_power_state(codec, 0x25, parm);
840 841
}

842
static int patch_vt1708S(struct hda_codec *codec);
843
static int patch_vt1708B(struct hda_codec *codec)
844 845 846 847
{
	struct via_spec *spec;
	int err;

848 849
	if (get_codec_type(codec) == VT1708BCE)
		return patch_vt1708S(codec);
850

851
	/* create a codec specific record */
852
	spec = via_new_spec(codec);
853 854 855
	if (spec == NULL)
		return -ENOMEM;

856
	spec->gen.mixer_nid = 0x16;
857

858
	/* automatic parse from the BIOS config */
859
	err = via_parse_auto_config(codec);
860 861 862 863 864 865 866
	if (err < 0) {
		via_free(codec);
		return err;
	}

	codec->patch_ops = via_patch_ops;

867 868
	spec->set_widgets_power_state =  set_widgets_power_state_vt1708B;

869 870 871
	return 0;
}

872
/* Patch for VT1708S */
873
static const struct hda_verb vt1708S_init_verbs[] = {
874 875
	/* Enable Mic Boost Volume backdoor */
	{0x1, 0xf98, 0x1},
876 877
	/* don't bybass mixer */
	{0x1, 0xf88, 0xc0},
878 879 880
	{ }
};

881 882 883
static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
			       int offset, int num_steps, int step_size)
{
884 885
	snd_hda_override_wcaps(codec, pin,
			       get_wcaps(codec, pin) | AC_WCAP_IN_AMP);
886 887 888 889 890 891 892
	snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
				  (offset << AC_AMPCAP_OFFSET_SHIFT) |
				  (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
				  (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
				  (0 << AC_AMPCAP_MUTE_SHIFT));
}

893 894 895 896 897 898
static int patch_vt1708S(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
899
	spec = via_new_spec(codec);
900 901 902
	if (spec == NULL)
		return -ENOMEM;

903
	spec->gen.mixer_nid = 0x16;
904 905
	override_mic_boost(codec, 0x1a, 0, 3, 40);
	override_mic_boost(codec, 0x1e, 0, 3, 40);
906

907 908 909 910
	/* correct names for VT1708BCE */
	if (get_codec_type(codec) == VT1708BCE)	{
		kfree(codec->chip_name);
		codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
911 912
		snprintf(codec->card->mixername,
			 sizeof(codec->card->mixername),
913
			 "%s %s", codec->vendor_name, codec->chip_name);
914
	}
915 916 917 918
	/* correct names for VT1705 */
	if (codec->vendor_id == 0x11064397)	{
		kfree(codec->chip_name);
		codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
919 920
		snprintf(codec->card->mixername,
			 sizeof(codec->card->mixername),
921 922
			 "%s %s", codec->vendor_name, codec->chip_name);
	}
923 924 925 926 927 928 929 930 931 932 933 934

	/* automatic parse from the BIOS config */
	err = via_parse_auto_config(codec);
	if (err < 0) {
		via_free(codec);
		return err;
	}

	spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;

	codec->patch_ops = via_patch_ops;

935
	spec->set_widgets_power_state =  set_widgets_power_state_vt1708B;
936 937 938 939 940
	return 0;
}

/* Patch for VT1702 */

941
static const struct hda_verb vt1702_init_verbs[] = {
942 943 944 945
	/* mixer enable */
	{0x1, 0xF88, 0x3},
	/* GPIO 0~2 */
	{0x1, 0xF82, 0x3F},
946 947 948
	{ }
};

949 950 951 952 953 954 955 956 957 958 959 960 961 962
static void set_widgets_power_state_vt1702(struct hda_codec *codec)
{
	int imux_is_smixer =
	snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
	unsigned int parm;
	/* inputs */
	/* PW 1/2/5 (14h/15h/18h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x14, &parm);
	set_pin_power_state(codec, 0x15, &parm);
	set_pin_power_state(codec, 0x18, &parm);
	if (imux_is_smixer)
		parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
	/* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
963 964 965 966
	update_power_state(codec, 0x13, parm);
	update_power_state(codec, 0x12, parm);
	update_power_state(codec, 0x1f, parm);
	update_power_state(codec, 0x20, parm);
967 968 969 970 971 972 973

	/* outputs */
	/* PW 3/4 (16h/17h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x17, &parm);
	set_pin_power_state(codec, 0x16, &parm);
	/* MW0 (1ah), AOW 0/1 (10h/1dh) */
974 975 976
	update_power_state(codec, 0x1a, imux_is_smixer ? AC_PWRST_D0 : parm);
	update_power_state(codec, 0x10, parm);
	update_power_state(codec, 0x1d, parm);
977 978
}

979 980 981 982 983 984
static int patch_vt1702(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
985
	spec = via_new_spec(codec);
986 987 988
	if (spec == NULL)
		return -ENOMEM;

989
	spec->gen.mixer_nid = 0x1a;
990

991 992 993 994 995 996 997
	/* limit AA path volume to 0 dB */
	snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
				  (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
				  (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
				  (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
				  (1 << AC_AMPCAP_MUTE_SHIFT));

998
	/* automatic parse from the BIOS config */
999
	err = via_parse_auto_config(codec);
1000 1001 1002 1003 1004
	if (err < 0) {
		via_free(codec);
		return err;
	}

1005
	spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
1006 1007 1008

	codec->patch_ops = via_patch_ops;

1009
	spec->set_widgets_power_state =  set_widgets_power_state_vt1702;
1010 1011 1012
	return 0;
}

L
Lydia Wang 已提交
1013 1014
/* Patch for VT1718S */

1015
static const struct hda_verb vt1718S_init_verbs[] = {
1016 1017
	/* Enable MW0 adjust Gain 5 */
	{0x1, 0xfb2, 0x10},
L
Lydia Wang 已提交
1018 1019
	/* Enable Boost Volume backdoor */
	{0x1, 0xf88, 0x8},
1020

L
Lydia Wang 已提交
1021 1022 1023
	{ }
};

1024 1025 1026 1027
static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int imux_is_smixer;
1028
	unsigned int parm, parm2;
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040
	/* MUX6 (1eh) = stereo mixer */
	imux_is_smixer =
	snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
	/* inputs */
	/* PW 5/6/7 (29h/2ah/2bh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x29, &parm);
	set_pin_power_state(codec, 0x2a, &parm);
	set_pin_power_state(codec, 0x2b, &parm);
	if (imux_is_smixer)
		parm = AC_PWRST_D0;
	/* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
1041 1042 1043 1044
	update_power_state(codec, 0x1e, parm);
	update_power_state(codec, 0x1f, parm);
	update_power_state(codec, 0x10, parm);
	update_power_state(codec, 0x11, parm);
1045 1046 1047 1048 1049

	/* outputs */
	/* PW3 (27h), MW2 (1ah), AOW3 (bh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x27, &parm);
1050
	update_power_state(codec, 0x1a, parm);
1051
	parm2 = parm; /* for pin 0x0b */
1052 1053 1054 1055

	/* PW2 (26h), AOW2 (ah) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x26, &parm);
1056
	if (smart51_enabled(codec))
1057
		set_pin_power_state(codec, 0x2b, &parm);
1058
	update_power_state(codec, 0xa, parm);
1059 1060 1061 1062

	/* PW0 (24h), AOW0 (8h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x24, &parm);
1063
	if (!spec->gen.indep_hp_enabled) /* check for redirected HP */
1064
		set_pin_power_state(codec, 0x28, &parm);
1065
	update_power_state(codec, 0x8, parm);
1066
	if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1067 1068
		parm = parm2;
	update_power_state(codec, 0xb, parm);
1069
	/* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
1070
	update_power_state(codec, 0x21, imux_is_smixer ? AC_PWRST_D0 : parm);
1071 1072 1073 1074

	/* PW1 (25h), AOW1 (9h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x25, &parm);
1075
	if (smart51_enabled(codec))
1076
		set_pin_power_state(codec, 0x2a, &parm);
1077
	update_power_state(codec, 0x9, parm);
1078

1079
	if (spec->gen.indep_hp_enabled) {
1080 1081 1082
		/* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x28, &parm);
1083 1084 1085
		update_power_state(codec, 0x1b, parm);
		update_power_state(codec, 0x34, parm);
		update_power_state(codec, 0xc, parm);
1086 1087 1088
	}
}

1089 1090 1091 1092 1093 1094 1095 1096 1097 1098
/* Add a connection to the primary DAC from AA-mixer for some codecs
 * This isn't listed from the raw info, but the chip has a secret connection.
 */
static int add_secret_dac_path(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int i, nums;
	hda_nid_t conn[8];
	hda_nid_t nid;

1099
	if (!spec->gen.mixer_nid)
1100
		return 0;
1101
	nums = snd_hda_get_connections(codec, spec->gen.mixer_nid, conn,
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
				       ARRAY_SIZE(conn) - 1);
	for (i = 0; i < nums; i++) {
		if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
			return 0;
	}

	/* find the primary DAC and add to the connection list */
	nid = codec->start_nid;
	for (i = 0; i < codec->num_nodes; i++, nid++) {
		unsigned int caps = get_wcaps(codec, nid);
		if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
		    !(caps & AC_WCAP_DIGITAL)) {
			conn[nums++] = nid;
			return snd_hda_override_conn_list(codec,
1116
							  spec->gen.mixer_nid,
1117 1118 1119 1120 1121 1122 1123
							  nums, conn);
		}
	}
	return 0;
}


L
Lydia Wang 已提交
1124 1125 1126 1127 1128 1129
static int patch_vt1718S(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
1130
	spec = via_new_spec(codec);
L
Lydia Wang 已提交
1131 1132 1133
	if (spec == NULL)
		return -ENOMEM;

1134
	spec->gen.mixer_nid = 0x21;
1135 1136
	override_mic_boost(codec, 0x2b, 0, 3, 40);
	override_mic_boost(codec, 0x29, 0, 3, 40);
1137
	add_secret_dac_path(codec);
1138

L
Lydia Wang 已提交
1139
	/* automatic parse from the BIOS config */
1140
	err = via_parse_auto_config(codec);
L
Lydia Wang 已提交
1141 1142 1143 1144 1145
	if (err < 0) {
		via_free(codec);
		return err;
	}

1146
	spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
L
Lydia Wang 已提交
1147 1148 1149

	codec->patch_ops = via_patch_ops;

1150 1151
	spec->set_widgets_power_state =  set_widgets_power_state_vt1718S;

L
Lydia Wang 已提交
1152 1153
	return 0;
}
L
Lydia Wang 已提交
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190

/* Patch for VT1716S */

static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_info *uinfo)
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
	uinfo->count = 1;
	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 1;
	return 0;
}

static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	int index = 0;

	index = snd_hda_codec_read(codec, 0x26, 0,
					       AC_VERB_GET_CONNECT_SEL, 0);
	if (index != -1)
		*ucontrol->value.integer.value = index;

	return 0;
}

static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
			   struct snd_ctl_elem_value *ucontrol)
{
	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
	struct via_spec *spec = codec->spec;
	int index = *ucontrol->value.integer.value;

	snd_hda_codec_write(codec, 0x26, 0,
					       AC_VERB_SET_CONNECT_SEL, index);
	spec->dmic_enabled = index;
1191
	set_widgets_power_state(codec);
L
Lydia Wang 已提交
1192 1193 1194
	return 1;
}

1195
static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
L
Lydia Wang 已提交
1196 1197 1198 1199
	HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
	{
	 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
	 .name = "Digital Mic Capture Switch",
1200
	 .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
L
Lydia Wang 已提交
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
	 .count = 1,
	 .info = vt1716s_dmic_info,
	 .get = vt1716s_dmic_get,
	 .put = vt1716s_dmic_put,
	 },
	{}			/* end */
};


/* mono-out mixer elements */
1211
static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
L
Lydia Wang 已提交
1212 1213 1214 1215
	HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
	{ } /* end */
};

1216
static const struct hda_verb vt1716S_init_verbs[] = {
L
Lydia Wang 已提交
1217 1218 1219 1220 1221 1222 1223 1224 1225
	/* Enable Boost Volume backdoor */
	{0x1, 0xf8a, 0x80},
	/* don't bybass mixer */
	{0x1, 0xf88, 0xc0},
	/* Enable mono output */
	{0x1, 0xf90, 0x08},
	{ }
};

1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int imux_is_smixer;
	unsigned int parm;
	unsigned int mono_out, present;
	/* SW0 (17h) = stereo mixer */
	imux_is_smixer =
	(snd_hda_codec_read(codec, 0x17, 0,
			    AC_VERB_GET_CONNECT_SEL, 0x00) ==  5);
	/* inputs */
	/* PW 1/2/5 (1ah/1bh/1eh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x1a, &parm);
	set_pin_power_state(codec, 0x1b, &parm);
	set_pin_power_state(codec, 0x1e, &parm);
	if (imux_is_smixer)
		parm = AC_PWRST_D0;
	/* SW0 (17h), AIW0(13h) */
1245 1246
	update_power_state(codec, 0x17, parm);
	update_power_state(codec, 0x13, parm);
1247 1248 1249 1250 1251 1252 1253

	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x1e, &parm);
	/* PW11 (22h) */
	if (spec->dmic_enabled)
		set_pin_power_state(codec, 0x22, &parm);
	else
1254
		update_power_state(codec, 0x22, AC_PWRST_D3);
1255 1256

	/* SW2(26h), AIW1(14h) */
1257 1258
	update_power_state(codec, 0x26, parm);
	update_power_state(codec, 0x14, parm);
1259 1260 1261 1262 1263 1264

	/* outputs */
	/* PW0 (19h), SW1 (18h), AOW1 (11h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x19, &parm);
	/* Smart 5.1 PW2(1bh) */
1265
	if (smart51_enabled(codec))
1266
		set_pin_power_state(codec, 0x1b, &parm);
1267 1268
	update_power_state(codec, 0x18, parm);
	update_power_state(codec, 0x11, parm);
1269 1270 1271 1272 1273

	/* PW7 (23h), SW3 (27h), AOW3 (25h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x23, &parm);
	/* Smart 5.1 PW1(1ah) */
1274
	if (smart51_enabled(codec))
1275
		set_pin_power_state(codec, 0x1a, &parm);
1276
	update_power_state(codec, 0x27, parm);
1277 1278

	/* Smart 5.1 PW5(1eh) */
1279
	if (smart51_enabled(codec))
1280
		set_pin_power_state(codec, 0x1e, &parm);
1281
	update_power_state(codec, 0x25, parm);
1282 1283 1284 1285 1286 1287 1288 1289 1290

	/* Mono out */
	/* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
	present = snd_hda_jack_detect(codec, 0x1c);

	if (present)
		mono_out = 0;
	else {
		present = snd_hda_jack_detect(codec, 0x1d);
1291
		if (!spec->gen.indep_hp_enabled && present)
1292 1293 1294 1295 1296
			mono_out = 0;
		else
			mono_out = 1;
	}
	parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
1297 1298 1299
	update_power_state(codec, 0x28, parm);
	update_power_state(codec, 0x29, parm);
	update_power_state(codec, 0x2a, parm);
1300 1301 1302 1303 1304 1305

	/* PW 3/4 (1ch/1dh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x1c, &parm);
	set_pin_power_state(codec, 0x1d, &parm);
	/* HP Independent Mode, power on AOW3 */
1306
	if (spec->gen.indep_hp_enabled)
1307
		update_power_state(codec, 0x25, parm);
1308 1309 1310

	/* force to D0 for internal Speaker */
	/* MW0 (16h), AOW0 (10h) */
1311 1312
	update_power_state(codec, 0x16, imux_is_smixer ? AC_PWRST_D0 : parm);
	update_power_state(codec, 0x10, mono_out ? AC_PWRST_D0 : parm);
1313 1314
}

L
Lydia Wang 已提交
1315 1316 1317 1318 1319 1320
static int patch_vt1716S(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
1321
	spec = via_new_spec(codec);
L
Lydia Wang 已提交
1322 1323 1324
	if (spec == NULL)
		return -ENOMEM;

1325
	spec->gen.mixer_nid = 0x16;
1326 1327
	override_mic_boost(codec, 0x1a, 0, 3, 40);
	override_mic_boost(codec, 0x1e, 0, 3, 40);
1328

L
Lydia Wang 已提交
1329
	/* automatic parse from the BIOS config */
1330
	err = via_parse_auto_config(codec);
L
Lydia Wang 已提交
1331 1332 1333 1334 1335
	if (err < 0) {
		via_free(codec);
		return err;
	}

1336
	spec->init_verbs[spec->num_iverbs++]  = vt1716S_init_verbs;
L
Lydia Wang 已提交
1337

1338
	spec->mixers[spec->num_mixers++] = vt1716s_dmic_mixer;
L
Lydia Wang 已提交
1339 1340 1341 1342
	spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;

	codec->patch_ops = via_patch_ops;

1343
	spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
L
Lydia Wang 已提交
1344 1345
	return 0;
}
L
Lydia Wang 已提交
1346 1347 1348

/* for vt2002P */

1349
static const struct hda_verb vt2002P_init_verbs[] = {
1350 1351 1352 1353
	/* Class-D speaker related verbs */
	{0x1, 0xfe0, 0x4},
	{0x1, 0xfe9, 0x80},
	{0x1, 0xfe2, 0x22},
L
Lydia Wang 已提交
1354 1355 1356 1357 1358 1359
	/* Enable Boost Volume backdoor */
	{0x1, 0xfb9, 0x24},
	/* Enable AOW0 to MW9 */
	{0x1, 0xfb8, 0x88},
	{ }
};
1360

1361
static const struct hda_verb vt1802_init_verbs[] = {
1362 1363 1364 1365 1366 1367
	/* Enable Boost Volume backdoor */
	{0x1, 0xfb9, 0x24},
	/* Enable AOW0 to MW9 */
	{0x1, 0xfb8, 0x88},
	{ }
};
L
Lydia Wang 已提交
1368

1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int imux_is_smixer;
	unsigned int parm;
	unsigned int present;
	/* MUX9 (1eh) = stereo mixer */
	imux_is_smixer =
	snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
	/* inputs */
	/* PW 5/6/7 (29h/2ah/2bh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x29, &parm);
	set_pin_power_state(codec, 0x2a, &parm);
	set_pin_power_state(codec, 0x2b, &parm);
	parm = AC_PWRST_D0;
	/* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
1386 1387 1388 1389
	update_power_state(codec, 0x1e, parm);
	update_power_state(codec, 0x1f, parm);
	update_power_state(codec, 0x10, parm);
	update_power_state(codec, 0x11, parm);
1390 1391 1392

	/* outputs */
	/* AOW0 (8h)*/
1393
	update_power_state(codec, 0x8, parm);
1394

1395 1396 1397 1398
	if (spec->codec_type == VT1802) {
		/* PW4 (28h), MW4 (18h), MUX4(38h) */
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x28, &parm);
1399 1400
		update_power_state(codec, 0x18, parm);
		update_power_state(codec, 0x38, parm);
1401 1402 1403 1404
	} else {
		/* PW4 (26h), MW4 (1ch), MUX4(37h) */
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x26, &parm);
1405 1406
		update_power_state(codec, 0x1c, parm);
		update_power_state(codec, 0x37, parm);
1407
	}
1408

1409 1410 1411 1412
	if (spec->codec_type == VT1802) {
		/* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x25, &parm);
1413 1414
		update_power_state(codec, 0x15, parm);
		update_power_state(codec, 0x35, parm);
1415 1416 1417 1418
	} else {
		/* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x25, &parm);
1419 1420
		update_power_state(codec, 0x19, parm);
		update_power_state(codec, 0x35, parm);
1421
	}
1422

1423
	if (spec->gen.indep_hp_enabled)
1424
		update_power_state(codec, 0x9, AC_PWRST_D0);
1425 1426 1427 1428 1429 1430 1431 1432

	/* Class-D */
	/* PW0 (24h), MW0(18h/14h), MUX0(34h) */
	present = snd_hda_jack_detect(codec, 0x25);

	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x24, &parm);
	parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1433
	if (spec->codec_type == VT1802)
1434
		update_power_state(codec, 0x14, parm);
1435
	else
1436 1437
		update_power_state(codec, 0x18, parm);
	update_power_state(codec, 0x34, parm);
1438 1439 1440 1441 1442

	/* Mono Out */
	present = snd_hda_jack_detect(codec, 0x26);

	parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
1443 1444
	if (spec->codec_type == VT1802) {
		/* PW15 (33h), MW8(1ch), MUX8(3ch) */
1445 1446 1447
		update_power_state(codec, 0x33, parm);
		update_power_state(codec, 0x1c, parm);
		update_power_state(codec, 0x3c, parm);
1448 1449
	} else {
		/* PW15 (31h), MW8(17h), MUX8(3bh) */
1450 1451 1452
		update_power_state(codec, 0x31, parm);
		update_power_state(codec, 0x17, parm);
		update_power_state(codec, 0x3b, parm);
1453
	}
1454 1455
	/* MW9 (21h) */
	if (imux_is_smixer || !is_aa_path_mute(codec))
1456
		update_power_state(codec, 0x21, AC_PWRST_D0);
1457
	else
1458
		update_power_state(codec, 0x21, AC_PWRST_D3);
1459
}
L
Lydia Wang 已提交
1460

1461 1462 1463 1464 1465
/*
 * pin fix-up
 */
enum {
	VIA_FIXUP_INTMIC_BOOST,
1466
	VIA_FIXUP_ASUS_G75,
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480
};

static void via_fixup_intmic_boost(struct hda_codec *codec,
				  const struct hda_fixup *fix, int action)
{
	if (action == HDA_FIXUP_ACT_PRE_PROBE)
		override_mic_boost(codec, 0x30, 0, 2, 40);
}

static const struct hda_fixup via_fixups[] = {
	[VIA_FIXUP_INTMIC_BOOST] = {
		.type = HDA_FIXUP_FUNC,
		.v.func = via_fixup_intmic_boost,
	},
1481 1482 1483 1484 1485 1486 1487 1488 1489
	[VIA_FIXUP_ASUS_G75] = {
		.type = HDA_FIXUP_PINS,
		.v.pins = (const struct hda_pintbl[]) {
			/* set 0x24 and 0x33 as speakers */
			{ 0x24, 0x991301f0 },
			{ 0x33, 0x991301f1 }, /* subwoofer */
			{ }
		}
	},
1490 1491 1492
};

static const struct snd_pci_quirk vt2002p_fixups[] = {
1493
	SND_PCI_QUIRK(0x1043, 0x1487, "Asus G75", VIA_FIXUP_ASUS_G75),
1494 1495 1496 1497
	SND_PCI_QUIRK(0x1043, 0x8532, "Asus X202E", VIA_FIXUP_INTMIC_BOOST),
	{}
};

1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
/* NIDs 0x24 and 0x33 on VT1802 have connections to non-existing NID 0x3e
 * Replace this with mixer NID 0x1c
 */
static void fix_vt1802_connections(struct hda_codec *codec)
{
	static hda_nid_t conn_24[] = { 0x14, 0x1c };
	static hda_nid_t conn_33[] = { 0x1c };

	snd_hda_override_conn_list(codec, 0x24, ARRAY_SIZE(conn_24), conn_24);
	snd_hda_override_conn_list(codec, 0x33, ARRAY_SIZE(conn_33), conn_33);
}

L
Lydia Wang 已提交
1510 1511 1512 1513 1514 1515 1516
/* patch for vt2002P */
static int patch_vt2002P(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
1517
	spec = via_new_spec(codec);
L
Lydia Wang 已提交
1518 1519 1520
	if (spec == NULL)
		return -ENOMEM;

1521
	spec->gen.mixer_nid = 0x21;
1522 1523
	override_mic_boost(codec, 0x2b, 0, 3, 40);
	override_mic_boost(codec, 0x29, 0, 3, 40);
1524 1525
	if (spec->codec_type == VT1802)
		fix_vt1802_connections(codec);
1526
	add_secret_dac_path(codec);
1527

1528 1529 1530
	snd_hda_pick_fixup(codec, NULL, vt2002p_fixups, via_fixups);
	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);

L
Lydia Wang 已提交
1531
	/* automatic parse from the BIOS config */
1532
	err = via_parse_auto_config(codec);
L
Lydia Wang 已提交
1533 1534 1535 1536 1537
	if (err < 0) {
		via_free(codec);
		return err;
	}

1538
	if (spec->codec_type == VT1802)
1539
		spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
1540
	else
1541
		spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
1542

L
Lydia Wang 已提交
1543 1544
	codec->patch_ops = via_patch_ops;

1545
	spec->set_widgets_power_state =  set_widgets_power_state_vt2002P;
L
Lydia Wang 已提交
1546 1547
	return 0;
}
L
Lydia Wang 已提交
1548 1549 1550

/* for vt1812 */

1551
static const struct hda_verb vt1812_init_verbs[] = {
L
Lydia Wang 已提交
1552 1553 1554 1555 1556 1557 1558
	/* Enable Boost Volume backdoor */
	{0x1, 0xfb9, 0x24},
	/* Enable AOW0 to MW9 */
	{0x1, 0xfb8, 0xa8},
	{ }
};

1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571
static void set_widgets_power_state_vt1812(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	unsigned int parm;
	unsigned int present;
	/* inputs */
	/* PW 5/6/7 (29h/2ah/2bh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x29, &parm);
	set_pin_power_state(codec, 0x2a, &parm);
	set_pin_power_state(codec, 0x2b, &parm);
	parm = AC_PWRST_D0;
	/* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
1572 1573 1574 1575
	update_power_state(codec, 0x1e, parm);
	update_power_state(codec, 0x1f, parm);
	update_power_state(codec, 0x10, parm);
	update_power_state(codec, 0x11, parm);
1576 1577 1578

	/* outputs */
	/* AOW0 (8h)*/
1579
	update_power_state(codec, 0x8, AC_PWRST_D0);
1580 1581 1582 1583

	/* PW4 (28h), MW4 (18h), MUX4(38h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x28, &parm);
1584 1585
	update_power_state(codec, 0x18, parm);
	update_power_state(codec, 0x38, parm);
1586 1587 1588 1589

	/* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x25, &parm);
1590 1591
	update_power_state(codec, 0x15, parm);
	update_power_state(codec, 0x35, parm);
1592
	if (spec->gen.indep_hp_enabled)
1593
		update_power_state(codec, 0x9, AC_PWRST_D0);
1594 1595 1596 1597 1598 1599 1600 1601

	/* Internal Speaker */
	/* PW0 (24h), MW0(14h), MUX0(34h) */
	present = snd_hda_jack_detect(codec, 0x25);

	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x24, &parm);
	if (present) {
1602 1603
		update_power_state(codec, 0x14, AC_PWRST_D3);
		update_power_state(codec, 0x34, AC_PWRST_D3);
1604
	} else {
1605 1606
		update_power_state(codec, 0x14, AC_PWRST_D0);
		update_power_state(codec, 0x34, AC_PWRST_D0);
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
	}


	/* Mono Out */
	/* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
	present = snd_hda_jack_detect(codec, 0x28);

	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x31, &parm);
	if (present) {
1617 1618 1619
		update_power_state(codec, 0x1c, AC_PWRST_D3);
		update_power_state(codec, 0x3c, AC_PWRST_D3);
		update_power_state(codec, 0x3e, AC_PWRST_D3);
1620
	} else {
1621 1622 1623
		update_power_state(codec, 0x1c, AC_PWRST_D0);
		update_power_state(codec, 0x3c, AC_PWRST_D0);
		update_power_state(codec, 0x3e, AC_PWRST_D0);
1624 1625 1626 1627 1628
	}

	/* PW15 (33h), MW15 (1dh), MUX15(3dh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x33, &parm);
1629 1630
	update_power_state(codec, 0x1d, parm);
	update_power_state(codec, 0x3d, parm);
1631 1632

}
L
Lydia Wang 已提交
1633 1634 1635 1636 1637 1638 1639 1640

/* patch for vt1812 */
static int patch_vt1812(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
1641
	spec = via_new_spec(codec);
L
Lydia Wang 已提交
1642 1643 1644
	if (spec == NULL)
		return -ENOMEM;

1645
	spec->gen.mixer_nid = 0x21;
1646 1647
	override_mic_boost(codec, 0x2b, 0, 3, 40);
	override_mic_boost(codec, 0x29, 0, 3, 40);
1648
	add_secret_dac_path(codec);
1649

L
Lydia Wang 已提交
1650
	/* automatic parse from the BIOS config */
1651
	err = via_parse_auto_config(codec);
L
Lydia Wang 已提交
1652 1653 1654 1655 1656
	if (err < 0) {
		via_free(codec);
		return err;
	}

1657
	spec->init_verbs[spec->num_iverbs++]  = vt1812_init_verbs;
L
Lydia Wang 已提交
1658 1659 1660

	codec->patch_ops = via_patch_ops;

1661
	spec->set_widgets_power_state =  set_widgets_power_state_vt1812;
L
Lydia Wang 已提交
1662 1663 1664
	return 0;
}

1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714
/* patch for vt3476 */

static const struct hda_verb vt3476_init_verbs[] = {
	/* Enable DMic 8/16/32K */
	{0x1, 0xF7B, 0x30},
	/* Enable Boost Volume backdoor */
	{0x1, 0xFB9, 0x20},
	/* Enable AOW-MW9 path */
	{0x1, 0xFB8, 0x10},
	{ }
};

static void set_widgets_power_state_vt3476(struct hda_codec *codec)
{
	struct via_spec *spec = codec->spec;
	int imux_is_smixer;
	unsigned int parm, parm2;
	/* MUX10 (1eh) = stereo mixer */
	imux_is_smixer =
	snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 4;
	/* inputs */
	/* PW 5/6/7 (29h/2ah/2bh) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x29, &parm);
	set_pin_power_state(codec, 0x2a, &parm);
	set_pin_power_state(codec, 0x2b, &parm);
	if (imux_is_smixer)
		parm = AC_PWRST_D0;
	/* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
	update_power_state(codec, 0x1e, parm);
	update_power_state(codec, 0x1f, parm);
	update_power_state(codec, 0x10, parm);
	update_power_state(codec, 0x11, parm);

	/* outputs */
	/* PW3 (27h), MW3(37h), AOW3 (bh) */
	if (spec->codec_type == VT1705CF) {
		parm = AC_PWRST_D3;
		update_power_state(codec, 0x27, parm);
		update_power_state(codec, 0x37, parm);
	}	else {
		parm = AC_PWRST_D3;
		set_pin_power_state(codec, 0x27, &parm);
		update_power_state(codec, 0x37, parm);
	}

	/* PW2 (26h), MW2(36h), AOW2 (ah) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x26, &parm);
	update_power_state(codec, 0x36, parm);
1715
	if (smart51_enabled(codec)) {
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726
		/* PW7(2bh), MW7(3bh), MUX7(1Bh) */
		set_pin_power_state(codec, 0x2b, &parm);
		update_power_state(codec, 0x3b, parm);
		update_power_state(codec, 0x1b, parm);
	}
	update_conv_power_state(codec, 0xa, parm, 2);

	/* PW1 (25h), MW1(35h), AOW1 (9h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x25, &parm);
	update_power_state(codec, 0x35, parm);
1727
	if (smart51_enabled(codec)) {
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
		/* PW6(2ah), MW6(3ah), MUX6(1ah) */
		set_pin_power_state(codec, 0x2a, &parm);
		update_power_state(codec, 0x3a, parm);
		update_power_state(codec, 0x1a, parm);
	}
	update_conv_power_state(codec, 0x9, parm, 1);

	/* PW4 (28h), MW4 (38h), MUX4(18h), AOW3(bh)/AOW0(8h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x28, &parm);
	update_power_state(codec, 0x38, parm);
	update_power_state(codec, 0x18, parm);
1740
	if (spec->gen.indep_hp_enabled)
1741 1742 1743 1744 1745 1746 1747
		update_conv_power_state(codec, 0xb, parm, 3);
	parm2 = parm; /* for pin 0x0b */

	/* PW0 (24h), MW0(34h), MW9(3fh), AOW0 (8h) */
	parm = AC_PWRST_D3;
	set_pin_power_state(codec, 0x24, &parm);
	update_power_state(codec, 0x34, parm);
1748
	if (!spec->gen.indep_hp_enabled && parm2 != AC_PWRST_D3)
1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
		parm = parm2;
	update_conv_power_state(codec, 0x8, parm, 0);
	/* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
	update_power_state(codec, 0x3f, imux_is_smixer ? AC_PWRST_D0 : parm);
}

static int patch_vt3476(struct hda_codec *codec)
{
	struct via_spec *spec;
	int err;

	/* create a codec specific record */
	spec = via_new_spec(codec);
	if (spec == NULL)
		return -ENOMEM;

1765
	spec->gen.mixer_nid = 0x3f;
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
	add_secret_dac_path(codec);

	/* automatic parse from the BIOS config */
	err = via_parse_auto_config(codec);
	if (err < 0) {
		via_free(codec);
		return err;
	}

	spec->init_verbs[spec->num_iverbs++] = vt3476_init_verbs;

	codec->patch_ops = via_patch_ops;

	spec->set_widgets_power_state = set_widgets_power_state_vt3476;

	return 0;
}

1784 1785 1786
/*
 * patch entries
 */
1787
static const struct hda_codec_preset snd_hda_preset_via[] = {
1788 1789 1790 1791 1792
	{ .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
	{ .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
	{ .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
	{ .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
	{ .id = 0x1106e710, .name = "VT1709 10-Ch",
1793
	  .patch = patch_vt1709},
1794
	{ .id = 0x1106e711, .name = "VT1709 10-Ch",
1795
	  .patch = patch_vt1709},
1796
	{ .id = 0x1106e712, .name = "VT1709 10-Ch",
1797
	  .patch = patch_vt1709},
1798
	{ .id = 0x1106e713, .name = "VT1709 10-Ch",
1799
	  .patch = patch_vt1709},
1800
	{ .id = 0x1106e714, .name = "VT1709 6-Ch",
1801
	  .patch = patch_vt1709},
1802
	{ .id = 0x1106e715, .name = "VT1709 6-Ch",
1803
	  .patch = patch_vt1709},
1804
	{ .id = 0x1106e716, .name = "VT1709 6-Ch",
1805
	  .patch = patch_vt1709},
1806
	{ .id = 0x1106e717, .name = "VT1709 6-Ch",
1807
	  .patch = patch_vt1709},
1808
	{ .id = 0x1106e720, .name = "VT1708B 8-Ch",
1809
	  .patch = patch_vt1708B},
1810
	{ .id = 0x1106e721, .name = "VT1708B 8-Ch",
1811
	  .patch = patch_vt1708B},
1812
	{ .id = 0x1106e722, .name = "VT1708B 8-Ch",
1813
	  .patch = patch_vt1708B},
1814
	{ .id = 0x1106e723, .name = "VT1708B 8-Ch",
1815
	  .patch = patch_vt1708B},
1816
	{ .id = 0x1106e724, .name = "VT1708B 4-Ch",
1817
	  .patch = patch_vt1708B},
1818
	{ .id = 0x1106e725, .name = "VT1708B 4-Ch",
1819
	  .patch = patch_vt1708B},
1820
	{ .id = 0x1106e726, .name = "VT1708B 4-Ch",
1821
	  .patch = patch_vt1708B},
1822
	{ .id = 0x1106e727, .name = "VT1708B 4-Ch",
1823
	  .patch = patch_vt1708B},
1824
	{ .id = 0x11060397, .name = "VT1708S",
1825
	  .patch = patch_vt1708S},
1826
	{ .id = 0x11061397, .name = "VT1708S",
1827
	  .patch = patch_vt1708S},
1828
	{ .id = 0x11062397, .name = "VT1708S",
1829
	  .patch = patch_vt1708S},
1830
	{ .id = 0x11063397, .name = "VT1708S",
1831
	  .patch = patch_vt1708S},
1832
	{ .id = 0x11064397, .name = "VT1705",
1833
	  .patch = patch_vt1708S},
1834
	{ .id = 0x11065397, .name = "VT1708S",
1835
	  .patch = patch_vt1708S},
1836
	{ .id = 0x11066397, .name = "VT1708S",
1837
	  .patch = patch_vt1708S},
1838
	{ .id = 0x11067397, .name = "VT1708S",
1839
	  .patch = patch_vt1708S},
1840
	{ .id = 0x11060398, .name = "VT1702",
1841
	  .patch = patch_vt1702},
1842
	{ .id = 0x11061398, .name = "VT1702",
1843
	  .patch = patch_vt1702},
1844
	{ .id = 0x11062398, .name = "VT1702",
1845
	  .patch = patch_vt1702},
1846
	{ .id = 0x11063398, .name = "VT1702",
1847
	  .patch = patch_vt1702},
1848
	{ .id = 0x11064398, .name = "VT1702",
1849
	  .patch = patch_vt1702},
1850
	{ .id = 0x11065398, .name = "VT1702",
1851
	  .patch = patch_vt1702},
1852
	{ .id = 0x11066398, .name = "VT1702",
1853
	  .patch = patch_vt1702},
1854
	{ .id = 0x11067398, .name = "VT1702",
1855
	  .patch = patch_vt1702},
L
Lydia Wang 已提交
1856 1857 1858 1859
	{ .id = 0x11060428, .name = "VT1718S",
	  .patch = patch_vt1718S},
	{ .id = 0x11064428, .name = "VT1718S",
	  .patch = patch_vt1718S},
1860 1861 1862 1863
	{ .id = 0x11060441, .name = "VT2020",
	  .patch = patch_vt1718S},
	{ .id = 0x11064441, .name = "VT1828S",
	  .patch = patch_vt1718S},
L
Lydia Wang 已提交
1864 1865 1866 1867
	{ .id = 0x11060433, .name = "VT1716S",
	  .patch = patch_vt1716S},
	{ .id = 0x1106a721, .name = "VT1716S",
	  .patch = patch_vt1716S},
L
Lydia Wang 已提交
1868 1869
	{ .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
	{ .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
L
Lydia Wang 已提交
1870
	{ .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
1871 1872
	{ .id = 0x11060440, .name = "VT1818S",
	  .patch = patch_vt1708S},
1873 1874 1875 1876
	{ .id = 0x11060446, .name = "VT1802",
		.patch = patch_vt2002P},
	{ .id = 0x11068446, .name = "VT1802",
		.patch = patch_vt2002P},
1877 1878
	{ .id = 0x11064760, .name = "VT1705CF",
		.patch = patch_vt3476},
1879 1880 1881 1882
	{ .id = 0x11064761, .name = "VT1708SCE",
		.patch = patch_vt3476},
	{ .id = 0x11064762, .name = "VT1808",
		.patch = patch_vt3476},
1883 1884
	{} /* terminator */
};
1885 1886 1887

MODULE_ALIAS("snd-hda-codec-id:1106*");

1888
static struct hda_codec_driver via_driver = {
1889 1890 1891 1892 1893 1894
	.preset = snd_hda_preset_via,
};

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("VIA HD-audio codec");

1895
module_hda_codec_driver(via_driver);