cam_soc_util.h 33 KB

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