cam_cpas_hw.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _CAM_CPAS_HW_H_
  6. #define _CAM_CPAS_HW_H_
  7. #include <dt-bindings/msm/msm-camera.h>
  8. #include "cam_cpas_api.h"
  9. #include "cam_cpas_hw_intf.h"
  10. #include "cam_common_util.h"
  11. #include "cam_soc_bus.h"
  12. #define CAM_CPAS_INFLIGHT_WORKS 5
  13. #define CAM_CPAS_MAX_CLIENTS 40
  14. #define CAM_CPAS_MAX_AXI_PORTS 6
  15. #define CAM_CPAS_MAX_TREE_LEVELS 4
  16. #define CAM_CPAS_MAX_GRAN_PATHS_PER_CLIENT 32
  17. #define CAM_CPAS_PATH_DATA_MAX 38
  18. #define CAM_CPAS_TRANSACTION_MAX 2
  19. #define CAM_CPAS_AXI_MIN_MNOC_AB_BW (2048 * 1024)
  20. #define CAM_CPAS_AXI_MIN_MNOC_IB_BW (2048 * 1024)
  21. #define CAM_CPAS_AXI_MIN_CAMNOC_AB_BW (2048 * 1024)
  22. #define CAM_CPAS_AXI_MIN_CAMNOC_IB_BW (3000000000UL)
  23. #define CAM_CPAS_GET_CLIENT_IDX(handle) (handle)
  24. #define CAM_CPAS_GET_CLIENT_HANDLE(indx) (indx)
  25. #define CAM_CPAS_CLIENT_VALID(indx) \
  26. ((indx >= 0) && (indx < CAM_CPAS_MAX_CLIENTS))
  27. #define CAM_CPAS_CLIENT_REGISTERED(cpas_core, indx) \
  28. ((CAM_CPAS_CLIENT_VALID(indx)) && \
  29. (cpas_core->cpas_client[indx]->registered))
  30. #define CAM_CPAS_CLIENT_STARTED(cpas_core, indx) \
  31. ((CAM_CPAS_CLIENT_REGISTERED(cpas_core, indx)) && \
  32. (cpas_core->cpas_client[indx]->started))
  33. /**
  34. * enum cam_cpas_access_type - Enum for Register access type
  35. */
  36. enum cam_cpas_access_type {
  37. CAM_REG_TYPE_READ,
  38. CAM_REG_TYPE_WRITE,
  39. CAM_REG_TYPE_READ_WRITE,
  40. };
  41. /**
  42. * struct cam_cpas_internal_ops - CPAS Hardware layer internal ops
  43. *
  44. * @get_hw_info: Function pointer for get hw info
  45. * @init_hw_version: Function pointer for hw init based on version
  46. * @handle_irq: Function poniter for irq handling
  47. * @setup_regbase: Function pointer for setup rebase indices
  48. * @power_on: Function pointer for hw core specific power on settings
  49. * @power_off: Function pointer for hw core specific power off settings
  50. * @setup_qos_settings: Function pointer for hw to select a specific qos header
  51. *
  52. */
  53. struct cam_cpas_internal_ops {
  54. int (*get_hw_info)(struct cam_hw_info *cpas_hw,
  55. struct cam_cpas_hw_caps *hw_caps);
  56. int (*init_hw_version)(struct cam_hw_info *cpas_hw,
  57. struct cam_cpas_hw_caps *hw_caps);
  58. irqreturn_t (*handle_irq)(int irq_num, void *data);
  59. int (*setup_regbase)(struct cam_hw_soc_info *soc_info,
  60. int32_t regbase_index[], int32_t num_reg_map);
  61. int (*power_on)(struct cam_hw_info *cpas_hw);
  62. int (*power_off)(struct cam_hw_info *cpas_hw);
  63. int (*setup_qos_settings)(struct cam_hw_info *cpas_hw,
  64. uint32_t selection_mask);
  65. };
  66. /**
  67. * struct cam_cpas_reg : CPAS register info
  68. *
  69. * @enable: Whether this reg info need to be enabled
  70. * @access_type: Register access type
  71. * @masked_value: Whether this register write/read is based on mask, shift
  72. * @mask: Mask for this register value
  73. * @shift: Shift for this register value
  74. * @value: Register value
  75. *
  76. */
  77. struct cam_cpas_reg {
  78. bool enable;
  79. enum cam_cpas_access_type access_type;
  80. bool masked_value;
  81. uint32_t offset;
  82. uint32_t mask;
  83. uint32_t shift;
  84. uint32_t value;
  85. };
  86. /**
  87. * struct cam_cpas_client : CPAS Client structure info
  88. *
  89. * @data: Client register params
  90. * @registered: Whether client has registered with cpas
  91. * @started: Whether client has streamed on
  92. * @tree_node_valid: Indicates whether tree node has at least one valid node
  93. * @ahb_level: Determined/Applied ahb level for the client
  94. * @axi_vote: Determined/Applied axi vote for the client
  95. * @axi_port: Client's parent axi port
  96. * @tree_node: All granular path voting nodes for the client
  97. *
  98. */
  99. struct cam_cpas_client {
  100. struct cam_cpas_register_params data;
  101. bool registered;
  102. bool started;
  103. bool tree_node_valid;
  104. enum cam_vote_level ahb_level;
  105. struct cam_axi_vote axi_vote;
  106. struct cam_cpas_axi_port *axi_port;
  107. struct cam_cpas_tree_node *tree_node[CAM_CPAS_PATH_DATA_MAX]
  108. [CAM_CPAS_TRANSACTION_MAX];
  109. };
  110. /**
  111. * struct cam_cpas_bus_client : Bus client information
  112. *
  113. * @valid: Whether bus client is valid
  114. * @name: Name of the bus client
  115. * @lock: Mutex lock used while voting on this client
  116. * @curr_vote_level: current voted index
  117. * @common_data: Common data fields for bus client
  118. * @soc_bus_client: Bus client private information
  119. */
  120. struct cam_cpas_bus_client {
  121. bool valid;
  122. struct mutex lock;
  123. unsigned int curr_vote_level;
  124. struct cam_soc_bus_client_common_data common_data;
  125. void *soc_bus_client;
  126. };
  127. /**
  128. * struct cam_cpas_axi_port : AXI port information
  129. *
  130. * @axi_port_name: Name of this AXI port
  131. * @bus_client: bus client info for this port
  132. * @ib_bw_voting_needed: if this port can update ib bw dynamically
  133. * @axi_port_node: Node representing AXI Port info in device tree
  134. * @ab_bw: AB bw value for this port
  135. * @ib_bw: IB bw value for this port
  136. * @camnoc_bw: CAMNOC bw value for this port
  137. * @additional_bw: Additional bandwidth to cover non-hw cpas clients
  138. * @applied_ab_bw: applied ab bw for this port
  139. * @applied_ib_bw: applied ib bw for this port
  140. */
  141. struct cam_cpas_axi_port {
  142. const char *axi_port_name;
  143. struct cam_cpas_bus_client bus_client;
  144. bool ib_bw_voting_needed;
  145. struct device_node *axi_port_node;
  146. uint64_t ab_bw;
  147. uint64_t ib_bw;
  148. uint64_t camnoc_bw;
  149. uint64_t additional_bw;
  150. uint64_t applied_ab_bw;
  151. uint64_t applied_ib_bw;
  152. };
  153. /**
  154. * struct cam_cpas : CPAS core data structure info
  155. *
  156. * @hw_caps: CPAS hw capabilities
  157. * @cpas_client: Array of pointers to CPAS clients info
  158. * @client_mutex: Mutex for accessing client info
  159. * @tree_lock: Mutex lock for accessing CPAS node tree
  160. * @num_clients: Total number of clients that CPAS supports
  161. * @num_axi_ports: Total number of axi ports found in device tree
  162. * @num_camnoc_axi_ports: Total number of camnoc axi ports found in device tree
  163. * @registered_clients: Number of Clients registered currently
  164. * @streamon_clients: Number of Clients that are in start state currently
  165. * @regbase_index: Register base indices for CPAS register base IDs
  166. * @ahb_bus_client: AHB Bus client info
  167. * @axi_port: AXI port info for a specific axi index
  168. * @camnoc_axi_port: CAMNOC AXI port info for a specific camnoc axi index
  169. * @internal_ops: CPAS HW internal ops
  170. * @work_queue: Work queue handle
  171. * @irq_count: atomic irq count
  172. * @irq_count_wq: wait variable to ensure all irq's are handled
  173. * @dentry: debugfs file entry
  174. * @ahb_bus_scaling_disable: ahb scaling based on src clk corner for bus
  175. * @applied_camnoc_axi_rate: applied camnoc axi clock rate
  176. */
  177. struct cam_cpas {
  178. struct cam_cpas_hw_caps hw_caps;
  179. struct cam_cpas_client *cpas_client[CAM_CPAS_MAX_CLIENTS];
  180. struct mutex client_mutex[CAM_CPAS_MAX_CLIENTS];
  181. struct mutex tree_lock;
  182. uint32_t num_clients;
  183. uint32_t num_axi_ports;
  184. uint32_t num_camnoc_axi_ports;
  185. uint32_t registered_clients;
  186. uint32_t streamon_clients;
  187. int32_t regbase_index[CAM_CPAS_REG_MAX];
  188. struct cam_cpas_bus_client ahb_bus_client;
  189. struct cam_cpas_axi_port axi_port[CAM_CPAS_MAX_AXI_PORTS];
  190. struct cam_cpas_axi_port camnoc_axi_port[CAM_CPAS_MAX_AXI_PORTS];
  191. struct cam_cpas_internal_ops internal_ops;
  192. struct workqueue_struct *work_queue;
  193. atomic_t irq_count;
  194. wait_queue_head_t irq_count_wq;
  195. struct dentry *dentry;
  196. bool ahb_bus_scaling_disable;
  197. uint64_t applied_camnoc_axi_rate;
  198. };
  199. int cam_camsstop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  200. int cam_cpastop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  201. int cam_cpas_util_reg_update(struct cam_hw_info *cpas_hw,
  202. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info);
  203. int cam_cpas_util_client_cleanup(struct cam_hw_info *cpas_hw);
  204. #endif /* _CAM_CPAS_HW_H_ */