| .. | .. |
|---|
| 2 | 2 | #ifndef _LINUX_RESET_H_ |
|---|
| 3 | 3 | #define _LINUX_RESET_H_ |
|---|
| 4 | 4 | |
|---|
| 5 | +#include <linux/err.h> |
|---|
| 6 | +#include <linux/errno.h> |
|---|
| 5 | 7 | #include <linux/types.h> |
|---|
| 6 | 8 | |
|---|
| 7 | 9 | struct device; |
|---|
| .. | .. |
|---|
| 14 | 16 | int reset_control_assert(struct reset_control *rstc); |
|---|
| 15 | 17 | int reset_control_deassert(struct reset_control *rstc); |
|---|
| 16 | 18 | int reset_control_status(struct reset_control *rstc); |
|---|
| 19 | +int reset_control_acquire(struct reset_control *rstc); |
|---|
| 20 | +void reset_control_release(struct reset_control *rstc); |
|---|
| 17 | 21 | |
|---|
| 18 | 22 | struct reset_control *__of_reset_control_get(struct device_node *node, |
|---|
| 19 | 23 | const char *id, int index, bool shared, |
|---|
| 20 | | - bool optional); |
|---|
| 24 | + bool optional, bool acquired); |
|---|
| 21 | 25 | struct reset_control *__reset_control_get(struct device *dev, const char *id, |
|---|
| 22 | 26 | int index, bool shared, |
|---|
| 23 | | - bool optional); |
|---|
| 27 | + bool optional, bool acquired); |
|---|
| 24 | 28 | void reset_control_put(struct reset_control *rstc); |
|---|
| 25 | 29 | int __device_reset(struct device *dev, bool optional); |
|---|
| 26 | 30 | struct reset_control *__devm_reset_control_get(struct device *dev, |
|---|
| 27 | 31 | const char *id, int index, bool shared, |
|---|
| 28 | | - bool optional); |
|---|
| 32 | + bool optional, bool acquired); |
|---|
| 29 | 33 | |
|---|
| 30 | 34 | struct reset_control *devm_reset_control_array_get(struct device *dev, |
|---|
| 31 | 35 | bool shared, bool optional); |
|---|
| 32 | 36 | struct reset_control *of_reset_control_array_get(struct device_node *np, |
|---|
| 33 | | - bool shared, bool optional); |
|---|
| 37 | + bool shared, bool optional, |
|---|
| 38 | + bool acquired); |
|---|
| 39 | + |
|---|
| 40 | +int reset_control_get_count(struct device *dev); |
|---|
| 34 | 41 | |
|---|
| 35 | 42 | #else |
|---|
| 36 | 43 | |
|---|
| .. | .. |
|---|
| 54 | 61 | return 0; |
|---|
| 55 | 62 | } |
|---|
| 56 | 63 | |
|---|
| 64 | +static inline int reset_control_acquire(struct reset_control *rstc) |
|---|
| 65 | +{ |
|---|
| 66 | + return 0; |
|---|
| 67 | +} |
|---|
| 68 | + |
|---|
| 69 | +static inline void reset_control_release(struct reset_control *rstc) |
|---|
| 70 | +{ |
|---|
| 71 | +} |
|---|
| 72 | + |
|---|
| 57 | 73 | static inline void reset_control_put(struct reset_control *rstc) |
|---|
| 58 | 74 | { |
|---|
| 59 | 75 | } |
|---|
| .. | .. |
|---|
| 66 | 82 | static inline struct reset_control *__of_reset_control_get( |
|---|
| 67 | 83 | struct device_node *node, |
|---|
| 68 | 84 | const char *id, int index, bool shared, |
|---|
| 69 | | - bool optional) |
|---|
| 85 | + bool optional, bool acquired) |
|---|
| 70 | 86 | { |
|---|
| 71 | 87 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
|---|
| 72 | 88 | } |
|---|
| 73 | 89 | |
|---|
| 74 | 90 | static inline struct reset_control *__reset_control_get( |
|---|
| 75 | 91 | struct device *dev, const char *id, |
|---|
| 76 | | - int index, bool shared, bool optional) |
|---|
| 92 | + int index, bool shared, bool optional, |
|---|
| 93 | + bool acquired) |
|---|
| 77 | 94 | { |
|---|
| 78 | 95 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
|---|
| 79 | 96 | } |
|---|
| 80 | 97 | |
|---|
| 81 | 98 | static inline struct reset_control *__devm_reset_control_get( |
|---|
| 82 | 99 | struct device *dev, const char *id, |
|---|
| 83 | | - int index, bool shared, bool optional) |
|---|
| 100 | + int index, bool shared, bool optional, |
|---|
| 101 | + bool acquired) |
|---|
| 84 | 102 | { |
|---|
| 85 | 103 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
|---|
| 86 | 104 | } |
|---|
| .. | .. |
|---|
| 92 | 110 | } |
|---|
| 93 | 111 | |
|---|
| 94 | 112 | static inline struct reset_control * |
|---|
| 95 | | -of_reset_control_array_get(struct device_node *np, bool shared, bool optional) |
|---|
| 113 | +of_reset_control_array_get(struct device_node *np, bool shared, bool optional, |
|---|
| 114 | + bool acquired) |
|---|
| 96 | 115 | { |
|---|
| 97 | 116 | return optional ? NULL : ERR_PTR(-ENOTSUPP); |
|---|
| 117 | +} |
|---|
| 118 | + |
|---|
| 119 | +static inline int reset_control_get_count(struct device *dev) |
|---|
| 120 | +{ |
|---|
| 121 | + return -ENOENT; |
|---|
| 98 | 122 | } |
|---|
| 99 | 123 | |
|---|
| 100 | 124 | #endif /* CONFIG_RESET_CONTROLLER */ |
|---|
| .. | .. |
|---|
| 116 | 140 | * @id: reset line name |
|---|
| 117 | 141 | * |
|---|
| 118 | 142 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
|---|
| 119 | | - * If this function is called more then once for the same reset_control it will |
|---|
| 143 | + * If this function is called more than once for the same reset_control it will |
|---|
| 120 | 144 | * return -EBUSY. |
|---|
| 121 | 145 | * |
|---|
| 122 | | - * See reset_control_get_shared for details on shared references to |
|---|
| 146 | + * See reset_control_get_shared() for details on shared references to |
|---|
| 123 | 147 | * reset-controls. |
|---|
| 124 | 148 | * |
|---|
| 125 | 149 | * Use of id names is optional. |
|---|
| .. | .. |
|---|
| 127 | 151 | static inline struct reset_control * |
|---|
| 128 | 152 | __must_check reset_control_get_exclusive(struct device *dev, const char *id) |
|---|
| 129 | 153 | { |
|---|
| 130 | | - return __reset_control_get(dev, id, 0, false, false); |
|---|
| 154 | + return __reset_control_get(dev, id, 0, false, false, true); |
|---|
| 155 | +} |
|---|
| 156 | + |
|---|
| 157 | +/** |
|---|
| 158 | + * reset_control_get_exclusive_released - Lookup and obtain a temoprarily |
|---|
| 159 | + * exclusive reference to a reset |
|---|
| 160 | + * controller. |
|---|
| 161 | + * @dev: device to be reset by the controller |
|---|
| 162 | + * @id: reset line name |
|---|
| 163 | + * |
|---|
| 164 | + * Returns a struct reset_control or IS_ERR() condition containing errno. |
|---|
| 165 | + * reset-controls returned by this function must be acquired via |
|---|
| 166 | + * reset_control_acquire() before they can be used and should be released |
|---|
| 167 | + * via reset_control_release() afterwards. |
|---|
| 168 | + * |
|---|
| 169 | + * Use of id names is optional. |
|---|
| 170 | + */ |
|---|
| 171 | +static inline struct reset_control * |
|---|
| 172 | +__must_check reset_control_get_exclusive_released(struct device *dev, |
|---|
| 173 | + const char *id) |
|---|
| 174 | +{ |
|---|
| 175 | + return __reset_control_get(dev, id, 0, false, false, false); |
|---|
| 131 | 176 | } |
|---|
| 132 | 177 | |
|---|
| 133 | 178 | /** |
|---|
| .. | .. |
|---|
| 138 | 183 | * |
|---|
| 139 | 184 | * Returns a struct reset_control or IS_ERR() condition containing errno. |
|---|
| 140 | 185 | * This function is intended for use with reset-controls which are shared |
|---|
| 141 | | - * between hardware-blocks. |
|---|
| 186 | + * between hardware blocks. |
|---|
| 142 | 187 | * |
|---|
| 143 | 188 | * When a reset-control is shared, the behavior of reset_control_assert / |
|---|
| 144 | 189 | * deassert is changed, the reset-core will keep track of a deassert_count |
|---|
| .. | .. |
|---|
| 155 | 200 | static inline struct reset_control *reset_control_get_shared( |
|---|
| 156 | 201 | struct device *dev, const char *id) |
|---|
| 157 | 202 | { |
|---|
| 158 | | - return __reset_control_get(dev, id, 0, true, false); |
|---|
| 203 | + return __reset_control_get(dev, id, 0, true, false, false); |
|---|
| 159 | 204 | } |
|---|
| 160 | 205 | |
|---|
| 206 | +/** |
|---|
| 207 | + * reset_control_get_optional_exclusive - optional reset_control_get_exclusive() |
|---|
| 208 | + * @dev: device to be reset by the controller |
|---|
| 209 | + * @id: reset line name |
|---|
| 210 | + * |
|---|
| 211 | + * Optional variant of reset_control_get_exclusive(). If the requested reset |
|---|
| 212 | + * is not specified in the device tree, this function returns NULL instead of |
|---|
| 213 | + * an error. |
|---|
| 214 | + * |
|---|
| 215 | + * See reset_control_get_exclusive() for more information. |
|---|
| 216 | + */ |
|---|
| 161 | 217 | static inline struct reset_control *reset_control_get_optional_exclusive( |
|---|
| 162 | 218 | struct device *dev, const char *id) |
|---|
| 163 | 219 | { |
|---|
| 164 | | - return __reset_control_get(dev, id, 0, false, true); |
|---|
| 220 | + return __reset_control_get(dev, id, 0, false, true, true); |
|---|
| 165 | 221 | } |
|---|
| 166 | 222 | |
|---|
| 223 | +/** |
|---|
| 224 | + * reset_control_get_optional_shared - optional reset_control_get_shared() |
|---|
| 225 | + * @dev: device to be reset by the controller |
|---|
| 226 | + * @id: reset line name |
|---|
| 227 | + * |
|---|
| 228 | + * Optional variant of reset_control_get_shared(). If the requested reset |
|---|
| 229 | + * is not specified in the device tree, this function returns NULL instead of |
|---|
| 230 | + * an error. |
|---|
| 231 | + * |
|---|
| 232 | + * See reset_control_get_shared() for more information. |
|---|
| 233 | + */ |
|---|
| 167 | 234 | static inline struct reset_control *reset_control_get_optional_shared( |
|---|
| 168 | 235 | struct device *dev, const char *id) |
|---|
| 169 | 236 | { |
|---|
| 170 | | - return __reset_control_get(dev, id, 0, true, true); |
|---|
| 237 | + return __reset_control_get(dev, id, 0, true, true, false); |
|---|
| 171 | 238 | } |
|---|
| 172 | 239 | |
|---|
| 173 | 240 | /** |
|---|
| .. | .. |
|---|
| 183 | 250 | static inline struct reset_control *of_reset_control_get_exclusive( |
|---|
| 184 | 251 | struct device_node *node, const char *id) |
|---|
| 185 | 252 | { |
|---|
| 186 | | - return __of_reset_control_get(node, id, 0, false, false); |
|---|
| 253 | + return __of_reset_control_get(node, id, 0, false, false, true); |
|---|
| 187 | 254 | } |
|---|
| 188 | 255 | |
|---|
| 189 | 256 | /** |
|---|
| 190 | | - * of_reset_control_get_shared - Lookup and obtain an shared reference |
|---|
| 257 | + * of_reset_control_get_shared - Lookup and obtain a shared reference |
|---|
| 191 | 258 | * to a reset controller. |
|---|
| 192 | 259 | * @node: device to be reset by the controller |
|---|
| 193 | 260 | * @id: reset line name |
|---|
| .. | .. |
|---|
| 208 | 275 | static inline struct reset_control *of_reset_control_get_shared( |
|---|
| 209 | 276 | struct device_node *node, const char *id) |
|---|
| 210 | 277 | { |
|---|
| 211 | | - return __of_reset_control_get(node, id, 0, true, false); |
|---|
| 278 | + return __of_reset_control_get(node, id, 0, true, false, false); |
|---|
| 212 | 279 | } |
|---|
| 213 | 280 | |
|---|
| 214 | 281 | /** |
|---|
| .. | .. |
|---|
| 225 | 292 | static inline struct reset_control *of_reset_control_get_exclusive_by_index( |
|---|
| 226 | 293 | struct device_node *node, int index) |
|---|
| 227 | 294 | { |
|---|
| 228 | | - return __of_reset_control_get(node, NULL, index, false, false); |
|---|
| 295 | + return __of_reset_control_get(node, NULL, index, false, false, true); |
|---|
| 229 | 296 | } |
|---|
| 230 | 297 | |
|---|
| 231 | 298 | /** |
|---|
| 232 | | - * of_reset_control_get_shared_by_index - Lookup and obtain an shared |
|---|
| 299 | + * of_reset_control_get_shared_by_index - Lookup and obtain a shared |
|---|
| 233 | 300 | * reference to a reset controller |
|---|
| 234 | 301 | * by index. |
|---|
| 235 | 302 | * @node: device to be reset by the controller |
|---|
| .. | .. |
|---|
| 253 | 320 | static inline struct reset_control *of_reset_control_get_shared_by_index( |
|---|
| 254 | 321 | struct device_node *node, int index) |
|---|
| 255 | 322 | { |
|---|
| 256 | | - return __of_reset_control_get(node, NULL, index, true, false); |
|---|
| 323 | + return __of_reset_control_get(node, NULL, index, true, false, false); |
|---|
| 257 | 324 | } |
|---|
| 258 | 325 | |
|---|
| 259 | 326 | /** |
|---|
| .. | .. |
|---|
| 272 | 339 | __must_check devm_reset_control_get_exclusive(struct device *dev, |
|---|
| 273 | 340 | const char *id) |
|---|
| 274 | 341 | { |
|---|
| 275 | | - return __devm_reset_control_get(dev, id, 0, false, false); |
|---|
| 342 | + return __devm_reset_control_get(dev, id, 0, false, false, true); |
|---|
| 343 | +} |
|---|
| 344 | + |
|---|
| 345 | +/** |
|---|
| 346 | + * devm_reset_control_get_exclusive_released - resource managed |
|---|
| 347 | + * reset_control_get_exclusive_released() |
|---|
| 348 | + * @dev: device to be reset by the controller |
|---|
| 349 | + * @id: reset line name |
|---|
| 350 | + * |
|---|
| 351 | + * Managed reset_control_get_exclusive_released(). For reset controllers |
|---|
| 352 | + * returned from this function, reset_control_put() is called automatically on |
|---|
| 353 | + * driver detach. |
|---|
| 354 | + * |
|---|
| 355 | + * See reset_control_get_exclusive_released() for more information. |
|---|
| 356 | + */ |
|---|
| 357 | +static inline struct reset_control * |
|---|
| 358 | +__must_check devm_reset_control_get_exclusive_released(struct device *dev, |
|---|
| 359 | + const char *id) |
|---|
| 360 | +{ |
|---|
| 361 | + return __devm_reset_control_get(dev, id, 0, false, false, false); |
|---|
| 276 | 362 | } |
|---|
| 277 | 363 | |
|---|
| 278 | 364 | /** |
|---|
| .. | .. |
|---|
| 287 | 373 | static inline struct reset_control *devm_reset_control_get_shared( |
|---|
| 288 | 374 | struct device *dev, const char *id) |
|---|
| 289 | 375 | { |
|---|
| 290 | | - return __devm_reset_control_get(dev, id, 0, true, false); |
|---|
| 376 | + return __devm_reset_control_get(dev, id, 0, true, false, false); |
|---|
| 291 | 377 | } |
|---|
| 292 | 378 | |
|---|
| 379 | +/** |
|---|
| 380 | + * devm_reset_control_get_optional_exclusive - resource managed |
|---|
| 381 | + * reset_control_get_optional_exclusive() |
|---|
| 382 | + * @dev: device to be reset by the controller |
|---|
| 383 | + * @id: reset line name |
|---|
| 384 | + * |
|---|
| 385 | + * Managed reset_control_get_optional_exclusive(). For reset controllers |
|---|
| 386 | + * returned from this function, reset_control_put() is called automatically on |
|---|
| 387 | + * driver detach. |
|---|
| 388 | + * |
|---|
| 389 | + * See reset_control_get_optional_exclusive() for more information. |
|---|
| 390 | + */ |
|---|
| 293 | 391 | static inline struct reset_control *devm_reset_control_get_optional_exclusive( |
|---|
| 294 | 392 | struct device *dev, const char *id) |
|---|
| 295 | 393 | { |
|---|
| 296 | | - return __devm_reset_control_get(dev, id, 0, false, true); |
|---|
| 394 | + return __devm_reset_control_get(dev, id, 0, false, true, true); |
|---|
| 297 | 395 | } |
|---|
| 298 | 396 | |
|---|
| 397 | +/** |
|---|
| 398 | + * devm_reset_control_get_optional_shared - resource managed |
|---|
| 399 | + * reset_control_get_optional_shared() |
|---|
| 400 | + * @dev: device to be reset by the controller |
|---|
| 401 | + * @id: reset line name |
|---|
| 402 | + * |
|---|
| 403 | + * Managed reset_control_get_optional_shared(). For reset controllers returned |
|---|
| 404 | + * from this function, reset_control_put() is called automatically on driver |
|---|
| 405 | + * detach. |
|---|
| 406 | + * |
|---|
| 407 | + * See reset_control_get_optional_shared() for more information. |
|---|
| 408 | + */ |
|---|
| 299 | 409 | static inline struct reset_control *devm_reset_control_get_optional_shared( |
|---|
| 300 | 410 | struct device *dev, const char *id) |
|---|
| 301 | 411 | { |
|---|
| 302 | | - return __devm_reset_control_get(dev, id, 0, true, true); |
|---|
| 412 | + return __devm_reset_control_get(dev, id, 0, true, true, false); |
|---|
| 303 | 413 | } |
|---|
| 304 | 414 | |
|---|
| 305 | 415 | /** |
|---|
| .. | .. |
|---|
| 317 | 427 | static inline struct reset_control * |
|---|
| 318 | 428 | devm_reset_control_get_exclusive_by_index(struct device *dev, int index) |
|---|
| 319 | 429 | { |
|---|
| 320 | | - return __devm_reset_control_get(dev, NULL, index, false, false); |
|---|
| 430 | + return __devm_reset_control_get(dev, NULL, index, false, false, true); |
|---|
| 321 | 431 | } |
|---|
| 322 | 432 | |
|---|
| 323 | 433 | /** |
|---|
| 324 | 434 | * devm_reset_control_get_shared_by_index - resource managed |
|---|
| 325 | | - * reset_control_get_shared |
|---|
| 435 | + * reset_control_get_shared |
|---|
| 326 | 436 | * @dev: device to be reset by the controller |
|---|
| 327 | 437 | * @index: index of the reset controller |
|---|
| 328 | 438 | * |
|---|
| .. | .. |
|---|
| 333 | 443 | static inline struct reset_control * |
|---|
| 334 | 444 | devm_reset_control_get_shared_by_index(struct device *dev, int index) |
|---|
| 335 | 445 | { |
|---|
| 336 | | - return __devm_reset_control_get(dev, NULL, index, true, false); |
|---|
| 446 | + return __devm_reset_control_get(dev, NULL, index, true, false, false); |
|---|
| 337 | 447 | } |
|---|
| 338 | 448 | |
|---|
| 339 | 449 | /* |
|---|
| .. | .. |
|---|
| 405 | 515 | static inline struct reset_control * |
|---|
| 406 | 516 | of_reset_control_array_get_exclusive(struct device_node *node) |
|---|
| 407 | 517 | { |
|---|
| 408 | | - return of_reset_control_array_get(node, false, false); |
|---|
| 518 | + return of_reset_control_array_get(node, false, false, true); |
|---|
| 519 | +} |
|---|
| 520 | + |
|---|
| 521 | +static inline struct reset_control * |
|---|
| 522 | +of_reset_control_array_get_exclusive_released(struct device_node *node) |
|---|
| 523 | +{ |
|---|
| 524 | + return of_reset_control_array_get(node, false, false, false); |
|---|
| 409 | 525 | } |
|---|
| 410 | 526 | |
|---|
| 411 | 527 | static inline struct reset_control * |
|---|
| 412 | 528 | of_reset_control_array_get_shared(struct device_node *node) |
|---|
| 413 | 529 | { |
|---|
| 414 | | - return of_reset_control_array_get(node, true, false); |
|---|
| 530 | + return of_reset_control_array_get(node, true, false, true); |
|---|
| 415 | 531 | } |
|---|
| 416 | 532 | |
|---|
| 417 | 533 | static inline struct reset_control * |
|---|
| 418 | 534 | of_reset_control_array_get_optional_exclusive(struct device_node *node) |
|---|
| 419 | 535 | { |
|---|
| 420 | | - return of_reset_control_array_get(node, false, true); |
|---|
| 536 | + return of_reset_control_array_get(node, false, true, true); |
|---|
| 421 | 537 | } |
|---|
| 422 | 538 | |
|---|
| 423 | 539 | static inline struct reset_control * |
|---|
| 424 | 540 | of_reset_control_array_get_optional_shared(struct device_node *node) |
|---|
| 425 | 541 | { |
|---|
| 426 | | - return of_reset_control_array_get(node, true, true); |
|---|
| 542 | + return of_reset_control_array_get(node, true, true, true); |
|---|
| 427 | 543 | } |
|---|
| 428 | 544 | #endif |
|---|