reset.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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(-ENOTSUPP);
  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(-ENOTSUPP);
  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. static inline struct reset_control *reset_control_get_optional_shared(
  123. struct device *dev, const char *id)
  124. {
  125. return __of_reset_control_get(dev ? dev->of_node : NULL, id, 0, 1);
  126. }
  127. /**
  128. * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
  129. * to a reset controller.
  130. * @node: device to be reset by the controller
  131. * @id: reset line name
  132. *
  133. * Returns a struct reset_control or IS_ERR() condition containing errno.
  134. *
  135. * Use of id names is optional.
  136. */
  137. static inline struct reset_control *of_reset_control_get_exclusive(
  138. struct device_node *node, const char *id)
  139. {
  140. return __of_reset_control_get(node, id, 0, 0);
  141. }
  142. /**
  143. * of_reset_control_get_shared - Lookup and obtain an shared reference
  144. * to a reset controller.
  145. * @node: device to be reset by the controller
  146. * @id: reset line name
  147. *
  148. * When a reset-control is shared, the behavior of reset_control_assert /
  149. * deassert is changed, the reset-core will keep track of a deassert_count
  150. * and only (re-)assert the reset after reset_control_assert has been called
  151. * as many times as reset_control_deassert was called. Also see the remark
  152. * about shared reset-controls in the reset_control_assert docs.
  153. *
  154. * Calling reset_control_assert without first calling reset_control_deassert
  155. * is not allowed on a shared reset control. Calling reset_control_reset is
  156. * also not allowed on a shared reset control.
  157. * Returns a struct reset_control or IS_ERR() condition containing errno.
  158. *
  159. * Use of id names is optional.
  160. */
  161. static inline struct reset_control *of_reset_control_get_shared(
  162. struct device_node *node, const char *id)
  163. {
  164. return __of_reset_control_get(node, id, 0, 1);
  165. }
  166. /**
  167. * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
  168. * reference to a reset controller
  169. * by index.
  170. * @node: device to be reset by the controller
  171. * @index: index of the reset controller
  172. *
  173. * This is to be used to perform a list of resets for a device or power domain
  174. * in whatever order. Returns a struct reset_control or IS_ERR() condition
  175. * containing errno.
  176. */
  177. static inline struct reset_control *of_reset_control_get_exclusive_by_index(
  178. struct device_node *node, int index)
  179. {
  180. return __of_reset_control_get(node, NULL, index, 0);
  181. }
  182. /**
  183. * of_reset_control_get_shared_by_index - Lookup and obtain an shared
  184. * reference to a reset controller
  185. * by index.
  186. * @node: device to be reset by the controller
  187. * @index: index of the reset controller
  188. *
  189. * When a reset-control is shared, the behavior of reset_control_assert /
  190. * deassert is changed, the reset-core will keep track of a deassert_count
  191. * and only (re-)assert the reset after reset_control_assert has been called
  192. * as many times as reset_control_deassert was called. Also see the remark
  193. * about shared reset-controls in the reset_control_assert docs.
  194. *
  195. * Calling reset_control_assert without first calling reset_control_deassert
  196. * is not allowed on a shared reset control. Calling reset_control_reset is
  197. * also not allowed on a shared reset control.
  198. * Returns a struct reset_control or IS_ERR() condition containing errno.
  199. *
  200. * This is to be used to perform a list of resets for a device or power domain
  201. * in whatever order. Returns a struct reset_control or IS_ERR() condition
  202. * containing errno.
  203. */
  204. static inline struct reset_control *of_reset_control_get_shared_by_index(
  205. struct device_node *node, int index)
  206. {
  207. return __of_reset_control_get(node, NULL, index, 1);
  208. }
  209. /**
  210. * devm_reset_control_get_exclusive - resource managed
  211. * reset_control_get_exclusive()
  212. * @dev: device to be reset by the controller
  213. * @id: reset line name
  214. *
  215. * Managed reset_control_get_exclusive(). For reset controllers returned
  216. * from this function, reset_control_put() is called automatically on driver
  217. * detach.
  218. *
  219. * See reset_control_get_exclusive() for more information.
  220. */
  221. static inline struct reset_control *
  222. __must_check devm_reset_control_get_exclusive(struct device *dev,
  223. const char *id)
  224. {
  225. #ifndef CONFIG_RESET_CONTROLLER
  226. WARN_ON(1);
  227. #endif
  228. return __devm_reset_control_get(dev, id, 0, 0);
  229. }
  230. /**
  231. * devm_reset_control_get_shared - resource managed reset_control_get_shared()
  232. * @dev: device to be reset by the controller
  233. * @id: reset line name
  234. *
  235. * Managed reset_control_get_shared(). For reset controllers returned from
  236. * this function, reset_control_put() is called automatically on driver detach.
  237. * See reset_control_get_shared() for more information.
  238. */
  239. static inline struct reset_control *devm_reset_control_get_shared(
  240. struct device *dev, const char *id)
  241. {
  242. return __devm_reset_control_get(dev, id, 0, 1);
  243. }
  244. static inline struct reset_control *devm_reset_control_get_optional_exclusive(
  245. struct device *dev, const char *id)
  246. {
  247. return __devm_reset_control_get(dev, id, 0, 0);
  248. }
  249. static inline struct reset_control *devm_reset_control_get_optional_shared(
  250. struct device *dev, const char *id)
  251. {
  252. return __devm_reset_control_get(dev, id, 0, 1);
  253. }
  254. /**
  255. * devm_reset_control_get_exclusive_by_index - resource managed
  256. * reset_control_get_exclusive()
  257. * @dev: device to be reset by the controller
  258. * @index: index of the reset controller
  259. *
  260. * Managed reset_control_get_exclusive(). For reset controllers returned from
  261. * this function, reset_control_put() is called automatically on driver
  262. * detach.
  263. *
  264. * See reset_control_get_exclusive() for more information.
  265. */
  266. static inline struct reset_control *
  267. devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
  268. {
  269. return __devm_reset_control_get(dev, NULL, index, 0);
  270. }
  271. /**
  272. * devm_reset_control_get_shared_by_index - resource managed
  273. * reset_control_get_shared
  274. * @dev: device to be reset by the controller
  275. * @index: index of the reset controller
  276. *
  277. * Managed reset_control_get_shared(). For reset controllers returned from
  278. * this function, reset_control_put() is called automatically on driver detach.
  279. * See reset_control_get_shared() for more information.
  280. */
  281. static inline struct reset_control *
  282. devm_reset_control_get_shared_by_index(struct device *dev, int index)
  283. {
  284. return __devm_reset_control_get(dev, NULL, index, 1);
  285. }
  286. /*
  287. * TEMPORARY calls to use during transition:
  288. *
  289. * of_reset_control_get() => of_reset_control_get_exclusive()
  290. *
  291. * These inline function calls will be removed once all consumers
  292. * have been moved over to the new explicit API.
  293. */
  294. static inline struct reset_control *reset_control_get(
  295. struct device *dev, const char *id)
  296. {
  297. return reset_control_get_exclusive(dev, id);
  298. }
  299. static inline struct reset_control *reset_control_get_optional(
  300. struct device *dev, const char *id)
  301. {
  302. return reset_control_get_optional_exclusive(dev, id);
  303. }
  304. static inline struct reset_control *of_reset_control_get(
  305. struct device_node *node, const char *id)
  306. {
  307. return of_reset_control_get_exclusive(node, id);
  308. }
  309. static inline struct reset_control *of_reset_control_get_by_index(
  310. struct device_node *node, int index)
  311. {
  312. return of_reset_control_get_exclusive_by_index(node, index);
  313. }
  314. static inline struct reset_control *devm_reset_control_get(
  315. struct device *dev, const char *id)
  316. {
  317. return devm_reset_control_get_exclusive(dev, id);
  318. }
  319. static inline struct reset_control *devm_reset_control_get_optional(
  320. struct device *dev, const char *id)
  321. {
  322. return devm_reset_control_get_optional_exclusive(dev, id);
  323. }
  324. static inline struct reset_control *devm_reset_control_get_by_index(
  325. struct device *dev, int index)
  326. {
  327. return devm_reset_control_get_exclusive_by_index(dev, index);
  328. }
  329. #endif