diff mbox series

[v1,2/4] ALSA: hda - Move snd_hda_jack_report_sync() call inside hdmi_present_sense_via_verbs()

Message ID 20200204072017.9554-2-nmahale@nvidia.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/4] ALSA: hda - Simplify hdmi_present_sense_via_verbs() | expand

Commit Message

Nikhil Mahale Feb. 4, 2020, 7:20 a.m. UTC
Move snd_hda_jack_report_sync() call inside
hdmi_present_sense_via_verbs(), and add parameter to control it.
snd_hda_jack_report_sync() should get called only for !acomp
drivers.

Signed-off-by: Nikhil Mahale <nmahale@nvidia.com>
---
 sound/pci/hda/patch_hdmi.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index ee084676f625..de45f5e5c724 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -753,7 +753,9 @@  static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
  * Unsolicited events
  */
 
-static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
+static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin,
+			       int repoll,
+			       bool jack_report_sync);
 
 static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
 				      int dev_id)
@@ -764,8 +766,8 @@  static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
 	if (pin_idx < 0)
 		return;
 	mutex_lock(&spec->pcm_lock);
-	if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
-		snd_hda_jack_report_sync(codec);
+	hdmi_present_sense(get_pin(spec, pin_idx),
+			   1, true /* jack_report_sync */);
 	mutex_unlock(&spec->pcm_lock);
 }
 
@@ -1551,8 +1553,9 @@  static bool update_eld(struct hda_codec *codec,
 }
 
 /* update ELD and jack state via HD-audio verbs */
-static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
-					 int repoll)
+static void hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
+					 int repoll,
+					 bool jack_report_sync)
 {
 	struct hda_jack_tbl *jack;
 	struct hda_codec *codec = per_pin->codec;
@@ -1608,9 +1611,11 @@  static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
 		jack->pin_sense = (eld->monitor_present && eld->eld_valid) ?
 			AC_PINSENSE_PRESENCE : 0;
 	}
-	mutex_unlock(&per_pin->lock);
 
-	return !do_repoll;
+	if (!do_repoll && jack_report_sync)
+		snd_hda_jack_report_sync(codec);
+
+	mutex_unlock(&per_pin->lock);
 }
 
 static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
@@ -1686,26 +1691,25 @@  static void sync_eld_via_acomp(struct hda_codec *codec,
 	mutex_unlock(&per_pin->lock);
 }
 
-static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
+static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin,
+			       int repoll,
+			       bool jack_report_sync)
 {
 	struct hda_codec *codec = per_pin->codec;
-	int ret;
 
 	/* no temporary power up/down needed for component notifier */
 	if (!codec_has_acomp(codec)) {
+		int ret;
+
 		ret = snd_hda_power_up_pm(codec);
 		if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) {
 			snd_hda_power_down_pm(codec);
-			return false;
 		}
-		ret = hdmi_present_sense_via_verbs(per_pin, repoll);
+		hdmi_present_sense_via_verbs(per_pin, repoll, jack_report_sync);
 		snd_hda_power_down_pm(codec);
 	} else {
 		sync_eld_via_acomp(codec, per_pin);
-		ret = false; /* don't call snd_hda_jack_report_sync() */
 	}
-
-	return ret;
 }
 
 static void hdmi_repoll_eld(struct work_struct *work)
@@ -1725,8 +1729,9 @@  static void hdmi_repoll_eld(struct work_struct *work)
 		per_pin->repoll_count = 0;
 
 	mutex_lock(&spec->pcm_lock);
-	if (hdmi_present_sense(per_pin, per_pin->repoll_count))
-		snd_hda_jack_report_sync(per_pin->codec);
+	hdmi_present_sense(per_pin,
+			   per_pin->repoll_count,
+			   true /* jack_report_sync */);
 	mutex_unlock(&spec->pcm_lock);
 }
 
@@ -2281,7 +2286,7 @@  static int generic_hdmi_build_controls(struct hda_codec *codec)
 	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
 		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
 
-		hdmi_present_sense(per_pin, 0);
+		hdmi_present_sense(per_pin, 0, false /* jack_report_sync */);
 	}
 
 	/* add channel maps */
@@ -2408,7 +2413,7 @@  static int generic_hdmi_resume(struct hda_codec *codec)
 
 	for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
 		struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
-		hdmi_present_sense(per_pin, 1);
+		hdmi_present_sense(per_pin, 1, false /* jack_report_sync */);
 	}
 	return 0;
 }