All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime@cerno.tech>
To: Daniel Vetter <daniel.vetter@intel.com>,
	David Airlie <airlied@linux.ie>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Maxime Ripard <maxime@cerno.tech>
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 09/13] drm/vc4: hdmi: Simplify the hotplug handling
Date: Tue,  2 Nov 2021 15:59:40 +0100	[thread overview]
Message-ID: <20211102145944.259181-10-maxime@cerno.tech> (raw)
In-Reply-To: <20211102145944.259181-1-maxime@cerno.tech>

Our detect callback has a bunch of operations to perform depending on
the current and last status of the connector, such a setting the CEC
physical address or enabling the scrambling again.

This is currently dealt with a bunch of if / else statetements that make
it fairly difficult to read and extend.

Let's move all that logic to a function of its own.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 50 ++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index 288c2bfbf88b..4f2f138f93e3 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -177,11 +177,35 @@ static void vc4_hdmi_cec_update_clk_div(struct vc4_hdmi *vc4_hdmi) {}
 
 static void vc4_hdmi_enable_scrambling(struct drm_encoder *encoder);
 
+static void vc4_hdmi_handle_hotplug(struct vc4_hdmi *vc4_hdmi,
+				    enum drm_connector_status status)
+{
+	struct drm_connector *connector = &vc4_hdmi->connector;
+	struct edid *edid;
+
+	if (status == connector->status)
+		return;
+
+	if (status == connector_status_disconnected) {
+		cec_phys_addr_invalidate(vc4_hdmi->cec_adap);
+		return;
+	}
+
+	edid = drm_get_edid(connector, vc4_hdmi->ddc);
+	if (!edid)
+		return;
+
+	cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid);
+	kfree(edid);
+
+	vc4_hdmi_enable_scrambling(&vc4_hdmi->encoder.base.base);
+}
+
 static enum drm_connector_status
 vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
 {
 	struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
-	bool connected = false;
+	enum drm_connector_status status = connector_status_disconnected;
 
 	/*
 	 * NOTE: This function should really take vc4_hdmi->mutex, but
@@ -198,7 +222,7 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
 
 	if (vc4_hdmi->hpd_gpio) {
 		if (gpiod_get_value_cansleep(vc4_hdmi->hpd_gpio))
-			connected = true;
+			status = connector_status_connected;
 	} else {
 		unsigned long flags;
 		u32 hotplug;
@@ -208,27 +232,13 @@ vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
 		spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
 
 		if (hotplug & VC4_HDMI_HOTPLUG_CONNECTED)
-			connected = true;
+			status = connector_status_connected;
 	}
 
-	if (connected) {
-		if (connector->status != connector_status_connected) {
-			struct edid *edid = drm_get_edid(connector, vc4_hdmi->ddc);
-
-			if (edid) {
-				cec_s_phys_addr_from_edid(vc4_hdmi->cec_adap, edid);
-				kfree(edid);
-			}
-		}
-
-		vc4_hdmi_enable_scrambling(&vc4_hdmi->encoder.base.base);
-		pm_runtime_put(&vc4_hdmi->pdev->dev);
-		return connector_status_connected;
-	}
-
-	cec_phys_addr_invalidate(vc4_hdmi->cec_adap);
+	vc4_hdmi_handle_hotplug(vc4_hdmi, status);
 	pm_runtime_put(&vc4_hdmi->pdev->dev);
-	return connector_status_disconnected;
+
+	return status;
 }
 
 static void vc4_hdmi_connector_destroy(struct drm_connector *connector)
-- 
2.32.0


  parent reply	other threads:[~2021-11-02 15:00 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 14:59 [PATCH 00/13] drm: Add generic helpers for HDMI scrambling Maxime Ripard
2021-11-02 14:59 ` [PATCH 01/13] drm/connector: Add define for HDMI 1.4 Maximum Pixel Rate Maxime Ripard
2021-11-02 14:59   ` Maxime Ripard
2021-11-02 14:59   ` Maxime Ripard
2021-11-02 14:59   ` Maxime Ripard
2021-11-02 14:59   ` [Intel-gfx] " Maxime Ripard
2021-11-02 14:59   ` Maxime Ripard
2021-11-02 17:50   ` Alex Deucher
2021-11-02 17:50     ` Alex Deucher
2021-11-02 17:50     ` Alex Deucher
2021-11-02 17:50     ` Alex Deucher
2021-11-02 17:50     ` [Intel-gfx] " Alex Deucher
2021-11-02 17:50     ` Alex Deucher
2021-11-03  9:08   ` Neil Armstrong
2021-11-03  9:08     ` Neil Armstrong
2021-11-03  9:08     ` Neil Armstrong
2021-11-03  9:08     ` Neil Armstrong
2021-11-03  9:08     ` [Intel-gfx] " Neil Armstrong
2021-11-03  9:08     ` Neil Armstrong
2021-11-03 11:02   ` Ville Syrjälä
2021-11-03 11:02     ` Ville Syrjälä
2021-11-03 11:02     ` Ville Syrjälä
2021-11-03 11:02     ` Ville Syrjälä
2021-11-03 11:02     ` [Intel-gfx] " Ville Syrjälä
2021-11-03 11:02     ` Ville Syrjälä
2021-11-03 18:05     ` Ville Syrjälä
2021-11-03 18:05       ` Ville Syrjälä
2021-11-03 18:05       ` Ville Syrjälä
2021-11-03 18:05       ` [Intel-gfx] " Ville Syrjälä
2021-11-03 18:05       ` Ville Syrjälä
2021-11-04  8:48       ` Maxime Ripard
2021-11-04  8:48         ` Maxime Ripard
2021-11-04  8:48         ` Maxime Ripard
2021-11-04  8:48         ` [Intel-gfx] " Maxime Ripard
2021-11-04  8:48         ` Maxime Ripard
2021-11-04 15:41         ` Ville Syrjälä
2021-11-04 15:41           ` Ville Syrjälä
2021-11-04 15:41           ` Ville Syrjälä
2021-11-04 15:41           ` [Intel-gfx] " Ville Syrjälä
2021-11-04 15:41           ` Ville Syrjälä
2021-11-08 14:59           ` Maxime Ripard
2021-11-08 14:59             ` Maxime Ripard
2021-11-08 14:59             ` Maxime Ripard
2021-11-08 14:59             ` [Intel-gfx] " Maxime Ripard
2021-11-08 14:59             ` Maxime Ripard
2021-11-02 14:59 ` [PATCH 02/13] drm/connector: Add helper to check if a mode requires scrambling Maxime Ripard
2021-11-02 14:59   ` Maxime Ripard
2021-11-04 15:37   ` Ville Syrjälä
2021-11-04 15:37     ` Ville Syrjälä
2021-11-05 18:02     ` Daniel Vetter
2021-11-05 18:02       ` Daniel Vetter
2021-11-05 18:14       ` Ville Syrjälä
2021-11-05 18:14         ` Ville Syrjälä
2021-11-08 15:58         ` Maxime Ripard
2021-11-08 15:58           ` Maxime Ripard
2021-11-08 16:03           ` Daniel Vetter
2021-11-08 16:03             ` Daniel Vetter
2021-11-08 17:55           ` Ville Syrjälä
2021-11-08 17:55             ` Ville Syrjälä
2021-11-15 12:15             ` Maxime Ripard
2021-11-15 12:15               ` Maxime Ripard
2021-11-17 10:01             ` Maxime Ripard
2021-11-17 10:01               ` Maxime Ripard
2021-11-02 14:59 ` [PATCH 03/13] drm/atomic: Add HDMI scrambler state helper Maxime Ripard
2021-11-02 14:59 ` [PATCH 04/13] drm/atomic: Add HDMI reset link helper Maxime Ripard
2021-11-02 14:59 ` [PATCH 05/13] drm/scdc: Document hotplug gotchas Maxime Ripard
2021-11-02 14:59 ` [PATCH 06/13] drm/vc4: hdmi: Remove unused argument in vc4_hdmi_supports_scrambling Maxime Ripard
2021-11-02 14:59 ` [PATCH 07/13] drm/vc4: hdmi: Remove mutex in detect Maxime Ripard
2021-11-02 14:59 ` [PATCH 08/13] drm/vc4: hdmi: Remove HDMI flag from encoder Maxime Ripard
2021-11-02 14:59 ` Maxime Ripard [this message]
2021-11-02 14:59 ` [PATCH 10/13] drm/vc4: hdmi: Simplify the connector state retrieval Maxime Ripard
2021-11-02 14:59 ` [PATCH 11/13] drm/vc4: hdmi: Switch to detect_ctx Maxime Ripard
2021-11-02 14:59 ` [PATCH 12/13] drm/vc4: hdmi: Leverage new SCDC atomic_check Maxime Ripard
2021-11-02 14:59 ` [PATCH 13/13] drm/vc4: hdmi: Reset link on hotplug 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=20211102145944.259181-10-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.