GNU Linux-libre 4.14.290-gnu1
[releases.git] / include / media / davinci / dm355_ccdc.h
1 /*
2  * Copyright (C) 2005-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 #ifndef _DM355_CCDC_H
15 #define _DM355_CCDC_H
16 #include <media/davinci/ccdc_types.h>
17 #include <media/davinci/vpfe_types.h>
18
19 /* enum for No of pixel per line to be avg. in Black Clamping */
20 enum ccdc_sample_length {
21         CCDC_SAMPLE_1PIXELS,
22         CCDC_SAMPLE_2PIXELS,
23         CCDC_SAMPLE_4PIXELS,
24         CCDC_SAMPLE_8PIXELS,
25         CCDC_SAMPLE_16PIXELS
26 };
27
28 /* enum for No of lines in Black Clamping */
29 enum ccdc_sample_line {
30         CCDC_SAMPLE_1LINES,
31         CCDC_SAMPLE_2LINES,
32         CCDC_SAMPLE_4LINES,
33         CCDC_SAMPLE_8LINES,
34         CCDC_SAMPLE_16LINES
35 };
36
37 /* enum for Alaw gamma width */
38 enum ccdc_gamma_width {
39         CCDC_GAMMA_BITS_13_4,
40         CCDC_GAMMA_BITS_12_3,
41         CCDC_GAMMA_BITS_11_2,
42         CCDC_GAMMA_BITS_10_1,
43         CCDC_GAMMA_BITS_09_0
44 };
45
46 enum ccdc_colpats {
47         CCDC_RED,
48         CCDC_GREEN_RED,
49         CCDC_GREEN_BLUE,
50         CCDC_BLUE
51 };
52
53 struct ccdc_col_pat {
54         enum ccdc_colpats olop;
55         enum ccdc_colpats olep;
56         enum ccdc_colpats elop;
57         enum ccdc_colpats elep;
58 };
59
60 enum ccdc_datasft {
61         CCDC_DATA_NO_SHIFT,
62         CCDC_DATA_SHIFT_1BIT,
63         CCDC_DATA_SHIFT_2BIT,
64         CCDC_DATA_SHIFT_3BIT,
65         CCDC_DATA_SHIFT_4BIT,
66         CCDC_DATA_SHIFT_5BIT,
67         CCDC_DATA_SHIFT_6BIT
68 };
69
70 enum ccdc_data_size {
71         CCDC_DATA_16BITS,
72         CCDC_DATA_15BITS,
73         CCDC_DATA_14BITS,
74         CCDC_DATA_13BITS,
75         CCDC_DATA_12BITS,
76         CCDC_DATA_11BITS,
77         CCDC_DATA_10BITS,
78         CCDC_DATA_8BITS
79 };
80 enum ccdc_mfilt1 {
81         CCDC_NO_MEDIAN_FILTER1,
82         CCDC_AVERAGE_FILTER1,
83         CCDC_MEDIAN_FILTER1
84 };
85
86 enum ccdc_mfilt2 {
87         CCDC_NO_MEDIAN_FILTER2,
88         CCDC_AVERAGE_FILTER2,
89         CCDC_MEDIAN_FILTER2
90 };
91
92 /* structure for ALaw */
93 struct ccdc_a_law {
94         /* Enable/disable A-Law */
95         unsigned char enable;
96         /* Gamma Width Input */
97         enum ccdc_gamma_width gamma_wd;
98 };
99
100 /* structure for Black Clamping */
101 struct ccdc_black_clamp {
102         /* only if bClampEnable is TRUE */
103         unsigned char b_clamp_enable;
104         /* only if bClampEnable is TRUE */
105         enum ccdc_sample_length sample_pixel;
106         /* only if bClampEnable is TRUE */
107         enum ccdc_sample_line sample_ln;
108         /* only if bClampEnable is TRUE */
109         unsigned short start_pixel;
110         /* only if bClampEnable is FALSE */
111         unsigned short sgain;
112         unsigned short dc_sub;
113 };
114
115 /* structure for Black Level Compensation */
116 struct ccdc_black_compensation {
117         /* Constant value to subtract from Red component */
118         unsigned char r;
119         /* Constant value to subtract from Gr component */
120         unsigned char gr;
121         /* Constant value to subtract from Blue component */
122         unsigned char b;
123         /* Constant value to subtract from Gb component */
124         unsigned char gb;
125 };
126
127 struct ccdc_float {
128         int integer;
129         unsigned int decimal;
130 };
131
132 #define CCDC_CSC_COEFF_TABLE_SIZE       16
133 /* structure for color space converter */
134 struct ccdc_csc {
135         unsigned char enable;
136         /*
137          * S8Q5. Use 2 decimal precision, user values range from -3.00 to 3.99.
138          * example - to use 1.03, set integer part as 1, and decimal part as 3
139          * to use -1.03, set integer part as -1 and decimal part as 3
140          */
141         struct ccdc_float coeff[CCDC_CSC_COEFF_TABLE_SIZE];
142 };
143
144 /* Structures for Vertical Defect Correction*/
145 enum ccdc_vdf_csl {
146         CCDC_VDF_NORMAL,
147         CCDC_VDF_HORZ_INTERPOL_SAT,
148         CCDC_VDF_HORZ_INTERPOL
149 };
150
151 enum ccdc_vdf_cuda {
152         CCDC_VDF_WHOLE_LINE_CORRECT,
153         CCDC_VDF_UPPER_DISABLE
154 };
155
156 enum ccdc_dfc_mwr {
157         CCDC_DFC_MWR_WRITE_COMPLETE,
158         CCDC_DFC_WRITE_REG
159 };
160
161 enum ccdc_dfc_mrd {
162         CCDC_DFC_READ_COMPLETE,
163         CCDC_DFC_READ_REG
164 };
165
166 enum ccdc_dfc_ma_rst {
167         CCDC_DFC_INCR_ADDR,
168         CCDC_DFC_CLR_ADDR
169 };
170
171 enum ccdc_dfc_mclr {
172         CCDC_DFC_CLEAR_COMPLETE,
173         CCDC_DFC_CLEAR
174 };
175
176 struct ccdc_dft_corr_ctl {
177         enum ccdc_vdf_csl vdfcsl;
178         enum ccdc_vdf_cuda vdfcuda;
179         unsigned int vdflsft;
180 };
181
182 struct ccdc_dft_corr_mem_ctl {
183         enum ccdc_dfc_mwr dfcmwr;
184         enum ccdc_dfc_mrd dfcmrd;
185         enum ccdc_dfc_ma_rst dfcmarst;
186         enum ccdc_dfc_mclr dfcmclr;
187 };
188
189 #define CCDC_DFT_TABLE_SIZE     16
190 /*
191  * Main Structure for vertical defect correction. Vertical defect
192  * correction can correct up to 16 defects if defects less than 16
193  * then pad the rest with 0
194  */
195 struct ccdc_vertical_dft {
196         unsigned char ver_dft_en;
197         unsigned char gen_dft_en;
198         unsigned int saturation_ctl;
199         struct ccdc_dft_corr_ctl dft_corr_ctl;
200         struct ccdc_dft_corr_mem_ctl dft_corr_mem_ctl;
201         int table_size;
202         unsigned int dft_corr_horz[CCDC_DFT_TABLE_SIZE];
203         unsigned int dft_corr_vert[CCDC_DFT_TABLE_SIZE];
204         unsigned int dft_corr_sub1[CCDC_DFT_TABLE_SIZE];
205         unsigned int dft_corr_sub2[CCDC_DFT_TABLE_SIZE];
206         unsigned int dft_corr_sub3[CCDC_DFT_TABLE_SIZE];
207 };
208
209 struct ccdc_data_offset {
210         unsigned char horz_offset;
211         unsigned char vert_offset;
212 };
213
214 /*
215  * Structure for CCDC configuration parameters for raw capture mode passed
216  * by application
217  */
218 struct ccdc_config_params_raw {
219         /* data shift to be applied before storing */
220         enum ccdc_datasft datasft;
221         /* data size value from 8 to 16 bits */
222         enum ccdc_data_size data_sz;
223         /* median filter for sdram */
224         enum ccdc_mfilt1 mfilt1;
225         enum ccdc_mfilt2 mfilt2;
226         /* low pass filter enable/disable */
227         unsigned char lpf_enable;
228         /* Threshold of median filter */
229         int med_filt_thres;
230         /*
231          * horz and vertical data offset. Appliable for defect correction
232          * and lsc
233          */
234         struct ccdc_data_offset data_offset;
235         /* Structure for Optional A-Law */
236         struct ccdc_a_law alaw;
237         /* Structure for Optical Black Clamp */
238         struct ccdc_black_clamp blk_clamp;
239         /* Structure for Black Compensation */
240         struct ccdc_black_compensation blk_comp;
241         /* struture for vertical Defect Correction Module Configuration */
242         struct ccdc_vertical_dft vertical_dft;
243         /* structure for color space converter Module Configuration */
244         struct ccdc_csc csc;
245         /* color patters for bayer capture */
246         struct ccdc_col_pat col_pat_field0;
247         struct ccdc_col_pat col_pat_field1;
248 };
249
250 #ifdef __KERNEL__
251 #include <linux/io.h>
252
253 #define CCDC_WIN_PAL    {0, 0, 720, 576}
254 #define CCDC_WIN_VGA    {0, 0, 640, 480}
255
256 struct ccdc_params_ycbcr {
257         /* pixel format */
258         enum ccdc_pixfmt pix_fmt;
259         /* progressive or interlaced frame */
260         enum ccdc_frmfmt frm_fmt;
261         /* video window */
262         struct v4l2_rect win;
263         /* field id polarity */
264         enum vpfe_pin_pol fid_pol;
265         /* vertical sync polarity */
266         enum vpfe_pin_pol vd_pol;
267         /* horizontal sync polarity */
268         enum vpfe_pin_pol hd_pol;
269         /* enable BT.656 embedded sync mode */
270         int bt656_enable;
271         /* cb:y:cr:y or y:cb:y:cr in memory */
272         enum ccdc_pixorder pix_order;
273         /* interleaved or separated fields  */
274         enum ccdc_buftype buf_type;
275 };
276
277 /* Gain applied to Raw Bayer data */
278 struct ccdc_gain {
279         unsigned short r_ye;
280         unsigned short gr_cy;
281         unsigned short gb_g;
282         unsigned short b_mg;
283 };
284
285 /* Structure for CCDC configuration parameters for raw capture mode */
286 struct ccdc_params_raw {
287         /* pixel format */
288         enum ccdc_pixfmt pix_fmt;
289         /* progressive or interlaced frame */
290         enum ccdc_frmfmt frm_fmt;
291         /* video window */
292         struct v4l2_rect win;
293         /* field id polarity */
294         enum vpfe_pin_pol fid_pol;
295         /* vertical sync polarity */
296         enum vpfe_pin_pol vd_pol;
297         /* horizontal sync polarity */
298         enum vpfe_pin_pol hd_pol;
299         /* interleaved or separated fields */
300         enum ccdc_buftype buf_type;
301         /* Gain values */
302         struct ccdc_gain gain;
303         /* offset */
304         unsigned int ccdc_offset;
305         /* horizontal flip enable */
306         unsigned char horz_flip_enable;
307         /*
308          * enable to store the image in inverse order in memory
309          * (bottom to top)
310          */
311         unsigned char image_invert_enable;
312         /* Configurable part of raw data */
313         struct ccdc_config_params_raw config_params;
314 };
315
316 #endif
317 #endif                          /* DM355_CCDC_H */