Lines Matching +full:strobe +full:- +full:pos

1 // SPDX-License-Identifier: GPL-2.0-only
5 * TI OMAP3 ISP - Core
7 * Copyright (C) 2006-2010 Nokia Corporation
8 * Copyright (C) 2007-2009 Texas Instruments, Inc.
17 * Stanimir Varbanov <svarbanov@mm-sol.com>
22 * Ivan T. Ivanov <iivanov@mm-sol.com>
23 * RaniSuneela <r-m@ti.com>
24 * Atanas Filipov <afilipov@mm-sol.com>
25 * Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
27 * Nayden Kanchev <nkanchev@mm-sol.com>
28 * Phil Carmody <ext-phil.2.carmody@nokia.com>
32 * Pallavi Kulkarni <p-kulkarni@ti.com>
39 * Troy Laramy <t-laramy@ti.com>
46 #include <linux/dma-mapping.h>
51 #include <linux/omap-iommu.h>
60 #include <asm/dma-iommu.h>
63 #include <media/v4l2-common.h>
64 #include <media/v4l2-fwnode.h>
65 #include <media/v4l2-device.h>
66 #include <media/v4l2-mc.h>
138 * omap3isp_flush - Post pending L3 bus writes by doing a register readback
145 * https://www.mail-archive.com/linux-omap@vger.kernel.org/msg08149.html
153 /* -----------------------------------------------------------------------------
161 switch (xclk->id) { in isp_xclk_update()
163 isp_reg_clr_set(xclk->isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL, in isp_xclk_update()
168 isp_reg_clr_set(xclk->isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL, in isp_xclk_update()
179 omap3isp_get(xclk->isp); in isp_xclk_prepare()
188 omap3isp_put(xclk->isp); in isp_xclk_unprepare()
196 spin_lock_irqsave(&xclk->lock, flags); in isp_xclk_enable()
197 isp_xclk_update(xclk, xclk->divider); in isp_xclk_enable()
198 xclk->enabled = true; in isp_xclk_enable()
199 spin_unlock_irqrestore(&xclk->lock, flags); in isp_xclk_enable()
209 spin_lock_irqsave(&xclk->lock, flags); in isp_xclk_disable()
211 xclk->enabled = false; in isp_xclk_disable()
212 spin_unlock_irqrestore(&xclk->lock, flags); in isp_xclk_disable()
220 return parent_rate / xclk->divider; in isp_xclk_recalc_rate()
237 divider = ISPTCTRL_CTRL_DIV_BYPASS - 1; in isp_xclk_calc_divider()
259 spin_lock_irqsave(&xclk->lock, flags); in isp_xclk_set_rate()
261 xclk->divider = divider; in isp_xclk_set_rate()
262 if (xclk->enabled) in isp_xclk_set_rate()
265 spin_unlock_irqrestore(&xclk->lock, flags); in isp_xclk_set_rate()
267 dev_dbg(xclk->isp->dev, "%s: cam_xclk%c set to %lu Hz (div %u)\n", in isp_xclk_set_rate()
268 __func__, xclk->id == ISP_XCLK_A ? 'a' : 'b', rate, divider); in isp_xclk_set_rate()
286 unsigned int idx = clkspec->args[0]; in isp_xclk_src_get()
289 if (idx >= ARRAY_SIZE(isp->xclks)) in isp_xclk_src_get()
290 return ERR_PTR(-ENOENT); in isp_xclk_src_get()
292 return isp->xclks[idx].clk; in isp_xclk_src_get()
297 struct device_node *np = isp->dev->of_node; in isp_xclk_init()
301 for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) in isp_xclk_init()
302 isp->xclks[i].clk = ERR_PTR(-EINVAL); in isp_xclk_init()
304 for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) { in isp_xclk_init()
305 struct isp_xclk *xclk = &isp->xclks[i]; in isp_xclk_init()
307 xclk->isp = isp; in isp_xclk_init()
308 xclk->id = i == 0 ? ISP_XCLK_A : ISP_XCLK_B; in isp_xclk_init()
309 xclk->divider = 1; in isp_xclk_init()
310 spin_lock_init(&xclk->lock); in isp_xclk_init()
317 xclk->hw.init = &init; in isp_xclk_init()
324 xclk->clk = clk_register(NULL, &xclk->hw); in isp_xclk_init()
325 if (IS_ERR(xclk->clk)) in isp_xclk_init()
326 return PTR_ERR(xclk->clk); in isp_xclk_init()
337 struct device_node *np = isp->dev->of_node; in isp_xclk_cleanup()
343 for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) { in isp_xclk_cleanup()
344 struct isp_xclk *xclk = &isp->xclks[i]; in isp_xclk_cleanup()
346 if (!IS_ERR(xclk->clk)) in isp_xclk_cleanup()
347 clk_unregister(xclk->clk); in isp_xclk_cleanup()
351 /* -----------------------------------------------------------------------------
356 * isp_enable_interrupts - Enable ISP interrupts.
379 * isp_disable_interrupts - Disable ISP interrupts.
388 * isp_core_init - ISP core settings
396 * enabled, as the sensor might be free-running and the ISP default setting
405 ((isp->revision == ISP_REVISION_15_0) ? in isp_core_init()
410 (isp->autoidle ? ISPCTRL_SBL_AUTOIDLE : 0) | in isp_core_init()
443 ispctrl_val |= parcfg->clk_pol << ISPCTRL_PAR_CLK_POL_SHIFT; in omap3isp_configure_bridge()
444 shift += parcfg->data_lane_shift; in omap3isp_configure_bridge()
470 if (omap3isp_ccdc_busy(&isp->isp_ccdc) || in omap3isp_hist_dma_done()
471 omap3isp_stat_pcr_busy(&isp->isp_hist)) { in omap3isp_hist_dma_done()
473 atomic_set(&isp->isp_hist.buf_err, 1); in omap3isp_hist_dma_done()
474 dev_dbg(isp->dev, in omap3isp_hist_dma_done()
518 dev_dbg(isp->dev, "ISP IRQ: "); in isp_isr_dbg()
529 struct device *dev = isp->dev; in isp_isr_sbl()
545 pipe = to_isp_pipeline(&isp->isp_ccp2.subdev.entity); in isp_isr_sbl()
547 pipe->error = true; in isp_isr_sbl()
551 pipe = to_isp_pipeline(&isp->isp_csi2a.subdev.entity); in isp_isr_sbl()
553 pipe->error = true; in isp_isr_sbl()
557 pipe = to_isp_pipeline(&isp->isp_ccdc.subdev.entity); in isp_isr_sbl()
559 pipe->error = true; in isp_isr_sbl()
563 pipe = to_isp_pipeline(&isp->isp_prev.subdev.entity); in isp_isr_sbl()
565 pipe->error = true; in isp_isr_sbl()
572 pipe = to_isp_pipeline(&isp->isp_res.subdev.entity); in isp_isr_sbl()
574 pipe->error = true; in isp_isr_sbl()
578 omap3isp_stat_sbl_overflow(&isp->isp_af); in isp_isr_sbl()
581 omap3isp_stat_sbl_overflow(&isp->isp_aewb); in isp_isr_sbl()
585 * isp_isr - Interrupt Service Routine for Camera ISP module.
607 omap3isp_csi2_isr(&isp->isp_csi2a); in isp_isr()
610 omap3isp_ccp2_isr(&isp->isp_ccp2); in isp_isr()
613 if (isp->isp_ccdc.output & CCDC_OUTPUT_PREVIEW) in isp_isr()
614 omap3isp_preview_isr_frame_sync(&isp->isp_prev); in isp_isr()
615 if (isp->isp_ccdc.output & CCDC_OUTPUT_RESIZER) in isp_isr()
616 omap3isp_resizer_isr_frame_sync(&isp->isp_res); in isp_isr()
617 omap3isp_stat_isr_frame_sync(&isp->isp_aewb); in isp_isr()
618 omap3isp_stat_isr_frame_sync(&isp->isp_af); in isp_isr()
619 omap3isp_stat_isr_frame_sync(&isp->isp_hist); in isp_isr()
623 omap3isp_ccdc_isr(&isp->isp_ccdc, irqstatus & ccdc_events); in isp_isr()
626 if (isp->isp_prev.output & PREVIEW_OUTPUT_RESIZER) in isp_isr()
627 omap3isp_resizer_isr_frame_sync(&isp->isp_res); in isp_isr()
628 omap3isp_preview_isr(&isp->isp_prev); in isp_isr()
632 omap3isp_resizer_isr(&isp->isp_res); in isp_isr()
635 omap3isp_stat_isr(&isp->isp_aewb); in isp_isr()
638 omap3isp_stat_isr(&isp->isp_af); in isp_isr()
641 omap3isp_stat_isr(&isp->isp_hist); in isp_isr()
656 /* -----------------------------------------------------------------------------
661 * isp_pipeline_enable - Enable streaming on a pipeline
674 struct isp_device *isp = pipe->output->isp; in isp_pipeline_enable()
686 if (media_entity_enum_intersects(&pipe->ent_enum, &isp->crashed)) in isp_pipeline_enable()
687 return -EIO; in isp_pipeline_enable()
689 spin_lock_irqsave(&pipe->lock, flags); in isp_pipeline_enable()
690 pipe->state &= ~(ISP_PIPELINE_IDLE_INPUT | ISP_PIPELINE_IDLE_OUTPUT); in isp_pipeline_enable()
691 spin_unlock_irqrestore(&pipe->lock, flags); in isp_pipeline_enable()
693 pipe->do_propagation = false; in isp_pipeline_enable()
695 mutex_lock(&isp->media_dev.graph_mutex); in isp_pipeline_enable()
697 entity = &pipe->output->video.entity; in isp_pipeline_enable()
699 pad = &entity->pads[0]; in isp_pipeline_enable()
700 if (!(pad->flags & MEDIA_PAD_FL_SINK)) in isp_pipeline_enable()
704 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in isp_pipeline_enable()
707 entity = pad->entity; in isp_pipeline_enable()
711 if (ret < 0 && ret != -ENOIOCTLCMD) { in isp_pipeline_enable()
712 mutex_unlock(&isp->media_dev.graph_mutex); in isp_pipeline_enable()
716 if (subdev == &isp->isp_ccdc.subdev) { in isp_pipeline_enable()
717 v4l2_subdev_call(&isp->isp_aewb.subdev, video, in isp_pipeline_enable()
719 v4l2_subdev_call(&isp->isp_af.subdev, video, in isp_pipeline_enable()
721 v4l2_subdev_call(&isp->isp_hist.subdev, video, in isp_pipeline_enable()
723 pipe->do_propagation = true; in isp_pipeline_enable()
726 /* Stop at the first external sub-device. */ in isp_pipeline_enable()
727 if (subdev->dev != isp->dev) in isp_pipeline_enable()
731 mutex_unlock(&isp->media_dev.graph_mutex); in isp_pipeline_enable()
738 return omap3isp_resizer_busy(&isp->isp_res); in isp_pipeline_wait_resizer()
743 return omap3isp_preview_busy(&isp->isp_prev); in isp_pipeline_wait_preview()
748 return omap3isp_stat_busy(&isp->isp_af) in isp_pipeline_wait_ccdc()
749 || omap3isp_stat_busy(&isp->isp_aewb) in isp_pipeline_wait_ccdc()
750 || omap3isp_stat_busy(&isp->isp_hist) in isp_pipeline_wait_ccdc()
751 || omap3isp_ccdc_busy(&isp->isp_ccdc); in isp_pipeline_wait_ccdc()
770 * isp_pipeline_disable - Disable streaming on a pipeline
777 * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
783 struct isp_device *isp = pipe->output->isp; in isp_pipeline_disable()
794 entity = &pipe->output->video.entity; in isp_pipeline_disable()
796 pad = &entity->pads[0]; in isp_pipeline_disable()
797 if (!(pad->flags & MEDIA_PAD_FL_SINK)) in isp_pipeline_disable()
801 if (!pad || !is_media_entity_v4l2_subdev(pad->entity)) in isp_pipeline_disable()
804 entity = pad->entity; in isp_pipeline_disable()
807 if (subdev == &isp->isp_ccdc.subdev) { in isp_pipeline_disable()
808 v4l2_subdev_call(&isp->isp_aewb.subdev, in isp_pipeline_disable()
810 v4l2_subdev_call(&isp->isp_af.subdev, in isp_pipeline_disable()
812 v4l2_subdev_call(&isp->isp_hist.subdev, in isp_pipeline_disable()
818 /* Stop at the first external sub-device. */ in isp_pipeline_disable()
819 if (subdev->dev != isp->dev) in isp_pipeline_disable()
822 if (subdev == &isp->isp_res.subdev) in isp_pipeline_disable()
824 else if (subdev == &isp->isp_prev.subdev) in isp_pipeline_disable()
826 else if (subdev == &isp->isp_ccdc.subdev) in isp_pipeline_disable()
842 dev_info(isp->dev, "Unable to stop %s\n", subdev->name); in isp_pipeline_disable()
843 isp->stop_failure = true; in isp_pipeline_disable()
844 if (subdev == &isp->isp_prev.subdev) in isp_pipeline_disable()
845 media_entity_enum_set(&isp->crashed, in isp_pipeline_disable()
846 &subdev->entity); in isp_pipeline_disable()
847 failure = -ETIMEDOUT; in isp_pipeline_disable()
855 * omap3isp_pipeline_set_stream - Enable/disable streaming on a pipeline
860 * single-shot or continuous mode.
877 pipe->stream_state = state; in omap3isp_pipeline_set_stream()
883 * omap3isp_pipeline_cancel_stream - Cancel stream on a pipeline
893 if (pipe->input) in omap3isp_pipeline_cancel_stream()
894 omap3isp_video_cancel_stream(pipe->input); in omap3isp_pipeline_cancel_stream()
895 if (pipe->output) in omap3isp_pipeline_cancel_stream()
896 omap3isp_video_cancel_stream(pipe->output); in omap3isp_pipeline_cancel_stream()
900 * isp_pipeline_resume - Resume streaming on a pipeline
903 * Resume video output and input and re-enable pipeline.
907 int singleshot = pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT; in isp_pipeline_resume()
909 omap3isp_video_resume(pipe->output, !singleshot); in isp_pipeline_resume()
911 omap3isp_video_resume(pipe->input, 0); in isp_pipeline_resume()
912 isp_pipeline_enable(pipe, pipe->stream_state); in isp_pipeline_resume()
916 * isp_pipeline_suspend - Suspend streaming on a pipeline
927 * isp_pipeline_is_last - Verify if entity has an enabled link to the output
941 if (!pipe || pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED) in isp_pipeline_is_last()
943 pad = media_pad_remote_pad_first(&pipe->output->pad); in isp_pipeline_is_last()
944 return pad->entity == me; in isp_pipeline_is_last()
948 * isp_suspend_module_pipeline - Suspend pipeline to which belongs the module
962 * isp_resume_module_pipeline - Resume pipeline to which belongs the module
976 * isp_suspend_modules - Suspend ISP submodules.
986 omap3isp_stat_suspend(&isp->isp_aewb); in isp_suspend_modules()
987 omap3isp_stat_suspend(&isp->isp_af); in isp_suspend_modules()
988 omap3isp_stat_suspend(&isp->isp_hist); in isp_suspend_modules()
989 isp_suspend_module_pipeline(&isp->isp_res.subdev.entity); in isp_suspend_modules()
990 isp_suspend_module_pipeline(&isp->isp_prev.subdev.entity); in isp_suspend_modules()
991 isp_suspend_module_pipeline(&isp->isp_ccdc.subdev.entity); in isp_suspend_modules()
992 isp_suspend_module_pipeline(&isp->isp_csi2a.subdev.entity); in isp_suspend_modules()
993 isp_suspend_module_pipeline(&isp->isp_ccp2.subdev.entity); in isp_suspend_modules()
996 while (omap3isp_stat_busy(&isp->isp_af) in isp_suspend_modules()
997 || omap3isp_stat_busy(&isp->isp_aewb) in isp_suspend_modules()
998 || omap3isp_stat_busy(&isp->isp_hist) in isp_suspend_modules()
999 || omap3isp_preview_busy(&isp->isp_prev) in isp_suspend_modules()
1000 || omap3isp_resizer_busy(&isp->isp_res) in isp_suspend_modules()
1001 || omap3isp_ccdc_busy(&isp->isp_ccdc)) { in isp_suspend_modules()
1003 dev_info(isp->dev, "can't stop modules.\n"); in isp_suspend_modules()
1013 * isp_resume_modules - Resume ISP submodules.
1018 omap3isp_stat_resume(&isp->isp_aewb); in isp_resume_modules()
1019 omap3isp_stat_resume(&isp->isp_af); in isp_resume_modules()
1020 omap3isp_stat_resume(&isp->isp_hist); in isp_resume_modules()
1021 isp_resume_module_pipeline(&isp->isp_res.subdev.entity); in isp_resume_modules()
1022 isp_resume_module_pipeline(&isp->isp_prev.subdev.entity); in isp_resume_modules()
1023 isp_resume_module_pipeline(&isp->isp_ccdc.subdev.entity); in isp_resume_modules()
1024 isp_resume_module_pipeline(&isp->isp_csi2a.subdev.entity); in isp_resume_modules()
1025 isp_resume_module_pipeline(&isp->isp_ccp2.subdev.entity); in isp_resume_modules()
1029 * isp_reset - Reset ISP with a timeout wait for idle.
1043 dev_alert(isp->dev, "cannot reset ISP\n"); in isp_reset()
1044 return -ETIMEDOUT; in isp_reset()
1049 isp->stop_failure = false; in isp_reset()
1050 media_entity_enum_zero(&isp->crashed); in isp_reset()
1055 * isp_save_context - Saves the values of the ISP module registers.
1065 for (; next->reg != ISP_TOK_TERM; next++) in isp_save_context()
1066 next->val = isp_reg_readl(isp, next->mmio_range, next->reg); in isp_save_context()
1070 * isp_restore_context - Restores the values of the ISP module registers.
1080 for (; next->reg != ISP_TOK_TERM; next++) in isp_restore_context()
1081 isp_reg_writel(isp, next->val, next->mmio_range, next->reg); in isp_restore_context()
1085 * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1094 omap_iommu_save_ctx(isp->dev); in isp_save_ctx()
1098 * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1107 omap_iommu_restore_ctx(isp->dev); in isp_restore_ctx()
1112 /* -----------------------------------------------------------------------------
1129 isp->sbl_resources |= res; in omap3isp_sbl_enable()
1131 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ) in omap3isp_sbl_enable()
1134 if (isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ) in omap3isp_sbl_enable()
1137 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE) in omap3isp_sbl_enable()
1140 if (isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE) in omap3isp_sbl_enable()
1143 if (isp->sbl_resources & OMAP3_ISP_SBL_WRITE) in omap3isp_sbl_enable()
1146 if (isp->sbl_resources & OMAP3_ISP_SBL_READ) in omap3isp_sbl_enable()
1156 isp->sbl_resources &= ~res; in omap3isp_sbl_disable()
1158 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ)) in omap3isp_sbl_disable()
1161 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ)) in omap3isp_sbl_disable()
1164 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE)) in omap3isp_sbl_disable()
1167 if (!(isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE)) in omap3isp_sbl_disable()
1170 if (!(isp->sbl_resources & OMAP3_ISP_SBL_WRITE)) in omap3isp_sbl_disable()
1173 if (!(isp->sbl_resources & OMAP3_ISP_SBL_READ)) in omap3isp_sbl_disable()
1180 * isp_module_sync_idle - Helper to sync module with its idle state
1193 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED || in omap3isp_module_sync_idle()
1194 (pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT && in omap3isp_module_sync_idle()
1215 struct isp_video *video = pipe->output; in omap3isp_module_sync_idle()
1217 spin_lock_irqsave(&video->irqlock, flags); in omap3isp_module_sync_idle()
1218 if (video->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_UNDERRUN) { in omap3isp_module_sync_idle()
1219 spin_unlock_irqrestore(&video->irqlock, flags); in omap3isp_module_sync_idle()
1224 spin_unlock_irqrestore(&video->irqlock, flags); in omap3isp_module_sync_idle()
1229 return -ETIMEDOUT; in omap3isp_module_sync_idle()
1237 * omap3isp_module_sync_is_stopping - Helper to verify if module was stopping
1256 /* --------------------------------------------------------------------------
1271 if (isp->subclk_resources & in __isp_subclk_update()
1275 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_HIST) in __isp_subclk_update()
1278 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_RESIZER) in __isp_subclk_update()
1284 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_CCDC) in __isp_subclk_update()
1287 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_PREVIEW) in __isp_subclk_update()
1297 isp->subclk_resources |= res; in omap3isp_subclk_enable()
1305 isp->subclk_resources &= ~res; in omap3isp_subclk_disable()
1311 * isp_enable_clocks - Enable ISP clocks
1322 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_ICK]); in isp_enable_clocks()
1324 dev_err(isp->dev, "failed to enable cam_ick clock\n"); in isp_enable_clocks()
1327 r = clk_set_rate(isp->clock[ISP_CLK_CAM_MCLK], CM_CAM_MCLK_HZ); in isp_enable_clocks()
1329 dev_err(isp->dev, "clk_set_rate for cam_mclk failed\n"); in isp_enable_clocks()
1332 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_MCLK]); in isp_enable_clocks()
1334 dev_err(isp->dev, "failed to enable cam_mclk clock\n"); in isp_enable_clocks()
1337 rate = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]); in isp_enable_clocks()
1339 dev_warn(isp->dev, "unexpected cam_mclk rate:\n" in isp_enable_clocks()
1342 r = clk_prepare_enable(isp->clock[ISP_CLK_CSI2_FCK]); in isp_enable_clocks()
1344 dev_err(isp->dev, "failed to enable csi2_fck clock\n"); in isp_enable_clocks()
1350 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]); in isp_enable_clocks()
1352 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]); in isp_enable_clocks()
1358 * isp_disable_clocks - Disable ISP clocks
1363 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]); in isp_disable_clocks()
1364 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]); in isp_disable_clocks()
1365 clk_disable_unprepare(isp->clock[ISP_CLK_CSI2_FCK]); in isp_disable_clocks()
1381 clk = devm_clk_get(isp->dev, isp_clocks[i]); in isp_get_clocks()
1383 dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]); in isp_get_clocks()
1387 isp->clock[i] = clk; in isp_get_clocks()
1394 * omap3isp_get - Acquire the ISP resource.
1399 * enable clocks and power-up all submodules.
1410 mutex_lock(&isp->isp_mutex); in __omap3isp_get()
1411 if (isp->ref_count > 0) in __omap3isp_get()
1420 if (isp->has_context) in __omap3isp_get()
1428 isp->ref_count++; in __omap3isp_get()
1429 mutex_unlock(&isp->isp_mutex); in __omap3isp_get()
1440 * omap3isp_put - Release the ISP
1443 * power-down all submodules, disable clocks and free temporary buffers.
1450 mutex_lock(&isp->isp_mutex); in __omap3isp_put()
1451 BUG_ON(isp->ref_count == 0); in __omap3isp_put()
1452 if (--isp->ref_count == 0) { in __omap3isp_put()
1456 isp->has_context = 1; in __omap3isp_put()
1461 if (!media_entity_enum_empty(&isp->crashed) || in __omap3isp_put()
1462 isp->stop_failure) in __omap3isp_put()
1466 mutex_unlock(&isp->isp_mutex); in __omap3isp_put()
1474 /* --------------------------------------------------------------------------
1479 * omap3isp_print_status - Prints the values of the ISP Control Module registers
1483 dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
1486 dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
1491 dev_dbg(isp->dev, "-------------ISP Register dump--------------\n"); in omap3isp_print_status()
1512 dev_dbg(isp->dev, "--------------------------------------------\n"); in omap3isp_print_status()
1528 * ISP clocks get disabled in suspend(). Similarly, the clocks are re-enabled in
1539 WARN_ON(mutex_is_locked(&isp->isp_mutex)); in isp_pm_prepare()
1541 if (isp->ref_count == 0) in isp_pm_prepare()
1557 WARN_ON(mutex_is_locked(&isp->isp_mutex)); in isp_pm_suspend()
1559 if (isp->ref_count) in isp_pm_suspend()
1569 if (isp->ref_count == 0) in isp_pm_resume()
1579 if (isp->ref_count == 0) in isp_pm_complete()
1598 media_device_unregister(&isp->media_dev); in isp_unregister_entities()
1600 omap3isp_csi2_unregister_entities(&isp->isp_csi2a); in isp_unregister_entities()
1601 omap3isp_ccp2_unregister_entities(&isp->isp_ccp2); in isp_unregister_entities()
1602 omap3isp_ccdc_unregister_entities(&isp->isp_ccdc); in isp_unregister_entities()
1603 omap3isp_preview_unregister_entities(&isp->isp_prev); in isp_unregister_entities()
1604 omap3isp_resizer_unregister_entities(&isp->isp_res); in isp_unregister_entities()
1605 omap3isp_stat_unregister_entities(&isp->isp_aewb); in isp_unregister_entities()
1606 omap3isp_stat_unregister_entities(&isp->isp_af); in isp_unregister_entities()
1607 omap3isp_stat_unregister_entities(&isp->isp_hist); in isp_unregister_entities()
1609 v4l2_device_unregister(&isp->v4l2_dev); in isp_unregister_entities()
1610 media_device_cleanup(&isp->media_dev); in isp_unregister_entities()
1629 input = &isp->isp_ccdc.subdev.entity; in isp_link_entity()
1635 input = &isp->isp_csi2a.subdev.entity; in isp_link_entity()
1642 input = &isp->isp_ccp2.subdev.entity; in isp_link_entity()
1648 input = &isp->isp_csi2c.subdev.entity; in isp_link_entity()
1654 dev_err(isp->dev, "%s: invalid interface type %u\n", __func__, in isp_link_entity()
1656 return -EINVAL; in isp_link_entity()
1661 * ISP. The sub-devices of those interfaces aren't initialised in isp_link_entity()
1663 * non-zero. in isp_link_entity()
1665 if (!input->num_pads) { in isp_link_entity()
1666 dev_err(isp->dev, "%s: invalid input %u\n", entity->name, in isp_link_entity()
1668 return -EINVAL; in isp_link_entity()
1671 for (i = 0; i < entity->num_pads; i++) { in isp_link_entity()
1672 if (entity->pads[i].flags & MEDIA_PAD_FL_SOURCE) in isp_link_entity()
1675 if (i == entity->num_pads) { in isp_link_entity()
1676 dev_err(isp->dev, "%s: no source pad in external entity %s\n", in isp_link_entity()
1677 __func__, entity->name); in isp_link_entity()
1678 return -EINVAL; in isp_link_entity()
1688 isp->media_dev.dev = isp->dev; in isp_register_entities()
1689 strscpy(isp->media_dev.model, "TI OMAP3 ISP", in isp_register_entities()
1690 sizeof(isp->media_dev.model)); in isp_register_entities()
1691 isp->media_dev.hw_revision = isp->revision; in isp_register_entities()
1692 isp->media_dev.ops = &isp_media_ops; in isp_register_entities()
1693 media_device_init(&isp->media_dev); in isp_register_entities()
1695 isp->v4l2_dev.mdev = &isp->media_dev; in isp_register_entities()
1696 ret = v4l2_device_register(isp->dev, &isp->v4l2_dev); in isp_register_entities()
1698 dev_err(isp->dev, "%s: V4L2 device registration failed (%d)\n", in isp_register_entities()
1704 ret = omap3isp_ccp2_register_entities(&isp->isp_ccp2, &isp->v4l2_dev); in isp_register_entities()
1708 ret = omap3isp_csi2_register_entities(&isp->isp_csi2a, &isp->v4l2_dev); in isp_register_entities()
1712 ret = omap3isp_ccdc_register_entities(&isp->isp_ccdc, &isp->v4l2_dev); in isp_register_entities()
1716 ret = omap3isp_preview_register_entities(&isp->isp_prev, in isp_register_entities()
1717 &isp->v4l2_dev); in isp_register_entities()
1721 ret = omap3isp_resizer_register_entities(&isp->isp_res, &isp->v4l2_dev); in isp_register_entities()
1725 ret = omap3isp_stat_register_entities(&isp->isp_aewb, &isp->v4l2_dev); in isp_register_entities()
1729 ret = omap3isp_stat_register_entities(&isp->isp_af, &isp->v4l2_dev); in isp_register_entities()
1733 ret = omap3isp_stat_register_entities(&isp->isp_hist, &isp->v4l2_dev); in isp_register_entities()
1745 * isp_create_links() - Create links for internal and external ISP entities
1759 &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE, in isp_create_links()
1760 &isp->isp_csi2a.video_out.video.entity, 0, 0); in isp_create_links()
1765 &isp->isp_ccp2.video_in.video.entity, 0, in isp_create_links()
1766 &isp->isp_ccp2.subdev.entity, CCP2_PAD_SINK, 0); in isp_create_links()
1771 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF, in isp_create_links()
1772 &isp->isp_ccdc.video_out.video.entity, 0, 0); in isp_create_links()
1777 &isp->isp_prev.video_in.video.entity, 0, in isp_create_links()
1778 &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0); in isp_create_links()
1783 &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE, in isp_create_links()
1784 &isp->isp_prev.video_out.video.entity, 0, 0); in isp_create_links()
1789 &isp->isp_res.video_in.video.entity, 0, in isp_create_links()
1790 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0); in isp_create_links()
1795 &isp->isp_res.subdev.entity, RESZ_PAD_SOURCE, in isp_create_links()
1796 &isp->isp_res.video_out.video.entity, 0, 0); in isp_create_links()
1803 &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE, in isp_create_links()
1804 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0); in isp_create_links()
1809 &isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE, in isp_create_links()
1810 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0); in isp_create_links()
1815 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP, in isp_create_links()
1816 &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0); in isp_create_links()
1821 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF, in isp_create_links()
1822 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0); in isp_create_links()
1827 &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE, in isp_create_links()
1828 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0); in isp_create_links()
1833 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP, in isp_create_links()
1834 &isp->isp_aewb.subdev.entity, 0, in isp_create_links()
1840 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP, in isp_create_links()
1841 &isp->isp_af.subdev.entity, 0, in isp_create_links()
1847 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP, in isp_create_links()
1848 &isp->isp_hist.subdev.entity, 0, in isp_create_links()
1875 dev_err(isp->dev, "CSI PHY initialization failed\n"); in isp_initialize_modules()
1881 dev_err(isp->dev, "CSI2 initialization failed\n"); in isp_initialize_modules()
1887 dev_err_probe(isp->dev, ret, "CCP2 initialization failed\n"); in isp_initialize_modules()
1893 dev_err(isp->dev, "CCDC initialization failed\n"); in isp_initialize_modules()
1899 dev_err(isp->dev, "Preview initialization failed\n"); in isp_initialize_modules()
1905 dev_err(isp->dev, "Resizer initialization failed\n"); in isp_initialize_modules()
1911 dev_err(isp->dev, "Histogram initialization failed\n"); in isp_initialize_modules()
1917 dev_err(isp->dev, "H3A AEWB initialization failed\n"); in isp_initialize_modules()
1923 dev_err(isp->dev, "H3A AF initialization failed\n"); in isp_initialize_modules()
1952 arm_iommu_detach_device(isp->dev); in isp_detach_iommu()
1953 arm_iommu_release_mapping(isp->mapping); in isp_detach_iommu()
1954 isp->mapping = NULL; in isp_detach_iommu()
1968 mapping = arm_iommu_create_mapping(isp->dev, SZ_1G, SZ_2G); in isp_attach_iommu()
1970 dev_err(isp->dev, "failed to create ARM IOMMU mapping\n"); in isp_attach_iommu()
1974 isp->mapping = mapping; in isp_attach_iommu()
1977 ret = arm_iommu_attach_device(isp->dev, mapping); in isp_attach_iommu()
1979 dev_err(isp->dev, "failed to attach device to VA mapping\n"); in isp_attach_iommu()
1986 arm_iommu_release_mapping(isp->mapping); in isp_attach_iommu()
1987 isp->mapping = NULL; in isp_attach_iommu()
1990 return -ENODEV; in isp_attach_iommu()
1995 * isp_remove - Remove ISP platform device
2004 v4l2_async_nf_unregister(&isp->notifier); in isp_remove()
2005 v4l2_async_nf_cleanup(&isp->notifier); in isp_remove()
2014 media_entity_enum_cleanup(&isp->crashed); in isp_remove()
2032 &container_of(asc, struct isp_async_subdev, asd)->bus; in isp_subdev_notifier_bound()
2035 mutex_lock(&isp->media_dev.graph_mutex); in isp_subdev_notifier_bound()
2036 ret = isp_link_entity(isp, &sd->entity, bus_cfg->interface); in isp_subdev_notifier_bound()
2037 mutex_unlock(&isp->media_dev.graph_mutex); in isp_subdev_notifier_bound()
2048 mutex_lock(&isp->media_dev.graph_mutex); in isp_subdev_notifier_complete()
2049 ret = media_entity_enum_init(&isp->crashed, &isp->media_dev); in isp_subdev_notifier_complete()
2050 mutex_unlock(&isp->media_dev.graph_mutex); in isp_subdev_notifier_complete()
2054 ret = v4l2_device_register_subdev_nodes(&isp->v4l2_dev); in isp_subdev_notifier_complete()
2058 return media_device_register(&isp->media_dev); in isp_subdev_notifier_complete()
2065 buscfg->interface = ISP_INTERFACE_PARALLEL; in isp_parse_of_parallel_endpoint()
2066 buscfg->bus.parallel.data_lane_shift = vep->bus.parallel.data_shift; in isp_parse_of_parallel_endpoint()
2067 buscfg->bus.parallel.clk_pol = in isp_parse_of_parallel_endpoint()
2068 !!(vep->bus.parallel.flags & V4L2_MBUS_PCLK_SAMPLE_FALLING); in isp_parse_of_parallel_endpoint()
2069 buscfg->bus.parallel.hs_pol = in isp_parse_of_parallel_endpoint()
2070 !!(vep->bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW); in isp_parse_of_parallel_endpoint()
2071 buscfg->bus.parallel.vs_pol = in isp_parse_of_parallel_endpoint()
2072 !!(vep->bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW); in isp_parse_of_parallel_endpoint()
2073 buscfg->bus.parallel.fld_pol = in isp_parse_of_parallel_endpoint()
2074 !!(vep->bus.parallel.flags & V4L2_MBUS_FIELD_EVEN_LOW); in isp_parse_of_parallel_endpoint()
2075 buscfg->bus.parallel.data_pol = in isp_parse_of_parallel_endpoint()
2076 !!(vep->bus.parallel.flags & V4L2_MBUS_DATA_ACTIVE_LOW); in isp_parse_of_parallel_endpoint()
2077 buscfg->bus.parallel.bt656 = vep->bus_type == V4L2_MBUS_BT656; in isp_parse_of_parallel_endpoint()
2086 buscfg->bus.csi2.lanecfg.clk.pos = vep->bus.mipi_csi2.clock_lane; in isp_parse_of_csi2_endpoint()
2087 buscfg->bus.csi2.lanecfg.clk.pol = in isp_parse_of_csi2_endpoint()
2088 vep->bus.mipi_csi2.lane_polarities[0]; in isp_parse_of_csi2_endpoint()
2089 dev_dbg(dev, "clock lane polarity %u, pos %u\n", in isp_parse_of_csi2_endpoint()
2090 buscfg->bus.csi2.lanecfg.clk.pol, in isp_parse_of_csi2_endpoint()
2091 buscfg->bus.csi2.lanecfg.clk.pos); in isp_parse_of_csi2_endpoint()
2093 buscfg->bus.csi2.num_data_lanes = vep->bus.mipi_csi2.num_data_lanes; in isp_parse_of_csi2_endpoint()
2095 for (i = 0; i < buscfg->bus.csi2.num_data_lanes; i++) { in isp_parse_of_csi2_endpoint()
2096 buscfg->bus.csi2.lanecfg.data[i].pos = in isp_parse_of_csi2_endpoint()
2097 vep->bus.mipi_csi2.data_lanes[i]; in isp_parse_of_csi2_endpoint()
2098 buscfg->bus.csi2.lanecfg.data[i].pol = in isp_parse_of_csi2_endpoint()
2099 vep->bus.mipi_csi2.lane_polarities[i + 1]; in isp_parse_of_csi2_endpoint()
2101 "data lane %u polarity %u, pos %u\n", i, in isp_parse_of_csi2_endpoint()
2102 buscfg->bus.csi2.lanecfg.data[i].pol, in isp_parse_of_csi2_endpoint()
2103 buscfg->bus.csi2.lanecfg.data[i].pos); in isp_parse_of_csi2_endpoint()
2109 buscfg->bus.csi2.crc = 1; in isp_parse_of_csi2_endpoint()
2116 buscfg->bus.ccp2.lanecfg.clk.pos = vep->bus.mipi_csi1.clock_lane; in isp_parse_of_csi1_endpoint()
2117 buscfg->bus.ccp2.lanecfg.clk.pol = vep->bus.mipi_csi1.lane_polarity[0]; in isp_parse_of_csi1_endpoint()
2118 dev_dbg(dev, "clock lane polarity %u, pos %u\n", in isp_parse_of_csi1_endpoint()
2119 buscfg->bus.ccp2.lanecfg.clk.pol, in isp_parse_of_csi1_endpoint()
2120 buscfg->bus.ccp2.lanecfg.clk.pos); in isp_parse_of_csi1_endpoint()
2122 buscfg->bus.ccp2.lanecfg.data[0].pos = vep->bus.mipi_csi1.data_lane; in isp_parse_of_csi1_endpoint()
2123 buscfg->bus.ccp2.lanecfg.data[0].pol = in isp_parse_of_csi1_endpoint()
2124 vep->bus.mipi_csi1.lane_polarity[1]; in isp_parse_of_csi1_endpoint()
2126 dev_dbg(dev, "data lane polarity %u, pos %u\n", in isp_parse_of_csi1_endpoint()
2127 buscfg->bus.ccp2.lanecfg.data[0].pol, in isp_parse_of_csi1_endpoint()
2128 buscfg->bus.ccp2.lanecfg.data[0].pos); in isp_parse_of_csi1_endpoint()
2130 buscfg->bus.ccp2.strobe_clk_pol = vep->bus.mipi_csi1.clock_inv; in isp_parse_of_csi1_endpoint()
2131 buscfg->bus.ccp2.phy_layer = vep->bus.mipi_csi1.strobe; in isp_parse_of_csi1_endpoint()
2132 buscfg->bus.ccp2.ccp2_mode = vep->bus_type == V4L2_MBUS_CCP2; in isp_parse_of_csi1_endpoint()
2133 buscfg->bus.ccp2.vp_clk_pol = 1; in isp_parse_of_csi1_endpoint()
2135 buscfg->bus.ccp2.crc = 1; in isp_parse_of_csi1_endpoint()
2156 dev_fwnode(isp->dev), ISP_OF_PHY_PARALLEL, 0, in isp_parse_of_endpoints()
2165 dev_dbg(isp->dev, "parsing parallel interface\n"); in isp_parse_of_endpoints()
2170 isd = v4l2_async_nf_add_fwnode_remote(&isp->notifier, in isp_parse_of_endpoints()
2174 isp_parse_of_parallel_endpoint(isp->dev, &vep, &isd->bus); in isp_parse_of_endpoints()
2187 dev_fwnode(isp->dev), isp_bus_interfaces[i].phy, 0, in isp_parse_of_endpoints()
2193 dev_dbg(isp->dev, "parsing serial interface %u, node %pOF\n", i, in isp_parse_of_endpoints()
2197 if (ret == -ENXIO) { in isp_parse_of_endpoints()
2202 if (ret == -ENXIO) { in isp_parse_of_endpoints()
2210 isd = v4l2_async_nf_add_fwnode_remote(&isp->notifier, in isp_parse_of_endpoints()
2218 isd->bus.interface = in isp_parse_of_endpoints()
2220 isp_parse_of_csi2_endpoint(isp->dev, &vep, &isd->bus); in isp_parse_of_endpoints()
2224 isd->bus.interface = in isp_parse_of_endpoints()
2226 isp_parse_of_csi1_endpoint(isp->dev, &vep, in isp_parse_of_endpoints()
2227 &isd->bus); in isp_parse_of_endpoints()
2247 * isp_probe - Probe ISP platform device
2251 * -ENOMEM if no memory available,
2252 * -ENODEV if no platform device resources found
2254 * -EINVAL if couldn't install ISR,
2266 dev_err(&pdev->dev, "could not allocate memory\n"); in isp_probe()
2267 return -ENOMEM; in isp_probe()
2270 ret = fwnode_property_read_u32(of_fwnode_handle(pdev->dev.of_node), in isp_probe()
2271 "ti,phy-type", &isp->phy_type); in isp_probe()
2275 isp->syscon = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, in isp_probe()
2277 if (IS_ERR(isp->syscon)) { in isp_probe()
2278 ret = PTR_ERR(isp->syscon); in isp_probe()
2282 ret = of_property_read_u32_index(pdev->dev.of_node, in isp_probe()
2283 "syscon", 1, &isp->syscon_offset); in isp_probe()
2287 isp->autoidle = autoidle; in isp_probe()
2289 mutex_init(&isp->isp_mutex); in isp_probe()
2290 spin_lock_init(&isp->stat_lock); in isp_probe()
2291 isp->dev = &pdev->dev; in isp_probe()
2293 isp->ref_count = 0; in isp_probe()
2295 ret = dma_coerce_mask_and_coherent(isp->dev, DMA_BIT_MASK(32)); in isp_probe()
2302 isp->isp_csiphy1.vdd = devm_regulator_get(&pdev->dev, "vdd-csiphy1"); in isp_probe()
2303 if (IS_ERR(isp->isp_csiphy1.vdd)) { in isp_probe()
2304 ret = PTR_ERR(isp->isp_csiphy1.vdd); in isp_probe()
2308 isp->isp_csiphy2.vdd = devm_regulator_get(&pdev->dev, "vdd-csiphy2"); in isp_probe()
2309 if (IS_ERR(isp->isp_csiphy2.vdd)) { in isp_probe()
2310 ret = PTR_ERR(isp->isp_csiphy2.vdd); in isp_probe()
2316 * The ISP clock tree is revision-dependent. We thus need to enable ICLK in isp_probe()
2327 isp->mmio_base[map_idx] = in isp_probe()
2329 if (IS_ERR(isp->mmio_base[map_idx])) { in isp_probe()
2330 ret = PTR_ERR(isp->mmio_base[map_idx]); in isp_probe()
2339 ret = clk_enable(isp->clock[ISP_CLK_CAM_ICK]); in isp_probe()
2343 isp->revision = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION); in isp_probe()
2344 dev_info(isp->dev, "Revision %d.%d found\n", in isp_probe()
2345 (isp->revision & 0xf0) >> 4, isp->revision & 0x0f); in isp_probe()
2347 clk_disable(isp->clock[ISP_CLK_CAM_ICK]); in isp_probe()
2350 ret = -ENODEV; in isp_probe()
2364 if (isp->revision == isp_res_maps[m].isp_rev) in isp_probe()
2368 dev_err(isp->dev, "No resource map found for ISP rev %d.%d\n", in isp_probe()
2369 (isp->revision & 0xf0) >> 4, isp->revision & 0xf); in isp_probe()
2370 ret = -ENODEV; in isp_probe()
2375 isp->mmio_base[i] = in isp_probe()
2376 isp->mmio_base[0] + isp_res_maps[m].offset[i]; in isp_probe()
2379 isp->mmio_base[i] = in isp_probe()
2380 isp->mmio_base[OMAP3_ISP_IOMEM_CSI2A_REGS1] in isp_probe()
2383 isp->mmio_hist_base_phys = in isp_probe()
2384 mem->start + isp_res_maps[m].offset[OMAP3_ISP_IOMEM_HIST]; in isp_probe()
2389 dev_err(&pdev->dev, "unable to attach to IOMMU\n"); in isp_probe()
2397 isp->irq_num = ret; in isp_probe()
2399 if (devm_request_irq(isp->dev, isp->irq_num, isp_isr, IRQF_SHARED, in isp_probe()
2401 dev_err(isp->dev, "Unable to request IRQ\n"); in isp_probe()
2402 ret = -EINVAL; in isp_probe()
2419 isp->notifier.ops = &isp_subdev_notifier_ops; in isp_probe()
2421 v4l2_async_nf_init(&isp->notifier, &isp->v4l2_dev); in isp_probe()
2427 ret = v4l2_async_nf_register(&isp->notifier); in isp_probe()
2437 v4l2_async_nf_cleanup(&isp->notifier); in isp_probe()
2447 mutex_destroy(&isp->isp_mutex); in isp_probe()
2468 { .compatible = "ti,omap3-isp" },