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) |
| 5 | * |
Romain Beauxis | 2961e875 | 2008-12-05 06:25:26 -0300 | [diff] [blame] | 6 | * This module is adapted from the ov51x-jpeg package, which itself |
| 7 | * was adapted from the ov511 driver. |
| 8 | * |
| 9 | * Original copyright for the ov511 driver is: |
| 10 | * |
| 11 | * Copyright (c) 1999-2004 Mark W. McClelland |
| 12 | * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach |
| 13 | * |
| 14 | * ov51x-jpeg original copyright is: |
| 15 | * |
| 16 | * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org> |
| 17 | * 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] | 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License as published by |
| 21 | * the Free Software Foundation; either version 2 of the License, or |
| 22 | * any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 32 | * |
| 33 | */ |
| 34 | #define MODULE_NAME "ov519" |
| 35 | |
| 36 | #include "gspca.h" |
| 37 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 38 | MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); |
| 39 | MODULE_DESCRIPTION("OV519 USB Camera Driver"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
| 42 | /* global parameters */ |
| 43 | static int frame_rate; |
| 44 | |
| 45 | /* Number of times to retry a failed I2C transaction. Increase this if you |
| 46 | * are getting "Failed to read sensor ID..." */ |
| 47 | static int i2c_detect_tries = 10; |
| 48 | |
| 49 | /* ov519 device descriptor */ |
| 50 | struct sd { |
| 51 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
| 52 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 53 | char bridge; |
| 54 | #define BRIDGE_OV511 0 |
| 55 | #define BRIDGE_OV511PLUS 1 |
| 56 | #define BRIDGE_OV518 2 |
| 57 | #define BRIDGE_OV518PLUS 3 |
| 58 | #define BRIDGE_OV519 4 |
| 59 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 60 | /* Determined by sensor type */ |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 61 | __u8 sif; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 62 | |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 63 | __u8 brightness; |
| 64 | __u8 contrast; |
| 65 | __u8 colors; |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 66 | __u8 hflip; |
| 67 | __u8 vflip; |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 68 | __u8 autobrightness; |
| 69 | __u8 freq; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 70 | |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 71 | __u8 stopped; /* Streaming is temporarily paused */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 72 | |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 73 | __u8 frame_rate; /* current Framerate (OV519 only) */ |
| 74 | __u8 clockdiv; /* clockdiv override for OV519 only */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 75 | |
| 76 | char sensor; /* Type of image sensor chip (SEN_*) */ |
| 77 | #define SEN_UNKNOWN 0 |
| 78 | #define SEN_OV6620 1 |
| 79 | #define SEN_OV6630 2 |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 80 | #define SEN_OV66308AF 3 |
| 81 | #define SEN_OV7610 4 |
| 82 | #define SEN_OV7620 5 |
| 83 | #define SEN_OV7640 6 |
| 84 | #define SEN_OV7670 7 |
| 85 | #define SEN_OV76BE 8 |
| 86 | #define SEN_OV8610 9 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /* V4L2 controls supported by the driver */ |
| 90 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); |
| 91 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); |
| 92 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); |
| 93 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); |
| 94 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); |
| 95 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 96 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); |
| 97 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); |
| 98 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); |
| 99 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 100 | static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val); |
| 101 | static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val); |
| 102 | static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); |
| 103 | static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 104 | static void setbrightness(struct gspca_dev *gspca_dev); |
| 105 | static void setcontrast(struct gspca_dev *gspca_dev); |
| 106 | static void setcolors(struct gspca_dev *gspca_dev); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 107 | static void setautobrightness(struct sd *sd); |
| 108 | static void setfreq(struct sd *sd); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 109 | |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 110 | static const struct ctrl sd_ctrls[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 111 | { |
| 112 | { |
| 113 | .id = V4L2_CID_BRIGHTNESS, |
| 114 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 115 | .name = "Brightness", |
| 116 | .minimum = 0, |
| 117 | .maximum = 255, |
| 118 | .step = 1, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 119 | #define BRIGHTNESS_DEF 127 |
| 120 | .default_value = BRIGHTNESS_DEF, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 121 | }, |
| 122 | .set = sd_setbrightness, |
| 123 | .get = sd_getbrightness, |
| 124 | }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 125 | { |
| 126 | { |
| 127 | .id = V4L2_CID_CONTRAST, |
| 128 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 129 | .name = "Contrast", |
| 130 | .minimum = 0, |
| 131 | .maximum = 255, |
| 132 | .step = 1, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 133 | #define CONTRAST_DEF 127 |
| 134 | .default_value = CONTRAST_DEF, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 135 | }, |
| 136 | .set = sd_setcontrast, |
| 137 | .get = sd_getcontrast, |
| 138 | }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 139 | { |
| 140 | { |
| 141 | .id = V4L2_CID_SATURATION, |
| 142 | .type = V4L2_CTRL_TYPE_INTEGER, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 143 | .name = "Color", |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 144 | .minimum = 0, |
| 145 | .maximum = 255, |
| 146 | .step = 1, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 147 | #define COLOR_DEF 127 |
| 148 | .default_value = COLOR_DEF, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 149 | }, |
| 150 | .set = sd_setcolors, |
| 151 | .get = sd_getcolors, |
| 152 | }, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 153 | /* The flip controls work with ov7670 only */ |
Jean-Francois Moine | de00448 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 154 | #define HFLIP_IDX 3 |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 155 | { |
| 156 | { |
| 157 | .id = V4L2_CID_HFLIP, |
| 158 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 159 | .name = "Mirror", |
| 160 | .minimum = 0, |
| 161 | .maximum = 1, |
| 162 | .step = 1, |
| 163 | #define HFLIP_DEF 0 |
| 164 | .default_value = HFLIP_DEF, |
| 165 | }, |
| 166 | .set = sd_sethflip, |
| 167 | .get = sd_gethflip, |
| 168 | }, |
Jean-Francois Moine | de00448 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 169 | #define VFLIP_IDX 4 |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 170 | { |
| 171 | { |
| 172 | .id = V4L2_CID_VFLIP, |
| 173 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 174 | .name = "Vflip", |
| 175 | .minimum = 0, |
| 176 | .maximum = 1, |
| 177 | .step = 1, |
| 178 | #define VFLIP_DEF 0 |
| 179 | .default_value = VFLIP_DEF, |
| 180 | }, |
| 181 | .set = sd_setvflip, |
| 182 | .get = sd_getvflip, |
| 183 | }, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 184 | #define AUTOBRIGHT_IDX 5 |
| 185 | { |
| 186 | { |
| 187 | .id = V4L2_CID_AUTOBRIGHTNESS, |
| 188 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 189 | .name = "Auto Brightness", |
| 190 | .minimum = 0, |
| 191 | .maximum = 1, |
| 192 | .step = 1, |
| 193 | #define AUTOBRIGHT_DEF 1 |
| 194 | .default_value = AUTOBRIGHT_DEF, |
| 195 | }, |
| 196 | .set = sd_setautobrightness, |
| 197 | .get = sd_getautobrightness, |
| 198 | }, |
| 199 | #define FREQ_IDX 6 |
| 200 | { |
| 201 | { |
| 202 | .id = V4L2_CID_POWER_LINE_FREQUENCY, |
| 203 | .type = V4L2_CTRL_TYPE_MENU, |
| 204 | .name = "Light frequency filter", |
| 205 | .minimum = 0, |
| 206 | .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ |
| 207 | .step = 1, |
| 208 | #define FREQ_DEF 0 |
| 209 | .default_value = FREQ_DEF, |
| 210 | }, |
| 211 | .set = sd_setfreq, |
| 212 | .get = sd_getfreq, |
| 213 | }, |
| 214 | #define OV7670_FREQ_IDX 7 |
| 215 | { |
| 216 | { |
| 217 | .id = V4L2_CID_POWER_LINE_FREQUENCY, |
| 218 | .type = V4L2_CTRL_TYPE_MENU, |
| 219 | .name = "Light frequency filter", |
| 220 | .minimum = 0, |
| 221 | .maximum = 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */ |
| 222 | .step = 1, |
| 223 | #define OV7670_FREQ_DEF 3 |
| 224 | .default_value = OV7670_FREQ_DEF, |
| 225 | }, |
| 226 | .set = sd_setfreq, |
| 227 | .get = sd_getfreq, |
| 228 | }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 229 | }; |
| 230 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 231 | static const struct v4l2_pix_format ov519_vga_mode[] = { |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 232 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 233 | .bytesperline = 320, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 234 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 235 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 236 | .priv = 1}, |
| 237 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 238 | .bytesperline = 640, |
| 239 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 240 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 241 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 242 | }; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 243 | static const struct v4l2_pix_format ov519_sif_mode[] = { |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 244 | {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 245 | .bytesperline = 160, |
| 246 | .sizeimage = 160 * 120 * 3 / 8 + 590, |
| 247 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 248 | .priv = 3}, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 249 | {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 250 | .bytesperline = 176, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 251 | .sizeimage = 176 * 144 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 252 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 253 | .priv = 1}, |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 254 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 255 | .bytesperline = 320, |
| 256 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 257 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 258 | .priv = 2}, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 259 | {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 260 | .bytesperline = 352, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 261 | .sizeimage = 352 * 288 * 3 / 8 + 590, |
Jean-Francois Moine | c2446b3 | 2008-07-05 11:49:20 -0300 | [diff] [blame] | 262 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 263 | .priv = 0}, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 264 | }; |
| 265 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 266 | static const struct v4l2_pix_format ov518_vga_mode[] = { |
| 267 | {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 268 | .bytesperline = 320, |
| 269 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 270 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 271 | .priv = 1}, |
| 272 | {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 273 | .bytesperline = 640, |
| 274 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
| 275 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 276 | .priv = 0}, |
| 277 | }; |
| 278 | static const struct v4l2_pix_format ov518_sif_mode[] = { |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 279 | {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 280 | .bytesperline = 160, |
| 281 | .sizeimage = 40000, |
| 282 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 283 | .priv = 3}, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 284 | {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 285 | .bytesperline = 176, |
| 286 | .sizeimage = 40000, |
| 287 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 288 | .priv = 1}, |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 289 | {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 290 | .bytesperline = 320, |
| 291 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 292 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 293 | .priv = 2}, |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 294 | {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE, |
| 295 | .bytesperline = 352, |
| 296 | .sizeimage = 352 * 288 * 3 / 8 + 590, |
| 297 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 298 | .priv = 0}, |
| 299 | }; |
| 300 | |
| 301 | |
| 302 | /* Registers common to OV511 / OV518 */ |
| 303 | #define R51x_SYS_RESET 0x50 |
| 304 | #define R51x_SYS_INIT 0x53 |
| 305 | #define R51x_SYS_SNAP 0x52 |
| 306 | #define R51x_SYS_CUST_ID 0x5F |
| 307 | #define R51x_COMP_LUT_BEGIN 0x80 |
| 308 | |
| 309 | /* OV511 Camera interface register numbers */ |
| 310 | #define R511_SYS_LED_CTL 0x55 /* OV511+ only */ |
| 311 | #define OV511_RESET_NOREGS 0x3F /* All but OV511 & regs */ |
| 312 | |
| 313 | /* OV518 Camera interface register numbers */ |
| 314 | #define R518_GPIO_OUT 0x56 /* OV518(+) only */ |
| 315 | #define R518_GPIO_CTL 0x57 /* OV518(+) only */ |
| 316 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 317 | /* OV519 Camera interface register numbers */ |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 318 | #define OV519_R10_H_SIZE 0x10 |
| 319 | #define OV519_R11_V_SIZE 0x11 |
| 320 | #define OV519_R12_X_OFFSETL 0x12 |
| 321 | #define OV519_R13_X_OFFSETH 0x13 |
| 322 | #define OV519_R14_Y_OFFSETL 0x14 |
| 323 | #define OV519_R15_Y_OFFSETH 0x15 |
| 324 | #define OV519_R16_DIVIDER 0x16 |
| 325 | #define OV519_R20_DFR 0x20 |
| 326 | #define OV519_R25_FORMAT 0x25 |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 327 | |
| 328 | /* OV519 System Controller register numbers */ |
| 329 | #define OV519_SYS_RESET1 0x51 |
| 330 | #define OV519_SYS_EN_CLK1 0x54 |
| 331 | |
| 332 | #define OV519_GPIO_DATA_OUT0 0x71 |
| 333 | #define OV519_GPIO_IO_CTRL0 0x72 |
| 334 | |
| 335 | #define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */ |
| 336 | |
| 337 | /* I2C registers */ |
| 338 | #define R51x_I2C_W_SID 0x41 |
| 339 | #define R51x_I2C_SADDR_3 0x42 |
| 340 | #define R51x_I2C_SADDR_2 0x43 |
| 341 | #define R51x_I2C_R_SID 0x44 |
| 342 | #define R51x_I2C_DATA 0x45 |
| 343 | #define R518_I2C_CTL 0x47 /* OV518(+) only */ |
| 344 | |
| 345 | /* I2C ADDRESSES */ |
| 346 | #define OV7xx0_SID 0x42 |
| 347 | #define OV8xx0_SID 0xa0 |
| 348 | #define OV6xx0_SID 0xc0 |
| 349 | |
| 350 | /* OV7610 registers */ |
| 351 | #define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 352 | #define OV7610_REG_BLUE 0x01 /* blue channel balance */ |
| 353 | #define OV7610_REG_RED 0x02 /* red channel balance */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 354 | #define OV7610_REG_SAT 0x03 /* saturation */ |
| 355 | #define OV8610_REG_HUE 0x04 /* 04 reserved */ |
| 356 | #define OV7610_REG_CNT 0x05 /* Y contrast */ |
| 357 | #define OV7610_REG_BRT 0x06 /* Y brightness */ |
| 358 | #define OV7610_REG_COM_C 0x14 /* misc common regs */ |
| 359 | #define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */ |
| 360 | #define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */ |
| 361 | #define OV7610_REG_COM_I 0x29 /* misc settings */ |
| 362 | |
| 363 | /* OV7670 registers */ |
| 364 | #define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */ |
| 365 | #define OV7670_REG_BLUE 0x01 /* blue gain */ |
| 366 | #define OV7670_REG_RED 0x02 /* red gain */ |
| 367 | #define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */ |
| 368 | #define OV7670_REG_COM1 0x04 /* Control 1 */ |
| 369 | #define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */ |
| 370 | #define OV7670_REG_COM3 0x0c /* Control 3 */ |
| 371 | #define OV7670_REG_COM4 0x0d /* Control 4 */ |
| 372 | #define OV7670_REG_COM5 0x0e /* All "reserved" */ |
| 373 | #define OV7670_REG_COM6 0x0f /* Control 6 */ |
| 374 | #define OV7670_REG_AECH 0x10 /* More bits of AEC value */ |
| 375 | #define OV7670_REG_CLKRC 0x11 /* Clock control */ |
| 376 | #define OV7670_REG_COM7 0x12 /* Control 7 */ |
| 377 | #define OV7670_COM7_FMT_VGA 0x00 |
| 378 | #define OV7670_COM7_YUV 0x00 /* YUV */ |
| 379 | #define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */ |
| 380 | #define OV7670_COM7_FMT_MASK 0x38 |
| 381 | #define OV7670_COM7_RESET 0x80 /* Register reset */ |
| 382 | #define OV7670_REG_COM8 0x13 /* Control 8 */ |
| 383 | #define OV7670_COM8_AEC 0x01 /* Auto exposure enable */ |
| 384 | #define OV7670_COM8_AWB 0x02 /* White balance enable */ |
| 385 | #define OV7670_COM8_AGC 0x04 /* Auto gain enable */ |
| 386 | #define OV7670_COM8_BFILT 0x20 /* Band filter enable */ |
| 387 | #define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */ |
| 388 | #define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */ |
| 389 | #define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */ |
| 390 | #define OV7670_REG_COM10 0x15 /* Control 10 */ |
| 391 | #define OV7670_REG_HSTART 0x17 /* Horiz start high bits */ |
| 392 | #define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */ |
| 393 | #define OV7670_REG_VSTART 0x19 /* Vert start high bits */ |
| 394 | #define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */ |
| 395 | #define OV7670_REG_MVFP 0x1e /* Mirror / vflip */ |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 396 | #define OV7670_MVFP_VFLIP 0x10 /* vertical flip */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 397 | #define OV7670_MVFP_MIRROR 0x20 /* Mirror image */ |
| 398 | #define OV7670_REG_AEW 0x24 /* AGC upper limit */ |
| 399 | #define OV7670_REG_AEB 0x25 /* AGC lower limit */ |
| 400 | #define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */ |
| 401 | #define OV7670_REG_HREF 0x32 /* HREF pieces */ |
| 402 | #define OV7670_REG_TSLB 0x3a /* lots of stuff */ |
| 403 | #define OV7670_REG_COM11 0x3b /* Control 11 */ |
| 404 | #define OV7670_COM11_EXP 0x02 |
| 405 | #define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */ |
| 406 | #define OV7670_REG_COM12 0x3c /* Control 12 */ |
| 407 | #define OV7670_REG_COM13 0x3d /* Control 13 */ |
| 408 | #define OV7670_COM13_GAMMA 0x80 /* Gamma enable */ |
| 409 | #define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */ |
| 410 | #define OV7670_REG_COM14 0x3e /* Control 14 */ |
| 411 | #define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */ |
| 412 | #define OV7670_REG_COM15 0x40 /* Control 15 */ |
| 413 | #define OV7670_COM15_R00FF 0xc0 /* 00 to FF */ |
| 414 | #define OV7670_REG_COM16 0x41 /* Control 16 */ |
| 415 | #define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */ |
| 416 | #define OV7670_REG_BRIGHT 0x55 /* Brightness */ |
| 417 | #define OV7670_REG_CONTRAS 0x56 /* Contrast control */ |
| 418 | #define OV7670_REG_GFIX 0x69 /* Fix gain control */ |
| 419 | #define OV7670_REG_RGB444 0x8c /* RGB 444 control */ |
| 420 | #define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */ |
| 421 | #define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */ |
| 422 | #define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */ |
| 423 | #define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */ |
| 424 | #define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */ |
| 425 | #define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */ |
| 426 | #define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */ |
| 427 | #define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */ |
| 428 | #define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */ |
| 429 | |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 430 | struct ov_regvals { |
| 431 | __u8 reg; |
| 432 | __u8 val; |
| 433 | }; |
| 434 | struct ov_i2c_regvals { |
| 435 | __u8 reg; |
| 436 | __u8 val; |
| 437 | }; |
| 438 | |
| 439 | static const struct ov_i2c_regvals norm_6x20[] = { |
| 440 | { 0x12, 0x80 }, /* reset */ |
| 441 | { 0x11, 0x01 }, |
| 442 | { 0x03, 0x60 }, |
| 443 | { 0x05, 0x7f }, /* For when autoadjust is off */ |
| 444 | { 0x07, 0xa8 }, |
| 445 | /* The ratio of 0x0c and 0x0d controls the white point */ |
| 446 | { 0x0c, 0x24 }, |
| 447 | { 0x0d, 0x24 }, |
| 448 | { 0x0f, 0x15 }, /* COMS */ |
| 449 | { 0x10, 0x75 }, /* AEC Exposure time */ |
| 450 | { 0x12, 0x24 }, /* Enable AGC */ |
| 451 | { 0x14, 0x04 }, |
| 452 | /* 0x16: 0x06 helps frame stability with moving objects */ |
| 453 | { 0x16, 0x06 }, |
| 454 | /* { 0x20, 0x30 }, * Aperture correction enable */ |
| 455 | { 0x26, 0xb2 }, /* BLC enable */ |
| 456 | /* 0x28: 0x05 Selects RGB format if RGB on */ |
| 457 | { 0x28, 0x05 }, |
| 458 | { 0x2a, 0x04 }, /* Disable framerate adjust */ |
| 459 | /* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */ |
| 460 | { 0x2d, 0x99 }, |
| 461 | { 0x33, 0xa0 }, /* Color Processing Parameter */ |
| 462 | { 0x34, 0xd2 }, /* Max A/D range */ |
| 463 | { 0x38, 0x8b }, |
| 464 | { 0x39, 0x40 }, |
| 465 | |
| 466 | { 0x3c, 0x39 }, /* Enable AEC mode changing */ |
| 467 | { 0x3c, 0x3c }, /* Change AEC mode */ |
| 468 | { 0x3c, 0x24 }, /* Disable AEC mode changing */ |
| 469 | |
| 470 | { 0x3d, 0x80 }, |
| 471 | /* These next two registers (0x4a, 0x4b) are undocumented. |
| 472 | * They control the color balance */ |
| 473 | { 0x4a, 0x80 }, |
| 474 | { 0x4b, 0x80 }, |
| 475 | { 0x4d, 0xd2 }, /* This reduces noise a bit */ |
| 476 | { 0x4e, 0xc1 }, |
| 477 | { 0x4f, 0x04 }, |
| 478 | /* Do 50-53 have any effect? */ |
| 479 | /* Toggle 0x12[2] off and on here? */ |
| 480 | }; |
| 481 | |
| 482 | static const struct ov_i2c_regvals norm_6x30[] = { |
| 483 | { 0x12, 0x80 }, /* Reset */ |
| 484 | { 0x00, 0x1f }, /* Gain */ |
| 485 | { 0x01, 0x99 }, /* Blue gain */ |
| 486 | { 0x02, 0x7c }, /* Red gain */ |
| 487 | { 0x03, 0xc0 }, /* Saturation */ |
| 488 | { 0x05, 0x0a }, /* Contrast */ |
| 489 | { 0x06, 0x95 }, /* Brightness */ |
| 490 | { 0x07, 0x2d }, /* Sharpness */ |
| 491 | { 0x0c, 0x20 }, |
| 492 | { 0x0d, 0x20 }, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 493 | { 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] | 494 | { 0x0f, 0x05 }, |
| 495 | { 0x10, 0x9a }, |
| 496 | { 0x11, 0x00 }, /* Pixel clock = fastest */ |
| 497 | { 0x12, 0x24 }, /* Enable AGC and AWB */ |
| 498 | { 0x13, 0x21 }, |
| 499 | { 0x14, 0x80 }, |
| 500 | { 0x15, 0x01 }, |
| 501 | { 0x16, 0x03 }, |
| 502 | { 0x17, 0x38 }, |
| 503 | { 0x18, 0xea }, |
| 504 | { 0x19, 0x04 }, |
| 505 | { 0x1a, 0x93 }, |
| 506 | { 0x1b, 0x00 }, |
| 507 | { 0x1e, 0xc4 }, |
| 508 | { 0x1f, 0x04 }, |
| 509 | { 0x20, 0x20 }, |
| 510 | { 0x21, 0x10 }, |
| 511 | { 0x22, 0x88 }, |
| 512 | { 0x23, 0xc0 }, /* Crystal circuit power level */ |
| 513 | { 0x25, 0x9a }, /* Increase AEC black ratio */ |
| 514 | { 0x26, 0xb2 }, /* BLC enable */ |
| 515 | { 0x27, 0xa2 }, |
| 516 | { 0x28, 0x00 }, |
| 517 | { 0x29, 0x00 }, |
| 518 | { 0x2a, 0x84 }, /* 60 Hz power */ |
| 519 | { 0x2b, 0xa8 }, /* 60 Hz power */ |
| 520 | { 0x2c, 0xa0 }, |
| 521 | { 0x2d, 0x95 }, /* Enable auto-brightness */ |
| 522 | { 0x2e, 0x88 }, |
| 523 | { 0x33, 0x26 }, |
| 524 | { 0x34, 0x03 }, |
| 525 | { 0x36, 0x8f }, |
| 526 | { 0x37, 0x80 }, |
| 527 | { 0x38, 0x83 }, |
| 528 | { 0x39, 0x80 }, |
| 529 | { 0x3a, 0x0f }, |
| 530 | { 0x3b, 0x3c }, |
| 531 | { 0x3c, 0x1a }, |
| 532 | { 0x3d, 0x80 }, |
| 533 | { 0x3e, 0x80 }, |
| 534 | { 0x3f, 0x0e }, |
| 535 | { 0x40, 0x00 }, /* White bal */ |
| 536 | { 0x41, 0x00 }, /* White bal */ |
| 537 | { 0x42, 0x80 }, |
| 538 | { 0x43, 0x3f }, /* White bal */ |
| 539 | { 0x44, 0x80 }, |
| 540 | { 0x45, 0x20 }, |
| 541 | { 0x46, 0x20 }, |
| 542 | { 0x47, 0x80 }, |
| 543 | { 0x48, 0x7f }, |
| 544 | { 0x49, 0x00 }, |
| 545 | { 0x4a, 0x00 }, |
| 546 | { 0x4b, 0x80 }, |
| 547 | { 0x4c, 0xd0 }, |
| 548 | { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */ |
| 549 | { 0x4e, 0x40 }, |
| 550 | { 0x4f, 0x07 }, /* UV avg., col. killer: max */ |
| 551 | { 0x50, 0xff }, |
| 552 | { 0x54, 0x23 }, /* Max AGC gain: 18dB */ |
| 553 | { 0x55, 0xff }, |
| 554 | { 0x56, 0x12 }, |
| 555 | { 0x57, 0x81 }, |
| 556 | { 0x58, 0x75 }, |
| 557 | { 0x59, 0x01 }, /* AGC dark current comp.: +1 */ |
| 558 | { 0x5a, 0x2c }, |
| 559 | { 0x5b, 0x0f }, /* AWB chrominance levels */ |
| 560 | { 0x5c, 0x10 }, |
| 561 | { 0x3d, 0x80 }, |
| 562 | { 0x27, 0xa6 }, |
| 563 | { 0x12, 0x20 }, /* Toggle AWB */ |
| 564 | { 0x12, 0x24 }, |
| 565 | }; |
| 566 | |
| 567 | /* Lawrence Glaister <lg@jfm.bc.ca> reports: |
| 568 | * |
| 569 | * Register 0x0f in the 7610 has the following effects: |
| 570 | * |
| 571 | * 0x85 (AEC method 1): Best overall, good contrast range |
| 572 | * 0x45 (AEC method 2): Very overexposed |
| 573 | * 0xa5 (spec sheet default): Ok, but the black level is |
| 574 | * shifted resulting in loss of contrast |
| 575 | * 0x05 (old driver setting): very overexposed, too much |
| 576 | * contrast |
| 577 | */ |
| 578 | static const struct ov_i2c_regvals norm_7610[] = { |
| 579 | { 0x10, 0xff }, |
| 580 | { 0x16, 0x06 }, |
| 581 | { 0x28, 0x24 }, |
| 582 | { 0x2b, 0xac }, |
| 583 | { 0x12, 0x00 }, |
| 584 | { 0x38, 0x81 }, |
| 585 | { 0x28, 0x24 }, /* 0c */ |
| 586 | { 0x0f, 0x85 }, /* lg's setting */ |
| 587 | { 0x15, 0x01 }, |
| 588 | { 0x20, 0x1c }, |
| 589 | { 0x23, 0x2a }, |
| 590 | { 0x24, 0x10 }, |
| 591 | { 0x25, 0x8a }, |
| 592 | { 0x26, 0xa2 }, |
| 593 | { 0x27, 0xc2 }, |
| 594 | { 0x2a, 0x04 }, |
| 595 | { 0x2c, 0xfe }, |
| 596 | { 0x2d, 0x93 }, |
| 597 | { 0x30, 0x71 }, |
| 598 | { 0x31, 0x60 }, |
| 599 | { 0x32, 0x26 }, |
| 600 | { 0x33, 0x20 }, |
| 601 | { 0x34, 0x48 }, |
| 602 | { 0x12, 0x24 }, |
| 603 | { 0x11, 0x01 }, |
| 604 | { 0x0c, 0x24 }, |
| 605 | { 0x0d, 0x24 }, |
| 606 | }; |
| 607 | |
| 608 | static const struct ov_i2c_regvals norm_7620[] = { |
| 609 | { 0x00, 0x00 }, /* gain */ |
| 610 | { 0x01, 0x80 }, /* blue gain */ |
| 611 | { 0x02, 0x80 }, /* red gain */ |
| 612 | { 0x03, 0xc0 }, /* OV7670_REG_VREF */ |
| 613 | { 0x06, 0x60 }, |
| 614 | { 0x07, 0x00 }, |
| 615 | { 0x0c, 0x24 }, |
| 616 | { 0x0c, 0x24 }, |
| 617 | { 0x0d, 0x24 }, |
| 618 | { 0x11, 0x01 }, |
| 619 | { 0x12, 0x24 }, |
| 620 | { 0x13, 0x01 }, |
| 621 | { 0x14, 0x84 }, |
| 622 | { 0x15, 0x01 }, |
| 623 | { 0x16, 0x03 }, |
| 624 | { 0x17, 0x2f }, |
| 625 | { 0x18, 0xcf }, |
| 626 | { 0x19, 0x06 }, |
| 627 | { 0x1a, 0xf5 }, |
| 628 | { 0x1b, 0x00 }, |
| 629 | { 0x20, 0x18 }, |
| 630 | { 0x21, 0x80 }, |
| 631 | { 0x22, 0x80 }, |
| 632 | { 0x23, 0x00 }, |
| 633 | { 0x26, 0xa2 }, |
| 634 | { 0x27, 0xea }, |
| 635 | { 0x28, 0x20 }, |
| 636 | { 0x29, 0x00 }, |
| 637 | { 0x2a, 0x10 }, |
| 638 | { 0x2b, 0x00 }, |
| 639 | { 0x2c, 0x88 }, |
| 640 | { 0x2d, 0x91 }, |
| 641 | { 0x2e, 0x80 }, |
| 642 | { 0x2f, 0x44 }, |
| 643 | { 0x60, 0x27 }, |
| 644 | { 0x61, 0x02 }, |
| 645 | { 0x62, 0x5f }, |
| 646 | { 0x63, 0xd5 }, |
| 647 | { 0x64, 0x57 }, |
| 648 | { 0x65, 0x83 }, |
| 649 | { 0x66, 0x55 }, |
| 650 | { 0x67, 0x92 }, |
| 651 | { 0x68, 0xcf }, |
| 652 | { 0x69, 0x76 }, |
| 653 | { 0x6a, 0x22 }, |
| 654 | { 0x6b, 0x00 }, |
| 655 | { 0x6c, 0x02 }, |
| 656 | { 0x6d, 0x44 }, |
| 657 | { 0x6e, 0x80 }, |
| 658 | { 0x6f, 0x1d }, |
| 659 | { 0x70, 0x8b }, |
| 660 | { 0x71, 0x00 }, |
| 661 | { 0x72, 0x14 }, |
| 662 | { 0x73, 0x54 }, |
| 663 | { 0x74, 0x00 }, |
| 664 | { 0x75, 0x8e }, |
| 665 | { 0x76, 0x00 }, |
| 666 | { 0x77, 0xff }, |
| 667 | { 0x78, 0x80 }, |
| 668 | { 0x79, 0x80 }, |
| 669 | { 0x7a, 0x80 }, |
| 670 | { 0x7b, 0xe2 }, |
| 671 | { 0x7c, 0x00 }, |
| 672 | }; |
| 673 | |
| 674 | /* 7640 and 7648. The defaults should be OK for most registers. */ |
| 675 | static const struct ov_i2c_regvals norm_7640[] = { |
| 676 | { 0x12, 0x80 }, |
| 677 | { 0x12, 0x14 }, |
| 678 | }; |
| 679 | |
| 680 | /* 7670. Defaults taken from OmniVision provided data, |
| 681 | * as provided by Jonathan Corbet of OLPC */ |
| 682 | static const struct ov_i2c_regvals norm_7670[] = { |
| 683 | { OV7670_REG_COM7, OV7670_COM7_RESET }, |
| 684 | { OV7670_REG_TSLB, 0x04 }, /* OV */ |
| 685 | { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */ |
| 686 | { OV7670_REG_CLKRC, 0x01 }, |
| 687 | /* |
| 688 | * Set the hardware window. These values from OV don't entirely |
| 689 | * make sense - hstop is less than hstart. But they work... |
| 690 | */ |
| 691 | { OV7670_REG_HSTART, 0x13 }, |
| 692 | { OV7670_REG_HSTOP, 0x01 }, |
| 693 | { OV7670_REG_HREF, 0xb6 }, |
| 694 | { OV7670_REG_VSTART, 0x02 }, |
| 695 | { OV7670_REG_VSTOP, 0x7a }, |
| 696 | { OV7670_REG_VREF, 0x0a }, |
| 697 | |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 698 | { OV7670_REG_COM3, 0x00 }, |
| 699 | { OV7670_REG_COM14, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 700 | /* Mystery scaling numbers */ |
| 701 | { 0x70, 0x3a }, |
| 702 | { 0x71, 0x35 }, |
| 703 | { 0x72, 0x11 }, |
| 704 | { 0x73, 0xf0 }, |
| 705 | { 0xa2, 0x02 }, |
| 706 | /* { OV7670_REG_COM10, 0x0 }, */ |
| 707 | |
| 708 | /* Gamma curve values */ |
| 709 | { 0x7a, 0x20 }, |
| 710 | { 0x7b, 0x10 }, |
| 711 | { 0x7c, 0x1e }, |
| 712 | { 0x7d, 0x35 }, |
| 713 | { 0x7e, 0x5a }, |
| 714 | { 0x7f, 0x69 }, |
| 715 | { 0x80, 0x76 }, |
| 716 | { 0x81, 0x80 }, |
| 717 | { 0x82, 0x88 }, |
| 718 | { 0x83, 0x8f }, |
| 719 | { 0x84, 0x96 }, |
| 720 | { 0x85, 0xa3 }, |
| 721 | { 0x86, 0xaf }, |
| 722 | { 0x87, 0xc4 }, |
| 723 | { 0x88, 0xd7 }, |
| 724 | { 0x89, 0xe8 }, |
| 725 | |
| 726 | /* AGC and AEC parameters. Note we start by disabling those features, |
| 727 | then turn them only after tweaking the values. */ |
| 728 | { OV7670_REG_COM8, OV7670_COM8_FASTAEC |
| 729 | | OV7670_COM8_AECSTEP |
| 730 | | OV7670_COM8_BFILT }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 731 | { OV7670_REG_GAIN, 0x00 }, |
| 732 | { OV7670_REG_AECH, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 733 | { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */ |
| 734 | { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */ |
| 735 | { OV7670_REG_BD50MAX, 0x05 }, |
| 736 | { OV7670_REG_BD60MAX, 0x07 }, |
| 737 | { OV7670_REG_AEW, 0x95 }, |
| 738 | { OV7670_REG_AEB, 0x33 }, |
| 739 | { OV7670_REG_VPT, 0xe3 }, |
| 740 | { OV7670_REG_HAECC1, 0x78 }, |
| 741 | { OV7670_REG_HAECC2, 0x68 }, |
| 742 | { 0xa1, 0x03 }, /* magic */ |
| 743 | { OV7670_REG_HAECC3, 0xd8 }, |
| 744 | { OV7670_REG_HAECC4, 0xd8 }, |
| 745 | { OV7670_REG_HAECC5, 0xf0 }, |
| 746 | { OV7670_REG_HAECC6, 0x90 }, |
| 747 | { OV7670_REG_HAECC7, 0x94 }, |
| 748 | { OV7670_REG_COM8, OV7670_COM8_FASTAEC |
| 749 | | OV7670_COM8_AECSTEP |
| 750 | | OV7670_COM8_BFILT |
| 751 | | OV7670_COM8_AGC |
| 752 | | OV7670_COM8_AEC }, |
| 753 | |
| 754 | /* Almost all of these are magic "reserved" values. */ |
| 755 | { OV7670_REG_COM5, 0x61 }, |
| 756 | { OV7670_REG_COM6, 0x4b }, |
| 757 | { 0x16, 0x02 }, |
| 758 | { OV7670_REG_MVFP, 0x07 }, |
| 759 | { 0x21, 0x02 }, |
| 760 | { 0x22, 0x91 }, |
| 761 | { 0x29, 0x07 }, |
| 762 | { 0x33, 0x0b }, |
| 763 | { 0x35, 0x0b }, |
| 764 | { 0x37, 0x1d }, |
| 765 | { 0x38, 0x71 }, |
| 766 | { 0x39, 0x2a }, |
| 767 | { OV7670_REG_COM12, 0x78 }, |
| 768 | { 0x4d, 0x40 }, |
| 769 | { 0x4e, 0x20 }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 770 | { OV7670_REG_GFIX, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 771 | { 0x6b, 0x4a }, |
| 772 | { 0x74, 0x10 }, |
| 773 | { 0x8d, 0x4f }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 774 | { 0x8e, 0x00 }, |
| 775 | { 0x8f, 0x00 }, |
| 776 | { 0x90, 0x00 }, |
| 777 | { 0x91, 0x00 }, |
| 778 | { 0x96, 0x00 }, |
| 779 | { 0x9a, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 780 | { 0xb0, 0x84 }, |
| 781 | { 0xb1, 0x0c }, |
| 782 | { 0xb2, 0x0e }, |
| 783 | { 0xb3, 0x82 }, |
| 784 | { 0xb8, 0x0a }, |
| 785 | |
| 786 | /* More reserved magic, some of which tweaks white balance */ |
| 787 | { 0x43, 0x0a }, |
| 788 | { 0x44, 0xf0 }, |
| 789 | { 0x45, 0x34 }, |
| 790 | { 0x46, 0x58 }, |
| 791 | { 0x47, 0x28 }, |
| 792 | { 0x48, 0x3a }, |
| 793 | { 0x59, 0x88 }, |
| 794 | { 0x5a, 0x88 }, |
| 795 | { 0x5b, 0x44 }, |
| 796 | { 0x5c, 0x67 }, |
| 797 | { 0x5d, 0x49 }, |
| 798 | { 0x5e, 0x0e }, |
| 799 | { 0x6c, 0x0a }, |
| 800 | { 0x6d, 0x55 }, |
| 801 | { 0x6e, 0x11 }, |
| 802 | { 0x6f, 0x9f }, |
| 803 | /* "9e for advance AWB" */ |
| 804 | { 0x6a, 0x40 }, |
| 805 | { OV7670_REG_BLUE, 0x40 }, |
| 806 | { OV7670_REG_RED, 0x60 }, |
| 807 | { OV7670_REG_COM8, OV7670_COM8_FASTAEC |
| 808 | | OV7670_COM8_AECSTEP |
| 809 | | OV7670_COM8_BFILT |
| 810 | | OV7670_COM8_AGC |
| 811 | | OV7670_COM8_AEC |
| 812 | | OV7670_COM8_AWB }, |
| 813 | |
| 814 | /* Matrix coefficients */ |
| 815 | { 0x4f, 0x80 }, |
| 816 | { 0x50, 0x80 }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 817 | { 0x51, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 818 | { 0x52, 0x22 }, |
| 819 | { 0x53, 0x5e }, |
| 820 | { 0x54, 0x80 }, |
| 821 | { 0x58, 0x9e }, |
| 822 | |
| 823 | { OV7670_REG_COM16, OV7670_COM16_AWBGAIN }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 824 | { OV7670_REG_EDGE, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 825 | { 0x75, 0x05 }, |
| 826 | { 0x76, 0xe1 }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 827 | { 0x4c, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 828 | { 0x77, 0x01 }, |
| 829 | { OV7670_REG_COM13, OV7670_COM13_GAMMA |
| 830 | | OV7670_COM13_UVSAT |
| 831 | | 2}, /* was 3 */ |
| 832 | { 0x4b, 0x09 }, |
| 833 | { 0xc9, 0x60 }, |
| 834 | { OV7670_REG_COM16, 0x38 }, |
| 835 | { 0x56, 0x40 }, |
| 836 | |
| 837 | { 0x34, 0x11 }, |
| 838 | { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO }, |
| 839 | { 0xa4, 0x88 }, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 840 | { 0x96, 0x00 }, |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 841 | { 0x97, 0x30 }, |
| 842 | { 0x98, 0x20 }, |
| 843 | { 0x99, 0x30 }, |
| 844 | { 0x9a, 0x84 }, |
| 845 | { 0x9b, 0x29 }, |
| 846 | { 0x9c, 0x03 }, |
| 847 | { 0x9d, 0x4c }, |
| 848 | { 0x9e, 0x3f }, |
| 849 | { 0x78, 0x04 }, |
| 850 | |
| 851 | /* Extra-weird stuff. Some sort of multiplexor register */ |
| 852 | { 0x79, 0x01 }, |
| 853 | { 0xc8, 0xf0 }, |
| 854 | { 0x79, 0x0f }, |
| 855 | { 0xc8, 0x00 }, |
| 856 | { 0x79, 0x10 }, |
| 857 | { 0xc8, 0x7e }, |
| 858 | { 0x79, 0x0a }, |
| 859 | { 0xc8, 0x80 }, |
| 860 | { 0x79, 0x0b }, |
| 861 | { 0xc8, 0x01 }, |
| 862 | { 0x79, 0x0c }, |
| 863 | { 0xc8, 0x0f }, |
| 864 | { 0x79, 0x0d }, |
| 865 | { 0xc8, 0x20 }, |
| 866 | { 0x79, 0x09 }, |
| 867 | { 0xc8, 0x80 }, |
| 868 | { 0x79, 0x02 }, |
| 869 | { 0xc8, 0xc0 }, |
| 870 | { 0x79, 0x03 }, |
| 871 | { 0xc8, 0x40 }, |
| 872 | { 0x79, 0x05 }, |
| 873 | { 0xc8, 0x30 }, |
| 874 | { 0x79, 0x26 }, |
| 875 | }; |
| 876 | |
| 877 | static const struct ov_i2c_regvals norm_8610[] = { |
| 878 | { 0x12, 0x80 }, |
| 879 | { 0x00, 0x00 }, |
| 880 | { 0x01, 0x80 }, |
| 881 | { 0x02, 0x80 }, |
| 882 | { 0x03, 0xc0 }, |
| 883 | { 0x04, 0x30 }, |
| 884 | { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */ |
| 885 | { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */ |
| 886 | { 0x0a, 0x86 }, |
| 887 | { 0x0b, 0xb0 }, |
| 888 | { 0x0c, 0x20 }, |
| 889 | { 0x0d, 0x20 }, |
| 890 | { 0x11, 0x01 }, |
| 891 | { 0x12, 0x25 }, |
| 892 | { 0x13, 0x01 }, |
| 893 | { 0x14, 0x04 }, |
| 894 | { 0x15, 0x01 }, /* Lin and Win think different about UV order */ |
| 895 | { 0x16, 0x03 }, |
| 896 | { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */ |
| 897 | { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */ |
| 898 | { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */ |
| 899 | { 0x1a, 0xf5 }, |
| 900 | { 0x1b, 0x00 }, |
| 901 | { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */ |
| 902 | { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */ |
| 903 | { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */ |
| 904 | { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */ |
| 905 | { 0x26, 0xa2 }, |
| 906 | { 0x27, 0xea }, |
| 907 | { 0x28, 0x00 }, |
| 908 | { 0x29, 0x00 }, |
| 909 | { 0x2a, 0x80 }, |
| 910 | { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */ |
| 911 | { 0x2c, 0xac }, |
| 912 | { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */ |
| 913 | { 0x2e, 0x80 }, |
| 914 | { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */ |
| 915 | { 0x4c, 0x00 }, |
| 916 | { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */ |
| 917 | { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */ |
| 918 | { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */ |
| 919 | { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */ |
| 920 | { 0x63, 0xff }, |
| 921 | { 0x64, 0x53 }, /* new windrv 090403 says 0x57, |
| 922 | * maybe thats wrong */ |
| 923 | { 0x65, 0x00 }, |
| 924 | { 0x66, 0x55 }, |
| 925 | { 0x67, 0xb0 }, |
| 926 | { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */ |
| 927 | { 0x69, 0x02 }, |
| 928 | { 0x6a, 0x22 }, |
| 929 | { 0x6b, 0x00 }, |
| 930 | { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but |
| 931 | * deleting bit7 colors the first images red */ |
| 932 | { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */ |
| 933 | { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */ |
| 934 | { 0x6f, 0x01 }, |
| 935 | { 0x70, 0x8b }, |
| 936 | { 0x71, 0x00 }, |
| 937 | { 0x72, 0x14 }, |
| 938 | { 0x73, 0x54 }, |
| 939 | { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */ |
| 940 | { 0x75, 0x0e }, |
| 941 | { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */ |
| 942 | { 0x77, 0xff }, |
| 943 | { 0x78, 0x80 }, |
| 944 | { 0x79, 0x80 }, |
| 945 | { 0x7a, 0x80 }, |
| 946 | { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */ |
| 947 | { 0x7c, 0x00 }, |
| 948 | { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */ |
| 949 | { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */ |
| 950 | { 0x7f, 0xfb }, |
| 951 | { 0x80, 0x28 }, |
| 952 | { 0x81, 0x00 }, |
| 953 | { 0x82, 0x23 }, |
| 954 | { 0x83, 0x0b }, |
| 955 | { 0x84, 0x00 }, |
| 956 | { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */ |
| 957 | { 0x86, 0xc9 }, |
| 958 | { 0x87, 0x00 }, |
| 959 | { 0x88, 0x00 }, |
| 960 | { 0x89, 0x01 }, |
| 961 | { 0x12, 0x20 }, |
| 962 | { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */ |
| 963 | }; |
| 964 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 965 | static unsigned char ov7670_abs_to_sm(unsigned char v) |
| 966 | { |
| 967 | if (v > 127) |
| 968 | return v & 0x7f; |
| 969 | return (128 - v) | 0x80; |
| 970 | } |
| 971 | |
| 972 | /* Write a OV519 register */ |
| 973 | static int reg_w(struct sd *sd, __u16 index, __u8 value) |
| 974 | { |
| 975 | int ret; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 976 | int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 2 : 1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 977 | |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 978 | sd->gspca_dev.usb_buf[0] = value; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 979 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 980 | usb_sndctrlpipe(sd->gspca_dev.dev, 0), |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 981 | req, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 982 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 983 | 0, index, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 984 | sd->gspca_dev.usb_buf, 1, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 985 | if (ret < 0) |
| 986 | PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value); |
| 987 | return ret; |
| 988 | } |
| 989 | |
| 990 | /* Read from a OV519 register */ |
| 991 | /* returns: negative is error, pos or zero is data */ |
| 992 | static int reg_r(struct sd *sd, __u16 index) |
| 993 | { |
| 994 | int ret; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 995 | int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 3 : 1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 996 | |
| 997 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 998 | usb_rcvctrlpipe(sd->gspca_dev.dev, 0), |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 999 | req, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1000 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 1001 | 0, index, sd->gspca_dev.usb_buf, 1, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1002 | |
| 1003 | if (ret >= 0) |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 1004 | ret = sd->gspca_dev.usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1005 | else |
| 1006 | PDEBUG(D_ERR, "Read reg [0x%02x] failed", index); |
| 1007 | return ret; |
| 1008 | } |
| 1009 | |
| 1010 | /* Read 8 values from a OV519 register */ |
| 1011 | static int reg_r8(struct sd *sd, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1012 | __u16 index) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1013 | { |
| 1014 | int ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1015 | |
| 1016 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 1017 | usb_rcvctrlpipe(sd->gspca_dev.dev, 0), |
| 1018 | 1, /* REQ_IO */ |
| 1019 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 1020 | 0, index, sd->gspca_dev.usb_buf, 8, 500); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1021 | |
| 1022 | if (ret >= 0) |
Jean-Francois Moine | 739570b | 2008-07-14 09:38:29 -0300 | [diff] [blame] | 1023 | ret = sd->gspca_dev.usb_buf[0]; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1024 | else |
| 1025 | PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index); |
| 1026 | return ret; |
| 1027 | } |
| 1028 | |
| 1029 | /* |
| 1030 | * Writes bits at positions specified by mask to an OV51x reg. Bits that are in |
| 1031 | * the same position as 1's in "mask" are cleared and set to "value". Bits |
| 1032 | * that are in the same position as 0's in "mask" are preserved, regardless |
| 1033 | * of their respective state in "value". |
| 1034 | */ |
| 1035 | static int reg_w_mask(struct sd *sd, |
| 1036 | __u16 index, |
| 1037 | __u8 value, |
| 1038 | __u8 mask) |
| 1039 | { |
| 1040 | int ret; |
| 1041 | __u8 oldval; |
| 1042 | |
| 1043 | if (mask != 0xff) { |
| 1044 | value &= mask; /* Enforce mask on value */ |
| 1045 | ret = reg_r(sd, index); |
| 1046 | if (ret < 0) |
| 1047 | return ret; |
| 1048 | |
| 1049 | oldval = ret & ~mask; /* Clear the masked bits */ |
| 1050 | value |= oldval; /* Set the desired bits */ |
| 1051 | } |
| 1052 | return reg_w(sd, index, value); |
| 1053 | } |
| 1054 | |
| 1055 | /* |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1056 | * Writes multiple (n) byte value to a single register. Only valid with certain |
| 1057 | * registers (0x30 and 0xc4 - 0xce). |
| 1058 | */ |
| 1059 | static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n) |
| 1060 | { |
| 1061 | int ret; |
| 1062 | |
| 1063 | *((u32 *)sd->gspca_dev.usb_buf) = __cpu_to_le32(value); |
| 1064 | |
| 1065 | ret = usb_control_msg(sd->gspca_dev.dev, |
| 1066 | usb_sndctrlpipe(sd->gspca_dev.dev, 0), |
| 1067 | 1 /* REG_IO */, |
| 1068 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 1069 | 0, index, |
| 1070 | sd->gspca_dev.usb_buf, n, 500); |
| 1071 | if (ret < 0) |
| 1072 | PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value); |
| 1073 | return ret; |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | /* |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1078 | * The OV518 I2C I/O procedure is different, hence, this function. |
| 1079 | * This is normally only called from i2c_w(). Note that this function |
| 1080 | * always succeeds regardless of whether the sensor is present and working. |
| 1081 | */ |
| 1082 | static int i2c_w(struct sd *sd, |
| 1083 | __u8 reg, |
| 1084 | __u8 value) |
| 1085 | { |
| 1086 | int rc; |
| 1087 | |
| 1088 | PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg); |
| 1089 | |
| 1090 | /* Select camera register */ |
| 1091 | rc = reg_w(sd, R51x_I2C_SADDR_3, reg); |
| 1092 | if (rc < 0) |
| 1093 | return rc; |
| 1094 | |
| 1095 | /* Write "value" to I2C data port of OV511 */ |
| 1096 | rc = reg_w(sd, R51x_I2C_DATA, value); |
| 1097 | if (rc < 0) |
| 1098 | return rc; |
| 1099 | |
| 1100 | /* Initiate 3-byte write cycle */ |
| 1101 | rc = reg_w(sd, R518_I2C_CTL, 0x01); |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1102 | if (rc < 0) |
| 1103 | return rc; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1104 | |
| 1105 | /* wait for write complete */ |
| 1106 | msleep(4); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1107 | return reg_r8(sd, R518_I2C_CTL); |
| 1108 | } |
| 1109 | |
| 1110 | /* |
| 1111 | * returns: negative is error, pos or zero is data |
| 1112 | * |
| 1113 | * The OV518 I2C I/O procedure is different, hence, this function. |
| 1114 | * This is normally only called from i2c_r(). Note that this function |
| 1115 | * always succeeds regardless of whether the sensor is present and working. |
| 1116 | */ |
| 1117 | static int i2c_r(struct sd *sd, __u8 reg) |
| 1118 | { |
| 1119 | int rc, value; |
| 1120 | |
| 1121 | /* Select camera register */ |
| 1122 | rc = reg_w(sd, R51x_I2C_SADDR_2, reg); |
| 1123 | if (rc < 0) |
| 1124 | return rc; |
| 1125 | |
| 1126 | /* Initiate 2-byte write cycle */ |
| 1127 | rc = reg_w(sd, R518_I2C_CTL, 0x03); |
| 1128 | if (rc < 0) |
| 1129 | return rc; |
| 1130 | |
| 1131 | /* Initiate 2-byte read cycle */ |
| 1132 | rc = reg_w(sd, R518_I2C_CTL, 0x05); |
| 1133 | if (rc < 0) |
| 1134 | return rc; |
| 1135 | value = reg_r(sd, R51x_I2C_DATA); |
| 1136 | PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value); |
| 1137 | return value; |
| 1138 | } |
| 1139 | |
| 1140 | /* Writes bits at positions specified by mask to an I2C reg. Bits that are in |
| 1141 | * the same position as 1's in "mask" are cleared and set to "value". Bits |
| 1142 | * that are in the same position as 0's in "mask" are preserved, regardless |
| 1143 | * of their respective state in "value". |
| 1144 | */ |
| 1145 | static int i2c_w_mask(struct sd *sd, |
| 1146 | __u8 reg, |
| 1147 | __u8 value, |
| 1148 | __u8 mask) |
| 1149 | { |
| 1150 | int rc; |
| 1151 | __u8 oldval; |
| 1152 | |
| 1153 | value &= mask; /* Enforce mask on value */ |
| 1154 | rc = i2c_r(sd, reg); |
| 1155 | if (rc < 0) |
| 1156 | return rc; |
| 1157 | oldval = rc & ~mask; /* Clear the masked bits */ |
| 1158 | value |= oldval; /* Set the desired bits */ |
| 1159 | return i2c_w(sd, reg, value); |
| 1160 | } |
| 1161 | |
| 1162 | /* Temporarily stops OV511 from functioning. Must do this before changing |
| 1163 | * registers while the camera is streaming */ |
| 1164 | static inline int ov51x_stop(struct sd *sd) |
| 1165 | { |
| 1166 | PDEBUG(D_STREAM, "stopping"); |
| 1167 | sd->stopped = 1; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1168 | switch (sd->bridge) { |
| 1169 | case BRIDGE_OV511: |
| 1170 | case BRIDGE_OV511PLUS: |
| 1171 | return reg_w(sd, R51x_SYS_RESET, 0x3d); |
| 1172 | case BRIDGE_OV518: |
| 1173 | case BRIDGE_OV518PLUS: |
| 1174 | return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a); |
| 1175 | case BRIDGE_OV519: |
| 1176 | return reg_w(sd, OV519_SYS_RESET1, 0x0f); |
| 1177 | } |
| 1178 | |
| 1179 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | /* Restarts OV511 after ov511_stop() is called. Has no effect if it is not |
| 1183 | * actually stopped (for performance). */ |
| 1184 | static inline int ov51x_restart(struct sd *sd) |
| 1185 | { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1186 | int rc; |
| 1187 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1188 | PDEBUG(D_STREAM, "restarting"); |
| 1189 | if (!sd->stopped) |
| 1190 | return 0; |
| 1191 | sd->stopped = 0; |
| 1192 | |
| 1193 | /* Reinitialize the stream */ |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1194 | switch (sd->bridge) { |
| 1195 | case BRIDGE_OV511: |
| 1196 | case BRIDGE_OV511PLUS: |
| 1197 | return reg_w(sd, R51x_SYS_RESET, 0x00); |
| 1198 | case BRIDGE_OV518: |
| 1199 | case BRIDGE_OV518PLUS: |
| 1200 | rc = reg_w(sd, 0x2f, 0x80); |
| 1201 | if (rc < 0) |
| 1202 | return rc; |
| 1203 | return reg_w(sd, R51x_SYS_RESET, 0x00); |
| 1204 | case BRIDGE_OV519: |
| 1205 | return reg_w(sd, OV519_SYS_RESET1, 0x00); |
| 1206 | } |
| 1207 | |
| 1208 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | /* This does an initial reset of an OmniVision sensor and ensures that I2C |
| 1212 | * is synchronized. Returns <0 on failure. |
| 1213 | */ |
| 1214 | static int init_ov_sensor(struct sd *sd) |
| 1215 | { |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1216 | int i; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1217 | |
| 1218 | /* Reset the sensor */ |
| 1219 | if (i2c_w(sd, 0x12, 0x80) < 0) |
| 1220 | return -EIO; |
| 1221 | |
| 1222 | /* Wait for it to initialize */ |
| 1223 | msleep(150); |
| 1224 | |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1225 | for (i = 0; i < i2c_detect_tries; i++) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1226 | if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f && |
| 1227 | i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) { |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1228 | PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i); |
| 1229 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | /* Reset the sensor */ |
| 1233 | if (i2c_w(sd, 0x12, 0x80) < 0) |
| 1234 | return -EIO; |
| 1235 | /* Wait for it to initialize */ |
| 1236 | msleep(150); |
| 1237 | /* Dummy read to sync I2C */ |
| 1238 | if (i2c_r(sd, 0x00) < 0) |
| 1239 | return -EIO; |
| 1240 | } |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1241 | return -EIO; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1242 | } |
| 1243 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1244 | /* Set the read and write slave IDs. The "slave" argument is the write slave, |
| 1245 | * and the read slave will be set to (slave + 1). |
| 1246 | * This should not be called from outside the i2c I/O functions. |
| 1247 | * Sets I2C read and write slave IDs. Returns <0 for error |
| 1248 | */ |
| 1249 | static int ov51x_set_slave_ids(struct sd *sd, |
| 1250 | __u8 slave) |
| 1251 | { |
| 1252 | int rc; |
| 1253 | |
| 1254 | rc = reg_w(sd, R51x_I2C_W_SID, slave); |
| 1255 | if (rc < 0) |
| 1256 | return rc; |
| 1257 | return reg_w(sd, R51x_I2C_R_SID, slave + 1); |
| 1258 | } |
| 1259 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1260 | static int write_regvals(struct sd *sd, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1261 | const struct ov_regvals *regvals, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1262 | int n) |
| 1263 | { |
| 1264 | int rc; |
| 1265 | |
| 1266 | while (--n >= 0) { |
| 1267 | rc = reg_w(sd, regvals->reg, regvals->val); |
| 1268 | if (rc < 0) |
| 1269 | return rc; |
| 1270 | regvals++; |
| 1271 | } |
| 1272 | return 0; |
| 1273 | } |
| 1274 | |
| 1275 | static int write_i2c_regvals(struct sd *sd, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1276 | const struct ov_i2c_regvals *regvals, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1277 | int n) |
| 1278 | { |
| 1279 | int rc; |
| 1280 | |
| 1281 | while (--n >= 0) { |
| 1282 | rc = i2c_w(sd, regvals->reg, regvals->val); |
| 1283 | if (rc < 0) |
| 1284 | return rc; |
| 1285 | regvals++; |
| 1286 | } |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | /**************************************************************************** |
| 1291 | * |
| 1292 | * OV511 and sensor configuration |
| 1293 | * |
| 1294 | ***************************************************************************/ |
| 1295 | |
| 1296 | /* This initializes the OV8110, OV8610 sensor. The OV8110 uses |
| 1297 | * the same register settings as the OV8610, since they are very similar. |
| 1298 | */ |
| 1299 | static int ov8xx0_configure(struct sd *sd) |
| 1300 | { |
| 1301 | int rc; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1302 | |
| 1303 | PDEBUG(D_PROBE, "starting ov8xx0 configuration"); |
| 1304 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1305 | /* Detect sensor (sub)type */ |
| 1306 | rc = i2c_r(sd, OV7610_REG_COM_I); |
| 1307 | if (rc < 0) { |
| 1308 | PDEBUG(D_ERR, "Error detecting sensor type"); |
| 1309 | return -1; |
| 1310 | } |
| 1311 | if ((rc & 3) == 1) { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1312 | sd->sensor = SEN_OV8610; |
| 1313 | } else { |
| 1314 | PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3); |
| 1315 | return -1; |
| 1316 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1317 | |
| 1318 | /* Set sensor-specific vars */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1319 | /* sd->sif = 0; already done */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
| 1322 | |
| 1323 | /* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses |
| 1324 | * the same register settings as the OV7610, since they are very similar. |
| 1325 | */ |
| 1326 | static int ov7xx0_configure(struct sd *sd) |
| 1327 | { |
| 1328 | int rc, high, low; |
| 1329 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1330 | |
| 1331 | PDEBUG(D_PROBE, "starting OV7xx0 configuration"); |
| 1332 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1333 | /* Detect sensor (sub)type */ |
| 1334 | rc = i2c_r(sd, OV7610_REG_COM_I); |
| 1335 | |
| 1336 | /* add OV7670 here |
| 1337 | * it appears to be wrongly detected as a 7610 by default */ |
| 1338 | if (rc < 0) { |
| 1339 | PDEBUG(D_ERR, "Error detecting sensor type"); |
| 1340 | return -1; |
| 1341 | } |
| 1342 | if ((rc & 3) == 3) { |
| 1343 | /* quick hack to make OV7670s work */ |
| 1344 | high = i2c_r(sd, 0x0a); |
| 1345 | low = i2c_r(sd, 0x0b); |
| 1346 | /* info("%x, %x", high, low); */ |
| 1347 | if (high == 0x76 && low == 0x73) { |
| 1348 | PDEBUG(D_PROBE, "Sensor is an OV7670"); |
| 1349 | sd->sensor = SEN_OV7670; |
| 1350 | } else { |
| 1351 | PDEBUG(D_PROBE, "Sensor is an OV7610"); |
| 1352 | sd->sensor = SEN_OV7610; |
| 1353 | } |
| 1354 | } else if ((rc & 3) == 1) { |
| 1355 | /* I don't know what's different about the 76BE yet. */ |
| 1356 | if (i2c_r(sd, 0x15) & 1) |
| 1357 | PDEBUG(D_PROBE, "Sensor is an OV7620AE"); |
| 1358 | else |
| 1359 | PDEBUG(D_PROBE, "Sensor is an OV76BE"); |
| 1360 | |
| 1361 | /* OV511+ will return all zero isoc data unless we |
| 1362 | * configure the sensor as a 7620. Someone needs to |
| 1363 | * find the exact reg. setting that causes this. */ |
| 1364 | sd->sensor = SEN_OV76BE; |
| 1365 | } else if ((rc & 3) == 0) { |
| 1366 | /* try to read product id registers */ |
| 1367 | high = i2c_r(sd, 0x0a); |
| 1368 | if (high < 0) { |
| 1369 | PDEBUG(D_ERR, "Error detecting camera chip PID"); |
| 1370 | return high; |
| 1371 | } |
| 1372 | low = i2c_r(sd, 0x0b); |
| 1373 | if (low < 0) { |
| 1374 | PDEBUG(D_ERR, "Error detecting camera chip VER"); |
| 1375 | return low; |
| 1376 | } |
| 1377 | if (high == 0x76) { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1378 | switch (low) { |
| 1379 | case 0x30: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1380 | PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635"); |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1381 | PDEBUG(D_ERR, |
| 1382 | "7630 is not supported by this driver"); |
| 1383 | return -1; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1384 | case 0x40: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1385 | PDEBUG(D_PROBE, "Sensor is an OV7645"); |
| 1386 | sd->sensor = SEN_OV7640; /* FIXME */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1387 | break; |
| 1388 | case 0x45: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1389 | PDEBUG(D_PROBE, "Sensor is an OV7645B"); |
| 1390 | sd->sensor = SEN_OV7640; /* FIXME */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1391 | break; |
| 1392 | case 0x48: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1393 | PDEBUG(D_PROBE, "Sensor is an OV7648"); |
| 1394 | sd->sensor = SEN_OV7640; /* FIXME */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1395 | break; |
| 1396 | default: |
| 1397 | PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1398 | return -1; |
| 1399 | } |
| 1400 | } else { |
| 1401 | PDEBUG(D_PROBE, "Sensor is an OV7620"); |
| 1402 | sd->sensor = SEN_OV7620; |
| 1403 | } |
| 1404 | } else { |
| 1405 | PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3); |
| 1406 | return -1; |
| 1407 | } |
| 1408 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1409 | /* Set sensor-specific vars */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1410 | /* sd->sif = 0; already done */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1411 | return 0; |
| 1412 | } |
| 1413 | |
| 1414 | /* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */ |
| 1415 | static int ov6xx0_configure(struct sd *sd) |
| 1416 | { |
| 1417 | int rc; |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1418 | PDEBUG(D_PROBE, "starting OV6xx0 configuration"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1419 | |
| 1420 | /* Detect sensor (sub)type */ |
| 1421 | rc = i2c_r(sd, OV7610_REG_COM_I); |
| 1422 | if (rc < 0) { |
| 1423 | PDEBUG(D_ERR, "Error detecting sensor type"); |
| 1424 | return -1; |
| 1425 | } |
| 1426 | |
| 1427 | /* Ugh. The first two bits are the version bits, but |
| 1428 | * the entire register value must be used. I guess OVT |
| 1429 | * underestimated how many variants they would make. */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1430 | switch (rc) { |
| 1431 | case 0x00: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1432 | sd->sensor = SEN_OV6630; |
| 1433 | PDEBUG(D_ERR, |
| 1434 | "WARNING: Sensor is an OV66308. Your camera may have"); |
| 1435 | PDEBUG(D_ERR, "been misdetected in previous driver versions."); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1436 | break; |
| 1437 | case 0x01: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1438 | sd->sensor = SEN_OV6620; |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 1439 | PDEBUG(D_PROBE, "Sensor is an OV6620"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1440 | break; |
| 1441 | case 0x02: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1442 | sd->sensor = SEN_OV6630; |
| 1443 | PDEBUG(D_PROBE, "Sensor is an OV66308AE"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1444 | break; |
| 1445 | case 0x03: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 1446 | sd->sensor = SEN_OV66308AF; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1447 | PDEBUG(D_PROBE, "Sensor is an OV66308AF"); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1448 | break; |
| 1449 | case 0x90: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1450 | sd->sensor = SEN_OV6630; |
| 1451 | PDEBUG(D_ERR, |
| 1452 | "WARNING: Sensor is an OV66307. Your camera may have"); |
| 1453 | PDEBUG(D_ERR, "been misdetected in previous driver versions."); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1454 | break; |
| 1455 | default: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1456 | PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc); |
| 1457 | return -1; |
| 1458 | } |
| 1459 | |
| 1460 | /* Set sensor-specific vars */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1461 | sd->sif = 1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1462 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1463 | return 0; |
| 1464 | } |
| 1465 | |
| 1466 | /* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */ |
| 1467 | static void ov51x_led_control(struct sd *sd, int on) |
| 1468 | { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1469 | switch (sd->bridge) { |
| 1470 | /* OV511 has no LED control */ |
| 1471 | case BRIDGE_OV511PLUS: |
| 1472 | reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0); |
| 1473 | break; |
| 1474 | case BRIDGE_OV518: |
| 1475 | case BRIDGE_OV518PLUS: |
| 1476 | reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02); |
| 1477 | break; |
| 1478 | case BRIDGE_OV519: |
| 1479 | reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */ |
| 1480 | break; |
| 1481 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1482 | } |
| 1483 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1484 | /* OV518 quantization tables are 8x4 (instead of 8x8) */ |
| 1485 | static int ov518_upload_quan_tables(struct sd *sd) |
| 1486 | { |
| 1487 | const unsigned char yQuanTable518[] = { |
| 1488 | 5, 4, 5, 6, 6, 7, 7, 7, |
| 1489 | 5, 5, 5, 5, 6, 7, 7, 7, |
| 1490 | 6, 6, 6, 6, 7, 7, 7, 8, |
| 1491 | 7, 7, 6, 7, 7, 7, 8, 8 |
| 1492 | }; |
| 1493 | |
| 1494 | const unsigned char uvQuanTable518[] = { |
| 1495 | 6, 6, 6, 7, 7, 7, 7, 7, |
| 1496 | 6, 6, 6, 7, 7, 7, 7, 7, |
| 1497 | 6, 6, 6, 7, 7, 7, 7, 8, |
| 1498 | 7, 7, 7, 7, 7, 7, 8, 8 |
| 1499 | }; |
| 1500 | |
| 1501 | const unsigned char *pYTable = yQuanTable518; |
| 1502 | const unsigned char *pUVTable = uvQuanTable518; |
| 1503 | unsigned char val0, val1; |
| 1504 | int i, rc, reg = R51x_COMP_LUT_BEGIN; |
| 1505 | |
| 1506 | PDEBUG(D_PROBE, "Uploading quantization tables"); |
| 1507 | |
| 1508 | for (i = 0; i < 16; i++) { |
| 1509 | val0 = *pYTable++; |
| 1510 | val1 = *pYTable++; |
| 1511 | val0 &= 0x0f; |
| 1512 | val1 &= 0x0f; |
| 1513 | val0 |= val1 << 4; |
| 1514 | rc = reg_w(sd, reg, val0); |
| 1515 | if (rc < 0) |
| 1516 | return rc; |
| 1517 | |
| 1518 | val0 = *pUVTable++; |
| 1519 | val1 = *pUVTable++; |
| 1520 | val0 &= 0x0f; |
| 1521 | val1 &= 0x0f; |
| 1522 | val0 |= val1 << 4; |
| 1523 | rc = reg_w(sd, reg + 16, val0); |
| 1524 | if (rc < 0) |
| 1525 | return rc; |
| 1526 | |
| 1527 | reg++; |
| 1528 | } |
| 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | /* This initializes the OV518/OV518+ and the sensor */ |
| 1534 | static int ov518_configure(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1535 | { |
| 1536 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1537 | int rc; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1538 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1539 | /* For 518 and 518+ */ |
| 1540 | static struct ov_regvals init_518[] = { |
| 1541 | { R51x_SYS_RESET, 0x40 }, |
| 1542 | { R51x_SYS_INIT, 0xe1 }, |
| 1543 | { R51x_SYS_RESET, 0x3e }, |
| 1544 | { R51x_SYS_INIT, 0xe1 }, |
| 1545 | { R51x_SYS_RESET, 0x00 }, |
| 1546 | { R51x_SYS_INIT, 0xe1 }, |
| 1547 | { 0x46, 0x00 }, |
| 1548 | { 0x5d, 0x03 }, |
| 1549 | }; |
| 1550 | |
| 1551 | static struct ov_regvals norm_518[] = { |
| 1552 | { R51x_SYS_SNAP, 0x02 }, /* Reset */ |
| 1553 | { R51x_SYS_SNAP, 0x01 }, /* Enable */ |
| 1554 | { 0x31, 0x0f }, |
| 1555 | { 0x5d, 0x03 }, |
| 1556 | { 0x24, 0x9f }, |
| 1557 | { 0x25, 0x90 }, |
| 1558 | { 0x20, 0x00 }, |
| 1559 | { 0x51, 0x04 }, |
| 1560 | { 0x71, 0x19 }, |
| 1561 | { 0x2f, 0x80 }, |
| 1562 | }; |
| 1563 | |
| 1564 | static struct ov_regvals norm_518_p[] = { |
| 1565 | { R51x_SYS_SNAP, 0x02 }, /* Reset */ |
| 1566 | { R51x_SYS_SNAP, 0x01 }, /* Enable */ |
| 1567 | { 0x31, 0x0f }, |
| 1568 | { 0x5d, 0x03 }, |
| 1569 | { 0x24, 0x9f }, |
| 1570 | { 0x25, 0x90 }, |
| 1571 | { 0x20, 0x60 }, |
| 1572 | { 0x51, 0x02 }, |
| 1573 | { 0x71, 0x19 }, |
| 1574 | { 0x40, 0xff }, |
| 1575 | { 0x41, 0x42 }, |
| 1576 | { 0x46, 0x00 }, |
| 1577 | { 0x33, 0x04 }, |
| 1578 | { 0x21, 0x19 }, |
| 1579 | { 0x3f, 0x10 }, |
| 1580 | { 0x2f, 0x80 }, |
| 1581 | }; |
| 1582 | |
| 1583 | /* First 5 bits of custom ID reg are a revision ID on OV518 */ |
| 1584 | PDEBUG(D_PROBE, "Device revision %d", |
| 1585 | 0x1F & reg_r(sd, R51x_SYS_CUST_ID)); |
| 1586 | |
| 1587 | rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518)); |
| 1588 | if (rc < 0) |
| 1589 | return rc; |
| 1590 | |
| 1591 | /* Set LED GPIO pin to output mode */ |
| 1592 | rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02); |
| 1593 | if (rc < 0) |
| 1594 | return rc; |
| 1595 | |
| 1596 | switch (sd->bridge) { |
| 1597 | case BRIDGE_OV518: |
| 1598 | rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518)); |
| 1599 | if (rc < 0) |
| 1600 | return rc; |
| 1601 | break; |
| 1602 | case BRIDGE_OV518PLUS: |
| 1603 | rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p)); |
| 1604 | if (rc < 0) |
| 1605 | return rc; |
| 1606 | break; |
| 1607 | } |
| 1608 | |
| 1609 | rc = ov518_upload_quan_tables(sd); |
| 1610 | if (rc < 0) { |
| 1611 | PDEBUG(D_ERR, "Error uploading quantization tables"); |
| 1612 | return rc; |
| 1613 | } |
| 1614 | |
| 1615 | rc = reg_w(sd, 0x2f, 0x80); |
| 1616 | if (rc < 0) |
| 1617 | return rc; |
| 1618 | |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
| 1622 | static int ov519_configure(struct sd *sd) |
| 1623 | { |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1624 | static const struct ov_regvals init_519[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1625 | { 0x5a, 0x6d }, /* EnableSystem */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1626 | { 0x53, 0x9b }, |
| 1627 | { 0x54, 0xff }, /* set bit2 to enable jpeg */ |
| 1628 | { 0x5d, 0x03 }, |
| 1629 | { 0x49, 0x01 }, |
| 1630 | { 0x48, 0x00 }, |
| 1631 | /* Set LED pin to output mode. Bit 4 must be cleared or sensor |
| 1632 | * detection will fail. This deserves further investigation. */ |
| 1633 | { OV519_GPIO_IO_CTRL0, 0xee }, |
| 1634 | { 0x51, 0x0f }, /* SetUsbInit */ |
| 1635 | { 0x51, 0x00 }, |
| 1636 | { 0x22, 0x00 }, |
| 1637 | /* windows reads 0x55 at this point*/ |
| 1638 | }; |
| 1639 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1640 | return write_regvals(sd, init_519, ARRAY_SIZE(init_519)); |
| 1641 | } |
| 1642 | |
| 1643 | /* this function is called at probe time */ |
| 1644 | static int sd_config(struct gspca_dev *gspca_dev, |
| 1645 | const struct usb_device_id *id) |
| 1646 | { |
| 1647 | struct sd *sd = (struct sd *) gspca_dev; |
| 1648 | struct cam *cam; |
| 1649 | int ret = 0; |
| 1650 | |
| 1651 | sd->bridge = id->driver_info; |
| 1652 | |
| 1653 | switch (sd->bridge) { |
| 1654 | case BRIDGE_OV518: |
| 1655 | case BRIDGE_OV518PLUS: |
| 1656 | ret = ov518_configure(gspca_dev); |
| 1657 | break; |
| 1658 | case BRIDGE_OV519: |
| 1659 | ret = ov519_configure(sd); |
| 1660 | break; |
| 1661 | } |
| 1662 | |
| 1663 | if (ret) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1664 | goto error; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1665 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1666 | ov51x_led_control(sd, 0); /* turn LED off */ |
| 1667 | |
| 1668 | /* Test for 76xx */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1669 | if (ov51x_set_slave_ids(sd, OV7xx0_SID) < 0) |
| 1670 | goto error; |
| 1671 | |
| 1672 | /* The OV519 must be more aggressive about sensor detection since |
| 1673 | * I2C write will never fail if the sensor is not present. We have |
| 1674 | * to try to initialize the sensor to detect its presence */ |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1675 | if (init_ov_sensor(sd) >= 0) { |
| 1676 | if (ov7xx0_configure(sd) < 0) { |
| 1677 | PDEBUG(D_ERR, "Failed to configure OV7xx0"); |
| 1678 | goto error; |
| 1679 | } |
| 1680 | } else { |
| 1681 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1682 | /* Test for 6xx0 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1683 | if (ov51x_set_slave_ids(sd, OV6xx0_SID) < 0) |
| 1684 | goto error; |
| 1685 | |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1686 | if (init_ov_sensor(sd) >= 0) { |
| 1687 | if (ov6xx0_configure(sd) < 0) { |
| 1688 | PDEBUG(D_ERR, "Failed to configure OV6xx0"); |
| 1689 | goto error; |
| 1690 | } |
| 1691 | } else { |
| 1692 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1693 | /* Test for 8xx0 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1694 | if (ov51x_set_slave_ids(sd, OV8xx0_SID) < 0) |
| 1695 | goto error; |
| 1696 | |
| 1697 | if (init_ov_sensor(sd) < 0) { |
| 1698 | PDEBUG(D_ERR, |
| 1699 | "Can't determine sensor slave IDs"); |
| 1700 | goto error; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1701 | } |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1702 | if (ov8xx0_configure(sd) < 0) { |
| 1703 | PDEBUG(D_ERR, |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1704 | "Failed to configure OV8xx0 sensor"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1705 | goto error; |
| 1706 | } |
| 1707 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | cam = &gspca_dev->cam; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1711 | switch (sd->bridge) { |
| 1712 | case BRIDGE_OV518: |
| 1713 | case BRIDGE_OV518PLUS: |
| 1714 | if (!sd->sif) { |
| 1715 | cam->cam_mode = ov518_vga_mode; |
| 1716 | cam->nmodes = ARRAY_SIZE(ov518_vga_mode); |
| 1717 | } else { |
| 1718 | cam->cam_mode = ov518_sif_mode; |
| 1719 | cam->nmodes = ARRAY_SIZE(ov518_sif_mode); |
| 1720 | } |
| 1721 | break; |
| 1722 | case BRIDGE_OV519: |
| 1723 | if (!sd->sif) { |
| 1724 | cam->cam_mode = ov519_vga_mode; |
| 1725 | cam->nmodes = ARRAY_SIZE(ov519_vga_mode); |
| 1726 | } else { |
| 1727 | cam->cam_mode = ov519_sif_mode; |
| 1728 | cam->nmodes = ARRAY_SIZE(ov519_sif_mode); |
| 1729 | } |
| 1730 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1731 | } |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1732 | sd->brightness = BRIGHTNESS_DEF; |
| 1733 | sd->contrast = CONTRAST_DEF; |
| 1734 | sd->colors = COLOR_DEF; |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 1735 | sd->hflip = HFLIP_DEF; |
| 1736 | sd->vflip = VFLIP_DEF; |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 1737 | sd->autobrightness = AUTOBRIGHT_DEF; |
| 1738 | if (sd->sensor == SEN_OV7670) { |
| 1739 | sd->freq = OV7670_FREQ_DEF; |
| 1740 | gspca_dev->ctrl_dis = 1 << FREQ_IDX; |
| 1741 | } else { |
| 1742 | sd->freq = FREQ_DEF; |
| 1743 | gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | |
| 1744 | (1 << OV7670_FREQ_IDX); |
| 1745 | } |
| 1746 | if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670) |
| 1747 | gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX; |
| 1748 | /* OV8610 Frequency filter control should work but needs testing */ |
| 1749 | if (sd->sensor == SEN_OV8610) |
| 1750 | gspca_dev->ctrl_dis |= 1 << FREQ_IDX; |
| 1751 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1752 | return 0; |
| 1753 | error: |
| 1754 | PDEBUG(D_ERR, "OV519 Config failed"); |
| 1755 | return -EBUSY; |
| 1756 | } |
| 1757 | |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 1758 | /* this function is called at probe and resume time */ |
| 1759 | static int sd_init(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1760 | { |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1761 | struct sd *sd = (struct sd *) gspca_dev; |
| 1762 | |
| 1763 | /* initialize the sensor */ |
| 1764 | switch (sd->sensor) { |
| 1765 | case SEN_OV6620: |
| 1766 | if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20))) |
| 1767 | return -EIO; |
| 1768 | break; |
| 1769 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 1770 | case SEN_OV66308AF: |
Jean-Francois Moine | 4202f71 | 2008-09-03 17:12:15 -0300 | [diff] [blame] | 1771 | if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30))) |
| 1772 | return -EIO; |
| 1773 | break; |
| 1774 | default: |
| 1775 | /* case SEN_OV7610: */ |
| 1776 | /* case SEN_OV76BE: */ |
| 1777 | if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610))) |
| 1778 | return -EIO; |
| 1779 | break; |
| 1780 | case SEN_OV7620: |
| 1781 | if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620))) |
| 1782 | return -EIO; |
| 1783 | break; |
| 1784 | case SEN_OV7640: |
| 1785 | if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640))) |
| 1786 | return -EIO; |
| 1787 | break; |
| 1788 | case SEN_OV7670: |
| 1789 | if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670))) |
| 1790 | return -EIO; |
| 1791 | break; |
| 1792 | case SEN_OV8610: |
| 1793 | if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610))) |
| 1794 | return -EIO; |
| 1795 | break; |
| 1796 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1797 | return 0; |
| 1798 | } |
| 1799 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 1800 | /* Sets up the OV518/OV518+ with the given image parameters |
| 1801 | * |
| 1802 | * OV518 needs a completely different approach, until we can figure out what |
| 1803 | * the individual registers do. Also, only 15 FPS is supported now. |
| 1804 | * |
| 1805 | * Do not put any sensor-specific code in here (including I2C I/O functions) |
| 1806 | */ |
| 1807 | static int ov518_mode_init_regs(struct sd *sd) |
| 1808 | { |
| 1809 | int hsegs, vsegs; |
| 1810 | |
| 1811 | /******** Set the mode ********/ |
| 1812 | |
| 1813 | reg_w(sd, 0x2b, 0); |
| 1814 | reg_w(sd, 0x2c, 0); |
| 1815 | reg_w(sd, 0x2d, 0); |
| 1816 | reg_w(sd, 0x2e, 0); |
| 1817 | reg_w(sd, 0x3b, 0); |
| 1818 | reg_w(sd, 0x3c, 0); |
| 1819 | reg_w(sd, 0x3d, 0); |
| 1820 | reg_w(sd, 0x3e, 0); |
| 1821 | |
| 1822 | if (sd->bridge == BRIDGE_OV518) { |
| 1823 | /* Set 8-bit (YVYU) input format */ |
| 1824 | reg_w_mask(sd, 0x20, 0x08, 0x08); |
| 1825 | |
| 1826 | /* Set 12-bit (4:2:0) output format */ |
| 1827 | reg_w_mask(sd, 0x28, 0x80, 0xf0); |
| 1828 | reg_w_mask(sd, 0x38, 0x80, 0xf0); |
| 1829 | } else { |
| 1830 | reg_w(sd, 0x28, 0x80); |
| 1831 | reg_w(sd, 0x38, 0x80); |
| 1832 | } |
| 1833 | |
| 1834 | hsegs = sd->gspca_dev.width / 16; |
| 1835 | vsegs = sd->gspca_dev.height / 4; |
| 1836 | |
| 1837 | reg_w(sd, 0x29, hsegs); |
| 1838 | reg_w(sd, 0x2a, vsegs); |
| 1839 | |
| 1840 | reg_w(sd, 0x39, hsegs); |
| 1841 | reg_w(sd, 0x3a, vsegs); |
| 1842 | |
| 1843 | /* Windows driver does this here; who knows why */ |
| 1844 | reg_w(sd, 0x2f, 0x80); |
| 1845 | |
| 1846 | /******** Set the framerate (to 30 FPS) ********/ |
| 1847 | if (sd->bridge == BRIDGE_OV518PLUS) |
| 1848 | sd->clockdiv = 1; |
| 1849 | else |
| 1850 | sd->clockdiv = 0; |
| 1851 | |
| 1852 | /* Mode independent, but framerate dependent, regs */ |
| 1853 | reg_w(sd, 0x51, 0x04); /* Clock divider; lower==faster */ |
| 1854 | reg_w(sd, 0x22, 0x18); |
| 1855 | reg_w(sd, 0x23, 0xff); |
| 1856 | |
| 1857 | if (sd->bridge == BRIDGE_OV518PLUS) |
| 1858 | reg_w(sd, 0x21, 0x19); |
| 1859 | else |
| 1860 | reg_w(sd, 0x71, 0x17); /* Compression-related? */ |
| 1861 | |
| 1862 | /* FIXME: Sensor-specific */ |
| 1863 | /* Bit 5 is what matters here. Of course, it is "reserved" */ |
| 1864 | i2c_w(sd, 0x54, 0x23); |
| 1865 | |
| 1866 | reg_w(sd, 0x2f, 0x80); |
| 1867 | |
| 1868 | if (sd->bridge == BRIDGE_OV518PLUS) { |
| 1869 | reg_w(sd, 0x24, 0x94); |
| 1870 | reg_w(sd, 0x25, 0x90); |
| 1871 | ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */ |
| 1872 | ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */ |
| 1873 | ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */ |
| 1874 | ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */ |
| 1875 | ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */ |
| 1876 | ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */ |
| 1877 | ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */ |
| 1878 | ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */ |
| 1879 | ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */ |
| 1880 | } else { |
| 1881 | reg_w(sd, 0x24, 0x9f); |
| 1882 | reg_w(sd, 0x25, 0x90); |
| 1883 | ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */ |
| 1884 | ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */ |
| 1885 | ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */ |
| 1886 | ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */ |
| 1887 | ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */ |
| 1888 | ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */ |
| 1889 | ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */ |
| 1890 | ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */ |
| 1891 | ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */ |
| 1892 | } |
| 1893 | |
| 1894 | reg_w(sd, 0x2f, 0x80); |
| 1895 | |
| 1896 | return 0; |
| 1897 | } |
| 1898 | |
| 1899 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1900 | /* Sets up the OV519 with the given image parameters |
| 1901 | * |
| 1902 | * OV519 needs a completely different approach, until we can figure out what |
| 1903 | * the individual registers do. |
| 1904 | * |
| 1905 | * Do not put any sensor-specific code in here (including I2C I/O functions) |
| 1906 | */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1907 | static int ov519_mode_init_regs(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1908 | { |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1909 | static const struct ov_regvals mode_init_519_ov7670[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1910 | { 0x5d, 0x03 }, /* Turn off suspend mode */ |
| 1911 | { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */ |
| 1912 | { 0x54, 0x0f }, /* bit2 (jpeg enable) */ |
| 1913 | { 0xa2, 0x20 }, /* a2-a5 are undocumented */ |
| 1914 | { 0xa3, 0x18 }, |
| 1915 | { 0xa4, 0x04 }, |
| 1916 | { 0xa5, 0x28 }, |
| 1917 | { 0x37, 0x00 }, /* SetUsbInit */ |
| 1918 | { 0x55, 0x02 }, /* 4.096 Mhz audio clock */ |
| 1919 | /* Enable both fields, YUV Input, disable defect comp (why?) */ |
| 1920 | { 0x20, 0x0c }, |
| 1921 | { 0x21, 0x38 }, |
| 1922 | { 0x22, 0x1d }, |
| 1923 | { 0x17, 0x50 }, /* undocumented */ |
| 1924 | { 0x37, 0x00 }, /* undocumented */ |
| 1925 | { 0x40, 0xff }, /* I2C timeout counter */ |
| 1926 | { 0x46, 0x00 }, /* I2C clock prescaler */ |
| 1927 | { 0x59, 0x04 }, /* new from windrv 090403 */ |
| 1928 | { 0xff, 0x00 }, /* undocumented */ |
| 1929 | /* windows reads 0x55 at this point, why? */ |
| 1930 | }; |
| 1931 | |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1932 | static const struct ov_regvals mode_init_519[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1933 | { 0x5d, 0x03 }, /* Turn off suspend mode */ |
| 1934 | { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */ |
| 1935 | { 0x54, 0x0f }, /* bit2 (jpeg enable) */ |
| 1936 | { 0xa2, 0x20 }, /* a2-a5 are undocumented */ |
| 1937 | { 0xa3, 0x18 }, |
| 1938 | { 0xa4, 0x04 }, |
| 1939 | { 0xa5, 0x28 }, |
| 1940 | { 0x37, 0x00 }, /* SetUsbInit */ |
| 1941 | { 0x55, 0x02 }, /* 4.096 Mhz audio clock */ |
| 1942 | /* Enable both fields, YUV Input, disable defect comp (why?) */ |
| 1943 | { 0x22, 0x1d }, |
| 1944 | { 0x17, 0x50 }, /* undocumented */ |
| 1945 | { 0x37, 0x00 }, /* undocumented */ |
| 1946 | { 0x40, 0xff }, /* I2C timeout counter */ |
| 1947 | { 0x46, 0x00 }, /* I2C clock prescaler */ |
| 1948 | { 0x59, 0x04 }, /* new from windrv 090403 */ |
| 1949 | { 0xff, 0x00 }, /* undocumented */ |
| 1950 | /* windows reads 0x55 at this point, why? */ |
| 1951 | }; |
| 1952 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1953 | /******** Set the mode ********/ |
| 1954 | if (sd->sensor != SEN_OV7670) { |
| 1955 | if (write_regvals(sd, mode_init_519, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1956 | ARRAY_SIZE(mode_init_519))) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1957 | return -EIO; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1958 | if (sd->sensor == SEN_OV7640) { |
| 1959 | /* Select 8-bit input mode */ |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1960 | reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1961 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1962 | } else { |
| 1963 | if (write_regvals(sd, mode_init_519_ov7670, |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 1964 | ARRAY_SIZE(mode_init_519_ov7670))) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1965 | return -EIO; |
| 1966 | } |
| 1967 | |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 1968 | reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4); |
| 1969 | reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3); |
| 1970 | reg_w(sd, OV519_R12_X_OFFSETL, 0x00); |
| 1971 | reg_w(sd, OV519_R13_X_OFFSETH, 0x00); |
| 1972 | reg_w(sd, OV519_R14_Y_OFFSETL, 0x00); |
| 1973 | reg_w(sd, OV519_R15_Y_OFFSETH, 0x00); |
| 1974 | reg_w(sd, OV519_R16_DIVIDER, 0x00); |
| 1975 | reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1976 | reg_w(sd, 0x26, 0x00); /* Undocumented */ |
| 1977 | |
| 1978 | /******** Set the framerate ********/ |
| 1979 | if (frame_rate > 0) |
| 1980 | sd->frame_rate = frame_rate; |
| 1981 | |
| 1982 | /* FIXME: These are only valid at the max resolution. */ |
| 1983 | sd->clockdiv = 0; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 1984 | switch (sd->sensor) { |
| 1985 | case SEN_OV7640: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1986 | switch (sd->frame_rate) { |
Jean-Francois Moine | 53e7451 | 2008-11-08 06:10:19 -0300 | [diff] [blame] | 1987 | default: |
| 1988 | /* case 30: */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 1989 | reg_w(sd, 0xa4, 0x0c); |
| 1990 | reg_w(sd, 0x23, 0xff); |
| 1991 | break; |
| 1992 | case 25: |
| 1993 | reg_w(sd, 0xa4, 0x0c); |
| 1994 | reg_w(sd, 0x23, 0x1f); |
| 1995 | break; |
| 1996 | case 20: |
| 1997 | reg_w(sd, 0xa4, 0x0c); |
| 1998 | reg_w(sd, 0x23, 0x1b); |
| 1999 | break; |
Jean-Francois Moine | 53e7451 | 2008-11-08 06:10:19 -0300 | [diff] [blame] | 2000 | case 15: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2001 | reg_w(sd, 0xa4, 0x04); |
| 2002 | reg_w(sd, 0x23, 0xff); |
| 2003 | sd->clockdiv = 1; |
| 2004 | break; |
| 2005 | case 10: |
| 2006 | reg_w(sd, 0xa4, 0x04); |
| 2007 | reg_w(sd, 0x23, 0x1f); |
| 2008 | sd->clockdiv = 1; |
| 2009 | break; |
| 2010 | case 5: |
| 2011 | reg_w(sd, 0xa4, 0x04); |
| 2012 | reg_w(sd, 0x23, 0x1b); |
| 2013 | sd->clockdiv = 1; |
| 2014 | break; |
| 2015 | } |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2016 | break; |
| 2017 | case SEN_OV8610: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2018 | switch (sd->frame_rate) { |
| 2019 | default: /* 15 fps */ |
| 2020 | /* case 15: */ |
| 2021 | reg_w(sd, 0xa4, 0x06); |
| 2022 | reg_w(sd, 0x23, 0xff); |
| 2023 | break; |
| 2024 | case 10: |
| 2025 | reg_w(sd, 0xa4, 0x06); |
| 2026 | reg_w(sd, 0x23, 0x1f); |
| 2027 | break; |
| 2028 | case 5: |
| 2029 | reg_w(sd, 0xa4, 0x06); |
| 2030 | reg_w(sd, 0x23, 0x1b); |
| 2031 | break; |
| 2032 | } |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2033 | break; |
| 2034 | case SEN_OV7670: /* guesses, based on 7640 */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2035 | PDEBUG(D_STREAM, "Setting framerate to %d fps", |
| 2036 | (sd->frame_rate == 0) ? 15 : sd->frame_rate); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2037 | reg_w(sd, 0xa4, 0x10); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2038 | switch (sd->frame_rate) { |
| 2039 | case 30: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2040 | reg_w(sd, 0x23, 0xff); |
| 2041 | break; |
| 2042 | case 20: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2043 | reg_w(sd, 0x23, 0x1b); |
| 2044 | break; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2045 | default: |
| 2046 | /* case 15: */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2047 | reg_w(sd, 0x23, 0xff); |
| 2048 | sd->clockdiv = 1; |
| 2049 | break; |
| 2050 | } |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2051 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2052 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2053 | return 0; |
| 2054 | } |
| 2055 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2056 | static int mode_init_ov_sensor_regs(struct sd *sd) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2057 | { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2058 | struct gspca_dev *gspca_dev; |
| 2059 | int qvga; |
| 2060 | |
| 2061 | gspca_dev = &sd->gspca_dev; |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 2062 | qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2063 | |
| 2064 | /******** Mode (VGA/QVGA) and sensor specific regs ********/ |
| 2065 | switch (sd->sensor) { |
| 2066 | case SEN_OV8610: |
| 2067 | /* For OV8610 qvga means qsvga */ |
| 2068 | i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5); |
| 2069 | break; |
| 2070 | case SEN_OV7610: |
| 2071 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 2072 | break; |
| 2073 | case SEN_OV7620: |
| 2074 | /* i2c_w(sd, 0x2b, 0x00); */ |
| 2075 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 2076 | i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); |
| 2077 | i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); |
| 2078 | i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); |
| 2079 | i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); |
| 2080 | i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); |
| 2081 | i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); |
| 2082 | break; |
| 2083 | case SEN_OV76BE: |
| 2084 | /* i2c_w(sd, 0x2b, 0x00); */ |
| 2085 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 2086 | break; |
| 2087 | case SEN_OV7640: |
| 2088 | /* i2c_w(sd, 0x2b, 0x00); */ |
| 2089 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 2090 | i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); |
| 2091 | /* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */ |
| 2092 | /* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */ |
| 2093 | /* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */ |
| 2094 | /* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */ |
| 2095 | /* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */ |
| 2096 | break; |
| 2097 | case SEN_OV7670: |
| 2098 | /* set COM7_FMT_VGA or COM7_FMT_QVGA |
| 2099 | * do we need to set anything else? |
| 2100 | * HSTART etc are set in set_ov_sensor_window itself */ |
| 2101 | i2c_w_mask(sd, OV7670_REG_COM7, |
| 2102 | qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA, |
| 2103 | OV7670_COM7_FMT_MASK); |
| 2104 | break; |
| 2105 | case SEN_OV6620: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2106 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2107 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2108 | i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); |
| 2109 | break; |
| 2110 | default: |
| 2111 | return -EINVAL; |
| 2112 | } |
| 2113 | |
| 2114 | /******** Palette-specific regs ********/ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2115 | if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) { |
| 2116 | /* not valid on the OV6620/OV7620/6630? */ |
| 2117 | i2c_w_mask(sd, 0x0e, 0x00, 0x40); |
| 2118 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2119 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2120 | /* The OV518 needs special treatment. Although both the OV518 |
| 2121 | * and the OV6630 support a 16-bit video bus, only the 8 bit Y |
| 2122 | * bus is actually used. The UV bus is tied to ground. |
| 2123 | * Therefore, the OV6630 needs to be in 8-bit multiplexed |
| 2124 | * output mode */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2125 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2126 | /* OV7640 is 8-bit only */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2127 | |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2128 | if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV66308AF && |
| 2129 | sd->sensor != SEN_OV7640) |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2130 | i2c_w_mask(sd, 0x13, 0x00, 0x20); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2131 | |
| 2132 | /******** Clock programming ********/ |
| 2133 | /* The OV6620 needs special handling. This prevents the |
| 2134 | * severe banding that normally occurs */ |
| 2135 | if (sd->sensor == SEN_OV6620) { |
| 2136 | |
| 2137 | /* Clock down */ |
| 2138 | i2c_w(sd, 0x2a, 0x04); |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2139 | i2c_w(sd, 0x11, sd->clockdiv); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2140 | i2c_w(sd, 0x2a, 0x84); |
| 2141 | /* This next setting is critical. It seems to improve |
| 2142 | * the gain or the contrast. The "reserved" bits seem |
| 2143 | * to have some effect in this case. */ |
| 2144 | i2c_w(sd, 0x2d, 0x85); |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2145 | } else { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2146 | i2c_w(sd, 0x11, sd->clockdiv); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2147 | } |
| 2148 | |
| 2149 | /******** Special Features ********/ |
| 2150 | /* no evidence this is possible with OV7670, either */ |
| 2151 | /* Test Pattern */ |
| 2152 | if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670) |
| 2153 | i2c_w_mask(sd, 0x12, 0x00, 0x02); |
| 2154 | |
| 2155 | /* Enable auto white balance */ |
| 2156 | if (sd->sensor == SEN_OV7670) |
| 2157 | i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB, |
| 2158 | OV7670_COM8_AWB); |
| 2159 | else |
| 2160 | i2c_w_mask(sd, 0x12, 0x04, 0x04); |
| 2161 | |
| 2162 | /* This will go away as soon as ov51x_mode_init_sensor_regs() */ |
| 2163 | /* is fully tested. */ |
| 2164 | /* 7620/6620/6630? don't have register 0x35, so play it safe */ |
| 2165 | if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2166 | if (!qvga) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2167 | i2c_w(sd, 0x35, 0x9e); |
| 2168 | else |
| 2169 | i2c_w(sd, 0x35, 0x1e); |
| 2170 | } |
| 2171 | return 0; |
| 2172 | } |
| 2173 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2174 | static void sethvflip(struct sd *sd) |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 2175 | { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2176 | if (sd->sensor != SEN_OV7670) |
| 2177 | return; |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 2178 | if (sd->gspca_dev.streaming) |
| 2179 | ov51x_stop(sd); |
| 2180 | i2c_w_mask(sd, OV7670_REG_MVFP, |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2181 | OV7670_MVFP_MIRROR * sd->hflip |
| 2182 | | OV7670_MVFP_VFLIP * sd->vflip, |
| 2183 | OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP); |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 2184 | if (sd->gspca_dev.streaming) |
| 2185 | ov51x_restart(sd); |
| 2186 | } |
| 2187 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2188 | static int set_ov_sensor_window(struct sd *sd) |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 2189 | { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2190 | struct gspca_dev *gspca_dev; |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 2191 | int qvga, crop; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2192 | int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale; |
| 2193 | int ret, hstart, hstop, vstop, vstart; |
| 2194 | __u8 v; |
| 2195 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2196 | gspca_dev = &sd->gspca_dev; |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 2197 | qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1; |
| 2198 | crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2; |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2199 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2200 | /* The different sensor ICs handle setting up of window differently. |
| 2201 | * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */ |
| 2202 | switch (sd->sensor) { |
| 2203 | case SEN_OV8610: |
| 2204 | hwsbase = 0x1e; |
| 2205 | hwebase = 0x1e; |
| 2206 | vwsbase = 0x02; |
| 2207 | vwebase = 0x02; |
| 2208 | break; |
| 2209 | case SEN_OV7610: |
| 2210 | case SEN_OV76BE: |
| 2211 | hwsbase = 0x38; |
| 2212 | hwebase = 0x3a; |
| 2213 | vwsbase = vwebase = 0x05; |
| 2214 | break; |
| 2215 | case SEN_OV6620: |
| 2216 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2217 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2218 | hwsbase = 0x38; |
| 2219 | hwebase = 0x3a; |
| 2220 | vwsbase = 0x05; |
| 2221 | vwebase = 0x06; |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2222 | if (sd->sensor == SEN_OV66308AF && qvga) |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2223 | /* HDG: this fixes U and V getting swapped */ |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2224 | hwsbase++; |
Hans de Goede | 124cc9c | 2009-06-14 05:48:00 -0300 | [diff] [blame^] | 2225 | if (crop) { |
| 2226 | hwsbase += 8; |
| 2227 | hwebase += 8; |
| 2228 | vwsbase += 11; |
| 2229 | vwebase += 11; |
| 2230 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2231 | break; |
| 2232 | case SEN_OV7620: |
| 2233 | hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */ |
| 2234 | hwebase = 0x2f; |
| 2235 | vwsbase = vwebase = 0x05; |
| 2236 | break; |
| 2237 | case SEN_OV7640: |
| 2238 | hwsbase = 0x1a; |
| 2239 | hwebase = 0x1a; |
| 2240 | vwsbase = vwebase = 0x03; |
| 2241 | break; |
| 2242 | case SEN_OV7670: |
| 2243 | /*handling of OV7670 hardware sensor start and stop values |
| 2244 | * is very odd, compared to the other OV sensors */ |
| 2245 | vwsbase = vwebase = hwebase = hwsbase = 0x00; |
| 2246 | break; |
| 2247 | default: |
| 2248 | return -EINVAL; |
| 2249 | } |
| 2250 | |
| 2251 | switch (sd->sensor) { |
| 2252 | case SEN_OV6620: |
| 2253 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2254 | case SEN_OV66308AF: |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2255 | if (qvga) { /* QCIF */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2256 | hwscale = 0; |
| 2257 | vwscale = 0; |
| 2258 | } else { /* CIF */ |
| 2259 | hwscale = 1; |
| 2260 | vwscale = 1; /* The datasheet says 0; |
| 2261 | * it's wrong */ |
| 2262 | } |
| 2263 | break; |
| 2264 | case SEN_OV8610: |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2265 | if (qvga) { /* QSVGA */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2266 | hwscale = 1; |
| 2267 | vwscale = 1; |
| 2268 | } else { /* SVGA */ |
| 2269 | hwscale = 2; |
| 2270 | vwscale = 2; |
| 2271 | } |
| 2272 | break; |
| 2273 | default: /* SEN_OV7xx0 */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2274 | if (qvga) { /* QVGA */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2275 | hwscale = 1; |
| 2276 | vwscale = 0; |
| 2277 | } else { /* VGA */ |
| 2278 | hwscale = 2; |
| 2279 | vwscale = 1; |
| 2280 | } |
| 2281 | } |
| 2282 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2283 | ret = mode_init_ov_sensor_regs(sd); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2284 | if (ret < 0) |
| 2285 | return ret; |
| 2286 | |
| 2287 | if (sd->sensor == SEN_OV8610) { |
| 2288 | i2c_w_mask(sd, 0x2d, 0x05, 0x40); |
| 2289 | /* old 0x95, new 0x05 from windrv 090403 */ |
| 2290 | /* bits 5-7: reserved */ |
| 2291 | i2c_w_mask(sd, 0x28, 0x20, 0x20); |
| 2292 | /* bit 5: progressive mode on */ |
| 2293 | } |
| 2294 | |
| 2295 | /* The below is wrong for OV7670s because their window registers |
| 2296 | * only store the high bits in 0x17 to 0x1a */ |
| 2297 | |
| 2298 | /* SRH Use sd->max values instead of requested win values */ |
| 2299 | /* SCS Since we're sticking with only the max hardware widths |
| 2300 | * for a given mode */ |
| 2301 | /* I can hard code this for OV7670s */ |
| 2302 | /* Yes, these numbers do look odd, but they're tested and work! */ |
| 2303 | if (sd->sensor == SEN_OV7670) { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2304 | if (qvga) { /* QVGA from ov7670.c by |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2305 | * Jonathan Corbet */ |
| 2306 | hstart = 164; |
| 2307 | hstop = 20; |
| 2308 | vstart = 14; |
| 2309 | vstop = 494; |
| 2310 | } else { /* VGA */ |
| 2311 | hstart = 158; |
| 2312 | hstop = 14; |
| 2313 | vstart = 10; |
| 2314 | vstop = 490; |
| 2315 | } |
| 2316 | /* OV7670 hardware window registers are split across |
| 2317 | * multiple locations */ |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2318 | i2c_w(sd, OV7670_REG_HSTART, hstart >> 3); |
| 2319 | i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2320 | v = i2c_r(sd, OV7670_REG_HREF); |
| 2321 | v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07); |
| 2322 | msleep(10); /* need to sleep between read and write to |
| 2323 | * same reg! */ |
| 2324 | i2c_w(sd, OV7670_REG_HREF, v); |
| 2325 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2326 | i2c_w(sd, OV7670_REG_VSTART, vstart >> 2); |
| 2327 | i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2328 | v = i2c_r(sd, OV7670_REG_VREF); |
| 2329 | v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03); |
| 2330 | msleep(10); /* need to sleep between read and write to |
| 2331 | * same reg! */ |
| 2332 | i2c_w(sd, OV7670_REG_VREF, v); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2333 | } else { |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2334 | i2c_w(sd, 0x17, hwsbase); |
| 2335 | i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale)); |
| 2336 | i2c_w(sd, 0x19, vwsbase); |
| 2337 | i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale)); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2338 | } |
| 2339 | return 0; |
| 2340 | } |
| 2341 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2342 | /* -- start the camera -- */ |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 2343 | static int sd_start(struct gspca_dev *gspca_dev) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2344 | { |
| 2345 | struct sd *sd = (struct sd *) gspca_dev; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2346 | int ret = 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2347 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2348 | switch (sd->bridge) { |
| 2349 | case BRIDGE_OV518: |
| 2350 | case BRIDGE_OV518PLUS: |
| 2351 | ret = ov518_mode_init_regs(sd); |
| 2352 | break; |
| 2353 | case BRIDGE_OV519: |
| 2354 | ret = ov519_mode_init_regs(sd); |
| 2355 | break; |
| 2356 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2357 | if (ret < 0) |
| 2358 | goto out; |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2359 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2360 | ret = set_ov_sensor_window(sd); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2361 | if (ret < 0) |
| 2362 | goto out; |
| 2363 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2364 | setcontrast(gspca_dev); |
| 2365 | setbrightness(gspca_dev); |
| 2366 | setcolors(gspca_dev); |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 2367 | sethvflip(sd); |
| 2368 | setautobrightness(sd); |
| 2369 | setfreq(sd); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2370 | |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2371 | ret = ov51x_restart(sd); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2372 | if (ret < 0) |
| 2373 | goto out; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2374 | ov51x_led_control(sd, 1); |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 2375 | return 0; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2376 | out: |
| 2377 | PDEBUG(D_ERR, "camera start error:%d", ret); |
Jean-Francois Moine | 72ab97c | 2008-09-20 06:39:08 -0300 | [diff] [blame] | 2378 | return ret; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2379 | } |
| 2380 | |
| 2381 | static void sd_stopN(struct gspca_dev *gspca_dev) |
| 2382 | { |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2383 | struct sd *sd = (struct sd *) gspca_dev; |
| 2384 | |
| 2385 | ov51x_stop(sd); |
| 2386 | ov51x_led_control(sd, 0); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2387 | } |
| 2388 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2389 | static void ov518_pkt_scan(struct gspca_dev *gspca_dev, |
| 2390 | struct gspca_frame *frame, /* target */ |
| 2391 | __u8 *data, /* isoc packet */ |
| 2392 | int len) /* iso packet length */ |
| 2393 | { |
| 2394 | PDEBUG(D_STREAM, "ov518_pkt_scan: %d bytes", len); |
| 2395 | |
| 2396 | if (len & 7) { |
| 2397 | len--; |
| 2398 | PDEBUG(D_STREAM, "packet number: %d\n", (int)data[len]); |
| 2399 | } |
| 2400 | |
| 2401 | /* A false positive here is likely, until OVT gives me |
| 2402 | * the definitive SOF/EOF format */ |
| 2403 | if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) { |
| 2404 | gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0); |
| 2405 | gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, 0); |
| 2406 | } |
| 2407 | |
| 2408 | /* intermediate packet */ |
| 2409 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); |
| 2410 | } |
| 2411 | |
| 2412 | static void ov519_pkt_scan(struct gspca_dev *gspca_dev, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2413 | struct gspca_frame *frame, /* target */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 2414 | __u8 *data, /* isoc packet */ |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2415 | int len) /* iso packet length */ |
| 2416 | { |
| 2417 | /* Header of ov519 is 16 bytes: |
| 2418 | * Byte Value Description |
| 2419 | * 0 0xff magic |
| 2420 | * 1 0xff magic |
| 2421 | * 2 0xff magic |
| 2422 | * 3 0xXX 0x50 = SOF, 0x51 = EOF |
| 2423 | * 9 0xXX 0x01 initial frame without data, |
| 2424 | * 0x00 standard frame with image |
| 2425 | * 14 Lo in EOF: length of image data / 8 |
| 2426 | * 15 Hi |
| 2427 | */ |
| 2428 | |
| 2429 | if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) { |
| 2430 | switch (data[3]) { |
| 2431 | case 0x50: /* start of frame */ |
| 2432 | #define HDRSZ 16 |
| 2433 | data += HDRSZ; |
| 2434 | len -= HDRSZ; |
| 2435 | #undef HDRSZ |
| 2436 | if (data[0] == 0xff || data[1] == 0xd8) |
| 2437 | gspca_frame_add(gspca_dev, FIRST_PACKET, frame, |
| 2438 | data, len); |
| 2439 | else |
| 2440 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 2441 | return; |
| 2442 | case 0x51: /* end of frame */ |
| 2443 | if (data[9] != 0) |
| 2444 | gspca_dev->last_packet_type = DISCARD_PACKET; |
| 2445 | gspca_frame_add(gspca_dev, LAST_PACKET, frame, |
| 2446 | data, 0); |
| 2447 | return; |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | /* intermediate packet */ |
| 2452 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, |
| 2453 | data, len); |
| 2454 | } |
| 2455 | |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2456 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, |
| 2457 | struct gspca_frame *frame, /* target */ |
| 2458 | __u8 *data, /* isoc packet */ |
| 2459 | int len) /* iso packet length */ |
| 2460 | { |
| 2461 | struct sd *sd = (struct sd *) gspca_dev; |
| 2462 | |
| 2463 | switch (sd->bridge) { |
| 2464 | case BRIDGE_OV511: |
| 2465 | case BRIDGE_OV511PLUS: |
| 2466 | break; |
| 2467 | case BRIDGE_OV518: |
| 2468 | case BRIDGE_OV518PLUS: |
| 2469 | ov518_pkt_scan(gspca_dev, frame, data, len); |
| 2470 | break; |
| 2471 | case BRIDGE_OV519: |
| 2472 | ov519_pkt_scan(gspca_dev, frame, data, len); |
| 2473 | break; |
| 2474 | } |
| 2475 | } |
| 2476 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2477 | /* -- management routines -- */ |
| 2478 | |
| 2479 | static void setbrightness(struct gspca_dev *gspca_dev) |
| 2480 | { |
| 2481 | struct sd *sd = (struct sd *) gspca_dev; |
| 2482 | int val; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2483 | |
| 2484 | val = sd->brightness; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2485 | switch (sd->sensor) { |
| 2486 | case SEN_OV8610: |
| 2487 | case SEN_OV7610: |
| 2488 | case SEN_OV76BE: |
| 2489 | case SEN_OV6620: |
| 2490 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2491 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2492 | case SEN_OV7640: |
| 2493 | i2c_w(sd, OV7610_REG_BRT, val); |
| 2494 | break; |
| 2495 | case SEN_OV7620: |
| 2496 | /* 7620 doesn't like manual changes when in auto mode */ |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 2497 | if (!sd->autobrightness) |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2498 | i2c_w(sd, OV7610_REG_BRT, val); |
| 2499 | break; |
| 2500 | case SEN_OV7670: |
Jean-Francois Moine | 594f5b8 | 2008-08-01 06:37:51 -0300 | [diff] [blame] | 2501 | /*win trace |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2502 | * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */ |
| 2503 | i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val)); |
| 2504 | break; |
| 2505 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | static void setcontrast(struct gspca_dev *gspca_dev) |
| 2509 | { |
| 2510 | struct sd *sd = (struct sd *) gspca_dev; |
| 2511 | int val; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2512 | |
| 2513 | val = sd->contrast; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2514 | switch (sd->sensor) { |
| 2515 | case SEN_OV7610: |
| 2516 | case SEN_OV6620: |
| 2517 | i2c_w(sd, OV7610_REG_CNT, val); |
| 2518 | break; |
| 2519 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2520 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2521 | i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f); |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2522 | break; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2523 | case SEN_OV8610: { |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 2524 | static const __u8 ctab[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2525 | 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f |
| 2526 | }; |
| 2527 | |
| 2528 | /* Use Y gamma control instead. Bit 0 enables it. */ |
| 2529 | i2c_w(sd, 0x64, ctab[val >> 5]); |
| 2530 | break; |
| 2531 | } |
| 2532 | case SEN_OV7620: { |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 2533 | static const __u8 ctab[] = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2534 | 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57, |
| 2535 | 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff |
| 2536 | }; |
| 2537 | |
| 2538 | /* Use Y gamma control instead. Bit 0 enables it. */ |
| 2539 | i2c_w(sd, 0x64, ctab[val >> 4]); |
| 2540 | break; |
| 2541 | } |
| 2542 | case SEN_OV7640: |
| 2543 | /* Use gain control instead. */ |
| 2544 | i2c_w(sd, OV7610_REG_GAIN, val >> 2); |
| 2545 | break; |
| 2546 | case SEN_OV7670: |
| 2547 | /* check that this isn't just the same as ov7610 */ |
| 2548 | i2c_w(sd, OV7670_REG_CONTRAS, val >> 1); |
| 2549 | break; |
| 2550 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | static void setcolors(struct gspca_dev *gspca_dev) |
| 2554 | { |
| 2555 | struct sd *sd = (struct sd *) gspca_dev; |
| 2556 | int val; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2557 | |
| 2558 | val = sd->colors; |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2559 | switch (sd->sensor) { |
| 2560 | case SEN_OV8610: |
| 2561 | case SEN_OV7610: |
| 2562 | case SEN_OV76BE: |
| 2563 | case SEN_OV6620: |
| 2564 | case SEN_OV6630: |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2565 | case SEN_OV66308AF: |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2566 | i2c_w(sd, OV7610_REG_SAT, val); |
| 2567 | break; |
| 2568 | case SEN_OV7620: |
| 2569 | /* Use UV gamma control instead. Bits 0 & 7 are reserved. */ |
| 2570 | /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e); |
| 2571 | if (rc < 0) |
| 2572 | goto out; */ |
| 2573 | i2c_w(sd, OV7610_REG_SAT, val); |
| 2574 | break; |
| 2575 | case SEN_OV7640: |
| 2576 | i2c_w(sd, OV7610_REG_SAT, val & 0xf0); |
| 2577 | break; |
| 2578 | case SEN_OV7670: |
| 2579 | /* supported later once I work out how to do it |
| 2580 | * transparently fail now! */ |
| 2581 | /* set REG_COM13 values for UV sat auto mode */ |
| 2582 | break; |
| 2583 | } |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2584 | } |
| 2585 | |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 2586 | static void setautobrightness(struct sd *sd) |
| 2587 | { |
| 2588 | if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670) |
| 2589 | return; |
| 2590 | |
| 2591 | i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10); |
| 2592 | } |
| 2593 | |
| 2594 | static void setfreq(struct sd *sd) |
| 2595 | { |
| 2596 | if (sd->sensor == SEN_OV7670) { |
| 2597 | switch (sd->freq) { |
| 2598 | case 0: /* Banding filter disabled */ |
| 2599 | i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT); |
| 2600 | break; |
| 2601 | case 1: /* 50 hz */ |
| 2602 | i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT, |
| 2603 | OV7670_COM8_BFILT); |
| 2604 | i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18); |
| 2605 | break; |
| 2606 | case 2: /* 60 hz */ |
| 2607 | i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT, |
| 2608 | OV7670_COM8_BFILT); |
| 2609 | i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18); |
| 2610 | break; |
| 2611 | case 3: /* Auto hz */ |
| 2612 | i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT, |
| 2613 | OV7670_COM8_BFILT); |
| 2614 | i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO, |
| 2615 | 0x18); |
| 2616 | break; |
| 2617 | } |
| 2618 | } else { |
| 2619 | switch (sd->freq) { |
| 2620 | case 0: /* Banding filter disabled */ |
| 2621 | i2c_w_mask(sd, 0x2d, 0x00, 0x04); |
| 2622 | i2c_w_mask(sd, 0x2a, 0x00, 0x80); |
| 2623 | break; |
| 2624 | case 1: /* 50 hz (filter on and framerate adj) */ |
| 2625 | i2c_w_mask(sd, 0x2d, 0x04, 0x04); |
| 2626 | i2c_w_mask(sd, 0x2a, 0x80, 0x80); |
| 2627 | /* 20 fps -> 16.667 fps */ |
| 2628 | if (sd->sensor == SEN_OV6620 || |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2629 | sd->sensor == SEN_OV6630 || |
| 2630 | sd->sensor == SEN_OV66308AF) |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 2631 | i2c_w(sd, 0x2b, 0x5e); |
| 2632 | else |
| 2633 | i2c_w(sd, 0x2b, 0xac); |
| 2634 | break; |
| 2635 | case 2: /* 60 hz (filter on, ...) */ |
| 2636 | i2c_w_mask(sd, 0x2d, 0x04, 0x04); |
| 2637 | if (sd->sensor == SEN_OV6620 || |
Hans de Goede | 7d97137 | 2009-06-14 05:28:17 -0300 | [diff] [blame] | 2638 | sd->sensor == SEN_OV6630 || |
| 2639 | sd->sensor == SEN_OV66308AF) { |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 2640 | /* 20 fps -> 15 fps */ |
| 2641 | i2c_w_mask(sd, 0x2a, 0x80, 0x80); |
| 2642 | i2c_w(sd, 0x2b, 0xa8); |
| 2643 | } else { |
| 2644 | /* no framerate adj. */ |
| 2645 | i2c_w_mask(sd, 0x2a, 0x00, 0x80); |
| 2646 | } |
| 2647 | break; |
| 2648 | } |
| 2649 | } |
| 2650 | } |
| 2651 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2652 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 2653 | { |
| 2654 | struct sd *sd = (struct sd *) gspca_dev; |
| 2655 | |
| 2656 | sd->brightness = val; |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2657 | if (gspca_dev->streaming) |
| 2658 | setbrightness(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2659 | return 0; |
| 2660 | } |
| 2661 | |
| 2662 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 2663 | { |
| 2664 | struct sd *sd = (struct sd *) gspca_dev; |
| 2665 | |
| 2666 | *val = sd->brightness; |
| 2667 | return 0; |
| 2668 | } |
| 2669 | |
| 2670 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) |
| 2671 | { |
| 2672 | struct sd *sd = (struct sd *) gspca_dev; |
| 2673 | |
| 2674 | sd->contrast = val; |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2675 | if (gspca_dev->streaming) |
| 2676 | setcontrast(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2677 | return 0; |
| 2678 | } |
| 2679 | |
| 2680 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) |
| 2681 | { |
| 2682 | struct sd *sd = (struct sd *) gspca_dev; |
| 2683 | |
| 2684 | *val = sd->contrast; |
| 2685 | return 0; |
| 2686 | } |
| 2687 | |
| 2688 | static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) |
| 2689 | { |
| 2690 | struct sd *sd = (struct sd *) gspca_dev; |
| 2691 | |
| 2692 | sd->colors = val; |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2693 | if (gspca_dev->streaming) |
| 2694 | setcolors(gspca_dev); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2695 | return 0; |
| 2696 | } |
| 2697 | |
| 2698 | static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) |
| 2699 | { |
| 2700 | struct sd *sd = (struct sd *) gspca_dev; |
| 2701 | |
| 2702 | *val = sd->colors; |
| 2703 | return 0; |
| 2704 | } |
| 2705 | |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 2706 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) |
| 2707 | { |
| 2708 | struct sd *sd = (struct sd *) gspca_dev; |
| 2709 | |
| 2710 | sd->hflip = val; |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2711 | if (gspca_dev->streaming) |
| 2712 | sethvflip(sd); |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 2713 | return 0; |
| 2714 | } |
| 2715 | |
| 2716 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 2717 | { |
| 2718 | struct sd *sd = (struct sd *) gspca_dev; |
| 2719 | |
| 2720 | *val = sd->hflip; |
| 2721 | return 0; |
| 2722 | } |
| 2723 | |
| 2724 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) |
| 2725 | { |
| 2726 | struct sd *sd = (struct sd *) gspca_dev; |
| 2727 | |
| 2728 | sd->vflip = val; |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2729 | if (gspca_dev->streaming) |
| 2730 | sethvflip(sd); |
Jean-Francois Moine | 0cd6759 | 2008-07-29 05:25:28 -0300 | [diff] [blame] | 2731 | return 0; |
| 2732 | } |
| 2733 | |
| 2734 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 2735 | { |
| 2736 | struct sd *sd = (struct sd *) gspca_dev; |
| 2737 | |
| 2738 | *val = sd->vflip; |
| 2739 | return 0; |
| 2740 | } |
| 2741 | |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 2742 | static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 2743 | { |
| 2744 | struct sd *sd = (struct sd *) gspca_dev; |
| 2745 | |
| 2746 | sd->autobrightness = val; |
| 2747 | if (gspca_dev->streaming) |
| 2748 | setautobrightness(sd); |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
| 2752 | static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 2753 | { |
| 2754 | struct sd *sd = (struct sd *) gspca_dev; |
| 2755 | |
| 2756 | *val = sd->autobrightness; |
| 2757 | return 0; |
| 2758 | } |
| 2759 | |
| 2760 | static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val) |
| 2761 | { |
| 2762 | struct sd *sd = (struct sd *) gspca_dev; |
| 2763 | |
| 2764 | sd->freq = val; |
| 2765 | if (gspca_dev->streaming) |
| 2766 | setfreq(sd); |
| 2767 | return 0; |
| 2768 | } |
| 2769 | |
| 2770 | static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) |
| 2771 | { |
| 2772 | struct sd *sd = (struct sd *) gspca_dev; |
| 2773 | |
| 2774 | *val = sd->freq; |
| 2775 | return 0; |
| 2776 | } |
| 2777 | |
| 2778 | static int sd_querymenu(struct gspca_dev *gspca_dev, |
| 2779 | struct v4l2_querymenu *menu) |
| 2780 | { |
| 2781 | struct sd *sd = (struct sd *) gspca_dev; |
| 2782 | |
| 2783 | switch (menu->id) { |
| 2784 | case V4L2_CID_POWER_LINE_FREQUENCY: |
| 2785 | switch (menu->index) { |
| 2786 | case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ |
| 2787 | strcpy((char *) menu->name, "NoFliker"); |
| 2788 | return 0; |
| 2789 | case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ |
| 2790 | strcpy((char *) menu->name, "50 Hz"); |
| 2791 | return 0; |
| 2792 | case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ |
| 2793 | strcpy((char *) menu->name, "60 Hz"); |
| 2794 | return 0; |
| 2795 | case 3: |
| 2796 | if (sd->sensor != SEN_OV7670) |
| 2797 | return -EINVAL; |
| 2798 | |
| 2799 | strcpy((char *) menu->name, "Automatic"); |
| 2800 | return 0; |
| 2801 | } |
| 2802 | break; |
| 2803 | } |
| 2804 | return -EINVAL; |
| 2805 | } |
| 2806 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2807 | /* sub-driver description */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 2808 | static const struct sd_desc sd_desc = { |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2809 | .name = MODULE_NAME, |
| 2810 | .ctrls = sd_ctrls, |
| 2811 | .nctrls = ARRAY_SIZE(sd_ctrls), |
| 2812 | .config = sd_config, |
Jean-Francois Moine | 012d6b0 | 2008-09-03 17:12:16 -0300 | [diff] [blame] | 2813 | .init = sd_init, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2814 | .start = sd_start, |
| 2815 | .stopN = sd_stopN, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2816 | .pkt_scan = sd_pkt_scan, |
Hans de Goede | 02ab18b | 2009-06-14 04:32:04 -0300 | [diff] [blame] | 2817 | .querymenu = sd_querymenu, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2818 | }; |
| 2819 | |
| 2820 | /* -- module initialisation -- */ |
Jean-Francois Moine | a5ae206 | 2008-07-04 11:16:16 -0300 | [diff] [blame] | 2821 | static const __devinitdata struct usb_device_id device_table[] = { |
Hans de Goede | 49809d6 | 2009-06-07 12:10:39 -0300 | [diff] [blame] | 2822 | {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 }, |
| 2823 | {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 }, |
| 2824 | {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 }, |
| 2825 | {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 }, |
| 2826 | {USB_DEVICE(0x041e, 0x4064), .driver_info = BRIDGE_OV519 }, |
| 2827 | {USB_DEVICE(0x041e, 0x4068), .driver_info = BRIDGE_OV519 }, |
| 2828 | {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 }, |
| 2829 | {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 }, |
| 2830 | {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 }, |
| 2831 | {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 }, |
| 2832 | {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 }, |
| 2833 | {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 }, |
| 2834 | {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 }, |
| 2835 | {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 }, |
| 2836 | {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS }, |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2837 | {} |
| 2838 | }; |
Jean-Francois Moine | ac40b1f | 2008-11-08 06:03:37 -0300 | [diff] [blame] | 2839 | |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2840 | MODULE_DEVICE_TABLE(usb, device_table); |
| 2841 | |
| 2842 | /* -- device connect -- */ |
| 2843 | static int sd_probe(struct usb_interface *intf, |
| 2844 | const struct usb_device_id *id) |
| 2845 | { |
| 2846 | return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), |
| 2847 | THIS_MODULE); |
| 2848 | } |
| 2849 | |
| 2850 | static struct usb_driver sd_driver = { |
| 2851 | .name = MODULE_NAME, |
| 2852 | .id_table = device_table, |
| 2853 | .probe = sd_probe, |
| 2854 | .disconnect = gspca_disconnect, |
Jean-Francois Moine | 6a70974 | 2008-09-03 16:48:10 -0300 | [diff] [blame] | 2855 | #ifdef CONFIG_PM |
| 2856 | .suspend = gspca_suspend, |
| 2857 | .resume = gspca_resume, |
| 2858 | #endif |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2859 | }; |
| 2860 | |
| 2861 | /* -- module insert / remove -- */ |
| 2862 | static int __init sd_mod_init(void) |
| 2863 | { |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 2864 | int ret; |
| 2865 | ret = usb_register(&sd_driver); |
| 2866 | if (ret < 0) |
Alexey Klimov | e6b1484 | 2009-01-01 13:04:58 -0300 | [diff] [blame] | 2867 | return ret; |
Jean-Francois Moine | 10b0e96 | 2008-07-22 05:35:10 -0300 | [diff] [blame] | 2868 | PDEBUG(D_PROBE, "registered"); |
Jean-Francois Moine | 6a7eba2 | 2008-06-30 15:50:11 -0300 | [diff] [blame] | 2869 | return 0; |
| 2870 | } |
| 2871 | static void __exit sd_mod_exit(void) |
| 2872 | { |
| 2873 | usb_deregister(&sd_driver); |
| 2874 | PDEBUG(D_PROBE, "deregistered"); |
| 2875 | } |
| 2876 | |
| 2877 | module_init(sd_mod_init); |
| 2878 | module_exit(sd_mod_exit); |
| 2879 | |
| 2880 | module_param(frame_rate, int, 0644); |
| 2881 | MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)"); |