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