[kernel] r16242 - in dists/sid/linux-2.6/debian: . patches/features/all/hda-via patches/series

Ben Hutchings benh at alioth.debian.org
Sun Sep 5 23:51:16 UTC 2010


Author: benh
Date: Sun Sep  5 23:51:14 2010
New Revision: 16242

Log:
snd-hda-intel: Add support for new VIA codecs

Added:
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0001-ALSA-HDA-VIA-Change-get_codec_type-argument-to-hda_c.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0002-ALSA-HDA-VIA-Add-VT1708B-CE-codec-support.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0003-ALSA-HDA-VIA-Add-VIA_CTL_WIDGET_ANALOG_MUTE-control-.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0004-ALSA-HDA-VIA-Add-low-current-mode-for-power-saving.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0005-ALSA-HDA-VIA-Change-VT1708S-VT1702-hp-mode-controls.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0006-ALSA-HDA-VIA-Rewrite-via_independent_hp_put.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0007-ALSA-HDA-VIA-Add-smart5.1-function.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0008-ALSA-HDA-VIA-When-changing-input-source-update-power.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0009-ALSA-HDA-VIA-Remove-unused-argument-of-via_new_analo.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0010-ALSA-HDA-VIA-Add-VIA_JACK_EVENT-process-in-via_unsol.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0011-ALSA-HDA-VIA-Refresh-front-playback-mute-in-via_hp_a.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0012-ALSA-HDA-VIA-Add-Jack-detect-feature-for-VT1708.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0013-ALSA-HDA-VIA-Replace-MIC_BOOST_VOLUME.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0014-ALSA-HDA-VIA-Add-VT1718S-support.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0015-ALSA-HDA-VIA-Add-VT1828S-and-VT2020-support.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0016-ALSA-HDA-VIA-Add-VT1716S-support.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0017-ALSA-HDA-VIA-Add-VT2002P-support.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0018-ALSA-HDA-VIA-Add-VT1812-support.patch
   dists/sid/linux-2.6/debian/patches/features/all/hda-via/0019-ALSA-VIA-HDA-Add-support-for-VT1818S.patch
Modified:
   dists/sid/linux-2.6/debian/changelog
   dists/sid/linux-2.6/debian/patches/series/22

Modified: dists/sid/linux-2.6/debian/changelog
==============================================================================
--- dists/sid/linux-2.6/debian/changelog	Sun Sep  5 23:46:29 2010	(r16241)
+++ dists/sid/linux-2.6/debian/changelog	Sun Sep  5 23:51:14 2010	(r16242)
@@ -34,6 +34,8 @@
     rely on running a default boot loader.
   * input: add compat support for sysfs and /proc capabilities output
     (Closes: #579017)
+  * snd-hda-intel: Add support for VIA V1708S, VT1718S, VT1828S, VT2020,
+    VT1716S, VT2002P, VT1812, VT1818S
 
   [ Bastian Blank ]
   * Use Breaks instead of Conflicts.

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0001-ALSA-HDA-VIA-Change-get_codec_type-argument-to-hda_c.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0001-ALSA-HDA-VIA-Change-get_codec_type-argument-to-hda_c.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,50 @@
+From 6f01e387d515cde65d2da981d41d60b593aa79dd Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:26 +0800
+Subject: [PATCH 01/19] ALSA: HDA VIA: Change get_codec_type argument to hda_codec type
+
+commit 744ff5f487925223beb6e21460c8cec468b54ab4 upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |    7 ++++---
+ 1 files changed, 4 insertions(+), 3 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index ee89db9..b859927 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -96,8 +96,9 @@ enum VIA_HDA_CODEC {
+ 	CODEC_TYPES,
+ };
+ 
+-static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
++static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ {
++	u32 vendor_id = codec->vendor_id;
+ 	u16 ven_id = vendor_id >> 16;
+ 	u16 dev_id = vendor_id & 0xffff;
+ 	enum VIA_HDA_CODEC codec_type;
+@@ -149,7 +150,7 @@ static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
+ 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+ 	hda_nid_t nid = get_amp_nid(kcontrol);
+ 
+-	if (get_codec_type(codec->vendor_id) == VT1708S
++	if (get_codec_type(codec) == VT1708S
+ 	    && (nid == 0x1a || nid == 0x1e)) {
+ 		if (size < 4 * sizeof(unsigned int))
+ 			return -ENOMEM;
+@@ -171,7 +172,7 @@ static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
+ 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+ 	hda_nid_t nid = get_amp_nid(kcontrol);
+ 
+-	if (get_codec_type(codec->vendor_id) == VT1708S
++	if (get_codec_type(codec) == VT1708S
+ 	    && (nid == 0x1a || nid == 0x1e)) {
+ 		uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+ 		uinfo->count = 2;
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0002-ALSA-HDA-VIA-Add-VT1708B-CE-codec-support.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0002-ALSA-HDA-VIA-Add-VT1708B-CE-codec-support.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,96 @@
+From e0a8de6d2c6c6818882aac4706c44bb2b3cbe945 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:29 +0800
+Subject: [PATCH 02/19] ALSA: HDA VIA: Add VT1708B-CE codec support.
+
+commit 518bf3ba753ad93644e7c6cf95c043c918d9429b upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   27 ++++++++++++++++++++++++---
+ 1 files changed, 24 insertions(+), 3 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index b859927..55e4a98 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -92,6 +92,7 @@ enum VIA_HDA_CODEC {
+ 	VT1708B_8CH,
+ 	VT1708B_4CH,
+ 	VT1708S,
++	VT1708BCE,
+ 	VT1702,
+ 	CODEC_TYPES,
+ };
+@@ -112,9 +113,11 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 		codec_type = VT1709_10CH;
+ 	else if (dev_id >= 0xe714 && dev_id <= 0xe717)
+ 		codec_type = VT1709_6CH;
+-	else if (dev_id >= 0xe720 && dev_id <= 0xe723)
++	else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
+ 		codec_type = VT1708B_8CH;
+-	else if (dev_id >= 0xe724 && dev_id <= 0xe727)
++		if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
++			codec_type = VT1708BCE;
++	} else if (dev_id >= 0xe724 && dev_id <= 0xe727)
+ 		codec_type = VT1708B_4CH;
+ 	else if ((dev_id & 0xfff) == 0x397
+ 		 && (dev_id >> 12) < 8)
+@@ -232,6 +235,8 @@ struct via_spec {
+ 	const struct hda_input_mux *hp_mux;
+ 	unsigned int hp_independent_mode;
+ 
++	enum VIA_HDA_CODEC codec_type;
++
+ #ifdef CONFIG_SND_HDA_POWER_SAVE
+ 	struct hda_loopback_check loopback;
+ #endif
+@@ -987,6 +992,10 @@ static int via_init(struct hda_codec *codec)
+ 	for (i = 0; i < spec->num_iverbs; i++)
+ 		snd_hda_sequence_write(codec, spec->init_verbs[i]);
+ 
++	spec->codec_type = get_codec_type(codec);
++	if (spec->codec_type == VT1708BCE)
++		spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
++					       same */
+ 	/* Lydia Add for EAPD enable */
+ 	if (!spec->dig_in_nid) { /* No Digital In connection */
+ 		if (spec->dig_in_pin) {
+@@ -2377,12 +2386,14 @@ static struct hda_amp_list vt1708B_loopbacks[] = {
+ 	{ } /* end */
+ };
+ #endif
+-
++static int patch_vt1708S(struct hda_codec *codec);
+ static int patch_vt1708B_8ch(struct hda_codec *codec)
+ {
+ 	struct via_spec *spec;
+ 	int err;
+ 
++	if (get_codec_type(codec) == VT1708BCE)
++		return patch_vt1708S(codec);
+ 	/* create a codec specific record */
+ 	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
+ 	if (spec == NULL)
+@@ -2914,6 +2925,16 @@ static int patch_vt1708S(struct hda_codec *codec)
+ 	spec->loopback.amplist = vt1708S_loopbacks;
+ #endif
+ 
++	/* correct names for VT1708BCE */
++	if (get_codec_type(codec) == VT1708BCE)	{
++		kfree(codec->chip_name);
++		codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
++		snprintf(codec->bus->card->mixername,
++			 sizeof(codec->bus->card->mixername),
++			 "%s %s", codec->vendor_name, codec->chip_name);
++		spec->stream_name_analog = "VT1708BCE Analog";
++		spec->stream_name_digital = "VT1708BCE Digital";
++	}
+ 	return 0;
+ }
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0003-ALSA-HDA-VIA-Add-VIA_CTL_WIDGET_ANALOG_MUTE-control-.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0003-ALSA-HDA-VIA-Add-VIA_CTL_WIDGET_ANALOG_MUTE-control-.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,301 @@
+From 9466cb387892b25fe61ee886c70586bdaab71c2b Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:35 +0800
+Subject: [PATCH 03/19] ALSA HDA VIA: Add VIA_CTL_WIDGET_ANALOG_MUTE control type
+
+commit f5271101faf1655d862849f42518c2a88ef394fb upstream.
+
+Enter low power state if AA-Path volume is muted.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |  240 ++++++++++++++++++++++++++++++++++++++++++++-
+ 1 files changed, 239 insertions(+), 1 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 55e4a98..c9b7bd4 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -136,6 +136,7 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ enum {
+ 	VIA_CTL_WIDGET_VOL,
+ 	VIA_CTL_WIDGET_MUTE,
++	VIA_CTL_WIDGET_ANALOG_MUTE,
+ };
+ 
+ enum {
+@@ -185,9 +186,34 @@ static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
+ 	return 0;
+ }
+ 
++static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
++static void set_jack_power_state(struct hda_codec *codec);
++
++static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
++				   struct snd_ctl_elem_value *ucontrol)
++{
++	int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
++	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
++
++	set_jack_power_state(codec);
++	analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
++	return change;
++}
++
++/* modify .put = snd_hda_mixer_amp_switch_put */
++#define ANALOG_INPUT_MUTE						\
++	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
++			.name = NULL,					\
++			.index = 0,					\
++			.info = snd_hda_mixer_amp_switch_info,		\
++			.get = snd_hda_mixer_amp_switch_get,		\
++			.put = analog_input_switch_put,			\
++			.private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
++
+ static struct snd_kcontrol_new vt1708_control_templates[] = {
+ 	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
+ 	HDA_CODEC_MUTE(NULL, 0, 0, 0),
++	ANALOG_INPUT_MUTE,
+ };
+ 
+ 
+@@ -311,7 +337,7 @@ static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
+ 	if (err < 0)
+ 		return err;
+ 	sprintf(name, "%s Playback Switch", ctlname);
+-	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
++	err = via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name,
+ 			      HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
+ 	if (err < 0)
+ 		return err;
+@@ -370,6 +396,131 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
+ 
+ 	}
+ }
++
++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 */
++	unsigned present = snd_hda_codec_read(codec, nid, 0,
++					      AC_VERB_GET_PIN_SENSE, 0) >> 31;
++
++	if ((no_presence || present) && get_defcfg_connect(def_conf)
++	    != AC_JACK_PORT_NONE) {
++		*affected_parm = AC_PWRST_D0; /* if it's connected */
++		parm = AC_PWRST_D0;
++	} else
++		parm = AC_PWRST_D3;
++
++	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
++}
++
++static void set_jack_power_state(struct hda_codec *codec)
++{
++	struct via_spec *spec = codec->spec;
++	int imux_is_smixer;
++	unsigned int parm;
++
++	if (spec->codec_type == VT1702) {
++		imux_is_smixer = snd_hda_codec_read(
++			codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
++		/* 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 = stereo mixer (idx 3) */
++		/* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
++		snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* outputs */
++		/* PW 3/4 (16h/17h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x16, &parm);
++		set_pin_power_state(codec, 0x17, &parm);
++		/* MW0 (1ah), AOW 0/1 (10h/1dh) */
++		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
++				    imux_is_smixer ? AC_PWRST_D0 : parm);
++		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++	} else if (spec->codec_type == VT1708B_8CH
++		   || spec->codec_type == VT1708B_4CH
++		   || spec->codec_type == VT1708S) {
++		/* SW0 (17h) = stereo mixer */
++		int is_8ch = spec->codec_type != VT1708B_4CH;
++		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) */
++		snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* outputs */
++		/* PW0 (19h), SW1 (18h), AOW1 (11h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x19, &parm);
++		snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* PW6 (22h), SW2 (26h), AOW2 (24h) */
++		if (is_8ch) {
++			parm = AC_PWRST_D3;
++			set_pin_power_state(codec, 0x22, &parm);
++			snd_hda_codec_write(codec, 0x26, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++			snd_hda_codec_write(codec, 0x24, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++		}
++
++		/* 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) */
++		snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
++				    imux_is_smixer ? AC_PWRST_D0 : parm);
++		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		if (is_8ch) {
++			snd_hda_codec_write(codec, 0x25, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++			snd_hda_codec_write(codec, 0x27, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++		}
++	}
++}
++
+ /*
+  * input MUX handling
+  */
+@@ -512,6 +663,93 @@ static struct snd_kcontrol_new vt1708_capture_mixer[] = {
+ 	},
+ 	{ } /* end */
+ };
++
++/* check AA path's mute statue */
++static int is_aa_path_mute(struct hda_codec *codec)
++{
++	int mute = 1;
++	hda_nid_t  nid_mixer;
++	int start_idx;
++	int end_idx;
++	int i;
++	struct via_spec *spec = codec->spec;
++	/* get nid of MW0 and start & end index */
++	switch (spec->codec_type) {
++	case VT1708B_8CH:
++	case VT1708B_4CH:
++	case VT1708S:
++		nid_mixer = 0x16;
++		start_idx = 2;
++		end_idx = 4;
++		break;
++	case VT1702:
++		nid_mixer = 0x1a;
++		start_idx = 1;
++		end_idx = 3;
++		break;
++	default:
++		return 0;
++	}
++	/* check AA path's mute status */
++	for (i = start_idx; i <= end_idx; i++) {
++		unsigned int con_list = snd_hda_codec_read(
++			codec, nid_mixer, 0, AC_VERB_GET_CONNECT_LIST, i/4*4);
++		int shift = 8 * (i % 4);
++		hda_nid_t nid_pin = (con_list & (0xff << shift)) >> shift;
++		unsigned int defconf = snd_hda_codec_get_pincfg(codec, nid_pin);
++		if (get_defcfg_connect(defconf) == AC_JACK_PORT_COMPLEX) {
++			/* check mute status while the pin is connected */
++			int mute_l = snd_hda_codec_amp_read(codec, nid_mixer, 0,
++							    HDA_INPUT, i) >> 7;
++			int mute_r = snd_hda_codec_amp_read(codec, nid_mixer, 1,
++							    HDA_INPUT, i) >> 7;
++			if (!mute_l || !mute_r) {
++				mute = 0;
++				break;
++			}
++		}
++	}
++	return mute;
++}
++
++/* enter/exit analog low-current mode */
++static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
++{
++	struct via_spec *spec = codec->spec;
++	static int saved_stream_idle = 1; /* saved stream idle status */
++	int enable = is_aa_path_mute(codec);
++	unsigned int verb = 0;
++	unsigned int parm = 0;
++
++	if (stream_idle == -1)	/* stream status did not change */
++		enable = enable && saved_stream_idle;
++	else {
++		enable = enable && stream_idle;
++		saved_stream_idle = stream_idle;
++	}
++
++	/* 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:
++		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;
++	default:
++		return;		/* other codecs are not supported */
++	}
++	/* send verb */
++	snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
++}
++
+ /*
+  * generic initialization of ADC, input mixers and output mixers
+  */
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0004-ALSA-HDA-VIA-Add-low-current-mode-for-power-saving.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0004-ALSA-HDA-VIA-Add-low-current-mode-for-power-saving.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,131 @@
+From b38df35beab7c48e131626e705daf75769778c47 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:37 +0800
+Subject: [PATCH 04/19] ALSA: HDA VIA: Add low current mode for power saving.
+
+commit 173143791068ac9f155c378a591d0b3d6c4a45ca upstream.
+
+For VT1708B, VT1708S and VT1702, enter low current mode if no analog
+stream is opened and all aa path mute.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   41 +++++++++++++++++++++++++++++++++++------
+ 1 files changed, 35 insertions(+), 6 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index c9b7bd4..4932a5e 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -791,6 +791,10 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
+ 				 struct snd_pcm_substream *substream)
+ {
+ 	struct via_spec *spec = codec->spec;
++	int idle = substream->pstr->substream_opened == 1
++		&& substream->ref_count == 0;
++
++	analog_low_current_mode(codec, idle);
+ 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
+ 					     hinfo);
+ }
+@@ -1097,6 +1101,11 @@ static int via_build_controls(struct hda_codec *codec)
+ 		if (err < 0)
+ 			return err;
+ 	}
++
++	/* init power states */
++	set_jack_power_state(codec);
++	analog_low_current_mode(codec, 1);
++
+ 	via_free_kctls(codec); /* no longer needed */
+ 	return 0;
+ }
+@@ -2320,6 +2329,17 @@ static struct hda_verb vt1708B_uniwill_init_verbs[] = {
+ 	{ }
+ };
+ 
++static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
++			      struct hda_codec *codec,
++			      struct snd_pcm_substream *substream)
++{
++	int idle = substream->pstr->substream_opened == 1
++		&& substream->ref_count == 0;
++
++	analog_low_current_mode(codec, idle);
++	return 0;
++}
++
+ static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
+ 	.substreams = 2,
+ 	.channels_min = 2,
+@@ -2328,7 +2348,8 @@ static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
+ 	.ops = {
+ 		.open = via_playback_pcm_open,
+ 		.prepare = via_playback_multi_pcm_prepare,
+-		.cleanup = via_playback_multi_pcm_cleanup
++		.cleanup = via_playback_multi_pcm_cleanup,
++		.close = via_pcm_open_close
+ 	},
+ };
+ 
+@@ -2350,8 +2371,10 @@ static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
+ 	.channels_max = 2,
+ 	.nid = 0x13, /* NID to query formats and rates */
+ 	.ops = {
++		.open = via_pcm_open_close,
+ 		.prepare = via_capture_pcm_prepare,
+-		.cleanup = via_capture_pcm_cleanup
++		.cleanup = via_capture_pcm_cleanup,
++		.close = via_pcm_open_close
+ 	},
+ };
+ 
+@@ -2808,7 +2831,8 @@ static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
+ 	.ops = {
+ 		.open = via_playback_pcm_open,
+ 		.prepare = via_playback_pcm_prepare,
+-		.cleanup = via_playback_pcm_cleanup
++		.cleanup = via_playback_pcm_cleanup,
++		.close = via_pcm_open_close
+ 	},
+ };
+ 
+@@ -2818,8 +2842,10 @@ static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
+ 	.channels_max = 2,
+ 	.nid = 0x13, /* NID to query formats and rates */
+ 	.ops = {
++		.open = via_pcm_open_close,
+ 		.prepare = via_capture_pcm_prepare,
+-		.cleanup = via_capture_pcm_cleanup
++		.cleanup = via_capture_pcm_cleanup,
++		.close = via_pcm_open_close
+ 	},
+ };
+ 
+@@ -3244,7 +3270,8 @@ static struct hda_pcm_stream vt1702_pcm_analog_playback = {
+ 	.ops = {
+ 		.open = via_playback_pcm_open,
+ 		.prepare = via_playback_multi_pcm_prepare,
+-		.cleanup = via_playback_multi_pcm_cleanup
++		.cleanup = via_playback_multi_pcm_cleanup,
++		.close = via_pcm_open_close
+ 	},
+ };
+ 
+@@ -3254,8 +3281,10 @@ static struct hda_pcm_stream vt1702_pcm_analog_capture = {
+ 	.channels_max = 2,
+ 	.nid = 0x12, /* NID to query formats and rates */
+ 	.ops = {
++		.open = via_pcm_open_close,
+ 		.prepare = via_capture_pcm_prepare,
+-		.cleanup = via_capture_pcm_cleanup
++		.cleanup = via_capture_pcm_cleanup,
++		.close = via_pcm_open_close
+ 	},
+ };
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0005-ALSA-HDA-VIA-Change-VT1708S-VT1702-hp-mode-controls.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0005-ALSA-HDA-VIA-Change-VT1708S-VT1702-hp-mode-controls.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,94 @@
+From 85508e3554717a3e94edbf7c5327d58d8a58decc Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:43 +0800
+Subject: [PATCH 05/19] ALSA: HDA VIA: Change VT1708S & VT1702 hp mode controls
+
+commit 0713efebfa1a1878feeeb17cbadc3d2d2c9e9ed2 upstream.
+
+For VT1708S and VT1702, deactivate "Headphone Playback Volume" and
+"Headphone Playback Mute" control if "Independent HP" mode is OFF.
+and rename VT1702 "Independent HP" text.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   38 ++++++++++++++++++++++++++++++++++----
+ 1 files changed, 34 insertions(+), 4 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 4932a5e..94352cb 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -580,6 +580,18 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
+ 	return 0;
+ }
+ 
++static void activate_ctl(struct hda_codec *codec, const char *name, int active)
++{
++	struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
++	if (ctl) {
++		ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
++		ctl->vd[0].access |= active
++			? 0 : SNDRV_CTL_ELEM_ACCESS_INACTIVE;
++		snd_ctl_notify(codec->bus->card,
++			       SNDRV_CTL_EVENT_MASK_VALUE, &ctl->id);
++	}
++}
++
+ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 				  struct snd_ctl_elem_value *ucontrol)
+ {
+@@ -628,6 +640,14 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 						   spec->multiout.hp_nid,
+ 						   0, 0, 0);
+ 
++	/* update HP volume/swtich active state */
++	if (spec->codec_type == VT1708S
++	    || spec->codec_type == VT1702) {
++		activate_ctl(codec, "Headphone Playback Volume",
++			     spec->hp_independent_mode);
++		activate_ctl(codec, "Headphone Playback Switch",
++			     spec->hp_independent_mode);
++	}
+ 	return 0;
+ }
+ 
+@@ -3354,11 +3374,11 @@ static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
+ 
+ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
+ {
+-	int err;
+-
++	int err, i;
++	struct hda_input_mux *imux;
++	static const char *texts[] = { "ON", "OFF", NULL};
+ 	if (!pin)
+ 		return 0;
+-
+ 	spec->multiout.hp_nid = 0x1D;
+ 
+ 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
+@@ -3373,8 +3393,18 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
+ 	if (err < 0)
+ 		return err;
+ 
+-	create_hp_imux(spec);
++	imux = &spec->private_imux[1];
+ 
++	/* for hp mode select */
++	i = 0;
++	while (texts[i] != NULL)	{
++		imux->items[imux->num_items].label =  texts[i];
++		imux->items[imux->num_items].index = i;
++		imux->num_items++;
++		i++;
++	}
++
++	spec->hp_mux = &spec->private_imux[1];
+ 	return 0;
+ }
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0006-ALSA-HDA-VIA-Rewrite-via_independent_hp_put.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0006-ALSA-HDA-VIA-Rewrite-via_independent_hp_put.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,167 @@
+From d315185d2608b0929e4add2395ba40d0a856e35b Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:47 +0800
+Subject: [PATCH 06/19] ALSA: HDA VIA: Rewrite via_independent_hp_put
+
+commit cdc1784d49258198df600fbc1d37c07d7eee5ed6 upstream.
+
+Use hp_independent_mode_index to store hp index, and simplify function
+via_independent_hp_put with it.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   85 ++++++++++++++++++++++++--------------------
+ 1 files changed, 46 insertions(+), 39 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 94352cb..4ea36ab 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -260,6 +260,7 @@ struct via_spec {
+ 	/* HP mode source */
+ 	const struct hda_input_mux *hp_mux;
+ 	unsigned int hp_independent_mode;
++	unsigned int hp_independent_mode_index;
+ 
+ 	enum VIA_HDA_CODEC codec_type;
+ 
+@@ -592,6 +593,36 @@ static void activate_ctl(struct hda_codec *codec, const char *name, int active)
+ 	}
+ }
+ 
++static int update_side_mute_status(struct hda_codec *codec)
++{
++	/* mute side channel */
++	struct via_spec *spec = codec->spec;
++	unsigned int parm = spec->hp_independent_mode
++		? AMP_OUT_MUTE : AMP_OUT_UNMUTE;
++	hda_nid_t sw3;
++
++	switch (spec->codec_type) {
++	case VT1708:
++		sw3 = 0x1b;
++		break;
++	case VT1709_10CH:
++		sw3 = 0x29;
++		break;
++	case VT1708B_8CH:
++	case VT1708S:
++		sw3 = 0x27;
++		break;
++	default:
++		sw3 = 0;
++		break;
++	}
++
++	if (sw3)
++		snd_hda_codec_write(codec, sw3, 0, AC_VERB_SET_AMP_GAIN_MUTE,
++				    parm);
++	return 0;
++}
++
+ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 				  struct snd_ctl_elem_value *ucontrol)
+ {
+@@ -599,47 +630,18 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 	struct via_spec *spec = codec->spec;
+ 	hda_nid_t nid = spec->autocfg.hp_pins[0];
+ 	unsigned int pinsel = ucontrol->value.enumerated.item[0];
+-	unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
+-					 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
+-
+-	if (con_nid == spec->multiout.hp_nid) {
+-		if (pinsel == 0) {
+-			if (!spec->hp_independent_mode) {
+-				if (spec->multiout.num_dacs > 1)
+-					spec->multiout.num_dacs -= 1;
+-				spec->hp_independent_mode = 1;
+-			}
+-		} else if (pinsel == 1) {
+-		       if (spec->hp_independent_mode) {
+-				if (spec->multiout.num_dacs > 1)
+-					spec->multiout.num_dacs += 1;
+-				spec->hp_independent_mode = 0;
+-		       }
+-		}
+-	} else {
+-		if (pinsel == 0) {
+-			if (spec->hp_independent_mode) {
+-				if (spec->multiout.num_dacs > 1)
+-					spec->multiout.num_dacs += 1;
+-				spec->hp_independent_mode = 0;
+-			}
+-		} else if (pinsel == 1) {
+-		       if (!spec->hp_independent_mode) {
+-				if (spec->multiout.num_dacs > 1)
+-					spec->multiout.num_dacs -= 1;
+-				spec->hp_independent_mode = 1;
+-		       }
+-		}
+-	}
+-	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
+-			    pinsel);
++	/* Get Independent Mode index of headphone pin widget */
++	spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
++		? 1 : 0;
+ 
+-	if (spec->multiout.hp_nid &&
+-	    spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
+-			snd_hda_codec_setup_stream(codec,
+-						   spec->multiout.hp_nid,
+-						   0, 0, 0);
++	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
++
++	if (spec->multiout.hp_nid && spec->multiout.hp_nid
++	    != spec->multiout.dac_nids[HDA_FRONT])
++		snd_hda_codec_setup_stream(codec, spec->multiout.hp_nid,
++					   0, 0, 0);
+ 
++	update_side_mute_status(codec);
+ 	/* update HP volume/swtich active state */
+ 	if (spec->codec_type == VT1708S
+ 	    || spec->codec_type == VT1702) {
+@@ -1455,6 +1457,7 @@ static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
+ 		return 0;
+ 
+ 	spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
++	spec->hp_independent_mode_index = 1;
+ 
+ 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
+ 			      "Headphone Playback Volume",
+@@ -1991,6 +1994,7 @@ static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
+ 		spec->multiout.hp_nid = VT1709_HP_DAC_NID;
+ 	else if (spec->multiout.num_dacs == 3) /* 6 channels */
+ 		spec->multiout.hp_nid = 0;
++	spec->hp_independent_mode_index = 1;
+ 
+ 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
+ 			      "Headphone Playback Volume",
+@@ -2551,6 +2555,7 @@ static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
+ 		return 0;
+ 
+ 	spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
++	spec->hp_independent_mode_index = 1;
+ 
+ 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
+ 			      "Headphone Playback Volume",
+@@ -3022,6 +3027,7 @@ static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
+ 		return 0;
+ 
+ 	spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
++	spec->hp_independent_mode_index = 1;
+ 
+ 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
+ 			      "Headphone Playback Volume",
+@@ -3380,6 +3386,7 @@ static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
+ 	if (!pin)
+ 		return 0;
+ 	spec->multiout.hp_nid = 0x1D;
++	spec->hp_independent_mode_index = 0;
+ 
+ 	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
+ 			      "Headphone Playback Volume",
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0007-ALSA-HDA-VIA-Add-smart5.1-function.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0007-ALSA-HDA-VIA-Add-smart5.1-function.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,265 @@
+From d3124da249c635ccf39672368e9f967966776ef5 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:52 +0800
+Subject: [PATCH 07/19] ALSA: HDA VIA: Add smart5.1 function.
+
+commit 1564b2878f5cf160f60af99d4dbca1dd7809ee8a upstream.
+
+Smart 5.1 is for 3-jacks model, to reuse input pins as outputs.
+While off, they act as "line out" / "line in" / "mic in".
+While on, they acts as "line out" / "back left/right" / "center/lfe".
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |  177 ++++++++++++++++++++++++++++++++++++++++++++-
+ 1 files changed, 173 insertions(+), 4 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 4ea36ab..3da12f9 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -219,7 +219,7 @@ static struct snd_kcontrol_new vt1708_control_templates[] = {
+ 
+ struct via_spec {
+ 	/* codec parameterization */
+-	struct snd_kcontrol_new *mixers[3];
++	struct snd_kcontrol_new *mixers[4];
+ 	unsigned int num_mixers;
+ 
+ 	struct hda_verb *init_verbs[5];
+@@ -261,6 +261,7 @@ struct via_spec {
+ 	const struct hda_input_mux *hp_mux;
+ 	unsigned int hp_independent_mode;
+ 	unsigned int hp_independent_mode_index;
++	unsigned int smart51_enabled;
+ 
+ 	enum VIA_HDA_CODEC codec_type;
+ 
+@@ -398,6 +399,8 @@ static void via_auto_init_analog_input(struct hda_codec *codec)
+ 	}
+ }
+ 
++static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin);
++
+ static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
+ 				unsigned int *affected_parm)
+ {
+@@ -408,9 +411,10 @@ static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
+ 		& AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
+ 	unsigned present = snd_hda_codec_read(codec, nid, 0,
+ 					      AC_VERB_GET_PIN_SENSE, 0) >> 31;
+-
+-	if ((no_presence || present) && get_defcfg_connect(def_conf)
+-	    != AC_JACK_PORT_NONE) {
++	struct via_spec *spec = codec->spec;
++	if ((spec->smart51_enabled && is_smart51_pins(spec, nid))
++	    || ((no_presence || present)
++		&& get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
+ 		*affected_parm = AC_PWRST_D0; /* if it's connected */
+ 		parm = AC_PWRST_D0;
+ 	} else
+@@ -665,6 +669,167 @@ static struct snd_kcontrol_new via_hp_mixer[] = {
+ 	{ } /* end */
+ };
+ 
++static void notify_aa_path_ctls(struct hda_codec *codec)
++{
++	int i;
++	struct snd_ctl_elem_id id;
++	const char *labels[] = {"Mic", "Front Mic", "Line"};
++
++	memset(&id, 0, sizeof(id));
++	id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
++	for (i = 0; i < ARRAY_SIZE(labels); i++) {
++		sprintf(id.name, "%s Playback Volume", labels[i]);
++		snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
++			       &id);
++	}
++}
++
++static void mute_aa_path(struct hda_codec *codec, int mute)
++{
++	struct via_spec *spec = codec->spec;
++	hda_nid_t  nid_mixer;
++	int start_idx;
++	int end_idx;
++	int i;
++	/* get nid of MW0 and start & end index */
++	switch (spec->codec_type) {
++	case VT1708:
++		nid_mixer = 0x17;
++		start_idx = 2;
++		end_idx = 4;
++		break;
++	case VT1709_10CH:
++	case VT1709_6CH:
++		nid_mixer = 0x18;
++		start_idx = 2;
++		end_idx = 4;
++		break;
++	case VT1708B_8CH:
++	case VT1708B_4CH:
++	case VT1708S:
++		nid_mixer = 0x16;
++		start_idx = 2;
++		end_idx = 4;
++		break;
++	default:
++		return;
++	}
++	/* check AA path's mute status */
++	for (i = start_idx; i <= end_idx; i++) {
++		int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
++		snd_hda_codec_amp_stereo(codec, nid_mixer, HDA_INPUT, i,
++					 HDA_AMP_MUTE, val);
++	}
++}
++static int is_smart51_pins(struct via_spec *spec, hda_nid_t pin)
++{
++	int res = 0;
++	int index;
++	for (index = AUTO_PIN_MIC; index < AUTO_PIN_FRONT_LINE; index++) {
++		if (pin == spec->autocfg.input_pins[index]) {
++			res = 1;
++			break;
++		}
++	}
++	return res;
++}
++
++static int via_smart51_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 via_smart51_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;
++	int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
++	int on = 1;
++	int i;
++
++	for (i = 0; i < ARRAY_SIZE(index); i++) {
++		hda_nid_t nid = spec->autocfg.input_pins[index[i]];
++		if (nid) {
++			int ctl =
++			    snd_hda_codec_read(codec, nid, 0,
++					       AC_VERB_GET_PIN_WIDGET_CONTROL,
++					       0);
++			if (i == AUTO_PIN_FRONT_MIC
++			    && spec->hp_independent_mode)
++				continue; /* ignore FMic for independent HP */
++			if (ctl & AC_PINCTL_IN_EN
++			    && !(ctl & AC_PINCTL_OUT_EN))
++				on = 0;
++		}
++	}
++	*ucontrol->value.integer.value = on;
++	return 0;
++}
++
++static int via_smart51_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 out_in = *ucontrol->value.integer.value
++		? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
++	int index[] = { AUTO_PIN_MIC, AUTO_PIN_FRONT_MIC, AUTO_PIN_LINE };
++	int i;
++
++	for (i = 0; i < ARRAY_SIZE(index); i++) {
++		hda_nid_t nid = spec->autocfg.input_pins[index[i]];
++		if (i == AUTO_PIN_FRONT_MIC
++		    && spec->hp_independent_mode)
++			continue; /* don't retask FMic for independent HP */
++		if (nid) {
++			unsigned int parm = snd_hda_codec_read(
++				codec, nid, 0,
++				AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
++			parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
++			parm |= out_in;
++			snd_hda_codec_write(codec, nid, 0,
++					    AC_VERB_SET_PIN_WIDGET_CONTROL,
++					    parm);
++			if (out_in == AC_PINCTL_OUT_EN) {
++				mute_aa_path(codec, 1);
++				notify_aa_path_ctls(codec);
++			}
++		}
++		if (i == AUTO_PIN_FRONT_MIC) {
++			if (spec->codec_type == VT1708S) {
++				/* input = index 1 (AOW3) */
++				snd_hda_codec_write(
++					codec, nid, 0,
++					AC_VERB_SET_CONNECT_SEL, 1);
++				snd_hda_codec_amp_stereo(
++					codec, nid, HDA_OUTPUT,
++					0, HDA_AMP_MUTE, HDA_AMP_UNMUTE);
++			}
++		}
++	}
++	spec->smart51_enabled = *ucontrol->value.integer.value;
++	set_jack_power_state(codec);
++	return 1;
++}
++
++static struct snd_kcontrol_new via_smart51_mixer[] = {
++	{
++	 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
++	 .name = "Smart 5.1",
++	 .count = 1,
++	 .info = via_smart51_info,
++	 .get = via_smart51_get,
++	 .put = via_smart51_put,
++	 },
++	{}			/* end */
++};
++
+ /* capture mixer elements */
+ static struct snd_kcontrol_new vt1708_capture_mixer[] = {
+ 	HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
+@@ -1596,6 +1761,7 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
+ 	if (spec->hp_mux)
+ 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
+ 
++	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
+ 	return 1;
+ }
+ 
+@@ -2097,6 +2263,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
+ 	if (spec->hp_mux)
+ 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
+ 
++	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
+ 	return 1;
+ }
+ 
+@@ -2660,6 +2827,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
+ 	if (spec->hp_mux)
+ 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
+ 
++	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
+ 	return 1;
+ }
+ 
+@@ -3154,6 +3322,7 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec)
+ 	if (spec->hp_mux)
+ 		spec->mixers[spec->num_mixers++] = via_hp_mixer;
+ 
++	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
+ 	return 1;
+ }
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0008-ALSA-HDA-VIA-When-changing-input-source-update-power.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0008-ALSA-HDA-VIA-When-changing-input-source-update-power.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,36 @@
+From 7a3d97b4f0e155d00df4eca6d2dd32c9eb57bb5b Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:55 +0800
+Subject: [PATCH 08/19] ALSA: HDA VIA: When changing input source, update power state.
+
+commit a80e6e3c8c21ca50837e2e42fa438a4ff4a9788e upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |    8 ++++++++
+ 1 files changed, 8 insertions(+), 0 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 3da12f9..bf28a49 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -557,6 +557,14 @@ static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
+ 
+ 	if (!spec->mux_nids[adc_idx])
+ 		return -EINVAL;
++	/* switch to D0 beofre change index */
++	if (snd_hda_codec_read(codec, spec->mux_nids[adc_idx], 0,
++			       AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
++		snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
++				    AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++	/* update jack power state */
++	set_jack_power_state(codec);
++
+ 	return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
+ 				     spec->mux_nids[adc_idx],
+ 				     &spec->cur_mux[adc_idx]);
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0009-ALSA-HDA-VIA-Remove-unused-argument-of-via_new_analo.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0009-ALSA-HDA-VIA-Remove-unused-argument-of-via_new_analo.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,82 @@
+From 4db16029262bb0cfe2bc8e3c8253a6e7958f5368 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:07:39 +0800
+Subject: [PATCH 09/19] ALSA: HDA VIA: Remove unused argument of via_new_analog_input
+
+commit 9510e8dd9cb4469d146953270364af6dd86a39be upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   19 +++++++------------
+ 1 files changed, 7 insertions(+), 12 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index bf28a49..128f6bc 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -327,8 +327,8 @@ static void via_free_kctls(struct hda_codec *codec)
+ }
+ 
+ /* create input playback/capture controls for the given pin */
+-static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
+-				const char *ctlname, int idx, int mix_nid)
++static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
++				int idx, int mix_nid)
+ {
+ 	char name[32];
+ 	int err;
+@@ -1684,8 +1684,7 @@ static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
+ 			idx = 1;
+ 			break;
+ 		}
+-		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
+-					   idx, 0x17);
++		err = via_new_analog_input(spec, labels[i], idx, 0x17);
+ 		if (err < 0)
+ 			return err;
+ 		imux->items[imux->num_items].label = labels[i];
+@@ -2220,8 +2219,7 @@ static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
+ 			idx = 1;
+ 			break;
+ 		}
+-		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
+-					   idx, 0x18);
++		err = via_new_analog_input(spec, labels[i], idx, 0x18);
+ 		if (err < 0)
+ 			return err;
+ 		imux->items[imux->num_items].label = labels[i];
+@@ -2784,8 +2782,7 @@ static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
+ 			idx = 1;
+ 			break;
+ 		}
+-		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
+-					   idx, 0x16);
++		err = via_new_analog_input(spec, labels[i], idx, 0x16);
+ 		if (err < 0)
+ 			return err;
+ 		imux->items[imux->num_items].label = labels[i];
+@@ -3258,8 +3255,7 @@ static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
+ 			idx = 1;
+ 			break;
+ 		}
+-		err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
+-					   idx, 0x16);
++		err = via_new_analog_input(spec, labels[i], idx, 0x16);
+ 		if (err < 0)
+ 			return err;
+ 		imux->items[imux->num_items].label = labels[i];
+@@ -3624,8 +3620,7 @@ static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
+ 			idx = 3;
+ 			break;
+ 		}
+-		err = via_new_analog_input(spec, cfg->input_pins[i],
+-					   labels[i], idx, 0x1A);
++		err = via_new_analog_input(spec, labels[i], idx, 0x1A);
+ 		if (err < 0)
+ 			return err;
+ 		imux->items[imux->num_items].label = labels[i];
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0010-ALSA-HDA-VIA-Add-VIA_JACK_EVENT-process-in-via_unsol.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0010-ALSA-HDA-VIA-Add-VIA_JACK_EVENT-process-in-via_unsol.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,103 @@
+From b09b243962bdb511da6c529205892b61df3e480a Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:01 +0800
+Subject: [PATCH 10/19] ALSA: HDA VIA: Add VIA_JACK_EVENT process in via_unsol_event.
+
+commit a34df19a658170fb7125e8017ee46ba54b1ad495 upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   38 +++++++++++++++++++++++++++++++-------
+ 1 files changed, 31 insertions(+), 7 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 128f6bc..c4a1e3e 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -132,6 +132,7 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 
+ #define VIA_HP_EVENT		0x01
+ #define VIA_GPIO_EVENT		0x02
++#define VIA_JACK_EVENT		0x04
+ 
+ enum {
+ 	VIA_CTL_WIDGET_VOL,
+@@ -1421,10 +1422,12 @@ static void via_unsol_event(struct hda_codec *codec,
+ 				  unsigned int res)
+ {
+ 	res >>= 26;
+-	if (res == VIA_HP_EVENT)
++	if (res & VIA_HP_EVENT)
+ 		via_hp_automute(codec);
+-	else if (res == VIA_GPIO_EVENT)
++	if (res & VIA_GPIO_EVENT)
+ 		via_gpio_control(codec);
++	if (res & VIA_JACK_EVENT)
++		set_jack_power_state(codec);
+ }
+ 
+ static int via_init(struct hda_codec *codec)
+@@ -1886,7 +1889,8 @@ static struct snd_kcontrol_new vt1709_capture_mixer[] = {
+ };
+ 
+ static struct hda_verb vt1709_uniwill_init_verbs[] = {
+-	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
++	{0x20, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
+ 	{ }
+ };
+ 
+@@ -2522,7 +2526,15 @@ static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
+ };
+ 
+ static struct hda_verb vt1708B_uniwill_init_verbs[] = {
+-	{0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
++	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
++	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
+ 	{ }
+ };
+ 
+@@ -3017,7 +3029,15 @@ static struct hda_verb vt1708S_volume_init_verbs[] = {
+ };
+ 
+ static struct hda_verb vt1708S_uniwill_init_verbs[] = {
+-	{0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
++	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
++	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x22, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
+ 	{ }
+ };
+ 
+@@ -3456,8 +3476,12 @@ static struct hda_verb vt1702_volume_init_verbs[] = {
+ };
+ 
+ static struct hda_verb vt1702_uniwill_init_verbs[] = {
+-	{0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
+-	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
++	{0x17, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
++	{0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
+ 	{ }
+ };
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0011-ALSA-HDA-VIA-Refresh-front-playback-mute-in-via_hp_a.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0011-ALSA-HDA-VIA-Refresh-front-playback-mute-in-via_hp_a.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,51 @@
+From cdb6cecebd9bad543612a7c5dacace53eb8298e0 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:15 +0800
+Subject: [PATCH 11/19] ALSA: HDA VIA: Refresh front playback mute in via_hp_automute.
+
+commit dcf34c8cc685781cebbe1f4c75272a3269eba3a1 upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   19 +++++++++++++++----
+ 1 files changed, 15 insertions(+), 4 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index c4a1e3e..810aa7c 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -1359,14 +1359,25 @@ static void via_free(struct hda_codec *codec)
+ /* mute internal speaker if HP is plugged */
+ static void via_hp_automute(struct hda_codec *codec)
+ {
+-	unsigned int present;
++	unsigned int present = 0;
+ 	struct via_spec *spec = codec->spec;
+ 
+ 	present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
+ 				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
+-	snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
+-				 HDA_OUTPUT, 0, HDA_AMP_MUTE,
+-				 present ? HDA_AMP_MUTE : 0);
++
++	if (!spec->hp_independent_mode) {
++		struct snd_ctl_elem_id id;
++		/* auto mute */
++		snd_hda_codec_amp_stereo(
++			codec, spec->autocfg.line_out_pins[0], HDA_OUTPUT, 0,
++			HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
++		/* notify change */
++		memset(&id, 0, sizeof(id));
++		id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
++		strcpy(id.name, "Front Playback Switch");
++		snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
++			       &id);
++	}
+ }
+ 
+ static void via_gpio_control(struct hda_codec *codec)
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0012-ALSA-HDA-VIA-Add-Jack-detect-feature-for-VT1708.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0012-ALSA-HDA-VIA-Add-Jack-detect-feature-for-VT1708.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,366 @@
+From c2b6052fbff276a383f8541998592724ca36a0f6 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:17 +0800
+Subject: [PATCH 12/19] ALSA: HDA VIA: Add Jack detect feature for VT1708.
+
+commit 1f2e99febd5dd0c91f0d0752674029a4376649e5 upstream.
+
+VT1708 does not support unsolicited response, but we need hp detect to
+automute speaker. Implemented in workqueue.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |  230 ++++++++++++++++++++++++++++++++++-----------
+ 1 files changed, 173 insertions(+), 57 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 810aa7c..e8fdaf8 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -97,6 +97,64 @@ enum VIA_HDA_CODEC {
+ 	CODEC_TYPES,
+ };
+ 
++struct via_spec {
++	/* codec parameterization */
++	struct snd_kcontrol_new *mixers[4];
++	unsigned int num_mixers;
++
++	struct hda_verb *init_verbs[5];
++	unsigned int num_iverbs;
++
++	char *stream_name_analog;
++	struct hda_pcm_stream *stream_analog_playback;
++	struct hda_pcm_stream *stream_analog_capture;
++
++	char *stream_name_digital;
++	struct hda_pcm_stream *stream_digital_playback;
++	struct hda_pcm_stream *stream_digital_capture;
++
++	/* playback */
++	struct hda_multi_out multiout;
++	hda_nid_t slave_dig_outs[2];
++
++	/* capture */
++	unsigned int num_adc_nids;
++	hda_nid_t *adc_nids;
++	hda_nid_t mux_nids[3];
++	hda_nid_t dig_in_nid;
++	hda_nid_t dig_in_pin;
++
++	/* capture source */
++	const struct hda_input_mux *input_mux;
++	unsigned int cur_mux[3];
++
++	/* PCM information */
++	struct hda_pcm pcm_rec[3];
++
++	/* dynamic controls, init_verbs and input_mux */
++	struct auto_pin_cfg autocfg;
++	struct snd_array kctls;
++	struct hda_input_mux private_imux[2];
++	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
++
++	/* HP mode source */
++	const struct hda_input_mux *hp_mux;
++	unsigned int hp_independent_mode;
++	unsigned int hp_independent_mode_index;
++	unsigned int smart51_enabled;
++
++	enum VIA_HDA_CODEC codec_type;
++
++	/* work to check hp jack state */
++	struct hda_codec *codec;
++	struct delayed_work vt1708_hp_work;
++	int vt1708_jack_detectect;
++	int vt1708_hp_present;
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++	struct hda_loopback_check loopback;
++#endif
++};
++
+ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ {
+ 	u32 vendor_id = codec->vendor_id;
+@@ -189,6 +247,31 @@ static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
+ 
+ static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
+ static void set_jack_power_state(struct hda_codec *codec);
++static int is_aa_path_mute(struct hda_codec *codec);
++
++static void vt1708_start_hp_work(struct via_spec *spec)
++{
++	if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
++		return;
++	snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
++			    !spec->vt1708_jack_detectect);
++	if (!delayed_work_pending(&spec->vt1708_hp_work))
++		schedule_delayed_work(&spec->vt1708_hp_work,
++				      msecs_to_jiffies(100));
++}
++
++static void vt1708_stop_hp_work(struct via_spec *spec)
++{
++	if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
++		return;
++	if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
++	    && !is_aa_path_mute(spec->codec))
++		return;
++	snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
++			    !spec->vt1708_jack_detectect);
++	cancel_delayed_work(&spec->vt1708_hp_work);
++	flush_scheduled_work();
++}
+ 
+ static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
+ 				   struct snd_ctl_elem_value *ucontrol)
+@@ -198,6 +281,12 @@ static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
+ 
+ 	set_jack_power_state(codec);
+ 	analog_low_current_mode(snd_kcontrol_chip(kcontrol), -1);
++	if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
++		if (is_aa_path_mute(codec))
++			vt1708_start_hp_work(codec->spec);
++		else
++			vt1708_stop_hp_work(codec->spec);
++	}
+ 	return change;
+ }
+ 
+@@ -218,59 +307,6 @@ static struct snd_kcontrol_new vt1708_control_templates[] = {
+ };
+ 
+ 
+-struct via_spec {
+-	/* codec parameterization */
+-	struct snd_kcontrol_new *mixers[4];
+-	unsigned int num_mixers;
+-
+-	struct hda_verb *init_verbs[5];
+-	unsigned int num_iverbs;
+-
+-	char *stream_name_analog;
+-	struct hda_pcm_stream *stream_analog_playback;
+-	struct hda_pcm_stream *stream_analog_capture;
+-
+-	char *stream_name_digital;
+-	struct hda_pcm_stream *stream_digital_playback;
+-	struct hda_pcm_stream *stream_digital_capture;
+-
+-	/* playback */
+-	struct hda_multi_out multiout;
+-	hda_nid_t slave_dig_outs[2];
+-
+-	/* capture */
+-	unsigned int num_adc_nids;
+-	hda_nid_t *adc_nids;
+-	hda_nid_t mux_nids[3];
+-	hda_nid_t dig_in_nid;
+-	hda_nid_t dig_in_pin;
+-
+-	/* capture source */
+-	const struct hda_input_mux *input_mux;
+-	unsigned int cur_mux[3];
+-
+-	/* PCM information */
+-	struct hda_pcm pcm_rec[3];
+-
+-	/* dynamic controls, init_verbs and input_mux */
+-	struct auto_pin_cfg autocfg;
+-	struct snd_array kctls;
+-	struct hda_input_mux private_imux[2];
+-	hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
+-
+-	/* HP mode source */
+-	const struct hda_input_mux *hp_mux;
+-	unsigned int hp_independent_mode;
+-	unsigned int hp_independent_mode_index;
+-	unsigned int smart51_enabled;
+-
+-	enum VIA_HDA_CODEC codec_type;
+-
+-#ifdef CONFIG_SND_HDA_POWER_SAVE
+-	struct hda_loopback_check loopback;
+-#endif
+-};
+-
+ static hda_nid_t vt1708_adc_nids[2] = {
+ 	/* ADC1-2 */
+ 	0x15, 0x27
+@@ -989,7 +1025,6 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
+ 	struct via_spec *spec = codec->spec;
+ 	int idle = substream->pstr->substream_opened == 1
+ 		&& substream->ref_count == 0;
+-
+ 	analog_low_current_mode(codec, idle);
+ 	return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
+ 					     hinfo);
+@@ -1002,6 +1037,7 @@ static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
+ 				    struct snd_pcm_substream *substream)
+ {
+ 	struct via_spec *spec = codec->spec;
++	vt1708_start_hp_work(spec);
+ 	return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
+ 						stream_tag, format, substream);
+ }
+@@ -1011,6 +1047,7 @@ static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
+ 				    struct snd_pcm_substream *substream)
+ {
+ 	struct via_spec *spec = codec->spec;
++	vt1708_stop_hp_work(spec);
+ 	return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
+ }
+ 
+@@ -1102,7 +1139,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
+ 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
+ 						   stream_tag, 0, format);
+ 	}
+-
++	vt1708_start_hp_work(spec);
+ 	return 0;
+ }
+ 
+@@ -1142,7 +1179,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
+ 			snd_hda_codec_setup_stream(codec, mout->hp_nid,
+ 						   0, 0, 0);
+ 	}
+-
++	vt1708_stop_hp_work(spec);
+ 	return 0;
+ }
+ 
+@@ -1353,6 +1390,7 @@ static void via_free(struct hda_codec *codec)
+ 		return;
+ 
+ 	via_free_kctls(codec);
++	vt1708_stop_hp_work(spec);
+ 	kfree(codec->spec);
+ }
+ 
+@@ -1472,6 +1510,15 @@ static int via_init(struct hda_codec *codec)
+  	return 0;
+ }
+ 
++#ifdef SND_HDA_NEEDS_RESUME
++static int via_suspend(struct hda_codec *codec, pm_message_t state)
++{
++	struct via_spec *spec = codec->spec;
++	vt1708_stop_hp_work(spec);
++	return 0;
++}
++#endif
++
+ #ifdef CONFIG_SND_HDA_POWER_SAVE
+ static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
+ {
+@@ -1487,6 +1534,9 @@ static struct hda_codec_ops via_patch_ops = {
+ 	.build_pcms = via_build_pcms,
+ 	.init = via_init,
+ 	.free = via_free,
++#ifdef SND_HDA_NEEDS_RESUME
++	.suspend = via_suspend,
++#endif
+ #ifdef CONFIG_SND_HDA_POWER_SAVE
+ 	.check_power_status = via_check_power_status,
+ #endif
+@@ -1736,6 +1786,51 @@ static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
+ 	return;
+ }
+ 
++static int vt1708_jack_detectect_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;
++
++	if (spec->codec_type != VT1708)
++		return 0;
++	spec->vt1708_jack_detectect =
++		!((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
++	ucontrol->value.integer.value[0] = spec->vt1708_jack_detectect;
++	return 0;
++}
++
++static int vt1708_jack_detectect_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 change;
++
++	if (spec->codec_type != VT1708)
++		return 0;
++	spec->vt1708_jack_detectect = ucontrol->value.integer.value[0];
++	change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
++		== !spec->vt1708_jack_detectect;
++	if (spec->vt1708_jack_detectect) {
++		mute_aa_path(codec, 1);
++		notify_aa_path_ctls(codec);
++	}
++	return change;
++}
++
++static struct snd_kcontrol_new vt1708_jack_detectect[] = {
++	{
++		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
++		.name = "Jack Detect",
++		.count = 1,
++		.info = snd_ctl_boolean_mono_info,
++		.get = vt1708_jack_detectect_get,
++		.put = vt1708_jack_detectect_put,
++	},
++	{} /* end */
++};
++
+ static int vt1708_parse_auto_config(struct hda_codec *codec)
+ {
+ 	struct via_spec *spec = codec->spec;
+@@ -1763,6 +1858,10 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
+ 	err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
+ 	if (err < 0)
+ 		return err;
++	/* add jack detect on/off control */
++	err = snd_hda_add_new_ctls(codec, vt1708_jack_detectect);
++	if (err < 0)
++		return err;
+ 
+ 	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
+ 
+@@ -1796,6 +1895,22 @@ static int via_auto_init(struct hda_codec *codec)
+ 	return 0;
+ }
+ 
++static void vt1708_update_hp_jack_state(struct work_struct *work)
++{
++	struct via_spec *spec = container_of(work, struct via_spec,
++					     vt1708_hp_work.work);
++	if (spec->codec_type != VT1708)
++		return;
++	/* if jack state toggled */
++	if (spec->vt1708_hp_present
++	    != (snd_hda_codec_read(spec->codec, spec->autocfg.hp_pins[0], 0,
++				   AC_VERB_GET_PIN_SENSE, 0) >> 31)) {
++		spec->vt1708_hp_present ^= 1;
++		via_hp_automute(spec->codec);
++	}
++	vt1708_start_hp_work(spec);
++}
++
+ static int get_mux_nids(struct hda_codec *codec)
+ {
+ 	struct via_spec *spec = codec->spec;
+@@ -1872,7 +1987,8 @@ static int patch_vt1708(struct hda_codec *codec)
+ #ifdef CONFIG_SND_HDA_POWER_SAVE
+ 	spec->loopback.amplist = vt1708_loopbacks;
+ #endif
+-
++	spec->codec = codec;
++	INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
+ 	return 0;
+ }
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0013-ALSA-HDA-VIA-Replace-MIC_BOOST_VOLUME.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0013-ALSA-HDA-VIA-Replace-MIC_BOOST_VOLUME.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,129 @@
+From 190c2b0bd27fc03cb8dfceae458a8d651c6ea996 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:31 +0800
+Subject: [PATCH 13/19] ALSA: HDA VIA: Replace MIC_BOOST_VOLUME.
+
+commit 6369bcfccb57da28ad3e09b25fecd841a415ae95 upstream.
+
+With snd_hda_override_amp_caps.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   72 +++++++++-----------------------------------
+ 1 files changed, 15 insertions(+), 57 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index e8fdaf8..1e9108f 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -205,46 +205,6 @@ enum {
+ 	AUTO_SEQ_SIDE
+ };
+ 
+-/* Some VT1708S based boards gets the micboost setting wrong, so we have
+- * to apply some brute-force and re-write the TLV's by software. */
+-static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
+-			 unsigned int size, unsigned int __user *_tlv)
+-{
+-	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+-	hda_nid_t nid = get_amp_nid(kcontrol);
+-
+-	if (get_codec_type(codec) == VT1708S
+-	    && (nid == 0x1a || nid == 0x1e)) {
+-		if (size < 4 * sizeof(unsigned int))
+-			return -ENOMEM;
+-		if (put_user(1, _tlv))	/* SNDRV_CTL_TLVT_DB_SCALE */
+-			return -EFAULT;
+-		if (put_user(2 * sizeof(unsigned int), _tlv + 1))
+-			return -EFAULT;
+-		if (put_user(0, _tlv + 2)) /* offset = 0 */
+-			return -EFAULT;
+-		if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
+-			return -EFAULT;
+-	}
+-	return 0;
+-}
+-
+-static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
+-				 struct snd_ctl_elem_info *uinfo)
+-{
+-	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+-	hda_nid_t nid = get_amp_nid(kcontrol);
+-
+-	if (get_codec_type(codec) == VT1708S
+-	    && (nid == 0x1a || nid == 0x1e)) {
+-		uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+-		uinfo->count = 2;
+-		uinfo->value.integer.min = 0;
+-		uinfo->value.integer.max = 3;
+-	}
+-	return 0;
+-}
+-
+ static void analog_low_current_mode(struct hda_codec *codec, int stream_idle);
+ static void set_jack_power_state(struct hda_codec *codec);
+ static int is_aa_path_mute(struct hda_codec *codec);
+@@ -3093,29 +3053,15 @@ static int patch_vt1708B_4ch(struct hda_codec *codec)
+ 
+ /* Patch for VT1708S */
+ 
+-/* VT1708S software backdoor based override for buggy hardware micboost
+- * setting */
+-#define MIC_BOOST_VOLUME(xname, nid) {				\
+-	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
+-	.name = xname,					\
+-	.index = 0,					\
+-	.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |	\
+-	SNDRV_CTL_ELEM_ACCESS_TLV_READ |		\
+-	SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,		\
+-	.info = mic_boost_volume_info,			\
+-	.get = snd_hda_mixer_amp_volume_get,		\
+-	.put = snd_hda_mixer_amp_volume_put,		\
+-	.tlv = { .c = mic_boost_tlv },			\
+-	.private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
+-
+ /* capture mixer elements */
+ static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
+ 	HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
+ 	HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
+ 	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
+ 	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
+-	MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
+-	MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
++	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
++			 HDA_INPUT),
+ 	{
+ 		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+ 		/* The multiple "Capture Source" controls confuse alsamixer
+@@ -3487,6 +3433,16 @@ static struct hda_amp_list vt1708S_loopbacks[] = {
+ };
+ #endif
+ 
++static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
++			       int offset, int num_steps, int step_size)
++{
++	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));
++}
++
+ static int patch_vt1708S(struct hda_codec *codec)
+ {
+ 	struct via_spec *spec;
+@@ -3523,6 +3479,8 @@ static int patch_vt1708S(struct hda_codec *codec)
+ 		spec->adc_nids = vt1708S_adc_nids;
+ 		spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
+ 		get_mux_nids(codec);
++		override_mic_boost(codec, 0x1a, 0, 3, 40);
++		override_mic_boost(codec, 0x1e, 0, 3, 40);
+ 		spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
+ 		spec->num_mixers++;
+ 	}
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0014-ALSA-HDA-VIA-Add-VT1718S-support.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0014-ALSA-HDA-VIA-Add-VT1718S-support.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,681 @@
+From 9072aed706cc7452dbfcfa7affae631b57a730df Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:34 +0800
+Subject: [PATCH 14/19] ALSA: HDA VIA: Add VT1718S support.
+
+commit eb7188cafcb7aa1419b8889494cdbd4e6a01da1c upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |  554 ++++++++++++++++++++++++++++++++++++++++++++-
+ 1 files changed, 545 insertions(+), 9 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 1e9108f..8ef845f 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -94,6 +94,7 @@ enum VIA_HDA_CODEC {
+ 	VT1708S,
+ 	VT1708BCE,
+ 	VT1702,
++	VT1718S,
+ 	CODEC_TYPES,
+ };
+ 
+@@ -183,6 +184,9 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 	else if ((dev_id & 0xfff) == 0x398
+ 		 && (dev_id >> 12) < 8)
+ 		codec_type = VT1702;
++	else if ((dev_id & 0xfff) == 0x428
++		 && (dev_id >> 12) < 8)
++		codec_type = VT1718S;
+ 	else
+ 		codec_type = UNKNOWN;
+ 	return codec_type;
+@@ -292,6 +296,11 @@ static hda_nid_t vt1702_adc_nids[3] = {
+ 	0x12, 0x20, 0x1F
+ };
+ 
++static hda_nid_t vt1718S_adc_nids[2] = {
++	/* ADC1-2 */
++	0x10, 0x11
++};
++
+ /* add dynamic controls */
+ static int via_add_control(struct via_spec *spec, int type, const char *name,
+ 			   unsigned long val)
+@@ -520,6 +529,67 @@ static void set_jack_power_state(struct hda_codec *codec)
+ 			snd_hda_codec_write(codec, 0x27, 0,
+ 					    AC_VERB_SET_POWER_STATE, parm);
+ 		}
++	}  else if (spec->codec_type == VT1718S) {
++		/* 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) */
++		snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* outputs */
++		/* PW3 (27h), MW2 (1ah), AOW3 (bh) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x27, &parm);
++		snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* PW2 (26h), AOW2 (ah) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x26, &parm);
++		snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* PW0/1 (24h/25h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x24, &parm);
++		set_pin_power_state(codec, 0x25, &parm);
++		if (!spec->hp_independent_mode) /* check for redirected HP */
++			set_pin_power_state(codec, 0x28, &parm);
++		snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		/* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
++		snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
++				    imux_is_smixer ? AC_PWRST_D0 : parm);
++		if (spec->hp_independent_mode) {
++			/* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
++			parm = AC_PWRST_D3;
++			set_pin_power_state(codec, 0x28, &parm);
++			snd_hda_codec_write(codec, 0x1b, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++			snd_hda_codec_write(codec, 0x34, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++			snd_hda_codec_write(codec, 0xc, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++		}
+ 	}
+ }
+ 
+@@ -580,11 +650,21 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
+ {
+ 	struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
+ 	struct via_spec *spec = codec->spec;
+-	hda_nid_t nid = spec->autocfg.hp_pins[0];
+-	unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
+-						 AC_VERB_GET_CONNECT_SEL,
+-						 0x00);
++	hda_nid_t nid;
++	unsigned int pinsel;
+ 
++	switch (spec->codec_type) {
++	case VT1718S:
++		nid = 0x34;
++		break;
++	default:
++		nid = spec->autocfg.hp_pins[0];
++		break;
++	}
++	/* use !! to translate conn sel 2 for VT1718S */
++	pinsel = !!snd_hda_codec_read(codec, nid, 0,
++				      AC_VERB_GET_CONNECT_SEL,
++				      0x00);
+ 	ucontrol->value.enumerated.item[0] = pinsel;
+ 
+ 	return 0;
+@@ -643,6 +723,16 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 	spec->hp_independent_mode = spec->hp_independent_mode_index == pinsel
+ 		? 1 : 0;
+ 
++	switch (spec->codec_type) {
++	case VT1718S:
++		nid = 0x34;
++		pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
++		spec->multiout.num_dacs = 4;
++		break;
++	default:
++		nid = spec->autocfg.hp_pins[0];
++		break;
++	}
+ 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, pinsel);
+ 
+ 	if (spec->multiout.hp_nid && spec->multiout.hp_nid
+@@ -653,7 +743,8 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 	update_side_mute_status(codec);
+ 	/* update HP volume/swtich active state */
+ 	if (spec->codec_type == VT1708S
+-	    || spec->codec_type == VT1702) {
++	    || spec->codec_type == VT1702
++	    || spec->codec_type == VT1718S) {
+ 		activate_ctl(codec, "Headphone Playback Volume",
+ 			     spec->hp_independent_mode);
+ 		activate_ctl(codec, "Headphone Playback Switch",
+@@ -766,7 +857,8 @@ static int via_smart51_get(struct snd_kcontrol *kcontrol,
+ 					       AC_VERB_GET_PIN_WIDGET_CONTROL,
+ 					       0);
+ 			if (i == AUTO_PIN_FRONT_MIC
+-			    && spec->hp_independent_mode)
++			    && spec->hp_independent_mode
++			    && spec->codec_type != VT1718S)
+ 				continue; /* ignore FMic for independent HP */
+ 			if (ctl & AC_PINCTL_IN_EN
+ 			    && !(ctl & AC_PINCTL_OUT_EN))
+@@ -790,7 +882,8 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol,
+ 	for (i = 0; i < ARRAY_SIZE(index); i++) {
+ 		hda_nid_t nid = spec->autocfg.input_pins[index[i]];
+ 		if (i == AUTO_PIN_FRONT_MIC
+-		    && spec->hp_independent_mode)
++		    && spec->hp_independent_mode
++		    && spec->codec_type != VT1718S)
+ 			continue; /* don't retask FMic for independent HP */
+ 		if (nid) {
+ 			unsigned int parm = snd_hda_codec_read(
+@@ -805,6 +898,10 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol,
+ 				mute_aa_path(codec, 1);
+ 				notify_aa_path_ctls(codec);
+ 			}
++			if (spec->codec_type == VT1718S)
++				snd_hda_codec_amp_stereo(
++					codec, nid, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++					HDA_AMP_UNMUTE);
+ 		}
+ 		if (i == AUTO_PIN_FRONT_MIC) {
+ 			if (spec->codec_type == VT1708S) {
+@@ -879,6 +976,11 @@ static int is_aa_path_mute(struct hda_codec *codec)
+ 		start_idx = 1;
+ 		end_idx = 3;
+ 		break;
++	case VT1718S:
++		nid_mixer = 0x21;
++		start_idx = 1;
++		end_idx = 3;
++		break;
+ 	default:
+ 		return 0;
+ 	}
+@@ -928,6 +1030,7 @@ static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
+ 		parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
+ 		break;
+ 	case VT1708S:
++	case VT1718S:
+ 		verb = 0xf73;
+ 		parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
+ 		break;
+@@ -1056,8 +1159,8 @@ static void playback_multi_pcm_prep_0(struct hda_codec *codec,
+ 	snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
+ 				   0, format);
+ 
+-	if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
+-	    !spec->hp_independent_mode)
++	if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT]
++	    && !spec->hp_independent_mode)
+ 		/* headphone out will just decode front left/right (stereo) */
+ 		snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
+ 					   0, format);
+@@ -3853,6 +3956,435 @@ static int patch_vt1702(struct hda_codec *codec)
+ 	return 0;
+ }
+ 
++/* Patch for VT1718S */
++
++/* capture mixer elements */
++static struct snd_kcontrol_new vt1718S_capture_mixer[] = {
++	HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
++			 HDA_INPUT),
++	{
++		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
++		/* The multiple "Capture Source" controls confuse alsamixer
++		 * So call somewhat different..
++		 */
++		.name = "Input Source",
++		.count = 2,
++		.info = via_mux_enum_info,
++		.get = via_mux_enum_get,
++		.put = via_mux_enum_put,
++	},
++	{ } /* end */
++};
++
++static struct hda_verb vt1718S_volume_init_verbs[] = {
++	/*
++	 * Unmute ADC0-1 and set the default input to mic-in
++	 */
++	{0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++
++
++	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
++	 * mixer widget
++	 */
++	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
++
++	/* Setup default input of Front HP to MW9 */
++	{0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
++	/* PW9 PW10 Output enable */
++	{0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
++	{0x2e, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
++	/* PW11 Input enable */
++	{0x2f, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_IN_EN},
++	/* Enable Boost Volume backdoor */
++	{0x1, 0xf88, 0x8},
++	/* MW0/1/2/3/4: un-mute index 0 (AOWx), mute index 1 (MW9) */
++	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
++	{0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
++	{0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
++	/* set MUX1 = 2 (AOW4), MUX2 = 1 (AOW3) */
++	{0x34, AC_VERB_SET_CONNECT_SEL, 0x2},
++	{0x35, AC_VERB_SET_CONNECT_SEL, 0x1},
++	/* Unmute MW4's index 0 */
++	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{ }
++};
++
++
++static struct hda_verb vt1718S_uniwill_init_verbs[] = {
++	{0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
++	{0x24, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x26, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x27, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{ }
++};
++
++static struct hda_pcm_stream vt1718S_pcm_analog_playback = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 10,
++	.nid = 0x8, /* NID to query formats and rates */
++	.ops = {
++		.open = via_playback_pcm_open,
++		.prepare = via_playback_multi_pcm_prepare,
++		.cleanup = via_playback_multi_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt1718S_pcm_analog_capture = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.nid = 0x10, /* NID to query formats and rates */
++	.ops = {
++		.open = via_pcm_open_close,
++		.prepare = via_capture_pcm_prepare,
++		.cleanup = via_capture_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt1718S_pcm_digital_playback = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.rates = SNDRV_PCM_RATE_48000,
++	/* NID is set in via_build_pcms */
++	.ops = {
++		.open = via_dig_playback_pcm_open,
++		.close = via_dig_playback_pcm_close,
++		.prepare = via_dig_playback_pcm_prepare,
++		.cleanup = via_dig_playback_pcm_cleanup
++	},
++};
++
++static struct hda_pcm_stream vt1718S_pcm_digital_capture = {
++	.substreams = 1,
++	.channels_min = 2,
++	.channels_max = 2,
++};
++
++/* fill in the dac_nids table from the parsed pin configuration */
++static int vt1718S_auto_fill_dac_nids(struct via_spec *spec,
++				     const struct auto_pin_cfg *cfg)
++{
++	int i;
++	hda_nid_t nid;
++
++	spec->multiout.num_dacs = cfg->line_outs;
++
++	spec->multiout.dac_nids = spec->private_dac_nids;
++
++	for (i = 0; i < 4; i++) {
++		nid = cfg->line_out_pins[i];
++		if (nid) {
++			/* config dac list */
++			switch (i) {
++			case AUTO_SEQ_FRONT:
++				spec->multiout.dac_nids[i] = 0x8;
++				break;
++			case AUTO_SEQ_CENLFE:
++				spec->multiout.dac_nids[i] = 0xa;
++				break;
++			case AUTO_SEQ_SURROUND:
++				spec->multiout.dac_nids[i] = 0x9;
++				break;
++			case AUTO_SEQ_SIDE:
++				spec->multiout.dac_nids[i] = 0xb;
++				break;
++			}
++		}
++	}
++
++	return 0;
++}
++
++/* add playback controls from the parsed DAC table */
++static int vt1718S_auto_create_multi_out_ctls(struct via_spec *spec,
++					     const struct auto_pin_cfg *cfg)
++{
++	char name[32];
++	static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
++	hda_nid_t nid_vols[] = {0x8, 0x9, 0xa, 0xb};
++	hda_nid_t nid_mutes[] = {0x24, 0x25, 0x26, 0x27};
++	hda_nid_t nid, nid_vol, nid_mute = 0;
++	int i, err;
++
++	for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
++		nid = cfg->line_out_pins[i];
++
++		if (!nid)
++			continue;
++		nid_vol = nid_vols[i];
++		nid_mute = nid_mutes[i];
++
++		if (i == AUTO_SEQ_CENLFE) {
++			/* Center/LFE */
++			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++					      "Center Playback Volume",
++					      HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
++								  HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++					      "LFE Playback Volume",
++					      HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
++								  HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE,
++				"Center Playback Switch",
++				HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE,
++				"LFE Playback Switch",
++				HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++		} else if (i == AUTO_SEQ_FRONT) {
++			/* Front */
++			sprintf(name, "%s Playback Volume", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_VOL, name,
++				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			sprintf(name, "%s Playback Switch", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE, name,
++				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++		} else {
++			sprintf(name, "%s Playback Volume", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_VOL, name,
++				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			sprintf(name, "%s Playback Switch", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE, name,
++				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++		}
++	}
++	return 0;
++}
++
++static int vt1718S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
++{
++	int err;
++
++	if (!pin)
++		return 0;
++
++	spec->multiout.hp_nid = 0xc; /* AOW4 */
++	spec->hp_independent_mode_index = 1;
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++			      "Headphone Playback Volume",
++			      HDA_COMPOSE_AMP_VAL(0xc, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
++			      "Headphone Playback Switch",
++			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	create_hp_imux(spec);
++	return 0;
++}
++
++/* create playback/capture controls for input pins */
++static int vt1718S_auto_create_analog_input_ctls(struct via_spec *spec,
++						const struct auto_pin_cfg *cfg)
++{
++	static char *labels[] = {
++		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
++	};
++	struct hda_input_mux *imux = &spec->private_imux[0];
++	int i, err, idx = 0;
++
++	/* for internal loopback recording select */
++	imux->items[imux->num_items].label = "Stereo Mixer";
++	imux->items[imux->num_items].index = 5;
++	imux->num_items++;
++
++	for (i = 0; i < AUTO_PIN_LAST; i++) {
++		if (!cfg->input_pins[i])
++			continue;
++
++		switch (cfg->input_pins[i]) {
++		case 0x2b: /* Mic */
++			idx = 1;
++			break;
++
++		case 0x2a: /* Line In */
++			idx = 2;
++			break;
++
++		case 0x29: /* Front Mic */
++			idx = 3;
++			break;
++
++		case 0x2c: /* CD */
++			idx = 0;
++			break;
++		}
++		err = via_new_analog_input(spec, labels[i], idx, 0x21);
++		if (err < 0)
++			return err;
++		imux->items[imux->num_items].label = labels[i];
++		imux->items[imux->num_items].index = idx;
++		imux->num_items++;
++	}
++	return 0;
++}
++
++static int vt1718S_parse_auto_config(struct hda_codec *codec)
++{
++	struct via_spec *spec = codec->spec;
++	int err;
++
++	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
++
++	if (err < 0)
++		return err;
++	err = vt1718S_auto_fill_dac_nids(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
++		return 0; /* can't find valid BIOS pin config */
++
++	err = vt1718S_auto_create_multi_out_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++	err = vt1718S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
++	if (err < 0)
++		return err;
++	err = vt1718S_auto_create_analog_input_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++
++	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
++
++	fill_dig_outs(codec);
++
++	if (spec->autocfg.dig_in_pin && codec->vendor_id == 0x11060428)
++		spec->dig_in_nid = 0x13;
++
++	if (spec->kctls.list)
++		spec->mixers[spec->num_mixers++] = spec->kctls.list;
++
++	spec->input_mux = &spec->private_imux[0];
++
++	if (spec->hp_mux)
++		spec->mixers[spec->num_mixers++] = via_hp_mixer;
++
++	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
++
++	return 1;
++}
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++static struct hda_amp_list vt1718S_loopbacks[] = {
++	{ 0x21, HDA_INPUT, 1 },
++	{ 0x21, HDA_INPUT, 2 },
++	{ 0x21, HDA_INPUT, 3 },
++	{ 0x21, HDA_INPUT, 4 },
++	{ } /* end */
++};
++#endif
++
++static int patch_vt1718S(struct hda_codec *codec)
++{
++	struct via_spec *spec;
++	int err;
++
++	/* create a codec specific record */
++	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
++	if (spec == NULL)
++		return -ENOMEM;
++
++	codec->spec = spec;
++
++	/* automatic parse from the BIOS config */
++	err = vt1718S_parse_auto_config(codec);
++	if (err < 0) {
++		via_free(codec);
++		return err;
++	} else if (!err) {
++		printk(KERN_INFO "hda_codec: Cannot set up configuration "
++		       "from BIOS.  Using genenic mode...\n");
++	}
++
++	spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
++	spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
++
++	spec->stream_name_analog = "VT1718S Analog";
++	spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
++	spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
++
++	spec->stream_name_digital = "VT1718S Digital";
++	spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
++	if (codec->vendor_id == 0x11060428)
++		spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
++
++	if (!spec->adc_nids && spec->input_mux) {
++		spec->adc_nids = vt1718S_adc_nids;
++		spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
++		get_mux_nids(codec);
++		override_mic_boost(codec, 0x1a, 0, 3, 40);
++		override_mic_boost(codec, 0x1e, 0, 3, 40);
++		spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
++		spec->num_mixers++;
++	}
++
++	codec->patch_ops = via_patch_ops;
++
++	codec->patch_ops.init = via_auto_init;
++	codec->patch_ops.unsol_event = via_unsol_event,
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++	spec->loopback.amplist = vt1718S_loopbacks;
++#endif
++
++	return 0;
++}
+ /*
+  * patch entries
+  */
+@@ -3925,6 +4457,10 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
+ 	  .patch = patch_vt1702},
+ 	{ .id = 0x11067398, .name = "VT1702",
+ 	  .patch = patch_vt1702},
++	{ .id = 0x11060428, .name = "VT1718S",
++	  .patch = patch_vt1718S},
++	{ .id = 0x11064428, .name = "VT1718S",
++	  .patch = patch_vt1718S},
+ 	{} /* terminator */
+ };
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0015-ALSA-HDA-VIA-Add-VT1828S-and-VT2020-support.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0015-ALSA-HDA-VIA-Add-VT1828S-and-VT2020-support.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,78 @@
+From 158f9c55820f79d4c53e48cc7650753a4b7ab226 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:39 +0800
+Subject: [PATCH 15/19] ALSA: HDA VIA: Add VT1828S and VT2020 support.
+
+commit bb3c6bfc3f7a5416d85c5dbc312e2d47fc672eef upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   26 +++++++++++++++++++++-----
+ 1 files changed, 21 insertions(+), 5 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 8ef845f..e30d590 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -187,6 +187,8 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 	else if ((dev_id & 0xfff) == 0x428
+ 		 && (dev_id >> 12) < 8)
+ 		codec_type = VT1718S;
++	else if (dev_id == 0x0441 || dev_id == 0x4441)
++		codec_type = VT1718S;
+ 	else
+ 		codec_type = UNKNOWN;
+ 	return codec_type;
+@@ -4355,21 +4357,31 @@ static int patch_vt1718S(struct hda_codec *codec)
+ 	spec->init_verbs[spec->num_iverbs++] = vt1718S_volume_init_verbs;
+ 	spec->init_verbs[spec->num_iverbs++] = vt1718S_uniwill_init_verbs;
+ 
+-	spec->stream_name_analog = "VT1718S Analog";
++	if (codec->vendor_id == 0x11060441)
++		spec->stream_name_analog = "VT2020 Analog";
++	else if (codec->vendor_id == 0x11064441)
++		spec->stream_name_analog = "VT1828S Analog";
++	else
++		spec->stream_name_analog = "VT1718S Analog";
+ 	spec->stream_analog_playback = &vt1718S_pcm_analog_playback;
+ 	spec->stream_analog_capture = &vt1718S_pcm_analog_capture;
+ 
+-	spec->stream_name_digital = "VT1718S Digital";
++	if (codec->vendor_id == 0x11060441)
++		spec->stream_name_digital = "VT2020 Digital";
++	else if (codec->vendor_id == 0x11064441)
++		spec->stream_name_digital = "VT1828S Digital";
++	else
++		spec->stream_name_digital = "VT1718S Digital";
+ 	spec->stream_digital_playback = &vt1718S_pcm_digital_playback;
+-	if (codec->vendor_id == 0x11060428)
++	if (codec->vendor_id == 0x11060428 || codec->vendor_id == 0x11060441)
+ 		spec->stream_digital_capture = &vt1718S_pcm_digital_capture;
+ 
+ 	if (!spec->adc_nids && spec->input_mux) {
+ 		spec->adc_nids = vt1718S_adc_nids;
+ 		spec->num_adc_nids = ARRAY_SIZE(vt1718S_adc_nids);
+ 		get_mux_nids(codec);
+-		override_mic_boost(codec, 0x1a, 0, 3, 40);
+-		override_mic_boost(codec, 0x1e, 0, 3, 40);
++		override_mic_boost(codec, 0x2b, 0, 3, 40);
++		override_mic_boost(codec, 0x29, 0, 3, 40);
+ 		spec->mixers[spec->num_mixers] = vt1718S_capture_mixer;
+ 		spec->num_mixers++;
+ 	}
+@@ -4461,6 +4473,10 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
+ 	  .patch = patch_vt1718S},
+ 	{ .id = 0x11064428, .name = "VT1718S",
+ 	  .patch = patch_vt1718S},
++	{ .id = 0x11060441, .name = "VT2020",
++	  .patch = patch_vt1718S},
++	{ .id = 0x11064441, .name = "VT1828S",
++	  .patch = patch_vt1718S},
+ 	{} /* terminator */
+ };
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0016-ALSA-HDA-VIA-Add-VT1716S-support.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0016-ALSA-HDA-VIA-Add-VT1716S-support.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,779 @@
+From 1a51904c20e6ef6da30d8aca4e97bda6d622cd6a Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:41 +0800
+Subject: [PATCH 16/19] ALSA: HDA VIA: Add VT1716S support.
+
+commit f3db423df84570c9950754a5771ad26f0111235f upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |  648 ++++++++++++++++++++++++++++++++++++++++++++-
+ 1 files changed, 644 insertions(+), 4 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index e30d590..21309f9 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -95,12 +95,13 @@ enum VIA_HDA_CODEC {
+ 	VT1708BCE,
+ 	VT1702,
+ 	VT1718S,
++	VT1716S,
+ 	CODEC_TYPES,
+ };
+ 
+ struct via_spec {
+ 	/* codec parameterization */
+-	struct snd_kcontrol_new *mixers[4];
++	struct snd_kcontrol_new *mixers[6];
+ 	unsigned int num_mixers;
+ 
+ 	struct hda_verb *init_verbs[5];
+@@ -143,7 +144,7 @@ struct via_spec {
+ 	unsigned int hp_independent_mode;
+ 	unsigned int hp_independent_mode_index;
+ 	unsigned int smart51_enabled;
+-
++	unsigned int dmic_enabled;
+ 	enum VIA_HDA_CODEC codec_type;
+ 
+ 	/* work to check hp jack state */
+@@ -187,6 +188,8 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 	else if ((dev_id & 0xfff) == 0x428
+ 		 && (dev_id >> 12) < 8)
+ 		codec_type = VT1718S;
++	else if (dev_id == 0x0433 || dev_id == 0xa721)
++		codec_type = VT1716S;
+ 	else if (dev_id == 0x0441 || dev_id == 0x4441)
+ 		codec_type = VT1718S;
+ 	else
+@@ -197,6 +200,7 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ #define VIA_HP_EVENT		0x01
+ #define VIA_GPIO_EVENT		0x02
+ #define VIA_JACK_EVENT		0x04
++#define VIA_MONO_EVENT		0x08
+ 
+ enum {
+ 	VIA_CTL_WIDGET_VOL,
+@@ -303,6 +307,11 @@ static hda_nid_t vt1718S_adc_nids[2] = {
+ 	0x10, 0x11
+ };
+ 
++static hda_nid_t vt1716S_adc_nids[2] = {
++	/* ADC1-2 */
++	0x13, 0x14
++};
++
+ /* add dynamic controls */
+ static int via_add_control(struct via_spec *spec, int type, const char *name,
+ 			   unsigned long val)
+@@ -592,6 +601,106 @@ static void set_jack_power_state(struct hda_codec *codec)
+ 			snd_hda_codec_write(codec, 0xc, 0,
+ 					    AC_VERB_SET_POWER_STATE, parm);
+ 		}
++	} else if (spec->codec_type == VT1716S) {
++		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) */
++		snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		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
++			snd_hda_codec_write(
++				codec, 0x22, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
++
++		/* SW2(26h), AIW1(14h) */
++		snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* outputs */
++		/* PW0 (19h), SW1 (18h), AOW1 (11h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x19, &parm);
++		/* Smart 5.1 PW2(1bh) */
++		if (spec->smart51_enabled)
++			set_pin_power_state(codec, 0x1b, &parm);
++		snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* PW7 (23h), SW3 (27h), AOW3 (25h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x23, &parm);
++		/* Smart 5.1 PW1(1ah) */
++		if (spec->smart51_enabled)
++			set_pin_power_state(codec, 0x1a, &parm);
++		snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* Smart 5.1 PW5(1eh) */
++		if (spec->smart51_enabled)
++			set_pin_power_state(codec, 0x1e, &parm);
++		snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* Mono out */
++		/* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
++		present = snd_hda_codec_read(
++			codec, 0x1c, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++		if (present)
++			mono_out = 0;
++		else {
++			present = snd_hda_codec_read(
++				codec, 0x1d, 0, AC_VERB_GET_PIN_SENSE, 0)
++				& 0x80000000;
++			if (!spec->hp_independent_mode && present)
++				mono_out = 0;
++			else
++				mono_out = 1;
++		}
++		parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
++		snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++		snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE,
++				    parm);
++
++		/* 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 */
++		if (spec->hp_independent_mode)
++			snd_hda_codec_write(codec, 0x25, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++
++		/* force to D0 for internal Speaker */
++		/* MW0 (16h), AOW0 (10h) */
++		snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
++				    imux_is_smixer ? AC_PWRST_D0 : parm);
++		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
++				    mono_out ? AC_PWRST_D0 : parm);
+ 	}
+ }
+ 
+@@ -746,7 +855,8 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 	/* update HP volume/swtich active state */
+ 	if (spec->codec_type == VT1708S
+ 	    || spec->codec_type == VT1702
+-	    || spec->codec_type == VT1718S) {
++	    || spec->codec_type == VT1718S
++	    || spec->codec_type == VT1716S) {
+ 		activate_ctl(codec, "Headphone Playback Volume",
+ 			     spec->hp_independent_mode);
+ 		activate_ctl(codec, "Headphone Playback Switch",
+@@ -805,6 +915,7 @@ static void mute_aa_path(struct hda_codec *codec, int mute)
+ 	case VT1708B_8CH:
+ 	case VT1708B_4CH:
+ 	case VT1708S:
++	case VT1716S:
+ 		nid_mixer = 0x16;
+ 		start_idx = 2;
+ 		end_idx = 4;
+@@ -906,7 +1017,8 @@ static int via_smart51_put(struct snd_kcontrol *kcontrol,
+ 					HDA_AMP_UNMUTE);
+ 		}
+ 		if (i == AUTO_PIN_FRONT_MIC) {
+-			if (spec->codec_type == VT1708S) {
++			if (spec->codec_type == VT1708S
++			    || spec->codec_type == VT1716S) {
+ 				/* input = index 1 (AOW3) */
+ 				snd_hda_codec_write(
+ 					codec, nid, 0,
+@@ -969,6 +1081,7 @@ static int is_aa_path_mute(struct hda_codec *codec)
+ 	case VT1708B_8CH:
+ 	case VT1708B_4CH:
+ 	case VT1708S:
++	case VT1716S:
+ 		nid_mixer = 0x16;
+ 		start_idx = 2;
+ 		end_idx = 4;
+@@ -1033,6 +1146,7 @@ static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
+ 		break;
+ 	case VT1708S:
+ 	case VT1718S:
++	case VT1716S:
+ 		verb = 0xf73;
+ 		parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
+ 		break;
+@@ -1483,6 +1597,36 @@ static void via_hp_automute(struct hda_codec *codec)
+ 	}
+ }
+ 
++/* mute mono out if HP or Line out is plugged */
++static void via_mono_automute(struct hda_codec *codec)
++{
++	unsigned int hp_present, lineout_present;
++	struct via_spec *spec = codec->spec;
++
++	if (spec->codec_type != VT1716S)
++		return;
++
++	lineout_present = snd_hda_codec_read(
++		codec, spec->autocfg.line_out_pins[0], 0,
++		AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++
++	/* Mute Mono Out if Line Out is plugged */
++	if (lineout_present) {
++		snd_hda_codec_amp_stereo(
++			codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE, HDA_AMP_MUTE);
++		return;
++	}
++
++	hp_present = snd_hda_codec_read(
++		codec, spec->autocfg.hp_pins[0], 0,
++		AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++
++	if (!spec->hp_independent_mode)
++		snd_hda_codec_amp_stereo(
++			codec, 0x2A, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++			hp_present ? HDA_AMP_MUTE : 0);
++}
++
+ static void via_gpio_control(struct hda_codec *codec)
+ {
+ 	unsigned int gpio_data;
+@@ -1542,6 +1686,8 @@ static void via_unsol_event(struct hda_codec *codec,
+ 		via_gpio_control(codec);
+ 	if (res & VIA_JACK_EVENT)
+ 		set_jack_power_state(codec);
++	if (res & VIA_MONO_EVENT)
++		via_mono_automute(codec);
+ }
+ 
+ static int via_init(struct hda_codec *codec)
+@@ -4397,6 +4543,496 @@ static int patch_vt1718S(struct hda_codec *codec)
+ 
+ 	return 0;
+ }
++
++/* 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;
++	set_jack_power_state(codec);
++
++	return 1;
++}
++
++/* capture mixer elements */
++static struct snd_kcontrol_new vt1716S_capture_mixer[] = {
++	HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x1A, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x1E, 0x0,
++			 HDA_INPUT),
++	{
++		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
++		.name = "Input Source",
++		.count = 1,
++		.info = via_mux_enum_info,
++		.get = via_mux_enum_get,
++		.put = via_mux_enum_put,
++	},
++	{ } /* end */
++};
++
++static struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
++	HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
++	{
++	 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
++	 .name = "Digital Mic Capture Switch",
++	 .count = 1,
++	 .info = vt1716s_dmic_info,
++	 .get = vt1716s_dmic_get,
++	 .put = vt1716s_dmic_put,
++	 },
++	{}			/* end */
++};
++
++
++/* mono-out mixer elements */
++static struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
++	HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
++	{ } /* end */
++};
++
++static struct hda_verb vt1716S_volume_init_verbs[] = {
++	/*
++	 * Unmute ADC0-1 and set the default input to mic-in
++	 */
++	{0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++
++
++	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
++	 * mixer widget
++	 */
++	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
++	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
++	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
++	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
++	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
++	{0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
++
++	/* MUX Indices: Stereo Mixer = 5 */
++	{0x17, AC_VERB_SET_CONNECT_SEL, 0x5},
++
++	/* Setup default input of PW4 to MW0 */
++	{0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
++
++	/* Setup default input of SW1 as MW0 */
++	{0x18, AC_VERB_SET_CONNECT_SEL, 0x1},
++
++	/* Setup default input of SW4 as AOW0 */
++	{0x28, AC_VERB_SET_CONNECT_SEL, 0x1},
++
++	/* PW9 PW10 Output enable */
++	{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
++	{0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
++
++	/* Unmute SW1, PW12 */
++	{0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
++	/* PW12 Output enable */
++	{0x2a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
++	/* Enable Boost Volume backdoor */
++	{0x1, 0xf8a, 0x80},
++	/* don't bybass mixer */
++	{0x1, 0xf88, 0xc0},
++	/* Enable mono output */
++	{0x1, 0xf90, 0x08},
++	{ }
++};
++
++
++static struct hda_verb vt1716S_uniwill_init_verbs[] = {
++	{0x1d, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT},
++	{0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x1c, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_MONO_EVENT | VIA_JACK_EVENT},
++	{0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x23, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{ }
++};
++
++static struct hda_pcm_stream vt1716S_pcm_analog_playback = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 6,
++	.nid = 0x10, /* NID to query formats and rates */
++	.ops = {
++		.open = via_playback_pcm_open,
++		.prepare = via_playback_multi_pcm_prepare,
++		.cleanup = via_playback_multi_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt1716S_pcm_analog_capture = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.nid = 0x13, /* NID to query formats and rates */
++	.ops = {
++		.open = via_pcm_open_close,
++		.prepare = via_capture_pcm_prepare,
++		.cleanup = via_capture_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt1716S_pcm_digital_playback = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.rates = SNDRV_PCM_RATE_48000,
++	/* NID is set in via_build_pcms */
++	.ops = {
++		.open = via_dig_playback_pcm_open,
++		.close = via_dig_playback_pcm_close,
++		.prepare = via_dig_playback_pcm_prepare,
++		.cleanup = via_dig_playback_pcm_cleanup
++	},
++};
++
++/* fill in the dac_nids table from the parsed pin configuration */
++static int vt1716S_auto_fill_dac_nids(struct via_spec *spec,
++				      const struct auto_pin_cfg *cfg)
++{	int i;
++	hda_nid_t nid;
++
++	spec->multiout.num_dacs = cfg->line_outs;
++
++	spec->multiout.dac_nids = spec->private_dac_nids;
++
++	for (i = 0; i < 3; i++) {
++		nid = cfg->line_out_pins[i];
++		if (nid) {
++			/* config dac list */
++			switch (i) {
++			case AUTO_SEQ_FRONT:
++				spec->multiout.dac_nids[i] = 0x10;
++				break;
++			case AUTO_SEQ_CENLFE:
++				spec->multiout.dac_nids[i] = 0x25;
++				break;
++			case AUTO_SEQ_SURROUND:
++				spec->multiout.dac_nids[i] = 0x11;
++				break;
++			}
++		}
++	}
++
++	return 0;
++}
++
++/* add playback controls from the parsed DAC table */
++static int vt1716S_auto_create_multi_out_ctls(struct via_spec *spec,
++					      const struct auto_pin_cfg *cfg)
++{
++	char name[32];
++	static const char *chname[3] = { "Front", "Surround", "C/LFE" };
++	hda_nid_t nid_vols[] = {0x10, 0x11, 0x25};
++	hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x27};
++	hda_nid_t nid, nid_vol, nid_mute;
++	int i, err;
++
++	for (i = 0; i <= AUTO_SEQ_CENLFE; i++) {
++		nid = cfg->line_out_pins[i];
++
++		if (!nid)
++			continue;
++
++		nid_vol = nid_vols[i];
++		nid_mute = nid_mutes[i];
++
++		if (i == AUTO_SEQ_CENLFE) {
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_VOL,
++				"Center Playback Volume",
++				HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0, HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_VOL,
++				"LFE Playback Volume",
++				HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE,
++				"Center Playback Switch",
++				HDA_COMPOSE_AMP_VAL(nid_mute, 1, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE,
++				"LFE Playback Switch",
++				HDA_COMPOSE_AMP_VAL(nid_mute, 2, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++		} else if (i == AUTO_SEQ_FRONT) {
++
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_VOL,
++				"Master Front Playback Volume",
++				HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
++			if (err < 0)
++				return err;
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE,
++				"Master Front Playback Switch",
++				HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_INPUT));
++			if (err < 0)
++				return err;
++
++			sprintf(name, "%s Playback Volume", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_VOL, name,
++				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			sprintf(name, "%s Playback Switch", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE, name,
++				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++		} else {
++			sprintf(name, "%s Playback Volume", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_VOL, name,
++				HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT));
++			if (err < 0)
++				return err;
++			sprintf(name, "%s Playback Switch", chname[i]);
++			err = via_add_control(
++				spec, VIA_CTL_WIDGET_MUTE, name,
++				HDA_COMPOSE_AMP_VAL(nid_mute, 3, 0,
++						    HDA_OUTPUT));
++			if (err < 0)
++				return err;
++		}
++	}
++	return 0;
++}
++
++static int vt1716S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
++{
++	int err;
++
++	if (!pin)
++		return 0;
++
++	spec->multiout.hp_nid = 0x25; /* AOW3 */
++	spec->hp_independent_mode_index = 1;
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++			      "Headphone Playback Volume",
++			      HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
++			      "Headphone Playback Switch",
++			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	create_hp_imux(spec);
++	return 0;
++}
++
++/* create playback/capture controls for input pins */
++static int vt1716S_auto_create_analog_input_ctls(struct via_spec *spec,
++						const struct auto_pin_cfg *cfg)
++{
++	static char *labels[] = {
++		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
++	};
++	struct hda_input_mux *imux = &spec->private_imux[0];
++	int i, err, idx = 0;
++
++	/* for internal loopback recording select */
++	imux->items[imux->num_items].label = "Stereo Mixer";
++	imux->items[imux->num_items].index = 5;
++	imux->num_items++;
++
++	for (i = 0; i < AUTO_PIN_LAST; i++) {
++		if (!cfg->input_pins[i])
++			continue;
++
++		switch (cfg->input_pins[i]) {
++		case 0x1a: /* Mic */
++			idx = 2;
++			break;
++
++		case 0x1b: /* Line In */
++			idx = 3;
++			break;
++
++		case 0x1e: /* Front Mic */
++			idx = 4;
++			break;
++
++		case 0x1f: /* CD */
++			idx = 1;
++			break;
++		}
++		err = via_new_analog_input(spec, labels[i], idx, 0x16);
++		if (err < 0)
++			return err;
++		imux->items[imux->num_items].label = labels[i];
++		imux->items[imux->num_items].index = idx-1;
++		imux->num_items++;
++	}
++	return 0;
++}
++
++static int vt1716S_parse_auto_config(struct hda_codec *codec)
++{
++	struct via_spec *spec = codec->spec;
++	int err;
++
++	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
++	if (err < 0)
++		return err;
++	err = vt1716S_auto_fill_dac_nids(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
++		return 0; /* can't find valid BIOS pin config */
++
++	err = vt1716S_auto_create_multi_out_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++	err = vt1716S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
++	if (err < 0)
++		return err;
++	err = vt1716S_auto_create_analog_input_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++
++	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
++
++	fill_dig_outs(codec);
++
++	if (spec->kctls.list)
++		spec->mixers[spec->num_mixers++] = spec->kctls.list;
++
++	spec->input_mux = &spec->private_imux[0];
++
++	if (spec->hp_mux)
++		spec->mixers[spec->num_mixers++] = via_hp_mixer;
++
++	spec->mixers[spec->num_mixers++] = via_smart51_mixer;
++
++	return 1;
++}
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++static struct hda_amp_list vt1716S_loopbacks[] = {
++	{ 0x16, HDA_INPUT, 1 },
++	{ 0x16, HDA_INPUT, 2 },
++	{ 0x16, HDA_INPUT, 3 },
++	{ 0x16, HDA_INPUT, 4 },
++	{ } /* end */
++};
++#endif
++
++static int patch_vt1716S(struct hda_codec *codec)
++{
++	struct via_spec *spec;
++	int err;
++
++	/* create a codec specific record */
++	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
++	if (spec == NULL)
++		return -ENOMEM;
++
++	codec->spec = spec;
++
++	/* automatic parse from the BIOS config */
++	err = vt1716S_parse_auto_config(codec);
++	if (err < 0) {
++		via_free(codec);
++		return err;
++	} else if (!err) {
++		printk(KERN_INFO "hda_codec: Cannot set up configuration "
++		       "from BIOS.  Using genenic mode...\n");
++	}
++
++	spec->init_verbs[spec->num_iverbs++]  = vt1716S_volume_init_verbs;
++	spec->init_verbs[spec->num_iverbs++] = vt1716S_uniwill_init_verbs;
++
++	spec->stream_name_analog = "VT1716S Analog";
++	spec->stream_analog_playback = &vt1716S_pcm_analog_playback;
++	spec->stream_analog_capture = &vt1716S_pcm_analog_capture;
++
++	spec->stream_name_digital = "VT1716S Digital";
++	spec->stream_digital_playback = &vt1716S_pcm_digital_playback;
++
++	if (!spec->adc_nids && spec->input_mux) {
++		spec->adc_nids = vt1716S_adc_nids;
++		spec->num_adc_nids = ARRAY_SIZE(vt1716S_adc_nids);
++		get_mux_nids(codec);
++		override_mic_boost(codec, 0x1a, 0, 3, 40);
++		override_mic_boost(codec, 0x1e, 0, 3, 40);
++		spec->mixers[spec->num_mixers] = vt1716S_capture_mixer;
++		spec->num_mixers++;
++	}
++
++	spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
++	spec->num_mixers++;
++
++	spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
++
++	codec->patch_ops = via_patch_ops;
++
++	codec->patch_ops.init = via_auto_init;
++	codec->patch_ops.unsol_event = via_unsol_event,
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++	spec->loopback.amplist = vt1716S_loopbacks;
++#endif
++
++	return 0;
++}
+ /*
+  * patch entries
+  */
+@@ -4477,6 +5113,10 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
+ 	  .patch = patch_vt1718S},
+ 	{ .id = 0x11064441, .name = "VT1828S",
+ 	  .patch = patch_vt1718S},
++	{ .id = 0x11060433, .name = "VT1716S",
++	  .patch = patch_vt1716S},
++	{ .id = 0x1106a721, .name = "VT1716S",
++	  .patch = patch_vt1716S},
+ 	{} /* terminator */
+ };
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0017-ALSA-HDA-VIA-Add-VT2002P-support.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0017-ALSA-HDA-VIA-Add-VT2002P-support.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,817 @@
+From 813f378b9d2486cd4bcff07f25406de4f1401954 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:43 +0800
+Subject: [PATCH 17/19] ALSA: HDA VIA: Add VT2002P support.
+
+commit 25eaba2f8a6877ba6f58197c4723c2433a316e09 upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |  663 ++++++++++++++++++++++++++++++++++++++++++++-
+ 1 files changed, 659 insertions(+), 4 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index 21309f9..e2635ed 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -96,6 +96,7 @@ enum VIA_HDA_CODEC {
+ 	VT1702,
+ 	VT1718S,
+ 	VT1716S,
++	VT2002P,
+ 	CODEC_TYPES,
+ };
+ 
+@@ -192,6 +193,8 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 		codec_type = VT1716S;
+ 	else if (dev_id == 0x0441 || dev_id == 0x4441)
+ 		codec_type = VT1718S;
++	else if (dev_id == 0x0438 || dev_id == 0x4438)
++		codec_type = VT2002P;
+ 	else
+ 		codec_type = UNKNOWN;
+ 	return codec_type;
+@@ -201,11 +204,14 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ #define VIA_GPIO_EVENT		0x02
+ #define VIA_JACK_EVENT		0x04
+ #define VIA_MONO_EVENT		0x08
++#define VIA_SPEAKER_EVENT	0x10
++#define VIA_BIND_HP_EVENT	0x20
+ 
+ enum {
+ 	VIA_CTL_WIDGET_VOL,
+ 	VIA_CTL_WIDGET_MUTE,
+ 	VIA_CTL_WIDGET_ANALOG_MUTE,
++	VIA_CTL_WIDGET_BIND_PIN_MUTE,
+ };
+ 
+ enum {
+@@ -270,10 +276,106 @@ static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
+ 			.put = analog_input_switch_put,			\
+ 			.private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
+ 
++static void via_hp_bind_automute(struct hda_codec *codec);
++
++static int bind_pin_switch_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 i;
++	int change = 0;
++
++	long *valp = ucontrol->value.integer.value;
++	int lmute, rmute;
++	if (strstr(kcontrol->id.name, "Switch") == NULL) {
++		snd_printd("Invalid control!\n");
++		return change;
++	}
++	change = snd_hda_mixer_amp_switch_put(kcontrol,
++					      ucontrol);
++	/* Get mute value */
++	lmute = *valp ? 0 : HDA_AMP_MUTE;
++	valp++;
++	rmute = *valp ? 0 : HDA_AMP_MUTE;
++
++	/* Set hp pins */
++	if (!spec->hp_independent_mode) {
++		for (i = 0; i < spec->autocfg.hp_outs; i++) {
++			snd_hda_codec_amp_update(
++				codec, spec->autocfg.hp_pins[i],
++				0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++				lmute);
++			snd_hda_codec_amp_update(
++				codec, spec->autocfg.hp_pins[i],
++				1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++				rmute);
++		}
++	}
++
++	if (!lmute && !rmute) {
++		/* Line Outs */
++		for (i = 0; i < spec->autocfg.line_outs; i++)
++			snd_hda_codec_amp_stereo(
++				codec, spec->autocfg.line_out_pins[i],
++				HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
++		/* Speakers */
++		for (i = 0; i < spec->autocfg.speaker_outs; i++)
++			snd_hda_codec_amp_stereo(
++				codec, spec->autocfg.speaker_pins[i],
++				HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
++		/* unmute */
++		via_hp_bind_automute(codec);
++
++	} else {
++		if (lmute) {
++			/* Mute all left channels */
++			for (i = 1; i < spec->autocfg.line_outs; i++)
++				snd_hda_codec_amp_update(
++					codec,
++					spec->autocfg.line_out_pins[i],
++					0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++					lmute);
++			for (i = 0; i < spec->autocfg.speaker_outs; i++)
++				snd_hda_codec_amp_update(
++					codec,
++					spec->autocfg.speaker_pins[i],
++					0, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++					lmute);
++		}
++		if (rmute) {
++			/* mute all right channels */
++			for (i = 1; i < spec->autocfg.line_outs; i++)
++				snd_hda_codec_amp_update(
++					codec,
++					spec->autocfg.line_out_pins[i],
++					1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++					rmute);
++			for (i = 0; i < spec->autocfg.speaker_outs; i++)
++				snd_hda_codec_amp_update(
++					codec,
++					spec->autocfg.speaker_pins[i],
++					1, HDA_OUTPUT, 0, HDA_AMP_MUTE,
++					rmute);
++		}
++	}
++	return change;
++}
++
++#define BIND_PIN_MUTE							\
++	{		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,		\
++			.name = NULL,					\
++			.index = 0,					\
++			.info = snd_hda_mixer_amp_switch_info,		\
++			.get = snd_hda_mixer_amp_switch_get,		\
++			.put = bind_pin_switch_put,			\
++			.private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
++
+ static struct snd_kcontrol_new vt1708_control_templates[] = {
+ 	HDA_CODEC_VOLUME(NULL, 0, 0, 0),
+ 	HDA_CODEC_MUTE(NULL, 0, 0, 0),
+ 	ANALOG_INPUT_MUTE,
++	BIND_PIN_MUTE,
+ };
+ 
+ 
+@@ -312,6 +414,11 @@ static hda_nid_t vt1716S_adc_nids[2] = {
+ 	0x13, 0x14
+ };
+ 
++static hda_nid_t vt2002P_adc_nids[2] = {
++	/* ADC1-2 */
++	0x10, 0x11
++};
++
+ /* add dynamic controls */
+ static int via_add_control(struct via_spec *spec, int type, const char *name,
+ 			   unsigned long val)
+@@ -394,10 +501,13 @@ static void via_auto_init_hp_out(struct hda_codec *codec)
+ {
+ 	struct via_spec *spec = codec->spec;
+ 	hda_nid_t pin;
++	int i;
+ 
+-	pin = spec->autocfg.hp_pins[0];
+-	if (pin) /* connect to front */
+-		via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
++	for (i = 0; i < spec->autocfg.hp_outs; i++) {
++		pin = spec->autocfg.hp_pins[i];
++		if (pin) /* connect to front */
++			via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
++	}
+ }
+ 
+ static void via_auto_init_analog_input(struct hda_codec *codec)
+@@ -701,6 +811,107 @@ static void set_jack_power_state(struct hda_codec *codec)
+ 				    imux_is_smixer ? AC_PWRST_D0 : parm);
+ 		snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
+ 				    mono_out ? AC_PWRST_D0 : parm);
++	} else if (spec->codec_type == VT2002P) {
++		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);
++		if (imux_is_smixer)
++			parm = AC_PWRST_D0;
++		/* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
++		snd_hda_codec_write(codec, 0x1e, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x1f, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x10, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x11, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++
++		/* outputs */
++		/* AOW0 (8h)*/
++		snd_hda_codec_write(codec, 0x8, 0,
++				    AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++
++		/* PW4 (26h), MW4 (1ch), MUX4(37h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x26, &parm);
++		snd_hda_codec_write(codec, 0x1c, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x37,
++				    0, AC_VERB_SET_POWER_STATE, parm);
++
++		/* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x25, &parm);
++		snd_hda_codec_write(codec, 0x19, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x35, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		if (spec->hp_independent_mode)	{
++			snd_hda_codec_write(codec, 0x9, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++		}
++
++		/* Class-D */
++		/* PW0 (24h), MW0(18h), MUX0(34h) */
++		present = snd_hda_codec_read(
++			codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x24, &parm);
++		if (present) {
++			snd_hda_codec_write(
++				codec, 0x18, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
++			snd_hda_codec_write(
++				codec, 0x34, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
++		} else {
++			snd_hda_codec_write(
++				codec, 0x18, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++			snd_hda_codec_write(
++				codec, 0x34, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++		}
++
++		/* Mono Out */
++		/* PW15 (31h), MW8(17h), MUX8(3bh) */
++		present = snd_hda_codec_read(
++			codec, 0x26, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x31, &parm);
++		if (present) {
++			snd_hda_codec_write(
++				codec, 0x17, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
++			snd_hda_codec_write(
++				codec, 0x3b, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
++		} else {
++			snd_hda_codec_write(
++				codec, 0x17, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++			snd_hda_codec_write(
++				codec, 0x3b, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++		}
++
++		/* MW9 (21h) */
++		if (imux_is_smixer || !is_aa_path_mute(codec))
++			snd_hda_codec_write(
++				codec, 0x21, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++		else
++			snd_hda_codec_write(
++				codec, 0x21, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
+ 	}
+ }
+ 
+@@ -768,6 +979,9 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
+ 	case VT1718S:
+ 		nid = 0x34;
+ 		break;
++	case VT2002P:
++		nid = 0x35;
++		break;
+ 	default:
+ 		nid = spec->autocfg.hp_pins[0];
+ 		break;
+@@ -840,6 +1054,9 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 		pinsel = pinsel ? 2 : 0; /* indep HP use AOW4 (index 2) */
+ 		spec->multiout.num_dacs = 4;
+ 		break;
++	case VT2002P:
++		nid = 0x35;
++		break;
+ 	default:
+ 		nid = spec->autocfg.hp_pins[0];
+ 		break;
+@@ -856,7 +1073,8 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 	if (spec->codec_type == VT1708S
+ 	    || spec->codec_type == VT1702
+ 	    || spec->codec_type == VT1718S
+-	    || spec->codec_type == VT1716S) {
++	    || spec->codec_type == VT1716S
++	    || spec->codec_type == VT2002P) {
+ 		activate_ctl(codec, "Headphone Playback Volume",
+ 			     spec->hp_independent_mode);
+ 		activate_ctl(codec, "Headphone Playback Switch",
+@@ -1096,6 +1314,11 @@ static int is_aa_path_mute(struct hda_codec *codec)
+ 		start_idx = 1;
+ 		end_idx = 3;
+ 		break;
++	case VT2002P:
++		nid_mixer = 0x21;
++		start_idx = 0;
++		end_idx = 2;
++		break;
+ 	default:
+ 		return 0;
+ 	}
+@@ -1154,6 +1377,10 @@ static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
+ 		verb = 0xf73;
+ 		parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
+ 		break;
++	case VT2002P:
++		verb = 0xf93;
++		parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
++		break;
+ 	default:
+ 		return;		/* other codecs are not supported */
+ 	}
+@@ -1675,6 +1902,66 @@ static void via_gpio_control(struct hda_codec *codec)
+ 	}
+ }
+ 
++/* mute Internal-Speaker if HP is plugged */
++static void via_speaker_automute(struct hda_codec *codec)
++{
++	unsigned int hp_present;
++	struct via_spec *spec = codec->spec;
++
++	if (spec->codec_type != VT2002P)
++		return;
++
++	hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
++				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++
++	if (!spec->hp_independent_mode) {
++		struct snd_ctl_elem_id id;
++		snd_hda_codec_amp_stereo(
++			codec, spec->autocfg.speaker_pins[0], HDA_OUTPUT, 0,
++			HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
++		/* notify change */
++		memset(&id, 0, sizeof(id));
++		id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
++		strcpy(id.name, "Speaker Playback Switch");
++		snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE,
++			       &id);
++	}
++}
++
++/* mute line-out and internal speaker if HP is plugged */
++static void via_hp_bind_automute(struct hda_codec *codec)
++{
++	unsigned int hp_present, present = 0;
++	struct via_spec *spec = codec->spec;
++	int i;
++
++	if (!spec->autocfg.hp_pins[0] || !spec->autocfg.line_out_pins[0])
++		return;
++
++	hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
++					AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++
++	present = snd_hda_codec_read(codec, spec->autocfg.line_out_pins[0], 0,
++				     AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++
++	if (!spec->hp_independent_mode) {
++		/* Mute Line-Outs */
++		for (i = 0; i < spec->autocfg.line_outs; i++)
++			snd_hda_codec_amp_stereo(
++				codec, spec->autocfg.line_out_pins[i],
++				HDA_OUTPUT, 0,
++				HDA_AMP_MUTE, hp_present ? HDA_AMP_MUTE : 0);
++		if (hp_present)
++			present = hp_present;
++	}
++	/* Speakers */
++	for (i = 0; i < spec->autocfg.speaker_outs; i++)
++		snd_hda_codec_amp_stereo(
++			codec, spec->autocfg.speaker_pins[i], HDA_OUTPUT, 0,
++			HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
++}
++
++
+ /* unsolicited event for jack sensing */
+ static void via_unsol_event(struct hda_codec *codec,
+ 				  unsigned int res)
+@@ -1688,6 +1975,10 @@ static void via_unsol_event(struct hda_codec *codec,
+ 		set_jack_power_state(codec);
+ 	if (res & VIA_MONO_EVENT)
+ 		via_mono_automute(codec);
++	if (res & VIA_SPEAKER_EVENT)
++		via_speaker_automute(codec);
++	if (res & VIA_BIND_HP_EVENT)
++		via_hp_bind_automute(codec);
+ }
+ 
+ static int via_init(struct hda_codec *codec)
+@@ -2099,10 +2390,19 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
+ /* init callback for auto-configuration model -- overriding the default init */
+ static int via_auto_init(struct hda_codec *codec)
+ {
++	struct via_spec *spec = codec->spec;
++
+ 	via_init(codec);
+ 	via_auto_init_multi_out(codec);
+ 	via_auto_init_hp_out(codec);
+ 	via_auto_init_analog_input(codec);
++	if (spec->codec_type == VT2002P) {
++		via_hp_bind_automute(codec);
++	} else {
++		via_hp_automute(codec);
++		via_speaker_automute(codec);
++	}
++
+ 	return 0;
+ }
+ 
+@@ -5033,6 +5333,359 @@ static int patch_vt1716S(struct hda_codec *codec)
+ 
+ 	return 0;
+ }
++
++/* for vt2002P */
++
++/* capture mixer elements */
++static struct snd_kcontrol_new vt2002P_capture_mixer[] = {
++	HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME("Front Mic Boost Capture Volume", 0x29, 0x0,
++			 HDA_INPUT),
++	{
++		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
++		/* The multiple "Capture Source" controls confuse alsamixer
++		 * So call somewhat different..
++		 */
++		/* .name = "Capture Source", */
++		.name = "Input Source",
++		.count = 2,
++		.info = via_mux_enum_info,
++		.get = via_mux_enum_get,
++		.put = via_mux_enum_put,
++	},
++	{ } /* end */
++};
++
++static struct hda_verb vt2002P_volume_init_verbs[] = {
++	/*
++	 * Unmute ADC0-1 and set the default input to mic-in
++	 */
++	{0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++
++
++	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
++	 * mixer widget
++	 */
++	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
++
++	/* MUX Indices: Mic = 0 */
++	{0x1e, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x1f, AC_VERB_SET_CONNECT_SEL, 0},
++
++	/* PW9 Output enable */
++	{0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
++
++	/* Enable Boost Volume backdoor */
++	{0x1, 0xfb9, 0x24},
++
++	/* MW0/1/4/8: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
++	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++
++	/* set MUX0/1/4/8 = 0 (AOW0) */
++	{0x34, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x35, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x37, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x3b, AC_VERB_SET_CONNECT_SEL, 0},
++
++	/* set PW0 index=0 (MW0) */
++	{0x24, AC_VERB_SET_CONNECT_SEL, 0},
++
++	/* Enable AOW0 to MW9 */
++	{0x1, 0xfb8, 0x88},
++	{ }
++};
++
++
++static struct hda_verb vt2002P_uniwill_init_verbs[] = {
++	{0x25, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
++	{0x26, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
++	{0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{ }
++};
++
++static struct hda_pcm_stream vt2002P_pcm_analog_playback = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.nid = 0x8, /* NID to query formats and rates */
++	.ops = {
++		.open = via_playback_pcm_open,
++		.prepare = via_playback_multi_pcm_prepare,
++		.cleanup = via_playback_multi_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt2002P_pcm_analog_capture = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.nid = 0x10, /* NID to query formats and rates */
++	.ops = {
++		.open = via_pcm_open_close,
++		.prepare = via_capture_pcm_prepare,
++		.cleanup = via_capture_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt2002P_pcm_digital_playback = {
++	.substreams = 1,
++	.channels_min = 2,
++	.channels_max = 2,
++	.rates = SNDRV_PCM_RATE_48000,
++	/* NID is set in via_build_pcms */
++	.ops = {
++		.open = via_dig_playback_pcm_open,
++		.close = via_dig_playback_pcm_close,
++		.prepare = via_dig_playback_pcm_prepare,
++		.cleanup = via_dig_playback_pcm_cleanup
++	},
++};
++
++/* fill in the dac_nids table from the parsed pin configuration */
++static int vt2002P_auto_fill_dac_nids(struct via_spec *spec,
++				      const struct auto_pin_cfg *cfg)
++{
++	spec->multiout.num_dacs = 1;
++	spec->multiout.dac_nids = spec->private_dac_nids;
++	if (cfg->line_out_pins[0])
++		spec->multiout.dac_nids[0] = 0x8;
++	return 0;
++}
++
++/* add playback controls from the parsed DAC table */
++static int vt2002P_auto_create_multi_out_ctls(struct via_spec *spec,
++					     const struct auto_pin_cfg *cfg)
++{
++	int err;
++
++	if (!cfg->line_out_pins[0])
++		return -1;
++
++
++	/* Line-Out: PortE */
++	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++			      "Master Front Playback Volume",
++			      HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++	err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
++			      "Master Front Playback Switch",
++			      HDA_COMPOSE_AMP_VAL(0x26, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	return 0;
++}
++
++static int vt2002P_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
++{
++	int err;
++
++	if (!pin)
++		return 0;
++
++	spec->multiout.hp_nid = 0x9;
++	spec->hp_independent_mode_index = 1;
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++			      "Headphone Playback Volume",
++			      HDA_COMPOSE_AMP_VAL(
++				      spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
++			      "Headphone Playback Switch",
++			      HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	create_hp_imux(spec);
++	return 0;
++}
++
++/* create playback/capture controls for input pins */
++static int vt2002P_auto_create_analog_input_ctls(struct via_spec *spec,
++						const struct auto_pin_cfg *cfg)
++{
++	static char *labels[] = {
++		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
++	};
++	struct hda_input_mux *imux = &spec->private_imux[0];
++	int i, err, idx = 0;
++
++	for (i = 0; i < AUTO_PIN_LAST; i++) {
++		if (!cfg->input_pins[i])
++			continue;
++
++		switch (cfg->input_pins[i]) {
++		case 0x2b: /* Mic */
++			idx = 0;
++			break;
++
++		case 0x2a: /* Line In */
++			idx = 1;
++			break;
++
++		case 0x29: /* Front Mic */
++			idx = 2;
++			break;
++		}
++		err = via_new_analog_input(spec, labels[i], idx, 0x21);
++		if (err < 0)
++			return err;
++		imux->items[imux->num_items].label = labels[i];
++		imux->items[imux->num_items].index = idx;
++		imux->num_items++;
++	}
++
++	/* build volume/mute control of loopback */
++	err = via_new_analog_input(spec, "Stereo Mixer", 3, 0x21);
++	if (err < 0)
++		return err;
++
++	/* for internal loopback recording select */
++	imux->items[imux->num_items].label = "Stereo Mixer";
++	imux->items[imux->num_items].index = 3;
++	imux->num_items++;
++
++	/* for digital mic select */
++	imux->items[imux->num_items].label = "Digital Mic";
++	imux->items[imux->num_items].index = 4;
++	imux->num_items++;
++
++	return 0;
++}
++
++static int vt2002P_parse_auto_config(struct hda_codec *codec)
++{
++	struct via_spec *spec = codec->spec;
++	int err;
++
++
++	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
++	if (err < 0)
++		return err;
++
++	err = vt2002P_auto_fill_dac_nids(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++
++	if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
++		return 0; /* can't find valid BIOS pin config */
++
++	err = vt2002P_auto_create_multi_out_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++	err = vt2002P_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
++	if (err < 0)
++		return err;
++	err = vt2002P_auto_create_analog_input_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++
++	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
++
++	fill_dig_outs(codec);
++
++	if (spec->kctls.list)
++		spec->mixers[spec->num_mixers++] = spec->kctls.list;
++
++	spec->input_mux = &spec->private_imux[0];
++
++	if (spec->hp_mux)
++		spec->mixers[spec->num_mixers++] = via_hp_mixer;
++
++	return 1;
++}
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++static struct hda_amp_list vt2002P_loopbacks[] = {
++	{ 0x21, HDA_INPUT, 0 },
++	{ 0x21, HDA_INPUT, 1 },
++	{ 0x21, HDA_INPUT, 2 },
++	{ } /* end */
++};
++#endif
++
++
++/* patch for vt2002P */
++static int patch_vt2002P(struct hda_codec *codec)
++{
++	struct via_spec *spec;
++	int err;
++
++	/* create a codec specific record */
++	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
++	if (spec == NULL)
++		return -ENOMEM;
++
++	codec->spec = spec;
++
++	/* automatic parse from the BIOS config */
++	err = vt2002P_parse_auto_config(codec);
++	if (err < 0) {
++		via_free(codec);
++		return err;
++	} else if (!err) {
++		printk(KERN_INFO "hda_codec: Cannot set up configuration "
++		       "from BIOS.  Using genenic mode...\n");
++	}
++
++	spec->init_verbs[spec->num_iverbs++]  = vt2002P_volume_init_verbs;
++	spec->init_verbs[spec->num_iverbs++] = vt2002P_uniwill_init_verbs;
++
++	spec->stream_name_analog = "VT2002P Analog";
++	spec->stream_analog_playback = &vt2002P_pcm_analog_playback;
++	spec->stream_analog_capture = &vt2002P_pcm_analog_capture;
++
++	spec->stream_name_digital = "VT2002P Digital";
++	spec->stream_digital_playback = &vt2002P_pcm_digital_playback;
++
++	if (!spec->adc_nids && spec->input_mux) {
++		spec->adc_nids = vt2002P_adc_nids;
++		spec->num_adc_nids = ARRAY_SIZE(vt2002P_adc_nids);
++		get_mux_nids(codec);
++		override_mic_boost(codec, 0x2b, 0, 3, 40);
++		override_mic_boost(codec, 0x29, 0, 3, 40);
++		spec->mixers[spec->num_mixers] = vt2002P_capture_mixer;
++		spec->num_mixers++;
++	}
++
++	codec->patch_ops = via_patch_ops;
++
++	codec->patch_ops.init = via_auto_init;
++	codec->patch_ops.unsol_event = via_unsol_event,
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++	spec->loopback.amplist = vt2002P_loopbacks;
++#endif
++
++	return 0;
++}
+ /*
+  * patch entries
+  */
+@@ -5117,6 +5770,8 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
+ 	  .patch = patch_vt1716S},
+ 	{ .id = 0x1106a721, .name = "VT1716S",
+ 	  .patch = patch_vt1716S},
++	{ .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
++	{ .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
+ 	{} /* terminator */
+ };
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0018-ALSA-HDA-VIA-Add-VT1812-support.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0018-ALSA-HDA-VIA-Add-VT1812-support.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,606 @@
+From 6122b15b56cc317b70aa7ec69411a88c285d12c2 Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Sat, 10 Oct 2009 19:08:46 +0800
+Subject: [PATCH 18/19] ALSA: HDA VIA: Add VT1812 support.
+
+commit ab6734e7ea32e9f9cbe0f55eeddf4aa629ed1c3d upstream.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Logan Li <loganli at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |  494 ++++++++++++++++++++++++++++++++++++++++++++-
+ 1 files changed, 491 insertions(+), 3 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index e2635ed..ab4bfdd 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -97,6 +97,7 @@ enum VIA_HDA_CODEC {
+ 	VT1718S,
+ 	VT1716S,
+ 	VT2002P,
++	VT1812,
+ 	CODEC_TYPES,
+ };
+ 
+@@ -195,6 +196,8 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 		codec_type = VT1718S;
+ 	else if (dev_id == 0x0438 || dev_id == 0x4438)
+ 		codec_type = VT2002P;
++	else if (dev_id == 0x0448)
++		codec_type = VT1812;
+ 	else
+ 		codec_type = UNKNOWN;
+ 	return codec_type;
+@@ -419,6 +422,12 @@ static hda_nid_t vt2002P_adc_nids[2] = {
+ 	0x10, 0x11
+ };
+ 
++static hda_nid_t vt1812_adc_nids[2] = {
++	/* ADC1-2 */
++	0x10, 0x11
++};
++
++
+ /* add dynamic controls */
+ static int via_add_control(struct via_spec *spec, int type, const char *name,
+ 			   unsigned long val)
+@@ -912,6 +921,120 @@ static void set_jack_power_state(struct hda_codec *codec)
+ 			snd_hda_codec_write(
+ 				codec, 0x21, 0,
+ 				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
++	} else if (spec->codec_type == VT1812) {
++		unsigned int present;
++		/* MUX10 (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;
++		/* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
++		snd_hda_codec_write(codec, 0x1e, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x1f, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x10, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x11, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++
++		/* outputs */
++		/* AOW0 (8h)*/
++		snd_hda_codec_write(codec, 0x8, 0,
++				    AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++
++		/* PW4 (28h), MW4 (18h), MUX4(38h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x28, &parm);
++		snd_hda_codec_write(codec, 0x18, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x38, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++
++		/* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x25, &parm);
++		snd_hda_codec_write(codec, 0x15, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x35, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		if (spec->hp_independent_mode)	{
++			snd_hda_codec_write(codec, 0x9, 0,
++					    AC_VERB_SET_POWER_STATE, parm);
++		}
++
++		/* Internal Speaker */
++		/* PW0 (24h), MW0(14h), MUX0(34h) */
++		present = snd_hda_codec_read(
++			codec, 0x25, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x24, &parm);
++		if (present) {
++			snd_hda_codec_write(codec, 0x14, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D3);
++			snd_hda_codec_write(codec, 0x34, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D3);
++		} else {
++			snd_hda_codec_write(codec, 0x14, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D0);
++			snd_hda_codec_write(codec, 0x34, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D0);
++		}
++		/* Mono Out */
++		/* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
++		present = snd_hda_codec_read(
++			codec, 0x28, 0, AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x31, &parm);
++		if (present) {
++			snd_hda_codec_write(codec, 0x1c, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D3);
++			snd_hda_codec_write(codec, 0x3c, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D3);
++			snd_hda_codec_write(codec, 0x3e, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D3);
++		} else {
++			snd_hda_codec_write(codec, 0x1c, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D0);
++			snd_hda_codec_write(codec, 0x3c, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D0);
++			snd_hda_codec_write(codec, 0x3e, 0,
++					    AC_VERB_SET_POWER_STATE,
++					    AC_PWRST_D0);
++		}
++
++		/* PW15 (33h), MW15 (1dh), MUX15(3dh) */
++		parm = AC_PWRST_D3;
++		set_pin_power_state(codec, 0x33, &parm);
++		snd_hda_codec_write(codec, 0x1d, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++		snd_hda_codec_write(codec, 0x3d, 0,
++				    AC_VERB_SET_POWER_STATE, parm);
++
++		/* MW9 (21h) */
++		if (imux_is_smixer || !is_aa_path_mute(codec))
++			snd_hda_codec_write(
++				codec, 0x21, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
++		else
++			snd_hda_codec_write(
++				codec, 0x21, 0,
++				AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
+ 	}
+ }
+ 
+@@ -982,6 +1105,9 @@ static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
+ 	case VT2002P:
+ 		nid = 0x35;
+ 		break;
++	case VT1812:
++		nid = 0x3d;
++		break;
+ 	default:
+ 		nid = spec->autocfg.hp_pins[0];
+ 		break;
+@@ -1057,6 +1183,9 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 	case VT2002P:
+ 		nid = 0x35;
+ 		break;
++	case VT1812:
++		nid = 0x3d;
++		break;
+ 	default:
+ 		nid = spec->autocfg.hp_pins[0];
+ 		break;
+@@ -1074,7 +1203,8 @@ static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
+ 	    || spec->codec_type == VT1702
+ 	    || spec->codec_type == VT1718S
+ 	    || spec->codec_type == VT1716S
+-	    || spec->codec_type == VT2002P) {
++	    || spec->codec_type == VT2002P
++	    || spec->codec_type == VT1812) {
+ 		activate_ctl(codec, "Headphone Playback Volume",
+ 			     spec->hp_independent_mode);
+ 		activate_ctl(codec, "Headphone Playback Switch",
+@@ -1315,6 +1445,7 @@ static int is_aa_path_mute(struct hda_codec *codec)
+ 		end_idx = 3;
+ 		break;
+ 	case VT2002P:
++	case VT1812:
+ 		nid_mixer = 0x21;
+ 		start_idx = 0;
+ 		end_idx = 2;
+@@ -1378,6 +1509,7 @@ static void analog_low_current_mode(struct hda_codec *codec, int stream_idle)
+ 		parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
+ 		break;
+ 	case VT2002P:
++	case VT1812:
+ 		verb = 0xf93;
+ 		parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
+ 		break;
+@@ -1908,7 +2040,7 @@ static void via_speaker_automute(struct hda_codec *codec)
+ 	unsigned int hp_present;
+ 	struct via_spec *spec = codec->spec;
+ 
+-	if (spec->codec_type != VT2002P)
++	if (spec->codec_type != VT2002P && spec->codec_type != VT1812)
+ 		return;
+ 
+ 	hp_present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
+@@ -2396,7 +2528,7 @@ static int via_auto_init(struct hda_codec *codec)
+ 	via_auto_init_multi_out(codec);
+ 	via_auto_init_hp_out(codec);
+ 	via_auto_init_analog_input(codec);
+-	if (spec->codec_type == VT2002P) {
++	if (spec->codec_type == VT2002P || spec->codec_type == VT1812) {
+ 		via_hp_bind_automute(codec);
+ 	} else {
+ 		via_hp_automute(codec);
+@@ -5686,6 +5818,361 @@ static int patch_vt2002P(struct hda_codec *codec)
+ 
+ 	return 0;
+ }
++
++/* for vt1812 */
++
++/* capture mixer elements */
++static struct snd_kcontrol_new vt1812_capture_mixer[] = {
++	HDA_CODEC_VOLUME("Capture Volume", 0x10, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE("Capture Switch", 0x10, 0x0, HDA_INPUT),
++	HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x11, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x11, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE("Mic Boost Capture Volume", 0x2b, 0x0, HDA_INPUT),
++	HDA_CODEC_MUTE("Front Mic Boost Capture Volume", 0x29, 0x0,
++		       HDA_INPUT),
++	{
++		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
++		/* The multiple "Capture Source" controls confuse alsamixer
++		 * So call somewhat different..
++		 */
++		.name = "Input Source",
++		.count = 2,
++		.info = via_mux_enum_info,
++		.get = via_mux_enum_get,
++		.put = via_mux_enum_put,
++	},
++	{ } /* end */
++};
++
++static struct hda_verb vt1812_volume_init_verbs[] = {
++	/*
++	 * Unmute ADC0-1 and set the default input to mic-in
++	 */
++	{0x8, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x9, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++
++
++	/* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
++	 * mixer widget
++	 */
++	/* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
++	{0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
++
++	/* MUX Indices: Mic = 0 */
++	{0x1e, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x1f, AC_VERB_SET_CONNECT_SEL, 0},
++
++	/* PW9 Output enable */
++	{0x2d, AC_VERB_SET_PIN_WIDGET_CONTROL, AC_PINCTL_OUT_EN},
++
++	/* Enable Boost Volume backdoor */
++	{0x1, 0xfb9, 0x24},
++
++	/* MW0/1/4/13/15: un-mute index 0 (MUXx), un-mute index 1 (MW9) */
++	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
++	{0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++	{0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
++
++	/* set MUX0/1/4/13/15 = 0 (AOW0) */
++	{0x34, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x35, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x38, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x3c, AC_VERB_SET_CONNECT_SEL, 0},
++	{0x3d, AC_VERB_SET_CONNECT_SEL, 0},
++
++	/* Enable AOW0 to MW9 */
++	{0x1, 0xfb8, 0xa8},
++	{ }
++};
++
++
++static struct hda_verb vt1812_uniwill_init_verbs[] = {
++	{0x33, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
++	{0x25, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT },
++	{0x28, AC_VERB_SET_UNSOLICITED_ENABLE,
++	 AC_USRSP_EN | VIA_JACK_EVENT | VIA_BIND_HP_EVENT},
++	{0x29, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x2a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{0x2b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_JACK_EVENT},
++	{ }
++};
++
++static struct hda_pcm_stream vt1812_pcm_analog_playback = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.nid = 0x8, /* NID to query formats and rates */
++	.ops = {
++		.open = via_playback_pcm_open,
++		.prepare = via_playback_multi_pcm_prepare,
++		.cleanup = via_playback_multi_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt1812_pcm_analog_capture = {
++	.substreams = 2,
++	.channels_min = 2,
++	.channels_max = 2,
++	.nid = 0x10, /* NID to query formats and rates */
++	.ops = {
++		.open = via_pcm_open_close,
++		.prepare = via_capture_pcm_prepare,
++		.cleanup = via_capture_pcm_cleanup,
++		.close = via_pcm_open_close,
++	},
++};
++
++static struct hda_pcm_stream vt1812_pcm_digital_playback = {
++	.substreams = 1,
++	.channels_min = 2,
++	.channels_max = 2,
++	.rates = SNDRV_PCM_RATE_48000,
++	/* NID is set in via_build_pcms */
++	.ops = {
++		.open = via_dig_playback_pcm_open,
++		.close = via_dig_playback_pcm_close,
++		.prepare = via_dig_playback_pcm_prepare,
++		.cleanup = via_dig_playback_pcm_cleanup
++	},
++};
++/* fill in the dac_nids table from the parsed pin configuration */
++static int vt1812_auto_fill_dac_nids(struct via_spec *spec,
++				     const struct auto_pin_cfg *cfg)
++{
++	spec->multiout.num_dacs = 1;
++	spec->multiout.dac_nids = spec->private_dac_nids;
++	if (cfg->line_out_pins[0])
++		spec->multiout.dac_nids[0] = 0x8;
++	return 0;
++}
++
++
++/* add playback controls from the parsed DAC table */
++static int vt1812_auto_create_multi_out_ctls(struct via_spec *spec,
++					     const struct auto_pin_cfg *cfg)
++{
++	int err;
++
++	if (!cfg->line_out_pins[0])
++		return -1;
++
++	/* Line-Out: PortE */
++	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++			      "Master Front Playback Volume",
++			      HDA_COMPOSE_AMP_VAL(0x8, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++	err = via_add_control(spec, VIA_CTL_WIDGET_BIND_PIN_MUTE,
++			      "Master Front Playback Switch",
++			      HDA_COMPOSE_AMP_VAL(0x28, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	return 0;
++}
++
++static int vt1812_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
++{
++	int err;
++
++	if (!pin)
++		return 0;
++
++	spec->multiout.hp_nid = 0x9;
++	spec->hp_independent_mode_index = 1;
++
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
++			      "Headphone Playback Volume",
++			      HDA_COMPOSE_AMP_VAL(
++				      spec->multiout.hp_nid, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
++			      "Headphone Playback Switch",
++			      HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
++	if (err < 0)
++		return err;
++
++	create_hp_imux(spec);
++	return 0;
++}
++
++/* create playback/capture controls for input pins */
++static int vt1812_auto_create_analog_input_ctls(struct via_spec *spec,
++						const struct auto_pin_cfg *cfg)
++{
++	static char *labels[] = {
++		"Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
++	};
++	struct hda_input_mux *imux = &spec->private_imux[0];
++	int i, err, idx = 0;
++
++	for (i = 0; i < AUTO_PIN_LAST; i++) {
++		if (!cfg->input_pins[i])
++			continue;
++
++		switch (cfg->input_pins[i]) {
++		case 0x2b: /* Mic */
++			idx = 0;
++			break;
++
++		case 0x2a: /* Line In */
++			idx = 1;
++			break;
++
++		case 0x29: /* Front Mic */
++			idx = 2;
++			break;
++		}
++		err = via_new_analog_input(spec, labels[i], idx, 0x21);
++		if (err < 0)
++			return err;
++		imux->items[imux->num_items].label = labels[i];
++		imux->items[imux->num_items].index = idx;
++		imux->num_items++;
++	}
++	/* build volume/mute control of loopback */
++	err = via_new_analog_input(spec, "Stereo Mixer", 5, 0x21);
++	if (err < 0)
++		return err;
++
++	/* for internal loopback recording select */
++	imux->items[imux->num_items].label = "Stereo Mixer";
++	imux->items[imux->num_items].index = 5;
++	imux->num_items++;
++
++	/* for digital mic select */
++	imux->items[imux->num_items].label = "Digital Mic";
++	imux->items[imux->num_items].index = 6;
++	imux->num_items++;
++
++	return 0;
++}
++
++static int vt1812_parse_auto_config(struct hda_codec *codec)
++{
++	struct via_spec *spec = codec->spec;
++	int err;
++
++
++	err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
++	if (err < 0)
++		return err;
++	fill_dig_outs(codec);
++	err = vt1812_auto_fill_dac_nids(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++
++	if (!spec->autocfg.line_outs && !spec->autocfg.hp_outs)
++		return 0; /* can't find valid BIOS pin config */
++
++	err = vt1812_auto_create_multi_out_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++	err = vt1812_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
++	if (err < 0)
++		return err;
++	err = vt1812_auto_create_analog_input_ctls(spec, &spec->autocfg);
++	if (err < 0)
++		return err;
++
++	spec->multiout.max_channels = spec->multiout.num_dacs * 2;
++
++	fill_dig_outs(codec);
++
++	if (spec->kctls.list)
++		spec->mixers[spec->num_mixers++] = spec->kctls.list;
++
++	spec->input_mux = &spec->private_imux[0];
++
++	if (spec->hp_mux)
++		spec->mixers[spec->num_mixers++] = via_hp_mixer;
++
++	return 1;
++}
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++static struct hda_amp_list vt1812_loopbacks[] = {
++	{ 0x21, HDA_INPUT, 0 },
++	{ 0x21, HDA_INPUT, 1 },
++	{ 0x21, HDA_INPUT, 2 },
++	{ } /* end */
++};
++#endif
++
++
++/* patch for vt1812 */
++static int patch_vt1812(struct hda_codec *codec)
++{
++	struct via_spec *spec;
++	int err;
++
++	/* create a codec specific record */
++	spec = kzalloc(sizeof(*spec), GFP_KERNEL);
++	if (spec == NULL)
++		return -ENOMEM;
++
++	codec->spec = spec;
++
++	/* automatic parse from the BIOS config */
++	err = vt1812_parse_auto_config(codec);
++	if (err < 0) {
++		via_free(codec);
++		return err;
++	} else if (!err) {
++		printk(KERN_INFO "hda_codec: Cannot set up configuration "
++		       "from BIOS.  Using genenic mode...\n");
++	}
++
++
++	spec->init_verbs[spec->num_iverbs++]  = vt1812_volume_init_verbs;
++	spec->init_verbs[spec->num_iverbs++] = vt1812_uniwill_init_verbs;
++
++	spec->stream_name_analog = "VT1812 Analog";
++	spec->stream_analog_playback = &vt1812_pcm_analog_playback;
++	spec->stream_analog_capture = &vt1812_pcm_analog_capture;
++
++	spec->stream_name_digital = "VT1812 Digital";
++	spec->stream_digital_playback = &vt1812_pcm_digital_playback;
++
++
++	if (!spec->adc_nids && spec->input_mux) {
++		spec->adc_nids = vt1812_adc_nids;
++		spec->num_adc_nids = ARRAY_SIZE(vt1812_adc_nids);
++		get_mux_nids(codec);
++		override_mic_boost(codec, 0x2b, 0, 3, 40);
++		override_mic_boost(codec, 0x29, 0, 3, 40);
++		spec->mixers[spec->num_mixers] = vt1812_capture_mixer;
++		spec->num_mixers++;
++	}
++
++	codec->patch_ops = via_patch_ops;
++
++	codec->patch_ops.init = via_auto_init;
++	codec->patch_ops.unsol_event = via_unsol_event,
++
++#ifdef CONFIG_SND_HDA_POWER_SAVE
++	spec->loopback.amplist = vt1812_loopbacks;
++#endif
++
++	return 0;
++}
++
+ /*
+  * patch entries
+  */
+@@ -5772,6 +6259,7 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
+ 	  .patch = patch_vt1716S},
+ 	{ .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
+ 	{ .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
++	{ .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
+ 	{} /* terminator */
+ };
+ 
+-- 
+1.7.1
+

Added: dists/sid/linux-2.6/debian/patches/features/all/hda-via/0019-ALSA-VIA-HDA-Add-support-for-VT1818S.patch
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ dists/sid/linux-2.6/debian/patches/features/all/hda-via/0019-ALSA-VIA-HDA-Add-support-for-VT1818S.patch	Sun Sep  5 23:51:14 2010	(r16242)
@@ -0,0 +1,60 @@
+From 032954293dea7b07c965f6e9b5ea69c643ea6bbc Mon Sep 17 00:00:00 2001
+From: Lydia Wang <lydiawang at viatech.com.cn>
+Date: Tue, 20 Oct 2009 13:18:04 +0800
+Subject: [PATCH 19/19] ALSA: VIA HDA: Add support for VT1818S.
+
+commit 36dd5c4afff825fca1b6ccde678f51d6933a6850 upstream.
+
+Add support for VT1818S codec, which is similiar with VT1708S.
+
+Signed-off-by: Lydia Wang <lydiawang at viatech.com.cn>
+Signed-off-by: Takashi Iwai <tiwai at suse.de>
+---
+ sound/pci/hda/patch_via.c |   14 ++++++++++++--
+ 1 files changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
+index ab4bfdd..afe8715 100644
+--- a/sound/pci/hda/patch_via.c
++++ b/sound/pci/hda/patch_via.c
+@@ -198,6 +198,8 @@ static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
+ 		codec_type = VT2002P;
+ 	else if (dev_id == 0x0448)
+ 		codec_type = VT1812;
++	else if (dev_id == 0x0440)
++		codec_type = VT1708S;
+ 	else
+ 		codec_type = UNKNOWN;
+ 	return codec_type;
+@@ -4151,11 +4153,17 @@ static int patch_vt1708S(struct hda_codec *codec)
+ 	spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
+ 	spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
+ 
+-	spec->stream_name_analog = "VT1708S Analog";
++	if (codec->vendor_id == 0x11060440)
++		spec->stream_name_analog = "VT1818S Analog";
++	else
++		spec->stream_name_analog = "VT1708S Analog";
+ 	spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
+ 	spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
+ 
+-	spec->stream_name_digital = "VT1708S Digital";
++	if (codec->vendor_id == 0x11060440)
++		spec->stream_name_digital = "VT1818S Digital";
++	else
++		spec->stream_name_digital = "VT1708S Digital";
+ 	spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
+ 
+ 	if (!spec->adc_nids && spec->input_mux) {
+@@ -6260,6 +6268,8 @@ static struct hda_codec_preset snd_hda_preset_via[] = {
+ 	{ .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
+ 	{ .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
+ 	{ .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
++	{ .id = 0x11060440, .name = "VT1818S",
++	  .patch = patch_vt1708S},
+ 	{} /* terminator */
+ };
+ 
+-- 
+1.7.1
+

Modified: dists/sid/linux-2.6/debian/patches/series/22
==============================================================================
--- dists/sid/linux-2.6/debian/patches/series/22	Sun Sep  5 23:46:29 2010	(r16241)
+++ dists/sid/linux-2.6/debian/patches/series/22	Sun Sep  5 23:51:14 2010	(r16242)
@@ -76,3 +76,22 @@
 + features/all/sky2/0055-sky2-version-1.28.patch
 + bugfix/all/input-add-compat-support-for-sysfs-and-proc-capabilities.patch
 + bugfix/mips/mips-DMA-computation-fix.patch
++ features/all/hda-via/0001-ALSA-HDA-VIA-Change-get_codec_type-argument-to-hda_c.patch
++ features/all/hda-via/0002-ALSA-HDA-VIA-Add-VT1708B-CE-codec-support.patch
++ features/all/hda-via/0003-ALSA-HDA-VIA-Add-VIA_CTL_WIDGET_ANALOG_MUTE-control-.patch
++ features/all/hda-via/0004-ALSA-HDA-VIA-Add-low-current-mode-for-power-saving.patch
++ features/all/hda-via/0005-ALSA-HDA-VIA-Change-VT1708S-VT1702-hp-mode-controls.patch
++ features/all/hda-via/0006-ALSA-HDA-VIA-Rewrite-via_independent_hp_put.patch
++ features/all/hda-via/0007-ALSA-HDA-VIA-Add-smart5.1-function.patch
++ features/all/hda-via/0008-ALSA-HDA-VIA-When-changing-input-source-update-power.patch
++ features/all/hda-via/0009-ALSA-HDA-VIA-Remove-unused-argument-of-via_new_analo.patch
++ features/all/hda-via/0010-ALSA-HDA-VIA-Add-VIA_JACK_EVENT-process-in-via_unsol.patch
++ features/all/hda-via/0011-ALSA-HDA-VIA-Refresh-front-playback-mute-in-via_hp_a.patch
++ features/all/hda-via/0012-ALSA-HDA-VIA-Add-Jack-detect-feature-for-VT1708.patch
++ features/all/hda-via/0013-ALSA-HDA-VIA-Replace-MIC_BOOST_VOLUME.patch
++ features/all/hda-via/0014-ALSA-HDA-VIA-Add-VT1718S-support.patch
++ features/all/hda-via/0015-ALSA-HDA-VIA-Add-VT1828S-and-VT2020-support.patch
++ features/all/hda-via/0016-ALSA-HDA-VIA-Add-VT1716S-support.patch
++ features/all/hda-via/0017-ALSA-HDA-VIA-Add-VT2002P-support.patch
++ features/all/hda-via/0018-ALSA-HDA-VIA-Add-VT1812-support.patch
++ features/all/hda-via/0019-ALSA-VIA-HDA-Add-support-for-VT1818S.patch



More information about the Kernel-svn-changes mailing list