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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21 #include "m5602_ov9650.h"
23 static int ov9650_set_exposure(struct gspca_dev
*gspca_dev
, __s32 val
);
24 static int ov9650_get_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
);
25 static int ov9650_get_gain(struct gspca_dev
*gspca_dev
, __s32
*val
);
26 static int ov9650_set_gain(struct gspca_dev
*gspca_dev
, __s32 val
);
27 static int ov9650_get_red_balance(struct gspca_dev
*gspca_dev
, __s32
*val
);
28 static int ov9650_set_red_balance(struct gspca_dev
*gspca_dev
, __s32 val
);
29 static int ov9650_get_blue_balance(struct gspca_dev
*gspca_dev
, __s32
*val
);
30 static int ov9650_set_blue_balance(struct gspca_dev
*gspca_dev
, __s32 val
);
31 static int ov9650_get_hflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
32 static int ov9650_set_hflip(struct gspca_dev
*gspca_dev
, __s32 val
);
33 static int ov9650_get_vflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
34 static int ov9650_set_vflip(struct gspca_dev
*gspca_dev
, __s32 val
);
35 static int ov9650_get_auto_white_balance(struct gspca_dev
*gspca_dev
,
37 static int ov9650_set_auto_white_balance(struct gspca_dev
*gspca_dev
,
39 static int ov9650_get_auto_gain(struct gspca_dev
*gspca_dev
, __s32
*val
);
40 static int ov9650_set_auto_gain(struct gspca_dev
*gspca_dev
, __s32 val
);
41 static int ov9650_get_auto_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
);
42 static int ov9650_set_auto_exposure(struct gspca_dev
*gspca_dev
, __s32 val
);
44 /* Vertically and horizontally flips the image if matched, needed for machines
45 where the sensor is mounted upside down */
48 struct dmi_system_id ov9650_flip_dmi_table
[] = {
52 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
53 DMI_MATCH(DMI_PRODUCT_NAME
, "A6J")
59 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
60 DMI_MATCH(DMI_PRODUCT_NAME
, "A6JC")
66 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
67 DMI_MATCH(DMI_PRODUCT_NAME
, "A6K")
73 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
74 DMI_MATCH(DMI_PRODUCT_NAME
, "A6Kt")
80 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
81 DMI_MATCH(DMI_PRODUCT_NAME
, "A6VA")
88 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
89 DMI_MATCH(DMI_PRODUCT_NAME
, "A6VC")
95 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
96 DMI_MATCH(DMI_PRODUCT_NAME
, "A6VM")
102 DMI_MATCH(DMI_SYS_VENDOR
, "ASUSTeK Computer Inc."),
103 DMI_MATCH(DMI_PRODUCT_NAME
, "A7V")
107 .ident
= "Alienware Aurora m9700",
109 DMI_MATCH(DMI_SYS_VENDOR
, "alienware"),
110 DMI_MATCH(DMI_PRODUCT_NAME
, "Aurora m9700")
116 static const struct ctrl ov9650_ctrls
[] = {
117 #define EXPOSURE_IDX 0
120 .id
= V4L2_CID_EXPOSURE
,
121 .type
= V4L2_CTRL_TYPE_INTEGER
,
126 .default_value
= EXPOSURE_DEFAULT
,
127 .flags
= V4L2_CTRL_FLAG_SLIDER
129 .set
= ov9650_set_exposure
,
130 .get
= ov9650_get_exposure
136 .type
= V4L2_CTRL_TYPE_INTEGER
,
141 .default_value
= GAIN_DEFAULT
,
142 .flags
= V4L2_CTRL_FLAG_SLIDER
144 .set
= ov9650_set_gain
,
145 .get
= ov9650_get_gain
147 #define RED_BALANCE_IDX 2
150 .id
= V4L2_CID_RED_BALANCE
,
151 .type
= V4L2_CTRL_TYPE_INTEGER
,
152 .name
= "red balance",
156 .default_value
= RED_GAIN_DEFAULT
,
157 .flags
= V4L2_CTRL_FLAG_SLIDER
159 .set
= ov9650_set_red_balance
,
160 .get
= ov9650_get_red_balance
162 #define BLUE_BALANCE_IDX 3
165 .id
= V4L2_CID_BLUE_BALANCE
,
166 .type
= V4L2_CTRL_TYPE_INTEGER
,
167 .name
= "blue balance",
171 .default_value
= BLUE_GAIN_DEFAULT
,
172 .flags
= V4L2_CTRL_FLAG_SLIDER
174 .set
= ov9650_set_blue_balance
,
175 .get
= ov9650_get_blue_balance
180 .id
= V4L2_CID_HFLIP
,
181 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
182 .name
= "horizontal flip",
188 .set
= ov9650_set_hflip
,
189 .get
= ov9650_get_hflip
194 .id
= V4L2_CID_VFLIP
,
195 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
196 .name
= "vertical flip",
202 .set
= ov9650_set_vflip
,
203 .get
= ov9650_get_vflip
205 #define AUTO_WHITE_BALANCE_IDX 6
208 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
209 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
210 .name
= "auto white balance",
216 .set
= ov9650_set_auto_white_balance
,
217 .get
= ov9650_get_auto_white_balance
219 #define AUTO_GAIN_CTRL_IDX 7
222 .id
= V4L2_CID_AUTOGAIN
,
223 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
224 .name
= "auto gain control",
230 .set
= ov9650_set_auto_gain
,
231 .get
= ov9650_get_auto_gain
233 #define AUTO_EXPOSURE_IDX 8
236 .id
= V4L2_CID_EXPOSURE_AUTO
,
237 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
238 .name
= "auto exposure",
244 .set
= ov9650_set_auto_exposure
,
245 .get
= ov9650_get_auto_exposure
250 static struct v4l2_pix_format ov9650_modes
[] = {
259 .colorspace
= V4L2_COLORSPACE_SRGB
,
269 .colorspace
= V4L2_COLORSPACE_SRGB
,
279 .colorspace
= V4L2_COLORSPACE_SRGB
,
289 .colorspace
= V4L2_COLORSPACE_SRGB
,
294 static void ov9650_dump_registers(struct sd
*sd
);
296 int ov9650_probe(struct sd
*sd
)
299 u8 prod_id
= 0, ver_id
= 0, i
;
300 s32
*sensor_settings
;
303 if (force_sensor
== OV9650_SENSOR
) {
304 pr_info("Forcing an %s sensor\n", ov9650
.name
);
307 /* If we want to force another sensor,
308 don't try to probe this one */
312 PDEBUG(D_PROBE
, "Probing for an ov9650 sensor");
314 /* Run the pre-init before probing the sensor */
315 for (i
= 0; i
< ARRAY_SIZE(preinit_ov9650
) && !err
; i
++) {
316 u8 data
= preinit_ov9650
[i
][2];
317 if (preinit_ov9650
[i
][0] == SENSOR
)
318 err
= m5602_write_sensor(sd
,
319 preinit_ov9650
[i
][1], &data
, 1);
321 err
= m5602_write_bridge(sd
,
322 preinit_ov9650
[i
][1], data
);
328 if (m5602_read_sensor(sd
, OV9650_PID
, &prod_id
, 1))
331 if (m5602_read_sensor(sd
, OV9650_VER
, &ver_id
, 1))
334 if ((prod_id
== 0x96) && (ver_id
== 0x52)) {
335 pr_info("Detected an ov9650 sensor\n");
341 sensor_settings
= kmalloc(
342 ARRAY_SIZE(ov9650_ctrls
) * sizeof(s32
), GFP_KERNEL
);
343 if (!sensor_settings
)
346 sd
->gspca_dev
.cam
.cam_mode
= ov9650_modes
;
347 sd
->gspca_dev
.cam
.nmodes
= ARRAY_SIZE(ov9650_modes
);
348 sd
->desc
->ctrls
= ov9650_ctrls
;
349 sd
->desc
->nctrls
= ARRAY_SIZE(ov9650_ctrls
);
351 for (i
= 0; i
< ARRAY_SIZE(ov9650_ctrls
); i
++)
352 sensor_settings
[i
] = ov9650_ctrls
[i
].qctrl
.default_value
;
353 sd
->sensor_priv
= sensor_settings
;
357 int ov9650_init(struct sd
*sd
)
361 s32
*sensor_settings
= sd
->sensor_priv
;
364 ov9650_dump_registers(sd
);
366 for (i
= 0; i
< ARRAY_SIZE(init_ov9650
) && !err
; i
++) {
367 data
= init_ov9650
[i
][2];
368 if (init_ov9650
[i
][0] == SENSOR
)
369 err
= m5602_write_sensor(sd
, init_ov9650
[i
][1],
372 err
= m5602_write_bridge(sd
, init_ov9650
[i
][1], data
);
375 err
= ov9650_set_exposure(&sd
->gspca_dev
,
376 sensor_settings
[EXPOSURE_IDX
]);
380 err
= ov9650_set_gain(&sd
->gspca_dev
, sensor_settings
[GAIN_IDX
]);
384 err
= ov9650_set_red_balance(&sd
->gspca_dev
,
385 sensor_settings
[RED_BALANCE_IDX
]);
389 err
= ov9650_set_blue_balance(&sd
->gspca_dev
,
390 sensor_settings
[BLUE_BALANCE_IDX
]);
394 err
= ov9650_set_hflip(&sd
->gspca_dev
, sensor_settings
[HFLIP_IDX
]);
398 err
= ov9650_set_vflip(&sd
->gspca_dev
, sensor_settings
[VFLIP_IDX
]);
402 err
= ov9650_set_auto_exposure(&sd
->gspca_dev
,
403 sensor_settings
[AUTO_EXPOSURE_IDX
]);
407 err
= ov9650_set_auto_white_balance(&sd
->gspca_dev
,
408 sensor_settings
[AUTO_WHITE_BALANCE_IDX
]);
412 err
= ov9650_set_auto_gain(&sd
->gspca_dev
,
413 sensor_settings
[AUTO_GAIN_CTRL_IDX
]);
417 int ov9650_start(struct sd
*sd
)
421 struct cam
*cam
= &sd
->gspca_dev
.cam
;
422 s32
*sensor_settings
= sd
->sensor_priv
;
424 int width
= cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].width
;
425 int height
= cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].height
;
426 int ver_offs
= cam
->cam_mode
[sd
->gspca_dev
.curr_mode
].priv
;
427 int hor_offs
= OV9650_LEFT_OFFSET
;
429 if ((!dmi_check_system(ov9650_flip_dmi_table
) &&
430 sensor_settings
[VFLIP_IDX
]) ||
431 (dmi_check_system(ov9650_flip_dmi_table
) &&
432 !sensor_settings
[VFLIP_IDX
]))
438 /* Synthesize the vsync/hsync setup */
439 for (i
= 0; i
< ARRAY_SIZE(res_init_ov9650
) && !err
; i
++) {
440 if (res_init_ov9650
[i
][0] == BRIDGE
)
441 err
= m5602_write_bridge(sd
, res_init_ov9650
[i
][1],
442 res_init_ov9650
[i
][2]);
443 else if (res_init_ov9650
[i
][0] == SENSOR
) {
444 data
= res_init_ov9650
[i
][2];
445 err
= m5602_write_sensor(sd
,
446 res_init_ov9650
[i
][1], &data
, 1);
452 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
,
453 ((ver_offs
>> 8) & 0xff));
457 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, (ver_offs
& 0xff));
461 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, 0);
465 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, (height
>> 8) & 0xff);
469 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, (height
& 0xff));
473 for (i
= 0; i
< 2 && !err
; i
++)
474 err
= m5602_write_bridge(sd
, M5602_XB_VSYNC_PARA
, 0);
478 err
= m5602_write_bridge(sd
, M5602_XB_SIG_INI
, 0);
482 err
= m5602_write_bridge(sd
, M5602_XB_SIG_INI
, 2);
486 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
,
487 (hor_offs
>> 8) & 0xff);
491 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
, hor_offs
& 0xff);
495 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
,
496 ((width
+ hor_offs
) >> 8) & 0xff);
500 err
= m5602_write_bridge(sd
, M5602_XB_HSYNC_PARA
,
501 ((width
+ hor_offs
) & 0xff));
505 err
= m5602_write_bridge(sd
, M5602_XB_SIG_INI
, 0);
511 PDEBUG(D_V4L2
, "Configuring camera for VGA mode");
513 data
= OV9650_VGA_SELECT
| OV9650_RGB_SELECT
|
514 OV9650_RAW_RGB_SELECT
;
515 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
519 PDEBUG(D_V4L2
, "Configuring camera for CIF mode");
521 data
= OV9650_CIF_SELECT
| OV9650_RGB_SELECT
|
522 OV9650_RAW_RGB_SELECT
;
523 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
527 PDEBUG(D_V4L2
, "Configuring camera for QVGA mode");
529 data
= OV9650_QVGA_SELECT
| OV9650_RGB_SELECT
|
530 OV9650_RAW_RGB_SELECT
;
531 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
535 PDEBUG(D_V4L2
, "Configuring camera for QCIF mode");
537 data
= OV9650_QCIF_SELECT
| OV9650_RGB_SELECT
|
538 OV9650_RAW_RGB_SELECT
;
539 err
= m5602_write_sensor(sd
, OV9650_COM7
, &data
, 1);
545 int ov9650_stop(struct sd
*sd
)
547 u8 data
= OV9650_SOFT_SLEEP
| OV9650_OUTPUT_DRIVE_2X
;
548 return m5602_write_sensor(sd
, OV9650_COM2
, &data
, 1);
551 void ov9650_disconnect(struct sd
*sd
)
556 kfree(sd
->sensor_priv
);
559 static int ov9650_get_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
)
561 struct sd
*sd
= (struct sd
*) gspca_dev
;
562 s32
*sensor_settings
= sd
->sensor_priv
;
564 *val
= sensor_settings
[EXPOSURE_IDX
];
565 PDEBUG(D_V4L2
, "Read exposure %d", *val
);
569 static int ov9650_set_exposure(struct gspca_dev
*gspca_dev
, __s32 val
)
571 struct sd
*sd
= (struct sd
*) gspca_dev
;
572 s32
*sensor_settings
= sd
->sensor_priv
;
576 PDEBUG(D_V4L2
, "Set exposure to %d", val
);
578 sensor_settings
[EXPOSURE_IDX
] = val
;
580 i2c_data
= (val
>> 10) & 0x3f;
581 err
= m5602_write_sensor(sd
, OV9650_AECHM
,
586 /* The 8 middle bits */
587 i2c_data
= (val
>> 2) & 0xff;
588 err
= m5602_write_sensor(sd
, OV9650_AECH
,
594 i2c_data
= val
& 0x03;
595 err
= m5602_write_sensor(sd
, OV9650_COM1
, &i2c_data
, 1);
599 static int ov9650_get_gain(struct gspca_dev
*gspca_dev
, __s32
*val
)
601 struct sd
*sd
= (struct sd
*) gspca_dev
;
602 s32
*sensor_settings
= sd
->sensor_priv
;
604 *val
= sensor_settings
[GAIN_IDX
];
605 PDEBUG(D_V4L2
, "Read gain %d", *val
);
609 static int ov9650_set_gain(struct gspca_dev
*gspca_dev
, __s32 val
)
613 struct sd
*sd
= (struct sd
*) gspca_dev
;
614 s32
*sensor_settings
= sd
->sensor_priv
;
616 PDEBUG(D_V4L2
, "Setting gain to %d", val
);
618 sensor_settings
[GAIN_IDX
] = val
;
621 /* Read the OV9650_VREF register first to avoid
622 corrupting the VREF high and low bits */
623 err
= m5602_read_sensor(sd
, OV9650_VREF
, &i2c_data
, 1);
627 /* Mask away all uninteresting bits */
628 i2c_data
= ((val
& 0x0300) >> 2) |
630 err
= m5602_write_sensor(sd
, OV9650_VREF
, &i2c_data
, 1);
635 i2c_data
= val
& 0xff;
636 err
= m5602_write_sensor(sd
, OV9650_GAIN
, &i2c_data
, 1);
640 static int ov9650_get_red_balance(struct gspca_dev
*gspca_dev
, __s32
*val
)
642 struct sd
*sd
= (struct sd
*) gspca_dev
;
643 s32
*sensor_settings
= sd
->sensor_priv
;
645 *val
= sensor_settings
[RED_BALANCE_IDX
];
646 PDEBUG(D_V4L2
, "Read red gain %d", *val
);
650 static int ov9650_set_red_balance(struct gspca_dev
*gspca_dev
, __s32 val
)
654 struct sd
*sd
= (struct sd
*) gspca_dev
;
655 s32
*sensor_settings
= sd
->sensor_priv
;
657 PDEBUG(D_V4L2
, "Set red gain to %d", val
);
659 sensor_settings
[RED_BALANCE_IDX
] = val
;
661 i2c_data
= val
& 0xff;
662 err
= m5602_write_sensor(sd
, OV9650_RED
, &i2c_data
, 1);
666 static int ov9650_get_blue_balance(struct gspca_dev
*gspca_dev
, __s32
*val
)
668 struct sd
*sd
= (struct sd
*) gspca_dev
;
669 s32
*sensor_settings
= sd
->sensor_priv
;
671 *val
= sensor_settings
[BLUE_BALANCE_IDX
];
672 PDEBUG(D_V4L2
, "Read blue gain %d", *val
);
677 static int ov9650_set_blue_balance(struct gspca_dev
*gspca_dev
, __s32 val
)
681 struct sd
*sd
= (struct sd
*) gspca_dev
;
682 s32
*sensor_settings
= sd
->sensor_priv
;
684 PDEBUG(D_V4L2
, "Set blue gain to %d", val
);
686 sensor_settings
[BLUE_BALANCE_IDX
] = val
;
688 i2c_data
= val
& 0xff;
689 err
= m5602_write_sensor(sd
, OV9650_BLUE
, &i2c_data
, 1);
693 static int ov9650_get_hflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
695 struct sd
*sd
= (struct sd
*) gspca_dev
;
696 s32
*sensor_settings
= sd
->sensor_priv
;
698 *val
= sensor_settings
[HFLIP_IDX
];
699 PDEBUG(D_V4L2
, "Read horizontal flip %d", *val
);
703 static int ov9650_set_hflip(struct gspca_dev
*gspca_dev
, __s32 val
)
707 struct sd
*sd
= (struct sd
*) gspca_dev
;
708 s32
*sensor_settings
= sd
->sensor_priv
;
710 PDEBUG(D_V4L2
, "Set horizontal flip to %d", val
);
712 sensor_settings
[HFLIP_IDX
] = val
;
714 if (!dmi_check_system(ov9650_flip_dmi_table
))
715 i2c_data
= ((val
& 0x01) << 5) |
716 (sensor_settings
[VFLIP_IDX
] << 4);
718 i2c_data
= ((val
& 0x01) << 5) |
719 (!sensor_settings
[VFLIP_IDX
] << 4);
721 err
= m5602_write_sensor(sd
, OV9650_MVFP
, &i2c_data
, 1);
726 static int ov9650_get_vflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
728 struct sd
*sd
= (struct sd
*) gspca_dev
;
729 s32
*sensor_settings
= sd
->sensor_priv
;
731 *val
= sensor_settings
[VFLIP_IDX
];
732 PDEBUG(D_V4L2
, "Read vertical flip %d", *val
);
737 static int ov9650_set_vflip(struct gspca_dev
*gspca_dev
, __s32 val
)
741 struct sd
*sd
= (struct sd
*) gspca_dev
;
742 s32
*sensor_settings
= sd
->sensor_priv
;
744 PDEBUG(D_V4L2
, "Set vertical flip to %d", val
);
745 sensor_settings
[VFLIP_IDX
] = val
;
747 if (dmi_check_system(ov9650_flip_dmi_table
))
750 i2c_data
= ((val
& 0x01) << 4) | (sensor_settings
[VFLIP_IDX
] << 5);
751 err
= m5602_write_sensor(sd
, OV9650_MVFP
, &i2c_data
, 1);
755 /* When vflip is toggled we need to readjust the bridge hsync/vsync */
756 if (gspca_dev
->streaming
)
757 err
= ov9650_start(sd
);
762 static int ov9650_get_auto_exposure(struct gspca_dev
*gspca_dev
, __s32
*val
)
764 struct sd
*sd
= (struct sd
*) gspca_dev
;
765 s32
*sensor_settings
= sd
->sensor_priv
;
767 *val
= sensor_settings
[AUTO_EXPOSURE_IDX
];
768 PDEBUG(D_V4L2
, "Read auto exposure control %d", *val
);
772 static int ov9650_set_auto_exposure(struct gspca_dev
*gspca_dev
,
777 struct sd
*sd
= (struct sd
*) gspca_dev
;
778 s32
*sensor_settings
= sd
->sensor_priv
;
780 PDEBUG(D_V4L2
, "Set auto exposure control to %d", val
);
782 sensor_settings
[AUTO_EXPOSURE_IDX
] = val
;
783 err
= m5602_read_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
787 i2c_data
= ((i2c_data
& 0xfe) | ((val
& 0x01) << 0));
789 return m5602_write_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
792 static int ov9650_get_auto_white_balance(struct gspca_dev
*gspca_dev
,
795 struct sd
*sd
= (struct sd
*) gspca_dev
;
796 s32
*sensor_settings
= sd
->sensor_priv
;
798 *val
= sensor_settings
[AUTO_WHITE_BALANCE_IDX
];
802 static int ov9650_set_auto_white_balance(struct gspca_dev
*gspca_dev
,
807 struct sd
*sd
= (struct sd
*) gspca_dev
;
808 s32
*sensor_settings
= sd
->sensor_priv
;
810 PDEBUG(D_V4L2
, "Set auto white balance to %d", val
);
812 sensor_settings
[AUTO_WHITE_BALANCE_IDX
] = val
;
813 err
= m5602_read_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
817 i2c_data
= ((i2c_data
& 0xfd) | ((val
& 0x01) << 1));
818 err
= m5602_write_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
823 static int ov9650_get_auto_gain(struct gspca_dev
*gspca_dev
, __s32
*val
)
825 struct sd
*sd
= (struct sd
*) gspca_dev
;
826 s32
*sensor_settings
= sd
->sensor_priv
;
828 *val
= sensor_settings
[AUTO_GAIN_CTRL_IDX
];
829 PDEBUG(D_V4L2
, "Read auto gain control %d", *val
);
833 static int ov9650_set_auto_gain(struct gspca_dev
*gspca_dev
, __s32 val
)
837 struct sd
*sd
= (struct sd
*) gspca_dev
;
838 s32
*sensor_settings
= sd
->sensor_priv
;
840 PDEBUG(D_V4L2
, "Set auto gain control to %d", val
);
842 sensor_settings
[AUTO_GAIN_CTRL_IDX
] = val
;
843 err
= m5602_read_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
847 i2c_data
= ((i2c_data
& 0xfb) | ((val
& 0x01) << 2));
849 return m5602_write_sensor(sd
, OV9650_COM8
, &i2c_data
, 1);
852 static void ov9650_dump_registers(struct sd
*sd
)
855 pr_info("Dumping the ov9650 register state\n");
856 for (address
= 0; address
< 0xa9; address
++) {
858 m5602_read_sensor(sd
, address
, &value
, 1);
859 pr_info("register 0x%x contains 0x%x\n", address
, value
);
862 pr_info("ov9650 register state dump complete\n");
864 pr_info("Probing for which registers that are read/write\n");
865 for (address
= 0; address
< 0xff; address
++) {
866 u8 old_value
, ctrl_value
;
867 u8 test_value
[2] = {0xff, 0xff};
869 m5602_read_sensor(sd
, address
, &old_value
, 1);
870 m5602_write_sensor(sd
, address
, test_value
, 1);
871 m5602_read_sensor(sd
, address
, &ctrl_value
, 1);
873 if (ctrl_value
== test_value
[0])
874 pr_info("register 0x%x is writeable\n", address
);
876 pr_info("register 0x%x is read only\n", address
);
878 /* Restore original value */
879 m5602_write_sensor(sd
, address
, &old_value
, 1);