Skip to content

Commit 06ed0fc

Browse files
mripardbebarino
authored andcommitted
clk: stm32: composite: Switch to determine_rate
The STM32 composite 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: Alexandre Torgue <alexandre.torgue@foss.st.com> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://lore.kernel.org/r/20221018-clk-range-checks-fixes-v4-63-971d5077e7d2@cerno.tech Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 36f8a30 commit 06ed0fc

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

drivers/clk/stm32/clk-stm32-core.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,15 @@ static unsigned long clk_stm32_composite_recalc_rate(struct clk_hw *hw,
426426
composite->div_id, parent_rate);
427427
}
428428

429-
static long clk_stm32_composite_round_rate(struct clk_hw *hw, unsigned long rate,
430-
unsigned long *prate)
429+
static int clk_stm32_composite_determine_rate(struct clk_hw *hw,
430+
struct clk_rate_request *req)
431431
{
432432
struct clk_stm32_composite *composite = to_clk_stm32_composite(hw);
433-
434433
const struct stm32_div_cfg *divider;
434+
unsigned long rate;
435435

436436
if (composite->div_id == NO_STM32_DIV)
437-
return rate;
437+
return 0;
438438

439439
divider = &composite->clock_data->dividers[composite->div_id];
440440

@@ -445,14 +445,24 @@ static long clk_stm32_composite_round_rate(struct clk_hw *hw, unsigned long rate
445445
val = readl(composite->base + divider->offset) >> divider->shift;
446446
val &= clk_div_mask(divider->width);
447447

448-
return divider_ro_round_rate(hw, rate, prate, divider->table,
449-
divider->width, divider->flags,
450-
val);
448+
rate = divider_ro_round_rate(hw, req->rate, &req->best_parent_rate,
449+
divider->table, divider->width, divider->flags,
450+
val);
451+
if (rate < 0)
452+
return rate;
453+
454+
req->rate = rate;
455+
return 0;
451456
}
452457

453-
return divider_round_rate_parent(hw, clk_hw_get_parent(hw),
454-
rate, prate, divider->table,
455-
divider->width, divider->flags);
458+
rate = divider_round_rate_parent(hw, clk_hw_get_parent(hw),
459+
req->rate, &req->best_parent_rate,
460+
divider->table, divider->width, divider->flags);
461+
if (rate < 0)
462+
return rate;
463+
464+
req->rate = rate;
465+
return 0;
456466
}
457467

458468
static u8 clk_stm32_composite_get_parent(struct clk_hw *hw)
@@ -602,7 +612,7 @@ static void clk_stm32_composite_disable_unused(struct clk_hw *hw)
602612
const struct clk_ops clk_stm32_composite_ops = {
603613
.set_rate = clk_stm32_composite_set_rate,
604614
.recalc_rate = clk_stm32_composite_recalc_rate,
605-
.round_rate = clk_stm32_composite_round_rate,
615+
.determine_rate = clk_stm32_composite_determine_rate,
606616
.get_parent = clk_stm32_composite_get_parent,
607617
.set_parent = clk_stm32_composite_set_parent,
608618
.enable = clk_stm32_composite_gate_enable,

0 commit comments

Comments
 (0)