cam_soc_util.h 27 KB

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