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