]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/media/platform/davinci/dm644x_ccdc.c
drm/nouveau/disp/nv04: avoid creation of output paths
[karo-tx-linux.git] / drivers / media / platform / davinci / dm644x_ccdc.c
1 /*
2  * Copyright (C) 2006-2009 Texas Instruments Inc
3  *
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.
8  *
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.
13  *
14  * CCDC hardware module for DM6446
15  * ------------------------------
16  *
17  * This module is for configuring CCD controller of DM6446 VPFE to capture
18  * Raw yuv or Bayer RGB data from a decoder. CCDC has several modules
19  * such as Defect Pixel Correction, Color Space Conversion etc to
20  * pre-process the Raw Bayer RGB data, before writing it to SDRAM. This
21  * module also allows application to configure individual
22  * module parameters through VPFE_CMD_S_CCDC_RAW_PARAMS IOCTL.
23  * To do so, application includes dm644x_ccdc.h and vpfe_capture.h header
24  * files.  The setparams() API is called by vpfe_capture driver
25  * to configure module parameters. This file is named DM644x so that other
26  * variants such DM6443 may be supported using the same module.
27  *
28  * TODO: Test Raw bayer parameter settings and bayer capture
29  *       Split module parameter structure to module specific ioctl structs
30  *       investigate if enum used for user space type definition
31  *       to be replaced by #defines or integer
32  */
33 #include <linux/platform_device.h>
34 #include <linux/uaccess.h>
35 #include <linux/videodev2.h>
36 #include <linux/gfp.h>
37 #include <linux/err.h>
38 #include <linux/module.h>
39
40 #include <media/davinci/dm644x_ccdc.h>
41 #include <media/davinci/vpss.h>
42
43 #include "dm644x_ccdc_regs.h"
44 #include "ccdc_hw_device.h"
45
46 MODULE_LICENSE("GPL");
47 MODULE_DESCRIPTION("CCDC Driver for DM6446");
48 MODULE_AUTHOR("Texas Instruments");
49
50 static struct ccdc_oper_config {
51         struct device *dev;
52         /* CCDC interface type */
53         enum vpfe_hw_if_type if_type;
54         /* Raw Bayer configuration */
55         struct ccdc_params_raw bayer;
56         /* YCbCr configuration */
57         struct ccdc_params_ycbcr ycbcr;
58         /* ccdc base address */
59         void __iomem *base_addr;
60 } ccdc_cfg = {
61         /* Raw configurations */
62         .bayer = {
63                 .pix_fmt = CCDC_PIXFMT_RAW,
64                 .frm_fmt = CCDC_FRMFMT_PROGRESSIVE,
65                 .win = CCDC_WIN_VGA,
66                 .fid_pol = VPFE_PINPOL_POSITIVE,
67                 .vd_pol = VPFE_PINPOL_POSITIVE,
68                 .hd_pol = VPFE_PINPOL_POSITIVE,
69                 .config_params = {
70                         .data_sz = CCDC_DATA_10BITS,
71                 },
72         },
73         .ycbcr = {
74                 .pix_fmt = CCDC_PIXFMT_YCBCR_8BIT,
75                 .frm_fmt = CCDC_FRMFMT_INTERLACED,
76                 .win = CCDC_WIN_PAL,
77                 .fid_pol = VPFE_PINPOL_POSITIVE,
78                 .vd_pol = VPFE_PINPOL_POSITIVE,
79                 .hd_pol = VPFE_PINPOL_POSITIVE,
80                 .bt656_enable = 1,
81                 .pix_order = CCDC_PIXORDER_CBYCRY,
82                 .buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED
83         },
84 };
85
86 #define CCDC_MAX_RAW_YUV_FORMATS        2
87
88 /* Raw Bayer formats */
89 static u32 ccdc_raw_bayer_pix_formats[] =
90         {V4L2_PIX_FMT_SBGGR8, V4L2_PIX_FMT_SBGGR16};
91
92 /* Raw YUV formats */
93 static u32 ccdc_raw_yuv_pix_formats[] =
94         {V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_YUYV};
95
96 /* CCDC Save/Restore context */
97 static u32 ccdc_ctx[CCDC_REG_END / sizeof(u32)];
98
99 /* register access routines */
100 static inline u32 regr(u32 offset)
101 {
102         return __raw_readl(ccdc_cfg.base_addr + offset);
103 }
104
105 static inline void regw(u32 val, u32 offset)
106 {
107         __raw_writel(val, ccdc_cfg.base_addr + offset);
108 }
109
110 static void ccdc_enable(int flag)
111 {
112         regw(flag, CCDC_PCR);
113 }
114
115 static void ccdc_enable_vport(int flag)
116 {
117         if (flag)
118                 /* enable video port */
119                 regw(CCDC_ENABLE_VIDEO_PORT, CCDC_FMTCFG);
120         else
121                 regw(CCDC_DISABLE_VIDEO_PORT, CCDC_FMTCFG);
122 }
123
124 /*
125  * ccdc_setwin()
126  * This function will configure the window size
127  * to be capture in CCDC reg
128  */
129 static void ccdc_setwin(struct v4l2_rect *image_win,
130                         enum ccdc_frmfmt frm_fmt,
131                         int ppc)
132 {
133         int horz_start, horz_nr_pixels;
134         int vert_start, vert_nr_lines;
135         int val = 0, mid_img = 0;
136
137         dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_setwin...");
138         /*
139          * ppc - per pixel count. indicates how many pixels per cell
140          * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
141          * raw capture this is 1
142          */
143         horz_start = image_win->left << (ppc - 1);
144         horz_nr_pixels = (image_win->width << (ppc - 1)) - 1;
145         regw((horz_start << CCDC_HORZ_INFO_SPH_SHIFT) | horz_nr_pixels,
146              CCDC_HORZ_INFO);
147
148         vert_start = image_win->top;
149
150         if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
151                 vert_nr_lines = (image_win->height >> 1) - 1;
152                 vert_start >>= 1;
153                 /* Since first line doesn't have any data */
154                 vert_start += 1;
155                 /* configure VDINT0 */
156                 val = (vert_start << CCDC_VDINT_VDINT0_SHIFT);
157                 regw(val, CCDC_VDINT);
158
159         } else {
160                 /* Since first line doesn't have any data */
161                 vert_start += 1;
162                 vert_nr_lines = image_win->height - 1;
163                 /*
164                  * configure VDINT0 and VDINT1. VDINT1 will be at half
165                  * of image height
166                  */
167                 mid_img = vert_start + (image_win->height / 2);
168                 val = (vert_start << CCDC_VDINT_VDINT0_SHIFT) |
169                     (mid_img & CCDC_VDINT_VDINT1_MASK);
170                 regw(val, CCDC_VDINT);
171
172         }
173         regw((vert_start << CCDC_VERT_START_SLV0_SHIFT) | vert_start,
174              CCDC_VERT_START);
175         regw(vert_nr_lines, CCDC_VERT_LINES);
176         dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_setwin...");
177 }
178
179 static void ccdc_readregs(void)
180 {
181         unsigned int val = 0;
182
183         val = regr(CCDC_ALAW);
184         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to ALAW...\n", val);
185         val = regr(CCDC_CLAMP);
186         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to CLAMP...\n", val);
187         val = regr(CCDC_DCSUB);
188         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to DCSUB...\n", val);
189         val = regr(CCDC_BLKCMP);
190         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to BLKCMP...\n", val);
191         val = regr(CCDC_FPC_ADDR);
192         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FPC_ADDR...\n", val);
193         val = regr(CCDC_FPC);
194         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FPC...\n", val);
195         val = regr(CCDC_FMTCFG);
196         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMTCFG...\n", val);
197         val = regr(CCDC_COLPTN);
198         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to COLPTN...\n", val);
199         val = regr(CCDC_FMT_HORZ);
200         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMT_HORZ...\n", val);
201         val = regr(CCDC_FMT_VERT);
202         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to FMT_VERT...\n", val);
203         val = regr(CCDC_HSIZE_OFF);
204         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to HSIZE_OFF...\n", val);
205         val = regr(CCDC_SDOFST);
206         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to SDOFST...\n", val);
207         val = regr(CCDC_VP_OUT);
208         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VP_OUT...\n", val);
209         val = regr(CCDC_SYN_MODE);
210         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to SYN_MODE...\n", val);
211         val = regr(CCDC_HORZ_INFO);
212         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to HORZ_INFO...\n", val);
213         val = regr(CCDC_VERT_START);
214         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VERT_START...\n", val);
215         val = regr(CCDC_VERT_LINES);
216         dev_notice(ccdc_cfg.dev, "\nReading 0x%x to VERT_LINES...\n", val);
217 }
218
219 static int validate_ccdc_param(struct ccdc_config_params_raw *ccdcparam)
220 {
221         if (ccdcparam->alaw.enable) {
222                 u8 max_gamma = ccdc_gamma_width_max_bit(ccdcparam->alaw.gamma_wd);
223                 u8 max_data = ccdc_data_size_max_bit(ccdcparam->data_sz);
224
225                 if ((ccdcparam->alaw.gamma_wd > CCDC_GAMMA_BITS_09_0) ||
226                     (ccdcparam->alaw.gamma_wd < CCDC_GAMMA_BITS_15_6) ||
227                     (max_gamma > max_data)) {
228                         dev_dbg(ccdc_cfg.dev, "\nInvalid data line select");
229                         return -1;
230                 }
231         }
232         return 0;
233 }
234
235 static int ccdc_update_raw_params(struct ccdc_config_params_raw *raw_params)
236 {
237         struct ccdc_config_params_raw *config_params =
238                                 &ccdc_cfg.bayer.config_params;
239         unsigned int *fpc_virtaddr = NULL;
240         unsigned int *fpc_physaddr = NULL;
241
242         memcpy(config_params, raw_params, sizeof(*raw_params));
243         /*
244          * allocate memory for fault pixel table and copy the user
245          * values to the table
246          */
247         if (!config_params->fault_pxl.enable)
248                 return 0;
249
250         fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr;
251         fpc_virtaddr = (unsigned int *)phys_to_virt(
252                                 (unsigned long)fpc_physaddr);
253         /*
254          * Allocate memory for FPC table if current
255          * FPC table buffer is not big enough to
256          * accommodate FPC Number requested
257          */
258         if (raw_params->fault_pxl.fp_num != config_params->fault_pxl.fp_num) {
259                 if (fpc_physaddr != NULL) {
260                         free_pages((unsigned long)fpc_virtaddr,
261                                    get_order
262                                    (config_params->fault_pxl.fp_num *
263                                    FP_NUM_BYTES));
264                 }
265
266                 /* Allocate memory for FPC table */
267                 fpc_virtaddr =
268                         (unsigned int *)__get_free_pages(GFP_KERNEL | GFP_DMA,
269                                                          get_order(raw_params->
270                                                          fault_pxl.fp_num *
271                                                          FP_NUM_BYTES));
272
273                 if (fpc_virtaddr == NULL) {
274                         dev_dbg(ccdc_cfg.dev,
275                                 "\nUnable to allocate memory for FPC");
276                         return -EFAULT;
277                 }
278                 fpc_physaddr =
279                     (unsigned int *)virt_to_phys((void *)fpc_virtaddr);
280         }
281
282         /* Copy number of fault pixels and FPC table */
283         config_params->fault_pxl.fp_num = raw_params->fault_pxl.fp_num;
284         if (copy_from_user(fpc_virtaddr,
285                         (void __user *)raw_params->fault_pxl.fpc_table_addr,
286                         config_params->fault_pxl.fp_num * FP_NUM_BYTES)) {
287                 dev_dbg(ccdc_cfg.dev, "\n copy_from_user failed");
288                 return -EFAULT;
289         }
290         config_params->fault_pxl.fpc_table_addr = (unsigned long)fpc_physaddr;
291         return 0;
292 }
293
294 static int ccdc_close(struct device *dev)
295 {
296         struct ccdc_config_params_raw *config_params =
297                                 &ccdc_cfg.bayer.config_params;
298         unsigned int *fpc_physaddr = NULL, *fpc_virtaddr = NULL;
299
300         fpc_physaddr = (unsigned int *)config_params->fault_pxl.fpc_table_addr;
301
302         if (fpc_physaddr != NULL) {
303                 fpc_virtaddr = (unsigned int *)
304                     phys_to_virt((unsigned long)fpc_physaddr);
305                 free_pages((unsigned long)fpc_virtaddr,
306                            get_order(config_params->fault_pxl.fp_num *
307                            FP_NUM_BYTES));
308         }
309         return 0;
310 }
311
312 /*
313  * ccdc_restore_defaults()
314  * This function will write defaults to all CCDC registers
315  */
316 static void ccdc_restore_defaults(void)
317 {
318         int i;
319
320         /* disable CCDC */
321         ccdc_enable(0);
322         /* set all registers to default value */
323         for (i = 4; i <= 0x94; i += 4)
324                 regw(0,  i);
325         regw(CCDC_NO_CULLING, CCDC_CULLING);
326         regw(CCDC_GAMMA_BITS_11_2, CCDC_ALAW);
327 }
328
329 static int ccdc_open(struct device *device)
330 {
331         ccdc_restore_defaults();
332         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
333                 ccdc_enable_vport(1);
334         return 0;
335 }
336
337 static void ccdc_sbl_reset(void)
338 {
339         vpss_clear_wbl_overflow(VPSS_PCR_CCDC_WBL_O);
340 }
341
342 /* Parameter operations */
343 static int ccdc_set_params(void __user *params)
344 {
345         struct ccdc_config_params_raw ccdc_raw_params;
346         int x;
347
348         if (ccdc_cfg.if_type != VPFE_RAW_BAYER)
349                 return -EINVAL;
350
351         x = copy_from_user(&ccdc_raw_params, params, sizeof(ccdc_raw_params));
352         if (x) {
353                 dev_dbg(ccdc_cfg.dev, "ccdc_set_params: error in copyingccdc params, %d\n",
354                         x);
355                 return -EFAULT;
356         }
357
358         if (!validate_ccdc_param(&ccdc_raw_params)) {
359                 if (!ccdc_update_raw_params(&ccdc_raw_params))
360                         return 0;
361         }
362         return -EINVAL;
363 }
364
365 /*
366  * ccdc_config_ycbcr()
367  * This function will configure CCDC for YCbCr video capture
368  */
369 static void ccdc_config_ycbcr(void)
370 {
371         struct ccdc_params_ycbcr *params = &ccdc_cfg.ycbcr;
372         u32 syn_mode;
373
374         dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_ycbcr...");
375         /*
376          * first restore the CCDC registers to default values
377          * This is important since we assume default values to be set in
378          * a lot of registers that we didn't touch
379          */
380         ccdc_restore_defaults();
381
382         /*
383          * configure pixel format, frame format, configure video frame
384          * format, enable output to SDRAM, enable internal timing generator
385          * and 8bit pack mode
386          */
387         syn_mode = (((params->pix_fmt & CCDC_SYN_MODE_INPMOD_MASK) <<
388                     CCDC_SYN_MODE_INPMOD_SHIFT) |
389                     ((params->frm_fmt & CCDC_SYN_FLDMODE_MASK) <<
390                     CCDC_SYN_FLDMODE_SHIFT) | CCDC_VDHDEN_ENABLE |
391                     CCDC_WEN_ENABLE | CCDC_DATA_PACK_ENABLE);
392
393         /* setup BT.656 sync mode */
394         if (params->bt656_enable) {
395                 regw(CCDC_REC656IF_BT656_EN, CCDC_REC656IF);
396
397                 /*
398                  * configure the FID, VD, HD pin polarity,
399                  * fld,hd pol positive, vd negative, 8-bit data
400                  */
401                 syn_mode |= CCDC_SYN_MODE_VD_POL_NEGATIVE;
402                 if (ccdc_cfg.if_type == VPFE_BT656_10BIT)
403                         syn_mode |= CCDC_SYN_MODE_10BITS;
404                 else
405                         syn_mode |= CCDC_SYN_MODE_8BITS;
406         } else {
407                 /* y/c external sync mode */
408                 syn_mode |= (((params->fid_pol & CCDC_FID_POL_MASK) <<
409                              CCDC_FID_POL_SHIFT) |
410                              ((params->hd_pol & CCDC_HD_POL_MASK) <<
411                              CCDC_HD_POL_SHIFT) |
412                              ((params->vd_pol & CCDC_VD_POL_MASK) <<
413                              CCDC_VD_POL_SHIFT));
414         }
415         regw(syn_mode, CCDC_SYN_MODE);
416
417         /* configure video window */
418         ccdc_setwin(&params->win, params->frm_fmt, 2);
419
420         /*
421          * configure the order of y cb cr in SDRAM, and disable latch
422          * internal register on vsync
423          */
424         if (ccdc_cfg.if_type == VPFE_BT656_10BIT)
425                 regw((params->pix_order << CCDC_CCDCFG_Y8POS_SHIFT) |
426                         CCDC_LATCH_ON_VSYNC_DISABLE | CCDC_CCDCFG_BW656_10BIT,
427                         CCDC_CCDCFG);
428         else
429                 regw((params->pix_order << CCDC_CCDCFG_Y8POS_SHIFT) |
430                         CCDC_LATCH_ON_VSYNC_DISABLE, CCDC_CCDCFG);
431
432         /*
433          * configure the horizontal line offset. This should be a
434          * on 32 byte boundary. So clear LSB 5 bits
435          */
436         regw(((params->win.width * 2  + 31) & ~0x1f), CCDC_HSIZE_OFF);
437
438         /* configure the memory line offset */
439         if (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED)
440                 /* two fields are interleaved in memory */
441                 regw(CCDC_SDOFST_FIELD_INTERLEAVED, CCDC_SDOFST);
442
443         ccdc_sbl_reset();
444         dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_config_ycbcr...\n");
445 }
446
447 static void ccdc_config_black_clamp(struct ccdc_black_clamp *bclamp)
448 {
449         u32 val;
450
451         if (!bclamp->enable) {
452                 /* configure DCSub */
453                 val = (bclamp->dc_sub) & CCDC_BLK_DC_SUB_MASK;
454                 regw(val, CCDC_DCSUB);
455                 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to DCSUB...\n", val);
456                 regw(CCDC_CLAMP_DEFAULT_VAL, CCDC_CLAMP);
457                 dev_dbg(ccdc_cfg.dev, "\nWriting 0x0000 to CLAMP...\n");
458                 return;
459         }
460         /*
461          * Configure gain,  Start pixel, No of line to be avg,
462          * No of pixel/line to be avg, & Enable the Black clamping
463          */
464         val = ((bclamp->sgain & CCDC_BLK_SGAIN_MASK) |
465                ((bclamp->start_pixel & CCDC_BLK_ST_PXL_MASK) <<
466                 CCDC_BLK_ST_PXL_SHIFT) |
467                ((bclamp->sample_ln & CCDC_BLK_SAMPLE_LINE_MASK) <<
468                 CCDC_BLK_SAMPLE_LINE_SHIFT) |
469                ((bclamp->sample_pixel & CCDC_BLK_SAMPLE_LN_MASK) <<
470                 CCDC_BLK_SAMPLE_LN_SHIFT) | CCDC_BLK_CLAMP_ENABLE);
471         regw(val, CCDC_CLAMP);
472         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to CLAMP...\n", val);
473         /* If Black clamping is enable then make dcsub 0 */
474         regw(CCDC_DCSUB_DEFAULT_VAL, CCDC_DCSUB);
475         dev_dbg(ccdc_cfg.dev, "\nWriting 0x00000000 to DCSUB...\n");
476 }
477
478 static void ccdc_config_black_compense(struct ccdc_black_compensation *bcomp)
479 {
480         u32 val;
481
482         val = ((bcomp->b & CCDC_BLK_COMP_MASK) |
483               ((bcomp->gb & CCDC_BLK_COMP_MASK) <<
484                CCDC_BLK_COMP_GB_COMP_SHIFT) |
485               ((bcomp->gr & CCDC_BLK_COMP_MASK) <<
486                CCDC_BLK_COMP_GR_COMP_SHIFT) |
487               ((bcomp->r & CCDC_BLK_COMP_MASK) <<
488                CCDC_BLK_COMP_R_COMP_SHIFT));
489         regw(val, CCDC_BLKCMP);
490 }
491
492 static void ccdc_config_fpc(struct ccdc_fault_pixel *fpc)
493 {
494         u32 val;
495
496         /* Initially disable FPC */
497         val = CCDC_FPC_DISABLE;
498         regw(val, CCDC_FPC);
499
500         if (!fpc->enable)
501                 return;
502
503         /* Configure Fault pixel if needed */
504         regw(fpc->fpc_table_addr, CCDC_FPC_ADDR);
505         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%lx to FPC_ADDR...\n",
506                        (fpc->fpc_table_addr));
507         /* Write the FPC params with FPC disable */
508         val = fpc->fp_num & CCDC_FPC_FPC_NUM_MASK;
509         regw(val, CCDC_FPC);
510
511         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
512         /* read the FPC register */
513         val = regr(CCDC_FPC) | CCDC_FPC_ENABLE;
514         regw(val, CCDC_FPC);
515         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FPC...\n", val);
516 }
517
518 /*
519  * ccdc_config_raw()
520  * This function will configure CCDC for Raw capture mode
521  */
522 static void ccdc_config_raw(void)
523 {
524         struct ccdc_params_raw *params = &ccdc_cfg.bayer;
525         struct ccdc_config_params_raw *config_params =
526                                 &ccdc_cfg.bayer.config_params;
527         unsigned int syn_mode = 0;
528         unsigned int val;
529
530         dev_dbg(ccdc_cfg.dev, "\nStarting ccdc_config_raw...");
531
532         /*      Reset CCDC */
533         ccdc_restore_defaults();
534
535         /* Disable latching function registers on VSYNC  */
536         regw(CCDC_LATCH_ON_VSYNC_DISABLE, CCDC_CCDCFG);
537
538         /*
539          * Configure the vertical sync polarity(SYN_MODE.VDPOL),
540          * horizontal sync polarity (SYN_MODE.HDPOL), frame id polarity
541          * (SYN_MODE.FLDPOL), frame format(progressive or interlace),
542          * data size(SYNMODE.DATSIZ), &pixel format (Input mode), output
543          * SDRAM, enable internal timing generator
544          */
545         syn_mode =
546                 (((params->vd_pol & CCDC_VD_POL_MASK) << CCDC_VD_POL_SHIFT) |
547                 ((params->hd_pol & CCDC_HD_POL_MASK) << CCDC_HD_POL_SHIFT) |
548                 ((params->fid_pol & CCDC_FID_POL_MASK) << CCDC_FID_POL_SHIFT) |
549                 ((params->frm_fmt & CCDC_FRM_FMT_MASK) << CCDC_FRM_FMT_SHIFT) |
550                 ((config_params->data_sz & CCDC_DATA_SZ_MASK) <<
551                 CCDC_DATA_SZ_SHIFT) |
552                 ((params->pix_fmt & CCDC_PIX_FMT_MASK) << CCDC_PIX_FMT_SHIFT) |
553                 CCDC_WEN_ENABLE | CCDC_VDHDEN_ENABLE);
554
555         /* Enable and configure aLaw register if needed */
556         if (config_params->alaw.enable) {
557                 val = ((config_params->alaw.gamma_wd &
558                       CCDC_ALAW_GAMMA_WD_MASK) | CCDC_ALAW_ENABLE);
559                 regw(val, CCDC_ALAW);
560                 dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to ALAW...\n", val);
561         }
562
563         /* Configure video window */
564         ccdc_setwin(&params->win, params->frm_fmt, CCDC_PPC_RAW);
565
566         /* Configure Black Clamp */
567         ccdc_config_black_clamp(&config_params->blk_clamp);
568
569         /* Configure Black level compensation */
570         ccdc_config_black_compense(&config_params->blk_comp);
571
572         /* Configure Fault Pixel Correction */
573         ccdc_config_fpc(&config_params->fault_pxl);
574
575         /* If data size is 8 bit then pack the data */
576         if ((config_params->data_sz == CCDC_DATA_8BITS) ||
577              config_params->alaw.enable)
578                 syn_mode |= CCDC_DATA_PACK_ENABLE;
579
580         /* disable video port */
581         val = CCDC_DISABLE_VIDEO_PORT;
582
583         if (config_params->data_sz == CCDC_DATA_8BITS)
584                 val |= (CCDC_DATA_10BITS & CCDC_FMTCFG_VPIN_MASK)
585                     << CCDC_FMTCFG_VPIN_SHIFT;
586         else
587                 val |= (config_params->data_sz & CCDC_FMTCFG_VPIN_MASK)
588                     << CCDC_FMTCFG_VPIN_SHIFT;
589         /* Write value in FMTCFG */
590         regw(val, CCDC_FMTCFG);
591
592         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMTCFG...\n", val);
593         /* Configure the color pattern according to mt9t001 sensor */
594         regw(CCDC_COLPTN_VAL, CCDC_COLPTN);
595
596         dev_dbg(ccdc_cfg.dev, "\nWriting 0xBB11BB11 to COLPTN...\n");
597         /*
598          * Configure Data formatter(Video port) pixel selection
599          * (FMT_HORZ, FMT_VERT)
600          */
601         val = ((params->win.left & CCDC_FMT_HORZ_FMTSPH_MASK) <<
602               CCDC_FMT_HORZ_FMTSPH_SHIFT) |
603               (params->win.width & CCDC_FMT_HORZ_FMTLNH_MASK);
604         regw(val, CCDC_FMT_HORZ);
605
606         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMT_HORZ...\n", val);
607         val = (params->win.top & CCDC_FMT_VERT_FMTSLV_MASK)
608             << CCDC_FMT_VERT_FMTSLV_SHIFT;
609         if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE)
610                 val |= (params->win.height) & CCDC_FMT_VERT_FMTLNV_MASK;
611         else
612                 val |= (params->win.height >> 1) & CCDC_FMT_VERT_FMTLNV_MASK;
613
614         dev_dbg(ccdc_cfg.dev, "\nparams->win.height  0x%x ...\n",
615                params->win.height);
616         regw(val, CCDC_FMT_VERT);
617
618         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to FMT_VERT...\n", val);
619
620         dev_dbg(ccdc_cfg.dev, "\nbelow regw(val, FMT_VERT)...");
621
622         /*
623          * Configure Horizontal offset register. If pack 8 is enabled then
624          * 1 pixel will take 1 byte
625          */
626         if ((config_params->data_sz == CCDC_DATA_8BITS) ||
627             config_params->alaw.enable)
628                 regw((params->win.width + CCDC_32BYTE_ALIGN_VAL) &
629                     CCDC_HSIZE_OFF_MASK, CCDC_HSIZE_OFF);
630         else
631                 /* else one pixel will take 2 byte */
632                 regw(((params->win.width * CCDC_TWO_BYTES_PER_PIXEL) +
633                     CCDC_32BYTE_ALIGN_VAL) & CCDC_HSIZE_OFF_MASK,
634                     CCDC_HSIZE_OFF);
635
636         /* Set value for SDOFST */
637         if (params->frm_fmt == CCDC_FRMFMT_INTERLACED) {
638                 if (params->image_invert_enable) {
639                         /* For intelace inverse mode */
640                         regw(CCDC_INTERLACED_IMAGE_INVERT, CCDC_SDOFST);
641                         dev_dbg(ccdc_cfg.dev, "\nWriting 0x4B6D to SDOFST..\n");
642                 }
643
644                 else {
645                         /* For intelace non inverse mode */
646                         regw(CCDC_INTERLACED_NO_IMAGE_INVERT, CCDC_SDOFST);
647                         dev_dbg(ccdc_cfg.dev, "\nWriting 0x0249 to SDOFST..\n");
648                 }
649         } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
650                 regw(CCDC_PROGRESSIVE_NO_IMAGE_INVERT, CCDC_SDOFST);
651                 dev_dbg(ccdc_cfg.dev, "\nWriting 0x0000 to SDOFST...\n");
652         }
653
654         /*
655          * Configure video port pixel selection (VPOUT)
656          * Here -1 is to make the height value less than FMT_VERT.FMTLNV
657          */
658         if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE)
659                 val = (((params->win.height - 1) & CCDC_VP_OUT_VERT_NUM_MASK))
660                     << CCDC_VP_OUT_VERT_NUM_SHIFT;
661         else
662                 val =
663                     ((((params->win.height >> CCDC_INTERLACED_HEIGHT_SHIFT) -
664                      1) & CCDC_VP_OUT_VERT_NUM_MASK)) <<
665                     CCDC_VP_OUT_VERT_NUM_SHIFT;
666
667         val |= ((((params->win.width))) & CCDC_VP_OUT_HORZ_NUM_MASK)
668             << CCDC_VP_OUT_HORZ_NUM_SHIFT;
669         val |= (params->win.left) & CCDC_VP_OUT_HORZ_ST_MASK;
670         regw(val, CCDC_VP_OUT);
671
672         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to VP_OUT...\n", val);
673         regw(syn_mode, CCDC_SYN_MODE);
674         dev_dbg(ccdc_cfg.dev, "\nWriting 0x%x to SYN_MODE...\n", syn_mode);
675
676         ccdc_sbl_reset();
677         dev_dbg(ccdc_cfg.dev, "\nend of ccdc_config_raw...");
678         ccdc_readregs();
679 }
680
681 static int ccdc_configure(void)
682 {
683         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
684                 ccdc_config_raw();
685         else
686                 ccdc_config_ycbcr();
687         return 0;
688 }
689
690 static int ccdc_set_buftype(enum ccdc_buftype buf_type)
691 {
692         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
693                 ccdc_cfg.bayer.buf_type = buf_type;
694         else
695                 ccdc_cfg.ycbcr.buf_type = buf_type;
696         return 0;
697 }
698
699 static enum ccdc_buftype ccdc_get_buftype(void)
700 {
701         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
702                 return ccdc_cfg.bayer.buf_type;
703         return ccdc_cfg.ycbcr.buf_type;
704 }
705
706 static int ccdc_enum_pix(u32 *pix, int i)
707 {
708         int ret = -EINVAL;
709         if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
710                 if (i < ARRAY_SIZE(ccdc_raw_bayer_pix_formats)) {
711                         *pix = ccdc_raw_bayer_pix_formats[i];
712                         ret = 0;
713                 }
714         } else {
715                 if (i < ARRAY_SIZE(ccdc_raw_yuv_pix_formats)) {
716                         *pix = ccdc_raw_yuv_pix_formats[i];
717                         ret = 0;
718                 }
719         }
720         return ret;
721 }
722
723 static int ccdc_set_pixel_format(u32 pixfmt)
724 {
725         if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
726                 ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
727                 if (pixfmt == V4L2_PIX_FMT_SBGGR8)
728                         ccdc_cfg.bayer.config_params.alaw.enable = 1;
729                 else if (pixfmt != V4L2_PIX_FMT_SBGGR16)
730                         return -EINVAL;
731         } else {
732                 if (pixfmt == V4L2_PIX_FMT_YUYV)
733                         ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_YCBYCR;
734                 else if (pixfmt == V4L2_PIX_FMT_UYVY)
735                         ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
736                 else
737                         return -EINVAL;
738         }
739         return 0;
740 }
741
742 static u32 ccdc_get_pixel_format(void)
743 {
744         struct ccdc_a_law *alaw = &ccdc_cfg.bayer.config_params.alaw;
745         u32 pixfmt;
746
747         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
748                 if (alaw->enable)
749                         pixfmt = V4L2_PIX_FMT_SBGGR8;
750                 else
751                         pixfmt = V4L2_PIX_FMT_SBGGR16;
752         else {
753                 if (ccdc_cfg.ycbcr.pix_order == CCDC_PIXORDER_YCBYCR)
754                         pixfmt = V4L2_PIX_FMT_YUYV;
755                 else
756                         pixfmt = V4L2_PIX_FMT_UYVY;
757         }
758         return pixfmt;
759 }
760
761 static int ccdc_set_image_window(struct v4l2_rect *win)
762 {
763         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
764                 ccdc_cfg.bayer.win = *win;
765         else
766                 ccdc_cfg.ycbcr.win = *win;
767         return 0;
768 }
769
770 static void ccdc_get_image_window(struct v4l2_rect *win)
771 {
772         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
773                 *win = ccdc_cfg.bayer.win;
774         else
775                 *win = ccdc_cfg.ycbcr.win;
776 }
777
778 static unsigned int ccdc_get_line_length(void)
779 {
780         struct ccdc_config_params_raw *config_params =
781                                 &ccdc_cfg.bayer.config_params;
782         unsigned int len;
783
784         if (ccdc_cfg.if_type == VPFE_RAW_BAYER) {
785                 if ((config_params->alaw.enable) ||
786                     (config_params->data_sz == CCDC_DATA_8BITS))
787                         len = ccdc_cfg.bayer.win.width;
788                 else
789                         len = ccdc_cfg.bayer.win.width * 2;
790         } else
791                 len = ccdc_cfg.ycbcr.win.width * 2;
792         return ALIGN(len, 32);
793 }
794
795 static int ccdc_set_frame_format(enum ccdc_frmfmt frm_fmt)
796 {
797         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
798                 ccdc_cfg.bayer.frm_fmt = frm_fmt;
799         else
800                 ccdc_cfg.ycbcr.frm_fmt = frm_fmt;
801         return 0;
802 }
803
804 static enum ccdc_frmfmt ccdc_get_frame_format(void)
805 {
806         if (ccdc_cfg.if_type == VPFE_RAW_BAYER)
807                 return ccdc_cfg.bayer.frm_fmt;
808         else
809                 return ccdc_cfg.ycbcr.frm_fmt;
810 }
811
812 static int ccdc_getfid(void)
813 {
814         return (regr(CCDC_SYN_MODE) >> 15) & 1;
815 }
816
817 /* misc operations */
818 static inline void ccdc_setfbaddr(unsigned long addr)
819 {
820         regw(addr & 0xffffffe0, CCDC_SDR_ADDR);
821 }
822
823 static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params)
824 {
825         ccdc_cfg.if_type = params->if_type;
826
827         switch (params->if_type) {
828         case VPFE_BT656:
829         case VPFE_YCBCR_SYNC_16:
830         case VPFE_YCBCR_SYNC_8:
831         case VPFE_BT656_10BIT:
832                 ccdc_cfg.ycbcr.vd_pol = params->vdpol;
833                 ccdc_cfg.ycbcr.hd_pol = params->hdpol;
834                 break;
835         default:
836                 /* TODO add support for raw bayer here */
837                 return -EINVAL;
838         }
839         return 0;
840 }
841
842 static void ccdc_save_context(void)
843 {
844         ccdc_ctx[CCDC_PCR >> 2] = regr(CCDC_PCR);
845         ccdc_ctx[CCDC_SYN_MODE >> 2] = regr(CCDC_SYN_MODE);
846         ccdc_ctx[CCDC_HD_VD_WID >> 2] = regr(CCDC_HD_VD_WID);
847         ccdc_ctx[CCDC_PIX_LINES >> 2] = regr(CCDC_PIX_LINES);
848         ccdc_ctx[CCDC_HORZ_INFO >> 2] = regr(CCDC_HORZ_INFO);
849         ccdc_ctx[CCDC_VERT_START >> 2] = regr(CCDC_VERT_START);
850         ccdc_ctx[CCDC_VERT_LINES >> 2] = regr(CCDC_VERT_LINES);
851         ccdc_ctx[CCDC_CULLING >> 2] = regr(CCDC_CULLING);
852         ccdc_ctx[CCDC_HSIZE_OFF >> 2] = regr(CCDC_HSIZE_OFF);
853         ccdc_ctx[CCDC_SDOFST >> 2] = regr(CCDC_SDOFST);
854         ccdc_ctx[CCDC_SDR_ADDR >> 2] = regr(CCDC_SDR_ADDR);
855         ccdc_ctx[CCDC_CLAMP >> 2] = regr(CCDC_CLAMP);
856         ccdc_ctx[CCDC_DCSUB >> 2] = regr(CCDC_DCSUB);
857         ccdc_ctx[CCDC_COLPTN >> 2] = regr(CCDC_COLPTN);
858         ccdc_ctx[CCDC_BLKCMP >> 2] = regr(CCDC_BLKCMP);
859         ccdc_ctx[CCDC_FPC >> 2] = regr(CCDC_FPC);
860         ccdc_ctx[CCDC_FPC_ADDR >> 2] = regr(CCDC_FPC_ADDR);
861         ccdc_ctx[CCDC_VDINT >> 2] = regr(CCDC_VDINT);
862         ccdc_ctx[CCDC_ALAW >> 2] = regr(CCDC_ALAW);
863         ccdc_ctx[CCDC_REC656IF >> 2] = regr(CCDC_REC656IF);
864         ccdc_ctx[CCDC_CCDCFG >> 2] = regr(CCDC_CCDCFG);
865         ccdc_ctx[CCDC_FMTCFG >> 2] = regr(CCDC_FMTCFG);
866         ccdc_ctx[CCDC_FMT_HORZ >> 2] = regr(CCDC_FMT_HORZ);
867         ccdc_ctx[CCDC_FMT_VERT >> 2] = regr(CCDC_FMT_VERT);
868         ccdc_ctx[CCDC_FMT_ADDR0 >> 2] = regr(CCDC_FMT_ADDR0);
869         ccdc_ctx[CCDC_FMT_ADDR1 >> 2] = regr(CCDC_FMT_ADDR1);
870         ccdc_ctx[CCDC_FMT_ADDR2 >> 2] = regr(CCDC_FMT_ADDR2);
871         ccdc_ctx[CCDC_FMT_ADDR3 >> 2] = regr(CCDC_FMT_ADDR3);
872         ccdc_ctx[CCDC_FMT_ADDR4 >> 2] = regr(CCDC_FMT_ADDR4);
873         ccdc_ctx[CCDC_FMT_ADDR5 >> 2] = regr(CCDC_FMT_ADDR5);
874         ccdc_ctx[CCDC_FMT_ADDR6 >> 2] = regr(CCDC_FMT_ADDR6);
875         ccdc_ctx[CCDC_FMT_ADDR7 >> 2] = regr(CCDC_FMT_ADDR7);
876         ccdc_ctx[CCDC_PRGEVEN_0 >> 2] = regr(CCDC_PRGEVEN_0);
877         ccdc_ctx[CCDC_PRGEVEN_1 >> 2] = regr(CCDC_PRGEVEN_1);
878         ccdc_ctx[CCDC_PRGODD_0 >> 2] = regr(CCDC_PRGODD_0);
879         ccdc_ctx[CCDC_PRGODD_1 >> 2] = regr(CCDC_PRGODD_1);
880         ccdc_ctx[CCDC_VP_OUT >> 2] = regr(CCDC_VP_OUT);
881 }
882
883 static void ccdc_restore_context(void)
884 {
885         regw(ccdc_ctx[CCDC_SYN_MODE >> 2], CCDC_SYN_MODE);
886         regw(ccdc_ctx[CCDC_HD_VD_WID >> 2], CCDC_HD_VD_WID);
887         regw(ccdc_ctx[CCDC_PIX_LINES >> 2], CCDC_PIX_LINES);
888         regw(ccdc_ctx[CCDC_HORZ_INFO >> 2], CCDC_HORZ_INFO);
889         regw(ccdc_ctx[CCDC_VERT_START >> 2], CCDC_VERT_START);
890         regw(ccdc_ctx[CCDC_VERT_LINES >> 2], CCDC_VERT_LINES);
891         regw(ccdc_ctx[CCDC_CULLING >> 2], CCDC_CULLING);
892         regw(ccdc_ctx[CCDC_HSIZE_OFF >> 2], CCDC_HSIZE_OFF);
893         regw(ccdc_ctx[CCDC_SDOFST >> 2], CCDC_SDOFST);
894         regw(ccdc_ctx[CCDC_SDR_ADDR >> 2], CCDC_SDR_ADDR);
895         regw(ccdc_ctx[CCDC_CLAMP >> 2], CCDC_CLAMP);
896         regw(ccdc_ctx[CCDC_DCSUB >> 2], CCDC_DCSUB);
897         regw(ccdc_ctx[CCDC_COLPTN >> 2], CCDC_COLPTN);
898         regw(ccdc_ctx[CCDC_BLKCMP >> 2], CCDC_BLKCMP);
899         regw(ccdc_ctx[CCDC_FPC >> 2], CCDC_FPC);
900         regw(ccdc_ctx[CCDC_FPC_ADDR >> 2], CCDC_FPC_ADDR);
901         regw(ccdc_ctx[CCDC_VDINT >> 2], CCDC_VDINT);
902         regw(ccdc_ctx[CCDC_ALAW >> 2], CCDC_ALAW);
903         regw(ccdc_ctx[CCDC_REC656IF >> 2], CCDC_REC656IF);
904         regw(ccdc_ctx[CCDC_CCDCFG >> 2], CCDC_CCDCFG);
905         regw(ccdc_ctx[CCDC_FMTCFG >> 2], CCDC_FMTCFG);
906         regw(ccdc_ctx[CCDC_FMT_HORZ >> 2], CCDC_FMT_HORZ);
907         regw(ccdc_ctx[CCDC_FMT_VERT >> 2], CCDC_FMT_VERT);
908         regw(ccdc_ctx[CCDC_FMT_ADDR0 >> 2], CCDC_FMT_ADDR0);
909         regw(ccdc_ctx[CCDC_FMT_ADDR1 >> 2], CCDC_FMT_ADDR1);
910         regw(ccdc_ctx[CCDC_FMT_ADDR2 >> 2], CCDC_FMT_ADDR2);
911         regw(ccdc_ctx[CCDC_FMT_ADDR3 >> 2], CCDC_FMT_ADDR3);
912         regw(ccdc_ctx[CCDC_FMT_ADDR4 >> 2], CCDC_FMT_ADDR4);
913         regw(ccdc_ctx[CCDC_FMT_ADDR5 >> 2], CCDC_FMT_ADDR5);
914         regw(ccdc_ctx[CCDC_FMT_ADDR6 >> 2], CCDC_FMT_ADDR6);
915         regw(ccdc_ctx[CCDC_FMT_ADDR7 >> 2], CCDC_FMT_ADDR7);
916         regw(ccdc_ctx[CCDC_PRGEVEN_0 >> 2], CCDC_PRGEVEN_0);
917         regw(ccdc_ctx[CCDC_PRGEVEN_1 >> 2], CCDC_PRGEVEN_1);
918         regw(ccdc_ctx[CCDC_PRGODD_0 >> 2], CCDC_PRGODD_0);
919         regw(ccdc_ctx[CCDC_PRGODD_1 >> 2], CCDC_PRGODD_1);
920         regw(ccdc_ctx[CCDC_VP_OUT >> 2], CCDC_VP_OUT);
921         regw(ccdc_ctx[CCDC_PCR >> 2], CCDC_PCR);
922 }
923 static struct ccdc_hw_device ccdc_hw_dev = {
924         .name = "DM6446 CCDC",
925         .owner = THIS_MODULE,
926         .hw_ops = {
927                 .open = ccdc_open,
928                 .close = ccdc_close,
929                 .reset = ccdc_sbl_reset,
930                 .enable = ccdc_enable,
931                 .set_hw_if_params = ccdc_set_hw_if_params,
932                 .set_params = ccdc_set_params,
933                 .configure = ccdc_configure,
934                 .set_buftype = ccdc_set_buftype,
935                 .get_buftype = ccdc_get_buftype,
936                 .enum_pix = ccdc_enum_pix,
937                 .set_pixel_format = ccdc_set_pixel_format,
938                 .get_pixel_format = ccdc_get_pixel_format,
939                 .set_frame_format = ccdc_set_frame_format,
940                 .get_frame_format = ccdc_get_frame_format,
941                 .set_image_window = ccdc_set_image_window,
942                 .get_image_window = ccdc_get_image_window,
943                 .get_line_length = ccdc_get_line_length,
944                 .setfbaddr = ccdc_setfbaddr,
945                 .getfid = ccdc_getfid,
946         },
947 };
948
949 static int dm644x_ccdc_probe(struct platform_device *pdev)
950 {
951         struct resource *res;
952         int status = 0;
953
954         /*
955          * first try to register with vpfe. If not correct platform, then we
956          * don't have to iomap
957          */
958         status = vpfe_register_ccdc_device(&ccdc_hw_dev);
959         if (status < 0)
960                 return status;
961
962         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
963         if (!res) {
964                 status = -ENODEV;
965                 goto fail_nores;
966         }
967
968         res = request_mem_region(res->start, resource_size(res), res->name);
969         if (!res) {
970                 status = -EBUSY;
971                 goto fail_nores;
972         }
973
974         ccdc_cfg.base_addr = ioremap_nocache(res->start, resource_size(res));
975         if (!ccdc_cfg.base_addr) {
976                 status = -ENOMEM;
977                 goto fail_nomem;
978         }
979
980         ccdc_cfg.dev = &pdev->dev;
981         printk(KERN_NOTICE "%s is registered with vpfe.\n", ccdc_hw_dev.name);
982         return 0;
983 fail_nomem:
984         release_mem_region(res->start, resource_size(res));
985 fail_nores:
986         vpfe_unregister_ccdc_device(&ccdc_hw_dev);
987         return status;
988 }
989
990 static int dm644x_ccdc_remove(struct platform_device *pdev)
991 {
992         struct resource *res;
993
994         iounmap(ccdc_cfg.base_addr);
995         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
996         if (res)
997                 release_mem_region(res->start, resource_size(res));
998         vpfe_unregister_ccdc_device(&ccdc_hw_dev);
999         return 0;
1000 }
1001
1002 static int dm644x_ccdc_suspend(struct device *dev)
1003 {
1004         /* Save CCDC context */
1005         ccdc_save_context();
1006         /* Disable CCDC */
1007         ccdc_enable(0);
1008
1009         return 0;
1010 }
1011
1012 static int dm644x_ccdc_resume(struct device *dev)
1013 {
1014         /* Restore CCDC context */
1015         ccdc_restore_context();
1016
1017         return 0;
1018 }
1019
1020 static const struct dev_pm_ops dm644x_ccdc_pm_ops = {
1021         .suspend = dm644x_ccdc_suspend,
1022         .resume = dm644x_ccdc_resume,
1023 };
1024
1025 static struct platform_driver dm644x_ccdc_driver = {
1026         .driver = {
1027                 .name   = "dm644x_ccdc",
1028                 .pm = &dm644x_ccdc_pm_ops,
1029         },
1030         .remove = dm644x_ccdc_remove,
1031         .probe = dm644x_ccdc_probe,
1032 };
1033
1034 module_platform_driver(dm644x_ccdc_driver);