public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm: at91: do not disable/enable clocks in a row
@ 2016-03-29 13:26 Sebastian Andrzej Siewior
  2016-03-29 13:32 ` Nicolas Ferre
  2016-03-30 18:06 ` Daniel Lezcano
  0 siblings, 2 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2016-03-29 13:26 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Daniel Lezcano, Thomas Gleixner, linux-arm-kernel, linux-kernel,
	Sebastian Andrzej Siewior

Currently the driver will disable the clock and enable it one line later
if it is switching from periodic mode into one shot.
This can be avoided and causes a needless warning on -RT.

Tested-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 drivers/clocksource/tcb_clksrc.c | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c
index 4da2af9694a2..ed1ae4445e8d 100644
--- a/drivers/clocksource/tcb_clksrc.c
+++ b/drivers/clocksource/tcb_clksrc.c
@@ -74,6 +74,7 @@ static struct clocksource clksrc = {
 struct tc_clkevt_device {
 	struct clock_event_device	clkevt;
 	struct clk			*clk;
+	bool				clk_enabled;
 	void __iomem			*regs;
 };
 
@@ -91,6 +92,24 @@ static struct tc_clkevt_device *to_tc_clkevt(struct clock_event_device *clkevt)
  */
 static u32 timer_clock;
 
+static void tc_clk_disable(struct clock_event_device *d)
+{
+	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
+
+	clk_disable(tcd->clk);
+	tcd->clk_enabled = false;
+}
+
+static void tc_clk_enable(struct clock_event_device *d)
+{
+	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
+
+	if (tcd->clk_enabled)
+		return;
+	clk_enable(tcd->clk);
+	tcd->clk_enabled = true;
+}
+
 static int tc_shutdown(struct clock_event_device *d)
 {
 	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
@@ -98,8 +117,14 @@ static int tc_shutdown(struct clock_event_device *d)
 
 	__raw_writel(0xff, regs + ATMEL_TC_REG(2, IDR));
 	__raw_writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR));
+	return 0;
+}
+
+static int tc_shutdown_clk_off(struct clock_event_device *d)
+{
+	tc_shutdown(d);
 	if (!clockevent_state_detached(d))
-		clk_disable(tcd->clk);
+		tc_clk_disable(d);
 
 	return 0;
 }
@@ -112,7 +137,7 @@ static int tc_set_oneshot(struct clock_event_device *d)
 	if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
 		tc_shutdown(d);
 
-	clk_enable(tcd->clk);
+	tc_clk_enable(d);
 
 	/* slow clock, count up to RC, then irq and stop */
 	__raw_writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE |
@@ -134,7 +159,7 @@ static int tc_set_periodic(struct clock_event_device *d)
 	/* By not making the gentime core emulate periodic mode on top
 	 * of oneshot, we get lower overhead and improved accuracy.
 	 */
-	clk_enable(tcd->clk);
+	tc_clk_enable(d);
 
 	/* slow clock, count up to RC, then irq and restart */
 	__raw_writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
@@ -168,7 +193,7 @@ static struct tc_clkevt_device clkevt = {
 		/* Should be lower than at91rm9200's system timer */
 		.rating			= 125,
 		.set_next_event		= tc_next_event,
-		.set_state_shutdown	= tc_shutdown,
+		.set_state_shutdown	= tc_shutdown_clk_off,
 		.set_state_periodic	= tc_set_periodic,
 		.set_state_oneshot	= tc_set_oneshot,
 	},
-- 
2.8.0.rc3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm: at91: do not disable/enable clocks in a row
  2016-03-29 13:26 [PATCH] arm: at91: do not disable/enable clocks in a row Sebastian Andrzej Siewior
@ 2016-03-29 13:32 ` Nicolas Ferre
  2016-03-30 18:06 ` Daniel Lezcano
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolas Ferre @ 2016-03-29 13:32 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, Daniel Lezcano
  Cc: Thomas Gleixner, linux-arm-kernel, linux-kernel

Le 29/03/2016 15:26, Sebastian Andrzej Siewior a écrit :
> Currently the driver will disable the clock and enable it one line later
> if it is switching from periodic mode into one shot.
> This can be avoided and causes a needless warning on -RT.
> 
> Tested-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Absolutely makes sense:
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

Thanks.

> ---
>  drivers/clocksource/tcb_clksrc.c | 33 +++++++++++++++++++++++++++++----
>  1 file changed, 29 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c
> index 4da2af9694a2..ed1ae4445e8d 100644
> --- a/drivers/clocksource/tcb_clksrc.c
> +++ b/drivers/clocksource/tcb_clksrc.c
> @@ -74,6 +74,7 @@ static struct clocksource clksrc = {
>  struct tc_clkevt_device {
>  	struct clock_event_device	clkevt;
>  	struct clk			*clk;
> +	bool				clk_enabled;
>  	void __iomem			*regs;
>  };
>  
> @@ -91,6 +92,24 @@ static struct tc_clkevt_device *to_tc_clkevt(struct clock_event_device *clkevt)
>   */
>  static u32 timer_clock;
>  
> +static void tc_clk_disable(struct clock_event_device *d)
> +{
> +	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
> +
> +	clk_disable(tcd->clk);
> +	tcd->clk_enabled = false;
> +}
> +
> +static void tc_clk_enable(struct clock_event_device *d)
> +{
> +	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
> +
> +	if (tcd->clk_enabled)
> +		return;
> +	clk_enable(tcd->clk);
> +	tcd->clk_enabled = true;
> +}
> +
>  static int tc_shutdown(struct clock_event_device *d)
>  {
>  	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
> @@ -98,8 +117,14 @@ static int tc_shutdown(struct clock_event_device *d)
>  
>  	__raw_writel(0xff, regs + ATMEL_TC_REG(2, IDR));
>  	__raw_writel(ATMEL_TC_CLKDIS, regs + ATMEL_TC_REG(2, CCR));
> +	return 0;
> +}
> +
> +static int tc_shutdown_clk_off(struct clock_event_device *d)
> +{
> +	tc_shutdown(d);
>  	if (!clockevent_state_detached(d))
> -		clk_disable(tcd->clk);
> +		tc_clk_disable(d);
>  
>  	return 0;
>  }
> @@ -112,7 +137,7 @@ static int tc_set_oneshot(struct clock_event_device *d)
>  	if (clockevent_state_oneshot(d) || clockevent_state_periodic(d))
>  		tc_shutdown(d);
>  
> -	clk_enable(tcd->clk);
> +	tc_clk_enable(d);
>  
>  	/* slow clock, count up to RC, then irq and stop */
>  	__raw_writel(timer_clock | ATMEL_TC_CPCSTOP | ATMEL_TC_WAVE |
> @@ -134,7 +159,7 @@ static int tc_set_periodic(struct clock_event_device *d)
>  	/* By not making the gentime core emulate periodic mode on top
>  	 * of oneshot, we get lower overhead and improved accuracy.
>  	 */
> -	clk_enable(tcd->clk);
> +	tc_clk_enable(d);
>  
>  	/* slow clock, count up to RC, then irq and restart */
>  	__raw_writel(timer_clock | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
> @@ -168,7 +193,7 @@ static struct tc_clkevt_device clkevt = {
>  		/* Should be lower than at91rm9200's system timer */
>  		.rating			= 125,
>  		.set_next_event		= tc_next_event,
> -		.set_state_shutdown	= tc_shutdown,
> +		.set_state_shutdown	= tc_shutdown_clk_off,
>  		.set_state_periodic	= tc_set_periodic,
>  		.set_state_oneshot	= tc_set_oneshot,
>  	},
> 


-- 
Nicolas Ferre

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] arm: at91: do not disable/enable clocks in a row
  2016-03-29 13:26 [PATCH] arm: at91: do not disable/enable clocks in a row Sebastian Andrzej Siewior
  2016-03-29 13:32 ` Nicolas Ferre
@ 2016-03-30 18:06 ` Daniel Lezcano
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2016-03-30 18:06 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, Nicolas Ferre
  Cc: Thomas Gleixner, linux-arm-kernel, linux-kernel

On 03/29/2016 03:26 PM, Sebastian Andrzej Siewior wrote:
> Currently the driver will disable the clock and enable it one line later
> if it is switching from periodic mode into one shot.
> This can be avoided and causes a needless warning on -RT.

I don't see the connection between the description and the content of 
the patch.

It can be avoided by not disabling the clock when going to periodic / 
oneshot.

The function below suggest clk_enable() is called twice, is that the 
real issue ?

> Tested-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
>   drivers/clocksource/tcb_clksrc.c | 33 +++++++++++++++++++++++++++++----
>   1 file changed, 29 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c
> index 4da2af9694a2..ed1ae4445e8d 100644
> --- a/drivers/clocksource/tcb_clksrc.c
> +++ b/drivers/clocksource/tcb_clksrc.c
> @@ -74,6 +74,7 @@ static struct clocksource clksrc = {
>   struct tc_clkevt_device {
>   	struct clock_event_device	clkevt;
>   	struct clk			*clk;
> +	bool				clk_enabled;
>   	void __iomem			*regs;
>   };
>
> @@ -91,6 +92,24 @@ static struct tc_clkevt_device *to_tc_clkevt(struct clock_event_device *clkevt)
>    */
>   static u32 timer_clock;
>
> +static void tc_clk_disable(struct clock_event_device *d)
> +{
> +	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
> +
> +	clk_disable(tcd->clk);
> +	tcd->clk_enabled = false;
> +}
> +
> +static void tc_clk_enable(struct clock_event_device *d)
> +{
> +	struct tc_clkevt_device *tcd = to_tc_clkevt(d);
> +
> +	if (tcd->clk_enabled)
> +		return;
> +	clk_enable(tcd->clk);
> +	tcd->clk_enabled = true;
> +}

This function.


-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-30 18:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-29 13:26 [PATCH] arm: at91: do not disable/enable clocks in a row Sebastian Andrzej Siewior
2016-03-29 13:32 ` Nicolas Ferre
2016-03-30 18:06 ` Daniel Lezcano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox