1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
7 #define LOG_CATEGORY UCLASS_SYSRESET
18 #include <dm/device-internal.h>
21 #include <linux/delay.h>
22 #include <linux/err.h>
24 int sysreset_request(struct udevice *dev, enum sysreset_t type)
26 struct sysreset_ops *ops = sysreset_get_ops(dev);
31 return ops->request(dev, type);
34 int sysreset_get_status(struct udevice *dev, char *buf, int size)
36 struct sysreset_ops *ops = sysreset_get_ops(dev);
41 return ops->get_status(dev, buf, size);
44 int sysreset_get_last(struct udevice *dev)
46 struct sysreset_ops *ops = sysreset_get_ops(dev);
51 return ops->get_last(dev);
54 int sysreset_walk(enum sysreset_t type)
59 while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
60 for (uclass_first_device(UCLASS_SYSRESET, &dev);
62 uclass_next_device(&dev)) {
63 ret = sysreset_request(dev, type);
64 if (ret == -EINPROGRESS)
73 int sysreset_get_last_walk(void)
78 for (uclass_first_device(UCLASS_SYSRESET, &dev);
80 uclass_next_device(&dev)) {
83 ret = sysreset_get_last(dev);
93 void sysreset_walk_halt(enum sysreset_t type)
97 ret = sysreset_walk(type);
99 /* Wait for the reset to take effect */
100 if (ret == -EINPROGRESS)
103 /* Still no reset? Give up */
104 log_err("System reset not supported on this platform\n");
109 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
111 void reset_cpu(ulong addr)
113 sysreset_walk_halt(SYSRESET_WARM);
117 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
119 printf("resetting ...\n");
121 sysreset_walk_halt(SYSRESET_COLD);
126 #if IS_ENABLED(CONFIG_SYSRESET_CMD_POWEROFF)
127 int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
131 puts("poweroff ...\n");
134 ret = sysreset_walk(SYSRESET_POWER_OFF);
136 if (ret == -EINPROGRESS)
139 /*NOTREACHED when power off*/
140 return CMD_RET_FAILURE;
144 static int sysreset_post_bind(struct udevice *dev)
146 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
147 struct sysreset_ops *ops = sysreset_get_ops(dev);
148 static int reloc_done;
152 ops->request += gd->reloc_off;
159 UCLASS_DRIVER(sysreset) = {
160 .id = UCLASS_SYSRESET,
162 .post_bind = sysreset_post_bind,