1 /* 2 * Support for Medifield PNW Camera Imaging ISP subsystem. 3 * 4 * Copyright (c) 2010 Intel Corporation. All Rights Reserved. 5 * 6 * Copyright (c) 2010 Silicon Hive www.siliconhive.com. 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License version 10 * 2 as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * 18 */ 19 20 #ifndef __ATOMISP_CMD_H__ 21 #define __ATOMISP_CMD_H__ 22 23 #include "../../include/linux/atomisp.h" 24 #include <linux/interrupt.h> 25 #include <linux/videodev2.h> 26 27 #include <media/v4l2-subdev.h> 28 29 #include "atomisp_internal.h" 30 31 #include "ia_css_types.h" 32 #include "ia_css.h" 33 34 struct atomisp_device; 35 struct ia_css_frame; 36 37 #define MSI_ENABLE_BIT 16 38 #define INTR_DISABLE_BIT 10 39 #define BUS_MASTER_ENABLE 2 40 #define MEMORY_SPACE_ENABLE 1 41 #define INTR_IER 24 42 #define INTR_IIR 16 43 44 /* ISP2401 */ 45 #define RUNMODE_MASK (ATOMISP_RUN_MODE_VIDEO | ATOMISP_RUN_MODE_STILL_CAPTURE \ 46 | ATOMISP_RUN_MODE_PREVIEW) 47 48 /* FIXME: check if can go */ 49 extern int atomisp_punit_hpll_freq; 50 51 /* 52 * Helper function 53 */ 54 void dump_sp_dmem(struct atomisp_device *isp, unsigned int addr, 55 unsigned int size); 56 struct camera_mipi_info *atomisp_to_sensor_mipi_info(struct v4l2_subdev *sd); 57 struct atomisp_video_pipe *atomisp_to_video_pipe(struct video_device *dev); 58 struct atomisp_acc_pipe *atomisp_to_acc_pipe(struct video_device *dev); 59 int atomisp_reset(struct atomisp_device *isp); 60 void atomisp_flush_bufs_and_wakeup(struct atomisp_sub_device *asd); 61 void atomisp_clear_css_buffer_counters(struct atomisp_sub_device *asd); 62 /* ISP2400 */ 63 bool atomisp_buffers_queued(struct atomisp_sub_device *asd); 64 /* ISP2401 */ 65 bool atomisp_buffers_queued_pipe(struct atomisp_video_pipe *pipe); 66 67 /* TODO:should be here instead of atomisp_helper.h 68 extern void __iomem *atomisp_io_base; 69 70 static inline void __iomem *atomisp_get_io_virt_addr(unsigned int address) 71 { 72 void __iomem *ret = atomisp_io_base + (address & 0x003FFFFF); 73 return ret; 74 } 75 */ 76 77 /* 78 * Interrupt functions 79 */ 80 void atomisp_msi_irq_init(struct atomisp_device *isp, struct pci_dev *dev); 81 void atomisp_msi_irq_uninit(struct atomisp_device *isp, struct pci_dev *dev); 82 void atomisp_wdt_work(struct work_struct *work); 83 void atomisp_wdt(struct timer_list *t); 84 void atomisp_setup_flash(struct atomisp_sub_device *asd); 85 irqreturn_t atomisp_isr(int irq, void *dev); 86 irqreturn_t atomisp_isr_thread(int irq, void *isp_ptr); 87 const struct atomisp_format_bridge *get_atomisp_format_bridge_from_mbus( 88 u32 mbus_code); 89 bool atomisp_is_mbuscode_raw(uint32_t code); 90 int atomisp_get_frame_pgnr(struct atomisp_device *isp, 91 const struct ia_css_frame *frame, u32 *p_pgnr); 92 void atomisp_delayed_init_work(struct work_struct *work); 93 94 /* 95 * Get internal fmt according to V4L2 fmt 96 */ 97 98 bool atomisp_is_viewfinder_support(struct atomisp_device *isp); 99 100 /* 101 * ISP features control function 102 */ 103 104 /* 105 * Function to set sensor runmode by user when 106 * ATOMISP_IOC_S_SENSOR_RUNMODE ioctl was called 107 */ 108 int atomisp_set_sensor_runmode(struct atomisp_sub_device *asd, 109 struct atomisp_s_runmode *runmode); 110 /* 111 * Function to enable/disable lens geometry distortion correction (GDC) and 112 * chromatic aberration correction (CAC) 113 */ 114 int atomisp_gdc_cac(struct atomisp_sub_device *asd, int flag, 115 __s32 *value); 116 117 /* 118 * Function to enable/disable low light mode (including ANR) 119 */ 120 int atomisp_low_light(struct atomisp_sub_device *asd, int flag, 121 __s32 *value); 122 123 /* 124 * Function to enable/disable extra noise reduction (XNR) in low light 125 * condition 126 */ 127 int atomisp_xnr(struct atomisp_sub_device *asd, int flag, int *arg); 128 129 int atomisp_formats(struct atomisp_sub_device *asd, int flag, 130 struct atomisp_formats_config *config); 131 132 /* 133 * Function to configure noise reduction 134 */ 135 int atomisp_nr(struct atomisp_sub_device *asd, int flag, 136 struct atomisp_nr_config *config); 137 138 /* 139 * Function to configure temporal noise reduction (TNR) 140 */ 141 int atomisp_tnr(struct atomisp_sub_device *asd, int flag, 142 struct atomisp_tnr_config *config); 143 144 /* 145 * Function to configure black level compensation 146 */ 147 int atomisp_black_level(struct atomisp_sub_device *asd, int flag, 148 struct atomisp_ob_config *config); 149 150 /* 151 * Function to configure edge enhancement 152 */ 153 int atomisp_ee(struct atomisp_sub_device *asd, int flag, 154 struct atomisp_ee_config *config); 155 156 /* 157 * Function to update Gamma table for gamma, brightness and contrast config 158 */ 159 int atomisp_gamma(struct atomisp_sub_device *asd, int flag, 160 struct atomisp_gamma_table *config); 161 /* 162 * Function to update Ctc table for Chroma Enhancement 163 */ 164 int atomisp_ctc(struct atomisp_sub_device *asd, int flag, 165 struct atomisp_ctc_table *config); 166 167 /* 168 * Function to update gamma correction parameters 169 */ 170 int atomisp_gamma_correction(struct atomisp_sub_device *asd, int flag, 171 struct atomisp_gc_config *config); 172 173 /* 174 * Function to update Gdc table for gdc 175 */ 176 int atomisp_gdc_cac_table(struct atomisp_sub_device *asd, int flag, 177 struct atomisp_morph_table *config); 178 179 /* 180 * Function to update table for macc 181 */ 182 int atomisp_macc_table(struct atomisp_sub_device *asd, int flag, 183 struct atomisp_macc_config *config); 184 /* 185 * Function to get DIS statistics. 186 */ 187 int atomisp_get_dis_stat(struct atomisp_sub_device *asd, 188 struct atomisp_dis_statistics *stats); 189 190 /* 191 * Function to get DVS2 BQ resolution settings 192 */ 193 int atomisp_get_dvs2_bq_resolutions(struct atomisp_sub_device *asd, 194 struct atomisp_dvs2_bq_resolutions *bq_res); 195 196 /* 197 * Function to set the DIS coefficients. 198 */ 199 int atomisp_set_dis_coefs(struct atomisp_sub_device *asd, 200 struct atomisp_dis_coefficients *coefs); 201 202 /* 203 * Function to set the DIS motion vector. 204 */ 205 int atomisp_set_dis_vector(struct atomisp_sub_device *asd, 206 struct atomisp_dis_vector *vector); 207 208 /* 209 * Function to set/get 3A stat from isp 210 */ 211 int atomisp_3a_stat(struct atomisp_sub_device *asd, int flag, 212 struct atomisp_3a_statistics *config); 213 214 /* 215 * Function to get metadata from isp 216 */ 217 int atomisp_get_metadata(struct atomisp_sub_device *asd, int flag, 218 struct atomisp_metadata *config); 219 220 int atomisp_get_metadata_by_type(struct atomisp_sub_device *asd, int flag, 221 struct atomisp_metadata_with_type *config); 222 223 int atomisp_set_parameters(struct video_device *vdev, 224 struct atomisp_parameters *arg); 225 /* 226 * Function to set/get isp parameters to isp 227 */ 228 int atomisp_param(struct atomisp_sub_device *asd, int flag, 229 struct atomisp_parm *config); 230 231 /* 232 * Function to configure color effect of the image 233 */ 234 int atomisp_color_effect(struct atomisp_sub_device *asd, int flag, 235 __s32 *effect); 236 237 /* 238 * Function to configure bad pixel correction 239 */ 240 int atomisp_bad_pixel(struct atomisp_sub_device *asd, int flag, 241 __s32 *value); 242 243 /* 244 * Function to configure bad pixel correction params 245 */ 246 int atomisp_bad_pixel_param(struct atomisp_sub_device *asd, int flag, 247 struct atomisp_dp_config *config); 248 249 /* 250 * Function to enable/disable video image stablization 251 */ 252 int atomisp_video_stable(struct atomisp_sub_device *asd, int flag, 253 __s32 *value); 254 255 /* 256 * Function to configure fixed pattern noise 257 */ 258 int atomisp_fixed_pattern(struct atomisp_sub_device *asd, int flag, 259 __s32 *value); 260 261 /* 262 * Function to configure fixed pattern noise table 263 */ 264 int atomisp_fixed_pattern_table(struct atomisp_sub_device *asd, 265 struct v4l2_framebuffer *config); 266 267 /* 268 * Function to configure false color correction 269 */ 270 int atomisp_false_color(struct atomisp_sub_device *asd, int flag, 271 __s32 *value); 272 273 /* 274 * Function to configure false color correction params 275 */ 276 int atomisp_false_color_param(struct atomisp_sub_device *asd, int flag, 277 struct atomisp_de_config *config); 278 279 /* 280 * Function to configure white balance params 281 */ 282 int atomisp_white_balance_param(struct atomisp_sub_device *asd, int flag, 283 struct atomisp_wb_config *config); 284 285 int atomisp_3a_config_param(struct atomisp_sub_device *asd, int flag, 286 struct atomisp_3a_config *config); 287 288 /* 289 * Function to setup digital zoom 290 */ 291 int atomisp_digital_zoom(struct atomisp_sub_device *asd, int flag, 292 __s32 *value); 293 294 /* 295 * Function set camera_prefiles.xml current sensor pixel array size 296 */ 297 int atomisp_set_array_res(struct atomisp_sub_device *asd, 298 struct atomisp_resolution *config); 299 300 /* 301 * Function to calculate real zoom region for every pipe 302 */ 303 int atomisp_calculate_real_zoom_region(struct atomisp_sub_device *asd, 304 struct ia_css_dz_config *dz_config, 305 enum ia_css_pipe_id css_pipe_id); 306 307 int atomisp_cp_general_isp_parameters(struct atomisp_sub_device *asd, 308 struct atomisp_parameters *arg, 309 struct atomisp_css_params *css_param, 310 bool from_user); 311 312 int atomisp_cp_lsc_table(struct atomisp_sub_device *asd, 313 struct atomisp_shading_table *source_st, 314 struct atomisp_css_params *css_param, 315 bool from_user); 316 317 int atomisp_css_cp_dvs2_coefs(struct atomisp_sub_device *asd, 318 struct ia_css_dvs2_coefficients *coefs, 319 struct atomisp_css_params *css_param, 320 bool from_user); 321 322 int atomisp_cp_morph_table(struct atomisp_sub_device *asd, 323 struct atomisp_morph_table *source_morph_table, 324 struct atomisp_css_params *css_param, 325 bool from_user); 326 327 int atomisp_cp_dvs_6axis_config(struct atomisp_sub_device *asd, 328 struct atomisp_dvs_6axis_config *user_6axis_config, 329 struct atomisp_css_params *css_param, 330 bool from_user); 331 332 int atomisp_makeup_css_parameters(struct atomisp_sub_device *asd, 333 struct atomisp_parameters *arg, 334 struct atomisp_css_params *css_param); 335 336 int atomisp_compare_grid(struct atomisp_sub_device *asd, 337 struct atomisp_grid_info *atomgrid); 338 339 int atomisp_get_sensor_mode_data(struct atomisp_sub_device *asd, 340 struct atomisp_sensor_mode_data *config); 341 342 int atomisp_get_fmt(struct video_device *vdev, struct v4l2_format *f); 343 344 /* This function looks up the closest available resolution. */ 345 int atomisp_try_fmt(struct video_device *vdev, struct v4l2_format *f, 346 bool *res_overflow); 347 348 int atomisp_set_fmt(struct video_device *vdev, struct v4l2_format *f); 349 int atomisp_set_fmt_file(struct video_device *vdev, struct v4l2_format *f); 350 351 int atomisp_set_shading_table(struct atomisp_sub_device *asd, 352 struct atomisp_shading_table *shading_table); 353 354 int atomisp_offline_capture_configure(struct atomisp_sub_device *asd, 355 struct atomisp_cont_capture_conf *cvf_config); 356 357 int atomisp_ospm_dphy_down(struct atomisp_device *isp); 358 int atomisp_ospm_dphy_up(struct atomisp_device *isp); 359 int atomisp_exif_makernote(struct atomisp_sub_device *asd, 360 struct atomisp_makernote_info *config); 361 362 void atomisp_free_internal_buffers(struct atomisp_sub_device *asd); 363 364 int atomisp_s_ae_window(struct atomisp_sub_device *asd, 365 struct atomisp_ae_window *arg); 366 367 int atomisp_flash_enable(struct atomisp_sub_device *asd, 368 int num_frames); 369 370 int atomisp_freq_scaling(struct atomisp_device *vdev, 371 enum atomisp_dfs_mode mode, 372 bool force); 373 374 void atomisp_buf_done(struct atomisp_sub_device *asd, int error, 375 enum ia_css_buffer_type buf_type, 376 enum ia_css_pipe_id css_pipe_id, 377 bool q_buffers, enum atomisp_input_stream_id stream_id); 378 379 void atomisp_css_flush(struct atomisp_device *isp); 380 int atomisp_source_pad_to_stream_id(struct atomisp_sub_device *asd, 381 uint16_t source_pad); 382 383 /* 384 * Events. Only one event has to be exported for now. 385 */ 386 void atomisp_eof_event(struct atomisp_sub_device *asd, uint8_t exp_id); 387 388 enum mipi_port_id __get_mipi_port(struct atomisp_device *isp, 389 enum atomisp_camera_port port); 390 391 bool atomisp_is_vf_pipe(struct atomisp_video_pipe *pipe); 392 393 void atomisp_apply_css_parameters( 394 struct atomisp_sub_device *asd, 395 struct atomisp_css_params *css_param); 396 void atomisp_free_css_parameters(struct atomisp_css_params *css_param); 397 398 void atomisp_handle_parameter_and_buffer(struct atomisp_video_pipe *pipe); 399 400 void atomisp_flush_params_queue(struct atomisp_video_pipe *asd); 401 /* 402 * Function to do Raw Buffer related operation, after enable Lock Unlock Raw Buffer 403 */ 404 int atomisp_exp_id_unlock(struct atomisp_sub_device *asd, int *exp_id); 405 int atomisp_exp_id_capture(struct atomisp_sub_device *asd, int *exp_id); 406 407 /* 408 * Function to update Raw Buffer bitmap 409 */ 410 int atomisp_set_raw_buffer_bitmap(struct atomisp_sub_device *asd, int exp_id); 411 void atomisp_init_raw_buffer_bitmap(struct atomisp_sub_device *asd); 412 413 /* 414 * Function to enable/disable zoom for capture pipe 415 */ 416 int atomisp_enable_dz_capt_pipe(struct atomisp_sub_device *asd, 417 unsigned int *enable); 418 419 /* 420 * Function to get metadata type bu pipe id 421 */ 422 enum atomisp_metadata_type 423 atomisp_get_metadata_type(struct atomisp_sub_device *asd, 424 enum ia_css_pipe_id pipe_id); 425 426 /* 427 * Function for HAL to inject a fake event to wake up poll thread 428 */ 429 int atomisp_inject_a_fake_event(struct atomisp_sub_device *asd, int *event); 430 431 /* 432 * Function for HAL to query how many invalid frames at the beginning of ISP 433 * pipeline output 434 */ 435 int atomisp_get_invalid_frame_num(struct video_device *vdev, 436 int *invalid_frame_num); 437 438 int atomisp_mrfld_power_up(struct atomisp_device *isp); 439 int atomisp_mrfld_power_down(struct atomisp_device *isp); 440 int atomisp_runtime_suspend(struct device *dev); 441 int atomisp_runtime_resume(struct device *dev); 442 #endif /* __ATOMISP_CMD_H__ */ 443