cam_cpas_api.h 16 KB

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