1e6938cc1SHelen Koike // SPDX-License-Identifier: (GPL-2.0+ OR MIT) 2e6938cc1SHelen Koike /* 3e6938cc1SHelen Koike * Rockchip ISP1 Driver - Params subdevice 4e6938cc1SHelen Koike * 5e6938cc1SHelen Koike * Copyright (C) 2017 Rockchip Electronics Co., Ltd. 6e6938cc1SHelen Koike */ 7e6938cc1SHelen Koike 8e6938cc1SHelen Koike #include <media/v4l2-common.h> 9e6938cc1SHelen Koike #include <media/v4l2-event.h> 10e6938cc1SHelen Koike #include <media/v4l2-ioctl.h> 11e6938cc1SHelen Koike #include <media/videobuf2-core.h> 12e6938cc1SHelen Koike #include <media/videobuf2-vmalloc.h> /* for ISP params */ 13e6938cc1SHelen Koike 14e6938cc1SHelen Koike #include "rkisp1-common.h" 15e6938cc1SHelen Koike 16e6938cc1SHelen Koike #define RKISP1_PARAMS_DEV_NAME RKISP1_DRIVER_NAME "_params" 17e6938cc1SHelen Koike 18e6938cc1SHelen Koike #define RKISP1_ISP_PARAMS_REQ_BUFS_MIN 2 19e6938cc1SHelen Koike #define RKISP1_ISP_PARAMS_REQ_BUFS_MAX 8 20e6938cc1SHelen Koike 21e6938cc1SHelen Koike #define RKISP1_ISP_DPCC_LINE_THRESH(n) \ 22e6938cc1SHelen Koike (RKISP1_CIF_ISP_DPCC_LINE_THRESH_1 + 0x14 * (n)) 23e6938cc1SHelen Koike #define RKISP1_ISP_DPCC_LINE_MAD_FAC(n) \ 24e6938cc1SHelen Koike (RKISP1_CIF_ISP_DPCC_LINE_MAD_FAC_1 + 0x14 * (n)) 25e6938cc1SHelen Koike #define RKISP1_ISP_DPCC_PG_FAC(n) \ 26e6938cc1SHelen Koike (RKISP1_CIF_ISP_DPCC_PG_FAC_1 + 0x14 * (n)) 27e6938cc1SHelen Koike #define RKISP1_ISP_DPCC_RND_THRESH(n) \ 28e6938cc1SHelen Koike (RKISP1_CIF_ISP_DPCC_RND_THRESH_1 + 0x14 * (n)) 29e6938cc1SHelen Koike #define RKISP1_ISP_DPCC_RG_FAC(n) \ 30e6938cc1SHelen Koike (RKISP1_CIF_ISP_DPCC_RG_FAC_1 + 0x14 * (n)) 31e6938cc1SHelen Koike #define RKISP1_ISP_CC_COEFF(n) \ 32e6938cc1SHelen Koike (RKISP1_CIF_ISP_CC_COEFF_0 + (n) * 4) 33e6938cc1SHelen Koike 34e6938cc1SHelen Koike static inline void 35e6938cc1SHelen Koike rkisp1_param_set_bits(struct rkisp1_params *params, u32 reg, u32 bit_mask) 36e6938cc1SHelen Koike { 37e6938cc1SHelen Koike u32 val; 38e6938cc1SHelen Koike 39e6938cc1SHelen Koike val = rkisp1_read(params->rkisp1, reg); 40e6938cc1SHelen Koike rkisp1_write(params->rkisp1, val | bit_mask, reg); 41e6938cc1SHelen Koike } 42e6938cc1SHelen Koike 43e6938cc1SHelen Koike static inline void 44e6938cc1SHelen Koike rkisp1_param_clear_bits(struct rkisp1_params *params, u32 reg, u32 bit_mask) 45e6938cc1SHelen Koike { 46e6938cc1SHelen Koike u32 val; 47e6938cc1SHelen Koike 48e6938cc1SHelen Koike val = rkisp1_read(params->rkisp1, reg); 49e6938cc1SHelen Koike rkisp1_write(params->rkisp1, val & ~bit_mask, reg); 50e6938cc1SHelen Koike } 51e6938cc1SHelen Koike 52e6938cc1SHelen Koike /* ISP BP interface function */ 53e6938cc1SHelen Koike static void rkisp1_dpcc_config(struct rkisp1_params *params, 54e6938cc1SHelen Koike const struct rkisp1_cif_isp_dpcc_config *arg) 55e6938cc1SHelen Koike { 56e6938cc1SHelen Koike unsigned int i; 57e6938cc1SHelen Koike u32 mode; 58e6938cc1SHelen Koike 59e6938cc1SHelen Koike /* avoid to override the old enable value */ 60e6938cc1SHelen Koike mode = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_DPCC_MODE); 61e6938cc1SHelen Koike mode &= RKISP1_CIF_ISP_DPCC_ENA; 62e6938cc1SHelen Koike mode |= arg->mode & ~RKISP1_CIF_ISP_DPCC_ENA; 63e6938cc1SHelen Koike rkisp1_write(params->rkisp1, mode, RKISP1_CIF_ISP_DPCC_MODE); 64e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->output_mode, 65e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_OUTPUT_MODE); 66e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->set_use, 67e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_SET_USE); 68e6938cc1SHelen Koike 69e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[0].method, 70e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_METHODS_SET_1); 71e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[1].method, 72e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_METHODS_SET_2); 73e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[2].method, 74e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_METHODS_SET_3); 75e6938cc1SHelen Koike for (i = 0; i < RKISP1_CIF_ISP_DPCC_METHODS_MAX; i++) { 76e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[i].line_thresh, 77e6938cc1SHelen Koike RKISP1_ISP_DPCC_LINE_THRESH(i)); 78e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[i].line_mad_fac, 79e6938cc1SHelen Koike RKISP1_ISP_DPCC_LINE_MAD_FAC(i)); 80e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[i].pg_fac, 81e6938cc1SHelen Koike RKISP1_ISP_DPCC_PG_FAC(i)); 82e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[i].rnd_thresh, 83e6938cc1SHelen Koike RKISP1_ISP_DPCC_RND_THRESH(i)); 84e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->methods[i].rg_fac, 85e6938cc1SHelen Koike RKISP1_ISP_DPCC_RG_FAC(i)); 86e6938cc1SHelen Koike } 87e6938cc1SHelen Koike 88e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->rnd_offs, 89e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_RND_OFFS); 90e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->ro_limits, 91e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_RO_LIMITS); 92e6938cc1SHelen Koike } 93e6938cc1SHelen Koike 94e6938cc1SHelen Koike /* ISP black level subtraction interface function */ 95e6938cc1SHelen Koike static void rkisp1_bls_config(struct rkisp1_params *params, 96e6938cc1SHelen Koike const struct rkisp1_cif_isp_bls_config *arg) 97e6938cc1SHelen Koike { 98e6938cc1SHelen Koike /* avoid to override the old enable value */ 99e6938cc1SHelen Koike u32 new_control; 100e6938cc1SHelen Koike 101e6938cc1SHelen Koike new_control = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_BLS_CTRL); 102e6938cc1SHelen Koike new_control &= RKISP1_CIF_ISP_BLS_ENA; 103e6938cc1SHelen Koike /* fixed subtraction values */ 104e6938cc1SHelen Koike if (!arg->enable_auto) { 105e6938cc1SHelen Koike const struct rkisp1_cif_isp_bls_fixed_val *pval = 106e6938cc1SHelen Koike &arg->fixed_val; 107e6938cc1SHelen Koike 108e6938cc1SHelen Koike switch (params->raw_type) { 109e6938cc1SHelen Koike case RKISP1_RAW_BGGR: 110e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 111e6938cc1SHelen Koike pval->r, RKISP1_CIF_ISP_BLS_D_FIXED); 112e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 113e6938cc1SHelen Koike pval->gr, RKISP1_CIF_ISP_BLS_C_FIXED); 114e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 115e6938cc1SHelen Koike pval->gb, RKISP1_CIF_ISP_BLS_B_FIXED); 116e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 117e6938cc1SHelen Koike pval->b, RKISP1_CIF_ISP_BLS_A_FIXED); 118e6938cc1SHelen Koike break; 119e6938cc1SHelen Koike case RKISP1_RAW_GBRG: 120e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 121e6938cc1SHelen Koike pval->r, RKISP1_CIF_ISP_BLS_C_FIXED); 122e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 123e6938cc1SHelen Koike pval->gr, RKISP1_CIF_ISP_BLS_D_FIXED); 124e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 125e6938cc1SHelen Koike pval->gb, RKISP1_CIF_ISP_BLS_A_FIXED); 126e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 127e6938cc1SHelen Koike pval->b, RKISP1_CIF_ISP_BLS_B_FIXED); 128e6938cc1SHelen Koike break; 129e6938cc1SHelen Koike case RKISP1_RAW_GRBG: 130e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 131e6938cc1SHelen Koike pval->r, RKISP1_CIF_ISP_BLS_B_FIXED); 132e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 133e6938cc1SHelen Koike pval->gr, RKISP1_CIF_ISP_BLS_A_FIXED); 134e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 135e6938cc1SHelen Koike pval->gb, RKISP1_CIF_ISP_BLS_D_FIXED); 136e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 137e6938cc1SHelen Koike pval->b, RKISP1_CIF_ISP_BLS_C_FIXED); 138e6938cc1SHelen Koike break; 139e6938cc1SHelen Koike case RKISP1_RAW_RGGB: 140e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 141e6938cc1SHelen Koike pval->r, RKISP1_CIF_ISP_BLS_A_FIXED); 142e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 143e6938cc1SHelen Koike pval->gr, RKISP1_CIF_ISP_BLS_B_FIXED); 144e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 145e6938cc1SHelen Koike pval->gb, RKISP1_CIF_ISP_BLS_C_FIXED); 146e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 147e6938cc1SHelen Koike pval->b, RKISP1_CIF_ISP_BLS_D_FIXED); 148e6938cc1SHelen Koike break; 149e6938cc1SHelen Koike default: 150e6938cc1SHelen Koike break; 151e6938cc1SHelen Koike } 152e6938cc1SHelen Koike 153e6938cc1SHelen Koike } else { 154e6938cc1SHelen Koike if (arg->en_windows & BIT(1)) { 155e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window2.h_offs, 156e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_H2_START); 157e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window2.h_size, 158e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_H2_STOP); 159e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window2.v_offs, 160e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_V2_START); 161e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window2.v_size, 162e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_V2_STOP); 163e6938cc1SHelen Koike new_control |= RKISP1_CIF_ISP_BLS_WINDOW_2; 164e6938cc1SHelen Koike } 165e6938cc1SHelen Koike 166e6938cc1SHelen Koike if (arg->en_windows & BIT(0)) { 167e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window1.h_offs, 168e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_H1_START); 169e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window1.h_size, 170e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_H1_STOP); 171e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window1.v_offs, 172e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_V1_START); 173e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_window1.v_size, 174e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_V1_STOP); 175e6938cc1SHelen Koike new_control |= RKISP1_CIF_ISP_BLS_WINDOW_1; 176e6938cc1SHelen Koike } 177e6938cc1SHelen Koike 178e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->bls_samples, 179e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_SAMPLES); 180e6938cc1SHelen Koike 181e6938cc1SHelen Koike new_control |= RKISP1_CIF_ISP_BLS_MODE_MEASURED; 182e6938cc1SHelen Koike } 183e6938cc1SHelen Koike rkisp1_write(params->rkisp1, new_control, RKISP1_CIF_ISP_BLS_CTRL); 184e6938cc1SHelen Koike } 185e6938cc1SHelen Koike 186e6938cc1SHelen Koike /* ISP LS correction interface function */ 187e6938cc1SHelen Koike static void 188*dce8ccb2SHeiko Stuebner rkisp1_lsc_matrix_config_v10(struct rkisp1_params *params, 189e6938cc1SHelen Koike const struct rkisp1_cif_isp_lsc_config *pconfig) 190e6938cc1SHelen Koike { 191e6938cc1SHelen Koike unsigned int isp_lsc_status, sram_addr, isp_lsc_table_sel, i, j, data; 192e6938cc1SHelen Koike 193e6938cc1SHelen Koike isp_lsc_status = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_LSC_STATUS); 194e6938cc1SHelen Koike 195e6938cc1SHelen Koike /* RKISP1_CIF_ISP_LSC_TABLE_ADDRESS_153 = ( 17 * 18 ) >> 1 */ 196e6938cc1SHelen Koike sram_addr = (isp_lsc_status & RKISP1_CIF_ISP_LSC_ACTIVE_TABLE) ? 197e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_TABLE_ADDRESS_0 : 198e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_TABLE_ADDRESS_153; 199e6938cc1SHelen Koike rkisp1_write(params->rkisp1, sram_addr, 200e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_R_TABLE_ADDR); 201e6938cc1SHelen Koike rkisp1_write(params->rkisp1, sram_addr, 202e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_GR_TABLE_ADDR); 203e6938cc1SHelen Koike rkisp1_write(params->rkisp1, sram_addr, 204e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_GB_TABLE_ADDR); 205e6938cc1SHelen Koike rkisp1_write(params->rkisp1, sram_addr, 206e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_B_TABLE_ADDR); 207e6938cc1SHelen Koike 208e6938cc1SHelen Koike /* program data tables (table size is 9 * 17 = 153) */ 209e6938cc1SHelen Koike for (i = 0; i < RKISP1_CIF_ISP_LSC_SAMPLES_MAX; i++) { 210e6938cc1SHelen Koike /* 211e6938cc1SHelen Koike * 17 sectors with 2 values in one DWORD = 9 212e6938cc1SHelen Koike * DWORDs (2nd value of last DWORD unused) 213e6938cc1SHelen Koike */ 214e6938cc1SHelen Koike for (j = 0; j < RKISP1_CIF_ISP_LSC_SAMPLES_MAX - 1; j += 2) { 215*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->r_data_tbl[i][j], 216e6938cc1SHelen Koike pconfig->r_data_tbl[i][j + 1]); 217e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 218e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_R_TABLE_DATA); 219e6938cc1SHelen Koike 220*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->gr_data_tbl[i][j], 221e6938cc1SHelen Koike pconfig->gr_data_tbl[i][j + 1]); 222e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 223e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_GR_TABLE_DATA); 224e6938cc1SHelen Koike 225*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->gb_data_tbl[i][j], 226e6938cc1SHelen Koike pconfig->gb_data_tbl[i][j + 1]); 227e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 228e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_GB_TABLE_DATA); 229e6938cc1SHelen Koike 230*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->b_data_tbl[i][j], 231e6938cc1SHelen Koike pconfig->b_data_tbl[i][j + 1]); 232e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 233e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_B_TABLE_DATA); 234e6938cc1SHelen Koike } 235*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->r_data_tbl[i][j], 0); 236e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 237e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_R_TABLE_DATA); 238e6938cc1SHelen Koike 239*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->gr_data_tbl[i][j], 0); 240e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 241e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_GR_TABLE_DATA); 242e6938cc1SHelen Koike 243*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->gb_data_tbl[i][j], 0); 244e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 245e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_GB_TABLE_DATA); 246e6938cc1SHelen Koike 247*dce8ccb2SHeiko Stuebner data = RKISP1_CIF_ISP_LSC_TABLE_DATA_V10(pconfig->b_data_tbl[i][j], 0); 248e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 249e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_B_TABLE_DATA); 250e6938cc1SHelen Koike } 251e6938cc1SHelen Koike isp_lsc_table_sel = (isp_lsc_status & RKISP1_CIF_ISP_LSC_ACTIVE_TABLE) ? 252e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_TABLE_0 : 253e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_TABLE_1; 254e6938cc1SHelen Koike rkisp1_write(params->rkisp1, isp_lsc_table_sel, 255e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_TABLE_SEL); 256e6938cc1SHelen Koike } 257e6938cc1SHelen Koike 258e6938cc1SHelen Koike static void rkisp1_lsc_config(struct rkisp1_params *params, 259e6938cc1SHelen Koike const struct rkisp1_cif_isp_lsc_config *arg) 260e6938cc1SHelen Koike { 261e6938cc1SHelen Koike unsigned int i, data; 262e6938cc1SHelen Koike u32 lsc_ctrl; 263e6938cc1SHelen Koike 264e6938cc1SHelen Koike /* To config must be off , store the current status firstly */ 265e6938cc1SHelen Koike lsc_ctrl = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_LSC_CTRL); 266e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_LSC_CTRL, 267e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL_ENA); 2685e8d9d72SHeiko Stuebner params->ops->lsc_matrix_config(params, arg); 269e6938cc1SHelen Koike 270e6938cc1SHelen Koike for (i = 0; i < RKISP1_CIF_ISP_LSC_SECTORS_TBL_SIZE / 2; i++) { 271e6938cc1SHelen Koike /* program x size tables */ 272e6938cc1SHelen Koike data = RKISP1_CIF_ISP_LSC_SECT_SIZE(arg->x_size_tbl[i * 2], 273e6938cc1SHelen Koike arg->x_size_tbl[i * 2 + 1]); 274e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 275e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_XSIZE_01 + i * 4); 276e6938cc1SHelen Koike 277e6938cc1SHelen Koike /* program x grad tables */ 278e6938cc1SHelen Koike data = RKISP1_CIF_ISP_LSC_SECT_SIZE(arg->x_grad_tbl[i * 2], 279e6938cc1SHelen Koike arg->x_grad_tbl[i * 2 + 1]); 280e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 281e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_XGRAD_01 + i * 4); 282e6938cc1SHelen Koike 283e6938cc1SHelen Koike /* program y size tables */ 284e6938cc1SHelen Koike data = RKISP1_CIF_ISP_LSC_SECT_SIZE(arg->y_size_tbl[i * 2], 285e6938cc1SHelen Koike arg->y_size_tbl[i * 2 + 1]); 286e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 287e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_YSIZE_01 + i * 4); 288e6938cc1SHelen Koike 289e6938cc1SHelen Koike /* program y grad tables */ 290e6938cc1SHelen Koike data = RKISP1_CIF_ISP_LSC_SECT_SIZE(arg->y_grad_tbl[i * 2], 291e6938cc1SHelen Koike arg->y_grad_tbl[i * 2 + 1]); 292e6938cc1SHelen Koike rkisp1_write(params->rkisp1, data, 293e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_YGRAD_01 + i * 4); 294e6938cc1SHelen Koike } 295e6938cc1SHelen Koike 296e6938cc1SHelen Koike /* restore the lsc ctrl status */ 297e6938cc1SHelen Koike if (lsc_ctrl & RKISP1_CIF_ISP_LSC_CTRL_ENA) { 298e6938cc1SHelen Koike rkisp1_param_set_bits(params, 299e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL, 300e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL_ENA); 301e6938cc1SHelen Koike } else { 302e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 303e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL, 304e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL_ENA); 305e6938cc1SHelen Koike } 306e6938cc1SHelen Koike } 307e6938cc1SHelen Koike 308e6938cc1SHelen Koike /* ISP Filtering function */ 309e6938cc1SHelen Koike static void rkisp1_flt_config(struct rkisp1_params *params, 310e6938cc1SHelen Koike const struct rkisp1_cif_isp_flt_config *arg) 311e6938cc1SHelen Koike { 312e6938cc1SHelen Koike u32 filt_mode; 313e6938cc1SHelen Koike 314e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 315e6938cc1SHelen Koike arg->thresh_bl0, RKISP1_CIF_ISP_FILT_THRESH_BL0); 316e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 317e6938cc1SHelen Koike arg->thresh_bl1, RKISP1_CIF_ISP_FILT_THRESH_BL1); 318e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 319e6938cc1SHelen Koike arg->thresh_sh0, RKISP1_CIF_ISP_FILT_THRESH_SH0); 320e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 321e6938cc1SHelen Koike arg->thresh_sh1, RKISP1_CIF_ISP_FILT_THRESH_SH1); 322e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->fac_bl0, RKISP1_CIF_ISP_FILT_FAC_BL0); 323e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->fac_bl1, RKISP1_CIF_ISP_FILT_FAC_BL1); 324e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->fac_mid, RKISP1_CIF_ISP_FILT_FAC_MID); 325e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->fac_sh0, RKISP1_CIF_ISP_FILT_FAC_SH0); 326e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->fac_sh1, RKISP1_CIF_ISP_FILT_FAC_SH1); 327e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 328e6938cc1SHelen Koike arg->lum_weight, RKISP1_CIF_ISP_FILT_LUM_WEIGHT); 329e6938cc1SHelen Koike 330e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 331e6938cc1SHelen Koike (arg->mode ? RKISP1_CIF_ISP_FLT_MODE_DNR : 0) | 332e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_CHROMA_V_MODE(arg->chr_v_mode) | 333e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_CHROMA_H_MODE(arg->chr_h_mode) | 334e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_GREEN_STAGE1(arg->grn_stage1), 335e6938cc1SHelen Koike RKISP1_CIF_ISP_FILT_MODE); 336e6938cc1SHelen Koike 337e6938cc1SHelen Koike /* avoid to override the old enable value */ 338e6938cc1SHelen Koike filt_mode = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_FILT_MODE); 339e6938cc1SHelen Koike filt_mode &= RKISP1_CIF_ISP_FLT_ENA; 340e6938cc1SHelen Koike if (arg->mode) 341e6938cc1SHelen Koike filt_mode |= RKISP1_CIF_ISP_FLT_MODE_DNR; 342e6938cc1SHelen Koike filt_mode |= RKISP1_CIF_ISP_FLT_CHROMA_V_MODE(arg->chr_v_mode) | 343e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_CHROMA_H_MODE(arg->chr_h_mode) | 344e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_GREEN_STAGE1(arg->grn_stage1); 345e6938cc1SHelen Koike rkisp1_write(params->rkisp1, filt_mode, RKISP1_CIF_ISP_FILT_MODE); 346e6938cc1SHelen Koike } 347e6938cc1SHelen Koike 348e6938cc1SHelen Koike /* ISP demosaic interface function */ 349e6938cc1SHelen Koike static int rkisp1_bdm_config(struct rkisp1_params *params, 350e6938cc1SHelen Koike const struct rkisp1_cif_isp_bdm_config *arg) 351e6938cc1SHelen Koike { 352e6938cc1SHelen Koike u32 bdm_th; 353e6938cc1SHelen Koike 354e6938cc1SHelen Koike /* avoid to override the old enable value */ 355e6938cc1SHelen Koike bdm_th = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_DEMOSAIC); 356e6938cc1SHelen Koike bdm_th &= RKISP1_CIF_ISP_DEMOSAIC_BYPASS; 357e6938cc1SHelen Koike bdm_th |= arg->demosaic_th & ~RKISP1_CIF_ISP_DEMOSAIC_BYPASS; 358e6938cc1SHelen Koike /* set demosaic threshold */ 359e6938cc1SHelen Koike rkisp1_write(params->rkisp1, bdm_th, RKISP1_CIF_ISP_DEMOSAIC); 360e6938cc1SHelen Koike return 0; 361e6938cc1SHelen Koike } 362e6938cc1SHelen Koike 363e6938cc1SHelen Koike /* ISP GAMMA correction interface function */ 364e6938cc1SHelen Koike static void rkisp1_sdg_config(struct rkisp1_params *params, 365e6938cc1SHelen Koike const struct rkisp1_cif_isp_sdg_config *arg) 366e6938cc1SHelen Koike { 367e6938cc1SHelen Koike unsigned int i; 368e6938cc1SHelen Koike 369e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 370e6938cc1SHelen Koike arg->xa_pnts.gamma_dx0, RKISP1_CIF_ISP_GAMMA_DX_LO); 371e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 372e6938cc1SHelen Koike arg->xa_pnts.gamma_dx1, RKISP1_CIF_ISP_GAMMA_DX_HI); 373e6938cc1SHelen Koike 374e6938cc1SHelen Koike for (i = 0; i < RKISP1_CIF_ISP_DEGAMMA_CURVE_SIZE; i++) { 375e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->curve_r.gamma_y[i], 376e6938cc1SHelen Koike RKISP1_CIF_ISP_GAMMA_R_Y0 + i * 4); 377e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->curve_g.gamma_y[i], 378e6938cc1SHelen Koike RKISP1_CIF_ISP_GAMMA_G_Y0 + i * 4); 379e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->curve_b.gamma_y[i], 380e6938cc1SHelen Koike RKISP1_CIF_ISP_GAMMA_B_Y0 + i * 4); 381e6938cc1SHelen Koike } 382e6938cc1SHelen Koike } 383e6938cc1SHelen Koike 384e6938cc1SHelen Koike /* ISP GAMMA correction interface function */ 385*dce8ccb2SHeiko Stuebner static void rkisp1_goc_config_v10(struct rkisp1_params *params, 386e6938cc1SHelen Koike const struct rkisp1_cif_isp_goc_config *arg) 387e6938cc1SHelen Koike { 388e6938cc1SHelen Koike unsigned int i; 389e6938cc1SHelen Koike 390e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, 391e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA); 392*dce8ccb2SHeiko Stuebner rkisp1_write(params->rkisp1, arg->mode, RKISP1_CIF_ISP_GAMMA_OUT_MODE_V10); 393e6938cc1SHelen Koike 394ef357e02SHeiko Stuebner for (i = 0; i < RKISP1_CIF_ISP_GAMMA_OUT_MAX_SAMPLES_V10; i++) 395e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->gamma_y[i], 396*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_GAMMA_OUT_Y_0_V10 + i * 4); 397e6938cc1SHelen Koike } 398e6938cc1SHelen Koike 399e6938cc1SHelen Koike /* ISP Cross Talk */ 400e6938cc1SHelen Koike static void rkisp1_ctk_config(struct rkisp1_params *params, 401e6938cc1SHelen Koike const struct rkisp1_cif_isp_ctk_config *arg) 402e6938cc1SHelen Koike { 403e6938cc1SHelen Koike unsigned int i, j, k = 0; 404e6938cc1SHelen Koike 405e6938cc1SHelen Koike for (i = 0; i < 3; i++) 406e6938cc1SHelen Koike for (j = 0; j < 3; j++) 407e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->coeff[i][j], 408e6938cc1SHelen Koike RKISP1_CIF_ISP_CT_COEFF_0 + 4 * k++); 409e6938cc1SHelen Koike for (i = 0; i < 3; i++) 410e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->ct_offset[i], 411e6938cc1SHelen Koike RKISP1_CIF_ISP_CT_OFFSET_R + i * 4); 412e6938cc1SHelen Koike } 413e6938cc1SHelen Koike 414e6938cc1SHelen Koike static void rkisp1_ctk_enable(struct rkisp1_params *params, bool en) 415e6938cc1SHelen Koike { 416e6938cc1SHelen Koike if (en) 417e6938cc1SHelen Koike return; 418e6938cc1SHelen Koike 419e6938cc1SHelen Koike /* Write back the default values. */ 420e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0x80, RKISP1_CIF_ISP_CT_COEFF_0); 421e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_COEFF_1); 422e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_COEFF_2); 423e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_COEFF_3); 424e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0x80, RKISP1_CIF_ISP_CT_COEFF_4); 425e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_COEFF_5); 426e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_COEFF_6); 427e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_COEFF_7); 428e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0x80, RKISP1_CIF_ISP_CT_COEFF_8); 429e6938cc1SHelen Koike 430e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_OFFSET_R); 431e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_OFFSET_G); 432e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 0, RKISP1_CIF_ISP_CT_OFFSET_B); 433e6938cc1SHelen Koike } 434e6938cc1SHelen Koike 435e6938cc1SHelen Koike /* ISP White Balance Mode */ 436*dce8ccb2SHeiko Stuebner static void rkisp1_awb_meas_config_v10(struct rkisp1_params *params, 437e6938cc1SHelen Koike const struct rkisp1_cif_isp_awb_meas_config *arg) 438e6938cc1SHelen Koike { 439e6938cc1SHelen Koike u32 reg_val = 0; 440e6938cc1SHelen Koike /* based on the mode,configure the awb module */ 441e6938cc1SHelen Koike if (arg->awb_mode == RKISP1_CIF_ISP_AWB_MODE_YCBCR) { 442e6938cc1SHelen Koike /* Reference Cb and Cr */ 443e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 444e6938cc1SHelen Koike RKISP1_CIF_ISP_AWB_REF_CR_SET(arg->awb_ref_cr) | 445*dce8ccb2SHeiko Stuebner arg->awb_ref_cb, RKISP1_CIF_ISP_AWB_REF_V10); 446e6938cc1SHelen Koike /* Yc Threshold */ 447e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 448e6938cc1SHelen Koike RKISP1_CIF_ISP_AWB_MAX_Y_SET(arg->max_y) | 449e6938cc1SHelen Koike RKISP1_CIF_ISP_AWB_MIN_Y_SET(arg->min_y) | 450e6938cc1SHelen Koike RKISP1_CIF_ISP_AWB_MAX_CS_SET(arg->max_csum) | 451*dce8ccb2SHeiko Stuebner arg->min_c, RKISP1_CIF_ISP_AWB_THRESH_V10); 452e6938cc1SHelen Koike } 453e6938cc1SHelen Koike 454*dce8ccb2SHeiko Stuebner reg_val = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_AWB_PROP_V10); 455e6938cc1SHelen Koike if (arg->enable_ymax_cmp) 456e6938cc1SHelen Koike reg_val |= RKISP1_CIF_ISP_AWB_YMAX_CMP_EN; 457e6938cc1SHelen Koike else 458e6938cc1SHelen Koike reg_val &= ~RKISP1_CIF_ISP_AWB_YMAX_CMP_EN; 459*dce8ccb2SHeiko Stuebner rkisp1_write(params->rkisp1, reg_val, RKISP1_CIF_ISP_AWB_PROP_V10); 460e6938cc1SHelen Koike 461e6938cc1SHelen Koike /* window offset */ 462e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 463*dce8ccb2SHeiko Stuebner arg->awb_wnd.v_offs, RKISP1_CIF_ISP_AWB_WND_V_OFFS_V10); 464e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 465*dce8ccb2SHeiko Stuebner arg->awb_wnd.h_offs, RKISP1_CIF_ISP_AWB_WND_H_OFFS_V10); 466e6938cc1SHelen Koike /* AWB window size */ 467e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 468*dce8ccb2SHeiko Stuebner arg->awb_wnd.v_size, RKISP1_CIF_ISP_AWB_WND_V_SIZE_V10); 469e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 470*dce8ccb2SHeiko Stuebner arg->awb_wnd.h_size, RKISP1_CIF_ISP_AWB_WND_H_SIZE_V10); 471e6938cc1SHelen Koike /* Number of frames */ 472e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 473*dce8ccb2SHeiko Stuebner arg->frames, RKISP1_CIF_ISP_AWB_FRAMES_V10); 474e6938cc1SHelen Koike } 475e6938cc1SHelen Koike 476e6938cc1SHelen Koike static void 477*dce8ccb2SHeiko Stuebner rkisp1_awb_meas_enable_v10(struct rkisp1_params *params, 478e6938cc1SHelen Koike const struct rkisp1_cif_isp_awb_meas_config *arg, 479e6938cc1SHelen Koike bool en) 480e6938cc1SHelen Koike { 481*dce8ccb2SHeiko Stuebner u32 reg_val = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_AWB_PROP_V10); 482e6938cc1SHelen Koike 483e6938cc1SHelen Koike /* switch off */ 484e6938cc1SHelen Koike reg_val &= RKISP1_CIF_ISP_AWB_MODE_MASK_NONE; 485e6938cc1SHelen Koike 486e6938cc1SHelen Koike if (en) { 487e6938cc1SHelen Koike if (arg->awb_mode == RKISP1_CIF_ISP_AWB_MODE_RGB) 488e6938cc1SHelen Koike reg_val |= RKISP1_CIF_ISP_AWB_MODE_RGB_EN; 489e6938cc1SHelen Koike else 490e6938cc1SHelen Koike reg_val |= RKISP1_CIF_ISP_AWB_MODE_YCBCR_EN; 491e6938cc1SHelen Koike 492*dce8ccb2SHeiko Stuebner rkisp1_write(params->rkisp1, reg_val, RKISP1_CIF_ISP_AWB_PROP_V10); 493e6938cc1SHelen Koike 494e6938cc1SHelen Koike /* Measurements require AWB block be active. */ 495e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_ISP_CTRL, 496e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_AWB_ENA); 497e6938cc1SHelen Koike } else { 498e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 499*dce8ccb2SHeiko Stuebner reg_val, RKISP1_CIF_ISP_AWB_PROP_V10); 500e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, 501e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_AWB_ENA); 502e6938cc1SHelen Koike } 503e6938cc1SHelen Koike } 504e6938cc1SHelen Koike 505e6938cc1SHelen Koike static void 506*dce8ccb2SHeiko Stuebner rkisp1_awb_gain_config_v10(struct rkisp1_params *params, 507e6938cc1SHelen Koike const struct rkisp1_cif_isp_awb_gain_config *arg) 508e6938cc1SHelen Koike { 509e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 510e6938cc1SHelen Koike RKISP1_CIF_ISP_AWB_GAIN_R_SET(arg->gain_green_r) | 511*dce8ccb2SHeiko Stuebner arg->gain_green_b, RKISP1_CIF_ISP_AWB_GAIN_G_V10); 512e6938cc1SHelen Koike 513e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 514e6938cc1SHelen Koike RKISP1_CIF_ISP_AWB_GAIN_R_SET(arg->gain_red) | 515*dce8ccb2SHeiko Stuebner arg->gain_blue, RKISP1_CIF_ISP_AWB_GAIN_RB_V10); 516e6938cc1SHelen Koike } 517e6938cc1SHelen Koike 518*dce8ccb2SHeiko Stuebner static void rkisp1_aec_config_v10(struct rkisp1_params *params, 519e6938cc1SHelen Koike const struct rkisp1_cif_isp_aec_config *arg) 520e6938cc1SHelen Koike { 521e6938cc1SHelen Koike unsigned int block_hsize, block_vsize; 522e6938cc1SHelen Koike u32 exp_ctrl; 523e6938cc1SHelen Koike 524e6938cc1SHelen Koike /* avoid to override the old enable value */ 525e6938cc1SHelen Koike exp_ctrl = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_EXP_CTRL); 526e6938cc1SHelen Koike exp_ctrl &= RKISP1_CIF_ISP_EXP_ENA; 527e6938cc1SHelen Koike if (arg->autostop) 528e6938cc1SHelen Koike exp_ctrl |= RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP; 529e6938cc1SHelen Koike if (arg->mode == RKISP1_CIF_ISP_EXP_MEASURING_MODE_1) 530e6938cc1SHelen Koike exp_ctrl |= RKISP1_CIF_ISP_EXP_CTRL_MEASMODE_1; 531e6938cc1SHelen Koike rkisp1_write(params->rkisp1, exp_ctrl, RKISP1_CIF_ISP_EXP_CTRL); 532e6938cc1SHelen Koike 533e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 534*dce8ccb2SHeiko Stuebner arg->meas_window.h_offs, RKISP1_CIF_ISP_EXP_H_OFFSET_V10); 535e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 536*dce8ccb2SHeiko Stuebner arg->meas_window.v_offs, RKISP1_CIF_ISP_EXP_V_OFFSET_V10); 537e6938cc1SHelen Koike 538e6938cc1SHelen Koike block_hsize = arg->meas_window.h_size / 539*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_EXP_COLUMN_NUM_V10 - 1; 540e6938cc1SHelen Koike block_vsize = arg->meas_window.v_size / 541*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_EXP_ROW_NUM_V10 - 1; 542e6938cc1SHelen Koike 543e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 544*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_EXP_H_SIZE_SET_V10(block_hsize), 545*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_EXP_H_SIZE_V10); 546e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 547*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_EXP_V_SIZE_SET_V10(block_vsize), 548*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_EXP_V_SIZE_V10); 549e6938cc1SHelen Koike } 550e6938cc1SHelen Koike 551e6938cc1SHelen Koike static void rkisp1_cproc_config(struct rkisp1_params *params, 552e6938cc1SHelen Koike const struct rkisp1_cif_isp_cproc_config *arg) 553e6938cc1SHelen Koike { 554e6938cc1SHelen Koike struct rkisp1_cif_isp_isp_other_cfg *cur_other_cfg = 555e6938cc1SHelen Koike container_of(arg, struct rkisp1_cif_isp_isp_other_cfg, cproc_config); 556e6938cc1SHelen Koike struct rkisp1_cif_isp_ie_config *cur_ie_config = 557e6938cc1SHelen Koike &cur_other_cfg->ie_config; 558e6938cc1SHelen Koike u32 effect = cur_ie_config->effect; 559e6938cc1SHelen Koike u32 quantization = params->quantization; 560e6938cc1SHelen Koike 561e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->contrast, RKISP1_CIF_C_PROC_CONTRAST); 562e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->hue, RKISP1_CIF_C_PROC_HUE); 563e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->sat, RKISP1_CIF_C_PROC_SATURATION); 564e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->brightness, 565e6938cc1SHelen Koike RKISP1_CIF_C_PROC_BRIGHTNESS); 566e6938cc1SHelen Koike 567e6938cc1SHelen Koike if (quantization != V4L2_QUANTIZATION_FULL_RANGE || 568e6938cc1SHelen Koike effect != V4L2_COLORFX_NONE) { 569e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_C_PROC_CTRL, 570e6938cc1SHelen Koike RKISP1_CIF_C_PROC_YOUT_FULL | 571e6938cc1SHelen Koike RKISP1_CIF_C_PROC_YIN_FULL | 572e6938cc1SHelen Koike RKISP1_CIF_C_PROC_COUT_FULL); 573e6938cc1SHelen Koike } else { 574e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_C_PROC_CTRL, 575e6938cc1SHelen Koike RKISP1_CIF_C_PROC_YOUT_FULL | 576e6938cc1SHelen Koike RKISP1_CIF_C_PROC_YIN_FULL | 577e6938cc1SHelen Koike RKISP1_CIF_C_PROC_COUT_FULL); 578e6938cc1SHelen Koike } 579e6938cc1SHelen Koike } 580e6938cc1SHelen Koike 581*dce8ccb2SHeiko Stuebner static void rkisp1_hst_config_v10(struct rkisp1_params *params, 582e6938cc1SHelen Koike const struct rkisp1_cif_isp_hst_config *arg) 583e6938cc1SHelen Koike { 584e6938cc1SHelen Koike unsigned int block_hsize, block_vsize; 585e6938cc1SHelen Koike static const u32 hist_weight_regs[] = { 586*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_WEIGHT_00TO30_V10, 587*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_WEIGHT_40TO21_V10, 588*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_WEIGHT_31TO12_V10, 589*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_WEIGHT_22TO03_V10, 590*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_WEIGHT_13TO43_V10, 591*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_WEIGHT_04TO34_V10, 592e6938cc1SHelen Koike }; 593e6938cc1SHelen Koike const u8 *weight; 594e6938cc1SHelen Koike unsigned int i; 595e6938cc1SHelen Koike u32 hist_prop; 596e6938cc1SHelen Koike 597e6938cc1SHelen Koike /* avoid to override the old enable value */ 598*dce8ccb2SHeiko Stuebner hist_prop = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_HIST_PROP_V10); 599*dce8ccb2SHeiko Stuebner hist_prop &= RKISP1_CIF_ISP_HIST_PROP_MODE_MASK_V10; 600*dce8ccb2SHeiko Stuebner hist_prop |= RKISP1_CIF_ISP_HIST_PREDIV_SET_V10(arg->histogram_predivider); 601*dce8ccb2SHeiko Stuebner rkisp1_write(params->rkisp1, hist_prop, RKISP1_CIF_ISP_HIST_PROP_V10); 602e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 603e6938cc1SHelen Koike arg->meas_window.h_offs, 604*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_H_OFFS_V10); 605e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 606e6938cc1SHelen Koike arg->meas_window.v_offs, 607*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_V_OFFS_V10); 608e6938cc1SHelen Koike 609e6938cc1SHelen Koike block_hsize = arg->meas_window.h_size / 610*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_COLUMN_NUM_V10 - 1; 611*dce8ccb2SHeiko Stuebner block_vsize = arg->meas_window.v_size / RKISP1_CIF_ISP_HIST_ROW_NUM_V10 - 1; 612e6938cc1SHelen Koike 613*dce8ccb2SHeiko Stuebner rkisp1_write(params->rkisp1, block_hsize, RKISP1_CIF_ISP_HIST_H_SIZE_V10); 614*dce8ccb2SHeiko Stuebner rkisp1_write(params->rkisp1, block_vsize, RKISP1_CIF_ISP_HIST_V_SIZE_V10); 615e6938cc1SHelen Koike 616e6938cc1SHelen Koike weight = arg->hist_weight; 617e6938cc1SHelen Koike for (i = 0; i < ARRAY_SIZE(hist_weight_regs); ++i, weight += 4) 618e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 619*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_WEIGHT_SET_V10(weight[0], 620e6938cc1SHelen Koike weight[1], 621e6938cc1SHelen Koike weight[2], 622e6938cc1SHelen Koike weight[3]), 623e6938cc1SHelen Koike hist_weight_regs[i]); 62466d81de7SHeiko Stuebner 625*dce8ccb2SHeiko Stuebner rkisp1_write(params->rkisp1, weight[0] & 0x1F, RKISP1_CIF_ISP_HIST_WEIGHT_44_V10); 626e6938cc1SHelen Koike } 627e6938cc1SHelen Koike 628e6938cc1SHelen Koike static void 629*dce8ccb2SHeiko Stuebner rkisp1_hst_enable_v10(struct rkisp1_params *params, 630e6938cc1SHelen Koike const struct rkisp1_cif_isp_hst_config *arg, bool en) 631e6938cc1SHelen Koike { 632e6938cc1SHelen Koike if (en) { 633e6938cc1SHelen Koike u32 hist_prop = rkisp1_read(params->rkisp1, 634*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_PROP_V10); 635e6938cc1SHelen Koike 636*dce8ccb2SHeiko Stuebner hist_prop &= ~RKISP1_CIF_ISP_HIST_PROP_MODE_MASK_V10; 637e6938cc1SHelen Koike hist_prop |= arg->mode; 638*dce8ccb2SHeiko Stuebner rkisp1_param_set_bits(params, RKISP1_CIF_ISP_HIST_PROP_V10, 639e6938cc1SHelen Koike hist_prop); 640e6938cc1SHelen Koike } else { 641*dce8ccb2SHeiko Stuebner rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_HIST_PROP_V10, 642*dce8ccb2SHeiko Stuebner RKISP1_CIF_ISP_HIST_PROP_MODE_MASK_V10); 643e6938cc1SHelen Koike } 644e6938cc1SHelen Koike } 645e6938cc1SHelen Koike 646*dce8ccb2SHeiko Stuebner static void rkisp1_afm_config_v10(struct rkisp1_params *params, 647e6938cc1SHelen Koike const struct rkisp1_cif_isp_afc_config *arg) 648e6938cc1SHelen Koike { 649e6938cc1SHelen Koike size_t num_of_win = min_t(size_t, ARRAY_SIZE(arg->afm_win), 650e6938cc1SHelen Koike arg->num_afm_win); 651e6938cc1SHelen Koike u32 afm_ctrl = rkisp1_read(params->rkisp1, RKISP1_CIF_ISP_AFM_CTRL); 652e6938cc1SHelen Koike unsigned int i; 653e6938cc1SHelen Koike 654e6938cc1SHelen Koike /* Switch off to configure. */ 655e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_AFM_CTRL, 656e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_ENA); 657e6938cc1SHelen Koike 658e6938cc1SHelen Koike for (i = 0; i < num_of_win; i++) { 659e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 660e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_WINDOW_X(arg->afm_win[i].h_offs) | 661e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_WINDOW_Y(arg->afm_win[i].v_offs), 662e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_LT_A + i * 8); 663e6938cc1SHelen Koike rkisp1_write(params->rkisp1, 664e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_WINDOW_X(arg->afm_win[i].h_size + 665e6938cc1SHelen Koike arg->afm_win[i].h_offs) | 666e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_WINDOW_Y(arg->afm_win[i].v_size + 667e6938cc1SHelen Koike arg->afm_win[i].v_offs), 668e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_RB_A + i * 8); 669e6938cc1SHelen Koike } 670e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->thres, RKISP1_CIF_ISP_AFM_THRES); 671e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->var_shift, 672e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_VAR_SHIFT); 673e6938cc1SHelen Koike /* restore afm status */ 674e6938cc1SHelen Koike rkisp1_write(params->rkisp1, afm_ctrl, RKISP1_CIF_ISP_AFM_CTRL); 675e6938cc1SHelen Koike } 676e6938cc1SHelen Koike 677e6938cc1SHelen Koike static void rkisp1_ie_config(struct rkisp1_params *params, 678e6938cc1SHelen Koike const struct rkisp1_cif_isp_ie_config *arg) 679e6938cc1SHelen Koike { 680e6938cc1SHelen Koike u32 eff_ctrl; 681e6938cc1SHelen Koike 682e6938cc1SHelen Koike eff_ctrl = rkisp1_read(params->rkisp1, RKISP1_CIF_IMG_EFF_CTRL); 683e6938cc1SHelen Koike eff_ctrl &= ~RKISP1_CIF_IMG_EFF_CTRL_MODE_MASK; 684e6938cc1SHelen Koike 685e6938cc1SHelen Koike if (params->quantization == V4L2_QUANTIZATION_FULL_RANGE) 686e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_YCBCR_FULL; 687e6938cc1SHelen Koike 688e6938cc1SHelen Koike switch (arg->effect) { 689e6938cc1SHelen Koike case V4L2_COLORFX_SEPIA: 690e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_MODE_SEPIA; 691e6938cc1SHelen Koike break; 692e6938cc1SHelen Koike case V4L2_COLORFX_SET_CBCR: 693e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->eff_tint, 694e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_TINT); 695e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_MODE_SEPIA; 696e6938cc1SHelen Koike break; 697e6938cc1SHelen Koike /* 698e6938cc1SHelen Koike * Color selection is similar to water color(AQUA): 699e6938cc1SHelen Koike * grayscale + selected color w threshold 700e6938cc1SHelen Koike */ 701e6938cc1SHelen Koike case V4L2_COLORFX_AQUA: 702e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_MODE_COLOR_SEL; 703e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->color_sel, 704e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_COLOR_SEL); 705e6938cc1SHelen Koike break; 706e6938cc1SHelen Koike case V4L2_COLORFX_EMBOSS: 707e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_MODE_EMBOSS; 708e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->eff_mat_1, 709e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_MAT_1); 710e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->eff_mat_2, 711e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_MAT_2); 712e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->eff_mat_3, 713e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_MAT_3); 714e6938cc1SHelen Koike break; 715e6938cc1SHelen Koike case V4L2_COLORFX_SKETCH: 716e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_MODE_SKETCH; 717e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->eff_mat_3, 718e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_MAT_3); 719e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->eff_mat_4, 720e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_MAT_4); 721e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->eff_mat_5, 722e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_MAT_5); 723e6938cc1SHelen Koike break; 724e6938cc1SHelen Koike case V4L2_COLORFX_BW: 725e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_MODE_BLACKWHITE; 726e6938cc1SHelen Koike break; 727e6938cc1SHelen Koike case V4L2_COLORFX_NEGATIVE: 728e6938cc1SHelen Koike eff_ctrl |= RKISP1_CIF_IMG_EFF_CTRL_MODE_NEGATIVE; 729e6938cc1SHelen Koike break; 730e6938cc1SHelen Koike default: 731e6938cc1SHelen Koike break; 732e6938cc1SHelen Koike } 733e6938cc1SHelen Koike 734e6938cc1SHelen Koike rkisp1_write(params->rkisp1, eff_ctrl, RKISP1_CIF_IMG_EFF_CTRL); 735e6938cc1SHelen Koike } 736e6938cc1SHelen Koike 737e6938cc1SHelen Koike static void rkisp1_ie_enable(struct rkisp1_params *params, bool en) 738e6938cc1SHelen Koike { 739e6938cc1SHelen Koike if (en) { 740e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_ICCL, 741e6938cc1SHelen Koike RKISP1_CIF_ICCL_IE_CLK); 742e6938cc1SHelen Koike rkisp1_write(params->rkisp1, RKISP1_CIF_IMG_EFF_CTRL_ENABLE, 743e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_CTRL); 744e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_IMG_EFF_CTRL, 745e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_CTRL_CFG_UPD); 746e6938cc1SHelen Koike } else { 747e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_IMG_EFF_CTRL, 748e6938cc1SHelen Koike RKISP1_CIF_IMG_EFF_CTRL_ENABLE); 749e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ICCL, 750e6938cc1SHelen Koike RKISP1_CIF_ICCL_IE_CLK); 751e6938cc1SHelen Koike } 752e6938cc1SHelen Koike } 753e6938cc1SHelen Koike 754e6938cc1SHelen Koike static void rkisp1_csm_config(struct rkisp1_params *params, bool full_range) 755e6938cc1SHelen Koike { 756e6938cc1SHelen Koike static const u16 full_range_coeff[] = { 757e6938cc1SHelen Koike 0x0026, 0x004b, 0x000f, 758e6938cc1SHelen Koike 0x01ea, 0x01d6, 0x0040, 759e6938cc1SHelen Koike 0x0040, 0x01ca, 0x01f6 760e6938cc1SHelen Koike }; 761e6938cc1SHelen Koike static const u16 limited_range_coeff[] = { 762e6938cc1SHelen Koike 0x0021, 0x0040, 0x000d, 763e6938cc1SHelen Koike 0x01ed, 0x01db, 0x0038, 764e6938cc1SHelen Koike 0x0038, 0x01d1, 0x01f7, 765e6938cc1SHelen Koike }; 766e6938cc1SHelen Koike unsigned int i; 767e6938cc1SHelen Koike 768e6938cc1SHelen Koike if (full_range) { 769e6938cc1SHelen Koike for (i = 0; i < ARRAY_SIZE(full_range_coeff); i++) 770e6938cc1SHelen Koike rkisp1_write(params->rkisp1, full_range_coeff[i], 771e6938cc1SHelen Koike RKISP1_CIF_ISP_CC_COEFF_0 + i * 4); 772e6938cc1SHelen Koike 773e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_ISP_CTRL, 774e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_CSM_Y_FULL_ENA | 775e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_CSM_C_FULL_ENA); 776e6938cc1SHelen Koike } else { 777e6938cc1SHelen Koike for (i = 0; i < ARRAY_SIZE(limited_range_coeff); i++) 778e6938cc1SHelen Koike rkisp1_write(params->rkisp1, limited_range_coeff[i], 779e6938cc1SHelen Koike RKISP1_CIF_ISP_CC_COEFF_0 + i * 4); 780e6938cc1SHelen Koike 781e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, 782e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_CSM_Y_FULL_ENA | 783e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_CSM_C_FULL_ENA); 784e6938cc1SHelen Koike } 785e6938cc1SHelen Koike } 786e6938cc1SHelen Koike 787e6938cc1SHelen Koike /* ISP De-noise Pre-Filter(DPF) function */ 788e6938cc1SHelen Koike static void rkisp1_dpf_config(struct rkisp1_params *params, 789e6938cc1SHelen Koike const struct rkisp1_cif_isp_dpf_config *arg) 790e6938cc1SHelen Koike { 791e6938cc1SHelen Koike unsigned int isp_dpf_mode, spatial_coeff, i; 792e6938cc1SHelen Koike 793e6938cc1SHelen Koike switch (arg->gain.mode) { 794e6938cc1SHelen Koike case RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_GAINS: 795e6938cc1SHelen Koike isp_dpf_mode = RKISP1_CIF_ISP_DPF_MODE_USE_NF_GAIN | 796e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE_AWB_GAIN_COMP; 797e6938cc1SHelen Koike break; 798e6938cc1SHelen Koike case RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS: 799e6938cc1SHelen Koike isp_dpf_mode = RKISP1_CIF_ISP_DPF_MODE_LSC_GAIN_COMP; 800e6938cc1SHelen Koike break; 801e6938cc1SHelen Koike case RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_LSC_GAINS: 802e6938cc1SHelen Koike isp_dpf_mode = RKISP1_CIF_ISP_DPF_MODE_USE_NF_GAIN | 803e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE_AWB_GAIN_COMP | 804e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE_LSC_GAIN_COMP; 805e6938cc1SHelen Koike break; 806e6938cc1SHelen Koike case RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS: 807e6938cc1SHelen Koike isp_dpf_mode = RKISP1_CIF_ISP_DPF_MODE_AWB_GAIN_COMP; 808e6938cc1SHelen Koike break; 809e6938cc1SHelen Koike case RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS: 810e6938cc1SHelen Koike isp_dpf_mode = RKISP1_CIF_ISP_DPF_MODE_LSC_GAIN_COMP | 811e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE_AWB_GAIN_COMP; 812e6938cc1SHelen Koike break; 813e6938cc1SHelen Koike case RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED: 814e6938cc1SHelen Koike default: 815e6938cc1SHelen Koike isp_dpf_mode = 0; 816e6938cc1SHelen Koike break; 817e6938cc1SHelen Koike } 818e6938cc1SHelen Koike 819e6938cc1SHelen Koike if (arg->nll.scale_mode == RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC) 820e6938cc1SHelen Koike isp_dpf_mode |= RKISP1_CIF_ISP_DPF_MODE_NLL_SEGMENTATION; 821e6938cc1SHelen Koike if (arg->rb_flt.fltsize == RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9) 822e6938cc1SHelen Koike isp_dpf_mode |= RKISP1_CIF_ISP_DPF_MODE_RB_FLTSIZE_9x9; 823e6938cc1SHelen Koike if (!arg->rb_flt.r_enable) 824e6938cc1SHelen Koike isp_dpf_mode |= RKISP1_CIF_ISP_DPF_MODE_R_FLT_DIS; 825e6938cc1SHelen Koike if (!arg->rb_flt.b_enable) 826e6938cc1SHelen Koike isp_dpf_mode |= RKISP1_CIF_ISP_DPF_MODE_B_FLT_DIS; 827e6938cc1SHelen Koike if (!arg->g_flt.gb_enable) 828e6938cc1SHelen Koike isp_dpf_mode |= RKISP1_CIF_ISP_DPF_MODE_GB_FLT_DIS; 829e6938cc1SHelen Koike if (!arg->g_flt.gr_enable) 830e6938cc1SHelen Koike isp_dpf_mode |= RKISP1_CIF_ISP_DPF_MODE_GR_FLT_DIS; 831e6938cc1SHelen Koike 832e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_ISP_DPF_MODE, 833e6938cc1SHelen Koike isp_dpf_mode); 834e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->gain.nf_b_gain, 835e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_NF_GAIN_B); 836e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->gain.nf_r_gain, 837e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_NF_GAIN_R); 838e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->gain.nf_gb_gain, 839e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_NF_GAIN_GB); 840e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->gain.nf_gr_gain, 841e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_NF_GAIN_GR); 842e6938cc1SHelen Koike 843e6938cc1SHelen Koike for (i = 0; i < RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS; i++) { 844e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->nll.coeff[i], 845e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_NULL_COEFF_0 + i * 4); 846e6938cc1SHelen Koike } 847e6938cc1SHelen Koike 848e6938cc1SHelen Koike spatial_coeff = arg->g_flt.spatial_coeff[0] | 849e6938cc1SHelen Koike (arg->g_flt.spatial_coeff[1] << 8) | 850e6938cc1SHelen Koike (arg->g_flt.spatial_coeff[2] << 16) | 851e6938cc1SHelen Koike (arg->g_flt.spatial_coeff[3] << 24); 852e6938cc1SHelen Koike rkisp1_write(params->rkisp1, spatial_coeff, 853e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_S_WEIGHT_G_1_4); 854e6938cc1SHelen Koike 855e6938cc1SHelen Koike spatial_coeff = arg->g_flt.spatial_coeff[4] | 856e6938cc1SHelen Koike (arg->g_flt.spatial_coeff[5] << 8); 857e6938cc1SHelen Koike rkisp1_write(params->rkisp1, spatial_coeff, 858e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_S_WEIGHT_G_5_6); 859e6938cc1SHelen Koike 860e6938cc1SHelen Koike spatial_coeff = arg->rb_flt.spatial_coeff[0] | 861e6938cc1SHelen Koike (arg->rb_flt.spatial_coeff[1] << 8) | 862e6938cc1SHelen Koike (arg->rb_flt.spatial_coeff[2] << 16) | 863e6938cc1SHelen Koike (arg->rb_flt.spatial_coeff[3] << 24); 864e6938cc1SHelen Koike rkisp1_write(params->rkisp1, spatial_coeff, 865e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_S_WEIGHT_RB_1_4); 866e6938cc1SHelen Koike 867e6938cc1SHelen Koike spatial_coeff = arg->rb_flt.spatial_coeff[4] | 868e6938cc1SHelen Koike (arg->rb_flt.spatial_coeff[5] << 8); 869e6938cc1SHelen Koike rkisp1_write(params->rkisp1, spatial_coeff, 870e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_S_WEIGHT_RB_5_6); 871e6938cc1SHelen Koike } 872e6938cc1SHelen Koike 873e6938cc1SHelen Koike static void 874e6938cc1SHelen Koike rkisp1_dpf_strength_config(struct rkisp1_params *params, 875e6938cc1SHelen Koike const struct rkisp1_cif_isp_dpf_strength_config *arg) 876e6938cc1SHelen Koike { 877e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->b, RKISP1_CIF_ISP_DPF_STRENGTH_B); 878e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->g, RKISP1_CIF_ISP_DPF_STRENGTH_G); 879e6938cc1SHelen Koike rkisp1_write(params->rkisp1, arg->r, RKISP1_CIF_ISP_DPF_STRENGTH_R); 880e6938cc1SHelen Koike } 881e6938cc1SHelen Koike 882e6938cc1SHelen Koike static void 883e6938cc1SHelen Koike rkisp1_isp_isr_other_config(struct rkisp1_params *params, 884e6938cc1SHelen Koike const struct rkisp1_params_cfg *new_params) 885e6938cc1SHelen Koike { 886e6938cc1SHelen Koike unsigned int module_en_update, module_cfg_update, module_ens; 887e6938cc1SHelen Koike 888e6938cc1SHelen Koike module_en_update = new_params->module_en_update; 889e6938cc1SHelen Koike module_cfg_update = new_params->module_cfg_update; 890e6938cc1SHelen Koike module_ens = new_params->module_ens; 891e6938cc1SHelen Koike 892e6938cc1SHelen Koike /* update dpc config */ 893e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_DPCC) 894e6938cc1SHelen Koike rkisp1_dpcc_config(params, 895e6938cc1SHelen Koike &new_params->others.dpcc_config); 896e6938cc1SHelen Koike 897e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_DPCC) { 898e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_DPCC) 899e6938cc1SHelen Koike rkisp1_param_set_bits(params, 900e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_MODE, 901e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_ENA); 902e6938cc1SHelen Koike else 903e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 904e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_MODE, 905e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_ENA); 906e6938cc1SHelen Koike } 907e6938cc1SHelen Koike 908e6938cc1SHelen Koike /* update bls config */ 909e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_BLS) 910e6938cc1SHelen Koike rkisp1_bls_config(params, 911e6938cc1SHelen Koike &new_params->others.bls_config); 912e6938cc1SHelen Koike 913e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_BLS) { 914e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_BLS) 915e6938cc1SHelen Koike rkisp1_param_set_bits(params, 916e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_CTRL, 917e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_ENA); 918e6938cc1SHelen Koike else 919e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 920e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_CTRL, 921e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_ENA); 922e6938cc1SHelen Koike } 923e6938cc1SHelen Koike 924e6938cc1SHelen Koike /* update sdg config */ 925e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_SDG) 926e6938cc1SHelen Koike rkisp1_sdg_config(params, 927e6938cc1SHelen Koike &new_params->others.sdg_config); 928e6938cc1SHelen Koike 929e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_SDG) { 930e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_SDG) 931e6938cc1SHelen Koike rkisp1_param_set_bits(params, 932e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL, 933e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_GAMMA_IN_ENA); 934e6938cc1SHelen Koike else 935e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 936e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL, 937e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_GAMMA_IN_ENA); 938e6938cc1SHelen Koike } 939e6938cc1SHelen Koike 940e6938cc1SHelen Koike /* update lsc config */ 941e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_LSC) 942e6938cc1SHelen Koike rkisp1_lsc_config(params, 943e6938cc1SHelen Koike &new_params->others.lsc_config); 944e6938cc1SHelen Koike 945e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_LSC) { 946e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_LSC) 947e6938cc1SHelen Koike rkisp1_param_set_bits(params, 948e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL, 949e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL_ENA); 950e6938cc1SHelen Koike else 951e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 952e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL, 953e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL_ENA); 954e6938cc1SHelen Koike } 955e6938cc1SHelen Koike 956e6938cc1SHelen Koike /* update awb gains */ 957e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_AWB_GAIN) 9585e8d9d72SHeiko Stuebner params->ops->awb_gain_config(params, &new_params->others.awb_gain_config); 959e6938cc1SHelen Koike 960e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_AWB_GAIN) { 961e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_AWB_GAIN) 962e6938cc1SHelen Koike rkisp1_param_set_bits(params, 963e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL, 964e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_AWB_ENA); 965e6938cc1SHelen Koike else 966e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 967e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL, 968e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_AWB_ENA); 969e6938cc1SHelen Koike } 970e6938cc1SHelen Koike 971e6938cc1SHelen Koike /* update bdm config */ 972e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_BDM) 973e6938cc1SHelen Koike rkisp1_bdm_config(params, 974e6938cc1SHelen Koike &new_params->others.bdm_config); 975e6938cc1SHelen Koike 976e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_BDM) { 977e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_BDM) 978e6938cc1SHelen Koike rkisp1_param_set_bits(params, 979e6938cc1SHelen Koike RKISP1_CIF_ISP_DEMOSAIC, 980e6938cc1SHelen Koike RKISP1_CIF_ISP_DEMOSAIC_BYPASS); 981e6938cc1SHelen Koike else 982e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 983e6938cc1SHelen Koike RKISP1_CIF_ISP_DEMOSAIC, 984e6938cc1SHelen Koike RKISP1_CIF_ISP_DEMOSAIC_BYPASS); 985e6938cc1SHelen Koike } 986e6938cc1SHelen Koike 987e6938cc1SHelen Koike /* update filter config */ 988e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_FLT) 989e6938cc1SHelen Koike rkisp1_flt_config(params, 990e6938cc1SHelen Koike &new_params->others.flt_config); 991e6938cc1SHelen Koike 992e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_FLT) { 993e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_FLT) 994e6938cc1SHelen Koike rkisp1_param_set_bits(params, 995e6938cc1SHelen Koike RKISP1_CIF_ISP_FILT_MODE, 996e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_ENA); 997e6938cc1SHelen Koike else 998e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 999e6938cc1SHelen Koike RKISP1_CIF_ISP_FILT_MODE, 1000e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_ENA); 1001e6938cc1SHelen Koike } 1002e6938cc1SHelen Koike 1003e6938cc1SHelen Koike /* update ctk config */ 1004e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_CTK) 1005e6938cc1SHelen Koike rkisp1_ctk_config(params, 1006e6938cc1SHelen Koike &new_params->others.ctk_config); 1007e6938cc1SHelen Koike 1008e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_CTK) 100918a4ca76SDafna Hirschfeld rkisp1_ctk_enable(params, !!(module_ens & RKISP1_CIF_ISP_MODULE_CTK)); 1010e6938cc1SHelen Koike 1011e6938cc1SHelen Koike /* update goc config */ 1012e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_GOC) 10135e8d9d72SHeiko Stuebner params->ops->goc_config(params, &new_params->others.goc_config); 1014e6938cc1SHelen Koike 1015e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_GOC) { 1016e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_GOC) 1017e6938cc1SHelen Koike rkisp1_param_set_bits(params, 1018e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL, 1019e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA); 1020e6938cc1SHelen Koike else 1021e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 1022e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL, 1023e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA); 1024e6938cc1SHelen Koike } 1025e6938cc1SHelen Koike 1026e6938cc1SHelen Koike /* update cproc config */ 102718a4ca76SDafna Hirschfeld if (module_cfg_update & RKISP1_CIF_ISP_MODULE_CPROC) 1028e6938cc1SHelen Koike rkisp1_cproc_config(params, 1029e6938cc1SHelen Koike &new_params->others.cproc_config); 1030e6938cc1SHelen Koike 1031e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_CPROC) { 1032e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_CPROC) 1033e6938cc1SHelen Koike rkisp1_param_set_bits(params, 1034e6938cc1SHelen Koike RKISP1_CIF_C_PROC_CTRL, 1035e6938cc1SHelen Koike RKISP1_CIF_C_PROC_CTR_ENABLE); 1036e6938cc1SHelen Koike else 1037e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 1038e6938cc1SHelen Koike RKISP1_CIF_C_PROC_CTRL, 1039e6938cc1SHelen Koike RKISP1_CIF_C_PROC_CTR_ENABLE); 1040e6938cc1SHelen Koike } 1041e6938cc1SHelen Koike 1042e6938cc1SHelen Koike /* update ie config */ 1043e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_IE) 104418a4ca76SDafna Hirschfeld rkisp1_ie_config(params, &new_params->others.ie_config); 1045e6938cc1SHelen Koike 1046e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_IE) 104718a4ca76SDafna Hirschfeld rkisp1_ie_enable(params, !!(module_ens & RKISP1_CIF_ISP_MODULE_IE)); 1048e6938cc1SHelen Koike 1049e6938cc1SHelen Koike /* update dpf config */ 1050e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_DPF) 105118a4ca76SDafna Hirschfeld rkisp1_dpf_config(params, &new_params->others.dpf_config); 1052e6938cc1SHelen Koike 1053e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_DPF) { 1054e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_DPF) 1055e6938cc1SHelen Koike rkisp1_param_set_bits(params, 1056e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE, 1057e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE_EN); 1058e6938cc1SHelen Koike else 1059e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 1060e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE, 1061e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE_EN); 1062e6938cc1SHelen Koike } 1063e6938cc1SHelen Koike 1064e6938cc1SHelen Koike if ((module_en_update & RKISP1_CIF_ISP_MODULE_DPF_STRENGTH) || 1065e6938cc1SHelen Koike (module_cfg_update & RKISP1_CIF_ISP_MODULE_DPF_STRENGTH)) { 1066e6938cc1SHelen Koike /* update dpf strength config */ 1067e6938cc1SHelen Koike rkisp1_dpf_strength_config(params, 1068e6938cc1SHelen Koike &new_params->others.dpf_strength_config); 1069e6938cc1SHelen Koike } 1070e6938cc1SHelen Koike } 1071e6938cc1SHelen Koike 1072e6938cc1SHelen Koike static void rkisp1_isp_isr_meas_config(struct rkisp1_params *params, 1073e6938cc1SHelen Koike struct rkisp1_params_cfg *new_params) 1074e6938cc1SHelen Koike { 1075e6938cc1SHelen Koike unsigned int module_en_update, module_cfg_update, module_ens; 1076e6938cc1SHelen Koike 1077e6938cc1SHelen Koike module_en_update = new_params->module_en_update; 1078e6938cc1SHelen Koike module_cfg_update = new_params->module_cfg_update; 1079e6938cc1SHelen Koike module_ens = new_params->module_ens; 1080e6938cc1SHelen Koike 1081e6938cc1SHelen Koike /* update awb config */ 1082e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_AWB) 10835e8d9d72SHeiko Stuebner params->ops->awb_meas_config(params, &new_params->meas.awb_meas_config); 1084e6938cc1SHelen Koike 1085e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_AWB) 10865e8d9d72SHeiko Stuebner params->ops->awb_meas_enable(params, 1087e6938cc1SHelen Koike &new_params->meas.awb_meas_config, 1088e6938cc1SHelen Koike !!(module_ens & RKISP1_CIF_ISP_MODULE_AWB)); 1089e6938cc1SHelen Koike 1090e6938cc1SHelen Koike /* update afc config */ 1091e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_AFC) 10925e8d9d72SHeiko Stuebner params->ops->afm_config(params, 1093e6938cc1SHelen Koike &new_params->meas.afc_config); 1094e6938cc1SHelen Koike 1095e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_AFC) { 1096e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_AFC) 1097e6938cc1SHelen Koike rkisp1_param_set_bits(params, 1098e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_CTRL, 1099e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_ENA); 1100e6938cc1SHelen Koike else 1101e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 1102e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_CTRL, 1103e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_ENA); 1104e6938cc1SHelen Koike } 1105e6938cc1SHelen Koike 1106e6938cc1SHelen Koike /* update hst config */ 1107e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_HST) 11085e8d9d72SHeiko Stuebner params->ops->hst_config(params, 1109e6938cc1SHelen Koike &new_params->meas.hst_config); 1110e6938cc1SHelen Koike 1111e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_HST) 11125e8d9d72SHeiko Stuebner params->ops->hst_enable(params, 1113e6938cc1SHelen Koike &new_params->meas.hst_config, 1114e6938cc1SHelen Koike !!(module_ens & RKISP1_CIF_ISP_MODULE_HST)); 1115e6938cc1SHelen Koike 1116e6938cc1SHelen Koike /* update aec config */ 1117e6938cc1SHelen Koike if (module_cfg_update & RKISP1_CIF_ISP_MODULE_AEC) 11185e8d9d72SHeiko Stuebner params->ops->aec_config(params, 1119e6938cc1SHelen Koike &new_params->meas.aec_config); 1120e6938cc1SHelen Koike 1121e6938cc1SHelen Koike if (module_en_update & RKISP1_CIF_ISP_MODULE_AEC) { 1122e6938cc1SHelen Koike if (module_ens & RKISP1_CIF_ISP_MODULE_AEC) 1123e6938cc1SHelen Koike rkisp1_param_set_bits(params, 1124e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_CTRL, 1125e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_ENA); 1126e6938cc1SHelen Koike else 1127e6938cc1SHelen Koike rkisp1_param_clear_bits(params, 1128e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_CTRL, 1129e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_ENA); 1130e6938cc1SHelen Koike } 1131e6938cc1SHelen Koike } 1132e6938cc1SHelen Koike 1133e6938cc1SHelen Koike static void rkisp1_params_apply_params_cfg(struct rkisp1_params *params, 1134e6938cc1SHelen Koike unsigned int frame_sequence) 1135e6938cc1SHelen Koike { 1136e6938cc1SHelen Koike struct rkisp1_params_cfg *new_params; 1137e6938cc1SHelen Koike struct rkisp1_buffer *cur_buf = NULL; 1138e6938cc1SHelen Koike 1139e6938cc1SHelen Koike if (list_empty(¶ms->params)) 1140e6938cc1SHelen Koike return; 1141e6938cc1SHelen Koike 1142e6938cc1SHelen Koike cur_buf = list_first_entry(¶ms->params, 1143e6938cc1SHelen Koike struct rkisp1_buffer, queue); 1144e6938cc1SHelen Koike 114507e59d91SDafna Hirschfeld new_params = (struct rkisp1_params_cfg *)vb2_plane_vaddr(&cur_buf->vb.vb2_buf, 0); 1146e6938cc1SHelen Koike 1147e6938cc1SHelen Koike rkisp1_isp_isr_other_config(params, new_params); 1148e6938cc1SHelen Koike rkisp1_isp_isr_meas_config(params, new_params); 1149e6938cc1SHelen Koike 1150e6938cc1SHelen Koike /* update shadow register immediately */ 1151e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_ISP_CTRL, RKISP1_CIF_ISP_CTRL_ISP_CFG_UPD); 1152e6938cc1SHelen Koike 1153e6938cc1SHelen Koike list_del(&cur_buf->queue); 1154e6938cc1SHelen Koike 1155e6938cc1SHelen Koike cur_buf->vb.sequence = frame_sequence; 1156e6938cc1SHelen Koike vb2_buffer_done(&cur_buf->vb.vb2_buf, VB2_BUF_STATE_DONE); 1157e6938cc1SHelen Koike } 1158e6938cc1SHelen Koike 1159e6938cc1SHelen Koike void rkisp1_params_isr(struct rkisp1_device *rkisp1) 1160e6938cc1SHelen Koike { 1161e6938cc1SHelen Koike /* 1162e6938cc1SHelen Koike * This isr is called when the ISR finishes processing a frame (RKISP1_CIF_ISP_FRAME). 1163e6938cc1SHelen Koike * Configurations performed here will be applied on the next frame. 1164e6938cc1SHelen Koike * Since frame_sequence is updated on the vertical sync signal, we should use 1165e6938cc1SHelen Koike * frame_sequence + 1 here to indicate to userspace on which frame these parameters 1166e6938cc1SHelen Koike * are being applied. 1167e6938cc1SHelen Koike */ 1168e6938cc1SHelen Koike unsigned int frame_sequence = rkisp1->isp.frame_sequence + 1; 1169e6938cc1SHelen Koike struct rkisp1_params *params = &rkisp1->params; 1170e6938cc1SHelen Koike 1171e6938cc1SHelen Koike spin_lock(¶ms->config_lock); 1172e6938cc1SHelen Koike rkisp1_params_apply_params_cfg(params, frame_sequence); 1173e6938cc1SHelen Koike 1174e6938cc1SHelen Koike spin_unlock(¶ms->config_lock); 1175e6938cc1SHelen Koike } 1176e6938cc1SHelen Koike 1177e6938cc1SHelen Koike static const struct rkisp1_cif_isp_awb_meas_config rkisp1_awb_params_default_config = { 1178e6938cc1SHelen Koike { 1179e6938cc1SHelen Koike 0, 0, RKISP1_DEFAULT_WIDTH, RKISP1_DEFAULT_HEIGHT 1180e6938cc1SHelen Koike }, 1181e6938cc1SHelen Koike RKISP1_CIF_ISP_AWB_MODE_YCBCR, 200, 30, 20, 20, 0, 128, 128 1182e6938cc1SHelen Koike }; 1183e6938cc1SHelen Koike 1184e6938cc1SHelen Koike static const struct rkisp1_cif_isp_aec_config rkisp1_aec_params_default_config = { 1185e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_MEASURING_MODE_0, 1186e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_CTRL_AUTOSTOP_0, 1187e6938cc1SHelen Koike { 1188e6938cc1SHelen Koike RKISP1_DEFAULT_WIDTH >> 2, RKISP1_DEFAULT_HEIGHT >> 2, 1189e6938cc1SHelen Koike RKISP1_DEFAULT_WIDTH >> 1, RKISP1_DEFAULT_HEIGHT >> 1 1190e6938cc1SHelen Koike } 1191e6938cc1SHelen Koike }; 1192e6938cc1SHelen Koike 1193e6938cc1SHelen Koike static const struct rkisp1_cif_isp_hst_config rkisp1_hst_params_default_config = { 1194e6938cc1SHelen Koike RKISP1_CIF_ISP_HISTOGRAM_MODE_RGB_COMBINED, 1195e6938cc1SHelen Koike 3, 1196e6938cc1SHelen Koike { 1197e6938cc1SHelen Koike RKISP1_DEFAULT_WIDTH >> 2, RKISP1_DEFAULT_HEIGHT >> 2, 1198e6938cc1SHelen Koike RKISP1_DEFAULT_WIDTH >> 1, RKISP1_DEFAULT_HEIGHT >> 1 1199e6938cc1SHelen Koike }, 1200e6938cc1SHelen Koike { 1201e6938cc1SHelen Koike 0, /* To be filled in with 0x01 at runtime. */ 1202e6938cc1SHelen Koike } 1203e6938cc1SHelen Koike }; 1204e6938cc1SHelen Koike 1205e6938cc1SHelen Koike static const struct rkisp1_cif_isp_afc_config rkisp1_afc_params_default_config = { 1206e6938cc1SHelen Koike 1, 1207e6938cc1SHelen Koike { 1208e6938cc1SHelen Koike { 1209e6938cc1SHelen Koike 300, 225, 200, 150 1210e6938cc1SHelen Koike } 1211e6938cc1SHelen Koike }, 1212e6938cc1SHelen Koike 4, 1213e6938cc1SHelen Koike 14 1214e6938cc1SHelen Koike }; 1215e6938cc1SHelen Koike 1216e6938cc1SHelen Koike static void rkisp1_params_config_parameter(struct rkisp1_params *params) 1217e6938cc1SHelen Koike { 1218e6938cc1SHelen Koike struct rkisp1_cif_isp_hst_config hst = rkisp1_hst_params_default_config; 1219e6938cc1SHelen Koike 12205e8d9d72SHeiko Stuebner params->ops->awb_meas_config(params, &rkisp1_awb_params_default_config); 12215e8d9d72SHeiko Stuebner params->ops->awb_meas_enable(params, &rkisp1_awb_params_default_config, 1222e6938cc1SHelen Koike true); 1223e6938cc1SHelen Koike 12245e8d9d72SHeiko Stuebner params->ops->aec_config(params, &rkisp1_aec_params_default_config); 1225e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_ISP_EXP_CTRL, 1226e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_ENA); 1227e6938cc1SHelen Koike 12285e8d9d72SHeiko Stuebner params->ops->afm_config(params, &rkisp1_afc_params_default_config); 1229e6938cc1SHelen Koike rkisp1_param_set_bits(params, RKISP1_CIF_ISP_AFM_CTRL, 1230e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_ENA); 1231e6938cc1SHelen Koike 1232e6938cc1SHelen Koike memset(hst.hist_weight, 0x01, sizeof(hst.hist_weight)); 12335e8d9d72SHeiko Stuebner params->ops->hst_config(params, &hst); 1234*dce8ccb2SHeiko Stuebner rkisp1_param_set_bits(params, RKISP1_CIF_ISP_HIST_PROP_V10, 1235e6938cc1SHelen Koike rkisp1_hst_params_default_config.mode); 1236e6938cc1SHelen Koike 1237e6938cc1SHelen Koike /* set the range */ 1238e6938cc1SHelen Koike if (params->quantization == V4L2_QUANTIZATION_FULL_RANGE) 1239e6938cc1SHelen Koike rkisp1_csm_config(params, true); 1240e6938cc1SHelen Koike else 1241e6938cc1SHelen Koike rkisp1_csm_config(params, false); 1242e6938cc1SHelen Koike 1243e6938cc1SHelen Koike spin_lock_irq(¶ms->config_lock); 1244e6938cc1SHelen Koike 1245e6938cc1SHelen Koike /* apply the first buffer if there is one already */ 1246e6938cc1SHelen Koike rkisp1_params_apply_params_cfg(params, 0); 1247e6938cc1SHelen Koike 1248e6938cc1SHelen Koike spin_unlock_irq(¶ms->config_lock); 1249e6938cc1SHelen Koike } 1250e6938cc1SHelen Koike 1251e6938cc1SHelen Koike void rkisp1_params_configure(struct rkisp1_params *params, 1252e6938cc1SHelen Koike enum rkisp1_fmt_raw_pat_type bayer_pat, 1253e6938cc1SHelen Koike enum v4l2_quantization quantization) 1254e6938cc1SHelen Koike { 1255e6938cc1SHelen Koike params->quantization = quantization; 1256e6938cc1SHelen Koike params->raw_type = bayer_pat; 1257e6938cc1SHelen Koike rkisp1_params_config_parameter(params); 1258e6938cc1SHelen Koike } 1259e6938cc1SHelen Koike 126027ba4427SSebastian Fricke /* 126127ba4427SSebastian Fricke * Not called when the camera is active, therefore there is no need to acquire 126227ba4427SSebastian Fricke * a lock. 126327ba4427SSebastian Fricke */ 1264e6938cc1SHelen Koike void rkisp1_params_disable(struct rkisp1_params *params) 1265e6938cc1SHelen Koike { 1266e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_DPCC_MODE, 1267e6938cc1SHelen Koike RKISP1_CIF_ISP_DPCC_ENA); 1268e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_LSC_CTRL, 1269e6938cc1SHelen Koike RKISP1_CIF_ISP_LSC_CTRL_ENA); 1270e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_BLS_CTRL, 1271e6938cc1SHelen Koike RKISP1_CIF_ISP_BLS_ENA); 1272e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, 1273e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_GAMMA_IN_ENA); 1274e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, 1275e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_GAMMA_OUT_ENA); 1276e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_DEMOSAIC, 1277e6938cc1SHelen Koike RKISP1_CIF_ISP_DEMOSAIC_BYPASS); 1278e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_FILT_MODE, 1279e6938cc1SHelen Koike RKISP1_CIF_ISP_FLT_ENA); 12805e8d9d72SHeiko Stuebner params->ops->awb_meas_enable(params, NULL, false); 1281e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_CTRL, 1282e6938cc1SHelen Koike RKISP1_CIF_ISP_CTRL_ISP_AWB_ENA); 1283e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_EXP_CTRL, 1284e6938cc1SHelen Koike RKISP1_CIF_ISP_EXP_ENA); 1285e6938cc1SHelen Koike rkisp1_ctk_enable(params, false); 1286e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_C_PROC_CTRL, 1287e6938cc1SHelen Koike RKISP1_CIF_C_PROC_CTR_ENABLE); 12885e8d9d72SHeiko Stuebner params->ops->hst_enable(params, NULL, false); 1289e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_AFM_CTRL, 1290e6938cc1SHelen Koike RKISP1_CIF_ISP_AFM_ENA); 1291e6938cc1SHelen Koike rkisp1_ie_enable(params, false); 1292e6938cc1SHelen Koike rkisp1_param_clear_bits(params, RKISP1_CIF_ISP_DPF_MODE, 1293e6938cc1SHelen Koike RKISP1_CIF_ISP_DPF_MODE_EN); 1294e6938cc1SHelen Koike } 1295e6938cc1SHelen Koike 1296*dce8ccb2SHeiko Stuebner static const struct rkisp1_params_ops rkisp1_v10_params_ops = { 1297*dce8ccb2SHeiko Stuebner .lsc_matrix_config = rkisp1_lsc_matrix_config_v10, 1298*dce8ccb2SHeiko Stuebner .goc_config = rkisp1_goc_config_v10, 1299*dce8ccb2SHeiko Stuebner .awb_meas_config = rkisp1_awb_meas_config_v10, 1300*dce8ccb2SHeiko Stuebner .awb_meas_enable = rkisp1_awb_meas_enable_v10, 1301*dce8ccb2SHeiko Stuebner .awb_gain_config = rkisp1_awb_gain_config_v10, 1302*dce8ccb2SHeiko Stuebner .aec_config = rkisp1_aec_config_v10, 1303*dce8ccb2SHeiko Stuebner .hst_config = rkisp1_hst_config_v10, 1304*dce8ccb2SHeiko Stuebner .hst_enable = rkisp1_hst_enable_v10, 1305*dce8ccb2SHeiko Stuebner .afm_config = rkisp1_afm_config_v10, 13065e8d9d72SHeiko Stuebner }; 13075e8d9d72SHeiko Stuebner 1308e6938cc1SHelen Koike static int rkisp1_params_enum_fmt_meta_out(struct file *file, void *priv, 1309e6938cc1SHelen Koike struct v4l2_fmtdesc *f) 1310e6938cc1SHelen Koike { 1311e6938cc1SHelen Koike struct video_device *video = video_devdata(file); 1312e6938cc1SHelen Koike struct rkisp1_params *params = video_get_drvdata(video); 1313e6938cc1SHelen Koike 1314e6938cc1SHelen Koike if (f->index > 0 || f->type != video->queue->type) 1315e6938cc1SHelen Koike return -EINVAL; 1316e6938cc1SHelen Koike 1317e6938cc1SHelen Koike f->pixelformat = params->vdev_fmt.fmt.meta.dataformat; 1318e6938cc1SHelen Koike 1319e6938cc1SHelen Koike return 0; 1320e6938cc1SHelen Koike } 1321e6938cc1SHelen Koike 1322e6938cc1SHelen Koike static int rkisp1_params_g_fmt_meta_out(struct file *file, void *fh, 1323e6938cc1SHelen Koike struct v4l2_format *f) 1324e6938cc1SHelen Koike { 1325e6938cc1SHelen Koike struct video_device *video = video_devdata(file); 1326e6938cc1SHelen Koike struct rkisp1_params *params = video_get_drvdata(video); 1327e6938cc1SHelen Koike struct v4l2_meta_format *meta = &f->fmt.meta; 1328e6938cc1SHelen Koike 1329e6938cc1SHelen Koike if (f->type != video->queue->type) 1330e6938cc1SHelen Koike return -EINVAL; 1331e6938cc1SHelen Koike 1332e6938cc1SHelen Koike memset(meta, 0, sizeof(*meta)); 1333e6938cc1SHelen Koike meta->dataformat = params->vdev_fmt.fmt.meta.dataformat; 1334e6938cc1SHelen Koike meta->buffersize = params->vdev_fmt.fmt.meta.buffersize; 1335e6938cc1SHelen Koike 1336e6938cc1SHelen Koike return 0; 1337e6938cc1SHelen Koike } 1338e6938cc1SHelen Koike 1339e6938cc1SHelen Koike static int rkisp1_params_querycap(struct file *file, 1340e6938cc1SHelen Koike void *priv, struct v4l2_capability *cap) 1341e6938cc1SHelen Koike { 1342e6938cc1SHelen Koike struct video_device *vdev = video_devdata(file); 1343e6938cc1SHelen Koike 1344e6938cc1SHelen Koike strscpy(cap->driver, RKISP1_DRIVER_NAME, sizeof(cap->driver)); 1345e6938cc1SHelen Koike strscpy(cap->card, vdev->name, sizeof(cap->card)); 1346e6938cc1SHelen Koike strscpy(cap->bus_info, RKISP1_BUS_INFO, sizeof(cap->bus_info)); 1347e6938cc1SHelen Koike 1348e6938cc1SHelen Koike return 0; 1349e6938cc1SHelen Koike } 1350e6938cc1SHelen Koike 1351e6938cc1SHelen Koike /* ISP params video device IOCTLs */ 1352e6938cc1SHelen Koike static const struct v4l2_ioctl_ops rkisp1_params_ioctl = { 1353e6938cc1SHelen Koike .vidioc_reqbufs = vb2_ioctl_reqbufs, 1354e6938cc1SHelen Koike .vidioc_querybuf = vb2_ioctl_querybuf, 1355e6938cc1SHelen Koike .vidioc_create_bufs = vb2_ioctl_create_bufs, 1356e6938cc1SHelen Koike .vidioc_qbuf = vb2_ioctl_qbuf, 1357e6938cc1SHelen Koike .vidioc_dqbuf = vb2_ioctl_dqbuf, 1358e6938cc1SHelen Koike .vidioc_prepare_buf = vb2_ioctl_prepare_buf, 1359e6938cc1SHelen Koike .vidioc_expbuf = vb2_ioctl_expbuf, 1360e6938cc1SHelen Koike .vidioc_streamon = vb2_ioctl_streamon, 1361e6938cc1SHelen Koike .vidioc_streamoff = vb2_ioctl_streamoff, 1362e6938cc1SHelen Koike .vidioc_enum_fmt_meta_out = rkisp1_params_enum_fmt_meta_out, 1363e6938cc1SHelen Koike .vidioc_g_fmt_meta_out = rkisp1_params_g_fmt_meta_out, 1364e6938cc1SHelen Koike .vidioc_s_fmt_meta_out = rkisp1_params_g_fmt_meta_out, 1365e6938cc1SHelen Koike .vidioc_try_fmt_meta_out = rkisp1_params_g_fmt_meta_out, 1366e6938cc1SHelen Koike .vidioc_querycap = rkisp1_params_querycap, 1367e6938cc1SHelen Koike .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 1368e6938cc1SHelen Koike .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 1369e6938cc1SHelen Koike }; 1370e6938cc1SHelen Koike 1371e6938cc1SHelen Koike static int rkisp1_params_vb2_queue_setup(struct vb2_queue *vq, 1372e6938cc1SHelen Koike unsigned int *num_buffers, 1373e6938cc1SHelen Koike unsigned int *num_planes, 1374e6938cc1SHelen Koike unsigned int sizes[], 1375e6938cc1SHelen Koike struct device *alloc_devs[]) 1376e6938cc1SHelen Koike { 1377e6938cc1SHelen Koike *num_buffers = clamp_t(u32, *num_buffers, 1378e6938cc1SHelen Koike RKISP1_ISP_PARAMS_REQ_BUFS_MIN, 1379e6938cc1SHelen Koike RKISP1_ISP_PARAMS_REQ_BUFS_MAX); 1380e6938cc1SHelen Koike 1381e6938cc1SHelen Koike *num_planes = 1; 1382e6938cc1SHelen Koike 1383e6938cc1SHelen Koike sizes[0] = sizeof(struct rkisp1_params_cfg); 1384e6938cc1SHelen Koike 1385e6938cc1SHelen Koike return 0; 1386e6938cc1SHelen Koike } 1387e6938cc1SHelen Koike 1388e6938cc1SHelen Koike static void rkisp1_params_vb2_buf_queue(struct vb2_buffer *vb) 1389e6938cc1SHelen Koike { 1390e6938cc1SHelen Koike struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 1391e6938cc1SHelen Koike struct rkisp1_buffer *params_buf = 1392e6938cc1SHelen Koike container_of(vbuf, struct rkisp1_buffer, vb); 1393e6938cc1SHelen Koike struct vb2_queue *vq = vb->vb2_queue; 1394e6938cc1SHelen Koike struct rkisp1_params *params = vq->drv_priv; 1395e6938cc1SHelen Koike 1396e6938cc1SHelen Koike spin_lock_irq(¶ms->config_lock); 1397e6938cc1SHelen Koike list_add_tail(¶ms_buf->queue, ¶ms->params); 1398e6938cc1SHelen Koike spin_unlock_irq(¶ms->config_lock); 1399e6938cc1SHelen Koike } 1400e6938cc1SHelen Koike 1401e6938cc1SHelen Koike static int rkisp1_params_vb2_buf_prepare(struct vb2_buffer *vb) 1402e6938cc1SHelen Koike { 1403e6938cc1SHelen Koike if (vb2_plane_size(vb, 0) < sizeof(struct rkisp1_params_cfg)) 1404e6938cc1SHelen Koike return -EINVAL; 1405e6938cc1SHelen Koike 1406e6938cc1SHelen Koike vb2_set_plane_payload(vb, 0, sizeof(struct rkisp1_params_cfg)); 1407e6938cc1SHelen Koike 1408e6938cc1SHelen Koike return 0; 1409e6938cc1SHelen Koike } 1410e6938cc1SHelen Koike 1411e6938cc1SHelen Koike static void rkisp1_params_vb2_stop_streaming(struct vb2_queue *vq) 1412e6938cc1SHelen Koike { 1413e6938cc1SHelen Koike struct rkisp1_params *params = vq->drv_priv; 1414e6938cc1SHelen Koike struct rkisp1_buffer *buf; 1415e6938cc1SHelen Koike LIST_HEAD(tmp_list); 1416e6938cc1SHelen Koike 1417e6938cc1SHelen Koike /* 1418e6938cc1SHelen Koike * we first move the buffers into a local list 'tmp_list' 1419e6938cc1SHelen Koike * and then we can iterate it and call vb2_buffer_done 1420e6938cc1SHelen Koike * without holding the lock 1421e6938cc1SHelen Koike */ 1422e6938cc1SHelen Koike spin_lock_irq(¶ms->config_lock); 1423e6938cc1SHelen Koike list_splice_init(¶ms->params, &tmp_list); 1424e6938cc1SHelen Koike spin_unlock_irq(¶ms->config_lock); 1425e6938cc1SHelen Koike 1426e6938cc1SHelen Koike list_for_each_entry(buf, &tmp_list, queue) 1427e6938cc1SHelen Koike vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); 1428e6938cc1SHelen Koike } 1429e6938cc1SHelen Koike 1430a109073bSRikard Falkeborn static const struct vb2_ops rkisp1_params_vb2_ops = { 1431e6938cc1SHelen Koike .queue_setup = rkisp1_params_vb2_queue_setup, 1432e6938cc1SHelen Koike .wait_prepare = vb2_ops_wait_prepare, 1433e6938cc1SHelen Koike .wait_finish = vb2_ops_wait_finish, 1434e6938cc1SHelen Koike .buf_queue = rkisp1_params_vb2_buf_queue, 1435e6938cc1SHelen Koike .buf_prepare = rkisp1_params_vb2_buf_prepare, 1436e6938cc1SHelen Koike .stop_streaming = rkisp1_params_vb2_stop_streaming, 1437e6938cc1SHelen Koike 1438e6938cc1SHelen Koike }; 1439e6938cc1SHelen Koike 1440a109073bSRikard Falkeborn static const struct v4l2_file_operations rkisp1_params_fops = { 1441e6938cc1SHelen Koike .mmap = vb2_fop_mmap, 1442e6938cc1SHelen Koike .unlocked_ioctl = video_ioctl2, 1443e6938cc1SHelen Koike .poll = vb2_fop_poll, 1444e6938cc1SHelen Koike .open = v4l2_fh_open, 1445e6938cc1SHelen Koike .release = vb2_fop_release 1446e6938cc1SHelen Koike }; 1447e6938cc1SHelen Koike 1448e6938cc1SHelen Koike static int rkisp1_params_init_vb2_queue(struct vb2_queue *q, 1449e6938cc1SHelen Koike struct rkisp1_params *params) 1450e6938cc1SHelen Koike { 1451e6938cc1SHelen Koike struct rkisp1_vdev_node *node; 1452e6938cc1SHelen Koike 1453e6938cc1SHelen Koike node = container_of(q, struct rkisp1_vdev_node, buf_queue); 1454e6938cc1SHelen Koike 1455e6938cc1SHelen Koike q->type = V4L2_BUF_TYPE_META_OUTPUT; 1456e6938cc1SHelen Koike q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF; 1457e6938cc1SHelen Koike q->drv_priv = params; 1458e6938cc1SHelen Koike q->ops = &rkisp1_params_vb2_ops; 1459e6938cc1SHelen Koike q->mem_ops = &vb2_vmalloc_memops; 1460e6938cc1SHelen Koike q->buf_struct_size = sizeof(struct rkisp1_buffer); 1461e6938cc1SHelen Koike q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1462e6938cc1SHelen Koike q->lock = &node->vlock; 1463e6938cc1SHelen Koike 1464e6938cc1SHelen Koike return vb2_queue_init(q); 1465e6938cc1SHelen Koike } 1466e6938cc1SHelen Koike 1467e6938cc1SHelen Koike static void rkisp1_init_params(struct rkisp1_params *params) 1468e6938cc1SHelen Koike { 1469e6938cc1SHelen Koike params->vdev_fmt.fmt.meta.dataformat = 1470e6938cc1SHelen Koike V4L2_META_FMT_RK_ISP1_PARAMS; 1471e6938cc1SHelen Koike params->vdev_fmt.fmt.meta.buffersize = 1472e6938cc1SHelen Koike sizeof(struct rkisp1_params_cfg); 14735e8d9d72SHeiko Stuebner 1474*dce8ccb2SHeiko Stuebner params->ops = &rkisp1_v10_params_ops; 1475e6938cc1SHelen Koike } 1476e6938cc1SHelen Koike 1477e6938cc1SHelen Koike int rkisp1_params_register(struct rkisp1_device *rkisp1) 1478e6938cc1SHelen Koike { 1479e6938cc1SHelen Koike struct rkisp1_params *params = &rkisp1->params; 1480e6938cc1SHelen Koike struct rkisp1_vdev_node *node = ¶ms->vnode; 1481e6938cc1SHelen Koike struct video_device *vdev = &node->vdev; 1482e6938cc1SHelen Koike int ret; 1483e6938cc1SHelen Koike 1484e6938cc1SHelen Koike params->rkisp1 = rkisp1; 1485e6938cc1SHelen Koike mutex_init(&node->vlock); 1486e6938cc1SHelen Koike INIT_LIST_HEAD(¶ms->params); 1487e6938cc1SHelen Koike spin_lock_init(¶ms->config_lock); 1488e6938cc1SHelen Koike 1489e6938cc1SHelen Koike strscpy(vdev->name, RKISP1_PARAMS_DEV_NAME, sizeof(vdev->name)); 1490e6938cc1SHelen Koike 1491e6938cc1SHelen Koike video_set_drvdata(vdev, params); 1492e6938cc1SHelen Koike vdev->ioctl_ops = &rkisp1_params_ioctl; 1493e6938cc1SHelen Koike vdev->fops = &rkisp1_params_fops; 1494e6938cc1SHelen Koike vdev->release = video_device_release_empty; 1495e6938cc1SHelen Koike /* 1496e6938cc1SHelen Koike * Provide a mutex to v4l2 core. It will be used 1497e6938cc1SHelen Koike * to protect all fops and v4l2 ioctls. 1498e6938cc1SHelen Koike */ 1499e6938cc1SHelen Koike vdev->lock = &node->vlock; 1500e6938cc1SHelen Koike vdev->v4l2_dev = &rkisp1->v4l2_dev; 1501e6938cc1SHelen Koike vdev->queue = &node->buf_queue; 1502e6938cc1SHelen Koike vdev->device_caps = V4L2_CAP_STREAMING | V4L2_CAP_META_OUTPUT; 1503e6938cc1SHelen Koike vdev->vfl_dir = VFL_DIR_TX; 1504e6938cc1SHelen Koike rkisp1_params_init_vb2_queue(vdev->queue, params); 1505e6938cc1SHelen Koike rkisp1_init_params(params); 1506e6938cc1SHelen Koike video_set_drvdata(vdev, params); 1507e6938cc1SHelen Koike 1508e6938cc1SHelen Koike node->pad.flags = MEDIA_PAD_FL_SOURCE; 1509e6938cc1SHelen Koike ret = media_entity_pads_init(&vdev->entity, 1, &node->pad); 1510e6938cc1SHelen Koike if (ret) 1511e6938cc1SHelen Koike return ret; 1512e6938cc1SHelen Koike ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); 1513e6938cc1SHelen Koike if (ret) { 1514e6938cc1SHelen Koike dev_err(rkisp1->dev, 1515e6938cc1SHelen Koike "failed to register %s, ret=%d\n", vdev->name, ret); 1516e6938cc1SHelen Koike goto err_cleanup_media_entity; 1517e6938cc1SHelen Koike } 1518e6938cc1SHelen Koike return 0; 1519e6938cc1SHelen Koike err_cleanup_media_entity: 1520e6938cc1SHelen Koike media_entity_cleanup(&vdev->entity); 1521e6938cc1SHelen Koike return ret; 1522e6938cc1SHelen Koike } 1523e6938cc1SHelen Koike 1524e6938cc1SHelen Koike void rkisp1_params_unregister(struct rkisp1_device *rkisp1) 1525e6938cc1SHelen Koike { 1526e6938cc1SHelen Koike struct rkisp1_params *params = &rkisp1->params; 1527e6938cc1SHelen Koike struct rkisp1_vdev_node *node = ¶ms->vnode; 1528e6938cc1SHelen Koike struct video_device *vdev = &node->vdev; 1529e6938cc1SHelen Koike 1530e6938cc1SHelen Koike vb2_video_unregister_device(vdev); 1531e6938cc1SHelen Koike media_entity_cleanup(&vdev->entity); 1532e6938cc1SHelen Koike } 1533