cam_soc_util.h 32 KB

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