Skip to content

Commit fa0dadd

Browse files
mripardbebarino
authored andcommitted
clk: ingenic: cgu: Switch to determine_rate
The Ingenic CGU 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. Cc: Paul Cercueil <paul@crapouillou.net> Cc: linux-mips@vger.kernel.org Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-59-971d5077e7d2@cerno.tech Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 15d3f36 commit fa0dadd

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/clk/ingenic/cgu.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,22 +491,23 @@ ingenic_clk_calc_div(struct clk_hw *hw,
491491
return div;
492492
}
493493

494-
static long
495-
ingenic_clk_round_rate(struct clk_hw *hw, unsigned long req_rate,
496-
unsigned long *parent_rate)
494+
static int ingenic_clk_determine_rate(struct clk_hw *hw,
495+
struct clk_rate_request *req)
497496
{
498497
struct ingenic_clk *ingenic_clk = to_ingenic_clk(hw);
499498
const struct ingenic_cgu_clk_info *clk_info = to_clk_info(ingenic_clk);
500499
unsigned int div = 1;
501500

502501
if (clk_info->type & CGU_CLK_DIV)
503-
div = ingenic_clk_calc_div(hw, clk_info, *parent_rate, req_rate);
502+
div = ingenic_clk_calc_div(hw, clk_info, req->best_parent_rate,
503+
req->rate);
504504
else if (clk_info->type & CGU_CLK_FIXDIV)
505505
div = clk_info->fixdiv.div;
506506
else if (clk_hw_can_set_rate_parent(hw))
507-
*parent_rate = req_rate;
507+
req->best_parent_rate = req->rate;
508508

509-
return DIV_ROUND_UP(*parent_rate, div);
509+
req->rate = DIV_ROUND_UP(req->best_parent_rate, div);
510+
return 0;
510511
}
511512

512513
static inline int ingenic_clk_check_stable(struct ingenic_cgu *cgu,
@@ -626,7 +627,7 @@ static const struct clk_ops ingenic_clk_ops = {
626627
.set_parent = ingenic_clk_set_parent,
627628

628629
.recalc_rate = ingenic_clk_recalc_rate,
629-
.round_rate = ingenic_clk_round_rate,
630+
.determine_rate = ingenic_clk_determine_rate,
630631
.set_rate = ingenic_clk_set_rate,
631632

632633
.enable = ingenic_clk_enable,

0 commit comments

Comments
 (0)