reset.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2016, NVIDIA CORPORATION.
  4. */
  5. #ifndef _RESET_H
  6. #define _RESET_H
  7. #include <linux/errno.h>
  8. /**
  9. * A reset is a hardware signal indicating that a HW module (or IP block, or
  10. * sometimes an entire off-CPU chip) reset all of its internal state to some
  11. * known-good initial state. Drivers will often reset HW modules when they
  12. * begin execution to ensure that hardware correctly responds to all requests,
  13. * or in response to some error condition. Reset signals are often controlled
  14. * externally to the HW module being reset, by an entity this API calls a reset
  15. * controller. This API provides a standard means for drivers to request that
  16. * reset controllers set or clear reset signals.
  17. *
  18. * A driver that implements UCLASS_RESET is a reset controller or provider. A
  19. * controller will often implement multiple separate reset signals, since the
  20. * hardware it manages often has this capability. reset-uclass.h describes the
  21. * interface which reset controllers must implement.
  22. *
  23. * Reset consumers/clients are the HW modules affected by reset signals. This
  24. * header file describes the API used by drivers for those HW modules.
  25. */
  26. struct udevice;
  27. /**
  28. * struct reset_ctl - A handle to (allowing control of) a single reset signal.
  29. *
  30. * Clients provide storage for reset control handles. The content of the
  31. * structure is managed solely by the reset API and reset drivers. A reset
  32. * control struct is initialized by "get"ing the reset control struct. The
  33. * reset control struct is passed to all other reset APIs to identify which
  34. * reset signal to operate upon.
  35. *
  36. * @dev: The device which implements the reset signal.
  37. * @id: The reset signal ID within the provider.
  38. *
  39. * Currently, the reset API assumes that a single integer ID is enough to
  40. * identify and configure any reset signal for any reset provider. If this
  41. * assumption becomes invalid in the future, the struct could be expanded to
  42. * either (a) add more fields to allow reset providers to store additional
  43. * information, or (b) replace the id field with an opaque pointer, which the
  44. * provider would dynamically allocated during its .of_xlate op, and process
  45. * during is .request op. This may require the addition of an extra op to clean
  46. * up the allocation.
  47. */
  48. struct reset_ctl {
  49. struct udevice *dev;
  50. /*
  51. * Written by of_xlate. We assume a single id is enough for now. In the
  52. * future, we might add more fields here.
  53. */
  54. unsigned long id;
  55. };
  56. /**
  57. * struct reset_ctl_bulk - A handle to (allowing control of) a bulk of reset
  58. * signals.
  59. *
  60. * Clients provide storage for the reset control bulk. The content of the
  61. * structure is managed solely by the reset API. A reset control bulk struct is
  62. * initialized by "get"ing the reset control bulk struct.
  63. * The reset control bulk struct is passed to all other bulk reset APIs to apply
  64. * the API to all the reset signals in the bulk struct.
  65. *
  66. * @resets: An array of reset signal handles handles.
  67. * @count: The number of reset signal handles in the reset array.
  68. */
  69. struct reset_ctl_bulk {
  70. struct reset_ctl *resets;
  71. unsigned int count;
  72. };
  73. #ifdef CONFIG_DM_RESET
  74. /**
  75. * reset_get_by_index - Get/request a reset signal by integer index.
  76. *
  77. * This looks up and requests a reset signal. The index is relative to the
  78. * client device; each device is assumed to have n reset signals associated
  79. * with it somehow, and this function finds and requests one of them. The
  80. * mapping of client device reset signal indices to provider reset signals may
  81. * be via device-tree properties, board-provided mapping tables, or some other
  82. * mechanism.
  83. *
  84. * @dev: The client device.
  85. * @index: The index of the reset signal to request, within the client's
  86. * list of reset signals.
  87. * @reset_ctl A pointer to a reset control struct to initialize.
  88. * @return 0 if OK, or a negative error code.
  89. */
  90. int reset_get_by_index(struct udevice *dev, int index,
  91. struct reset_ctl *reset_ctl);
  92. /**
  93. * reset_get_bulk - Get/request all reset signals of a device.
  94. *
  95. * This looks up and requests all reset signals of the client device; each
  96. * device is assumed to have n reset signals associated with it somehow,
  97. * and this function finds and requests all of them in a separate structure.
  98. * The mapping of client device reset signals indices to provider reset signals
  99. * may be via device-tree properties, board-provided mapping tables, or some
  100. * other mechanism.
  101. *
  102. * @dev: The client device.
  103. * @bulk A pointer to a reset control bulk struct to initialize.
  104. * @return 0 if OK, or a negative error code.
  105. */
  106. int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk);
  107. /**
  108. * reset_get_by_name - Get/request a reset signal by name.
  109. *
  110. * This looks up and requests a reset signal. The name is relative to the
  111. * client device; each device is assumed to have n reset signals associated
  112. * with it somehow, and this function finds and requests one of them. The
  113. * mapping of client device reset signal names to provider reset signal may be
  114. * via device-tree properties, board-provided mapping tables, or some other
  115. * mechanism.
  116. *
  117. * @dev: The client device.
  118. * @name: The name of the reset signal to request, within the client's
  119. * list of reset signals.
  120. * @reset_ctl: A pointer to a reset control struct to initialize.
  121. * @return 0 if OK, or a negative error code.
  122. */
  123. int reset_get_by_name(struct udevice *dev, const char *name,
  124. struct reset_ctl *reset_ctl);
  125. /**
  126. * reset_request - Request a reset signal.
  127. *
  128. * @reset_ctl: A reset control struct.
  129. *
  130. * @return 0 if OK, or a negative error code.
  131. */
  132. int reset_request(struct reset_ctl *reset_ctl);
  133. /**
  134. * reset_free - Free a previously requested reset signal.
  135. *
  136. * @reset_ctl: A reset control struct that was previously successfully
  137. * requested by reset_get_by_*().
  138. * @return 0 if OK, or a negative error code.
  139. */
  140. int reset_free(struct reset_ctl *reset_ctl);
  141. /**
  142. * reset_assert - Assert a reset signal.
  143. *
  144. * This function will assert the specified reset signal, thus resetting the
  145. * affected HW module(s). Depending on the reset controller hardware, the reset
  146. * signal will either stay asserted until reset_deassert() is called, or the
  147. * hardware may autonomously clear the reset signal itself.
  148. *
  149. * @reset_ctl: A reset control struct that was previously successfully
  150. * requested by reset_get_by_*().
  151. * @return 0 if OK, or a negative error code.
  152. */
  153. int reset_assert(struct reset_ctl *reset_ctl);
  154. /**
  155. * reset_assert_bulk - Assert all reset signals in a reset control bulk struct.
  156. *
  157. * This function will assert the specified reset signals in a reset control
  158. * bulk struct, thus resetting the affected HW module(s). Depending on the
  159. * reset controller hardware, the reset signals will either stay asserted
  160. * until reset_deassert_bulk() is called, or the hardware may autonomously
  161. * clear the reset signals itself.
  162. *
  163. * @bulk: A reset control bulk struct that was previously successfully
  164. * requested by reset_get_bulk().
  165. * @return 0 if OK, or a negative error code.
  166. */
  167. int reset_assert_bulk(struct reset_ctl_bulk *bulk);
  168. /**
  169. * reset_deassert - Deassert a reset signal.
  170. *
  171. * This function will deassert the specified reset signal, thus releasing the
  172. * affected HW modules() from reset, and allowing them to continue normal
  173. * operation.
  174. *
  175. * @reset_ctl: A reset control struct that was previously successfully
  176. * requested by reset_get_by_*().
  177. * @return 0 if OK, or a negative error code.
  178. */
  179. int reset_deassert(struct reset_ctl *reset_ctl);
  180. /**
  181. * reset_deassert_bulk - Deassert all reset signals in a reset control bulk
  182. * struct.
  183. *
  184. * This function will deassert the specified reset signals in a reset control
  185. * bulk struct, thus releasing the affected HW modules() from reset, and
  186. * allowing them to continue normal operation.
  187. *
  188. * @bulk: A reset control bulk struct that was previously successfully
  189. * requested by reset_get_bulk().
  190. * @return 0 if OK, or a negative error code.
  191. */
  192. int reset_deassert_bulk(struct reset_ctl_bulk *bulk);
  193. /**
  194. * reset_release_all - Assert/Free an array of previously requested resets.
  195. *
  196. * For each reset contained in the reset array, this function will check if
  197. * reset has been previously requested and then will assert and free it.
  198. *
  199. * @reset_ctl: A reset struct array that was previously successfully
  200. * requested by reset_get_by_*().
  201. * @count Number of reset contained in the array
  202. * @return 0 if OK, or a negative error code.
  203. */
  204. int reset_release_all(struct reset_ctl *reset_ctl, int count);
  205. /**
  206. * reset_release_bulk - Assert/Free an array of previously requested reset
  207. * signals in a reset control bulk struct.
  208. *
  209. * For each reset contained in the reset control bulk struct, this function
  210. * will check if reset has been previously requested and then will assert
  211. * and free it.
  212. *
  213. * @bulk: A reset control bulk struct that was previously successfully
  214. * requested by reset_get_bulk().
  215. * @return 0 if OK, or a negative error code.
  216. */
  217. static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
  218. {
  219. return reset_release_all(bulk->resets, bulk->count);
  220. }
  221. #else
  222. static inline int reset_get_by_index(struct udevice *dev, int index,
  223. struct reset_ctl *reset_ctl)
  224. {
  225. return -ENOTSUPP;
  226. }
  227. static inline int reset_get_bulk(struct udevice *dev,
  228. struct reset_ctl_bulk *bulk)
  229. {
  230. return -ENOTSUPP;
  231. }
  232. static inline int reset_get_by_name(struct udevice *dev, const char *name,
  233. struct reset_ctl *reset_ctl)
  234. {
  235. return -ENOTSUPP;
  236. }
  237. static inline int reset_free(struct reset_ctl *reset_ctl)
  238. {
  239. return 0;
  240. }
  241. static inline int reset_assert(struct reset_ctl *reset_ctl)
  242. {
  243. return 0;
  244. }
  245. static inline int reset_assert_bulk(struct reset_ctl_bulk *bulk)
  246. {
  247. return 0;
  248. }
  249. static inline int reset_deassert(struct reset_ctl *reset_ctl)
  250. {
  251. return 0;
  252. }
  253. static inline int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
  254. {
  255. return 0;
  256. }
  257. static inline int reset_release_all(struct reset_ctl *reset_ctl, int count)
  258. {
  259. return 0;
  260. }
  261. static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
  262. {
  263. return 0;
  264. }
  265. #endif
  266. #endif