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