mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/9] clk: Keep enable count consistent over reparent
Date: Mon,  6 Feb 2017 07:50:49 +0100	[thread overview]
Message-ID: <20170206065057.19483-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170206065057.19483-1-s.hauer@pengutronix.de>

When reparenting a clock we have to make sure the new parent is enabled
when the clock was enabled on the old parent. Also we have to decrease
the old parents use counter when the clock was enabled.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/clk/clk.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 1566beabd..6f3053727 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -173,14 +173,15 @@ struct clk *clk_lookup(const char *name)
 	return ERR_PTR(-ENODEV);
 }
 
-int clk_set_parent(struct clk *clk, struct clk *parent)
+int clk_set_parent(struct clk *clk, struct clk *newparent)
 {
-	int i;
+	int i, ret;
+	struct clk *curparent = clk_get_parent(clk);
 
 	if (IS_ERR(clk))
 		return PTR_ERR(clk);
-	if (IS_ERR(parent))
-		return PTR_ERR(parent);
+	if (IS_ERR(newparent))
+		return PTR_ERR(newparent);
 
 	if (!clk->num_parents)
 		return -EINVAL;
@@ -192,14 +193,22 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
 			clk->parents[i] = clk_lookup(clk->parent_names[i]);
 
 		if (!IS_ERR_OR_NULL(clk->parents[i]))
-			if (clk->parents[i] == parent)
+			if (clk->parents[i] == newparent)
 				break;
 	}
 
 	if (i == clk->num_parents)
 		return -EINVAL;
 
-	return clk->ops->set_parent(clk, i);
+	if (clk->enable_count)
+		clk_enable(newparent);
+
+	ret = clk->ops->set_parent(clk, i);
+
+	if (clk->enable_count)
+		clk_disable(curparent);
+
+	return ret;
 }
 
 struct clk *clk_get_parent(struct clk *clk)
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2017-02-06  6:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-06  6:50 i.MX7 Ethernet clock fixes Sascha Hauer
2017-02-06  6:50 ` Sascha Hauer [this message]
2017-02-06  6:50 ` [PATCH 2/9] clk: implement CLK_OPS_PARENT_ENABLE Sascha Hauer
2017-02-06  6:50 ` [PATCH 3/9] clk: i.MX: clk-gate2: Allow to pass flags Sascha Hauer
2017-02-06  6:50 ` [PATCH 4/9] clk: i.MX: Pass CLK_OPS_PARENT_ENABLE where necessary Sascha Hauer
2017-02-06  6:50 ` [PATCH 5/9] clk: i.MX7: do clock reparenting when all clocks are initialized Sascha Hauer
2017-02-06  6:50 ` [PATCH 6/9] clk: Add support for shared gates Sascha Hauer
2017-02-06  6:50 ` [PATCH 7/9] clk: i.MX7: Fix ethernet clocks Sascha Hauer
2017-02-06  6:50 ` [PATCH 8/9] clk: i.MX7: do not register PLL bypass clocks as separate clocks Sascha Hauer
2017-02-06  6:50 ` [PATCH 9/9] clk: i.MX7: setup ethernet clocks Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170206065057.19483-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox