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