cam_cdm.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _CAM_CDM_H_
  7. #define _CAM_CDM_H_
  8. #include <linux/module.h>
  9. #include <linux/of_platform.h>
  10. #include <linux/random.h>
  11. #include <linux/spinlock_types.h>
  12. #include <linux/mutex.h>
  13. #include <linux/workqueue.h>
  14. #include <linux/bug.h>
  15. #include "cam_cdm_intf_api.h"
  16. #include "cam_soc_util.h"
  17. #include "cam_cpas_api.h"
  18. #include "cam_hw_intf.h"
  19. #include "cam_hw.h"
  20. #include "cam_debug_util.h"
  21. #define CAM_MAX_SW_CDM_VERSION_SUPPORTED 1
  22. #define CAM_SW_CDM_INDEX 0
  23. #define CAM_CDM_INFLIGHT_WORKS 5
  24. #define CAM_CDM_HW_RESET_TIMEOUT 300
  25. #define CAM_CDM_PAUSE_CORE_US_TIMEOUT 10000
  26. /*
  27. * Macros to get prepare and get information
  28. * from client CDM handles.
  29. */
  30. #define CAM_CDM_HW_ID_MASK 0xF
  31. #define CAM_CDM_HW_ID_SHIFT 0x10
  32. #define CAM_CDM_CLIENTS_ID_MASK 0xFF
  33. #define CAM_CDM_BL_FIFO_ID_MASK 0xF
  34. #define CAM_CDM_BL_FIFO_ID_SHIFT 0x8
  35. #define CAM_CDM_GET_HW_IDX(x) (((x) >> CAM_CDM_HW_ID_SHIFT) & \
  36. CAM_CDM_HW_ID_MASK)
  37. #define CAM_CDM_GET_BLFIFO_IDX(x) (((x) >> CAM_CDM_BL_FIFO_ID_SHIFT) & \
  38. CAM_CDM_BL_FIFO_ID_MASK)
  39. #define CAM_CDM_CREATE_CLIENT_HANDLE(hw_idx, priority, client_idx) \
  40. ((((hw_idx) & CAM_CDM_HW_ID_MASK) << CAM_CDM_HW_ID_SHIFT) | \
  41. (((priority) & CAM_CDM_BL_FIFO_ID_MASK) << CAM_CDM_BL_FIFO_ID_SHIFT)| \
  42. ((client_idx) & CAM_CDM_CLIENTS_ID_MASK))
  43. #define CAM_CDM_GET_CLIENT_IDX(x) ((x) & CAM_CDM_CLIENTS_ID_MASK)
  44. #define CAM_PER_CDM_MAX_REGISTERED_CLIENTS (CAM_CDM_CLIENTS_ID_MASK + 1)
  45. #define CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM (CAM_CDM_HW_ID_MASK + 1)
  46. /* Number of FIFO supported on CDM */
  47. #define CAM_CDM_NUM_BL_FIFO 0x4
  48. #define CAM_CDM_NUM_TEST_BUS 16
  49. /* Max number of register set for different CDM */
  50. #define CAM_CDM_BL_FIFO_REG_NUM 0x4
  51. #define CAM_CDM_BL_FIFO_IRQ_REG_NUM 0x4
  52. #define CAM_CDM_BL_FIFO_PENDING_REQ_REG_NUM 0x2
  53. #define CAM_CDM_SCRATCH_REG_NUM 0xc
  54. #define CAM_CDM_COMP_WAIT_STATUS_REG_NUM 0x2
  55. #define CAM_CDM_PERF_MON_REG_NUM 0x2
  56. /* BL_FIFO configurations*/
  57. #define CAM_CDM_BL_FIFO_LENGTH_MAX_DEFAULT 0x40
  58. #define CAM_CDM_BL_FIFO_LENGTH_CFG_SHIFT 0x10
  59. #define CAM_CDM_BL_FIFO_FLUSH_SHIFT 0x3
  60. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX 0x00
  61. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX_DIV2 0x01
  62. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX_DIV4 0x10
  63. #define CAM_CDM_BL_FIFO_REQ_SIZE_MAX_DIV8 0x11
  64. /* CDM core status bitmap */
  65. #define CAM_CDM_HW_INIT_STATUS 0x0
  66. #define CAM_CDM_FIFO_0_BLDONE_STATUS 0x0
  67. #define CAM_CDM_FIFO_1_BLDONE_STATUS 0x1
  68. #define CAM_CDM_FIFO_2_BLDONE_STATUS 0x2
  69. #define CAM_CDM_FIFO_3_BLDONE_STATUS 0x3
  70. #define CAM_CDM_RESET_HW_STATUS 0x4
  71. #define CAM_CDM_ERROR_HW_STATUS 0x5
  72. #define CAM_CDM_FLUSH_HW_STATUS 0x6
  73. #define CAM_CDM_RESET_ERR_STATUS 0x7
  74. #define CAM_CDM_PF_HW_STATUS 0x8
  75. /* Curent used AHB masks and shifts */
  76. #define CAM_CDM_AHB_LOG_CID_SHIFT 28
  77. #define CAM_CDM_AHB_LOG_CID_MASK 0X30000000
  78. #define CAM_CDM_AHB_ADDR_MASK 0x00FFFFFF
  79. /* Invalid command status register's masks and shifts */
  80. #define CAM_CDM_ICL_STATUS_LAST_CID_SHIFT 4
  81. #define CAM_CDM_ICL_STATUS_LAST_CID_MASK 0X30
  82. #define CAM_CDM_ICL_STATUS_INV_CID_MASK 0x03
  83. /* Core_cfg register's masks and shifts */
  84. #define CAM_CDM_CORE_CFG_PRIORITY_MASK 0XF00000
  85. #define CAM_CDM_CORE_CFG_PRIORITY_SHIFT 20
  86. #define CAM_CDM_CORE_CFG_IMPLICIT_WAIT_EN_MASK 0x20000
  87. #define CAM_CDM_CORE_CFG_ARB_SEL_RR_MASK 0x10000
  88. #define CAM_CDM_CORE_CFG_AHB_STOP_ON_ERR_MASK 0x100
  89. #define CAM_CDM_CORE_CFG_AHB_BURST_EN_MASK 0x10
  90. #define CAM_CDM_CORE_CFG_AHB_BURST_LEN_MASK 0x0F
  91. /* Core enable register masks and shifts */
  92. #define CAM_CDM_CORE_EN_MASK 0x1
  93. #define CAM_CDM_CORE_PAUSE_MASK 0X2
  94. /* Core Debug register masks and shifts */
  95. #define CAM_CDM_CORE_DBG_TEST_BUS_EN_MASK 0X01
  96. #define CAM_CDM_CORE_DBG_TEST_BUS_SEL_MASK 0XF0
  97. #define CAM_CDM_CORE_DBG_TEST_BUS_SEL_SHIFT 4
  98. #define CAM_CDM_CORE_DBG_LOG_AHB_MASK 0X100
  99. #define CAM_CDM_CORE_DBG_LOG_SHIFT 8
  100. #define CAM_CDM_CORE_DBG_FIFO_RB_EN_MASK 0x10000
  101. #define CAM_CDM_CORE_DBG_FIFO_RB_EN_SHIFT 16
  102. /* Curent BL command masks and shifts */
  103. #define CAM_CDM_CURRENT_BL_LEN 0xFFFFF
  104. #define CAM_CDM_CURRENT_BL_ARB 0x100000
  105. #define CAM_CDM_CURRENT_BL_FIFO 0xC00000
  106. #define CAM_CDM_CURRENT_BL_TAG 0xFF000000
  107. #define CAM_CDM_CURRENT_BL_ARB_SHIFT 0x14
  108. #define CAM_CDM_CURRENT_BL_FIFO_SHIFT 0x16
  109. #define CAM_CDM_CURRENT_BL_TAG_SHIFT 0x18
  110. /* IRQ bit-masks */
  111. #define CAM_CDM_IRQ_STATUS_RST_DONE_MASK 0x1
  112. #define CAM_CDM_IRQ_STATUS_INLINE_IRQ_MASK 0x2
  113. #define CAM_CDM_IRQ_STATUS_BL_DONE_MASK 0x4
  114. #define CAM_CDM_IRQ_STATUS_ERROR_INV_CMD_MASK 0x10000
  115. #define CAM_CDM_IRQ_STATUS_ERROR_OVER_FLOW_MASK 0x20000
  116. #define CAM_CDM_IRQ_STATUS_ERROR_AHB_BUS_MASK 0x40000
  117. #define CAM_CDM_IRQ_STATUS_USR_DATA_MASK 0xFF
  118. #define CAM_CDM_IRQ_STATUS_ERRORS \
  119. (CAM_CDM_IRQ_STATUS_ERROR_INV_CMD_MASK | \
  120. CAM_CDM_IRQ_STATUS_ERROR_OVER_FLOW_MASK | \
  121. CAM_CDM_IRQ_STATUS_ERROR_AHB_BUS_MASK)
  122. /* Structure to store hw version info */
  123. struct cam_version_reg {
  124. uint32_t hw_version;
  125. };
  126. /**
  127. * struct cam_cdm_irq_regs - CDM IRQ registers
  128. *
  129. * @irq_mask: register offset for irq_mask
  130. * @irq_clear: register offset for irq_clear
  131. * @irq_clear_cmd: register offset to initiate irq clear
  132. * @irq_set: register offset to set irq
  133. * @irq_set_cmd: register offset to issue set_irq from irq_set
  134. * @irq_status: register offset to look which irq is received
  135. */
  136. struct cam_cdm_irq_regs {
  137. uint32_t irq_mask;
  138. uint32_t irq_clear;
  139. uint32_t irq_clear_cmd;
  140. uint32_t irq_set;
  141. uint32_t irq_set_cmd;
  142. uint32_t irq_status;
  143. };
  144. /**
  145. * struct cam_cdm_bl_fifo_regs - BL_FIFO registers
  146. *
  147. * @bl_fifo_base: register offset to write bl_cmd base address
  148. * @bl_fifo_len: register offset to write bl_cmd length
  149. * @bl_fifo_store: register offset to commit the BL cmd
  150. * @bl_fifo_cfg: register offset to config BL_FIFO depth, etc.
  151. */
  152. struct cam_cdm_bl_fifo_regs {
  153. uint32_t bl_fifo_base;
  154. uint32_t bl_fifo_len;
  155. uint32_t bl_fifo_store;
  156. uint32_t bl_fifo_cfg;
  157. };
  158. /**
  159. * struct cam_cdm_bl_pending_req_reg_params - BL_FIFO pending registers
  160. *
  161. * @rb_offset: register offset pending bl request in BL_FIFO
  162. * @rb_mask: mask to get number of pending BLs in BL_FIFO
  163. * @rb_num_fifo: number of BL_FIFO's information in the register
  164. * @rb_next_fifo_shift: shift to get next fifo's pending BLs.
  165. */
  166. struct cam_cdm_bl_pending_req_reg_params {
  167. uint32_t rb_offset;
  168. uint32_t rb_mask;
  169. uint32_t rb_num_fifo;
  170. uint32_t rb_next_fifo_shift;
  171. };
  172. /**
  173. * struct cam_cdm_scratch_reg - scratch register
  174. *
  175. * @scratch_reg: offset of scratch register
  176. */
  177. struct cam_cdm_scratch_reg {
  178. uint32_t scratch_reg;
  179. };
  180. /* struct cam_cdm_perf_mon_regs - perf_mon registers */
  181. struct cam_cdm_perf_mon_regs {
  182. uint32_t perf_mon_ctrl;
  183. uint32_t perf_mon_0;
  184. uint32_t perf_mon_1;
  185. uint32_t perf_mon_2;
  186. };
  187. /**
  188. * struct cam_cdm_perf_mon_regs - perf mon counter's registers
  189. *
  190. * @count_cfg_0: register offset to configure perf measures
  191. * @always_count_val: register offset for always count value
  192. * @busy_count_val: register offset to get busy count
  193. * @stall_axi_count_val: register offset to get axi stall counts
  194. * @count_status: register offset to know if count status finished
  195. * for stall, busy and always.
  196. */
  197. struct cam_cdm_perf_regs {
  198. uint32_t count_cfg_0;
  199. uint32_t always_count_val;
  200. uint32_t busy_count_val;
  201. uint32_t stall_axi_count_val;
  202. uint32_t count_status;
  203. };
  204. /**
  205. * struct cam_cdm_icl_data_regs - CDM icl data registers
  206. *
  207. * @icl_last_data_0: register offset to log last known good command
  208. * @icl_last_data_1: register offset to log last known good command 1
  209. * @icl_last_data_2: register offset to log last known good command 2
  210. * @icl_inv_data: register offset to log CDM cmd that triggered
  211. * invalid command.
  212. */
  213. struct cam_cdm_icl_data_regs {
  214. uint32_t icl_last_data_0;
  215. uint32_t icl_last_data_1;
  216. uint32_t icl_last_data_2;
  217. uint32_t icl_inv_data;
  218. };
  219. /**
  220. * struct cam_cdm_icl_misc_regs - CDM icl misc registers
  221. *
  222. * @icl_inv_bl_addr: register offset to give address of bl_cmd that
  223. * gave invalid command
  224. * @icl_status: register offset for context that gave good BL
  225. * command and invalid command.
  226. */
  227. struct cam_cdm_icl_misc_regs {
  228. uint32_t icl_inv_bl_addr;
  229. uint32_t icl_status;
  230. };
  231. /**
  232. * struct cam_cdm_icl_regs - CDM icl registers
  233. *
  234. * @data_regs: structure with registers of all cdm good and invalid
  235. * BL command information.
  236. * @misc_regs: structure with registers for invalid command address
  237. * and context
  238. */
  239. struct cam_cdm_icl_regs {
  240. struct cam_cdm_icl_data_regs *data_regs;
  241. struct cam_cdm_icl_misc_regs *misc_regs;
  242. };
  243. /**
  244. * struct cam_cdm_comp_wait_status - BL_FIFO comp_event status register
  245. *
  246. * @comp_wait_status: register offset to give information on whether the
  247. * CDM is waiting for an event from another module
  248. */
  249. struct cam_cdm_comp_wait_status {
  250. uint32_t comp_wait_status;
  251. };
  252. /**
  253. * struct cam_cdm_common_reg_data - structure for register data
  254. *
  255. * @num_bl_fifo: number of FIFO are there in CDM
  256. * @num_bl_fifo_irq: number of FIFO irqs in CDM
  257. * @num_bl_pending_req_reg: number of pending_requests register in CDM
  258. * @num_scratch_reg: number of scratch registers in CDM
  259. */
  260. struct cam_cdm_common_reg_data {
  261. uint32_t num_bl_fifo;
  262. uint32_t num_bl_fifo_irq;
  263. uint32_t num_bl_pending_req_reg;
  264. uint32_t num_scratch_reg;
  265. };
  266. /**
  267. * struct cam_cdm_common_regs - common structure to get common registers
  268. * of CDM
  269. *
  270. * @cdm_hw_version: offset to read cdm_hw_version
  271. * @cam_version: offset to read the camera Titan architecture version
  272. * @rst_cmd: offset to reset the CDM
  273. * @cgc_cfg: offset to configure CDM CGC logic
  274. * @core_cfg: offset to configure CDM core with ARB_SEL, implicit
  275. * wait, etc.
  276. * @core_en: offset to pause/enable CDM
  277. * @fe_cfg: offset to configure CDM fetch engine
  278. * @cdm_status: offset to read CDM status register, this register
  279. * indicates if CDM is idle, and if a pause operation
  280. * is successfully completed or not
  281. * @irq_context_status offset to read back irq context status
  282. * @bl_fifo_rb: offset to set BL_FIFO read back
  283. * @bl_fifo_base_rb: offset to read back base address on offset set by
  284. * bl_fifo_rb
  285. * @bl_fifo_len_rb: offset to read back base len and tag on offset set by
  286. * bl_fifo_rb
  287. * @usr_data: offset to read user data from GEN_IRQ commands
  288. * @wait_status: offset to read status for last WAIT command
  289. * @last_ahb_addr: offset to read back last AHB address generated by CDM
  290. * @last_ahb_data: offset to read back last AHB data generated by CDM
  291. * @core_debug: offset to configure CDM debug bus and debug features
  292. * @last_ahb_err_addr: offset to read back last AHB Error address generated
  293. * by CDM
  294. * @last_ahb_err_data: offset to read back last AHB Error data generated
  295. * by CDM
  296. * @current_bl_base: offset to read back current command buffer BASE address
  297. * value out of BL_FIFO
  298. * @current_bl_len: offset to read back current command buffer len, TAG,
  299. * context ID ARB value out of BL_FIFO
  300. * @current_used_ahb_base: offset to read back current base address used by
  301. * CDM to access camera register
  302. * @debug_status: offset to read back current CDM status
  303. * @bus_misr_cfg0: offset to enable bus MISR and configure sampling mode
  304. * @bus_misr_cfg1: offset to select from one of the six MISR's for reading
  305. * signature value
  306. * @bus_misr_rd_val: offset to read MISR signature
  307. * @pending_req: registers to read pending request in FIFO
  308. * @comp_wait: registers to read comp_event CDM is waiting for
  309. * @perf_mon: registers to read perf_mon information
  310. * @scratch: registers to read scratch register value
  311. * @perf_reg: registers to read performance counters value
  312. * @icl_reg: registers to read information related to good
  313. * and invalid commands in FIFO
  314. * @spare: spare register
  315. * @priority_group_bit_offset offset of priority group bits
  316. *
  317. */
  318. struct cam_cdm_common_regs {
  319. uint32_t cdm_hw_version;
  320. const struct cam_version_reg *cam_version;
  321. uint32_t rst_cmd;
  322. uint32_t cgc_cfg;
  323. uint32_t core_cfg;
  324. uint32_t core_en;
  325. uint32_t fe_cfg;
  326. uint32_t cdm_status;
  327. uint32_t irq_context_status;
  328. uint32_t bl_fifo_rb;
  329. uint32_t bl_fifo_base_rb;
  330. uint32_t bl_fifo_len_rb;
  331. uint32_t usr_data;
  332. uint32_t wait_status;
  333. uint32_t last_ahb_addr;
  334. uint32_t last_ahb_data;
  335. uint32_t core_debug;
  336. uint32_t last_ahb_err_addr;
  337. uint32_t last_ahb_err_data;
  338. uint32_t current_bl_base;
  339. uint32_t current_bl_len;
  340. uint32_t current_used_ahb_base;
  341. uint32_t debug_status;
  342. uint32_t bus_misr_cfg0;
  343. uint32_t bus_misr_cfg1;
  344. uint32_t bus_misr_rd_val;
  345. const struct cam_cdm_bl_pending_req_reg_params
  346. *pending_req[CAM_CDM_BL_FIFO_PENDING_REQ_REG_NUM];
  347. const struct cam_cdm_comp_wait_status
  348. *comp_wait[CAM_CDM_COMP_WAIT_STATUS_REG_NUM];
  349. const struct cam_cdm_perf_mon_regs
  350. *perf_mon[CAM_CDM_PERF_MON_REG_NUM];
  351. const struct cam_cdm_scratch_reg
  352. *scratch[CAM_CDM_SCRATCH_REG_NUM];
  353. const struct cam_cdm_perf_regs *perf_reg;
  354. const struct cam_cdm_icl_regs *icl_reg;
  355. uint32_t spare;
  356. uint32_t priority_group_bit_offset;
  357. };
  358. /**
  359. * struct cam_cdm_hw_reg_offset - BL_FIFO comp_event status register
  360. *
  361. * @cmn_reg: pointer to structure to get common registers of a CDM
  362. * @bl_fifo_reg: pointer to structure to get BL_FIFO registers of a CDM
  363. * @irq_reg: pointer to structure to get IRQ registers of a CDM
  364. * @reg_data: pointer to structure to reg_data related to CDM
  365. * registers
  366. */
  367. struct cam_cdm_hw_reg_offset {
  368. const struct cam_cdm_common_regs *cmn_reg;
  369. const struct cam_cdm_bl_fifo_regs *bl_fifo_reg[CAM_CDM_BL_FIFO_REG_NUM];
  370. const struct cam_cdm_irq_regs *irq_reg[CAM_CDM_BL_FIFO_IRQ_REG_NUM];
  371. const struct cam_cdm_common_reg_data *reg_data;
  372. };
  373. /* enum cam_cdm_hw_process_intf_cmd - interface commands.*/
  374. enum cam_cdm_hw_process_intf_cmd {
  375. CAM_CDM_HW_INTF_CMD_ACQUIRE,
  376. CAM_CDM_HW_INTF_CMD_RELEASE,
  377. CAM_CDM_HW_INTF_CMD_SUBMIT_BL,
  378. CAM_CDM_HW_INTF_CMD_RESET_HW,
  379. CAM_CDM_HW_INTF_CMD_FLUSH_HW,
  380. CAM_CDM_HW_INTF_CMD_HANDLE_ERROR,
  381. CAM_CDM_HW_INTF_CMD_HANG_DETECT,
  382. CAM_CDM_HW_INTF_DUMP_DBG_REGS,
  383. CAM_CDM_HW_INTF_CMD_INVALID,
  384. };
  385. /* enum cam_cdm_flags - Bit fields for CDM flags used */
  386. enum cam_cdm_flags {
  387. CAM_CDM_FLAG_SHARED_CDM,
  388. CAM_CDM_FLAG_PRIVATE_CDM,
  389. };
  390. /* enum cam_cdm_type - Enum for possible CAM CDM types */
  391. enum cam_cdm_type {
  392. CAM_VIRTUAL_CDM,
  393. CAM_HW_CDM,
  394. };
  395. /* enum cam_cdm_mem_base_index - Enum for possible CAM CDM types */
  396. enum cam_cdm_mem_base_index {
  397. CAM_HW_CDM_BASE_INDEX,
  398. CAM_HW_CDM_MAX_INDEX = CAM_SOC_MAX_BLOCK,
  399. };
  400. /* enum cam_cdm_bl_cb_type - Enum for possible CAM CDM cb request types */
  401. enum cam_cdm_bl_cb_type {
  402. CAM_HW_CDM_BL_CB_CLIENT = 1,
  403. CAM_HW_CDM_BL_CB_INTERNAL,
  404. };
  405. /* enum cam_cdm_arbitration - Enum type of arbitration */
  406. enum cam_cdm_arbitration {
  407. CAM_CDM_ARBITRATION_NONE,
  408. CAM_CDM_ARBITRATION_ROUND_ROBIN,
  409. CAM_CDM_ARBITRATION_PRIORITY_BASED,
  410. CAM_CDM_ARBITRATION_MAX,
  411. };
  412. enum cam_cdm_hw_version {
  413. CAM_CDM_VERSION = 0,
  414. CAM_CDM_VERSION_1_0 = 0x10000000,
  415. CAM_CDM_VERSION_1_1 = 0x10010000,
  416. CAM_CDM_VERSION_1_2 = 0x10020000,
  417. CAM_CDM_VERSION_2_0 = 0x20000000,
  418. CAM_CDM_VERSION_2_1 = 0x20010000,
  419. CAM_CDM_VERSION_2_2 = 0x20020000,
  420. CAM_CDM_VERSION_MAX,
  421. };
  422. /* struct cam_cdm_client - struct for cdm clients data.*/
  423. struct cam_cdm_client {
  424. struct cam_cdm_acquire_data data;
  425. void __iomem *changebase_addr;
  426. uint32_t stream_on;
  427. uint32_t refcount;
  428. struct mutex lock;
  429. uint32_t handle;
  430. };
  431. /* struct cam_cdm_work_payload - struct for cdm work payload data.*/
  432. struct cam_cdm_work_payload {
  433. struct cam_hw_info *hw;
  434. uint32_t irq_status;
  435. uint32_t irq_data;
  436. int fifo_idx;
  437. ktime_t workq_scheduled_ts;
  438. struct work_struct work;
  439. };
  440. /* struct cam_cdm_bl_cb_request_entry - callback entry for work to process.*/
  441. struct cam_cdm_bl_cb_request_entry {
  442. uint8_t bl_tag;
  443. enum cam_cdm_bl_cb_type request_type;
  444. uint32_t client_hdl;
  445. void *userdata;
  446. uint32_t cookie;
  447. struct list_head entry;
  448. };
  449. /* struct cam_cdm_hw_intf_cmd_submit_bl - cdm interface submit command.*/
  450. struct cam_cdm_hw_intf_cmd_submit_bl {
  451. uint32_t handle;
  452. struct cam_cdm_bl_request *data;
  453. };
  454. /* struct cam_cdm_bl_fifo - CDM hw memory struct */
  455. struct cam_cdm_bl_fifo {
  456. struct completion bl_complete;
  457. struct workqueue_struct *work_queue;
  458. struct list_head bl_request_list;
  459. struct mutex fifo_lock;
  460. uint8_t bl_tag;
  461. uint32_t bl_depth;
  462. uint8_t last_bl_tag_done;
  463. atomic_t work_record;
  464. };
  465. /**
  466. * struct cam_cdm - CDM hw device struct
  467. *
  468. * @index: index of CDM hardware
  469. * @name: cdm_name
  470. * @id: enum for possible CDM hardwares
  471. * @flags: enum to tell if CDM is private of shared
  472. * @reset_complete: completion event to make CDM wait for reset
  473. * @work_queue: workqueue to schedule work for virtual CDM
  474. * @bl_request_list: bl_request list for submitted commands in
  475. * virtual CDM
  476. * @version: CDM version with major, minor, incr and reserved
  477. * @hw_version: CDM version as read from the cdm_version register
  478. * @hw_family_version: version of hw family the CDM belongs to
  479. * @iommu_hdl: CDM iommu handle
  480. * @offsets: pointer to structure of CDM registers
  481. * @ops: CDM ops for generating cdm commands
  482. * @clients: CDM clients array currently active on CDM
  483. * @bl_fifo: structure with per fifo related attributes
  484. * @cdm_status: bitfield with bits assigned for different cdm status
  485. * @bl_tag: slot value at which the next bl cmd will be written
  486. * in case of virtual CDM
  487. * @gen_irq: memory region in which gen_irq command will be written
  488. * @cpas_handle: handle for cpas driver
  489. * @arbitration: type of arbitration to be used for the CDM
  490. * @num_active_clients: Number of currently active clients
  491. */
  492. struct cam_cdm {
  493. uint32_t index;
  494. char name[128];
  495. enum cam_cdm_id id;
  496. enum cam_cdm_flags flags;
  497. struct completion reset_complete;
  498. struct workqueue_struct *work_queue;
  499. struct list_head bl_request_list;
  500. struct cam_hw_version version;
  501. uint32_t hw_version;
  502. uint32_t hw_family_version;
  503. struct cam_iommu_handle iommu_hdl;
  504. struct cam_cdm_hw_reg_offset *offsets;
  505. struct cam_cdm_utils_ops *ops;
  506. struct cam_cdm_client *clients[CAM_PER_CDM_MAX_REGISTERED_CLIENTS];
  507. struct cam_cdm_bl_fifo bl_fifo[CAM_CDM_BL_FIFO_MAX];
  508. unsigned long cdm_status;
  509. uint8_t bl_tag;
  510. uint32_t cpas_handle;
  511. enum cam_cdm_arbitration arbitration;
  512. uint8_t num_active_clients;
  513. };
  514. /* struct cam_cdm_private_dt_data - CDM hw custom dt data */
  515. struct cam_cdm_private_dt_data {
  516. bool dt_cdm_shared;
  517. bool config_fifo;
  518. bool is_single_ctx_cdm;
  519. uint8_t priority_group;
  520. uint32_t fifo_depth[CAM_CDM_BL_FIFO_MAX];
  521. uint32_t dt_num_supported_clients;
  522. uint32_t pid;
  523. uint32_t mid;
  524. const char *dt_cdm_client_name[CAM_PER_CDM_MAX_REGISTERED_CLIENTS];
  525. };
  526. /* struct cam_cdm_intf_devices - CDM mgr interface devices */
  527. struct cam_cdm_intf_devices {
  528. struct mutex lock;
  529. uint32_t refcount;
  530. struct cam_hw_intf *device;
  531. struct cam_cdm_private_dt_data *data;
  532. };
  533. /* struct cam_cdm_intf_mgr - CDM mgr interface device struct */
  534. struct cam_cdm_intf_mgr {
  535. bool probe_done;
  536. uint32_t cdm_count;
  537. uint32_t dt_supported_hw_cdm;
  538. int32_t refcount;
  539. struct cam_cdm_intf_devices nodes[CAM_CDM_INTF_MGR_MAX_SUPPORTED_CDM];
  540. struct dentry *dentry;
  541. };
  542. int cam_cdm_intf_register_hw_cdm(struct cam_hw_intf *hw,
  543. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  544. uint32_t *index);
  545. int cam_cdm_intf_deregister_hw_cdm(struct cam_hw_intf *hw,
  546. struct cam_cdm_private_dt_data *data, enum cam_cdm_type type,
  547. uint32_t index);
  548. #endif /* _CAM_CDM_H_ */