Skip to contentSkip to conversation

ARM: sunxi: stop timer from ticking before enabling interrupts

PATCH New Marc Zyngier 3 participants 5 messages Dec 2, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: sunxi: stop timer from ticking before enabling interrupts

The sun4i timer can still be ticking when we enable the interrupt. If another timer is actually used (A7 architected timer, for example), odds are that the interrupt will eventually fire with the event_handler pointer being NULL.

The obvious fix it to stop the timer before registering the interrupt.

Observed and tested on sun7i (cubietruck).

---
Daniel,

Maxime asked me to forward this to you directly. Please consider merging it for 3.13.

Thanks,

	M.
 drivers/clocksource/sun4i_timer.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/sun4i_timer.c +3 -0
index 2fb4695..a4f6119 100644
@@ -179,6 +179,9 @@ static void __init sun4i_timer_init(struct device_node *node)
 	writel(TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M),
 	       timer_base + TIMER_CTL_REG(0));
 
+	/* Make sure timer is stopped before playing with interrupts */
+	sun4i_clkevt_time_stop(0);
+
 	ret = setup_irq(irq, &sun4i_timer_irq);
 	if (ret)
 		pr_warn("failed to setup irq %d\n", irq);
Signature · 1 line
1.8.2.3
#1 lore raw

PATCH 1/1 ARM: sunxi: stop timer from ticking before enabling interrupts

Quoted 30 lines · Marc Zyngier

The sun4i timer can still be ticking when we enable the interrupt. If another timer is actually used (A7 architected timer, for example), odds are that the interrupt will eventually fire with the event_handler pointer being NULL.

The obvious fix it to stop the timer before registering the interrupt.

Observed and tested on sun7i (cubietruck).

---
Daniel,

Maxime asked me to forward this to you directly. Please consider merging it for 3.13.

Thanks,

	M.
  drivers/clocksource/sun4i_timer.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/clocksource/sun4i_timer.c +0 -0
index 2fb4695..a4f6119 100644

drivers/clocksource/sun4i_timer.c static void __init sun4i_timer_init(struct device_node *node) · line 184

Quoted 6 lines
drivers/clocksource/sun4i_timer.c +3 -0
@@ -179,6 +179,9 @@ static void __init sun4i_timer_init(struct device_node *node)
  	writel(TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M),
  	       timer_base + TIMER_CTL_REG(0));
 
+	/* Make sure timer is stopped before playing with interrupts */
+	sun4i_clkevt_time_stop(0);
+

It isn't possible to *not* enable it instead of stopping it ?

In the code before we have:

         writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD |
                TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M),
                timer_base + TIMER_CTL_REG(1));

If we remove the TIMER_CTL_ENABLE flag, wouldn't it fix the issue ?

Quoted 4 lines
drivers/clocksource/sun4i_timer.c +0 -0
  	ret = setup_irq(irq, &sun4i_timer_irq);
  	if (ret)
  		pr_warn("failed to setup irq %d\n", irq);
Signature · 5 lines
  <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
#2 lore raw

PATCH 1/1 ARM: sunxi: stop timer from ticking before enabling interrupts

Quoted 34 lines · Daniel Lezcano
Quoted 33 lines · Marc Zyngier

The sun4i timer can still be ticking when we enable the interrupt. If another timer is actually used (A7 architected timer, for example), odds are that the interrupt will eventually fire with the event_handler pointer being NULL.

The obvious fix it to stop the timer before registering the interrupt.

Observed and tested on sun7i (cubietruck).

---
Daniel,

Maxime asked me to forward this to you directly. Please consider merging it for 3.13.

Thanks,

	M.
  drivers/clocksource/sun4i_timer.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/clocksource/sun4i_timer.c +0 -0
index 2fb4695..a4f6119 100644
@@ -179,6 +179,9 @@ static void __init sun4i_timer_init(struct device_node *node)
  	writel(TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M),
  	       timer_base + TIMER_CTL_REG(0));
 
Quoted 5 lines

drivers/clocksource/sun4i_timer.c static void __init sun4i_timer_init(struct device_node *node) · line 184

Quoted 3 lines
drivers/clocksource/sun4i_timer.c +3 -0
+	/* Make sure timer is stopped before playing with interrupts */
+	sun4i_clkevt_time_stop(0);
+

It isn't possible to *not* enable it instead of stopping it ?

Well, it is already enabled by the bootloader.

Quoted 7 lines

In the code before we have:

         writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD |
                TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M),
                timer_base + TIMER_CTL_REG(1));

If we remove the TIMER_CTL_ENABLE flag, wouldn't it fix the issue ?

No. This piece of code enables the clocksource, which is implemented using timer 1. Timer 0 still needs to be disabled.

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#3 lore raw

PATCH 1/1 ARM: sunxi: stop timer from ticking before enabling interrupts

In reply to Daniel Lezcano

Hi Daniel,

Quoted 6 lines · Daniel Lezcano

drivers/clocksource/sun4i_timer.c static void __init sun4i_timer_init(struct device_node *node) · line 184

Quoted 3 lines
drivers/clocksource/sun4i_timer.c +3 -0
+	/* Make sure timer is stopped before playing with interrupts */
+	sun4i_clkevt_time_stop(0);
+

It isn't possible to *not* enable it instead of stopping it ?

Quoted 7 lines

In the code before we have:

        writel(TIMER_CTL_ENABLE | TIMER_CTL_RELOAD |
               TIMER_CTL_CLK_SRC(TIMER_CTL_CLK_SRC_OSC24M),
               timer_base + TIMER_CTL_REG(1));

If we remove the TIMER_CTL_ENABLE flag, wouldn't it fix the issue ?

Actually, this excerpt enables the timer 1, that is used as a clocksource, while Marc stops the timer 0, which is used as our clock event.

The timer 0 is enabled only whenever either .set_mode or .set_next_event is called.

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131202/490fefcf/attachment.sig>
#4 lore raw

PATCH 1/1 ARM: sunxi: stop timer from ticking before enabling interrupts

In reply to Marc Zyngier
Quoted 5 lines · Marc Zyngier

The sun4i timer can still be ticking when we enable the interrupt. If another timer is actually used (A7 architected timer, for example), odds are that the interrupt will eventually fire with the event_handler pointer being NULL.

Quoted 8 lines

The obvious fix it to stop the timer before registering the interrupt.

Observed and tested on sun7i (cubietruck).

---

Applied to my tree as 3.13 fixes.

Thanks
-- Daniel

Signature · 5 lines
  <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