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

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>

authored by

Maxime Ripard and committed by
Stephen Boyd
06ed0fc0 36f8a30c

+21 -11
+21 -11
drivers/clk/stm32/clk-stm32-core.c
··· 426 426 composite->div_id, parent_rate); 427 427 } 428 428 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) 431 431 { 432 432 struct clk_stm32_composite *composite = to_clk_stm32_composite(hw); 433 - 434 433 const struct stm32_div_cfg *divider; 434 + unsigned long rate; 435 435 436 436 if (composite->div_id == NO_STM32_DIV) 437 - return rate; 437 + return 0; 438 438 439 439 divider = &composite->clock_data->dividers[composite->div_id]; 440 440 ··· 445 445 val = readl(composite->base + divider->offset) >> divider->shift; 446 446 val &= clk_div_mask(divider->width); 447 447 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; 451 456 } 452 457 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; 456 466 } 457 467 458 468 static u8 clk_stm32_composite_get_parent(struct clk_hw *hw) ··· 612 602 const struct clk_ops clk_stm32_composite_ops = { 613 603 .set_rate = clk_stm32_composite_set_rate, 614 604 .recalc_rate = clk_stm32_composite_recalc_rate, 615 - .round_rate = clk_stm32_composite_round_rate, 605 + .determine_rate = clk_stm32_composite_determine_rate, 616 606 .get_parent = clk_stm32_composite_get_parent, 617 607 .set_parent = clk_stm32_composite_set_parent, 618 608 .enable = clk_stm32_composite_gate_enable,