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