From 64be285b669e5eed65fb3630f1b2b549447b9f1e Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Fri, 17 Jun 2011 16:51:39 +0200
Subject: [PATCH] ALSA: hda - Auto-mute all LO and speakers in patch_via.c
Git-commit: 64be285b669e5eed65fb3630f1b2b549447b9f1e
Patch-mainline: 3.1-rc2
References: FATE#314310

Muting all line-outs and/or speakers is more common in other drivers,
so we should follow it, too.

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

---
 sound/pci/hda/patch_via.c |   63 ++++++++++++++++++++++------------------------
 1 file changed, 31 insertions(+), 32 deletions(-)

--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -1620,6 +1620,17 @@ static void via_free(struct hda_codec *c
 	kfree(codec->spec);
 }
 
+/* mute/unmute outputs */
+static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
+				hda_nid_t *pins, bool mute)
+{
+	int i;
+	for (i = 0; i < num_pins; i++)
+		snd_hda_codec_write(codec, pins[i], 0,
+				    AC_VERB_SET_PIN_WIDGET_CONTROL,
+				    mute ? 0 : PIN_OUT);
+}
+
 /* mute internal speaker if HP is plugged */
 static void via_hp_automute(struct hda_codec *codec)
 {
@@ -1628,12 +1639,10 @@ static void via_hp_automute(struct hda_c
 
 	present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
 
-	if (!spec->hp_independent_mode) {
-		/* auto mute */
-		snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
-				    AC_VERB_SET_PIN_WIDGET_CONTROL,
-				    present ? 0 : PIN_OUT);
-	}
+	if (!spec->hp_independent_mode)
+		toggle_output_mutes(codec, spec->autocfg.line_outs,
+				    spec->autocfg.line_out_pins,
+				    present);
 }
 
 /* mute mono out if HP or Line out is plugged */
@@ -1722,45 +1731,35 @@ static void via_speaker_automute(struct
 
 	hp_present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
 
-	if (!spec->hp_independent_mode) {
-		snd_hda_codec_write(codec, spec->autocfg.speaker_pins[0], 0,
-				    AC_VERB_SET_PIN_WIDGET_CONTROL,
-				    hp_present ? 0 : PIN_OUT);
-	}
+	if (!spec->hp_independent_mode)
+		toggle_output_mutes(codec, spec->autocfg.speaker_outs,
+				    spec->autocfg.speaker_pins,
+				    hp_present);
 }
 
 /* mute line-out and internal speaker if HP is plugged */
 static void via_hp_bind_automute(struct hda_codec *codec)
 {
-	/* use long instead of int below just to avoid an internal compiler
-	 * error with gcc 4.0.x
-	 */
-	unsigned long hp_present, present = 0;
+	int present;
 	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_jack_detect(codec, spec->autocfg.hp_pins[0]);
+	present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
+	if (!spec->hp_independent_mode)
+		toggle_output_mutes(codec, spec->autocfg.line_outs,
+				    spec->autocfg.line_out_pins,
+				    present);
 
-	present = snd_hda_jack_detect(codec, spec->autocfg.line_out_pins[0]);
+	if (!present)
+		present = snd_hda_jack_detect(codec,
+					      spec->autocfg.line_out_pins[0]);
 
-	if (!spec->hp_independent_mode) {
-		/* Mute Line-Outs */
-		for (i = 0; i < spec->autocfg.line_outs; i++)
-			snd_hda_codec_write(codec,
-					    spec->autocfg.line_out_pins[i], 0,
-					    AC_VERB_SET_PIN_WIDGET_CONTROL,
-					    hp_present ? 0 : PIN_OUT);
-		if (hp_present)
-			present = hp_present;
-	}
 	/* Speakers */
-	for (i = 0; i < spec->autocfg.speaker_outs; i++)
-		snd_hda_codec_write(codec, spec->autocfg.speaker_pins[i], 0,
-				    AC_VERB_SET_PIN_WIDGET_CONTROL,
-				    present ? 0 : PIN_OUT);
+	toggle_output_mutes(codec, spec->autocfg.speaker_outs,
+			    spec->autocfg.speaker_pins,
+			    present);
 }
 
 
