2 * Driver for the ov9650 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 #include "m5602_ov9650.h"
21 static int ov9650_set_exposure(struct gspca_dev
*gspca_dev
, __s32 val
);
22 static int ov9650_get_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
);
23 static int ov9650_get_gain(struct gspca_dev
*gspca_dev
, __s32
*val
);
24 static int ov9650_set_gain(struct gspca_dev
*gspca_dev
, __s32 val
);
25 static int ov9650_get_red_balance(struct gspca_dev
*gspca_dev
, __s32
*val
);
26 static int ov9650_set_red_balance(struct gspca_dev
*gspca_dev
, __s32 val
);
27 static int ov9650_get_blue_balance(struct gspca_dev
*gspca_dev
, __s32
*val
);
28 static int ov9650_set_blue_balance(struct gspca_dev
*gspca_dev
, __s32 val
);
29 static int ov9650_get_hflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
30 static int ov9650_set_hflip(struct gspca_dev
*gspca_dev
, __s32 val
);
31 static int ov9650_get_vflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
32 static int ov9650_set_vflip(struct gspca_dev
*gspca_dev
, __s32 val
);
33 static int ov9650_get_auto_white_balance(struct gspca_dev
*gspca_dev
,
35 static int ov9650_set_auto_white_balance(struct gspca_dev
*gspca_dev
,
37 static int ov9650_get_auto_gain(struct gspca_dev
*gspca_dev
, __s32
*val
);
38 static int ov9650_set_auto_gain(struct gspca_dev
*gspca_dev
, __s32 val
);
39 static int ov9650_get_auto_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
);
40 static int ov9650_set_auto_exposure(struct gspca_dev
*gspca_dev
, __s32 val
);
42 /* Vertically and horizontally flips the image if matched, needed for machines
43 where the sensor is mounted upside down */
46 struct dmi_system_id ov9650_flip_dmi_table
[] = {
50 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
51 DMI_MATCH(DMI_PRODUCT_NAME
, "A6J")
57 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
58 DMI_MATCH(DMI_PRODUCT_NAME
, "A6JC")
64 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
65 DMI_MATCH(DMI_PRODUCT_NAME
, "A6K")
71 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
72 DMI_MATCH(DMI_PRODUCT_NAME
, "A6Kt")
78 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
79 DMI_MATCH(DMI_PRODUCT_NAME
, "A6VA")
86 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
87 DMI_MATCH(DMI_PRODUCT_NAME
, "A6VC")
93 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
94 DMI_MATCH(DMI_PRODUCT_NAME
, "A6VM")
100 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
101 DMI_MATCH(DMI_PRODUCT_NAME
, "A7V")
105 .ident
= "Alienware Aurora m9700",
107 DMI_MATCH(DMI_SYS_VENDOR
, "alienware"),
108 DMI_MATCH(DMI_PRODUCT_NAME
, "Aurora m9700")
114 static const struct ctrl ov9650_ctrls
[] = {
115 #define EXPOSURE_IDX 0
118 .id
= V4L2_CID_EXPOSURE
,
119 .type
= V4L2_CTRL_TYPE_INTEGER
,
124 .default_value
= EXPOSURE_DEFAULT
,
125 .flags
= V4L2_CTRL_FLAG_SLIDER
127 .set
= ov9650_set_exposure
,
128 .get
= ov9650_get_exposure
134 .type
= V4L2_CTRL_TYPE_INTEGER
,
139 .default_value
= GAIN_DEFAULT
,
140 .flags
= V4L2_CTRL_FLAG_SLIDER
142 .set
= ov9650_set_gain
,
143 .get
= ov9650_get_gain
145 #define RED_BALANCE_IDX 2
148 .id
= V4L2_CID_RED_BALANCE
,
149 .type
= V4L2_CTRL_TYPE_INTEGER
,
150 .name
= "red balance",
154 .default_value
= RED_GAIN_DEFAULT
,
155 .flags
= V4L2_CTRL_FLAG_SLIDER
157 .set
= ov9650_set_red_balance
,
158 .get
= ov9650_get_red_balance
160 #define BLUE_BALANCE_IDX 3
163 .id
= V4L2_CID_BLUE_BALANCE
,
164 .type
= V4L2_CTRL_TYPE_INTEGER
,
165 .name
= "blue balance",
169 .default_value
= BLUE_GAIN_DEFAULT
,
170 .flags
= V4L2_CTRL_FLAG_SLIDER
172 .set
= ov9650_set_blue_balance
,
173 .get
= ov9650_get_blue_balance
178 .id
= V4L2_CID_HFLIP
,
179 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
180 .name
= "horizontal flip",
186 .set
= ov9650_set_hflip
,
187 .get
= ov9650_get_hflip
192 .id
= V4L2_CID_VFLIP
,
193 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
194 .name
= "vertical flip",
200 .set
= ov9650_set_vflip
,
201 .get
= ov9650_get_vflip
203 #define AUTO_WHITE_BALANCE_IDX 6
206 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
207 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
208 .name
= "auto white balance",
214 .set
= ov9650_set_auto_white_balance
,
215 .get
= ov9650_get_auto_white_balance
217 #define AUTO_GAIN_CTRL_IDX 7
220 .id
= V4L2_CID_AUTOGAIN
,
221 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
222 .name
= "auto gain control",
228 .set
= ov9650_set_auto_gain
,
229 .get
= ov9650_get_auto_gain
231 #define AUTO_EXPOSURE_IDX 8
234 .id
= V4L2_CID_EXPOSURE_AUTO
,
235 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
236 .name
= "auto exposure",
242 .set
= ov9650_set_auto_exposure
,
243 .get
= ov9650_get_auto_exposure
248 static struct v4l2_pix_format ov9650_modes
[] = {
257 .colorspace
= V4L2_COLORSPACE_SRGB
,
267 .colorspace
= V4L2_COLORSPACE_SRGB
,
277 .colorspace
= V4L2_COLORSPACE_SRGB
,
287 .colorspace
= V4L2_COLORSPACE_SRGB
,
292 static void ov9650_dump_registers(struct sd
*sd
);
294 int ov9650_probe(struct sd
*sd
)
297 u8 prod_id
= 0, ver_id
= 0, i
;
298 s32
*sensor_settings
;
301 if (force_sensor
== OV9650_SENSOR
) {
302 info("Forcing an %s sensor", ov9650
.name
);
305 /* If we want to force another sensor,
306 don't try to probe this one */
310 PDEBUG(D_PROBE
, "Probing for an ov9650 sensor");
312 /* Run the pre-init before probing the sensor */
313 for (i
= 0; i
< ARRAY_SIZE(preinit_ov9650
) && !err
; i
++) {
314 u8 data
= preinit_ov9650
[i
][2];
315 if (preinit_ov9650
[i
][0] == SENSOR
)
316 err
= m5602_write_sensor(sd
,
317 preinit_ov9650
[i
][1], &data
, 1);
319 err
= m5602_write_bridge(sd
,
320 preinit_ov9650
[i
][1], data
);
326 if (m5602_read_sensor(sd
, OV9650_PID
, &prod_id
, 1))
329 if (m5602_read_sensor(sd
, OV9650_VER
, &ver_id
, 1))
332 if ((prod_id
== 0x96) && (ver_id
== 0x52)) {
333 info("Detected an ov9650 sensor");
339 sensor_settings
= kmalloc(
340 ARRAY_SIZE(ov9650_ctrls
) * sizeof(s32
), GFP_KERNEL
);
341 if (!sensor_settings
)
344 sd
->gspca_dev
.cam
.cam_mode
= ov9650_modes
;
345 sd
->gspca_dev
.cam
.nmodes
= ARRAY_SIZE(ov9650_modes
);
346 sd
->desc
->ctrls
= ov9650_ctrls
;
347 sd
->desc
->nctrls
= ARRAY_SIZE(ov9650_ctrls
);
349 for (i
= 0; i
< ARRAY_SIZE(ov9650_ctrls
); i
++)
350 sensor_settings
[i
] = ov9650_ctrls
[i
].qctrl
.default_value
;
351 sd
->sensor_priv
= sensor_settings
;
355 int ov9650_init(struct sd
*sd
)
359 s32
*sensor_settings
= sd
->sensor_priv
;
362 ov9650_dump_registers(sd
);
364 for (i
= 0; i
< ARRAY_SIZE(init_ov9650
) && !err
; i
++) {
365 data
= init_ov9650
[i
][2];
366 if (init_ov9650
[i
][0] == SENSOR
)
367 err
= m5602_write_sensor(sd
, init_ov9650
[i
][1],
370 err
= m5602_write_bridge(sd
, init_ov9650
[i
][1], data
);
373 err
= ov9650_set_exposure(&sd
->gspca_dev
,
374 sensor_settings
[EXPOSURE_IDX
]);
378 err
= ov9650_set_gain(&sd
->gspca_dev
, sensor_settings
[GAIN_IDX
]);
382 err
= ov9650_set_red_balance(&sd
->gspca_dev
,
383 sensor_settings
[RED_BALANCE_IDX
]);
387 err
= ov9650_set_blue_balance(&sd
->gspca_dev
,
388 sensor_settings
[BLUE_BALANCE_IDX
]);
392 err
= ov9650_set_hflip(&sd
->gspca_dev
, sensor_settings
[HFLIP_IDX
]);
396 err
= ov9650_set_vflip(&sd
->gspca_dev
, sensor_settings
[VFLIP_IDX
]);
400 err
= ov9650_set_auto_exposure(&sd
->gspca_dev
,
401 sensor_settings
[AUTO_EXPOSURE_IDX
]);
405 err
= ov9650_set_auto_white_balance(&sd
->gspca_dev
,
406 sensor_settings
[AUTO_WHITE_BALANCE_IDX
]);
410 err
= ov9650_set_auto_gain(&sd
->gspca_dev
,
411 sensor_settings
[AUTO_GAIN_CTRL_IDX
]);
415 int ov9650_start(struct sd
*sd
)
419 struct cam
*cam
= &sd
->gspca_dev
.cam
;
420 s32
*sensor_settings
= sd
->sensor_priv
;
422 int width
= cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].width
;
423 int height
= cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].height
;
424 int ver_offs
= cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].priv
;
425 int hor_offs
= OV9650_LEFT_OFFSET
;
427 if ((!dmi_check_system(ov9650_flip_dmi_table
) &&
428 sensor_settings
[VFLIP_IDX
]) ||
429 (dmi_check_system(ov9650_flip_dmi_table
) &&
430 !sensor_settings
[VFLIP_IDX
]))
436 /* Synthesize the vsync/hsync setup */
437 for (i
= 0; i
< ARRAY_SIZE(res_init_ov9650
) && !err
; i
++) {
438 if (res_init_ov9650
[i
][0] == BRIDGE
)
439 err
= m5602_write_bridge(sd
, res_init_ov9650
[i
][1],
440 res_init_ov9650
[i
][2]);
441 else if (res_init_ov9650
[i
][0] == SENSOR
) {
442 data
= res_init_ov9650
[i
][2];
443 err
= m5602_write_sensor(sd
,
444 res_init_ov9650
[i
][1], &data
, 1);
450 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
,
451 ((ver_offs
>> 8) & 0xff));
455 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, (ver_offs
& 0xff));
459 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, 0);
463 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, (height
>> 8) & 0xff);
467 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, (height
& 0xff));
471 for (i
= 0; i
< 2 && !err
; i
++)
472 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, 0);
476 err
= m5602_write_bridge(sd
, M5602_XB_SIG_INI
, 0);
480 err
= m5602_write_bridge(sd
, M5602_XB_SIG_INI
, 2);
484 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
,
485 (hor_offs
>> 8) & 0xff);
489 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
, hor_offs
& 0xff);
493 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
,
494 ((width
+ hor_offs
) >> 8) & 0xff);
498 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
,
499 ((width
+ hor_offs
) & 0xff));
503 err
= m5602_write_bridge(sd
, M5602_XB_SIG_INI
, 0);
509 PDEBUG(D_V4L2
, "Configuring camera for VGA mode");
511 data
= OV9650_VGA_SELECT
| OV9650_RGB_SELECT
|
512 OV9650_RAW_RGB_SELECT
;
513 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
517 PDEBUG(D_V4L2
, "Configuring camera for CIF mode");
519 data
= OV9650_CIF_SELECT
| OV9650_RGB_SELECT
|
520 OV9650_RAW_RGB_SELECT
;
521 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
525 PDEBUG(D_V4L2
, "Configuring camera for QVGA mode");
527 data
= OV9650_QVGA_SELECT
| OV9650_RGB_SELECT
|
528 OV9650_RAW_RGB_SELECT
;
529 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
533 PDEBUG(D_V4L2
, "Configuring camera for QCIF mode");
535 data
= OV9650_QCIF_SELECT
| OV9650_RGB_SELECT
|
536 OV9650_RAW_RGB_SELECT
;
537 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
543 int ov9650_stop(struct sd
*sd
)
545 u8 data
= OV9650_SOFT_SLEEP
| OV9650_OUTPUT_DRIVE_2X
;
546 return m5602_write_sensor(sd
, OV9650_COM2
, &data
, 1);
549 void ov9650_disconnect(struct sd
*sd
)
554 kfree(sd
->sensor_priv
);
557 static int ov9650_get_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
)
559 struct sd
*sd
= (struct sd
*) gspca_dev
;
560 s32
*sensor_settings
= sd
->sensor_priv
;
562 *val
= sensor_settings
[EXPOSURE_IDX
];
563 PDEBUG(D_V4L2
, "Read exposure %d", *val
);
567 static int ov9650_set_exposure(struct gspca_dev
*gspca_dev
, __s32 val
)
569 struct sd
*sd
= (struct sd
*) gspca_dev
;
570 s32
*sensor_settings
= sd
->sensor_priv
;
574 PDEBUG(D_V4L2
, "Set exposure to %d", val
);
576 sensor_settings
[EXPOSURE_IDX
] = val
;
578 i2c_data
= (val
>> 10) & 0x3f;
579 err
= m5602_write_sensor(sd
, OV9650_AECHM
,
584 /* The 8 middle bits */
585 i2c_data
= (val
>> 2) & 0xff;
586 err
= m5602_write_sensor(sd
, OV9650_AECH
,
592 i2c_data
= val
& 0x03;
593 err
= m5602_write_sensor(sd
, OV9650_COM1
, &i2c_data
, 1);
597 static int ov9650_get_gain(struct gspca_dev
*gspca_dev
, __s32
*val
)
599 struct sd
*sd
= (struct sd
*) gspca_dev
;
600 s32
*sensor_settings
= sd
->sensor_priv
;
602 *val
= sensor_settings
[GAIN_IDX
];
603 PDEBUG(D_V4L2
, "Read gain %d", *val
);
607 static int ov9650_set_gain(struct gspca_dev
*gspca_dev
, __s32 val
)
611 struct sd
*sd
= (struct sd
*) gspca_dev
;
612 s32
*sensor_settings
= sd
->sensor_priv
;
614 PDEBUG(D_V4L2
, "Setting gain to %d", val
);
616 sensor_settings
[GAIN_IDX
] = val
;
619 /* Read the OV9650_VREF register first to avoid
620 corrupting the VREF high and low bits */
621 err
= m5602_read_sensor(sd
, OV9650_VREF
, &i2c_data
, 1);
625 /* Mask away all uninteresting bits */
626 i2c_data
= ((val
& 0x0300) >> 2) |
628 err
= m5602_write_sensor(sd
, OV9650_VREF
, &i2c_data
, 1);
633 i2c_data
= val
& 0xff;
634 err
= m5602_write_sensor(sd
, OV9650_GAIN
, &i2c_data
, 1);
638 static int ov9650_get_red_balance(struct gspca_dev
*gspca_dev
, __s32
*val
)
640 struct sd
*sd
= (struct sd
*) gspca_dev
;
641 s32
*sensor_settings
= sd
->sensor_priv
;
643 *val
= sensor_settings
[RED_BALANCE_IDX
];
644 PDEBUG(D_V4L2
, "Read red gain %d", *val
);
648 static int ov9650_set_red_balance(struct gspca_dev
*gspca_dev
, __s32 val
)
652 struct sd
*sd
= (struct sd
*) gspca_dev
;
653 s32
*sensor_settings
= sd
->sensor_priv
;
655 PDEBUG(D_V4L2
, "Set red gain to %d", val
);
657 sensor_settings
[RED_BALANCE_IDX
] = val
;
659 i2c_data
= val
& 0xff;
660 err
= m5602_write_sensor(sd
, OV9650_RED
, &i2c_data
, 1);
664 static int ov9650_get_blue_balance(struct gspca_dev
*gspca_dev
, __s32
*val
)
666 struct sd
*sd
= (struct sd
*) gspca_dev
;
667 s32
*sensor_settings
= sd
->sensor_priv
;
669 *val
= sensor_settings
[BLUE_BALANCE_IDX
];
670 PDEBUG(D_V4L2
, "Read blue gain %d", *val
);
675 static int ov9650_set_blue_balance(struct gspca_dev
*gspca_dev
, __s32 val
)
679 struct sd
*sd
= (struct sd
*) gspca_dev
;
680 s32
*sensor_settings
= sd
->sensor_priv
;
682 PDEBUG(D_V4L2
, "Set blue gain to %d", val
);
684 sensor_settings
[BLUE_BALANCE_IDX
] = val
;
686 i2c_data
= val
& 0xff;
687 err
= m5602_write_sensor(sd
, OV9650_BLUE
, &i2c_data
, 1);
691 static int ov9650_get_hflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
693 struct sd
*sd
= (struct sd
*) gspca_dev
;
694 s32
*sensor_settings
= sd
->sensor_priv
;
696 *val
= sensor_settings
[HFLIP_IDX
];
697 PDEBUG(D_V4L2
, "Read horizontal flip %d", *val
);
701 static int ov9650_set_hflip(struct gspca_dev
*gspca_dev
, __s32 val
)
705 struct sd
*sd
= (struct sd
*) gspca_dev
;
706 s32
*sensor_settings
= sd
->sensor_priv
;
708 PDEBUG(D_V4L2
, "Set horizontal flip to %d", val
);
710 sensor_settings
[HFLIP_IDX
] = val
;
712 if (!dmi_check_system(ov9650_flip_dmi_table
))
713 i2c_data
= ((val
& 0x01) << 5) |
714 (sensor_settings
[VFLIP_IDX
] << 4);
716 i2c_data
= ((val
& 0x01) << 5) |
717 (!sensor_settings
[VFLIP_IDX
] << 4);
719 err
= m5602_write_sensor(sd
, OV9650_MVFP
, &i2c_data
, 1);
724 static int ov9650_get_vflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
726 struct sd
*sd
= (struct sd
*) gspca_dev
;
727 s32
*sensor_settings
= sd
->sensor_priv
;
729 *val
= sensor_settings
[VFLIP_IDX
];
730 PDEBUG(D_V4L2
, "Read vertical flip %d", *val
);
735 static int ov9650_set_vflip(struct gspca_dev
*gspca_dev
, __s32 val
)
739 struct sd
*sd
= (struct sd
*) gspca_dev
;
740 s32
*sensor_settings
= sd
->sensor_priv
;
742 PDEBUG(D_V4L2
, "Set vertical flip to %d", val
);
743 sensor_settings
[VFLIP_IDX
] = val
;
745 if (dmi_check_system(ov9650_flip_dmi_table
))
748 i2c_data
= ((val
& 0x01) << 4) | (sensor_settings
[VFLIP_IDX
] << 5);
749 err
= m5602_write_sensor(sd
, OV9650_MVFP
, &i2c_data
, 1);
753 /* When vflip is toggled we need to readjust the bridge hsync/vsync */
754 if (gspca_dev
->streaming
)
755 err
= ov9650_start(sd
);
760 static int ov9650_get_auto_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
)
762 struct sd
*sd
= (struct sd
*) gspca_dev
;
763 s32
*sensor_settings
= sd
->sensor_priv
;
765 *val
= sensor_settings
[AUTO_EXPOSURE_IDX
];
766 PDEBUG(D_V4L2
, "Read auto exposure control %d", *val
);
770 static int ov9650_set_auto_exposure(struct gspca_dev
*gspca_dev
,
775 struct sd
*sd
= (struct sd
*) gspca_dev
;
776 s32
*sensor_settings
= sd
->sensor_priv
;
778 PDEBUG(D_V4L2
, "Set auto exposure control to %d", val
);
780 sensor_settings
[AUTO_EXPOSURE_IDX
] = val
;
781 err
= m5602_read_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
785 i2c_data
= ((i2c_data
& 0xfe) | ((val
& 0x01) << 0));
787 return m5602_write_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
790 static int ov9650_get_auto_white_balance(struct gspca_dev
*gspca_dev
,
793 struct sd
*sd
= (struct sd
*) gspca_dev
;
794 s32
*sensor_settings
= sd
->sensor_priv
;
796 *val
= sensor_settings
[AUTO_WHITE_BALANCE_IDX
];
800 static int ov9650_set_auto_white_balance(struct gspca_dev
*gspca_dev
,
805 struct sd
*sd
= (struct sd
*) gspca_dev
;
806 s32
*sensor_settings
= sd
->sensor_priv
;
808 PDEBUG(D_V4L2
, "Set auto white balance to %d", val
);
810 sensor_settings
[AUTO_WHITE_BALANCE_IDX
] = val
;
811 err
= m5602_read_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
815 i2c_data
= ((i2c_data
& 0xfd) | ((val
& 0x01) << 1));
816 err
= m5602_write_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
821 static int ov9650_get_auto_gain(struct gspca_dev
*gspca_dev
, __s32
*val
)
823 struct sd
*sd
= (struct sd
*) gspca_dev
;
824 s32
*sensor_settings
= sd
->sensor_priv
;
826 *val
= sensor_settings
[AUTO_GAIN_CTRL_IDX
];
827 PDEBUG(D_V4L2
, "Read auto gain control %d", *val
);
831 static int ov9650_set_auto_gain(struct gspca_dev
*gspca_dev
, __s32 val
)
835 struct sd
*sd
= (struct sd
*) gspca_dev
;
836 s32
*sensor_settings
= sd
->sensor_priv
;
838 PDEBUG(D_V4L2
, "Set auto gain control to %d", val
);
840 sensor_settings
[AUTO_GAIN_CTRL_IDX
] = val
;
841 err
= m5602_read_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
845 i2c_data
= ((i2c_data
& 0xfb) | ((val
& 0x01) << 2));
847 return m5602_write_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
850 static void ov9650_dump_registers(struct sd
*sd
)
853 info("Dumping the ov9650 register state");
854 for (address
= 0; address
< 0xa9; address
++) {
856 m5602_read_sensor(sd
, address
, &value
, 1);
857 info("register 0x%x contains 0x%x",
861 info("ov9650 register state dump complete");
863 info("Probing for which registers that are read/write");
864 for (address
= 0; address
< 0xff; address
++) {
865 u8 old_value
, ctrl_value
;
866 u8 test_value
[2] = {0xff, 0xff};
868 m5602_read_sensor(sd
, address
, &old_value
, 1);
869 m5602_write_sensor(sd
, address
, test_value
, 1);
870 m5602_read_sensor(sd
, address
, &ctrl_value
, 1);
872 if (ctrl_value
== test_value
[0])
873 info("register 0x%x is writeable", address
);
875 info("register 0x%x is read only", address
);
877 /* Restore original value */
878 m5602_write_sensor(sd
, address
, &old_value
, 1);