2 * Copyright (C) 2012 Texas Instruments Inc
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Manjunath Hadli <manjunath.hadli@ti.com>
19 * Prabhakar Lad <prabhakar.lad@ti.com>
22 * IPIPE allows fine tuning of the input image using different
23 * tuning modules in IPIPE. Some examples :- Noise filter, Defect
24 * pixel correction etc. It essentially operate on Bayer Raw data
25 * or YUV raw data. To do image tuning, application call,
29 #include <linux/slab.h>
31 #include "dm365_ipipe.h"
32 #include "dm365_ipipe_hw.h"
33 #include "vpfe_mc_capture.h"
35 #define MIN_OUT_WIDTH 32
36 #define MIN_OUT_HEIGHT 32
38 /* ipipe input format's */
39 static const unsigned int ipipe_input_fmts[] = {
40 MEDIA_BUS_FMT_UYVY8_2X8,
41 MEDIA_BUS_FMT_SGRBG12_1X12,
42 MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8,
43 MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8,
46 /* ipipe output format's */
47 static const unsigned int ipipe_output_fmts[] = {
48 MEDIA_BUS_FMT_UYVY8_2X8,
51 static int ipipe_validate_lutdpc_params(struct vpfe_ipipe_lutdpc *lutdpc)
55 if (lutdpc->en > 1 || lutdpc->repl_white > 1 ||
56 lutdpc->dpc_size > LUT_DPC_MAX_SIZE)
59 if (lutdpc->en && !lutdpc->table)
62 for (i = 0; i < lutdpc->dpc_size; i++)
63 if (lutdpc->table[i].horz_pos > LUT_DPC_H_POS_MASK ||
64 lutdpc->table[i].vert_pos > LUT_DPC_V_POS_MASK)
70 static int ipipe_set_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
72 struct vpfe_ipipe_lutdpc *lutdpc = &ipipe->config.lutdpc;
73 struct vpfe_ipipe_lutdpc *dpc_param;
77 memset((void *)lutdpc, 0, sizeof(struct vpfe_ipipe_lutdpc));
81 dev = ipipe->subdev.v4l2_dev->dev;
82 dpc_param = (struct vpfe_ipipe_lutdpc *)param;
83 lutdpc->en = dpc_param->en;
84 lutdpc->repl_white = dpc_param->repl_white;
85 lutdpc->dpc_size = dpc_param->dpc_size;
86 memcpy(&lutdpc->table, &dpc_param->table,
87 (dpc_param->dpc_size * sizeof(struct vpfe_ipipe_lutdpc_entry)));
88 if (ipipe_validate_lutdpc_params(lutdpc) < 0)
92 ipipe_set_lutdpc_regs(ipipe->base_addr, ipipe->isp5_base_addr, lutdpc);
97 static int ipipe_get_lutdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
99 struct vpfe_ipipe_lutdpc *lut_param = (struct vpfe_ipipe_lutdpc *)param;
100 struct vpfe_ipipe_lutdpc *lutdpc = &ipipe->config.lutdpc;
102 lut_param->en = lutdpc->en;
103 lut_param->repl_white = lutdpc->repl_white;
104 lut_param->dpc_size = lutdpc->dpc_size;
105 memcpy(&lut_param->table, &lutdpc->table,
106 (lutdpc->dpc_size * sizeof(struct vpfe_ipipe_lutdpc_entry)));
111 static int ipipe_set_input_config(struct vpfe_ipipe_device *ipipe, void *param)
113 struct vpfe_ipipe_input_config *config = &ipipe->config.input_config;
116 memset(config, 0, sizeof(struct vpfe_ipipe_input_config));
118 memcpy(config, param, sizeof(struct vpfe_ipipe_input_config));
122 static int ipipe_get_input_config(struct vpfe_ipipe_device *ipipe, void *param)
124 struct vpfe_ipipe_input_config *config = &ipipe->config.input_config;
129 memcpy(param, config, sizeof(struct vpfe_ipipe_input_config));
134 static int ipipe_validate_otfdpc_params(struct vpfe_ipipe_otfdpc *dpc_param)
136 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_2_0;
137 struct vpfe_ipipe_otfdpc_3_0_cfg *dpc_3_0;
139 if (dpc_param->en > 1)
142 if (dpc_param->alg == VPFE_IPIPE_OTFDPC_2_0) {
143 dpc_2_0 = &dpc_param->alg_cfg.dpc_2_0;
144 if (dpc_2_0->det_thr.r > OTFDPC_DPC2_THR_MASK ||
145 dpc_2_0->det_thr.gr > OTFDPC_DPC2_THR_MASK ||
146 dpc_2_0->det_thr.gb > OTFDPC_DPC2_THR_MASK ||
147 dpc_2_0->det_thr.b > OTFDPC_DPC2_THR_MASK ||
148 dpc_2_0->corr_thr.r > OTFDPC_DPC2_THR_MASK ||
149 dpc_2_0->corr_thr.gr > OTFDPC_DPC2_THR_MASK ||
150 dpc_2_0->corr_thr.gb > OTFDPC_DPC2_THR_MASK ||
151 dpc_2_0->corr_thr.b > OTFDPC_DPC2_THR_MASK)
156 dpc_3_0 = &dpc_param->alg_cfg.dpc_3_0;
158 if (dpc_3_0->act_adj_shf > OTF_DPC3_0_SHF_MASK ||
159 dpc_3_0->det_thr > OTF_DPC3_0_DET_MASK ||
160 dpc_3_0->det_slp > OTF_DPC3_0_SLP_MASK ||
161 dpc_3_0->det_thr_min > OTF_DPC3_0_DET_MASK ||
162 dpc_3_0->det_thr_max > OTF_DPC3_0_DET_MASK ||
163 dpc_3_0->corr_thr > OTF_DPC3_0_CORR_MASK ||
164 dpc_3_0->corr_slp > OTF_DPC3_0_SLP_MASK ||
165 dpc_3_0->corr_thr_min > OTF_DPC3_0_CORR_MASK ||
166 dpc_3_0->corr_thr_max > OTF_DPC3_0_CORR_MASK)
172 static int ipipe_set_otfdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
174 struct vpfe_ipipe_otfdpc *dpc_param = (struct vpfe_ipipe_otfdpc *)param;
175 struct vpfe_ipipe_otfdpc *otfdpc = &ipipe->config.otfdpc;
179 memset((void *)otfdpc, 0, sizeof(struct ipipe_otfdpc_2_0));
182 dev = ipipe->subdev.v4l2_dev->dev;
183 memcpy(otfdpc, dpc_param, sizeof(struct vpfe_ipipe_otfdpc));
184 if (ipipe_validate_otfdpc_params(otfdpc) < 0) {
185 dev_err(dev, "Invalid otfdpc params\n");
190 ipipe_set_otfdpc_regs(ipipe->base_addr, otfdpc);
195 static int ipipe_get_otfdpc_params(struct vpfe_ipipe_device *ipipe, void *param)
197 struct vpfe_ipipe_otfdpc *dpc_param = (struct vpfe_ipipe_otfdpc *)param;
198 struct vpfe_ipipe_otfdpc *otfdpc = &ipipe->config.otfdpc;
200 memcpy(dpc_param, otfdpc, sizeof(struct vpfe_ipipe_otfdpc));
204 static int ipipe_validate_nf_params(struct vpfe_ipipe_nf *nf_param)
208 if (nf_param->en > 1 || nf_param->shft_val > D2F_SHFT_VAL_MASK ||
209 nf_param->spread_val > D2F_SPR_VAL_MASK ||
210 nf_param->apply_lsc_gain > 1 ||
211 nf_param->edge_det_min_thr > D2F_EDGE_DET_THR_MASK ||
212 nf_param->edge_det_max_thr > D2F_EDGE_DET_THR_MASK)
215 for (i = 0; i < VPFE_IPIPE_NF_THR_TABLE_SIZE; i++)
216 if (nf_param->thr[i] > D2F_THR_VAL_MASK)
219 for (i = 0; i < VPFE_IPIPE_NF_STR_TABLE_SIZE; i++)
220 if (nf_param->str[i] > D2F_STR_VAL_MASK)
226 static int ipipe_set_nf_params(struct vpfe_ipipe_device *ipipe,
227 unsigned int id, void *param)
229 struct vpfe_ipipe_nf *nf_param = (struct vpfe_ipipe_nf *)param;
230 struct vpfe_ipipe_nf *nf = &ipipe->config.nf1;
233 if (id == IPIPE_D2F_2ND)
234 nf = &ipipe->config.nf2;
237 memset((void *)nf, 0, sizeof(struct vpfe_ipipe_nf));
241 dev = ipipe->subdev.v4l2_dev->dev;
242 memcpy(nf, nf_param, sizeof(struct vpfe_ipipe_nf));
243 if (ipipe_validate_nf_params(nf) < 0) {
244 dev_err(dev, "Invalid nf params\n");
249 ipipe_set_d2f_regs(ipipe->base_addr, id, nf);
254 static int ipipe_set_nf1_params(struct vpfe_ipipe_device *ipipe, void *param)
256 return ipipe_set_nf_params(ipipe, IPIPE_D2F_1ST, param);
259 static int ipipe_set_nf2_params(struct vpfe_ipipe_device *ipipe, void *param)
261 return ipipe_set_nf_params(ipipe, IPIPE_D2F_2ND, param);
264 static int ipipe_get_nf_params(struct vpfe_ipipe_device *ipipe,
265 unsigned int id, void *param)
267 struct vpfe_ipipe_nf *nf_param = (struct vpfe_ipipe_nf *)param;
268 struct vpfe_ipipe_nf *nf = &ipipe->config.nf1;
270 if (id == IPIPE_D2F_2ND)
271 nf = &ipipe->config.nf2;
273 memcpy(nf_param, nf, sizeof(struct vpfe_ipipe_nf));
278 static int ipipe_get_nf1_params(struct vpfe_ipipe_device *ipipe, void *param)
280 return ipipe_get_nf_params(ipipe, IPIPE_D2F_1ST, param);
283 static int ipipe_get_nf2_params(struct vpfe_ipipe_device *ipipe, void *param)
285 return ipipe_get_nf_params(ipipe, IPIPE_D2F_2ND, param);
288 static int ipipe_validate_gic_params(struct vpfe_ipipe_gic *gic)
290 if (gic->en > 1 || gic->gain > GIC_GAIN_MASK ||
291 gic->thr > GIC_THR_MASK || gic->slope > GIC_SLOPE_MASK ||
292 gic->apply_lsc_gain > 1 ||
293 gic->nf2_thr_gain.integer > GIC_NFGAN_INT_MASK ||
294 gic->nf2_thr_gain.decimal > GIC_NFGAN_DECI_MASK)
300 static int ipipe_set_gic_params(struct vpfe_ipipe_device *ipipe, void *param)
302 struct vpfe_ipipe_gic *gic_param = (struct vpfe_ipipe_gic *)param;
303 struct device *dev = ipipe->subdev.v4l2_dev->dev;
304 struct vpfe_ipipe_gic *gic = &ipipe->config.gic;
307 memset((void *)gic, 0, sizeof(struct vpfe_ipipe_gic));
311 memcpy(gic, gic_param, sizeof(struct vpfe_ipipe_gic));
312 if (ipipe_validate_gic_params(gic) < 0) {
313 dev_err(dev, "Invalid gic params\n");
318 ipipe_set_gic_regs(ipipe->base_addr, gic);
323 static int ipipe_get_gic_params(struct vpfe_ipipe_device *ipipe, void *param)
325 struct vpfe_ipipe_gic *gic_param = (struct vpfe_ipipe_gic *)param;
326 struct vpfe_ipipe_gic *gic = &ipipe->config.gic;
328 memcpy(gic_param, gic, sizeof(struct vpfe_ipipe_gic));
333 static int ipipe_validate_wb_params(struct vpfe_ipipe_wb *wbal)
335 if (wbal->ofst_r > WB_OFFSET_MASK ||
336 wbal->ofst_gr > WB_OFFSET_MASK ||
337 wbal->ofst_gb > WB_OFFSET_MASK ||
338 wbal->ofst_b > WB_OFFSET_MASK ||
339 wbal->gain_r.integer > WB_GAIN_INT_MASK ||
340 wbal->gain_r.decimal > WB_GAIN_DECI_MASK ||
341 wbal->gain_gr.integer > WB_GAIN_INT_MASK ||
342 wbal->gain_gr.decimal > WB_GAIN_DECI_MASK ||
343 wbal->gain_gb.integer > WB_GAIN_INT_MASK ||
344 wbal->gain_gb.decimal > WB_GAIN_DECI_MASK ||
345 wbal->gain_b.integer > WB_GAIN_INT_MASK ||
346 wbal->gain_b.decimal > WB_GAIN_DECI_MASK)
352 static int ipipe_set_wb_params(struct vpfe_ipipe_device *ipipe, void *param)
354 struct vpfe_ipipe_wb *wb_param = (struct vpfe_ipipe_wb *)param;
355 struct vpfe_ipipe_wb *wbal = &ipipe->config.wbal;
358 const struct vpfe_ipipe_wb wb_defaults = {
364 memcpy(wbal, &wb_defaults, sizeof(struct vpfe_ipipe_wb));
368 memcpy(wbal, wb_param, sizeof(struct vpfe_ipipe_wb));
369 if (ipipe_validate_wb_params(wbal) < 0)
373 ipipe_set_wb_regs(ipipe->base_addr, wbal);
378 static int ipipe_get_wb_params(struct vpfe_ipipe_device *ipipe, void *param)
380 struct vpfe_ipipe_wb *wb_param = (struct vpfe_ipipe_wb *)param;
381 struct vpfe_ipipe_wb *wbal = &ipipe->config.wbal;
383 memcpy(wb_param, wbal, sizeof(struct vpfe_ipipe_wb));
387 static int ipipe_validate_cfa_params(struct vpfe_ipipe_cfa *cfa)
389 if (cfa->hpf_thr_2dir > CFA_HPF_THR_2DIR_MASK ||
390 cfa->hpf_slp_2dir > CFA_HPF_SLOPE_2DIR_MASK ||
391 cfa->hp_mix_thr_2dir > CFA_HPF_MIX_THR_2DIR_MASK ||
392 cfa->hp_mix_slope_2dir > CFA_HPF_MIX_SLP_2DIR_MASK ||
393 cfa->dir_thr_2dir > CFA_DIR_THR_2DIR_MASK ||
394 cfa->dir_slope_2dir > CFA_DIR_SLP_2DIR_MASK ||
395 cfa->nd_wt_2dir > CFA_ND_WT_2DIR_MASK ||
396 cfa->hue_fract_daa > CFA_DAA_HUE_FRA_MASK ||
397 cfa->edge_thr_daa > CFA_DAA_EDG_THR_MASK ||
398 cfa->thr_min_daa > CFA_DAA_THR_MIN_MASK ||
399 cfa->thr_slope_daa > CFA_DAA_THR_SLP_MASK ||
400 cfa->slope_min_daa > CFA_DAA_SLP_MIN_MASK ||
401 cfa->slope_slope_daa > CFA_DAA_SLP_SLP_MASK ||
402 cfa->lp_wt_daa > CFA_DAA_LP_WT_MASK)
408 static int ipipe_set_cfa_params(struct vpfe_ipipe_device *ipipe, void *param)
410 struct vpfe_ipipe_cfa *cfa_param = (struct vpfe_ipipe_cfa *)param;
411 struct vpfe_ipipe_cfa *cfa = &ipipe->config.cfa;
414 memset(cfa, 0, sizeof(struct vpfe_ipipe_cfa));
415 cfa->alg = VPFE_IPIPE_CFA_ALG_2DIRAC;
419 memcpy(cfa, cfa_param, sizeof(struct vpfe_ipipe_cfa));
420 if (ipipe_validate_cfa_params(cfa) < 0)
424 ipipe_set_cfa_regs(ipipe->base_addr, cfa);
429 static int ipipe_get_cfa_params(struct vpfe_ipipe_device *ipipe, void *param)
431 struct vpfe_ipipe_cfa *cfa_param = (struct vpfe_ipipe_cfa *)param;
432 struct vpfe_ipipe_cfa *cfa = &ipipe->config.cfa;
434 memcpy(cfa_param, cfa, sizeof(struct vpfe_ipipe_cfa));
439 ipipe_validate_rgb2rgb_params(struct vpfe_ipipe_rgb2rgb *rgb2rgb,
442 u32 gain_int_upper = RGB2RGB_1_GAIN_INT_MASK;
443 u32 offset_upper = RGB2RGB_1_OFST_MASK;
445 if (id == IPIPE_RGB2RGB_2) {
446 offset_upper = RGB2RGB_2_OFST_MASK;
447 gain_int_upper = RGB2RGB_2_GAIN_INT_MASK;
450 if (rgb2rgb->coef_rr.decimal > RGB2RGB_GAIN_DECI_MASK ||
451 rgb2rgb->coef_rr.integer > gain_int_upper)
454 if (rgb2rgb->coef_gr.decimal > RGB2RGB_GAIN_DECI_MASK ||
455 rgb2rgb->coef_gr.integer > gain_int_upper)
458 if (rgb2rgb->coef_br.decimal > RGB2RGB_GAIN_DECI_MASK ||
459 rgb2rgb->coef_br.integer > gain_int_upper)
462 if (rgb2rgb->coef_rg.decimal > RGB2RGB_GAIN_DECI_MASK ||
463 rgb2rgb->coef_rg.integer > gain_int_upper)
466 if (rgb2rgb->coef_gg.decimal > RGB2RGB_GAIN_DECI_MASK ||
467 rgb2rgb->coef_gg.integer > gain_int_upper)
470 if (rgb2rgb->coef_bg.decimal > RGB2RGB_GAIN_DECI_MASK ||
471 rgb2rgb->coef_bg.integer > gain_int_upper)
474 if (rgb2rgb->coef_rb.decimal > RGB2RGB_GAIN_DECI_MASK ||
475 rgb2rgb->coef_rb.integer > gain_int_upper)
478 if (rgb2rgb->coef_gb.decimal > RGB2RGB_GAIN_DECI_MASK ||
479 rgb2rgb->coef_gb.integer > gain_int_upper)
482 if (rgb2rgb->coef_bb.decimal > RGB2RGB_GAIN_DECI_MASK ||
483 rgb2rgb->coef_bb.integer > gain_int_upper)
486 if (rgb2rgb->out_ofst_r > offset_upper ||
487 rgb2rgb->out_ofst_g > offset_upper ||
488 rgb2rgb->out_ofst_b > offset_upper)
494 static int ipipe_set_rgb2rgb_params(struct vpfe_ipipe_device *ipipe,
495 unsigned int id, void *param)
497 struct vpfe_ipipe_rgb2rgb *rgb2rgb = &ipipe->config.rgb2rgb1;
498 struct device *dev = ipipe->subdev.v4l2_dev->dev;
499 struct vpfe_ipipe_rgb2rgb *rgb2rgb_param;
501 rgb2rgb_param = (struct vpfe_ipipe_rgb2rgb *)param;
503 if (id == IPIPE_RGB2RGB_2)
504 rgb2rgb = &ipipe->config.rgb2rgb2;
506 if (!rgb2rgb_param) {
507 const struct vpfe_ipipe_rgb2rgb rgb2rgb_defaults = {
508 .coef_rr = {1, 0}, /* 256 */
512 .coef_gg = {1, 0}, /* 256 */
516 .coef_bb = {1, 0}, /* 256 */
518 /* Copy defaults for rgb2rgb conversion */
519 memcpy(rgb2rgb, &rgb2rgb_defaults,
520 sizeof(struct vpfe_ipipe_rgb2rgb));
524 memcpy(rgb2rgb, rgb2rgb_param, sizeof(struct vpfe_ipipe_rgb2rgb));
525 if (ipipe_validate_rgb2rgb_params(rgb2rgb, id) < 0) {
526 dev_err(dev, "Invalid rgb2rgb params\n");
531 ipipe_set_rgb2rgb_regs(ipipe->base_addr, id, rgb2rgb);
537 ipipe_set_rgb2rgb_1_params(struct vpfe_ipipe_device *ipipe, void *param)
539 return ipipe_set_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_1, param);
543 ipipe_set_rgb2rgb_2_params(struct vpfe_ipipe_device *ipipe, void *param)
545 return ipipe_set_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_2, param);
548 static int ipipe_get_rgb2rgb_params(struct vpfe_ipipe_device *ipipe,
549 unsigned int id, void *param)
551 struct vpfe_ipipe_rgb2rgb *rgb2rgb = &ipipe->config.rgb2rgb1;
552 struct vpfe_ipipe_rgb2rgb *rgb2rgb_param;
554 rgb2rgb_param = (struct vpfe_ipipe_rgb2rgb *)param;
556 if (id == IPIPE_RGB2RGB_2)
557 rgb2rgb = &ipipe->config.rgb2rgb2;
559 memcpy(rgb2rgb_param, rgb2rgb, sizeof(struct vpfe_ipipe_rgb2rgb));
565 ipipe_get_rgb2rgb_1_params(struct vpfe_ipipe_device *ipipe, void *param)
567 return ipipe_get_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_1, param);
571 ipipe_get_rgb2rgb_2_params(struct vpfe_ipipe_device *ipipe, void *param)
573 return ipipe_get_rgb2rgb_params(ipipe, IPIPE_RGB2RGB_2, param);
577 ipipe_validate_gamma_entry(struct vpfe_ipipe_gamma_entry *table, int size)
584 for (i = 0; i < size; i++)
585 if (table[i].slope > GAMMA_MASK ||
586 table[i].offset > GAMMA_MASK)
593 ipipe_validate_gamma_params(struct vpfe_ipipe_gamma *gamma, struct device *dev)
598 if (gamma->bypass_r > 1 ||
599 gamma->bypass_b > 1 ||
603 if (gamma->tbl_sel != VPFE_IPIPE_GAMMA_TBL_RAM)
606 table_size = gamma->tbl_size;
607 if (!gamma->bypass_r) {
608 err = ipipe_validate_gamma_entry(gamma->table_r, table_size);
610 dev_err(dev, "GAMMA R - table entry invalid\n");
615 if (!gamma->bypass_b) {
616 err = ipipe_validate_gamma_entry(gamma->table_b, table_size);
618 dev_err(dev, "GAMMA B - table entry invalid\n");
623 if (!gamma->bypass_g) {
624 err = ipipe_validate_gamma_entry(gamma->table_g, table_size);
626 dev_err(dev, "GAMMA G - table entry invalid\n");
635 ipipe_set_gamma_params(struct vpfe_ipipe_device *ipipe, void *param)
637 struct vpfe_ipipe_gamma *gamma_param = (struct vpfe_ipipe_gamma *)param;
638 struct vpfe_ipipe_gamma *gamma = &ipipe->config.gamma;
639 struct device *dev = ipipe->subdev.v4l2_dev->dev;
643 memset(gamma, 0, sizeof(struct vpfe_ipipe_gamma));
644 gamma->tbl_sel = VPFE_IPIPE_GAMMA_TBL_ROM;
648 gamma->bypass_r = gamma_param->bypass_r;
649 gamma->bypass_b = gamma_param->bypass_b;
650 gamma->bypass_g = gamma_param->bypass_g;
651 gamma->tbl_sel = gamma_param->tbl_sel;
652 gamma->tbl_size = gamma_param->tbl_size;
654 if (ipipe_validate_gamma_params(gamma, dev) < 0)
657 if (gamma_param->tbl_sel != VPFE_IPIPE_GAMMA_TBL_RAM)
660 table_size = gamma->tbl_size;
661 if (!gamma_param->bypass_r)
662 memcpy(&gamma->table_r, &gamma_param->table_r,
663 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
665 if (!gamma_param->bypass_b)
666 memcpy(&gamma->table_b, &gamma_param->table_b,
667 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
669 if (!gamma_param->bypass_g)
670 memcpy(&gamma->table_g, &gamma_param->table_g,
671 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
674 ipipe_set_gamma_regs(ipipe->base_addr, ipipe->isp5_base_addr, gamma);
679 static int ipipe_get_gamma_params(struct vpfe_ipipe_device *ipipe, void *param)
681 struct vpfe_ipipe_gamma *gamma_param = (struct vpfe_ipipe_gamma *)param;
682 struct vpfe_ipipe_gamma *gamma = &ipipe->config.gamma;
683 struct device *dev = ipipe->subdev.v4l2_dev->dev;
686 gamma_param->bypass_r = gamma->bypass_r;
687 gamma_param->bypass_g = gamma->bypass_g;
688 gamma_param->bypass_b = gamma->bypass_b;
689 gamma_param->tbl_sel = gamma->tbl_sel;
690 gamma_param->tbl_size = gamma->tbl_size;
692 if (gamma->tbl_sel != VPFE_IPIPE_GAMMA_TBL_RAM)
695 table_size = gamma->tbl_size;
697 if (!gamma->bypass_r && !gamma_param->table_r) {
699 "ipipe_get_gamma_params: table ptr empty for R\n");
702 memcpy(gamma_param->table_r, gamma->table_r,
703 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
705 if (!gamma->bypass_g && !gamma_param->table_g) {
706 dev_err(dev, "ipipe_get_gamma_params: table ptr empty for G\n");
709 memcpy(gamma_param->table_g, gamma->table_g,
710 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
712 if (!gamma->bypass_b && !gamma_param->table_b) {
713 dev_err(dev, "ipipe_get_gamma_params: table ptr empty for B\n");
716 memcpy(gamma_param->table_b, gamma->table_b,
717 (table_size * sizeof(struct vpfe_ipipe_gamma_entry)));
722 static int ipipe_validate_3d_lut_params(struct vpfe_ipipe_3d_lut *lut)
729 for (i = 0; i < VPFE_IPIPE_MAX_SIZE_3D_LUT; i++)
730 if (lut->table[i].r > D3_LUT_ENTRY_MASK ||
731 lut->table[i].g > D3_LUT_ENTRY_MASK ||
732 lut->table[i].b > D3_LUT_ENTRY_MASK)
738 static int ipipe_get_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param)
740 struct vpfe_ipipe_3d_lut *lut_param = (struct vpfe_ipipe_3d_lut *)param;
741 struct vpfe_ipipe_3d_lut *lut = &ipipe->config.lut;
742 struct device *dev = ipipe->subdev.v4l2_dev->dev;
744 lut_param->en = lut->en;
745 if (!lut_param->table) {
746 dev_err(dev, "ipipe_get_3d_lut_params: Invalid table ptr\n");
750 memcpy(lut_param->table, &lut->table,
751 (VPFE_IPIPE_MAX_SIZE_3D_LUT *
752 sizeof(struct vpfe_ipipe_3d_lut_entry)));
758 ipipe_set_3d_lut_params(struct vpfe_ipipe_device *ipipe, void *param)
760 struct vpfe_ipipe_3d_lut *lut_param = (struct vpfe_ipipe_3d_lut *)param;
761 struct vpfe_ipipe_3d_lut *lut = &ipipe->config.lut;
762 struct device *dev = ipipe->subdev.v4l2_dev->dev;
765 memset(lut, 0, sizeof(struct vpfe_ipipe_3d_lut));
769 memcpy(lut, lut_param, sizeof(struct vpfe_ipipe_3d_lut));
770 if (ipipe_validate_3d_lut_params(lut) < 0) {
771 dev_err(dev, "Invalid 3D-LUT Params\n");
776 ipipe_set_3d_lut_regs(ipipe->base_addr, ipipe->isp5_base_addr, lut);
781 static int ipipe_validate_rgb2yuv_params(struct vpfe_ipipe_rgb2yuv *rgb2yuv)
783 if (rgb2yuv->coef_ry.decimal > RGB2YCBCR_COEF_DECI_MASK ||
784 rgb2yuv->coef_ry.integer > RGB2YCBCR_COEF_INT_MASK)
787 if (rgb2yuv->coef_gy.decimal > RGB2YCBCR_COEF_DECI_MASK ||
788 rgb2yuv->coef_gy.integer > RGB2YCBCR_COEF_INT_MASK)
791 if (rgb2yuv->coef_by.decimal > RGB2YCBCR_COEF_DECI_MASK ||
792 rgb2yuv->coef_by.integer > RGB2YCBCR_COEF_INT_MASK)
795 if (rgb2yuv->coef_rcb.decimal > RGB2YCBCR_COEF_DECI_MASK ||
796 rgb2yuv->coef_rcb.integer > RGB2YCBCR_COEF_INT_MASK)
799 if (rgb2yuv->coef_gcb.decimal > RGB2YCBCR_COEF_DECI_MASK ||
800 rgb2yuv->coef_gcb.integer > RGB2YCBCR_COEF_INT_MASK)
803 if (rgb2yuv->coef_bcb.decimal > RGB2YCBCR_COEF_DECI_MASK ||
804 rgb2yuv->coef_bcb.integer > RGB2YCBCR_COEF_INT_MASK)
807 if (rgb2yuv->coef_rcr.decimal > RGB2YCBCR_COEF_DECI_MASK ||
808 rgb2yuv->coef_rcr.integer > RGB2YCBCR_COEF_INT_MASK)
811 if (rgb2yuv->coef_gcr.decimal > RGB2YCBCR_COEF_DECI_MASK ||
812 rgb2yuv->coef_gcr.integer > RGB2YCBCR_COEF_INT_MASK)
815 if (rgb2yuv->coef_bcr.decimal > RGB2YCBCR_COEF_DECI_MASK ||
816 rgb2yuv->coef_bcr.integer > RGB2YCBCR_COEF_INT_MASK)
819 if (rgb2yuv->out_ofst_y > RGB2YCBCR_OFST_MASK ||
820 rgb2yuv->out_ofst_cb > RGB2YCBCR_OFST_MASK ||
821 rgb2yuv->out_ofst_cr > RGB2YCBCR_OFST_MASK)
828 ipipe_set_rgb2yuv_params(struct vpfe_ipipe_device *ipipe, void *param)
830 struct vpfe_ipipe_rgb2yuv *rgb2yuv = &ipipe->config.rgb2yuv;
831 struct device *dev = ipipe->subdev.v4l2_dev->dev;
832 struct vpfe_ipipe_rgb2yuv *rgb2yuv_param;
834 rgb2yuv_param = (struct vpfe_ipipe_rgb2yuv *)param;
835 if (!rgb2yuv_param) {
836 /* Defaults for rgb2yuv conversion */
837 const struct vpfe_ipipe_rgb2yuv rgb2yuv_defaults = {
838 .coef_ry = {0, 0x4d},
839 .coef_gy = {0, 0x96},
840 .coef_by = {0, 0x1d},
841 .coef_rcb = {0xf, 0xd5},
842 .coef_gcb = {0xf, 0xab},
843 .coef_bcb = {0, 0x80},
844 .coef_rcr = {0, 0x80},
845 .coef_gcr = {0xf, 0x95},
846 .coef_bcr = {0xf, 0xeb},
850 /* Copy defaults for rgb2yuv conversion */
851 memcpy(rgb2yuv, &rgb2yuv_defaults,
852 sizeof(struct vpfe_ipipe_rgb2yuv));
856 memcpy(rgb2yuv, rgb2yuv_param, sizeof(struct vpfe_ipipe_rgb2yuv));
857 if (ipipe_validate_rgb2yuv_params(rgb2yuv) < 0) {
858 dev_err(dev, "Invalid rgb2yuv params\n");
863 ipipe_set_rgb2ycbcr_regs(ipipe->base_addr, rgb2yuv);
869 ipipe_get_rgb2yuv_params(struct vpfe_ipipe_device *ipipe, void *param)
871 struct vpfe_ipipe_rgb2yuv *rgb2yuv = &ipipe->config.rgb2yuv;
872 struct vpfe_ipipe_rgb2yuv *rgb2yuv_param;
874 rgb2yuv_param = (struct vpfe_ipipe_rgb2yuv *)param;
875 memcpy(rgb2yuv_param, rgb2yuv, sizeof(struct vpfe_ipipe_rgb2yuv));
879 static int ipipe_validate_gbce_params(struct vpfe_ipipe_gbce *gbce)
881 u32 max = GBCE_Y_VAL_MASK;
887 if (gbce->type == VPFE_IPIPE_GBCE_GAIN_TBL)
888 max = GBCE_GAIN_VAL_MASK;
890 for (i = 0; i < VPFE_IPIPE_MAX_SIZE_GBCE_LUT; i++)
891 if (gbce->table[i] > max)
897 static int ipipe_set_gbce_params(struct vpfe_ipipe_device *ipipe, void *param)
899 struct vpfe_ipipe_gbce *gbce_param = (struct vpfe_ipipe_gbce *)param;
900 struct vpfe_ipipe_gbce *gbce = &ipipe->config.gbce;
901 struct device *dev = ipipe->subdev.v4l2_dev->dev;
904 memset(gbce, 0, sizeof(struct vpfe_ipipe_gbce));
906 memcpy(gbce, gbce_param, sizeof(struct vpfe_ipipe_gbce));
907 if (ipipe_validate_gbce_params(gbce) < 0) {
908 dev_err(dev, "Invalid gbce params\n");
913 ipipe_set_gbce_regs(ipipe->base_addr, ipipe->isp5_base_addr, gbce);
918 static int ipipe_get_gbce_params(struct vpfe_ipipe_device *ipipe, void *param)
920 struct vpfe_ipipe_gbce *gbce_param = (struct vpfe_ipipe_gbce *)param;
921 struct vpfe_ipipe_gbce *gbce = &ipipe->config.gbce;
922 struct device *dev = ipipe->subdev.v4l2_dev->dev;
924 gbce_param->en = gbce->en;
925 gbce_param->type = gbce->type;
926 if (!gbce_param->table) {
927 dev_err(dev, "ipipe_get_gbce_params: Invalid table ptr\n");
931 memcpy(gbce_param->table, gbce->table,
932 (VPFE_IPIPE_MAX_SIZE_GBCE_LUT * sizeof(unsigned short)));
938 ipipe_validate_yuv422_conv_params(struct vpfe_ipipe_yuv422_conv *yuv422_conv)
940 if (yuv422_conv->en_chrom_lpf > 1)
947 ipipe_set_yuv422_conv_params(struct vpfe_ipipe_device *ipipe, void *param)
949 struct vpfe_ipipe_yuv422_conv *yuv422_conv = &ipipe->config.yuv422_conv;
950 struct vpfe_ipipe_yuv422_conv *yuv422_conv_param;
951 struct device *dev = ipipe->subdev.v4l2_dev->dev;
953 yuv422_conv_param = (struct vpfe_ipipe_yuv422_conv *)param;
954 if (!yuv422_conv_param) {
955 memset(yuv422_conv, 0, sizeof(struct vpfe_ipipe_yuv422_conv));
956 yuv422_conv->chrom_pos = VPFE_IPIPE_YUV422_CHR_POS_COSITE;
958 memcpy(yuv422_conv, yuv422_conv_param,
959 sizeof(struct vpfe_ipipe_yuv422_conv));
960 if (ipipe_validate_yuv422_conv_params(yuv422_conv) < 0) {
961 dev_err(dev, "Invalid yuv422 params\n");
966 ipipe_set_yuv422_conv_regs(ipipe->base_addr, yuv422_conv);
972 ipipe_get_yuv422_conv_params(struct vpfe_ipipe_device *ipipe, void *param)
974 struct vpfe_ipipe_yuv422_conv *yuv422_conv = &ipipe->config.yuv422_conv;
975 struct vpfe_ipipe_yuv422_conv *yuv422_conv_param;
977 yuv422_conv_param = (struct vpfe_ipipe_yuv422_conv *)param;
978 memcpy(yuv422_conv_param, yuv422_conv,
979 sizeof(struct vpfe_ipipe_yuv422_conv));
984 static int ipipe_validate_yee_params(struct vpfe_ipipe_yee *yee)
989 yee->en_halo_red > 1 ||
990 yee->hpf_shft > YEE_HPF_SHIFT_MASK)
993 if (yee->hpf_coef_00 > YEE_COEF_MASK ||
994 yee->hpf_coef_01 > YEE_COEF_MASK ||
995 yee->hpf_coef_02 > YEE_COEF_MASK ||
996 yee->hpf_coef_10 > YEE_COEF_MASK ||
997 yee->hpf_coef_11 > YEE_COEF_MASK ||
998 yee->hpf_coef_12 > YEE_COEF_MASK ||
999 yee->hpf_coef_20 > YEE_COEF_MASK ||
1000 yee->hpf_coef_21 > YEE_COEF_MASK ||
1001 yee->hpf_coef_22 > YEE_COEF_MASK)
1004 if (yee->yee_thr > YEE_THR_MASK ||
1005 yee->es_gain > YEE_ES_GAIN_MASK ||
1006 yee->es_thr1 > YEE_ES_THR1_MASK ||
1007 yee->es_thr2 > YEE_THR_MASK ||
1008 yee->es_gain_grad > YEE_THR_MASK ||
1009 yee->es_ofst_grad > YEE_THR_MASK)
1012 for (i = 0; i < VPFE_IPIPE_MAX_SIZE_YEE_LUT; i++)
1013 if (yee->table[i] > YEE_ENTRY_MASK)
1019 static int ipipe_set_yee_params(struct vpfe_ipipe_device *ipipe, void *param)
1021 struct vpfe_ipipe_yee *yee_param = (struct vpfe_ipipe_yee *)param;
1022 struct device *dev = ipipe->subdev.v4l2_dev->dev;
1023 struct vpfe_ipipe_yee *yee = &ipipe->config.yee;
1026 memset(yee, 0, sizeof(struct vpfe_ipipe_yee));
1028 memcpy(yee, yee_param, sizeof(struct vpfe_ipipe_yee));
1029 if (ipipe_validate_yee_params(yee) < 0) {
1030 dev_err(dev, "Invalid yee params\n");
1035 ipipe_set_ee_regs(ipipe->base_addr, ipipe->isp5_base_addr, yee);
1040 static int ipipe_get_yee_params(struct vpfe_ipipe_device *ipipe, void *param)
1042 struct vpfe_ipipe_yee *yee_param = (struct vpfe_ipipe_yee *)param;
1043 struct vpfe_ipipe_yee *yee = &ipipe->config.yee;
1045 yee_param->en = yee->en;
1046 yee_param->en_halo_red = yee->en_halo_red;
1047 yee_param->merge_meth = yee->merge_meth;
1048 yee_param->hpf_shft = yee->hpf_shft;
1049 yee_param->hpf_coef_00 = yee->hpf_coef_00;
1050 yee_param->hpf_coef_01 = yee->hpf_coef_01;
1051 yee_param->hpf_coef_02 = yee->hpf_coef_02;
1052 yee_param->hpf_coef_10 = yee->hpf_coef_10;
1053 yee_param->hpf_coef_11 = yee->hpf_coef_11;
1054 yee_param->hpf_coef_12 = yee->hpf_coef_12;
1055 yee_param->hpf_coef_20 = yee->hpf_coef_20;
1056 yee_param->hpf_coef_21 = yee->hpf_coef_21;
1057 yee_param->hpf_coef_22 = yee->hpf_coef_22;
1058 yee_param->yee_thr = yee->yee_thr;
1059 yee_param->es_gain = yee->es_gain;
1060 yee_param->es_thr1 = yee->es_thr1;
1061 yee_param->es_thr2 = yee->es_thr2;
1062 yee_param->es_gain_grad = yee->es_gain_grad;
1063 yee_param->es_ofst_grad = yee->es_ofst_grad;
1064 memcpy(yee_param->table, &yee->table,
1065 (VPFE_IPIPE_MAX_SIZE_YEE_LUT * sizeof(short)));
1070 static int ipipe_validate_car_params(struct vpfe_ipipe_car *car)
1072 if (car->en > 1 || car->hpf_shft > CAR_HPF_SHIFT_MASK ||
1073 car->gain1.shft > CAR_GAIN1_SHFT_MASK ||
1074 car->gain1.gain_min > CAR_GAIN_MIN_MASK ||
1075 car->gain2.shft > CAR_GAIN2_SHFT_MASK ||
1076 car->gain2.gain_min > CAR_GAIN_MIN_MASK)
1082 static int ipipe_set_car_params(struct vpfe_ipipe_device *ipipe, void *param)
1084 struct vpfe_ipipe_car *car_param = (struct vpfe_ipipe_car *)param;
1085 struct device *dev = ipipe->subdev.v4l2_dev->dev;
1086 struct vpfe_ipipe_car *car = &ipipe->config.car;
1089 memset(car, 0, sizeof(struct vpfe_ipipe_car));
1091 memcpy(car, car_param, sizeof(struct vpfe_ipipe_car));
1092 if (ipipe_validate_car_params(car) < 0) {
1093 dev_err(dev, "Invalid car params\n");
1098 ipipe_set_car_regs(ipipe->base_addr, car);
1103 static int ipipe_get_car_params(struct vpfe_ipipe_device *ipipe, void *param)
1105 struct vpfe_ipipe_car *car_param = (struct vpfe_ipipe_car *)param;
1106 struct vpfe_ipipe_car *car = &ipipe->config.car;
1108 memcpy(car_param, car, sizeof(struct vpfe_ipipe_car));
1112 static int ipipe_validate_cgs_params(struct vpfe_ipipe_cgs *cgs)
1114 if (cgs->en > 1 || cgs->h_shft > CAR_SHIFT_MASK)
1120 static int ipipe_set_cgs_params(struct vpfe_ipipe_device *ipipe, void *param)
1122 struct vpfe_ipipe_cgs *cgs_param = (struct vpfe_ipipe_cgs *)param;
1123 struct device *dev = ipipe->subdev.v4l2_dev->dev;
1124 struct vpfe_ipipe_cgs *cgs = &ipipe->config.cgs;
1127 memset(cgs, 0, sizeof(struct vpfe_ipipe_cgs));
1129 memcpy(cgs, cgs_param, sizeof(struct vpfe_ipipe_cgs));
1130 if (ipipe_validate_cgs_params(cgs) < 0) {
1131 dev_err(dev, "Invalid cgs params\n");
1136 ipipe_set_cgs_regs(ipipe->base_addr, cgs);
1141 static int ipipe_get_cgs_params(struct vpfe_ipipe_device *ipipe, void *param)
1143 struct vpfe_ipipe_cgs *cgs_param = (struct vpfe_ipipe_cgs *)param;
1144 struct vpfe_ipipe_cgs *cgs = &ipipe->config.cgs;
1146 memcpy(cgs_param, cgs, sizeof(struct vpfe_ipipe_cgs));
1151 static const struct ipipe_module_if ipipe_modules[VPFE_IPIPE_MAX_MODULES] = {
1152 /* VPFE_IPIPE_INPUT_CONFIG */ {
1153 offsetof(struct ipipe_module_params, input_config),
1154 FIELD_SIZEOF(struct ipipe_module_params, input_config),
1155 offsetof(struct vpfe_ipipe_config, input_config),
1156 ipipe_set_input_config,
1157 ipipe_get_input_config,
1158 }, /* VPFE_IPIPE_LUTDPC */ {
1159 offsetof(struct ipipe_module_params, lutdpc),
1160 FIELD_SIZEOF(struct ipipe_module_params, lutdpc),
1161 offsetof(struct vpfe_ipipe_config, lutdpc),
1162 ipipe_set_lutdpc_params,
1163 ipipe_get_lutdpc_params,
1164 }, /* VPFE_IPIPE_OTFDPC */ {
1165 offsetof(struct ipipe_module_params, otfdpc),
1166 FIELD_SIZEOF(struct ipipe_module_params, otfdpc),
1167 offsetof(struct vpfe_ipipe_config, otfdpc),
1168 ipipe_set_otfdpc_params,
1169 ipipe_get_otfdpc_params,
1170 }, /* VPFE_IPIPE_NF1 */ {
1171 offsetof(struct ipipe_module_params, nf1),
1172 FIELD_SIZEOF(struct ipipe_module_params, nf1),
1173 offsetof(struct vpfe_ipipe_config, nf1),
1174 ipipe_set_nf1_params,
1175 ipipe_get_nf1_params,
1176 }, /* VPFE_IPIPE_NF2 */ {
1177 offsetof(struct ipipe_module_params, nf2),
1178 FIELD_SIZEOF(struct ipipe_module_params, nf2),
1179 offsetof(struct vpfe_ipipe_config, nf2),
1180 ipipe_set_nf2_params,
1181 ipipe_get_nf2_params,
1182 }, /* VPFE_IPIPE_WB */ {
1183 offsetof(struct ipipe_module_params, wbal),
1184 FIELD_SIZEOF(struct ipipe_module_params, wbal),
1185 offsetof(struct vpfe_ipipe_config, wbal),
1186 ipipe_set_wb_params,
1187 ipipe_get_wb_params,
1188 }, /* VPFE_IPIPE_RGB2RGB_1 */ {
1189 offsetof(struct ipipe_module_params, rgb2rgb1),
1190 FIELD_SIZEOF(struct ipipe_module_params, rgb2rgb1),
1191 offsetof(struct vpfe_ipipe_config, rgb2rgb1),
1192 ipipe_set_rgb2rgb_1_params,
1193 ipipe_get_rgb2rgb_1_params,
1194 }, /* VPFE_IPIPE_RGB2RGB_2 */ {
1195 offsetof(struct ipipe_module_params, rgb2rgb2),
1196 FIELD_SIZEOF(struct ipipe_module_params, rgb2rgb2),
1197 offsetof(struct vpfe_ipipe_config, rgb2rgb2),
1198 ipipe_set_rgb2rgb_2_params,
1199 ipipe_get_rgb2rgb_2_params,
1200 }, /* VPFE_IPIPE_GAMMA */ {
1201 offsetof(struct ipipe_module_params, gamma),
1202 FIELD_SIZEOF(struct ipipe_module_params, gamma),
1203 offsetof(struct vpfe_ipipe_config, gamma),
1204 ipipe_set_gamma_params,
1205 ipipe_get_gamma_params,
1206 }, /* VPFE_IPIPE_3D_LUT */ {
1207 offsetof(struct ipipe_module_params, lut),
1208 FIELD_SIZEOF(struct ipipe_module_params, lut),
1209 offsetof(struct vpfe_ipipe_config, lut),
1210 ipipe_set_3d_lut_params,
1211 ipipe_get_3d_lut_params,
1212 }, /* VPFE_IPIPE_RGB2YUV */ {
1213 offsetof(struct ipipe_module_params, rgb2yuv),
1214 FIELD_SIZEOF(struct ipipe_module_params, rgb2yuv),
1215 offsetof(struct vpfe_ipipe_config, rgb2yuv),
1216 ipipe_set_rgb2yuv_params,
1217 ipipe_get_rgb2yuv_params,
1218 }, /* VPFE_IPIPE_YUV422_CONV */ {
1219 offsetof(struct ipipe_module_params, yuv422_conv),
1220 FIELD_SIZEOF(struct ipipe_module_params, yuv422_conv),
1221 offsetof(struct vpfe_ipipe_config, yuv422_conv),
1222 ipipe_set_yuv422_conv_params,
1223 ipipe_get_yuv422_conv_params,
1224 }, /* VPFE_IPIPE_YEE */ {
1225 offsetof(struct ipipe_module_params, yee),
1226 FIELD_SIZEOF(struct ipipe_module_params, yee),
1227 offsetof(struct vpfe_ipipe_config, yee),
1228 ipipe_set_yee_params,
1229 ipipe_get_yee_params,
1230 }, /* VPFE_IPIPE_GIC */ {
1231 offsetof(struct ipipe_module_params, gic),
1232 FIELD_SIZEOF(struct ipipe_module_params, gic),
1233 offsetof(struct vpfe_ipipe_config, gic),
1234 ipipe_set_gic_params,
1235 ipipe_get_gic_params,
1236 }, /* VPFE_IPIPE_CFA */ {
1237 offsetof(struct ipipe_module_params, cfa),
1238 FIELD_SIZEOF(struct ipipe_module_params, cfa),
1239 offsetof(struct vpfe_ipipe_config, cfa),
1240 ipipe_set_cfa_params,
1241 ipipe_get_cfa_params,
1242 }, /* VPFE_IPIPE_CAR */ {
1243 offsetof(struct ipipe_module_params, car),
1244 FIELD_SIZEOF(struct ipipe_module_params, car),
1245 offsetof(struct vpfe_ipipe_config, car),
1246 ipipe_set_car_params,
1247 ipipe_get_car_params,
1248 }, /* VPFE_IPIPE_CGS */ {
1249 offsetof(struct ipipe_module_params, cgs),
1250 FIELD_SIZEOF(struct ipipe_module_params, cgs),
1251 offsetof(struct vpfe_ipipe_config, cgs),
1252 ipipe_set_cgs_params,
1253 ipipe_get_cgs_params,
1254 }, /* VPFE_IPIPE_GBCE */ {
1255 offsetof(struct ipipe_module_params, gbce),
1256 FIELD_SIZEOF(struct ipipe_module_params, gbce),
1257 offsetof(struct vpfe_ipipe_config, gbce),
1258 ipipe_set_gbce_params,
1259 ipipe_get_gbce_params,
1263 static int ipipe_s_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg)
1265 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1269 for (i = 0; i < ARRAY_SIZE(ipipe_modules); i++) {
1270 unsigned int bit = 1 << i;
1272 if (cfg->flag & bit) {
1273 const struct ipipe_module_if *module_if =
1275 struct ipipe_module_params *params;
1276 void __user *from = *(void * __user *)
1277 ((void *)cfg + module_if->config_offset);
1281 params = kmalloc(sizeof(struct ipipe_module_params),
1283 to = (void *)params + module_if->param_offset;
1284 size = module_if->param_size;
1286 if (to && from && size) {
1287 if (copy_from_user(to, from, size)) {
1291 rval = module_if->set(ipipe, to);
1294 } else if (to && !from && size) {
1295 rval = module_if->set(ipipe, NULL);
1306 static int ipipe_g_config(struct v4l2_subdev *sd, struct vpfe_ipipe_config *cfg)
1308 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1312 for (i = 1; i < ARRAY_SIZE(ipipe_modules); i++) {
1313 unsigned int bit = 1 << i;
1315 if (cfg->flag & bit) {
1316 const struct ipipe_module_if *module_if =
1318 struct ipipe_module_params *params;
1319 void __user *to = *(void * __user *)
1320 ((void *)cfg + module_if->config_offset);
1324 params = kmalloc(sizeof(struct ipipe_module_params),
1326 from = (void *)params + module_if->param_offset;
1327 size = module_if->param_size;
1329 if (to && from && size) {
1330 rval = module_if->get(ipipe, from);
1333 if (copy_to_user(to, from, size)) {
1346 * ipipe_ioctl() - Handle ipipe module private ioctl's
1347 * @sd: pointer to v4l2 subdev structure
1348 * @cmd: configuration command
1349 * @arg: configuration argument
1351 static long ipipe_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1356 case VIDIOC_VPFE_IPIPE_S_CONFIG:
1357 ret = ipipe_s_config(sd, arg);
1360 case VIDIOC_VPFE_IPIPE_G_CONFIG:
1361 ret = ipipe_g_config(sd, arg);
1370 void vpfe_ipipe_enable(struct vpfe_device *vpfe_dev, int en)
1372 struct vpfe_ipipeif_device *ipipeif = &vpfe_dev->vpfe_ipipeif;
1373 struct vpfe_ipipe_device *ipipe = &vpfe_dev->vpfe_ipipe;
1376 if (ipipe->input == IPIPE_INPUT_NONE)
1379 /* ipipe is set to single shot */
1380 if (ipipeif->input == IPIPEIF_INPUT_MEMORY && en) {
1381 /* for single-shot mode, need to wait for h/w to
1382 * reset many register bits
1385 val = regr_ip(vpfe_dev->vpfe_ipipe.base_addr,
1389 regw_ip(vpfe_dev->vpfe_ipipe.base_addr, en, IPIPE_SRC_EN);
1393 * ipipe_set_stream() - Enable/Disable streaming on the ipipe subdevice
1394 * @sd: pointer to v4l2 subdev structure
1395 * @enable: 1 == Enable, 0 == Disable
1397 static int ipipe_set_stream(struct v4l2_subdev *sd, int enable)
1399 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1400 struct vpfe_device *vpfe_dev = to_vpfe_device(ipipe);
1402 if (enable && ipipe->input != IPIPE_INPUT_NONE &&
1403 ipipe->output != IPIPE_OUTPUT_NONE) {
1404 if (config_ipipe_hw(ipipe) < 0)
1408 vpfe_ipipe_enable(vpfe_dev, enable);
1414 * __ipipe_get_format() - helper function for getting ipipe format
1415 * @ipipe: pointer to ipipe private structure.
1417 * @cfg: V4L2 subdev pad config
1418 * @which: wanted subdev format.
1421 static struct v4l2_mbus_framefmt *
1422 __ipipe_get_format(struct vpfe_ipipe_device *ipipe,
1423 struct v4l2_subdev_pad_config *cfg, unsigned int pad,
1424 enum v4l2_subdev_format_whence which)
1426 if (which == V4L2_SUBDEV_FORMAT_TRY)
1427 return v4l2_subdev_get_try_format(&ipipe->subdev, cfg, pad);
1429 return &ipipe->formats[pad];
1433 * ipipe_try_format() - Handle try format by pad subdev method
1434 * @ipipe: VPFE ipipe device.
1435 * @cfg: V4L2 subdev pad config
1437 * @fmt: pointer to v4l2 format structure.
1438 * @which : wanted subdev format
1441 ipipe_try_format(struct vpfe_ipipe_device *ipipe,
1442 struct v4l2_subdev_pad_config *cfg, unsigned int pad,
1443 struct v4l2_mbus_framefmt *fmt,
1444 enum v4l2_subdev_format_whence which)
1446 unsigned int max_out_height;
1447 unsigned int max_out_width;
1450 max_out_width = IPIPE_MAX_OUTPUT_WIDTH_A;
1451 max_out_height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1453 if (pad == IPIPE_PAD_SINK) {
1454 for (i = 0; i < ARRAY_SIZE(ipipe_input_fmts); i++)
1455 if (fmt->code == ipipe_input_fmts[i])
1458 /* If not found, use SBGGR10 as default */
1459 if (i >= ARRAY_SIZE(ipipe_input_fmts))
1460 fmt->code = MEDIA_BUS_FMT_SGRBG12_1X12;
1461 } else if (pad == IPIPE_PAD_SOURCE) {
1462 for (i = 0; i < ARRAY_SIZE(ipipe_output_fmts); i++)
1463 if (fmt->code == ipipe_output_fmts[i])
1466 /* If not found, use UYVY as default */
1467 if (i >= ARRAY_SIZE(ipipe_output_fmts))
1468 fmt->code = MEDIA_BUS_FMT_UYVY8_2X8;
1471 fmt->width = clamp_t(u32, fmt->width, MIN_OUT_HEIGHT, max_out_width);
1472 fmt->height = clamp_t(u32, fmt->height, MIN_OUT_WIDTH, max_out_height);
1476 * ipipe_set_format() - Handle set format by pads subdev method
1477 * @sd: pointer to v4l2 subdev structure
1478 * @cfg: V4L2 subdev pad config
1479 * @fmt: pointer to v4l2 subdev format structure
1480 * return -EINVAL or zero on success
1483 ipipe_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
1484 struct v4l2_subdev_format *fmt)
1486 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1487 struct v4l2_mbus_framefmt *format;
1489 format = __ipipe_get_format(ipipe, cfg, fmt->pad, fmt->which);
1493 ipipe_try_format(ipipe, cfg, fmt->pad, &fmt->format, fmt->which);
1494 *format = fmt->format;
1496 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
1499 if (fmt->pad == IPIPE_PAD_SINK &&
1500 (ipipe->input == IPIPE_INPUT_CCDC ||
1501 ipipe->input == IPIPE_INPUT_MEMORY))
1502 ipipe->formats[fmt->pad] = fmt->format;
1503 else if (fmt->pad == IPIPE_PAD_SOURCE &&
1504 ipipe->output == IPIPE_OUTPUT_RESIZER)
1505 ipipe->formats[fmt->pad] = fmt->format;
1513 * ipipe_get_format() - Handle get format by pads subdev method.
1514 * @sd: pointer to v4l2 subdev structure.
1515 * @cfg: V4L2 subdev pad config
1516 * @fmt: pointer to v4l2 subdev format structure.
1519 ipipe_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
1520 struct v4l2_subdev_format *fmt)
1522 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1524 if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE)
1525 fmt->format = ipipe->formats[fmt->pad];
1527 fmt->format = *(v4l2_subdev_get_try_format(sd, cfg, fmt->pad));
1533 * ipipe_enum_frame_size() - enum frame sizes on pads
1534 * @sd: pointer to v4l2 subdev structure.
1535 * @cfg: V4L2 subdev pad config
1536 * @fse: pointer to v4l2_subdev_frame_size_enum structure.
1539 ipipe_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
1540 struct v4l2_subdev_frame_size_enum *fse)
1542 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1543 struct v4l2_mbus_framefmt format;
1545 if (fse->index != 0)
1548 format.code = fse->code;
1551 ipipe_try_format(ipipe, cfg, fse->pad, &format, fse->which);
1552 fse->min_width = format.width;
1553 fse->min_height = format.height;
1555 if (format.code != fse->code)
1558 format.code = fse->code;
1561 ipipe_try_format(ipipe, cfg, fse->pad, &format, fse->which);
1562 fse->max_width = format.width;
1563 fse->max_height = format.height;
1569 * ipipe_enum_mbus_code() - enum mbus codes for pads
1570 * @sd: pointer to v4l2 subdev structure.
1571 * @cfg: V4L2 subdev pad config
1572 * @code: pointer to v4l2_subdev_mbus_code_enum structure
1575 ipipe_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg,
1576 struct v4l2_subdev_mbus_code_enum *code)
1578 switch (code->pad) {
1579 case IPIPE_PAD_SINK:
1580 if (code->index >= ARRAY_SIZE(ipipe_input_fmts))
1582 code->code = ipipe_input_fmts[code->index];
1585 case IPIPE_PAD_SOURCE:
1586 if (code->index >= ARRAY_SIZE(ipipe_output_fmts))
1588 code->code = ipipe_output_fmts[code->index];
1599 * ipipe_s_ctrl() - Handle set control subdev method
1600 * @ctrl: pointer to v4l2 control structure
1602 static int ipipe_s_ctrl(struct v4l2_ctrl *ctrl)
1604 struct vpfe_ipipe_device *ipipe =
1605 container_of(ctrl->handler, struct vpfe_ipipe_device, ctrls);
1606 struct ipipe_lum_adj *lum_adj = &ipipe->config.lum_adj;
1609 case V4L2_CID_BRIGHTNESS:
1610 lum_adj->brightness = ctrl->val;
1611 ipipe_set_lum_adj_regs(ipipe->base_addr, lum_adj);
1614 case V4L2_CID_CONTRAST:
1615 lum_adj->contrast = ctrl->val;
1616 ipipe_set_lum_adj_regs(ipipe->base_addr, lum_adj);
1627 * ipipe_init_formats() - Initialize formats on all pads
1628 * @sd: pointer to v4l2 subdev structure.
1629 * @fh: V4L2 subdev file handle
1631 * Initialize all pad formats with default values. Try formats are initialized
1632 * on the file handle.
1635 ipipe_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1637 struct v4l2_subdev_format format;
1639 memset(&format, 0, sizeof(format));
1640 format.pad = IPIPE_PAD_SINK;
1641 format.which = V4L2_SUBDEV_FORMAT_TRY;
1642 format.format.code = MEDIA_BUS_FMT_SGRBG12_1X12;
1643 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_A;
1644 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1645 ipipe_set_format(sd, fh->pad, &format);
1647 memset(&format, 0, sizeof(format));
1648 format.pad = IPIPE_PAD_SOURCE;
1649 format.which = V4L2_SUBDEV_FORMAT_TRY;
1650 format.format.code = MEDIA_BUS_FMT_UYVY8_2X8;
1651 format.format.width = IPIPE_MAX_OUTPUT_WIDTH_A;
1652 format.format.height = IPIPE_MAX_OUTPUT_HEIGHT_A;
1653 ipipe_set_format(sd, fh->pad, &format);
1658 /* subdev core operations */
1659 static const struct v4l2_subdev_core_ops ipipe_v4l2_core_ops = {
1660 .ioctl = ipipe_ioctl,
1663 static const struct v4l2_ctrl_ops ipipe_ctrl_ops = {
1664 .s_ctrl = ipipe_s_ctrl,
1667 /* subdev file operations */
1668 static const struct v4l2_subdev_internal_ops ipipe_v4l2_internal_ops = {
1669 .open = ipipe_init_formats,
1672 /* subdev video operations */
1673 static const struct v4l2_subdev_video_ops ipipe_v4l2_video_ops = {
1674 .s_stream = ipipe_set_stream,
1677 /* subdev pad operations */
1678 static const struct v4l2_subdev_pad_ops ipipe_v4l2_pad_ops = {
1679 .enum_mbus_code = ipipe_enum_mbus_code,
1680 .enum_frame_size = ipipe_enum_frame_size,
1681 .get_fmt = ipipe_get_format,
1682 .set_fmt = ipipe_set_format,
1685 /* v4l2 subdev operation */
1686 static const struct v4l2_subdev_ops ipipe_v4l2_ops = {
1687 .core = &ipipe_v4l2_core_ops,
1688 .video = &ipipe_v4l2_video_ops,
1689 .pad = &ipipe_v4l2_pad_ops,
1693 * Media entity operations
1697 * ipipe_link_setup() - Setup ipipe connections
1698 * @entity: ipipe media entity
1699 * @local: Pad at the local end of the link
1700 * @remote: Pad at the remote end of the link
1701 * @flags: Link flags
1703 * return -EINVAL or zero on success
1706 ipipe_link_setup(struct media_entity *entity, const struct media_pad *local,
1707 const struct media_pad *remote, u32 flags)
1709 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
1710 struct vpfe_ipipe_device *ipipe = v4l2_get_subdevdata(sd);
1711 struct vpfe_device *vpfe_dev = to_vpfe_device(ipipe);
1712 u16 ipipeif_sink = vpfe_dev->vpfe_ipipeif.input;
1714 switch (local->index | media_entity_type(remote->entity)) {
1715 case IPIPE_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
1716 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
1717 ipipe->input = IPIPE_INPUT_NONE;
1720 if (ipipe->input != IPIPE_INPUT_NONE)
1722 if (ipipeif_sink == IPIPEIF_INPUT_MEMORY)
1723 ipipe->input = IPIPE_INPUT_MEMORY;
1725 ipipe->input = IPIPE_INPUT_CCDC;
1728 case IPIPE_PAD_SOURCE | MEDIA_ENT_T_V4L2_SUBDEV:
1729 /* out to RESIZER */
1730 if (flags & MEDIA_LNK_FL_ENABLED)
1731 ipipe->output = IPIPE_OUTPUT_RESIZER;
1733 ipipe->output = IPIPE_OUTPUT_NONE;
1743 static const struct media_entity_operations ipipe_media_ops = {
1744 .link_setup = ipipe_link_setup,
1748 * vpfe_ipipe_unregister_entities() - ipipe unregister entity
1749 * @vpfe_ipipe: pointer to ipipe subdevice structure.
1751 void vpfe_ipipe_unregister_entities(struct vpfe_ipipe_device *vpfe_ipipe)
1753 /* unregister subdev */
1754 v4l2_device_unregister_subdev(&vpfe_ipipe->subdev);
1755 /* cleanup entity */
1756 media_entity_cleanup(&vpfe_ipipe->subdev.entity);
1760 * vpfe_ipipe_register_entities() - ipipe register entity
1761 * @ipipe: pointer to ipipe subdevice structure.
1762 * @vdev: pointer to v4l2 device structure.
1765 vpfe_ipipe_register_entities(struct vpfe_ipipe_device *ipipe,
1766 struct v4l2_device *vdev)
1770 /* Register the subdev */
1771 ret = v4l2_device_register_subdev(vdev, &ipipe->subdev);
1773 pr_err("Failed to register ipipe as v4l2 subdevice\n");
1780 #define IPIPE_CONTRAST_HIGH 0xff
1781 #define IPIPE_BRIGHT_HIGH 0xff
1784 * vpfe_ipipe_init() - ipipe module initialization.
1785 * @ipipe: pointer to ipipe subdevice structure.
1786 * @pdev: platform device pointer.
1789 vpfe_ipipe_init(struct vpfe_ipipe_device *ipipe, struct platform_device *pdev)
1791 struct media_pad *pads = &ipipe->pads[0];
1792 struct v4l2_subdev *sd = &ipipe->subdev;
1793 struct media_entity *me = &sd->entity;
1794 static resource_size_t res_len;
1795 struct resource *res;
1797 res = platform_get_resource(pdev, IORESOURCE_MEM, 4);
1801 res_len = resource_size(res);
1802 res = request_mem_region(res->start, res_len, res->name);
1805 ipipe->base_addr = ioremap_nocache(res->start, res_len);
1806 if (!ipipe->base_addr)
1809 res = platform_get_resource(pdev, IORESOURCE_MEM, 6);
1812 ipipe->isp5_base_addr = ioremap_nocache(res->start, res_len);
1813 if (!ipipe->isp5_base_addr)
1816 v4l2_subdev_init(sd, &ipipe_v4l2_ops);
1817 sd->internal_ops = &ipipe_v4l2_internal_ops;
1818 strlcpy(sd->name, "DAVINCI IPIPE", sizeof(sd->name));
1819 sd->grp_id = 1 << 16; /* group ID for davinci subdevs */
1820 v4l2_set_subdevdata(sd, ipipe);
1821 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1823 pads[IPIPE_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
1824 pads[IPIPE_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
1826 ipipe->input = IPIPE_INPUT_NONE;
1827 ipipe->output = IPIPE_OUTPUT_NONE;
1829 me->ops = &ipipe_media_ops;
1830 v4l2_ctrl_handler_init(&ipipe->ctrls, 2);
1831 v4l2_ctrl_new_std(&ipipe->ctrls, &ipipe_ctrl_ops,
1832 V4L2_CID_BRIGHTNESS, 0,
1833 IPIPE_BRIGHT_HIGH, 1, 16);
1834 v4l2_ctrl_new_std(&ipipe->ctrls, &ipipe_ctrl_ops,
1835 V4L2_CID_CONTRAST, 0,
1836 IPIPE_CONTRAST_HIGH, 1, 16);
1839 v4l2_ctrl_handler_setup(&ipipe->ctrls);
1840 sd->ctrl_handler = &ipipe->ctrls;
1842 return media_entity_init(me, IPIPE_PADS_NUM, pads, 0);
1846 * vpfe_ipipe_cleanup() - ipipe subdevice cleanup.
1847 * @ipipe: pointer to ipipe subdevice
1848 * @dev: pointer to platform device
1850 void vpfe_ipipe_cleanup(struct vpfe_ipipe_device *ipipe,
1851 struct platform_device *pdev)
1853 struct resource *res;
1855 v4l2_ctrl_handler_free(&ipipe->ctrls);
1857 iounmap(ipipe->base_addr);
1858 iounmap(ipipe->isp5_base_addr);
1859 res = platform_get_resource(pdev, IORESOURCE_MEM, 4);
1861 release_mem_region(res->start, resource_size(res));