1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for the s5k4aa sensor
5 * Copyright (C) 2008 Erik Andrén
6 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
7 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
9 * Portions of code to USB interface and ALi driver software,
10 * Copyright (c) 2006 Willem Duinker
11 * v4l2 interface modeled after the V4L2 driver
12 * for SN9C10x PC Camera Controllers
15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include "m5602_s5k4aa.h"
19 static const unsigned char preinit_s5k4aa
[][4] = {
20 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
21 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
22 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
23 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
24 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
25 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x0d, 0x00},
26 {BRIDGE
, M5602_XB_SENSOR_CTRL
, 0x00, 0x00},
28 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
29 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x08, 0x00},
30 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0xb0, 0x00},
31 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0x80, 0x00},
32 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x3f, 0x00},
33 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x3f, 0x00},
34 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
35 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
36 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x00, 0x00},
37 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0xff, 0x00},
38 {BRIDGE
, M5602_XB_GPIO_DIR_L
, 0xff, 0x00},
39 {BRIDGE
, M5602_XB_GPIO_DAT_L
, 0x00, 0x00},
40 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
41 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
42 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
43 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
45 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
46 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
47 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
48 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x14, 0x00},
49 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
50 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xf0, 0x00},
51 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
52 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x1c, 0x00},
53 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x06, 0x00},
54 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x06, 0x00},
55 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
56 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0x00, 0x00},
57 {BRIDGE
, M5602_XB_I2C_CLK_DIV
, 0x20, 0x00},
59 {SENSOR
, S5K4AA_PAGE_MAP
, 0x00, 0x00}
62 static const unsigned char init_s5k4aa
[][4] = {
63 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
64 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
65 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
66 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
67 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
68 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x0d, 0x00},
69 {BRIDGE
, M5602_XB_SENSOR_CTRL
, 0x00, 0x00},
71 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
72 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x08, 0x00},
73 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0xb0, 0x00},
74 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0x80, 0x00},
75 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x3f, 0x00},
76 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x3f, 0x00},
77 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
78 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
79 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x00, 0x00},
80 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0xff, 0x00},
81 {BRIDGE
, M5602_XB_GPIO_DIR_L
, 0xff, 0x00},
82 {BRIDGE
, M5602_XB_GPIO_DAT_L
, 0x00, 0x00},
83 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
84 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
85 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
86 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
88 {BRIDGE
, M5602_XB_MCU_CLK_DIV
, 0x02, 0x00},
89 {BRIDGE
, M5602_XB_MCU_CLK_CTRL
, 0xb0, 0x00},
90 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
91 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x14, 0x00},
92 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
93 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xf0, 0x00},
94 {BRIDGE
, M5602_XB_GPIO_DIR
, 0x1d, 0x00},
95 {BRIDGE
, M5602_XB_GPIO_DAT
, 0x1c, 0x00},
96 {BRIDGE
, M5602_XB_GPIO_EN_H
, 0x06, 0x00},
97 {BRIDGE
, M5602_XB_GPIO_DIR_H
, 0x06, 0x00},
98 {BRIDGE
, M5602_XB_GPIO_DAT_H
, 0x00, 0x00},
99 {BRIDGE
, M5602_XB_GPIO_EN_L
, 0x00, 0x00},
100 {BRIDGE
, M5602_XB_I2C_CLK_DIV
, 0x20, 0x00},
102 {SENSOR
, S5K4AA_PAGE_MAP
, 0x07, 0x00},
103 {SENSOR
, 0x36, 0x01, 0x00},
104 {SENSOR
, S5K4AA_PAGE_MAP
, 0x00, 0x00},
105 {SENSOR
, 0x7b, 0xff, 0x00},
106 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
107 {SENSOR
, 0x0c, 0x05, 0x00},
108 {SENSOR
, 0x02, 0x0e, 0x00},
109 {SENSOR
, S5K4AA_READ_MODE
, 0xa0, 0x00},
110 {SENSOR
, 0x37, 0x00, 0x00},
113 static const unsigned char VGA_s5k4aa
[][4] = {
114 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x06, 0x00},
115 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
116 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
117 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
118 {BRIDGE
, M5602_XB_LINE_OF_FRAME_H
, 0x81, 0x00},
119 {BRIDGE
, M5602_XB_PIX_OF_LINE_H
, 0x82, 0x00},
120 {BRIDGE
, M5602_XB_SIG_INI
, 0x01, 0x00},
121 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
122 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
123 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
124 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
125 /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
126 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x01, 0x00},
127 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0xe0, 0x00},
128 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
129 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
130 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
131 {BRIDGE
, M5602_XB_SIG_INI
, 0x02, 0x00},
132 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
133 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
134 /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
135 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x02, 0x00},
136 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x80, 0x00},
137 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
138 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
139 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xa0, 0x00}, /* 48 MHz */
141 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
142 {SENSOR
, S5K4AA_READ_MODE
, S5K4AA_RM_H_FLIP
| S5K4AA_RM_ROW_SKIP_2X
143 | S5K4AA_RM_COL_SKIP_2X
, 0x00},
144 /* 0x37 : Fix image stability when light is too bright and improves
145 * image quality in 640x480, but worsens it in 1280x1024 */
146 {SENSOR
, 0x37, 0x01, 0x00},
147 /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
148 {SENSOR
, S5K4AA_ROWSTART_HI
, 0x00, 0x00},
149 {SENSOR
, S5K4AA_ROWSTART_LO
, 0x29, 0x00},
150 {SENSOR
, S5K4AA_COLSTART_HI
, 0x00, 0x00},
151 {SENSOR
, S5K4AA_COLSTART_LO
, 0x0c, 0x00},
152 /* window_height_hi, window_height_lo : 960 = 0x03c0 */
153 {SENSOR
, S5K4AA_WINDOW_HEIGHT_HI
, 0x03, 0x00},
154 {SENSOR
, S5K4AA_WINDOW_HEIGHT_LO
, 0xc0, 0x00},
155 /* window_width_hi, window_width_lo : 1280 = 0x0500 */
156 {SENSOR
, S5K4AA_WINDOW_WIDTH_HI
, 0x05, 0x00},
157 {SENSOR
, S5K4AA_WINDOW_WIDTH_LO
, 0x00, 0x00},
158 {SENSOR
, S5K4AA_H_BLANK_HI__
, 0x00, 0x00},
159 {SENSOR
, S5K4AA_H_BLANK_LO__
, 0xa8, 0x00}, /* helps to sync... */
160 {SENSOR
, S5K4AA_EXPOSURE_HI
, 0x01, 0x00},
161 {SENSOR
, S5K4AA_EXPOSURE_LO
, 0x00, 0x00},
162 {SENSOR
, 0x11, 0x04, 0x00},
163 {SENSOR
, 0x12, 0xc3, 0x00},
164 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
165 {SENSOR
, 0x02, 0x0e, 0x00},
168 static const unsigned char SXGA_s5k4aa
[][4] = {
169 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x06, 0x00},
170 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xb0, 0x00},
171 {BRIDGE
, M5602_XB_ADC_CTRL
, 0xc0, 0x00},
172 {BRIDGE
, M5602_XB_SENSOR_TYPE
, 0x08, 0x00},
173 {BRIDGE
, M5602_XB_LINE_OF_FRAME_H
, 0x81, 0x00},
174 {BRIDGE
, M5602_XB_PIX_OF_LINE_H
, 0x82, 0x00},
175 {BRIDGE
, M5602_XB_SIG_INI
, 0x01, 0x00},
176 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
177 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
178 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
179 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
180 /* VSYNC_PARA, VSYNC_PARA : img height 1024 = 0x0400 */
181 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x04, 0x00},
182 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
183 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
184 {BRIDGE
, M5602_XB_VSYNC_PARA
, 0x00, 0x00},
185 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
186 {BRIDGE
, M5602_XB_SIG_INI
, 0x02, 0x00},
187 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
188 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
189 /* HSYNC_PARA, HSYNC_PARA : img width 1280 = 0x0500 */
190 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x05, 0x00},
191 {BRIDGE
, M5602_XB_HSYNC_PARA
, 0x00, 0x00},
192 {BRIDGE
, M5602_XB_SIG_INI
, 0x00, 0x00},
193 {BRIDGE
, M5602_XB_SEN_CLK_DIV
, 0x00, 0x00},
194 {BRIDGE
, M5602_XB_SEN_CLK_CTRL
, 0xa0, 0x00}, /* 48 MHz */
196 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
197 {SENSOR
, S5K4AA_READ_MODE
, S5K4AA_RM_H_FLIP
, 0x00},
198 {SENSOR
, 0x37, 0x01, 0x00},
199 {SENSOR
, S5K4AA_ROWSTART_HI
, 0x00, 0x00},
200 {SENSOR
, S5K4AA_ROWSTART_LO
, 0x09, 0x00},
201 {SENSOR
, S5K4AA_COLSTART_HI
, 0x00, 0x00},
202 {SENSOR
, S5K4AA_COLSTART_LO
, 0x0a, 0x00},
203 {SENSOR
, S5K4AA_WINDOW_HEIGHT_HI
, 0x04, 0x00},
204 {SENSOR
, S5K4AA_WINDOW_HEIGHT_LO
, 0x00, 0x00},
205 {SENSOR
, S5K4AA_WINDOW_WIDTH_HI
, 0x05, 0x00},
206 {SENSOR
, S5K4AA_WINDOW_WIDTH_LO
, 0x00, 0x00},
207 {SENSOR
, S5K4AA_H_BLANK_HI__
, 0x01, 0x00},
208 {SENSOR
, S5K4AA_H_BLANK_LO__
, 0xa8, 0x00},
209 {SENSOR
, S5K4AA_EXPOSURE_HI
, 0x01, 0x00},
210 {SENSOR
, S5K4AA_EXPOSURE_LO
, 0x00, 0x00},
211 {SENSOR
, 0x11, 0x04, 0x00},
212 {SENSOR
, 0x12, 0xc3, 0x00},
213 {SENSOR
, S5K4AA_PAGE_MAP
, 0x02, 0x00},
214 {SENSOR
, 0x02, 0x0e, 0x00},
218 static int s5k4aa_s_ctrl(struct v4l2_ctrl
*ctrl
);
219 static void s5k4aa_dump_registers(struct sd
*sd
);
221 static const struct v4l2_ctrl_ops s5k4aa_ctrl_ops
= {
222 .s_ctrl
= s5k4aa_s_ctrl
,
227 struct dmi_system_id s5k4aa_vflip_dmi_table
[] = {
229 .ident
= "BRUNEINIT",
231 DMI_MATCH(DMI_SYS_VENDOR
, "BRUNENIT"),
232 DMI_MATCH(DMI_PRODUCT_NAME
, "BRUNENIT"),
233 DMI_MATCH(DMI_BOARD_VERSION
, "00030D0000000001")
236 .ident
= "Fujitsu-Siemens Amilo Xa 2528",
238 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
239 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xa 2528")
242 .ident
= "Fujitsu-Siemens Amilo Xi 2428",
244 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
245 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xi 2428")
248 .ident
= "Fujitsu-Siemens Amilo Xi 2528",
250 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
251 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xi 2528")
254 .ident
= "Fujitsu-Siemens Amilo Xi 2550",
256 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
257 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Xi 2550")
260 .ident
= "Fujitsu-Siemens Amilo Pa 2548",
262 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
263 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Pa 2548")
266 .ident
= "Fujitsu-Siemens Amilo Pi 2530",
268 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
269 DMI_MATCH(DMI_PRODUCT_NAME
, "AMILO Pi 2530")
272 .ident
= "MSI GX700",
274 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
275 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700"),
276 DMI_MATCH(DMI_BIOS_DATE
, "12/02/2008")
279 .ident
= "MSI GX700",
281 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
282 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700"),
283 DMI_MATCH(DMI_BIOS_DATE
, "07/26/2007")
286 .ident
= "MSI GX700",
288 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
289 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700"),
290 DMI_MATCH(DMI_BIOS_DATE
, "07/19/2007")
293 .ident
= "MSI GX700/GX705/EX700",
295 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
296 DMI_MATCH(DMI_PRODUCT_NAME
, "GX700/GX705/EX700")
301 DMI_MATCH(DMI_SYS_VENDOR
, "Micro-Star International"),
302 DMI_MATCH(DMI_PRODUCT_NAME
, "MS-1717X")
305 .ident
= "Lenovo Y300",
307 DMI_MATCH(DMI_SYS_VENDOR
, "L3000 Y300"),
308 DMI_MATCH(DMI_PRODUCT_NAME
, "Y300")
314 static struct v4l2_pix_format s5k4aa_modes
[] = {
323 .colorspace
= V4L2_COLORSPACE_SRGB
,
333 .bytesperline
= 1280,
334 .colorspace
= V4L2_COLORSPACE_SRGB
,
339 int s5k4aa_probe(struct sd
*sd
)
341 u8 prod_id
[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
342 const u8 expected_prod_id
[6] = {0x00, 0x10, 0x00, 0x4b, 0x33, 0x75};
343 struct gspca_dev
*gspca_dev
= (struct gspca_dev
*)sd
;
347 if (force_sensor
== S5K4AA_SENSOR
) {
348 pr_info("Forcing a %s sensor\n", s5k4aa
.name
);
351 /* If we want to force another sensor, don't try to probe this
356 gspca_dbg(gspca_dev
, D_PROBE
, "Probing for a s5k4aa sensor\n");
358 /* Preinit the sensor */
359 for (i
= 0; i
< ARRAY_SIZE(preinit_s5k4aa
) && !err
; i
++) {
360 u8 data
[2] = {0x00, 0x00};
362 switch (preinit_s5k4aa
[i
][0]) {
364 err
= m5602_write_bridge(sd
,
365 preinit_s5k4aa
[i
][1],
366 preinit_s5k4aa
[i
][2]);
370 data
[0] = preinit_s5k4aa
[i
][2];
371 err
= m5602_write_sensor(sd
,
372 preinit_s5k4aa
[i
][1],
377 data
[0] = preinit_s5k4aa
[i
][2];
378 data
[1] = preinit_s5k4aa
[i
][3];
379 err
= m5602_write_sensor(sd
,
380 preinit_s5k4aa
[i
][1],
384 pr_info("Invalid stream command, exiting init\n");
389 /* Test some registers, but we don't know their exact meaning yet */
390 if (m5602_read_sensor(sd
, 0x00, prod_id
, 2))
392 if (m5602_read_sensor(sd
, 0x02, prod_id
+2, 2))
394 if (m5602_read_sensor(sd
, 0x04, prod_id
+4, 2))
397 if (memcmp(prod_id
, expected_prod_id
, sizeof(prod_id
)))
400 pr_info("Detected a s5k4aa sensor\n");
403 sd
->gspca_dev
.cam
.cam_mode
= s5k4aa_modes
;
404 sd
->gspca_dev
.cam
.nmodes
= ARRAY_SIZE(s5k4aa_modes
);
409 int s5k4aa_start(struct sd
*sd
)
413 struct cam
*cam
= &sd
->gspca_dev
.cam
;
414 struct gspca_dev
*gspca_dev
= (struct gspca_dev
*)sd
;
416 switch (cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].width
) {
418 gspca_dbg(gspca_dev
, D_CONF
, "Configuring camera for SXGA mode\n");
420 for (i
= 0; i
< ARRAY_SIZE(SXGA_s5k4aa
); i
++) {
421 switch (SXGA_s5k4aa
[i
][0]) {
423 err
= m5602_write_bridge(sd
,
429 data
[0] = SXGA_s5k4aa
[i
][2];
430 err
= m5602_write_sensor(sd
,
436 data
[0] = SXGA_s5k4aa
[i
][2];
437 data
[1] = SXGA_s5k4aa
[i
][3];
438 err
= m5602_write_sensor(sd
,
444 pr_err("Invalid stream command, exiting init\n");
451 gspca_dbg(gspca_dev
, D_CONF
, "Configuring camera for VGA mode\n");
453 for (i
= 0; i
< ARRAY_SIZE(VGA_s5k4aa
); i
++) {
454 switch (VGA_s5k4aa
[i
][0]) {
456 err
= m5602_write_bridge(sd
,
462 data
[0] = VGA_s5k4aa
[i
][2];
463 err
= m5602_write_sensor(sd
,
469 data
[0] = VGA_s5k4aa
[i
][2];
470 data
[1] = VGA_s5k4aa
[i
][3];
471 err
= m5602_write_sensor(sd
,
477 pr_err("Invalid stream command, exiting init\n");
489 int s5k4aa_init(struct sd
*sd
)
493 for (i
= 0; i
< ARRAY_SIZE(init_s5k4aa
) && !err
; i
++) {
494 u8 data
[2] = {0x00, 0x00};
496 switch (init_s5k4aa
[i
][0]) {
498 err
= m5602_write_bridge(sd
,
504 data
[0] = init_s5k4aa
[i
][2];
505 err
= m5602_write_sensor(sd
,
506 init_s5k4aa
[i
][1], data
, 1);
510 data
[0] = init_s5k4aa
[i
][2];
511 data
[1] = init_s5k4aa
[i
][3];
512 err
= m5602_write_sensor(sd
,
513 init_s5k4aa
[i
][1], data
, 2);
516 pr_info("Invalid stream command, exiting init\n");
522 s5k4aa_dump_registers(sd
);
527 int s5k4aa_init_controls(struct sd
*sd
)
529 struct v4l2_ctrl_handler
*hdl
= &sd
->gspca_dev
.ctrl_handler
;
531 sd
->gspca_dev
.vdev
.ctrl_handler
= hdl
;
532 v4l2_ctrl_handler_init(hdl
, 6);
534 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_BRIGHTNESS
,
535 0, 0x1f, 1, S5K4AA_DEFAULT_BRIGHTNESS
);
537 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_EXPOSURE
,
538 13, 0xfff, 1, 0x100);
540 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_GAIN
,
541 0, 127, 1, S5K4AA_DEFAULT_GAIN
);
543 v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_SHARPNESS
,
546 sd
->hflip
= v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_HFLIP
,
548 sd
->vflip
= v4l2_ctrl_new_std(hdl
, &s5k4aa_ctrl_ops
, V4L2_CID_VFLIP
,
552 pr_err("Could not initialize controls\n");
556 v4l2_ctrl_cluster(2, &sd
->hflip
);
561 static int s5k4aa_set_exposure(struct gspca_dev
*gspca_dev
, __s32 val
)
563 struct sd
*sd
= (struct sd
*) gspca_dev
;
564 u8 data
= S5K4AA_PAGE_MAP_2
;
567 gspca_dbg(gspca_dev
, D_CONF
, "Set exposure to %d\n", val
);
568 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
571 data
= (val
>> 8) & 0xff;
572 err
= m5602_write_sensor(sd
, S5K4AA_EXPOSURE_HI
, &data
, 1);
576 err
= m5602_write_sensor(sd
, S5K4AA_EXPOSURE_LO
, &data
, 1);
581 static int s5k4aa_set_hvflip(struct gspca_dev
*gspca_dev
)
583 struct sd
*sd
= (struct sd
*) gspca_dev
;
584 u8 data
= S5K4AA_PAGE_MAP_2
;
586 int hflip
= sd
->hflip
->val
;
587 int vflip
= sd
->vflip
->val
;
589 gspca_dbg(gspca_dev
, D_CONF
, "Set hvflip %d %d\n", hflip
, vflip
);
590 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
594 err
= m5602_read_sensor(sd
, S5K4AA_READ_MODE
, &data
, 1);
598 if (dmi_check_system(s5k4aa_vflip_dmi_table
)) {
603 data
= (data
& 0x7f) | (vflip
<< 7) | (hflip
<< 6);
604 err
= m5602_write_sensor(sd
, S5K4AA_READ_MODE
, &data
, 1);
608 err
= m5602_read_sensor(sd
, S5K4AA_COLSTART_LO
, &data
, 1);
615 err
= m5602_write_sensor(sd
, S5K4AA_COLSTART_LO
, &data
, 1);
619 err
= m5602_read_sensor(sd
, S5K4AA_ROWSTART_LO
, &data
, 1);
626 err
= m5602_write_sensor(sd
, S5K4AA_ROWSTART_LO
, &data
, 1);
633 static int s5k4aa_set_gain(struct gspca_dev
*gspca_dev
, __s32 val
)
635 struct sd
*sd
= (struct sd
*) gspca_dev
;
636 u8 data
= S5K4AA_PAGE_MAP_2
;
639 gspca_dbg(gspca_dev
, D_CONF
, "Set gain to %d\n", val
);
640 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
645 err
= m5602_write_sensor(sd
, S5K4AA_GAIN
, &data
, 1);
650 static int s5k4aa_set_brightness(struct gspca_dev
*gspca_dev
, __s32 val
)
652 struct sd
*sd
= (struct sd
*) gspca_dev
;
653 u8 data
= S5K4AA_PAGE_MAP_2
;
656 gspca_dbg(gspca_dev
, D_CONF
, "Set brightness to %d\n", val
);
657 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
662 return m5602_write_sensor(sd
, S5K4AA_BRIGHTNESS
, &data
, 1);
665 static int s5k4aa_set_noise(struct gspca_dev
*gspca_dev
, __s32 val
)
667 struct sd
*sd
= (struct sd
*) gspca_dev
;
668 u8 data
= S5K4AA_PAGE_MAP_2
;
671 gspca_dbg(gspca_dev
, D_CONF
, "Set noise to %d\n", val
);
672 err
= m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &data
, 1);
677 return m5602_write_sensor(sd
, S5K4AA_NOISE_SUPP
, &data
, 1);
680 static int s5k4aa_s_ctrl(struct v4l2_ctrl
*ctrl
)
682 struct gspca_dev
*gspca_dev
=
683 container_of(ctrl
->handler
, struct gspca_dev
, ctrl_handler
);
686 if (!gspca_dev
->streaming
)
690 case V4L2_CID_BRIGHTNESS
:
691 err
= s5k4aa_set_brightness(gspca_dev
, ctrl
->val
);
693 case V4L2_CID_EXPOSURE
:
694 err
= s5k4aa_set_exposure(gspca_dev
, ctrl
->val
);
697 err
= s5k4aa_set_gain(gspca_dev
, ctrl
->val
);
699 case V4L2_CID_SHARPNESS
:
700 err
= s5k4aa_set_noise(gspca_dev
, ctrl
->val
);
703 err
= s5k4aa_set_hvflip(gspca_dev
);
712 void s5k4aa_disconnect(struct sd
*sd
)
717 static void s5k4aa_dump_registers(struct sd
*sd
)
721 m5602_read_sensor(sd
, S5K4AA_PAGE_MAP
, &old_page
, 1);
722 for (page
= 0; page
< 16; page
++) {
723 m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &page
, 1);
724 pr_info("Dumping the s5k4aa register state for page 0x%x\n",
726 for (address
= 0; address
<= 0xff; address
++) {
728 m5602_read_sensor(sd
, address
, &value
, 1);
729 pr_info("register 0x%x contains 0x%x\n",
733 pr_info("s5k4aa register state dump complete\n");
735 for (page
= 0; page
< 16; page
++) {
736 m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &page
, 1);
737 pr_info("Probing for which registers that are read/write for page 0x%x\n",
739 for (address
= 0; address
<= 0xff; address
++) {
740 u8 old_value
, ctrl_value
, test_value
= 0xff;
742 m5602_read_sensor(sd
, address
, &old_value
, 1);
743 m5602_write_sensor(sd
, address
, &test_value
, 1);
744 m5602_read_sensor(sd
, address
, &ctrl_value
, 1);
746 if (ctrl_value
== test_value
)
747 pr_info("register 0x%x is writeable\n",
750 pr_info("register 0x%x is read only\n",
753 /* Restore original value */
754 m5602_write_sensor(sd
, address
, &old_value
, 1);
757 pr_info("Read/write register probing complete\n");
758 m5602_write_sensor(sd
, S5K4AA_PAGE_MAP
, &old_page
, 1);