Skip to contentSkip to conversation

clk: use get_phase() if available

PATCH In review Jerome Brunet 1 participant 2 messages Feb 15, 2018 Common clk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: use get_phase() if available

When the get_phase() callback is available, we should use it instead of just relying the values cached, and assumed un-rounded, by the framework

---

Hi Mike, Stephen,

This changes applies on top of the phase fix I've sent [0]

[0]: https://lkml.kernel.org/r/[email protected]

 drivers/clk/clk.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/clk/clk.c +22 -3
index b33d362239e7..bcd6ec980903 100644
@@ -2297,6 +2297,21 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
 }
 EXPORT_SYMBOL_GPL(clk_set_parent);
 
+static int clk_core_get_phase_nolock(struct clk_core *core)
+{
+	int ret;
+
+	if (!core->ops->get_phase)
+		return core->phase;
+
+	/* Update the phase if the callback is available */
+	ret = core->ops->get_phase(core->hw);
+	if (ret >= 0)
+		core->phase = ret;
+
+	return ret;
+}
+
 static int clk_core_set_phase_nolock(struct clk_core *core, int degrees)
 {
 	int ret = -EINVAL;
@@ -2314,12 +2329,16 @@ static int clk_core_set_phase_nolock(struct clk_core *core, int degrees)
 	if (core->ops->set_phase)
 		ret = core->ops->set_phase(core->hw, degrees);
 
-	if (!ret)
+	if (!ret) {
 		core->phase = degrees;
 
+		/* Read back the phase in case it got rounded */
+		ret = clk_core_get_phase_nolock(core);
+	}
+
 	trace_clk_set_phase_complete(core, degrees);
 
-	return ret;
+	return ret > 0 ? 0 : ret;
 }
 
 /**
@@ -2375,7 +2394,7 @@ static int clk_core_get_phase(struct clk_core *core)
 	int ret;
 
 	clk_prepare_lock();
-	ret = core->phase;
+	ret = clk_core_get_phase_nolock(core);
 	clk_prepare_unlock();
 
 	return ret;
Signature · 1 line
2.14.3
#1 lore raw
Quoted 21 lines · Jerome Brunet

When the get_phase() callback is available, we should use it instead of just relying the values cached, and assumed un-rounded, by the framework

---

Hi Mike, Stephen,

This changes applies on top of the phase fix I've sent [0]

[0]: https://lkml.kernel.org/r/[email protected]

 drivers/clk/clk.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/clk/clk.c +0 -0
index b33d362239e7..bcd6ec980903 100644

drivers/clk/clk.c int clk_set_parent(struct clk *clk, struct clk *parent) · line 2302

Quoted 6 lines
drivers/clk/clk.c +3 -0
@@ -2297,6 +2297,21 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
 }
 EXPORT_SYMBOL_GPL(clk_set_parent);
 
+static int clk_core_get_phase_nolock(struct clk_core *core)
+{
+	int ret;

+ if (!core)
+ return 0;

Forgot this, will add it the v2

Quoted 43 lines
drivers/clk/clk.c +19 -3
+
+	if (!core->ops->get_phase)
+		return core->phase;
+
+	/* Update the phase if the callback is available */
+	ret = core->ops->get_phase(core->hw);
+	if (ret >= 0)
+		core->phase = ret;
+
+	return ret;
+}
+
 static int clk_core_set_phase_nolock(struct clk_core *core, int degrees)
 {
 	int ret = -EINVAL;
@@ -2314,12 +2329,16 @@ static int clk_core_set_phase_nolock(struct clk_core *core, int degrees)
 	if (core->ops->set_phase)
 		ret = core->ops->set_phase(core->hw, degrees);
 
-	if (!ret)
+	if (!ret) {
 		core->phase = degrees;
 
+		/* Read back the phase in case it got rounded */
+		ret = clk_core_get_phase_nolock(core);
+	}
+
 	trace_clk_set_phase_complete(core, degrees);
 
-	return ret;
+	return ret > 0 ? 0 : ret;
 }
 
 /**
@@ -2375,7 +2394,7 @@ static int clk_core_get_phase(struct clk_core *core)
 	int ret;
 
 	clk_prepare_lock();
-	ret = core->phase;
+	ret = clk_core_get_phase_nolock(core);
 	clk_prepare_unlock();
 
 	return ret;