Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
m5602_s5k4aa.h
Go to the documentation of this file.
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 <[email protected]>
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_BRIGHTNESS 0x1f /* (digital?) gain : 5 bits */
51 #define S5K4AA_GAIN 0x20 /* (analogue?) gain : 7 bits */
52 #define S5K4AA_NOISE_SUPP 0x37
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 #define S5K4AA_DEFAULT_GAIN 0x5f
62 #define S5K4AA_DEFAULT_BRIGHTNESS 0x10
63 
64 /*****************************************************************************/
65 
66 /* Kernel module parameters */
67 extern int force_sensor;
68 extern bool dump_sensor;
69 
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);
74 
75 static const struct m5602_sensor s5k4aa = {
76  .name = "S5K4AA",
77  .i2c_slave_id = 0x5a,
78  .i2c_regW = 2,
79 
80  .probe = s5k4aa_probe,
81  .init = s5k4aa_init,
82  .start = s5k4aa_start,
83  .disconnect = s5k4aa_disconnect,
84 };
85 
86 static const unsigned char preinit_s5k4aa[][4] = {
87  {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
88  {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
89  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
90  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
91  {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
92  {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
93  {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
94 
95  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
96  {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
97  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
98  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
99  {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
100  {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
101  {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
102  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
103  {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
104  {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
105  {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
106  {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
107  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
108  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
109  {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
110  {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
111 
112  {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
113  {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
114  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
115  {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
116  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
117  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
118  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
119  {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
120  {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
121  {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
122  {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
123  {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
124  {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
125 
126  {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
127 };
128 
129 static const unsigned char init_s5k4aa[][4] = {
130  {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
131  {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
132  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
133  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
134  {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
135  {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
136  {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
137 
138  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
139  {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
140  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
141  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
142  {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
143  {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
144  {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
145  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
146  {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
147  {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
148  {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
149  {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
150  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
151  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
152  {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
153  {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
154 
155  {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
156  {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
157  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
158  {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
159  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
160  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
161  {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
162  {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
163  {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
164  {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
165  {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
166  {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
167  {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
168 
169  {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
170  {SENSOR, 0x36, 0x01, 0x00},
171  {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
172  {SENSOR, 0x7b, 0xff, 0x00},
173  {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
174  {SENSOR, 0x0c, 0x05, 0x00},
175  {SENSOR, 0x02, 0x0e, 0x00},
176  {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
177  {SENSOR, 0x37, 0x00, 0x00},
178 };
179 
180 static const unsigned char VGA_s5k4aa[][4] = {
181  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 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  {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
186  {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
187  {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
188  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
189  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
190  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
191  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
192  /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
193  {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
194  {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
195  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
196  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
197  {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
198  {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
199  {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
200  {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
201  /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
202  {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
203  {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
204  {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
205  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
206  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
207 
208  {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
210  | S5K4AA_RM_COL_SKIP_2X, 0x00},
211  /* 0x37 : Fix image stability when light is too bright and improves
212  * image quality in 640x480, but worsens it in 1280x1024 */
213  {SENSOR, 0x37, 0x01, 0x00},
214  /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
215  {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
216  {SENSOR, S5K4AA_ROWSTART_LO, 0x29, 0x00},
217  {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
218  {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
219  /* window_height_hi, window_height_lo : 960 = 0x03c0 */
220  {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
221  {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
222  /* window_width_hi, window_width_lo : 1280 = 0x0500 */
223  {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
224  {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
225  {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
226  {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
227  {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
228  {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
229  {SENSOR, 0x11, 0x04, 0x00},
230  {SENSOR, 0x12, 0xc3, 0x00},
231  {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
232  {SENSOR, 0x02, 0x0e, 0x00},
233 };
234 
235 static const unsigned char SXGA_s5k4aa[][4] = {
236  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
237  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
238  {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
239  {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
240  {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
241  {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
242  {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
243  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
244  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
245  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
246  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
247  /* VSYNC_PARA, VSYNC_PARA : img height 1024 = 0x0400 */
248  {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
249  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
250  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
251  {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
252  {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
253  {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
254  {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
255  {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
256  /* HSYNC_PARA, HSYNC_PARA : img width 1280 = 0x0500 */
257  {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
258  {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
259  {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
260  {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
261  {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
262 
263  {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
265  {SENSOR, 0x37, 0x01, 0x00},
266  {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
267  {SENSOR, S5K4AA_ROWSTART_LO, 0x09, 0x00},
268  {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
269  {SENSOR, S5K4AA_COLSTART_LO, 0x0a, 0x00},
270  {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x04, 0x00},
271  {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0x00, 0x00},
272  {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
273  {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
274  {SENSOR, S5K4AA_H_BLANK_HI__, 0x01, 0x00},
275  {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00},
276  {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
277  {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
278  {SENSOR, 0x11, 0x04, 0x00},
279  {SENSOR, 0x12, 0xc3, 0x00},
280  {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
281  {SENSOR, 0x02, 0x0e, 0x00},
282 };
283 #endif