1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_RESET_H_ 3 #define _LINUX_RESET_H_ 4 5 #include <linux/err.h> 6 #include <linux/errno.h> 7 #include <linux/types.h> 8 9 struct device; 10 struct device_node; 11 struct reset_control; 12 13 /** 14 * struct reset_control_bulk_data - Data used for bulk reset control operations. 15 * 16 * @id: reset control consumer ID 17 * @rstc: struct reset_control * to store the associated reset control 18 * 19 * The reset APIs provide a series of reset_control_bulk_*() API calls as 20 * a convenience to consumers which require multiple reset controls. 21 * This structure is used to manage data for these calls. 22 */ 23 struct reset_control_bulk_data { 24 const char *id; 25 struct reset_control *rstc; 26 }; 27 28 #define RESET_CONTROL_FLAGS_BIT_SHARED BIT(0) /* not exclusive */ 29 #define RESET_CONTROL_FLAGS_BIT_OPTIONAL BIT(1) 30 #define RESET_CONTROL_FLAGS_BIT_ACQUIRED BIT(2) /* iff exclusive, not released */ 31 #define RESET_CONTROL_FLAGS_BIT_DEASSERTED BIT(3) 32 33 /** 34 * enum reset_control_flags - Flags that can be passed to the reset_control_get functions 35 * to determine the type of reset control. 36 * These values cannot be OR'd. 37 * 38 * @RESET_CONTROL_EXCLUSIVE: exclusive, acquired, 39 * @RESET_CONTROL_EXCLUSIVE_DEASSERTED: exclusive, acquired, deasserted 40 * @RESET_CONTROL_EXCLUSIVE_RELEASED: exclusive, released, 41 * @RESET_CONTROL_SHARED: shared 42 * @RESET_CONTROL_SHARED_DEASSERTED: shared, deasserted 43 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE: optional, exclusive, acquired 44 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED: optional, exclusive, acquired, deasserted 45 * @RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED: optional, exclusive, released 46 * @RESET_CONTROL_OPTIONAL_SHARED: optional, shared 47 * @RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED: optional, shared, deasserted 48 */ 49 enum reset_control_flags { 50 RESET_CONTROL_EXCLUSIVE = RESET_CONTROL_FLAGS_BIT_ACQUIRED, 51 RESET_CONTROL_EXCLUSIVE_DEASSERTED = RESET_CONTROL_FLAGS_BIT_ACQUIRED | 52 RESET_CONTROL_FLAGS_BIT_DEASSERTED, 53 RESET_CONTROL_EXCLUSIVE_RELEASED = 0, 54 RESET_CONTROL_SHARED = RESET_CONTROL_FLAGS_BIT_SHARED, 55 RESET_CONTROL_SHARED_DEASSERTED = RESET_CONTROL_FLAGS_BIT_SHARED | 56 RESET_CONTROL_FLAGS_BIT_DEASSERTED, 57 RESET_CONTROL_OPTIONAL_EXCLUSIVE = RESET_CONTROL_FLAGS_BIT_OPTIONAL | 58 RESET_CONTROL_FLAGS_BIT_ACQUIRED, 59 RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED = RESET_CONTROL_FLAGS_BIT_OPTIONAL | 60 RESET_CONTROL_FLAGS_BIT_ACQUIRED | 61 RESET_CONTROL_FLAGS_BIT_DEASSERTED, 62 RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED = RESET_CONTROL_FLAGS_BIT_OPTIONAL, 63 RESET_CONTROL_OPTIONAL_SHARED = RESET_CONTROL_FLAGS_BIT_OPTIONAL | 64 RESET_CONTROL_FLAGS_BIT_SHARED, 65 RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED = RESET_CONTROL_FLAGS_BIT_OPTIONAL | 66 RESET_CONTROL_FLAGS_BIT_SHARED | 67 RESET_CONTROL_FLAGS_BIT_DEASSERTED, 68 }; 69 70 #ifdef CONFIG_RESET_CONTROLLER 71 72 int reset_control_reset(struct reset_control *rstc); 73 int reset_control_rearm(struct reset_control *rstc); 74 int reset_control_assert(struct reset_control *rstc); 75 int reset_control_deassert(struct reset_control *rstc); 76 int reset_control_status(struct reset_control *rstc); 77 int reset_control_acquire(struct reset_control *rstc); 78 void reset_control_release(struct reset_control *rstc); 79 80 int reset_control_bulk_reset(int num_rstcs, struct reset_control_bulk_data *rstcs); 81 int reset_control_bulk_assert(int num_rstcs, struct reset_control_bulk_data *rstcs); 82 int reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *rstcs); 83 int reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs); 84 void reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs); 85 86 struct reset_control *__of_reset_control_get(struct device_node *node, 87 const char *id, int index, enum reset_control_flags flags); 88 struct reset_control *__reset_control_get(struct device *dev, const char *id, 89 int index, enum reset_control_flags flags); 90 void reset_control_put(struct reset_control *rstc); 91 int __reset_control_bulk_get(struct device *dev, int num_rstcs, 92 struct reset_control_bulk_data *rstcs, 93 enum reset_control_flags flags); 94 void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs); 95 96 int __device_reset(struct device *dev, bool optional); 97 struct reset_control *__devm_reset_control_get(struct device *dev, 98 const char *id, int index, enum reset_control_flags flags); 99 int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs, 100 struct reset_control_bulk_data *rstcs, 101 enum reset_control_flags flags); 102 103 struct reset_control *devm_reset_control_array_get(struct device *dev, 104 enum reset_control_flags flags); 105 struct reset_control *of_reset_control_array_get(struct device_node *np, enum reset_control_flags); 106 107 int reset_control_get_count(struct device *dev); 108 109 #else 110 111 static inline int reset_control_reset(struct reset_control *rstc) 112 { 113 return 0; 114 } 115 116 static inline int reset_control_rearm(struct reset_control *rstc) 117 { 118 return 0; 119 } 120 121 static inline int reset_control_assert(struct reset_control *rstc) 122 { 123 return 0; 124 } 125 126 static inline int reset_control_deassert(struct reset_control *rstc) 127 { 128 return 0; 129 } 130 131 static inline int reset_control_status(struct reset_control *rstc) 132 { 133 return 0; 134 } 135 136 static inline int reset_control_acquire(struct reset_control *rstc) 137 { 138 return 0; 139 } 140 141 static inline void reset_control_release(struct reset_control *rstc) 142 { 143 } 144 145 static inline void reset_control_put(struct reset_control *rstc) 146 { 147 } 148 149 static inline int __device_reset(struct device *dev, bool optional) 150 { 151 return optional ? 0 : -ENOTSUPP; 152 } 153 154 static inline struct reset_control *__of_reset_control_get( 155 struct device_node *node, 156 const char *id, int index, enum reset_control_flags flags) 157 { 158 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; 159 160 return optional ? NULL : ERR_PTR(-ENOTSUPP); 161 } 162 163 static inline struct reset_control *__reset_control_get( 164 struct device *dev, const char *id, 165 int index, enum reset_control_flags flags) 166 { 167 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; 168 169 return optional ? NULL : ERR_PTR(-ENOTSUPP); 170 } 171 172 static inline int 173 reset_control_bulk_reset(int num_rstcs, struct reset_control_bulk_data *rstcs) 174 { 175 return 0; 176 } 177 178 static inline int 179 reset_control_bulk_assert(int num_rstcs, struct reset_control_bulk_data *rstcs) 180 { 181 return 0; 182 } 183 184 static inline int 185 reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *rstcs) 186 { 187 return 0; 188 } 189 190 static inline int 191 reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs) 192 { 193 return 0; 194 } 195 196 static inline void 197 reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs) 198 { 199 } 200 201 static inline int 202 __reset_control_bulk_get(struct device *dev, int num_rstcs, 203 struct reset_control_bulk_data *rstcs, 204 enum reset_control_flags flags) 205 { 206 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; 207 208 return optional ? 0 : -EOPNOTSUPP; 209 } 210 211 static inline void 212 reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs) 213 { 214 } 215 216 static inline struct reset_control *__devm_reset_control_get( 217 struct device *dev, const char *id, 218 int index, enum reset_control_flags flags) 219 { 220 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; 221 222 return optional ? NULL : ERR_PTR(-ENOTSUPP); 223 } 224 225 static inline int 226 __devm_reset_control_bulk_get(struct device *dev, int num_rstcs, 227 struct reset_control_bulk_data *rstcs, 228 enum reset_control_flags flags) 229 { 230 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; 231 232 return optional ? 0 : -EOPNOTSUPP; 233 } 234 235 static inline struct reset_control * 236 devm_reset_control_array_get(struct device *dev, enum reset_control_flags flags) 237 { 238 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; 239 240 return optional ? NULL : ERR_PTR(-ENOTSUPP); 241 } 242 243 static inline struct reset_control * 244 of_reset_control_array_get(struct device_node *np, enum reset_control_flags flags) 245 { 246 bool optional = flags & RESET_CONTROL_FLAGS_BIT_OPTIONAL; 247 248 return optional ? NULL : ERR_PTR(-ENOTSUPP); 249 } 250 251 static inline int reset_control_get_count(struct device *dev) 252 { 253 return -ENOENT; 254 } 255 256 #endif /* CONFIG_RESET_CONTROLLER */ 257 258 static inline int __must_check device_reset(struct device *dev) 259 { 260 return __device_reset(dev, false); 261 } 262 263 static inline int device_reset_optional(struct device *dev) 264 { 265 return __device_reset(dev, true); 266 } 267 268 /** 269 * reset_control_get_exclusive - Lookup and obtain an exclusive reference 270 * to a reset controller. 271 * @dev: device to be reset by the controller 272 * @id: reset line name 273 * 274 * Returns a struct reset_control or IS_ERR() condition containing errno. 275 * If this function is called more than once for the same reset_control it will 276 * return -EBUSY. 277 * 278 * See reset_control_get_shared() for details on shared references to 279 * reset-controls. 280 * 281 * Use of id names is optional. 282 */ 283 static inline struct reset_control * 284 __must_check reset_control_get_exclusive(struct device *dev, const char *id) 285 { 286 return __reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE); 287 } 288 289 /** 290 * reset_control_bulk_get_exclusive - Lookup and obtain exclusive references to 291 * multiple reset controllers. 292 * @dev: device to be reset by the controller 293 * @num_rstcs: number of entries in rstcs array 294 * @rstcs: array of struct reset_control_bulk_data with reset line names set 295 * 296 * Fills the rstcs array with pointers to exclusive reset controls and 297 * returns 0, or an IS_ERR() condition containing errno. 298 */ 299 static inline int __must_check 300 reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs, 301 struct reset_control_bulk_data *rstcs) 302 { 303 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_EXCLUSIVE); 304 } 305 306 /** 307 * reset_control_get_exclusive_released - Lookup and obtain a temoprarily 308 * exclusive reference to a reset 309 * controller. 310 * @dev: device to be reset by the controller 311 * @id: reset line name 312 * 313 * Returns a struct reset_control or IS_ERR() condition containing errno. 314 * reset-controls returned by this function must be acquired via 315 * reset_control_acquire() before they can be used and should be released 316 * via reset_control_release() afterwards. 317 * 318 * Use of id names is optional. 319 */ 320 static inline struct reset_control * 321 __must_check reset_control_get_exclusive_released(struct device *dev, 322 const char *id) 323 { 324 return __reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_RELEASED); 325 } 326 327 /** 328 * reset_control_bulk_get_exclusive_released - Lookup and obtain temporarily 329 * exclusive references to multiple reset 330 * controllers. 331 * @dev: device to be reset by the controller 332 * @num_rstcs: number of entries in rstcs array 333 * @rstcs: array of struct reset_control_bulk_data with reset line names set 334 * 335 * Fills the rstcs array with pointers to exclusive reset controls and 336 * returns 0, or an IS_ERR() condition containing errno. 337 * reset-controls returned by this function must be acquired via 338 * reset_control_bulk_acquire() before they can be used and should be released 339 * via reset_control_bulk_release() afterwards. 340 */ 341 static inline int __must_check 342 reset_control_bulk_get_exclusive_released(struct device *dev, int num_rstcs, 343 struct reset_control_bulk_data *rstcs) 344 { 345 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_EXCLUSIVE_RELEASED); 346 } 347 348 /** 349 * reset_control_bulk_get_optional_exclusive_released - Lookup and obtain optional 350 * temporarily exclusive references to multiple 351 * reset controllers. 352 * @dev: device to be reset by the controller 353 * @num_rstcs: number of entries in rstcs array 354 * @rstcs: array of struct reset_control_bulk_data with reset line names set 355 * 356 * Optional variant of reset_control_bulk_get_exclusive_released(). If the 357 * requested reset is not specified in the device tree, this function returns 0 358 * instead of an error and missing rtsc is set to NULL. 359 * 360 * See reset_control_bulk_get_exclusive_released() for more information. 361 */ 362 static inline int __must_check 363 reset_control_bulk_get_optional_exclusive_released(struct device *dev, int num_rstcs, 364 struct reset_control_bulk_data *rstcs) 365 { 366 return __reset_control_bulk_get(dev, num_rstcs, rstcs, 367 RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED); 368 } 369 370 /** 371 * reset_control_get_shared - Lookup and obtain a shared reference to a 372 * reset controller. 373 * @dev: device to be reset by the controller 374 * @id: reset line name 375 * 376 * Returns a struct reset_control or IS_ERR() condition containing errno. 377 * This function is intended for use with reset-controls which are shared 378 * between hardware blocks. 379 * 380 * When a reset-control is shared, the behavior of reset_control_assert / 381 * deassert is changed, the reset-core will keep track of a deassert_count 382 * and only (re-)assert the reset after reset_control_assert has been called 383 * as many times as reset_control_deassert was called. Also see the remark 384 * about shared reset-controls in the reset_control_assert docs. 385 * 386 * Calling reset_control_assert without first calling reset_control_deassert 387 * is not allowed on a shared reset control. Calling reset_control_reset is 388 * also not allowed on a shared reset control. 389 * 390 * Use of id names is optional. 391 */ 392 static inline struct reset_control *reset_control_get_shared( 393 struct device *dev, const char *id) 394 { 395 return __reset_control_get(dev, id, 0, RESET_CONTROL_SHARED); 396 } 397 398 /** 399 * reset_control_bulk_get_shared - Lookup and obtain shared references to 400 * multiple reset controllers. 401 * @dev: device to be reset by the controller 402 * @num_rstcs: number of entries in rstcs array 403 * @rstcs: array of struct reset_control_bulk_data with reset line names set 404 * 405 * Fills the rstcs array with pointers to shared reset controls and 406 * returns 0, or an IS_ERR() condition containing errno. 407 */ 408 static inline int __must_check 409 reset_control_bulk_get_shared(struct device *dev, int num_rstcs, 410 struct reset_control_bulk_data *rstcs) 411 { 412 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_SHARED); 413 } 414 415 /** 416 * reset_control_get_optional_exclusive - optional reset_control_get_exclusive() 417 * @dev: device to be reset by the controller 418 * @id: reset line name 419 * 420 * Optional variant of reset_control_get_exclusive(). If the requested reset 421 * is not specified in the device tree, this function returns NULL instead of 422 * an error. 423 * 424 * See reset_control_get_exclusive() for more information. 425 */ 426 static inline struct reset_control *reset_control_get_optional_exclusive( 427 struct device *dev, const char *id) 428 { 429 return __reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE); 430 } 431 432 /** 433 * reset_control_bulk_get_optional_exclusive - optional 434 * reset_control_bulk_get_exclusive() 435 * @dev: device to be reset by the controller 436 * @num_rstcs: number of entries in rstcs array 437 * @rstcs: array of struct reset_control_bulk_data with reset line names set 438 * 439 * Optional variant of reset_control_bulk_get_exclusive(). If any of the 440 * requested resets are not specified in the device tree, this function sets 441 * them to NULL instead of returning an error. 442 * 443 * See reset_control_bulk_get_exclusive() for more information. 444 */ 445 static inline int __must_check 446 reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs, 447 struct reset_control_bulk_data *rstcs) 448 { 449 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTIONAL_EXCLUSIVE); 450 } 451 452 /** 453 * reset_control_get_optional_shared - optional reset_control_get_shared() 454 * @dev: device to be reset by the controller 455 * @id: reset line name 456 * 457 * Optional variant of reset_control_get_shared(). If the requested reset 458 * is not specified in the device tree, this function returns NULL instead of 459 * an error. 460 * 461 * See reset_control_get_shared() for more information. 462 */ 463 static inline struct reset_control *reset_control_get_optional_shared( 464 struct device *dev, const char *id) 465 { 466 return __reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED); 467 } 468 469 /** 470 * reset_control_bulk_get_optional_shared - optional 471 * reset_control_bulk_get_shared() 472 * @dev: device to be reset by the controller 473 * @num_rstcs: number of entries in rstcs array 474 * @rstcs: array of struct reset_control_bulk_data with reset line names set 475 * 476 * Optional variant of reset_control_bulk_get_shared(). If the requested resets 477 * are not specified in the device tree, this function sets them to NULL 478 * instead of returning an error. 479 * 480 * See reset_control_bulk_get_shared() for more information. 481 */ 482 static inline int __must_check 483 reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs, 484 struct reset_control_bulk_data *rstcs) 485 { 486 return __reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTIONAL_SHARED); 487 } 488 489 /** 490 * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference 491 * to a reset controller. 492 * @node: device to be reset by the controller 493 * @id: reset line name 494 * 495 * Returns a struct reset_control or IS_ERR() condition containing errno. 496 * 497 * Use of id names is optional. 498 */ 499 static inline struct reset_control *of_reset_control_get_exclusive( 500 struct device_node *node, const char *id) 501 { 502 return __of_reset_control_get(node, id, 0, RESET_CONTROL_EXCLUSIVE); 503 } 504 505 /** 506 * of_reset_control_get_optional_exclusive - Lookup and obtain an optional exclusive 507 * reference to a reset controller. 508 * @node: device to be reset by the controller 509 * @id: reset line name 510 * 511 * Optional variant of of_reset_control_get_exclusive(). If the requested reset 512 * is not specified in the device tree, this function returns NULL instead of 513 * an error. 514 * 515 * Returns a struct reset_control or IS_ERR() condition containing errno. 516 * 517 * Use of id names is optional. 518 */ 519 static inline struct reset_control *of_reset_control_get_optional_exclusive( 520 struct device_node *node, const char *id) 521 { 522 return __of_reset_control_get(node, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE); 523 } 524 525 /** 526 * of_reset_control_get_shared - Lookup and obtain a shared reference 527 * to a reset controller. 528 * @node: device to be reset by the controller 529 * @id: reset line name 530 * 531 * When a reset-control is shared, the behavior of reset_control_assert / 532 * deassert is changed, the reset-core will keep track of a deassert_count 533 * and only (re-)assert the reset after reset_control_assert has been called 534 * as many times as reset_control_deassert was called. Also see the remark 535 * about shared reset-controls in the reset_control_assert docs. 536 * 537 * Calling reset_control_assert without first calling reset_control_deassert 538 * is not allowed on a shared reset control. Calling reset_control_reset is 539 * also not allowed on a shared reset control. 540 * Returns a struct reset_control or IS_ERR() condition containing errno. 541 * 542 * Use of id names is optional. 543 */ 544 static inline struct reset_control *of_reset_control_get_shared( 545 struct device_node *node, const char *id) 546 { 547 return __of_reset_control_get(node, id, 0, RESET_CONTROL_SHARED); 548 } 549 550 /** 551 * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive 552 * reference to a reset controller 553 * by index. 554 * @node: device to be reset by the controller 555 * @index: index of the reset controller 556 * 557 * This is to be used to perform a list of resets for a device or power domain 558 * in whatever order. Returns a struct reset_control or IS_ERR() condition 559 * containing errno. 560 */ 561 static inline struct reset_control *of_reset_control_get_exclusive_by_index( 562 struct device_node *node, int index) 563 { 564 return __of_reset_control_get(node, NULL, index, RESET_CONTROL_EXCLUSIVE); 565 } 566 567 /** 568 * of_reset_control_get_shared_by_index - Lookup and obtain a shared 569 * reference to a reset controller 570 * by index. 571 * @node: device to be reset by the controller 572 * @index: index of the reset controller 573 * 574 * When a reset-control is shared, the behavior of reset_control_assert / 575 * deassert is changed, the reset-core will keep track of a deassert_count 576 * and only (re-)assert the reset after reset_control_assert has been called 577 * as many times as reset_control_deassert was called. Also see the remark 578 * about shared reset-controls in the reset_control_assert docs. 579 * 580 * Calling reset_control_assert without first calling reset_control_deassert 581 * is not allowed on a shared reset control. Calling reset_control_reset is 582 * also not allowed on a shared reset control. 583 * Returns a struct reset_control or IS_ERR() condition containing errno. 584 * 585 * This is to be used to perform a list of resets for a device or power domain 586 * in whatever order. Returns a struct reset_control or IS_ERR() condition 587 * containing errno. 588 */ 589 static inline struct reset_control *of_reset_control_get_shared_by_index( 590 struct device_node *node, int index) 591 { 592 return __of_reset_control_get(node, NULL, index, RESET_CONTROL_SHARED); 593 } 594 595 /** 596 * devm_reset_control_get_exclusive - resource managed 597 * reset_control_get_exclusive() 598 * @dev: device to be reset by the controller 599 * @id: reset line name 600 * 601 * Managed reset_control_get_exclusive(). For reset controllers returned 602 * from this function, reset_control_put() is called automatically on driver 603 * detach. 604 * 605 * See reset_control_get_exclusive() for more information. 606 */ 607 static inline struct reset_control * 608 __must_check devm_reset_control_get_exclusive(struct device *dev, 609 const char *id) 610 { 611 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE); 612 } 613 614 /** 615 * devm_reset_control_get_exclusive_deasserted - resource managed 616 * reset_control_get_exclusive() + 617 * reset_control_deassert() 618 * @dev: device to be reset by the controller 619 * @id: reset line name 620 * 621 * Managed reset_control_get_exclusive() + reset_control_deassert(). For reset 622 * controllers returned from this function, reset_control_assert() + 623 * reset_control_put() is called automatically on driver detach. 624 * 625 * See reset_control_get_exclusive() for more information. 626 */ 627 static inline struct reset_control * __must_check 628 devm_reset_control_get_exclusive_deasserted(struct device *dev, const char *id) 629 { 630 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_DEASSERTED); 631 } 632 633 /** 634 * devm_reset_control_bulk_get_exclusive - resource managed 635 * reset_control_bulk_get_exclusive() 636 * @dev: device to be reset by the controller 637 * @num_rstcs: number of entries in rstcs array 638 * @rstcs: array of struct reset_control_bulk_data with reset line names set 639 * 640 * Managed reset_control_bulk_get_exclusive(). For reset controllers returned 641 * from this function, reset_control_put() is called automatically on driver 642 * detach. 643 * 644 * See reset_control_bulk_get_exclusive() for more information. 645 */ 646 static inline int __must_check 647 devm_reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs, 648 struct reset_control_bulk_data *rstcs) 649 { 650 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, 651 RESET_CONTROL_EXCLUSIVE); 652 } 653 654 /** 655 * devm_reset_control_get_exclusive_released - resource managed 656 * reset_control_get_exclusive_released() 657 * @dev: device to be reset by the controller 658 * @id: reset line name 659 * 660 * Managed reset_control_get_exclusive_released(). For reset controllers 661 * returned from this function, reset_control_put() is called automatically on 662 * driver detach. 663 * 664 * See reset_control_get_exclusive_released() for more information. 665 */ 666 static inline struct reset_control * 667 __must_check devm_reset_control_get_exclusive_released(struct device *dev, 668 const char *id) 669 { 670 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_EXCLUSIVE_RELEASED); 671 } 672 673 /** 674 * devm_reset_control_bulk_get_exclusive_released - resource managed 675 * reset_control_bulk_get_exclusive_released() 676 * @dev: device to be reset by the controller 677 * @num_rstcs: number of entries in rstcs array 678 * @rstcs: array of struct reset_control_bulk_data with reset line names set 679 * 680 * Managed reset_control_bulk_get_exclusive_released(). For reset controllers 681 * returned from this function, reset_control_put() is called automatically on 682 * driver detach. 683 * 684 * See reset_control_bulk_get_exclusive_released() for more information. 685 */ 686 static inline int __must_check 687 devm_reset_control_bulk_get_exclusive_released(struct device *dev, int num_rstcs, 688 struct reset_control_bulk_data *rstcs) 689 { 690 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, 691 RESET_CONTROL_EXCLUSIVE_RELEASED); 692 } 693 694 /** 695 * devm_reset_control_get_optional_exclusive_released - resource managed 696 * reset_control_get_optional_exclusive_released() 697 * @dev: device to be reset by the controller 698 * @id: reset line name 699 * 700 * Managed-and-optional variant of reset_control_get_exclusive_released(). For 701 * reset controllers returned from this function, reset_control_put() is called 702 * automatically on driver detach. 703 * 704 * See reset_control_get_exclusive_released() for more information. 705 */ 706 static inline struct reset_control * 707 __must_check devm_reset_control_get_optional_exclusive_released(struct device *dev, 708 const char *id) 709 { 710 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED); 711 } 712 713 /** 714 * devm_reset_control_bulk_get_optional_exclusive_released - resource managed 715 * reset_control_bulk_optional_get_exclusive_released() 716 * @dev: device to be reset by the controller 717 * @num_rstcs: number of entries in rstcs array 718 * @rstcs: array of struct reset_control_bulk_data with reset line names set 719 * 720 * Managed reset_control_bulk_optional_get_exclusive_released(). For reset 721 * controllers returned from this function, reset_control_put() is called 722 * automatically on driver detach. 723 * 724 * See reset_control_bulk_optional_get_exclusive_released() for more information. 725 */ 726 static inline int __must_check 727 devm_reset_control_bulk_get_optional_exclusive_released(struct device *dev, int num_rstcs, 728 struct reset_control_bulk_data *rstcs) 729 { 730 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, 731 RESET_CONTROL_OPTIONAL_EXCLUSIVE_RELEASED); 732 } 733 734 /** 735 * devm_reset_control_get_shared - resource managed reset_control_get_shared() 736 * @dev: device to be reset by the controller 737 * @id: reset line name 738 * 739 * Managed reset_control_get_shared(). For reset controllers returned from 740 * this function, reset_control_put() is called automatically on driver detach. 741 * See reset_control_get_shared() for more information. 742 */ 743 static inline struct reset_control *devm_reset_control_get_shared( 744 struct device *dev, const char *id) 745 { 746 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_SHARED); 747 } 748 749 /** 750 * devm_reset_control_get_shared_deasserted - resource managed 751 * reset_control_get_shared() + 752 * reset_control_deassert() 753 * @dev: device to be reset by the controller 754 * @id: reset line name 755 * 756 * Managed reset_control_get_shared() + reset_control_deassert(). For reset 757 * controllers returned from this function, reset_control_assert() + 758 * reset_control_put() is called automatically on driver detach. 759 * 760 * See devm_reset_control_get_shared() for more information. 761 */ 762 static inline struct reset_control * __must_check 763 devm_reset_control_get_shared_deasserted(struct device *dev, const char *id) 764 { 765 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_SHARED_DEASSERTED); 766 } 767 768 /** 769 * devm_reset_control_bulk_get_shared - resource managed 770 * reset_control_bulk_get_shared() 771 * @dev: device to be reset by the controller 772 * @num_rstcs: number of entries in rstcs array 773 * @rstcs: array of struct reset_control_bulk_data with reset line names set 774 * 775 * Managed reset_control_bulk_get_shared(). For reset controllers returned 776 * from this function, reset_control_put() is called automatically on driver 777 * detach. 778 * 779 * See reset_control_bulk_get_shared() for more information. 780 */ 781 static inline int __must_check 782 devm_reset_control_bulk_get_shared(struct device *dev, int num_rstcs, 783 struct reset_control_bulk_data *rstcs) 784 { 785 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_SHARED); 786 } 787 788 /** 789 * devm_reset_control_bulk_get_shared_deasserted - resource managed 790 * reset_control_bulk_get_shared() + 791 * reset_control_bulk_deassert() 792 * @dev: device to be reset by the controller 793 * @num_rstcs: number of entries in rstcs array 794 * @rstcs: array of struct reset_control_bulk_data with reset line names set 795 * 796 * Managed reset_control_bulk_get_shared() + reset_control_bulk_deassert(). For 797 * reset controllers returned from this function, reset_control_bulk_assert() + 798 * reset_control_bulk_put() are called automatically on driver detach. 799 * 800 * See devm_reset_control_bulk_get_shared() for more information. 801 */ 802 static inline int __must_check 803 devm_reset_control_bulk_get_shared_deasserted(struct device *dev, int num_rstcs, 804 struct reset_control_bulk_data *rstcs) 805 { 806 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, 807 RESET_CONTROL_SHARED_DEASSERTED); 808 } 809 810 /** 811 * devm_reset_control_get_optional_exclusive - resource managed 812 * reset_control_get_optional_exclusive() 813 * @dev: device to be reset by the controller 814 * @id: reset line name 815 * 816 * Managed reset_control_get_optional_exclusive(). For reset controllers 817 * returned from this function, reset_control_put() is called automatically on 818 * driver detach. 819 * 820 * See reset_control_get_optional_exclusive() for more information. 821 */ 822 static inline struct reset_control *devm_reset_control_get_optional_exclusive( 823 struct device *dev, const char *id) 824 { 825 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE); 826 } 827 828 /** 829 * devm_reset_control_get_optional_exclusive_deasserted - resource managed 830 * reset_control_get_optional_exclusive() + 831 * reset_control_deassert() 832 * @dev: device to be reset by the controller 833 * @id: reset line name 834 * 835 * Managed reset_control_get_optional_exclusive() + reset_control_deassert(). 836 * For reset controllers returned from this function, reset_control_assert() + 837 * reset_control_put() is called automatically on driver detach. 838 * 839 * See devm_reset_control_get_optional_exclusive() for more information. 840 */ 841 static inline struct reset_control * 842 devm_reset_control_get_optional_exclusive_deasserted(struct device *dev, const char *id) 843 { 844 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_EXCLUSIVE_DEASSERTED); 845 } 846 847 /** 848 * devm_reset_control_bulk_get_optional_exclusive - resource managed 849 * reset_control_bulk_get_optional_exclusive() 850 * @dev: device to be reset by the controller 851 * @num_rstcs: number of entries in rstcs array 852 * @rstcs: array of struct reset_control_bulk_data with reset line names set 853 * 854 * Managed reset_control_bulk_get_optional_exclusive(). For reset controllers 855 * returned from this function, reset_control_put() is called automatically on 856 * driver detach. 857 * 858 * See reset_control_bulk_get_optional_exclusive() for more information. 859 */ 860 static inline int __must_check 861 devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs, 862 struct reset_control_bulk_data *rstcs) 863 { 864 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, 865 RESET_CONTROL_OPTIONAL_EXCLUSIVE); 866 } 867 868 /** 869 * devm_reset_control_get_optional_shared - resource managed 870 * reset_control_get_optional_shared() 871 * @dev: device to be reset by the controller 872 * @id: reset line name 873 * 874 * Managed reset_control_get_optional_shared(). For reset controllers returned 875 * from this function, reset_control_put() is called automatically on driver 876 * detach. 877 * 878 * See reset_control_get_optional_shared() for more information. 879 */ 880 static inline struct reset_control *devm_reset_control_get_optional_shared( 881 struct device *dev, const char *id) 882 { 883 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED); 884 } 885 886 /** 887 * devm_reset_control_get_optional_shared_deasserted - resource managed 888 * reset_control_get_optional_shared() + 889 * reset_control_deassert() 890 * @dev: device to be reset by the controller 891 * @id: reset line name 892 * 893 * Managed reset_control_get_optional_shared() + reset_control_deassert(). For 894 * reset controllers returned from this function, reset_control_assert() + 895 * reset_control_put() is called automatically on driver detach. 896 * 897 * See devm_reset_control_get_optional_shared() for more information. 898 */ 899 static inline struct reset_control * 900 devm_reset_control_get_optional_shared_deasserted(struct device *dev, const char *id) 901 { 902 return __devm_reset_control_get(dev, id, 0, RESET_CONTROL_OPTIONAL_SHARED_DEASSERTED); 903 } 904 905 /** 906 * devm_reset_control_bulk_get_optional_shared - resource managed 907 * reset_control_bulk_get_optional_shared() 908 * @dev: device to be reset by the controller 909 * @num_rstcs: number of entries in rstcs array 910 * @rstcs: array of struct reset_control_bulk_data with reset line names set 911 * 912 * Managed reset_control_bulk_get_optional_shared(). For reset controllers 913 * returned from this function, reset_control_put() is called automatically on 914 * driver detach. 915 * 916 * See reset_control_bulk_get_optional_shared() for more information. 917 */ 918 static inline int __must_check 919 devm_reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs, 920 struct reset_control_bulk_data *rstcs) 921 { 922 return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, RESET_CONTROL_OPTIONAL_SHARED); 923 } 924 925 /** 926 * devm_reset_control_get_exclusive_by_index - resource managed 927 * reset_control_get_exclusive() 928 * @dev: device to be reset by the controller 929 * @index: index of the reset controller 930 * 931 * Managed reset_control_get_exclusive(). For reset controllers returned from 932 * this function, reset_control_put() is called automatically on driver 933 * detach. 934 * 935 * See reset_control_get_exclusive() for more information. 936 */ 937 static inline struct reset_control * 938 devm_reset_control_get_exclusive_by_index(struct device *dev, int index) 939 { 940 return __devm_reset_control_get(dev, NULL, index, RESET_CONTROL_EXCLUSIVE); 941 } 942 943 /** 944 * devm_reset_control_get_shared_by_index - resource managed 945 * reset_control_get_shared 946 * @dev: device to be reset by the controller 947 * @index: index of the reset controller 948 * 949 * Managed reset_control_get_shared(). For reset controllers returned from 950 * this function, reset_control_put() is called automatically on driver detach. 951 * See reset_control_get_shared() for more information. 952 */ 953 static inline struct reset_control * 954 devm_reset_control_get_shared_by_index(struct device *dev, int index) 955 { 956 return __devm_reset_control_get(dev, NULL, index, RESET_CONTROL_SHARED); 957 } 958 959 /* 960 * TEMPORARY calls to use during transition: 961 * 962 * of_reset_control_get() => of_reset_control_get_exclusive() 963 * 964 * These inline function calls will be removed once all consumers 965 * have been moved over to the new explicit API. 966 */ 967 static inline struct reset_control *of_reset_control_get( 968 struct device_node *node, const char *id) 969 { 970 return of_reset_control_get_exclusive(node, id); 971 } 972 973 static inline struct reset_control *of_reset_control_get_by_index( 974 struct device_node *node, int index) 975 { 976 return of_reset_control_get_exclusive_by_index(node, index); 977 } 978 979 static inline struct reset_control *devm_reset_control_get( 980 struct device *dev, const char *id) 981 { 982 return devm_reset_control_get_exclusive(dev, id); 983 } 984 985 static inline struct reset_control *devm_reset_control_get_optional( 986 struct device *dev, const char *id) 987 { 988 return devm_reset_control_get_optional_exclusive(dev, id); 989 990 } 991 992 static inline struct reset_control *devm_reset_control_get_by_index( 993 struct device *dev, int index) 994 { 995 return devm_reset_control_get_exclusive_by_index(dev, index); 996 } 997 998 /* 999 * APIs to manage a list of reset controllers 1000 */ 1001 static inline struct reset_control * 1002 devm_reset_control_array_get_exclusive(struct device *dev) 1003 { 1004 return devm_reset_control_array_get(dev, RESET_CONTROL_EXCLUSIVE); 1005 } 1006 1007 static inline struct reset_control * 1008 devm_reset_control_array_get_shared(struct device *dev) 1009 { 1010 return devm_reset_control_array_get(dev, RESET_CONTROL_SHARED); 1011 } 1012 1013 static inline struct reset_control * 1014 devm_reset_control_array_get_optional_exclusive(struct device *dev) 1015 { 1016 return devm_reset_control_array_get(dev, RESET_CONTROL_OPTIONAL_EXCLUSIVE); 1017 } 1018 1019 static inline struct reset_control * 1020 devm_reset_control_array_get_optional_shared(struct device *dev) 1021 { 1022 return devm_reset_control_array_get(dev, RESET_CONTROL_OPTIONAL_SHARED); 1023 } 1024 1025 static inline struct reset_control * 1026 of_reset_control_array_get_exclusive(struct device_node *node) 1027 { 1028 return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE); 1029 } 1030 1031 static inline struct reset_control * 1032 of_reset_control_array_get_exclusive_released(struct device_node *node) 1033 { 1034 return of_reset_control_array_get(node, RESET_CONTROL_EXCLUSIVE_RELEASED); 1035 } 1036 1037 static inline struct reset_control * 1038 of_reset_control_array_get_shared(struct device_node *node) 1039 { 1040 return of_reset_control_array_get(node, RESET_CONTROL_SHARED); 1041 } 1042 1043 static inline struct reset_control * 1044 of_reset_control_array_get_optional_exclusive(struct device_node *node) 1045 { 1046 return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_EXCLUSIVE); 1047 } 1048 1049 static inline struct reset_control * 1050 of_reset_control_array_get_optional_shared(struct device_node *node) 1051 { 1052 return of_reset_control_array_get(node, RESET_CONTROL_OPTIONAL_SHARED); 1053 } 1054 #endif 1055