/*1* Copyright (C) 2008-2009 Texas Instruments Inc2*3* This program is free software; you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation; either version 2 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program; if not, write to the Free Software15* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA16*17* isif header file18*/19#ifndef _ISIF_H20#define _ISIF_H2122#include <media/davinci/ccdc_types.h>23#include <media/davinci/vpfe_types.h>2425/* isif float type S8Q8/U8Q8 */26struct isif_float_8 {27/* 8 bit integer part */28__u8 integer;29/* 8 bit decimal part */30__u8 decimal;31};3233/* isif float type U16Q16/S16Q16 */34struct isif_float_16 {35/* 16 bit integer part */36__u16 integer;37/* 16 bit decimal part */38__u16 decimal;39};4041/************************************************************************42* Vertical Defect Correction parameters43***********************************************************************/44/* Defect Correction (DFC) table entry */45struct isif_vdfc_entry {46/* vertical position of defect */47__u16 pos_vert;48/* horizontal position of defect */49__u16 pos_horz;50/*51* Defect level of Vertical line defect position. This is subtracted52* from the data at the defect position53*/54__u8 level_at_pos;55/*56* Defect level of the pixels upper than the vertical line defect.57* This is subtracted from the data58*/59__u8 level_up_pixels;60/*61* Defect level of the pixels lower than the vertical line defect.62* This is subtracted from the data63*/64__u8 level_low_pixels;65};6667#define ISIF_VDFC_TABLE_SIZE 868struct isif_dfc {69/* enable vertical defect correction */70__u8 en;71/* Defect level subtraction. Just fed through if saturating */72#define ISIF_VDFC_NORMAL 073/*74* Defect level subtraction. Horizontal interpolation ((i-2)+(i+2))/275* if data saturating76*/77#define ISIF_VDFC_HORZ_INTERPOL_IF_SAT 178/* Horizontal interpolation (((i-2)+(i+2))/2) */79#define ISIF_VDFC_HORZ_INTERPOL 280/* one of the vertical defect correction modes above */81__u8 corr_mode;82/* 0 - whole line corrected, 1 - not pixels upper than the defect */83__u8 corr_whole_line;84#define ISIF_VDFC_NO_SHIFT 085#define ISIF_VDFC_SHIFT_1 186#define ISIF_VDFC_SHIFT_2 287#define ISIF_VDFC_SHIFT_3 388#define ISIF_VDFC_SHIFT_4 489/*90* defect level shift value. level_at_pos, level_upper_pos,91* and level_lower_pos can be shifted up by this value. Choose92* one of the values above93*/94__u8 def_level_shift;95/* defect saturation level */96__u16 def_sat_level;97/* number of vertical defects. Max is ISIF_VDFC_TABLE_SIZE */98__u16 num_vdefects;99/* VDFC table ptr */100struct isif_vdfc_entry table[ISIF_VDFC_TABLE_SIZE];101};102103struct isif_horz_bclamp {104105/* Horizontal clamp disabled. Only vertical clamp value is subtracted */106#define ISIF_HORZ_BC_DISABLE 0107/*108* Horizontal clamp value is calculated and subtracted from image data109* along with vertical clamp value110*/111#define ISIF_HORZ_BC_CLAMP_CALC_ENABLED 1112/*113* Horizontal clamp value calculated from previous image is subtracted114* from image data along with vertical clamp value.115*/116#define ISIF_HORZ_BC_CLAMP_NOT_UPDATED 2117/* horizontal clamp mode. One of the values above */118__u8 mode;119/*120* pixel value limit enable.121* 0 - limit disabled122* 1 - pixel value limited to 1023123*/124__u8 clamp_pix_limit;125/* Select Most left window for bc calculation */126#define ISIF_SEL_MOST_LEFT_WIN 0127/* Select Most right window for bc calculation */128#define ISIF_SEL_MOST_RIGHT_WIN 1129/* Select most left or right window for clamp val calculation */130__u8 base_win_sel_calc;131/* Window count per color for calculation. range 1-32 */132__u8 win_count_calc;133/* Window start position - horizontal for calculation. 0 - 8191 */134__u16 win_start_h_calc;135/* Window start position - vertical for calculation 0 - 8191 */136__u16 win_start_v_calc;137#define ISIF_HORZ_BC_SZ_H_2PIXELS 0138#define ISIF_HORZ_BC_SZ_H_4PIXELS 1139#define ISIF_HORZ_BC_SZ_H_8PIXELS 2140#define ISIF_HORZ_BC_SZ_H_16PIXELS 3141/* Width of the sample window in pixels for calculation */142__u8 win_h_sz_calc;143#define ISIF_HORZ_BC_SZ_V_32PIXELS 0144#define ISIF_HORZ_BC_SZ_V_64PIXELS 1145#define ISIF_HORZ_BC_SZ_V_128PIXELS 2146#define ISIF_HORZ_BC_SZ_V_256PIXELS 3147/* Height of the sample window in pixels for calculation */148__u8 win_v_sz_calc;149};150151/************************************************************************152* Black Clamp parameters153***********************************************************************/154struct isif_vert_bclamp {155/* Reset value used is the clamp value calculated */156#define ISIF_VERT_BC_USE_HORZ_CLAMP_VAL 0157/* Reset value used is reset_clamp_val configured */158#define ISIF_VERT_BC_USE_CONFIG_CLAMP_VAL 1159/* No update, previous image value is used */160#define ISIF_VERT_BC_NO_UPDATE 2161/*162* Reset value selector for vertical clamp calculation. Use one of163* the above values164*/165__u8 reset_val_sel;166/* U8Q8. Line average coefficient used in vertical clamp calculation */167__u8 line_ave_coef;168/* Height of the optical black region for calculation */169__u16 ob_v_sz_calc;170/* Optical black region start position - horizontal. 0 - 8191 */171__u16 ob_start_h;172/* Optical black region start position - vertical 0 - 8191 */173__u16 ob_start_v;174};175176struct isif_black_clamp {177/*178* This offset value is added irrespective of the clamp enable status.179* S13180*/181__u16 dc_offset;182/*183* Enable black/digital clamp value to be subtracted from the image data184*/185__u8 en;186/*187* black clamp mode. same/separate clamp for 4 colors188* 0 - disable - same clamp value for all colors189* 1 - clamp value calculated separately for all colors190*/191__u8 bc_mode_color;192/* Vrtical start position for bc subtraction */193__u16 vert_start_sub;194/* Black clamp for horizontal direction */195struct isif_horz_bclamp horz;196/* Black clamp for vertical direction */197struct isif_vert_bclamp vert;198};199200/*************************************************************************201** Color Space Conversion (CSC)202*************************************************************************/203#define ISIF_CSC_NUM_COEFF 16204struct isif_color_space_conv {205/* Enable color space conversion */206__u8 en;207/*208* csc coeffient table. S8Q5, M00 at index 0, M01 at index 1, and209* so forth210*/211struct isif_float_8 coeff[ISIF_CSC_NUM_COEFF];212};213214215/*************************************************************************216** Black Compensation parameters217*************************************************************************/218struct isif_black_comp {219/* Comp for Red */220__s8 r_comp;221/* Comp for Gr */222__s8 gr_comp;223/* Comp for Blue */224__s8 b_comp;225/* Comp for Gb */226__s8 gb_comp;227};228229/*************************************************************************230** Gain parameters231*************************************************************************/232struct isif_gain {233/* Gain for Red or ye */234struct isif_float_16 r_ye;235/* Gain for Gr or cy */236struct isif_float_16 gr_cy;237/* Gain for Gb or g */238struct isif_float_16 gb_g;239/* Gain for Blue or mg */240struct isif_float_16 b_mg;241};242243#define ISIF_LINEAR_TAB_SIZE 192244/*************************************************************************245** Linearization parameters246*************************************************************************/247struct isif_linearize {248/* Enable or Disable linearization of data */249__u8 en;250/* Shift value applied */251__u8 corr_shft;252/* scale factor applied U11Q10 */253struct isif_float_16 scale_fact;254/* Size of the linear table */255__u16 table[ISIF_LINEAR_TAB_SIZE];256};257258/* Color patterns */259#define ISIF_RED 0260#define ISIF_GREEN_RED 1261#define ISIF_GREEN_BLUE 2262#define ISIF_BLUE 3263struct isif_col_pat {264__u8 olop;265__u8 olep;266__u8 elop;267__u8 elep;268};269270/*************************************************************************271** Data formatter parameters272*************************************************************************/273struct isif_fmtplen {274/*275* number of program entries for SET0, range 1 - 16276* when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is277* ISIF_COMBINE278*/279__u16 plen0;280/*281* number of program entries for SET1, range 1 - 16282* when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is283* ISIF_COMBINE284*/285__u16 plen1;286/**287* number of program entries for SET2, range 1 - 16288* when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is289* ISIF_COMBINE290*/291__u16 plen2;292/**293* number of program entries for SET3, range 1 - 16294* when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is295* ISIF_COMBINE296*/297__u16 plen3;298};299300struct isif_fmt_cfg {301#define ISIF_SPLIT 0302#define ISIF_COMBINE 1303/* Split or combine or line alternate */304__u8 fmtmode;305/* enable or disable line alternating mode */306__u8 ln_alter_en;307#define ISIF_1LINE 0308#define ISIF_2LINES 1309#define ISIF_3LINES 2310#define ISIF_4LINES 3311/* Split/combine line number */312__u8 lnum;313/* Address increment Range 1 - 16 */314__u8 addrinc;315};316317struct isif_fmt_addr_ptr {318/* Initial address */319__u32 init_addr;320/* output line number */321#define ISIF_1STLINE 0322#define ISIF_2NDLINE 1323#define ISIF_3RDLINE 2324#define ISIF_4THLINE 3325__u8 out_line;326};327328struct isif_fmtpgm_ap {329/* program address pointer */330__u8 pgm_aptr;331/* program address increment or decrement */332__u8 pgmupdt;333};334335struct isif_data_formatter {336/* Enable/Disable data formatter */337__u8 en;338/* data formatter configuration */339struct isif_fmt_cfg cfg;340/* Formatter program entries length */341struct isif_fmtplen plen;342/* first pixel in a line fed to formatter */343__u16 fmtrlen;344/* HD interval for output line. Only valid when split line */345__u16 fmthcnt;346/* formatter address pointers */347struct isif_fmt_addr_ptr fmtaddr_ptr[16];348/* program enable/disable */349__u8 pgm_en[32];350/* program address pointers */351struct isif_fmtpgm_ap fmtpgm_ap[32];352};353354struct isif_df_csc {355/* Color Space Conversion confguration, 0 - csc, 1 - df */356__u8 df_or_csc;357/* csc configuration valid if df_or_csc is 0 */358struct isif_color_space_conv csc;359/* data formatter configuration valid if df_or_csc is 1 */360struct isif_data_formatter df;361/* start pixel in a line at the input */362__u32 start_pix;363/* number of pixels in input line */364__u32 num_pixels;365/* start line at the input */366__u32 start_line;367/* number of lines at the input */368__u32 num_lines;369};370371struct isif_gain_offsets_adj {372/* Gain adjustment per color */373struct isif_gain gain;374/* Offset adjustment */375__u16 offset;376/* Enable or Disable Gain adjustment for SDRAM data */377__u8 gain_sdram_en;378/* Enable or Disable Gain adjustment for IPIPE data */379__u8 gain_ipipe_en;380/* Enable or Disable Gain adjustment for H3A data */381__u8 gain_h3a_en;382/* Enable or Disable Gain adjustment for SDRAM data */383__u8 offset_sdram_en;384/* Enable or Disable Gain adjustment for IPIPE data */385__u8 offset_ipipe_en;386/* Enable or Disable Gain adjustment for H3A data */387__u8 offset_h3a_en;388};389390struct isif_cul {391/* Horizontal Cull pattern for odd lines */392__u8 hcpat_odd;393/* Horizontal Cull pattern for even lines */394__u8 hcpat_even;395/* Vertical Cull pattern */396__u8 vcpat;397/* Enable or disable lpf. Apply when cull is enabled */398__u8 en_lpf;399};400401struct isif_compress {402#define ISIF_ALAW 0403#define ISIF_DPCM 1404#define ISIF_NO_COMPRESSION 2405/* Compression Algorithm used */406__u8 alg;407/* Choose Predictor1 for DPCM compression */408#define ISIF_DPCM_PRED1 0409/* Choose Predictor2 for DPCM compression */410#define ISIF_DPCM_PRED2 1411/* Predictor for DPCM compression */412__u8 pred;413};414415/* all the stuff in this struct will be provided by userland */416struct isif_config_params_raw {417/* Linearization parameters for image sensor data input */418struct isif_linearize linearize;419/* Data formatter or CSC */420struct isif_df_csc df_csc;421/* Defect Pixel Correction (DFC) confguration */422struct isif_dfc dfc;423/* Black/Digital Clamp configuration */424struct isif_black_clamp bclamp;425/* Gain, offset adjustments */426struct isif_gain_offsets_adj gain_offset;427/* Culling */428struct isif_cul culling;429/* A-Law and DPCM compression options */430struct isif_compress compress;431/* horizontal offset for Gain/LSC/DFC */432__u16 horz_offset;433/* vertical offset for Gain/LSC/DFC */434__u16 vert_offset;435/* color pattern for field 0 */436struct isif_col_pat col_pat_field0;437/* color pattern for field 1 */438struct isif_col_pat col_pat_field1;439#define ISIF_NO_SHIFT 0440#define ISIF_1BIT_SHIFT 1441#define ISIF_2BIT_SHIFT 2442#define ISIF_3BIT_SHIFT 3443#define ISIF_4BIT_SHIFT 4444#define ISIF_5BIT_SHIFT 5445#define ISIF_6BIT_SHIFT 6446/* Data shift applied before storing to SDRAM */447__u8 data_shift;448/* enable input test pattern generation */449__u8 test_pat_gen;450};451452#ifdef __KERNEL__453struct isif_ycbcr_config {454/* isif pixel format */455enum ccdc_pixfmt pix_fmt;456/* isif frame format */457enum ccdc_frmfmt frm_fmt;458/* ISIF crop window */459struct v4l2_rect win;460/* field polarity */461enum vpfe_pin_pol fid_pol;462/* interface VD polarity */463enum vpfe_pin_pol vd_pol;464/* interface HD polarity */465enum vpfe_pin_pol hd_pol;466/* isif pix order. Only used for ycbcr capture */467enum ccdc_pixorder pix_order;468/* isif buffer type. Only used for ycbcr capture */469enum ccdc_buftype buf_type;470};471472/* MSB of image data connected to sensor port */473enum isif_data_msb {474ISIF_BIT_MSB_15,475ISIF_BIT_MSB_14,476ISIF_BIT_MSB_13,477ISIF_BIT_MSB_12,478ISIF_BIT_MSB_11,479ISIF_BIT_MSB_10,480ISIF_BIT_MSB_9,481ISIF_BIT_MSB_8,482ISIF_BIT_MSB_7483};484485enum isif_cfa_pattern {486ISIF_CFA_PAT_MOSAIC,487ISIF_CFA_PAT_STRIPE488};489490struct isif_params_raw {491/* isif pixel format */492enum ccdc_pixfmt pix_fmt;493/* isif frame format */494enum ccdc_frmfmt frm_fmt;495/* video window */496struct v4l2_rect win;497/* field polarity */498enum vpfe_pin_pol fid_pol;499/* interface VD polarity */500enum vpfe_pin_pol vd_pol;501/* interface HD polarity */502enum vpfe_pin_pol hd_pol;503/* buffer type. Applicable for interlaced mode */504enum ccdc_buftype buf_type;505/* Gain values */506struct isif_gain gain;507/* cfa pattern */508enum isif_cfa_pattern cfa_pat;509/* Data MSB position */510enum isif_data_msb data_msb;511/* Enable horizontal flip */512unsigned char horz_flip_en;513/* Enable image invert vertically */514unsigned char image_invert_en;515516/* all the userland defined stuff*/517struct isif_config_params_raw config_params;518};519520enum isif_data_pack {521ISIF_PACK_16BIT,522ISIF_PACK_12BIT,523ISIF_PACK_8BIT524};525526#define ISIF_WIN_NTSC {0, 0, 720, 480}527#define ISIF_WIN_VGA {0, 0, 640, 480}528529#endif530#endif531532533