2023-07-17 06:58:54

by Li, Hua Qian

[permalink] [raw]
Subject: [PATCH v5 0/3] Add support for WDIOF_CARDRESET on TI AM65x

From: Li Hua Qian <[email protected]>

The watchdog hardware of TI AM65X platform does not support
WDIOF_CARDRESET feature, add a reserved memory to save the watchdog
reset cause, to know if the board reboot is due to a watchdog reset.

Signed-off-by: Li Hua Qian <[email protected]>
---
Changes in v5:
- Corret the `Reviewed-by` info.
- Link to v4:
https://lore.kernel.org/linux-watchdog/[email protected]

Changes in v4:
- Fix the coding style.
- Add usage note for the reserved memory.
- Link to v3:
https://lore.kernel.org/linux-watchdog/[email protected]

Changes in v3:
- Add memory-region back for the reserved memory, and remove reserved
memory from the watchdog IO address space.
- Add changelog.
- Link to v2:
https://lore.kernel.org/linux-watchdog/[email protected]

Changes in v2:
- Remove memory-region and memory-size properties, and bind the reserved
memory to watchdog IO address space.
- Remove the unnecessary rti_wdt_ioctl.
- Fix the mail list
- Link to v1:
https://lore.kernel.org/all/[email protected]
v1 had a wrong mail list at the beginning, and the mail thread was
messed up.

Li Hua Qian (3):
dt-bindings: watchdog: ti,rti-wdt: Add support for WDIOF_CARDRESET
arm64: dts: ti: Add reserved memory for watchdog
watchdog:rit_wdt: Add support for WDIOF_CARDRESET

.../bindings/watchdog/ti,rti-wdt.yaml | 41 ++++++++++++++++
.../boot/dts/ti/k3-am65-iot2050-common.dtsi | 10 ++++
drivers/watchdog/rti_wdt.c | 48 +++++++++++++++++++
3 files changed, 99 insertions(+)

--
2.34.1



2023-07-17 06:58:54

by Li, Hua Qian

[permalink] [raw]
Subject: [PATCH v5 3/3] watchdog:rit_wdt: Add support for WDIOF_CARDRESET

From: Li Hua Qian <[email protected]>

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 <[email protected]>
---
drivers/watchdog/rti_wdt.c | 48 ++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)

diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
index ce8f18e93aa9..901109d979f0 100644
--- a/drivers/watchdog/rti_wdt.c
+++ b/drivers/watchdog/rti_wdt.c
@@ -14,6 +14,8 @@
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/types.h>
@@ -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,42 @@ static int rti_wdt_probe(struct platform_device *pdev)
}
}

+ node = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
+ if (node) {
+ 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 = resource_size(&res);
+ 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) {
+ wdd->bootstatus |= WDIOF_CARDRESET;
+ }
+ memset(vaddr, 0, reserved_mem_size);
+ memunmap(vaddr);
+ }
+
watchdog_init_timeout(wdd, heartbeat, dev);

ret = watchdog_register_device(wdd);
--
2.34.1


2023-07-17 07:01:32

by Li, Hua Qian

[permalink] [raw]
Subject: [DONOTMERGE PATCH v5 2/3] arm64: dts: ti: Add reserved memory for watchdog

From: Li Hua Qian <[email protected]>

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 <[email protected]>
---
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>;
+};
--
2.34.1


2023-07-17 07:21:06

by Li, Hua Qian

[permalink] [raw]
Subject: [PATCH v5 1/3] dt-bindings: watchdog: ti,rti-wdt: Add support for WDIOF_CARDRESET

From: Li Hua Qian <[email protected]>

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.

Reviewed-by: Guenter Roeck <[email protected]>
Signed-off-by: Li Hua Qian <[email protected]>
---
.../bindings/watchdog/ti,rti-wdt.yaml | 41 +++++++++++++++++++
1 file changed, 41 insertions(+)

diff --git a/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml b/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml
index fc553211e42d..4b66c4fcdf35 100644
--- a/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml
+++ b/Documentation/devicetree/bindings/watchdog/ti,rti-wdt.yaml
@@ -34,6 +34,20 @@ 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. Surely, if this
+ property is set, at least 12 bytes reserved memory starting from
+ specific memory address(0xa220000) should be set. More please
+ refer to Example 2.
+
required:
- compatible
- reg
@@ -59,3 +73,30 @@ examples:
assigned-clocks = <&k3_clks 252 1>;
assigned-clock-parents = <&k3_clks 252 5>;
};
+
+ - |
+ // Example 2 (Add reserved memory for watchdog reset cause):
+ /*
+ * RTI WDT in main domain on J721e SoC. Assigned clocks are used to
+ * select the source clock for the watchdog, forcing it to tick with
+ * a 32kHz clock in this case. Add a reserved memory to keep the
+ * watchdog reset cause persistent, which was be written in 12 bytes
+ * starting from 0xa2200000 by RTI Watchdog Firmware.
+ *
+ * Reserved memory should be defined as follows:
+ * reserved-memory {
+ * wdt_reset_memory_region: wdt-memory@a2200000 {
+ * reg = <0x00 0xa2200000 0x00 0x1000>;
+ * no-map;
+ * };
+ * }
+ */
+ watchdog@40610000 {
+ compatible = "ti,j7-rti-wdt";
+ reg = <0x40610000 0x100>;
+ clocks = <&k3_clks 135 1>;
+ power-domains = <&k3_pds 135 TI_SCI_PD_EXCLUSIVE>;
+ assigned-clocks = <&k3_clks 135 0>;
+ assigned-clock-parents = <&k3_clks 135 4>;
+ memory-region = <&wdt_reset_memory_region>;
+ };
--
2.34.1


2023-07-17 13:46:56

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v5 1/3] dt-bindings: watchdog: ti,rti-wdt: Add support for WDIOF_CARDRESET

On 7/16/23 23:41, [email protected] wrote:
> From: Li Hua Qian <[email protected]>
>
> 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.
>
> Reviewed-by: Guenter Roeck <[email protected]>

Drop that. I did not realize you cheated, and I was just trying
to match the other (apparently fake) Reviewed-by: tags.

Guenter