blob: 7e06c3c90a7124e362f1daaa4e08fc3db895b709 [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
77UCLASS_DRIVER(sysreset) = {
78 .id = UCLASS_SYSRESET,
79 .name = "sysreset",
80};