From patchwork Sun Mar 1 09:40:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 11414191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97DBF921 for ; Sun, 1 Mar 2020 10:08:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7654321775 for ; Sun, 1 Mar 2020 10:08:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725874AbgCAKIO (ORCPT ); Sun, 1 Mar 2020 05:08:14 -0500 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:38444 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725768AbgCAKIO (ORCPT ); Sun, 1 Mar 2020 05:08:14 -0500 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 0219ehkc028746; Sun, 1 Mar 2020 11:40:43 +0200 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 4E5926032F; Sun, 1 Mar 2020 11:40:43 +0200 (IST) From: Tomer Maimon To: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, mark.rutland@arm.com, joel@jms.id.au, avifishman70@gmail.com, tali.perry1@gmail.com, yuenn@google.com, benjaminfair@google.com Cc: linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Tomer Maimon Subject: [PATCH v1 1/4] dt-binding: watchdog: add restart priority documentation Date: Sun, 1 Mar 2020 11:40:37 +0200 Message-Id: <20200301094040.123189-2-tmaimon77@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200301094040.123189-1-tmaimon77@gmail.com> References: <20200301094040.123189-1-tmaimon77@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Add device tree restart priority documentation. Signed-off-by: Tomer Maimon --- Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt b/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt index 6d593003c933..0a0f86a25eb0 100644 --- a/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt +++ b/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt @@ -17,6 +17,7 @@ Required clocking property, have to be one of: Optional properties: - timeout-sec : Contains the watchdog timeout in seconds +- nuvoton,restart-priority : Contains the card restart priority. Example: @@ -25,4 +26,5 @@ timer@f000801c { interrupts = ; reg = <0xf000801c 0x4>; clocks = <&clk NPCM7XX_CLK_TIMER>; + nuvoton,restart-priority = <155>; }; From patchwork Sun Mar 1 09:40:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 11414193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBE85930 for ; Sun, 1 Mar 2020 10:08:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BA99621775 for ; Sun, 1 Mar 2020 10:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725877AbgCAKIP (ORCPT ); Sun, 1 Mar 2020 05:08:15 -0500 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:38444 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725768AbgCAKIP (ORCPT ); Sun, 1 Mar 2020 05:08:15 -0500 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 0219ehYm028747; Sun, 1 Mar 2020 11:40:43 +0200 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id C7D2660330; Sun, 1 Mar 2020 11:40:43 +0200 (IST) From: Tomer Maimon To: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, mark.rutland@arm.com, joel@jms.id.au, avifishman70@gmail.com, tali.perry1@gmail.com, yuenn@google.com, benjaminfair@google.com Cc: linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Tomer Maimon Subject: [PATCH v1 2/4] watchdog: npcm: add restart priority support Date: Sun, 1 Mar 2020 11:40:38 +0200 Message-Id: <20200301094040.123189-3-tmaimon77@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200301094040.123189-1-tmaimon77@gmail.com> References: <20200301094040.123189-1-tmaimon77@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Add NPCM watchdog restart priority support. The default restart priority is 128. Signed-off-by: Tomer Maimon --- drivers/watchdog/npcm_wdt.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c index 9c773c3d6d5d..8609c7acf17d 100644 --- a/drivers/watchdog/npcm_wdt.c +++ b/drivers/watchdog/npcm_wdt.c @@ -181,6 +181,7 @@ static int npcm_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct npcm_wdt *wdt; + u32 priority; int irq; int ret; @@ -196,6 +197,11 @@ static int npcm_wdt_probe(struct platform_device *pdev) if (irq < 0) return irq; + if (of_property_read_u32(pdev->dev.of_node, "nuvoton,restart-priority", &priority)) + watchdog_set_restart_priority(&wdt->wdd, 128); + else + watchdog_set_restart_priority(&wdt->wdd, priority); + wdt->wdd.info = &npcm_wdt_info; wdt->wdd.ops = &npcm_wdt_ops; wdt->wdd.min_timeout = 1; From patchwork Sun Mar 1 09:40:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 11414195 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AA80930 for ; Sun, 1 Mar 2020 10:08:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EDBA821775 for ; Sun, 1 Mar 2020 10:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725884AbgCAKIQ (ORCPT ); Sun, 1 Mar 2020 05:08:16 -0500 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:38444 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725768AbgCAKIQ (ORCPT ); Sun, 1 Mar 2020 05:08:16 -0500 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 0219eidV028748; Sun, 1 Mar 2020 11:40:44 +0200 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id 34FF8603B0; Sun, 1 Mar 2020 11:40:44 +0200 (IST) From: Tomer Maimon To: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, mark.rutland@arm.com, joel@jms.id.au, avifishman70@gmail.com, tali.perry1@gmail.com, yuenn@google.com, benjaminfair@google.com Cc: linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Tomer Maimon Subject: [PATCH v1 3/4] dt-binding: watchdog: add bootstatus reset type documentation Date: Sun, 1 Mar 2020 11:40:39 +0200 Message-Id: <20200301094040.123189-4-tmaimon77@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200301094040.123189-1-tmaimon77@gmail.com> References: <20200301094040.123189-1-tmaimon77@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Add device tree three bootstatus reset types documentation. Signed-off-by: Tomer Maimon --- .../bindings/watchdog/nuvoton,npcm-wdt.txt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt b/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt index 0a0f86a25eb0..836e0ac29196 100644 --- a/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt +++ b/Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt @@ -18,6 +18,33 @@ Required clocking property, have to be one of: Optional properties: - timeout-sec : Contains the watchdog timeout in seconds - nuvoton,restart-priority : Contains the card restart priority. +- nuvoton,card-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the card reset type for checking and indicating + the last card reset status (WDIOF_CARDRESET) + + If 'nuvoton,card-reset-type' is not specified the default is porst + + Reset types: + - porst: Power reset + - corst: Core reset + - wdX : Watchdog reset X (X represante 0-2) + - swX : Software reset X (X represante 1-4) + +- nuvoton,ext1-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the external 2 reset type for checking and indicating + the last external 2 reset status (WDIOF_EXTERN1) + + If 'nuvoton,card-reset-type' is not specified the default is wd0. + + Reset types are the same as in nuvoton,card-reset-type property. + +- nuvoton,ext2-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the external 2 reset type for checking and indicating + the last external 2 reset status (WDIOF_EXTERN2) + + If 'nuvoton,card-reset-type' is not specified the default is sw1. + + Reset types are the same as in nuvoton,card-reset-type property. Example: @@ -27,4 +54,7 @@ timer@f000801c { reg = <0xf000801c 0x4>; clocks = <&clk NPCM7XX_CLK_TIMER>; nuvoton,restart-priority = <155>; + nuvoton,card-reset-type = "porst"; + nuvoton,ext1-reset-type = "wd1"; + nuvoton,ext2-reset-type = "sw2"; }; From patchwork Sun Mar 1 09:40:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomer Maimon X-Patchwork-Id: 11414197 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0969D921 for ; Sun, 1 Mar 2020 10:08:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7B59222C2 for ; Sun, 1 Mar 2020 10:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725892AbgCAKIS (ORCPT ); Sun, 1 Mar 2020 05:08:18 -0500 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:38444 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725768AbgCAKIS (ORCPT ); Sun, 1 Mar 2020 05:08:18 -0500 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 0219ej21028757; Sun, 1 Mar 2020 11:40:45 +0200 Received: by taln60.nuvoton.co.il (Postfix, from userid 10070) id B468E6032E; Sun, 1 Mar 2020 11:40:45 +0200 (IST) From: Tomer Maimon To: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, mark.rutland@arm.com, joel@jms.id.au, avifishman70@gmail.com, tali.perry1@gmail.com, yuenn@google.com, benjaminfair@google.com Cc: linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, Tomer Maimon Subject: [PATCH v1 4/4] watchdog: npcm: sets card ext1 and ext2 bootstatus during probe Date: Sun, 1 Mar 2020 11:40:40 +0200 Message-Id: <20200301094040.123189-5-tmaimon77@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200301094040.123189-1-tmaimon77@gmail.com> References: <20200301094040.123189-1-tmaimon77@gmail.com> MIME-Version: 1.0 Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org During probe NPCM watchdog sets the following bootstatus flags: - WDIOF_CARDRESET represent power and core reset. - WDIOF_EXTERN1 represent watchdog 0-2 reset. - WDIOF_EXTERN2 represent software 1-4 reset. Each flag is representing a group of bootstatus. The user can configure through the device treethe exact reset to each flag group. Signed-off-by: Tomer Maimon --- drivers/watchdog/npcm_wdt.c | 132 ++++++++++++++++++++++++++++++++---- 1 file changed, 119 insertions(+), 13 deletions(-) diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c index 8609c7acf17d..dba9a73249c9 100644 --- a/drivers/watchdog/npcm_wdt.c +++ b/drivers/watchdog/npcm_wdt.c @@ -11,7 +11,24 @@ #include #include #include - +#include +#include + +/* NPCM7xx GCR module */ +#define NPCM7XX_RESSR_OFFSET 0x6C +#define NPCM7XX_INTCR2_OFFSET 0x60 + +#define NPCM7XX_PORST BIT(31) +#define NPCM7XX_CORST BIT(30) +#define NPCM7XX_WD0RST BIT(29) +#define NPCM7XX_WD1RST BIT(24) +#define NPCM7XX_WD2RST BIT(23) +#define NPCM7XX_SWR1RST BIT(28) +#define NPCM7XX_SWR2RST BIT(27) +#define NPCM7XX_SWR3RST BIT(26) +#define NPCM7XX_SWR4RST BIT(25) + + /* WD register */ #define NPCM_WTCR 0x1C #define NPCM_WTCLK (BIT(10) | BIT(11)) /* Clock divider */ @@ -43,6 +60,9 @@ struct npcm_wdt { struct watchdog_device wdd; void __iomem *reg; + u32 card_reset; + u32 ext1_reset; + u32 ext2_reset; }; static inline struct npcm_wdt *to_npcm_wdt(struct watchdog_device *wdd) @@ -103,30 +123,29 @@ static int npcm_wdt_stop(struct watchdog_device *wdd) return 0; } - static int npcm_wdt_set_timeout(struct watchdog_device *wdd, unsigned int timeout) { if (timeout < 2) wdd->timeout = 1; else if (timeout < 3) - wdd->timeout = 2; + wdd->timeout = 2; else if (timeout < 6) - wdd->timeout = 5; + wdd->timeout = 5; else if (timeout < 11) - wdd->timeout = 10; + wdd->timeout = 10; else if (timeout < 22) - wdd->timeout = 21; + wdd->timeout = 21; else if (timeout < 44) - wdd->timeout = 43; + wdd->timeout = 43; else if (timeout < 87) - wdd->timeout = 86; + wdd->timeout = 86; else if (timeout < 173) - wdd->timeout = 172; + wdd->timeout = 172; else if (timeout < 688) - wdd->timeout = 687; + wdd->timeout = 687; else - wdd->timeout = 2750; + wdd->timeout = 2750; if (watchdog_active(wdd)) npcm_wdt_start(wdd); @@ -177,9 +196,61 @@ static const struct watchdog_ops npcm_wdt_ops = { .restart = npcm_wdt_restart, }; +static void npcm_get_reset_status(struct npcm_wdt *wdt, struct device *dev) +{ + struct regmap *gcr_regmap; + u32 rstval; + + if (of_device_is_compatible(dev->of_node, "nuvoton,npcm750-wdt")) { + gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr"); + if (IS_ERR(gcr_regmap)) + dev_warn(dev, "Failed to find nuvoton,npcm750-gcr WD reset status not supported\n"); + + regmap_read(gcr_regmap, NPCM7XX_RESSR_OFFSET, &rstval); + if (!rstval) { + regmap_read(gcr_regmap, NPCM7XX_INTCR2_OFFSET, &rstval); + rstval = ~rstval; + } + + if (rstval & wdt->card_reset) + wdt->wdd.bootstatus |= WDIOF_CARDRESET; + if (rstval & wdt->ext1_reset) + wdt->wdd.bootstatus |= WDIOF_EXTERN1; + if (rstval & wdt->ext2_reset) + wdt->wdd.bootstatus |= WDIOF_EXTERN2; + } +} + +static u32 npcm_wdt_reset_type(const char *reset_type) +{ + if (!strcmp(reset_type, "porst")) + return NPCM7XX_PORST; + else if (!strcmp(reset_type, "corst")) + return NPCM7XX_CORST; + else if (!strcmp(reset_type, "wd0")) + return NPCM7XX_WD0RST; + else if (!strcmp(reset_type, "wd1")) + return NPCM7XX_WD1RST; + else if (!strcmp(reset_type, "wd2")) + return NPCM7XX_WD2RST; + else if (!strcmp(reset_type, "sw1")) + return NPCM7XX_SWR1RST; + else if (!strcmp(reset_type, "sw2")) + return NPCM7XX_SWR2RST; + else if (!strcmp(reset_type, "sw3")) + return NPCM7XX_SWR3RST; + else if (!strcmp(reset_type, "sw4")) + return NPCM7XX_SWR4RST; + + return 0; +} + static int npcm_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; + const char *card_reset_type; + const char *ext1_reset_type; + const char *ext2_reset_type; struct npcm_wdt *wdt; u32 priority; int irq; @@ -202,6 +273,39 @@ static int npcm_wdt_probe(struct platform_device *pdev) else watchdog_set_restart_priority(&wdt->wdd, priority); + ret = of_property_read_string(pdev->dev.of_node, + "nuvoton,card-reset-type", + &card_reset_type); + if (ret) { + wdt->card_reset = NPCM7XX_PORST; + } else { + wdt->card_reset = npcm_wdt_reset_type(card_reset_type); + if (!wdt->card_reset) + wdt->card_reset = NPCM7XX_PORST; + } + + ret = of_property_read_string(pdev->dev.of_node, + "nuvoton,ext1-reset-type", + &ext1_reset_type); + if (ret) { + wdt->ext1_reset = NPCM7XX_WD0RST; + } else { + wdt->ext1_reset = npcm_wdt_reset_type(ext1_reset_type); + if (!wdt->ext1_reset) + wdt->ext1_reset = NPCM7XX_WD0RST; + } + + ret = of_property_read_string(pdev->dev.of_node, + "nuvoton,ext2-reset-type", + &ext2_reset_type); + if (ret) { + wdt->ext2_reset = NPCM7XX_SWR1RST; + } else { + wdt->ext2_reset = npcm_wdt_reset_type(ext2_reset_type); + if (!wdt->ext2_reset) + wdt->ext2_reset = NPCM7XX_SWR1RST; + } + wdt->wdd.info = &npcm_wdt_info; wdt->wdd.ops = &npcm_wdt_ops; wdt->wdd.min_timeout = 1; @@ -220,8 +324,10 @@ static int npcm_wdt_probe(struct platform_device *pdev) set_bit(WDOG_HW_RUNNING, &wdt->wdd.status); } - ret = devm_request_irq(dev, irq, npcm_wdt_interrupt, 0, "watchdog", - wdt); + npcm_get_reset_status(wdt, dev); + + ret = devm_request_irq(dev, irq, npcm_wdt_interrupt, 0, + "watchdog", wdt); if (ret) return ret;