diff mbox

[v3,5/5] ARM: bcm4760: Add restart hook

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

Commit Message

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

Restart hook implementation for the Broadcom BCM4760 based ARM11 SoCs.

v2,v3:
* unchanged 

v1:
* initial release

Cc: devicetree@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
---
 Documentation/devicetree/bindings/watchdog/brcm,bcm4760-pm-wdt.txt |   14 ++
 arch/arm/boot/dts/bcm4760.dtsi                                     |    5 +
 arch/arm/mach-bcm/bcm4760.c                                        |   79 ++++++++++
 3 files changed, 98 insertions(+)

Comments

Olof Johansson Aug. 29, 2013, 11:36 p.m. UTC | #1
Hi,

On Thu, Aug 15, 2013 at 12:10:48AM +0200, Domenico Andreoli wrote:
> From: Domenico Andreoli <domenico.andreoli@linux.com>
> 
> Restart hook implementation for the Broadcom BCM4760 based ARM11 SoCs.

This essentially implements a wdt driver under mach-bcm. It'd be better
to contain this under drivers/watchdog and use the reboot notifier to
do the restart from there.


-Olof
Domenico Andreoli Aug. 30, 2013, 8:01 a.m. UTC | #2
On Thu, Aug 29, 2013 at 04:36:47PM -0700, Olof Johansson wrote:
> Hi,
> 
> On Thu, Aug 15, 2013 at 12:10:48AM +0200, Domenico Andreoli wrote:
> > From: Domenico Andreoli <domenico.andreoli@linux.com>
> > 
> > Restart hook implementation for the Broadcom BCM4760 based ARM11 SoCs.
> 
> This essentially implements a wdt driver under mach-bcm. It'd be better
> to contain this under drivers/watchdog and use the reboot notifier to
> do the restart from there.

do I need also a config option? I don't think I need one unless I have
also a complete implementation.

Domenico
diff mbox

Patch

Index: b/Documentation/devicetree/bindings/watchdog/brcm,bcm4760-pm-wdt.txt
===================================================================
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/brcm,bcm4760-pm-wdt.txt
@@ -0,0 +1,14 @@ 
+Broadcom BCM4760 watchdog timer device tree bindings
+----------------------------------------------------
+
+Required properties:
+
+- compatible : should be "brcm,bcm4760-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
@@ -40,6 +40,11 @@ 
 			reg = <0xbc000 0x1000>;
 		};
 
+		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/mach-bcm/bcm4760.c
===================================================================
--- a/arch/arm/mach-bcm/bcm4760.c
+++ b/arch/arm/mach-bcm/bcm4760.c
@@ -15,14 +15,92 @@ 
  */
 
 #include <linux/init.h>
+#include <linux/delay.h>
 #include <linux/clk-provider.h>
+#include <linux/of_address.h>
 #include <linux/of_platform.h>
 
 #include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+
+#define BCM4760_WDT_LOAD      0x000
+#define BCM4760_WDT_CTRL      0x008
+#define BCM4760_WDT_INTCLR    0x00c
+#define BCM4760_WDT_LOCK      0xc00
+
+#define BCM4760_WDT_PASSWORD  0x1acce551
+#define BCM4760_WDT_INTEN     BIT(0)
+#define BCM4760_WDT_RESEN     BIT(1)
+
+static void __iomem *wdt_regs;
+
+static const struct of_device_id bcm4760_pm_wdt_match[] __initconst = {
+	{ .compatible = "brcm,bcm4760-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 __init bcm4760_setup_restart(void)
+{
+	struct device_node *node;
+
+	node = of_find_matching_node(NULL, bcm4760_pm_wdt_match);
+	if (!node) {
+		pr_info("No bcm4760 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(BCM4760_WDT_PASSWORD, wdt_regs + BCM4760_WDT_LOCK);
+	/* disable watchdog */
+	writel(0, wdt_regs + BCM4760_WDT_CTRL);
+	/* lock watchdog registers */
+	writel(1, wdt_regs + BCM4760_WDT_LOCK);
+}
+
+static void bcm4760_restart(enum reboot_mode mode, const char *cmd)
+{
+	if (!wdt_regs) {
+		pr_err("No restart hook installed. ");
+		return;
+	}
+
+	/* unlock watchdog registers */
+	writel(BCM4760_WDT_PASSWORD, wdt_regs + BCM4760_WDT_LOCK);
+
+	/* disable watchdog */
+	writel(0, wdt_regs + BCM4760_WDT_CTRL);
+	udelay(20);
+
+	/* clear the irq status */
+	writel(1, wdt_regs + BCM4760_WDT_INTCLR);
+	udelay(20);
+
+	/* expire after 5 cycles (~156us) */
+	writel(5, wdt_regs + BCM4760_WDT_LOAD);
+	/* enable watchdog */
+	writel(BCM4760_WDT_INTEN | BCM4760_WDT_RESEN,
+		wdt_regs + BCM4760_WDT_CTRL);
+
+	/* lock watchdog registers */
+	writel(1, wdt_regs + BCM4760_WDT_LOCK);
+	/* wait the bite */
+	udelay(400);
+}
 
 static void __init bcm4760_init(void)
 {
 	of_clk_init(NULL);
+	bcm4760_setup_restart();
 	of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
 }
 
@@ -33,5 +111,6 @@  static const char * const bcm4760_compat
 
 DT_MACHINE_START(BCM4760, "Broadcom BCM4760")
 	.init_machine = bcm4760_init,
+	.restart = bcm4760_restart,
 	.dt_compat = bcm4760_compat
 MACHINE_END