[PATCH RFC 1/3] drm/display/dp: Export function to wake the sink AUX_CH

Arun R Murthy posted 3 patches 1 month ago
[PATCH RFC 1/3] drm/display/dp: Export function to wake the sink AUX_CH
Posted by Arun R Murthy 1 month ago
On a native AUX_CH transaction timeout, as per Spec 2.1 Section 2.3.4
says that if the AUX Reply Timeout timer timesout, DPTX can rety for 3
times because the No Reply may be due to the DPRX waking up from
power-saving state.
Export a function to wake the DP sink AUX_CH.

Signed-off-by: Arun R Murthy <arun.r.murthy@intel.com>
---
 drivers/gpu/drm/display/drm_dp_helper.c | 36 +++++++++++++++++++++++++++++++++
 include/drm/display/drm_dp_helper.h     |  1 +
 2 files changed, 37 insertions(+)

diff --git a/drivers/gpu/drm/display/drm_dp_helper.c b/drivers/gpu/drm/display/drm_dp_helper.c
index a697cc227e28964cd8322803298178e7d788e820..1b8aa543ec3dc5819948af6f2724f3514b96b918 100644
--- a/drivers/gpu/drm/display/drm_dp_helper.c
+++ b/drivers/gpu/drm/display/drm_dp_helper.c
@@ -701,6 +701,42 @@ void drm_dp_dpcd_set_powered(struct drm_dp_aux *aux, bool powered)
 }
 EXPORT_SYMBOL(drm_dp_dpcd_set_powered);
 
+/**
+ * drm_dp_wake_sink() - Try to wake up the sink device AUX_CH if in sleep
+ *
+ * @aux: DisplayPort AUX channel
+ */
+void drm_dp_wake_sink(struct drm_dp_aux *aux)
+{
+	const u8 wake_retry = 6;
+	u8 value = 0;
+	int ret = 0;
+
+	/*
+	 * Wake the sink device
+	 * Spec DP2.1 section 2.3.1.2 if AUX CH is powered down by writing 0x02
+	 * to DP_SET_POWER dpcd reg, 1ms time would be required to wake it up
+	 */
+	ret = poll_timeout_us(ret = drm_dp_dpcd_readb(aux, DP_SET_POWER, &value),
+			      ret > 0,
+			      1000, wake_retry * 1000, true);
+
+	/*
+	 * If sink is in D3 then it may not respond to the AUX tx so
+	 * wake it up to D3_AUX_ON state
+	 * If the above poll_timeout_us fails, try waking the sink.
+	 */
+	if (value == DP_SET_POWER_D3 || ret < 0) {
+		/* After setting to D0 need a min of 1ms to wake(Spec DP2.1 sec 2.3.1.2) */
+		drm_dp_dpcd_writeb(aux, DP_SET_POWER,
+				   DP_SET_POWER_D0);
+		fsleep(1000);
+		drm_dp_dpcd_writeb(aux, DP_SET_POWER,
+				   DP_SET_POWER_D3_AUX_ON);
+	}
+}
+EXPORT_SYMBOL(drm_dp_wake_sink);
+
 /**
  * drm_dp_dpcd_set_probe() - Set whether a probing before DPCD access is done
  * @aux: DisplayPort AUX channel
diff --git a/include/drm/display/drm_dp_helper.h b/include/drm/display/drm_dp_helper.h
index 1d0acd58f48676f60ff6a07cc6812f72cbb452e8..933428025c4d75ab7a0aa63039ed5f8e45ca625b 100644
--- a/include/drm/display/drm_dp_helper.h
+++ b/include/drm/display/drm_dp_helper.h
@@ -546,6 +546,7 @@ struct drm_dp_aux {
 	bool dpcd_probe_disabled;
 };
 
+void drm_dp_wake_sink(struct drm_dp_aux *aux);
 int drm_dp_dpcd_probe(struct drm_dp_aux *aux, unsigned int offset);
 void drm_dp_dpcd_set_powered(struct drm_dp_aux *aux, bool powered);
 void drm_dp_dpcd_set_probe(struct drm_dp_aux *aux, bool enable);

-- 
2.25.1