Linux clock framework development
 help / color / mirror / Atom feed
* [PATCH] clk: Don't show the incorrect clock phase
@ 2018-03-08  7:54 Shawn Lin
  2018-03-08  9:40 ` Geert Uytterhoeven
  2018-03-08 10:04 ` Jerome Brunet
  0 siblings, 2 replies; 10+ messages in thread
From: Shawn Lin @ 2018-03-08  7:54 UTC (permalink / raw)
  To: Heiko Stuebner, Michael Turquette, Stephen Boyd; +Cc: linux-clk, Shawn Lin

It's found that the clock phase output from clk_summary is
wrong compared to the actual phase reading from the register.

cat /sys/kernel/debug/clk/clk_summary | grep sdio_sample
sdio_sample     0        1        0 50000000          0 -22

It expose an issue that clk core, clk_core_get_phase, always
return the cached core->phase which should be either updated
by calling clk_set_phase or directly from the first place the
clk was registered. When registering the clk, the core->phase
geting from ->get_phase() may return negative value indicating
error. This is quite common since the clk's phase may be highly
related to its praent chain, but it was temporary orphan when
registered, since its parent chain hadn't be ready at that time,
so the clk drivers decide to return error in this case. However,
if no clk_set_phase is called, core->phase would never be updated.
This is wrong, and we should try to update it when all its parent
chain is settled down, like the way of updating clock rate for that.
It's not derserved to complicate the code but just update it if
seeing it's a nagative number when calling clk_core_get_phase, which
would be much simple and enough.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
---

 drivers/clk/clk.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 0f686a9..b49e4c8 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2370,6 +2370,15 @@ static int clk_core_get_phase(struct clk_core *core)
 	int ret;
 
 	clk_prepare_lock();
+	/*
+	 * clk_set_phase always set the phase in [0, 360],
+	 * so the only reason for core->phase to be nagative
+	 * number is it's a error number propagated back from
+	 * the clk drivers. So we should try to update it if
+	 * possible.
+	 */
+	if (core->phase < 0 && core->ops->get_phase)
+		core->phase = core->ops->get_phase(core->hw);
 	ret = core->phase;
 	clk_prepare_unlock();
 
-- 
1.9.1

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

end of thread, other threads:[~2018-03-08 12:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-08  7:54 [PATCH] clk: Don't show the incorrect clock phase Shawn Lin
2018-03-08  9:40 ` Geert Uytterhoeven
2018-03-08 11:15   ` Shawn Lin
2018-03-08 10:04 ` Jerome Brunet
2018-03-08 11:28   ` Shawn Lin
2018-03-08 11:37     ` Jerome Brunet
2018-03-08 11:39       ` Jerome Brunet
2018-03-08 11:46         ` Shawn Lin
2018-03-08 12:03           ` Jerome Brunet
2018-03-08 12:11             ` Shawn Lin

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