From patchwork Sun Oct 7 01:53:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Andreoli X-Patchwork-Id: 1560221 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id A288DE00DD for ; Sun, 7 Oct 2012 01:56:51 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TKg4P-0007ft-4Y; Sun, 07 Oct 2012 01:54:17 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TKg4K-0007ei-FA for linux-arm-kernel@lists.infradead.org; Sun, 07 Oct 2012 01:54:13 +0000 Received: by mail-wi0-f177.google.com with SMTP id hj13so1627593wib.0 for ; Sat, 06 Oct 2012 18:54:10 -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=cuMzQ7ERXwEqR+4ezqAhWMWuoyu3AMY0VhMbtiGF+sQ=; b=P1RDhgEecegwAC3XFrnPqRIULwWeoDyvJO3GJeNf/qrW2sA3MGoqPryB0nmBah6rro 4uBckn6lG+KP5Yf1yF4ywPPEcntPFDv8gH8hG0Xq3b6lSGWh7IWdswmzAiXOuG1XQHU8 KqesMnz6T5AdU96ap0XQn+5K01sbj5V1dkvq6EmQUVPYbjOSuPhmVI9IB/3cJeg/Qqgv xtvX4KD/3AgQo//XNzkxct+OGVkisp6YJS8NCT2bKQyvPFJ4UyZSDGldRP/Kk1W0XNA0 +Mh9uiUtonu7v4MmdimTFbjtSqW4AQWvWKD9ScPGss4KSLHbf/eAjSm7PRR6lz/Njo9O C9wg== Received: by 10.216.99.199 with SMTP id x49mr7828980wef.171.1349574850703; Sat, 06 Oct 2012 18:54:10 -0700 (PDT) Received: from raptus.dandreoli.com (178-85-163-250.dynamic.upc.nl. [178.85.163.250]) by mx.google.com with ESMTPS id hv8sm11776358wib.0.2012.10.06.18.54.09 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 06 Oct 2012 18:54:10 -0700 (PDT) Received: by raptus.dandreoli.com (Postfix, from userid 1000) id C6EBC3C3C0; Sun, 7 Oct 2012 03:54:07 +0200 (CEST) Message-Id: <20121007015407.522256287@gmail.com> User-Agent: quilt/0.60-1 Date: Sun, 07 Oct 2012 03:53:05 +0200 From: Domenico Andreoli To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/6] ARM: bcm476x: Add restart hook References: <20121007015300.828366635@gmail.com> Content-Disposition: inline; filename=arm-bcm476x-add-restart-hook.patch X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (cavokz[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Domenico Andreoli , devicetree-discuss@lists.ozlabs.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Domenico Andreoli Restart hook implementation for the BCM476x SoC (uses the watchdog). Signed-off-by: Domenico Andreoli --- Documentation/devicetree/bindings/watchdog/brcm,bcm476x-pm-wdt.txt | 13 ++ arch/arm/boot/dts/bcm476x.dtsi | 5 + arch/arm/mach-bcm476x/bcm476x.c | 66 ++++++++++ 3 files changed, 84 insertions(+) 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,13 @@ +BCM476x Watchdog timer + +Required properties: + +- compatible : should be "brcm,bcm476x-pm-wdt" +- reg : Specifies base physical address and size of the registers. + +Example: + +watchdog { + compatible = "brcm,bcm476x-pm-wdt"; + reg = <0xbd000 0x1000>; +}; Index: b/arch/arm/boot/dts/bcm476x.dtsi =================================================================== --- a/arch/arm/boot/dts/bcm476x.dtsi +++ b/arch/arm/boot/dts/bcm476x.dtsi @@ -28,6 +28,11 @@ clock-frequency = <32000>; }; + watchdog { + compatible = "brcm,bcm476x-pm-wdt"; + reg = <0xbd000 0x1000>; + }; + vic0: interrupt-controller@80000 { compatible = "brcm,bcm476x-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 +#include #include +#include #include #include #include @@ -28,6 +30,17 @@ #define BCM476X_PERIPH_VIRT 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 = BCM476X_PERIPH_VIRT, .pfn = __phys_to_pfn(BCM476X_PERIPH_PHYS), @@ -40,10 +53,62 @@ void __init bcm476x_map_io(void) iotable_init(&io_map, 1); } +/* + * 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 *np; + + np = of_find_compatible_node(NULL, NULL, "brcm,bcm476x-pm-wdt"); + if (WARN(!np, "unable to setup watchdog restart")) + return; + + wdt_regs = of_iomap(np, 0); + WARN(!wdt_regs, "Can't remap watchdog registers"); + + /* 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) + 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); +} + void __init bcm476x_init(void) { int ret; + bcm476x_setup_restart(); bcm476x_init_clocks(); ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); @@ -74,5 +139,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