Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 2 | #ifndef _LINUX_RESET_H_ |
| 3 | #define _LINUX_RESET_H_ |
| 4 | |
Randy Dunlap | d005aa7 | 2019-04-02 08:20:08 -0700 | [diff] [blame] | 5 | #include <linux/err.h> |
| 6 | #include <linux/errno.h> |
Masahiro Yamada | dfc1d9b | 2017-10-29 01:50:08 +0900 | [diff] [blame] | 7 | #include <linux/types.h> |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 8 | |
Masahiro Yamada | dfc1d9b | 2017-10-29 01:50:08 +0900 | [diff] [blame] | 9 | struct device; |
| 10 | struct device_node; |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 11 | struct reset_control; |
| 12 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 13 | #ifdef CONFIG_RESET_CONTROLLER |
| 14 | |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 15 | int reset_control_reset(struct reset_control *rstc); |
| 16 | int reset_control_assert(struct reset_control *rstc); |
| 17 | int reset_control_deassert(struct reset_control *rstc); |
Dinh Nguyen | 729de41 | 2014-10-10 10:21:14 -0500 | [diff] [blame] | 18 | int reset_control_status(struct reset_control *rstc); |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 19 | int reset_control_acquire(struct reset_control *rstc); |
| 20 | void reset_control_release(struct reset_control *rstc); |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 21 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 22 | struct reset_control *__of_reset_control_get(struct device_node *node, |
Ramiro Oliveira | bb47523 | 2017-01-13 17:57:41 +0000 | [diff] [blame] | 23 | const char *id, int index, bool shared, |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 24 | bool optional, bool acquired); |
Philipp Zabel | 62e24c5 | 2016-02-05 13:41:39 +0100 | [diff] [blame] | 25 | struct reset_control *__reset_control_get(struct device *dev, const char *id, |
| 26 | int index, bool shared, |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 27 | bool optional, bool acquired); |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 28 | void reset_control_put(struct reset_control *rstc); |
Masahiro Yamada | 1554bbd | 2017-10-29 01:50:06 +0900 | [diff] [blame] | 29 | int __device_reset(struct device *dev, bool optional); |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 30 | struct reset_control *__devm_reset_control_get(struct device *dev, |
Ramiro Oliveira | bb47523 | 2017-01-13 17:57:41 +0000 | [diff] [blame] | 31 | const char *id, int index, bool shared, |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 32 | bool optional, bool acquired); |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 33 | |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 34 | struct reset_control *devm_reset_control_array_get(struct device *dev, |
| 35 | bool shared, bool optional); |
| 36 | struct reset_control *of_reset_control_array_get(struct device_node *np, |
Thierry Reding | f31d5c2 | 2019-02-21 16:25:54 +0100 | [diff] [blame] | 37 | bool shared, bool optional, |
| 38 | bool acquired); |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 39 | |
Geert Uytterhoeven | eaf91db | 2018-11-13 13:47:44 +0100 | [diff] [blame] | 40 | int reset_control_get_count(struct device *dev); |
| 41 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 42 | #else |
| 43 | |
| 44 | static inline int reset_control_reset(struct reset_control *rstc) |
| 45 | { |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | static inline int reset_control_assert(struct reset_control *rstc) |
| 50 | { |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static inline int reset_control_deassert(struct reset_control *rstc) |
| 55 | { |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
Dinh Nguyen | 729de41 | 2014-10-10 10:21:14 -0500 | [diff] [blame] | 59 | static inline int reset_control_status(struct reset_control *rstc) |
| 60 | { |
Dinh Nguyen | 729de41 | 2014-10-10 10:21:14 -0500 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 64 | static inline int reset_control_acquire(struct reset_control *rstc) |
| 65 | { |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static inline void reset_control_release(struct reset_control *rstc) |
| 70 | { |
| 71 | } |
| 72 | |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 73 | static inline void reset_control_put(struct reset_control *rstc) |
| 74 | { |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Masahiro Yamada | 1554bbd | 2017-10-29 01:50:06 +0900 | [diff] [blame] | 77 | static inline int __device_reset(struct device *dev, bool optional) |
Daniel Lezcano | 4113652 | 2016-04-01 21:38:16 +0200 | [diff] [blame] | 78 | { |
Masahiro Yamada | 1554bbd | 2017-10-29 01:50:06 +0900 | [diff] [blame] | 79 | return optional ? 0 : -ENOTSUPP; |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 82 | static inline struct reset_control *__of_reset_control_get( |
| 83 | struct device_node *node, |
Ramiro Oliveira | bb47523 | 2017-01-13 17:57:41 +0000 | [diff] [blame] | 84 | const char *id, int index, bool shared, |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 85 | bool optional, bool acquired) |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 86 | { |
Philipp Zabel | 0ca10b6 | 2017-03-20 11:25:16 +0100 | [diff] [blame] | 87 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 88 | } |
| 89 | |
Philipp Zabel | 62e24c5 | 2016-02-05 13:41:39 +0100 | [diff] [blame] | 90 | static inline struct reset_control *__reset_control_get( |
| 91 | struct device *dev, const char *id, |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 92 | int index, bool shared, bool optional, |
| 93 | bool acquired) |
Philipp Zabel | 62e24c5 | 2016-02-05 13:41:39 +0100 | [diff] [blame] | 94 | { |
| 95 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
| 96 | } |
| 97 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 98 | static inline struct reset_control *__devm_reset_control_get( |
Ramiro Oliveira | bb47523 | 2017-01-13 17:57:41 +0000 | [diff] [blame] | 99 | struct device *dev, const char *id, |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 100 | int index, bool shared, bool optional, |
| 101 | bool acquired) |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 102 | { |
Philipp Zabel | 0ca10b6 | 2017-03-20 11:25:16 +0100 | [diff] [blame] | 103 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 106 | static inline struct reset_control * |
| 107 | devm_reset_control_array_get(struct device *dev, bool shared, bool optional) |
| 108 | { |
| 109 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
| 110 | } |
| 111 | |
| 112 | static inline struct reset_control * |
Thierry Reding | f31d5c2 | 2019-02-21 16:25:54 +0100 | [diff] [blame] | 113 | of_reset_control_array_get(struct device_node *np, bool shared, bool optional, |
| 114 | bool acquired) |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 115 | { |
| 116 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
| 117 | } |
| 118 | |
Geert Uytterhoeven | eaf91db | 2018-11-13 13:47:44 +0100 | [diff] [blame] | 119 | static inline int reset_control_get_count(struct device *dev) |
| 120 | { |
| 121 | return -ENOENT; |
| 122 | } |
| 123 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 124 | #endif /* CONFIG_RESET_CONTROLLER */ |
| 125 | |
Masahiro Yamada | 1554bbd | 2017-10-29 01:50:06 +0900 | [diff] [blame] | 126 | static inline int __must_check device_reset(struct device *dev) |
| 127 | { |
| 128 | return __device_reset(dev, false); |
| 129 | } |
| 130 | |
| 131 | static inline int device_reset_optional(struct device *dev) |
| 132 | { |
| 133 | return __device_reset(dev, true); |
| 134 | } |
| 135 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 136 | /** |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 137 | * reset_control_get_exclusive - Lookup and obtain an exclusive reference |
| 138 | * to a reset controller. |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 139 | * @dev: device to be reset by the controller |
| 140 | * @id: reset line name |
| 141 | * |
| 142 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
Geert Uytterhoeven | 34845c9 | 2018-09-26 15:20:03 +0200 | [diff] [blame] | 143 | * If this function is called more than once for the same reset_control it will |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 144 | * return -EBUSY. |
| 145 | * |
Philipp Zabel | b9e9348 | 2019-10-22 18:19:22 +0200 | [diff] [blame] | 146 | * See reset_control_get_shared() for details on shared references to |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 147 | * reset-controls. |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 148 | * |
| 149 | * Use of id names is optional. |
| 150 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 151 | static inline struct reset_control * |
| 152 | __must_check reset_control_get_exclusive(struct device *dev, const char *id) |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 153 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 154 | return __reset_control_get(dev, id, 0, false, false, true); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * reset_control_get_exclusive_released - Lookup and obtain a temoprarily |
| 159 | * exclusive reference to a reset |
| 160 | * controller. |
| 161 | * @dev: device to be reset by the controller |
| 162 | * @id: reset line name |
| 163 | * |
| 164 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
| 165 | * reset-controls returned by this function must be acquired via |
| 166 | * reset_control_acquire() before they can be used and should be released |
| 167 | * via reset_control_release() afterwards. |
| 168 | * |
| 169 | * Use of id names is optional. |
| 170 | */ |
| 171 | static inline struct reset_control * |
| 172 | __must_check reset_control_get_exclusive_released(struct device *dev, |
| 173 | const char *id) |
| 174 | { |
| 175 | return __reset_control_get(dev, id, 0, false, false, false); |
Axel Lin | 5bcd0b7 | 2015-09-01 07:56:38 +0800 | [diff] [blame] | 176 | } |
| 177 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 178 | /** |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 179 | * reset_control_get_shared - Lookup and obtain a shared reference to a |
| 180 | * reset controller. |
| 181 | * @dev: device to be reset by the controller |
| 182 | * @id: reset line name |
| 183 | * |
| 184 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
| 185 | * This function is intended for use with reset-controls which are shared |
Geert Uytterhoeven | 12c62b9 | 2018-10-08 13:15:43 +0200 | [diff] [blame] | 186 | * between hardware blocks. |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 187 | * |
| 188 | * When a reset-control is shared, the behavior of reset_control_assert / |
| 189 | * deassert is changed, the reset-core will keep track of a deassert_count |
| 190 | * and only (re-)assert the reset after reset_control_assert has been called |
| 191 | * as many times as reset_control_deassert was called. Also see the remark |
| 192 | * about shared reset-controls in the reset_control_assert docs. |
| 193 | * |
| 194 | * Calling reset_control_assert without first calling reset_control_deassert |
| 195 | * is not allowed on a shared reset control. Calling reset_control_reset is |
| 196 | * also not allowed on a shared reset control. |
| 197 | * |
| 198 | * Use of id names is optional. |
| 199 | */ |
| 200 | static inline struct reset_control *reset_control_get_shared( |
| 201 | struct device *dev, const char *id) |
| 202 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 203 | return __reset_control_get(dev, id, 0, true, false, false); |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Philipp Zabel | c2ffa00 | 2019-10-22 16:53:25 +0200 | [diff] [blame] | 206 | /** |
| 207 | * reset_control_get_optional_exclusive - optional reset_control_get_exclusive() |
| 208 | * @dev: device to be reset by the controller |
| 209 | * @id: reset line name |
| 210 | * |
| 211 | * Optional variant of reset_control_get_exclusive(). If the requested reset |
| 212 | * is not specified in the device tree, this function returns NULL instead of |
| 213 | * an error. |
| 214 | * |
| 215 | * See reset_control_get_exclusive() for more information. |
| 216 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 217 | static inline struct reset_control *reset_control_get_optional_exclusive( |
Lee Jones | 3c35f6e | 2016-06-06 16:56:49 +0100 | [diff] [blame] | 218 | struct device *dev, const char *id) |
| 219 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 220 | return __reset_control_get(dev, id, 0, false, true, true); |
Lee Jones | 3c35f6e | 2016-06-06 16:56:49 +0100 | [diff] [blame] | 221 | } |
| 222 | |
Philipp Zabel | c2ffa00 | 2019-10-22 16:53:25 +0200 | [diff] [blame] | 223 | /** |
| 224 | * reset_control_get_optional_shared - optional reset_control_get_shared() |
| 225 | * @dev: device to be reset by the controller |
| 226 | * @id: reset line name |
| 227 | * |
| 228 | * Optional variant of reset_control_get_shared(). If the requested reset |
| 229 | * is not specified in the device tree, this function returns NULL instead of |
| 230 | * an error. |
| 231 | * |
| 232 | * See reset_control_get_shared() for more information. |
| 233 | */ |
Lee Jones | c33d61a | 2016-06-06 16:56:52 +0100 | [diff] [blame] | 234 | static inline struct reset_control *reset_control_get_optional_shared( |
| 235 | struct device *dev, const char *id) |
| 236 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 237 | return __reset_control_get(dev, id, 0, true, true, false); |
Lee Jones | c33d61a | 2016-06-06 16:56:52 +0100 | [diff] [blame] | 238 | } |
| 239 | |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 240 | /** |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 241 | * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference |
| 242 | * to a reset controller. |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 243 | * @node: device to be reset by the controller |
| 244 | * @id: reset line name |
| 245 | * |
| 246 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
| 247 | * |
| 248 | * Use of id names is optional. |
| 249 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 250 | static inline struct reset_control *of_reset_control_get_exclusive( |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 251 | struct device_node *node, const char *id) |
| 252 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 253 | return __of_reset_control_get(node, id, 0, false, false, true); |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /** |
Geert Uytterhoeven | 12c62b9 | 2018-10-08 13:15:43 +0200 | [diff] [blame] | 257 | * of_reset_control_get_shared - Lookup and obtain a shared reference |
Lee Jones | 40faee8e | 2016-06-06 16:56:51 +0100 | [diff] [blame] | 258 | * to a reset controller. |
| 259 | * @node: device to be reset by the controller |
| 260 | * @id: reset line name |
| 261 | * |
| 262 | * When a reset-control is shared, the behavior of reset_control_assert / |
| 263 | * deassert is changed, the reset-core will keep track of a deassert_count |
| 264 | * and only (re-)assert the reset after reset_control_assert has been called |
| 265 | * as many times as reset_control_deassert was called. Also see the remark |
| 266 | * about shared reset-controls in the reset_control_assert docs. |
| 267 | * |
| 268 | * Calling reset_control_assert without first calling reset_control_deassert |
| 269 | * is not allowed on a shared reset control. Calling reset_control_reset is |
| 270 | * also not allowed on a shared reset control. |
| 271 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
| 272 | * |
| 273 | * Use of id names is optional. |
| 274 | */ |
| 275 | static inline struct reset_control *of_reset_control_get_shared( |
| 276 | struct device_node *node, const char *id) |
| 277 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 278 | return __of_reset_control_get(node, id, 0, true, false, false); |
Lee Jones | 40faee8e | 2016-06-06 16:56:51 +0100 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /** |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 282 | * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive |
| 283 | * reference to a reset controller |
| 284 | * by index. |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 285 | * @node: device to be reset by the controller |
| 286 | * @index: index of the reset controller |
| 287 | * |
| 288 | * This is to be used to perform a list of resets for a device or power domain |
| 289 | * in whatever order. Returns a struct reset_control or IS_ERR() condition |
| 290 | * containing errno. |
| 291 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 292 | static inline struct reset_control *of_reset_control_get_exclusive_by_index( |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 293 | struct device_node *node, int index) |
| 294 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 295 | return __of_reset_control_get(node, NULL, index, false, false, true); |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /** |
Geert Uytterhoeven | 12c62b9 | 2018-10-08 13:15:43 +0200 | [diff] [blame] | 299 | * of_reset_control_get_shared_by_index - Lookup and obtain a shared |
Lee Jones | 40faee8e | 2016-06-06 16:56:51 +0100 | [diff] [blame] | 300 | * reference to a reset controller |
| 301 | * by index. |
| 302 | * @node: device to be reset by the controller |
| 303 | * @index: index of the reset controller |
| 304 | * |
| 305 | * When a reset-control is shared, the behavior of reset_control_assert / |
| 306 | * deassert is changed, the reset-core will keep track of a deassert_count |
| 307 | * and only (re-)assert the reset after reset_control_assert has been called |
| 308 | * as many times as reset_control_deassert was called. Also see the remark |
| 309 | * about shared reset-controls in the reset_control_assert docs. |
| 310 | * |
| 311 | * Calling reset_control_assert without first calling reset_control_deassert |
| 312 | * is not allowed on a shared reset control. Calling reset_control_reset is |
| 313 | * also not allowed on a shared reset control. |
| 314 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
| 315 | * |
| 316 | * This is to be used to perform a list of resets for a device or power domain |
| 317 | * in whatever order. Returns a struct reset_control or IS_ERR() condition |
| 318 | * containing errno. |
| 319 | */ |
| 320 | static inline struct reset_control *of_reset_control_get_shared_by_index( |
| 321 | struct device_node *node, int index) |
| 322 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 323 | return __of_reset_control_get(node, NULL, index, true, false, false); |
Lee Jones | 40faee8e | 2016-06-06 16:56:51 +0100 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /** |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 327 | * devm_reset_control_get_exclusive - resource managed |
| 328 | * reset_control_get_exclusive() |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 329 | * @dev: device to be reset by the controller |
| 330 | * @id: reset line name |
| 331 | * |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 332 | * Managed reset_control_get_exclusive(). For reset controllers returned |
| 333 | * from this function, reset_control_put() is called automatically on driver |
| 334 | * detach. |
| 335 | * |
| 336 | * See reset_control_get_exclusive() for more information. |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 337 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 338 | static inline struct reset_control * |
| 339 | __must_check devm_reset_control_get_exclusive(struct device *dev, |
| 340 | const char *id) |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 341 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 342 | return __devm_reset_control_get(dev, id, 0, false, false, true); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * devm_reset_control_get_exclusive_released - resource managed |
| 347 | * reset_control_get_exclusive_released() |
| 348 | * @dev: device to be reset by the controller |
| 349 | * @id: reset line name |
| 350 | * |
| 351 | * Managed reset_control_get_exclusive_released(). For reset controllers |
| 352 | * returned from this function, reset_control_put() is called automatically on |
| 353 | * driver detach. |
| 354 | * |
| 355 | * See reset_control_get_exclusive_released() for more information. |
| 356 | */ |
| 357 | static inline struct reset_control * |
| 358 | __must_check devm_reset_control_get_exclusive_released(struct device *dev, |
| 359 | const char *id) |
| 360 | { |
| 361 | return __devm_reset_control_get(dev, id, 0, false, false, false); |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 364 | /** |
| 365 | * devm_reset_control_get_shared - resource managed reset_control_get_shared() |
| 366 | * @dev: device to be reset by the controller |
| 367 | * @id: reset line name |
| 368 | * |
| 369 | * Managed reset_control_get_shared(). For reset controllers returned from |
| 370 | * this function, reset_control_put() is called automatically on driver detach. |
| 371 | * See reset_control_get_shared() for more information. |
| 372 | */ |
| 373 | static inline struct reset_control *devm_reset_control_get_shared( |
| 374 | struct device *dev, const char *id) |
| 375 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 376 | return __devm_reset_control_get(dev, id, 0, true, false, false); |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Philipp Zabel | c2ffa00 | 2019-10-22 16:53:25 +0200 | [diff] [blame] | 379 | /** |
| 380 | * devm_reset_control_get_optional_exclusive - resource managed |
| 381 | * reset_control_get_optional_exclusive() |
| 382 | * @dev: device to be reset by the controller |
| 383 | * @id: reset line name |
| 384 | * |
| 385 | * Managed reset_control_get_optional_exclusive(). For reset controllers |
| 386 | * returned from this function, reset_control_put() is called automatically on |
| 387 | * driver detach. |
| 388 | * |
| 389 | * See reset_control_get_optional_exclusive() for more information. |
| 390 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 391 | static inline struct reset_control *devm_reset_control_get_optional_exclusive( |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 392 | struct device *dev, const char *id) |
| 393 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 394 | return __devm_reset_control_get(dev, id, 0, false, true, true); |
Philipp Zabel | b424080 | 2014-03-07 15:18:47 +0100 | [diff] [blame] | 395 | } |
| 396 | |
Philipp Zabel | c2ffa00 | 2019-10-22 16:53:25 +0200 | [diff] [blame] | 397 | /** |
| 398 | * devm_reset_control_get_optional_shared - resource managed |
| 399 | * reset_control_get_optional_shared() |
| 400 | * @dev: device to be reset by the controller |
| 401 | * @id: reset line name |
| 402 | * |
| 403 | * Managed reset_control_get_optional_shared(). For reset controllers returned |
| 404 | * from this function, reset_control_put() is called automatically on driver |
| 405 | * detach. |
| 406 | * |
| 407 | * See reset_control_get_optional_shared() for more information. |
| 408 | */ |
Lee Jones | c33d61a | 2016-06-06 16:56:52 +0100 | [diff] [blame] | 409 | static inline struct reset_control *devm_reset_control_get_optional_shared( |
| 410 | struct device *dev, const char *id) |
| 411 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 412 | return __devm_reset_control_get(dev, id, 0, true, true, false); |
Lee Jones | c33d61a | 2016-06-06 16:56:52 +0100 | [diff] [blame] | 413 | } |
| 414 | |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 415 | /** |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 416 | * devm_reset_control_get_exclusive_by_index - resource managed |
| 417 | * reset_control_get_exclusive() |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 418 | * @dev: device to be reset by the controller |
| 419 | * @index: index of the reset controller |
| 420 | * |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 421 | * Managed reset_control_get_exclusive(). For reset controllers returned from |
| 422 | * this function, reset_control_put() is called automatically on driver |
| 423 | * detach. |
| 424 | * |
| 425 | * See reset_control_get_exclusive() for more information. |
Hans de Goede | 6c96f05 | 2016-02-23 18:46:24 +0100 | [diff] [blame] | 426 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 427 | static inline struct reset_control * |
| 428 | devm_reset_control_get_exclusive_by_index(struct device *dev, int index) |
Hans de Goede | e3ec0a8 | 2014-04-13 14:09:15 +0200 | [diff] [blame] | 429 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 430 | return __devm_reset_control_get(dev, NULL, index, false, false, true); |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 433 | /** |
| 434 | * devm_reset_control_get_shared_by_index - resource managed |
Geert Uytterhoeven | 12c62b9 | 2018-10-08 13:15:43 +0200 | [diff] [blame] | 435 | * reset_control_get_shared |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 436 | * @dev: device to be reset by the controller |
| 437 | * @index: index of the reset controller |
| 438 | * |
| 439 | * Managed reset_control_get_shared(). For reset controllers returned from |
| 440 | * this function, reset_control_put() is called automatically on driver detach. |
| 441 | * See reset_control_get_shared() for more information. |
| 442 | */ |
Lee Jones | 0bcc0ea | 2016-06-06 16:56:53 +0100 | [diff] [blame] | 443 | static inline struct reset_control * |
| 444 | devm_reset_control_get_shared_by_index(struct device *dev, int index) |
Hans de Goede | 0b52297 | 2016-02-23 18:46:26 +0100 | [diff] [blame] | 445 | { |
Philipp Zabel | c84b032 | 2019-02-21 16:25:53 +0100 | [diff] [blame] | 446 | return __devm_reset_control_get(dev, NULL, index, true, false, false); |
Hans de Goede | e3ec0a8 | 2014-04-13 14:09:15 +0200 | [diff] [blame] | 447 | } |
| 448 | |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 449 | /* |
| 450 | * TEMPORARY calls to use during transition: |
| 451 | * |
| 452 | * of_reset_control_get() => of_reset_control_get_exclusive() |
| 453 | * |
| 454 | * These inline function calls will be removed once all consumers |
| 455 | * have been moved over to the new explicit API. |
| 456 | */ |
Lee Jones | a53e35d | 2016-06-06 16:56:50 +0100 | [diff] [blame] | 457 | static inline struct reset_control *of_reset_control_get( |
| 458 | struct device_node *node, const char *id) |
| 459 | { |
| 460 | return of_reset_control_get_exclusive(node, id); |
| 461 | } |
| 462 | |
| 463 | static inline struct reset_control *of_reset_control_get_by_index( |
| 464 | struct device_node *node, int index) |
| 465 | { |
| 466 | return of_reset_control_get_exclusive_by_index(node, index); |
| 467 | } |
| 468 | |
| 469 | static inline struct reset_control *devm_reset_control_get( |
| 470 | struct device *dev, const char *id) |
| 471 | { |
| 472 | return devm_reset_control_get_exclusive(dev, id); |
| 473 | } |
| 474 | |
| 475 | static inline struct reset_control *devm_reset_control_get_optional( |
| 476 | struct device *dev, const char *id) |
| 477 | { |
| 478 | return devm_reset_control_get_optional_exclusive(dev, id); |
| 479 | |
| 480 | } |
| 481 | |
| 482 | static inline struct reset_control *devm_reset_control_get_by_index( |
| 483 | struct device *dev, int index) |
| 484 | { |
| 485 | return devm_reset_control_get_exclusive_by_index(dev, index); |
| 486 | } |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 487 | |
| 488 | /* |
| 489 | * APIs to manage a list of reset controllers |
| 490 | */ |
| 491 | static inline struct reset_control * |
| 492 | devm_reset_control_array_get_exclusive(struct device *dev) |
| 493 | { |
| 494 | return devm_reset_control_array_get(dev, false, false); |
| 495 | } |
| 496 | |
| 497 | static inline struct reset_control * |
| 498 | devm_reset_control_array_get_shared(struct device *dev) |
| 499 | { |
| 500 | return devm_reset_control_array_get(dev, true, false); |
| 501 | } |
| 502 | |
| 503 | static inline struct reset_control * |
| 504 | devm_reset_control_array_get_optional_exclusive(struct device *dev) |
| 505 | { |
| 506 | return devm_reset_control_array_get(dev, false, true); |
| 507 | } |
| 508 | |
| 509 | static inline struct reset_control * |
| 510 | devm_reset_control_array_get_optional_shared(struct device *dev) |
| 511 | { |
| 512 | return devm_reset_control_array_get(dev, true, true); |
| 513 | } |
| 514 | |
| 515 | static inline struct reset_control * |
| 516 | of_reset_control_array_get_exclusive(struct device_node *node) |
| 517 | { |
Thierry Reding | f31d5c2 | 2019-02-21 16:25:54 +0100 | [diff] [blame] | 518 | return of_reset_control_array_get(node, false, false, true); |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | static inline struct reset_control * |
Thierry Reding | 22815f18 | 2019-02-21 16:25:55 +0100 | [diff] [blame] | 522 | of_reset_control_array_get_exclusive_released(struct device_node *node) |
| 523 | { |
| 524 | return of_reset_control_array_get(node, false, false, false); |
| 525 | } |
| 526 | |
| 527 | static inline struct reset_control * |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 528 | of_reset_control_array_get_shared(struct device_node *node) |
| 529 | { |
Thierry Reding | f31d5c2 | 2019-02-21 16:25:54 +0100 | [diff] [blame] | 530 | return of_reset_control_array_get(node, true, false, true); |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static inline struct reset_control * |
| 534 | of_reset_control_array_get_optional_exclusive(struct device_node *node) |
| 535 | { |
Thierry Reding | f31d5c2 | 2019-02-21 16:25:54 +0100 | [diff] [blame] | 536 | return of_reset_control_array_get(node, false, true, true); |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | static inline struct reset_control * |
| 540 | of_reset_control_array_get_optional_shared(struct device_node *node) |
| 541 | { |
Thierry Reding | f31d5c2 | 2019-02-21 16:25:54 +0100 | [diff] [blame] | 542 | return of_reset_control_array_get(node, true, true, true); |
Vivek Gautam | 17c82e2 | 2017-05-22 16:53:25 +0530 | [diff] [blame] | 543 | } |
Philipp Zabel | 61fc413 | 2012-11-19 17:23:13 +0100 | [diff] [blame] | 544 | #endif |