6 * Copyright (C) 2006-2010 Nokia Corporation
7 * Copyright (C) 2007-2009 Texas Instruments, Inc.
9 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10 * Sakari Ailus <sakari.ailus@iki.fi>
13 * Laurent Pinchart <laurent.pinchart@ideasonboard.com>
14 * Sakari Ailus <sakari.ailus@iki.fi>
15 * David Cohen <dacohen@gmail.com>
16 * Stanimir Varbanov <svarbanov@mm-sol.com>
17 * Vimarsh Zutshi <vimarsh.zutshi@gmail.com>
18 * Tuukka Toivonen <tuukkat76@gmail.com>
19 * Sergio Aguirre <saaguirre@ti.com>
20 * Antti Koskipaa <akoskipa@gmail.com>
21 * Ivan T. Ivanov <iivanov@mm-sol.com>
22 * RaniSuneela <r-m@ti.com>
23 * Atanas Filipov <afilipov@mm-sol.com>
24 * Gjorgji Rosikopulos <grosikopulos@mm-sol.com>
25 * Hiroshi DOYU <hiroshi.doyu@nokia.com>
26 * Nayden Kanchev <nkanchev@mm-sol.com>
27 * Phil Carmody <ext-phil.2.carmody@nokia.com>
28 * Artem Bityutskiy <artem.bityutskiy@nokia.com>
29 * Dominic Curran <dcurran@ti.com>
30 * Ilkka Myllyperkio <ilkka.myllyperkio@sofica.fi>
31 * Pallavi Kulkarni <p-kulkarni@ti.com>
32 * Vaibhav Hiremath <hvaibhav@ti.com>
33 * Mohit Jalori <mjalori@ti.com>
34 * Sameer Venkatraman <sameerv@ti.com>
35 * Senthilvadivu Guruswamy <svadivu@ti.com>
36 * Thara Gopinath <thara@ti.com>
37 * Toni Leinonen <toni.leinonen@nokia.com>
38 * Troy Laramy <t-laramy@ti.com>
40 * This program is free software; you can redistribute it and/or modify
41 * it under the terms of the GNU General Public License version 2 as
42 * published by the Free Software Foundation.
44 * This program is distributed in the hope that it will be useful, but
45 * WITHOUT ANY WARRANTY; without even the implied warranty of
46 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47 * General Public License for more details.
49 * You should have received a copy of the GNU General Public License
50 * along with this program; if not, write to the Free Software
51 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
55 #include <asm/cacheflush.h>
57 #include <linux/clk.h>
58 #include <linux/clkdev.h>
59 #include <linux/delay.h>
60 #include <linux/device.h>
61 #include <linux/dma-mapping.h>
62 #include <linux/i2c.h>
63 #include <linux/interrupt.h>
64 #include <linux/module.h>
65 #include <linux/omap-iommu.h>
66 #include <linux/platform_device.h>
67 #include <linux/regulator/consumer.h>
68 #include <linux/slab.h>
69 #include <linux/sched.h>
70 #include <linux/vmalloc.h>
72 #include <media/v4l2-common.h>
73 #include <media/v4l2-device.h>
78 #include "isppreview.h"
79 #include "ispresizer.h"
85 static unsigned int autoidle;
86 module_param(autoidle, int, 0444);
87 MODULE_PARM_DESC(autoidle, "Enable OMAP3ISP AUTOIDLE support");
89 static void isp_save_ctx(struct isp_device *isp);
91 static void isp_restore_ctx(struct isp_device *isp);
93 static const struct isp_res_mapping isp_res_maps[] = {
95 .isp_rev = ISP_REVISION_2_0,
96 .map = 1 << OMAP3_ISP_IOMEM_MAIN |
97 1 << OMAP3_ISP_IOMEM_CCP2 |
98 1 << OMAP3_ISP_IOMEM_CCDC |
99 1 << OMAP3_ISP_IOMEM_HIST |
100 1 << OMAP3_ISP_IOMEM_H3A |
101 1 << OMAP3_ISP_IOMEM_PREV |
102 1 << OMAP3_ISP_IOMEM_RESZ |
103 1 << OMAP3_ISP_IOMEM_SBL |
104 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1 |
105 1 << OMAP3_ISP_IOMEM_CSIPHY2 |
106 1 << OMAP3_ISP_IOMEM_343X_CONTROL_CSIRXFE,
109 .isp_rev = ISP_REVISION_15_0,
110 .map = 1 << OMAP3_ISP_IOMEM_MAIN |
111 1 << OMAP3_ISP_IOMEM_CCP2 |
112 1 << OMAP3_ISP_IOMEM_CCDC |
113 1 << OMAP3_ISP_IOMEM_HIST |
114 1 << OMAP3_ISP_IOMEM_H3A |
115 1 << OMAP3_ISP_IOMEM_PREV |
116 1 << OMAP3_ISP_IOMEM_RESZ |
117 1 << OMAP3_ISP_IOMEM_SBL |
118 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1 |
119 1 << OMAP3_ISP_IOMEM_CSIPHY2 |
120 1 << OMAP3_ISP_IOMEM_CSI2A_REGS2 |
121 1 << OMAP3_ISP_IOMEM_CSI2C_REGS1 |
122 1 << OMAP3_ISP_IOMEM_CSIPHY1 |
123 1 << OMAP3_ISP_IOMEM_CSI2C_REGS2 |
124 1 << OMAP3_ISP_IOMEM_3630_CONTROL_CAMERA_PHY_CTRL,
128 /* Structure for saving/restoring ISP module registers */
129 static struct isp_reg isp_reg_list[] = {
130 {OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG, 0},
131 {OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, 0},
132 {OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL, 0},
137 * omap3isp_flush - Post pending L3 bus writes by doing a register readback
138 * @isp: OMAP3 ISP device
140 * In order to force posting of pending writes, we need to write and
141 * readback the same register, in this case the revision register.
143 * See this link for reference:
144 * http://www.mail-archive.com/linux-omap@vger.kernel.org/msg08149.html
146 void omap3isp_flush(struct isp_device *isp)
148 isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
149 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
152 /* -----------------------------------------------------------------------------
156 #define to_isp_xclk(_hw) container_of(_hw, struct isp_xclk, hw)
158 static void isp_xclk_update(struct isp_xclk *xclk, u32 divider)
162 isp_reg_clr_set(xclk->isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
163 ISPTCTRL_CTRL_DIVA_MASK,
164 divider << ISPTCTRL_CTRL_DIVA_SHIFT);
167 isp_reg_clr_set(xclk->isp, OMAP3_ISP_IOMEM_MAIN, ISP_TCTRL_CTRL,
168 ISPTCTRL_CTRL_DIVB_MASK,
169 divider << ISPTCTRL_CTRL_DIVB_SHIFT);
174 static int isp_xclk_prepare(struct clk_hw *hw)
176 struct isp_xclk *xclk = to_isp_xclk(hw);
178 omap3isp_get(xclk->isp);
183 static void isp_xclk_unprepare(struct clk_hw *hw)
185 struct isp_xclk *xclk = to_isp_xclk(hw);
187 omap3isp_put(xclk->isp);
190 static int isp_xclk_enable(struct clk_hw *hw)
192 struct isp_xclk *xclk = to_isp_xclk(hw);
195 spin_lock_irqsave(&xclk->lock, flags);
196 isp_xclk_update(xclk, xclk->divider);
197 xclk->enabled = true;
198 spin_unlock_irqrestore(&xclk->lock, flags);
203 static void isp_xclk_disable(struct clk_hw *hw)
205 struct isp_xclk *xclk = to_isp_xclk(hw);
208 spin_lock_irqsave(&xclk->lock, flags);
209 isp_xclk_update(xclk, 0);
210 xclk->enabled = false;
211 spin_unlock_irqrestore(&xclk->lock, flags);
214 static unsigned long isp_xclk_recalc_rate(struct clk_hw *hw,
215 unsigned long parent_rate)
217 struct isp_xclk *xclk = to_isp_xclk(hw);
219 return parent_rate / xclk->divider;
222 static u32 isp_xclk_calc_divider(unsigned long *rate, unsigned long parent_rate)
226 if (*rate >= parent_rate) {
228 return ISPTCTRL_CTRL_DIV_BYPASS;
231 divider = DIV_ROUND_CLOSEST(parent_rate, *rate);
232 if (divider >= ISPTCTRL_CTRL_DIV_BYPASS)
233 divider = ISPTCTRL_CTRL_DIV_BYPASS - 1;
235 *rate = parent_rate / divider;
239 static long isp_xclk_round_rate(struct clk_hw *hw, unsigned long rate,
240 unsigned long *parent_rate)
242 isp_xclk_calc_divider(&rate, *parent_rate);
246 static int isp_xclk_set_rate(struct clk_hw *hw, unsigned long rate,
247 unsigned long parent_rate)
249 struct isp_xclk *xclk = to_isp_xclk(hw);
253 divider = isp_xclk_calc_divider(&rate, parent_rate);
255 spin_lock_irqsave(&xclk->lock, flags);
257 xclk->divider = divider;
259 isp_xclk_update(xclk, divider);
261 spin_unlock_irqrestore(&xclk->lock, flags);
263 dev_dbg(xclk->isp->dev, "%s: cam_xclk%c set to %lu Hz (div %u)\n",
264 __func__, xclk->id == ISP_XCLK_A ? 'a' : 'b', rate, divider);
268 static const struct clk_ops isp_xclk_ops = {
269 .prepare = isp_xclk_prepare,
270 .unprepare = isp_xclk_unprepare,
271 .enable = isp_xclk_enable,
272 .disable = isp_xclk_disable,
273 .recalc_rate = isp_xclk_recalc_rate,
274 .round_rate = isp_xclk_round_rate,
275 .set_rate = isp_xclk_set_rate,
278 static const char *isp_xclk_parent_name = "cam_mclk";
280 static const struct clk_init_data isp_xclk_init_data = {
282 .ops = &isp_xclk_ops,
283 .parent_names = &isp_xclk_parent_name,
287 static int isp_xclk_init(struct isp_device *isp)
289 struct isp_platform_data *pdata = isp->pdata;
290 struct clk_init_data init;
293 for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) {
294 struct isp_xclk *xclk = &isp->xclks[i];
298 xclk->id = i == 0 ? ISP_XCLK_A : ISP_XCLK_B;
300 spin_lock_init(&xclk->lock);
302 init.name = i == 0 ? "cam_xclka" : "cam_xclkb";
303 init.ops = &isp_xclk_ops;
304 init.parent_names = &isp_xclk_parent_name;
305 init.num_parents = 1;
307 xclk->hw.init = &init;
309 clk = devm_clk_register(isp->dev, &xclk->hw);
313 if (pdata->xclks[i].con_id == NULL &&
314 pdata->xclks[i].dev_id == NULL)
317 xclk->lookup = kzalloc(sizeof(*xclk->lookup), GFP_KERNEL);
318 if (xclk->lookup == NULL)
321 xclk->lookup->con_id = pdata->xclks[i].con_id;
322 xclk->lookup->dev_id = pdata->xclks[i].dev_id;
323 xclk->lookup->clk = clk;
325 clkdev_add(xclk->lookup);
331 static void isp_xclk_cleanup(struct isp_device *isp)
335 for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) {
336 struct isp_xclk *xclk = &isp->xclks[i];
339 clkdev_drop(xclk->lookup);
343 /* -----------------------------------------------------------------------------
348 * isp_enable_interrupts - Enable ISP interrupts.
349 * @isp: OMAP3 ISP device
351 static void isp_enable_interrupts(struct isp_device *isp)
353 static const u32 irq = IRQ0ENABLE_CSIA_IRQ
354 | IRQ0ENABLE_CSIB_IRQ
355 | IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ
356 | IRQ0ENABLE_CCDC_LSC_DONE_IRQ
357 | IRQ0ENABLE_CCDC_VD0_IRQ
358 | IRQ0ENABLE_CCDC_VD1_IRQ
359 | IRQ0ENABLE_HS_VS_IRQ
360 | IRQ0ENABLE_HIST_DONE_IRQ
361 | IRQ0ENABLE_H3A_AWB_DONE_IRQ
362 | IRQ0ENABLE_H3A_AF_DONE_IRQ
363 | IRQ0ENABLE_PRV_DONE_IRQ
364 | IRQ0ENABLE_RSZ_DONE_IRQ;
366 isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
367 isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
371 * isp_disable_interrupts - Disable ISP interrupts.
372 * @isp: OMAP3 ISP device
374 static void isp_disable_interrupts(struct isp_device *isp)
376 isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
380 * isp_core_init - ISP core settings
381 * @isp: OMAP3 ISP device
382 * @idle: Consider idle state.
384 * Set the power settings for the ISP and SBL bus and cConfigure the HS/VS
387 * We need to configure the HS/VS interrupt source before interrupts get
388 * enabled, as the sensor might be free-running and the ISP default setting
389 * (HS edge) would put an unnecessary burden on the CPU.
391 static void isp_core_init(struct isp_device *isp, int idle)
394 ((idle ? ISP_SYSCONFIG_MIDLEMODE_SMARTSTANDBY :
395 ISP_SYSCONFIG_MIDLEMODE_FORCESTANDBY) <<
396 ISP_SYSCONFIG_MIDLEMODE_SHIFT) |
397 ((isp->revision == ISP_REVISION_15_0) ?
398 ISP_SYSCONFIG_AUTOIDLE : 0),
399 OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
402 (isp->autoidle ? ISPCTRL_SBL_AUTOIDLE : 0) |
403 ISPCTRL_SYNC_DETECT_VSRISE,
404 OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
408 * Configure the bridge and lane shifter. Valid inputs are
410 * CCDC_INPUT_PARALLEL: Parallel interface
411 * CCDC_INPUT_CSI2A: CSI2a receiver
412 * CCDC_INPUT_CCP2B: CCP2b receiver
413 * CCDC_INPUT_CSI2C: CSI2c receiver
415 * The bridge and lane shifter are configured according to the selected input
416 * and the ISP platform data.
418 void omap3isp_configure_bridge(struct isp_device *isp,
419 enum ccdc_input_entity input,
420 const struct isp_parallel_platform_data *pdata,
421 unsigned int shift, unsigned int bridge)
425 ispctrl_val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
426 ispctrl_val &= ~ISPCTRL_SHIFT_MASK;
427 ispctrl_val &= ~ISPCTRL_PAR_CLK_POL_INV;
428 ispctrl_val &= ~ISPCTRL_PAR_SER_CLK_SEL_MASK;
429 ispctrl_val &= ~ISPCTRL_PAR_BRIDGE_MASK;
430 ispctrl_val |= bridge;
433 case CCDC_INPUT_PARALLEL:
434 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_PARALLEL;
435 ispctrl_val |= pdata->clk_pol << ISPCTRL_PAR_CLK_POL_SHIFT;
436 shift += pdata->data_lane_shift * 2;
439 case CCDC_INPUT_CSI2A:
440 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIA;
443 case CCDC_INPUT_CCP2B:
444 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIB;
447 case CCDC_INPUT_CSI2C:
448 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIC;
455 ispctrl_val |= ((shift/2) << ISPCTRL_SHIFT_SHIFT) & ISPCTRL_SHIFT_MASK;
457 isp_reg_writel(isp, ispctrl_val, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
460 void omap3isp_hist_dma_done(struct isp_device *isp)
462 if (omap3isp_ccdc_busy(&isp->isp_ccdc) ||
463 omap3isp_stat_pcr_busy(&isp->isp_hist)) {
464 /* Histogram cannot be enabled in this frame anymore */
465 atomic_set(&isp->isp_hist.buf_err, 1);
466 dev_dbg(isp->dev, "hist: Out of synchronization with "
467 "CCDC. Ignoring next buffer.\n");
471 static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
473 static const char *name[] = {
492 "CCDC_LSC_PREFETCH_COMPLETED",
493 "CCDC_LSC_PREFETCH_ERROR",
509 dev_dbg(isp->dev, "ISP IRQ: ");
511 for (i = 0; i < ARRAY_SIZE(name); i++) {
512 if ((1 << i) & irqstatus)
513 printk(KERN_CONT "%s ", name[i]);
515 printk(KERN_CONT "\n");
518 static void isp_isr_sbl(struct isp_device *isp)
520 struct device *dev = isp->dev;
521 struct isp_pipeline *pipe;
525 * Handle shared buffer logic overflows for video buffers.
526 * ISPSBL_PCR_CCDCPRV_2_RSZ_OVF can be safely ignored.
528 sbl_pcr = isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
529 isp_reg_writel(isp, sbl_pcr, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
530 sbl_pcr &= ~ISPSBL_PCR_CCDCPRV_2_RSZ_OVF;
533 dev_dbg(dev, "SBL overflow (PCR = 0x%08x)\n", sbl_pcr);
535 if (sbl_pcr & ISPSBL_PCR_CSIB_WBL_OVF) {
536 pipe = to_isp_pipeline(&isp->isp_ccp2.subdev.entity);
541 if (sbl_pcr & ISPSBL_PCR_CSIA_WBL_OVF) {
542 pipe = to_isp_pipeline(&isp->isp_csi2a.subdev.entity);
547 if (sbl_pcr & ISPSBL_PCR_CCDC_WBL_OVF) {
548 pipe = to_isp_pipeline(&isp->isp_ccdc.subdev.entity);
553 if (sbl_pcr & ISPSBL_PCR_PRV_WBL_OVF) {
554 pipe = to_isp_pipeline(&isp->isp_prev.subdev.entity);
559 if (sbl_pcr & (ISPSBL_PCR_RSZ1_WBL_OVF
560 | ISPSBL_PCR_RSZ2_WBL_OVF
561 | ISPSBL_PCR_RSZ3_WBL_OVF
562 | ISPSBL_PCR_RSZ4_WBL_OVF)) {
563 pipe = to_isp_pipeline(&isp->isp_res.subdev.entity);
568 if (sbl_pcr & ISPSBL_PCR_H3A_AF_WBL_OVF)
569 omap3isp_stat_sbl_overflow(&isp->isp_af);
571 if (sbl_pcr & ISPSBL_PCR_H3A_AEAWB_WBL_OVF)
572 omap3isp_stat_sbl_overflow(&isp->isp_aewb);
576 * isp_isr - Interrupt Service Routine for Camera ISP module.
577 * @irq: Not used currently.
578 * @_isp: Pointer to the OMAP3 ISP device
580 * Handles the corresponding callback if plugged in.
582 * Returns IRQ_HANDLED when IRQ was correctly handled, or IRQ_NONE when the
583 * IRQ wasn't handled.
585 static irqreturn_t isp_isr(int irq, void *_isp)
587 static const u32 ccdc_events = IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ |
588 IRQ0STATUS_CCDC_LSC_DONE_IRQ |
589 IRQ0STATUS_CCDC_VD0_IRQ |
590 IRQ0STATUS_CCDC_VD1_IRQ |
591 IRQ0STATUS_HS_VS_IRQ;
592 struct isp_device *isp = _isp;
595 irqstatus = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
596 isp_reg_writel(isp, irqstatus, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
600 if (irqstatus & IRQ0STATUS_CSIA_IRQ)
601 omap3isp_csi2_isr(&isp->isp_csi2a);
603 if (irqstatus & IRQ0STATUS_CSIB_IRQ)
604 omap3isp_ccp2_isr(&isp->isp_ccp2);
606 if (irqstatus & IRQ0STATUS_CCDC_VD0_IRQ) {
607 if (isp->isp_ccdc.output & CCDC_OUTPUT_PREVIEW)
608 omap3isp_preview_isr_frame_sync(&isp->isp_prev);
609 if (isp->isp_ccdc.output & CCDC_OUTPUT_RESIZER)
610 omap3isp_resizer_isr_frame_sync(&isp->isp_res);
611 omap3isp_stat_isr_frame_sync(&isp->isp_aewb);
612 omap3isp_stat_isr_frame_sync(&isp->isp_af);
613 omap3isp_stat_isr_frame_sync(&isp->isp_hist);
616 if (irqstatus & ccdc_events)
617 omap3isp_ccdc_isr(&isp->isp_ccdc, irqstatus & ccdc_events);
619 if (irqstatus & IRQ0STATUS_PRV_DONE_IRQ) {
620 if (isp->isp_prev.output & PREVIEW_OUTPUT_RESIZER)
621 omap3isp_resizer_isr_frame_sync(&isp->isp_res);
622 omap3isp_preview_isr(&isp->isp_prev);
625 if (irqstatus & IRQ0STATUS_RSZ_DONE_IRQ)
626 omap3isp_resizer_isr(&isp->isp_res);
628 if (irqstatus & IRQ0STATUS_H3A_AWB_DONE_IRQ)
629 omap3isp_stat_isr(&isp->isp_aewb);
631 if (irqstatus & IRQ0STATUS_H3A_AF_DONE_IRQ)
632 omap3isp_stat_isr(&isp->isp_af);
634 if (irqstatus & IRQ0STATUS_HIST_DONE_IRQ)
635 omap3isp_stat_isr(&isp->isp_hist);
639 #if defined(DEBUG) && defined(ISP_ISR_DEBUG)
640 isp_isr_dbg(isp, irqstatus);
646 /* -----------------------------------------------------------------------------
647 * Pipeline power management
649 * Entities must be powered up when part of a pipeline that contains at least
650 * one open video device node.
652 * To achieve this use the entity use_count field to track the number of users.
653 * For entities corresponding to video device nodes the use_count field stores
654 * the users count of the node. For entities corresponding to subdevs the
655 * use_count field stores the total number of users of all video device nodes
658 * The omap3isp_pipeline_pm_use() function must be called in the open() and
659 * close() handlers of video device nodes. It increments or decrements the use
660 * count of all subdev entities in the pipeline.
662 * To react to link management on powered pipelines, the link setup notification
663 * callback updates the use count of all entities in the source and sink sides
668 * isp_pipeline_pm_use_count - Count the number of users of a pipeline
669 * @entity: The entity
671 * Return the total number of users of all video device nodes in the pipeline.
673 static int isp_pipeline_pm_use_count(struct media_entity *entity)
675 struct media_entity_graph graph;
678 media_entity_graph_walk_start(&graph, entity);
680 while ((entity = media_entity_graph_walk_next(&graph))) {
681 if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
682 use += entity->use_count;
689 * isp_pipeline_pm_power_one - Apply power change to an entity
690 * @entity: The entity
691 * @change: Use count change
693 * Change the entity use count by @change. If the entity is a subdev update its
694 * power state by calling the core::s_power operation when the use count goes
695 * from 0 to != 0 or from != 0 to 0.
697 * Return 0 on success or a negative error code on failure.
699 static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
701 struct v4l2_subdev *subdev;
704 subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
705 ? media_entity_to_v4l2_subdev(entity) : NULL;
707 if (entity->use_count == 0 && change > 0 && subdev != NULL) {
708 ret = v4l2_subdev_call(subdev, core, s_power, 1);
709 if (ret < 0 && ret != -ENOIOCTLCMD)
713 entity->use_count += change;
714 WARN_ON(entity->use_count < 0);
716 if (entity->use_count == 0 && change < 0 && subdev != NULL)
717 v4l2_subdev_call(subdev, core, s_power, 0);
723 * isp_pipeline_pm_power - Apply power change to all entities in a pipeline
724 * @entity: The entity
725 * @change: Use count change
727 * Walk the pipeline to update the use count and the power state of all non-node
730 * Return 0 on success or a negative error code on failure.
732 static int isp_pipeline_pm_power(struct media_entity *entity, int change)
734 struct media_entity_graph graph;
735 struct media_entity *first = entity;
741 media_entity_graph_walk_start(&graph, entity);
743 while (!ret && (entity = media_entity_graph_walk_next(&graph)))
744 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
745 ret = isp_pipeline_pm_power_one(entity, change);
750 media_entity_graph_walk_start(&graph, first);
752 while ((first = media_entity_graph_walk_next(&graph))
754 if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
755 isp_pipeline_pm_power_one(first, -change);
761 * omap3isp_pipeline_pm_use - Update the use count of an entity
762 * @entity: The entity
763 * @use: Use (1) or stop using (0) the entity
765 * Update the use count of all entities in the pipeline and power entities on or
768 * Return 0 on success or a negative error code on failure. Powering entities
769 * off is assumed to never fail. No failure can occur when the use parameter is
772 int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
774 int change = use ? 1 : -1;
777 mutex_lock(&entity->parent->graph_mutex);
779 /* Apply use count to node. */
780 entity->use_count += change;
781 WARN_ON(entity->use_count < 0);
783 /* Apply power change to connected non-nodes. */
784 ret = isp_pipeline_pm_power(entity, change);
786 entity->use_count -= change;
788 mutex_unlock(&entity->parent->graph_mutex);
794 * isp_pipeline_link_notify - Link management notification callback
796 * @flags: New link flags that will be applied
797 * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
799 * React to link management on powered pipelines by updating the use count of
800 * all entities in the source and sink sides of the link. Entities are powered
801 * on or off accordingly.
803 * Return 0 on success or a negative error code on failure. Powering entities
804 * off is assumed to never fail. This function will not fail for disconnection
807 static int isp_pipeline_link_notify(struct media_link *link, u32 flags,
808 unsigned int notification)
810 struct media_entity *source = link->source->entity;
811 struct media_entity *sink = link->sink->entity;
812 int source_use = isp_pipeline_pm_use_count(source);
813 int sink_use = isp_pipeline_pm_use_count(sink);
816 if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
817 !(link->flags & MEDIA_LNK_FL_ENABLED)) {
818 /* Powering off entities is assumed to never fail. */
819 isp_pipeline_pm_power(source, -sink_use);
820 isp_pipeline_pm_power(sink, -source_use);
824 if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
825 (flags & MEDIA_LNK_FL_ENABLED)) {
827 ret = isp_pipeline_pm_power(source, sink_use);
831 ret = isp_pipeline_pm_power(sink, source_use);
833 isp_pipeline_pm_power(source, -sink_use);
841 /* -----------------------------------------------------------------------------
842 * Pipeline stream management
846 * isp_pipeline_enable - Enable streaming on a pipeline
847 * @pipe: ISP pipeline
848 * @mode: Stream mode (single shot or continuous)
850 * Walk the entities chain starting at the pipeline output video node and start
851 * all modules in the chain in the given mode.
853 * Return 0 if successful, or the return value of the failed video::s_stream
854 * operation otherwise.
856 static int isp_pipeline_enable(struct isp_pipeline *pipe,
857 enum isp_pipeline_stream_state mode)
859 struct isp_device *isp = pipe->output->isp;
860 struct media_entity *entity;
861 struct media_pad *pad;
862 struct v4l2_subdev *subdev;
866 /* If the preview engine crashed it might not respond to read/write
867 * operations on the L4 bus. This would result in a bus fault and a
868 * kernel oops. Refuse to start streaming in that case. This check must
869 * be performed before the loop below to avoid starting entities if the
870 * pipeline won't start anyway (those entities would then likely fail to
871 * stop, making the problem worse).
873 if ((pipe->entities & isp->crashed) &
874 (1U << isp->isp_prev.subdev.entity.id))
877 spin_lock_irqsave(&pipe->lock, flags);
878 pipe->state &= ~(ISP_PIPELINE_IDLE_INPUT | ISP_PIPELINE_IDLE_OUTPUT);
879 spin_unlock_irqrestore(&pipe->lock, flags);
881 pipe->do_propagation = false;
883 entity = &pipe->output->video.entity;
885 pad = &entity->pads[0];
886 if (!(pad->flags & MEDIA_PAD_FL_SINK))
889 pad = media_entity_remote_pad(pad);
891 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
894 entity = pad->entity;
895 subdev = media_entity_to_v4l2_subdev(entity);
897 ret = v4l2_subdev_call(subdev, video, s_stream, mode);
898 if (ret < 0 && ret != -ENOIOCTLCMD)
901 if (subdev == &isp->isp_ccdc.subdev) {
902 v4l2_subdev_call(&isp->isp_aewb.subdev, video,
904 v4l2_subdev_call(&isp->isp_af.subdev, video,
906 v4l2_subdev_call(&isp->isp_hist.subdev, video,
908 pipe->do_propagation = true;
915 static int isp_pipeline_wait_resizer(struct isp_device *isp)
917 return omap3isp_resizer_busy(&isp->isp_res);
920 static int isp_pipeline_wait_preview(struct isp_device *isp)
922 return omap3isp_preview_busy(&isp->isp_prev);
925 static int isp_pipeline_wait_ccdc(struct isp_device *isp)
927 return omap3isp_stat_busy(&isp->isp_af)
928 || omap3isp_stat_busy(&isp->isp_aewb)
929 || omap3isp_stat_busy(&isp->isp_hist)
930 || omap3isp_ccdc_busy(&isp->isp_ccdc);
933 #define ISP_STOP_TIMEOUT msecs_to_jiffies(1000)
935 static int isp_pipeline_wait(struct isp_device *isp,
936 int(*busy)(struct isp_device *isp))
938 unsigned long timeout = jiffies + ISP_STOP_TIMEOUT;
940 while (!time_after(jiffies, timeout)) {
949 * isp_pipeline_disable - Disable streaming on a pipeline
950 * @pipe: ISP pipeline
952 * Walk the entities chain starting at the pipeline output video node and stop
953 * all modules in the chain. Wait synchronously for the modules to be stopped if
956 * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
957 * can't be stopped (in which case a software reset of the ISP is probably
960 static int isp_pipeline_disable(struct isp_pipeline *pipe)
962 struct isp_device *isp = pipe->output->isp;
963 struct media_entity *entity;
964 struct media_pad *pad;
965 struct v4l2_subdev *subdev;
970 * We need to stop all the modules after CCDC first or they'll
971 * never stop since they may not get a full frame from CCDC.
973 entity = &pipe->output->video.entity;
975 pad = &entity->pads[0];
976 if (!(pad->flags & MEDIA_PAD_FL_SINK))
979 pad = media_entity_remote_pad(pad);
981 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
984 entity = pad->entity;
985 subdev = media_entity_to_v4l2_subdev(entity);
987 if (subdev == &isp->isp_ccdc.subdev) {
988 v4l2_subdev_call(&isp->isp_aewb.subdev,
990 v4l2_subdev_call(&isp->isp_af.subdev,
992 v4l2_subdev_call(&isp->isp_hist.subdev,
996 v4l2_subdev_call(subdev, video, s_stream, 0);
998 if (subdev == &isp->isp_res.subdev)
999 ret = isp_pipeline_wait(isp, isp_pipeline_wait_resizer);
1000 else if (subdev == &isp->isp_prev.subdev)
1001 ret = isp_pipeline_wait(isp, isp_pipeline_wait_preview);
1002 else if (subdev == &isp->isp_ccdc.subdev)
1003 ret = isp_pipeline_wait(isp, isp_pipeline_wait_ccdc);
1008 dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
1009 /* If the entity failed to stopped, assume it has
1010 * crashed. Mark it as such, the ISP will be reset when
1011 * applications will release it.
1013 isp->crashed |= 1U << subdev->entity.id;
1014 failure = -ETIMEDOUT;
1022 * omap3isp_pipeline_set_stream - Enable/disable streaming on a pipeline
1023 * @pipe: ISP pipeline
1024 * @state: Stream state (stopped, single shot or continuous)
1026 * Set the pipeline to the given stream state. Pipelines can be started in
1027 * single-shot or continuous mode.
1029 * Return 0 if successful, or the return value of the failed video::s_stream
1030 * operation otherwise. The pipeline state is not updated when the operation
1031 * fails, except when stopping the pipeline.
1033 int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
1034 enum isp_pipeline_stream_state state)
1038 if (state == ISP_PIPELINE_STREAM_STOPPED)
1039 ret = isp_pipeline_disable(pipe);
1041 ret = isp_pipeline_enable(pipe, state);
1043 if (ret == 0 || state == ISP_PIPELINE_STREAM_STOPPED)
1044 pipe->stream_state = state;
1050 * isp_pipeline_resume - Resume streaming on a pipeline
1051 * @pipe: ISP pipeline
1053 * Resume video output and input and re-enable pipeline.
1055 static void isp_pipeline_resume(struct isp_pipeline *pipe)
1057 int singleshot = pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT;
1059 omap3isp_video_resume(pipe->output, !singleshot);
1061 omap3isp_video_resume(pipe->input, 0);
1062 isp_pipeline_enable(pipe, pipe->stream_state);
1066 * isp_pipeline_suspend - Suspend streaming on a pipeline
1067 * @pipe: ISP pipeline
1071 static void isp_pipeline_suspend(struct isp_pipeline *pipe)
1073 isp_pipeline_disable(pipe);
1077 * isp_pipeline_is_last - Verify if entity has an enabled link to the output
1079 * @me: ISP module's media entity
1081 * Returns 1 if the entity has an enabled link to the output video node or 0
1082 * otherwise. It's true only while pipeline can have no more than one output
1085 static int isp_pipeline_is_last(struct media_entity *me)
1087 struct isp_pipeline *pipe;
1088 struct media_pad *pad;
1092 pipe = to_isp_pipeline(me);
1093 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
1095 pad = media_entity_remote_pad(&pipe->output->pad);
1096 return pad->entity == me;
1100 * isp_suspend_module_pipeline - Suspend pipeline to which belongs the module
1101 * @me: ISP module's media entity
1103 * Suspend the whole pipeline if module's entity has an enabled link to the
1104 * output video node. It works only while pipeline can have no more than one
1107 static void isp_suspend_module_pipeline(struct media_entity *me)
1109 if (isp_pipeline_is_last(me))
1110 isp_pipeline_suspend(to_isp_pipeline(me));
1114 * isp_resume_module_pipeline - Resume pipeline to which belongs the module
1115 * @me: ISP module's media entity
1117 * Resume the whole pipeline if module's entity has an enabled link to the
1118 * output video node. It works only while pipeline can have no more than one
1121 static void isp_resume_module_pipeline(struct media_entity *me)
1123 if (isp_pipeline_is_last(me))
1124 isp_pipeline_resume(to_isp_pipeline(me));
1128 * isp_suspend_modules - Suspend ISP submodules.
1129 * @isp: OMAP3 ISP device
1131 * Returns 0 if suspend left in idle state all the submodules properly,
1132 * or returns 1 if a general Reset is required to suspend the submodules.
1134 static int isp_suspend_modules(struct isp_device *isp)
1136 unsigned long timeout;
1138 omap3isp_stat_suspend(&isp->isp_aewb);
1139 omap3isp_stat_suspend(&isp->isp_af);
1140 omap3isp_stat_suspend(&isp->isp_hist);
1141 isp_suspend_module_pipeline(&isp->isp_res.subdev.entity);
1142 isp_suspend_module_pipeline(&isp->isp_prev.subdev.entity);
1143 isp_suspend_module_pipeline(&isp->isp_ccdc.subdev.entity);
1144 isp_suspend_module_pipeline(&isp->isp_csi2a.subdev.entity);
1145 isp_suspend_module_pipeline(&isp->isp_ccp2.subdev.entity);
1147 timeout = jiffies + ISP_STOP_TIMEOUT;
1148 while (omap3isp_stat_busy(&isp->isp_af)
1149 || omap3isp_stat_busy(&isp->isp_aewb)
1150 || omap3isp_stat_busy(&isp->isp_hist)
1151 || omap3isp_preview_busy(&isp->isp_prev)
1152 || omap3isp_resizer_busy(&isp->isp_res)
1153 || omap3isp_ccdc_busy(&isp->isp_ccdc)) {
1154 if (time_after(jiffies, timeout)) {
1155 dev_info(isp->dev, "can't stop modules.\n");
1165 * isp_resume_modules - Resume ISP submodules.
1166 * @isp: OMAP3 ISP device
1168 static void isp_resume_modules(struct isp_device *isp)
1170 omap3isp_stat_resume(&isp->isp_aewb);
1171 omap3isp_stat_resume(&isp->isp_af);
1172 omap3isp_stat_resume(&isp->isp_hist);
1173 isp_resume_module_pipeline(&isp->isp_res.subdev.entity);
1174 isp_resume_module_pipeline(&isp->isp_prev.subdev.entity);
1175 isp_resume_module_pipeline(&isp->isp_ccdc.subdev.entity);
1176 isp_resume_module_pipeline(&isp->isp_csi2a.subdev.entity);
1177 isp_resume_module_pipeline(&isp->isp_ccp2.subdev.entity);
1181 * isp_reset - Reset ISP with a timeout wait for idle.
1182 * @isp: OMAP3 ISP device
1184 static int isp_reset(struct isp_device *isp)
1186 unsigned long timeout = 0;
1189 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG)
1190 | ISP_SYSCONFIG_SOFTRESET,
1191 OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
1192 while (!(isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN,
1193 ISP_SYSSTATUS) & 0x1)) {
1194 if (timeout++ > 10000) {
1195 dev_alert(isp->dev, "cannot reset ISP\n");
1206 * isp_save_context - Saves the values of the ISP module registers.
1207 * @isp: OMAP3 ISP device
1208 * @reg_list: Structure containing pairs of register address and value to
1212 isp_save_context(struct isp_device *isp, struct isp_reg *reg_list)
1214 struct isp_reg *next = reg_list;
1216 for (; next->reg != ISP_TOK_TERM; next++)
1217 next->val = isp_reg_readl(isp, next->mmio_range, next->reg);
1221 * isp_restore_context - Restores the values of the ISP module registers.
1222 * @isp: OMAP3 ISP device
1223 * @reg_list: Structure containing pairs of register address and value to
1227 isp_restore_context(struct isp_device *isp, struct isp_reg *reg_list)
1229 struct isp_reg *next = reg_list;
1231 for (; next->reg != ISP_TOK_TERM; next++)
1232 isp_reg_writel(isp, next->val, next->mmio_range, next->reg);
1236 * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1237 * @isp: OMAP3 ISP device
1239 * Routine for saving the context of each module in the ISP.
1240 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1242 static void isp_save_ctx(struct isp_device *isp)
1244 isp_save_context(isp, isp_reg_list);
1245 omap_iommu_save_ctx(isp->dev);
1249 * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1250 * @isp: OMAP3 ISP device
1252 * Routine for restoring the context of each module in the ISP.
1253 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1255 static void isp_restore_ctx(struct isp_device *isp)
1257 isp_restore_context(isp, isp_reg_list);
1258 omap_iommu_restore_ctx(isp->dev);
1259 omap3isp_ccdc_restore_context(isp);
1260 omap3isp_preview_restore_context(isp);
1263 /* -----------------------------------------------------------------------------
1264 * SBL resources management
1266 #define OMAP3_ISP_SBL_READ (OMAP3_ISP_SBL_CSI1_READ | \
1267 OMAP3_ISP_SBL_CCDC_LSC_READ | \
1268 OMAP3_ISP_SBL_PREVIEW_READ | \
1269 OMAP3_ISP_SBL_RESIZER_READ)
1270 #define OMAP3_ISP_SBL_WRITE (OMAP3_ISP_SBL_CSI1_WRITE | \
1271 OMAP3_ISP_SBL_CSI2A_WRITE | \
1272 OMAP3_ISP_SBL_CSI2C_WRITE | \
1273 OMAP3_ISP_SBL_CCDC_WRITE | \
1274 OMAP3_ISP_SBL_PREVIEW_WRITE)
1276 void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res)
1280 isp->sbl_resources |= res;
1282 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ)
1283 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1285 if (isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ)
1286 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1288 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE)
1289 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1291 if (isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE)
1292 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1294 if (isp->sbl_resources & OMAP3_ISP_SBL_WRITE)
1295 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1297 if (isp->sbl_resources & OMAP3_ISP_SBL_READ)
1298 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1300 isp_reg_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1303 void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res)
1307 isp->sbl_resources &= ~res;
1309 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ))
1310 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1312 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ))
1313 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1315 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE))
1316 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1318 if (!(isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE))
1319 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1321 if (!(isp->sbl_resources & OMAP3_ISP_SBL_WRITE))
1322 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1324 if (!(isp->sbl_resources & OMAP3_ISP_SBL_READ))
1325 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1327 isp_reg_clr(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1331 * isp_module_sync_idle - Helper to sync module with its idle state
1332 * @me: ISP submodule's media entity
1333 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1334 * @stopping: flag which tells module wants to stop
1336 * This function checks if ISP submodule needs to wait for next interrupt. If
1337 * yes, makes the caller to sleep while waiting for such event.
1339 int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
1342 struct isp_pipeline *pipe = to_isp_pipeline(me);
1344 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED ||
1345 (pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT &&
1346 !isp_pipeline_ready(pipe)))
1350 * atomic_set() doesn't include memory barrier on ARM platform for SMP
1351 * scenario. We'll call it here to avoid race conditions.
1353 atomic_set(stopping, 1);
1357 * If module is the last one, it's writing to memory. In this case,
1358 * it's necessary to check if the module is already paused due to
1359 * DMA queue underrun or if it has to wait for next interrupt to be
1361 * If it isn't the last one, the function won't sleep but *stopping
1362 * will still be set to warn next submodule caller's interrupt the
1363 * module wants to be idle.
1365 if (isp_pipeline_is_last(me)) {
1366 struct isp_video *video = pipe->output;
1367 unsigned long flags;
1368 spin_lock_irqsave(&video->queue->irqlock, flags);
1369 if (video->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_UNDERRUN) {
1370 spin_unlock_irqrestore(&video->queue->irqlock, flags);
1371 atomic_set(stopping, 0);
1375 spin_unlock_irqrestore(&video->queue->irqlock, flags);
1376 if (!wait_event_timeout(*wait, !atomic_read(stopping),
1377 msecs_to_jiffies(1000))) {
1378 atomic_set(stopping, 0);
1388 * omap3isp_module_sync_is_stopped - Helper to verify if module was stopping
1389 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1390 * @stopping: flag which tells module wants to stop
1392 * This function checks if ISP submodule was stopping. In case of yes, it
1393 * notices the caller by setting stopping to 0 and waking up the wait queue.
1394 * Returns 1 if it was stopping or 0 otherwise.
1396 int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
1399 if (atomic_cmpxchg(stopping, 1, 0)) {
1407 /* --------------------------------------------------------------------------
1411 #define ISPCTRL_CLKS_MASK (ISPCTRL_H3A_CLK_EN | \
1412 ISPCTRL_HIST_CLK_EN | \
1413 ISPCTRL_RSZ_CLK_EN | \
1414 (ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN) | \
1415 (ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN))
1417 static void __isp_subclk_update(struct isp_device *isp)
1421 /* AEWB and AF share the same clock. */
1422 if (isp->subclk_resources &
1423 (OMAP3_ISP_SUBCLK_AEWB | OMAP3_ISP_SUBCLK_AF))
1424 clk |= ISPCTRL_H3A_CLK_EN;
1426 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_HIST)
1427 clk |= ISPCTRL_HIST_CLK_EN;
1429 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_RESIZER)
1430 clk |= ISPCTRL_RSZ_CLK_EN;
1432 /* NOTE: For CCDC & Preview submodules, we need to affect internal
1435 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_CCDC)
1436 clk |= ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN;
1438 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_PREVIEW)
1439 clk |= ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN;
1441 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL,
1442 ISPCTRL_CLKS_MASK, clk);
1445 void omap3isp_subclk_enable(struct isp_device *isp,
1446 enum isp_subclk_resource res)
1448 isp->subclk_resources |= res;
1450 __isp_subclk_update(isp);
1453 void omap3isp_subclk_disable(struct isp_device *isp,
1454 enum isp_subclk_resource res)
1456 isp->subclk_resources &= ~res;
1458 __isp_subclk_update(isp);
1462 * isp_enable_clocks - Enable ISP clocks
1463 * @isp: OMAP3 ISP device
1465 * Return 0 if successful, or clk_prepare_enable return value if any of them
1468 static int isp_enable_clocks(struct isp_device *isp)
1473 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_ICK]);
1475 dev_err(isp->dev, "failed to enable cam_ick clock\n");
1476 goto out_clk_enable_ick;
1478 r = clk_set_rate(isp->clock[ISP_CLK_CAM_MCLK], CM_CAM_MCLK_HZ);
1480 dev_err(isp->dev, "clk_set_rate for cam_mclk failed\n");
1481 goto out_clk_enable_mclk;
1483 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_MCLK]);
1485 dev_err(isp->dev, "failed to enable cam_mclk clock\n");
1486 goto out_clk_enable_mclk;
1488 rate = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]);
1489 if (rate != CM_CAM_MCLK_HZ)
1490 dev_warn(isp->dev, "unexpected cam_mclk rate:\n"
1492 " actual : %ld\n", CM_CAM_MCLK_HZ, rate);
1493 r = clk_prepare_enable(isp->clock[ISP_CLK_CSI2_FCK]);
1495 dev_err(isp->dev, "failed to enable csi2_fck clock\n");
1496 goto out_clk_enable_csi2_fclk;
1500 out_clk_enable_csi2_fclk:
1501 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
1502 out_clk_enable_mclk:
1503 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
1509 * isp_disable_clocks - Disable ISP clocks
1510 * @isp: OMAP3 ISP device
1512 static void isp_disable_clocks(struct isp_device *isp)
1514 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
1515 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
1516 clk_disable_unprepare(isp->clock[ISP_CLK_CSI2_FCK]);
1519 static const char *isp_clocks[] = {
1526 static int isp_get_clocks(struct isp_device *isp)
1531 for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
1532 clk = devm_clk_get(isp->dev, isp_clocks[i]);
1534 dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]);
1535 return PTR_ERR(clk);
1538 isp->clock[i] = clk;
1545 * omap3isp_get - Acquire the ISP resource.
1547 * Initializes the clocks for the first acquire.
1549 * Increment the reference count on the ISP. If the first reference is taken,
1550 * enable clocks and power-up all submodules.
1552 * Return a pointer to the ISP device structure, or NULL if an error occurred.
1554 static struct isp_device *__omap3isp_get(struct isp_device *isp, bool irq)
1556 struct isp_device *__isp = isp;
1561 mutex_lock(&isp->isp_mutex);
1562 if (isp->ref_count > 0)
1565 if (isp_enable_clocks(isp) < 0) {
1570 /* We don't want to restore context before saving it! */
1571 if (isp->has_context)
1572 isp_restore_ctx(isp);
1575 isp_enable_interrupts(isp);
1580 mutex_unlock(&isp->isp_mutex);
1585 struct isp_device *omap3isp_get(struct isp_device *isp)
1587 return __omap3isp_get(isp, true);
1591 * omap3isp_put - Release the ISP
1593 * Decrement the reference count on the ISP. If the last reference is released,
1594 * power-down all submodules, disable clocks and free temporary buffers.
1596 void omap3isp_put(struct isp_device *isp)
1601 mutex_lock(&isp->isp_mutex);
1602 BUG_ON(isp->ref_count == 0);
1603 if (--isp->ref_count == 0) {
1604 isp_disable_interrupts(isp);
1607 isp->has_context = 1;
1609 /* Reset the ISP if an entity has failed to stop. This is the
1610 * only way to recover from such conditions.
1614 isp_disable_clocks(isp);
1616 mutex_unlock(&isp->isp_mutex);
1619 /* --------------------------------------------------------------------------
1620 * Platform device driver
1624 * omap3isp_print_status - Prints the values of the ISP Control Module registers
1625 * @isp: OMAP3 ISP device
1627 #define ISP_PRINT_REGISTER(isp, name)\
1628 dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
1629 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_##name))
1630 #define SBL_PRINT_REGISTER(isp, name)\
1631 dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
1632 isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_##name))
1634 void omap3isp_print_status(struct isp_device *isp)
1636 dev_dbg(isp->dev, "-------------ISP Register dump--------------\n");
1638 ISP_PRINT_REGISTER(isp, SYSCONFIG);
1639 ISP_PRINT_REGISTER(isp, SYSSTATUS);
1640 ISP_PRINT_REGISTER(isp, IRQ0ENABLE);
1641 ISP_PRINT_REGISTER(isp, IRQ0STATUS);
1642 ISP_PRINT_REGISTER(isp, TCTRL_GRESET_LENGTH);
1643 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_REPLAY);
1644 ISP_PRINT_REGISTER(isp, CTRL);
1645 ISP_PRINT_REGISTER(isp, TCTRL_CTRL);
1646 ISP_PRINT_REGISTER(isp, TCTRL_FRAME);
1647 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_DELAY);
1648 ISP_PRINT_REGISTER(isp, TCTRL_STRB_DELAY);
1649 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_DELAY);
1650 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_LENGTH);
1651 ISP_PRINT_REGISTER(isp, TCTRL_STRB_LENGTH);
1652 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_LENGTH);
1654 SBL_PRINT_REGISTER(isp, PCR);
1655 SBL_PRINT_REGISTER(isp, SDR_REQ_EXP);
1657 dev_dbg(isp->dev, "--------------------------------------------\n");
1663 * Power management support.
1665 * As the ISP can't properly handle an input video stream interruption on a non
1666 * frame boundary, the ISP pipelines need to be stopped before sensors get
1667 * suspended. However, as suspending the sensors can require a running clock,
1668 * which can be provided by the ISP, the ISP can't be completely suspended
1669 * before the sensor.
1671 * To solve this problem power management support is split into prepare/complete
1672 * and suspend/resume operations. The pipelines are stopped in prepare() and the
1673 * ISP clocks get disabled in suspend(). Similarly, the clocks are reenabled in
1674 * resume(), and the the pipelines are restarted in complete().
1676 * TODO: PM dependencies between the ISP and sensors are not modeled explicitly
1679 static int isp_pm_prepare(struct device *dev)
1681 struct isp_device *isp = dev_get_drvdata(dev);
1684 WARN_ON(mutex_is_locked(&isp->isp_mutex));
1686 if (isp->ref_count == 0)
1689 reset = isp_suspend_modules(isp);
1690 isp_disable_interrupts(isp);
1698 static int isp_pm_suspend(struct device *dev)
1700 struct isp_device *isp = dev_get_drvdata(dev);
1702 WARN_ON(mutex_is_locked(&isp->isp_mutex));
1705 isp_disable_clocks(isp);
1710 static int isp_pm_resume(struct device *dev)
1712 struct isp_device *isp = dev_get_drvdata(dev);
1714 if (isp->ref_count == 0)
1717 return isp_enable_clocks(isp);
1720 static void isp_pm_complete(struct device *dev)
1722 struct isp_device *isp = dev_get_drvdata(dev);
1724 if (isp->ref_count == 0)
1727 isp_restore_ctx(isp);
1728 isp_enable_interrupts(isp);
1729 isp_resume_modules(isp);
1734 #define isp_pm_prepare NULL
1735 #define isp_pm_suspend NULL
1736 #define isp_pm_resume NULL
1737 #define isp_pm_complete NULL
1739 #endif /* CONFIG_PM */
1741 static void isp_unregister_entities(struct isp_device *isp)
1743 omap3isp_csi2_unregister_entities(&isp->isp_csi2a);
1744 omap3isp_ccp2_unregister_entities(&isp->isp_ccp2);
1745 omap3isp_ccdc_unregister_entities(&isp->isp_ccdc);
1746 omap3isp_preview_unregister_entities(&isp->isp_prev);
1747 omap3isp_resizer_unregister_entities(&isp->isp_res);
1748 omap3isp_stat_unregister_entities(&isp->isp_aewb);
1749 omap3isp_stat_unregister_entities(&isp->isp_af);
1750 omap3isp_stat_unregister_entities(&isp->isp_hist);
1752 v4l2_device_unregister(&isp->v4l2_dev);
1753 media_device_unregister(&isp->media_dev);
1757 * isp_register_subdev_group - Register a group of subdevices
1758 * @isp: OMAP3 ISP device
1759 * @board_info: I2C subdevs board information array
1761 * Register all I2C subdevices in the board_info array. The array must be
1762 * terminated by a NULL entry, and the first entry must be the sensor.
1764 * Return a pointer to the sensor media entity if it has been successfully
1765 * registered, or NULL otherwise.
1767 static struct v4l2_subdev *
1768 isp_register_subdev_group(struct isp_device *isp,
1769 struct isp_subdev_i2c_board_info *board_info)
1771 struct v4l2_subdev *sensor = NULL;
1774 if (board_info->board_info == NULL)
1777 for (first = 1; board_info->board_info; ++board_info, first = 0) {
1778 struct v4l2_subdev *subdev;
1779 struct i2c_adapter *adapter;
1781 adapter = i2c_get_adapter(board_info->i2c_adapter_id);
1782 if (adapter == NULL) {
1783 dev_err(isp->dev, "%s: Unable to get I2C adapter %d for "
1784 "device %s\n", __func__,
1785 board_info->i2c_adapter_id,
1786 board_info->board_info->type);
1790 subdev = v4l2_i2c_new_subdev_board(&isp->v4l2_dev, adapter,
1791 board_info->board_info, NULL);
1792 if (subdev == NULL) {
1793 dev_err(isp->dev, "%s: Unable to register subdev %s\n",
1794 __func__, board_info->board_info->type);
1805 static int isp_register_entities(struct isp_device *isp)
1807 struct isp_platform_data *pdata = isp->pdata;
1808 struct isp_v4l2_subdevs_group *subdevs;
1811 isp->media_dev.dev = isp->dev;
1812 strlcpy(isp->media_dev.model, "TI OMAP3 ISP",
1813 sizeof(isp->media_dev.model));
1814 isp->media_dev.hw_revision = isp->revision;
1815 isp->media_dev.link_notify = isp_pipeline_link_notify;
1816 ret = media_device_register(&isp->media_dev);
1818 dev_err(isp->dev, "%s: Media device registration failed (%d)\n",
1823 isp->v4l2_dev.mdev = &isp->media_dev;
1824 ret = v4l2_device_register(isp->dev, &isp->v4l2_dev);
1826 dev_err(isp->dev, "%s: V4L2 device registration failed (%d)\n",
1831 /* Register internal entities */
1832 ret = omap3isp_ccp2_register_entities(&isp->isp_ccp2, &isp->v4l2_dev);
1836 ret = omap3isp_csi2_register_entities(&isp->isp_csi2a, &isp->v4l2_dev);
1840 ret = omap3isp_ccdc_register_entities(&isp->isp_ccdc, &isp->v4l2_dev);
1844 ret = omap3isp_preview_register_entities(&isp->isp_prev,
1849 ret = omap3isp_resizer_register_entities(&isp->isp_res, &isp->v4l2_dev);
1853 ret = omap3isp_stat_register_entities(&isp->isp_aewb, &isp->v4l2_dev);
1857 ret = omap3isp_stat_register_entities(&isp->isp_af, &isp->v4l2_dev);
1861 ret = omap3isp_stat_register_entities(&isp->isp_hist, &isp->v4l2_dev);
1865 /* Register external entities */
1866 for (subdevs = pdata->subdevs; subdevs && subdevs->subdevs; ++subdevs) {
1867 struct v4l2_subdev *sensor;
1868 struct media_entity *input;
1873 sensor = isp_register_subdev_group(isp, subdevs->subdevs);
1877 sensor->host_priv = subdevs;
1879 /* Connect the sensor to the correct interface module. Parallel
1880 * sensors are connected directly to the CCDC, while serial
1881 * sensors are connected to the CSI2a, CCP2b or CSI2c receiver
1882 * through CSIPHY1 or CSIPHY2.
1884 switch (subdevs->interface) {
1885 case ISP_INTERFACE_PARALLEL:
1886 input = &isp->isp_ccdc.subdev.entity;
1887 pad = CCDC_PAD_SINK;
1891 case ISP_INTERFACE_CSI2A_PHY2:
1892 input = &isp->isp_csi2a.subdev.entity;
1893 pad = CSI2_PAD_SINK;
1894 flags = MEDIA_LNK_FL_IMMUTABLE
1895 | MEDIA_LNK_FL_ENABLED;
1898 case ISP_INTERFACE_CCP2B_PHY1:
1899 case ISP_INTERFACE_CCP2B_PHY2:
1900 input = &isp->isp_ccp2.subdev.entity;
1901 pad = CCP2_PAD_SINK;
1905 case ISP_INTERFACE_CSI2C_PHY1:
1906 input = &isp->isp_csi2c.subdev.entity;
1907 pad = CSI2_PAD_SINK;
1908 flags = MEDIA_LNK_FL_IMMUTABLE
1909 | MEDIA_LNK_FL_ENABLED;
1913 dev_err(isp->dev, "%s: invalid interface type %u\n",
1914 __func__, subdevs->interface);
1919 for (i = 0; i < sensor->entity.num_pads; i++) {
1920 if (sensor->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE)
1923 if (i == sensor->entity.num_pads) {
1925 "%s: no source pad in external entity\n",
1931 ret = media_entity_create_link(&sensor->entity, i, input, pad,
1937 ret = v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
1941 isp_unregister_entities(isp);
1946 static void isp_cleanup_modules(struct isp_device *isp)
1948 omap3isp_h3a_aewb_cleanup(isp);
1949 omap3isp_h3a_af_cleanup(isp);
1950 omap3isp_hist_cleanup(isp);
1951 omap3isp_resizer_cleanup(isp);
1952 omap3isp_preview_cleanup(isp);
1953 omap3isp_ccdc_cleanup(isp);
1954 omap3isp_ccp2_cleanup(isp);
1955 omap3isp_csi2_cleanup(isp);
1958 static int isp_initialize_modules(struct isp_device *isp)
1962 ret = omap3isp_csiphy_init(isp);
1964 dev_err(isp->dev, "CSI PHY initialization failed\n");
1968 ret = omap3isp_csi2_init(isp);
1970 dev_err(isp->dev, "CSI2 initialization failed\n");
1974 ret = omap3isp_ccp2_init(isp);
1976 dev_err(isp->dev, "CCP2 initialization failed\n");
1980 ret = omap3isp_ccdc_init(isp);
1982 dev_err(isp->dev, "CCDC initialization failed\n");
1986 ret = omap3isp_preview_init(isp);
1988 dev_err(isp->dev, "Preview initialization failed\n");
1992 ret = omap3isp_resizer_init(isp);
1994 dev_err(isp->dev, "Resizer initialization failed\n");
1998 ret = omap3isp_hist_init(isp);
2000 dev_err(isp->dev, "Histogram initialization failed\n");
2004 ret = omap3isp_h3a_aewb_init(isp);
2006 dev_err(isp->dev, "H3A AEWB initialization failed\n");
2007 goto error_h3a_aewb;
2010 ret = omap3isp_h3a_af_init(isp);
2012 dev_err(isp->dev, "H3A AF initialization failed\n");
2016 /* Connect the submodules. */
2017 ret = media_entity_create_link(
2018 &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
2019 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
2023 ret = media_entity_create_link(
2024 &isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
2025 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
2029 ret = media_entity_create_link(
2030 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2031 &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
2035 ret = media_entity_create_link(
2036 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
2037 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
2041 ret = media_entity_create_link(
2042 &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
2043 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
2047 ret = media_entity_create_link(
2048 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2049 &isp->isp_aewb.subdev.entity, 0,
2050 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
2054 ret = media_entity_create_link(
2055 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2056 &isp->isp_af.subdev.entity, 0,
2057 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
2061 ret = media_entity_create_link(
2062 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2063 &isp->isp_hist.subdev.entity, 0,
2064 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
2071 omap3isp_h3a_af_cleanup(isp);
2073 omap3isp_h3a_aewb_cleanup(isp);
2075 omap3isp_hist_cleanup(isp);
2077 omap3isp_resizer_cleanup(isp);
2079 omap3isp_preview_cleanup(isp);
2081 omap3isp_ccdc_cleanup(isp);
2083 omap3isp_ccp2_cleanup(isp);
2085 omap3isp_csi2_cleanup(isp);
2092 * isp_remove - Remove ISP platform device
2093 * @pdev: Pointer to ISP platform device
2097 static int isp_remove(struct platform_device *pdev)
2099 struct isp_device *isp = platform_get_drvdata(pdev);
2101 isp_unregister_entities(isp);
2102 isp_cleanup_modules(isp);
2103 isp_xclk_cleanup(isp);
2105 __omap3isp_get(isp, false);
2106 iommu_detach_device(isp->domain, &pdev->dev);
2107 iommu_domain_free(isp->domain);
2114 static int isp_map_mem_resource(struct platform_device *pdev,
2115 struct isp_device *isp,
2116 enum isp_mem_resources res)
2118 struct resource *mem;
2120 /* request the mem region for the camera registers */
2122 mem = platform_get_resource(pdev, IORESOURCE_MEM, res);
2124 dev_err(isp->dev, "no mem resource?\n");
2128 if (!devm_request_mem_region(isp->dev, mem->start, resource_size(mem),
2131 "cannot reserve camera register I/O region\n");
2134 isp->mmio_base_phys[res] = mem->start;
2135 isp->mmio_size[res] = resource_size(mem);
2137 /* map the region */
2138 isp->mmio_base[res] = devm_ioremap_nocache(isp->dev,
2139 isp->mmio_base_phys[res],
2140 isp->mmio_size[res]);
2141 if (!isp->mmio_base[res]) {
2142 dev_err(isp->dev, "cannot map camera register I/O region\n");
2150 * isp_probe - Probe ISP platform device
2151 * @pdev: Pointer to ISP platform device
2153 * Returns 0 if successful,
2154 * -ENOMEM if no memory available,
2155 * -ENODEV if no platform device resources found
2156 * or no space for remapping registers,
2157 * -EINVAL if couldn't install ISR,
2158 * or clk_get return error value.
2160 static int isp_probe(struct platform_device *pdev)
2162 struct isp_platform_data *pdata = pdev->dev.platform_data;
2163 struct isp_device *isp;
2170 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL);
2172 dev_err(&pdev->dev, "could not allocate memory\n");
2176 isp->autoidle = autoidle;
2178 mutex_init(&isp->isp_mutex);
2179 spin_lock_init(&isp->stat_lock);
2181 isp->dev = &pdev->dev;
2185 ret = dma_coerce_mask_and_coherent(isp->dev, DMA_BIT_MASK(32));
2189 platform_set_drvdata(pdev, isp);
2192 isp->isp_csiphy1.vdd = devm_regulator_get(&pdev->dev, "VDD_CSIPHY1");
2193 isp->isp_csiphy2.vdd = devm_regulator_get(&pdev->dev, "VDD_CSIPHY2");
2197 * The ISP clock tree is revision-dependent. We thus need to enable ICLK
2198 * manually to read the revision before calling __omap3isp_get().
2200 ret = isp_map_mem_resource(pdev, isp, OMAP3_ISP_IOMEM_MAIN);
2204 ret = isp_get_clocks(isp);
2208 ret = clk_enable(isp->clock[ISP_CLK_CAM_ICK]);
2212 isp->revision = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
2213 dev_info(isp->dev, "Revision %d.%d found\n",
2214 (isp->revision & 0xf0) >> 4, isp->revision & 0x0f);
2216 clk_disable(isp->clock[ISP_CLK_CAM_ICK]);
2218 if (__omap3isp_get(isp, false) == NULL) {
2223 ret = isp_reset(isp);
2227 ret = isp_xclk_init(isp);
2231 /* Memory resources */
2232 for (m = 0; m < ARRAY_SIZE(isp_res_maps); m++)
2233 if (isp->revision == isp_res_maps[m].isp_rev)
2236 if (m == ARRAY_SIZE(isp_res_maps)) {
2237 dev_err(isp->dev, "No resource map found for ISP rev %d.%d\n",
2238 (isp->revision & 0xf0) >> 4, isp->revision & 0xf);
2243 for (i = 1; i < OMAP3_ISP_IOMEM_LAST; i++) {
2244 if (isp_res_maps[m].map & 1 << i) {
2245 ret = isp_map_mem_resource(pdev, isp, i);
2251 isp->domain = iommu_domain_alloc(pdev->dev.bus);
2253 dev_err(isp->dev, "can't alloc iommu domain\n");
2258 ret = iommu_attach_device(isp->domain, &pdev->dev);
2260 dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret);
2261 ret = -EPROBE_DEFER;
2266 isp->irq_num = platform_get_irq(pdev, 0);
2267 if (isp->irq_num <= 0) {
2268 dev_err(isp->dev, "No IRQ resource\n");
2273 if (devm_request_irq(isp->dev, isp->irq_num, isp_isr, IRQF_SHARED,
2274 "OMAP3 ISP", isp)) {
2275 dev_err(isp->dev, "Unable to request IRQ\n");
2281 ret = isp_initialize_modules(isp);
2285 ret = isp_register_entities(isp);
2289 isp_core_init(isp, 1);
2295 isp_cleanup_modules(isp);
2297 iommu_detach_device(isp->domain, &pdev->dev);
2299 iommu_domain_free(isp->domain);
2302 isp_xclk_cleanup(isp);
2305 mutex_destroy(&isp->isp_mutex);
2310 static const struct dev_pm_ops omap3isp_pm_ops = {
2311 .prepare = isp_pm_prepare,
2312 .suspend = isp_pm_suspend,
2313 .resume = isp_pm_resume,
2314 .complete = isp_pm_complete,
2317 static struct platform_device_id omap3isp_id_table[] = {
2321 MODULE_DEVICE_TABLE(platform, omap3isp_id_table);
2323 static struct platform_driver omap3isp_driver = {
2325 .remove = isp_remove,
2326 .id_table = omap3isp_id_table,
2328 .owner = THIS_MODULE,
2330 .pm = &omap3isp_pm_ops,
2334 module_platform_driver(omap3isp_driver);
2336 MODULE_AUTHOR("Nokia Corporation");
2337 MODULE_DESCRIPTION("TI OMAP3 ISP driver");
2338 MODULE_LICENSE("GPL");
2339 MODULE_VERSION(ISP_VIDEO_DRIVER_VERSION);