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