cam_cpas_soc.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _CAM_CPAS_SOC_H_
  7. #define _CAM_CPAS_SOC_H_
  8. #include <linux/soc/qcom/llcc-qcom.h>
  9. #include "cam_soc_util.h"
  10. #include "cam_cpas_hw.h"
  11. #define CAM_REGULATOR_LEVEL_MAX 16
  12. #define CAM_CPAS_MAX_TREE_NODES 63
  13. #define CAM_CPAS_MAX_FUSE_FEATURE 10
  14. /**
  15. * enum cam_cpas_num_subparts_types - Enum for types of number of camera subparts
  16. */
  17. enum cam_cpas_num_subparts_types {
  18. CAM_CPAS_AVAILABLE_NUM_SUBPARTS,
  19. CAM_CPAS_FUNCTIONAL_NUM_SUBPARTS,
  20. CAM_CPAS_NUM_SUBPARTS_MAX_TYPES,
  21. };
  22. /**
  23. * struct cpas_tree_node: Generic cpas tree node for BW voting
  24. *
  25. * @cell_idx: Index to identify node from device tree and its parent
  26. * @level_idx: Index to identify at what level the node is present
  27. * @axi_port_idx_arr: Index to identify which axi port to vote the consolidated bw.
  28. * It can point to multiple indexes in case of camera DRV
  29. * @drv_voting_idx: Specifies the index to which the child node would finally vote.
  30. * @camnoc_axi_port_idx: Index to find which axi port to vote consolidated bw
  31. * @path_data_type: Traffic type info from device tree (ife-vid, ife-disp etc)
  32. * @path_trans_type: Transaction type info from device tree (rd, wr)
  33. * @merge_type: Traffic merge type (calculation info) from device tree
  34. * @bus_width_factor: Factor for accounting bus width in CAMNOC bw calculation
  35. * @bw_info: AXI BW info for all drv ports
  36. * @camnoc_max_needed: If node is needed for CAMNOC BW calculation then true
  37. * @constituent_paths: Constituent paths presence info from device tree
  38. * Ex: For CAM_CPAS_PATH_DATA_IFE_UBWC_STATS, index corresponding to
  39. * CAM_CPAS_PATH_DATA_IFE_VID, CAM_CPAS_PATH_DATA_IFE_DISP and
  40. * CAM_CPAS_PATH_DATA_IFE_STATS
  41. * @tree_dev_node: Device node from devicetree for current tree node
  42. * @parent_node: Pointer to node one or more level above the current level
  43. * (starting from end node of cpas client)
  44. * @pri_lut_low_offset: Register offset value for priority lut low.
  45. * Valid only for level1 nodes (representing NIUs)
  46. * @pri_lut_high_offset: Register offset value for priority lut high.
  47. * Valid only for level1 nodes (representing NIUs)
  48. * @niu_size: Size of NIU that this node represents. Size in KB
  49. * @curr_priority_low: New calculated priority lut low values
  50. * @curr_priority_high: New calculated priority lut high values
  51. * @applied_priority_low: Currently applied priority lut low values
  52. * @applied_priority_high: Currently applied priority lut high values
  53. *
  54. */
  55. struct cam_cpas_tree_node {
  56. uint32_t cell_idx;
  57. int level_idx;
  58. int *axi_port_idx_arr;
  59. int drv_voting_idx;
  60. int camnoc_axi_port_idx;
  61. const char *node_name;
  62. uint32_t path_data_type;
  63. uint32_t path_trans_type;
  64. uint32_t merge_type;
  65. uint32_t bus_width_factor;
  66. struct cam_cpas_axi_bw_info *bw_info;
  67. bool camnoc_max_needed;
  68. bool constituent_paths[CAM_CPAS_PATH_DATA_MAX];
  69. struct device_node *tree_dev_node;
  70. struct cam_cpas_tree_node *parent_node;
  71. uint32_t pri_lut_low_offset;
  72. uint32_t pri_lut_high_offset;
  73. uint32_t niu_size;
  74. uint32_t curr_priority_low;
  75. uint32_t curr_priority_high;
  76. uint32_t applied_priority_low;
  77. uint32_t applied_priority_high;
  78. };
  79. /**
  80. * struct cam_cpas_feature_info : CPAS fuse feature info
  81. * @feature: Identifier for feature
  82. * @type: Type of feature
  83. * @value: Fuse value
  84. * @enable: Feature enable or disable
  85. * @hw_map: Each bit position indicates if the hw_id for the feature
  86. */
  87. struct cam_cpas_feature_info {
  88. uint32_t feature;
  89. uint32_t type;
  90. uint32_t value;
  91. bool enable;
  92. uint32_t hw_map;
  93. };
  94. /**
  95. * struct cam_sys_cache_local_info : camera cache info saving locally
  96. *
  97. * @type: cache type small/large etc.
  98. * @staling_distance: staling_distance
  99. * @mode: camera llc's stalling mode
  100. * @op_type: cache operation type EVICT, FORGET
  101. */
  102. struct cam_sys_cache_local_info {
  103. enum cam_sys_cache_config_types type;
  104. uint32_t staling_distance;
  105. enum cam_sys_cache_llcc_staling_mode mode;
  106. enum cam_sys_cache_llcc_staling_op_type op_type;
  107. };
  108. /**
  109. * struct cam_sys_cache_info : Last level camera cache info
  110. *
  111. * @ref_cnt: Ref cnt activate/deactivate cache
  112. * @type: cache type small/large etc.
  113. * @uid: Client user ID
  114. * @size: Cache size
  115. * @scid: Slice ID
  116. * @slic_desc: Slice descriptor
  117. * @staling_distance: staling_distance
  118. * @mode: camera llc's stalling mode
  119. * @op_type: cache operation type EVICT, FORGET
  120. */
  121. struct cam_sys_cache_info {
  122. uint32_t ref_cnt;
  123. enum cam_sys_cache_config_types type;
  124. uint32_t uid;
  125. size_t size;
  126. int32_t scid;
  127. const char *name;
  128. struct llcc_slice_desc *slic_desc;
  129. uint32_t staling_distance;
  130. enum cam_sys_cache_llcc_staling_mode mode;
  131. enum cam_sys_cache_llcc_staling_op_type op_type;
  132. };
  133. /**
  134. * struct cam_cpas_smart_qos_info : Smart QOS info
  135. *
  136. * @rt_wr_priority_min: Minimum priority value for rt write nius
  137. * @rt_wr_priority_max: Maximum priority value for rt write nius
  138. * @rt_wr_priority_clamp: Clamp priority value for rt write nius
  139. * @rt_wr_slope_factor: Slope factor value for rt write nius
  140. * @leaststressed_clamp_th: Leaststressed clamp threshold value for rt write nius
  141. * @moststressed_clamp_th: Moststressed clamp threshold value for rt write nius
  142. * @highstress_indicator_th: Highstress indicator threshold value for rt write nius
  143. * @lowstress_indicator_th: Lowstress indicator threshold value for rt write nius
  144. * @bw_ratio_scale_factor: BW ratio scale factor value for rt write nius
  145. * @num_rt_wr_nius: Number of rt write nius
  146. * @rt_wr_niu_node: List of level1 nodes representing rt write nius
  147. */
  148. struct cam_cpas_smart_qos_info {
  149. uint8_t rt_wr_priority_min;
  150. uint8_t rt_wr_priority_max;
  151. uint8_t rt_wr_priority_clamp;
  152. uint8_t rt_wr_slope_factor;
  153. uint8_t leaststressed_clamp_th;
  154. uint8_t moststressed_clamp_th;
  155. uint8_t highstress_indicator_th;
  156. uint8_t lowstress_indicator_th;
  157. uint8_t bw_ratio_scale_factor;
  158. uint8_t num_rt_wr_nius;
  159. struct cam_cpas_tree_node *rt_wr_niu_node[CAM_CPAS_MAX_RT_WR_NIU_NODES];
  160. };
  161. /**
  162. * struct cam_cpas_domain_id_mapping : Domain id mapping
  163. *
  164. * @domain_type: Domain type, currently defined as two,
  165. * secure/non-secure. This will be expanded
  166. * later to more types, and correspnding ID
  167. * @mapping_id: ID of domain type
  168. */
  169. struct cam_cpas_domain_id_mapping {
  170. uint32_t domain_type;
  171. uint32_t mapping_id;
  172. };
  173. /**
  174. * struct cam_cpas_domain_id_info : Stores all information related
  175. * to domain-id support
  176. * @domain_id_entries: Stores mapping between domain types and their IDs
  177. * @num_domain_ids: Num of domain id types found from dtsi
  178. * @domain_id_supported: Whether domain id is supported
  179. */
  180. struct cam_cpas_domain_id_info {
  181. struct cam_cpas_domain_id_mapping *domain_id_entries;
  182. uint32_t num_domain_ids;
  183. bool domain_id_supported;
  184. };
  185. /**
  186. * struct cam_cpas_domain_id_support_clks : Stores all information
  187. * related to clocks
  188. * needed to turn on SWIs
  189. * for domain id programming
  190. * @clk_names: Clock names as declared in DT
  191. * @clk_idx: Corresponding clk index as declared in DT
  192. * @number_clks: Number of clocks declared to turn all CSIDs
  193. */
  194. struct cam_cpas_domain_id_support_clks {
  195. const char *clk_names[CAM_SOC_MAX_OPT_CLK];
  196. int32_t clk_idx[CAM_SOC_MAX_OPT_CLK];
  197. int number_clks;
  198. };
  199. /**
  200. * struct cam_cpas_soc_irq_data: irq data to be passed in irq handler from ISR
  201. *
  202. * @cpas_hw: cpas hw info
  203. * @camnoc_type: type of camnoc associated with the irq
  204. *
  205. */
  206. struct cam_cpas_soc_irq_data {
  207. struct cam_hw_info *cpas_hw;
  208. enum cam_camnoc_hw_type camnoc_type;
  209. };
  210. /**
  211. * struct cam_cpas_sysfs_info - cpas sysfs info
  212. *
  213. * @kobj: Kobj for camera directory
  214. * @num_ifes: Number of available and functional IFEs
  215. * @num_ife_lites: Number of available and functional IFE-LITEs
  216. * @num_sfes: Number of available and functional SFEs
  217. * @num_custom: Number of available and functional CUSTOM
  218. */
  219. struct cam_cpas_sysfs_info {
  220. struct kobject *kobj;
  221. uint32_t num_ifes[CAM_CPAS_NUM_SUBPARTS_MAX_TYPES];
  222. uint32_t num_ife_lites[CAM_CPAS_NUM_SUBPARTS_MAX_TYPES];
  223. uint32_t num_sfes[CAM_CPAS_NUM_SUBPARTS_MAX_TYPES];
  224. uint32_t num_custom[CAM_CPAS_NUM_SUBPARTS_MAX_TYPES];
  225. };
  226. /**
  227. * struct cam_cpas_private_soc : CPAS private DT info
  228. *
  229. * @arch_compat: ARCH compatible string
  230. * @client_id_based: Whether clients are id based
  231. * @bus_icc_based: Interconnect based bus interaction
  232. * @num_clients: Number of clients supported
  233. * @client_name: Client names
  234. * @tree_node: Array of pointers to all tree nodes required to calculate
  235. * axi bw, arranged with help of cell index in device tree
  236. * @camera_bus_node: Device tree node from cpas node
  237. * @level_node: Device tree node for each level in camera_bus_node
  238. * @num_vdd_ahb_mapping : Number of vdd to ahb level mapping supported
  239. * @vdd_ahb : AHB level mapping info for the supported vdd levels
  240. * @control_camnoc_axi_clk : Whether CPAS driver need to set camnoc axi clk freq
  241. * @camnoc_bus_width : CAMNOC Bus width
  242. * @camnoc_axi_clk_bw_margin : BW Margin in percentage to add while calculating
  243. * camnoc axi clock
  244. * @camnoc_axi_min_ib_bw: Min camnoc BW which varies based on target
  245. * @fuse_info: fuse information
  246. * @sysfs_info: Camera subparts sysfs information
  247. * @rpmh_info: RPMH BCM info
  248. * @num_feature_info: number of feature_info entries
  249. * @feature_info: Structure for storing feature information
  250. * @num_caches: Number of last level caches
  251. * @part_info: Camera Hw subpart info
  252. * @llcc_info: Cache info
  253. * @enable_secure_qos_update: whether to program QoS securely on current chipset
  254. * @enable_smart_qos: Whether to enable Smart QoS mechanism on current chipset
  255. * @enable_cam_ddr_drv: Whether to enable Camera DDR DRV on current chipset
  256. * @enable_cam_clk_drv: Whether to enable Camera Clk DRV on current chipset
  257. * @smart_qos_info: Pointer to smart qos info
  258. * @icp_clk_index: Index of optional icp clk
  259. * @domain_id_info: Stores all information related to domain id support
  260. * @domain_id_clks: All clock related information for domain id support
  261. * @irq_data: array of data for each irq line to be passed in irq handler
  262. */
  263. struct cam_cpas_private_soc {
  264. const char *arch_compat;
  265. bool client_id_based;
  266. bool bus_icc_based;
  267. uint32_t num_clients;
  268. const char *client_name[CAM_CPAS_MAX_CLIENTS];
  269. struct cam_cpas_tree_node *tree_node[CAM_CPAS_MAX_TREE_NODES];
  270. struct device_node *camera_bus_node;
  271. struct device_node *level_node[CAM_CPAS_MAX_TREE_LEVELS];
  272. uint32_t num_vdd_ahb_mapping;
  273. struct cam_cpas_vdd_ahb_mapping vdd_ahb[CAM_REGULATOR_LEVEL_MAX];
  274. bool control_camnoc_axi_clk;
  275. uint32_t camnoc_bus_width;
  276. uint32_t camnoc_axi_clk_bw_margin;
  277. uint64_t camnoc_axi_min_ib_bw;
  278. struct cam_cpas_fuse_info fuse_info;
  279. struct cam_cpas_sysfs_info sysfs_info;
  280. uint32_t rpmh_info[CAM_RPMH_BCM_INFO_MAX];
  281. uint32_t num_feature_info;
  282. struct cam_cpas_feature_info feature_info[CAM_CPAS_MAX_FUSE_FEATURE];
  283. uint32_t num_caches;
  284. uint32_t part_info;
  285. struct cam_sys_cache_info *llcc_info;
  286. bool enable_smart_qos;
  287. bool enable_cam_ddr_drv;
  288. bool enable_cam_clk_drv;
  289. bool enable_secure_qos_update;
  290. struct cam_cpas_smart_qos_info *smart_qos_info;
  291. int32_t icp_clk_index;
  292. struct cam_cpas_domain_id_info domain_id_info;
  293. struct cam_cpas_domain_id_support_clks *domain_id_clks;
  294. struct cam_cpas_soc_irq_data *irq_data;
  295. };
  296. void cam_cpas_dump_tree_vote_info(struct cam_hw_info *cpas_hw,
  297. const struct cam_cpas_tree_node *tree_node,
  298. const char *identifier, int ddr_drv_idx, int cesta_drv_idx);
  299. void cam_cpas_dump_full_tree_state(struct cam_hw_info *cpas_hw, const char *identifier);
  300. void cam_cpas_util_debug_parse_data(struct cam_cpas_private_soc *soc_private);
  301. void cam_cpas_dump_axi_vote_info(
  302. const struct cam_cpas_client *cpas_client,
  303. const char *identifier,
  304. struct cam_axi_vote *axi_vote);
  305. int cam_cpas_node_tree_cleanup(struct cam_cpas *cpas_core,
  306. struct cam_cpas_private_soc *soc_private);
  307. int cam_cpas_soc_init_resources(struct cam_hw_soc_info *soc_info,
  308. irq_handler_t vfe_irq_handler, struct cam_hw_info *cpas_hw);
  309. int cam_cpas_soc_deinit_resources(struct cam_hw_soc_info *soc_info);
  310. int cam_cpas_soc_enable_resources(struct cam_hw_soc_info *soc_info,
  311. enum cam_vote_level default_level);
  312. int cam_cpas_soc_disable_resources(struct cam_hw_soc_info *soc_info,
  313. bool disable_clocks, bool disable_irq);
  314. int cam_cpas_soc_disable_irq(struct cam_hw_soc_info *soc_info);
  315. #endif /* _CAM_CPAS_SOC_H_ */