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/err.h>
36 #include <linux/module.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
;
90 /* ISIF base address */
91 void __iomem
*base_addr
;
92 /* ISIF Linear Table 0 */
93 void __iomem
*linear_tbl0_addr
;
94 /* ISIF Linear Table 1 */
95 void __iomem
*linear_tbl1_addr
;
98 .pix_fmt
= CCDC_PIXFMT_YCBCR_8BIT
,
99 .frm_fmt
= CCDC_FRMFMT_INTERLACED
,
100 .win
= ISIF_WIN_NTSC
,
101 .fid_pol
= VPFE_PINPOL_POSITIVE
,
102 .vd_pol
= VPFE_PINPOL_POSITIVE
,
103 .hd_pol
= VPFE_PINPOL_POSITIVE
,
104 .pix_order
= CCDC_PIXORDER_CBYCRY
,
105 .buf_type
= CCDC_BUFTYPE_FLD_INTERLEAVED
,
108 .pix_fmt
= CCDC_PIXFMT_RAW
,
109 .frm_fmt
= CCDC_FRMFMT_PROGRESSIVE
,
111 .fid_pol
= VPFE_PINPOL_POSITIVE
,
112 .vd_pol
= VPFE_PINPOL_POSITIVE
,
113 .hd_pol
= VPFE_PINPOL_POSITIVE
,
120 .cfa_pat
= ISIF_CFA_PAT_MOSAIC
,
121 .data_msb
= ISIF_BIT_MSB_11
,
123 .data_shift
= ISIF_NO_SHIFT
,
125 .olop
= ISIF_GREEN_BLUE
,
128 .elep
= ISIF_GREEN_RED
,
131 .olop
= ISIF_GREEN_BLUE
,
134 .elep
= ISIF_GREEN_RED
,
139 .data_pack
= ISIF_DATA_PACK8
,
142 /* Raw Bayer formats */
143 static const u32 isif_raw_bayer_pix_formats
[] = {
144 V4L2_PIX_FMT_SBGGR8
, V4L2_PIX_FMT_SBGGR16
};
146 /* Raw YUV formats */
147 static const u32 isif_raw_yuv_pix_formats
[] = {
148 V4L2_PIX_FMT_UYVY
, V4L2_PIX_FMT_YUYV
};
150 /* register access routines */
151 static inline u32
regr(u32 offset
)
153 return __raw_readl(isif_cfg
.base_addr
+ offset
);
156 static inline void regw(u32 val
, u32 offset
)
158 __raw_writel(val
, isif_cfg
.base_addr
+ offset
);
161 /* reg_modify() - read, modify and write register */
162 static inline u32
reg_modify(u32 mask
, u32 val
, u32 offset
)
164 u32 new_val
= (regr(offset
) & ~mask
) | (val
& mask
);
166 regw(new_val
, offset
);
170 static inline void regw_lin_tbl(u32 val
, u32 offset
, int i
)
173 __raw_writel(val
, isif_cfg
.linear_tbl0_addr
+ offset
);
175 __raw_writel(val
, isif_cfg
.linear_tbl1_addr
+ offset
);
178 static void isif_disable_all_modules(void)
186 /* disable linearization */
188 /* disable other modules here as they are supported */
191 static void isif_enable(int en
)
194 /* Before disable isif, disable all ISIF modules */
195 isif_disable_all_modules();
197 * wait for next VD. Assume lowest scan rate is 12 Hz. So
198 * 100 msec delay is good enough
202 reg_modify(ISIF_SYNCEN_VDHDEN_MASK
, en
, SYNCEN
);
205 static void isif_enable_output_to_sdram(int en
)
207 reg_modify(ISIF_SYNCEN_WEN_MASK
, en
<< ISIF_SYNCEN_WEN_SHIFT
, SYNCEN
);
210 static void isif_config_culling(struct isif_cul
*cul
)
214 /* Horizontal pattern */
215 val
= (cul
->hcpat_even
<< CULL_PAT_EVEN_LINE_SHIFT
) | cul
->hcpat_odd
;
218 /* vertical pattern */
219 regw(cul
->vcpat
, CULV
);
222 reg_modify(ISIF_LPF_MASK
<< ISIF_LPF_SHIFT
,
223 cul
->en_lpf
<< ISIF_LPF_SHIFT
, MODESET
);
226 static void isif_config_gain_offset(void)
228 struct isif_gain_offsets_adj
*gain_off_p
=
229 &isif_cfg
.bayer
.config_params
.gain_offset
;
232 val
= (!!gain_off_p
->gain_sdram_en
<< GAIN_SDRAM_EN_SHIFT
) |
233 (!!gain_off_p
->gain_ipipe_en
<< GAIN_IPIPE_EN_SHIFT
) |
234 (!!gain_off_p
->gain_h3a_en
<< GAIN_H3A_EN_SHIFT
) |
235 (!!gain_off_p
->offset_sdram_en
<< OFST_SDRAM_EN_SHIFT
) |
236 (!!gain_off_p
->offset_ipipe_en
<< OFST_IPIPE_EN_SHIFT
) |
237 (!!gain_off_p
->offset_h3a_en
<< OFST_H3A_EN_SHIFT
);
239 reg_modify(GAIN_OFFSET_EN_MASK
, val
, CGAMMAWD
);
241 val
= (gain_off_p
->gain
.r_ye
.integer
<< GAIN_INTEGER_SHIFT
) |
242 gain_off_p
->gain
.r_ye
.decimal
;
245 val
= (gain_off_p
->gain
.gr_cy
.integer
<< GAIN_INTEGER_SHIFT
) |
246 gain_off_p
->gain
.gr_cy
.decimal
;
249 val
= (gain_off_p
->gain
.gb_g
.integer
<< GAIN_INTEGER_SHIFT
) |
250 gain_off_p
->gain
.gb_g
.decimal
;
253 val
= (gain_off_p
->gain
.b_mg
.integer
<< GAIN_INTEGER_SHIFT
) |
254 gain_off_p
->gain
.b_mg
.decimal
;
257 regw(gain_off_p
->offset
, COFSTA
);
260 static void isif_restore_defaults(void)
262 enum vpss_ccdc_source_sel source
= VPSS_CCDCIN
;
264 dev_dbg(isif_cfg
.dev
, "\nstarting isif_restore_defaults...");
265 isif_cfg
.bayer
.config_params
= isif_config_defaults
;
266 /* Enable clock to ISIF, IPIPEIF and BL */
267 vpss_enable_clock(VPSS_CCDC_CLOCK
, 1);
268 vpss_enable_clock(VPSS_IPIPEIF_CLOCK
, 1);
269 vpss_enable_clock(VPSS_BL_CLOCK
, 1);
270 /* Set default offset and gain */
271 isif_config_gain_offset();
272 vpss_select_ccdc_source(source
);
273 dev_dbg(isif_cfg
.dev
, "\nEnd of isif_restore_defaults...");
276 static int isif_open(struct device
*device
)
278 isif_restore_defaults();
282 /* This function will configure the window size to be capture in ISIF reg */
283 static void isif_setwin(struct v4l2_rect
*image_win
,
284 enum ccdc_frmfmt frm_fmt
, int ppc
)
286 int horz_start
, horz_nr_pixels
;
287 int vert_start
, vert_nr_lines
;
290 dev_dbg(isif_cfg
.dev
, "\nStarting isif_setwin...");
292 * ppc - per pixel count. indicates how many pixels per cell
293 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
294 * raw capture this is 1
296 horz_start
= image_win
->left
<< (ppc
- 1);
297 horz_nr_pixels
= ((image_win
->width
) << (ppc
- 1)) - 1;
299 /* Writing the horizontal info into the registers */
300 regw(horz_start
& START_PX_HOR_MASK
, SPH
);
301 regw(horz_nr_pixels
& NUM_PX_HOR_MASK
, LNH
);
302 vert_start
= image_win
->top
;
304 if (frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
305 vert_nr_lines
= (image_win
->height
>> 1) - 1;
307 /* To account for VD since line 0 doesn't have any data */
310 /* To account for VD since line 0 doesn't have any data */
312 vert_nr_lines
= image_win
->height
- 1;
313 /* configure VDINT0 and VDINT1 */
314 mid_img
= vert_start
+ (image_win
->height
/ 2);
315 regw(mid_img
, VDINT1
);
319 regw(vert_start
& START_VER_ONE_MASK
, SLV0
);
320 regw(vert_start
& START_VER_TWO_MASK
, SLV1
);
321 regw(vert_nr_lines
& NUM_LINES_VER
, LNV
);
324 static void isif_config_bclamp(struct isif_black_clamp
*bc
)
329 * DC Offset is always added to image data irrespective of bc enable
332 regw(bc
->dc_offset
, CLDCOFST
);
335 val
= bc
->bc_mode_color
<< ISIF_BC_MODE_COLOR_SHIFT
;
337 /* Enable BC and horizontal clamp caculation paramaters */
338 val
= val
| 1 | (bc
->horz
.mode
<< ISIF_HORZ_BC_MODE_SHIFT
);
342 if (bc
->horz
.mode
!= ISIF_HORZ_BC_DISABLE
) {
344 * Window count for calculation
345 * Base window selection
347 * Horizontal size of window
348 * vertical size of the window
349 * Horizontal start position of the window
350 * Vertical start position of the window
352 val
= bc
->horz
.win_count_calc
|
353 ((!!bc
->horz
.base_win_sel_calc
) <<
354 ISIF_HORZ_BC_WIN_SEL_SHIFT
) |
355 ((!!bc
->horz
.clamp_pix_limit
) <<
356 ISIF_HORZ_BC_PIX_LIMIT_SHIFT
) |
357 (bc
->horz
.win_h_sz_calc
<<
358 ISIF_HORZ_BC_WIN_H_SIZE_SHIFT
) |
359 (bc
->horz
.win_v_sz_calc
<<
360 ISIF_HORZ_BC_WIN_V_SIZE_SHIFT
);
363 regw(bc
->horz
.win_start_h_calc
, CLHWIN1
);
364 regw(bc
->horz
.win_start_v_calc
, CLHWIN2
);
367 /* vertical clamp caculation paramaters */
369 /* Reset clamp value sel for previous line */
371 (bc
->vert
.reset_val_sel
<< ISIF_VERT_BC_RST_VAL_SEL_SHIFT
) |
372 (bc
->vert
.line_ave_coef
<< ISIF_VERT_BC_LINE_AVE_COEF_SHIFT
);
375 /* Optical Black horizontal start position */
376 regw(bc
->vert
.ob_start_h
, CLVWIN1
);
377 /* Optical Black vertical start position */
378 regw(bc
->vert
.ob_start_v
, CLVWIN2
);
379 /* Optical Black vertical size for calculation */
380 regw(bc
->vert
.ob_v_sz_calc
, CLVWIN3
);
381 /* Vertical start position for BC subtraction */
382 regw(bc
->vert_start_sub
, CLSV
);
386 static void isif_config_linearization(struct isif_linearize
*linearize
)
390 if (!linearize
->en
) {
395 /* shift value for correction & enable linearization (set lsb) */
396 val
= (linearize
->corr_shft
<< ISIF_LIN_CORRSFT_SHIFT
) | 1;
400 val
= ((!!linearize
->scale_fact
.integer
) <<
401 ISIF_LIN_SCALE_FACT_INTEG_SHIFT
) |
402 linearize
->scale_fact
.decimal
;
405 for (i
= 0; i
< ISIF_LINEAR_TAB_SIZE
; i
++) {
407 regw_lin_tbl(linearize
->table
[i
], ((i
>> 1) << 2), 1);
409 regw_lin_tbl(linearize
->table
[i
], ((i
>> 1) << 2), 0);
413 static int isif_config_dfc(struct isif_dfc
*vdfc
)
415 /* initialize retries to loop for max ~ 250 usec */
416 u32 val
, count
, retries
= loops_per_jiffy
/ (4000/HZ
);
422 /* Correction mode */
423 val
= (vdfc
->corr_mode
<< ISIF_VDFC_CORR_MOD_SHIFT
);
425 /* Correct whole line or partial */
426 if (vdfc
->corr_whole_line
)
427 val
|= 1 << ISIF_VDFC_CORR_WHOLE_LN_SHIFT
;
429 /* level shift value */
430 val
|= vdfc
->def_level_shift
<< ISIF_VDFC_LEVEL_SHFT_SHIFT
;
434 /* Defect saturation level */
435 regw(vdfc
->def_sat_level
, VDFSATLV
);
437 regw(vdfc
->table
[0].pos_vert
, DFCMEM0
);
438 regw(vdfc
->table
[0].pos_horz
, DFCMEM1
);
439 if (vdfc
->corr_mode
== ISIF_VDFC_NORMAL
||
440 vdfc
->corr_mode
== ISIF_VDFC_HORZ_INTERPOL_IF_SAT
) {
441 regw(vdfc
->table
[0].level_at_pos
, DFCMEM2
);
442 regw(vdfc
->table
[0].level_up_pixels
, DFCMEM3
);
443 regw(vdfc
->table
[0].level_low_pixels
, DFCMEM4
);
446 /* set DFCMARST and set DFCMWR */
447 val
= regr(DFCMEMCTL
) | (1 << ISIF_DFCMEMCTL_DFCMARST_SHIFT
) | 1;
448 regw(val
, DFCMEMCTL
);
451 while (count
&& (regr(DFCMEMCTL
) & 0x1))
455 dev_dbg(isif_cfg
.dev
, "defect table write timeout !!!\n");
459 for (i
= 1; i
< vdfc
->num_vdefects
; i
++) {
460 regw(vdfc
->table
[i
].pos_vert
, DFCMEM0
);
461 regw(vdfc
->table
[i
].pos_horz
, DFCMEM1
);
462 if (vdfc
->corr_mode
== ISIF_VDFC_NORMAL
||
463 vdfc
->corr_mode
== ISIF_VDFC_HORZ_INTERPOL_IF_SAT
) {
464 regw(vdfc
->table
[i
].level_at_pos
, DFCMEM2
);
465 regw(vdfc
->table
[i
].level_up_pixels
, DFCMEM3
);
466 regw(vdfc
->table
[i
].level_low_pixels
, DFCMEM4
);
468 val
= regr(DFCMEMCTL
);
469 /* clear DFCMARST and set DFCMWR */
470 val
&= ~BIT(ISIF_DFCMEMCTL_DFCMARST_SHIFT
);
472 regw(val
, DFCMEMCTL
);
475 while (count
&& (regr(DFCMEMCTL
) & 0x1))
479 dev_err(isif_cfg
.dev
,
480 "defect table write timeout !!!\n");
484 if (vdfc
->num_vdefects
< ISIF_VDFC_TABLE_SIZE
) {
485 /* Extra cycle needed */
487 regw(0x1FFF, DFCMEM1
);
492 reg_modify((1 << ISIF_VDFC_EN_SHIFT
), (1 << ISIF_VDFC_EN_SHIFT
),
497 static void isif_config_csc(struct isif_df_csc
*df_csc
)
499 u32 val1
= 0, val2
= 0, i
;
501 if (!df_csc
->csc
.en
) {
505 for (i
= 0; i
< ISIF_CSC_NUM_COEFF
; i
++) {
508 val1
= (df_csc
->csc
.coeff
[i
].integer
<<
509 ISIF_CSC_COEF_INTEG_SHIFT
) |
510 df_csc
->csc
.coeff
[i
].decimal
;
514 val2
= (df_csc
->csc
.coeff
[i
].integer
<<
515 ISIF_CSC_COEF_INTEG_SHIFT
) |
516 df_csc
->csc
.coeff
[i
].decimal
;
517 val2
<<= ISIF_CSCM_MSB_SHIFT
;
519 regw(val2
, (CSCM0
+ ((i
- 1) << 1)));
523 /* program the active area */
524 regw(df_csc
->start_pix
, FMTSPH
);
526 * one extra pixel as required for CSC. Actually number of
527 * pixel - 1 should be configured in this register. So we
528 * need to subtract 1 before writing to FMTSPH, but we will
529 * not do this since csc requires one extra pixel
531 regw(df_csc
->num_pixels
, FMTLNH
);
532 regw(df_csc
->start_line
, FMTSLV
);
534 * one extra line as required for CSC. See reason documented for
537 regw(df_csc
->num_lines
, FMTLNV
);
543 static int isif_config_raw(void)
545 struct isif_params_raw
*params
= &isif_cfg
.bayer
;
546 struct isif_config_params_raw
*module_params
=
547 &isif_cfg
.bayer
.config_params
;
548 struct vpss_pg_frame_size frame_size
;
549 struct vpss_sync_pol sync
;
552 dev_dbg(isif_cfg
.dev
, "\nStarting isif_config_raw..\n");
555 * Configure CCDCFG register:-
556 * Set CCD Not to swap input since input is RAW data
557 * Set FID detection function to Latch at V-Sync
558 * Set WENLOG - isif valid area
561 * Packed to 8 or 16 bits
564 val
= ISIF_YCINSWP_RAW
| ISIF_CCDCFG_FIDMD_LATCH_VSYNC
|
565 ISIF_CCDCFG_WENLOG_AND
| ISIF_CCDCFG_TRGSEL_WEN
|
566 ISIF_CCDCFG_EXTRG_DISABLE
| isif_cfg
.data_pack
;
568 dev_dbg(isif_cfg
.dev
, "Writing 0x%x to ...CCDCFG \n", val
);
572 * Configure the vertical sync polarity(MODESET.VDPOL)
573 * Configure the horizontal sync polarity (MODESET.HDPOL)
574 * Configure frame id polarity (MODESET.FLDPOL)
575 * Configure data polarity
576 * Configure External WEN Selection
577 * Configure frame format(progressive or interlace)
578 * Configure pixel format (Input mode)
579 * Configure the data shift
582 val
= ISIF_VDHDOUT_INPUT
| (params
->vd_pol
<< ISIF_VD_POL_SHIFT
) |
583 (params
->hd_pol
<< ISIF_HD_POL_SHIFT
) |
584 (params
->fid_pol
<< ISIF_FID_POL_SHIFT
) |
585 (ISIF_DATAPOL_NORMAL
<< ISIF_DATAPOL_SHIFT
) |
586 (ISIF_EXWEN_DISABLE
<< ISIF_EXWEN_SHIFT
) |
587 (params
->frm_fmt
<< ISIF_FRM_FMT_SHIFT
) |
588 (params
->pix_fmt
<< ISIF_INPUT_SHIFT
) |
589 (params
->config_params
.data_shift
<< ISIF_DATASFT_SHIFT
);
592 dev_dbg(isif_cfg
.dev
, "Writing 0x%x to MODESET...\n", val
);
595 * Configure GAMMAWD register
596 * CFA pattern setting
598 val
= params
->cfa_pat
<< ISIF_GAMMAWD_CFA_SHIFT
;
601 if (module_params
->compress
.alg
== ISIF_ALAW
)
602 val
|= ISIF_ALAW_ENABLE
;
604 val
|= (params
->data_msb
<< ISIF_ALAW_GAMMA_WD_SHIFT
);
607 /* Configure DPCM compression settings */
608 if (module_params
->compress
.alg
== ISIF_DPCM
) {
609 val
= BIT(ISIF_DPCM_EN_SHIFT
) |
610 (module_params
->compress
.pred
<<
611 ISIF_DPCM_PREDICTOR_SHIFT
);
616 /* Configure Gain & Offset */
617 isif_config_gain_offset();
619 /* Configure Color pattern */
620 val
= (params
->config_params
.col_pat_field0
.olop
) |
621 (params
->config_params
.col_pat_field0
.olep
<< 2) |
622 (params
->config_params
.col_pat_field0
.elop
<< 4) |
623 (params
->config_params
.col_pat_field0
.elep
<< 6) |
624 (params
->config_params
.col_pat_field1
.olop
<< 8) |
625 (params
->config_params
.col_pat_field1
.olep
<< 10) |
626 (params
->config_params
.col_pat_field1
.elop
<< 12) |
627 (params
->config_params
.col_pat_field1
.elep
<< 14);
629 dev_dbg(isif_cfg
.dev
, "Writing %x to CCOLP ...\n", val
);
631 /* Configure HSIZE register */
632 val
= (!!params
->horz_flip_en
) << ISIF_HSIZE_FLIP_SHIFT
;
634 /* calculate line offset in 32 bytes based on pack value */
635 if (isif_cfg
.data_pack
== ISIF_PACK_8BIT
)
636 val
|= ((params
->win
.width
+ 31) >> 5);
637 else if (isif_cfg
.data_pack
== ISIF_PACK_12BIT
)
638 val
|= (((params
->win
.width
+
639 (params
->win
.width
>> 2)) + 31) >> 5);
641 val
|= (((params
->win
.width
* 2) + 31) >> 5);
644 /* Configure SDOFST register */
645 if (params
->frm_fmt
== CCDC_FRMFMT_INTERLACED
) {
646 if (params
->image_invert_en
) {
647 /* For interlace inverse mode */
648 regw(0x4B6D, SDOFST
);
649 dev_dbg(isif_cfg
.dev
, "Writing 0x4B6D to SDOFST...\n");
651 /* For interlace non inverse mode */
652 regw(0x0B6D, SDOFST
);
653 dev_dbg(isif_cfg
.dev
, "Writing 0x0B6D to SDOFST...\n");
655 } else if (params
->frm_fmt
== CCDC_FRMFMT_PROGRESSIVE
) {
656 if (params
->image_invert_en
) {
657 /* For progressive inverse mode */
658 regw(0x4000, SDOFST
);
659 dev_dbg(isif_cfg
.dev
, "Writing 0x4000 to SDOFST...\n");
661 /* For progressive non inverse mode */
662 regw(0x0000, SDOFST
);
663 dev_dbg(isif_cfg
.dev
, "Writing 0x0000 to SDOFST...\n");
667 /* Configure video window */
668 isif_setwin(¶ms
->win
, params
->frm_fmt
, 1);
670 /* Configure Black Clamp */
671 isif_config_bclamp(&module_params
->bclamp
);
673 /* Configure Vertical Defection Pixel Correction */
674 if (isif_config_dfc(&module_params
->dfc
) < 0)
677 if (!module_params
->df_csc
.df_or_csc
)
678 /* Configure Color Space Conversion */
679 isif_config_csc(&module_params
->df_csc
);
681 isif_config_linearization(&module_params
->linearize
);
683 /* Configure Culling */
684 isif_config_culling(&module_params
->culling
);
686 /* Configure horizontal and vertical offsets(DFC,LSC,Gain) */
687 regw(module_params
->horz_offset
, DATAHOFST
);
688 regw(module_params
->vert_offset
, DATAVOFST
);
690 /* Setup test pattern if enabled */
691 if (params
->config_params
.test_pat_gen
) {
692 /* Use the HD/VD pol settings from user */
693 sync
.ccdpg_hdpol
= params
->hd_pol
;
694 sync
.ccdpg_vdpol
= params
->vd_pol
;
695 dm365_vpss_set_sync_pol(sync
);
696 frame_size
.hlpfr
= isif_cfg
.bayer
.win
.width
;
697 frame_size
.pplen
= isif_cfg
.bayer
.win
.height
;
698 dm365_vpss_set_pg_frame_size(frame_size
);
699 vpss_select_ccdc_source(VPSS_PGLPBK
);
702 dev_dbg(isif_cfg
.dev
, "\nEnd of isif_config_ycbcr...\n");
706 static int isif_set_buftype(enum ccdc_buftype buf_type
)
708 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
709 isif_cfg
.bayer
.buf_type
= buf_type
;
711 isif_cfg
.ycbcr
.buf_type
= buf_type
;
716 static enum ccdc_buftype
isif_get_buftype(void)
718 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
719 return isif_cfg
.bayer
.buf_type
;
721 return isif_cfg
.ycbcr
.buf_type
;
724 static int isif_enum_pix(u32
*pix
, int i
)
728 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
729 if (i
< ARRAY_SIZE(isif_raw_bayer_pix_formats
)) {
730 *pix
= isif_raw_bayer_pix_formats
[i
];
734 if (i
< ARRAY_SIZE(isif_raw_yuv_pix_formats
)) {
735 *pix
= isif_raw_yuv_pix_formats
[i
];
743 static int isif_set_pixel_format(unsigned int pixfmt
)
745 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
746 if (pixfmt
== V4L2_PIX_FMT_SBGGR8
) {
747 if ((isif_cfg
.bayer
.config_params
.compress
.alg
!=
749 (isif_cfg
.bayer
.config_params
.compress
.alg
!=
751 dev_dbg(isif_cfg
.dev
,
752 "Either configure A-Law or DPCM\n");
755 isif_cfg
.data_pack
= ISIF_PACK_8BIT
;
756 } else if (pixfmt
== V4L2_PIX_FMT_SBGGR16
) {
757 isif_cfg
.bayer
.config_params
.compress
.alg
=
759 isif_cfg
.data_pack
= ISIF_PACK_16BIT
;
762 isif_cfg
.bayer
.pix_fmt
= CCDC_PIXFMT_RAW
;
764 if (pixfmt
== V4L2_PIX_FMT_YUYV
)
765 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_YCBYCR
;
766 else if (pixfmt
== V4L2_PIX_FMT_UYVY
)
767 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
770 isif_cfg
.data_pack
= ISIF_PACK_8BIT
;
775 static u32
isif_get_pixel_format(void)
779 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
780 if (isif_cfg
.bayer
.config_params
.compress
.alg
== ISIF_ALAW
||
781 isif_cfg
.bayer
.config_params
.compress
.alg
== ISIF_DPCM
)
782 pixfmt
= V4L2_PIX_FMT_SBGGR8
;
784 pixfmt
= V4L2_PIX_FMT_SBGGR16
;
786 if (isif_cfg
.ycbcr
.pix_order
== CCDC_PIXORDER_YCBYCR
)
787 pixfmt
= V4L2_PIX_FMT_YUYV
;
789 pixfmt
= V4L2_PIX_FMT_UYVY
;
794 static int isif_set_image_window(struct v4l2_rect
*win
)
796 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
797 isif_cfg
.bayer
.win
.top
= win
->top
;
798 isif_cfg
.bayer
.win
.left
= win
->left
;
799 isif_cfg
.bayer
.win
.width
= win
->width
;
800 isif_cfg
.bayer
.win
.height
= win
->height
;
802 isif_cfg
.ycbcr
.win
.top
= win
->top
;
803 isif_cfg
.ycbcr
.win
.left
= win
->left
;
804 isif_cfg
.ycbcr
.win
.width
= win
->width
;
805 isif_cfg
.ycbcr
.win
.height
= win
->height
;
810 static void isif_get_image_window(struct v4l2_rect
*win
)
812 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
813 *win
= isif_cfg
.bayer
.win
;
815 *win
= isif_cfg
.ycbcr
.win
;
818 static unsigned int isif_get_line_length(void)
822 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
) {
823 if (isif_cfg
.data_pack
== ISIF_PACK_8BIT
)
824 len
= ((isif_cfg
.bayer
.win
.width
));
825 else if (isif_cfg
.data_pack
== ISIF_PACK_12BIT
)
826 len
= (((isif_cfg
.bayer
.win
.width
* 2) +
827 (isif_cfg
.bayer
.win
.width
>> 2)));
829 len
= (((isif_cfg
.bayer
.win
.width
* 2)));
831 len
= (((isif_cfg
.ycbcr
.win
.width
* 2)));
832 return ALIGN(len
, 32);
835 static int isif_set_frame_format(enum ccdc_frmfmt frm_fmt
)
837 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
838 isif_cfg
.bayer
.frm_fmt
= frm_fmt
;
840 isif_cfg
.ycbcr
.frm_fmt
= frm_fmt
;
843 static enum ccdc_frmfmt
isif_get_frame_format(void)
845 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
846 return isif_cfg
.bayer
.frm_fmt
;
847 return isif_cfg
.ycbcr
.frm_fmt
;
850 static int isif_getfid(void)
852 return (regr(MODESET
) >> 15) & 0x1;
855 /* misc operations */
856 static void isif_setfbaddr(unsigned long addr
)
858 regw((addr
>> 21) & 0x07ff, CADU
);
859 regw((addr
>> 5) & 0x0ffff, CADL
);
862 static int isif_set_hw_if_params(struct vpfe_hw_if_param
*params
)
864 isif_cfg
.if_type
= params
->if_type
;
866 switch (params
->if_type
) {
868 case VPFE_BT656_10BIT
:
869 case VPFE_YCBCR_SYNC_8
:
870 isif_cfg
.ycbcr
.pix_fmt
= CCDC_PIXFMT_YCBCR_8BIT
;
871 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
874 case VPFE_YCBCR_SYNC_16
:
875 isif_cfg
.ycbcr
.pix_fmt
= CCDC_PIXFMT_YCBCR_16BIT
;
876 isif_cfg
.ycbcr
.pix_order
= CCDC_PIXORDER_CBYCRY
;
879 isif_cfg
.bayer
.pix_fmt
= CCDC_PIXFMT_RAW
;
882 dev_dbg(isif_cfg
.dev
, "Invalid interface type\n");
889 /* This function will configure ISIF for YCbCr parameters. */
890 static int isif_config_ycbcr(void)
892 struct isif_ycbcr_config
*params
= &isif_cfg
.ycbcr
;
893 struct vpss_pg_frame_size frame_size
;
894 u32 modeset
= 0, ccdcfg
= 0;
895 struct vpss_sync_pol sync
;
897 dev_dbg(isif_cfg
.dev
, "\nStarting isif_config_ycbcr...");
899 /* configure pixel format or input mode */
900 modeset
= modeset
| (params
->pix_fmt
<< ISIF_INPUT_SHIFT
) |
901 (params
->frm_fmt
<< ISIF_FRM_FMT_SHIFT
) |
902 (params
->fid_pol
<< ISIF_FID_POL_SHIFT
) |
903 (params
->hd_pol
<< ISIF_HD_POL_SHIFT
) |
904 (params
->vd_pol
<< ISIF_VD_POL_SHIFT
);
906 /* pack the data to 8-bit ISIFCFG */
907 switch (isif_cfg
.if_type
) {
909 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_8BIT
) {
910 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
913 modeset
|= (VPFE_PINPOL_NEGATIVE
<< ISIF_VD_POL_SHIFT
);
915 ccdcfg
= ccdcfg
| ISIF_DATA_PACK8
| ISIF_YCINSWP_YCBCR
;
917 case VPFE_BT656_10BIT
:
918 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_8BIT
) {
919 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
922 /* setup BT.656, embedded sync */
924 /* enable 10 bit mode in ccdcfg */
925 ccdcfg
= ccdcfg
| ISIF_DATA_PACK8
| ISIF_YCINSWP_YCBCR
|
929 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_16BIT
) {
930 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
936 case VPFE_YCBCR_SYNC_8
:
937 ccdcfg
|= ISIF_DATA_PACK8
;
938 ccdcfg
|= ISIF_YCINSWP_YCBCR
;
939 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_8BIT
) {
940 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
944 case VPFE_YCBCR_SYNC_16
:
945 if (params
->pix_fmt
!= CCDC_PIXFMT_YCBCR_16BIT
) {
946 dev_dbg(isif_cfg
.dev
, "Invalid pix_fmt(input mode)\n");
951 /* should never come here */
952 dev_dbg(isif_cfg
.dev
, "Invalid interface type\n");
956 regw(modeset
, MODESET
);
958 /* Set up pix order */
959 ccdcfg
|= params
->pix_order
<< ISIF_PIX_ORDER_SHIFT
;
961 regw(ccdcfg
, CCDCFG
);
963 /* configure video window */
964 if ((isif_cfg
.if_type
== VPFE_BT1120
) ||
965 (isif_cfg
.if_type
== VPFE_YCBCR_SYNC_16
))
966 isif_setwin(¶ms
->win
, params
->frm_fmt
, 1);
968 isif_setwin(¶ms
->win
, params
->frm_fmt
, 2);
971 * configure the horizontal line offset
972 * this is done by rounding up width to a multiple of 16 pixels
973 * and multiply by two to account for y:cb:cr 4:2:2 data
975 regw(((((params
->win
.width
* 2) + 31) & 0xffffffe0) >> 5), HSIZE
);
977 /* configure the memory line offset */
978 if ((params
->frm_fmt
== CCDC_FRMFMT_INTERLACED
) &&
979 (params
->buf_type
== CCDC_BUFTYPE_FLD_INTERLEAVED
))
980 /* two fields are interleaved in memory */
981 regw(0x00000249, SDOFST
);
983 /* Setup test pattern if enabled */
984 if (isif_cfg
.bayer
.config_params
.test_pat_gen
) {
985 sync
.ccdpg_hdpol
= params
->hd_pol
;
986 sync
.ccdpg_vdpol
= params
->vd_pol
;
987 dm365_vpss_set_sync_pol(sync
);
988 dm365_vpss_set_pg_frame_size(frame_size
);
993 static int isif_configure(void)
995 if (isif_cfg
.if_type
== VPFE_RAW_BAYER
)
996 return isif_config_raw();
997 return isif_config_ycbcr();
1000 static int isif_close(struct device
*device
)
1002 /* copy defaults to module params */
1003 isif_cfg
.bayer
.config_params
= isif_config_defaults
;
1007 static struct ccdc_hw_device isif_hw_dev
= {
1009 .owner
= THIS_MODULE
,
1012 .close
= isif_close
,
1013 .enable
= isif_enable
,
1014 .enable_out_to_sdram
= isif_enable_output_to_sdram
,
1015 .set_hw_if_params
= isif_set_hw_if_params
,
1016 .configure
= isif_configure
,
1017 .set_buftype
= isif_set_buftype
,
1018 .get_buftype
= isif_get_buftype
,
1019 .enum_pix
= isif_enum_pix
,
1020 .set_pixel_format
= isif_set_pixel_format
,
1021 .get_pixel_format
= isif_get_pixel_format
,
1022 .set_frame_format
= isif_set_frame_format
,
1023 .get_frame_format
= isif_get_frame_format
,
1024 .set_image_window
= isif_set_image_window
,
1025 .get_image_window
= isif_get_image_window
,
1026 .get_line_length
= isif_get_line_length
,
1027 .setfbaddr
= isif_setfbaddr
,
1028 .getfid
= isif_getfid
,
1032 static int isif_probe(struct platform_device
*pdev
)
1034 void (*setup_pinmux
)(void);
1035 struct resource
*res
;
1039 /* Platform data holds setup_pinmux function ptr */
1040 if (!pdev
->dev
.platform_data
)
1044 * first try to register with vpfe. If not correct platform, then we
1045 * don't have to iomap
1047 status
= vpfe_register_ccdc_device(&isif_hw_dev
);
1051 setup_pinmux
= pdev
->dev
.platform_data
;
1053 * setup Mux configuration for ccdc which may be different for
1054 * different SoCs using this CCDC
1059 /* Get the ISIF base address, linearization table0 and table1 addr. */
1061 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, i
);
1064 goto fail_nobase_res
;
1066 res
= request_mem_region(res
->start
, resource_size(res
),
1070 goto fail_nobase_res
;
1072 addr
= ioremap_nocache(res
->start
, resource_size(res
));
1075 goto fail_base_iomap
;
1079 /* ISIF base address */
1080 isif_cfg
.base_addr
= addr
;
1083 /* ISIF linear tbl0 address */
1084 isif_cfg
.linear_tbl0_addr
= addr
;
1087 /* ISIF linear tbl0 address */
1088 isif_cfg
.linear_tbl1_addr
= addr
;
1093 isif_cfg
.dev
= &pdev
->dev
;
1095 printk(KERN_NOTICE
"%s is registered with vpfe.\n",
1099 release_mem_region(res
->start
, resource_size(res
));
1102 if (isif_cfg
.base_addr
)
1103 iounmap(isif_cfg
.base_addr
);
1104 if (isif_cfg
.linear_tbl0_addr
)
1105 iounmap(isif_cfg
.linear_tbl0_addr
);
1108 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, i
);
1109 release_mem_region(res
->start
, resource_size(res
));
1112 vpfe_unregister_ccdc_device(&isif_hw_dev
);
1116 static int isif_remove(struct platform_device
*pdev
)
1118 struct resource
*res
;
1121 iounmap(isif_cfg
.base_addr
);
1122 iounmap(isif_cfg
.linear_tbl0_addr
);
1123 iounmap(isif_cfg
.linear_tbl1_addr
);
1125 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, i
);
1127 release_mem_region(res
->start
, resource_size(res
));
1130 vpfe_unregister_ccdc_device(&isif_hw_dev
);
1134 static struct platform_driver isif_driver
= {
1137 .owner
= THIS_MODULE
,
1139 .remove
= isif_remove
,
1140 .probe
= isif_probe
,
1143 module_platform_driver(isif_driver
);
1145 MODULE_LICENSE("GPL");