Skip to contentSkip to conversation

ARM: at91: fix hanged boot

PATCH Superseded Johan Hovold 3 participants 25 messages Mar 8, 2013 – Nov 15, 2013

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

cover ARM: at91: fix hanged boot

These patches fix a few severe issues affecting most AT91 SOCs where boot can hang after a non-general reset, and where the only way to get the system booting again is to do a general reset -- something which could require physically removing any backup battery.

The problems stem from the fact that the RTC and RTT-peripherals are powered by backup power (VDDBU) and are not reset on wake-up, user, watchdog or software reset. Consequently, RTC and RTT-alarms and their interrupts may be enabled at boot, leading to a system lock-up when an interrupt arrives on the shared system-interrupt line before the appropriate handler (e.g. RTC-driver) has been installed.

The easiest way to trigger this is to simply wake up from an RTC-alarm on at91sam9g45. The RTC-driver currently does not disable interrupts at shutdown so even after a clean shut-down the system will always hang after waking up.

The first patch fixes this very general case of RTC-wake up after a clean shutdown in the RTC-driver and is marked for stable as it is perfectly straight-forward. [ Note that the other, RTT-based, AT91 RTC-driver already disables its interrupts at shutdown. ]

The more general problem can be triggered, for example, by doing a user-reset while updating the RTC-time or if an RTC or RTT-alarm goes off after a non-clean shutdown.

To fix this I propose that arch-code should mask the relevant interrupts at early boot, and this is what the third patch does. To access the RTC-registers I choose to revert a recent patch that moved the register definitions to drivers/rtc.

Arguably, the interrupts could also be disabled in bootloaders, but I strongly suggest fixing it in the kernel once and for all. By adding a new, mandatory AT91 SOC-initialiser (rather extending init) it will not be overlooked when adding new SOCs either.

The patches have been tested on at91sam9263 and at91sam9g45, and compile-tested for the other SOCs.

Johan

Johan Hovold (3):
ARM: at91/rtc: fix boot after RTC wake-up
Revert "arm: at91: move at91rm9200 rtc header in drivers/rtc"
ARM: at91: fix hanged boot

 arch/arm/mach-at91/at91rm9200.c               |  9 ++++
 arch/arm/mach-at91/at91sam9260.c              |  6 +++
 arch/arm/mach-at91/at91sam9261.c              |  6 +++
 arch/arm/mach-at91/at91sam9263.c              |  7 +++
 arch/arm/mach-at91/at91sam9g45.c              |  7 +++
 arch/arm/mach-at91/at91sam9n12.c              |  6 +++
 arch/arm/mach-at91/at91sam9rl.c               |  7 +++
 arch/arm/mach-at91/at91sam9x5.c               |  6 +++
 arch/arm/mach-at91/generic.h                  |  2 +
 arch/arm/mach-at91/include/mach/at91_rtc.h    | 75 +++++++++++++++++++++++++++
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 ++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 ++
 arch/arm/mach-at91/setup.c                    | 31 +++++++++++
 arch/arm/mach-at91/soc.h                      |  1 +
 drivers/rtc/rtc-at91rm9200.c                  | 11 +++-
 drivers/rtc/rtc-at91rm9200.h                  | 75 ---------------------------
 16 files changed, 183 insertions(+), 76 deletions(-)
 create mode 100644 arch/arm/mach-at91/include/mach/at91_rtc.h
 delete mode 100644 drivers/rtc/rtc-at91rm9200.h
Signature · 1 line
1.8.1.1
#1 lore raw

PATCH 1/3 ARM: at91/rtc: fix boot after RTC wake-up

Fix failed boot after RTC wake-up by making sure RTC-interrupts are disabled at shutdown.

The RTC-registers are not reset at shutdown when there is backup power available, and hence the RTC-interrupt, which uses the shared system interrupt, may be enabled during early boot. If an RTC-alarm goes off before the RTC-driver is initialised (e.g. when waking up from an RTC-alarm) this results in disabled system interrupts.

Without earlyprintk boot hangs after

Uncompressing Linux... done, booting the kernel.

and earlyprintk reveals that the shared system interrupt gets disabled:

irq 17: nobody cared (try booting with the "irqpoll" option)
[<c000cf8c>] (unwind_backtrace+0x0/0xf0) from [<c00513ec>] (__report_bad_irq+0x20/0xe8) [<c00513ec>] (__report_bad_irq+0x20/0xe8) from [<c00516fc>] (note_interrupt+0x1e0/0x244) [<c00516fc>] (note_interrupt+0x1e0/0x244) from [<c004f980>] (handle_irq_event_percpu+0xac/0x1c4) [<c004f980>] (handle_irq_event_percpu+0xac/0x1c4) from [<c004faec>] (handle_irq_event+0x54/0x84) [<c004faec>] (handle_irq_event+0x54/0x84) from [<c0052364>] (handle_fasteoi_irq+0x84/0x154) [<c0052364>] (handle_fasteoi_irq+0x84/0x154) from [<c004f1f8>] (generic_handle_irq+0x20/0x30) [<c004f1f8>] (generic_handle_irq+0x20/0x30) from [<c0009b8c>] (handle_IRQ+0x30/0x84) [<c0009b8c>] (handle_IRQ+0x30/0x84) from [<c0008fa0>] (__irq_svc+0x40/0x6c) [<c0008fa0>] (__irq_svc+0x40/0x6c) from [<c001cd6c>] (__do_softirq+0x5c/0x164) [<c001cd6c>] (__do_softirq+0x5c/0x164) from [<c001d268>] (irq_exit+0x58/0x60) [<c001d268>] (irq_exit+0x58/0x60) from [<c0009b90>] (handle_IRQ+0x34/0x84) [<c0009b90>] (handle_IRQ+0x34/0x84) from [<c0008fa0>] (__irq_svc+0x40/0x6c) [<c0008fa0>] (__irq_svc+0x40/0x6c) from [<c03e668c>] (start_kernel+0x1d8/0x29c) [<c03e668c>] (start_kernel+0x1d8/0x29c) from [<70008040>] (0x70008040)
handlers:
[<c0012df0>] at91sam926x_pit_interrupt
Disabling IRQ #17

Note that disabling the RTC-interrupts at shutdown fixes boot after a clean shutdown, but that an RTC-alarm after a user (or watchdog) reset could still prevent the system from booting.

Note also that the only way to recover from a failed boot after an RTC-alarm is to remove any backup power (e.g. backup battery) or to disable (or acknowledge) the RTC-interrupt manually from the bootloader. In particular, a user-reset is not sufficient.

Tested on at91sam9g45.

---
 drivers/rtc/rtc-at91rm9200.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/rtc/rtc-at91rm9200.c +9 -0
index b6469e2..936c75a 100644
@@ -338,6 +338,14 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void at91_rtc_shutdown(struct platform_device *pdev)
+{
+	/* Disable all interrupts */
+	at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
+					AT91_RTC_SECEV | AT91_RTC_TIMEV |
+					AT91_RTC_CALEV);
+}
+
 #ifdef CONFIG_PM
 
 /* AT91RM9200 RTC Power management control */
@@ -384,6 +392,7 @@ static const struct dev_pm_ops at91_rtc_pm = {
 
 static struct platform_driver at91_rtc_driver = {
 	.remove		= __exit_p(at91_rtc_remove),
+	.shutdown	= at91_rtc_shutdown,
 	.driver		= {
 		.name	= "at91_rtc",
 		.owner	= THIS_MODULE,
Signature · 1 line
1.8.1.1
#2 lore raw

PATCH 2/3 Revert "arm: at91: move at91rm9200 rtc header in drivers/rtc"

In reply to Johan Hovold

This reverts commit 75984df05d86956541795f01e62d7dc67bc522fd.

A couple of these register definitions are needed by arch code as the RTC-interrupts must be disabled at early boot.

---
 arch/arm/mach-at91/include/mach/at91_rtc.h | 75 ++++++++++++++++++++++++++++++
 drivers/rtc/rtc-at91rm9200.c               |  2 +-
 drivers/rtc/rtc-at91rm9200.h               | 75 ------------------------------
 3 files changed, 76 insertions(+), 76 deletions(-)
 create mode 100644 arch/arm/mach-at91/include/mach/at91_rtc.h
 delete mode 100644 drivers/rtc/rtc-at91rm9200.h
arch/arm/mach-at91/include/mach/at91_rtc.h new file +75 -0
new file mode 100644
index 0000000..da1945e
@@ -0,0 +1,75 @@
+/*
+ * arch/arm/mach-at91/include/mach/at91_rtc.h
+ *
+ * Copyright (C) 2005 Ivan Kokshaysky
+ * Copyright (C) SAN People
+ *
+ * Real Time Clock (RTC) - System peripheral registers.
+ * Based on AT91RM9200 datasheet revision E.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef AT91_RTC_H
+#define AT91_RTC_H
+
+#define	AT91_RTC_CR		0x00			/* Control Register */
+#define		AT91_RTC_UPDTIM		(1 <<  0)		/* Update Request Time Register */
+#define		AT91_RTC_UPDCAL		(1 <<  1)		/* Update Request Calendar Register */
+#define		AT91_RTC_TIMEVSEL	(3 <<  8)		/* Time Event Selection */
+#define			AT91_RTC_TIMEVSEL_MINUTE	(0 << 8)
+#define			AT91_RTC_TIMEVSEL_HOUR		(1 << 8)
+#define			AT91_RTC_TIMEVSEL_DAY24		(2 << 8)
+#define			AT91_RTC_TIMEVSEL_DAY12		(3 << 8)
+#define		AT91_RTC_CALEVSEL	(3 << 16)		/* Calendar Event Selection */
+#define			AT91_RTC_CALEVSEL_WEEK		(0 << 16)
+#define			AT91_RTC_CALEVSEL_MONTH		(1 << 16)
+#define			AT91_RTC_CALEVSEL_YEAR		(2 << 16)
+
+#define	AT91_RTC_MR		0x04			/* Mode Register */
+#define			AT91_RTC_HRMOD		(1 <<  0)		/* 12/24 Hour Mode */
+
+#define	AT91_RTC_TIMR		0x08			/* Time Register */
+#define		AT91_RTC_SEC		(0x7f <<  0)		/* Current Second */
+#define		AT91_RTC_MIN		(0x7f <<  8)		/* Current Minute */
+#define		AT91_RTC_HOUR		(0x3f << 16)		/* Current Hour */
+#define		AT91_RTC_AMPM		(1    << 22)		/* Ante Meridiem Post Meridiem Indicator */
+
+#define	AT91_RTC_CALR		0x0c			/* Calendar Register */
+#define		AT91_RTC_CENT		(0x7f <<  0)		/* Current Century */
+#define		AT91_RTC_YEAR		(0xff <<  8)		/* Current Year */
+#define		AT91_RTC_MONTH		(0x1f << 16)		/* Current Month */
+#define		AT91_RTC_DAY		(7    << 21)		/* Current Day */
+#define		AT91_RTC_DATE		(0x3f << 24)		/* Current Date */
+
+#define	AT91_RTC_TIMALR		0x10			/* Time Alarm Register */
+#define		AT91_RTC_SECEN		(1 <<  7)		/* Second Alarm Enable */
+#define		AT91_RTC_MINEN		(1 << 15)		/* Minute Alarm Enable */
+#define		AT91_RTC_HOUREN		(1 << 23)		/* Hour Alarm Enable */
+
+#define	AT91_RTC_CALALR		0x14			/* Calendar Alarm Register */
+#define		AT91_RTC_MTHEN		(1 << 23)		/* Month Alarm Enable */
+#define		AT91_RTC_DATEEN		(1 << 31)		/* Date Alarm Enable */
+
+#define	AT91_RTC_SR		0x18			/* Status Register */
+#define		AT91_RTC_ACKUPD		(1 <<  0)		/* Acknowledge for Update */
+#define		AT91_RTC_ALARM		(1 <<  1)		/* Alarm Flag */
+#define		AT91_RTC_SECEV		(1 <<  2)		/* Second Event */
+#define		AT91_RTC_TIMEV		(1 <<  3)		/* Time Event */
+#define		AT91_RTC_CALEV		(1 <<  4)		/* Calendar Event */
+
+#define	AT91_RTC_SCCR		0x1c			/* Status Clear Command Register */
+#define	AT91_RTC_IER		0x20			/* Interrupt Enable Register */
+#define	AT91_RTC_IDR		0x24			/* Interrupt Disable Register */
+#define	AT91_RTC_IMR		0x28			/* Interrupt Mask Register */
+
+#define	AT91_RTC_VER		0x2c			/* Valid Entry Register */
+#define		AT91_RTC_NVTIM		(1 <<  0)		/* Non valid Time */
+#define		AT91_RTC_NVCAL		(1 <<  1)		/* Non valid Calendar */
+#define		AT91_RTC_NVTIMALR	(1 <<  2)		/* Non valid Time Alarm */
+#define		AT91_RTC_NVCALALR	(1 <<  3)		/* Non valid Calendar Alarm */
+
+#endif
drivers/rtc/rtc-at91rm9200.c +1 -1
index 936c75a..1ed0433 100644
@@ -31,7 +31,7 @@
 
 #include <asm/uaccess.h>
 
-#include "rtc-at91rm9200.h"
+#include <mach/at91_rtc.h>
 
 #define at91_rtc_read(field) \
 	__raw_readl(at91_rtc_regs + field)
drivers/rtc/rtc-at91rm9200.h deleted +0 -75

75 lines not on this page · raw message

Signature · 1 line
1.8.1.1
#3 lore raw

PATCH 3/3 ARM: at91: fix hanged boot

In reply to Johan Hovold

Make sure the RTC and RTT-interrupts are masked at boot by adding a new SOC-initialiser and helpers functions.

This fixes hanged boot on all AT91 SOCs but RM9200, for example, after a reset during an RTC-update or if an RTC or RTT-alarm goes off after a non-clean shutdown.

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

Tested on at91sam9263 and at91sam9g45.

---
 arch/arm/mach-at91/at91rm9200.c               |  9 ++++++++
 arch/arm/mach-at91/at91sam9260.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9261.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9263.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9g45.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9n12.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9rl.c               |  7 ++++++
 arch/arm/mach-at91/at91sam9x5.c               |  6 ++++++
 arch/arm/mach-at91/generic.h                  |  2 ++
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 +++++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 +++++
 arch/arm/mach-at91/setup.c                    | 31 +++++++++++++++++++++++++++
 arch/arm/mach-at91/soc.h                      |  1 +
 13 files changed, 98 insertions(+)
arch/arm/mach-at91/at91rm9200.c +9 -0
index 7aeb473..4651ebb 100644
@@ -325,6 +325,14 @@ static void __init at91rm9200_ioremap_registers(void)
 	at91_ioremap_ramc(0, AT91RM9200_BASE_MC, 256);
 }
 
+static void __init at91rm9200_sysirq_mask(void)
+{
+	/*
+	 * No need to mask any system interrupts as the RM9200 has no backup
+	 * power and resets all system peripherals at every reset.
+	 */
+}
+
 static void __init at91rm9200_initialize(void)
 {
 	arm_pm_idle = at91rm9200_idle;
@@ -387,5 +395,6 @@ AT91_SOC_START(rm9200)
 	.default_irq_priority = at91rm9200_default_irq_priority,
 	.ioremap_registers = at91rm9200_ioremap_registers,
 	.register_clocks = at91rm9200_register_clocks,
+	.sysirq_mask = at91rm9200_sysirq_mask,
 	.init = at91rm9200_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9260.c +6 -0
index b67cd53..c47a0db 100644
@@ -342,6 +342,11 @@ static void __init at91sam9260_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9260_BASE_MATRIX);
 }
 
+static void __init at91sam9260_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT);
+}
+
 static void __init at91sam9260_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -400,5 +405,6 @@ AT91_SOC_START(sam9260)
 	.default_irq_priority = at91sam9260_default_irq_priority,
 	.ioremap_registers = at91sam9260_ioremap_registers,
 	.register_clocks = at91sam9260_register_clocks,
+	.sysirq_mask = at91sam9260_sysirq_mask,
 	.init = at91sam9260_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9261.c +6 -0
index 0204f4c..396e4cb 100644
@@ -286,6 +286,11 @@ static void __init at91sam9261_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9261_BASE_MATRIX);
 }
 
+static void __init at91sam9261_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
+}
+
 static void __init at91sam9261_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -344,5 +349,6 @@ AT91_SOC_START(sam9261)
 	.default_irq_priority = at91sam9261_default_irq_priority,
 	.ioremap_registers = at91sam9261_ioremap_registers,
 	.register_clocks = at91sam9261_register_clocks,
+	.sysirq_mask = at91sam9261_sysirq_mask,
 	.init = at91sam9261_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9263.c +7 -0
index c0cbb81..a0166a3 100644
@@ -325,6 +325,12 @@ static void __init at91sam9263_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9263_BASE_MATRIX);
 }
 
+static void __init at91sam9263_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0);
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1);
+}
+
 static void __init at91sam9263_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -382,5 +388,6 @@ AT91_SOC_START(sam9263)
 	.default_irq_priority = at91sam9263_default_irq_priority,
 	.ioremap_registers = at91sam9263_ioremap_registers,
 	.register_clocks = at91sam9263_register_clocks,
+	.sysirq_mask = at91sam9263_sysirq_mask,
 	.init = at91sam9263_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9g45.c +7 -0
index b4968aa..3d5498e 100644
@@ -370,6 +370,12 @@ static void __init at91sam9g45_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9G45_BASE_MATRIX);
 }
 
+static void __init at91sam9g45_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT);
+}
+
 static void __init at91sam9g45_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -427,5 +433,6 @@ AT91_SOC_START(sam9g45)
 	.default_irq_priority = at91sam9g45_default_irq_priority,
 	.ioremap_registers = at91sam9g45_ioremap_registers,
 	.register_clocks = at91sam9g45_register_clocks,
+	.sysirq_mask = at91sam9g45_sysirq_mask,
 	.init = at91sam9g45_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9n12.c +6 -0
index 5dfc8fd..e2ddb89 100644
@@ -221,6 +221,11 @@ static void __init at91sam9n12_map_io(void)
 	at91_init_sram(0, AT91SAM9N12_SRAM_BASE, AT91SAM9N12_SRAM_SIZE);
 }
 
+static void __init at91sam9n12_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9N12_BASE_RTC);
+}
+
 void __init at91sam9n12_initialize(void)
 {
 	at91_extern_irq = (1 << AT91SAM9N12_ID_IRQ0);
@@ -229,5 +234,6 @@ void __init at91sam9n12_initialize(void)
 AT91_SOC_START(sam9n12)
 	.map_io = at91sam9n12_map_io,
 	.register_clocks = at91sam9n12_register_clocks,
+	.sysirq_mask = at91sam9n12_sysirq_mask,
 	.init = at91sam9n12_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9rl.c +7 -0
index 3de3e04..bde999f 100644
@@ -289,6 +289,12 @@ static void __init at91sam9rl_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9RL_BASE_MATRIX);
 }
 
+static void __init at91sam9rl_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT);
+}
+
 static void __init at91sam9rl_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -346,5 +352,6 @@ AT91_SOC_START(sam9rl)
 	.default_irq_priority = at91sam9rl_default_irq_priority,
 	.ioremap_registers = at91sam9rl_ioremap_registers,
 	.register_clocks = at91sam9rl_register_clocks,
+	.sysirq_mask = at91sam9rl_sysirq_mask,
 	.init = at91sam9rl_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9x5.c +6 -0
index 44a9a62..20a214f 100644
@@ -316,6 +316,11 @@ static void __init at91sam9x5_map_io(void)
 	at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
 }
 
+static void __init at91sam9x5_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9X5_BASE_RTC);
+}
+
 /* --------------------------------------------------------------------
  *  Interrupt initialization
  * -------------------------------------------------------------------- */
@@ -323,4 +328,5 @@ static void __init at91sam9x5_map_io(void)
 AT91_SOC_START(sam9x5)
 	.map_io = at91sam9x5_map_io,
 	.register_clocks = at91sam9x5_register_clocks,
+	.sysirq_mask = at91sam9x5_sysirq_mask,
 AT91_SOC_END
arch/arm/mach-at91/generic.h +2 -0
index fc593d6..90a854d 100644
@@ -33,6 +33,8 @@ extern int  __init at91_aic_of_init(struct device_node *node,
 				    struct device_node *parent);
 extern int  __init at91_aic5_of_init(struct device_node *node,
 				    struct device_node *parent);
+extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
+extern void __init at91_sysirq_mask_rtt(u32 rtt_base);
 
 
  /* Timer */
arch/arm/mach-at91/include/mach/at91sam9n12.h +5 -0
index d374b87..0151bcf 100644
@@ -49,6 +49,11 @@
 #define AT91SAM9N12_BASE_USART3	0xf8028000
 
 /*
+ * System Peripherals
+ */
+#define AT91SAM9N12_BASE_RTC	0xfffffeb0
+
+/*
  * Internal Memory.
  */
 #define AT91SAM9N12_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/include/mach/at91sam9x5.h +5 -0
index c75ee19..2fc76c4 100644
@@ -55,6 +55,11 @@
 #define AT91SAM9X5_BASE_USART2	0xf8024000
 
 /*
+ * System Peripherals
+ */
+#define AT91SAM9X5_BASE_RTC	0xfffffeb0
+
+/*
  * Internal Memory.
  */
 #define AT91SAM9X5_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/setup.c +31 -0
index 4b67847..ac05453 100644
@@ -19,6 +19,8 @@
 #include <mach/cpu.h>
 #include <mach/at91_dbgu.h>
 #include <mach/at91_pmc.h>
+#include <mach/at91_rtc.h>
+#include <mach/at91_rtt.h>
 
 #include "at91_shdwc.h"
 #include "soc.h"
@@ -311,6 +313,31 @@ void __init at91_ioremap_matrix(u32 base_addr)
 		panic("Impossible to ioremap at91_matrix_base\n");
 }
 
+void __init at91_sysirq_mask_rtc(u32 rtc_base)
+{
+	void *base = AT91_IO_P2V(rtc_base);
+	u32 mask;
+
+	mask = __raw_readl(base + AT91_RTC_IMR);
+	if (mask) {
+		pr_info("AT91: Disabling rtc irq\n");
+		__raw_writel(mask, base + AT91_RTC_IDR);
+	}
+}
+
+void __init at91_sysirq_mask_rtt(u32 rtt_base)
+{
+	void *base = AT91_IO_P2V(rtt_base);
+	u32 mr;
+
+	mr = __raw_readl(base + AT91_RTT_MR);
+	if (mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)) {
+		pr_info("AT91: Disabling rtt irq\n");
+		mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+		__raw_writel(mr, base + AT91_RTT_MR);
+	}
+}
+
 #if defined(CONFIG_OF)
 static struct of_device_id rstc_ids[] = {
 	{ .compatible = "atmel,at91sam9260-rstc", .data = at91sam9_alt_restart },
@@ -467,6 +494,8 @@ void __init at91_dt_initialize(void)
 
 	if (at91_boot_soc.init)
 		at91_boot_soc.init();
+
+	at91_boot_soc.sysirq_mask();
 }
 #endif
 
@@ -482,5 +511,7 @@ void __init at91_initialize(unsigned long main_clock)
 
 	at91_boot_soc.init();
 
+	at91_boot_soc.sysirq_mask();
+
 	pinctrl_provide_dummies();
 }
arch/arm/mach-at91/soc.h +1 -0
index 9c6d3d4..134f4c4 100644
@@ -10,6 +10,7 @@ struct at91_init_soc {
 	void (*map_io)(void);
 	void (*ioremap_registers)(void);
 	void (*register_clocks)(void);
+	void (*sysirq_mask)(void);
 	void (*init)(void);
 };
 
Signature · 1 line
1.8.1.1
#4 lore raw
Quoted 27 lines · Johan Hovold

Make sure the RTC and RTT-interrupts are masked at boot by adding a new SOC-initialiser and helpers functions.

This fixes hanged boot on all AT91 SOCs but RM9200, for example, after a reset during an RTC-update or if an RTC or RTT-alarm goes off after a non-clean shutdown.

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

Tested on at91sam9263 and at91sam9g45.

Quoted 12 lines
---
 arch/arm/mach-at91/at91rm9200.c               |  9 ++++++++
 arch/arm/mach-at91/at91sam9260.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9261.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9263.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9g45.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9n12.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9rl.c               |  7 ++++++
 arch/arm/mach-at91/at91sam9x5.c               |  6 ++++++
 arch/arm/mach-at91/generic.h                  |  2 ++
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 +++++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 +++++

nack for DT probe te address via DT

Quoted 3 lines
 arch/arm/mach-at91/setup.c                    | 31 +++++++++++++++++++++++++++
 arch/arm/mach-at91/soc.h                      |  1 +
 13 files changed, 98 insertions(+)

at boot time we can disable all the irq as we need none of them

Quoted 6 lines
arch/arm/mach-at91/at91rm9200.c +0 -0
index 7aeb473..4651ebb 100644

arch/arm/mach-at91/at91rm9200.c static void __init at91rm9200_ioremap_registers(void) · line 334

Quoted 10 lines
arch/arm/mach-at91/at91rm9200.c +7 -0
@@ -325,6 +325,14 @@ static void __init at91rm9200_ioremap_registers(void)
 	at91_ioremap_ramc(0, AT91RM9200_BASE_MC, 256);
 }
 
+static void __init at91rm9200_sysirq_mask(void)
+{
+	/*
+	 * No need to mask any system interrupts as the RM9200 has no backup
+	 * power and resets all system peripherals at every reset.
+	 */
+}

no need drop it

Quoted 308 lines
arch/arm/mach-at91/at91rm9200.c +2 -0
+
 static void __init at91rm9200_initialize(void)
 {
 	arm_pm_idle = at91rm9200_idle;
@@ -387,5 +395,6 @@ AT91_SOC_START(rm9200)
 	.default_irq_priority = at91rm9200_default_irq_priority,
 	.ioremap_registers = at91rm9200_ioremap_registers,
 	.register_clocks = at91rm9200_register_clocks,
+	.sysirq_mask = at91rm9200_sysirq_mask,
 	.init = at91rm9200_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9260.c +6 -0
index b67cd53..c47a0db 100644
@@ -342,6 +342,11 @@ static void __init at91sam9260_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9260_BASE_MATRIX);
 }
 
+static void __init at91sam9260_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT);
+}
+
 static void __init at91sam9260_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -400,5 +405,6 @@ AT91_SOC_START(sam9260)
 	.default_irq_priority = at91sam9260_default_irq_priority,
 	.ioremap_registers = at91sam9260_ioremap_registers,
 	.register_clocks = at91sam9260_register_clocks,
+	.sysirq_mask = at91sam9260_sysirq_mask,
 	.init = at91sam9260_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9261.c +6 -0
index 0204f4c..396e4cb 100644
@@ -286,6 +286,11 @@ static void __init at91sam9261_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9261_BASE_MATRIX);
 }
 
+static void __init at91sam9261_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
+}
+
 static void __init at91sam9261_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -344,5 +349,6 @@ AT91_SOC_START(sam9261)
 	.default_irq_priority = at91sam9261_default_irq_priority,
 	.ioremap_registers = at91sam9261_ioremap_registers,
 	.register_clocks = at91sam9261_register_clocks,
+	.sysirq_mask = at91sam9261_sysirq_mask,
 	.init = at91sam9261_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9263.c +7 -0
index c0cbb81..a0166a3 100644
@@ -325,6 +325,12 @@ static void __init at91sam9263_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9263_BASE_MATRIX);
 }
 
+static void __init at91sam9263_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0);
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1);
+}
+
 static void __init at91sam9263_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -382,5 +388,6 @@ AT91_SOC_START(sam9263)
 	.default_irq_priority = at91sam9263_default_irq_priority,
 	.ioremap_registers = at91sam9263_ioremap_registers,
 	.register_clocks = at91sam9263_register_clocks,
+	.sysirq_mask = at91sam9263_sysirq_mask,
 	.init = at91sam9263_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9g45.c +7 -0
index b4968aa..3d5498e 100644
@@ -370,6 +370,12 @@ static void __init at91sam9g45_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9G45_BASE_MATRIX);
 }
 
+static void __init at91sam9g45_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT);
+}
+
 static void __init at91sam9g45_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -427,5 +433,6 @@ AT91_SOC_START(sam9g45)
 	.default_irq_priority = at91sam9g45_default_irq_priority,
 	.ioremap_registers = at91sam9g45_ioremap_registers,
 	.register_clocks = at91sam9g45_register_clocks,
+	.sysirq_mask = at91sam9g45_sysirq_mask,
 	.init = at91sam9g45_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9n12.c +6 -0
index 5dfc8fd..e2ddb89 100644
@@ -221,6 +221,11 @@ static void __init at91sam9n12_map_io(void)
 	at91_init_sram(0, AT91SAM9N12_SRAM_BASE, AT91SAM9N12_SRAM_SIZE);
 }
 
+static void __init at91sam9n12_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9N12_BASE_RTC);
+}
+
 void __init at91sam9n12_initialize(void)
 {
 	at91_extern_irq = (1 << AT91SAM9N12_ID_IRQ0);
@@ -229,5 +234,6 @@ void __init at91sam9n12_initialize(void)
 AT91_SOC_START(sam9n12)
 	.map_io = at91sam9n12_map_io,
 	.register_clocks = at91sam9n12_register_clocks,
+	.sysirq_mask = at91sam9n12_sysirq_mask,
 	.init = at91sam9n12_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9rl.c +7 -0
index 3de3e04..bde999f 100644
@@ -289,6 +289,12 @@ static void __init at91sam9rl_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9RL_BASE_MATRIX);
 }
 
+static void __init at91sam9rl_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT);
+}
+
 static void __init at91sam9rl_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -346,5 +352,6 @@ AT91_SOC_START(sam9rl)
 	.default_irq_priority = at91sam9rl_default_irq_priority,
 	.ioremap_registers = at91sam9rl_ioremap_registers,
 	.register_clocks = at91sam9rl_register_clocks,
+	.sysirq_mask = at91sam9rl_sysirq_mask,
 	.init = at91sam9rl_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9x5.c +6 -0
index 44a9a62..20a214f 100644
@@ -316,6 +316,11 @@ static void __init at91sam9x5_map_io(void)
 	at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
 }
 
+static void __init at91sam9x5_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9X5_BASE_RTC);
+}
+
 /* --------------------------------------------------------------------
  *  Interrupt initialization
  * -------------------------------------------------------------------- */
@@ -323,4 +328,5 @@ static void __init at91sam9x5_map_io(void)
 AT91_SOC_START(sam9x5)
 	.map_io = at91sam9x5_map_io,
 	.register_clocks = at91sam9x5_register_clocks,
+	.sysirq_mask = at91sam9x5_sysirq_mask,
 AT91_SOC_END
arch/arm/mach-at91/generic.h +2 -0
index fc593d6..90a854d 100644
@@ -33,6 +33,8 @@ extern int  __init at91_aic_of_init(struct device_node *node,
 				    struct device_node *parent);
 extern int  __init at91_aic5_of_init(struct device_node *node,
 				    struct device_node *parent);
+extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
+extern void __init at91_sysirq_mask_rtt(u32 rtt_base);
 
 
  /* Timer */
arch/arm/mach-at91/include/mach/at91sam9n12.h +5 -0
index d374b87..0151bcf 100644
@@ -49,6 +49,11 @@
 #define AT91SAM9N12_BASE_USART3	0xf8028000
 
 /*
+ * System Peripherals
+ */
+#define AT91SAM9N12_BASE_RTC	0xfffffeb0
+
+/*
  * Internal Memory.
  */
 #define AT91SAM9N12_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/include/mach/at91sam9x5.h +5 -0
index c75ee19..2fc76c4 100644
@@ -55,6 +55,11 @@
 #define AT91SAM9X5_BASE_USART2	0xf8024000
 
 /*
+ * System Peripherals
+ */
+#define AT91SAM9X5_BASE_RTC	0xfffffeb0
+
+/*
  * Internal Memory.
  */
 #define AT91SAM9X5_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/setup.c +31 -0
index 4b67847..ac05453 100644
@@ -19,6 +19,8 @@
 #include <mach/cpu.h>
 #include <mach/at91_dbgu.h>
 #include <mach/at91_pmc.h>
+#include <mach/at91_rtc.h>
+#include <mach/at91_rtt.h>
 
 #include "at91_shdwc.h"
 #include "soc.h"
@@ -311,6 +313,31 @@ void __init at91_ioremap_matrix(u32 base_addr)
 		panic("Impossible to ioremap at91_matrix_base\n");
 }
 
+void __init at91_sysirq_mask_rtc(u32 rtc_base)
+{
+	void *base = AT91_IO_P2V(rtc_base);
+	u32 mask;
+
+	mask = __raw_readl(base + AT91_RTC_IMR);
+	if (mask) {
+		pr_info("AT91: Disabling rtc irq\n");
+		__raw_writel(mask, base + AT91_RTC_IDR);
+	}
+}
+
+void __init at91_sysirq_mask_rtt(u32 rtt_base)
+{
+	void *base = AT91_IO_P2V(rtt_base);
+	u32 mr;
+
+	mr = __raw_readl(base + AT91_RTT_MR);
+	if (mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)) {
+		pr_info("AT91: Disabling rtt irq\n");
+		mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+		__raw_writel(mr, base + AT91_RTT_MR);
+	}
+}
+
 #if defined(CONFIG_OF)
 static struct of_device_id rstc_ids[] = {
 	{ .compatible = "atmel,at91sam9260-rstc", .data = at91sam9_alt_restart },
@@ -467,6 +494,8 @@ void __init at91_dt_initialize(void)
 
 	if (at91_boot_soc.init)
 		at91_boot_soc.init();
+
+	at91_boot_soc.sysirq_mask();
 }
 #endif
 
@@ -482,5 +511,7 @@ void __init at91_initialize(unsigned long main_clock)
 
 	at91_boot_soc.init();
 
+	at91_boot_soc.sysirq_mask();
+
 	pinctrl_provide_dummies();
 }
arch/arm/mach-at91/soc.h +1 -0
index 9c6d3d4..134f4c4 100644
@@ -10,6 +10,7 @@ struct at91_init_soc {
 	void (*map_io)(void);
 	void (*ioremap_registers)(void);
 	void (*register_clocks)(void);
+	void (*sysirq_mask)(void);
 	void (*init)(void);
 };
 
Signature · 12 lines
1.8.1.1

-- 
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe at googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
#5 lore raw
Quoted 40 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 27 lines · Johan Hovold

Make sure the RTC and RTT-interrupts are masked at boot by adding a new SOC-initialiser and helpers functions.

This fixes hanged boot on all AT91 SOCs but RM9200, for example, after a reset during an RTC-update or if an RTC or RTT-alarm goes off after a non-clean shutdown.

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

Tested on at91sam9263 and at91sam9g45.

Quoted 12 lines
---
 arch/arm/mach-at91/at91rm9200.c               |  9 ++++++++
 arch/arm/mach-at91/at91sam9260.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9261.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9263.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9g45.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9n12.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9rl.c               |  7 ++++++
 arch/arm/mach-at91/at91sam9x5.c               |  6 ++++++
 arch/arm/mach-at91/generic.h                  |  2 ++
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 +++++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 +++++
Quoted 1 line

nack for DT probe te address via DT

Fair enough. I'll respin and add proper DT-support.

Quoted 5 lines
Quoted 3 lines
 arch/arm/mach-at91/setup.c                    | 31 +++++++++++++++++++++++++++
 arch/arm/mach-at91/soc.h                      |  1 +
 13 files changed, 98 insertions(+)

at boot time we can disable all the irq as we need none of them

Yes, but all but the VDDBU-powered-peripheral ones will already have been disabled at reset. If a buggy bootloader enables something it should not, then the bootloader should be fixed.

Quoted 8 lines
Quoted 8 lines
arch/arm/mach-at91/at91rm9200.c +0 -0
index 7aeb473..4651ebb 100644
@@ -325,6 +325,14 @@ static void __init at91rm9200_ioremap_registers(void)
 	at91_ioremap_ramc(0, AT91RM9200_BASE_MC, 256);
 }
 
Quoted 8 lines

arch/arm/mach-at91/at91rm9200.c static void __init at91rm9200_ioremap_registers(void) · line 334

Quoted 7 lines
arch/arm/mach-at91/at91rm9200.c +7 -0
+static void __init at91rm9200_sysirq_mask(void)
+{
+	/*
+	 * No need to mask any system interrupts as the RM9200 has no backup
+	 * power and resets all system peripherals at every reset.
+	 */
+}

no need drop it

Ok.

Thanks,
Johan

Quoted 11 lines
Quoted 11 lines
arch/arm/mach-at91/at91rm9200.c +2 -0
+
 static void __init at91rm9200_initialize(void)
 {
 	arm_pm_idle = at91rm9200_idle;
@@ -387,5 +395,6 @@ AT91_SOC_START(rm9200)
 	.default_irq_priority = at91rm9200_default_irq_priority,
 	.ioremap_registers = at91rm9200_ioremap_registers,
 	.register_clocks = at91rm9200_register_clocks,
+	.sysirq_mask = at91rm9200_sysirq_mask,
 	.init = at91rm9200_initialize,
 AT91_SOC_END
#6 lore raw
Quoted 49 lines · Johan Hovold
Quoted 40 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 27 lines · Johan Hovold

Make sure the RTC and RTT-interrupts are masked at boot by adding a new SOC-initialiser and helpers functions.

This fixes hanged boot on all AT91 SOCs but RM9200, for example, after a reset during an RTC-update or if an RTC or RTT-alarm goes off after a non-clean shutdown.

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

Tested on at91sam9263 and at91sam9g45.

Quoted 12 lines
---
 arch/arm/mach-at91/at91rm9200.c               |  9 ++++++++
 arch/arm/mach-at91/at91sam9260.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9261.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9263.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9g45.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9n12.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9rl.c               |  7 ++++++
 arch/arm/mach-at91/at91sam9x5.c               |  6 ++++++
 arch/arm/mach-at91/generic.h                  |  2 ++
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 +++++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 +++++
Quoted 1 line

nack for DT probe te address via DT

Fair enough. I'll respin and add proper DT-support.

Quoted 4 lines
Quoted 3 lines
 arch/arm/mach-at91/setup.c                    | 31 +++++++++++++++++++++++++++
 arch/arm/mach-at91/soc.h                      |  1 +
 13 files changed, 98 insertions(+)
Quoted 5 lines
Quoted 1 line

at boot time we can disable all the irq as we need none of them

Yes, but all but the VDDBU-powered-peripheral ones will already have been disabled at reset. If a buggy bootloader enables something it should not, then the bootloader should be fixed.

so fix the bootloader NACK in the kernel
it's too much ugly

the kernel requirere the interrupt to be disabled

Best Regards,
J.

#7 lore raw
Quoted 50 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 49 lines · Johan Hovold
Quoted 40 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 27 lines · Johan Hovold

Make sure the RTC and RTT-interrupts are masked at boot by adding a new SOC-initialiser and helpers functions.

This fixes hanged boot on all AT91 SOCs but RM9200, for example, after a reset during an RTC-update or if an RTC or RTT-alarm goes off after a non-clean shutdown.

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

Tested on at91sam9263 and at91sam9g45.

Quoted 12 lines
---
 arch/arm/mach-at91/at91rm9200.c               |  9 ++++++++
 arch/arm/mach-at91/at91sam9260.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9261.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9263.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9g45.c              |  7 ++++++
 arch/arm/mach-at91/at91sam9n12.c              |  6 ++++++
 arch/arm/mach-at91/at91sam9rl.c               |  7 ++++++
 arch/arm/mach-at91/at91sam9x5.c               |  6 ++++++
 arch/arm/mach-at91/generic.h                  |  2 ++
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 +++++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 +++++
Quoted 1 line

nack for DT probe te address via DT

Fair enough. I'll respin and add proper DT-support.

Quoted 4 lines
Quoted 3 lines
 arch/arm/mach-at91/setup.c                    | 31 +++++++++++++++++++++++++++
 arch/arm/mach-at91/soc.h                      |  1 +
 13 files changed, 98 insertions(+)
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

at boot time we can disable all the irq as we need none of them

Yes, but all but the VDDBU-powered-peripheral ones will already have been disabled at reset. If a buggy bootloader enables something it should not, then the bootloader should be fixed.

so fix the bootloader NACK in the kernel

If it had been enabled by the bootloader, it would no doubt be a bootloader bug. The problem is that bootloader may not know anything about RTT/RTC and it was Linux that enabled the interrupts in the first place. The question is whether it should still be the bootloader's responsibility to clean it up.

Quoted 1 line

it's too much ugly

Agreed, but this needs to be fixed somewhere.

Quoted 1 line

the kernel requirere the interrupt to be disabled

And this is the problem -- the interrupts _are_ disabled when the kernel is executed. It is Linux that enables the system interrupt without making sure it can handle the interrupts that could arrive.

But sure, I can see arguments in favor of either solution (fix in bootloader or kernel).

It is a severe bug, which affects all AT91 systems (but RM9200). It's fairly hard to track down, and this has apparently already been done over and over again. In my opinion, fixing it once and for all in the kernel has some appeal.

To give an idea of what it could look like, I'm responding to this mail with with a v2 of my series with added DT-support (the DT-bits are compile-only tested).

Thanks,
Johan

#8 lore raw

v2 cover ARM: at91: fix hanged boot

These patches fix a few severe issues affecting most AT91 SOCs where boot can hang after a non-general reset, and where the only way to get the system booting again is to do a general reset -- something which could require physically removing any backup battery.

The problems stem from the fact that the RTC and RTT-peripherals are powered by backup power (VDDBU) and are not reset on wake-up, user, watchdog or software reset. Consequently, RTC and RTT-alarms and their interrupts may be enabled at boot, leading to a system lock-up when an interrupt arrives on the shared system-interrupt line before the appropriate handler (e.g. RTC-driver) has been installed.

The easiest way to trigger this is to simply wake up from an RTC-alarm on at91sam9g45. The RTC-driver currently does not disable interrupts at shutdown so even after a clean shut-down the system will always hang after waking up.

The first patch fixes this very general case of RTC-wake up after a clean shutdown in the RTC-driver and is marked for stable as it is perfectly straight-forward. [ Note that the other, RTT-based, AT91 RTC-driver already disables its interrupts at shutdown. ]

The more general problem can be triggered, for example, by doing a user-reset while updating the RTC-time or if an RTC or RTT-alarm goes off after a non-clean shutdown.

To fix this I propose that arch-code should mask the relevant interrupts before enabling the system interrupt at early boot, and this is what the fifth patch does. To access the RTC-registers I choose to revert a recent patch that moved the register definitions to drivers/rtc.

Arguably, the relevant interrupts could also be disabled in bootloaders, but I suggest fixing it in the kernel once and for all.

The patches have been tested on at91sam9263 and at91sam9g45 (non-DT), and compile-tested for the other SOCs and DT.

Johan

v2:
- add DT-support
- make sys_irq_mask non-mandatory

Johan Hovold (5):
ARM: at91/rtc: fix boot after RTC wake-up
ARM: at91/dts: add RTC nodes
ARM: at91/dts: add RTT nodes
Revert "arm: at91: move at91rm9200 rtc header in drivers/rtc"
ARM: at91: fix hanged boot

 arch/arm/boot/dts/at91rm9200.dtsi          |  5 ++
 arch/arm/boot/dts/at91sam9260.dtsi         |  5 ++
 arch/arm/boot/dts/at91sam9263.dtsi         | 10 ++++
 arch/arm/boot/dts/at91sam9g45.dtsi         | 10 ++++
 arch/arm/boot/dts/at91sam9n12.dtsi         |  5 ++
 arch/arm/boot/dts/at91sam9x5.dtsi          |  5 ++
 arch/arm/mach-at91/at91sam9260.c           |  6 ++
 arch/arm/mach-at91/at91sam9261.c           |  6 ++
 arch/arm/mach-at91/at91sam9263.c           |  7 +++
 arch/arm/mach-at91/at91sam9g45.c           |  7 +++
 arch/arm/mach-at91/at91sam9rl.c            |  7 +++
 arch/arm/mach-at91/generic.h               |  2 +
 arch/arm/mach-at91/include/mach/at91_rtc.h | 75 +++++++++++++++++++++++++
 arch/arm/mach-at91/setup.c                 | 88 ++++++++++++++++++++++++++++++
 arch/arm/mach-at91/soc.h                   |  1 +
 drivers/rtc/rtc-at91rm9200.c               | 11 +++-
 drivers/rtc/rtc-at91rm9200.h               | 75 -------------------------
 17 files changed, 249 insertions(+), 76 deletions(-)
 create mode 100644 arch/arm/mach-at91/include/mach/at91_rtc.h
 delete mode 100644 drivers/rtc/rtc-at91rm9200.h
Signature · 1 line
1.8.1.5
#9 lore raw

PATCH v2 1/5 ARM: at91/rtc: fix boot after RTC wake-up

Fix failed boot after RTC wake-up by making sure RTC-interrupts are disabled at shutdown.

The RTC-registers are not reset at shutdown when there is backup power available, and hence the RTC-interrupt, which uses the shared system interrupt, may be enabled during early boot. If an RTC-alarm goes off before the RTC-driver is initialised (e.g. when waking up from an RTC-alarm) this results in disabled system interrupts.

Without earlyprintk boot hangs after

Uncompressing Linux... done, booting the kernel.

and earlyprintk reveals that the shared system interrupt gets disabled:

irq 17: nobody cared (try booting with the "irqpoll" option)
[<c000cf8c>] (unwind_backtrace+0x0/0xf0) from [<c00513ec>] (__report_bad_irq+0x20/0xe8) [<c00513ec>] (__report_bad_irq+0x20/0xe8) from [<c00516fc>] (note_interrupt+0x1e0/0x244) [<c00516fc>] (note_interrupt+0x1e0/0x244) from [<c004f980>] (handle_irq_event_percpu+0xac/0x1c4) [<c004f980>] (handle_irq_event_percpu+0xac/0x1c4) from [<c004faec>] (handle_irq_event+0x54/0x84) [<c004faec>] (handle_irq_event+0x54/0x84) from [<c0052364>] (handle_fasteoi_irq+0x84/0x154) [<c0052364>] (handle_fasteoi_irq+0x84/0x154) from [<c004f1f8>] (generic_handle_irq+0x20/0x30) [<c004f1f8>] (generic_handle_irq+0x20/0x30) from [<c0009b8c>] (handle_IRQ+0x30/0x84) [<c0009b8c>] (handle_IRQ+0x30/0x84) from [<c0008fa0>] (__irq_svc+0x40/0x6c) [<c0008fa0>] (__irq_svc+0x40/0x6c) from [<c001cd6c>] (__do_softirq+0x5c/0x164) [<c001cd6c>] (__do_softirq+0x5c/0x164) from [<c001d268>] (irq_exit+0x58/0x60) [<c001d268>] (irq_exit+0x58/0x60) from [<c0009b90>] (handle_IRQ+0x34/0x84) [<c0009b90>] (handle_IRQ+0x34/0x84) from [<c0008fa0>] (__irq_svc+0x40/0x6c) [<c0008fa0>] (__irq_svc+0x40/0x6c) from [<c03e668c>] (start_kernel+0x1d8/0x29c) [<c03e668c>] (start_kernel+0x1d8/0x29c) from [<70008040>] (0x70008040)
handlers:
[<c0012df0>] at91sam926x_pit_interrupt
Disabling IRQ #17

Note that disabling the RTC-interrupts at shutdown fixes boot after a clean shutdown, but that an RTC-alarm after a user (or watchdog) reset could still prevent the system from booting.

Note also that the only way to recover from a failed boot after an RTC-alarm is to remove any backup power (e.g. backup battery) or to disable (or acknowledge) the RTC-interrupt manually from the bootloader. In particular, a user-reset is not sufficient.

Tested on at91sam9g45.

---
 drivers/rtc/rtc-at91rm9200.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/rtc/rtc-at91rm9200.c +9 -0
index b6469e2..936c75a 100644
@@ -338,6 +338,14 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void at91_rtc_shutdown(struct platform_device *pdev)
+{
+	/* Disable all interrupts */
+	at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
+					AT91_RTC_SECEV | AT91_RTC_TIMEV |
+					AT91_RTC_CALEV);
+}
+
 #ifdef CONFIG_PM
 
 /* AT91RM9200 RTC Power management control */
@@ -384,6 +392,7 @@ static const struct dev_pm_ops at91_rtc_pm = {
 
 static struct platform_driver at91_rtc_driver = {
 	.remove		= __exit_p(at91_rtc_remove),
+	.shutdown	= at91_rtc_shutdown,
 	.driver		= {
 		.name	= "at91_rtc",
 		.owner	= THIS_MODULE,
Signature · 1 line
1.8.1.5
#10 lore raw

PATCH v2 2/5 ARM: at91/dts: add RTC nodes

In reply to Johan Hovold

Add RTC nodes for Atmel SOCs.

Use two different compatible properties to reflect the fact that the RTC-peripherals are backup powered (VDDBU) and are thus not reset on wake-up, user, watchdog or software reset on all SOCs but at91rm9200.

---
 arch/arm/boot/dts/at91rm9200.dtsi  | 5 +++++
 arch/arm/boot/dts/at91sam9g45.dtsi | 5 +++++
 arch/arm/boot/dts/at91sam9n12.dtsi | 5 +++++
 arch/arm/boot/dts/at91sam9x5.dtsi  | 5 +++++
 4 files changed, 20 insertions(+)
arch/arm/boot/dts/at91rm9200.dtsi +5 -0
index 222047f..96b4e30 100644
@@ -326,6 +326,11 @@
 			status = "disabled";
 		};
 
+		rtc at fffffe00 {
+			compatible = "atmel,at91rm9200-rtc";
+			reg = <0xfffffe00 0x30>;
+		};
+
 		usb0: ohci at 00300000 {
 			compatible = "atmel,at91rm9200-ohci", "usb-ohci";
 			reg = <0x00300000 0x100000>;
arch/arm/boot/dts/at91sam9g45.dtsi +5 -0
index 6b1d4ca..c1ad522 100644
@@ -526,6 +526,11 @@
 				status = "disabled";
 			};
 
+			rtc at fffffdb0 {
+				compatible = "atmel,at91sam9g45-rtc";
+				reg = <0xfffffdb0 0x30>;
+			};
+
 			watchdog at fffffd40 {
 				compatible = "atmel,at91sam9260-wdt";
 				reg = <0xfffffd40 0x10>;
arch/arm/boot/dts/at91sam9n12.dtsi +5 -0
index 4801717..802e92f 100644
@@ -311,6 +311,11 @@
 				status = "disabled";
 			};
 
+			rtc at fffffeb0 {
+				compatible = "atmel,at91sam9g45-rtc";
+				reg = <0xfffffeb0 0x30>;
+			};
+
 			ssc0: ssc at f0010000 {
 				compatible = "atmel,at91sam9g45-ssc";
 				reg = <0xf0010000 0x4000>;
arch/arm/boot/dts/at91sam9x5.dtsi +5 -0
index c461e11..432fbfb 100644
@@ -362,6 +362,11 @@
 				};
 			};
 
+			rtc at fffffeb0 {
+				compatible = "atmel,at91sam9g45-rtc";
+				reg = <0xfffffeb0 0x30>;
+			};
+
 			ssc0: ssc at f0010000 {
 				compatible = "atmel,at91sam9g45-ssc";
 				reg = <0xf0010000 0x4000>;
Signature · 1 line
1.8.1.5
#11 lore raw

PATCH v2 3/5 ARM: at91/dts: add RTT nodes

In reply to Johan Hovold

Add RTT nodes for Atmel SOCs.

---
 arch/arm/boot/dts/at91sam9260.dtsi |  5 +++++
 arch/arm/boot/dts/at91sam9263.dtsi | 10 ++++++++++
 arch/arm/boot/dts/at91sam9g45.dtsi |  5 +++++
 3 files changed, 20 insertions(+)
arch/arm/boot/dts/at91sam9260.dtsi +5 -0
index cb7bcc5..3a7a8dd 100644
@@ -462,6 +462,11 @@
 				status = "disabled";
 			};
 
+			rtt at fffffd20 {
+				compatible = "atmel,at91sam9260-rtt";
+				reg = <0xfffffd20 0x10>;
+			};
+
 			ssc0: ssc at fffbc000 {
 				compatible = "atmel,at91rm9200-ssc";
 				reg = <0xfffbc000 0x4000>;
arch/arm/boot/dts/at91sam9263.dtsi +10 -0
index 271d4de..3a44382 100644
@@ -457,6 +457,16 @@
 				status = "disabled";
 			};
 
+			rtt at fffffd20 {
+				compatible = "atmel,at91sam9260-rtt";
+				reg = <0xfffffd20 0x10>;
+			};
+
+			rtt at fffffd50 {
+				compatible = "atmel,at91sam9260-rtt";
+				reg = <0xfffffd50 0x10>;
+			};
+
 			watchdog at fffffd40 {
 				compatible = "atmel,at91sam9260-wdt";
 				reg = <0xfffffd40 0x10>;
arch/arm/boot/dts/at91sam9g45.dtsi +5 -0
index c1ad522..750b696 100644
@@ -531,6 +531,11 @@
 				reg = <0xfffffdb0 0x30>;
 			};
 
+			rtt at fffffd20 {
+				compatible = "atmel,at91sam9260-rtt";
+				reg = <0xfffffd20 0x10>;
+			};
+
 			watchdog at fffffd40 {
 				compatible = "atmel,at91sam9260-wdt";
 				reg = <0xfffffd40 0x10>;
Signature · 1 line
1.8.1.5
#12 lore raw

PATCH v2 4/5 Revert "arm: at91: move at91rm9200 rtc header in drivers/rtc"

In reply to Johan Hovold

This reverts commit 75984df05d86956541795f01e62d7dc67bc522fd.

A couple of these register definitions are needed by arch code as the RTC-interrupts must be disabled at early boot.

---
 arch/arm/mach-at91/include/mach/at91_rtc.h | 75 ++++++++++++++++++++++++++++++
 drivers/rtc/rtc-at91rm9200.c               |  2 +-
 drivers/rtc/rtc-at91rm9200.h               | 75 ------------------------------
 3 files changed, 76 insertions(+), 76 deletions(-)
 create mode 100644 arch/arm/mach-at91/include/mach/at91_rtc.h
 delete mode 100644 drivers/rtc/rtc-at91rm9200.h
arch/arm/mach-at91/include/mach/at91_rtc.h new file +75 -0
new file mode 100644
index 0000000..da1945e
@@ -0,0 +1,75 @@
+/*
+ * arch/arm/mach-at91/include/mach/at91_rtc.h
+ *
+ * Copyright (C) 2005 Ivan Kokshaysky
+ * Copyright (C) SAN People
+ *
+ * Real Time Clock (RTC) - System peripheral registers.
+ * Based on AT91RM9200 datasheet revision E.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef AT91_RTC_H
+#define AT91_RTC_H
+
+#define	AT91_RTC_CR		0x00			/* Control Register */
+#define		AT91_RTC_UPDTIM		(1 <<  0)		/* Update Request Time Register */
+#define		AT91_RTC_UPDCAL		(1 <<  1)		/* Update Request Calendar Register */
+#define		AT91_RTC_TIMEVSEL	(3 <<  8)		/* Time Event Selection */
+#define			AT91_RTC_TIMEVSEL_MINUTE	(0 << 8)
+#define			AT91_RTC_TIMEVSEL_HOUR		(1 << 8)
+#define			AT91_RTC_TIMEVSEL_DAY24		(2 << 8)
+#define			AT91_RTC_TIMEVSEL_DAY12		(3 << 8)
+#define		AT91_RTC_CALEVSEL	(3 << 16)		/* Calendar Event Selection */
+#define			AT91_RTC_CALEVSEL_WEEK		(0 << 16)
+#define			AT91_RTC_CALEVSEL_MONTH		(1 << 16)
+#define			AT91_RTC_CALEVSEL_YEAR		(2 << 16)
+
+#define	AT91_RTC_MR		0x04			/* Mode Register */
+#define			AT91_RTC_HRMOD		(1 <<  0)		/* 12/24 Hour Mode */
+
+#define	AT91_RTC_TIMR		0x08			/* Time Register */
+#define		AT91_RTC_SEC		(0x7f <<  0)		/* Current Second */
+#define		AT91_RTC_MIN		(0x7f <<  8)		/* Current Minute */
+#define		AT91_RTC_HOUR		(0x3f << 16)		/* Current Hour */
+#define		AT91_RTC_AMPM		(1    << 22)		/* Ante Meridiem Post Meridiem Indicator */
+
+#define	AT91_RTC_CALR		0x0c			/* Calendar Register */
+#define		AT91_RTC_CENT		(0x7f <<  0)		/* Current Century */
+#define		AT91_RTC_YEAR		(0xff <<  8)		/* Current Year */
+#define		AT91_RTC_MONTH		(0x1f << 16)		/* Current Month */
+#define		AT91_RTC_DAY		(7    << 21)		/* Current Day */
+#define		AT91_RTC_DATE		(0x3f << 24)		/* Current Date */
+
+#define	AT91_RTC_TIMALR		0x10			/* Time Alarm Register */
+#define		AT91_RTC_SECEN		(1 <<  7)		/* Second Alarm Enable */
+#define		AT91_RTC_MINEN		(1 << 15)		/* Minute Alarm Enable */
+#define		AT91_RTC_HOUREN		(1 << 23)		/* Hour Alarm Enable */
+
+#define	AT91_RTC_CALALR		0x14			/* Calendar Alarm Register */
+#define		AT91_RTC_MTHEN		(1 << 23)		/* Month Alarm Enable */
+#define		AT91_RTC_DATEEN		(1 << 31)		/* Date Alarm Enable */
+
+#define	AT91_RTC_SR		0x18			/* Status Register */
+#define		AT91_RTC_ACKUPD		(1 <<  0)		/* Acknowledge for Update */
+#define		AT91_RTC_ALARM		(1 <<  1)		/* Alarm Flag */
+#define		AT91_RTC_SECEV		(1 <<  2)		/* Second Event */
+#define		AT91_RTC_TIMEV		(1 <<  3)		/* Time Event */
+#define		AT91_RTC_CALEV		(1 <<  4)		/* Calendar Event */
+
+#define	AT91_RTC_SCCR		0x1c			/* Status Clear Command Register */
+#define	AT91_RTC_IER		0x20			/* Interrupt Enable Register */
+#define	AT91_RTC_IDR		0x24			/* Interrupt Disable Register */
+#define	AT91_RTC_IMR		0x28			/* Interrupt Mask Register */
+
+#define	AT91_RTC_VER		0x2c			/* Valid Entry Register */
+#define		AT91_RTC_NVTIM		(1 <<  0)		/* Non valid Time */
+#define		AT91_RTC_NVCAL		(1 <<  1)		/* Non valid Calendar */
+#define		AT91_RTC_NVTIMALR	(1 <<  2)		/* Non valid Time Alarm */
+#define		AT91_RTC_NVCALALR	(1 <<  3)		/* Non valid Calendar Alarm */
+
+#endif
drivers/rtc/rtc-at91rm9200.c +1 -1
index 936c75a..1ed0433 100644
@@ -31,7 +31,7 @@
 
 #include <asm/uaccess.h>
 
-#include "rtc-at91rm9200.h"
+#include <mach/at91_rtc.h>
 
 #define at91_rtc_read(field) \
 	__raw_readl(at91_rtc_regs + field)
drivers/rtc/rtc-at91rm9200.h deleted +0 -75

75 lines not on this page · raw message

Signature · 1 line
1.8.1.5
#13 lore raw

PATCH v2 5/5 ARM: at91: fix hanged boot

In reply to Johan Hovold

Make sure the RTC and RTT-interrupts are masked at boot by adding a new SOC-initialiser and helpers functions.

This fixes hanged boot on all AT91 SOCs but RM9200, for example, after a reset during an RTC-update or if an RTC or RTT-alarm goes off after a non-clean shutdown.

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

Tested on at91sam9263 and at91sam9g45.

---
 arch/arm/mach-at91/at91sam9260.c |  6 +++
 arch/arm/mach-at91/at91sam9261.c |  6 +++
 arch/arm/mach-at91/at91sam9263.c |  7 ++++
 arch/arm/mach-at91/at91sam9g45.c |  7 ++++
 arch/arm/mach-at91/at91sam9rl.c  |  7 ++++
 arch/arm/mach-at91/generic.h     |  2 +
 arch/arm/mach-at91/setup.c       | 88 ++++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-at91/soc.h         |  1 +
 8 files changed, 124 insertions(+)
arch/arm/mach-at91/at91sam9260.c +6 -0
index b67cd53..c47a0db 100644
@@ -342,6 +342,11 @@ static void __init at91sam9260_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9260_BASE_MATRIX);
 }
 
+static void __init at91sam9260_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT);
+}
+
 static void __init at91sam9260_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -400,5 +405,6 @@ AT91_SOC_START(sam9260)
 	.default_irq_priority = at91sam9260_default_irq_priority,
 	.ioremap_registers = at91sam9260_ioremap_registers,
 	.register_clocks = at91sam9260_register_clocks,
+	.sysirq_mask = at91sam9260_sysirq_mask,
 	.init = at91sam9260_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9261.c +6 -0
index 0204f4c..396e4cb 100644
@@ -286,6 +286,11 @@ static void __init at91sam9261_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9261_BASE_MATRIX);
 }
 
+static void __init at91sam9261_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
+}
+
 static void __init at91sam9261_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -344,5 +349,6 @@ AT91_SOC_START(sam9261)
 	.default_irq_priority = at91sam9261_default_irq_priority,
 	.ioremap_registers = at91sam9261_ioremap_registers,
 	.register_clocks = at91sam9261_register_clocks,
+	.sysirq_mask = at91sam9261_sysirq_mask,
 	.init = at91sam9261_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9263.c +7 -0
index c0cbb81..a0166a3 100644
@@ -325,6 +325,12 @@ static void __init at91sam9263_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9263_BASE_MATRIX);
 }
 
+static void __init at91sam9263_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0);
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1);
+}
+
 static void __init at91sam9263_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -382,5 +388,6 @@ AT91_SOC_START(sam9263)
 	.default_irq_priority = at91sam9263_default_irq_priority,
 	.ioremap_registers = at91sam9263_ioremap_registers,
 	.register_clocks = at91sam9263_register_clocks,
+	.sysirq_mask = at91sam9263_sysirq_mask,
 	.init = at91sam9263_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9g45.c +7 -0
index b4968aa..3d5498e 100644
@@ -370,6 +370,12 @@ static void __init at91sam9g45_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9G45_BASE_MATRIX);
 }
 
+static void __init at91sam9g45_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT);
+}
+
 static void __init at91sam9g45_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -427,5 +433,6 @@ AT91_SOC_START(sam9g45)
 	.default_irq_priority = at91sam9g45_default_irq_priority,
 	.ioremap_registers = at91sam9g45_ioremap_registers,
 	.register_clocks = at91sam9g45_register_clocks,
+	.sysirq_mask = at91sam9g45_sysirq_mask,
 	.init = at91sam9g45_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9rl.c +7 -0
index 3de3e04..bde999f 100644
@@ -289,6 +289,12 @@ static void __init at91sam9rl_ioremap_registers(void)
 	at91_ioremap_matrix(AT91SAM9RL_BASE_MATRIX);
 }
 
+static void __init at91sam9rl_sysirq_mask(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT);
+}
+
 static void __init at91sam9rl_initialize(void)
 {
 	arm_pm_idle = at91sam9_idle;
@@ -346,5 +352,6 @@ AT91_SOC_START(sam9rl)
 	.default_irq_priority = at91sam9rl_default_irq_priority,
 	.ioremap_registers = at91sam9rl_ioremap_registers,
 	.register_clocks = at91sam9rl_register_clocks,
+	.sysirq_mask = at91sam9rl_sysirq_mask,
 	.init = at91sam9rl_initialize,
 AT91_SOC_END
arch/arm/mach-at91/generic.h +2 -0
index fc593d6..90a854d 100644
@@ -33,6 +33,8 @@ extern int  __init at91_aic_of_init(struct device_node *node,
 				    struct device_node *parent);
 extern int  __init at91_aic5_of_init(struct device_node *node,
 				    struct device_node *parent);
+extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
+extern void __init at91_sysirq_mask_rtt(u32 rtt_base);
 
 
  /* Timer */
arch/arm/mach-at91/setup.c +88 -0

117 lines not on this page · raw message

arch/arm/mach-at91/soc.h +1 -0
index 9c6d3d4..134f4c4 100644
@@ -10,6 +10,7 @@ struct at91_init_soc {
 	void (*map_io)(void);
 	void (*ioremap_registers)(void);
 	void (*register_clocks)(void);
+	void (*sysirq_mask)(void);
 	void (*init)(void);
 };
 
Signature · 1 line
1.8.1.5
#14 lore raw
In reply to Johan Hovold
Quoted 4 lines · Johan Hovold

These patches fix a few severe issues affecting most AT91 SOCs where boot can hang after a non-general reset, and where the only way to get the system booting again is to do a general reset -- something which could require physically removing any backup battery.

Have you had time to look at these patches yet, Nicolas?

I don't think not having decided on the path forward for DT-support for rtc-at91sam9 needs to be a blocker. The rtt-nodes will be needed in any case.

I could respin the series on top of the DT-patch for rtc-at91rm9200, and add interrupt and status-disabled properties to the DT-nodes as well.

Thanks,
Johan

Quoted 46 lines

The problems stem from the fact that the RTC and RTT-peripherals are powered by backup power (VDDBU) and are not reset on wake-up, user, watchdog or software reset. Consequently, RTC and RTT-alarms and their interrupts may be enabled at boot, leading to a system lock-up when an interrupt arrives on the shared system-interrupt line before the appropriate handler (e.g. RTC-driver) has been installed.

The easiest way to trigger this is to simply wake up from an RTC-alarm on at91sam9g45. The RTC-driver currently does not disable interrupts at shutdown so even after a clean shut-down the system will always hang after waking up.

The first patch fixes this very general case of RTC-wake up after a clean shutdown in the RTC-driver and is marked for stable as it is perfectly straight-forward. [ Note that the other, RTT-based, AT91 RTC-driver already disables its interrupts at shutdown. ]

The more general problem can be triggered, for example, by doing a user-reset while updating the RTC-time or if an RTC or RTT-alarm goes off after a non-clean shutdown.

To fix this I propose that arch-code should mask the relevant interrupts before enabling the system interrupt at early boot, and this is what the fifth patch does. To access the RTC-registers I choose to revert a recent patch that moved the register definitions to drivers/rtc.

Arguably, the relevant interrupts could also be disabled in bootloaders, but I suggest fixing it in the kernel once and for all.

The patches have been tested on at91sam9263 and at91sam9g45 (non-DT), and compile-tested for the other SOCs and DT.

Johan

v2:
- add DT-support
- make sys_irq_mask non-mandatory

Johan Hovold (5):
ARM: at91/rtc: fix boot after RTC wake-up
ARM: at91/dts: add RTC nodes
ARM: at91/dts: add RTT nodes
Revert "arm: at91: move at91rm9200 rtc header in drivers/rtc"
ARM: at91: fix hanged boot

#15 lore raw
Quoted 6 lines · Johan Hovold
Quoted 4 lines · Johan Hovold

These patches fix a few severe issues affecting most AT91 SOCs where boot can hang after a non-general reset, and where the only way to get the system booting again is to do a general reset -- something which could require physically removing any backup battery.

Quoted 8 lines

Have you had time to look at these patches yet, Nicolas?

I don't think not having decided on the path forward for DT-support for rtc-at91sam9 needs to be a blocker. The rtt-nodes will be needed in any case.

I could respin the series on top of the DT-patch for rtc-at91rm9200, and add interrupt and status-disabled properties to the DT-nodes as well.

for this this is still a no go

this way too much ugly

Best Regards,
J.

Quoted 63 lines

Thanks,
Johan

Quoted 46 lines

The problems stem from the fact that the RTC and RTT-peripherals are powered by backup power (VDDBU) and are not reset on wake-up, user, watchdog or software reset. Consequently, RTC and RTT-alarms and their interrupts may be enabled at boot, leading to a system lock-up when an interrupt arrives on the shared system-interrupt line before the appropriate handler (e.g. RTC-driver) has been installed.

The easiest way to trigger this is to simply wake up from an RTC-alarm on at91sam9g45. The RTC-driver currently does not disable interrupts at shutdown so even after a clean shut-down the system will always hang after waking up.

The first patch fixes this very general case of RTC-wake up after a clean shutdown in the RTC-driver and is marked for stable as it is perfectly straight-forward. [ Note that the other, RTT-based, AT91 RTC-driver already disables its interrupts at shutdown. ]

The more general problem can be triggered, for example, by doing a user-reset while updating the RTC-time or if an RTC or RTT-alarm goes off after a non-clean shutdown.

To fix this I propose that arch-code should mask the relevant interrupts before enabling the system interrupt at early boot, and this is what the fifth patch does. To access the RTC-registers I choose to revert a recent patch that moved the register definitions to drivers/rtc.

Arguably, the relevant interrupts could also be disabled in bootloaders, but I suggest fixing it in the kernel once and for all.

The patches have been tested on at91sam9263 and at91sam9g45 (non-DT), and compile-tested for the other SOCs and DT.

Johan

v2:
- add DT-support
- make sys_irq_mask non-mandatory

Johan Hovold (5):
ARM: at91/rtc: fix boot after RTC wake-up
ARM: at91/dts: add RTC nodes
ARM: at91/dts: add RTT nodes
Revert "arm: at91: move at91rm9200 rtc header in drivers/rtc"
ARM: at91: fix hanged boot

Signature · 9 lines
-- 
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
--- 
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe at googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
#16 lore raw
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 12 lines · Johan Hovold
Quoted 4 lines · Johan Hovold

These patches fix a few severe issues affecting most AT91 SOCs where boot can hang after a non-general reset, and where the only way to get the system booting again is to do a general reset -- something which could require physically removing any backup battery.

Have you had time to look at these patches yet, Nicolas?

I don't think not having decided on the path forward for DT-support for rtc-at91sam9 needs to be a blocker. The rtt-nodes will be needed in any case.

Quoted 5 lines
Quoted 2 lines

I could respin the series on top of the DT-patch for rtc-at91rm9200, and add interrupt and status-disabled properties to the DT-nodes as well.

for this this is still a no go

this way too much ugly

I understand that you prefer fixing every bootloader. I was just making sure everyone agrees that that is the best solution.

The two interrupt masks has to be cleared before the kernel enables the system interrupt; either it needs to be done by the bootloader or by the at91 arch code.

The various bootloaders may not know anything about RTT or RTC, but have all made sure interrupts are disabled before executing the kernel. That is, they have fulfilled the requirement that interrupts must be disabled.

So the trade-off seems to be: Either we fix this once and for all using the infrastructure already in place in the kernel (DT), or risk further (apparently) bricked systems as there are bound to be bootloaders that won't get updated.

[...]

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

The problems stem from the fact that the RTC and RTT-peripherals are powered by backup power (VDDBU) and are not reset on wake-up, user, watchdog or software reset. Consequently, RTC and RTT-alarms and their interrupts may be enabled at boot, leading to a system lock-up when an interrupt arrives on the shared system-interrupt line before the appropriate handler (e.g. RTC-driver) has been installed.

The easiest way to trigger this is to simply wake up from an RTC-alarm on at91sam9g45. The RTC-driver currently does not disable interrupts at shutdown so even after a clean shut-down the system will always hang after waking up.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The first patch fixes this very general case of RTC-wake up after a clean shutdown in the RTC-driver and is marked for stable as it is perfectly straight-forward. [ Note that the other, RTT-based, AT91 RTC-driver already disables its interrupts at shutdown. ]

And what about this patch? If it's decided that every bootloader needs to be updated, then perhaps it's better to risk bricked systems also after a clean shutdown to enforce those updates? Should we then remove the corresponding disable of interrupts at shutdown from the rtc-at91sam9 driver by the same logic?

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

The more general problem can be triggered, for example, by doing a user-reset while updating the RTC-time or if an RTC or RTT-alarm goes off after a non-clean shutdown.

To fix this I propose that arch-code should mask the relevant interrupts before enabling the system interrupt at early boot, and this is what the fifth patch does. To access the RTC-registers I choose to revert a recent patch that moved the register definitions to drivers/rtc.

Arguably, the relevant interrupts could also be disabled in bootloaders, but I suggest fixing it in the kernel once and for all.

Thanks,
Johan

#17 lore raw

On 04/12/2013 11:33 AM, Johan Hovold :

Quoted 32 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 13 lines · Johan Hovold
Quoted 12 lines · Johan Hovold
Quoted 4 lines

These patches fix a few severe issues affecting most AT91 SOCs where boot can hang after a non-general reset, and where the only way to get the system booting again is to do a general reset -- something which could require physically removing any backup battery.

Have you had time to look at these patches yet, Nicolas?

I don't think not having decided on the path forward for DT-support for rtc-at91sam9 needs to be a blocker. The rtt-nodes will be needed in any case.

Quoted 5 lines
Quoted 2 lines

I could respin the series on top of the DT-patch for rtc-at91rm9200, and add interrupt and status-disabled properties to the DT-nodes as well.

for this this is still a no go

this way too much ugly

I understand that you prefer fixing every bootloader. I was just making sure everyone agrees that that is the best solution.

The two interrupt masks has to be cleared before the kernel enables the system interrupt; either it needs to be done by the bootloader or by the at91 arch code.

The various bootloaders may not know anything about RTT or RTC, but have all made sure interrupts are disabled before executing the kernel. That is, they have fulfilled the requirement that interrupts must be disabled.

Quoted 4 lines

So the trade-off seems to be: Either we fix this once and for all using the infrastructure already in place in the kernel (DT), or risk further (apparently) bricked systems as there are bound to be bootloaders that won't get updated.

Note that I didn't read your patch series yet, so I am not commenting on the implementation.

BUT, from my experience with customers facing this issue, I do thing that we must provide a solution (even in Linux kernel itself).

Quoted 41 lines

[...]

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

The problems stem from the fact that the RTC and RTT-peripherals are powered by backup power (VDDBU) and are not reset on wake-up, user, watchdog or software reset. Consequently, RTC and RTT-alarms and their interrupts may be enabled at boot, leading to a system lock-up when an interrupt arrives on the shared system-interrupt line before the appropriate handler (e.g. RTC-driver) has been installed.

The easiest way to trigger this is to simply wake up from an RTC-alarm on at91sam9g45. The RTC-driver currently does not disable interrupts at shutdown so even after a clean shut-down the system will always hang after waking up.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

The first patch fixes this very general case of RTC-wake up after a clean shutdown in the RTC-driver and is marked for stable as it is perfectly straight-forward. [ Note that the other, RTT-based, AT91 RTC-driver already disables its interrupts at shutdown. ]

And what about this patch? If it's decided that every bootloader needs to be updated, then perhaps it's better to risk bricked systems also after a clean shutdown to enforce those updates? Should we then remove the corresponding disable of interrupts at shutdown from the rtc-at91sam9 driver by the same logic?

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

The more general problem can be triggered, for example, by doing a user-reset while updating the RTC-time or if an RTC or RTT-alarm goes off after a non-clean shutdown.

To fix this I propose that arch-code should mask the relevant interrupts before enabling the system interrupt at early boot, and this is what the fifth patch does. To access the RTC-registers I choose to revert a recent patch that moved the register definitions to drivers/rtc.

Arguably, the relevant interrupts could also be disabled in bootloaders, but I suggest fixing it in the kernel once and for all.

Thanks,
Johan

Signature · 1 line
Nicolas Ferre
#18 lore raw

v3 cover ARM: at91: fix hanged boot

In reply to Johan Hovold

These patches fix a few severe issues affecting most AT91 SOCs where boot can hang after a non-general reset, and where the only way to get the system booting again is to do a general reset -- something which could require physically removing any backup battery.

The problems stem from the fact that the RTC and RTT-peripherals are powered by backup power (VDDBU) and are not reset on wake-up, user, watchdog or software reset. Consequently, RTC and RTT-alarms and their interrupts may be enabled at boot, leading to a system lock-up when an interrupt arrives on the shared system-interrupt line before the appropriate handler (e.g. RTC-driver) has been installed.

The easiest way to trigger this is to simply wake up from an RTC-alarm on at91sam9g45. The RTC-driver currently does not disable interrupts at shutdown so even after a clean shut-down the system will always hang after waking up.

The more general problem can be triggered, for example, by doing a user-reset while updating the RTC-time or if an RTC or RTT-alarm goes off after a non-clean shutdown.

To fix this I add two helper functions to be called called by arch-code to mask the relevant interrupts before enabling the system interrupt at early boot.

The patches have been tested on at91sam9g45 and compile-tested for the other SOCs.

Johan

v2:
- add DT-support
- make sys_irq_mask non-mandatory

v3
- rebase on v3.12-rc5
- drop DT-support (interrupt masking is needed even if RTC or RTT nodes are missing)
- drop dedicated SOC-initialiser and call helpers directly from init
- drop revert-patch of move of RTC-register definitions to drivers/ and copy the two needed definitions instead
- move helper functions from setup.c to a separate file
- add fix for new sama5d3 SOC
- add a register read back to make sure write has reached the devices
- split fix in two patches for RTC and RTT, respectively

Johan Hovold (3):
ARM: at91: fix hanged boot due to early rtc-interrupt
ARM: at91: fix hanged boot due to early rtt-interrupt
ARM: at91/rtc: disable interrupts at shutdown

 arch/arm/mach-at91/Makefile                   |  2 +-
 arch/arm/mach-at91/at91sam9260.c              |  2 +
 arch/arm/mach-at91/at91sam9261.c              |  2 +
 arch/arm/mach-at91/at91sam9263.c              |  3 ++
 arch/arm/mach-at91/at91sam9g45.c              |  3 ++
 arch/arm/mach-at91/at91sam9n12.c              |  6 +++
 arch/arm/mach-at91/at91sam9rl.c               |  3 ++
 arch/arm/mach-at91/at91sam9x5.c               |  6 +++
 arch/arm/mach-at91/generic.h                  |  2 +
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 ++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 ++
 arch/arm/mach-at91/include/mach/sama5d3.h     |  5 ++
 arch/arm/mach-at91/sama5d3.c                  |  6 +++
 arch/arm/mach-at91/sysirq_mask.c              | 71 +++++++++++++++++++++++++++
 drivers/rtc/rtc-at91rm9200.c                  |  9 ++++
 15 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-at91/sysirq_mask.c
Signature · 1 line
1.8.4
#19 lore raw

PATCH v3 1/3 ARM: at91: fix hanged boot due to early rtc-interrupt

Make sure the RTC-interrupts are masked at boot by adding a new helper function to be used at SOC-init.

This fixes hanged boot on all AT91 SOCs with an RTC (but RM9200), for example, after a reset during an RTC-update or if an RTC-alarm goes off after shutdown (e.g. when using RTC wakeup).

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, which is also used by the PIT, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

---
 arch/arm/mach-at91/Makefile                   |  2 +-
 arch/arm/mach-at91/at91sam9g45.c              |  2 ++
 arch/arm/mach-at91/at91sam9n12.c              |  6 ++++
 arch/arm/mach-at91/at91sam9rl.c               |  2 ++
 arch/arm/mach-at91/at91sam9x5.c               |  6 ++++
 arch/arm/mach-at91/generic.h                  |  1 +
 arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 +++
 arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 +++
 arch/arm/mach-at91/include/mach/sama5d3.h     |  5 +++
 arch/arm/mach-at91/sama5d3.c                  |  6 ++++
 arch/arm/mach-at91/sysirq_mask.c              | 47 +++++++++++++++++++++++++++
 11 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-at91/sysirq_mask.c
arch/arm/mach-at91/Makefile +1 -1
index aa33b0f..8879a41 100644
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y		:= irq.o gpio.o setup.o
+obj-y		:= irq.o gpio.o setup.o sysirq_mask.o
 obj-m		:=
 obj-n		:=
 obj-		:=
arch/arm/mach-at91/at91sam9g45.c +2 -0
index b9fe138..8d4da6d 100644
@@ -379,6 +379,8 @@ static void __init at91sam9g45_initialize(void)
 	arm_pm_idle = at91sam9_idle;
 	arm_pm_restart = at91sam9g45_restart;
 
+	at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+
 	/* Register GPIO subsystem */
 	at91_gpio_init(at91sam9g45_gpio, 5);
 }
arch/arm/mach-at91/at91sam9n12.c +6 -0
index c7d670d..4d6001c 100644
@@ -223,7 +223,13 @@ static void __init at91sam9n12_map_io(void)
 	at91_init_sram(0, AT91SAM9N12_SRAM_BASE, AT91SAM9N12_SRAM_SIZE);
 }
 
+static void __init at91sam9n12_initialize(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9N12_BASE_RTC);
+}
+
 AT91_SOC_START(at91sam9n12)
 	.map_io = at91sam9n12_map_io,
 	.register_clocks = at91sam9n12_register_clocks,
+	.init = at91sam9n12_initialize,
 AT91_SOC_END
arch/arm/mach-at91/at91sam9rl.c +2 -0
index d4ec0d9..b5a8c9d 100644
@@ -294,6 +294,8 @@ static void __init at91sam9rl_initialize(void)
 	arm_pm_idle = at91sam9_idle;
 	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+
 	/* Register GPIO subsystem */
 	at91_gpio_init(at91sam9rl_gpio, 4);
 }
arch/arm/mach-at91/at91sam9x5.c +6 -0
index 916e5a1..e8a2e07 100644
@@ -322,6 +322,11 @@ static void __init at91sam9x5_map_io(void)
 	at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
 }
 
+static void __init at91sam9x5_initialize(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9X5_BASE_RTC);
+}
+
 /* --------------------------------------------------------------------
  *  Interrupt initialization
  * -------------------------------------------------------------------- */
@@ -329,4 +334,5 @@ static void __init at91sam9x5_map_io(void)
 AT91_SOC_START(at91sam9x5)
 	.map_io = at91sam9x5_map_io,
 	.register_clocks = at91sam9x5_register_clocks,
+	.init = at91sam9x5_initialize,
 AT91_SOC_END
arch/arm/mach-at91/generic.h +1 -0
index dc6e2f5..80269bd 100644
@@ -34,6 +34,7 @@ extern int  __init at91_aic_of_init(struct device_node *node,
 				    struct device_node *parent);
 extern int  __init at91_aic5_of_init(struct device_node *node,
 				    struct device_node *parent);
+extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
 
 
  /* Timer */
arch/arm/mach-at91/include/mach/at91sam9n12.h +5 -0
index d374b87..0151bcf 100644
@@ -49,6 +49,11 @@
 #define AT91SAM9N12_BASE_USART3	0xf8028000
 
 /*
+ * System Peripherals
+ */
+#define AT91SAM9N12_BASE_RTC	0xfffffeb0
+
+/*
  * Internal Memory.
  */
 #define AT91SAM9N12_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/include/mach/at91sam9x5.h +5 -0
index c75ee19..2fc76c4 100644
@@ -55,6 +55,11 @@
 #define AT91SAM9X5_BASE_USART2	0xf8024000
 
 /*
+ * System Peripherals
+ */
+#define AT91SAM9X5_BASE_RTC	0xfffffeb0
+
+/*
  * Internal Memory.
  */
 #define AT91SAM9X5_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/include/mach/sama5d3.h +5 -0
index 31096a8..25613d8 100644
@@ -73,6 +73,11 @@
 #define SAMA5D3_BASE_USART3	0xf8024000
 
 /*
+ * System Peripherals
+ */
+#define SAMA5D3_BASE_RTC	0xfffffeb0
+
+/*
  * Internal Memory
  */
 #define SAMA5D3_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/sama5d3.c +6 -0
index 4012797..3ea8642 100644
@@ -371,7 +371,13 @@ static void __init sama5d3_map_io(void)
 	at91_init_sram(0, SAMA5D3_SRAM_BASE, SAMA5D3_SRAM_SIZE);
 }
 
+static void __init sama5d3_initialize(void)
+{
+	at91_sysirq_mask_rtc(SAMA5D3_BASE_RTC);
+}
+
 AT91_SOC_START(sama5d3)
 	.map_io = sama5d3_map_io,
 	.register_clocks = sama5d3_register_clocks,
+	.init = sama5d3_initialize,
 AT91_SOC_END
arch/arm/mach-at91/sysirq_mask.c new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
1.8.4
Acked-by on v3 1/3
#20 lore raw

Re: [PATCH v3 1/3] ARM: at91: fix hanged boot due to early rtc-interrupt

On 16/10/2013 11:56, Johan Hovold :

Quoted 19 lines

Make sure the RTC-interrupts are masked at boot by adding a new helper function to be used at SOC-init.

This fixes hanged boot on all AT91 SOCs with an RTC (but RM9200), for example, after a reset during an RTC-update or if an RTC-alarm goes off after shutdown (e.g. when using RTC wakeup).

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, which is also used by the PIT, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Quoted 6 lines

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

and added to the at91-3.13-fixes-non-critical branch with the "stable" tag:
Cc: stable at vger.kernel.org # 3.11.x

Thanks a lot Johan.

Quoted 226 lines
---
  arch/arm/mach-at91/Makefile                   |  2 +-
  arch/arm/mach-at91/at91sam9g45.c              |  2 ++
  arch/arm/mach-at91/at91sam9n12.c              |  6 ++++
  arch/arm/mach-at91/at91sam9rl.c               |  2 ++
  arch/arm/mach-at91/at91sam9x5.c               |  6 ++++
  arch/arm/mach-at91/generic.h                  |  1 +
  arch/arm/mach-at91/include/mach/at91sam9n12.h |  5 +++
  arch/arm/mach-at91/include/mach/at91sam9x5.h  |  5 +++
  arch/arm/mach-at91/include/mach/sama5d3.h     |  5 +++
  arch/arm/mach-at91/sama5d3.c                  |  6 ++++
  arch/arm/mach-at91/sysirq_mask.c              | 47 +++++++++++++++++++++++++++
  11 files changed, 86 insertions(+), 1 deletion(-)

create mode 100644 arch/arm/mach-at91/sysirq_mask.c

arch/arm/mach-at91/Makefile +1 -1
index aa33b0f..8879a41 100644
@@ -2,7 +2,7 @@
  # Makefile for the linux kernel.
  #
 
-obj-y		:= irq.o gpio.o setup.o
+obj-y		:= irq.o gpio.o setup.o sysirq_mask.o
  obj-m		:=
  obj-n		:=
  obj-		:=
arch/arm/mach-at91/at91sam9g45.c +2 -0
index b9fe138..8d4da6d 100644
@@ -379,6 +379,8 @@ static void __init at91sam9g45_initialize(void)
  	arm_pm_idle = at91sam9_idle;
  	arm_pm_restart = at91sam9g45_restart;
 
+	at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+
  	/* Register GPIO subsystem */
  	at91_gpio_init(at91sam9g45_gpio, 5);
  }
arch/arm/mach-at91/at91sam9n12.c +6 -0
index c7d670d..4d6001c 100644
@@ -223,7 +223,13 @@ static void __init at91sam9n12_map_io(void)
  	at91_init_sram(0, AT91SAM9N12_SRAM_BASE, AT91SAM9N12_SRAM_SIZE);
  }
 
+static void __init at91sam9n12_initialize(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9N12_BASE_RTC);
+}
+
  AT91_SOC_START(at91sam9n12)
  	.map_io = at91sam9n12_map_io,
  	.register_clocks = at91sam9n12_register_clocks,
+	.init = at91sam9n12_initialize,
  AT91_SOC_END
arch/arm/mach-at91/at91sam9rl.c +2 -0
index d4ec0d9..b5a8c9d 100644
@@ -294,6 +294,8 @@ static void __init at91sam9rl_initialize(void)
  	arm_pm_idle = at91sam9_idle;
  	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+
  	/* Register GPIO subsystem */
  	at91_gpio_init(at91sam9rl_gpio, 4);
  }
arch/arm/mach-at91/at91sam9x5.c +6 -0
index 916e5a1..e8a2e07 100644
@@ -322,6 +322,11 @@ static void __init at91sam9x5_map_io(void)
  	at91_init_sram(0, AT91SAM9X5_SRAM_BASE, AT91SAM9X5_SRAM_SIZE);
  }
 
+static void __init at91sam9x5_initialize(void)
+{
+	at91_sysirq_mask_rtc(AT91SAM9X5_BASE_RTC);
+}
+
  /* --------------------------------------------------------------------
   *  Interrupt initialization
   * -------------------------------------------------------------------- */
@@ -329,4 +334,5 @@ static void __init at91sam9x5_map_io(void)
  AT91_SOC_START(at91sam9x5)
  	.map_io = at91sam9x5_map_io,
  	.register_clocks = at91sam9x5_register_clocks,
+	.init = at91sam9x5_initialize,
  AT91_SOC_END
arch/arm/mach-at91/generic.h +1 -0
index dc6e2f5..80269bd 100644
@@ -34,6 +34,7 @@ extern int  __init at91_aic_of_init(struct device_node *node,
  				    struct device_node *parent);
  extern int  __init at91_aic5_of_init(struct device_node *node,
  				    struct device_node *parent);
+extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
 
 
   /* Timer */
arch/arm/mach-at91/include/mach/at91sam9n12.h +5 -0
index d374b87..0151bcf 100644
@@ -49,6 +49,11 @@
  #define AT91SAM9N12_BASE_USART3	0xf8028000
 
  /*
+ * System Peripherals
+ */
+#define AT91SAM9N12_BASE_RTC	0xfffffeb0
+
+/*
   * Internal Memory.
   */
  #define AT91SAM9N12_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/include/mach/at91sam9x5.h +5 -0
index c75ee19..2fc76c4 100644
@@ -55,6 +55,11 @@
  #define AT91SAM9X5_BASE_USART2	0xf8024000
 
  /*
+ * System Peripherals
+ */
+#define AT91SAM9X5_BASE_RTC	0xfffffeb0
+
+/*
   * Internal Memory.
   */
  #define AT91SAM9X5_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/include/mach/sama5d3.h +5 -0
index 31096a8..25613d8 100644
@@ -73,6 +73,11 @@
  #define SAMA5D3_BASE_USART3	0xf8024000
 
  /*
+ * System Peripherals
+ */
+#define SAMA5D3_BASE_RTC	0xfffffeb0
+
+/*
   * Internal Memory
   */
  #define SAMA5D3_SRAM_BASE	0x00300000	/* Internal SRAM base address */
arch/arm/mach-at91/sama5d3.c +6 -0
index 4012797..3ea8642 100644
@@ -371,7 +371,13 @@ static void __init sama5d3_map_io(void)
  	at91_init_sram(0, SAMA5D3_SRAM_BASE, SAMA5D3_SRAM_SIZE);
  }
 
+static void __init sama5d3_initialize(void)
+{
+	at91_sysirq_mask_rtc(SAMA5D3_BASE_RTC);
+}
+
  AT91_SOC_START(sama5d3)
  	.map_io = sama5d3_map_io,
  	.register_clocks = sama5d3_register_clocks,
+	.init = sama5d3_initialize,
  AT91_SOC_END
arch/arm/mach-at91/sysirq_mask.c new file +47 -0
new file mode 100644
index 0000000..ee3e22c
@@ -0,0 +1,47 @@
+/*
+ * sysirq_mask.c - System-interrupt masking
+ *
+ * Copyright (C) 2013 Johan Hovold <[email protected]>
+ *
+ * Functions to disable system interrupts from backup-powered peripherals.
+ *
+ * The RTC and RTT-peripherals are generally powered by backup power (VDDBU)
+ * and are not reset on wake-up, user, watchdog or software reset. This means
+ * that their interrupts may be enabled during early boot (e.g. after a user
+ * reset).
+ *
+ * As the RTC and RTT share the system-interrupt line with the PIT, an
+ * interrupt occurring before a handler has been installed would lead to the
+ * system interrupt being disabled and prevent the system from booting.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/io.h>
+
+#include "generic.h"
+
+#define AT91_RTC_IDR	0x24	/* Interrupt Disable Register */
+#define AT91_RTC_IMR	0x28	/* Interrupt Mask Register */
+
+void __init at91_sysirq_mask_rtc(u32 rtc_base)
+{
+	void __iomem *base;
+	u32 mask;
+
+	base = ioremap(rtc_base, 64);
+	if (!base)
+		return;
+
+	mask = readl_relaxed(base + AT91_RTC_IMR);
+	if (mask) {
+		pr_info("AT91: Disabling rtc irq\n");
+		writel_relaxed(mask, base + AT91_RTC_IDR);
+		(void)readl_relaxed(base + AT91_RTC_IMR);	/* flush */
+	}
+
+	iounmap(base);
+}
Signature · 1 line
Nicolas Ferre
#21 lore raw

PATCH v3 2/3 ARM: at91: fix hanged boot due to early rtt-interrupt

In reply to Johan Hovold

Make sure the RTT-interrupts are masked at boot by adding a new helper function to be used at SOC-init.

This fixes hanged boot on all AT91 SOCs with an RTT, for example, if an RTT-alarm goes off after a non-clean shutdown (e.g. when using RTC wakeup).

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, which is also used by the PIT, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

---
 arch/arm/mach-at91/at91sam9260.c |  2 ++
 arch/arm/mach-at91/at91sam9261.c |  2 ++
 arch/arm/mach-at91/at91sam9263.c |  3 +++
 arch/arm/mach-at91/at91sam9g45.c |  1 +
 arch/arm/mach-at91/at91sam9rl.c  |  1 +
 arch/arm/mach-at91/generic.h     |  1 +
 arch/arm/mach-at91/sysirq_mask.c | 24 ++++++++++++++++++++++++
 7 files changed, 34 insertions(+)
arch/arm/mach-at91/at91sam9260.c +2 -0
index 5de6074..ae10d14 100644
@@ -349,6 +349,8 @@ static void __init at91sam9260_initialize(void)
 	arm_pm_idle = at91sam9_idle;
 	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT);
+
 	/* Register GPIO subsystem */
 	at91_gpio_init(at91sam9260_gpio, 3);
 }
arch/arm/mach-at91/at91sam9261.c +2 -0
index 0e07932..e761e74 100644
@@ -291,6 +291,8 @@ static void __init at91sam9261_initialize(void)
 	arm_pm_idle = at91sam9_idle;
 	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
+
 	/* Register GPIO subsystem */
 	at91_gpio_init(at91sam9261_gpio, 3);
 }
arch/arm/mach-at91/at91sam9263.c +3 -0
index 962768b..ad02281 100644
@@ -330,6 +330,9 @@ static void __init at91sam9263_initialize(void)
 	arm_pm_idle = at91sam9_idle;
 	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0);
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1);
+
 	/* Register GPIO subsystem */
 	at91_gpio_init(at91sam9263_gpio, 5);
 }
arch/arm/mach-at91/at91sam9g45.c +1 -0
index 8d4da6d..88e6f7b 100644
@@ -380,6 +380,7 @@ static void __init at91sam9g45_initialize(void)
 	arm_pm_restart = at91sam9g45_restart;
 
 	at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT);
 
 	/* Register GPIO subsystem */
 	at91_gpio_init(at91sam9g45_gpio, 5);
arch/arm/mach-at91/at91sam9rl.c +1 -0
index b5a8c9d..301e172 100644
@@ -295,6 +295,7 @@ static void __init at91sam9rl_initialize(void)
 	arm_pm_restart = at91sam9_alt_restart;
 
 	at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT);
 
 	/* Register GPIO subsystem */
 	at91_gpio_init(at91sam9rl_gpio, 4);
arch/arm/mach-at91/generic.h +1 -0
index 80269bd..26dee3c 100644
@@ -35,6 +35,7 @@ extern int  __init at91_aic_of_init(struct device_node *node,
 extern int  __init at91_aic5_of_init(struct device_node *node,
 				    struct device_node *parent);
 extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
+extern void __init at91_sysirq_mask_rtt(u32 rtt_base);
 
 
  /* Timer */
arch/arm/mach-at91/sysirq_mask.c +24 -0
index ee3e22c..2ba694f 100644
@@ -21,6 +21,7 @@
  */
 
 #include <linux/io.h>
+#include <mach/at91_rtt.h>
 
 #include "generic.h"
 
@@ -45,3 +46,26 @@ void __init at91_sysirq_mask_rtc(u32 rtc_base)
 
 	iounmap(base);
 }
+
+void __init at91_sysirq_mask_rtt(u32 rtt_base)
+{
+	void __iomem *base;
+	void __iomem *reg;
+	u32 mode;
+
+	base = ioremap(rtt_base, 16);
+	if (!base)
+		return;
+
+	reg = base + AT91_RTT_MR;
+
+	mode = readl_relaxed(reg);
+	if (mode & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)) {
+		pr_info("AT91: Disabling rtt irq\n");
+		mode &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+		writel_relaxed(mode, reg);
+		(void)readl_relaxed(reg);			/* flush */
+	}
+
+	iounmap(base);
+}
Signature · 1 line
1.8.4
Acked-by on v3 2/3
#22 lore raw

Re: [PATCH v3 2/3] ARM: at91: fix hanged boot due to early rtt-interrupt

On 16/10/2013 11:56, Johan Hovold :

Quoted 19 lines

Make sure the RTT-interrupts are masked at boot by adding a new helper function to be used at SOC-init.

This fixes hanged boot on all AT91 SOCs with an RTT, for example, if an RTT-alarm goes off after a non-clean shutdown (e.g. when using RTC wakeup).

The RTC and RTT-peripherals are powered by backup power (VDDBU) (on all AT91 SOCs but RM9200) and are not reset on wake-up, user, watchdog or software reset. This means that their interrupts may be enabled during early boot if, for example, they where not disabled during a previous shutdown (e.g. due to a buggy driver or a non-clean shutdown such as a user reset). Furthermore, an RTC or RTT-alarm may also be active.

The RTC and RTT-interrupts use the shared system-interrupt line, which is also used by the PIT, and if an interrupt occurs before a handler (e.g. RTC-driver) has been installed this leads to the system interrupt being disabled and prevents the system from booting.

Quoted 6 lines

Note that when boot hangs due to an early RTC or RTT-interrupt, the only way to get the system to start again is to remove the backup power (e.g. battery) or to disable the interrupt manually from the bootloader. In particular, a user reset is not sufficient.

and added to the at91-3.13-fixes-non-critical branch with the "stable" tag:
Cc: stable at vger.kernel.org # 3.11.x

Thanks for your patience, bye,

Quoted 126 lines
---
  arch/arm/mach-at91/at91sam9260.c |  2 ++
  arch/arm/mach-at91/at91sam9261.c |  2 ++
  arch/arm/mach-at91/at91sam9263.c |  3 +++
  arch/arm/mach-at91/at91sam9g45.c |  1 +
  arch/arm/mach-at91/at91sam9rl.c  |  1 +
  arch/arm/mach-at91/generic.h     |  1 +
  arch/arm/mach-at91/sysirq_mask.c | 24 ++++++++++++++++++++++++
  7 files changed, 34 insertions(+)
arch/arm/mach-at91/at91sam9260.c +2 -0
index 5de6074..ae10d14 100644
@@ -349,6 +349,8 @@ static void __init at91sam9260_initialize(void)
  	arm_pm_idle = at91sam9_idle;
  	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT);
+
  	/* Register GPIO subsystem */
  	at91_gpio_init(at91sam9260_gpio, 3);
  }
arch/arm/mach-at91/at91sam9261.c +2 -0
index 0e07932..e761e74 100644
@@ -291,6 +291,8 @@ static void __init at91sam9261_initialize(void)
  	arm_pm_idle = at91sam9_idle;
  	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
+
  	/* Register GPIO subsystem */
  	at91_gpio_init(at91sam9261_gpio, 3);
  }
arch/arm/mach-at91/at91sam9263.c +3 -0
index 962768b..ad02281 100644
@@ -330,6 +330,9 @@ static void __init at91sam9263_initialize(void)
  	arm_pm_idle = at91sam9_idle;
  	arm_pm_restart = at91sam9_alt_restart;
 
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0);
+	at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1);
+
  	/* Register GPIO subsystem */
  	at91_gpio_init(at91sam9263_gpio, 5);
  }
arch/arm/mach-at91/at91sam9g45.c +1 -0
index 8d4da6d..88e6f7b 100644
@@ -380,6 +380,7 @@ static void __init at91sam9g45_initialize(void)
  	arm_pm_restart = at91sam9g45_restart;
 
  	at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT);
 
  	/* Register GPIO subsystem */
  	at91_gpio_init(at91sam9g45_gpio, 5);
arch/arm/mach-at91/at91sam9rl.c +1 -0
index b5a8c9d..301e172 100644
@@ -295,6 +295,7 @@ static void __init at91sam9rl_initialize(void)
  	arm_pm_restart = at91sam9_alt_restart;
 
  	at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
+	at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT);
 
  	/* Register GPIO subsystem */
  	at91_gpio_init(at91sam9rl_gpio, 4);
arch/arm/mach-at91/generic.h +1 -0
index 80269bd..26dee3c 100644
@@ -35,6 +35,7 @@ extern int  __init at91_aic_of_init(struct device_node *node,
  extern int  __init at91_aic5_of_init(struct device_node *node,
  				    struct device_node *parent);
  extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
+extern void __init at91_sysirq_mask_rtt(u32 rtt_base);
 
 
   /* Timer */
arch/arm/mach-at91/sysirq_mask.c +24 -0
index ee3e22c..2ba694f 100644
@@ -21,6 +21,7 @@
   */
 
  #include <linux/io.h>
+#include <mach/at91_rtt.h>
 
  #include "generic.h"
 
@@ -45,3 +46,26 @@ void __init at91_sysirq_mask_rtc(u32 rtc_base)
 
  	iounmap(base);
  }
+
+void __init at91_sysirq_mask_rtt(u32 rtt_base)
+{
+	void __iomem *base;
+	void __iomem *reg;
+	u32 mode;
+
+	base = ioremap(rtt_base, 16);
+	if (!base)
+		return;
+
+	reg = base + AT91_RTT_MR;
+
+	mode = readl_relaxed(reg);
+	if (mode & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)) {
+		pr_info("AT91: Disabling rtt irq\n");
+		mode &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
+		writel_relaxed(mode, reg);
+		(void)readl_relaxed(reg);			/* flush */
+	}
+
+	iounmap(base);
+}
Signature · 1 line
Nicolas Ferre
#23 lore raw

PATCH v3 3/3 ARM: at91/rtc: disable interrupts at shutdown

In reply to Johan Hovold

Make sure RTC-interrupts are disabled at shutdown.

As the RTC is generally powered by backup power (VDDBU), its interrupts are not disabled on wake-up, user, watchdog or software reset. This could cause troubles on other systems (e.g. older kernels) if an interrupt occurs before a handler has been installed at next boot.

Let us be well-behaved and disable them on clean shutdowns at least (as do the RTT-based rtc-at91sam9 driver).

---
 drivers/rtc/rtc-at91rm9200.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/rtc/rtc-at91rm9200.c +9 -0
index 7418926..ea088e9 100644
@@ -442,6 +442,14 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static void at91_rtc_shutdown(struct platform_device *pdev)
+{
+	/* Disable all interrupts */
+	at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
+					AT91_RTC_SECEV | AT91_RTC_TIMEV |
+					AT91_RTC_CALEV);
+}
+
 #ifdef CONFIG_PM_SLEEP
 
 /* AT91RM9200 RTC Power management control */
@@ -480,6 +488,7 @@ static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
 
 static struct platform_driver at91_rtc_driver = {
 	.remove		= __exit_p(at91_rtc_remove),
+	.shutdown	= at91_rtc_shutdown,
 	.driver		= {
 		.name	= "at91_rtc",
 		.owner	= THIS_MODULE,
Signature · 1 line
1.8.4
Acked-by on v3 3/3
#24 lore raw

Re: [PATCH v3 3/3] ARM: at91/rtc: disable interrupts at shutdown

On 16/10/2013 11:56, Johan Hovold :

Quoted 11 lines

Make sure RTC-interrupts are disabled at shutdown.

As the RTC is generally powered by backup power (VDDBU), its interrupts are not disabled on wake-up, user, watchdog or software reset. This could cause troubles on other systems (e.g. older kernels) if an interrupt occurs before a handler has been installed at next boot.

Let us be well-behaved and disable them on clean shutdowns at least (as do the RTT-based rtc-at91sam9 driver).

Thank you Johan.

Andrew, could you add this patch to your rtc queue or should I re-send it ?

Best regards,

Quoted 32 lines
---
  drivers/rtc/rtc-at91rm9200.c | 9 +++++++++
  1 file changed, 9 insertions(+)
drivers/rtc/rtc-at91rm9200.c +9 -0
index 7418926..ea088e9 100644
@@ -442,6 +442,14 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
  	return 0;
  }
 
+static void at91_rtc_shutdown(struct platform_device *pdev)
+{
+	/* Disable all interrupts */
+	at91_rtc_write(AT91_RTC_IDR, AT91_RTC_ACKUPD | AT91_RTC_ALARM |
+					AT91_RTC_SECEV | AT91_RTC_TIMEV |
+					AT91_RTC_CALEV);
+}
+
  #ifdef CONFIG_PM_SLEEP
 
  /* AT91RM9200 RTC Power management control */
@@ -480,6 +488,7 @@ static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
 
  static struct platform_driver at91_rtc_driver = {
  	.remove		= __exit_p(at91_rtc_remove),
+	.shutdown	= at91_rtc_shutdown,
  	.driver		= {
  		.name	= "at91_rtc",
  		.owner	= THIS_MODULE,
Signature · 1 line
Nicolas Ferre