2 * Copyright (C) 2006-2009 Texas Instruments Inc
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * CCDC hardware module for DM6446
19 * ------------------------------
21 * This module is for configuring CCD controller of DM6446 VPFE to capture
22 * Raw yuv or Bayer RGB data from a decoder. CCDC has several modules
23 * such as Defect Pixel Correction, Color Space Conversion etc to
24 * pre-process the Raw Bayer RGB data, before writing it to SDRAM. This
25 * module also allows application to configure individual
26 * module parameters through VPFE_CMD_S_CCDC_RAW_PARAMS IOCTL.
27 * To do so, application includes dm644x_ccdc.h and vpfe_capture.h header
28 * files. The setparams() API is called by vpfe_capture driver
29 * to configure module parameters. This file is named DM644x so that other
30 * variants such DM6443 may be supported using the same module.
32 * TODO: Test Raw bayer parameter settings and bayer capture
33 * Split module parameter structure to module specific ioctl structs
34 * investigate if enum used for user space type definition
35 * to be replaced by #defines or integer
37 #include <linux/platform_device.h>
38 #include <linux/uaccess.h>
39 #include <linux/videodev2.h>
40 #include <media/davinci/dm644x_ccdc.h>
41 #include <media/davinci/vpss.h>
42 #include "dm644x_ccdc_regs.h"
43 #include "ccdc_hw_device.h"
45 MODULE_LICENSE("GPL");
46 MODULE_DESCRIPTION("CCDC Driver for DM6446");
47 MODULE_AUTHOR("Texas Instruments");
49 static struct device
*dev
;
51 /* Object for CCDC raw mode */
52 static struct ccdc_params_raw ccdc_hw_params_raw
= {
53 .pix_fmt
= CCDC_PIXFMT_RAW
,
54 .frm_fmt
= CCDC_FRMFMT_PROGRESSIVE
,
56 .fid_pol
= VPFE_PINPOL_POSITIVE
,
57 .vd_pol
= VPFE_PINPOL_POSITIVE
,
58 .hd_pol
= VPFE_PINPOL_POSITIVE
,
60 .data_sz
= CCDC_DATA_10BITS
,
64 /* Object for CCDC ycbcr mode */
65 static struct ccdc_params_ycbcr ccdc_hw_params_ycbcr
= {
66 .pix_fmt
= CCDC_PIXFMT_YCBCR_8BIT
,
67 .frm_fmt
= CCDC_FRMFMT_INTERLACED
,
69 .fid_pol
= VPFE_PINPOL_POSITIVE
,
70 .vd_pol
= VPFE_PINPOL_POSITIVE
,
71 .hd_pol
= VPFE_PINPOL_POSITIVE
,
73 .pix_order
= CCDC_PIXORDER_CBYCRY
,
74 .buf_type
= CCDC_BUFTYPE_FLD_INTERLEAVED
77 #define CCDC_MAX_RAW_YUV_FORMATS 2
79 /* Raw Bayer formats */
80 static u32 ccdc_raw_bayer_pix_formats
[] =
81 {V4L2_PIX_FMT_SBGGR8
, V4L2_PIX_FMT_SBGGR16
};
84 static u32 ccdc_raw_yuv_pix_formats
[] =
85 {V4L2_PIX_FMT_UYVY
, V4L2_PIX_FMT_YUYV
};
87 static void *__iomem ccdc_base_addr
;
88 static int ccdc_addr_size
;
89 static enum vpfe_hw_if_type ccdc_if_type
;
91 /* register access routines */
92 static inline u32
regr(u32 offset
)
94 return __raw_readl(ccdc_base_addr
+ offset
);
97 static inline void regw(u32 val
, u32 offset
)
99 __raw_writel(val
, ccdc_base_addr
+ offset
);
102 static void ccdc_set_ccdc_base(void *addr
, int size
)
104 ccdc_base_addr
= addr
;
105 ccdc_addr_size
= size
;
108 static void ccdc_enable(int flag
)
110 regw(flag
, CCDC_PCR
);
113 static void ccdc_enable_vport(int flag
)
116 /* enable video port */
117 regw(CCDC_ENABLE_VIDEO_PORT
, CCDC_FMTCFG
);
119 regw(CCDC_DISABLE_VIDEO_PORT
, CCDC_FMTCFG
);
124 * This function will configure the window size
125 * to be capture in CCDC reg
127 void ccdc_setwin(struct v4l2_rect
*image_win
,
128 enum ccdc_frmfmt frm_fmt
,
131 int horz_start
, horz_nr_pixels
;
132 int vert_start
, vert_nr_lines
;
133 int val
= 0, mid_img
= 0;
135 dev_dbg(dev
, "\nStarting ccdc_setwin...");
137 * ppc - per pixel count. indicates how many pixels per cell
138 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
139 * raw capture this is 1
141 horz_start
= image_win
->left
<< (ppc
- 1);
142 horz_nr_pixels
= (image_win
->width
<< (ppc
- 1)) - 1;
143 regw((horz_start
<< CCDC_HORZ_INFO_SPH_SHIFT
) | horz_nr_pixels
,
146 vert_start
= image_win
->top
;
148 if (frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
149 vert_nr_lines
= (image_win
->height
>> 1) - 1;
151 /* Since first line doesn't have any data */
153 /* configure VDINT0 */
154 val
= (vert_start
<< CCDC_VDINT_VDINT0_SHIFT
);
155 regw(val
, CCDC_VDINT
);
158 /* Since first line doesn't have any data */
160 vert_nr_lines
= image_win
->height
- 1;
162 * configure VDINT0 and VDINT1. VDINT1 will be at half
165 mid_img
= vert_start
+ (image_win
->height
/ 2);
166 val
= (vert_start
<< CCDC_VDINT_VDINT0_SHIFT
) |
167 (mid_img
& CCDC_VDINT_VDINT1_MASK
);
168 regw(val
, CCDC_VDINT
);
171 regw((vert_start
<< CCDC_VERT_START_SLV0_SHIFT
) | vert_start
,
173 regw(vert_nr_lines
, CCDC_VERT_LINES
);
174 dev_dbg(dev
, "\nEnd of ccdc_setwin...");
177 static void ccdc_readregs(void)
179 unsigned int val
= 0;
181 val
= regr(CCDC_ALAW
);
182 dev_notice(dev
, "\nReading 0x%x to ALAW...\n", val
);
183 val
= regr(CCDC_CLAMP
);
184 dev_notice(dev
, "\nReading 0x%x to CLAMP...\n", val
);
185 val
= regr(CCDC_DCSUB
);
186 dev_notice(dev
, "\nReading 0x%x to DCSUB...\n", val
);
187 val
= regr(CCDC_BLKCMP
);
188 dev_notice(dev
, "\nReading 0x%x to BLKCMP...\n", val
);
189 val
= regr(CCDC_FPC_ADDR
);
190 dev_notice(dev
, "\nReading 0x%x to FPC_ADDR...\n", val
);
191 val
= regr(CCDC_FPC
);
192 dev_notice(dev
, "\nReading 0x%x to FPC...\n", val
);
193 val
= regr(CCDC_FMTCFG
);
194 dev_notice(dev
, "\nReading 0x%x to FMTCFG...\n", val
);
195 val
= regr(CCDC_COLPTN
);
196 dev_notice(dev
, "\nReading 0x%x to COLPTN...\n", val
);
197 val
= regr(CCDC_FMT_HORZ
);
198 dev_notice(dev
, "\nReading 0x%x to FMT_HORZ...\n", val
);
199 val
= regr(CCDC_FMT_VERT
);
200 dev_notice(dev
, "\nReading 0x%x to FMT_VERT...\n", val
);
201 val
= regr(CCDC_HSIZE_OFF
);
202 dev_notice(dev
, "\nReading 0x%x to HSIZE_OFF...\n", val
);
203 val
= regr(CCDC_SDOFST
);
204 dev_notice(dev
, "\nReading 0x%x to SDOFST...\n", val
);
205 val
= regr(CCDC_VP_OUT
);
206 dev_notice(dev
, "\nReading 0x%x to VP_OUT...\n", val
);
207 val
= regr(CCDC_SYN_MODE
);
208 dev_notice(dev
, "\nReading 0x%x to SYN_MODE...\n", val
);
209 val
= regr(CCDC_HORZ_INFO
);
210 dev_notice(dev
, "\nReading 0x%x to HORZ_INFO...\n", val
);
211 val
= regr(CCDC_VERT_START
);
212 dev_notice(dev
, "\nReading 0x%x to VERT_START...\n", val
);
213 val
= regr(CCDC_VERT_LINES
);
214 dev_notice(dev
, "\nReading 0x%x to VERT_LINES...\n", val
);
217 static int validate_ccdc_param(struct ccdc_config_params_raw
*ccdcparam
)
219 if (ccdcparam
->alaw
.enable
) {
220 if ((ccdcparam
->alaw
.gama_wd
> CCDC_GAMMA_BITS_09_0
) ||
221 (ccdcparam
->alaw
.gama_wd
< CCDC_GAMMA_BITS_15_6
) ||
222 (ccdcparam
->alaw
.gama_wd
< ccdcparam
->data_sz
)) {
223 dev_dbg(dev
, "\nInvalid data line select");
230 static int ccdc_update_raw_params(struct ccdc_config_params_raw
*raw_params
)
232 struct ccdc_config_params_raw
*config_params
=
233 &ccdc_hw_params_raw
.config_params
;
234 unsigned int *fpc_virtaddr
= NULL
;
235 unsigned int *fpc_physaddr
= NULL
;
237 memcpy(config_params
, raw_params
, sizeof(*raw_params
));
239 * allocate memory for fault pixel table and copy the user
240 * values to the table
242 if (!config_params
->fault_pxl
.enable
)
245 fpc_physaddr
= (unsigned int *)config_params
->fault_pxl
.fpc_table_addr
;
246 fpc_virtaddr
= (unsigned int *)phys_to_virt(
247 (unsigned long)fpc_physaddr
);
249 * Allocate memory for FPC table if current
250 * FPC table buffer is not big enough to
251 * accomodate FPC Number requested
253 if (raw_params
->fault_pxl
.fp_num
!= config_params
->fault_pxl
.fp_num
) {
254 if (fpc_physaddr
!= NULL
) {
255 free_pages((unsigned long)fpc_physaddr
,
257 (config_params
->fault_pxl
.fp_num
*
261 /* Allocate memory for FPC table */
263 (unsigned int *)__get_free_pages(GFP_KERNEL
| GFP_DMA
,
264 get_order(raw_params
->
268 if (fpc_virtaddr
== NULL
) {
270 "\nUnable to allocate memory for FPC");
274 (unsigned int *)virt_to_phys((void *)fpc_virtaddr
);
277 /* Copy number of fault pixels and FPC table */
278 config_params
->fault_pxl
.fp_num
= raw_params
->fault_pxl
.fp_num
;
279 if (copy_from_user(fpc_virtaddr
,
280 (void __user
*)raw_params
->fault_pxl
.fpc_table_addr
,
281 config_params
->fault_pxl
.fp_num
* FP_NUM_BYTES
)) {
282 dev_dbg(dev
, "\n copy_from_user failed");
285 config_params
->fault_pxl
.fpc_table_addr
= (unsigned int)fpc_physaddr
;
289 static int ccdc_close(struct device
*dev
)
291 struct ccdc_config_params_raw
*config_params
=
292 &ccdc_hw_params_raw
.config_params
;
293 unsigned int *fpc_physaddr
= NULL
, *fpc_virtaddr
= NULL
;
295 fpc_physaddr
= (unsigned int *)config_params
->fault_pxl
.fpc_table_addr
;
297 if (fpc_physaddr
!= NULL
) {
298 fpc_virtaddr
= (unsigned int *)
299 phys_to_virt((unsigned long)fpc_physaddr
);
300 free_pages((unsigned long)fpc_virtaddr
,
301 get_order(config_params
->fault_pxl
.fp_num
*
308 * ccdc_restore_defaults()
309 * This function will write defaults to all CCDC registers
311 static void ccdc_restore_defaults(void)
317 /* set all registers to default value */
318 for (i
= 4; i
<= 0x94; i
+= 4)
320 regw(CCDC_NO_CULLING
, CCDC_CULLING
);
321 regw(CCDC_GAMMA_BITS_11_2
, CCDC_ALAW
);
324 static int ccdc_open(struct device
*device
)
327 ccdc_restore_defaults();
328 if (ccdc_if_type
== VPFE_RAW_BAYER
)
329 ccdc_enable_vport(1);
333 static void ccdc_sbl_reset(void)
335 vpss_clear_wbl_overflow(VPSS_PCR_CCDC_WBL_O
);
338 /* Parameter operations */
339 static int ccdc_set_params(void __user
*params
)
341 struct ccdc_config_params_raw ccdc_raw_params
;
344 if (ccdc_if_type
!= VPFE_RAW_BAYER
)
347 x
= copy_from_user(&ccdc_raw_params
, params
, sizeof(ccdc_raw_params
));
349 dev_dbg(dev
, "ccdc_set_params: error in copying"
350 "ccdc params, %d\n", x
);
354 if (!validate_ccdc_param(&ccdc_raw_params
)) {
355 if (!ccdc_update_raw_params(&ccdc_raw_params
))
362 * ccdc_config_ycbcr()
363 * This function will configure CCDC for YCbCr video capture
365 void ccdc_config_ycbcr(void)
367 struct ccdc_params_ycbcr
*params
= &ccdc_hw_params_ycbcr
;
370 dev_dbg(dev
, "\nStarting ccdc_config_ycbcr...");
372 * first restore the CCDC registers to default values
373 * This is important since we assume default values to be set in
374 * a lot of registers that we didn't touch
376 ccdc_restore_defaults();
379 * configure pixel format, frame format, configure video frame
380 * format, enable output to SDRAM, enable internal timing generator
383 syn_mode
= (((params
->pix_fmt
& CCDC_SYN_MODE_INPMOD_MASK
) <<
384 CCDC_SYN_MODE_INPMOD_SHIFT
) |
385 ((params
->frm_fmt
& CCDC_SYN_FLDMODE_MASK
) <<
386 CCDC_SYN_FLDMODE_SHIFT
) | CCDC_VDHDEN_ENABLE
|
387 CCDC_WEN_ENABLE
| CCDC_DATA_PACK_ENABLE
);
389 /* setup BT.656 sync mode */
390 if (params
->bt656_enable
) {
391 regw(CCDC_REC656IF_BT656_EN
, CCDC_REC656IF
);
394 * configure the FID, VD, HD pin polarity,
395 * fld,hd pol positive, vd negative, 8-bit data
397 syn_mode
|= CCDC_SYN_MODE_VD_POL_NEGATIVE
| CCDC_SYN_MODE_8BITS
;
399 /* y/c external sync mode */
400 syn_mode
|= (((params
->fid_pol
& CCDC_FID_POL_MASK
) <<
401 CCDC_FID_POL_SHIFT
) |
402 ((params
->hd_pol
& CCDC_HD_POL_MASK
) <<
404 ((params
->vd_pol
& CCDC_VD_POL_MASK
) <<
407 regw(syn_mode
, CCDC_SYN_MODE
);
409 /* configure video window */
410 ccdc_setwin(¶ms
->win
, params
->frm_fmt
, 2);
413 * configure the order of y cb cr in SDRAM, and disable latch
414 * internal register on vsync
416 regw((params
->pix_order
<< CCDC_CCDCFG_Y8POS_SHIFT
) |
417 CCDC_LATCH_ON_VSYNC_DISABLE
, CCDC_CCDCFG
);
420 * configure the horizontal line offset. This should be a
421 * on 32 byte bondary. So clear LSB 5 bits
423 regw(((params
->win
.width
* 2 + 31) & ~0x1f), CCDC_HSIZE_OFF
);
425 /* configure the memory line offset */
426 if (params
->buf_type
== CCDC_BUFTYPE_FLD_INTERLEAVED
)
427 /* two fields are interleaved in memory */
428 regw(CCDC_SDOFST_FIELD_INTERLEAVED
, CCDC_SDOFST
);
431 dev_dbg(dev
, "\nEnd of ccdc_config_ycbcr...\n");
435 static void ccdc_config_black_clamp(struct ccdc_black_clamp
*bclamp
)
439 if (!bclamp
->enable
) {
440 /* configure DCSub */
441 val
= (bclamp
->dc_sub
) & CCDC_BLK_DC_SUB_MASK
;
442 regw(val
, CCDC_DCSUB
);
443 dev_dbg(dev
, "\nWriting 0x%x to DCSUB...\n", val
);
444 regw(CCDC_CLAMP_DEFAULT_VAL
, CCDC_CLAMP
);
445 dev_dbg(dev
, "\nWriting 0x0000 to CLAMP...\n");
449 * Configure gain, Start pixel, No of line to be avg,
450 * No of pixel/line to be avg, & Enable the Black clamping
452 val
= ((bclamp
->sgain
& CCDC_BLK_SGAIN_MASK
) |
453 ((bclamp
->start_pixel
& CCDC_BLK_ST_PXL_MASK
) <<
454 CCDC_BLK_ST_PXL_SHIFT
) |
455 ((bclamp
->sample_ln
& CCDC_BLK_SAMPLE_LINE_MASK
) <<
456 CCDC_BLK_SAMPLE_LINE_SHIFT
) |
457 ((bclamp
->sample_pixel
& CCDC_BLK_SAMPLE_LN_MASK
) <<
458 CCDC_BLK_SAMPLE_LN_SHIFT
) | CCDC_BLK_CLAMP_ENABLE
);
459 regw(val
, CCDC_CLAMP
);
460 dev_dbg(dev
, "\nWriting 0x%x to CLAMP...\n", val
);
461 /* If Black clamping is enable then make dcsub 0 */
462 regw(CCDC_DCSUB_DEFAULT_VAL
, CCDC_DCSUB
);
463 dev_dbg(dev
, "\nWriting 0x00000000 to DCSUB...\n");
466 static void ccdc_config_black_compense(struct ccdc_black_compensation
*bcomp
)
470 val
= ((bcomp
->b
& CCDC_BLK_COMP_MASK
) |
471 ((bcomp
->gb
& CCDC_BLK_COMP_MASK
) <<
472 CCDC_BLK_COMP_GB_COMP_SHIFT
) |
473 ((bcomp
->gr
& CCDC_BLK_COMP_MASK
) <<
474 CCDC_BLK_COMP_GR_COMP_SHIFT
) |
475 ((bcomp
->r
& CCDC_BLK_COMP_MASK
) <<
476 CCDC_BLK_COMP_R_COMP_SHIFT
));
477 regw(val
, CCDC_BLKCMP
);
480 static void ccdc_config_fpc(struct ccdc_fault_pixel
*fpc
)
484 /* Initially disable FPC */
485 val
= CCDC_FPC_DISABLE
;
491 /* Configure Fault pixel if needed */
492 regw(fpc
->fpc_table_addr
, CCDC_FPC_ADDR
);
493 dev_dbg(dev
, "\nWriting 0x%x to FPC_ADDR...\n",
494 (fpc
->fpc_table_addr
));
495 /* Write the FPC params with FPC disable */
496 val
= fpc
->fp_num
& CCDC_FPC_FPC_NUM_MASK
;
499 dev_dbg(dev
, "\nWriting 0x%x to FPC...\n", val
);
500 /* read the FPC register */
501 val
= regr(CCDC_FPC
) | CCDC_FPC_ENABLE
;
503 dev_dbg(dev
, "\nWriting 0x%x to FPC...\n", val
);
508 * This function will configure CCDC for Raw capture mode
510 void ccdc_config_raw(void)
512 struct ccdc_params_raw
*params
= &ccdc_hw_params_raw
;
513 struct ccdc_config_params_raw
*config_params
=
514 &ccdc_hw_params_raw
.config_params
;
515 unsigned int syn_mode
= 0;
518 dev_dbg(dev
, "\nStarting ccdc_config_raw...");
521 ccdc_restore_defaults();
523 /* Disable latching function registers on VSYNC */
524 regw(CCDC_LATCH_ON_VSYNC_DISABLE
, CCDC_CCDCFG
);
527 * Configure the vertical sync polarity(SYN_MODE.VDPOL),
528 * horizontal sync polarity (SYN_MODE.HDPOL), frame id polarity
529 * (SYN_MODE.FLDPOL), frame format(progressive or interlace),
530 * data size(SYNMODE.DATSIZ), &pixel format (Input mode), output
531 * SDRAM, enable internal timing generator
534 (((params
->vd_pol
& CCDC_VD_POL_MASK
) << CCDC_VD_POL_SHIFT
) |
535 ((params
->hd_pol
& CCDC_HD_POL_MASK
) << CCDC_HD_POL_SHIFT
) |
536 ((params
->fid_pol
& CCDC_FID_POL_MASK
) << CCDC_FID_POL_SHIFT
) |
537 ((params
->frm_fmt
& CCDC_FRM_FMT_MASK
) << CCDC_FRM_FMT_SHIFT
) |
538 ((config_params
->data_sz
& CCDC_DATA_SZ_MASK
) <<
539 CCDC_DATA_SZ_SHIFT
) |
540 ((params
->pix_fmt
& CCDC_PIX_FMT_MASK
) << CCDC_PIX_FMT_SHIFT
) |
541 CCDC_WEN_ENABLE
| CCDC_VDHDEN_ENABLE
);
543 /* Enable and configure aLaw register if needed */
544 if (config_params
->alaw
.enable
) {
545 val
= ((config_params
->alaw
.gama_wd
&
546 CCDC_ALAW_GAMA_WD_MASK
) | CCDC_ALAW_ENABLE
);
547 regw(val
, CCDC_ALAW
);
548 dev_dbg(dev
, "\nWriting 0x%x to ALAW...\n", val
);
551 /* Configure video window */
552 ccdc_setwin(¶ms
->win
, params
->frm_fmt
, CCDC_PPC_RAW
);
554 /* Configure Black Clamp */
555 ccdc_config_black_clamp(&config_params
->blk_clamp
);
557 /* Configure Black level compensation */
558 ccdc_config_black_compense(&config_params
->blk_comp
);
560 /* Configure Fault Pixel Correction */
561 ccdc_config_fpc(&config_params
->fault_pxl
);
563 /* If data size is 8 bit then pack the data */
564 if ((config_params
->data_sz
== CCDC_DATA_8BITS
) ||
565 config_params
->alaw
.enable
)
566 syn_mode
|= CCDC_DATA_PACK_ENABLE
;
568 #ifdef CONFIG_DM644X_VIDEO_PORT_ENABLE
569 /* enable video port */
570 val
= CCDC_ENABLE_VIDEO_PORT
;
572 /* disable video port */
573 val
= CCDC_DISABLE_VIDEO_PORT
;
576 if (config_params
->data_sz
== CCDC_DATA_8BITS
)
577 val
|= (CCDC_DATA_10BITS
& CCDC_FMTCFG_VPIN_MASK
)
578 << CCDC_FMTCFG_VPIN_SHIFT
;
580 val
|= (config_params
->data_sz
& CCDC_FMTCFG_VPIN_MASK
)
581 << CCDC_FMTCFG_VPIN_SHIFT
;
582 /* Write value in FMTCFG */
583 regw(val
, CCDC_FMTCFG
);
585 dev_dbg(dev
, "\nWriting 0x%x to FMTCFG...\n", val
);
586 /* Configure the color pattern according to mt9t001 sensor */
587 regw(CCDC_COLPTN_VAL
, CCDC_COLPTN
);
589 dev_dbg(dev
, "\nWriting 0xBB11BB11 to COLPTN...\n");
591 * Configure Data formatter(Video port) pixel selection
592 * (FMT_HORZ, FMT_VERT)
594 val
= ((params
->win
.left
& CCDC_FMT_HORZ_FMTSPH_MASK
) <<
595 CCDC_FMT_HORZ_FMTSPH_SHIFT
) |
596 (params
->win
.width
& CCDC_FMT_HORZ_FMTLNH_MASK
);
597 regw(val
, CCDC_FMT_HORZ
);
599 dev_dbg(dev
, "\nWriting 0x%x to FMT_HORZ...\n", val
);
600 val
= (params
->win
.top
& CCDC_FMT_VERT_FMTSLV_MASK
)
601 << CCDC_FMT_VERT_FMTSLV_SHIFT
;
602 if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
)
603 val
|= (params
->win
.height
) & CCDC_FMT_VERT_FMTLNV_MASK
;
605 val
|= (params
->win
.height
>> 1) & CCDC_FMT_VERT_FMTLNV_MASK
;
607 dev_dbg(dev
, "\nparams->win.height 0x%x ...\n",
609 regw(val
, CCDC_FMT_VERT
);
611 dev_dbg(dev
, "\nWriting 0x%x to FMT_VERT...\n", val
);
613 dev_dbg(dev
, "\nbelow regw(val, FMT_VERT)...");
616 * Configure Horizontal offset register. If pack 8 is enabled then
617 * 1 pixel will take 1 byte
619 if ((config_params
->data_sz
== CCDC_DATA_8BITS
) ||
620 config_params
->alaw
.enable
)
621 regw((params
->win
.width
+ CCDC_32BYTE_ALIGN_VAL
) &
622 CCDC_HSIZE_OFF_MASK
, CCDC_HSIZE_OFF
);
624 /* else one pixel will take 2 byte */
625 regw(((params
->win
.width
* CCDC_TWO_BYTES_PER_PIXEL
) +
626 CCDC_32BYTE_ALIGN_VAL
) & CCDC_HSIZE_OFF_MASK
,
629 /* Set value for SDOFST */
630 if (params
->frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
631 if (params
->image_invert_enable
) {
632 /* For intelace inverse mode */
633 regw(CCDC_INTERLACED_IMAGE_INVERT
, CCDC_SDOFST
);
634 dev_dbg(dev
, "\nWriting 0x4B6D to SDOFST...\n");
638 /* For intelace non inverse mode */
639 regw(CCDC_INTERLACED_NO_IMAGE_INVERT
, CCDC_SDOFST
);
640 dev_dbg(dev
, "\nWriting 0x0249 to SDOFST...\n");
642 } else if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
) {
643 regw(CCDC_PROGRESSIVE_NO_IMAGE_INVERT
, CCDC_SDOFST
);
644 dev_dbg(dev
, "\nWriting 0x0000 to SDOFST...\n");
648 * Configure video port pixel selection (VPOUT)
649 * Here -1 is to make the height value less than FMT_VERT.FMTLNV
651 if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
)
652 val
= (((params
->win
.height
- 1) & CCDC_VP_OUT_VERT_NUM_MASK
))
653 << CCDC_VP_OUT_VERT_NUM_SHIFT
;
656 ((((params
->win
.height
>> CCDC_INTERLACED_HEIGHT_SHIFT
) -
657 1) & CCDC_VP_OUT_VERT_NUM_MASK
)) <<
658 CCDC_VP_OUT_VERT_NUM_SHIFT
;
660 val
|= ((((params
->win
.width
))) & CCDC_VP_OUT_HORZ_NUM_MASK
)
661 << CCDC_VP_OUT_HORZ_NUM_SHIFT
;
662 val
|= (params
->win
.left
) & CCDC_VP_OUT_HORZ_ST_MASK
;
663 regw(val
, CCDC_VP_OUT
);
665 dev_dbg(dev
, "\nWriting 0x%x to VP_OUT...\n", val
);
666 regw(syn_mode
, CCDC_SYN_MODE
);
667 dev_dbg(dev
, "\nWriting 0x%x to SYN_MODE...\n", syn_mode
);
670 dev_dbg(dev
, "\nend of ccdc_config_raw...");
674 static int ccdc_configure(void)
676 if (ccdc_if_type
== VPFE_RAW_BAYER
)
683 static int ccdc_set_buftype(enum ccdc_buftype buf_type
)
685 if (ccdc_if_type
== VPFE_RAW_BAYER
)
686 ccdc_hw_params_raw
.buf_type
= buf_type
;
688 ccdc_hw_params_ycbcr
.buf_type
= buf_type
;
692 static enum ccdc_buftype
ccdc_get_buftype(void)
694 if (ccdc_if_type
== VPFE_RAW_BAYER
)
695 return ccdc_hw_params_raw
.buf_type
;
696 return ccdc_hw_params_ycbcr
.buf_type
;
699 static int ccdc_enum_pix(u32
*pix
, int i
)
702 if (ccdc_if_type
== VPFE_RAW_BAYER
) {
703 if (i
< ARRAY_SIZE(ccdc_raw_bayer_pix_formats
)) {
704 *pix
= ccdc_raw_bayer_pix_formats
[i
];
708 if (i
< ARRAY_SIZE(ccdc_raw_yuv_pix_formats
)) {
709 *pix
= ccdc_raw_yuv_pix_formats
[i
];
716 static int ccdc_set_pixel_format(u32 pixfmt
)
718 if (ccdc_if_type
== VPFE_RAW_BAYER
) {
719 ccdc_hw_params_raw
.pix_fmt
= CCDC_PIXFMT_RAW
;
720 if (pixfmt
== V4L2_PIX_FMT_SBGGR8
)
721 ccdc_hw_params_raw
.config_params
.alaw
.enable
= 1;
722 else if (pixfmt
!= V4L2_PIX_FMT_SBGGR16
)
725 if (pixfmt
== V4L2_PIX_FMT_YUYV
)
726 ccdc_hw_params_ycbcr
.pix_order
= CCDC_PIXORDER_YCBYCR
;
727 else if (pixfmt
== V4L2_PIX_FMT_UYVY
)
728 ccdc_hw_params_ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
735 static u32
ccdc_get_pixel_format(void)
737 struct ccdc_a_law
*alaw
=
738 &ccdc_hw_params_raw
.config_params
.alaw
;
741 if (ccdc_if_type
== VPFE_RAW_BAYER
)
743 pixfmt
= V4L2_PIX_FMT_SBGGR8
;
745 pixfmt
= V4L2_PIX_FMT_SBGGR16
;
747 if (ccdc_hw_params_ycbcr
.pix_order
== CCDC_PIXORDER_YCBYCR
)
748 pixfmt
= V4L2_PIX_FMT_YUYV
;
750 pixfmt
= V4L2_PIX_FMT_UYVY
;
755 static int ccdc_set_image_window(struct v4l2_rect
*win
)
757 if (ccdc_if_type
== VPFE_RAW_BAYER
)
758 ccdc_hw_params_raw
.win
= *win
;
760 ccdc_hw_params_ycbcr
.win
= *win
;
764 static void ccdc_get_image_window(struct v4l2_rect
*win
)
766 if (ccdc_if_type
== VPFE_RAW_BAYER
)
767 *win
= ccdc_hw_params_raw
.win
;
769 *win
= ccdc_hw_params_ycbcr
.win
;
772 static unsigned int ccdc_get_line_length(void)
774 struct ccdc_config_params_raw
*config_params
=
775 &ccdc_hw_params_raw
.config_params
;
778 if (ccdc_if_type
== VPFE_RAW_BAYER
) {
779 if ((config_params
->alaw
.enable
) ||
780 (config_params
->data_sz
== CCDC_DATA_8BITS
))
781 len
= ccdc_hw_params_raw
.win
.width
;
783 len
= ccdc_hw_params_raw
.win
.width
* 2;
785 len
= ccdc_hw_params_ycbcr
.win
.width
* 2;
786 return ALIGN(len
, 32);
789 static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt
)
791 if (ccdc_if_type
== VPFE_RAW_BAYER
)
792 ccdc_hw_params_raw
.frm_fmt
= frm_fmt
;
794 ccdc_hw_params_ycbcr
.frm_fmt
= frm_fmt
;
798 static enum ccdc_frmfmt
ccdc_get_frame_format(void)
800 if (ccdc_if_type
== VPFE_RAW_BAYER
)
801 return ccdc_hw_params_raw
.frm_fmt
;
803 return ccdc_hw_params_ycbcr
.frm_fmt
;
806 static int ccdc_getfid(void)
808 return (regr(CCDC_SYN_MODE
) >> 15) & 1;
811 /* misc operations */
812 static inline void ccdc_setfbaddr(unsigned long addr
)
814 regw(addr
& 0xffffffe0, CCDC_SDR_ADDR
);
817 static int ccdc_set_hw_if_params(struct vpfe_hw_if_param
*params
)
819 ccdc_if_type
= params
->if_type
;
821 switch (params
->if_type
) {
823 case VPFE_YCBCR_SYNC_16
:
824 case VPFE_YCBCR_SYNC_8
:
825 ccdc_hw_params_ycbcr
.vd_pol
= params
->vdpol
;
826 ccdc_hw_params_ycbcr
.hd_pol
= params
->hdpol
;
829 /* TODO add support for raw bayer here */
835 static struct ccdc_hw_device ccdc_hw_dev
= {
836 .name
= "DM6446 CCDC",
837 .owner
= THIS_MODULE
,
841 .set_ccdc_base
= ccdc_set_ccdc_base
,
842 .reset
= ccdc_sbl_reset
,
843 .enable
= ccdc_enable
,
844 .set_hw_if_params
= ccdc_set_hw_if_params
,
845 .set_params
= ccdc_set_params
,
846 .configure
= ccdc_configure
,
847 .set_buftype
= ccdc_set_buftype
,
848 .get_buftype
= ccdc_get_buftype
,
849 .enum_pix
= ccdc_enum_pix
,
850 .set_pixel_format
= ccdc_set_pixel_format
,
851 .get_pixel_format
= ccdc_get_pixel_format
,
852 .set_frame_format
= ccdc_set_frame_format
,
853 .get_frame_format
= ccdc_get_frame_format
,
854 .set_image_window
= ccdc_set_image_window
,
855 .get_image_window
= ccdc_get_image_window
,
856 .get_line_length
= ccdc_get_line_length
,
857 .setfbaddr
= ccdc_setfbaddr
,
858 .getfid
= ccdc_getfid
,
862 static int dm644x_ccdc_init(void)
864 printk(KERN_NOTICE
"dm644x_ccdc_init\n");
865 if (vpfe_register_ccdc_device(&ccdc_hw_dev
) < 0)
867 printk(KERN_NOTICE
"%s is registered with vpfe.\n",
872 static void dm644x_ccdc_exit(void)
874 vpfe_unregister_ccdc_device(&ccdc_hw_dev
);
877 module_init(dm644x_ccdc_init
);
878 module_exit(dm644x_ccdc_exit
);