Full support for Ginger Console
[linux-ginger.git] / drivers / media / video / gspca / m5602 / m5602_s5k4aa.h
blob4440da4e7f0ff3595fde22eabf7b3e4add002fd9
1 /*
2 * Driver for the s5k4aa sensor
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>
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
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.
19 #ifndef M5602_S5K4AA_H_
20 #define M5602_S5K4AA_H_
22 #include <linux/dmi.h>
24 #include "m5602_sensor.h"
26 /*****************************************************************************/
28 #define S5K4AA_PAGE_MAP 0xec
30 #define S5K4AA_PAGE_MAP_0 0x00
31 #define S5K4AA_PAGE_MAP_1 0x01
32 #define S5K4AA_PAGE_MAP_2 0x02
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_BRIGHTNESS 0x1f /* (digital?) gain : 5 bits */
51 #define S5K4AA_GAIN 0x20 /* (analogue?) gain : 7 bits */
52 #define S5K4AA_NOISE_SUPP 0x37
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
61 #define S5K4AA_DEFAULT_GAIN 0x5f
62 #define S5K4AA_DEFAULT_BRIGHTNESS 0x10
64 /*****************************************************************************/
66 /* Kernel module parameters */
67 extern int force_sensor;
68 extern int dump_sensor;
70 int s5k4aa_probe(struct sd *sd);
71 int s5k4aa_init(struct sd *sd);
72 int s5k4aa_start(struct sd *sd);
73 void s5k4aa_disconnect(struct sd *sd);
75 static const struct m5602_sensor s5k4aa = {
76 .name = "S5K4AA",
77 .i2c_slave_id = 0x5a,
78 .i2c_regW = 2,
80 .probe = s5k4aa_probe,
81 .init = s5k4aa_init,
82 .start = s5k4aa_start,
83 .disconnect = s5k4aa_disconnect,
86 static const unsigned char preinit_s5k4aa[][4] =
88 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
89 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
90 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
91 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
92 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
93 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
94 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
96 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
97 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
98 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
99 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
100 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
101 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
102 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
103 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
104 {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
105 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
106 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
107 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
108 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
109 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
110 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
111 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
113 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
114 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
115 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
116 {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
117 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
118 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
119 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
120 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
121 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
122 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
123 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
124 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
125 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
127 {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
130 static const unsigned char init_s5k4aa[][4] =
132 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
133 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
134 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
135 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
136 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
137 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
138 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
140 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
141 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
142 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
143 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
144 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
145 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
146 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
147 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
148 {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
149 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
150 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
151 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
152 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
153 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
154 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
155 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
157 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
158 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
159 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
160 {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
161 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
162 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
163 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
164 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
165 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
166 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
167 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
168 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
169 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
171 {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
172 {SENSOR, 0x36, 0x01, 0x00},
173 {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
174 {SENSOR, 0x7b, 0xff, 0x00},
175 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
176 {SENSOR, 0x0c, 0x05, 0x00},
177 {SENSOR, 0x02, 0x0e, 0x00},
178 {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
179 {SENSOR, 0x37, 0x00, 0x00},
182 static const unsigned char VGA_s5k4aa[][4] =
184 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
185 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
186 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
187 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
188 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
189 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
190 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
191 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
192 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
193 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
194 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
195 /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
196 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
197 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
198 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
199 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
200 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
201 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
202 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
203 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
204 /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
205 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
206 {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
207 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
208 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
209 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
211 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
212 {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
213 | S5K4AA_RM_COL_SKIP_2X, 0x00},
214 /* 0x37 : Fix image stability when light is too bright and improves
215 * image quality in 640x480, but worsens it in 1280x1024 */
216 {SENSOR, 0x37, 0x01, 0x00},
217 /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
218 {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
219 {SENSOR, S5K4AA_ROWSTART_LO, 0x29, 0x00},
220 {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
221 {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
222 /* window_height_hi, window_height_lo : 960 = 0x03c0 */
223 {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
224 {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
225 /* window_width_hi, window_width_lo : 1280 = 0x0500 */
226 {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
227 {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
228 {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
229 {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
230 {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
231 {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
232 {SENSOR, 0x11, 0x04, 0x00},
233 {SENSOR, 0x12, 0xc3, 0x00},
234 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
235 {SENSOR, 0x02, 0x0e, 0x00},
238 static const unsigned char SXGA_s5k4aa[][4] =
240 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
241 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
242 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
243 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
244 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
245 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
246 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
247 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
248 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
249 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
250 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
251 /* VSYNC_PARA, VSYNC_PARA : img height 1024 = 0x0400 */
252 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
253 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
254 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
255 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
256 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
257 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
258 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
259 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
260 /* HSYNC_PARA, HSYNC_PARA : img width 1280 = 0x0500 */
261 {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
262 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
263 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
264 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
265 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
267 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
268 {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP, 0x00},
269 {SENSOR, 0x37, 0x01, 0x00},
270 {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
271 {SENSOR, S5K4AA_ROWSTART_LO, 0x09, 0x00},
272 {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
273 {SENSOR, S5K4AA_COLSTART_LO, 0x0a, 0x00},
274 {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x04, 0x00},
275 {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0x00, 0x00},
276 {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
277 {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
278 {SENSOR, S5K4AA_H_BLANK_HI__, 0x01, 0x00},
279 {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00},
280 {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
281 {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
282 {SENSOR, 0x11, 0x04, 0x00},
283 {SENSOR, 0x12, 0xc3, 0x00},
284 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
285 {SENSOR, 0x02, 0x0e, 0x00},
289 #endif