reset.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 <dm/ofnode.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. * @data: An optional data field for scenarios where a single integer ID is not
  40. * sufficient. If used, it can be populated through an .of_xlate op and
  41. * processed during the various reset ops.
  42. * @polarity: An optional polarity field for drivers that support
  43. * different reset polarities.
  44. *
  45. * Should additional information to identify and configure any reset signal
  46. * for any provider be required in the future, the struct could be expanded to
  47. * either (a) add more fields to allow reset providers to store additional
  48. * information, or (b) replace the id field with an opaque pointer, which the
  49. * provider would dynamically allocated during its .of_xlate op, and process
  50. * during is .request op. This may require the addition of an extra op to clean
  51. * up the allocation.
  52. */
  53. struct reset_ctl {
  54. struct udevice *dev;
  55. /*
  56. * Written by of_xlate. In the future, we might add more fields here.
  57. */
  58. unsigned long id;
  59. unsigned long data;
  60. unsigned long polarity;
  61. };
  62. /**
  63. * struct reset_ctl_bulk - A handle to (allowing control of) a bulk of reset
  64. * signals.
  65. *
  66. * Clients provide storage for the reset control bulk. The content of the
  67. * structure is managed solely by the reset API. A reset control bulk struct is
  68. * initialized by "get"ing the reset control bulk struct.
  69. * The reset control bulk struct is passed to all other bulk reset APIs to apply
  70. * the API to all the reset signals in the bulk struct.
  71. *
  72. * @resets: An array of reset signal handles handles.
  73. * @count: The number of reset signal handles in the reset array.
  74. */
  75. struct reset_ctl_bulk {
  76. struct reset_ctl *resets;
  77. unsigned int count;
  78. };
  79. #if CONFIG_IS_ENABLED(DM_RESET)
  80. /**
  81. * reset_get_by_index - Get/request a reset signal by integer index.
  82. *
  83. * This looks up and requests a reset signal. The index is relative to the
  84. * client device; each device is assumed to have n reset signals associated
  85. * with it somehow, and this function finds and requests one of them. The
  86. * mapping of client device reset signal indices to provider reset signals may
  87. * be via device-tree properties, board-provided mapping tables, or some other
  88. * mechanism.
  89. *
  90. * @dev: The client device.
  91. * @index: The index of the reset signal to request, within the client's
  92. * list of reset signals.
  93. * @reset_ctl A pointer to a reset control struct to initialize.
  94. * @return 0 if OK, or a negative error code.
  95. */
  96. int reset_get_by_index(struct udevice *dev, int index,
  97. struct reset_ctl *reset_ctl);
  98. /**
  99. * reset_get_by_index_nodev - Get/request a reset signal by integer index
  100. * without a device.
  101. *
  102. * This is a version of reset_get_by_index() that does not use a device.
  103. *
  104. * @node: The client ofnode.
  105. * @index: The index of the reset signal to request, within the client's
  106. * list of reset signals.
  107. * @reset_ctl A pointer to a reset control struct to initialize.
  108. * @return 0 if OK, or a negative error code.
  109. */
  110. int reset_get_by_index_nodev(ofnode node, int index,
  111. struct reset_ctl *reset_ctl);
  112. /**
  113. * reset_get_bulk - Get/request all reset signals of a device.
  114. *
  115. * This looks up and requests all reset signals of the client device; each
  116. * device is assumed to have n reset signals associated with it somehow,
  117. * and this function finds and requests all of them in a separate structure.
  118. * The mapping of client device reset signals indices to provider reset signals
  119. * may be via device-tree properties, board-provided mapping tables, or some
  120. * other mechanism.
  121. *
  122. * @dev: The client device.
  123. * @bulk A pointer to a reset control bulk struct to initialize.
  124. * @return 0 if OK, or a negative error code.
  125. */
  126. int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk);
  127. /**
  128. * reset_get_by_name - Get/request a reset signal by name.
  129. *
  130. * This looks up and requests a reset signal. The name is relative to the
  131. * client device; each device is assumed to have n reset signals associated
  132. * with it somehow, and this function finds and requests one of them. The
  133. * mapping of client device reset signal names to provider reset signal may be
  134. * via device-tree properties, board-provided mapping tables, or some other
  135. * mechanism.
  136. *
  137. * @dev: The client device.
  138. * @name: The name of the reset signal to request, within the client's
  139. * list of reset signals.
  140. * @reset_ctl: A pointer to a reset control struct to initialize.
  141. * @return 0 if OK, or a negative error code.
  142. */
  143. int reset_get_by_name(struct udevice *dev, const char *name,
  144. struct reset_ctl *reset_ctl);
  145. /**
  146. * reset_request - Request a reset signal.
  147. *
  148. * @reset_ctl: A reset control struct.
  149. *
  150. * @return 0 if OK, or a negative error code.
  151. */
  152. int reset_request(struct reset_ctl *reset_ctl);
  153. /**
  154. * reset_free - Free a previously requested reset signal.
  155. *
  156. * @reset_ctl: A reset control struct that was previously successfully
  157. * requested by reset_get_by_*().
  158. * @return 0 if OK, or a negative error code.
  159. */
  160. int reset_free(struct reset_ctl *reset_ctl);
  161. /**
  162. * reset_assert - Assert a reset signal.
  163. *
  164. * This function will assert the specified reset signal, thus resetting the
  165. * affected HW module(s). Depending on the reset controller hardware, the reset
  166. * signal will either stay asserted until reset_deassert() is called, or the
  167. * hardware may autonomously clear the reset signal itself.
  168. *
  169. * @reset_ctl: A reset control struct that was previously successfully
  170. * requested by reset_get_by_*().
  171. * @return 0 if OK, or a negative error code.
  172. */
  173. int reset_assert(struct reset_ctl *reset_ctl);
  174. /**
  175. * reset_assert_bulk - Assert all reset signals in a reset control bulk struct.
  176. *
  177. * This function will assert the specified reset signals in a reset control
  178. * bulk struct, thus resetting the affected HW module(s). Depending on the
  179. * reset controller hardware, the reset signals will either stay asserted
  180. * until reset_deassert_bulk() is called, or the hardware may autonomously
  181. * clear the reset signals itself.
  182. *
  183. * @bulk: A reset control bulk struct that was previously successfully
  184. * requested by reset_get_bulk().
  185. * @return 0 if OK, or a negative error code.
  186. */
  187. int reset_assert_bulk(struct reset_ctl_bulk *bulk);
  188. /**
  189. * reset_deassert - Deassert a reset signal.
  190. *
  191. * This function will deassert the specified reset signal, thus releasing the
  192. * affected HW modules() from reset, and allowing them to continue normal
  193. * operation.
  194. *
  195. * @reset_ctl: A reset control struct that was previously successfully
  196. * requested by reset_get_by_*().
  197. * @return 0 if OK, or a negative error code.
  198. */
  199. int reset_deassert(struct reset_ctl *reset_ctl);
  200. /**
  201. * reset_deassert_bulk - Deassert all reset signals in a reset control bulk
  202. * struct.
  203. *
  204. * This function will deassert the specified reset signals in a reset control
  205. * bulk struct, thus releasing the affected HW modules() from reset, and
  206. * allowing them to continue normal operation.
  207. *
  208. * @bulk: A reset control bulk struct that was previously successfully
  209. * requested by reset_get_bulk().
  210. * @return 0 if OK, or a negative error code.
  211. */
  212. int reset_deassert_bulk(struct reset_ctl_bulk *bulk);
  213. /**
  214. * rst_status - Check reset signal status.
  215. *
  216. * @reset_ctl: The reset signal to check.
  217. * @return 0 if deasserted, positive if asserted, or a negative
  218. * error code.
  219. */
  220. int reset_status(struct reset_ctl *reset_ctl);
  221. /**
  222. * reset_release_all - Assert/Free an array of previously requested resets.
  223. *
  224. * For each reset contained in the reset array, this function will check if
  225. * reset has been previously requested and then will assert and free it.
  226. *
  227. * @reset_ctl: A reset struct array that was previously successfully
  228. * requested by reset_get_by_*().
  229. * @count Number of reset contained in the array
  230. * @return 0 if OK, or a negative error code.
  231. */
  232. int reset_release_all(struct reset_ctl *reset_ctl, int count);
  233. /**
  234. * reset_release_bulk - Assert/Free an array of previously requested reset
  235. * signals in a reset control bulk struct.
  236. *
  237. * For each reset contained in the reset control bulk struct, this function
  238. * will check if reset has been previously requested and then will assert
  239. * and free it.
  240. *
  241. * @bulk: A reset control bulk struct that was previously successfully
  242. * requested by reset_get_bulk().
  243. * @return 0 if OK, or a negative error code.
  244. */
  245. static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
  246. {
  247. return reset_release_all(bulk->resets, bulk->count);
  248. }
  249. #else
  250. static inline int reset_get_by_index(struct udevice *dev, int index,
  251. struct reset_ctl *reset_ctl)
  252. {
  253. return -ENOTSUPP;
  254. }
  255. static inline int reset_get_bulk(struct udevice *dev,
  256. struct reset_ctl_bulk *bulk)
  257. {
  258. return -ENOTSUPP;
  259. }
  260. static inline int reset_get_by_name(struct udevice *dev, const char *name,
  261. struct reset_ctl *reset_ctl)
  262. {
  263. return -ENOTSUPP;
  264. }
  265. static inline int reset_free(struct reset_ctl *reset_ctl)
  266. {
  267. return 0;
  268. }
  269. static inline int reset_assert(struct reset_ctl *reset_ctl)
  270. {
  271. return 0;
  272. }
  273. static inline int reset_assert_bulk(struct reset_ctl_bulk *bulk)
  274. {
  275. return 0;
  276. }
  277. static inline int reset_deassert(struct reset_ctl *reset_ctl)
  278. {
  279. return 0;
  280. }
  281. static inline int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
  282. {
  283. return 0;
  284. }
  285. static inline int reset_status(struct reset_ctl *reset_ctl)
  286. {
  287. return -ENOTSUPP;
  288. }
  289. static inline int reset_release_all(struct reset_ctl *reset_ctl, int count)
  290. {
  291. return 0;
  292. }
  293. static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
  294. {
  295. return 0;
  296. }
  297. #endif
  298. /**
  299. * reset_valid() - check if reset is valid
  300. *
  301. * @reset_ctl: the reset to check
  302. * @return TRUE if valid, or FALSE
  303. */
  304. static inline bool reset_valid(struct reset_ctl *reset_ctl)
  305. {
  306. return !!reset_ctl->dev;
  307. }
  308. #endif