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 isp->xclks[i].clk = ERR_PTR(-EINVAL);
296 for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) {
297 struct isp_xclk *xclk = &isp->xclks[i];
300 xclk->id = i == 0 ? ISP_XCLK_A : ISP_XCLK_B;
302 spin_lock_init(&xclk->lock);
304 init.name = i == 0 ? "cam_xclka" : "cam_xclkb";
305 init.ops = &isp_xclk_ops;
306 init.parent_names = &isp_xclk_parent_name;
307 init.num_parents = 1;
309 xclk->hw.init = &init;
311 * The first argument is NULL in order to avoid circular
312 * reference, as this driver takes reference on the
313 * sensor subdevice modules and the sensors would take
314 * reference on this module through clk_get().
316 xclk->clk = clk_register(NULL, &xclk->hw);
317 if (IS_ERR(xclk->clk))
318 return PTR_ERR(xclk->clk);
320 if (pdata->xclks[i].con_id == NULL &&
321 pdata->xclks[i].dev_id == NULL)
324 xclk->lookup = kzalloc(sizeof(*xclk->lookup), GFP_KERNEL);
325 if (xclk->lookup == NULL)
328 xclk->lookup->con_id = pdata->xclks[i].con_id;
329 xclk->lookup->dev_id = pdata->xclks[i].dev_id;
330 xclk->lookup->clk = xclk->clk;
332 clkdev_add(xclk->lookup);
338 static void isp_xclk_cleanup(struct isp_device *isp)
342 for (i = 0; i < ARRAY_SIZE(isp->xclks); ++i) {
343 struct isp_xclk *xclk = &isp->xclks[i];
345 if (!IS_ERR(xclk->clk))
346 clk_unregister(xclk->clk);
349 clkdev_drop(xclk->lookup);
353 /* -----------------------------------------------------------------------------
358 * isp_enable_interrupts - Enable ISP interrupts.
359 * @isp: OMAP3 ISP device
361 static void isp_enable_interrupts(struct isp_device *isp)
363 static const u32 irq = IRQ0ENABLE_CSIA_IRQ
364 | IRQ0ENABLE_CSIB_IRQ
365 | IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ
366 | IRQ0ENABLE_CCDC_LSC_DONE_IRQ
367 | IRQ0ENABLE_CCDC_VD0_IRQ
368 | IRQ0ENABLE_CCDC_VD1_IRQ
369 | IRQ0ENABLE_HS_VS_IRQ
370 | IRQ0ENABLE_HIST_DONE_IRQ
371 | IRQ0ENABLE_H3A_AWB_DONE_IRQ
372 | IRQ0ENABLE_H3A_AF_DONE_IRQ
373 | IRQ0ENABLE_PRV_DONE_IRQ
374 | IRQ0ENABLE_RSZ_DONE_IRQ;
376 isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
377 isp_reg_writel(isp, irq, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
381 * isp_disable_interrupts - Disable ISP interrupts.
382 * @isp: OMAP3 ISP device
384 static void isp_disable_interrupts(struct isp_device *isp)
386 isp_reg_writel(isp, 0, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0ENABLE);
390 * isp_core_init - ISP core settings
391 * @isp: OMAP3 ISP device
392 * @idle: Consider idle state.
394 * Set the power settings for the ISP and SBL bus and cConfigure the HS/VS
397 * We need to configure the HS/VS interrupt source before interrupts get
398 * enabled, as the sensor might be free-running and the ISP default setting
399 * (HS edge) would put an unnecessary burden on the CPU.
401 static void isp_core_init(struct isp_device *isp, int idle)
404 ((idle ? ISP_SYSCONFIG_MIDLEMODE_SMARTSTANDBY :
405 ISP_SYSCONFIG_MIDLEMODE_FORCESTANDBY) <<
406 ISP_SYSCONFIG_MIDLEMODE_SHIFT) |
407 ((isp->revision == ISP_REVISION_15_0) ?
408 ISP_SYSCONFIG_AUTOIDLE : 0),
409 OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
412 (isp->autoidle ? ISPCTRL_SBL_AUTOIDLE : 0) |
413 ISPCTRL_SYNC_DETECT_VSRISE,
414 OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
418 * Configure the bridge and lane shifter. Valid inputs are
420 * CCDC_INPUT_PARALLEL: Parallel interface
421 * CCDC_INPUT_CSI2A: CSI2a receiver
422 * CCDC_INPUT_CCP2B: CCP2b receiver
423 * CCDC_INPUT_CSI2C: CSI2c receiver
425 * The bridge and lane shifter are configured according to the selected input
426 * and the ISP platform data.
428 void omap3isp_configure_bridge(struct isp_device *isp,
429 enum ccdc_input_entity input,
430 const struct isp_parallel_platform_data *pdata,
431 unsigned int shift, unsigned int bridge)
435 ispctrl_val = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
436 ispctrl_val &= ~ISPCTRL_SHIFT_MASK;
437 ispctrl_val &= ~ISPCTRL_PAR_CLK_POL_INV;
438 ispctrl_val &= ~ISPCTRL_PAR_SER_CLK_SEL_MASK;
439 ispctrl_val &= ~ISPCTRL_PAR_BRIDGE_MASK;
440 ispctrl_val |= bridge;
443 case CCDC_INPUT_PARALLEL:
444 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_PARALLEL;
445 ispctrl_val |= pdata->clk_pol << ISPCTRL_PAR_CLK_POL_SHIFT;
446 shift += pdata->data_lane_shift * 2;
449 case CCDC_INPUT_CSI2A:
450 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIA;
453 case CCDC_INPUT_CCP2B:
454 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIB;
457 case CCDC_INPUT_CSI2C:
458 ispctrl_val |= ISPCTRL_PAR_SER_CLK_SEL_CSIC;
465 ispctrl_val |= ((shift/2) << ISPCTRL_SHIFT_SHIFT) & ISPCTRL_SHIFT_MASK;
467 isp_reg_writel(isp, ispctrl_val, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL);
470 void omap3isp_hist_dma_done(struct isp_device *isp)
472 if (omap3isp_ccdc_busy(&isp->isp_ccdc) ||
473 omap3isp_stat_pcr_busy(&isp->isp_hist)) {
474 /* Histogram cannot be enabled in this frame anymore */
475 atomic_set(&isp->isp_hist.buf_err, 1);
476 dev_dbg(isp->dev, "hist: Out of synchronization with "
477 "CCDC. Ignoring next buffer.\n");
481 static inline void isp_isr_dbg(struct isp_device *isp, u32 irqstatus)
483 static const char *name[] = {
502 "CCDC_LSC_PREFETCH_COMPLETED",
503 "CCDC_LSC_PREFETCH_ERROR",
519 dev_dbg(isp->dev, "ISP IRQ: ");
521 for (i = 0; i < ARRAY_SIZE(name); i++) {
522 if ((1 << i) & irqstatus)
523 printk(KERN_CONT "%s ", name[i]);
525 printk(KERN_CONT "\n");
528 static void isp_isr_sbl(struct isp_device *isp)
530 struct device *dev = isp->dev;
531 struct isp_pipeline *pipe;
535 * Handle shared buffer logic overflows for video buffers.
536 * ISPSBL_PCR_CCDCPRV_2_RSZ_OVF can be safely ignored.
538 sbl_pcr = isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
539 isp_reg_writel(isp, sbl_pcr, OMAP3_ISP_IOMEM_SBL, ISPSBL_PCR);
540 sbl_pcr &= ~ISPSBL_PCR_CCDCPRV_2_RSZ_OVF;
543 dev_dbg(dev, "SBL overflow (PCR = 0x%08x)\n", sbl_pcr);
545 if (sbl_pcr & ISPSBL_PCR_CSIB_WBL_OVF) {
546 pipe = to_isp_pipeline(&isp->isp_ccp2.subdev.entity);
551 if (sbl_pcr & ISPSBL_PCR_CSIA_WBL_OVF) {
552 pipe = to_isp_pipeline(&isp->isp_csi2a.subdev.entity);
557 if (sbl_pcr & ISPSBL_PCR_CCDC_WBL_OVF) {
558 pipe = to_isp_pipeline(&isp->isp_ccdc.subdev.entity);
563 if (sbl_pcr & ISPSBL_PCR_PRV_WBL_OVF) {
564 pipe = to_isp_pipeline(&isp->isp_prev.subdev.entity);
569 if (sbl_pcr & (ISPSBL_PCR_RSZ1_WBL_OVF
570 | ISPSBL_PCR_RSZ2_WBL_OVF
571 | ISPSBL_PCR_RSZ3_WBL_OVF
572 | ISPSBL_PCR_RSZ4_WBL_OVF)) {
573 pipe = to_isp_pipeline(&isp->isp_res.subdev.entity);
578 if (sbl_pcr & ISPSBL_PCR_H3A_AF_WBL_OVF)
579 omap3isp_stat_sbl_overflow(&isp->isp_af);
581 if (sbl_pcr & ISPSBL_PCR_H3A_AEAWB_WBL_OVF)
582 omap3isp_stat_sbl_overflow(&isp->isp_aewb);
586 * isp_isr - Interrupt Service Routine for Camera ISP module.
587 * @irq: Not used currently.
588 * @_isp: Pointer to the OMAP3 ISP device
590 * Handles the corresponding callback if plugged in.
592 * Returns IRQ_HANDLED when IRQ was correctly handled, or IRQ_NONE when the
593 * IRQ wasn't handled.
595 static irqreturn_t isp_isr(int irq, void *_isp)
597 static const u32 ccdc_events = IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ |
598 IRQ0STATUS_CCDC_LSC_DONE_IRQ |
599 IRQ0STATUS_CCDC_VD0_IRQ |
600 IRQ0STATUS_CCDC_VD1_IRQ |
601 IRQ0STATUS_HS_VS_IRQ;
602 struct isp_device *isp = _isp;
605 irqstatus = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
606 isp_reg_writel(isp, irqstatus, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
610 if (irqstatus & IRQ0STATUS_CSIA_IRQ)
611 omap3isp_csi2_isr(&isp->isp_csi2a);
613 if (irqstatus & IRQ0STATUS_CSIB_IRQ)
614 omap3isp_ccp2_isr(&isp->isp_ccp2);
616 if (irqstatus & IRQ0STATUS_CCDC_VD0_IRQ) {
617 if (isp->isp_ccdc.output & CCDC_OUTPUT_PREVIEW)
618 omap3isp_preview_isr_frame_sync(&isp->isp_prev);
619 if (isp->isp_ccdc.output & CCDC_OUTPUT_RESIZER)
620 omap3isp_resizer_isr_frame_sync(&isp->isp_res);
621 omap3isp_stat_isr_frame_sync(&isp->isp_aewb);
622 omap3isp_stat_isr_frame_sync(&isp->isp_af);
623 omap3isp_stat_isr_frame_sync(&isp->isp_hist);
626 if (irqstatus & ccdc_events)
627 omap3isp_ccdc_isr(&isp->isp_ccdc, irqstatus & ccdc_events);
629 if (irqstatus & IRQ0STATUS_PRV_DONE_IRQ) {
630 if (isp->isp_prev.output & PREVIEW_OUTPUT_RESIZER)
631 omap3isp_resizer_isr_frame_sync(&isp->isp_res);
632 omap3isp_preview_isr(&isp->isp_prev);
635 if (irqstatus & IRQ0STATUS_RSZ_DONE_IRQ)
636 omap3isp_resizer_isr(&isp->isp_res);
638 if (irqstatus & IRQ0STATUS_H3A_AWB_DONE_IRQ)
639 omap3isp_stat_isr(&isp->isp_aewb);
641 if (irqstatus & IRQ0STATUS_H3A_AF_DONE_IRQ)
642 omap3isp_stat_isr(&isp->isp_af);
644 if (irqstatus & IRQ0STATUS_HIST_DONE_IRQ)
645 omap3isp_stat_isr(&isp->isp_hist);
649 #if defined(DEBUG) && defined(ISP_ISR_DEBUG)
650 isp_isr_dbg(isp, irqstatus);
656 /* -----------------------------------------------------------------------------
657 * Pipeline power management
659 * Entities must be powered up when part of a pipeline that contains at least
660 * one open video device node.
662 * To achieve this use the entity use_count field to track the number of users.
663 * For entities corresponding to video device nodes the use_count field stores
664 * the users count of the node. For entities corresponding to subdevs the
665 * use_count field stores the total number of users of all video device nodes
668 * The omap3isp_pipeline_pm_use() function must be called in the open() and
669 * close() handlers of video device nodes. It increments or decrements the use
670 * count of all subdev entities in the pipeline.
672 * To react to link management on powered pipelines, the link setup notification
673 * callback updates the use count of all entities in the source and sink sides
678 * isp_pipeline_pm_use_count - Count the number of users of a pipeline
679 * @entity: The entity
681 * Return the total number of users of all video device nodes in the pipeline.
683 static int isp_pipeline_pm_use_count(struct media_entity *entity)
685 struct media_entity_graph graph;
688 media_entity_graph_walk_start(&graph, entity);
690 while ((entity = media_entity_graph_walk_next(&graph))) {
691 if (media_entity_type(entity) == MEDIA_ENT_T_DEVNODE)
692 use += entity->use_count;
699 * isp_pipeline_pm_power_one - Apply power change to an entity
700 * @entity: The entity
701 * @change: Use count change
703 * Change the entity use count by @change. If the entity is a subdev update its
704 * power state by calling the core::s_power operation when the use count goes
705 * from 0 to != 0 or from != 0 to 0.
707 * Return 0 on success or a negative error code on failure.
709 static int isp_pipeline_pm_power_one(struct media_entity *entity, int change)
711 struct v4l2_subdev *subdev;
714 subdev = media_entity_type(entity) == MEDIA_ENT_T_V4L2_SUBDEV
715 ? media_entity_to_v4l2_subdev(entity) : NULL;
717 if (entity->use_count == 0 && change > 0 && subdev != NULL) {
718 ret = v4l2_subdev_call(subdev, core, s_power, 1);
719 if (ret < 0 && ret != -ENOIOCTLCMD)
723 entity->use_count += change;
724 WARN_ON(entity->use_count < 0);
726 if (entity->use_count == 0 && change < 0 && subdev != NULL)
727 v4l2_subdev_call(subdev, core, s_power, 0);
733 * isp_pipeline_pm_power - Apply power change to all entities in a pipeline
734 * @entity: The entity
735 * @change: Use count change
737 * Walk the pipeline to update the use count and the power state of all non-node
740 * Return 0 on success or a negative error code on failure.
742 static int isp_pipeline_pm_power(struct media_entity *entity, int change)
744 struct media_entity_graph graph;
745 struct media_entity *first = entity;
751 media_entity_graph_walk_start(&graph, entity);
753 while (!ret && (entity = media_entity_graph_walk_next(&graph)))
754 if (media_entity_type(entity) != MEDIA_ENT_T_DEVNODE)
755 ret = isp_pipeline_pm_power_one(entity, change);
760 media_entity_graph_walk_start(&graph, first);
762 while ((first = media_entity_graph_walk_next(&graph))
764 if (media_entity_type(first) != MEDIA_ENT_T_DEVNODE)
765 isp_pipeline_pm_power_one(first, -change);
771 * omap3isp_pipeline_pm_use - Update the use count of an entity
772 * @entity: The entity
773 * @use: Use (1) or stop using (0) the entity
775 * Update the use count of all entities in the pipeline and power entities on or
778 * Return 0 on success or a negative error code on failure. Powering entities
779 * off is assumed to never fail. No failure can occur when the use parameter is
782 int omap3isp_pipeline_pm_use(struct media_entity *entity, int use)
784 int change = use ? 1 : -1;
787 mutex_lock(&entity->parent->graph_mutex);
789 /* Apply use count to node. */
790 entity->use_count += change;
791 WARN_ON(entity->use_count < 0);
793 /* Apply power change to connected non-nodes. */
794 ret = isp_pipeline_pm_power(entity, change);
796 entity->use_count -= change;
798 mutex_unlock(&entity->parent->graph_mutex);
804 * isp_pipeline_link_notify - Link management notification callback
806 * @flags: New link flags that will be applied
807 * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
809 * React to link management on powered pipelines by updating the use count of
810 * all entities in the source and sink sides of the link. Entities are powered
811 * on or off accordingly.
813 * Return 0 on success or a negative error code on failure. Powering entities
814 * off is assumed to never fail. This function will not fail for disconnection
817 static int isp_pipeline_link_notify(struct media_link *link, u32 flags,
818 unsigned int notification)
820 struct media_entity *source = link->source->entity;
821 struct media_entity *sink = link->sink->entity;
822 int source_use = isp_pipeline_pm_use_count(source);
823 int sink_use = isp_pipeline_pm_use_count(sink);
826 if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
827 !(link->flags & MEDIA_LNK_FL_ENABLED)) {
828 /* Powering off entities is assumed to never fail. */
829 isp_pipeline_pm_power(source, -sink_use);
830 isp_pipeline_pm_power(sink, -source_use);
834 if (notification == MEDIA_DEV_NOTIFY_POST_LINK_CH &&
835 (flags & MEDIA_LNK_FL_ENABLED)) {
837 ret = isp_pipeline_pm_power(source, sink_use);
841 ret = isp_pipeline_pm_power(sink, source_use);
843 isp_pipeline_pm_power(source, -sink_use);
851 /* -----------------------------------------------------------------------------
852 * Pipeline stream management
856 * isp_pipeline_enable - Enable streaming on a pipeline
857 * @pipe: ISP pipeline
858 * @mode: Stream mode (single shot or continuous)
860 * Walk the entities chain starting at the pipeline output video node and start
861 * all modules in the chain in the given mode.
863 * Return 0 if successful, or the return value of the failed video::s_stream
864 * operation otherwise.
866 static int isp_pipeline_enable(struct isp_pipeline *pipe,
867 enum isp_pipeline_stream_state mode)
869 struct isp_device *isp = pipe->output->isp;
870 struct media_entity *entity;
871 struct media_pad *pad;
872 struct v4l2_subdev *subdev;
876 /* If the preview engine crashed it might not respond to read/write
877 * operations on the L4 bus. This would result in a bus fault and a
878 * kernel oops. Refuse to start streaming in that case. This check must
879 * be performed before the loop below to avoid starting entities if the
880 * pipeline won't start anyway (those entities would then likely fail to
881 * stop, making the problem worse).
883 if ((pipe->entities & isp->crashed) &
884 (1U << isp->isp_prev.subdev.entity.id))
887 spin_lock_irqsave(&pipe->lock, flags);
888 pipe->state &= ~(ISP_PIPELINE_IDLE_INPUT | ISP_PIPELINE_IDLE_OUTPUT);
889 spin_unlock_irqrestore(&pipe->lock, flags);
891 pipe->do_propagation = false;
893 entity = &pipe->output->video.entity;
895 pad = &entity->pads[0];
896 if (!(pad->flags & MEDIA_PAD_FL_SINK))
899 pad = media_entity_remote_pad(pad);
901 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
904 entity = pad->entity;
905 subdev = media_entity_to_v4l2_subdev(entity);
907 ret = v4l2_subdev_call(subdev, video, s_stream, mode);
908 if (ret < 0 && ret != -ENOIOCTLCMD)
911 if (subdev == &isp->isp_ccdc.subdev) {
912 v4l2_subdev_call(&isp->isp_aewb.subdev, video,
914 v4l2_subdev_call(&isp->isp_af.subdev, video,
916 v4l2_subdev_call(&isp->isp_hist.subdev, video,
918 pipe->do_propagation = true;
925 static int isp_pipeline_wait_resizer(struct isp_device *isp)
927 return omap3isp_resizer_busy(&isp->isp_res);
930 static int isp_pipeline_wait_preview(struct isp_device *isp)
932 return omap3isp_preview_busy(&isp->isp_prev);
935 static int isp_pipeline_wait_ccdc(struct isp_device *isp)
937 return omap3isp_stat_busy(&isp->isp_af)
938 || omap3isp_stat_busy(&isp->isp_aewb)
939 || omap3isp_stat_busy(&isp->isp_hist)
940 || omap3isp_ccdc_busy(&isp->isp_ccdc);
943 #define ISP_STOP_TIMEOUT msecs_to_jiffies(1000)
945 static int isp_pipeline_wait(struct isp_device *isp,
946 int(*busy)(struct isp_device *isp))
948 unsigned long timeout = jiffies + ISP_STOP_TIMEOUT;
950 while (!time_after(jiffies, timeout)) {
959 * isp_pipeline_disable - Disable streaming on a pipeline
960 * @pipe: ISP pipeline
962 * Walk the entities chain starting at the pipeline output video node and stop
963 * all modules in the chain. Wait synchronously for the modules to be stopped if
966 * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
967 * can't be stopped (in which case a software reset of the ISP is probably
970 static int isp_pipeline_disable(struct isp_pipeline *pipe)
972 struct isp_device *isp = pipe->output->isp;
973 struct media_entity *entity;
974 struct media_pad *pad;
975 struct v4l2_subdev *subdev;
980 * We need to stop all the modules after CCDC first or they'll
981 * never stop since they may not get a full frame from CCDC.
983 entity = &pipe->output->video.entity;
985 pad = &entity->pads[0];
986 if (!(pad->flags & MEDIA_PAD_FL_SINK))
989 pad = media_entity_remote_pad(pad);
991 media_entity_type(pad->entity) != MEDIA_ENT_T_V4L2_SUBDEV)
994 entity = pad->entity;
995 subdev = media_entity_to_v4l2_subdev(entity);
997 if (subdev == &isp->isp_ccdc.subdev) {
998 v4l2_subdev_call(&isp->isp_aewb.subdev,
1000 v4l2_subdev_call(&isp->isp_af.subdev,
1001 video, s_stream, 0);
1002 v4l2_subdev_call(&isp->isp_hist.subdev,
1003 video, s_stream, 0);
1006 v4l2_subdev_call(subdev, video, s_stream, 0);
1008 if (subdev == &isp->isp_res.subdev)
1009 ret = isp_pipeline_wait(isp, isp_pipeline_wait_resizer);
1010 else if (subdev == &isp->isp_prev.subdev)
1011 ret = isp_pipeline_wait(isp, isp_pipeline_wait_preview);
1012 else if (subdev == &isp->isp_ccdc.subdev)
1013 ret = isp_pipeline_wait(isp, isp_pipeline_wait_ccdc);
1018 dev_info(isp->dev, "Unable to stop %s\n", subdev->name);
1019 /* If the entity failed to stopped, assume it has
1020 * crashed. Mark it as such, the ISP will be reset when
1021 * applications will release it.
1023 isp->crashed |= 1U << subdev->entity.id;
1024 failure = -ETIMEDOUT;
1032 * omap3isp_pipeline_set_stream - Enable/disable streaming on a pipeline
1033 * @pipe: ISP pipeline
1034 * @state: Stream state (stopped, single shot or continuous)
1036 * Set the pipeline to the given stream state. Pipelines can be started in
1037 * single-shot or continuous mode.
1039 * Return 0 if successful, or the return value of the failed video::s_stream
1040 * operation otherwise. The pipeline state is not updated when the operation
1041 * fails, except when stopping the pipeline.
1043 int omap3isp_pipeline_set_stream(struct isp_pipeline *pipe,
1044 enum isp_pipeline_stream_state state)
1048 if (state == ISP_PIPELINE_STREAM_STOPPED)
1049 ret = isp_pipeline_disable(pipe);
1051 ret = isp_pipeline_enable(pipe, state);
1053 if (ret == 0 || state == ISP_PIPELINE_STREAM_STOPPED)
1054 pipe->stream_state = state;
1060 * isp_pipeline_resume - Resume streaming on a pipeline
1061 * @pipe: ISP pipeline
1063 * Resume video output and input and re-enable pipeline.
1065 static void isp_pipeline_resume(struct isp_pipeline *pipe)
1067 int singleshot = pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT;
1069 omap3isp_video_resume(pipe->output, !singleshot);
1071 omap3isp_video_resume(pipe->input, 0);
1072 isp_pipeline_enable(pipe, pipe->stream_state);
1076 * isp_pipeline_suspend - Suspend streaming on a pipeline
1077 * @pipe: ISP pipeline
1081 static void isp_pipeline_suspend(struct isp_pipeline *pipe)
1083 isp_pipeline_disable(pipe);
1087 * isp_pipeline_is_last - Verify if entity has an enabled link to the output
1089 * @me: ISP module's media entity
1091 * Returns 1 if the entity has an enabled link to the output video node or 0
1092 * otherwise. It's true only while pipeline can have no more than one output
1095 static int isp_pipeline_is_last(struct media_entity *me)
1097 struct isp_pipeline *pipe;
1098 struct media_pad *pad;
1102 pipe = to_isp_pipeline(me);
1103 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED)
1105 pad = media_entity_remote_pad(&pipe->output->pad);
1106 return pad->entity == me;
1110 * isp_suspend_module_pipeline - Suspend pipeline to which belongs the module
1111 * @me: ISP module's media entity
1113 * Suspend the whole pipeline if module's entity has an enabled link to the
1114 * output video node. It works only while pipeline can have no more than one
1117 static void isp_suspend_module_pipeline(struct media_entity *me)
1119 if (isp_pipeline_is_last(me))
1120 isp_pipeline_suspend(to_isp_pipeline(me));
1124 * isp_resume_module_pipeline - Resume pipeline to which belongs the module
1125 * @me: ISP module's media entity
1127 * Resume the whole pipeline if module's entity has an enabled link to the
1128 * output video node. It works only while pipeline can have no more than one
1131 static void isp_resume_module_pipeline(struct media_entity *me)
1133 if (isp_pipeline_is_last(me))
1134 isp_pipeline_resume(to_isp_pipeline(me));
1138 * isp_suspend_modules - Suspend ISP submodules.
1139 * @isp: OMAP3 ISP device
1141 * Returns 0 if suspend left in idle state all the submodules properly,
1142 * or returns 1 if a general Reset is required to suspend the submodules.
1144 static int isp_suspend_modules(struct isp_device *isp)
1146 unsigned long timeout;
1148 omap3isp_stat_suspend(&isp->isp_aewb);
1149 omap3isp_stat_suspend(&isp->isp_af);
1150 omap3isp_stat_suspend(&isp->isp_hist);
1151 isp_suspend_module_pipeline(&isp->isp_res.subdev.entity);
1152 isp_suspend_module_pipeline(&isp->isp_prev.subdev.entity);
1153 isp_suspend_module_pipeline(&isp->isp_ccdc.subdev.entity);
1154 isp_suspend_module_pipeline(&isp->isp_csi2a.subdev.entity);
1155 isp_suspend_module_pipeline(&isp->isp_ccp2.subdev.entity);
1157 timeout = jiffies + ISP_STOP_TIMEOUT;
1158 while (omap3isp_stat_busy(&isp->isp_af)
1159 || omap3isp_stat_busy(&isp->isp_aewb)
1160 || omap3isp_stat_busy(&isp->isp_hist)
1161 || omap3isp_preview_busy(&isp->isp_prev)
1162 || omap3isp_resizer_busy(&isp->isp_res)
1163 || omap3isp_ccdc_busy(&isp->isp_ccdc)) {
1164 if (time_after(jiffies, timeout)) {
1165 dev_info(isp->dev, "can't stop modules.\n");
1175 * isp_resume_modules - Resume ISP submodules.
1176 * @isp: OMAP3 ISP device
1178 static void isp_resume_modules(struct isp_device *isp)
1180 omap3isp_stat_resume(&isp->isp_aewb);
1181 omap3isp_stat_resume(&isp->isp_af);
1182 omap3isp_stat_resume(&isp->isp_hist);
1183 isp_resume_module_pipeline(&isp->isp_res.subdev.entity);
1184 isp_resume_module_pipeline(&isp->isp_prev.subdev.entity);
1185 isp_resume_module_pipeline(&isp->isp_ccdc.subdev.entity);
1186 isp_resume_module_pipeline(&isp->isp_csi2a.subdev.entity);
1187 isp_resume_module_pipeline(&isp->isp_ccp2.subdev.entity);
1191 * isp_reset - Reset ISP with a timeout wait for idle.
1192 * @isp: OMAP3 ISP device
1194 static int isp_reset(struct isp_device *isp)
1196 unsigned long timeout = 0;
1199 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG)
1200 | ISP_SYSCONFIG_SOFTRESET,
1201 OMAP3_ISP_IOMEM_MAIN, ISP_SYSCONFIG);
1202 while (!(isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN,
1203 ISP_SYSSTATUS) & 0x1)) {
1204 if (timeout++ > 10000) {
1205 dev_alert(isp->dev, "cannot reset ISP\n");
1216 * isp_save_context - Saves the values of the ISP module registers.
1217 * @isp: OMAP3 ISP device
1218 * @reg_list: Structure containing pairs of register address and value to
1222 isp_save_context(struct isp_device *isp, struct isp_reg *reg_list)
1224 struct isp_reg *next = reg_list;
1226 for (; next->reg != ISP_TOK_TERM; next++)
1227 next->val = isp_reg_readl(isp, next->mmio_range, next->reg);
1231 * isp_restore_context - Restores the values of the ISP module registers.
1232 * @isp: OMAP3 ISP device
1233 * @reg_list: Structure containing pairs of register address and value to
1237 isp_restore_context(struct isp_device *isp, struct isp_reg *reg_list)
1239 struct isp_reg *next = reg_list;
1241 for (; next->reg != ISP_TOK_TERM; next++)
1242 isp_reg_writel(isp, next->val, next->mmio_range, next->reg);
1246 * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1247 * @isp: OMAP3 ISP device
1249 * Routine for saving the context of each module in the ISP.
1250 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1252 static void isp_save_ctx(struct isp_device *isp)
1254 isp_save_context(isp, isp_reg_list);
1255 omap_iommu_save_ctx(isp->dev);
1259 * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1260 * @isp: OMAP3 ISP device
1262 * Routine for restoring the context of each module in the ISP.
1263 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1265 static void isp_restore_ctx(struct isp_device *isp)
1267 isp_restore_context(isp, isp_reg_list);
1268 omap_iommu_restore_ctx(isp->dev);
1269 omap3isp_ccdc_restore_context(isp);
1270 omap3isp_preview_restore_context(isp);
1273 /* -----------------------------------------------------------------------------
1274 * SBL resources management
1276 #define OMAP3_ISP_SBL_READ (OMAP3_ISP_SBL_CSI1_READ | \
1277 OMAP3_ISP_SBL_CCDC_LSC_READ | \
1278 OMAP3_ISP_SBL_PREVIEW_READ | \
1279 OMAP3_ISP_SBL_RESIZER_READ)
1280 #define OMAP3_ISP_SBL_WRITE (OMAP3_ISP_SBL_CSI1_WRITE | \
1281 OMAP3_ISP_SBL_CSI2A_WRITE | \
1282 OMAP3_ISP_SBL_CSI2C_WRITE | \
1283 OMAP3_ISP_SBL_CCDC_WRITE | \
1284 OMAP3_ISP_SBL_PREVIEW_WRITE)
1286 void omap3isp_sbl_enable(struct isp_device *isp, enum isp_sbl_resource res)
1290 isp->sbl_resources |= res;
1292 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ)
1293 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1295 if (isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ)
1296 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1298 if (isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE)
1299 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1301 if (isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE)
1302 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1304 if (isp->sbl_resources & OMAP3_ISP_SBL_WRITE)
1305 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1307 if (isp->sbl_resources & OMAP3_ISP_SBL_READ)
1308 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1310 isp_reg_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1313 void omap3isp_sbl_disable(struct isp_device *isp, enum isp_sbl_resource res)
1317 isp->sbl_resources &= ~res;
1319 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI1_READ))
1320 sbl |= ISPCTRL_SBL_SHARED_RPORTA;
1322 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CCDC_LSC_READ))
1323 sbl |= ISPCTRL_SBL_SHARED_RPORTB;
1325 if (!(isp->sbl_resources & OMAP3_ISP_SBL_CSI2C_WRITE))
1326 sbl |= ISPCTRL_SBL_SHARED_WPORTC;
1328 if (!(isp->sbl_resources & OMAP3_ISP_SBL_RESIZER_WRITE))
1329 sbl |= ISPCTRL_SBL_WR0_RAM_EN;
1331 if (!(isp->sbl_resources & OMAP3_ISP_SBL_WRITE))
1332 sbl |= ISPCTRL_SBL_WR1_RAM_EN;
1334 if (!(isp->sbl_resources & OMAP3_ISP_SBL_READ))
1335 sbl |= ISPCTRL_SBL_RD_RAM_EN;
1337 isp_reg_clr(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL, sbl);
1341 * isp_module_sync_idle - Helper to sync module with its idle state
1342 * @me: ISP submodule's media entity
1343 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1344 * @stopping: flag which tells module wants to stop
1346 * This function checks if ISP submodule needs to wait for next interrupt. If
1347 * yes, makes the caller to sleep while waiting for such event.
1349 int omap3isp_module_sync_idle(struct media_entity *me, wait_queue_head_t *wait,
1352 struct isp_pipeline *pipe = to_isp_pipeline(me);
1354 if (pipe->stream_state == ISP_PIPELINE_STREAM_STOPPED ||
1355 (pipe->stream_state == ISP_PIPELINE_STREAM_SINGLESHOT &&
1356 !isp_pipeline_ready(pipe)))
1360 * atomic_set() doesn't include memory barrier on ARM platform for SMP
1361 * scenario. We'll call it here to avoid race conditions.
1363 atomic_set(stopping, 1);
1367 * If module is the last one, it's writing to memory. In this case,
1368 * it's necessary to check if the module is already paused due to
1369 * DMA queue underrun or if it has to wait for next interrupt to be
1371 * If it isn't the last one, the function won't sleep but *stopping
1372 * will still be set to warn next submodule caller's interrupt the
1373 * module wants to be idle.
1375 if (isp_pipeline_is_last(me)) {
1376 struct isp_video *video = pipe->output;
1377 unsigned long flags;
1378 spin_lock_irqsave(&video->queue->irqlock, flags);
1379 if (video->dmaqueue_flags & ISP_VIDEO_DMAQUEUE_UNDERRUN) {
1380 spin_unlock_irqrestore(&video->queue->irqlock, flags);
1381 atomic_set(stopping, 0);
1385 spin_unlock_irqrestore(&video->queue->irqlock, flags);
1386 if (!wait_event_timeout(*wait, !atomic_read(stopping),
1387 msecs_to_jiffies(1000))) {
1388 atomic_set(stopping, 0);
1398 * omap3isp_module_sync_is_stopped - Helper to verify if module was stopping
1399 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1400 * @stopping: flag which tells module wants to stop
1402 * This function checks if ISP submodule was stopping. In case of yes, it
1403 * notices the caller by setting stopping to 0 and waking up the wait queue.
1404 * Returns 1 if it was stopping or 0 otherwise.
1406 int omap3isp_module_sync_is_stopping(wait_queue_head_t *wait,
1409 if (atomic_cmpxchg(stopping, 1, 0)) {
1417 /* --------------------------------------------------------------------------
1421 #define ISPCTRL_CLKS_MASK (ISPCTRL_H3A_CLK_EN | \
1422 ISPCTRL_HIST_CLK_EN | \
1423 ISPCTRL_RSZ_CLK_EN | \
1424 (ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN) | \
1425 (ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN))
1427 static void __isp_subclk_update(struct isp_device *isp)
1431 /* AEWB and AF share the same clock. */
1432 if (isp->subclk_resources &
1433 (OMAP3_ISP_SUBCLK_AEWB | OMAP3_ISP_SUBCLK_AF))
1434 clk |= ISPCTRL_H3A_CLK_EN;
1436 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_HIST)
1437 clk |= ISPCTRL_HIST_CLK_EN;
1439 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_RESIZER)
1440 clk |= ISPCTRL_RSZ_CLK_EN;
1442 /* NOTE: For CCDC & Preview submodules, we need to affect internal
1445 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_CCDC)
1446 clk |= ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN;
1448 if (isp->subclk_resources & OMAP3_ISP_SUBCLK_PREVIEW)
1449 clk |= ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN;
1451 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_MAIN, ISP_CTRL,
1452 ISPCTRL_CLKS_MASK, clk);
1455 void omap3isp_subclk_enable(struct isp_device *isp,
1456 enum isp_subclk_resource res)
1458 isp->subclk_resources |= res;
1460 __isp_subclk_update(isp);
1463 void omap3isp_subclk_disable(struct isp_device *isp,
1464 enum isp_subclk_resource res)
1466 isp->subclk_resources &= ~res;
1468 __isp_subclk_update(isp);
1472 * isp_enable_clocks - Enable ISP clocks
1473 * @isp: OMAP3 ISP device
1475 * Return 0 if successful, or clk_prepare_enable return value if any of them
1478 static int isp_enable_clocks(struct isp_device *isp)
1483 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_ICK]);
1485 dev_err(isp->dev, "failed to enable cam_ick clock\n");
1486 goto out_clk_enable_ick;
1488 r = clk_set_rate(isp->clock[ISP_CLK_CAM_MCLK], CM_CAM_MCLK_HZ);
1490 dev_err(isp->dev, "clk_set_rate for cam_mclk failed\n");
1491 goto out_clk_enable_mclk;
1493 r = clk_prepare_enable(isp->clock[ISP_CLK_CAM_MCLK]);
1495 dev_err(isp->dev, "failed to enable cam_mclk clock\n");
1496 goto out_clk_enable_mclk;
1498 rate = clk_get_rate(isp->clock[ISP_CLK_CAM_MCLK]);
1499 if (rate != CM_CAM_MCLK_HZ)
1500 dev_warn(isp->dev, "unexpected cam_mclk rate:\n"
1502 " actual : %ld\n", CM_CAM_MCLK_HZ, rate);
1503 r = clk_prepare_enable(isp->clock[ISP_CLK_CSI2_FCK]);
1505 dev_err(isp->dev, "failed to enable csi2_fck clock\n");
1506 goto out_clk_enable_csi2_fclk;
1510 out_clk_enable_csi2_fclk:
1511 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
1512 out_clk_enable_mclk:
1513 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
1519 * isp_disable_clocks - Disable ISP clocks
1520 * @isp: OMAP3 ISP device
1522 static void isp_disable_clocks(struct isp_device *isp)
1524 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_ICK]);
1525 clk_disable_unprepare(isp->clock[ISP_CLK_CAM_MCLK]);
1526 clk_disable_unprepare(isp->clock[ISP_CLK_CSI2_FCK]);
1529 static const char *isp_clocks[] = {
1536 static int isp_get_clocks(struct isp_device *isp)
1541 for (i = 0; i < ARRAY_SIZE(isp_clocks); ++i) {
1542 clk = devm_clk_get(isp->dev, isp_clocks[i]);
1544 dev_err(isp->dev, "clk_get %s failed\n", isp_clocks[i]);
1545 return PTR_ERR(clk);
1548 isp->clock[i] = clk;
1555 * omap3isp_get - Acquire the ISP resource.
1557 * Initializes the clocks for the first acquire.
1559 * Increment the reference count on the ISP. If the first reference is taken,
1560 * enable clocks and power-up all submodules.
1562 * Return a pointer to the ISP device structure, or NULL if an error occurred.
1564 static struct isp_device *__omap3isp_get(struct isp_device *isp, bool irq)
1566 struct isp_device *__isp = isp;
1571 mutex_lock(&isp->isp_mutex);
1572 if (isp->ref_count > 0)
1575 if (isp_enable_clocks(isp) < 0) {
1580 /* We don't want to restore context before saving it! */
1581 if (isp->has_context)
1582 isp_restore_ctx(isp);
1585 isp_enable_interrupts(isp);
1590 mutex_unlock(&isp->isp_mutex);
1595 struct isp_device *omap3isp_get(struct isp_device *isp)
1597 return __omap3isp_get(isp, true);
1601 * omap3isp_put - Release the ISP
1603 * Decrement the reference count on the ISP. If the last reference is released,
1604 * power-down all submodules, disable clocks and free temporary buffers.
1606 void omap3isp_put(struct isp_device *isp)
1611 mutex_lock(&isp->isp_mutex);
1612 BUG_ON(isp->ref_count == 0);
1613 if (--isp->ref_count == 0) {
1614 isp_disable_interrupts(isp);
1617 isp->has_context = 1;
1619 /* Reset the ISP if an entity has failed to stop. This is the
1620 * only way to recover from such conditions.
1624 isp_disable_clocks(isp);
1626 mutex_unlock(&isp->isp_mutex);
1629 /* --------------------------------------------------------------------------
1630 * Platform device driver
1634 * omap3isp_print_status - Prints the values of the ISP Control Module registers
1635 * @isp: OMAP3 ISP device
1637 #define ISP_PRINT_REGISTER(isp, name)\
1638 dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
1639 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_##name))
1640 #define SBL_PRINT_REGISTER(isp, name)\
1641 dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
1642 isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_##name))
1644 void omap3isp_print_status(struct isp_device *isp)
1646 dev_dbg(isp->dev, "-------------ISP Register dump--------------\n");
1648 ISP_PRINT_REGISTER(isp, SYSCONFIG);
1649 ISP_PRINT_REGISTER(isp, SYSSTATUS);
1650 ISP_PRINT_REGISTER(isp, IRQ0ENABLE);
1651 ISP_PRINT_REGISTER(isp, IRQ0STATUS);
1652 ISP_PRINT_REGISTER(isp, TCTRL_GRESET_LENGTH);
1653 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_REPLAY);
1654 ISP_PRINT_REGISTER(isp, CTRL);
1655 ISP_PRINT_REGISTER(isp, TCTRL_CTRL);
1656 ISP_PRINT_REGISTER(isp, TCTRL_FRAME);
1657 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_DELAY);
1658 ISP_PRINT_REGISTER(isp, TCTRL_STRB_DELAY);
1659 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_DELAY);
1660 ISP_PRINT_REGISTER(isp, TCTRL_PSTRB_LENGTH);
1661 ISP_PRINT_REGISTER(isp, TCTRL_STRB_LENGTH);
1662 ISP_PRINT_REGISTER(isp, TCTRL_SHUT_LENGTH);
1664 SBL_PRINT_REGISTER(isp, PCR);
1665 SBL_PRINT_REGISTER(isp, SDR_REQ_EXP);
1667 dev_dbg(isp->dev, "--------------------------------------------\n");
1673 * Power management support.
1675 * As the ISP can't properly handle an input video stream interruption on a non
1676 * frame boundary, the ISP pipelines need to be stopped before sensors get
1677 * suspended. However, as suspending the sensors can require a running clock,
1678 * which can be provided by the ISP, the ISP can't be completely suspended
1679 * before the sensor.
1681 * To solve this problem power management support is split into prepare/complete
1682 * and suspend/resume operations. The pipelines are stopped in prepare() and the
1683 * ISP clocks get disabled in suspend(). Similarly, the clocks are reenabled in
1684 * resume(), and the the pipelines are restarted in complete().
1686 * TODO: PM dependencies between the ISP and sensors are not modelled explicitly
1689 static int isp_pm_prepare(struct device *dev)
1691 struct isp_device *isp = dev_get_drvdata(dev);
1694 WARN_ON(mutex_is_locked(&isp->isp_mutex));
1696 if (isp->ref_count == 0)
1699 reset = isp_suspend_modules(isp);
1700 isp_disable_interrupts(isp);
1708 static int isp_pm_suspend(struct device *dev)
1710 struct isp_device *isp = dev_get_drvdata(dev);
1712 WARN_ON(mutex_is_locked(&isp->isp_mutex));
1715 isp_disable_clocks(isp);
1720 static int isp_pm_resume(struct device *dev)
1722 struct isp_device *isp = dev_get_drvdata(dev);
1724 if (isp->ref_count == 0)
1727 return isp_enable_clocks(isp);
1730 static void isp_pm_complete(struct device *dev)
1732 struct isp_device *isp = dev_get_drvdata(dev);
1734 if (isp->ref_count == 0)
1737 isp_restore_ctx(isp);
1738 isp_enable_interrupts(isp);
1739 isp_resume_modules(isp);
1744 #define isp_pm_prepare NULL
1745 #define isp_pm_suspend NULL
1746 #define isp_pm_resume NULL
1747 #define isp_pm_complete NULL
1749 #endif /* CONFIG_PM */
1751 static void isp_unregister_entities(struct isp_device *isp)
1753 omap3isp_csi2_unregister_entities(&isp->isp_csi2a);
1754 omap3isp_ccp2_unregister_entities(&isp->isp_ccp2);
1755 omap3isp_ccdc_unregister_entities(&isp->isp_ccdc);
1756 omap3isp_preview_unregister_entities(&isp->isp_prev);
1757 omap3isp_resizer_unregister_entities(&isp->isp_res);
1758 omap3isp_stat_unregister_entities(&isp->isp_aewb);
1759 omap3isp_stat_unregister_entities(&isp->isp_af);
1760 omap3isp_stat_unregister_entities(&isp->isp_hist);
1762 v4l2_device_unregister(&isp->v4l2_dev);
1763 media_device_unregister(&isp->media_dev);
1767 * isp_register_subdev_group - Register a group of subdevices
1768 * @isp: OMAP3 ISP device
1769 * @board_info: I2C subdevs board information array
1771 * Register all I2C subdevices in the board_info array. The array must be
1772 * terminated by a NULL entry, and the first entry must be the sensor.
1774 * Return a pointer to the sensor media entity if it has been successfully
1775 * registered, or NULL otherwise.
1777 static struct v4l2_subdev *
1778 isp_register_subdev_group(struct isp_device *isp,
1779 struct isp_subdev_i2c_board_info *board_info)
1781 struct v4l2_subdev *sensor = NULL;
1784 if (board_info->board_info == NULL)
1787 for (first = 1; board_info->board_info; ++board_info, first = 0) {
1788 struct v4l2_subdev *subdev;
1789 struct i2c_adapter *adapter;
1791 adapter = i2c_get_adapter(board_info->i2c_adapter_id);
1792 if (adapter == NULL) {
1793 dev_err(isp->dev, "%s: Unable to get I2C adapter %d for "
1794 "device %s\n", __func__,
1795 board_info->i2c_adapter_id,
1796 board_info->board_info->type);
1800 subdev = v4l2_i2c_new_subdev_board(&isp->v4l2_dev, adapter,
1801 board_info->board_info, NULL);
1802 if (subdev == NULL) {
1803 dev_err(isp->dev, "%s: Unable to register subdev %s\n",
1804 __func__, board_info->board_info->type);
1815 static int isp_register_entities(struct isp_device *isp)
1817 struct isp_platform_data *pdata = isp->pdata;
1818 struct isp_v4l2_subdevs_group *subdevs;
1821 isp->media_dev.dev = isp->dev;
1822 strlcpy(isp->media_dev.model, "TI OMAP3 ISP",
1823 sizeof(isp->media_dev.model));
1824 isp->media_dev.hw_revision = isp->revision;
1825 isp->media_dev.link_notify = isp_pipeline_link_notify;
1826 ret = media_device_register(&isp->media_dev);
1828 dev_err(isp->dev, "%s: Media device registration failed (%d)\n",
1833 isp->v4l2_dev.mdev = &isp->media_dev;
1834 ret = v4l2_device_register(isp->dev, &isp->v4l2_dev);
1836 dev_err(isp->dev, "%s: V4L2 device registration failed (%d)\n",
1841 /* Register internal entities */
1842 ret = omap3isp_ccp2_register_entities(&isp->isp_ccp2, &isp->v4l2_dev);
1846 ret = omap3isp_csi2_register_entities(&isp->isp_csi2a, &isp->v4l2_dev);
1850 ret = omap3isp_ccdc_register_entities(&isp->isp_ccdc, &isp->v4l2_dev);
1854 ret = omap3isp_preview_register_entities(&isp->isp_prev,
1859 ret = omap3isp_resizer_register_entities(&isp->isp_res, &isp->v4l2_dev);
1863 ret = omap3isp_stat_register_entities(&isp->isp_aewb, &isp->v4l2_dev);
1867 ret = omap3isp_stat_register_entities(&isp->isp_af, &isp->v4l2_dev);
1871 ret = omap3isp_stat_register_entities(&isp->isp_hist, &isp->v4l2_dev);
1875 /* Register external entities */
1876 for (subdevs = pdata->subdevs; subdevs && subdevs->subdevs; ++subdevs) {
1877 struct v4l2_subdev *sensor;
1878 struct media_entity *input;
1883 sensor = isp_register_subdev_group(isp, subdevs->subdevs);
1887 sensor->host_priv = subdevs;
1889 /* Connect the sensor to the correct interface module. Parallel
1890 * sensors are connected directly to the CCDC, while serial
1891 * sensors are connected to the CSI2a, CCP2b or CSI2c receiver
1892 * through CSIPHY1 or CSIPHY2.
1894 switch (subdevs->interface) {
1895 case ISP_INTERFACE_PARALLEL:
1896 input = &isp->isp_ccdc.subdev.entity;
1897 pad = CCDC_PAD_SINK;
1901 case ISP_INTERFACE_CSI2A_PHY2:
1902 input = &isp->isp_csi2a.subdev.entity;
1903 pad = CSI2_PAD_SINK;
1904 flags = MEDIA_LNK_FL_IMMUTABLE
1905 | MEDIA_LNK_FL_ENABLED;
1908 case ISP_INTERFACE_CCP2B_PHY1:
1909 case ISP_INTERFACE_CCP2B_PHY2:
1910 input = &isp->isp_ccp2.subdev.entity;
1911 pad = CCP2_PAD_SINK;
1915 case ISP_INTERFACE_CSI2C_PHY1:
1916 input = &isp->isp_csi2c.subdev.entity;
1917 pad = CSI2_PAD_SINK;
1918 flags = MEDIA_LNK_FL_IMMUTABLE
1919 | MEDIA_LNK_FL_ENABLED;
1923 dev_err(isp->dev, "%s: invalid interface type %u\n",
1924 __func__, subdevs->interface);
1929 for (i = 0; i < sensor->entity.num_pads; i++) {
1930 if (sensor->entity.pads[i].flags & MEDIA_PAD_FL_SOURCE)
1933 if (i == sensor->entity.num_pads) {
1935 "%s: no source pad in external entity\n",
1941 ret = media_entity_create_link(&sensor->entity, i, input, pad,
1947 ret = v4l2_device_register_subdev_nodes(&isp->v4l2_dev);
1951 isp_unregister_entities(isp);
1956 static void isp_cleanup_modules(struct isp_device *isp)
1958 omap3isp_h3a_aewb_cleanup(isp);
1959 omap3isp_h3a_af_cleanup(isp);
1960 omap3isp_hist_cleanup(isp);
1961 omap3isp_resizer_cleanup(isp);
1962 omap3isp_preview_cleanup(isp);
1963 omap3isp_ccdc_cleanup(isp);
1964 omap3isp_ccp2_cleanup(isp);
1965 omap3isp_csi2_cleanup(isp);
1968 static int isp_initialize_modules(struct isp_device *isp)
1972 ret = omap3isp_csiphy_init(isp);
1974 dev_err(isp->dev, "CSI PHY initialization failed\n");
1978 ret = omap3isp_csi2_init(isp);
1980 dev_err(isp->dev, "CSI2 initialization failed\n");
1984 ret = omap3isp_ccp2_init(isp);
1986 dev_err(isp->dev, "CCP2 initialization failed\n");
1990 ret = omap3isp_ccdc_init(isp);
1992 dev_err(isp->dev, "CCDC initialization failed\n");
1996 ret = omap3isp_preview_init(isp);
1998 dev_err(isp->dev, "Preview initialization failed\n");
2002 ret = omap3isp_resizer_init(isp);
2004 dev_err(isp->dev, "Resizer initialization failed\n");
2008 ret = omap3isp_hist_init(isp);
2010 dev_err(isp->dev, "Histogram initialization failed\n");
2014 ret = omap3isp_h3a_aewb_init(isp);
2016 dev_err(isp->dev, "H3A AEWB initialization failed\n");
2017 goto error_h3a_aewb;
2020 ret = omap3isp_h3a_af_init(isp);
2022 dev_err(isp->dev, "H3A AF initialization failed\n");
2026 /* Connect the submodules. */
2027 ret = media_entity_create_link(
2028 &isp->isp_csi2a.subdev.entity, CSI2_PAD_SOURCE,
2029 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
2033 ret = media_entity_create_link(
2034 &isp->isp_ccp2.subdev.entity, CCP2_PAD_SOURCE,
2035 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SINK, 0);
2039 ret = media_entity_create_link(
2040 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2041 &isp->isp_prev.subdev.entity, PREV_PAD_SINK, 0);
2045 ret = media_entity_create_link(
2046 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_OF,
2047 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
2051 ret = media_entity_create_link(
2052 &isp->isp_prev.subdev.entity, PREV_PAD_SOURCE,
2053 &isp->isp_res.subdev.entity, RESZ_PAD_SINK, 0);
2057 ret = media_entity_create_link(
2058 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2059 &isp->isp_aewb.subdev.entity, 0,
2060 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
2064 ret = media_entity_create_link(
2065 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2066 &isp->isp_af.subdev.entity, 0,
2067 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
2071 ret = media_entity_create_link(
2072 &isp->isp_ccdc.subdev.entity, CCDC_PAD_SOURCE_VP,
2073 &isp->isp_hist.subdev.entity, 0,
2074 MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE);
2081 omap3isp_h3a_af_cleanup(isp);
2083 omap3isp_h3a_aewb_cleanup(isp);
2085 omap3isp_hist_cleanup(isp);
2087 omap3isp_resizer_cleanup(isp);
2089 omap3isp_preview_cleanup(isp);
2091 omap3isp_ccdc_cleanup(isp);
2093 omap3isp_ccp2_cleanup(isp);
2095 omap3isp_csi2_cleanup(isp);
2102 * isp_remove - Remove ISP platform device
2103 * @pdev: Pointer to ISP platform device
2107 static int isp_remove(struct platform_device *pdev)
2109 struct isp_device *isp = platform_get_drvdata(pdev);
2111 isp_unregister_entities(isp);
2112 isp_cleanup_modules(isp);
2113 isp_xclk_cleanup(isp);
2115 __omap3isp_get(isp, false);
2116 iommu_detach_device(isp->domain, &pdev->dev);
2117 iommu_domain_free(isp->domain);
2124 static int isp_map_mem_resource(struct platform_device *pdev,
2125 struct isp_device *isp,
2126 enum isp_mem_resources res)
2128 struct resource *mem;
2130 /* request the mem region for the camera registers */
2132 mem = platform_get_resource(pdev, IORESOURCE_MEM, res);
2134 /* map the region */
2135 isp->mmio_base[res] = devm_ioremap_resource(isp->dev, mem);
2136 if (IS_ERR(isp->mmio_base[res]))
2137 return PTR_ERR(isp->mmio_base[res]);
2139 isp->mmio_base_phys[res] = mem->start;
2145 * isp_probe - Probe ISP platform device
2146 * @pdev: Pointer to ISP platform device
2148 * Returns 0 if successful,
2149 * -ENOMEM if no memory available,
2150 * -ENODEV if no platform device resources found
2151 * or no space for remapping registers,
2152 * -EINVAL if couldn't install ISR,
2153 * or clk_get return error value.
2155 static int isp_probe(struct platform_device *pdev)
2157 struct isp_platform_data *pdata = pdev->dev.platform_data;
2158 struct isp_device *isp;
2165 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL);
2167 dev_err(&pdev->dev, "could not allocate memory\n");
2171 isp->autoidle = autoidle;
2173 mutex_init(&isp->isp_mutex);
2174 spin_lock_init(&isp->stat_lock);
2176 isp->dev = &pdev->dev;
2180 ret = dma_coerce_mask_and_coherent(isp->dev, DMA_BIT_MASK(32));
2184 platform_set_drvdata(pdev, isp);
2187 isp->isp_csiphy1.vdd = devm_regulator_get(&pdev->dev, "VDD_CSIPHY1");
2188 isp->isp_csiphy2.vdd = devm_regulator_get(&pdev->dev, "VDD_CSIPHY2");
2192 * The ISP clock tree is revision-dependent. We thus need to enable ICLK
2193 * manually to read the revision before calling __omap3isp_get().
2195 ret = isp_map_mem_resource(pdev, isp, OMAP3_ISP_IOMEM_MAIN);
2199 ret = isp_get_clocks(isp);
2203 ret = clk_enable(isp->clock[ISP_CLK_CAM_ICK]);
2207 isp->revision = isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_REVISION);
2208 dev_info(isp->dev, "Revision %d.%d found\n",
2209 (isp->revision & 0xf0) >> 4, isp->revision & 0x0f);
2211 clk_disable(isp->clock[ISP_CLK_CAM_ICK]);
2213 if (__omap3isp_get(isp, false) == NULL) {
2218 ret = isp_reset(isp);
2222 ret = isp_xclk_init(isp);
2226 /* Memory resources */
2227 for (m = 0; m < ARRAY_SIZE(isp_res_maps); m++)
2228 if (isp->revision == isp_res_maps[m].isp_rev)
2231 if (m == ARRAY_SIZE(isp_res_maps)) {
2232 dev_err(isp->dev, "No resource map found for ISP rev %d.%d\n",
2233 (isp->revision & 0xf0) >> 4, isp->revision & 0xf);
2238 for (i = 1; i < OMAP3_ISP_IOMEM_LAST; i++) {
2239 if (isp_res_maps[m].map & 1 << i) {
2240 ret = isp_map_mem_resource(pdev, isp, i);
2246 isp->domain = iommu_domain_alloc(pdev->dev.bus);
2248 dev_err(isp->dev, "can't alloc iommu domain\n");
2253 ret = iommu_attach_device(isp->domain, &pdev->dev);
2255 dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret);
2256 ret = -EPROBE_DEFER;
2261 isp->irq_num = platform_get_irq(pdev, 0);
2262 if (isp->irq_num <= 0) {
2263 dev_err(isp->dev, "No IRQ resource\n");
2268 if (devm_request_irq(isp->dev, isp->irq_num, isp_isr, IRQF_SHARED,
2269 "OMAP3 ISP", isp)) {
2270 dev_err(isp->dev, "Unable to request IRQ\n");
2276 ret = isp_initialize_modules(isp);
2280 ret = isp_register_entities(isp);
2284 isp_core_init(isp, 1);
2290 isp_cleanup_modules(isp);
2292 iommu_detach_device(isp->domain, &pdev->dev);
2294 iommu_domain_free(isp->domain);
2297 isp_xclk_cleanup(isp);
2300 mutex_destroy(&isp->isp_mutex);
2305 static const struct dev_pm_ops omap3isp_pm_ops = {
2306 .prepare = isp_pm_prepare,
2307 .suspend = isp_pm_suspend,
2308 .resume = isp_pm_resume,
2309 .complete = isp_pm_complete,
2312 static struct platform_device_id omap3isp_id_table[] = {
2316 MODULE_DEVICE_TABLE(platform, omap3isp_id_table);
2318 static struct platform_driver omap3isp_driver = {
2320 .remove = isp_remove,
2321 .id_table = omap3isp_id_table,
2323 .owner = THIS_MODULE,
2325 .pm = &omap3isp_pm_ops,
2329 module_platform_driver(omap3isp_driver);
2331 MODULE_AUTHOR("Nokia Corporation");
2332 MODULE_DESCRIPTION("TI OMAP3 ISP driver");
2333 MODULE_LICENSE("GPL");
2334 MODULE_VERSION(ISP_VIDEO_DRIVER_VERSION);