blob: 9953e976695442142a77f9935f7e7d96e232bb65 [file] [log] [blame]
Erik Andrenc109f812008-10-01 04:51:53 -03001/*
2 * Driver for the s5k4aa sensor
3 *
Erik Andren0c505e682008-10-16 16:43:16 -03004 * Copyright (C) 2008 Erik Andrén
Erik Andrenc109f812008-10-01 04:51:53 -03005 * 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
Erik Andrén32500702008-11-20 04:02:44 -030044#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
Erik Andrenc109f812008-10-01 04:51:53 -030048#define S5K4AA_EXPOSURE_HI 0x17
49#define S5K4AA_EXPOSURE_LO 0x18
Erik Andr?n7ee46292009-01-14 03:37:03 -030050#define S5K4AA_BRIGHTNESS 0x1f /* (digital?) gain : 5 bits */
51#define S5K4AA_GAIN 0x20 /* (analogue?) gain : 7 bits */
Erik Andr?n3290d402009-01-13 16:40:28 -030052#define S5K4AA_NOISE_SUPP 0x37
Erik Andrenc109f812008-10-01 04:51:53 -030053
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
Erik Andr?n7ee46292009-01-14 03:37:03 -030061#define S5K4AA_DEFAULT_GAIN 0x5f
62#define S5K4AA_DEFAULT_BRIGHTNESS 0x10
Erik Andr?n71c6e592009-01-13 16:24:19 -030063
Erik Andrenc109f812008-10-01 04:51:53 -030064/*****************************************************************************/
65
66/* Kernel module parameters */
67extern int force_sensor;
Rusty Russell90ab5ee2012-01-13 09:32:20 +103068extern bool dump_sensor;
Erik Andrenc109f812008-10-01 04:51:53 -030069
70int s5k4aa_probe(struct sd *sd);
71int s5k4aa_init(struct sd *sd);
Hans de Goedec84e4122013-02-19 14:57:03 -030072int s5k4aa_init_controls(struct sd *sd);
Erik Andr?nad567ec2008-12-26 12:57:42 -030073int s5k4aa_start(struct sd *sd);
Erik Andr?na594fb42009-01-06 11:37:03 -030074void s5k4aa_disconnect(struct sd *sd);
Erik Andrenc109f812008-10-01 04:51:53 -030075
Erik Andr?ndac136e2008-12-30 17:35:34 -030076static const struct m5602_sensor s5k4aa = {
Erik Andr?ne4cc4fc2008-12-30 15:27:17 -030077 .name = "S5K4AA",
Erik Andr?na594fb42009-01-06 11:37:03 -030078 .i2c_slave_id = 0x5a,
79 .i2c_regW = 2,
80
Erik Andr?ne4cc4fc2008-12-30 15:27:17 -030081 .probe = s5k4aa_probe,
82 .init = s5k4aa_init,
Hans de Goedec84e4122013-02-19 14:57:03 -030083 .init_controls = s5k4aa_init_controls,
Erik Andr?ne4cc4fc2008-12-30 15:27:17 -030084 .start = s5k4aa_start,
Erik Andr?na594fb42009-01-06 11:37:03 -030085 .disconnect = s5k4aa_disconnect,
Erik Andrenc109f812008-10-01 04:51:53 -030086};
87
Jean-François Moine780e3122010-10-19 04:29:10 -030088static const unsigned char preinit_s5k4aa[][4] = {
Erik Andrenc109f812008-10-01 04:51:53 -030089 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
90 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
91 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
92 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
93 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
94 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
95 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
96
97 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
98 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
99 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
100 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
101 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
102 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
103 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
104 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
105 {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
106 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
107 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
108 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
109 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
110 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
111 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
112 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
113
114 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
115 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
116 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
117 {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
118 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
119 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
120 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
121 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
122 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
123 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
124 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
125 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
126 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
127
128 {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
129};
130
Jean-François Moine780e3122010-10-19 04:29:10 -0300131static const unsigned char init_s5k4aa[][4] = {
Erik Andrenc109f812008-10-01 04:51:53 -0300132 {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},
139
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},
156
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},
170
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},
Erik Andrenc109f812008-10-01 04:51:53 -0300178 {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
179 {SENSOR, 0x37, 0x00, 0x00},
Erik Andrenc109f812008-10-01 04:51:53 -0300180};
181
Jean-François Moine780e3122010-10-19 04:29:10 -0300182static const unsigned char VGA_s5k4aa[][4] = {
Erik Andr?nad567ec2008-12-26 12:57:42 -0300183 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
184 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
185 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
186 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
187 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
188 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
189 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
190 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 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 /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
195 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
196 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
197 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
198 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
199 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
200 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
201 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
202 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
203 /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
204 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
205 {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
206 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
207 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
208 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
209
210 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
211 {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
212 | S5K4AA_RM_COL_SKIP_2X, 0x00},
213 /* 0x37 : Fix image stability when light is too bright and improves
214 * image quality in 640x480, but worsens it in 1280x1024 */
215 {SENSOR, 0x37, 0x01, 0x00},
216 /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
217 {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
Erik Andr?n71c6e592009-01-13 16:24:19 -0300218 {SENSOR, S5K4AA_ROWSTART_LO, 0x29, 0x00},
Erik Andr?nad567ec2008-12-26 12:57:42 -0300219 {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
220 {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
221 /* window_height_hi, window_height_lo : 960 = 0x03c0 */
222 {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
223 {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
224 /* window_width_hi, window_width_lo : 1280 = 0x0500 */
225 {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
226 {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
227 {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
228 {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
229 {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
230 {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
231 {SENSOR, 0x11, 0x04, 0x00},
232 {SENSOR, 0x12, 0xc3, 0x00},
233 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
234 {SENSOR, 0x02, 0x0e, 0x00},
Erik Andr?nad567ec2008-12-26 12:57:42 -0300235};
236
Jean-François Moine780e3122010-10-19 04:29:10 -0300237static const unsigned char SXGA_s5k4aa[][4] = {
Erik Andrén4fcec142009-01-29 13:34:41 -0300238 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
239 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
240 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
241 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
242 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
243 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
244 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
245 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
246 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
247 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
248 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
249 /* VSYNC_PARA, VSYNC_PARA : img height 1024 = 0x0400 */
250 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
251 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
252 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
253 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
254 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
255 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
256 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
257 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
258 /* HSYNC_PARA, HSYNC_PARA : img width 1280 = 0x0500 */
259 {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
260 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
261 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
262 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
263 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
264
265 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
Grégory Lardière60d52ce2009-02-12 03:32:52 -0300266 {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP, 0x00},
Erik Andrén4fcec142009-01-29 13:34:41 -0300267 {SENSOR, 0x37, 0x01, 0x00},
268 {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
Grégory Lardière60d52ce2009-02-12 03:32:52 -0300269 {SENSOR, S5K4AA_ROWSTART_LO, 0x09, 0x00},
Erik Andrén4fcec142009-01-29 13:34:41 -0300270 {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
Grégory Lardière60d52ce2009-02-12 03:32:52 -0300271 {SENSOR, S5K4AA_COLSTART_LO, 0x0a, 0x00},
Erik Andrén4fcec142009-01-29 13:34:41 -0300272 {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x04, 0x00},
273 {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0x00, 0x00},
274 {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
275 {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
Grégory Lardière60d52ce2009-02-12 03:32:52 -0300276 {SENSOR, S5K4AA_H_BLANK_HI__, 0x01, 0x00},
Erik Andrén4fcec142009-01-29 13:34:41 -0300277 {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00},
278 {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
279 {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
280 {SENSOR, 0x11, 0x04, 0x00},
281 {SENSOR, 0x12, 0xc3, 0x00},
282 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
283 {SENSOR, 0x02, 0x0e, 0x00},
284};
Erik Andrenc109f812008-10-01 04:51:53 -0300285#endif