4 * TI OMAP3 ISP - CCDC module
6 * Copyright (C) 2009-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
27 #include <linux/module.h>
28 #include <linux/uaccess.h>
29 #include <linux/delay.h>
30 #include <linux/device.h>
31 #include <linux/dma-mapping.h>
33 #include <linux/sched.h>
34 #include <media/v4l2-event.h>
40 static struct v4l2_mbus_framefmt
*
41 __ccdc_get_format(struct isp_ccdc_device
*ccdc
, struct v4l2_subdev_fh
*fh
,
42 unsigned int pad
, enum v4l2_subdev_format_whence which
);
44 static const unsigned int ccdc_fmts
[] = {
46 V4L2_MBUS_FMT_SGRBG10_1X10
,
47 V4L2_MBUS_FMT_SRGGB10_1X10
,
48 V4L2_MBUS_FMT_SBGGR10_1X10
,
49 V4L2_MBUS_FMT_SGBRG10_1X10
,
50 V4L2_MBUS_FMT_SGRBG12_1X12
,
51 V4L2_MBUS_FMT_SRGGB12_1X12
,
52 V4L2_MBUS_FMT_SBGGR12_1X12
,
53 V4L2_MBUS_FMT_SGBRG12_1X12
,
57 * ccdc_print_status - Print current CCDC Module register values.
58 * @ccdc: Pointer to ISP CCDC device.
60 * Also prints other debug information stored in the CCDC module.
62 #define CCDC_PRINT_REGISTER(isp, name)\
63 dev_dbg(isp->dev, "###CCDC " #name "=0x%08x\n", \
64 isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_##name))
66 static void ccdc_print_status(struct isp_ccdc_device
*ccdc
)
68 struct isp_device
*isp
= to_isp_device(ccdc
);
70 dev_dbg(isp
->dev
, "-------------CCDC Register dump-------------\n");
72 CCDC_PRINT_REGISTER(isp
, PCR
);
73 CCDC_PRINT_REGISTER(isp
, SYN_MODE
);
74 CCDC_PRINT_REGISTER(isp
, HD_VD_WID
);
75 CCDC_PRINT_REGISTER(isp
, PIX_LINES
);
76 CCDC_PRINT_REGISTER(isp
, HORZ_INFO
);
77 CCDC_PRINT_REGISTER(isp
, VERT_START
);
78 CCDC_PRINT_REGISTER(isp
, VERT_LINES
);
79 CCDC_PRINT_REGISTER(isp
, CULLING
);
80 CCDC_PRINT_REGISTER(isp
, HSIZE_OFF
);
81 CCDC_PRINT_REGISTER(isp
, SDOFST
);
82 CCDC_PRINT_REGISTER(isp
, SDR_ADDR
);
83 CCDC_PRINT_REGISTER(isp
, CLAMP
);
84 CCDC_PRINT_REGISTER(isp
, DCSUB
);
85 CCDC_PRINT_REGISTER(isp
, COLPTN
);
86 CCDC_PRINT_REGISTER(isp
, BLKCMP
);
87 CCDC_PRINT_REGISTER(isp
, FPC
);
88 CCDC_PRINT_REGISTER(isp
, FPC_ADDR
);
89 CCDC_PRINT_REGISTER(isp
, VDINT
);
90 CCDC_PRINT_REGISTER(isp
, ALAW
);
91 CCDC_PRINT_REGISTER(isp
, REC656IF
);
92 CCDC_PRINT_REGISTER(isp
, CFG
);
93 CCDC_PRINT_REGISTER(isp
, FMTCFG
);
94 CCDC_PRINT_REGISTER(isp
, FMT_HORZ
);
95 CCDC_PRINT_REGISTER(isp
, FMT_VERT
);
96 CCDC_PRINT_REGISTER(isp
, PRGEVEN0
);
97 CCDC_PRINT_REGISTER(isp
, PRGEVEN1
);
98 CCDC_PRINT_REGISTER(isp
, PRGODD0
);
99 CCDC_PRINT_REGISTER(isp
, PRGODD1
);
100 CCDC_PRINT_REGISTER(isp
, VP_OUT
);
101 CCDC_PRINT_REGISTER(isp
, LSC_CONFIG
);
102 CCDC_PRINT_REGISTER(isp
, LSC_INITIAL
);
103 CCDC_PRINT_REGISTER(isp
, LSC_TABLE_BASE
);
104 CCDC_PRINT_REGISTER(isp
, LSC_TABLE_OFFSET
);
106 dev_dbg(isp
->dev
, "--------------------------------------------\n");
110 * omap3isp_ccdc_busy - Get busy state of the CCDC.
111 * @ccdc: Pointer to ISP CCDC device.
113 int omap3isp_ccdc_busy(struct isp_ccdc_device
*ccdc
)
115 struct isp_device
*isp
= to_isp_device(ccdc
);
117 return isp_reg_readl(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_PCR
) &
121 /* -----------------------------------------------------------------------------
122 * Lens Shading Compensation
126 * ccdc_lsc_validate_config - Check that LSC configuration is valid.
127 * @ccdc: Pointer to ISP CCDC device.
128 * @lsc_cfg: the LSC configuration to check.
130 * Returns 0 if the LSC configuration is valid, or -EINVAL if invalid.
132 static int ccdc_lsc_validate_config(struct isp_ccdc_device
*ccdc
,
133 struct omap3isp_ccdc_lsc_config
*lsc_cfg
)
135 struct isp_device
*isp
= to_isp_device(ccdc
);
136 struct v4l2_mbus_framefmt
*format
;
137 unsigned int paxel_width
, paxel_height
;
138 unsigned int paxel_shift_x
, paxel_shift_y
;
139 unsigned int min_width
, min_height
, min_size
;
140 unsigned int input_width
, input_height
;
142 paxel_shift_x
= lsc_cfg
->gain_mode_m
;
143 paxel_shift_y
= lsc_cfg
->gain_mode_n
;
145 if ((paxel_shift_x
< 2) || (paxel_shift_x
> 6) ||
146 (paxel_shift_y
< 2) || (paxel_shift_y
> 6)) {
147 dev_dbg(isp
->dev
, "CCDC: LSC: Invalid paxel size\n");
151 if (lsc_cfg
->offset
& 3) {
152 dev_dbg(isp
->dev
, "CCDC: LSC: Offset must be a multiple of "
157 if ((lsc_cfg
->initial_x
& 1) || (lsc_cfg
->initial_y
& 1)) {
158 dev_dbg(isp
->dev
, "CCDC: LSC: initial_x and y must be even\n");
162 format
= __ccdc_get_format(ccdc
, NULL
, CCDC_PAD_SINK
,
163 V4L2_SUBDEV_FORMAT_ACTIVE
);
164 input_width
= format
->width
;
165 input_height
= format
->height
;
167 /* Calculate minimum bytesize for validation */
168 paxel_width
= 1 << paxel_shift_x
;
169 min_width
= ((input_width
+ lsc_cfg
->initial_x
+ paxel_width
- 1)
170 >> paxel_shift_x
) + 1;
172 paxel_height
= 1 << paxel_shift_y
;
173 min_height
= ((input_height
+ lsc_cfg
->initial_y
+ paxel_height
- 1)
174 >> paxel_shift_y
) + 1;
176 min_size
= 4 * min_width
* min_height
;
177 if (min_size
> lsc_cfg
->size
) {
178 dev_dbg(isp
->dev
, "CCDC: LSC: too small table\n");
181 if (lsc_cfg
->offset
< (min_width
* 4)) {
182 dev_dbg(isp
->dev
, "CCDC: LSC: Offset is too small\n");
185 if ((lsc_cfg
->size
/ lsc_cfg
->offset
) < min_height
) {
186 dev_dbg(isp
->dev
, "CCDC: LSC: Wrong size/offset combination\n");
193 * ccdc_lsc_program_table - Program Lens Shading Compensation table address.
194 * @ccdc: Pointer to ISP CCDC device.
196 static void ccdc_lsc_program_table(struct isp_ccdc_device
*ccdc
, u32 addr
)
198 isp_reg_writel(to_isp_device(ccdc
), addr
,
199 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_LSC_TABLE_BASE
);
203 * ccdc_lsc_setup_regs - Configures the lens shading compensation module
204 * @ccdc: Pointer to ISP CCDC device.
206 static void ccdc_lsc_setup_regs(struct isp_ccdc_device
*ccdc
,
207 struct omap3isp_ccdc_lsc_config
*cfg
)
209 struct isp_device
*isp
= to_isp_device(ccdc
);
212 isp_reg_writel(isp
, cfg
->offset
, OMAP3_ISP_IOMEM_CCDC
,
213 ISPCCDC_LSC_TABLE_OFFSET
);
216 reg
|= cfg
->gain_mode_n
<< ISPCCDC_LSC_GAIN_MODE_N_SHIFT
;
217 reg
|= cfg
->gain_mode_m
<< ISPCCDC_LSC_GAIN_MODE_M_SHIFT
;
218 reg
|= cfg
->gain_format
<< ISPCCDC_LSC_GAIN_FORMAT_SHIFT
;
219 isp_reg_writel(isp
, reg
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_LSC_CONFIG
);
222 reg
&= ~ISPCCDC_LSC_INITIAL_X_MASK
;
223 reg
|= cfg
->initial_x
<< ISPCCDC_LSC_INITIAL_X_SHIFT
;
224 reg
&= ~ISPCCDC_LSC_INITIAL_Y_MASK
;
225 reg
|= cfg
->initial_y
<< ISPCCDC_LSC_INITIAL_Y_SHIFT
;
226 isp_reg_writel(isp
, reg
, OMAP3_ISP_IOMEM_CCDC
,
227 ISPCCDC_LSC_INITIAL
);
230 static int ccdc_lsc_wait_prefetch(struct isp_ccdc_device
*ccdc
)
232 struct isp_device
*isp
= to_isp_device(ccdc
);
235 isp_reg_writel(isp
, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ
,
236 OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0STATUS
);
239 for (wait
= 0; wait
< 1000; wait
++) {
240 if (isp_reg_readl(isp
, OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0STATUS
) &
241 IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ
) {
242 isp_reg_writel(isp
, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ
,
243 OMAP3_ISP_IOMEM_MAIN
, ISP_IRQ0STATUS
);
255 * __ccdc_lsc_enable - Enables/Disables the Lens Shading Compensation module.
256 * @ccdc: Pointer to ISP CCDC device.
257 * @enable: 0 Disables LSC, 1 Enables LSC.
259 static int __ccdc_lsc_enable(struct isp_ccdc_device
*ccdc
, int enable
)
261 struct isp_device
*isp
= to_isp_device(ccdc
);
262 const struct v4l2_mbus_framefmt
*format
=
263 __ccdc_get_format(ccdc
, NULL
, CCDC_PAD_SINK
,
264 V4L2_SUBDEV_FORMAT_ACTIVE
);
266 if ((format
->code
!= V4L2_MBUS_FMT_SGRBG10_1X10
) &&
267 (format
->code
!= V4L2_MBUS_FMT_SRGGB10_1X10
) &&
268 (format
->code
!= V4L2_MBUS_FMT_SBGGR10_1X10
) &&
269 (format
->code
!= V4L2_MBUS_FMT_SGBRG10_1X10
))
273 omap3isp_sbl_enable(isp
, OMAP3_ISP_SBL_CCDC_LSC_READ
);
275 isp_reg_clr_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_LSC_CONFIG
,
276 ISPCCDC_LSC_ENABLE
, enable
? ISPCCDC_LSC_ENABLE
: 0);
279 if (ccdc_lsc_wait_prefetch(ccdc
) < 0) {
280 isp_reg_clr(isp
, OMAP3_ISP_IOMEM_CCDC
,
281 ISPCCDC_LSC_CONFIG
, ISPCCDC_LSC_ENABLE
);
282 ccdc
->lsc
.state
= LSC_STATE_STOPPED
;
283 dev_warn(to_device(ccdc
), "LSC prefecth timeout\n");
286 ccdc
->lsc
.state
= LSC_STATE_RUNNING
;
288 ccdc
->lsc
.state
= LSC_STATE_STOPPING
;
294 static int ccdc_lsc_busy(struct isp_ccdc_device
*ccdc
)
296 struct isp_device
*isp
= to_isp_device(ccdc
);
298 return isp_reg_readl(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_LSC_CONFIG
) &
302 /* __ccdc_lsc_configure - Apply a new configuration to the LSC engine
303 * @ccdc: Pointer to ISP CCDC device
304 * @req: New configuration request
306 * context: in_interrupt()
308 static int __ccdc_lsc_configure(struct isp_ccdc_device
*ccdc
,
309 struct ispccdc_lsc_config_req
*req
)
314 if (ccdc_lsc_validate_config(ccdc
, &req
->config
) < 0) {
315 dev_dbg(to_device(ccdc
), "Discard LSC configuration\n");
319 if (ccdc_lsc_busy(ccdc
))
322 ccdc_lsc_setup_regs(ccdc
, &req
->config
);
323 ccdc_lsc_program_table(ccdc
, req
->table
);
328 * ccdc_lsc_error_handler - Handle LSC prefetch error scenario.
329 * @ccdc: Pointer to ISP CCDC device.
331 * Disables LSC, and defers enablement to shadow registers update time.
333 static void ccdc_lsc_error_handler(struct isp_ccdc_device
*ccdc
)
335 struct isp_device
*isp
= to_isp_device(ccdc
);
337 * From OMAP3 TRM: When this event is pending, the module
338 * goes into transparent mode (output =input). Normal
339 * operation can be resumed at the start of the next frame
341 * 1) Clearing this event
342 * 2) Disabling the LSC module
345 isp_reg_clr(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_LSC_CONFIG
,
347 ccdc
->lsc
.state
= LSC_STATE_STOPPED
;
350 static void ccdc_lsc_free_request(struct isp_ccdc_device
*ccdc
,
351 struct ispccdc_lsc_config_req
*req
)
353 struct isp_device
*isp
= to_isp_device(ccdc
);
359 dma_unmap_sg(isp
->dev
, req
->iovm
->sgt
->sgl
,
360 req
->iovm
->sgt
->nents
, DMA_TO_DEVICE
);
362 iommu_vfree(isp
->iommu
, req
->table
);
366 static void ccdc_lsc_free_queue(struct isp_ccdc_device
*ccdc
,
367 struct list_head
*queue
)
369 struct ispccdc_lsc_config_req
*req
, *n
;
372 spin_lock_irqsave(&ccdc
->lsc
.req_lock
, flags
);
373 list_for_each_entry_safe(req
, n
, queue
, list
) {
374 list_del(&req
->list
);
375 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
376 ccdc_lsc_free_request(ccdc
, req
);
377 spin_lock_irqsave(&ccdc
->lsc
.req_lock
, flags
);
379 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
382 static void ccdc_lsc_free_table_work(struct work_struct
*work
)
384 struct isp_ccdc_device
*ccdc
;
385 struct ispccdc_lsc
*lsc
;
387 lsc
= container_of(work
, struct ispccdc_lsc
, table_work
);
388 ccdc
= container_of(lsc
, struct isp_ccdc_device
, lsc
);
390 ccdc_lsc_free_queue(ccdc
, &lsc
->free_queue
);
394 * ccdc_lsc_config - Configure the LSC module from a userspace request
396 * Store the request LSC configuration in the LSC engine request pointer. The
397 * configuration will be applied to the hardware when the CCDC will be enabled,
398 * or at the next LSC interrupt if the CCDC is already running.
400 static int ccdc_lsc_config(struct isp_ccdc_device
*ccdc
,
401 struct omap3isp_ccdc_update_config
*config
)
403 struct isp_device
*isp
= to_isp_device(ccdc
);
404 struct ispccdc_lsc_config_req
*req
;
410 update
= config
->update
&
411 (OMAP3ISP_CCDC_CONFIG_LSC
| OMAP3ISP_CCDC_TBL_LSC
);
415 if (update
!= (OMAP3ISP_CCDC_CONFIG_LSC
| OMAP3ISP_CCDC_TBL_LSC
)) {
416 dev_dbg(to_device(ccdc
), "%s: Both LSC configuration and table "
417 "need to be supplied\n", __func__
);
421 req
= kzalloc(sizeof(*req
), GFP_KERNEL
);
425 if (config
->flag
& OMAP3ISP_CCDC_CONFIG_LSC
) {
426 if (copy_from_user(&req
->config
, config
->lsc_cfg
,
427 sizeof(req
->config
))) {
434 req
->table
= iommu_vmalloc(isp
->iommu
, 0, req
->config
.size
,
436 if (IS_ERR_VALUE(req
->table
)) {
442 req
->iovm
= find_iovm_area(isp
->iommu
, req
->table
);
443 if (req
->iovm
== NULL
) {
448 if (!dma_map_sg(isp
->dev
, req
->iovm
->sgt
->sgl
,
449 req
->iovm
->sgt
->nents
, DMA_TO_DEVICE
)) {
455 dma_sync_sg_for_cpu(isp
->dev
, req
->iovm
->sgt
->sgl
,
456 req
->iovm
->sgt
->nents
, DMA_TO_DEVICE
);
458 table
= da_to_va(isp
->iommu
, req
->table
);
459 if (copy_from_user(table
, config
->lsc
, req
->config
.size
)) {
464 dma_sync_sg_for_device(isp
->dev
, req
->iovm
->sgt
->sgl
,
465 req
->iovm
->sgt
->nents
, DMA_TO_DEVICE
);
468 spin_lock_irqsave(&ccdc
->lsc
.req_lock
, flags
);
469 if (ccdc
->lsc
.request
) {
470 list_add_tail(&ccdc
->lsc
.request
->list
, &ccdc
->lsc
.free_queue
);
471 schedule_work(&ccdc
->lsc
.table_work
);
473 ccdc
->lsc
.request
= req
;
474 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
480 ccdc_lsc_free_request(ccdc
, req
);
485 static inline int ccdc_lsc_is_configured(struct isp_ccdc_device
*ccdc
)
489 spin_lock_irqsave(&ccdc
->lsc
.req_lock
, flags
);
490 if (ccdc
->lsc
.active
) {
491 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
494 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
498 static int ccdc_lsc_enable(struct isp_ccdc_device
*ccdc
)
500 struct ispccdc_lsc
*lsc
= &ccdc
->lsc
;
502 if (lsc
->state
!= LSC_STATE_STOPPED
)
506 list_add_tail(&lsc
->active
->list
, &lsc
->free_queue
);
510 if (__ccdc_lsc_configure(ccdc
, lsc
->request
) < 0) {
511 omap3isp_sbl_disable(to_isp_device(ccdc
),
512 OMAP3_ISP_SBL_CCDC_LSC_READ
);
513 list_add_tail(&lsc
->request
->list
, &lsc
->free_queue
);
518 lsc
->active
= lsc
->request
;
520 __ccdc_lsc_enable(ccdc
, 1);
523 if (!list_empty(&lsc
->free_queue
))
524 schedule_work(&lsc
->table_work
);
529 /* -----------------------------------------------------------------------------
530 * Parameters configuration
534 * ccdc_configure_clamp - Configure optical-black or digital clamping
535 * @ccdc: Pointer to ISP CCDC device.
537 * The CCDC performs either optical-black or digital clamp. Configure and enable
538 * the selected clamp method.
540 static void ccdc_configure_clamp(struct isp_ccdc_device
*ccdc
)
542 struct isp_device
*isp
= to_isp_device(ccdc
);
546 clamp
= ccdc
->clamp
.obgain
<< ISPCCDC_CLAMP_OBGAIN_SHIFT
;
547 clamp
|= ccdc
->clamp
.oblen
<< ISPCCDC_CLAMP_OBSLEN_SHIFT
;
548 clamp
|= ccdc
->clamp
.oblines
<< ISPCCDC_CLAMP_OBSLN_SHIFT
;
549 clamp
|= ccdc
->clamp
.obstpixel
<< ISPCCDC_CLAMP_OBST_SHIFT
;
550 isp_reg_writel(isp
, clamp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_CLAMP
);
552 isp_reg_writel(isp
, ccdc
->clamp
.dcsubval
,
553 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_DCSUB
);
556 isp_reg_clr_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_CLAMP
,
557 ISPCCDC_CLAMP_CLAMPEN
,
558 ccdc
->obclamp
? ISPCCDC_CLAMP_CLAMPEN
: 0);
562 * ccdc_configure_fpc - Configure Faulty Pixel Correction
563 * @ccdc: Pointer to ISP CCDC device.
565 static void ccdc_configure_fpc(struct isp_ccdc_device
*ccdc
)
567 struct isp_device
*isp
= to_isp_device(ccdc
);
569 isp_reg_clr(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FPC
, ISPCCDC_FPC_FPCEN
);
574 isp_reg_writel(isp
, ccdc
->fpc
.fpcaddr
, OMAP3_ISP_IOMEM_CCDC
,
576 /* The FPNUM field must be set before enabling FPC. */
577 isp_reg_writel(isp
, (ccdc
->fpc
.fpnum
<< ISPCCDC_FPC_FPNUM_SHIFT
),
578 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FPC
);
579 isp_reg_writel(isp
, (ccdc
->fpc
.fpnum
<< ISPCCDC_FPC_FPNUM_SHIFT
) |
580 ISPCCDC_FPC_FPCEN
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FPC
);
584 * ccdc_configure_black_comp - Configure Black Level Compensation.
585 * @ccdc: Pointer to ISP CCDC device.
587 static void ccdc_configure_black_comp(struct isp_ccdc_device
*ccdc
)
589 struct isp_device
*isp
= to_isp_device(ccdc
);
592 blcomp
= ccdc
->blcomp
.b_mg
<< ISPCCDC_BLKCMP_B_MG_SHIFT
;
593 blcomp
|= ccdc
->blcomp
.gb_g
<< ISPCCDC_BLKCMP_GB_G_SHIFT
;
594 blcomp
|= ccdc
->blcomp
.gr_cy
<< ISPCCDC_BLKCMP_GR_CY_SHIFT
;
595 blcomp
|= ccdc
->blcomp
.r_ye
<< ISPCCDC_BLKCMP_R_YE_SHIFT
;
597 isp_reg_writel(isp
, blcomp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_BLKCMP
);
601 * ccdc_configure_lpf - Configure Low-Pass Filter (LPF).
602 * @ccdc: Pointer to ISP CCDC device.
604 static void ccdc_configure_lpf(struct isp_ccdc_device
*ccdc
)
606 struct isp_device
*isp
= to_isp_device(ccdc
);
608 isp_reg_clr_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SYN_MODE
,
609 ISPCCDC_SYN_MODE_LPF
,
610 ccdc
->lpf
? ISPCCDC_SYN_MODE_LPF
: 0);
614 * ccdc_configure_alaw - Configure A-law compression.
615 * @ccdc: Pointer to ISP CCDC device.
617 static void ccdc_configure_alaw(struct isp_ccdc_device
*ccdc
)
619 struct isp_device
*isp
= to_isp_device(ccdc
);
622 switch (ccdc
->syncif
.datsz
) {
627 alaw
= ISPCCDC_ALAW_GWDI_9_0
;
630 alaw
= ISPCCDC_ALAW_GWDI_10_1
;
633 alaw
= ISPCCDC_ALAW_GWDI_11_2
;
636 alaw
= ISPCCDC_ALAW_GWDI_12_3
;
641 alaw
|= ISPCCDC_ALAW_CCDTBL
;
643 isp_reg_writel(isp
, alaw
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_ALAW
);
647 * ccdc_config_imgattr - Configure sensor image specific attributes.
648 * @ccdc: Pointer to ISP CCDC device.
649 * @colptn: Color pattern of the sensor.
651 static void ccdc_config_imgattr(struct isp_ccdc_device
*ccdc
, u32 colptn
)
653 struct isp_device
*isp
= to_isp_device(ccdc
);
655 isp_reg_writel(isp
, colptn
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_COLPTN
);
659 * ccdc_config - Set CCDC configuration from userspace
660 * @ccdc: Pointer to ISP CCDC device.
661 * @userspace_add: Structure containing CCDC configuration sent from userspace.
663 * Returns 0 if successful, -EINVAL if the pointer to the configuration
664 * structure is null, or the copy_from_user function fails to copy user space
665 * memory to kernel space memory.
667 static int ccdc_config(struct isp_ccdc_device
*ccdc
,
668 struct omap3isp_ccdc_update_config
*ccdc_struct
)
670 struct isp_device
*isp
= to_isp_device(ccdc
);
673 spin_lock_irqsave(&ccdc
->lock
, flags
);
674 ccdc
->shadow_update
= 1;
675 spin_unlock_irqrestore(&ccdc
->lock
, flags
);
677 if (OMAP3ISP_CCDC_ALAW
& ccdc_struct
->update
) {
678 ccdc
->alaw
= !!(OMAP3ISP_CCDC_ALAW
& ccdc_struct
->flag
);
679 ccdc
->update
|= OMAP3ISP_CCDC_ALAW
;
682 if (OMAP3ISP_CCDC_LPF
& ccdc_struct
->update
) {
683 ccdc
->lpf
= !!(OMAP3ISP_CCDC_LPF
& ccdc_struct
->flag
);
684 ccdc
->update
|= OMAP3ISP_CCDC_LPF
;
687 if (OMAP3ISP_CCDC_BLCLAMP
& ccdc_struct
->update
) {
688 if (copy_from_user(&ccdc
->clamp
, ccdc_struct
->bclamp
,
689 sizeof(ccdc
->clamp
))) {
690 ccdc
->shadow_update
= 0;
694 ccdc
->obclamp
= !!(OMAP3ISP_CCDC_BLCLAMP
& ccdc_struct
->flag
);
695 ccdc
->update
|= OMAP3ISP_CCDC_BLCLAMP
;
698 if (OMAP3ISP_CCDC_BCOMP
& ccdc_struct
->update
) {
699 if (copy_from_user(&ccdc
->blcomp
, ccdc_struct
->blcomp
,
700 sizeof(ccdc
->blcomp
))) {
701 ccdc
->shadow_update
= 0;
705 ccdc
->update
|= OMAP3ISP_CCDC_BCOMP
;
708 ccdc
->shadow_update
= 0;
710 if (OMAP3ISP_CCDC_FPC
& ccdc_struct
->update
) {
715 if (ccdc
->state
!= ISP_PIPELINE_STREAM_STOPPED
)
718 ccdc
->fpc_en
= !!(OMAP3ISP_CCDC_FPC
& ccdc_struct
->flag
);
721 if (copy_from_user(&ccdc
->fpc
, ccdc_struct
->fpc
,
726 * table_new must be 64-bytes aligned, but it's
727 * already done by iommu_vmalloc().
729 size
= ccdc
->fpc
.fpnum
* 4;
730 table_new
= iommu_vmalloc(isp
->iommu
, 0, size
,
732 if (IS_ERR_VALUE(table_new
))
735 if (copy_from_user(da_to_va(isp
->iommu
, table_new
),
736 (__force
void __user
*)
737 ccdc
->fpc
.fpcaddr
, size
)) {
738 iommu_vfree(isp
->iommu
, table_new
);
742 table_old
= ccdc
->fpc
.fpcaddr
;
743 ccdc
->fpc
.fpcaddr
= table_new
;
746 ccdc_configure_fpc(ccdc
);
748 iommu_vfree(isp
->iommu
, table_old
);
751 return ccdc_lsc_config(ccdc
, ccdc_struct
);
754 static void ccdc_apply_controls(struct isp_ccdc_device
*ccdc
)
756 if (ccdc
->update
& OMAP3ISP_CCDC_ALAW
) {
757 ccdc_configure_alaw(ccdc
);
758 ccdc
->update
&= ~OMAP3ISP_CCDC_ALAW
;
761 if (ccdc
->update
& OMAP3ISP_CCDC_LPF
) {
762 ccdc_configure_lpf(ccdc
);
763 ccdc
->update
&= ~OMAP3ISP_CCDC_LPF
;
766 if (ccdc
->update
& OMAP3ISP_CCDC_BLCLAMP
) {
767 ccdc_configure_clamp(ccdc
);
768 ccdc
->update
&= ~OMAP3ISP_CCDC_BLCLAMP
;
771 if (ccdc
->update
& OMAP3ISP_CCDC_BCOMP
) {
772 ccdc_configure_black_comp(ccdc
);
773 ccdc
->update
&= ~OMAP3ISP_CCDC_BCOMP
;
778 * omap3isp_ccdc_restore_context - Restore values of the CCDC module registers
779 * @dev: Pointer to ISP device
781 void omap3isp_ccdc_restore_context(struct isp_device
*isp
)
783 struct isp_ccdc_device
*ccdc
= &isp
->isp_ccdc
;
785 isp_reg_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_CFG
, ISPCCDC_CFG_VDLC
);
787 ccdc
->update
= OMAP3ISP_CCDC_ALAW
| OMAP3ISP_CCDC_LPF
788 | OMAP3ISP_CCDC_BLCLAMP
| OMAP3ISP_CCDC_BCOMP
;
789 ccdc_apply_controls(ccdc
);
790 ccdc_configure_fpc(ccdc
);
793 /* -----------------------------------------------------------------------------
794 * Format- and pipeline-related configuration helpers
798 * ccdc_config_vp - Configure the Video Port.
799 * @ccdc: Pointer to ISP CCDC device.
801 static void ccdc_config_vp(struct isp_ccdc_device
*ccdc
)
803 struct isp_pipeline
*pipe
= to_isp_pipeline(&ccdc
->subdev
.entity
);
804 struct isp_device
*isp
= to_isp_device(ccdc
);
805 unsigned long l3_ick
= pipe
->l3_ick
;
806 unsigned int max_div
= isp
->revision
== ISP_REVISION_15_0
? 64 : 8;
807 unsigned int div
= 0;
810 fmtcfg_vp
= isp_reg_readl(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FMTCFG
)
811 & ~(ISPCCDC_FMTCFG_VPIN_MASK
| ISPCCDC_FMTCFG_VPIF_FRQ_MASK
);
813 switch (ccdc
->syncif
.datsz
) {
816 fmtcfg_vp
|= ISPCCDC_FMTCFG_VPIN_9_0
;
819 fmtcfg_vp
|= ISPCCDC_FMTCFG_VPIN_10_1
;
822 fmtcfg_vp
|= ISPCCDC_FMTCFG_VPIN_11_2
;
825 fmtcfg_vp
|= ISPCCDC_FMTCFG_VPIN_12_3
;
830 div
= DIV_ROUND_UP(l3_ick
, pipe
->max_rate
);
831 else if (ccdc
->vpcfg
.pixelclk
)
832 div
= l3_ick
/ ccdc
->vpcfg
.pixelclk
;
834 div
= clamp(div
, 2U, max_div
);
835 fmtcfg_vp
|= (div
- 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT
;
837 isp_reg_writel(isp
, fmtcfg_vp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FMTCFG
);
841 * ccdc_enable_vp - Enable Video Port.
842 * @ccdc: Pointer to ISP CCDC device.
843 * @enable: 0 Disables VP, 1 Enables VP
845 * This is needed for outputting image to Preview, H3A and HIST ISP submodules.
847 static void ccdc_enable_vp(struct isp_ccdc_device
*ccdc
, u8 enable
)
849 struct isp_device
*isp
= to_isp_device(ccdc
);
851 isp_reg_clr_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FMTCFG
,
852 ISPCCDC_FMTCFG_VPEN
, enable
? ISPCCDC_FMTCFG_VPEN
: 0);
856 * ccdc_config_outlineoffset - Configure memory saving output line offset
857 * @ccdc: Pointer to ISP CCDC device.
858 * @offset: Address offset to start a new line. Must be twice the
859 * Output width and aligned on 32 byte boundary
860 * @oddeven: Specifies the odd/even line pattern to be chosen to store the
862 * @numlines: Set the value 0-3 for +1-4lines, 4-7 for -1-4lines.
864 * - Configures the output line offset when stored in memory
865 * - Sets the odd/even line pattern to store the output
866 * (EVENEVEN (1), ODDEVEN (2), EVENODD (3), ODDODD (4))
867 * - Configures the number of even and odd line fields in case of rearranging
870 static void ccdc_config_outlineoffset(struct isp_ccdc_device
*ccdc
,
871 u32 offset
, u8 oddeven
, u8 numlines
)
873 struct isp_device
*isp
= to_isp_device(ccdc
);
875 isp_reg_writel(isp
, offset
& 0xffff,
876 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_HSIZE_OFF
);
878 isp_reg_clr(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SDOFST
,
879 ISPCCDC_SDOFST_FINV
);
881 isp_reg_clr(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SDOFST
,
882 ISPCCDC_SDOFST_FOFST_4L
);
886 isp_reg_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SDOFST
,
887 (numlines
& 0x7) << ISPCCDC_SDOFST_LOFST0_SHIFT
);
890 isp_reg_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SDOFST
,
891 (numlines
& 0x7) << ISPCCDC_SDOFST_LOFST1_SHIFT
);
894 isp_reg_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SDOFST
,
895 (numlines
& 0x7) << ISPCCDC_SDOFST_LOFST2_SHIFT
);
898 isp_reg_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SDOFST
,
899 (numlines
& 0x7) << ISPCCDC_SDOFST_LOFST3_SHIFT
);
907 * ccdc_set_outaddr - Set memory address to save output image
908 * @ccdc: Pointer to ISP CCDC device.
909 * @addr: ISP MMU Mapped 32-bit memory address aligned on 32 byte boundary.
911 * Sets the memory address where the output will be saved.
913 static void ccdc_set_outaddr(struct isp_ccdc_device
*ccdc
, u32 addr
)
915 struct isp_device
*isp
= to_isp_device(ccdc
);
917 isp_reg_writel(isp
, addr
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SDR_ADDR
);
921 * omap3isp_ccdc_max_rate - Calculate maximum input data rate based on the input
922 * @ccdc: Pointer to ISP CCDC device.
923 * @max_rate: Maximum calculated data rate.
925 * Returns in *max_rate less value between calculated and passed
927 void omap3isp_ccdc_max_rate(struct isp_ccdc_device
*ccdc
,
928 unsigned int *max_rate
)
930 struct isp_pipeline
*pipe
= to_isp_pipeline(&ccdc
->subdev
.entity
);
937 * TRM says that for parallel sensors the maximum data rate
938 * should be 90% form L3/2 clock, otherwise just L3/2.
940 if (ccdc
->input
== CCDC_INPUT_PARALLEL
)
941 rate
= pipe
->l3_ick
/ 2 * 9 / 10;
943 rate
= pipe
->l3_ick
/ 2;
945 *max_rate
= min(*max_rate
, rate
);
949 * ccdc_config_sync_if - Set CCDC sync interface configuration
950 * @ccdc: Pointer to ISP CCDC device.
951 * @syncif: Structure containing the sync parameters like field state, CCDC in
952 * master/slave mode, raw/yuv data, polarity of data, field, hs, vs
955 static void ccdc_config_sync_if(struct isp_ccdc_device
*ccdc
,
956 struct ispccdc_syncif
*syncif
)
958 struct isp_device
*isp
= to_isp_device(ccdc
);
959 u32 syn_mode
= isp_reg_readl(isp
, OMAP3_ISP_IOMEM_CCDC
,
962 syn_mode
|= ISPCCDC_SYN_MODE_VDHDEN
;
965 syn_mode
|= ISPCCDC_SYN_MODE_FLDSTAT
;
967 syn_mode
&= ~ISPCCDC_SYN_MODE_FLDSTAT
;
969 syn_mode
&= ~ISPCCDC_SYN_MODE_DATSIZ_MASK
;
970 switch (syncif
->datsz
) {
972 syn_mode
|= ISPCCDC_SYN_MODE_DATSIZ_8
;
975 syn_mode
|= ISPCCDC_SYN_MODE_DATSIZ_10
;
978 syn_mode
|= ISPCCDC_SYN_MODE_DATSIZ_11
;
981 syn_mode
|= ISPCCDC_SYN_MODE_DATSIZ_12
;
986 syn_mode
|= ISPCCDC_SYN_MODE_FLDMODE
;
988 syn_mode
&= ~ISPCCDC_SYN_MODE_FLDMODE
;
991 syn_mode
|= ISPCCDC_SYN_MODE_DATAPOL
;
993 syn_mode
&= ~ISPCCDC_SYN_MODE_DATAPOL
;
996 syn_mode
|= ISPCCDC_SYN_MODE_FLDPOL
;
998 syn_mode
&= ~ISPCCDC_SYN_MODE_FLDPOL
;
1001 syn_mode
|= ISPCCDC_SYN_MODE_HDPOL
;
1003 syn_mode
&= ~ISPCCDC_SYN_MODE_HDPOL
;
1006 syn_mode
|= ISPCCDC_SYN_MODE_VDPOL
;
1008 syn_mode
&= ~ISPCCDC_SYN_MODE_VDPOL
;
1010 if (syncif
->ccdc_mastermode
) {
1011 syn_mode
|= ISPCCDC_SYN_MODE_FLDOUT
| ISPCCDC_SYN_MODE_VDHDOUT
;
1013 syncif
->hs_width
<< ISPCCDC_HD_VD_WID_HDW_SHIFT
1014 | syncif
->vs_width
<< ISPCCDC_HD_VD_WID_VDW_SHIFT
,
1015 OMAP3_ISP_IOMEM_CCDC
,
1019 syncif
->ppln
<< ISPCCDC_PIX_LINES_PPLN_SHIFT
1020 | syncif
->hlprf
<< ISPCCDC_PIX_LINES_HLPRF_SHIFT
,
1021 OMAP3_ISP_IOMEM_CCDC
,
1024 syn_mode
&= ~(ISPCCDC_SYN_MODE_FLDOUT
|
1025 ISPCCDC_SYN_MODE_VDHDOUT
);
1027 isp_reg_writel(isp
, syn_mode
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SYN_MODE
);
1029 if (!syncif
->bt_r656_en
)
1030 isp_reg_clr(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_REC656IF
,
1031 ISPCCDC_REC656IF_R656ON
);
1034 /* CCDC formats descriptions */
1035 static const u32 ccdc_sgrbg_pattern
=
1036 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP0PLC0_SHIFT
|
1037 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP0PLC1_SHIFT
|
1038 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP0PLC2_SHIFT
|
1039 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP0PLC3_SHIFT
|
1040 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP1PLC0_SHIFT
|
1041 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP1PLC1_SHIFT
|
1042 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP1PLC2_SHIFT
|
1043 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP1PLC3_SHIFT
|
1044 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP2PLC0_SHIFT
|
1045 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP2PLC1_SHIFT
|
1046 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP2PLC2_SHIFT
|
1047 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP2PLC3_SHIFT
|
1048 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP3PLC0_SHIFT
|
1049 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP3PLC1_SHIFT
|
1050 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP3PLC2_SHIFT
|
1051 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP3PLC3_SHIFT
;
1053 static const u32 ccdc_srggb_pattern
=
1054 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP0PLC0_SHIFT
|
1055 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP0PLC1_SHIFT
|
1056 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP0PLC2_SHIFT
|
1057 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP0PLC3_SHIFT
|
1058 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP1PLC0_SHIFT
|
1059 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP1PLC1_SHIFT
|
1060 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP1PLC2_SHIFT
|
1061 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP1PLC3_SHIFT
|
1062 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP2PLC0_SHIFT
|
1063 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP2PLC1_SHIFT
|
1064 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP2PLC2_SHIFT
|
1065 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP2PLC3_SHIFT
|
1066 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP3PLC0_SHIFT
|
1067 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP3PLC1_SHIFT
|
1068 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP3PLC2_SHIFT
|
1069 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP3PLC3_SHIFT
;
1071 static const u32 ccdc_sbggr_pattern
=
1072 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP0PLC0_SHIFT
|
1073 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP0PLC1_SHIFT
|
1074 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP0PLC2_SHIFT
|
1075 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP0PLC3_SHIFT
|
1076 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP1PLC0_SHIFT
|
1077 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP1PLC1_SHIFT
|
1078 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP1PLC2_SHIFT
|
1079 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP1PLC3_SHIFT
|
1080 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP2PLC0_SHIFT
|
1081 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP2PLC1_SHIFT
|
1082 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP2PLC2_SHIFT
|
1083 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP2PLC3_SHIFT
|
1084 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP3PLC0_SHIFT
|
1085 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP3PLC1_SHIFT
|
1086 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP3PLC2_SHIFT
|
1087 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP3PLC3_SHIFT
;
1089 static const u32 ccdc_sgbrg_pattern
=
1090 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP0PLC0_SHIFT
|
1091 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP0PLC1_SHIFT
|
1092 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP0PLC2_SHIFT
|
1093 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP0PLC3_SHIFT
|
1094 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP1PLC0_SHIFT
|
1095 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP1PLC1_SHIFT
|
1096 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP1PLC2_SHIFT
|
1097 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP1PLC3_SHIFT
|
1098 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP2PLC0_SHIFT
|
1099 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP2PLC1_SHIFT
|
1100 ISPCCDC_COLPTN_Gb_G
<< ISPCCDC_COLPTN_CP2PLC2_SHIFT
|
1101 ISPCCDC_COLPTN_B_Mg
<< ISPCCDC_COLPTN_CP2PLC3_SHIFT
|
1102 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP3PLC0_SHIFT
|
1103 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP3PLC1_SHIFT
|
1104 ISPCCDC_COLPTN_R_Ye
<< ISPCCDC_COLPTN_CP3PLC2_SHIFT
|
1105 ISPCCDC_COLPTN_Gr_Cy
<< ISPCCDC_COLPTN_CP3PLC3_SHIFT
;
1107 static void ccdc_configure(struct isp_ccdc_device
*ccdc
)
1109 struct isp_device
*isp
= to_isp_device(ccdc
);
1110 struct isp_parallel_platform_data
*pdata
= NULL
;
1111 struct v4l2_subdev
*sensor
;
1112 struct v4l2_mbus_framefmt
*format
;
1113 struct media_pad
*pad
;
1114 unsigned long flags
;
1118 if (ccdc
->input
== CCDC_INPUT_PARALLEL
) {
1119 pad
= media_entity_remote_source(&ccdc
->pads
[CCDC_PAD_SINK
]);
1120 sensor
= media_entity_to_v4l2_subdev(pad
->entity
);
1121 pdata
= &((struct isp_v4l2_subdevs_group
*)sensor
->host_priv
)
1125 omap3isp_configure_bridge(isp
, ccdc
->input
, pdata
);
1127 ccdc
->syncif
.datsz
= pdata
? pdata
->width
: 10;
1128 ccdc_config_sync_if(ccdc
, &ccdc
->syncif
);
1131 format
= &ccdc
->formats
[CCDC_PAD_SINK
];
1133 syn_mode
= isp_reg_readl(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SYN_MODE
);
1135 /* Use the raw, unprocessed data when writing to memory. The H3A and
1136 * histogram modules are still fed with lens shading corrected data.
1138 syn_mode
&= ~ISPCCDC_SYN_MODE_VP2SDR
;
1140 if (ccdc
->output
& CCDC_OUTPUT_MEMORY
)
1141 syn_mode
|= ISPCCDC_SYN_MODE_WEN
;
1143 syn_mode
&= ~ISPCCDC_SYN_MODE_WEN
;
1145 if (ccdc
->output
& CCDC_OUTPUT_RESIZER
)
1146 syn_mode
|= ISPCCDC_SYN_MODE_SDR2RSZ
;
1148 syn_mode
&= ~ISPCCDC_SYN_MODE_SDR2RSZ
;
1150 /* Use PACK8 mode for 1byte per pixel formats. */
1151 if (omap3isp_video_format_info(format
->code
)->bpp
<= 8)
1152 syn_mode
|= ISPCCDC_SYN_MODE_PACK8
;
1154 syn_mode
&= ~ISPCCDC_SYN_MODE_PACK8
;
1156 isp_reg_writel(isp
, syn_mode
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_SYN_MODE
);
1159 switch (format
->code
) {
1160 case V4L2_MBUS_FMT_SRGGB10_1X10
:
1161 case V4L2_MBUS_FMT_SRGGB12_1X12
:
1162 ccdc_pattern
= ccdc_srggb_pattern
;
1164 case V4L2_MBUS_FMT_SBGGR10_1X10
:
1165 case V4L2_MBUS_FMT_SBGGR12_1X12
:
1166 ccdc_pattern
= ccdc_sbggr_pattern
;
1168 case V4L2_MBUS_FMT_SGBRG10_1X10
:
1169 case V4L2_MBUS_FMT_SGBRG12_1X12
:
1170 ccdc_pattern
= ccdc_sgbrg_pattern
;
1174 ccdc_pattern
= ccdc_sgrbg_pattern
;
1177 ccdc_config_imgattr(ccdc
, ccdc_pattern
);
1179 /* Generate VD0 on the last line of the image and VD1 on the
1182 isp_reg_writel(isp
, ((format
->height
- 2) << ISPCCDC_VDINT_0_SHIFT
) |
1183 ((format
->height
* 2 / 3) << ISPCCDC_VDINT_1_SHIFT
),
1184 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_VDINT
);
1186 /* CCDC_PAD_SOURCE_OF */
1187 format
= &ccdc
->formats
[CCDC_PAD_SOURCE_OF
];
1189 isp_reg_writel(isp
, (0 << ISPCCDC_HORZ_INFO_SPH_SHIFT
) |
1190 ((format
->width
- 1) << ISPCCDC_HORZ_INFO_NPH_SHIFT
),
1191 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_HORZ_INFO
);
1192 isp_reg_writel(isp
, 0 << ISPCCDC_VERT_START_SLV0_SHIFT
,
1193 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_VERT_START
);
1194 isp_reg_writel(isp
, (format
->height
- 1)
1195 << ISPCCDC_VERT_LINES_NLV_SHIFT
,
1196 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_VERT_LINES
);
1198 ccdc_config_outlineoffset(ccdc
, ccdc
->video_out
.bpl_value
, 0, 0);
1200 /* CCDC_PAD_SOURCE_VP */
1201 format
= &ccdc
->formats
[CCDC_PAD_SOURCE_VP
];
1203 isp_reg_writel(isp
, (0 << ISPCCDC_FMT_HORZ_FMTSPH_SHIFT
) |
1204 (format
->width
<< ISPCCDC_FMT_HORZ_FMTLNH_SHIFT
),
1205 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FMT_HORZ
);
1206 isp_reg_writel(isp
, (0 << ISPCCDC_FMT_VERT_FMTSLV_SHIFT
) |
1207 ((format
->height
+ 1) << ISPCCDC_FMT_VERT_FMTLNV_SHIFT
),
1208 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_FMT_VERT
);
1210 isp_reg_writel(isp
, (format
->width
<< ISPCCDC_VP_OUT_HORZ_NUM_SHIFT
) |
1211 (format
->height
<< ISPCCDC_VP_OUT_VERT_NUM_SHIFT
),
1212 OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_VP_OUT
);
1214 spin_lock_irqsave(&ccdc
->lsc
.req_lock
, flags
);
1215 if (ccdc
->lsc
.request
== NULL
)
1218 WARN_ON(ccdc
->lsc
.active
);
1220 /* Get last good LSC configuration. If it is not supported for
1221 * the current active resolution discard it.
1223 if (ccdc
->lsc
.active
== NULL
&&
1224 __ccdc_lsc_configure(ccdc
, ccdc
->lsc
.request
) == 0) {
1225 ccdc
->lsc
.active
= ccdc
->lsc
.request
;
1227 list_add_tail(&ccdc
->lsc
.request
->list
, &ccdc
->lsc
.free_queue
);
1228 schedule_work(&ccdc
->lsc
.table_work
);
1231 ccdc
->lsc
.request
= NULL
;
1234 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
1236 ccdc_apply_controls(ccdc
);
1239 static void __ccdc_enable(struct isp_ccdc_device
*ccdc
, int enable
)
1241 struct isp_device
*isp
= to_isp_device(ccdc
);
1243 isp_reg_clr_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_PCR
,
1244 ISPCCDC_PCR_EN
, enable
? ISPCCDC_PCR_EN
: 0);
1247 static int ccdc_disable(struct isp_ccdc_device
*ccdc
)
1249 unsigned long flags
;
1252 spin_lock_irqsave(&ccdc
->lock
, flags
);
1253 if (ccdc
->state
== ISP_PIPELINE_STREAM_CONTINUOUS
)
1254 ccdc
->stopping
= CCDC_STOP_REQUEST
;
1255 spin_unlock_irqrestore(&ccdc
->lock
, flags
);
1257 ret
= wait_event_timeout(ccdc
->wait
,
1258 ccdc
->stopping
== CCDC_STOP_FINISHED
,
1259 msecs_to_jiffies(2000));
1262 dev_warn(to_device(ccdc
), "CCDC stop timeout!\n");
1265 omap3isp_sbl_disable(to_isp_device(ccdc
), OMAP3_ISP_SBL_CCDC_LSC_READ
);
1267 mutex_lock(&ccdc
->ioctl_lock
);
1268 ccdc_lsc_free_request(ccdc
, ccdc
->lsc
.request
);
1269 ccdc
->lsc
.request
= ccdc
->lsc
.active
;
1270 ccdc
->lsc
.active
= NULL
;
1271 cancel_work_sync(&ccdc
->lsc
.table_work
);
1272 ccdc_lsc_free_queue(ccdc
, &ccdc
->lsc
.free_queue
);
1273 mutex_unlock(&ccdc
->ioctl_lock
);
1275 ccdc
->stopping
= CCDC_STOP_NOT_REQUESTED
;
1277 return ret
> 0 ? 0 : ret
;
1280 static void ccdc_enable(struct isp_ccdc_device
*ccdc
)
1282 if (ccdc_lsc_is_configured(ccdc
))
1283 __ccdc_lsc_enable(ccdc
, 1);
1284 __ccdc_enable(ccdc
, 1);
1287 /* -----------------------------------------------------------------------------
1288 * Interrupt handling
1292 * ccdc_sbl_busy - Poll idle state of CCDC and related SBL memory write bits
1293 * @ccdc: Pointer to ISP CCDC device.
1295 * Returns zero if the CCDC is idle and the image has been written to
1298 static int ccdc_sbl_busy(struct isp_ccdc_device
*ccdc
)
1300 struct isp_device
*isp
= to_isp_device(ccdc
);
1302 return omap3isp_ccdc_busy(ccdc
)
1303 | (isp_reg_readl(isp
, OMAP3_ISP_IOMEM_SBL
, ISPSBL_CCDC_WR_0
) &
1304 ISPSBL_CCDC_WR_0_DATA_READY
)
1305 | (isp_reg_readl(isp
, OMAP3_ISP_IOMEM_SBL
, ISPSBL_CCDC_WR_1
) &
1306 ISPSBL_CCDC_WR_0_DATA_READY
)
1307 | (isp_reg_readl(isp
, OMAP3_ISP_IOMEM_SBL
, ISPSBL_CCDC_WR_2
) &
1308 ISPSBL_CCDC_WR_0_DATA_READY
)
1309 | (isp_reg_readl(isp
, OMAP3_ISP_IOMEM_SBL
, ISPSBL_CCDC_WR_3
) &
1310 ISPSBL_CCDC_WR_0_DATA_READY
);
1314 * ccdc_sbl_wait_idle - Wait until the CCDC and related SBL are idle
1315 * @ccdc: Pointer to ISP CCDC device.
1316 * @max_wait: Max retry count in us for wait for idle/busy transition.
1318 static int ccdc_sbl_wait_idle(struct isp_ccdc_device
*ccdc
,
1319 unsigned int max_wait
)
1321 unsigned int wait
= 0;
1324 max_wait
= 10000; /* 10 ms */
1326 for (wait
= 0; wait
<= max_wait
; wait
++) {
1327 if (!ccdc_sbl_busy(ccdc
))
1337 /* __ccdc_handle_stopping - Handle CCDC and/or LSC stopping sequence
1338 * @ccdc: Pointer to ISP CCDC device.
1339 * @event: Pointing which event trigger handler
1341 * Return 1 when the event and stopping request combination is satisfyied,
1344 static int __ccdc_handle_stopping(struct isp_ccdc_device
*ccdc
, u32 event
)
1348 switch ((ccdc
->stopping
& 3) | event
) {
1349 case CCDC_STOP_REQUEST
| CCDC_EVENT_VD1
:
1350 if (ccdc
->lsc
.state
!= LSC_STATE_STOPPED
)
1351 __ccdc_lsc_enable(ccdc
, 0);
1352 __ccdc_enable(ccdc
, 0);
1353 ccdc
->stopping
= CCDC_STOP_EXECUTED
;
1356 case CCDC_STOP_EXECUTED
| CCDC_EVENT_VD0
:
1357 ccdc
->stopping
|= CCDC_STOP_CCDC_FINISHED
;
1358 if (ccdc
->lsc
.state
== LSC_STATE_STOPPED
)
1359 ccdc
->stopping
|= CCDC_STOP_LSC_FINISHED
;
1363 case CCDC_STOP_EXECUTED
| CCDC_EVENT_LSC_DONE
:
1364 ccdc
->stopping
|= CCDC_STOP_LSC_FINISHED
;
1368 case CCDC_STOP_EXECUTED
| CCDC_EVENT_VD1
:
1372 if (ccdc
->stopping
== CCDC_STOP_FINISHED
) {
1373 wake_up(&ccdc
->wait
);
1380 static void ccdc_hs_vs_isr(struct isp_ccdc_device
*ccdc
)
1382 struct video_device
*vdev
= &ccdc
->subdev
.devnode
;
1383 struct v4l2_event event
;
1385 memset(&event
, 0, sizeof(event
));
1386 event
.type
= V4L2_EVENT_OMAP3ISP_HS_VS
;
1388 v4l2_event_queue(vdev
, &event
);
1392 * ccdc_lsc_isr - Handle LSC events
1393 * @ccdc: Pointer to ISP CCDC device.
1394 * @events: LSC events
1396 static void ccdc_lsc_isr(struct isp_ccdc_device
*ccdc
, u32 events
)
1398 unsigned long flags
;
1400 if (events
& IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ
) {
1401 ccdc_lsc_error_handler(ccdc
);
1403 dev_dbg(to_device(ccdc
), "lsc prefetch error\n");
1406 if (!(events
& IRQ0STATUS_CCDC_LSC_DONE_IRQ
))
1409 /* LSC_DONE interrupt occur, there are two cases
1410 * 1. stopping for reconfiguration
1411 * 2. stopping because of STREAM OFF command
1413 spin_lock_irqsave(&ccdc
->lsc
.req_lock
, flags
);
1415 if (ccdc
->lsc
.state
== LSC_STATE_STOPPING
)
1416 ccdc
->lsc
.state
= LSC_STATE_STOPPED
;
1418 if (__ccdc_handle_stopping(ccdc
, CCDC_EVENT_LSC_DONE
))
1421 if (ccdc
->lsc
.state
!= LSC_STATE_RECONFIG
)
1424 /* LSC is in STOPPING state, change to the new state */
1425 ccdc
->lsc
.state
= LSC_STATE_STOPPED
;
1427 /* This is an exception. Start of frame and LSC_DONE interrupt
1428 * have been received on the same time. Skip this event and wait
1431 if (events
& IRQ0STATUS_HS_VS_IRQ
)
1434 /* The LSC engine is stopped at this point. Enable it if there's a
1437 if (ccdc
->lsc
.request
== NULL
)
1440 ccdc_lsc_enable(ccdc
);
1443 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
1446 static int ccdc_isr_buffer(struct isp_ccdc_device
*ccdc
)
1448 struct isp_pipeline
*pipe
= to_isp_pipeline(&ccdc
->subdev
.entity
);
1449 struct isp_device
*isp
= to_isp_device(ccdc
);
1450 struct isp_buffer
*buffer
;
1453 /* The CCDC generates VD0 interrupts even when disabled (the datasheet
1454 * doesn't explicitly state if that's supposed to happen or not, so it
1455 * can be considered as a hardware bug or as a feature, but we have to
1456 * deal with it anyway). Disabling the CCDC when no buffer is available
1457 * would thus not be enough, we need to handle the situation explicitly.
1459 if (list_empty(&ccdc
->video_out
.dmaqueue
))
1462 /* We're in continuous mode, and memory writes were disabled due to a
1463 * buffer underrun. Reenable them now that we have a buffer. The buffer
1464 * address has been set in ccdc_video_queue.
1466 if (ccdc
->state
== ISP_PIPELINE_STREAM_CONTINUOUS
&& ccdc
->underrun
) {
1472 if (ccdc_sbl_wait_idle(ccdc
, 1000)) {
1473 dev_info(isp
->dev
, "CCDC won't become idle!\n");
1477 buffer
= omap3isp_video_buffer_next(&ccdc
->video_out
, ccdc
->error
);
1478 if (buffer
!= NULL
) {
1479 ccdc_set_outaddr(ccdc
, buffer
->isp_addr
);
1483 pipe
->state
|= ISP_PIPELINE_IDLE_OUTPUT
;
1485 if (ccdc
->state
== ISP_PIPELINE_STREAM_SINGLESHOT
&&
1486 isp_pipeline_ready(pipe
))
1487 omap3isp_pipeline_set_stream(pipe
,
1488 ISP_PIPELINE_STREAM_SINGLESHOT
);
1496 * ccdc_vd0_isr - Handle VD0 event
1497 * @ccdc: Pointer to ISP CCDC device.
1499 * Executes LSC deferred enablement before next frame starts.
1501 static void ccdc_vd0_isr(struct isp_ccdc_device
*ccdc
)
1503 unsigned long flags
;
1506 if (ccdc
->output
& CCDC_OUTPUT_MEMORY
)
1507 restart
= ccdc_isr_buffer(ccdc
);
1509 spin_lock_irqsave(&ccdc
->lock
, flags
);
1510 if (__ccdc_handle_stopping(ccdc
, CCDC_EVENT_VD0
)) {
1511 spin_unlock_irqrestore(&ccdc
->lock
, flags
);
1515 if (!ccdc
->shadow_update
)
1516 ccdc_apply_controls(ccdc
);
1517 spin_unlock_irqrestore(&ccdc
->lock
, flags
);
1524 * ccdc_vd1_isr - Handle VD1 event
1525 * @ccdc: Pointer to ISP CCDC device.
1527 static void ccdc_vd1_isr(struct isp_ccdc_device
*ccdc
)
1529 unsigned long flags
;
1531 spin_lock_irqsave(&ccdc
->lsc
.req_lock
, flags
);
1534 * Depending on the CCDC pipeline state, CCDC stopping should be
1535 * handled differently. In SINGLESHOT we emulate an internal CCDC
1536 * stopping because the CCDC hw works only in continuous mode.
1537 * When CONTINUOUS pipeline state is used and the CCDC writes it's
1538 * data to memory the CCDC and LSC are stopped immediately but
1539 * without change the CCDC stopping state machine. The CCDC
1540 * stopping state machine should be used only when user request
1541 * for stopping is received (SINGLESHOT is an exeption).
1543 switch (ccdc
->state
) {
1544 case ISP_PIPELINE_STREAM_SINGLESHOT
:
1545 ccdc
->stopping
= CCDC_STOP_REQUEST
;
1548 case ISP_PIPELINE_STREAM_CONTINUOUS
:
1549 if (ccdc
->output
& CCDC_OUTPUT_MEMORY
) {
1550 if (ccdc
->lsc
.state
!= LSC_STATE_STOPPED
)
1551 __ccdc_lsc_enable(ccdc
, 0);
1552 __ccdc_enable(ccdc
, 0);
1556 case ISP_PIPELINE_STREAM_STOPPED
:
1560 if (__ccdc_handle_stopping(ccdc
, CCDC_EVENT_VD1
))
1563 if (ccdc
->lsc
.request
== NULL
)
1567 * LSC need to be reconfigured. Stop it here and on next LSC_DONE IRQ
1568 * do the appropriate changes in registers
1570 if (ccdc
->lsc
.state
== LSC_STATE_RUNNING
) {
1571 __ccdc_lsc_enable(ccdc
, 0);
1572 ccdc
->lsc
.state
= LSC_STATE_RECONFIG
;
1576 /* LSC has been in STOPPED state, enable it */
1577 if (ccdc
->lsc
.state
== LSC_STATE_STOPPED
)
1578 ccdc_lsc_enable(ccdc
);
1581 spin_unlock_irqrestore(&ccdc
->lsc
.req_lock
, flags
);
1585 * omap3isp_ccdc_isr - Configure CCDC during interframe time.
1586 * @ccdc: Pointer to ISP CCDC device.
1587 * @events: CCDC events
1589 int omap3isp_ccdc_isr(struct isp_ccdc_device
*ccdc
, u32 events
)
1591 if (ccdc
->state
== ISP_PIPELINE_STREAM_STOPPED
)
1594 if (events
& IRQ0STATUS_CCDC_VD1_IRQ
)
1597 ccdc_lsc_isr(ccdc
, events
);
1599 if (events
& IRQ0STATUS_CCDC_VD0_IRQ
)
1602 if (events
& IRQ0STATUS_HS_VS_IRQ
)
1603 ccdc_hs_vs_isr(ccdc
);
1608 /* -----------------------------------------------------------------------------
1609 * ISP video operations
1612 static int ccdc_video_queue(struct isp_video
*video
, struct isp_buffer
*buffer
)
1614 struct isp_ccdc_device
*ccdc
= &video
->isp
->isp_ccdc
;
1616 if (!(ccdc
->output
& CCDC_OUTPUT_MEMORY
))
1619 ccdc_set_outaddr(ccdc
, buffer
->isp_addr
);
1621 /* We now have a buffer queued on the output, restart the pipeline in
1622 * on the next CCDC interrupt if running in continuous mode (or when
1623 * starting the stream).
1630 static const struct isp_video_operations ccdc_video_ops
= {
1631 .queue
= ccdc_video_queue
,
1634 /* -----------------------------------------------------------------------------
1635 * V4L2 subdev operations
1639 * ccdc_ioctl - CCDC module private ioctl's
1640 * @sd: ISP CCDC V4L2 subdevice
1641 * @cmd: ioctl command
1642 * @arg: ioctl argument
1644 * Return 0 on success or a negative error code otherwise.
1646 static long ccdc_ioctl(struct v4l2_subdev
*sd
, unsigned int cmd
, void *arg
)
1648 struct isp_ccdc_device
*ccdc
= v4l2_get_subdevdata(sd
);
1652 case VIDIOC_OMAP3ISP_CCDC_CFG
:
1653 mutex_lock(&ccdc
->ioctl_lock
);
1654 ret
= ccdc_config(ccdc
, arg
);
1655 mutex_unlock(&ccdc
->ioctl_lock
);
1659 return -ENOIOCTLCMD
;
1665 static int ccdc_subscribe_event(struct v4l2_subdev
*sd
, struct v4l2_fh
*fh
,
1666 struct v4l2_event_subscription
*sub
)
1668 if (sub
->type
!= V4L2_EVENT_OMAP3ISP_HS_VS
)
1671 return v4l2_event_subscribe(fh
, sub
);
1674 static int ccdc_unsubscribe_event(struct v4l2_subdev
*sd
, struct v4l2_fh
*fh
,
1675 struct v4l2_event_subscription
*sub
)
1677 return v4l2_event_unsubscribe(fh
, sub
);
1681 * ccdc_set_stream - Enable/Disable streaming on the CCDC module
1682 * @sd: ISP CCDC V4L2 subdevice
1683 * @enable: Enable/disable stream
1685 * When writing to memory, the CCDC hardware can't be enabled without a memory
1686 * buffer to write to. As the s_stream operation is called in response to a
1687 * STREAMON call without any buffer queued yet, just update the enabled field
1688 * and return immediately. The CCDC will be enabled in ccdc_isr_buffer().
1690 * When not writing to memory enable the CCDC immediately.
1692 static int ccdc_set_stream(struct v4l2_subdev
*sd
, int enable
)
1694 struct isp_ccdc_device
*ccdc
= v4l2_get_subdevdata(sd
);
1695 struct isp_device
*isp
= to_isp_device(ccdc
);
1698 if (ccdc
->state
== ISP_PIPELINE_STREAM_STOPPED
) {
1699 if (enable
== ISP_PIPELINE_STREAM_STOPPED
)
1702 omap3isp_subclk_enable(isp
, OMAP3_ISP_SUBCLK_CCDC
);
1703 isp_reg_set(isp
, OMAP3_ISP_IOMEM_CCDC
, ISPCCDC_CFG
,
1706 ccdc_configure(ccdc
);
1708 /* TODO: Don't configure the video port if all of its output
1709 * links are inactive.
1711 ccdc_config_vp(ccdc
);
1712 ccdc_enable_vp(ccdc
, 1);
1714 ccdc_print_status(ccdc
);
1718 case ISP_PIPELINE_STREAM_CONTINUOUS
:
1719 if (ccdc
->output
& CCDC_OUTPUT_MEMORY
)
1720 omap3isp_sbl_enable(isp
, OMAP3_ISP_SBL_CCDC_WRITE
);
1722 if (ccdc
->underrun
|| !(ccdc
->output
& CCDC_OUTPUT_MEMORY
))
1728 case ISP_PIPELINE_STREAM_SINGLESHOT
:
1729 if (ccdc
->output
& CCDC_OUTPUT_MEMORY
&&
1730 ccdc
->state
!= ISP_PIPELINE_STREAM_SINGLESHOT
)
1731 omap3isp_sbl_enable(isp
, OMAP3_ISP_SBL_CCDC_WRITE
);
1736 case ISP_PIPELINE_STREAM_STOPPED
:
1737 ret
= ccdc_disable(ccdc
);
1738 if (ccdc
->output
& CCDC_OUTPUT_MEMORY
)
1739 omap3isp_sbl_disable(isp
, OMAP3_ISP_SBL_CCDC_WRITE
);
1740 omap3isp_subclk_disable(isp
, OMAP3_ISP_SUBCLK_CCDC
);
1745 ccdc
->state
= enable
;
1749 static struct v4l2_mbus_framefmt
*
1750 __ccdc_get_format(struct isp_ccdc_device
*ccdc
, struct v4l2_subdev_fh
*fh
,
1751 unsigned int pad
, enum v4l2_subdev_format_whence which
)
1753 if (which
== V4L2_SUBDEV_FORMAT_TRY
)
1754 return v4l2_subdev_get_try_format(fh
, pad
);
1756 return &ccdc
->formats
[pad
];
1760 * ccdc_try_format - Try video format on a pad
1761 * @ccdc: ISP CCDC device
1762 * @fh : V4L2 subdev file handle
1767 ccdc_try_format(struct isp_ccdc_device
*ccdc
, struct v4l2_subdev_fh
*fh
,
1768 unsigned int pad
, struct v4l2_mbus_framefmt
*fmt
,
1769 enum v4l2_subdev_format_whence which
)
1771 struct v4l2_mbus_framefmt
*format
;
1772 const struct isp_format_info
*info
;
1773 unsigned int width
= fmt
->width
;
1774 unsigned int height
= fmt
->height
;
1779 /* TODO: If the CCDC output formatter pad is connected directly
1780 * to the resizer, only YUV formats can be used.
1782 for (i
= 0; i
< ARRAY_SIZE(ccdc_fmts
); i
++) {
1783 if (fmt
->code
== ccdc_fmts
[i
])
1787 /* If not found, use SGRBG10 as default */
1788 if (i
>= ARRAY_SIZE(ccdc_fmts
))
1789 fmt
->code
= V4L2_MBUS_FMT_SGRBG10_1X10
;
1791 /* Clamp the input size. */
1792 fmt
->width
= clamp_t(u32
, width
, 32, 4096);
1793 fmt
->height
= clamp_t(u32
, height
, 32, 4096);
1796 case CCDC_PAD_SOURCE_OF
:
1797 format
= __ccdc_get_format(ccdc
, fh
, CCDC_PAD_SINK
, which
);
1798 memcpy(fmt
, format
, sizeof(*fmt
));
1800 /* The data formatter truncates the number of horizontal output
1801 * pixels to a multiple of 16. To avoid clipping data, allow
1802 * callers to request an output size bigger than the input size
1803 * up to the nearest multiple of 16.
1805 fmt
->width
= clamp_t(u32
, width
, 32, (fmt
->width
+ 15) & ~15);
1807 fmt
->height
= clamp_t(u32
, height
, 32, fmt
->height
);
1810 case CCDC_PAD_SOURCE_VP
:
1811 format
= __ccdc_get_format(ccdc
, fh
, CCDC_PAD_SINK
, which
);
1812 memcpy(fmt
, format
, sizeof(*fmt
));
1814 /* The video port interface truncates the data to 10 bits. */
1815 info
= omap3isp_video_format_info(fmt
->code
);
1816 fmt
->code
= info
->truncated
;
1818 /* The number of lines that can be clocked out from the video
1819 * port output must be at least one line less than the number
1822 fmt
->width
= clamp_t(u32
, width
, 32, fmt
->width
);
1823 fmt
->height
= clamp_t(u32
, height
, 32, fmt
->height
- 1);
1827 /* Data is written to memory unpacked, each 10-bit or 12-bit pixel is
1828 * stored on 2 bytes.
1830 fmt
->colorspace
= V4L2_COLORSPACE_SRGB
;
1831 fmt
->field
= V4L2_FIELD_NONE
;
1835 * ccdc_enum_mbus_code - Handle pixel format enumeration
1836 * @sd : pointer to v4l2 subdev structure
1837 * @fh : V4L2 subdev file handle
1838 * @code : pointer to v4l2_subdev_mbus_code_enum structure
1839 * return -EINVAL or zero on success
1841 static int ccdc_enum_mbus_code(struct v4l2_subdev
*sd
,
1842 struct v4l2_subdev_fh
*fh
,
1843 struct v4l2_subdev_mbus_code_enum
*code
)
1845 struct isp_ccdc_device
*ccdc
= v4l2_get_subdevdata(sd
);
1846 struct v4l2_mbus_framefmt
*format
;
1848 switch (code
->pad
) {
1850 if (code
->index
>= ARRAY_SIZE(ccdc_fmts
))
1853 code
->code
= ccdc_fmts
[code
->index
];
1856 case CCDC_PAD_SOURCE_OF
:
1857 case CCDC_PAD_SOURCE_VP
:
1858 /* No format conversion inside CCDC */
1859 if (code
->index
!= 0)
1862 format
= __ccdc_get_format(ccdc
, fh
, CCDC_PAD_SINK
,
1863 V4L2_SUBDEV_FORMAT_TRY
);
1865 code
->code
= format
->code
;
1875 static int ccdc_enum_frame_size(struct v4l2_subdev
*sd
,
1876 struct v4l2_subdev_fh
*fh
,
1877 struct v4l2_subdev_frame_size_enum
*fse
)
1879 struct isp_ccdc_device
*ccdc
= v4l2_get_subdevdata(sd
);
1880 struct v4l2_mbus_framefmt format
;
1882 if (fse
->index
!= 0)
1885 format
.code
= fse
->code
;
1888 ccdc_try_format(ccdc
, fh
, fse
->pad
, &format
, V4L2_SUBDEV_FORMAT_TRY
);
1889 fse
->min_width
= format
.width
;
1890 fse
->min_height
= format
.height
;
1892 if (format
.code
!= fse
->code
)
1895 format
.code
= fse
->code
;
1898 ccdc_try_format(ccdc
, fh
, fse
->pad
, &format
, V4L2_SUBDEV_FORMAT_TRY
);
1899 fse
->max_width
= format
.width
;
1900 fse
->max_height
= format
.height
;
1906 * ccdc_get_format - Retrieve the video format on a pad
1907 * @sd : ISP CCDC V4L2 subdevice
1908 * @fh : V4L2 subdev file handle
1911 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
1912 * to the format type.
1914 static int ccdc_get_format(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
,
1915 struct v4l2_subdev_format
*fmt
)
1917 struct isp_ccdc_device
*ccdc
= v4l2_get_subdevdata(sd
);
1918 struct v4l2_mbus_framefmt
*format
;
1920 format
= __ccdc_get_format(ccdc
, fh
, fmt
->pad
, fmt
->which
);
1924 fmt
->format
= *format
;
1929 * ccdc_set_format - Set the video format on a pad
1930 * @sd : ISP CCDC V4L2 subdevice
1931 * @fh : V4L2 subdev file handle
1934 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
1935 * to the format type.
1937 static int ccdc_set_format(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
,
1938 struct v4l2_subdev_format
*fmt
)
1940 struct isp_ccdc_device
*ccdc
= v4l2_get_subdevdata(sd
);
1941 struct v4l2_mbus_framefmt
*format
;
1943 format
= __ccdc_get_format(ccdc
, fh
, fmt
->pad
, fmt
->which
);
1947 ccdc_try_format(ccdc
, fh
, fmt
->pad
, &fmt
->format
, fmt
->which
);
1948 *format
= fmt
->format
;
1950 /* Propagate the format from sink to source */
1951 if (fmt
->pad
== CCDC_PAD_SINK
) {
1952 format
= __ccdc_get_format(ccdc
, fh
, CCDC_PAD_SOURCE_OF
,
1954 *format
= fmt
->format
;
1955 ccdc_try_format(ccdc
, fh
, CCDC_PAD_SOURCE_OF
, format
,
1958 format
= __ccdc_get_format(ccdc
, fh
, CCDC_PAD_SOURCE_VP
,
1960 *format
= fmt
->format
;
1961 ccdc_try_format(ccdc
, fh
, CCDC_PAD_SOURCE_VP
, format
,
1969 * ccdc_init_formats - Initialize formats on all pads
1970 * @sd: ISP CCDC V4L2 subdevice
1971 * @fh: V4L2 subdev file handle
1973 * Initialize all pad formats with default values. If fh is not NULL, try
1974 * formats are initialized on the file handle. Otherwise active formats are
1975 * initialized on the device.
1977 static int ccdc_init_formats(struct v4l2_subdev
*sd
, struct v4l2_subdev_fh
*fh
)
1979 struct v4l2_subdev_format format
;
1981 memset(&format
, 0, sizeof(format
));
1982 format
.pad
= CCDC_PAD_SINK
;
1983 format
.which
= fh
? V4L2_SUBDEV_FORMAT_TRY
: V4L2_SUBDEV_FORMAT_ACTIVE
;
1984 format
.format
.code
= V4L2_MBUS_FMT_SGRBG10_1X10
;
1985 format
.format
.width
= 4096;
1986 format
.format
.height
= 4096;
1987 ccdc_set_format(sd
, fh
, &format
);
1992 /* V4L2 subdev core operations */
1993 static const struct v4l2_subdev_core_ops ccdc_v4l2_core_ops
= {
1994 .ioctl
= ccdc_ioctl
,
1995 .subscribe_event
= ccdc_subscribe_event
,
1996 .unsubscribe_event
= ccdc_unsubscribe_event
,
1999 /* V4L2 subdev video operations */
2000 static const struct v4l2_subdev_video_ops ccdc_v4l2_video_ops
= {
2001 .s_stream
= ccdc_set_stream
,
2004 /* V4L2 subdev pad operations */
2005 static const struct v4l2_subdev_pad_ops ccdc_v4l2_pad_ops
= {
2006 .enum_mbus_code
= ccdc_enum_mbus_code
,
2007 .enum_frame_size
= ccdc_enum_frame_size
,
2008 .get_fmt
= ccdc_get_format
,
2009 .set_fmt
= ccdc_set_format
,
2012 /* V4L2 subdev operations */
2013 static const struct v4l2_subdev_ops ccdc_v4l2_ops
= {
2014 .core
= &ccdc_v4l2_core_ops
,
2015 .video
= &ccdc_v4l2_video_ops
,
2016 .pad
= &ccdc_v4l2_pad_ops
,
2019 /* V4L2 subdev internal operations */
2020 static const struct v4l2_subdev_internal_ops ccdc_v4l2_internal_ops
= {
2021 .open
= ccdc_init_formats
,
2024 /* -----------------------------------------------------------------------------
2025 * Media entity operations
2029 * ccdc_link_setup - Setup CCDC connections
2030 * @entity: CCDC media entity
2031 * @local: Pad at the local end of the link
2032 * @remote: Pad at the remote end of the link
2033 * @flags: Link flags
2035 * return -EINVAL or zero on success
2037 static int ccdc_link_setup(struct media_entity
*entity
,
2038 const struct media_pad
*local
,
2039 const struct media_pad
*remote
, u32 flags
)
2041 struct v4l2_subdev
*sd
= media_entity_to_v4l2_subdev(entity
);
2042 struct isp_ccdc_device
*ccdc
= v4l2_get_subdevdata(sd
);
2043 struct isp_device
*isp
= to_isp_device(ccdc
);
2045 switch (local
->index
| media_entity_type(remote
->entity
)) {
2046 case CCDC_PAD_SINK
| MEDIA_ENT_T_V4L2_SUBDEV
:
2047 /* Read from the sensor (parallel interface), CCP2, CSI2a or
2050 if (!(flags
& MEDIA_LNK_FL_ENABLED
)) {
2051 ccdc
->input
= CCDC_INPUT_NONE
;
2055 if (ccdc
->input
!= CCDC_INPUT_NONE
)
2058 if (remote
->entity
== &isp
->isp_ccp2
.subdev
.entity
)
2059 ccdc
->input
= CCDC_INPUT_CCP2B
;
2060 else if (remote
->entity
== &isp
->isp_csi2a
.subdev
.entity
)
2061 ccdc
->input
= CCDC_INPUT_CSI2A
;
2062 else if (remote
->entity
== &isp
->isp_csi2c
.subdev
.entity
)
2063 ccdc
->input
= CCDC_INPUT_CSI2C
;
2065 ccdc
->input
= CCDC_INPUT_PARALLEL
;
2070 * The ISP core doesn't support pipelines with multiple video outputs.
2071 * Revisit this when it will be implemented, and return -EBUSY for now.
2074 case CCDC_PAD_SOURCE_VP
| MEDIA_ENT_T_V4L2_SUBDEV
:
2075 /* Write to preview engine, histogram and H3A. When none of
2076 * those links are active, the video port can be disabled.
2078 if (flags
& MEDIA_LNK_FL_ENABLED
) {
2079 if (ccdc
->output
& ~CCDC_OUTPUT_PREVIEW
)
2081 ccdc
->output
|= CCDC_OUTPUT_PREVIEW
;
2083 ccdc
->output
&= ~CCDC_OUTPUT_PREVIEW
;
2087 case CCDC_PAD_SOURCE_OF
| MEDIA_ENT_T_DEVNODE
:
2088 /* Write to memory */
2089 if (flags
& MEDIA_LNK_FL_ENABLED
) {
2090 if (ccdc
->output
& ~CCDC_OUTPUT_MEMORY
)
2092 ccdc
->output
|= CCDC_OUTPUT_MEMORY
;
2094 ccdc
->output
&= ~CCDC_OUTPUT_MEMORY
;
2098 case CCDC_PAD_SOURCE_OF
| MEDIA_ENT_T_V4L2_SUBDEV
:
2099 /* Write to resizer */
2100 if (flags
& MEDIA_LNK_FL_ENABLED
) {
2101 if (ccdc
->output
& ~CCDC_OUTPUT_RESIZER
)
2103 ccdc
->output
|= CCDC_OUTPUT_RESIZER
;
2105 ccdc
->output
&= ~CCDC_OUTPUT_RESIZER
;
2116 /* media operations */
2117 static const struct media_entity_operations ccdc_media_ops
= {
2118 .link_setup
= ccdc_link_setup
,
2122 * ccdc_init_entities - Initialize V4L2 subdev and media entity
2123 * @ccdc: ISP CCDC module
2125 * Return 0 on success and a negative error code on failure.
2127 static int ccdc_init_entities(struct isp_ccdc_device
*ccdc
)
2129 struct v4l2_subdev
*sd
= &ccdc
->subdev
;
2130 struct media_pad
*pads
= ccdc
->pads
;
2131 struct media_entity
*me
= &sd
->entity
;
2134 ccdc
->input
= CCDC_INPUT_NONE
;
2136 v4l2_subdev_init(sd
, &ccdc_v4l2_ops
);
2137 sd
->internal_ops
= &ccdc_v4l2_internal_ops
;
2138 strlcpy(sd
->name
, "OMAP3 ISP CCDC", sizeof(sd
->name
));
2139 sd
->grp_id
= 1 << 16; /* group ID for isp subdevs */
2140 v4l2_set_subdevdata(sd
, ccdc
);
2141 sd
->flags
|= V4L2_SUBDEV_FL_HAS_EVENTS
| V4L2_SUBDEV_FL_HAS_DEVNODE
;
2142 sd
->nevents
= OMAP3ISP_CCDC_NEVENTS
;
2144 pads
[CCDC_PAD_SINK
].flags
= MEDIA_PAD_FL_SINK
;
2145 pads
[CCDC_PAD_SOURCE_VP
].flags
= MEDIA_PAD_FL_SOURCE
;
2146 pads
[CCDC_PAD_SOURCE_OF
].flags
= MEDIA_PAD_FL_SOURCE
;
2148 me
->ops
= &ccdc_media_ops
;
2149 ret
= media_entity_init(me
, CCDC_PADS_NUM
, pads
, 0);
2153 ccdc_init_formats(sd
, NULL
);
2155 ccdc
->video_out
.type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
2156 ccdc
->video_out
.ops
= &ccdc_video_ops
;
2157 ccdc
->video_out
.isp
= to_isp_device(ccdc
);
2158 ccdc
->video_out
.capture_mem
= PAGE_ALIGN(4096 * 4096) * 3;
2159 ccdc
->video_out
.bpl_alignment
= 32;
2161 ret
= omap3isp_video_init(&ccdc
->video_out
, "CCDC");
2165 /* Connect the CCDC subdev to the video node. */
2166 ret
= media_entity_create_link(&ccdc
->subdev
.entity
, CCDC_PAD_SOURCE_OF
,
2167 &ccdc
->video_out
.video
.entity
, 0, 0);
2174 void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device
*ccdc
)
2176 media_entity_cleanup(&ccdc
->subdev
.entity
);
2178 v4l2_device_unregister_subdev(&ccdc
->subdev
);
2179 omap3isp_video_unregister(&ccdc
->video_out
);
2182 int omap3isp_ccdc_register_entities(struct isp_ccdc_device
*ccdc
,
2183 struct v4l2_device
*vdev
)
2187 /* Register the subdev and video node. */
2188 ret
= v4l2_device_register_subdev(vdev
, &ccdc
->subdev
);
2192 ret
= omap3isp_video_register(&ccdc
->video_out
, vdev
);
2199 omap3isp_ccdc_unregister_entities(ccdc
);
2203 /* -----------------------------------------------------------------------------
2204 * ISP CCDC initialisation and cleanup
2208 * omap3isp_ccdc_init - CCDC module initialization.
2209 * @dev: Device pointer specific to the OMAP3 ISP.
2211 * TODO: Get the initialisation values from platform data.
2213 * Return 0 on success or a negative error code otherwise.
2215 int omap3isp_ccdc_init(struct isp_device
*isp
)
2217 struct isp_ccdc_device
*ccdc
= &isp
->isp_ccdc
;
2219 spin_lock_init(&ccdc
->lock
);
2220 init_waitqueue_head(&ccdc
->wait
);
2221 mutex_init(&ccdc
->ioctl_lock
);
2223 ccdc
->stopping
= CCDC_STOP_NOT_REQUESTED
;
2225 INIT_WORK(&ccdc
->lsc
.table_work
, ccdc_lsc_free_table_work
);
2226 ccdc
->lsc
.state
= LSC_STATE_STOPPED
;
2227 INIT_LIST_HEAD(&ccdc
->lsc
.free_queue
);
2228 spin_lock_init(&ccdc
->lsc
.req_lock
);
2230 ccdc
->syncif
.ccdc_mastermode
= 0;
2231 ccdc
->syncif
.datapol
= 0;
2232 ccdc
->syncif
.datsz
= 0;
2233 ccdc
->syncif
.fldmode
= 0;
2234 ccdc
->syncif
.fldout
= 0;
2235 ccdc
->syncif
.fldpol
= 0;
2236 ccdc
->syncif
.fldstat
= 0;
2237 ccdc
->syncif
.hdpol
= 0;
2238 ccdc
->syncif
.vdpol
= 0;
2240 ccdc
->clamp
.oblen
= 0;
2241 ccdc
->clamp
.dcsubval
= 0;
2243 ccdc
->vpcfg
.pixelclk
= 0;
2245 ccdc
->update
= OMAP3ISP_CCDC_BLCLAMP
;
2246 ccdc_apply_controls(ccdc
);
2248 return ccdc_init_entities(ccdc
);
2252 * omap3isp_ccdc_cleanup - CCDC module cleanup.
2253 * @dev: Device pointer specific to the OMAP3 ISP.
2255 void omap3isp_ccdc_cleanup(struct isp_device
*isp
)
2257 struct isp_ccdc_device
*ccdc
= &isp
->isp_ccdc
;
2259 /* Free LSC requests. As the CCDC is stopped there's no active request,
2260 * so only the pending request and the free queue need to be handled.
2262 ccdc_lsc_free_request(ccdc
, ccdc
->lsc
.request
);
2263 cancel_work_sync(&ccdc
->lsc
.table_work
);
2264 ccdc_lsc_free_queue(ccdc
, &ccdc
->lsc
.free_queue
);
2266 if (ccdc
->fpc
.fpcaddr
!= 0)
2267 iommu_vfree(isp
->iommu
, ccdc
->fpc
.fpcaddr
);