From patchwork Wed Aug 14 22:10:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Andreoli X-Patchwork-Id: 2844824 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 C7B3A9F271 for ; Wed, 14 Aug 2013 22:14:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CC5912064C for ; Wed, 14 Aug 2013 22:14:29 +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 9A27020638 for ; Wed, 14 Aug 2013 22:14:28 +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 1V9jKB-0001Er-H9; Wed, 14 Aug 2013 22:13:52 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1V9jJx-00085L-PJ; Wed, 14 Aug 2013 22:13:37 +0000 Received: from mail-ee0-x22b.google.com ([2a00:1450:4013:c00::22b]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V9jJS-00081C-Du for linux-arm-kernel@lists.infradead.org; Wed, 14 Aug 2013 22:13:12 +0000 Received: by mail-ee0-f43.google.com with SMTP id e52so14683eek.30 for ; Wed, 14 Aug 2013 15:12:44 -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=1nQLc23rTo2g0cQnVw3S+HaEfWFId21iqpW3/s/4Vuk=; b=dDMXzsy1gv7ZN7z3FwZq+Jv6nema7QWDIt5FYUEvC5EZE4hdcvu5zkJPG5hGwf9rBR LCw2yY9x5fGJeRz9lhTnw6PWblKm0uQoq5u0DED3zZYsCV2W4Idk0jPL/yZs78Ixpoge Mu3AKVsYXG4588xgZBZ1NDik908ostxlW3NsHUiLW4fpDTOQNafEOWu4blNzFOBEkTGv 41r4ToRRXiUYfNXpeCp/cLxD4OXn+aJPDSIvuucHuy75jXtnh3hvg+V312uyCnf0lDNT H7vbWQt8xFmkKr0lUbcZiadd4K5wP4T9W4drU8OZZYKhCwpkRsJ1s6UDTX8tltn0kBy4 XFgA== X-Received: by 10.15.23.1 with SMTP id g1mr98998eeu.110.1376518364646; Wed, 14 Aug 2013 15:12:44 -0700 (PDT) Received: from shock.dandreoli.com (j115181.upc-j.chello.nl. [24.132.115.181]) by mx.google.com with ESMTPSA id bq1sm78941521eeb.9.2013.08.14.15.12.42 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 Aug 2013 15:12:43 -0700 (PDT) Received: by shock.dandreoli.com (Postfix, from userid 1000) id 7C0483402B2; Thu, 15 Aug 2013 00:12:38 +0200 (CEST) Message-Id: <20130814221238.291003843@gmail.com> User-Agent: quilt/0.60-1 Date: Thu, 15 Aug 2013 00:10:48 +0200 From: Domenico Andreoli To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 5/5] ARM: bcm4760: Add restart hook References: <20130814221043.528864175@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-20130814_181306_682277_5EAF6920 X-CRM114-Status: GOOD ( 15.00 ) X-Spam-Score: -1.9 (-) Cc: Olof Johansson , Domenico Andreoli , Russell King - ARM Linux , 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=-6.9 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. v2,v3: * unchanged v1: * initial release Cc: devicetree@vger.kernel.org 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 | 79 ++++++++++ 3 files changed, 98 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 @@ -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 +#include #include +#include #include #include +#include + +#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