From patchwork Thu Feb 16 17:23:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Brandt X-Patchwork-Id: 9577765 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 553D760209 for ; Thu, 16 Feb 2017 17:24:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 477C528649 for ; Thu, 16 Feb 2017 17:24:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C5652864D; Thu, 16 Feb 2017 17:24:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75D142864C for ; Thu, 16 Feb 2017 17:24:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932716AbdBPRYD (ORCPT ); Thu, 16 Feb 2017 12:24:03 -0500 Received: from relmlor1.renesas.com ([210.160.252.171]:19247 "EHLO relmlie4.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932254AbdBPRYB (ORCPT ); Thu, 16 Feb 2017 12:24:01 -0500 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie4.idc.renesas.com with ESMTP; 17 Feb 2017 02:23:59 +0900 Received: from relmlac3.idc.renesas.com (relmlac3.idc.renesas.com [10.200.69.23]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 5D4F94ACEF; Fri, 17 Feb 2017 02:23:59 +0900 (JST) Received: by relmlac3.idc.renesas.com (Postfix, from userid 0) id 4FEAC18070; Fri, 17 Feb 2017 02:23:59 +0900 (JST) Received: from relmlac3.idc.renesas.com (localhost [127.0.0.1]) by relmlac3.idc.renesas.com (Postfix) with ESMTP id 4998A1806F; Fri, 17 Feb 2017 02:23:59 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac3.idc.renesas.com with ESMTP id CAK07013; Fri, 17 Feb 2017 02:23:59 +0900 X-IronPort-AV: E=Sophos;i="5.35,169,1483974000"; d="scan'208";a="234792789" Received: from unknown (HELO rtamta01.rta.renesas.com) ([143.103.48.75]) by relmlii2.idc.renesas.com with ESMTP; 17 Feb 2017 02:23:57 +0900 Received: from localhost.localdomain (unknown [143.103.58.208]) by rtamta01.rta.renesas.com (Postfix) with ESMTP id 8180A5CF; Thu, 16 Feb 2017 17:23:51 +0000 (UTC) From: Chris Brandt To: Wim Van Sebroeck , Guenter Roeck , Sebastian Reichel , Rob Herring , Mark Rutland , Simon Horman , Geert Uytterhoeven Cc: linux-renesas-soc@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-watchdog@vger.kernel.org, Chris Brandt Subject: [PATCH v2 1/3] power: reset: Add Renesas reset driver Date: Thu, 16 Feb 2017 12:23:18 -0500 Message-Id: <20170216172320.10897-2-chris.brandt@renesas.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170216172320.10897-1-chris.brandt@renesas.com> References: <20170216172320.10897-1-chris.brandt@renesas.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some Renesas SoCs do not have a reset register and the only way to do a SW controlled reset is to use the watchdog timer. Additionally, since all the WDT timeout options are so quick, a system reset is about the only thing it's good for. Signed-off-by: Chris Brandt Reviewed-by: Geert Uytterhoeven --- v2: * changed DT bindings from 'wdt-reset' to 'rza-wdt' * changed hard coded register values to defines * added msleep to while(1) loop * removed unnecessary #include files * added Reviewed-by: Geert Uytterhoeven --- drivers/power/reset/Kconfig | 9 +++ drivers/power/reset/Makefile | 1 + drivers/power/reset/renesas-reset.c | 112 ++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 drivers/power/reset/renesas-reset.c diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index b8caccc..e3100c9 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig @@ -130,6 +130,15 @@ config POWER_RESET_QNAP Say Y if you have a QNAP NAS. +config POWER_RESET_RENESAS + tristate "Renesas WDT reset driver" + depends on ARCH_RENESAS || COMPILE_TEST + depends on HAS_IOMEM + help + Reboot support for Renesas SoCs with WDT reset. + Some Renesas SoCs do not have a reset register and the only way + to do a SW controlled reset is to use the watchdog timer. + config POWER_RESET_RESTART bool "Restart power-off driver" help diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index 11dae3b..a78a56c 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o +obj-$(CONFIG_POWER_RESET_RENESAS) += renesas-reset.o obj-$(CONFIG_POWER_RESET_RESTART) += restart-poweroff.o obj-$(CONFIG_POWER_RESET_ST) += st-poweroff.o obj-$(CONFIG_POWER_RESET_VERSATILE) += arm-versatile-reboot.o diff --git a/drivers/power/reset/renesas-reset.c b/drivers/power/reset/renesas-reset.c new file mode 100644 index 0000000..812cee0 --- /dev/null +++ b/drivers/power/reset/renesas-reset.c @@ -0,0 +1,112 @@ +/* + * Renesas WDT Reset Driver + * + * Copyright (C) 2017 Renesas Electronics America, Inc. + * Copyright (C) 2017 Chris Brandt + * + * This file is subject to the terms and conditions of the GNU General Public + * License. See the file "COPYING" in the main directory of this archive + * for more details. + * + * based on rmobile-reset.c + * + */ + +#include +#include +#include +#include +#include + +/* Watchdog Timer Registers */ +#define WTCSR 0 +#define WTCSR_MAGIC 0xA500 +#define WTSCR_WT (1<<6) +#define WTSCR_TME (1<<5) + +#define WTCNT 2 +#define WTCNT_MAGIC 0x5A00 + +#define WRCSR 4 +#define WRCSR_MAGIC 0x5A00 +#define WRCSR_RSTE (1<<6) +#define WRCSR_CLEAR_WOVF 0xA500 /* special value */ + +static void __iomem *base; + +static int wdt_reset_handler(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + pr_debug("%s %lu\n", __func__, mode); + + /* Dummy read (must read WRCSR:WOVF at least once before clearing) */ + readb(base + WRCSR); + + writew(WRCSR_CLEAR_WOVF, base + WRCSR); /* Clear WOVF */ + writew(WRCSR_MAGIC | WRCSR_RSTE, base + WRCSR); /* Reset Enable */ + writew(WTCNT_MAGIC, base + WTCNT); /* Counter to 00 */ + + /* Start timer */ + writew(WTCSR_MAGIC | WTSCR_WT | WTSCR_TME, base + WTCSR); + + /* Wait for WDT overflow (reset) */ + while (1) + msleep(1); + + return NOTIFY_DONE; +} + +static struct notifier_block wdt_reset_nb = { + .notifier_call = wdt_reset_handler, + .priority = 192, +}; + +static int wdt_reset_probe(struct platform_device *pdev) +{ + int error; + + base = of_iomap(pdev->dev.of_node, 0); + if (!base) + return -ENODEV; + + error = register_restart_handler(&wdt_reset_nb); + if (error) { + dev_err(&pdev->dev, + "cannot register restart handler (err=%d)\n", error); + goto fail_unmap; + } + + return 0; + +fail_unmap: + iounmap(base); + return error; +} + +static int wdt_reset_remove(struct platform_device *pdev) +{ + unregister_restart_handler(&wdt_reset_nb); + iounmap(base); + return 0; +} + +static const struct of_device_id wdt_reset_of_match[] = { + { .compatible = "renesas,rza-wdt", }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, wdt_reset_of_match); + +static struct platform_driver wdt_reset_driver = { + .probe = wdt_reset_probe, + .remove = wdt_reset_remove, + .driver = { + .name = "wdt_reset", + .of_match_table = wdt_reset_of_match, + }, +}; + +module_platform_driver(wdt_reset_driver); + +MODULE_DESCRIPTION("Renesas WDT Reset Driver"); +MODULE_AUTHOR("Chris Brandt "); +MODULE_LICENSE("GPL v2");