cam_soc_util.h 32 KB

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