1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
7 #define LOG_CATEGORY UCLASS_SYSRESET
17 #include <dm/device-internal.h>
20 #include <linux/err.h>
22 int sysreset_request(struct udevice *dev, enum sysreset_t type)
24 struct sysreset_ops *ops = sysreset_get_ops(dev);
29 return ops->request(dev, type);
32 int sysreset_get_status(struct udevice *dev, char *buf, int size)
34 struct sysreset_ops *ops = sysreset_get_ops(dev);
39 return ops->get_status(dev, buf, size);
42 int sysreset_get_last(struct udevice *dev)
44 struct sysreset_ops *ops = sysreset_get_ops(dev);
49 return ops->get_last(dev);
52 int sysreset_walk(enum sysreset_t type)
57 while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
58 for (uclass_first_device(UCLASS_SYSRESET, &dev);
60 uclass_next_device(&dev)) {
61 ret = sysreset_request(dev, type);
62 if (ret == -EINPROGRESS)
71 int sysreset_get_last_walk(void)
76 for (uclass_first_device(UCLASS_SYSRESET, &dev);
78 uclass_next_device(&dev)) {
81 ret = sysreset_get_last(dev);
91 void sysreset_walk_halt(enum sysreset_t type)
95 ret = sysreset_walk(type);
97 /* Wait for the reset to take effect */
98 if (ret == -EINPROGRESS)
101 /* Still no reset? Give up */
102 log_err("System reset not supported on this platform\n");
107 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
109 void reset_cpu(ulong addr)
111 sysreset_walk_halt(SYSRESET_WARM);
115 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
117 printf("resetting ...\n");
119 sysreset_walk_halt(SYSRESET_COLD);
124 #if IS_ENABLED(CONFIG_SYSRESET_CMD_POWEROFF)
125 int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
129 puts("poweroff ...\n");
132 ret = sysreset_walk(SYSRESET_POWER_OFF);
134 if (ret == -EINPROGRESS)
137 /*NOTREACHED when power off*/
138 return CMD_RET_FAILURE;
142 static int sysreset_post_bind(struct udevice *dev)
144 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
145 struct sysreset_ops *ops = sysreset_get_ops(dev);
146 static int reloc_done;
150 ops->request += gd->reloc_off;
157 UCLASS_DRIVER(sysreset) = {
158 .id = UCLASS_SYSRESET,
160 .post_bind = sysreset_post_bind,