cam_cdm_util.h 5.7 KB

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