cam_soc_util.h 22 KB

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