From patchwork Fri Aug 4 10:44:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp203564vqb; Fri, 4 Aug 2023 04:51:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGJuMqOobzsN73urbnTnU1sIZc7SvSmV7LcjU48uLsD9Rubdm9mtCpthkMJafmrQdM6D8uT X-Received: by 2002:a17:906:8a51:b0:99b:d075:18ba with SMTP id gx17-20020a1709068a5100b0099bd07518bamr1151639ejc.56.1691149870129; Fri, 04 Aug 2023 04:51:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691149870; cv=none; d=google.com; s=arc-20160816; b=umyMhKU3q78cl1BkvOdSpHbfkmamaz+e6eom9tTRVp0nHS3/KLcT27COHYqhVQVjIo PeFjlx5+LYqr0mwIVQhE0stcscXYIhNU4xp7qp+Z6mfYmkyUePPpue8okWKD8H4a6MAf P7NCRxJ9Id6Fa+uFqTlm+JvJ2pFOfW8gmvCBBD/cPMzgs97r0xS9fHFeCUE2dExPSOq1 aVgcoPVYvAqa8tBYocXG6MlVhJVr3mjZ9trcnIEIAQB/FOg8rA9QcEt4tvrcAF+iUCPi S0jwbcaTZydOeSZBFcVXIXEazjU4HcwBV9j7AP54QPAVtLs/a3KVbsjC92fbWp0gnzG+ iHKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=g3lT3rHInnuiE2J1EkX8+K3Na3EpFrT8uIMc3sBdEro=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=NIXO5znKH5XQ0yp8DLcTzvHMHhImhv42FZR376gDfalkJg7qv5iP4idi1lKXq6iiWR xGE4GjPeISA7kOaeg/Gp5exzs2Bd1wGsc2k9KdsdZPnSd0Z99WhscqMU31B8umKxmNUO uBWMaN8ssebqJsdzawu2tQF0DjZin0Qqok1/oYgN7iw2SMBTMwvDNDlcqRj3fXrRTwPp PJNas8ZAed4ZBQEDK947AEC0uSFrc5aggl8RZTWmqFd0dz4rNYpSJ06y9jtHCOOOKw3W ms9xXvtGUVpJWfM58NWBRuUlFHO7xX2V5cWEcUgqjZZHnZYYTn8zZdd7O+BSzwKnWinN qvQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=FT+PbaJN; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d9-20020a170906174900b00993b3881eccsi1564771eje.691.2023.08.04.04.50.42; Fri, 04 Aug 2023 04:51:10 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=FT+PbaJN; 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 S229455AbjHDKop (ORCPT + 99 others); Fri, 4 Aug 2023 06:44:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjHDKom (ORCPT ); Fri, 4 Aug 2023 06:44:42 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A9E46BD for ; Fri, 4 Aug 2023 03:44:41 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AA6BE12E4; Fri, 4 Aug 2023 12:43:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145814; bh=3BEyrzp4IUiLGe9w3xtacn7Yy6nvFBbT4HOk9yd56NA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FT+PbaJNlTpwZPIvNYkMtzEJmWRm4vJP236yMj3QUZ5O2XhBrzD1necB+dYoKY6wV GgcPIDSfVxczEKuGBNYKzjwoYx8NSdRYMdoWx9rrk5HHSEU41ytiL7PEcZ4gjeA4HR EmW3pd7FO9GnC2C/2q8CEM8l33wgvTTldB005cG0= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:06 +0300 Subject: [PATCH 01/11] drm/bridge: tc358768: Fix use of uninitialized variable MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-1-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=909; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=3BEyrzp4IUiLGe9w3xtacn7Yy6nvFBbT4HOk9yd56NA=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaRGYqdx9CLtWjNaw71yuxZ7twAVPL/kKywz 73jg/nITEyJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkQAKCRD6PaqMvJYe 9R/ED/0e1faduwhJY8SxU8fljAbFFDWdEBvarjI1D4D/CRcIKgRU7Mc2sn7RFbrHSOJrYeCYJWS h1pGjDdPvKmhw4njBLZefSGXAaSJTo8oI9ZOEwkbTuEcuFZaLaGwtCOJQGSlLMt0NJgv5LcKi3v u8QJOwmEkzwiANoErF84woZj5cIH22ZuCT/ZIt8KsaAfHR8N8DFNrslZkTFPEMnL3PWVS4NKlxI rTDp/nqU0G9GQUywOp2dQA7IupqBJJZXFh9anZ/yJNhKy58SuMb04Yo5JQjhZqTkMhrB4NTXctu 42hGy57/TkRT0dsm0h5XiK4/s+ldCDn0wjy+hWsbVe1R4NAmfJWdwVIMlrjVQuASMAOfitCwSsA Z4NOWBQjx5Vzo9oJuTos5mabMOGW9Ji6CpycTPPTfnTkLEu8bNlIFC09yOB7PSb0inUNAMaB2W3 BSntU0hS4MgAHptNXQFy5p+BGYUUnZ6P5Da2ByeWbH6/WOj2XgwWGPmchNY+RDoamePLay70lzU xvcdg94Te/QIi2sJTT2dyMoopwJfmQRBE6jTY+nAhw9XgU7LoId9YRffFHwUhPVguLSNGHKhoHX ouVb8j94cHFEMytHccOLohg70pvFxrgNIvcJd1BbMP1X8S2vzcUcC/6FjRoD+yfIP97Uvj0ZXN5 hOnOfe5OhhqfXMA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773299166297190928 X-GMAIL-MSGID: 1773299166297190928 smatch reports: drivers/gpu/drm/bridge/tc358768.c:223 tc358768_update_bits() error: uninitialized symbol 'orig'. Fix this by bailing out from tc358768_update_bits() if the tc358768_read() produces an error. Fixes: ff1ca6397b1d ("drm/bridge: Add tc358768 driver") Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/bridge/tc358768.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index 819a4b6ec2a0..bc97a837955b 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -216,6 +216,10 @@ static void tc358768_update_bits(struct tc358768_priv *priv, u32 reg, u32 mask, u32 tmp, orig; tc358768_read(priv, reg, &orig); + + if (priv->error) + return; + tmp = orig & ~mask; tmp |= val & mask; if (tmp != orig) From patchwork Fri Aug 4 10:44:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131114 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp195116vqb; Fri, 4 Aug 2023 04:33:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFl98ofo1yNTtwxvPx4HgoLgpiDLEHluCNSPPQx8Vg2NzwplK6CJPP3wPArq1bUGXEC8fPW X-Received: by 2002:aa7:cd98:0:b0:522:29b7:a95f with SMTP id x24-20020aa7cd98000000b0052229b7a95fmr1358877edv.30.1691148794436; Fri, 04 Aug 2023 04:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691148794; cv=none; d=google.com; s=arc-20160816; b=ljs116JTMJCkGosIjCXSWORMdc08PDX9+gCcz6vugQhMU5FyXNk42K2ExcTlrnAP40 o654+2shuhLiFyhNBYBJEsZgzf8nQtaJ3RMZbpDnuqblg+jjDmZ6liFIEUWYN/vEdMv7 21Rz5aj0xxeaB4pv+ZWYhEpN4SWNuIjIKbKb6Y9X+MD75zEXlUoP7GVfTgibAXWGjFBR AGKfL/AKQttV2DiadlCABrgeQtyVzr1tVZYUyQl3uQ+X4iCgdac1DaJqJLnVHTi0jx1c D/dG3PLc5aYpi+P9G4RRIDUCsvTAIdqiEhZZ7+uilb+oRXNI7Yq3UOMW2LcvViiCc/6Z w10g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=z1QlFJoC1ctkLIGKMQu7Ef6z3FYZ2GksOm/qxtJ4hqI=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=cFbLaRySqqnmY8514R9c4PQ3dflUfreLdK4gTD1MEyyS6Zws3piakvt75WlpkHI+Fa OgF0o5dtDbyrhQlGKWao314oEzhEyi/Nwcmo8xjWbyLyJbO8ffBA6lflFQtpr0OGR++f oMOR9tJ4FFQEkxnCmK+NNIbC57ZOWZdbX842AOW/C7UTe4WLqYLu1h0z39Dl0N0B22u0 MFisOXrBVj0KatDr12CvcNPS0kDXfM9LxrE1BITLc/MdriWkjWUKRCFicRY6WeJhOihD 4i/83cFj5H5L8n4MS50Zr/eAO6Ik8po3dAtnjggb6xSWxa+eLBUFE+G8K0yjr5vZRY2P lhHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ogHmPUfZ; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a50fa8e000000b0052288239e89si1492585edr.231.2023.08.04.04.32.51; Fri, 04 Aug 2023 04:33:14 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ogHmPUfZ; 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 S231530AbjHDKot (ORCPT + 99 others); Fri, 4 Aug 2023 06:44:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231509AbjHDKoo (ORCPT ); Fri, 4 Aug 2023 06:44:44 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B1C46B5 for ; Fri, 4 Aug 2023 03:44:43 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B21ED188E; Fri, 4 Aug 2023 12:43:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145815; bh=rtp9mGXPYI+O3f2aQFTiJmta7zUghg7DuTpPSnMYVrU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ogHmPUfZs6vovAKVCrGMNPw6M8LeS3Z0RaiFNbFy2ICeJueV++UWVIJREG2oaD5Nc 5iRKFrToeFG0nM7TVHvkv0O1j8wga9YGP+2RqEQjwKPgfhvaWzKS+KlC0GWFQUQBFO I5qbvgZ0z97r+Dc29xy+53K6Rrb21foDNyMixXQM= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:07 +0300 Subject: [PATCH 02/11] drm/bridge: tc358768: Fix bit updates MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-2-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1966; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=rtp9mGXPYI+O3f2aQFTiJmta7zUghg7DuTpPSnMYVrU=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaRHlppAaUlp8wmp8JUbwlcKbfRJpNDPjydH YYi+Al1AKWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkQAKCRD6PaqMvJYe 9R8aD/91CxuRAWCF7MErsxmijuy+KAwtPMqSW0zBy2N6+cCaXwDex4qa57bXDMHnlvmo3h2kLYw VkoEqMtdAVe123Cxi7jJXLBTvV/4FmQNdl+oGMumHwf/HpXPo8htpApWiFrf8m+fybRVXQZ5lAo fOtFiuF319tJONUj5P4t3Y9/k3zsJPoXEgC8HdGt5xXf+HPTDUgQHU/0PDPQSP6y8wE0KmOQOdT UZ5NHK5MSFnchZZgqgZM6XP9Sq54GShRmgjf+iDajV85zHO77y2rvB0QGAXXaEYWM3nyHvvPv77 ptl/yPC/YwktitF95mwf9UALiB+VBA8YKok/qap9k0bIwclno/8JYwBsK2bfTKhN6q3ZhuZUyKW MGzFAQtnWb+agPRefMO1eiBJ4mMRY7Jp6NFLyWvRDxIY/fb356yzIBaX8g6JwjbQuarWrL/Xwxy INQPQ70R9YZRCyaKsEtoEXvb+zJ4BBuOwrXYEEkeyCxPYk/RKSzyee5LccSWhyqCf1BAWFaw134 PqBHf/bU8/SEy5jDNhyLGN1+xsPba4DP262HhsVhDJ67RwsVjk1Fbybtf/H1loICZ6e/Ow2PjR0 xxcjAwC97H936jk0jI9AThKf1Cbs7EmFnpo6yQl+RSdmCi6SCe4fRjZVwWxdkkfTJ2DenXxfpso xJMzgO12Zbn5/bA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773298038380551870 X-GMAIL-MSGID: 1773298038380551870 The driver has a few places where it does: if (thing_is_enabled_in_config) update_thing_bit_in_hw() This means that if the thing is _not_ enabled, the bit never gets cleared. This affects the h/vsyncs and continuous DSI clock bits. Fix the driver to always update the bit. Fixes: ff1ca6397b1d ("drm/bridge: Add tc358768 driver") Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/bridge/tc358768.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index bc97a837955b..b668f77673c3 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -794,8 +794,8 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) val |= BIT(i + 1); tc358768_write(priv, TC358768_HSTXVREGEN, val); - if (!(mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)) - tc358768_write(priv, TC358768_TXOPTIONCNTRL, 0x1); + tc358768_write(priv, TC358768_TXOPTIONCNTRL, + (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) ? 0 : BIT(0)); /* TXTAGOCNT[26:16] RXTASURECNT[10:0] */ val = tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk * 4); @@ -861,11 +861,12 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) tc358768_write(priv, TC358768_DSI_HACT, hact); /* VSYNC polarity */ - if (!(mode->flags & DRM_MODE_FLAG_NVSYNC)) - tc358768_update_bits(priv, TC358768_CONFCTL, BIT(5), BIT(5)); + tc358768_update_bits(priv, TC358768_CONFCTL, BIT(5), + (mode->flags & DRM_MODE_FLAG_PVSYNC) ? BIT(5) : 0); + /* HSYNC polarity */ - if (mode->flags & DRM_MODE_FLAG_PHSYNC) - tc358768_update_bits(priv, TC358768_PP_MISC, BIT(0), BIT(0)); + tc358768_update_bits(priv, TC358768_PP_MISC, BIT(0), + (mode->flags & DRM_MODE_FLAG_PHSYNC) ? BIT(0) : 0); /* Start DSI Tx */ tc358768_write(priv, TC358768_DSI_START, 0x1); From patchwork Fri Aug 4 10:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131153 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp237103vqb; Fri, 4 Aug 2023 05:49:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvJgNaursioxqP2KuB40wdYlgg0acnW/Ri4WB0HmN/iY+JAD3Q18TwebuPE22dt7oxLf9K X-Received: by 2002:a17:906:d6:b0:99c:2289:63bc with SMTP id 22-20020a17090600d600b0099c228963bcmr1379119eji.74.1691153361624; Fri, 04 Aug 2023 05:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691153361; cv=none; d=google.com; s=arc-20160816; b=cHrUcOIk1mwRf4VBKX49wdirHJd440uGqqeY2FBD7IBJx/HWnIzPEYQIouYwY3PoKK THKkQ1B1TmuZsJY8NtmS1xyGofrvk4gn1/O+VgMD5/uhtq1JqogSDNqpYRhmuw1vg1pn w8sYe5h1Sdd04H7G7+RDbp7YEKfkIKa55maMqFs0ilw+W9oRWRcPTu2G3sK+SVXQe34W icieGz9RkaFCOOwmaLHAAfI92iWL984fBYb9JADyWU/kEC4Llnel/IuUTP6QfpHKJShb 31JkhoF6ItR5V4sMuFF4da4QvXseOeaMmWFS2nfX+acRHLgCvQfTBfGMdxn6pwsaCcQ5 NG+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=F/FPJPd5UMEt74/rYsaX6wITTGvYGDEA3lkb1kv/LzM=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=G9HJhTTSlU2LpeBbsV0uFCrUVu/1zRou44qKV3W+Wy9eEqalbJjgv+j9u2qzhoya20 /r8ikhP6Z7I+oPpE5zI3lWHd8x6DB6EWlrokXpomBQ3zM/W46fWLfZIsTD01ehwEGPmU QuqSowsX9eC+DTqNrkvjQ43zIi3mghSGOqRK9CQ1Htv107Xn1M96+6Cb3pr+bu+PcKxc SIsex/qF7aqMES5DvEpnNEhoJEcyUOZ3g6ZGRUC7t9xfbv4FNAwzWCnGHloUdj3wQgvb Gwnd/tm+g0eu8EEv/dFpXlIuprLetu5pcFehdlbacy4M58fAG0geOlAQsU+BdMCXHHB6 E8Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZBKaogA8; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a1709060f4f00b009980c2658e0si1726212ejj.763.2023.08.04.05.48.47; Fri, 04 Aug 2023 05:49:21 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZBKaogA8; 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 S231544AbjHDKow (ORCPT + 99 others); Fri, 4 Aug 2023 06:44:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbjHDKoo (ORCPT ); Fri, 4 Aug 2023 06:44:44 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7E4246BD for ; Fri, 4 Aug 2023 03:44:43 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B52AB1AB3; Fri, 4 Aug 2023 12:43:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145816; bh=TUkJXEdGx2L3x9eOO5C14gMRZFfjPUo5XB/iG7hSXNo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ZBKaogA8fDtPzUHgLJ47o74td6AxNRtTuZ0YDFbVcXz2cO8MWPFItGTgP+VyoU7Is X4J7VUL5w15BSA33yIKC0wCZ8j1l4YbXOLg5p/Z40rHSvW27t2RfRwjzkDSIz66qaw WPuVYrpiJMXWFd4/nib02sVqMUF+nwr07AYpCFBc= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:08 +0300 Subject: [PATCH 03/11] drm/bridge: tc358768: Cleanup PLL calculations MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-3-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2487; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=TUkJXEdGx2L3x9eOO5C14gMRZFfjPUo5XB/iG7hSXNo=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaRbMCh94UFjagognh3oJEUiI6qNt+gM+fzG Yv/rFC3ImWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkQAKCRD6PaqMvJYe 9dNsD/0UNDVcvUORRAtGZiv2RIJjqZLr5U/45ualp74tfJ9OTV89JWa2IrNOMeHrsrJFISQ4LJs iAgOMgOAFINCQiCMeBPRJwCjaWBNr6Y3yWmUkIuHcGIpYpf2uq9QcgPHtI2fbGqrYRsNVK80Vn8 Qlb5BSltsktT4Y4TVlFFMnyNOSKQMd63cGKTY2oQgZKSkeD+MKC8AOJqUAqwEdD8SnmV7tdhifk oGrT3y4K+LlS88kACQyjmfqyn+plqzZ5O/Yd1a4/nD7kK3OKTgYDt0mE+fItq+c3uvbCvL6IiYm vxXmrSOqlPb4bFVYNlIjmchhY7TMq8rQabtnNv7ELvUNT+O2UGrMMY8eqlrF2CNqYZXc1Es2OJz AZ/YsJog7994aGwkE5kBGz2V02CXcnYTtISRgFClbKICbSENUaGMSNMO4XjvPWVlWVmMm5oS5N6 XCUzqIlciigPUo/msfredtN1E65XFdxwX0q6l99r48T+okcdI2Yf4CA2YgCpYevMxEoEN3rWXEt +J+PX/1D2OUhhuwutu8oQ9LGt2teasgouJtoMSkDmXtVrvY0Vim4VC4YPM1VScaQlwFEJBchczr pM2i2gJ045jjjyA8h1p/z4VPvSN29soY4lp96V64xoSDNYZKw/ogBTUidUpmInaJi81br24qAF5 +70lWAqiaoul+bw== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773302827171556484 X-GMAIL-MSGID: 1773302827171556484 As is quite common, some of TC358768's PLL register fields are to be programmed with (value - 1). Specifically, the FBD and PRD, multiplier and divider, are such fields. However, what the driver currently does is that it considers that the formula used for PLL rate calculation is: RefClk * [(FBD + 1)/ (PRD + 1)] * [1 / (2^FRS)] where FBD and PRD are values directly from the registers, while a more sensible way to look at it is: RefClk * FBD / PRD * (1 / (2^FRS)) and when the FBD and PRD values are written to the registers, they will be subtracted by one. Change the driver accordingly, as it simplifies the PLL code. Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index b668f77673c3..d5831a1236e9 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -316,7 +316,7 @@ static int tc358768_calc_pll(struct tc358768_priv *priv, target_pll = tc358768_pclk_to_pll(priv, mode->clock * 1000); - /* pll_clk = RefClk * [(FBD + 1)/ (PRD + 1)] * [1 / (2^FRS)] */ + /* pll_clk = RefClk * FBD / PRD * (1 / (2^FRS)) */ for (i = 0; i < ARRAY_SIZE(frs_limits); i++) if (target_pll >= frs_limits[i]) @@ -336,19 +336,19 @@ static int tc358768_calc_pll(struct tc358768_priv *priv, best_prd = 0; best_fbd = 0; - for (prd = 0; prd < 16; ++prd) { - u32 divisor = (prd + 1) * (1 << frs); + for (prd = 1; prd <= 16; ++prd) { + u32 divisor = prd * (1 << frs); u32 fbd; - for (fbd = 0; fbd < 512; ++fbd) { + for (fbd = 1; fbd <= 512; ++fbd) { u32 pll, diff, pll_in; - pll = (u32)div_u64((u64)refclk * (fbd + 1), divisor); + pll = (u32)div_u64((u64)refclk * fbd, divisor); if (pll >= max_pll || pll < min_pll) continue; - pll_in = (u32)div_u64((u64)refclk, prd + 1); + pll_in = (u32)div_u64((u64)refclk, prd); if (pll_in < 4000000) continue; @@ -611,7 +611,7 @@ static int tc358768_setup_pll(struct tc358768_priv *priv, mode->clock * 1000); /* PRD[15:12] FBD[8:0] */ - tc358768_write(priv, TC358768_PLLCTL0, (prd << 12) | fbd); + tc358768_write(priv, TC358768_PLLCTL0, ((prd - 1) << 12) | (fbd - 1)); /* FRS[11:10] LBWS[9:8] CKEN[4] RESETB[1] EN[0] */ tc358768_write(priv, TC358768_PLLCTL1, From patchwork Fri Aug 4 10:44:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp203706vqb; Fri, 4 Aug 2023 04:51:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGwPhiYFHC1FaipohzpqlFNbw6YLVBLgTnfKJaySKqewSJmNB3dPyKOP3uNVnQF0PwThMuK X-Received: by 2002:aa7:c707:0:b0:522:38f9:e653 with SMTP id i7-20020aa7c707000000b0052238f9e653mr1408350edq.30.1691149885934; Fri, 04 Aug 2023 04:51:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691149885; cv=none; d=google.com; s=arc-20160816; b=EDG9Qogg0IvVYr6WiZOiX+EVd9Imu774eaFTxSxUKhhsDWfqCNftBhHVXeJ/Pe8pRC yBVwfaGsNvGpFbeqU3pstBy/MqiFqIAAEPondbHqw+852Qp3wia3/KZGeOazcqy90CIX s91bjRXrg5ybXAHYqADX4txtGS13HjnSDxeRBp+klsBO8JhCJSM/aeY73tpxvCczmCS5 RHkFo1JyzByNwLKyMLFLVhoW0jKRcRVhxcN+O1jdB3VuKxrBYuYRvwiw0WyOUGVMi7j/ S/lQI2pgpouf7D/Le4FjqZIc6F+MbJfIFDoEZxN7ml/W/9mLhdP8TKV9AwrRfZ+EK4J+ u0cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ga1xoWtVPptjcKlrN9JW8m7d+GPeaevb80VCU6lv8wY=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=b7h6dcawl02x4k21TMGQTijQoA+GN0C62S3bPCk/7p+uOUHeAA5eXLSsXKdlgry9GB binrFL9G6EzmO8uRv2OQvJH+necykL/yYamb11JSNDMPwcirSItXmsi8Qif4TitWuyLH zWvFi7qSw4yet0Y+Uj+NamzXyGI4scjEs6kh0FsJofS/xF2VdHdwzcy6Ph8o1kjpTCbp gxJym29nEOpc3tXhSN42VVh4ijmvbRPy+Wpsk8NPZLZU8HS6RXLT0HIJSUFfEtQUIwKs 4yt6wUhrQbhcYnU+7Z8xegUzxOnlsXF2S5CTtgoU8qMMYpUgNvRK8CVqJ3GR3iZ4h+o9 fy0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=MK2AtVNh; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d14-20020aa7ce0e000000b005227a1274e8si1488183edv.662.2023.08.04.04.51.01; Fri, 04 Aug 2023 04:51:25 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=MK2AtVNh; 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 S231559AbjHDKo6 (ORCPT + 99 others); Fri, 4 Aug 2023 06:44:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231508AbjHDKor (ORCPT ); Fri, 4 Aug 2023 06:44:47 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C601649C1 for ; Fri, 4 Aug 2023 03:44:45 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BB74A1BAD; Fri, 4 Aug 2023 12:43:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145817; bh=WCGNIXcGcdl4nJn+dx6lcBvQUFqQ55HfWTEz54MJwVw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MK2AtVNhVEBgVjSDGNhmtoZ8KjiMA7AiCJPz9eFTXEgyi/l/jOP1Xr0NxtJt+0tG2 pAvOj33+r1KziwPiPQQCFQMuuJlEIgDrtRmf4kGlif2+edjN7lMNI8F2byBb5YOBpz ARyojtie+6BJmGYmYGX1nnJFb31zDaJJN00kqXNE= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:09 +0300 Subject: [PATCH 04/11] drm/bridge: tc358768: Use struct videomode MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-4-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4738; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=WCGNIXcGcdl4nJn+dx6lcBvQUFqQ55HfWTEz54MJwVw=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaSZtaCZTUTMK2vRUk8BC+9py3CA7QFWEyvh Y2y2pe7w6SJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkgAKCRD6PaqMvJYe 9XRpEACGSSmoQ7fJZ7Gv5yX/hogaE80D+3dt7+5wRL8c09/59O0sLcAYQTFnlL2l7ttC0MxNbqy 8WJISu1ptKdyhP3Q+fEVqRQL9O51QsUvAkcXqjaQvH2suLpAqvtU2k1HXlYtn8yCOjSb5phtJUZ mtqzns7g5Zl2ac0J2AMx5N9M4TmiH3V9uAE82vhsq2Xul1KH/7xG5/lGaBuqQ114s3mO+WhTrxT Ump8ZuZ80MymE21vsEyaOW5J4D7C9okUWx+5+lU+w2k5epzv0nvnCCeSAyN6Jg8/qfkqllJjmlP cdcQKqD866RWsjBSIW1zS6jr7zO72SaX1zuG1GlWL3fZguYP8yod/VyhJi4ZvsNv3/pnWBCwApw ADf3zxu8h4E4xGZOcEhI6Hbq3P7DtPaqbGIjFBnJsyITVKEI/Ei5CTjh4zCzNGsd+cAD554qWiH SdHoHnbu6wSC1Vji9nQEj7wT/ZOzUPLaw7Vi2FB5prx49Me/pzGKjgdLIFsQM+kkC/ftW4JqDRj wiAcdNOgMqlplu5Wgyg3qM9C/WfqBo4WAEeqaGwDyzY094X0i0idqNVmTb5ol9lXCZJyw9z4OPd 4J70tJdjBFzhce+Xnv7U6AyLorhfekJdG6KbQcYFTSEJfx9JS7R8/DZImww12wITt6UZl/lzHDV CFp04MYkSYpJuRA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773299182441074814 X-GMAIL-MSGID: 1773299182441074814 The TC358768 documentation uses HFP, HBP, etc. values to deal with the video mode, while the driver currently uses the DRM display mode (htotal, hsync_start, etc). Change the driver to convert the DRM display mode to struct videomode, which then allows us to use the same units the documentation uses. This makes it much easier to work on the code when using the TC358768 documentation as a reference. Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 45 +++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index d5831a1236e9..9b633038af33 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -650,6 +650,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) u32 dsiclk, dsibclk, video_start; const u32 internal_delay = 40; int ret, i; + struct videomode vm; if (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) { dev_warn_once(priv->dev, "Non-continuous mode unimplemented, falling back to continuous\n"); @@ -673,6 +674,8 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) return; } + drm_display_mode_to_videomode(mode, &vm); + dsiclk = priv->dsiclk; dsibclk = dsiclk / 4; @@ -681,28 +684,28 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) switch (dsi_dev->format) { case MIPI_DSI_FMT_RGB888: val |= (0x3 << 4); - hact = mode->hdisplay * 3; - video_start = (mode->htotal - mode->hsync_start) * 3; + hact = vm.hactive * 3; + video_start = (vm.hsync_len + vm.hback_porch) * 3; data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24; break; case MIPI_DSI_FMT_RGB666: val |= (0x4 << 4); - hact = mode->hdisplay * 3; - video_start = (mode->htotal - mode->hsync_start) * 3; + hact = vm.hactive * 3; + video_start = (vm.hsync_len + vm.hback_porch) * 3; data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18; break; case MIPI_DSI_FMT_RGB666_PACKED: val |= (0x4 << 4) | BIT(3); - hact = mode->hdisplay * 18 / 8; - video_start = (mode->htotal - mode->hsync_start) * 18 / 8; + hact = vm.hactive * 18 / 8; + video_start = (vm.hsync_len + vm.hback_porch) * 18 / 8; data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18; break; case MIPI_DSI_FMT_RGB565: val |= (0x5 << 4); - hact = mode->hdisplay * 2; - video_start = (mode->htotal - mode->hsync_start) * 2; + hact = vm.hactive * 2; + video_start = (vm.hsync_len + vm.hback_porch) * 2; data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16; break; default: @@ -814,43 +817,43 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) tc358768_write(priv, TC358768_DSI_EVENT, 0); /* vact */ - tc358768_write(priv, TC358768_DSI_VACT, mode->vdisplay); + tc358768_write(priv, TC358768_DSI_VACT, vm.vactive); /* vsw */ - tc358768_write(priv, TC358768_DSI_VSW, - mode->vsync_end - mode->vsync_start); + tc358768_write(priv, TC358768_DSI_VSW, vm.vsync_len); + /* vbp */ - tc358768_write(priv, TC358768_DSI_VBPR, - mode->vtotal - mode->vsync_end); + tc358768_write(priv, TC358768_DSI_VBPR, vm.vback_porch); /* hsw * byteclk * ndl / pclk */ - val = (u32)div_u64((mode->hsync_end - mode->hsync_start) * + val = (u32)div_u64(vm.hsync_len * ((u64)priv->dsiclk / 4) * priv->dsi_lanes, - mode->clock * 1000); + vm.pixelclock); tc358768_write(priv, TC358768_DSI_HSW, val); /* hbp * byteclk * ndl / pclk */ - val = (u32)div_u64((mode->htotal - mode->hsync_end) * + val = (u32)div_u64(vm.hback_porch * ((u64)priv->dsiclk / 4) * priv->dsi_lanes, - mode->clock * 1000); + vm.pixelclock); tc358768_write(priv, TC358768_DSI_HBPR, val); } else { /* Set event mode */ tc358768_write(priv, TC358768_DSI_EVENT, 1); /* vact */ - tc358768_write(priv, TC358768_DSI_VACT, mode->vdisplay); + tc358768_write(priv, TC358768_DSI_VACT, vm.vactive); /* vsw (+ vbp) */ tc358768_write(priv, TC358768_DSI_VSW, - mode->vtotal - mode->vsync_start); + vm.vsync_len + vm.vback_porch); + /* vbp (not used in event mode) */ tc358768_write(priv, TC358768_DSI_VBPR, 0); /* (hsw + hbp) * byteclk * ndl / pclk */ - val = (u32)div_u64((mode->htotal - mode->hsync_start) * + val = (u32)div_u64((vm.hsync_len + vm.hback_porch) * ((u64)priv->dsiclk / 4) * priv->dsi_lanes, - mode->clock * 1000); + vm.pixelclock); tc358768_write(priv, TC358768_DSI_HSW, val); /* hbp (not used in event mode) */ From patchwork Fri Aug 4 10:44:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131120 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp203146vqb; Fri, 4 Aug 2023 04:50:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKQ4osqF+gyaIf9QHMwi3VDtZ2SgUBqwa9nCZwqUJndokv41YU9dsi8QdRFE2bWccDwFv4 X-Received: by 2002:a50:fc18:0:b0:50b:c630:a956 with SMTP id i24-20020a50fc18000000b0050bc630a956mr1261118edr.17.1691149814404; Fri, 04 Aug 2023 04:50:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691149814; cv=none; d=google.com; s=arc-20160816; b=PoHZ/mwKYMOaawB2yQPmtGIATMIVerp8zhM0a203NG4N6MQii9cvK0KNDbM/xRxP7t qspfc3EessJ1kkpD4Ta5yFUP+c44uPhNV8rE49XkDKpTtt7Vzh9nJ3CNMUKJVonFUyUX Sy/taJhZuhEBLRWY7Yzs9Nq9xrJQUQ/XPsxmRSQPE6wbr2uy8bu112XvsFQsVOb6M2de GzwPjrDCQZ+geU/JkXAHBvZ2k/agCeJRxZKaikwUC5wpTYFOPrHUWqjjiSO7SDLWscEL sNgHXFKuueC69n1OQ3mTiW/ESI9bX3T/GMUOMbLKZMnKuRpOahPxOI5Pq/25gpAnAP+w pqlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=GEFU12BZgipi56TLbbLr4vBe7e5F1OiRJU7hDiKhQMw=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=QkTKHa3zUeOTrJz40oJ6wIoMDyT+h8d/ZKk45G0jSxGzvaUI8wTybN4+xUpgNZAubd RmcWeVy6OAwezs7G/CFmGr7zTFD+yfxTRsj/jrlsU+IHujPSJ/VulTGyL7qxDQd8SCNy 0Y15Fhol3Zn3CF3NgAPoyf+jtwdVMnC2eVu7eefIEuOfueAlU2H1cetKVC6fpFd+HP4l YLEKWBxtRJa0S1NL7+WlwdDDvP1xF4F3vSIjlyOxIPAAhvSADwmc76y0oEDkot1vmx/v 6A3WEVi2Vkeenl10pLiBbzp8fhSK+zWTG0/XcvfCmCdQwE936jSjKetdeQovyAPW1fue gWIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=u4ULlL7t; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l25-20020aa7d959000000b0052237839228si1479143eds.562.2023.08.04.04.49.50; Fri, 04 Aug 2023 04:50:14 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=u4ULlL7t; 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 S231567AbjHDKpB (ORCPT + 99 others); Fri, 4 Aug 2023 06:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231518AbjHDKor (ORCPT ); Fri, 4 Aug 2023 06:44:47 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E67546BD for ; Fri, 4 Aug 2023 03:44:46 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C0E1E1BAE; Fri, 4 Aug 2023 12:43:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145818; bh=VL2Zw7Ueb46o20OnyXzo7UsNsItrGawjFD5subpRhLA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=u4ULlL7tvxIKpOUx0VJO+MVbnfZrDOfOYTnlihOhFO8TLNvLS2KO/yUsNHy+OBkxJ QwM7FLJRxjgHAbzy+0V6M5tH53AzKpi2jGaUpB1jvHnbnLv8FEVznyEnbwPVX0ilQn Ssii+EpwteLN6FRajzPbcTNJ76hVn4cuxdA0EWXI= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:10 +0300 Subject: [PATCH 05/11] drm/bridge: tc358768: Print logical values, not raw register values MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-5-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4161; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=VL2Zw7Ueb46o20OnyXzo7UsNsItrGawjFD5subpRhLA=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaS4UeqJCGOhxjM1pf6s/5aVvSD48+u23FYF z4/mHBK/+uJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkgAKCRD6PaqMvJYe 9T2RD/0YwlqUpyhFktnI4J/zqdVjHTNjyt/hhVrv7zBqKOlX8+ZReohrJ0sZpZrjyZSv4/tTr/Y Zy5PXtHTEbGDeOFMXz3XU5HUef7+E2OPuwRUVgDT+ATsVsQNC5LFPwJWsLifRFfYjm1/SY0NM/T oA64T3LV4LxWUrt/8NU5wAje4EzTdmd0OZ6ZY2L4xobZ4irxFaBqRBFNk/fmcPgw8twucBBPRZv pCy9bJSXEQ9kgMNMrJSlPyw4GMGavR9DpazR3KfIWbGwBEGDr2iVgDrRJVBdHl3X37bzJvkGgm8 lNTymEtfWemDw93TLBblbaQqPI0pSHYrItEaUVEHmbIHaybKpkWqg4iAetEVbEhkYbgJt/N40Bc 5Kv1RQQJq0Xme3ZZ0eJ6a04/fKfM8u9LSuJCABhI0YT6KCEIZwepYeX1XICC8F3YLCznzd7mAI1 YmRzUs9OE17GNmacEXdkR7F2Fg7oQ9hJ8Yyyvfz29KA23+BpAwyqUOfwFsfFR0dGRPY+b4HFJOF yQF1hTSCwoCphmDZkdUvuNlTy8dERNwHHa+/44hZMd4aFIhYy07sxHW/BiXeAlHSD1oN6QMLgyg AT/VIf25BsW1z3OuQHP6DQIDP++dlvmFzm4TJZj9EvBVJUazGRVgoI3Xa2pf5ycylS28mX4ZjCL 5Jxd0QW8KowqPGw== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773299108074540451 X-GMAIL-MSGID: 1773299108074540451 The driver debug prints DSI related timings as raw register values in hex. It is much more useful to see the "logical" value of the timing, not the register value. Change the prints to print the values separately, in case a single register contains multiple values, and use %u to have it in a more human consumable form. Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index 9b633038af33..0ef51d04bb21 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -739,57 +739,59 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) /* LP11 > 100us for D-PHY Rx Init */ val = tc358768_ns_to_cnt(100 * 1000, dsibclk_nsk) - 1; - dev_dbg(priv->dev, "LINEINITCNT: 0x%x\n", val); + dev_dbg(priv->dev, "LINEINITCNT: %u\n", val); tc358768_write(priv, TC358768_LINEINITCNT, val); /* LPTimeCnt > 50ns */ val = tc358768_ns_to_cnt(50, dsibclk_nsk) - 1; lptxcnt = val; - dev_dbg(priv->dev, "LPTXTIMECNT: 0x%x\n", val); + dev_dbg(priv->dev, "LPTXTIMECNT: %u\n", val); tc358768_write(priv, TC358768_LPTXTIMECNT, val); /* 38ns < TCLK_PREPARE < 95ns */ val = tc358768_ns_to_cnt(65, dsibclk_nsk) - 1; + dev_dbg(priv->dev, "TCLK_PREPARECNT %u\n", val); /* TCLK_PREPARE + TCLK_ZERO > 300ns */ val2 = tc358768_ns_to_cnt(300 - tc358768_to_ns(2 * ui_nsk), dsibclk_nsk) - 2; + dev_dbg(priv->dev, "TCLK_ZEROCNT %u\n", val2); val |= val2 << 8; - dev_dbg(priv->dev, "TCLK_HEADERCNT: 0x%x\n", val); tc358768_write(priv, TC358768_TCLK_HEADERCNT, val); /* 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); + dev_dbg(priv->dev, "TCLK_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_TRAILCNT, val); /* 40ns + 4*UI < THS_PREPARE < 85ns + 6*UI */ val = 50 + tc358768_to_ns(4 * ui_nsk); val = tc358768_ns_to_cnt(val, dsibclk_nsk) - 1; + dev_dbg(priv->dev, "THS_PREPARECNT %u\n", val); /* THS_PREPARE + THS_ZERO > 145ns + 10*UI */ raw_val = tc358768_ns_to_cnt(145 - tc358768_to_ns(3 * ui_nsk), dsibclk_nsk) - 10; val2 = clamp(raw_val, 0, 127); + dev_dbg(priv->dev, "THS_ZEROCNT %u\n", val2); val |= val2 << 8; - dev_dbg(priv->dev, "THS_HEADERCNT: 0x%x\n", val); tc358768_write(priv, TC358768_THS_HEADERCNT, val); /* TWAKEUP > 1ms in lptxcnt steps */ val = tc358768_ns_to_cnt(1020000, dsibclk_nsk); val = val / (lptxcnt + 1) - 1; - dev_dbg(priv->dev, "TWAKEUP: 0x%x\n", val); + dev_dbg(priv->dev, "TWAKEUP: %u\n", val); tc358768_write(priv, TC358768_TWAKEUP, val); /* TCLK_POSTCNT > 60ns + 52*UI */ val = tc358768_ns_to_cnt(60 + tc358768_to_ns(52 * ui_nsk), dsibclk_nsk) - 3; - dev_dbg(priv->dev, "TCLK_POSTCNT: 0x%x\n", val); + dev_dbg(priv->dev, "TCLK_POSTCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_POSTCNT, val); /* max(60ns + 4*UI, 8*UI) < THS_TRAILCNT < 105ns + 12*UI */ raw_val = tc358768_ns_to_cnt(60 + tc358768_to_ns(18 * ui_nsk), dsibclk_nsk) - 4; val = clamp(raw_val, 0, 15); - dev_dbg(priv->dev, "THS_TRAILCNT: 0x%x\n", val); + dev_dbg(priv->dev, "THS_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_THS_TRAILCNT, val); val = BIT(0); @@ -803,10 +805,11 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) /* TXTAGOCNT[26:16] RXTASURECNT[10:0] */ val = tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk * 4); val = tc358768_ns_to_cnt(val, dsibclk_nsk) / 4 - 1; + dev_dbg(priv->dev, "TXTAGOCNT: %u\n", val); val2 = tc358768_ns_to_cnt(tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk), dsibclk_nsk) - 2; + dev_dbg(priv->dev, "RXTASURECNT: %u\n", val2); val = val << 16 | val2; - dev_dbg(priv->dev, "BTACNTRL1: 0x%x\n", val); tc358768_write(priv, TC358768_BTACNTRL1, val); /* START[0] */ From patchwork Fri Aug 4 10:44:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp182485vqb; Fri, 4 Aug 2023 04:08:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGY/uAH3KVBzD2p5MIYhlSXr42P+VFJrc4nPC8i9G1PTqTDZsPweAoPsJSNLwaXR3sIcMfB X-Received: by 2002:a05:6a00:1a8c:b0:686:6166:3738 with SMTP id e12-20020a056a001a8c00b0068661663738mr1339848pfv.28.1691147321031; Fri, 04 Aug 2023 04:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691147321; cv=none; d=google.com; s=arc-20160816; b=PqZ8IPe8x/PhuLzwWp4vDnVMMImj3L8UYauS51bhGsb2JevrdCHpvU6j31qdjjaX3Y 5o9He1O8aglF+j9Q3RN2kx7eYeyCNIBvZtIbioj001Wce5ga6KuUEfp+/SUUa7f9Cv8W YAn5Gz/dG4m/m8xQkqtt6uf+Nc6jc/wltjBecs6VeOjb89wBkHJNA8u4DRAAMwoFfB2Q n1RfXkcar/eVT608PsGh0K6/Y9mQYLwKhCdgdUcvLhEKnxAScjjrT2VYbSDDb21tJ9O3 rSBaYxpeQHPp37jbqIu4M4vjlooM4mHhCWR2xIGI0lWrxHY9qgxmp6wTGFqYNPte+KKl mkYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=JwTRi+HzqlhiXrDvb60NUe9BegV9sYT0BRAPZACat28=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=Gb2y3tMGAdeZb5vJIxp6dJO9W44WI3hxIeHJfu/ZkgxKCQjyZ2CpuP1REzf0dkecuD rCT/vp1SZYSA6OiNHdPDUaoP0jT1NbnkJM6Pwqlgz2ixOYZWlKmhiqtQAK+3xelIo7dr CM5o/L+KLO15jAdD6NA6s1oyEJdWRFlUr8ho0pF4wxI+FBaxuRCOqQdUOrtaRPxwXYJh bz2h70EDA8iYdS9i/bTHpmGUKxAf6HQ9Ec45ZE/K/LQ2a75pzikFg4i+P8LWPds0IazJ U8nh6zDFNeAO6kGZnwT1FnfV4ORYEuIO3WoJZEjhO1Dn+PCQYu8gKMrOA+p8YNfzVbi9 v28Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=tDBX70oT; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s187-20020a635ec4000000b005637e28270fsi1563297pgb.243.2023.08.04.04.08.13; Fri, 04 Aug 2023 04:08:41 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=tDBX70oT; 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 S231588AbjHDKpH (ORCPT + 99 others); Fri, 4 Aug 2023 06:45:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231533AbjHDKou (ORCPT ); Fri, 4 Aug 2023 06:44:50 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4582349CB for ; Fri, 4 Aug 2023 03:44:48 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CA8792E4; Fri, 4 Aug 2023 12:43:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145819; bh=TDI9Cw23pqxLneDtSVZkuUlDvO2vp0pomzNNIvZxHCc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=tDBX70oTEiRrV57weoEqw73RKdubUeomLY50iaZDIUuYnD5fIK3tLhuZkcYvfvZOR LjDa3/d8fQzia7oUxEoCr/vLv83a1b47XMOBrcLkUdqHnzr67jj8hrJzzBke2LXibu teQ4GbumgqhQAr+mJXL03vAXFhP9YLYaHlV6l1Pc= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:11 +0300 Subject: [PATCH 06/11] drm/bridge: tc358768: Use dev for dbg prints, not priv->dev MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-6-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6214; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=TDI9Cw23pqxLneDtSVZkuUlDvO2vp0pomzNNIvZxHCc=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaSpke1QciS+X445m7BNs2NHAURVJkC9xUl7 bvewAkTfvWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkgAKCRD6PaqMvJYe 9QBQD/94UvRBDpwfWCu6SsfgrgZxRQgWwFWY/1TYnp28tDiRs1sGvVRNGBHXYBepsXysFxqUQtA RJmM/kTxIEyJVO9GWOeSO3vh2auPQl2RQrt4pe7m7mk49HOXhv0u/EM8zOgFNK7H382WZ1DFrgI fx2NKN2/UhTSN7pUK0In2jnEhMHMetgwj95iDJN0iJDsoEwWcu1wVEOHO38ATHCNoeJ7WKb+2Nb I83bfG6mai2Pf/v9QGKnOj/Kpj6K6PoRW3P8IiySzJxDOM6pe26k1SsrgD+Oy69yOUe6ZLiDZfu 9AwhfJwwYnczDF9S5Ugj+P1LenHkx7kbp6VbvRO7wiyFcXGi0oo/RLr7SGCvz53jul6/jswHyPv +LA/6jkdYsqDM0YZICZZyygFbq9REbOF3f3RvVI9B9pnnxW9GO7r7ADK1vVEEZtHjVc1X02f8TD iTGqA6sYD26WRgtfvdMVx73Hsk7ia2AU/kHKUQBMmDQwXeoLgUOl63icr6AUzLnDsRax+G+R6gJ AmTzLxuE5zqPBAkqqNnMX0EZaaTkqVnpLqKBU2bB7rra/dr1JIUMo3CkE/j9TGxtJwFTmmwyZ5Y IIgYpWUa7s18O0HEgWJ1eg8ZwijhrwF54a/RD/Aopw+ioXebY6xJTNU0gteQ4bnXkcpDzx8i9jQ MGdpV22P8tTuPKQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773296493270055246 X-GMAIL-MSGID: 1773296493270055246 Simplify the code by capturing the priv->dev value to dev variable, and use it. Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 41 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index 0ef51d04bb21..3266c08d9bf1 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -651,9 +651,10 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) const u32 internal_delay = 40; int ret, i; struct videomode vm; + struct device *dev = priv->dev; if (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) { - dev_warn_once(priv->dev, "Non-continuous mode unimplemented, falling back to continuous\n"); + dev_warn_once(dev, "Non-continuous mode unimplemented, falling back to continuous\n"); mode_flags &= ~MIPI_DSI_CLOCK_NON_CONTINUOUS; } @@ -661,7 +662,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) ret = tc358768_sw_reset(priv); if (ret) { - dev_err(priv->dev, "Software reset failed: %d\n", ret); + dev_err(dev, "Software reset failed: %d\n", ret); tc358768_hw_disable(priv); return; } @@ -669,7 +670,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) mode = &bridge->encoder->crtc->state->adjusted_mode; ret = tc358768_setup_pll(priv, mode); if (ret) { - dev_err(priv->dev, "PLL setup failed: %d\n", ret); + dev_err(dev, "PLL setup failed: %d\n", ret); tc358768_hw_disable(priv); return; } @@ -709,7 +710,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16; break; default: - dev_err(priv->dev, "Invalid data format (%u)\n", + dev_err(dev, "Invalid data format (%u)\n", dsi_dev->format); tc358768_hw_disable(priv); return; @@ -733,65 +734,65 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) dsibclk); dsiclk_nsk = (u32)div_u64((u64)1000000000 * TC358768_PRECISION, dsiclk); ui_nsk = dsiclk_nsk / 2; - dev_dbg(priv->dev, "dsiclk_nsk: %u\n", dsiclk_nsk); - dev_dbg(priv->dev, "ui_nsk: %u\n", ui_nsk); - dev_dbg(priv->dev, "dsibclk_nsk: %u\n", dsibclk_nsk); + dev_dbg(dev, "dsiclk_nsk: %u\n", dsiclk_nsk); + dev_dbg(dev, "ui_nsk: %u\n", ui_nsk); + dev_dbg(dev, "dsibclk_nsk: %u\n", dsibclk_nsk); /* LP11 > 100us for D-PHY Rx Init */ val = tc358768_ns_to_cnt(100 * 1000, dsibclk_nsk) - 1; - dev_dbg(priv->dev, "LINEINITCNT: %u\n", val); + dev_dbg(dev, "LINEINITCNT: %u\n", val); tc358768_write(priv, TC358768_LINEINITCNT, val); /* LPTimeCnt > 50ns */ val = tc358768_ns_to_cnt(50, dsibclk_nsk) - 1; lptxcnt = val; - dev_dbg(priv->dev, "LPTXTIMECNT: %u\n", val); + dev_dbg(dev, "LPTXTIMECNT: %u\n", val); tc358768_write(priv, TC358768_LPTXTIMECNT, val); /* 38ns < TCLK_PREPARE < 95ns */ val = tc358768_ns_to_cnt(65, dsibclk_nsk) - 1; - dev_dbg(priv->dev, "TCLK_PREPARECNT %u\n", val); + dev_dbg(dev, "TCLK_PREPARECNT %u\n", val); /* TCLK_PREPARE + TCLK_ZERO > 300ns */ val2 = tc358768_ns_to_cnt(300 - tc358768_to_ns(2 * ui_nsk), dsibclk_nsk) - 2; - dev_dbg(priv->dev, "TCLK_ZEROCNT %u\n", val2); + dev_dbg(dev, "TCLK_ZEROCNT %u\n", val2); val |= val2 << 8; tc358768_write(priv, TC358768_TCLK_HEADERCNT, val); /* 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: %u\n", val); + dev_dbg(dev, "TCLK_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_TRAILCNT, val); /* 40ns + 4*UI < THS_PREPARE < 85ns + 6*UI */ val = 50 + tc358768_to_ns(4 * ui_nsk); val = tc358768_ns_to_cnt(val, dsibclk_nsk) - 1; - dev_dbg(priv->dev, "THS_PREPARECNT %u\n", val); + dev_dbg(dev, "THS_PREPARECNT %u\n", val); /* THS_PREPARE + THS_ZERO > 145ns + 10*UI */ raw_val = tc358768_ns_to_cnt(145 - tc358768_to_ns(3 * ui_nsk), dsibclk_nsk) - 10; val2 = clamp(raw_val, 0, 127); - dev_dbg(priv->dev, "THS_ZEROCNT %u\n", val2); + dev_dbg(dev, "THS_ZEROCNT %u\n", val2); val |= val2 << 8; tc358768_write(priv, TC358768_THS_HEADERCNT, val); /* TWAKEUP > 1ms in lptxcnt steps */ val = tc358768_ns_to_cnt(1020000, dsibclk_nsk); val = val / (lptxcnt + 1) - 1; - dev_dbg(priv->dev, "TWAKEUP: %u\n", val); + dev_dbg(dev, "TWAKEUP: %u\n", val); tc358768_write(priv, TC358768_TWAKEUP, val); /* TCLK_POSTCNT > 60ns + 52*UI */ val = tc358768_ns_to_cnt(60 + tc358768_to_ns(52 * ui_nsk), dsibclk_nsk) - 3; - dev_dbg(priv->dev, "TCLK_POSTCNT: %u\n", val); + dev_dbg(dev, "TCLK_POSTCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_POSTCNT, val); /* max(60ns + 4*UI, 8*UI) < THS_TRAILCNT < 105ns + 12*UI */ raw_val = tc358768_ns_to_cnt(60 + tc358768_to_ns(18 * ui_nsk), dsibclk_nsk) - 4; val = clamp(raw_val, 0, 15); - dev_dbg(priv->dev, "THS_TRAILCNT: %u\n", val); + dev_dbg(dev, "THS_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_THS_TRAILCNT, val); val = BIT(0); @@ -805,10 +806,10 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) /* TXTAGOCNT[26:16] RXTASURECNT[10:0] */ val = tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk * 4); val = tc358768_ns_to_cnt(val, dsibclk_nsk) / 4 - 1; - dev_dbg(priv->dev, "TXTAGOCNT: %u\n", val); + dev_dbg(dev, "TXTAGOCNT: %u\n", val); val2 = tc358768_ns_to_cnt(tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk), dsibclk_nsk) - 2; - dev_dbg(priv->dev, "RXTASURECNT: %u\n", val2); + dev_dbg(dev, "RXTASURECNT: %u\n", val2); val = val << 16 | val2; tc358768_write(priv, TC358768_BTACNTRL1, val); @@ -902,7 +903,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) ret = tc358768_clear_error(priv); if (ret) { - dev_err(priv->dev, "Bridge pre_enable failed: %d\n", ret); + dev_err(dev, "Bridge pre_enable failed: %d\n", ret); tc358768_bridge_disable(bridge); tc358768_bridge_post_disable(bridge); } From patchwork Fri Aug 4 10:44:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp195359vqb; Fri, 4 Aug 2023 04:33:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0nvBsTl2zt62Smx6lkPWYIvfzADa6aYj6yPlZuxl7Z9EdSbnrpETy6piADnegLbwq9NhS X-Received: by 2002:a05:6402:1e8c:b0:51e:5bd5:fe7e with SMTP id f12-20020a0564021e8c00b0051e5bd5fe7emr1659483edf.17.1691148819748; Fri, 04 Aug 2023 04:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691148819; cv=none; d=google.com; s=arc-20160816; b=XT+TFf1OXXZHrkB43IKjD3Gp8gXVMOLF97LhiTqT9CXRSV+wogf5lLFXU1jPUIQnIO X2Tz1S07HjI1TU+u178GBB39t7cQQQOZihR0maoX8+jIEqtKGRZpP+NCrikJl/6UAqYS 2XXCwcX2didtXMrQARteG4mggHmvqOIyNKLlhJqGxiaX3lmegl45HYjZeJYzwvVnqo3O nFQyLv4Rb3trcTFhQzindBBNJmNK1p2btg/WykoTcOiOMUG0nx8claS7hS0qhcMMtwqq Q/i+Pic7e6qxiTL5qElOV5xaiyEkQrvlTdp6+MhZmLqICLLBLV18m0lhMF16t7OdeADU AJZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=9XIgOCCzPD0hd2pjVc+mqwSIxAk9qwxXpEsjFLm4hao=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=Qs2UkUUtqEeUh5B2TIioHPylZmwAcTzLHDvQFyfPZWNSieoUTpMzaBbrJko7ybRqaH 7qGpob15x/iGcBRwarL2F8S4+N8ke0PirbY3cIBwDCZDfJ+Gn8vPdmtlbtCe/KzY9V2/ SwTSTECU4OmFHh+sjkSmIh+IdxcK0mVB5nZ1FZ4vNjBHNs7+RNvBZI0rUWnd0VMcMhns mqOFKTdCxPoPiomA99y6MSyVErqWbAwe2etfJ2oPLcjMdSlND0OIOt+vgLClLl/BUTVJ aTsJtU90NV1QPBP7RMuw64yd7f46WOk1GPV0oeHy0fXcqXhUPeiOhZguelVOSgV3WipT 9s4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="cHtA/ikZ"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d24-20020a056402079800b005222007595fsi116072edy.87.2023.08.04.04.33.16; Fri, 04 Aug 2023 04:33:39 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="cHtA/ikZ"; 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 S231593AbjHDKpK (ORCPT + 99 others); Fri, 4 Aug 2023 06:45:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231535AbjHDKou (ORCPT ); Fri, 4 Aug 2023 06:44:50 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D12B49D6 for ; Fri, 4 Aug 2023 03:44:48 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E3F1712E4; Fri, 4 Aug 2023 12:43:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145820; bh=Z33kVdpZefR4T4jHN2TcfkOhn6sG3FUQswblV1pZ7fI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cHtA/ikZSPUMXiwKutlgFnMOpC173aa8kIGA7QGqxZWegVQrNwVgb+rLmcGoWFh6e /Koa9D0GSfLAmyYFBNreiQSM5dPf1UriZWvUR4/uYoxVa7tVxvIH8pCtnnVb+rUyqj mV3ZXe9BNoyfVdV26Ha+7WzexlSkx8G/j3kbJeHg= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:12 +0300 Subject: [PATCH 07/11] drm/bridge: tc358768: Rename dsibclk to hsbyteclk MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-7-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=7306; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=Z33kVdpZefR4T4jHN2TcfkOhn6sG3FUQswblV1pZ7fI=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaThNg+d7lEAoswYIxJMzYYMiMGqrtH+deZe fIT6teBN1mJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkwAKCRD6PaqMvJYe 9Q4eD/wI506iloc5UhJvk5OJX1jmdwK7cTpLn7Rl8obueJ4FAbsfHnS2cYsc70qrzIRaH1qtvSm RMmnrKekU1DMZqprAnFJDV39AJVP7ln5+Ol7Wd6k9bIiyNRqS4PEBBH9Jrnbo9og3h0sf5CewTN JHQ0dM3kH5eIYwpOC7MBw1Q2kt1ZFo1hWgF6FskssU1hdQrv357ENlmJtTI2twPRzvglOkeWrcy 6Mp1yzvQSWF/p2sifDIm9TqnLUeWrtFFGKIRW7m4/rg4NUVVWHtb9ONNZ5f9UZnZznnFLEwsOij Wlx6fbeRyKksqz2a7OCXocC89wGyi++qHPZz14+Nm8ncqWOCqbhRJF7SlngT2NUnFqaA0TG/U4b L3gyJPx0zICHxfxSM8lqJfnEoHJpxyXQtNgNBZg5PUPMM7xsbF+pBghhyK/+JfNNPh8d9M667Nq fJdyD8p7Co16zlZozEtp+tJFojf+5+LML37UnExQVrbKjHldszLGFnBwIwk/fLKW6Fnx+WFvWVl or4nZNxzAMScOOAArPQxhuiM7VAGhecI375JfZsnTsvULBTGtj0EUUQ2cmeSm9YjyATgqgnr+tg 8cSCSYdb039A5aSZd7bMbAP6+w3ZrccuOaqTEfywUOc1NW/YPvNn8tfsAGMidfVcYY3MMr/0TXd Ud8Hhb1X61zlSWQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773298064509938536 X-GMAIL-MSGID: 1773298064509938536 The Toshiba documentation talks about HSByteClk when referring to the DSI HS byte clock, whereas the driver uses 'dsibclk' name. Also, in a few places the driver calculates the byte clock from the DSI clock, even if the byte clock is already available in a variable. To align the driver with the documentation, change the 'dsibclk' variable to 'hsbyteclk'. This also make it easier to visually separate 'dsibclk' and 'dsiclk' variables. Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index 3266c08d9bf1..db45b4a982c0 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -604,7 +604,7 @@ static int tc358768_setup_pll(struct tc358768_priv *priv, dev_dbg(priv->dev, "PLL: refclk %lu, fbd %u, prd %u, frs %u\n", clk_get_rate(priv->refclk), fbd, prd, frs); - dev_dbg(priv->dev, "PLL: pll_clk: %u, DSIClk %u, DSIByteClk %u\n", + dev_dbg(priv->dev, "PLL: pll_clk: %u, DSIClk %u, HSByteClk %u\n", priv->dsiclk * 2, priv->dsiclk, priv->dsiclk / 4); dev_dbg(priv->dev, "PLL: pclk %u (panel: %u)\n", tc358768_pll_to_pclk(priv, priv->dsiclk * 2), @@ -646,8 +646,8 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) u32 val, val2, lptxcnt, hact, data_type; s32 raw_val; const struct drm_display_mode *mode; - u32 dsibclk_nsk, dsiclk_nsk, ui_nsk; - u32 dsiclk, dsibclk, video_start; + u32 hsbyteclk_nsk, dsiclk_nsk, ui_nsk; + u32 dsiclk, hsbyteclk, video_start; const u32 internal_delay = 40; int ret, i; struct videomode vm; @@ -678,7 +678,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) drm_display_mode_to_videomode(mode, &vm); dsiclk = priv->dsiclk; - dsibclk = dsiclk / 4; + hsbyteclk = dsiclk / 4; /* Data Format Control Register */ val = BIT(2) | BIT(1) | BIT(0); /* rdswap_en | dsitx_en | txdt_en */ @@ -730,67 +730,67 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) tc358768_write(priv, TC358768_D0W_CNTRL + i * 4, 0x0000); /* DSI Timings */ - dsibclk_nsk = (u32)div_u64((u64)1000000000 * TC358768_PRECISION, - dsibclk); + hsbyteclk_nsk = (u32)div_u64((u64)1000000000 * TC358768_PRECISION, + hsbyteclk); dsiclk_nsk = (u32)div_u64((u64)1000000000 * TC358768_PRECISION, dsiclk); ui_nsk = dsiclk_nsk / 2; dev_dbg(dev, "dsiclk_nsk: %u\n", dsiclk_nsk); dev_dbg(dev, "ui_nsk: %u\n", ui_nsk); - dev_dbg(dev, "dsibclk_nsk: %u\n", dsibclk_nsk); + dev_dbg(dev, "hsbyteclk_nsk: %u\n", hsbyteclk_nsk); /* LP11 > 100us for D-PHY Rx Init */ - val = tc358768_ns_to_cnt(100 * 1000, dsibclk_nsk) - 1; + val = tc358768_ns_to_cnt(100 * 1000, hsbyteclk_nsk) - 1; dev_dbg(dev, "LINEINITCNT: %u\n", val); tc358768_write(priv, TC358768_LINEINITCNT, val); /* LPTimeCnt > 50ns */ - val = tc358768_ns_to_cnt(50, dsibclk_nsk) - 1; + val = tc358768_ns_to_cnt(50, hsbyteclk_nsk) - 1; lptxcnt = val; dev_dbg(dev, "LPTXTIMECNT: %u\n", val); tc358768_write(priv, TC358768_LPTXTIMECNT, val); /* 38ns < TCLK_PREPARE < 95ns */ - val = tc358768_ns_to_cnt(65, dsibclk_nsk) - 1; + val = tc358768_ns_to_cnt(65, hsbyteclk_nsk) - 1; dev_dbg(dev, "TCLK_PREPARECNT %u\n", val); /* TCLK_PREPARE + TCLK_ZERO > 300ns */ val2 = tc358768_ns_to_cnt(300 - tc358768_to_ns(2 * ui_nsk), - dsibclk_nsk) - 2; + hsbyteclk_nsk) - 2; dev_dbg(dev, "TCLK_ZEROCNT %u\n", val2); val |= val2 << 8; tc358768_write(priv, TC358768_TCLK_HEADERCNT, val); /* 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; + raw_val = tc358768_ns_to_cnt(60 + tc358768_to_ns(2 * ui_nsk), hsbyteclk_nsk) - 5; val = clamp(raw_val, 0, 127); dev_dbg(dev, "TCLK_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_TRAILCNT, val); /* 40ns + 4*UI < THS_PREPARE < 85ns + 6*UI */ val = 50 + tc358768_to_ns(4 * ui_nsk); - val = tc358768_ns_to_cnt(val, dsibclk_nsk) - 1; + val = tc358768_ns_to_cnt(val, hsbyteclk_nsk) - 1; dev_dbg(dev, "THS_PREPARECNT %u\n", val); /* THS_PREPARE + THS_ZERO > 145ns + 10*UI */ - raw_val = tc358768_ns_to_cnt(145 - tc358768_to_ns(3 * ui_nsk), dsibclk_nsk) - 10; + raw_val = tc358768_ns_to_cnt(145 - tc358768_to_ns(3 * ui_nsk), hsbyteclk_nsk) - 10; val2 = clamp(raw_val, 0, 127); dev_dbg(dev, "THS_ZEROCNT %u\n", val2); val |= val2 << 8; tc358768_write(priv, TC358768_THS_HEADERCNT, val); /* TWAKEUP > 1ms in lptxcnt steps */ - val = tc358768_ns_to_cnt(1020000, dsibclk_nsk); + val = tc358768_ns_to_cnt(1020000, hsbyteclk_nsk); val = val / (lptxcnt + 1) - 1; dev_dbg(dev, "TWAKEUP: %u\n", val); tc358768_write(priv, TC358768_TWAKEUP, val); /* TCLK_POSTCNT > 60ns + 52*UI */ val = tc358768_ns_to_cnt(60 + tc358768_to_ns(52 * ui_nsk), - dsibclk_nsk) - 3; + hsbyteclk_nsk) - 3; dev_dbg(dev, "TCLK_POSTCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_POSTCNT, val); /* max(60ns + 4*UI, 8*UI) < THS_TRAILCNT < 105ns + 12*UI */ raw_val = tc358768_ns_to_cnt(60 + tc358768_to_ns(18 * ui_nsk), - dsibclk_nsk) - 4; + hsbyteclk_nsk) - 4; val = clamp(raw_val, 0, 15); dev_dbg(dev, "THS_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_THS_TRAILCNT, val); @@ -804,11 +804,11 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) ? 0 : BIT(0)); /* TXTAGOCNT[26:16] RXTASURECNT[10:0] */ - val = tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk * 4); - val = tc358768_ns_to_cnt(val, dsibclk_nsk) / 4 - 1; + val = tc358768_to_ns((lptxcnt + 1) * hsbyteclk_nsk * 4); + val = tc358768_ns_to_cnt(val, hsbyteclk_nsk) / 4 - 1; dev_dbg(dev, "TXTAGOCNT: %u\n", val); - val2 = tc358768_ns_to_cnt(tc358768_to_ns((lptxcnt + 1) * dsibclk_nsk), - dsibclk_nsk) - 2; + val2 = tc358768_ns_to_cnt(tc358768_to_ns((lptxcnt + 1) * hsbyteclk_nsk), + hsbyteclk_nsk) - 2; dev_dbg(dev, "RXTASURECNT: %u\n", val2); val = val << 16 | val2; tc358768_write(priv, TC358768_BTACNTRL1, val); @@ -831,13 +831,13 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) /* hsw * byteclk * ndl / pclk */ val = (u32)div_u64(vm.hsync_len * - ((u64)priv->dsiclk / 4) * priv->dsi_lanes, + (u64)hsbyteclk * priv->dsi_lanes, vm.pixelclock); tc358768_write(priv, TC358768_DSI_HSW, val); /* hbp * byteclk * ndl / pclk */ val = (u32)div_u64(vm.hback_porch * - ((u64)priv->dsiclk / 4) * priv->dsi_lanes, + (u64)hsbyteclk * priv->dsi_lanes, vm.pixelclock); tc358768_write(priv, TC358768_DSI_HBPR, val); } else { @@ -856,7 +856,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) /* (hsw + hbp) * byteclk * ndl / pclk */ val = (u32)div_u64((vm.hsync_len + vm.hback_porch) * - ((u64)priv->dsiclk / 4) * priv->dsi_lanes, + (u64)hsbyteclk * priv->dsi_lanes, vm.pixelclock); tc358768_write(priv, TC358768_DSI_HSW, val); From patchwork Fri Aug 4 10:44:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp219549vqb; Fri, 4 Aug 2023 05:17:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGm37M8Jc5sRIw06GbycnFIYAWZsaoX0/gRemN50K1Jrz4AAUTNoMOrVL+nD2gtE8ehmxmT X-Received: by 2002:aa7:c990:0:b0:521:a99b:a233 with SMTP id c16-20020aa7c990000000b00521a99ba233mr1521727edt.10.1691151435757; Fri, 04 Aug 2023 05:17:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691151435; cv=none; d=google.com; s=arc-20160816; b=qIETnuaXyyzEFROWbFFhnGw2C9nNovpByCnV/FWMPD8JphdbCw33ShfeKIM/4k8PWO kaemsfsinVM5KhOvbwoxl87wMwh1wvKIxeaVAvEPlBLiLa2ojZQ+hyyDKxslaRGH6RZ3 RcA22Y1EM2+PZiXnoIIF1iD5HOCJMwUtBrGcauJ9nu9fzjZG7AkF7vqsWtgzjjANsAD/ YbN46kQ74PXBHueJPctZIrjTGjCcUS0iiPLyuJsNd39hKlaC8cLHwBt4exqGrB0x5W4f OoSv9RjQh/qbPRNIPHAuc66i9BBRXugp8ZBJA5X9P2WttMgFaWqKMZi9HLdO+B2QMRiX seRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=ARkrtq4DPGQqf9pcD00VOwvgSHMggU8tVWbvOV1odwE=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=0o/vPIY+UhqTpQ7ooi7Hk1jLHIhMjvtsx7LxlofY3r2MHhaDWy5N+KaoDIhwOdWlMz /nQyLhGjEsPVc5Y/7tlfw7oV6Bt5bjem8+ARAfeHuHlKahLs2fWvYh3vemw3qg3CQEiy EnsgnzE0XD5p9frJsYOh2BcMmwvM1bIItWlQSguPVGUGv8RbA/xAcABko+DfQaWrTdEC Jwbo5wNNLxQd3jNNNNrHFAilhSbXu4nxzC1d03vuE9fdXJX3DYTENNsFjTuBqnbze2ho zG41O6K68gaEtYO8jb1JhTAyC21nRwSA4CI5kIxQZ/YzfRfoq7z+DUz8DS7gjAdtAfdE vijQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=QYTeoUI6; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x13-20020aa7dacd000000b0052317adcb31si1559057eds.393.2023.08.04.05.16.51; Fri, 04 Aug 2023 05:17:15 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=QYTeoUI6; 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 S229882AbjHDKpd (ORCPT + 99 others); Fri, 4 Aug 2023 06:45:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbjHDKpB (ORCPT ); Fri, 4 Aug 2023 06:45:01 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ADEC49EF for ; Fri, 4 Aug 2023 03:44:52 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EB3772A4B; Fri, 4 Aug 2023 12:43:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145821; bh=ELgigWtoD/WjDlm4NjUr8bRyAjoxE3TF/Vb3awGuK/o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QYTeoUI6Z1KP9jf5JNFolFg1oOnCxfAWxOwnaejdsgSk3mgHhAE9UzhfeIem3ckTq mFQDX06n3asaAk/PsPidPV7dL/88XCfsI/8gS2GM4Mc5FW3MnXSoF5/J2crh6Yiapb CxGU1JUmovBYRcEeUU0N2DWGNJBfpRtpliEc7Oc8= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:13 +0300 Subject: [PATCH 08/11] drm/bridge: tc358768: Clean up clock period code MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-8-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6503; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=ELgigWtoD/WjDlm4NjUr8bRyAjoxE3TF/Vb3awGuK/o=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaTuuWogQSf6kACTFvu2u3h7ud5VB+1iSfB+ k8sp2aRBLyJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkwAKCRD6PaqMvJYe 9WLGEACZmidk7hLfu+CoMCAeSUbSFXTWFRD210fCVc+r7o1kzbQJ/IIZP+NmbUiaUkYAvl4l8bh n/Z7K5Hibr/Rq3RXPz2sSxGt3Mh0DpmFgH6DMkUjMUo5EPlVpn3jBuYT4lur0ecSVqjyAYp8DlB glUi5hLQMlFBc2zFaBBhXHeKkCpBG2WqXyzyoLkmvHcBgyY4LckKCgOJVZZMqLWLbobG6Ejgd8Q pwtC0iEZ8g20aBsnueri2dInvpDOSZsEejQX4JyW+YeCiwZN+WlnTnaOy9lIZBijHWabj+zAfOX CKjnR/eveGG6+X0DUVSFCvC9LIkZe27C3Up00ScFfooujkl0bd0fO08UsZ+z0Lp/d9t32Zyw/F4 6FYdILNlhHhBjZEy3DXeX3wgsBv3K82lCGLKvGVPLaQ6sn6fPmyWmBxA4rAl6r3DfSrMOfnCNOx ZzErsEJe0MUnCtQR+DohVWAtRRNZLk9mtauS7LqsXasQamN9SjIrvt/vbOnRnyuqM5QGISLQa51 r3cVq3e3MkXs5+bE6cx3/2SKfNz6abb/YXbldBamUl/Iij8olzW8izYZgpWV2oN/zlV/+Jvjs55 GNbr3qXNBL6SIW6f3DAE6xGZavfBiYYc7efnlCe7UXXo4HTEm3Z1c6yZvNXcw5H8X5HFdJO5sMn u6K+UZWWB+ufaRg== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773300807601944809 X-GMAIL-MSGID: 1773300807601944809 The driver defines TC358768_PRECISION as 1000, and uses "nsk" to refer to clock periods. The original author does not remember where all this came from. Effectively the driver is using picoseconds as the unit for clock periods, yet referring to them by "nsk". Clean this up by just saying the periods are in picoseconds. Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 60 +++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index db45b4a982c0..9411b0fb471e 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -627,15 +628,14 @@ static int tc358768_setup_pll(struct tc358768_priv *priv, return tc358768_clear_error(priv); } -#define TC358768_PRECISION 1000 -static u32 tc358768_ns_to_cnt(u32 ns, u32 period_nsk) +static u32 tc358768_ns_to_cnt(u32 ns, u32 period_ps) { - return (ns * TC358768_PRECISION + period_nsk) / period_nsk; + return (ns * 1000 + period_ps) / period_ps; } -static u32 tc358768_to_ns(u32 nsk) +static u32 tc358768_ps_to_ns(u32 ps) { - return (nsk / TC358768_PRECISION); + return ps / 1000; } static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) @@ -646,7 +646,7 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) u32 val, val2, lptxcnt, hact, data_type; s32 raw_val; const struct drm_display_mode *mode; - u32 hsbyteclk_nsk, dsiclk_nsk, ui_nsk; + u32 hsbyteclk_ps, dsiclk_ps, ui_ps; u32 dsiclk, hsbyteclk, video_start; const u32 internal_delay = 40; int ret, i; @@ -730,67 +730,65 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) tc358768_write(priv, TC358768_D0W_CNTRL + i * 4, 0x0000); /* DSI Timings */ - hsbyteclk_nsk = (u32)div_u64((u64)1000000000 * TC358768_PRECISION, - hsbyteclk); - dsiclk_nsk = (u32)div_u64((u64)1000000000 * TC358768_PRECISION, dsiclk); - ui_nsk = dsiclk_nsk / 2; - dev_dbg(dev, "dsiclk_nsk: %u\n", dsiclk_nsk); - dev_dbg(dev, "ui_nsk: %u\n", ui_nsk); - dev_dbg(dev, "hsbyteclk_nsk: %u\n", hsbyteclk_nsk); + hsbyteclk_ps = (u32)div_u64(PICO, hsbyteclk); + dsiclk_ps = (u32)div_u64(PICO, dsiclk); + ui_ps = dsiclk_ps / 2; + dev_dbg(dev, "dsiclk: %u ps, ui %u ps, hsbyteclk %u ps\n", dsiclk_ps, + ui_ps, hsbyteclk_ps); /* LP11 > 100us for D-PHY Rx Init */ - val = tc358768_ns_to_cnt(100 * 1000, hsbyteclk_nsk) - 1; + val = tc358768_ns_to_cnt(100 * 1000, hsbyteclk_ps) - 1; dev_dbg(dev, "LINEINITCNT: %u\n", val); tc358768_write(priv, TC358768_LINEINITCNT, val); /* LPTimeCnt > 50ns */ - val = tc358768_ns_to_cnt(50, hsbyteclk_nsk) - 1; + val = tc358768_ns_to_cnt(50, hsbyteclk_ps) - 1; lptxcnt = val; dev_dbg(dev, "LPTXTIMECNT: %u\n", val); tc358768_write(priv, TC358768_LPTXTIMECNT, val); /* 38ns < TCLK_PREPARE < 95ns */ - val = tc358768_ns_to_cnt(65, hsbyteclk_nsk) - 1; + val = tc358768_ns_to_cnt(65, hsbyteclk_ps) - 1; dev_dbg(dev, "TCLK_PREPARECNT %u\n", val); /* TCLK_PREPARE + TCLK_ZERO > 300ns */ - val2 = tc358768_ns_to_cnt(300 - tc358768_to_ns(2 * ui_nsk), - hsbyteclk_nsk) - 2; + val2 = tc358768_ns_to_cnt(300 - tc358768_ps_to_ns(2 * ui_ps), + hsbyteclk_ps) - 2; dev_dbg(dev, "TCLK_ZEROCNT %u\n", val2); val |= val2 << 8; tc358768_write(priv, TC358768_TCLK_HEADERCNT, val); /* TCLK_TRAIL > 60ns AND TEOT <= 105 ns + 12*UI */ - raw_val = tc358768_ns_to_cnt(60 + tc358768_to_ns(2 * ui_nsk), hsbyteclk_nsk) - 5; + raw_val = tc358768_ns_to_cnt(60 + tc358768_ps_to_ns(2 * ui_ps), hsbyteclk_ps) - 5; val = clamp(raw_val, 0, 127); dev_dbg(dev, "TCLK_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_TRAILCNT, val); /* 40ns + 4*UI < THS_PREPARE < 85ns + 6*UI */ - val = 50 + tc358768_to_ns(4 * ui_nsk); - val = tc358768_ns_to_cnt(val, hsbyteclk_nsk) - 1; + val = 50 + tc358768_ps_to_ns(4 * ui_ps); + val = tc358768_ns_to_cnt(val, hsbyteclk_ps) - 1; dev_dbg(dev, "THS_PREPARECNT %u\n", val); /* THS_PREPARE + THS_ZERO > 145ns + 10*UI */ - raw_val = tc358768_ns_to_cnt(145 - tc358768_to_ns(3 * ui_nsk), hsbyteclk_nsk) - 10; + raw_val = tc358768_ns_to_cnt(145 - tc358768_ps_to_ns(3 * ui_ps), hsbyteclk_ps) - 10; val2 = clamp(raw_val, 0, 127); dev_dbg(dev, "THS_ZEROCNT %u\n", val2); val |= val2 << 8; tc358768_write(priv, TC358768_THS_HEADERCNT, val); /* TWAKEUP > 1ms in lptxcnt steps */ - val = tc358768_ns_to_cnt(1020000, hsbyteclk_nsk); + val = tc358768_ns_to_cnt(1020000, hsbyteclk_ps); val = val / (lptxcnt + 1) - 1; dev_dbg(dev, "TWAKEUP: %u\n", val); tc358768_write(priv, TC358768_TWAKEUP, val); /* TCLK_POSTCNT > 60ns + 52*UI */ - val = tc358768_ns_to_cnt(60 + tc358768_to_ns(52 * ui_nsk), - hsbyteclk_nsk) - 3; + val = tc358768_ns_to_cnt(60 + tc358768_ps_to_ns(52 * ui_ps), + hsbyteclk_ps) - 3; dev_dbg(dev, "TCLK_POSTCNT: %u\n", val); tc358768_write(priv, TC358768_TCLK_POSTCNT, val); /* max(60ns + 4*UI, 8*UI) < THS_TRAILCNT < 105ns + 12*UI */ - raw_val = tc358768_ns_to_cnt(60 + tc358768_to_ns(18 * ui_nsk), - hsbyteclk_nsk) - 4; + raw_val = tc358768_ns_to_cnt(60 + tc358768_ps_to_ns(18 * ui_ps), + hsbyteclk_ps) - 4; val = clamp(raw_val, 0, 15); dev_dbg(dev, "THS_TRAILCNT: %u\n", val); tc358768_write(priv, TC358768_THS_TRAILCNT, val); @@ -804,11 +802,11 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) ? 0 : BIT(0)); /* TXTAGOCNT[26:16] RXTASURECNT[10:0] */ - val = tc358768_to_ns((lptxcnt + 1) * hsbyteclk_nsk * 4); - val = tc358768_ns_to_cnt(val, hsbyteclk_nsk) / 4 - 1; + val = tc358768_ps_to_ns((lptxcnt + 1) * hsbyteclk_ps * 4); + val = tc358768_ns_to_cnt(val, hsbyteclk_ps) / 4 - 1; dev_dbg(dev, "TXTAGOCNT: %u\n", val); - val2 = tc358768_ns_to_cnt(tc358768_to_ns((lptxcnt + 1) * hsbyteclk_nsk), - hsbyteclk_nsk) - 2; + val2 = tc358768_ns_to_cnt(tc358768_ps_to_ns((lptxcnt + 1) * hsbyteclk_ps), + hsbyteclk_ps) - 2; dev_dbg(dev, "RXTASURECNT: %u\n", val2); val = val << 16 | val2; tc358768_write(priv, TC358768_BTACNTRL1, val); From patchwork Fri Aug 4 10:44:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131103 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp185850vqb; Fri, 4 Aug 2023 04:14:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZz3Yc/E14cqgYoOvHOPXMBlxHxaS1mm8d/8waCJANaS2PRKtESVewEEroe+Kl5Q7q5ASM X-Received: by 2002:a9d:6b93:0:b0:6b9:6a43:1f7c with SMTP id b19-20020a9d6b93000000b006b96a431f7cmr1376481otq.26.1691147687103; Fri, 04 Aug 2023 04:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691147687; cv=none; d=google.com; s=arc-20160816; b=CXcQ1yG3uvlopm9xTRZW6dE+Ql+GEvyHCjqfduZz0r9S2reAz4A9VoZ3GjCKqL2eTJ kbiPKqnPt29H1msVNukMffl/bXMjCixUmoqmaPKy8ii0ggIAzMV/IF31KwHni8uVNAp0 DSFA/WiEg/rJm6Edr/2FSIR2EsVTzoMKocKCvWtPsg9f1DcI2aIC/gSkeSn9LABKv0hD kahwWj1kfGPZkV2bBlaPInO9MMzGjrJ/7QLnrnOrGo0K1MHE491BDDbt9yQ0DLNcDQnM lvCRqW7KCKgI61mn1ZQBpwUkaXBn2WEBQX9sUsqhR1SGPpKFGhRKQ4YpUoL78E42235T eieQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=VQd/B6bu2LF+k6NSA3bjXSMakNCvn8KiiBowJ0Xv67c=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=t1YeLOi6qtz4ifDxXq3I79IlkAiK16Cy1TgsNYNZswNTROwEDCsYtMNV1jUps+wysL C7EAJ6BUUeZCBTtl2bb3AYRAd7im6R9PkRMF46wciiXzrdNNzSpBRCPG1Ygf7oBWGQ7F qgVqJL6NvUIWhJeXHkStrp7+mGirconbtvFTV9Z7nm4Fblvm7uwSNgZHf7rMNhcjVVMs 48b589u3bm84GtxWEqJnOp57Wa0NVZmDxPO0z4ll9bTooeDLlbv0S+OdOGJi6ScZb67f 7rmMOQBbMV/ck+8lyeqL1ZReAj9tMDVHmUjyHbu8zvP09oIzz2c9ms+Yk1oJ6pwHBQyc d67A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=QQDrQw2z; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 190-20020a6309c7000000b0054ff4634f1asi1608157pgj.658.2023.08.04.04.14.24; Fri, 04 Aug 2023 04:14:47 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=QQDrQw2z; 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 S231625AbjHDKpb (ORCPT + 99 others); Fri, 4 Aug 2023 06:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbjHDKoy (ORCPT ); Fri, 4 Aug 2023 06:44:54 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A13349F2 for ; Fri, 4 Aug 2023 03:44:52 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F2C942B6A; Fri, 4 Aug 2023 12:43:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145822; bh=V/DMo8p5jJ8+UtiQ3KTL91bfgqjlzonLkdA5+0U3ogc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QQDrQw2zsdZc2behvl1P1HZYOJm5BRjBhPLP4HW8UoUklhgQOib+VkcfdAdacF5sP U3lE+2lnXRBNCW5C3HGf9nNrM9GHkxT24BWlve/ulCYmuf9cHVRkGB2Ir9Bj41wJQJ c5nGUHluGuSnyiYk3ZgaxRX4x/lQellgHqWz0mzA= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:14 +0300 Subject: [PATCH 09/11] drm/bridge: tc358768: Fix tc358768_ns_to_cnt() MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-9-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=900; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=V/DMo8p5jJ8+UtiQ3KTL91bfgqjlzonLkdA5+0U3ogc=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaTNhDk+zBX+nctIEkqq6764yQTt3//SgEa4 LXEPMvQJ2iJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWkwAKCRD6PaqMvJYe 9f9cD/4vJ0wTQJ84zUrVTjnCcNpInCDTRekKAhZydWgGkY/wt7GfIkXDTZh9wN49zcFXHeTDH/a 3qZEA+WTOpJEw6oFxy4uMC/sP5y13aCG7HMeaAccxYh+Euqc5NrSE+bcJ3JCror4+CWKtBJJHrr QG/Ol9aJYit3s1o5r6QQ/PaUI5j1diao0NxADE4b9fzVJiDcVbsAszjYWDs34cHxqySM3QbBNUH OB7f1W7dxHb25zddImzuzdq03UplxmDGTRFB65JeENBsqkR4+G0wiXJzXNBoBDUokWh/rgSo9Ew o2qgbELY7nGucvTh9GqKdYFnk5wU7+V5ABn4g9J1FzL/872wScuXyu4Lyb2cX9gMuOGAp9UbkbE BKPkfGiBm5p2Hi5VvHbaYOuWOw8laaBjoDRhRnPvftsBOgzBAip8sp3sWA3OF5eexN6FbMkOd/J nJlrNujDBoAIEuB13Gfdhe1ooryBOMb/Of7yEOqhCSEPfzdrHggvulrw851yqXkb8BSp0Om0MI6 cjWo4oUwBwXa2gkOtWLRWcArQsDyJX5Gf3wEu++8kXNdqBX8abt4YH7hLB7Zqw7/DWf5P2qsTmV 8ay6GL0DuZe4jDypl4V2bSJ0aXiHyFGdeLZ9oKZ/jKEnTE9s1WX7Og9f+6OsZm+uJS8MXLhw1ar VDeOYwZfH60M/dw== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773296876959244391 X-GMAIL-MSGID: 1773296876959244391 The tc358768_ns_to_cnt() is, most likely, supposed to do a div-round-up operation, but it misses subtracting one from the dividend. Fix this by just using DIV_ROUND_UP(). Fixes: ff1ca6397b1d ("drm/bridge: Add tc358768 driver") Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index 9411b0fb471e..dc2241c18dde 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -630,7 +630,7 @@ static int tc358768_setup_pll(struct tc358768_priv *priv, static u32 tc358768_ns_to_cnt(u32 ns, u32 period_ps) { - return (ns * 1000 + period_ps) / period_ps; + return DIV_ROUND_UP(ns * 1000, period_ps); } static u32 tc358768_ps_to_ns(u32 ps) From patchwork Fri Aug 4 10:44:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131092 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp176264vqb; Fri, 4 Aug 2023 03:58:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWN4WCkAy7F2pIR3QdteDuRzWDFkrFHgcisqU0j0/sEzHIAZDyaVKee/7qdSzHmAnSA4lf X-Received: by 2002:a05:6512:368b:b0:4fe:62f:35eb with SMTP id d11-20020a056512368b00b004fe062f35ebmr1073330lfs.20.1691146687284; Fri, 04 Aug 2023 03:58:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691146687; cv=none; d=google.com; s=arc-20160816; b=EqZwjtLAxnJTeWoIhMebc+2JGkWinoVTCHHpiNHTmOX3A8YvIukKOnrbgORQWwHnMB 1KIV4mBJb1mVnnxznGv+ieM8EZUQokiW5KNe6/1yy0om/nIGySS11nqa9iHPpLBmsCrD QE/mVSIcBGLgzrOTH832SPWo0GWvHUuY46OJQ7JG7GtoWmIsjiEVKlef4UrW3KuQhjMZ d/IQuNF95OI+4p9A51LRHmjYX1eOVSUYEf0DBMmOsIFVzZMsyAeRFYYMVwg+Sd2g0O0B MCpJiimX6lMTKjBF49hzmJBNm5ynEEFCOnddgVnAJXhC7Tcj4Zsp3fLOPkw6HpZEK6yI eyog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=7pvnaY3wmTsE1oNJYsjMrsJ/iAruCeK7PuqJxOdImsY=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=z8IbSlPrgqVQtno59maljOxCuC9MqNfAKjQkWpnV8z1sMwe1RuELJ7PFRgEMIcmUT9 A+zye6f5KLMgGwcVvecin+rfQeo5AZPMzkVTK0vHG1HQVRLIM5Phgm7d2uKSB/TS0AXw 1kW1jFwogUMDcuZPzlCBMenBkW6oP83qg8LkTDoIdJ2bI8q/iOKwoKx0mSzcAQDAxtVV WfzHazgc9DFPQ6d7PDxrBHq6OEzg3dkWJaEYvO+xTRPwfyUvkHgjfM7gjEQsQg4Z6SX8 oi260UnE1rtvDEnOie36m2ryMwuF2A6UAhVoMiuNOAAOwQL7WdxO/EvDl6jeEcaIZPrR G+2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=iDJynuOG; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z25-20020aa7cf99000000b00522ac23622dsi1454462edx.168.2023.08.04.03.57.43; Fri, 04 Aug 2023 03:58:07 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=iDJynuOG; 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 S231667AbjHDKpn (ORCPT + 99 others); Fri, 4 Aug 2023 06:45:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231602AbjHDKpZ (ORCPT ); Fri, 4 Aug 2023 06:45:25 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFCB349FA for ; Fri, 4 Aug 2023 03:44:54 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 07798188E; Fri, 4 Aug 2023 12:43:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145823; bh=mzuNNrlR1ZEml0Ert0BP5I69sb5mNHms4gIhBN+F6LM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iDJynuOGxKruA16kvC/vwbx+D5LWAu0ecDwmXSDPqRH1BV+IN185nIYn9Q3EdKCpJ FSvKi2AHm7sPwju8YuI7GZlpGyhYVrOffAuVUU9eAj1P2wH7kO3XpcyMr3YdXtQThM i5L9UENxzqpLiMvWhtzS1wvur5LsjxyrqsnvM4xo= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:15 +0300 Subject: [PATCH 10/11] drm/bridge: tc358768: Attempt to fix DSI horizontal timings MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-10-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=11714; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=mzuNNrlR1ZEml0Ert0BP5I69sb5mNHms4gIhBN+F6LM=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaUZkI+X2XFkRCR1GnPjwqHx6GhUR5BLGn2Y /kmo1d+q8mJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWlAAKCRD6PaqMvJYe 9azmD/42tL4IOGpRdSwhJ7/oX04fozZ9uwRKjXGhT5ci/yDf5zpY9RAhjHTVo2+49H7zYw7H3rD IYf2yG55vYjbUaLf2n/V7N4OE6b0WJ2vmayssavjWor6ZtgIUJQ9n4VfPN1FSUEUuWzV9XftQW6 UZsl7WjeNltAxFGItdhk2J8XsXwCvaB3iOoeKlNw/rInyDHN5zC4a71VnnHgGe6rG6rX2Vr32C6 66N61NvQBguWYzxip14NIvcxrkjPe9ettX1x6Mg1ynsUaH5ve4A9NfBzuUHloM8COYz+fe4Lz9l XeqxxVviORN7mli+DH9Z7bEYM4hHTo7iKwImFA2QYZVb6wUHPX5TJaqtTpezhrXJA5ToqYmANxh qaSnYajlznLqU6TNXRMIR5nct/30i8r9SUq+simVGB0M5HIXnZmtnjKEbpKFt6vP/uj4L5KBevX utOKsFF0TEAct0Jif4chziSC88hxf0BzW7e3beuA5NIwTyIdKirpvVjNYmVR4ICYG7k3QLHdGM8 NN/C7cR8reS+VQrhn/OyTKYVY+9QN8+EDMpZTVLTrVT/tSSR6tzW4paxCe4ejHRcWlIWqR1bt/r BFyTyRSf4tmfipxUCM4M2P94gF+P22kRxKXuTBNrGn8ortkerob6L7L10HIqHprjJs3zsjlA81c e/ViFET1V7J75XA== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773295828978705595 X-GMAIL-MSGID: 1773295828978705595 The DSI horizontal timing calculations done by the driver seem to often lead to underflows or overflows, depending on the videomode. There are two main things the current driver doesn't seem to get right: DSI HSW and HFP, and VSDly. However, even following Toshiba's documentation it seems we don't always get a working display. This patch attempts to fix the horizontal timings for DSI event mode, and on a system with a DSI->HDMI encoder, a lot of standard HDMI modes now seem to work. The work relies on Toshiba's documentation, but also quite a bit on empirical testing. This also adds timing related debug prints to make it easier to improve on this later. The DSI pulse mode has only been tested with a fixed-resolution panel, which limits the testing of different modes on DSI pulse mode. However, as the VSDly calculation also affects pulse mode, so this might cause a regression. Signed-off-by: Tomi Valkeinen Reviewed-by: Peter Ujfalusi --- drivers/gpu/drm/bridge/tc358768.c | 211 +++++++++++++++++++++++++++++++++----- 1 file changed, 183 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index dc2241c18dde..ea19de5509ed 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 @@ -157,6 +158,7 @@ struct tc358768_priv { u32 frs; /* PLL Freqency range for HSCK (post divider) */ u32 dsiclk; /* pll_clk / 2 */ + u32 pclk; /* incoming pclk rate */ }; static inline struct tc358768_priv *dsi_host_to_tc358768(struct mipi_dsi_host @@ -380,6 +382,7 @@ static int tc358768_calc_pll(struct tc358768_priv *priv, priv->prd = best_prd; priv->frs = frs; priv->dsiclk = best_pll / 2; + priv->pclk = mode->clock * 1000; return 0; } @@ -638,6 +641,28 @@ static u32 tc358768_ps_to_ns(u32 ps) return ps / 1000; } +static u32 tc358768_dpi_to_ns(u32 val, u32 pclk) +{ + return (u32)div_u64((u64)val * NANO, pclk); +} + +/* Convert value in DPI pixel clock units to DSI byte count */ +static u32 tc358768_dpi_to_dsi_bytes(struct tc358768_priv *priv, u32 val) +{ + u64 m = (u64)val * priv->dsiclk / 4 * priv->dsi_lanes; + u64 n = priv->pclk; + + return (u32)div_u64(m + n - 1, n); +} + +static u32 tc358768_dsi_bytes_to_ns(struct tc358768_priv *priv, u32 val) +{ + u64 m = (u64)val * NANO; + u64 n = priv->dsiclk / 4 * priv->dsi_lanes; + + return (u32)div_u64(m, n); +} + static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) { struct tc358768_priv *priv = bridge_to_tc358768(bridge); @@ -647,11 +672,19 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) s32 raw_val; const struct drm_display_mode *mode; u32 hsbyteclk_ps, dsiclk_ps, ui_ps; - u32 dsiclk, hsbyteclk, video_start; - const u32 internal_delay = 40; + u32 dsiclk, hsbyteclk; int ret, i; struct videomode vm; struct device *dev = priv->dev; + /* In pixelclock units */ + u32 dpi_htot, dpi_data_start; + /* In byte units */ + u32 dsi_dpi_htot, dsi_dpi_data_start; + u32 dsi_hsw, dsi_hbp, dsi_hact, dsi_hfp; + const u32 dsi_hss = 4; /* HSS is a short packet (4 bytes) */ + /* In hsbyteclk units */ + u32 dsi_vsdly; + const u32 internal_dly = 40; if (mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) { dev_warn_once(dev, "Non-continuous mode unimplemented, falling back to continuous\n"); @@ -686,27 +719,23 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) case MIPI_DSI_FMT_RGB888: val |= (0x3 << 4); hact = vm.hactive * 3; - video_start = (vm.hsync_len + vm.hback_porch) * 3; data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24; break; case MIPI_DSI_FMT_RGB666: val |= (0x4 << 4); hact = vm.hactive * 3; - video_start = (vm.hsync_len + vm.hback_porch) * 3; data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18; break; case MIPI_DSI_FMT_RGB666_PACKED: val |= (0x4 << 4) | BIT(3); hact = vm.hactive * 18 / 8; - video_start = (vm.hsync_len + vm.hback_porch) * 18 / 8; data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18; break; case MIPI_DSI_FMT_RGB565: val |= (0x5 << 4); hact = vm.hactive * 2; - video_start = (vm.hsync_len + vm.hback_porch) * 2; data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16; break; default: @@ -716,9 +745,150 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) return; } + /* + * There are three important things to make TC358768 work correctly, + * which are not trivial to manage: + * + * 1. Keep the DPI line-time and the DSI line-time as close to each + * other as possible. + * 2. TC358768 goes to LP mode after each line's active area. The DSI + * HFP period has to be long enough for entering and exiting LP mode. + * But it is not clear how to calculate this. + * 3. VSDly (video start delay) has to be long enough to ensure that the + * DSI TX does not start transmitting util we have started receiving + * pixel data from the DPI input. It is not clear how to calculate + * this either. + */ + + dpi_htot = vm.hactive + vm.hfront_porch + vm.hsync_len + vm.hback_porch; + dpi_data_start = vm.hsync_len + vm.hback_porch; + + dev_dbg(dev, "dpi horiz timing (pclk): %u + %u + %u + %u = %u\n", + vm.hsync_len, vm.hback_porch, vm.hactive, vm.hfront_porch, + dpi_htot); + + dev_dbg(dev, "dpi horiz timing (ns): %u + %u + %u + %u = %u\n", + tc358768_dpi_to_ns(vm.hsync_len, vm.pixelclock), + tc358768_dpi_to_ns(vm.hback_porch, vm.pixelclock), + tc358768_dpi_to_ns(vm.hactive, vm.pixelclock), + tc358768_dpi_to_ns(vm.hfront_porch, vm.pixelclock), + tc358768_dpi_to_ns(dpi_htot, vm.pixelclock)); + + dev_dbg(dev, "dpi data start (ns): %u + %u = %u\n", + tc358768_dpi_to_ns(vm.hsync_len, vm.pixelclock), + tc358768_dpi_to_ns(vm.hback_porch, vm.pixelclock), + tc358768_dpi_to_ns(dpi_data_start, vm.pixelclock)); + + dsi_dpi_htot = tc358768_dpi_to_dsi_bytes(priv, dpi_htot); + dsi_dpi_data_start = tc358768_dpi_to_dsi_bytes(priv, dpi_data_start); + + if (dsi_dev->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) { + dsi_hsw = tc358768_dpi_to_dsi_bytes(priv, vm.hsync_len); + dsi_hbp = tc358768_dpi_to_dsi_bytes(priv, vm.hback_porch); + } else { + /* HBP is included in HSW in event mode */ + dsi_hbp = 0; + dsi_hsw = tc358768_dpi_to_dsi_bytes(priv, + vm.hsync_len + vm.hback_porch); + + /* + * The pixel packet includes the actual pixel data, and: + * DSI packet header = 4 bytes + * DCS code = 1 byte + * DSI packet footer = 2 bytes + */ + dsi_hact = hact + 4 + 1 + 2; + + dsi_hfp = dsi_dpi_htot - dsi_hact - dsi_hsw - dsi_hss; + + /* + * Here we should check if HFP is long enough for entering LP + * and exiting LP, but it's not clear how to calculate that. + * Instead, this is a naive algorithm that just adjusts the HFP + * and HSW so that HFP is (at least) roughly 2/3 of the total + * blanking time. + */ + if (dsi_hfp < (dsi_hfp + dsi_hsw + dsi_hss) * 2 / 3) { + u32 old_hfp = dsi_hfp; + u32 old_hsw = dsi_hsw; + u32 tot = dsi_hfp + dsi_hsw + dsi_hss; + + dsi_hsw = tot / 3; + + /* + * Seems like sometimes HSW has to be divisible by num-lanes, but + * not always... + */ + dsi_hsw = roundup(dsi_hsw, priv->dsi_lanes); + + dsi_hfp = dsi_dpi_htot - dsi_hact - dsi_hsw - dsi_hss; + + dev_dbg(dev, + "hfp too short, adjusting dsi hfp and dsi hsw from %u, %u to %u, %u\n", + old_hfp, old_hsw, dsi_hfp, dsi_hsw); + } + + dev_dbg(dev, + "dsi horiz timing (bytes): %u, %u + %u + %u + %u = %u\n", + dsi_hss, dsi_hsw, dsi_hbp, dsi_hact, dsi_hfp, + dsi_hss + dsi_hsw + dsi_hbp + dsi_hact + dsi_hfp); + + dev_dbg(dev, "dsi horiz timing (ns): %u + %u + %u + %u + %u = %u\n", + tc358768_dsi_bytes_to_ns(priv, dsi_hss), + tc358768_dsi_bytes_to_ns(priv, dsi_hsw), + tc358768_dsi_bytes_to_ns(priv, dsi_hbp), + tc358768_dsi_bytes_to_ns(priv, dsi_hact), + tc358768_dsi_bytes_to_ns(priv, dsi_hfp), + tc358768_dsi_bytes_to_ns(priv, dsi_hss + dsi_hsw + dsi_hbp + dsi_hact + dsi_hfp)); + } + + /* VSDly calculation */ + + /* Start with the HW internal delay */ + dsi_vsdly = internal_dly; + + /* Convert to byte units as the other variables are in byte units */ + dsi_vsdly *= priv->dsi_lanes; + + /* Do we need more delay, in addition to the internal? */ + if (dsi_dpi_data_start > dsi_vsdly + dsi_hss + dsi_hsw + dsi_hbp) { + dsi_vsdly = dsi_dpi_data_start - dsi_hss - dsi_hsw - dsi_hbp; + dsi_vsdly = roundup(dsi_vsdly, priv->dsi_lanes); + } + + dev_dbg(dev, "dsi data start (bytes) %u + %u + %u + %u = %u\n", + dsi_vsdly, dsi_hss, dsi_hsw, dsi_hbp, + dsi_vsdly + dsi_hss + dsi_hsw + dsi_hbp); + + dev_dbg(dev, "dsi data start (ns) %u + %u + %u + %u = %u\n", + tc358768_dsi_bytes_to_ns(priv, dsi_vsdly), + tc358768_dsi_bytes_to_ns(priv, dsi_hss), + tc358768_dsi_bytes_to_ns(priv, dsi_hsw), + tc358768_dsi_bytes_to_ns(priv, dsi_hbp), + tc358768_dsi_bytes_to_ns(priv, dsi_vsdly + dsi_hss + dsi_hsw + dsi_hbp)); + + /* Convert back to hsbyteclk */ + dsi_vsdly /= priv->dsi_lanes; + + /* + * The docs say that there is an internal delay of 40 cycles. + * However, we get underflows if we follow that rule. If we + * instead ignore the internal delay, things work. So either + * the docs are wrong or the calculations are wrong. + * + * As a temporary fix, add the internal delay here, to counter + * the subtraction when writing the register. + */ + dsi_vsdly += internal_dly; + + /* Clamp to the register max */ + if (dsi_vsdly - internal_dly > 0x3ff) { + dev_warn(dev, "VSDly too high, underflows likely\n"); + dsi_vsdly = 0x3ff + internal_dly; + } + /* VSDly[9:0] */ - video_start = max(video_start, internal_delay + 1) - internal_delay; - tc358768_write(priv, TC358768_VSDLY, video_start); + tc358768_write(priv, TC358768_VSDLY, dsi_vsdly - internal_dly); tc358768_write(priv, TC358768_DATAFMT, val); tc358768_write(priv, TC358768_DSITX_DT, data_type); @@ -826,18 +996,6 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) /* vbp */ tc358768_write(priv, TC358768_DSI_VBPR, vm.vback_porch); - - /* hsw * byteclk * ndl / pclk */ - val = (u32)div_u64(vm.hsync_len * - (u64)hsbyteclk * priv->dsi_lanes, - vm.pixelclock); - tc358768_write(priv, TC358768_DSI_HSW, val); - - /* hbp * byteclk * ndl / pclk */ - val = (u32)div_u64(vm.hback_porch * - (u64)hsbyteclk * priv->dsi_lanes, - vm.pixelclock); - tc358768_write(priv, TC358768_DSI_HBPR, val); } else { /* Set event mode */ tc358768_write(priv, TC358768_DSI_EVENT, 1); @@ -851,16 +1009,13 @@ static void tc358768_bridge_pre_enable(struct drm_bridge *bridge) /* vbp (not used in event mode) */ tc358768_write(priv, TC358768_DSI_VBPR, 0); + } - /* (hsw + hbp) * byteclk * ndl / pclk */ - val = (u32)div_u64((vm.hsync_len + vm.hback_porch) * - (u64)hsbyteclk * priv->dsi_lanes, - vm.pixelclock); - tc358768_write(priv, TC358768_DSI_HSW, val); + /* hsw (bytes) */ + tc358768_write(priv, TC358768_DSI_HSW, dsi_hsw); - /* hbp (not used in event mode) */ - tc358768_write(priv, TC358768_DSI_HBPR, 0); - } + /* hbp (bytes) */ + tc358768_write(priv, TC358768_DSI_HBPR, dsi_hbp); /* hact (bytes) */ tc358768_write(priv, TC358768_DSI_HACT, hact); From patchwork Fri Aug 4 10:44:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 131104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:44a:b0:3f2:4152:657d with SMTP id ez10csp185883vqb; Fri, 4 Aug 2023 04:14:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnA7J5T2iwglU2LJXCs9194cQ2SsgCf3cr2sZ42255IOluZOEt7/m7rU1z3GPQmNzsiKuv X-Received: by 2002:a17:903:41c6:b0:1bb:ab0d:4f76 with SMTP id u6-20020a17090341c600b001bbab0d4f76mr1847742ple.58.1691147689706; Fri, 04 Aug 2023 04:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691147689; cv=none; d=google.com; s=arc-20160816; b=FfyZxos8h/QRLxmlDTHUmPqY0qoV4DO2sGBG+K6BHRMnO4gXCrAvndesiK4+lX4eLm eT7J3fY5pLXROg3q0Wjg5k7+GCxTlzGYCof3LT64SXlcrE8vnD2o9bzul4PSfLfnu8Do LjjREnNUAGlj+jEHcmP9P4bL7sWCAmvzlpJ6MfbsHjQlKfQyK2ilhu7qgVEPYr+4BiS5 OhEgXA4vBJXPzhZbnLkggwCfnsdEhinVVAoFJBbBXZHOThF+HX9pWKkMeEQOJXXX78He bu+nRQ7wRE1f1505FYVVprMAbUvzsXoGNlw+mbGQc9Z0KfJ9Gvb+HIq7VqzrtNgKCKMc W4ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=kzVWueXpYGukXxzwso5CiX9i2OR433Tta+3HippSZVg=; fh=7GYuw25cWCmHG5LrbyQUwFOElFQ4tchxd/wzYEHngW8=; b=FkjDjzTOtcdvBa06Ka4kQL8T2ZU7Th7ke68gp6rBSJ3nEgaj7vRhYzCUMxIf0ge+LG 1/qrM4xhFyOGS+tw0G6f98L4e0s4c3wMy0QhtcztxdgtrwT2NVi/dfsFDwgi/GEdAXG1 yH0lS+V2FB/dYDmQ8iS2IItg9RbOKlL5yICs9V7hpk6ahJCN6eNcEjL9pmfSmzNl9TEU quBLTSEzxS7WVr+YiBnXPvTICpuVwI0J8PJFQLJGSzKIYRmMU4DhHWzwAk06WzDozpPy ZLsILfdi8g/lbX9SSl+vgX3slxjvNU4LIVQoVaCp+99Fd9qN44ZaTj6c3vXRL1tNs4f8 VXrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=dGDYFKiR; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t6-20020a170902e84600b001b89bcfb2c3si1690941plg.162.2023.08.04.04.14.26; Fri, 04 Aug 2023 04:14:49 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=dGDYFKiR; 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 S231535AbjHDKpp (ORCPT + 99 others); Fri, 4 Aug 2023 06:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231609AbjHDKp0 (ORCPT ); Fri, 4 Aug 2023 06:45:26 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F08B84C06 for ; Fri, 4 Aug 2023 03:44:55 -0700 (PDT) Received: from [127.0.1.1] (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0FFA81AB3; Fri, 4 Aug 2023 12:43:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691145824; bh=NVGv48ZsaW1J2ePUXosAluIgk8qR+1DrF7efAr7lM4w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=dGDYFKiRY3ejkAX1kWBtrueu0SEW5lxRwH92ud9Fe8DbjpkvBgjWLhXcumV9/AJfF KF19+EBtC0ql19kWEcAO9xd1NdMKirgUIF5Ax3zAbA57x3H0cZ9iKndFzEVAVhzD3f +vSaM3Qz6n0tbhbNt7mDycPPs3CPG8wv26aLTXdk= From: Tomi Valkeinen Date: Fri, 04 Aug 2023 13:44:16 +0300 Subject: [PATCH 11/11] drm/bridge: tc358768: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support MIME-Version: 1.0 Message-Id: <20230804-tc358768-v1-11-1afd44b7826b@ideasonboard.com> References: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> In-Reply-To: <20230804-tc358768-v1-0-1afd44b7826b@ideasonboard.com> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , =?utf-8?q?P=C3=A9ter_Ujfalusi?= , Francesco Dolcini Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Aradhya Bhatia , Tomi Valkeinen X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3311; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=NVGv48ZsaW1J2ePUXosAluIgk8qR+1DrF7efAr7lM4w=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBkzNaUTL0ctCqlqan7C6QJgIPS0jOOK19pqZh0f tnCtHFYzGWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCZMzWlAAKCRD6PaqMvJYe 9Z3oD/9GvdukB96G4adIbYXsQ7SSiIRzmYQYNiFOUQW55h6eof6UJRwPyXL+5wiOP9/MyFGtsLv Uk32KzqAHGJChrf2erw9ZGghKeZG0M/UQ8GJeQ+BjTSMGgOh0ySP/+bSgqvic65dsayZ5Fmg11b CVhophTt8Q4uCahRYBjQgc06ueGYQPKj8Qw0p6kJY1D3KhLvHxCDjQj4i+gFd9++hbPBw+wg0zc +n4vi3WG/S7vytZLqJvhZV3pKqteZw+SRNYux7kWeLOpQ2QIBOntlPm6KJi7ymcsAYBYFusDwiz 6Lscmd9PudbiBvPA+8vCcIZUaMuBNkZLYIlUtMtrBZHb9qlzKyRpoKtOeB0hql8j16N0b4DTg4C x7MR3m3NjuqvTdloSLRHfydtvDH9MJQhUdkxQRIPO++KLyQX9uVsN4OFnYfockwKfsSGvSxQQX6 YKAb5vw0FCx00uBHGxjZoFlhCBphTFmen4hmo9qU8+8wfP2dLt6Xj9189q8KSTUueFOX+gGJZGS 7tC54hRSst9FBUaZYC00YPgXkjAlWMcdNARl2zQXEJU/jJFWHjt22UXsiftwPgdei9SjR8fiamp 6cci8rii7FfrhOWFYz2a+31j4hZGvVaxW6Dnqxwl5aJPzLMFy7lGfj5Ap/TuxpQiywsljV50Aez Yqj74AJoa4QYsSw== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773296879802539905 X-GMAIL-MSGID: 1773296879802539905 Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/bridge/tc358768.c | 64 +++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/bridge/tc358768.c b/drivers/gpu/drm/bridge/tc358768.c index ea19de5509ed..a567f136ddc7 100644 --- a/drivers/gpu/drm/bridge/tc358768.c +++ b/drivers/gpu/drm/bridge/tc358768.c @@ -131,8 +131,17 @@ static const char * const tc358768_supplies[] = { struct tc358768_dsi_output { struct mipi_dsi_device *dev; + + /* Legacy field if DRM_BRIDGE_ATTACH_NO_CONNECTOR is not used */ struct drm_panel *panel; - struct drm_bridge *bridge; + + /* + * If DRM_BRIDGE_ATTACH_NO_CONNECTOR is not used and a panel is attached + * to tc358768, 'next_bridge' contains the bridge the driver created + * with drm_panel_bridge_add_typed(). Otherwise 'next_bridge' contains + * the next bridge the driver found. + */ + struct drm_bridge *next_bridge; }; struct tc358768_priv { @@ -391,8 +400,6 @@ static int tc358768_dsi_host_attach(struct mipi_dsi_host *host, struct mipi_dsi_device *dev) { struct tc358768_priv *priv = dsi_host_to_tc358768(host); - struct drm_bridge *bridge; - struct drm_panel *panel; struct device_node *ep; int ret; @@ -420,21 +427,7 @@ static int tc358768_dsi_host_attach(struct mipi_dsi_host *host, return -ENOTSUPP; } - ret = drm_of_find_panel_or_bridge(host->dev->of_node, 1, 0, &panel, - &bridge); - if (ret) - return ret; - - if (panel) { - bridge = drm_panel_bridge_add_typed(panel, - DRM_MODE_CONNECTOR_DSI); - if (IS_ERR(bridge)) - return PTR_ERR(bridge); - } - priv->output.dev = dev; - priv->output.bridge = bridge; - priv->output.panel = panel; priv->dsi_lanes = dev->lanes; priv->dsi_bpp = mipi_dsi_pixel_format_to_bpp(dev->format); @@ -463,7 +456,7 @@ static int tc358768_dsi_host_detach(struct mipi_dsi_host *host, drm_bridge_remove(&priv->bridge); if (priv->output.panel) - drm_panel_bridge_remove(priv->output.bridge); + drm_panel_bridge_remove(priv->output.next_bridge); return 0; } @@ -544,7 +537,40 @@ static int tc358768_bridge_attach(struct drm_bridge *bridge, return -ENOTSUPP; } - return drm_bridge_attach(bridge->encoder, priv->output.bridge, bridge, + if (flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR) { + struct device_node *node; + + /* Get the next bridge, connected to port@1. */ + node = of_graph_get_remote_node(priv->dev->of_node, 1, -1); + if (!node) + return -ENODEV; + + priv->output.next_bridge = of_drm_find_bridge(node); + of_node_put(node); + if (!priv->output.next_bridge) + return -EPROBE_DEFER; + } else { + struct drm_bridge *bridge; + struct drm_panel *panel; + int ret; + + ret = drm_of_find_panel_or_bridge(priv->dev->of_node, 1, 0, + &panel, &bridge); + if (ret) + return ret; + + if (panel) { + bridge = drm_panel_bridge_add_typed(panel, + DRM_MODE_CONNECTOR_DSI); + if (IS_ERR(bridge)) + return PTR_ERR(bridge); + } + + priv->output.next_bridge = bridge; + priv->output.panel = panel; + } + + return drm_bridge_attach(bridge->encoder, priv->output.next_bridge, bridge, flags); }