Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1 | /** |
| 2 | * OV519 driver |
| 3 | * |
Jean-François Moine | 58c92d3 | 2011-03-13 16:36:49 -0300 | [diff] [blame] | 4 | * Copyright (C) 2008-2011 Jean-François Moine <moinejf@free.fr> |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 5 | * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com> |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 6 | * |
Romain Beauxis | 2961e875 | 2008-12-05 06:25:26 -0300 | [diff] [blame] | 7 | * This module is adapted from the ov51x-jpeg package, which itself |
| 8 | * was adapted from the ov511 driver. |
| 9 | * |
| 10 | * Original copyright for the ov511 driver is: |
| 11 | * |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 12 | * Copyright (c) 1999-2006 Mark W. McClelland |
Romain Beauxis | 2961e875 | 2008-12-05 06:25:26 -0300 | [diff] [blame] | 13 | * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 14 | * Many improvements by Bret Wallach <bwallac1@san.rr.com> |
| 15 | * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000) |
| 16 | * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org> |
| 17 | * Changes by Claudio Matsuoka <claudio@conectiva.com> |
Romain Beauxis | 2961e875 | 2008-12-05 06:25:26 -0300 | [diff] [blame] | 18 | * |
| 19 | * ov51x-jpeg original copyright is: |
| 20 | * |
| 21 | * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org> |
| 22 | * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com> |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 23 | * |
| 24 | * This program is free software; you can redistribute it and/or modify |
| 25 | * it under the terms of the GNU General Public License as published by |
| 26 | * the Free Software Foundation; either version 2 of the License, or |
| 27 | * any later version. |
| 28 | * |
| 29 | * This program is distributed in the hope that it will be useful, |
| 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 | * GNU General Public License for more details. |
| 33 | * |
| 34 | * You should have received a copy of the GNU General Public License |
| 35 | * along with this program; if not, write to the Free Software |
| 36 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 37 | * |
| 38 | */ |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 39 | |
| 40 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 41 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 42 | #define MODULE_NAME "ov519" |
| 43 | |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 44 | #include <linux/input.h> |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 45 | #include "gspca.h" |
| 46 | |
Jean-François Moine | 9a731a3 | 2010-06-04 05:26:42 -0300 | [diff] [blame] | 47 | /* The jpeg_hdr is used by w996Xcf only */ |
| 48 | /* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */ |
| 49 | #define CONEX_CAM |
| 50 | #include "jpeg.h" |
| 51 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 52 | MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); |
| 53 | MODULE_DESCRIPTION("OV519 USB Camera Driver"); |
| 54 | MODULE_LICENSE("GPL"); |
| 55 | |
| 56 | /* global parameters */ |
| 57 | static int frame_rate; |
| 58 | |
| 59 | /* Number of times to retry a failed I2C transaction. Increase this if you |
| 60 | * are getting "Failed to read sensor ID..." */ |
| 61 | static int i2c_detect_tries = 10; |
| 62 | |
| 63 | /* ov519 device descriptor */ |
| 64 | struct sd { |
| 65 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 66 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 67 | struct v4l2_ctrl *jpegqual; |
| 68 | struct v4l2_ctrl *freq; |
| 69 | struct { /* h/vflip control cluster */ |
| 70 | struct v4l2_ctrl *hflip; |
| 71 | struct v4l2_ctrl *vflip; |
| 72 | }; |
| 73 | struct { /* autobrightness/brightness control cluster */ |
| 74 | struct v4l2_ctrl *autobright; |
| 75 | struct v4l2_ctrl *brightness; |
| 76 | }; |
Jean-François Moine | 62833ac | 2010-10-02 04:27:02 -0300 | [diff] [blame] | 77 | |
Hans de Goede | b82180d | 2013-08-22 12:41:14 -0300 | [diff] [blame] | 78 | u8 revision; |
| 79 | |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 80 | u8 packet_nr; |
Hans de Goede | 92918a5 | 2009-06-14 06:21:35 -0300 | [diff] [blame] | 81 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 82 | char bridge; |
| 83 | #define BRIDGE_OV511 0 |
| 84 | #define BRIDGE_OV511PLUS 1 |
| 85 | #define BRIDGE_OV518 2 |
| 86 | #define BRIDGE_OV518PLUS 3 |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 87 | #define BRIDGE_OV519 4 /* = ov530 */ |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 88 | #define BRIDGE_OVFX2 5 |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 89 | #define BRIDGE_W9968CF 6 |
Hans de Goede | 9e4d825 | 2009-06-14 06:25:06 -0300 | [diff] [blame] | 90 | #define BRIDGE_MASK 7 |
| 91 | |
| 92 | char invert_led; |
| 93 | #define BRIDGE_INVERT_LED 8 |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 94 | |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 95 | char snapshot_pressed; |
| 96 | char snapshot_needs_reset; |
| 97 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 98 | /* Determined by sensor type */ |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 99 | u8 sif; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 100 | |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 101 | #define QUALITY_MIN 50 |
| 102 | #define QUALITY_MAX 70 |
| 103 | #define QUALITY_DEF 50 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 104 | |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 105 | u8 stopped; /* Streaming is temporarily paused */ |
| 106 | u8 first_frame; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 107 | |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 108 | u8 frame_rate; /* current Framerate */ |
| 109 | u8 clockdiv; /* clockdiv override */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 110 | |
Jean-François Moine | 7bbe6b8 | 2010-11-11 08:27:24 -0300 | [diff] [blame] | 111 | s8 sensor; /* Type of image sensor chip (SEN_*) */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 112 | |
| 113 | u8 sensor_addr; |
Jean-François Moine | d6fa663 | 2010-11-11 08:05:50 -0300 | [diff] [blame] | 114 | u16 sensor_width; |
| 115 | u16 sensor_height; |
| 116 | s16 sensor_reg_cache[256]; |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 117 | |
Jean-François Moine | 9a731a3 | 2010-06-04 05:26:42 -0300 | [diff] [blame] | 118 | u8 jpeg_hdr[JPEG_HDR_SZ]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 119 | }; |
Jean-François Moine | 7bbe6b8 | 2010-11-11 08:27:24 -0300 | [diff] [blame] | 120 | enum sensors { |
| 121 | SEN_OV2610, |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 122 | SEN_OV2610AE, |
Jean-François Moine | 7bbe6b8 | 2010-11-11 08:27:24 -0300 | [diff] [blame] | 123 | SEN_OV3610, |
| 124 | SEN_OV6620, |
| 125 | SEN_OV6630, |
| 126 | SEN_OV66308AF, |
| 127 | SEN_OV7610, |
| 128 | SEN_OV7620, |
| 129 | SEN_OV7620AE, |
| 130 | SEN_OV7640, |
| 131 | SEN_OV7648, |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 132 | SEN_OV7660, |
Jean-François Moine | 7bbe6b8 | 2010-11-11 08:27:24 -0300 | [diff] [blame] | 133 | SEN_OV7670, |
| 134 | SEN_OV76BE, |
| 135 | SEN_OV8610, |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 136 | SEN_OV9600, |
Jean-François Moine | 7bbe6b8 | 2010-11-11 08:27:24 -0300 | [diff] [blame] | 137 | }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 138 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 139 | /* Note this is a bit of a hack, but the w9968cf driver needs the code for all |
| 140 | the ov sensors which is already present here. When we have the time we |
| 141 | really should move the sensor drivers to v4l2 sub drivers. */ |
| 142 | #include "w996Xcf.c" |
| 143 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 144 | /* table of the disabled controls */ |
| 145 | struct ctrl_valid { |
Emil Goode | 50c457a | 2012-08-05 09:34:26 -0300 | [diff] [blame] | 146 | unsigned int has_brightness:1; |
| 147 | unsigned int has_contrast:1; |
| 148 | unsigned int has_exposure:1; |
| 149 | unsigned int has_autogain:1; |
| 150 | unsigned int has_sat:1; |
| 151 | unsigned int has_hvflip:1; |
| 152 | unsigned int has_autobright:1; |
| 153 | unsigned int has_freq:1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 154 | }; |
| 155 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 156 | static const struct ctrl_valid valid_controls[] = { |
| 157 | [SEN_OV2610] = { |
| 158 | .has_exposure = 1, |
| 159 | .has_autogain = 1, |
| 160 | }, |
| 161 | [SEN_OV2610AE] = { |
| 162 | .has_exposure = 1, |
| 163 | .has_autogain = 1, |
| 164 | }, |
| 165 | [SEN_OV3610] = { |
| 166 | /* No controls */ |
| 167 | }, |
| 168 | [SEN_OV6620] = { |
| 169 | .has_brightness = 1, |
| 170 | .has_contrast = 1, |
| 171 | .has_sat = 1, |
| 172 | .has_autobright = 1, |
| 173 | .has_freq = 1, |
| 174 | }, |
| 175 | [SEN_OV6630] = { |
| 176 | .has_brightness = 1, |
| 177 | .has_contrast = 1, |
| 178 | .has_sat = 1, |
| 179 | .has_autobright = 1, |
| 180 | .has_freq = 1, |
| 181 | }, |
| 182 | [SEN_OV66308AF] = { |
| 183 | .has_brightness = 1, |
| 184 | .has_contrast = 1, |
| 185 | .has_sat = 1, |
| 186 | .has_autobright = 1, |
| 187 | .has_freq = 1, |
| 188 | }, |
| 189 | [SEN_OV7610] = { |
| 190 | .has_brightness = 1, |
| 191 | .has_contrast = 1, |
| 192 | .has_sat = 1, |
| 193 | .has_autobright = 1, |
| 194 | .has_freq = 1, |
| 195 | }, |
| 196 | [SEN_OV7620] = { |
| 197 | .has_brightness = 1, |
| 198 | .has_contrast = 1, |
| 199 | .has_sat = 1, |
| 200 | .has_autobright = 1, |
| 201 | .has_freq = 1, |
| 202 | }, |
| 203 | [SEN_OV7620AE] = { |
| 204 | .has_brightness = 1, |
| 205 | .has_contrast = 1, |
| 206 | .has_sat = 1, |
| 207 | .has_autobright = 1, |
| 208 | .has_freq = 1, |
| 209 | }, |
| 210 | [SEN_OV7640] = { |
| 211 | .has_brightness = 1, |
| 212 | .has_sat = 1, |
| 213 | .has_freq = 1, |
| 214 | }, |
| 215 | [SEN_OV7648] = { |
| 216 | .has_brightness = 1, |
| 217 | .has_sat = 1, |
| 218 | .has_freq = 1, |
| 219 | }, |
| 220 | [SEN_OV7660] = { |
| 221 | .has_brightness = 1, |
| 222 | .has_contrast = 1, |
| 223 | .has_sat = 1, |
| 224 | .has_hvflip = 1, |
| 225 | .has_freq = 1, |
| 226 | }, |
| 227 | [SEN_OV7670] = { |
| 228 | .has_brightness = 1, |
| 229 | .has_contrast = 1, |
| 230 | .has_hvflip = 1, |
| 231 | .has_freq = 1, |
| 232 | }, |
| 233 | [SEN_OV76BE] = { |
| 234 | .has_brightness = 1, |
| 235 | .has_contrast = 1, |
| 236 | .has_sat = 1, |
| 237 | .has_autobright = 1, |
| 238 | .has_freq = 1, |
| 239 | }, |
| 240 | [SEN_OV8610] = { |
| 241 | .has_brightness = 1, |
| 242 | .has_contrast = 1, |
| 243 | .has_sat = 1, |
| 244 | .has_autobright = 1, |
| 245 | }, |
| 246 | [SEN_OV9600] = { |
| 247 | .has_exposure = 1, |
| 248 | .has_autogain = 1, |
| 249 | }, |
Jean-François Moine | 83db768 | 2010-11-12 07:14:08 -0300 | [diff] [blame] | 250 | }; |
| 251 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 252 | static const struct v4l2_pix_format ov519_vga_mode[] = { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 253 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 254 | .bytesperline = 320, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 255 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 256 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 257 | .priv = 1}, |
| 258 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 259 | .bytesperline = 640, |
| 260 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 261 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 262 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 263 | }; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 264 | static const struct v4l2_pix_format ov519_sif_mode[] = { |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 265 | {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 266 | .bytesperline = 160, |
| 267 | .sizeimage = 160 * 120 * 3 / 8 + 590, |
| 268 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 269 | .priv = 3}, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 270 | {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 271 | .bytesperline = 176, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 272 | .sizeimage = 176 * 144 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 273 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 274 | .priv = 1}, |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 275 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 276 | .bytesperline = 320, |
| 277 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 278 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 279 | .priv = 2}, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 280 | {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 281 | .bytesperline = 352, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 282 | .sizeimage = 352 * 288 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 283 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 284 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 285 | }; |
| 286 | |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 287 | /* Note some of the sizeimage values for the ov511 / ov518 may seem |
| 288 | larger then necessary, however they need to be this big as the ov511 / |
| 289 | ov518 always fills the entire isoc frame, using 0 padding bytes when |
| 290 | it doesn't have any data. So with low framerates the amount of data |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 291 | transferred can become quite large (libv4l will remove all the 0 padding |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 292 | in userspace). */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 293 | static const struct v4l2_pix_format ov518_vga_mode[] = { |
| 294 | {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 295 | .bytesperline = 320, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 296 | .sizeimage = 320 * 240 * 3, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 297 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 298 | .priv = 1}, |
| 299 | {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 300 | .bytesperline = 640, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 301 | .sizeimage = 640 * 480 * 2, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 302 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 303 | .priv = 0}, |
| 304 | }; |
| 305 | static const struct v4l2_pix_format ov518_sif_mode[] = { |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 306 | {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 307 | .bytesperline = 160, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 308 | .sizeimage = 70000, |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 309 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 310 | .priv = 3}, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 311 | {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 312 | .bytesperline = 176, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 313 | .sizeimage = 70000, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 314 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 315 | .priv = 1}, |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 316 | {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 317 | .bytesperline = 320, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 318 | .sizeimage = 320 * 240 * 3, |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 319 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 320 | .priv = 2}, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 321 | {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 322 | .bytesperline = 352, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 323 | .sizeimage = 352 * 288 * 3, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 324 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 325 | .priv = 0}, |
| 326 | }; |
| 327 | |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 328 | static const struct v4l2_pix_format ov511_vga_mode[] = { |
| 329 | {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE, |
| 330 | .bytesperline = 320, |
| 331 | .sizeimage = 320 * 240 * 3, |
| 332 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 333 | .priv = 1}, |
| 334 | {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE, |
| 335 | .bytesperline = 640, |
| 336 | .sizeimage = 640 * 480 * 2, |
| 337 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 338 | .priv = 0}, |
| 339 | }; |
| 340 | static const struct v4l2_pix_format ov511_sif_mode[] = { |
| 341 | {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE, |
| 342 | .bytesperline = 160, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 343 | .sizeimage = 70000, |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 344 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 345 | .priv = 3}, |
| 346 | {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE, |
| 347 | .bytesperline = 176, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 348 | .sizeimage = 70000, |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 349 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 350 | .priv = 1}, |
| 351 | {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE, |
| 352 | .bytesperline = 320, |
| 353 | .sizeimage = 320 * 240 * 3, |
| 354 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 355 | .priv = 2}, |
| 356 | {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE, |
| 357 | .bytesperline = 352, |
| 358 | .sizeimage = 352 * 288 * 3, |
| 359 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 360 | .priv = 0}, |
| 361 | }; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 362 | |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 363 | static const struct v4l2_pix_format ovfx2_ov2610_mode[] = { |
Jean-François Moine | c42cedb | 2011-02-10 13:37:48 -0300 | [diff] [blame] | 364 | {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 365 | .bytesperline = 800, |
| 366 | .sizeimage = 800 * 600, |
| 367 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 368 | .priv = 1}, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 369 | {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 370 | .bytesperline = 1600, |
| 371 | .sizeimage = 1600 * 1200, |
| 372 | .colorspace = V4L2_COLORSPACE_SRGB}, |
| 373 | }; |
| 374 | static const struct v4l2_pix_format ovfx2_ov3610_mode[] = { |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 375 | {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 376 | .bytesperline = 640, |
| 377 | .sizeimage = 640 * 480, |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 378 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 379 | .priv = 1}, |
| 380 | {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 381 | .bytesperline = 800, |
| 382 | .sizeimage = 800 * 600, |
| 383 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 384 | .priv = 1}, |
| 385 | {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 386 | .bytesperline = 1024, |
| 387 | .sizeimage = 1024 * 768, |
| 388 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 389 | .priv = 1}, |
| 390 | {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 391 | .bytesperline = 1600, |
| 392 | .sizeimage = 1600 * 1200, |
| 393 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 394 | .priv = 0}, |
| 395 | {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 396 | .bytesperline = 2048, |
| 397 | .sizeimage = 2048 * 1536, |
| 398 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 399 | .priv = 0}, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 400 | }; |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 401 | static const struct v4l2_pix_format ovfx2_ov9600_mode[] = { |
| 402 | {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 403 | .bytesperline = 640, |
| 404 | .sizeimage = 640 * 480, |
| 405 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 406 | .priv = 1}, |
| 407 | {1280, 1024, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE, |
| 408 | .bytesperline = 1280, |
| 409 | .sizeimage = 1280 * 1024, |
| 410 | .colorspace = V4L2_COLORSPACE_SRGB}, |
| 411 | }; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 412 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 413 | /* Registers common to OV511 / OV518 */ |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 414 | #define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */ |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 415 | #define R51x_SYS_RESET 0x50 |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 416 | /* Reset type flags */ |
| 417 | #define OV511_RESET_OMNICE 0x08 |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 418 | #define R51x_SYS_INIT 0x53 |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 419 | #define R51x_SYS_SNAP 0x52 |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 420 | #define R51x_SYS_CUST_ID 0x5f |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 421 | #define R51x_COMP_LUT_BEGIN 0x80 |
| 422 | |
| 423 | /* OV511 Camera interface register numbers */ |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 424 | #define R511_CAM_DELAY 0x10 |
| 425 | #define R511_CAM_EDGE 0x11 |
| 426 | #define R511_CAM_PXCNT 0x12 |
| 427 | #define R511_CAM_LNCNT 0x13 |
| 428 | #define R511_CAM_PXDIV 0x14 |
| 429 | #define R511_CAM_LNDIV 0x15 |
| 430 | #define R511_CAM_UV_EN 0x16 |
| 431 | #define R511_CAM_LINE_MODE 0x17 |
| 432 | #define R511_CAM_OPTS 0x18 |
| 433 | |
| 434 | #define R511_SNAP_FRAME 0x19 |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 435 | #define R511_SNAP_PXCNT 0x1a |
| 436 | #define R511_SNAP_LNCNT 0x1b |
| 437 | #define R511_SNAP_PXDIV 0x1c |
| 438 | #define R511_SNAP_LNDIV 0x1d |
| 439 | #define R511_SNAP_UV_EN 0x1e |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 440 | #define R511_SNAP_OPTS 0x1f |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 441 | |
| 442 | #define R511_DRAM_FLOW_CTL 0x20 |
| 443 | #define R511_FIFO_OPTS 0x31 |
| 444 | #define R511_I2C_CTL 0x40 |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 445 | #define R511_SYS_LED_CTL 0x55 /* OV511+ only */ |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 446 | #define R511_COMP_EN 0x78 |
| 447 | #define R511_COMP_LUT_EN 0x79 |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 448 | |
| 449 | /* OV518 Camera interface register numbers */ |
| 450 | #define R518_GPIO_OUT 0x56 /* OV518(+) only */ |
| 451 | #define R518_GPIO_CTL 0x57 /* OV518(+) only */ |
| 452 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 453 | /* OV519 Camera interface register numbers */ |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 454 | #define OV519_R10_H_SIZE 0x10 |
| 455 | #define OV519_R11_V_SIZE 0x11 |
| 456 | #define OV519_R12_X_OFFSETL 0x12 |
| 457 | #define OV519_R13_X_OFFSETH 0x13 |
| 458 | #define OV519_R14_Y_OFFSETL 0x14 |
| 459 | #define OV519_R15_Y_OFFSETH 0x15 |
| 460 | #define OV519_R16_DIVIDER 0x16 |
| 461 | #define OV519_R20_DFR 0x20 |
| 462 | #define OV519_R25_FORMAT 0x25 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 463 | |
| 464 | /* OV519 System Controller register numbers */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 465 | #define OV519_R51_RESET1 0x51 |
| 466 | #define OV519_R54_EN_CLK1 0x54 |
Jean-François Moine | b4e96ea | 2010-11-12 16:13:17 -0300 | [diff] [blame] | 467 | #define OV519_R57_SNAPSHOT 0x57 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 468 | |
| 469 | #define OV519_GPIO_DATA_OUT0 0x71 |
| 470 | #define OV519_GPIO_IO_CTRL0 0x72 |
| 471 | |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 472 | /*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 473 | |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 474 | /* |
| 475 | * The FX2 chip does not give us a zero length read at end of frame. |
| 476 | * It does, however, give a short read at the end of a frame, if |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 477 | * necessary, rather than run two frames together. |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 478 | * |
| 479 | * By choosing the right bulk transfer size, we are guaranteed to always |
| 480 | * get a short read for the last read of each frame. Frame sizes are |
| 481 | * always a composite number (width * height, or a multiple) so if we |
| 482 | * choose a prime number, we are guaranteed that the last read of a |
| 483 | * frame will be short. |
| 484 | * |
| 485 | * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB, |
| 486 | * otherwise EOVERFLOW "babbling" errors occur. I have not been able |
| 487 | * to figure out why. [PMiller] |
| 488 | * |
| 489 | * The constant (13 * 4096) is the largest "prime enough" number less than 64KB. |
| 490 | * |
| 491 | * It isn't enough to know the number of bytes per frame, in case we |
| 492 | * have data dropouts or buffer overruns (even though the FX2 double |
| 493 | * buffers, there are some pretty strict real time constraints for |
| 494 | * isochronous transfer for larger frame sizes). |
| 495 | */ |
Jean-François Moine | 9cf208e | 2011-05-22 05:05:11 -0300 | [diff] [blame] | 496 | /*jfm: this value does not work for 800x600 - see isoc_init */ |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 497 | #define OVFX2_BULK_SIZE (13 * 4096) |
| 498 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 499 | /* I2C registers */ |
| 500 | #define R51x_I2C_W_SID 0x41 |
| 501 | #define R51x_I2C_SADDR_3 0x42 |
| 502 | #define R51x_I2C_SADDR_2 0x43 |
| 503 | #define R51x_I2C_R_SID 0x44 |
| 504 | #define R51x_I2C_DATA 0x45 |
| 505 | #define R518_I2C_CTL 0x47 /* OV518(+) only */ |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 506 | #define OVFX2_I2C_ADDR 0x00 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 507 | |
| 508 | /* I2C ADDRESSES */ |
| 509 | #define OV7xx0_SID 0x42 |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 510 | #define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 511 | #define OV8xx0_SID 0xa0 |
| 512 | #define OV6xx0_SID 0xc0 |
| 513 | |
| 514 | /* OV7610 registers */ |
| 515 | #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 516 | #define OV7610_REG_BLUE 0x01 /* blue channel balance */ |
| 517 | #define OV7610_REG_RED 0x02 /* red channel balance */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 518 | #define OV7610_REG_SAT 0x03 /* saturation */ |
| 519 | #define OV8610_REG_HUE 0x04 /* 04 reserved */ |
| 520 | #define OV7610_REG_CNT 0x05 /* Y contrast */ |
| 521 | #define OV7610_REG_BRT 0x06 /* Y brightness */ |
| 522 | #define OV7610_REG_COM_C 0x14 /* misc common regs */ |
| 523 | #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */ |
| 524 | #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */ |
| 525 | #define OV7610_REG_COM_I 0x29 /* misc settings */ |
| 526 | |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 527 | /* OV7660 and OV7670 registers */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 528 | #define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */ |
| 529 | #define OV7670_R01_BLUE 0x01 /* blue gain */ |
| 530 | #define OV7670_R02_RED 0x02 /* red gain */ |
| 531 | #define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */ |
| 532 | #define OV7670_R04_COM1 0x04 /* Control 1 */ |
| 533 | /*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */ |
| 534 | #define OV7670_R0C_COM3 0x0c /* Control 3 */ |
| 535 | #define OV7670_R0D_COM4 0x0d /* Control 4 */ |
| 536 | #define OV7670_R0E_COM5 0x0e /* All "reserved" */ |
| 537 | #define OV7670_R0F_COM6 0x0f /* Control 6 */ |
| 538 | #define OV7670_R10_AECH 0x10 /* More bits of AEC value */ |
| 539 | #define OV7670_R11_CLKRC 0x11 /* Clock control */ |
| 540 | #define OV7670_R12_COM7 0x12 /* Control 7 */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 541 | #define OV7670_COM7_FMT_VGA 0x00 |
| 542 | /*#define OV7670_COM7_YUV 0x00 * YUV */ |
| 543 | #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */ |
| 544 | #define OV7670_COM7_FMT_MASK 0x38 |
| 545 | #define OV7670_COM7_RESET 0x80 /* Register reset */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 546 | #define OV7670_R13_COM8 0x13 /* Control 8 */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 547 | #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */ |
| 548 | #define OV7670_COM8_AWB 0x02 /* White balance enable */ |
| 549 | #define OV7670_COM8_AGC 0x04 /* Auto gain enable */ |
| 550 | #define OV7670_COM8_BFILT 0x20 /* Band filter enable */ |
| 551 | #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */ |
| 552 | #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 553 | #define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */ |
| 554 | #define OV7670_R15_COM10 0x15 /* Control 10 */ |
| 555 | #define OV7670_R17_HSTART 0x17 /* Horiz start high bits */ |
| 556 | #define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */ |
| 557 | #define OV7670_R19_VSTART 0x19 /* Vert start high bits */ |
| 558 | #define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */ |
| 559 | #define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 560 | #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */ |
| 561 | #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 562 | #define OV7670_R24_AEW 0x24 /* AGC upper limit */ |
| 563 | #define OV7670_R25_AEB 0x25 /* AGC lower limit */ |
| 564 | #define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */ |
| 565 | #define OV7670_R32_HREF 0x32 /* HREF pieces */ |
| 566 | #define OV7670_R3A_TSLB 0x3a /* lots of stuff */ |
| 567 | #define OV7670_R3B_COM11 0x3b /* Control 11 */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 568 | #define OV7670_COM11_EXP 0x02 |
| 569 | #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 570 | #define OV7670_R3C_COM12 0x3c /* Control 12 */ |
| 571 | #define OV7670_R3D_COM13 0x3d /* Control 13 */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 572 | #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */ |
| 573 | #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 574 | #define OV7670_R3E_COM14 0x3e /* Control 14 */ |
| 575 | #define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */ |
| 576 | #define OV7670_R40_COM15 0x40 /* Control 15 */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 577 | /*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 578 | #define OV7670_R41_COM16 0x41 /* Control 16 */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 579 | #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */ |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 580 | /* end of ov7660 common registers */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 581 | #define OV7670_R55_BRIGHT 0x55 /* Brightness */ |
| 582 | #define OV7670_R56_CONTRAS 0x56 /* Contrast control */ |
| 583 | #define OV7670_R69_GFIX 0x69 /* Fix gain control */ |
| 584 | /*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */ |
| 585 | #define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */ |
| 586 | #define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */ |
| 587 | #define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */ |
| 588 | #define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */ |
| 589 | #define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */ |
| 590 | #define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */ |
| 591 | #define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */ |
| 592 | #define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */ |
| 593 | #define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 594 | |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 595 | struct ov_regvals { |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 596 | u8 reg; |
| 597 | u8 val; |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 598 | }; |
| 599 | struct ov_i2c_regvals { |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 600 | u8 reg; |
| 601 | u8 val; |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 602 | }; |
| 603 | |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 604 | /* Settings for OV2610 camera chip */ |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 605 | static const struct ov_i2c_regvals norm_2610[] = { |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 606 | { 0x12, 0x80 }, /* reset */ |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 607 | }; |
| 608 | |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 609 | static const struct ov_i2c_regvals norm_2610ae[] = { |
| 610 | {0x12, 0x80}, /* reset */ |
| 611 | {0x13, 0xcd}, |
| 612 | {0x09, 0x01}, |
| 613 | {0x0d, 0x00}, |
| 614 | {0x11, 0x80}, |
| 615 | {0x12, 0x20}, /* 1600x1200 */ |
| 616 | {0x33, 0x0c}, |
| 617 | {0x35, 0x90}, |
| 618 | {0x36, 0x37}, |
| 619 | /* ms-win traces */ |
| 620 | {0x11, 0x83}, /* clock / 3 ? */ |
| 621 | {0x2d, 0x00}, /* 60 Hz filter */ |
| 622 | {0x24, 0xb0}, /* normal colors */ |
| 623 | {0x25, 0x90}, |
| 624 | {0x10, 0x43}, |
| 625 | }; |
| 626 | |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 627 | static const struct ov_i2c_regvals norm_3620b[] = { |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 628 | /* |
| 629 | * From the datasheet: "Note that after writing to register COMH |
| 630 | * (0x12) to change the sensor mode, registers related to the |
| 631 | * sensor’s cropping window will be reset back to their default |
| 632 | * values." |
| 633 | * |
| 634 | * "wait 4096 external clock ... to make sure the sensor is |
| 635 | * stable and ready to access registers" i.e. 160us at 24MHz |
| 636 | */ |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 637 | { 0x12, 0x80 }, /* COMH reset */ |
| 638 | { 0x12, 0x00 }, /* QXGA, master */ |
| 639 | |
| 640 | /* |
| 641 | * 11 CLKRC "Clock Rate Control" |
| 642 | * [7] internal frequency doublers: on |
| 643 | * [6] video port mode: master |
| 644 | * [5:0] clock divider: 1 |
| 645 | */ |
| 646 | { 0x11, 0x80 }, |
| 647 | |
| 648 | /* |
| 649 | * 13 COMI "Common Control I" |
| 650 | * = 192 (0xC0) 11000000 |
| 651 | * COMI[7] "AEC speed selection" |
| 652 | * = 1 (0x01) 1....... "Faster AEC correction" |
| 653 | * COMI[6] "AEC speed step selection" |
| 654 | * = 1 (0x01) .1...... "Big steps, fast" |
| 655 | * COMI[5] "Banding filter on off" |
| 656 | * = 0 (0x00) ..0..... "Off" |
| 657 | * COMI[4] "Banding filter option" |
| 658 | * = 0 (0x00) ...0.... "Main clock is 48 MHz and |
| 659 | * the PLL is ON" |
| 660 | * COMI[3] "Reserved" |
| 661 | * = 0 (0x00) ....0... |
| 662 | * COMI[2] "AGC auto manual control selection" |
| 663 | * = 0 (0x00) .....0.. "Manual" |
| 664 | * COMI[1] "AWB auto manual control selection" |
| 665 | * = 0 (0x00) ......0. "Manual" |
| 666 | * COMI[0] "Exposure control" |
| 667 | * = 0 (0x00) .......0 "Manual" |
| 668 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 669 | { 0x13, 0xc0 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 670 | |
| 671 | /* |
| 672 | * 09 COMC "Common Control C" |
| 673 | * = 8 (0x08) 00001000 |
| 674 | * COMC[7:5] "Reserved" |
| 675 | * = 0 (0x00) 000..... |
| 676 | * COMC[4] "Sleep Mode Enable" |
| 677 | * = 0 (0x00) ...0.... "Normal mode" |
| 678 | * COMC[3:2] "Sensor sampling reset timing selection" |
| 679 | * = 2 (0x02) ....10.. "Longer reset time" |
| 680 | * COMC[1:0] "Output drive current select" |
| 681 | * = 0 (0x00) ......00 "Weakest" |
| 682 | */ |
| 683 | { 0x09, 0x08 }, |
| 684 | |
| 685 | /* |
| 686 | * 0C COMD "Common Control D" |
| 687 | * = 8 (0x08) 00001000 |
| 688 | * COMD[7] "Reserved" |
| 689 | * = 0 (0x00) 0....... |
| 690 | * COMD[6] "Swap MSB and LSB at the output port" |
| 691 | * = 0 (0x00) .0...... "False" |
| 692 | * COMD[5:3] "Reserved" |
| 693 | * = 1 (0x01) ..001... |
| 694 | * COMD[2] "Output Average On Off" |
| 695 | * = 0 (0x00) .....0.. "Output Normal" |
| 696 | * COMD[1] "Sensor precharge voltage selection" |
| 697 | * = 0 (0x00) ......0. "Selects internal |
| 698 | * reference precharge |
| 699 | * voltage" |
| 700 | * COMD[0] "Snapshot option" |
| 701 | * = 0 (0x00) .......0 "Enable live video output |
| 702 | * after snapshot sequence" |
| 703 | */ |
| 704 | { 0x0c, 0x08 }, |
| 705 | |
| 706 | /* |
| 707 | * 0D COME "Common Control E" |
| 708 | * = 161 (0xA1) 10100001 |
| 709 | * COME[7] "Output average option" |
| 710 | * = 1 (0x01) 1....... "Output average of 4 pixels" |
| 711 | * COME[6] "Anti-blooming control" |
| 712 | * = 0 (0x00) .0...... "Off" |
| 713 | * COME[5:3] "Reserved" |
| 714 | * = 4 (0x04) ..100... |
| 715 | * COME[2] "Clock output power down pin status" |
| 716 | * = 0 (0x00) .....0.. "Tri-state data output pin |
| 717 | * on power down" |
| 718 | * COME[1] "Data output pin status selection at power down" |
| 719 | * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK, |
| 720 | * HREF, and CHSYNC pins on |
| 721 | * power down" |
| 722 | * COME[0] "Auto zero circuit select" |
| 723 | * = 1 (0x01) .......1 "On" |
| 724 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 725 | { 0x0d, 0xa1 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 726 | |
| 727 | /* |
| 728 | * 0E COMF "Common Control F" |
| 729 | * = 112 (0x70) 01110000 |
| 730 | * COMF[7] "System clock selection" |
| 731 | * = 0 (0x00) 0....... "Use 24 MHz system clock" |
| 732 | * COMF[6:4] "Reserved" |
| 733 | * = 7 (0x07) .111.... |
| 734 | * COMF[3] "Manual auto negative offset canceling selection" |
| 735 | * = 0 (0x00) ....0... "Auto detect negative |
| 736 | * offset and cancel it" |
| 737 | * COMF[2:0] "Reserved" |
| 738 | * = 0 (0x00) .....000 |
| 739 | */ |
| 740 | { 0x0e, 0x70 }, |
| 741 | |
| 742 | /* |
| 743 | * 0F COMG "Common Control G" |
| 744 | * = 66 (0x42) 01000010 |
| 745 | * COMG[7] "Optical black output selection" |
| 746 | * = 0 (0x00) 0....... "Disable" |
| 747 | * COMG[6] "Black level calibrate selection" |
| 748 | * = 1 (0x01) .1...... "Use optical black pixels |
| 749 | * to calibrate" |
| 750 | * COMG[5:4] "Reserved" |
| 751 | * = 0 (0x00) ..00.... |
| 752 | * COMG[3] "Channel offset adjustment" |
| 753 | * = 0 (0x00) ....0... "Disable offset adjustment" |
| 754 | * COMG[2] "ADC black level calibration option" |
| 755 | * = 0 (0x00) .....0.. "Use B/G line and G/R |
| 756 | * line to calibrate each |
| 757 | * channel's black level" |
| 758 | * COMG[1] "Reserved" |
| 759 | * = 1 (0x01) ......1. |
| 760 | * COMG[0] "ADC black level calibration enable" |
| 761 | * = 0 (0x00) .......0 "Disable" |
| 762 | */ |
| 763 | { 0x0f, 0x42 }, |
| 764 | |
| 765 | /* |
| 766 | * 14 COMJ "Common Control J" |
| 767 | * = 198 (0xC6) 11000110 |
| 768 | * COMJ[7:6] "AGC gain ceiling" |
| 769 | * = 3 (0x03) 11...... "8x" |
| 770 | * COMJ[5:4] "Reserved" |
| 771 | * = 0 (0x00) ..00.... |
| 772 | * COMJ[3] "Auto banding filter" |
| 773 | * = 0 (0x00) ....0... "Banding filter is always |
| 774 | * on off depending on |
| 775 | * COMI[5] setting" |
| 776 | * COMJ[2] "VSYNC drop option" |
| 777 | * = 1 (0x01) .....1.. "SYNC is dropped if frame |
| 778 | * data is dropped" |
| 779 | * COMJ[1] "Frame data drop" |
| 780 | * = 1 (0x01) ......1. "Drop frame data if |
| 781 | * exposure is not within |
| 782 | * tolerance. In AEC mode, |
| 783 | * data is normally dropped |
| 784 | * when data is out of |
| 785 | * range." |
| 786 | * COMJ[0] "Reserved" |
| 787 | * = 0 (0x00) .......0 |
| 788 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 789 | { 0x14, 0xc6 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 790 | |
| 791 | /* |
| 792 | * 15 COMK "Common Control K" |
| 793 | * = 2 (0x02) 00000010 |
| 794 | * COMK[7] "CHSYNC pin output swap" |
| 795 | * = 0 (0x00) 0....... "CHSYNC" |
| 796 | * COMK[6] "HREF pin output swap" |
| 797 | * = 0 (0x00) .0...... "HREF" |
| 798 | * COMK[5] "PCLK output selection" |
| 799 | * = 0 (0x00) ..0..... "PCLK always output" |
| 800 | * COMK[4] "PCLK edge selection" |
| 801 | * = 0 (0x00) ...0.... "Data valid on falling edge" |
| 802 | * COMK[3] "HREF output polarity" |
| 803 | * = 0 (0x00) ....0... "positive" |
| 804 | * COMK[2] "Reserved" |
| 805 | * = 0 (0x00) .....0.. |
| 806 | * COMK[1] "VSYNC polarity" |
| 807 | * = 1 (0x01) ......1. "negative" |
| 808 | * COMK[0] "HSYNC polarity" |
| 809 | * = 0 (0x00) .......0 "positive" |
| 810 | */ |
| 811 | { 0x15, 0x02 }, |
| 812 | |
| 813 | /* |
| 814 | * 33 CHLF "Current Control" |
| 815 | * = 9 (0x09) 00001001 |
| 816 | * CHLF[7:6] "Sensor current control" |
| 817 | * = 0 (0x00) 00...... |
| 818 | * CHLF[5] "Sensor current range control" |
| 819 | * = 0 (0x00) ..0..... "normal range" |
| 820 | * CHLF[4] "Sensor current" |
| 821 | * = 0 (0x00) ...0.... "normal current" |
| 822 | * CHLF[3] "Sensor buffer current control" |
| 823 | * = 1 (0x01) ....1... "half current" |
| 824 | * CHLF[2] "Column buffer current control" |
| 825 | * = 0 (0x00) .....0.. "normal current" |
| 826 | * CHLF[1] "Analog DSP current control" |
| 827 | * = 0 (0x00) ......0. "normal current" |
| 828 | * CHLF[1] "ADC current control" |
| 829 | * = 0 (0x00) ......0. "normal current" |
| 830 | */ |
| 831 | { 0x33, 0x09 }, |
| 832 | |
| 833 | /* |
| 834 | * 34 VBLM "Blooming Control" |
| 835 | * = 80 (0x50) 01010000 |
| 836 | * VBLM[7] "Hard soft reset switch" |
| 837 | * = 0 (0x00) 0....... "Hard reset" |
| 838 | * VBLM[6:4] "Blooming voltage selection" |
| 839 | * = 5 (0x05) .101.... |
| 840 | * VBLM[3:0] "Sensor current control" |
| 841 | * = 0 (0x00) ....0000 |
| 842 | */ |
| 843 | { 0x34, 0x50 }, |
| 844 | |
| 845 | /* |
| 846 | * 36 VCHG "Sensor Precharge Voltage Control" |
| 847 | * = 0 (0x00) 00000000 |
| 848 | * VCHG[7] "Reserved" |
| 849 | * = 0 (0x00) 0....... |
| 850 | * VCHG[6:4] "Sensor precharge voltage control" |
| 851 | * = 0 (0x00) .000.... |
| 852 | * VCHG[3:0] "Sensor array common reference" |
| 853 | * = 0 (0x00) ....0000 |
| 854 | */ |
| 855 | { 0x36, 0x00 }, |
| 856 | |
| 857 | /* |
| 858 | * 37 ADC "ADC Reference Control" |
| 859 | * = 4 (0x04) 00000100 |
| 860 | * ADC[7:4] "Reserved" |
| 861 | * = 0 (0x00) 0000.... |
| 862 | * ADC[3] "ADC input signal range" |
| 863 | * = 0 (0x00) ....0... "Input signal 1.0x" |
| 864 | * ADC[2:0] "ADC range control" |
| 865 | * = 4 (0x04) .....100 |
| 866 | */ |
| 867 | { 0x37, 0x04 }, |
| 868 | |
| 869 | /* |
| 870 | * 38 ACOM "Analog Common Ground" |
| 871 | * = 82 (0x52) 01010010 |
| 872 | * ACOM[7] "Analog gain control" |
| 873 | * = 0 (0x00) 0....... "Gain 1x" |
| 874 | * ACOM[6] "Analog black level calibration" |
| 875 | * = 1 (0x01) .1...... "On" |
| 876 | * ACOM[5:0] "Reserved" |
| 877 | * = 18 (0x12) ..010010 |
| 878 | */ |
| 879 | { 0x38, 0x52 }, |
| 880 | |
| 881 | /* |
| 882 | * 3A FREFA "Internal Reference Adjustment" |
| 883 | * = 0 (0x00) 00000000 |
| 884 | * FREFA[7:0] "Range" |
| 885 | * = 0 (0x00) 00000000 |
| 886 | */ |
| 887 | { 0x3a, 0x00 }, |
| 888 | |
| 889 | /* |
| 890 | * 3C FVOPT "Internal Reference Adjustment" |
| 891 | * = 31 (0x1F) 00011111 |
| 892 | * FVOPT[7:0] "Range" |
| 893 | * = 31 (0x1F) 00011111 |
| 894 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 895 | { 0x3c, 0x1f }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 896 | |
| 897 | /* |
| 898 | * 44 Undocumented = 0 (0x00) 00000000 |
| 899 | * 44[7:0] "It's a secret" |
| 900 | * = 0 (0x00) 00000000 |
| 901 | */ |
| 902 | { 0x44, 0x00 }, |
| 903 | |
| 904 | /* |
| 905 | * 40 Undocumented = 0 (0x00) 00000000 |
| 906 | * 40[7:0] "It's a secret" |
| 907 | * = 0 (0x00) 00000000 |
| 908 | */ |
| 909 | { 0x40, 0x00 }, |
| 910 | |
| 911 | /* |
| 912 | * 41 Undocumented = 0 (0x00) 00000000 |
| 913 | * 41[7:0] "It's a secret" |
| 914 | * = 0 (0x00) 00000000 |
| 915 | */ |
| 916 | { 0x41, 0x00 }, |
| 917 | |
| 918 | /* |
| 919 | * 42 Undocumented = 0 (0x00) 00000000 |
| 920 | * 42[7:0] "It's a secret" |
| 921 | * = 0 (0x00) 00000000 |
| 922 | */ |
| 923 | { 0x42, 0x00 }, |
| 924 | |
| 925 | /* |
| 926 | * 43 Undocumented = 0 (0x00) 00000000 |
| 927 | * 43[7:0] "It's a secret" |
| 928 | * = 0 (0x00) 00000000 |
| 929 | */ |
| 930 | { 0x43, 0x00 }, |
| 931 | |
| 932 | /* |
| 933 | * 45 Undocumented = 128 (0x80) 10000000 |
| 934 | * 45[7:0] "It's a secret" |
| 935 | * = 128 (0x80) 10000000 |
| 936 | */ |
| 937 | { 0x45, 0x80 }, |
| 938 | |
| 939 | /* |
| 940 | * 48 Undocumented = 192 (0xC0) 11000000 |
| 941 | * 48[7:0] "It's a secret" |
| 942 | * = 192 (0xC0) 11000000 |
| 943 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 944 | { 0x48, 0xc0 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 945 | |
| 946 | /* |
| 947 | * 49 Undocumented = 25 (0x19) 00011001 |
| 948 | * 49[7:0] "It's a secret" |
| 949 | * = 25 (0x19) 00011001 |
| 950 | */ |
| 951 | { 0x49, 0x19 }, |
| 952 | |
| 953 | /* |
| 954 | * 4B Undocumented = 128 (0x80) 10000000 |
| 955 | * 4B[7:0] "It's a secret" |
| 956 | * = 128 (0x80) 10000000 |
| 957 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 958 | { 0x4b, 0x80 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 959 | |
| 960 | /* |
| 961 | * 4D Undocumented = 196 (0xC4) 11000100 |
| 962 | * 4D[7:0] "It's a secret" |
| 963 | * = 196 (0xC4) 11000100 |
| 964 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 965 | { 0x4d, 0xc4 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 966 | |
| 967 | /* |
| 968 | * 35 VREF "Reference Voltage Control" |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 969 | * = 76 (0x4c) 01001100 |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 970 | * VREF[7:5] "Column high reference control" |
| 971 | * = 2 (0x02) 010..... "higher voltage" |
| 972 | * VREF[4:2] "Column low reference control" |
| 973 | * = 3 (0x03) ...011.. "Highest voltage" |
| 974 | * VREF[1:0] "Reserved" |
| 975 | * = 0 (0x00) ......00 |
| 976 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 977 | { 0x35, 0x4c }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 978 | |
| 979 | /* |
| 980 | * 3D Undocumented = 0 (0x00) 00000000 |
| 981 | * 3D[7:0] "It's a secret" |
| 982 | * = 0 (0x00) 00000000 |
| 983 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 984 | { 0x3d, 0x00 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 985 | |
| 986 | /* |
| 987 | * 3E Undocumented = 0 (0x00) 00000000 |
| 988 | * 3E[7:0] "It's a secret" |
| 989 | * = 0 (0x00) 00000000 |
| 990 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 991 | { 0x3e, 0x00 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 992 | |
| 993 | /* |
| 994 | * 3B FREFB "Internal Reference Adjustment" |
| 995 | * = 24 (0x18) 00011000 |
| 996 | * FREFB[7:0] "Range" |
| 997 | * = 24 (0x18) 00011000 |
| 998 | */ |
| 999 | { 0x3b, 0x18 }, |
| 1000 | |
| 1001 | /* |
| 1002 | * 33 CHLF "Current Control" |
| 1003 | * = 25 (0x19) 00011001 |
| 1004 | * CHLF[7:6] "Sensor current control" |
| 1005 | * = 0 (0x00) 00...... |
| 1006 | * CHLF[5] "Sensor current range control" |
| 1007 | * = 0 (0x00) ..0..... "normal range" |
| 1008 | * CHLF[4] "Sensor current" |
| 1009 | * = 1 (0x01) ...1.... "double current" |
| 1010 | * CHLF[3] "Sensor buffer current control" |
| 1011 | * = 1 (0x01) ....1... "half current" |
| 1012 | * CHLF[2] "Column buffer current control" |
| 1013 | * = 0 (0x00) .....0.. "normal current" |
| 1014 | * CHLF[1] "Analog DSP current control" |
| 1015 | * = 0 (0x00) ......0. "normal current" |
| 1016 | * CHLF[1] "ADC current control" |
| 1017 | * = 0 (0x00) ......0. "normal current" |
| 1018 | */ |
| 1019 | { 0x33, 0x19 }, |
| 1020 | |
| 1021 | /* |
| 1022 | * 34 VBLM "Blooming Control" |
| 1023 | * = 90 (0x5A) 01011010 |
| 1024 | * VBLM[7] "Hard soft reset switch" |
| 1025 | * = 0 (0x00) 0....... "Hard reset" |
| 1026 | * VBLM[6:4] "Blooming voltage selection" |
| 1027 | * = 5 (0x05) .101.... |
| 1028 | * VBLM[3:0] "Sensor current control" |
| 1029 | * = 10 (0x0A) ....1010 |
| 1030 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1031 | { 0x34, 0x5a }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1032 | |
| 1033 | /* |
| 1034 | * 3B FREFB "Internal Reference Adjustment" |
| 1035 | * = 0 (0x00) 00000000 |
| 1036 | * FREFB[7:0] "Range" |
| 1037 | * = 0 (0x00) 00000000 |
| 1038 | */ |
| 1039 | { 0x3b, 0x00 }, |
| 1040 | |
| 1041 | /* |
| 1042 | * 33 CHLF "Current Control" |
| 1043 | * = 9 (0x09) 00001001 |
| 1044 | * CHLF[7:6] "Sensor current control" |
| 1045 | * = 0 (0x00) 00...... |
| 1046 | * CHLF[5] "Sensor current range control" |
| 1047 | * = 0 (0x00) ..0..... "normal range" |
| 1048 | * CHLF[4] "Sensor current" |
| 1049 | * = 0 (0x00) ...0.... "normal current" |
| 1050 | * CHLF[3] "Sensor buffer current control" |
| 1051 | * = 1 (0x01) ....1... "half current" |
| 1052 | * CHLF[2] "Column buffer current control" |
| 1053 | * = 0 (0x00) .....0.. "normal current" |
| 1054 | * CHLF[1] "Analog DSP current control" |
| 1055 | * = 0 (0x00) ......0. "normal current" |
| 1056 | * CHLF[1] "ADC current control" |
| 1057 | * = 0 (0x00) ......0. "normal current" |
| 1058 | */ |
| 1059 | { 0x33, 0x09 }, |
| 1060 | |
| 1061 | /* |
| 1062 | * 34 VBLM "Blooming Control" |
| 1063 | * = 80 (0x50) 01010000 |
| 1064 | * VBLM[7] "Hard soft reset switch" |
| 1065 | * = 0 (0x00) 0....... "Hard reset" |
| 1066 | * VBLM[6:4] "Blooming voltage selection" |
| 1067 | * = 5 (0x05) .101.... |
| 1068 | * VBLM[3:0] "Sensor current control" |
| 1069 | * = 0 (0x00) ....0000 |
| 1070 | */ |
| 1071 | { 0x34, 0x50 }, |
| 1072 | |
| 1073 | /* |
| 1074 | * 12 COMH "Common Control H" |
| 1075 | * = 64 (0x40) 01000000 |
| 1076 | * COMH[7] "SRST" |
| 1077 | * = 0 (0x00) 0....... "No-op" |
| 1078 | * COMH[6:4] "Resolution selection" |
| 1079 | * = 4 (0x04) .100.... "XGA" |
| 1080 | * COMH[3] "Master slave selection" |
| 1081 | * = 0 (0x00) ....0... "Master mode" |
| 1082 | * COMH[2] "Internal B/R channel option" |
| 1083 | * = 0 (0x00) .....0.. "B/R use same channel" |
| 1084 | * COMH[1] "Color bar test pattern" |
| 1085 | * = 0 (0x00) ......0. "Off" |
| 1086 | * COMH[0] "Reserved" |
| 1087 | * = 0 (0x00) .......0 |
| 1088 | */ |
| 1089 | { 0x12, 0x40 }, |
| 1090 | |
| 1091 | /* |
| 1092 | * 17 HREFST "Horizontal window start" |
| 1093 | * = 31 (0x1F) 00011111 |
| 1094 | * HREFST[7:0] "Horizontal window start, 8 MSBs" |
| 1095 | * = 31 (0x1F) 00011111 |
| 1096 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1097 | { 0x17, 0x1f }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1098 | |
| 1099 | /* |
| 1100 | * 18 HREFEND "Horizontal window end" |
| 1101 | * = 95 (0x5F) 01011111 |
| 1102 | * HREFEND[7:0] "Horizontal Window End, 8 MSBs" |
| 1103 | * = 95 (0x5F) 01011111 |
| 1104 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1105 | { 0x18, 0x5f }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1106 | |
| 1107 | /* |
| 1108 | * 19 VSTRT "Vertical window start" |
| 1109 | * = 0 (0x00) 00000000 |
| 1110 | * VSTRT[7:0] "Vertical Window Start, 8 MSBs" |
| 1111 | * = 0 (0x00) 00000000 |
| 1112 | */ |
| 1113 | { 0x19, 0x00 }, |
| 1114 | |
| 1115 | /* |
| 1116 | * 1A VEND "Vertical window end" |
| 1117 | * = 96 (0x60) 01100000 |
| 1118 | * VEND[7:0] "Vertical Window End, 8 MSBs" |
| 1119 | * = 96 (0x60) 01100000 |
| 1120 | */ |
| 1121 | { 0x1a, 0x60 }, |
| 1122 | |
| 1123 | /* |
| 1124 | * 32 COMM "Common Control M" |
| 1125 | * = 18 (0x12) 00010010 |
| 1126 | * COMM[7:6] "Pixel clock divide option" |
| 1127 | * = 0 (0x00) 00...... "/1" |
| 1128 | * COMM[5:3] "Horizontal window end position, 3 LSBs" |
| 1129 | * = 2 (0x02) ..010... |
| 1130 | * COMM[2:0] "Horizontal window start position, 3 LSBs" |
| 1131 | * = 2 (0x02) .....010 |
| 1132 | */ |
| 1133 | { 0x32, 0x12 }, |
| 1134 | |
| 1135 | /* |
| 1136 | * 03 COMA "Common Control A" |
| 1137 | * = 74 (0x4A) 01001010 |
| 1138 | * COMA[7:4] "AWB Update Threshold" |
| 1139 | * = 4 (0x04) 0100.... |
| 1140 | * COMA[3:2] "Vertical window end line control 2 LSBs" |
| 1141 | * = 2 (0x02) ....10.. |
| 1142 | * COMA[1:0] "Vertical window start line control 2 LSBs" |
| 1143 | * = 2 (0x02) ......10 |
| 1144 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1145 | { 0x03, 0x4a }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1146 | |
| 1147 | /* |
| 1148 | * 11 CLKRC "Clock Rate Control" |
| 1149 | * = 128 (0x80) 10000000 |
| 1150 | * CLKRC[7] "Internal frequency doublers on off seclection" |
| 1151 | * = 1 (0x01) 1....... "On" |
| 1152 | * CLKRC[6] "Digital video master slave selection" |
| 1153 | * = 0 (0x00) .0...... "Master mode, sensor |
| 1154 | * provides PCLK" |
| 1155 | * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }" |
| 1156 | * = 0 (0x00) ..000000 |
| 1157 | */ |
| 1158 | { 0x11, 0x80 }, |
| 1159 | |
| 1160 | /* |
| 1161 | * 12 COMH "Common Control H" |
| 1162 | * = 0 (0x00) 00000000 |
| 1163 | * COMH[7] "SRST" |
| 1164 | * = 0 (0x00) 0....... "No-op" |
| 1165 | * COMH[6:4] "Resolution selection" |
| 1166 | * = 0 (0x00) .000.... "QXGA" |
| 1167 | * COMH[3] "Master slave selection" |
| 1168 | * = 0 (0x00) ....0... "Master mode" |
| 1169 | * COMH[2] "Internal B/R channel option" |
| 1170 | * = 0 (0x00) .....0.. "B/R use same channel" |
| 1171 | * COMH[1] "Color bar test pattern" |
| 1172 | * = 0 (0x00) ......0. "Off" |
| 1173 | * COMH[0] "Reserved" |
| 1174 | * = 0 (0x00) .......0 |
| 1175 | */ |
| 1176 | { 0x12, 0x00 }, |
| 1177 | |
| 1178 | /* |
| 1179 | * 12 COMH "Common Control H" |
| 1180 | * = 64 (0x40) 01000000 |
| 1181 | * COMH[7] "SRST" |
| 1182 | * = 0 (0x00) 0....... "No-op" |
| 1183 | * COMH[6:4] "Resolution selection" |
| 1184 | * = 4 (0x04) .100.... "XGA" |
| 1185 | * COMH[3] "Master slave selection" |
| 1186 | * = 0 (0x00) ....0... "Master mode" |
| 1187 | * COMH[2] "Internal B/R channel option" |
| 1188 | * = 0 (0x00) .....0.. "B/R use same channel" |
| 1189 | * COMH[1] "Color bar test pattern" |
| 1190 | * = 0 (0x00) ......0. "Off" |
| 1191 | * COMH[0] "Reserved" |
| 1192 | * = 0 (0x00) .......0 |
| 1193 | */ |
| 1194 | { 0x12, 0x40 }, |
| 1195 | |
| 1196 | /* |
| 1197 | * 17 HREFST "Horizontal window start" |
| 1198 | * = 31 (0x1F) 00011111 |
| 1199 | * HREFST[7:0] "Horizontal window start, 8 MSBs" |
| 1200 | * = 31 (0x1F) 00011111 |
| 1201 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1202 | { 0x17, 0x1f }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1203 | |
| 1204 | /* |
| 1205 | * 18 HREFEND "Horizontal window end" |
| 1206 | * = 95 (0x5F) 01011111 |
| 1207 | * HREFEND[7:0] "Horizontal Window End, 8 MSBs" |
| 1208 | * = 95 (0x5F) 01011111 |
| 1209 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1210 | { 0x18, 0x5f }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1211 | |
| 1212 | /* |
| 1213 | * 19 VSTRT "Vertical window start" |
| 1214 | * = 0 (0x00) 00000000 |
| 1215 | * VSTRT[7:0] "Vertical Window Start, 8 MSBs" |
| 1216 | * = 0 (0x00) 00000000 |
| 1217 | */ |
| 1218 | { 0x19, 0x00 }, |
| 1219 | |
| 1220 | /* |
| 1221 | * 1A VEND "Vertical window end" |
| 1222 | * = 96 (0x60) 01100000 |
| 1223 | * VEND[7:0] "Vertical Window End, 8 MSBs" |
| 1224 | * = 96 (0x60) 01100000 |
| 1225 | */ |
| 1226 | { 0x1a, 0x60 }, |
| 1227 | |
| 1228 | /* |
| 1229 | * 32 COMM "Common Control M" |
| 1230 | * = 18 (0x12) 00010010 |
| 1231 | * COMM[7:6] "Pixel clock divide option" |
| 1232 | * = 0 (0x00) 00...... "/1" |
| 1233 | * COMM[5:3] "Horizontal window end position, 3 LSBs" |
| 1234 | * = 2 (0x02) ..010... |
| 1235 | * COMM[2:0] "Horizontal window start position, 3 LSBs" |
| 1236 | * = 2 (0x02) .....010 |
| 1237 | */ |
| 1238 | { 0x32, 0x12 }, |
| 1239 | |
| 1240 | /* |
| 1241 | * 03 COMA "Common Control A" |
| 1242 | * = 74 (0x4A) 01001010 |
| 1243 | * COMA[7:4] "AWB Update Threshold" |
| 1244 | * = 4 (0x04) 0100.... |
| 1245 | * COMA[3:2] "Vertical window end line control 2 LSBs" |
| 1246 | * = 2 (0x02) ....10.. |
| 1247 | * COMA[1:0] "Vertical window start line control 2 LSBs" |
| 1248 | * = 2 (0x02) ......10 |
| 1249 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1250 | { 0x03, 0x4a }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1251 | |
| 1252 | /* |
| 1253 | * 02 RED "Red Gain Control" |
| 1254 | * = 175 (0xAF) 10101111 |
| 1255 | * RED[7] "Action" |
| 1256 | * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))" |
| 1257 | * RED[6:0] "Value" |
| 1258 | * = 47 (0x2F) .0101111 |
| 1259 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1260 | { 0x02, 0xaf }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1261 | |
| 1262 | /* |
| 1263 | * 2D ADDVSL "VSYNC Pulse Width" |
| 1264 | * = 210 (0xD2) 11010010 |
| 1265 | * ADDVSL[7:0] "VSYNC pulse width, LSB" |
| 1266 | * = 210 (0xD2) 11010010 |
| 1267 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1268 | { 0x2d, 0xd2 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1269 | |
| 1270 | /* |
| 1271 | * 00 GAIN = 24 (0x18) 00011000 |
| 1272 | * GAIN[7:6] "Reserved" |
| 1273 | * = 0 (0x00) 00...... |
| 1274 | * GAIN[5] "Double" |
| 1275 | * = 0 (0x00) ..0..... "False" |
| 1276 | * GAIN[4] "Double" |
| 1277 | * = 1 (0x01) ...1.... "True" |
| 1278 | * GAIN[3:0] "Range" |
| 1279 | * = 8 (0x08) ....1000 |
| 1280 | */ |
| 1281 | { 0x00, 0x18 }, |
| 1282 | |
| 1283 | /* |
| 1284 | * 01 BLUE "Blue Gain Control" |
| 1285 | * = 240 (0xF0) 11110000 |
| 1286 | * BLUE[7] "Action" |
| 1287 | * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))" |
| 1288 | * BLUE[6:0] "Value" |
| 1289 | * = 112 (0x70) .1110000 |
| 1290 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1291 | { 0x01, 0xf0 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1292 | |
| 1293 | /* |
| 1294 | * 10 AEC "Automatic Exposure Control" |
| 1295 | * = 10 (0x0A) 00001010 |
| 1296 | * AEC[7:0] "Automatic Exposure Control, 8 MSBs" |
| 1297 | * = 10 (0x0A) 00001010 |
| 1298 | */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1299 | { 0x10, 0x0a }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1300 | |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1301 | { 0xe1, 0x67 }, |
| 1302 | { 0xe3, 0x03 }, |
| 1303 | { 0xe4, 0x26 }, |
| 1304 | { 0xe5, 0x3e }, |
| 1305 | { 0xf8, 0x01 }, |
| 1306 | { 0xff, 0x01 }, |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 1307 | }; |
| 1308 | |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1309 | static const struct ov_i2c_regvals norm_6x20[] = { |
| 1310 | { 0x12, 0x80 }, /* reset */ |
| 1311 | { 0x11, 0x01 }, |
| 1312 | { 0x03, 0x60 }, |
| 1313 | { 0x05, 0x7f }, /* For when autoadjust is off */ |
| 1314 | { 0x07, 0xa8 }, |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 1315 | /* The ratio of 0x0c and 0x0d controls the white point */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1316 | { 0x0c, 0x24 }, |
| 1317 | { 0x0d, 0x24 }, |
| 1318 | { 0x0f, 0x15 }, /* COMS */ |
| 1319 | { 0x10, 0x75 }, /* AEC Exposure time */ |
| 1320 | { 0x12, 0x24 }, /* Enable AGC */ |
| 1321 | { 0x14, 0x04 }, |
| 1322 | /* 0x16: 0x06 helps frame stability with moving objects */ |
| 1323 | { 0x16, 0x06 }, |
| 1324 | /* { 0x20, 0x30 }, * Aperture correction enable */ |
| 1325 | { 0x26, 0xb2 }, /* BLC enable */ |
| 1326 | /* 0x28: 0x05 Selects RGB format if RGB on */ |
| 1327 | { 0x28, 0x05 }, |
| 1328 | { 0x2a, 0x04 }, /* Disable framerate adjust */ |
| 1329 | /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */ |
Hans de Goede | ae49c40 | 2009-06-14 19:15:07 -0300 | [diff] [blame] | 1330 | { 0x2d, 0x85 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1331 | { 0x33, 0xa0 }, /* Color Processing Parameter */ |
| 1332 | { 0x34, 0xd2 }, /* Max A/D range */ |
| 1333 | { 0x38, 0x8b }, |
| 1334 | { 0x39, 0x40 }, |
| 1335 | |
| 1336 | { 0x3c, 0x39 }, /* Enable AEC mode changing */ |
| 1337 | { 0x3c, 0x3c }, /* Change AEC mode */ |
| 1338 | { 0x3c, 0x24 }, /* Disable AEC mode changing */ |
| 1339 | |
| 1340 | { 0x3d, 0x80 }, |
| 1341 | /* These next two registers (0x4a, 0x4b) are undocumented. |
| 1342 | * They control the color balance */ |
| 1343 | { 0x4a, 0x80 }, |
| 1344 | { 0x4b, 0x80 }, |
| 1345 | { 0x4d, 0xd2 }, /* This reduces noise a bit */ |
| 1346 | { 0x4e, 0xc1 }, |
| 1347 | { 0x4f, 0x04 }, |
| 1348 | /* Do 50-53 have any effect? */ |
| 1349 | /* Toggle 0x12[2] off and on here? */ |
| 1350 | }; |
| 1351 | |
| 1352 | static const struct ov_i2c_regvals norm_6x30[] = { |
| 1353 | { 0x12, 0x80 }, /* Reset */ |
| 1354 | { 0x00, 0x1f }, /* Gain */ |
| 1355 | { 0x01, 0x99 }, /* Blue gain */ |
| 1356 | { 0x02, 0x7c }, /* Red gain */ |
| 1357 | { 0x03, 0xc0 }, /* Saturation */ |
| 1358 | { 0x05, 0x0a }, /* Contrast */ |
| 1359 | { 0x06, 0x95 }, /* Brightness */ |
| 1360 | { 0x07, 0x2d }, /* Sharpness */ |
| 1361 | { 0x0c, 0x20 }, |
| 1362 | { 0x0d, 0x20 }, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 1363 | { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1364 | { 0x0f, 0x05 }, |
| 1365 | { 0x10, 0x9a }, |
| 1366 | { 0x11, 0x00 }, /* Pixel clock = fastest */ |
| 1367 | { 0x12, 0x24 }, /* Enable AGC and AWB */ |
| 1368 | { 0x13, 0x21 }, |
| 1369 | { 0x14, 0x80 }, |
| 1370 | { 0x15, 0x01 }, |
| 1371 | { 0x16, 0x03 }, |
| 1372 | { 0x17, 0x38 }, |
| 1373 | { 0x18, 0xea }, |
| 1374 | { 0x19, 0x04 }, |
| 1375 | { 0x1a, 0x93 }, |
| 1376 | { 0x1b, 0x00 }, |
| 1377 | { 0x1e, 0xc4 }, |
| 1378 | { 0x1f, 0x04 }, |
| 1379 | { 0x20, 0x20 }, |
| 1380 | { 0x21, 0x10 }, |
| 1381 | { 0x22, 0x88 }, |
| 1382 | { 0x23, 0xc0 }, /* Crystal circuit power level */ |
| 1383 | { 0x25, 0x9a }, /* Increase AEC black ratio */ |
| 1384 | { 0x26, 0xb2 }, /* BLC enable */ |
| 1385 | { 0x27, 0xa2 }, |
| 1386 | { 0x28, 0x00 }, |
| 1387 | { 0x29, 0x00 }, |
| 1388 | { 0x2a, 0x84 }, /* 60 Hz power */ |
| 1389 | { 0x2b, 0xa8 }, /* 60 Hz power */ |
| 1390 | { 0x2c, 0xa0 }, |
| 1391 | { 0x2d, 0x95 }, /* Enable auto-brightness */ |
| 1392 | { 0x2e, 0x88 }, |
| 1393 | { 0x33, 0x26 }, |
| 1394 | { 0x34, 0x03 }, |
| 1395 | { 0x36, 0x8f }, |
| 1396 | { 0x37, 0x80 }, |
| 1397 | { 0x38, 0x83 }, |
| 1398 | { 0x39, 0x80 }, |
| 1399 | { 0x3a, 0x0f }, |
| 1400 | { 0x3b, 0x3c }, |
| 1401 | { 0x3c, 0x1a }, |
| 1402 | { 0x3d, 0x80 }, |
| 1403 | { 0x3e, 0x80 }, |
| 1404 | { 0x3f, 0x0e }, |
| 1405 | { 0x40, 0x00 }, /* White bal */ |
| 1406 | { 0x41, 0x00 }, /* White bal */ |
| 1407 | { 0x42, 0x80 }, |
| 1408 | { 0x43, 0x3f }, /* White bal */ |
| 1409 | { 0x44, 0x80 }, |
| 1410 | { 0x45, 0x20 }, |
| 1411 | { 0x46, 0x20 }, |
| 1412 | { 0x47, 0x80 }, |
| 1413 | { 0x48, 0x7f }, |
| 1414 | { 0x49, 0x00 }, |
| 1415 | { 0x4a, 0x00 }, |
| 1416 | { 0x4b, 0x80 }, |
| 1417 | { 0x4c, 0xd0 }, |
| 1418 | { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */ |
| 1419 | { 0x4e, 0x40 }, |
| 1420 | { 0x4f, 0x07 }, /* UV avg., col. killer: max */ |
| 1421 | { 0x50, 0xff }, |
| 1422 | { 0x54, 0x23 }, /* Max AGC gain: 18dB */ |
| 1423 | { 0x55, 0xff }, |
| 1424 | { 0x56, 0x12 }, |
| 1425 | { 0x57, 0x81 }, |
| 1426 | { 0x58, 0x75 }, |
| 1427 | { 0x59, 0x01 }, /* AGC dark current comp.: +1 */ |
| 1428 | { 0x5a, 0x2c }, |
| 1429 | { 0x5b, 0x0f }, /* AWB chrominance levels */ |
| 1430 | { 0x5c, 0x10 }, |
| 1431 | { 0x3d, 0x80 }, |
| 1432 | { 0x27, 0xa6 }, |
| 1433 | { 0x12, 0x20 }, /* Toggle AWB */ |
| 1434 | { 0x12, 0x24 }, |
| 1435 | }; |
| 1436 | |
| 1437 | /* Lawrence Glaister <lg@jfm.bc.ca> reports: |
| 1438 | * |
| 1439 | * Register 0x0f in the 7610 has the following effects: |
| 1440 | * |
| 1441 | * 0x85 (AEC method 1): Best overall, good contrast range |
| 1442 | * 0x45 (AEC method 2): Very overexposed |
| 1443 | * 0xa5 (spec sheet default): Ok, but the black level is |
| 1444 | * shifted resulting in loss of contrast |
| 1445 | * 0x05 (old driver setting): very overexposed, too much |
| 1446 | * contrast |
| 1447 | */ |
| 1448 | static const struct ov_i2c_regvals norm_7610[] = { |
| 1449 | { 0x10, 0xff }, |
| 1450 | { 0x16, 0x06 }, |
| 1451 | { 0x28, 0x24 }, |
| 1452 | { 0x2b, 0xac }, |
| 1453 | { 0x12, 0x00 }, |
| 1454 | { 0x38, 0x81 }, |
| 1455 | { 0x28, 0x24 }, /* 0c */ |
| 1456 | { 0x0f, 0x85 }, /* lg's setting */ |
| 1457 | { 0x15, 0x01 }, |
| 1458 | { 0x20, 0x1c }, |
| 1459 | { 0x23, 0x2a }, |
| 1460 | { 0x24, 0x10 }, |
| 1461 | { 0x25, 0x8a }, |
| 1462 | { 0x26, 0xa2 }, |
| 1463 | { 0x27, 0xc2 }, |
| 1464 | { 0x2a, 0x04 }, |
| 1465 | { 0x2c, 0xfe }, |
| 1466 | { 0x2d, 0x93 }, |
| 1467 | { 0x30, 0x71 }, |
| 1468 | { 0x31, 0x60 }, |
| 1469 | { 0x32, 0x26 }, |
| 1470 | { 0x33, 0x20 }, |
| 1471 | { 0x34, 0x48 }, |
| 1472 | { 0x12, 0x24 }, |
| 1473 | { 0x11, 0x01 }, |
| 1474 | { 0x0c, 0x24 }, |
| 1475 | { 0x0d, 0x24 }, |
| 1476 | }; |
| 1477 | |
| 1478 | static const struct ov_i2c_regvals norm_7620[] = { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 1479 | { 0x12, 0x80 }, /* reset */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1480 | { 0x00, 0x00 }, /* gain */ |
| 1481 | { 0x01, 0x80 }, /* blue gain */ |
| 1482 | { 0x02, 0x80 }, /* red gain */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1483 | { 0x03, 0xc0 }, /* OV7670_R03_VREF */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1484 | { 0x06, 0x60 }, |
| 1485 | { 0x07, 0x00 }, |
| 1486 | { 0x0c, 0x24 }, |
| 1487 | { 0x0c, 0x24 }, |
| 1488 | { 0x0d, 0x24 }, |
| 1489 | { 0x11, 0x01 }, |
| 1490 | { 0x12, 0x24 }, |
| 1491 | { 0x13, 0x01 }, |
| 1492 | { 0x14, 0x84 }, |
| 1493 | { 0x15, 0x01 }, |
| 1494 | { 0x16, 0x03 }, |
| 1495 | { 0x17, 0x2f }, |
| 1496 | { 0x18, 0xcf }, |
| 1497 | { 0x19, 0x06 }, |
| 1498 | { 0x1a, 0xf5 }, |
| 1499 | { 0x1b, 0x00 }, |
| 1500 | { 0x20, 0x18 }, |
| 1501 | { 0x21, 0x80 }, |
| 1502 | { 0x22, 0x80 }, |
| 1503 | { 0x23, 0x00 }, |
| 1504 | { 0x26, 0xa2 }, |
| 1505 | { 0x27, 0xea }, |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 1506 | { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1507 | { 0x29, 0x00 }, |
| 1508 | { 0x2a, 0x10 }, |
| 1509 | { 0x2b, 0x00 }, |
| 1510 | { 0x2c, 0x88 }, |
| 1511 | { 0x2d, 0x91 }, |
| 1512 | { 0x2e, 0x80 }, |
| 1513 | { 0x2f, 0x44 }, |
| 1514 | { 0x60, 0x27 }, |
| 1515 | { 0x61, 0x02 }, |
| 1516 | { 0x62, 0x5f }, |
| 1517 | { 0x63, 0xd5 }, |
| 1518 | { 0x64, 0x57 }, |
| 1519 | { 0x65, 0x83 }, |
| 1520 | { 0x66, 0x55 }, |
| 1521 | { 0x67, 0x92 }, |
| 1522 | { 0x68, 0xcf }, |
| 1523 | { 0x69, 0x76 }, |
| 1524 | { 0x6a, 0x22 }, |
| 1525 | { 0x6b, 0x00 }, |
| 1526 | { 0x6c, 0x02 }, |
| 1527 | { 0x6d, 0x44 }, |
| 1528 | { 0x6e, 0x80 }, |
| 1529 | { 0x6f, 0x1d }, |
| 1530 | { 0x70, 0x8b }, |
| 1531 | { 0x71, 0x00 }, |
| 1532 | { 0x72, 0x14 }, |
| 1533 | { 0x73, 0x54 }, |
| 1534 | { 0x74, 0x00 }, |
| 1535 | { 0x75, 0x8e }, |
| 1536 | { 0x76, 0x00 }, |
| 1537 | { 0x77, 0xff }, |
| 1538 | { 0x78, 0x80 }, |
| 1539 | { 0x79, 0x80 }, |
| 1540 | { 0x7a, 0x80 }, |
| 1541 | { 0x7b, 0xe2 }, |
| 1542 | { 0x7c, 0x00 }, |
| 1543 | }; |
| 1544 | |
| 1545 | /* 7640 and 7648. The defaults should be OK for most registers. */ |
| 1546 | static const struct ov_i2c_regvals norm_7640[] = { |
| 1547 | { 0x12, 0x80 }, |
| 1548 | { 0x12, 0x14 }, |
| 1549 | }; |
| 1550 | |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 1551 | static const struct ov_regvals init_519_ov7660[] = { |
| 1552 | { 0x5d, 0x03 }, /* Turn off suspend mode */ |
| 1553 | { 0x53, 0x9b }, /* 0x9f enables the (unused) microcontroller */ |
| 1554 | { 0x54, 0x0f }, /* bit2 (jpeg enable) */ |
| 1555 | { 0xa2, 0x20 }, /* a2-a5 are undocumented */ |
| 1556 | { 0xa3, 0x18 }, |
| 1557 | { 0xa4, 0x04 }, |
| 1558 | { 0xa5, 0x28 }, |
| 1559 | { 0x37, 0x00 }, /* SetUsbInit */ |
| 1560 | { 0x55, 0x02 }, /* 4.096 Mhz audio clock */ |
| 1561 | /* Enable both fields, YUV Input, disable defect comp (why?) */ |
| 1562 | { 0x20, 0x0c }, /* 0x0d does U <-> V swap */ |
| 1563 | { 0x21, 0x38 }, |
| 1564 | { 0x22, 0x1d }, |
| 1565 | { 0x17, 0x50 }, /* undocumented */ |
| 1566 | { 0x37, 0x00 }, /* undocumented */ |
| 1567 | { 0x40, 0xff }, /* I2C timeout counter */ |
| 1568 | { 0x46, 0x00 }, /* I2C clock prescaler */ |
| 1569 | }; |
| 1570 | static const struct ov_i2c_regvals norm_7660[] = { |
| 1571 | {OV7670_R12_COM7, OV7670_COM7_RESET}, |
| 1572 | {OV7670_R11_CLKRC, 0x81}, |
| 1573 | {0x92, 0x00}, /* DM_LNL */ |
| 1574 | {0x93, 0x00}, /* DM_LNH */ |
| 1575 | {0x9d, 0x4c}, /* BD50ST */ |
| 1576 | {0x9e, 0x3f}, /* BD60ST */ |
| 1577 | {OV7670_R3B_COM11, 0x02}, |
| 1578 | {OV7670_R13_COM8, 0xf5}, |
| 1579 | {OV7670_R10_AECH, 0x00}, |
| 1580 | {OV7670_R00_GAIN, 0x00}, |
| 1581 | {OV7670_R01_BLUE, 0x7c}, |
| 1582 | {OV7670_R02_RED, 0x9d}, |
| 1583 | {OV7670_R12_COM7, 0x00}, |
| 1584 | {OV7670_R04_COM1, 00}, |
| 1585 | {OV7670_R18_HSTOP, 0x01}, |
| 1586 | {OV7670_R17_HSTART, 0x13}, |
| 1587 | {OV7670_R32_HREF, 0x92}, |
| 1588 | {OV7670_R19_VSTART, 0x02}, |
| 1589 | {OV7670_R1A_VSTOP, 0x7a}, |
| 1590 | {OV7670_R03_VREF, 0x00}, |
| 1591 | {OV7670_R0E_COM5, 0x04}, |
| 1592 | {OV7670_R0F_COM6, 0x62}, |
| 1593 | {OV7670_R15_COM10, 0x00}, |
| 1594 | {0x16, 0x02}, /* RSVD */ |
| 1595 | {0x1b, 0x00}, /* PSHFT */ |
| 1596 | {OV7670_R1E_MVFP, 0x01}, |
| 1597 | {0x29, 0x3c}, /* RSVD */ |
| 1598 | {0x33, 0x00}, /* CHLF */ |
| 1599 | {0x34, 0x07}, /* ARBLM */ |
| 1600 | {0x35, 0x84}, /* RSVD */ |
| 1601 | {0x36, 0x00}, /* RSVD */ |
| 1602 | {0x37, 0x04}, /* ADC */ |
| 1603 | {0x39, 0x43}, /* OFON */ |
| 1604 | {OV7670_R3A_TSLB, 0x00}, |
| 1605 | {OV7670_R3C_COM12, 0x6c}, |
| 1606 | {OV7670_R3D_COM13, 0x98}, |
| 1607 | {OV7670_R3F_EDGE, 0x23}, |
| 1608 | {OV7670_R40_COM15, 0xc1}, |
| 1609 | {OV7670_R41_COM16, 0x22}, |
| 1610 | {0x6b, 0x0a}, /* DBLV */ |
| 1611 | {0xa1, 0x08}, /* RSVD */ |
| 1612 | {0x69, 0x80}, /* HV */ |
| 1613 | {0x43, 0xf0}, /* RSVD.. */ |
| 1614 | {0x44, 0x10}, |
| 1615 | {0x45, 0x78}, |
| 1616 | {0x46, 0xa8}, |
| 1617 | {0x47, 0x60}, |
| 1618 | {0x48, 0x80}, |
| 1619 | {0x59, 0xba}, |
| 1620 | {0x5a, 0x9a}, |
| 1621 | {0x5b, 0x22}, |
| 1622 | {0x5c, 0xb9}, |
| 1623 | {0x5d, 0x9b}, |
| 1624 | {0x5e, 0x10}, |
| 1625 | {0x5f, 0xe0}, |
| 1626 | {0x60, 0x85}, |
| 1627 | {0x61, 0x60}, |
| 1628 | {0x9f, 0x9d}, /* RSVD */ |
| 1629 | {0xa0, 0xa0}, /* DSPC2 */ |
| 1630 | {0x4f, 0x60}, /* matrix */ |
| 1631 | {0x50, 0x64}, |
| 1632 | {0x51, 0x04}, |
| 1633 | {0x52, 0x18}, |
| 1634 | {0x53, 0x3c}, |
| 1635 | {0x54, 0x54}, |
| 1636 | {0x55, 0x40}, |
| 1637 | {0x56, 0x40}, |
| 1638 | {0x57, 0x40}, |
| 1639 | {0x58, 0x0d}, /* matrix sign */ |
| 1640 | {0x8b, 0xcc}, /* RSVD */ |
| 1641 | {0x8c, 0xcc}, |
| 1642 | {0x8d, 0xcf}, |
| 1643 | {0x6c, 0x40}, /* gamma curve */ |
| 1644 | {0x6d, 0xe0}, |
| 1645 | {0x6e, 0xa0}, |
| 1646 | {0x6f, 0x80}, |
| 1647 | {0x70, 0x70}, |
| 1648 | {0x71, 0x80}, |
| 1649 | {0x72, 0x60}, |
| 1650 | {0x73, 0x60}, |
| 1651 | {0x74, 0x50}, |
| 1652 | {0x75, 0x40}, |
| 1653 | {0x76, 0x38}, |
| 1654 | {0x77, 0x3c}, |
| 1655 | {0x78, 0x32}, |
| 1656 | {0x79, 0x1a}, |
| 1657 | {0x7a, 0x28}, |
| 1658 | {0x7b, 0x24}, |
| 1659 | {0x7c, 0x04}, /* gamma curve */ |
| 1660 | {0x7d, 0x12}, |
| 1661 | {0x7e, 0x26}, |
| 1662 | {0x7f, 0x46}, |
| 1663 | {0x80, 0x54}, |
| 1664 | {0x81, 0x64}, |
| 1665 | {0x82, 0x70}, |
| 1666 | {0x83, 0x7c}, |
| 1667 | {0x84, 0x86}, |
| 1668 | {0x85, 0x8e}, |
| 1669 | {0x86, 0x9c}, |
| 1670 | {0x87, 0xab}, |
| 1671 | {0x88, 0xc4}, |
| 1672 | {0x89, 0xd1}, |
| 1673 | {0x8a, 0xe5}, |
| 1674 | {OV7670_R14_COM9, 0x1e}, |
| 1675 | {OV7670_R24_AEW, 0x80}, |
| 1676 | {OV7670_R25_AEB, 0x72}, |
| 1677 | {OV7670_R26_VPT, 0xb3}, |
| 1678 | {0x62, 0x80}, /* LCC1 */ |
| 1679 | {0x63, 0x80}, /* LCC2 */ |
| 1680 | {0x64, 0x06}, /* LCC3 */ |
| 1681 | {0x65, 0x00}, /* LCC4 */ |
| 1682 | {0x66, 0x01}, /* LCC5 */ |
| 1683 | {0x94, 0x0e}, /* RSVD.. */ |
| 1684 | {0x95, 0x14}, |
| 1685 | {OV7670_R13_COM8, OV7670_COM8_FASTAEC |
| 1686 | | OV7670_COM8_AECSTEP |
| 1687 | | OV7670_COM8_BFILT |
| 1688 | | 0x10 |
| 1689 | | OV7670_COM8_AGC |
| 1690 | | OV7670_COM8_AWB |
| 1691 | | OV7670_COM8_AEC}, |
| 1692 | {0xa1, 0xc8} |
| 1693 | }; |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 1694 | static const struct ov_i2c_regvals norm_9600[] = { |
| 1695 | {0x12, 0x80}, |
| 1696 | {0x0c, 0x28}, |
| 1697 | {0x11, 0x80}, |
| 1698 | {0x13, 0xb5}, |
| 1699 | {0x14, 0x3e}, |
| 1700 | {0x1b, 0x04}, |
| 1701 | {0x24, 0xb0}, |
| 1702 | {0x25, 0x90}, |
| 1703 | {0x26, 0x94}, |
| 1704 | {0x35, 0x90}, |
| 1705 | {0x37, 0x07}, |
| 1706 | {0x38, 0x08}, |
| 1707 | {0x01, 0x8e}, |
| 1708 | {0x02, 0x85} |
| 1709 | }; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 1710 | |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1711 | /* 7670. Defaults taken from OmniVision provided data, |
| 1712 | * as provided by Jonathan Corbet of OLPC */ |
| 1713 | static const struct ov_i2c_regvals norm_7670[] = { |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1714 | { OV7670_R12_COM7, OV7670_COM7_RESET }, |
| 1715 | { OV7670_R3A_TSLB, 0x04 }, /* OV */ |
| 1716 | { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */ |
| 1717 | { OV7670_R11_CLKRC, 0x01 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1718 | /* |
| 1719 | * Set the hardware window. These values from OV don't entirely |
| 1720 | * make sense - hstop is less than hstart. But they work... |
| 1721 | */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1722 | { OV7670_R17_HSTART, 0x13 }, |
| 1723 | { OV7670_R18_HSTOP, 0x01 }, |
| 1724 | { OV7670_R32_HREF, 0xb6 }, |
| 1725 | { OV7670_R19_VSTART, 0x02 }, |
| 1726 | { OV7670_R1A_VSTOP, 0x7a }, |
| 1727 | { OV7670_R03_VREF, 0x0a }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1728 | |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1729 | { OV7670_R0C_COM3, 0x00 }, |
| 1730 | { OV7670_R3E_COM14, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1731 | /* Mystery scaling numbers */ |
| 1732 | { 0x70, 0x3a }, |
| 1733 | { 0x71, 0x35 }, |
| 1734 | { 0x72, 0x11 }, |
| 1735 | { 0x73, 0xf0 }, |
| 1736 | { 0xa2, 0x02 }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1737 | /* { OV7670_R15_COM10, 0x0 }, */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1738 | |
| 1739 | /* Gamma curve values */ |
| 1740 | { 0x7a, 0x20 }, |
| 1741 | { 0x7b, 0x10 }, |
| 1742 | { 0x7c, 0x1e }, |
| 1743 | { 0x7d, 0x35 }, |
| 1744 | { 0x7e, 0x5a }, |
| 1745 | { 0x7f, 0x69 }, |
| 1746 | { 0x80, 0x76 }, |
| 1747 | { 0x81, 0x80 }, |
| 1748 | { 0x82, 0x88 }, |
| 1749 | { 0x83, 0x8f }, |
| 1750 | { 0x84, 0x96 }, |
| 1751 | { 0x85, 0xa3 }, |
| 1752 | { 0x86, 0xaf }, |
| 1753 | { 0x87, 0xc4 }, |
| 1754 | { 0x88, 0xd7 }, |
| 1755 | { 0x89, 0xe8 }, |
| 1756 | |
| 1757 | /* AGC and AEC parameters. Note we start by disabling those features, |
| 1758 | then turn them only after tweaking the values. */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1759 | { OV7670_R13_COM8, OV7670_COM8_FASTAEC |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1760 | | OV7670_COM8_AECSTEP |
| 1761 | | OV7670_COM8_BFILT }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1762 | { OV7670_R00_GAIN, 0x00 }, |
| 1763 | { OV7670_R10_AECH, 0x00 }, |
| 1764 | { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */ |
| 1765 | { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */ |
| 1766 | { OV7670_RA5_BD50MAX, 0x05 }, |
| 1767 | { OV7670_RAB_BD60MAX, 0x07 }, |
| 1768 | { OV7670_R24_AEW, 0x95 }, |
| 1769 | { OV7670_R25_AEB, 0x33 }, |
| 1770 | { OV7670_R26_VPT, 0xe3 }, |
| 1771 | { OV7670_R9F_HAECC1, 0x78 }, |
| 1772 | { OV7670_RA0_HAECC2, 0x68 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1773 | { 0xa1, 0x03 }, /* magic */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1774 | { OV7670_RA6_HAECC3, 0xd8 }, |
| 1775 | { OV7670_RA7_HAECC4, 0xd8 }, |
| 1776 | { OV7670_RA8_HAECC5, 0xf0 }, |
| 1777 | { OV7670_RA9_HAECC6, 0x90 }, |
| 1778 | { OV7670_RAA_HAECC7, 0x94 }, |
| 1779 | { OV7670_R13_COM8, OV7670_COM8_FASTAEC |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1780 | | OV7670_COM8_AECSTEP |
| 1781 | | OV7670_COM8_BFILT |
| 1782 | | OV7670_COM8_AGC |
| 1783 | | OV7670_COM8_AEC }, |
| 1784 | |
| 1785 | /* Almost all of these are magic "reserved" values. */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1786 | { OV7670_R0E_COM5, 0x61 }, |
| 1787 | { OV7670_R0F_COM6, 0x4b }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1788 | { 0x16, 0x02 }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1789 | { OV7670_R1E_MVFP, 0x07 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1790 | { 0x21, 0x02 }, |
| 1791 | { 0x22, 0x91 }, |
| 1792 | { 0x29, 0x07 }, |
| 1793 | { 0x33, 0x0b }, |
| 1794 | { 0x35, 0x0b }, |
| 1795 | { 0x37, 0x1d }, |
| 1796 | { 0x38, 0x71 }, |
| 1797 | { 0x39, 0x2a }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1798 | { OV7670_R3C_COM12, 0x78 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1799 | { 0x4d, 0x40 }, |
| 1800 | { 0x4e, 0x20 }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1801 | { OV7670_R69_GFIX, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1802 | { 0x6b, 0x4a }, |
| 1803 | { 0x74, 0x10 }, |
| 1804 | { 0x8d, 0x4f }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1805 | { 0x8e, 0x00 }, |
| 1806 | { 0x8f, 0x00 }, |
| 1807 | { 0x90, 0x00 }, |
| 1808 | { 0x91, 0x00 }, |
| 1809 | { 0x96, 0x00 }, |
| 1810 | { 0x9a, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1811 | { 0xb0, 0x84 }, |
| 1812 | { 0xb1, 0x0c }, |
| 1813 | { 0xb2, 0x0e }, |
| 1814 | { 0xb3, 0x82 }, |
| 1815 | { 0xb8, 0x0a }, |
| 1816 | |
| 1817 | /* More reserved magic, some of which tweaks white balance */ |
| 1818 | { 0x43, 0x0a }, |
| 1819 | { 0x44, 0xf0 }, |
| 1820 | { 0x45, 0x34 }, |
| 1821 | { 0x46, 0x58 }, |
| 1822 | { 0x47, 0x28 }, |
| 1823 | { 0x48, 0x3a }, |
| 1824 | { 0x59, 0x88 }, |
| 1825 | { 0x5a, 0x88 }, |
| 1826 | { 0x5b, 0x44 }, |
| 1827 | { 0x5c, 0x67 }, |
| 1828 | { 0x5d, 0x49 }, |
| 1829 | { 0x5e, 0x0e }, |
| 1830 | { 0x6c, 0x0a }, |
| 1831 | { 0x6d, 0x55 }, |
| 1832 | { 0x6e, 0x11 }, |
Jean-François Moine | fc63de88 | 2011-01-13 05:35:18 -0300 | [diff] [blame] | 1833 | { 0x6f, 0x9f }, /* "9e for advance AWB" */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1834 | { 0x6a, 0x40 }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1835 | { OV7670_R01_BLUE, 0x40 }, |
| 1836 | { OV7670_R02_RED, 0x60 }, |
| 1837 | { OV7670_R13_COM8, OV7670_COM8_FASTAEC |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1838 | | OV7670_COM8_AECSTEP |
| 1839 | | OV7670_COM8_BFILT |
| 1840 | | OV7670_COM8_AGC |
| 1841 | | OV7670_COM8_AEC |
| 1842 | | OV7670_COM8_AWB }, |
| 1843 | |
| 1844 | /* Matrix coefficients */ |
| 1845 | { 0x4f, 0x80 }, |
| 1846 | { 0x50, 0x80 }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1847 | { 0x51, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1848 | { 0x52, 0x22 }, |
| 1849 | { 0x53, 0x5e }, |
| 1850 | { 0x54, 0x80 }, |
| 1851 | { 0x58, 0x9e }, |
| 1852 | |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1853 | { OV7670_R41_COM16, OV7670_COM16_AWBGAIN }, |
| 1854 | { OV7670_R3F_EDGE, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1855 | { 0x75, 0x05 }, |
| 1856 | { 0x76, 0xe1 }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1857 | { 0x4c, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1858 | { 0x77, 0x01 }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1859 | { OV7670_R3D_COM13, OV7670_COM13_GAMMA |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1860 | | OV7670_COM13_UVSAT |
| 1861 | | 2}, /* was 3 */ |
| 1862 | { 0x4b, 0x09 }, |
| 1863 | { 0xc9, 0x60 }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1864 | { OV7670_R41_COM16, 0x38 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1865 | { 0x56, 0x40 }, |
| 1866 | |
| 1867 | { 0x34, 0x11 }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 1868 | { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1869 | { 0xa4, 0x88 }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1870 | { 0x96, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1871 | { 0x97, 0x30 }, |
| 1872 | { 0x98, 0x20 }, |
| 1873 | { 0x99, 0x30 }, |
| 1874 | { 0x9a, 0x84 }, |
| 1875 | { 0x9b, 0x29 }, |
| 1876 | { 0x9c, 0x03 }, |
| 1877 | { 0x9d, 0x4c }, |
| 1878 | { 0x9e, 0x3f }, |
| 1879 | { 0x78, 0x04 }, |
| 1880 | |
| 1881 | /* Extra-weird stuff. Some sort of multiplexor register */ |
| 1882 | { 0x79, 0x01 }, |
| 1883 | { 0xc8, 0xf0 }, |
| 1884 | { 0x79, 0x0f }, |
| 1885 | { 0xc8, 0x00 }, |
| 1886 | { 0x79, 0x10 }, |
| 1887 | { 0xc8, 0x7e }, |
| 1888 | { 0x79, 0x0a }, |
| 1889 | { 0xc8, 0x80 }, |
| 1890 | { 0x79, 0x0b }, |
| 1891 | { 0xc8, 0x01 }, |
| 1892 | { 0x79, 0x0c }, |
| 1893 | { 0xc8, 0x0f }, |
| 1894 | { 0x79, 0x0d }, |
| 1895 | { 0xc8, 0x20 }, |
| 1896 | { 0x79, 0x09 }, |
| 1897 | { 0xc8, 0x80 }, |
| 1898 | { 0x79, 0x02 }, |
| 1899 | { 0xc8, 0xc0 }, |
| 1900 | { 0x79, 0x03 }, |
| 1901 | { 0xc8, 0x40 }, |
| 1902 | { 0x79, 0x05 }, |
| 1903 | { 0xc8, 0x30 }, |
| 1904 | { 0x79, 0x26 }, |
| 1905 | }; |
| 1906 | |
| 1907 | static const struct ov_i2c_regvals norm_8610[] = { |
| 1908 | { 0x12, 0x80 }, |
| 1909 | { 0x00, 0x00 }, |
| 1910 | { 0x01, 0x80 }, |
| 1911 | { 0x02, 0x80 }, |
| 1912 | { 0x03, 0xc0 }, |
| 1913 | { 0x04, 0x30 }, |
| 1914 | { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */ |
| 1915 | { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */ |
| 1916 | { 0x0a, 0x86 }, |
| 1917 | { 0x0b, 0xb0 }, |
| 1918 | { 0x0c, 0x20 }, |
| 1919 | { 0x0d, 0x20 }, |
| 1920 | { 0x11, 0x01 }, |
| 1921 | { 0x12, 0x25 }, |
| 1922 | { 0x13, 0x01 }, |
| 1923 | { 0x14, 0x04 }, |
| 1924 | { 0x15, 0x01 }, /* Lin and Win think different about UV order */ |
| 1925 | { 0x16, 0x03 }, |
| 1926 | { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */ |
| 1927 | { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */ |
| 1928 | { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */ |
| 1929 | { 0x1a, 0xf5 }, |
| 1930 | { 0x1b, 0x00 }, |
| 1931 | { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */ |
| 1932 | { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */ |
| 1933 | { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */ |
| 1934 | { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */ |
| 1935 | { 0x26, 0xa2 }, |
| 1936 | { 0x27, 0xea }, |
| 1937 | { 0x28, 0x00 }, |
| 1938 | { 0x29, 0x00 }, |
| 1939 | { 0x2a, 0x80 }, |
| 1940 | { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */ |
| 1941 | { 0x2c, 0xac }, |
| 1942 | { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */ |
| 1943 | { 0x2e, 0x80 }, |
| 1944 | { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */ |
| 1945 | { 0x4c, 0x00 }, |
| 1946 | { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */ |
| 1947 | { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */ |
| 1948 | { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */ |
| 1949 | { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */ |
| 1950 | { 0x63, 0xff }, |
| 1951 | { 0x64, 0x53 }, /* new windrv 090403 says 0x57, |
| 1952 | * maybe thats wrong */ |
| 1953 | { 0x65, 0x00 }, |
| 1954 | { 0x66, 0x55 }, |
| 1955 | { 0x67, 0xb0 }, |
| 1956 | { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */ |
| 1957 | { 0x69, 0x02 }, |
| 1958 | { 0x6a, 0x22 }, |
| 1959 | { 0x6b, 0x00 }, |
| 1960 | { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but |
| 1961 | * deleting bit7 colors the first images red */ |
| 1962 | { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */ |
| 1963 | { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */ |
| 1964 | { 0x6f, 0x01 }, |
| 1965 | { 0x70, 0x8b }, |
| 1966 | { 0x71, 0x00 }, |
| 1967 | { 0x72, 0x14 }, |
| 1968 | { 0x73, 0x54 }, |
| 1969 | { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */ |
| 1970 | { 0x75, 0x0e }, |
| 1971 | { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */ |
| 1972 | { 0x77, 0xff }, |
| 1973 | { 0x78, 0x80 }, |
| 1974 | { 0x79, 0x80 }, |
| 1975 | { 0x7a, 0x80 }, |
| 1976 | { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */ |
| 1977 | { 0x7c, 0x00 }, |
| 1978 | { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */ |
| 1979 | { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */ |
| 1980 | { 0x7f, 0xfb }, |
| 1981 | { 0x80, 0x28 }, |
| 1982 | { 0x81, 0x00 }, |
| 1983 | { 0x82, 0x23 }, |
| 1984 | { 0x83, 0x0b }, |
| 1985 | { 0x84, 0x00 }, |
| 1986 | { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */ |
| 1987 | { 0x86, 0xc9 }, |
| 1988 | { 0x87, 0x00 }, |
| 1989 | { 0x88, 0x00 }, |
| 1990 | { 0x89, 0x01 }, |
| 1991 | { 0x12, 0x20 }, |
| 1992 | { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */ |
| 1993 | }; |
| 1994 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1995 | static unsigned char ov7670_abs_to_sm(unsigned char v) |
| 1996 | { |
| 1997 | if (v > 127) |
| 1998 | return v & 0x7f; |
| 1999 | return (128 - v) | 0x80; |
| 2000 | } |
| 2001 | |
| 2002 | /* Write a OV519 register */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2003 | static void reg_w(struct sd *sd, u16 index, u16 value) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2004 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2005 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2006 | int ret, req = 0; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2007 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2008 | if (sd->gspca_dev.usb_err < 0) |
| 2009 | return; |
| 2010 | |
Wesley Post | f7c7ac4 | 2016-02-29 15:39:10 -0300 | [diff] [blame] | 2011 | /* Avoid things going to fast for the bridge with a xhci host */ |
| 2012 | udelay(150); |
| 2013 | |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2014 | switch (sd->bridge) { |
| 2015 | case BRIDGE_OV511: |
| 2016 | case BRIDGE_OV511PLUS: |
| 2017 | req = 2; |
| 2018 | break; |
| 2019 | case BRIDGE_OVFX2: |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2020 | req = 0x0a; |
| 2021 | /* fall through */ |
| 2022 | case BRIDGE_W9968CF: |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2023 | PDEBUG(D_USBO, "SET %02x %04x %04x", |
| 2024 | req, value, index); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2025 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 2026 | usb_sndctrlpipe(sd->gspca_dev.dev, 0), |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2027 | req, |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2028 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2029 | value, index, NULL, 0, 500); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2030 | goto leave; |
| 2031 | default: |
| 2032 | req = 1; |
| 2033 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2034 | |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2035 | PDEBUG(D_USBO, "SET %02x 0000 %04x %02x", |
| 2036 | req, index, value); |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 2037 | sd->gspca_dev.usb_buf[0] = value; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2038 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 2039 | usb_sndctrlpipe(sd->gspca_dev.dev, 0), |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2040 | req, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2041 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 2042 | 0, index, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 2043 | sd->gspca_dev.usb_buf, 1, 500); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2044 | leave: |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2045 | if (ret < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2046 | PERR("reg_w %02x failed %d\n", index, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2047 | sd->gspca_dev.usb_err = ret; |
| 2048 | return; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2049 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2050 | } |
| 2051 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2052 | /* Read from a OV519 register, note not valid for the w9968cf!! */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2053 | /* returns: negative is error, pos or zero is data */ |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2054 | static int reg_r(struct sd *sd, u16 index) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2055 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2056 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2057 | int ret; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2058 | int req; |
| 2059 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2060 | if (sd->gspca_dev.usb_err < 0) |
| 2061 | return -1; |
| 2062 | |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2063 | switch (sd->bridge) { |
| 2064 | case BRIDGE_OV511: |
| 2065 | case BRIDGE_OV511PLUS: |
| 2066 | req = 3; |
| 2067 | break; |
| 2068 | case BRIDGE_OVFX2: |
| 2069 | req = 0x0b; |
| 2070 | break; |
| 2071 | default: |
| 2072 | req = 1; |
| 2073 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2074 | |
Wesley Post | f7c7ac4 | 2016-02-29 15:39:10 -0300 | [diff] [blame] | 2075 | /* Avoid things going to fast for the bridge with a xhci host */ |
| 2076 | udelay(150); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2077 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 2078 | usb_rcvctrlpipe(sd->gspca_dev.dev, 0), |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2079 | req, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2080 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 2081 | 0, index, sd->gspca_dev.usb_buf, 1, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2082 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2083 | if (ret >= 0) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 2084 | ret = sd->gspca_dev.usb_buf[0]; |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2085 | PDEBUG(D_USBI, "GET %02x 0000 %04x %02x", |
| 2086 | req, index, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2087 | } else { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2088 | PERR("reg_r %02x failed %d\n", index, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2089 | sd->gspca_dev.usb_err = ret; |
Hans Verkuil | b44a551 | 2019-08-16 03:38:13 -0300 | [diff] [blame] | 2090 | /* |
| 2091 | * Make sure the result is zeroed to avoid uninitialized |
| 2092 | * values. |
| 2093 | */ |
| 2094 | gspca_dev->usb_buf[0] = 0; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2095 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2096 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2097 | return ret; |
| 2098 | } |
| 2099 | |
| 2100 | /* Read 8 values from a OV519 register */ |
| 2101 | static int reg_r8(struct sd *sd, |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2102 | u16 index) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2103 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2104 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2105 | int ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2106 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2107 | if (sd->gspca_dev.usb_err < 0) |
| 2108 | return -1; |
| 2109 | |
Wesley Post | f7c7ac4 | 2016-02-29 15:39:10 -0300 | [diff] [blame] | 2110 | /* Avoid things going to fast for the bridge with a xhci host */ |
| 2111 | udelay(150); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2112 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 2113 | usb_rcvctrlpipe(sd->gspca_dev.dev, 0), |
| 2114 | 1, /* REQ_IO */ |
| 2115 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 2116 | 0, index, sd->gspca_dev.usb_buf, 8, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2117 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2118 | if (ret >= 0) { |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 2119 | ret = sd->gspca_dev.usb_buf[0]; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2120 | } else { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2121 | PERR("reg_r8 %02x failed %d\n", index, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2122 | sd->gspca_dev.usb_err = ret; |
Hans Verkuil | b44a551 | 2019-08-16 03:38:13 -0300 | [diff] [blame] | 2123 | /* |
| 2124 | * Make sure the buffer is zeroed to avoid uninitialized |
| 2125 | * values. |
| 2126 | */ |
| 2127 | memset(gspca_dev->usb_buf, 0, 8); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2128 | } |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2129 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2130 | return ret; |
| 2131 | } |
| 2132 | |
| 2133 | /* |
| 2134 | * Writes bits at positions specified by mask to an OV51x reg. Bits that are in |
| 2135 | * the same position as 1's in "mask" are cleared and set to "value". Bits |
| 2136 | * that are in the same position as 0's in "mask" are preserved, regardless |
| 2137 | * of their respective state in "value". |
| 2138 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2139 | static void reg_w_mask(struct sd *sd, |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2140 | u16 index, |
| 2141 | u8 value, |
| 2142 | u8 mask) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2143 | { |
| 2144 | int ret; |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2145 | u8 oldval; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2146 | |
| 2147 | if (mask != 0xff) { |
| 2148 | value &= mask; /* Enforce mask on value */ |
| 2149 | ret = reg_r(sd, index); |
| 2150 | if (ret < 0) |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2151 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2152 | |
| 2153 | oldval = ret & ~mask; /* Clear the masked bits */ |
| 2154 | value |= oldval; /* Set the desired bits */ |
| 2155 | } |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2156 | reg_w(sd, index, value); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | /* |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2160 | * Writes multiple (n) byte value to a single register. Only valid with certain |
| 2161 | * registers (0x30 and 0xc4 - 0xce). |
| 2162 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2163 | static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n) |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2164 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2165 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2166 | int ret; |
| 2167 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2168 | if (sd->gspca_dev.usb_err < 0) |
| 2169 | return; |
| 2170 | |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 2171 | *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2172 | |
Wesley Post | f7c7ac4 | 2016-02-29 15:39:10 -0300 | [diff] [blame] | 2173 | /* Avoid things going to fast for the bridge with a xhci host */ |
| 2174 | udelay(150); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2175 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 2176 | usb_sndctrlpipe(sd->gspca_dev.dev, 0), |
| 2177 | 1 /* REG_IO */, |
| 2178 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 2179 | 0, index, |
| 2180 | sd->gspca_dev.usb_buf, n, 500); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2181 | if (ret < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2182 | PERR("reg_w32 %02x failed %d\n", index, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2183 | sd->gspca_dev.usb_err = ret; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2184 | } |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2185 | } |
| 2186 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2187 | static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value) |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2188 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2189 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2190 | int rc, retries; |
| 2191 | |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2192 | PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2193 | |
| 2194 | /* Three byte write cycle */ |
| 2195 | for (retries = 6; ; ) { |
| 2196 | /* Select camera register */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2197 | reg_w(sd, R51x_I2C_SADDR_3, reg); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2198 | |
| 2199 | /* Write "value" to I2C data port of OV511 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2200 | reg_w(sd, R51x_I2C_DATA, value); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2201 | |
| 2202 | /* Initiate 3-byte write cycle */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2203 | reg_w(sd, R511_I2C_CTL, 0x01); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2204 | |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 2205 | do { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2206 | rc = reg_r(sd, R511_I2C_CTL); |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 2207 | } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */ |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2208 | |
| 2209 | if (rc < 0) |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2210 | return; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2211 | |
| 2212 | if ((rc & 2) == 0) /* Ack? */ |
| 2213 | break; |
| 2214 | if (--retries < 0) { |
| 2215 | PDEBUG(D_USBO, "i2c write retries exhausted"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2216 | return; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2217 | } |
| 2218 | } |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2219 | } |
| 2220 | |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2221 | static int ov511_i2c_r(struct sd *sd, u8 reg) |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2222 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2223 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2224 | int rc, value, retries; |
| 2225 | |
| 2226 | /* Two byte write cycle */ |
| 2227 | for (retries = 6; ; ) { |
| 2228 | /* Select camera register */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2229 | reg_w(sd, R51x_I2C_SADDR_2, reg); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2230 | |
| 2231 | /* Initiate 2-byte write cycle */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2232 | reg_w(sd, R511_I2C_CTL, 0x03); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2233 | |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 2234 | do { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2235 | rc = reg_r(sd, R511_I2C_CTL); |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 2236 | } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */ |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2237 | |
| 2238 | if (rc < 0) |
| 2239 | return rc; |
| 2240 | |
| 2241 | if ((rc & 2) == 0) /* Ack? */ |
| 2242 | break; |
| 2243 | |
| 2244 | /* I2C abort */ |
| 2245 | reg_w(sd, R511_I2C_CTL, 0x10); |
| 2246 | |
| 2247 | if (--retries < 0) { |
| 2248 | PDEBUG(D_USBI, "i2c write retries exhausted"); |
| 2249 | return -1; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | /* Two byte read cycle */ |
| 2254 | for (retries = 6; ; ) { |
| 2255 | /* Initiate 2-byte read cycle */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2256 | reg_w(sd, R511_I2C_CTL, 0x05); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2257 | |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 2258 | do { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2259 | rc = reg_r(sd, R511_I2C_CTL); |
Jean-Francois Moine | 8395555 | 2009-12-12 06:58:01 -0300 | [diff] [blame] | 2260 | } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */ |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2261 | |
| 2262 | if (rc < 0) |
| 2263 | return rc; |
| 2264 | |
| 2265 | if ((rc & 2) == 0) /* Ack? */ |
| 2266 | break; |
| 2267 | |
| 2268 | /* I2C abort */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2269 | reg_w(sd, R511_I2C_CTL, 0x10); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2270 | |
| 2271 | if (--retries < 0) { |
| 2272 | PDEBUG(D_USBI, "i2c read retries exhausted"); |
| 2273 | return -1; |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | value = reg_r(sd, R51x_I2C_DATA); |
| 2278 | |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2279 | PDEBUG(D_USBI, "ov511_i2c_r %02x %02x", reg, value); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2280 | |
| 2281 | /* This is needed to make i2c_w() work */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2282 | reg_w(sd, R511_I2C_CTL, 0x05); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2283 | |
| 2284 | return value; |
| 2285 | } |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2286 | |
| 2287 | /* |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2288 | * The OV518 I2C I/O procedure is different, hence, this function. |
| 2289 | * This is normally only called from i2c_w(). Note that this function |
| 2290 | * always succeeds regardless of whether the sensor is present and working. |
| 2291 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2292 | static void ov518_i2c_w(struct sd *sd, |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2293 | u8 reg, |
| 2294 | u8 value) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2295 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2296 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
| 2297 | |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2298 | PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2299 | |
| 2300 | /* Select camera register */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2301 | reg_w(sd, R51x_I2C_SADDR_3, reg); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2302 | |
| 2303 | /* Write "value" to I2C data port of OV511 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2304 | reg_w(sd, R51x_I2C_DATA, value); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2305 | |
| 2306 | /* Initiate 3-byte write cycle */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2307 | reg_w(sd, R518_I2C_CTL, 0x01); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2308 | |
| 2309 | /* wait for write complete */ |
| 2310 | msleep(4); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2311 | reg_r8(sd, R518_I2C_CTL); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | /* |
| 2315 | * returns: negative is error, pos or zero is data |
| 2316 | * |
| 2317 | * The OV518 I2C I/O procedure is different, hence, this function. |
| 2318 | * This is normally only called from i2c_r(). Note that this function |
| 2319 | * always succeeds regardless of whether the sensor is present and working. |
| 2320 | */ |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2321 | static int ov518_i2c_r(struct sd *sd, u8 reg) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2322 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2323 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2324 | int value; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2325 | |
| 2326 | /* Select camera register */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2327 | reg_w(sd, R51x_I2C_SADDR_2, reg); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2328 | |
| 2329 | /* Initiate 2-byte write cycle */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2330 | reg_w(sd, R518_I2C_CTL, 0x03); |
Jean-François Moine | b877a9a | 2011-07-03 05:17:27 -0300 | [diff] [blame] | 2331 | reg_r8(sd, R518_I2C_CTL); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2332 | |
| 2333 | /* Initiate 2-byte read cycle */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2334 | reg_w(sd, R518_I2C_CTL, 0x05); |
Jean-François Moine | b877a9a | 2011-07-03 05:17:27 -0300 | [diff] [blame] | 2335 | reg_r8(sd, R518_I2C_CTL); |
| 2336 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2337 | value = reg_r(sd, R51x_I2C_DATA); |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2338 | PDEBUG(D_USBI, "ov518_i2c_r %02x %02x", reg, value); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2339 | return value; |
| 2340 | } |
| 2341 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2342 | static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value) |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2343 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2344 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2345 | int ret; |
| 2346 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2347 | if (sd->gspca_dev.usb_err < 0) |
| 2348 | return; |
| 2349 | |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2350 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 2351 | usb_sndctrlpipe(sd->gspca_dev.dev, 0), |
| 2352 | 0x02, |
| 2353 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2354 | (u16) value, (u16) reg, NULL, 0, 500); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2355 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2356 | if (ret < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2357 | PERR("ovfx2_i2c_w %02x failed %d\n", reg, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2358 | sd->gspca_dev.usb_err = ret; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2359 | } |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2360 | |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2361 | PDEBUG(D_USBO, "ovfx2_i2c_w %02x %02x", reg, value); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2362 | } |
| 2363 | |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2364 | static int ovfx2_i2c_r(struct sd *sd, u8 reg) |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2365 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2366 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2367 | int ret; |
| 2368 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2369 | if (sd->gspca_dev.usb_err < 0) |
| 2370 | return -1; |
| 2371 | |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2372 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 2373 | usb_rcvctrlpipe(sd->gspca_dev.dev, 0), |
| 2374 | 0x03, |
| 2375 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2376 | 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2377 | |
| 2378 | if (ret >= 0) { |
| 2379 | ret = sd->gspca_dev.usb_buf[0]; |
Jean-François Moine | 858ea5e | 2010-11-12 13:53:10 -0300 | [diff] [blame] | 2380 | PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2381 | } else { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2382 | PERR("ovfx2_i2c_r %02x failed %d\n", reg, ret); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2383 | sd->gspca_dev.usb_err = ret; |
| 2384 | } |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2385 | |
| 2386 | return ret; |
| 2387 | } |
| 2388 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2389 | static void i2c_w(struct sd *sd, u8 reg, u8 value) |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2390 | { |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2391 | if (sd->sensor_reg_cache[reg] == value) |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2392 | return; |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2393 | |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2394 | switch (sd->bridge) { |
| 2395 | case BRIDGE_OV511: |
| 2396 | case BRIDGE_OV511PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2397 | ov511_i2c_w(sd, reg, value); |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2398 | break; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2399 | case BRIDGE_OV518: |
| 2400 | case BRIDGE_OV518PLUS: |
| 2401 | case BRIDGE_OV519: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2402 | ov518_i2c_w(sd, reg, value); |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2403 | break; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2404 | case BRIDGE_OVFX2: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2405 | ovfx2_i2c_w(sd, reg, value); |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2406 | break; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2407 | case BRIDGE_W9968CF: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2408 | w9968cf_i2c_w(sd, reg, value); |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2409 | break; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2410 | } |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2411 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2412 | if (sd->gspca_dev.usb_err >= 0) { |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2413 | /* Up on sensor reset empty the register cache */ |
| 2414 | if (reg == 0x12 && (value & 0x80)) |
| 2415 | memset(sd->sensor_reg_cache, -1, |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 2416 | sizeof(sd->sensor_reg_cache)); |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2417 | else |
| 2418 | sd->sensor_reg_cache[reg] = value; |
| 2419 | } |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2420 | } |
| 2421 | |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2422 | static int i2c_r(struct sd *sd, u8 reg) |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2423 | { |
Hans de Goede | 8394bcf | 2009-10-16 11:26:22 -0300 | [diff] [blame] | 2424 | int ret = -1; |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2425 | |
| 2426 | if (sd->sensor_reg_cache[reg] != -1) |
| 2427 | return sd->sensor_reg_cache[reg]; |
| 2428 | |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2429 | switch (sd->bridge) { |
| 2430 | case BRIDGE_OV511: |
| 2431 | case BRIDGE_OV511PLUS: |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2432 | ret = ov511_i2c_r(sd, reg); |
| 2433 | break; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2434 | case BRIDGE_OV518: |
| 2435 | case BRIDGE_OV518PLUS: |
| 2436 | case BRIDGE_OV519: |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2437 | ret = ov518_i2c_r(sd, reg); |
| 2438 | break; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2439 | case BRIDGE_OVFX2: |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2440 | ret = ovfx2_i2c_r(sd, reg); |
| 2441 | break; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2442 | case BRIDGE_W9968CF: |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2443 | ret = w9968cf_i2c_r(sd, reg); |
| 2444 | break; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2445 | } |
Hans de Goede | fb1f902 | 2009-10-16 07:42:53 -0300 | [diff] [blame] | 2446 | |
| 2447 | if (ret >= 0) |
| 2448 | sd->sensor_reg_cache[reg] = ret; |
| 2449 | |
| 2450 | return ret; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2451 | } |
| 2452 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2453 | /* Writes bits at positions specified by mask to an I2C reg. Bits that are in |
| 2454 | * the same position as 1's in "mask" are cleared and set to "value". Bits |
| 2455 | * that are in the same position as 0's in "mask" are preserved, regardless |
| 2456 | * of their respective state in "value". |
| 2457 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2458 | static void i2c_w_mask(struct sd *sd, |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2459 | u8 reg, |
| 2460 | u8 value, |
| 2461 | u8 mask) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2462 | { |
| 2463 | int rc; |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2464 | u8 oldval; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2465 | |
| 2466 | value &= mask; /* Enforce mask on value */ |
| 2467 | rc = i2c_r(sd, reg); |
| 2468 | if (rc < 0) |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2469 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2470 | oldval = rc & ~mask; /* Clear the masked bits */ |
| 2471 | value |= oldval; /* Set the desired bits */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2472 | i2c_w(sd, reg, value); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | /* Temporarily stops OV511 from functioning. Must do this before changing |
| 2476 | * registers while the camera is streaming */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2477 | static inline void ov51x_stop(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2478 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2479 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
| 2480 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2481 | PDEBUG(D_STREAM, "stopping"); |
| 2482 | sd->stopped = 1; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2483 | switch (sd->bridge) { |
| 2484 | case BRIDGE_OV511: |
| 2485 | case BRIDGE_OV511PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2486 | reg_w(sd, R51x_SYS_RESET, 0x3d); |
| 2487 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2488 | case BRIDGE_OV518: |
| 2489 | case BRIDGE_OV518PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2490 | reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a); |
| 2491 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2492 | case BRIDGE_OV519: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2493 | reg_w(sd, OV519_R51_RESET1, 0x0f); |
Jean-François Moine | 5927abc | 2010-11-12 15:32:29 -0300 | [diff] [blame] | 2494 | reg_w(sd, OV519_R51_RESET1, 0x00); |
| 2495 | reg_w(sd, 0x22, 0x00); /* FRAR */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2496 | break; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2497 | case BRIDGE_OVFX2: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2498 | reg_w_mask(sd, 0x0f, 0x00, 0x02); |
| 2499 | break; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2500 | case BRIDGE_W9968CF: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2501 | reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */ |
| 2502 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2503 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not |
| 2507 | * actually stopped (for performance). */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2508 | static inline void ov51x_restart(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2509 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2510 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
| 2511 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2512 | PDEBUG(D_STREAM, "restarting"); |
| 2513 | if (!sd->stopped) |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2514 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2515 | sd->stopped = 0; |
| 2516 | |
| 2517 | /* Reinitialize the stream */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2518 | switch (sd->bridge) { |
| 2519 | case BRIDGE_OV511: |
| 2520 | case BRIDGE_OV511PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2521 | reg_w(sd, R51x_SYS_RESET, 0x00); |
| 2522 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2523 | case BRIDGE_OV518: |
| 2524 | case BRIDGE_OV518PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2525 | reg_w(sd, 0x2f, 0x80); |
| 2526 | reg_w(sd, R51x_SYS_RESET, 0x00); |
| 2527 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2528 | case BRIDGE_OV519: |
Jean-François Moine | 5927abc | 2010-11-12 15:32:29 -0300 | [diff] [blame] | 2529 | reg_w(sd, OV519_R51_RESET1, 0x0f); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2530 | reg_w(sd, OV519_R51_RESET1, 0x00); |
Jean-François Moine | 5927abc | 2010-11-12 15:32:29 -0300 | [diff] [blame] | 2531 | reg_w(sd, 0x22, 0x1d); /* FRAR */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2532 | break; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2533 | case BRIDGE_OVFX2: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2534 | reg_w_mask(sd, 0x0f, 0x02, 0x02); |
| 2535 | break; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2536 | case BRIDGE_W9968CF: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2537 | reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */ |
| 2538 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2539 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2540 | } |
| 2541 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2542 | static void ov51x_set_slave_ids(struct sd *sd, u8 slave); |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 2543 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2544 | /* This does an initial reset of an OmniVision sensor and ensures that I2C |
| 2545 | * is synchronized. Returns <0 on failure. |
| 2546 | */ |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2547 | static int init_ov_sensor(struct sd *sd, u8 slave) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2548 | { |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2549 | int i; |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2550 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2551 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2552 | ov51x_set_slave_ids(sd, slave); |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 2553 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2554 | /* Reset the sensor */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2555 | i2c_w(sd, 0x12, 0x80); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2556 | |
| 2557 | /* Wait for it to initialize */ |
| 2558 | msleep(150); |
| 2559 | |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2560 | for (i = 0; i < i2c_detect_tries; i++) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2561 | if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f && |
| 2562 | i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) { |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2563 | PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i); |
| 2564 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2565 | } |
| 2566 | |
| 2567 | /* Reset the sensor */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2568 | i2c_w(sd, 0x12, 0x80); |
| 2569 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2570 | /* Wait for it to initialize */ |
| 2571 | msleep(150); |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 2572 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2573 | /* Dummy read to sync I2C */ |
| 2574 | if (i2c_r(sd, 0x00) < 0) |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2575 | return -1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2576 | } |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2577 | return -1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2578 | } |
| 2579 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2580 | /* Set the read and write slave IDs. The "slave" argument is the write slave, |
| 2581 | * and the read slave will be set to (slave + 1). |
| 2582 | * This should not be called from outside the i2c I/O functions. |
| 2583 | * Sets I2C read and write slave IDs. Returns <0 for error |
| 2584 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2585 | static void ov51x_set_slave_ids(struct sd *sd, |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 2586 | u8 slave) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2587 | { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2588 | switch (sd->bridge) { |
| 2589 | case BRIDGE_OVFX2: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2590 | reg_w(sd, OVFX2_I2C_ADDR, slave); |
| 2591 | return; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2592 | case BRIDGE_W9968CF: |
| 2593 | sd->sensor_addr = slave; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2594 | return; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 2595 | } |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 2596 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2597 | reg_w(sd, R51x_I2C_W_SID, slave); |
| 2598 | reg_w(sd, R51x_I2C_R_SID, slave + 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2599 | } |
| 2600 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2601 | static void write_regvals(struct sd *sd, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 2602 | const struct ov_regvals *regvals, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2603 | int n) |
| 2604 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2605 | while (--n >= 0) { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2606 | reg_w(sd, regvals->reg, regvals->val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2607 | regvals++; |
| 2608 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2609 | } |
| 2610 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2611 | static void write_i2c_regvals(struct sd *sd, |
| 2612 | const struct ov_i2c_regvals *regvals, |
| 2613 | int n) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2614 | { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2615 | while (--n >= 0) { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2616 | i2c_w(sd, regvals->reg, regvals->val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2617 | regvals++; |
| 2618 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | /**************************************************************************** |
| 2622 | * |
| 2623 | * OV511 and sensor configuration |
| 2624 | * |
| 2625 | ***************************************************************************/ |
| 2626 | |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 2627 | /* This initializes the OV2x10 / OV3610 / OV3620 / OV9600 */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2628 | static void ov_hires_configure(struct sd *sd) |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 2629 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2630 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 2631 | int high, low; |
| 2632 | |
| 2633 | if (sd->bridge != BRIDGE_OVFX2) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2634 | PERR("error hires sensors only supported with ovfx2\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2635 | return; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | PDEBUG(D_PROBE, "starting ov hires configuration"); |
| 2639 | |
| 2640 | /* Detect sensor (sub)type */ |
| 2641 | high = i2c_r(sd, 0x0a); |
| 2642 | low = i2c_r(sd, 0x0b); |
| 2643 | /* info("%x, %x", high, low); */ |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 2644 | switch (high) { |
| 2645 | case 0x96: |
| 2646 | switch (low) { |
| 2647 | case 0x40: |
| 2648 | PDEBUG(D_PROBE, "Sensor is a OV2610"); |
| 2649 | sd->sensor = SEN_OV2610; |
| 2650 | return; |
| 2651 | case 0x41: |
| 2652 | PDEBUG(D_PROBE, "Sensor is a OV2610AE"); |
| 2653 | sd->sensor = SEN_OV2610AE; |
| 2654 | return; |
| 2655 | case 0xb1: |
| 2656 | PDEBUG(D_PROBE, "Sensor is a OV9600"); |
| 2657 | sd->sensor = SEN_OV9600; |
| 2658 | return; |
| 2659 | } |
| 2660 | break; |
| 2661 | case 0x36: |
| 2662 | if ((low & 0x0f) == 0x00) { |
| 2663 | PDEBUG(D_PROBE, "Sensor is a OV3610"); |
| 2664 | sd->sensor = SEN_OV3610; |
| 2665 | return; |
| 2666 | } |
| 2667 | break; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 2668 | } |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2669 | PERR("Error unknown sensor type: %02x%02x\n", high, low); |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 2670 | } |
| 2671 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2672 | /* This initializes the OV8110, OV8610 sensor. The OV8110 uses |
| 2673 | * the same register settings as the OV8610, since they are very similar. |
| 2674 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2675 | static void ov8xx0_configure(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2676 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2677 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2678 | int rc; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2679 | |
| 2680 | PDEBUG(D_PROBE, "starting ov8xx0 configuration"); |
| 2681 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2682 | /* Detect sensor (sub)type */ |
| 2683 | rc = i2c_r(sd, OV7610_REG_COM_I); |
| 2684 | if (rc < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2685 | PERR("Error detecting sensor type"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2686 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2687 | } |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2688 | if ((rc & 3) == 1) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2689 | sd->sensor = SEN_OV8610; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2690 | else |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2691 | PERR("Unknown image sensor version: %d\n", rc & 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses |
| 2695 | * the same register settings as the OV7610, since they are very similar. |
| 2696 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2697 | static void ov7xx0_configure(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2698 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2699 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2700 | int rc, high, low; |
| 2701 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2702 | PDEBUG(D_PROBE, "starting OV7xx0 configuration"); |
| 2703 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2704 | /* Detect sensor (sub)type */ |
| 2705 | rc = i2c_r(sd, OV7610_REG_COM_I); |
| 2706 | |
| 2707 | /* add OV7670 here |
| 2708 | * it appears to be wrongly detected as a 7610 by default */ |
| 2709 | if (rc < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2710 | PERR("Error detecting sensor type\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2711 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2712 | } |
| 2713 | if ((rc & 3) == 3) { |
| 2714 | /* quick hack to make OV7670s work */ |
| 2715 | high = i2c_r(sd, 0x0a); |
| 2716 | low = i2c_r(sd, 0x0b); |
| 2717 | /* info("%x, %x", high, low); */ |
Jean-François Moine | 7a5a414 | 2010-12-25 13:58:45 -0300 | [diff] [blame] | 2718 | if (high == 0x76 && (low & 0xf0) == 0x70) { |
| 2719 | PDEBUG(D_PROBE, "Sensor is an OV76%02x", low); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2720 | sd->sensor = SEN_OV7670; |
| 2721 | } else { |
| 2722 | PDEBUG(D_PROBE, "Sensor is an OV7610"); |
| 2723 | sd->sensor = SEN_OV7610; |
| 2724 | } |
| 2725 | } else if ((rc & 3) == 1) { |
| 2726 | /* I don't know what's different about the 76BE yet. */ |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 2727 | if (i2c_r(sd, 0x15) & 1) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2728 | PDEBUG(D_PROBE, "Sensor is an OV7620AE"); |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 2729 | sd->sensor = SEN_OV7620AE; |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 2730 | } else { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2731 | PDEBUG(D_PROBE, "Sensor is an OV76BE"); |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 2732 | sd->sensor = SEN_OV76BE; |
| 2733 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2734 | } else if ((rc & 3) == 0) { |
| 2735 | /* try to read product id registers */ |
| 2736 | high = i2c_r(sd, 0x0a); |
| 2737 | if (high < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2738 | PERR("Error detecting camera chip PID\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2739 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2740 | } |
| 2741 | low = i2c_r(sd, 0x0b); |
| 2742 | if (low < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2743 | PERR("Error detecting camera chip VER\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2744 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2745 | } |
| 2746 | if (high == 0x76) { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2747 | switch (low) { |
| 2748 | case 0x30: |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2749 | PERR("Sensor is an OV7630/OV7635\n"); |
| 2750 | PERR("7630 is not supported by this driver\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2751 | return; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2752 | case 0x40: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2753 | PDEBUG(D_PROBE, "Sensor is an OV7645"); |
| 2754 | sd->sensor = SEN_OV7640; /* FIXME */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2755 | break; |
| 2756 | case 0x45: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2757 | PDEBUG(D_PROBE, "Sensor is an OV7645B"); |
| 2758 | sd->sensor = SEN_OV7640; /* FIXME */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2759 | break; |
| 2760 | case 0x48: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2761 | PDEBUG(D_PROBE, "Sensor is an OV7648"); |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 2762 | sd->sensor = SEN_OV7648; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2763 | break; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 2764 | case 0x60: |
| 2765 | PDEBUG(D_PROBE, "Sensor is a OV7660"); |
| 2766 | sd->sensor = SEN_OV7660; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 2767 | break; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2768 | default: |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2769 | PERR("Unknown sensor: 0x76%02x\n", low); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2770 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2771 | } |
| 2772 | } else { |
| 2773 | PDEBUG(D_PROBE, "Sensor is an OV7620"); |
| 2774 | sd->sensor = SEN_OV7620; |
| 2775 | } |
| 2776 | } else { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2777 | PERR("Unknown image sensor version: %d\n", rc & 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2778 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2782 | static void ov6xx0_configure(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2783 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2784 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2785 | int rc; |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2786 | |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 2787 | PDEBUG(D_PROBE, "starting OV6xx0 configuration"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2788 | |
| 2789 | /* Detect sensor (sub)type */ |
| 2790 | rc = i2c_r(sd, OV7610_REG_COM_I); |
| 2791 | if (rc < 0) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2792 | PERR("Error detecting sensor type\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2793 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | /* Ugh. The first two bits are the version bits, but |
| 2797 | * the entire register value must be used. I guess OVT |
| 2798 | * underestimated how many variants they would make. */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2799 | switch (rc) { |
| 2800 | case 0x00: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2801 | sd->sensor = SEN_OV6630; |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 2802 | pr_warn("WARNING: Sensor is an OV66308. Your camera may have been misdetected in previous driver versions.\n"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2803 | break; |
| 2804 | case 0x01: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2805 | sd->sensor = SEN_OV6620; |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2806 | PDEBUG(D_PROBE, "Sensor is an OV6620"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2807 | break; |
| 2808 | case 0x02: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2809 | sd->sensor = SEN_OV6630; |
| 2810 | PDEBUG(D_PROBE, "Sensor is an OV66308AE"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2811 | break; |
| 2812 | case 0x03: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2813 | sd->sensor = SEN_OV66308AF; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2814 | PDEBUG(D_PROBE, "Sensor is an OV66308AF"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2815 | break; |
| 2816 | case 0x90: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2817 | sd->sensor = SEN_OV6630; |
Joe Perches | 133a9fe | 2011-08-21 19:56:57 -0300 | [diff] [blame] | 2818 | pr_warn("WARNING: Sensor is an OV66307. Your camera may have been misdetected in previous driver versions.\n"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2819 | break; |
| 2820 | default: |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2821 | PERR("FATAL: Unknown sensor version: 0x%02x\n", rc); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2822 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | /* Set sensor-specific vars */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2826 | sd->sif = 1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */ |
| 2830 | static void ov51x_led_control(struct sd *sd, int on) |
| 2831 | { |
Hans de Goede | 9e4d825 | 2009-06-14 06:25:06 -0300 | [diff] [blame] | 2832 | if (sd->invert_led) |
| 2833 | on = !on; |
| 2834 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2835 | switch (sd->bridge) { |
| 2836 | /* OV511 has no LED control */ |
| 2837 | case BRIDGE_OV511PLUS: |
Jean-François Moine | a23acec4 | 2010-11-12 15:07:35 -0300 | [diff] [blame] | 2838 | reg_w(sd, R511_SYS_LED_CTL, on); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2839 | break; |
| 2840 | case BRIDGE_OV518: |
| 2841 | case BRIDGE_OV518PLUS: |
Jean-François Moine | a23acec4 | 2010-11-12 15:07:35 -0300 | [diff] [blame] | 2842 | reg_w_mask(sd, R518_GPIO_OUT, 0x02 * on, 0x02); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2843 | break; |
| 2844 | case BRIDGE_OV519: |
Jean-François Moine | a23acec4 | 2010-11-12 15:07:35 -0300 | [diff] [blame] | 2845 | reg_w_mask(sd, OV519_GPIO_DATA_OUT0, on, 1); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2846 | break; |
| 2847 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2848 | } |
| 2849 | |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 2850 | static void sd_reset_snapshot(struct gspca_dev *gspca_dev) |
| 2851 | { |
| 2852 | struct sd *sd = (struct sd *) gspca_dev; |
| 2853 | |
| 2854 | if (!sd->snapshot_needs_reset) |
| 2855 | return; |
| 2856 | |
| 2857 | /* Note it is important that we clear sd->snapshot_needs_reset, |
| 2858 | before actually clearing the snapshot state in the bridge |
| 2859 | otherwise we might race with the pkt_scan interrupt handler */ |
| 2860 | sd->snapshot_needs_reset = 0; |
| 2861 | |
| 2862 | switch (sd->bridge) { |
Hans de Goede | 88e8d20 | 2010-02-20 04:45:49 -0300 | [diff] [blame] | 2863 | case BRIDGE_OV511: |
| 2864 | case BRIDGE_OV511PLUS: |
| 2865 | reg_w(sd, R51x_SYS_SNAP, 0x02); |
| 2866 | reg_w(sd, R51x_SYS_SNAP, 0x00); |
| 2867 | break; |
Hans de Goede | 92e232a | 2010-02-20 04:30:45 -0300 | [diff] [blame] | 2868 | case BRIDGE_OV518: |
| 2869 | case BRIDGE_OV518PLUS: |
| 2870 | reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */ |
| 2871 | reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */ |
| 2872 | break; |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 2873 | case BRIDGE_OV519: |
| 2874 | reg_w(sd, R51x_SYS_RESET, 0x40); |
| 2875 | reg_w(sd, R51x_SYS_RESET, 0x00); |
| 2876 | break; |
| 2877 | } |
| 2878 | } |
| 2879 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2880 | static void ov51x_upload_quan_tables(struct sd *sd) |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2881 | { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2882 | const unsigned char yQuanTable511[] = { |
| 2883 | 0, 1, 1, 2, 2, 3, 3, 4, |
| 2884 | 1, 1, 1, 2, 2, 3, 4, 4, |
| 2885 | 1, 1, 2, 2, 3, 4, 4, 4, |
| 2886 | 2, 2, 2, 3, 4, 4, 4, 4, |
| 2887 | 2, 2, 3, 4, 4, 5, 5, 5, |
| 2888 | 3, 3, 4, 4, 5, 5, 5, 5, |
| 2889 | 3, 4, 4, 4, 5, 5, 5, 5, |
| 2890 | 4, 4, 4, 4, 5, 5, 5, 5 |
| 2891 | }; |
| 2892 | |
| 2893 | const unsigned char uvQuanTable511[] = { |
| 2894 | 0, 2, 2, 3, 4, 4, 4, 4, |
| 2895 | 2, 2, 2, 4, 4, 4, 4, 4, |
| 2896 | 2, 2, 3, 4, 4, 4, 4, 4, |
| 2897 | 3, 4, 4, 4, 4, 4, 4, 4, |
| 2898 | 4, 4, 4, 4, 4, 4, 4, 4, |
| 2899 | 4, 4, 4, 4, 4, 4, 4, 4, |
| 2900 | 4, 4, 4, 4, 4, 4, 4, 4, |
| 2901 | 4, 4, 4, 4, 4, 4, 4, 4 |
| 2902 | }; |
| 2903 | |
| 2904 | /* OV518 quantization tables are 8x4 (instead of 8x8) */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2905 | const unsigned char yQuanTable518[] = { |
| 2906 | 5, 4, 5, 6, 6, 7, 7, 7, |
| 2907 | 5, 5, 5, 5, 6, 7, 7, 7, |
| 2908 | 6, 6, 6, 6, 7, 7, 7, 8, |
| 2909 | 7, 7, 6, 7, 7, 7, 8, 8 |
| 2910 | }; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2911 | const unsigned char uvQuanTable518[] = { |
| 2912 | 6, 6, 6, 7, 7, 7, 7, 7, |
| 2913 | 6, 6, 6, 7, 7, 7, 7, 7, |
| 2914 | 6, 6, 6, 7, 7, 7, 7, 8, |
| 2915 | 7, 7, 7, 7, 7, 7, 8, 8 |
| 2916 | }; |
| 2917 | |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 2918 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2919 | const unsigned char *pYTable, *pUVTable; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2920 | unsigned char val0, val1; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2921 | int i, size, reg = R51x_COMP_LUT_BEGIN; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2922 | |
| 2923 | PDEBUG(D_PROBE, "Uploading quantization tables"); |
| 2924 | |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2925 | if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) { |
| 2926 | pYTable = yQuanTable511; |
| 2927 | pUVTable = uvQuanTable511; |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 2928 | size = 32; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2929 | } else { |
| 2930 | pYTable = yQuanTable518; |
| 2931 | pUVTable = uvQuanTable518; |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 2932 | size = 16; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | for (i = 0; i < size; i++) { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2936 | val0 = *pYTable++; |
| 2937 | val1 = *pYTable++; |
| 2938 | val0 &= 0x0f; |
| 2939 | val1 &= 0x0f; |
| 2940 | val0 |= val1 << 4; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2941 | reg_w(sd, reg, val0); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2942 | |
| 2943 | val0 = *pUVTable++; |
| 2944 | val1 = *pUVTable++; |
| 2945 | val0 &= 0x0f; |
| 2946 | val1 &= 0x0f; |
| 2947 | val0 |= val1 << 4; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2948 | reg_w(sd, reg + size, val0); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2949 | |
| 2950 | reg++; |
| 2951 | } |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2952 | } |
| 2953 | |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2954 | /* This initializes the OV511/OV511+ and the sensor */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 2955 | static void ov511_configure(struct gspca_dev *gspca_dev) |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2956 | { |
| 2957 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2958 | |
| 2959 | /* For 511 and 511+ */ |
| 2960 | const struct ov_regvals init_511[] = { |
| 2961 | { R51x_SYS_RESET, 0x7f }, |
| 2962 | { R51x_SYS_INIT, 0x01 }, |
| 2963 | { R51x_SYS_RESET, 0x7f }, |
| 2964 | { R51x_SYS_INIT, 0x01 }, |
| 2965 | { R51x_SYS_RESET, 0x3f }, |
| 2966 | { R51x_SYS_INIT, 0x01 }, |
| 2967 | { R51x_SYS_RESET, 0x3d }, |
| 2968 | }; |
| 2969 | |
| 2970 | const struct ov_regvals norm_511[] = { |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 2971 | { R511_DRAM_FLOW_CTL, 0x01 }, |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 2972 | { R51x_SYS_SNAP, 0x00 }, |
| 2973 | { R51x_SYS_SNAP, 0x02 }, |
| 2974 | { R51x_SYS_SNAP, 0x00 }, |
| 2975 | { R511_FIFO_OPTS, 0x1f }, |
| 2976 | { R511_COMP_EN, 0x00 }, |
| 2977 | { R511_COMP_LUT_EN, 0x03 }, |
| 2978 | }; |
| 2979 | |
| 2980 | const struct ov_regvals norm_511_p[] = { |
| 2981 | { R511_DRAM_FLOW_CTL, 0xff }, |
| 2982 | { R51x_SYS_SNAP, 0x00 }, |
| 2983 | { R51x_SYS_SNAP, 0x02 }, |
| 2984 | { R51x_SYS_SNAP, 0x00 }, |
| 2985 | { R511_FIFO_OPTS, 0xff }, |
| 2986 | { R511_COMP_EN, 0x00 }, |
| 2987 | { R511_COMP_LUT_EN, 0x03 }, |
| 2988 | }; |
| 2989 | |
| 2990 | const struct ov_regvals compress_511[] = { |
| 2991 | { 0x70, 0x1f }, |
| 2992 | { 0x71, 0x05 }, |
| 2993 | { 0x72, 0x06 }, |
| 2994 | { 0x73, 0x06 }, |
| 2995 | { 0x74, 0x14 }, |
| 2996 | { 0x75, 0x03 }, |
| 2997 | { 0x76, 0x04 }, |
| 2998 | { 0x77, 0x04 }, |
| 2999 | }; |
| 3000 | |
| 3001 | PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID)); |
| 3002 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3003 | write_regvals(sd, init_511, ARRAY_SIZE(init_511)); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3004 | |
| 3005 | switch (sd->bridge) { |
| 3006 | case BRIDGE_OV511: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3007 | write_regvals(sd, norm_511, ARRAY_SIZE(norm_511)); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3008 | break; |
| 3009 | case BRIDGE_OV511PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3010 | write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p)); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3011 | break; |
| 3012 | } |
| 3013 | |
| 3014 | /* Init compression */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3015 | write_regvals(sd, compress_511, ARRAY_SIZE(compress_511)); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3016 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3017 | ov51x_upload_quan_tables(sd); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3018 | } |
| 3019 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3020 | /* This initializes the OV518/OV518+ and the sensor */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3021 | static void ov518_configure(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3022 | { |
| 3023 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3024 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3025 | /* For 518 and 518+ */ |
Hans de Goede | e080fcd | 2009-06-18 05:03:16 -0300 | [diff] [blame] | 3026 | const struct ov_regvals init_518[] = { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3027 | { R51x_SYS_RESET, 0x40 }, |
| 3028 | { R51x_SYS_INIT, 0xe1 }, |
| 3029 | { R51x_SYS_RESET, 0x3e }, |
| 3030 | { R51x_SYS_INIT, 0xe1 }, |
| 3031 | { R51x_SYS_RESET, 0x00 }, |
| 3032 | { R51x_SYS_INIT, 0xe1 }, |
| 3033 | { 0x46, 0x00 }, |
| 3034 | { 0x5d, 0x03 }, |
| 3035 | }; |
| 3036 | |
Hans de Goede | e080fcd | 2009-06-18 05:03:16 -0300 | [diff] [blame] | 3037 | const struct ov_regvals norm_518[] = { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3038 | { R51x_SYS_SNAP, 0x02 }, /* Reset */ |
| 3039 | { R51x_SYS_SNAP, 0x01 }, /* Enable */ |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 3040 | { 0x31, 0x0f }, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3041 | { 0x5d, 0x03 }, |
| 3042 | { 0x24, 0x9f }, |
| 3043 | { 0x25, 0x90 }, |
| 3044 | { 0x20, 0x00 }, |
| 3045 | { 0x51, 0x04 }, |
| 3046 | { 0x71, 0x19 }, |
| 3047 | { 0x2f, 0x80 }, |
| 3048 | }; |
| 3049 | |
Hans de Goede | e080fcd | 2009-06-18 05:03:16 -0300 | [diff] [blame] | 3050 | const struct ov_regvals norm_518_p[] = { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3051 | { R51x_SYS_SNAP, 0x02 }, /* Reset */ |
| 3052 | { R51x_SYS_SNAP, 0x01 }, /* Enable */ |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 3053 | { 0x31, 0x0f }, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3054 | { 0x5d, 0x03 }, |
| 3055 | { 0x24, 0x9f }, |
| 3056 | { 0x25, 0x90 }, |
| 3057 | { 0x20, 0x60 }, |
| 3058 | { 0x51, 0x02 }, |
| 3059 | { 0x71, 0x19 }, |
| 3060 | { 0x40, 0xff }, |
| 3061 | { 0x41, 0x42 }, |
| 3062 | { 0x46, 0x00 }, |
| 3063 | { 0x33, 0x04 }, |
| 3064 | { 0x21, 0x19 }, |
| 3065 | { 0x3f, 0x10 }, |
| 3066 | { 0x2f, 0x80 }, |
| 3067 | }; |
| 3068 | |
| 3069 | /* First 5 bits of custom ID reg are a revision ID on OV518 */ |
Hans de Goede | b82180d | 2013-08-22 12:41:14 -0300 | [diff] [blame] | 3070 | sd->revision = reg_r(sd, R51x_SYS_CUST_ID) & 0x1f; |
| 3071 | PDEBUG(D_PROBE, "Device revision %d", sd->revision); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3072 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3073 | write_regvals(sd, init_518, ARRAY_SIZE(init_518)); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3074 | |
| 3075 | /* Set LED GPIO pin to output mode */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3076 | reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3077 | |
| 3078 | switch (sd->bridge) { |
| 3079 | case BRIDGE_OV518: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3080 | write_regvals(sd, norm_518, ARRAY_SIZE(norm_518)); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3081 | break; |
| 3082 | case BRIDGE_OV518PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3083 | write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p)); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3084 | break; |
| 3085 | } |
| 3086 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3087 | ov51x_upload_quan_tables(sd); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3088 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3089 | reg_w(sd, 0x2f, 0x80); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3090 | } |
| 3091 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3092 | static void ov519_configure(struct sd *sd) |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3093 | { |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 3094 | static const struct ov_regvals init_519[] = { |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 3095 | { 0x5a, 0x6d }, /* EnableSystem */ |
Jean-François Moine | fc63de88 | 2011-01-13 05:35:18 -0300 | [diff] [blame] | 3096 | { 0x53, 0x9b }, /* don't enable the microcontroller */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 3097 | { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */ |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 3098 | { 0x5d, 0x03 }, |
| 3099 | { 0x49, 0x01 }, |
| 3100 | { 0x48, 0x00 }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3101 | /* Set LED pin to output mode. Bit 4 must be cleared or sensor |
| 3102 | * detection will fail. This deserves further investigation. */ |
| 3103 | { OV519_GPIO_IO_CTRL0, 0xee }, |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 3104 | { OV519_R51_RESET1, 0x0f }, |
| 3105 | { OV519_R51_RESET1, 0x00 }, |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 3106 | { 0x22, 0x00 }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3107 | /* windows reads 0x55 at this point*/ |
| 3108 | }; |
| 3109 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3110 | write_regvals(sd, init_519, ARRAY_SIZE(init_519)); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3111 | } |
| 3112 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3113 | static void ovfx2_configure(struct sd *sd) |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 3114 | { |
| 3115 | static const struct ov_regvals init_fx2[] = { |
| 3116 | { 0x00, 0x60 }, |
| 3117 | { 0x02, 0x01 }, |
| 3118 | { 0x0f, 0x1d }, |
| 3119 | { 0xe9, 0x82 }, |
| 3120 | { 0xea, 0xc7 }, |
| 3121 | { 0xeb, 0x10 }, |
| 3122 | { 0xec, 0xf6 }, |
| 3123 | }; |
| 3124 | |
| 3125 | sd->stopped = 1; |
| 3126 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3127 | write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2)); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 3128 | } |
| 3129 | |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 3130 | /* set the mode */ |
| 3131 | /* This function works for ov7660 only */ |
| 3132 | static void ov519_set_mode(struct sd *sd) |
| 3133 | { |
| 3134 | static const struct ov_regvals bridge_ov7660[2][10] = { |
| 3135 | {{0x10, 0x14}, {0x11, 0x1e}, {0x12, 0x00}, {0x13, 0x00}, |
| 3136 | {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x20, 0x0c}, |
| 3137 | {0x25, 0x01}, {0x26, 0x00}}, |
| 3138 | {{0x10, 0x28}, {0x11, 0x3c}, {0x12, 0x00}, {0x13, 0x00}, |
| 3139 | {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x20, 0x0c}, |
| 3140 | {0x25, 0x03}, {0x26, 0x00}} |
| 3141 | }; |
| 3142 | static const struct ov_i2c_regvals sensor_ov7660[2][3] = { |
| 3143 | {{0x12, 0x00}, {0x24, 0x00}, {0x0c, 0x0c}}, |
| 3144 | {{0x12, 0x00}, {0x04, 0x00}, {0x0c, 0x00}} |
| 3145 | }; |
| 3146 | static const struct ov_i2c_regvals sensor_ov7660_2[] = { |
| 3147 | {OV7670_R17_HSTART, 0x13}, |
| 3148 | {OV7670_R18_HSTOP, 0x01}, |
| 3149 | {OV7670_R32_HREF, 0x92}, |
| 3150 | {OV7670_R19_VSTART, 0x02}, |
| 3151 | {OV7670_R1A_VSTOP, 0x7a}, |
| 3152 | {OV7670_R03_VREF, 0x00}, |
| 3153 | /* {0x33, 0x00}, */ |
| 3154 | /* {0x34, 0x07}, */ |
| 3155 | /* {0x36, 0x00}, */ |
| 3156 | /* {0x6b, 0x0a}, */ |
| 3157 | }; |
| 3158 | |
| 3159 | write_regvals(sd, bridge_ov7660[sd->gspca_dev.curr_mode], |
| 3160 | ARRAY_SIZE(bridge_ov7660[0])); |
| 3161 | write_i2c_regvals(sd, sensor_ov7660[sd->gspca_dev.curr_mode], |
| 3162 | ARRAY_SIZE(sensor_ov7660[0])); |
| 3163 | write_i2c_regvals(sd, sensor_ov7660_2, |
| 3164 | ARRAY_SIZE(sensor_ov7660_2)); |
| 3165 | } |
| 3166 | |
| 3167 | /* set the frame rate */ |
| 3168 | /* This function works for sensors ov7640, ov7648 ov7660 and ov7670 only */ |
| 3169 | static void ov519_set_fr(struct sd *sd) |
| 3170 | { |
| 3171 | int fr; |
| 3172 | u8 clock; |
| 3173 | /* frame rate table with indices: |
| 3174 | * - mode = 0: 320x240, 1: 640x480 |
| 3175 | * - fr rate = 0: 30, 1: 25, 2: 20, 3: 15, 4: 10, 5: 5 |
| 3176 | * - reg = 0: bridge a4, 1: bridge 23, 2: sensor 11 (clock) |
| 3177 | */ |
| 3178 | static const u8 fr_tb[2][6][3] = { |
| 3179 | {{0x04, 0xff, 0x00}, |
| 3180 | {0x04, 0x1f, 0x00}, |
| 3181 | {0x04, 0x1b, 0x00}, |
| 3182 | {0x04, 0x15, 0x00}, |
| 3183 | {0x04, 0x09, 0x00}, |
| 3184 | {0x04, 0x01, 0x00}}, |
| 3185 | {{0x0c, 0xff, 0x00}, |
| 3186 | {0x0c, 0x1f, 0x00}, |
| 3187 | {0x0c, 0x1b, 0x00}, |
| 3188 | {0x04, 0xff, 0x01}, |
| 3189 | {0x04, 0x1f, 0x01}, |
| 3190 | {0x04, 0x1b, 0x01}}, |
| 3191 | }; |
| 3192 | |
| 3193 | if (frame_rate > 0) |
| 3194 | sd->frame_rate = frame_rate; |
| 3195 | if (sd->frame_rate >= 30) |
| 3196 | fr = 0; |
| 3197 | else if (sd->frame_rate >= 25) |
| 3198 | fr = 1; |
| 3199 | else if (sd->frame_rate >= 20) |
| 3200 | fr = 2; |
| 3201 | else if (sd->frame_rate >= 15) |
| 3202 | fr = 3; |
| 3203 | else if (sd->frame_rate >= 10) |
| 3204 | fr = 4; |
| 3205 | else |
| 3206 | fr = 5; |
| 3207 | reg_w(sd, 0xa4, fr_tb[sd->gspca_dev.curr_mode][fr][0]); |
| 3208 | reg_w(sd, 0x23, fr_tb[sd->gspca_dev.curr_mode][fr][1]); |
| 3209 | clock = fr_tb[sd->gspca_dev.curr_mode][fr][2]; |
| 3210 | if (sd->sensor == SEN_OV7660) |
| 3211 | clock |= 0x80; /* enable double clock */ |
| 3212 | ov518_i2c_w(sd, OV7670_R11_CLKRC, clock); |
| 3213 | } |
| 3214 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 3215 | static void setautogain(struct gspca_dev *gspca_dev, s32 val) |
Jean-François Moine | 58c92d3 | 2011-03-13 16:36:49 -0300 | [diff] [blame] | 3216 | { |
| 3217 | struct sd *sd = (struct sd *) gspca_dev; |
| 3218 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 3219 | i2c_w_mask(sd, 0x13, val ? 0x05 : 0x00, 0x05); |
Jean-François Moine | 58c92d3 | 2011-03-13 16:36:49 -0300 | [diff] [blame] | 3220 | } |
| 3221 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3222 | /* this function is called at probe time */ |
| 3223 | static int sd_config(struct gspca_dev *gspca_dev, |
| 3224 | const struct usb_device_id *id) |
| 3225 | { |
| 3226 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 3227 | struct cam *cam = &gspca_dev->cam; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3228 | |
Hans de Goede | 9e4d825 | 2009-06-14 06:25:06 -0300 | [diff] [blame] | 3229 | sd->bridge = id->driver_info & BRIDGE_MASK; |
Jean-François Moine | a23acec4 | 2010-11-12 15:07:35 -0300 | [diff] [blame] | 3230 | sd->invert_led = (id->driver_info & BRIDGE_INVERT_LED) != 0; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3231 | |
| 3232 | switch (sd->bridge) { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3233 | case BRIDGE_OV511: |
| 3234 | case BRIDGE_OV511PLUS: |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3235 | cam->cam_mode = ov511_vga_mode; |
| 3236 | cam->nmodes = ARRAY_SIZE(ov511_vga_mode); |
| 3237 | break; |
| 3238 | case BRIDGE_OV518: |
| 3239 | case BRIDGE_OV518PLUS: |
| 3240 | cam->cam_mode = ov518_vga_mode; |
| 3241 | cam->nmodes = ARRAY_SIZE(ov518_vga_mode); |
| 3242 | break; |
| 3243 | case BRIDGE_OV519: |
| 3244 | cam->cam_mode = ov519_vga_mode; |
| 3245 | cam->nmodes = ARRAY_SIZE(ov519_vga_mode); |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3246 | break; |
| 3247 | case BRIDGE_OVFX2: |
| 3248 | cam->cam_mode = ov519_vga_mode; |
| 3249 | cam->nmodes = ARRAY_SIZE(ov519_vga_mode); |
| 3250 | cam->bulk_size = OVFX2_BULK_SIZE; |
| 3251 | cam->bulk_nurbs = MAX_NURBS; |
| 3252 | cam->bulk = 1; |
| 3253 | break; |
| 3254 | case BRIDGE_W9968CF: |
| 3255 | cam->cam_mode = w9968cf_vga_mode; |
| 3256 | cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode); |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3257 | break; |
| 3258 | } |
| 3259 | |
Jean-François Moine | c8ef0a5 | 2011-05-23 06:08:49 -0300 | [diff] [blame] | 3260 | sd->frame_rate = 15; |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3261 | |
| 3262 | return 0; |
| 3263 | } |
| 3264 | |
| 3265 | /* this function is called at probe and resume time */ |
| 3266 | static int sd_init(struct gspca_dev *gspca_dev) |
| 3267 | { |
| 3268 | struct sd *sd = (struct sd *) gspca_dev; |
| 3269 | struct cam *cam = &gspca_dev->cam; |
| 3270 | |
| 3271 | switch (sd->bridge) { |
| 3272 | case BRIDGE_OV511: |
| 3273 | case BRIDGE_OV511PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3274 | ov511_configure(gspca_dev); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3275 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3276 | case BRIDGE_OV518: |
| 3277 | case BRIDGE_OV518PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3278 | ov518_configure(gspca_dev); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3279 | break; |
| 3280 | case BRIDGE_OV519: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3281 | ov519_configure(sd); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3282 | break; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 3283 | case BRIDGE_OVFX2: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3284 | ovfx2_configure(sd); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 3285 | break; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 3286 | case BRIDGE_W9968CF: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3287 | w9968cf_configure(sd); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 3288 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3289 | } |
| 3290 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3291 | /* The OV519 must be more aggressive about sensor detection since |
| 3292 | * I2C write will never fail if the sensor is not present. We have |
| 3293 | * to try to initialize the sensor to detect its presence */ |
Jean-François Moine | 7bbe6b8 | 2010-11-11 08:27:24 -0300 | [diff] [blame] | 3294 | sd->sensor = -1; |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 3295 | |
| 3296 | /* Test for 76xx */ |
| 3297 | if (init_ov_sensor(sd, OV7xx0_SID) >= 0) { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3298 | ov7xx0_configure(sd); |
| 3299 | |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 3300 | /* Test for 6xx0 */ |
| 3301 | } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3302 | ov6xx0_configure(sd); |
| 3303 | |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 3304 | /* Test for 8xx0 */ |
| 3305 | } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3306 | ov8xx0_configure(sd); |
| 3307 | |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3308 | /* Test for 3xxx / 2xxx */ |
| 3309 | } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) { |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3310 | ov_hires_configure(sd); |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 3311 | } else { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3312 | PERR("Can't determine sensor slave IDs\n"); |
Hans de Goede | 229bb7d | 2009-10-11 07:41:46 -0300 | [diff] [blame] | 3313 | goto error; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3314 | } |
| 3315 | |
Jean-François Moine | 7bbe6b8 | 2010-11-11 08:27:24 -0300 | [diff] [blame] | 3316 | if (sd->sensor < 0) |
| 3317 | goto error; |
| 3318 | |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3319 | ov51x_led_control(sd, 0); /* turn LED off */ |
| 3320 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3321 | switch (sd->bridge) { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3322 | case BRIDGE_OV511: |
| 3323 | case BRIDGE_OV511PLUS: |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3324 | if (sd->sif) { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3325 | cam->cam_mode = ov511_sif_mode; |
| 3326 | cam->nmodes = ARRAY_SIZE(ov511_sif_mode); |
| 3327 | } |
| 3328 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3329 | case BRIDGE_OV518: |
| 3330 | case BRIDGE_OV518PLUS: |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3331 | if (sd->sif) { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3332 | cam->cam_mode = ov518_sif_mode; |
| 3333 | cam->nmodes = ARRAY_SIZE(ov518_sif_mode); |
| 3334 | } |
| 3335 | break; |
| 3336 | case BRIDGE_OV519: |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3337 | if (sd->sif) { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3338 | cam->cam_mode = ov519_sif_mode; |
| 3339 | cam->nmodes = ARRAY_SIZE(ov519_sif_mode); |
| 3340 | } |
| 3341 | break; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3342 | case BRIDGE_OVFX2: |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 3343 | switch (sd->sensor) { |
| 3344 | case SEN_OV2610: |
| 3345 | case SEN_OV2610AE: |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3346 | cam->cam_mode = ovfx2_ov2610_mode; |
| 3347 | cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode); |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 3348 | break; |
| 3349 | case SEN_OV3610: |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3350 | cam->cam_mode = ovfx2_ov3610_mode; |
| 3351 | cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode); |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 3352 | break; |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 3353 | case SEN_OV9600: |
| 3354 | cam->cam_mode = ovfx2_ov9600_mode; |
| 3355 | cam->nmodes = ARRAY_SIZE(ovfx2_ov9600_mode); |
| 3356 | break; |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 3357 | default: |
| 3358 | if (sd->sif) { |
| 3359 | cam->cam_mode = ov519_sif_mode; |
| 3360 | cam->nmodes = ARRAY_SIZE(ov519_sif_mode); |
| 3361 | } |
| 3362 | break; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3363 | } |
| 3364 | break; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 3365 | case BRIDGE_W9968CF: |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 3366 | if (sd->sif) |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3367 | cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode) - 1; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 3368 | |
| 3369 | /* w9968cf needs initialisation once the sensor is known */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3370 | w9968cf_init(sd); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 3371 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3372 | } |
Jean-François Moine | 83db768 | 2010-11-12 07:14:08 -0300 | [diff] [blame] | 3373 | |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3374 | /* initialize the sensor */ |
| 3375 | switch (sd->sensor) { |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3376 | case SEN_OV2610: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3377 | write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610)); |
| 3378 | |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3379 | /* Enable autogain, autoexpo, awb, bandfilter */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3380 | i2c_w_mask(sd, 0x13, 0x27, 0x27); |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3381 | break; |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 3382 | case SEN_OV2610AE: |
| 3383 | write_i2c_regvals(sd, norm_2610ae, ARRAY_SIZE(norm_2610ae)); |
| 3384 | |
| 3385 | /* enable autoexpo */ |
| 3386 | i2c_w_mask(sd, 0x13, 0x05, 0x05); |
| 3387 | break; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3388 | case SEN_OV3610: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3389 | write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b)); |
| 3390 | |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3391 | /* Enable autogain, autoexpo, awb, bandfilter */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3392 | i2c_w_mask(sd, 0x13, 0x27, 0x27); |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3393 | break; |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3394 | case SEN_OV6620: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3395 | write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3396 | break; |
| 3397 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 3398 | case SEN_OV66308AF: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3399 | write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3400 | break; |
| 3401 | default: |
| 3402 | /* case SEN_OV7610: */ |
| 3403 | /* case SEN_OV76BE: */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3404 | write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)); |
| 3405 | i2c_w_mask(sd, 0x0e, 0x00, 0x40); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3406 | break; |
| 3407 | case SEN_OV7620: |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 3408 | case SEN_OV7620AE: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3409 | write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3410 | break; |
| 3411 | case SEN_OV7640: |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3412 | case SEN_OV7648: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3413 | write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3414 | break; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 3415 | case SEN_OV7660: |
| 3416 | i2c_w(sd, OV7670_R12_COM7, OV7670_COM7_RESET); |
| 3417 | msleep(14); |
| 3418 | reg_w(sd, OV519_R57_SNAPSHOT, 0x23); |
| 3419 | write_regvals(sd, init_519_ov7660, |
| 3420 | ARRAY_SIZE(init_519_ov7660)); |
| 3421 | write_i2c_regvals(sd, norm_7660, ARRAY_SIZE(norm_7660)); |
| 3422 | sd->gspca_dev.curr_mode = 1; /* 640x480 */ |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 3423 | ov519_set_mode(sd); |
| 3424 | ov519_set_fr(sd); |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 3425 | sd_reset_snapshot(gspca_dev); |
| 3426 | ov51x_restart(sd); |
| 3427 | ov51x_stop(sd); /* not in win traces */ |
| 3428 | ov51x_led_control(sd, 0); |
| 3429 | break; |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3430 | case SEN_OV7670: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3431 | write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3432 | break; |
| 3433 | case SEN_OV8610: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3434 | write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3435 | break; |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 3436 | case SEN_OV9600: |
| 3437 | write_i2c_regvals(sd, norm_9600, ARRAY_SIZE(norm_9600)); |
| 3438 | |
| 3439 | /* enable autoexpo */ |
| 3440 | /* i2c_w_mask(sd, 0x13, 0x05, 0x05); */ |
| 3441 | break; |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 3442 | } |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3443 | return gspca_dev->usb_err; |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3444 | error: |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3445 | PERR("OV519 Config failed"); |
Jean-François Moine | 7491f78 | 2010-11-13 03:56:41 -0300 | [diff] [blame] | 3446 | return -EINVAL; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3447 | } |
| 3448 | |
Jean-François Moine | c42cedb | 2011-02-10 13:37:48 -0300 | [diff] [blame] | 3449 | /* function called at start time before URB creation */ |
| 3450 | static int sd_isoc_init(struct gspca_dev *gspca_dev) |
| 3451 | { |
| 3452 | struct sd *sd = (struct sd *) gspca_dev; |
| 3453 | |
| 3454 | switch (sd->bridge) { |
| 3455 | case BRIDGE_OVFX2: |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3456 | if (gspca_dev->pixfmt.width != 800) |
Jean-François Moine | c42cedb | 2011-02-10 13:37:48 -0300 | [diff] [blame] | 3457 | gspca_dev->cam.bulk_size = OVFX2_BULK_SIZE; |
| 3458 | else |
| 3459 | gspca_dev->cam.bulk_size = 7 * 4096; |
| 3460 | break; |
| 3461 | } |
| 3462 | return 0; |
| 3463 | } |
| 3464 | |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3465 | /* Set up the OV511/OV511+ with the given image parameters. |
| 3466 | * |
| 3467 | * Do not put any sensor-specific code in here (including I2C I/O functions) |
| 3468 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3469 | static void ov511_mode_init_regs(struct sd *sd) |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3470 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3471 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3472 | int hsegs, vsegs, packet_size, fps, needed; |
| 3473 | int interlaced = 0; |
| 3474 | struct usb_host_interface *alt; |
| 3475 | struct usb_interface *intf; |
| 3476 | |
| 3477 | intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); |
| 3478 | alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); |
| 3479 | if (!alt) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3480 | PERR("Couldn't get altsetting\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3481 | sd->gspca_dev.usb_err = -EIO; |
| 3482 | return; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); |
| 3486 | reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5); |
| 3487 | |
| 3488 | reg_w(sd, R511_CAM_UV_EN, 0x01); |
| 3489 | reg_w(sd, R511_SNAP_UV_EN, 0x01); |
| 3490 | reg_w(sd, R511_SNAP_OPTS, 0x03); |
| 3491 | |
| 3492 | /* Here I'm assuming that snapshot size == image size. |
| 3493 | * I hope that's always true. --claudio |
| 3494 | */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3495 | hsegs = (sd->gspca_dev.pixfmt.width >> 3) - 1; |
| 3496 | vsegs = (sd->gspca_dev.pixfmt.height >> 3) - 1; |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3497 | |
| 3498 | reg_w(sd, R511_CAM_PXCNT, hsegs); |
| 3499 | reg_w(sd, R511_CAM_LNCNT, vsegs); |
| 3500 | reg_w(sd, R511_CAM_PXDIV, 0x00); |
| 3501 | reg_w(sd, R511_CAM_LNDIV, 0x00); |
| 3502 | |
| 3503 | /* YUV420, low pass filter on */ |
| 3504 | reg_w(sd, R511_CAM_OPTS, 0x03); |
| 3505 | |
| 3506 | /* Snapshot additions */ |
| 3507 | reg_w(sd, R511_SNAP_PXCNT, hsegs); |
| 3508 | reg_w(sd, R511_SNAP_LNCNT, vsegs); |
| 3509 | reg_w(sd, R511_SNAP_PXDIV, 0x00); |
| 3510 | reg_w(sd, R511_SNAP_LNDIV, 0x00); |
| 3511 | |
| 3512 | /******** Set the framerate ********/ |
| 3513 | if (frame_rate > 0) |
| 3514 | sd->frame_rate = frame_rate; |
| 3515 | |
| 3516 | switch (sd->sensor) { |
| 3517 | case SEN_OV6620: |
| 3518 | /* No framerate control, doesn't like higher rates yet */ |
| 3519 | sd->clockdiv = 3; |
| 3520 | break; |
| 3521 | |
| 3522 | /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed |
| 3523 | for more sensors we need to do this for them too */ |
| 3524 | case SEN_OV7620: |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 3525 | case SEN_OV7620AE: |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3526 | case SEN_OV7640: |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3527 | case SEN_OV7648: |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3528 | case SEN_OV76BE: |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3529 | if (sd->gspca_dev.pixfmt.width == 320) |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3530 | interlaced = 1; |
| 3531 | /* Fall through */ |
| 3532 | case SEN_OV6630: |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3533 | case SEN_OV7610: |
| 3534 | case SEN_OV7670: |
| 3535 | switch (sd->frame_rate) { |
| 3536 | case 30: |
| 3537 | case 25: |
| 3538 | /* Not enough bandwidth to do 640x480 @ 30 fps */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3539 | if (sd->gspca_dev.pixfmt.width != 640) { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3540 | sd->clockdiv = 0; |
| 3541 | break; |
| 3542 | } |
| 3543 | /* Fall through for 640x480 case */ |
| 3544 | default: |
| 3545 | /* case 20: */ |
| 3546 | /* case 15: */ |
| 3547 | sd->clockdiv = 1; |
| 3548 | break; |
| 3549 | case 10: |
| 3550 | sd->clockdiv = 2; |
| 3551 | break; |
| 3552 | case 5: |
| 3553 | sd->clockdiv = 5; |
| 3554 | break; |
| 3555 | } |
| 3556 | if (interlaced) { |
| 3557 | sd->clockdiv = (sd->clockdiv + 1) * 2 - 1; |
| 3558 | /* Higher then 10 does not work */ |
| 3559 | if (sd->clockdiv > 10) |
| 3560 | sd->clockdiv = 10; |
| 3561 | } |
| 3562 | break; |
| 3563 | |
| 3564 | case SEN_OV8610: |
| 3565 | /* No framerate control ?? */ |
| 3566 | sd->clockdiv = 0; |
| 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | /* Check if we have enough bandwidth to disable compression */ |
| 3571 | fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1; |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3572 | needed = fps * sd->gspca_dev.pixfmt.width * |
| 3573 | sd->gspca_dev.pixfmt.height * 3 / 2; |
Hans de Goede | 0218d53 | 2012-01-01 13:45:43 -0300 | [diff] [blame] | 3574 | /* 1000 isoc packets/sec */ |
| 3575 | if (needed > 1000 * packet_size) { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3576 | /* Enable Y and UV quantization and compression */ |
| 3577 | reg_w(sd, R511_COMP_EN, 0x07); |
| 3578 | reg_w(sd, R511_COMP_LUT_EN, 0x03); |
| 3579 | } else { |
| 3580 | reg_w(sd, R511_COMP_EN, 0x06); |
| 3581 | reg_w(sd, R511_COMP_LUT_EN, 0x00); |
| 3582 | } |
| 3583 | |
| 3584 | reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE); |
| 3585 | reg_w(sd, R51x_SYS_RESET, 0); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 3586 | } |
| 3587 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3588 | /* Sets up the OV518/OV518+ with the given image parameters |
| 3589 | * |
| 3590 | * OV518 needs a completely different approach, until we can figure out what |
| 3591 | * the individual registers do. Also, only 15 FPS is supported now. |
| 3592 | * |
| 3593 | * Do not put any sensor-specific code in here (including I2C I/O functions) |
| 3594 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3595 | static void ov518_mode_init_regs(struct sd *sd) |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3596 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3597 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3598 | int hsegs, vsegs, packet_size; |
| 3599 | struct usb_host_interface *alt; |
| 3600 | struct usb_interface *intf; |
| 3601 | |
| 3602 | intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); |
| 3603 | alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); |
| 3604 | if (!alt) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3605 | PERR("Couldn't get altsetting\n"); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3606 | sd->gspca_dev.usb_err = -EIO; |
| 3607 | return; |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); |
| 3611 | ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3612 | |
| 3613 | /******** Set the mode ********/ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3614 | reg_w(sd, 0x2b, 0); |
| 3615 | reg_w(sd, 0x2c, 0); |
| 3616 | reg_w(sd, 0x2d, 0); |
| 3617 | reg_w(sd, 0x2e, 0); |
| 3618 | reg_w(sd, 0x3b, 0); |
| 3619 | reg_w(sd, 0x3c, 0); |
| 3620 | reg_w(sd, 0x3d, 0); |
| 3621 | reg_w(sd, 0x3e, 0); |
| 3622 | |
| 3623 | if (sd->bridge == BRIDGE_OV518) { |
| 3624 | /* Set 8-bit (YVYU) input format */ |
| 3625 | reg_w_mask(sd, 0x20, 0x08, 0x08); |
| 3626 | |
| 3627 | /* Set 12-bit (4:2:0) output format */ |
| 3628 | reg_w_mask(sd, 0x28, 0x80, 0xf0); |
| 3629 | reg_w_mask(sd, 0x38, 0x80, 0xf0); |
| 3630 | } else { |
| 3631 | reg_w(sd, 0x28, 0x80); |
| 3632 | reg_w(sd, 0x38, 0x80); |
| 3633 | } |
| 3634 | |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3635 | hsegs = sd->gspca_dev.pixfmt.width / 16; |
| 3636 | vsegs = sd->gspca_dev.pixfmt.height / 4; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3637 | |
| 3638 | reg_w(sd, 0x29, hsegs); |
| 3639 | reg_w(sd, 0x2a, vsegs); |
| 3640 | |
| 3641 | reg_w(sd, 0x39, hsegs); |
| 3642 | reg_w(sd, 0x3a, vsegs); |
| 3643 | |
| 3644 | /* Windows driver does this here; who knows why */ |
| 3645 | reg_w(sd, 0x2f, 0x80); |
| 3646 | |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 3647 | /******** Set the framerate ********/ |
Hans de Goede | b82180d | 2013-08-22 12:41:14 -0300 | [diff] [blame] | 3648 | if (sd->bridge == BRIDGE_OV518PLUS && sd->revision == 0 && |
| 3649 | sd->sensor == SEN_OV7620AE) |
| 3650 | sd->clockdiv = 0; |
| 3651 | else |
| 3652 | sd->clockdiv = 1; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3653 | |
| 3654 | /* Mode independent, but framerate dependent, regs */ |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3655 | /* 0x51: Clock divider; Only works on some cams which use 2 crystals */ |
| 3656 | reg_w(sd, 0x51, 0x04); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3657 | reg_w(sd, 0x22, 0x18); |
| 3658 | reg_w(sd, 0x23, 0xff); |
| 3659 | |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3660 | if (sd->bridge == BRIDGE_OV518PLUS) { |
| 3661 | switch (sd->sensor) { |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 3662 | case SEN_OV7620AE: |
Hans de Goede | b82180d | 2013-08-22 12:41:14 -0300 | [diff] [blame] | 3663 | /* |
| 3664 | * HdG: 640x480 needs special handling on device |
| 3665 | * revision 2, we check for device revison > 0 to |
| 3666 | * avoid regressions, as we don't know the correct |
| 3667 | * thing todo for revision 1. |
| 3668 | * |
| 3669 | * Also this likely means we don't need to |
| 3670 | * differentiate between the OV7620 and OV7620AE, |
| 3671 | * earlier testing hitting this same problem likely |
| 3672 | * happened to be with revision < 2 cams using an |
| 3673 | * OV7620 and revision 2 cams using an OV7620AE. |
| 3674 | */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3675 | if (sd->revision > 0 && |
| 3676 | sd->gspca_dev.pixfmt.width == 640) { |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3677 | reg_w(sd, 0x20, 0x60); |
| 3678 | reg_w(sd, 0x21, 0x1f); |
Hans de Goede | b82180d | 2013-08-22 12:41:14 -0300 | [diff] [blame] | 3679 | } else { |
| 3680 | reg_w(sd, 0x20, 0x00); |
| 3681 | reg_w(sd, 0x21, 0x19); |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3682 | } |
| 3683 | break; |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 3684 | case SEN_OV7620: |
| 3685 | reg_w(sd, 0x20, 0x00); |
| 3686 | reg_w(sd, 0x21, 0x19); |
| 3687 | break; |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3688 | default: |
| 3689 | reg_w(sd, 0x21, 0x19); |
| 3690 | } |
| 3691 | } else |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3692 | reg_w(sd, 0x71, 0x17); /* Compression-related? */ |
| 3693 | |
| 3694 | /* FIXME: Sensor-specific */ |
| 3695 | /* Bit 5 is what matters here. Of course, it is "reserved" */ |
| 3696 | i2c_w(sd, 0x54, 0x23); |
| 3697 | |
| 3698 | reg_w(sd, 0x2f, 0x80); |
| 3699 | |
| 3700 | if (sd->bridge == BRIDGE_OV518PLUS) { |
| 3701 | reg_w(sd, 0x24, 0x94); |
| 3702 | reg_w(sd, 0x25, 0x90); |
| 3703 | ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */ |
| 3704 | ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */ |
| 3705 | ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */ |
| 3706 | ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */ |
| 3707 | ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */ |
| 3708 | ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */ |
| 3709 | ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */ |
| 3710 | ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */ |
| 3711 | ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */ |
| 3712 | } else { |
| 3713 | reg_w(sd, 0x24, 0x9f); |
| 3714 | reg_w(sd, 0x25, 0x90); |
| 3715 | ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */ |
| 3716 | ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */ |
| 3717 | ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */ |
| 3718 | ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */ |
| 3719 | ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */ |
| 3720 | ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */ |
| 3721 | ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */ |
| 3722 | ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */ |
| 3723 | ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */ |
| 3724 | } |
| 3725 | |
| 3726 | reg_w(sd, 0x2f, 0x80); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 3727 | } |
| 3728 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3729 | /* Sets up the OV519 with the given image parameters |
| 3730 | * |
| 3731 | * OV519 needs a completely different approach, until we can figure out what |
| 3732 | * the individual registers do. |
| 3733 | * |
| 3734 | * Do not put any sensor-specific code in here (including I2C I/O functions) |
| 3735 | */ |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3736 | static void ov519_mode_init_regs(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3737 | { |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 3738 | static const struct ov_regvals mode_init_519_ov7670[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3739 | { 0x5d, 0x03 }, /* Turn off suspend mode */ |
| 3740 | { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 3741 | { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3742 | { 0xa2, 0x20 }, /* a2-a5 are undocumented */ |
| 3743 | { 0xa3, 0x18 }, |
| 3744 | { 0xa4, 0x04 }, |
| 3745 | { 0xa5, 0x28 }, |
| 3746 | { 0x37, 0x00 }, /* SetUsbInit */ |
| 3747 | { 0x55, 0x02 }, /* 4.096 Mhz audio clock */ |
| 3748 | /* Enable both fields, YUV Input, disable defect comp (why?) */ |
| 3749 | { 0x20, 0x0c }, |
| 3750 | { 0x21, 0x38 }, |
| 3751 | { 0x22, 0x1d }, |
| 3752 | { 0x17, 0x50 }, /* undocumented */ |
| 3753 | { 0x37, 0x00 }, /* undocumented */ |
| 3754 | { 0x40, 0xff }, /* I2C timeout counter */ |
| 3755 | { 0x46, 0x00 }, /* I2C clock prescaler */ |
| 3756 | { 0x59, 0x04 }, /* new from windrv 090403 */ |
| 3757 | { 0xff, 0x00 }, /* undocumented */ |
| 3758 | /* windows reads 0x55 at this point, why? */ |
| 3759 | }; |
| 3760 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 3761 | static const struct ov_regvals mode_init_519[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3762 | { 0x5d, 0x03 }, /* Turn off suspend mode */ |
| 3763 | { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 3764 | { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3765 | { 0xa2, 0x20 }, /* a2-a5 are undocumented */ |
| 3766 | { 0xa3, 0x18 }, |
| 3767 | { 0xa4, 0x04 }, |
| 3768 | { 0xa5, 0x28 }, |
| 3769 | { 0x37, 0x00 }, /* SetUsbInit */ |
| 3770 | { 0x55, 0x02 }, /* 4.096 Mhz audio clock */ |
| 3771 | /* Enable both fields, YUV Input, disable defect comp (why?) */ |
| 3772 | { 0x22, 0x1d }, |
| 3773 | { 0x17, 0x50 }, /* undocumented */ |
| 3774 | { 0x37, 0x00 }, /* undocumented */ |
| 3775 | { 0x40, 0xff }, /* I2C timeout counter */ |
| 3776 | { 0x46, 0x00 }, /* I2C clock prescaler */ |
| 3777 | { 0x59, 0x04 }, /* new from windrv 090403 */ |
| 3778 | { 0xff, 0x00 }, /* undocumented */ |
| 3779 | /* windows reads 0x55 at this point, why? */ |
| 3780 | }; |
| 3781 | |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3782 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
| 3783 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3784 | /******** Set the mode ********/ |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 3785 | switch (sd->sensor) { |
| 3786 | default: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3787 | write_regvals(sd, mode_init_519, ARRAY_SIZE(mode_init_519)); |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3788 | if (sd->sensor == SEN_OV7640 || |
| 3789 | sd->sensor == SEN_OV7648) { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3790 | /* Select 8-bit input mode */ |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 3791 | reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3792 | } |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 3793 | break; |
| 3794 | case SEN_OV7660: |
| 3795 | return; /* done by ov519_set_mode/fr() */ |
| 3796 | case SEN_OV7670: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3797 | write_regvals(sd, mode_init_519_ov7670, |
| 3798 | ARRAY_SIZE(mode_init_519_ov7670)); |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 3799 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3800 | } |
| 3801 | |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3802 | reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.pixfmt.width >> 4); |
| 3803 | reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.pixfmt.height >> 3); |
Hans de Goede | 80142ef | 2009-06-14 06:26:49 -0300 | [diff] [blame] | 3804 | if (sd->sensor == SEN_OV7670 && |
| 3805 | sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv) |
| 3806 | reg_w(sd, OV519_R12_X_OFFSETL, 0x04); |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3807 | else if (sd->sensor == SEN_OV7648 && |
| 3808 | sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv) |
| 3809 | reg_w(sd, OV519_R12_X_OFFSETL, 0x01); |
Hans de Goede | 80142ef | 2009-06-14 06:26:49 -0300 | [diff] [blame] | 3810 | else |
| 3811 | reg_w(sd, OV519_R12_X_OFFSETL, 0x00); |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 3812 | reg_w(sd, OV519_R13_X_OFFSETH, 0x00); |
| 3813 | reg_w(sd, OV519_R14_Y_OFFSETL, 0x00); |
| 3814 | reg_w(sd, OV519_R15_Y_OFFSETH, 0x00); |
| 3815 | reg_w(sd, OV519_R16_DIVIDER, 0x00); |
| 3816 | reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3817 | reg_w(sd, 0x26, 0x00); /* Undocumented */ |
| 3818 | |
| 3819 | /******** Set the framerate ********/ |
| 3820 | if (frame_rate > 0) |
| 3821 | sd->frame_rate = frame_rate; |
| 3822 | |
| 3823 | /* FIXME: These are only valid at the max resolution. */ |
| 3824 | sd->clockdiv = 0; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3825 | switch (sd->sensor) { |
| 3826 | case SEN_OV7640: |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3827 | case SEN_OV7648: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3828 | switch (sd->frame_rate) { |
Jean-Francois Moine | 53e7451 | 2008-11-08 06:10:19 -0300 | [diff] [blame] | 3829 | default: |
| 3830 | /* case 30: */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3831 | reg_w(sd, 0xa4, 0x0c); |
| 3832 | reg_w(sd, 0x23, 0xff); |
| 3833 | break; |
| 3834 | case 25: |
| 3835 | reg_w(sd, 0xa4, 0x0c); |
| 3836 | reg_w(sd, 0x23, 0x1f); |
| 3837 | break; |
| 3838 | case 20: |
| 3839 | reg_w(sd, 0xa4, 0x0c); |
| 3840 | reg_w(sd, 0x23, 0x1b); |
| 3841 | break; |
Jean-Francois Moine | 53e7451 | 2008-11-08 06:10:19 -0300 | [diff] [blame] | 3842 | case 15: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3843 | reg_w(sd, 0xa4, 0x04); |
| 3844 | reg_w(sd, 0x23, 0xff); |
| 3845 | sd->clockdiv = 1; |
| 3846 | break; |
| 3847 | case 10: |
| 3848 | reg_w(sd, 0xa4, 0x04); |
| 3849 | reg_w(sd, 0x23, 0x1f); |
| 3850 | sd->clockdiv = 1; |
| 3851 | break; |
| 3852 | case 5: |
| 3853 | reg_w(sd, 0xa4, 0x04); |
| 3854 | reg_w(sd, 0x23, 0x1b); |
| 3855 | sd->clockdiv = 1; |
| 3856 | break; |
| 3857 | } |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3858 | break; |
| 3859 | case SEN_OV8610: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3860 | switch (sd->frame_rate) { |
| 3861 | default: /* 15 fps */ |
| 3862 | /* case 15: */ |
| 3863 | reg_w(sd, 0xa4, 0x06); |
| 3864 | reg_w(sd, 0x23, 0xff); |
| 3865 | break; |
| 3866 | case 10: |
| 3867 | reg_w(sd, 0xa4, 0x06); |
| 3868 | reg_w(sd, 0x23, 0x1f); |
| 3869 | break; |
| 3870 | case 5: |
| 3871 | reg_w(sd, 0xa4, 0x06); |
| 3872 | reg_w(sd, 0x23, 0x1b); |
| 3873 | break; |
| 3874 | } |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3875 | break; |
| 3876 | case SEN_OV7670: /* guesses, based on 7640 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3877 | PDEBUG(D_STREAM, "Setting framerate to %d fps", |
| 3878 | (sd->frame_rate == 0) ? 15 : sd->frame_rate); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3879 | reg_w(sd, 0xa4, 0x10); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3880 | switch (sd->frame_rate) { |
| 3881 | case 30: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3882 | reg_w(sd, 0x23, 0xff); |
| 3883 | break; |
| 3884 | case 20: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3885 | reg_w(sd, 0x23, 0x1b); |
| 3886 | break; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3887 | default: |
| 3888 | /* case 15: */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3889 | reg_w(sd, 0x23, 0xff); |
| 3890 | sd->clockdiv = 1; |
| 3891 | break; |
| 3892 | } |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3893 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3894 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3895 | } |
| 3896 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3897 | static void mode_init_ov_sensor_regs(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3898 | { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 3899 | struct gspca_dev *gspca_dev = (struct gspca_dev *)sd; |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 3900 | int qvga, xstart, xend, ystart, yend; |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 3901 | u8 v; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 3902 | |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 3903 | qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3904 | |
| 3905 | /******** Mode (VGA/QVGA) and sensor specific regs ********/ |
| 3906 | switch (sd->sensor) { |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3907 | case SEN_OV2610: |
| 3908 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 3909 | i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); |
| 3910 | i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); |
| 3911 | i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); |
| 3912 | i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); |
| 3913 | i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); |
| 3914 | i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3915 | return; |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 3916 | case SEN_OV2610AE: { |
| 3917 | u8 v; |
| 3918 | |
| 3919 | /* frame rates: |
| 3920 | * 10fps / 5 fps for 1600x1200 |
| 3921 | * 40fps / 20fps for 800x600 |
| 3922 | */ |
| 3923 | v = 80; |
| 3924 | if (qvga) { |
| 3925 | if (sd->frame_rate < 25) |
| 3926 | v = 0x81; |
| 3927 | } else { |
| 3928 | if (sd->frame_rate < 10) |
| 3929 | v = 0x81; |
| 3930 | } |
| 3931 | i2c_w(sd, 0x11, v); |
| 3932 | i2c_w(sd, 0x12, qvga ? 0x60 : 0x20); |
| 3933 | return; |
| 3934 | } |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 3935 | case SEN_OV3610: |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3936 | if (qvga) { |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3937 | xstart = (1040 - gspca_dev->pixfmt.width) / 2 + |
| 3938 | (0x1f << 4); |
| 3939 | ystart = (776 - gspca_dev->pixfmt.height) / 2; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3940 | } else { |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3941 | xstart = (2076 - gspca_dev->pixfmt.width) / 2 + |
| 3942 | (0x10 << 4); |
| 3943 | ystart = (1544 - gspca_dev->pixfmt.height) / 2; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3944 | } |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 3945 | xend = xstart + gspca_dev->pixfmt.width; |
| 3946 | yend = ystart + gspca_dev->pixfmt.height; |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 3947 | /* Writing to the COMH register resets the other windowing regs |
| 3948 | to their default values, so we must do this first. */ |
| 3949 | i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0); |
| 3950 | i2c_w_mask(sd, 0x32, |
| 3951 | (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7), |
| 3952 | 0x3f); |
| 3953 | i2c_w_mask(sd, 0x03, |
| 3954 | (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3), |
| 3955 | 0x0f); |
| 3956 | i2c_w(sd, 0x17, xstart >> 4); |
| 3957 | i2c_w(sd, 0x18, xend >> 4); |
| 3958 | i2c_w(sd, 0x19, ystart >> 3); |
| 3959 | i2c_w(sd, 0x1a, yend >> 3); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 3960 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3961 | case SEN_OV8610: |
| 3962 | /* For OV8610 qvga means qsvga */ |
| 3963 | i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 3964 | i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ |
| 3965 | i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ |
| 3966 | i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */ |
| 3967 | i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3968 | break; |
| 3969 | case SEN_OV7610: |
| 3970 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
Jean-François Moine | 780e312 | 2010-10-19 04:29:10 -0300 | [diff] [blame] | 3971 | i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 3972 | i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ |
| 3973 | i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3974 | break; |
| 3975 | case SEN_OV7620: |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 3976 | case SEN_OV7620AE: |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3977 | case SEN_OV76BE: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3978 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 3979 | i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); |
| 3980 | i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); |
| 3981 | i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); |
| 3982 | i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); |
Hans de Goede | b282d87 | 2009-06-14 19:10:40 -0300 | [diff] [blame] | 3983 | i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3984 | i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 3985 | i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ |
| 3986 | i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ |
| 3987 | if (sd->sensor == SEN_OV76BE) |
| 3988 | i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3989 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3990 | case SEN_OV7640: |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3991 | case SEN_OV7648: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 3992 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 3993 | i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); |
Hans de Goede | 8d0082f | 2010-01-09 19:45:44 -0300 | [diff] [blame] | 3994 | /* Setting this undocumented bit in qvga mode removes a very |
| 3995 | annoying vertical shaking of the image */ |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3996 | i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); |
Hans de Goede | 8d0082f | 2010-01-09 19:45:44 -0300 | [diff] [blame] | 3997 | /* Unknown */ |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 3998 | i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); |
Hans de Goede | 8d0082f | 2010-01-09 19:45:44 -0300 | [diff] [blame] | 3999 | /* Allow higher automatic gain (to allow higher framerates) */ |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 4000 | i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4001 | i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4002 | break; |
| 4003 | case SEN_OV7670: |
| 4004 | /* set COM7_FMT_VGA or COM7_FMT_QVGA |
| 4005 | * do we need to set anything else? |
| 4006 | * HSTART etc are set in set_ov_sensor_window itself */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4007 | i2c_w_mask(sd, OV7670_R12_COM7, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4008 | qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA, |
| 4009 | OV7670_COM7_FMT_MASK); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4010 | i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4011 | i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB, |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4012 | OV7670_COM8_AWB); |
| 4013 | if (qvga) { /* QVGA from ov7670.c by |
| 4014 | * Jonathan Corbet */ |
| 4015 | xstart = 164; |
| 4016 | xend = 28; |
| 4017 | ystart = 14; |
| 4018 | yend = 494; |
| 4019 | } else { /* VGA */ |
| 4020 | xstart = 158; |
| 4021 | xend = 14; |
| 4022 | ystart = 10; |
| 4023 | yend = 490; |
| 4024 | } |
| 4025 | /* OV7670 hardware window registers are split across |
| 4026 | * multiple locations */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4027 | i2c_w(sd, OV7670_R17_HSTART, xstart >> 3); |
| 4028 | i2c_w(sd, OV7670_R18_HSTOP, xend >> 3); |
| 4029 | v = i2c_r(sd, OV7670_R32_HREF); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4030 | v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07); |
| 4031 | msleep(10); /* need to sleep between read and write to |
| 4032 | * same reg! */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4033 | i2c_w(sd, OV7670_R32_HREF, v); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4034 | |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4035 | i2c_w(sd, OV7670_R19_VSTART, ystart >> 2); |
| 4036 | i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2); |
| 4037 | v = i2c_r(sd, OV7670_R03_VREF); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4038 | v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03); |
| 4039 | msleep(10); /* need to sleep between read and write to |
| 4040 | * same reg! */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4041 | i2c_w(sd, OV7670_R03_VREF, v); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4042 | break; |
| 4043 | case SEN_OV6620: |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4044 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 4045 | i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ |
| 4046 | i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ |
| 4047 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4048 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4049 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4050 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4051 | i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4052 | break; |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 4053 | case SEN_OV9600: { |
| 4054 | const struct ov_i2c_regvals *vals; |
| 4055 | static const struct ov_i2c_regvals sxga_15[] = { |
| 4056 | {0x11, 0x80}, {0x14, 0x3e}, {0x24, 0x85}, {0x25, 0x75} |
| 4057 | }; |
| 4058 | static const struct ov_i2c_regvals sxga_7_5[] = { |
| 4059 | {0x11, 0x81}, {0x14, 0x3e}, {0x24, 0x85}, {0x25, 0x75} |
| 4060 | }; |
| 4061 | static const struct ov_i2c_regvals vga_30[] = { |
| 4062 | {0x11, 0x81}, {0x14, 0x7e}, {0x24, 0x70}, {0x25, 0x60} |
| 4063 | }; |
| 4064 | static const struct ov_i2c_regvals vga_15[] = { |
| 4065 | {0x11, 0x83}, {0x14, 0x3e}, {0x24, 0x80}, {0x25, 0x70} |
| 4066 | }; |
| 4067 | |
| 4068 | /* frame rates: |
| 4069 | * 15fps / 7.5 fps for 1280x1024 |
| 4070 | * 30fps / 15fps for 640x480 |
| 4071 | */ |
| 4072 | i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0x40); |
| 4073 | if (qvga) |
| 4074 | vals = sd->frame_rate < 30 ? vga_15 : vga_30; |
| 4075 | else |
| 4076 | vals = sd->frame_rate < 15 ? sxga_7_5 : sxga_15; |
| 4077 | write_i2c_regvals(sd, vals, ARRAY_SIZE(sxga_15)); |
| 4078 | return; |
| 4079 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4080 | default: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4081 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4082 | } |
| 4083 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4084 | /******** Clock programming ********/ |
Hans de Goede | ae49c40 | 2009-06-14 19:15:07 -0300 | [diff] [blame] | 4085 | i2c_w(sd, 0x11, sd->clockdiv); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4086 | } |
| 4087 | |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4088 | /* this function works for bridge ov519 and sensors ov7660 and ov7670 only */ |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4089 | static void sethvflip(struct gspca_dev *gspca_dev, s32 hflip, s32 vflip) |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 4090 | { |
Jean-François Moine | 62833ac | 2010-10-02 04:27:02 -0300 | [diff] [blame] | 4091 | struct sd *sd = (struct sd *) gspca_dev; |
| 4092 | |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 4093 | if (sd->gspca_dev.streaming) |
Jean-François Moine | 5927abc | 2010-11-12 15:32:29 -0300 | [diff] [blame] | 4094 | reg_w(sd, OV519_R51_RESET1, 0x0f); /* block stream */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4095 | i2c_w_mask(sd, OV7670_R1E_MVFP, |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4096 | OV7670_MVFP_MIRROR * hflip | OV7670_MVFP_VFLIP * vflip, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4097 | OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP); |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 4098 | if (sd->gspca_dev.streaming) |
Jean-François Moine | 5927abc | 2010-11-12 15:32:29 -0300 | [diff] [blame] | 4099 | reg_w(sd, OV519_R51_RESET1, 0x00); /* restart stream */ |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 4100 | } |
| 4101 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4102 | static void set_ov_sensor_window(struct sd *sd) |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 4103 | { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4104 | struct gspca_dev *gspca_dev; |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 4105 | int qvga, crop; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4106 | int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4107 | |
Hans de Goede | 635118d | 2009-10-11 09:49:03 -0300 | [diff] [blame] | 4108 | /* mode setup is fully handled in mode_init_ov_sensor_regs for these */ |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4109 | switch (sd->sensor) { |
| 4110 | case SEN_OV2610: |
Jean-François Moine | 07c6c9c | 2011-02-10 13:32:22 -0300 | [diff] [blame] | 4111 | case SEN_OV2610AE: |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4112 | case SEN_OV3610: |
| 4113 | case SEN_OV7670: |
Jean-François Moine | 798ae15 | 2011-05-23 05:38:10 -0300 | [diff] [blame] | 4114 | case SEN_OV9600: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4115 | mode_init_ov_sensor_regs(sd); |
| 4116 | return; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4117 | case SEN_OV7660: |
| 4118 | ov519_set_mode(sd); |
| 4119 | ov519_set_fr(sd); |
| 4120 | return; |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4121 | } |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4122 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4123 | gspca_dev = &sd->gspca_dev; |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 4124 | qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1; |
| 4125 | crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4126 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4127 | /* The different sensor ICs handle setting up of window differently. |
| 4128 | * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */ |
| 4129 | switch (sd->sensor) { |
| 4130 | case SEN_OV8610: |
| 4131 | hwsbase = 0x1e; |
| 4132 | hwebase = 0x1e; |
| 4133 | vwsbase = 0x02; |
| 4134 | vwebase = 0x02; |
| 4135 | break; |
| 4136 | case SEN_OV7610: |
| 4137 | case SEN_OV76BE: |
| 4138 | hwsbase = 0x38; |
| 4139 | hwebase = 0x3a; |
| 4140 | vwsbase = vwebase = 0x05; |
| 4141 | break; |
| 4142 | case SEN_OV6620: |
| 4143 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4144 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4145 | hwsbase = 0x38; |
| 4146 | hwebase = 0x3a; |
| 4147 | vwsbase = 0x05; |
| 4148 | vwebase = 0x06; |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4149 | if (sd->sensor == SEN_OV66308AF && qvga) |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4150 | /* HDG: this fixes U and V getting swapped */ |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4151 | hwsbase++; |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame] | 4152 | if (crop) { |
| 4153 | hwsbase += 8; |
| 4154 | hwebase += 8; |
| 4155 | vwsbase += 11; |
| 4156 | vwebase += 11; |
| 4157 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4158 | break; |
| 4159 | case SEN_OV7620: |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 4160 | case SEN_OV7620AE: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4161 | hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */ |
| 4162 | hwebase = 0x2f; |
| 4163 | vwsbase = vwebase = 0x05; |
| 4164 | break; |
| 4165 | case SEN_OV7640: |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 4166 | case SEN_OV7648: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4167 | hwsbase = 0x1a; |
| 4168 | hwebase = 0x1a; |
| 4169 | vwsbase = vwebase = 0x03; |
| 4170 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4171 | default: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4172 | return; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | switch (sd->sensor) { |
| 4176 | case SEN_OV6620: |
| 4177 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4178 | case SEN_OV66308AF: |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4179 | if (qvga) { /* QCIF */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4180 | hwscale = 0; |
| 4181 | vwscale = 0; |
| 4182 | } else { /* CIF */ |
| 4183 | hwscale = 1; |
| 4184 | vwscale = 1; /* The datasheet says 0; |
| 4185 | * it's wrong */ |
| 4186 | } |
| 4187 | break; |
| 4188 | case SEN_OV8610: |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4189 | if (qvga) { /* QSVGA */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4190 | hwscale = 1; |
| 4191 | vwscale = 1; |
| 4192 | } else { /* SVGA */ |
| 4193 | hwscale = 2; |
| 4194 | vwscale = 2; |
| 4195 | } |
| 4196 | break; |
| 4197 | default: /* SEN_OV7xx0 */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4198 | if (qvga) { /* QVGA */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4199 | hwscale = 1; |
| 4200 | vwscale = 0; |
| 4201 | } else { /* VGA */ |
| 4202 | hwscale = 2; |
| 4203 | vwscale = 1; |
| 4204 | } |
| 4205 | } |
| 4206 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4207 | mode_init_ov_sensor_regs(sd); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4208 | |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4209 | i2c_w(sd, 0x17, hwsbase); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4210 | i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale)); |
Hans de Goede | ebbb5c3 | 2009-10-12 11:32:44 -0300 | [diff] [blame] | 4211 | i2c_w(sd, 0x19, vwsbase); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4212 | i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale)); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4213 | } |
| 4214 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4215 | /* -- start the camera -- */ |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 4216 | static int sd_start(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4217 | { |
| 4218 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4219 | |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4220 | /* Default for most bridges, allow bridge_mode_init_regs to override */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 4221 | sd->sensor_width = sd->gspca_dev.pixfmt.width; |
| 4222 | sd->sensor_height = sd->gspca_dev.pixfmt.height; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4223 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4224 | switch (sd->bridge) { |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4225 | case BRIDGE_OV511: |
| 4226 | case BRIDGE_OV511PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4227 | ov511_mode_init_regs(sd); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4228 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4229 | case BRIDGE_OV518: |
| 4230 | case BRIDGE_OV518PLUS: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4231 | ov518_mode_init_regs(sd); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4232 | break; |
| 4233 | case BRIDGE_OV519: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4234 | ov519_mode_init_regs(sd); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4235 | break; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4236 | /* case BRIDGE_OVFX2: nothing to do */ |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4237 | case BRIDGE_W9968CF: |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4238 | w9968cf_mode_init_regs(sd); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4239 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4240 | } |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4241 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4242 | set_ov_sensor_window(sd); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4243 | |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 4244 | /* Force clear snapshot state in case the snapshot button was |
| 4245 | pressed while we weren't streaming */ |
| 4246 | sd->snapshot_needs_reset = 1; |
| 4247 | sd_reset_snapshot(gspca_dev); |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 4248 | |
Hans de Goede | d6b6d7a | 2010-05-08 08:55:42 -0300 | [diff] [blame] | 4249 | sd->first_frame = 3; |
| 4250 | |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4251 | ov51x_restart(sd); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4252 | ov51x_led_control(sd, 1); |
Jean-François Moine | f8f2018 | 2010-11-12 07:54:02 -0300 | [diff] [blame] | 4253 | return gspca_dev->usb_err; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 4257 | { |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 4258 | struct sd *sd = (struct sd *) gspca_dev; |
| 4259 | |
| 4260 | ov51x_stop(sd); |
| 4261 | ov51x_led_control(sd, 0); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4262 | } |
| 4263 | |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4264 | static void sd_stop0(struct gspca_dev *gspca_dev) |
| 4265 | { |
| 4266 | struct sd *sd = (struct sd *) gspca_dev; |
| 4267 | |
Jean-François Moine | d65174c | 2010-11-11 06:20:42 -0300 | [diff] [blame] | 4268 | if (!sd->gspca_dev.present) |
| 4269 | return; |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4270 | if (sd->bridge == BRIDGE_W9968CF) |
| 4271 | w9968cf_stop0(sd); |
Hans de Goede | 614d069 | 2010-10-27 07:42:28 -0300 | [diff] [blame] | 4272 | |
Peter Senna Tschudin | c4ea799 | 2013-01-24 19:29:01 -0300 | [diff] [blame] | 4273 | #if IS_ENABLED(CONFIG_INPUT) |
Hans de Goede | 614d069 | 2010-10-27 07:42:28 -0300 | [diff] [blame] | 4274 | /* If the last button state is pressed, release it now! */ |
| 4275 | if (sd->snapshot_pressed) { |
| 4276 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); |
| 4277 | input_sync(gspca_dev->input_dev); |
| 4278 | sd->snapshot_pressed = 0; |
| 4279 | } |
| 4280 | #endif |
Jean-François Moine | b4e96ea | 2010-11-12 16:13:17 -0300 | [diff] [blame] | 4281 | if (sd->bridge == BRIDGE_OV519) |
| 4282 | reg_w(sd, OV519_R57_SNAPSHOT, 0x23); |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4283 | } |
| 4284 | |
Hans de Goede | 92e232a | 2010-02-20 04:30:45 -0300 | [diff] [blame] | 4285 | static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state) |
| 4286 | { |
| 4287 | struct sd *sd = (struct sd *) gspca_dev; |
| 4288 | |
| 4289 | if (sd->snapshot_pressed != state) { |
Peter Senna Tschudin | c4ea799 | 2013-01-24 19:29:01 -0300 | [diff] [blame] | 4290 | #if IS_ENABLED(CONFIG_INPUT) |
Hans de Goede | 92e232a | 2010-02-20 04:30:45 -0300 | [diff] [blame] | 4291 | input_report_key(gspca_dev->input_dev, KEY_CAMERA, state); |
| 4292 | input_sync(gspca_dev->input_dev); |
| 4293 | #endif |
| 4294 | if (state) |
| 4295 | sd->snapshot_needs_reset = 1; |
| 4296 | |
| 4297 | sd->snapshot_pressed = state; |
| 4298 | } else { |
Hans de Goede | 88e8d20 | 2010-02-20 04:45:49 -0300 | [diff] [blame] | 4299 | /* On the ov511 / ov519 we need to reset the button state |
| 4300 | multiple times, as resetting does not work as long as the |
| 4301 | button stays pressed */ |
| 4302 | switch (sd->bridge) { |
| 4303 | case BRIDGE_OV511: |
| 4304 | case BRIDGE_OV511PLUS: |
| 4305 | case BRIDGE_OV519: |
| 4306 | if (state) |
| 4307 | sd->snapshot_needs_reset = 1; |
| 4308 | break; |
| 4309 | } |
Hans de Goede | 92e232a | 2010-02-20 04:30:45 -0300 | [diff] [blame] | 4310 | } |
| 4311 | } |
| 4312 | |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4313 | static void ov511_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4314 | u8 *in, /* isoc packet */ |
| 4315 | int len) /* iso packet length */ |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4316 | { |
| 4317 | struct sd *sd = (struct sd *) gspca_dev; |
| 4318 | |
| 4319 | /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th |
| 4320 | * byte non-zero. The EOF packet has image width/height in the |
| 4321 | * 10th and 11th bytes. The 9th byte is given as follows: |
| 4322 | * |
| 4323 | * bit 7: EOF |
| 4324 | * 6: compression enabled |
| 4325 | * 5: 422/420/400 modes |
| 4326 | * 4: 422/420/400 modes |
| 4327 | * 3: 1 |
| 4328 | * 2: snapshot button on |
| 4329 | * 1: snapshot frame |
| 4330 | * 0: even/odd field |
| 4331 | */ |
| 4332 | if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) && |
| 4333 | (in[8] & 0x08)) { |
Hans de Goede | 88e8d20 | 2010-02-20 04:45:49 -0300 | [diff] [blame] | 4334 | ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4335 | if (in[8] & 0x80) { |
| 4336 | /* Frame end */ |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 4337 | if ((in[9] + 1) * 8 != gspca_dev->pixfmt.width || |
| 4338 | (in[10] + 1) * 8 != gspca_dev->pixfmt.height) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 4339 | PERR("Invalid frame size, got: %dx%d," |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4340 | " requested: %dx%d\n", |
| 4341 | (in[9] + 1) * 8, (in[10] + 1) * 8, |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 4342 | gspca_dev->pixfmt.width, |
| 4343 | gspca_dev->pixfmt.height); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4344 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 4345 | return; |
| 4346 | } |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4347 | /* Add 11 byte footer to frame, might be useful */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4348 | gspca_frame_add(gspca_dev, LAST_PACKET, in, 11); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4349 | return; |
| 4350 | } else { |
| 4351 | /* Frame start */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4352 | gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4353 | sd->packet_nr = 0; |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | /* Ignore the packet number */ |
| 4358 | len--; |
| 4359 | |
| 4360 | /* intermediate packet */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4361 | gspca_frame_add(gspca_dev, INTER_PACKET, in, len); |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4362 | } |
| 4363 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4364 | static void ov518_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4365 | u8 *data, /* isoc packet */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4366 | int len) /* iso packet length */ |
| 4367 | { |
Hans de Goede | 92918a5 | 2009-06-14 06:21:35 -0300 | [diff] [blame] | 4368 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4369 | |
| 4370 | /* A false positive here is likely, until OVT gives me |
| 4371 | * the definitive SOF/EOF format */ |
| 4372 | if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) { |
Hans de Goede | 92e232a | 2010-02-20 04:30:45 -0300 | [diff] [blame] | 4373 | ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1); |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4374 | gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); |
| 4375 | gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); |
Hans de Goede | 92918a5 | 2009-06-14 06:21:35 -0300 | [diff] [blame] | 4376 | sd->packet_nr = 0; |
| 4377 | } |
| 4378 | |
| 4379 | if (gspca_dev->last_packet_type == DISCARD_PACKET) |
| 4380 | return; |
| 4381 | |
| 4382 | /* Does this device use packet numbers ? */ |
| 4383 | if (len & 7) { |
| 4384 | len--; |
| 4385 | if (sd->packet_nr == data[len]) |
| 4386 | sd->packet_nr++; |
| 4387 | /* The last few packets of the frame (which are all 0's |
| 4388 | except that they may contain part of the footer), are |
| 4389 | numbered 0 */ |
| 4390 | else if (sd->packet_nr == 0 || data[len]) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 4391 | PERR("Invalid packet nr: %d (expect: %d)", |
Hans de Goede | 92918a5 | 2009-06-14 06:21:35 -0300 | [diff] [blame] | 4392 | (int)data[len], (int)sd->packet_nr); |
| 4393 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 4394 | return; |
| 4395 | } |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | /* intermediate packet */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4399 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4400 | } |
| 4401 | |
| 4402 | static void ov519_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4403 | u8 *data, /* isoc packet */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4404 | int len) /* iso packet length */ |
| 4405 | { |
| 4406 | /* Header of ov519 is 16 bytes: |
| 4407 | * Byte Value Description |
| 4408 | * 0 0xff magic |
| 4409 | * 1 0xff magic |
| 4410 | * 2 0xff magic |
| 4411 | * 3 0xXX 0x50 = SOF, 0x51 = EOF |
| 4412 | * 9 0xXX 0x01 initial frame without data, |
| 4413 | * 0x00 standard frame with image |
| 4414 | * 14 Lo in EOF: length of image data / 8 |
| 4415 | * 15 Hi |
| 4416 | */ |
| 4417 | |
| 4418 | if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) { |
| 4419 | switch (data[3]) { |
| 4420 | case 0x50: /* start of frame */ |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 4421 | /* Don't check the button state here, as the state |
| 4422 | usually (always ?) changes at EOF and checking it |
| 4423 | here leads to unnecessary snapshot state resets. */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4424 | #define HDRSZ 16 |
| 4425 | data += HDRSZ; |
| 4426 | len -= HDRSZ; |
| 4427 | #undef HDRSZ |
| 4428 | if (data[0] == 0xff || data[1] == 0xd8) |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4429 | gspca_frame_add(gspca_dev, FIRST_PACKET, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4430 | data, len); |
| 4431 | else |
| 4432 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 4433 | return; |
| 4434 | case 0x51: /* end of frame */ |
Hans de Goede | 92e232a | 2010-02-20 04:30:45 -0300 | [diff] [blame] | 4435 | ov51x_handle_button(gspca_dev, data[11] & 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4436 | if (data[9] != 0) |
| 4437 | gspca_dev->last_packet_type = DISCARD_PACKET; |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4438 | gspca_frame_add(gspca_dev, LAST_PACKET, |
| 4439 | NULL, 0); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4440 | return; |
| 4441 | } |
| 4442 | } |
| 4443 | |
| 4444 | /* intermediate packet */ |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4445 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4446 | } |
| 4447 | |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4448 | static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4449 | u8 *data, /* isoc packet */ |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4450 | int len) /* iso packet length */ |
| 4451 | { |
Hans de Goede | d6b6d7a | 2010-05-08 08:55:42 -0300 | [diff] [blame] | 4452 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | d6b6d7a | 2010-05-08 08:55:42 -0300 | [diff] [blame] | 4453 | |
| 4454 | gspca_frame_add(gspca_dev, INTER_PACKET, data, len); |
| 4455 | |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4456 | /* A short read signals EOF */ |
Jean-François Moine | 9d2b909 | 2011-05-22 04:56:32 -0300 | [diff] [blame] | 4457 | if (len < gspca_dev->cam.bulk_size) { |
Hans de Goede | d6b6d7a | 2010-05-08 08:55:42 -0300 | [diff] [blame] | 4458 | /* If the frame is short, and it is one of the first ones |
| 4459 | the sensor and bridge are still syncing, so drop it. */ |
| 4460 | if (sd->first_frame) { |
| 4461 | sd->first_frame--; |
Jean-François Moine | b192ca9 | 2010-06-27 03:08:19 -0300 | [diff] [blame] | 4462 | if (gspca_dev->image_len < |
Ondrej Zary | 1966bc2 | 2013-08-30 17:54:23 -0300 | [diff] [blame] | 4463 | sd->gspca_dev.pixfmt.width * |
| 4464 | sd->gspca_dev.pixfmt.height) |
Hans de Goede | d6b6d7a | 2010-05-08 08:55:42 -0300 | [diff] [blame] | 4465 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 4466 | } |
| 4467 | gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4468 | gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4469 | } |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4470 | } |
| 4471 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4472 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4473 | u8 *data, /* isoc packet */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4474 | int len) /* iso packet length */ |
| 4475 | { |
| 4476 | struct sd *sd = (struct sd *) gspca_dev; |
| 4477 | |
| 4478 | switch (sd->bridge) { |
| 4479 | case BRIDGE_OV511: |
| 4480 | case BRIDGE_OV511PLUS: |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4481 | ov511_pkt_scan(gspca_dev, data, len); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4482 | break; |
| 4483 | case BRIDGE_OV518: |
| 4484 | case BRIDGE_OV518PLUS: |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4485 | ov518_pkt_scan(gspca_dev, data, len); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4486 | break; |
| 4487 | case BRIDGE_OV519: |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4488 | ov519_pkt_scan(gspca_dev, data, len); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4489 | break; |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4490 | case BRIDGE_OVFX2: |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4491 | ovfx2_pkt_scan(gspca_dev, data, len); |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4492 | break; |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4493 | case BRIDGE_W9968CF: |
Jean-Francois Moine | 76dd272 | 2009-11-13 09:21:03 -0300 | [diff] [blame] | 4494 | w9968cf_pkt_scan(gspca_dev, data, len); |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4495 | break; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4496 | } |
| 4497 | } |
| 4498 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4499 | /* -- management routines -- */ |
| 4500 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4501 | static void setbrightness(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4502 | { |
| 4503 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4504 | static const struct ov_i2c_regvals brit_7660[][7] = { |
| 4505 | {{0x0f, 0x6a}, {0x24, 0x40}, {0x25, 0x2b}, {0x26, 0x90}, |
| 4506 | {0x27, 0xe0}, {0x28, 0xe0}, {0x2c, 0xe0}}, |
| 4507 | {{0x0f, 0x6a}, {0x24, 0x50}, {0x25, 0x40}, {0x26, 0xa1}, |
| 4508 | {0x27, 0xc0}, {0x28, 0xc0}, {0x2c, 0xc0}}, |
| 4509 | {{0x0f, 0x6a}, {0x24, 0x68}, {0x25, 0x58}, {0x26, 0xc2}, |
| 4510 | {0x27, 0xa0}, {0x28, 0xa0}, {0x2c, 0xa0}}, |
| 4511 | {{0x0f, 0x6a}, {0x24, 0x70}, {0x25, 0x68}, {0x26, 0xd3}, |
| 4512 | {0x27, 0x80}, {0x28, 0x80}, {0x2c, 0x80}}, |
| 4513 | {{0x0f, 0x6a}, {0x24, 0x80}, {0x25, 0x70}, {0x26, 0xd3}, |
| 4514 | {0x27, 0x20}, {0x28, 0x20}, {0x2c, 0x20}}, |
| 4515 | {{0x0f, 0x6a}, {0x24, 0x88}, {0x25, 0x78}, {0x26, 0xd3}, |
| 4516 | {0x27, 0x40}, {0x28, 0x40}, {0x2c, 0x40}}, |
| 4517 | {{0x0f, 0x6a}, {0x24, 0x90}, {0x25, 0x80}, {0x26, 0xd4}, |
| 4518 | {0x27, 0x60}, {0x28, 0x60}, {0x2c, 0x60}} |
| 4519 | }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4520 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4521 | switch (sd->sensor) { |
| 4522 | case SEN_OV8610: |
| 4523 | case SEN_OV7610: |
| 4524 | case SEN_OV76BE: |
| 4525 | case SEN_OV6620: |
| 4526 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4527 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4528 | case SEN_OV7640: |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 4529 | case SEN_OV7648: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4530 | i2c_w(sd, OV7610_REG_BRT, val); |
| 4531 | break; |
| 4532 | case SEN_OV7620: |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 4533 | case SEN_OV7620AE: |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4534 | i2c_w(sd, OV7610_REG_BRT, val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4535 | break; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4536 | case SEN_OV7660: |
| 4537 | write_i2c_regvals(sd, brit_7660[val], |
| 4538 | ARRAY_SIZE(brit_7660[0])); |
| 4539 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4540 | case SEN_OV7670: |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 4541 | /*win trace |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4542 | * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */ |
| 4543 | i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val)); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4544 | break; |
| 4545 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4546 | } |
| 4547 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4548 | static void setcontrast(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4549 | { |
| 4550 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4551 | static const struct ov_i2c_regvals contrast_7660[][31] = { |
| 4552 | {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf8}, {0x6f, 0xa0}, |
| 4553 | {0x70, 0x58}, {0x71, 0x38}, {0x72, 0x30}, {0x73, 0x30}, |
| 4554 | {0x74, 0x28}, {0x75, 0x28}, {0x76, 0x24}, {0x77, 0x24}, |
| 4555 | {0x78, 0x22}, {0x79, 0x28}, {0x7a, 0x2a}, {0x7b, 0x34}, |
| 4556 | {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3d}, {0x7f, 0x65}, |
| 4557 | {0x80, 0x70}, {0x81, 0x77}, {0x82, 0x7d}, {0x83, 0x83}, |
| 4558 | {0x84, 0x88}, {0x85, 0x8d}, {0x86, 0x96}, {0x87, 0x9f}, |
| 4559 | {0x88, 0xb0}, {0x89, 0xc4}, {0x8a, 0xd9}}, |
| 4560 | {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf8}, {0x6f, 0x94}, |
| 4561 | {0x70, 0x58}, {0x71, 0x40}, {0x72, 0x30}, {0x73, 0x30}, |
| 4562 | {0x74, 0x30}, {0x75, 0x30}, {0x76, 0x2c}, {0x77, 0x24}, |
| 4563 | {0x78, 0x22}, {0x79, 0x28}, {0x7a, 0x2a}, {0x7b, 0x31}, |
| 4564 | {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3d}, {0x7f, 0x62}, |
| 4565 | {0x80, 0x6d}, {0x81, 0x75}, {0x82, 0x7b}, {0x83, 0x81}, |
| 4566 | {0x84, 0x87}, {0x85, 0x8d}, {0x86, 0x98}, {0x87, 0xa1}, |
| 4567 | {0x88, 0xb2}, {0x89, 0xc6}, {0x8a, 0xdb}}, |
| 4568 | {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf0}, {0x6f, 0x84}, |
| 4569 | {0x70, 0x58}, {0x71, 0x48}, {0x72, 0x40}, {0x73, 0x40}, |
| 4570 | {0x74, 0x28}, {0x75, 0x28}, {0x76, 0x28}, {0x77, 0x24}, |
| 4571 | {0x78, 0x26}, {0x79, 0x28}, {0x7a, 0x28}, {0x7b, 0x34}, |
| 4572 | {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3c}, {0x7f, 0x5d}, |
| 4573 | {0x80, 0x68}, {0x81, 0x71}, {0x82, 0x79}, {0x83, 0x81}, |
| 4574 | {0x84, 0x86}, {0x85, 0x8b}, {0x86, 0x95}, {0x87, 0x9e}, |
| 4575 | {0x88, 0xb1}, {0x89, 0xc5}, {0x8a, 0xd9}}, |
| 4576 | {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf0}, {0x6f, 0x70}, |
| 4577 | {0x70, 0x58}, {0x71, 0x58}, {0x72, 0x48}, {0x73, 0x48}, |
| 4578 | {0x74, 0x38}, {0x75, 0x40}, {0x76, 0x34}, {0x77, 0x34}, |
| 4579 | {0x78, 0x2e}, {0x79, 0x28}, {0x7a, 0x24}, {0x7b, 0x22}, |
| 4580 | {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3c}, {0x7f, 0x58}, |
| 4581 | {0x80, 0x63}, {0x81, 0x6e}, {0x82, 0x77}, {0x83, 0x80}, |
| 4582 | {0x84, 0x87}, {0x85, 0x8f}, {0x86, 0x9c}, {0x87, 0xa9}, |
| 4583 | {0x88, 0xc0}, {0x89, 0xd4}, {0x8a, 0xe6}}, |
| 4584 | {{0x6c, 0xa0}, {0x6d, 0xf0}, {0x6e, 0x90}, {0x6f, 0x80}, |
| 4585 | {0x70, 0x70}, {0x71, 0x80}, {0x72, 0x60}, {0x73, 0x60}, |
| 4586 | {0x74, 0x58}, {0x75, 0x60}, {0x76, 0x4c}, {0x77, 0x38}, |
| 4587 | {0x78, 0x38}, {0x79, 0x2a}, {0x7a, 0x20}, {0x7b, 0x0e}, |
| 4588 | {0x7c, 0x0a}, {0x7d, 0x14}, {0x7e, 0x26}, {0x7f, 0x46}, |
| 4589 | {0x80, 0x54}, {0x81, 0x64}, {0x82, 0x70}, {0x83, 0x7c}, |
| 4590 | {0x84, 0x87}, {0x85, 0x93}, {0x86, 0xa6}, {0x87, 0xb4}, |
| 4591 | {0x88, 0xd0}, {0x89, 0xe5}, {0x8a, 0xf5}}, |
| 4592 | {{0x6c, 0x60}, {0x6d, 0x80}, {0x6e, 0x60}, {0x6f, 0x80}, |
| 4593 | {0x70, 0x80}, {0x71, 0x80}, {0x72, 0x88}, {0x73, 0x30}, |
| 4594 | {0x74, 0x70}, {0x75, 0x68}, {0x76, 0x64}, {0x77, 0x50}, |
| 4595 | {0x78, 0x3c}, {0x79, 0x22}, {0x7a, 0x10}, {0x7b, 0x08}, |
| 4596 | {0x7c, 0x06}, {0x7d, 0x0e}, {0x7e, 0x1a}, {0x7f, 0x3a}, |
| 4597 | {0x80, 0x4a}, {0x81, 0x5a}, {0x82, 0x6b}, {0x83, 0x7b}, |
| 4598 | {0x84, 0x89}, {0x85, 0x96}, {0x86, 0xaf}, {0x87, 0xc3}, |
| 4599 | {0x88, 0xe1}, {0x89, 0xf2}, {0x8a, 0xfa}}, |
| 4600 | {{0x6c, 0x20}, {0x6d, 0x40}, {0x6e, 0x20}, {0x6f, 0x60}, |
| 4601 | {0x70, 0x88}, {0x71, 0xc8}, {0x72, 0xc0}, {0x73, 0xb8}, |
| 4602 | {0x74, 0xa8}, {0x75, 0xb8}, {0x76, 0x80}, {0x77, 0x5c}, |
| 4603 | {0x78, 0x26}, {0x79, 0x10}, {0x7a, 0x08}, {0x7b, 0x04}, |
| 4604 | {0x7c, 0x02}, {0x7d, 0x06}, {0x7e, 0x0a}, {0x7f, 0x22}, |
| 4605 | {0x80, 0x33}, {0x81, 0x4c}, {0x82, 0x64}, {0x83, 0x7b}, |
| 4606 | {0x84, 0x90}, {0x85, 0xa7}, {0x86, 0xc7}, {0x87, 0xde}, |
| 4607 | {0x88, 0xf1}, {0x89, 0xf9}, {0x8a, 0xfd}}, |
| 4608 | }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4609 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4610 | switch (sd->sensor) { |
| 4611 | case SEN_OV7610: |
| 4612 | case SEN_OV6620: |
| 4613 | i2c_w(sd, OV7610_REG_CNT, val); |
| 4614 | break; |
| 4615 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4616 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4617 | i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4618 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4619 | case SEN_OV8610: { |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 4620 | static const u8 ctab[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4621 | 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f |
| 4622 | }; |
| 4623 | |
| 4624 | /* Use Y gamma control instead. Bit 0 enables it. */ |
| 4625 | i2c_w(sd, 0x64, ctab[val >> 5]); |
| 4626 | break; |
| 4627 | } |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 4628 | case SEN_OV7620: |
| 4629 | case SEN_OV7620AE: { |
Jean-François Moine | 9d1593a | 2010-11-11 08:04:06 -0300 | [diff] [blame] | 4630 | static const u8 ctab[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4631 | 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57, |
| 4632 | 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff |
| 4633 | }; |
| 4634 | |
| 4635 | /* Use Y gamma control instead. Bit 0 enables it. */ |
| 4636 | i2c_w(sd, 0x64, ctab[val >> 4]); |
| 4637 | break; |
| 4638 | } |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4639 | case SEN_OV7660: |
| 4640 | write_i2c_regvals(sd, contrast_7660[val], |
| 4641 | ARRAY_SIZE(contrast_7660[0])); |
| 4642 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4643 | case SEN_OV7670: |
| 4644 | /* check that this isn't just the same as ov7610 */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4645 | i2c_w(sd, OV7670_R56_CONTRAS, val >> 1); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4646 | break; |
| 4647 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4648 | } |
| 4649 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4650 | static void setexposure(struct gspca_dev *gspca_dev, s32 val) |
Jean-François Moine | 58c92d3 | 2011-03-13 16:36:49 -0300 | [diff] [blame] | 4651 | { |
| 4652 | struct sd *sd = (struct sd *) gspca_dev; |
| 4653 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4654 | i2c_w(sd, 0x10, val); |
Jean-François Moine | 58c92d3 | 2011-03-13 16:36:49 -0300 | [diff] [blame] | 4655 | } |
| 4656 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4657 | static void setcolors(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4658 | { |
| 4659 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4660 | static const struct ov_i2c_regvals colors_7660[][6] = { |
| 4661 | {{0x4f, 0x28}, {0x50, 0x2a}, {0x51, 0x02}, {0x52, 0x0a}, |
| 4662 | {0x53, 0x19}, {0x54, 0x23}}, |
| 4663 | {{0x4f, 0x47}, {0x50, 0x4a}, {0x51, 0x03}, {0x52, 0x11}, |
| 4664 | {0x53, 0x2c}, {0x54, 0x3e}}, |
| 4665 | {{0x4f, 0x66}, {0x50, 0x6b}, {0x51, 0x05}, {0x52, 0x19}, |
| 4666 | {0x53, 0x40}, {0x54, 0x59}}, |
| 4667 | {{0x4f, 0x84}, {0x50, 0x8b}, {0x51, 0x06}, {0x52, 0x20}, |
| 4668 | {0x53, 0x53}, {0x54, 0x73}}, |
| 4669 | {{0x4f, 0xa3}, {0x50, 0xab}, {0x51, 0x08}, {0x52, 0x28}, |
| 4670 | {0x53, 0x66}, {0x54, 0x8e}}, |
| 4671 | }; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4672 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4673 | switch (sd->sensor) { |
| 4674 | case SEN_OV8610: |
| 4675 | case SEN_OV7610: |
| 4676 | case SEN_OV76BE: |
| 4677 | case SEN_OV6620: |
| 4678 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4679 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4680 | i2c_w(sd, OV7610_REG_SAT, val); |
| 4681 | break; |
| 4682 | case SEN_OV7620: |
Hans de Goede | 859cc47 | 2010-01-07 15:42:35 -0300 | [diff] [blame] | 4683 | case SEN_OV7620AE: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4684 | /* Use UV gamma control instead. Bits 0 & 7 are reserved. */ |
| 4685 | /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e); |
| 4686 | if (rc < 0) |
| 4687 | goto out; */ |
| 4688 | i2c_w(sd, OV7610_REG_SAT, val); |
| 4689 | break; |
| 4690 | case SEN_OV7640: |
Hans de Goede | 035d3a3 | 2010-01-09 08:14:43 -0300 | [diff] [blame] | 4691 | case SEN_OV7648: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4692 | i2c_w(sd, OV7610_REG_SAT, val & 0xf0); |
| 4693 | break; |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4694 | case SEN_OV7660: |
| 4695 | write_i2c_regvals(sd, colors_7660[val], |
| 4696 | ARRAY_SIZE(colors_7660[0])); |
| 4697 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4698 | case SEN_OV7670: |
| 4699 | /* supported later once I work out how to do it |
| 4700 | * transparently fail now! */ |
| 4701 | /* set REG_COM13 values for UV sat auto mode */ |
| 4702 | break; |
| 4703 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4704 | } |
| 4705 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4706 | static void setautobright(struct gspca_dev *gspca_dev, s32 val) |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4707 | { |
Jean-François Moine | 62833ac | 2010-10-02 04:27:02 -0300 | [diff] [blame] | 4708 | struct sd *sd = (struct sd *) gspca_dev; |
| 4709 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4710 | i2c_w_mask(sd, 0x2d, val ? 0x10 : 0x00, 0x10); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4711 | } |
| 4712 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4713 | static void setfreq_i(struct sd *sd, s32 val) |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4714 | { |
Jean-François Moine | 42e142f | 2010-11-13 05:10:27 -0300 | [diff] [blame] | 4715 | if (sd->sensor == SEN_OV7660 |
| 4716 | || sd->sensor == SEN_OV7670) { |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4717 | switch (val) { |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4718 | case 0: /* Banding filter disabled */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4719 | i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4720 | break; |
| 4721 | case 1: /* 50 hz */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4722 | i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4723 | OV7670_COM8_BFILT); |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4724 | i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4725 | break; |
| 4726 | case 2: /* 60 hz */ |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4727 | i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4728 | OV7670_COM8_BFILT); |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4729 | i2c_w_mask(sd, OV7670_R3B_COM11, 0x00, 0x18); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4730 | break; |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4731 | case 3: /* Auto hz - ov7670 only */ |
| 4732 | i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4733 | OV7670_COM8_BFILT); |
Jean-François Moine | 2186780 | 2010-11-12 06:12:09 -0300 | [diff] [blame] | 4734 | i2c_w_mask(sd, OV7670_R3B_COM11, OV7670_COM11_HZAUTO, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4735 | 0x18); |
| 4736 | break; |
| 4737 | } |
| 4738 | } else { |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4739 | switch (val) { |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4740 | case 0: /* Banding filter disabled */ |
| 4741 | i2c_w_mask(sd, 0x2d, 0x00, 0x04); |
| 4742 | i2c_w_mask(sd, 0x2a, 0x00, 0x80); |
| 4743 | break; |
| 4744 | case 1: /* 50 hz (filter on and framerate adj) */ |
| 4745 | i2c_w_mask(sd, 0x2d, 0x04, 0x04); |
| 4746 | i2c_w_mask(sd, 0x2a, 0x80, 0x80); |
| 4747 | /* 20 fps -> 16.667 fps */ |
| 4748 | if (sd->sensor == SEN_OV6620 || |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4749 | sd->sensor == SEN_OV6630 || |
| 4750 | sd->sensor == SEN_OV66308AF) |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4751 | i2c_w(sd, 0x2b, 0x5e); |
| 4752 | else |
| 4753 | i2c_w(sd, 0x2b, 0xac); |
| 4754 | break; |
| 4755 | case 2: /* 60 hz (filter on, ...) */ |
| 4756 | i2c_w_mask(sd, 0x2d, 0x04, 0x04); |
| 4757 | if (sd->sensor == SEN_OV6620 || |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 4758 | sd->sensor == SEN_OV6630 || |
| 4759 | sd->sensor == SEN_OV66308AF) { |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4760 | /* 20 fps -> 15 fps */ |
| 4761 | i2c_w_mask(sd, 0x2a, 0x80, 0x80); |
| 4762 | i2c_w(sd, 0x2b, 0xa8); |
| 4763 | } else { |
| 4764 | /* no framerate adj. */ |
| 4765 | i2c_w_mask(sd, 0x2a, 0x00, 0x80); |
| 4766 | } |
| 4767 | break; |
| 4768 | } |
| 4769 | } |
| 4770 | } |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4771 | |
| 4772 | static void setfreq(struct gspca_dev *gspca_dev, s32 val) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4773 | { |
| 4774 | struct sd *sd = (struct sd *) gspca_dev; |
| 4775 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4776 | setfreq_i(sd, val); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4777 | |
Jean-François Moine | 62833ac | 2010-10-02 04:27:02 -0300 | [diff] [blame] | 4778 | /* Ugly but necessary */ |
| 4779 | if (sd->bridge == BRIDGE_W9968CF) |
| 4780 | w9968cf_set_crop_window(sd); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 4781 | } |
| 4782 | |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4783 | static int sd_get_jcomp(struct gspca_dev *gspca_dev, |
| 4784 | struct v4l2_jpegcompression *jcomp) |
| 4785 | { |
| 4786 | struct sd *sd = (struct sd *) gspca_dev; |
| 4787 | |
| 4788 | if (sd->bridge != BRIDGE_W9968CF) |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4789 | return -ENOTTY; |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4790 | |
| 4791 | memset(jcomp, 0, sizeof *jcomp); |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4792 | jcomp->quality = v4l2_ctrl_g_ctrl(sd->jpegqual); |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4793 | jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT | |
| 4794 | V4L2_JPEG_MARKER_DRI; |
| 4795 | return 0; |
| 4796 | } |
| 4797 | |
| 4798 | static int sd_set_jcomp(struct gspca_dev *gspca_dev, |
Hans Verkuil | d88aab5 | 2012-09-17 05:05:25 -0300 | [diff] [blame] | 4799 | const struct v4l2_jpegcompression *jcomp) |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4800 | { |
| 4801 | struct sd *sd = (struct sd *) gspca_dev; |
| 4802 | |
| 4803 | if (sd->bridge != BRIDGE_W9968CF) |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4804 | return -ENOTTY; |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4805 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4806 | v4l2_ctrl_s_ctrl(sd->jpegqual, jcomp->quality); |
| 4807 | return 0; |
| 4808 | } |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4809 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4810 | static int sd_g_volatile_ctrl(struct v4l2_ctrl *ctrl) |
| 4811 | { |
| 4812 | struct gspca_dev *gspca_dev = |
| 4813 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); |
| 4814 | struct sd *sd = (struct sd *)gspca_dev; |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4815 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4816 | gspca_dev->usb_err = 0; |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4817 | |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4818 | switch (ctrl->id) { |
| 4819 | case V4L2_CID_AUTOGAIN: |
| 4820 | gspca_dev->exposure->val = i2c_r(sd, 0x10); |
| 4821 | break; |
| 4822 | } |
| 4823 | return 0; |
| 4824 | } |
| 4825 | |
| 4826 | static int sd_s_ctrl(struct v4l2_ctrl *ctrl) |
| 4827 | { |
| 4828 | struct gspca_dev *gspca_dev = |
| 4829 | container_of(ctrl->handler, struct gspca_dev, ctrl_handler); |
| 4830 | struct sd *sd = (struct sd *)gspca_dev; |
| 4831 | |
| 4832 | gspca_dev->usb_err = 0; |
| 4833 | |
| 4834 | if (!gspca_dev->streaming) |
| 4835 | return 0; |
| 4836 | |
| 4837 | switch (ctrl->id) { |
| 4838 | case V4L2_CID_BRIGHTNESS: |
| 4839 | setbrightness(gspca_dev, ctrl->val); |
| 4840 | break; |
| 4841 | case V4L2_CID_CONTRAST: |
| 4842 | setcontrast(gspca_dev, ctrl->val); |
| 4843 | break; |
| 4844 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 4845 | setfreq(gspca_dev, ctrl->val); |
| 4846 | break; |
| 4847 | case V4L2_CID_AUTOBRIGHTNESS: |
| 4848 | if (ctrl->is_new) |
| 4849 | setautobright(gspca_dev, ctrl->val); |
| 4850 | if (!ctrl->val && sd->brightness->is_new) |
| 4851 | setbrightness(gspca_dev, sd->brightness->val); |
| 4852 | break; |
| 4853 | case V4L2_CID_SATURATION: |
| 4854 | setcolors(gspca_dev, ctrl->val); |
| 4855 | break; |
| 4856 | case V4L2_CID_HFLIP: |
| 4857 | sethvflip(gspca_dev, ctrl->val, sd->vflip->val); |
| 4858 | break; |
| 4859 | case V4L2_CID_AUTOGAIN: |
| 4860 | if (ctrl->is_new) |
| 4861 | setautogain(gspca_dev, ctrl->val); |
| 4862 | if (!ctrl->val && gspca_dev->exposure->is_new) |
| 4863 | setexposure(gspca_dev, gspca_dev->exposure->val); |
| 4864 | break; |
| 4865 | case V4L2_CID_JPEG_COMPRESSION_QUALITY: |
| 4866 | return -EBUSY; /* Should never happen, as we grab the ctrl */ |
| 4867 | } |
| 4868 | return gspca_dev->usb_err; |
| 4869 | } |
| 4870 | |
| 4871 | static const struct v4l2_ctrl_ops sd_ctrl_ops = { |
| 4872 | .g_volatile_ctrl = sd_g_volatile_ctrl, |
| 4873 | .s_ctrl = sd_s_ctrl, |
| 4874 | }; |
| 4875 | |
| 4876 | static int sd_init_controls(struct gspca_dev *gspca_dev) |
| 4877 | { |
| 4878 | struct sd *sd = (struct sd *)gspca_dev; |
| 4879 | struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler; |
| 4880 | |
| 4881 | gspca_dev->vdev.ctrl_handler = hdl; |
| 4882 | v4l2_ctrl_handler_init(hdl, 10); |
| 4883 | if (valid_controls[sd->sensor].has_brightness) |
| 4884 | sd->brightness = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4885 | V4L2_CID_BRIGHTNESS, 0, |
| 4886 | sd->sensor == SEN_OV7660 ? 6 : 255, 1, |
| 4887 | sd->sensor == SEN_OV7660 ? 3 : 127); |
| 4888 | if (valid_controls[sd->sensor].has_contrast) { |
| 4889 | if (sd->sensor == SEN_OV7660) |
| 4890 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4891 | V4L2_CID_CONTRAST, 0, 6, 1, 3); |
| 4892 | else |
| 4893 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4894 | V4L2_CID_CONTRAST, 0, 255, 1, |
| 4895 | (sd->sensor == SEN_OV6630 || |
| 4896 | sd->sensor == SEN_OV66308AF) ? 200 : 127); |
| 4897 | } |
| 4898 | if (valid_controls[sd->sensor].has_sat) |
| 4899 | v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4900 | V4L2_CID_SATURATION, 0, |
| 4901 | sd->sensor == SEN_OV7660 ? 4 : 255, 1, |
| 4902 | sd->sensor == SEN_OV7660 ? 2 : 127); |
| 4903 | if (valid_controls[sd->sensor].has_exposure) |
| 4904 | gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4905 | V4L2_CID_EXPOSURE, 0, 255, 1, 127); |
| 4906 | if (valid_controls[sd->sensor].has_hvflip) { |
| 4907 | sd->hflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4908 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
| 4909 | sd->vflip = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4910 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
| 4911 | } |
| 4912 | if (valid_controls[sd->sensor].has_autobright) |
| 4913 | sd->autobright = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4914 | V4L2_CID_AUTOBRIGHTNESS, 0, 1, 1, 1); |
| 4915 | if (valid_controls[sd->sensor].has_autogain) |
| 4916 | gspca_dev->autogain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4917 | V4L2_CID_AUTOGAIN, 0, 1, 1, 1); |
| 4918 | if (valid_controls[sd->sensor].has_freq) { |
| 4919 | if (sd->sensor == SEN_OV7670) |
| 4920 | sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, |
| 4921 | V4L2_CID_POWER_LINE_FREQUENCY, |
| 4922 | V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0, |
| 4923 | V4L2_CID_POWER_LINE_FREQUENCY_AUTO); |
| 4924 | else |
| 4925 | sd->freq = v4l2_ctrl_new_std_menu(hdl, &sd_ctrl_ops, |
| 4926 | V4L2_CID_POWER_LINE_FREQUENCY, |
| 4927 | V4L2_CID_POWER_LINE_FREQUENCY_60HZ, 0, 0); |
| 4928 | } |
| 4929 | if (sd->bridge == BRIDGE_W9968CF) |
| 4930 | sd->jpegqual = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops, |
| 4931 | V4L2_CID_JPEG_COMPRESSION_QUALITY, |
| 4932 | QUALITY_MIN, QUALITY_MAX, 1, QUALITY_DEF); |
| 4933 | |
| 4934 | if (hdl->error) { |
Theodore Kilgore | c93396e | 2013-02-04 13:17:55 -0300 | [diff] [blame] | 4935 | PERR("Could not initialize controls\n"); |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4936 | return hdl->error; |
| 4937 | } |
| 4938 | if (gspca_dev->autogain) |
| 4939 | v4l2_ctrl_auto_cluster(3, &gspca_dev->autogain, 0, true); |
| 4940 | if (sd->autobright) |
| 4941 | v4l2_ctrl_auto_cluster(2, &sd->autobright, 0, false); |
| 4942 | if (sd->hflip) |
| 4943 | v4l2_ctrl_cluster(2, &sd->hflip); |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4944 | return 0; |
| 4945 | } |
| 4946 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4947 | /* sub-driver description */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 4948 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4949 | .name = MODULE_NAME, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4950 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 4951 | .init = sd_init, |
Hans Verkuil | cf9211e | 2012-05-16 06:19:46 -0300 | [diff] [blame] | 4952 | .init_controls = sd_init_controls, |
Jean-François Moine | c42cedb | 2011-02-10 13:37:48 -0300 | [diff] [blame] | 4953 | .isoc_init = sd_isoc_init, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4954 | .start = sd_start, |
| 4955 | .stopN = sd_stopN, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4956 | .stop0 = sd_stop0, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4957 | .pkt_scan = sd_pkt_scan, |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 4958 | .dq_callback = sd_reset_snapshot, |
Hans de Goede | 79b3590 | 2009-10-19 06:08:01 -0300 | [diff] [blame] | 4959 | .get_jcomp = sd_get_jcomp, |
| 4960 | .set_jcomp = sd_set_jcomp, |
Peter Senna Tschudin | c4ea799 | 2013-01-24 19:29:01 -0300 | [diff] [blame] | 4961 | #if IS_ENABLED(CONFIG_INPUT) |
Hans de Goede | 417a4d2 | 2010-02-19 07:37:08 -0300 | [diff] [blame] | 4962 | .other_input = 1, |
| 4963 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4964 | }; |
| 4965 | |
| 4966 | /* -- module initialisation -- */ |
Jean-François Moine | 95c967c | 2011-01-13 05:20:29 -0300 | [diff] [blame] | 4967 | static const struct usb_device_id device_table[] = { |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4968 | {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF }, |
Jean-François Moine | 72a16e8 | 2011-08-09 05:28:17 -0300 | [diff] [blame] | 4969 | {USB_DEVICE(0x041e, 0x4052), |
Jean-François Moine | 0fdee88 | 2011-07-03 05:24:05 -0300 | [diff] [blame] | 4970 | .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, |
Jean-François Moine | 72a16e8 | 2011-08-09 05:28:17 -0300 | [diff] [blame] | 4971 | {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 }, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4972 | {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 }, |
| 4973 | {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 }, |
Jean-François Moine | 72a16e8 | 2011-08-09 05:28:17 -0300 | [diff] [blame] | 4974 | {USB_DEVICE(0x041e, 0x4064), .driver_info = BRIDGE_OV519 }, |
Rafal Milecki | 518c8df | 2009-10-02 03:54:44 -0300 | [diff] [blame] | 4975 | {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 }, |
Jean-François Moine | 72a16e8 | 2011-08-09 05:28:17 -0300 | [diff] [blame] | 4976 | {USB_DEVICE(0x041e, 0x4068), .driver_info = BRIDGE_OV519 }, |
| 4977 | {USB_DEVICE(0x045e, 0x028c), |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 4978 | .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4979 | {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 }, |
Jean-François Moine | 72a16e8 | 2011-08-09 05:28:17 -0300 | [diff] [blame] | 4980 | {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 }, |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4981 | {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 }, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4982 | {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 }, |
Jean-François Moine | 72a16e8 | 2011-08-09 05:28:17 -0300 | [diff] [blame] | 4983 | {USB_DEVICE(0x05a9, 0x0519), |
| 4984 | .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, |
| 4985 | {USB_DEVICE(0x05a9, 0x0530), |
| 4986 | .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4987 | {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 }, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4988 | {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 }, |
| 4989 | {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 }, |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4990 | {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS }, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 4991 | {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS }, |
Hans de Goede | 1876bb9 | 2009-06-14 06:45:50 -0300 | [diff] [blame] | 4992 | {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS }, |
Hans de Goede | b46aaa0 | 2009-10-12 10:07:57 -0300 | [diff] [blame] | 4993 | {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 }, |
| 4994 | {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 }, |
Hans de Goede | a511ba9 | 2009-10-16 07:13:07 -0300 | [diff] [blame] | 4995 | {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF }, |
Jean-François Moine | 87bae74 | 2010-11-12 05:31:34 -0300 | [diff] [blame] | 4996 | {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 4997 | {} |
| 4998 | }; |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 4999 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 5000 | MODULE_DEVICE_TABLE(usb, device_table); |
| 5001 | |
| 5002 | /* -- device connect -- */ |
| 5003 | static int sd_probe(struct usb_interface *intf, |
| 5004 | const struct usb_device_id *id) |
| 5005 | { |
| 5006 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 5007 | THIS_MODULE); |
| 5008 | } |
| 5009 | |
| 5010 | static struct usb_driver sd_driver = { |
| 5011 | .name = MODULE_NAME, |
| 5012 | .id_table = device_table, |
| 5013 | .probe = sd_probe, |
| 5014 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 5015 | #ifdef CONFIG_PM |
| 5016 | .suspend = gspca_suspend, |
| 5017 | .resume = gspca_resume, |
Hans de Goede | 8bb5896 | 2012-06-30 06:44:47 -0300 | [diff] [blame] | 5018 | .reset_resume = gspca_resume, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 5019 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 5020 | }; |
| 5021 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 5022 | module_usb_driver(sd_driver); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 5023 | |
| 5024 | module_param(frame_rate, int, 0644); |
| 5025 | MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)"); |