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