1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2019 Michael Walle <michael@walle.cc>
12 static struct udevice
*currdev
;
14 static int do_wdt_list(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
21 ret
= uclass_get(UCLASS_WDT
, &uc
);
23 return CMD_RET_FAILURE
;
25 uclass_foreach_dev(dev
, uc
)
26 printf("%s (%s)\n", dev
->name
, dev
->driver
->name
);
28 return CMD_RET_SUCCESS
;
31 static int do_wdt_dev(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
37 ret
= uclass_get_device_by_name(UCLASS_WDT
, argv
[1], &currdev
);
39 printf("Can't get the watchdog timer: %s\n", argv
[1]);
40 return CMD_RET_FAILURE
;
44 printf("No watchdog timer device set!\n");
45 return CMD_RET_FAILURE
;
47 printf("dev: %s\n", currdev
->name
);
50 return CMD_RET_SUCCESS
;
53 static int check_currdev(void)
56 printf("No device set, use 'wdt dev' first\n");
57 return CMD_RET_FAILURE
;
62 static int do_wdt_start(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
72 ret
= check_currdev();
76 timeout
= simple_strtoull(argv
[1], NULL
, 0);
78 flags
= simple_strtoul(argv
[2], NULL
, 0);
80 ret
= wdt_start(currdev
, timeout
, flags
);
82 printf("Starting watchdog timer not supported.\n");
83 return CMD_RET_FAILURE
;
85 printf("Starting watchdog timer failed (%d)\n", ret
);
86 return CMD_RET_FAILURE
;
89 return CMD_RET_SUCCESS
;
92 static int do_wdt_stop(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
97 ret
= check_currdev();
101 ret
= wdt_stop(currdev
);
102 if (ret
== -ENOSYS
) {
103 printf("Stopping watchdog timer not supported.\n");
104 return CMD_RET_FAILURE
;
106 printf("Stopping watchdog timer failed (%d)\n", ret
);
107 return CMD_RET_FAILURE
;
110 return CMD_RET_SUCCESS
;
113 static int do_wdt_reset(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
118 ret
= check_currdev();
122 ret
= wdt_reset(currdev
);
123 if (ret
== -ENOSYS
) {
124 printf("Resetting watchdog timer not supported.\n");
125 return CMD_RET_FAILURE
;
127 printf("Resetting watchdog timer failed (%d)\n", ret
);
128 return CMD_RET_FAILURE
;
131 return CMD_RET_SUCCESS
;
134 static int do_wdt_expire(struct cmd_tbl
*cmdtp
, int flag
, int argc
,
140 ret
= check_currdev();
145 flags
= simple_strtoul(argv
[1], NULL
, 0);
147 ret
= wdt_expire_now(currdev
, flags
);
148 if (ret
== -ENOSYS
) {
149 printf("Expiring watchdog timer not supported.\n");
150 return CMD_RET_FAILURE
;
152 printf("Expiring watchdog timer failed (%d)\n", ret
);
153 return CMD_RET_FAILURE
;
156 return CMD_RET_SUCCESS
;
160 "list - list watchdog devices\n"
161 "wdt dev [<name>] - get/set current watchdog device\n"
162 "wdt start <timeout ms> [flags] - start watchdog timer\n"
163 "wdt stop - stop watchdog timer\n"
164 "wdt reset - reset watchdog timer\n"
165 "wdt expire [flags] - expire watchdog timer immediately\n");
167 U_BOOT_CMD_WITH_SUBCMDS(wdt
, "Watchdog sub-system", wdt_help_text
,
168 U_BOOT_SUBCMD_MKENT(list
, 1, 1, do_wdt_list
),
169 U_BOOT_SUBCMD_MKENT(dev
, 2, 1, do_wdt_dev
),
170 U_BOOT_SUBCMD_MKENT(start
, 3, 1, do_wdt_start
),
171 U_BOOT_SUBCMD_MKENT(stop
, 1, 1, do_wdt_stop
),
172 U_BOOT_SUBCMD_MKENT(reset
, 1, 1, do_wdt_reset
),
173 U_BOOT_SUBCMD_MKENT(expire
, 2, 1, do_wdt_expire
));