From: "Péter Ujfalusi" <peter.ujfalusi@gmail.com>
To: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>,
Andrzej Hajda <andrzej.hajda@intel.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Robert Foss <rfoss@kernel.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Francesco Dolcini <francesco@dolcini.it>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
Aradhya Bhatia <a-bhatia1@ti.com>
Subject: Re: [PATCH 03/11] drm/bridge: tc358768: Cleanup PLL calculations
Date: Fri, 11 Aug 2023 19:25:42 +0300 [thread overview]
Message-ID: <37cf3e0d-5a30-466f-86d3-cda077c3921f@gmail.com> (raw)
In-Reply-To: <20230804-tc358768-v1-3-1afd44b7826b@ideasonboard.com>
On 04/08/2023 13:44, Tomi Valkeinen wrote:
> 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.
Reviewed-by: Peter Ujfalusi <peter.ujfalusi@gmail.com>
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
> ---
> 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,
>
--
Péter
next prev parent reply other threads:[~2023-08-11 16:23 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-04 10:44 [PATCH 00/11] drm/bridge: tc358768: Fixes and timings improvements Tomi Valkeinen
2023-08-04 10:44 ` [PATCH 01/11] drm/bridge: tc358768: Fix use of uninitialized variable Tomi Valkeinen
2023-08-11 16:19 ` Péter Ujfalusi
2023-08-04 10:44 ` [PATCH 02/11] drm/bridge: tc358768: Fix bit updates Tomi Valkeinen
2023-08-11 16:23 ` Péter Ujfalusi
2023-08-11 17:02 ` Tomi Valkeinen
2023-08-13 0:23 ` Maxim Schwalm
2023-08-14 6:34 ` Tomi Valkeinen
2023-08-15 17:21 ` Maxim Schwalm
2023-08-16 8:14 ` Tomi Valkeinen
2023-08-16 8:21 ` Tomi Valkeinen
2023-08-04 10:44 ` [PATCH 03/11] drm/bridge: tc358768: Cleanup PLL calculations Tomi Valkeinen
2023-08-11 16:25 ` Péter Ujfalusi [this message]
2023-08-04 10:44 ` [PATCH 04/11] drm/bridge: tc358768: Use struct videomode Tomi Valkeinen
2023-08-11 16:26 ` Péter Ujfalusi
2023-08-04 10:44 ` [PATCH 05/11] drm/bridge: tc358768: Print logical values, not raw register values Tomi Valkeinen
2023-08-11 16:31 ` Péter Ujfalusi
2023-08-11 17:05 ` Tomi Valkeinen
2023-08-04 10:44 ` [PATCH 06/11] drm/bridge: tc358768: Use dev for dbg prints, not priv->dev Tomi Valkeinen
2023-08-11 16:32 ` Péter Ujfalusi
2023-08-04 10:44 ` [PATCH 07/11] drm/bridge: tc358768: Rename dsibclk to hsbyteclk Tomi Valkeinen
2023-08-11 16:33 ` Péter Ujfalusi
2023-08-04 10:44 ` [PATCH 08/11] drm/bridge: tc358768: Clean up clock period code Tomi Valkeinen
2023-08-11 16:34 ` Péter Ujfalusi
2023-08-04 10:44 ` [PATCH 09/11] drm/bridge: tc358768: Fix tc358768_ns_to_cnt() Tomi Valkeinen
2023-08-11 16:35 ` Péter Ujfalusi
2023-08-04 10:44 ` [PATCH 10/11] drm/bridge: tc358768: Attempt to fix DSI horizontal timings Tomi Valkeinen
2023-08-11 16:39 ` Péter Ujfalusi
2023-08-04 10:44 ` [PATCH 11/11] drm/bridge: tc358768: Add DRM_BRIDGE_ATTACH_NO_CONNECTOR support Tomi Valkeinen
2023-08-11 16:44 ` Péter Ujfalusi
2023-08-11 16:58 ` Tomi Valkeinen
2023-08-13 17:11 ` Maxim Schwalm
2023-08-14 7:31 ` Tomi Valkeinen
2023-08-14 10:04 ` Tomi Valkeinen
2023-08-14 10:10 ` Sam Ravnborg
2023-08-14 10:17 ` Laurent Pinchart
2023-08-14 13:29 ` Tomi Valkeinen
2023-08-15 17:44 ` Maxim Schwalm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=37cf3e0d-5a30-466f-86d3-cda077c3921f@gmail.com \
--to=peter.ujfalusi@gmail.com \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=a-bhatia1@ti.com \
--cc=airlied@gmail.com \
--cc=andrzej.hajda@intel.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=francesco@dolcini.it \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=linux-kernel@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=rfoss@kernel.org \
--cc=tomi.valkeinen@ideasonboard.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®