Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp738702rwr; Thu, 27 Apr 2023 07:35:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7DXJV2fMK/JEvC77p7W4EDl9Oumi08MkrTlHL2Lz2YURoZwaCqG2u+77Lw2FDxkjc7K97a X-Received: by 2002:a05:6a00:4c11:b0:641:23df:e929 with SMTP id ea17-20020a056a004c1100b0064123dfe929mr830082pfb.2.1682606128251; Thu, 27 Apr 2023 07:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682606128; cv=none; d=google.com; s=arc-20160816; b=PmS4tutPDdWdamPaZjq3OdlWHPtz/cAF4XiBwpPN3rsTPQa1cpQOvsOOmO3w6beU7S 92Rvkj9uhRaZBm6rfua+tgP/yfamNnIJoeMLuGT3qkGmlqVFmBL7UGGTnEWJrYcnr7ue ABwTMbCXt0nSv2V64nBLu0ZEi7Cp1z1E+Z0R/MmAcO8Zue1+3HbbBdmL5wQmb4orj9r1 TOo0WVddSGV409x+qg5SNXkUPq7/yuShM1vD8xKUOSuomMpkfs1IPSDPt+GL8owNnec5 mKfj+GpvQ55e8G4sQ7UiXhLcEldVi16lEAH+2gw3AgIqlaPFxmztNVyPcAwADUidL/NH GZ/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tLHkemfDZBn/4H9YVuCFBMZjMeFBV1Xv/e5XpsNZBVg=; b=UnfIMd5AkylwUPO6Ed+ZCiEulp4OZfSvdsf1FK8Sg5oLSsQJ6lpYhovU4UZQpgEZiN ABQRFqMuTBWfpn8GuiHuDrCvAy1CFlrYPWLUbnAtS7xR6NhIuKhwBARfy6T8vGsExOSd kWLXzDBB62LUMb52iudBuhf5AI3PBGIk5LcBAbS6zcN4iPgkh11IqwaRwN3PuAbBVS1Y FHKNxNa5Ngg2M/Ps2H+4hRFpYYAbLh+kafABzQyWTVIlfMl6grQmi6wNe108AR7Y4kHi QZPjIN27drPk98AKEjFinnaYS53nkEQwQHlJ10l1g9fX+gy+SJAEb5n0Ef96fWwgJGS7 FJoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 204-20020a6300d5000000b00520ad015da5si19198492pga.462.2023.04.27.07.35.14; Thu, 27 Apr 2023 07:35:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244182AbjD0Oay (ORCPT + 99 others); Thu, 27 Apr 2023 10:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244110AbjD0OaZ (ORCPT ); Thu, 27 Apr 2023 10:30:25 -0400 Received: from mail11.truemail.it (mail11.truemail.it [217.194.8.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E933E4497 for ; Thu, 27 Apr 2023 07:30:19 -0700 (PDT) Received: from francesco-nb.pivistrello.it (93-49-2-63.ip317.fastwebnet.it [93.49.2.63]) by mail11.truemail.it (Postfix) with ESMTPA id C13F420B58; Thu, 27 Apr 2023 16:29:41 +0200 (CEST) From: Francesco Dolcini To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , tomi.valkeinen@ideasonboard.com, dri-devel@lists.freedesktop.org Cc: Francesco Dolcini , David Airlie , Daniel Vetter , linux-kernel@vger.kernel.org Subject: [PATCH v1 5/9] drm/bridge: tc358768: fix TCLK_TRAILCNT computation Date: Thu, 27 Apr 2023 16:29:30 +0200 Message-Id: <20230427142934.55435-6-francesco@dolcini.it> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230427142934.55435-1-francesco@dolcini.it> References: <20230427142934.55435-1-francesco@dolcini.it> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Francesco Dolcini Correct computation of TCLK_TRAILCNT register. The driver does not implement non-continuous clock mode, so the actual value doesn't make a practical difference yet. However this change also ensures that the value does not write to reserved registers bits in case of under/overflow. This register must be set to a value that ensures that TCLK-TRAIL > 60ns and TEOT <= (105 ns + 12 x UI) with the actual value of TCLK-TRAIL being (TCLK_TRAILCNT + (1 to 2)) xHSByteClkCycle + (2 + (1 to 2)) * HSBYTECLKCycle - (PHY output delay) with PHY output delay being about (2 to 3) x MIPIBitClk cycle in the BitClk conversion. Fixes: ff1ca6397b1d ("drm/bridge: Add tc358768 driver") Signed-off-by: Francesco Dolcini --- drivers/gpu/drm/bridge/tc358768.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index aff400c36066..360c7c65f8c4 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -638,6 +639,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) struct mipi_dsi_device *dsi_dev = priv->output.dev; unsigned long mode_flags = dsi_dev->mode_flags; u32 val, val2, lptxcnt, hact, data_type; + s32 raw_val; const struct drm_display_mode *mode; u32 dsibclk_nsk, dsiclk_nsk, ui_nsk, phy_delay_nsk; u32 dsiclk, dsibclk, video_start; @@ -749,9 +751,9 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) dev_dbg(priv->dev, "TCLK_HEADERCNT: 0x%x\n", val); tc358768_write(priv, TC358768_TCLK_HEADERCNT, val); - /* TCLK_TRAIL > 60ns + 3*UI */ - val = 60 + tc358768_to_ns(3 * ui_nsk); - val = tc358768_ns_to_cnt(val, dsibclk_nsk) - 5; + /* TCLK_TRAIL > 60ns AND TEOT <= 105 ns + 12*UI */ + raw_val = tc358768_ns_to_cnt(60 + tc358768_to_ns(2 * ui_nsk), dsibclk_nsk) - 5; + val = clamp(raw_val, 0, 127); dev_dbg(priv->dev, "TCLK_TRAILCNT: 0x%x\n", val); tc358768_write(priv, TC358768_TCLK_TRAILCNT, val); -- 2.25.1