2 * Copyright (C) 2008-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 * Image Sensor Interface (ISIF) driver
20 * This driver is for configuring the ISIF IP available on DM365 or any other
21 * TI SoCs. This is used for capturing yuv or bayer video or image data
22 * from a decoder or sensor. This IP is similar to the CCDC IP on DM355
23 * and DM6446, but with enhanced or additional ip blocks. The driver
24 * configures the ISIF upon commands from the vpfe bridge driver through
25 * ccdc_hw_device interface.
27 * TODO: 1) Raw bayer parameter settings and bayer capture
28 * 2) Add support for control ioctl
30 #include <linux/delay.h>
31 #include <linux/platform_device.h>
32 #include <linux/uaccess.h>
34 #include <linux/videodev2.h>
35 #include <linux/clk.h>
36 #include <linux/err.h>
40 #include <media/davinci/isif.h>
41 #include <media/davinci/vpss.h>
43 #include "isif_regs.h"
44 #include "ccdc_hw_device.h"
46 /* Defaults for module configuration parameters */
47 static struct isif_config_params_raw isif_config_defaults
= {
50 .corr_shft
= ISIF_NO_SHIFT
,
83 /* ISIF operation configuration */
84 static struct isif_oper_config
{
86 enum vpfe_hw_if_type if_type
;
87 struct isif_ycbcr_config ycbcr
;
88 struct isif_params_raw bayer
;
89 enum isif_data_pack data_pack
;
92 /* ISIF base address */
93 void __iomem
*base_addr
;
94 /* ISIF Linear Table 0 */
95 void __iomem
*linear_tbl0_addr
;
96 /* ISIF Linear Table 1 */
97 void __iomem
*linear_tbl1_addr
;
100 .pix_fmt
= CCDC_PIXFMT_YCBCR_8BIT
,
101 .frm_fmt
= CCDC_FRMFMT_INTERLACED
,
102 .win
= ISIF_WIN_NTSC
,
103 .fid_pol
= VPFE_PINPOL_POSITIVE
,
104 .vd_pol
= VPFE_PINPOL_POSITIVE
,
105 .hd_pol
= VPFE_PINPOL_POSITIVE
,
106 .pix_order
= CCDC_PIXORDER_CBYCRY
,
107 .buf_type
= CCDC_BUFTYPE_FLD_INTERLEAVED
,
110 .pix_fmt
= CCDC_PIXFMT_RAW
,
111 .frm_fmt
= CCDC_FRMFMT_PROGRESSIVE
,
113 .fid_pol
= VPFE_PINPOL_POSITIVE
,
114 .vd_pol
= VPFE_PINPOL_POSITIVE
,
115 .hd_pol
= VPFE_PINPOL_POSITIVE
,
122 .cfa_pat
= ISIF_CFA_PAT_MOSAIC
,
123 .data_msb
= ISIF_BIT_MSB_11
,
125 .data_shift
= ISIF_NO_SHIFT
,
127 .olop
= ISIF_GREEN_BLUE
,
130 .elep
= ISIF_GREEN_RED
,
133 .olop
= ISIF_GREEN_BLUE
,
136 .elep
= ISIF_GREEN_RED
,
141 .data_pack
= ISIF_DATA_PACK8
,
144 /* Raw Bayer formats */
145 static const u32 isif_raw_bayer_pix_formats
[] = {
146 V4L2_PIX_FMT_SBGGR8
, V4L2_PIX_FMT_SBGGR16
};
148 /* Raw YUV formats */
149 static const u32 isif_raw_yuv_pix_formats
[] = {
150 V4L2_PIX_FMT_UYVY
, V4L2_PIX_FMT_YUYV
};
152 /* register access routines */
153 static inline u32
regr(u32 offset
)
155 return __raw_readl(isif_cfg
.base_addr
+ offset
);
158 static inline void regw(u32 val
, u32 offset
)
160 __raw_writel(val
, isif_cfg
.base_addr
+ offset
);
163 /* reg_modify() - read, modify and write register */
164 static inline u32
reg_modify(u32 mask
, u32 val
, u32 offset
)
166 u32 new_val
= (regr(offset
) & ~mask
) | (val
& mask
);
168 regw(new_val
, offset
);
172 static inline void regw_lin_tbl(u32 val
, u32 offset
, int i
)
175 __raw_writel(val
, isif_cfg
.linear_tbl0_addr
+ offset
);
177 __raw_writel(val
, isif_cfg
.linear_tbl1_addr
+ offset
);
180 static void isif_disable_all_modules(void)
188 /* disable linearization */
190 /* disable other modules here as they are supported */
193 static void isif_enable(int en
)
196 /* Before disable isif, disable all ISIF modules */
197 isif_disable_all_modules();
199 * wait for next VD. Assume lowest scan rate is 12 Hz. So
200 * 100 msec delay is good enough
204 reg_modify(ISIF_SYNCEN_VDHDEN_MASK
, en
, SYNCEN
);
207 static void isif_enable_output_to_sdram(int en
)
209 reg_modify(ISIF_SYNCEN_WEN_MASK
, en
<< ISIF_SYNCEN_WEN_SHIFT
, SYNCEN
);
212 static void isif_config_culling(struct isif_cul
*cul
)
216 /* Horizontal pattern */
217 val
= (cul
->hcpat_even
<< CULL_PAT_EVEN_LINE_SHIFT
) | cul
->hcpat_odd
;
220 /* vertical pattern */
221 regw(cul
->vcpat
, CULV
);
224 reg_modify(ISIF_LPF_MASK
<< ISIF_LPF_SHIFT
,
225 cul
->en_lpf
<< ISIF_LPF_SHIFT
, MODESET
);
228 static void isif_config_gain_offset(void)
230 struct isif_gain_offsets_adj
*gain_off_p
=
231 &isif_cfg
.bayer
.config_params
.gain_offset
;
234 val
= (!!gain_off_p
->gain_sdram_en
<< GAIN_SDRAM_EN_SHIFT
) |
235 (!!gain_off_p
->gain_ipipe_en
<< GAIN_IPIPE_EN_SHIFT
) |
236 (!!gain_off_p
->gain_h3a_en
<< GAIN_H3A_EN_SHIFT
) |
237 (!!gain_off_p
->offset_sdram_en
<< OFST_SDRAM_EN_SHIFT
) |
238 (!!gain_off_p
->offset_ipipe_en
<< OFST_IPIPE_EN_SHIFT
) |
239 (!!gain_off_p
->offset_h3a_en
<< OFST_H3A_EN_SHIFT
);
241 reg_modify(GAIN_OFFSET_EN_MASK
, val
, CGAMMAWD
);
243 val
= (gain_off_p
->gain
.r_ye
.integer
<< GAIN_INTEGER_SHIFT
) |
244 gain_off_p
->gain
.r_ye
.decimal
;
247 val
= (gain_off_p
->gain
.gr_cy
.integer
<< GAIN_INTEGER_SHIFT
) |
248 gain_off_p
->gain
.gr_cy
.decimal
;
251 val
= (gain_off_p
->gain
.gb_g
.integer
<< GAIN_INTEGER_SHIFT
) |
252 gain_off_p
->gain
.gb_g
.decimal
;
255 val
= (gain_off_p
->gain
.b_mg
.integer
<< GAIN_INTEGER_SHIFT
) |
256 gain_off_p
->gain
.b_mg
.decimal
;
259 regw(gain_off_p
->offset
, COFSTA
);
262 static void isif_restore_defaults(void)
264 enum vpss_ccdc_source_sel source
= VPSS_CCDCIN
;
266 dev_dbg(isif_cfg
.dev
, "\nstarting isif_restore_defaults...");
267 isif_cfg
.bayer
.config_params
= isif_config_defaults
;
268 /* Enable clock to ISIF, IPIPEIF and BL */
269 vpss_enable_clock(VPSS_CCDC_CLOCK
, 1);
270 vpss_enable_clock(VPSS_IPIPEIF_CLOCK
, 1);
271 vpss_enable_clock(VPSS_BL_CLOCK
, 1);
272 /* Set default offset and gain */
273 isif_config_gain_offset();
274 vpss_select_ccdc_source(source
);
275 dev_dbg(isif_cfg
.dev
, "\nEnd of isif_restore_defaults...");
278 static int isif_open(struct device
*device
)
280 isif_restore_defaults();
284 /* This function will configure the window size to be capture in ISIF reg */
285 static void isif_setwin(struct v4l2_rect
*image_win
,
286 enum ccdc_frmfmt frm_fmt
, int ppc
)
288 int horz_start
, horz_nr_pixels
;
289 int vert_start
, vert_nr_lines
;
292 dev_dbg(isif_cfg
.dev
, "\nStarting isif_setwin...");
294 * ppc - per pixel count. indicates how many pixels per cell
295 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
296 * raw capture this is 1
298 horz_start
= image_win
->left
<< (ppc
- 1);
299 horz_nr_pixels
= ((image_win
->width
) << (ppc
- 1)) - 1;
301 /* Writing the horizontal info into the registers */
302 regw(horz_start
& START_PX_HOR_MASK
, SPH
);
303 regw(horz_nr_pixels
& NUM_PX_HOR_MASK
, LNH
);
304 vert_start
= image_win
->top
;
306 if (frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
307 vert_nr_lines
= (image_win
->height
>> 1) - 1;
309 /* To account for VD since line 0 doesn't have any data */
312 /* To account for VD since line 0 doesn't have any data */
314 vert_nr_lines
= image_win
->height
- 1;
315 /* configure VDINT0 and VDINT1 */
316 mid_img
= vert_start
+ (image_win
->height
/ 2);
317 regw(mid_img
, VDINT1
);
321 regw(vert_start
& START_VER_ONE_MASK
, SLV0
);
322 regw(vert_start
& START_VER_TWO_MASK
, SLV1
);
323 regw(vert_nr_lines
& NUM_LINES_VER
, LNV
);
326 static void isif_config_bclamp(struct isif_black_clamp
*bc
)
331 * DC Offset is always added to image data irrespective of bc enable
334 regw(bc
->dc_offset
, CLDCOFST
);
337 val
= bc
->bc_mode_color
<< ISIF_BC_MODE_COLOR_SHIFT
;
339 /* Enable BC and horizontal clamp caculation paramaters */
340 val
= val
| 1 | (bc
->horz
.mode
<< ISIF_HORZ_BC_MODE_SHIFT
);
344 if (bc
->horz
.mode
!= ISIF_HORZ_BC_DISABLE
) {
346 * Window count for calculation
347 * Base window selection
349 * Horizontal size of window
350 * vertical size of the window
351 * Horizontal start position of the window
352 * Vertical start position of the window
354 val
= bc
->horz
.win_count_calc
|
355 ((!!bc
->horz
.base_win_sel_calc
) <<
356 ISIF_HORZ_BC_WIN_SEL_SHIFT
) |
357 ((!!bc
->horz
.clamp_pix_limit
) <<
358 ISIF_HORZ_BC_PIX_LIMIT_SHIFT
) |
359 (bc
->horz
.win_h_sz_calc
<<
360 ISIF_HORZ_BC_WIN_H_SIZE_SHIFT
) |
361 (bc
->horz
.win_v_sz_calc
<<
362 ISIF_HORZ_BC_WIN_V_SIZE_SHIFT
);
365 regw(bc
->horz
.win_start_h_calc
, CLHWIN1
);
366 regw(bc
->horz
.win_start_v_calc
, CLHWIN2
);
369 /* vertical clamp caculation paramaters */
371 /* Reset clamp value sel for previous line */
373 (bc
->vert
.reset_val_sel
<< ISIF_VERT_BC_RST_VAL_SEL_SHIFT
) |
374 (bc
->vert
.line_ave_coef
<< ISIF_VERT_BC_LINE_AVE_COEF_SHIFT
);
377 /* Optical Black horizontal start position */
378 regw(bc
->vert
.ob_start_h
, CLVWIN1
);
379 /* Optical Black vertical start position */
380 regw(bc
->vert
.ob_start_v
, CLVWIN2
);
381 /* Optical Black vertical size for calculation */
382 regw(bc
->vert
.ob_v_sz_calc
, CLVWIN3
);
383 /* Vertical start position for BC subtraction */
384 regw(bc
->vert_start_sub
, CLSV
);
388 static void isif_config_linearization(struct isif_linearize
*linearize
)
392 if (!linearize
->en
) {
397 /* shift value for correction & enable linearization (set lsb) */
398 val
= (linearize
->corr_shft
<< ISIF_LIN_CORRSFT_SHIFT
) | 1;
402 val
= ((!!linearize
->scale_fact
.integer
) <<
403 ISIF_LIN_SCALE_FACT_INTEG_SHIFT
) |
404 linearize
->scale_fact
.decimal
;
407 for (i
= 0; i
< ISIF_LINEAR_TAB_SIZE
; i
++) {
409 regw_lin_tbl(linearize
->table
[i
], ((i
>> 1) << 2), 1);
411 regw_lin_tbl(linearize
->table
[i
], ((i
>> 1) << 2), 0);
415 static int isif_config_dfc(struct isif_dfc
*vdfc
)
417 /* initialize retries to loop for max ~ 250 usec */
418 u32 val
, count
, retries
= loops_per_jiffy
/ (4000/HZ
);
424 /* Correction mode */
425 val
= (vdfc
->corr_mode
<< ISIF_VDFC_CORR_MOD_SHIFT
);
427 /* Correct whole line or partial */
428 if (vdfc
->corr_whole_line
)
429 val
|= 1 << ISIF_VDFC_CORR_WHOLE_LN_SHIFT
;
431 /* level shift value */
432 val
|= vdfc
->def_level_shift
<< ISIF_VDFC_LEVEL_SHFT_SHIFT
;
436 /* Defect saturation level */
437 regw(vdfc
->def_sat_level
, VDFSATLV
);
439 regw(vdfc
->table
[0].pos_vert
, DFCMEM0
);
440 regw(vdfc
->table
[0].pos_horz
, DFCMEM1
);
441 if (vdfc
->corr_mode
== ISIF_VDFC_NORMAL
||
442 vdfc
->corr_mode
== ISIF_VDFC_HORZ_INTERPOL_IF_SAT
) {
443 regw(vdfc
->table
[0].level_at_pos
, DFCMEM2
);
444 regw(vdfc
->table
[0].level_up_pixels
, DFCMEM3
);
445 regw(vdfc
->table
[0].level_low_pixels
, DFCMEM4
);
448 /* set DFCMARST and set DFCMWR */
449 val
= regr(DFCMEMCTL
) | (1 << ISIF_DFCMEMCTL_DFCMARST_SHIFT
) | 1;
450 regw(val
, DFCMEMCTL
);
453 while (count
&& (regr(DFCMEMCTL
) & 0x1))
457 dev_dbg(isif_cfg
.dev
, "defect table write timeout !!!\n");
461 for (i
= 1; i
< vdfc
->num_vdefects
; i
++) {
462 regw(vdfc
->table
[i
].pos_vert
, DFCMEM0
);
463 regw(vdfc
->table
[i
].pos_horz
, DFCMEM1
);
464 if (vdfc
->corr_mode
== ISIF_VDFC_NORMAL
||
465 vdfc
->corr_mode
== ISIF_VDFC_HORZ_INTERPOL_IF_SAT
) {
466 regw(vdfc
->table
[i
].level_at_pos
, DFCMEM2
);
467 regw(vdfc
->table
[i
].level_up_pixels
, DFCMEM3
);
468 regw(vdfc
->table
[i
].level_low_pixels
, DFCMEM4
);
470 val
= regr(DFCMEMCTL
);
471 /* clear DFCMARST and set DFCMWR */
472 val
&= ~BIT(ISIF_DFCMEMCTL_DFCMARST_SHIFT
);
474 regw(val
, DFCMEMCTL
);
477 while (count
&& (regr(DFCMEMCTL
) & 0x1))
481 dev_err(isif_cfg
.dev
,
482 "defect table write timeout !!!\n");
486 if (vdfc
->num_vdefects
< ISIF_VDFC_TABLE_SIZE
) {
487 /* Extra cycle needed */
489 regw(0x1FFF, DFCMEM1
);
494 reg_modify((1 << ISIF_VDFC_EN_SHIFT
), (1 << ISIF_VDFC_EN_SHIFT
),
499 static void isif_config_csc(struct isif_df_csc
*df_csc
)
501 u32 val1
= 0, val2
= 0, i
;
503 if (!df_csc
->csc
.en
) {
507 for (i
= 0; i
< ISIF_CSC_NUM_COEFF
; i
++) {
510 val1
= (df_csc
->csc
.coeff
[i
].integer
<<
511 ISIF_CSC_COEF_INTEG_SHIFT
) |
512 df_csc
->csc
.coeff
[i
].decimal
;
516 val2
= (df_csc
->csc
.coeff
[i
].integer
<<
517 ISIF_CSC_COEF_INTEG_SHIFT
) |
518 df_csc
->csc
.coeff
[i
].decimal
;
519 val2
<<= ISIF_CSCM_MSB_SHIFT
;
521 regw(val2
, (CSCM0
+ ((i
- 1) << 1)));
525 /* program the active area */
526 regw(df_csc
->start_pix
, FMTSPH
);
528 * one extra pixel as required for CSC. Actually number of
529 * pixel - 1 should be configured in this register. So we
530 * need to subtract 1 before writing to FMTSPH, but we will
531 * not do this since csc requires one extra pixel
533 regw(df_csc
->num_pixels
, FMTLNH
);
534 regw(df_csc
->start_line
, FMTSLV
);
536 * one extra line as required for CSC. See reason documented for
539 regw(df_csc
->num_lines
, FMTLNV
);
545 static int isif_config_raw(void)
547 struct isif_params_raw
*params
= &isif_cfg
.bayer
;
548 struct isif_config_params_raw
*module_params
=
549 &isif_cfg
.bayer
.config_params
;
550 struct vpss_pg_frame_size frame_size
;
551 struct vpss_sync_pol sync
;
554 dev_dbg(isif_cfg
.dev
, "\nStarting isif_config_raw..\n");
557 * Configure CCDCFG register:-
558 * Set CCD Not to swap input since input is RAW data
559 * Set FID detection function to Latch at V-Sync
560 * Set WENLOG - isif valid area
563 * Packed to 8 or 16 bits
566 val
= ISIF_YCINSWP_RAW
| ISIF_CCDCFG_FIDMD_LATCH_VSYNC
|
567 ISIF_CCDCFG_WENLOG_AND
| ISIF_CCDCFG_TRGSEL_WEN
|
568 ISIF_CCDCFG_EXTRG_DISABLE
| isif_cfg
.data_pack
;
570 dev_dbg(isif_cfg
.dev
, "Writing 0x%x to ...CCDCFG \n", val
);
574 * Configure the vertical sync polarity(MODESET.VDPOL)
575 * Configure the horizontal sync polarity (MODESET.HDPOL)
576 * Configure frame id polarity (MODESET.FLDPOL)
577 * Configure data polarity
578 * Configure External WEN Selection
579 * Configure frame format(progressive or interlace)
580 * Configure pixel format (Input mode)
581 * Configure the data shift
584 val
= ISIF_VDHDOUT_INPUT
| (params
->vd_pol
<< ISIF_VD_POL_SHIFT
) |
585 (params
->hd_pol
<< ISIF_HD_POL_SHIFT
) |
586 (params
->fid_pol
<< ISIF_FID_POL_SHIFT
) |
587 (ISIF_DATAPOL_NORMAL
<< ISIF_DATAPOL_SHIFT
) |
588 (ISIF_EXWEN_DISABLE
<< ISIF_EXWEN_SHIFT
) |
589 (params
->frm_fmt
<< ISIF_FRM_FMT_SHIFT
) |
590 (params
->pix_fmt
<< ISIF_INPUT_SHIFT
) |
591 (params
->config_params
.data_shift
<< ISIF_DATASFT_SHIFT
);
594 dev_dbg(isif_cfg
.dev
, "Writing 0x%x to MODESET...\n", val
);
597 * Configure GAMMAWD register
598 * CFA pattern setting
600 val
= params
->cfa_pat
<< ISIF_GAMMAWD_CFA_SHIFT
;
603 if (module_params
->compress
.alg
== ISIF_ALAW
)
604 val
|= ISIF_ALAW_ENABLE
;
606 val
|= (params
->data_msb
<< ISIF_ALAW_GAMA_WD_SHIFT
);
609 /* Configure DPCM compression settings */
610 if (module_params
->compress
.alg
== ISIF_DPCM
) {
611 val
= BIT(ISIF_DPCM_EN_SHIFT
) |
612 (module_params
->compress
.pred
<<
613 ISIF_DPCM_PREDICTOR_SHIFT
);
618 /* Configure Gain & Offset */
619 isif_config_gain_offset();
621 /* Configure Color pattern */
622 val
= (params
->config_params
.col_pat_field0
.olop
) |
623 (params
->config_params
.col_pat_field0
.olep
<< 2) |
624 (params
->config_params
.col_pat_field0
.elop
<< 4) |
625 (params
->config_params
.col_pat_field0
.elep
<< 6) |
626 (params
->config_params
.col_pat_field1
.olop
<< 8) |
627 (params
->config_params
.col_pat_field1
.olep
<< 10) |
628 (params
->config_params
.col_pat_field1
.elop
<< 12) |
629 (params
->config_params
.col_pat_field1
.elep
<< 14);
631 dev_dbg(isif_cfg
.dev
, "Writing %x to CCOLP ...\n", val
);
633 /* Configure HSIZE register */
634 val
= (!!params
->horz_flip_en
) << ISIF_HSIZE_FLIP_SHIFT
;
636 /* calculate line offset in 32 bytes based on pack value */
637 if (isif_cfg
.data_pack
== ISIF_PACK_8BIT
)
638 val
|= ((params
->win
.width
+ 31) >> 5);
639 else if (isif_cfg
.data_pack
== ISIF_PACK_12BIT
)
640 val
|= (((params
->win
.width
+
641 (params
->win
.width
>> 2)) + 31) >> 5);
643 val
|= (((params
->win
.width
* 2) + 31) >> 5);
646 /* Configure SDOFST register */
647 if (params
->frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
648 if (params
->image_invert_en
) {
649 /* For interlace inverse mode */
650 regw(0x4B6D, SDOFST
);
651 dev_dbg(isif_cfg
.dev
, "Writing 0x4B6D to SDOFST...\n");
653 /* For interlace non inverse mode */
654 regw(0x0B6D, SDOFST
);
655 dev_dbg(isif_cfg
.dev
, "Writing 0x0B6D to SDOFST...\n");
657 } else if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
) {
658 if (params
->image_invert_en
) {
659 /* For progressive inverse mode */
660 regw(0x4000, SDOFST
);
661 dev_dbg(isif_cfg
.dev
, "Writing 0x4000 to SDOFST...\n");
663 /* For progressive non inverse mode */
664 regw(0x0000, SDOFST
);
665 dev_dbg(isif_cfg
.dev
, "Writing 0x0000 to SDOFST...\n");
669 /* Configure video window */
670 isif_setwin(¶ms
->win
, params
->frm_fmt
, 1);
672 /* Configure Black Clamp */
673 isif_config_bclamp(&module_params
->bclamp
);
675 /* Configure Vertical Defection Pixel Correction */
676 if (isif_config_dfc(&module_params
->dfc
) < 0)
679 if (!module_params
->df_csc
.df_or_csc
)
680 /* Configure Color Space Conversion */
681 isif_config_csc(&module_params
->df_csc
);
683 isif_config_linearization(&module_params
->linearize
);
685 /* Configure Culling */
686 isif_config_culling(&module_params
->culling
);
688 /* Configure horizontal and vertical offsets(DFC,LSC,Gain) */
689 regw(module_params
->horz_offset
, DATAHOFST
);
690 regw(module_params
->vert_offset
, DATAVOFST
);
692 /* Setup test pattern if enabled */
693 if (params
->config_params
.test_pat_gen
) {
694 /* Use the HD/VD pol settings from user */
695 sync
.ccdpg_hdpol
= params
->hd_pol
;
696 sync
.ccdpg_vdpol
= params
->vd_pol
;
697 dm365_vpss_set_sync_pol(sync
);
698 frame_size
.hlpfr
= isif_cfg
.bayer
.win
.width
;
699 frame_size
.pplen
= isif_cfg
.bayer
.win
.height
;
700 dm365_vpss_set_pg_frame_size(frame_size
);
701 vpss_select_ccdc_source(VPSS_PGLPBK
);
704 dev_dbg(isif_cfg
.dev
, "\nEnd of isif_config_ycbcr...\n");
708 static int isif_set_buftype(enum ccdc_buftype buf_type
)
710 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
711 isif_cfg
.bayer
.buf_type
= buf_type
;
713 isif_cfg
.ycbcr
.buf_type
= buf_type
;
718 static enum ccdc_buftype
isif_get_buftype(void)
720 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
721 return isif_cfg
.bayer
.buf_type
;
723 return isif_cfg
.ycbcr
.buf_type
;
726 static int isif_enum_pix(u32
*pix
, int i
)
730 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
731 if (i
< ARRAY_SIZE(isif_raw_bayer_pix_formats
)) {
732 *pix
= isif_raw_bayer_pix_formats
[i
];
736 if (i
< ARRAY_SIZE(isif_raw_yuv_pix_formats
)) {
737 *pix
= isif_raw_yuv_pix_formats
[i
];
745 static int isif_set_pixel_format(unsigned int pixfmt
)
747 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
748 if (pixfmt
== V4L2_PIX_FMT_SBGGR8
) {
749 if ((isif_cfg
.bayer
.config_params
.compress
.alg
!=
751 (isif_cfg
.bayer
.config_params
.compress
.alg
!=
753 dev_dbg(isif_cfg
.dev
,
754 "Either configure A-Law or DPCM\n");
757 isif_cfg
.data_pack
= ISIF_PACK_8BIT
;
758 } else if (pixfmt
== V4L2_PIX_FMT_SBGGR16
) {
759 isif_cfg
.bayer
.config_params
.compress
.alg
=
761 isif_cfg
.data_pack
= ISIF_PACK_16BIT
;
764 isif_cfg
.bayer
.pix_fmt
= CCDC_PIXFMT_RAW
;
766 if (pixfmt
== V4L2_PIX_FMT_YUYV
)
767 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_YCBYCR
;
768 else if (pixfmt
== V4L2_PIX_FMT_UYVY
)
769 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
772 isif_cfg
.data_pack
= ISIF_PACK_8BIT
;
777 static u32
isif_get_pixel_format(void)
781 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
782 if (isif_cfg
.bayer
.config_params
.compress
.alg
== ISIF_ALAW
||
783 isif_cfg
.bayer
.config_params
.compress
.alg
== ISIF_DPCM
)
784 pixfmt
= V4L2_PIX_FMT_SBGGR8
;
786 pixfmt
= V4L2_PIX_FMT_SBGGR16
;
788 if (isif_cfg
.ycbcr
.pix_order
== CCDC_PIXORDER_YCBYCR
)
789 pixfmt
= V4L2_PIX_FMT_YUYV
;
791 pixfmt
= V4L2_PIX_FMT_UYVY
;
796 static int isif_set_image_window(struct v4l2_rect
*win
)
798 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
799 isif_cfg
.bayer
.win
.top
= win
->top
;
800 isif_cfg
.bayer
.win
.left
= win
->left
;
801 isif_cfg
.bayer
.win
.width
= win
->width
;
802 isif_cfg
.bayer
.win
.height
= win
->height
;
804 isif_cfg
.ycbcr
.win
.top
= win
->top
;
805 isif_cfg
.ycbcr
.win
.left
= win
->left
;
806 isif_cfg
.ycbcr
.win
.width
= win
->width
;
807 isif_cfg
.ycbcr
.win
.height
= win
->height
;
812 static void isif_get_image_window(struct v4l2_rect
*win
)
814 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
815 *win
= isif_cfg
.bayer
.win
;
817 *win
= isif_cfg
.ycbcr
.win
;
820 static unsigned int isif_get_line_length(void)
824 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
825 if (isif_cfg
.data_pack
== ISIF_PACK_8BIT
)
826 len
= ((isif_cfg
.bayer
.win
.width
));
827 else if (isif_cfg
.data_pack
== ISIF_PACK_12BIT
)
828 len
= (((isif_cfg
.bayer
.win
.width
* 2) +
829 (isif_cfg
.bayer
.win
.width
>> 2)));
831 len
= (((isif_cfg
.bayer
.win
.width
* 2)));
833 len
= (((isif_cfg
.ycbcr
.win
.width
* 2)));
834 return ALIGN(len
, 32);
837 static int isif_set_frame_format(enum ccdc_frmfmt frm_fmt
)
839 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
840 isif_cfg
.bayer
.frm_fmt
= frm_fmt
;
842 isif_cfg
.ycbcr
.frm_fmt
= frm_fmt
;
845 static enum ccdc_frmfmt
isif_get_frame_format(void)
847 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
848 return isif_cfg
.bayer
.frm_fmt
;
849 return isif_cfg
.ycbcr
.frm_fmt
;
852 static int isif_getfid(void)
854 return (regr(MODESET
) >> 15) & 0x1;
857 /* misc operations */
858 static void isif_setfbaddr(unsigned long addr
)
860 regw((addr
>> 21) & 0x07ff, CADU
);
861 regw((addr
>> 5) & 0x0ffff, CADL
);
864 static int isif_set_hw_if_params(struct vpfe_hw_if_param
*params
)
866 isif_cfg
.if_type
= params
->if_type
;
868 switch (params
->if_type
) {
870 case VPFE_BT656_10BIT
:
871 case VPFE_YCBCR_SYNC_8
:
872 isif_cfg
.ycbcr
.pix_fmt
= CCDC_PIXFMT_YCBCR_8BIT
;
873 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
876 case VPFE_YCBCR_SYNC_16
:
877 isif_cfg
.ycbcr
.pix_fmt
= CCDC_PIXFMT_YCBCR_16BIT
;
878 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
881 isif_cfg
.bayer
.pix_fmt
= CCDC_PIXFMT_RAW
;
884 dev_dbg(isif_cfg
.dev
, "Invalid interface type\n");
891 /* This function will configure ISIF for YCbCr parameters. */
892 static int isif_config_ycbcr(void)
894 struct isif_ycbcr_config
*params
= &isif_cfg
.ycbcr
;
895 struct vpss_pg_frame_size frame_size
;
896 u32 modeset
= 0, ccdcfg
= 0;
897 struct vpss_sync_pol sync
;
899 dev_dbg(isif_cfg
.dev
, "\nStarting isif_config_ycbcr...");
901 /* configure pixel format or input mode */
902 modeset
= modeset
| (params
->pix_fmt
<< ISIF_INPUT_SHIFT
) |
903 (params
->frm_fmt
<< ISIF_FRM_FMT_SHIFT
) |
904 (params
->fid_pol
<< ISIF_FID_POL_SHIFT
) |
905 (params
->hd_pol
<< ISIF_HD_POL_SHIFT
) |
906 (params
->vd_pol
<< ISIF_VD_POL_SHIFT
);
908 /* pack the data to 8-bit ISIFCFG */
909 switch (isif_cfg
.if_type
) {
911 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_8BIT
) {
912 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
915 modeset
|= (VPFE_PINPOL_NEGATIVE
<< ISIF_VD_POL_SHIFT
);
917 ccdcfg
= ccdcfg
| ISIF_DATA_PACK8
| ISIF_YCINSWP_YCBCR
;
919 case VPFE_BT656_10BIT
:
920 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_8BIT
) {
921 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
924 /* setup BT.656, embedded sync */
926 /* enable 10 bit mode in ccdcfg */
927 ccdcfg
= ccdcfg
| ISIF_DATA_PACK8
| ISIF_YCINSWP_YCBCR
|
931 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_16BIT
) {
932 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
938 case VPFE_YCBCR_SYNC_8
:
939 ccdcfg
|= ISIF_DATA_PACK8
;
940 ccdcfg
|= ISIF_YCINSWP_YCBCR
;
941 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_8BIT
) {
942 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
946 case VPFE_YCBCR_SYNC_16
:
947 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_16BIT
) {
948 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
953 /* should never come here */
954 dev_dbg(isif_cfg
.dev
, "Invalid interface type\n");
958 regw(modeset
, MODESET
);
960 /* Set up pix order */
961 ccdcfg
|= params
->pix_order
<< ISIF_PIX_ORDER_SHIFT
;
963 regw(ccdcfg
, CCDCFG
);
965 /* configure video window */
966 if ((isif_cfg
.if_type
== VPFE_BT1120
) ||
967 (isif_cfg
.if_type
== VPFE_YCBCR_SYNC_16
))
968 isif_setwin(¶ms
->win
, params
->frm_fmt
, 1);
970 isif_setwin(¶ms
->win
, params
->frm_fmt
, 2);
973 * configure the horizontal line offset
974 * this is done by rounding up width to a multiple of 16 pixels
975 * and multiply by two to account for y:cb:cr 4:2:2 data
977 regw(((((params
->win
.width
* 2) + 31) & 0xffffffe0) >> 5), HSIZE
);
979 /* configure the memory line offset */
980 if ((params
->frm_fmt
== CCDC_FRMFMT_INTERLACED
) &&
981 (params
->buf_type
== CCDC_BUFTYPE_FLD_INTERLEAVED
))
982 /* two fields are interleaved in memory */
983 regw(0x00000249, SDOFST
);
985 /* Setup test pattern if enabled */
986 if (isif_cfg
.bayer
.config_params
.test_pat_gen
) {
987 sync
.ccdpg_hdpol
= params
->hd_pol
;
988 sync
.ccdpg_vdpol
= params
->vd_pol
;
989 dm365_vpss_set_sync_pol(sync
);
990 dm365_vpss_set_pg_frame_size(frame_size
);
995 static int isif_configure(void)
997 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
998 return isif_config_raw();
999 return isif_config_ycbcr();
1002 static int isif_close(struct device
*device
)
1004 /* copy defaults to module params */
1005 isif_cfg
.bayer
.config_params
= isif_config_defaults
;
1009 static struct ccdc_hw_device isif_hw_dev
= {
1011 .owner
= THIS_MODULE
,
1014 .close
= isif_close
,
1015 .enable
= isif_enable
,
1016 .enable_out_to_sdram
= isif_enable_output_to_sdram
,
1017 .set_hw_if_params
= isif_set_hw_if_params
,
1018 .configure
= isif_configure
,
1019 .set_buftype
= isif_set_buftype
,
1020 .get_buftype
= isif_get_buftype
,
1021 .enum_pix
= isif_enum_pix
,
1022 .set_pixel_format
= isif_set_pixel_format
,
1023 .get_pixel_format
= isif_get_pixel_format
,
1024 .set_frame_format
= isif_set_frame_format
,
1025 .get_frame_format
= isif_get_frame_format
,
1026 .set_image_window
= isif_set_image_window
,
1027 .get_image_window
= isif_get_image_window
,
1028 .get_line_length
= isif_get_line_length
,
1029 .setfbaddr
= isif_setfbaddr
,
1030 .getfid
= isif_getfid
,
1034 static int __init
isif_probe(struct platform_device
*pdev
)
1036 void (*setup_pinmux
)(void);
1037 struct resource
*res
;
1042 * first try to register with vpfe. If not correct platform, then we
1043 * don't have to iomap
1045 status
= vpfe_register_ccdc_device(&isif_hw_dev
);
1049 /* Get and enable Master clock */
1050 isif_cfg
.mclk
= clk_get(&pdev
->dev
, "master");
1051 if (IS_ERR(isif_cfg
.mclk
)) {
1052 status
= PTR_ERR(isif_cfg
.mclk
);
1055 if (clk_enable(isif_cfg
.mclk
)) {
1060 /* Platform data holds setup_pinmux function ptr */
1061 if (NULL
== pdev
->dev
.platform_data
) {
1065 setup_pinmux
= pdev
->dev
.platform_data
;
1067 * setup Mux configuration for ccdc which may be different for
1068 * different SoCs using this CCDC
1073 /* Get the ISIF base address, linearization table0 and table1 addr. */
1075 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, i
);
1078 goto fail_nobase_res
;
1080 res
= request_mem_region(res
->start
, resource_size(res
),
1084 goto fail_nobase_res
;
1086 addr
= ioremap_nocache(res
->start
, resource_size(res
));
1089 goto fail_base_iomap
;
1093 /* ISIF base address */
1094 isif_cfg
.base_addr
= addr
;
1097 /* ISIF linear tbl0 address */
1098 isif_cfg
.linear_tbl0_addr
= addr
;
1101 /* ISIF linear tbl0 address */
1102 isif_cfg
.linear_tbl1_addr
= addr
;
1107 isif_cfg
.dev
= &pdev
->dev
;
1109 printk(KERN_NOTICE
"%s is registered with vpfe.\n",
1113 release_mem_region(res
->start
, resource_size(res
));
1116 if (isif_cfg
.base_addr
)
1117 iounmap(isif_cfg
.base_addr
);
1118 if (isif_cfg
.linear_tbl0_addr
)
1119 iounmap(isif_cfg
.linear_tbl0_addr
);
1122 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, i
);
1123 release_mem_region(res
->start
, resource_size(res
));
1127 clk_put(isif_cfg
.mclk
);
1128 vpfe_unregister_ccdc_device(&isif_hw_dev
);
1132 static int isif_remove(struct platform_device
*pdev
)
1134 struct resource
*res
;
1137 iounmap(isif_cfg
.base_addr
);
1138 iounmap(isif_cfg
.linear_tbl0_addr
);
1139 iounmap(isif_cfg
.linear_tbl1_addr
);
1141 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, i
);
1143 release_mem_region(res
->start
, resource_size(res
));
1146 vpfe_unregister_ccdc_device(&isif_hw_dev
);
1150 static struct platform_driver isif_driver
= {
1153 .owner
= THIS_MODULE
,
1155 .remove
= __devexit_p(isif_remove
),
1156 .probe
= isif_probe
,
1159 static int __init
isif_init(void)
1161 return platform_driver_register(&isif_driver
);
1164 static void isif_exit(void)
1166 platform_driver_unregister(&isif_driver
);
1169 module_init(isif_init
);
1170 module_exit(isif_exit
);
1172 MODULE_LICENSE("GPL");