From patchwork Fri Jul 26 14:56:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Andreoli X-Patchwork-Id: 2834225 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BF4BAC0319 for ; Fri, 26 Jul 2013 15:14:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7E452018D for ; Fri, 26 Jul 2013 15:14:38 +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 8EC7C2018A for ; Fri, 26 Jul 2013 15:14:37 +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 1V2jiJ-0000AU-Fc; Fri, 26 Jul 2013 15: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 1V2jhy-0006cK-Gn; Fri, 26 Jul 2013 15:13:30 +0000 Received: from mail-ea0-x236.google.com ([2a00:1450:4013:c01::236]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1V2jhM-0006XX-9q for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2013 15:12:55 +0000 Received: by mail-ea0-f182.google.com with SMTP id o10so1631029eaj.27 for ; Fri, 26 Jul 2013 08:12:30 -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=KMhEs3EWn8CE5pmvLpRPxWHNly8b1zhc7tfgvg2LI6o=; b=pWL4k3Rgef12T/6ZWuTjF+bwi81a8v8PDsu1NloqGF5cs3fuP96/lB4vEv1gNohUlq 8S5/I3AVNz9nOv8W0/e9I+jEBNZ9vOrtyTrMsA8PVV7IxcmEo9kHS3cwkYyEirZnoqQb o8hVKlyg7DB+RN6vausgyL4zyRTOAV4csV60mVGgpWcwkmClwOO7QnnjypjqCXNiHkJG uKX9ciY9SmMKzROf867cYQBk3vpiDOooBTRD7DnKbXIDmd73Rz6ICstk/Z8wJfHlqxtx itL2LLvb9o/SqjOeQQASG9Y0dky1FP8caAc35FuDqu+n/p7U4cMzslADK32Nt6XyB/r1 LB5Q== X-Received: by 10.14.176.199 with SMTP id b47mr47976923eem.117.1374851550593; Fri, 26 Jul 2013 08:12:30 -0700 (PDT) Received: from shock.dandreoli.com (j115181.upc-j.chello.nl. [24.132.115.181]) by mx.google.com with ESMTPSA id e44sm81519746eeh.11.2013.07.26.08.12.28 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 26 Jul 2013 08:12:29 -0700 (PDT) Received: by shock.dandreoli.com (Postfix, from userid 1000) id 86D1E3402EA; Fri, 26 Jul 2013 17:12:24 +0200 (CEST) Message-Id: <20130726151224.265718946@gmail.com> User-Agent: quilt/0.60-1 Date: Fri, 26 Jul 2013 16:56:44 +0200 From: Domenico Andreoli To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 5/5] ARM: bcm4760: Add restart hook References: <20130726145639.116237136@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-20130726_111252_563633_A3B55E12 X-CRM114-Status: GOOD ( 15.13 ) 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=-5.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. v2: * 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