All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org, "Wang,
	Zhenyu Z" <zhenyu.z.wang@intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"Barnes, Jesse" <jesse.barnes@intel.com>,
	Jeremy Bush <contractfrombelow@gmail.com>,
	Christopher White <c.white@pulseforce.com>,
	"Bossart, Pierre-louis" <pierre-louis.bossart@intel.com>
Subject: [PATCH 2/2] hda - delayed ELD repoll
Date: Tue, 15 Nov 2011 22:33:15 +0800	[thread overview]
Message-ID: <20111115143315.GA28561@localhost> (raw)
In-Reply-To: <20111115143155.GA28175@localhost>

The Intel HDMI chips (ironlake at least) are found to have ~250ms delay
between the ELD_Valid=1 hotplug event is send and the ELD buffer becomes
actually readable. During the time the ELD buffer is mysteriously all 0.

Fix it by scheduling a delayed work to re-read ELD buffer after 300ms.

Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
 sound/pci/hda/hda_local.h  |    2 +
 sound/pci/hda/patch_hdmi.c |   49 ++++++++++++++++++++++++++++++-----
 2 files changed, 44 insertions(+), 7 deletions(-)

--- linux.orig/sound/pci/hda/hda_local.h	2011-11-15 21:29:53.000000000 +0800
+++ linux/sound/pci/hda/hda_local.h	2011-11-15 21:29:54.000000000 +0800
@@ -655,6 +655,8 @@ struct hdmi_eld {
 #ifdef CONFIG_PROC_FS
 	struct snd_info_entry *proc_entry;
 #endif
+	struct hda_codec *codec;
+	struct delayed_work work;
 };
 
 int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
--- linux.orig/sound/pci/hda/patch_hdmi.c	2011-11-15 21:29:53.000000000 +0800
+++ linux/sound/pci/hda/patch_hdmi.c	2011-11-15 21:31:48.000000000 +0800
@@ -746,7 +746,7 @@ static void hdmi_setup_audio_infoframe(s
  */
 
 static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
-			       struct hdmi_eld *eld);
+			       struct hdmi_eld *eld, bool retry);
 
 static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
 {
@@ -766,7 +766,7 @@ static void hdmi_intrinsic_event(struct 
 		return;
 	eld = &spec->pins[pin_idx].sink_eld;
 
-	hdmi_present_sense(codec, pin_nid, eld);
+	hdmi_present_sense(codec, pin_nid, eld, true);
 
 	/*
 	 * HDMI sink's ELD info cannot always be retrieved for now, e.g.
@@ -969,7 +969,7 @@ static int hdmi_read_pin_conn(struct hda
 }
 
 static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
-			       struct hdmi_eld *eld)
+			       struct hdmi_eld *eld, bool retry)
 {
 	/*
 	 * Always execute a GetPinSense verb here, even when called from
@@ -992,13 +992,31 @@ static void hdmi_present_sense(struct hd
 		"HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
 		codec->addr, pin_nid, eld->monitor_present, eld_valid);
 
-	if (eld_valid)
+	if (eld_valid) {
 		if (!snd_hdmi_get_eld(eld, codec, pin_nid))
 			snd_hdmi_show_eld(eld);
+		else {
+			queue_delayed_work(codec->bus->workq,
+					   &eld->work,
+					   msecs_to_jiffies(300));
+		}
+	}
 
 	snd_hda_input_jack_report(codec, pin_nid);
 }
 
+static void hda_eld_work(struct work_struct *work)
+{
+	struct hdmi_eld *eld = container_of(
+				container_of(work, struct delayed_work, work),
+				struct hdmi_eld, work);
+	struct hdmi_spec_per_pin *per_pin =
+			container_of(eld, struct hdmi_spec_per_pin, sink_eld);
+	struct hda_codec *codec = eld->codec;
+
+	hdmi_present_sense(codec, per_pin->pin_nid, eld, false);
+}
+
 static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
 {
 	struct hdmi_spec *spec = codec->spec;
@@ -1227,7 +1245,7 @@ static int generic_hdmi_build_jack(struc
 	if (err < 0)
 		return err;
 
-	hdmi_present_sense(codec, per_pin->pin_nid, &per_pin->sink_eld);
+	hdmi_present_sense(codec, per_pin->pin_nid, &per_pin->sink_eld, false);
 	return 0;
 }
 
@@ -1263,6 +1281,23 @@ static int generic_hdmi_build_controls(s
 	return 0;
 }
 
+static void snd_hda_eld_init(struct hda_codec *codec, struct hdmi_eld *eld,
+			     int pin_idx)
+{
+	eld->codec = codec;
+	INIT_DELAYED_WORK(&eld->work, hda_eld_work);
+
+	snd_hda_eld_proc_new(codec, eld, pin_idx);
+}
+
+static void snd_hda_eld_free(struct hda_codec *codec, struct hdmi_eld *eld)
+{
+	cancel_delayed_work(&eld->work);
+	flush_workqueue(codec->bus->workq);
+
+	snd_hda_eld_proc_free(codec, eld);
+}
+
 static int generic_hdmi_init(struct hda_codec *codec)
 {
 	struct hdmi_spec *spec = codec->spec;
@@ -1278,7 +1313,7 @@ static int generic_hdmi_init(struct hda_
 				    AC_VERB_SET_UNSOLICITED_ENABLE,
 				    AC_USRSP_EN | pin_nid);
 
-		snd_hda_eld_proc_new(codec, eld, pin_idx);
+		snd_hda_eld_init(codec, eld, pin_idx);
 	}
 	return 0;
 }
@@ -1292,7 +1327,7 @@ static void generic_hdmi_free(struct hda
 		struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
 		struct hdmi_eld *eld = &per_pin->sink_eld;
 
-		snd_hda_eld_proc_free(codec, eld);
+		snd_hda_eld_free(codec, eld);
 	}
 	snd_hda_input_jack_free(codec);

  reply	other threads:[~2011-11-15 14:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-15 14:31 [PATCH 1/2] hda - fix ELD memory leak Wu Fengguang
2011-11-15 14:33 ` Wu Fengguang [this message]
2011-11-15 16:56   ` [PATCH 2/2] hda - delayed ELD repoll Wu Fengguang
2011-11-15 16:57     ` [PATCH 2/2 v2] " Wu Fengguang
2011-11-15 17:10       ` Takashi Iwai
2011-11-16  2:35         ` Wu Fengguang
2011-11-16  7:02       ` Paul Menzel
2011-11-15 18:25   ` [PATCH 2/2] " Stephen Warren
2011-11-16  2:48     ` [alsa-devel] " Wu Fengguang
2011-11-16 15:51       ` Stephen Warren
2011-11-16 15:57         ` Takashi Iwai
2011-11-16 16:12           ` Stephen Warren
2011-11-16 16:16             ` [alsa-devel] " Takashi Iwai
2011-11-16 22:46         ` Wu Fengguang
2011-11-16 23:12           ` Wu Fengguang
2011-11-15 14:35 ` [PATCH 1/2] hda - fix ELD memory leak Takashi Iwai
2011-11-15 14:41   ` Wu Fengguang
2011-11-15 14:45     ` Takashi Iwai
2011-11-15 16:56       ` Wu Fengguang
2011-11-15 18:19 ` Stephen Warren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111115143315.GA28561@localhost \
    --to=fengguang.wu@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=c.white@pulseforce.com \
    --cc=contractfrombelow@gmail.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=jesse.barnes@intel.com \
    --cc=pierre-louis.bossart@intel.com \
    --cc=tiwai@suse.de \
    --cc=zhenyu.z.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.