alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed.
@ 2013-08-05  4:09 Chih-Chung Chang
  2013-08-05  7:24 ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Chih-Chung Chang @ 2013-08-05  4:09 UTC (permalink / raw)
  To: patch; +Cc: tiwai, chihchung, alsa-devel, kailang, dgreid

The snd_hda_jack_set_gating_jack() call didn't work when
auto_{mute,mic} is suppressed because (1) am_entry is
not filled with nid of the mic pin. (2) The jacks are not
created (by snd_hda_jack_detect_enable_callback) before the
snd_hda_jack_set_gating_jack call.

Now we use the first input pin nid directly, and create the jack if it
doesn't exist yet.

Signed-off-by: Chih-Chung Chang <chihchung@chromium.org>

diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 3fd2973..aa02c0f 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -247,8 +247,8 @@ EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
 				 hda_nid_t gating_nid)
 {
-	struct hda_jack_tbl *gated = snd_hda_jack_tbl_get(codec, gated_nid);
-	struct hda_jack_tbl *gating = snd_hda_jack_tbl_get(codec, gating_nid);
+	struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid);
+	struct hda_jack_tbl *gating = snd_hda_jack_tbl_new(codec, gating_nid);
 
 	if (!gated || !gating)
 		return -EINVAL;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 8bd2261..2b64de5 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -3258,11 +3258,12 @@ static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
 	struct alc_spec *spec = codec->spec;
 
 	if (action == HDA_FIXUP_ACT_PROBE) {
-		if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
-			       !spec->gen.autocfg.hp_pins[0]))
+		int mic_pin = spec->gen.autocfg.inputs[0].pin;
+		int hp_pin = spec->gen.autocfg.hp_pins[0];
+
+		if (snd_BUG_ON(!mic_pin || !hp_pin))
 			return;
-		snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
-					     spec->gen.autocfg.hp_pins[0]);
+		snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
 	}
 }
 
-- 
1.8.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed.
  2013-08-05  4:09 Chih-Chung Chang
@ 2013-08-05  7:24 ` Takashi Iwai
  2013-08-05  8:22   ` Chih-Chung Chang
  0 siblings, 1 reply; 6+ messages in thread
From: Takashi Iwai @ 2013-08-05  7:24 UTC (permalink / raw)
  To: Chih-Chung Chang; +Cc: alsa-devel, kailang, dgreid

At Mon,  5 Aug 2013 12:09:21 +0800,
Chih-Chung Chang wrote:
> 
> The snd_hda_jack_set_gating_jack() call didn't work when
> auto_{mute,mic} is suppressed because (1) am_entry is
> not filled with nid of the mic pin. (2) The jacks are not
> created (by snd_hda_jack_detect_enable_callback) before the
> snd_hda_jack_set_gating_jack call.
> 
> Now we use the first input pin nid directly, and create the jack if it
> doesn't exist yet.
> 
> Signed-off-by: Chih-Chung Chang <chihchung@chromium.org>

Where we need this kind of fix, the choice of the mic pin via
autocfg.inputs[0].pin doesn't look right.  For example, an internal
mic pin with a smaller NID than an external mic pin would screw it
up.


thanks,

Takashi


> 
> diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
> index 3fd2973..aa02c0f 100644
> --- a/sound/pci/hda/hda_jack.c
> +++ b/sound/pci/hda/hda_jack.c
> @@ -247,8 +247,8 @@ EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
>  int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
>  				 hda_nid_t gating_nid)
>  {
> -	struct hda_jack_tbl *gated = snd_hda_jack_tbl_get(codec, gated_nid);
> -	struct hda_jack_tbl *gating = snd_hda_jack_tbl_get(codec, gating_nid);
> +	struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid);
> +	struct hda_jack_tbl *gating = snd_hda_jack_tbl_new(codec, gating_nid);
>  
>  	if (!gated || !gating)
>  		return -EINVAL;
> diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
> index 8bd2261..2b64de5 100644
> --- a/sound/pci/hda/patch_realtek.c
> +++ b/sound/pci/hda/patch_realtek.c
> @@ -3258,11 +3258,12 @@ static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
>  	struct alc_spec *spec = codec->spec;
>  
>  	if (action == HDA_FIXUP_ACT_PROBE) {
> -		if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
> -			       !spec->gen.autocfg.hp_pins[0]))
> +		int mic_pin = spec->gen.autocfg.inputs[0].pin;
> +		int hp_pin = spec->gen.autocfg.hp_pins[0];
> +
> +		if (snd_BUG_ON(!mic_pin || !hp_pin))
>  			return;
> -		snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
> -					     spec->gen.autocfg.hp_pins[0]);
> +		snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
>  	}
>  }
>  
> -- 
> 1.8.3
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed.
  2013-08-05  7:24 ` Takashi Iwai
@ 2013-08-05  8:22   ` Chih-Chung Chang
  0 siblings, 0 replies; 6+ messages in thread
From: Chih-Chung Chang @ 2013-08-05  8:22 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Chih-Chung Chang, alsa-devel, kailang, Dylan Reid

On Mon, Aug 5, 2013 at 3:24 PM, Takashi Iwai <tiwai@suse.de> wrote:

> At Mon,  5 Aug 2013 12:09:21 +0800,
> Chih-Chung Chang wrote:
> >
> > The snd_hda_jack_set_gating_jack() call didn't work when
> > auto_{mute,mic} is suppressed because (1) am_entry is
> > not filled with nid of the mic pin. (2) The jacks are not
> > created (by snd_hda_jack_detect_enable_callback) before the
> > snd_hda_jack_set_gating_jack call.
> >
> > Now we use the first input pin nid directly, and create the jack if it
> > doesn't exist yet.
> >
> > Signed-off-by: Chih-Chung Chang <chihchung@chromium.org>
>
> Where we need this kind of fix, the choice of the mic pin via
> autocfg.inputs[0].pin doesn't look right.  For example, an internal
> mic pin with a smaller NID than an external mic pin would screw it
> up.
>

Thanks for review. I will send a revised patch.


>
>
> thanks,
>
> Takashi
>
>
> >
> > diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
> > index 3fd2973..aa02c0f 100644
> > --- a/sound/pci/hda/hda_jack.c
> > +++ b/sound/pci/hda/hda_jack.c
> > @@ -247,8 +247,8 @@ EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
> >  int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t
> gated_nid,
> >                                hda_nid_t gating_nid)
> >  {
> > -     struct hda_jack_tbl *gated = snd_hda_jack_tbl_get(codec,
> gated_nid);
> > -     struct hda_jack_tbl *gating = snd_hda_jack_tbl_get(codec,
> gating_nid);
> > +     struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec,
> gated_nid);
> > +     struct hda_jack_tbl *gating = snd_hda_jack_tbl_new(codec,
> gating_nid);
> >
> >       if (!gated || !gating)
> >               return -EINVAL;
> > diff --git a/sound/pci/hda/patch_realtek.c
> b/sound/pci/hda/patch_realtek.c
> > index 8bd2261..2b64de5 100644
> > --- a/sound/pci/hda/patch_realtek.c
> > +++ b/sound/pci/hda/patch_realtek.c
> > @@ -3258,11 +3258,12 @@ static void alc271_hp_gate_mic_jack(struct
> hda_codec *codec,
> >       struct alc_spec *spec = codec->spec;
> >
> >       if (action == HDA_FIXUP_ACT_PROBE) {
> > -             if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
> > -                            !spec->gen.autocfg.hp_pins[0]))
> > +             int mic_pin = spec->gen.autocfg.inputs[0].pin;
> > +             int hp_pin = spec->gen.autocfg.hp_pins[0];
> > +
> > +             if (snd_BUG_ON(!mic_pin || !hp_pin))
> >                       return;
> > -             snd_hda_jack_set_gating_jack(codec,
> spec->gen.am_entry[1].pin,
> > -                                          spec->gen.autocfg.hp_pins[0]);
> > +             snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
> >       }
> >  }
> >
> > --
> > 1.8.3
> >
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* (no subject)
@ 2013-08-05  8:38 Chih-Chung Chang
  2013-08-05  8:38 ` [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed Chih-Chung Chang
  0 siblings, 1 reply; 6+ messages in thread
From: Chih-Chung Chang @ 2013-08-05  8:38 UTC (permalink / raw)
  To: patch; +Cc: tiwai, chihchung, alsa-devel, kailang, dgreid

This is a revised patch which also checks if the mic is external.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed.
  2013-08-05  8:38 (no subject) Chih-Chung Chang
@ 2013-08-05  8:38 ` Chih-Chung Chang
  2013-08-05  9:20   ` Takashi Iwai
  0 siblings, 1 reply; 6+ messages in thread
From: Chih-Chung Chang @ 2013-08-05  8:38 UTC (permalink / raw)
  To: patch; +Cc: tiwai, chihchung, alsa-devel, kailang, dgreid

The snd_hda_jack_set_gating_jack() call didn't work when
auto_{mute,mic} is suppressed because (1) am_entry is
not filled with nid of the mic pin. (2) The jacks are not
created (by snd_hda_jack_detect_enable_callback) before the
snd_hda_jack_set_gating_jack call.

Now we use the first input pin nid directly, and create the jack if it
doesn't exist yet.

Signed-off-by: Chih-Chung Chang <chihchung@chromium.org>

diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index 3fd2973..aa02c0f 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -247,8 +247,8 @@ EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
 int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
 				 hda_nid_t gating_nid)
 {
-	struct hda_jack_tbl *gated = snd_hda_jack_tbl_get(codec, gated_nid);
-	struct hda_jack_tbl *gating = snd_hda_jack_tbl_get(codec, gating_nid);
+	struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid);
+	struct hda_jack_tbl *gating = snd_hda_jack_tbl_new(codec, gating_nid);
 
 	if (!gated || !gating)
 		return -EINVAL;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 8bd2261..095062c 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -3251,6 +3251,28 @@ static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
 	alc_fixup_headset_mode(codec, fix, action);
 }
 
+/* Returns the nid of the external mic input pin, or 0 if it cannot be found. */
+static int find_ext_mic_pin(struct hda_codec *codec)
+{
+	struct alc_spec *spec = codec->spec;
+	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
+	hda_nid_t nid;
+	unsigned int defcfg;
+	int i;
+
+	for (i = 0; i < cfg->num_inputs; i++) {
+		if (cfg->inputs[i].type != AUTO_PIN_MIC)
+			continue;
+		nid = cfg->inputs[i].pin;
+		defcfg = snd_hda_codec_get_pincfg(codec, nid);
+		if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
+			continue;
+		return nid;
+	}
+
+	return 0;
+}
+
 static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
 				    const struct hda_fixup *fix,
 				    int action)
@@ -3258,11 +3280,12 @@ static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
 	struct alc_spec *spec = codec->spec;
 
 	if (action == HDA_FIXUP_ACT_PROBE) {
-		if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
-			       !spec->gen.autocfg.hp_pins[0]))
+		int mic_pin = find_ext_mic_pin(codec);
+		int hp_pin = spec->gen.autocfg.hp_pins[0];
+
+		if (snd_BUG_ON(!mic_pin || !hp_pin))
 			return;
-		snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
-					     spec->gen.autocfg.hp_pins[0]);
+		snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
 	}
 }
 
-- 
1.8.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed.
  2013-08-05  8:38 ` [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed Chih-Chung Chang
@ 2013-08-05  9:20   ` Takashi Iwai
  0 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2013-08-05  9:20 UTC (permalink / raw)
  To: Chih-Chung Chang; +Cc: alsa-devel, kailang, dgreid

At Mon,  5 Aug 2013 16:38:42 +0800,
Chih-Chung Chang wrote:
> 
> The snd_hda_jack_set_gating_jack() call didn't work when
> auto_{mute,mic} is suppressed because (1) am_entry is
> not filled with nid of the mic pin. (2) The jacks are not
> created (by snd_hda_jack_detect_enable_callback) before the
> snd_hda_jack_set_gating_jack call.
> 
> Now we use the first input pin nid directly, and create the jack if it
> doesn't exist yet.
> 
> Signed-off-by: Chih-Chung Chang <chihchung@chromium.org>

Thanks, applied now.


Takashi

> 
> diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
> index 3fd2973..aa02c0f 100644
> --- a/sound/pci/hda/hda_jack.c
> +++ b/sound/pci/hda/hda_jack.c
> @@ -247,8 +247,8 @@ EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
>  int snd_hda_jack_set_gating_jack(struct hda_codec *codec, hda_nid_t gated_nid,
>  				 hda_nid_t gating_nid)
>  {
> -	struct hda_jack_tbl *gated = snd_hda_jack_tbl_get(codec, gated_nid);
> -	struct hda_jack_tbl *gating = snd_hda_jack_tbl_get(codec, gating_nid);
> +	struct hda_jack_tbl *gated = snd_hda_jack_tbl_new(codec, gated_nid);
> +	struct hda_jack_tbl *gating = snd_hda_jack_tbl_new(codec, gating_nid);
>  
>  	if (!gated || !gating)
>  		return -EINVAL;
> diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
> index 8bd2261..095062c 100644
> --- a/sound/pci/hda/patch_realtek.c
> +++ b/sound/pci/hda/patch_realtek.c
> @@ -3251,6 +3251,28 @@ static void alc_fixup_headset_mode_alc668(struct hda_codec *codec,
>  	alc_fixup_headset_mode(codec, fix, action);
>  }
>  
> +/* Returns the nid of the external mic input pin, or 0 if it cannot be found. */
> +static int find_ext_mic_pin(struct hda_codec *codec)
> +{
> +	struct alc_spec *spec = codec->spec;
> +	struct auto_pin_cfg *cfg = &spec->gen.autocfg;
> +	hda_nid_t nid;
> +	unsigned int defcfg;
> +	int i;
> +
> +	for (i = 0; i < cfg->num_inputs; i++) {
> +		if (cfg->inputs[i].type != AUTO_PIN_MIC)
> +			continue;
> +		nid = cfg->inputs[i].pin;
> +		defcfg = snd_hda_codec_get_pincfg(codec, nid);
> +		if (snd_hda_get_input_pin_attr(defcfg) == INPUT_PIN_ATTR_INT)
> +			continue;
> +		return nid;
> +	}
> +
> +	return 0;
> +}
> +
>  static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
>  				    const struct hda_fixup *fix,
>  				    int action)
> @@ -3258,11 +3280,12 @@ static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
>  	struct alc_spec *spec = codec->spec;
>  
>  	if (action == HDA_FIXUP_ACT_PROBE) {
> -		if (snd_BUG_ON(!spec->gen.am_entry[1].pin ||
> -			       !spec->gen.autocfg.hp_pins[0]))
> +		int mic_pin = find_ext_mic_pin(codec);
> +		int hp_pin = spec->gen.autocfg.hp_pins[0];
> +
> +		if (snd_BUG_ON(!mic_pin || !hp_pin))
>  			return;
> -		snd_hda_jack_set_gating_jack(codec, spec->gen.am_entry[1].pin,
> -					     spec->gen.autocfg.hp_pins[0]);
> +		snd_hda_jack_set_gating_jack(codec, mic_pin, hp_pin);
>  	}
>  }
>  
> -- 
> 1.8.3
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-08-05  9:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-05  8:38 (no subject) Chih-Chung Chang
2013-08-05  8:38 ` [PATCH 1/1] ALSA: hda - Fix jack gating when auto_{mute, mic} is suppressed Chih-Chung Chang
2013-08-05  9:20   ` Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2013-08-05  4:09 Chih-Chung Chang
2013-08-05  7:24 ` Takashi Iwai
2013-08-05  8:22   ` Chih-Chung Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).