From: Maxime Ripard <maxime@cerno.tech>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
Maxime Ripard <maxime@cerno.tech>,
Daniel Vetter <daniel.vetter@intel.com>,
David Airlie <airlied@linux.ie>
Cc: Dom Cobley <dom@raspberrypi.com>,
Tim Gover <tim.gover@raspberrypi.com>,
Dave Stevenson <dave.stevenson@raspberrypi.com>,
dri-devel@lists.freedesktop.org,
Phil Elwell <phil@raspberrypi.com>
Subject: [PATCH v2 03/13] drm/atomic: Add HDMI reset link helper
Date: Thu, 18 Nov 2021 11:38:04 +0100 [thread overview]
Message-ID: <20211118103814.524670-4-maxime@cerno.tech> (raw)
In-Reply-To: <20211118103814.524670-1-maxime@cerno.tech>
During a hotplug cycle (such as a TV going out of suspend, or when the
cable is disconnected and reconnected), the expectation is that the same
state used before the disconnection is reused until the next commit.
However, the HDMI scrambling requires that some flags are set in the
monitor, and those flags are very likely to be reset when the cable has
been disconnected. This will thus result in a blank display, even if the
display pipeline configuration hasn't been modified or is in the exact
same state.
One solution would be to enable the scrambling-related bits again on
reconnection, but the HDMI 2.0 specification (Section 6.1.3.1 -
Scrambling Control) requires that the scrambling enable bit is set
before sending any scrambled video signal. Using that solution would
break that specification expectation.
Thus, we need to do a full modeset on the connector so that we disable
the video signal, enable the scrambling bit, and enable the video signal
again.
The i915 code was doing this already, so let's take its code and
convert it into a generic helper.
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
drivers/gpu/drm/drm_atomic_helper.c | 109 ++++++++++++++++++++++++++++
include/drm/drm_atomic_helper.h | 3 +
2 files changed, 112 insertions(+)
diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 2c0c6ec92820..9f3fcc65e66e 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -38,6 +38,7 @@
#include <drm/drm_gem_atomic_helper.h>
#include <drm/drm_plane_helper.h>
#include <drm/drm_print.h>
+#include <drm/drm_scdc_helper.h>
#include <drm/drm_self_refresh_helper.h>
#include <drm/drm_vblank.h>
#include <drm/drm_writeback.h>
@@ -3524,3 +3525,111 @@ drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
return input_fmts;
}
EXPORT_SYMBOL(drm_atomic_helper_bridge_propagate_bus_fmt);
+
+static int modeset_pipe(struct drm_crtc *crtc,
+ struct drm_modeset_acquire_ctx *ctx)
+{
+ struct drm_atomic_state *state;
+ struct drm_crtc_state *crtc_state;
+ int ret;
+
+ state = drm_atomic_state_alloc(crtc->dev);
+ if (!state)
+ return -ENOMEM;
+
+ state->acquire_ctx = ctx;
+
+ crtc_state = drm_atomic_get_crtc_state(state, crtc);
+ if (IS_ERR(crtc_state)) {
+ ret = PTR_ERR(crtc_state);
+ goto out;
+ }
+
+ crtc_state->connectors_changed = true;
+
+ ret = drm_atomic_commit(state);
+out:
+ drm_atomic_state_put(state);
+
+ return ret;
+}
+
+/**
+ * drm_atomic_helper_connector_hdmi_reset_link() - Resets an HDMI link
+ * @connector: DRM connector we want to reset
+ * @ctx: Lock acquisition context
+ *
+ * This helper is here to restore the HDMI link state after the
+ * connector status has changed, typically when a TV has come out of
+ * suspend or when the HDMI cable has been disconnected and then
+ * reconnected.
+ *
+ * Returns:
+ * 0 on success, a negative error code otherwise.
+ */
+int drm_atomic_helper_connector_hdmi_reset_link(struct drm_connector *connector,
+ struct drm_modeset_acquire_ctx *ctx)
+{
+ struct drm_device *drm = connector->dev;
+ struct drm_connector_state *conn_state;
+ struct drm_crtc_state *crtc_state;
+ struct drm_crtc *crtc;
+ u8 config;
+ int ret;
+
+ if (!connector)
+ return 0;
+
+ drm_WARN_ON(drm,
+ (connector->connector_type != DRM_MODE_CONNECTOR_HDMIA) &&
+ (connector->connector_type != DRM_MODE_CONNECTOR_HDMIB));
+
+ ret = drm_modeset_lock(&drm->mode_config.connection_mutex, ctx);
+ if (ret)
+ return ret;
+
+ conn_state = connector->state;
+ crtc = conn_state->crtc;
+ if (!crtc)
+ return 0;
+
+ ret = drm_modeset_lock(&crtc->mutex, ctx);
+ if (ret)
+ return ret;
+
+ crtc_state = crtc->state;
+ if (!crtc_state->active)
+ return 0;
+
+ if (!conn_state->hdmi_needs_high_tmds_ratio &&
+ !conn_state->hdmi_needs_scrambling)
+ return 0;
+
+ if (conn_state->commit &&
+ !try_wait_for_completion(&conn_state->commit->hw_done))
+ return 0;
+
+ ret = drm_scdc_readb(connector->ddc, SCDC_TMDS_CONFIG, &config);
+ if (ret < 0) {
+ drm_err(drm, "Failed to read TMDS config: %d\n", ret);
+ return 0;
+ }
+
+ if (!!(config & SCDC_TMDS_BIT_CLOCK_RATIO_BY_40) ==
+ conn_state->hdmi_needs_high_tmds_ratio &&
+ !!(config & SCDC_SCRAMBLING_ENABLE) ==
+ conn_state->hdmi_needs_scrambling)
+ return 0;
+
+ /*
+ * HDMI 2.0 says that one should not send scrambled data
+ * prior to configuring the sink scrambling, and that
+ * TMDS clock/data transmission should be suspended when
+ * changing the TMDS clock rate in the sink. So let's
+ * just do a full modeset here, even though some sinks
+ * would be perfectly happy if were to just reconfigure
+ * the SCDC settings on the fly.
+ */
+ return modeset_pipe(crtc, ctx);
+}
+EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_reset_link);
diff --git a/include/drm/drm_atomic_helper.h b/include/drm/drm_atomic_helper.h
index 4045e2507e11..d7727f9a6fe9 100644
--- a/include/drm/drm_atomic_helper.h
+++ b/include/drm/drm_atomic_helper.h
@@ -231,4 +231,7 @@ drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
u32 output_fmt,
unsigned int *num_input_fmts);
+int drm_atomic_helper_connector_hdmi_reset_link(struct drm_connector *connector,
+ struct drm_modeset_acquire_ctx *ctx);
+
#endif /* DRM_ATOMIC_HELPER_H_ */
--
2.33.1
next prev parent reply other threads:[~2021-11-18 10:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 10:38 [PATCH v2 00/13] drm: Add generic helpers for HDMI scrambling Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 01/13] drm/connector: Add helper to check if a mode requires scrambling Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 02/13] drm/atomic: Add HDMI scrambler state helper Maxime Ripard
2021-11-18 10:38 ` Maxime Ripard [this message]
2021-11-18 10:38 ` [PATCH v2 04/13] drm/scdc: Document hotplug gotchas Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 05/13] drm/vc4: hdmi: Constify drm_display_mode Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 06/13] drm/vc4: hdmi: Remove unused argument in vc4_hdmi_supports_scrambling Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 07/13] drm/vc4: hdmi: Remove mutex in detect Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 08/13] drm/vc4: hdmi: Remove HDMI flag from encoder Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 09/13] drm/vc4: hdmi: Simplify the hotplug handling Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 10/13] drm/vc4: hdmi: Simplify the connector state retrieval Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 11/13] drm/vc4: hdmi: Switch to detect_ctx Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 12/13] drm/vc4: hdmi: Leverage new SCDC atomic_check Maxime Ripard
2021-11-18 10:38 ` [PATCH v2 13/13] drm/vc4: hdmi: Reset link on hotplug Maxime Ripard
2021-11-19 16:01 ` [PATCH v2 00/13] drm: Add generic helpers for HDMI scrambling Daniel Vetter
2021-11-26 15:43 ` Maxime Ripard
2021-11-26 17:12 ` Daniel Vetter
2021-11-29 10:07 ` Maxime Ripard
2021-11-30 8:29 ` Daniel Vetter
2021-11-30 9:00 ` Maxime Ripard
2021-12-15 13:51 ` Maxime Ripard
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=20211118103814.524670-4-maxime@cerno.tech \
--to=maxime@cerno.tech \
--cc=airlied@linux.ie \
--cc=daniel.vetter@intel.com \
--cc=dave.stevenson@raspberrypi.com \
--cc=dom@raspberrypi.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=phil@raspberrypi.com \
--cc=tim.gover@raspberrypi.com \
--cc=tzimmermann@suse.de \
/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.