reset.h 8.8 KB

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