]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - cmd/wdt.c
1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2019 Michael Walle <michael@walle.cc>
13 static struct udevice
*currdev
;
15 static int do_wdt_list(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
22 ret
= uclass_get(UCLASS_WDT
, &uc
);
24 return CMD_RET_FAILURE
;
26 uclass_foreach_dev(dev
, uc
)
27 printf("%s (%s)\n", dev
->name
, dev
->driver
->name
);
29 return CMD_RET_SUCCESS
;
32 static int do_wdt_dev(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
38 ret
= uclass_get_device_by_name(UCLASS_WDT
, argv
[1], &currdev
);
40 printf("Can't get the watchdog timer: %s\n", argv
[1]);
41 return CMD_RET_FAILURE
;
45 printf("No watchdog timer device set!\n");
46 return CMD_RET_FAILURE
;
48 printf("dev: %s\n", currdev
->name
);
51 return CMD_RET_SUCCESS
;
54 static int check_currdev(void)
57 printf("No device set, use 'wdt dev' first\n");
58 return CMD_RET_FAILURE
;
63 static int do_wdt_start(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
73 ret
= check_currdev();
77 timeout
= simple_strtoull(argv
[1], NULL
, 0);
79 flags
= simple_strtoul(argv
[2], NULL
, 0);
81 ret
= wdt_start(currdev
, timeout
, flags
);
83 printf("Starting watchdog timer not supported.\n");
84 return CMD_RET_FAILURE
;
86 printf("Starting watchdog timer failed (%d)\n", ret
);
87 return CMD_RET_FAILURE
;
90 return CMD_RET_SUCCESS
;
93 static int do_wdt_stop(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
98 ret
= check_currdev();
102 ret
= wdt_stop(currdev
);
103 if (ret
== -ENOSYS
) {
104 printf("Stopping watchdog timer not supported.\n");
105 return CMD_RET_FAILURE
;
107 printf("Stopping watchdog timer failed (%d)\n", ret
);
108 return CMD_RET_FAILURE
;
111 return CMD_RET_SUCCESS
;
114 static int do_wdt_reset(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
119 ret
= check_currdev();
123 ret
= wdt_reset(currdev
);
124 if (ret
== -ENOSYS
) {
125 printf("Resetting watchdog timer not supported.\n");
126 return CMD_RET_FAILURE
;
128 printf("Resetting watchdog timer failed (%d)\n", ret
);
129 return CMD_RET_FAILURE
;
132 return CMD_RET_SUCCESS
;
135 static int do_wdt_expire(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
141 ret
= check_currdev();
146 flags
= simple_strtoul(argv
[1], NULL
, 0);
148 ret
= wdt_expire_now(currdev
, flags
);
149 if (ret
== -ENOSYS
) {
150 printf("Expiring watchdog timer not supported.\n");
151 return CMD_RET_FAILURE
;
153 printf("Expiring watchdog timer failed (%d)\n", ret
);
154 return CMD_RET_FAILURE
;
157 return CMD_RET_SUCCESS
;
160 static char wdt_help_text
[] =
161 "list - list watchdog devices\n"
162 "wdt dev [<name>] - get/set current watchdog device\n"
163 "wdt start <timeout ms> [flags] - start watchdog timer\n"
164 "wdt stop - stop watchdog timer\n"
165 "wdt reset - reset watchdog timer\n"
166 "wdt expire [flags] - expire watchdog timer immediately\n";
168 U_BOOT_CMD_WITH_SUBCMDS(wdt
, "Watchdog sub-system", wdt_help_text
,
169 U_BOOT_SUBCMD_MKENT(list
, 1, 1, do_wdt_list
),
170 U_BOOT_SUBCMD_MKENT(dev
, 2, 1, do_wdt_dev
),
171 U_BOOT_SUBCMD_MKENT(start
, 3, 1, do_wdt_start
),
172 U_BOOT_SUBCMD_MKENT(stop
, 1, 1, do_wdt_stop
),
173 U_BOOT_SUBCMD_MKENT(reset
, 1, 1, do_wdt_reset
),
174 U_BOOT_SUBCMD_MKENT(expire
, 2, 1, do_wdt_expire
));