isif.h 14 KB

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