Add support for the subcommand wdt gettimeout in the U-Boot shell.

The command queries the selected watchdog device and reports its
timeout when the driver implements get_timeout operation. This
exposes the timeout printing added to the watchdog uclass to
the shell interface.

Signed-off-by: Juuso Rinta <[email protected]>
---
 cmd/wdt.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/cmd/wdt.c b/cmd/wdt.c
index c7a06cca181..3e2ca069fe9 100644
--- a/cmd/wdt.c
+++ b/cmd/wdt.c
@@ -131,6 +131,30 @@ static int do_wdt_reset(struct cmd_tbl *cmdtp, int flag, 
int argc,
        return CMD_RET_SUCCESS;
 }
 
+static int do_wdt_gettimeout(struct cmd_tbl *cmdtp, int flag, int argc,
+                            char *const argv[])
+{
+       int ret;
+       u64 timeout_ms = 0;
+
+       ret = check_currdev();
+       if (ret)
+               return ret;
+
+       ret = wdt_get_timeout(currdev, &timeout_ms);
+       if (ret == -ENOSYS) {
+               printf("Getting watchdog timeout not supported.\n");
+               return CMD_RET_FAILURE;
+       } else if (ret) {
+               printf("Getting watchdog timeout failed (%d)\n", ret);
+               return CMD_RET_FAILURE;
+       }
+
+       printf("Timeout: %llums\n", timeout_ms);
+
+       return CMD_RET_SUCCESS;
+}
+
 static int do_wdt_expire(struct cmd_tbl *cmdtp, int flag, int argc,
                         char *const argv[])
 {
@@ -162,6 +186,7 @@ U_BOOT_LONGHELP(wdt,
        "wdt start <timeout ms> [flags] - start watchdog timer\n"
        "wdt stop - stop watchdog timer\n"
        "wdt reset - reset watchdog timer\n"
+       "wdt gettimeout - get device timeout in ms\n"
        "wdt expire [flags] - expire watchdog timer immediately\n");
 
 U_BOOT_CMD_WITH_SUBCMDS(wdt, "Watchdog sub-system", wdt_help_text,
@@ -170,4 +195,5 @@ U_BOOT_CMD_WITH_SUBCMDS(wdt, "Watchdog sub-system", 
wdt_help_text,
        U_BOOT_SUBCMD_MKENT(start, 3, 1, do_wdt_start),
        U_BOOT_SUBCMD_MKENT(stop, 1, 1, do_wdt_stop),
        U_BOOT_SUBCMD_MKENT(reset, 1, 1, do_wdt_reset),
+       U_BOOT_SUBCMD_MKENT(gettimeout, 1, 1, do_wdt_gettimeout),
        U_BOOT_SUBCMD_MKENT(expire, 2, 1, do_wdt_expire));

-- 
2.39.2

Reply via email to