From patchwork Sat Sep 14 15:20:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Domenico Andreoli X-Patchwork-Id: 2893481 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 5C04D9F1C0 for ; Sat, 14 Sep 2013 15:23:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E91820263 for ; Sat, 14 Sep 2013 15:23:04 +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 0A77320258 for ; Sat, 14 Sep 2013 15:23:03 +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 1VKrg1-0007gj-Iv; Sat, 14 Sep 2013 15:22:26 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VKrfq-0004u1-1Z; Sat, 14 Sep 2013 15:22:14 +0000 Received: from mail-ee0-x22a.google.com ([2a00:1450:4013:c00::22a]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VKrfU-0004r1-TJ for linux-arm-kernel@lists.infradead.org; Sat, 14 Sep 2013 15:21:58 +0000 Received: by mail-ee0-f42.google.com with SMTP id b45so1150732eek.29 for ; Sat, 14 Sep 2013 08:21:31 -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=F4XPJCTeUXDE8xjexePgHyUv+HT81c1QXjr/3nv//Lk=; b=UdDoU2tQCUy+17WY7XP1bWgCiVag3qlEMb+RcFc8dOVCSpfg8/we1fFkJ04kbK0TFG oye2dU1uvFAh0in0bLlssAjgwEsmRMDvs0BjXRx1MI7vqlFQv2AvZDGOqDRbwY+fh2et suctGuQLWfFLbLZ53DWvi5oKSsYD1fUkVHZiQooGBhFhH+87FaR2R62+B8AUslNVq7wK cjgn4G0bKbK782V5eiETtHSI+3oo2Rwd0Kc8u/TcsSwZqchh138cdf0hF7LOqbhrB+tO hzQQY/whAhDCTKfCC69ylXf1pr+Lcswp0afhzMwjs7GIwm5Ku4qXWBt+vKzfVdsbQnIA k4pA== X-Received: by 10.14.107.68 with SMTP id n44mr27387701eeg.26.1379172088884; Sat, 14 Sep 2013 08:21:28 -0700 (PDT) Received: from shock.dandreoli.com (j115181.upc-j.chello.nl. [24.132.115.181]) by mx.google.com with ESMTPSA id y47sm24866969eew.12.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 14 Sep 2013 08:21:27 -0700 (PDT) Received: by shock.dandreoli.com (Postfix, from userid 1000) id 93E2D34020D; Sat, 14 Sep 2013 17:21:24 +0200 (CEST) Message-Id: <20130914152124.317379835@gmail.com> User-Agent: quilt/0.60-1 Date: Sat, 14 Sep 2013 17:20:36 +0200 From: Domenico Andreoli To: Russell King - ARM Linux , Olof Johansson , Arnd Bergmann Subject: [PATCH v4 4/4] ARM: bcm4760: Add restart hook References: <20130914152032.401907974@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-20130914_112153_236737_936EF8DC X-CRM114-Status: GOOD ( 19.23 ) X-Spam-Score: -1.9 (-) Cc: Domenico Andreoli , linux-arm-kernel@lists.infradead.org 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.0 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. v4: * moved the watchdog based implementation to drivers/watchdog 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/Kconfig | 2 + drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/bcm4760_wdt.c | 109 ++++++++++ 6 files changed, 142 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 @@ -39,6 +39,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/drivers/watchdog/Makefile =================================================================== --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_USBPCWATCHDOG) += pcwd_usb. obj-$(CONFIG_ARM_SP805_WATCHDOG) += sp805_wdt.o obj-$(CONFIG_AT91RM9200_WATCHDOG) += at91rm9200_wdt.o obj-$(CONFIG_AT91SAM9X_WATCHDOG) += at91sam9_wdt.o +obj-$(CONFIG_BCM4760_WDT) += bcm4760_wdt.o obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o obj-$(CONFIG_TWL4030_WATCHDOG) += twl4030_wdt.o obj-$(CONFIG_21285_WATCHDOG) += wdt285.o Index: b/drivers/watchdog/bcm4760_wdt.c =================================================================== --- /dev/null +++ b/drivers/watchdog/bcm4760_wdt.c @@ -0,0 +1,109 @@ +/* + * Broadcom BCM4760 based ARM11 SoCs watchdog support + * + * Copyright (C) 2013 Domenico Andreoli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#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) + +/* + * The machine restart method can be called from an atomic context so we won't + * be able to ioremap the regs then. + */ +static void __iomem *wdt_regs; + +static void *arm_pm_restart_saved; + +static void bcm4760_restart(enum reboot_mode mode, const char *cmd) +{ + /* 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 const struct of_device_id bcm4760_pm_wdt_match[] __initconst = { + { .compatible = "brcm,bcm4760-pm-wdt" }, + {}, +}; + +static int __init bcm4760_wdt_init(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 -1; + } + + wdt_regs = of_iomap(node, 0); + of_node_put(node); + + if (!wdt_regs) { + pr_err("Can't remap watchdog registers\n"); + return -1; + } + + /* 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); + + arm_pm_restart_saved = arm_pm_restart; + arm_pm_restart = bcm4760_restart; + return 0; +} + +static int __exit bcm4760_wdt_exit(void) +{ + arm_pm_restart = arm_pm_restart_saved; + iounmap(wdt_regs); + return 0; +} + +module_init(bcm4760_wdt_init); +module_exit(bcm4760_wdt_exit); Index: b/arch/arm/mach-bcm/Kconfig =================================================================== --- a/arch/arm/mach-bcm/Kconfig +++ b/arch/arm/mach-bcm/Kconfig @@ -23,6 +23,8 @@ config ARCH_BCM4760 bool "Broadcom BCM4760 based SoCs (ARM11)" if ARCH_MULTI_V6 select ARM_AMBA select ARM_VIC + select BCM4760_WDT select CLKSRC_OF select GENERIC_CLOCKEVENTS select SOC_BUS + select WATCHDOG Index: b/drivers/watchdog/Kconfig =================================================================== --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -130,6 +130,17 @@ config AT91SAM9X_WATCHDOG Watchdog timer embedded into AT91SAM9X and AT91CAP9 chips. This will reboot your system when the timeout is reached. +config BCM4760_WDT + tristate "Broadcom BCM4760 hardware watchdog" + depends on ARCH_BCM4760 + select WATCHDOG_CORE + help + Watchdog driver for the built in watchdog hardware in Broadcom + BCM4760 SoC, currently used only as restart-hook implementation. + + To compile this driver as a loadable module, choose M here. + The module will be called bcm4760_wdt. + config 21285_WATCHDOG tristate "DC21285 watchdog" depends on FOOTBRIDGE