2 *************************************************************************
3 * Rockchip driver for CIF ISP 1.0
4 * (Based on Intel driver for sofiaxxx)
6 * Copyright (C) 2015 Intel Mobile Communications GmbH
7 * Copyright (C) 2016 Fuzhou Rockchip Electronics Co., Ltd.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *************************************************************************
16 #ifndef _RK_ISP11_CONFIG_H
17 #define _RK_ISP11_CONFIG_H
19 #include <media/v4l2-config_rockchip.h>
21 #define CIFISP_MODULE_DPCC BIT(0)
22 #define CIFISP_MODULE_BLS BIT(1)
23 #define CIFISP_MODULE_SDG BIT(2)
24 #define CIFISP_MODULE_HST BIT(3)
25 #define CIFISP_MODULE_LSC BIT(4)
26 #define CIFISP_MODULE_AWB_GAIN BIT(5)
27 #define CIFISP_MODULE_FLT BIT(6)
28 #define CIFISP_MODULE_BDM BIT(7)
29 #define CIFISP_MODULE_CTK BIT(8)
30 #define CIFISP_MODULE_GOC BIT(9)
31 #define CIFISP_MODULE_CPROC BIT(10)
32 #define CIFISP_MODULE_AFC BIT(11)
33 #define CIFISP_MODULE_AWB BIT(12)
34 #define CIFISP_MODULE_IE BIT(13)
35 #define CIFISP_MODULE_AEC BIT(14)
36 #define CIFISP_MODULE_WDR BIT(15)
37 #define CIFISP_MODULE_DPF BIT(16)
38 #define CIFISP_MODULE_DPF_STRENGTH BIT(17)
40 #define CIFISP_CTK_COEFF_MAX 0x100
41 #define CIFISP_CTK_OFFSET_MAX 0x800
43 #define CIFISP_AE_MEAN_MAX 25
44 #define CIFISP_HIST_BIN_N_MAX 16
45 #define CIFISP_AFM_MAX_WINDOWS 3
46 #define CIFISP_DEGAMMA_CURVE_SIZE 17
48 #define CIFISP_BDM_MAX_TH 0xFF
50 /* maximum value for horizontal start address */
51 #define CIFISP_BLS_START_H_MAX (0x00000FFF)
52 /* maximum value for horizontal stop address */
53 #define CIFISP_BLS_STOP_H_MAX (0x00000FFF)
54 /* maximum value for vertical start address */
55 #define CIFISP_BLS_START_V_MAX (0x00000FFF)
56 /* maximum value for vertical stop address */
57 #define CIFISP_BLS_STOP_V_MAX (0x00000FFF)
58 /* maximum is 2^18 = 262144*/
59 #define CIFISP_BLS_SAMPLES_MAX (0x00000012)
60 /* maximum value for fixed black level */
61 #define CIFISP_BLS_FIX_SUB_MAX (0x00000FFF)
62 /* minimum value for fixed black level */
63 #define CIFISP_BLS_FIX_SUB_MIN (0xFFFFF000)
64 /* 13 bit range (signed)*/
65 #define CIFISP_BLS_FIX_MASK (0x00001FFF)
67 #define CIFISP_AWB_MAX_GRID 1
68 #define CIFISP_AWB_MAX_FRAMES 7
71 /* Maximum number of color samples supported */
72 #define CIFISP_GAMMA_OUT_MAX_SAMPLES 17
75 #define CIFISP_LSC_GRAD_TBL_SIZE 8
76 #define CIFISP_LSC_SIZE_TBL_SIZE 8
78 * The following matches the tuning process,
79 * not the max capabilities of the chip.
81 #define CIFISP_LSC_DATA_TBL_SIZE 289
83 #define CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE 25
86 #define CIFISP_DPCC_METHODS_MAX (3)
89 #define CIFISP_DPF_MAX_NLF_COEFFS 17
90 #define CIFISP_DPF_MAX_SPATIAL_COEFFS 6
92 #define CIFISP_STAT_AWB BIT(0)
93 #define CIFISP_STAT_AUTOEXP BIT(1)
94 #define CIFISP_STAT_AFM_FIN BIT(2)
95 #define CIFISP_STAT_HIST BIT(3)
97 enum cifisp_histogram_mode {
98 CIFISP_HISTOGRAM_MODE_DISABLE = 0,
99 CIFISP_HISTOGRAM_MODE_RGB_COMBINED = 1,
100 CIFISP_HISTOGRAM_MODE_R_HISTOGRAM = 2,
101 CIFISP_HISTOGRAM_MODE_G_HISTOGRAM = 3,
102 CIFISP_HISTOGRAM_MODE_B_HISTOGRAM = 4,
103 CIFISP_HISTOGRAM_MODE_Y_HISTOGRAM = 5
106 enum cifisp_exp_ctrl_autostop {
107 CIFISP_EXP_CTRL_AUTOSTOP_0 = 0,
108 CIFISP_EXP_CTRL_AUTOSTOP_1 = 1
111 enum cifisp_exp_meas_mode {
112 /* < Y = 16 + 0.25R + 0.5G + 0.1094B */
113 CIFISP_EXP_MEASURING_MODE_0 = 0,
114 /* < Y = (R + G + B) x (85/256) */
115 CIFISP_EXP_MEASURING_MODE_1 = 1,
118 struct cifisp_window {
119 unsigned short h_offs;
120 unsigned short v_offs;
121 unsigned short h_size;
122 unsigned short v_size;
125 enum cifisp_awb_mode_type {
126 CIFISP_AWB_MODE_MANUAL = 0,
127 CIFISP_AWB_MODE_RGB = 1,
128 CIFISP_AWB_MODE_YCBCR = 2
131 enum cifisp_bls_win_enable {
132 ISP_BLS_CTRL_WINDOW_ENABLE_0 = 0,
133 ISP_BLS_CTRL_WINDOW_ENABLE_1 = 1,
134 ISP_BLS_CTRL_WINDOW_ENABLE_2 = 2,
135 ISP_BLS_CTRL_WINDOW_ENABLE_3 = 3
138 enum cifisp_flt_mode {
139 CIFISP_FLT_STATIC_MODE,
140 CIFISP_FLT_DYNAMIC_MODE
143 struct cifisp_awb_meas {
145 unsigned char mean_y;
146 unsigned char mean_cb;
147 unsigned char mean_cr;
148 unsigned short mean_r;
149 unsigned short mean_b;
150 unsigned short mean_g;
153 struct cifisp_awb_stat {
154 struct cifisp_awb_meas awb_mean[CIFISP_AWB_MAX_GRID];
157 struct cifisp_hist_stat {
158 unsigned short hist_bins[CIFISP_HIST_BIN_N_MAX];
161 /*! BLS mean measured values */
162 struct cifisp_bls_meas_val {
163 /*! Mean measured value for Bayer pattern R.*/
164 unsigned short meas_r;
165 /*! Mean measured value for Bayer pattern Gr.*/
166 unsigned short meas_gr;
167 /*! Mean measured value for Bayer pattern Gb.*/
168 unsigned short meas_gb;
169 /*! Mean measured value for Bayer pattern B.*/
170 unsigned short meas_b;
174 * BLS fixed subtraction values. The values will be subtracted from the sensor
175 * values. Therefore a negative value means addition instead of subtraction!
177 struct cifisp_bls_fixed_val {
178 /*! Fixed (signed!) subtraction value for Bayer pattern R. */
180 /*! Fixed (signed!) subtraction value for Bayer pattern Gr. */
182 /*! Fixed (signed!) subtraction value for Bayer pattern Gb. */
184 /*! Fixed (signed!) subtraction value for Bayer pattern B. */
188 /* Configuration used by black level subtraction */
189 struct cifisp_bls_config {
191 * Automatic mode activated means that the measured values
192 * are subtracted.Otherwise the fixed subtraction
193 * values will be subtracted.
196 unsigned char en_windows;
197 struct cifisp_window bls_window1; /* < Measurement window 1. */
198 struct cifisp_window bls_window2; /* !< Measurement window 2 */
200 * Set amount of measured pixels for each Bayer position
201 * (A, B,C and D) to 2^bls_samples.
203 unsigned char bls_samples;
204 /* !< Fixed subtraction values. */
205 struct cifisp_bls_fixed_val fixed_val;
208 struct cifisp_ae_stat {
209 unsigned char exp_mean[CIFISP_AE_MEAN_MAX];
210 struct cifisp_bls_meas_val bls_val; /* available wit exposure results */
213 struct cifisp_af_meas_val {
218 struct cifisp_af_stat {
219 struct cifisp_af_meas_val window[CIFISP_AFM_MAX_WINDOWS];
223 struct cifisp_awb_stat awb;
224 struct cifisp_ae_stat ae;
225 struct cifisp_af_stat af;
226 struct cifisp_hist_stat hist;
229 struct cifisp_stat_buffer {
230 unsigned int meas_type;
231 struct cifisp_stat params;
232 struct isp_supplemental_sensor_mode_data sensor_mode;
235 struct cifisp_dpcc_methods_config {
237 unsigned int line_thresh;
238 unsigned int line_mad_fac;
240 unsigned int rnd_thresh;
244 struct cifisp_dpcc_config {
246 unsigned int output_mode;
247 unsigned int set_use;
248 struct cifisp_dpcc_methods_config methods[CIFISP_DPCC_METHODS_MAX];
249 unsigned int ro_limits;
250 unsigned int rnd_offs;
253 struct cifisp_gamma_corr_curve {
254 unsigned short gamma_y[CIFISP_DEGAMMA_CURVE_SIZE];
257 struct cifisp_gamma_curve_x_axis_pnts {
258 unsigned int gamma_dx0;
259 unsigned int gamma_dx1;
262 /* Configuration used by sensor degamma */
263 struct cifisp_sdg_config {
264 struct cifisp_gamma_corr_curve curve_r;
265 struct cifisp_gamma_corr_curve curve_g;
266 struct cifisp_gamma_corr_curve curve_b;
267 struct cifisp_gamma_curve_x_axis_pnts xa_pnts;
270 /* Configuration used by Lens shading correction */
271 struct cifisp_lsc_config {
272 unsigned int r_data_tbl[CIFISP_LSC_DATA_TBL_SIZE];
273 unsigned int gr_data_tbl[CIFISP_LSC_DATA_TBL_SIZE];
274 unsigned int gb_data_tbl[CIFISP_LSC_DATA_TBL_SIZE];
275 unsigned int b_data_tbl[CIFISP_LSC_DATA_TBL_SIZE];
277 unsigned int x_grad_tbl[CIFISP_LSC_GRAD_TBL_SIZE];
278 unsigned int y_grad_tbl[CIFISP_LSC_GRAD_TBL_SIZE];
280 unsigned int x_size_tbl[CIFISP_LSC_SIZE_TBL_SIZE];
281 unsigned int y_size_tbl[CIFISP_LSC_SIZE_TBL_SIZE];
282 unsigned short config_width;
283 unsigned short config_height;
286 struct cifisp_ie_config {
287 enum v4l2_colorfx effect;
288 unsigned short color_sel;
289 /* 3x3 Matrix Coefficients for Emboss Effect 1 */
290 unsigned short eff_mat_1;
291 /* 3x3 Matrix Coefficients for Emboss Effect 2 */
292 unsigned short eff_mat_2;
293 /* 3x3 Matrix Coefficients for Emboss 3/Sketch 1 */
294 unsigned short eff_mat_3;
295 /* 3x3 Matrix Coefficients for Sketch Effect 2 */
296 unsigned short eff_mat_4;
297 /* 3x3 Matrix Coefficients for Sketch Effect 3 */
298 unsigned short eff_mat_5;
299 /* Chrominance increment values of tint (used for sepia effect) */
300 unsigned short eff_tint;
303 /* Configuration used by auto white balance */
304 struct cifisp_awb_meas_config {
306 * white balance measurement window (in pixels)
307 * Note: currently the h and v offsets are mapped to grid offsets
309 struct cifisp_window awb_wnd;
310 enum cifisp_awb_mode_type awb_mode;
312 * only pixels values < max_y contribute to awb measurement
313 * (set to 0 to disable this feature)
316 /* only pixels values > min_y contribute to awb measurement */
319 * Chrominance sum maximum value, only consider pixels with Cb+Cr
320 * smaller than threshold for awb measurements
322 unsigned char max_csum;
324 * Chrominance minimum value, only consider pixels with Cb/Cr
325 * each greater than threshold value for awb measurements
329 * number of frames - 1 used for mean value calculation
330 * (ucFrames=0 means 1 Frame)
332 unsigned char frames;
333 /* reference Cr value for AWB regulation, target for AWB */
334 unsigned char awb_ref_cr;
335 /* reference Cb value for AWB regulation, target for AWB */
336 unsigned char awb_ref_cb;
337 bool enable_ymax_cmp;
340 struct cifisp_awb_gain_config {
341 unsigned short gain_red;
342 unsigned short gain_green_r;
343 unsigned short gain_blue;
344 unsigned short gain_green_b;
347 /* Configuration used by ISP filtering */
348 struct cifisp_flt_config {
349 enum cifisp_flt_mode mode; /* ISP_FILT_MODE register fields */
350 unsigned char grn_stage1; /* ISP_FILT_MODE register fields */
351 unsigned char chr_h_mode; /* ISP_FILT_MODE register fields */
352 unsigned char chr_v_mode; /* ISP_FILT_MODE register fields */
353 unsigned int thresh_bl0;
354 unsigned int thresh_bl1;
355 unsigned int thresh_sh0;
356 unsigned int thresh_sh1;
357 unsigned int lum_weight;
358 unsigned int fac_sh1;
359 unsigned int fac_sh0;
360 unsigned int fac_mid;
361 unsigned int fac_bl0;
362 unsigned int fac_bl1;
365 /* Configuration used by Bayer DeMosaic */
366 struct cifisp_bdm_config {
367 unsigned char demosaic_th;
370 /* Configuration used by Cross Talk correction */
371 struct cifisp_ctk_config {
372 unsigned short coeff0;
373 unsigned short coeff1;
374 unsigned short coeff2;
375 unsigned short coeff3;
376 unsigned short coeff4;
377 unsigned short coeff5;
378 unsigned short coeff6;
379 unsigned short coeff7;
380 unsigned short coeff8;
381 /* offset for the crosstalk correction matrix */
382 unsigned short ct_offset_r;
383 unsigned short ct_offset_g;
384 unsigned short ct_offset_b;
387 enum cifisp_goc_mode {
388 CIFISP_GOC_MODE_LOGARITHMIC,
389 CIFISP_GOC_MODE_EQUIDISTANT
392 /* Configuration used by Gamma Out correction */
393 struct cifisp_goc_config {
394 enum cifisp_goc_mode mode;
395 unsigned short gamma_y[CIFISP_GAMMA_OUT_MAX_SAMPLES];
398 /* CCM (Color Correction) */
399 struct cifisp_cproc_config {
400 unsigned char c_out_range;
401 unsigned char y_in_range;
402 unsigned char y_out_range;
403 unsigned char contrast;
404 unsigned char brightness;
409 /* Configuration used by Histogram */
410 struct cifisp_hst_config {
411 enum cifisp_histogram_mode mode;
412 unsigned char histogram_predivider;
413 struct cifisp_window meas_window;
414 unsigned char hist_weight[CIFISP_HISTOGRAM_WEIGHT_GRIDS_SIZE];
417 /* Configuration used by Auto Exposure Control */
418 struct cifisp_aec_config {
419 enum cifisp_exp_meas_mode mode;
420 enum cifisp_exp_ctrl_autostop autostop;
421 struct cifisp_window meas_window;
424 struct cifisp_afc_config {
425 unsigned char num_afm_win; /* max CIFISP_AFM_MAX_WINDOWS */
426 struct cifisp_window afm_win[CIFISP_AFM_MAX_WINDOWS];
428 unsigned int var_shift;
431 enum cifisp_dpf_gain_usage {
432 /* don't use any gains in preprocessing stage */
433 CIFISP_DPF_GAIN_USAGE_DISABLED = 1,
434 /* use only the noise function gains from registers DPF_NF_GAIN_R, ... */
435 CIFISP_DPF_GAIN_USAGE_NF_GAINS = 2,
436 /* use only the gains from LSC module */
437 CIFISP_DPF_GAIN_USAGE_LSC_GAINS = 3,
438 /* use the moise function gains and the gains from LSC module */
439 CIFISP_DPF_GAIN_USAGE_NF_LSC_GAINS = 4,
440 /* use only the gains from AWB module */
441 CIFISP_DPF_GAIN_USAGE_AWB_GAINS = 5,
442 /* use the gains from AWB and LSC module */
443 CIFISP_DPF_GAIN_USAGE_AWB_LSC_GAINS = 6,
444 /* upper border (only for an internal evaluation) */
445 CIFISP_DPF_GAIN_USAGE_MAX
448 enum cifisp_dpf_rb_filtersize {
449 /* red and blue filter kernel size 13x9 (means 7x5 active pixel) */
450 CIFISP_DPF_RB_FILTERSIZE_13x9 = 0,
451 /* red and blue filter kernel size 9x9 (means 5x5 active pixel) */
452 CIFISP_DPF_RB_FILTERSIZE_9x9 = 1,
455 enum cifisp_dpf_nll_scale_mode {
456 /* use a linear scaling */
457 CIFISP_NLL_SCALE_LINEAR = 0,
458 /* use a logarithmic scaling */
459 CIFISP_NLL_SCALE_LOGARITHMIC = 1,
462 struct cifisp_dpf_nll {
463 unsigned short coeff[CIFISP_DPF_MAX_NLF_COEFFS];
464 enum cifisp_dpf_nll_scale_mode scale_mode;
467 struct cifisp_dpf_rb_flt {
468 enum cifisp_dpf_rb_filtersize fltsize;
469 unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS];
474 struct cifisp_dpf_g_flt {
475 unsigned char spatial_coeff[CIFISP_DPF_MAX_SPATIAL_COEFFS];
480 struct cifisp_dpf_gain {
481 enum cifisp_dpf_gain_usage mode;
482 unsigned short nf_r_gain;
483 unsigned short nf_b_gain;
484 unsigned short nf_gr_gain;
485 unsigned short nf_gb_gain;
488 struct cifisp_dpf_config {
489 struct cifisp_dpf_gain gain;
490 struct cifisp_dpf_g_flt g_flt;
491 struct cifisp_dpf_rb_flt rb_flt;
492 struct cifisp_dpf_nll nll;
495 struct cifisp_dpf_strength_config {
501 struct cifisp_last_capture_config {
502 struct cifisp_cproc_config cproc;
503 struct cifisp_goc_config goc;
504 struct cifisp_ctk_config ctk;
505 struct cifisp_bdm_config bdm;
506 struct cifisp_flt_config flt;
507 struct cifisp_awb_gain_config awb_gain;
508 struct cifisp_awb_meas_config awb_meas;
509 struct cifisp_lsc_config lsc;
510 struct cifisp_sdg_config sdg;
511 struct cifisp_bls_config bls;
514 struct cifisp_isp_other_cfg {
515 unsigned int s_frame_id;/* Set isp hardware frame id */
517 unsigned int module_ens;
519 struct cifisp_dpcc_config dpcc_config;
520 struct cifisp_bls_config bls_config;
521 struct cifisp_sdg_config sdg_config;
522 struct cifisp_lsc_config lsc_config;
523 struct cifisp_awb_gain_config awb_gain_config;
524 struct cifisp_flt_config flt_config;
525 struct cifisp_bdm_config bdm_config;
526 struct cifisp_ctk_config ctk_config;
527 struct cifisp_goc_config goc_config;
528 struct cifisp_cproc_config cproc_config;
529 struct cifisp_ie_config ie_config;
530 struct cifisp_dpf_config dpf_config;
531 struct cifisp_dpf_strength_config dpf_strength_config;
534 struct cifisp_isp_meas_cfg {
535 unsigned int s_frame_id; /* Set isp hardware frame id */
537 unsigned int module_ens;
539 struct cifisp_awb_meas_config awb_meas_config;
540 struct cifisp_hst_config hst_config;
541 struct cifisp_aec_config aec_config;
542 struct cifisp_afc_config afc_config;
545 struct cifisp_isp_metadata {
546 struct cifisp_isp_other_cfg other_cfg;
547 struct cifisp_isp_meas_cfg meas_cfg;
548 struct cifisp_stat_buffer meas_stat;