Re: [PATCH] arm: mxc: utilise usecount field in clock operations

Previous thread: [PATCH] mxc: Change gpt timer code to be more generic by using V2 instead of MX3 by Amit Kucheria on Wednesday, April 21, 2010 - 11:34 am. (2 messages)

Next thread: [PATCH] i2c-algo-pca: fix all coding style issues in i2c-algo-pca.c by Farid Hammane on Wednesday, April 21, 2010 - 12:11 pm. (6 messages)
From: Amit Kucheria
Date: Wednesday, April 21, 2010 - 11:37 am

clk->usecount can be used by platform code to check if a clock is active or
not.

Signed-off-by: Amit Kucheria <amit.kucheria@canonical.com>
---
 arch/arm/plat-mxc/clock.c |   37 ++++++++++++++++++++++++-------------
 1 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/arch/arm/plat-mxc/clock.c b/arch/arm/plat-mxc/clock.c
index 323ff8c..c791f38 100644
--- a/arch/arm/plat-mxc/clock.c
+++ b/arch/arm/plat-mxc/clock.c
@@ -50,15 +50,15 @@ static DEFINE_MUTEX(clocks_mutex);
 
 static void __clk_disable(struct clk *clk)
 {
-	if (clk == NULL || IS_ERR(clk))
+	if (clk == NULL || IS_ERR(clk) || !clk->usecount)
 		return;
 
-	__clk_disable(clk->parent);
-	__clk_disable(clk->secondary);
-
-	WARN_ON(!clk->usecount);
-	if (!(--clk->usecount) && clk->disable)
-		clk->disable(clk);
+	if (!(--clk->usecount)) {
+		if (clk->disable)
+			clk->disable(clk);
+		__clk_disable(clk->parent);
+		__clk_disable(clk->secondary);
+	}
 }
 
 static int __clk_enable(struct clk *clk)
@@ -66,12 +66,13 @@ static int __clk_enable(struct clk *clk)
 	if (clk == NULL || IS_ERR(clk))
 		return -EINVAL;
 
-	__clk_enable(clk->parent);
-	__clk_enable(clk->secondary);
-
-	if (clk->usecount++ == 0 && clk->enable)
-		clk->enable(clk);
+	if (clk->usecount++ == 0) {
+		__clk_enable(clk->parent);
+		__clk_enable(clk->secondary);
 
+		if (clk->enable)
+			clk->enable(clk);
+	}
 	return 0;
 }
 
@@ -160,17 +161,27 @@ EXPORT_SYMBOL(clk_set_rate);
 int clk_set_parent(struct clk *clk, struct clk *parent)
 {
 	int ret = -EINVAL;
+	struct clk *prev_parent = clk->parent;
 
 	if (clk == NULL || IS_ERR(clk) || parent == NULL ||
 	    IS_ERR(parent) || clk->set_parent == NULL)
 		return ret;
 
+	if (clk->usecount != 0) {
+		clk_enable(parent);
+	}
+
 	mutex_lock(&clocks_mutex);
 	ret = clk->set_parent(clk, parent);
-	if (ret == 0)
+	if (ret == 0) {
 		clk->parent = parent;
+	}
 	mutex_unlock(&clocks_mutex);
 
+	if (clk->usecount != 0) {
+		clk_disable(prev_parent);
+	}
+
 ...
From: Baruch Siach
Date: Thursday, April 22, 2010 - 4:47 am

Hi Amit,






baruch

-- 
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
--

From: Sascha Hauer
Date: Thursday, April 22, 2010 - 4:56 am

The patch seems mostly fine but the commit log not. How about something like
'This patch fixes the clock refcounting when reparenting is used.'

A reference to

http://www.spinics.net/lists/arm-kernel/msg85879.html


Please remove this hunk. It does not change anything except violating

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
--

From: Amit Kucheria
Date: Thursday, April 22, 2010 - 6:01 am

Interesting. I had no idea about this work. I was just resurrecting old
patches from January.

Will fix and resend.


-- 
----------------------------------------------------------------------
Amit Kucheria, Kernel Engineer || amit.kucheria@canonical.com
----------------------------------------------------------------------
--

From: Uwe Kleine-König
Date: Thursday, April 22, 2010 - 7:37 am

This removes the WARN_ON if the clock is already off.  Is this intended?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
--

Previous thread: [PATCH] mxc: Change gpt timer code to be more generic by using V2 instead of MX3 by Amit Kucheria on Wednesday, April 21, 2010 - 11:34 am. (2 messages)

Next thread: [PATCH] i2c-algo-pca: fix all coding style issues in i2c-algo-pca.c by Farid Hammane on Wednesday, April 21, 2010 - 12:11 pm. (6 messages)