blob: 840eab6b57035baa3e1b8ae9276cdb411a4d16dc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stephen Warren859f2562016-05-12 12:03:35 -06002/*
3 * Copyright (C) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Stephen Warren859f2562016-05-12 12:03:35 -06005 */
6
7#include <common.h>
8#include <sysreset.h>
9#include <dm.h>
10#include <errno.h>
11#include <regmap.h>
12#include <dm/device-internal.h>
13#include <dm/lists.h>
14#include <dm/root.h>
15#include <linux/err.h>
16
17int sysreset_request(struct udevice *dev, enum sysreset_t type)
18{
19 struct sysreset_ops *ops = sysreset_get_ops(dev);
20
21 if (!ops->request)
22 return -ENOSYS;
23
24 return ops->request(dev, type);
25}
26
27int sysreset_walk(enum sysreset_t type)
28{
29 struct udevice *dev;
30 int ret = -ENOSYS;
31
32 while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
33 for (uclass_first_device(UCLASS_SYSRESET, &dev);
34 dev;
35 uclass_next_device(&dev)) {
36 ret = sysreset_request(dev, type);
37 if (ret == -EINPROGRESS)
38 break;
39 }
40 type++;
41 }
42
43 return ret;
44}
45
46void sysreset_walk_halt(enum sysreset_t type)
47{
48 int ret;
49
50 ret = sysreset_walk(type);
51
52 /* Wait for the reset to take effect */
53 if (ret == -EINPROGRESS)
54 mdelay(100);
55
56 /* Still no reset? Give up */
Simon Glassa8c5ac02016-05-14 14:02:54 -060057 debug("System reset not supported on this platform\n");
Stephen Warren859f2562016-05-12 12:03:35 -060058 hang();
59}
60
61/**
62 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
63 */
64void reset_cpu(ulong addr)
65{
66 sysreset_walk_halt(SYSRESET_WARM);
67}
68
69
70int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
71{
Philipp Tomsich8caba822017-11-24 18:37:58 +010072 sysreset_walk_halt(SYSRESET_COLD);
Stephen Warren859f2562016-05-12 12:03:35 -060073
74 return 0;
75}
76
Michal Simek28d3deb2018-07-12 10:36:07 +020077static int sysreset_post_bind(struct udevice *dev)
78{
79#if defined(CONFIG_NEEDS_MANUAL_RELOC)
80 struct sysreset_ops *ops = sysreset_get_ops(dev);
81 static int reloc_done;
82
83 if (!reloc_done) {
84 if (ops->request)
85 ops->request += gd->reloc_off;
86 reloc_done++;
87 }
88#endif
89 return 0;
90}
91
Stephen Warren859f2562016-05-12 12:03:35 -060092UCLASS_DRIVER(sysreset) = {
93 .id = UCLASS_SYSRESET,
94 .name = "sysreset",
Michal Simek28d3deb2018-07-12 10:36:07 +020095 .post_bind = sysreset_post_bind,
Stephen Warren859f2562016-05-12 12:03:35 -060096};