* [PATCH] arm: mxc: utilise usecount field in clock operations
@ 2009-12-03 23:02 Amit Kucheria
0 siblings, 0 replies; 6+ messages in thread
From: Amit Kucheria @ 2009-12-03 23:02 UTC (permalink / raw)
To: linux-arm-kernel
This patch fixes the clock refcounting when reparenting is used.
Boot-tested on imx51 babbage board.
Sascha pointed out a good explanation of refcounting here:
http://www.spinics.net/lists/arm-kernel/msg85879.html
Signed-off-by: Amit Kucheria <amit.kucheria@canonical.com>
---
arch/arm/plat-mxc/clock.c | 37 +++++++++++++++++++++++++------------
1 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/arch/arm/plat-mxc/clock.c b/arch/arm/plat-mxc/clock.c
index 323ff8c..2ed3ab1 100644
--- a/arch/arm/plat-mxc/clock.c
+++ b/arch/arm/plat-mxc/clock.c
@@ -52,13 +52,14 @@ static void __clk_disable(struct clk *clk)
{
if (clk == NULL || IS_ERR(clk))
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 +67,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 +162,28 @@ EXPORT_SYMBOL(clk_set_rate);
int clk_set_parent(struct clk *clk, struct clk *parent)
{
int ret = -EINVAL;
+ struct clk *old;
if (clk == NULL || IS_ERR(clk) || parent == NULL ||
IS_ERR(parent) || clk->set_parent == NULL)
return ret;
+ if (clk->usecount)
+ clk_enable(parent);
+
mutex_lock(&clocks_mutex);
ret = clk->set_parent(clk, parent);
- if (ret == 0)
+ if (ret == 0) {
+ old = clk->parent;
clk->parent = parent;
+ } else {
+ old = parent;
+ }
mutex_unlock(&clocks_mutex);
+ if (clk->usecount)
+ clk_disable(old);
+
return ret;
}
EXPORT_SYMBOL(clk_set_parent);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] arm: mxc: utilise usecount field in clock operations
@ 2010-04-21 18:37 Amit Kucheria
2010-04-22 11:47 ` Baruch Siach
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Amit Kucheria @ 2010-04-21 18:37 UTC (permalink / raw)
To: linux-arm-kernel
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);
+ }
+
return ret;
}
EXPORT_SYMBOL(clk_set_parent);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] arm: mxc: utilise usecount field in clock operations
2010-04-21 18:37 [PATCH] arm: mxc: utilise usecount field in clock operations Amit Kucheria
@ 2010-04-22 11:47 ` Baruch Siach
2010-04-22 11:56 ` Sascha Hauer
2010-04-22 14:37 ` Uwe Kleine-König
2 siblings, 0 replies; 6+ messages in thread
From: Baruch Siach @ 2010-04-22 11:47 UTC (permalink / raw)
To: linux-arm-kernel
Hi Amit,
On Wed, Apr 21, 2010 at 09:37:31PM +0300, Amit Kucheria wrote:
> 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
[snip]
> @@ -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);
> + }
Unnecessary braces here. See chapter 3 of Documentation/CodingStyle.
> +
> mutex_lock(&clocks_mutex);
> ret = clk->set_parent(clk, parent);
> - if (ret == 0)
> + if (ret == 0) {
> clk->parent = parent;
> + }
Ditto
> mutex_unlock(&clocks_mutex);
>
> + if (clk->usecount != 0) {
> + clk_disable(prev_parent);
> + }
Ditto
> +
> return ret;
> }
> EXPORT_SYMBOL(clk_set_parent);
> --
baruch
--
~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] arm: mxc: utilise usecount field in clock operations
2010-04-21 18:37 [PATCH] arm: mxc: utilise usecount field in clock operations Amit Kucheria
2010-04-22 11:47 ` Baruch Siach
@ 2010-04-22 11:56 ` Sascha Hauer
2010-04-22 13:01 ` Amit Kucheria
2010-04-22 14:37 ` Uwe Kleine-König
2 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2010-04-22 11:56 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Apr 21, 2010 at 09:37:31PM +0300, Amit Kucheria wrote:
> clk->usecount can be used by platform code to check if a clock is active or
> not.
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
might help aswell.
>
> 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;
> + }
Please remove this hunk. It does not change anything except violating
the coding style. Also, please remove unnecessary braces.
> mutex_unlock(&clocks_mutex);
>
> + if (clk->usecount != 0) {
> + clk_disable(prev_parent);
> + }
> +
> return ret;
> }
> EXPORT_SYMBOL(clk_set_parent);
> --
> 1.7.0.4
>
>
--
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 |
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] arm: mxc: utilise usecount field in clock operations
2010-04-22 11:56 ` Sascha Hauer
@ 2010-04-22 13:01 ` Amit Kucheria
0 siblings, 0 replies; 6+ messages in thread
From: Amit Kucheria @ 2010-04-22 13:01 UTC (permalink / raw)
To: linux-arm-kernel
On 10 Apr 22, Sascha Hauer wrote:
> On Wed, Apr 21, 2010 at 09:37:31PM +0300, Amit Kucheria wrote:
> > clk->usecount can be used by platform code to check if a clock is active or
> > not.
>
> 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
>
> might help aswell.
Interesting. I had no idea about this work. I was just resurrecting old
patches from January.
Will fix and resend.
/Amit
> >
> > 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;
> > + }
>
> Please remove this hunk. It does not change anything except violating
> the coding style. Also, please remove unnecessary braces.
>
> > mutex_unlock(&clocks_mutex);
> >
> > + if (clk->usecount != 0) {
> > + clk_disable(prev_parent);
> > + }
> > +
> > return ret;
> > }
> > EXPORT_SYMBOL(clk_set_parent);
> > --
> > 1.7.0.4
> >
> >
>
> --
> 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 |
--
----------------------------------------------------------------------
Amit Kucheria, Kernel Engineer || amit.kucheria at canonical.com
----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] arm: mxc: utilise usecount field in clock operations
2010-04-21 18:37 [PATCH] arm: mxc: utilise usecount field in clock operations Amit Kucheria
2010-04-22 11:47 ` Baruch Siach
2010-04-22 11:56 ` Sascha Hauer
@ 2010-04-22 14:37 ` Uwe Kleine-König
2 siblings, 0 replies; 6+ messages in thread
From: Uwe Kleine-König @ 2010-04-22 14:37 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, Apr 21, 2010 at 09:37:31PM +0300, Amit Kucheria wrote:
> 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);
> + }
> }
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/ |
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-04-22 14:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-21 18:37 [PATCH] arm: mxc: utilise usecount field in clock operations Amit Kucheria
2010-04-22 11:47 ` Baruch Siach
2010-04-22 11:56 ` Sascha Hauer
2010-04-22 13:01 ` Amit Kucheria
2010-04-22 14:37 ` Uwe Kleine-König
-- strict thread matches above, loose matches on Subject: below --
2009-12-03 23:02 Amit Kucheria
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).