V4L/DVB (10040): m5602 - ov9650: Activate variopixel
[linux-2.6] / drivers / media / video / gspca / m5602 / m5602_s5k4aa.h
1 /*
2  * Driver for the s5k4aa 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_S5K4AA_H_
20 #define M5602_S5K4AA_H_
21
22 #include <linux/dmi.h>
23
24 #include "m5602_sensor.h"
25
26 /*****************************************************************************/
27
28 #define S5K4AA_PAGE_MAP                 0xec
29
30 #define S5K4AA_PAGE_MAP_0               0x00
31 #define S5K4AA_PAGE_MAP_1               0x01
32 #define S5K4AA_PAGE_MAP_2               0x02
33
34 /* Sensor register definitions for page 0x02 */
35 #define S5K4AA_READ_MODE                0x03
36 #define S5K4AA_ROWSTART_HI              0x04
37 #define S5K4AA_ROWSTART_LO              0x05
38 #define S5K4AA_COLSTART_HI              0x06
39 #define S5K4AA_COLSTART_LO              0x07
40 #define S5K4AA_WINDOW_HEIGHT_HI         0x08
41 #define S5K4AA_WINDOW_HEIGHT_LO         0x09
42 #define S5K4AA_WINDOW_WIDTH_HI          0x0a
43 #define S5K4AA_WINDOW_WIDTH_LO          0x0b
44 #define S5K4AA_GLOBAL_GAIN__            0x0f
45 /* sync lost, if too low, reduces frame rate if too high */
46 #define S5K4AA_H_BLANK_HI__             0x1d
47 #define S5K4AA_H_BLANK_LO__             0x1e
48 #define S5K4AA_EXPOSURE_HI              0x17
49 #define S5K4AA_EXPOSURE_LO              0x18
50 #define S5K4AA_GAIN_1                   0x1f /* (digital?) gain : 5 bits */
51 #define S5K4AA_GAIN_2                   0x20 /* (analogue?) gain : 7 bits */
52
53 #define S5K4AA_RM_ROW_SKIP_4X           0x08
54 #define S5K4AA_RM_ROW_SKIP_2X           0x04
55 #define S5K4AA_RM_COL_SKIP_4X           0x02
56 #define S5K4AA_RM_COL_SKIP_2X           0x01
57 #define S5K4AA_RM_H_FLIP                0x40
58 #define S5K4AA_RM_V_FLIP                0x80
59
60 /*****************************************************************************/
61
62 /* Kernel module parameters */
63 extern int force_sensor;
64 extern int dump_sensor;
65
66 int s5k4aa_probe(struct sd *sd);
67 int s5k4aa_init(struct sd *sd);
68 int s5k4aa_power_down(struct sd *sd);
69
70 int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
71 int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
72 int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
73 int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
74 int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
75 int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
76 int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
77 int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val);
78
79 static struct m5602_sensor s5k4aa = {
80         .name = "S5K4AA",
81         .probe = s5k4aa_probe,
82         .init = s5k4aa_init,
83         .power_down = s5k4aa_power_down,
84         .i2c_slave_id = 0x5a,
85         .i2c_regW = 2,
86         .nctrls = 4,
87         .ctrls = {
88         {
89                 {
90                         .id             = V4L2_CID_VFLIP,
91                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
92                         .name           = "vertical flip",
93                         .minimum        = 0,
94                         .maximum        = 1,
95                         .step           = 1,
96                         .default_value  = 0
97                 },
98                 .set = s5k4aa_set_vflip,
99                 .get = s5k4aa_get_vflip
100
101         }, {
102                 {
103                         .id             = V4L2_CID_HFLIP,
104                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
105                         .name           = "horizontal flip",
106                         .minimum        = 0,
107                         .maximum        = 1,
108                         .step           = 1,
109                         .default_value  = 0
110                 },
111                 .set = s5k4aa_set_hflip,
112                 .get = s5k4aa_get_hflip
113
114         }, {
115                 {
116                         .id             = V4L2_CID_GAIN,
117                         .type           = V4L2_CTRL_TYPE_INTEGER,
118                         .name           = "Gain",
119                         .minimum        = 0,
120                         .maximum        = 127,
121                         .step           = 1,
122                         .default_value  = 0xa0,
123                         .flags          = V4L2_CTRL_FLAG_SLIDER
124                 },
125                 .set = s5k4aa_set_gain,
126                 .get = s5k4aa_get_gain
127         }, {
128                 {
129                         .id             = V4L2_CID_EXPOSURE,
130                         .type           = V4L2_CTRL_TYPE_INTEGER,
131                         .name           = "Exposure",
132                         .minimum        = 13,
133                         .maximum        = 0xfff,
134                         .step           = 1,
135                         .default_value  = 0x100,
136                         .flags          = V4L2_CTRL_FLAG_SLIDER
137                 },
138                 .set = s5k4aa_set_exposure,
139                 .get = s5k4aa_get_exposure
140         }
141         },
142
143         .nmodes = 1,
144         .modes = {
145         {
146                 M5602_DEFAULT_FRAME_WIDTH,
147                 M5602_DEFAULT_FRAME_HEIGHT,
148                 V4L2_PIX_FMT_SBGGR8,
149                 V4L2_FIELD_NONE,
150                 .sizeimage =
151                         M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
152                 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
153                 .colorspace = V4L2_COLORSPACE_SRGB,
154                 .priv = 1
155         }
156         }
157 };
158
159 static const unsigned char preinit_s5k4aa[][4] =
160 {
161         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
162         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
163         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
164         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
165         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
166         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
167         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
168
169         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
170         {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
171         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
172         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
173         {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
174         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
175         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
176         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
177         {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
178         {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
179         {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
180         {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
181         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
182         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
183         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
184         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
185
186         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
187         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
188         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
189         {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
190         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
191         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
192         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
193         {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
194         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
195         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
196         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
197         {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
198         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
199
200         {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
201 };
202
203 static const unsigned char init_s5k4aa[][4] =
204 {
205         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
206         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
207         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
208         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
209         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
210         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
211         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
212
213         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
214         {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
215         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
216         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
217         {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
218         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
219         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
220         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
221         {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
222         {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
223         {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
224         {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
225         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
226         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
227         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
228         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
229
230         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
231         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
232         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
233         {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
234         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
235         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
236         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
237         {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
238         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
239         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
240         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
241         {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
242         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
243
244         {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
245         {SENSOR, 0x36, 0x01, 0x00},
246         {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
247         {SENSOR, 0x7b, 0xff, 0x00},
248         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
249         {SENSOR, 0x0c, 0x05, 0x00},
250         {SENSOR, 0x02, 0x0e, 0x00},
251         {SENSOR, S5K4AA_GAIN_1, 0x0f, 0x00},
252         {SENSOR, S5K4AA_GAIN_2, 0x00, 0x00},
253         {SENSOR, S5K4AA_GLOBAL_GAIN__, 0x01, 0x00},
254         {SENSOR, 0x11, 0x00, 0x00},
255         {SENSOR, 0x12, 0x00, 0x00},
256         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
257         {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
258         {SENSOR, 0x37, 0x00, 0x00},
259         {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
260         {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
261         {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
262         {SENSOR, S5K4AA_COLSTART_LO, 0x0b, 0x00},
263         {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
264         {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc4, 0x00},
265         {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
266         {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x08, 0x00},
267         {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
268         {SENSOR, S5K4AA_H_BLANK_LO__, 0x48, 0x00},
269         {SENSOR, S5K4AA_EXPOSURE_HI, 0x00, 0x00},
270         {SENSOR, S5K4AA_EXPOSURE_LO, 0x43, 0x00},
271         {SENSOR, 0x11, 0x04, 0x00},
272         {SENSOR, 0x12, 0xc3, 0x00},
273         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
274
275         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
276         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
277         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
278         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
279         {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
280         {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
281         {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
282         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
283         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
284         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
285         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
286         /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
287         {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
288         {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
289         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
290         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
291         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
292         {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
293         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
294         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
295         /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
296         {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
297         {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
298         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
299         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
300         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
301
302         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
303         {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
304                 | S5K4AA_RM_COL_SKIP_2X, 0x00},
305         /* 0x37 : Fix image stability when light is too bright and improves
306          * image quality in 640x480, but worsens it in 1280x1024 */
307         {SENSOR, 0x37, 0x01, 0x00},
308         /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
309         {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
310         {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
311         {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
312         {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
313         /* window_height_hi, window_height_lo : 960 = 0x03c0 */
314         {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
315         {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
316         /* window_width_hi, window_width_lo : 1280 = 0x0500 */
317         {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
318         {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
319         {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
320         {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
321         {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
322         {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
323         {SENSOR, 0x11, 0x04, 0x00},
324         {SENSOR, 0x12, 0xc3, 0x00},
325         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
326         {SENSOR, 0x02, 0x0e, 0x00},
327         {SENSOR_LONG, S5K4AA_GLOBAL_GAIN__, 0x0f, 0x00},
328         {SENSOR, S5K4AA_GAIN_1, 0x0b, 0x00},
329         {SENSOR, S5K4AA_GAIN_2, 0xa0, 0x00}
330 };
331
332 #endif