cam_cpas_hw.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2017-2019, 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. *
  51. */
  52. struct cam_cpas_internal_ops {
  53. int (*get_hw_info)(struct cam_hw_info *cpas_hw,
  54. struct cam_cpas_hw_caps *hw_caps);
  55. int (*init_hw_version)(struct cam_hw_info *cpas_hw,
  56. struct cam_cpas_hw_caps *hw_caps);
  57. irqreturn_t (*handle_irq)(int irq_num, void *data);
  58. int (*setup_regbase)(struct cam_hw_soc_info *soc_info,
  59. int32_t regbase_index[], int32_t num_reg_map);
  60. int (*power_on)(struct cam_hw_info *cpas_hw);
  61. int (*power_off)(struct cam_hw_info *cpas_hw);
  62. };
  63. /**
  64. * struct cam_cpas_reg : CPAS register info
  65. *
  66. * @enable: Whether this reg info need to be enabled
  67. * @access_type: Register access type
  68. * @masked_value: Whether this register write/read is based on mask, shift
  69. * @mask: Mask for this register value
  70. * @shift: Shift for this register value
  71. * @value: Register value
  72. *
  73. */
  74. struct cam_cpas_reg {
  75. bool enable;
  76. enum cam_cpas_access_type access_type;
  77. bool masked_value;
  78. uint32_t offset;
  79. uint32_t mask;
  80. uint32_t shift;
  81. uint32_t value;
  82. };
  83. /**
  84. * struct cam_cpas_client : CPAS Client structure info
  85. *
  86. * @data: Client register params
  87. * @registered: Whether client has registered with cpas
  88. * @started: Whether client has streamed on
  89. * @tree_node_valid: Indicates whether tree node has at least one valid node
  90. * @ahb_level: Determined/Applied ahb level for the client
  91. * @axi_vote: Determined/Applied axi vote for the client
  92. * @axi_port: Client's parent axi port
  93. * @tree_node: All granular path voting nodes for the client
  94. *
  95. */
  96. struct cam_cpas_client {
  97. struct cam_cpas_register_params data;
  98. bool registered;
  99. bool started;
  100. bool tree_node_valid;
  101. enum cam_vote_level ahb_level;
  102. struct cam_axi_vote axi_vote;
  103. struct cam_cpas_axi_port *axi_port;
  104. struct cam_cpas_tree_node *tree_node[CAM_CPAS_PATH_DATA_MAX]
  105. [CAM_CPAS_TRANSACTION_MAX];
  106. };
  107. /**
  108. * struct cam_cpas_bus_client : Bus client information
  109. *
  110. * @valid: Whether bus client is valid
  111. * @name: Name of the bus client
  112. * @lock: Mutex lock used while voting on this client
  113. * @curr_vote_level: current voted index
  114. * @common_data: Common data fields for bus client
  115. * @soc_bus_client: Bus client private information
  116. */
  117. struct cam_cpas_bus_client {
  118. bool valid;
  119. struct mutex lock;
  120. unsigned int curr_vote_level;
  121. struct cam_soc_bus_client_common_data common_data;
  122. void *soc_bus_client;
  123. };
  124. /**
  125. * struct cam_cpas_axi_port : AXI port information
  126. *
  127. * @bus_client: bus client info for this port
  128. * @ib_bw_voting_needed: if this port can update ib bw dynamically
  129. * @axi_port_node: Node representing AXI Port info in device tree
  130. * @ab_bw: AB bw value for this port
  131. * @ib_bw: IB bw value for this port
  132. * @additional_bw: Additional bandwidth to cover non-hw cpas clients
  133. */
  134. struct cam_cpas_axi_port {
  135. struct cam_cpas_bus_client bus_client;
  136. bool ib_bw_voting_needed;
  137. struct device_node *axi_port_node;
  138. uint64_t ab_bw;
  139. uint64_t ib_bw;
  140. uint64_t additional_bw;
  141. };
  142. /**
  143. * struct cam_cpas : CPAS core data structure info
  144. *
  145. * @hw_caps: CPAS hw capabilities
  146. * @cpas_client: Array of pointers to CPAS clients info
  147. * @client_mutex: Mutex for accessing client info
  148. * @tree_lock: Mutex lock for accessing CPAS node tree
  149. * @num_clients: Total number of clients that CPAS supports
  150. * @num_axi_ports: Total number of axi ports found in device tree
  151. * @registered_clients: Number of Clients registered currently
  152. * @streamon_clients: Number of Clients that are in start state currently
  153. * @regbase_index: Register base indices for CPAS register base IDs
  154. * @ahb_bus_client: AHB Bus client info
  155. * @axi_port: AXI port info for a specific axi index
  156. * @internal_ops: CPAS HW internal ops
  157. * @work_queue: Work queue handle
  158. * @irq_count: atomic irq count
  159. * @irq_count_wq: wait variable to ensure all irq's are handled
  160. * @dentry: debugfs file entry
  161. * @ahb_bus_scaling_disable: ahb scaling based on src clk corner for bus
  162. */
  163. struct cam_cpas {
  164. struct cam_cpas_hw_caps hw_caps;
  165. struct cam_cpas_client *cpas_client[CAM_CPAS_MAX_CLIENTS];
  166. struct mutex client_mutex[CAM_CPAS_MAX_CLIENTS];
  167. struct mutex tree_lock;
  168. uint32_t num_clients;
  169. uint32_t num_axi_ports;
  170. uint32_t registered_clients;
  171. uint32_t streamon_clients;
  172. int32_t regbase_index[CAM_CPAS_REG_MAX];
  173. struct cam_cpas_bus_client ahb_bus_client;
  174. struct cam_cpas_axi_port axi_port[CAM_CPAS_MAX_AXI_PORTS];
  175. struct cam_cpas_internal_ops internal_ops;
  176. struct workqueue_struct *work_queue;
  177. atomic_t irq_count;
  178. wait_queue_head_t irq_count_wq;
  179. struct dentry *dentry;
  180. bool ahb_bus_scaling_disable;
  181. };
  182. int cam_camsstop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  183. int cam_cpastop_get_internal_ops(struct cam_cpas_internal_ops *internal_ops);
  184. int cam_cpas_util_reg_update(struct cam_hw_info *cpas_hw,
  185. enum cam_cpas_reg_base reg_base, struct cam_cpas_reg *reg_info);
  186. int cam_cpas_util_client_cleanup(struct cam_hw_info *cpas_hw);
  187. #endif /* _CAM_CPAS_HW_H_ */