cam_soc_util.h 27 KB

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