1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Support for Medifield PNW Camera Imaging ISP subsystem. 4 * 5 * Copyright (c) 2010 Intel Corporation. All Rights Reserved. 6 * 7 * Copyright (c) 2010 Silicon Hive www.siliconhive.com. 8 */ 9 10 #ifndef __ATOMISP_CMD_H__ 11 #define __ATOMISP_CMD_H__ 12 13 #include "../../include/linux/atomisp.h" 14 #include <linux/interrupt.h> 15 #include <linux/videodev2.h> 16 17 #include <media/v4l2-subdev.h> 18 19 #include "atomisp_internal.h" 20 21 #include "ia_css_types.h" 22 #include "ia_css.h" 23 24 struct atomisp_device; 25 struct ia_css_frame; 26 27 #define MSI_ENABLE_BIT 16 28 #define INTR_DISABLE_BIT 10 29 #define BUS_MASTER_ENABLE 2 30 #define MEMORY_SPACE_ENABLE 1 31 #define INTR_IER 24 32 #define INTR_IIR 16 33 34 /* Helper function */ 35 void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr, 36 unsigned int size); 37 struct camera_mipi_info *atomisp_to_sensor_mipi_info(struct v4l2_subdev *sd); 38 struct atomisp_video_pipe *atomisp_to_video_pipe(struct video_device *dev); 39 int atomisp_reset(struct atomisp_device *isp); 40 int atomisp_buffers_in_css(struct atomisp_video_pipe *pipe); 41 void atomisp_buffer_done(struct ia_css_frame *frame, enum vb2_buffer_state state); 42 void atomisp_flush_video_pipe(struct atomisp_video_pipe *pipe, enum vb2_buffer_state state, 43 bool warn_on_css_frames); 44 void atomisp_clear_css_buffer_counters(struct atomisp_sub_device *asd); 45 46 /* Interrupt functions */ 47 void atomisp_msi_irq_init(struct atomisp_device *isp); 48 void atomisp_msi_irq_uninit(struct atomisp_device *isp); 49 void atomisp_assert_recovery_work(struct work_struct *work); 50 irqreturn_t atomisp_isr(int irq, void *dev); 51 irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr); 52 const struct atomisp_format_bridge *get_atomisp_format_bridge_from_mbus( 53 u32 mbus_code); 54 bool atomisp_is_mbuscode_raw(uint32_t code); 55 56 /* Get internal fmt according to V4L2 fmt */ 57 bool atomisp_is_viewfinder_support(struct atomisp_device *isp); 58 59 /* ISP features control function */ 60 61 /* 62 * Function to enable/disable lens geometry distortion correction (GDC) and 63 * chromatic aberration correction (CAC) 64 */ 65 int atomisp_gdc_cac(struct atomisp_sub_device *asd, int flag, 66 __s32 *value); 67 68 /* Function to enable/disable low light mode (including ANR) */ 69 int atomisp_low_light(struct atomisp_sub_device *asd, int flag, 70 __s32 *value); 71 72 /* 73 * Function to enable/disable extra noise reduction (XNR) in low light 74 * condition 75 */ 76 int atomisp_xnr(struct atomisp_sub_device *asd, int flag, int *arg); 77 78 int atomisp_formats(struct atomisp_sub_device *asd, int flag, 79 struct atomisp_formats_config *config); 80 81 /* Function to configure noise reduction */ 82 int atomisp_nr(struct atomisp_sub_device *asd, int flag, 83 struct atomisp_nr_config *config); 84 85 /* Function to configure temporal noise reduction (TNR) */ 86 int atomisp_tnr(struct atomisp_sub_device *asd, int flag, 87 struct atomisp_tnr_config *config); 88 89 /* Function to configure black level compensation */ 90 int atomisp_black_level(struct atomisp_sub_device *asd, int flag, 91 struct atomisp_ob_config *config); 92 93 /* Function to configure edge enhancement */ 94 int atomisp_ee(struct atomisp_sub_device *asd, int flag, 95 struct atomisp_ee_config *config); 96 97 /* Function to update Gamma table for gamma, brightness and contrast config */ 98 int atomisp_gamma(struct atomisp_sub_device *asd, int flag, 99 struct atomisp_gamma_table *config); 100 101 /* Function to update Ctc table for Chroma Enhancement */ 102 int atomisp_ctc(struct atomisp_sub_device *asd, int flag, 103 struct atomisp_ctc_table *config); 104 105 /* Function to update gamma correction parameters */ 106 int atomisp_gamma_correction(struct atomisp_sub_device *asd, int flag, 107 struct atomisp_gc_config *config); 108 109 /* Function to update Gdc table for gdc */ 110 int atomisp_gdc_cac_table(struct atomisp_sub_device *asd, int flag, 111 struct atomisp_morph_table *config); 112 113 /* Function to update table for macc */ 114 int atomisp_macc_table(struct atomisp_sub_device *asd, int flag, 115 struct atomisp_macc_config *config); 116 117 /* Function to get DIS statistics. */ 118 int atomisp_get_dis_stat(struct atomisp_sub_device *asd, 119 struct atomisp_dis_statistics *stats); 120 121 /* Function to get DVS2 BQ resolution settings */ 122 int atomisp_get_dvs2_bq_resolutions(struct atomisp_sub_device *asd, 123 struct atomisp_dvs2_bq_resolutions *bq_res); 124 125 /* Function to set the DIS coefficients. */ 126 int atomisp_set_dis_coefs(struct atomisp_sub_device *asd, 127 struct atomisp_dis_coefficients *coefs); 128 129 /* Function to set the DIS motion vector. */ 130 int atomisp_set_dis_vector(struct atomisp_sub_device *asd, 131 struct atomisp_dis_vector *vector); 132 133 /* Function to set/get 3A stat from isp */ 134 int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag, 135 struct atomisp_3a_statistics *config); 136 137 int atomisp_set_parameters(struct video_device *vdev, 138 struct atomisp_parameters *arg); 139 140 /* Function to set/get isp parameters to isp */ 141 int atomisp_param(struct atomisp_sub_device *asd, int flag, 142 struct atomisp_parm *config); 143 144 /* Function to configure color effect of the image */ 145 int atomisp_color_effect(struct atomisp_sub_device *asd, int flag, 146 __s32 *effect); 147 148 /* Function to configure bad pixel correction */ 149 int atomisp_bad_pixel(struct atomisp_sub_device *asd, int flag, 150 __s32 *value); 151 152 /* Function to configure bad pixel correction params */ 153 int atomisp_bad_pixel_param(struct atomisp_sub_device *asd, int flag, 154 struct atomisp_dp_config *config); 155 156 /* Function to enable/disable video image stablization */ 157 int atomisp_video_stable(struct atomisp_sub_device *asd, int flag, 158 __s32 *value); 159 160 /* Function to configure fixed pattern noise */ 161 int atomisp_fixed_pattern(struct atomisp_sub_device *asd, int flag, 162 __s32 *value); 163 164 /* Function to configure fixed pattern noise table */ 165 int atomisp_fixed_pattern_table(struct atomisp_sub_device *asd, 166 struct v4l2_framebuffer *config); 167 168 /* Function to configure false color correction */ 169 int atomisp_false_color(struct atomisp_sub_device *asd, int flag, 170 __s32 *value); 171 172 /* Function to configure false color correction params */ 173 int atomisp_false_color_param(struct atomisp_sub_device *asd, int flag, 174 struct atomisp_de_config *config); 175 176 /* Function to configure white balance params */ 177 int atomisp_white_balance_param(struct atomisp_sub_device *asd, int flag, 178 struct atomisp_wb_config *config); 179 180 int atomisp_3a_config_param(struct atomisp_sub_device *asd, int flag, 181 struct atomisp_3a_config *config); 182 183 /* Function to setup digital zoom */ 184 int atomisp_digital_zoom(struct atomisp_sub_device *asd, int flag, 185 __s32 *value); 186 187 /* Function set camera_prefiles.xml current sensor pixel array size */ 188 int atomisp_set_array_res(struct atomisp_sub_device *asd, 189 struct atomisp_resolution *config); 190 191 /* Function to calculate real zoom region for every pipe */ 192 int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd, 193 struct ia_css_dz_config *dz_config, 194 enum ia_css_pipe_id css_pipe_id); 195 196 int atomisp_cp_general_isp_parameters(struct atomisp_sub_device *asd, 197 struct atomisp_parameters *arg, 198 struct atomisp_css_params *css_param, 199 bool from_user); 200 201 int atomisp_cp_lsc_table(struct atomisp_sub_device *asd, 202 struct atomisp_shading_table *source_st, 203 struct atomisp_css_params *css_param, 204 bool from_user); 205 206 int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd, 207 struct ia_css_dvs2_coefficients *coefs, 208 struct atomisp_css_params *css_param, 209 bool from_user); 210 211 int atomisp_cp_morph_table(struct atomisp_sub_device *asd, 212 struct atomisp_morph_table *source_morph_table, 213 struct atomisp_css_params *css_param, 214 bool from_user); 215 216 int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd, 217 struct atomisp_dvs_6axis_config *user_6axis_config, 218 struct atomisp_css_params *css_param, 219 bool from_user); 220 221 int atomisp_makeup_css_parameters(struct atomisp_sub_device *asd, 222 struct atomisp_parameters *arg, 223 struct atomisp_css_params *css_param); 224 225 int atomisp_compare_grid(struct atomisp_sub_device *asd, 226 struct atomisp_grid_info *atomgrid); 227 228 /* Get sensor padding values for the non padded width x height resolution */ 229 void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height, 230 u32 *padding_w, u32 *padding_h); 231 232 /* Set sensor power (no-op if already on/off) */ 233 int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on); 234 235 /* Select which sensor to use, must be called with a valid input */ 236 int atomisp_select_input(struct atomisp_device *isp, unsigned int input); 237 238 /* Setup media-controller links to reflect input_curr setting */ 239 void atomisp_setup_input_links(struct atomisp_device *isp); 240 241 /* This function looks up the closest available resolution. */ 242 int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f, 243 const struct atomisp_format_bridge **fmt_ret, 244 const struct atomisp_format_bridge **snr_fmt_ret); 245 246 int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f); 247 248 int atomisp_set_shading_table(struct atomisp_sub_device *asd, 249 struct atomisp_shading_table *shading_table); 250 251 void atomisp_free_internal_buffers(struct atomisp_sub_device *asd); 252 253 int atomisp_freq_scaling(struct atomisp_device *vdev, 254 enum atomisp_dfs_mode mode, 255 bool force); 256 257 void atomisp_buf_done(struct atomisp_sub_device *asd, int error, 258 enum ia_css_buffer_type buf_type, 259 enum ia_css_pipe_id css_pipe_id, 260 bool q_buffers, enum atomisp_input_stream_id stream_id); 261 262 /* Events. Only one event has to be exported for now. */ 263 void atomisp_eof_event(struct atomisp_sub_device *asd, uint8_t exp_id); 264 265 enum mipi_port_id atomisp_port_to_mipi_port(struct atomisp_device *isp, 266 enum atomisp_camera_port port); 267 268 void atomisp_apply_css_parameters( 269 struct atomisp_sub_device *asd, 270 struct atomisp_css_params *css_param); 271 void atomisp_free_css_parameters(struct atomisp_css_params *css_param); 272 273 void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe); 274 275 void atomisp_flush_params_queue(struct atomisp_video_pipe *asd); 276 277 /* Function to do Raw Buffer related operation, after enable Lock Unlock Raw Buffer */ 278 int atomisp_exp_id_unlock(struct atomisp_sub_device *asd, int *exp_id); 279 int atomisp_exp_id_capture(struct atomisp_sub_device *asd, int *exp_id); 280 281 void atomisp_init_raw_buffer_bitmap(struct atomisp_sub_device *asd); 282 283 /* Function to enable/disable zoom for capture pipe */ 284 int atomisp_enable_dz_capt_pipe(struct atomisp_sub_device *asd, 285 unsigned int *enable); 286 287 u32 atomisp_get_pixel_depth(u32 pixelformat); 288 289 /* Function for HAL to inject a fake event to wake up poll thread */ 290 int atomisp_inject_a_fake_event(struct atomisp_sub_device *asd, int *event); 291 292 /* 293 * Function for HAL to query how many invalid frames at the beginning of ISP 294 * pipeline output 295 */ 296 int atomisp_get_invalid_frame_num(struct video_device *vdev, 297 int *invalid_frame_num); 298 299 int atomisp_power_off(struct device *dev); 300 int atomisp_power_on(struct device *dev); 301 #endif /* __ATOMISP_CMD_H__ */ 302