* [PATCH] clk: ingenic: Fix bugs with divided dividers
@ 2021-10-01 17:20 Paul Cercueil
2021-11-02 21:27 ` Stephen Boyd
0 siblings, 1 reply; 2+ messages in thread
From: Paul Cercueil @ 2021-10-01 17:20 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd
Cc: linux-mips, list, linux-clk, linux-kernel, Paul Cercueil, Artur Rojek
Two fixes in one:
- In the "impose hardware constraints" block, the "logical" divider
value (aka. not translated to the hardware) was clamped to fit in the
register area, but this totally ignored the fact that the divider
value can itself have a fixed divider.
- The code that made sure that the divider value returned by the
function was a multiple of its own fixed divider could result in a
wrong value being calculated, because it was rounded down instead of
rounded up.
Fixes: 4afe2d1a6ed5 ("clk: ingenic: Allow divider value to be divided")
Co-developed-by: Artur Rojek <contact@artur-rojek.eu>
Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
drivers/clk/ingenic/cgu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/ingenic/cgu.c b/drivers/clk/ingenic/cgu.c
index 266c7595d330..af31633a8862 100644
--- a/drivers/clk/ingenic/cgu.c
+++ b/drivers/clk/ingenic/cgu.c
@@ -453,15 +453,15 @@ ingenic_clk_calc_div(struct clk_hw *hw,
}
/* Impose hardware constraints */
- div = min_t(unsigned, div, 1 << clk_info->div.bits);
- div = max_t(unsigned, div, 1);
+ div = clamp_t(unsigned int, div, clk_info->div.div,
+ clk_info->div.div << clk_info->div.bits);
/*
* If the divider value itself must be divided before being written to
* the divider register, we must ensure we don't have any bits set that
* would be lost as a result of doing so.
*/
- div /= clk_info->div.div;
+ div = DIV_ROUND_UP(div, clk_info->div.div);
div *= clk_info->div.div;
return div;
--
2.33.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clk: ingenic: Fix bugs with divided dividers
2021-10-01 17:20 [PATCH] clk: ingenic: Fix bugs with divided dividers Paul Cercueil
@ 2021-11-02 21:27 ` Stephen Boyd
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2021-11-02 21:27 UTC (permalink / raw)
To: Michael Turquette, Paul Cercueil
Cc: linux-mips, list, linux-clk, linux-kernel, Paul Cercueil, Artur Rojek
Quoting Paul Cercueil (2021-10-01 10:20:33)
> Two fixes in one:
>
> - In the "impose hardware constraints" block, the "logical" divider
> value (aka. not translated to the hardware) was clamped to fit in the
> register area, but this totally ignored the fact that the divider
> value can itself have a fixed divider.
>
> - The code that made sure that the divider value returned by the
> function was a multiple of its own fixed divider could result in a
> wrong value being calculated, because it was rounded down instead of
> rounded up.
>
> Fixes: 4afe2d1a6ed5 ("clk: ingenic: Allow divider value to be divided")
> Co-developed-by: Artur Rojek <contact@artur-rojek.eu>
> Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
Applied to clk-next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-02 21:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 17:20 [PATCH] clk: ingenic: Fix bugs with divided dividers Paul Cercueil
2021-11-02 21:27 ` 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).