cam_cpas_api.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_CPAS_API_H_
  6. #define _CAM_CPAS_API_H_
  7. #include <linux/device.h>
  8. #include <linux/platform_device.h>
  9. #include <media/cam_cpas.h>
  10. #include "cam_soc_util.h"
  11. #define CAM_HW_IDENTIFIER_LENGTH 128
  12. /* Default AXI Bandwidth vote */
  13. #define CAM_CPAS_DEFAULT_AXI_BW 1024
  14. #define CAM_CPAS_MAX_PATHS_PER_CLIENT 15
  15. #define CAM_CPAS_API_PATH_DATA_STD_START 512
  16. /**
  17. * enum cam_cpas_reg_base - Enum for register base identifier. These
  18. * are the identifiers used in generic register
  19. * write/read APIs provided by cpas driver.
  20. */
  21. enum cam_cpas_reg_base {
  22. CAM_CPAS_REG_CPASTOP,
  23. CAM_CPAS_REG_CAMNOC,
  24. CAM_CPAS_REG_CAMSS,
  25. CAM_CPAS_REG_MAX
  26. };
  27. /**
  28. * enum cam_cpas_hw_version - Enum for Titan CPAS HW Versions
  29. */
  30. enum cam_cpas_hw_version {
  31. CAM_CPAS_TITAN_NONE = 0,
  32. CAM_CPAS_TITAN_150_V100 = 0x150100,
  33. CAM_CPAS_TITAN_170_V100 = 0x170100,
  34. CAM_CPAS_TITAN_170_V110 = 0x170110,
  35. CAM_CPAS_TITAN_170_V120 = 0x170120,
  36. CAM_CPAS_TITAN_175_V100 = 0x175100,
  37. CAM_CPAS_TITAN_175_V101 = 0x175101,
  38. CAM_CPAS_TITAN_175_V120 = 0x175120,
  39. CAM_CPAS_TITAN_175_V130 = 0x175130,
  40. CAM_CPAS_TITAN_480_V100 = 0x480100,
  41. CAM_CPAS_TITAN_580_V100 = 0x580100,
  42. CAM_CPAS_TITAN_540_V100 = 0x540100,
  43. CAM_CPAS_TITAN_MAX
  44. };
  45. /**
  46. * enum cam_camnoc_irq_type - Enum for camnoc irq types
  47. *
  48. * @CAM_CAMNOC_IRQ_SLAVE_ERROR: Each slave port in CAMNOC (3 QSB ports and
  49. * 1 QHB port) has an error logger. The error
  50. * observed at any slave port is logged into
  51. * the error logger register and an IRQ is
  52. * triggered
  53. * @CAM_CAMNOC_IRQ_IFE_UBWC_STATS_ENCODE_ERROR: Triggered if any error detected
  54. * in the IFE UBWC-Stats encoder
  55. * instance
  56. * @CAM_CAMNOC_IRQ_IFE02_UBWC_ENCODE_ERROR : Triggered if any error detected
  57. * in the IFE0 UBWC encoder instance
  58. * @CAM_CAMNOC_IRQ_IFE13_UBWC_ENCODE_ERROR : Triggered if any error detected
  59. * in the IFE1 or IFE3 UBWC encoder
  60. * instance
  61. * @CAM_CAMNOC_IRQ_IFE0_UBWC_ENCODE_ERROR : Triggered if any error detected
  62. * in the IFE0 UBWC encoder instance
  63. * @CAM_CAMNOC_IRQ_IFE1_WR_UBWC_ENCODE_ERROR : Triggered if any error detected
  64. * in the IFE1 UBWC encoder
  65. * instance
  66. * @CAM_CAMNOC_IRQ_IPE1_BPS_UBWC_DECODE_ERROR: Triggered if any error detected
  67. * in the IPE1/BPS read path decoder
  68. * instance
  69. * @CAM_CAMNOC_IRQ_IPE0_UBWC_DECODE_ERROR : Triggered if any error detected
  70. * in the IPE0 read path decoder
  71. * instance
  72. * @CAM_CAMNOC_IRQ_IPE_BPS_UBWC_DECODE_ERROR: Triggered if any error detected
  73. * in the IPE/BPS UBWC decoder
  74. * instance
  75. * @CAM_CAMNOC_IRQ_IPE_BPS_UBWC_ENCODE_ERROR: Triggered if any error detected
  76. * in the IPE/BPS UBWC encoder
  77. * instance
  78. * @CAM_CAMNOC_IRQ_AHB_TIMEOUT : Triggered when the QHS_ICP slave
  79. * times out after 4000 AHB cycles
  80. */
  81. enum cam_camnoc_irq_type {
  82. CAM_CAMNOC_IRQ_SLAVE_ERROR,
  83. CAM_CAMNOC_IRQ_IFE_UBWC_STATS_ENCODE_ERROR,
  84. CAM_CAMNOC_IRQ_IFE_UBWC_STATS_1_ENCODE_ERROR,
  85. CAM_CAMNOC_IRQ_IFE02_UBWC_ENCODE_ERROR,
  86. CAM_CAMNOC_IRQ_IFE13_UBWC_ENCODE_ERROR,
  87. CAM_CAMNOC_IRQ_IFE0_UBWC_ENCODE_ERROR,
  88. CAM_CAMNOC_IRQ_IFE1_WRITE_UBWC_ENCODE_ERROR,
  89. CAM_CAMNOC_IRQ_IPE1_BPS_UBWC_DECODE_ERROR,
  90. CAM_CAMNOC_IRQ_IPE0_UBWC_DECODE_ERROR,
  91. CAM_CAMNOC_IRQ_IPE_BPS_UBWC_DECODE_ERROR,
  92. CAM_CAMNOC_IRQ_IPE_BPS_UBWC_ENCODE_ERROR,
  93. CAM_CAMNOC_IRQ_AHB_TIMEOUT,
  94. };
  95. /**
  96. * struct cam_camnoc_irq_slave_err_data : Data for Slave error.
  97. *
  98. * @mainctrl : Err logger mainctrl info
  99. * @errvld : Err logger errvld info
  100. * @errlog0_low : Err logger errlog0_low info
  101. * @errlog0_high : Err logger errlog0_high info
  102. * @errlog1_low : Err logger errlog1_low info
  103. * @errlog1_high : Err logger errlog1_high info
  104. * @errlog2_low : Err logger errlog2_low info
  105. * @errlog2_high : Err logger errlog2_high info
  106. * @errlog3_low : Err logger errlog3_low info
  107. * @errlog3_high : Err logger errlog3_high info
  108. *
  109. */
  110. struct cam_camnoc_irq_slave_err_data {
  111. union {
  112. struct {
  113. uint32_t stall_en : 1; /* bit 0 */
  114. uint32_t fault_en : 1; /* bit 1 */
  115. uint32_t rsv : 30; /* bits 2-31 */
  116. };
  117. uint32_t value;
  118. } mainctrl;
  119. union {
  120. struct {
  121. uint32_t err_vld : 1; /* bit 0 */
  122. uint32_t rsv : 31; /* bits 1-31 */
  123. };
  124. uint32_t value;
  125. } errvld;
  126. union {
  127. struct {
  128. uint32_t loginfo_vld : 1; /* bit 0 */
  129. uint32_t word_error : 1; /* bit 1 */
  130. uint32_t non_secure : 1; /* bit 2 */
  131. uint32_t device : 1; /* bit 3 */
  132. uint32_t opc : 3; /* bits 4 - 6 */
  133. uint32_t rsv0 : 1; /* bit 7 */
  134. uint32_t err_code : 3; /* bits 8 - 10 */
  135. uint32_t sizef : 3; /* bits 11 - 13 */
  136. uint32_t rsv1 : 2; /* bits 14 - 15 */
  137. uint32_t addr_space : 6; /* bits 16 - 21 */
  138. uint32_t rsv2 : 10; /* bits 22 - 31 */
  139. };
  140. uint32_t value;
  141. } errlog0_low;
  142. union {
  143. struct {
  144. uint32_t len1 : 10; /* bits 0 - 9 */
  145. uint32_t rsv : 22; /* bits 10 - 31 */
  146. };
  147. uint32_t value;
  148. } errlog0_high;
  149. union {
  150. struct {
  151. uint32_t path : 16; /* bits 0 - 15 */
  152. uint32_t rsv : 16; /* bits 16 - 31 */
  153. };
  154. uint32_t value;
  155. } errlog1_low;
  156. union {
  157. struct {
  158. uint32_t extid : 18; /* bits 0 - 17 */
  159. uint32_t rsv : 14; /* bits 18 - 31 */
  160. };
  161. uint32_t value;
  162. } errlog1_high;
  163. union {
  164. struct {
  165. uint32_t errlog2_lsb : 32; /* bits 0 - 31 */
  166. };
  167. uint32_t value;
  168. } errlog2_low;
  169. union {
  170. struct {
  171. uint32_t errlog2_msb : 16; /* bits 0 - 16 */
  172. uint32_t rsv : 16; /* bits 16 - 31 */
  173. };
  174. uint32_t value;
  175. } errlog2_high;
  176. union {
  177. struct {
  178. uint32_t errlog3_lsb : 32; /* bits 0 - 31 */
  179. };
  180. uint32_t value;
  181. } errlog3_low;
  182. union {
  183. struct {
  184. uint32_t errlog3_msb : 32; /* bits 0 - 31 */
  185. };
  186. uint32_t value;
  187. } errlog3_high;
  188. };
  189. /**
  190. * struct cam_camnoc_irq_ubwc_enc_data : Data for UBWC Encode error.
  191. *
  192. * @encerr_status : Encode error status
  193. *
  194. */
  195. struct cam_camnoc_irq_ubwc_enc_data {
  196. union {
  197. struct {
  198. uint32_t encerrstatus : 3; /* bits 0 - 2 */
  199. uint32_t rsv : 29; /* bits 3 - 31 */
  200. };
  201. uint32_t value;
  202. } encerr_status;
  203. };
  204. /**
  205. * struct cam_camnoc_irq_ubwc_dec_data : Data for UBWC Decode error.
  206. *
  207. * @decerr_status : Decoder error status
  208. * @thr_err : Set to 1 if
  209. * At least one of the bflc_len fields in the bit steam exceeds
  210. * its threshold value. This error is possible only for
  211. * RGBA1010102, TP10, and RGB565 formats
  212. * @fcl_err : Set to 1 if
  213. * Fast clear with a legal non-RGB format
  214. * @len_md_err : Set to 1 if
  215. * The calculated burst length does not match burst length
  216. * specified by the metadata value
  217. * @format_err : Set to 1 if
  218. * Illegal format
  219. * 1. bad format :2,3,6
  220. * 2. For 32B MAL, metadata=6
  221. * 3. For 32B MAL RGB565, Metadata != 0,1,7
  222. * 4. For 64B MAL RGB565, metadata[3:1] == 1,2
  223. *
  224. */
  225. struct cam_camnoc_irq_ubwc_dec_data {
  226. union {
  227. struct {
  228. uint32_t thr_err : 1; /* bit 0 */
  229. uint32_t fcl_err : 1; /* bit 1 */
  230. uint32_t len_md_err : 1; /* bit 2 */
  231. uint32_t format_err : 1; /* bit 3 */
  232. uint32_t rsv : 28; /* bits 4 - 31 */
  233. };
  234. uint32_t value;
  235. } decerr_status;
  236. };
  237. struct cam_camnoc_irq_ahb_timeout_data {
  238. uint32_t data;
  239. };
  240. /**
  241. * struct cam_cpas_irq_data : CAMNOC IRQ data
  242. *
  243. * @irq_type : To identify the type of IRQ
  244. * @u : Union of irq err data information
  245. * @slave_err : Data for Slave error.
  246. * Valid if type is CAM_CAMNOC_IRQ_SLAVE_ERROR
  247. * @enc_err : Data for UBWC Encode error.
  248. * Valid if type is one of below:
  249. * CAM_CAMNOC_IRQ_IFE02_UBWC_ENCODE_ERROR
  250. * CAM_CAMNOC_IRQ_IFE13_UBWC_ENCODE_ERROR
  251. * CAM_CAMNOC_IRQ_IPE_BPS_UBWC_ENCODE_ERROR
  252. * @dec_err : Data for UBWC Decode error.
  253. * Valid if type is CAM_CAMNOC_IRQ_IPE_BPS_UBWC_DECODE_ERROR
  254. * @ahb_err : Data for Slave error.
  255. * Valid if type is CAM_CAMNOC_IRQ_AHB_TIMEOUT
  256. *
  257. */
  258. struct cam_cpas_irq_data {
  259. enum cam_camnoc_irq_type irq_type;
  260. union {
  261. struct cam_camnoc_irq_slave_err_data slave_err;
  262. struct cam_camnoc_irq_ubwc_enc_data enc_err;
  263. struct cam_camnoc_irq_ubwc_dec_data dec_err;
  264. struct cam_camnoc_irq_ahb_timeout_data ahb_err;
  265. } u;
  266. };
  267. /**
  268. * struct cam_cpas_register_params : Register params for cpas client
  269. *
  270. * @identifier : Input identifier string which is the device label
  271. * from dt like vfe, ife, jpeg etc
  272. * @cell_index : Input integer identifier pointing to the cell index
  273. * from dt of the device. This can be used to form a
  274. * unique string with @identifier like vfe0, ife1,
  275. * jpeg0, etc
  276. * @dev : device handle
  277. * @userdata : Input private data which will be passed as
  278. * an argument while callback.
  279. * @cam_cpas_callback : Input callback pointer for triggering the
  280. * callbacks from CPAS driver.
  281. * @client_handle : CPAS client handle
  282. * @userdata : User data given at the time of register
  283. * @event_type : event type
  284. * @event_data : event data
  285. * @client_handle : Output Unique handle generated for this register
  286. *
  287. */
  288. struct cam_cpas_register_params {
  289. char identifier[CAM_HW_IDENTIFIER_LENGTH];
  290. uint32_t cell_index;
  291. struct device *dev;
  292. void *userdata;
  293. bool (*cam_cpas_client_cb)(
  294. uint32_t client_handle,
  295. void *userdata,
  296. struct cam_cpas_irq_data *irq_data);
  297. uint32_t client_handle;
  298. };
  299. /**
  300. * enum cam_vote_type - Enum for voting type
  301. *
  302. * @CAM_VOTE_ABSOLUTE : Absolute vote
  303. * @CAM_VOTE_DYNAMIC : Dynamic vote
  304. */
  305. enum cam_vote_type {
  306. CAM_VOTE_ABSOLUTE,
  307. CAM_VOTE_DYNAMIC,
  308. };
  309. /**
  310. * struct cam_ahb_vote : AHB vote
  311. *
  312. * @type : AHB voting type.
  313. * CAM_VOTE_ABSOLUTE : vote based on the value 'level' is set
  314. * CAM_VOTE_DYNAMIC : vote calculated dynamically using 'freq'
  315. * and 'dev' handle is set
  316. * @level : AHB vote level
  317. * @freq : AHB vote dynamic frequency
  318. *
  319. */
  320. struct cam_ahb_vote {
  321. enum cam_vote_type type;
  322. union {
  323. enum cam_vote_level level;
  324. unsigned long freq;
  325. } vote;
  326. };
  327. /**
  328. * struct cam_axi_vote : AXI vote
  329. *
  330. * @num_paths: Number of paths on which BW vote is sent to CPAS
  331. * @axi_path: Per path BW vote info
  332. *
  333. */
  334. struct cam_axi_vote {
  335. uint32_t num_paths;
  336. struct cam_axi_per_path_bw_vote axi_path[CAM_CPAS_MAX_PATHS_PER_CLIENT];
  337. };
  338. /**
  339. * cam_cpas_register_client()
  340. *
  341. * @brief: API to register cpas client
  342. *
  343. * @register_params: Input params to register as a client to CPAS
  344. *
  345. * @return 0 on success.
  346. *
  347. */
  348. int cam_cpas_register_client(
  349. struct cam_cpas_register_params *register_params);
  350. /**
  351. * cam_cpas_unregister_client()
  352. *
  353. * @brief: API to unregister cpas client
  354. *
  355. * @client_handle: Client handle to be unregistered
  356. *
  357. * @return 0 on success.
  358. *
  359. */
  360. int cam_cpas_unregister_client(uint32_t client_handle);
  361. /**
  362. * cam_cpas_start()
  363. *
  364. * @brief: API to start cpas client hw. Clients have to vote for minimal
  365. * bandwidth requirements for AHB, AXI. Use cam_cpas_update_ahb_vote
  366. * to scale bandwidth after start.
  367. *
  368. * @client_handle: client cpas handle
  369. * @ahb_vote : Pointer to ahb vote info
  370. * @axi_vote : Pointer to axi bandwidth vote info
  371. *
  372. * If AXI vote is not applicable to a particular client, use the value exposed
  373. * by CAM_CPAS_DEFAULT_AXI_BW as the default vote request.
  374. *
  375. * @return 0 on success.
  376. *
  377. */
  378. int cam_cpas_start(
  379. uint32_t client_handle,
  380. struct cam_ahb_vote *ahb_vote,
  381. struct cam_axi_vote *axi_vote);
  382. /**
  383. * cam_cpas_stop()
  384. *
  385. * @brief: API to stop cpas client hw. Bandwidth for AHB, AXI votes
  386. * would be removed for this client on this call. Clients should not
  387. * use cam_cpas_update_ahb_vote or cam_cpas_update_axi_vote
  388. * to remove their bandwidth vote.
  389. *
  390. * @client_handle: client cpas handle
  391. *
  392. * @return 0 on success.
  393. *
  394. */
  395. int cam_cpas_stop(uint32_t client_handle);
  396. /**
  397. * cam_cpas_update_ahb_vote()
  398. *
  399. * @brief: API to update AHB vote requirement. Use this function only
  400. * between cam_cpas_start and cam_cpas_stop in case clients wants
  401. * to scale to different vote level. Do not use this function to de-vote,
  402. * removing client's vote is implicit on cam_cpas_stop
  403. *
  404. * @client_handle : Client cpas handle
  405. * @ahb_vote : Pointer to ahb vote info
  406. *
  407. * @return 0 on success.
  408. *
  409. */
  410. int cam_cpas_update_ahb_vote(
  411. uint32_t client_handle,
  412. struct cam_ahb_vote *ahb_vote);
  413. /**
  414. * cam_cpas_update_axi_vote()
  415. *
  416. * @brief: API to update AXI vote requirement. Use this function only
  417. * between cam_cpas_start and cam_cpas_stop in case clients wants
  418. * to scale to different vote level. Do not use this function to de-vote,
  419. * removing client's vote is implicit on cam_cpas_stop
  420. *
  421. * @client_handle : Client cpas handle
  422. * @axi_vote : Pointer to axi bandwidth vote info
  423. *
  424. * @return 0 on success.
  425. *
  426. */
  427. int cam_cpas_update_axi_vote(
  428. uint32_t client_handle,
  429. struct cam_axi_vote *axi_vote);
  430. /**
  431. * cam_cpas_reg_write()
  432. *
  433. * @brief: API to write a register value in CPAS register space
  434. *
  435. * @client_handle : Client cpas handle
  436. * @reg_base : Register base identifier
  437. * @offset : Offset from the register base address
  438. * @mb : Whether to do reg write with memory barrier
  439. * @value : Value to be written in register
  440. *
  441. * @return 0 on success.
  442. *
  443. */
  444. int cam_cpas_reg_write(
  445. uint32_t client_handle,
  446. enum cam_cpas_reg_base reg_base,
  447. uint32_t offset,
  448. bool mb,
  449. uint32_t value);
  450. /**
  451. * cam_cpas_reg_read()
  452. *
  453. * @brief: API to read a register value from CPAS register space
  454. *
  455. * @client_handle : Client cpas handle
  456. * @reg_base : Register base identifier
  457. * @offset : Offset from the register base address
  458. * @mb : Whether to do reg read with memory barrier
  459. * @value : Value to be red from register
  460. *
  461. * @return 0 on success.
  462. *
  463. */
  464. int cam_cpas_reg_read(
  465. uint32_t client_handle,
  466. enum cam_cpas_reg_base reg_base,
  467. uint32_t offset,
  468. bool mb,
  469. uint32_t *value);
  470. /**
  471. * cam_cpas_get_hw_info()
  472. *
  473. * @brief: API to get camera hw information
  474. *
  475. * @camera_family : Camera family type. One of
  476. * CAM_FAMILY_CAMERA_SS
  477. * CAM_FAMILY_CPAS_SS
  478. * @camera_version : Camera platform version
  479. * @cpas_version : Camera cpas version
  480. * @cam_caps : Camera capability
  481. *
  482. * @return 0 on success.
  483. *
  484. */
  485. int cam_cpas_get_hw_info(
  486. uint32_t *camera_family,
  487. struct cam_hw_version *camera_version,
  488. struct cam_hw_version *cpas_version,
  489. uint32_t *cam_caps);
  490. /**
  491. * cam_cpas_get_cpas_hw_version()
  492. *
  493. * @brief: API to get camera cpas hw version
  494. *
  495. * @hw_version : Camera cpas hw version
  496. *
  497. * @return 0 on success.
  498. *
  499. */
  500. int cam_cpas_get_cpas_hw_version(
  501. uint32_t *hw_version);
  502. /**
  503. * cam_cpas_is_feature_supported()
  504. *
  505. * @brief: API to get camera features
  506. *
  507. * @flag : Camera hw features to check
  508. *
  509. * @return 1 if feature is supported
  510. *
  511. */
  512. int cam_cpas_is_feature_supported(
  513. uint32_t flag);
  514. /**
  515. * cam_cpas_axi_util_path_type_to_string()
  516. *
  517. * @brief: API to get string for given path type
  518. *
  519. * @path_data_type : Path type
  520. *
  521. * @return string.
  522. *
  523. */
  524. const char *cam_cpas_axi_util_path_type_to_string(
  525. uint32_t path_data_type);
  526. /**
  527. * cam_cpas_axi_util_trans_type_to_string()
  528. *
  529. * @brief: API to get string for given transaction type
  530. *
  531. * @path_data_type : Transaction type
  532. *
  533. * @return string.
  534. *
  535. */
  536. const char *cam_cpas_axi_util_trans_type_to_string(
  537. uint32_t path_data_type);
  538. #endif /* _CAM_CPAS_API_H_ */