diff mbox

[v2,5/5] ARM: bcm476x: Add restart hook

Message ID 20121014223025.133094217@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Domenico Andreoli Oct. 14, 2012, 10:14 p.m. UTC
From: Domenico Andreoli <domenico.andreoli@linux.com>

Restart hook implementation for the BCM476x SoC (uses the watchdog).

v2:
* bcm476x_setup_restart() now manages correctly the failure of of_iomap()
* match DT with the specific product names instead of the generic bcm476x

v1:
* initial release

Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
Acked-by: Olof Johansson <olof@lixom.net>
---
 Documentation/devicetree/bindings/watchdog/brcm,bcm476x-pm-wdt.txt |   15 ++
 arch/arm/boot/dts/bcm4760.dtsi                                     |    5 +
 arch/arm/boot/dts/bcm4761.dtsi                                     |    5 +
 arch/arm/mach-bcm476x/bcm476x.c                                    |   79 ++++++++++
 4 files changed, 104 insertions(+)
diff mbox

Patch

Index: b/Documentation/devicetree/bindings/watchdog/brcm,bcm476x-pm-wdt.txt
===================================================================
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/brcm,bcm476x-pm-wdt.txt
@@ -0,0 +1,15 @@ 
+Broadcom BCM4760 and BCM4761 watchdog timer device tree bindings
+----------------------------------------------------------------
+
+Required properties:
+
+- compatible : should be "brcm,bcm4760-pm-wdt" or
+                         "brcm,bcm4761-pm-wdt"
+- reg : Specifies base physical address and size of the registers.
+
+Example:
+
+watchdog {
+	compatible = "brcm,bcm4760-pm-wdt";
+	reg = <0xbd000 0x1000>;
+};
Index: b/arch/arm/boot/dts/bcm4760.dtsi
===================================================================
--- a/arch/arm/boot/dts/bcm4760.dtsi
+++ b/arch/arm/boot/dts/bcm4760.dtsi
@@ -24,6 +24,11 @@ 
 			clock-frequency = <32000>;
 		};
 
+		watchdog {
+			compatible = "brcm,bcm4760-pm-wdt";
+			reg = <0xbd000 0x1000>;
+		};
+
 		vic0: interrupt-controller@80000 {
 			compatible = "brcm,bcm4760-pl192", "arm,pl192-vic", "arm,primecell";
 			reg = <0x80000 0x1000>;
Index: b/arch/arm/boot/dts/bcm4761.dtsi
===================================================================
--- a/arch/arm/boot/dts/bcm4761.dtsi
+++ b/arch/arm/boot/dts/bcm4761.dtsi
@@ -24,6 +24,11 @@ 
 			clock-frequency = <32000>;
 		};
 
+		watchdog {
+			compatible = "brcm,bcm4761-pm-wdt";
+			reg = <0xbd000 0x1000>;
+		};
+
 		vic0: interrupt-controller@80000 {
 			compatible = "brcm,bcm4761-pl192", "arm,pl192-vic", "arm,primecell";
 			reg = <0x80000 0x1000>;
Index: b/arch/arm/mach-bcm476x/bcm476x.c
===================================================================
--- a/arch/arm/mach-bcm476x/bcm476x.c
+++ b/arch/arm/mach-bcm476x/bcm476x.c
@@ -15,7 +15,9 @@ 
  */
 
 #include <linux/init.h>
+#include <linux/delay.h>
 #include <linux/of_irq.h>
+#include <linux/of_address.h>
 #include <linux/of_platform.h>
 #include <linux/bcm476x_timer.h>
 #include <linux/clk/bcm476x.h>
@@ -28,6 +30,17 @@ 
 #define BCM476X_PERIPH_VIRT   IOMEM(0xd0080000)
 #define BCM476X_PERIPH_SIZE   SZ_512K
 
+#define BCM476X_WDT_LOAD      0x000
+#define BCM476X_WDT_CTRL      0x008
+#define BCM476X_WDT_INTCLR    0x00c
+#define BCM476X_WDT_LOCK      0xc00
+
+#define BCM476X_WDT_PASSWORD  0x1acce551
+#define BCM476X_WDT_INTEN     BIT(0)
+#define BCM476X_WDT_RESEN     BIT(1)
+
+static void __iomem *wdt_regs;
+
 static struct map_desc io_map __initdata = {
 	.virtual = (unsigned long) BCM476X_PERIPH_VIRT,
 	.pfn = __phys_to_pfn(BCM476X_PERIPH_PHYS),
@@ -40,10 +53,75 @@  static void __init bcm476x_map_io(void)
 	iotable_init(&io_map, 1);
 }
 
+static const struct of_device_id bcm476x_pm_wdt_match[] __initconst = {
+	{ .compatible = "brcm,bcm4760-pm-wdt" },
+	{ .compatible = "brcm,bcm4761-pm-wdt" },
+	{}
+};
+
+/*
+ * The machine restart method can be called from an atomic context so we won't
+ * be able to ioremap the regs then.
+ */
+static void bcm476x_setup_restart(void)
+{
+	struct device_node *node;
+
+	node = of_find_matching_node(NULL, bcm476x_pm_wdt_match);
+	if (!node) {
+		pr_info("No bcm476x watchdog node\n");
+		return;
+	}
+
+	wdt_regs = of_iomap(node, 0);
+	if (!wdt_regs) {
+		pr_err("Can't remap watchdog registers\n");
+		return;
+	}
+
+	/* unlock watchdog registers */
+	writel(BCM476X_WDT_PASSWORD, wdt_regs + BCM476X_WDT_LOCK);
+	/* disable watchdog */
+	writel(0, wdt_regs + BCM476X_WDT_CTRL);
+	/* lock watchdog registers */
+	writel(1, wdt_regs + BCM476X_WDT_LOCK);
+}
+
+static void bcm476x_restart(char mode, const char *cmd)
+{
+	if (!wdt_regs) {
+		pr_err("No restart hook installed. ");
+		return;
+	}
+
+	/* unlock watchdog registers */
+	writel(BCM476X_WDT_PASSWORD, wdt_regs + BCM476X_WDT_LOCK);
+
+	/* disable watchdog */
+	writel(0, wdt_regs + BCM476X_WDT_CTRL);
+	udelay(20);
+
+	/* clear the irq status */
+	writel(1, wdt_regs + BCM476X_WDT_INTCLR);
+	udelay(20);
+
+	/* expire after 5 cycles (~156us) */
+	writel(5, wdt_regs + BCM476X_WDT_LOAD);
+	/* enable watchdog */
+	writel(BCM476X_WDT_INTEN | BCM476X_WDT_RESEN,
+		wdt_regs + BCM476X_WDT_CTRL);
+
+	/* lock watchdog registers */
+	writel(1, wdt_regs + BCM476X_WDT_LOCK);
+	/* wait the bite */
+	udelay(400);
+}
+
 static void __init bcm476x_init(void)
 {
 	int err;
 
+	bcm476x_setup_restart();
 	bcm476x_init_clocks();
 
 	err = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
@@ -75,5 +153,6 @@  DT_MACHINE_START(BCM476X, "Broadcom BCM4
 	.handle_irq = vic_handle_irq,
 	.init_machine = bcm476x_init,
 	.timer = &bcm476x_timer,
+	.restart = bcm476x_restart,
 	.dt_compat = bcm476x_compat
 MACHINE_END