* [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv
@ 2022-12-10 20:38 Kevin Groeneveld
2023-02-10 23:24 ` Stephen Boyd
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Kevin Groeneveld @ 2022-12-10 20:38 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team, linux-clk, linux-arm-kernel, linux-kernel
Cc: Kevin Groeneveld
kdiv is a signed 16 bit value in the DEV_CTL1 register. Commit
53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation") changed
the kdiv variable from a short int to just int. When the value read from
the DIV_CTL1 register is assigned directly to an int the sign of the value
is lost resulting in incorrect results when the value is negative. Adding
a s16 cast to the register value fixes the issue.
Fixes: 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation")
Signed-off-by: Kevin Groeneveld <kgroeneveld@lenbrook.com>
---
drivers/clk/imx/clk-pll14xx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c
index 1d0f79e9c346..d12194d17b10 100644
--- a/drivers/clk/imx/clk-pll14xx.c
+++ b/drivers/clk/imx/clk-pll14xx.c
@@ -254,7 +254,7 @@ static unsigned long clk_pll14xx_recalc_rate(struct clk_hw *hw,
if (pll->type == PLL_1443X) {
pll_div_ctl1 = readl_relaxed(pll->base + DIV_CTL1);
- kdiv = FIELD_GET(KDIV_MASK, pll_div_ctl1);
+ kdiv = (s16)FIELD_GET(KDIV_MASK, pll_div_ctl1);
} else {
kdiv = 0;
}
--
2.17.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv
2022-12-10 20:38 [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv Kevin Groeneveld
@ 2023-02-10 23:24 ` Stephen Boyd
2023-02-14 14:51 ` Kevin Groeneveld
2023-02-15 12:24 ` Abel Vesa
2023-02-18 1:44 ` Stephen Boyd
2 siblings, 1 reply; 5+ messages in thread
From: Stephen Boyd @ 2023-02-10 23:24 UTC (permalink / raw)
To: Abel Vesa, Fabio Estevam, Kevin Groeneveld, Michael Turquette,
NXP Linux Team, Pengutronix Kernel Team, Sascha Hauer, Shawn Guo,
linux-arm-kernel, linux-clk, linux-kernel
Cc: Kevin Groeneveld
Quoting Kevin Groeneveld (2022-12-10 12:38:35)
> kdiv is a signed 16 bit value in the DEV_CTL1 register. Commit
> 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation") changed
> the kdiv variable from a short int to just int. When the value read from
> the DIV_CTL1 register is assigned directly to an int the sign of the value
> is lost resulting in incorrect results when the value is negative. Adding
Can the field be negative?
> a s16 cast to the register value fixes the issue.
>
> Fixes: 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation")
> Signed-off-by: Kevin Groeneveld <kgroeneveld@lenbrook.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv
2023-02-10 23:24 ` Stephen Boyd
@ 2023-02-14 14:51 ` Kevin Groeneveld
0 siblings, 0 replies; 5+ messages in thread
From: Kevin Groeneveld @ 2023-02-14 14:51 UTC (permalink / raw)
To: Stephen Boyd, Abel Vesa, Fabio Estevam, Michael Turquette,
NXP Linux Team, Pengutronix Kernel Team, Sascha Hauer, Shawn Guo,
linux-arm-kernel, linux-clk, linux-kernel
On 2023-02-10 18:24, Stephen Boyd wrote:
> Quoting Kevin Groeneveld (2022-12-10 12:38:35)
>> kdiv is a signed 16 bit value in the DEV_CTL1 register. Commit
>> 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation") changed
>> the kdiv variable from a short int to just int. When the value read from
>> the DIV_CTL1 register is assigned directly to an int the sign of the value
>> is lost resulting in incorrect results when the value is negative. Adding
>
> Can the field be negative?
Yes it can be. That is how I found the issue as I had a negative value
in imx_pll14xx_rate_table which used to work but broke with the above
mentioned commit.
The i.MX8MM reference manual states:
>Formula for Fraction PLLOUT:
>* FOUT=((m+k/65536) x FIN) /(p x 2s)
>* Where, 1 ≤ p ≤ 63, 64 ≤ m ≤ 1023, 0 ≤ s ≤ 6, -32768 ≤ k ≤ 32767
>* p, m, and s are unsigned integers. k is a two's complement integer.
The comments in the imx_pll14xx_calc_settings function also mention the
same range for kdiv. And this function also uses negative values. For
example:
>/* Then see if we can get the desired rate by only adjusting kdiv
(glitch free) */
>rate_min = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, KDIV_MIN, prate);
>rate_max = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, KDIV_MAX, prate);
Where KDIV_MIN is defined as SHRT_MIN which is negative.
Kevin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv
2022-12-10 20:38 [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv Kevin Groeneveld
2023-02-10 23:24 ` Stephen Boyd
@ 2023-02-15 12:24 ` Abel Vesa
2023-02-18 1:44 ` Stephen Boyd
2 siblings, 0 replies; 5+ messages in thread
From: Abel Vesa @ 2023-02-15 12:24 UTC (permalink / raw)
To: Kevin Groeneveld
Cc: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
NXP Linux Team, linux-clk, linux-arm-kernel, linux-kernel
On 22-12-10 15:38:35, Kevin Groeneveld wrote:
> kdiv is a signed 16 bit value in the DEV_CTL1 register. Commit
> 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation") changed
> the kdiv variable from a short int to just int. When the value read from
> the DIV_CTL1 register is assigned directly to an int the sign of the value
> is lost resulting in incorrect results when the value is negative. Adding
> a s16 cast to the register value fixes the issue.
>
> Fixes: 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation")
> Signed-off-by: Kevin Groeneveld <kgroeneveld@lenbrook.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
Stephen, can you pick this up through fixes?
> ---
> drivers/clk/imx/clk-pll14xx.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c
> index 1d0f79e9c346..d12194d17b10 100644
> --- a/drivers/clk/imx/clk-pll14xx.c
> +++ b/drivers/clk/imx/clk-pll14xx.c
> @@ -254,7 +254,7 @@ static unsigned long clk_pll14xx_recalc_rate(struct clk_hw *hw,
>
> if (pll->type == PLL_1443X) {
> pll_div_ctl1 = readl_relaxed(pll->base + DIV_CTL1);
> - kdiv = FIELD_GET(KDIV_MASK, pll_div_ctl1);
> + kdiv = (s16)FIELD_GET(KDIV_MASK, pll_div_ctl1);
> } else {
> kdiv = 0;
> }
> --
> 2.17.1
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv
2022-12-10 20:38 [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv Kevin Groeneveld
2023-02-10 23:24 ` Stephen Boyd
2023-02-15 12:24 ` Abel Vesa
@ 2023-02-18 1:44 ` Stephen Boyd
2 siblings, 0 replies; 5+ messages in thread
From: Stephen Boyd @ 2023-02-18 1:44 UTC (permalink / raw)
To: Abel Vesa, Fabio Estevam, Kevin Groeneveld, Michael Turquette,
NXP Linux Team, Pengutronix Kernel Team, Sascha Hauer, Shawn Guo,
linux-arm-kernel, linux-clk, linux-kernel
Cc: Kevin Groeneveld
Quoting Kevin Groeneveld (2022-12-10 12:38:35)
> kdiv is a signed 16 bit value in the DEV_CTL1 register. Commit
> 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation") changed
> the kdiv variable from a short int to just int. When the value read from
> the DIV_CTL1 register is assigned directly to an int the sign of the value
> is lost resulting in incorrect results when the value is negative. Adding
> a s16 cast to the register value fixes the issue.
>
> Fixes: 53990cf9d5b4 ("clk: imx: pll14xx: consolidate rate calculation")
> Signed-off-by: Kevin Groeneveld <kgroeneveld@lenbrook.com>
> ---
Applied to clk-fixes
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-02-18 1:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-10 20:38 [PATCH] clk: imx: pll14xx: fix recalc_rate for negative kdiv Kevin Groeneveld
2023-02-10 23:24 ` Stephen Boyd
2023-02-14 14:51 ` Kevin Groeneveld
2023-02-15 12:24 ` Abel Vesa
2023-02-18 1:44 ` Stephen Boyd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).