1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
12 #include <dm/device-internal.h>
15 #include <linux/err.h>
17 int sysreset_request(struct udevice *dev, enum sysreset_t type)
19 struct sysreset_ops *ops = sysreset_get_ops(dev);
24 return ops->request(dev, type);
27 int sysreset_get_status(struct udevice *dev, char *buf, int size)
29 struct sysreset_ops *ops = sysreset_get_ops(dev);
34 return ops->get_status(dev, buf, size);
37 int sysreset_walk(enum sysreset_t type)
42 while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
43 for (uclass_first_device(UCLASS_SYSRESET, &dev);
45 uclass_next_device(&dev)) {
46 ret = sysreset_request(dev, type);
47 if (ret == -EINPROGRESS)
56 void sysreset_walk_halt(enum sysreset_t type)
60 ret = sysreset_walk(type);
62 /* Wait for the reset to take effect */
63 if (ret == -EINPROGRESS)
66 /* Still no reset? Give up */
67 debug("System reset not supported on this platform\n");
72 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
74 void reset_cpu(ulong addr)
76 sysreset_walk_halt(SYSRESET_WARM);
80 int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
82 printf("resetting ...\n");
84 sysreset_walk_halt(SYSRESET_COLD);
89 static int sysreset_post_bind(struct udevice *dev)
91 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
92 struct sysreset_ops *ops = sysreset_get_ops(dev);
93 static int reloc_done;
97 ops->request += gd->reloc_off;
104 UCLASS_DRIVER(sysreset) = {
105 .id = UCLASS_SYSRESET,
107 .post_bind = sysreset_post_bind,