cam_soc_util.h 26 KB

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