From 7ec9c6ccc6007b14a916021d4ba7ffbcc7822ae3 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Mon, 27 Jun 2011 15:53:38 +0200
Subject: [PATCH] ALSA: hda - Fix volume-init for ALC259 with invalid widget caps
Git-commit: 7ec9c6ccc6007b14a916021d4ba7ffbcc7822ae3
Patch-mainline: 3.1-rc2
Refernces: FATE#314106,FATE#314311,FATE#313695

ALC259 seems to provide an invalid widget capability for the input-src
selector widget.  The widget shows the input-amp while it's a selector,
and this confuses the current ALC882 initialization code that is used
for ALC259, too.  For fixing this, check the amp capability and handle
the connection selection individually.

Also, ALC259 has no mute bit in DAC volume, so we need to initialize
it as ZERO instead of MUTE.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

---
 sound/pci/hda/patch_realtek.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -11098,6 +11098,7 @@ static void alc882_auto_init_input_src(s
 		unsigned int mux_idx;
 		const struct hda_input_mux *imux;
 		int conns, mute, idx, item;
+		unsigned int wid_type;
 
 		/* mute ADC */
 		snd_hda_codec_write(codec, spec->adc_nids[c], 0,
@@ -11111,6 +11112,7 @@ static void alc882_auto_init_input_src(s
 		imux = &spec->input_mux[mux_idx];
 		if (!imux->num_items && mux_idx > 0)
 			imux = &spec->input_mux[0];
+		wid_type = get_wcaps_type(get_wcaps(codec, nid));
 		for (idx = 0; idx < conns; idx++) {
 			/* if the current connection is the selected one,
 			 * unmute it as default - otherwise mute it
@@ -11123,17 +11125,13 @@ static void alc882_auto_init_input_src(s
 					break;
 				}
 			}
-			/* check if we have a selector or mixer
-			 * we could check for the widget type instead, but
-			 * just check for Amp-In presence (in case of mixer
-			 * without amp-in there is something wrong, this
-			 * function shouldn't be used or capsrc nid is wrong)
-			 */
-			if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
+			/* initialize the mute status if mute-amp is present */
+			if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
 				snd_hda_codec_write(codec, nid, 0,
 						    AC_VERB_SET_AMP_GAIN_MUTE,
 						    mute);
-			else if (mute != AMP_IN_MUTE(idx))
+			if (wid_type == AC_WID_AUD_SEL &&
+			    mute != AMP_IN_MUTE(idx))
 				snd_hda_codec_write(codec, nid, 0,
 						    AC_VERB_SET_CONNECT_SEL,
 						    idx);
@@ -13617,7 +13615,7 @@ static void alc268_auto_init_dac(struct
 	if (!nid)
 		return;
 	snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
-			    AMP_OUT_MUTE);
+			    AMP_OUT_ZERO);
 }
 
 static void alc268_auto_init_multi_out(struct hda_codec *codec)
