public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] clk: set initial best mux parent to current parent with CLK_MUX_ROUND_CLOSEST
@ 2024-03-07  2:03 Yang Xiwen via B4 Relay
  2024-03-07  8:48 ` Maxime Ripard
  0 siblings, 1 reply; 7+ messages in thread
From: Yang Xiwen via B4 Relay @ 2024-03-07  2:03 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd
  Cc: Maxime Ripard, linux-clk, linux-kernel, Yang Xiwen

From: Yang Xiwen <forbidden405@outlook.com>

Originally, the initial clock rate is hardcoded to 0, this can lead to
some problem when setting a very small rate with CLK_MUX_ROUND_CLOSEST.

For example, if the lowest possible rate provided by the mux is 1000Hz,
setting a rate below 500Hz will fail, because no clock can provide a
better rate than the non-existant 0Hz. But it should succeed with 1000Hz
being set.

Setting the initial best parent to current parent could solve this bug.

Signed-off-by: Yang Xiwen <forbidden405@outlook.com>
---
This is actually a v2 of [1]. It's tested in a mmc host driver.

[1]: https://lore.kernel.org/linux-clk/20230421-clk-v3-1-9ff79e7e7fed@outlook.com/
---
Changes in v3:
- remove the fix for clk_test.c
- limit the fix to CLK_MUX_ROUND_CLOSEST
- Link to v2: https://lore.kernel.org/r/20240306-mux-v2-0-92a5fa461fd2@outlook.com

Changes in v2:
- cover letter: remove statements about unittest
- add fix for clk_test.c
- s/privide/provide
- Cc Maxime
All suggested by Stephan Boyd
- Link to v1: https://lore.kernel.org/r/20240215-mux-v1-1-ebb2fba31d49@outlook.com
---
 drivers/clk/clk.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 2253c154a824..74dd61f7269f 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -647,6 +647,12 @@ int clk_mux_determine_rate_flags(struct clk_hw *hw,
 	if (core->flags & CLK_SET_RATE_NO_REPARENT)
 		return clk_core_determine_rate_no_reparent(hw, req);
 
+	/* if MUX_ROUND_CLOSEST is set, set the initial best parent to current parent */
+	if (flags & CLK_MUX_ROUND_CLOSEST) {
+		best_parent = core->parent;
+		best = clk_core_get_rate_nolock(core);
+	}
+
 	/* find the parent that can provide the fastest rate <= rate */
 	num_parents = core->num_parents;
 	for (i = 0; i < num_parents; i++) {

---
base-commit: 90d35da658da8cff0d4ecbb5113f5fac9d00eb72
change-id: 20240215-mux-6db8b3714590

Best regards,
-- 
Yang Xiwen <forbidden405@outlook.com>


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-11  3:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-07  2:03 [PATCH v3] clk: set initial best mux parent to current parent with CLK_MUX_ROUND_CLOSEST Yang Xiwen via B4 Relay
2024-03-07  8:48 ` Maxime Ripard
2024-03-07 11:18   ` Yang Xiwen
2024-03-11  9:34     ` Maxime Ripard
2024-03-12  8:52       ` Yang Xiwen
2024-03-12 10:14         ` Maxime Ripard
2024-04-11  3:07         ` Sean Anderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox