From patchwork Sat Dec 11 21:26:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 523347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E603FC433EF for ; Sat, 11 Dec 2021 21:26:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbhLKV0Y (ORCPT ); Sat, 11 Dec 2021 16:26:24 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:2584 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229615AbhLKV0Y (ORCPT ); Sat, 11 Dec 2021 16:26:24 -0500 X-IronPort-AV: E=Sophos;i="5.88,199,1635174000"; d="scan'208";a="103588511" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 12 Dec 2021 06:26:22 +0900 Received: from localhost.localdomain (unknown [10.226.92.13]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 96A2B4106FBA; Sun, 12 Dec 2021 06:26:20 +0900 (JST) From: Biju Das To: Wim Van Sebroeck , Guenter Roeck Cc: Biju Das , linux-watchdog@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Biju Das , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH 1/4] watchdog: rzg2l_wdt: Fix 32bit overflow issue Date: Sat, 11 Dec 2021 21:26:14 +0000 Message-Id: <20211211212617.19639-1-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org The value of timer_cycle_us can be 0 due to 32bit overflow. For eg:- If we assign the counter value "0xfff" for computing maxval. This patch fixes this issue by appending ULL to 1024, so that it is promoted to 64bit. Signed-off-by: Biju Das Reviewed-by: Guenter Roeck Reviewed-by: Guenter Roeck Reviewed-by: Geert Uytterhoeven --- drivers/watchdog/rzg2l_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/watchdog/rzg2l_wdt.c b/drivers/watchdog/rzg2l_wdt.c index 6b426df34fd6..96f2a018ab62 100644 --- a/drivers/watchdog/rzg2l_wdt.c +++ b/drivers/watchdog/rzg2l_wdt.c @@ -53,7 +53,7 @@ static void rzg2l_wdt_wait_delay(struct rzg2l_wdt_priv *priv) static u32 rzg2l_wdt_get_cycle_usec(unsigned long cycle, u32 wdttime) { - u64 timer_cycle_us = 1024 * 1024 * (wdttime + 1) * MICRO; + u64 timer_cycle_us = 1024 * 1024ULL * (wdttime + 1) * MICRO; return div64_ul(timer_cycle_us, cycle); } From patchwork Sat Dec 11 21:26:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 523632 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B36DC433EF for ; Sat, 11 Dec 2021 21:26:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbhLKV00 (ORCPT ); Sat, 11 Dec 2021 16:26:26 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:2584 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229615AbhLKV0Z (ORCPT ); Sat, 11 Dec 2021 16:26:25 -0500 X-IronPort-AV: E=Sophos;i="5.88,199,1635174000"; d="scan'208";a="103588514" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 12 Dec 2021 06:26:25 +0900 Received: from localhost.localdomain (unknown [10.226.92.13]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 07CD64106FDB; Sun, 12 Dec 2021 06:26:22 +0900 (JST) From: Biju Das To: Wim Van Sebroeck , Guenter Roeck Cc: Biju Das , linux-watchdog@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Biju Das , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH 2/4] watchdog: rzg2l_wdt: Add error check for reset_control_{deassert/reset} Date: Sat, 11 Dec 2021 21:26:15 +0000 Message-Id: <20211211212617.19639-2-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211211212617.19639-1-biju.das.jz@bp.renesas.com> References: <20211211212617.19639-1-biju.das.jz@bp.renesas.com> Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org If reset_control_deassert()/reset_control_reset() fails, then we won't be able to access the device registers. Therefore check the return code of reset_control_deassert()/reset_control_reset() and return the error code to caller in case of error. While at it remove the unnecessary pm_runtime_resume_and_get() from probe(), as it turns on the clocks. Signed-off-by: Biju Das --- drivers/watchdog/rzg2l_wdt.c | 37 +++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/drivers/watchdog/rzg2l_wdt.c b/drivers/watchdog/rzg2l_wdt.c index 96f2a018ab62..58fe4efd9a89 100644 --- a/drivers/watchdog/rzg2l_wdt.c +++ b/drivers/watchdog/rzg2l_wdt.c @@ -85,8 +85,14 @@ static void rzg2l_wdt_init_timeout(struct watchdog_device *wdev) static int rzg2l_wdt_start(struct watchdog_device *wdev) { struct rzg2l_wdt_priv *priv = watchdog_get_drvdata(wdev); + int ret; + + ret = reset_control_deassert(priv->rstc); + if (ret) { + dev_err(wdev->parent, "failed to deassert"); + return ret; + } - reset_control_deassert(priv->rstc); pm_runtime_get_sync(wdev->parent); /* Initialize time out */ @@ -115,9 +121,15 @@ static int rzg2l_wdt_restart(struct watchdog_device *wdev, unsigned long action, void *data) { struct rzg2l_wdt_priv *priv = watchdog_get_drvdata(wdev); + int ret; /* Reset the module before we modify any register */ - reset_control_reset(priv->rstc); + ret = reset_control_reset(priv->rstc); + if (ret) { + dev_err(wdev->parent, "failed to reset"); + return ret; + } + pm_runtime_get_sync(wdev->parent); /* smallest counter value to reboot soon */ @@ -151,12 +163,11 @@ static const struct watchdog_ops rzg2l_wdt_ops = { .restart = rzg2l_wdt_restart, }; -static void rzg2l_wdt_reset_assert_pm_disable_put(void *data) +static void rzg2l_wdt_reset_assert_pm_disable(void *data) { struct watchdog_device *wdev = data; struct rzg2l_wdt_priv *priv = watchdog_get_drvdata(wdev); - pm_runtime_put(wdev->parent); pm_runtime_disable(wdev->parent); reset_control_assert(priv->rstc); } @@ -204,13 +215,11 @@ static int rzg2l_wdt_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, PTR_ERR(priv->rstc), "failed to get cpg reset"); - reset_control_deassert(priv->rstc); + ret = reset_control_deassert(priv->rstc); + if (ret) + return dev_err_probe(dev, ret, "failed to deassert"); + pm_runtime_enable(&pdev->dev); - ret = pm_runtime_resume_and_get(&pdev->dev); - if (ret < 0) { - dev_err(dev, "pm_runtime_resume_and_get failed ret=%pe", ERR_PTR(ret)); - goto out_pm_get; - } priv->wdev.info = &rzg2l_wdt_ident; priv->wdev.ops = &rzg2l_wdt_ops; @@ -222,7 +231,7 @@ static int rzg2l_wdt_probe(struct platform_device *pdev) watchdog_set_drvdata(&priv->wdev, priv); ret = devm_add_action_or_reset(&pdev->dev, - rzg2l_wdt_reset_assert_pm_disable_put, + rzg2l_wdt_reset_assert_pm_disable, &priv->wdev); if (ret < 0) return ret; @@ -235,12 +244,6 @@ static int rzg2l_wdt_probe(struct platform_device *pdev) dev_warn(dev, "Specified timeout invalid, using default"); return devm_watchdog_register_device(&pdev->dev, &priv->wdev); - -out_pm_get: - pm_runtime_disable(dev); - reset_control_assert(priv->rstc); - - return ret; } static const struct of_device_id rzg2l_wdt_ids[] = { From patchwork Sat Dec 11 21:26:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 523346 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1109CC433FE for ; Sat, 11 Dec 2021 21:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230190AbhLKV02 (ORCPT ); Sat, 11 Dec 2021 16:26:28 -0500 Received: from relmlor2.renesas.com ([210.160.252.172]:2584 "EHLO relmlie6.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229615AbhLKV02 (ORCPT ); Sat, 11 Dec 2021 16:26:28 -0500 X-IronPort-AV: E=Sophos;i="5.88,199,1635174000"; d="scan'208";a="103588517" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 12 Dec 2021 06:26:27 +0900 Received: from localhost.localdomain (unknown [10.226.92.13]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id 6F2B44106FDB; Sun, 12 Dec 2021 06:26:25 +0900 (JST) From: Biju Das To: Wim Van Sebroeck , Guenter Roeck Cc: Biju Das , linux-watchdog@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Biju Das , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH 3/4] watchdog: rzg2l_wdt: Add set_timeout callback Date: Sat, 11 Dec 2021 21:26:16 +0000 Message-Id: <20211211212617.19639-3-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211211212617.19639-1-biju.das.jz@bp.renesas.com> References: <20211211212617.19639-1-biju.das.jz@bp.renesas.com> Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org Add support for set_timeout() callback. Signed-off-by: Biju Das --- drivers/watchdog/rzg2l_wdt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/watchdog/rzg2l_wdt.c b/drivers/watchdog/rzg2l_wdt.c index 58fe4efd9a89..c81b9dd05e63 100644 --- a/drivers/watchdog/rzg2l_wdt.c +++ b/drivers/watchdog/rzg2l_wdt.c @@ -117,6 +117,15 @@ static int rzg2l_wdt_stop(struct watchdog_device *wdev) return 0; } +static int rzg2l_wdt_set_timeout(struct watchdog_device *wdev, unsigned int timeout) +{ + wdev->timeout = timeout; + rzg2l_wdt_stop(wdev); + rzg2l_wdt_start(wdev); + + return 0; +} + static int rzg2l_wdt_restart(struct watchdog_device *wdev, unsigned long action, void *data) { @@ -160,6 +169,7 @@ static const struct watchdog_ops rzg2l_wdt_ops = { .start = rzg2l_wdt_start, .stop = rzg2l_wdt_stop, .ping = rzg2l_wdt_ping, + .set_timeout = rzg2l_wdt_set_timeout, .restart = rzg2l_wdt_restart, }; From patchwork Sat Dec 11 21:26:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 523631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 185A7C433F5 for ; Sat, 11 Dec 2021 21:26:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230203AbhLKV0b (ORCPT ); Sat, 11 Dec 2021 16:26:31 -0500 Received: from relmlor1.renesas.com ([210.160.252.171]:39715 "EHLO relmlie5.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229615AbhLKV0b (ORCPT ); Sat, 11 Dec 2021 16:26:31 -0500 X-IronPort-AV: E=Sophos;i="5.88,199,1635174000"; d="scan'208";a="103152636" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie5.idc.renesas.com with ESMTP; 12 Dec 2021 06:26:29 +0900 Received: from localhost.localdomain (unknown [10.226.92.13]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id DB87A4106FBA; Sun, 12 Dec 2021 06:26:27 +0900 (JST) From: Biju Das To: Wim Van Sebroeck , Guenter Roeck Cc: Biju Das , linux-watchdog@vger.kernel.org, Geert Uytterhoeven , Chris Paterson , Biju Das , Prabhakar Mahadev Lad , linux-renesas-soc@vger.kernel.org Subject: [PATCH 4/4] watchdog: rzg2l_wdt: Fix Reboot failed message Date: Sat, 11 Dec 2021 21:26:17 +0000 Message-Id: <20211211212617.19639-4-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211211212617.19639-1-biju.das.jz@bp.renesas.com> References: <20211211212617.19639-1-biju.das.jz@bp.renesas.com> Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org This patch fixes the message "Reboot failed -- System halted" by triggering WDT reset by enabling force reset(WDTRSTB). Signed-off-by: Biju Das --- drivers/watchdog/rzg2l_wdt.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/watchdog/rzg2l_wdt.c b/drivers/watchdog/rzg2l_wdt.c index c81b9dd05e63..497c86129f20 100644 --- a/drivers/watchdog/rzg2l_wdt.c +++ b/drivers/watchdog/rzg2l_wdt.c @@ -21,8 +21,11 @@ #define WDTSET 0x04 #define WDTTIM 0x08 #define WDTINT 0x0C +#define PECR 0x10 +#define PEEN 0x14 #define WDTCNT_WDTEN BIT(0) #define WDTINT_INTDISP BIT(0) +#define PEEN_FORCE_RST BIT(0) #define WDT_DEFAULT_TIMEOUT 60U @@ -130,22 +133,12 @@ static int rzg2l_wdt_restart(struct watchdog_device *wdev, unsigned long action, void *data) { struct rzg2l_wdt_priv *priv = watchdog_get_drvdata(wdev); - int ret; - /* Reset the module before we modify any register */ - ret = reset_control_reset(priv->rstc); - if (ret) { - dev_err(wdev->parent, "failed to reset"); - return ret; - } + /* Generate Reset (WDTRSTB) Signal */ + rzg2l_wdt_write(priv, 0, PECR); - pm_runtime_get_sync(wdev->parent); - - /* smallest counter value to reboot soon */ - rzg2l_wdt_write(priv, WDTSET_COUNTER_VAL(1), WDTSET); - - /* Enable watchdog timer*/ - rzg2l_wdt_write(priv, WDTCNT_WDTEN, WDTCNT); + /* Force reset (WDTRSTB) */ + rzg2l_wdt_write(priv, PEEN_FORCE_RST, PEEN); return 0; }