4 * TI OMAP3 ISP - CSI2 module
6 * Copyright (C) 2010 Nokia Corporation
7 * Copyright (C) 2009 Texas Instruments, Inc.
9 * Contacts: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
10 * Sakari Ailus <sakari.ailus@iki.fi>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include <linux/delay.h>
27 #include <media/v4l2-common.h>
28 #include <linux/v4l2-mediabus.h>
36 * csi2_if_enable - Enable CSI2 Receiver interface.
37 * @enable: enable flag
40 static void csi2_if_enable(struct isp_device
*isp
,
41 struct isp_csi2_device
*csi2
, u8 enable
)
43 struct isp_csi2_ctrl_cfg
*currctrl
= &csi2
->ctrl
;
45 isp_reg_clr_set(isp
, csi2
->regs1
, ISPCSI2_CTRL
, ISPCSI2_CTRL_IF_EN
,
46 enable
? ISPCSI2_CTRL_IF_EN
: 0);
48 currctrl
->if_enable
= enable
;
52 * csi2_recv_config - CSI2 receiver module configuration.
53 * @currctrl: isp_csi2_ctrl_cfg structure
56 static void csi2_recv_config(struct isp_device
*isp
,
57 struct isp_csi2_device
*csi2
,
58 struct isp_csi2_ctrl_cfg
*currctrl
)
62 reg
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_CTRL
);
64 if (currctrl
->frame_mode
)
65 reg
|= ISPCSI2_CTRL_FRAME
;
67 reg
&= ~ISPCSI2_CTRL_FRAME
;
69 if (currctrl
->vp_clk_enable
)
70 reg
|= ISPCSI2_CTRL_VP_CLK_EN
;
72 reg
&= ~ISPCSI2_CTRL_VP_CLK_EN
;
74 if (currctrl
->vp_only_enable
)
75 reg
|= ISPCSI2_CTRL_VP_ONLY_EN
;
77 reg
&= ~ISPCSI2_CTRL_VP_ONLY_EN
;
79 reg
&= ~ISPCSI2_CTRL_VP_OUT_CTRL_MASK
;
80 reg
|= currctrl
->vp_out_ctrl
<< ISPCSI2_CTRL_VP_OUT_CTRL_SHIFT
;
82 if (currctrl
->ecc_enable
)
83 reg
|= ISPCSI2_CTRL_ECC_EN
;
85 reg
&= ~ISPCSI2_CTRL_ECC_EN
;
87 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_CTRL
);
90 static const unsigned int csi2_input_fmts
[] = {
91 V4L2_MBUS_FMT_SGRBG10_1X10
,
92 V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8
,
93 V4L2_MBUS_FMT_SRGGB10_1X10
,
94 V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8
,
95 V4L2_MBUS_FMT_SBGGR10_1X10
,
96 V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8
,
97 V4L2_MBUS_FMT_SGBRG10_1X10
,
98 V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8
,
99 V4L2_MBUS_FMT_YUYV8_2X8
,
102 /* To set the format on the CSI2 requires a mapping function that takes
103 * the following inputs:
104 * - 3 different formats (at this time)
105 * - 2 destinations (mem, vp+mem) (vp only handled separately)
106 * - 2 decompression options (on, off)
107 * - 2 isp revisions (certain format must be handled differently on OMAP3630)
108 * Output should be CSI2 frame format code
109 * Array indices as follows: [format][dest][decompr][is_3630]
110 * Not all combinations are valid. 0 means invalid.
112 static const u16 __csi2_fmt_map
[3][2][2][2] = {
115 /* Output to memory */
117 /* No DPCM decompression */
118 { CSI2_PIX_FMT_RAW10_EXP16
, CSI2_PIX_FMT_RAW10_EXP16
},
119 /* DPCM decompression */
124 /* No DPCM decompression */
125 { CSI2_PIX_FMT_RAW10_EXP16_VP
,
126 CSI2_PIX_FMT_RAW10_EXP16_VP
},
127 /* DPCM decompression */
131 /* RAW10 DPCM8 formats */
133 /* Output to memory */
135 /* No DPCM decompression */
136 { CSI2_PIX_FMT_RAW8
, CSI2_USERDEF_8BIT_DATA1
},
137 /* DPCM decompression */
138 { CSI2_PIX_FMT_RAW8_DPCM10_EXP16
,
139 CSI2_USERDEF_8BIT_DATA1_DPCM10
},
143 /* No DPCM decompression */
144 { CSI2_PIX_FMT_RAW8_VP
,
145 CSI2_PIX_FMT_RAW8_VP
},
146 /* DPCM decompression */
147 { CSI2_PIX_FMT_RAW8_DPCM10_VP
,
148 CSI2_USERDEF_8BIT_DATA1_DPCM10_VP
},
151 /* YUYV8 2X8 formats */
153 /* Output to memory */
155 /* No DPCM decompression */
156 { CSI2_PIX_FMT_YUV422_8BIT
,
157 CSI2_PIX_FMT_YUV422_8BIT
},
158 /* DPCM decompression */
163 /* No DPCM decompression */
164 { CSI2_PIX_FMT_YUV422_8BIT_VP
,
165 CSI2_PIX_FMT_YUV422_8BIT_VP
},
166 /* DPCM decompression */
173 * csi2_ctx_map_format - Map CSI2 sink media bus format to CSI2 format ID
174 * @csi2: ISP CSI2 device
176 * Returns CSI2 physical format id
178 static u16
csi2_ctx_map_format(struct isp_csi2_device
*csi2
)
180 const struct v4l2_mbus_framefmt
*fmt
= &csi2
->formats
[CSI2_PAD_SINK
];
181 int fmtidx
, destidx
, is_3630
;
184 case V4L2_MBUS_FMT_SGRBG10_1X10
:
185 case V4L2_MBUS_FMT_SRGGB10_1X10
:
186 case V4L2_MBUS_FMT_SBGGR10_1X10
:
187 case V4L2_MBUS_FMT_SGBRG10_1X10
:
190 case V4L2_MBUS_FMT_SGRBG10_DPCM8_1X8
:
191 case V4L2_MBUS_FMT_SRGGB10_DPCM8_1X8
:
192 case V4L2_MBUS_FMT_SBGGR10_DPCM8_1X8
:
193 case V4L2_MBUS_FMT_SGBRG10_DPCM8_1X8
:
196 case V4L2_MBUS_FMT_YUYV8_2X8
:
200 WARN(1, KERN_ERR
"CSI2: pixel format %08x unsupported!\n",
205 if (!(csi2
->output
& CSI2_OUTPUT_CCDC
) &&
206 !(csi2
->output
& CSI2_OUTPUT_MEMORY
)) {
207 /* Neither output enabled is a valid combination */
208 return CSI2_PIX_FMT_OTHERS
;
211 /* If we need to skip frames at the beginning of the stream disable the
212 * video port to avoid sending the skipped frames to the CCDC.
214 destidx
= csi2
->frame_skip
? 0 : !!(csi2
->output
& CSI2_OUTPUT_CCDC
);
215 is_3630
= csi2
->isp
->revision
== ISP_REVISION_15_0
;
217 return __csi2_fmt_map
[fmtidx
][destidx
][csi2
->dpcm_decompress
][is_3630
];
221 * csi2_set_outaddr - Set memory address to save output image
222 * @csi2: Pointer to ISP CSI2a device.
223 * @addr: ISP MMU Mapped 32-bit memory address aligned on 32 byte boundary.
225 * Sets the memory address where the output will be saved.
227 * Returns 0 if successful, or -EINVAL if the address is not in the 32 byte
230 static void csi2_set_outaddr(struct isp_csi2_device
*csi2
, u32 addr
)
232 struct isp_device
*isp
= csi2
->isp
;
233 struct isp_csi2_ctx_cfg
*ctx
= &csi2
->contexts
[0];
235 ctx
->ping_addr
= addr
;
236 ctx
->pong_addr
= addr
;
237 isp_reg_writel(isp
, ctx
->ping_addr
,
238 csi2
->regs1
, ISPCSI2_CTX_DAT_PING_ADDR(ctx
->ctxnum
));
239 isp_reg_writel(isp
, ctx
->pong_addr
,
240 csi2
->regs1
, ISPCSI2_CTX_DAT_PONG_ADDR(ctx
->ctxnum
));
244 * is_usr_def_mapping - Checks whether USER_DEF_MAPPING should
245 * be enabled by CSI2.
246 * @format_id: mapped format id
249 static inline int is_usr_def_mapping(u32 format_id
)
251 return (format_id
& 0x40) ? 1 : 0;
255 * csi2_ctx_enable - Enable specified CSI2 context
256 * @ctxnum: Context number, valid between 0 and 7 values.
260 static void csi2_ctx_enable(struct isp_device
*isp
,
261 struct isp_csi2_device
*csi2
, u8 ctxnum
, u8 enable
)
263 struct isp_csi2_ctx_cfg
*ctx
= &csi2
->contexts
[ctxnum
];
264 unsigned int skip
= 0;
267 reg
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_CTX_CTRL1(ctxnum
));
270 if (csi2
->frame_skip
)
271 skip
= csi2
->frame_skip
;
272 else if (csi2
->output
& CSI2_OUTPUT_MEMORY
)
275 reg
&= ~ISPCSI2_CTX_CTRL1_COUNT_MASK
;
276 reg
|= ISPCSI2_CTX_CTRL1_COUNT_UNLOCK
277 | (skip
<< ISPCSI2_CTX_CTRL1_COUNT_SHIFT
)
278 | ISPCSI2_CTX_CTRL1_CTX_EN
;
280 reg
&= ~ISPCSI2_CTX_CTRL1_CTX_EN
;
283 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_CTX_CTRL1(ctxnum
));
284 ctx
->enabled
= enable
;
288 * csi2_ctx_config - CSI2 context configuration.
289 * @ctx: context configuration
292 static void csi2_ctx_config(struct isp_device
*isp
,
293 struct isp_csi2_device
*csi2
,
294 struct isp_csi2_ctx_cfg
*ctx
)
298 /* Set up CSI2_CTx_CTRL1 */
299 reg
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_CTX_CTRL1(ctx
->ctxnum
));
301 if (ctx
->eof_enabled
)
302 reg
|= ISPCSI2_CTX_CTRL1_EOF_EN
;
304 reg
&= ~ISPCSI2_CTX_CTRL1_EOF_EN
;
306 if (ctx
->eol_enabled
)
307 reg
|= ISPCSI2_CTX_CTRL1_EOL_EN
;
309 reg
&= ~ISPCSI2_CTX_CTRL1_EOL_EN
;
311 if (ctx
->checksum_enabled
)
312 reg
|= ISPCSI2_CTX_CTRL1_CS_EN
;
314 reg
&= ~ISPCSI2_CTX_CTRL1_CS_EN
;
316 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_CTX_CTRL1(ctx
->ctxnum
));
318 /* Set up CSI2_CTx_CTRL2 */
319 reg
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_CTX_CTRL2(ctx
->ctxnum
));
321 reg
&= ~(ISPCSI2_CTX_CTRL2_VIRTUAL_ID_MASK
);
322 reg
|= ctx
->virtual_id
<< ISPCSI2_CTX_CTRL2_VIRTUAL_ID_SHIFT
;
324 reg
&= ~(ISPCSI2_CTX_CTRL2_FORMAT_MASK
);
325 reg
|= ctx
->format_id
<< ISPCSI2_CTX_CTRL2_FORMAT_SHIFT
;
327 if (ctx
->dpcm_decompress
) {
328 if (ctx
->dpcm_predictor
)
329 reg
|= ISPCSI2_CTX_CTRL2_DPCM_PRED
;
331 reg
&= ~ISPCSI2_CTX_CTRL2_DPCM_PRED
;
334 if (is_usr_def_mapping(ctx
->format_id
)) {
335 reg
&= ~ISPCSI2_CTX_CTRL2_USER_DEF_MAP_MASK
;
336 reg
|= 2 << ISPCSI2_CTX_CTRL2_USER_DEF_MAP_SHIFT
;
339 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_CTX_CTRL2(ctx
->ctxnum
));
341 /* Set up CSI2_CTx_CTRL3 */
342 reg
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_CTX_CTRL3(ctx
->ctxnum
));
343 reg
&= ~(ISPCSI2_CTX_CTRL3_ALPHA_MASK
);
344 reg
|= (ctx
->alpha
<< ISPCSI2_CTX_CTRL3_ALPHA_SHIFT
);
346 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_CTX_CTRL3(ctx
->ctxnum
));
348 /* Set up CSI2_CTx_DAT_OFST */
349 reg
= isp_reg_readl(isp
, csi2
->regs1
,
350 ISPCSI2_CTX_DAT_OFST(ctx
->ctxnum
));
351 reg
&= ~ISPCSI2_CTX_DAT_OFST_OFST_MASK
;
352 reg
|= ctx
->data_offset
<< ISPCSI2_CTX_DAT_OFST_OFST_SHIFT
;
353 isp_reg_writel(isp
, reg
, csi2
->regs1
,
354 ISPCSI2_CTX_DAT_OFST(ctx
->ctxnum
));
356 isp_reg_writel(isp
, ctx
->ping_addr
,
357 csi2
->regs1
, ISPCSI2_CTX_DAT_PING_ADDR(ctx
->ctxnum
));
359 isp_reg_writel(isp
, ctx
->pong_addr
,
360 csi2
->regs1
, ISPCSI2_CTX_DAT_PONG_ADDR(ctx
->ctxnum
));
364 * csi2_timing_config - CSI2 timing configuration.
365 * @timing: csi2_timing_cfg structure
367 static void csi2_timing_config(struct isp_device
*isp
,
368 struct isp_csi2_device
*csi2
,
369 struct isp_csi2_timing_cfg
*timing
)
373 reg
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_TIMING
);
375 if (timing
->force_rx_mode
)
376 reg
|= ISPCSI2_TIMING_FORCE_RX_MODE_IO(timing
->ionum
);
378 reg
&= ~ISPCSI2_TIMING_FORCE_RX_MODE_IO(timing
->ionum
);
380 if (timing
->stop_state_16x
)
381 reg
|= ISPCSI2_TIMING_STOP_STATE_X16_IO(timing
->ionum
);
383 reg
&= ~ISPCSI2_TIMING_STOP_STATE_X16_IO(timing
->ionum
);
385 if (timing
->stop_state_4x
)
386 reg
|= ISPCSI2_TIMING_STOP_STATE_X4_IO(timing
->ionum
);
388 reg
&= ~ISPCSI2_TIMING_STOP_STATE_X4_IO(timing
->ionum
);
390 reg
&= ~ISPCSI2_TIMING_STOP_STATE_COUNTER_IO_MASK(timing
->ionum
);
391 reg
|= timing
->stop_state_counter
<<
392 ISPCSI2_TIMING_STOP_STATE_COUNTER_IO_SHIFT(timing
->ionum
);
394 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_TIMING
);
398 * csi2_irq_ctx_set - Enables CSI2 Context IRQs.
399 * @enable: Enable/disable CSI2 Context interrupts
401 static void csi2_irq_ctx_set(struct isp_device
*isp
,
402 struct isp_csi2_device
*csi2
, int enable
)
406 for (i
= 0; i
< 8; i
++) {
407 isp_reg_writel(isp
, ISPCSI2_CTX_IRQSTATUS_FE_IRQ
, csi2
->regs1
,
408 ISPCSI2_CTX_IRQSTATUS(i
));
410 isp_reg_set(isp
, csi2
->regs1
, ISPCSI2_CTX_IRQENABLE(i
),
411 ISPCSI2_CTX_IRQSTATUS_FE_IRQ
);
413 isp_reg_clr(isp
, csi2
->regs1
, ISPCSI2_CTX_IRQENABLE(i
),
414 ISPCSI2_CTX_IRQSTATUS_FE_IRQ
);
419 * csi2_irq_complexio1_set - Enables CSI2 ComplexIO IRQs.
420 * @enable: Enable/disable CSI2 ComplexIO #1 interrupts
422 static void csi2_irq_complexio1_set(struct isp_device
*isp
,
423 struct isp_csi2_device
*csi2
, int enable
)
426 reg
= ISPCSI2_PHY_IRQENABLE_STATEALLULPMEXIT
|
427 ISPCSI2_PHY_IRQENABLE_STATEALLULPMENTER
|
428 ISPCSI2_PHY_IRQENABLE_STATEULPM5
|
429 ISPCSI2_PHY_IRQENABLE_ERRCONTROL5
|
430 ISPCSI2_PHY_IRQENABLE_ERRESC5
|
431 ISPCSI2_PHY_IRQENABLE_ERRSOTSYNCHS5
|
432 ISPCSI2_PHY_IRQENABLE_ERRSOTHS5
|
433 ISPCSI2_PHY_IRQENABLE_STATEULPM4
|
434 ISPCSI2_PHY_IRQENABLE_ERRCONTROL4
|
435 ISPCSI2_PHY_IRQENABLE_ERRESC4
|
436 ISPCSI2_PHY_IRQENABLE_ERRSOTSYNCHS4
|
437 ISPCSI2_PHY_IRQENABLE_ERRSOTHS4
|
438 ISPCSI2_PHY_IRQENABLE_STATEULPM3
|
439 ISPCSI2_PHY_IRQENABLE_ERRCONTROL3
|
440 ISPCSI2_PHY_IRQENABLE_ERRESC3
|
441 ISPCSI2_PHY_IRQENABLE_ERRSOTSYNCHS3
|
442 ISPCSI2_PHY_IRQENABLE_ERRSOTHS3
|
443 ISPCSI2_PHY_IRQENABLE_STATEULPM2
|
444 ISPCSI2_PHY_IRQENABLE_ERRCONTROL2
|
445 ISPCSI2_PHY_IRQENABLE_ERRESC2
|
446 ISPCSI2_PHY_IRQENABLE_ERRSOTSYNCHS2
|
447 ISPCSI2_PHY_IRQENABLE_ERRSOTHS2
|
448 ISPCSI2_PHY_IRQENABLE_STATEULPM1
|
449 ISPCSI2_PHY_IRQENABLE_ERRCONTROL1
|
450 ISPCSI2_PHY_IRQENABLE_ERRESC1
|
451 ISPCSI2_PHY_IRQENABLE_ERRSOTSYNCHS1
|
452 ISPCSI2_PHY_IRQENABLE_ERRSOTHS1
;
453 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_PHY_IRQSTATUS
);
455 reg
|= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_PHY_IRQENABLE
);
458 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_PHY_IRQENABLE
);
462 * csi2_irq_status_set - Enables CSI2 Status IRQs.
463 * @enable: Enable/disable CSI2 Status interrupts
465 static void csi2_irq_status_set(struct isp_device
*isp
,
466 struct isp_csi2_device
*csi2
, int enable
)
469 reg
= ISPCSI2_IRQSTATUS_OCP_ERR_IRQ
|
470 ISPCSI2_IRQSTATUS_SHORT_PACKET_IRQ
|
471 ISPCSI2_IRQSTATUS_ECC_CORRECTION_IRQ
|
472 ISPCSI2_IRQSTATUS_ECC_NO_CORRECTION_IRQ
|
473 ISPCSI2_IRQSTATUS_COMPLEXIO2_ERR_IRQ
|
474 ISPCSI2_IRQSTATUS_COMPLEXIO1_ERR_IRQ
|
475 ISPCSI2_IRQSTATUS_FIFO_OVF_IRQ
|
476 ISPCSI2_IRQSTATUS_CONTEXT(0);
477 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_IRQSTATUS
);
479 reg
|= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_IRQENABLE
);
483 isp_reg_writel(isp
, reg
, csi2
->regs1
, ISPCSI2_IRQENABLE
);
487 * omap3isp_csi2_reset - Resets the CSI2 module.
489 * Must be called with the phy lock held.
491 * Returns 0 if successful, or -EBUSY if power command didn't respond.
493 int omap3isp_csi2_reset(struct isp_csi2_device
*csi2
)
495 struct isp_device
*isp
= csi2
->isp
;
496 u8 soft_reset_retries
= 0;
500 if (!csi2
->available
)
503 if (csi2
->phy
->phy_in_use
)
506 isp_reg_set(isp
, csi2
->regs1
, ISPCSI2_SYSCONFIG
,
507 ISPCSI2_SYSCONFIG_SOFT_RESET
);
510 reg
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_SYSSTATUS
) &
511 ISPCSI2_SYSSTATUS_RESET_DONE
;
512 if (reg
== ISPCSI2_SYSSTATUS_RESET_DONE
)
514 soft_reset_retries
++;
515 if (soft_reset_retries
< 5)
517 } while (soft_reset_retries
< 5);
519 if (soft_reset_retries
== 5) {
520 dev_err(isp
->dev
, "CSI2: Soft reset try count exceeded!\n");
524 if (isp
->revision
== ISP_REVISION_15_0
)
525 isp_reg_set(isp
, csi2
->regs1
, ISPCSI2_PHY_CFG
,
526 ISPCSI2_PHY_CFG_RESET_CTRL
);
530 reg
= isp_reg_readl(isp
, csi2
->phy
->phy_regs
, ISPCSIPHY_REG1
)
531 & ISPCSIPHY_REG1_RESET_DONE_CTRLCLK
;
532 if (reg
== ISPCSIPHY_REG1_RESET_DONE_CTRLCLK
)
539 "CSI2: Reset for CSI2_96M_FCLK domain Failed!\n");
544 isp_reg_clr_set(isp
, csi2
->regs1
, ISPCSI2_SYSCONFIG
,
545 ISPCSI2_SYSCONFIG_MSTANDBY_MODE_MASK
|
546 ISPCSI2_SYSCONFIG_AUTO_IDLE
,
547 ISPCSI2_SYSCONFIG_MSTANDBY_MODE_SMART
|
548 ((isp
->revision
== ISP_REVISION_15_0
) ?
549 ISPCSI2_SYSCONFIG_AUTO_IDLE
: 0));
551 isp_reg_clr_set(isp
, csi2
->regs1
, ISPCSI2_SYSCONFIG
,
552 ISPCSI2_SYSCONFIG_MSTANDBY_MODE_MASK
|
553 ISPCSI2_SYSCONFIG_AUTO_IDLE
,
554 ISPCSI2_SYSCONFIG_MSTANDBY_MODE_NO
);
559 static int csi2_configure(struct isp_csi2_device
*csi2
)
561 const struct isp_v4l2_subdevs_group
*pdata
;
562 struct isp_device
*isp
= csi2
->isp
;
563 struct isp_csi2_timing_cfg
*timing
= &csi2
->timing
[0];
564 struct v4l2_subdev
*sensor
;
565 struct media_pad
*pad
;
568 * CSI2 fields that can be updated while the context has
569 * been enabled or the interface has been enabled are not
570 * updated dynamically currently. So we do not allow to
571 * reconfigure if either has been enabled
573 if (csi2
->contexts
[0].enabled
|| csi2
->ctrl
.if_enable
)
576 pad
= media_entity_remote_pad(&csi2
->pads
[CSI2_PAD_SINK
]);
577 sensor
= media_entity_to_v4l2_subdev(pad
->entity
);
578 pdata
= sensor
->host_priv
;
580 csi2
->frame_skip
= 0;
581 v4l2_subdev_call(sensor
, sensor
, g_skip_frames
, &csi2
->frame_skip
);
583 csi2
->ctrl
.vp_out_ctrl
= pdata
->bus
.csi2
.vpclk_div
;
584 csi2
->ctrl
.frame_mode
= ISP_CSI2_FRAME_IMMEDIATE
;
585 csi2
->ctrl
.ecc_enable
= pdata
->bus
.csi2
.crc
;
588 timing
->force_rx_mode
= 1;
589 timing
->stop_state_16x
= 1;
590 timing
->stop_state_4x
= 1;
591 timing
->stop_state_counter
= 0x1FF;
594 * The CSI2 receiver can't do any format conversion except DPCM
595 * decompression, so every set_format call configures both pads
596 * and enables DPCM decompression as a special case:
598 if (csi2
->formats
[CSI2_PAD_SINK
].code
!=
599 csi2
->formats
[CSI2_PAD_SOURCE
].code
)
600 csi2
->dpcm_decompress
= true;
602 csi2
->dpcm_decompress
= false;
604 csi2
->contexts
[0].format_id
= csi2_ctx_map_format(csi2
);
606 if (csi2
->video_out
.bpl_padding
== 0)
607 csi2
->contexts
[0].data_offset
= 0;
609 csi2
->contexts
[0].data_offset
= csi2
->video_out
.bpl_value
;
612 * Enable end of frame and end of line signals generation for
613 * context 0. These signals are generated from CSI2 receiver to
614 * qualify the last pixel of a frame and the last pixel of a line.
615 * Without enabling the signals CSI2 receiver writes data to memory
616 * beyond buffer size and/or data line offset is not handled correctly.
618 csi2
->contexts
[0].eof_enabled
= 1;
619 csi2
->contexts
[0].eol_enabled
= 1;
621 csi2_irq_complexio1_set(isp
, csi2
, 1);
622 csi2_irq_ctx_set(isp
, csi2
, 1);
623 csi2_irq_status_set(isp
, csi2
, 1);
625 /* Set configuration (timings, format and links) */
626 csi2_timing_config(isp
, csi2
, timing
);
627 csi2_recv_config(isp
, csi2
, &csi2
->ctrl
);
628 csi2_ctx_config(isp
, csi2
, &csi2
->contexts
[0]);
634 * csi2_print_status - Prints CSI2 debug information.
636 #define CSI2_PRINT_REGISTER(isp, regs, name)\
637 dev_dbg(isp->dev, "###CSI2 " #name "=0x%08x\n", \
638 isp_reg_readl(isp, regs, ISPCSI2_##name))
640 static void csi2_print_status(struct isp_csi2_device
*csi2
)
642 struct isp_device
*isp
= csi2
->isp
;
644 if (!csi2
->available
)
647 dev_dbg(isp
->dev
, "-------------CSI2 Register dump-------------\n");
649 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, SYSCONFIG
);
650 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, SYSSTATUS
);
651 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, IRQENABLE
);
652 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, IRQSTATUS
);
653 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTRL
);
654 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, DBG_H
);
655 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, GNQ
);
656 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, PHY_CFG
);
657 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, PHY_IRQSTATUS
);
658 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, SHORT_PACKET
);
659 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, PHY_IRQENABLE
);
660 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, DBG_P
);
661 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, TIMING
);
662 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_CTRL1(0));
663 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_CTRL2(0));
664 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_DAT_OFST(0));
665 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_DAT_PING_ADDR(0));
666 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_DAT_PONG_ADDR(0));
667 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_IRQENABLE(0));
668 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_IRQSTATUS(0));
669 CSI2_PRINT_REGISTER(isp
, csi2
->regs1
, CTX_CTRL3(0));
671 dev_dbg(isp
->dev
, "--------------------------------------------\n");
674 /* -----------------------------------------------------------------------------
679 * csi2_isr_buffer - Does buffer handling at end-of-frame
680 * when writing to memory.
682 static void csi2_isr_buffer(struct isp_csi2_device
*csi2
)
684 struct isp_device
*isp
= csi2
->isp
;
685 struct isp_buffer
*buffer
;
687 csi2_ctx_enable(isp
, csi2
, 0, 0);
689 buffer
= omap3isp_video_buffer_next(&csi2
->video_out
);
692 * Let video queue operation restart engine if there is an underrun
698 csi2_set_outaddr(csi2
, buffer
->isp_addr
);
699 csi2_ctx_enable(isp
, csi2
, 0, 1);
702 static void csi2_isr_ctx(struct isp_csi2_device
*csi2
,
703 struct isp_csi2_ctx_cfg
*ctx
)
705 struct isp_device
*isp
= csi2
->isp
;
706 unsigned int n
= ctx
->ctxnum
;
709 status
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_CTX_IRQSTATUS(n
));
710 isp_reg_writel(isp
, status
, csi2
->regs1
, ISPCSI2_CTX_IRQSTATUS(n
));
712 if (!(status
& ISPCSI2_CTX_IRQSTATUS_FE_IRQ
))
715 /* Skip interrupts until we reach the frame skip count. The CSI2 will be
716 * automatically disabled, as the frame skip count has been programmed
717 * in the CSI2_CTx_CTRL1::COUNT field, so reenable it.
719 * It would have been nice to rely on the FRAME_NUMBER interrupt instead
720 * but it turned out that the interrupt is only generated when the CSI2
721 * writes to memory (the CSI2_CTx_CTRL1::COUNT field is decreased
722 * correctly and reaches 0 when data is forwarded to the video port only
723 * but no interrupt arrives). Maybe a CSI2 hardware bug.
725 if (csi2
->frame_skip
) {
727 if (csi2
->frame_skip
== 0) {
728 ctx
->format_id
= csi2_ctx_map_format(csi2
);
729 csi2_ctx_config(isp
, csi2
, ctx
);
730 csi2_ctx_enable(isp
, csi2
, n
, 1);
735 if (csi2
->output
& CSI2_OUTPUT_MEMORY
)
736 csi2_isr_buffer(csi2
);
740 * omap3isp_csi2_isr - CSI2 interrupt handling.
742 void omap3isp_csi2_isr(struct isp_csi2_device
*csi2
)
744 struct isp_pipeline
*pipe
= to_isp_pipeline(&csi2
->subdev
.entity
);
745 u32 csi2_irqstatus
, cpxio1_irqstatus
;
746 struct isp_device
*isp
= csi2
->isp
;
748 if (!csi2
->available
)
751 csi2_irqstatus
= isp_reg_readl(isp
, csi2
->regs1
, ISPCSI2_IRQSTATUS
);
752 isp_reg_writel(isp
, csi2_irqstatus
, csi2
->regs1
, ISPCSI2_IRQSTATUS
);
755 if (csi2_irqstatus
& ISPCSI2_IRQSTATUS_COMPLEXIO1_ERR_IRQ
) {
756 cpxio1_irqstatus
= isp_reg_readl(isp
, csi2
->regs1
,
757 ISPCSI2_PHY_IRQSTATUS
);
758 isp_reg_writel(isp
, cpxio1_irqstatus
,
759 csi2
->regs1
, ISPCSI2_PHY_IRQSTATUS
);
760 dev_dbg(isp
->dev
, "CSI2: ComplexIO Error IRQ "
761 "%x\n", cpxio1_irqstatus
);
765 if (csi2_irqstatus
& (ISPCSI2_IRQSTATUS_OCP_ERR_IRQ
|
766 ISPCSI2_IRQSTATUS_SHORT_PACKET_IRQ
|
767 ISPCSI2_IRQSTATUS_ECC_NO_CORRECTION_IRQ
|
768 ISPCSI2_IRQSTATUS_COMPLEXIO2_ERR_IRQ
|
769 ISPCSI2_IRQSTATUS_FIFO_OVF_IRQ
)) {
770 dev_dbg(isp
->dev
, "CSI2 Err:"
778 ISPCSI2_IRQSTATUS_OCP_ERR_IRQ
) ? 1 : 0,
780 ISPCSI2_IRQSTATUS_SHORT_PACKET_IRQ
) ? 1 : 0,
782 ISPCSI2_IRQSTATUS_ECC_NO_CORRECTION_IRQ
) ? 1 : 0,
784 ISPCSI2_IRQSTATUS_COMPLEXIO2_ERR_IRQ
) ? 1 : 0,
786 ISPCSI2_IRQSTATUS_FIFO_OVF_IRQ
) ? 1 : 0);
790 if (omap3isp_module_sync_is_stopping(&csi2
->wait
, &csi2
->stopping
))
793 /* Successful cases */
794 if (csi2_irqstatus
& ISPCSI2_IRQSTATUS_CONTEXT(0))
795 csi2_isr_ctx(csi2
, &csi2
->contexts
[0]);
797 if (csi2_irqstatus
& ISPCSI2_IRQSTATUS_ECC_CORRECTION_IRQ
)
798 dev_dbg(isp
->dev
, "CSI2: ECC correction done\n");
801 /* -----------------------------------------------------------------------------
802 * ISP video operations
806 * csi2_queue - Queues the first buffer when using memory output
807 * @video: The video node
808 * @buffer: buffer to queue
810 static int csi2_queue(struct isp_video
*video
, struct isp_buffer
*buffer
)
812 struct isp_device
*isp
= video
->isp
;
813 struct isp_csi2_device
*csi2
= &isp
->isp_csi2a
;
815 csi2_set_outaddr(csi2
, buffer
->isp_addr
);
818 * If streaming was enabled before there was a buffer queued
819 * or underrun happened in the ISR, the hardware was not enabled
820 * and DMA queue flag ISP_VIDEO_DMAQUEUE_UNDERRUN is still set.
823 if (csi2
->video_out
.dmaqueue_flags
& ISP_VIDEO_DMAQUEUE_UNDERRUN
) {
824 /* Enable / disable context 0 and IRQs */
825 csi2_if_enable(isp
, csi2
, 1);
826 csi2_ctx_enable(isp
, csi2
, 0, 1);
827 isp_video_dmaqueue_flags_clr(&csi2
->video_out
);
833 static const struct isp_video_operations csi2_ispvideo_ops
= {
837 /* -----------------------------------------------------------------------------
838 * V4L2 subdev operations
841 static struct v4l2_mbus_framefmt
*
842 __csi2_get_format(struct isp_csi2_device
*csi2
, struct v4l2_subdev_fh
*fh
,
843 unsigned int pad
, enum v4l2_subdev_format_whence which
)
845 if (which
== V4L2_SUBDEV_FORMAT_TRY
)
846 return v4l2_subdev_get_try_format(fh
, pad
);
848 return &csi2
->formats
[pad
];
852 csi2_try_format(struct isp_csi2_device
*csi2
, struct v4l2_subdev_fh
*fh
,
853 unsigned int pad
, struct v4l2_mbus_framefmt
*fmt
,
854 enum v4l2_subdev_format_whence which
)
856 enum v4l2_mbus_pixelcode pixelcode
;
857 struct v4l2_mbus_framefmt
*format
;
858 const struct isp_format_info
*info
;
863 /* Clamp the width and height to valid range (1-8191). */
864 for (i
= 0; i
< ARRAY_SIZE(csi2_input_fmts
); i
++) {
865 if (fmt
->code
== csi2_input_fmts
[i
])
869 /* If not found, use SGRBG10 as default */
870 if (i
>= ARRAY_SIZE(csi2_input_fmts
))
871 fmt
->code
= V4L2_MBUS_FMT_SGRBG10_1X10
;
873 fmt
->width
= clamp_t(u32
, fmt
->width
, 1, 8191);
874 fmt
->height
= clamp_t(u32
, fmt
->height
, 1, 8191);
877 case CSI2_PAD_SOURCE
:
878 /* Source format same as sink format, except for DPCM
881 pixelcode
= fmt
->code
;
882 format
= __csi2_get_format(csi2
, fh
, CSI2_PAD_SINK
, which
);
883 memcpy(fmt
, format
, sizeof(*fmt
));
886 * Only Allow DPCM decompression, and check that the
887 * pattern is preserved
889 info
= omap3isp_video_format_info(fmt
->code
);
890 if (info
->uncompressed
== pixelcode
)
891 fmt
->code
= pixelcode
;
895 /* RGB, non-interlaced */
896 fmt
->colorspace
= V4L2_COLORSPACE_SRGB
;
897 fmt
->field
= V4L2_FIELD_NONE
;
901 * csi2_enum_mbus_code - Handle pixel format enumeration
902 * @sd : pointer to v4l2 subdev structure
903 * @fh : V4L2 subdev file handle
904 * @code : pointer to v4l2_subdev_mbus_code_enum structure
905 * return -EINVAL or zero on success
907 static int csi2_enum_mbus_code(struct v4l2_subdev
*sd
,
908 struct v4l2_subdev_fh
*fh
,
909 struct v4l2_subdev_mbus_code_enum
*code
)
911 struct isp_csi2_device
*csi2
= v4l2_get_subdevdata(sd
);
912 struct v4l2_mbus_framefmt
*format
;
913 const struct isp_format_info
*info
;
915 if (code
->pad
== CSI2_PAD_SINK
) {
916 if (code
->index
>= ARRAY_SIZE(csi2_input_fmts
))
919 code
->code
= csi2_input_fmts
[code
->index
];
921 format
= __csi2_get_format(csi2
, fh
, CSI2_PAD_SINK
,
922 V4L2_SUBDEV_FORMAT_TRY
);
923 switch (code
->index
) {
925 /* Passthrough sink pad code */
926 code
->code
= format
->code
;
929 /* Uncompressed code */
930 info
= omap3isp_video_format_info(format
->code
);
931 if (info
->uncompressed
== format
->code
)
934 code
->code
= info
->uncompressed
;
944 static int csi2_enum_frame_size(struct v4l2_subdev
*sd
,
945 struct v4l2_subdev_fh
*fh
,
946 struct v4l2_subdev_frame_size_enum
*fse
)
948 struct isp_csi2_device
*csi2
= v4l2_get_subdevdata(sd
);
949 struct v4l2_mbus_framefmt format
;
954 format
.code
= fse
->code
;
957 csi2_try_format(csi2
, fh
, fse
->pad
, &format
, V4L2_SUBDEV_FORMAT_TRY
);
958 fse
->min_width
= format
.width
;
959 fse
->min_height
= format
.height
;
961 if (format
.code
!= fse
->code
)
964 format
.code
= fse
->code
;
967 csi2_try_format(csi2
, fh
, fse
->pad
, &format
, V4L2_SUBDEV_FORMAT_TRY
);
968 fse
->max_width
= format
.width
;
969 fse
->max_height
= format
.height
;
975 * csi2_get_format - Handle get format by pads subdev method
976 * @sd : pointer to v4l2 subdev structure
977 * @fh : V4L2 subdev file handle
978 * @fmt: pointer to v4l2 subdev format structure
979 * return -EINVAL or zero on success
981 static int csi2_get_format(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
,
982 struct v4l2_subdev_format
*fmt
)
984 struct isp_csi2_device
*csi2
= v4l2_get_subdevdata(sd
);
985 struct v4l2_mbus_framefmt
*format
;
987 format
= __csi2_get_format(csi2
, fh
, fmt
->pad
, fmt
->which
);
991 fmt
->format
= *format
;
996 * csi2_set_format - Handle set format by pads subdev method
997 * @sd : pointer to v4l2 subdev structure
998 * @fh : V4L2 subdev file handle
999 * @fmt: pointer to v4l2 subdev format structure
1000 * return -EINVAL or zero on success
1002 static int csi2_set_format(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
,
1003 struct v4l2_subdev_format
*fmt
)
1005 struct isp_csi2_device
*csi2
= v4l2_get_subdevdata(sd
);
1006 struct v4l2_mbus_framefmt
*format
;
1008 format
= __csi2_get_format(csi2
, fh
, fmt
->pad
, fmt
->which
);
1012 csi2_try_format(csi2
, fh
, fmt
->pad
, &fmt
->format
, fmt
->which
);
1013 *format
= fmt
->format
;
1015 /* Propagate the format from sink to source */
1016 if (fmt
->pad
== CSI2_PAD_SINK
) {
1017 format
= __csi2_get_format(csi2
, fh
, CSI2_PAD_SOURCE
,
1019 *format
= fmt
->format
;
1020 csi2_try_format(csi2
, fh
, CSI2_PAD_SOURCE
, format
, fmt
->which
);
1027 * csi2_init_formats - Initialize formats on all pads
1028 * @sd: ISP CSI2 V4L2 subdevice
1029 * @fh: V4L2 subdev file handle
1031 * Initialize all pad formats with default values. If fh is not NULL, try
1032 * formats are initialized on the file handle. Otherwise active formats are
1033 * initialized on the device.
1035 static int csi2_init_formats(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
1037 struct v4l2_subdev_format format
;
1039 memset(&format
, 0, sizeof(format
));
1040 format
.pad
= CSI2_PAD_SINK
;
1041 format
.which
= fh
? V4L2_SUBDEV_FORMAT_TRY
: V4L2_SUBDEV_FORMAT_ACTIVE
;
1042 format
.format
.code
= V4L2_MBUS_FMT_SGRBG10_1X10
;
1043 format
.format
.width
= 4096;
1044 format
.format
.height
= 4096;
1045 csi2_set_format(sd
, fh
, &format
);
1051 * csi2_set_stream - Enable/Disable streaming on the CSI2 module
1052 * @sd: ISP CSI2 V4L2 subdevice
1053 * @enable: ISP pipeline stream state
1055 * Return 0 on success or a negative error code otherwise.
1057 static int csi2_set_stream(struct v4l2_subdev
*sd
, int enable
)
1059 struct isp_csi2_device
*csi2
= v4l2_get_subdevdata(sd
);
1060 struct isp_device
*isp
= csi2
->isp
;
1061 struct isp_video
*video_out
= &csi2
->video_out
;
1064 case ISP_PIPELINE_STREAM_CONTINUOUS
:
1065 if (omap3isp_csiphy_acquire(csi2
->phy
) < 0)
1067 if (csi2
->output
& CSI2_OUTPUT_MEMORY
)
1068 omap3isp_sbl_enable(isp
, OMAP3_ISP_SBL_CSI2A_WRITE
);
1069 csi2_configure(csi2
);
1070 csi2_print_status(csi2
);
1073 * When outputting to memory with no buffer available, let the
1074 * buffer queue handler start the hardware. A DMA queue flag
1075 * ISP_VIDEO_DMAQUEUE_QUEUED will be set as soon as there is
1076 * a buffer available.
1078 if (csi2
->output
& CSI2_OUTPUT_MEMORY
&&
1079 !(video_out
->dmaqueue_flags
& ISP_VIDEO_DMAQUEUE_QUEUED
))
1081 /* Enable context 0 and IRQs */
1082 atomic_set(&csi2
->stopping
, 0);
1083 csi2_ctx_enable(isp
, csi2
, 0, 1);
1084 csi2_if_enable(isp
, csi2
, 1);
1085 isp_video_dmaqueue_flags_clr(video_out
);
1088 case ISP_PIPELINE_STREAM_STOPPED
:
1089 if (csi2
->state
== ISP_PIPELINE_STREAM_STOPPED
)
1091 if (omap3isp_module_sync_idle(&sd
->entity
, &csi2
->wait
,
1093 dev_dbg(isp
->dev
, "%s: module stop timeout.\n",
1095 csi2_ctx_enable(isp
, csi2
, 0, 0);
1096 csi2_if_enable(isp
, csi2
, 0);
1097 csi2_irq_ctx_set(isp
, csi2
, 0);
1098 omap3isp_csiphy_release(csi2
->phy
);
1099 isp_video_dmaqueue_flags_clr(video_out
);
1100 omap3isp_sbl_disable(isp
, OMAP3_ISP_SBL_CSI2A_WRITE
);
1104 csi2
->state
= enable
;
1108 /* subdev video operations */
1109 static const struct v4l2_subdev_video_ops csi2_video_ops
= {
1110 .s_stream
= csi2_set_stream
,
1113 /* subdev pad operations */
1114 static const struct v4l2_subdev_pad_ops csi2_pad_ops
= {
1115 .enum_mbus_code
= csi2_enum_mbus_code
,
1116 .enum_frame_size
= csi2_enum_frame_size
,
1117 .get_fmt
= csi2_get_format
,
1118 .set_fmt
= csi2_set_format
,
1121 /* subdev operations */
1122 static const struct v4l2_subdev_ops csi2_ops
= {
1123 .video
= &csi2_video_ops
,
1124 .pad
= &csi2_pad_ops
,
1127 /* subdev internal operations */
1128 static const struct v4l2_subdev_internal_ops csi2_internal_ops
= {
1129 .open
= csi2_init_formats
,
1132 /* -----------------------------------------------------------------------------
1133 * Media entity operations
1137 * csi2_link_setup - Setup CSI2 connections.
1138 * @entity : Pointer to media entity structure
1139 * @local : Pointer to local pad array
1140 * @remote : Pointer to remote pad array
1141 * @flags : Link flags
1142 * return -EINVAL or zero on success
1144 static int csi2_link_setup(struct media_entity
*entity
,
1145 const struct media_pad
*local
,
1146 const struct media_pad
*remote
, u32 flags
)
1148 struct v4l2_subdev
*sd
= media_entity_to_v4l2_subdev(entity
);
1149 struct isp_csi2_device
*csi2
= v4l2_get_subdevdata(sd
);
1150 struct isp_csi2_ctrl_cfg
*ctrl
= &csi2
->ctrl
;
1153 * The ISP core doesn't support pipelines with multiple video outputs.
1154 * Revisit this when it will be implemented, and return -EBUSY for now.
1157 switch (local
->index
| media_entity_type(remote
->entity
)) {
1158 case CSI2_PAD_SOURCE
| MEDIA_ENT_T_DEVNODE
:
1159 if (flags
& MEDIA_LNK_FL_ENABLED
) {
1160 if (csi2
->output
& ~CSI2_OUTPUT_MEMORY
)
1162 csi2
->output
|= CSI2_OUTPUT_MEMORY
;
1164 csi2
->output
&= ~CSI2_OUTPUT_MEMORY
;
1168 case CSI2_PAD_SOURCE
| MEDIA_ENT_T_V4L2_SUBDEV
:
1169 if (flags
& MEDIA_LNK_FL_ENABLED
) {
1170 if (csi2
->output
& ~CSI2_OUTPUT_CCDC
)
1172 csi2
->output
|= CSI2_OUTPUT_CCDC
;
1174 csi2
->output
&= ~CSI2_OUTPUT_CCDC
;
1179 /* Link from camera to CSI2 is fixed... */
1183 ctrl
->vp_only_enable
=
1184 (csi2
->output
& CSI2_OUTPUT_MEMORY
) ? false : true;
1185 ctrl
->vp_clk_enable
= !!(csi2
->output
& CSI2_OUTPUT_CCDC
);
1190 /* media operations */
1191 static const struct media_entity_operations csi2_media_ops
= {
1192 .link_setup
= csi2_link_setup
,
1193 .link_validate
= v4l2_subdev_link_validate
,
1196 void omap3isp_csi2_unregister_entities(struct isp_csi2_device
*csi2
)
1198 v4l2_device_unregister_subdev(&csi2
->subdev
);
1199 omap3isp_video_unregister(&csi2
->video_out
);
1202 int omap3isp_csi2_register_entities(struct isp_csi2_device
*csi2
,
1203 struct v4l2_device
*vdev
)
1207 /* Register the subdev and video nodes. */
1208 ret
= v4l2_device_register_subdev(vdev
, &csi2
->subdev
);
1212 ret
= omap3isp_video_register(&csi2
->video_out
, vdev
);
1219 omap3isp_csi2_unregister_entities(csi2
);
1223 /* -----------------------------------------------------------------------------
1224 * ISP CSI2 initialisation and cleanup
1228 * csi2_init_entities - Initialize subdev and media entity.
1229 * @csi2: Pointer to csi2 structure.
1230 * return -ENOMEM or zero on success
1232 static int csi2_init_entities(struct isp_csi2_device
*csi2
)
1234 struct v4l2_subdev
*sd
= &csi2
->subdev
;
1235 struct media_pad
*pads
= csi2
->pads
;
1236 struct media_entity
*me
= &sd
->entity
;
1239 v4l2_subdev_init(sd
, &csi2_ops
);
1240 sd
->internal_ops
= &csi2_internal_ops
;
1241 strlcpy(sd
->name
, "OMAP3 ISP CSI2a", sizeof(sd
->name
));
1243 sd
->grp_id
= 1 << 16; /* group ID for isp subdevs */
1244 v4l2_set_subdevdata(sd
, csi2
);
1245 sd
->flags
|= V4L2_SUBDEV_FL_HAS_DEVNODE
;
1247 pads
[CSI2_PAD_SOURCE
].flags
= MEDIA_PAD_FL_SOURCE
;
1248 pads
[CSI2_PAD_SINK
].flags
= MEDIA_PAD_FL_SINK
1249 | MEDIA_PAD_FL_MUST_CONNECT
;
1251 me
->ops
= &csi2_media_ops
;
1252 ret
= media_entity_init(me
, CSI2_PADS_NUM
, pads
, 0);
1256 csi2_init_formats(sd
, NULL
);
1258 /* Video device node */
1259 csi2
->video_out
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1260 csi2
->video_out
.ops
= &csi2_ispvideo_ops
;
1261 csi2
->video_out
.bpl_alignment
= 32;
1262 csi2
->video_out
.bpl_zero_padding
= 1;
1263 csi2
->video_out
.bpl_max
= 0x1ffe0;
1264 csi2
->video_out
.isp
= csi2
->isp
;
1265 csi2
->video_out
.capture_mem
= PAGE_ALIGN(4096 * 4096) * 3;
1267 ret
= omap3isp_video_init(&csi2
->video_out
, "CSI2a");
1271 /* Connect the CSI2 subdev to the video node. */
1272 ret
= media_entity_create_link(&csi2
->subdev
.entity
, CSI2_PAD_SOURCE
,
1273 &csi2
->video_out
.video
.entity
, 0, 0);
1280 omap3isp_video_cleanup(&csi2
->video_out
);
1282 media_entity_cleanup(&csi2
->subdev
.entity
);
1287 * omap3isp_csi2_init - Routine for module driver init
1289 int omap3isp_csi2_init(struct isp_device
*isp
)
1291 struct isp_csi2_device
*csi2a
= &isp
->isp_csi2a
;
1292 struct isp_csi2_device
*csi2c
= &isp
->isp_csi2c
;
1296 csi2a
->available
= 1;
1297 csi2a
->regs1
= OMAP3_ISP_IOMEM_CSI2A_REGS1
;
1298 csi2a
->regs2
= OMAP3_ISP_IOMEM_CSI2A_REGS2
;
1299 csi2a
->phy
= &isp
->isp_csiphy2
;
1300 csi2a
->state
= ISP_PIPELINE_STREAM_STOPPED
;
1301 init_waitqueue_head(&csi2a
->wait
);
1303 ret
= csi2_init_entities(csi2a
);
1307 if (isp
->revision
== ISP_REVISION_15_0
) {
1309 csi2c
->available
= 1;
1310 csi2c
->regs1
= OMAP3_ISP_IOMEM_CSI2C_REGS1
;
1311 csi2c
->regs2
= OMAP3_ISP_IOMEM_CSI2C_REGS2
;
1312 csi2c
->phy
= &isp
->isp_csiphy1
;
1313 csi2c
->state
= ISP_PIPELINE_STREAM_STOPPED
;
1314 init_waitqueue_head(&csi2c
->wait
);
1321 * omap3isp_csi2_cleanup - Routine for module driver cleanup
1323 void omap3isp_csi2_cleanup(struct isp_device
*isp
)
1325 struct isp_csi2_device
*csi2a
= &isp
->isp_csi2a
;
1327 omap3isp_video_cleanup(&csi2a
->video_out
);
1328 media_entity_cleanup(&csi2a
->subdev
.entity
);