From patchwork Sun Jul 21 00:23:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Andreoli X-Patchwork-Id: 2830869 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3C35B9F3EB for ; Sun, 21 Jul 2013 00:56:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47BDC20158 for ; Sun, 21 Jul 2013 00:56:12 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8C39120154 for ; Sun, 21 Jul 2013 00:56:09 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V0huM-0003Xu-7I; Sun, 21 Jul 2013 00:53:56 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V0htw-00046o-T4; Sun, 21 Jul 2013 00:53:28 +0000 Received: from mail-ea0-x235.google.com ([2a00:1450:4013:c01::235]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V0htS-00042z-1P for linux-arm-kernel@lists.infradead.org; Sun, 21 Jul 2013 00:53:00 +0000 Received: by mail-ea0-f181.google.com with SMTP id a15so3136271eae.12 for ; Sat, 20 Jul 2013 17:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:user-agent:date:from:to:cc:subject:references :content-disposition; bh=y6eqkvrfMsMdzVwEjta3qb5X5Mzu7XAEjkAaFtnuOo4=; b=W8+SnFqWTvy5ZP5PfkiD8hEP5h2vZbESeonWfIsOMinYyiQY5Z2TrNqveH5WiwjKji OFSWGLIIvSHE9Ho+S2lHX16pLlqPr7RJ5sItu8V8907qXCezZV1JJNFM06laSU8GMj+M 2oVteo/r2aAkydhaD7B7YOoW1AQK1/OhuxjzoYXW40UMusUex0/ZaCRhH3N75cFfbm61 i9DGd6kZkHNE0pXxJeECd6L8mamPRE9ozUKLS9Sc7hXzJa6zxCCK1knXAluYN3fingKj qASF6VVGGMZjqHt4Dwmx5icaVSV5nZ9SLjXTY+HO2yEdXzWqOh/i16Bnhba/tNWdbQEo chFQ== X-Received: by 10.14.8.197 with SMTP id 45mr21402832eer.66.1374367956397; Sat, 20 Jul 2013 17:52:36 -0700 (PDT) Received: from shock.dandreoli.com (j115181.upc-j.chello.nl. [24.132.115.181]) by mx.google.com with ESMTPSA id b7sm39092461eef.16.2013.07.20.17.52.34 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 20 Jul 2013 17:52:35 -0700 (PDT) Received: by shock.dandreoli.com (Postfix, from userid 1000) id EF10A34021A; Sun, 21 Jul 2013 02:27:14 +0200 (CEST) Message-Id: <20130721002714.732402573@gmail.com> User-Agent: quilt/0.60-1 Date: Sun, 21 Jul 2013 02:23:25 +0200 From: Domenico Andreoli To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/5] ARM: bcm4760: Add restart hook References: <20130721002320.730568671@gmail.com> Content-Disposition: inline; filename=arm-bcm476x-add-restart-hook.patch X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130720_205258_433847_46C861F5 X-CRM114-Status: GOOD ( 15.95 ) X-Spam-Score: -1.9 (-) Cc: Olof Johansson , Domenico Andreoli , Russell King , Arnd Bergmann X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Domenico Andreoli Restart hook implementation for the Broadcom BCM4760 based ARM11 SoCs. Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Domenico Andreoli --- Documentation/devicetree/bindings/watchdog/brcm,bcm4760-pm-wdt.txt | 14 ++ arch/arm/boot/dts/bcm4760.dtsi | 5 + arch/arm/mach-bcm/bcm4760.c | 78 ++++++++++ 3 files changed, 97 insertions(+) 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 @@ -23,6 +23,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 @@ -16,7 +16,9 @@ #include #include +#include #include +#include #include #include @@ -28,6 +30,17 @@ #define BCM4760_PERIPH_VIRT IOMEM(0xd0080000) #define BCM4760_PERIPH_SIZE SZ_512K +#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 struct map_desc io_map __initdata = { .virtual = (unsigned long) BCM4760_PERIPH_VIRT, .pfn = __phys_to_pfn(BCM4760_PERIPH_PHYS), @@ -56,11 +69,75 @@ static void __init bcm4760_system_rev(vo system_rev = id0 << 8 | (id1 & 0xff); } +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) { int err; bcm4760_system_rev(); + bcm4760_setup_restart(); bcm4760_init_clocks(); err = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); @@ -78,5 +155,6 @@ static const char * const bcm4760_compat DT_MACHINE_START(BCM4760, "Broadcom BCM4760") .map_io = bcm4760_map_io, .init_machine = bcm4760_init, + .restart = bcm4760_restart, .dt_compat = bcm4760_compat MACHINE_END