Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda/hdmi: Use 'AC_PINSENSE_ELDV' to detect pinsense for Loongson
@ 2026-05-26 11:19 Huacai Chen
  2026-05-26 14:31 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Huacai Chen @ 2026-05-26 11:19 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela, Huacai Chen
  Cc: linux-sound, linux-kernel, Xuerui Wang, Jiaxun Yang, Huacai Chen,
	stable, Baoqi Zhang, Haowei Zheng

Due to a hardware defect, for Loongson PCI HDMI devices with a reversion
ID of 2, the pin sense status must be determined via the ELD.

Add a codec flag, eld_jack_detect, to indicate this case, and do special
handlings in read_pin_sense().

Cc: stable@vger.kernel.org
Signed-off-by: Baoqi Zhang <zhangbaoqi@loongson.cn>
Signed-off-by: Haowei Zheng <zhenghaowei@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 include/sound/hda_codec.h    | 1 +
 sound/hda/codecs/hdmi/hdmi.c | 8 +++++++-
 sound/hda/common/jack.c      | 4 ++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
index 24581080e26a..1a1fe7a904c3 100644
--- a/include/sound/hda_codec.h
+++ b/include/sound/hda_codec.h
@@ -259,6 +259,7 @@ struct hda_codec {
 	unsigned int forced_resume:1; /* forced resume for jack */
 	unsigned int no_stream_clean_at_suspend:1; /* do not clean streams at suspend */
 	unsigned int ctl_dev_id:1; /* old control element id build behaviour */
+	unsigned int eld_jack_detect:1;	/* Machine jack-detection by ELD */
 
 	unsigned long power_on_acct;
 	unsigned long power_off_acct;
diff --git a/sound/hda/codecs/hdmi/hdmi.c b/sound/hda/codecs/hdmi/hdmi.c
index f20d1715da62..423cd9f683c6 100644
--- a/sound/hda/codecs/hdmi/hdmi.c
+++ b/sound/hda/codecs/hdmi/hdmi.c
@@ -2285,6 +2285,7 @@ EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_acomp_init, "SND_HDA_CODEC_HDMI");
 enum {
 	MODEL_GENERIC,
 	MODEL_GF,
+	MODEL_LOONGSON,
 };
 
 static int generichdmi_probe(struct hda_codec *codec,
@@ -2302,6 +2303,11 @@ static int generichdmi_probe(struct hda_codec *codec,
 	if (id->driver_data == MODEL_GF)
 		codec->no_sticky_stream = 1;
 
+	if (id->driver_data == MODEL_LOONGSON) {
+		if (codec->bus && codec->bus->pci->revision == 0x2)
+			codec->eld_jack_detect = 1; /* Jack-detection by ELD */
+	}
+
 	return 0;
 }
 
@@ -2319,7 +2325,7 @@ static const struct hda_codec_ops generichdmi_codec_ops = {
 /*
  */
 static const struct hda_device_id snd_hda_id_generichdmi[] = {
-	HDA_CODEC_ID_MODEL(0x00147a47, "Loongson HDMI",		MODEL_GENERIC),
+	HDA_CODEC_ID_MODEL(0x00147a47, "Loongson HDMI",		MODEL_LOONGSON),
 	HDA_CODEC_ID_MODEL(0x10951390, "SiI1390 HDMI",		MODEL_GENERIC),
 	HDA_CODEC_ID_MODEL(0x10951392, "SiI1392 HDMI",		MODEL_GENERIC),
 	HDA_CODEC_ID_MODEL(0x11069f84, "VX11 HDMI/DP",		MODEL_GENERIC),
diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
index 98ba1c4d5ba4..1f0ebf9cd151 100644
--- a/sound/hda/common/jack.c
+++ b/sound/hda/common/jack.c
@@ -58,6 +58,10 @@ static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id)
 				  AC_VERB_GET_PIN_SENSE, dev_id);
 	if (codec->inv_jack_detect)
 		val ^= AC_PINSENSE_PRESENCE;
+	if (codec->eld_jack_detect) {
+		val &= ~AC_PINSENSE_PRESENCE;
+		val |= !!(val & AC_PINSENSE_ELDV) << 31;
+	}
 	return val;
 }
 
-- 
2.52.0


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

* Re: [PATCH] ALSA: hda/hdmi: Use 'AC_PINSENSE_ELDV' to detect pinsense for Loongson
  2026-05-26 11:19 [PATCH] ALSA: hda/hdmi: Use 'AC_PINSENSE_ELDV' to detect pinsense for Loongson Huacai Chen
@ 2026-05-26 14:31 ` Takashi Iwai
  2026-05-26 16:42   ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2026-05-26 14:31 UTC (permalink / raw)
  To: Huacai Chen
  Cc: Takashi Iwai, Jaroslav Kysela, Huacai Chen, linux-sound,
	linux-kernel, Xuerui Wang, Jiaxun Yang, stable, Baoqi Zhang,
	Haowei Zheng

On Tue, 26 May 2026 13:19:40 +0200,
Huacai Chen wrote:
> 
> Due to a hardware defect, for Loongson PCI HDMI devices with a reversion
> ID of 2, the pin sense status must be determined via the ELD.
> 
> Add a codec flag, eld_jack_detect, to indicate this case, and do special
> handlings in read_pin_sense().
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Baoqi Zhang <zhangbaoqi@loongson.cn>
> Signed-off-by: Haowei Zheng <zhenghaowei@loongson.cn>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>  include/sound/hda_codec.h    | 1 +
>  sound/hda/codecs/hdmi/hdmi.c | 8 +++++++-
>  sound/hda/common/jack.c      | 4 ++++
>  3 files changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
> index 24581080e26a..1a1fe7a904c3 100644
> --- a/include/sound/hda_codec.h
> +++ b/include/sound/hda_codec.h
> @@ -259,6 +259,7 @@ struct hda_codec {
>  	unsigned int forced_resume:1; /* forced resume for jack */
>  	unsigned int no_stream_clean_at_suspend:1; /* do not clean streams at suspend */
>  	unsigned int ctl_dev_id:1; /* old control element id build behaviour */
> +	unsigned int eld_jack_detect:1;	/* Machine jack-detection by ELD */
>  
>  	unsigned long power_on_acct;
>  	unsigned long power_off_acct;
> diff --git a/sound/hda/codecs/hdmi/hdmi.c b/sound/hda/codecs/hdmi/hdmi.c
> index f20d1715da62..423cd9f683c6 100644
> --- a/sound/hda/codecs/hdmi/hdmi.c
> +++ b/sound/hda/codecs/hdmi/hdmi.c
> @@ -2285,6 +2285,7 @@ EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_acomp_init, "SND_HDA_CODEC_HDMI");
>  enum {
>  	MODEL_GENERIC,
>  	MODEL_GF,
> +	MODEL_LOONGSON,
>  };
>  
>  static int generichdmi_probe(struct hda_codec *codec,
> @@ -2302,6 +2303,11 @@ static int generichdmi_probe(struct hda_codec *codec,
>  	if (id->driver_data == MODEL_GF)
>  		codec->no_sticky_stream = 1;
>  
> +	if (id->driver_data == MODEL_LOONGSON) {
> +		if (codec->bus && codec->bus->pci->revision == 0x2)
> +			codec->eld_jack_detect = 1; /* Jack-detection by ELD */
> +	}
> +
>  	return 0;
>  }
>  
> @@ -2319,7 +2325,7 @@ static const struct hda_codec_ops generichdmi_codec_ops = {
>  /*
>   */
>  static const struct hda_device_id snd_hda_id_generichdmi[] = {
> -	HDA_CODEC_ID_MODEL(0x00147a47, "Loongson HDMI",		MODEL_GENERIC),
> +	HDA_CODEC_ID_MODEL(0x00147a47, "Loongson HDMI",		MODEL_LOONGSON),
>  	HDA_CODEC_ID_MODEL(0x10951390, "SiI1390 HDMI",		MODEL_GENERIC),
>  	HDA_CODEC_ID_MODEL(0x10951392, "SiI1392 HDMI",		MODEL_GENERIC),
>  	HDA_CODEC_ID_MODEL(0x11069f84, "VX11 HDMI/DP",		MODEL_GENERIC),
> diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
> index 98ba1c4d5ba4..1f0ebf9cd151 100644
> --- a/sound/hda/common/jack.c
> +++ b/sound/hda/common/jack.c
> @@ -58,6 +58,10 @@ static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id)
>  				  AC_VERB_GET_PIN_SENSE, dev_id);
>  	if (codec->inv_jack_detect)
>  		val ^= AC_PINSENSE_PRESENCE;
> +	if (codec->eld_jack_detect) {
> +		val &= ~AC_PINSENSE_PRESENCE;
> +		val |= !!(val & AC_PINSENSE_ELDV) << 31;
> +	}

IMO it's worth for a comment in the above; basically it's faking the
AC_PINSENSE_PRESENCE from AC_PINSENSE_ELDV bit, which explains the
magic shift number.


thanks,

Takashi

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

* Re: [PATCH] ALSA: hda/hdmi: Use 'AC_PINSENSE_ELDV' to detect pinsense for Loongson
  2026-05-26 14:31 ` Takashi Iwai
@ 2026-05-26 16:42   ` Takashi Iwai
  0 siblings, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-05-26 16:42 UTC (permalink / raw)
  To: Huacai Chen
  Cc: Takashi Iwai, Jaroslav Kysela, Huacai Chen, linux-sound,
	linux-kernel, Xuerui Wang, Jiaxun Yang, stable, Baoqi Zhang,
	Haowei Zheng

On Tue, 26 May 2026 16:31:04 +0200,
Takashi Iwai wrote:
> 
> On Tue, 26 May 2026 13:19:40 +0200,
> Huacai Chen wrote:
> > 
> > Due to a hardware defect, for Loongson PCI HDMI devices with a reversion
> > ID of 2, the pin sense status must be determined via the ELD.
> > 
> > Add a codec flag, eld_jack_detect, to indicate this case, and do special
> > handlings in read_pin_sense().
> > 
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Baoqi Zhang <zhangbaoqi@loongson.cn>
> > Signed-off-by: Haowei Zheng <zhenghaowei@loongson.cn>
> > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> >  include/sound/hda_codec.h    | 1 +
> >  sound/hda/codecs/hdmi/hdmi.c | 8 +++++++-
> >  sound/hda/common/jack.c      | 4 ++++
> >  3 files changed, 12 insertions(+), 1 deletion(-)
> > 
> > diff --git a/include/sound/hda_codec.h b/include/sound/hda_codec.h
> > index 24581080e26a..1a1fe7a904c3 100644
> > --- a/include/sound/hda_codec.h
> > +++ b/include/sound/hda_codec.h
> > @@ -259,6 +259,7 @@ struct hda_codec {
> >  	unsigned int forced_resume:1; /* forced resume for jack */
> >  	unsigned int no_stream_clean_at_suspend:1; /* do not clean streams at suspend */
> >  	unsigned int ctl_dev_id:1; /* old control element id build behaviour */
> > +	unsigned int eld_jack_detect:1;	/* Machine jack-detection by ELD */
> >  
> >  	unsigned long power_on_acct;
> >  	unsigned long power_off_acct;
> > diff --git a/sound/hda/codecs/hdmi/hdmi.c b/sound/hda/codecs/hdmi/hdmi.c
> > index f20d1715da62..423cd9f683c6 100644
> > --- a/sound/hda/codecs/hdmi/hdmi.c
> > +++ b/sound/hda/codecs/hdmi/hdmi.c
> > @@ -2285,6 +2285,7 @@ EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_acomp_init, "SND_HDA_CODEC_HDMI");
> >  enum {
> >  	MODEL_GENERIC,
> >  	MODEL_GF,
> > +	MODEL_LOONGSON,
> >  };
> >  
> >  static int generichdmi_probe(struct hda_codec *codec,
> > @@ -2302,6 +2303,11 @@ static int generichdmi_probe(struct hda_codec *codec,
> >  	if (id->driver_data == MODEL_GF)
> >  		codec->no_sticky_stream = 1;
> >  
> > +	if (id->driver_data == MODEL_LOONGSON) {
> > +		if (codec->bus && codec->bus->pci->revision == 0x2)
> > +			codec->eld_jack_detect = 1; /* Jack-detection by ELD */
> > +	}
> > +
> >  	return 0;
> >  }
> >  
> > @@ -2319,7 +2325,7 @@ static const struct hda_codec_ops generichdmi_codec_ops = {
> >  /*
> >   */
> >  static const struct hda_device_id snd_hda_id_generichdmi[] = {
> > -	HDA_CODEC_ID_MODEL(0x00147a47, "Loongson HDMI",		MODEL_GENERIC),
> > +	HDA_CODEC_ID_MODEL(0x00147a47, "Loongson HDMI",		MODEL_LOONGSON),
> >  	HDA_CODEC_ID_MODEL(0x10951390, "SiI1390 HDMI",		MODEL_GENERIC),
> >  	HDA_CODEC_ID_MODEL(0x10951392, "SiI1392 HDMI",		MODEL_GENERIC),
> >  	HDA_CODEC_ID_MODEL(0x11069f84, "VX11 HDMI/DP",		MODEL_GENERIC),
> > diff --git a/sound/hda/common/jack.c b/sound/hda/common/jack.c
> > index 98ba1c4d5ba4..1f0ebf9cd151 100644
> > --- a/sound/hda/common/jack.c
> > +++ b/sound/hda/common/jack.c
> > @@ -58,6 +58,10 @@ static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid, int dev_id)
> >  				  AC_VERB_GET_PIN_SENSE, dev_id);
> >  	if (codec->inv_jack_detect)
> >  		val ^= AC_PINSENSE_PRESENCE;
> > +	if (codec->eld_jack_detect) {
> > +		val &= ~AC_PINSENSE_PRESENCE;
> > +		val |= !!(val & AC_PINSENSE_ELDV) << 31;
> > +	}
> 
> IMO it's worth for a comment in the above; basically it's faking the
> AC_PINSENSE_PRESENCE from AC_PINSENSE_ELDV bit, which explains the
> magic shift number.

... or an idiomatic form would be even simpler & safer:

		if (val & AC_PINSENSE_ELDV)
			val |= AC_PINSENSE_PRESENCE;
		else
			val &= ~AC_PINSENSE_PRESENCE;


thanks,

Takashi

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

end of thread, other threads:[~2026-05-26 16:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-26 11:19 [PATCH] ALSA: hda/hdmi: Use 'AC_PINSENSE_ELDV' to detect pinsense for Loongson Huacai Chen
2026-05-26 14:31 ` Takashi Iwai
2026-05-26 16:42   ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox