reset.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_RESET_H_
  3. #define _LINUX_RESET_H_
  4. #include <linux/err.h>
  5. #include <linux/errno.h>
  6. #include <linux/types.h>
  7. struct device;
  8. struct device_node;
  9. struct reset_control;
  10. /**
  11. * struct reset_control_bulk_data - Data used for bulk reset control operations.
  12. *
  13. * @id: reset control consumer ID
  14. * @rstc: struct reset_control * to store the associated reset control
  15. *
  16. * The reset APIs provide a series of reset_control_bulk_*() API calls as
  17. * a convenience to consumers which require multiple reset controls.
  18. * This structure is used to manage data for these calls.
  19. */
  20. struct reset_control_bulk_data {
  21. const char *id;
  22. struct reset_control *rstc;
  23. };
  24. #ifdef CONFIG_RESET_CONTROLLER
  25. int reset_control_reset(struct reset_control *rstc);
  26. int reset_control_rearm(struct reset_control *rstc);
  27. int reset_control_assert(struct reset_control *rstc);
  28. int reset_control_deassert(struct reset_control *rstc);
  29. int reset_control_status(struct reset_control *rstc);
  30. int reset_control_acquire(struct reset_control *rstc);
  31. void reset_control_release(struct reset_control *rstc);
  32. int reset_control_bulk_reset(int num_rstcs, struct reset_control_bulk_data *rstcs);
  33. int reset_control_bulk_assert(int num_rstcs, struct reset_control_bulk_data *rstcs);
  34. int reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *rstcs);
  35. int reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs);
  36. void reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs);
  37. struct reset_control *__of_reset_control_get(struct device_node *node,
  38. const char *id, int index, bool shared,
  39. bool optional, bool acquired);
  40. struct reset_control *__reset_control_get(struct device *dev, const char *id,
  41. int index, bool shared,
  42. bool optional, bool acquired);
  43. void reset_control_put(struct reset_control *rstc);
  44. int __reset_control_bulk_get(struct device *dev, int num_rstcs,
  45. struct reset_control_bulk_data *rstcs,
  46. bool shared, bool optional, bool acquired);
  47. void reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs);
  48. int __device_reset(struct device *dev, bool optional);
  49. struct reset_control *__devm_reset_control_get(struct device *dev,
  50. const char *id, int index, bool shared,
  51. bool optional, bool acquired);
  52. int __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
  53. struct reset_control_bulk_data *rstcs,
  54. bool shared, bool optional, bool acquired);
  55. struct reset_control *devm_reset_control_array_get(struct device *dev,
  56. bool shared, bool optional);
  57. struct reset_control *of_reset_control_array_get(struct device_node *np,
  58. bool shared, bool optional,
  59. bool acquired);
  60. int reset_control_get_count(struct device *dev);
  61. #else
  62. static inline int reset_control_reset(struct reset_control *rstc)
  63. {
  64. return 0;
  65. }
  66. static inline int reset_control_rearm(struct reset_control *rstc)
  67. {
  68. return 0;
  69. }
  70. static inline int reset_control_assert(struct reset_control *rstc)
  71. {
  72. return 0;
  73. }
  74. static inline int reset_control_deassert(struct reset_control *rstc)
  75. {
  76. return 0;
  77. }
  78. static inline int reset_control_status(struct reset_control *rstc)
  79. {
  80. return 0;
  81. }
  82. static inline int reset_control_acquire(struct reset_control *rstc)
  83. {
  84. return 0;
  85. }
  86. static inline void reset_control_release(struct reset_control *rstc)
  87. {
  88. }
  89. static inline void reset_control_put(struct reset_control *rstc)
  90. {
  91. }
  92. static inline int __device_reset(struct device *dev, bool optional)
  93. {
  94. return optional ? 0 : -ENOTSUPP;
  95. }
  96. static inline struct reset_control *__of_reset_control_get(
  97. struct device_node *node,
  98. const char *id, int index, bool shared,
  99. bool optional, bool acquired)
  100. {
  101. return optional ? NULL : ERR_PTR(-ENOTSUPP);
  102. }
  103. static inline struct reset_control *__reset_control_get(
  104. struct device *dev, const char *id,
  105. int index, bool shared, bool optional,
  106. bool acquired)
  107. {
  108. return optional ? NULL : ERR_PTR(-ENOTSUPP);
  109. }
  110. static inline int
  111. reset_control_bulk_reset(int num_rstcs, struct reset_control_bulk_data *rstcs)
  112. {
  113. return 0;
  114. }
  115. static inline int
  116. reset_control_bulk_assert(int num_rstcs, struct reset_control_bulk_data *rstcs)
  117. {
  118. return 0;
  119. }
  120. static inline int
  121. reset_control_bulk_deassert(int num_rstcs, struct reset_control_bulk_data *rstcs)
  122. {
  123. return 0;
  124. }
  125. static inline int
  126. reset_control_bulk_acquire(int num_rstcs, struct reset_control_bulk_data *rstcs)
  127. {
  128. return 0;
  129. }
  130. static inline void
  131. reset_control_bulk_release(int num_rstcs, struct reset_control_bulk_data *rstcs)
  132. {
  133. }
  134. static inline int
  135. __reset_control_bulk_get(struct device *dev, int num_rstcs,
  136. struct reset_control_bulk_data *rstcs,
  137. bool shared, bool optional, bool acquired)
  138. {
  139. return optional ? 0 : -EOPNOTSUPP;
  140. }
  141. static inline void
  142. reset_control_bulk_put(int num_rstcs, struct reset_control_bulk_data *rstcs)
  143. {
  144. }
  145. static inline struct reset_control *__devm_reset_control_get(
  146. struct device *dev, const char *id,
  147. int index, bool shared, bool optional,
  148. bool acquired)
  149. {
  150. return optional ? NULL : ERR_PTR(-ENOTSUPP);
  151. }
  152. static inline int
  153. __devm_reset_control_bulk_get(struct device *dev, int num_rstcs,
  154. struct reset_control_bulk_data *rstcs,
  155. bool shared, bool optional, bool acquired)
  156. {
  157. return optional ? 0 : -EOPNOTSUPP;
  158. }
  159. static inline struct reset_control *
  160. devm_reset_control_array_get(struct device *dev, bool shared, bool optional)
  161. {
  162. return optional ? NULL : ERR_PTR(-ENOTSUPP);
  163. }
  164. static inline struct reset_control *
  165. of_reset_control_array_get(struct device_node *np, bool shared, bool optional,
  166. bool acquired)
  167. {
  168. return optional ? NULL : ERR_PTR(-ENOTSUPP);
  169. }
  170. static inline int reset_control_get_count(struct device *dev)
  171. {
  172. return -ENOENT;
  173. }
  174. #endif /* CONFIG_RESET_CONTROLLER */
  175. static inline int __must_check device_reset(struct device *dev)
  176. {
  177. return __device_reset(dev, false);
  178. }
  179. static inline int device_reset_optional(struct device *dev)
  180. {
  181. return __device_reset(dev, true);
  182. }
  183. /**
  184. * reset_control_get_exclusive - Lookup and obtain an exclusive reference
  185. * to a reset controller.
  186. * @dev: device to be reset by the controller
  187. * @id: reset line name
  188. *
  189. * Returns a struct reset_control or IS_ERR() condition containing errno.
  190. * If this function is called more than once for the same reset_control it will
  191. * return -EBUSY.
  192. *
  193. * See reset_control_get_shared() for details on shared references to
  194. * reset-controls.
  195. *
  196. * Use of id names is optional.
  197. */
  198. static inline struct reset_control *
  199. __must_check reset_control_get_exclusive(struct device *dev, const char *id)
  200. {
  201. return __reset_control_get(dev, id, 0, false, false, true);
  202. }
  203. /**
  204. * reset_control_bulk_get_exclusive - Lookup and obtain exclusive references to
  205. * multiple reset controllers.
  206. * @dev: device to be reset by the controller
  207. * @num_rstcs: number of entries in rstcs array
  208. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  209. *
  210. * Fills the rstcs array with pointers to exclusive reset controls and
  211. * returns 0, or an IS_ERR() condition containing errno.
  212. */
  213. static inline int __must_check
  214. reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs,
  215. struct reset_control_bulk_data *rstcs)
  216. {
  217. return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, false, true);
  218. }
  219. /**
  220. * reset_control_get_exclusive_released - Lookup and obtain a temoprarily
  221. * exclusive reference to a reset
  222. * controller.
  223. * @dev: device to be reset by the controller
  224. * @id: reset line name
  225. *
  226. * Returns a struct reset_control or IS_ERR() condition containing errno.
  227. * reset-controls returned by this function must be acquired via
  228. * reset_control_acquire() before they can be used and should be released
  229. * via reset_control_release() afterwards.
  230. *
  231. * Use of id names is optional.
  232. */
  233. static inline struct reset_control *
  234. __must_check reset_control_get_exclusive_released(struct device *dev,
  235. const char *id)
  236. {
  237. return __reset_control_get(dev, id, 0, false, false, false);
  238. }
  239. /**
  240. * reset_control_bulk_get_exclusive_released - Lookup and obtain temporarily
  241. * exclusive references to multiple reset
  242. * controllers.
  243. * @dev: device to be reset by the controller
  244. * @num_rstcs: number of entries in rstcs array
  245. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  246. *
  247. * Fills the rstcs array with pointers to exclusive reset controls and
  248. * returns 0, or an IS_ERR() condition containing errno.
  249. * reset-controls returned by this function must be acquired via
  250. * reset_control_bulk_acquire() before they can be used and should be released
  251. * via reset_control_bulk_release() afterwards.
  252. */
  253. static inline int __must_check
  254. reset_control_bulk_get_exclusive_released(struct device *dev, int num_rstcs,
  255. struct reset_control_bulk_data *rstcs)
  256. {
  257. return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, false, false);
  258. }
  259. /**
  260. * reset_control_bulk_get_optional_exclusive_released - Lookup and obtain optional
  261. * temporarily exclusive references to multiple
  262. * reset controllers.
  263. * @dev: device to be reset by the controller
  264. * @num_rstcs: number of entries in rstcs array
  265. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  266. *
  267. * Optional variant of reset_control_bulk_get_exclusive_released(). If the
  268. * requested reset is not specified in the device tree, this function returns 0
  269. * instead of an error and missing rtsc is set to NULL.
  270. *
  271. * See reset_control_bulk_get_exclusive_released() for more information.
  272. */
  273. static inline int __must_check
  274. reset_control_bulk_get_optional_exclusive_released(struct device *dev, int num_rstcs,
  275. struct reset_control_bulk_data *rstcs)
  276. {
  277. return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, false);
  278. }
  279. /**
  280. * reset_control_get_shared - Lookup and obtain a shared reference to a
  281. * reset controller.
  282. * @dev: device to be reset by the controller
  283. * @id: reset line name
  284. *
  285. * Returns a struct reset_control or IS_ERR() condition containing errno.
  286. * This function is intended for use with reset-controls which are shared
  287. * between hardware blocks.
  288. *
  289. * When a reset-control is shared, the behavior of reset_control_assert /
  290. * deassert is changed, the reset-core will keep track of a deassert_count
  291. * and only (re-)assert the reset after reset_control_assert has been called
  292. * as many times as reset_control_deassert was called. Also see the remark
  293. * about shared reset-controls in the reset_control_assert docs.
  294. *
  295. * Calling reset_control_assert without first calling reset_control_deassert
  296. * is not allowed on a shared reset control. Calling reset_control_reset is
  297. * also not allowed on a shared reset control.
  298. *
  299. * Use of id names is optional.
  300. */
  301. static inline struct reset_control *reset_control_get_shared(
  302. struct device *dev, const char *id)
  303. {
  304. return __reset_control_get(dev, id, 0, true, false, false);
  305. }
  306. /**
  307. * reset_control_bulk_get_shared - Lookup and obtain shared references to
  308. * multiple reset controllers.
  309. * @dev: device to be reset by the controller
  310. * @num_rstcs: number of entries in rstcs array
  311. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  312. *
  313. * Fills the rstcs array with pointers to shared reset controls and
  314. * returns 0, or an IS_ERR() condition containing errno.
  315. */
  316. static inline int __must_check
  317. reset_control_bulk_get_shared(struct device *dev, int num_rstcs,
  318. struct reset_control_bulk_data *rstcs)
  319. {
  320. return __reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, false);
  321. }
  322. /**
  323. * reset_control_get_optional_exclusive - optional reset_control_get_exclusive()
  324. * @dev: device to be reset by the controller
  325. * @id: reset line name
  326. *
  327. * Optional variant of reset_control_get_exclusive(). If the requested reset
  328. * is not specified in the device tree, this function returns NULL instead of
  329. * an error.
  330. *
  331. * See reset_control_get_exclusive() for more information.
  332. */
  333. static inline struct reset_control *reset_control_get_optional_exclusive(
  334. struct device *dev, const char *id)
  335. {
  336. return __reset_control_get(dev, id, 0, false, true, true);
  337. }
  338. /**
  339. * reset_control_bulk_get_optional_exclusive - optional
  340. * reset_control_bulk_get_exclusive()
  341. * @dev: device to be reset by the controller
  342. * @num_rstcs: number of entries in rstcs array
  343. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  344. *
  345. * Optional variant of reset_control_bulk_get_exclusive(). If any of the
  346. * requested resets are not specified in the device tree, this function sets
  347. * them to NULL instead of returning an error.
  348. *
  349. * See reset_control_bulk_get_exclusive() for more information.
  350. */
  351. static inline int __must_check
  352. reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
  353. struct reset_control_bulk_data *rstcs)
  354. {
  355. return __reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true);
  356. }
  357. /**
  358. * reset_control_get_optional_shared - optional reset_control_get_shared()
  359. * @dev: device to be reset by the controller
  360. * @id: reset line name
  361. *
  362. * Optional variant of reset_control_get_shared(). If the requested reset
  363. * is not specified in the device tree, this function returns NULL instead of
  364. * an error.
  365. *
  366. * See reset_control_get_shared() for more information.
  367. */
  368. static inline struct reset_control *reset_control_get_optional_shared(
  369. struct device *dev, const char *id)
  370. {
  371. return __reset_control_get(dev, id, 0, true, true, false);
  372. }
  373. /**
  374. * reset_control_bulk_get_optional_shared - optional
  375. * reset_control_bulk_get_shared()
  376. * @dev: device to be reset by the controller
  377. * @num_rstcs: number of entries in rstcs array
  378. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  379. *
  380. * Optional variant of reset_control_bulk_get_shared(). If the requested resets
  381. * are not specified in the device tree, this function sets them to NULL
  382. * instead of returning an error.
  383. *
  384. * See reset_control_bulk_get_shared() for more information.
  385. */
  386. static inline int __must_check
  387. reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs,
  388. struct reset_control_bulk_data *rstcs)
  389. {
  390. return __reset_control_bulk_get(dev, num_rstcs, rstcs, true, true, false);
  391. }
  392. /**
  393. * of_reset_control_get_exclusive - Lookup and obtain an exclusive reference
  394. * to a reset controller.
  395. * @node: device to be reset by the controller
  396. * @id: reset line name
  397. *
  398. * Returns a struct reset_control or IS_ERR() condition containing errno.
  399. *
  400. * Use of id names is optional.
  401. */
  402. static inline struct reset_control *of_reset_control_get_exclusive(
  403. struct device_node *node, const char *id)
  404. {
  405. return __of_reset_control_get(node, id, 0, false, false, true);
  406. }
  407. /**
  408. * of_reset_control_get_optional_exclusive - Lookup and obtain an optional exclusive
  409. * reference to a reset controller.
  410. * @node: device to be reset by the controller
  411. * @id: reset line name
  412. *
  413. * Optional variant of of_reset_control_get_exclusive(). If the requested reset
  414. * is not specified in the device tree, this function returns NULL instead of
  415. * an error.
  416. *
  417. * Returns a struct reset_control or IS_ERR() condition containing errno.
  418. *
  419. * Use of id names is optional.
  420. */
  421. static inline struct reset_control *of_reset_control_get_optional_exclusive(
  422. struct device_node *node, const char *id)
  423. {
  424. return __of_reset_control_get(node, id, 0, false, true, true);
  425. }
  426. /**
  427. * of_reset_control_get_shared - Lookup and obtain a shared reference
  428. * to a reset controller.
  429. * @node: device to be reset by the controller
  430. * @id: reset line name
  431. *
  432. * When a reset-control is shared, the behavior of reset_control_assert /
  433. * deassert is changed, the reset-core will keep track of a deassert_count
  434. * and only (re-)assert the reset after reset_control_assert has been called
  435. * as many times as reset_control_deassert was called. Also see the remark
  436. * about shared reset-controls in the reset_control_assert docs.
  437. *
  438. * Calling reset_control_assert without first calling reset_control_deassert
  439. * is not allowed on a shared reset control. Calling reset_control_reset is
  440. * also not allowed on a shared reset control.
  441. * Returns a struct reset_control or IS_ERR() condition containing errno.
  442. *
  443. * Use of id names is optional.
  444. */
  445. static inline struct reset_control *of_reset_control_get_shared(
  446. struct device_node *node, const char *id)
  447. {
  448. return __of_reset_control_get(node, id, 0, true, false, false);
  449. }
  450. /**
  451. * of_reset_control_get_exclusive_by_index - Lookup and obtain an exclusive
  452. * reference to a reset controller
  453. * by index.
  454. * @node: device to be reset by the controller
  455. * @index: index of the reset controller
  456. *
  457. * This is to be used to perform a list of resets for a device or power domain
  458. * in whatever order. Returns a struct reset_control or IS_ERR() condition
  459. * containing errno.
  460. */
  461. static inline struct reset_control *of_reset_control_get_exclusive_by_index(
  462. struct device_node *node, int index)
  463. {
  464. return __of_reset_control_get(node, NULL, index, false, false, true);
  465. }
  466. /**
  467. * of_reset_control_get_shared_by_index - Lookup and obtain a shared
  468. * reference to a reset controller
  469. * by index.
  470. * @node: device to be reset by the controller
  471. * @index: index of the reset controller
  472. *
  473. * When a reset-control is shared, the behavior of reset_control_assert /
  474. * deassert is changed, the reset-core will keep track of a deassert_count
  475. * and only (re-)assert the reset after reset_control_assert has been called
  476. * as many times as reset_control_deassert was called. Also see the remark
  477. * about shared reset-controls in the reset_control_assert docs.
  478. *
  479. * Calling reset_control_assert without first calling reset_control_deassert
  480. * is not allowed on a shared reset control. Calling reset_control_reset is
  481. * also not allowed on a shared reset control.
  482. * Returns a struct reset_control or IS_ERR() condition containing errno.
  483. *
  484. * This is to be used to perform a list of resets for a device or power domain
  485. * in whatever order. Returns a struct reset_control or IS_ERR() condition
  486. * containing errno.
  487. */
  488. static inline struct reset_control *of_reset_control_get_shared_by_index(
  489. struct device_node *node, int index)
  490. {
  491. return __of_reset_control_get(node, NULL, index, true, false, false);
  492. }
  493. /**
  494. * devm_reset_control_get_exclusive - resource managed
  495. * reset_control_get_exclusive()
  496. * @dev: device to be reset by the controller
  497. * @id: reset line name
  498. *
  499. * Managed reset_control_get_exclusive(). For reset controllers returned
  500. * from this function, reset_control_put() is called automatically on driver
  501. * detach.
  502. *
  503. * See reset_control_get_exclusive() for more information.
  504. */
  505. static inline struct reset_control *
  506. __must_check devm_reset_control_get_exclusive(struct device *dev,
  507. const char *id)
  508. {
  509. return __devm_reset_control_get(dev, id, 0, false, false, true);
  510. }
  511. /**
  512. * devm_reset_control_bulk_get_exclusive - resource managed
  513. * reset_control_bulk_get_exclusive()
  514. * @dev: device to be reset by the controller
  515. * @num_rstcs: number of entries in rstcs array
  516. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  517. *
  518. * Managed reset_control_bulk_get_exclusive(). For reset controllers returned
  519. * from this function, reset_control_put() is called automatically on driver
  520. * detach.
  521. *
  522. * See reset_control_bulk_get_exclusive() for more information.
  523. */
  524. static inline int __must_check
  525. devm_reset_control_bulk_get_exclusive(struct device *dev, int num_rstcs,
  526. struct reset_control_bulk_data *rstcs)
  527. {
  528. return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, false, true);
  529. }
  530. /**
  531. * devm_reset_control_get_exclusive_released - resource managed
  532. * reset_control_get_exclusive_released()
  533. * @dev: device to be reset by the controller
  534. * @id: reset line name
  535. *
  536. * Managed reset_control_get_exclusive_released(). For reset controllers
  537. * returned from this function, reset_control_put() is called automatically on
  538. * driver detach.
  539. *
  540. * See reset_control_get_exclusive_released() for more information.
  541. */
  542. static inline struct reset_control *
  543. __must_check devm_reset_control_get_exclusive_released(struct device *dev,
  544. const char *id)
  545. {
  546. return __devm_reset_control_get(dev, id, 0, false, false, false);
  547. }
  548. /**
  549. * devm_reset_control_bulk_get_exclusive_released - resource managed
  550. * reset_control_bulk_get_exclusive_released()
  551. * @dev: device to be reset by the controller
  552. * @num_rstcs: number of entries in rstcs array
  553. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  554. *
  555. * Managed reset_control_bulk_get_exclusive_released(). For reset controllers
  556. * returned from this function, reset_control_put() is called automatically on
  557. * driver detach.
  558. *
  559. * See reset_control_bulk_get_exclusive_released() for more information.
  560. */
  561. static inline int __must_check
  562. devm_reset_control_bulk_get_exclusive_released(struct device *dev, int num_rstcs,
  563. struct reset_control_bulk_data *rstcs)
  564. {
  565. return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, false, false);
  566. }
  567. /**
  568. * devm_reset_control_get_optional_exclusive_released - resource managed
  569. * reset_control_get_optional_exclusive_released()
  570. * @dev: device to be reset by the controller
  571. * @id: reset line name
  572. *
  573. * Managed-and-optional variant of reset_control_get_exclusive_released(). For
  574. * reset controllers returned from this function, reset_control_put() is called
  575. * automatically on driver detach.
  576. *
  577. * See reset_control_get_exclusive_released() for more information.
  578. */
  579. static inline struct reset_control *
  580. __must_check devm_reset_control_get_optional_exclusive_released(struct device *dev,
  581. const char *id)
  582. {
  583. return __devm_reset_control_get(dev, id, 0, false, true, false);
  584. }
  585. /**
  586. * devm_reset_control_bulk_get_optional_exclusive_released - resource managed
  587. * reset_control_bulk_optional_get_exclusive_released()
  588. * @dev: device to be reset by the controller
  589. * @num_rstcs: number of entries in rstcs array
  590. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  591. *
  592. * Managed reset_control_bulk_optional_get_exclusive_released(). For reset
  593. * controllers returned from this function, reset_control_put() is called
  594. * automatically on driver detach.
  595. *
  596. * See reset_control_bulk_optional_get_exclusive_released() for more information.
  597. */
  598. static inline int __must_check
  599. devm_reset_control_bulk_get_optional_exclusive_released(struct device *dev, int num_rstcs,
  600. struct reset_control_bulk_data *rstcs)
  601. {
  602. return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, false);
  603. }
  604. /**
  605. * devm_reset_control_get_shared - resource managed reset_control_get_shared()
  606. * @dev: device to be reset by the controller
  607. * @id: reset line name
  608. *
  609. * Managed reset_control_get_shared(). For reset controllers returned from
  610. * this function, reset_control_put() is called automatically on driver detach.
  611. * See reset_control_get_shared() for more information.
  612. */
  613. static inline struct reset_control *devm_reset_control_get_shared(
  614. struct device *dev, const char *id)
  615. {
  616. return __devm_reset_control_get(dev, id, 0, true, false, false);
  617. }
  618. /**
  619. * devm_reset_control_bulk_get_shared - resource managed
  620. * reset_control_bulk_get_shared()
  621. * @dev: device to be reset by the controller
  622. * @num_rstcs: number of entries in rstcs array
  623. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  624. *
  625. * Managed reset_control_bulk_get_shared(). For reset controllers returned
  626. * from this function, reset_control_put() is called automatically on driver
  627. * detach.
  628. *
  629. * See reset_control_bulk_get_shared() for more information.
  630. */
  631. static inline int __must_check
  632. devm_reset_control_bulk_get_shared(struct device *dev, int num_rstcs,
  633. struct reset_control_bulk_data *rstcs)
  634. {
  635. return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, false, false);
  636. }
  637. /**
  638. * devm_reset_control_get_optional_exclusive - resource managed
  639. * reset_control_get_optional_exclusive()
  640. * @dev: device to be reset by the controller
  641. * @id: reset line name
  642. *
  643. * Managed reset_control_get_optional_exclusive(). For reset controllers
  644. * returned from this function, reset_control_put() is called automatically on
  645. * driver detach.
  646. *
  647. * See reset_control_get_optional_exclusive() for more information.
  648. */
  649. static inline struct reset_control *devm_reset_control_get_optional_exclusive(
  650. struct device *dev, const char *id)
  651. {
  652. return __devm_reset_control_get(dev, id, 0, false, true, true);
  653. }
  654. /**
  655. * devm_reset_control_bulk_get_optional_exclusive - resource managed
  656. * reset_control_bulk_get_optional_exclusive()
  657. * @dev: device to be reset by the controller
  658. * @num_rstcs: number of entries in rstcs array
  659. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  660. *
  661. * Managed reset_control_bulk_get_optional_exclusive(). For reset controllers
  662. * returned from this function, reset_control_put() is called automatically on
  663. * driver detach.
  664. *
  665. * See reset_control_bulk_get_optional_exclusive() for more information.
  666. */
  667. static inline int __must_check
  668. devm_reset_control_bulk_get_optional_exclusive(struct device *dev, int num_rstcs,
  669. struct reset_control_bulk_data *rstcs)
  670. {
  671. return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, false, true, true);
  672. }
  673. /**
  674. * devm_reset_control_get_optional_shared - resource managed
  675. * reset_control_get_optional_shared()
  676. * @dev: device to be reset by the controller
  677. * @id: reset line name
  678. *
  679. * Managed reset_control_get_optional_shared(). For reset controllers returned
  680. * from this function, reset_control_put() is called automatically on driver
  681. * detach.
  682. *
  683. * See reset_control_get_optional_shared() for more information.
  684. */
  685. static inline struct reset_control *devm_reset_control_get_optional_shared(
  686. struct device *dev, const char *id)
  687. {
  688. return __devm_reset_control_get(dev, id, 0, true, true, false);
  689. }
  690. /**
  691. * devm_reset_control_bulk_get_optional_shared - resource managed
  692. * reset_control_bulk_get_optional_shared()
  693. * @dev: device to be reset by the controller
  694. * @num_rstcs: number of entries in rstcs array
  695. * @rstcs: array of struct reset_control_bulk_data with reset line names set
  696. *
  697. * Managed reset_control_bulk_get_optional_shared(). For reset controllers
  698. * returned from this function, reset_control_put() is called automatically on
  699. * driver detach.
  700. *
  701. * See reset_control_bulk_get_optional_shared() for more information.
  702. */
  703. static inline int __must_check
  704. devm_reset_control_bulk_get_optional_shared(struct device *dev, int num_rstcs,
  705. struct reset_control_bulk_data *rstcs)
  706. {
  707. return __devm_reset_control_bulk_get(dev, num_rstcs, rstcs, true, true, false);
  708. }
  709. /**
  710. * devm_reset_control_get_exclusive_by_index - resource managed
  711. * reset_control_get_exclusive()
  712. * @dev: device to be reset by the controller
  713. * @index: index of the reset controller
  714. *
  715. * Managed reset_control_get_exclusive(). For reset controllers returned from
  716. * this function, reset_control_put() is called automatically on driver
  717. * detach.
  718. *
  719. * See reset_control_get_exclusive() for more information.
  720. */
  721. static inline struct reset_control *
  722. devm_reset_control_get_exclusive_by_index(struct device *dev, int index)
  723. {
  724. return __devm_reset_control_get(dev, NULL, index, false, false, true);
  725. }
  726. /**
  727. * devm_reset_control_get_shared_by_index - resource managed
  728. * reset_control_get_shared
  729. * @dev: device to be reset by the controller
  730. * @index: index of the reset controller
  731. *
  732. * Managed reset_control_get_shared(). For reset controllers returned from
  733. * this function, reset_control_put() is called automatically on driver detach.
  734. * See reset_control_get_shared() for more information.
  735. */
  736. static inline struct reset_control *
  737. devm_reset_control_get_shared_by_index(struct device *dev, int index)
  738. {
  739. return __devm_reset_control_get(dev, NULL, index, true, false, false);
  740. }
  741. /*
  742. * TEMPORARY calls to use during transition:
  743. *
  744. * of_reset_control_get() => of_reset_control_get_exclusive()
  745. *
  746. * These inline function calls will be removed once all consumers
  747. * have been moved over to the new explicit API.
  748. */
  749. static inline struct reset_control *of_reset_control_get(
  750. struct device_node *node, const char *id)
  751. {
  752. return of_reset_control_get_exclusive(node, id);
  753. }
  754. static inline struct reset_control *of_reset_control_get_by_index(
  755. struct device_node *node, int index)
  756. {
  757. return of_reset_control_get_exclusive_by_index(node, index);
  758. }
  759. static inline struct reset_control *devm_reset_control_get(
  760. struct device *dev, const char *id)
  761. {
  762. return devm_reset_control_get_exclusive(dev, id);
  763. }
  764. static inline struct reset_control *devm_reset_control_get_optional(
  765. struct device *dev, const char *id)
  766. {
  767. return devm_reset_control_get_optional_exclusive(dev, id);
  768. }
  769. static inline struct reset_control *devm_reset_control_get_by_index(
  770. struct device *dev, int index)
  771. {
  772. return devm_reset_control_get_exclusive_by_index(dev, index);
  773. }
  774. /*
  775. * APIs to manage a list of reset controllers
  776. */
  777. static inline struct reset_control *
  778. devm_reset_control_array_get_exclusive(struct device *dev)
  779. {
  780. return devm_reset_control_array_get(dev, false, false);
  781. }
  782. static inline struct reset_control *
  783. devm_reset_control_array_get_shared(struct device *dev)
  784. {
  785. return devm_reset_control_array_get(dev, true, false);
  786. }
  787. static inline struct reset_control *
  788. devm_reset_control_array_get_optional_exclusive(struct device *dev)
  789. {
  790. return devm_reset_control_array_get(dev, false, true);
  791. }
  792. static inline struct reset_control *
  793. devm_reset_control_array_get_optional_shared(struct device *dev)
  794. {
  795. return devm_reset_control_array_get(dev, true, true);
  796. }
  797. static inline struct reset_control *
  798. of_reset_control_array_get_exclusive(struct device_node *node)
  799. {
  800. return of_reset_control_array_get(node, false, false, true);
  801. }
  802. static inline struct reset_control *
  803. of_reset_control_array_get_exclusive_released(struct device_node *node)
  804. {
  805. return of_reset_control_array_get(node, false, false, false);
  806. }
  807. static inline struct reset_control *
  808. of_reset_control_array_get_shared(struct device_node *node)
  809. {
  810. return of_reset_control_array_get(node, true, false, true);
  811. }
  812. static inline struct reset_control *
  813. of_reset_control_array_get_optional_exclusive(struct device_node *node)
  814. {
  815. return of_reset_control_array_get(node, false, true, true);
  816. }
  817. static inline struct reset_control *
  818. of_reset_control_array_get_optional_shared(struct device_node *node)
  819. {
  820. return of_reset_control_array_get(node, true, true, true);
  821. }
  822. #endif