Lines Matching refs:isc
51 static inline void isc_update_v4l2_ctrls(struct isc_device *isc) in isc_update_v4l2_ctrls() argument
53 struct isc_ctrls *ctrls = &isc->ctrls; in isc_update_v4l2_ctrls()
56 v4l2_ctrl_s_ctrl(isc->r_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_R]); in isc_update_v4l2_ctrls()
57 v4l2_ctrl_s_ctrl(isc->b_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_B]); in isc_update_v4l2_ctrls()
58 v4l2_ctrl_s_ctrl(isc->gr_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_GR]); in isc_update_v4l2_ctrls()
59 v4l2_ctrl_s_ctrl(isc->gb_gain_ctrl, ctrls->gain[ISC_HIS_CFG_MODE_GB]); in isc_update_v4l2_ctrls()
61 v4l2_ctrl_s_ctrl(isc->r_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_R]); in isc_update_v4l2_ctrls()
62 v4l2_ctrl_s_ctrl(isc->b_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_B]); in isc_update_v4l2_ctrls()
63 v4l2_ctrl_s_ctrl(isc->gr_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_GR]); in isc_update_v4l2_ctrls()
64 v4l2_ctrl_s_ctrl(isc->gb_off_ctrl, ctrls->offset[ISC_HIS_CFG_MODE_GB]); in isc_update_v4l2_ctrls()
67 static inline void isc_update_awb_ctrls(struct isc_device *isc) in isc_update_awb_ctrls() argument
69 struct isc_ctrls *ctrls = &isc->ctrls; in isc_update_awb_ctrls()
73 regmap_write(isc->regmap, ISC_WB_O_RGR, in isc_update_awb_ctrls()
76 regmap_write(isc->regmap, ISC_WB_O_BGB, in isc_update_awb_ctrls()
79 regmap_write(isc->regmap, ISC_WB_G_RGR, in isc_update_awb_ctrls()
82 regmap_write(isc->regmap, ISC_WB_G_BGB, in isc_update_awb_ctrls()
87 static inline void isc_reset_awb_ctrls(struct isc_device *isc) in isc_reset_awb_ctrls() argument
93 isc->ctrls.gain[c] = 1 << 9; in isc_reset_awb_ctrls()
95 isc->ctrls.offset[c] = 0; in isc_reset_awb_ctrls()
104 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_queue_setup() local
105 unsigned int size = isc->fmt.fmt.pix.sizeimage; in isc_queue_setup()
119 struct isc_device *isc = vb2_get_drv_priv(vb->vb2_queue); in isc_buffer_prepare() local
120 unsigned long size = isc->fmt.fmt.pix.sizeimage; in isc_buffer_prepare()
123 v4l2_err(&isc->v4l2_dev, "buffer too small (%lu < %lu)\n", in isc_buffer_prepare()
130 vbuf->field = isc->fmt.fmt.pix.field; in isc_buffer_prepare()
135 static void isc_crop_pfe(struct isc_device *isc) in isc_crop_pfe() argument
137 struct regmap *regmap = isc->regmap; in isc_crop_pfe()
140 h = isc->fmt.fmt.pix.height; in isc_crop_pfe()
141 w = isc->fmt.fmt.pix.width; in isc_crop_pfe()
149 if (!ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) { in isc_crop_pfe()
174 static void isc_start_dma(struct isc_device *isc) in isc_start_dma() argument
176 struct regmap *regmap = isc->regmap; in isc_start_dma()
177 u32 sizeimage = isc->fmt.fmt.pix.sizeimage; in isc_start_dma()
181 addr0 = vb2_dma_contig_plane_dma_addr(&isc->cur_frm->vb.vb2_buf, 0); in isc_start_dma()
182 regmap_write(regmap, ISC_DAD0 + isc->offsets.dma, addr0); in isc_start_dma()
184 switch (isc->config.fourcc) { in isc_start_dma()
186 regmap_write(regmap, ISC_DAD1 + isc->offsets.dma, in isc_start_dma()
188 regmap_write(regmap, ISC_DAD2 + isc->offsets.dma, in isc_start_dma()
192 regmap_write(regmap, ISC_DAD1 + isc->offsets.dma, in isc_start_dma()
194 regmap_write(regmap, ISC_DAD2 + isc->offsets.dma, in isc_start_dma()
201 dctrl_dview = isc->config.dctrl_dview; in isc_start_dma()
203 regmap_write(regmap, ISC_DCTRL + isc->offsets.dma, in isc_start_dma()
205 spin_lock(&isc->awb_lock); in isc_start_dma()
207 spin_unlock(&isc->awb_lock); in isc_start_dma()
210 static void isc_set_pipeline(struct isc_device *isc, u32 pipeline) in isc_set_pipeline() argument
212 struct regmap *regmap = isc->regmap; in isc_set_pipeline()
213 struct isc_ctrls *ctrls = &isc->ctrls; in isc_set_pipeline()
221 regmap_field_write(isc->pipeline[i], val); in isc_set_pipeline()
227 bay_cfg = isc->config.sd_format->cfa_baycfg; in isc_set_pipeline()
230 isc_update_awb_ctrls(isc); in isc_set_pipeline()
231 isc_update_v4l2_ctrls(isc); in isc_set_pipeline()
235 gamma = &isc->gamma_table[ctrls->gamma_index][0]; in isc_set_pipeline()
240 isc->config_dpc(isc); in isc_set_pipeline()
241 isc->config_csc(isc); in isc_set_pipeline()
242 isc->config_cbc(isc); in isc_set_pipeline()
243 isc->config_cc(isc); in isc_set_pipeline()
244 isc->config_gam(isc); in isc_set_pipeline()
247 static int isc_update_profile(struct isc_device *isc) in isc_update_profile() argument
249 struct regmap *regmap = isc->regmap; in isc_update_profile()
262 v4l2_warn(&isc->v4l2_dev, "Time out to update profile\n"); in isc_update_profile()
269 static void isc_set_histogram(struct isc_device *isc, bool enable) in isc_set_histogram() argument
271 struct regmap *regmap = isc->regmap; in isc_set_histogram()
272 struct isc_ctrls *ctrls = &isc->ctrls; in isc_set_histogram()
275 regmap_write(regmap, ISC_HIS_CFG + isc->offsets.his, in isc_set_histogram()
277 (isc->config.sd_format->cfa_baycfg in isc_set_histogram()
280 regmap_write(regmap, ISC_HIS_CTRL + isc->offsets.his, in isc_set_histogram()
284 isc_update_profile(isc); in isc_set_histogram()
290 regmap_write(regmap, ISC_HIS_CTRL + isc->offsets.his, in isc_set_histogram()
297 static int isc_configure(struct isc_device *isc) in isc_configure() argument
299 struct regmap *regmap = isc->regmap; in isc_configure()
301 struct isc_subdev_entity *subdev = isc->current_subdev; in isc_configure()
303 pfe_cfg0 = isc->config.sd_format->pfe_cfg0_bps; in isc_configure()
304 pipeline = isc->config.bits_pipeline; in isc_configure()
306 dcfg = isc->config.dcfg_imode | isc->dcfg; in isc_configure()
316 isc->config_rlp(isc); in isc_configure()
318 regmap_write(regmap, ISC_DCFG + isc->offsets.dma, dcfg); in isc_configure()
321 isc_set_pipeline(isc, pipeline); in isc_configure()
327 if (isc->ctrls.awb && in isc_configure()
328 ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) in isc_configure()
329 isc_set_histogram(isc, true); in isc_configure()
331 isc_set_histogram(isc, false); in isc_configure()
334 return isc_update_profile(isc); in isc_configure()
339 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_start_streaming() local
340 struct regmap *regmap = isc->regmap; in isc_start_streaming()
346 ret = v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 1); in isc_start_streaming()
348 v4l2_err(&isc->v4l2_dev, "stream on failed in subdev %d\n", in isc_start_streaming()
353 ret = pm_runtime_resume_and_get(isc->dev); in isc_start_streaming()
355 v4l2_err(&isc->v4l2_dev, "RPM resume failed in subdev %d\n", in isc_start_streaming()
360 ret = isc_configure(isc); in isc_start_streaming()
367 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_start_streaming()
369 isc->sequence = 0; in isc_start_streaming()
370 isc->stop = false; in isc_start_streaming()
371 reinit_completion(&isc->comp); in isc_start_streaming()
373 isc->cur_frm = list_first_entry(&isc->dma_queue, in isc_start_streaming()
375 list_del(&isc->cur_frm->list); in isc_start_streaming()
377 isc_crop_pfe(isc); in isc_start_streaming()
378 isc_start_dma(isc); in isc_start_streaming()
380 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_start_streaming()
383 if (ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) in isc_start_streaming()
384 v4l2_ctrl_activate(isc->do_wb_ctrl, true); in isc_start_streaming()
389 pm_runtime_put_sync(isc->dev); in isc_start_streaming()
391 v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0); in isc_start_streaming()
394 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_start_streaming()
395 list_for_each_entry(buf, &isc->dma_queue, list) in isc_start_streaming()
397 INIT_LIST_HEAD(&isc->dma_queue); in isc_start_streaming()
398 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_start_streaming()
405 struct isc_device *isc = vb2_get_drv_priv(vq); in isc_stop_streaming() local
410 mutex_lock(&isc->awb_mutex); in isc_stop_streaming()
411 v4l2_ctrl_activate(isc->do_wb_ctrl, false); in isc_stop_streaming()
413 isc->stop = true; in isc_stop_streaming()
416 if (isc->cur_frm && !wait_for_completion_timeout(&isc->comp, 5 * HZ)) in isc_stop_streaming()
417 v4l2_err(&isc->v4l2_dev, in isc_stop_streaming()
420 mutex_unlock(&isc->awb_mutex); in isc_stop_streaming()
423 regmap_write(isc->regmap, ISC_INTDIS, ISC_INT_DDONE); in isc_stop_streaming()
425 pm_runtime_put_sync(isc->dev); in isc_stop_streaming()
428 ret = v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0); in isc_stop_streaming()
430 v4l2_err(&isc->v4l2_dev, "stream off failed in subdev\n"); in isc_stop_streaming()
433 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_stop_streaming()
434 if (unlikely(isc->cur_frm)) { in isc_stop_streaming()
435 vb2_buffer_done(&isc->cur_frm->vb.vb2_buf, in isc_stop_streaming()
437 isc->cur_frm = NULL; in isc_stop_streaming()
439 list_for_each_entry(buf, &isc->dma_queue, list) in isc_stop_streaming()
441 INIT_LIST_HEAD(&isc->dma_queue); in isc_stop_streaming()
442 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_stop_streaming()
449 struct isc_device *isc = vb2_get_drv_priv(vb->vb2_queue); in isc_buffer_queue() local
452 spin_lock_irqsave(&isc->dma_queue_lock, flags); in isc_buffer_queue()
453 if (!isc->cur_frm && list_empty(&isc->dma_queue) && in isc_buffer_queue()
455 isc->cur_frm = buf; in isc_buffer_queue()
456 isc_start_dma(isc); in isc_buffer_queue()
458 list_add_tail(&buf->list, &isc->dma_queue); in isc_buffer_queue()
459 spin_unlock_irqrestore(&isc->dma_queue_lock, flags); in isc_buffer_queue()
462 static struct isc_format *find_format_by_fourcc(struct isc_device *isc, in find_format_by_fourcc() argument
465 unsigned int num_formats = isc->num_user_formats; in find_format_by_fourcc()
470 fmt = isc->user_formats[i]; in find_format_by_fourcc()
491 struct isc_device *isc = video_drvdata(file); in isc_querycap() local
496 "platform:%s", isc->v4l2_dev.name); in isc_querycap()
504 struct isc_device *isc = video_drvdata(file); in isc_enum_fmt_vid_cap() local
508 if (index < isc->controller_formats_size) { in isc_enum_fmt_vid_cap()
509 f->pixelformat = isc->controller_formats[index].fourcc; in isc_enum_fmt_vid_cap()
513 index -= isc->controller_formats_size; in isc_enum_fmt_vid_cap()
517 for (i = 0; i < isc->formats_list_size; i++) { in isc_enum_fmt_vid_cap()
518 if (!ISC_IS_FORMAT_RAW(isc->formats_list[i].mbus_code) || in isc_enum_fmt_vid_cap()
519 !isc->formats_list[i].sd_support) in isc_enum_fmt_vid_cap()
522 f->pixelformat = isc->formats_list[i].fourcc; in isc_enum_fmt_vid_cap()
534 struct isc_device *isc = video_drvdata(file); in isc_g_fmt_vid_cap() local
536 *fmt = isc->fmt; in isc_g_fmt_vid_cap()
545 static int isc_try_validate_formats(struct isc_device *isc) in isc_try_validate_formats() argument
551 switch (isc->try_config.fourcc) { in isc_try_validate_formats()
595 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_try_validate_formats()
600 if ((bayer) && !ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) in isc_try_validate_formats()
604 if (grey && !ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code) && in isc_try_validate_formats()
605 !ISC_IS_FORMAT_GREY(isc->try_config.sd_format->mbus_code)) in isc_try_validate_formats()
616 static int isc_try_configure_rlp_dma(struct isc_device *isc, bool direct_dump) in isc_try_configure_rlp_dma() argument
618 isc->try_config.rlp_cfg_mode = 0; in isc_try_configure_rlp_dma()
620 switch (isc->try_config.fourcc) { in isc_try_configure_rlp_dma()
625 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT8; in isc_try_configure_rlp_dma()
626 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8; in isc_try_configure_rlp_dma()
627 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
628 isc->try_config.bpp = 8; in isc_try_configure_rlp_dma()
629 isc->try_config.bpp_v4l2 = 8; in isc_try_configure_rlp_dma()
635 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT10; in isc_try_configure_rlp_dma()
636 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
637 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
638 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
639 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
645 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT12; in isc_try_configure_rlp_dma()
646 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
647 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
648 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
649 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
652 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_RGB565; in isc_try_configure_rlp_dma()
653 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
654 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
655 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
656 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
659 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_ARGB444; in isc_try_configure_rlp_dma()
660 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; 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 = 16; in isc_try_configure_rlp_dma()
663 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
666 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_ARGB555; in isc_try_configure_rlp_dma()
667 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
668 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
669 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
670 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
674 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_ARGB32; in isc_try_configure_rlp_dma()
675 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
676 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
677 isc->try_config.bpp = 32; in isc_try_configure_rlp_dma()
678 isc->try_config.bpp_v4l2 = 32; in isc_try_configure_rlp_dma()
681 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YYCC; in isc_try_configure_rlp_dma()
682 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_YC420P; in isc_try_configure_rlp_dma()
683 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PLANAR; in isc_try_configure_rlp_dma()
684 isc->try_config.bpp = 12; in isc_try_configure_rlp_dma()
685 isc->try_config.bpp_v4l2 = 8; /* only first plane */ in isc_try_configure_rlp_dma()
688 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YYCC; in isc_try_configure_rlp_dma()
689 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_YC422P; in isc_try_configure_rlp_dma()
690 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PLANAR; in isc_try_configure_rlp_dma()
691 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
692 isc->try_config.bpp_v4l2 = 8; /* only first plane */ in isc_try_configure_rlp_dma()
695 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YCYC | ISC_RLP_CFG_YMODE_YUYV; in isc_try_configure_rlp_dma()
696 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
697 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
698 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
699 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
702 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YCYC | ISC_RLP_CFG_YMODE_UYVY; in isc_try_configure_rlp_dma()
703 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
704 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
705 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
706 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
709 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_YCYC | ISC_RLP_CFG_YMODE_VYUY; in isc_try_configure_rlp_dma()
710 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED32; in isc_try_configure_rlp_dma()
711 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
712 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
713 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
716 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DATY8; in isc_try_configure_rlp_dma()
717 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8; in isc_try_configure_rlp_dma()
718 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
719 isc->try_config.bpp = 8; in isc_try_configure_rlp_dma()
720 isc->try_config.bpp_v4l2 = 8; in isc_try_configure_rlp_dma()
723 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DATY10 | ISC_RLP_CFG_LSH; in isc_try_configure_rlp_dma()
726 isc->try_config.rlp_cfg_mode |= ISC_RLP_CFG_MODE_DATY10; in isc_try_configure_rlp_dma()
727 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED16; in isc_try_configure_rlp_dma()
728 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
729 isc->try_config.bpp = 16; in isc_try_configure_rlp_dma()
730 isc->try_config.bpp_v4l2 = 16; in isc_try_configure_rlp_dma()
737 isc->try_config.rlp_cfg_mode = ISC_RLP_CFG_MODE_DAT8; in isc_try_configure_rlp_dma()
738 isc->try_config.dcfg_imode = ISC_DCFG_IMODE_PACKED8; in isc_try_configure_rlp_dma()
739 isc->try_config.dctrl_dview = ISC_DCTRL_DVIEW_PACKED; in isc_try_configure_rlp_dma()
750 static int isc_try_configure_pipeline(struct isc_device *isc) in isc_try_configure_pipeline() argument
752 switch (isc->try_config.fourcc) { in isc_try_configure_pipeline()
759 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
760 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
764 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
769 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
770 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
775 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
780 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
781 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
785 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
792 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) { in isc_try_configure_pipeline()
793 isc->try_config.bits_pipeline = CFA_ENABLE | in isc_try_configure_pipeline()
797 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()
808 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
812 if (ISC_IS_FORMAT_RAW(isc->try_config.sd_format->mbus_code)) in isc_try_configure_pipeline()
813 isc->try_config.bits_pipeline = WB_ENABLE | DPC_BLCENABLE; in isc_try_configure_pipeline()
815 isc->try_config.bits_pipeline = 0x0; in isc_try_configure_pipeline()
819 isc->adapt_pipeline(isc); in isc_try_configure_pipeline()
824 static void isc_try_fse(struct isc_device *isc, in isc_try_fse() argument
834 if (!isc->try_config.sd_format) in isc_try_fse()
837 fse.code = isc->try_config.sd_format->mbus_code; in isc_try_fse()
840 ret = v4l2_subdev_call(isc->current_subdev->sd, pad, enum_frame_size, in isc_try_fse()
847 sd_state->pads->try_crop.width = isc->max_width; in isc_try_fse()
848 sd_state->pads->try_crop.height = isc->max_height; in isc_try_fse()
855 static int isc_try_fmt(struct isc_device *isc, struct v4l2_format *f, in isc_try_fmt() argument
876 for (i = 0; i < isc->num_user_formats; i++) { in isc_try_fmt()
877 if (ISC_IS_FORMAT_RAW(isc->user_formats[i]->mbus_code)) { in isc_try_fmt()
878 sd_fmt = isc->user_formats[i]; in isc_try_fmt()
885 direct_fmt = find_format_by_fourcc(isc, pixfmt->pixelformat); in isc_try_fmt()
908 sd_fmt = isc->user_formats[isc->num_user_formats - 1]; in isc_try_fmt()
909 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_try_fmt()
920 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_try_fmt()
925 isc->try_config.sd_format = sd_fmt; in isc_try_fmt()
928 if (pixfmt->width > isc->max_width) in isc_try_fmt()
929 pixfmt->width = isc->max_width; in isc_try_fmt()
930 if (pixfmt->height > isc->max_height) in isc_try_fmt()
931 pixfmt->height = isc->max_height; in isc_try_fmt()
943 isc->try_config.fourcc = pixfmt->pixelformat; in isc_try_fmt()
945 if (isc_try_validate_formats(isc)) { in isc_try_fmt()
946 pixfmt->pixelformat = isc->try_config.fourcc = sd_fmt->fourcc; in isc_try_fmt()
948 ret = isc_try_validate_formats(isc); in isc_try_fmt()
953 ret = isc_try_configure_rlp_dma(isc, rlp_dma_direct_dump); in isc_try_fmt()
957 ret = isc_try_configure_pipeline(isc); in isc_try_fmt()
962 isc_try_fse(isc, &pad_state); in isc_try_fmt()
965 ret = v4l2_subdev_call(isc->current_subdev->sd, pad, set_fmt, in isc_try_fmt()
973 if (pixfmt->width > isc->max_width) in isc_try_fmt()
974 pixfmt->width = isc->max_width; in isc_try_fmt()
975 if (pixfmt->height > isc->max_height) in isc_try_fmt()
976 pixfmt->height = isc->max_height; in isc_try_fmt()
979 pixfmt->bytesperline = (pixfmt->width * isc->try_config.bpp_v4l2) >> 3; in isc_try_fmt()
980 pixfmt->sizeimage = ((pixfmt->width * isc->try_config.bpp) >> 3) * in isc_try_fmt()
989 v4l2_err(&isc->v4l2_dev, "Could not find any possible format for a working pipeline\n"); in isc_try_fmt()
991 memset(&isc->try_config, 0, sizeof(isc->try_config)); in isc_try_fmt()
996 static int isc_set_fmt(struct isc_device *isc, struct v4l2_format *f) in isc_set_fmt() argument
1004 ret = isc_try_fmt(isc, f, &mbus_code); in isc_set_fmt()
1009 ret = v4l2_subdev_call(isc->current_subdev->sd, pad, in isc_set_fmt()
1015 if (f->fmt.pix.width > isc->max_width) in isc_set_fmt()
1016 f->fmt.pix.width = isc->max_width; in isc_set_fmt()
1017 if (f->fmt.pix.height > isc->max_height) in isc_set_fmt()
1018 f->fmt.pix.height = isc->max_height; in isc_set_fmt()
1020 isc->fmt = *f; in isc_set_fmt()
1022 if (isc->try_config.sd_format && isc->config.sd_format && in isc_set_fmt()
1023 isc->try_config.sd_format != isc->config.sd_format) { in isc_set_fmt()
1024 isc->ctrls.hist_stat = HIST_INIT; in isc_set_fmt()
1025 isc_reset_awb_ctrls(isc); in isc_set_fmt()
1026 isc_update_v4l2_ctrls(isc); in isc_set_fmt()
1029 isc->config = isc->try_config; in isc_set_fmt()
1031 v4l2_dbg(1, debug, &isc->v4l2_dev, "New ISC configuration in place\n"); in isc_set_fmt()
1039 struct isc_device *isc = video_drvdata(file); in isc_s_fmt_vid_cap() local
1041 if (vb2_is_busy(&isc->vb2_vidq)) in isc_s_fmt_vid_cap()
1044 return isc_set_fmt(isc, f); in isc_s_fmt_vid_cap()
1050 struct isc_device *isc = video_drvdata(file); in isc_try_fmt_vid_cap() local
1052 return isc_try_fmt(isc, f, NULL); in isc_try_fmt_vid_cap()
1085 struct isc_device *isc = video_drvdata(file); in isc_g_parm() local
1087 return v4l2_g_parm_cap(video_devdata(file), isc->current_subdev->sd, a); in isc_g_parm()
1092 struct isc_device *isc = video_drvdata(file); in isc_s_parm() local
1094 return v4l2_s_parm_cap(video_devdata(file), isc->current_subdev->sd, a); in isc_s_parm()
1100 struct isc_device *isc = video_drvdata(file); in isc_enum_framesizes() local
1107 for (i = 0; i < isc->num_user_formats; i++) in isc_enum_framesizes()
1108 if (isc->user_formats[i]->fourcc == fsize->pixel_format) in isc_enum_framesizes()
1111 for (i = 0; i < isc->controller_formats_size; i++) in isc_enum_framesizes()
1112 if (isc->controller_formats[i].fourcc == fsize->pixel_format) in isc_enum_framesizes()
1121 fsize->stepwise.max_width = isc->max_width; in isc_enum_framesizes()
1123 fsize->stepwise.max_height = isc->max_height; in isc_enum_framesizes()
1162 struct isc_device *isc = video_drvdata(file); in isc_open() local
1163 struct v4l2_subdev *sd = isc->current_subdev->sd; in isc_open()
1166 if (mutex_lock_interruptible(&isc->lock)) in isc_open()
1182 ret = isc_set_fmt(isc, &isc->fmt); in isc_open()
1189 mutex_unlock(&isc->lock); in isc_open()
1195 struct isc_device *isc = video_drvdata(file); in isc_release() local
1196 struct v4l2_subdev *sd = isc->current_subdev->sd; in isc_release()
1200 mutex_lock(&isc->lock); in isc_release()
1209 mutex_unlock(&isc->lock); in isc_release()
1226 struct isc_device *isc = (struct isc_device *)dev_id; in isc_interrupt() local
1227 struct regmap *regmap = isc->regmap; in isc_interrupt()
1237 spin_lock(&isc->dma_queue_lock); in isc_interrupt()
1238 if (isc->cur_frm) { in isc_interrupt()
1239 struct vb2_v4l2_buffer *vbuf = &isc->cur_frm->vb; in isc_interrupt()
1243 vbuf->sequence = isc->sequence++; in isc_interrupt()
1245 isc->cur_frm = NULL; in isc_interrupt()
1248 if (!list_empty(&isc->dma_queue) && !isc->stop) { in isc_interrupt()
1249 isc->cur_frm = list_first_entry(&isc->dma_queue, in isc_interrupt()
1251 list_del(&isc->cur_frm->list); in isc_interrupt()
1253 isc_start_dma(isc); in isc_interrupt()
1256 if (isc->stop) in isc_interrupt()
1257 complete(&isc->comp); in isc_interrupt()
1260 spin_unlock(&isc->dma_queue_lock); in isc_interrupt()
1264 schedule_work(&isc->awb_work); in isc_interrupt()
1272 static void isc_hist_count(struct isc_device *isc, u32 *min, u32 *max) in isc_hist_count() argument
1274 struct regmap *regmap = isc->regmap; in isc_hist_count()
1275 struct isc_ctrls *ctrls = &isc->ctrls; in isc_hist_count()
1283 regmap_bulk_read(regmap, ISC_HIS_ENTRY + isc->offsets.his_entry, in isc_hist_count()
1302 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_hist_count()
1309 struct isc_device *isc = container_of(ctrls, struct isc_device, ctrls); in isc_wb_update() local
1326 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_wb_update()
1381 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_wb_update()
1391 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_wb_update()
1399 struct isc_device *isc = in isc_awb_work() local
1401 struct regmap *regmap = isc->regmap; in isc_awb_work()
1402 struct isc_ctrls *ctrls = &isc->ctrls; in isc_awb_work()
1412 isc_hist_count(isc, &min, &max); in isc_awb_work()
1414 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_awb_work()
1428 baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT; in isc_awb_work()
1430 ret = pm_runtime_resume_and_get(isc->dev); in isc_awb_work()
1445 spin_lock_irqsave(&isc->awb_lock, flags); in isc_awb_work()
1446 isc_update_awb_ctrls(isc); in isc_awb_work()
1447 spin_unlock_irqrestore(&isc->awb_lock, flags); in isc_awb_work()
1454 v4l2_info(&isc->v4l2_dev, in isc_awb_work()
1457 isc_update_v4l2_ctrls(isc); in isc_awb_work()
1461 regmap_write(regmap, ISC_HIS_CFG + isc->offsets.his, in isc_awb_work()
1469 mutex_lock(&isc->awb_mutex); in isc_awb_work()
1472 if (isc->stop) { in isc_awb_work()
1473 mutex_unlock(&isc->awb_mutex); in isc_awb_work()
1477 isc_update_profile(isc); in isc_awb_work()
1479 mutex_unlock(&isc->awb_mutex); in isc_awb_work()
1485 pm_runtime_put_sync(isc->dev); in isc_awb_work()
1490 struct isc_device *isc = container_of(ctrl->handler, in isc_s_ctrl() local
1492 struct isc_ctrls *ctrls = &isc->ctrls; in isc_s_ctrl()
1520 struct isc_device *isc = container_of(ctrl->handler, in isc_s_awb_ctrl() local
1522 struct isc_ctrls *ctrls = &isc->ctrls; in isc_s_awb_ctrl()
1536 ctrls->gain[ISC_HIS_CFG_MODE_R] = isc->r_gain_ctrl->val; in isc_s_awb_ctrl()
1538 ctrls->gain[ISC_HIS_CFG_MODE_B] = isc->b_gain_ctrl->val; in isc_s_awb_ctrl()
1540 ctrls->gain[ISC_HIS_CFG_MODE_GR] = isc->gr_gain_ctrl->val; in isc_s_awb_ctrl()
1542 ctrls->gain[ISC_HIS_CFG_MODE_GB] = isc->gb_gain_ctrl->val; in isc_s_awb_ctrl()
1545 ctrls->offset[ISC_HIS_CFG_MODE_R] = isc->r_off_ctrl->val; in isc_s_awb_ctrl()
1547 ctrls->offset[ISC_HIS_CFG_MODE_B] = isc->b_off_ctrl->val; in isc_s_awb_ctrl()
1549 ctrls->offset[ISC_HIS_CFG_MODE_GR] = isc->gr_off_ctrl->val; in isc_s_awb_ctrl()
1551 ctrls->offset[ISC_HIS_CFG_MODE_GB] = isc->gb_off_ctrl->val; in isc_s_awb_ctrl()
1553 isc_update_awb_ctrls(isc); in isc_s_awb_ctrl()
1555 mutex_lock(&isc->awb_mutex); in isc_s_awb_ctrl()
1556 if (vb2_is_streaming(&isc->vb2_vidq)) { in isc_s_awb_ctrl()
1561 isc_update_profile(isc); in isc_s_awb_ctrl()
1568 v4l2_ctrl_activate(isc->do_wb_ctrl, false); in isc_s_awb_ctrl()
1570 mutex_unlock(&isc->awb_mutex); in isc_s_awb_ctrl()
1574 vb2_is_streaming(&isc->vb2_vidq) && in isc_s_awb_ctrl()
1575 ISC_IS_FORMAT_RAW(isc->config.sd_format->mbus_code)) in isc_s_awb_ctrl()
1576 isc_set_histogram(isc, true); in isc_s_awb_ctrl()
1587 isc_set_histogram(isc, true); in isc_s_awb_ctrl()
1588 v4l2_dbg(1, debug, &isc->v4l2_dev, in isc_s_awb_ctrl()
1598 struct isc_device *isc = container_of(ctrl->handler, in isc_g_volatile_awb_ctrl() local
1600 struct isc_ctrls *ctrls = &isc->ctrls; in isc_g_volatile_awb_ctrl()
1668 static int isc_ctrl_init(struct isc_device *isc) in isc_ctrl_init() argument
1671 struct isc_ctrls *ctrls = &isc->ctrls; in isc_ctrl_init()
1676 isc_reset_awb_ctrls(isc); in isc_ctrl_init()
1683 isc->config_ctrls(isc, ops); in isc_ctrl_init()
1688 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAMMA, 0, isc->gamma_max, 1, in isc_ctrl_init()
1689 isc->gamma_max); in isc_ctrl_init()
1690 isc->awb_ctrl = v4l2_ctrl_new_std(hdl, &isc_awb_ops, in isc_ctrl_init()
1695 isc->do_wb_ctrl = v4l2_ctrl_new_std(hdl, &isc_awb_ops, in isc_ctrl_init()
1699 if (!isc->do_wb_ctrl) { in isc_ctrl_init()
1705 v4l2_ctrl_activate(isc->do_wb_ctrl, false); in isc_ctrl_init()
1707 isc->r_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_r_gain_ctrl, NULL); in isc_ctrl_init()
1708 isc->b_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_b_gain_ctrl, NULL); in isc_ctrl_init()
1709 isc->gr_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gr_gain_ctrl, NULL); in isc_ctrl_init()
1710 isc->gb_gain_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gb_gain_ctrl, NULL); in isc_ctrl_init()
1711 isc->r_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_r_off_ctrl, NULL); in isc_ctrl_init()
1712 isc->b_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_b_off_ctrl, NULL); in isc_ctrl_init()
1713 isc->gr_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gr_off_ctrl, NULL); in isc_ctrl_init()
1714 isc->gb_off_ctrl = v4l2_ctrl_new_custom(hdl, &isc_gb_off_ctrl, NULL); in isc_ctrl_init()
1720 v4l2_ctrl_auto_cluster(10, &isc->awb_ctrl, 0, true); in isc_ctrl_init()
1731 struct isc_device *isc = container_of(notifier->v4l2_dev, in isc_async_bound() local
1736 if (video_is_registered(&isc->video_dev)) { in isc_async_bound()
1737 v4l2_err(&isc->v4l2_dev, "only supports one sub-device.\n"); in isc_async_bound()
1750 struct isc_device *isc = container_of(notifier->v4l2_dev, in isc_async_unbind() local
1752 mutex_destroy(&isc->awb_mutex); in isc_async_unbind()
1753 cancel_work_sync(&isc->awb_work); in isc_async_unbind()
1754 video_unregister_device(&isc->video_dev); in isc_async_unbind()
1755 v4l2_ctrl_handler_free(&isc->ctrls.handler); in isc_async_unbind()
1758 static struct isc_format *find_format_by_code(struct isc_device *isc, in find_format_by_code() argument
1761 struct isc_format *fmt = &isc->formats_list[0]; in find_format_by_code()
1764 for (i = 0; i < isc->formats_list_size; i++) { in find_format_by_code()
1776 static int isc_formats_init(struct isc_device *isc) in isc_formats_init() argument
1779 struct v4l2_subdev *subdev = isc->current_subdev->sd; in isc_formats_init()
1781 u32 list_size = isc->formats_list_size; in isc_formats_init()
1791 fmt = find_format_by_code(isc, mbus_code.code, &i); in isc_formats_init()
1793 v4l2_warn(&isc->v4l2_dev, "Mbus code %x not supported\n", in isc_formats_init()
1805 isc->num_user_formats = num_fmts; in isc_formats_init()
1806 isc->user_formats = devm_kcalloc(isc->dev, in isc_formats_init()
1807 num_fmts, sizeof(*isc->user_formats), in isc_formats_init()
1809 if (!isc->user_formats) in isc_formats_init()
1812 fmt = &isc->formats_list[0]; in isc_formats_init()
1815 isc->user_formats[j++] = fmt; in isc_formats_init()
1822 static int isc_set_default_fmt(struct isc_device *isc) in isc_set_default_fmt() argument
1830 .pixelformat = isc->user_formats[0]->fourcc, in isc_set_default_fmt()
1835 ret = isc_try_fmt(isc, &f, NULL); in isc_set_default_fmt()
1839 isc->fmt = f; in isc_set_default_fmt()
1845 struct isc_device *isc = container_of(notifier->v4l2_dev, in isc_async_complete() local
1847 struct video_device *vdev = &isc->video_dev; in isc_async_complete()
1848 struct vb2_queue *q = &isc->vb2_vidq; in isc_async_complete()
1851 INIT_WORK(&isc->awb_work, isc_awb_work); in isc_async_complete()
1853 ret = v4l2_device_register_subdev_nodes(&isc->v4l2_dev); in isc_async_complete()
1855 v4l2_err(&isc->v4l2_dev, "Failed to register subdev nodes\n"); in isc_async_complete()
1859 isc->current_subdev = container_of(notifier, in isc_async_complete()
1861 mutex_init(&isc->lock); in isc_async_complete()
1862 mutex_init(&isc->awb_mutex); in isc_async_complete()
1864 init_completion(&isc->comp); in isc_async_complete()
1869 q->drv_priv = isc; in isc_async_complete()
1874 q->lock = &isc->lock; in isc_async_complete()
1876 q->dev = isc->dev; in isc_async_complete()
1880 v4l2_err(&isc->v4l2_dev, in isc_async_complete()
1886 INIT_LIST_HEAD(&isc->dma_queue); in isc_async_complete()
1887 spin_lock_init(&isc->dma_queue_lock); in isc_async_complete()
1888 spin_lock_init(&isc->awb_lock); in isc_async_complete()
1890 ret = isc_formats_init(isc); in isc_async_complete()
1892 v4l2_err(&isc->v4l2_dev, in isc_async_complete()
1897 ret = isc_set_default_fmt(isc); in isc_async_complete()
1899 v4l2_err(&isc->v4l2_dev, "Could not set default format\n"); in isc_async_complete()
1903 ret = isc_ctrl_init(isc); in isc_async_complete()
1905 v4l2_err(&isc->v4l2_dev, "Init isc ctrols failed: %d\n", ret); in isc_async_complete()
1914 vdev->v4l2_dev = &isc->v4l2_dev; in isc_async_complete()
1917 vdev->lock = &isc->lock; in isc_async_complete()
1918 vdev->ctrl_handler = &isc->ctrls.handler; in isc_async_complete()
1920 video_set_drvdata(vdev, isc); in isc_async_complete()
1924 v4l2_err(&isc->v4l2_dev, in isc_async_complete()
1932 mutex_destroy(&isc->awb_mutex); in isc_async_complete()
1933 mutex_destroy(&isc->lock); in isc_async_complete()
1944 void isc_subdev_cleanup(struct isc_device *isc) in isc_subdev_cleanup() argument
1948 list_for_each_entry(subdev_entity, &isc->subdev_entities, list) { in isc_subdev_cleanup()
1953 INIT_LIST_HEAD(&isc->subdev_entities); in isc_subdev_cleanup()
1957 int isc_pipeline_init(struct isc_device *isc) in isc_pipeline_init() argument
1959 struct device *dev = isc->dev; in isc_pipeline_init()
1960 struct regmap *regmap = isc->regmap; in isc_pipeline_init()
1980 REG_FIELD(ISC_CSC_CTRL + isc->offsets.csc, 0, 0), in isc_pipeline_init()
1981 REG_FIELD(ISC_CBC_CTRL + isc->offsets.cbc, 0, 0), in isc_pipeline_init()
1982 REG_FIELD(ISC_SUB422_CTRL + isc->offsets.sub422, 0, 0), in isc_pipeline_init()
1983 REG_FIELD(ISC_SUB420_CTRL + isc->offsets.sub420, 0, 0), in isc_pipeline_init()
1991 isc->pipeline[i] = regs; in isc_pipeline_init()