drm/bridge: it6505: fix HDCP CTS KSV list wait timer
authorHermes Wu <hermes.wu@ite.com.tw>
Mon, 30 Dec 2024 10:51:27 +0000 (18:51 +0800)
committerDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Fri, 3 Jan 2025 18:24:32 +0000 (20:24 +0200)
HDCP must disabled encryption and restart authentication after
waiting KSV for 5s.
The original method uses a counter in a waitting loop that may
wait much longer than it is supposed to.
Use time_after() for KSV wait timeout.

Signed-off-by: Hermes Wu <hermes.wu@ite.com.tw>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20241230-v7-upstream-v7-9-e0fdd4844703@ite.corp-partner.google.com
drivers/gpu/drm/bridge/ite-it6505.c

index e6badb2540f310f7209f84829b8ddbc2d053643c..264779f14366d64975f9e69f2960b5dbf1e5a52a 100644 (file)
@@ -2096,12 +2096,13 @@ static void it6505_hdcp_wait_ksv_list(struct work_struct *work)
        struct it6505 *it6505 = container_of(work, struct it6505,
                                             hdcp_wait_ksv_list);
        struct device *dev = it6505->dev;
-       unsigned int timeout = 5000;
-       u8 bstatus = 0;
+       u8 bstatus;
        bool ksv_list_check;
+       /* 1B-04 wait ksv list for 5s */
+       unsigned long timeout = jiffies +
+                               msecs_to_jiffies(5000) + 1;
 
-       timeout /= 20;
-       while (timeout > 0) {
+       for (;;) {
                if (!it6505_get_sink_hpd_status(it6505))
                        return;
 
@@ -2110,13 +2111,12 @@ static void it6505_hdcp_wait_ksv_list(struct work_struct *work)
                if (bstatus & DP_BSTATUS_READY)
                        break;
 
-               msleep(20);
-               timeout--;
-       }
+               if (time_after(jiffies, timeout)) {
+                       DRM_DEV_DEBUG_DRIVER(dev, "KSV list wait timeout");
+                       goto timeout;
+               }
 
-       if (timeout == 0) {
-               DRM_DEV_DEBUG_DRIVER(dev, "timeout and ksv list wait failed");
-               goto timeout;
+               msleep(20);
        }
 
        ksv_list_check = it6505_hdcp_part2_ksvlist_check(it6505);