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
14 #include <dm/device-internal.h>
17 #include <linux/err.h>
19 int sysreset_request(struct udevice *dev, enum sysreset_t type)
21 struct sysreset_ops *ops = sysreset_get_ops(dev);
26 return ops->request(dev, type);
29 int sysreset_get_status(struct udevice *dev, char *buf, int size)
31 struct sysreset_ops *ops = sysreset_get_ops(dev);
36 return ops->get_status(dev, buf, size);
39 int sysreset_get_last(struct udevice *dev)
41 struct sysreset_ops *ops = sysreset_get_ops(dev);
46 return ops->get_last(dev);
49 int sysreset_walk(enum sysreset_t type)
54 while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
55 for (uclass_first_device(UCLASS_SYSRESET, &dev);
57 uclass_next_device(&dev)) {
58 ret = sysreset_request(dev, type);
59 if (ret == -EINPROGRESS)
68 int sysreset_get_last_walk(void)
73 for (uclass_first_device(UCLASS_SYSRESET, &dev);
75 uclass_next_device(&dev)) {
78 ret = sysreset_get_last(dev);
88 void sysreset_walk_halt(enum sysreset_t type)
92 ret = sysreset_walk(type);
94 /* Wait for the reset to take effect */
95 if (ret == -EINPROGRESS)
98 /* Still no reset? Give up */
99 log_err("System reset not supported on this platform\n");
104 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
106 void reset_cpu(ulong addr)
108 sysreset_walk_halt(SYSRESET_WARM);
112 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
114 printf("resetting ...\n");
116 sysreset_walk_halt(SYSRESET_COLD);
121 #if IS_ENABLED(CONFIG_SYSRESET_CMD_POWEROFF)
122 int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
126 puts("poweroff ...\n");
129 ret = sysreset_walk(SYSRESET_POWER_OFF);
131 if (ret == -EINPROGRESS)
134 /*NOTREACHED when power off*/
135 return CMD_RET_FAILURE;
139 static int sysreset_post_bind(struct udevice *dev)
141 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
142 struct sysreset_ops *ops = sysreset_get_ops(dev);
143 static int reloc_done;
147 ops->request += gd->reloc_off;
154 UCLASS_DRIVER(sysreset) = {
155 .id = UCLASS_SYSRESET,
157 .post_bind = sysreset_post_bind,