qal_vbus_dev.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. /**
  20. * DOC: qal_vbus_dev
  21. * QCA abstraction layer (QAL) virtual bus management APIs
  22. */
  23. #if !defined(__QAL_VBUS_DEV_H)
  24. #define __QAL_VBUS_DEV_H
  25. /* Include Files */
  26. #include <qdf_types.h>
  27. #include <i_qal_vbus_dev.h>
  28. struct qdf_vbus_resource;
  29. struct qdf_vbus_rstctl;
  30. struct qdf_dev_clk;
  31. struct qdf_pfm_hndl;
  32. struct qdf_pfm_drv;
  33. struct qdf_device_node;
  34. typedef __qdf_of_gpio_flags qdf_of_gpio_flags;
  35. #ifdef ENHANCED_OS_ABSTRACTION
  36. /**
  37. * qal_vbus_get_iorsc() - acquire io resource
  38. * @devnum: Device Number
  39. * @flag: Property bitmap for the io resource
  40. * @devname: Device name string
  41. *
  42. * This function will allocate the io resource for a device
  43. *
  44. * Return: QDF_STATUS_SUCCESS on success
  45. */
  46. QDF_STATUS
  47. qal_vbus_get_iorsc(int devnum, uint32_t flag, char *devname);
  48. /**
  49. * qal_vbus_release_iorsc() - release io resource
  50. * @devnum: Device Number
  51. *
  52. * This function will release the io resource attached to a device
  53. *
  54. * Return: QDF_STATUS_SUCCESS on success
  55. */
  56. QDF_STATUS
  57. qal_vbus_release_iorsc(int devnum);
  58. /**
  59. * qal_vbus_allocate_iorsc() - allocate io resource
  60. * @pinnum: pin Number
  61. * @label: pin name string
  62. *
  63. * This function will allocate the io resource for a device
  64. *
  65. * Return: QDF_STATUS_SUCCESS on success
  66. */
  67. QDF_STATUS
  68. qal_vbus_allocate_iorsc(unsigned int pinnum, const char *label);
  69. /**
  70. * qal_vbus_iorsc_dir_output() - set pin dirction to output
  71. * @pin: pin Number
  72. * @val: value
  73. *
  74. * This function set the gpio pin direction to output
  75. *
  76. * Return: 0 on success, error no on failure
  77. */
  78. QDF_STATUS
  79. qal_vbus_iorsc_dir_output(unsigned int pin, int val);
  80. /**
  81. * qal_vbus_iorsc_set_value() - set pin direction
  82. * @pin: pin Number
  83. * @val: value
  84. *
  85. * This function set the gpio pin direction based on value
  86. *
  87. * Return: QDF_STATUS_SUCCESS on success
  88. */
  89. QDF_STATUS
  90. qal_vbus_iorsc_set_value(unsigned int pin, int val);
  91. /**
  92. * qal_vbus_iorsc_toirq() - set irq number to gpio
  93. * @pin: pin Number
  94. *
  95. * This function set the irq number to gpio pin
  96. *
  97. * Return: QDF_STATUS_SUCCESS on success
  98. */
  99. QDF_STATUS
  100. qal_vbus_iorsc_toirq(unsigned int pin);
  101. /**
  102. * qal_vbus_request_irq() - set interrupt handler
  103. * @irqnum: irq Number
  104. * @handler: function handler to be called
  105. * @flags: irq flags
  106. * @dev_name: device name
  107. * @ctx: pointer to device context
  108. * This function set up the handling of the interrupt
  109. *
  110. * Return: QDF_STATUS_SUCCESS on success, Error code on failure
  111. */
  112. QDF_STATUS
  113. qal_vbus_request_irq(unsigned int irqnum,
  114. irqreturn_t (*handler)(int irq, void *arg),
  115. unsigned long flags, const char *dev_name,
  116. void *ctx);
  117. /**
  118. * __qal_vbus_free_irq() - free irq
  119. * @irqnum: irq Number
  120. * @ctx: pointer to device context
  121. *
  122. * This function free the irq number set to gpio pin
  123. *
  124. * Return: QDF_STATUS_SUCCESS on success
  125. */
  126. static inline QDF_STATUS
  127. __qal_vbus_free_irq(unsigned int irqnum, void *ctx);
  128. /**
  129. * qal_vbus_enable_devclk() - enable device clock
  130. * @clk: Device clock
  131. *
  132. * This function will enable the clock for a device
  133. *
  134. * Return: QDF_STATUS_SUCCESS on success
  135. */
  136. QDF_STATUS
  137. qal_vbus_enable_devclk(struct qdf_dev_clk *clk);
  138. /**
  139. * qal_vbus_disable_devclk() - disable device clock
  140. * @clk: Device clock
  141. *
  142. * This function will disable the clock for a device
  143. *
  144. * Return: QDF_STATUS_SUCCESS on success
  145. */
  146. QDF_STATUS
  147. qal_vbus_disable_devclk(struct qdf_dev_clk *clk);
  148. /**
  149. * qal_vbus_get_dev_rstctl() - get device reset control
  150. * @pfhndl: Device handle
  151. * @state: Device state information
  152. * @rstctl: Device reset control handle
  153. *
  154. * This function will acquire the control to reset the device
  155. *
  156. * Return: QDF_STATUS_SUCCESS on success
  157. */
  158. QDF_STATUS
  159. qal_vbus_get_dev_rstctl(struct qdf_pfm_hndl *pfhndl, const char *state,
  160. struct qdf_vbus_rstctl **rstctl);
  161. /**
  162. * qal_vbus_release_dev_rstctl() - release device reset control
  163. * @pfhndl: Device handle
  164. * @rstctl: Device reset control handle
  165. *
  166. * This function will release the control to reset the device
  167. *
  168. * Return: QDF_STATUS_SUCCESS on success
  169. */
  170. QDF_STATUS
  171. qal_vbus_release_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
  172. struct qdf_vbus_rstctl *rstctl);
  173. /**
  174. * qal_vbus_activate_dev_rstctl() - activate device reset control
  175. * @pfhndl: Device handle
  176. * @rstctl: Device reset control handle
  177. *
  178. * This function will activate the reset control for the device
  179. *
  180. * Return: QDF_STATUS_SUCCESS on success
  181. */
  182. QDF_STATUS
  183. qal_vbus_activate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
  184. struct qdf_vbus_rstctl *rstctl);
  185. /**
  186. * qal_vbus_deactivate_dev_rstctl() - deactivate device reset control
  187. * @pfhndl: Device handle
  188. * @rstctl: Device reset control handle
  189. *
  190. * This function will deactivate the reset control for the device
  191. *
  192. * Return: QDF_STATUS_SUCCESS on success
  193. */
  194. QDF_STATUS
  195. qal_vbus_deactivate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
  196. struct qdf_vbus_rstctl *rstctl);
  197. /**
  198. * qal_vbus_get_resource() - get resource
  199. * @pfhndl: Device handle
  200. * @rsc: Resource handle
  201. * @restype: Resource type
  202. * @residx: Resource index
  203. *
  204. * This function will acquire a particular resource and attach it to the device
  205. *
  206. * Return: QDF_STATUS_SUCCESS on success
  207. */
  208. QDF_STATUS
  209. qal_vbus_get_resource(struct qdf_pfm_hndl *pfhndl,
  210. struct qdf_vbus_resource **rsc, uint32_t restype,
  211. uint32_t residx);
  212. /**
  213. * qal_vbus_get_irq() - get irq
  214. * @pfhndl: Device handle
  215. * @str: Device identifier
  216. * @irq: irq number
  217. *
  218. * This function will acquire an irq for the device
  219. *
  220. * Return: QDF_STATUS_SUCCESS on success
  221. */
  222. QDF_STATUS
  223. qal_vbus_get_irq(struct qdf_pfm_hndl *pfhndl, const char *str, int *irq);
  224. /**
  225. * qal_vbus_register_driver() - register driver
  226. * @pfdev: Device handle
  227. *
  228. * This function will initialize a device
  229. *
  230. * Return: QDF_STATUS_SUCCESS on success
  231. */
  232. QDF_STATUS
  233. qal_vbus_register_driver(struct qdf_pfm_drv *pfdev);
  234. /**
  235. * qal_vbus_deregister_driver() - deregister driver
  236. * @pfdev: Device handle
  237. *
  238. * This function will deregister the driver for a device
  239. *
  240. * Return: QDF_STATUS_SUCCESS on success
  241. */
  242. QDF_STATUS
  243. qal_vbus_deregister_driver(struct qdf_pfm_drv *pfdev);
  244. /**
  245. * qal_vbus_gpio_set_value_cansleep() - assign a gpio's value
  246. * @gpio: gpio whose value will be assigned
  247. * @value: value to assign
  248. *
  249. * Return: QDF_STATUS_SUCCESS on success
  250. */
  251. QDF_STATUS
  252. qal_vbus_gpio_set_value_cansleep(unsigned int gpio, int value);
  253. /**
  254. * qal_vbus_rcu_read_lock() - mark the beginning of an RCU read-side critical
  255. * section
  256. *
  257. * Return: QDF_STATUS_SUCCESS on success
  258. */
  259. QDF_STATUS
  260. qal_vbus_rcu_read_lock(void);
  261. /**
  262. * qal_vbus_rcu_read_unlock() - mark the end of an RCU read-side critical
  263. * section
  264. *
  265. * Return: QDF_STATUS_SUCCESS on success
  266. */
  267. QDF_STATUS
  268. qal_vbus_rcu_read_unlock(void);
  269. /**
  270. * qal_vbus_of_get_named_gpio_flags() - Get a GPIO descriptor and flags
  271. * for GPIO API
  272. * @np: device node to get GPIO from
  273. * @list_name: property name containing gpio specifier(s)
  274. * @index: index of the GPIO
  275. * @flags: a flags pointer to fill in
  276. *
  277. * The global GPIO number for the GPIO specified by its descriptor.
  278. */
  279. int
  280. qal_vbus_of_get_named_gpio_flags(struct qdf_device_node *np,
  281. const char *list_name,
  282. int index, qdf_of_gpio_flags *flags);
  283. #else
  284. static inline QDF_STATUS
  285. qal_vbus_get_iorsc(int devnum, uint32_t flag, char *devname)
  286. {
  287. return __qal_vbus_get_iorsc(devnum, flag, devname);
  288. }
  289. static inline QDF_STATUS
  290. qal_vbus_allocate_iorsc(unsigned int pinnum, const char *label)
  291. {
  292. return __qal_vbus_allocate_iorsc(pinnum, label);
  293. }
  294. static inline QDF_STATUS
  295. qal_vbus_iorsc_dir_output(unsigned int pin, int val)
  296. {
  297. return __qal_vbus_iorsc_dir_output(pin, val);
  298. }
  299. static inline QDF_STATUS
  300. qal_vbus_iorsc_set_value(unsigned int pin, int val)
  301. {
  302. return __qal_vbus_iorsc_set_value(pin, val);
  303. }
  304. static inline QDF_STATUS
  305. qal_vbus_release_iorsc(int devnum)
  306. {
  307. return __qal_vbus_release_iorsc(devnum);
  308. }
  309. static inline QDF_STATUS
  310. qal_vbus_iorsc_toirq(unsigned int pin)
  311. {
  312. return __qal_vbus_iorsc_toirq(pin);
  313. }
  314. static inline QDF_STATUS
  315. qal_vbus_request_irq(unsigned int irqnum,
  316. irqreturn_t (*handler)(int irq, void *arg),
  317. unsigned long flags, const char *dev_name, void *ctx)
  318. {
  319. return __qal_vbus_request_irq(irqnum, handler, flags, dev_name, ctx);
  320. }
  321. static inline QDF_STATUS
  322. qal_vbus_free_irq(unsigned int irqnum, void *ctx)
  323. {
  324. return __qal_vbus_free_irq(irqnum, ctx);
  325. }
  326. static inline QDF_STATUS
  327. qal_vbus_enable_devclk(struct qdf_dev_clk *clk)
  328. {
  329. return __qal_vbus_enable_devclk(clk);
  330. }
  331. static inline QDF_STATUS
  332. qal_vbus_disable_devclk(struct qdf_dev_clk *clk)
  333. {
  334. return __qal_vbus_disable_devclk(clk);
  335. }
  336. static inline QDF_STATUS
  337. qal_vbus_get_dev_rstctl(struct qdf_pfm_hndl *pfhndl, const char *state,
  338. struct qdf_vbus_rstctl **rstctl)
  339. {
  340. return __qal_vbus_get_dev_rstctl(pfhndl, state, rstctl);
  341. }
  342. static inline QDF_STATUS
  343. qal_vbus_release_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
  344. struct qdf_vbus_rstctl *rstctl)
  345. {
  346. return __qal_vbus_release_dev_rstctl(pfhndl, rstctl);
  347. }
  348. static inline QDF_STATUS
  349. qal_vbus_activate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
  350. struct qdf_vbus_rstctl *rstctl)
  351. {
  352. return __qal_vbus_activate_dev_rstctl(pfhndl, rstctl);
  353. }
  354. static inline QDF_STATUS
  355. qal_vbus_deactivate_dev_rstctl(struct qdf_pfm_hndl *pfhndl,
  356. struct qdf_vbus_rstctl *rstctl)
  357. {
  358. return __qal_vbus_deactivate_dev_rstctl(pfhndl, rstctl);
  359. }
  360. static inline QDF_STATUS
  361. qal_vbus_get_resource(struct qdf_pfm_hndl *pfhndl,
  362. struct qdf_vbus_resource **rsc, uint32_t restype,
  363. uint32_t residx)
  364. {
  365. return __qal_vbus_get_resource(pfhndl, rsc, restype, residx);
  366. }
  367. static inline QDF_STATUS
  368. qal_vbus_get_irq(struct qdf_pfm_hndl *pfhndl, const char *str, int *irq)
  369. {
  370. return __qal_vbus_get_irq(pfhndl, str, irq);
  371. }
  372. static inline QDF_STATUS
  373. qal_vbus_register_driver(struct qdf_pfm_drv *pfdev)
  374. {
  375. return __qal_vbus_register_driver(pfdev);
  376. }
  377. static inline QDF_STATUS
  378. qal_vbus_deregister_driver(struct qdf_pfm_drv *pfdev)
  379. {
  380. return __qal_vbus_deregister_driver(pfdev);
  381. }
  382. static inline QDF_STATUS
  383. qal_vbus_gpio_set_value_cansleep(unsigned int gpio, int value)
  384. {
  385. return __qal_vbus_gpio_set_value_cansleep(gpio, value);
  386. }
  387. static inline QDF_STATUS
  388. qal_vbus_rcu_read_lock(void)
  389. {
  390. return __qal_vbus_rcu_read_lock();
  391. }
  392. static inline QDF_STATUS
  393. qal_vbus_rcu_read_unlock(void)
  394. {
  395. return __qal_vbus_rcu_read_unlock();
  396. }
  397. static inline int
  398. qal_vbus_of_get_named_gpio_flags(struct qdf_device_node *np,
  399. const char *list_name,
  400. int index, qdf_of_gpio_flags *flags)
  401. {
  402. return __qal_vbus_of_get_named_gpio_flags(np, list_name, index, flags);
  403. }
  404. #endif
  405. #endif /* __QAL_VBUS_DEV_H */