55 #include <asm/cacheflush.h>
59 #include <linux/device.h>
61 #include <linux/i2c.h>
63 #include <linux/module.h>
66 #include <linux/slab.h>
67 #include <linux/sched.h>
85 static unsigned int autoidle;
89 static void isp_save_ctx(
struct isp_device *isp);
91 static void isp_restore_ctx(
struct isp_device *isp);
127 static struct isp_reg isp_reg_list[] = {
154 static void isp_enable_interrupts(
struct isp_device *isp)
177 static void isp_disable_interrupts(
struct isp_device *isp)
199 unsigned long mclk_hz;
206 if (xclk >= mclk_hz) {
208 currentxclk = mclk_hz;
209 }
else if (xclk >= 2) {
210 divisor = mclk_hz / xclk;
213 currentxclk = mclk_hz /
divisor;
224 dev_dbg(isp->
dev,
"isp_set_xclk(): cam_xclka set to %d Hz\n",
231 dev_dbg(isp->
dev,
"isp_set_xclk(): cam_xclkb set to %d Hz\n",
237 dev_dbg(isp->
dev,
"ISP_ERR: isp_set_xclk(): Invalid requested "
238 "xclk. Must be 0 (A) or 1 (B).\n");
246 else if (divisor < 2 && isp->xclk_divisor[xclksel - 1] >= 2)
298 unsigned int shift,
unsigned int bridge)
307 ispctrl_val |= bridge;
343 dev_dbg(isp->
dev,
"hist: Out of synchronization with "
344 "CCDC. Ignoring next buffer.\n");
348 static inline void isp_isr_dbg(
struct isp_device *isp,
u32 irqstatus)
350 static const char *
name[] = {
369 "CCDC_LSC_PREFETCH_COMPLETED",
370 "CCDC_LSC_PREFETCH_ERROR",
389 if ((1 << i) & irqstatus)
395 static void isp_isr_sbl(
struct isp_device *isp)
410 dev_dbg(dev,
"SBL overflow (PCR = 0x%08x)\n", sbl_pcr);
413 pipe = to_isp_pipeline(&isp->
isp_ccp2.subdev.entity);
419 pipe = to_isp_pipeline(&isp->
isp_csi2a.subdev.entity);
425 pipe = to_isp_pipeline(&isp->
isp_ccdc.subdev.entity);
431 pipe = to_isp_pipeline(&isp->
isp_prev.subdev.entity);
440 pipe = to_isp_pipeline(&isp->
isp_res.subdev.entity);
493 if (irqstatus & ccdc_events)
516 #if defined(DEBUG) && defined(ISP_ISR_DEBUG)
517 isp_isr_dbg(isp, irqstatus);
550 static int isp_pipeline_pm_use_count(
struct media_entity *entity)
576 static int isp_pipeline_pm_power_one(
struct media_entity *entity,
int change)
584 if (entity->
use_count == 0 && change > 0 && subdev !=
NULL) {
609 static int isp_pipeline_pm_power(
struct media_entity *entity,
int change)
622 ret = isp_pipeline_pm_power_one(entity, change);
632 isp_pipeline_pm_power_one(first, -change);
651 int change = use ? 1 : -1;
661 ret = isp_pipeline_pm_power(entity, change);
687 int source_use = isp_pipeline_pm_use_count(source->
entity);
688 int sink_use = isp_pipeline_pm_use_count(sink->
entity);
693 isp_pipeline_pm_power(source->
entity, -sink_use);
694 isp_pipeline_pm_power(sink->
entity, -source_use);
698 ret = isp_pipeline_pm_power(source->
entity, sink_use);
702 ret = isp_pipeline_pm_power(sink->
entity, source_use);
704 isp_pipeline_pm_power(source->
entity, -sink_use);
724 static int isp_pipeline_enable(
struct isp_pipeline *pipe,
747 spin_unlock_irqrestore(&pipe->
lock, flags);
751 entity = &pipe->
output->video.entity;
753 pad = &entity->
pads[0];
769 if (subdev == &isp->
isp_ccdc.subdev) {
783 static int isp_pipeline_wait_resizer(
struct isp_device *isp)
788 static int isp_pipeline_wait_preview(
struct isp_device *isp)
793 static int isp_pipeline_wait_ccdc(
struct isp_device *isp)
801 #define ISP_STOP_TIMEOUT msecs_to_jiffies(1000)
803 static int isp_pipeline_wait(
struct isp_device *isp,
828 static int isp_pipeline_disable(
struct isp_pipeline *pipe)
841 entity = &pipe->
output->video.entity;
843 pad = &entity->
pads[0];
855 if (subdev == &isp->
isp_ccdc.subdev) {
866 if (subdev == &isp->
isp_res.subdev)
867 ret = isp_pipeline_wait(isp, isp_pipeline_wait_resizer);
868 else if (subdev == &isp->
isp_prev.subdev)
869 ret = isp_pipeline_wait(isp, isp_pipeline_wait_preview);
870 else if (subdev == &isp->
isp_ccdc.subdev)
871 ret = isp_pipeline_wait(isp, isp_pipeline_wait_ccdc);
881 isp->
crashed |= 1
U << subdev->entity.id;
907 ret = isp_pipeline_disable(pipe);
909 ret = isp_pipeline_enable(pipe, state);
923 static void isp_pipeline_resume(
struct isp_pipeline *pipe)
939 static void isp_pipeline_suspend(
struct isp_pipeline *pipe)
941 isp_pipeline_disable(pipe);
953 static int isp_pipeline_is_last(
struct media_entity *me)
960 pipe = to_isp_pipeline(me);
975 static void isp_suspend_module_pipeline(
struct media_entity *me)
977 if (isp_pipeline_is_last(me))
978 isp_pipeline_suspend(to_isp_pipeline(me));
989 static void isp_resume_module_pipeline(
struct media_entity *me)
991 if (isp_pipeline_is_last(me))
992 isp_pipeline_resume(to_isp_pipeline(me));
1002 static int isp_suspend_modules(
struct isp_device *isp)
1004 unsigned long timeout;
1009 isp_suspend_module_pipeline(&isp->
isp_res.subdev.entity);
1010 isp_suspend_module_pipeline(&isp->
isp_prev.subdev.entity);
1011 isp_suspend_module_pipeline(&isp->
isp_ccdc.subdev.entity);
1012 isp_suspend_module_pipeline(&isp->
isp_csi2a.subdev.entity);
1013 isp_suspend_module_pipeline(&isp->
isp_ccp2.subdev.entity);
1015 timeout =
jiffies + ISP_STOP_TIMEOUT;
1036 static void isp_resume_modules(
struct isp_device *isp)
1041 isp_resume_module_pipeline(&isp->
isp_res.subdev.entity);
1042 isp_resume_module_pipeline(&isp->
isp_prev.subdev.entity);
1043 isp_resume_module_pipeline(&isp->
isp_ccdc.subdev.entity);
1044 isp_resume_module_pipeline(&isp->
isp_csi2a.subdev.entity);
1045 isp_resume_module_pipeline(&isp->
isp_ccp2.subdev.entity);
1054 unsigned long timeout = 0;
1062 if (timeout++ > 10000) {
1063 dev_alert(isp->
dev,
"cannot reset ISP\n");
1097 struct isp_reg *next = reg_list;
1110 static void isp_save_ctx(
struct isp_device *isp)
1112 isp_save_context(isp, isp_reg_list);
1123 static void isp_restore_ctx(
struct isp_device *isp)
1125 isp_restore_context(isp, isp_reg_list);
1134 #define OMAP3_ISP_SBL_READ (OMAP3_ISP_SBL_CSI1_READ | \
1135 OMAP3_ISP_SBL_CCDC_LSC_READ | \
1136 OMAP3_ISP_SBL_PREVIEW_READ | \
1137 OMAP3_ISP_SBL_RESIZER_READ)
1138 #define OMAP3_ISP_SBL_WRITE (OMAP3_ISP_SBL_CSI1_WRITE | \
1139 OMAP3_ISP_SBL_CSI2A_WRITE | \
1140 OMAP3_ISP_SBL_CSI2C_WRITE | \
1141 OMAP3_ISP_SBL_CCDC_WRITE | \
1142 OMAP3_ISP_SBL_PREVIEW_WRITE)
1214 !isp_pipeline_ready(pipe)))
1233 if (isp_pipeline_is_last(me)) {
1235 unsigned long flags;
1238 spin_unlock_irqrestore(&video->
queue->irqlock, flags);
1243 spin_unlock_irqrestore(&video->
queue->irqlock, flags);
1279 #define ISPCTRL_CLKS_MASK (ISPCTRL_H3A_CLK_EN | \
1280 ISPCTRL_HIST_CLK_EN | \
1281 ISPCTRL_RSZ_CLK_EN | \
1282 (ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN) | \
1283 (ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN))
1285 static void __isp_subclk_update(
struct isp_device *isp)
1310 ISPCTRL_CLKS_MASK, clk);
1318 __isp_subclk_update(isp);
1326 __isp_subclk_update(isp);
1335 static int isp_enable_clocks(
struct isp_device *isp)
1357 dev_err(isp->
dev,
"clk_enable cam_ick failed\n");
1358 goto out_clk_enable_ick;
1363 dev_err(isp->
dev,
"clk_set_rate for dpll4_m5_ck failed\n");
1364 goto out_clk_enable_mclk;
1368 dev_err(isp->
dev,
"clk_enable cam_mclk failed\n");
1369 goto out_clk_enable_mclk;
1378 dev_err(isp->
dev,
"clk_enable csi2_fck failed\n");
1379 goto out_clk_enable_csi2_fclk;
1383 out_clk_enable_csi2_fclk:
1385 out_clk_enable_mclk:
1395 static void isp_disable_clocks(
struct isp_device *isp)
1402 static const char *isp_clocks[] = {
1410 static void isp_put_clocks(
struct isp_device *isp)
1415 if (isp->
clock[i]) {
1422 static int isp_get_clocks(
struct isp_device *isp)
1430 dev_err(isp->
dev,
"clk_get %s failed\n", isp_clocks[i]);
1431 isp_put_clocks(isp);
1432 return PTR_ERR(clk);
1462 if (isp_enable_clocks(isp) < 0) {
1469 isp_restore_ctx(isp);
1472 isp_enable_interrupts(isp);
1484 return __omap3isp_get(isp,
true);
1501 isp_disable_interrupts(isp);
1511 isp_disable_clocks(isp);
1524 #define ISP_PRINT_REGISTER(isp, name)\
1525 dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
1526 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_##name))
1527 #define SBL_PRINT_REGISTER(isp, name)\
1528 dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
1529 isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_##name))
1533 dev_dbg(isp->
dev,
"-------------ISP Register dump--------------\n");
1535 ISP_PRINT_REGISTER(isp, SYSCONFIG);
1537 ISP_PRINT_REGISTER(isp, IRQ0ENABLE);
1538 ISP_PRINT_REGISTER(isp, IRQ0STATUS);
1539 ISP_PRINT_REGISTER(isp, TCTRL_GRESET_LENGTH);
1540 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_REPLAY);
1541 ISP_PRINT_REGISTER(isp,
CTRL);
1542 ISP_PRINT_REGISTER(isp, TCTRL_CTRL);
1543 ISP_PRINT_REGISTER(isp, TCTRL_FRAME);
1544 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_DELAY);
1545 ISP_PRINT_REGISTER(isp, TCTRL_STRB_DELAY);
1546 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_DELAY);
1547 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_LENGTH);
1548 ISP_PRINT_REGISTER(isp, TCTRL_STRB_LENGTH);
1549 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_LENGTH);
1551 SBL_PRINT_REGISTER(isp,
PCR);
1552 SBL_PRINT_REGISTER(isp, SDR_REQ_EXP);
1554 dev_dbg(isp->
dev,
"--------------------------------------------\n");
1576 static int isp_pm_prepare(
struct device *dev)
1586 reset = isp_suspend_modules(isp);
1587 isp_disable_interrupts(isp);
1595 static int isp_pm_suspend(
struct device *dev)
1602 isp_disable_clocks(isp);
1607 static int isp_pm_resume(
struct device *dev)
1614 return isp_enable_clocks(isp);
1617 static void isp_pm_complete(
struct device *dev)
1624 isp_restore_ctx(isp);
1625 isp_enable_interrupts(isp);
1626 isp_resume_modules(isp);
1631 #define isp_pm_prepare NULL
1632 #define isp_pm_suspend NULL
1633 #define isp_pm_resume NULL
1634 #define isp_pm_complete NULL
1638 static void isp_unregister_entities(
struct isp_device *isp)
1665 isp_register_subdev_group(
struct isp_device *isp,
1679 if (adapter ==
NULL) {
1681 "device %s\n", __func__,
1689 if (subdev ==
NULL) {
1702 static int isp_register_entities(
struct isp_device *isp)
1712 isp->
media_dev.link_notify = isp_pipeline_link_notify;
1763 for (subdevs = pdata->
subdevs; subdevs && subdevs->
subdevs; ++subdevs) {
1769 sensor = isp_register_subdev_group(isp, subdevs->
subdevs);
1782 input = &isp->
isp_ccdc.subdev.entity;
1796 input = &isp->
isp_ccp2.subdev.entity;
1825 isp_unregister_entities(isp);
1830 static void isp_cleanup_modules(
struct isp_device *isp)
1842 static int isp_initialize_modules(
struct isp_device *isp)
1848 dev_err(isp->
dev,
"CSI PHY initialization failed\n");
1854 dev_err(isp->
dev,
"CSI2 initialization failed\n");
1860 dev_err(isp->
dev,
"CCP2 initialization failed\n");
1866 dev_err(isp->
dev,
"CCDC initialization failed\n");
1872 dev_err(isp->
dev,
"Preview initialization failed\n");
1878 dev_err(isp->
dev,
"Resizer initialization failed\n");
1884 dev_err(isp->
dev,
"Histogram initialization failed\n");
1890 dev_err(isp->
dev,
"H3A AEWB initialization failed\n");
1891 goto error_h3a_aewb;
1896 dev_err(isp->
dev,
"H3A AF initialization failed\n");
1940 &isp->
isp_af.subdev.entity, 0,
1983 struct isp_device *isp = platform_get_drvdata(pdev);
1986 isp_unregister_entities(isp);
1987 isp_cleanup_modules(isp);
1989 __omap3isp_get(isp,
false);
1996 isp_put_clocks(isp);
2034 "cannot reserve camera register I/O region\n");
2044 dev_err(isp->
dev,
"cannot map camera register I/O region\n");
2074 dev_err(&pdev->
dev,
"could not allocate memory\n");
2092 platform_set_drvdata(pdev, isp);
2103 ret = isp_get_clocks(isp);
2107 if (__omap3isp_get(isp,
false) ==
NULL) {
2112 ret = isp_reset(isp);
2121 for (m = 0; m <
ARRAY_SIZE(isp_res_maps); m++)
2126 dev_err(isp->
dev,
"No resource map found for ISP rev %d.%d\n",
2133 if (isp_res_maps[m].
map & 1 << i) {
2134 ret = isp_map_mem_resource(pdev, isp, i);
2142 dev_err(isp->
dev,
"can't alloc iommu domain\n");
2149 dev_err(&pdev->
dev,
"can't attach iommu device: %d\n", ret);
2162 dev_err(isp->
dev,
"Unable to request IRQ\n");
2168 ret = isp_initialize_modules(isp);
2172 ret = isp_register_entities(isp);
2176 isp_core_init(isp, 1);
2182 isp_cleanup_modules(isp);
2192 isp_put_clocks(isp);
2208 platform_set_drvdata(pdev,
NULL);
2216 static const struct dev_pm_ops omap3isp_pm_ops = {
2217 .prepare = isp_pm_prepare,
2218 .suspend = isp_pm_suspend,
2219 .resume = isp_pm_resume,
2220 .complete = isp_pm_complete,
2232 .id_table = omap3isp_id_table,
2236 .pm = &omap3isp_pm_ops,