From patchwork Wed May 24 06:34:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keiji Hayashibara X-Patchwork-Id: 100416 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp136123qge; Tue, 23 May 2017 23:45:16 -0700 (PDT) X-Received: by 10.84.224.77 with SMTP id a13mr41731689plt.132.1495608316498; Tue, 23 May 2017 23:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495608316; cv=none; d=google.com; s=arc-20160816; b=cvEH7eGjv1PwCqcEkFZNxApjAIs1PtamXzUAZSVngo8AgdVupjdGVc6X6qF4ufW23D SwESICxmT7FzZPdbgsLzogEv4TQ6kEoarOGgpow4wTSnBAUsDezNuHOIRBVcUWm2ZfEX TxQpwMMPyaPfBAvLs3K/s7DuucX6vhIpV4M2kwyDK0hZLroZXNF+2uy4GNdCLsh4JiAZ F0eBa/W5zdUWTId8kyWvtCiZq4GdPsDBatiNXDQYPObSFT3DXlBZnC4rB3AKTkE2kFq5 ctqHfF1cVjBAgPQuT834Z58481RiGxTn8G5PlSgvX1yHz4Invm9ziLsP6wIBatVJSCtl U1Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=8R9EJiyergfK0GrKgmkQu3cH2q2RItkftdw8tPAP7bA=; b=VRK6pSfeXCHfzXGkPcigLlF6rj7IqIPks9eAsqAZRZtJh/OXY3XKadWaSguC5/m6Rj S2EvG7iW0EEW2yXbQ3ZIFKvrOxQhQKlKZUI2F1IQ22Eu4OVyYYxBHaGmu/M2/vlOBC9q V6bcPcSyEL60E2bTvUK3QmkNTucjSkqQVepS0U5KB7u8mZoyIGzDToMZmWgfs5pLHjm8 bEc7076pIGOFkK0U99KztFuCnWlmtoMS1NDryOJF0J9P/PhqTBsR7xnFi7t/bGyEudg8 0g1rmWwZaaN/Nk8udBiP9calBvDyNIrjOQfoYn7uQ09sDhQ4Uxv3wI86iaDs3VadNEhS h2rA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i75si17048548pfk.363.2017.05.23.23.45.16 for ; Tue, 23 May 2017 23:45:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934208AbdEXGpP (ORCPT ); Wed, 24 May 2017 02:45:15 -0400 Received: from mx.socionext.com ([202.248.49.38]:58380 "EHLO mx.socionext.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751381AbdEXGpO (ORCPT ); Wed, 24 May 2017 02:45:14 -0400 X-Greylist: delayed 591 seconds by postgrey-1.27 at vger.kernel.org; Wed, 24 May 2017 02:45:14 EDT Received: from unknown (HELO kinkan-ex.css.socionext.com) ([172.31.9.52]) by mx.socionext.com with ESMTP; 24 May 2017 15:35:22 +0900 Received: from mail.mfilter.local (unknown [10.213.24.62]) by kinkan-ex.css.socionext.com (Postfix) with ESMTP id B7FDF180C03; Wed, 24 May 2017 15:35:22 +0900 (JST) Received: from 172.31.9.51 (172.31.9.51) by m-FILTER with ESMTP; Wed, 24 May 2017 15:35:22 +0900 Received: from plum.e01.socionext.com (unknown [10.213.132.32]) by kinkan.css.socionext.com (Postfix) with ESMTP id 1A8E21A1207; Wed, 24 May 2017 15:35:22 +0900 (JST) From: Keiji Hayashibara To: wim@iguana.be, linux@roeck-us.net Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, masami.hiramatsu@linaro.org, jaswinder.singh@linaro.org, yamada.masahiro@socionext.com, hayashi.kunihiko@socionext.com, owada.kiyoshi@socionext.com, Keiji Hayashibara Subject: [PATCH 1/2] watchdog: uniphier: add UniPhier watchdog driver Date: Wed, 24 May 2017 15:34:51 +0900 Message-Id: <1495607692-657-2-git-send-email-hayashibara.keiji@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495607692-657-1-git-send-email-hayashibara.keiji@socionext.com> References: <1495607692-657-1-git-send-email-hayashibara.keiji@socionext.com> Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Add a watchdog driver for Socionext UniPhier series SoC. Note that the timeout value for this device must be a power of 2 because of the specification. Signed-off-by: Keiji Hayashibara --- .../devicetree/bindings/watchdog/uniphier-wdt.txt | 20 ++ Documentation/watchdog/watchdog-parameters.txt | 6 + drivers/watchdog/Kconfig | 11 + drivers/watchdog/Makefile | 1 + drivers/watchdog/uniphier_wdt.c | 273 +++++++++++++++++++++ 5 files changed, 311 insertions(+) create mode 100644 Documentation/devicetree/bindings/watchdog/uniphier-wdt.txt create mode 100644 drivers/watchdog/uniphier_wdt.c -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/Documentation/devicetree/bindings/watchdog/uniphier-wdt.txt b/Documentation/devicetree/bindings/watchdog/uniphier-wdt.txt new file mode 100644 index 0000000..a59d1ba --- /dev/null +++ b/Documentation/devicetree/bindings/watchdog/uniphier-wdt.txt @@ -0,0 +1,20 @@ +UniPhier watchdog timer controller + +This UniPhier watchdog timer controller must be under sysctrl compatible node. + +Required properties: +- compatible: should be "socionext,uniphier-wdt" + +Example: + + sysctrl@61840000 { + compatible = "socionext,uniphier-ld11-sysctrl", + "simple-mfd", "syscon"; + reg = <0x61840000 0x4000>; + + sys_wdt: watchdog { + compatible = "socionext,uniphier-wdt"; + } + + other nodes ... + }; diff --git a/Documentation/watchdog/watchdog-parameters.txt b/Documentation/watchdog/watchdog-parameters.txt index 4f7d86d..6f9d7b4 100644 --- a/Documentation/watchdog/watchdog-parameters.txt +++ b/Documentation/watchdog/watchdog-parameters.txt @@ -369,6 +369,12 @@ timeout: Watchdog timeout in seconds. (0 +#include +#include +#include +#include +#include +#include + +/* WDT timer setting register */ +#define WDTTIMSET 0x3004 +#define WDTTIMSET_PERIOD_MASK (0xf << 0) +#define WDTTIMSET_PERIOD_1_SEC (0x3 << 0) +#define WDTTIMSET_PERIOD_2_SEC (0x4 << 0) +#define WDTTIMSET_PERIOD_4_SEC (0x5 << 0) +#define WDTTIMSET_PERIOD_8_SEC (0x6 << 0) +#define WDTTIMSET_PERIOD_16_SEC (0x7 << 0) +#define WDTTIMSET_PERIOD_32_SEC (0x8 << 0) +#define WDTTIMSET_PERIOD_64_SEC (0x9 << 0) +#define WDTTIMSET_PERIOD_128_SEC (0xa << 0) + +/* WDT reset selection register */ +#define WDTRSTSEL 0x3008 +#define WDTRSTSEL_RSTSEL_MASK (0x3 << 0) +#define WDTRSTSEL_RSTSEL_BOTH (0x0 << 0) +#define WDTRSTSEL_RSTSEL_IRQ_ONLY (0x2 << 0) + +/* WDT control register */ +#define WDTCTRL 0x300c +#define WDTCTRL_STATUS BIT(8) +#define WDTCTRL_CLEAR BIT(1) +#define WDTCTRL_ENABLE BIT(0) + +#define SEC_TO_WDTTIMSET_PRD(sec) \ + (ilog2(sec) + WDTTIMSET_PERIOD_1_SEC) + +#define WDTST_TIMEOUT 1000 /* usec */ + +#define WDT_DEFAULT_TIMEOUT 64 /* Default is 64 seconds */ +#define WDT_PERIOD_MIN 1 +#define WDT_PERIOD_MAX 128 + +static unsigned int timeout = WDT_DEFAULT_TIMEOUT; +static bool nowayout = WATCHDOG_NOWAYOUT; + +struct uniphier_wdt_dev { + struct watchdog_device wdt_dev; + struct regmap *regmap; +}; + +/* + * UniPhier Watchdog operations + */ +static int uniphier_watchdog_ping(struct watchdog_device *w) +{ + struct uniphier_wdt_dev *wdev = watchdog_get_drvdata(w); + + /* Clear counter */ + return regmap_write(wdev->regmap, WDTCTRL, + WDTCTRL_CLEAR | WDTCTRL_ENABLE); +} + +static int __uniphier_watchdog_start(struct regmap *regmap, unsigned int sec) +{ + int ret; + + /* Setup period */ + ret = regmap_write(regmap, WDTTIMSET, + SEC_TO_WDTTIMSET_PRD(sec)); + if (ret) + return ret; + + /* Enable and clear watchdog */ + return regmap_write(regmap, WDTCTRL, WDTCTRL_ENABLE | WDTCTRL_CLEAR); +} + +static int __uniphier_watchdog_stop(struct regmap *regmap) +{ + /* Disable and stop watchdog */ + return regmap_write_bits(regmap, WDTCTRL, WDTCTRL_ENABLE, 0); +} + +static int __uniphier_watchdog_restart(struct regmap *regmap, unsigned int sec) +{ + unsigned int val; + int ret; + + ret = __uniphier_watchdog_stop(regmap); + if (ret) + return ret; + + ret = regmap_read_poll_timeout(regmap, WDTCTRL, val, + !(val & WDTCTRL_STATUS), + 0, WDTST_TIMEOUT); + if (ret) + return ret; + + return __uniphier_watchdog_start(regmap, sec); +} + +static int uniphier_watchdog_start(struct watchdog_device *w) +{ + struct uniphier_wdt_dev *wdev = watchdog_get_drvdata(w); + unsigned int tmp_timeout; + + tmp_timeout = roundup_pow_of_two(w->timeout); + + return __uniphier_watchdog_start(wdev->regmap, tmp_timeout); +} + +static int uniphier_watchdog_stop(struct watchdog_device *w) +{ + struct uniphier_wdt_dev *wdev = watchdog_get_drvdata(w); + + return __uniphier_watchdog_stop(wdev->regmap); +} + +static int uniphier_watchdog_set_timeout(struct watchdog_device *w, + unsigned int t) +{ + struct uniphier_wdt_dev *wdev = watchdog_get_drvdata(w); + unsigned int tmp_timeout; + int ret; + + tmp_timeout = roundup_pow_of_two(t); + if (tmp_timeout == w->timeout) + return 0; + + if (watchdog_active(w)) { + ret = __uniphier_watchdog_restart(wdev->regmap, tmp_timeout); + if (ret) + return ret; + } + + w->timeout = tmp_timeout; + + return 0; +} + +/* + * Kernel Interfaces + */ +static const struct watchdog_info uniphier_wdt_info = { + .identity = "uniphier-wdt", + .options = WDIOF_SETTIMEOUT | + WDIOF_KEEPALIVEPING | + WDIOF_MAGICCLOSE | + WDIOF_OVERHEAT, +}; + +static const struct watchdog_ops uniphier_wdt_ops = { + .owner = THIS_MODULE, + .start = uniphier_watchdog_start, + .stop = uniphier_watchdog_stop, + .ping = uniphier_watchdog_ping, + .set_timeout = uniphier_watchdog_set_timeout, + .restart = NULL, +}; + +static int uniphier_wdt_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct uniphier_wdt_dev *wdev; + struct regmap *regmap; + struct device_node *parent; + int ret; + + wdev = devm_kzalloc(dev, sizeof(*wdev), GFP_KERNEL); + if (!wdev) + return -ENOMEM; + + platform_set_drvdata(pdev, wdev); + + parent = of_get_parent(dev->of_node); /* parent should be syscon node */ + regmap = syscon_node_to_regmap(parent); + of_node_put(parent); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + wdev->regmap = regmap; + wdev->wdt_dev.info = &uniphier_wdt_info; + wdev->wdt_dev.ops = &uniphier_wdt_ops; + wdev->wdt_dev.timeout = WDT_DEFAULT_TIMEOUT; + wdev->wdt_dev.max_timeout = WDT_PERIOD_MAX; + wdev->wdt_dev.min_timeout = WDT_PERIOD_MIN; + wdev->wdt_dev.parent = dev; + + watchdog_init_timeout(&wdev->wdt_dev, timeout, dev); + watchdog_set_nowayout(&wdev->wdt_dev, nowayout); + watchdog_set_restart_priority(&wdev->wdt_dev, 128); + + watchdog_set_drvdata(&wdev->wdt_dev, wdev); + + uniphier_watchdog_stop(&wdev->wdt_dev); + ret = regmap_write(wdev->regmap, WDTRSTSEL, WDTRSTSEL_RSTSEL_BOTH); + if (ret) + return ret; + + ret = watchdog_register_device(&wdev->wdt_dev); + if (ret) + return ret; + + dev_info(dev, "watchdog driver (timeout=%d sec, nowayout=%d)\n", + wdev->wdt_dev.timeout, nowayout); + + return 0; +} + +static void uniphier_wdt_shutdown(struct platform_device *pdev) +{ + struct uniphier_wdt_dev *wdev = platform_get_drvdata(pdev); + + if (watchdog_active(&wdev->wdt_dev)) + uniphier_watchdog_stop(&wdev->wdt_dev); +} + +static int uniphier_wdt_remove(struct platform_device *pdev) +{ + struct uniphier_wdt_dev *wdev = platform_get_drvdata(pdev); + + watchdog_unregister_device(&wdev->wdt_dev); + + return 0; +} + +static const struct of_device_id uniphier_wdt_dt_ids[] = { + { .compatible = "socionext,uniphier-wdt" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, uniphier_wdt_dt_ids); + +static struct platform_driver uniphier_wdt_driver = { + .probe = uniphier_wdt_probe, + .remove = uniphier_wdt_remove, + .shutdown = uniphier_wdt_shutdown, + .driver = { + .name = "uniphier-wdt", + .of_match_table = uniphier_wdt_dt_ids, + }, +}; + +module_platform_driver(uniphier_wdt_driver); + +module_param(timeout, uint, 0000); +MODULE_PARM_DESC(timeout, + "Watchdog timeout seconds in power of 2. (0 < timeout < 128, default=" + __MODULE_STRING(WDT_DEFAULT_TIMEOUT) ")"); + +module_param(nowayout, bool, 0000); +MODULE_PARM_DESC(nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +MODULE_AUTHOR("Socionext Inc."); +MODULE_DESCRIPTION("UniPhier Watchdog Device Driver"); +MODULE_LICENSE("GPL v2"); From patchwork Wed May 24 06:34:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keiji Hayashibara X-Patchwork-Id: 100417 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp136226qge; Tue, 23 May 2017 23:45:43 -0700 (PDT) X-Received: by 10.99.98.66 with SMTP id w63mr36438237pgb.223.1495608343848; Tue, 23 May 2017 23:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495608343; cv=none; d=google.com; s=arc-20160816; b=JMZWsP6/ceZtt2JkV8oxM7MfcjoMFrIYCEM8CyvYTbKKLZGrvcXzKBUoEfEF6cAbl2 Gppt3Mc2McajCC5YQKKwWQtu6Zle7K4f9XirAH4xrudCBsOToQ3NmTLG5rOoRLW7xz8p RrC2BjwWL9y0dsMrt9/XdJIjlmvg3xss0MK6aSIN2/xoJ0mXonPh2iSll6SFyW5Sbe0V gF8Z9JhOmlwqwvA9aVASSgZMt+I8ySLSro/dZs0k9JNziS+FS2roMpyCOcO+D9suSC8+ q08ql0ltSN3vhHHXMrr5oYF8gfIpkwhzQWvj1OlPLmW9Z8aemLhp1DDdwsyOxSUCh52k JAgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=o+rr9/BZFIbSMnBPI6eKNA63CIo09vr6BXGyDc2MI2Q=; b=0ACKCeJjYi7Y22qF6ec9jWTPBUCjJZSFS2KIuSKuqlkvwUX85GHcuzti/VUAzkFevO bdOb26FGi5z6w/Kha/0TQq/b7DWfru4xm7n+bP0lQtLD6atd45n5bAAwqRHgo2FFYCvr TVAf9yBvhXdjwyylxG6jImbNhi5gp58NeX2JG+emZ9TO9zrRwxYS6MUti4YnoiDRM1O6 V4k+Ga1knYIXwd5eja6laRKs0d5y+4vfCmpNZcvYwZfZlRJOKVWd4tf+tUSdcwtjpiJZ //21v5rek9OxNsfqrPqJ0qd+ksVwee6T/3dJsowOUf+X2owP6qky9fSeF+4XVDDQz0Wh Ns8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 88si8786729plb.310.2017.05.23.23.45.43 for ; Tue, 23 May 2017 23:45:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-watchdog-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-watchdog-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938475AbdEXGpX (ORCPT ); Wed, 24 May 2017 02:45:23 -0400 Received: from mx.socionext.com ([202.248.49.38]:58383 "EHLO mx.socionext.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S938474AbdEXGpV (ORCPT ); Wed, 24 May 2017 02:45:21 -0400 Received: from unknown (HELO kinkan-ex.css.socionext.com) ([172.31.9.52]) by mx.socionext.com with ESMTP; 24 May 2017 15:35:23 +0900 Received: from mail.mfilter.local (unknown [10.213.24.61]) by kinkan-ex.css.socionext.com (Postfix) with ESMTP id C75BE180C03; Wed, 24 May 2017 15:35:23 +0900 (JST) Received: from 172.31.9.51 (172.31.9.51) by m-FILTER with ESMTP; Wed, 24 May 2017 15:35:23 +0900 Received: from plum.e01.socionext.com (unknown [10.213.132.32]) by kinkan.css.socionext.com (Postfix) with ESMTP id 64B591A1207; Wed, 24 May 2017 15:35:23 +0900 (JST) From: Keiji Hayashibara To: wim@iguana.be, linux@roeck-us.net Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, masami.hiramatsu@linaro.org, jaswinder.singh@linaro.org, yamada.masahiro@socionext.com, hayashi.kunihiko@socionext.com, owada.kiyoshi@socionext.com, Keiji Hayashibara Subject: [PATCH 2/2] arm64: dts: uniphier: add watchdog node for LD11 and LD20 Date: Wed, 24 May 2017 15:34:52 +0900 Message-Id: <1495607692-657-3-git-send-email-hayashibara.keiji@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495607692-657-1-git-send-email-hayashibara.keiji@socionext.com> References: <1495607692-657-1-git-send-email-hayashibara.keiji@socionext.com> Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Add nodes of watchdog timer for UniPhier LD11 and LD20 SoC. The watchdog timer is included in sysctrl. Signed-off-by: Keiji Hayashibara --- arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi | 4 ++++ arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi | 4 ++++ 2 files changed, 8 insertions(+) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-watchdog" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi b/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi index da881f5..a3205dc 100644 --- a/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi +++ b/arch/arm64/boot/dts/socionext/uniphier-ld11.dtsi @@ -393,6 +393,10 @@ compatible = "socionext,uniphier-ld11-reset"; #reset-cells = <1>; }; + + sys_wdt: watchdog { + compatible = "socionext,uniphier-wdt"; + }; }; }; }; diff --git a/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi b/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi index a6b3a70..cd08a61 100644 --- a/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi +++ b/arch/arm64/boot/dts/socionext/uniphier-ld20.dtsi @@ -417,6 +417,10 @@ compatible = "socionext,uniphier-ld20-reset"; #reset-cells = <1>; }; + + sys_wdt: watchdog { + compatible = "socionext,uniphier-wdt"; + }; }; }; };