V4L/DVB (11417): gspca - m5602-ov9650: Autogain is on by default
[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_start(struct sd *sd);
69 int s5k4aa_power_down(struct sd *sd);
70
71 int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
72 int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
73 int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
74 int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
75 int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
76 int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
77 int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
78 int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val);
79
80 static const struct m5602_sensor s5k4aa = {
81         .name = "S5K4AA",
82         .probe = s5k4aa_probe,
83         .init = s5k4aa_init,
84         .start = s5k4aa_start,
85         .power_down = s5k4aa_power_down,
86         .i2c_slave_id = 0x5a,
87         .i2c_regW = 2,
88 };
89
90 static const unsigned char preinit_s5k4aa[][4] =
91 {
92         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
93         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
94         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
95         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
96         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
97         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
98         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
99
100         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
101         {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
102         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
103         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
104         {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
105         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
106         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
107         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
108         {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
109         {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
110         {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
111         {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
112         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
113         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
114         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
115         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
116
117         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
118         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
119         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
120         {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
121         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
122         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
123         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
124         {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
125         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
126         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
127         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
128         {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
129         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
130
131         {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
132 };
133
134 static const unsigned char init_s5k4aa[][4] =
135 {
136         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
137         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
138         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
139         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
140         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
141         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
142         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
143
144         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
145         {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
146         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
147         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
148         {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
149         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
150         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
151         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
152         {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
153         {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
154         {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
155         {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
156         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
157         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
158         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
159         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
160
161         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
162         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
163         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
164         {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
165         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
166         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
167         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
168         {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
169         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
170         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
171         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
172         {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
173         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
174
175         {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
176         {SENSOR, 0x36, 0x01, 0x00},
177         {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
178         {SENSOR, 0x7b, 0xff, 0x00},
179         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
180         {SENSOR, 0x0c, 0x05, 0x00},
181         {SENSOR, 0x02, 0x0e, 0x00},
182         {SENSOR, S5K4AA_GAIN_1, 0x0f, 0x00},
183         {SENSOR, S5K4AA_GAIN_2, 0x00, 0x00},
184         {SENSOR, S5K4AA_GLOBAL_GAIN__, 0x01, 0x00},
185         {SENSOR, 0x11, 0x00, 0x00},
186         {SENSOR, 0x12, 0x00, 0x00},
187         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
188         {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
189         {SENSOR, 0x37, 0x00, 0x00},
190         {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
191         {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
192         {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
193         {SENSOR, S5K4AA_COLSTART_LO, 0x0b, 0x00},
194         {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
195         {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc4, 0x00},
196         {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
197         {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x08, 0x00},
198         {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
199         {SENSOR, S5K4AA_H_BLANK_LO__, 0x48, 0x00},
200         {SENSOR, S5K4AA_EXPOSURE_HI, 0x00, 0x00},
201         {SENSOR, S5K4AA_EXPOSURE_LO, 0x43, 0x00},
202         {SENSOR, 0x11, 0x04, 0x00},
203         {SENSOR, 0x12, 0xc3, 0x00},
204         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
205
206         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
207         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
208         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
209         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
210         {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
211         {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
212         {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
213         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
214         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
215         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
216         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
217         /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
218         {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
219         {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
220         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
221         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
222         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
223         {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
224         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
225         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
226         /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
227         {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
228         {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
229         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
230         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
231         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
232
233         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
234         {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
235                 | S5K4AA_RM_COL_SKIP_2X, 0x00},
236         /* 0x37 : Fix image stability when light is too bright and improves
237          * image quality in 640x480, but worsens it in 1280x1024 */
238         {SENSOR, 0x37, 0x01, 0x00},
239         /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
240         {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
241         {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
242         {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
243         {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
244         /* window_height_hi, window_height_lo : 960 = 0x03c0 */
245         {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
246         {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
247         /* window_width_hi, window_width_lo : 1280 = 0x0500 */
248         {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
249         {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
250         {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
251         {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
252         {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
253         {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
254         {SENSOR, 0x11, 0x04, 0x00},
255         {SENSOR, 0x12, 0xc3, 0x00},
256         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
257         {SENSOR, 0x02, 0x0e, 0x00},
258         {SENSOR_LONG, S5K4AA_GLOBAL_GAIN__, 0x0f, 0x00},
259         {SENSOR, S5K4AA_GAIN_1, 0x0b, 0x00},
260         {SENSOR, S5K4AA_GAIN_2, 0xa0, 0x00}
261 };
262
263 static const unsigned char VGA_s5k4aa[][4] =
264 {
265         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
266         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
267         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
268         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
269         {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
270         {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
271         {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
272         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
273         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
274         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
275         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
276         /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
277         {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
278         {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
279         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
280         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
281         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
282         {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
283         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
284         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
285         /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
286         {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
287         {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
288         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
289         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
290         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
291
292         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
293         {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
294                 | S5K4AA_RM_COL_SKIP_2X, 0x00},
295         /* 0x37 : Fix image stability when light is too bright and improves
296          * image quality in 640x480, but worsens it in 1280x1024 */
297         {SENSOR, 0x37, 0x01, 0x00},
298         /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
299         {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
300         {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
301         {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
302         {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
303         /* window_height_hi, window_height_lo : 960 = 0x03c0 */
304         {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
305         {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
306         /* window_width_hi, window_width_lo : 1280 = 0x0500 */
307         {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
308         {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
309         {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
310         {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
311         {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
312         {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
313         {SENSOR, 0x11, 0x04, 0x00},
314         {SENSOR, 0x12, 0xc3, 0x00},
315         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
316         {SENSOR, 0x02, 0x0e, 0x00},
317         {SENSOR_LONG, S5K4AA_GLOBAL_GAIN__, 0x0f, 0x00},
318         {SENSOR, S5K4AA_GAIN_1, 0x0b, 0x00},
319         {SENSOR, S5K4AA_GAIN_2, 0xa0, 0x00}
320 };
321
322 #endif