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.
45 #include <asm/cacheflush.h>
47 #include <linux/clk.h>
48 #include <linux/clkdev.h>
49 #include <linux/delay.h>
50 #include <linux/device.h>
51 #include <linux/dma-mapping.h>
52 #include <linux/i2c.h>
53 #include <linux/interrupt.h>
54 #include <linux/module.h>
55 #include <linux/omap-iommu.h>
56 #include <linux/platform_device.h>
57 #include <linux/regulator/consumer.h>
58 #include <linux/slab.h>
59 #include <linux/sched.h>
60 #include <linux/vmalloc.h>
62 #include <asm/dma-iommu.h>
64 #include <media/v4l2-common.h>
65 #include <media/v4l2-device.h>
70 #include "isppreview.h"
71 #include "ispresizer.h"
77 static unsigned int autoidle
;
78 module_param(autoidle
, int, 0444);
79 MODULE_PARM_DESC(autoidle
, "Enable OMAP3ISP AUTOIDLE support");
81 static void isp_save_ctx(struct isp_device
*isp
);
83 static void isp_restore_ctx(struct isp_device
*isp
);
85 static const struct isp_res_mapping isp_res_maps
[] = {
87 .isp_rev
= ISP_REVISION_2_0
,
88 .map
= 1 << OMAP3_ISP_IOMEM_MAIN
|
89 1 << OMAP3_ISP_IOMEM_CCP2
|
90 1 << OMAP3_ISP_IOMEM_CCDC
|
91 1 << OMAP3_ISP_IOMEM_HIST
|
92 1 << OMAP3_ISP_IOMEM_H3A
|
93 1 << OMAP3_ISP_IOMEM_PREV
|
94 1 << OMAP3_ISP_IOMEM_RESZ
|
95 1 << OMAP3_ISP_IOMEM_SBL
|
96 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1
|
97 1 << OMAP3_ISP_IOMEM_CSIPHY2
|
98 1 << OMAP3_ISP_IOMEM_343X_CONTROL_CSIRXFE
,
101 .isp_rev
= ISP_REVISION_15_0
,
102 .map
= 1 << OMAP3_ISP_IOMEM_MAIN
|
103 1 << OMAP3_ISP_IOMEM_CCP2
|
104 1 << OMAP3_ISP_IOMEM_CCDC
|
105 1 << OMAP3_ISP_IOMEM_HIST
|
106 1 << OMAP3_ISP_IOMEM_H3A
|
107 1 << OMAP3_ISP_IOMEM_PREV
|
108 1 << OMAP3_ISP_IOMEM_RESZ
|
109 1 << OMAP3_ISP_IOMEM_SBL
|
110 1 << OMAP3_ISP_IOMEM_CSI2A_REGS1
|
111 1 << OMAP3_ISP_IOMEM_CSIPHY2
|
112 1 << OMAP3_ISP_IOMEM_CSI2A_REGS2
|
113 1 << OMAP3_ISP_IOMEM_CSI2C_REGS1
|
114 1 << OMAP3_ISP_IOMEM_CSIPHY1
|
115 1 << OMAP3_ISP_IOMEM_CSI2C_REGS2
|
116 1 << OMAP3_ISP_IOMEM_3630_CONTROL_CAMERA_PHY_CTRL
,
120 /* Structure for saving/restoring ISP module registers */
121 static struct isp_reg isp_reg_list
[] = {
122 {OMAP3_ISP_IOMEM_MAIN
, ISP_SYSCONFIG
, 0},
123 {OMAP3_ISP_IOMEM_MAIN
, ISP_CTRL
, 0},
124 {OMAP3_ISP_IOMEM_MAIN
, ISP_TCTRL_CTRL
, 0},
129 * omap3isp_flush - Post pending L3 bus writes by doing a register readback
130 * @isp: OMAP3 ISP device
132 * In order to force posting of pending writes, we need to write and
133 * readback the same register, in this case the revision register.
135 * See this link for reference:
136 * http://www.mail-archive.com/linux-omap@vger.kernel.org/msg08149.html
138 void omap3isp_flush(struct isp_device
*isp
)
140 isp_reg_writel(isp
, 0, OMAP3_ISP_IOMEM_MAIN
, ISP_REVISION
);
141 isp_reg_readl(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_REVISION
);
144 /* -----------------------------------------------------------------------------
148 #define to_isp_xclk(_hw) container_of(_hw, struct isp_xclk, hw)
150 static void isp_xclk_update(struct isp_xclk
*xclk
, u32 divider
)
154 isp_reg_clr_set(xclk
->isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_TCTRL_CTRL
,
155 ISPTCTRL_CTRL_DIVA_MASK
,
156 divider
<< ISPTCTRL_CTRL_DIVA_SHIFT
);
159 isp_reg_clr_set(xclk
->isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_TCTRL_CTRL
,
160 ISPTCTRL_CTRL_DIVB_MASK
,
161 divider
<< ISPTCTRL_CTRL_DIVB_SHIFT
);
166 static int isp_xclk_prepare(struct clk_hw
*hw
)
168 struct isp_xclk
*xclk
= to_isp_xclk(hw
);
170 omap3isp_get(xclk
->isp
);
175 static void isp_xclk_unprepare(struct clk_hw
*hw
)
177 struct isp_xclk
*xclk
= to_isp_xclk(hw
);
179 omap3isp_put(xclk
->isp
);
182 static int isp_xclk_enable(struct clk_hw
*hw
)
184 struct isp_xclk
*xclk
= to_isp_xclk(hw
);
187 spin_lock_irqsave(&xclk
->lock
, flags
);
188 isp_xclk_update(xclk
, xclk
->divider
);
189 xclk
->enabled
= true;
190 spin_unlock_irqrestore(&xclk
->lock
, flags
);
195 static void isp_xclk_disable(struct clk_hw
*hw
)
197 struct isp_xclk
*xclk
= to_isp_xclk(hw
);
200 spin_lock_irqsave(&xclk
->lock
, flags
);
201 isp_xclk_update(xclk
, 0);
202 xclk
->enabled
= false;
203 spin_unlock_irqrestore(&xclk
->lock
, flags
);
206 static unsigned long isp_xclk_recalc_rate(struct clk_hw
*hw
,
207 unsigned long parent_rate
)
209 struct isp_xclk
*xclk
= to_isp_xclk(hw
);
211 return parent_rate
/ xclk
->divider
;
214 static u32
isp_xclk_calc_divider(unsigned long *rate
, unsigned long parent_rate
)
218 if (*rate
>= parent_rate
) {
220 return ISPTCTRL_CTRL_DIV_BYPASS
;
226 divider
= DIV_ROUND_CLOSEST(parent_rate
, *rate
);
227 if (divider
>= ISPTCTRL_CTRL_DIV_BYPASS
)
228 divider
= ISPTCTRL_CTRL_DIV_BYPASS
- 1;
230 *rate
= parent_rate
/ divider
;
234 static long isp_xclk_round_rate(struct clk_hw
*hw
, unsigned long rate
,
235 unsigned long *parent_rate
)
237 isp_xclk_calc_divider(&rate
, *parent_rate
);
241 static int isp_xclk_set_rate(struct clk_hw
*hw
, unsigned long rate
,
242 unsigned long parent_rate
)
244 struct isp_xclk
*xclk
= to_isp_xclk(hw
);
248 divider
= isp_xclk_calc_divider(&rate
, parent_rate
);
250 spin_lock_irqsave(&xclk
->lock
, flags
);
252 xclk
->divider
= divider
;
254 isp_xclk_update(xclk
, divider
);
256 spin_unlock_irqrestore(&xclk
->lock
, flags
);
258 dev_dbg(xclk
->isp
->dev
, "%s: cam_xclk%c set to %lu Hz (div %u)\n",
259 __func__
, xclk
->id
== ISP_XCLK_A
? 'a' : 'b', rate
, divider
);
263 static const struct clk_ops isp_xclk_ops
= {
264 .prepare
= isp_xclk_prepare
,
265 .unprepare
= isp_xclk_unprepare
,
266 .enable
= isp_xclk_enable
,
267 .disable
= isp_xclk_disable
,
268 .recalc_rate
= isp_xclk_recalc_rate
,
269 .round_rate
= isp_xclk_round_rate
,
270 .set_rate
= isp_xclk_set_rate
,
273 static const char *isp_xclk_parent_name
= "cam_mclk";
275 static const struct clk_init_data isp_xclk_init_data
= {
277 .ops
= &isp_xclk_ops
,
278 .parent_names
= &isp_xclk_parent_name
,
282 static int isp_xclk_init(struct isp_device
*isp
)
284 struct isp_platform_data
*pdata
= isp
->pdata
;
285 struct clk_init_data init
;
288 for (i
= 0; i
< ARRAY_SIZE(isp
->xclks
); ++i
)
289 isp
->xclks
[i
].clk
= ERR_PTR(-EINVAL
);
291 for (i
= 0; i
< ARRAY_SIZE(isp
->xclks
); ++i
) {
292 struct isp_xclk
*xclk
= &isp
->xclks
[i
];
295 xclk
->id
= i
== 0 ? ISP_XCLK_A
: ISP_XCLK_B
;
297 spin_lock_init(&xclk
->lock
);
299 init
.name
= i
== 0 ? "cam_xclka" : "cam_xclkb";
300 init
.ops
= &isp_xclk_ops
;
301 init
.parent_names
= &isp_xclk_parent_name
;
302 init
.num_parents
= 1;
304 xclk
->hw
.init
= &init
;
306 * The first argument is NULL in order to avoid circular
307 * reference, as this driver takes reference on the
308 * sensor subdevice modules and the sensors would take
309 * reference on this module through clk_get().
311 xclk
->clk
= clk_register(NULL
, &xclk
->hw
);
312 if (IS_ERR(xclk
->clk
))
313 return PTR_ERR(xclk
->clk
);
315 if (pdata
->xclks
[i
].con_id
== NULL
&&
316 pdata
->xclks
[i
].dev_id
== NULL
)
319 xclk
->lookup
= kzalloc(sizeof(*xclk
->lookup
), GFP_KERNEL
);
320 if (xclk
->lookup
== NULL
)
323 xclk
->lookup
->con_id
= pdata
->xclks
[i
].con_id
;
324 xclk
->lookup
->dev_id
= pdata
->xclks
[i
].dev_id
;
325 xclk
->lookup
->clk
= xclk
->clk
;
327 clkdev_add(xclk
->lookup
);
333 static void isp_xclk_cleanup(struct isp_device
*isp
)
337 for (i
= 0; i
< ARRAY_SIZE(isp
->xclks
); ++i
) {
338 struct isp_xclk
*xclk
= &isp
->xclks
[i
];
340 if (!IS_ERR(xclk
->clk
))
341 clk_unregister(xclk
->clk
);
344 clkdev_drop(xclk
->lookup
);
348 /* -----------------------------------------------------------------------------
353 * isp_enable_interrupts - Enable ISP interrupts.
354 * @isp: OMAP3 ISP device
356 static void isp_enable_interrupts(struct isp_device
*isp
)
358 static const u32 irq
= IRQ0ENABLE_CSIA_IRQ
359 | IRQ0ENABLE_CSIB_IRQ
360 | IRQ0ENABLE_CCDC_LSC_PREF_ERR_IRQ
361 | IRQ0ENABLE_CCDC_LSC_DONE_IRQ
362 | IRQ0ENABLE_CCDC_VD0_IRQ
363 | IRQ0ENABLE_CCDC_VD1_IRQ
364 | IRQ0ENABLE_HS_VS_IRQ
365 | IRQ0ENABLE_HIST_DONE_IRQ
366 | IRQ0ENABLE_H3A_AWB_DONE_IRQ
367 | IRQ0ENABLE_H3A_AF_DONE_IRQ
368 | IRQ0ENABLE_PRV_DONE_IRQ
369 | IRQ0ENABLE_RSZ_DONE_IRQ
;
371 isp_reg_writel(isp
, irq
, OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0STATUS
);
372 isp_reg_writel(isp
, irq
, OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0ENABLE
);
376 * isp_disable_interrupts - Disable ISP interrupts.
377 * @isp: OMAP3 ISP device
379 static void isp_disable_interrupts(struct isp_device
*isp
)
381 isp_reg_writel(isp
, 0, OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0ENABLE
);
385 * isp_core_init - ISP core settings
386 * @isp: OMAP3 ISP device
387 * @idle: Consider idle state.
389 * Set the power settings for the ISP and SBL bus and configure the HS/VS
392 * We need to configure the HS/VS interrupt source before interrupts get
393 * enabled, as the sensor might be free-running and the ISP default setting
394 * (HS edge) would put an unnecessary burden on the CPU.
396 static void isp_core_init(struct isp_device
*isp
, int idle
)
399 ((idle
? ISP_SYSCONFIG_MIDLEMODE_SMARTSTANDBY
:
400 ISP_SYSCONFIG_MIDLEMODE_FORCESTANDBY
) <<
401 ISP_SYSCONFIG_MIDLEMODE_SHIFT
) |
402 ((isp
->revision
== ISP_REVISION_15_0
) ?
403 ISP_SYSCONFIG_AUTOIDLE
: 0),
404 OMAP3_ISP_IOMEM_MAIN
, ISP_SYSCONFIG
);
407 (isp
->autoidle
? ISPCTRL_SBL_AUTOIDLE
: 0) |
408 ISPCTRL_SYNC_DETECT_VSRISE
,
409 OMAP3_ISP_IOMEM_MAIN
, ISP_CTRL
);
413 * Configure the bridge and lane shifter. Valid inputs are
415 * CCDC_INPUT_PARALLEL: Parallel interface
416 * CCDC_INPUT_CSI2A: CSI2a receiver
417 * CCDC_INPUT_CCP2B: CCP2b receiver
418 * CCDC_INPUT_CSI2C: CSI2c receiver
420 * The bridge and lane shifter are configured according to the selected input
421 * and the ISP platform data.
423 void omap3isp_configure_bridge(struct isp_device
*isp
,
424 enum ccdc_input_entity input
,
425 const struct isp_parallel_platform_data
*pdata
,
426 unsigned int shift
, unsigned int bridge
)
430 ispctrl_val
= isp_reg_readl(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_CTRL
);
431 ispctrl_val
&= ~ISPCTRL_SHIFT_MASK
;
432 ispctrl_val
&= ~ISPCTRL_PAR_CLK_POL_INV
;
433 ispctrl_val
&= ~ISPCTRL_PAR_SER_CLK_SEL_MASK
;
434 ispctrl_val
&= ~ISPCTRL_PAR_BRIDGE_MASK
;
435 ispctrl_val
|= bridge
;
438 case CCDC_INPUT_PARALLEL
:
439 ispctrl_val
|= ISPCTRL_PAR_SER_CLK_SEL_PARALLEL
;
440 ispctrl_val
|= pdata
->clk_pol
<< ISPCTRL_PAR_CLK_POL_SHIFT
;
441 shift
+= pdata
->data_lane_shift
* 2;
444 case CCDC_INPUT_CSI2A
:
445 ispctrl_val
|= ISPCTRL_PAR_SER_CLK_SEL_CSIA
;
448 case CCDC_INPUT_CCP2B
:
449 ispctrl_val
|= ISPCTRL_PAR_SER_CLK_SEL_CSIB
;
452 case CCDC_INPUT_CSI2C
:
453 ispctrl_val
|= ISPCTRL_PAR_SER_CLK_SEL_CSIC
;
460 ispctrl_val
|= ((shift
/2) << ISPCTRL_SHIFT_SHIFT
) & ISPCTRL_SHIFT_MASK
;
462 isp_reg_writel(isp
, ispctrl_val
, OMAP3_ISP_IOMEM_MAIN
, ISP_CTRL
);
465 void omap3isp_hist_dma_done(struct isp_device
*isp
)
467 if (omap3isp_ccdc_busy(&isp
->isp_ccdc
) ||
468 omap3isp_stat_pcr_busy(&isp
->isp_hist
)) {
469 /* Histogram cannot be enabled in this frame anymore */
470 atomic_set(&isp
->isp_hist
.buf_err
, 1);
471 dev_dbg(isp
->dev
, "hist: Out of synchronization with "
472 "CCDC. Ignoring next buffer.\n");
476 static inline void isp_isr_dbg(struct isp_device
*isp
, u32 irqstatus
)
478 static const char *name
[] = {
497 "CCDC_LSC_PREFETCH_COMPLETED",
498 "CCDC_LSC_PREFETCH_ERROR",
514 dev_dbg(isp
->dev
, "ISP IRQ: ");
516 for (i
= 0; i
< ARRAY_SIZE(name
); i
++) {
517 if ((1 << i
) & irqstatus
)
518 printk(KERN_CONT
"%s ", name
[i
]);
520 printk(KERN_CONT
"\n");
523 static void isp_isr_sbl(struct isp_device
*isp
)
525 struct device
*dev
= isp
->dev
;
526 struct isp_pipeline
*pipe
;
530 * Handle shared buffer logic overflows for video buffers.
531 * ISPSBL_PCR_CCDCPRV_2_RSZ_OVF can be safely ignored.
533 sbl_pcr
= isp_reg_readl(isp
, OMAP3_ISP_IOMEM_SBL
, ISPSBL_PCR
);
534 isp_reg_writel(isp
, sbl_pcr
, OMAP3_ISP_IOMEM_SBL
, ISPSBL_PCR
);
535 sbl_pcr
&= ~ISPSBL_PCR_CCDCPRV_2_RSZ_OVF
;
538 dev_dbg(dev
, "SBL overflow (PCR = 0x%08x)\n", sbl_pcr
);
540 if (sbl_pcr
& ISPSBL_PCR_CSIB_WBL_OVF
) {
541 pipe
= to_isp_pipeline(&isp
->isp_ccp2
.subdev
.entity
);
546 if (sbl_pcr
& ISPSBL_PCR_CSIA_WBL_OVF
) {
547 pipe
= to_isp_pipeline(&isp
->isp_csi2a
.subdev
.entity
);
552 if (sbl_pcr
& ISPSBL_PCR_CCDC_WBL_OVF
) {
553 pipe
= to_isp_pipeline(&isp
->isp_ccdc
.subdev
.entity
);
558 if (sbl_pcr
& ISPSBL_PCR_PRV_WBL_OVF
) {
559 pipe
= to_isp_pipeline(&isp
->isp_prev
.subdev
.entity
);
564 if (sbl_pcr
& (ISPSBL_PCR_RSZ1_WBL_OVF
565 | ISPSBL_PCR_RSZ2_WBL_OVF
566 | ISPSBL_PCR_RSZ3_WBL_OVF
567 | ISPSBL_PCR_RSZ4_WBL_OVF
)) {
568 pipe
= to_isp_pipeline(&isp
->isp_res
.subdev
.entity
);
573 if (sbl_pcr
& ISPSBL_PCR_H3A_AF_WBL_OVF
)
574 omap3isp_stat_sbl_overflow(&isp
->isp_af
);
576 if (sbl_pcr
& ISPSBL_PCR_H3A_AEAWB_WBL_OVF
)
577 omap3isp_stat_sbl_overflow(&isp
->isp_aewb
);
581 * isp_isr - Interrupt Service Routine for Camera ISP module.
582 * @irq: Not used currently.
583 * @_isp: Pointer to the OMAP3 ISP device
585 * Handles the corresponding callback if plugged in.
587 static irqreturn_t
isp_isr(int irq
, void *_isp
)
589 static const u32 ccdc_events
= IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ
|
590 IRQ0STATUS_CCDC_LSC_DONE_IRQ
|
591 IRQ0STATUS_CCDC_VD0_IRQ
|
592 IRQ0STATUS_CCDC_VD1_IRQ
|
593 IRQ0STATUS_HS_VS_IRQ
;
594 struct isp_device
*isp
= _isp
;
597 irqstatus
= isp_reg_readl(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0STATUS
);
598 isp_reg_writel(isp
, irqstatus
, OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0STATUS
);
602 if (irqstatus
& IRQ0STATUS_CSIA_IRQ
)
603 omap3isp_csi2_isr(&isp
->isp_csi2a
);
605 if (irqstatus
& IRQ0STATUS_CSIB_IRQ
)
606 omap3isp_ccp2_isr(&isp
->isp_ccp2
);
608 if (irqstatus
& IRQ0STATUS_CCDC_VD0_IRQ
) {
609 if (isp
->isp_ccdc
.output
& CCDC_OUTPUT_PREVIEW
)
610 omap3isp_preview_isr_frame_sync(&isp
->isp_prev
);
611 if (isp
->isp_ccdc
.output
& CCDC_OUTPUT_RESIZER
)
612 omap3isp_resizer_isr_frame_sync(&isp
->isp_res
);
613 omap3isp_stat_isr_frame_sync(&isp
->isp_aewb
);
614 omap3isp_stat_isr_frame_sync(&isp
->isp_af
);
615 omap3isp_stat_isr_frame_sync(&isp
->isp_hist
);
618 if (irqstatus
& ccdc_events
)
619 omap3isp_ccdc_isr(&isp
->isp_ccdc
, irqstatus
& ccdc_events
);
621 if (irqstatus
& IRQ0STATUS_PRV_DONE_IRQ
) {
622 if (isp
->isp_prev
.output
& PREVIEW_OUTPUT_RESIZER
)
623 omap3isp_resizer_isr_frame_sync(&isp
->isp_res
);
624 omap3isp_preview_isr(&isp
->isp_prev
);
627 if (irqstatus
& IRQ0STATUS_RSZ_DONE_IRQ
)
628 omap3isp_resizer_isr(&isp
->isp_res
);
630 if (irqstatus
& IRQ0STATUS_H3A_AWB_DONE_IRQ
)
631 omap3isp_stat_isr(&isp
->isp_aewb
);
633 if (irqstatus
& IRQ0STATUS_H3A_AF_DONE_IRQ
)
634 omap3isp_stat_isr(&isp
->isp_af
);
636 if (irqstatus
& IRQ0STATUS_HIST_DONE_IRQ
)
637 omap3isp_stat_isr(&isp
->isp_hist
);
641 #if defined(DEBUG) && defined(ISP_ISR_DEBUG)
642 isp_isr_dbg(isp
, irqstatus
);
648 /* -----------------------------------------------------------------------------
649 * Pipeline power management
651 * Entities must be powered up when part of a pipeline that contains at least
652 * one open video device node.
654 * To achieve this use the entity use_count field to track the number of users.
655 * For entities corresponding to video device nodes the use_count field stores
656 * the users count of the node. For entities corresponding to subdevs the
657 * use_count field stores the total number of users of all video device nodes
660 * The omap3isp_pipeline_pm_use() function must be called in the open() and
661 * close() handlers of video device nodes. It increments or decrements the use
662 * count of all subdev entities in the pipeline.
664 * To react to link management on powered pipelines, the link setup notification
665 * callback updates the use count of all entities in the source and sink sides
670 * isp_pipeline_pm_use_count - Count the number of users of a pipeline
671 * @entity: The entity
673 * Return the total number of users of all video device nodes in the pipeline.
675 static int isp_pipeline_pm_use_count(struct media_entity
*entity
)
677 struct media_entity_graph graph
;
680 media_entity_graph_walk_start(&graph
, entity
);
682 while ((entity
= media_entity_graph_walk_next(&graph
))) {
683 if (media_entity_type(entity
) == MEDIA_ENT_T_DEVNODE
)
684 use
+= entity
->use_count
;
691 * isp_pipeline_pm_power_one - Apply power change to an entity
692 * @entity: The entity
693 * @change: Use count change
695 * Change the entity use count by @change. If the entity is a subdev update its
696 * power state by calling the core::s_power operation when the use count goes
697 * from 0 to != 0 or from != 0 to 0.
699 * Return 0 on success or a negative error code on failure.
701 static int isp_pipeline_pm_power_one(struct media_entity
*entity
, int change
)
703 struct v4l2_subdev
*subdev
;
706 subdev
= media_entity_type(entity
) == MEDIA_ENT_T_V4L2_SUBDEV
707 ? media_entity_to_v4l2_subdev(entity
) : NULL
;
709 if (entity
->use_count
== 0 && change
> 0 && subdev
!= NULL
) {
710 ret
= v4l2_subdev_call(subdev
, core
, s_power
, 1);
711 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
715 entity
->use_count
+= change
;
716 WARN_ON(entity
->use_count
< 0);
718 if (entity
->use_count
== 0 && change
< 0 && subdev
!= NULL
)
719 v4l2_subdev_call(subdev
, core
, s_power
, 0);
725 * isp_pipeline_pm_power - Apply power change to all entities in a pipeline
726 * @entity: The entity
727 * @change: Use count change
729 * Walk the pipeline to update the use count and the power state of all non-node
732 * Return 0 on success or a negative error code on failure.
734 static int isp_pipeline_pm_power(struct media_entity
*entity
, int change
)
736 struct media_entity_graph graph
;
737 struct media_entity
*first
= entity
;
743 media_entity_graph_walk_start(&graph
, entity
);
745 while (!ret
&& (entity
= media_entity_graph_walk_next(&graph
)))
746 if (media_entity_type(entity
) != MEDIA_ENT_T_DEVNODE
)
747 ret
= isp_pipeline_pm_power_one(entity
, change
);
752 media_entity_graph_walk_start(&graph
, first
);
754 while ((first
= media_entity_graph_walk_next(&graph
))
756 if (media_entity_type(first
) != MEDIA_ENT_T_DEVNODE
)
757 isp_pipeline_pm_power_one(first
, -change
);
763 * omap3isp_pipeline_pm_use - Update the use count of an entity
764 * @entity: The entity
765 * @use: Use (1) or stop using (0) the entity
767 * Update the use count of all entities in the pipeline and power entities on or
770 * Return 0 on success or a negative error code on failure. Powering entities
771 * off is assumed to never fail. No failure can occur when the use parameter is
774 int omap3isp_pipeline_pm_use(struct media_entity
*entity
, int use
)
776 int change
= use
? 1 : -1;
779 mutex_lock(&entity
->parent
->graph_mutex
);
781 /* Apply use count to node. */
782 entity
->use_count
+= change
;
783 WARN_ON(entity
->use_count
< 0);
785 /* Apply power change to connected non-nodes. */
786 ret
= isp_pipeline_pm_power(entity
, change
);
788 entity
->use_count
-= change
;
790 mutex_unlock(&entity
->parent
->graph_mutex
);
796 * isp_pipeline_link_notify - Link management notification callback
798 * @flags: New link flags that will be applied
799 * @notification: The link's state change notification type (MEDIA_DEV_NOTIFY_*)
801 * React to link management on powered pipelines by updating the use count of
802 * all entities in the source and sink sides of the link. Entities are powered
803 * on or off accordingly.
805 * Return 0 on success or a negative error code on failure. Powering entities
806 * off is assumed to never fail. This function will not fail for disconnection
809 static int isp_pipeline_link_notify(struct media_link
*link
, u32 flags
,
810 unsigned int notification
)
812 struct media_entity
*source
= link
->source
->entity
;
813 struct media_entity
*sink
= link
->sink
->entity
;
814 int source_use
= isp_pipeline_pm_use_count(source
);
815 int sink_use
= isp_pipeline_pm_use_count(sink
);
818 if (notification
== MEDIA_DEV_NOTIFY_POST_LINK_CH
&&
819 !(link
->flags
& MEDIA_LNK_FL_ENABLED
)) {
820 /* Powering off entities is assumed to never fail. */
821 isp_pipeline_pm_power(source
, -sink_use
);
822 isp_pipeline_pm_power(sink
, -source_use
);
826 if (notification
== MEDIA_DEV_NOTIFY_POST_LINK_CH
&&
827 (flags
& MEDIA_LNK_FL_ENABLED
)) {
829 ret
= isp_pipeline_pm_power(source
, sink_use
);
833 ret
= isp_pipeline_pm_power(sink
, source_use
);
835 isp_pipeline_pm_power(source
, -sink_use
);
843 /* -----------------------------------------------------------------------------
844 * Pipeline stream management
848 * isp_pipeline_enable - Enable streaming on a pipeline
849 * @pipe: ISP pipeline
850 * @mode: Stream mode (single shot or continuous)
852 * Walk the entities chain starting at the pipeline output video node and start
853 * all modules in the chain in the given mode.
855 * Return 0 if successful, or the return value of the failed video::s_stream
856 * operation otherwise.
858 static int isp_pipeline_enable(struct isp_pipeline
*pipe
,
859 enum isp_pipeline_stream_state mode
)
861 struct isp_device
*isp
= pipe
->output
->isp
;
862 struct media_entity
*entity
;
863 struct media_pad
*pad
;
864 struct v4l2_subdev
*subdev
;
868 /* Refuse to start streaming if an entity included in the pipeline has
869 * crashed. This check must be performed before the loop below to avoid
870 * starting entities if the pipeline won't start anyway (those entities
871 * would then likely fail to stop, making the problem worse).
873 if (pipe
->entities
& isp
->crashed
)
876 spin_lock_irqsave(&pipe
->lock
, flags
);
877 pipe
->state
&= ~(ISP_PIPELINE_IDLE_INPUT
| ISP_PIPELINE_IDLE_OUTPUT
);
878 spin_unlock_irqrestore(&pipe
->lock
, flags
);
880 pipe
->do_propagation
= false;
882 entity
= &pipe
->output
->video
.entity
;
884 pad
= &entity
->pads
[0];
885 if (!(pad
->flags
& MEDIA_PAD_FL_SINK
))
888 pad
= media_entity_remote_pad(pad
);
890 media_entity_type(pad
->entity
) != MEDIA_ENT_T_V4L2_SUBDEV
)
893 entity
= pad
->entity
;
894 subdev
= media_entity_to_v4l2_subdev(entity
);
896 ret
= v4l2_subdev_call(subdev
, video
, s_stream
, mode
);
897 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
900 if (subdev
== &isp
->isp_ccdc
.subdev
) {
901 v4l2_subdev_call(&isp
->isp_aewb
.subdev
, video
,
903 v4l2_subdev_call(&isp
->isp_af
.subdev
, video
,
905 v4l2_subdev_call(&isp
->isp_hist
.subdev
, video
,
907 pipe
->do_propagation
= true;
914 static int isp_pipeline_wait_resizer(struct isp_device
*isp
)
916 return omap3isp_resizer_busy(&isp
->isp_res
);
919 static int isp_pipeline_wait_preview(struct isp_device
*isp
)
921 return omap3isp_preview_busy(&isp
->isp_prev
);
924 static int isp_pipeline_wait_ccdc(struct isp_device
*isp
)
926 return omap3isp_stat_busy(&isp
->isp_af
)
927 || omap3isp_stat_busy(&isp
->isp_aewb
)
928 || omap3isp_stat_busy(&isp
->isp_hist
)
929 || omap3isp_ccdc_busy(&isp
->isp_ccdc
);
932 #define ISP_STOP_TIMEOUT msecs_to_jiffies(1000)
934 static int isp_pipeline_wait(struct isp_device
*isp
,
935 int(*busy
)(struct isp_device
*isp
))
937 unsigned long timeout
= jiffies
+ ISP_STOP_TIMEOUT
;
939 while (!time_after(jiffies
, timeout
)) {
948 * isp_pipeline_disable - Disable streaming on a pipeline
949 * @pipe: ISP pipeline
951 * Walk the entities chain starting at the pipeline output video node and stop
952 * all modules in the chain. Wait synchronously for the modules to be stopped if
955 * Return 0 if all modules have been properly stopped, or -ETIMEDOUT if a module
956 * can't be stopped (in which case a software reset of the ISP is probably
959 static int isp_pipeline_disable(struct isp_pipeline
*pipe
)
961 struct isp_device
*isp
= pipe
->output
->isp
;
962 struct media_entity
*entity
;
963 struct media_pad
*pad
;
964 struct v4l2_subdev
*subdev
;
969 * We need to stop all the modules after CCDC first or they'll
970 * never stop since they may not get a full frame from CCDC.
972 entity
= &pipe
->output
->video
.entity
;
974 pad
= &entity
->pads
[0];
975 if (!(pad
->flags
& MEDIA_PAD_FL_SINK
))
978 pad
= media_entity_remote_pad(pad
);
980 media_entity_type(pad
->entity
) != MEDIA_ENT_T_V4L2_SUBDEV
)
983 entity
= pad
->entity
;
984 subdev
= media_entity_to_v4l2_subdev(entity
);
986 if (subdev
== &isp
->isp_ccdc
.subdev
) {
987 v4l2_subdev_call(&isp
->isp_aewb
.subdev
,
989 v4l2_subdev_call(&isp
->isp_af
.subdev
,
991 v4l2_subdev_call(&isp
->isp_hist
.subdev
,
995 ret
= v4l2_subdev_call(subdev
, video
, s_stream
, 0);
997 if (subdev
== &isp
->isp_res
.subdev
)
998 ret
|= isp_pipeline_wait(isp
, isp_pipeline_wait_resizer
);
999 else if (subdev
== &isp
->isp_prev
.subdev
)
1000 ret
|= isp_pipeline_wait(isp
, isp_pipeline_wait_preview
);
1001 else if (subdev
== &isp
->isp_ccdc
.subdev
)
1002 ret
|= isp_pipeline_wait(isp
, isp_pipeline_wait_ccdc
);
1004 /* Handle stop failures. An entity that fails to stop can
1005 * usually just be restarted. Flag the stop failure nonetheless
1006 * to trigger an ISP reset the next time the device is released,
1009 * The preview engine is a special case. A failure to stop can
1010 * mean a hardware crash. When that happens the preview engine
1011 * won't respond to read/write operations on the L4 bus anymore,
1012 * resulting in a bus fault and a kernel oops next time it gets
1013 * accessed. Mark it as crashed to prevent pipelines including
1014 * it from being started.
1017 dev_info(isp
->dev
, "Unable to stop %s\n", subdev
->name
);
1018 isp
->stop_failure
= true;
1019 if (subdev
== &isp
->isp_prev
.subdev
)
1020 isp
->crashed
|= 1U << subdev
->entity
.id
;
1021 failure
= -ETIMEDOUT
;
1029 * omap3isp_pipeline_set_stream - Enable/disable streaming on a pipeline
1030 * @pipe: ISP pipeline
1031 * @state: Stream state (stopped, single shot or continuous)
1033 * Set the pipeline to the given stream state. Pipelines can be started in
1034 * single-shot or continuous mode.
1036 * Return 0 if successful, or the return value of the failed video::s_stream
1037 * operation otherwise. The pipeline state is not updated when the operation
1038 * fails, except when stopping the pipeline.
1040 int omap3isp_pipeline_set_stream(struct isp_pipeline
*pipe
,
1041 enum isp_pipeline_stream_state state
)
1045 if (state
== ISP_PIPELINE_STREAM_STOPPED
)
1046 ret
= isp_pipeline_disable(pipe
);
1048 ret
= isp_pipeline_enable(pipe
, state
);
1050 if (ret
== 0 || state
== ISP_PIPELINE_STREAM_STOPPED
)
1051 pipe
->stream_state
= state
;
1057 * omap3isp_pipeline_cancel_stream - Cancel stream on a pipeline
1058 * @pipe: ISP pipeline
1060 * Cancelling a stream mark all buffers on all video nodes in the pipeline as
1061 * erroneous and makes sure no new buffer can be queued. This function is called
1062 * when a fatal error that prevents any further operation on the pipeline
1065 void omap3isp_pipeline_cancel_stream(struct isp_pipeline
*pipe
)
1068 omap3isp_video_cancel_stream(pipe
->input
);
1070 omap3isp_video_cancel_stream(pipe
->output
);
1074 * isp_pipeline_resume - Resume streaming on a pipeline
1075 * @pipe: ISP pipeline
1077 * Resume video output and input and re-enable pipeline.
1079 static void isp_pipeline_resume(struct isp_pipeline
*pipe
)
1081 int singleshot
= pipe
->stream_state
== ISP_PIPELINE_STREAM_SINGLESHOT
;
1083 omap3isp_video_resume(pipe
->output
, !singleshot
);
1085 omap3isp_video_resume(pipe
->input
, 0);
1086 isp_pipeline_enable(pipe
, pipe
->stream_state
);
1090 * isp_pipeline_suspend - Suspend streaming on a pipeline
1091 * @pipe: ISP pipeline
1095 static void isp_pipeline_suspend(struct isp_pipeline
*pipe
)
1097 isp_pipeline_disable(pipe
);
1101 * isp_pipeline_is_last - Verify if entity has an enabled link to the output
1103 * @me: ISP module's media entity
1105 * Returns 1 if the entity has an enabled link to the output video node or 0
1106 * otherwise. It's true only while pipeline can have no more than one output
1109 static int isp_pipeline_is_last(struct media_entity
*me
)
1111 struct isp_pipeline
*pipe
;
1112 struct media_pad
*pad
;
1116 pipe
= to_isp_pipeline(me
);
1117 if (pipe
->stream_state
== ISP_PIPELINE_STREAM_STOPPED
)
1119 pad
= media_entity_remote_pad(&pipe
->output
->pad
);
1120 return pad
->entity
== me
;
1124 * isp_suspend_module_pipeline - Suspend pipeline to which belongs the module
1125 * @me: ISP module's media entity
1127 * Suspend 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_suspend_module_pipeline(struct media_entity
*me
)
1133 if (isp_pipeline_is_last(me
))
1134 isp_pipeline_suspend(to_isp_pipeline(me
));
1138 * isp_resume_module_pipeline - Resume pipeline to which belongs the module
1139 * @me: ISP module's media entity
1141 * Resume the whole pipeline if module's entity has an enabled link to the
1142 * output video node. It works only while pipeline can have no more than one
1145 static void isp_resume_module_pipeline(struct media_entity
*me
)
1147 if (isp_pipeline_is_last(me
))
1148 isp_pipeline_resume(to_isp_pipeline(me
));
1152 * isp_suspend_modules - Suspend ISP submodules.
1153 * @isp: OMAP3 ISP device
1155 * Returns 0 if suspend left in idle state all the submodules properly,
1156 * or returns 1 if a general Reset is required to suspend the submodules.
1158 static int isp_suspend_modules(struct isp_device
*isp
)
1160 unsigned long timeout
;
1162 omap3isp_stat_suspend(&isp
->isp_aewb
);
1163 omap3isp_stat_suspend(&isp
->isp_af
);
1164 omap3isp_stat_suspend(&isp
->isp_hist
);
1165 isp_suspend_module_pipeline(&isp
->isp_res
.subdev
.entity
);
1166 isp_suspend_module_pipeline(&isp
->isp_prev
.subdev
.entity
);
1167 isp_suspend_module_pipeline(&isp
->isp_ccdc
.subdev
.entity
);
1168 isp_suspend_module_pipeline(&isp
->isp_csi2a
.subdev
.entity
);
1169 isp_suspend_module_pipeline(&isp
->isp_ccp2
.subdev
.entity
);
1171 timeout
= jiffies
+ ISP_STOP_TIMEOUT
;
1172 while (omap3isp_stat_busy(&isp
->isp_af
)
1173 || omap3isp_stat_busy(&isp
->isp_aewb
)
1174 || omap3isp_stat_busy(&isp
->isp_hist
)
1175 || omap3isp_preview_busy(&isp
->isp_prev
)
1176 || omap3isp_resizer_busy(&isp
->isp_res
)
1177 || omap3isp_ccdc_busy(&isp
->isp_ccdc
)) {
1178 if (time_after(jiffies
, timeout
)) {
1179 dev_info(isp
->dev
, "can't stop modules.\n");
1189 * isp_resume_modules - Resume ISP submodules.
1190 * @isp: OMAP3 ISP device
1192 static void isp_resume_modules(struct isp_device
*isp
)
1194 omap3isp_stat_resume(&isp
->isp_aewb
);
1195 omap3isp_stat_resume(&isp
->isp_af
);
1196 omap3isp_stat_resume(&isp
->isp_hist
);
1197 isp_resume_module_pipeline(&isp
->isp_res
.subdev
.entity
);
1198 isp_resume_module_pipeline(&isp
->isp_prev
.subdev
.entity
);
1199 isp_resume_module_pipeline(&isp
->isp_ccdc
.subdev
.entity
);
1200 isp_resume_module_pipeline(&isp
->isp_csi2a
.subdev
.entity
);
1201 isp_resume_module_pipeline(&isp
->isp_ccp2
.subdev
.entity
);
1205 * isp_reset - Reset ISP with a timeout wait for idle.
1206 * @isp: OMAP3 ISP device
1208 static int isp_reset(struct isp_device
*isp
)
1210 unsigned long timeout
= 0;
1213 isp_reg_readl(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_SYSCONFIG
)
1214 | ISP_SYSCONFIG_SOFTRESET
,
1215 OMAP3_ISP_IOMEM_MAIN
, ISP_SYSCONFIG
);
1216 while (!(isp_reg_readl(isp
, OMAP3_ISP_IOMEM_MAIN
,
1217 ISP_SYSSTATUS
) & 0x1)) {
1218 if (timeout
++ > 10000) {
1219 dev_alert(isp
->dev
, "cannot reset ISP\n");
1225 isp
->stop_failure
= false;
1231 * isp_save_context - Saves 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_save_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 next
->val
= isp_reg_readl(isp
, next
->mmio_range
, next
->reg
);
1246 * isp_restore_context - Restores the values of the ISP module registers.
1247 * @isp: OMAP3 ISP device
1248 * @reg_list: Structure containing pairs of register address and value to
1252 isp_restore_context(struct isp_device
*isp
, struct isp_reg
*reg_list
)
1254 struct isp_reg
*next
= reg_list
;
1256 for (; next
->reg
!= ISP_TOK_TERM
; next
++)
1257 isp_reg_writel(isp
, next
->val
, next
->mmio_range
, next
->reg
);
1261 * isp_save_ctx - Saves ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1262 * @isp: OMAP3 ISP device
1264 * Routine for saving the context of each module in the ISP.
1265 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1267 static void isp_save_ctx(struct isp_device
*isp
)
1269 isp_save_context(isp
, isp_reg_list
);
1270 omap_iommu_save_ctx(isp
->dev
);
1274 * isp_restore_ctx - Restores ISP, CCDC, HIST, H3A, PREV, RESZ & MMU context.
1275 * @isp: OMAP3 ISP device
1277 * Routine for restoring the context of each module in the ISP.
1278 * CCDC, HIST, H3A, PREV, RESZ and MMU.
1280 static void isp_restore_ctx(struct isp_device
*isp
)
1282 isp_restore_context(isp
, isp_reg_list
);
1283 omap_iommu_restore_ctx(isp
->dev
);
1284 omap3isp_ccdc_restore_context(isp
);
1285 omap3isp_preview_restore_context(isp
);
1288 /* -----------------------------------------------------------------------------
1289 * SBL resources management
1291 #define OMAP3_ISP_SBL_READ (OMAP3_ISP_SBL_CSI1_READ | \
1292 OMAP3_ISP_SBL_CCDC_LSC_READ | \
1293 OMAP3_ISP_SBL_PREVIEW_READ | \
1294 OMAP3_ISP_SBL_RESIZER_READ)
1295 #define OMAP3_ISP_SBL_WRITE (OMAP3_ISP_SBL_CSI1_WRITE | \
1296 OMAP3_ISP_SBL_CSI2A_WRITE | \
1297 OMAP3_ISP_SBL_CSI2C_WRITE | \
1298 OMAP3_ISP_SBL_CCDC_WRITE | \
1299 OMAP3_ISP_SBL_PREVIEW_WRITE)
1301 void omap3isp_sbl_enable(struct isp_device
*isp
, enum isp_sbl_resource res
)
1305 isp
->sbl_resources
|= res
;
1307 if (isp
->sbl_resources
& OMAP3_ISP_SBL_CSI1_READ
)
1308 sbl
|= ISPCTRL_SBL_SHARED_RPORTA
;
1310 if (isp
->sbl_resources
& OMAP3_ISP_SBL_CCDC_LSC_READ
)
1311 sbl
|= ISPCTRL_SBL_SHARED_RPORTB
;
1313 if (isp
->sbl_resources
& OMAP3_ISP_SBL_CSI2C_WRITE
)
1314 sbl
|= ISPCTRL_SBL_SHARED_WPORTC
;
1316 if (isp
->sbl_resources
& OMAP3_ISP_SBL_RESIZER_WRITE
)
1317 sbl
|= ISPCTRL_SBL_WR0_RAM_EN
;
1319 if (isp
->sbl_resources
& OMAP3_ISP_SBL_WRITE
)
1320 sbl
|= ISPCTRL_SBL_WR1_RAM_EN
;
1322 if (isp
->sbl_resources
& OMAP3_ISP_SBL_READ
)
1323 sbl
|= ISPCTRL_SBL_RD_RAM_EN
;
1325 isp_reg_set(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_CTRL
, sbl
);
1328 void omap3isp_sbl_disable(struct isp_device
*isp
, enum isp_sbl_resource res
)
1332 isp
->sbl_resources
&= ~res
;
1334 if (!(isp
->sbl_resources
& OMAP3_ISP_SBL_CSI1_READ
))
1335 sbl
|= ISPCTRL_SBL_SHARED_RPORTA
;
1337 if (!(isp
->sbl_resources
& OMAP3_ISP_SBL_CCDC_LSC_READ
))
1338 sbl
|= ISPCTRL_SBL_SHARED_RPORTB
;
1340 if (!(isp
->sbl_resources
& OMAP3_ISP_SBL_CSI2C_WRITE
))
1341 sbl
|= ISPCTRL_SBL_SHARED_WPORTC
;
1343 if (!(isp
->sbl_resources
& OMAP3_ISP_SBL_RESIZER_WRITE
))
1344 sbl
|= ISPCTRL_SBL_WR0_RAM_EN
;
1346 if (!(isp
->sbl_resources
& OMAP3_ISP_SBL_WRITE
))
1347 sbl
|= ISPCTRL_SBL_WR1_RAM_EN
;
1349 if (!(isp
->sbl_resources
& OMAP3_ISP_SBL_READ
))
1350 sbl
|= ISPCTRL_SBL_RD_RAM_EN
;
1352 isp_reg_clr(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_CTRL
, sbl
);
1356 * isp_module_sync_idle - Helper to sync module with its idle state
1357 * @me: ISP submodule's media entity
1358 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1359 * @stopping: flag which tells module wants to stop
1361 * This function checks if ISP submodule needs to wait for next interrupt. If
1362 * yes, makes the caller to sleep while waiting for such event.
1364 int omap3isp_module_sync_idle(struct media_entity
*me
, wait_queue_head_t
*wait
,
1367 struct isp_pipeline
*pipe
= to_isp_pipeline(me
);
1369 if (pipe
->stream_state
== ISP_PIPELINE_STREAM_STOPPED
||
1370 (pipe
->stream_state
== ISP_PIPELINE_STREAM_SINGLESHOT
&&
1371 !isp_pipeline_ready(pipe
)))
1375 * atomic_set() doesn't include memory barrier on ARM platform for SMP
1376 * scenario. We'll call it here to avoid race conditions.
1378 atomic_set(stopping
, 1);
1382 * If module is the last one, it's writing to memory. In this case,
1383 * it's necessary to check if the module is already paused due to
1384 * DMA queue underrun or if it has to wait for next interrupt to be
1386 * If it isn't the last one, the function won't sleep but *stopping
1387 * will still be set to warn next submodule caller's interrupt the
1388 * module wants to be idle.
1390 if (isp_pipeline_is_last(me
)) {
1391 struct isp_video
*video
= pipe
->output
;
1392 unsigned long flags
;
1393 spin_lock_irqsave(&video
->irqlock
, flags
);
1394 if (video
->dmaqueue_flags
& ISP_VIDEO_DMAQUEUE_UNDERRUN
) {
1395 spin_unlock_irqrestore(&video
->irqlock
, flags
);
1396 atomic_set(stopping
, 0);
1400 spin_unlock_irqrestore(&video
->irqlock
, flags
);
1401 if (!wait_event_timeout(*wait
, !atomic_read(stopping
),
1402 msecs_to_jiffies(1000))) {
1403 atomic_set(stopping
, 0);
1413 * omap3isp_module_sync_is_stopping - Helper to verify if module was stopping
1414 * @wait: ISP submodule's wait queue for streamoff/interrupt synchronization
1415 * @stopping: flag which tells module wants to stop
1417 * This function checks if ISP submodule was stopping. In case of yes, it
1418 * notices the caller by setting stopping to 0 and waking up the wait queue.
1419 * Returns 1 if it was stopping or 0 otherwise.
1421 int omap3isp_module_sync_is_stopping(wait_queue_head_t
*wait
,
1424 if (atomic_cmpxchg(stopping
, 1, 0)) {
1432 /* --------------------------------------------------------------------------
1436 #define ISPCTRL_CLKS_MASK (ISPCTRL_H3A_CLK_EN | \
1437 ISPCTRL_HIST_CLK_EN | \
1438 ISPCTRL_RSZ_CLK_EN | \
1439 (ISPCTRL_CCDC_CLK_EN | ISPCTRL_CCDC_RAM_EN) | \
1440 (ISPCTRL_PREV_CLK_EN | ISPCTRL_PREV_RAM_EN))
1442 static void __isp_subclk_update(struct isp_device
*isp
)
1446 /* AEWB and AF share the same clock. */
1447 if (isp
->subclk_resources
&
1448 (OMAP3_ISP_SUBCLK_AEWB
| OMAP3_ISP_SUBCLK_AF
))
1449 clk
|= ISPCTRL_H3A_CLK_EN
;
1451 if (isp
->subclk_resources
& OMAP3_ISP_SUBCLK_HIST
)
1452 clk
|= ISPCTRL_HIST_CLK_EN
;
1454 if (isp
->subclk_resources
& OMAP3_ISP_SUBCLK_RESIZER
)
1455 clk
|= ISPCTRL_RSZ_CLK_EN
;
1457 /* NOTE: For CCDC & Preview submodules, we need to affect internal
1460 if (isp
->subclk_resources
& OMAP3_ISP_SUBCLK_CCDC
)
1461 clk
|= ISPCTRL_CCDC_CLK_EN
| ISPCTRL_CCDC_RAM_EN
;
1463 if (isp
->subclk_resources
& OMAP3_ISP_SUBCLK_PREVIEW
)
1464 clk
|= ISPCTRL_PREV_CLK_EN
| ISPCTRL_PREV_RAM_EN
;
1466 isp_reg_clr_set(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_CTRL
,
1467 ISPCTRL_CLKS_MASK
, clk
);
1470 void omap3isp_subclk_enable(struct isp_device
*isp
,
1471 enum isp_subclk_resource res
)
1473 isp
->subclk_resources
|= res
;
1475 __isp_subclk_update(isp
);
1478 void omap3isp_subclk_disable(struct isp_device
*isp
,
1479 enum isp_subclk_resource res
)
1481 isp
->subclk_resources
&= ~res
;
1483 __isp_subclk_update(isp
);
1487 * isp_enable_clocks - Enable ISP clocks
1488 * @isp: OMAP3 ISP device
1490 * Return 0 if successful, or clk_prepare_enable return value if any of them
1493 static int isp_enable_clocks(struct isp_device
*isp
)
1498 r
= clk_prepare_enable(isp
->clock
[ISP_CLK_CAM_ICK
]);
1500 dev_err(isp
->dev
, "failed to enable cam_ick clock\n");
1501 goto out_clk_enable_ick
;
1503 r
= clk_set_rate(isp
->clock
[ISP_CLK_CAM_MCLK
], CM_CAM_MCLK_HZ
);
1505 dev_err(isp
->dev
, "clk_set_rate for cam_mclk failed\n");
1506 goto out_clk_enable_mclk
;
1508 r
= clk_prepare_enable(isp
->clock
[ISP_CLK_CAM_MCLK
]);
1510 dev_err(isp
->dev
, "failed to enable cam_mclk clock\n");
1511 goto out_clk_enable_mclk
;
1513 rate
= clk_get_rate(isp
->clock
[ISP_CLK_CAM_MCLK
]);
1514 if (rate
!= CM_CAM_MCLK_HZ
)
1515 dev_warn(isp
->dev
, "unexpected cam_mclk rate:\n"
1517 " actual : %ld\n", CM_CAM_MCLK_HZ
, rate
);
1518 r
= clk_prepare_enable(isp
->clock
[ISP_CLK_CSI2_FCK
]);
1520 dev_err(isp
->dev
, "failed to enable csi2_fck clock\n");
1521 goto out_clk_enable_csi2_fclk
;
1525 out_clk_enable_csi2_fclk
:
1526 clk_disable_unprepare(isp
->clock
[ISP_CLK_CAM_MCLK
]);
1527 out_clk_enable_mclk
:
1528 clk_disable_unprepare(isp
->clock
[ISP_CLK_CAM_ICK
]);
1534 * isp_disable_clocks - Disable ISP clocks
1535 * @isp: OMAP3 ISP device
1537 static void isp_disable_clocks(struct isp_device
*isp
)
1539 clk_disable_unprepare(isp
->clock
[ISP_CLK_CAM_ICK
]);
1540 clk_disable_unprepare(isp
->clock
[ISP_CLK_CAM_MCLK
]);
1541 clk_disable_unprepare(isp
->clock
[ISP_CLK_CSI2_FCK
]);
1544 static const char *isp_clocks
[] = {
1551 static int isp_get_clocks(struct isp_device
*isp
)
1556 for (i
= 0; i
< ARRAY_SIZE(isp_clocks
); ++i
) {
1557 clk
= devm_clk_get(isp
->dev
, isp_clocks
[i
]);
1559 dev_err(isp
->dev
, "clk_get %s failed\n", isp_clocks
[i
]);
1560 return PTR_ERR(clk
);
1563 isp
->clock
[i
] = clk
;
1570 * omap3isp_get - Acquire the ISP resource.
1572 * Initializes the clocks for the first acquire.
1574 * Increment the reference count on the ISP. If the first reference is taken,
1575 * enable clocks and power-up all submodules.
1577 * Return a pointer to the ISP device structure, or NULL if an error occurred.
1579 static struct isp_device
*__omap3isp_get(struct isp_device
*isp
, bool irq
)
1581 struct isp_device
*__isp
= isp
;
1586 mutex_lock(&isp
->isp_mutex
);
1587 if (isp
->ref_count
> 0)
1590 if (isp_enable_clocks(isp
) < 0) {
1595 /* We don't want to restore context before saving it! */
1596 if (isp
->has_context
)
1597 isp_restore_ctx(isp
);
1600 isp_enable_interrupts(isp
);
1605 mutex_unlock(&isp
->isp_mutex
);
1610 struct isp_device
*omap3isp_get(struct isp_device
*isp
)
1612 return __omap3isp_get(isp
, true);
1616 * omap3isp_put - Release the ISP
1618 * Decrement the reference count on the ISP. If the last reference is released,
1619 * power-down all submodules, disable clocks and free temporary buffers.
1621 static void __omap3isp_put(struct isp_device
*isp
, bool save_ctx
)
1626 mutex_lock(&isp
->isp_mutex
);
1627 BUG_ON(isp
->ref_count
== 0);
1628 if (--isp
->ref_count
== 0) {
1629 isp_disable_interrupts(isp
);
1632 isp
->has_context
= 1;
1634 /* Reset the ISP if an entity has failed to stop. This is the
1635 * only way to recover from such conditions.
1637 if (isp
->crashed
|| isp
->stop_failure
)
1639 isp_disable_clocks(isp
);
1641 mutex_unlock(&isp
->isp_mutex
);
1644 void omap3isp_put(struct isp_device
*isp
)
1646 __omap3isp_put(isp
, true);
1649 /* --------------------------------------------------------------------------
1650 * Platform device driver
1654 * omap3isp_print_status - Prints the values of the ISP Control Module registers
1655 * @isp: OMAP3 ISP device
1657 #define ISP_PRINT_REGISTER(isp, name)\
1658 dev_dbg(isp->dev, "###ISP " #name "=0x%08x\n", \
1659 isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_##name))
1660 #define SBL_PRINT_REGISTER(isp, name)\
1661 dev_dbg(isp->dev, "###SBL " #name "=0x%08x\n", \
1662 isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_##name))
1664 void omap3isp_print_status(struct isp_device
*isp
)
1666 dev_dbg(isp
->dev
, "-------------ISP Register dump--------------\n");
1668 ISP_PRINT_REGISTER(isp
, SYSCONFIG
);
1669 ISP_PRINT_REGISTER(isp
, SYSSTATUS
);
1670 ISP_PRINT_REGISTER(isp
, IRQ0ENABLE
);
1671 ISP_PRINT_REGISTER(isp
, IRQ0STATUS
);
1672 ISP_PRINT_REGISTER(isp
, TCTRL_GRESET_LENGTH
);
1673 ISP_PRINT_REGISTER(isp
, TCTRL_PSTRB_REPLAY
);
1674 ISP_PRINT_REGISTER(isp
, CTRL
);
1675 ISP_PRINT_REGISTER(isp
, TCTRL_CTRL
);
1676 ISP_PRINT_REGISTER(isp
, TCTRL_FRAME
);
1677 ISP_PRINT_REGISTER(isp
, TCTRL_PSTRB_DELAY
);
1678 ISP_PRINT_REGISTER(isp
, TCTRL_STRB_DELAY
);
1679 ISP_PRINT_REGISTER(isp
, TCTRL_SHUT_DELAY
);
1680 ISP_PRINT_REGISTER(isp
, TCTRL_PSTRB_LENGTH
);
1681 ISP_PRINT_REGISTER(isp
, TCTRL_STRB_LENGTH
);
1682 ISP_PRINT_REGISTER(isp
, TCTRL_SHUT_LENGTH
);
1684 SBL_PRINT_REGISTER(isp
, PCR
);
1685 SBL_PRINT_REGISTER(isp
, SDR_REQ_EXP
);
1687 dev_dbg(isp
->dev
, "--------------------------------------------\n");
1693 * Power management support.
1695 * As the ISP can't properly handle an input video stream interruption on a non
1696 * frame boundary, the ISP pipelines need to be stopped before sensors get
1697 * suspended. However, as suspending the sensors can require a running clock,
1698 * which can be provided by the ISP, the ISP can't be completely suspended
1699 * before the sensor.
1701 * To solve this problem power management support is split into prepare/complete
1702 * and suspend/resume operations. The pipelines are stopped in prepare() and the
1703 * ISP clocks get disabled in suspend(). Similarly, the clocks are reenabled in
1704 * resume(), and the the pipelines are restarted in complete().
1706 * TODO: PM dependencies between the ISP and sensors are not modelled explicitly
1709 static int isp_pm_prepare(struct device
*dev
)
1711 struct isp_device
*isp
= dev_get_drvdata(dev
);
1714 WARN_ON(mutex_is_locked(&isp
->isp_mutex
));
1716 if (isp
->ref_count
== 0)
1719 reset
= isp_suspend_modules(isp
);
1720 isp_disable_interrupts(isp
);
1728 static int isp_pm_suspend(struct device
*dev
)
1730 struct isp_device
*isp
= dev_get_drvdata(dev
);
1732 WARN_ON(mutex_is_locked(&isp
->isp_mutex
));
1735 isp_disable_clocks(isp
);
1740 static int isp_pm_resume(struct device
*dev
)
1742 struct isp_device
*isp
= dev_get_drvdata(dev
);
1744 if (isp
->ref_count
== 0)
1747 return isp_enable_clocks(isp
);
1750 static void isp_pm_complete(struct device
*dev
)
1752 struct isp_device
*isp
= dev_get_drvdata(dev
);
1754 if (isp
->ref_count
== 0)
1757 isp_restore_ctx(isp
);
1758 isp_enable_interrupts(isp
);
1759 isp_resume_modules(isp
);
1764 #define isp_pm_prepare NULL
1765 #define isp_pm_suspend NULL
1766 #define isp_pm_resume NULL
1767 #define isp_pm_complete NULL
1769 #endif /* CONFIG_PM */
1771 static void isp_unregister_entities(struct isp_device
*isp
)
1773 omap3isp_csi2_unregister_entities(&isp
->isp_csi2a
);
1774 omap3isp_ccp2_unregister_entities(&isp
->isp_ccp2
);
1775 omap3isp_ccdc_unregister_entities(&isp
->isp_ccdc
);
1776 omap3isp_preview_unregister_entities(&isp
->isp_prev
);
1777 omap3isp_resizer_unregister_entities(&isp
->isp_res
);
1778 omap3isp_stat_unregister_entities(&isp
->isp_aewb
);
1779 omap3isp_stat_unregister_entities(&isp
->isp_af
);
1780 omap3isp_stat_unregister_entities(&isp
->isp_hist
);
1782 v4l2_device_unregister(&isp
->v4l2_dev
);
1783 media_device_unregister(&isp
->media_dev
);
1787 * isp_register_subdev_group - Register a group of subdevices
1788 * @isp: OMAP3 ISP device
1789 * @board_info: I2C subdevs board information array
1791 * Register all I2C subdevices in the board_info array. The array must be
1792 * terminated by a NULL entry, and the first entry must be the sensor.
1794 * Return a pointer to the sensor media entity if it has been successfully
1795 * registered, or NULL otherwise.
1797 static struct v4l2_subdev
*
1798 isp_register_subdev_group(struct isp_device
*isp
,
1799 struct isp_subdev_i2c_board_info
*board_info
)
1801 struct v4l2_subdev
*sensor
= NULL
;
1804 if (board_info
->board_info
== NULL
)
1807 for (first
= 1; board_info
->board_info
; ++board_info
, first
= 0) {
1808 struct v4l2_subdev
*subdev
;
1809 struct i2c_adapter
*adapter
;
1811 adapter
= i2c_get_adapter(board_info
->i2c_adapter_id
);
1812 if (adapter
== NULL
) {
1813 dev_err(isp
->dev
, "%s: Unable to get I2C adapter %d for "
1814 "device %s\n", __func__
,
1815 board_info
->i2c_adapter_id
,
1816 board_info
->board_info
->type
);
1820 subdev
= v4l2_i2c_new_subdev_board(&isp
->v4l2_dev
, adapter
,
1821 board_info
->board_info
, NULL
);
1822 if (subdev
== NULL
) {
1823 dev_err(isp
->dev
, "%s: Unable to register subdev %s\n",
1824 __func__
, board_info
->board_info
->type
);
1835 static int isp_register_entities(struct isp_device
*isp
)
1837 struct isp_platform_data
*pdata
= isp
->pdata
;
1838 struct isp_v4l2_subdevs_group
*subdevs
;
1841 isp
->media_dev
.dev
= isp
->dev
;
1842 strlcpy(isp
->media_dev
.model
, "TI OMAP3 ISP",
1843 sizeof(isp
->media_dev
.model
));
1844 isp
->media_dev
.hw_revision
= isp
->revision
;
1845 isp
->media_dev
.link_notify
= isp_pipeline_link_notify
;
1846 ret
= media_device_register(&isp
->media_dev
);
1848 dev_err(isp
->dev
, "%s: Media device registration failed (%d)\n",
1853 isp
->v4l2_dev
.mdev
= &isp
->media_dev
;
1854 ret
= v4l2_device_register(isp
->dev
, &isp
->v4l2_dev
);
1856 dev_err(isp
->dev
, "%s: V4L2 device registration failed (%d)\n",
1861 /* Register internal entities */
1862 ret
= omap3isp_ccp2_register_entities(&isp
->isp_ccp2
, &isp
->v4l2_dev
);
1866 ret
= omap3isp_csi2_register_entities(&isp
->isp_csi2a
, &isp
->v4l2_dev
);
1870 ret
= omap3isp_ccdc_register_entities(&isp
->isp_ccdc
, &isp
->v4l2_dev
);
1874 ret
= omap3isp_preview_register_entities(&isp
->isp_prev
,
1879 ret
= omap3isp_resizer_register_entities(&isp
->isp_res
, &isp
->v4l2_dev
);
1883 ret
= omap3isp_stat_register_entities(&isp
->isp_aewb
, &isp
->v4l2_dev
);
1887 ret
= omap3isp_stat_register_entities(&isp
->isp_af
, &isp
->v4l2_dev
);
1891 ret
= omap3isp_stat_register_entities(&isp
->isp_hist
, &isp
->v4l2_dev
);
1895 /* Register external entities */
1896 for (subdevs
= pdata
->subdevs
; subdevs
&& subdevs
->subdevs
; ++subdevs
) {
1897 struct v4l2_subdev
*sensor
;
1898 struct media_entity
*input
;
1903 sensor
= isp_register_subdev_group(isp
, subdevs
->subdevs
);
1907 sensor
->host_priv
= subdevs
;
1909 /* Connect the sensor to the correct interface module. Parallel
1910 * sensors are connected directly to the CCDC, while serial
1911 * sensors are connected to the CSI2a, CCP2b or CSI2c receiver
1912 * through CSIPHY1 or CSIPHY2.
1914 switch (subdevs
->interface
) {
1915 case ISP_INTERFACE_PARALLEL
:
1916 input
= &isp
->isp_ccdc
.subdev
.entity
;
1917 pad
= CCDC_PAD_SINK
;
1921 case ISP_INTERFACE_CSI2A_PHY2
:
1922 input
= &isp
->isp_csi2a
.subdev
.entity
;
1923 pad
= CSI2_PAD_SINK
;
1924 flags
= MEDIA_LNK_FL_IMMUTABLE
1925 | MEDIA_LNK_FL_ENABLED
;
1928 case ISP_INTERFACE_CCP2B_PHY1
:
1929 case ISP_INTERFACE_CCP2B_PHY2
:
1930 input
= &isp
->isp_ccp2
.subdev
.entity
;
1931 pad
= CCP2_PAD_SINK
;
1935 case ISP_INTERFACE_CSI2C_PHY1
:
1936 input
= &isp
->isp_csi2c
.subdev
.entity
;
1937 pad
= CSI2_PAD_SINK
;
1938 flags
= MEDIA_LNK_FL_IMMUTABLE
1939 | MEDIA_LNK_FL_ENABLED
;
1943 dev_err(isp
->dev
, "%s: invalid interface type %u\n",
1944 __func__
, subdevs
->interface
);
1949 for (i
= 0; i
< sensor
->entity
.num_pads
; i
++) {
1950 if (sensor
->entity
.pads
[i
].flags
& MEDIA_PAD_FL_SOURCE
)
1953 if (i
== sensor
->entity
.num_pads
) {
1955 "%s: no source pad in external entity\n",
1961 ret
= media_entity_create_link(&sensor
->entity
, i
, input
, pad
,
1967 ret
= v4l2_device_register_subdev_nodes(&isp
->v4l2_dev
);
1971 isp_unregister_entities(isp
);
1976 static void isp_cleanup_modules(struct isp_device
*isp
)
1978 omap3isp_h3a_aewb_cleanup(isp
);
1979 omap3isp_h3a_af_cleanup(isp
);
1980 omap3isp_hist_cleanup(isp
);
1981 omap3isp_resizer_cleanup(isp
);
1982 omap3isp_preview_cleanup(isp
);
1983 omap3isp_ccdc_cleanup(isp
);
1984 omap3isp_ccp2_cleanup(isp
);
1985 omap3isp_csi2_cleanup(isp
);
1988 static int isp_initialize_modules(struct isp_device
*isp
)
1992 ret
= omap3isp_csiphy_init(isp
);
1994 dev_err(isp
->dev
, "CSI PHY initialization failed\n");
1998 ret
= omap3isp_csi2_init(isp
);
2000 dev_err(isp
->dev
, "CSI2 initialization failed\n");
2004 ret
= omap3isp_ccp2_init(isp
);
2006 dev_err(isp
->dev
, "CCP2 initialization failed\n");
2010 ret
= omap3isp_ccdc_init(isp
);
2012 dev_err(isp
->dev
, "CCDC initialization failed\n");
2016 ret
= omap3isp_preview_init(isp
);
2018 dev_err(isp
->dev
, "Preview initialization failed\n");
2022 ret
= omap3isp_resizer_init(isp
);
2024 dev_err(isp
->dev
, "Resizer initialization failed\n");
2028 ret
= omap3isp_hist_init(isp
);
2030 dev_err(isp
->dev
, "Histogram initialization failed\n");
2034 ret
= omap3isp_h3a_aewb_init(isp
);
2036 dev_err(isp
->dev
, "H3A AEWB initialization failed\n");
2037 goto error_h3a_aewb
;
2040 ret
= omap3isp_h3a_af_init(isp
);
2042 dev_err(isp
->dev
, "H3A AF initialization failed\n");
2046 /* Connect the submodules. */
2047 ret
= media_entity_create_link(
2048 &isp
->isp_csi2a
.subdev
.entity
, CSI2_PAD_SOURCE
,
2049 &isp
->isp_ccdc
.subdev
.entity
, CCDC_PAD_SINK
, 0);
2053 ret
= media_entity_create_link(
2054 &isp
->isp_ccp2
.subdev
.entity
, CCP2_PAD_SOURCE
,
2055 &isp
->isp_ccdc
.subdev
.entity
, CCDC_PAD_SINK
, 0);
2059 ret
= media_entity_create_link(
2060 &isp
->isp_ccdc
.subdev
.entity
, CCDC_PAD_SOURCE_VP
,
2061 &isp
->isp_prev
.subdev
.entity
, PREV_PAD_SINK
, 0);
2065 ret
= media_entity_create_link(
2066 &isp
->isp_ccdc
.subdev
.entity
, CCDC_PAD_SOURCE_OF
,
2067 &isp
->isp_res
.subdev
.entity
, RESZ_PAD_SINK
, 0);
2071 ret
= media_entity_create_link(
2072 &isp
->isp_prev
.subdev
.entity
, PREV_PAD_SOURCE
,
2073 &isp
->isp_res
.subdev
.entity
, RESZ_PAD_SINK
, 0);
2077 ret
= media_entity_create_link(
2078 &isp
->isp_ccdc
.subdev
.entity
, CCDC_PAD_SOURCE_VP
,
2079 &isp
->isp_aewb
.subdev
.entity
, 0,
2080 MEDIA_LNK_FL_ENABLED
| MEDIA_LNK_FL_IMMUTABLE
);
2084 ret
= media_entity_create_link(
2085 &isp
->isp_ccdc
.subdev
.entity
, CCDC_PAD_SOURCE_VP
,
2086 &isp
->isp_af
.subdev
.entity
, 0,
2087 MEDIA_LNK_FL_ENABLED
| MEDIA_LNK_FL_IMMUTABLE
);
2091 ret
= media_entity_create_link(
2092 &isp
->isp_ccdc
.subdev
.entity
, CCDC_PAD_SOURCE_VP
,
2093 &isp
->isp_hist
.subdev
.entity
, 0,
2094 MEDIA_LNK_FL_ENABLED
| MEDIA_LNK_FL_IMMUTABLE
);
2101 omap3isp_h3a_af_cleanup(isp
);
2103 omap3isp_h3a_aewb_cleanup(isp
);
2105 omap3isp_hist_cleanup(isp
);
2107 omap3isp_resizer_cleanup(isp
);
2109 omap3isp_preview_cleanup(isp
);
2111 omap3isp_ccdc_cleanup(isp
);
2113 omap3isp_ccp2_cleanup(isp
);
2115 omap3isp_csi2_cleanup(isp
);
2121 static void isp_detach_iommu(struct isp_device
*isp
)
2123 arm_iommu_release_mapping(isp
->mapping
);
2124 isp
->mapping
= NULL
;
2125 iommu_group_remove_device(isp
->dev
);
2128 static int isp_attach_iommu(struct isp_device
*isp
)
2130 struct dma_iommu_mapping
*mapping
;
2131 struct iommu_group
*group
;
2134 /* Create a device group and add the device to it. */
2135 group
= iommu_group_alloc();
2136 if (IS_ERR(group
)) {
2137 dev_err(isp
->dev
, "failed to allocate IOMMU group\n");
2138 return PTR_ERR(group
);
2141 ret
= iommu_group_add_device(group
, isp
->dev
);
2142 iommu_group_put(group
);
2145 dev_err(isp
->dev
, "failed to add device to IPMMU group\n");
2150 * Create the ARM mapping, used by the ARM DMA mapping core to allocate
2151 * VAs. This will allocate a corresponding IOMMU domain.
2153 mapping
= arm_iommu_create_mapping(&platform_bus_type
, SZ_1G
, SZ_2G
);
2154 if (IS_ERR(mapping
)) {
2155 dev_err(isp
->dev
, "failed to create ARM IOMMU mapping\n");
2156 ret
= PTR_ERR(mapping
);
2160 isp
->mapping
= mapping
;
2162 /* Attach the ARM VA mapping to the device. */
2163 ret
= arm_iommu_attach_device(isp
->dev
, mapping
);
2165 dev_err(isp
->dev
, "failed to attach device to VA mapping\n");
2172 isp_detach_iommu(isp
);
2177 * isp_remove - Remove ISP platform device
2178 * @pdev: Pointer to ISP platform device
2182 static int isp_remove(struct platform_device
*pdev
)
2184 struct isp_device
*isp
= platform_get_drvdata(pdev
);
2186 isp_unregister_entities(isp
);
2187 isp_cleanup_modules(isp
);
2188 isp_xclk_cleanup(isp
);
2190 __omap3isp_get(isp
, false);
2191 isp_detach_iommu(isp
);
2192 __omap3isp_put(isp
, false);
2197 static int isp_map_mem_resource(struct platform_device
*pdev
,
2198 struct isp_device
*isp
,
2199 enum isp_mem_resources res
)
2201 struct resource
*mem
;
2203 /* request the mem region for the camera registers */
2205 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, res
);
2207 /* map the region */
2208 isp
->mmio_base
[res
] = devm_ioremap_resource(isp
->dev
, mem
);
2209 if (IS_ERR(isp
->mmio_base
[res
]))
2210 return PTR_ERR(isp
->mmio_base
[res
]);
2212 isp
->mmio_base_phys
[res
] = mem
->start
;
2218 * isp_probe - Probe ISP platform device
2219 * @pdev: Pointer to ISP platform device
2221 * Returns 0 if successful,
2222 * -ENOMEM if no memory available,
2223 * -ENODEV if no platform device resources found
2224 * or no space for remapping registers,
2225 * -EINVAL if couldn't install ISR,
2226 * or clk_get return error value.
2228 static int isp_probe(struct platform_device
*pdev
)
2230 struct isp_platform_data
*pdata
= pdev
->dev
.platform_data
;
2231 struct isp_device
*isp
;
2238 isp
= devm_kzalloc(&pdev
->dev
, sizeof(*isp
), GFP_KERNEL
);
2240 dev_err(&pdev
->dev
, "could not allocate memory\n");
2244 isp
->autoidle
= autoidle
;
2246 mutex_init(&isp
->isp_mutex
);
2247 spin_lock_init(&isp
->stat_lock
);
2249 isp
->dev
= &pdev
->dev
;
2253 ret
= dma_coerce_mask_and_coherent(isp
->dev
, DMA_BIT_MASK(32));
2257 platform_set_drvdata(pdev
, isp
);
2260 isp
->isp_csiphy1
.vdd
= devm_regulator_get(&pdev
->dev
, "VDD_CSIPHY1");
2261 isp
->isp_csiphy2
.vdd
= devm_regulator_get(&pdev
->dev
, "VDD_CSIPHY2");
2265 * The ISP clock tree is revision-dependent. We thus need to enable ICLK
2266 * manually to read the revision before calling __omap3isp_get().
2268 ret
= isp_map_mem_resource(pdev
, isp
, OMAP3_ISP_IOMEM_MAIN
);
2272 ret
= isp_get_clocks(isp
);
2276 ret
= clk_enable(isp
->clock
[ISP_CLK_CAM_ICK
]);
2280 isp
->revision
= isp_reg_readl(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_REVISION
);
2281 dev_info(isp
->dev
, "Revision %d.%d found\n",
2282 (isp
->revision
& 0xf0) >> 4, isp
->revision
& 0x0f);
2284 clk_disable(isp
->clock
[ISP_CLK_CAM_ICK
]);
2286 if (__omap3isp_get(isp
, false) == NULL
) {
2291 ret
= isp_reset(isp
);
2295 ret
= isp_xclk_init(isp
);
2299 /* Memory resources */
2300 for (m
= 0; m
< ARRAY_SIZE(isp_res_maps
); m
++)
2301 if (isp
->revision
== isp_res_maps
[m
].isp_rev
)
2304 if (m
== ARRAY_SIZE(isp_res_maps
)) {
2305 dev_err(isp
->dev
, "No resource map found for ISP rev %d.%d\n",
2306 (isp
->revision
& 0xf0) >> 4, isp
->revision
& 0xf);
2311 for (i
= 1; i
< OMAP3_ISP_IOMEM_LAST
; i
++) {
2312 if (isp_res_maps
[m
].map
& 1 << i
) {
2313 ret
= isp_map_mem_resource(pdev
, isp
, i
);
2320 ret
= isp_attach_iommu(isp
);
2322 dev_err(&pdev
->dev
, "unable to attach to IOMMU\n");
2327 isp
->irq_num
= platform_get_irq(pdev
, 0);
2328 if (isp
->irq_num
<= 0) {
2329 dev_err(isp
->dev
, "No IRQ resource\n");
2334 if (devm_request_irq(isp
->dev
, isp
->irq_num
, isp_isr
, IRQF_SHARED
,
2335 "OMAP3 ISP", isp
)) {
2336 dev_err(isp
->dev
, "Unable to request IRQ\n");
2342 ret
= isp_initialize_modules(isp
);
2346 ret
= isp_register_entities(isp
);
2350 isp_core_init(isp
, 1);
2356 isp_cleanup_modules(isp
);
2358 isp_detach_iommu(isp
);
2360 isp_xclk_cleanup(isp
);
2361 __omap3isp_put(isp
, false);
2363 mutex_destroy(&isp
->isp_mutex
);
2368 static const struct dev_pm_ops omap3isp_pm_ops
= {
2369 .prepare
= isp_pm_prepare
,
2370 .suspend
= isp_pm_suspend
,
2371 .resume
= isp_pm_resume
,
2372 .complete
= isp_pm_complete
,
2375 static struct platform_device_id omap3isp_id_table
[] = {
2379 MODULE_DEVICE_TABLE(platform
, omap3isp_id_table
);
2381 static struct platform_driver omap3isp_driver
= {
2383 .remove
= isp_remove
,
2384 .id_table
= omap3isp_id_table
,
2387 .pm
= &omap3isp_pm_ops
,
2391 module_platform_driver(omap3isp_driver
);
2393 MODULE_AUTHOR("Nokia Corporation");
2394 MODULE_DESCRIPTION("TI OMAP3 ISP driver");
2395 MODULE_LICENSE("GPL");
2396 MODULE_VERSION(ISP_VIDEO_DRIVER_VERSION
);