reset.rst 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. .. SPDX-License-Identifier: GPL-2.0-only
  2. ====================
  3. Reset controller API
  4. ====================
  5. Introduction
  6. ============
  7. Reset controllers are central units that control the reset signals to multiple
  8. peripherals.
  9. The reset controller API is split into two parts:
  10. the `consumer driver interface <#consumer-driver-interface>`__ (`API reference
  11. <#reset-consumer-api>`__), which allows peripheral drivers to request control
  12. over their reset input signals, and the `reset controller driver interface
  13. <#reset-controller-driver-interface>`__ (`API reference
  14. <#reset-controller-driver-api>`__), which is used by drivers for reset
  15. controller devices to register their reset controls to provide them to the
  16. consumers.
  17. While some reset controller hardware units also implement system restart
  18. functionality, restart handlers are out of scope for the reset controller API.
  19. Glossary
  20. --------
  21. The reset controller API uses these terms with a specific meaning:
  22. Reset line
  23. Physical reset line carrying a reset signal from a reset controller
  24. hardware unit to a peripheral module.
  25. Reset control
  26. Control method that determines the state of one or multiple reset lines.
  27. Most commonly this is a single bit in reset controller register space that
  28. either allows direct control over the physical state of the reset line, or
  29. is self-clearing and can be used to trigger a predetermined pulse on the
  30. reset line.
  31. In more complicated reset controls, a single trigger action can launch a
  32. carefully timed sequence of pulses on multiple reset lines.
  33. Reset controller
  34. A hardware module that provides a number of reset controls to control a
  35. number of reset lines.
  36. Reset consumer
  37. Peripheral module or external IC that is put into reset by the signal on a
  38. reset line.
  39. Consumer driver interface
  40. =========================
  41. This interface provides an API that is similar to the kernel clock framework.
  42. Consumer drivers use get and put operations to acquire and release reset
  43. controls.
  44. Functions are provided to assert and deassert the controlled reset lines,
  45. trigger reset pulses, or to query reset line status.
  46. When requesting reset controls, consumers can use symbolic names for their
  47. reset inputs, which are mapped to an actual reset control on an existing reset
  48. controller device by the core.
  49. A stub version of this API is provided when the reset controller framework is
  50. not in use in order to minimize the need to use ifdefs.
  51. Shared and exclusive resets
  52. ---------------------------
  53. The reset controller API provides either reference counted deassertion and
  54. assertion or direct, exclusive control.
  55. The distinction between shared and exclusive reset controls is made at the time
  56. the reset control is requested, either via devm_reset_control_get_shared() or
  57. via devm_reset_control_get_exclusive().
  58. This choice determines the behavior of the API calls made with the reset
  59. control.
  60. Shared resets behave similarly to clocks in the kernel clock framework.
  61. They provide reference counted deassertion, where only the first deassert,
  62. which increments the deassertion reference count to one, and the last assert
  63. which decrements the deassertion reference count back to zero, have a physical
  64. effect on the reset line.
  65. Exclusive resets on the other hand guarantee direct control.
  66. That is, an assert causes the reset line to be asserted immediately, and a
  67. deassert causes the reset line to be deasserted immediately.
  68. Assertion and deassertion
  69. -------------------------
  70. Consumer drivers use the reset_control_assert() and reset_control_deassert()
  71. functions to assert and deassert reset lines.
  72. For shared reset controls, calls to the two functions must be balanced.
  73. Note that since multiple consumers may be using a shared reset control, there
  74. is no guarantee that calling reset_control_assert() on a shared reset control
  75. will actually cause the reset line to be asserted.
  76. Consumer drivers using shared reset controls should assume that the reset line
  77. may be kept deasserted at all times.
  78. The API only guarantees that the reset line can not be asserted as long as any
  79. consumer has requested it to be deasserted.
  80. Triggering
  81. ----------
  82. Consumer drivers use reset_control_reset() to trigger a reset pulse on a
  83. self-deasserting reset control.
  84. In general, these resets can not be shared between multiple consumers, since
  85. requesting a pulse from any consumer driver will reset all connected
  86. peripherals.
  87. The reset controller API allows requesting self-deasserting reset controls as
  88. shared, but for those only the first trigger request causes an actual pulse to
  89. be issued on the reset line.
  90. All further calls to this function have no effect until all consumers have
  91. called reset_control_rearm().
  92. For shared reset controls, calls to the two functions must be balanced.
  93. This allows devices that only require an initial reset at any point before the
  94. driver is probed or resumed to share a pulsed reset line.
  95. Querying
  96. --------
  97. Only some reset controllers support querying the current status of a reset
  98. line, via reset_control_status().
  99. If supported, this function returns a positive non-zero value if the given
  100. reset line is asserted.
  101. The reset_control_status() function does not accept a
  102. `reset control array <#reset-control-arrays>`__ handle as its input parameter.
  103. Optional resets
  104. ---------------
  105. Often peripherals require a reset line on some platforms but not on others.
  106. For this, reset controls can be requested as optional using
  107. devm_reset_control_get_optional_exclusive() or
  108. devm_reset_control_get_optional_shared().
  109. These functions return a NULL pointer instead of an error when the requested
  110. reset control is not specified in the device tree.
  111. Passing a NULL pointer to the reset_control functions causes them to return
  112. quietly without an error.
  113. Reset control arrays
  114. --------------------
  115. Some drivers need to assert a bunch of reset lines in no particular order.
  116. devm_reset_control_array_get() returns an opaque reset control handle that can
  117. be used to assert, deassert, or trigger all specified reset controls at once.
  118. The reset control API does not guarantee the order in which the individual
  119. controls therein are handled.
  120. Reset controller driver interface
  121. =================================
  122. Drivers for reset controller modules provide the functionality necessary to
  123. assert or deassert reset signals, to trigger a reset pulse on a reset line, or
  124. to query its current state.
  125. All functions are optional.
  126. Initialization
  127. --------------
  128. Drivers fill a struct :c:type:`reset_controller_dev` and register it with
  129. reset_controller_register() in their probe function.
  130. The actual functionality is implemented in callback functions via a struct
  131. :c:type:`reset_control_ops`.
  132. API reference
  133. =============
  134. The reset controller API is documented here in two parts:
  135. the `reset consumer API <#reset-consumer-api>`__ and the `reset controller
  136. driver API <#reset-controller-driver-api>`__.
  137. Reset consumer API
  138. ------------------
  139. Reset consumers can control a reset line using an opaque reset control handle,
  140. which can be obtained from devm_reset_control_get_exclusive() or
  141. devm_reset_control_get_shared().
  142. Given the reset control, consumers can call reset_control_assert() and
  143. reset_control_deassert(), trigger a reset pulse using reset_control_reset(), or
  144. query the reset line status using reset_control_status().
  145. .. kernel-doc:: include/linux/reset.h
  146. :internal:
  147. .. kernel-doc:: drivers/reset/core.c
  148. :functions: reset_control_reset
  149. reset_control_assert
  150. reset_control_deassert
  151. reset_control_status
  152. reset_control_acquire
  153. reset_control_release
  154. reset_control_rearm
  155. reset_control_put
  156. of_reset_control_get_count
  157. of_reset_control_array_get
  158. devm_reset_control_array_get
  159. reset_control_get_count
  160. Reset controller driver API
  161. ---------------------------
  162. Reset controller drivers are supposed to implement the necessary functions in
  163. a static constant structure :c:type:`reset_control_ops`, allocate and fill out
  164. a struct :c:type:`reset_controller_dev`, and register it using
  165. devm_reset_controller_register().
  166. .. kernel-doc:: include/linux/reset-controller.h
  167. :internal:
  168. .. kernel-doc:: drivers/reset/core.c
  169. :functions: of_reset_simple_xlate
  170. reset_controller_register
  171. reset_controller_unregister
  172. devm_reset_controller_register
  173. reset_controller_add_lookup