2 * Driver for the po1030 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 * Register defines taken from Pascal Stangs Procyon Armlib
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation, version 2.
21 #ifndef M5602_PO1030_H_
22 #define M5602_PO1030_H_
24 #include "m5602_sensor.h"
26 /*****************************************************************************/
28 #define PO1030_REG_DEVID_H 0x00
29 #define PO1030_REG_DEVID_L 0x01
30 #define PO1030_REG_FRAMEWIDTH_H 0x04
31 #define PO1030_REG_FRAMEWIDTH_L 0x05
32 #define PO1030_REG_FRAMEHEIGHT_H 0x06
33 #define PO1030_REG_FRAMEHEIGHT_L 0x07
34 #define PO1030_REG_WINDOWX_H 0x08
35 #define PO1030_REG_WINDOWX_L 0x09
36 #define PO1030_REG_WINDOWY_H 0x0a
37 #define PO1030_REG_WINDOWY_L 0x0b
38 #define PO1030_REG_WINDOWWIDTH_H 0x0c
39 #define PO1030_REG_WINDOWWIDTH_L 0x0d
40 #define PO1030_REG_WINDOWHEIGHT_H 0x0e
41 #define PO1030_REG_WINDOWHEIGHT_L 0x0f
43 #define PO1030_REG_GLOBALIBIAS 0x12
44 #define PO1030_REG_PIXELIBIAS 0x13
46 #define PO1030_REG_GLOBALGAIN 0x15
47 #define PO1030_REG_RED_GAIN 0x16
48 #define PO1030_REG_GREEN_1_GAIN 0x17
49 #define PO1030_REG_BLUE_GAIN 0x18
50 #define PO1030_REG_GREEN_2_GAIN 0x19
52 #define PO1030_REG_INTEGLINES_H 0x1a
53 #define PO1030_REG_INTEGLINES_M 0x1b
54 #define PO1030_REG_INTEGLINES_L 0x1c
56 #define PO1030_REG_CONTROL1 0x1d
57 #define PO1030_REG_CONTROL2 0x1e
58 #define PO1030_REG_CONTROL3 0x1f
59 #define PO1030_REG_CONTROL4 0x20
61 #define PO1030_REG_PERIOD50_H 0x23
62 #define PO1030_REG_PERIOD50_L 0x24
63 #define PO1030_REG_PERIOD60_H 0x25
64 #define PO1030_REG_PERIOD60_L 0x26
65 #define PO1030_REG_REGCLK167 0x27
66 #define PO1030_REG_DELTA50 0x28
67 #define PO1030_REG_DELTA60 0x29
69 #define PO1030_REG_ADCOFFSET 0x2c
71 /* Gamma Correction Coeffs */
72 #define PO1030_REG_GC0 0x2d
73 #define PO1030_REG_GC1 0x2e
74 #define PO1030_REG_GC2 0x2f
75 #define PO1030_REG_GC3 0x30
76 #define PO1030_REG_GC4 0x31
77 #define PO1030_REG_GC5 0x32
78 #define PO1030_REG_GC6 0x33
79 #define PO1030_REG_GC7 0x34
81 /* Color Transform Matrix */
82 #define PO1030_REG_CT0 0x35
83 #define PO1030_REG_CT1 0x36
84 #define PO1030_REG_CT2 0x37
85 #define PO1030_REG_CT3 0x38
86 #define PO1030_REG_CT4 0x39
87 #define PO1030_REG_CT5 0x3a
88 #define PO1030_REG_CT6 0x3b
89 #define PO1030_REG_CT7 0x3c
90 #define PO1030_REG_CT8 0x3d
92 #define PO1030_REG_AUTOCTRL1 0x3e
93 #define PO1030_REG_AUTOCTRL2 0x3f
95 #define PO1030_REG_YTARGET 0x40
96 #define PO1030_REG_GLOBALGAINMIN 0x41
97 #define PO1030_REG_GLOBALGAINMAX 0x42
99 /* Output format control */
100 #define PO1030_REG_OUTFORMCTRL1 0x5a
101 #define PO1030_REG_OUTFORMCTRL2 0x5b
102 #define PO1030_REG_OUTFORMCTRL3 0x5c
103 #define PO1030_REG_OUTFORMCTRL4 0x5d
104 #define PO1030_REG_OUTFORMCTRL5 0x5e
106 /* Imaging coefficients */
107 #define PO1030_REG_YBRIGHT 0x73
108 #define PO1030_REG_YCONTRAST 0x74
109 #define PO1030_REG_YSATURATION 0x75
111 #define PO1030_HFLIP (1 << 7)
112 #define PO1030_VFLIP (1 << 6)
114 /*****************************************************************************/
116 #define PO1030_GLOBAL_GAIN_DEFAULT 0x12
117 #define PO1030_EXPOSURE_DEFAULT 0x0085
118 #define PO1030_BLUE_GAIN_DEFAULT 0x40
119 #define PO1030_RED_GAIN_DEFAULT 0x40
121 /*****************************************************************************/
123 /* Kernel module parameters */
124 extern int force_sensor;
125 extern int dump_sensor;
127 int po1030_probe(struct sd *sd);
128 int po1030_init(struct sd *sd);
129 int po1030_power_down(struct sd *sd);
131 int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
132 int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
133 int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
134 int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val);
135 int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
136 int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
137 int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
138 int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
139 int po1030_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
140 int po1030_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
141 int po1030_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
142 int po1030_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
144 static struct ctrl po1030_ctrls[] = {
148 .type = V4L2_CTRL_TYPE_INTEGER,
153 .default_value = PO1030_GLOBAL_GAIN_DEFAULT,
154 .flags = V4L2_CTRL_FLAG_SLIDER
156 .set = po1030_set_gain,
157 .get = po1030_get_gain
160 .id = V4L2_CID_EXPOSURE,
161 .type = V4L2_CTRL_TYPE_INTEGER,
166 .default_value = PO1030_EXPOSURE_DEFAULT,
167 .flags = V4L2_CTRL_FLAG_SLIDER
169 .set = po1030_set_exposure,
170 .get = po1030_get_exposure
173 .id = V4L2_CID_RED_BALANCE,
174 .type = V4L2_CTRL_TYPE_INTEGER,
175 .name = "red balance",
179 .default_value = PO1030_RED_GAIN_DEFAULT,
180 .flags = V4L2_CTRL_FLAG_SLIDER
182 .set = po1030_set_red_balance,
183 .get = po1030_get_red_balance
186 .id = V4L2_CID_BLUE_BALANCE,
187 .type = V4L2_CTRL_TYPE_INTEGER,
188 .name = "blue balance",
192 .default_value = PO1030_BLUE_GAIN_DEFAULT,
193 .flags = V4L2_CTRL_FLAG_SLIDER
195 .set = po1030_set_blue_balance,
196 .get = po1030_get_blue_balance
199 .id = V4L2_CID_HFLIP,
200 .type = V4L2_CTRL_TYPE_BOOLEAN,
201 .name = "horizontal flip",
207 .set = po1030_set_hflip,
208 .get = po1030_get_hflip
211 .id = V4L2_CID_VFLIP,
212 .type = V4L2_CTRL_TYPE_BOOLEAN,
213 .name = "vertical flip",
219 .set = po1030_set_vflip,
220 .get = po1030_get_vflip
224 static struct m5602_sensor po1030 = {
227 .i2c_slave_id = 0xdc,
230 .probe = po1030_probe,
232 .power_down = po1030_power_down,
234 .ctrls = po1030_ctrls,
237 static const unsigned char preinit_po1030[][3] =
239 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
240 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
241 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
242 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
243 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
244 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
245 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
246 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
247 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
249 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
251 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
252 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
253 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
254 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
255 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
256 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
257 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
258 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
259 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
260 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
261 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
262 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
263 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
264 {BRIDGE, M5602_XB_SIG_INI, 0x01},
265 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
266 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
267 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
268 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
269 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
270 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
271 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
272 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
273 {BRIDGE, M5602_XB_SIG_INI, 0x00},
274 {BRIDGE, M5602_XB_SIG_INI, 0x02},
275 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
276 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
277 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
278 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
279 {BRIDGE, M5602_XB_SIG_INI, 0x00},
281 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
283 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
284 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
285 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
286 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
287 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
288 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
289 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
290 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
291 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
292 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
293 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
294 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
295 {BRIDGE, M5602_XB_GPIO_DAT, 0x00}
298 static const unsigned char init_po1030[][4] =
300 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
301 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
303 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
304 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
305 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
306 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
308 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
309 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
310 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
311 /*end of sequence 1*/
313 /*sequence 2 (same as stop sequence)*/
314 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
315 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
316 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
317 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
318 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
319 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
321 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
322 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
323 /*end of sequence 2*/
326 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
327 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
328 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
329 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
330 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
331 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
332 {BRIDGE, M5602_XB_SIG_INI, 0x01},
333 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
334 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
335 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
336 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
337 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
338 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
339 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
340 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
341 {BRIDGE, M5602_XB_SIG_INI, 0x00},
342 {BRIDGE, M5602_XB_SIG_INI, 0x02},
343 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
344 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
345 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
346 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
347 {BRIDGE, M5602_XB_SIG_INI, 0x00},
348 /*end of sequence 5*/
351 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
353 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
354 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
355 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
356 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
357 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
358 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
359 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
360 /*end of sequence 2 stop */
362 /* ---------------------------------
363 * end of init - begin of start
364 * --------------------------------- */
367 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
368 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
369 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
370 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
371 /*end of sequence 3*/
373 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
374 {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
375 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
376 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00},
378 {SENSOR, PO1030_REG_AUTOCTRL2, 0x04},
380 /* Set the width to 751 */
381 {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
382 {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef},
384 /* Set the height to 540 */
385 {SENSOR, PO1030_REG_FRAMEHEIGHT_H, 0x02},
386 {SENSOR, PO1030_REG_FRAMEHEIGHT_L, 0x1c},
388 /* Set the x window to 1 */
389 {SENSOR, PO1030_REG_WINDOWX_H, 0x00},
390 {SENSOR, PO1030_REG_WINDOWX_L, 0x01},
392 /* Set the y window to 1 */
393 {SENSOR, PO1030_REG_WINDOWY_H, 0x00},
394 {SENSOR, PO1030_REG_WINDOWY_L, 0x01},
396 {SENSOR, PO1030_REG_WINDOWWIDTH_H, 0x02},
397 {SENSOR, PO1030_REG_WINDOWWIDTH_L, 0x87},
398 {SENSOR, PO1030_REG_WINDOWHEIGHT_H, 0x01},
399 {SENSOR, PO1030_REG_WINDOWHEIGHT_L, 0xe3},
401 {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
402 {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
403 {SENSOR, PO1030_REG_AUTOCTRL1, 0x08},
404 {SENSOR, PO1030_REG_CONTROL2, 0x03},
405 {SENSOR, 0x21, 0x90},
406 {SENSOR, PO1030_REG_YTARGET, 0x60},
407 {SENSOR, 0x59, 0x13},
408 {SENSOR, PO1030_REG_OUTFORMCTRL1, 0x40},
409 {SENSOR, 0x5f, 0x00},
410 {SENSOR, 0x60, 0x80},
411 {SENSOR, 0x78, 0x14},
412 {SENSOR, 0x6f, 0x01},
413 {SENSOR, PO1030_REG_CONTROL1, 0x18},
414 {SENSOR, PO1030_REG_GLOBALGAINMAX, 0x14},
415 {SENSOR, 0x63, 0x38},
416 {SENSOR, 0x64, 0x38},
417 {SENSOR, PO1030_REG_CONTROL1, 0x58},
418 {SENSOR, PO1030_REG_RED_GAIN, 0x30},
419 {SENSOR, PO1030_REG_GREEN_1_GAIN, 0x30},
420 {SENSOR, PO1030_REG_BLUE_GAIN, 0x30},
421 {SENSOR, PO1030_REG_GREEN_2_GAIN, 0x30},
422 {SENSOR, PO1030_REG_GC0, 0x10},
423 {SENSOR, PO1030_REG_GC1, 0x20},
424 {SENSOR, PO1030_REG_GC2, 0x40},
425 {SENSOR, PO1030_REG_GC3, 0x60},
426 {SENSOR, PO1030_REG_GC4, 0x80},
427 {SENSOR, PO1030_REG_GC5, 0xa0},
428 {SENSOR, PO1030_REG_GC6, 0xc0},
429 {SENSOR, PO1030_REG_GC7, 0xff},
430 /*end of sequence 4*/
432 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
433 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
434 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
435 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
436 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
437 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
438 {BRIDGE, M5602_XB_SIG_INI, 0x01},
439 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
440 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
441 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
442 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
443 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
444 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
445 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
446 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
447 {BRIDGE, M5602_XB_SIG_INI, 0x00},
448 {BRIDGE, M5602_XB_SIG_INI, 0x00},
449 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
450 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
451 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
452 {BRIDGE, M5602_XB_HSYNC_PARA, 0x7e},
453 {BRIDGE, M5602_XB_SIG_INI, 0x00},
454 /*end of sequence 5*/
457 /* Changing 40 in f0 the image becomes green in bayer mode and red in
459 {SENSOR, PO1030_REG_RED_GAIN, PO1030_RED_GAIN_DEFAULT},
460 /* in changing 40 in f0 the image becomes green in bayer mode and red in
462 {SENSOR, PO1030_REG_BLUE_GAIN, PO1030_BLUE_GAIN_DEFAULT},
464 /* with a very low lighted environment increase the exposure but
465 * decrease the FPS (Frame Per Second) */
466 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
467 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
469 /* Controls high exposure more than SENSOR_LOW_EXPOSURE, use only in
470 * low lighted environment (f0 is more than ff ?)*/
471 {SENSOR, PO1030_REG_INTEGLINES_H, ((PO1030_EXPOSURE_DEFAULT >> 2)
474 /* Controls middle exposure, use only in high lighted environment */
475 {SENSOR, PO1030_REG_INTEGLINES_M, PO1030_EXPOSURE_DEFAULT & 0xff},
477 /* Controls clarity (not sure) */
478 {SENSOR, PO1030_REG_INTEGLINES_L, 0x00},
479 /* Controls gain (the image is more lighted) */
480 {SENSOR, PO1030_REG_GLOBALGAIN, PO1030_GLOBAL_GAIN_DEFAULT},
483 {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
484 {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef}
485 /*end of sequence 6*/