reset.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. #ifndef _LINUX_RESET_H_
  2. #define _LINUX_RESET_H_
  3. #include <linux/device.h>
  4. struct reset_control;
  5. #ifdef CONFIG_RESET_CONTROLLER
  6. int reset_control_reset(struct reset_control *rstc);
  7. int reset_control_assert(struct reset_control *rstc);
  8. int reset_control_deassert(struct reset_control *rstc);
  9. int reset_control_status(struct reset_control *rstc);
  10. struct reset_control *__of_reset_control_get(struct device_node *node,
  11. const char *id, int index, bool shared,
  12. bool optional);
  13. void reset_control_put(struct reset_control *rstc);
  14. struct reset_control *__devm_reset_control_get(struct device *dev,
  15. const char *id, int index, bool shared,
  16. bool optional);
  17. int __must_check device_reset(struct device *dev);
  18. static inline int device_reset_optional(struct device *dev)
  19. {
  20. return device_reset(dev);
  21. }
  22. #else
  23. static inline int reset_control_reset(struct reset_control *rstc)
  24. {
  25. return 0;
  26. }
  27. static inline int reset_control_assert(struct reset_control *rstc)
  28. {
  29. return 0;
  30. }
  31. static inline int reset_control_deassert(struct reset_control *rstc)
  32. {
  33. return 0;
  34. }
  35. static inline int reset_control_status(struct reset_control *rstc)
  36. {
  37. return 0;
  38. }
  39. static inline void reset_control_put(struct reset_control *rstc)
  40. {
  41. }
  42. static inline int __must_check device_reset(struct device *dev)
  43. {
  44. WARN_ON(1);
  45. return -ENOTSUPP;
  46. }
  47. static inline int device_reset_optional(struct device *dev)
  48. {
  49. return -ENOTSUPP;
  50. }
  51. static inline struct reset_control *__of_reset_control_get(
  52. struct device_node *node,
  53. const char *id, int index, bool shared,
  54. bool optional)
  55. {
  56. return optional ? NULL : ERR_PTR(-ENOTSUPP);
  57. }
  58. static inline struct reset_control *__devm_reset_control_get(
  59. struct device *dev, const char *id,
  60. int index, bool shared, bool optional)
  61. {
  62. return optional ? NULL : ERR_PTR(-ENOTSUPP);
  63. }
  64. #endif /* CONFIG_RESET_CONTROLLER */
  65. /**
  66. * reset_control_get_exclusive - Lookup and obtain an exclusive reference
  67. * to a reset controller.
  68. * @dev: device to be reset by the controller
  69. * @id: reset line name
  70. *
  71. * Returns a struct reset_control or IS_ERR() condition containing errno.
  72. * If this function is called more then once for the same reset_control it will
  73. * return -EBUSY.
  74. *
  75. * See reset_control_get_shared for details on shared references to
  76. * reset-controls.
  77. *
  78. * Use of id names is optional.
  79. */
  80. static inline struct reset_control *
  81. __must_check reset_control_get_exclusive(struct device *dev, const char *id)
  82. {
  83. #ifndef CONFIG_RESET_CONTROLLER
  84. WARN_ON(1);
  85. #endif
  86. return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
  87. false);
  88. }
  89. /**
  90. * reset_control_get_shared - Lookup and obtain a shared reference to a
  91. * reset controller.
  92. * @dev: device to be reset by the controller
  93. * @id: reset line name
  94. *
  95. * Returns a struct reset_control or IS_ERR() condition containing errno.
  96. * This function is intended for use with reset-controls which are shared
  97. * between hardware-blocks.
  98. *
  99. * When a reset-control is shared, the behavior of reset_control_assert /
  100. * deassert is changed, the reset-core will keep track of a deassert_count
  101. * and only (re-)assert the reset after reset_control_assert has been called
  102. * as many times as reset_control_deassert was called. Also see the remark
  103. * about shared reset-controls in the reset_control_assert docs.
  104. *
  105. * Calling reset_control_assert without first calling reset_control_deassert
  106. * is not allowed on a shared reset control. Calling reset_control_reset is
  107. * also not allowed on a shared reset control.
  108. *
  109. * Use of id names is optional.
  110. */
  111. static inline struct reset_control *reset_control_get_shared(
  112. struct device *dev, const char *id)
  113. {
  114. return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
  115. false);
  116. }
  117. static inline struct reset_control *reset_control_get_optional_exclusive(
  118. struct device *dev, const char *id)
  119. {
  120. return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, false,
  121. true);
  122. }
  123. static inline struct reset_control *reset_control_get_optional_shared(
  124. struct device *dev, const char *id)
  125. {
  126. return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, true,
  127. true);
  128. }
  129. /**
  130. * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
  131. * to a reset controller.
  132. * @node: device to be reset by the controller
  133. * @id: reset line name
  134. *
  135. * Returns a struct reset_control or IS_ERR() condition containing errno.
  136. *
  137. * Use of id names is optional.
  138. */
  139. static inline struct reset_control *of_reset_control_get_exclusive(
  140. struct device_node *node, const char *id)
  141. {
  142. return __of_reset_control_get(node, id, 0, false, false);
  143. }
  144. /**
  145. * of_reset_control_get_shared - Lookup and obtain an shared reference
  146. * to a reset controller.
  147. * @node: device to be reset by the controller
  148. * @id: reset line name
  149. *
  150. * When a reset-control is shared, the behavior of reset_control_assert /
  151. * deassert is changed, the reset-core will keep track of a deassert_count
  152. * and only (re-)assert the reset after reset_control_assert has been called
  153. * as many times as reset_control_deassert was called. Also see the remark
  154. * about shared reset-controls in the reset_control_assert docs.
  155. *
  156. * Calling reset_control_assert without first calling reset_control_deassert
  157. * is not allowed on a shared reset control. Calling reset_control_reset is
  158. * also not allowed on a shared reset control.
  159. * Returns a struct reset_control or IS_ERR() condition containing errno.
  160. *
  161. * Use of id names is optional.
  162. */
  163. static inline struct reset_control *of_reset_control_get_shared(
  164. struct device_node *node, const char *id)
  165. {
  166. return __of_reset_control_get(node, id, 0, true, false);
  167. }
  168. /**
  169. * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
  170. * reference to a reset controller
  171. * by index.
  172. * @node: device to be reset by the controller
  173. * @index: index of the reset controller
  174. *
  175. * This is to be used to perform a list of resets for a device or power domain
  176. * in whatever order. Returns a struct reset_control or IS_ERR() condition
  177. * containing errno.
  178. */
  179. static inline struct reset_control *of_reset_control_get_exclusive_by_index(
  180. struct device_node *node, int index)
  181. {
  182. return __of_reset_control_get(node, NULL, index, false, false);
  183. }
  184. /**
  185. * of_reset_control_get_shared_by_index - Lookup and obtain an shared
  186. * reference to a reset controller
  187. * by index.
  188. * @node: device to be reset by the controller
  189. * @index: index of the reset controller
  190. *
  191. * When a reset-control is shared, the behavior of reset_control_assert /
  192. * deassert is changed, the reset-core will keep track of a deassert_count
  193. * and only (re-)assert the reset after reset_control_assert has been called
  194. * as many times as reset_control_deassert was called. Also see the remark
  195. * about shared reset-controls in the reset_control_assert docs.
  196. *
  197. * Calling reset_control_assert without first calling reset_control_deassert
  198. * is not allowed on a shared reset control. Calling reset_control_reset is
  199. * also not allowed on a shared reset control.
  200. * Returns a struct reset_control or IS_ERR() condition containing errno.
  201. *
  202. * This is to be used to perform a list of resets for a device or power domain
  203. * in whatever order. Returns a struct reset_control or IS_ERR() condition
  204. * containing errno.
  205. */
  206. static inline struct reset_control *of_reset_control_get_shared_by_index(
  207. struct device_node *node, int index)
  208. {
  209. return __of_reset_control_get(node, NULL, index, true, false);
  210. }
  211. /**
  212. * devm_reset_control_get_exclusive - resource managed
  213. * reset_control_get_exclusive()
  214. * @dev: device to be reset by the controller
  215. * @id: reset line name
  216. *
  217. * Managed reset_control_get_exclusive(). For reset controllers returned
  218. * from this function, reset_control_put() is called automatically on driver
  219. * detach.
  220. *
  221. * See reset_control_get_exclusive() for more information.
  222. */
  223. static inline struct reset_control *
  224. __must_check devm_reset_control_get_exclusive(struct device *dev,
  225. const char *id)
  226. {
  227. #ifndef CONFIG_RESET_CONTROLLER
  228. WARN_ON(1);
  229. #endif
  230. return __devm_reset_control_get(dev, id, 0, false, false);
  231. }
  232. /**
  233. * devm_reset_control_get_shared - resource managed reset_control_get_shared()
  234. * @dev: device to be reset by the controller
  235. * @id: reset line name
  236. *
  237. * Managed reset_control_get_shared(). For reset controllers returned from
  238. * this function, reset_control_put() is called automatically on driver detach.
  239. * See reset_control_get_shared() for more information.
  240. */
  241. static inline struct reset_control *devm_reset_control_get_shared(
  242. struct device *dev, const char *id)
  243. {
  244. return __devm_reset_control_get(dev, id, 0, true, false);
  245. }
  246. static inline struct reset_control *devm_reset_control_get_optional_exclusive(
  247. struct device *dev, const char *id)
  248. {
  249. return __devm_reset_control_get(dev, id, 0, false, true);
  250. }
  251. static inline struct reset_control *devm_reset_control_get_optional_shared(
  252. struct device *dev, const char *id)
  253. {
  254. return __devm_reset_control_get(dev, id, 0, true, true);
  255. }
  256. /**
  257. * devm_reset_control_get_exclusive_by_index - resource managed
  258. * reset_control_get_exclusive()
  259. * @dev: device to be reset by the controller
  260. * @index: index of the reset controller
  261. *
  262. * Managed reset_control_get_exclusive(). For reset controllers returned from
  263. * this function, reset_control_put() is called automatically on driver
  264. * detach.
  265. *
  266. * See reset_control_get_exclusive() for more information.
  267. */
  268. static inline struct reset_control *
  269. devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
  270. {
  271. return __devm_reset_control_get(dev, NULL, index, false, false);
  272. }
  273. /**
  274. * devm_reset_control_get_shared_by_index - resource managed
  275. * reset_control_get_shared
  276. * @dev: device to be reset by the controller
  277. * @index: index of the reset controller
  278. *
  279. * Managed reset_control_get_shared(). For reset controllers returned from
  280. * this function, reset_control_put() is called automatically on driver detach.
  281. * See reset_control_get_shared() for more information.
  282. */
  283. static inline struct reset_control *
  284. devm_reset_control_get_shared_by_index(struct device *dev, int index)
  285. {
  286. return __devm_reset_control_get(dev, NULL, index, true, false);
  287. }
  288. /*
  289. * TEMPORARY calls to use during transition:
  290. *
  291. * of_reset_control_get() => of_reset_control_get_exclusive()
  292. *
  293. * These inline function calls will be removed once all consumers
  294. * have been moved over to the new explicit API.
  295. */
  296. static inline struct reset_control *reset_control_get(
  297. struct device *dev, const char *id)
  298. {
  299. return reset_control_get_exclusive(dev, id);
  300. }
  301. static inline struct reset_control *reset_control_get_optional(
  302. struct device *dev, const char *id)
  303. {
  304. return reset_control_get_optional_exclusive(dev, id);
  305. }
  306. static inline struct reset_control *of_reset_control_get(
  307. struct device_node *node, const char *id)
  308. {
  309. return of_reset_control_get_exclusive(node, id);
  310. }
  311. static inline struct reset_control *of_reset_control_get_by_index(
  312. struct device_node *node, int index)
  313. {
  314. return of_reset_control_get_exclusive_by_index(node, index);
  315. }
  316. static inline struct reset_control *devm_reset_control_get(
  317. struct device *dev, const char *id)
  318. {
  319. return devm_reset_control_get_exclusive(dev, id);
  320. }
  321. static inline struct reset_control *devm_reset_control_get_optional(
  322. struct device *dev, const char *id)
  323. {
  324. return devm_reset_control_get_optional_exclusive(dev, id);
  325. }
  326. static inline struct reset_control *devm_reset_control_get_by_index(
  327. struct device *dev, int index)
  328. {
  329. return devm_reset_control_get_exclusive_by_index(dev, index);
  330. }
  331. #endif