Merge commit 'v2.6.28-rc6' into core/debug
[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 /* Only a guess ATM !!! */
45 #define S5K4AA_H_BLANK_HI__             0x1d /* Only a guess ATM !!! sync lost
46                                                 if too low, reduces frame rate
47                                                 if too high */
48 #define S5K4AA_H_BLANK_LO__             0x1e /* Only a guess ATM !!! */
49 #define S5K4AA_EXPOSURE_HI              0x17
50 #define S5K4AA_EXPOSURE_LO              0x18
51 #define S5K4AA_GAIN_1                   0x1f /* (digital?) gain : 5 bits */
52 #define S5K4AA_GAIN_2                   0x20 /* (analogue?) gain : 7 bits */
53
54 #define S5K4AA_RM_ROW_SKIP_4X           0x08
55 #define S5K4AA_RM_ROW_SKIP_2X           0x04
56 #define S5K4AA_RM_COL_SKIP_4X           0x02
57 #define S5K4AA_RM_COL_SKIP_2X           0x01
58 #define S5K4AA_RM_H_FLIP                0x40
59 #define S5K4AA_RM_V_FLIP                0x80
60
61 /*****************************************************************************/
62
63 /* Kernel module parameters */
64 extern int force_sensor;
65 extern int dump_sensor;
66
67 int s5k4aa_probe(struct sd *sd);
68 int s5k4aa_init(struct sd *sd);
69 int s5k4aa_power_down(struct sd *sd);
70
71 void s5k4aa_dump_registers(struct sd *sd);
72
73 int s5k4aa_read_sensor(struct sd *sd, const u8 address,
74                        u8 *i2c_data, const u8 len);
75 int s5k4aa_write_sensor(struct sd *sd, const u8 address,
76                         u8 *i2c_data, const u8 len);
77
78 int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
79 int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
80 int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
81 int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
82 int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
83 int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
84 int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
85 int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val);
86
87 static struct m5602_sensor s5k4aa = {
88         .name = "S5K4AA",
89         .probe = s5k4aa_probe,
90         .init = s5k4aa_init,
91         .power_down = s5k4aa_power_down,
92         .read_sensor = s5k4aa_read_sensor,
93         .write_sensor = s5k4aa_write_sensor,
94         .i2c_slave_id = 0x5a,
95         .nctrls = 4,
96         .ctrls = {
97         {
98                 {
99                         .id             = V4L2_CID_VFLIP,
100                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
101                         .name           = "vertical flip",
102                         .minimum        = 0,
103                         .maximum        = 1,
104                         .step           = 1,
105                         .default_value  = 0
106                 },
107                 .set = s5k4aa_set_vflip,
108                 .get = s5k4aa_get_vflip
109
110         }, {
111                 {
112                         .id             = V4L2_CID_HFLIP,
113                         .type           = V4L2_CTRL_TYPE_BOOLEAN,
114                         .name           = "horizontal flip",
115                         .minimum        = 0,
116                         .maximum        = 1,
117                         .step           = 1,
118                         .default_value  = 0
119                 },
120                 .set = s5k4aa_set_hflip,
121                 .get = s5k4aa_get_hflip
122
123         }, {
124                 {
125                         .id             = V4L2_CID_GAIN,
126                         .type           = V4L2_CTRL_TYPE_INTEGER,
127                         .name           = "Gain",
128                         .minimum        = 0,
129                         .maximum        = 127,
130                         .step           = 1,
131                         .default_value  = 0xa0,
132                         .flags          = V4L2_CTRL_FLAG_SLIDER
133                 },
134                 .set = s5k4aa_set_gain,
135                 .get = s5k4aa_get_gain
136         }, {
137                 {
138                         .id             = V4L2_CID_EXPOSURE,
139                         .type           = V4L2_CTRL_TYPE_INTEGER,
140                         .name           = "Exposure",
141                         .minimum        = 13,
142                         .maximum        = 0xfff,
143                         .step           = 1,
144                         .default_value  = 0x100,
145                         .flags          = V4L2_CTRL_FLAG_SLIDER
146                 },
147                 .set = s5k4aa_set_exposure,
148                 .get = s5k4aa_get_exposure
149         }
150         },
151
152         .nmodes = 1,
153         .modes = {
154         {
155                 M5602_DEFAULT_FRAME_WIDTH,
156                 M5602_DEFAULT_FRAME_HEIGHT,
157                 V4L2_PIX_FMT_SBGGR8,
158                 V4L2_FIELD_NONE,
159                 .sizeimage =
160                         M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
161                 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
162                 .colorspace = V4L2_COLORSPACE_SRGB,
163                 .priv = 1
164         }
165         }
166 };
167
168 static const unsigned char preinit_s5k4aa[][4] =
169 {
170         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
171         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
172         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
173         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
174         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
175         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
176         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
177
178         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
179         {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
180         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
181         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
182         {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
183         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
184         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
185         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
186         {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
187         {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
188         {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
189         {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
190         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
191         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
192         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
193         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
194
195         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
196         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
197         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
198         {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
199         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
200         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
201         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
202         {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
203         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
204         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
205         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
206         {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
207         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
208
209         {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
210 };
211
212 static const unsigned char init_s5k4aa[][4] =
213 {
214         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
215         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
216         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
217         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
218         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
219         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
220         {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
221
222         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
223         {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
224         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
225         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
226         {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
227         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
228         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
229         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
230         {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
231         {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
232         {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
233         {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
234         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
235         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
236         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
237         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
238
239         {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
240         {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
241         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
242         {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
243         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
244         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
245         {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
246         {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
247         {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
248         {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
249         {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
250         {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
251         {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
252
253         {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
254         {SENSOR, 0x36, 0x01, 0x00},
255         {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
256         {SENSOR, 0x7b, 0xff, 0x00},
257         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
258         {SENSOR, 0x0c, 0x05, 0x00},
259         {SENSOR, 0x02, 0x0e, 0x00},
260         {SENSOR, S5K4AA_GAIN_1, 0x0f, 0x00},
261         {SENSOR, S5K4AA_GAIN_2, 0x00, 0x00},
262         {SENSOR, S5K4AA_GLOBAL_GAIN__, 0x01, 0x00},
263         {SENSOR, 0x11, 0x00, 0x00},
264         {SENSOR, 0x12, 0x00, 0x00},
265         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
266         {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
267         {SENSOR, 0x37, 0x00, 0x00},
268         {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
269         {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
270         {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
271         {SENSOR, S5K4AA_COLSTART_LO, 0x0b, 0x00},
272         {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
273         {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc4, 0x00},
274         {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
275         {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x08, 0x00},
276         {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
277         {SENSOR, S5K4AA_H_BLANK_LO__, 0x48, 0x00},
278         {SENSOR, S5K4AA_EXPOSURE_HI, 0x00, 0x00},
279         {SENSOR, S5K4AA_EXPOSURE_LO, 0x43, 0x00},
280         {SENSOR, 0x11, 0x04, 0x00},
281         {SENSOR, 0x12, 0xc3, 0x00},
282         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
283
284         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
285         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
286         {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
287         {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
288         {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
289         {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
290         {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
291         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
292         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
293         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
294         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
295         /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
296         {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
297         {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
298         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
299         {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
300         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
301         {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
302         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
303         {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
304         /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
305         {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
306         {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
307         {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
308         {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
309         {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
310
311         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
312         {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
313                 | S5K4AA_RM_COL_SKIP_2X, 0x00},
314         /* 0x37 : Fix image stability when light is too bright and improves
315          * image quality in 640x480, but worsens it in 1280x1024 */
316         {SENSOR, 0x37, 0x01, 0x00},
317         /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
318         {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
319         {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
320         {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
321         {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
322         /* window_height_hi, window_height_lo : 960 = 0x03c0 */
323         {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
324         {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
325         /* window_width_hi, window_width_lo : 1280 = 0x0500 */
326         {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
327         {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
328         {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
329         {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
330         {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
331         {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
332         {SENSOR, 0x11, 0x04, 0x00},
333         {SENSOR, 0x12, 0xc3, 0x00},
334         {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
335         {SENSOR, 0x02, 0x0e, 0x00},
336         {SENSOR_LONG, S5K4AA_GLOBAL_GAIN__, 0x0f, 0x00},
337         {SENSOR, S5K4AA_GAIN_1, 0x0b, 0x00},
338         {SENSOR, S5K4AA_GAIN_2, 0xa0, 0x00}
339 };
340
341 static
342     const
343         struct dmi_system_id s5k4aa_vflip_dmi_table[] = {
344         {
345                 .ident = "Fujitsu-Siemens Amilo Xa 2528",
346                 .matches = {
347                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
348                         DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xa 2528")
349                 }
350         },
351         {
352                 .ident = "Fujitsu-Siemens Amilo Xi 2550",
353                 .matches = {
354                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
355                         DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 2550")
356                 }
357         },
358                 {
359                 .ident = "MSI GX700",
360                 .matches = {
361                         DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
362                         DMI_MATCH(DMI_PRODUCT_NAME, "GX700"),
363                         DMI_MATCH(DMI_BIOS_DATE, "07/26/2007")
364                 }
365         },
366         { }
367 };
368
369 #endif