From: Michael Trimarchi <michael@amarulasolutions.com>
In Linux, CLK_OPS_PARENT_ENABLE marks the clocks whose parents must be
running while they are reparented or their rate is changed, such as the
i.MX8M composite clocks, and CLK_SET_RATE_UNGATE the clocks which must
be enabled while their rate is changed.
Support both flags in clk_set_rate() and clk_set_parent(), reading them
from the private clock like the other CCF flags.
Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
(no changes since v2)
Changes in v2:
- Rebase on top of the parent enabling now done by clk_set_parent()
- Read the flags from the private clock
- Add CLK_SET_RATE_UNGATE support
- Treat an error pointer returned by clk_get_parent() as no parent
- Reword subject and commit message
drivers/clk/clk-uclass.c | 49 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
@@ -598,7 +598,9 @@ static void clk_clean_rate_cache(struct clk *clk)
ulong clk_set_rate(struct clk *clk, ulong rate)
{
const struct clk_ops *ops;
+ struct clk *pclk = NULL;
struct clk *clkp;
+ ulong ret;
debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
if (!clk_valid(clk))
@@ -625,13 +627,42 @@ ulong clk_set_rate(struct clk *clk, ulong rate)
/* Clean up cached rates for us and all child clocks */
clk_clean_rate_cache(clkp);
- return ops->set_rate(clk, rate);
+ if (clkp->flags & CLK_SET_RATE_UNGATE) {
+ ret = clk_enable(clk);
+ if (ret)
+ return ret;
+ }
+
+ if (clkp->flags & CLK_OPS_PARENT_ENABLE) {
+ pclk = clk_get_parent(clk);
+ if (IS_ERR(pclk))
+ pclk = NULL;
+
+ if (pclk) {
+ ret = clk_enable(pclk);
+ if (ret)
+ goto out;
+ }
+ }
+
+ ret = ops->set_rate(clk, rate);
+
+ if (pclk)
+ clk_disable(pclk);
+
+out:
+ if (clkp->flags & CLK_SET_RATE_UNGATE)
+ clk_disable(clk);
+
+ return ret;
}
int clk_set_parent(struct clk *clk, struct clk *parent)
{
const struct clk_ops *ops;
struct clk *old_parent = NULL;
+ struct clk *clkp;
+ bool parents_enable;
int ret;
debug("%s(clk=%p, parent=%p)\n", __func__, clk, parent);
@@ -642,6 +673,9 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
if (!ops->set_parent)
return -ENOSYS;
+ clk_get_priv(clk, &clkp);
+ parents_enable = clkp->flags & CLK_OPS_PARENT_ENABLE;
+
if (CONFIG_IS_ENABLED(CLK_CCF)) {
old_parent = clk_get_parent(clk);
if (IS_ERR(old_parent))
@@ -656,10 +690,23 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
}
}
+ /* Both the old and the new parent must be running while switching */
+ if (parents_enable) {
+ if (old_parent)
+ clk_enable(old_parent);
+ clk_enable(parent);
+ }
+
ret = ops->set_parent(clk, parent);
if (!ret && CONFIG_IS_ENABLED(CLK_CCF))
ret = device_reparent(clk->dev, parent->dev);
+ if (parents_enable) {
+ clk_disable(parent);
+ if (old_parent)
+ clk_disable(old_parent);
+ }
+
if (ret) {
if (clk->enable_count)
clk_disable(parent);