linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] clocksource: timer-atmel-pit: driver fix and cleanups
@ 2016-08-08 13:33 Alexandre Belloni
  2016-08-08 13:33 ` [PATCH v2 1/4] clocksource: timer-atmel-pit: enable mck Alexandre Belloni
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Alexandre Belloni @ 2016-08-08 13:33 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

The first patch in the series is a fix that will be needed starting v4.9. The
remaining patches are cleanups.

Changes in v2:
 - Rebased on v4.8-rc1
 - Collected acks

Alexandre Belloni (4):
  clocksource: timer-atmel-pit: enable mck
  clocksource: timer-atmel-pit: drop at91sam926x_pit_common_init
  clocksource: timer-atmel-pit: remove uselesss WARN_ON_ONCE
  clocksource: timer-atmel-pit: simplify IRQ handler

 drivers/clocksource/timer-atmel-pit.c | 78 +++++++++++++----------------------
 1 file changed, 29 insertions(+), 49 deletions(-)

-- 
2.8.1

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

* [PATCH v2 1/4] clocksource: timer-atmel-pit: enable mck
  2016-08-08 13:33 [PATCH v2 0/4] clocksource: timer-atmel-pit: driver fix and cleanups Alexandre Belloni
@ 2016-08-08 13:33 ` Alexandre Belloni
  2016-08-17  9:48   ` Daniel Lezcano
  2016-08-08 13:33 ` [PATCH v2 2/4] clocksource: timer-atmel-pit: drop at91sam926x_pit_common_init Alexandre Belloni
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2016-08-08 13:33 UTC (permalink / raw)
  To: linux-arm-kernel

mck is needed to get the PIT working. Explicitly prepare_enable it instead
of assuming it is enabled.

This solves an issue where the system is freezing when the ETM/ETB drivers
are enabled.

Reported-by: Olivier Schonken <olivier.schonken@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/clocksource/timer-atmel-pit.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index 1ffac0cb0cb7..db839fc99a8e 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -261,6 +261,9 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
 		return PTR_ERR(data->mck);
 	}
 
+	if (clk_prepare_enable(data->mck))
+		panic(pr_fmt("Unable to enable mck\n"));
+
 	/* Get the interrupts property */
 	data->irq = irq_of_parse_and_map(node, 0);
 	if (!data->irq) {
-- 
2.8.1

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

* [PATCH v2 2/4] clocksource: timer-atmel-pit: drop at91sam926x_pit_common_init
  2016-08-08 13:33 [PATCH v2 0/4] clocksource: timer-atmel-pit: driver fix and cleanups Alexandre Belloni
  2016-08-08 13:33 ` [PATCH v2 1/4] clocksource: timer-atmel-pit: enable mck Alexandre Belloni
@ 2016-08-08 13:33 ` Alexandre Belloni
  2016-08-08 13:33 ` [PATCH v2 3/4] clocksource: timer-atmel-pit: remove uselesss WARN_ON_ONCE Alexandre Belloni
  2016-08-08 13:33 ` [PATCH v2 4/4] clocksource: timer-atmel-pit: simplify IRQ handler Alexandre Belloni
  3 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2016-08-08 13:33 UTC (permalink / raw)
  To: linux-arm-kernel

Merge at91sam926x_pit_common_init in at91sam926x_pit_dt_init as this is the
only initialization method now.

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/clocksource/timer-atmel-pit.c | 64 ++++++++++++++---------------------
 1 file changed, 26 insertions(+), 38 deletions(-)

diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index db839fc99a8e..6767768a7849 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -177,11 +177,36 @@ static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id)
 /*
  * Set up both clocksource and clockevent support.
  */
-static int __init at91sam926x_pit_common_init(struct pit_data *data)
+static int __init at91sam926x_pit_dt_init(struct device_node *node)
 {
 	unsigned long	pit_rate;
 	unsigned	bits;
 	int		ret;
+	struct pit_data *data;
+
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data)
+		panic(pr_fmt("Unable to allocate memory\n"));
+
+	data->base = of_iomap(node, 0);
+	if (!data->base)
+		panic(pr_fmt("Could not map PIT address\n"));
+
+	data->mck = of_clk_get(node, 0);
+	if (IS_ERR(data->mck))
+		/* Fallback on clkdev for !CCF-based boards */
+		data->mck = clk_get(NULL, "mck");
+
+	if (IS_ERR(data->mck))
+		panic(pr_fmt("Unable to get mck clk\n"));
+
+	if (clk_prepare_enable(data->mck))
+		panic(pr_fmt("Unable to enable mck\n"));
+
+	/* Get the interrupts property */
+	data->irq = irq_of_parse_and_map(node, 0);
+	if (!data->irq)
+		panic(pr_fmt("Unable to get IRQ from DT\n"));
 
 	/*
 	 * Use our actual MCK to figure out how many MCK/16 ticks per
@@ -236,42 +261,5 @@ static int __init at91sam926x_pit_common_init(struct pit_data *data)
 
 	return 0;
 }
-
-static int __init at91sam926x_pit_dt_init(struct device_node *node)
-{
-	struct pit_data *data;
-
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	data->base = of_iomap(node, 0);
-	if (!data->base) {
-		pr_err("Could not map PIT address\n");
-		return -ENXIO;
-	}
-
-	data->mck = of_clk_get(node, 0);
-	if (IS_ERR(data->mck))
-		/* Fallback on clkdev for !CCF-based boards */
-		data->mck = clk_get(NULL, "mck");
-
-	if (IS_ERR(data->mck)) {
-		pr_err("Unable to get mck clk\n");
-		return PTR_ERR(data->mck);
-	}
-
-	if (clk_prepare_enable(data->mck))
-		panic(pr_fmt("Unable to enable mck\n"));
-
-	/* Get the interrupts property */
-	data->irq = irq_of_parse_and_map(node, 0);
-	if (!data->irq) {
-		pr_err("Unable to get IRQ from DT\n");
-		return -EINVAL;
-	}
-
-	return at91sam926x_pit_common_init(data);
-}
 CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
 		       at91sam926x_pit_dt_init);
-- 
2.8.1

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

* [PATCH v2 3/4] clocksource: timer-atmel-pit: remove uselesss WARN_ON_ONCE
  2016-08-08 13:33 [PATCH v2 0/4] clocksource: timer-atmel-pit: driver fix and cleanups Alexandre Belloni
  2016-08-08 13:33 ` [PATCH v2 1/4] clocksource: timer-atmel-pit: enable mck Alexandre Belloni
  2016-08-08 13:33 ` [PATCH v2 2/4] clocksource: timer-atmel-pit: drop at91sam926x_pit_common_init Alexandre Belloni
@ 2016-08-08 13:33 ` Alexandre Belloni
  2016-08-08 13:33 ` [PATCH v2 4/4] clocksource: timer-atmel-pit: simplify IRQ handler Alexandre Belloni
  3 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2016-08-08 13:33 UTC (permalink / raw)
  To: linux-arm-kernel

IRQ handlers are running with IRQ disabled for a while, remove wrong
comment and useless test.

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/clocksource/timer-atmel-pit.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index 6767768a7849..af657fdce665 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -149,12 +149,6 @@ static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id)
 {
 	struct pit_data *data = dev_id;
 
-	/*
-	 * irqs should be disabled here, but as the irq is shared they are only
-	 * guaranteed to be off if the timer irq is registered first.
-	 */
-	WARN_ON_ONCE(!irqs_disabled());
-
 	/* The PIT interrupt may be disabled, and is shared */
 	if (clockevent_state_periodic(&data->clkevt) &&
 	    (pit_read(data->base, AT91_PIT_SR) & AT91_PIT_PITS)) {
-- 
2.8.1

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

* [PATCH v2 4/4] clocksource: timer-atmel-pit: simplify IRQ handler
  2016-08-08 13:33 [PATCH v2 0/4] clocksource: timer-atmel-pit: driver fix and cleanups Alexandre Belloni
                   ` (2 preceding siblings ...)
  2016-08-08 13:33 ` [PATCH v2 3/4] clocksource: timer-atmel-pit: remove uselesss WARN_ON_ONCE Alexandre Belloni
@ 2016-08-08 13:33 ` Alexandre Belloni
  3 siblings, 0 replies; 6+ messages in thread
From: Alexandre Belloni @ 2016-08-08 13:33 UTC (permalink / raw)
  To: linux-arm-kernel

Because the PIT is also a proper clocksource, the timekeeping code  is
already able to handle lost ticks.

Reported-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/clocksource/timer-atmel-pit.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index af657fdce665..c5f3291328bd 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -152,15 +152,10 @@ static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id)
 	/* The PIT interrupt may be disabled, and is shared */
 	if (clockevent_state_periodic(&data->clkevt) &&
 	    (pit_read(data->base, AT91_PIT_SR) & AT91_PIT_PITS)) {
-		unsigned nr_ticks;
-
 		/* Get number of ticks performed before irq, and ack it */
-		nr_ticks = PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR));
-		do {
-			data->cnt += data->cycle;
-			data->clkevt.event_handler(&data->clkevt);
-			nr_ticks--;
-		} while (nr_ticks);
+		data->cnt += data->cycle * PIT_PICNT(pit_read(data->base,
+							      AT91_PIT_PIVR));
+		data->clkevt.event_handler(&data->clkevt);
 
 		return IRQ_HANDLED;
 	}
-- 
2.8.1

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

* [PATCH v2 1/4] clocksource: timer-atmel-pit: enable mck
  2016-08-08 13:33 ` [PATCH v2 1/4] clocksource: timer-atmel-pit: enable mck Alexandre Belloni
@ 2016-08-17  9:48   ` Daniel Lezcano
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Lezcano @ 2016-08-17  9:48 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/08/2016 03:33 PM, Alexandre Belloni wrote:
> mck is needed to get the PIT working. Explicitly prepare_enable it instead
> of assuming it is enabled.
> 
> This solves an issue where the system is freezing when the ETM/ETB drivers
> are enabled.
> 
> Reported-by: Olivier Schonken <olivier.schonken@gmail.com>
> Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
>  drivers/clocksource/timer-atmel-pit.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
> index 1ffac0cb0cb7..db839fc99a8e 100644
> --- a/drivers/clocksource/timer-atmel-pit.c
> +++ b/drivers/clocksource/timer-atmel-pit.c
> @@ -261,6 +261,9 @@ static int __init at91sam926x_pit_dt_init(struct device_node *node)
>  		return PTR_ERR(data->mck);
>  	}
>  
> +	if (clk_prepare_enable(data->mck))
> +		panic(pr_fmt("Unable to enable mck\n"));
> +

Replace the panic by a proper error handling please.

Thanks !

  -- Daniel



-- 
 <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] 6+ messages in thread

end of thread, other threads:[~2016-08-17  9:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-08 13:33 [PATCH v2 0/4] clocksource: timer-atmel-pit: driver fix and cleanups Alexandre Belloni
2016-08-08 13:33 ` [PATCH v2 1/4] clocksource: timer-atmel-pit: enable mck Alexandre Belloni
2016-08-17  9:48   ` Daniel Lezcano
2016-08-08 13:33 ` [PATCH v2 2/4] clocksource: timer-atmel-pit: drop at91sam926x_pit_common_init Alexandre Belloni
2016-08-08 13:33 ` [PATCH v2 3/4] clocksource: timer-atmel-pit: remove uselesss WARN_ON_ONCE Alexandre Belloni
2016-08-08 13:33 ` [PATCH v2 4/4] clocksource: timer-atmel-pit: simplify IRQ handler Alexandre Belloni

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).