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");
59 NCTRLS
/* number of controls */
62 /* specific webcam descriptor */
64 struct gspca_dev gspca_dev
; /* !! must be the first item */
65 struct gspca_ctrl ctrls
[NCTRLS
];
72 SENSOR_OV965x
, /* ov9657 */
73 SENSOR_OV971x
, /* ov9712 */
74 SENSOR_OV562x
, /* ov5621 */
78 /* V4L2 controls supported by the driver */
79 static void setbrightness(struct gspca_dev
*gspca_dev
);
80 static void setcontrast(struct gspca_dev
*gspca_dev
);
81 static void setautogain(struct gspca_dev
*gspca_dev
);
82 static void setexposure(struct gspca_dev
*gspca_dev
);
83 static void setsharpness(struct gspca_dev
*gspca_dev
);
84 static void setsatur(struct gspca_dev
*gspca_dev
);
85 static void setlightfreq(struct gspca_dev
*gspca_dev
);
87 static const struct ctrl sd_ctrls
[NCTRLS
] = {
90 .id
= V4L2_CID_BRIGHTNESS
,
91 .type
= V4L2_CTRL_TYPE_INTEGER
,
98 .set_control
= setbrightness
102 .id
= V4L2_CID_CONTRAST
,
103 .type
= V4L2_CTRL_TYPE_INTEGER
,
110 .set_control
= setcontrast
114 .id
= V4L2_CID_AUTOGAIN
,
115 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
120 #define AUTOGAIN_DEF 1
121 .default_value
= AUTOGAIN_DEF
,
123 .set_control
= setautogain
127 .id
= V4L2_CID_EXPOSURE
,
128 .type
= V4L2_CTRL_TYPE_INTEGER
,
135 .set_control
= setexposure
139 .id
= V4L2_CID_SHARPNESS
,
140 .type
= V4L2_CTRL_TYPE_INTEGER
,
142 .minimum
= -1, /* -1 = auto */
147 .set_control
= setsharpness
151 .id
= V4L2_CID_SATURATION
,
152 .type
= V4L2_CTRL_TYPE_INTEGER
,
153 .name
= "Saturation",
159 .set_control
= setsatur
163 .id
= V4L2_CID_POWER_LINE_FREQUENCY
,
164 .type
= V4L2_CTRL_TYPE_MENU
,
165 .name
= "Light frequency filter",
167 .maximum
= 2, /* 0: 0, 1: 50Hz, 2:60Hz */
171 .set_control
= setlightfreq
175 static const struct v4l2_pix_format ov965x_mode
[] = {
177 {320, 240, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
179 .sizeimage
= 320 * 240 * 3 / 8 + 590,
180 .colorspace
= V4L2_COLORSPACE_JPEG
},
182 {640, 480, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
184 .sizeimage
= 640 * 480 * 3 / 8 + 590,
185 .colorspace
= V4L2_COLORSPACE_JPEG
},
187 {800, 600, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
189 .sizeimage
= 800 * 600 * 3 / 8 + 590,
190 .colorspace
= V4L2_COLORSPACE_JPEG
},
192 {1024, 768, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
193 .bytesperline
= 1024,
194 .sizeimage
= 1024 * 768 * 3 / 8 + 590,
195 .colorspace
= V4L2_COLORSPACE_JPEG
},
197 {1280, 1024, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
198 .bytesperline
= 1280,
199 .sizeimage
= 1280 * 1024 * 3 / 8 + 590,
200 .colorspace
= V4L2_COLORSPACE_JPEG
},
203 static const struct v4l2_pix_format ov971x_mode
[] = {
204 {640, 480, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
206 .sizeimage
= 640 * 480,
207 .colorspace
= V4L2_COLORSPACE_SRGB
211 static const struct v4l2_pix_format ov562x_mode
[] = {
212 {2592, 1680, V4L2_PIX_FMT_SBGGR8
, V4L2_FIELD_NONE
,
213 .bytesperline
= 2592,
214 .sizeimage
= 2592 * 1680,
215 .colorspace
= V4L2_COLORSPACE_SRGB
219 static const u8 bridge_init
[][2] = {
253 static const u8 ov965x_init
[][2] = {
254 {0x12, 0x80}, /* com7 - SSCB reset */
255 {0x00, 0x00}, /* gain */
256 {0x01, 0x80}, /* blue */
257 {0x02, 0x80}, /* red */
258 {0x03, 0x1b}, /* vref */
259 {0x04, 0x03}, /* com1 - exposure low bits */
260 {0x0b, 0x57}, /* ver */
261 {0x0e, 0x61}, /* com5 */
262 {0x0f, 0x42}, /* com6 */
263 {0x11, 0x00}, /* clkrc */
264 {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
265 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
266 {0x14, 0x28}, /* com9 */
267 {0x16, 0x24}, /* reg16 */
268 {0x17, 0x1d}, /* hstart*/
269 {0x18, 0xbd}, /* hstop */
270 {0x19, 0x01}, /* vstrt */
271 {0x1a, 0x81}, /* vstop*/
272 {0x1e, 0x04}, /* mvfp */
273 {0x24, 0x3c}, /* aew */
274 {0x25, 0x36}, /* aeb */
275 {0x26, 0x71}, /* vpt */
276 {0x27, 0x08}, /* bbias */
277 {0x28, 0x08}, /* gbbias */
278 {0x29, 0x15}, /* gr com */
279 {0x2a, 0x00}, /* exhch */
280 {0x2b, 0x00}, /* exhcl */
281 {0x2c, 0x08}, /* rbias */
282 {0x32, 0xff}, /* href */
283 {0x33, 0x00}, /* chlf */
284 {0x34, 0x3f}, /* aref1 */
285 {0x35, 0x00}, /* aref2 */
286 {0x36, 0xf8}, /* aref3 */
287 {0x38, 0x72}, /* adc2 */
288 {0x39, 0x57}, /* aref4 */
289 {0x3a, 0x80}, /* tslb - yuyv */
290 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
291 {0x3d, 0x99}, /* com13 */
292 {0x3f, 0xc1}, /* edge */
293 {0x40, 0xc0}, /* com15 */
294 {0x41, 0x40}, /* com16 */
295 {0x42, 0xc0}, /* com17 */
296 {0x43, 0x0a}, /* rsvd */
307 {0x4f, 0x98}, /* matrix */
313 {0x58, 0x1a}, /* matrix coef sign */
314 {0x59, 0x85}, /* AWB control */
320 {0x5f, 0xf0}, /* AWB blue limit */
321 {0x60, 0xf0}, /* AWB red limit */
322 {0x61, 0xf0}, /* AWB green limit */
323 {0x62, 0x00}, /* lcc1 */
324 {0x63, 0x00}, /* lcc2 */
325 {0x64, 0x02}, /* lcc3 */
326 {0x65, 0x16}, /* lcc4 */
327 {0x66, 0x01}, /* lcc5 */
328 {0x69, 0x02}, /* hv */
329 {0x6b, 0x5a}, /* dbvl */
334 {0x70, 0x21}, /* dnsth */
336 {0x72, 0x00}, /* poidx */
337 {0x73, 0x01}, /* pckdv */
338 {0x74, 0x3a}, /* xindx */
339 {0x75, 0x35}, /* yindx */
342 {0x7a, 0x12}, /* gamma curve */
359 {0x8c, 0x89}, /* com19 */
360 {0x14, 0x28}, /* com9 */
363 {0x9d, 0x03}, /* lcc6 */
364 {0x9e, 0x04}, /* lcc7 */
367 {0xa1, 0x40}, /* aechm */
368 {0xa4, 0x50}, /* com21 */
369 {0xa5, 0x68}, /* com26 */
370 {0xa6, 0x4a}, /* AWB green */
371 {0xa8, 0xc1}, /* refa8 */
372 {0xa9, 0xef}, /* refa9 */
375 {0xac, 0x80}, /* black level control */
381 {0xb4, 0x20}, /* ctrlb4 */
385 {0xbc, 0x7f}, /* ADC channel offsets */
394 {0xc7, 0x80}, /* com24 */
400 {0x4f, 0x98}, /* matrix */
407 {0xff, 0x41}, /* read 41, write ff 00 */
408 {0x41, 0x40}, /* com16 */
410 {0xc5, 0x03}, /* 60 Hz banding filter */
411 {0x6a, 0x02}, /* 50 Hz banding filter */
413 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
414 {0x36, 0xfa}, /* aref3 */
415 {0x69, 0x0a}, /* hv */
416 {0x8c, 0x89}, /* com22 */
417 {0x14, 0x28}, /* com9 */
419 {0x41, 0x40}, /* com16 */
426 {0x03, 0x12}, /* vref */
427 {0x17, 0x16}, /* hstart */
428 {0x18, 0x02}, /* hstop */
429 {0x19, 0x01}, /* vstrt */
430 {0x1a, 0x3d}, /* vstop */
431 {0x32, 0xff}, /* href */
435 static const u8 bridge_init_2
[][2] = {
463 static const u8 ov965x_init_2
[][2] = {
465 {0x1e, 0x04}, /* mvfp */
466 {0x13, 0xe0}, /* com8 */
467 {0x00, 0x00}, /* gain */
468 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
469 {0x11, 0x03}, /* clkrc */
470 {0x6b, 0x5a}, /* dblv */
476 {0xff, 0x42}, /* read 42, write ff 00 */
477 {0x42, 0xc0}, /* com17 */
479 {0xff, 0x42}, /* read 42, write ff 00 */
480 {0x42, 0xc1}, /* com17 */
483 {0xff, 0x42}, /* read 42, write ff 00 */
484 {0x42, 0xc1}, /* com17 */
486 {0x4f, 0x98}, /* matrix */
493 {0xff, 0x41}, /* read 41, write ff 00 */
494 {0x41, 0x40}, /* com16 */
500 {0x10, 0x25}, /* aech - exposure high bits */
501 {0xff, 0x13}, /* read 13, write ff 00 */
502 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
505 static const u8 ov971x_init
[][2] = {
529 {0x98, 0x40}, /*{0x98, 0x00},*/
530 {0x99, 0xA0}, /*{0x99, 0x00},*/
531 {0x9a, 0x01}, /*{0x9a, 0x00},*/
533 {0x58, 0x78}, /*{0x58, 0xc8},*/
534 {0x59, 0x50}, /*{0x59, 0xa0},*/
539 {0xbd, 0x50}, /*{0xbd, 0xa0},*/
540 {0xbe, 0x78}, /*{0xbe, 0xc8},*/
563 static const u8 ov965x_start_1_vga
[][2] = { /* same for qvga */
564 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
565 {0x36, 0xfa}, /* aref3 */
566 {0x69, 0x0a}, /* hv */
567 {0x8c, 0x89}, /* com22 */
568 {0x14, 0x28}, /* com9 */
569 {0x3e, 0x0c}, /* com14 */
570 {0x41, 0x40}, /* com16 */
576 {0xc7, 0x80}, /* com24 */
577 {0x03, 0x12}, /* vref */
578 {0x17, 0x16}, /* hstart */
579 {0x18, 0x02}, /* hstop */
580 {0x19, 0x01}, /* vstrt */
581 {0x1a, 0x3d}, /* vstop */
582 {0x32, 0xff}, /* href */
586 static const u8 ov965x_start_1_svga
[][2] = {
587 {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
588 {0x36, 0xf8}, /* aref3 */
589 {0x69, 0x02}, /* hv */
590 {0x8c, 0x0d}, /* com22 */
591 {0x3e, 0x0c}, /* com14 */
592 {0x41, 0x40}, /* com16 */
598 {0xc7, 0x80}, /* com24 */
599 {0x03, 0x1b}, /* vref */
600 {0x17, 0x1d}, /* hstart */
601 {0x18, 0xbd}, /* hstop */
602 {0x19, 0x01}, /* vstrt */
603 {0x1a, 0x81}, /* vstop */
604 {0x32, 0xff}, /* href */
608 static const u8 ov965x_start_1_xga
[][2] = {
609 {0x12, 0x02}, /* com7 */
610 {0x36, 0xf8}, /* aref3 */
611 {0x69, 0x02}, /* hv */
612 {0x8c, 0x89}, /* com22 */
613 {0x14, 0x28}, /* com9 */
614 {0x3e, 0x0c}, /* com14 */
615 {0x41, 0x40}, /* com16 */
621 {0xc7, 0x80}, /* com24 */
622 {0x03, 0x1b}, /* vref */
623 {0x17, 0x1d}, /* hstart */
624 {0x18, 0xbd}, /* hstop */
625 {0x19, 0x01}, /* vstrt */
626 {0x1a, 0x81}, /* vstop */
627 {0x32, 0xff}, /* href */
631 static const u8 ov965x_start_1_sxga
[][2] = {
632 {0x12, 0x02}, /* com7 */
633 {0x36, 0xf8}, /* aref3 */
634 {0x69, 0x02}, /* hv */
635 {0x8c, 0x89}, /* com22 */
636 {0x14, 0x28}, /* com9 */
637 {0x3e, 0x0c}, /* com14 */
638 {0x41, 0x40}, /* com16 */
644 {0xc7, 0x80}, /* com24 */
645 {0x03, 0x1b}, /* vref */
646 {0x17, 0x1d}, /* hstart */
647 {0x18, 0x02}, /* hstop */
648 {0x19, 0x01}, /* vstrt */
649 {0x1a, 0x81}, /* vstop */
650 {0x32, 0xff}, /* href */
654 static const u8 bridge_start_qvga
[][2] = {
682 static const u8 bridge_start_vga
[][2] = {
709 static const u8 bridge_start_svga
[][2] = {
736 static const u8 bridge_start_xga
[][2] = {
763 static const u8 bridge_start_sxga
[][2] = {
780 static const u8 ov965x_start_2_qvga
[][2] = {
781 {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
782 {0x1e, 0x04}, /* mvfp */
783 {0x13, 0xe0}, /* com8 */
785 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
786 {0x11, 0x01}, /* clkrc */
787 {0x6b, 0x5a}, /* dblv */
788 {0x6a, 0x02}, /* 50 Hz banding filter */
789 {0xc5, 0x03}, /* 60 Hz banding filter */
790 {0xa2, 0x96}, /* bd50 */
791 {0xa3, 0x7d}, /* bd60 */
793 {0xff, 0x13}, /* read 13, write ff 00 */
795 {0x3a, 0x80}, /* tslb - yuyv */
798 static const u8 ov965x_start_2_vga
[][2] = {
799 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
800 {0x1e, 0x04}, /* mvfp */
801 {0x13, 0xe0}, /* com8 */
803 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
804 {0x11, 0x03}, /* clkrc */
805 {0x6b, 0x5a}, /* dblv */
806 {0x6a, 0x05}, /* 50 Hz banding filter */
807 {0xc5, 0x07}, /* 60 Hz banding filter */
808 {0xa2, 0x4b}, /* bd50 */
809 {0xa3, 0x3e}, /* bd60 */
811 {0x2d, 0x00}, /* advfl */
814 static const u8 ov965x_start_2_svga
[][2] = { /* same for xga */
815 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
816 {0x1e, 0x04}, /* mvfp */
817 {0x13, 0xe0}, /* com8 */
819 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
820 {0x11, 0x01}, /* clkrc */
821 {0x6b, 0x5a}, /* dblv */
822 {0x6a, 0x0c}, /* 50 Hz banding filter */
823 {0xc5, 0x0f}, /* 60 Hz banding filter */
824 {0xa2, 0x4e}, /* bd50 */
825 {0xa3, 0x41}, /* bd60 */
828 static const u8 ov965x_start_2_sxga
[][2] = {
829 {0x13, 0xe0}, /* com8 */
831 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
832 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
833 {0x1e, 0x04}, /* mvfp */
834 {0x11, 0x01}, /* clkrc */
835 {0x6b, 0x5a}, /* dblv */
836 {0x6a, 0x0c}, /* 50 Hz banding filter */
837 {0xc5, 0x0f}, /* 60 Hz banding filter */
838 {0xa2, 0x4e}, /* bd50 */
839 {0xa3, 0x41}, /* bd60 */
842 static const u8 ov562x_init
[][2] = {
858 static const u8 ov562x_init_2
[][2] = {
960 static void reg_w_i(struct gspca_dev
*gspca_dev
, u16 reg
, u8 val
)
962 struct usb_device
*udev
= gspca_dev
->dev
;
965 if (gspca_dev
->usb_err
< 0)
967 gspca_dev
->usb_buf
[0] = val
;
968 ret
= usb_control_msg(udev
,
969 usb_sndctrlpipe(udev
, 0),
971 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
972 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
974 pr_err("reg_w failed %d\n", ret
);
975 gspca_dev
->usb_err
= ret
;
979 static void reg_w(struct gspca_dev
*gspca_dev
, u16 reg
, u8 val
)
981 PDEBUG(D_USBO
, "reg_w [%04x] = %02x", reg
, val
);
982 reg_w_i(gspca_dev
, reg
, val
);
985 static u8
reg_r(struct gspca_dev
*gspca_dev
, u16 reg
)
987 struct usb_device
*udev
= gspca_dev
->dev
;
990 if (gspca_dev
->usb_err
< 0)
992 ret
= usb_control_msg(udev
,
993 usb_rcvctrlpipe(udev
, 0),
995 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
996 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
997 PDEBUG(D_USBI
, "reg_r [%04x] -> %02x", reg
, gspca_dev
->usb_buf
[0]);
999 pr_err("reg_r err %d\n", ret
);
1000 gspca_dev
->usb_err
= ret
;
1002 return gspca_dev
->usb_buf
[0];
1005 static int sccb_check_status(struct gspca_dev
*gspca_dev
)
1010 for (i
= 0; i
< 5; i
++) {
1012 data
= reg_r(gspca_dev
, OV534_REG_STATUS
);
1022 PDEBUG(D_USBI
|D_USBO
,
1023 "sccb status 0x%02x, attempt %d/5",
1030 static void sccb_write(struct gspca_dev
*gspca_dev
, u8 reg
, u8 val
)
1032 PDEBUG(D_USBO
, "sccb_write [%02x] = %02x", reg
, val
);
1033 reg_w_i(gspca_dev
, OV534_REG_SUBADDR
, reg
);
1034 reg_w_i(gspca_dev
, OV534_REG_WRITE
, val
);
1035 reg_w_i(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_3
);
1037 if (!sccb_check_status(gspca_dev
))
1038 pr_err("sccb_write failed\n");
1041 static u8
sccb_read(struct gspca_dev
*gspca_dev
, u16 reg
)
1043 reg_w(gspca_dev
, OV534_REG_SUBADDR
, reg
);
1044 reg_w(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_2
);
1045 if (!sccb_check_status(gspca_dev
))
1046 pr_err("sccb_read failed 1\n");
1048 reg_w(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_READ_2
);
1049 if (!sccb_check_status(gspca_dev
))
1050 pr_err("sccb_read failed 2\n");
1052 return reg_r(gspca_dev
, OV534_REG_READ
);
1055 /* output a bridge sequence (reg - val) */
1056 static void reg_w_array(struct gspca_dev
*gspca_dev
,
1057 const u8 (*data
)[2], int len
)
1059 while (--len
>= 0) {
1060 reg_w(gspca_dev
, (*data
)[0], (*data
)[1]);
1065 /* output a sensor sequence (reg - val) */
1066 static void sccb_w_array(struct gspca_dev
*gspca_dev
,
1067 const u8 (*data
)[2], int len
)
1069 while (--len
>= 0) {
1070 if ((*data
)[0] != 0xff) {
1071 sccb_write(gspca_dev
, (*data
)[0], (*data
)[1]);
1073 sccb_read(gspca_dev
, (*data
)[1]);
1074 sccb_write(gspca_dev
, 0xff, 0x00);
1080 /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
1081 * (direction and output)? */
1082 static void set_led(struct gspca_dev
*gspca_dev
, int status
)
1086 PDEBUG(D_CONF
, "led status: %d", status
);
1088 data
= reg_r(gspca_dev
, 0x21);
1090 reg_w(gspca_dev
, 0x21, data
);
1092 data
= reg_r(gspca_dev
, 0x23);
1098 reg_w(gspca_dev
, 0x23, data
);
1101 data
= reg_r(gspca_dev
, 0x21);
1103 reg_w(gspca_dev
, 0x21, data
);
1107 static void setbrightness(struct gspca_dev
*gspca_dev
)
1109 struct sd
*sd
= (struct sd
*) gspca_dev
;
1113 if (gspca_dev
->ctrl_dis
& (1 << BRIGHTNESS
))
1115 if (sd
->sensor
== SENSOR_OV562x
) {
1116 sval
= sd
->ctrls
[BRIGHTNESS
].val
;
1119 sccb_write(gspca_dev
, 0x24, val
);
1122 sccb_write(gspca_dev
, 0x25, val
);
1129 sccb_write(gspca_dev
, 0x26, val
);
1131 val
= sd
->ctrls
[BRIGHTNESS
].val
;
1133 val
= 15 - val
; /* f .. 8 */
1135 val
= val
- 8; /* 0 .. 7 */
1136 sccb_write(gspca_dev
, 0x55, /* brtn - brightness adjustment */
1141 static void setcontrast(struct gspca_dev
*gspca_dev
)
1143 struct sd
*sd
= (struct sd
*) gspca_dev
;
1145 if (gspca_dev
->ctrl_dis
& (1 << CONTRAST
))
1147 sccb_write(gspca_dev
, 0x56, /* cnst1 - contrast 1 ctrl coeff */
1148 sd
->ctrls
[CONTRAST
].val
<< 4);
1151 static void setautogain(struct gspca_dev
*gspca_dev
)
1153 struct sd
*sd
= (struct sd
*) gspca_dev
;
1156 if (gspca_dev
->ctrl_dis
& (1 << AUTOGAIN
))
1158 /*fixme: should adjust agc/awb/aec by different controls */
1159 val
= sccb_read(gspca_dev
, 0x13); /* com8 */
1160 sccb_write(gspca_dev
, 0xff, 0x00);
1161 if (sd
->ctrls
[AUTOGAIN
].val
)
1162 val
|= 0x05; /* agc & aec */
1165 sccb_write(gspca_dev
, 0x13, val
);
1168 static void setexposure(struct gspca_dev
*gspca_dev
)
1170 struct sd
*sd
= (struct sd
*) gspca_dev
;
1172 static const u8 expo
[4] = {0x00, 0x25, 0x38, 0x5e};
1174 if (gspca_dev
->ctrl_dis
& (1 << EXPOSURE
))
1176 sccb_write(gspca_dev
, 0x10, /* aec[9:2] */
1177 expo
[sd
->ctrls
[EXPOSURE
].val
]);
1179 val
= sccb_read(gspca_dev
, 0x13); /* com8 */
1180 sccb_write(gspca_dev
, 0xff, 0x00);
1181 sccb_write(gspca_dev
, 0x13, val
);
1183 val
= sccb_read(gspca_dev
, 0xa1); /* aech */
1184 sccb_write(gspca_dev
, 0xff, 0x00);
1185 sccb_write(gspca_dev
, 0xa1, val
& 0xe0); /* aec[15:10] = 0 */
1188 static void setsharpness(struct gspca_dev
*gspca_dev
)
1190 struct sd
*sd
= (struct sd
*) gspca_dev
;
1193 if (gspca_dev
->ctrl_dis
& (1 << SHARPNESS
))
1195 val
= sd
->ctrls
[SHARPNESS
].val
;
1196 if (val
< 0) { /* auto */
1197 val
= sccb_read(gspca_dev
, 0x42); /* com17 */
1198 sccb_write(gspca_dev
, 0xff, 0x00);
1199 sccb_write(gspca_dev
, 0x42, val
| 0x40);
1200 /* Edge enhancement strength auto adjust */
1204 val
= 1 << (val
- 1);
1205 sccb_write(gspca_dev
, 0x3f, /* edge - edge enhance. factor */
1207 val
= sccb_read(gspca_dev
, 0x42); /* com17 */
1208 sccb_write(gspca_dev
, 0xff, 0x00);
1209 sccb_write(gspca_dev
, 0x42, val
& 0xbf);
1212 static void setsatur(struct gspca_dev
*gspca_dev
)
1214 struct sd
*sd
= (struct sd
*) gspca_dev
;
1215 u8 val1
, val2
, val3
;
1216 static const u8 matrix
[5][2] = {
1224 if (gspca_dev
->ctrl_dis
& (1 << SATUR
))
1226 val1
= matrix
[sd
->ctrls
[SATUR
].val
][0];
1227 val2
= matrix
[sd
->ctrls
[SATUR
].val
][1];
1229 sccb_write(gspca_dev
, 0x4f, val3
); /* matrix coeff */
1230 sccb_write(gspca_dev
, 0x50, val3
);
1231 sccb_write(gspca_dev
, 0x51, 0x00);
1232 sccb_write(gspca_dev
, 0x52, val1
);
1233 sccb_write(gspca_dev
, 0x53, val2
);
1234 sccb_write(gspca_dev
, 0x54, val3
);
1235 sccb_write(gspca_dev
, 0x58, 0x1a); /* mtxs - coeff signs */
1237 val1
= sccb_read(gspca_dev
, 0x41); /* com16 */
1238 sccb_write(gspca_dev
, 0xff, 0x00);
1239 sccb_write(gspca_dev
, 0x41, val1
);
1242 static void setlightfreq(struct gspca_dev
*gspca_dev
)
1244 struct sd
*sd
= (struct sd
*) gspca_dev
;
1247 if (gspca_dev
->ctrl_dis
& (1 << LIGHTFREQ
))
1249 val
= sccb_read(gspca_dev
, 0x13); /* com8 */
1250 sccb_write(gspca_dev
, 0xff, 0x00);
1251 if (sd
->ctrls
[LIGHTFREQ
].val
== 0) {
1252 sccb_write(gspca_dev
, 0x13, val
& 0xdf);
1255 sccb_write(gspca_dev
, 0x13, val
| 0x20);
1257 val
= sccb_read(gspca_dev
, 0x42); /* com17 */
1258 sccb_write(gspca_dev
, 0xff, 0x00);
1259 if (sd
->ctrls
[LIGHTFREQ
].val
== 1)
1263 sccb_write(gspca_dev
, 0x42, val
);
1266 /* this function is called at probe time */
1267 static int sd_config(struct gspca_dev
*gspca_dev
,
1268 const struct usb_device_id
*id
)
1270 struct sd
*sd
= (struct sd
*) gspca_dev
;
1272 gspca_dev
->cam
.ctrls
= sd
->ctrls
;
1274 #if AUTOGAIN_DEF != 0
1275 gspca_dev
->ctrl_inac
|= (1 << EXPOSURE
);
1280 /* this function is called at probe and resume time */
1281 static int sd_init(struct gspca_dev
*gspca_dev
)
1283 struct sd
*sd
= (struct sd
*) gspca_dev
;
1287 reg_w(gspca_dev
, 0xe7, 0x3a);
1288 reg_w(gspca_dev
, 0xe0, 0x08);
1291 /* initialize the sensor address */
1292 reg_w(gspca_dev
, OV534_REG_ADDRESS
, 0x60);
1295 sccb_write(gspca_dev
, 0x12, 0x80);
1298 /* probe the sensor */
1299 sccb_read(gspca_dev
, 0x0a);
1300 sensor_id
= sccb_read(gspca_dev
, 0x0a) << 8;
1301 sccb_read(gspca_dev
, 0x0b);
1302 sensor_id
|= sccb_read(gspca_dev
, 0x0b);
1303 PDEBUG(D_PROBE
, "Sensor ID: %04x", sensor_id
);
1306 if ((sensor_id
& 0xfff0) == 0x9650) {
1307 sd
->sensor
= SENSOR_OV965x
;
1309 gspca_dev
->cam
.cam_mode
= ov965x_mode
;
1310 gspca_dev
->cam
.nmodes
= ARRAY_SIZE(ov965x_mode
);
1312 reg_w_array(gspca_dev
, bridge_init
,
1313 ARRAY_SIZE(bridge_init
));
1314 sccb_w_array(gspca_dev
, ov965x_init
,
1315 ARRAY_SIZE(ov965x_init
));
1316 reg_w_array(gspca_dev
, bridge_init_2
,
1317 ARRAY_SIZE(bridge_init_2
));
1318 sccb_w_array(gspca_dev
, ov965x_init_2
,
1319 ARRAY_SIZE(ov965x_init_2
));
1320 reg_w(gspca_dev
, 0xe0, 0x00);
1321 reg_w(gspca_dev
, 0xe0, 0x01);
1322 set_led(gspca_dev
, 0);
1323 reg_w(gspca_dev
, 0xe0, 0x00);
1324 } else if ((sensor_id
& 0xfff0) == 0x9710) {
1328 sd
->sensor
= SENSOR_OV971x
;
1330 gspca_dev
->cam
.cam_mode
= ov971x_mode
;
1331 gspca_dev
->cam
.nmodes
= ARRAY_SIZE(ov971x_mode
);
1333 /* no control yet */
1334 gspca_dev
->ctrl_dis
= (1 << NCTRLS
) - 1;
1336 gspca_dev
->cam
.bulk
= 1;
1337 gspca_dev
->cam
.bulk_size
= 16384;
1338 gspca_dev
->cam
.bulk_nurbs
= 2;
1340 sccb_w_array(gspca_dev
, ov971x_init
,
1341 ARRAY_SIZE(ov971x_init
));
1343 /* set video format on bridge processor */
1344 /* access bridge processor's video format registers at: 0x00 */
1345 reg_w(gspca_dev
, 0x1c, 0x00);
1346 /*set register: 0x00 is 'RAW8', 0x40 is 'YUV422' (YUYV?)*/
1347 reg_w(gspca_dev
, 0x1d, 0x00);
1349 /* Will W. specific stuff
1351 * output (0x1f) if first webcam
1352 * input (0x17) if 2nd or 3rd webcam */
1353 p
= video_device_node_name(&gspca_dev
->vdev
);
1356 reg_w(gspca_dev
, 0x56, 0x1f);
1358 reg_w(gspca_dev
, 0x56, 0x17);
1359 } else if ((sensor_id
& 0xfff0) == 0x5620) {
1360 sd
->sensor
= SENSOR_OV562x
;
1361 gspca_dev
->ctrl_dis
= (1 << CONTRAST
) |
1368 sd
->ctrls
[BRIGHTNESS
].min
= -90;
1369 sd
->ctrls
[BRIGHTNESS
].max
= 90;
1370 sd
->ctrls
[BRIGHTNESS
].def
= 0;
1371 gspca_dev
->cam
.cam_mode
= ov562x_mode
;
1372 gspca_dev
->cam
.nmodes
= ARRAY_SIZE(ov562x_mode
);
1374 reg_w_array(gspca_dev
, ov562x_init
,
1375 ARRAY_SIZE(ov562x_init
));
1376 sccb_w_array(gspca_dev
, ov562x_init_2
,
1377 ARRAY_SIZE(ov562x_init_2
));
1378 reg_w(gspca_dev
, 0xe0, 0x00);
1380 pr_err("Unknown sensor %04x", sensor_id
);
1384 return gspca_dev
->usb_err
;
1387 static int sd_start(struct gspca_dev
*gspca_dev
)
1389 struct sd
*sd
= (struct sd
*) gspca_dev
;
1391 if (sd
->sensor
== SENSOR_OV971x
)
1392 return gspca_dev
->usb_err
;
1393 else if (sd
->sensor
== SENSOR_OV562x
) {
1394 setbrightness(gspca_dev
);
1395 return gspca_dev
->usb_err
;
1397 switch (gspca_dev
->curr_mode
) {
1398 case QVGA_MODE
: /* 320x240 */
1399 sccb_w_array(gspca_dev
, ov965x_start_1_vga
,
1400 ARRAY_SIZE(ov965x_start_1_vga
));
1401 reg_w_array(gspca_dev
, bridge_start_qvga
,
1402 ARRAY_SIZE(bridge_start_qvga
));
1403 sccb_w_array(gspca_dev
, ov965x_start_2_qvga
,
1404 ARRAY_SIZE(ov965x_start_2_qvga
));
1406 case VGA_MODE
: /* 640x480 */
1407 sccb_w_array(gspca_dev
, ov965x_start_1_vga
,
1408 ARRAY_SIZE(ov965x_start_1_vga
));
1409 reg_w_array(gspca_dev
, bridge_start_vga
,
1410 ARRAY_SIZE(bridge_start_vga
));
1411 sccb_w_array(gspca_dev
, ov965x_start_2_vga
,
1412 ARRAY_SIZE(ov965x_start_2_vga
));
1414 case SVGA_MODE
: /* 800x600 */
1415 sccb_w_array(gspca_dev
, ov965x_start_1_svga
,
1416 ARRAY_SIZE(ov965x_start_1_svga
));
1417 reg_w_array(gspca_dev
, bridge_start_svga
,
1418 ARRAY_SIZE(bridge_start_svga
));
1419 sccb_w_array(gspca_dev
, ov965x_start_2_svga
,
1420 ARRAY_SIZE(ov965x_start_2_svga
));
1422 case XGA_MODE
: /* 1024x768 */
1423 sccb_w_array(gspca_dev
, ov965x_start_1_xga
,
1424 ARRAY_SIZE(ov965x_start_1_xga
));
1425 reg_w_array(gspca_dev
, bridge_start_xga
,
1426 ARRAY_SIZE(bridge_start_xga
));
1427 sccb_w_array(gspca_dev
, ov965x_start_2_svga
,
1428 ARRAY_SIZE(ov965x_start_2_svga
));
1431 /* case SXGA_MODE: * 1280x1024 */
1432 sccb_w_array(gspca_dev
, ov965x_start_1_sxga
,
1433 ARRAY_SIZE(ov965x_start_1_sxga
));
1434 reg_w_array(gspca_dev
, bridge_start_sxga
,
1435 ARRAY_SIZE(bridge_start_sxga
));
1436 sccb_w_array(gspca_dev
, ov965x_start_2_sxga
,
1437 ARRAY_SIZE(ov965x_start_2_sxga
));
1440 setlightfreq(gspca_dev
);
1441 setautogain(gspca_dev
);
1442 setbrightness(gspca_dev
);
1443 setcontrast(gspca_dev
);
1444 setexposure(gspca_dev
);
1445 setsharpness(gspca_dev
);
1446 setsatur(gspca_dev
);
1448 reg_w(gspca_dev
, 0xe0, 0x00);
1449 reg_w(gspca_dev
, 0xe0, 0x00);
1450 set_led(gspca_dev
, 1);
1451 return gspca_dev
->usb_err
;
1454 static void sd_stopN(struct gspca_dev
*gspca_dev
)
1456 reg_w(gspca_dev
, 0xe0, 0x01);
1457 set_led(gspca_dev
, 0);
1458 reg_w(gspca_dev
, 0xe0, 0x00);
1461 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
1462 #define UVC_STREAM_EOH (1 << 7)
1463 #define UVC_STREAM_ERR (1 << 6)
1464 #define UVC_STREAM_STI (1 << 5)
1465 #define UVC_STREAM_RES (1 << 4)
1466 #define UVC_STREAM_SCR (1 << 3)
1467 #define UVC_STREAM_PTS (1 << 2)
1468 #define UVC_STREAM_EOF (1 << 1)
1469 #define UVC_STREAM_FID (1 << 0)
1471 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
1474 struct sd
*sd
= (struct sd
*) gspca_dev
;
1477 int remaining_len
= len
;
1480 payload_len
= gspca_dev
->cam
.bulk
? 2048 : 2040;
1482 len
= min(remaining_len
, payload_len
);
1484 /* Payloads are prefixed with a UVC-style header. We
1485 consider a frame to start when the FID toggles, or the PTS
1486 changes. A frame ends when EOF is set, and we've received
1487 the correct number of bytes. */
1489 /* Verify UVC header. Header length is always 12 */
1490 if (data
[0] != 12 || len
< 12) {
1491 PDEBUG(D_PACK
, "bad header");
1496 if (data
[1] & UVC_STREAM_ERR
) {
1497 PDEBUG(D_PACK
, "payload error");
1501 /* Extract PTS and FID */
1502 if (!(data
[1] & UVC_STREAM_PTS
)) {
1503 PDEBUG(D_PACK
, "PTS not present");
1506 this_pts
= (data
[5] << 24) | (data
[4] << 16)
1507 | (data
[3] << 8) | data
[2];
1508 this_fid
= data
[1] & UVC_STREAM_FID
;
1510 /* If PTS or FID has changed, start a new frame. */
1511 if (this_pts
!= sd
->last_pts
|| this_fid
!= sd
->last_fid
) {
1512 if (gspca_dev
->last_packet_type
== INTER_PACKET
)
1513 gspca_frame_add(gspca_dev
, LAST_PACKET
,
1515 sd
->last_pts
= this_pts
;
1516 sd
->last_fid
= this_fid
;
1517 gspca_frame_add(gspca_dev
, FIRST_PACKET
,
1518 data
+ 12, len
- 12);
1519 /* If this packet is marked as EOF, end the frame */
1520 } else if (data
[1] & UVC_STREAM_EOF
) {
1522 gspca_frame_add(gspca_dev
, LAST_PACKET
,
1523 data
+ 12, len
- 12);
1526 /* Add the data from this payload */
1527 gspca_frame_add(gspca_dev
, INTER_PACKET
,
1528 data
+ 12, len
- 12);
1531 /* Done this payload */
1535 /* Discard data until a new frame starts. */
1536 gspca_dev
->last_packet_type
= DISCARD_PACKET
;
1539 remaining_len
-= len
;
1541 } while (remaining_len
> 0);
1544 static int sd_querymenu(struct gspca_dev
*gspca_dev
,
1545 struct v4l2_querymenu
*menu
)
1548 case V4L2_CID_POWER_LINE_FREQUENCY
:
1549 switch (menu
->index
) {
1550 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1551 strcpy((char *) menu
->name
, "NoFliker");
1553 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1554 strcpy((char *) menu
->name
, "50 Hz");
1556 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
1557 strcpy((char *) menu
->name
, "60 Hz");
1565 /* sub-driver description */
1566 static const struct sd_desc sd_desc
= {
1567 .name
= MODULE_NAME
,
1570 .config
= sd_config
,
1574 .pkt_scan
= sd_pkt_scan
,
1575 .querymenu
= sd_querymenu
,
1578 /* -- module initialisation -- */
1579 static const struct usb_device_id device_table
[] = {
1580 {USB_DEVICE(0x05a9, 0x8065)},
1581 {USB_DEVICE(0x06f8, 0x3003)},
1582 {USB_DEVICE(0x05a9, 0x1550)},
1586 MODULE_DEVICE_TABLE(usb
, device_table
);
1588 /* -- device connect -- */
1589 static int sd_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1591 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
1595 static struct usb_driver sd_driver
= {
1596 .name
= MODULE_NAME
,
1597 .id_table
= device_table
,
1599 .disconnect
= gspca_disconnect
,
1601 .suspend
= gspca_suspend
,
1602 .resume
= gspca_resume
,
1606 module_usb_driver(sd_driver
);