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