2 * ov534-ov9xxx gspca driver
4 * Copyright (C) 2009-2011 Jean-Francois Moine http://moinejf.free.fr
5 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
6 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
8 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
9 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
10 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #define MODULE_NAME "ov534_9"
33 #define OV534_REG_ADDRESS 0xf1 /* sensor address */
34 #define OV534_REG_SUBADDR 0xf2
35 #define OV534_REG_WRITE 0xf3
36 #define OV534_REG_READ 0xf4
37 #define OV534_REG_OPERATION 0xf5
38 #define OV534_REG_STATUS 0xf6
40 #define OV534_OP_WRITE_3 0x37
41 #define OV534_OP_WRITE_2 0x33
42 #define OV534_OP_READ_2 0xf9
44 #define CTRL_TIMEOUT 500
46 MODULE_AUTHOR("Jean-Francois Moine <moinejf@free.fr>");
47 MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver");
48 MODULE_LICENSE("GPL");
50 /* specific webcam descriptor */
52 struct gspca_dev gspca_dev
; /* !! must be the first item */
59 SENSOR_OV965x
, /* ov9657 */
60 SENSOR_OV971x
, /* ov9712 */
61 SENSOR_OV562x
, /* ov5621 */
65 static const struct v4l2_pix_format ov965x_mode
[] = {
67 {320, 240, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
69 .sizeimage
= 320 * 240 * 3 / 8 + 590,
70 .colorspace
= V4L2_COLORSPACE_JPEG
},
72 {640, 480, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
74 .sizeimage
= 640 * 480 * 3 / 8 + 590,
75 .colorspace
= V4L2_COLORSPACE_JPEG
},
77 {800, 600, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
79 .sizeimage
= 800 * 600 * 3 / 8 + 590,
80 .colorspace
= V4L2_COLORSPACE_JPEG
},
82 {1024, 768, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
84 .sizeimage
= 1024 * 768 * 3 / 8 + 590,
85 .colorspace
= V4L2_COLORSPACE_JPEG
},
87 {1280, 1024, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
89 .sizeimage
= 1280 * 1024 * 3 / 8 + 590,
90 .colorspace
= V4L2_COLORSPACE_JPEG
},
93 static const struct v4l2_pix_format ov971x_mode
[] = {
94 {640, 480, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
96 .sizeimage
= 640 * 480,
97 .colorspace
= V4L2_COLORSPACE_SRGB
101 static const struct v4l2_pix_format ov562x_mode
[] = {
102 {2592, 1680, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
103 .bytesperline
= 2592,
104 .sizeimage
= 2592 * 1680,
105 .colorspace
= V4L2_COLORSPACE_SRGB
109 static const u8 bridge_init
[][2] = {
143 static const u8 ov965x_init
[][2] = {
144 {0x12, 0x80}, /* com7 - SSCB reset */
145 {0x00, 0x00}, /* gain */
146 {0x01, 0x80}, /* blue */
147 {0x02, 0x80}, /* red */
148 {0x03, 0x1b}, /* vref */
149 {0x04, 0x03}, /* com1 - exposure low bits */
150 {0x0b, 0x57}, /* ver */
151 {0x0e, 0x61}, /* com5 */
152 {0x0f, 0x42}, /* com6 */
153 {0x11, 0x00}, /* clkrc */
154 {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
155 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
156 {0x14, 0x28}, /* com9 */
157 {0x16, 0x24}, /* reg16 */
158 {0x17, 0x1d}, /* hstart*/
159 {0x18, 0xbd}, /* hstop */
160 {0x19, 0x01}, /* vstrt */
161 {0x1a, 0x81}, /* vstop*/
162 {0x1e, 0x04}, /* mvfp */
163 {0x24, 0x3c}, /* aew */
164 {0x25, 0x36}, /* aeb */
165 {0x26, 0x71}, /* vpt */
166 {0x27, 0x08}, /* bbias */
167 {0x28, 0x08}, /* gbbias */
168 {0x29, 0x15}, /* gr com */
169 {0x2a, 0x00}, /* exhch */
170 {0x2b, 0x00}, /* exhcl */
171 {0x2c, 0x08}, /* rbias */
172 {0x32, 0xff}, /* href */
173 {0x33, 0x00}, /* chlf */
174 {0x34, 0x3f}, /* aref1 */
175 {0x35, 0x00}, /* aref2 */
176 {0x36, 0xf8}, /* aref3 */
177 {0x38, 0x72}, /* adc2 */
178 {0x39, 0x57}, /* aref4 */
179 {0x3a, 0x80}, /* tslb - yuyv */
180 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
181 {0x3d, 0x99}, /* com13 */
182 {0x3f, 0xc1}, /* edge */
183 {0x40, 0xc0}, /* com15 */
184 {0x41, 0x40}, /* com16 */
185 {0x42, 0xc0}, /* com17 */
186 {0x43, 0x0a}, /* rsvd */
197 {0x4f, 0x98}, /* matrix */
203 {0x58, 0x1a}, /* matrix coef sign */
204 {0x59, 0x85}, /* AWB control */
210 {0x5f, 0xf0}, /* AWB blue limit */
211 {0x60, 0xf0}, /* AWB red limit */
212 {0x61, 0xf0}, /* AWB green limit */
213 {0x62, 0x00}, /* lcc1 */
214 {0x63, 0x00}, /* lcc2 */
215 {0x64, 0x02}, /* lcc3 */
216 {0x65, 0x16}, /* lcc4 */
217 {0x66, 0x01}, /* lcc5 */
218 {0x69, 0x02}, /* hv */
219 {0x6b, 0x5a}, /* dbvl */
224 {0x70, 0x21}, /* dnsth */
226 {0x72, 0x00}, /* poidx */
227 {0x73, 0x01}, /* pckdv */
228 {0x74, 0x3a}, /* xindx */
229 {0x75, 0x35}, /* yindx */
232 {0x7a, 0x12}, /* gamma curve */
249 {0x8c, 0x89}, /* com19 */
250 {0x14, 0x28}, /* com9 */
253 {0x9d, 0x03}, /* lcc6 */
254 {0x9e, 0x04}, /* lcc7 */
257 {0xa1, 0x40}, /* aechm */
258 {0xa4, 0x50}, /* com21 */
259 {0xa5, 0x68}, /* com26 */
260 {0xa6, 0x4a}, /* AWB green */
261 {0xa8, 0xc1}, /* refa8 */
262 {0xa9, 0xef}, /* refa9 */
265 {0xac, 0x80}, /* black level control */
271 {0xb4, 0x20}, /* ctrlb4 */
275 {0xbc, 0x7f}, /* ADC channel offsets */
284 {0xc7, 0x80}, /* com24 */
290 {0x4f, 0x98}, /* matrix */
297 {0xff, 0x41}, /* read 41, write ff 00 */
298 {0x41, 0x40}, /* com16 */
300 {0xc5, 0x03}, /* 60 Hz banding filter */
301 {0x6a, 0x02}, /* 50 Hz banding filter */
303 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
304 {0x36, 0xfa}, /* aref3 */
305 {0x69, 0x0a}, /* hv */
306 {0x8c, 0x89}, /* com22 */
307 {0x14, 0x28}, /* com9 */
309 {0x41, 0x40}, /* com16 */
316 {0x03, 0x12}, /* vref */
317 {0x17, 0x16}, /* hstart */
318 {0x18, 0x02}, /* hstop */
319 {0x19, 0x01}, /* vstrt */
320 {0x1a, 0x3d}, /* vstop */
321 {0x32, 0xff}, /* href */
325 static const u8 bridge_init_2
[][2] = {
353 static const u8 ov965x_init_2
[][2] = {
355 {0x1e, 0x04}, /* mvfp */
356 {0x13, 0xe0}, /* com8 */
357 {0x00, 0x00}, /* gain */
358 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
359 {0x11, 0x03}, /* clkrc */
360 {0x6b, 0x5a}, /* dblv */
366 {0xff, 0x42}, /* read 42, write ff 00 */
367 {0x42, 0xc0}, /* com17 */
369 {0xff, 0x42}, /* read 42, write ff 00 */
370 {0x42, 0xc1}, /* com17 */
373 {0xff, 0x42}, /* read 42, write ff 00 */
374 {0x42, 0xc1}, /* com17 */
376 {0x4f, 0x98}, /* matrix */
383 {0xff, 0x41}, /* read 41, write ff 00 */
384 {0x41, 0x40}, /* com16 */
390 {0x10, 0x25}, /* aech - exposure high bits */
391 {0xff, 0x13}, /* read 13, write ff 00 */
392 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
395 static const u8 ov971x_init
[][2] = {
419 {0x98, 0x40}, /*{0x98, 0x00},*/
420 {0x99, 0xA0}, /*{0x99, 0x00},*/
421 {0x9a, 0x01}, /*{0x9a, 0x00},*/
423 {0x58, 0x78}, /*{0x58, 0xc8},*/
424 {0x59, 0x50}, /*{0x59, 0xa0},*/
429 {0xbd, 0x50}, /*{0xbd, 0xa0},*/
430 {0xbe, 0x78}, /*{0xbe, 0xc8},*/
453 static const u8 ov965x_start_1_vga
[][2] = { /* same for qvga */
454 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
455 {0x36, 0xfa}, /* aref3 */
456 {0x69, 0x0a}, /* hv */
457 {0x8c, 0x89}, /* com22 */
458 {0x14, 0x28}, /* com9 */
459 {0x3e, 0x0c}, /* com14 */
460 {0x41, 0x40}, /* com16 */
466 {0xc7, 0x80}, /* com24 */
467 {0x03, 0x12}, /* vref */
468 {0x17, 0x16}, /* hstart */
469 {0x18, 0x02}, /* hstop */
470 {0x19, 0x01}, /* vstrt */
471 {0x1a, 0x3d}, /* vstop */
472 {0x32, 0xff}, /* href */
476 static const u8 ov965x_start_1_svga
[][2] = {
477 {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
478 {0x36, 0xf8}, /* aref3 */
479 {0x69, 0x02}, /* hv */
480 {0x8c, 0x0d}, /* com22 */
481 {0x3e, 0x0c}, /* com14 */
482 {0x41, 0x40}, /* com16 */
488 {0xc7, 0x80}, /* com24 */
489 {0x03, 0x1b}, /* vref */
490 {0x17, 0x1d}, /* hstart */
491 {0x18, 0xbd}, /* hstop */
492 {0x19, 0x01}, /* vstrt */
493 {0x1a, 0x81}, /* vstop */
494 {0x32, 0xff}, /* href */
498 static const u8 ov965x_start_1_xga
[][2] = {
499 {0x12, 0x02}, /* com7 */
500 {0x36, 0xf8}, /* aref3 */
501 {0x69, 0x02}, /* hv */
502 {0x8c, 0x89}, /* com22 */
503 {0x14, 0x28}, /* com9 */
504 {0x3e, 0x0c}, /* com14 */
505 {0x41, 0x40}, /* com16 */
511 {0xc7, 0x80}, /* com24 */
512 {0x03, 0x1b}, /* vref */
513 {0x17, 0x1d}, /* hstart */
514 {0x18, 0xbd}, /* hstop */
515 {0x19, 0x01}, /* vstrt */
516 {0x1a, 0x81}, /* vstop */
517 {0x32, 0xff}, /* href */
521 static const u8 ov965x_start_1_sxga
[][2] = {
522 {0x12, 0x02}, /* com7 */
523 {0x36, 0xf8}, /* aref3 */
524 {0x69, 0x02}, /* hv */
525 {0x8c, 0x89}, /* com22 */
526 {0x14, 0x28}, /* com9 */
527 {0x3e, 0x0c}, /* com14 */
528 {0x41, 0x40}, /* com16 */
534 {0xc7, 0x80}, /* com24 */
535 {0x03, 0x1b}, /* vref */
536 {0x17, 0x1d}, /* hstart */
537 {0x18, 0x02}, /* hstop */
538 {0x19, 0x01}, /* vstrt */
539 {0x1a, 0x81}, /* vstop */
540 {0x32, 0xff}, /* href */
544 static const u8 bridge_start_qvga
[][2] = {
572 static const u8 bridge_start_vga
[][2] = {
599 static const u8 bridge_start_svga
[][2] = {
626 static const u8 bridge_start_xga
[][2] = {
653 static const u8 bridge_start_sxga
[][2] = {
670 static const u8 ov965x_start_2_qvga
[][2] = {
671 {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
672 {0x1e, 0x04}, /* mvfp */
673 {0x13, 0xe0}, /* com8 */
675 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
676 {0x11, 0x01}, /* clkrc */
677 {0x6b, 0x5a}, /* dblv */
678 {0x6a, 0x02}, /* 50 Hz banding filter */
679 {0xc5, 0x03}, /* 60 Hz banding filter */
680 {0xa2, 0x96}, /* bd50 */
681 {0xa3, 0x7d}, /* bd60 */
683 {0xff, 0x13}, /* read 13, write ff 00 */
685 {0x3a, 0x80}, /* tslb - yuyv */
688 static const u8 ov965x_start_2_vga
[][2] = {
689 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
690 {0x1e, 0x04}, /* mvfp */
691 {0x13, 0xe0}, /* com8 */
693 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
694 {0x11, 0x03}, /* clkrc */
695 {0x6b, 0x5a}, /* dblv */
696 {0x6a, 0x05}, /* 50 Hz banding filter */
697 {0xc5, 0x07}, /* 60 Hz banding filter */
698 {0xa2, 0x4b}, /* bd50 */
699 {0xa3, 0x3e}, /* bd60 */
701 {0x2d, 0x00}, /* advfl */
704 static const u8 ov965x_start_2_svga
[][2] = { /* same for xga */
705 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
706 {0x1e, 0x04}, /* mvfp */
707 {0x13, 0xe0}, /* com8 */
709 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
710 {0x11, 0x01}, /* clkrc */
711 {0x6b, 0x5a}, /* dblv */
712 {0x6a, 0x0c}, /* 50 Hz banding filter */
713 {0xc5, 0x0f}, /* 60 Hz banding filter */
714 {0xa2, 0x4e}, /* bd50 */
715 {0xa3, 0x41}, /* bd60 */
718 static const u8 ov965x_start_2_sxga
[][2] = {
719 {0x13, 0xe0}, /* com8 */
721 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
722 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
723 {0x1e, 0x04}, /* mvfp */
724 {0x11, 0x01}, /* clkrc */
725 {0x6b, 0x5a}, /* dblv */
726 {0x6a, 0x0c}, /* 50 Hz banding filter */
727 {0xc5, 0x0f}, /* 60 Hz banding filter */
728 {0xa2, 0x4e}, /* bd50 */
729 {0xa3, 0x41}, /* bd60 */
732 static const u8 ov562x_init
[][2] = {
748 static const u8 ov562x_init_2
[][2] = {
850 static void reg_w_i(struct gspca_dev
*gspca_dev
, u16 reg
, u8 val
)
852 struct usb_device
*udev
= gspca_dev
->dev
;
855 if (gspca_dev
->usb_err
< 0)
857 gspca_dev
->usb_buf
[0] = val
;
858 ret
= usb_control_msg(udev
,
859 usb_sndctrlpipe(udev
, 0),
861 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
862 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
864 pr_err("reg_w failed %d\n", ret
);
865 gspca_dev
->usb_err
= ret
;
869 static void reg_w(struct gspca_dev
*gspca_dev
, u16 reg
, u8 val
)
871 PDEBUG(D_USBO
, "reg_w [%04x] = %02x", reg
, val
);
872 reg_w_i(gspca_dev
, reg
, val
);
875 static u8
reg_r(struct gspca_dev
*gspca_dev
, u16 reg
)
877 struct usb_device
*udev
= gspca_dev
->dev
;
880 if (gspca_dev
->usb_err
< 0)
882 ret
= usb_control_msg(udev
,
883 usb_rcvctrlpipe(udev
, 0),
885 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
886 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
887 PDEBUG(D_USBI
, "reg_r [%04x] -> %02x", reg
, gspca_dev
->usb_buf
[0]);
889 pr_err("reg_r err %d\n", ret
);
890 gspca_dev
->usb_err
= ret
;
892 return gspca_dev
->usb_buf
[0];
895 static int sccb_check_status(struct gspca_dev
*gspca_dev
)
900 for (i
= 0; i
< 5; i
++) {
902 data
= reg_r(gspca_dev
, OV534_REG_STATUS
);
912 PDEBUG(D_USBI
|D_USBO
,
913 "sccb status 0x%02x, attempt %d/5",
920 static void sccb_write(struct gspca_dev
*gspca_dev
, u8 reg
, u8 val
)
922 PDEBUG(D_USBO
, "sccb_write [%02x] = %02x", reg
, val
);
923 reg_w_i(gspca_dev
, OV534_REG_SUBADDR
, reg
);
924 reg_w_i(gspca_dev
, OV534_REG_WRITE
, val
);
925 reg_w_i(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_3
);
927 if (!sccb_check_status(gspca_dev
))
928 pr_err("sccb_write failed\n");
931 static u8
sccb_read(struct gspca_dev
*gspca_dev
, u16 reg
)
933 reg_w(gspca_dev
, OV534_REG_SUBADDR
, reg
);
934 reg_w(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_2
);
935 if (!sccb_check_status(gspca_dev
))
936 pr_err("sccb_read failed 1\n");
938 reg_w(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_READ_2
);
939 if (!sccb_check_status(gspca_dev
))
940 pr_err("sccb_read failed 2\n");
942 return reg_r(gspca_dev
, OV534_REG_READ
);
945 /* output a bridge sequence (reg - val) */
946 static void reg_w_array(struct gspca_dev
*gspca_dev
,
947 const u8 (*data
)[2], int len
)
950 reg_w(gspca_dev
, (*data
)[0], (*data
)[1]);
955 /* output a sensor sequence (reg - val) */
956 static void sccb_w_array(struct gspca_dev
*gspca_dev
,
957 const u8 (*data
)[2], int len
)
960 if ((*data
)[0] != 0xff) {
961 sccb_write(gspca_dev
, (*data
)[0], (*data
)[1]);
963 sccb_read(gspca_dev
, (*data
)[1]);
964 sccb_write(gspca_dev
, 0xff, 0x00);
970 /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
971 * (direction and output)? */
972 static void set_led(struct gspca_dev
*gspca_dev
, int status
)
976 PDEBUG(D_CONF
, "led status: %d", status
);
978 data
= reg_r(gspca_dev
, 0x21);
980 reg_w(gspca_dev
, 0x21, data
);
982 data
= reg_r(gspca_dev
, 0x23);
988 reg_w(gspca_dev
, 0x23, data
);
991 data
= reg_r(gspca_dev
, 0x21);
993 reg_w(gspca_dev
, 0x21, data
);
997 static void setbrightness(struct gspca_dev
*gspca_dev
, s32 brightness
)
999 struct sd
*sd
= (struct sd
*) gspca_dev
;
1003 if (sd
->sensor
== SENSOR_OV562x
) {
1007 sccb_write(gspca_dev
, 0x24, val
);
1010 sccb_write(gspca_dev
, 0x25, val
);
1017 sccb_write(gspca_dev
, 0x26, val
);
1021 val
= 15 - val
; /* f .. 8 */
1023 val
= val
- 8; /* 0 .. 7 */
1024 sccb_write(gspca_dev
, 0x55, /* brtn - brightness adjustment */
1029 static void setcontrast(struct gspca_dev
*gspca_dev
, s32 val
)
1031 sccb_write(gspca_dev
, 0x56, /* cnst1 - contrast 1 ctrl coeff */
1035 static void setautogain(struct gspca_dev
*gspca_dev
, s32 autogain
)
1039 /*fixme: should adjust agc/awb/aec by different controls */
1040 val
= sccb_read(gspca_dev
, 0x13); /* com8 */
1041 sccb_write(gspca_dev
, 0xff, 0x00);
1043 val
|= 0x05; /* agc & aec */
1046 sccb_write(gspca_dev
, 0x13, val
);
1049 static void setexposure(struct gspca_dev
*gspca_dev
, s32 exposure
)
1051 static const u8 expo
[4] = {0x00, 0x25, 0x38, 0x5e};
1054 sccb_write(gspca_dev
, 0x10, expo
[exposure
]); /* aec[9:2] */
1056 val
= sccb_read(gspca_dev
, 0x13); /* com8 */
1057 sccb_write(gspca_dev
, 0xff, 0x00);
1058 sccb_write(gspca_dev
, 0x13, val
);
1060 val
= sccb_read(gspca_dev
, 0xa1); /* aech */
1061 sccb_write(gspca_dev
, 0xff, 0x00);
1062 sccb_write(gspca_dev
, 0xa1, val
& 0xe0); /* aec[15:10] = 0 */
1065 static void setsharpness(struct gspca_dev
*gspca_dev
, s32 val
)
1067 if (val
< 0) { /* auto */
1068 val
= sccb_read(gspca_dev
, 0x42); /* com17 */
1069 sccb_write(gspca_dev
, 0xff, 0x00);
1070 sccb_write(gspca_dev
, 0x42, val
| 0x40);
1071 /* Edge enhancement strength auto adjust */
1075 val
= 1 << (val
- 1);
1076 sccb_write(gspca_dev
, 0x3f, /* edge - edge enhance. factor */
1078 val
= sccb_read(gspca_dev
, 0x42); /* com17 */
1079 sccb_write(gspca_dev
, 0xff, 0x00);
1080 sccb_write(gspca_dev
, 0x42, val
& 0xbf);
1083 static void setsatur(struct gspca_dev
*gspca_dev
, s32 val
)
1085 u8 val1
, val2
, val3
;
1086 static const u8 matrix
[5][2] = {
1094 val1
= matrix
[val
][0];
1095 val2
= matrix
[val
][1];
1097 sccb_write(gspca_dev
, 0x4f, val3
); /* matrix coeff */
1098 sccb_write(gspca_dev
, 0x50, val3
);
1099 sccb_write(gspca_dev
, 0x51, 0x00);
1100 sccb_write(gspca_dev
, 0x52, val1
);
1101 sccb_write(gspca_dev
, 0x53, val2
);
1102 sccb_write(gspca_dev
, 0x54, val3
);
1103 sccb_write(gspca_dev
, 0x58, 0x1a); /* mtxs - coeff signs */
1105 val1
= sccb_read(gspca_dev
, 0x41); /* com16 */
1106 sccb_write(gspca_dev
, 0xff, 0x00);
1107 sccb_write(gspca_dev
, 0x41, val1
);
1110 static void setlightfreq(struct gspca_dev
*gspca_dev
, s32 freq
)
1114 val
= sccb_read(gspca_dev
, 0x13); /* com8 */
1115 sccb_write(gspca_dev
, 0xff, 0x00);
1117 sccb_write(gspca_dev
, 0x13, val
& 0xdf);
1120 sccb_write(gspca_dev
, 0x13, val
| 0x20);
1122 val
= sccb_read(gspca_dev
, 0x42); /* com17 */
1123 sccb_write(gspca_dev
, 0xff, 0x00);
1128 sccb_write(gspca_dev
, 0x42, val
);
1131 /* this function is called at probe time */
1132 static int sd_config(struct gspca_dev
*gspca_dev
,
1133 const struct usb_device_id
*id
)
1138 /* this function is called at probe and resume time */
1139 static int sd_init(struct gspca_dev
*gspca_dev
)
1141 struct sd
*sd
= (struct sd
*) gspca_dev
;
1145 reg_w(gspca_dev
, 0xe7, 0x3a);
1146 reg_w(gspca_dev
, 0xe0, 0x08);
1149 /* initialize the sensor address */
1150 reg_w(gspca_dev
, OV534_REG_ADDRESS
, 0x60);
1153 sccb_write(gspca_dev
, 0x12, 0x80);
1156 /* probe the sensor */
1157 sccb_read(gspca_dev
, 0x0a);
1158 sensor_id
= sccb_read(gspca_dev
, 0x0a) << 8;
1159 sccb_read(gspca_dev
, 0x0b);
1160 sensor_id
|= sccb_read(gspca_dev
, 0x0b);
1161 PDEBUG(D_PROBE
, "Sensor ID: %04x", sensor_id
);
1164 if ((sensor_id
& 0xfff0) == 0x9650) {
1165 sd
->sensor
= SENSOR_OV965x
;
1167 gspca_dev
->cam
.cam_mode
= ov965x_mode
;
1168 gspca_dev
->cam
.nmodes
= ARRAY_SIZE(ov965x_mode
);
1170 reg_w_array(gspca_dev
, bridge_init
,
1171 ARRAY_SIZE(bridge_init
));
1172 sccb_w_array(gspca_dev
, ov965x_init
,
1173 ARRAY_SIZE(ov965x_init
));
1174 reg_w_array(gspca_dev
, bridge_init_2
,
1175 ARRAY_SIZE(bridge_init_2
));
1176 sccb_w_array(gspca_dev
, ov965x_init_2
,
1177 ARRAY_SIZE(ov965x_init_2
));
1178 reg_w(gspca_dev
, 0xe0, 0x00);
1179 reg_w(gspca_dev
, 0xe0, 0x01);
1180 set_led(gspca_dev
, 0);
1181 reg_w(gspca_dev
, 0xe0, 0x00);
1182 } else if ((sensor_id
& 0xfff0) == 0x9710) {
1186 sd
->sensor
= SENSOR_OV971x
;
1188 gspca_dev
->cam
.cam_mode
= ov971x_mode
;
1189 gspca_dev
->cam
.nmodes
= ARRAY_SIZE(ov971x_mode
);
1191 gspca_dev
->cam
.bulk
= 1;
1192 gspca_dev
->cam
.bulk_size
= 16384;
1193 gspca_dev
->cam
.bulk_nurbs
= 2;
1195 sccb_w_array(gspca_dev
, ov971x_init
,
1196 ARRAY_SIZE(ov971x_init
));
1198 /* set video format on bridge processor */
1199 /* access bridge processor's video format registers at: 0x00 */
1200 reg_w(gspca_dev
, 0x1c, 0x00);
1201 /*set register: 0x00 is 'RAW8', 0x40 is 'YUV422' (YUYV?)*/
1202 reg_w(gspca_dev
, 0x1d, 0x00);
1204 /* Will W. specific stuff
1206 * output (0x1f) if first webcam
1207 * input (0x17) if 2nd or 3rd webcam */
1208 p
= video_device_node_name(&gspca_dev
->vdev
);
1211 reg_w(gspca_dev
, 0x56, 0x1f);
1213 reg_w(gspca_dev
, 0x56, 0x17);
1214 } else if ((sensor_id
& 0xfff0) == 0x5620) {
1215 sd
->sensor
= SENSOR_OV562x
;
1216 gspca_dev
->cam
.cam_mode
= ov562x_mode
;
1217 gspca_dev
->cam
.nmodes
= ARRAY_SIZE(ov562x_mode
);
1219 reg_w_array(gspca_dev
, ov562x_init
,
1220 ARRAY_SIZE(ov562x_init
));
1221 sccb_w_array(gspca_dev
, ov562x_init_2
,
1222 ARRAY_SIZE(ov562x_init_2
));
1223 reg_w(gspca_dev
, 0xe0, 0x00);
1225 pr_err("Unknown sensor %04x", sensor_id
);
1229 return gspca_dev
->usb_err
;
1232 static int sd_start(struct gspca_dev
*gspca_dev
)
1234 struct sd
*sd
= (struct sd
*) gspca_dev
;
1236 if (sd
->sensor
== SENSOR_OV971x
)
1237 return gspca_dev
->usb_err
;
1238 if (sd
->sensor
== SENSOR_OV562x
)
1239 return gspca_dev
->usb_err
;
1241 switch (gspca_dev
->curr_mode
) {
1242 case QVGA_MODE
: /* 320x240 */
1243 sccb_w_array(gspca_dev
, ov965x_start_1_vga
,
1244 ARRAY_SIZE(ov965x_start_1_vga
));
1245 reg_w_array(gspca_dev
, bridge_start_qvga
,
1246 ARRAY_SIZE(bridge_start_qvga
));
1247 sccb_w_array(gspca_dev
, ov965x_start_2_qvga
,
1248 ARRAY_SIZE(ov965x_start_2_qvga
));
1250 case VGA_MODE
: /* 640x480 */
1251 sccb_w_array(gspca_dev
, ov965x_start_1_vga
,
1252 ARRAY_SIZE(ov965x_start_1_vga
));
1253 reg_w_array(gspca_dev
, bridge_start_vga
,
1254 ARRAY_SIZE(bridge_start_vga
));
1255 sccb_w_array(gspca_dev
, ov965x_start_2_vga
,
1256 ARRAY_SIZE(ov965x_start_2_vga
));
1258 case SVGA_MODE
: /* 800x600 */
1259 sccb_w_array(gspca_dev
, ov965x_start_1_svga
,
1260 ARRAY_SIZE(ov965x_start_1_svga
));
1261 reg_w_array(gspca_dev
, bridge_start_svga
,
1262 ARRAY_SIZE(bridge_start_svga
));
1263 sccb_w_array(gspca_dev
, ov965x_start_2_svga
,
1264 ARRAY_SIZE(ov965x_start_2_svga
));
1266 case XGA_MODE
: /* 1024x768 */
1267 sccb_w_array(gspca_dev
, ov965x_start_1_xga
,
1268 ARRAY_SIZE(ov965x_start_1_xga
));
1269 reg_w_array(gspca_dev
, bridge_start_xga
,
1270 ARRAY_SIZE(bridge_start_xga
));
1271 sccb_w_array(gspca_dev
, ov965x_start_2_svga
,
1272 ARRAY_SIZE(ov965x_start_2_svga
));
1275 /* case SXGA_MODE: * 1280x1024 */
1276 sccb_w_array(gspca_dev
, ov965x_start_1_sxga
,
1277 ARRAY_SIZE(ov965x_start_1_sxga
));
1278 reg_w_array(gspca_dev
, bridge_start_sxga
,
1279 ARRAY_SIZE(bridge_start_sxga
));
1280 sccb_w_array(gspca_dev
, ov965x_start_2_sxga
,
1281 ARRAY_SIZE(ov965x_start_2_sxga
));
1285 reg_w(gspca_dev
, 0xe0, 0x00);
1286 reg_w(gspca_dev
, 0xe0, 0x00);
1287 set_led(gspca_dev
, 1);
1288 return gspca_dev
->usb_err
;
1291 static void sd_stopN(struct gspca_dev
*gspca_dev
)
1293 reg_w(gspca_dev
, 0xe0, 0x01);
1294 set_led(gspca_dev
, 0);
1295 reg_w(gspca_dev
, 0xe0, 0x00);
1298 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
1299 #define UVC_STREAM_EOH (1 << 7)
1300 #define UVC_STREAM_ERR (1 << 6)
1301 #define UVC_STREAM_STI (1 << 5)
1302 #define UVC_STREAM_RES (1 << 4)
1303 #define UVC_STREAM_SCR (1 << 3)
1304 #define UVC_STREAM_PTS (1 << 2)
1305 #define UVC_STREAM_EOF (1 << 1)
1306 #define UVC_STREAM_FID (1 << 0)
1308 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
1311 struct sd
*sd
= (struct sd
*) gspca_dev
;
1314 int remaining_len
= len
;
1317 payload_len
= gspca_dev
->cam
.bulk
? 2048 : 2040;
1319 len
= min(remaining_len
, payload_len
);
1321 /* Payloads are prefixed with a UVC-style header. We
1322 consider a frame to start when the FID toggles, or the PTS
1323 changes. A frame ends when EOF is set, and we've received
1324 the correct number of bytes. */
1326 /* Verify UVC header. Header length is always 12 */
1327 if (data
[0] != 12 || len
< 12) {
1328 PDEBUG(D_PACK
, "bad header");
1333 if (data
[1] & UVC_STREAM_ERR
) {
1334 PDEBUG(D_PACK
, "payload error");
1338 /* Extract PTS and FID */
1339 if (!(data
[1] & UVC_STREAM_PTS
)) {
1340 PDEBUG(D_PACK
, "PTS not present");
1343 this_pts
= (data
[5] << 24) | (data
[4] << 16)
1344 | (data
[3] << 8) | data
[2];
1345 this_fid
= data
[1] & UVC_STREAM_FID
;
1347 /* If PTS or FID has changed, start a new frame. */
1348 if (this_pts
!= sd
->last_pts
|| this_fid
!= sd
->last_fid
) {
1349 if (gspca_dev
->last_packet_type
== INTER_PACKET
)
1350 gspca_frame_add(gspca_dev
, LAST_PACKET
,
1352 sd
->last_pts
= this_pts
;
1353 sd
->last_fid
= this_fid
;
1354 gspca_frame_add(gspca_dev
, FIRST_PACKET
,
1355 data
+ 12, len
- 12);
1356 /* If this packet is marked as EOF, end the frame */
1357 } else if (data
[1] & UVC_STREAM_EOF
) {
1359 gspca_frame_add(gspca_dev
, LAST_PACKET
,
1360 data
+ 12, len
- 12);
1363 /* Add the data from this payload */
1364 gspca_frame_add(gspca_dev
, INTER_PACKET
,
1365 data
+ 12, len
- 12);
1368 /* Done this payload */
1372 /* Discard data until a new frame starts. */
1373 gspca_dev
->last_packet_type
= DISCARD_PACKET
;
1376 remaining_len
-= len
;
1378 } while (remaining_len
> 0);
1381 static int sd_s_ctrl(struct v4l2_ctrl
*ctrl
)
1383 struct gspca_dev
*gspca_dev
=
1384 container_of(ctrl
->handler
, struct gspca_dev
, ctrl_handler
);
1386 gspca_dev
->usb_err
= 0;
1388 if (!gspca_dev
->streaming
)
1392 case V4L2_CID_BRIGHTNESS
:
1393 setbrightness(gspca_dev
, ctrl
->val
);
1395 case V4L2_CID_CONTRAST
:
1396 setcontrast(gspca_dev
, ctrl
->val
);
1398 case V4L2_CID_SATURATION
:
1399 setsatur(gspca_dev
, ctrl
->val
);
1401 case V4L2_CID_POWER_LINE_FREQUENCY
:
1402 setlightfreq(gspca_dev
, ctrl
->val
);
1404 case V4L2_CID_SHARPNESS
:
1405 setsharpness(gspca_dev
, ctrl
->val
);
1407 case V4L2_CID_AUTOGAIN
:
1409 setautogain(gspca_dev
, ctrl
->val
);
1410 if (!ctrl
->val
&& gspca_dev
->exposure
->is_new
)
1411 setexposure(gspca_dev
, gspca_dev
->exposure
->val
);
1414 return gspca_dev
->usb_err
;
1417 static const struct v4l2_ctrl_ops sd_ctrl_ops
= {
1418 .s_ctrl
= sd_s_ctrl
,
1421 static int sd_init_controls(struct gspca_dev
*gspca_dev
)
1423 struct sd
*sd
= (struct sd
*)gspca_dev
;
1424 struct v4l2_ctrl_handler
*hdl
= &gspca_dev
->ctrl_handler
;
1426 if (sd
->sensor
== SENSOR_OV971x
)
1428 gspca_dev
->vdev
.ctrl_handler
= hdl
;
1429 v4l2_ctrl_handler_init(hdl
, 7);
1430 if (sd
->sensor
== SENSOR_OV562x
) {
1431 v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
1432 V4L2_CID_BRIGHTNESS
, -90, 90, 1, 0);
1434 v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
1435 V4L2_CID_BRIGHTNESS
, 0, 15, 1, 7);
1436 v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
1437 V4L2_CID_CONTRAST
, 0, 15, 1, 3);
1438 v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
1439 V4L2_CID_SATURATION
, 0, 4, 1, 2);
1441 v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
1442 V4L2_CID_SHARPNESS
, -1, 4, 1, -1);
1443 gspca_dev
->autogain
= v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
1444 V4L2_CID_AUTOGAIN
, 0, 1, 1, 1);
1445 gspca_dev
->exposure
= v4l2_ctrl_new_std(hdl
, &sd_ctrl_ops
,
1446 V4L2_CID_EXPOSURE
, 0, 3, 1, 0);
1447 v4l2_ctrl_new_std_menu(hdl
, &sd_ctrl_ops
,
1448 V4L2_CID_POWER_LINE_FREQUENCY
,
1449 V4L2_CID_POWER_LINE_FREQUENCY_60HZ
, 0, 0);
1450 v4l2_ctrl_auto_cluster(3, &gspca_dev
->autogain
, 0, false);
1454 pr_err("Could not initialize controls\n");
1460 /* sub-driver description */
1461 static const struct sd_desc sd_desc
= {
1462 .name
= MODULE_NAME
,
1463 .config
= sd_config
,
1465 .init_controls
= sd_init_controls
,
1468 .pkt_scan
= sd_pkt_scan
,
1471 /* -- module initialisation -- */
1472 static const struct usb_device_id device_table
[] = {
1473 {USB_DEVICE(0x05a9, 0x8065)},
1474 {USB_DEVICE(0x06f8, 0x3003)},
1475 {USB_DEVICE(0x05a9, 0x1550)},
1479 MODULE_DEVICE_TABLE(usb
, device_table
);
1481 /* -- device connect -- */
1482 static int sd_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1484 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
1488 static struct usb_driver sd_driver
= {
1489 .name
= MODULE_NAME
,
1490 .id_table
= device_table
,
1492 .disconnect
= gspca_disconnect
,
1494 .suspend
= gspca_suspend
,
1495 .resume
= gspca_resume
,
1496 .reset_resume
= gspca_resume
,
1500 module_usb_driver(sd_driver
);