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
16 #include <dm/device-internal.h>
19 #include <linux/err.h>
21 int sysreset_request(struct udevice *dev, enum sysreset_t type)
23 struct sysreset_ops *ops = sysreset_get_ops(dev);
28 return ops->request(dev, type);
31 int sysreset_get_status(struct udevice *dev, char *buf, int size)
33 struct sysreset_ops *ops = sysreset_get_ops(dev);
38 return ops->get_status(dev, buf, size);
41 int sysreset_get_last(struct udevice *dev)
43 struct sysreset_ops *ops = sysreset_get_ops(dev);
48 return ops->get_last(dev);
51 int sysreset_walk(enum sysreset_t type)
56 while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
57 for (uclass_first_device(UCLASS_SYSRESET, &dev);
59 uclass_next_device(&dev)) {
60 ret = sysreset_request(dev, type);
61 if (ret == -EINPROGRESS)
70 int sysreset_get_last_walk(void)
75 for (uclass_first_device(UCLASS_SYSRESET, &dev);
77 uclass_next_device(&dev)) {
80 ret = sysreset_get_last(dev);
90 void sysreset_walk_halt(enum sysreset_t type)
94 ret = sysreset_walk(type);
96 /* Wait for the reset to take effect */
97 if (ret == -EINPROGRESS)
100 /* Still no reset? Give up */
101 log_err("System reset not supported on this platform\n");
106 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
108 void reset_cpu(ulong addr)
110 sysreset_walk_halt(SYSRESET_WARM);
114 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
116 printf("resetting ...\n");
118 sysreset_walk_halt(SYSRESET_COLD);
123 #if IS_ENABLED(CONFIG_SYSRESET_CMD_POWEROFF)
124 int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
128 puts("poweroff ...\n");
131 ret = sysreset_walk(SYSRESET_POWER_OFF);
133 if (ret == -EINPROGRESS)
136 /*NOTREACHED when power off*/
137 return CMD_RET_FAILURE;
141 static int sysreset_post_bind(struct udevice *dev)
143 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
144 struct sysreset_ops *ops = sysreset_get_ops(dev);
145 static int reloc_done;
149 ops->request += gd->reloc_off;
156 UCLASS_DRIVER(sysreset) = {
157 .id = UCLASS_SYSRESET,
159 .post_bind = sysreset_post_bind,