Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: st: flexgen: Switch to determine_rate

The ST Flexgen clocks implements a mux with a set_parent hook, but
doesn't provide a determine_rate implementation.

This is a bit odd, since set_parent() is there to, as its name implies,
change the parent of a clock. However, the most likely candidate to
trigger that parent change is a call to clk_set_rate(), with
determine_rate() figuring out which parent is the best suited for a
given rate.

The other trigger would be a call to clk_set_parent(), but it's far less
used, and it doesn't look like there's any obvious user for that clock.

So, the set_parent hook is effectively unused, possibly because of an
oversight. However, it could also be an explicit decision by the
original author to avoid any reparenting but through an explicit call to
clk_set_parent().

The driver does implement round_rate() though, which means that we can
change the rate of the clock, but we will never get to change the
parent.

However, It's hard to tell whether it's been done on purpose or not.

Since we'll start mandating a determine_rate() implementation, let's
convert the round_rate() implementation to a determine_rate(), which
will also make the current behavior explicit. And if it was an
oversight, the clock behaviour can be adjusted later on.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-62-971d5077e7d2@cerno.tech
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Maxime Ripard and committed by
Stephen Boyd
36f8a30c 302d2f83

+8 -7
+8 -7
drivers/clk/st/clk-flexgen.c
··· 119 119 return parent_rate / rate + ((rate > (2*(parent_rate % rate))) ? 0 : 1); 120 120 } 121 121 122 - static long flexgen_round_rate(struct clk_hw *hw, unsigned long rate, 123 - unsigned long *prate) 122 + static int flexgen_determine_rate(struct clk_hw *hw, 123 + struct clk_rate_request *req) 124 124 { 125 125 unsigned long div; 126 126 127 127 /* Round div according to exact prate and wished rate */ 128 - div = clk_best_div(*prate, rate); 128 + div = clk_best_div(req->best_parent_rate, req->rate); 129 129 130 130 if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { 131 - *prate = rate * div; 132 - return rate; 131 + req->best_parent_rate = req->rate * div; 132 + return 0; 133 133 } 134 134 135 - return *prate / div; 135 + req->rate = req->best_parent_rate / div; 136 + return 0; 136 137 } 137 138 138 139 static unsigned long flexgen_recalc_rate(struct clk_hw *hw, ··· 198 197 .is_enabled = flexgen_is_enabled, 199 198 .get_parent = flexgen_get_parent, 200 199 .set_parent = flexgen_set_parent, 201 - .round_rate = flexgen_round_rate, 200 + .determine_rate = flexgen_determine_rate, 202 201 .recalc_rate = flexgen_recalc_rate, 203 202 .set_rate = flexgen_set_rate, 204 203 };