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 static int sysreset_post_bind(struct udevice *dev)
123 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
124 struct sysreset_ops *ops = sysreset_get_ops(dev);
125 static int reloc_done;
129 ops->request += gd->reloc_off;
136 UCLASS_DRIVER(sysreset) = {
137 .id = UCLASS_SYSRESET,
139 .post_bind = sysreset_post_bind,