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 <linux/slab.h>
35 #include <media/v4l2-event.h>
41 #define CCDC_MIN_WIDTH 32
42 #define CCDC_MIN_HEIGHT 32
44 static struct v4l2_mbus_framefmt *
45 __ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
46 unsigned int pad, enum v4l2_subdev_format_whence which);
48 static const unsigned int ccdc_fmts[] = {
50 V4L2_MBUS_FMT_Y10_1X10,
51 V4L2_MBUS_FMT_Y12_1X12,
52 V4L2_MBUS_FMT_SGRBG8_1X8,
53 V4L2_MBUS_FMT_SRGGB8_1X8,
54 V4L2_MBUS_FMT_SBGGR8_1X8,
55 V4L2_MBUS_FMT_SGBRG8_1X8,
56 V4L2_MBUS_FMT_SGRBG10_1X10,
57 V4L2_MBUS_FMT_SRGGB10_1X10,
58 V4L2_MBUS_FMT_SBGGR10_1X10,
59 V4L2_MBUS_FMT_SGBRG10_1X10,
60 V4L2_MBUS_FMT_SGRBG12_1X12,
61 V4L2_MBUS_FMT_SRGGB12_1X12,
62 V4L2_MBUS_FMT_SBGGR12_1X12,
63 V4L2_MBUS_FMT_SGBRG12_1X12,
64 V4L2_MBUS_FMT_YUYV8_2X8,
65 V4L2_MBUS_FMT_UYVY8_2X8,
69 * ccdc_print_status - Print current CCDC Module register values.
70 * @ccdc: Pointer to ISP CCDC device.
72 * Also prints other debug information stored in the CCDC module.
74 #define CCDC_PRINT_REGISTER(isp, name)\
75 dev_dbg(isp->dev, "###CCDC " #name "=0x%08x\n", \
76 isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_##name))
78 static void ccdc_print_status(struct isp_ccdc_device *ccdc)
80 struct isp_device *isp = to_isp_device(ccdc);
82 dev_dbg(isp->dev, "-------------CCDC Register dump-------------\n");
84 CCDC_PRINT_REGISTER(isp, PCR);
85 CCDC_PRINT_REGISTER(isp, SYN_MODE);
86 CCDC_PRINT_REGISTER(isp, HD_VD_WID);
87 CCDC_PRINT_REGISTER(isp, PIX_LINES);
88 CCDC_PRINT_REGISTER(isp, HORZ_INFO);
89 CCDC_PRINT_REGISTER(isp, VERT_START);
90 CCDC_PRINT_REGISTER(isp, VERT_LINES);
91 CCDC_PRINT_REGISTER(isp, CULLING);
92 CCDC_PRINT_REGISTER(isp, HSIZE_OFF);
93 CCDC_PRINT_REGISTER(isp, SDOFST);
94 CCDC_PRINT_REGISTER(isp, SDR_ADDR);
95 CCDC_PRINT_REGISTER(isp, CLAMP);
96 CCDC_PRINT_REGISTER(isp, DCSUB);
97 CCDC_PRINT_REGISTER(isp, COLPTN);
98 CCDC_PRINT_REGISTER(isp, BLKCMP);
99 CCDC_PRINT_REGISTER(isp, FPC);
100 CCDC_PRINT_REGISTER(isp, FPC_ADDR);
101 CCDC_PRINT_REGISTER(isp, VDINT);
102 CCDC_PRINT_REGISTER(isp, ALAW);
103 CCDC_PRINT_REGISTER(isp, REC656IF);
104 CCDC_PRINT_REGISTER(isp, CFG);
105 CCDC_PRINT_REGISTER(isp, FMTCFG);
106 CCDC_PRINT_REGISTER(isp, FMT_HORZ);
107 CCDC_PRINT_REGISTER(isp, FMT_VERT);
108 CCDC_PRINT_REGISTER(isp, PRGEVEN0);
109 CCDC_PRINT_REGISTER(isp, PRGEVEN1);
110 CCDC_PRINT_REGISTER(isp, PRGODD0);
111 CCDC_PRINT_REGISTER(isp, PRGODD1);
112 CCDC_PRINT_REGISTER(isp, VP_OUT);
113 CCDC_PRINT_REGISTER(isp, LSC_CONFIG);
114 CCDC_PRINT_REGISTER(isp, LSC_INITIAL);
115 CCDC_PRINT_REGISTER(isp, LSC_TABLE_BASE);
116 CCDC_PRINT_REGISTER(isp, LSC_TABLE_OFFSET);
118 dev_dbg(isp->dev, "--------------------------------------------\n");
122 * omap3isp_ccdc_busy - Get busy state of the CCDC.
123 * @ccdc: Pointer to ISP CCDC device.
125 int omap3isp_ccdc_busy(struct isp_ccdc_device *ccdc)
127 struct isp_device *isp = to_isp_device(ccdc);
129 return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR) &
133 /* -----------------------------------------------------------------------------
134 * Lens Shading Compensation
138 * ccdc_lsc_validate_config - Check that LSC configuration is valid.
139 * @ccdc: Pointer to ISP CCDC device.
140 * @lsc_cfg: the LSC configuration to check.
142 * Returns 0 if the LSC configuration is valid, or -EINVAL if invalid.
144 static int ccdc_lsc_validate_config(struct isp_ccdc_device *ccdc,
145 struct omap3isp_ccdc_lsc_config *lsc_cfg)
147 struct isp_device *isp = to_isp_device(ccdc);
148 struct v4l2_mbus_framefmt *format;
149 unsigned int paxel_width, paxel_height;
150 unsigned int paxel_shift_x, paxel_shift_y;
151 unsigned int min_width, min_height, min_size;
152 unsigned int input_width, input_height;
154 paxel_shift_x = lsc_cfg->gain_mode_m;
155 paxel_shift_y = lsc_cfg->gain_mode_n;
157 if ((paxel_shift_x < 2) || (paxel_shift_x > 6) ||
158 (paxel_shift_y < 2) || (paxel_shift_y > 6)) {
159 dev_dbg(isp->dev, "CCDC: LSC: Invalid paxel size\n");
163 if (lsc_cfg->offset & 3) {
164 dev_dbg(isp->dev, "CCDC: LSC: Offset must be a multiple of "
169 if ((lsc_cfg->initial_x & 1) || (lsc_cfg->initial_y & 1)) {
170 dev_dbg(isp->dev, "CCDC: LSC: initial_x and y must be even\n");
174 format = __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK,
175 V4L2_SUBDEV_FORMAT_ACTIVE);
176 input_width = format->width;
177 input_height = format->height;
179 /* Calculate minimum bytesize for validation */
180 paxel_width = 1 << paxel_shift_x;
181 min_width = ((input_width + lsc_cfg->initial_x + paxel_width - 1)
182 >> paxel_shift_x) + 1;
184 paxel_height = 1 << paxel_shift_y;
185 min_height = ((input_height + lsc_cfg->initial_y + paxel_height - 1)
186 >> paxel_shift_y) + 1;
188 min_size = 4 * min_width * min_height;
189 if (min_size > lsc_cfg->size) {
190 dev_dbg(isp->dev, "CCDC: LSC: too small table\n");
193 if (lsc_cfg->offset < (min_width * 4)) {
194 dev_dbg(isp->dev, "CCDC: LSC: Offset is too small\n");
197 if ((lsc_cfg->size / lsc_cfg->offset) < min_height) {
198 dev_dbg(isp->dev, "CCDC: LSC: Wrong size/offset combination\n");
205 * ccdc_lsc_program_table - Program Lens Shading Compensation table address.
206 * @ccdc: Pointer to ISP CCDC device.
208 static void ccdc_lsc_program_table(struct isp_ccdc_device *ccdc, u32 addr)
210 isp_reg_writel(to_isp_device(ccdc), addr,
211 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_TABLE_BASE);
215 * ccdc_lsc_setup_regs - Configures the lens shading compensation module
216 * @ccdc: Pointer to ISP CCDC device.
218 static void ccdc_lsc_setup_regs(struct isp_ccdc_device *ccdc,
219 struct omap3isp_ccdc_lsc_config *cfg)
221 struct isp_device *isp = to_isp_device(ccdc);
224 isp_reg_writel(isp, cfg->offset, OMAP3_ISP_IOMEM_CCDC,
225 ISPCCDC_LSC_TABLE_OFFSET);
228 reg |= cfg->gain_mode_n << ISPCCDC_LSC_GAIN_MODE_N_SHIFT;
229 reg |= cfg->gain_mode_m << ISPCCDC_LSC_GAIN_MODE_M_SHIFT;
230 reg |= cfg->gain_format << ISPCCDC_LSC_GAIN_FORMAT_SHIFT;
231 isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG);
234 reg &= ~ISPCCDC_LSC_INITIAL_X_MASK;
235 reg |= cfg->initial_x << ISPCCDC_LSC_INITIAL_X_SHIFT;
236 reg &= ~ISPCCDC_LSC_INITIAL_Y_MASK;
237 reg |= cfg->initial_y << ISPCCDC_LSC_INITIAL_Y_SHIFT;
238 isp_reg_writel(isp, reg, OMAP3_ISP_IOMEM_CCDC,
239 ISPCCDC_LSC_INITIAL);
242 static int ccdc_lsc_wait_prefetch(struct isp_ccdc_device *ccdc)
244 struct isp_device *isp = to_isp_device(ccdc);
247 isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ,
248 OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
251 for (wait = 0; wait < 1000; wait++) {
252 if (isp_reg_readl(isp, OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS) &
253 IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ) {
254 isp_reg_writel(isp, IRQ0STATUS_CCDC_LSC_PREF_COMP_IRQ,
255 OMAP3_ISP_IOMEM_MAIN, ISP_IRQ0STATUS);
267 * __ccdc_lsc_enable - Enables/Disables the Lens Shading Compensation module.
268 * @ccdc: Pointer to ISP CCDC device.
269 * @enable: 0 Disables LSC, 1 Enables LSC.
271 static int __ccdc_lsc_enable(struct isp_ccdc_device *ccdc, int enable)
273 struct isp_device *isp = to_isp_device(ccdc);
274 const struct v4l2_mbus_framefmt *format =
275 __ccdc_get_format(ccdc, NULL, CCDC_PAD_SINK,
276 V4L2_SUBDEV_FORMAT_ACTIVE);
278 if ((format->code != V4L2_MBUS_FMT_SGRBG10_1X10) &&
279 (format->code != V4L2_MBUS_FMT_SRGGB10_1X10) &&
280 (format->code != V4L2_MBUS_FMT_SBGGR10_1X10) &&
281 (format->code != V4L2_MBUS_FMT_SGBRG10_1X10))
285 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_LSC_READ);
287 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG,
288 ISPCCDC_LSC_ENABLE, enable ? ISPCCDC_LSC_ENABLE : 0);
291 if (ccdc_lsc_wait_prefetch(ccdc) < 0) {
292 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC,
293 ISPCCDC_LSC_CONFIG, ISPCCDC_LSC_ENABLE);
294 ccdc->lsc.state = LSC_STATE_STOPPED;
295 dev_warn(to_device(ccdc), "LSC prefecth timeout\n");
298 ccdc->lsc.state = LSC_STATE_RUNNING;
300 ccdc->lsc.state = LSC_STATE_STOPPING;
306 static int ccdc_lsc_busy(struct isp_ccdc_device *ccdc)
308 struct isp_device *isp = to_isp_device(ccdc);
310 return isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG) &
314 /* __ccdc_lsc_configure - Apply a new configuration to the LSC engine
315 * @ccdc: Pointer to ISP CCDC device
316 * @req: New configuration request
318 * context: in_interrupt()
320 static int __ccdc_lsc_configure(struct isp_ccdc_device *ccdc,
321 struct ispccdc_lsc_config_req *req)
326 if (ccdc_lsc_validate_config(ccdc, &req->config) < 0) {
327 dev_dbg(to_device(ccdc), "Discard LSC configuration\n");
331 if (ccdc_lsc_busy(ccdc))
334 ccdc_lsc_setup_regs(ccdc, &req->config);
335 ccdc_lsc_program_table(ccdc, req->table);
340 * ccdc_lsc_error_handler - Handle LSC prefetch error scenario.
341 * @ccdc: Pointer to ISP CCDC device.
343 * Disables LSC, and defers enablement to shadow registers update time.
345 static void ccdc_lsc_error_handler(struct isp_ccdc_device *ccdc)
347 struct isp_device *isp = to_isp_device(ccdc);
349 * From OMAP3 TRM: When this event is pending, the module
350 * goes into transparent mode (output =input). Normal
351 * operation can be resumed at the start of the next frame
353 * 1) Clearing this event
354 * 2) Disabling the LSC module
357 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_LSC_CONFIG,
359 ccdc->lsc.state = LSC_STATE_STOPPED;
362 static void ccdc_lsc_free_request(struct isp_ccdc_device *ccdc,
363 struct ispccdc_lsc_config_req *req)
365 struct isp_device *isp = to_isp_device(ccdc);
371 dma_unmap_sg(isp->dev, req->iovm->sgt->sgl,
372 req->iovm->sgt->nents, DMA_TO_DEVICE);
374 omap_iommu_vfree(isp->domain, isp->dev, req->table);
378 static void ccdc_lsc_free_queue(struct isp_ccdc_device *ccdc,
379 struct list_head *queue)
381 struct ispccdc_lsc_config_req *req, *n;
384 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
385 list_for_each_entry_safe(req, n, queue, list) {
386 list_del(&req->list);
387 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
388 ccdc_lsc_free_request(ccdc, req);
389 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
391 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
394 static void ccdc_lsc_free_table_work(struct work_struct *work)
396 struct isp_ccdc_device *ccdc;
397 struct ispccdc_lsc *lsc;
399 lsc = container_of(work, struct ispccdc_lsc, table_work);
400 ccdc = container_of(lsc, struct isp_ccdc_device, lsc);
402 ccdc_lsc_free_queue(ccdc, &lsc->free_queue);
406 * ccdc_lsc_config - Configure the LSC module from a userspace request
408 * Store the request LSC configuration in the LSC engine request pointer. The
409 * configuration will be applied to the hardware when the CCDC will be enabled,
410 * or at the next LSC interrupt if the CCDC is already running.
412 static int ccdc_lsc_config(struct isp_ccdc_device *ccdc,
413 struct omap3isp_ccdc_update_config *config)
415 struct isp_device *isp = to_isp_device(ccdc);
416 struct ispccdc_lsc_config_req *req;
422 update = config->update &
423 (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC);
427 if (update != (OMAP3ISP_CCDC_CONFIG_LSC | OMAP3ISP_CCDC_TBL_LSC)) {
428 dev_dbg(to_device(ccdc), "%s: Both LSC configuration and table "
429 "need to be supplied\n", __func__);
433 req = kzalloc(sizeof(*req), GFP_KERNEL);
437 if (config->flag & OMAP3ISP_CCDC_CONFIG_LSC) {
438 if (copy_from_user(&req->config, config->lsc_cfg,
439 sizeof(req->config))) {
446 req->table = omap_iommu_vmalloc(isp->domain, isp->dev, 0,
447 req->config.size, IOMMU_FLAG);
448 if (IS_ERR_VALUE(req->table)) {
454 req->iovm = omap_find_iovm_area(isp->dev, req->table);
455 if (req->iovm == NULL) {
460 if (!dma_map_sg(isp->dev, req->iovm->sgt->sgl,
461 req->iovm->sgt->nents, DMA_TO_DEVICE)) {
467 dma_sync_sg_for_cpu(isp->dev, req->iovm->sgt->sgl,
468 req->iovm->sgt->nents, DMA_TO_DEVICE);
470 table = omap_da_to_va(isp->dev, req->table);
471 if (copy_from_user(table, config->lsc, req->config.size)) {
476 dma_sync_sg_for_device(isp->dev, req->iovm->sgt->sgl,
477 req->iovm->sgt->nents, DMA_TO_DEVICE);
480 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
481 if (ccdc->lsc.request) {
482 list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue);
483 schedule_work(&ccdc->lsc.table_work);
485 ccdc->lsc.request = req;
486 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
492 ccdc_lsc_free_request(ccdc, req);
497 static inline int ccdc_lsc_is_configured(struct isp_ccdc_device *ccdc)
501 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
502 if (ccdc->lsc.active) {
503 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
506 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
510 static int ccdc_lsc_enable(struct isp_ccdc_device *ccdc)
512 struct ispccdc_lsc *lsc = &ccdc->lsc;
514 if (lsc->state != LSC_STATE_STOPPED)
518 list_add_tail(&lsc->active->list, &lsc->free_queue);
522 if (__ccdc_lsc_configure(ccdc, lsc->request) < 0) {
523 omap3isp_sbl_disable(to_isp_device(ccdc),
524 OMAP3_ISP_SBL_CCDC_LSC_READ);
525 list_add_tail(&lsc->request->list, &lsc->free_queue);
530 lsc->active = lsc->request;
532 __ccdc_lsc_enable(ccdc, 1);
535 if (!list_empty(&lsc->free_queue))
536 schedule_work(&lsc->table_work);
541 /* -----------------------------------------------------------------------------
542 * Parameters configuration
546 * ccdc_configure_clamp - Configure optical-black or digital clamping
547 * @ccdc: Pointer to ISP CCDC device.
549 * The CCDC performs either optical-black or digital clamp. Configure and enable
550 * the selected clamp method.
552 static void ccdc_configure_clamp(struct isp_ccdc_device *ccdc)
554 struct isp_device *isp = to_isp_device(ccdc);
558 clamp = ccdc->clamp.obgain << ISPCCDC_CLAMP_OBGAIN_SHIFT;
559 clamp |= ccdc->clamp.oblen << ISPCCDC_CLAMP_OBSLEN_SHIFT;
560 clamp |= ccdc->clamp.oblines << ISPCCDC_CLAMP_OBSLN_SHIFT;
561 clamp |= ccdc->clamp.obstpixel << ISPCCDC_CLAMP_OBST_SHIFT;
562 isp_reg_writel(isp, clamp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP);
564 isp_reg_writel(isp, ccdc->clamp.dcsubval,
565 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_DCSUB);
568 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CLAMP,
569 ISPCCDC_CLAMP_CLAMPEN,
570 ccdc->obclamp ? ISPCCDC_CLAMP_CLAMPEN : 0);
574 * ccdc_configure_fpc - Configure Faulty Pixel Correction
575 * @ccdc: Pointer to ISP CCDC device.
577 static void ccdc_configure_fpc(struct isp_ccdc_device *ccdc)
579 struct isp_device *isp = to_isp_device(ccdc);
581 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC, ISPCCDC_FPC_FPCEN);
586 isp_reg_writel(isp, ccdc->fpc.fpcaddr, OMAP3_ISP_IOMEM_CCDC,
588 /* The FPNUM field must be set before enabling FPC. */
589 isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT),
590 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC);
591 isp_reg_writel(isp, (ccdc->fpc.fpnum << ISPCCDC_FPC_FPNUM_SHIFT) |
592 ISPCCDC_FPC_FPCEN, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FPC);
596 * ccdc_configure_black_comp - Configure Black Level Compensation.
597 * @ccdc: Pointer to ISP CCDC device.
599 static void ccdc_configure_black_comp(struct isp_ccdc_device *ccdc)
601 struct isp_device *isp = to_isp_device(ccdc);
604 blcomp = ccdc->blcomp.b_mg << ISPCCDC_BLKCMP_B_MG_SHIFT;
605 blcomp |= ccdc->blcomp.gb_g << ISPCCDC_BLKCMP_GB_G_SHIFT;
606 blcomp |= ccdc->blcomp.gr_cy << ISPCCDC_BLKCMP_GR_CY_SHIFT;
607 blcomp |= ccdc->blcomp.r_ye << ISPCCDC_BLKCMP_R_YE_SHIFT;
609 isp_reg_writel(isp, blcomp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_BLKCMP);
613 * ccdc_configure_lpf - Configure Low-Pass Filter (LPF).
614 * @ccdc: Pointer to ISP CCDC device.
616 static void ccdc_configure_lpf(struct isp_ccdc_device *ccdc)
618 struct isp_device *isp = to_isp_device(ccdc);
620 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE,
621 ISPCCDC_SYN_MODE_LPF,
622 ccdc->lpf ? ISPCCDC_SYN_MODE_LPF : 0);
626 * ccdc_configure_alaw - Configure A-law compression.
627 * @ccdc: Pointer to ISP CCDC device.
629 static void ccdc_configure_alaw(struct isp_ccdc_device *ccdc)
631 struct isp_device *isp = to_isp_device(ccdc);
632 const struct isp_format_info *info;
635 info = omap3isp_video_format_info(ccdc->formats[CCDC_PAD_SINK].code);
637 switch (info->width) {
642 alaw = ISPCCDC_ALAW_GWDI_9_0;
645 alaw = ISPCCDC_ALAW_GWDI_10_1;
648 alaw = ISPCCDC_ALAW_GWDI_11_2;
651 alaw = ISPCCDC_ALAW_GWDI_12_3;
656 alaw |= ISPCCDC_ALAW_CCDTBL;
658 isp_reg_writel(isp, alaw, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_ALAW);
662 * ccdc_config_imgattr - Configure sensor image specific attributes.
663 * @ccdc: Pointer to ISP CCDC device.
664 * @colptn: Color pattern of the sensor.
666 static void ccdc_config_imgattr(struct isp_ccdc_device *ccdc, u32 colptn)
668 struct isp_device *isp = to_isp_device(ccdc);
670 isp_reg_writel(isp, colptn, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_COLPTN);
674 * ccdc_config - Set CCDC configuration from userspace
675 * @ccdc: Pointer to ISP CCDC device.
676 * @userspace_add: Structure containing CCDC configuration sent from userspace.
678 * Returns 0 if successful, -EINVAL if the pointer to the configuration
679 * structure is null, or the copy_from_user function fails to copy user space
680 * memory to kernel space memory.
682 static int ccdc_config(struct isp_ccdc_device *ccdc,
683 struct omap3isp_ccdc_update_config *ccdc_struct)
685 struct isp_device *isp = to_isp_device(ccdc);
688 spin_lock_irqsave(&ccdc->lock, flags);
689 ccdc->shadow_update = 1;
690 spin_unlock_irqrestore(&ccdc->lock, flags);
692 if (OMAP3ISP_CCDC_ALAW & ccdc_struct->update) {
693 ccdc->alaw = !!(OMAP3ISP_CCDC_ALAW & ccdc_struct->flag);
694 ccdc->update |= OMAP3ISP_CCDC_ALAW;
697 if (OMAP3ISP_CCDC_LPF & ccdc_struct->update) {
698 ccdc->lpf = !!(OMAP3ISP_CCDC_LPF & ccdc_struct->flag);
699 ccdc->update |= OMAP3ISP_CCDC_LPF;
702 if (OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->update) {
703 if (copy_from_user(&ccdc->clamp, ccdc_struct->bclamp,
704 sizeof(ccdc->clamp))) {
705 ccdc->shadow_update = 0;
709 ccdc->obclamp = !!(OMAP3ISP_CCDC_BLCLAMP & ccdc_struct->flag);
710 ccdc->update |= OMAP3ISP_CCDC_BLCLAMP;
713 if (OMAP3ISP_CCDC_BCOMP & ccdc_struct->update) {
714 if (copy_from_user(&ccdc->blcomp, ccdc_struct->blcomp,
715 sizeof(ccdc->blcomp))) {
716 ccdc->shadow_update = 0;
720 ccdc->update |= OMAP3ISP_CCDC_BCOMP;
723 ccdc->shadow_update = 0;
725 if (OMAP3ISP_CCDC_FPC & ccdc_struct->update) {
730 if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED)
733 ccdc->fpc_en = !!(OMAP3ISP_CCDC_FPC & ccdc_struct->flag);
736 if (copy_from_user(&ccdc->fpc, ccdc_struct->fpc,
741 * table_new must be 64-bytes aligned, but it's
742 * already done by omap_iommu_vmalloc().
744 size = ccdc->fpc.fpnum * 4;
745 table_new = omap_iommu_vmalloc(isp->domain, isp->dev,
746 0, size, IOMMU_FLAG);
747 if (IS_ERR_VALUE(table_new))
750 if (copy_from_user(omap_da_to_va(isp->dev, table_new),
751 (__force void __user *)
752 ccdc->fpc.fpcaddr, size)) {
753 omap_iommu_vfree(isp->domain, isp->dev,
758 table_old = ccdc->fpc.fpcaddr;
759 ccdc->fpc.fpcaddr = table_new;
762 ccdc_configure_fpc(ccdc);
764 omap_iommu_vfree(isp->domain, isp->dev, table_old);
767 return ccdc_lsc_config(ccdc, ccdc_struct);
770 static void ccdc_apply_controls(struct isp_ccdc_device *ccdc)
772 if (ccdc->update & OMAP3ISP_CCDC_ALAW) {
773 ccdc_configure_alaw(ccdc);
774 ccdc->update &= ~OMAP3ISP_CCDC_ALAW;
777 if (ccdc->update & OMAP3ISP_CCDC_LPF) {
778 ccdc_configure_lpf(ccdc);
779 ccdc->update &= ~OMAP3ISP_CCDC_LPF;
782 if (ccdc->update & OMAP3ISP_CCDC_BLCLAMP) {
783 ccdc_configure_clamp(ccdc);
784 ccdc->update &= ~OMAP3ISP_CCDC_BLCLAMP;
787 if (ccdc->update & OMAP3ISP_CCDC_BCOMP) {
788 ccdc_configure_black_comp(ccdc);
789 ccdc->update &= ~OMAP3ISP_CCDC_BCOMP;
794 * omap3isp_ccdc_restore_context - Restore values of the CCDC module registers
795 * @dev: Pointer to ISP device
797 void omap3isp_ccdc_restore_context(struct isp_device *isp)
799 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
801 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG, ISPCCDC_CFG_VDLC);
803 ccdc->update = OMAP3ISP_CCDC_ALAW | OMAP3ISP_CCDC_LPF
804 | OMAP3ISP_CCDC_BLCLAMP | OMAP3ISP_CCDC_BCOMP;
805 ccdc_apply_controls(ccdc);
806 ccdc_configure_fpc(ccdc);
809 /* -----------------------------------------------------------------------------
810 * Format- and pipeline-related configuration helpers
814 * ccdc_config_vp - Configure the Video Port.
815 * @ccdc: Pointer to ISP CCDC device.
817 static void ccdc_config_vp(struct isp_ccdc_device *ccdc)
819 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
820 struct isp_device *isp = to_isp_device(ccdc);
821 const struct isp_format_info *info;
822 unsigned long l3_ick = pipe->l3_ick;
823 unsigned int max_div = isp->revision == ISP_REVISION_15_0 ? 64 : 8;
824 unsigned int div = 0;
827 fmtcfg_vp = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG)
828 & ~(ISPCCDC_FMTCFG_VPIN_MASK | ISPCCDC_FMTCFG_VPIF_FRQ_MASK);
830 info = omap3isp_video_format_info(ccdc->formats[CCDC_PAD_SINK].code);
832 switch (info->width) {
835 fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_9_0;
838 fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_10_1;
841 fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_11_2;
844 fmtcfg_vp |= ISPCCDC_FMTCFG_VPIN_12_3;
849 div = DIV_ROUND_UP(l3_ick, pipe->max_rate);
850 else if (pipe->external_rate)
851 div = l3_ick / pipe->external_rate;
853 div = clamp(div, 2U, max_div);
854 fmtcfg_vp |= (div - 2) << ISPCCDC_FMTCFG_VPIF_FRQ_SHIFT;
856 isp_reg_writel(isp, fmtcfg_vp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG);
860 * ccdc_enable_vp - Enable Video Port.
861 * @ccdc: Pointer to ISP CCDC device.
862 * @enable: 0 Disables VP, 1 Enables VP
864 * This is needed for outputting image to Preview, H3A and HIST ISP submodules.
866 static void ccdc_enable_vp(struct isp_ccdc_device *ccdc, u8 enable)
868 struct isp_device *isp = to_isp_device(ccdc);
870 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMTCFG,
871 ISPCCDC_FMTCFG_VPEN, enable ? ISPCCDC_FMTCFG_VPEN : 0);
875 * ccdc_config_outlineoffset - Configure memory saving output line offset
876 * @ccdc: Pointer to ISP CCDC device.
877 * @offset: Address offset to start a new line. Must be twice the
878 * Output width and aligned on 32 byte boundary
879 * @oddeven: Specifies the odd/even line pattern to be chosen to store the
881 * @numlines: Set the value 0-3 for +1-4lines, 4-7 for -1-4lines.
883 * - Configures the output line offset when stored in memory
884 * - Sets the odd/even line pattern to store the output
885 * (EVENEVEN (1), ODDEVEN (2), EVENODD (3), ODDODD (4))
886 * - Configures the number of even and odd line fields in case of rearranging
889 static void ccdc_config_outlineoffset(struct isp_ccdc_device *ccdc,
890 u32 offset, u8 oddeven, u8 numlines)
892 struct isp_device *isp = to_isp_device(ccdc);
894 isp_reg_writel(isp, offset & 0xffff,
895 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_HSIZE_OFF);
897 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
898 ISPCCDC_SDOFST_FINV);
900 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
901 ISPCCDC_SDOFST_FOFST_4L);
905 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
906 (numlines & 0x7) << ISPCCDC_SDOFST_LOFST0_SHIFT);
909 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
910 (numlines & 0x7) << ISPCCDC_SDOFST_LOFST1_SHIFT);
913 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
914 (numlines & 0x7) << ISPCCDC_SDOFST_LOFST2_SHIFT);
917 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDOFST,
918 (numlines & 0x7) << ISPCCDC_SDOFST_LOFST3_SHIFT);
926 * ccdc_set_outaddr - Set memory address to save output image
927 * @ccdc: Pointer to ISP CCDC device.
928 * @addr: ISP MMU Mapped 32-bit memory address aligned on 32 byte boundary.
930 * Sets the memory address where the output will be saved.
932 static void ccdc_set_outaddr(struct isp_ccdc_device *ccdc, u32 addr)
934 struct isp_device *isp = to_isp_device(ccdc);
936 isp_reg_writel(isp, addr, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SDR_ADDR);
940 * omap3isp_ccdc_max_rate - Calculate maximum input data rate based on the input
941 * @ccdc: Pointer to ISP CCDC device.
942 * @max_rate: Maximum calculated data rate.
944 * Returns in *max_rate less value between calculated and passed
946 void omap3isp_ccdc_max_rate(struct isp_ccdc_device *ccdc,
947 unsigned int *max_rate)
949 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
956 * TRM says that for parallel sensors the maximum data rate
957 * should be 90% form L3/2 clock, otherwise just L3/2.
959 if (ccdc->input == CCDC_INPUT_PARALLEL)
960 rate = pipe->l3_ick / 2 * 9 / 10;
962 rate = pipe->l3_ick / 2;
964 *max_rate = min(*max_rate, rate);
968 * ccdc_config_sync_if - Set CCDC sync interface configuration
969 * @ccdc: Pointer to ISP CCDC device.
970 * @pdata: Parallel interface platform data (may be NULL)
971 * @data_size: Data size
973 static void ccdc_config_sync_if(struct isp_ccdc_device *ccdc,
974 struct isp_parallel_platform_data *pdata,
975 unsigned int data_size)
977 struct isp_device *isp = to_isp_device(ccdc);
978 const struct v4l2_mbus_framefmt *format;
979 u32 syn_mode = ISPCCDC_SYN_MODE_VDHDEN;
981 format = &ccdc->formats[CCDC_PAD_SINK];
983 if (format->code == V4L2_MBUS_FMT_YUYV8_2X8 ||
984 format->code == V4L2_MBUS_FMT_UYVY8_2X8) {
985 /* The bridge is enabled for YUV8 formats. Configure the input
988 syn_mode |= ISPCCDC_SYN_MODE_INPMOD_YCBCR16;
993 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_8;
996 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_10;
999 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_11;
1002 syn_mode |= ISPCCDC_SYN_MODE_DATSIZ_12;
1006 if (pdata && pdata->data_pol)
1007 syn_mode |= ISPCCDC_SYN_MODE_DATAPOL;
1009 if (pdata && pdata->hs_pol)
1010 syn_mode |= ISPCCDC_SYN_MODE_HDPOL;
1012 if (pdata && pdata->vs_pol)
1013 syn_mode |= ISPCCDC_SYN_MODE_VDPOL;
1015 isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
1017 /* The CCDC_CFG.Y8POS bit is used in YCbCr8 input mode only. The
1018 * hardware seems to ignore it in all other input modes.
1020 if (format->code == V4L2_MBUS_FMT_UYVY8_2X8)
1021 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1024 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1027 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_REC656IF,
1028 ISPCCDC_REC656IF_R656ON);
1031 /* CCDC formats descriptions */
1032 static const u32 ccdc_sgrbg_pattern =
1033 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1034 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1035 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1036 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1037 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1038 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1039 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1040 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1041 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1042 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1043 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1044 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1045 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1046 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1047 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1048 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1050 static const u32 ccdc_srggb_pattern =
1051 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1052 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1053 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1054 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1055 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1056 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1057 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1058 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1059 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1060 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1061 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1062 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1063 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1064 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1065 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1066 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1068 static const u32 ccdc_sbggr_pattern =
1069 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1070 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1071 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1072 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1073 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1074 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1075 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1076 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1077 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1078 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1079 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1080 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1081 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1082 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1083 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1084 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1086 static const u32 ccdc_sgbrg_pattern =
1087 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC0_SHIFT |
1088 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC1_SHIFT |
1089 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP0PLC2_SHIFT |
1090 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP0PLC3_SHIFT |
1091 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC0_SHIFT |
1092 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC1_SHIFT |
1093 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP1PLC2_SHIFT |
1094 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP1PLC3_SHIFT |
1095 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC0_SHIFT |
1096 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC1_SHIFT |
1097 ISPCCDC_COLPTN_Gb_G << ISPCCDC_COLPTN_CP2PLC2_SHIFT |
1098 ISPCCDC_COLPTN_B_Mg << ISPCCDC_COLPTN_CP2PLC3_SHIFT |
1099 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC0_SHIFT |
1100 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC1_SHIFT |
1101 ISPCCDC_COLPTN_R_Ye << ISPCCDC_COLPTN_CP3PLC2_SHIFT |
1102 ISPCCDC_COLPTN_Gr_Cy << ISPCCDC_COLPTN_CP3PLC3_SHIFT;
1104 static void ccdc_configure(struct isp_ccdc_device *ccdc)
1106 struct isp_device *isp = to_isp_device(ccdc);
1107 struct isp_parallel_platform_data *pdata = NULL;
1108 struct v4l2_subdev *sensor;
1109 struct v4l2_mbus_framefmt *format;
1110 const struct v4l2_rect *crop;
1111 const struct isp_format_info *fmt_info;
1112 struct v4l2_subdev_format fmt_src;
1113 unsigned int depth_out;
1114 unsigned int depth_in = 0;
1115 struct media_pad *pad;
1116 unsigned long flags;
1117 unsigned int bridge;
1122 pad = media_entity_remote_source(&ccdc->pads[CCDC_PAD_SINK]);
1123 sensor = media_entity_to_v4l2_subdev(pad->entity);
1124 if (ccdc->input == CCDC_INPUT_PARALLEL)
1125 pdata = &((struct isp_v4l2_subdevs_group *)sensor->host_priv)
1128 /* Compute the lane shifter shift value and enable the bridge when the
1129 * input format is YUV.
1131 fmt_src.pad = pad->index;
1132 fmt_src.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1133 if (!v4l2_subdev_call(sensor, pad, get_fmt, NULL, &fmt_src)) {
1134 fmt_info = omap3isp_video_format_info(fmt_src.format.code);
1135 depth_in = fmt_info->width;
1138 fmt_info = omap3isp_video_format_info
1139 (isp->isp_ccdc.formats[CCDC_PAD_SINK].code);
1140 depth_out = fmt_info->width;
1141 shift = depth_in - depth_out;
1143 if (fmt_info->code == V4L2_MBUS_FMT_YUYV8_2X8)
1144 bridge = ISPCTRL_PAR_BRIDGE_LENDIAN;
1145 else if (fmt_info->code == V4L2_MBUS_FMT_UYVY8_2X8)
1146 bridge = ISPCTRL_PAR_BRIDGE_BENDIAN;
1148 bridge = ISPCTRL_PAR_BRIDGE_DISABLE;
1150 omap3isp_configure_bridge(isp, ccdc->input, pdata, shift, bridge);
1152 ccdc_config_sync_if(ccdc, pdata, depth_out);
1154 syn_mode = isp_reg_readl(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
1156 /* Use the raw, unprocessed data when writing to memory. The H3A and
1157 * histogram modules are still fed with lens shading corrected data.
1159 syn_mode &= ~ISPCCDC_SYN_MODE_VP2SDR;
1161 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1162 syn_mode |= ISPCCDC_SYN_MODE_WEN;
1164 syn_mode &= ~ISPCCDC_SYN_MODE_WEN;
1166 if (ccdc->output & CCDC_OUTPUT_RESIZER)
1167 syn_mode |= ISPCCDC_SYN_MODE_SDR2RSZ;
1169 syn_mode &= ~ISPCCDC_SYN_MODE_SDR2RSZ;
1172 format = &ccdc->formats[CCDC_PAD_SINK];
1175 switch (format->code) {
1176 case V4L2_MBUS_FMT_SRGGB10_1X10:
1177 case V4L2_MBUS_FMT_SRGGB12_1X12:
1178 ccdc_pattern = ccdc_srggb_pattern;
1180 case V4L2_MBUS_FMT_SBGGR10_1X10:
1181 case V4L2_MBUS_FMT_SBGGR12_1X12:
1182 ccdc_pattern = ccdc_sbggr_pattern;
1184 case V4L2_MBUS_FMT_SGBRG10_1X10:
1185 case V4L2_MBUS_FMT_SGBRG12_1X12:
1186 ccdc_pattern = ccdc_sgbrg_pattern;
1190 ccdc_pattern = ccdc_sgrbg_pattern;
1193 ccdc_config_imgattr(ccdc, ccdc_pattern);
1195 /* Generate VD0 on the last line of the image and VD1 on the
1198 isp_reg_writel(isp, ((format->height - 2) << ISPCCDC_VDINT_0_SHIFT) |
1199 ((format->height * 2 / 3) << ISPCCDC_VDINT_1_SHIFT),
1200 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VDINT);
1202 /* CCDC_PAD_SOURCE_OF */
1203 format = &ccdc->formats[CCDC_PAD_SOURCE_OF];
1206 isp_reg_writel(isp, (crop->left << ISPCCDC_HORZ_INFO_SPH_SHIFT) |
1207 ((crop->width - 1) << ISPCCDC_HORZ_INFO_NPH_SHIFT),
1208 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_HORZ_INFO);
1209 isp_reg_writel(isp, crop->top << ISPCCDC_VERT_START_SLV0_SHIFT,
1210 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_START);
1211 isp_reg_writel(isp, (crop->height - 1)
1212 << ISPCCDC_VERT_LINES_NLV_SHIFT,
1213 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VERT_LINES);
1215 ccdc_config_outlineoffset(ccdc, ccdc->video_out.bpl_value, 0, 0);
1217 /* The CCDC outputs data in UYVY order by default. Swap bytes to get
1220 if (format->code == V4L2_MBUS_FMT_YUYV8_1X16)
1221 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1224 isp_reg_clr(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1227 /* Use PACK8 mode for 1byte per pixel formats. */
1228 if (omap3isp_video_format_info(format->code)->width <= 8)
1229 syn_mode |= ISPCCDC_SYN_MODE_PACK8;
1231 syn_mode &= ~ISPCCDC_SYN_MODE_PACK8;
1233 isp_reg_writel(isp, syn_mode, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_SYN_MODE);
1235 /* CCDC_PAD_SOURCE_VP */
1236 format = &ccdc->formats[CCDC_PAD_SOURCE_VP];
1238 isp_reg_writel(isp, (0 << ISPCCDC_FMT_HORZ_FMTSPH_SHIFT) |
1239 (format->width << ISPCCDC_FMT_HORZ_FMTLNH_SHIFT),
1240 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_HORZ);
1241 isp_reg_writel(isp, (0 << ISPCCDC_FMT_VERT_FMTSLV_SHIFT) |
1242 ((format->height + 1) << ISPCCDC_FMT_VERT_FMTLNV_SHIFT),
1243 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_FMT_VERT);
1245 isp_reg_writel(isp, (format->width << ISPCCDC_VP_OUT_HORZ_NUM_SHIFT) |
1246 (format->height << ISPCCDC_VP_OUT_VERT_NUM_SHIFT),
1247 OMAP3_ISP_IOMEM_CCDC, ISPCCDC_VP_OUT);
1249 /* Lens shading correction. */
1250 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
1251 if (ccdc->lsc.request == NULL)
1254 WARN_ON(ccdc->lsc.active);
1256 /* Get last good LSC configuration. If it is not supported for
1257 * the current active resolution discard it.
1259 if (ccdc->lsc.active == NULL &&
1260 __ccdc_lsc_configure(ccdc, ccdc->lsc.request) == 0) {
1261 ccdc->lsc.active = ccdc->lsc.request;
1263 list_add_tail(&ccdc->lsc.request->list, &ccdc->lsc.free_queue);
1264 schedule_work(&ccdc->lsc.table_work);
1267 ccdc->lsc.request = NULL;
1270 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
1272 ccdc_apply_controls(ccdc);
1275 static void __ccdc_enable(struct isp_ccdc_device *ccdc, int enable)
1277 struct isp_device *isp = to_isp_device(ccdc);
1279 isp_reg_clr_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_PCR,
1280 ISPCCDC_PCR_EN, enable ? ISPCCDC_PCR_EN : 0);
1283 static int ccdc_disable(struct isp_ccdc_device *ccdc)
1285 unsigned long flags;
1288 spin_lock_irqsave(&ccdc->lock, flags);
1289 if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS)
1290 ccdc->stopping = CCDC_STOP_REQUEST;
1291 spin_unlock_irqrestore(&ccdc->lock, flags);
1293 ret = wait_event_timeout(ccdc->wait,
1294 ccdc->stopping == CCDC_STOP_FINISHED,
1295 msecs_to_jiffies(2000));
1298 dev_warn(to_device(ccdc), "CCDC stop timeout!\n");
1301 omap3isp_sbl_disable(to_isp_device(ccdc), OMAP3_ISP_SBL_CCDC_LSC_READ);
1303 mutex_lock(&ccdc->ioctl_lock);
1304 ccdc_lsc_free_request(ccdc, ccdc->lsc.request);
1305 ccdc->lsc.request = ccdc->lsc.active;
1306 ccdc->lsc.active = NULL;
1307 cancel_work_sync(&ccdc->lsc.table_work);
1308 ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue);
1309 mutex_unlock(&ccdc->ioctl_lock);
1311 ccdc->stopping = CCDC_STOP_NOT_REQUESTED;
1313 return ret > 0 ? 0 : ret;
1316 static void ccdc_enable(struct isp_ccdc_device *ccdc)
1318 if (ccdc_lsc_is_configured(ccdc))
1319 __ccdc_lsc_enable(ccdc, 1);
1320 __ccdc_enable(ccdc, 1);
1323 /* -----------------------------------------------------------------------------
1324 * Interrupt handling
1328 * ccdc_sbl_busy - Poll idle state of CCDC and related SBL memory write bits
1329 * @ccdc: Pointer to ISP CCDC device.
1331 * Returns zero if the CCDC is idle and the image has been written to
1334 static int ccdc_sbl_busy(struct isp_ccdc_device *ccdc)
1336 struct isp_device *isp = to_isp_device(ccdc);
1338 return omap3isp_ccdc_busy(ccdc)
1339 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_0) &
1340 ISPSBL_CCDC_WR_0_DATA_READY)
1341 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_1) &
1342 ISPSBL_CCDC_WR_0_DATA_READY)
1343 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_2) &
1344 ISPSBL_CCDC_WR_0_DATA_READY)
1345 | (isp_reg_readl(isp, OMAP3_ISP_IOMEM_SBL, ISPSBL_CCDC_WR_3) &
1346 ISPSBL_CCDC_WR_0_DATA_READY);
1350 * ccdc_sbl_wait_idle - Wait until the CCDC and related SBL are idle
1351 * @ccdc: Pointer to ISP CCDC device.
1352 * @max_wait: Max retry count in us for wait for idle/busy transition.
1354 static int ccdc_sbl_wait_idle(struct isp_ccdc_device *ccdc,
1355 unsigned int max_wait)
1357 unsigned int wait = 0;
1360 max_wait = 10000; /* 10 ms */
1362 for (wait = 0; wait <= max_wait; wait++) {
1363 if (!ccdc_sbl_busy(ccdc))
1373 /* __ccdc_handle_stopping - Handle CCDC and/or LSC stopping sequence
1374 * @ccdc: Pointer to ISP CCDC device.
1375 * @event: Pointing which event trigger handler
1377 * Return 1 when the event and stopping request combination is satisfied,
1380 static int __ccdc_handle_stopping(struct isp_ccdc_device *ccdc, u32 event)
1384 switch ((ccdc->stopping & 3) | event) {
1385 case CCDC_STOP_REQUEST | CCDC_EVENT_VD1:
1386 if (ccdc->lsc.state != LSC_STATE_STOPPED)
1387 __ccdc_lsc_enable(ccdc, 0);
1388 __ccdc_enable(ccdc, 0);
1389 ccdc->stopping = CCDC_STOP_EXECUTED;
1392 case CCDC_STOP_EXECUTED | CCDC_EVENT_VD0:
1393 ccdc->stopping |= CCDC_STOP_CCDC_FINISHED;
1394 if (ccdc->lsc.state == LSC_STATE_STOPPED)
1395 ccdc->stopping |= CCDC_STOP_LSC_FINISHED;
1399 case CCDC_STOP_EXECUTED | CCDC_EVENT_LSC_DONE:
1400 ccdc->stopping |= CCDC_STOP_LSC_FINISHED;
1404 case CCDC_STOP_EXECUTED | CCDC_EVENT_VD1:
1408 if (ccdc->stopping == CCDC_STOP_FINISHED) {
1409 wake_up(&ccdc->wait);
1416 static void ccdc_hs_vs_isr(struct isp_ccdc_device *ccdc)
1418 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
1419 struct video_device *vdev = ccdc->subdev.devnode;
1420 struct v4l2_event event;
1422 /* Frame number propagation */
1423 atomic_inc(&pipe->frame_number);
1425 memset(&event, 0, sizeof(event));
1426 event.type = V4L2_EVENT_FRAME_SYNC;
1427 event.u.frame_sync.frame_sequence = atomic_read(&pipe->frame_number);
1429 v4l2_event_queue(vdev, &event);
1433 * ccdc_lsc_isr - Handle LSC events
1434 * @ccdc: Pointer to ISP CCDC device.
1435 * @events: LSC events
1437 static void ccdc_lsc_isr(struct isp_ccdc_device *ccdc, u32 events)
1439 unsigned long flags;
1441 if (events & IRQ0STATUS_CCDC_LSC_PREF_ERR_IRQ) {
1442 struct isp_pipeline *pipe =
1443 to_isp_pipeline(&ccdc->subdev.entity);
1445 ccdc_lsc_error_handler(ccdc);
1447 dev_dbg(to_device(ccdc), "lsc prefetch error\n");
1450 if (!(events & IRQ0STATUS_CCDC_LSC_DONE_IRQ))
1453 /* LSC_DONE interrupt occur, there are two cases
1454 * 1. stopping for reconfiguration
1455 * 2. stopping because of STREAM OFF command
1457 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
1459 if (ccdc->lsc.state == LSC_STATE_STOPPING)
1460 ccdc->lsc.state = LSC_STATE_STOPPED;
1462 if (__ccdc_handle_stopping(ccdc, CCDC_EVENT_LSC_DONE))
1465 if (ccdc->lsc.state != LSC_STATE_RECONFIG)
1468 /* LSC is in STOPPING state, change to the new state */
1469 ccdc->lsc.state = LSC_STATE_STOPPED;
1471 /* This is an exception. Start of frame and LSC_DONE interrupt
1472 * have been received on the same time. Skip this event and wait
1475 if (events & IRQ0STATUS_HS_VS_IRQ)
1478 /* The LSC engine is stopped at this point. Enable it if there's a
1481 if (ccdc->lsc.request == NULL)
1484 ccdc_lsc_enable(ccdc);
1487 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
1490 static int ccdc_isr_buffer(struct isp_ccdc_device *ccdc)
1492 struct isp_pipeline *pipe = to_isp_pipeline(&ccdc->subdev.entity);
1493 struct isp_device *isp = to_isp_device(ccdc);
1494 struct isp_buffer *buffer;
1497 /* The CCDC generates VD0 interrupts even when disabled (the datasheet
1498 * doesn't explicitly state if that's supposed to happen or not, so it
1499 * can be considered as a hardware bug or as a feature, but we have to
1500 * deal with it anyway). Disabling the CCDC when no buffer is available
1501 * would thus not be enough, we need to handle the situation explicitly.
1503 if (list_empty(&ccdc->video_out.dmaqueue))
1506 /* We're in continuous mode, and memory writes were disabled due to a
1507 * buffer underrun. Reenable them now that we have a buffer. The buffer
1508 * address has been set in ccdc_video_queue.
1510 if (ccdc->state == ISP_PIPELINE_STREAM_CONTINUOUS && ccdc->underrun) {
1516 if (ccdc_sbl_wait_idle(ccdc, 1000)) {
1517 dev_info(isp->dev, "CCDC won't become idle!\n");
1521 buffer = omap3isp_video_buffer_next(&ccdc->video_out);
1522 if (buffer != NULL) {
1523 ccdc_set_outaddr(ccdc, buffer->isp_addr);
1527 pipe->state |= ISP_PIPELINE_IDLE_OUTPUT;
1529 if (ccdc->state == ISP_PIPELINE_STREAM_SINGLESHOT &&
1530 isp_pipeline_ready(pipe))
1531 omap3isp_pipeline_set_stream(pipe,
1532 ISP_PIPELINE_STREAM_SINGLESHOT);
1539 * ccdc_vd0_isr - Handle VD0 event
1540 * @ccdc: Pointer to ISP CCDC device.
1542 * Executes LSC deferred enablement before next frame starts.
1544 static void ccdc_vd0_isr(struct isp_ccdc_device *ccdc)
1546 unsigned long flags;
1549 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1550 restart = ccdc_isr_buffer(ccdc);
1552 spin_lock_irqsave(&ccdc->lock, flags);
1553 if (__ccdc_handle_stopping(ccdc, CCDC_EVENT_VD0)) {
1554 spin_unlock_irqrestore(&ccdc->lock, flags);
1558 if (!ccdc->shadow_update)
1559 ccdc_apply_controls(ccdc);
1560 spin_unlock_irqrestore(&ccdc->lock, flags);
1567 * ccdc_vd1_isr - Handle VD1 event
1568 * @ccdc: Pointer to ISP CCDC device.
1570 static void ccdc_vd1_isr(struct isp_ccdc_device *ccdc)
1572 unsigned long flags;
1574 spin_lock_irqsave(&ccdc->lsc.req_lock, flags);
1577 * Depending on the CCDC pipeline state, CCDC stopping should be
1578 * handled differently. In SINGLESHOT we emulate an internal CCDC
1579 * stopping because the CCDC hw works only in continuous mode.
1580 * When CONTINUOUS pipeline state is used and the CCDC writes it's
1581 * data to memory the CCDC and LSC are stopped immediately but
1582 * without change the CCDC stopping state machine. The CCDC
1583 * stopping state machine should be used only when user request
1584 * for stopping is received (SINGLESHOT is an exeption).
1586 switch (ccdc->state) {
1587 case ISP_PIPELINE_STREAM_SINGLESHOT:
1588 ccdc->stopping = CCDC_STOP_REQUEST;
1591 case ISP_PIPELINE_STREAM_CONTINUOUS:
1592 if (ccdc->output & CCDC_OUTPUT_MEMORY) {
1593 if (ccdc->lsc.state != LSC_STATE_STOPPED)
1594 __ccdc_lsc_enable(ccdc, 0);
1595 __ccdc_enable(ccdc, 0);
1599 case ISP_PIPELINE_STREAM_STOPPED:
1603 if (__ccdc_handle_stopping(ccdc, CCDC_EVENT_VD1))
1606 if (ccdc->lsc.request == NULL)
1610 * LSC need to be reconfigured. Stop it here and on next LSC_DONE IRQ
1611 * do the appropriate changes in registers
1613 if (ccdc->lsc.state == LSC_STATE_RUNNING) {
1614 __ccdc_lsc_enable(ccdc, 0);
1615 ccdc->lsc.state = LSC_STATE_RECONFIG;
1619 /* LSC has been in STOPPED state, enable it */
1620 if (ccdc->lsc.state == LSC_STATE_STOPPED)
1621 ccdc_lsc_enable(ccdc);
1624 spin_unlock_irqrestore(&ccdc->lsc.req_lock, flags);
1628 * omap3isp_ccdc_isr - Configure CCDC during interframe time.
1629 * @ccdc: Pointer to ISP CCDC device.
1630 * @events: CCDC events
1632 int omap3isp_ccdc_isr(struct isp_ccdc_device *ccdc, u32 events)
1634 if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED)
1637 if (events & IRQ0STATUS_CCDC_VD1_IRQ)
1640 ccdc_lsc_isr(ccdc, events);
1642 if (events & IRQ0STATUS_CCDC_VD0_IRQ)
1645 if (events & IRQ0STATUS_HS_VS_IRQ)
1646 ccdc_hs_vs_isr(ccdc);
1651 /* -----------------------------------------------------------------------------
1652 * ISP video operations
1655 static int ccdc_video_queue(struct isp_video *video, struct isp_buffer *buffer)
1657 struct isp_ccdc_device *ccdc = &video->isp->isp_ccdc;
1659 if (!(ccdc->output & CCDC_OUTPUT_MEMORY))
1662 ccdc_set_outaddr(ccdc, buffer->isp_addr);
1664 /* We now have a buffer queued on the output, restart the pipeline
1665 * on the next CCDC interrupt if running in continuous mode (or when
1666 * starting the stream).
1673 static const struct isp_video_operations ccdc_video_ops = {
1674 .queue = ccdc_video_queue,
1677 /* -----------------------------------------------------------------------------
1678 * V4L2 subdev operations
1682 * ccdc_ioctl - CCDC module private ioctl's
1683 * @sd: ISP CCDC V4L2 subdevice
1684 * @cmd: ioctl command
1685 * @arg: ioctl argument
1687 * Return 0 on success or a negative error code otherwise.
1689 static long ccdc_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1691 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
1695 case VIDIOC_OMAP3ISP_CCDC_CFG:
1696 mutex_lock(&ccdc->ioctl_lock);
1697 ret = ccdc_config(ccdc, arg);
1698 mutex_unlock(&ccdc->ioctl_lock);
1702 return -ENOIOCTLCMD;
1708 static int ccdc_subscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1709 const struct v4l2_event_subscription *sub)
1711 if (sub->type != V4L2_EVENT_FRAME_SYNC)
1714 /* line number is zero at frame start */
1718 return v4l2_event_subscribe(fh, sub, OMAP3ISP_CCDC_NEVENTS, NULL);
1721 static int ccdc_unsubscribe_event(struct v4l2_subdev *sd, struct v4l2_fh *fh,
1722 const struct v4l2_event_subscription *sub)
1724 return v4l2_event_unsubscribe(fh, sub);
1728 * ccdc_set_stream - Enable/Disable streaming on the CCDC module
1729 * @sd: ISP CCDC V4L2 subdevice
1730 * @enable: Enable/disable stream
1732 * When writing to memory, the CCDC hardware can't be enabled without a memory
1733 * buffer to write to. As the s_stream operation is called in response to a
1734 * STREAMON call without any buffer queued yet, just update the enabled field
1735 * and return immediately. The CCDC will be enabled in ccdc_isr_buffer().
1737 * When not writing to memory enable the CCDC immediately.
1739 static int ccdc_set_stream(struct v4l2_subdev *sd, int enable)
1741 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
1742 struct isp_device *isp = to_isp_device(ccdc);
1745 if (ccdc->state == ISP_PIPELINE_STREAM_STOPPED) {
1746 if (enable == ISP_PIPELINE_STREAM_STOPPED)
1749 omap3isp_subclk_enable(isp, OMAP3_ISP_SUBCLK_CCDC);
1750 isp_reg_set(isp, OMAP3_ISP_IOMEM_CCDC, ISPCCDC_CFG,
1753 ccdc_configure(ccdc);
1755 /* TODO: Don't configure the video port if all of its output
1756 * links are inactive.
1758 ccdc_config_vp(ccdc);
1759 ccdc_enable_vp(ccdc, 1);
1760 ccdc_print_status(ccdc);
1764 case ISP_PIPELINE_STREAM_CONTINUOUS:
1765 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1766 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
1768 if (ccdc->underrun || !(ccdc->output & CCDC_OUTPUT_MEMORY))
1774 case ISP_PIPELINE_STREAM_SINGLESHOT:
1775 if (ccdc->output & CCDC_OUTPUT_MEMORY &&
1776 ccdc->state != ISP_PIPELINE_STREAM_SINGLESHOT)
1777 omap3isp_sbl_enable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
1782 case ISP_PIPELINE_STREAM_STOPPED:
1783 ret = ccdc_disable(ccdc);
1784 if (ccdc->output & CCDC_OUTPUT_MEMORY)
1785 omap3isp_sbl_disable(isp, OMAP3_ISP_SBL_CCDC_WRITE);
1786 omap3isp_subclk_disable(isp, OMAP3_ISP_SUBCLK_CCDC);
1791 ccdc->state = enable;
1795 static struct v4l2_mbus_framefmt *
1796 __ccdc_get_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
1797 unsigned int pad, enum v4l2_subdev_format_whence which)
1799 if (which == V4L2_SUBDEV_FORMAT_TRY)
1800 return v4l2_subdev_get_try_format(fh, pad);
1802 return &ccdc->formats[pad];
1805 static struct v4l2_rect *
1806 __ccdc_get_crop(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
1807 enum v4l2_subdev_format_whence which)
1809 if (which == V4L2_SUBDEV_FORMAT_TRY)
1810 return v4l2_subdev_get_try_crop(fh, CCDC_PAD_SOURCE_OF);
1816 * ccdc_try_format - Try video format on a pad
1817 * @ccdc: ISP CCDC device
1818 * @fh : V4L2 subdev file handle
1823 ccdc_try_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
1824 unsigned int pad, struct v4l2_mbus_framefmt *fmt,
1825 enum v4l2_subdev_format_whence which)
1827 const struct isp_format_info *info;
1828 enum v4l2_mbus_pixelcode pixelcode;
1829 unsigned int width = fmt->width;
1830 unsigned int height = fmt->height;
1831 struct v4l2_rect *crop;
1836 for (i = 0; i < ARRAY_SIZE(ccdc_fmts); i++) {
1837 if (fmt->code == ccdc_fmts[i])
1841 /* If not found, use SGRBG10 as default */
1842 if (i >= ARRAY_SIZE(ccdc_fmts))
1843 fmt->code = V4L2_MBUS_FMT_SGRBG10_1X10;
1845 /* Clamp the input size. */
1846 fmt->width = clamp_t(u32, width, 32, 4096);
1847 fmt->height = clamp_t(u32, height, 32, 4096);
1850 case CCDC_PAD_SOURCE_OF:
1851 pixelcode = fmt->code;
1852 *fmt = *__ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, which);
1854 /* YUV formats are converted from 2X8 to 1X16 by the bridge and
1855 * can be byte-swapped.
1857 if (fmt->code == V4L2_MBUS_FMT_YUYV8_2X8 ||
1858 fmt->code == V4L2_MBUS_FMT_UYVY8_2X8) {
1859 /* Use the user requested format if YUV. */
1860 if (pixelcode == V4L2_MBUS_FMT_YUYV8_2X8 ||
1861 pixelcode == V4L2_MBUS_FMT_UYVY8_2X8 ||
1862 pixelcode == V4L2_MBUS_FMT_YUYV8_1X16 ||
1863 pixelcode == V4L2_MBUS_FMT_UYVY8_1X16)
1864 fmt->code = pixelcode;
1866 if (fmt->code == V4L2_MBUS_FMT_YUYV8_2X8)
1867 fmt->code = V4L2_MBUS_FMT_YUYV8_1X16;
1868 else if (fmt->code == V4L2_MBUS_FMT_UYVY8_2X8)
1869 fmt->code = V4L2_MBUS_FMT_UYVY8_1X16;
1872 /* Hardcode the output size to the crop rectangle size. */
1873 crop = __ccdc_get_crop(ccdc, fh, which);
1874 fmt->width = crop->width;
1875 fmt->height = crop->height;
1878 case CCDC_PAD_SOURCE_VP:
1879 *fmt = *__ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, which);
1881 /* The video port interface truncates the data to 10 bits. */
1882 info = omap3isp_video_format_info(fmt->code);
1883 fmt->code = info->truncated;
1885 /* YUV formats are not supported by the video port. */
1886 if (fmt->code == V4L2_MBUS_FMT_YUYV8_2X8 ||
1887 fmt->code == V4L2_MBUS_FMT_UYVY8_2X8)
1890 /* The number of lines that can be clocked out from the video
1891 * port output must be at least one line less than the number
1894 fmt->width = clamp_t(u32, width, 32, fmt->width);
1895 fmt->height = clamp_t(u32, height, 32, fmt->height - 1);
1899 /* Data is written to memory unpacked, each 10-bit or 12-bit pixel is
1900 * stored on 2 bytes.
1902 fmt->colorspace = V4L2_COLORSPACE_SRGB;
1903 fmt->field = V4L2_FIELD_NONE;
1907 * ccdc_try_crop - Validate a crop rectangle
1908 * @ccdc: ISP CCDC device
1909 * @sink: format on the sink pad
1910 * @crop: crop rectangle to be validated
1912 static void ccdc_try_crop(struct isp_ccdc_device *ccdc,
1913 const struct v4l2_mbus_framefmt *sink,
1914 struct v4l2_rect *crop)
1916 const struct isp_format_info *info;
1917 unsigned int max_width;
1919 /* For Bayer formats, restrict left/top and width/height to even values
1920 * to keep the Bayer pattern.
1922 info = omap3isp_video_format_info(sink->code);
1923 if (info->flavor != V4L2_MBUS_FMT_Y8_1X8) {
1928 crop->left = clamp_t(u32, crop->left, 0, sink->width - CCDC_MIN_WIDTH);
1929 crop->top = clamp_t(u32, crop->top, 0, sink->height - CCDC_MIN_HEIGHT);
1931 /* The data formatter truncates the number of horizontal output pixels
1932 * to a multiple of 16. To avoid clipping data, allow callers to request
1933 * an output size bigger than the input size up to the nearest multiple
1936 max_width = (sink->width - crop->left + 15) & ~15;
1937 crop->width = clamp_t(u32, crop->width, CCDC_MIN_WIDTH, max_width)
1939 crop->height = clamp_t(u32, crop->height, CCDC_MIN_HEIGHT,
1940 sink->height - crop->top);
1942 /* Odd width/height values don't make sense for Bayer formats. */
1943 if (info->flavor != V4L2_MBUS_FMT_Y8_1X8) {
1950 * ccdc_enum_mbus_code - Handle pixel format enumeration
1951 * @sd : pointer to v4l2 subdev structure
1952 * @fh : V4L2 subdev file handle
1953 * @code : pointer to v4l2_subdev_mbus_code_enum structure
1954 * return -EINVAL or zero on success
1956 static int ccdc_enum_mbus_code(struct v4l2_subdev *sd,
1957 struct v4l2_subdev_fh *fh,
1958 struct v4l2_subdev_mbus_code_enum *code)
1960 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
1961 struct v4l2_mbus_framefmt *format;
1963 switch (code->pad) {
1965 if (code->index >= ARRAY_SIZE(ccdc_fmts))
1968 code->code = ccdc_fmts[code->index];
1971 case CCDC_PAD_SOURCE_OF:
1972 format = __ccdc_get_format(ccdc, fh, code->pad,
1973 V4L2_SUBDEV_FORMAT_TRY);
1975 if (format->code == V4L2_MBUS_FMT_YUYV8_2X8 ||
1976 format->code == V4L2_MBUS_FMT_UYVY8_2X8) {
1977 /* In YUV mode the CCDC can swap bytes. */
1978 if (code->index == 0)
1979 code->code = V4L2_MBUS_FMT_YUYV8_1X16;
1980 else if (code->index == 1)
1981 code->code = V4L2_MBUS_FMT_UYVY8_1X16;
1985 /* In raw mode, no configurable format confversion is
1988 if (code->index == 0)
1989 code->code = format->code;
1995 case CCDC_PAD_SOURCE_VP:
1996 /* The CCDC supports no configurable format conversion
1997 * compatible with the video port. Enumerate a single output
2000 if (code->index != 0)
2003 format = __ccdc_get_format(ccdc, fh, code->pad,
2004 V4L2_SUBDEV_FORMAT_TRY);
2006 /* A pixel code equal to 0 means that the video port doesn't
2007 * support the input format. Don't enumerate any pixel code.
2009 if (format->code == 0)
2012 code->code = format->code;
2022 static int ccdc_enum_frame_size(struct v4l2_subdev *sd,
2023 struct v4l2_subdev_fh *fh,
2024 struct v4l2_subdev_frame_size_enum *fse)
2026 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2027 struct v4l2_mbus_framefmt format;
2029 if (fse->index != 0)
2032 format.code = fse->code;
2035 ccdc_try_format(ccdc, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
2036 fse->min_width = format.width;
2037 fse->min_height = format.height;
2039 if (format.code != fse->code)
2042 format.code = fse->code;
2045 ccdc_try_format(ccdc, fh, fse->pad, &format, V4L2_SUBDEV_FORMAT_TRY);
2046 fse->max_width = format.width;
2047 fse->max_height = format.height;
2053 * ccdc_get_selection - Retrieve a selection rectangle on a pad
2054 * @sd: ISP CCDC V4L2 subdevice
2055 * @fh: V4L2 subdev file handle
2056 * @sel: Selection rectangle
2058 * The only supported rectangles are the crop rectangles on the output formatter
2061 * Return 0 on success or a negative error code otherwise.
2063 static int ccdc_get_selection(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
2064 struct v4l2_subdev_selection *sel)
2066 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2067 struct v4l2_mbus_framefmt *format;
2069 if (sel->pad != CCDC_PAD_SOURCE_OF)
2072 switch (sel->target) {
2073 case V4L2_SEL_TGT_CROP_BOUNDS:
2076 sel->r.width = INT_MAX;
2077 sel->r.height = INT_MAX;
2079 format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, sel->which);
2080 ccdc_try_crop(ccdc, format, &sel->r);
2083 case V4L2_SEL_TGT_CROP:
2084 sel->r = *__ccdc_get_crop(ccdc, fh, sel->which);
2095 * ccdc_set_selection - Set a selection rectangle on a pad
2096 * @sd: ISP CCDC V4L2 subdevice
2097 * @fh: V4L2 subdev file handle
2098 * @sel: Selection rectangle
2100 * The only supported rectangle is the actual crop rectangle on the output
2101 * formatter source pad.
2103 * Return 0 on success or a negative error code otherwise.
2105 static int ccdc_set_selection(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
2106 struct v4l2_subdev_selection *sel)
2108 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2109 struct v4l2_mbus_framefmt *format;
2111 if (sel->target != V4L2_SEL_TGT_CROP ||
2112 sel->pad != CCDC_PAD_SOURCE_OF)
2115 /* The crop rectangle can't be changed while streaming. */
2116 if (ccdc->state != ISP_PIPELINE_STREAM_STOPPED)
2119 /* Modifying the crop rectangle always changes the format on the source
2120 * pad. If the KEEP_CONFIG flag is set, just return the current crop
2123 if (sel->flags & V4L2_SEL_FLAG_KEEP_CONFIG) {
2124 sel->r = *__ccdc_get_crop(ccdc, fh, sel->which);
2128 format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SINK, sel->which);
2129 ccdc_try_crop(ccdc, format, &sel->r);
2130 *__ccdc_get_crop(ccdc, fh, sel->which) = sel->r;
2132 /* Update the source format. */
2133 format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SOURCE_OF, sel->which);
2134 ccdc_try_format(ccdc, fh, CCDC_PAD_SOURCE_OF, format, sel->which);
2140 * ccdc_get_format - Retrieve the video format on a pad
2141 * @sd : ISP CCDC V4L2 subdevice
2142 * @fh : V4L2 subdev file handle
2145 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
2146 * to the format type.
2148 static int ccdc_get_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
2149 struct v4l2_subdev_format *fmt)
2151 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2152 struct v4l2_mbus_framefmt *format;
2154 format = __ccdc_get_format(ccdc, fh, fmt->pad, fmt->which);
2158 fmt->format = *format;
2163 * ccdc_set_format - Set the video format on a pad
2164 * @sd : ISP CCDC V4L2 subdevice
2165 * @fh : V4L2 subdev file handle
2168 * Return 0 on success or -EINVAL if the pad is invalid or doesn't correspond
2169 * to the format type.
2171 static int ccdc_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
2172 struct v4l2_subdev_format *fmt)
2174 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2175 struct v4l2_mbus_framefmt *format;
2176 struct v4l2_rect *crop;
2178 format = __ccdc_get_format(ccdc, fh, fmt->pad, fmt->which);
2182 ccdc_try_format(ccdc, fh, fmt->pad, &fmt->format, fmt->which);
2183 *format = fmt->format;
2185 /* Propagate the format from sink to source */
2186 if (fmt->pad == CCDC_PAD_SINK) {
2187 /* Reset the crop rectangle. */
2188 crop = __ccdc_get_crop(ccdc, fh, fmt->which);
2191 crop->width = fmt->format.width;
2192 crop->height = fmt->format.height;
2194 ccdc_try_crop(ccdc, &fmt->format, crop);
2196 /* Update the source formats. */
2197 format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SOURCE_OF,
2199 *format = fmt->format;
2200 ccdc_try_format(ccdc, fh, CCDC_PAD_SOURCE_OF, format,
2203 format = __ccdc_get_format(ccdc, fh, CCDC_PAD_SOURCE_VP,
2205 *format = fmt->format;
2206 ccdc_try_format(ccdc, fh, CCDC_PAD_SOURCE_VP, format,
2214 * Decide whether desired output pixel code can be obtained with
2215 * the lane shifter by shifting the input pixel code.
2216 * @in: input pixelcode to shifter
2217 * @out: output pixelcode from shifter
2218 * @additional_shift: # of bits the sensor's LSB is offset from CAMEXT[0]
2220 * return true if the combination is possible
2221 * return false otherwise
2223 static bool ccdc_is_shiftable(enum v4l2_mbus_pixelcode in,
2224 enum v4l2_mbus_pixelcode out,
2225 unsigned int additional_shift)
2227 const struct isp_format_info *in_info, *out_info;
2232 in_info = omap3isp_video_format_info(in);
2233 out_info = omap3isp_video_format_info(out);
2235 if ((in_info->flavor == 0) || (out_info->flavor == 0))
2238 if (in_info->flavor != out_info->flavor)
2241 return in_info->width - out_info->width + additional_shift <= 6;
2244 static int ccdc_link_validate(struct v4l2_subdev *sd,
2245 struct media_link *link,
2246 struct v4l2_subdev_format *source_fmt,
2247 struct v4l2_subdev_format *sink_fmt)
2249 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2250 unsigned long parallel_shift;
2252 /* Check if the two ends match */
2253 if (source_fmt->format.width != sink_fmt->format.width ||
2254 source_fmt->format.height != sink_fmt->format.height)
2257 /* We've got a parallel sensor here. */
2258 if (ccdc->input == CCDC_INPUT_PARALLEL) {
2259 struct isp_parallel_platform_data *pdata =
2260 &((struct isp_v4l2_subdevs_group *)
2261 media_entity_to_v4l2_subdev(link->source->entity)
2262 ->host_priv)->bus.parallel;
2263 parallel_shift = pdata->data_lane_shift * 2;
2268 /* Lane shifter may be used to drop bits on CCDC sink pad */
2269 if (!ccdc_is_shiftable(source_fmt->format.code,
2270 sink_fmt->format.code, parallel_shift))
2277 * ccdc_init_formats - Initialize formats on all pads
2278 * @sd: ISP CCDC V4L2 subdevice
2279 * @fh: V4L2 subdev file handle
2281 * Initialize all pad formats with default values. If fh is not NULL, try
2282 * formats are initialized on the file handle. Otherwise active formats are
2283 * initialized on the device.
2285 static int ccdc_init_formats(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
2287 struct v4l2_subdev_format format;
2289 memset(&format, 0, sizeof(format));
2290 format.pad = CCDC_PAD_SINK;
2291 format.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
2292 format.format.code = V4L2_MBUS_FMT_SGRBG10_1X10;
2293 format.format.width = 4096;
2294 format.format.height = 4096;
2295 ccdc_set_format(sd, fh, &format);
2300 /* V4L2 subdev core operations */
2301 static const struct v4l2_subdev_core_ops ccdc_v4l2_core_ops = {
2302 .ioctl = ccdc_ioctl,
2303 .subscribe_event = ccdc_subscribe_event,
2304 .unsubscribe_event = ccdc_unsubscribe_event,
2307 /* V4L2 subdev video operations */
2308 static const struct v4l2_subdev_video_ops ccdc_v4l2_video_ops = {
2309 .s_stream = ccdc_set_stream,
2312 /* V4L2 subdev pad operations */
2313 static const struct v4l2_subdev_pad_ops ccdc_v4l2_pad_ops = {
2314 .enum_mbus_code = ccdc_enum_mbus_code,
2315 .enum_frame_size = ccdc_enum_frame_size,
2316 .get_fmt = ccdc_get_format,
2317 .set_fmt = ccdc_set_format,
2318 .get_selection = ccdc_get_selection,
2319 .set_selection = ccdc_set_selection,
2320 .link_validate = ccdc_link_validate,
2323 /* V4L2 subdev operations */
2324 static const struct v4l2_subdev_ops ccdc_v4l2_ops = {
2325 .core = &ccdc_v4l2_core_ops,
2326 .video = &ccdc_v4l2_video_ops,
2327 .pad = &ccdc_v4l2_pad_ops,
2330 /* V4L2 subdev internal operations */
2331 static const struct v4l2_subdev_internal_ops ccdc_v4l2_internal_ops = {
2332 .open = ccdc_init_formats,
2335 /* -----------------------------------------------------------------------------
2336 * Media entity operations
2340 * ccdc_link_setup - Setup CCDC connections
2341 * @entity: CCDC media entity
2342 * @local: Pad at the local end of the link
2343 * @remote: Pad at the remote end of the link
2344 * @flags: Link flags
2346 * return -EINVAL or zero on success
2348 static int ccdc_link_setup(struct media_entity *entity,
2349 const struct media_pad *local,
2350 const struct media_pad *remote, u32 flags)
2352 struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
2353 struct isp_ccdc_device *ccdc = v4l2_get_subdevdata(sd);
2354 struct isp_device *isp = to_isp_device(ccdc);
2356 switch (local->index | media_entity_type(remote->entity)) {
2357 case CCDC_PAD_SINK | MEDIA_ENT_T_V4L2_SUBDEV:
2358 /* Read from the sensor (parallel interface), CCP2, CSI2a or
2361 if (!(flags & MEDIA_LNK_FL_ENABLED)) {
2362 ccdc->input = CCDC_INPUT_NONE;
2366 if (ccdc->input != CCDC_INPUT_NONE)
2369 if (remote->entity == &isp->isp_ccp2.subdev.entity)
2370 ccdc->input = CCDC_INPUT_CCP2B;
2371 else if (remote->entity == &isp->isp_csi2a.subdev.entity)
2372 ccdc->input = CCDC_INPUT_CSI2A;
2373 else if (remote->entity == &isp->isp_csi2c.subdev.entity)
2374 ccdc->input = CCDC_INPUT_CSI2C;
2376 ccdc->input = CCDC_INPUT_PARALLEL;
2381 * The ISP core doesn't support pipelines with multiple video outputs.
2382 * Revisit this when it will be implemented, and return -EBUSY for now.
2385 case CCDC_PAD_SOURCE_VP | MEDIA_ENT_T_V4L2_SUBDEV:
2386 /* Write to preview engine, histogram and H3A. When none of
2387 * those links are active, the video port can be disabled.
2389 if (flags & MEDIA_LNK_FL_ENABLED) {
2390 if (ccdc->output & ~CCDC_OUTPUT_PREVIEW)
2392 ccdc->output |= CCDC_OUTPUT_PREVIEW;
2394 ccdc->output &= ~CCDC_OUTPUT_PREVIEW;
2398 case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_DEVNODE:
2399 /* Write to memory */
2400 if (flags & MEDIA_LNK_FL_ENABLED) {
2401 if (ccdc->output & ~CCDC_OUTPUT_MEMORY)
2403 ccdc->output |= CCDC_OUTPUT_MEMORY;
2405 ccdc->output &= ~CCDC_OUTPUT_MEMORY;
2409 case CCDC_PAD_SOURCE_OF | MEDIA_ENT_T_V4L2_SUBDEV:
2410 /* Write to resizer */
2411 if (flags & MEDIA_LNK_FL_ENABLED) {
2412 if (ccdc->output & ~CCDC_OUTPUT_RESIZER)
2414 ccdc->output |= CCDC_OUTPUT_RESIZER;
2416 ccdc->output &= ~CCDC_OUTPUT_RESIZER;
2427 /* media operations */
2428 static const struct media_entity_operations ccdc_media_ops = {
2429 .link_setup = ccdc_link_setup,
2430 .link_validate = v4l2_subdev_link_validate,
2433 void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
2435 v4l2_device_unregister_subdev(&ccdc->subdev);
2436 omap3isp_video_unregister(&ccdc->video_out);
2439 int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
2440 struct v4l2_device *vdev)
2444 /* Register the subdev and video node. */
2445 ret = v4l2_device_register_subdev(vdev, &ccdc->subdev);
2449 ret = omap3isp_video_register(&ccdc->video_out, vdev);
2456 omap3isp_ccdc_unregister_entities(ccdc);
2460 /* -----------------------------------------------------------------------------
2461 * ISP CCDC initialisation and cleanup
2465 * ccdc_init_entities - Initialize V4L2 subdev and media entity
2466 * @ccdc: ISP CCDC module
2468 * Return 0 on success and a negative error code on failure.
2470 static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
2472 struct v4l2_subdev *sd = &ccdc->subdev;
2473 struct media_pad *pads = ccdc->pads;
2474 struct media_entity *me = &sd->entity;
2477 ccdc->input = CCDC_INPUT_NONE;
2479 v4l2_subdev_init(sd, &ccdc_v4l2_ops);
2480 sd->internal_ops = &ccdc_v4l2_internal_ops;
2481 strlcpy(sd->name, "OMAP3 ISP CCDC", sizeof(sd->name));
2482 sd->grp_id = 1 << 16; /* group ID for isp subdevs */
2483 v4l2_set_subdevdata(sd, ccdc);
2484 sd->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
2486 pads[CCDC_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
2487 pads[CCDC_PAD_SOURCE_VP].flags = MEDIA_PAD_FL_SOURCE;
2488 pads[CCDC_PAD_SOURCE_OF].flags = MEDIA_PAD_FL_SOURCE;
2490 me->ops = &ccdc_media_ops;
2491 ret = media_entity_init(me, CCDC_PADS_NUM, pads, 0);
2495 ccdc_init_formats(sd, NULL);
2497 ccdc->video_out.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2498 ccdc->video_out.ops = &ccdc_video_ops;
2499 ccdc->video_out.isp = to_isp_device(ccdc);
2500 ccdc->video_out.capture_mem = PAGE_ALIGN(4096 * 4096) * 3;
2501 ccdc->video_out.bpl_alignment = 32;
2503 ret = omap3isp_video_init(&ccdc->video_out, "CCDC");
2507 /* Connect the CCDC subdev to the video node. */
2508 ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
2509 &ccdc->video_out.video.entity, 0, 0);
2516 omap3isp_video_cleanup(&ccdc->video_out);
2518 media_entity_cleanup(me);
2523 * omap3isp_ccdc_init - CCDC module initialization.
2524 * @dev: Device pointer specific to the OMAP3 ISP.
2526 * TODO: Get the initialisation values from platform data.
2528 * Return 0 on success or a negative error code otherwise.
2530 int omap3isp_ccdc_init(struct isp_device *isp)
2532 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
2535 spin_lock_init(&ccdc->lock);
2536 init_waitqueue_head(&ccdc->wait);
2537 mutex_init(&ccdc->ioctl_lock);
2539 ccdc->stopping = CCDC_STOP_NOT_REQUESTED;
2541 INIT_WORK(&ccdc->lsc.table_work, ccdc_lsc_free_table_work);
2542 ccdc->lsc.state = LSC_STATE_STOPPED;
2543 INIT_LIST_HEAD(&ccdc->lsc.free_queue);
2544 spin_lock_init(&ccdc->lsc.req_lock);
2546 ccdc->clamp.oblen = 0;
2547 ccdc->clamp.dcsubval = 0;
2549 ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
2550 ccdc_apply_controls(ccdc);
2552 ret = ccdc_init_entities(ccdc);
2554 mutex_destroy(&ccdc->ioctl_lock);
2562 * omap3isp_ccdc_cleanup - CCDC module cleanup.
2563 * @dev: Device pointer specific to the OMAP3 ISP.
2565 void omap3isp_ccdc_cleanup(struct isp_device *isp)
2567 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
2569 omap3isp_video_cleanup(&ccdc->video_out);
2570 media_entity_cleanup(&ccdc->subdev.entity);
2572 /* Free LSC requests. As the CCDC is stopped there's no active request,
2573 * so only the pending request and the free queue need to be handled.
2575 ccdc_lsc_free_request(ccdc, ccdc->lsc.request);
2576 cancel_work_sync(&ccdc->lsc.table_work);
2577 ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue);
2579 if (ccdc->fpc.fpcaddr != 0)
2580 omap_iommu_vfree(isp->domain, isp->dev, ccdc->fpc.fpcaddr);
2582 mutex_destroy(&ccdc->ioctl_lock);