diff mbox series

[v3] drm/bridge:anx7625: Update HDCP status at atomic_enable()

Message ID 20241212055110.1862487-1-xji@analogixsemi.com (mailing list archive)
State New
Headers show
Series [v3] drm/bridge:anx7625: Update HDCP status at atomic_enable() | expand

Commit Message

Xin Ji Dec. 12, 2024, 5:51 a.m. UTC
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.

However once HDCP content turn to DRM_MODE_CONTENT_PROTECTION_ENABLED
userspace will not update the HDCP content to
DRM_MODE_CONTENT_PROTECTION_UNDESIRED until monitor disconnect.

So, anx7625 driver move hdcp content value checking from bridge
interface .atomic_check() to .atomic_enable(), then update hdcp content
according from currently HDCP status. And also disabled HDCP in bridge
interface .atomic_disable().

Signed-off-by: Xin Ji <xji@analogixsemi.com>
---
 drivers/gpu/drm/bridge/analogix/anx7625.c | 74 ++++++++++++++---------
 1 file changed, 46 insertions(+), 28 deletions(-)

Comments

Chen-Yu Tsai Dec. 12, 2024, 7:29 a.m. UTC | #1
On Thu, Dec 12, 2024 at 1:51 PM Xin Ji <xji@analogixsemi.com> wrote:
>
> 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.
>
> However once HDCP content turn to DRM_MODE_CONTENT_PROTECTION_ENABLED
> userspace will not update the HDCP content to
> DRM_MODE_CONTENT_PROTECTION_UNDESIRED until monitor disconnect.
>
> So, anx7625 driver move hdcp content value checking from bridge
> interface .atomic_check() to .atomic_enable(), then update hdcp content
> according from currently HDCP status. And also disabled HDCP in bridge
> interface .atomic_disable().
>
> Signed-off-by: Xin Ji <xji@analogixsemi.com>
> ---

No need to resend, but please provide a changelog under the "---" line
so reviewers know what you changed in this new version.

>  drivers/gpu/drm/bridge/analogix/anx7625.c | 74 ++++++++++++++---------
>  1 file changed, 46 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index a2675b121fe4..f96ce5665e8d 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -861,6 +861,22 @@ static int anx7625_hdcp_disable(struct anx7625_data *ctx)
>                                  TX_HDCP_CTRL0, ~HARD_AUTH_EN & 0xFF);
>  }
>
> +static void anx7625_hdcp_disable_and_update_cp(struct anx7625_data *ctx)
> +{
> +       struct device *dev = ctx->dev;
> +
> +       if (!ctx->connector)
> +               return;
> +
> +       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");
> +}
> +
>  static int anx7625_hdcp_enable(struct anx7625_data *ctx)
>  {
>         u8 bcap;
> @@ -2149,34 +2165,6 @@ static int anx7625_connector_atomic_check(struct anx7625_data *ctx,
>         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;
>  }
>
> @@ -2425,6 +2413,8 @@ 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;
> +       int cp;
>
>         dev_dbg(dev, "drm atomic enable\n");
>
> @@ -2439,6 +2429,32 @@ 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;
> +
> +       cp = conn_state->content_protection;
> +       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;
> +               }
> +
> +               anx7625_hdcp_disable_and_update_cp(ctx);
> +       }
>  }
>
>  static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
> @@ -2449,6 +2465,8 @@ static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
>
>         dev_dbg(dev, "drm atomic disable\n");
>
> +       anx7625_hdcp_disable_and_update_cp(ctx);
> +
>         ctx->connector = NULL;
>         anx7625_dp_stop(ctx);
>
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
index a2675b121fe4..f96ce5665e8d 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -861,6 +861,22 @@  static int anx7625_hdcp_disable(struct anx7625_data *ctx)
 				 TX_HDCP_CTRL0, ~HARD_AUTH_EN & 0xFF);
 }
 
+static void anx7625_hdcp_disable_and_update_cp(struct anx7625_data *ctx)
+{
+	struct device *dev = ctx->dev;
+
+	if (!ctx->connector)
+		return;
+
+	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");
+}
+
 static int anx7625_hdcp_enable(struct anx7625_data *ctx)
 {
 	u8 bcap;
@@ -2149,34 +2165,6 @@  static int anx7625_connector_atomic_check(struct anx7625_data *ctx,
 	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;
 }
 
@@ -2425,6 +2413,8 @@  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;
+	int cp;
 
 	dev_dbg(dev, "drm atomic enable\n");
 
@@ -2439,6 +2429,32 @@  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;
+
+	cp = conn_state->content_protection;
+	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;
+		}
+
+		anx7625_hdcp_disable_and_update_cp(ctx);
+	}
 }
 
 static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
@@ -2449,6 +2465,8 @@  static void anx7625_bridge_atomic_disable(struct drm_bridge *bridge,
 
 	dev_dbg(dev, "drm atomic disable\n");
 
+	anx7625_hdcp_disable_and_update_cp(ctx);
+
 	ctx->connector = NULL;
 	anx7625_dp_stop(ctx);