Skip to content

Commit f20ca59

Browse files
huaqianliWim Van Sebroeck
authored andcommitted
watchdog:rit_wdt: Add support for WDIOF_CARDRESET
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]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] [groeck: vaddr == NULL --> !vaddr] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent 11efe9e commit f20ca59

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

drivers/watchdog/rti_wdt.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/mod_devicetable.h>
1515
#include <linux/module.h>
1616
#include <linux/moduleparam.h>
17+
#include <linux/of.h>
18+
#include <linux/of_address.h>
1719
#include <linux/platform_device.h>
1820
#include <linux/pm_runtime.h>
1921
#include <linux/types.h>
@@ -52,6 +54,11 @@
5254

5355
#define DWDST BIT(1)
5456

57+
#define PON_REASON_SOF_NUM 0xBBBBCCCC
58+
#define PON_REASON_MAGIC_NUM 0xDDDDDDDD
59+
#define PON_REASON_EOF_NUM 0xCCCCBBBB
60+
#define RESERVED_MEM_MIN_SIZE 12
61+
5562
static int heartbeat = DEFAULT_HEARTBEAT;
5663

5764
/*
@@ -198,6 +205,11 @@ static int rti_wdt_probe(struct platform_device *pdev)
198205
struct rti_wdt_device *wdt;
199206
struct clk *clk;
200207
u32 last_ping = 0;
208+
struct device_node *node;
209+
u32 reserved_mem_size;
210+
struct resource res;
211+
u32 *vaddr;
212+
u64 paddr;
201213

202214
wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
203215
if (!wdt)
@@ -284,6 +296,42 @@ static int rti_wdt_probe(struct platform_device *pdev)
284296
}
285297
}
286298

299+
node = of_parse_phandle(pdev->dev.of_node, "memory-region", 0);
300+
if (node) {
301+
ret = of_address_to_resource(node, 0, &res);
302+
if (ret) {
303+
dev_err(dev, "No memory address assigned to the region.\n");
304+
goto err_iomap;
305+
}
306+
307+
/*
308+
* If reserved memory is defined for watchdog reset cause.
309+
* Readout the Power-on(PON) reason and pass to bootstatus.
310+
*/
311+
paddr = res.start;
312+
reserved_mem_size = resource_size(&res);
313+
if (reserved_mem_size < RESERVED_MEM_MIN_SIZE) {
314+
dev_err(dev, "The size of reserved memory is too small.\n");
315+
ret = -EINVAL;
316+
goto err_iomap;
317+
}
318+
319+
vaddr = memremap(paddr, reserved_mem_size, MEMREMAP_WB);
320+
if (!vaddr) {
321+
dev_err(dev, "Failed to map memory-region.\n");
322+
ret = -ENOMEM;
323+
goto err_iomap;
324+
}
325+
326+
if (vaddr[0] == PON_REASON_SOF_NUM &&
327+
vaddr[1] == PON_REASON_MAGIC_NUM &&
328+
vaddr[2] == PON_REASON_EOF_NUM) {
329+
wdd->bootstatus |= WDIOF_CARDRESET;
330+
}
331+
memset(vaddr, 0, reserved_mem_size);
332+
memunmap(vaddr);
333+
}
334+
287335
watchdog_init_timeout(wdd, heartbeat, dev);
288336

289337
ret = watchdog_register_device(wdd);

0 commit comments

Comments
 (0)