4 * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
6 * This module is adapted from the ov51x-jpeg package, which itself
7 * was adapted from the ov511 driver.
9 * Original copyright for the ov511 driver is:
11 * Copyright (c) 1999-2004 Mark W. McClelland
12 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
14 * ov51x-jpeg original copyright is:
16 * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
17 * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define MODULE_NAME "ov519"
38 MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
39 MODULE_DESCRIPTION("OV519 USB Camera Driver");
40 MODULE_LICENSE("GPL");
42 /* global parameters */
43 static int frame_rate
;
45 /* Number of times to retry a failed I2C transaction. Increase this if you
46 * are getting "Failed to read sensor ID..." */
47 static int i2c_detect_tries
= 10;
49 /* ov519 device descriptor */
51 struct gspca_dev gspca_dev
; /* !! must be the first item */
56 #define BRIDGE_OV511 0
57 #define BRIDGE_OV511PLUS 1
58 #define BRIDGE_OV518 2
59 #define BRIDGE_OV518PLUS 3
60 #define BRIDGE_OV519 4
64 #define BRIDGE_INVERT_LED 8
66 /* Determined by sensor type */
77 __u8 stopped
; /* Streaming is temporarily paused */
79 __u8 frame_rate
; /* current Framerate */
80 __u8 clockdiv
; /* clockdiv override */
82 char sensor
; /* Type of image sensor chip (SEN_*) */
86 #define SEN_OV66308AF 3
95 /* V4L2 controls supported by the driver */
96 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
97 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
98 static int sd_setcontrast(struct gspca_dev
*gspca_dev
, __s32 val
);
99 static int sd_getcontrast(struct gspca_dev
*gspca_dev
, __s32
*val
);
100 static int sd_setcolors(struct gspca_dev
*gspca_dev
, __s32 val
);
101 static int sd_getcolors(struct gspca_dev
*gspca_dev
, __s32
*val
);
102 static int sd_sethflip(struct gspca_dev
*gspca_dev
, __s32 val
);
103 static int sd_gethflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
104 static int sd_setvflip(struct gspca_dev
*gspca_dev
, __s32 val
);
105 static int sd_getvflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
106 static int sd_setautobrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
107 static int sd_getautobrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
108 static int sd_setfreq(struct gspca_dev
*gspca_dev
, __s32 val
);
109 static int sd_getfreq(struct gspca_dev
*gspca_dev
, __s32
*val
);
110 static void setbrightness(struct gspca_dev
*gspca_dev
);
111 static void setcontrast(struct gspca_dev
*gspca_dev
);
112 static void setcolors(struct gspca_dev
*gspca_dev
);
113 static void setautobrightness(struct sd
*sd
);
114 static void setfreq(struct sd
*sd
);
116 static const struct ctrl sd_ctrls
[] = {
119 .id
= V4L2_CID_BRIGHTNESS
,
120 .type
= V4L2_CTRL_TYPE_INTEGER
,
121 .name
= "Brightness",
125 #define BRIGHTNESS_DEF 127
126 .default_value
= BRIGHTNESS_DEF
,
128 .set
= sd_setbrightness
,
129 .get
= sd_getbrightness
,
133 .id
= V4L2_CID_CONTRAST
,
134 .type
= V4L2_CTRL_TYPE_INTEGER
,
139 #define CONTRAST_DEF 127
140 .default_value
= CONTRAST_DEF
,
142 .set
= sd_setcontrast
,
143 .get
= sd_getcontrast
,
147 .id
= V4L2_CID_SATURATION
,
148 .type
= V4L2_CTRL_TYPE_INTEGER
,
153 #define COLOR_DEF 127
154 .default_value
= COLOR_DEF
,
159 /* The flip controls work with ov7670 only */
163 .id
= V4L2_CID_HFLIP
,
164 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
170 .default_value
= HFLIP_DEF
,
178 .id
= V4L2_CID_VFLIP
,
179 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
185 .default_value
= VFLIP_DEF
,
190 #define AUTOBRIGHT_IDX 5
193 .id
= V4L2_CID_AUTOBRIGHTNESS
,
194 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
195 .name
= "Auto Brightness",
199 #define AUTOBRIGHT_DEF 1
200 .default_value
= AUTOBRIGHT_DEF
,
202 .set
= sd_setautobrightness
,
203 .get
= sd_getautobrightness
,
208 .id
= V4L2_CID_POWER_LINE_FREQUENCY
,
209 .type
= V4L2_CTRL_TYPE_MENU
,
210 .name
= "Light frequency filter",
212 .maximum
= 2, /* 0: 0, 1: 50Hz, 2:60Hz */
215 .default_value
= FREQ_DEF
,
220 #define OV7670_FREQ_IDX 7
223 .id
= V4L2_CID_POWER_LINE_FREQUENCY
,
224 .type
= V4L2_CTRL_TYPE_MENU
,
225 .name
= "Light frequency filter",
227 .maximum
= 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */
229 #define OV7670_FREQ_DEF 3
230 .default_value
= OV7670_FREQ_DEF
,
237 static const struct v4l2_pix_format ov519_vga_mode
[] = {
238 {320, 240, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
240 .sizeimage
= 320 * 240 * 3 / 8 + 590,
241 .colorspace
= V4L2_COLORSPACE_JPEG
,
243 {640, 480, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
245 .sizeimage
= 640 * 480 * 3 / 8 + 590,
246 .colorspace
= V4L2_COLORSPACE_JPEG
,
249 static const struct v4l2_pix_format ov519_sif_mode
[] = {
250 {160, 120, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
252 .sizeimage
= 160 * 120 * 3 / 8 + 590,
253 .colorspace
= V4L2_COLORSPACE_JPEG
,
255 {176, 144, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
257 .sizeimage
= 176 * 144 * 3 / 8 + 590,
258 .colorspace
= V4L2_COLORSPACE_JPEG
,
260 {320, 240, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
262 .sizeimage
= 320 * 240 * 3 / 8 + 590,
263 .colorspace
= V4L2_COLORSPACE_JPEG
,
265 {352, 288, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
267 .sizeimage
= 352 * 288 * 3 / 8 + 590,
268 .colorspace
= V4L2_COLORSPACE_JPEG
,
272 /* Note some of the sizeimage values for the ov511 / ov518 may seem
273 larger then necessary, however they need to be this big as the ov511 /
274 ov518 always fills the entire isoc frame, using 0 padding bytes when
275 it doesn't have any data. So with low framerates the amount of data
276 transfered can become quite large (libv4l will remove all the 0 padding
278 static const struct v4l2_pix_format ov518_vga_mode
[] = {
279 {320, 240, V4L2_PIX_FMT_OV518
, V4L2_FIELD_NONE
,
281 .sizeimage
= 320 * 240 * 3,
282 .colorspace
= V4L2_COLORSPACE_JPEG
,
284 {640, 480, V4L2_PIX_FMT_OV518
, V4L2_FIELD_NONE
,
286 .sizeimage
= 640 * 480 * 2,
287 .colorspace
= V4L2_COLORSPACE_JPEG
,
290 static const struct v4l2_pix_format ov518_sif_mode
[] = {
291 {160, 120, V4L2_PIX_FMT_OV518
, V4L2_FIELD_NONE
,
294 .colorspace
= V4L2_COLORSPACE_JPEG
,
296 {176, 144, V4L2_PIX_FMT_OV518
, V4L2_FIELD_NONE
,
299 .colorspace
= V4L2_COLORSPACE_JPEG
,
301 {320, 240, V4L2_PIX_FMT_OV518
, V4L2_FIELD_NONE
,
303 .sizeimage
= 320 * 240 * 3,
304 .colorspace
= V4L2_COLORSPACE_JPEG
,
306 {352, 288, V4L2_PIX_FMT_OV518
, V4L2_FIELD_NONE
,
308 .sizeimage
= 352 * 288 * 3,
309 .colorspace
= V4L2_COLORSPACE_JPEG
,
313 static const struct v4l2_pix_format ov511_vga_mode
[] = {
314 {320, 240, V4L2_PIX_FMT_OV511
, V4L2_FIELD_NONE
,
316 .sizeimage
= 320 * 240 * 3,
317 .colorspace
= V4L2_COLORSPACE_JPEG
,
319 {640, 480, V4L2_PIX_FMT_OV511
, V4L2_FIELD_NONE
,
321 .sizeimage
= 640 * 480 * 2,
322 .colorspace
= V4L2_COLORSPACE_JPEG
,
325 static const struct v4l2_pix_format ov511_sif_mode
[] = {
326 {160, 120, V4L2_PIX_FMT_OV511
, V4L2_FIELD_NONE
,
329 .colorspace
= V4L2_COLORSPACE_JPEG
,
331 {176, 144, V4L2_PIX_FMT_OV511
, V4L2_FIELD_NONE
,
334 .colorspace
= V4L2_COLORSPACE_JPEG
,
336 {320, 240, V4L2_PIX_FMT_OV511
, V4L2_FIELD_NONE
,
338 .sizeimage
= 320 * 240 * 3,
339 .colorspace
= V4L2_COLORSPACE_JPEG
,
341 {352, 288, V4L2_PIX_FMT_OV511
, V4L2_FIELD_NONE
,
343 .sizeimage
= 352 * 288 * 3,
344 .colorspace
= V4L2_COLORSPACE_JPEG
,
348 /* Registers common to OV511 / OV518 */
349 #define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
350 #define R51x_SYS_RESET 0x50
351 /* Reset type flags */
352 #define OV511_RESET_OMNICE 0x08
353 #define R51x_SYS_INIT 0x53
354 #define R51x_SYS_SNAP 0x52
355 #define R51x_SYS_CUST_ID 0x5F
356 #define R51x_COMP_LUT_BEGIN 0x80
358 /* OV511 Camera interface register numbers */
359 #define R511_CAM_DELAY 0x10
360 #define R511_CAM_EDGE 0x11
361 #define R511_CAM_PXCNT 0x12
362 #define R511_CAM_LNCNT 0x13
363 #define R511_CAM_PXDIV 0x14
364 #define R511_CAM_LNDIV 0x15
365 #define R511_CAM_UV_EN 0x16
366 #define R511_CAM_LINE_MODE 0x17
367 #define R511_CAM_OPTS 0x18
369 #define R511_SNAP_FRAME 0x19
370 #define R511_SNAP_PXCNT 0x1A
371 #define R511_SNAP_LNCNT 0x1B
372 #define R511_SNAP_PXDIV 0x1C
373 #define R511_SNAP_LNDIV 0x1D
374 #define R511_SNAP_UV_EN 0x1E
375 #define R511_SNAP_UV_EN 0x1E
376 #define R511_SNAP_OPTS 0x1F
378 #define R511_DRAM_FLOW_CTL 0x20
379 #define R511_FIFO_OPTS 0x31
380 #define R511_I2C_CTL 0x40
381 #define R511_SYS_LED_CTL 0x55 /* OV511+ only */
382 #define R511_COMP_EN 0x78
383 #define R511_COMP_LUT_EN 0x79
385 /* OV518 Camera interface register numbers */
386 #define R518_GPIO_OUT 0x56 /* OV518(+) only */
387 #define R518_GPIO_CTL 0x57 /* OV518(+) only */
389 /* OV519 Camera interface register numbers */
390 #define OV519_R10_H_SIZE 0x10
391 #define OV519_R11_V_SIZE 0x11
392 #define OV519_R12_X_OFFSETL 0x12
393 #define OV519_R13_X_OFFSETH 0x13
394 #define OV519_R14_Y_OFFSETL 0x14
395 #define OV519_R15_Y_OFFSETH 0x15
396 #define OV519_R16_DIVIDER 0x16
397 #define OV519_R20_DFR 0x20
398 #define OV519_R25_FORMAT 0x25
400 /* OV519 System Controller register numbers */
401 #define OV519_SYS_RESET1 0x51
402 #define OV519_SYS_EN_CLK1 0x54
404 #define OV519_GPIO_DATA_OUT0 0x71
405 #define OV519_GPIO_IO_CTRL0 0x72
407 #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
410 #define R51x_I2C_W_SID 0x41
411 #define R51x_I2C_SADDR_3 0x42
412 #define R51x_I2C_SADDR_2 0x43
413 #define R51x_I2C_R_SID 0x44
414 #define R51x_I2C_DATA 0x45
415 #define R518_I2C_CTL 0x47 /* OV518(+) only */
418 #define OV7xx0_SID 0x42
419 #define OV8xx0_SID 0xa0
420 #define OV6xx0_SID 0xc0
422 /* OV7610 registers */
423 #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
424 #define OV7610_REG_BLUE 0x01 /* blue channel balance */
425 #define OV7610_REG_RED 0x02 /* red channel balance */
426 #define OV7610_REG_SAT 0x03 /* saturation */
427 #define OV8610_REG_HUE 0x04 /* 04 reserved */
428 #define OV7610_REG_CNT 0x05 /* Y contrast */
429 #define OV7610_REG_BRT 0x06 /* Y brightness */
430 #define OV7610_REG_COM_C 0x14 /* misc common regs */
431 #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
432 #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
433 #define OV7610_REG_COM_I 0x29 /* misc settings */
435 /* OV7670 registers */
436 #define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
437 #define OV7670_REG_BLUE 0x01 /* blue gain */
438 #define OV7670_REG_RED 0x02 /* red gain */
439 #define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
440 #define OV7670_REG_COM1 0x04 /* Control 1 */
441 #define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
442 #define OV7670_REG_COM3 0x0c /* Control 3 */
443 #define OV7670_REG_COM4 0x0d /* Control 4 */
444 #define OV7670_REG_COM5 0x0e /* All "reserved" */
445 #define OV7670_REG_COM6 0x0f /* Control 6 */
446 #define OV7670_REG_AECH 0x10 /* More bits of AEC value */
447 #define OV7670_REG_CLKRC 0x11 /* Clock control */
448 #define OV7670_REG_COM7 0x12 /* Control 7 */
449 #define OV7670_COM7_FMT_VGA 0x00
450 #define OV7670_COM7_YUV 0x00 /* YUV */
451 #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
452 #define OV7670_COM7_FMT_MASK 0x38
453 #define OV7670_COM7_RESET 0x80 /* Register reset */
454 #define OV7670_REG_COM8 0x13 /* Control 8 */
455 #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
456 #define OV7670_COM8_AWB 0x02 /* White balance enable */
457 #define OV7670_COM8_AGC 0x04 /* Auto gain enable */
458 #define OV7670_COM8_BFILT 0x20 /* Band filter enable */
459 #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
460 #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
461 #define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
462 #define OV7670_REG_COM10 0x15 /* Control 10 */
463 #define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
464 #define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
465 #define OV7670_REG_VSTART 0x19 /* Vert start high bits */
466 #define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
467 #define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
468 #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
469 #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
470 #define OV7670_REG_AEW 0x24 /* AGC upper limit */
471 #define OV7670_REG_AEB 0x25 /* AGC lower limit */
472 #define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
473 #define OV7670_REG_HREF 0x32 /* HREF pieces */
474 #define OV7670_REG_TSLB 0x3a /* lots of stuff */
475 #define OV7670_REG_COM11 0x3b /* Control 11 */
476 #define OV7670_COM11_EXP 0x02
477 #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
478 #define OV7670_REG_COM12 0x3c /* Control 12 */
479 #define OV7670_REG_COM13 0x3d /* Control 13 */
480 #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
481 #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
482 #define OV7670_REG_COM14 0x3e /* Control 14 */
483 #define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
484 #define OV7670_REG_COM15 0x40 /* Control 15 */
485 #define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
486 #define OV7670_REG_COM16 0x41 /* Control 16 */
487 #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
488 #define OV7670_REG_BRIGHT 0x55 /* Brightness */
489 #define OV7670_REG_CONTRAS 0x56 /* Contrast control */
490 #define OV7670_REG_GFIX 0x69 /* Fix gain control */
491 #define OV7670_REG_RGB444 0x8c /* RGB 444 control */
492 #define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
493 #define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
494 #define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
495 #define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
496 #define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
497 #define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
498 #define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
499 #define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
500 #define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
506 struct ov_i2c_regvals
{
511 static const struct ov_i2c_regvals norm_6x20
[] = {
512 { 0x12, 0x80 }, /* reset */
515 { 0x05, 0x7f }, /* For when autoadjust is off */
517 /* The ratio of 0x0c and 0x0d controls the white point */
520 { 0x0f, 0x15 }, /* COMS */
521 { 0x10, 0x75 }, /* AEC Exposure time */
522 { 0x12, 0x24 }, /* Enable AGC */
524 /* 0x16: 0x06 helps frame stability with moving objects */
526 /* { 0x20, 0x30 }, * Aperture correction enable */
527 { 0x26, 0xb2 }, /* BLC enable */
528 /* 0x28: 0x05 Selects RGB format if RGB on */
530 { 0x2a, 0x04 }, /* Disable framerate adjust */
531 /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
533 { 0x33, 0xa0 }, /* Color Processing Parameter */
534 { 0x34, 0xd2 }, /* Max A/D range */
538 { 0x3c, 0x39 }, /* Enable AEC mode changing */
539 { 0x3c, 0x3c }, /* Change AEC mode */
540 { 0x3c, 0x24 }, /* Disable AEC mode changing */
543 /* These next two registers (0x4a, 0x4b) are undocumented.
544 * They control the color balance */
547 { 0x4d, 0xd2 }, /* This reduces noise a bit */
550 /* Do 50-53 have any effect? */
551 /* Toggle 0x12[2] off and on here? */
554 static const struct ov_i2c_regvals norm_6x30
[] = {
555 { 0x12, 0x80 }, /* Reset */
556 { 0x00, 0x1f }, /* Gain */
557 { 0x01, 0x99 }, /* Blue gain */
558 { 0x02, 0x7c }, /* Red gain */
559 { 0x03, 0xc0 }, /* Saturation */
560 { 0x05, 0x0a }, /* Contrast */
561 { 0x06, 0x95 }, /* Brightness */
562 { 0x07, 0x2d }, /* Sharpness */
565 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
568 { 0x11, 0x00 }, /* Pixel clock = fastest */
569 { 0x12, 0x24 }, /* Enable AGC and AWB */
584 { 0x23, 0xc0 }, /* Crystal circuit power level */
585 { 0x25, 0x9a }, /* Increase AEC black ratio */
586 { 0x26, 0xb2 }, /* BLC enable */
590 { 0x2a, 0x84 }, /* 60 Hz power */
591 { 0x2b, 0xa8 }, /* 60 Hz power */
593 { 0x2d, 0x95 }, /* Enable auto-brightness */
607 { 0x40, 0x00 }, /* White bal */
608 { 0x41, 0x00 }, /* White bal */
610 { 0x43, 0x3f }, /* White bal */
620 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
622 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
624 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
629 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
631 { 0x5b, 0x0f }, /* AWB chrominance levels */
635 { 0x12, 0x20 }, /* Toggle AWB */
639 /* Lawrence Glaister <lg@jfm.bc.ca> reports:
641 * Register 0x0f in the 7610 has the following effects:
643 * 0x85 (AEC method 1): Best overall, good contrast range
644 * 0x45 (AEC method 2): Very overexposed
645 * 0xa5 (spec sheet default): Ok, but the black level is
646 * shifted resulting in loss of contrast
647 * 0x05 (old driver setting): very overexposed, too much
650 static const struct ov_i2c_regvals norm_7610
[] = {
657 { 0x28, 0x24 }, /* 0c */
658 { 0x0f, 0x85 }, /* lg's setting */
680 static const struct ov_i2c_regvals norm_7620
[] = {
681 { 0x00, 0x00 }, /* gain */
682 { 0x01, 0x80 }, /* blue gain */
683 { 0x02, 0x80 }, /* red gain */
684 { 0x03, 0xc0 }, /* OV7670_REG_VREF */
707 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
746 /* 7640 and 7648. The defaults should be OK for most registers. */
747 static const struct ov_i2c_regvals norm_7640
[] = {
752 /* 7670. Defaults taken from OmniVision provided data,
753 * as provided by Jonathan Corbet of OLPC */
754 static const struct ov_i2c_regvals norm_7670
[] = {
755 { OV7670_REG_COM7
, OV7670_COM7_RESET
},
756 { OV7670_REG_TSLB
, 0x04 }, /* OV */
757 { OV7670_REG_COM7
, OV7670_COM7_FMT_VGA
}, /* VGA */
758 { OV7670_REG_CLKRC
, 0x01 },
760 * Set the hardware window. These values from OV don't entirely
761 * make sense - hstop is less than hstart. But they work...
763 { OV7670_REG_HSTART
, 0x13 },
764 { OV7670_REG_HSTOP
, 0x01 },
765 { OV7670_REG_HREF
, 0xb6 },
766 { OV7670_REG_VSTART
, 0x02 },
767 { OV7670_REG_VSTOP
, 0x7a },
768 { OV7670_REG_VREF
, 0x0a },
770 { OV7670_REG_COM3
, 0x00 },
771 { OV7670_REG_COM14
, 0x00 },
772 /* Mystery scaling numbers */
778 /* { OV7670_REG_COM10, 0x0 }, */
780 /* Gamma curve values */
798 /* AGC and AEC parameters. Note we start by disabling those features,
799 then turn them only after tweaking the values. */
800 { OV7670_REG_COM8
, OV7670_COM8_FASTAEC
801 | OV7670_COM8_AECSTEP
802 | OV7670_COM8_BFILT
},
803 { OV7670_REG_GAIN
, 0x00 },
804 { OV7670_REG_AECH
, 0x00 },
805 { OV7670_REG_COM4
, 0x40 }, /* magic reserved bit */
806 { OV7670_REG_COM9
, 0x18 }, /* 4x gain + magic rsvd bit */
807 { OV7670_REG_BD50MAX
, 0x05 },
808 { OV7670_REG_BD60MAX
, 0x07 },
809 { OV7670_REG_AEW
, 0x95 },
810 { OV7670_REG_AEB
, 0x33 },
811 { OV7670_REG_VPT
, 0xe3 },
812 { OV7670_REG_HAECC1
, 0x78 },
813 { OV7670_REG_HAECC2
, 0x68 },
814 { 0xa1, 0x03 }, /* magic */
815 { OV7670_REG_HAECC3
, 0xd8 },
816 { OV7670_REG_HAECC4
, 0xd8 },
817 { OV7670_REG_HAECC5
, 0xf0 },
818 { OV7670_REG_HAECC6
, 0x90 },
819 { OV7670_REG_HAECC7
, 0x94 },
820 { OV7670_REG_COM8
, OV7670_COM8_FASTAEC
821 | OV7670_COM8_AECSTEP
826 /* Almost all of these are magic "reserved" values. */
827 { OV7670_REG_COM5
, 0x61 },
828 { OV7670_REG_COM6
, 0x4b },
830 { OV7670_REG_MVFP
, 0x07 },
839 { OV7670_REG_COM12
, 0x78 },
842 { OV7670_REG_GFIX
, 0x00 },
858 /* More reserved magic, some of which tweaks white balance */
875 /* "9e for advance AWB" */
877 { OV7670_REG_BLUE
, 0x40 },
878 { OV7670_REG_RED
, 0x60 },
879 { OV7670_REG_COM8
, OV7670_COM8_FASTAEC
880 | OV7670_COM8_AECSTEP
886 /* Matrix coefficients */
895 { OV7670_REG_COM16
, OV7670_COM16_AWBGAIN
},
896 { OV7670_REG_EDGE
, 0x00 },
901 { OV7670_REG_COM13
, OV7670_COM13_GAMMA
906 { OV7670_REG_COM16
, 0x38 },
910 { OV7670_REG_COM11
, OV7670_COM11_EXP
|OV7670_COM11_HZAUTO
},
923 /* Extra-weird stuff. Some sort of multiplexor register */
949 static const struct ov_i2c_regvals norm_8610
[] = {
956 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
957 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
966 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
968 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
969 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
970 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
973 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
974 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
975 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
976 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
982 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
984 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
986 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
988 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
989 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
990 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
991 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
993 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
994 * maybe thats wrong */
998 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
1002 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1003 * deleting bit7 colors the first images red */
1004 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1005 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1011 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1013 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1018 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1020 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1021 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1028 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1034 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1037 static unsigned char ov7670_abs_to_sm(unsigned char v
)
1041 return (128 - v
) | 0x80;
1044 /* Write a OV519 register */
1045 static int reg_w(struct sd
*sd
, __u16 index
, __u8 value
)
1048 int req
= (sd
->bridge
<= BRIDGE_OV511PLUS
) ? 2 : 1;
1050 sd
->gspca_dev
.usb_buf
[0] = value
;
1051 ret
= usb_control_msg(sd
->gspca_dev
.dev
,
1052 usb_sndctrlpipe(sd
->gspca_dev
.dev
, 0),
1054 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1056 sd
->gspca_dev
.usb_buf
, 1, 500);
1058 PDEBUG(D_ERR
, "Write reg [%02x] %02x failed", index
, value
);
1062 /* Read from a OV519 register */
1063 /* returns: negative is error, pos or zero is data */
1064 static int reg_r(struct sd
*sd
, __u16 index
)
1067 int req
= (sd
->bridge
<= BRIDGE_OV511PLUS
) ? 3 : 1;
1069 ret
= usb_control_msg(sd
->gspca_dev
.dev
,
1070 usb_rcvctrlpipe(sd
->gspca_dev
.dev
, 0),
1072 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1073 0, index
, sd
->gspca_dev
.usb_buf
, 1, 500);
1076 ret
= sd
->gspca_dev
.usb_buf
[0];
1078 PDEBUG(D_ERR
, "Read reg [0x%02x] failed", index
);
1082 /* Read 8 values from a OV519 register */
1083 static int reg_r8(struct sd
*sd
,
1088 ret
= usb_control_msg(sd
->gspca_dev
.dev
,
1089 usb_rcvctrlpipe(sd
->gspca_dev
.dev
, 0),
1091 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1092 0, index
, sd
->gspca_dev
.usb_buf
, 8, 500);
1095 ret
= sd
->gspca_dev
.usb_buf
[0];
1097 PDEBUG(D_ERR
, "Read reg 8 [0x%02x] failed", index
);
1102 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1103 * the same position as 1's in "mask" are cleared and set to "value". Bits
1104 * that are in the same position as 0's in "mask" are preserved, regardless
1105 * of their respective state in "value".
1107 static int reg_w_mask(struct sd
*sd
,
1116 value
&= mask
; /* Enforce mask on value */
1117 ret
= reg_r(sd
, index
);
1121 oldval
= ret
& ~mask
; /* Clear the masked bits */
1122 value
|= oldval
; /* Set the desired bits */
1124 return reg_w(sd
, index
, value
);
1128 * Writes multiple (n) byte value to a single register. Only valid with certain
1129 * registers (0x30 and 0xc4 - 0xce).
1131 static int ov518_reg_w32(struct sd
*sd
, __u16 index
, u32 value
, int n
)
1135 *((u32
*)sd
->gspca_dev
.usb_buf
) = __cpu_to_le32(value
);
1137 ret
= usb_control_msg(sd
->gspca_dev
.dev
,
1138 usb_sndctrlpipe(sd
->gspca_dev
.dev
, 0),
1140 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1142 sd
->gspca_dev
.usb_buf
, n
, 500);
1144 PDEBUG(D_ERR
, "Write reg32 [%02x] %08x failed", index
, value
);
1148 static int ov511_i2c_w(struct sd
*sd
, __u8 reg
, __u8 value
)
1152 PDEBUG(D_USBO
, "i2c 0x%02x -> [0x%02x]", value
, reg
);
1154 /* Three byte write cycle */
1155 for (retries
= 6; ; ) {
1156 /* Select camera register */
1157 rc
= reg_w(sd
, R51x_I2C_SADDR_3
, reg
);
1161 /* Write "value" to I2C data port of OV511 */
1162 rc
= reg_w(sd
, R51x_I2C_DATA
, value
);
1166 /* Initiate 3-byte write cycle */
1167 rc
= reg_w(sd
, R511_I2C_CTL
, 0x01);
1172 rc
= reg_r(sd
, R511_I2C_CTL
);
1173 while (rc
> 0 && ((rc
& 1) == 0)); /* Retry until idle */
1178 if ((rc
& 2) == 0) /* Ack? */
1180 if (--retries
< 0) {
1181 PDEBUG(D_USBO
, "i2c write retries exhausted");
1189 static int ov511_i2c_r(struct sd
*sd
, __u8 reg
)
1191 int rc
, value
, retries
;
1193 /* Two byte write cycle */
1194 for (retries
= 6; ; ) {
1195 /* Select camera register */
1196 rc
= reg_w(sd
, R51x_I2C_SADDR_2
, reg
);
1200 /* Initiate 2-byte write cycle */
1201 rc
= reg_w(sd
, R511_I2C_CTL
, 0x03);
1206 rc
= reg_r(sd
, R511_I2C_CTL
);
1207 while (rc
> 0 && ((rc
& 1) == 0)); /* Retry until idle */
1212 if ((rc
& 2) == 0) /* Ack? */
1216 reg_w(sd
, R511_I2C_CTL
, 0x10);
1218 if (--retries
< 0) {
1219 PDEBUG(D_USBI
, "i2c write retries exhausted");
1224 /* Two byte read cycle */
1225 for (retries
= 6; ; ) {
1226 /* Initiate 2-byte read cycle */
1227 rc
= reg_w(sd
, R511_I2C_CTL
, 0x05);
1232 rc
= reg_r(sd
, R511_I2C_CTL
);
1233 while (rc
> 0 && ((rc
& 1) == 0)); /* Retry until idle */
1238 if ((rc
& 2) == 0) /* Ack? */
1242 rc
= reg_w(sd
, R511_I2C_CTL
, 0x10);
1246 if (--retries
< 0) {
1247 PDEBUG(D_USBI
, "i2c read retries exhausted");
1252 value
= reg_r(sd
, R51x_I2C_DATA
);
1254 PDEBUG(D_USBI
, "i2c [0x%02X] -> 0x%02X", reg
, value
);
1256 /* This is needed to make i2c_w() work */
1257 rc
= reg_w(sd
, R511_I2C_CTL
, 0x05);
1265 * The OV518 I2C I/O procedure is different, hence, this function.
1266 * This is normally only called from i2c_w(). Note that this function
1267 * always succeeds regardless of whether the sensor is present and working.
1269 static int ov518_i2c_w(struct sd
*sd
,
1275 PDEBUG(D_USBO
, "i2c 0x%02x -> [0x%02x]", value
, reg
);
1277 /* Select camera register */
1278 rc
= reg_w(sd
, R51x_I2C_SADDR_3
, reg
);
1282 /* Write "value" to I2C data port of OV511 */
1283 rc
= reg_w(sd
, R51x_I2C_DATA
, value
);
1287 /* Initiate 3-byte write cycle */
1288 rc
= reg_w(sd
, R518_I2C_CTL
, 0x01);
1292 /* wait for write complete */
1294 return reg_r8(sd
, R518_I2C_CTL
);
1298 * returns: negative is error, pos or zero is data
1300 * The OV518 I2C I/O procedure is different, hence, this function.
1301 * This is normally only called from i2c_r(). Note that this function
1302 * always succeeds regardless of whether the sensor is present and working.
1304 static int ov518_i2c_r(struct sd
*sd
, __u8 reg
)
1308 /* Select camera register */
1309 rc
= reg_w(sd
, R51x_I2C_SADDR_2
, reg
);
1313 /* Initiate 2-byte write cycle */
1314 rc
= reg_w(sd
, R518_I2C_CTL
, 0x03);
1318 /* Initiate 2-byte read cycle */
1319 rc
= reg_w(sd
, R518_I2C_CTL
, 0x05);
1322 value
= reg_r(sd
, R51x_I2C_DATA
);
1323 PDEBUG(D_USBI
, "i2c [0x%02X] -> 0x%02X", reg
, value
);
1327 static int i2c_w(struct sd
*sd
, __u8 reg
, __u8 value
)
1329 switch (sd
->bridge
) {
1331 case BRIDGE_OV511PLUS
:
1332 return ov511_i2c_w(sd
, reg
, value
);
1334 case BRIDGE_OV518PLUS
:
1336 return ov518_i2c_w(sd
, reg
, value
);
1338 return -1; /* Should never happen */
1341 static int i2c_r(struct sd
*sd
, __u8 reg
)
1343 switch (sd
->bridge
) {
1345 case BRIDGE_OV511PLUS
:
1346 return ov511_i2c_r(sd
, reg
);
1348 case BRIDGE_OV518PLUS
:
1350 return ov518_i2c_r(sd
, reg
);
1352 return -1; /* Should never happen */
1355 /* Writes bits at positions specified by mask to an I2C reg. Bits that are in
1356 * the same position as 1's in "mask" are cleared and set to "value". Bits
1357 * that are in the same position as 0's in "mask" are preserved, regardless
1358 * of their respective state in "value".
1360 static int i2c_w_mask(struct sd
*sd
,
1368 value
&= mask
; /* Enforce mask on value */
1369 rc
= i2c_r(sd
, reg
);
1372 oldval
= rc
& ~mask
; /* Clear the masked bits */
1373 value
|= oldval
; /* Set the desired bits */
1374 return i2c_w(sd
, reg
, value
);
1377 /* Temporarily stops OV511 from functioning. Must do this before changing
1378 * registers while the camera is streaming */
1379 static inline int ov51x_stop(struct sd
*sd
)
1381 PDEBUG(D_STREAM
, "stopping");
1383 switch (sd
->bridge
) {
1385 case BRIDGE_OV511PLUS
:
1386 return reg_w(sd
, R51x_SYS_RESET
, 0x3d);
1388 case BRIDGE_OV518PLUS
:
1389 return reg_w_mask(sd
, R51x_SYS_RESET
, 0x3a, 0x3a);
1391 return reg_w(sd
, OV519_SYS_RESET1
, 0x0f);
1397 /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1398 * actually stopped (for performance). */
1399 static inline int ov51x_restart(struct sd
*sd
)
1403 PDEBUG(D_STREAM
, "restarting");
1408 /* Reinitialize the stream */
1409 switch (sd
->bridge
) {
1411 case BRIDGE_OV511PLUS
:
1412 return reg_w(sd
, R51x_SYS_RESET
, 0x00);
1414 case BRIDGE_OV518PLUS
:
1415 rc
= reg_w(sd
, 0x2f, 0x80);
1418 return reg_w(sd
, R51x_SYS_RESET
, 0x00);
1420 return reg_w(sd
, OV519_SYS_RESET1
, 0x00);
1426 /* This does an initial reset of an OmniVision sensor and ensures that I2C
1427 * is synchronized. Returns <0 on failure.
1429 static int init_ov_sensor(struct sd
*sd
)
1433 /* Reset the sensor */
1434 if (i2c_w(sd
, 0x12, 0x80) < 0)
1437 /* Wait for it to initialize */
1440 for (i
= 0; i
< i2c_detect_tries
; i
++) {
1441 if (i2c_r(sd
, OV7610_REG_ID_HIGH
) == 0x7f &&
1442 i2c_r(sd
, OV7610_REG_ID_LOW
) == 0xa2) {
1443 PDEBUG(D_PROBE
, "I2C synced in %d attempt(s)", i
);
1447 /* Reset the sensor */
1448 if (i2c_w(sd
, 0x12, 0x80) < 0)
1450 /* Wait for it to initialize */
1452 /* Dummy read to sync I2C */
1453 if (i2c_r(sd
, 0x00) < 0)
1459 /* Set the read and write slave IDs. The "slave" argument is the write slave,
1460 * and the read slave will be set to (slave + 1).
1461 * This should not be called from outside the i2c I/O functions.
1462 * Sets I2C read and write slave IDs. Returns <0 for error
1464 static int ov51x_set_slave_ids(struct sd
*sd
,
1469 rc
= reg_w(sd
, R51x_I2C_W_SID
, slave
);
1472 return reg_w(sd
, R51x_I2C_R_SID
, slave
+ 1);
1475 static int write_regvals(struct sd
*sd
,
1476 const struct ov_regvals
*regvals
,
1482 rc
= reg_w(sd
, regvals
->reg
, regvals
->val
);
1490 static int write_i2c_regvals(struct sd
*sd
,
1491 const struct ov_i2c_regvals
*regvals
,
1497 rc
= i2c_w(sd
, regvals
->reg
, regvals
->val
);
1505 /****************************************************************************
1507 * OV511 and sensor configuration
1509 ***************************************************************************/
1511 /* This initializes the OV8110, OV8610 sensor. The OV8110 uses
1512 * the same register settings as the OV8610, since they are very similar.
1514 static int ov8xx0_configure(struct sd
*sd
)
1518 PDEBUG(D_PROBE
, "starting ov8xx0 configuration");
1520 /* Detect sensor (sub)type */
1521 rc
= i2c_r(sd
, OV7610_REG_COM_I
);
1523 PDEBUG(D_ERR
, "Error detecting sensor type");
1526 if ((rc
& 3) == 1) {
1527 sd
->sensor
= SEN_OV8610
;
1529 PDEBUG(D_ERR
, "Unknown image sensor version: %d", rc
& 3);
1533 /* Set sensor-specific vars */
1537 /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
1538 * the same register settings as the OV7610, since they are very similar.
1540 static int ov7xx0_configure(struct sd
*sd
)
1545 PDEBUG(D_PROBE
, "starting OV7xx0 configuration");
1547 /* Detect sensor (sub)type */
1548 rc
= i2c_r(sd
, OV7610_REG_COM_I
);
1551 * it appears to be wrongly detected as a 7610 by default */
1553 PDEBUG(D_ERR
, "Error detecting sensor type");
1556 if ((rc
& 3) == 3) {
1557 /* quick hack to make OV7670s work */
1558 high
= i2c_r(sd
, 0x0a);
1559 low
= i2c_r(sd
, 0x0b);
1560 /* info("%x, %x", high, low); */
1561 if (high
== 0x76 && low
== 0x73) {
1562 PDEBUG(D_PROBE
, "Sensor is an OV7670");
1563 sd
->sensor
= SEN_OV7670
;
1565 PDEBUG(D_PROBE
, "Sensor is an OV7610");
1566 sd
->sensor
= SEN_OV7610
;
1568 } else if ((rc
& 3) == 1) {
1569 /* I don't know what's different about the 76BE yet. */
1570 if (i2c_r(sd
, 0x15) & 1) {
1571 PDEBUG(D_PROBE
, "Sensor is an OV7620AE");
1572 sd
->sensor
= SEN_OV7620
;
1574 PDEBUG(D_PROBE
, "Sensor is an OV76BE");
1575 sd
->sensor
= SEN_OV76BE
;
1577 } else if ((rc
& 3) == 0) {
1578 /* try to read product id registers */
1579 high
= i2c_r(sd
, 0x0a);
1581 PDEBUG(D_ERR
, "Error detecting camera chip PID");
1584 low
= i2c_r(sd
, 0x0b);
1586 PDEBUG(D_ERR
, "Error detecting camera chip VER");
1592 PDEBUG(D_PROBE
, "Sensor is an OV7630/OV7635");
1594 "7630 is not supported by this driver");
1597 PDEBUG(D_PROBE
, "Sensor is an OV7645");
1598 sd
->sensor
= SEN_OV7640
; /* FIXME */
1601 PDEBUG(D_PROBE
, "Sensor is an OV7645B");
1602 sd
->sensor
= SEN_OV7640
; /* FIXME */
1605 PDEBUG(D_PROBE
, "Sensor is an OV7648");
1606 sd
->sensor
= SEN_OV7640
; /* FIXME */
1609 PDEBUG(D_PROBE
, "Unknown sensor: 0x76%x", low
);
1613 PDEBUG(D_PROBE
, "Sensor is an OV7620");
1614 sd
->sensor
= SEN_OV7620
;
1617 PDEBUG(D_ERR
, "Unknown image sensor version: %d", rc
& 3);
1621 /* Set sensor-specific vars */
1625 /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
1626 static int ov6xx0_configure(struct sd
*sd
)
1629 PDEBUG(D_PROBE
, "starting OV6xx0 configuration");
1631 /* Detect sensor (sub)type */
1632 rc
= i2c_r(sd
, OV7610_REG_COM_I
);
1634 PDEBUG(D_ERR
, "Error detecting sensor type");
1638 /* Ugh. The first two bits are the version bits, but
1639 * the entire register value must be used. I guess OVT
1640 * underestimated how many variants they would make. */
1643 sd
->sensor
= SEN_OV6630
;
1645 "WARNING: Sensor is an OV66308. Your camera may have");
1646 PDEBUG(D_ERR
, "been misdetected in previous driver versions.");
1649 sd
->sensor
= SEN_OV6620
;
1650 PDEBUG(D_PROBE
, "Sensor is an OV6620");
1653 sd
->sensor
= SEN_OV6630
;
1654 PDEBUG(D_PROBE
, "Sensor is an OV66308AE");
1657 sd
->sensor
= SEN_OV66308AF
;
1658 PDEBUG(D_PROBE
, "Sensor is an OV66308AF");
1661 sd
->sensor
= SEN_OV6630
;
1663 "WARNING: Sensor is an OV66307. Your camera may have");
1664 PDEBUG(D_ERR
, "been misdetected in previous driver versions.");
1667 PDEBUG(D_ERR
, "FATAL: Unknown sensor version: 0x%02x", rc
);
1671 /* Set sensor-specific vars */
1677 /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
1678 static void ov51x_led_control(struct sd
*sd
, int on
)
1683 switch (sd
->bridge
) {
1684 /* OV511 has no LED control */
1685 case BRIDGE_OV511PLUS
:
1686 reg_w(sd
, R511_SYS_LED_CTL
, on
? 1 : 0);
1689 case BRIDGE_OV518PLUS
:
1690 reg_w_mask(sd
, R518_GPIO_OUT
, on
? 0x02 : 0x00, 0x02);
1693 reg_w_mask(sd
, OV519_GPIO_DATA_OUT0
, !on
, 1); /* 0 / 1 */
1698 static int ov51x_upload_quan_tables(struct sd
*sd
)
1700 const unsigned char yQuanTable511
[] = {
1701 0, 1, 1, 2, 2, 3, 3, 4,
1702 1, 1, 1, 2, 2, 3, 4, 4,
1703 1, 1, 2, 2, 3, 4, 4, 4,
1704 2, 2, 2, 3, 4, 4, 4, 4,
1705 2, 2, 3, 4, 4, 5, 5, 5,
1706 3, 3, 4, 4, 5, 5, 5, 5,
1707 3, 4, 4, 4, 5, 5, 5, 5,
1708 4, 4, 4, 4, 5, 5, 5, 5
1711 const unsigned char uvQuanTable511
[] = {
1712 0, 2, 2, 3, 4, 4, 4, 4,
1713 2, 2, 2, 4, 4, 4, 4, 4,
1714 2, 2, 3, 4, 4, 4, 4, 4,
1715 3, 4, 4, 4, 4, 4, 4, 4,
1716 4, 4, 4, 4, 4, 4, 4, 4,
1717 4, 4, 4, 4, 4, 4, 4, 4,
1718 4, 4, 4, 4, 4, 4, 4, 4,
1719 4, 4, 4, 4, 4, 4, 4, 4
1722 /* OV518 quantization tables are 8x4 (instead of 8x8) */
1723 const unsigned char yQuanTable518
[] = {
1724 5, 4, 5, 6, 6, 7, 7, 7,
1725 5, 5, 5, 5, 6, 7, 7, 7,
1726 6, 6, 6, 6, 7, 7, 7, 8,
1727 7, 7, 6, 7, 7, 7, 8, 8
1730 const unsigned char uvQuanTable518
[] = {
1731 6, 6, 6, 7, 7, 7, 7, 7,
1732 6, 6, 6, 7, 7, 7, 7, 7,
1733 6, 6, 6, 7, 7, 7, 7, 8,
1734 7, 7, 7, 7, 7, 7, 8, 8
1737 const unsigned char *pYTable
, *pUVTable
;
1738 unsigned char val0
, val1
;
1739 int i
, size
, rc
, reg
= R51x_COMP_LUT_BEGIN
;
1741 PDEBUG(D_PROBE
, "Uploading quantization tables");
1743 if (sd
->bridge
== BRIDGE_OV511
|| sd
->bridge
== BRIDGE_OV511PLUS
) {
1744 pYTable
= yQuanTable511
;
1745 pUVTable
= uvQuanTable511
;
1748 pYTable
= yQuanTable518
;
1749 pUVTable
= uvQuanTable518
;
1753 for (i
= 0; i
< size
; i
++) {
1759 rc
= reg_w(sd
, reg
, val0
);
1768 rc
= reg_w(sd
, reg
+ size
, val0
);
1778 /* This initializes the OV511/OV511+ and the sensor */
1779 static int ov511_configure(struct gspca_dev
*gspca_dev
)
1781 struct sd
*sd
= (struct sd
*) gspca_dev
;
1784 /* For 511 and 511+ */
1785 const struct ov_regvals init_511
[] = {
1786 { R51x_SYS_RESET
, 0x7f },
1787 { R51x_SYS_INIT
, 0x01 },
1788 { R51x_SYS_RESET
, 0x7f },
1789 { R51x_SYS_INIT
, 0x01 },
1790 { R51x_SYS_RESET
, 0x3f },
1791 { R51x_SYS_INIT
, 0x01 },
1792 { R51x_SYS_RESET
, 0x3d },
1795 const struct ov_regvals norm_511
[] = {
1796 { R511_DRAM_FLOW_CTL
, 0x01 },
1797 { R51x_SYS_SNAP
, 0x00 },
1798 { R51x_SYS_SNAP
, 0x02 },
1799 { R51x_SYS_SNAP
, 0x00 },
1800 { R511_FIFO_OPTS
, 0x1f },
1801 { R511_COMP_EN
, 0x00 },
1802 { R511_COMP_LUT_EN
, 0x03 },
1805 const struct ov_regvals norm_511_p
[] = {
1806 { R511_DRAM_FLOW_CTL
, 0xff },
1807 { R51x_SYS_SNAP
, 0x00 },
1808 { R51x_SYS_SNAP
, 0x02 },
1809 { R51x_SYS_SNAP
, 0x00 },
1810 { R511_FIFO_OPTS
, 0xff },
1811 { R511_COMP_EN
, 0x00 },
1812 { R511_COMP_LUT_EN
, 0x03 },
1815 const struct ov_regvals compress_511
[] = {
1826 PDEBUG(D_PROBE
, "Device custom id %x", reg_r(sd
, R51x_SYS_CUST_ID
));
1828 rc
= write_regvals(sd
, init_511
, ARRAY_SIZE(init_511
));
1832 switch (sd
->bridge
) {
1834 rc
= write_regvals(sd
, norm_511
, ARRAY_SIZE(norm_511
));
1838 case BRIDGE_OV511PLUS
:
1839 rc
= write_regvals(sd
, norm_511_p
, ARRAY_SIZE(norm_511_p
));
1845 /* Init compression */
1846 rc
= write_regvals(sd
, compress_511
, ARRAY_SIZE(compress_511
));
1850 rc
= ov51x_upload_quan_tables(sd
);
1852 PDEBUG(D_ERR
, "Error uploading quantization tables");
1859 /* This initializes the OV518/OV518+ and the sensor */
1860 static int ov518_configure(struct gspca_dev
*gspca_dev
)
1862 struct sd
*sd
= (struct sd
*) gspca_dev
;
1865 /* For 518 and 518+ */
1866 const struct ov_regvals init_518
[] = {
1867 { R51x_SYS_RESET
, 0x40 },
1868 { R51x_SYS_INIT
, 0xe1 },
1869 { R51x_SYS_RESET
, 0x3e },
1870 { R51x_SYS_INIT
, 0xe1 },
1871 { R51x_SYS_RESET
, 0x00 },
1872 { R51x_SYS_INIT
, 0xe1 },
1877 const struct ov_regvals norm_518
[] = {
1878 { R51x_SYS_SNAP
, 0x02 }, /* Reset */
1879 { R51x_SYS_SNAP
, 0x01 }, /* Enable */
1890 const struct ov_regvals norm_518_p
[] = {
1891 { R51x_SYS_SNAP
, 0x02 }, /* Reset */
1892 { R51x_SYS_SNAP
, 0x01 }, /* Enable */
1909 /* First 5 bits of custom ID reg are a revision ID on OV518 */
1910 PDEBUG(D_PROBE
, "Device revision %d",
1911 0x1F & reg_r(sd
, R51x_SYS_CUST_ID
));
1913 rc
= write_regvals(sd
, init_518
, ARRAY_SIZE(init_518
));
1917 /* Set LED GPIO pin to output mode */
1918 rc
= reg_w_mask(sd
, R518_GPIO_CTL
, 0x00, 0x02);
1922 switch (sd
->bridge
) {
1924 rc
= write_regvals(sd
, norm_518
, ARRAY_SIZE(norm_518
));
1928 case BRIDGE_OV518PLUS
:
1929 rc
= write_regvals(sd
, norm_518_p
, ARRAY_SIZE(norm_518_p
));
1935 rc
= ov51x_upload_quan_tables(sd
);
1937 PDEBUG(D_ERR
, "Error uploading quantization tables");
1941 rc
= reg_w(sd
, 0x2f, 0x80);
1948 static int ov519_configure(struct sd
*sd
)
1950 static const struct ov_regvals init_519
[] = {
1951 { 0x5a, 0x6d }, /* EnableSystem */
1953 { 0x54, 0xff }, /* set bit2 to enable jpeg */
1957 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
1958 * detection will fail. This deserves further investigation. */
1959 { OV519_GPIO_IO_CTRL0
, 0xee },
1960 { 0x51, 0x0f }, /* SetUsbInit */
1963 /* windows reads 0x55 at this point*/
1966 return write_regvals(sd
, init_519
, ARRAY_SIZE(init_519
));
1969 /* this function is called at probe time */
1970 static int sd_config(struct gspca_dev
*gspca_dev
,
1971 const struct usb_device_id
*id
)
1973 struct sd
*sd
= (struct sd
*) gspca_dev
;
1977 sd
->bridge
= id
->driver_info
& BRIDGE_MASK
;
1978 sd
->invert_led
= id
->driver_info
& BRIDGE_INVERT_LED
;
1980 switch (sd
->bridge
) {
1982 case BRIDGE_OV511PLUS
:
1983 ret
= ov511_configure(gspca_dev
);
1986 case BRIDGE_OV518PLUS
:
1987 ret
= ov518_configure(gspca_dev
);
1990 ret
= ov519_configure(sd
);
1997 ov51x_led_control(sd
, 0); /* turn LED off */
2000 if (ov51x_set_slave_ids(sd
, OV7xx0_SID
) < 0)
2003 /* The OV519 must be more aggressive about sensor detection since
2004 * I2C write will never fail if the sensor is not present. We have
2005 * to try to initialize the sensor to detect its presence */
2006 if (init_ov_sensor(sd
) >= 0) {
2007 if (ov7xx0_configure(sd
) < 0) {
2008 PDEBUG(D_ERR
, "Failed to configure OV7xx0");
2014 if (ov51x_set_slave_ids(sd
, OV6xx0_SID
) < 0)
2017 if (init_ov_sensor(sd
) >= 0) {
2018 if (ov6xx0_configure(sd
) < 0) {
2019 PDEBUG(D_ERR
, "Failed to configure OV6xx0");
2025 if (ov51x_set_slave_ids(sd
, OV8xx0_SID
) < 0)
2028 if (init_ov_sensor(sd
) < 0) {
2030 "Can't determine sensor slave IDs");
2033 if (ov8xx0_configure(sd
) < 0) {
2035 "Failed to configure OV8xx0 sensor");
2041 cam
= &gspca_dev
->cam
;
2042 switch (sd
->bridge
) {
2044 case BRIDGE_OV511PLUS
:
2046 cam
->cam_mode
= ov511_vga_mode
;
2047 cam
->nmodes
= ARRAY_SIZE(ov511_vga_mode
);
2049 cam
->cam_mode
= ov511_sif_mode
;
2050 cam
->nmodes
= ARRAY_SIZE(ov511_sif_mode
);
2054 case BRIDGE_OV518PLUS
:
2056 cam
->cam_mode
= ov518_vga_mode
;
2057 cam
->nmodes
= ARRAY_SIZE(ov518_vga_mode
);
2059 cam
->cam_mode
= ov518_sif_mode
;
2060 cam
->nmodes
= ARRAY_SIZE(ov518_sif_mode
);
2065 cam
->cam_mode
= ov519_vga_mode
;
2066 cam
->nmodes
= ARRAY_SIZE(ov519_vga_mode
);
2068 cam
->cam_mode
= ov519_sif_mode
;
2069 cam
->nmodes
= ARRAY_SIZE(ov519_sif_mode
);
2073 sd
->brightness
= BRIGHTNESS_DEF
;
2074 if (sd
->sensor
== SEN_OV6630
|| sd
->sensor
== SEN_OV66308AF
)
2075 sd
->contrast
= 200; /* The default is too low for the ov6630 */
2077 sd
->contrast
= CONTRAST_DEF
;
2078 sd
->colors
= COLOR_DEF
;
2079 sd
->hflip
= HFLIP_DEF
;
2080 sd
->vflip
= VFLIP_DEF
;
2081 sd
->autobrightness
= AUTOBRIGHT_DEF
;
2082 if (sd
->sensor
== SEN_OV7670
) {
2083 sd
->freq
= OV7670_FREQ_DEF
;
2084 gspca_dev
->ctrl_dis
= 1 << FREQ_IDX
;
2086 sd
->freq
= FREQ_DEF
;
2087 gspca_dev
->ctrl_dis
= (1 << HFLIP_IDX
) | (1 << VFLIP_IDX
) |
2088 (1 << OV7670_FREQ_IDX
);
2090 if (sd
->sensor
== SEN_OV7640
|| sd
->sensor
== SEN_OV7670
)
2091 gspca_dev
->ctrl_dis
|= 1 << AUTOBRIGHT_IDX
;
2092 /* OV8610 Frequency filter control should work but needs testing */
2093 if (sd
->sensor
== SEN_OV8610
)
2094 gspca_dev
->ctrl_dis
|= 1 << FREQ_IDX
;
2098 PDEBUG(D_ERR
, "OV519 Config failed");
2102 /* this function is called at probe and resume time */
2103 static int sd_init(struct gspca_dev
*gspca_dev
)
2105 struct sd
*sd
= (struct sd
*) gspca_dev
;
2107 /* initialize the sensor */
2108 switch (sd
->sensor
) {
2110 if (write_i2c_regvals(sd
, norm_6x20
, ARRAY_SIZE(norm_6x20
)))
2115 if (write_i2c_regvals(sd
, norm_6x30
, ARRAY_SIZE(norm_6x30
)))
2119 /* case SEN_OV7610: */
2120 /* case SEN_OV76BE: */
2121 if (write_i2c_regvals(sd
, norm_7610
, ARRAY_SIZE(norm_7610
)))
2123 if (i2c_w_mask(sd
, 0x0e, 0x00, 0x40))
2127 if (write_i2c_regvals(sd
, norm_7620
, ARRAY_SIZE(norm_7620
)))
2131 if (write_i2c_regvals(sd
, norm_7640
, ARRAY_SIZE(norm_7640
)))
2135 if (write_i2c_regvals(sd
, norm_7670
, ARRAY_SIZE(norm_7670
)))
2139 if (write_i2c_regvals(sd
, norm_8610
, ARRAY_SIZE(norm_8610
)))
2146 /* Set up the OV511/OV511+ with the given image parameters.
2148 * Do not put any sensor-specific code in here (including I2C I/O functions)
2150 static int ov511_mode_init_regs(struct sd
*sd
)
2152 int hsegs
, vsegs
, packet_size
, fps
, needed
;
2154 struct usb_host_interface
*alt
;
2155 struct usb_interface
*intf
;
2157 intf
= usb_ifnum_to_if(sd
->gspca_dev
.dev
, sd
->gspca_dev
.iface
);
2158 alt
= usb_altnum_to_altsetting(intf
, sd
->gspca_dev
.alt
);
2160 PDEBUG(D_ERR
, "Couldn't get altsetting");
2164 packet_size
= le16_to_cpu(alt
->endpoint
[0].desc
.wMaxPacketSize
);
2165 reg_w(sd
, R51x_FIFO_PSIZE
, packet_size
>> 5);
2167 reg_w(sd
, R511_CAM_UV_EN
, 0x01);
2168 reg_w(sd
, R511_SNAP_UV_EN
, 0x01);
2169 reg_w(sd
, R511_SNAP_OPTS
, 0x03);
2171 /* Here I'm assuming that snapshot size == image size.
2172 * I hope that's always true. --claudio
2174 hsegs
= (sd
->gspca_dev
.width
>> 3) - 1;
2175 vsegs
= (sd
->gspca_dev
.height
>> 3) - 1;
2177 reg_w(sd
, R511_CAM_PXCNT
, hsegs
);
2178 reg_w(sd
, R511_CAM_LNCNT
, vsegs
);
2179 reg_w(sd
, R511_CAM_PXDIV
, 0x00);
2180 reg_w(sd
, R511_CAM_LNDIV
, 0x00);
2182 /* YUV420, low pass filter on */
2183 reg_w(sd
, R511_CAM_OPTS
, 0x03);
2185 /* Snapshot additions */
2186 reg_w(sd
, R511_SNAP_PXCNT
, hsegs
);
2187 reg_w(sd
, R511_SNAP_LNCNT
, vsegs
);
2188 reg_w(sd
, R511_SNAP_PXDIV
, 0x00);
2189 reg_w(sd
, R511_SNAP_LNDIV
, 0x00);
2191 /******** Set the framerate ********/
2193 sd
->frame_rate
= frame_rate
;
2195 switch (sd
->sensor
) {
2197 /* No framerate control, doesn't like higher rates yet */
2201 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
2202 for more sensors we need to do this for them too */
2206 if (sd
->gspca_dev
.width
== 320)
2212 switch (sd
->frame_rate
) {
2215 /* Not enough bandwidth to do 640x480 @ 30 fps */
2216 if (sd
->gspca_dev
.width
!= 640) {
2220 /* Fall through for 640x480 case */
2234 sd
->clockdiv
= (sd
->clockdiv
+ 1) * 2 - 1;
2235 /* Higher then 10 does not work */
2236 if (sd
->clockdiv
> 10)
2242 /* No framerate control ?? */
2247 /* Check if we have enough bandwidth to disable compression */
2248 fps
= (interlaced
? 60 : 30) / (sd
->clockdiv
+ 1) + 1;
2249 needed
= fps
* sd
->gspca_dev
.width
* sd
->gspca_dev
.height
* 3 / 2;
2250 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
2251 if (needed
> 1400 * packet_size
) {
2252 /* Enable Y and UV quantization and compression */
2253 reg_w(sd
, R511_COMP_EN
, 0x07);
2254 reg_w(sd
, R511_COMP_LUT_EN
, 0x03);
2256 reg_w(sd
, R511_COMP_EN
, 0x06);
2257 reg_w(sd
, R511_COMP_LUT_EN
, 0x00);
2260 reg_w(sd
, R51x_SYS_RESET
, OV511_RESET_OMNICE
);
2261 reg_w(sd
, R51x_SYS_RESET
, 0);
2266 /* Sets up the OV518/OV518+ with the given image parameters
2268 * OV518 needs a completely different approach, until we can figure out what
2269 * the individual registers do. Also, only 15 FPS is supported now.
2271 * Do not put any sensor-specific code in here (including I2C I/O functions)
2273 static int ov518_mode_init_regs(struct sd
*sd
)
2275 int hsegs
, vsegs
, packet_size
;
2276 struct usb_host_interface
*alt
;
2277 struct usb_interface
*intf
;
2279 intf
= usb_ifnum_to_if(sd
->gspca_dev
.dev
, sd
->gspca_dev
.iface
);
2280 alt
= usb_altnum_to_altsetting(intf
, sd
->gspca_dev
.alt
);
2282 PDEBUG(D_ERR
, "Couldn't get altsetting");
2286 packet_size
= le16_to_cpu(alt
->endpoint
[0].desc
.wMaxPacketSize
);
2287 ov518_reg_w32(sd
, R51x_FIFO_PSIZE
, packet_size
& ~7, 2);
2289 /******** Set the mode ********/
2300 if (sd
->bridge
== BRIDGE_OV518
) {
2301 /* Set 8-bit (YVYU) input format */
2302 reg_w_mask(sd
, 0x20, 0x08, 0x08);
2304 /* Set 12-bit (4:2:0) output format */
2305 reg_w_mask(sd
, 0x28, 0x80, 0xf0);
2306 reg_w_mask(sd
, 0x38, 0x80, 0xf0);
2308 reg_w(sd
, 0x28, 0x80);
2309 reg_w(sd
, 0x38, 0x80);
2312 hsegs
= sd
->gspca_dev
.width
/ 16;
2313 vsegs
= sd
->gspca_dev
.height
/ 4;
2315 reg_w(sd
, 0x29, hsegs
);
2316 reg_w(sd
, 0x2a, vsegs
);
2318 reg_w(sd
, 0x39, hsegs
);
2319 reg_w(sd
, 0x3a, vsegs
);
2321 /* Windows driver does this here; who knows why */
2322 reg_w(sd
, 0x2f, 0x80);
2324 /******** Set the framerate ********/
2327 /* Mode independent, but framerate dependent, regs */
2328 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
2329 reg_w(sd
, 0x51, 0x04);
2330 reg_w(sd
, 0x22, 0x18);
2331 reg_w(sd
, 0x23, 0xff);
2333 if (sd
->bridge
== BRIDGE_OV518PLUS
) {
2334 switch (sd
->sensor
) {
2336 if (sd
->gspca_dev
.width
== 320) {
2337 reg_w(sd
, 0x20, 0x00);
2338 reg_w(sd
, 0x21, 0x19);
2340 reg_w(sd
, 0x20, 0x60);
2341 reg_w(sd
, 0x21, 0x1f);
2345 reg_w(sd
, 0x21, 0x19);
2348 reg_w(sd
, 0x71, 0x17); /* Compression-related? */
2350 /* FIXME: Sensor-specific */
2351 /* Bit 5 is what matters here. Of course, it is "reserved" */
2352 i2c_w(sd
, 0x54, 0x23);
2354 reg_w(sd
, 0x2f, 0x80);
2356 if (sd
->bridge
== BRIDGE_OV518PLUS
) {
2357 reg_w(sd
, 0x24, 0x94);
2358 reg_w(sd
, 0x25, 0x90);
2359 ov518_reg_w32(sd
, 0xc4, 400, 2); /* 190h */
2360 ov518_reg_w32(sd
, 0xc6, 540, 2); /* 21ch */
2361 ov518_reg_w32(sd
, 0xc7, 540, 2); /* 21ch */
2362 ov518_reg_w32(sd
, 0xc8, 108, 2); /* 6ch */
2363 ov518_reg_w32(sd
, 0xca, 131098, 3); /* 2001ah */
2364 ov518_reg_w32(sd
, 0xcb, 532, 2); /* 214h */
2365 ov518_reg_w32(sd
, 0xcc, 2400, 2); /* 960h */
2366 ov518_reg_w32(sd
, 0xcd, 32, 2); /* 20h */
2367 ov518_reg_w32(sd
, 0xce, 608, 2); /* 260h */
2369 reg_w(sd
, 0x24, 0x9f);
2370 reg_w(sd
, 0x25, 0x90);
2371 ov518_reg_w32(sd
, 0xc4, 400, 2); /* 190h */
2372 ov518_reg_w32(sd
, 0xc6, 381, 2); /* 17dh */
2373 ov518_reg_w32(sd
, 0xc7, 381, 2); /* 17dh */
2374 ov518_reg_w32(sd
, 0xc8, 128, 2); /* 80h */
2375 ov518_reg_w32(sd
, 0xca, 183331, 3); /* 2cc23h */
2376 ov518_reg_w32(sd
, 0xcb, 746, 2); /* 2eah */
2377 ov518_reg_w32(sd
, 0xcc, 1750, 2); /* 6d6h */
2378 ov518_reg_w32(sd
, 0xcd, 45, 2); /* 2dh */
2379 ov518_reg_w32(sd
, 0xce, 851, 2); /* 353h */
2382 reg_w(sd
, 0x2f, 0x80);
2388 /* Sets up the OV519 with the given image parameters
2390 * OV519 needs a completely different approach, until we can figure out what
2391 * the individual registers do.
2393 * Do not put any sensor-specific code in here (including I2C I/O functions)
2395 static int ov519_mode_init_regs(struct sd
*sd
)
2397 static const struct ov_regvals mode_init_519_ov7670
[] = {
2398 { 0x5d, 0x03 }, /* Turn off suspend mode */
2399 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
2400 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
2401 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
2405 { 0x37, 0x00 }, /* SetUsbInit */
2406 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
2407 /* Enable both fields, YUV Input, disable defect comp (why?) */
2411 { 0x17, 0x50 }, /* undocumented */
2412 { 0x37, 0x00 }, /* undocumented */
2413 { 0x40, 0xff }, /* I2C timeout counter */
2414 { 0x46, 0x00 }, /* I2C clock prescaler */
2415 { 0x59, 0x04 }, /* new from windrv 090403 */
2416 { 0xff, 0x00 }, /* undocumented */
2417 /* windows reads 0x55 at this point, why? */
2420 static const struct ov_regvals mode_init_519
[] = {
2421 { 0x5d, 0x03 }, /* Turn off suspend mode */
2422 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
2423 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
2424 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
2428 { 0x37, 0x00 }, /* SetUsbInit */
2429 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
2430 /* Enable both fields, YUV Input, disable defect comp (why?) */
2432 { 0x17, 0x50 }, /* undocumented */
2433 { 0x37, 0x00 }, /* undocumented */
2434 { 0x40, 0xff }, /* I2C timeout counter */
2435 { 0x46, 0x00 }, /* I2C clock prescaler */
2436 { 0x59, 0x04 }, /* new from windrv 090403 */
2437 { 0xff, 0x00 }, /* undocumented */
2438 /* windows reads 0x55 at this point, why? */
2441 /******** Set the mode ********/
2442 if (sd
->sensor
!= SEN_OV7670
) {
2443 if (write_regvals(sd
, mode_init_519
,
2444 ARRAY_SIZE(mode_init_519
)))
2446 if (sd
->sensor
== SEN_OV7640
) {
2447 /* Select 8-bit input mode */
2448 reg_w_mask(sd
, OV519_R20_DFR
, 0x10, 0x10);
2451 if (write_regvals(sd
, mode_init_519_ov7670
,
2452 ARRAY_SIZE(mode_init_519_ov7670
)))
2456 reg_w(sd
, OV519_R10_H_SIZE
, sd
->gspca_dev
.width
>> 4);
2457 reg_w(sd
, OV519_R11_V_SIZE
, sd
->gspca_dev
.height
>> 3);
2458 if (sd
->sensor
== SEN_OV7670
&&
2459 sd
->gspca_dev
.cam
.cam_mode
[sd
->gspca_dev
.curr_mode
].priv
)
2460 reg_w(sd
, OV519_R12_X_OFFSETL
, 0x04);
2462 reg_w(sd
, OV519_R12_X_OFFSETL
, 0x00);
2463 reg_w(sd
, OV519_R13_X_OFFSETH
, 0x00);
2464 reg_w(sd
, OV519_R14_Y_OFFSETL
, 0x00);
2465 reg_w(sd
, OV519_R15_Y_OFFSETH
, 0x00);
2466 reg_w(sd
, OV519_R16_DIVIDER
, 0x00);
2467 reg_w(sd
, OV519_R25_FORMAT
, 0x03); /* YUV422 */
2468 reg_w(sd
, 0x26, 0x00); /* Undocumented */
2470 /******** Set the framerate ********/
2472 sd
->frame_rate
= frame_rate
;
2474 /* FIXME: These are only valid at the max resolution. */
2476 switch (sd
->sensor
) {
2478 switch (sd
->frame_rate
) {
2481 reg_w(sd
, 0xa4, 0x0c);
2482 reg_w(sd
, 0x23, 0xff);
2485 reg_w(sd
, 0xa4, 0x0c);
2486 reg_w(sd
, 0x23, 0x1f);
2489 reg_w(sd
, 0xa4, 0x0c);
2490 reg_w(sd
, 0x23, 0x1b);
2493 reg_w(sd
, 0xa4, 0x04);
2494 reg_w(sd
, 0x23, 0xff);
2498 reg_w(sd
, 0xa4, 0x04);
2499 reg_w(sd
, 0x23, 0x1f);
2503 reg_w(sd
, 0xa4, 0x04);
2504 reg_w(sd
, 0x23, 0x1b);
2510 switch (sd
->frame_rate
) {
2511 default: /* 15 fps */
2513 reg_w(sd
, 0xa4, 0x06);
2514 reg_w(sd
, 0x23, 0xff);
2517 reg_w(sd
, 0xa4, 0x06);
2518 reg_w(sd
, 0x23, 0x1f);
2521 reg_w(sd
, 0xa4, 0x06);
2522 reg_w(sd
, 0x23, 0x1b);
2526 case SEN_OV7670
: /* guesses, based on 7640 */
2527 PDEBUG(D_STREAM
, "Setting framerate to %d fps",
2528 (sd
->frame_rate
== 0) ? 15 : sd
->frame_rate
);
2529 reg_w(sd
, 0xa4, 0x10);
2530 switch (sd
->frame_rate
) {
2532 reg_w(sd
, 0x23, 0xff);
2535 reg_w(sd
, 0x23, 0x1b);
2539 reg_w(sd
, 0x23, 0xff);
2548 static int mode_init_ov_sensor_regs(struct sd
*sd
)
2550 struct gspca_dev
*gspca_dev
;
2553 gspca_dev
= &sd
->gspca_dev
;
2554 qvga
= gspca_dev
->cam
.cam_mode
[(int) gspca_dev
->curr_mode
].priv
& 1;
2556 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2557 switch (sd
->sensor
) {
2559 /* For OV8610 qvga means qsvga */
2560 i2c_w_mask(sd
, OV7610_REG_COM_C
, qvga
? (1 << 5) : 0, 1 << 5);
2563 i2c_w_mask(sd
, 0x14, qvga
? 0x20 : 0x00, 0x20);
2567 i2c_w_mask(sd
, 0x14, qvga
? 0x20 : 0x00, 0x20);
2568 i2c_w_mask(sd
, 0x28, qvga
? 0x00 : 0x20, 0x20);
2569 i2c_w(sd
, 0x24, qvga
? 0x20 : 0x3a);
2570 i2c_w(sd
, 0x25, qvga
? 0x30 : 0x60);
2571 i2c_w_mask(sd
, 0x2d, qvga
? 0x40 : 0x00, 0x40);
2572 i2c_w_mask(sd
, 0x67, qvga
? 0xb0 : 0x90, 0xf0);
2573 i2c_w_mask(sd
, 0x74, qvga
? 0x20 : 0x00, 0x20);
2576 i2c_w_mask(sd
, 0x14, qvga
? 0x20 : 0x00, 0x20);
2577 i2c_w_mask(sd
, 0x28, qvga
? 0x00 : 0x20, 0x20);
2578 /* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
2579 /* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
2580 /* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
2581 /* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
2582 /* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
2585 /* set COM7_FMT_VGA or COM7_FMT_QVGA
2586 * do we need to set anything else?
2587 * HSTART etc are set in set_ov_sensor_window itself */
2588 i2c_w_mask(sd
, OV7670_REG_COM7
,
2589 qvga
? OV7670_COM7_FMT_QVGA
: OV7670_COM7_FMT_VGA
,
2590 OV7670_COM7_FMT_MASK
);
2595 i2c_w_mask(sd
, 0x14, qvga
? 0x20 : 0x00, 0x20);
2601 /******** Palette-specific regs ********/
2603 /* The OV518 needs special treatment. Although both the OV518
2604 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2605 * bus is actually used. The UV bus is tied to ground.
2606 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2609 /* OV7640 is 8-bit only */
2611 if (sd
->sensor
!= SEN_OV6630
&& sd
->sensor
!= SEN_OV66308AF
&&
2612 sd
->sensor
!= SEN_OV7640
)
2613 i2c_w_mask(sd
, 0x13, 0x00, 0x20);
2615 /******** Clock programming ********/
2616 i2c_w(sd
, 0x11, sd
->clockdiv
);
2618 /******** Special Features ********/
2619 /* no evidence this is possible with OV7670, either */
2621 if (sd
->sensor
!= SEN_OV7640
&& sd
->sensor
!= SEN_OV7670
)
2622 i2c_w_mask(sd
, 0x12, 0x00, 0x02);
2624 /* Enable auto white balance */
2625 if (sd
->sensor
== SEN_OV7670
)
2626 i2c_w_mask(sd
, OV7670_REG_COM8
, OV7670_COM8_AWB
,
2629 i2c_w_mask(sd
, 0x12, 0x04, 0x04);
2631 /* This will go away as soon as ov51x_mode_init_sensor_regs() */
2632 /* is fully tested. */
2633 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2634 if (sd
->sensor
== SEN_OV7610
|| sd
->sensor
== SEN_OV76BE
) {
2636 i2c_w(sd
, 0x35, 0x9e);
2638 i2c_w(sd
, 0x35, 0x1e);
2643 static void sethvflip(struct sd
*sd
)
2645 if (sd
->sensor
!= SEN_OV7670
)
2647 if (sd
->gspca_dev
.streaming
)
2649 i2c_w_mask(sd
, OV7670_REG_MVFP
,
2650 OV7670_MVFP_MIRROR
* sd
->hflip
2651 | OV7670_MVFP_VFLIP
* sd
->vflip
,
2652 OV7670_MVFP_MIRROR
| OV7670_MVFP_VFLIP
);
2653 if (sd
->gspca_dev
.streaming
)
2657 static int set_ov_sensor_window(struct sd
*sd
)
2659 struct gspca_dev
*gspca_dev
;
2661 int hwsbase
, hwebase
, vwsbase
, vwebase
, hwscale
, vwscale
;
2662 int ret
, hstart
, hstop
, vstop
, vstart
;
2665 gspca_dev
= &sd
->gspca_dev
;
2666 qvga
= gspca_dev
->cam
.cam_mode
[(int) gspca_dev
->curr_mode
].priv
& 1;
2667 crop
= gspca_dev
->cam
.cam_mode
[(int) gspca_dev
->curr_mode
].priv
& 2;
2669 /* The different sensor ICs handle setting up of window differently.
2670 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
2671 switch (sd
->sensor
) {
2682 vwsbase
= vwebase
= 0x05;
2691 if (sd
->sensor
== SEN_OV66308AF
&& qvga
)
2692 /* HDG: this fixes U and V getting swapped */
2702 hwsbase
= 0x2f; /* From 7620.SET (spec is wrong) */
2704 vwsbase
= vwebase
= 0x05;
2709 vwsbase
= vwebase
= 0x03;
2712 /*handling of OV7670 hardware sensor start and stop values
2713 * is very odd, compared to the other OV sensors */
2714 vwsbase
= vwebase
= hwebase
= hwsbase
= 0x00;
2720 switch (sd
->sensor
) {
2724 if (qvga
) { /* QCIF */
2729 vwscale
= 1; /* The datasheet says 0;
2734 if (qvga
) { /* QSVGA */
2742 default: /* SEN_OV7xx0 */
2743 if (qvga
) { /* QVGA */
2752 ret
= mode_init_ov_sensor_regs(sd
);
2756 if (sd
->sensor
== SEN_OV8610
) {
2757 i2c_w_mask(sd
, 0x2d, 0x05, 0x40);
2758 /* old 0x95, new 0x05 from windrv 090403 */
2759 /* bits 5-7: reserved */
2760 i2c_w_mask(sd
, 0x28, 0x20, 0x20);
2761 /* bit 5: progressive mode on */
2764 /* The below is wrong for OV7670s because their window registers
2765 * only store the high bits in 0x17 to 0x1a */
2767 /* SRH Use sd->max values instead of requested win values */
2768 /* SCS Since we're sticking with only the max hardware widths
2769 * for a given mode */
2770 /* I can hard code this for OV7670s */
2771 /* Yes, these numbers do look odd, but they're tested and work! */
2772 if (sd
->sensor
== SEN_OV7670
) {
2773 if (qvga
) { /* QVGA from ov7670.c by
2774 * Jonathan Corbet */
2785 /* OV7670 hardware window registers are split across
2786 * multiple locations */
2787 i2c_w(sd
, OV7670_REG_HSTART
, hstart
>> 3);
2788 i2c_w(sd
, OV7670_REG_HSTOP
, hstop
>> 3);
2789 v
= i2c_r(sd
, OV7670_REG_HREF
);
2790 v
= (v
& 0xc0) | ((hstop
& 0x7) << 3) | (hstart
& 0x07);
2791 msleep(10); /* need to sleep between read and write to
2793 i2c_w(sd
, OV7670_REG_HREF
, v
);
2795 i2c_w(sd
, OV7670_REG_VSTART
, vstart
>> 2);
2796 i2c_w(sd
, OV7670_REG_VSTOP
, vstop
>> 2);
2797 v
= i2c_r(sd
, OV7670_REG_VREF
);
2798 v
= (v
& 0xc0) | ((vstop
& 0x3) << 2) | (vstart
& 0x03);
2799 msleep(10); /* need to sleep between read and write to
2801 i2c_w(sd
, OV7670_REG_VREF
, v
);
2803 i2c_w(sd
, 0x17, hwsbase
);
2804 i2c_w(sd
, 0x18, hwebase
+ (sd
->gspca_dev
.width
>> hwscale
));
2805 i2c_w(sd
, 0x19, vwsbase
);
2806 i2c_w(sd
, 0x1a, vwebase
+ (sd
->gspca_dev
.height
>> vwscale
));
2811 /* -- start the camera -- */
2812 static int sd_start(struct gspca_dev
*gspca_dev
)
2814 struct sd
*sd
= (struct sd
*) gspca_dev
;
2817 switch (sd
->bridge
) {
2819 case BRIDGE_OV511PLUS
:
2820 ret
= ov511_mode_init_regs(sd
);
2823 case BRIDGE_OV518PLUS
:
2824 ret
= ov518_mode_init_regs(sd
);
2827 ret
= ov519_mode_init_regs(sd
);
2833 ret
= set_ov_sensor_window(sd
);
2837 setcontrast(gspca_dev
);
2838 setbrightness(gspca_dev
);
2839 setcolors(gspca_dev
);
2841 setautobrightness(sd
);
2844 ret
= ov51x_restart(sd
);
2847 ov51x_led_control(sd
, 1);
2850 PDEBUG(D_ERR
, "camera start error:%d", ret
);
2854 static void sd_stopN(struct gspca_dev
*gspca_dev
)
2856 struct sd
*sd
= (struct sd
*) gspca_dev
;
2859 ov51x_led_control(sd
, 0);
2862 static void ov511_pkt_scan(struct gspca_dev
*gspca_dev
,
2863 struct gspca_frame
*frame
, /* target */
2864 __u8
*in
, /* isoc packet */
2865 int len
) /* iso packet length */
2867 struct sd
*sd
= (struct sd
*) gspca_dev
;
2869 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
2870 * byte non-zero. The EOF packet has image width/height in the
2871 * 10th and 11th bytes. The 9th byte is given as follows:
2874 * 6: compression enabled
2875 * 5: 422/420/400 modes
2876 * 4: 422/420/400 modes
2878 * 2: snapshot button on
2882 if (!(in
[0] | in
[1] | in
[2] | in
[3] | in
[4] | in
[5] | in
[6] | in
[7]) &&
2886 if ((in
[9] + 1) * 8 != gspca_dev
->width
||
2887 (in
[10] + 1) * 8 != gspca_dev
->height
) {
2888 PDEBUG(D_ERR
, "Invalid frame size, got: %dx%d,"
2889 " requested: %dx%d\n",
2890 (in
[9] + 1) * 8, (in
[10] + 1) * 8,
2891 gspca_dev
->width
, gspca_dev
->height
);
2892 gspca_dev
->last_packet_type
= DISCARD_PACKET
;
2895 /* Add 11 byte footer to frame, might be usefull */
2896 gspca_frame_add(gspca_dev
, LAST_PACKET
, frame
, in
, 11);
2900 gspca_frame_add(gspca_dev
, FIRST_PACKET
, frame
, in
, 0);
2905 /* Ignore the packet number */
2908 /* intermediate packet */
2909 gspca_frame_add(gspca_dev
, INTER_PACKET
, frame
, in
, len
);
2912 static void ov518_pkt_scan(struct gspca_dev
*gspca_dev
,
2913 struct gspca_frame
*frame
, /* target */
2914 __u8
*data
, /* isoc packet */
2915 int len
) /* iso packet length */
2917 struct sd
*sd
= (struct sd
*) gspca_dev
;
2919 /* A false positive here is likely, until OVT gives me
2920 * the definitive SOF/EOF format */
2921 if ((!(data
[0] | data
[1] | data
[2] | data
[3] | data
[5])) && data
[6]) {
2922 gspca_frame_add(gspca_dev
, LAST_PACKET
, frame
, data
, 0);
2923 gspca_frame_add(gspca_dev
, FIRST_PACKET
, frame
, data
, 0);
2927 if (gspca_dev
->last_packet_type
== DISCARD_PACKET
)
2930 /* Does this device use packet numbers ? */
2933 if (sd
->packet_nr
== data
[len
])
2935 /* The last few packets of the frame (which are all 0's
2936 except that they may contain part of the footer), are
2938 else if (sd
->packet_nr
== 0 || data
[len
]) {
2939 PDEBUG(D_ERR
, "Invalid packet nr: %d (expect: %d)",
2940 (int)data
[len
], (int)sd
->packet_nr
);
2941 gspca_dev
->last_packet_type
= DISCARD_PACKET
;
2946 /* intermediate packet */
2947 gspca_frame_add(gspca_dev
, INTER_PACKET
, frame
, data
, len
);
2950 static void ov519_pkt_scan(struct gspca_dev
*gspca_dev
,
2951 struct gspca_frame
*frame
, /* target */
2952 __u8
*data
, /* isoc packet */
2953 int len
) /* iso packet length */
2955 /* Header of ov519 is 16 bytes:
2956 * Byte Value Description
2960 * 3 0xXX 0x50 = SOF, 0x51 = EOF
2961 * 9 0xXX 0x01 initial frame without data,
2962 * 0x00 standard frame with image
2963 * 14 Lo in EOF: length of image data / 8
2967 if (data
[0] == 0xff && data
[1] == 0xff && data
[2] == 0xff) {
2969 case 0x50: /* start of frame */
2974 if (data
[0] == 0xff || data
[1] == 0xd8)
2975 gspca_frame_add(gspca_dev
, FIRST_PACKET
, frame
,
2978 gspca_dev
->last_packet_type
= DISCARD_PACKET
;
2980 case 0x51: /* end of frame */
2982 gspca_dev
->last_packet_type
= DISCARD_PACKET
;
2983 gspca_frame_add(gspca_dev
, LAST_PACKET
, frame
,
2989 /* intermediate packet */
2990 gspca_frame_add(gspca_dev
, INTER_PACKET
, frame
,
2994 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
2995 struct gspca_frame
*frame
, /* target */
2996 __u8
*data
, /* isoc packet */
2997 int len
) /* iso packet length */
2999 struct sd
*sd
= (struct sd
*) gspca_dev
;
3001 switch (sd
->bridge
) {
3003 case BRIDGE_OV511PLUS
:
3004 ov511_pkt_scan(gspca_dev
, frame
, data
, len
);
3007 case BRIDGE_OV518PLUS
:
3008 ov518_pkt_scan(gspca_dev
, frame
, data
, len
);
3011 ov519_pkt_scan(gspca_dev
, frame
, data
, len
);
3016 /* -- management routines -- */
3018 static void setbrightness(struct gspca_dev
*gspca_dev
)
3020 struct sd
*sd
= (struct sd
*) gspca_dev
;
3023 val
= sd
->brightness
;
3024 switch (sd
->sensor
) {
3032 i2c_w(sd
, OV7610_REG_BRT
, val
);
3035 /* 7620 doesn't like manual changes when in auto mode */
3036 if (!sd
->autobrightness
)
3037 i2c_w(sd
, OV7610_REG_BRT
, val
);
3041 * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
3042 i2c_w(sd
, OV7670_REG_BRIGHT
, ov7670_abs_to_sm(val
));
3047 static void setcontrast(struct gspca_dev
*gspca_dev
)
3049 struct sd
*sd
= (struct sd
*) gspca_dev
;
3053 switch (sd
->sensor
) {
3056 i2c_w(sd
, OV7610_REG_CNT
, val
);
3060 i2c_w_mask(sd
, OV7610_REG_CNT
, val
>> 4, 0x0f);
3063 static const __u8 ctab
[] = {
3064 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
3067 /* Use Y gamma control instead. Bit 0 enables it. */
3068 i2c_w(sd
, 0x64, ctab
[val
>> 5]);
3072 static const __u8 ctab
[] = {
3073 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
3074 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
3077 /* Use Y gamma control instead. Bit 0 enables it. */
3078 i2c_w(sd
, 0x64, ctab
[val
>> 4]);
3082 /* Use gain control instead. */
3083 i2c_w(sd
, OV7610_REG_GAIN
, val
>> 2);
3086 /* check that this isn't just the same as ov7610 */
3087 i2c_w(sd
, OV7670_REG_CONTRAS
, val
>> 1);
3092 static void setcolors(struct gspca_dev
*gspca_dev
)
3094 struct sd
*sd
= (struct sd
*) gspca_dev
;
3098 switch (sd
->sensor
) {
3105 i2c_w(sd
, OV7610_REG_SAT
, val
);
3108 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
3109 /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
3112 i2c_w(sd
, OV7610_REG_SAT
, val
);
3115 i2c_w(sd
, OV7610_REG_SAT
, val
& 0xf0);
3118 /* supported later once I work out how to do it
3119 * transparently fail now! */
3120 /* set REG_COM13 values for UV sat auto mode */
3125 static void setautobrightness(struct sd
*sd
)
3127 if (sd
->sensor
== SEN_OV7640
|| sd
->sensor
== SEN_OV7670
)
3130 i2c_w_mask(sd
, 0x2d, sd
->autobrightness
? 0x10 : 0x00, 0x10);
3133 static void setfreq(struct sd
*sd
)
3135 if (sd
->sensor
== SEN_OV7670
) {
3137 case 0: /* Banding filter disabled */
3138 i2c_w_mask(sd
, OV7670_REG_COM8
, 0, OV7670_COM8_BFILT
);
3141 i2c_w_mask(sd
, OV7670_REG_COM8
, OV7670_COM8_BFILT
,
3143 i2c_w_mask(sd
, OV7670_REG_COM11
, 0x08, 0x18);
3146 i2c_w_mask(sd
, OV7670_REG_COM8
, OV7670_COM8_BFILT
,
3148 i2c_w_mask(sd
, OV7670_REG_COM11
, 0x00, 0x18);
3150 case 3: /* Auto hz */
3151 i2c_w_mask(sd
, OV7670_REG_COM8
, OV7670_COM8_BFILT
,
3153 i2c_w_mask(sd
, OV7670_REG_COM11
, OV7670_COM11_HZAUTO
,
3159 case 0: /* Banding filter disabled */
3160 i2c_w_mask(sd
, 0x2d, 0x00, 0x04);
3161 i2c_w_mask(sd
, 0x2a, 0x00, 0x80);
3163 case 1: /* 50 hz (filter on and framerate adj) */
3164 i2c_w_mask(sd
, 0x2d, 0x04, 0x04);
3165 i2c_w_mask(sd
, 0x2a, 0x80, 0x80);
3166 /* 20 fps -> 16.667 fps */
3167 if (sd
->sensor
== SEN_OV6620
||
3168 sd
->sensor
== SEN_OV6630
||
3169 sd
->sensor
== SEN_OV66308AF
)
3170 i2c_w(sd
, 0x2b, 0x5e);
3172 i2c_w(sd
, 0x2b, 0xac);
3174 case 2: /* 60 hz (filter on, ...) */
3175 i2c_w_mask(sd
, 0x2d, 0x04, 0x04);
3176 if (sd
->sensor
== SEN_OV6620
||
3177 sd
->sensor
== SEN_OV6630
||
3178 sd
->sensor
== SEN_OV66308AF
) {
3179 /* 20 fps -> 15 fps */
3180 i2c_w_mask(sd
, 0x2a, 0x80, 0x80);
3181 i2c_w(sd
, 0x2b, 0xa8);
3183 /* no framerate adj. */
3184 i2c_w_mask(sd
, 0x2a, 0x00, 0x80);
3191 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
3193 struct sd
*sd
= (struct sd
*) gspca_dev
;
3195 sd
->brightness
= val
;
3196 if (gspca_dev
->streaming
)
3197 setbrightness(gspca_dev
);
3201 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
3203 struct sd
*sd
= (struct sd
*) gspca_dev
;
3205 *val
= sd
->brightness
;
3209 static int sd_setcontrast(struct gspca_dev
*gspca_dev
, __s32 val
)
3211 struct sd
*sd
= (struct sd
*) gspca_dev
;
3214 if (gspca_dev
->streaming
)
3215 setcontrast(gspca_dev
);
3219 static int sd_getcontrast(struct gspca_dev
*gspca_dev
, __s32
*val
)
3221 struct sd
*sd
= (struct sd
*) gspca_dev
;
3223 *val
= sd
->contrast
;
3227 static int sd_setcolors(struct gspca_dev
*gspca_dev
, __s32 val
)
3229 struct sd
*sd
= (struct sd
*) gspca_dev
;
3232 if (gspca_dev
->streaming
)
3233 setcolors(gspca_dev
);
3237 static int sd_getcolors(struct gspca_dev
*gspca_dev
, __s32
*val
)
3239 struct sd
*sd
= (struct sd
*) gspca_dev
;
3245 static int sd_sethflip(struct gspca_dev
*gspca_dev
, __s32 val
)
3247 struct sd
*sd
= (struct sd
*) gspca_dev
;
3250 if (gspca_dev
->streaming
)
3255 static int sd_gethflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
3257 struct sd
*sd
= (struct sd
*) gspca_dev
;
3263 static int sd_setvflip(struct gspca_dev
*gspca_dev
, __s32 val
)
3265 struct sd
*sd
= (struct sd
*) gspca_dev
;
3268 if (gspca_dev
->streaming
)
3273 static int sd_getvflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
3275 struct sd
*sd
= (struct sd
*) gspca_dev
;
3281 static int sd_setautobrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
3283 struct sd
*sd
= (struct sd
*) gspca_dev
;
3285 sd
->autobrightness
= val
;
3286 if (gspca_dev
->streaming
)
3287 setautobrightness(sd
);
3291 static int sd_getautobrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
3293 struct sd
*sd
= (struct sd
*) gspca_dev
;
3295 *val
= sd
->autobrightness
;
3299 static int sd_setfreq(struct gspca_dev
*gspca_dev
, __s32 val
)
3301 struct sd
*sd
= (struct sd
*) gspca_dev
;
3304 if (gspca_dev
->streaming
)
3309 static int sd_getfreq(struct gspca_dev
*gspca_dev
, __s32
*val
)
3311 struct sd
*sd
= (struct sd
*) gspca_dev
;
3317 static int sd_querymenu(struct gspca_dev
*gspca_dev
,
3318 struct v4l2_querymenu
*menu
)
3320 struct sd
*sd
= (struct sd
*) gspca_dev
;
3323 case V4L2_CID_POWER_LINE_FREQUENCY
:
3324 switch (menu
->index
) {
3325 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
3326 strcpy((char *) menu
->name
, "NoFliker");
3328 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
3329 strcpy((char *) menu
->name
, "50 Hz");
3331 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
3332 strcpy((char *) menu
->name
, "60 Hz");
3335 if (sd
->sensor
!= SEN_OV7670
)
3338 strcpy((char *) menu
->name
, "Automatic");
3346 /* sub-driver description */
3347 static const struct sd_desc sd_desc
= {
3348 .name
= MODULE_NAME
,
3350 .nctrls
= ARRAY_SIZE(sd_ctrls
),
3351 .config
= sd_config
,
3355 .pkt_scan
= sd_pkt_scan
,
3356 .querymenu
= sd_querymenu
,
3359 /* -- module initialisation -- */
3360 static const __devinitdata
struct usb_device_id device_table
[] = {
3361 {USB_DEVICE(0x041e, 0x4052), .driver_info
= BRIDGE_OV519
},
3362 {USB_DEVICE(0x041e, 0x405f), .driver_info
= BRIDGE_OV519
},
3363 {USB_DEVICE(0x041e, 0x4060), .driver_info
= BRIDGE_OV519
},
3364 {USB_DEVICE(0x041e, 0x4061), .driver_info
= BRIDGE_OV519
},
3365 {USB_DEVICE(0x041e, 0x4064),
3366 .driver_info
= BRIDGE_OV519
| BRIDGE_INVERT_LED
},
3367 {USB_DEVICE(0x041e, 0x4068),
3368 .driver_info
= BRIDGE_OV519
| BRIDGE_INVERT_LED
},
3369 {USB_DEVICE(0x045e, 0x028c), .driver_info
= BRIDGE_OV519
},
3370 {USB_DEVICE(0x054c, 0x0154), .driver_info
= BRIDGE_OV519
},
3371 {USB_DEVICE(0x054c, 0x0155), .driver_info
= BRIDGE_OV519
},
3372 {USB_DEVICE(0x05a9, 0x0511), .driver_info
= BRIDGE_OV511
},
3373 {USB_DEVICE(0x05a9, 0x0518), .driver_info
= BRIDGE_OV518
},
3374 {USB_DEVICE(0x05a9, 0x0519), .driver_info
= BRIDGE_OV519
},
3375 {USB_DEVICE(0x05a9, 0x0530), .driver_info
= BRIDGE_OV519
},
3376 {USB_DEVICE(0x05a9, 0x4519), .driver_info
= BRIDGE_OV519
},
3377 {USB_DEVICE(0x05a9, 0x8519), .driver_info
= BRIDGE_OV519
},
3378 {USB_DEVICE(0x05a9, 0xa511), .driver_info
= BRIDGE_OV511PLUS
},
3379 {USB_DEVICE(0x05a9, 0xa518), .driver_info
= BRIDGE_OV518PLUS
},
3380 {USB_DEVICE(0x0813, 0x0002), .driver_info
= BRIDGE_OV511PLUS
},
3384 MODULE_DEVICE_TABLE(usb
, device_table
);
3386 /* -- device connect -- */
3387 static int sd_probe(struct usb_interface
*intf
,
3388 const struct usb_device_id
*id
)
3390 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
3394 static struct usb_driver sd_driver
= {
3395 .name
= MODULE_NAME
,
3396 .id_table
= device_table
,
3398 .disconnect
= gspca_disconnect
,
3400 .suspend
= gspca_suspend
,
3401 .resume
= gspca_resume
,
3405 /* -- module insert / remove -- */
3406 static int __init
sd_mod_init(void)
3409 ret
= usb_register(&sd_driver
);
3412 PDEBUG(D_PROBE
, "registered");
3415 static void __exit
sd_mod_exit(void)
3417 usb_deregister(&sd_driver
);
3418 PDEBUG(D_PROBE
, "deregistered");
3421 module_init(sd_mod_init
);
3422 module_exit(sd_mod_exit
);
3424 module_param(frame_rate
, int, 0644);
3425 MODULE_PARM_DESC(frame_rate
, "Frame rate (5, 10, 15, 20 or 30 fps)");