2 * Driver for the po1030 sensor.
3 * This is probably a pixel plus sensor but we haven't identified it yet
5 * Copyright (c) 2008 Erik Andren
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
14 * Register defines taken from Pascal Stangs Proxycon Armlib
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation, version 2.
22 #ifndef M5602_PO1030_H_
23 #define M5602_PO1030_H_
25 #include "m5602_sensor.h"
27 /*****************************************************************************/
29 #define PO1030_REG_DEVID_H 0x00
30 #define PO1030_REG_DEVID_L 0x01
31 #define PO1030_REG_FRAMEWIDTH_H 0x04
32 #define PO1030_REG_FRAMEWIDTH_L 0x05
33 #define PO1030_REG_FRAMEHEIGHT_H 0x06
34 #define PO1030_REG_FRAMEHEIGHT_L 0x07
35 #define PO1030_REG_WINDOWX_H 0x08
36 #define PO1030_REG_WINDOWX_L 0x09
37 #define PO1030_REG_WINDOWY_H 0x0a
38 #define PO1030_REG_WINDOWY_L 0x0b
39 #define PO1030_REG_WINDOWWIDTH_H 0x0c
40 #define PO1030_REG_WINDOWWIDTH_L 0x0d
41 #define PO1030_REG_WINDOWHEIGHT_H 0x0e
42 #define PO1030_REG_WINDOWHEIGHT_L 0x0f
44 #define PO1030_REG_GLOBALIBIAS 0x12
45 #define PO1030_REG_PIXELIBIAS 0x13
47 #define PO1030_REG_GLOBALGAIN 0x15
48 #define PO1030_REG_RED_GAIN 0x16
49 #define PO1030_REG_GREEN_1_GAIN 0x17
50 #define PO1030_REG_BLUE_GAIN 0x18
51 #define PO1030_REG_GREEN_2_GAIN 0x19
53 #define PO1030_REG_INTEGLINES_H 0x1a
54 #define PO1030_REG_INTEGLINES_M 0x1b
55 #define PO1030_REG_INTEGLINES_L 0x1c
57 #define PO1030_REG_CONTROL1 0x1d
58 #define PO1030_REG_CONTROL2 0x1e
59 #define PO1030_REG_CONTROL3 0x1f
60 #define PO1030_REG_CONTROL4 0x20
62 #define PO1030_REG_PERIOD50_H 0x23
63 #define PO1030_REG_PERIOD50_L 0x24
64 #define PO1030_REG_PERIOD60_H 0x25
65 #define PO1030_REG_PERIOD60_L 0x26
66 #define PO1030_REG_REGCLK167 0x27
67 #define PO1030_REG_DELTA50 0x28
68 #define PO1030_REG_DELTA60 0x29
70 #define PO1030_REG_ADCOFFSET 0x2c
72 /* Gamma Correction Coeffs */
73 #define PO1030_REG_GC0 0x2d
74 #define PO1030_REG_GC1 0x2e
75 #define PO1030_REG_GC2 0x2f
76 #define PO1030_REG_GC3 0x30
77 #define PO1030_REG_GC4 0x31
78 #define PO1030_REG_GC5 0x32
79 #define PO1030_REG_GC6 0x33
80 #define PO1030_REG_GC7 0x34
82 /* Color Transform Matrix */
83 #define PO1030_REG_CT0 0x35
84 #define PO1030_REG_CT1 0x36
85 #define PO1030_REG_CT2 0x37
86 #define PO1030_REG_CT3 0x38
87 #define PO1030_REG_CT4 0x39
88 #define PO1030_REG_CT5 0x3a
89 #define PO1030_REG_CT6 0x3b
90 #define PO1030_REG_CT7 0x3c
91 #define PO1030_REG_CT8 0x3d
93 #define PO1030_REG_AUTOCTRL1 0x3e
94 #define PO1030_REG_AUTOCTRL2 0x3f
96 #define PO1030_REG_YTARGET 0x40
97 #define PO1030_REG_GLOBALGAINMIN 0x41
98 #define PO1030_REG_GLOBALGAINMAX 0x42
100 /* Output format control */
101 #define PO1030_REG_OUTFORMCTRL1 0x5a
102 #define PO1030_REG_OUTFORMCTRL2 0x5b
103 #define PO1030_REG_OUTFORMCTRL3 0x5c
104 #define PO1030_REG_OUTFORMCTRL4 0x5d
105 #define PO1030_REG_OUTFORMCTRL5 0x5e
107 /* Imaging coefficients */
108 #define PO1030_REG_YBRIGHT 0x73
109 #define PO1030_REG_YCONTRAST 0x74
110 #define PO1030_REG_YSATURATION 0x75
112 /*****************************************************************************/
114 #define PO1030_GLOBAL_GAIN_DEFAULT 0x12
115 #define PO1030_EXPOSURE_DEFAULT 0xf0ff
116 #define PO1030_BLUE_GAIN_DEFAULT 0x40
117 #define PO1030_RED_GAIN_DEFAULT 0x40
119 /*****************************************************************************/
121 /* Kernel module parameters */
122 extern int force_sensor;
123 extern int dump_sensor;
124 extern unsigned int m5602_debug;
126 int po1030_probe(struct sd *sd);
127 int po1030_init(struct sd *sd);
128 int po1030_power_down(struct sd *sd);
130 void po1030_dump_registers(struct sd *sd);
132 int po1030_read_sensor(struct sd *sd, const u8 address,
133 u8 *i2c_data, const u8 len);
134 int po1030_write_sensor(struct sd *sd, const u8 address,
135 u8 *i2c_data, const u8 len);
137 int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
138 int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
139 int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
140 int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val);
141 int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
142 int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
143 int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
144 int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
146 static struct m5602_sensor po1030 = {
149 .i2c_slave_id = 0xdc,
151 .probe = po1030_probe,
153 .power_down = po1030_power_down,
160 .type = V4L2_CTRL_TYPE_INTEGER,
165 .default_value = PO1030_GLOBAL_GAIN_DEFAULT,
166 .flags = V4L2_CTRL_FLAG_SLIDER
168 .set = po1030_set_gain,
169 .get = po1030_get_gain
172 .id = V4L2_CID_EXPOSURE,
173 .type = V4L2_CTRL_TYPE_INTEGER,
178 .default_value = PO1030_EXPOSURE_DEFAULT,
179 .flags = V4L2_CTRL_FLAG_SLIDER
181 .set = po1030_set_exposure,
182 .get = po1030_get_exposure
185 .id = V4L2_CID_RED_BALANCE,
186 .type = V4L2_CTRL_TYPE_INTEGER,
187 .name = "red balance",
191 .default_value = PO1030_RED_GAIN_DEFAULT,
192 .flags = V4L2_CTRL_FLAG_SLIDER
194 .set = po1030_set_red_balance,
195 .get = po1030_get_red_balance
198 .id = V4L2_CID_BLUE_BALANCE,
199 .type = V4L2_CTRL_TYPE_INTEGER,
200 .name = "blue balance",
204 .default_value = PO1030_BLUE_GAIN_DEFAULT,
205 .flags = V4L2_CTRL_FLAG_SLIDER
207 .set = po1030_set_blue_balance,
208 .get = po1030_get_blue_balance
214 M5602_DEFAULT_FRAME_WIDTH,
215 M5602_DEFAULT_FRAME_HEIGHT,
219 M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
220 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
221 .colorspace = V4L2_COLORSPACE_SRGB,
227 static const unsigned char preinit_po1030[][3] =
229 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
230 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
231 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
232 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
233 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
234 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
235 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
236 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
237 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
239 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
241 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
242 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
243 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
244 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
245 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
246 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
247 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
248 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
249 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
250 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
251 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
252 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
253 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
254 {BRIDGE, M5602_XB_SIG_INI, 0x01},
255 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
256 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
257 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
258 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
259 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
260 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
261 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
262 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
263 {BRIDGE, M5602_XB_SIG_INI, 0x00},
264 {BRIDGE, M5602_XB_SIG_INI, 0x02},
265 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
266 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
267 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
268 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
269 {BRIDGE, M5602_XB_SIG_INI, 0x00},
271 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
273 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
274 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
275 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
276 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
277 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
278 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
279 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
280 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
281 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
282 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
283 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
284 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
285 {BRIDGE, M5602_XB_GPIO_DAT, 0x00}
288 static const unsigned char init_po1030[][4] =
290 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
291 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
293 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
294 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
295 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
296 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
298 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
299 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
300 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
301 /*end of sequence 1*/
303 /*sequence 2 (same as stop sequence)*/
304 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
305 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
306 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
307 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
308 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
309 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
311 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
312 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
313 /*end of sequence 2*/
316 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
317 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
318 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
319 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
320 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
321 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
322 {BRIDGE, M5602_XB_SIG_INI, 0x01},
323 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
324 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
325 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
326 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
327 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
328 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
329 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
330 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
331 {BRIDGE, M5602_XB_SIG_INI, 0x00},
332 {BRIDGE, M5602_XB_SIG_INI, 0x02},
333 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
334 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
335 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
336 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
337 {BRIDGE, M5602_XB_SIG_INI, 0x00},
338 /*end of sequence 5*/
341 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
343 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
344 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
345 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
346 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
347 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
348 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
349 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
350 /*end of sequence 2 stop */
352 /* ---------------------------------
353 * end of init - begin of start
354 * --------------------------------- */
357 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
358 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
359 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
360 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
361 /*end of sequence 3*/
363 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
364 {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
365 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
366 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00},
368 {SENSOR, PO1030_REG_AUTOCTRL2, 0x04},
370 /* Set the width to 751 */
371 {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
372 {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef},
374 /* Set the height to 540 */
375 {SENSOR, PO1030_REG_FRAMEHEIGHT_H, 0x02},
376 {SENSOR, PO1030_REG_FRAMEHEIGHT_L, 0x1c},
378 /* Set the x window to 1 */
379 {SENSOR, PO1030_REG_WINDOWX_H, 0x00},
380 {SENSOR, PO1030_REG_WINDOWX_L, 0x01},
382 /* Set the y window to 1 */
383 {SENSOR, PO1030_REG_WINDOWY_H, 0x00},
384 {SENSOR, PO1030_REG_WINDOWX_L, 0x01},
386 {SENSOR, PO1030_REG_WINDOWWIDTH_H, 0x02},
387 {SENSOR, PO1030_REG_WINDOWWIDTH_L, 0x87},
388 {SENSOR, PO1030_REG_WINDOWHEIGHT_H, 0x01},
389 {SENSOR, PO1030_REG_WINDOWHEIGHT_L, 0xe3},
391 {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
392 {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
393 {SENSOR, PO1030_REG_AUTOCTRL1, 0x08},
394 {SENSOR, PO1030_REG_CONTROL2, 0x03},
395 {SENSOR, 0x21, 0x90},
396 {SENSOR, PO1030_REG_YTARGET, 0x60},
397 {SENSOR, 0x59, 0x13},
398 {SENSOR, PO1030_REG_OUTFORMCTRL1, 0x40},
399 {SENSOR, 0x5f, 0x00},
400 {SENSOR, 0x60, 0x80},
401 {SENSOR, 0x78, 0x14},
402 {SENSOR, 0x6f, 0x01},
403 {SENSOR, PO1030_REG_CONTROL1, 0x18},
404 {SENSOR, PO1030_REG_GLOBALGAINMAX, 0x14},
405 {SENSOR, 0x63, 0x38},
406 {SENSOR, 0x64, 0x38},
407 {SENSOR, PO1030_REG_CONTROL1, 0x58},
408 {SENSOR, PO1030_REG_RED_GAIN, 0x30},
409 {SENSOR, PO1030_REG_GREEN_1_GAIN, 0x30},
410 {SENSOR, PO1030_REG_BLUE_GAIN, 0x30},
411 {SENSOR, PO1030_REG_GREEN_2_GAIN, 0x30},
412 {SENSOR, PO1030_REG_GC0, 0x10},
413 {SENSOR, PO1030_REG_GC1, 0x20},
414 {SENSOR, PO1030_REG_GC2, 0x40},
415 {SENSOR, PO1030_REG_GC3, 0x60},
416 {SENSOR, PO1030_REG_GC4, 0x80},
417 {SENSOR, PO1030_REG_GC5, 0xa0},
418 {SENSOR, PO1030_REG_GC6, 0xc0},
419 {SENSOR, PO1030_REG_GC7, 0xff},
420 /*end of sequence 4*/
422 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
423 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
424 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
425 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
426 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
427 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
428 {BRIDGE, M5602_XB_SIG_INI, 0x01},
429 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
430 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
431 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
432 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
433 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
434 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
435 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
436 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
437 {BRIDGE, M5602_XB_SIG_INI, 0x00},
438 {BRIDGE, M5602_XB_SIG_INI, 0x00},
439 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
440 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
441 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
442 {BRIDGE, M5602_XB_HSYNC_PARA, 0x7e},
443 {BRIDGE, M5602_XB_SIG_INI, 0x00},
444 /*end of sequence 5*/
447 /* Changing 40 in f0 the image becomes green in bayer mode and red in
449 {SENSOR, PO1030_REG_RED_GAIN, PO1030_RED_GAIN_DEFAULT},
450 /* in changing 40 in f0 the image becomes green in bayer mode and red in
452 {SENSOR, PO1030_REG_BLUE_GAIN, PO1030_BLUE_GAIN_DEFAULT},
454 /* with a very low lighted environment increase the exposure but
455 * decrease the FPS (Frame Per Second) */
456 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
457 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
459 /* Controls high exposure more than SENSOR_LOW_EXPOSURE, use only in
460 * low lighted environment (f0 is more than ff ?)*/
461 {SENSOR, PO1030_REG_INTEGLINES_H, ((PO1030_EXPOSURE_DEFAULT >> 2)
464 /* Controls middle exposure, use only in high lighted environment */
465 {SENSOR, PO1030_REG_INTEGLINES_M, PO1030_EXPOSURE_DEFAULT & 0xff},
467 /* Controls clarity (not sure) */
468 {SENSOR, PO1030_REG_INTEGLINES_L, 0x00},
469 /* Controls gain (the image is more lighted) */
470 {SENSOR, PO1030_REG_GLOBALGAIN, PO1030_GLOBAL_GAIN_DEFAULT},
473 {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
474 {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef}
475 /*end of sequence 6*/