Pavan Kumar Chilamkurthi | 5719f21 | 2017-07-20 15:02:21 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef _CAM_FD_HW_CORE_H_ |
| 14 | #define _CAM_FD_HW_CORE_H_ |
| 15 | |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <media/cam_defs.h> |
| 20 | #include <media/cam_fd.h> |
| 21 | |
| 22 | #include "cam_common_util.h" |
| 23 | #include "cam_debug_util.h" |
| 24 | #include "cam_io_util.h" |
| 25 | #include "cam_cpas_api.h" |
| 26 | #include "cam_cdm_intf_api.h" |
| 27 | #include "cam_fd_hw_intf.h" |
| 28 | #include "cam_fd_hw_soc.h" |
| 29 | |
| 30 | #define CAM_FD_IRQ_TO_MASK(irq) (1 << (irq)) |
| 31 | #define CAM_FD_MASK_TO_IRQ(mask, irq) ((mask) >> (irq)) |
| 32 | |
| 33 | #define CAM_FD_HW_HALT_RESET_TIMEOUT 3000 |
| 34 | |
| 35 | /** |
| 36 | * enum cam_fd_core_state - FD Core internal states |
| 37 | * |
| 38 | * @CAM_FD_CORE_STATE_POWERDOWN : Indicates FD core is powered down |
| 39 | * @CAM_FD_CORE_STATE_IDLE : Indicates FD HW is in idle state. |
| 40 | * Core can be in this state when it is |
| 41 | * ready to process frames or when |
| 42 | * processing is finished and results are |
| 43 | * available |
| 44 | * @CAM_FD_CORE_STATE_PROCESSING : Indicates FD core is processing frame |
| 45 | * @CAM_FD_CORE_STATE_READING_RESULTS : Indicates results are being read from |
| 46 | * FD core |
| 47 | * @CAM_FD_CORE_STATE_RESET_PROGRESS : Indicates FD Core is in reset state |
| 48 | */ |
| 49 | enum cam_fd_core_state { |
| 50 | CAM_FD_CORE_STATE_POWERDOWN, |
| 51 | CAM_FD_CORE_STATE_IDLE, |
| 52 | CAM_FD_CORE_STATE_PROCESSING, |
| 53 | CAM_FD_CORE_STATE_READING_RESULTS, |
| 54 | CAM_FD_CORE_STATE_RESET_PROGRESS, |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * struct cam_fd_ctx_hw_private : HW private information for a specific hw ctx. |
| 59 | * This information is populated by HW layer on |
| 60 | * reserve() and given back to HW Mgr as private |
| 61 | * data for the hw context. This private_data |
| 62 | * has to be passed by HW Mgr layer while |
| 63 | * further HW layer calls |
| 64 | * |
| 65 | * @hw_ctx : Corresponding hw_ctx pointer |
| 66 | * @fd_hw : FD HW info pointer |
| 67 | * @cdm_handle : CDM Handle for this context |
| 68 | * @cdm_ops : CDM Ops |
| 69 | * @cdm_cmd : CDM command pointer |
| 70 | * @mode : Mode this context is running |
| 71 | * @curr_req_private : Current Request information |
| 72 | * |
| 73 | */ |
| 74 | struct cam_fd_ctx_hw_private { |
| 75 | void *hw_ctx; |
| 76 | struct cam_hw_info *fd_hw; |
| 77 | uint32_t cdm_handle; |
| 78 | struct cam_cdm_utils_ops *cdm_ops; |
| 79 | struct cam_cdm_bl_request *cdm_cmd; |
| 80 | enum cam_fd_hw_mode mode; |
| 81 | struct cam_fd_hw_req_private *curr_req_private; |
| 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * struct cam_fd_core_regs : FD HW Core register offsets info |
| 86 | * |
| 87 | * @version : Offset of version register |
| 88 | * @control : Offset of control register |
| 89 | * @result_cnt : Offset of result count register |
| 90 | * @result_addr : Offset of results address register |
| 91 | * @image_addr : Offset of image address register |
| 92 | * @work_addr : Offset of work address register |
| 93 | * @ro_mode : Offset of ro_mode register |
| 94 | * @results_reg_base : Offset of results_reg_base register |
| 95 | * @raw_results_reg_base : Offset of raw_results_reg_base register |
| 96 | * |
| 97 | */ |
| 98 | struct cam_fd_core_regs { |
| 99 | uint32_t version; |
| 100 | uint32_t control; |
| 101 | uint32_t result_cnt; |
| 102 | uint32_t result_addr; |
| 103 | uint32_t image_addr; |
| 104 | uint32_t work_addr; |
| 105 | uint32_t ro_mode; |
| 106 | uint32_t results_reg_base; |
| 107 | uint32_t raw_results_reg_base; |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * struct cam_fd_core_regs : FD HW Wrapper register offsets info |
| 112 | * |
| 113 | * @wrapper_version : Offset of wrapper_version register |
| 114 | * @cgc_disable : Offset of cgc_disable register |
| 115 | * @hw_stop : Offset of hw_stop register |
| 116 | * @sw_reset : Offset of sw_reset register |
| 117 | * @vbif_req_priority : Offset of vbif_req_priority register |
| 118 | * @vbif_priority_level : Offset of vbif_priority_level register |
| 119 | * @vbif_done_status : Offset of vbif_done_status register |
| 120 | * @irq_mask : Offset of irq mask register |
| 121 | * @irq_status : Offset of irq status register |
| 122 | * @irq_clear : Offset of irq clear register |
| 123 | * |
| 124 | */ |
| 125 | struct cam_fd_wrapper_regs { |
| 126 | uint32_t wrapper_version; |
| 127 | uint32_t cgc_disable; |
| 128 | uint32_t hw_stop; |
| 129 | uint32_t sw_reset; |
| 130 | uint32_t vbif_req_priority; |
| 131 | uint32_t vbif_priority_level; |
| 132 | uint32_t vbif_done_status; |
| 133 | uint32_t irq_mask; |
| 134 | uint32_t irq_status; |
| 135 | uint32_t irq_clear; |
| 136 | }; |
| 137 | |
| 138 | /** |
| 139 | * struct cam_fd_hw_errata_wa : FD HW Errata workaround enable/dsiable info |
| 140 | * |
| 141 | * @single_irq_only : Whether to enable only one irq at any time |
| 142 | * @ro_mode_enable_always : Whether to enable ro mode always |
| 143 | * @ro_mode_results_invalid : Whether results written directly into output |
| 144 | * memory by HW are valid or not |
| 145 | */ |
| 146 | struct cam_fd_hw_errata_wa { |
| 147 | bool single_irq_only; |
| 148 | bool ro_mode_enable_always; |
| 149 | bool ro_mode_results_invalid; |
| 150 | }; |
| 151 | |
| 152 | /** |
| 153 | * struct cam_fd_hw_results_prop : FD HW Results properties |
| 154 | * |
| 155 | * @max_faces : Maximum number of faces supported |
| 156 | * @per_face_entries : Number of register with properties for each face |
| 157 | * @raw_results_entries : Number of raw results entries for the full search |
| 158 | * @raw_results_available : Whether raw results available on this HW |
| 159 | * |
| 160 | */ |
| 161 | struct cam_fd_hw_results_prop { |
| 162 | uint32_t max_faces; |
| 163 | uint32_t per_face_entries; |
| 164 | uint32_t raw_results_entries; |
| 165 | bool raw_results_available; |
| 166 | }; |
| 167 | |
| 168 | /** |
| 169 | * struct cam_fd_hw_static_info : FD HW information based on HW version |
| 170 | * |
| 171 | * @core_version : Core version of FD HW |
| 172 | * @wrapper_version : Wrapper version of FD HW |
| 173 | * @core_regs : Register offset information for core registers |
| 174 | * @wrapper_regs : Register offset information for wrapper registers |
| 175 | * @results : Information about results available on this HW |
| 176 | * @enable_errata_wa : Errata workaround information |
| 177 | * @irq_mask : IRQ mask to enable |
| 178 | * @qos_priority : QoS priority setting for this chipset |
| 179 | * @qos_priority_level : QoS priority level setting for this chipset |
| 180 | * @supported_modes : Supported HW modes on this HW version |
| 181 | * @ro_mode_supported : Whether RO mode is supported on this HW |
| 182 | * |
| 183 | */ |
| 184 | struct cam_fd_hw_static_info { |
| 185 | struct cam_hw_version core_version; |
| 186 | struct cam_hw_version wrapper_version; |
| 187 | struct cam_fd_core_regs core_regs; |
| 188 | struct cam_fd_wrapper_regs wrapper_regs; |
| 189 | struct cam_fd_hw_results_prop results; |
| 190 | struct cam_fd_hw_errata_wa enable_errata_wa; |
| 191 | uint32_t irq_mask; |
| 192 | uint32_t qos_priority; |
| 193 | uint32_t qos_priority_level; |
| 194 | uint32_t supported_modes; |
| 195 | bool ro_mode_supported; |
| 196 | }; |
| 197 | |
| 198 | /** |
| 199 | * struct cam_fd_core : FD HW core data structure |
| 200 | * |
| 201 | * @hw_static_info : HW information specific to version |
| 202 | * @hw_caps : HW capabilities |
| 203 | * @core_state : Current HW state |
| 204 | * @processing_complete : Whether processing is complete |
| 205 | * @reset_complete : Whether reset is complete |
| 206 | * @halt_complete : Whether halt is complete |
| 207 | * @hw_req_private : Request that is being currently processed by HW |
| 208 | * @results_valid : Whether HW frame results are available to get |
| 209 | * @spin_lock : Mutex to protect shared data in hw layer |
| 210 | * @irq_cb : HW Manager callback information |
| 211 | * |
| 212 | */ |
| 213 | struct cam_fd_core { |
| 214 | struct cam_fd_hw_static_info *hw_static_info; |
| 215 | struct cam_fd_hw_caps hw_caps; |
| 216 | enum cam_fd_core_state core_state; |
| 217 | struct completion processing_complete; |
| 218 | struct completion reset_complete; |
| 219 | struct completion halt_complete; |
| 220 | struct cam_fd_hw_req_private *hw_req_private; |
| 221 | bool results_valid; |
| 222 | spinlock_t spin_lock; |
| 223 | struct cam_fd_hw_cmd_set_irq_cb irq_cb; |
| 224 | }; |
| 225 | |
| 226 | int cam_fd_hw_util_get_hw_caps(struct cam_hw_info *fd_hw, |
| 227 | struct cam_fd_hw_caps *hw_caps); |
| 228 | irqreturn_t cam_fd_hw_irq(int irq_num, void *data); |
| 229 | |
| 230 | int cam_fd_hw_get_hw_caps(void *hw_priv, void *get_hw_cap_args, |
| 231 | uint32_t arg_size); |
| 232 | int cam_fd_hw_init(void *hw_priv, void *init_hw_args, uint32_t arg_size); |
| 233 | int cam_fd_hw_deinit(void *hw_priv, void *deinit_hw_args, uint32_t arg_size); |
| 234 | int cam_fd_hw_reset(void *hw_priv, void *reset_core_args, uint32_t arg_size); |
| 235 | int cam_fd_hw_reserve(void *hw_priv, void *hw_reserve_args, uint32_t arg_size); |
| 236 | int cam_fd_hw_release(void *hw_priv, void *hw_release_args, uint32_t arg_size); |
| 237 | int cam_fd_hw_start(void *hw_priv, void *hw_start_args, uint32_t arg_size); |
| 238 | int cam_fd_hw_halt_reset(void *hw_priv, void *stop_args, uint32_t arg_size); |
| 239 | int cam_fd_hw_read(void *hw_priv, void *read_args, uint32_t arg_size); |
| 240 | int cam_fd_hw_write(void *hw_priv, void *write_args, uint32_t arg_size); |
| 241 | int cam_fd_hw_process_cmd(void *hw_priv, uint32_t cmd_type, |
| 242 | void *cmd_args, uint32_t arg_size); |
| 243 | |
| 244 | #endif /* _CAM_FD_HW_CORE_H_ */ |