cam_io_util.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2011-2014, 2017-2018, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_IO_UTIL_H_
  6. #define _CAM_IO_UTIL_H_
  7. #include <linux/types.h>
  8. /**
  9. * cam_io_w()
  10. *
  11. * @brief: Camera IO util for register write
  12. *
  13. * @data: Value to be written
  14. * @addr: Address used to write the value
  15. *
  16. * @return: Success or Failure
  17. */
  18. int cam_io_w(uint32_t data, void __iomem *addr);
  19. /**
  20. * cam_io_w_mb()
  21. *
  22. * @brief: Camera IO util for register write with memory barrier.
  23. * Memory Barrier is only before the write to ensure the
  24. * order. If need to ensure this write is also flushed
  25. * call wmb() independently in the caller.
  26. *
  27. * @data: Value to be written
  28. * @addr: Address used to write the value
  29. *
  30. * @return: Success or Failure
  31. */
  32. int cam_io_w_mb(uint32_t data, void __iomem *addr);
  33. /**
  34. * cam_io_r()
  35. *
  36. * @brief: Camera IO util for register read
  37. *
  38. * @addr: Address of register to be read
  39. *
  40. * @return: Value read from the register address
  41. */
  42. uint32_t cam_io_r(void __iomem *addr);
  43. /**
  44. * cam_io_r_mb()
  45. *
  46. * @brief: Camera IO util for register read with memory barrier.
  47. * Memory Barrier is only before the write to ensure the
  48. * order. If need to ensure this write is also flushed
  49. * call rmb() independently in the caller.
  50. *
  51. * @addr: Address of register to be read
  52. *
  53. * @return: Value read from the register address
  54. */
  55. uint32_t cam_io_r_mb(void __iomem *addr);
  56. /**
  57. * cam_io_memcpy()
  58. *
  59. * @brief: Camera IO util for memory to register copy
  60. *
  61. * @dest_addr: Destination register address
  62. * @src_addr: Source regiser address
  63. * @len: Range to be copied
  64. *
  65. * @return: Success or Failure
  66. */
  67. int cam_io_memcpy(void __iomem *dest_addr,
  68. void __iomem *src_addr, uint32_t len);
  69. /**
  70. * cam_io_memcpy_mb()
  71. *
  72. * @brief: Camera IO util for memory to register copy
  73. * with barrier.
  74. * Memory Barrier is only before the write to ensure the
  75. * order. If need to ensure this write is also flushed
  76. * call wmb() independently in the caller.
  77. *
  78. * @dest_addr: Destination register address
  79. * @src_addr: Source regiser address
  80. * @len: Range to be copied
  81. *
  82. * @return: Success or Failure
  83. */
  84. int cam_io_memcpy_mb(void __iomem *dest_addr,
  85. void __iomem *src_addr, uint32_t len);
  86. /**
  87. * cam_io_poll_value_wmask()
  88. *
  89. * @brief: Poll register value with bitmask.
  90. *
  91. * @addr: Register address to be polled
  92. * @wait_data: Wait until @bmask read from @addr matches this data
  93. * @bmask: Bit mask
  94. * @retry: Number of retry
  95. * @min_usecs: Minimum time to wait for retry
  96. * @max_usecs: Maximum time to wait for retry
  97. *
  98. * @return: Success or Failure
  99. *
  100. * This function can sleep so it should not be called from interrupt
  101. * handler, spin_lock etc.
  102. */
  103. int cam_io_poll_value_wmask(void __iomem *addr, uint32_t wait_data,
  104. uint32_t bmask, uint32_t retry, unsigned long min_usecs,
  105. unsigned long max_usecs);
  106. /**
  107. * cam_io_poll_value()
  108. *
  109. * @brief: Poll register value
  110. *
  111. * @addr: Register address to be polled
  112. * @wait_data: Wait until value read from @addr matches this data
  113. * @retry: Number of retry
  114. * @min_usecs: Minimum time to wait for retry
  115. * @max_usecs: Maximum time to wait for retry
  116. *
  117. * @return: Success or Failure
  118. *
  119. * This function can sleep so it should not be called from interrupt
  120. * handler, spin_lock etc.
  121. */
  122. int cam_io_poll_value(void __iomem *addr, uint32_t wait_data, uint32_t retry,
  123. unsigned long min_usecs, unsigned long max_usecs);
  124. /**
  125. * cam_io_w_same_offset_block()
  126. *
  127. * @brief: Write a block of data to same address
  128. *
  129. * @data: Block data to be written
  130. * @addr: Register offset to be written.
  131. * @len: Number of the data to be written
  132. *
  133. * @return: Success or Failure
  134. */
  135. int cam_io_w_same_offset_block(const uint32_t *data, void __iomem *addr,
  136. uint32_t len);
  137. /**
  138. * cam_io_w_mb_same_offset_block()
  139. *
  140. * @brief: Write a block of data to same address with barrier.
  141. * Memory Barrier is only before the write to ensure the
  142. * order. If need to ensure this write is also flushed
  143. * call wmb() independently in the caller.
  144. *
  145. * @data: Block data to be written
  146. * @addr: Register offset to be written.
  147. * @len: Number of the data to be written
  148. *
  149. * @return: Success or Failure
  150. */
  151. int cam_io_w_mb_same_offset_block(const uint32_t *data, void __iomem *addr,
  152. uint32_t len);
  153. /**
  154. * cam_io_w_offset_val_block()
  155. *
  156. * @brief: This API is to write a block of registers
  157. * represented by a 2 dimensional array table with
  158. * register offset and value pair
  159. *
  160. * offset0, value0,
  161. * offset1, value1,
  162. * offset2, value2,
  163. * and so on...
  164. *
  165. * @data: Pointer to 2-dimensional offset-value array
  166. * @addr_base: Base address to which offset will be added to
  167. * get the register address
  168. * @len: Length of offset-value pair array to be written in
  169. * number of uin32_t
  170. *
  171. * @return: Success or Failure
  172. *
  173. */
  174. int32_t cam_io_w_offset_val_block(const uint32_t data[][2],
  175. void __iomem *addr_base, uint32_t len);
  176. /**
  177. * cam_io_w_mb_offset_val_block()
  178. *
  179. * @brief: This API is to write a block of registers
  180. * represented by a 2 dimensional array table with
  181. * register offset and value pair with memory barrier.
  182. * Memory Barrier is only before the write to ensure the
  183. * order. If need to ensure this write is also flushed
  184. * call wmb() independently in the caller.
  185. * The OFFSETS NEED to be different because of the way
  186. * barrier is used here.
  187. *
  188. * offset0, value0,
  189. * offset1, value1,
  190. * offset2, value2,
  191. * and so on...
  192. *
  193. * @data: Pointer to 2-dimensional offset-value array
  194. * @addr_base: Base address to which offset will be added to
  195. * get the register address
  196. * @len: Length of offset-value pair array to be written in
  197. * number of uin32_t
  198. *
  199. * @return: Success or Failure
  200. *
  201. */
  202. int32_t cam_io_w_mb_offset_val_block(const uint32_t data[][2],
  203. void __iomem *addr_base, uint32_t len);
  204. /**
  205. * cam_io_dump()
  206. *
  207. * @brief: Camera IO util for dumping a range of register
  208. *
  209. * @base_addr: Start register address for the dumping
  210. * @start_offset: Start register offset for the dump
  211. * @size: Size specifying the range for dumping
  212. *
  213. * @return: Success or Failure
  214. */
  215. int cam_io_dump(void __iomem *base_addr, uint32_t start_offset, int size);
  216. #endif /* _CAM_IO_UTIL_H_ */