V4L/DVB (9702): Move the ov9650 vflip table to avoid compilation warnings on older...
[sfrench/cifs-2.6.git] / drivers / media / video / gspca / m5602 / m5602_ov9650.h
1 /*
2  * Driver for the ov9650 sensor
3  *
4  * Copyright (C) 2008 Erik AndrĂ©n
5  * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6  * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7  *
8  * Portions of code to USB interface and ALi driver software,
9  * Copyright (c) 2006 Willem Duinker
10  * v4l2 interface modeled after the V4L2 driver
11  * for SN9C10x PC Camera Controllers
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation, version 2.
16  *
17  */
18
19 #ifndef M5602_OV9650_H_
20 #define M5602_OV9650_H_
21
22 #include <linux/dmi.h>
23
24 #include "m5602_sensor.h"
25
26 /*****************************************************************************/
27
28 #define OV9650_GAIN                     0x00
29 #define OV9650_BLUE                     0x01
30 #define OV9650_RED                      0x02
31 #define OV9650_VREF                     0x03
32 #define OV9650_COM1                     0x04
33 #define OV9650_BAVE                     0x05
34 #define OV9650_GEAVE                    0x06
35 #define OV9650_RSVD7                    0x07
36 #define OV9650_PID                      0x0a
37 #define OV9650_VER                      0x0b
38 #define OV9650_COM3                     0x0c
39 #define OV9650_COM5                     0x0e
40 #define OV9650_COM6                     0x0f
41 #define OV9650_AECH                     0x10
42 #define OV9650_CLKRC                    0x11
43 #define OV9650_COM7                     0x12
44 #define OV9650_COM8                     0x13
45 #define OV9650_COM9                     0x14
46 #define OV9650_COM10                    0x15
47 #define OV9650_RSVD16                   0x16
48 #define OV9650_HSTART                   0x17
49 #define OV9650_HSTOP                    0x18
50 #define OV9650_VSTRT                    0x19
51 #define OV9650_VSTOP                    0x1a
52 #define OV9650_PSHFT                    0x1b
53 #define OV9650_MVFP                     0x1e
54 #define OV9650_AEW                      0x24
55 #define OV9650_AEB                      0x25
56 #define OV9650_VPT                      0x26
57 #define OV9650_BBIAS                    0x27
58 #define OV9650_GbBIAS                   0x28
59 #define OV9650_Gr_COM                   0x29
60 #define OV9650_RBIAS                    0x2c
61 #define OV9650_HREF                     0x32
62 #define OV9650_CHLF                     0x33
63 #define OV9650_ARBLM                    0x34
64 #define OV9650_RSVD35                   0x35
65 #define OV9650_RSVD36                   0x36
66 #define OV9650_ADC                      0x37
67 #define OV9650_ACOM38                   0x38
68 #define OV9650_OFON                     0x39
69 #define OV9650_TSLB                     0x3a
70 #define OV9650_COM12                    0x3c
71 #define OV9650_COM13                    0x3d
72 #define OV9650_COM15                    0x40
73 #define OV9650_COM16                    0x41
74 #define OV9650_LCC1                     0x62
75 #define OV9650_LCC2                     0x63
76 #define OV9650_LCC3                     0x64
77 #define OV9650_LCC4                     0x65
78 #define OV9650_LCC5                     0x66
79 #define OV9650_HV                       0x69
80 #define OV9650_DBLV                     0x6b
81 #define OV9650_COM21                    0x8b
82 #define OV9650_COM22                    0x8c
83 #define OV9650_COM24                    0x8e
84 #define OV9650_DBLC1                    0x8f
85 #define OV9650_RSVD94                   0x94
86 #define OV9650_RSVD95                   0x95
87 #define OV9650_RSVD96                   0x96
88 #define OV9650_LCCFB                    0x9d
89 #define OV9650_LCCFR                    0x9e
90 #define OV9650_AECHM                    0xa1
91 #define OV9650_COM26                    0xa5
92 #define OV9650_ACOMA8                   0xa8
93 #define OV9650_ACOMA9                   0xa9
94
95 #define OV9650_REGISTER_RESET           (1 << 7)
96 #define OV9650_VGA_SELECT               (1 << 6)
97 #define OV9650_RGB_SELECT               (1 << 2)
98 #define OV9650_RAW_RGB_SELECT           (1 << 0)
99
100 #define OV9650_FAST_AGC_AEC             (1 << 7)
101 #define OV9650_AEC_UNLIM_STEP_SIZE      (1 << 6)
102 #define OV9650_BANDING                  (1 << 5)
103 #define OV9650_AGC_EN                   (1 << 2)
104 #define OV9650_AWB_EN                   (1 << 1)
105 #define OV9650_AEC_EN                   (1 << 0)
106
107 #define OV9650_VARIOPIXEL               (1 << 2)
108 #define OV9650_SYSTEM_CLK_SEL           (1 << 7)
109 #define OV9650_SLAM_MODE                (1 << 4)
110
111 #define OV9650_VFLIP                    (1 << 4)
112 #define OV9650_HFLIP                    (1 << 5)
113
114 #define GAIN_DEFAULT                    0x14
115 #define RED_GAIN_DEFAULT                0x70
116 #define BLUE_GAIN_DEFAULT               0x20
117 #define EXPOSURE_DEFAULT                0x5003
118
119 /*****************************************************************************/
120
121 /* Kernel module parameters */
122 extern int force_sensor;
123 extern int dump_sensor;
124
125 int ov9650_probe(struct sd *sd);
126 int ov9650_init(struct sd *sd);
127 int ov9650_power_down(struct sd *sd);
128
129 int ov9650_read_sensor(struct sd *sd, const u8 address,
130                        u8 *i2c_data, const u8 len);
131 int ov9650_write_sensor(struct sd *sd, const u8 address,
132                        u8 *i2c_data, const u8 len);
133
134 void ov9650_dump_registers(struct sd *sd);
135
136 int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
137 int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
138 int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
139 int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val);
140 int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
141 int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
142 int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
143 int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
144 int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
145 int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
146 int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
147 int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
148 int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val);
149 int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val);
150 int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val);
151 int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val);
152 int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val);
153 int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val);
154
155 static struct m5602_sensor ov9650 = {
156         .name = "OV9650",
157         .i2c_slave_id = 0x60,
158         .probe = ov9650_probe,
159         .init = ov9650_init,
160         .power_down = ov9650_power_down,
161         .read_sensor = ov9650_read_sensor,
162         .write_sensor = ov9650_write_sensor,
163
164         .nctrls = 8,
165         .ctrls = {
166         {
167                 {
168                         .id             = V4L2_CID_EXPOSURE,
169                         .type           = V4L2_CTRL_TYPE_INTEGER,
170                         .name           = "exposure",
171                         .minimum        = 0x00,
172                         .maximum        = 0xffff,
173                         .step           = 0x1,
174                         .default_value  = EXPOSURE_DEFAULT,
175                         .flags          = V4L2_CTRL_FLAG_SLIDER
176                 },
177                 .set = ov9650_set_exposure,
178                 .get = ov9650_get_exposure
179         }, {
180                 {
181                         .id             = V4L2_CID_GAIN,
182                         .type           = V4L2_CTRL_TYPE_INTEGER,
183                         .name           = "gain",
184                         .minimum        = 0x00,
185                         .maximum        = 0x3ff,
186                         .step           = 0x1,
187                         .default_value  = GAIN_DEFAULT,
188                         .flags          = V4L2_CTRL_FLAG_SLIDER
189                 },
190                 .set = ov9650_set_gain,
191                 .get = ov9650_get_gain
192         }, {
193                 {
194                         .type           = V4L2_CTRL_TYPE_INTEGER,
195                         .name           = "red balance",
196                         .minimum        = 0x00,
197                         .maximum        = 0xff,
198                         .step           = 0x1,
199                         .default_value  = RED_GAIN_DEFAULT,
200                         .flags          = V4L2_CTRL_FLAG_SLIDER
201                 },
202                 .set = ov9650_set_red_balance,
203                 .get = ov9650_get_red_balance
204         }, {
205                 {
206                         .type           = V4L2_CTRL_TYPE_INTEGER,
207                         .name           = "blue balance",
208                         .minimum        = 0x00,
209                         .maximum        = 0xff,
210                         .step           = 0x1,
211                         .default_value  = BLUE_GAIN_DEFAULT,
212                         .flags          = V4L2_CTRL_FLAG_SLIDER
213                 },
214                 .set = ov9650_set_blue_balance,
215                 .get = ov9650_get_blue_balance
216         }, {
217                 {
218                         .id             = V4L2_CID_HFLIP,
219                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
220                         .name           = "horizontal flip",
221                         .minimum        = 0,
222                         .maximum        = 1,
223                         .step           = 1,
224                         .default_value  = 0
225                 },
226                 .set = ov9650_set_hflip,
227                 .get = ov9650_get_hflip
228         }, {
229                 {
230                         .id             = V4L2_CID_VFLIP,
231                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
232                         .name           = "vertical flip",
233                         .minimum        = 0,
234                         .maximum        = 1,
235                         .step           = 1,
236                         .default_value  = 0
237                 },
238                 .set = ov9650_set_vflip,
239                 .get = ov9650_get_vflip
240         }, {
241                 {
242                         .id             = V4L2_CID_AUTO_WHITE_BALANCE,
243                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
244                         .name           = "auto white balance",
245                         .minimum        = 0,
246                         .maximum        = 1,
247                         .step           = 1,
248                         .default_value  = 0
249                 },
250                 .set = ov9650_set_auto_white_balance,
251                 .get = ov9650_get_auto_white_balance
252         }, {
253                 {
254                         .id             = V4L2_CID_AUTOGAIN,
255                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
256                         .name           = "auto gain control",
257                         .minimum        = 0,
258                         .maximum        = 1,
259                         .step           = 1,
260                         .default_value  = 0
261                 },
262                 .set = ov9650_set_auto_gain,
263                 .get = ov9650_get_auto_gain
264         }
265         },
266
267         .nmodes = 1,
268         .modes = {
269         {
270                 M5602_DEFAULT_FRAME_WIDTH,
271                 M5602_DEFAULT_FRAME_HEIGHT,
272                 V4L2_PIX_FMT_SBGGR8,
273                 V4L2_FIELD_NONE,
274                 .sizeimage =
275                         M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
276                 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
277                 .colorspace = V4L2_COLORSPACE_SRGB,
278                 .priv = 1
279         }
280         }
281 };
282
283 static const unsigned char preinit_ov9650[][3] =
284 {
285         /* [INITCAM] */
286         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
287         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
288         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
289         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
290         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
291         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
292
293         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08},
294         {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
295         {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
296         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
297         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
298         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00},
299         {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
300         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a},
301         /* Reset chip */
302         {SENSOR, OV9650_COM7, OV9650_REGISTER_RESET},
303         /* Enable double clock */
304         {SENSOR, OV9650_CLKRC, 0x80},
305         /* Do something out of spec with the power */
306         {SENSOR, OV9650_OFON, 0x40}
307 };
308
309 static const unsigned char init_ov9650[][3] =
310 {
311         /* [INITCAM] */
312         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
313         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
314         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
315         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
316         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
317         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
318
319         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08},
320         {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
321         {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
322         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
323         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
324         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00},
325         {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
326         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a},
327         /* Reset chip */
328         {SENSOR, OV9650_COM7, OV9650_REGISTER_RESET},
329         /* Enable double clock */
330         {SENSOR, OV9650_CLKRC, 0x80},
331         /* Do something out of spec with the power */
332         {SENSOR, OV9650_OFON, 0x40},
333
334         /* Set QQVGA */
335         {SENSOR, OV9650_COM1, 0x20},
336         /* Set fast AGC/AEC algorithm with unlimited step size */
337         {SENSOR, OV9650_COM8, OV9650_FAST_AGC_AEC |
338                               OV9650_AEC_UNLIM_STEP_SIZE |
339                               OV9650_AWB_EN | OV9650_AGC_EN},
340
341         {SENSOR, OV9650_CHLF, 0x10},
342         {SENSOR, OV9650_ARBLM, 0xbf},
343         {SENSOR, OV9650_ACOM38, 0x81},
344         /* Turn off color matrix coefficient double option */
345         {SENSOR, OV9650_COM16, 0x00},
346                 /* Enable color matrix for RGB/YUV, Delay Y channel,
347         set output Y/UV delay to 1 */
348         {SENSOR, OV9650_COM13, 0x19},
349         /* Enable digital BLC, Set output mode to U Y V Y */
350         {SENSOR, OV9650_TSLB, 0x0c},
351         /* Limit the AGC/AEC stable upper region */
352         {SENSOR, OV9650_COM24, 0x00},
353         /* Enable HREF and some out of spec things */
354         {SENSOR, OV9650_COM12, 0x73},
355                 /* Set all DBLC offset signs to positive and
356         do some out of spec stuff */
357         {SENSOR, OV9650_DBLC1, 0xdf},
358         {SENSOR, OV9650_COM21, 0x06},
359         {SENSOR, OV9650_RSVD35, 0x91},
360         /* Necessary, no camera stream without it */
361         {SENSOR, OV9650_RSVD16, 0x06},
362         {SENSOR, OV9650_RSVD94, 0x99},
363         {SENSOR, OV9650_RSVD95, 0x99},
364         {SENSOR, OV9650_RSVD96, 0x04},
365         /* Enable full range output */
366         {SENSOR, OV9650_COM15, 0x0},
367                 /* Enable HREF at optical black, enable ADBLC bias,
368         enable ADBLC, reset timings at format change */
369         {SENSOR, OV9650_COM6, 0x4b},
370         /* Subtract 32 from the B channel bias */
371         {SENSOR, OV9650_BBIAS, 0xa0},
372         /* Subtract 32 from the Gb channel bias */
373         {SENSOR, OV9650_GbBIAS, 0xa0},
374         /* Do not bypass the analog BLC and to some out of spec stuff */
375         {SENSOR, OV9650_Gr_COM, 0x00},
376         /* Subtract 32 from the R channel bias */
377         {SENSOR, OV9650_RBIAS, 0xa0},
378         /* Subtract 32 from the R channel bias */
379         {SENSOR, OV9650_RBIAS, 0x0},
380         {SENSOR, OV9650_COM26, 0x80},
381         {SENSOR, OV9650_ACOMA9, 0x98},
382         /* Set the AGC/AEC stable region upper limit */
383         {SENSOR, OV9650_AEW, 0x68},
384         /* Set the AGC/AEC stable region lower limit */
385         {SENSOR, OV9650_AEB, 0x5c},
386         /* Set the high and low limit nibbles to 3 */
387         {SENSOR, OV9650_VPT, 0xc3},
388                 /* Set the Automatic Gain Ceiling (AGC) to 128x,
389         drop VSYNC at frame drop,
390         limit exposure timing,
391         drop frame when the AEC step is larger than the exposure gap */
392         {SENSOR, OV9650_COM9, 0x6e},
393         /* Set VSYNC negative, Set RESET to SLHS (slave mode horizontal sync)
394         and set PWDN to SLVS (slave mode vertical sync) */
395         {SENSOR, OV9650_COM10, 0x42},
396         /* Set horizontal column start high to default value */
397         {SENSOR, OV9650_HSTART, 0x1a},
398         /* Set horizontal column end */
399         {SENSOR, OV9650_HSTOP, 0xbf},
400         /* Complementing register to the two writes above */
401         {SENSOR, OV9650_HREF, 0xb2},
402         /* Set vertical row start high bits */
403         {SENSOR, OV9650_VSTRT, 0x02},
404         /* Set vertical row end low bits */
405         {SENSOR, OV9650_VSTOP, 0x7e},
406         /* Set complementing vertical frame control */
407         {SENSOR, OV9650_VREF, 0x10},
408         /* Set raw RGB output format with VGA resolution */
409         {SENSOR, OV9650_COM7, OV9650_VGA_SELECT |
410                               OV9650_RGB_SELECT |
411                               OV9650_RAW_RGB_SELECT},
412         {SENSOR, OV9650_ADC, 0x04},
413         {SENSOR, OV9650_HV, 0x40},
414         /* Enable denoise, and white-pixel erase */
415         {SENSOR, OV9650_COM22, 0x23},
416
417         /* Set the high bits of the exposure value */
418         {SENSOR, OV9650_AECH, ((EXPOSURE_DEFAULT & 0xff00) >> 8)},
419
420         /* Set the low bits of the exposure value */
421         {SENSOR, OV9650_COM1, (EXPOSURE_DEFAULT & 0xff)},
422         {SENSOR, OV9650_GAIN, GAIN_DEFAULT},
423         {SENSOR, OV9650_BLUE, BLUE_GAIN_DEFAULT},
424         {SENSOR, OV9650_RED, RED_GAIN_DEFAULT},
425
426         {SENSOR, OV9650_COM3, OV9650_VARIOPIXEL},
427         {SENSOR, OV9650_COM5, OV9650_SYSTEM_CLK_SEL},
428
429         {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x82},
430         {BRIDGE, M5602_XB_LINE_OF_FRAME_L, 0x00},
431         {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
432         {BRIDGE, M5602_XB_PIX_OF_LINE_L, 0x00},
433         {BRIDGE, M5602_XB_SIG_INI, 0x01},
434         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
435         /* Moves the view window in a vertical orientation */
436         {BRIDGE, M5602_XB_VSYNC_PARA, 0x09},
437         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
438         {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
439         {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0},
440         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
441         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
442         {BRIDGE, M5602_XB_HSYNC_PARA, 0x5e},
443         {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
444         {BRIDGE, M5602_XB_HSYNC_PARA, 0xde}
445 };
446
447 static const unsigned char power_down_ov9650[][3] =
448 {
449         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
450         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
451         {SENSOR, OV9650_COM7, 0x80},
452         {SENSOR, OV9650_OFON, 0xf4},
453         {SENSOR, OV9650_MVFP, 0x80},
454         {SENSOR, OV9650_DBLV, 0x3f},
455         {SENSOR, OV9650_RSVD36, 0x49},
456         {SENSOR, OV9650_COM7, 0x05},
457
458         {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
459         {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
460         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
461         {BRIDGE, M5602_XB_GPIO_EN_L, 0x06},
462         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
463         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
464         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0}
465 };
466
467 #endif