]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: GPL-2.0+ */ | |
2 | /* | |
3 | * Copyright (c) 2015 Google, Inc | |
4 | * Written by Simon Glass <[email protected]> | |
5 | */ | |
6 | ||
7 | #ifndef __SYSRESET_H | |
8 | #define __SYSRESET_H | |
9 | ||
10 | struct udevice; | |
11 | ||
12 | /** | |
13 | * enum sysreset_t - system reset types | |
14 | */ | |
15 | enum sysreset_t { | |
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 */ | |
25 | SYSRESET_COUNT, | |
26 | }; | |
27 | ||
28 | /** | |
29 | * struct sysreset_ops - operations of system reset drivers | |
30 | */ | |
31 | struct sysreset_ops { | |
32 | /** | |
33 | * @request: request a sysreset of the given type | |
34 | * | |
35 | * Note that this function may return before the reset takes effect. | |
36 | * | |
37 | * @dev: Device to be used for system reset | |
38 | * @type: Reset type to request | |
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) | |
44 | */ | |
45 | int (*request)(struct udevice *dev, enum sysreset_t type); | |
46 | /** | |
47 | * @get_status: get printable reset status information | |
48 | * | |
49 | * @dev: Device to check | |
50 | * @buf: Buffer to receive the textual reset information | |
51 | * @size: Size of the passed buffer | |
52 | * Return: 0 if OK, -ve on error | |
53 | */ | |
54 | int (*get_status)(struct udevice *dev, char *buf, int size); | |
55 | ||
56 | /** | |
57 | * @get_last: get information on the last reset | |
58 | * | |
59 | * @dev: Device to check | |
60 | * Return: last reset state (enum :enum:`sysreset_t`) or -ve error | |
61 | */ | |
62 | int (*get_last)(struct udevice *dev); | |
63 | }; | |
64 | ||
65 | #define sysreset_get_ops(dev) ((struct sysreset_ops *)(dev)->driver->ops) | |
66 | ||
67 | /** | |
68 | * sysreset_request() - request a sysreset | |
69 | * | |
70 | * @dev: Device to be used for system reset | |
71 | * @type: Reset type to request | |
72 | * Return: 0 if OK, -EPROTONOSUPPORT if not supported by this device | |
73 | */ | |
74 | int sysreset_request(struct udevice *dev, enum sysreset_t type); | |
75 | ||
76 | /** | |
77 | * sysreset_get_status() - get printable reset status information | |
78 | * | |
79 | * @dev: Device to check | |
80 | * @buf: Buffer to receive the textual reset information | |
81 | * @size: Size of the passed buffer | |
82 | * Return: 0 if OK, -ve on error | |
83 | */ | |
84 | int sysreset_get_status(struct udevice *dev, char *buf, int size); | |
85 | ||
86 | /** | |
87 | * sysreset_get_last() - get information on the last reset | |
88 | * | |
89 | * @dev: Device to check | |
90 | * Return: last reset state (enum sysreset_t) or -ve error | |
91 | */ | |
92 | int sysreset_get_last(struct udevice *dev); | |
93 | ||
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 | |
104 | * Return: -EINPROGRESS if a reset is in progress, -ENOSYS if not available | |
105 | */ | |
106 | int sysreset_walk(enum sysreset_t type); | |
107 | ||
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 | * | |
117 | * Return: last reset state (enum sysreset_t) or -ve error | |
118 | */ | |
119 | int sysreset_get_last_walk(void); | |
120 | ||
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. | |
126 | * | |
127 | * @type: Reset type to request | |
128 | */ | |
129 | void sysreset_walk_halt(enum sysreset_t type); | |
130 | ||
131 | /** | |
132 | * reset_cpu() - calls sysreset_walk(SYSRESET_WARM) | |
133 | */ | |
134 | void reset_cpu(void); | |
135 | ||
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 | ||
146 | #endif |