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 <linux/clk.h>
41 #include <linux/err.h>
43 #include <media/davinci/dm644x_ccdc.h>
44 #include <media/davinci/vpss.h>
46 #include "dm644x_ccdc_regs.h"
47 #include "ccdc_hw_device.h"
49 MODULE_LICENSE("GPL");
50 MODULE_DESCRIPTION("CCDC Driver for DM6446");
51 MODULE_AUTHOR("Texas Instruments");
53 static struct ccdc_oper_config
{
55 /* CCDC interface type */
56 enum vpfe_hw_if_type if_type
;
57 /* Raw Bayer configuration */
58 struct ccdc_params_raw bayer
;
59 /* YCbCr configuration */
60 struct ccdc_params_ycbcr ycbcr
;
65 /* ccdc base address */
66 void __iomem
*base_addr
;
68 /* Raw configurations */
70 .pix_fmt
= CCDC_PIXFMT_RAW
,
71 .frm_fmt
= CCDC_FRMFMT_PROGRESSIVE
,
73 .fid_pol
= VPFE_PINPOL_POSITIVE
,
74 .vd_pol
= VPFE_PINPOL_POSITIVE
,
75 .hd_pol
= VPFE_PINPOL_POSITIVE
,
77 .data_sz
= CCDC_DATA_10BITS
,
81 .pix_fmt
= CCDC_PIXFMT_YCBCR_8BIT
,
82 .frm_fmt
= CCDC_FRMFMT_INTERLACED
,
84 .fid_pol
= VPFE_PINPOL_POSITIVE
,
85 .vd_pol
= VPFE_PINPOL_POSITIVE
,
86 .hd_pol
= VPFE_PINPOL_POSITIVE
,
88 .pix_order
= CCDC_PIXORDER_CBYCRY
,
89 .buf_type
= CCDC_BUFTYPE_FLD_INTERLEAVED
93 #define CCDC_MAX_RAW_YUV_FORMATS 2
95 /* Raw Bayer formats */
96 static u32 ccdc_raw_bayer_pix_formats
[] =
97 {V4L2_PIX_FMT_SBGGR8
, V4L2_PIX_FMT_SBGGR16
};
100 static u32 ccdc_raw_yuv_pix_formats
[] =
101 {V4L2_PIX_FMT_UYVY
, V4L2_PIX_FMT_YUYV
};
103 /* register access routines */
104 static inline u32
regr(u32 offset
)
106 return __raw_readl(ccdc_cfg
.base_addr
+ offset
);
109 static inline void regw(u32 val
, u32 offset
)
111 __raw_writel(val
, ccdc_cfg
.base_addr
+ offset
);
114 static void ccdc_enable(int flag
)
116 regw(flag
, CCDC_PCR
);
119 static void ccdc_enable_vport(int flag
)
122 /* enable video port */
123 regw(CCDC_ENABLE_VIDEO_PORT
, CCDC_FMTCFG
);
125 regw(CCDC_DISABLE_VIDEO_PORT
, CCDC_FMTCFG
);
130 * This function will configure the window size
131 * to be capture in CCDC reg
133 void ccdc_setwin(struct v4l2_rect
*image_win
,
134 enum ccdc_frmfmt frm_fmt
,
137 int horz_start
, horz_nr_pixels
;
138 int vert_start
, vert_nr_lines
;
139 int val
= 0, mid_img
= 0;
141 dev_dbg(ccdc_cfg
.dev
, "\nStarting ccdc_setwin...");
143 * ppc - per pixel count. indicates how many pixels per cell
144 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
145 * raw capture this is 1
147 horz_start
= image_win
->left
<< (ppc
- 1);
148 horz_nr_pixels
= (image_win
->width
<< (ppc
- 1)) - 1;
149 regw((horz_start
<< CCDC_HORZ_INFO_SPH_SHIFT
) | horz_nr_pixels
,
152 vert_start
= image_win
->top
;
154 if (frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
155 vert_nr_lines
= (image_win
->height
>> 1) - 1;
157 /* Since first line doesn't have any data */
159 /* configure VDINT0 */
160 val
= (vert_start
<< CCDC_VDINT_VDINT0_SHIFT
);
161 regw(val
, CCDC_VDINT
);
164 /* Since first line doesn't have any data */
166 vert_nr_lines
= image_win
->height
- 1;
168 * configure VDINT0 and VDINT1. VDINT1 will be at half
171 mid_img
= vert_start
+ (image_win
->height
/ 2);
172 val
= (vert_start
<< CCDC_VDINT_VDINT0_SHIFT
) |
173 (mid_img
& CCDC_VDINT_VDINT1_MASK
);
174 regw(val
, CCDC_VDINT
);
177 regw((vert_start
<< CCDC_VERT_START_SLV0_SHIFT
) | vert_start
,
179 regw(vert_nr_lines
, CCDC_VERT_LINES
);
180 dev_dbg(ccdc_cfg
.dev
, "\nEnd of ccdc_setwin...");
183 static void ccdc_readregs(void)
185 unsigned int val
= 0;
187 val
= regr(CCDC_ALAW
);
188 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to ALAW...\n", val
);
189 val
= regr(CCDC_CLAMP
);
190 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to CLAMP...\n", val
);
191 val
= regr(CCDC_DCSUB
);
192 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to DCSUB...\n", val
);
193 val
= regr(CCDC_BLKCMP
);
194 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to BLKCMP...\n", val
);
195 val
= regr(CCDC_FPC_ADDR
);
196 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to FPC_ADDR...\n", val
);
197 val
= regr(CCDC_FPC
);
198 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to FPC...\n", val
);
199 val
= regr(CCDC_FMTCFG
);
200 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to FMTCFG...\n", val
);
201 val
= regr(CCDC_COLPTN
);
202 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to COLPTN...\n", val
);
203 val
= regr(CCDC_FMT_HORZ
);
204 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to FMT_HORZ...\n", val
);
205 val
= regr(CCDC_FMT_VERT
);
206 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to FMT_VERT...\n", val
);
207 val
= regr(CCDC_HSIZE_OFF
);
208 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to HSIZE_OFF...\n", val
);
209 val
= regr(CCDC_SDOFST
);
210 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to SDOFST...\n", val
);
211 val
= regr(CCDC_VP_OUT
);
212 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to VP_OUT...\n", val
);
213 val
= regr(CCDC_SYN_MODE
);
214 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to SYN_MODE...\n", val
);
215 val
= regr(CCDC_HORZ_INFO
);
216 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to HORZ_INFO...\n", val
);
217 val
= regr(CCDC_VERT_START
);
218 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to VERT_START...\n", val
);
219 val
= regr(CCDC_VERT_LINES
);
220 dev_notice(ccdc_cfg
.dev
, "\nReading 0x%x to VERT_LINES...\n", val
);
223 static int validate_ccdc_param(struct ccdc_config_params_raw
*ccdcparam
)
225 if (ccdcparam
->alaw
.enable
) {
226 if ((ccdcparam
->alaw
.gama_wd
> CCDC_GAMMA_BITS_09_0
) ||
227 (ccdcparam
->alaw
.gama_wd
< CCDC_GAMMA_BITS_15_6
) ||
228 (ccdcparam
->alaw
.gama_wd
< ccdcparam
->data_sz
)) {
229 dev_dbg(ccdc_cfg
.dev
, "\nInvalid data line select");
236 static int ccdc_update_raw_params(struct ccdc_config_params_raw
*raw_params
)
238 struct ccdc_config_params_raw
*config_params
=
239 &ccdc_cfg
.bayer
.config_params
;
240 unsigned int *fpc_virtaddr
= NULL
;
241 unsigned int *fpc_physaddr
= NULL
;
243 memcpy(config_params
, raw_params
, sizeof(*raw_params
));
245 * allocate memory for fault pixel table and copy the user
246 * values to the table
248 if (!config_params
->fault_pxl
.enable
)
251 fpc_physaddr
= (unsigned int *)config_params
->fault_pxl
.fpc_table_addr
;
252 fpc_virtaddr
= (unsigned int *)phys_to_virt(
253 (unsigned long)fpc_physaddr
);
255 * Allocate memory for FPC table if current
256 * FPC table buffer is not big enough to
257 * accomodate FPC Number requested
259 if (raw_params
->fault_pxl
.fp_num
!= config_params
->fault_pxl
.fp_num
) {
260 if (fpc_physaddr
!= NULL
) {
261 free_pages((unsigned long)fpc_physaddr
,
263 (config_params
->fault_pxl
.fp_num
*
267 /* Allocate memory for FPC table */
269 (unsigned int *)__get_free_pages(GFP_KERNEL
| GFP_DMA
,
270 get_order(raw_params
->
274 if (fpc_virtaddr
== NULL
) {
275 dev_dbg(ccdc_cfg
.dev
,
276 "\nUnable to allocate memory for FPC");
280 (unsigned int *)virt_to_phys((void *)fpc_virtaddr
);
283 /* Copy number of fault pixels and FPC table */
284 config_params
->fault_pxl
.fp_num
= raw_params
->fault_pxl
.fp_num
;
285 if (copy_from_user(fpc_virtaddr
,
286 (void __user
*)raw_params
->fault_pxl
.fpc_table_addr
,
287 config_params
->fault_pxl
.fp_num
* FP_NUM_BYTES
)) {
288 dev_dbg(ccdc_cfg
.dev
, "\n copy_from_user failed");
291 config_params
->fault_pxl
.fpc_table_addr
= (unsigned int)fpc_physaddr
;
295 static int ccdc_close(struct device
*dev
)
297 struct ccdc_config_params_raw
*config_params
=
298 &ccdc_cfg
.bayer
.config_params
;
299 unsigned int *fpc_physaddr
= NULL
, *fpc_virtaddr
= NULL
;
301 fpc_physaddr
= (unsigned int *)config_params
->fault_pxl
.fpc_table_addr
;
303 if (fpc_physaddr
!= NULL
) {
304 fpc_virtaddr
= (unsigned int *)
305 phys_to_virt((unsigned long)fpc_physaddr
);
306 free_pages((unsigned long)fpc_virtaddr
,
307 get_order(config_params
->fault_pxl
.fp_num
*
314 * ccdc_restore_defaults()
315 * This function will write defaults to all CCDC registers
317 static void ccdc_restore_defaults(void)
323 /* set all registers to default value */
324 for (i
= 4; i
<= 0x94; i
+= 4)
326 regw(CCDC_NO_CULLING
, CCDC_CULLING
);
327 regw(CCDC_GAMMA_BITS_11_2
, CCDC_ALAW
);
330 static int ccdc_open(struct device
*device
)
332 ccdc_restore_defaults();
333 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
334 ccdc_enable_vport(1);
338 static void ccdc_sbl_reset(void)
340 vpss_clear_wbl_overflow(VPSS_PCR_CCDC_WBL_O
);
343 /* Parameter operations */
344 static int ccdc_set_params(void __user
*params
)
346 struct ccdc_config_params_raw ccdc_raw_params
;
349 if (ccdc_cfg
.if_type
!= VPFE_RAW_BAYER
)
352 x
= copy_from_user(&ccdc_raw_params
, params
, sizeof(ccdc_raw_params
));
354 dev_dbg(ccdc_cfg
.dev
, "ccdc_set_params: error in copying"
355 "ccdc params, %d\n", x
);
359 if (!validate_ccdc_param(&ccdc_raw_params
)) {
360 if (!ccdc_update_raw_params(&ccdc_raw_params
))
367 * ccdc_config_ycbcr()
368 * This function will configure CCDC for YCbCr video capture
370 void ccdc_config_ycbcr(void)
372 struct ccdc_params_ycbcr
*params
= &ccdc_cfg
.ycbcr
;
375 dev_dbg(ccdc_cfg
.dev
, "\nStarting ccdc_config_ycbcr...");
377 * first restore the CCDC registers to default values
378 * This is important since we assume default values to be set in
379 * a lot of registers that we didn't touch
381 ccdc_restore_defaults();
384 * configure pixel format, frame format, configure video frame
385 * format, enable output to SDRAM, enable internal timing generator
388 syn_mode
= (((params
->pix_fmt
& CCDC_SYN_MODE_INPMOD_MASK
) <<
389 CCDC_SYN_MODE_INPMOD_SHIFT
) |
390 ((params
->frm_fmt
& CCDC_SYN_FLDMODE_MASK
) <<
391 CCDC_SYN_FLDMODE_SHIFT
) | CCDC_VDHDEN_ENABLE
|
392 CCDC_WEN_ENABLE
| CCDC_DATA_PACK_ENABLE
);
394 /* setup BT.656 sync mode */
395 if (params
->bt656_enable
) {
396 regw(CCDC_REC656IF_BT656_EN
, CCDC_REC656IF
);
399 * configure the FID, VD, HD pin polarity,
400 * fld,hd pol positive, vd negative, 8-bit data
402 syn_mode
|= CCDC_SYN_MODE_VD_POL_NEGATIVE
| CCDC_SYN_MODE_8BITS
;
404 /* y/c external sync mode */
405 syn_mode
|= (((params
->fid_pol
& CCDC_FID_POL_MASK
) <<
406 CCDC_FID_POL_SHIFT
) |
407 ((params
->hd_pol
& CCDC_HD_POL_MASK
) <<
409 ((params
->vd_pol
& CCDC_VD_POL_MASK
) <<
412 regw(syn_mode
, CCDC_SYN_MODE
);
414 /* configure video window */
415 ccdc_setwin(¶ms
->win
, params
->frm_fmt
, 2);
418 * configure the order of y cb cr in SDRAM, and disable latch
419 * internal register on vsync
421 regw((params
->pix_order
<< CCDC_CCDCFG_Y8POS_SHIFT
) |
422 CCDC_LATCH_ON_VSYNC_DISABLE
, CCDC_CCDCFG
);
425 * configure the horizontal line offset. This should be a
426 * on 32 byte bondary. So clear LSB 5 bits
428 regw(((params
->win
.width
* 2 + 31) & ~0x1f), CCDC_HSIZE_OFF
);
430 /* configure the memory line offset */
431 if (params
->buf_type
== CCDC_BUFTYPE_FLD_INTERLEAVED
)
432 /* two fields are interleaved in memory */
433 regw(CCDC_SDOFST_FIELD_INTERLEAVED
, CCDC_SDOFST
);
436 dev_dbg(ccdc_cfg
.dev
, "\nEnd of ccdc_config_ycbcr...\n");
440 static void ccdc_config_black_clamp(struct ccdc_black_clamp
*bclamp
)
444 if (!bclamp
->enable
) {
445 /* configure DCSub */
446 val
= (bclamp
->dc_sub
) & CCDC_BLK_DC_SUB_MASK
;
447 regw(val
, CCDC_DCSUB
);
448 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to DCSUB...\n", val
);
449 regw(CCDC_CLAMP_DEFAULT_VAL
, CCDC_CLAMP
);
450 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x0000 to CLAMP...\n");
454 * Configure gain, Start pixel, No of line to be avg,
455 * No of pixel/line to be avg, & Enable the Black clamping
457 val
= ((bclamp
->sgain
& CCDC_BLK_SGAIN_MASK
) |
458 ((bclamp
->start_pixel
& CCDC_BLK_ST_PXL_MASK
) <<
459 CCDC_BLK_ST_PXL_SHIFT
) |
460 ((bclamp
->sample_ln
& CCDC_BLK_SAMPLE_LINE_MASK
) <<
461 CCDC_BLK_SAMPLE_LINE_SHIFT
) |
462 ((bclamp
->sample_pixel
& CCDC_BLK_SAMPLE_LN_MASK
) <<
463 CCDC_BLK_SAMPLE_LN_SHIFT
) | CCDC_BLK_CLAMP_ENABLE
);
464 regw(val
, CCDC_CLAMP
);
465 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to CLAMP...\n", val
);
466 /* If Black clamping is enable then make dcsub 0 */
467 regw(CCDC_DCSUB_DEFAULT_VAL
, CCDC_DCSUB
);
468 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x00000000 to DCSUB...\n");
471 static void ccdc_config_black_compense(struct ccdc_black_compensation
*bcomp
)
475 val
= ((bcomp
->b
& CCDC_BLK_COMP_MASK
) |
476 ((bcomp
->gb
& CCDC_BLK_COMP_MASK
) <<
477 CCDC_BLK_COMP_GB_COMP_SHIFT
) |
478 ((bcomp
->gr
& CCDC_BLK_COMP_MASK
) <<
479 CCDC_BLK_COMP_GR_COMP_SHIFT
) |
480 ((bcomp
->r
& CCDC_BLK_COMP_MASK
) <<
481 CCDC_BLK_COMP_R_COMP_SHIFT
));
482 regw(val
, CCDC_BLKCMP
);
485 static void ccdc_config_fpc(struct ccdc_fault_pixel
*fpc
)
489 /* Initially disable FPC */
490 val
= CCDC_FPC_DISABLE
;
496 /* Configure Fault pixel if needed */
497 regw(fpc
->fpc_table_addr
, CCDC_FPC_ADDR
);
498 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to FPC_ADDR...\n",
499 (fpc
->fpc_table_addr
));
500 /* Write the FPC params with FPC disable */
501 val
= fpc
->fp_num
& CCDC_FPC_FPC_NUM_MASK
;
504 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to FPC...\n", val
);
505 /* read the FPC register */
506 val
= regr(CCDC_FPC
) | CCDC_FPC_ENABLE
;
508 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to FPC...\n", val
);
513 * This function will configure CCDC for Raw capture mode
515 void ccdc_config_raw(void)
517 struct ccdc_params_raw
*params
= &ccdc_cfg
.bayer
;
518 struct ccdc_config_params_raw
*config_params
=
519 &ccdc_cfg
.bayer
.config_params
;
520 unsigned int syn_mode
= 0;
523 dev_dbg(ccdc_cfg
.dev
, "\nStarting ccdc_config_raw...");
526 ccdc_restore_defaults();
528 /* Disable latching function registers on VSYNC */
529 regw(CCDC_LATCH_ON_VSYNC_DISABLE
, CCDC_CCDCFG
);
532 * Configure the vertical sync polarity(SYN_MODE.VDPOL),
533 * horizontal sync polarity (SYN_MODE.HDPOL), frame id polarity
534 * (SYN_MODE.FLDPOL), frame format(progressive or interlace),
535 * data size(SYNMODE.DATSIZ), &pixel format (Input mode), output
536 * SDRAM, enable internal timing generator
539 (((params
->vd_pol
& CCDC_VD_POL_MASK
) << CCDC_VD_POL_SHIFT
) |
540 ((params
->hd_pol
& CCDC_HD_POL_MASK
) << CCDC_HD_POL_SHIFT
) |
541 ((params
->fid_pol
& CCDC_FID_POL_MASK
) << CCDC_FID_POL_SHIFT
) |
542 ((params
->frm_fmt
& CCDC_FRM_FMT_MASK
) << CCDC_FRM_FMT_SHIFT
) |
543 ((config_params
->data_sz
& CCDC_DATA_SZ_MASK
) <<
544 CCDC_DATA_SZ_SHIFT
) |
545 ((params
->pix_fmt
& CCDC_PIX_FMT_MASK
) << CCDC_PIX_FMT_SHIFT
) |
546 CCDC_WEN_ENABLE
| CCDC_VDHDEN_ENABLE
);
548 /* Enable and configure aLaw register if needed */
549 if (config_params
->alaw
.enable
) {
550 val
= ((config_params
->alaw
.gama_wd
&
551 CCDC_ALAW_GAMA_WD_MASK
) | CCDC_ALAW_ENABLE
);
552 regw(val
, CCDC_ALAW
);
553 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to ALAW...\n", val
);
556 /* Configure video window */
557 ccdc_setwin(¶ms
->win
, params
->frm_fmt
, CCDC_PPC_RAW
);
559 /* Configure Black Clamp */
560 ccdc_config_black_clamp(&config_params
->blk_clamp
);
562 /* Configure Black level compensation */
563 ccdc_config_black_compense(&config_params
->blk_comp
);
565 /* Configure Fault Pixel Correction */
566 ccdc_config_fpc(&config_params
->fault_pxl
);
568 /* If data size is 8 bit then pack the data */
569 if ((config_params
->data_sz
== CCDC_DATA_8BITS
) ||
570 config_params
->alaw
.enable
)
571 syn_mode
|= CCDC_DATA_PACK_ENABLE
;
573 #ifdef CONFIG_DM644X_VIDEO_PORT_ENABLE
574 /* enable video port */
575 val
= CCDC_ENABLE_VIDEO_PORT
;
577 /* disable video port */
578 val
= CCDC_DISABLE_VIDEO_PORT
;
581 if (config_params
->data_sz
== CCDC_DATA_8BITS
)
582 val
|= (CCDC_DATA_10BITS
& CCDC_FMTCFG_VPIN_MASK
)
583 << CCDC_FMTCFG_VPIN_SHIFT
;
585 val
|= (config_params
->data_sz
& CCDC_FMTCFG_VPIN_MASK
)
586 << CCDC_FMTCFG_VPIN_SHIFT
;
587 /* Write value in FMTCFG */
588 regw(val
, CCDC_FMTCFG
);
590 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to FMTCFG...\n", val
);
591 /* Configure the color pattern according to mt9t001 sensor */
592 regw(CCDC_COLPTN_VAL
, CCDC_COLPTN
);
594 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0xBB11BB11 to COLPTN...\n");
596 * Configure Data formatter(Video port) pixel selection
597 * (FMT_HORZ, FMT_VERT)
599 val
= ((params
->win
.left
& CCDC_FMT_HORZ_FMTSPH_MASK
) <<
600 CCDC_FMT_HORZ_FMTSPH_SHIFT
) |
601 (params
->win
.width
& CCDC_FMT_HORZ_FMTLNH_MASK
);
602 regw(val
, CCDC_FMT_HORZ
);
604 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to FMT_HORZ...\n", val
);
605 val
= (params
->win
.top
& CCDC_FMT_VERT_FMTSLV_MASK
)
606 << CCDC_FMT_VERT_FMTSLV_SHIFT
;
607 if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
)
608 val
|= (params
->win
.height
) & CCDC_FMT_VERT_FMTLNV_MASK
;
610 val
|= (params
->win
.height
>> 1) & CCDC_FMT_VERT_FMTLNV_MASK
;
612 dev_dbg(ccdc_cfg
.dev
, "\nparams->win.height 0x%x ...\n",
614 regw(val
, CCDC_FMT_VERT
);
616 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to FMT_VERT...\n", val
);
618 dev_dbg(ccdc_cfg
.dev
, "\nbelow regw(val, FMT_VERT)...");
621 * Configure Horizontal offset register. If pack 8 is enabled then
622 * 1 pixel will take 1 byte
624 if ((config_params
->data_sz
== CCDC_DATA_8BITS
) ||
625 config_params
->alaw
.enable
)
626 regw((params
->win
.width
+ CCDC_32BYTE_ALIGN_VAL
) &
627 CCDC_HSIZE_OFF_MASK
, CCDC_HSIZE_OFF
);
629 /* else one pixel will take 2 byte */
630 regw(((params
->win
.width
* CCDC_TWO_BYTES_PER_PIXEL
) +
631 CCDC_32BYTE_ALIGN_VAL
) & CCDC_HSIZE_OFF_MASK
,
634 /* Set value for SDOFST */
635 if (params
->frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
636 if (params
->image_invert_enable
) {
637 /* For intelace inverse mode */
638 regw(CCDC_INTERLACED_IMAGE_INVERT
, CCDC_SDOFST
);
639 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x4B6D to SDOFST..\n");
643 /* For intelace non inverse mode */
644 regw(CCDC_INTERLACED_NO_IMAGE_INVERT
, CCDC_SDOFST
);
645 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x0249 to SDOFST..\n");
647 } else if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
) {
648 regw(CCDC_PROGRESSIVE_NO_IMAGE_INVERT
, CCDC_SDOFST
);
649 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x0000 to SDOFST...\n");
653 * Configure video port pixel selection (VPOUT)
654 * Here -1 is to make the height value less than FMT_VERT.FMTLNV
656 if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
)
657 val
= (((params
->win
.height
- 1) & CCDC_VP_OUT_VERT_NUM_MASK
))
658 << CCDC_VP_OUT_VERT_NUM_SHIFT
;
661 ((((params
->win
.height
>> CCDC_INTERLACED_HEIGHT_SHIFT
) -
662 1) & CCDC_VP_OUT_VERT_NUM_MASK
)) <<
663 CCDC_VP_OUT_VERT_NUM_SHIFT
;
665 val
|= ((((params
->win
.width
))) & CCDC_VP_OUT_HORZ_NUM_MASK
)
666 << CCDC_VP_OUT_HORZ_NUM_SHIFT
;
667 val
|= (params
->win
.left
) & CCDC_VP_OUT_HORZ_ST_MASK
;
668 regw(val
, CCDC_VP_OUT
);
670 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to VP_OUT...\n", val
);
671 regw(syn_mode
, CCDC_SYN_MODE
);
672 dev_dbg(ccdc_cfg
.dev
, "\nWriting 0x%x to SYN_MODE...\n", syn_mode
);
675 dev_dbg(ccdc_cfg
.dev
, "\nend of ccdc_config_raw...");
679 static int ccdc_configure(void)
681 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
688 static int ccdc_set_buftype(enum ccdc_buftype buf_type
)
690 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
691 ccdc_cfg
.bayer
.buf_type
= buf_type
;
693 ccdc_cfg
.ycbcr
.buf_type
= buf_type
;
697 static enum ccdc_buftype
ccdc_get_buftype(void)
699 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
700 return ccdc_cfg
.bayer
.buf_type
;
701 return ccdc_cfg
.ycbcr
.buf_type
;
704 static int ccdc_enum_pix(u32
*pix
, int i
)
707 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
) {
708 if (i
< ARRAY_SIZE(ccdc_raw_bayer_pix_formats
)) {
709 *pix
= ccdc_raw_bayer_pix_formats
[i
];
713 if (i
< ARRAY_SIZE(ccdc_raw_yuv_pix_formats
)) {
714 *pix
= ccdc_raw_yuv_pix_formats
[i
];
721 static int ccdc_set_pixel_format(u32 pixfmt
)
723 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
) {
724 ccdc_cfg
.bayer
.pix_fmt
= CCDC_PIXFMT_RAW
;
725 if (pixfmt
== V4L2_PIX_FMT_SBGGR8
)
726 ccdc_cfg
.bayer
.config_params
.alaw
.enable
= 1;
727 else if (pixfmt
!= V4L2_PIX_FMT_SBGGR16
)
730 if (pixfmt
== V4L2_PIX_FMT_YUYV
)
731 ccdc_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_YCBYCR
;
732 else if (pixfmt
== V4L2_PIX_FMT_UYVY
)
733 ccdc_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
740 static u32
ccdc_get_pixel_format(void)
742 struct ccdc_a_law
*alaw
= &ccdc_cfg
.bayer
.config_params
.alaw
;
745 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
747 pixfmt
= V4L2_PIX_FMT_SBGGR8
;
749 pixfmt
= V4L2_PIX_FMT_SBGGR16
;
751 if (ccdc_cfg
.ycbcr
.pix_order
== CCDC_PIXORDER_YCBYCR
)
752 pixfmt
= V4L2_PIX_FMT_YUYV
;
754 pixfmt
= V4L2_PIX_FMT_UYVY
;
759 static int ccdc_set_image_window(struct v4l2_rect
*win
)
761 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
762 ccdc_cfg
.bayer
.win
= *win
;
764 ccdc_cfg
.ycbcr
.win
= *win
;
768 static void ccdc_get_image_window(struct v4l2_rect
*win
)
770 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
771 *win
= ccdc_cfg
.bayer
.win
;
773 *win
= ccdc_cfg
.ycbcr
.win
;
776 static unsigned int ccdc_get_line_length(void)
778 struct ccdc_config_params_raw
*config_params
=
779 &ccdc_cfg
.bayer
.config_params
;
782 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
) {
783 if ((config_params
->alaw
.enable
) ||
784 (config_params
->data_sz
== CCDC_DATA_8BITS
))
785 len
= ccdc_cfg
.bayer
.win
.width
;
787 len
= ccdc_cfg
.bayer
.win
.width
* 2;
789 len
= ccdc_cfg
.ycbcr
.win
.width
* 2;
790 return ALIGN(len
, 32);
793 static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt
)
795 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
796 ccdc_cfg
.bayer
.frm_fmt
= frm_fmt
;
798 ccdc_cfg
.ycbcr
.frm_fmt
= frm_fmt
;
802 static enum ccdc_frmfmt
ccdc_get_frame_format(void)
804 if (ccdc_cfg
.if_type
== VPFE_RAW_BAYER
)
805 return ccdc_cfg
.bayer
.frm_fmt
;
807 return ccdc_cfg
.ycbcr
.frm_fmt
;
810 static int ccdc_getfid(void)
812 return (regr(CCDC_SYN_MODE
) >> 15) & 1;
815 /* misc operations */
816 static inline void ccdc_setfbaddr(unsigned long addr
)
818 regw(addr
& 0xffffffe0, CCDC_SDR_ADDR
);
821 static int ccdc_set_hw_if_params(struct vpfe_hw_if_param
*params
)
823 ccdc_cfg
.if_type
= params
->if_type
;
825 switch (params
->if_type
) {
827 case VPFE_YCBCR_SYNC_16
:
828 case VPFE_YCBCR_SYNC_8
:
829 ccdc_cfg
.ycbcr
.vd_pol
= params
->vdpol
;
830 ccdc_cfg
.ycbcr
.hd_pol
= params
->hdpol
;
833 /* TODO add support for raw bayer here */
839 static struct ccdc_hw_device ccdc_hw_dev
= {
840 .name
= "DM6446 CCDC",
841 .owner
= THIS_MODULE
,
845 .reset
= ccdc_sbl_reset
,
846 .enable
= ccdc_enable
,
847 .set_hw_if_params
= ccdc_set_hw_if_params
,
848 .set_params
= ccdc_set_params
,
849 .configure
= ccdc_configure
,
850 .set_buftype
= ccdc_set_buftype
,
851 .get_buftype
= ccdc_get_buftype
,
852 .enum_pix
= ccdc_enum_pix
,
853 .set_pixel_format
= ccdc_set_pixel_format
,
854 .get_pixel_format
= ccdc_get_pixel_format
,
855 .set_frame_format
= ccdc_set_frame_format
,
856 .get_frame_format
= ccdc_get_frame_format
,
857 .set_image_window
= ccdc_set_image_window
,
858 .get_image_window
= ccdc_get_image_window
,
859 .get_line_length
= ccdc_get_line_length
,
860 .setfbaddr
= ccdc_setfbaddr
,
861 .getfid
= ccdc_getfid
,
865 static int __init
dm644x_ccdc_probe(struct platform_device
*pdev
)
867 struct resource
*res
;
871 * first try to register with vpfe. If not correct platform, then we
872 * don't have to iomap
874 status
= vpfe_register_ccdc_device(&ccdc_hw_dev
);
878 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
884 res
= request_mem_region(res
->start
, resource_size(res
), res
->name
);
890 ccdc_cfg
.base_addr
= ioremap_nocache(res
->start
, resource_size(res
));
891 if (!ccdc_cfg
.base_addr
) {
896 /* Get and enable Master clock */
897 ccdc_cfg
.mclk
= clk_get(&pdev
->dev
, "master");
898 if (IS_ERR(ccdc_cfg
.mclk
)) {
899 status
= PTR_ERR(ccdc_cfg
.mclk
);
902 if (clk_enable(ccdc_cfg
.mclk
)) {
907 /* Get and enable Slave clock */
908 ccdc_cfg
.sclk
= clk_get(&pdev
->dev
, "slave");
909 if (IS_ERR(ccdc_cfg
.sclk
)) {
910 status
= PTR_ERR(ccdc_cfg
.sclk
);
913 if (clk_enable(ccdc_cfg
.sclk
)) {
917 ccdc_cfg
.dev
= &pdev
->dev
;
918 printk(KERN_NOTICE
"%s is registered with vpfe.\n", ccdc_hw_dev
.name
);
921 clk_put(ccdc_cfg
.sclk
);
923 clk_put(ccdc_cfg
.mclk
);
925 iounmap(ccdc_cfg
.base_addr
);
927 release_mem_region(res
->start
, resource_size(res
));
929 vpfe_unregister_ccdc_device(&ccdc_hw_dev
);
933 static int dm644x_ccdc_remove(struct platform_device
*pdev
)
935 struct resource
*res
;
937 clk_put(ccdc_cfg
.mclk
);
938 clk_put(ccdc_cfg
.sclk
);
939 iounmap(ccdc_cfg
.base_addr
);
940 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
942 release_mem_region(res
->start
, resource_size(res
));
943 vpfe_unregister_ccdc_device(&ccdc_hw_dev
);
947 static struct platform_driver dm644x_ccdc_driver
= {
949 .name
= "dm644x_ccdc",
950 .owner
= THIS_MODULE
,
952 .remove
= __devexit_p(dm644x_ccdc_remove
),
953 .probe
= dm644x_ccdc_probe
,
956 static int __init
dm644x_ccdc_init(void)
958 return platform_driver_register(&dm644x_ccdc_driver
);
961 static void __exit
dm644x_ccdc_exit(void)
963 platform_driver_unregister(&dm644x_ccdc_driver
);
966 module_init(dm644x_ccdc_init
);
967 module_exit(dm644x_ccdc_exit
);