isif.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. /*
  2. * Copyright (C) 2008-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. * 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
  17. *
  18. * isif header file
  19. */
  20. #ifndef _ISIF_H
  21. #define _ISIF_H
  22. #include <media/davinci/ccdc_types.h>
  23. #include <media/davinci/vpfe_types.h>
  24. /* isif float type S8Q8/U8Q8 */
  25. struct isif_float_8 {
  26. /* 8 bit integer part */
  27. __u8 integer;
  28. /* 8 bit decimal part */
  29. __u8 decimal;
  30. };
  31. /* isif float type U16Q16/S16Q16 */
  32. struct isif_float_16 {
  33. /* 16 bit integer part */
  34. __u16 integer;
  35. /* 16 bit decimal part */
  36. __u16 decimal;
  37. };
  38. /************************************************************************
  39. * Vertical Defect Correction parameters
  40. ***********************************************************************/
  41. /* Defect Correction (DFC) table entry */
  42. struct isif_vdfc_entry {
  43. /* vertical position of defect */
  44. __u16 pos_vert;
  45. /* horizontal position of defect */
  46. __u16 pos_horz;
  47. /*
  48. * Defect level of Vertical line defect position. This is subtracted
  49. * from the data at the defect position
  50. */
  51. __u8 level_at_pos;
  52. /*
  53. * Defect level of the pixels upper than the vertical line defect.
  54. * This is subtracted from the data
  55. */
  56. __u8 level_up_pixels;
  57. /*
  58. * Defect level of the pixels lower than the vertical line defect.
  59. * This is subtracted from the data
  60. */
  61. __u8 level_low_pixels;
  62. };
  63. #define ISIF_VDFC_TABLE_SIZE 8
  64. struct isif_dfc {
  65. /* enable vertical defect correction */
  66. __u8 en;
  67. /* Defect level subtraction. Just fed through if saturating */
  68. #define ISIF_VDFC_NORMAL 0
  69. /*
  70. * Defect level subtraction. Horizontal interpolation ((i-2)+(i+2))/2
  71. * if data saturating
  72. */
  73. #define ISIF_VDFC_HORZ_INTERPOL_IF_SAT 1
  74. /* Horizontal interpolation (((i-2)+(i+2))/2) */
  75. #define ISIF_VDFC_HORZ_INTERPOL 2
  76. /* one of the vertical defect correction modes above */
  77. __u8 corr_mode;
  78. /* 0 - whole line corrected, 1 - not pixels upper than the defect */
  79. __u8 corr_whole_line;
  80. #define ISIF_VDFC_NO_SHIFT 0
  81. #define ISIF_VDFC_SHIFT_1 1
  82. #define ISIF_VDFC_SHIFT_2 2
  83. #define ISIF_VDFC_SHIFT_3 3
  84. #define ISIF_VDFC_SHIFT_4 4
  85. /*
  86. * defect level shift value. level_at_pos, level_upper_pos,
  87. * and level_lower_pos can be shifted up by this value. Choose
  88. * one of the values above
  89. */
  90. __u8 def_level_shift;
  91. /* defect saturation level */
  92. __u16 def_sat_level;
  93. /* number of vertical defects. Max is ISIF_VDFC_TABLE_SIZE */
  94. __u16 num_vdefects;
  95. /* VDFC table ptr */
  96. struct isif_vdfc_entry table[ISIF_VDFC_TABLE_SIZE];
  97. };
  98. struct isif_horz_bclamp {
  99. /* Horizontal clamp disabled. Only vertical clamp value is subtracted */
  100. #define ISIF_HORZ_BC_DISABLE 0
  101. /*
  102. * Horizontal clamp value is calculated and subtracted from image data
  103. * along with vertical clamp value
  104. */
  105. #define ISIF_HORZ_BC_CLAMP_CALC_ENABLED 1
  106. /*
  107. * Horizontal clamp value calculated from previous image is subtracted
  108. * from image data along with vertical clamp value.
  109. */
  110. #define ISIF_HORZ_BC_CLAMP_NOT_UPDATED 2
  111. /* horizontal clamp mode. One of the values above */
  112. __u8 mode;
  113. /*
  114. * pixel value limit enable.
  115. * 0 - limit disabled
  116. * 1 - pixel value limited to 1023
  117. */
  118. __u8 clamp_pix_limit;
  119. /* Select Most left window for bc calculation */
  120. #define ISIF_SEL_MOST_LEFT_WIN 0
  121. /* Select Most right window for bc calculation */
  122. #define ISIF_SEL_MOST_RIGHT_WIN 1
  123. /* Select most left or right window for clamp val calculation */
  124. __u8 base_win_sel_calc;
  125. /* Window count per color for calculation. range 1-32 */
  126. __u8 win_count_calc;
  127. /* Window start position - horizontal for calculation. 0 - 8191 */
  128. __u16 win_start_h_calc;
  129. /* Window start position - vertical for calculation 0 - 8191 */
  130. __u16 win_start_v_calc;
  131. #define ISIF_HORZ_BC_SZ_H_2PIXELS 0
  132. #define ISIF_HORZ_BC_SZ_H_4PIXELS 1
  133. #define ISIF_HORZ_BC_SZ_H_8PIXELS 2
  134. #define ISIF_HORZ_BC_SZ_H_16PIXELS 3
  135. /* Width of the sample window in pixels for calculation */
  136. __u8 win_h_sz_calc;
  137. #define ISIF_HORZ_BC_SZ_V_32PIXELS 0
  138. #define ISIF_HORZ_BC_SZ_V_64PIXELS 1
  139. #define ISIF_HORZ_BC_SZ_V_128PIXELS 2
  140. #define ISIF_HORZ_BC_SZ_V_256PIXELS 3
  141. /* Height of the sample window in pixels for calculation */
  142. __u8 win_v_sz_calc;
  143. };
  144. /************************************************************************
  145. * Black Clamp parameters
  146. ***********************************************************************/
  147. struct isif_vert_bclamp {
  148. /* Reset value used is the clamp value calculated */
  149. #define ISIF_VERT_BC_USE_HORZ_CLAMP_VAL 0
  150. /* Reset value used is reset_clamp_val configured */
  151. #define ISIF_VERT_BC_USE_CONFIG_CLAMP_VAL 1
  152. /* No update, previous image value is used */
  153. #define ISIF_VERT_BC_NO_UPDATE 2
  154. /*
  155. * Reset value selector for vertical clamp calculation. Use one of
  156. * the above values
  157. */
  158. __u8 reset_val_sel;
  159. /* U8Q8. Line average coefficient used in vertical clamp calculation */
  160. __u8 line_ave_coef;
  161. /* Height of the optical black region for calculation */
  162. __u16 ob_v_sz_calc;
  163. /* Optical black region start position - horizontal. 0 - 8191 */
  164. __u16 ob_start_h;
  165. /* Optical black region start position - vertical 0 - 8191 */
  166. __u16 ob_start_v;
  167. };
  168. struct isif_black_clamp {
  169. /*
  170. * This offset value is added irrespective of the clamp enable status.
  171. * S13
  172. */
  173. __u16 dc_offset;
  174. /*
  175. * Enable black/digital clamp value to be subtracted from the image data
  176. */
  177. __u8 en;
  178. /*
  179. * black clamp mode. same/separate clamp for 4 colors
  180. * 0 - disable - same clamp value for all colors
  181. * 1 - clamp value calculated separately for all colors
  182. */
  183. __u8 bc_mode_color;
  184. /* Vrtical start position for bc subtraction */
  185. __u16 vert_start_sub;
  186. /* Black clamp for horizontal direction */
  187. struct isif_horz_bclamp horz;
  188. /* Black clamp for vertical direction */
  189. struct isif_vert_bclamp vert;
  190. };
  191. /*************************************************************************
  192. ** Color Space Conversion (CSC)
  193. *************************************************************************/
  194. #define ISIF_CSC_NUM_COEFF 16
  195. struct isif_color_space_conv {
  196. /* Enable color space conversion */
  197. __u8 en;
  198. /*
  199. * csc coeffient table. S8Q5, M00 at index 0, M01 at index 1, and
  200. * so forth
  201. */
  202. struct isif_float_8 coeff[ISIF_CSC_NUM_COEFF];
  203. };
  204. /*************************************************************************
  205. ** Black Compensation parameters
  206. *************************************************************************/
  207. struct isif_black_comp {
  208. /* Comp for Red */
  209. __s8 r_comp;
  210. /* Comp for Gr */
  211. __s8 gr_comp;
  212. /* Comp for Blue */
  213. __s8 b_comp;
  214. /* Comp for Gb */
  215. __s8 gb_comp;
  216. };
  217. /*************************************************************************
  218. ** Gain parameters
  219. *************************************************************************/
  220. struct isif_gain {
  221. /* Gain for Red or ye */
  222. struct isif_float_16 r_ye;
  223. /* Gain for Gr or cy */
  224. struct isif_float_16 gr_cy;
  225. /* Gain for Gb or g */
  226. struct isif_float_16 gb_g;
  227. /* Gain for Blue or mg */
  228. struct isif_float_16 b_mg;
  229. };
  230. #define ISIF_LINEAR_TAB_SIZE 192
  231. /*************************************************************************
  232. ** Linearization parameters
  233. *************************************************************************/
  234. struct isif_linearize {
  235. /* Enable or Disable linearization of data */
  236. __u8 en;
  237. /* Shift value applied */
  238. __u8 corr_shft;
  239. /* scale factor applied U11Q10 */
  240. struct isif_float_16 scale_fact;
  241. /* Size of the linear table */
  242. __u16 table[ISIF_LINEAR_TAB_SIZE];
  243. };
  244. /* Color patterns */
  245. #define ISIF_RED 0
  246. #define ISIF_GREEN_RED 1
  247. #define ISIF_GREEN_BLUE 2
  248. #define ISIF_BLUE 3
  249. struct isif_col_pat {
  250. __u8 olop;
  251. __u8 olep;
  252. __u8 elop;
  253. __u8 elep;
  254. };
  255. /*************************************************************************
  256. ** Data formatter parameters
  257. *************************************************************************/
  258. struct isif_fmtplen {
  259. /*
  260. * number of program entries for SET0, range 1 - 16
  261. * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
  262. * ISIF_COMBINE
  263. */
  264. __u16 plen0;
  265. /*
  266. * number of program entries for SET1, range 1 - 16
  267. * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
  268. * ISIF_COMBINE
  269. */
  270. __u16 plen1;
  271. /**
  272. * number of program entries for SET2, range 1 - 16
  273. * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
  274. * ISIF_COMBINE
  275. */
  276. __u16 plen2;
  277. /**
  278. * number of program entries for SET3, range 1 - 16
  279. * when fmtmode is ISIF_SPLIT, 1 - 8 when fmtmode is
  280. * ISIF_COMBINE
  281. */
  282. __u16 plen3;
  283. };
  284. struct isif_fmt_cfg {
  285. #define ISIF_SPLIT 0
  286. #define ISIF_COMBINE 1
  287. /* Split or combine or line alternate */
  288. __u8 fmtmode;
  289. /* enable or disable line alternating mode */
  290. __u8 ln_alter_en;
  291. #define ISIF_1LINE 0
  292. #define ISIF_2LINES 1
  293. #define ISIF_3LINES 2
  294. #define ISIF_4LINES 3
  295. /* Split/combine line number */
  296. __u8 lnum;
  297. /* Address increment Range 1 - 16 */
  298. __u8 addrinc;
  299. };
  300. struct isif_fmt_addr_ptr {
  301. /* Initial address */
  302. __u32 init_addr;
  303. /* output line number */
  304. #define ISIF_1STLINE 0
  305. #define ISIF_2NDLINE 1
  306. #define ISIF_3RDLINE 2
  307. #define ISIF_4THLINE 3
  308. __u8 out_line;
  309. };
  310. struct isif_fmtpgm_ap {
  311. /* program address pointer */
  312. __u8 pgm_aptr;
  313. /* program address increment or decrement */
  314. __u8 pgmupdt;
  315. };
  316. struct isif_data_formatter {
  317. /* Enable/Disable data formatter */
  318. __u8 en;
  319. /* data formatter configuration */
  320. struct isif_fmt_cfg cfg;
  321. /* Formatter program entries length */
  322. struct isif_fmtplen plen;
  323. /* first pixel in a line fed to formatter */
  324. __u16 fmtrlen;
  325. /* HD interval for output line. Only valid when split line */
  326. __u16 fmthcnt;
  327. /* formatter address pointers */
  328. struct isif_fmt_addr_ptr fmtaddr_ptr[16];
  329. /* program enable/disable */
  330. __u8 pgm_en[32];
  331. /* program address pointers */
  332. struct isif_fmtpgm_ap fmtpgm_ap[32];
  333. };
  334. struct isif_df_csc {
  335. /* Color Space Conversion confguration, 0 - csc, 1 - df */
  336. __u8 df_or_csc;
  337. /* csc configuration valid if df_or_csc is 0 */
  338. struct isif_color_space_conv csc;
  339. /* data formatter configuration valid if df_or_csc is 1 */
  340. struct isif_data_formatter df;
  341. /* start pixel in a line at the input */
  342. __u32 start_pix;
  343. /* number of pixels in input line */
  344. __u32 num_pixels;
  345. /* start line at the input */
  346. __u32 start_line;
  347. /* number of lines at the input */
  348. __u32 num_lines;
  349. };
  350. struct isif_gain_offsets_adj {
  351. /* Gain adjustment per color */
  352. struct isif_gain gain;
  353. /* Offset adjustment */
  354. __u16 offset;
  355. /* Enable or Disable Gain adjustment for SDRAM data */
  356. __u8 gain_sdram_en;
  357. /* Enable or Disable Gain adjustment for IPIPE data */
  358. __u8 gain_ipipe_en;
  359. /* Enable or Disable Gain adjustment for H3A data */
  360. __u8 gain_h3a_en;
  361. /* Enable or Disable Gain adjustment for SDRAM data */
  362. __u8 offset_sdram_en;
  363. /* Enable or Disable Gain adjustment for IPIPE data */
  364. __u8 offset_ipipe_en;
  365. /* Enable or Disable Gain adjustment for H3A data */
  366. __u8 offset_h3a_en;
  367. };
  368. struct isif_cul {
  369. /* Horizontal Cull pattern for odd lines */
  370. __u8 hcpat_odd;
  371. /* Horizontal Cull pattern for even lines */
  372. __u8 hcpat_even;
  373. /* Vertical Cull pattern */
  374. __u8 vcpat;
  375. /* Enable or disable lpf. Apply when cull is enabled */
  376. __u8 en_lpf;
  377. };
  378. struct isif_compress {
  379. #define ISIF_ALAW 0
  380. #define ISIF_DPCM 1
  381. #define ISIF_NO_COMPRESSION 2
  382. /* Compression Algorithm used */
  383. __u8 alg;
  384. /* Choose Predictor1 for DPCM compression */
  385. #define ISIF_DPCM_PRED1 0
  386. /* Choose Predictor2 for DPCM compression */
  387. #define ISIF_DPCM_PRED2 1
  388. /* Predictor for DPCM compression */
  389. __u8 pred;
  390. };
  391. /* all the stuff in this struct will be provided by userland */
  392. struct isif_config_params_raw {
  393. /* Linearization parameters for image sensor data input */
  394. struct isif_linearize linearize;
  395. /* Data formatter or CSC */
  396. struct isif_df_csc df_csc;
  397. /* Defect Pixel Correction (DFC) confguration */
  398. struct isif_dfc dfc;
  399. /* Black/Digital Clamp configuration */
  400. struct isif_black_clamp bclamp;
  401. /* Gain, offset adjustments */
  402. struct isif_gain_offsets_adj gain_offset;
  403. /* Culling */
  404. struct isif_cul culling;
  405. /* A-Law and DPCM compression options */
  406. struct isif_compress compress;
  407. /* horizontal offset for Gain/LSC/DFC */
  408. __u16 horz_offset;
  409. /* vertical offset for Gain/LSC/DFC */
  410. __u16 vert_offset;
  411. /* color pattern for field 0 */
  412. struct isif_col_pat col_pat_field0;
  413. /* color pattern for field 1 */
  414. struct isif_col_pat col_pat_field1;
  415. #define ISIF_NO_SHIFT 0
  416. #define ISIF_1BIT_SHIFT 1
  417. #define ISIF_2BIT_SHIFT 2
  418. #define ISIF_3BIT_SHIFT 3
  419. #define ISIF_4BIT_SHIFT 4
  420. #define ISIF_5BIT_SHIFT 5
  421. #define ISIF_6BIT_SHIFT 6
  422. /* Data shift applied before storing to SDRAM */
  423. __u8 data_shift;
  424. /* enable input test pattern generation */
  425. __u8 test_pat_gen;
  426. };
  427. #ifdef __KERNEL__
  428. struct isif_ycbcr_config {
  429. /* isif pixel format */
  430. enum ccdc_pixfmt pix_fmt;
  431. /* isif frame format */
  432. enum ccdc_frmfmt frm_fmt;
  433. /* ISIF crop window */
  434. struct v4l2_rect win;
  435. /* field polarity */
  436. enum vpfe_pin_pol fid_pol;
  437. /* interface VD polarity */
  438. enum vpfe_pin_pol vd_pol;
  439. /* interface HD polarity */
  440. enum vpfe_pin_pol hd_pol;
  441. /* isif pix order. Only used for ycbcr capture */
  442. enum ccdc_pixorder pix_order;
  443. /* isif buffer type. Only used for ycbcr capture */
  444. enum ccdc_buftype buf_type;
  445. };
  446. /* MSB of image data connected to sensor port */
  447. enum isif_data_msb {
  448. ISIF_BIT_MSB_15,
  449. ISIF_BIT_MSB_14,
  450. ISIF_BIT_MSB_13,
  451. ISIF_BIT_MSB_12,
  452. ISIF_BIT_MSB_11,
  453. ISIF_BIT_MSB_10,
  454. ISIF_BIT_MSB_9,
  455. ISIF_BIT_MSB_8,
  456. ISIF_BIT_MSB_7
  457. };
  458. enum isif_cfa_pattern {
  459. ISIF_CFA_PAT_MOSAIC,
  460. ISIF_CFA_PAT_STRIPE
  461. };
  462. struct isif_params_raw {
  463. /* isif pixel format */
  464. enum ccdc_pixfmt pix_fmt;
  465. /* isif frame format */
  466. enum ccdc_frmfmt frm_fmt;
  467. /* video window */
  468. struct v4l2_rect win;
  469. /* field polarity */
  470. enum vpfe_pin_pol fid_pol;
  471. /* interface VD polarity */
  472. enum vpfe_pin_pol vd_pol;
  473. /* interface HD polarity */
  474. enum vpfe_pin_pol hd_pol;
  475. /* buffer type. Applicable for interlaced mode */
  476. enum ccdc_buftype buf_type;
  477. /* Gain values */
  478. struct isif_gain gain;
  479. /* cfa pattern */
  480. enum isif_cfa_pattern cfa_pat;
  481. /* Data MSB position */
  482. enum isif_data_msb data_msb;
  483. /* Enable horizontal flip */
  484. unsigned char horz_flip_en;
  485. /* Enable image invert vertically */
  486. unsigned char image_invert_en;
  487. /* all the userland defined stuff*/
  488. struct isif_config_params_raw config_params;
  489. };
  490. enum isif_data_pack {
  491. ISIF_PACK_16BIT,
  492. ISIF_PACK_12BIT,
  493. ISIF_PACK_8BIT
  494. };
  495. #define ISIF_WIN_NTSC {0, 0, 720, 480}
  496. #define ISIF_WIN_VGA {0, 0, 640, 480}
  497. #endif
  498. #endif