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