cam_soc_util.h 24 KB

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