[PATCH v6 0/7] clk: add support for v1 / v2 clock rate negotiation and kunit tests

From: Brian Masney

Date: Fri Mar 13 2026 - 12:44:55 EST


The Common Clock Framework is expected to keep a clock’s rate stable
after setting a new rate with:

clk_set_rate(clk, NEW_RATE);

Clock consumers do not know about the clock hierarchy, sibling clocks,
or the type of clocks involved. However, several longstanding issues
affect how rate changes propagate through the clock tree when
CLK_SET_RATE_PARENT is involved, and the parent's clock rate is changed:

- A clock in some cases can unknowingly change a sibling clock's rate.

- No negotiation is done with the sibling clocks, so an inappropriate
or less than ideal parent rate can be selected.

A selection of some real world examples of where this shows up is at
[1]. DRM needs to run at precise clock rates, and this issue shows up
there, however will also show up in other subsystems that require
precise clock rates, such as sound.

This series introduces kunit tests to illustrate the current behavior in
the clk core. As discussed at Linux Plumbers Conference 2025 in Tokyo,
it was suggested to move the negotiation logic into the clk providers
themselves so that only the clks with this issue can have their rate
preserved, and add some common helpers to the clk core.

How to test on real hardware
============================

I am interested in getting feedback about testing this patch on real
hardware, particularly for scenarios where CLK_SET_RATE_PARENT needs
to be removed like this:
https://lore.kernel.org/all/20260303115550.9279-1-mitltlatltl@xxxxxxxxx/

1) First ensure that your board uses divider_determine_rate() or
divider_ro_determine_rate() from drivers/clk/clk-divider.c.

2) Boot the kernel with this patch set. There should be no change to the
existing behavior, and everything should still function as is.

3) Now boot the kernel with the parameter clk_v2_rate_negotiation.
Trigger the scenario where the clks get in a bad state, and it should
not occur with this series.

Changes since v5:
https://lore.kernel.org/r/20260306-clk-scaling-v5-0-d21b84ee6f27@xxxxxxxxxx
- Dropped all of the helpers, and complexity to the clk core. To solve
this problem, we don't need to chain rate requests together.
- Add more unit tests
- Convert clk-divider.c so that there's a real user of this new API.
- This series no longer has the problem where large numbers of boards are
moved over at once to the new v2 negotiation logic.

Changes since v4:
https://lore.kernel.org/linux-clk/20250923-clk-tests-docs-v4-0-9205cb3d3cba@xxxxxxxxxx/
- Reworked based on feedback at Linux Plumbers [2] as described in two
paragraphs above.
- Dropped gate and mux tests.

Changes since v3:
https://lore.kernel.org/r/20250812-clk-tests-docs-v3-0-054aed58dcd3@xxxxxxxxxx
- Update clk_core struct members (Maxime)
- Add v2 rate negotiation logic and additional kunit tests
- Drop clk_dummy_rate_mhz() in kunit tests; use HZ_PER_MHZ

[1] https://lore.kernel.org/lkml/20230825-pll-mipi_keep_rate-v1-0-35bc43570730@xxxxxxxxxxxx/
https://lore.kernel.org/linux-kernel/20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@xxxxxxxxxxxx/
https://lore.kernel.org/all/20241114065759.3341908-1-victor.liu@xxxxxxx/
https://lore.kernel.org/linux-clk/20241121-ge-ian-debug-imx8-clk-tree-v1-0-0f1b722588fe@xxxxxxxxxxx/

[2] Fixing Clock Tree Propagation in the Common Clk Framework
https://www.youtube.com/watch?v=R8TytDzlcFs
https://lpc.events/event/19/contributions/2152/

Link: https://lore.kernel.org/linux-clk/aUSWU7UymULCXOeF@xxxxxxxxxx/
Link: https://lpc.events/event/19/contributions/2152/
Signed-off-by: Brian Masney <bmasney@xxxxxxxxxx>
---
Brian Masney (7):
clk: test: introduce clk_dummy_div for a mock divider
clk: test: introduce test suite for sibling rate changes on a divider
clk: introduce new helper clk_hw_get_children_lcm() to calculate LCM of all child rates
clk: test: introduce additional test case showing sibling clock rate change
clk: introduce new flag CLK_V2_RATE_NEGOTIATION for sensitive clocks
clk: divider: enable optional support for v2 rate negotiation
clk: test: introduce additional test case showing v2 rate change + LCM parent

drivers/clk/clk-divider.c | 28 +++-
drivers/clk/clk.c | 118 +++++++++++++++--
drivers/clk/clk_test.c | 300 +++++++++++++++++++++++++++++++++++++++++++
include/linux/clk-provider.h | 5 +
4 files changed, 436 insertions(+), 15 deletions(-)
---
base-commit: 6a2abc8018be1ce9a03470ebb1c526f814903452
change-id: 20260305-clk-scaling-b3b63cae7624

Best regards,
--
Brian Masney <bmasney@xxxxxxxxxx>