1 /*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8 #ifndef __SYSRESET_H
9 #define __SYSRESET_H
10
11 enum sysreset_t {
12 SYSRESET_WARM, /* Reset CPU, keep GPIOs active */
13 SYSRESET_COLD, /* Reset CPU and GPIOs */
14 SYSRESET_POWER, /* Reset PMIC (remove and restore power) */
15
16 SYSRESET_COUNT,
17 };
18
19 struct sysreset_ops {
20 /**
21 * request() - request a sysreset of the given type
22 *
23 * Note that this function may return before the reset takes effect.
24 *
25 * @type: Reset type to request
26 * @return -EINPROGRESS if the reset has been started and
27 * will complete soon, -EPROTONOSUPPORT if not supported
28 * by this device, 0 if the reset has already happened
29 * (in which case this method will not actually return)
30 */
31 int (*request)(struct udevice *dev, enum sysreset_t type);
32
33 /**
34 * request_by_mode() - request a sysreset of the given mode
35 *
36 * Note that this function may return before the reset takes effect.
37 *
38 * @mode: mode to request
39 * @return -EINPROGRESS if the reset has been started and
40 * will complete soon, -EPROTONOSUPPORT if not supported
41 * by this device, 0 if the reset has already happened
42 * (in which case this method will not actually return)
43 */
44 int (*request_by_mode)(struct udevice *dev, const char *mode);
45 };
46
47 #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops)
48
49 #ifdef CONFIG_SYSRESET
50 /**
51 * sysreset_request() - request a sysreset
52 *
53 * @type: Reset type to request
54 * @return 0 if OK, -EPROTONOSUPPORT if not supported by this device
55 */
56 int sysreset_request(struct udevice *dev, enum sysreset_t type);
57
58 /**
59 * sysreset_walk() - cause a system reset
60 *
61 * This works through the available sysreset devices until it finds one that can
62 * perform a reset. If the provided sysreset type is not available, the next one
63 * will be tried.
64 *
65 * If this function fails to reset, it will display a message and halt
66 *
67 * @type: Reset type to request
68 * @return -EINPROGRESS if a reset is in progress, -ENOSYS if not available
69 */
70 int sysreset_walk(enum sysreset_t type);
71
72 /**
73 * sysreset_walk_halt() - try to reset, otherwise halt
74 *
75 * This calls sysreset_walk(). If it returns, indicating that reset is not
76 * supported, it prints a message and halts.
77 */
78 void sysreset_walk_halt(enum sysreset_t type);
79
80 /**
81 * reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
82 */
83 void reset_cpu(ulong addr);
84
85 /**
86 * reboot() - calls sysreset_walk(SYSRESET_WARM)
87 *
88 * Support the command like: reboot loader/bootloader/recovery, etc.
89 */
90 void reboot(const char *mode);
91
92 #else
93 #include <asm/io.h>
94
reset_cpu(ulong addr)95 inline void reset_cpu(ulong addr)
96 {
97 writel(CONFIG_SYSRESET_VAL, CONFIG_SYSRESET_REG);
98 dsb();
99 isb();
100
101 while (1)
102 ;
103 }
104 #endif
105
106 #endif
107