Skip to contentSkip to conversation

drm/bridge:anx7625: Update HDCP content status

PATCH Applied Xin Ji 4 participants 4 messages Dec 19, 2024 – Dec 20, 2024

Subsystems (3)
lore
Share & tools
lore

Xin Ji

author
#0 lore raw

PATCH v4 1/1 drm/bridge:anx7625: Update HDCP content status

When user enabled HDCP feature, userspace will set HDCP content to DRM_MODE_CONTENT_PROTECTION_DESIRED. Next, anx7625 will update HDCP content to DRM_MODE_CONTENT_PROTECTION_ENABLED if down stream support HDCP feature.

As anx7625 bridge IC will be power down after call .atomic_disable(), then all HDCP status will be lost on chip. So we should reestablish HDCP again in .atomic_enable(), and update hdcp content to DESIRE if current HDCP content is ENABLE in .atomic_disable().

v4:
- Change HDCP content value to DESIRED if HDCP status is ENABLE in bridge
interface .atomic_enable().

v3:
- Move hdcp content value checking from bridge interface
.atomic_check() to .atomic_enable()

v2:
- Add more details in commit message

---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 73 +++++++++--------------
 1 file changed, 29 insertions(+), 44 deletions(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +29 -44
index a2675b121fe4..1871262d5a97 100644
@@ -2137,49 +2137,6 @@ static void hdcp_check_work_func(struct work_struct *work)
 	drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
 }
 
-static int anx7625_connector_atomic_check(struct anx7625_data *ctx,
-					  struct drm_connector_state *state)
-{
-	struct device *dev = ctx->dev;
-	int cp;
-
-	dev_dbg(dev, "hdcp state check\n");
-	cp = state->content_protection;
-
-	if (cp == ctx->hdcp_cp)
-		return 0;
-
-	if (cp == DRM_MODE_CONTENT_PROTECTION_DESIRED) {
-		if (ctx->dp_en) {
-			dev_dbg(dev, "enable HDCP\n");
-			anx7625_hdcp_enable(ctx);
-
-			queue_delayed_work(ctx->hdcp_workqueue,
-					   &ctx->hdcp_work,
-					   msecs_to_jiffies(2000));
-		}
-	}
-
-	if (cp == DRM_MODE_CONTENT_PROTECTION_UNDESIRED) {
-		if (ctx->hdcp_cp != DRM_MODE_CONTENT_PROTECTION_ENABLED) {
-			dev_err(dev, "current CP is not ENABLED\n");
-			return -EINVAL;
-		}
-		anx7625_hdcp_disable(ctx);
-		ctx->hdcp_cp = DRM_MODE_CONTENT_PROTECTION_UNDESIRED;
-		drm_hdcp_update_content_protection(ctx->connector,
-						   ctx->hdcp_cp);
-		dev_dbg(dev, "update CP to UNDESIRE\n");
-	}
-
-	if (cp == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
-		dev_err(dev, "Userspace illegal set to PROTECTION ENABLE\n");
-		return -EINVAL;
-	}
-
-	return 0;
-}
-
 static int anx7625_bridge_attach(struct drm_bridge *bridge,
 				 enum drm_bridge_attach_flags flags)
 {
@@ -2416,7 +2373,7 @@ static int anx7625_bridge_atomic_check(struct drm_bridge *bridge,
 	anx7625_bridge_mode_fixup(bridge, &crtc_state->mode,
 				  &crtc_state->adjusted_mode);
 
-	return anx7625_connector_atomic_check(ctx, conn_state);
+	return 0;
 }
 
 static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
@@ -2425,6 +2382,7 @@ static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
 	struct anx7625_data *ctx = bridge_to_anx7625(bridge);
 	struct device *dev = ctx->dev;
 	struct drm_connector *connector;
+	struct drm_connector_state *conn_state;
 
 	dev_dbg(dev, "drm atomic enable\n");
 
@@ -2439,6 +2397,22 @@ static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
 	_anx7625_hpd_polling(ctx, 5000 * 100);
 
 	anx7625_dp_start(ctx);
+
+	conn_state = drm_atomic_get_new_connector_state(state->base.state, connector);
+
+	if (WARN_ON(!conn_state))
+		return;
+
+	if (conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_DESIRED) {
+		if (ctx->dp_en) {
+			dev_dbg(dev, "enable HDCP\n");
+			anx7625_hdcp_enable(ctx);
+
+			queue_delayed_work(ctx->hdcp_workqueue,
+					   &ctx->hdcp_work,
+					   msecs_to_jiffies(2000));
+		}
+	}
 }
 
 static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
@@ -2449,6 +2423,17 @@ static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
 
 	dev_dbg(dev, "drm atomic disable\n");
 
+	flush_workqueue(ctx->hdcp_workqueue);
+
+	if (ctx->connector &&
+	    ctx->hdcp_cp == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
+		anx7625_hdcp_disable(ctx);
+		ctx->hdcp_cp = DRM_MODE_CONTENT_PROTECTION_DESIRED;
+		drm_hdcp_update_content_protection(ctx->connector,
+						   ctx->hdcp_cp);
+		dev_dbg(dev, "update CP to DESIRE\n");
+	}
+
 	ctx->connector = NULL;
 	anx7625_dp_stop(ctx);
 
Signature · 1 line
2.25.1
Tested-by on v4 1/1
#1 lore raw
Quoted 15 lines · Xin Ji

When user enabled HDCP feature, userspace will set HDCP content to DRM_MODE_CONTENT_PROTECTION_DESIRED. Next, anx7625 will update HDCP content to DRM_MODE_CONTENT_PROTECTION_ENABLED if down stream support HDCP feature.

As anx7625 bridge IC will be power down after call .atomic_disable(), then all HDCP status will be lost on chip. So we should reestablish HDCP again in .atomic_enable(), and update hdcp content to DESIRE if current HDCP content is ENABLE in .atomic_disable().

v4:
- Change HDCP content value to DESIRED if HDCP status is ENABLE in bridge
interface .atomic_enable().

Quoted 8 lines

v3:
- Move hdcp content value checking from bridge interface
.atomic_check() to .atomic_enable()

v2:
- Add more details in commit message

Quoted 119 lines
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 73 +++++++++--------------
 1 file changed, 29 insertions(+), 44 deletions(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +29 -45
index a2675b121fe4..1871262d5a97 100644
@@ -2137,49 +2137,6 @@ static void hdcp_check_work_func(struct work_struct *work)
        drm_modeset_unlock(&drm_dev->mode_config.connection_mutex);
 }
 
-static int anx7625_connector_atomic_check(struct anx7625_data *ctx,
-                                         struct drm_connector_state *state)
-{
-       struct device *dev = ctx->dev;
-       int cp;
-
-       dev_dbg(dev, "hdcp state check\n");
-       cp = state->content_protection;
-
-       if (cp == ctx->hdcp_cp)
-               return 0;
-
-       if (cp == DRM_MODE_CONTENT_PROTECTION_DESIRED) {
-               if (ctx->dp_en) {
-                       dev_dbg(dev, "enable HDCP\n");
-                       anx7625_hdcp_enable(ctx);
-
-                       queue_delayed_work(ctx->hdcp_workqueue,
-                                          &ctx->hdcp_work,
-                                          msecs_to_jiffies(2000));
-               }
-       }
-
-       if (cp == DRM_MODE_CONTENT_PROTECTION_UNDESIRED) {
-               if (ctx->hdcp_cp != DRM_MODE_CONTENT_PROTECTION_ENABLED) {
-                       dev_err(dev, "current CP is not ENABLED\n");
-                       return -EINVAL;
-               }
-               anx7625_hdcp_disable(ctx);
-               ctx->hdcp_cp = DRM_MODE_CONTENT_PROTECTION_UNDESIRED;
-               drm_hdcp_update_content_protection(ctx->connector,
-                                                  ctx->hdcp_cp);
-               dev_dbg(dev, "update CP to UNDESIRE\n");
-       }
-
-       if (cp == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
-               dev_err(dev, "Userspace illegal set to PROTECTION ENABLE\n");
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
 static int anx7625_bridge_attach(struct drm_bridge *bridge,
                                 enum drm_bridge_attach_flags flags)
 {
@@ -2416,7 +2373,7 @@ static int anx7625_bridge_atomic_check(struct drm_bridge *bridge,
        anx7625_bridge_mode_fixup(bridge, &crtc_state->mode,
                                  &crtc_state->adjusted_mode);
 
-       return anx7625_connector_atomic_check(ctx, conn_state);
+       return 0;
 }
 
 static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
@@ -2425,6 +2382,7 @@ static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
        struct anx7625_data *ctx = bridge_to_anx7625(bridge);
        struct device *dev = ctx->dev;
        struct drm_connector *connector;
+       struct drm_connector_state *conn_state;
 
        dev_dbg(dev, "drm atomic enable\n");
 
@@ -2439,6 +2397,22 @@ static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge,
        _anx7625_hpd_polling(ctx, 5000 * 100);
 
        anx7625_dp_start(ctx);
+
+       conn_state = drm_atomic_get_new_connector_state(state->base.state, connector);
+
+       if (WARN_ON(!conn_state))
+               return;
+
+       if (conn_state->content_protection == DRM_MODE_CONTENT_PROTECTION_DESIRED) {
+               if (ctx->dp_en) {
+                       dev_dbg(dev, "enable HDCP\n");
+                       anx7625_hdcp_enable(ctx);
+
+                       queue_delayed_work(ctx->hdcp_workqueue,
+                                          &ctx->hdcp_work,
+                                          msecs_to_jiffies(2000));
+               }
+       }
 }
 
 static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
@@ -2449,6 +2423,17 @@ static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
 
        dev_dbg(dev, "drm atomic disable\n");
 
+       flush_workqueue(ctx->hdcp_workqueue);
+
+       if (ctx->connector &&
+           ctx->hdcp_cp == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
+               anx7625_hdcp_disable(ctx);
+               ctx->hdcp_cp = DRM_MODE_CONTENT_PROTECTION_DESIRED;
+               drm_hdcp_update_content_protection(ctx->connector,
+                                                  ctx->hdcp_cp);
+               dev_dbg(dev, "update CP to DESIRE\n");
+       }
+
        ctx->connector = NULL;
        anx7625_dp_stop(ctx);
 
--

2.25.1

Reviewed-by on v4 1/1
#2 lore raw
In reply to Xin Ji
Quoted 18 lines · Xin Ji

When user enabled HDCP feature, userspace will set HDCP content to DRM_MODE_CONTENT_PROTECTION_DESIRED. Next, anx7625 will update HDCP content to DRM_MODE_CONTENT_PROTECTION_ENABLED if down stream support HDCP feature.

As anx7625 bridge IC will be power down after call .atomic_disable(), then all HDCP status will be lost on chip. So we should reestablish HDCP again in .atomic_enable(), and update hdcp content to DESIRE if current HDCP content is ENABLE in .atomic_disable().

v4:
- Change HDCP content value to DESIRED if HDCP status is ENABLE in bridge
interface .atomic_enable().

v3:
- Move hdcp content value checking from bridge interface
.atomic_check() to .atomic_enable()

Quoted 7 lines

v2:
- Add more details in commit message

---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 73 +++++++++--------------
 1 file changed, 29 insertions(+), 44 deletions(-)

Thank you for going through the reviews and explaining the issue!

Signature · 2 lines
With best wishes
Dmitry
maintainer Applied
#3 lore raw
In reply to Xin Ji

Hi,

Quoted 11 lines · Xin Ji

When user enabled HDCP feature, userspace will set HDCP content to DRM_MODE_CONTENT_PROTECTION_DESIRED. Next, anx7625 will update HDCP content to DRM_MODE_CONTENT_PROTECTION_ENABLED if down stream support HDCP feature.

As anx7625 bridge IC will be power down after call .atomic_disable(), then all HDCP status will be lost on chip. So we should reestablish HDCP again in .atomic_enable(), and update hdcp content to DESIRE if current HDCP content is ENABLE in .atomic_disable().

[...]

Thanks, Applied to https://gitlab.freedesktop.org/drm/misc/kernel.git (drm-misc-next)

[1/1] drm/bridge:anx7625: Update HDCP content status

      https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/a253b0b1292b4db0fec5733acceffc87bad4ffaf
Signature · 1 line
Neil