Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _RESET_H |
| 7 | #define _RESET_H |
| 8 | |
Masahiro Yamada | 4815db8 | 2016-09-21 11:29:01 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
| 10 | |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 11 | /** |
| 12 | * A reset is a hardware signal indicating that a HW module (or IP block, or |
| 13 | * sometimes an entire off-CPU chip) reset all of its internal state to some |
| 14 | * known-good initial state. Drivers will often reset HW modules when they |
| 15 | * begin execution to ensure that hardware correctly responds to all requests, |
| 16 | * or in response to some error condition. Reset signals are often controlled |
| 17 | * externally to the HW module being reset, by an entity this API calls a reset |
| 18 | * controller. This API provides a standard means for drivers to request that |
| 19 | * reset controllers set or clear reset signals. |
| 20 | * |
| 21 | * A driver that implements UCLASS_RESET is a reset controller or provider. A |
| 22 | * controller will often implement multiple separate reset signals, since the |
| 23 | * hardware it manages often has this capability. reset-uclass.h describes the |
| 24 | * interface which reset controllers must implement. |
| 25 | * |
| 26 | * Reset consumers/clients are the HW modules affected by reset signals. This |
| 27 | * header file describes the API used by drivers for those HW modules. |
| 28 | */ |
| 29 | |
| 30 | struct udevice; |
| 31 | |
| 32 | /** |
| 33 | * struct reset_ctl - A handle to (allowing control of) a single reset signal. |
| 34 | * |
| 35 | * Clients provide storage for reset control handles. The content of the |
| 36 | * structure is managed solely by the reset API and reset drivers. A reset |
| 37 | * control struct is initialized by "get"ing the reset control struct. The |
| 38 | * reset control struct is passed to all other reset APIs to identify which |
| 39 | * reset signal to operate upon. |
| 40 | * |
| 41 | * @dev: The device which implements the reset signal. |
| 42 | * @id: The reset signal ID within the provider. |
Andreas Dannenberg | c72f9b7 | 2018-08-27 15:57:40 +0530 | [diff] [blame] | 43 | * @data: An optional data field for scenarios where a single integer ID is not |
| 44 | * sufficient. If used, it can be populated through an .of_xlate op and |
| 45 | * processed during the various reset ops. |
Shawn Guo | f5ed748 | 2019-03-20 15:32:38 +0800 | [diff] [blame^] | 46 | * @polarity: An optional polarity field for drivers that support |
| 47 | * different reset polarities. |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 48 | * |
Andreas Dannenberg | c72f9b7 | 2018-08-27 15:57:40 +0530 | [diff] [blame] | 49 | * Should additional information to identify and configure any reset signal |
| 50 | * for any provider be required in the future, the struct could be expanded to |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 51 | * either (a) add more fields to allow reset providers to store additional |
| 52 | * information, or (b) replace the id field with an opaque pointer, which the |
| 53 | * provider would dynamically allocated during its .of_xlate op, and process |
| 54 | * during is .request op. This may require the addition of an extra op to clean |
| 55 | * up the allocation. |
| 56 | */ |
| 57 | struct reset_ctl { |
| 58 | struct udevice *dev; |
| 59 | /* |
Andreas Dannenberg | c72f9b7 | 2018-08-27 15:57:40 +0530 | [diff] [blame] | 60 | * Written by of_xlate. In the future, we might add more fields here. |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 61 | */ |
| 62 | unsigned long id; |
Andreas Dannenberg | c72f9b7 | 2018-08-27 15:57:40 +0530 | [diff] [blame] | 63 | unsigned long data; |
Shawn Guo | f5ed748 | 2019-03-20 15:32:38 +0800 | [diff] [blame^] | 64 | unsigned long polarity; |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 65 | }; |
| 66 | |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 67 | /** |
| 68 | * struct reset_ctl_bulk - A handle to (allowing control of) a bulk of reset |
| 69 | * signals. |
| 70 | * |
| 71 | * Clients provide storage for the reset control bulk. The content of the |
| 72 | * structure is managed solely by the reset API. A reset control bulk struct is |
| 73 | * initialized by "get"ing the reset control bulk struct. |
| 74 | * The reset control bulk struct is passed to all other bulk reset APIs to apply |
| 75 | * the API to all the reset signals in the bulk struct. |
| 76 | * |
| 77 | * @resets: An array of reset signal handles handles. |
| 78 | * @count: The number of reset signal handles in the reset array. |
| 79 | */ |
| 80 | struct reset_ctl_bulk { |
| 81 | struct reset_ctl *resets; |
| 82 | unsigned int count; |
| 83 | }; |
| 84 | |
Ley Foon Tan | d99894d | 2018-06-14 18:45:20 +0800 | [diff] [blame] | 85 | #if CONFIG_IS_ENABLED(DM_RESET) |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 86 | /** |
| 87 | * reset_get_by_index - Get/request a reset signal by integer index. |
| 88 | * |
| 89 | * This looks up and requests a reset signal. The index is relative to the |
| 90 | * client device; each device is assumed to have n reset signals associated |
| 91 | * with it somehow, and this function finds and requests one of them. The |
| 92 | * mapping of client device reset signal indices to provider reset signals may |
| 93 | * be via device-tree properties, board-provided mapping tables, or some other |
| 94 | * mechanism. |
| 95 | * |
| 96 | * @dev: The client device. |
| 97 | * @index: The index of the reset signal to request, within the client's |
| 98 | * list of reset signals. |
| 99 | * @reset_ctl A pointer to a reset control struct to initialize. |
| 100 | * @return 0 if OK, or a negative error code. |
| 101 | */ |
| 102 | int reset_get_by_index(struct udevice *dev, int index, |
| 103 | struct reset_ctl *reset_ctl); |
| 104 | |
| 105 | /** |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 106 | * reset_get_bulk - Get/request all reset signals of a device. |
| 107 | * |
| 108 | * This looks up and requests all reset signals of the client device; each |
| 109 | * device is assumed to have n reset signals associated with it somehow, |
| 110 | * and this function finds and requests all of them in a separate structure. |
| 111 | * The mapping of client device reset signals indices to provider reset signals |
| 112 | * may be via device-tree properties, board-provided mapping tables, or some |
| 113 | * other mechanism. |
| 114 | * |
| 115 | * @dev: The client device. |
| 116 | * @bulk A pointer to a reset control bulk struct to initialize. |
| 117 | * @return 0 if OK, or a negative error code. |
| 118 | */ |
| 119 | int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk); |
| 120 | |
| 121 | /** |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 122 | * reset_get_by_name - Get/request a reset signal by name. |
| 123 | * |
| 124 | * This looks up and requests a reset signal. The name is relative to the |
| 125 | * client device; each device is assumed to have n reset signals associated |
| 126 | * with it somehow, and this function finds and requests one of them. The |
| 127 | * mapping of client device reset signal names to provider reset signal may be |
| 128 | * via device-tree properties, board-provided mapping tables, or some other |
| 129 | * mechanism. |
| 130 | * |
| 131 | * @dev: The client device. |
| 132 | * @name: The name of the reset signal to request, within the client's |
| 133 | * list of reset signals. |
| 134 | * @reset_ctl: A pointer to a reset control struct to initialize. |
| 135 | * @return 0 if OK, or a negative error code. |
| 136 | */ |
| 137 | int reset_get_by_name(struct udevice *dev, const char *name, |
| 138 | struct reset_ctl *reset_ctl); |
| 139 | |
| 140 | /** |
Patrice Chotard | 9bd5cdf | 2017-07-18 11:57:05 +0200 | [diff] [blame] | 141 | * reset_request - Request a reset signal. |
| 142 | * |
| 143 | * @reset_ctl: A reset control struct. |
| 144 | * |
| 145 | * @return 0 if OK, or a negative error code. |
| 146 | */ |
| 147 | int reset_request(struct reset_ctl *reset_ctl); |
| 148 | |
| 149 | /** |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 150 | * reset_free - Free a previously requested reset signal. |
| 151 | * |
| 152 | * @reset_ctl: A reset control struct that was previously successfully |
| 153 | * requested by reset_get_by_*(). |
| 154 | * @return 0 if OK, or a negative error code. |
| 155 | */ |
| 156 | int reset_free(struct reset_ctl *reset_ctl); |
| 157 | |
| 158 | /** |
| 159 | * reset_assert - Assert a reset signal. |
| 160 | * |
| 161 | * This function will assert the specified reset signal, thus resetting the |
| 162 | * affected HW module(s). Depending on the reset controller hardware, the reset |
| 163 | * signal will either stay asserted until reset_deassert() is called, or the |
| 164 | * hardware may autonomously clear the reset signal itself. |
| 165 | * |
| 166 | * @reset_ctl: A reset control struct that was previously successfully |
| 167 | * requested by reset_get_by_*(). |
| 168 | * @return 0 if OK, or a negative error code. |
| 169 | */ |
| 170 | int reset_assert(struct reset_ctl *reset_ctl); |
| 171 | |
| 172 | /** |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 173 | * reset_assert_bulk - Assert all reset signals in a reset control bulk struct. |
| 174 | * |
| 175 | * This function will assert the specified reset signals in a reset control |
| 176 | * bulk struct, thus resetting the affected HW module(s). Depending on the |
| 177 | * reset controller hardware, the reset signals will either stay asserted |
| 178 | * until reset_deassert_bulk() is called, or the hardware may autonomously |
| 179 | * clear the reset signals itself. |
| 180 | * |
| 181 | * @bulk: A reset control bulk struct that was previously successfully |
| 182 | * requested by reset_get_bulk(). |
| 183 | * @return 0 if OK, or a negative error code. |
| 184 | */ |
| 185 | int reset_assert_bulk(struct reset_ctl_bulk *bulk); |
| 186 | |
| 187 | /** |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 188 | * reset_deassert - Deassert a reset signal. |
| 189 | * |
| 190 | * This function will deassert the specified reset signal, thus releasing the |
| 191 | * affected HW modules() from reset, and allowing them to continue normal |
| 192 | * operation. |
| 193 | * |
| 194 | * @reset_ctl: A reset control struct that was previously successfully |
| 195 | * requested by reset_get_by_*(). |
| 196 | * @return 0 if OK, or a negative error code. |
| 197 | */ |
| 198 | int reset_deassert(struct reset_ctl *reset_ctl); |
| 199 | |
Patrice Chotard | 3b9d1bd | 2017-07-18 11:57:06 +0200 | [diff] [blame] | 200 | /** |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 201 | * reset_deassert_bulk - Deassert all reset signals in a reset control bulk |
| 202 | * struct. |
| 203 | * |
| 204 | * This function will deassert the specified reset signals in a reset control |
| 205 | * bulk struct, thus releasing the affected HW modules() from reset, and |
| 206 | * allowing them to continue normal operation. |
| 207 | * |
| 208 | * @bulk: A reset control bulk struct that was previously successfully |
| 209 | * requested by reset_get_bulk(). |
| 210 | * @return 0 if OK, or a negative error code. |
| 211 | */ |
| 212 | int reset_deassert_bulk(struct reset_ctl_bulk *bulk); |
| 213 | |
| 214 | /** |
Andreas Dannenberg | e7012e6 | 2018-08-27 15:57:39 +0530 | [diff] [blame] | 215 | * rst_status - Check reset signal status. |
| 216 | * |
| 217 | * @reset_ctl: The reset signal to check. |
| 218 | * @return 0 if deasserted, positive if asserted, or a negative |
| 219 | * error code. |
| 220 | */ |
| 221 | int reset_status(struct reset_ctl *reset_ctl); |
| 222 | |
| 223 | /** |
Patrice Chotard | 3b9d1bd | 2017-07-18 11:57:06 +0200 | [diff] [blame] | 224 | * reset_release_all - Assert/Free an array of previously requested resets. |
| 225 | * |
| 226 | * For each reset contained in the reset array, this function will check if |
| 227 | * reset has been previously requested and then will assert and free it. |
| 228 | * |
| 229 | * @reset_ctl: A reset struct array that was previously successfully |
| 230 | * requested by reset_get_by_*(). |
| 231 | * @count Number of reset contained in the array |
| 232 | * @return 0 if OK, or a negative error code. |
| 233 | */ |
| 234 | int reset_release_all(struct reset_ctl *reset_ctl, int count); |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * reset_release_bulk - Assert/Free an array of previously requested reset |
| 238 | * signals in a reset control bulk struct. |
| 239 | * |
| 240 | * For each reset contained in the reset control bulk struct, this function |
| 241 | * will check if reset has been previously requested and then will assert |
| 242 | * and free it. |
| 243 | * |
| 244 | * @bulk: A reset control bulk struct that was previously successfully |
| 245 | * requested by reset_get_bulk(). |
| 246 | * @return 0 if OK, or a negative error code. |
| 247 | */ |
| 248 | static inline int reset_release_bulk(struct reset_ctl_bulk *bulk) |
| 249 | { |
| 250 | return reset_release_all(bulk->resets, bulk->count); |
| 251 | } |
Masahiro Yamada | 4815db8 | 2016-09-21 11:29:01 +0900 | [diff] [blame] | 252 | #else |
| 253 | static inline int reset_get_by_index(struct udevice *dev, int index, |
| 254 | struct reset_ctl *reset_ctl) |
| 255 | { |
| 256 | return -ENOTSUPP; |
| 257 | } |
| 258 | |
Neil Armstrong | 1dd181f | 2018-04-12 10:03:19 +0200 | [diff] [blame] | 259 | static inline int reset_get_bulk(struct udevice *dev, |
| 260 | struct reset_ctl_bulk *bulk) |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 261 | { |
| 262 | return -ENOTSUPP; |
| 263 | } |
| 264 | |
Masahiro Yamada | 4815db8 | 2016-09-21 11:29:01 +0900 | [diff] [blame] | 265 | static inline int reset_get_by_name(struct udevice *dev, const char *name, |
| 266 | struct reset_ctl *reset_ctl) |
| 267 | { |
| 268 | return -ENOTSUPP; |
| 269 | } |
| 270 | |
| 271 | static inline int reset_free(struct reset_ctl *reset_ctl) |
| 272 | { |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static inline int reset_assert(struct reset_ctl *reset_ctl) |
| 277 | { |
| 278 | return 0; |
| 279 | } |
| 280 | |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 281 | static inline int reset_assert_bulk(struct reset_ctl_bulk *bulk) |
| 282 | { |
| 283 | return 0; |
| 284 | } |
| 285 | |
Masahiro Yamada | 4815db8 | 2016-09-21 11:29:01 +0900 | [diff] [blame] | 286 | static inline int reset_deassert(struct reset_ctl *reset_ctl) |
| 287 | { |
| 288 | return 0; |
| 289 | } |
Patrice Chotard | 3b9d1bd | 2017-07-18 11:57:06 +0200 | [diff] [blame] | 290 | |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 291 | static inline int reset_deassert_bulk(struct reset_ctl_bulk *bulk) |
| 292 | { |
| 293 | return 0; |
| 294 | } |
| 295 | |
Andreas Dannenberg | e7012e6 | 2018-08-27 15:57:39 +0530 | [diff] [blame] | 296 | static inline int reset_status(struct reset_ctl *reset_ctl) |
| 297 | { |
| 298 | return -ENOTSUPP; |
| 299 | } |
| 300 | |
Patrice Chotard | 3b9d1bd | 2017-07-18 11:57:06 +0200 | [diff] [blame] | 301 | static inline int reset_release_all(struct reset_ctl *reset_ctl, int count) |
| 302 | { |
| 303 | return 0; |
| 304 | } |
| 305 | |
Neil Armstrong | 1dd181f | 2018-04-12 10:03:19 +0200 | [diff] [blame] | 306 | static inline int reset_release_bulk(struct reset_ctl_bulk *bulk) |
Neil Armstrong | 0c28233 | 2018-04-03 11:40:50 +0200 | [diff] [blame] | 307 | { |
| 308 | return 0; |
| 309 | } |
Masahiro Yamada | 4815db8 | 2016-09-21 11:29:01 +0900 | [diff] [blame] | 310 | #endif |
| 311 | |
Jagan Teki | 652ee27 | 2018-08-06 18:55:06 +0530 | [diff] [blame] | 312 | /** |
| 313 | * reset_valid() - check if reset is valid |
| 314 | * |
| 315 | * @reset_ctl: the reset to check |
| 316 | * @return TRUE if valid, or FALSE |
| 317 | */ |
| 318 | static inline bool reset_valid(struct reset_ctl *reset_ctl) |
| 319 | { |
| 320 | return !!reset_ctl->dev; |
| 321 | } |
| 322 | |
Stephen Warren | 89c1e2d | 2016-06-17 09:43:58 -0600 | [diff] [blame] | 323 | #endif |