From patchwork Thu Jul 13 09:51:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Hua Qian" X-Patchwork-Id: 703538 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 36D14EB64DD for ; Thu, 13 Jul 2023 09:52:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233042AbjGMJwK (ORCPT ); Thu, 13 Jul 2023 05:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234236AbjGMJwE (ORCPT ); Thu, 13 Jul 2023 05:52:04 -0400 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C307526BA for ; Thu, 13 Jul 2023 02:51:56 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 20230713095154148cec6b3066112e55 for ; Thu, 13 Jul 2023 11:51:54 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=huaqian.li@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=02qU89AAuYA9eD+QvpZmA4hgJEjRQH3j6BCnYE1DiwI=; b=PK0XshIWBAT/+KK7oqZXTcjFhFB6B01p0rwPZf+/DmzMUJL9pExMg2RSsiwTcIfcNXu5GR 5r03eDrLnGd7SNpSVAOMRw4Qs5T7hbszN9k47kxJmCvQ6WDP81Z35yrY8JCG3758jjsXKoHD 91kspZqGeUp05M3P5LowIgy2fAmtk=; From: huaqian.li@siemens.com To: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: huaqianlee@gmail.com, nm@ti.com, vigneshr@ti.com, kristo@kernel.org, linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jan.kiszka@siemens.com, baocheng.su@siemens.com, Li Hua Qian Subject: [PATCH v3 1/3] dt-bindings: watchdog: ti,rti-wdt: Add support for WDIOF_CARDRESET Date: Thu, 13 Jul 2023 17:51:25 +0800 Message-Id: <20230713095127.1230109-2-huaqian.li@siemens.com> In-Reply-To: <20230713095127.1230109-1-huaqian.li@siemens.com> References: <20230713095127.1230109-1-huaqian.li@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-959203:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org From: Li Hua Qian TI RTI (Real Time Interrupt) Watchdog doesn't support to record the watchdog cause. Add a reserved memory to know the last reboot was caused by the watchdog card. In the reserved memory, some specific info will be saved to indicate whether the watchdog reset was triggered in last boot. Signed-off-by: Li Hua Qian --- .../devicetree/bindings/watchdog/ti,rti-wdt.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml b/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml index fc553211e42d..8c16fd3929ec 100644 --- a/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml +++ b/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml @@ -34,6 +34,18 @@ properties: power-domains: maxItems: 1 + memory-region: + maxItems: 1 + description: + Contains the watchdog reserved memory. It is optional. + In the reserved memory, the specified values, which are + PON_REASON_SOF_NUM(0xBBBBCCCC), PON_REASON_MAGIC_NUM(0xDDDDDDDD), + and PON_REASON_EOF_NUM(0xCCCCBBBB), are pre-stored at the first + 3 * 4 bytes to tell that last boot was caused by watchdog reset. + Once the PON reason is captured by driver(rti_wdt.c), the driver + is supposed to wipe the whole memory region. + + required: - compatible - reg From patchwork Thu Jul 13 09:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Hua Qian" X-Patchwork-Id: 702698 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 D5BFCC0015E for ; Thu, 13 Jul 2023 09:52:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234246AbjGMJwN (ORCPT ); Thu, 13 Jul 2023 05:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234336AbjGMJwH (ORCPT ); Thu, 13 Jul 2023 05:52:07 -0400 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E2632706 for ; Thu, 13 Jul 2023 02:52:01 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 20230713095159ae5bedb15f29cf8f94 for ; Thu, 13 Jul 2023 11:51:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=huaqian.li@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=jnvC6oqf7550vuX04Y+Pl19iCeyz3P0LnhYgz2I4V6w=; b=TWJRBH5iVvX4tC5XX1wgojIwaxZpSZSm67w/tCsfb6hvUKfnPg7cyvVHpDtwF2SGObMNHf 4y1FmtgAs4A4uX5e0i6DkY/l3KniLYZX/SulWyl+Etyt+hEC/LBAZnT5at+FZ32h0yRL3qyi +Zcu7Xc0DMy95PKDAkB0vlyRQVe94=; From: huaqian.li@siemens.com To: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: huaqianlee@gmail.com, nm@ti.com, vigneshr@ti.com, kristo@kernel.org, linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jan.kiszka@siemens.com, baocheng.su@siemens.com, Li Hua Qian Subject: [PATCH v3 2/3] arm64: dts: ti: Add reserved memory for watchdog Date: Thu, 13 Jul 2023 17:51:26 +0800 Message-Id: <20230713095127.1230109-3-huaqian.li@siemens.com> In-Reply-To: <20230713095127.1230109-1-huaqian.li@siemens.com> References: <20230713095127.1230109-1-huaqian.li@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-959203:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org From: Li Hua Qian This patch adds a reserved memory for the TI AM65X platform watchdog to reserve the specific info, triggering the watchdog reset in last boot, to know if the board reboot is due to a watchdog reset. Signed-off-by: Li Hua Qian --- arch/arm64/boot/dts/ti/k3-am65-iot2050-common.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/arm64/boot/dts/ti/k3-am65-iot2050-common.dtsi b/arch/arm64/boot/dts/ti/k3-am65-iot2050-common.dtsi index e26bd988e522..4bb20d493651 100644 --- a/arch/arm64/boot/dts/ti/k3-am65-iot2050-common.dtsi +++ b/arch/arm64/boot/dts/ti/k3-am65-iot2050-common.dtsi @@ -63,6 +63,12 @@ rtos_ipc_memory_region: ipc-memories@a2000000 { alignment = <0x1000>; no-map; }; + + /* To reserve the power-on(PON) reason for watchdog reset */ + wdt_reset_memory_region: wdt-memory@a2200000 { + reg = <0x00 0xa2200000 0x00 0x1000>; + no-map; + }; }; leds { @@ -718,3 +724,7 @@ &mcu_r5fss0_core1 { <&mcu_r5fss0_core1_memory_region>; mboxes = <&mailbox0_cluster1>, <&mbox_mcu_r5fss0_core1>; }; + +&mcu_rti1 { + memory-region = <&wdt_reset_memory_region>; +}; From patchwork Thu Jul 13 09:51:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Hua Qian" X-Patchwork-Id: 703537 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 2CFB7EB64DD for ; Thu, 13 Jul 2023 09:52:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234405AbjGMJwR (ORCPT ); Thu, 13 Jul 2023 05:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232195AbjGMJwK (ORCPT ); Thu, 13 Jul 2023 05:52:10 -0400 Received: from mta-64-226.siemens.flowmailer.net (mta-64-226.siemens.flowmailer.net [185.136.64.226]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B7BD2691 for ; Thu, 13 Jul 2023 02:52:05 -0700 (PDT) Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 20230713095204b4bbbcf3a55b02a6cb for ; Thu, 13 Jul 2023 11:52:05 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=huaqian.li@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=F9BzZKCWKnjicxXTDGFSKA38YJKol5g9fotOvc0nOpA=; b=AWRaobJSk0xCUdX00rLqIx9GNr2DyNsgU3FhIyW9kihWLDFwqcoQh1oWXePzXHuJZQWHBD S3ExjIP9KrX+jCou/BLIV5YPo8t51DpCeNqVLrA4Ib267GE/zqFdb9w7s0ccKZZO4ODtASxD oBRzlySY1+5onyzwXpNx9UMPWU/fo=; From: huaqian.li@siemens.com To: wim@linux-watchdog.org, linux@roeck-us.net, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org Cc: huaqianlee@gmail.com, nm@ti.com, vigneshr@ti.com, kristo@kernel.org, linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, jan.kiszka@siemens.com, baocheng.su@siemens.com, Li Hua Qian Subject: [PATCH v3 3/3] watchdog:rit_wdt: Add support for WDIOF_CARDRESET Date: Thu, 13 Jul 2023 17:51:27 +0800 Message-Id: <20230713095127.1230109-4-huaqian.li@siemens.com> In-Reply-To: <20230713095127.1230109-1-huaqian.li@siemens.com> References: <20230713095127.1230109-1-huaqian.li@siemens.com> MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-959203:519-21489:flowmailer Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org From: Li Hua Qian This patch adds the WDIOF_CARDRESET support for the platform watchdog whose hardware does not support this feature, to know if the board reboot is due to a watchdog reset. This is done via reserved memory(RAM), which indicates if specific info saved, triggering the watchdog reset in last boot. Signed-off-by: Li Hua Qian --- drivers/watchdog/rti_wdt.c | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c index ce8f18e93aa9..b9435b972cb9 100644 --- a/drivers/watchdog/rti_wdt.c +++ b/drivers/watchdog/rti_wdt.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #define DEFAULT_HEARTBEAT 60 @@ -52,6 +54,11 @@ #define DWDST BIT(1) +#define PON_REASON_SOF_NUM 0xBBBBCCCC +#define PON_REASON_MAGIC_NUM 0xDDDDDDDD +#define PON_REASON_EOF_NUM 0xCCCCBBBB +#define RESERVED_MEM_MIN_SIZE 12 + static int heartbeat = DEFAULT_HEARTBEAT; /* @@ -198,6 +205,11 @@ static int rti_wdt_probe(struct platform_device *pdev) struct rti_wdt_device *wdt; struct clk *clk; u32 last_ping = 0; + struct device_node *node; + u32 reserved_mem_size; + struct resource res; + u32 *vaddr; + u64 paddr; wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); if (!wdt) @@ -284,6 +296,45 @@ static int rti_wdt_probe(struct platform_device *pdev) } } + node = of_parse_phandle(pdev->dev.of_node, "memory-region", 0); + if (!node) { + dev_dbg(dev, "No memory-region specified.\n"); + } else { + ret = of_address_to_resource(node, 0, &res); + if (ret) { + dev_err(dev, "No memory address assigned to the region.\n"); + goto err_iomap; + } + + /* + * If reserved memory is defined for watchdog reset cause. + * Readout the Power-on(PON) reason and pass to bootstatus. + */ + paddr = res.start; + reserved_mem_size = res.end - (res.start - 1); + if (reserved_mem_size < RESERVED_MEM_MIN_SIZE) { + dev_err(dev, "The size of reserved memory is too small.\n"); + ret = -EINVAL; + goto err_iomap; + } + + vaddr = memremap(paddr, reserved_mem_size, MEMREMAP_WB); + if (vaddr == NULL) { + dev_err(dev, "Failed to map memory-region.\n"); + ret = -ENOMEM; + goto err_iomap; + } + + if (vaddr[0] == PON_REASON_SOF_NUM && + vaddr[1] == PON_REASON_MAGIC_NUM && + vaddr[2] == PON_REASON_EOF_NUM) { + dev_dbg(dev, "Watchdog reset cause detected.\n"); + wdd->bootstatus |= WDIOF_CARDRESET; + } + memset(vaddr, 0, reserved_mem_size); + memunmap(vaddr); + } + watchdog_init_timeout(wdd, heartbeat, dev); ret = watchdog_register_device(wdd);