cam_cdm_util.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_CDM_UTIL_H_
  6. #define _CAM_CDM_UTIL_H_
  7. #include <linux/types.h>
  8. enum cam_cdm_command {
  9. CAM_CDM_CMD_UNUSED = 0x0,
  10. CAM_CDM_CMD_DMI = 0x1,
  11. CAM_CDM_CMD_NOT_DEFINED = 0x2,
  12. CAM_CDM_CMD_REG_CONT = 0x3,
  13. CAM_CDM_CMD_REG_RANDOM = 0x4,
  14. CAM_CDM_CMD_BUFF_INDIRECT = 0x5,
  15. CAM_CDM_CMD_GEN_IRQ = 0x6,
  16. CAM_CDM_CMD_WAIT_EVENT = 0x7,
  17. CAM_CDM_CMD_CHANGE_BASE = 0x8,
  18. CAM_CDM_CMD_PERF_CTRL = 0x9,
  19. CAM_CDM_CMD_DMI_32 = 0xa,
  20. CAM_CDM_CMD_DMI_64 = 0xb,
  21. CAM_CDM_COMP_WAIT = 0xc,
  22. CAM_CDM_CLEAR_COMP_WAIT = 0xd,
  23. CAM_CDM_WAIT_PREFETCH_DISABLE = 0xe,
  24. CAM_CDM_CMD_PRIVATE_BASE = 0xf,
  25. CAM_CDM_CMD_SWD_DMI_32 = (CAM_CDM_CMD_PRIVATE_BASE + 0x64),
  26. CAM_CDM_CMD_SWD_DMI_64 = (CAM_CDM_CMD_PRIVATE_BASE + 0x65),
  27. CAM_CDM_CMD_PRIVATE_BASE_MAX = 0x7F,
  28. };
  29. /**
  30. * struct cam_cdm_utils_ops - Camera CDM util ops
  31. *
  32. * @cdm_get_cmd_header_size: Returns the size of the given command header
  33. * in DWORDs.
  34. * @command Command ID
  35. * @return Size of the command in DWORDs
  36. *
  37. * @cdm_required_size_reg_continuous: Calculates the size of a reg-continuous
  38. * command in dwords.
  39. * @numVals Number of continuous values
  40. * @return Size in dwords
  41. *
  42. * @cdm_required_size_reg_random: Calculates the size of a reg-random command
  43. * in dwords.
  44. * @numRegVals Number of register/value pairs
  45. * @return Size in dwords
  46. *
  47. * @cdm_required_size_dmi: Calculates the size of a DMI command in dwords.
  48. * @return Size in dwords
  49. *
  50. * @cdm_required_size_genirq: Calculates size of a Genirq command in dwords.
  51. * @return Size in dwords
  52. *
  53. * @cdm_required_size_indirect: Calculates the size of an indirect command
  54. * in dwords.
  55. * @return Size in dwords
  56. *
  57. * @cdm_required_size_comp_wait: Calculates the size of a comp-wait command
  58. * in dwords.
  59. * @return Size in dwords
  60. *
  61. * @cdm_required_size_changebase: Calculates the size of a change-base command
  62. * in dwords.
  63. * @return Size in dwords
  64. *
  65. * @cdm_offsetof_dmi_addr: Returns the offset of address field in the DMI
  66. * command header.
  67. * @return Offset of addr field
  68. *
  69. * @cdm_offsetof_indirect_addr: Returns the offset of address field in the
  70. * indirect command header.
  71. * @return Offset of addr field
  72. *
  73. * @cdm_write_regcontinuous: Writes a command into the command buffer.
  74. * @pCmdBuffer: Pointer to command buffer
  75. * @reg: Beginning of the register address range where
  76. * values will be written.
  77. * @numVals: Number of values (registers) that will be written
  78. * @pVals : An array of values that will be written
  79. * @return Pointer in command buffer pointing past the written commands
  80. *
  81. * @cdm_write_regrandom: Writes a command into the command buffer in
  82. * register/value pairs.
  83. * @pCmdBuffer: Pointer to command buffer
  84. * @numRegVals: Number of register/value pairs that will be written
  85. * @pRegVals: An array of register/value pairs that will be written
  86. * The even indices are registers and the odd indices
  87. * arevalues, e.g., {reg1, val1, reg2, val2, ...}.
  88. * @return Pointer in command buffer pointing past the written commands
  89. *
  90. * @cdm_write_dmi: Writes a DMI command into the command bufferM.
  91. * @pCmdBuffer: Pointer to command buffer
  92. * @dmiCmd: DMI command
  93. * @DMIAddr: Address of the DMI
  94. * @DMISel: Selected bank that the DMI will write to
  95. * @length: Size of data in bytes
  96. * @return Pointer in command buffer pointing past the written commands
  97. *
  98. * @cdm_write_indirect: Writes a indirect command into the command buffer.
  99. * @pCmdBuffer: Pointer to command buffer
  100. * @indirectBufferAddr: Device address of the indirect cmd buffer.
  101. * @length: Size of data in bytes
  102. * @return Pointer in command buffer pointing past the written commands
  103. *
  104. * @cdm_write_changebase: Writes a changing CDM (address) base command into
  105. * the command buffer.
  106. * @pCmdBuffer: Pointer to command buffer
  107. * @base: New base (device) address
  108. * @return Pointer in command buffer pointing past the written commands
  109. *
  110. * @cdm_write_genirq: Writes a gen irq command into the command buffer.
  111. * @pCmdBuffer: Pointer to command buffer
  112. * @userdata: userdata or cookie return by hardware during irq.
  113. *
  114. * @cdm_write_wait_comp_event: Writes a wait comp event cmd into the
  115. * command buffer.
  116. * @pCmdBuffer: Pointer to command buffer
  117. * @mask1: This value decides which comp events to wait (0 - 31).
  118. * @mask2: This value decides which comp events to wait (32 - 65).
  119. */
  120. struct cam_cdm_utils_ops {
  121. uint32_t (*cdm_get_cmd_header_size)(unsigned int command);
  122. uint32_t (*cdm_required_size_dmi)(void);
  123. uint32_t (*cdm_required_size_reg_continuous)(uint32_t numVals);
  124. uint32_t (*cdm_required_size_reg_random)(uint32_t numRegVals);
  125. uint32_t (*cdm_required_size_indirect)(void);
  126. uint32_t (*cdm_required_size_genirq)(void);
  127. uint32_t (*cdm_required_size_wait_event)(void);
  128. uint32_t (*cdm_required_size_changebase)(void);
  129. uint32_t (*cdm_required_size_comp_wait)(void);
  130. uint32_t (*cdm_required_size_prefetch_disable)(void);
  131. uint32_t (*cdm_offsetof_dmi_addr)(void);
  132. uint32_t (*cdm_offsetof_indirect_addr)(void);
  133. uint32_t *(*cdm_write_dmi)(
  134. uint32_t *pCmdBuffer,
  135. uint8_t dmiCmd,
  136. uint32_t DMIAddr,
  137. uint8_t DMISel,
  138. uint32_t dmiBufferAddr,
  139. uint32_t length);
  140. uint32_t* (*cdm_write_regcontinuous)(
  141. uint32_t *pCmdBuffer,
  142. uint32_t reg,
  143. uint32_t numVals,
  144. uint32_t *pVals);
  145. uint32_t *(*cdm_write_regrandom)(
  146. uint32_t *pCmdBuffer,
  147. uint32_t numRegVals,
  148. uint32_t *pRegVals);
  149. uint32_t *(*cdm_write_indirect)(
  150. uint32_t *pCmdBuffer,
  151. uint32_t indirectBufferAddr,
  152. uint32_t length);
  153. void (*cdm_write_genirq)(
  154. uint32_t *pCmdBuffer,
  155. uint32_t userdata,
  156. bool bit_wr_enable,
  157. uint32_t fifo_idx);
  158. uint32_t *(*cdm_write_wait_event)(
  159. uint32_t *pCmdBuffer,
  160. uint32_t iw,
  161. uint32_t id,
  162. uint32_t mask,
  163. uint32_t offset,
  164. uint32_t data);
  165. uint32_t *(*cdm_write_changebase)(
  166. uint32_t *pCmdBuffer,
  167. uint32_t base);
  168. uint32_t *(*cdm_write_wait_comp_event)(
  169. uint32_t *pCmdBuffer,
  170. uint32_t mask1,
  171. uint32_t mask2);
  172. uint32_t *(*cdm_write_wait_prefetch_disable)(
  173. uint32_t *pCmdBuffer,
  174. uint32_t id,
  175. uint32_t mask1,
  176. uint32_t mask2);
  177. };
  178. /**
  179. * cam_cdm_util_log_cmd_bufs()
  180. *
  181. * @brief: Util function to log cdm command buffers
  182. *
  183. * @cmd_buffer_start: Pointer to start of cmd buffer
  184. * @cmd_buffer_end: Pointer to end of cmd buffer
  185. *
  186. */
  187. void cam_cdm_util_dump_cmd_buf(
  188. uint32_t *cmd_buffer_start, uint32_t *cmd_buffer_end);
  189. #endif /* _CAM_CDM_UTIL_H_ */