cam_soc_util.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_SOC_UTIL_H_
  6. #define _CAM_SOC_UTIL_H_
  7. #include <linux/slab.h>
  8. #include <linux/clk.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/io.h>
  11. #include <linux/delay.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/i2c.h>
  14. #include <linux/regulator/consumer.h>
  15. #include <linux/debugfs.h>
  16. #include <linux/of_fdt.h>
  17. #include "cam_io_util.h"
  18. #include <media/cam_defs.h>
  19. #define NO_SET_RATE -1
  20. #define INIT_RATE -2
  21. /* maximum number of device block */
  22. #define CAM_SOC_MAX_BLOCK 7
  23. /* maximum number of device base */
  24. #define CAM_SOC_MAX_BASE CAM_SOC_MAX_BLOCK
  25. /* maximum number of device regulator */
  26. #define CAM_SOC_MAX_REGULATOR 10
  27. /* maximum number of device clock */
  28. #define CAM_SOC_MAX_CLK 32
  29. /* DDR device types */
  30. #define DDR_TYPE_LPDDR4 6
  31. #define DDR_TYPE_LPDDR4X 7
  32. #define DDR_TYPE_LPDDR5 8
  33. #define DDR_TYPE_LPDDR5X 9
  34. /* Maximum length of tag while dumping */
  35. #define CAM_SOC_HW_DUMP_TAG_MAX_LEN 32
  36. /**
  37. * enum cam_vote_level - Enum for voting level
  38. *
  39. * @CAM_SUSPEND_VOTE : Suspend vote
  40. * @CAM_MINSVS_VOTE : Min SVS vote
  41. * @CAM_LOWSVS_VOTE : Low SVS vote
  42. * @CAM_SVS_VOTE : SVS vote
  43. * @CAM_SVSL1_VOTE : SVS Plus vote
  44. * @CAM_NOMINAL_VOTE : Nominal vote
  45. * @CAM_NOMINALL1_VOTE: Nominal plus vote
  46. * @CAM_TURBO_VOTE : Turbo vote
  47. * @CAM_MAX_VOTE : Max voting level, This is invalid level.
  48. */
  49. enum cam_vote_level {
  50. CAM_SUSPEND_VOTE,
  51. CAM_MINSVS_VOTE,
  52. CAM_LOWSVS_VOTE,
  53. CAM_SVS_VOTE,
  54. CAM_SVSL1_VOTE,
  55. CAM_NOMINAL_VOTE,
  56. CAM_NOMINALL1_VOTE,
  57. CAM_TURBO_VOTE,
  58. CAM_MAX_VOTE,
  59. };
  60. /* pinctrl states */
  61. #define CAM_SOC_PINCTRL_STATE_SLEEP "cam_suspend"
  62. #define CAM_SOC_PINCTRL_STATE_DEFAULT "cam_default"
  63. /**
  64. * struct cam_soc_reg_map: Information about the mapped register space
  65. *
  66. * @mem_base: Starting location of MAPPED register space
  67. * @mem_cam_base: Starting offset of this register space compared
  68. * to ENTIRE Camera register space
  69. * @size: Size of register space
  70. **/
  71. struct cam_soc_reg_map {
  72. void __iomem *mem_base;
  73. uint32_t mem_cam_base;
  74. resource_size_t size;
  75. };
  76. /**
  77. * struct cam_soc_pinctrl_info: Information about pinctrl data
  78. *
  79. * @pinctrl: pintrl object
  80. * @gpio_state_active: default pinctrl state
  81. * @gpio_state_suspend suspend state of pinctrl
  82. **/
  83. struct cam_soc_pinctrl_info {
  84. struct pinctrl *pinctrl;
  85. struct pinctrl_state *gpio_state_active;
  86. struct pinctrl_state *gpio_state_suspend;
  87. };
  88. /**
  89. * struct cam_soc_gpio_data: Information about the gpio pins
  90. *
  91. * @cam_gpio_common_tbl: It is list of al the gpios present in gpios node
  92. * @cam_gpio_common_tbl_size: It is equal to number of gpios prsent in
  93. * gpios node in DTSI
  94. * @cam_gpio_req_tbl It is list of al the requesetd gpios
  95. * @cam_gpio_req_tbl_size: It is size of requested gpios
  96. **/
  97. struct cam_soc_gpio_data {
  98. struct gpio *cam_gpio_common_tbl;
  99. uint8_t cam_gpio_common_tbl_size;
  100. struct gpio *cam_gpio_req_tbl;
  101. uint8_t cam_gpio_req_tbl_size;
  102. };
  103. /**
  104. * struct cam_hw_soc_info: Soc information pertaining to specific instance of
  105. * Camera hardware driver module
  106. *
  107. * @pdev: Platform device pointer
  108. * @device: Device pointer
  109. * @hw_version: Camera device version
  110. * @index: Instance id for the camera device
  111. * @dev_name: Device Name
  112. * @irq_name: Name of the irq associated with the device
  113. * @label_name: label name
  114. * @irq_line: Irq resource
  115. * @irq_data: Private data that is passed when IRQ is requested
  116. * @compatible: Compatible string associated with the device
  117. * @num_mem_block: Number of entry in the "reg-names"
  118. * @mem_block_name: Array of the reg block name
  119. * @mem_block_cam_base: Array of offset of this register space compared
  120. * to ENTIRE Camera register space
  121. * @mem_block: Associated resource structs
  122. * @reg_map: Array of Mapped register info for the "reg-names"
  123. * @num_reg_map: Number of mapped register space associated
  124. * with mem_block. num_reg_map = num_mem_block in
  125. * most cases
  126. * @reserve_mem: Whether to reserve memory for Mem blocks
  127. * @num_rgltr: Number of regulators
  128. * @rgltr_name: Array of regulator names
  129. * @rgltr_ctrl_support: Whether regulator control is supported
  130. * @rgltr_min_volt: Array of minimum regulator voltage
  131. * @rgltr_max_volt: Array of maximum regulator voltage
  132. * @rgltr_op_mode: Array of regulator operation mode
  133. * @rgltr_type: Array of regulator names
  134. * @rgltr: Array of associated regulator resources
  135. * @rgltr_delay: Array of regulator delay values
  136. * @num_clk: Number of clocks
  137. * @clk_name: Array of clock names
  138. * @clk: Array of associated clock resources
  139. * @clk_rate: 2D array of clock rates representing clock rate
  140. * values at different vote levels
  141. * @prev_clk_level Last vote level
  142. * @src_clk_idx: Source clock index that is rate-controllable
  143. * @clk_level_valid: Indicates whether corresponding level is valid
  144. * @scl_clk_count: Number of scalable clocks present
  145. * @scl_clk_idx: Index of scalable clocks
  146. * @gpio_data: Pointer to gpio info
  147. * @pinctrl_info: Pointer to pinctrl info
  148. * @dentry: Debugfs entry
  149. * @clk_level_override: Clk level set from debugfs
  150. * @clk_control: Enable/disable clk rate control through debugfs
  151. * @cam_cx_ipeak_enable cx-ipeak enable/disable flag
  152. * @cam_cx_ipeak_bit cx-ipeak mask for driver
  153. * @soc_private: Soc private data
  154. */
  155. struct cam_hw_soc_info {
  156. struct platform_device *pdev;
  157. struct device *dev;
  158. uint32_t hw_version;
  159. uint32_t index;
  160. const char *dev_name;
  161. const char *irq_name;
  162. const char *label_name;
  163. struct resource *irq_line;
  164. void *irq_data;
  165. const char *compatible;
  166. uint32_t num_mem_block;
  167. const char *mem_block_name[CAM_SOC_MAX_BLOCK];
  168. uint32_t mem_block_cam_base[CAM_SOC_MAX_BLOCK];
  169. struct resource *mem_block[CAM_SOC_MAX_BLOCK];
  170. struct cam_soc_reg_map reg_map[CAM_SOC_MAX_BASE];
  171. uint32_t num_reg_map;
  172. uint32_t reserve_mem;
  173. uint32_t num_rgltr;
  174. const char *rgltr_name[CAM_SOC_MAX_REGULATOR];
  175. uint32_t rgltr_ctrl_support;
  176. uint32_t rgltr_min_volt[CAM_SOC_MAX_REGULATOR];
  177. uint32_t rgltr_max_volt[CAM_SOC_MAX_REGULATOR];
  178. uint32_t rgltr_op_mode[CAM_SOC_MAX_REGULATOR];
  179. uint32_t rgltr_type[CAM_SOC_MAX_REGULATOR];
  180. struct regulator *rgltr[CAM_SOC_MAX_REGULATOR];
  181. uint32_t rgltr_delay[CAM_SOC_MAX_REGULATOR];
  182. uint32_t use_shared_clk;
  183. uint32_t num_clk;
  184. const char *clk_name[CAM_SOC_MAX_CLK];
  185. struct clk *clk[CAM_SOC_MAX_CLK];
  186. int32_t clk_rate[CAM_MAX_VOTE][CAM_SOC_MAX_CLK];
  187. int32_t prev_clk_level;
  188. int32_t src_clk_idx;
  189. bool clk_level_valid[CAM_MAX_VOTE];
  190. int32_t scl_clk_count;
  191. int32_t scl_clk_idx[CAM_SOC_MAX_CLK];
  192. struct cam_soc_gpio_data *gpio_data;
  193. struct cam_soc_pinctrl_info pinctrl_info;
  194. struct dentry *dentry;
  195. uint32_t clk_level_override;
  196. bool clk_control_enable;
  197. bool cam_cx_ipeak_enable;
  198. int32_t cam_cx_ipeak_bit;
  199. void *soc_private;
  200. };
  201. /**
  202. * struct cam_hw_soc_dump_header - SOC dump header
  203. *
  204. * @Brief: soc hw dump header
  205. *
  206. * @tag: Tag name for the header
  207. * @word_size: Size of each word
  208. * @size: Total size of dumped data
  209. */
  210. struct cam_hw_soc_dump_header {
  211. uint8_t tag[CAM_SOC_HW_DUMP_TAG_MAX_LEN];
  212. uint64_t size;
  213. uint32_t word_size;
  214. };
  215. /**
  216. * struct cam_hw_soc_dump_args: SOC Dump args
  217. *
  218. * @request_id: Issue request id
  219. * @offset: Buffer offset, updated as the informaton is dumped
  220. * @buf_handle: Buffer handle of the out buffer
  221. */
  222. struct cam_hw_soc_dump_args {
  223. uint64_t request_id;
  224. size_t offset;
  225. uint32_t buf_handle;
  226. };
  227. /*
  228. * CAM_SOC_GET_REG_MAP_START
  229. *
  230. * @brief: This MACRO will get the mapped starting address
  231. * where the register space can be accessed
  232. *
  233. * @__soc_info: Device soc information
  234. * @__base_index: Index of register space in the HW block
  235. *
  236. * @return: Returns a pointer to the mapped register memory
  237. */
  238. #define CAM_SOC_GET_REG_MAP_START(__soc_info, __base_index) \
  239. ((!__soc_info || __base_index >= __soc_info->num_reg_map) ? \
  240. NULL : __soc_info->reg_map[__base_index].mem_base)
  241. /*
  242. * CAM_SOC_GET_REG_MAP_CAM_BASE
  243. *
  244. * @brief: This MACRO will get the cam_base of the
  245. * register space
  246. *
  247. * @__soc_info: Device soc information
  248. * @__base_index: Index of register space in the HW block
  249. *
  250. * @return: Returns an int32_t value.
  251. * Failure: -1
  252. * Success: Starting offset of register space compared
  253. * to entire Camera Register Map
  254. */
  255. #define CAM_SOC_GET_REG_MAP_CAM_BASE(__soc_info, __base_index) \
  256. ((!__soc_info || __base_index >= __soc_info->num_reg_map) ? \
  257. -1 : __soc_info->reg_map[__base_index].mem_cam_base)
  258. /*
  259. * CAM_SOC_GET_REG_MAP_SIZE
  260. *
  261. * @brief: This MACRO will get the size of the mapped
  262. * register space
  263. *
  264. * @__soc_info: Device soc information
  265. * @__base_index: Index of register space in the HW block
  266. *
  267. * @return: Returns a uint32_t value.
  268. * Failure: 0
  269. * Success: Non-zero size of mapped register space
  270. */
  271. #define CAM_SOC_GET_REG_MAP_SIZE(__soc_info, __base_index) \
  272. ((!__soc_info || __base_index >= __soc_info->num_reg_map) ? \
  273. 0 : __soc_info->reg_map[__base_index].size)
  274. /**
  275. * cam_soc_util_get_level_from_string()
  276. *
  277. * @brief: Get the associated vote level for the input string
  278. *
  279. * @string: Input string to compare with.
  280. * @level: Vote level corresponds to input string.
  281. *
  282. * @return: Success or failure
  283. */
  284. int cam_soc_util_get_level_from_string(const char *string,
  285. enum cam_vote_level *level);
  286. /**
  287. * cam_soc_util_get_dt_properties()
  288. *
  289. * @brief: Parse the DT and populate the common properties that
  290. * are part of the soc_info structure - register map,
  291. * clocks, regulators, irq, etc.
  292. *
  293. * @soc_info: Device soc struct to be populated
  294. *
  295. * @return: Success or failure
  296. */
  297. int cam_soc_util_get_dt_properties(struct cam_hw_soc_info *soc_info);
  298. /**
  299. * cam_soc_util_request_platform_resource()
  300. *
  301. * @brief: Request regulator, irq, and clock resources
  302. *
  303. * @soc_info: Device soc information
  304. * @handler: Irq handler function pointer
  305. * @irq_data: Irq handler function CB data
  306. *
  307. * @return: Success or failure
  308. */
  309. int cam_soc_util_request_platform_resource(struct cam_hw_soc_info *soc_info,
  310. irq_handler_t handler, void *irq_data);
  311. /**
  312. * cam_soc_util_release_platform_resource()
  313. *
  314. * @brief: Release regulator, irq, and clock resources
  315. *
  316. * @soc_info: Device soc information
  317. *
  318. * @return: Success or failure
  319. */
  320. int cam_soc_util_release_platform_resource(struct cam_hw_soc_info *soc_info);
  321. /**
  322. * cam_soc_util_enable_platform_resource()
  323. *
  324. * @brief: Enable regulator, irq resources
  325. *
  326. * @soc_info: Device soc information
  327. * @enable_clocks: Boolean flag:
  328. * TRUE: Enable all clocks in soc_info Now.
  329. * False: Don't enable clocks Now. Driver will
  330. * enable independently.
  331. * @clk_level: Clock level to be applied.
  332. * Applicable only if enable_clocks is true
  333. * Valid range : 0 to (CAM_MAX_VOTE - 1)
  334. * @enable_irq: Boolean flag:
  335. * TRUE: Enable IRQ in soc_info Now.
  336. * False: Don't enable IRQ Now. Driver will
  337. * enable independently.
  338. *
  339. * @return: Success or failure
  340. */
  341. int cam_soc_util_enable_platform_resource(struct cam_hw_soc_info *soc_info,
  342. bool enable_clocks, enum cam_vote_level clk_level, bool enable_irq);
  343. /**
  344. * cam_soc_util_disable_platform_resource()
  345. *
  346. * @brief: Disable regulator, irq resources
  347. *
  348. * @soc_info: Device soc information
  349. * @disable_irq: Boolean flag:
  350. * TRUE: Disable IRQ in soc_info Now.
  351. * False: Don't disable IRQ Now. Driver will
  352. * disable independently.
  353. *
  354. * @return: Success or failure
  355. */
  356. int cam_soc_util_disable_platform_resource(struct cam_hw_soc_info *soc_info,
  357. bool disable_clocks, bool disable_irq);
  358. /**
  359. * cam_soc_util_get_clk_round_rate()
  360. *
  361. * @brief: Get the rounded clock rate for the given clock's
  362. * clock rate value
  363. *
  364. * @soc_info: Device soc information
  365. * @clk_index: Clock index in soc_info for which round rate is needed
  366. * @clk_rate: Input clock rate for which rounded rate is needed
  367. *
  368. * @return: Rounded clock rate
  369. */
  370. long cam_soc_util_get_clk_round_rate(struct cam_hw_soc_info *soc_info,
  371. uint32_t clk_index, unsigned long clk_rate);
  372. /**
  373. * cam_soc_util_set_src_clk_rate()
  374. *
  375. * @brief: Set the rate on the source clock.
  376. *
  377. * @soc_info: Device soc information
  378. * @clk_rate: Clock rate associated with the src clk
  379. *
  380. * @return: success or failure
  381. */
  382. int cam_soc_util_set_src_clk_rate(struct cam_hw_soc_info *soc_info,
  383. int64_t clk_rate);
  384. /**
  385. * cam_soc_util_get_option_clk_by_name()
  386. *
  387. * @brief: Get reference to optional clk using name
  388. *
  389. * @soc_info: Device soc information
  390. * @clk_name: Name of clock to find reference for
  391. * @clk: Clock reference pointer to be filled if Success
  392. * @clk_index: Clk index in the option clk array to be returned
  393. * @clk_rate: Clk rate in the option clk array
  394. *
  395. * @return: 0: Success
  396. * Negative: Failure
  397. */
  398. int cam_soc_util_get_option_clk_by_name(struct cam_hw_soc_info *soc_info,
  399. const char *clk_name, struct clk **clk, int32_t *clk_index,
  400. int32_t *clk_rate);
  401. /**
  402. * cam_soc_util_clk_put()
  403. *
  404. * @brief: Put clock specified in params
  405. *
  406. * @clk: Reference to the Clock that needs to be put
  407. *
  408. * @return: Success or failure
  409. */
  410. int cam_soc_util_clk_put(struct clk **clk);
  411. /**
  412. * cam_soc_util_clk_enable()
  413. *
  414. * @brief: Enable clock specified in params
  415. *
  416. * @clk: Clock that needs to be turned ON
  417. * @clk_name: Clocks name associated with clk
  418. * @clk_rate: Clocks rate associated with clk
  419. *
  420. * @return: Success or failure
  421. */
  422. int cam_soc_util_clk_enable(struct clk *clk, const char *clk_name,
  423. int32_t clk_rate);
  424. /**
  425. * cam_soc_util_set_clk_rate_level()
  426. *
  427. * @brief: Apply clock rates for the requested level.
  428. * This applies the new requested level for all
  429. * the clocks listed in DT based on their values.
  430. *
  431. * @soc_info: Device soc information
  432. * @clk_level: Clock level number to set
  433. *
  434. * @return: Success or failure
  435. */
  436. int cam_soc_util_set_clk_rate_level(struct cam_hw_soc_info *soc_info,
  437. enum cam_vote_level clk_level);
  438. /**
  439. * cam_soc_util_clk_disable()
  440. *
  441. * @brief: Disable clock specified in params
  442. *
  443. * @clk: Clock that needs to be turned OFF
  444. * @clk_name: Clocks name associated with clk
  445. *
  446. * @return: Success or failure
  447. */
  448. int cam_soc_util_clk_disable(struct clk *clk, const char *clk_name);
  449. /**
  450. * cam_soc_util_irq_enable()
  451. *
  452. * @brief: Enable IRQ in SOC
  453. *
  454. * @soc_info: Device soc information
  455. *
  456. * @return: Success or failure
  457. */
  458. int cam_soc_util_irq_enable(struct cam_hw_soc_info *soc_info);
  459. /**
  460. * cam_soc_util_irq_disable()
  461. *
  462. * @brief: Disable IRQ in SOC
  463. *
  464. * @soc_info: Device soc information
  465. *
  466. * @return: Success or failure
  467. */
  468. int cam_soc_util_irq_disable(struct cam_hw_soc_info *soc_info);
  469. /**
  470. * cam_soc_util_regulator_enable()
  471. *
  472. * @brief: Enable single regulator
  473. *
  474. * @rgltr Regulator that needs to be turned ON
  475. * @rgltr_name Associated Regulator name
  476. * @rgltr_min_volt: Requested minimum volatage
  477. * @rgltr_max_volt: Requested maximum volatage
  478. * @rgltr_op_mode: Requested Load
  479. * @rgltr_delay: Requested delay needed aaftre enabling regulator
  480. *
  481. * @return: Success or failure
  482. */
  483. int cam_soc_util_regulator_enable(struct regulator *rgltr,
  484. const char *rgltr_name,
  485. uint32_t rgltr_min_volt, uint32_t rgltr_max_volt,
  486. uint32_t rgltr_op_mode, uint32_t rgltr_delay);
  487. /**
  488. * cam_soc_util_regulator_enable()
  489. *
  490. * @brief: Disable single regulator
  491. *
  492. * @rgltr Regulator that needs to be turned ON
  493. * @rgltr_name Associated Regulator name
  494. * @rgltr_min_volt: Requested minimum volatage
  495. * @rgltr_max_volt: Requested maximum volatage
  496. * @rgltr_op_mode: Requested Load
  497. * @rgltr_delay: Requested delay needed aaftre enabling regulator
  498. *
  499. * @return: Success or failure
  500. */
  501. int cam_soc_util_regulator_disable(struct regulator *rgltr,
  502. const char *rgltr_name,
  503. uint32_t rgltr_min_volt, uint32_t rgltr_max_volt,
  504. uint32_t rgltr_op_mode, uint32_t rgltr_delay);
  505. /**
  506. * cam_soc_util_w()
  507. *
  508. * @brief: Camera SOC util for register write
  509. *
  510. * @soc_info: Device soc information
  511. * @base_index: Index of register space in the HW block
  512. * @offset: Offset of register to be read
  513. * @data: Value to be written
  514. *
  515. * @return: Success or Failure
  516. */
  517. static inline int cam_soc_util_w(struct cam_hw_soc_info *soc_info,
  518. uint32_t base_index, uint32_t offset, uint32_t data)
  519. {
  520. if (!CAM_SOC_GET_REG_MAP_START(soc_info, base_index))
  521. return -EINVAL;
  522. return cam_io_w(data,
  523. CAM_SOC_GET_REG_MAP_START(soc_info, base_index) + offset);
  524. }
  525. /**
  526. * cam_soc_util_w_mb()
  527. *
  528. * @brief: Camera SOC util for register write with memory barrier.
  529. * Memory Barrier is only before the write to ensure the
  530. * order. If need to ensure this write is also flushed
  531. * call wmb() independently in the caller.
  532. *
  533. * @soc_info: Device soc information
  534. * @base_index: Index of register space in the HW block
  535. * @offset: Offset of register to be read
  536. * @data: Value to be written
  537. *
  538. * @return: Success or Failure
  539. */
  540. static inline int cam_soc_util_w_mb(struct cam_hw_soc_info *soc_info,
  541. uint32_t base_index, uint32_t offset, uint32_t data)
  542. {
  543. if (!CAM_SOC_GET_REG_MAP_START(soc_info, base_index))
  544. return -EINVAL;
  545. return cam_io_w_mb(data,
  546. CAM_SOC_GET_REG_MAP_START(soc_info, base_index) + offset);
  547. }
  548. /**
  549. * cam_soc_util_r()
  550. *
  551. * @brief: Camera SOC util for register read
  552. *
  553. * @soc_info: Device soc information
  554. * @base_index: Index of register space in the HW block
  555. * @offset: Offset of register to be read
  556. *
  557. * @return: Value read from the register address
  558. */
  559. static inline uint32_t cam_soc_util_r(struct cam_hw_soc_info *soc_info,
  560. uint32_t base_index, uint32_t offset)
  561. {
  562. if (!CAM_SOC_GET_REG_MAP_START(soc_info, base_index))
  563. return 0;
  564. return cam_io_r(
  565. CAM_SOC_GET_REG_MAP_START(soc_info, base_index) + offset);
  566. }
  567. /**
  568. * cam_soc_util_r_mb()
  569. *
  570. * @brief: Camera SOC util for register read with memory barrier.
  571. * Memory Barrier is only before the write to ensure the
  572. * order. If need to ensure this write is also flushed
  573. * call rmb() independently in the caller.
  574. *
  575. * @soc_info: Device soc information
  576. * @base_index: Index of register space in the HW block
  577. * @offset: Offset of register to be read
  578. *
  579. * @return: Value read from the register address
  580. */
  581. static inline uint32_t cam_soc_util_r_mb(struct cam_hw_soc_info *soc_info,
  582. uint32_t base_index, uint32_t offset)
  583. {
  584. if (!CAM_SOC_GET_REG_MAP_START(soc_info, base_index))
  585. return 0;
  586. return cam_io_r_mb(
  587. CAM_SOC_GET_REG_MAP_START(soc_info, base_index) + offset);
  588. }
  589. /**
  590. * cam_soc_util_reg_dump()
  591. *
  592. * @brief: Camera SOC util for dumping a range of register
  593. *
  594. * @soc_info: Device soc information
  595. * @base_index: Index of register space in the HW block
  596. * @offset: Start register offset for the dump
  597. * @size: Size specifying the range for dump
  598. *
  599. * @return: Success or Failure
  600. */
  601. int cam_soc_util_reg_dump(struct cam_hw_soc_info *soc_info,
  602. uint32_t base_index, uint32_t offset, int size);
  603. void cam_soc_util_clk_disable_default(struct cam_hw_soc_info *soc_info);
  604. int cam_soc_util_clk_enable_default(struct cam_hw_soc_info *soc_info,
  605. enum cam_vote_level clk_level);
  606. int cam_soc_util_get_clk_level(struct cam_hw_soc_info *soc_info,
  607. int64_t clk_rate, int clk_idx, int32_t *clk_lvl);
  608. /* Callback to get reg space data for specific HW */
  609. typedef int (*cam_soc_util_regspace_data_cb)(uint32_t reg_base_type,
  610. void *ctx, struct cam_hw_soc_info **soc_info_ptr,
  611. uint32_t *reg_base_idx);
  612. /**
  613. * cam_soc_util_reg_dump_to_cmd_buf()
  614. *
  615. * @brief: Camera SOC util for dumping sets of register ranges
  616. * command buffer
  617. *
  618. * @ctx: Context info from specific hardware manager
  619. * @cmd_desc: Command buffer descriptor
  620. * @req_id: Last applied req id for which reg dump is required
  621. * @reg_data_cb: Callback function to get reg space info based on type
  622. * in command buffer
  623. * @soc_dump_args: Dump buffer args to dump the soc information.
  624. * @user_triggered_dump: Flag to indicate if the dump request is issued by
  625. * user.
  626. * @return: Success or Failure
  627. */
  628. int cam_soc_util_reg_dump_to_cmd_buf(void *ctx,
  629. struct cam_cmd_buf_desc *cmd_desc, uint64_t req_id,
  630. cam_soc_util_regspace_data_cb reg_data_cb,
  631. struct cam_hw_soc_dump_args *soc_dump_args,
  632. bool user_triggered_dump);
  633. #endif /* _CAM_SOC_UTIL_H_ */