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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include "m5602_s5k4aa.h"
23 static const unsigned char preinit_s5k4aa
[][4] = {
24 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
25 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
26 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
27 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
28 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
29 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x0d, 0x00},
30 {BRIDGE
, M5602_XB_SENSOR_CTRL
, 0x00, 0x00},
32 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
33 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x08, 0x00},
34 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0xb0, 0x00},
35 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0x80, 0x00},
36 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x3f, 0x00},
37 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x3f, 0x00},
38 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
39 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
40 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x00, 0x00},
41 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0xff, 0x00},
42 {BRIDGE
, M5602_XB_GPIO_DIR_L
, 0xff, 0x00},
43 {BRIDGE
, M5602_XB_GPIO_DAT_L
, 0x00, 0x00},
44 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
45 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
46 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
47 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
49 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
50 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
51 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
52 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x14, 0x00},
53 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
54 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xf0, 0x00},
55 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
56 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x1c, 0x00},
57 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x06, 0x00},
58 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x06, 0x00},
59 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
60 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0x00, 0x00},
61 {BRIDGE
, M5602_XB_I2C_CLK_DIV
, 0x20, 0x00},
63 {SENSOR
, S5K4AA_PAGE_MAP
, 0x00, 0x00}
66 static const unsigned char init_s5k4aa
[][4] = {
67 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
68 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
69 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
70 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
71 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
72 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x0d, 0x00},
73 {BRIDGE
, M5602_XB_SENSOR_CTRL
, 0x00, 0x00},
75 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
76 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x08, 0x00},
77 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0xb0, 0x00},
78 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0x80, 0x00},
79 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x3f, 0x00},
80 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x3f, 0x00},
81 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
82 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
83 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x00, 0x00},
84 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0xff, 0x00},
85 {BRIDGE
, M5602_XB_GPIO_DIR_L
, 0xff, 0x00},
86 {BRIDGE
, M5602_XB_GPIO_DAT_L
, 0x00, 0x00},
87 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
88 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
89 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
90 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
92 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
93 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
94 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
95 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x14, 0x00},
96 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
97 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xf0, 0x00},
98 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
99 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x1c, 0x00},
100 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x06, 0x00},
101 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x06, 0x00},
102 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
103 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0x00, 0x00},
104 {BRIDGE
, M5602_XB_I2C_CLK_DIV
, 0x20, 0x00},
106 {SENSOR
, S5K4AA_PAGE_MAP
, 0x07, 0x00},
107 {SENSOR
, 0x36, 0x01, 0x00},
108 {SENSOR
, S5K4AA_PAGE_MAP
, 0x00, 0x00},
109 {SENSOR
, 0x7b, 0xff, 0x00},
110 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
111 {SENSOR
, 0x0c, 0x05, 0x00},
112 {SENSOR
, 0x02, 0x0e, 0x00},
113 {SENSOR
, S5K4AA_READ_MODE
, 0xa0, 0x00},
114 {SENSOR
, 0x37, 0x00, 0x00},
117 static const unsigned char VGA_s5k4aa
[][4] = {
118 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x06, 0x00},
119 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
120 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
121 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
122 {BRIDGE
, M5602_XB_LINE_OF_FRAME_H
, 0x81, 0x00},
123 {BRIDGE
, M5602_XB_PIX_OF_LINE_H
, 0x82, 0x00},
124 {BRIDGE
, M5602_XB_SIG_INI
, 0x01, 0x00},
125 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
126 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
127 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
128 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
129 /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
130 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x01, 0x00},
131 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0xe0, 0x00},
132 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
133 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
134 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
135 {BRIDGE
, M5602_XB_SIG_INI
, 0x02, 0x00},
136 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
137 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
138 /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
139 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x02, 0x00},
140 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x80, 0x00},
141 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
142 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
143 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xa0, 0x00}, /* 48 MHz */
145 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
146 {SENSOR
, S5K4AA_READ_MODE
, S5K4AA_RM_H_FLIP
| S5K4AA_RM_ROW_SKIP_2X
147 | S5K4AA_RM_COL_SKIP_2X
, 0x00},
148 /* 0x37 : Fix image stability when light is too bright and improves
149 * image quality in 640x480, but worsens it in 1280x1024 */
150 {SENSOR
, 0x37, 0x01, 0x00},
151 /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
152 {SENSOR
, S5K4AA_ROWSTART_HI
, 0x00, 0x00},
153 {SENSOR
, S5K4AA_ROWSTART_LO
, 0x29, 0x00},
154 {SENSOR
, S5K4AA_COLSTART_HI
, 0x00, 0x00},
155 {SENSOR
, S5K4AA_COLSTART_LO
, 0x0c, 0x00},
156 /* window_height_hi, window_height_lo : 960 = 0x03c0 */
157 {SENSOR
, S5K4AA_WINDOW_HEIGHT_HI
, 0x03, 0x00},
158 {SENSOR
, S5K4AA_WINDOW_HEIGHT_LO
, 0xc0, 0x00},
159 /* window_width_hi, window_width_lo : 1280 = 0x0500 */
160 {SENSOR
, S5K4AA_WINDOW_WIDTH_HI
, 0x05, 0x00},
161 {SENSOR
, S5K4AA_WINDOW_WIDTH_LO
, 0x00, 0x00},
162 {SENSOR
, S5K4AA_H_BLANK_HI__
, 0x00, 0x00},
163 {SENSOR
, S5K4AA_H_BLANK_LO__
, 0xa8, 0x00}, /* helps to sync... */
164 {SENSOR
, S5K4AA_EXPOSURE_HI
, 0x01, 0x00},
165 {SENSOR
, S5K4AA_EXPOSURE_LO
, 0x00, 0x00},
166 {SENSOR
, 0x11, 0x04, 0x00},
167 {SENSOR
, 0x12, 0xc3, 0x00},
168 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
169 {SENSOR
, 0x02, 0x0e, 0x00},
172 static const unsigned char SXGA_s5k4aa
[][4] = {
173 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x06, 0x00},
174 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
175 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
176 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
177 {BRIDGE
, M5602_XB_LINE_OF_FRAME_H
, 0x81, 0x00},
178 {BRIDGE
, M5602_XB_PIX_OF_LINE_H
, 0x82, 0x00},
179 {BRIDGE
, M5602_XB_SIG_INI
, 0x01, 0x00},
180 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
181 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
182 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
183 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
184 /* VSYNC_PARA, VSYNC_PARA : img height 1024 = 0x0400 */
185 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x04, 0x00},
186 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
187 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
188 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
189 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
190 {BRIDGE
, M5602_XB_SIG_INI
, 0x02, 0x00},
191 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
192 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
193 /* HSYNC_PARA, HSYNC_PARA : img width 1280 = 0x0500 */
194 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x05, 0x00},
195 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
196 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
197 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
198 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xa0, 0x00}, /* 48 MHz */
200 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
201 {SENSOR
, S5K4AA_READ_MODE
, S5K4AA_RM_H_FLIP
, 0x00},
202 {SENSOR
, 0x37, 0x01, 0x00},
203 {SENSOR
, S5K4AA_ROWSTART_HI
, 0x00, 0x00},
204 {SENSOR
, S5K4AA_ROWSTART_LO
, 0x09, 0x00},
205 {SENSOR
, S5K4AA_COLSTART_HI
, 0x00, 0x00},
206 {SENSOR
, S5K4AA_COLSTART_LO
, 0x0a, 0x00},
207 {SENSOR
, S5K4AA_WINDOW_HEIGHT_HI
, 0x04, 0x00},
208 {SENSOR
, S5K4AA_WINDOW_HEIGHT_LO
, 0x00, 0x00},
209 {SENSOR
, S5K4AA_WINDOW_WIDTH_HI
, 0x05, 0x00},
210 {SENSOR
, S5K4AA_WINDOW_WIDTH_LO
, 0x00, 0x00},
211 {SENSOR
, S5K4AA_H_BLANK_HI__
, 0x01, 0x00},
212 {SENSOR
, S5K4AA_H_BLANK_LO__
, 0xa8, 0x00},
213 {SENSOR
, S5K4AA_EXPOSURE_HI
, 0x01, 0x00},
214 {SENSOR
, S5K4AA_EXPOSURE_LO
, 0x00, 0x00},
215 {SENSOR
, 0x11, 0x04, 0x00},
216 {SENSOR
, 0x12, 0xc3, 0x00},
217 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
218 {SENSOR
, 0x02, 0x0e, 0x00},
222 static int s5k4aa_s_ctrl(struct v4l2_ctrl
*ctrl
);
223 static void s5k4aa_dump_registers(struct sd
*sd
);
225 static const struct v4l2_ctrl_ops s5k4aa_ctrl_ops
= {
226 .s_ctrl
= s5k4aa_s_ctrl
,
231 struct dmi_system_id s5k4aa_vflip_dmi_table
[] = {
233 .ident
= "BRUNEINIT",
235 DMI_MATCH(DMI_SYS_VENDOR
, "BRUNENIT"),
236 DMI_MATCH(DMI_PRODUCT_NAME
, "BRUNENIT"),
237 DMI_MATCH(DMI_BOARD_VERSION
, "00030D0000000001")
240 .ident
= "Fujitsu-Siemens Amilo Xa 2528",
242 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
243 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xa 2528")
246 .ident
= "Fujitsu-Siemens Amilo Xi 2428",
248 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
249 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xi 2428")
252 .ident
= "Fujitsu-Siemens Amilo Xi 2528",
254 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
255 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xi 2528")
258 .ident
= "Fujitsu-Siemens Amilo Xi 2550",
260 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
261 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xi 2550")
264 .ident
= "Fujitsu-Siemens Amilo Pa 2548",
266 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
267 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Pa 2548")
270 .ident
= "Fujitsu-Siemens Amilo Pi 2530",
272 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
273 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Pi 2530")
276 .ident
= "MSI GX700",
278 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
279 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700"),
280 DMI_MATCH(DMI_BIOS_DATE
, "12/02/2008")
283 .ident
= "MSI GX700",
285 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
286 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700"),
287 DMI_MATCH(DMI_BIOS_DATE
, "07/26/2007")
290 .ident
= "MSI GX700",
292 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
293 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700"),
294 DMI_MATCH(DMI_BIOS_DATE
, "07/19/2007")
297 .ident
= "MSI GX700/GX705/EX700",
299 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
300 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700/GX705/EX700")
305 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
306 DMI_MATCH(DMI_PRODUCT_NAME
, "MS-1717X")
309 .ident
= "Lenovo Y300",
311 DMI_MATCH(DMI_SYS_VENDOR
, "L3000 Y300"),
312 DMI_MATCH(DMI_PRODUCT_NAME
, "Y300")
318 static struct v4l2_pix_format s5k4aa_modes
[] = {
327 .colorspace
= V4L2_COLORSPACE_SRGB
,
337 .bytesperline
= 1280,
338 .colorspace
= V4L2_COLORSPACE_SRGB
,
343 int s5k4aa_probe(struct sd
*sd
)
345 u8 prod_id
[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
346 const u8 expected_prod_id
[6] = {0x00, 0x10, 0x00, 0x4b, 0x33, 0x75};
347 struct gspca_dev
*gspca_dev
= (struct gspca_dev
*)sd
;
351 if (force_sensor
== S5K4AA_SENSOR
) {
352 pr_info("Forcing a %s sensor\n", s5k4aa
.name
);
355 /* If we want to force another sensor, don't try to probe this
360 gspca_dbg(gspca_dev
, D_PROBE
, "Probing for a s5k4aa sensor\n");
362 /* Preinit the sensor */
363 for (i
= 0; i
< ARRAY_SIZE(preinit_s5k4aa
) && !err
; i
++) {
364 u8 data
[2] = {0x00, 0x00};
366 switch (preinit_s5k4aa
[i
][0]) {
368 err
= m5602_write_bridge(sd
,
369 preinit_s5k4aa
[i
][1],
370 preinit_s5k4aa
[i
][2]);
374 data
[0] = preinit_s5k4aa
[i
][2];
375 err
= m5602_write_sensor(sd
,
376 preinit_s5k4aa
[i
][1],
381 data
[0] = preinit_s5k4aa
[i
][2];
382 data
[1] = preinit_s5k4aa
[i
][3];
383 err
= m5602_write_sensor(sd
,
384 preinit_s5k4aa
[i
][1],
388 pr_info("Invalid stream command, exiting init\n");
393 /* Test some registers, but we don't know their exact meaning yet */
394 if (m5602_read_sensor(sd
, 0x00, prod_id
, 2))
396 if (m5602_read_sensor(sd
, 0x02, prod_id
+2, 2))
398 if (m5602_read_sensor(sd
, 0x04, prod_id
+4, 2))
401 if (memcmp(prod_id
, expected_prod_id
, sizeof(prod_id
)))
404 pr_info("Detected a s5k4aa sensor\n");
407 sd
->gspca_dev
.cam
.cam_mode
= s5k4aa_modes
;
408 sd
->gspca_dev
.cam
.nmodes
= ARRAY_SIZE(s5k4aa_modes
);
413 int s5k4aa_start(struct sd
*sd
)
417 struct cam
*cam
= &sd
->gspca_dev
.cam
;
418 struct gspca_dev
*gspca_dev
= (struct gspca_dev
*)sd
;
420 switch (cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].width
) {
422 gspca_dbg(gspca_dev
, D_CONF
, "Configuring camera for SXGA mode\n");
424 for (i
= 0; i
< ARRAY_SIZE(SXGA_s5k4aa
); i
++) {
425 switch (SXGA_s5k4aa
[i
][0]) {
427 err
= m5602_write_bridge(sd
,
433 data
[0] = SXGA_s5k4aa
[i
][2];
434 err
= m5602_write_sensor(sd
,
440 data
[0] = SXGA_s5k4aa
[i
][2];
441 data
[1] = SXGA_s5k4aa
[i
][3];
442 err
= m5602_write_sensor(sd
,
448 pr_err("Invalid stream command, exiting init\n");
455 gspca_dbg(gspca_dev
, D_CONF
, "Configuring camera for VGA mode\n");
457 for (i
= 0; i
< ARRAY_SIZE(VGA_s5k4aa
); i
++) {
458 switch (VGA_s5k4aa
[i
][0]) {
460 err
= m5602_write_bridge(sd
,
466 data
[0] = VGA_s5k4aa
[i
][2];
467 err
= m5602_write_sensor(sd
,
473 data
[0] = VGA_s5k4aa
[i
][2];
474 data
[1] = VGA_s5k4aa
[i
][3];
475 err
= m5602_write_sensor(sd
,
481 pr_err("Invalid stream command, exiting init\n");
493 int s5k4aa_init(struct sd
*sd
)
497 for (i
= 0; i
< ARRAY_SIZE(init_s5k4aa
) && !err
; i
++) {
498 u8 data
[2] = {0x00, 0x00};
500 switch (init_s5k4aa
[i
][0]) {
502 err
= m5602_write_bridge(sd
,
508 data
[0] = init_s5k4aa
[i
][2];
509 err
= m5602_write_sensor(sd
,
510 init_s5k4aa
[i
][1], data
, 1);
514 data
[0] = init_s5k4aa
[i
][2];
515 data
[1] = init_s5k4aa
[i
][3];
516 err
= m5602_write_sensor(sd
,
517 init_s5k4aa
[i
][1], data
, 2);
520 pr_info("Invalid stream command, exiting init\n");
526 s5k4aa_dump_registers(sd
);
531 int s5k4aa_init_controls(struct sd
*sd
)
533 struct v4l2_ctrl_handler
*hdl
= &sd
->gspca_dev
.ctrl_handler
;
535 sd
->gspca_dev
.vdev
.ctrl_handler
= hdl
;
536 v4l2_ctrl_handler_init(hdl
, 6);
538 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_BRIGHTNESS
,
539 0, 0x1f, 1, S5K4AA_DEFAULT_BRIGHTNESS
);
541 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_EXPOSURE
,
542 13, 0xfff, 1, 0x100);
544 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_GAIN
,
545 0, 127, 1, S5K4AA_DEFAULT_GAIN
);
547 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_SHARPNESS
,
550 sd
->hflip
= v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_HFLIP
,
552 sd
->vflip
= v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_VFLIP
,
556 pr_err("Could not initialize controls\n");
560 v4l2_ctrl_cluster(2, &sd
->hflip
);
565 static int s5k4aa_set_exposure(struct gspca_dev
*gspca_dev
, __s32 val
)
567 struct sd
*sd
= (struct sd
*) gspca_dev
;
568 u8 data
= S5K4AA_PAGE_MAP_2
;
571 gspca_dbg(gspca_dev
, D_CONF
, "Set exposure to %d\n", val
);
572 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
575 data
= (val
>> 8) & 0xff;
576 err
= m5602_write_sensor(sd
, S5K4AA_EXPOSURE_HI
, &data
, 1);
580 err
= m5602_write_sensor(sd
, S5K4AA_EXPOSURE_LO
, &data
, 1);
585 static int s5k4aa_set_hvflip(struct gspca_dev
*gspca_dev
)
587 struct sd
*sd
= (struct sd
*) gspca_dev
;
588 u8 data
= S5K4AA_PAGE_MAP_2
;
590 int hflip
= sd
->hflip
->val
;
591 int vflip
= sd
->vflip
->val
;
593 gspca_dbg(gspca_dev
, D_CONF
, "Set hvflip %d %d\n", hflip
, vflip
);
594 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
598 err
= m5602_read_sensor(sd
, S5K4AA_READ_MODE
, &data
, 1);
602 if (dmi_check_system(s5k4aa_vflip_dmi_table
)) {
607 data
= (data
& 0x7f) | (vflip
<< 7) | (hflip
<< 6);
608 err
= m5602_write_sensor(sd
, S5K4AA_READ_MODE
, &data
, 1);
612 err
= m5602_read_sensor(sd
, S5K4AA_COLSTART_LO
, &data
, 1);
619 err
= m5602_write_sensor(sd
, S5K4AA_COLSTART_LO
, &data
, 1);
623 err
= m5602_read_sensor(sd
, S5K4AA_ROWSTART_LO
, &data
, 1);
630 err
= m5602_write_sensor(sd
, S5K4AA_ROWSTART_LO
, &data
, 1);
637 static int s5k4aa_set_gain(struct gspca_dev
*gspca_dev
, __s32 val
)
639 struct sd
*sd
= (struct sd
*) gspca_dev
;
640 u8 data
= S5K4AA_PAGE_MAP_2
;
643 gspca_dbg(gspca_dev
, D_CONF
, "Set gain to %d\n", val
);
644 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
649 err
= m5602_write_sensor(sd
, S5K4AA_GAIN
, &data
, 1);
654 static int s5k4aa_set_brightness(struct gspca_dev
*gspca_dev
, __s32 val
)
656 struct sd
*sd
= (struct sd
*) gspca_dev
;
657 u8 data
= S5K4AA_PAGE_MAP_2
;
660 gspca_dbg(gspca_dev
, D_CONF
, "Set brightness to %d\n", val
);
661 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
666 return m5602_write_sensor(sd
, S5K4AA_BRIGHTNESS
, &data
, 1);
669 static int s5k4aa_set_noise(struct gspca_dev
*gspca_dev
, __s32 val
)
671 struct sd
*sd
= (struct sd
*) gspca_dev
;
672 u8 data
= S5K4AA_PAGE_MAP_2
;
675 gspca_dbg(gspca_dev
, D_CONF
, "Set noise to %d\n", val
);
676 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
681 return m5602_write_sensor(sd
, S5K4AA_NOISE_SUPP
, &data
, 1);
684 static int s5k4aa_s_ctrl(struct v4l2_ctrl
*ctrl
)
686 struct gspca_dev
*gspca_dev
=
687 container_of(ctrl
->handler
, struct gspca_dev
, ctrl_handler
);
690 if (!gspca_dev
->streaming
)
694 case V4L2_CID_BRIGHTNESS
:
695 err
= s5k4aa_set_brightness(gspca_dev
, ctrl
->val
);
697 case V4L2_CID_EXPOSURE
:
698 err
= s5k4aa_set_exposure(gspca_dev
, ctrl
->val
);
701 err
= s5k4aa_set_gain(gspca_dev
, ctrl
->val
);
703 case V4L2_CID_SHARPNESS
:
704 err
= s5k4aa_set_noise(gspca_dev
, ctrl
->val
);
707 err
= s5k4aa_set_hvflip(gspca_dev
);
716 void s5k4aa_disconnect(struct sd
*sd
)
721 static void s5k4aa_dump_registers(struct sd
*sd
)
725 m5602_read_sensor(sd
, S5K4AA_PAGE_MAP
, &old_page
, 1);
726 for (page
= 0; page
< 16; page
++) {
727 m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &page
, 1);
728 pr_info("Dumping the s5k4aa register state for page 0x%x\n",
730 for (address
= 0; address
<= 0xff; address
++) {
732 m5602_read_sensor(sd
, address
, &value
, 1);
733 pr_info("register 0x%x contains 0x%x\n",
737 pr_info("s5k4aa register state dump complete\n");
739 for (page
= 0; page
< 16; page
++) {
740 m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &page
, 1);
741 pr_info("Probing for which registers that are read/write for page 0x%x\n",
743 for (address
= 0; address
<= 0xff; address
++) {
744 u8 old_value
, ctrl_value
, test_value
= 0xff;
746 m5602_read_sensor(sd
, address
, &old_value
, 1);
747 m5602_write_sensor(sd
, address
, &test_value
, 1);
748 m5602_read_sensor(sd
, address
, &ctrl_value
, 1);
750 if (ctrl_value
== test_value
)
751 pr_info("register 0x%x is writeable\n",
754 pr_info("register 0x%x is read only\n",
757 /* Restore original value */
758 m5602_write_sensor(sd
, address
, &old_value
, 1);
761 pr_info("Read/write register probing complete\n");
762 m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &old_page
, 1);