Skip to contentSkip to conversation

ALSA: hda/hdmi - Read the pin sense from register when repolling

PATCH Applied Hui Wang 2 participants 5 messages May 6, 2019 Sound

lore
Share & tools
lore

Hui Wang

author
#0 lore raw

PATCH v2 1/2 ALSA: hda/hdmi - Read the pin sense from register when repolling

The driver will check the monitor presence when resuming from suspend, starting poll or interrupt triggers. In these 3 situations, the jack_dirty will be set to 1 first, then the hda_jack.c reads the pin_sense from register, after reading the register, the jack_dirty will be set to 0. But hdmi_repoll_work() is enabled in these 3 situations, It will read the pin_sense a couple of times subsequently, since the jack_dirty is 0 now, It does not read the register anymore, instead it uses the shadow pin_sense which is read at the first time.

It is meaningless to check the shadow pin_sense a couple of times, we need to read the register to check the real plugging state, so we set the jack_dirty to 1 in the hdmi_repoll_work().

---
 sound/pci/hda/patch_hdmi.c | 5 +++++
 1 file changed, 5 insertions(+)
sound/pci/hda/patch_hdmi.c +5 -0
index 8b3ac690efa3..410d94301941 100644
@@ -1663,6 +1663,11 @@ static void hdmi_repoll_eld(struct work_struct *work)
 	container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
 	struct hda_codec *codec = per_pin->codec;
 	struct hdmi_spec *spec = codec->spec;
+	struct hda_jack_tbl *jack;
+
+	jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
+	if (jack)
+		jack = jack->jack_dirty = 1;
 
 	if (per_pin->repoll_count++ > 6)
 		per_pin->repoll_count = 0;
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 2/2 ALSA: hda/hdmi - Consider eld_valid when reporting jack event

On the machines with AMD GPU or Nvidia GPU, we often meet this issue:
after s3, there are 4 HDMI/DP audio devices in the gnome-sound-setting even there is no any monitors plugged.

When this problem happens, we check the /proc/asound/cardX/eld#N.M, we will find the monitor_present=1, eld_valid=0.

The root cause is BIOS or GPU driver makes the PRESENCE valid even no monitor plugged, and of course the driver will not get the valid eld_data subsequently.

In this situation, we should not report the jack_plugged event, to do so, let us change the function hdmi_present_sense_via_verbs(). In this function, it reads the pin_sense via snd_hda_pin_sense(), after calling this function, the jack_dirty is 0, and before exiting via_verbs(), we change the shadow pin_sense according to both monitor_present and eld_valid, then in the snd_hda_jack_report_sync(), since the jack_dirty is still 0, it will report jack event according to this modified shadow pin_sense.

After this change, the driver will not report Jack_is_plugged event through hdmi_present_sense_via_verbs() if monitor_present is 1 and eld_valid is 0.

---
 sound/pci/hda/patch_hdmi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/pci/hda/patch_hdmi.c +4 -2
index 410d94301941..ec88b2e97c45 100644
@@ -1551,9 +1551,11 @@ static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
 	ret = !repoll || !eld->monitor_present || eld->eld_valid;
 
 	jack = snd_hda_jack_tbl_get(codec, pin_nid);
-	if (jack)
+	if (jack) {
 		jack->block_report = !ret;
-
+		jack->pin_sense = (eld->monitor_present && eld->eld_valid) ?
+			AC_PINSENSE_PRESENCE : 0;
+	}
 	mutex_unlock(&per_pin->lock);
 	return ret;
 }
Signature · 1 line
2.17.1
Applied
#2 lore raw
In reply to Hui Wang
Quoted 10 lines · Hui Wang

The driver will check the monitor presence when resuming from suspend, starting poll or interrupt triggers. In these 3 situations, the jack_dirty will be set to 1 first, then the hda_jack.c reads the pin_sense from register, after reading the register, the jack_dirty will be set to 0. But hdmi_repoll_work() is enabled in these 3 situations, It will read the pin_sense a couple of times subsequently, since the jack_dirty is 0 now, It does not read the register anymore, instead it uses the shadow pin_sense which is read at the first time.

Quoted 5 lines

It is meaningless to check the shadow pin_sense a couple of times, we need to read the register to check the real plugging state, so we set the jack_dirty to 1 in the hdmi_repoll_work().

Thanks, applied both patches.
They deserve for Cc-to-stable, so I added it.

Takashi

#3 lore raw
In reply to Hui Wang

sound/pci/hda/patch_hdmi.c static void hdmi_repoll_eld(struct work_struct *work) · line 1670

Quoted 10 lines · Hui Wang
sound/pci/hda/patch_hdmi.c +5 -0
@@ -1663,6 +1663,11 @@ static void hdmi_repoll_eld(struct work_struct *work)
 	container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
 	struct hda_codec *codec = per_pin->codec;
 	struct hdmi_spec *spec = codec->spec;
+	struct hda_jack_tbl *jack;
+
+	jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
+	if (jack)
+		jack = jack->jack_dirty = 1;

Oh, and I corrected the obvious typo above manually while applying. We don't need to substitute jack twice.

Takashi

author
#4 lore raw
Quoted 13 lines · Takashi Iwai

sound/pci/hda/patch_hdmi.c static void hdmi_repoll_eld(struct work_struct *work) · line 1670

Quoted 9 lines · Hui Wang
sound/pci/hda/patch_hdmi.c +5 -0
@@ -1663,6 +1663,11 @@ static void hdmi_repoll_eld(struct work_struct *work)
  	container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
  	struct hda_codec *codec = per_pin->codec;
  	struct hdmi_spec *spec = codec->spec;
+	struct hda_jack_tbl *jack;
+
+	jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
+	if (jack)
+		jack = jack->jack_dirty = 1;

Oh, and I corrected the obvious typo above manually while applying. We don't need to substitute jack twice.

Oh, sorry.

Quoted 8 lines

Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel