Lines Matching refs:isc
42 static inline void isc_update_v4l2_ctrls(struct isc_device *isc) in isc_update_v4l2_ctrls() argument
44 struct isc_ctrls *ctrls = &isc->ctrls; in isc_update_v4l2_ctrls()
47 v4l2_ctrl_s_ctrl(isc->r_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_R]); in isc_update_v4l2_ctrls()
48 v4l2_ctrl_s_ctrl(isc->b_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_B]); in isc_update_v4l2_ctrls()
49 v4l2_ctrl_s_ctrl(isc->gr_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_GR]); in isc_update_v4l2_ctrls()
50 v4l2_ctrl_s_ctrl(isc->gb_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_GB]); in isc_update_v4l2_ctrls()
52 v4l2_ctrl_s_ctrl(isc->r_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_R]); in isc_update_v4l2_ctrls()
53 v4l2_ctrl_s_ctrl(isc->b_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_B]); in isc_update_v4l2_ctrls()
54 v4l2_ctrl_s_ctrl(isc->gr_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_GR]); in isc_update_v4l2_ctrls()
55 v4l2_ctrl_s_ctrl(isc->gb_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_GB]); in isc_update_v4l2_ctrls()
58 static inline void isc_update_awb_ctrls(struct isc_device *isc) in isc_update_awb_ctrls() argument
60 struct isc_ctrls *ctrls = &isc->ctrls; in isc_update_awb_ctrls()
64 regmap_write(isc->regmap, ISC_WB_O_RGR, in isc_update_awb_ctrls()
67 regmap_write(isc->regmap, ISC_WB_O_BGB, in isc_update_awb_ctrls()
70 regmap_write(isc->regmap, ISC_WB_G_RGR, in isc_update_awb_ctrls()
73 regmap_write(isc->regmap, ISC_WB_G_BGB, in isc_update_awb_ctrls()
78 static inline void isc_reset_awb_ctrls(struct isc_device *isc) in isc_reset_awb_ctrls() argument
84 isc->ctrls.gain[c] = 1 << 9; in isc_reset_awb_ctrls()
86 isc->ctrls.offset[c] = 0; in isc_reset_awb_ctrls()
94 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_queue_setup() local
95 unsigned int size = isc->fmt.fmt.pix.sizeimage; in isc_queue_setup()
109 struct isc_device *isc = vb2_get_drv_priv(vb->vb2_queue); in isc_buffer_prepare() local
110 unsigned long size = isc->fmt.fmt.pix.sizeimage; in isc_buffer_prepare()
113 dev_err(isc->dev, "buffer too small (%lu < %lu)\n", in isc_buffer_prepare()
120 vbuf->field = isc->fmt.fmt.pix.field; in isc_buffer_prepare()
125 static void isc_crop_pfe(struct isc_device *isc) in isc_crop_pfe() argument
127 struct regmap *regmap = isc->regmap; in isc_crop_pfe()
130 h = isc->fmt.fmt.pix.height; in isc_crop_pfe()
131 w = isc->fmt.fmt.pix.width; in isc_crop_pfe()
139 if (!ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) { in isc_crop_pfe()
164 static void isc_start_dma(struct isc_device *isc) in isc_start_dma() argument
166 struct regmap *regmap = isc->regmap; in isc_start_dma()
167 u32 sizeimage = isc->fmt.fmt.pix.sizeimage; in isc_start_dma()
171 addr0 = vb2_dma_contig_plane_dma_addr(&isc->cur_frm->vb.vb2_buf, 0); in isc_start_dma()
172 regmap_write(regmap, ISC_DAD0 + isc->offsets.dma, addr0); in isc_start_dma()
174 switch (isc->config.fourcc) { in isc_start_dma()
176 regmap_write(regmap, ISC_DAD1 + isc->offsets.dma, in isc_start_dma()
178 regmap_write(regmap, ISC_DAD2 + isc->offsets.dma, in isc_start_dma()
182 regmap_write(regmap, ISC_DAD1 + isc->offsets.dma, in isc_start_dma()
184 regmap_write(regmap, ISC_DAD2 + isc->offsets.dma, in isc_start_dma()
191 dctrl_dview = isc->config.dctrl_dview; in isc_start_dma()
193 regmap_write(regmap, ISC_DCTRL + isc->offsets.dma, in isc_start_dma()
195 spin_lock(&isc->awb_lock); in isc_start_dma()
197 spin_unlock(&isc->awb_lock); in isc_start_dma()
200 static void isc_set_pipeline(struct isc_device *isc, u32 pipeline) in isc_set_pipeline() argument
202 struct regmap *regmap = isc->regmap; in isc_set_pipeline()
203 struct isc_ctrls *ctrls = &isc->ctrls; in isc_set_pipeline()
211 regmap_field_write(isc->pipeline[i], val); in isc_set_pipeline()
217 bay_cfg = isc->config.sd_format->cfa_baycfg; in isc_set_pipeline()
220 isc_update_awb_ctrls(isc); in isc_set_pipeline()
221 isc_update_v4l2_ctrls(isc); in isc_set_pipeline()
225 gamma = &isc->gamma_table[ctrls->gamma_index][0]; in isc_set_pipeline()
230 isc->config_dpc(isc); in isc_set_pipeline()
231 isc->config_csc(isc); in isc_set_pipeline()
232 isc->config_cbc(isc); in isc_set_pipeline()
233 isc->config_cc(isc); in isc_set_pipeline()
234 isc->config_gam(isc); in isc_set_pipeline()
237 static int isc_update_profile(struct isc_device *isc) in isc_update_profile() argument
239 struct regmap *regmap = isc->regmap; in isc_update_profile()
252 v4l2_warn(&isc->v4l2_dev, "Time out to update profile\n"); in isc_update_profile()
259 static void isc_set_histogram(struct isc_device *isc, bool enable) in isc_set_histogram() argument
261 struct regmap *regmap = isc->regmap; in isc_set_histogram()
262 struct isc_ctrls *ctrls = &isc->ctrls; in isc_set_histogram()
265 regmap_write(regmap, ISC_HIS_CFG + isc->offsets.his, in isc_set_histogram()
267 (isc->config.sd_format->cfa_baycfg in isc_set_histogram()
270 regmap_write(regmap, ISC_HIS_CTRL + isc->offsets.his, in isc_set_histogram()
274 isc_update_profile(isc); in isc_set_histogram()
280 regmap_write(regmap, ISC_HIS_CTRL + isc->offsets.his, in isc_set_histogram()
287 static int isc_configure(struct isc_device *isc) in isc_configure() argument
289 struct regmap *regmap = isc->regmap; in isc_configure()
291 struct isc_subdev_entity *subdev = isc->current_subdev; in isc_configure()
293 pfe_cfg0 = isc->config.sd_format->pfe_cfg0_bps; in isc_configure()
294 pipeline = isc->config.bits_pipeline; in isc_configure()
296 dcfg = isc->config.dcfg_imode | isc->dcfg; in isc_configure()
306 isc->config_rlp(isc); in isc_configure()
308 regmap_write(regmap, ISC_DCFG + isc->offsets.dma, dcfg); in isc_configure()
311 isc_set_pipeline(isc, pipeline); in isc_configure()
317 if (isc->ctrls.awb && in isc_configure()
318 ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) in isc_configure()
319 isc_set_histogram(isc, true); in isc_configure()
321 isc_set_histogram(isc, false); in isc_configure()
324 return isc_update_profile(isc); in isc_configure()
329 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_prepare_streaming() local
331 return media_pipeline_start(isc->video_dev.entity.pads, &isc->mpipe); in isc_prepare_streaming()
336 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_start_streaming() local
337 struct regmap *regmap = isc->regmap; in isc_start_streaming()
343 ret = v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 1); in isc_start_streaming()
345 dev_err(isc->dev, "stream on failed in subdev %d\n", ret); in isc_start_streaming()
349 ret = pm_runtime_resume_and_get(isc->dev); in isc_start_streaming()
351 dev_err(isc->dev, "RPM resume failed in subdev %d\n", in isc_start_streaming()
356 ret = isc_configure(isc); in isc_start_streaming()
363 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_start_streaming()
365 isc->sequence = 0; in isc_start_streaming()
366 isc->stop = false; in isc_start_streaming()
367 reinit_completion(&isc->comp); in isc_start_streaming()
369 isc->cur_frm = list_first_entry(&isc->dma_queue, in isc_start_streaming()
371 list_del(&isc->cur_frm->list); in isc_start_streaming()
373 isc_crop_pfe(isc); in isc_start_streaming()
374 isc_start_dma(isc); in isc_start_streaming()
376 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_start_streaming()
379 if (ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) in isc_start_streaming()
380 v4l2_ctrl_activate(isc->do_wb_ctrl, true); in isc_start_streaming()
385 pm_runtime_put_sync(isc->dev); in isc_start_streaming()
387 v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0); in isc_start_streaming()
390 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_start_streaming()
391 list_for_each_entry(buf, &isc->dma_queue, list) in isc_start_streaming()
393 INIT_LIST_HEAD(&isc->dma_queue); in isc_start_streaming()
394 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_start_streaming()
401 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_unprepare_streaming() local
404 media_pipeline_stop(isc->video_dev.entity.pads); in isc_unprepare_streaming()
409 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_stop_streaming() local
414 mutex_lock(&isc->awb_mutex); in isc_stop_streaming()
415 v4l2_ctrl_activate(isc->do_wb_ctrl, false); in isc_stop_streaming()
417 isc->stop = true; in isc_stop_streaming()
420 if (isc->cur_frm && !wait_for_completion_timeout(&isc->comp, 5 * HZ)) in isc_stop_streaming()
421 dev_err(isc->dev, "Timeout waiting for end of the capture\n"); in isc_stop_streaming()
423 mutex_unlock(&isc->awb_mutex); in isc_stop_streaming()
426 regmap_write(isc->regmap, ISC_INTDIS, ISC_INT_DDONE); in isc_stop_streaming()
428 pm_runtime_put_sync(isc->dev); in isc_stop_streaming()
431 ret = v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0); in isc_stop_streaming()
433 dev_err(isc->dev, "stream off failed in subdev\n"); in isc_stop_streaming()
436 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_stop_streaming()
437 if (unlikely(isc->cur_frm)) { in isc_stop_streaming()
438 vb2_buffer_done(&isc->cur_frm->vb.vb2_buf, in isc_stop_streaming()
440 isc->cur_frm = NULL; in isc_stop_streaming()
442 list_for_each_entry(buf, &isc->dma_queue, list) in isc_stop_streaming()
444 INIT_LIST_HEAD(&isc->dma_queue); in isc_stop_streaming()
445 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_stop_streaming()
452 struct isc_device *isc = vb2_get_drv_priv(vb->vb2_queue); in isc_buffer_queue() local
455 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_buffer_queue()
456 if (!isc->cur_frm && list_empty(&isc->dma_queue) && in isc_buffer_queue()
458 isc->cur_frm = buf; in isc_buffer_queue()
459 isc_start_dma(isc); in isc_buffer_queue()
461 list_add_tail(&buf->list, &isc->dma_queue); in isc_buffer_queue()
463 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_buffer_queue()
481 struct isc_device *isc = video_drvdata(file); in isc_querycap() local
486 "platform:%s", isc->v4l2_dev.name); in isc_querycap()
494 struct isc_device *isc = video_drvdata(file); in isc_enum_fmt_vid_cap() local
504 if (index >= isc->controller_formats_size) in isc_enum_fmt_vid_cap()
507 f->pixelformat = isc->controller_formats[index].fourcc; in isc_enum_fmt_vid_cap()
520 fmt = isc_find_format_by_code(isc, f->mbus_code, &i); in isc_enum_fmt_vid_cap()
542 for (i = 0; i < isc->controller_formats_size; i++) { in isc_enum_fmt_vid_cap()
543 if (isc->controller_formats[i].raw) in isc_enum_fmt_vid_cap()
546 f->pixelformat = isc->controller_formats[i].fourcc; in isc_enum_fmt_vid_cap()
558 struct isc_device *isc = video_drvdata(file); in isc_g_fmt_vid_cap() local
560 *fmt = isc->fmt; in isc_g_fmt_vid_cap()
569 static int isc_try_validate_formats(struct isc_device *isc) in isc_try_validate_formats() argument
575 switch (isc->try_config.fourcc) { in isc_try_validate_formats()
617 dev_err(isc->dev, "Requested unsupported format.\n"); in isc_try_validate_formats()
620 dev_dbg(isc->dev, in isc_try_validate_formats()
625 !ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_validate_formats()
626 dev_err(isc->dev, "Cannot output RAW if we do not receive RAW.\n"); in isc_try_validate_formats()
630 if (grey && !ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code) && in isc_try_validate_formats()
631 !ISC_IS_FORMAT_GREY(isc->try_config.sd_format->mbus_code)) { in isc_try_validate_formats()
632 dev_err(isc->dev, "Cannot output GREY if we do not receive RAW/GREY.\n"); in isc_try_validate_formats()
637 ISC_IS_FORMAT_GREY(isc->try_config.sd_format->mbus_code)) { in isc_try_validate_formats()
638 dev_err(isc->dev, "Cannot convert GREY to another format.\n"); in isc_try_validate_formats()
650 static int isc_try_configure_rlp_dma(struct isc_device *isc, bool direct_dump) in isc_try_configure_rlp_dma() argument
652 isc->try_config.rlp_cfg_mode = 0; in isc_try_configure_rlp_dma()
654 switch (isc->try_config.fourcc) { in isc_try_configure_rlp_dma()
659 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT8; in isc_try_configure_rlp_dma()
660 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8; in isc_try_configure_rlp_dma()
661 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
662 isc->try_config.bpp = 8; in isc_try_configure_rlp_dma()
663 isc->try_config.bpp_v4l2 = 8; in isc_try_configure_rlp_dma()
669 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT10; in isc_try_configure_rlp_dma()
670 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
671 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
672 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
673 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
679 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT12; in isc_try_configure_rlp_dma()
680 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
681 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
682 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
683 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
686 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_RGB565; in isc_try_configure_rlp_dma()
687 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
688 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
689 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
690 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
693 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_ARGB444; in isc_try_configure_rlp_dma()
694 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
695 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
696 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
697 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
700 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_ARGB555; in isc_try_configure_rlp_dma()
701 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
702 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
703 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
704 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
708 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_ARGB32; in isc_try_configure_rlp_dma()
709 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
710 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
711 isc->try_config.bpp = 32; in isc_try_configure_rlp_dma()
712 isc->try_config.bpp_v4l2 = 32; in isc_try_configure_rlp_dma()
715 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YYCC; in isc_try_configure_rlp_dma()
716 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_YC420P; in isc_try_configure_rlp_dma()
717 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PLANAR; in isc_try_configure_rlp_dma()
718 isc->try_config.bpp = 12; in isc_try_configure_rlp_dma()
719 isc->try_config.bpp_v4l2 = 8; /* only first plane */ in isc_try_configure_rlp_dma()
722 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YYCC; in isc_try_configure_rlp_dma()
723 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_YC422P; in isc_try_configure_rlp_dma()
724 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PLANAR; in isc_try_configure_rlp_dma()
725 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
726 isc->try_config.bpp_v4l2 = 8; /* only first plane */ in isc_try_configure_rlp_dma()
729 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YCYC | ISC_RLP_CFG_YMODE_YUYV; in isc_try_configure_rlp_dma()
730 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
731 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
732 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
733 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
736 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YCYC | ISC_RLP_CFG_YMODE_UYVY; in isc_try_configure_rlp_dma()
737 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
738 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
739 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
740 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
743 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YCYC | ISC_RLP_CFG_YMODE_VYUY; in isc_try_configure_rlp_dma()
744 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
745 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
746 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
747 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
750 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DATY8; in isc_try_configure_rlp_dma()
751 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8; in isc_try_configure_rlp_dma()
752 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
753 isc->try_config.bpp = 8; in isc_try_configure_rlp_dma()
754 isc->try_config.bpp_v4l2 = 8; in isc_try_configure_rlp_dma()
757 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DATY10 | ISC_RLP_CFG_LSH; in isc_try_configure_rlp_dma()
760 isc->try_config.rlp_cfg_mode |= ISC_RLP_CFG_MODE_DATY10; in isc_try_configure_rlp_dma()
761 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
762 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
763 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
764 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
771 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT8; in isc_try_configure_rlp_dma()
772 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8; in isc_try_configure_rlp_dma()
773 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
784 static int isc_try_configure_pipeline(struct isc_device *isc) in isc_try_configure_pipeline() argument
786 switch (isc->try_config.fourcc) { in isc_try_configure_pipeline()
793 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
794 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
798 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
803 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
804 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
809 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
814 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
815 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
819 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
826 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
827 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
831 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
837 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
838 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
842 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
846 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) in isc_try_configure_pipeline()
847 isc->try_config.bits_pipeline = WB_ENABLE | DPC_BLCENABLE; in isc_try_configure_pipeline()
849 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
853 isc->adapt_pipeline(isc); in isc_try_configure_pipeline()
858 static void isc_try_fse(struct isc_device *isc, in isc_try_fse() argument
870 if (!isc->config.sd_format) in isc_try_fse()
873 fse.code = isc->try_config.sd_format->mbus_code; in isc_try_fse()
875 ret = v4l2_subdev_call(isc->current_subdev->sd, pad, enum_frame_size, in isc_try_fse()
882 sd_state->pads->try_crop.width = isc->max_width; in isc_try_fse()
883 sd_state->pads->try_crop.height = isc->max_height; in isc_try_fse()
890 static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f) in isc_try_fmt() argument
898 isc->try_config.fourcc = isc->controller_formats[0].fourcc; in isc_try_fmt()
901 for (i = 0; i < isc->controller_formats_size; i++) in isc_try_fmt()
902 if (isc->controller_formats[i].fourcc == pixfmt->pixelformat) { in isc_try_fmt()
903 isc->try_config.fourcc = pixfmt->pixelformat; in isc_try_fmt()
907 isc_try_configure_rlp_dma(isc, false); in isc_try_fmt()
910 v4l_bound_align_image(&pixfmt->width, 16, isc->max_width, 0, in isc_try_fmt()
911 &pixfmt->height, 16, isc->max_height, 0, 0); in isc_try_fmt()
913 pixfmt->pixelformat = isc->try_config.fourcc; in isc_try_fmt()
917 pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >> 3; in isc_try_fmt()
918 pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >> 3) * in isc_try_fmt()
921 isc->try_fmt = *f; in isc_try_fmt()
926 static int isc_set_fmt(struct isc_device *isc, struct v4l2_format *f) in isc_set_fmt() argument
928 isc_try_fmt(isc, f); in isc_set_fmt()
931 isc->config = isc->try_config; in isc_set_fmt()
932 isc->fmt = isc->try_fmt; in isc_set_fmt()
934 dev_dbg(isc->dev, "ISC set_fmt to %.4s @%dx%d\n", in isc_set_fmt()
941 static int isc_validate(struct isc_device *isc) in isc_validate() argument
946 struct v4l2_pix_format *pixfmt = &isc->fmt.fmt.pix; in isc_validate()
949 .pad = isc->remote_pad, in isc_validate()
957 ret = v4l2_subdev_call(isc->current_subdev->sd, pad, get_fmt, NULL, in isc_validate()
963 for (i = 0; i < isc->formats_list_size; i++) in isc_validate()
964 if (isc->formats_list[i].mbus_code == format.format.code) { in isc_validate()
965 sd_fmt = &isc->formats_list[i]; in isc_validate()
971 dev_err(isc->dev, in isc_validate()
978 isc->try_config.sd_format = sd_fmt; in isc_validate()
981 if (!ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) in isc_validate()
982 isc_try_configure_rlp_dma(isc, true); in isc_validate()
985 v4l_bound_align_image(&format.format.width, 16, isc->max_width, 0, in isc_validate()
986 &format.format.height, 16, isc->max_height, 0, 0); in isc_validate()
991 dev_err(isc->dev, in isc_validate()
997 dev_dbg(isc->dev, in isc_validate()
1000 isc->try_config.bpp); in isc_validate()
1003 if (isc->try_config.sd_format && isc->config.sd_format && in isc_validate()
1004 isc->try_config.sd_format != isc->config.sd_format) { in isc_validate()
1005 isc->ctrls.hist_stat = HIST_INIT; in isc_validate()
1006 isc_reset_awb_ctrls(isc); in isc_validate()
1007 isc_update_v4l2_ctrls(isc); in isc_validate()
1011 ret = isc_try_validate_formats(isc); in isc_validate()
1016 isc_try_fse(isc, &pad_state); in isc_validate()
1019 ret = isc_try_configure_pipeline(isc); in isc_validate()
1023 isc->config = isc->try_config; in isc_validate()
1025 dev_dbg(isc->dev, "New ISC configuration in place\n"); in isc_validate()
1033 struct isc_device *isc = video_drvdata(file); in isc_s_fmt_vid_cap() local
1035 if (vb2_is_busy(&isc->vb2_vidq)) in isc_s_fmt_vid_cap()
1038 return isc_set_fmt(isc, f); in isc_s_fmt_vid_cap()
1044 struct isc_device *isc = video_drvdata(file); in isc_try_fmt_vid_cap() local
1046 return isc_try_fmt(isc, f); in isc_try_fmt_vid_cap()
1079 struct isc_device *isc = video_drvdata(file); in isc_g_parm() local
1081 return v4l2_g_parm_cap(video_devdata(file), isc->current_subdev->sd, a); in isc_g_parm()
1086 struct isc_device *isc = video_drvdata(file); in isc_s_parm() local
1088 return v4l2_s_parm_cap(video_devdata(file), isc->current_subdev->sd, a); in isc_s_parm()
1094 struct isc_device *isc = video_drvdata(file); in isc_enum_framesizes() local
1101 for (i = 0; i < isc->controller_formats_size; i++) in isc_enum_framesizes()
1102 if (isc->controller_formats[i].fourcc == fsize->pixel_format) in isc_enum_framesizes()
1111 fsize->stepwise.max_width = isc->max_width; in isc_enum_framesizes()
1113 fsize->stepwise.max_height = isc->max_height; in isc_enum_framesizes()
1152 struct isc_device *isc = video_drvdata(file); in isc_open() local
1153 struct v4l2_subdev *sd = isc->current_subdev->sd; in isc_open()
1156 if (mutex_lock_interruptible(&isc->lock)) in isc_open()
1172 ret = isc_set_fmt(isc, &isc->fmt); in isc_open()
1179 mutex_unlock(&isc->lock); in isc_open()
1185 struct isc_device *isc = video_drvdata(file); in isc_release() local
1186 struct v4l2_subdev *sd = isc->current_subdev->sd; in isc_release()
1190 mutex_lock(&isc->lock); in isc_release()
1199 mutex_unlock(&isc->lock); in isc_release()
1216 struct isc_device *isc = (struct isc_device *)dev_id; in microchip_isc_interrupt() local
1217 struct regmap *regmap = isc->regmap; in microchip_isc_interrupt()
1227 spin_lock(&isc->dma_queue_lock); in microchip_isc_interrupt()
1228 if (isc->cur_frm) { in microchip_isc_interrupt()
1229 struct vb2_v4l2_buffer *vbuf = &isc->cur_frm->vb; in microchip_isc_interrupt()
1233 vbuf->sequence = isc->sequence++; in microchip_isc_interrupt()
1235 isc->cur_frm = NULL; in microchip_isc_interrupt()
1238 if (!list_empty(&isc->dma_queue) && !isc->stop) { in microchip_isc_interrupt()
1239 isc->cur_frm = list_first_entry(&isc->dma_queue, in microchip_isc_interrupt()
1241 list_del(&isc->cur_frm->list); in microchip_isc_interrupt()
1243 isc_start_dma(isc); in microchip_isc_interrupt()
1246 if (isc->stop) in microchip_isc_interrupt()
1247 complete(&isc->comp); in microchip_isc_interrupt()
1250 spin_unlock(&isc->dma_queue_lock); in microchip_isc_interrupt()
1254 schedule_work(&isc->awb_work); in microchip_isc_interrupt()
1262 static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max) in isc_hist_count() argument
1264 struct regmap *regmap = isc->regmap; in isc_hist_count()
1265 struct isc_ctrls *ctrls = &isc->ctrls; in isc_hist_count()
1273 regmap_bulk_read(regmap, ISC_HIS_ENTRY + isc->offsets.his_entry, in isc_hist_count()
1292 dev_dbg(isc->dev, "isc wb: hist_id %u, hist_count %u", in isc_hist_count()
1298 struct isc_device *isc = container_of(ctrls, struct isc_device, ctrls); in isc_wb_update() local
1315 dev_dbg(isc->dev, "isc wb: green components average %llu\n", avg); in isc_wb_update()
1369 dev_dbg(isc->dev, in isc_wb_update()
1379 dev_dbg(isc->dev, "isc wb: component %d, final gain %u\n", in isc_wb_update()
1386 struct isc_device *isc = in isc_awb_work() local
1388 struct regmap *regmap = isc->regmap; in isc_awb_work()
1389 struct isc_ctrls *ctrls = &isc->ctrls; in isc_awb_work()
1399 isc_hist_count(isc, &min, &max); in isc_awb_work()
1401 dev_dbg(isc->dev, in isc_awb_work()
1415 baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT; in isc_awb_work()
1417 ret = pm_runtime_resume_and_get(isc->dev); in isc_awb_work()
1432 spin_lock_irqsave(&isc->awb_lock, flags); in isc_awb_work()
1433 isc_update_awb_ctrls(isc); in isc_awb_work()
1434 spin_unlock_irqrestore(&isc->awb_lock, flags); in isc_awb_work()
1441 dev_info(isc->dev, in isc_awb_work()
1444 isc_update_v4l2_ctrls(isc); in isc_awb_work()
1448 regmap_write(regmap, ISC_HIS_CFG + isc->offsets.his, in isc_awb_work()
1456 mutex_lock(&isc->awb_mutex); in isc_awb_work()
1459 if (isc->stop) { in isc_awb_work()
1460 mutex_unlock(&isc->awb_mutex); in isc_awb_work()
1464 isc_update_profile(isc); in isc_awb_work()
1466 mutex_unlock(&isc->awb_mutex); in isc_awb_work()
1472 pm_runtime_put_sync(isc->dev); in isc_awb_work()
1477 struct isc_device *isc = container_of(ctrl->handler, in isc_s_ctrl() local
1479 struct isc_ctrls *ctrls = &isc->ctrls; in isc_s_ctrl()
1507 struct isc_device *isc = container_of(ctrl->handler, in isc_s_awb_ctrl() local
1509 struct isc_ctrls *ctrls = &isc->ctrls; in isc_s_awb_ctrl()
1523 ctrls->gain[ISC_HIS_CFG_MODE_R] = isc->r_gain_ctrl->val; in isc_s_awb_ctrl()
1525 ctrls->gain[ISC_HIS_CFG_MODE_B] = isc->b_gain_ctrl->val; in isc_s_awb_ctrl()
1527 ctrls->gain[ISC_HIS_CFG_MODE_GR] = isc->gr_gain_ctrl->val; in isc_s_awb_ctrl()
1529 ctrls->gain[ISC_HIS_CFG_MODE_GB] = isc->gb_gain_ctrl->val; in isc_s_awb_ctrl()
1532 ctrls->offset[ISC_HIS_CFG_MODE_R] = isc->r_off_ctrl->val; in isc_s_awb_ctrl()
1534 ctrls->offset[ISC_HIS_CFG_MODE_B] = isc->b_off_ctrl->val; in isc_s_awb_ctrl()
1536 ctrls->offset[ISC_HIS_CFG_MODE_GR] = isc->gr_off_ctrl->val; in isc_s_awb_ctrl()
1538 ctrls->offset[ISC_HIS_CFG_MODE_GB] = isc->gb_off_ctrl->val; in isc_s_awb_ctrl()
1540 isc_update_awb_ctrls(isc); in isc_s_awb_ctrl()
1542 mutex_lock(&isc->awb_mutex); in isc_s_awb_ctrl()
1543 if (vb2_is_streaming(&isc->vb2_vidq)) { in isc_s_awb_ctrl()
1548 isc_update_profile(isc); in isc_s_awb_ctrl()
1555 v4l2_ctrl_activate(isc->do_wb_ctrl, false); in isc_s_awb_ctrl()
1557 mutex_unlock(&isc->awb_mutex); in isc_s_awb_ctrl()
1561 vb2_is_streaming(&isc->vb2_vidq) && in isc_s_awb_ctrl()
1562 ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) in isc_s_awb_ctrl()
1563 isc_set_histogram(isc, true); in isc_s_awb_ctrl()
1574 isc_set_histogram(isc, true); in isc_s_awb_ctrl()
1575 dev_dbg(isc->dev, "One time white-balance started.\n"); in isc_s_awb_ctrl()
1584 struct isc_device *isc = container_of(ctrl->handler, in isc_g_volatile_awb_ctrl() local
1586 struct isc_ctrls *ctrls = &isc->ctrls; in isc_g_volatile_awb_ctrl()
1654 static int isc_ctrl_init(struct isc_device *isc) in isc_ctrl_init() argument
1657 struct isc_ctrls *ctrls = &isc->ctrls; in isc_ctrl_init()
1662 isc_reset_awb_ctrls(isc); in isc_ctrl_init()
1669 isc->config_ctrls(isc, ops); in isc_ctrl_init()
1674 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, isc->gamma_max, 1, in isc_ctrl_init()
1675 isc->gamma_max); in isc_ctrl_init()
1676 isc->awb_ctrl = v4l2_ctrl_new_std(hdl, &isc_awb_ops, in isc_ctrl_init()
1681 isc->do_wb_ctrl = v4l2_ctrl_new_std(hdl, &isc_awb_ops, in isc_ctrl_init()
1685 if (!isc->do_wb_ctrl) { in isc_ctrl_init()
1691 v4l2_ctrl_activate(isc->do_wb_ctrl, false); in isc_ctrl_init()
1693 isc->r_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_r_gain_ctrl, NULL); in isc_ctrl_init()
1694 isc->b_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_b_gain_ctrl, NULL); in isc_ctrl_init()
1695 isc->gr_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gr_gain_ctrl, NULL); in isc_ctrl_init()
1696 isc->gb_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gb_gain_ctrl, NULL); in isc_ctrl_init()
1697 isc->r_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_r_off_ctrl, NULL); in isc_ctrl_init()
1698 isc->b_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_b_off_ctrl, NULL); in isc_ctrl_init()
1699 isc->gr_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gr_off_ctrl, NULL); in isc_ctrl_init()
1700 isc->gb_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gb_off_ctrl, NULL); in isc_ctrl_init()
1706 v4l2_ctrl_auto_cluster(10, &isc->awb_ctrl, 0, true); in isc_ctrl_init()
1717 struct isc_device *isc = container_of(notifier->v4l2_dev, in isc_async_bound() local
1723 if (video_is_registered(&isc->video_dev)) { in isc_async_bound()
1724 dev_err(isc->dev, "only supports one sub-device.\n"); in isc_async_bound()
1733 dev_err(isc->dev, "failed to find pad for %s\n", subdev->name); in isc_async_bound()
1737 isc->remote_pad = pad; in isc_async_bound()
1746 struct isc_device *isc = container_of(notifier->v4l2_dev, in isc_async_unbind() local
1748 mutex_destroy(&isc->awb_mutex); in isc_async_unbind()
1749 cancel_work_sync(&isc->awb_work); in isc_async_unbind()
1750 video_unregister_device(&isc->video_dev); in isc_async_unbind()
1751 v4l2_ctrl_handler_free(&isc->ctrls.handler); in isc_async_unbind()
1754 struct isc_format *isc_find_format_by_code(struct isc_device *isc, in isc_find_format_by_code() argument
1757 struct isc_format *fmt = &isc->formats_list[0]; in isc_find_format_by_code()
1760 for (i = 0; i < isc->formats_list_size; i++) { in isc_find_format_by_code()
1773 static int isc_set_default_fmt(struct isc_device *isc) in isc_set_default_fmt() argument
1781 .pixelformat = isc->controller_formats[0].fourcc, in isc_set_default_fmt()
1786 ret = isc_try_fmt(isc, &f); in isc_set_default_fmt()
1790 isc->fmt = f; in isc_set_default_fmt()
1796 struct isc_device *isc = container_of(notifier->v4l2_dev, in isc_async_complete() local
1798 struct video_device *vdev = &isc->video_dev; in isc_async_complete()
1799 struct vb2_queue *q = &isc->vb2_vidq; in isc_async_complete()
1802 INIT_WORK(&isc->awb_work, isc_awb_work); in isc_async_complete()
1804 ret = v4l2_device_register_subdev_nodes(&isc->v4l2_dev); in isc_async_complete()
1806 dev_err(isc->dev, "Failed to register subdev nodes\n"); in isc_async_complete()
1810 isc->current_subdev = container_of(notifier, in isc_async_complete()
1812 mutex_init(&isc->lock); in isc_async_complete()
1813 mutex_init(&isc->awb_mutex); in isc_async_complete()
1815 init_completion(&isc->comp); in isc_async_complete()
1820 q->drv_priv = isc; in isc_async_complete()
1825 q->lock = &isc->lock; in isc_async_complete()
1827 q->dev = isc->dev; in isc_async_complete()
1831 dev_err(isc->dev, "vb2_queue_init() failed: %d\n", ret); in isc_async_complete()
1836 INIT_LIST_HEAD(&isc->dma_queue); in isc_async_complete()
1837 spin_lock_init(&isc->dma_queue_lock); in isc_async_complete()
1838 spin_lock_init(&isc->awb_lock); in isc_async_complete()
1840 ret = isc_set_default_fmt(isc); in isc_async_complete()
1842 dev_err(isc->dev, "Could not set default format\n"); in isc_async_complete()
1846 ret = isc_ctrl_init(isc); in isc_async_complete()
1848 dev_err(isc->dev, "Init isc ctrols failed: %d\n", ret); in isc_async_complete()
1857 vdev->v4l2_dev = &isc->v4l2_dev; in isc_async_complete()
1860 vdev->lock = &isc->lock; in isc_async_complete()
1861 vdev->ctrl_handler = &isc->ctrls.handler; in isc_async_complete()
1864 video_set_drvdata(vdev, isc); in isc_async_complete()
1868 dev_err(isc->dev, "video_register_device failed: %d\n", ret); in isc_async_complete()
1872 ret = isc_scaler_link(isc); in isc_async_complete()
1876 ret = media_device_register(&isc->mdev); in isc_async_complete()
1886 mutex_destroy(&isc->awb_mutex); in isc_async_complete()
1887 mutex_destroy(&isc->lock); in isc_async_complete()
1898 void microchip_isc_subdev_cleanup(struct isc_device *isc) in microchip_isc_subdev_cleanup() argument
1902 list_for_each_entry(subdev_entity, &isc->subdev_entities, list) { in microchip_isc_subdev_cleanup()
1907 INIT_LIST_HEAD(&isc->subdev_entities); in microchip_isc_subdev_cleanup()
1911 int microchip_isc_pipeline_init(struct isc_device *isc) in microchip_isc_pipeline_init() argument
1913 struct device *dev = isc->dev; in microchip_isc_pipeline_init()
1914 struct regmap *regmap = isc->regmap; in microchip_isc_pipeline_init()
1934 REG_FIELD(ISC_CSC_CTRL + isc->offsets.csc, 0, 0), in microchip_isc_pipeline_init()
1935 REG_FIELD(ISC_CBC_CTRL + isc->offsets.cbc, 0, 0), in microchip_isc_pipeline_init()
1936 REG_FIELD(ISC_SUB422_CTRL + isc->offsets.sub422, 0, 0), in microchip_isc_pipeline_init()
1937 REG_FIELD(ISC_SUB420_CTRL + isc->offsets.sub420, 0, 0), in microchip_isc_pipeline_init()
1945 isc->pipeline[i] = regs; in microchip_isc_pipeline_init()
1956 struct isc_device *isc = video_get_drvdata(vdev); in isc_link_validate() local
1963 return isc_validate(isc); in isc_link_validate()
1970 int isc_mc_init(struct isc_device *isc, u32 ver) in isc_mc_init() argument
1975 isc->video_dev.entity.function = MEDIA_ENT_F_IO_V4L; in isc_mc_init()
1976 isc->video_dev.entity.flags = MEDIA_ENT_FL_DEFAULT; in isc_mc_init()
1977 isc->video_dev.entity.ops = &isc_entity_operations; in isc_mc_init()
1979 isc->pads[ISC_PAD_SINK].flags = MEDIA_PAD_FL_SINK; in isc_mc_init()
1981 ret = media_entity_pads_init(&isc->video_dev.entity, ISC_PADS_NUM, in isc_mc_init()
1982 isc->pads); in isc_mc_init()
1984 dev_err(isc->dev, "media entity init failed\n"); in isc_mc_init()
1988 isc->mdev.dev = isc->dev; in isc_mc_init()
1990 match = of_match_node(isc->dev->driver->of_match_table, in isc_mc_init()
1991 isc->dev->of_node); in isc_mc_init()
1993 strscpy(isc->mdev.driver_name, KBUILD_MODNAME, in isc_mc_init()
1994 sizeof(isc->mdev.driver_name)); in isc_mc_init()
1995 strscpy(isc->mdev.model, match->compatible, sizeof(isc->mdev.model)); in isc_mc_init()
1996 snprintf(isc->mdev.bus_info, sizeof(isc->mdev.bus_info), "platform:%s", in isc_mc_init()
1997 isc->v4l2_dev.name); in isc_mc_init()
1998 isc->mdev.hw_revision = ver; in isc_mc_init()
2000 media_device_init(&isc->mdev); in isc_mc_init()
2002 isc->v4l2_dev.mdev = &isc->mdev; in isc_mc_init()
2004 return isc_scaler_init(isc); in isc_mc_init()
2008 void isc_mc_cleanup(struct isc_device *isc) in isc_mc_cleanup() argument
2010 media_entity_cleanup(&isc->video_dev.entity); in isc_mc_cleanup()
2011 media_device_cleanup(&isc->mdev); in isc_mc_cleanup()