]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
11636258 SW |
2 | /* |
3 | * Copyright (c) 2015 Google, Inc | |
4 | * Written by Simon Glass <[email protected]> | |
11636258 SW |
5 | */ |
6 | ||
7 | #ifndef __SYSRESET_H | |
8 | #define __SYSRESET_H | |
9 | ||
401d1c4f SG |
10 | struct udevice; |
11 | ||
1da0b6ab HS |
12 | /** |
13 | * enum sysreset_t - system reset types | |
14 | */ | |
11636258 | 15 | enum sysreset_t { |
1da0b6ab HS |
16 | /** @SYSRESET_WARM: reset CPU, keep GPIOs active */ |
17 | SYSRESET_WARM, | |
18 | /** @SYSRESET_COLD: reset CPU and GPIOs */ | |
19 | SYSRESET_COLD, | |
20 | /** @SYSRESET_POWER: reset PMIC (remove and restore power) */ | |
21 | SYSRESET_POWER, | |
22 | /** @SYSRESET_POWER_OFF: turn off power */ | |
23 | SYSRESET_POWER_OFF, | |
24 | /** @SYSRESET_COUNT: number of available reset types */ | |
11636258 SW |
25 | SYSRESET_COUNT, |
26 | }; | |
27 | ||
1da0b6ab HS |
28 | /** |
29 | * struct sysreset_ops - operations of system reset drivers | |
30 | */ | |
11636258 SW |
31 | struct sysreset_ops { |
32 | /** | |
1da0b6ab | 33 | * @request: request a sysreset of the given type |
11636258 SW |
34 | * |
35 | * Note that this function may return before the reset takes effect. | |
36 | * | |
1da0b6ab | 37 | * @dev: Device to be used for system reset |
11636258 | 38 | * @type: Reset type to request |
1da0b6ab HS |
39 | * Return: |
40 | * -EINPROGRESS if the reset has been started and | |
41 | * will complete soon, -EPROTONOSUPPORT if not supported | |
42 | * by this device, 0 if the reset has already happened | |
43 | * (in which case this method will not actually return) | |
11636258 SW |
44 | */ |
45 | int (*request)(struct udevice *dev, enum sysreset_t type); | |
245f5cda | 46 | /** |
1da0b6ab | 47 | * @get_status: get printable reset status information |
245f5cda | 48 | * |
eb517315 | 49 | * @dev: Device to check |
245f5cda MS |
50 | * @buf: Buffer to receive the textual reset information |
51 | * @size: Size of the passed buffer | |
1da0b6ab | 52 | * Return: 0 if OK, -ve on error |
245f5cda MS |
53 | */ |
54 | int (*get_status)(struct udevice *dev, char *buf, int size); | |
751fed42 SG |
55 | |
56 | /** | |
1da0b6ab | 57 | * @get_last: get information on the last reset |
751fed42 SG |
58 | * |
59 | * @dev: Device to check | |
1da0b6ab | 60 | * Return: last reset state (enum :enum:`sysreset_t`) or -ve error |
751fed42 SG |
61 | */ |
62 | int (*get_last)(struct udevice *dev); | |
11636258 SW |
63 | }; |
64 | ||
65 | #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops) | |
66 | ||
67 | /** | |
68 | * sysreset_request() - request a sysreset | |
69 | * | |
1da0b6ab | 70 | * @dev: Device to be used for system reset |
11636258 | 71 | * @type: Reset type to request |
1da0b6ab | 72 | * Return: 0 if OK, -EPROTONOSUPPORT if not supported by this device |
11636258 SW |
73 | */ |
74 | int sysreset_request(struct udevice *dev, enum sysreset_t type); | |
75 | ||
245f5cda | 76 | /** |
eb517315 | 77 | * sysreset_get_status() - get printable reset status information |
245f5cda | 78 | * |
eb517315 | 79 | * @dev: Device to check |
245f5cda MS |
80 | * @buf: Buffer to receive the textual reset information |
81 | * @size: Size of the passed buffer | |
1da0b6ab | 82 | * Return: 0 if OK, -ve on error |
245f5cda MS |
83 | */ |
84 | int sysreset_get_status(struct udevice *dev, char *buf, int size); | |
85 | ||
751fed42 SG |
86 | /** |
87 | * sysreset_get_last() - get information on the last reset | |
88 | * | |
89 | * @dev: Device to check | |
1da0b6ab | 90 | * Return: last reset state (enum sysreset_t) or -ve error |
751fed42 SG |
91 | */ |
92 | int sysreset_get_last(struct udevice *dev); | |
93 | ||
11636258 SW |
94 | /** |
95 | * sysreset_walk() - cause a system reset | |
96 | * | |
97 | * This works through the available sysreset devices until it finds one that can | |
98 | * perform a reset. If the provided sysreset type is not available, the next one | |
99 | * will be tried. | |
100 | * | |
101 | * If this function fails to reset, it will display a message and halt | |
102 | * | |
103 | * @type: Reset type to request | |
1da0b6ab | 104 | * Return: -EINPROGRESS if a reset is in progress, -ENOSYS if not available |
11636258 SW |
105 | */ |
106 | int sysreset_walk(enum sysreset_t type); | |
107 | ||
751fed42 SG |
108 | /** |
109 | * sysreset_get_last_walk() - get information on the last reset | |
110 | * | |
111 | * This works through the available sysreset devices until it finds one that can | |
112 | * perform a reset. If the provided sysreset type is not available, the next one | |
113 | * will be tried. | |
114 | * | |
115 | * If no device prives the information, this function returns -ENOENT | |
116 | * | |
1da0b6ab | 117 | * Return: last reset state (enum sysreset_t) or -ve error |
751fed42 SG |
118 | */ |
119 | int sysreset_get_last_walk(void); | |
120 | ||
11636258 SW |
121 | /** |
122 | * sysreset_walk_halt() - try to reset, otherwise halt | |
123 | * | |
124 | * This calls sysreset_walk(). If it returns, indicating that reset is not | |
125 | * supported, it prints a message and halts. | |
1da0b6ab HS |
126 | * |
127 | * @type: Reset type to request | |
11636258 SW |
128 | */ |
129 | void sysreset_walk_halt(enum sysreset_t type); | |
130 | ||
131 | /** | |
132 | * reset_cpu() - calls sysreset_walk(SYSRESET_WARM) | |
133 | */ | |
35b65dd8 | 134 | void reset_cpu(void); |
11636258 | 135 | |
a8f63d18 SH |
136 | /** |
137 | * sysreset_register_wdt() - register a watchdog for use with sysreset | |
138 | * | |
139 | * This registers the given watchdog timer to be used to reset the system. | |
140 | * | |
141 | * @dev: WDT device | |
142 | * @return: 0 if OK, -errno if error | |
143 | */ | |
144 | int sysreset_register_wdt(struct udevice *dev); | |
145 | ||
11636258 | 146 | #endif |