cam_soc_util.h 31 KB

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