reset.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2016, NVIDIA CORPORATION.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0
  5. */
  6. #ifndef _RESET_H
  7. #define _RESET_H
  8. #include <linux/errno.h>
  9. /**
  10. * A reset is a hardware signal indicating that a HW module (or IP block, or
  11. * sometimes an entire off-CPU chip) reset all of its internal state to some
  12. * known-good initial state. Drivers will often reset HW modules when they
  13. * begin execution to ensure that hardware correctly responds to all requests,
  14. * or in response to some error condition. Reset signals are often controlled
  15. * externally to the HW module being reset, by an entity this API calls a reset
  16. * controller. This API provides a standard means for drivers to request that
  17. * reset controllers set or clear reset signals.
  18. *
  19. * A driver that implements UCLASS_RESET is a reset controller or provider. A
  20. * controller will often implement multiple separate reset signals, since the
  21. * hardware it manages often has this capability. reset-uclass.h describes the
  22. * interface which reset controllers must implement.
  23. *
  24. * Reset consumers/clients are the HW modules affected by reset signals. This
  25. * header file describes the API used by drivers for those HW modules.
  26. */
  27. struct udevice;
  28. /**
  29. * struct reset_ctl - A handle to (allowing control of) a single reset signal.
  30. *
  31. * Clients provide storage for reset control handles. The content of the
  32. * structure is managed solely by the reset API and reset drivers. A reset
  33. * control struct is initialized by "get"ing the reset control struct. The
  34. * reset control struct is passed to all other reset APIs to identify which
  35. * reset signal to operate upon.
  36. *
  37. * @dev: The device which implements the reset signal.
  38. * @id: The reset signal ID within the provider.
  39. *
  40. * Currently, the reset API assumes that a single integer ID is enough to
  41. * identify and configure any reset signal for any reset provider. If this
  42. * assumption becomes invalid in the future, the struct could be expanded to
  43. * either (a) add more fields to allow reset providers to store additional
  44. * information, or (b) replace the id field with an opaque pointer, which the
  45. * provider would dynamically allocated during its .of_xlate op, and process
  46. * during is .request op. This may require the addition of an extra op to clean
  47. * up the allocation.
  48. */
  49. struct reset_ctl {
  50. struct udevice *dev;
  51. /*
  52. * Written by of_xlate. We assume a single id is enough for now. In the
  53. * future, we might add more fields here.
  54. */
  55. unsigned long id;
  56. };
  57. #ifdef CONFIG_DM_RESET
  58. /**
  59. * reset_get_by_index - Get/request a reset signal by integer index.
  60. *
  61. * This looks up and requests a reset signal. The index is relative to the
  62. * client device; each device is assumed to have n reset signals associated
  63. * with it somehow, and this function finds and requests one of them. The
  64. * mapping of client device reset signal indices to provider reset signals may
  65. * be via device-tree properties, board-provided mapping tables, or some other
  66. * mechanism.
  67. *
  68. * @dev: The client device.
  69. * @index: The index of the reset signal to request, within the client's
  70. * list of reset signals.
  71. * @reset_ctl A pointer to a reset control struct to initialize.
  72. * @return 0 if OK, or a negative error code.
  73. */
  74. int reset_get_by_index(struct udevice *dev, int index,
  75. struct reset_ctl *reset_ctl);
  76. /**
  77. * reset_get_by_name - Get/request a reset signal by name.
  78. *
  79. * This looks up and requests a reset signal. The name is relative to the
  80. * client device; each device is assumed to have n reset signals associated
  81. * with it somehow, and this function finds and requests one of them. The
  82. * mapping of client device reset signal names to provider reset signal may be
  83. * via device-tree properties, board-provided mapping tables, or some other
  84. * mechanism.
  85. *
  86. * @dev: The client device.
  87. * @name: The name of the reset signal to request, within the client's
  88. * list of reset signals.
  89. * @reset_ctl: A pointer to a reset control struct to initialize.
  90. * @return 0 if OK, or a negative error code.
  91. */
  92. int reset_get_by_name(struct udevice *dev, const char *name,
  93. struct reset_ctl *reset_ctl);
  94. /**
  95. * reset_free - Free a previously requested reset signal.
  96. *
  97. * @reset_ctl: A reset control struct that was previously successfully
  98. * requested by reset_get_by_*().
  99. * @return 0 if OK, or a negative error code.
  100. */
  101. int reset_free(struct reset_ctl *reset_ctl);
  102. /**
  103. * reset_assert - Assert a reset signal.
  104. *
  105. * This function will assert the specified reset signal, thus resetting the
  106. * affected HW module(s). Depending on the reset controller hardware, the reset
  107. * signal will either stay asserted until reset_deassert() is called, or the
  108. * hardware may autonomously clear the reset signal itself.
  109. *
  110. * @reset_ctl: A reset control struct that was previously successfully
  111. * requested by reset_get_by_*().
  112. * @return 0 if OK, or a negative error code.
  113. */
  114. int reset_assert(struct reset_ctl *reset_ctl);
  115. /**
  116. * reset_deassert - Deassert a reset signal.
  117. *
  118. * This function will deassert the specified reset signal, thus releasing the
  119. * affected HW modules() from reset, and allowing them to continue normal
  120. * operation.
  121. *
  122. * @reset_ctl: A reset control struct that was previously successfully
  123. * requested by reset_get_by_*().
  124. * @return 0 if OK, or a negative error code.
  125. */
  126. int reset_deassert(struct reset_ctl *reset_ctl);
  127. #else
  128. static inline int reset_get_by_index(struct udevice *dev, int index,
  129. struct reset_ctl *reset_ctl)
  130. {
  131. return -ENOTSUPP;
  132. }
  133. static inline int reset_get_by_name(struct udevice *dev, const char *name,
  134. struct reset_ctl *reset_ctl)
  135. {
  136. return -ENOTSUPP;
  137. }
  138. static inline int reset_free(struct reset_ctl *reset_ctl)
  139. {
  140. return 0;
  141. }
  142. static inline int reset_assert(struct reset_ctl *reset_ctl)
  143. {
  144. return 0;
  145. }
  146. static inline int reset_deassert(struct reset_ctl *reset_ctl)
  147. {
  148. return 0;
  149. }
  150. #endif
  151. #endif