Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1 | /* |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 2 | * ov534 gspca driver |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 3 | * |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 4 | * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it> |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 5 | * Copyright (C) 2008 Jim Paris <jim@jtan.com> |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 6 | * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 7 | * |
| 8 | * Based on a prototype written by Mark Ferrell <majortrips@gmail.com> |
| 9 | * USB protocol reverse engineered by Jim Paris <jim@jtan.com> |
| 10 | * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/ |
| 11 | * |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 12 | * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 13 | * PS3 Eye camera, brightness, contrast, hue, AWB control added |
| 14 | * by Max Thrun <bear24rw@gmail.com> |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 15 | * |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 | */ |
| 30 | |
| 31 | #define MODULE_NAME "ov534" |
| 32 | |
| 33 | #include "gspca.h" |
| 34 | |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 35 | #define OV534_REG_ADDRESS 0xf1 /* sensor address */ |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 36 | #define OV534_REG_SUBADDR 0xf2 |
| 37 | #define OV534_REG_WRITE 0xf3 |
| 38 | #define OV534_REG_READ 0xf4 |
| 39 | #define OV534_REG_OPERATION 0xf5 |
| 40 | #define OV534_REG_STATUS 0xf6 |
| 41 | |
| 42 | #define OV534_OP_WRITE_3 0x37 |
| 43 | #define OV534_OP_WRITE_2 0x33 |
| 44 | #define OV534_OP_READ_2 0xf9 |
| 45 | |
| 46 | #define CTRL_TIMEOUT 500 |
| 47 | |
| 48 | MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>"); |
| 49 | MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver"); |
| 50 | MODULE_LICENSE("GPL"); |
| 51 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 52 | /* specific webcam descriptor */ |
| 53 | struct sd { |
| 54 | struct gspca_dev gspca_dev; /* !! must be the first item */ |
Jean-Francois Moine | 8c25205 | 2008-12-04 05:06:08 -0300 | [diff] [blame] | 55 | __u32 last_pts; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 56 | u16 last_fid; |
| 57 | u8 frame_rate; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 58 | |
| 59 | u8 brightness; |
| 60 | u8 contrast; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 61 | u8 gain; |
| 62 | u8 exposure; |
| 63 | u8 redblc; |
| 64 | u8 blueblc; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 65 | u8 hue; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 66 | u8 autogain; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 67 | u8 awb; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 68 | u8 sharpness; |
| 69 | u8 hflip; |
| 70 | u8 vflip; |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 71 | |
| 72 | u8 sensor; |
| 73 | #define SENSOR_OV772X 0 |
| 74 | #define SENSOR_OV965X 1 |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* V4L2 controls supported by the driver */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 78 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); |
| 79 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); |
| 80 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); |
| 81 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); |
| 82 | static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val); |
| 83 | static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val); |
| 84 | static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val); |
| 85 | static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val); |
| 86 | static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); |
| 87 | static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); |
| 88 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); |
| 89 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); |
| 90 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); |
| 91 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); |
| 92 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); |
| 93 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 94 | static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val); |
| 95 | static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val); |
| 96 | static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val); |
| 97 | static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val); |
| 98 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); |
| 99 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); |
| 100 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); |
| 101 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 102 | |
| 103 | static struct ctrl sd_ctrls_ov772x[] = { |
| 104 | { |
| 105 | { |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 106 | .id = V4L2_CID_BRIGHTNESS, |
| 107 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 108 | .name = "Brightness", |
| 109 | .minimum = 0, |
| 110 | .maximum = 255, |
| 111 | .step = 1, |
| 112 | #define BRIGHTNESS_DEF 20 |
| 113 | .default_value = BRIGHTNESS_DEF, |
| 114 | }, |
| 115 | .set = sd_setbrightness, |
| 116 | .get = sd_getbrightness, |
| 117 | }, |
| 118 | { |
| 119 | { |
| 120 | .id = V4L2_CID_CONTRAST, |
| 121 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 122 | .name = "Contrast", |
| 123 | .minimum = 0, |
| 124 | .maximum = 255, |
| 125 | .step = 1, |
| 126 | #define CONTRAST_DEF 37 |
| 127 | .default_value = CONTRAST_DEF, |
| 128 | }, |
| 129 | .set = sd_setcontrast, |
| 130 | .get = sd_getcontrast, |
| 131 | }, |
| 132 | { |
| 133 | { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 134 | .id = V4L2_CID_GAIN, |
| 135 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 136 | .name = "Main Gain", |
| 137 | .minimum = 0, |
| 138 | .maximum = 63, |
| 139 | .step = 1, |
| 140 | #define GAIN_DEF 20 |
| 141 | .default_value = GAIN_DEF, |
| 142 | }, |
| 143 | .set = sd_setgain, |
| 144 | .get = sd_getgain, |
| 145 | }, |
| 146 | { |
| 147 | { |
| 148 | .id = V4L2_CID_EXPOSURE, |
| 149 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 150 | .name = "Exposure", |
| 151 | .minimum = 0, |
| 152 | .maximum = 255, |
| 153 | .step = 1, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 154 | #define EXPO_DEF 120 |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 155 | .default_value = EXPO_DEF, |
| 156 | }, |
| 157 | .set = sd_setexposure, |
| 158 | .get = sd_getexposure, |
| 159 | }, |
| 160 | { |
| 161 | { |
| 162 | .id = V4L2_CID_RED_BALANCE, |
| 163 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 164 | .name = "Red Balance", |
| 165 | .minimum = 0, |
| 166 | .maximum = 255, |
| 167 | .step = 1, |
| 168 | #define RED_BALANCE_DEF 128 |
| 169 | .default_value = RED_BALANCE_DEF, |
| 170 | }, |
| 171 | .set = sd_setredblc, |
| 172 | .get = sd_getredblc, |
| 173 | }, |
| 174 | { |
| 175 | { |
| 176 | .id = V4L2_CID_BLUE_BALANCE, |
| 177 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 178 | .name = "Blue Balance", |
| 179 | .minimum = 0, |
| 180 | .maximum = 255, |
| 181 | .step = 1, |
| 182 | #define BLUE_BALANCE_DEF 128 |
| 183 | .default_value = BLUE_BALANCE_DEF, |
| 184 | }, |
| 185 | .set = sd_setblueblc, |
| 186 | .get = sd_getblueblc, |
| 187 | }, |
| 188 | { |
| 189 | { |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 190 | .id = V4L2_CID_HUE, |
| 191 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 192 | .name = "Hue", |
| 193 | .minimum = 0, |
| 194 | .maximum = 255, |
| 195 | .step = 1, |
| 196 | #define HUE_DEF 143 |
| 197 | .default_value = HUE_DEF, |
| 198 | }, |
| 199 | .set = sd_sethue, |
| 200 | .get = sd_gethue, |
| 201 | }, |
| 202 | { |
| 203 | { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 204 | .id = V4L2_CID_AUTOGAIN, |
| 205 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 206 | .name = "Autogain", |
| 207 | .minimum = 0, |
| 208 | .maximum = 1, |
| 209 | .step = 1, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 210 | #define AUTOGAIN_DEF 0 |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 211 | .default_value = AUTOGAIN_DEF, |
| 212 | }, |
| 213 | .set = sd_setautogain, |
| 214 | .get = sd_getautogain, |
| 215 | }, |
| 216 | { |
| 217 | { |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 218 | .id = V4L2_CID_AUTO_WHITE_BALANCE, |
| 219 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 220 | .name = "Auto White Balance", |
| 221 | .minimum = 0, |
| 222 | .maximum = 1, |
| 223 | .step = 1, |
| 224 | #define AWB_DEF 0 |
| 225 | .default_value = AWB_DEF, |
| 226 | }, |
| 227 | .set = sd_setawb, |
| 228 | .get = sd_getawb, |
| 229 | }, |
| 230 | { |
| 231 | { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 232 | .id = V4L2_CID_SHARPNESS, |
| 233 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 234 | .name = "Sharpness", |
| 235 | .minimum = 0, |
| 236 | .maximum = 63, |
| 237 | .step = 1, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 238 | #define SHARPNESS_DEF 0 |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 239 | .default_value = SHARPNESS_DEF, |
| 240 | }, |
| 241 | .set = sd_setsharpness, |
| 242 | .get = sd_getsharpness, |
| 243 | }, |
| 244 | { |
| 245 | { |
| 246 | .id = V4L2_CID_HFLIP, |
| 247 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 248 | .name = "HFlip", |
| 249 | .minimum = 0, |
| 250 | .maximum = 1, |
| 251 | .step = 1, |
| 252 | #define HFLIP_DEF 0 |
| 253 | .default_value = HFLIP_DEF, |
| 254 | }, |
| 255 | .set = sd_sethflip, |
| 256 | .get = sd_gethflip, |
| 257 | }, |
| 258 | { |
| 259 | { |
| 260 | .id = V4L2_CID_VFLIP, |
| 261 | .type = V4L2_CTRL_TYPE_BOOLEAN, |
| 262 | .name = "VFlip", |
| 263 | .minimum = 0, |
| 264 | .maximum = 1, |
| 265 | .step = 1, |
| 266 | #define VFLIP_DEF 0 |
| 267 | .default_value = VFLIP_DEF, |
| 268 | }, |
| 269 | .set = sd_setvflip, |
| 270 | .get = sd_getvflip, |
| 271 | }, |
| 272 | }; |
| 273 | static struct ctrl sd_ctrls_ov965x[] = { |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 274 | }; |
| 275 | |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 276 | static const struct v4l2_pix_format vga_yuyv_mode[] = { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 277 | {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, |
| 278 | .bytesperline = 320 * 2, |
| 279 | .sizeimage = 320 * 240 * 2, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 280 | .colorspace = V4L2_COLORSPACE_SRGB, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 281 | .priv = 1}, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 282 | {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, |
| 283 | .bytesperline = 640 * 2, |
| 284 | .sizeimage = 640 * 480 * 2, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 285 | .colorspace = V4L2_COLORSPACE_SRGB, |
| 286 | .priv = 0}, |
| 287 | }; |
| 288 | |
| 289 | static const struct v4l2_pix_format vga_jpeg_mode[] = { |
| 290 | {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 291 | .bytesperline = 320, |
| 292 | .sizeimage = 320 * 240 * 3 / 8 + 590, |
| 293 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 294 | .priv = 1}, |
| 295 | {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, |
| 296 | .bytesperline = 640, |
| 297 | .sizeimage = 640 * 480 * 3 / 8 + 590, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 298 | .colorspace = V4L2_COLORSPACE_JPEG, |
| 299 | .priv = 0}, |
| 300 | }; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 301 | static const u8 bridge_init_ov772x[][2] = { |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 302 | { 0xc2, 0x0c }, |
| 303 | { 0x88, 0xf8 }, |
| 304 | { 0xc3, 0x69 }, |
| 305 | { 0x89, 0xff }, |
| 306 | { 0x76, 0x03 }, |
| 307 | { 0x92, 0x01 }, |
| 308 | { 0x93, 0x18 }, |
| 309 | { 0x94, 0x10 }, |
| 310 | { 0x95, 0x10 }, |
| 311 | { 0xe2, 0x00 }, |
| 312 | { 0xe7, 0x3e }, |
| 313 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 314 | { 0x96, 0x00 }, |
| 315 | |
| 316 | { 0x97, 0x20 }, |
| 317 | { 0x97, 0x20 }, |
| 318 | { 0x97, 0x20 }, |
| 319 | { 0x97, 0x0a }, |
| 320 | { 0x97, 0x3f }, |
| 321 | { 0x97, 0x4a }, |
| 322 | { 0x97, 0x20 }, |
| 323 | { 0x97, 0x15 }, |
| 324 | { 0x97, 0x0b }, |
| 325 | |
| 326 | { 0x8e, 0x40 }, |
| 327 | { 0x1f, 0x81 }, |
| 328 | { 0x34, 0x05 }, |
| 329 | { 0xe3, 0x04 }, |
| 330 | { 0x88, 0x00 }, |
| 331 | { 0x89, 0x00 }, |
| 332 | { 0x76, 0x00 }, |
| 333 | { 0xe7, 0x2e }, |
| 334 | { 0x31, 0xf9 }, |
| 335 | { 0x25, 0x42 }, |
| 336 | { 0x21, 0xf0 }, |
| 337 | |
| 338 | { 0x1c, 0x00 }, |
| 339 | { 0x1d, 0x40 }, |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 340 | { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */ |
| 341 | { 0x1d, 0x00 }, /* payload size */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 342 | |
Jim Paris | 5ea9c4d | 2008-12-04 04:36:14 -0300 | [diff] [blame] | 343 | { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */ |
| 344 | { 0x1d, 0x58 }, /* frame size */ |
| 345 | { 0x1d, 0x00 }, /* frame size */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 346 | |
Jim Paris | c06eb61 | 2008-12-10 05:47:44 -0300 | [diff] [blame] | 347 | { 0x1c, 0x0a }, |
| 348 | { 0x1d, 0x08 }, /* turn on UVC header */ |
| 349 | { 0x1d, 0x0e }, /* .. */ |
| 350 | |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 351 | { 0x8d, 0x1c }, |
| 352 | { 0x8e, 0x80 }, |
| 353 | { 0xe5, 0x04 }, |
| 354 | |
| 355 | { 0xc0, 0x50 }, |
| 356 | { 0xc1, 0x3c }, |
| 357 | { 0xc2, 0x0c }, |
| 358 | }; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 359 | static const u8 sensor_init_ov772x[][2] = { |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 360 | { 0x12, 0x80 }, |
| 361 | { 0x11, 0x01 }, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 362 | /*fixme: better have a delay?*/ |
| 363 | { 0x11, 0x01 }, |
| 364 | { 0x11, 0x01 }, |
| 365 | { 0x11, 0x01 }, |
| 366 | { 0x11, 0x01 }, |
| 367 | { 0x11, 0x01 }, |
| 368 | { 0x11, 0x01 }, |
| 369 | { 0x11, 0x01 }, |
| 370 | { 0x11, 0x01 }, |
| 371 | { 0x11, 0x01 }, |
| 372 | { 0x11, 0x01 }, |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 373 | |
| 374 | { 0x3d, 0x03 }, |
| 375 | { 0x17, 0x26 }, |
| 376 | { 0x18, 0xa0 }, |
| 377 | { 0x19, 0x07 }, |
| 378 | { 0x1a, 0xf0 }, |
| 379 | { 0x32, 0x00 }, |
| 380 | { 0x29, 0xa0 }, |
| 381 | { 0x2c, 0xf0 }, |
| 382 | { 0x65, 0x20 }, |
| 383 | { 0x11, 0x01 }, |
| 384 | { 0x42, 0x7f }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 385 | { 0x63, 0xaa }, /* AWB - was e0 */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 386 | { 0x64, 0xff }, |
| 387 | { 0x66, 0x00 }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 388 | { 0x13, 0xf0 }, /* com8 */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 389 | { 0x0d, 0x41 }, |
| 390 | { 0x0f, 0xc5 }, |
| 391 | { 0x14, 0x11 }, |
| 392 | |
| 393 | { 0x22, 0x7f }, |
| 394 | { 0x23, 0x03 }, |
| 395 | { 0x24, 0x40 }, |
| 396 | { 0x25, 0x30 }, |
| 397 | { 0x26, 0xa1 }, |
| 398 | { 0x2a, 0x00 }, |
| 399 | { 0x2b, 0x00 }, |
| 400 | { 0x6b, 0xaa }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 401 | { 0x13, 0xff }, /* AWB */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 402 | |
| 403 | { 0x90, 0x05 }, |
| 404 | { 0x91, 0x01 }, |
| 405 | { 0x92, 0x03 }, |
| 406 | { 0x93, 0x00 }, |
| 407 | { 0x94, 0x60 }, |
| 408 | { 0x95, 0x3c }, |
| 409 | { 0x96, 0x24 }, |
| 410 | { 0x97, 0x1e }, |
| 411 | { 0x98, 0x62 }, |
| 412 | { 0x99, 0x80 }, |
| 413 | { 0x9a, 0x1e }, |
| 414 | { 0x9b, 0x08 }, |
| 415 | { 0x9c, 0x20 }, |
| 416 | { 0x9e, 0x81 }, |
| 417 | |
| 418 | { 0xa6, 0x04 }, |
| 419 | { 0x7e, 0x0c }, |
| 420 | { 0x7f, 0x16 }, |
| 421 | { 0x80, 0x2a }, |
| 422 | { 0x81, 0x4e }, |
| 423 | { 0x82, 0x61 }, |
| 424 | { 0x83, 0x6f }, |
| 425 | { 0x84, 0x7b }, |
| 426 | { 0x85, 0x86 }, |
| 427 | { 0x86, 0x8e }, |
| 428 | { 0x87, 0x97 }, |
| 429 | { 0x88, 0xa4 }, |
| 430 | { 0x89, 0xaf }, |
| 431 | { 0x8a, 0xc5 }, |
| 432 | { 0x8b, 0xd7 }, |
| 433 | { 0x8c, 0xe8 }, |
| 434 | { 0x8d, 0x20 }, |
| 435 | |
| 436 | { 0x0c, 0x90 }, |
| 437 | |
| 438 | { 0x2b, 0x00 }, |
| 439 | { 0x22, 0x7f }, |
| 440 | { 0x23, 0x03 }, |
| 441 | { 0x11, 0x01 }, |
| 442 | { 0x0c, 0xd0 }, |
| 443 | { 0x64, 0xff }, |
| 444 | { 0x0d, 0x41 }, |
| 445 | |
| 446 | { 0x14, 0x41 }, |
| 447 | { 0x0e, 0xcd }, |
| 448 | { 0xac, 0xbf }, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 449 | { 0x8e, 0x00 }, /* De-noise threshold */ |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 450 | { 0x0c, 0xd0 } |
| 451 | }; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 452 | static const u8 bridge_start_ov772x_vga[][2] = { |
| 453 | {0x1c, 0x00}, |
| 454 | {0x1d, 0x40}, |
| 455 | {0x1d, 0x02}, |
| 456 | {0x1d, 0x00}, |
| 457 | {0x1d, 0x02}, |
| 458 | {0x1d, 0x58}, |
| 459 | {0x1d, 0x00}, |
| 460 | {0xc0, 0x50}, |
| 461 | {0xc1, 0x3c}, |
| 462 | }; |
| 463 | static const u8 sensor_start_ov772x_vga[][2] = { |
| 464 | {0x12, 0x00}, |
| 465 | {0x17, 0x26}, |
| 466 | {0x18, 0xa0}, |
| 467 | {0x19, 0x07}, |
| 468 | {0x1a, 0xf0}, |
| 469 | {0x29, 0xa0}, |
| 470 | {0x2c, 0xf0}, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 471 | {0x65, 0x20}, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 472 | }; |
| 473 | static const u8 bridge_start_ov772x_qvga[][2] = { |
| 474 | {0x1c, 0x00}, |
| 475 | {0x1d, 0x40}, |
| 476 | {0x1d, 0x02}, |
| 477 | {0x1d, 0x00}, |
| 478 | {0x1d, 0x01}, |
| 479 | {0x1d, 0x4b}, |
| 480 | {0x1d, 0x00}, |
| 481 | {0xc0, 0x28}, |
| 482 | {0xc1, 0x1e}, |
| 483 | }; |
| 484 | static const u8 sensor_start_ov772x_qvga[][2] = { |
| 485 | {0x12, 0x40}, |
| 486 | {0x17, 0x3f}, |
| 487 | {0x18, 0x50}, |
| 488 | {0x19, 0x03}, |
| 489 | {0x1a, 0x78}, |
| 490 | {0x29, 0x50}, |
| 491 | {0x2c, 0x78}, |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 492 | {0x65, 0x2f}, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 493 | }; |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 494 | |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 495 | static const u8 bridge_init_ov965x[][2] = { |
| 496 | {0x88, 0xf8}, |
| 497 | {0x89, 0xff}, |
| 498 | {0x76, 0x03}, |
| 499 | {0x92, 0x03}, |
| 500 | {0x95, 0x10}, |
| 501 | {0xe2, 0x00}, |
| 502 | {0xe7, 0x3e}, |
| 503 | {0x8d, 0x1c}, |
| 504 | {0x8e, 0x00}, |
| 505 | {0x8f, 0x00}, |
| 506 | {0x1f, 0x00}, |
| 507 | {0xc3, 0xf9}, |
| 508 | {0x89, 0xff}, |
| 509 | {0x88, 0xf8}, |
| 510 | {0x76, 0x03}, |
| 511 | {0x92, 0x01}, |
| 512 | {0x93, 0x18}, |
| 513 | {0x1c, 0x0a}, |
| 514 | {0x1d, 0x48}, |
| 515 | {0xc0, 0x50}, |
| 516 | {0xc1, 0x3c}, |
| 517 | {0x34, 0x05}, |
| 518 | {0xc2, 0x0c}, |
| 519 | {0xc3, 0xf9}, |
| 520 | {0x34, 0x05}, |
| 521 | {0xe7, 0x2e}, |
| 522 | {0x31, 0xf9}, |
| 523 | {0x35, 0x02}, |
| 524 | {0xd9, 0x10}, |
| 525 | {0x25, 0x42}, |
| 526 | {0x94, 0x11}, |
| 527 | }; |
| 528 | |
| 529 | static const u8 sensor_init_ov965x[][2] = { |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 530 | {0x12, 0x80}, /* com7 - SSCB reset */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 531 | {0x00, 0x00}, /* gain */ |
| 532 | {0x01, 0x80}, /* blue */ |
| 533 | {0x02, 0x80}, /* red */ |
| 534 | {0x03, 0x1b}, /* vref */ |
| 535 | {0x04, 0x03}, /* com1 - exposure low bits */ |
| 536 | {0x0b, 0x57}, /* ver */ |
| 537 | {0x0e, 0x61}, /* com5 */ |
| 538 | {0x0f, 0x42}, /* com6 */ |
| 539 | {0x11, 0x00}, /* clkrc */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 540 | {0x12, 0x02}, /* com7 - 15fps VGA YUYV */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 541 | {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ |
| 542 | {0x14, 0x28}, /* com9 */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 543 | {0x16, 0x24}, /* reg16 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 544 | {0x17, 0x1d}, /* hstart*/ |
| 545 | {0x18, 0xbd}, /* hstop */ |
| 546 | {0x19, 0x01}, /* vstrt */ |
| 547 | {0x1a, 0x81}, /* vstop*/ |
| 548 | {0x1e, 0x04}, /* mvfp */ |
| 549 | {0x24, 0x3c}, /* aew */ |
| 550 | {0x25, 0x36}, /* aeb */ |
| 551 | {0x26, 0x71}, /* vpt */ |
| 552 | {0x27, 0x08}, /* bbias */ |
| 553 | {0x28, 0x08}, /* gbbias */ |
| 554 | {0x29, 0x15}, /* gr com */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 555 | {0x2a, 0x00}, /* exhch */ |
| 556 | {0x2b, 0x00}, /* exhcl */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 557 | {0x2c, 0x08}, /* rbias */ |
| 558 | {0x32, 0xff}, /* href */ |
| 559 | {0x33, 0x00}, /* chlf */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 560 | {0x34, 0x3f}, /* aref1 */ |
| 561 | {0x35, 0x00}, /* aref2 */ |
| 562 | {0x36, 0xf8}, /* aref3 */ |
| 563 | {0x38, 0x72}, /* adc2 */ |
| 564 | {0x39, 0x57}, /* aref4 */ |
| 565 | {0x3a, 0x80}, /* tslb - yuyv */ |
| 566 | {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 567 | {0x3d, 0x99}, /* com13 */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 568 | {0x3f, 0xc1}, /* edge */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 569 | {0x40, 0xc0}, /* com15 */ |
| 570 | {0x41, 0x40}, /* com16 */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 571 | {0x42, 0xc0}, /* com17 */ |
| 572 | {0x43, 0x0a}, /* rsvd */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 573 | {0x44, 0xf0}, |
| 574 | {0x45, 0x46}, |
| 575 | {0x46, 0x62}, |
| 576 | {0x47, 0x2a}, |
| 577 | {0x48, 0x3c}, |
| 578 | {0x4a, 0xfc}, |
| 579 | {0x4b, 0xfc}, |
| 580 | {0x4c, 0x7f}, |
| 581 | {0x4d, 0x7f}, |
| 582 | {0x4e, 0x7f}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 583 | {0x4f, 0x98}, /* matrix */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 584 | {0x50, 0x98}, |
| 585 | {0x51, 0x00}, |
| 586 | {0x52, 0x28}, |
| 587 | {0x53, 0x70}, |
| 588 | {0x54, 0x98}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 589 | {0x58, 0x1a}, /* matrix coef sign */ |
| 590 | {0x59, 0x85}, /* AWB control */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 591 | {0x5a, 0xa9}, |
| 592 | {0x5b, 0x64}, |
| 593 | {0x5c, 0x84}, |
| 594 | {0x5d, 0x53}, |
| 595 | {0x5e, 0x0e}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 596 | {0x5f, 0xf0}, /* AWB blue limit */ |
| 597 | {0x60, 0xf0}, /* AWB red limit */ |
| 598 | {0x61, 0xf0}, /* AWB green limit */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 599 | {0x62, 0x00}, /* lcc1 */ |
| 600 | {0x63, 0x00}, /* lcc2 */ |
| 601 | {0x64, 0x02}, /* lcc3 */ |
| 602 | {0x65, 0x16}, /* lcc4 */ |
| 603 | {0x66, 0x01}, /* lcc5 */ |
| 604 | {0x69, 0x02}, /* hv */ |
| 605 | {0x6b, 0x5a}, /* dbvl */ |
| 606 | {0x6c, 0x04}, |
| 607 | {0x6d, 0x55}, |
| 608 | {0x6e, 0x00}, |
| 609 | {0x6f, 0x9d}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 610 | {0x70, 0x21}, /* dnsth */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 611 | {0x71, 0x78}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 612 | {0x72, 0x00}, /* poidx */ |
| 613 | {0x73, 0x01}, /* pckdv */ |
| 614 | {0x74, 0x3a}, /* xindx */ |
| 615 | {0x75, 0x35}, /* yindx */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 616 | {0x76, 0x01}, |
| 617 | {0x77, 0x02}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 618 | {0x7a, 0x12}, /* gamma curve */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 619 | {0x7b, 0x08}, |
| 620 | {0x7c, 0x16}, |
| 621 | {0x7d, 0x30}, |
| 622 | {0x7e, 0x5e}, |
| 623 | {0x7f, 0x72}, |
| 624 | {0x80, 0x82}, |
| 625 | {0x81, 0x8e}, |
| 626 | {0x82, 0x9a}, |
| 627 | {0x83, 0xa4}, |
| 628 | {0x84, 0xac}, |
| 629 | {0x85, 0xb8}, |
| 630 | {0x86, 0xc3}, |
| 631 | {0x87, 0xd6}, |
| 632 | {0x88, 0xe6}, |
| 633 | {0x89, 0xf2}, |
| 634 | {0x8a, 0x03}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 635 | {0x8c, 0x89}, /* com19 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 636 | {0x14, 0x28}, /* com9 */ |
| 637 | {0x90, 0x7d}, |
| 638 | {0x91, 0x7b}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 639 | {0x9d, 0x03}, /* lcc6 */ |
| 640 | {0x9e, 0x04}, /* lcc7 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 641 | {0x9f, 0x7a}, |
| 642 | {0xa0, 0x79}, |
| 643 | {0xa1, 0x40}, /* aechm */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 644 | {0xa4, 0x50}, /* com21 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 645 | {0xa5, 0x68}, /* com26 */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 646 | {0xa6, 0x4a}, /* AWB green */ |
| 647 | {0xa8, 0xc1}, /* refa8 */ |
| 648 | {0xa9, 0xef}, /* refa9 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 649 | {0xaa, 0x92}, |
| 650 | {0xab, 0x04}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 651 | {0xac, 0x80}, /* black level control */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 652 | {0xad, 0x80}, |
| 653 | {0xae, 0x80}, |
| 654 | {0xaf, 0x80}, |
| 655 | {0xb2, 0xf2}, |
| 656 | {0xb3, 0x20}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 657 | {0xb4, 0x20}, /* ctrlb4 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 658 | {0xb5, 0x00}, |
| 659 | {0xb6, 0xaf}, |
| 660 | {0xbb, 0xae}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 661 | {0xbc, 0x7f}, /* ADC channel offsets */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 662 | {0xdb, 0x7f}, |
| 663 | {0xbe, 0x7f}, |
| 664 | {0xbf, 0x7f}, |
| 665 | {0xc0, 0xe2}, |
| 666 | {0xc1, 0xc0}, |
| 667 | {0xc2, 0x01}, |
| 668 | {0xc3, 0x4e}, |
| 669 | {0xc6, 0x85}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 670 | {0xc7, 0x80}, /* com24 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 671 | {0xc9, 0xe0}, |
| 672 | {0xca, 0xe8}, |
| 673 | {0xcb, 0xf0}, |
| 674 | {0xcc, 0xd8}, |
| 675 | {0xcd, 0xf1}, |
| 676 | {0x4f, 0x98}, |
| 677 | {0x50, 0x98}, |
| 678 | {0x51, 0x00}, |
| 679 | {0x52, 0x28}, |
| 680 | {0x53, 0x70}, |
| 681 | {0x54, 0x98}, |
| 682 | {0x58, 0x1a}, |
| 683 | {0xff, 0x41}, /* read 41, write ff 00 */ |
| 684 | {0x41, 0x40}, /* com16 */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 685 | {0xc5, 0x03}, /* 60 Hz banding filter */ |
| 686 | {0x6a, 0x02}, /* 50 Hz banding filter */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 687 | |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 688 | {0x12, 0x62}, /* com7 - 30fps VGA YUV */ |
| 689 | {0x36, 0xfa}, /* aref3 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 690 | {0x69, 0x0a}, /* hv */ |
| 691 | {0x8c, 0x89}, /* com22 */ |
| 692 | {0x14, 0x28}, /* com9 */ |
| 693 | {0x3e, 0x0c}, |
| 694 | {0x41, 0x40}, /* com16 */ |
| 695 | {0x72, 0x00}, |
| 696 | {0x73, 0x00}, |
| 697 | {0x74, 0x3a}, |
| 698 | {0x75, 0x35}, |
| 699 | {0x76, 0x01}, |
| 700 | {0xc7, 0x80}, |
| 701 | {0x03, 0x12}, /* vref */ |
| 702 | {0x17, 0x16}, /* hstart */ |
| 703 | {0x18, 0x02}, /* hstop */ |
| 704 | {0x19, 0x01}, /* vstrt */ |
| 705 | {0x1a, 0x3d}, /* vstop */ |
| 706 | {0x32, 0xff}, /* href */ |
| 707 | {0xc0, 0xaa}, |
| 708 | }; |
| 709 | |
| 710 | static const u8 bridge_init_ov965x_2[][2] = { |
| 711 | {0x94, 0xaa}, |
| 712 | {0xf1, 0x60}, |
| 713 | {0xe5, 0x04}, |
| 714 | {0xc0, 0x50}, |
| 715 | {0xc1, 0x3c}, |
| 716 | {0x8c, 0x00}, |
| 717 | {0x8d, 0x1c}, |
| 718 | {0x34, 0x05}, |
| 719 | |
| 720 | {0xc2, 0x0c}, |
| 721 | {0xc3, 0xf9}, |
| 722 | {0xda, 0x01}, |
| 723 | {0x50, 0x00}, |
| 724 | {0x51, 0xa0}, |
| 725 | {0x52, 0x3c}, |
| 726 | {0x53, 0x00}, |
| 727 | {0x54, 0x00}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 728 | {0x55, 0x00}, /* brightness */ |
| 729 | {0x57, 0x00}, /* contrast 2 */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 730 | {0x5c, 0x00}, |
| 731 | {0x5a, 0xa0}, |
| 732 | {0x5b, 0x78}, |
| 733 | {0x35, 0x02}, |
| 734 | {0xd9, 0x10}, |
| 735 | {0x94, 0x11}, |
| 736 | }; |
| 737 | |
| 738 | static const u8 sensor_init_ov965x_2[][2] = { |
| 739 | {0x3b, 0xc4}, |
| 740 | {0x1e, 0x04}, /* mvfp */ |
| 741 | {0x13, 0xe0}, /* com8 */ |
| 742 | {0x00, 0x00}, /* gain */ |
| 743 | {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ |
| 744 | {0x11, 0x03}, /* clkrc */ |
| 745 | {0x6b, 0x5a}, /* dblv */ |
| 746 | {0x6a, 0x05}, |
| 747 | {0xc5, 0x07}, |
| 748 | {0xa2, 0x4b}, |
| 749 | {0xa3, 0x3e}, |
| 750 | {0x2d, 0x00}, |
| 751 | {0xff, 0x42}, /* read 42, write ff 00 */ |
| 752 | {0x42, 0xc0}, |
| 753 | {0x2d, 0x00}, |
| 754 | {0xff, 0x42}, /* read 42, write ff 00 */ |
| 755 | {0x42, 0xc1}, |
| 756 | {0x3f, 0x01}, |
| 757 | {0xff, 0x42}, /* read 42, write ff 00 */ |
| 758 | {0x42, 0xc1}, |
| 759 | {0x4f, 0x98}, |
| 760 | {0x50, 0x98}, |
| 761 | {0x51, 0x00}, |
| 762 | {0x52, 0x28}, |
| 763 | {0x53, 0x70}, |
| 764 | {0x54, 0x98}, |
| 765 | {0x58, 0x1a}, |
| 766 | {0xff, 0x41}, /* read 41, write ff 00 */ |
| 767 | {0x41, 0x40}, /* com16 */ |
| 768 | {0x56, 0x40}, |
| 769 | {0x55, 0x8f}, |
| 770 | {0x10, 0x25}, /* aech - exposure high bits */ |
| 771 | {0xff, 0x13}, /* read 13, write ff 00 */ |
| 772 | {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ |
| 773 | }; |
| 774 | |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 775 | static const u8 sensor_start_ov965x[][2] = { |
| 776 | {0x12, 0x62}, /* com7 - 30fps VGA YUV */ |
| 777 | {0x36, 0xfa}, /* aref3 */ |
| 778 | {0x69, 0x0a}, /* hv */ |
| 779 | {0x8c, 0x89}, /* com22 */ |
| 780 | {0x14, 0x28}, /* com9 */ |
| 781 | {0x3e, 0x0c}, /* com14 */ |
| 782 | {0x41, 0x40}, /* com16 */ |
| 783 | {0x72, 0x00}, |
| 784 | {0x73, 0x00}, |
| 785 | {0x74, 0x3a}, |
| 786 | {0x75, 0x35}, |
| 787 | {0x76, 0x01}, |
| 788 | {0xc7, 0x80}, /* com24 */ |
| 789 | {0x03, 0x12}, /* vref */ |
| 790 | {0x17, 0x16}, /* hstart */ |
| 791 | {0x18, 0x02}, /* hstop */ |
| 792 | {0x19, 0x01}, /* vstrt */ |
| 793 | {0x1a, 0x3d}, /* vstop */ |
| 794 | {0x32, 0xff}, /* href */ |
| 795 | {0xc0, 0xaa}, |
| 796 | {} |
| 797 | }; |
| 798 | |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 799 | static const u8 bridge_start_ov965x[][2] = { |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 800 | {0x94, 0xaa}, |
| 801 | {0xf1, 0x60}, |
| 802 | {0xe5, 0x04}, |
| 803 | {0xc0, 0x50}, |
| 804 | {0xc1, 0x3c}, |
| 805 | {0x8c, 0x00}, |
| 806 | {0x8d, 0x1c}, |
| 807 | {0x34, 0x05}, |
| 808 | {} |
| 809 | }; |
| 810 | |
| 811 | static const u8 bridge_start_ov965x_vga[][2] = { |
| 812 | {0xc2, 0x0c}, |
| 813 | {0xc3, 0xf9}, |
| 814 | {0xda, 0x01}, |
| 815 | {0x50, 0x00}, |
| 816 | {0x51, 0xa0}, |
| 817 | {0x52, 0x3c}, |
| 818 | {0x53, 0x00}, |
| 819 | {0x54, 0x00}, |
| 820 | {0x55, 0x00}, |
| 821 | {0x57, 0x00}, |
| 822 | {0x5c, 0x00}, |
| 823 | {0x5a, 0xa0}, |
| 824 | {0x5b, 0x78}, |
| 825 | {0x35, 0x02}, |
| 826 | {0xd9, 0x10}, |
| 827 | {0x94, 0x11}, |
| 828 | {} |
| 829 | }; |
| 830 | |
| 831 | static const u8 bridge_start_ov965x_cif[][2] = { |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 832 | {0xc2, 0x4c}, |
| 833 | {0xc3, 0xf9}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 834 | {0xda, 0x00}, |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 835 | {0x50, 0x00}, |
| 836 | {0x51, 0xa0}, |
| 837 | {0x52, 0x78}, |
| 838 | {0x53, 0x00}, |
| 839 | {0x54, 0x00}, |
| 840 | {0x55, 0x00}, |
| 841 | {0x57, 0x00}, |
| 842 | {0x5c, 0x00}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 843 | {0x5a, 0x50}, |
| 844 | {0x5b, 0x3c}, |
| 845 | {0x35, 0x02}, |
| 846 | {0xd9, 0x10}, |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 847 | {0x94, 0x11}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 848 | {} |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 849 | }; |
| 850 | |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 851 | static const u8 sensor_start_ov965x_vga[][2] = { |
| 852 | {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ |
| 853 | {0x1e, 0x04}, /* mvfp */ |
| 854 | {0x13, 0xe0}, /* com8 */ |
| 855 | {0x00, 0x00}, |
| 856 | {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ |
| 857 | {0x11, 0x03}, /* clkrc */ |
| 858 | {0x6b, 0x5a}, /* dblv */ |
| 859 | {0x6a, 0x05}, /* 50 Hz banding filter */ |
| 860 | {0xc5, 0x07}, /* 60 Hz banding filter */ |
| 861 | {0xa2, 0x4b}, /* bd50 */ |
| 862 | {0xa3, 0x3e}, /* bd60 */ |
| 863 | |
| 864 | {0x2d, 0x00}, /* advfl */ |
| 865 | {} |
| 866 | }; |
| 867 | |
| 868 | static const u8 sensor_start_ov965x_cif[][2] = { |
| 869 | {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */ |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 870 | {0x1e, 0x04}, /* mvfp */ |
| 871 | {0x13, 0xe0}, /* com8 */ |
| 872 | {0x00, 0x00}, |
| 873 | {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ |
| 874 | {0x11, 0x01}, /* clkrc */ |
| 875 | {0x6b, 0x5a}, /* dblv */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 876 | {0x6a, 0x02}, /* 50 Hz banding filter */ |
| 877 | {0xc5, 0x03}, /* 60 Hz banding filter */ |
| 878 | {0xa2, 0x96}, /* bd50 */ |
| 879 | {0xa3, 0x7d}, /* bd60 */ |
| 880 | |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 881 | {0xff, 0x13}, /* read 13, write ff 00 */ |
| 882 | {0x13, 0xe7}, |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 883 | {0x3a, 0x80}, /* tslb - yuyv */ |
| 884 | {} |
| 885 | }; |
| 886 | |
| 887 | static const u8 sensor_start_ov965x_2[][2] = { |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 888 | {0xff, 0x42}, /* read 42, write ff 00 */ |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 889 | {0x42, 0xc1}, /* com17 - 50 Hz filter */ |
| 890 | {} |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 891 | }; |
| 892 | |
| 893 | |
| 894 | static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) |
| 895 | { |
| 896 | struct usb_device *udev = gspca_dev->dev; |
| 897 | int ret; |
| 898 | |
| 899 | PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val); |
| 900 | gspca_dev->usb_buf[0] = val; |
| 901 | ret = usb_control_msg(udev, |
| 902 | usb_sndctrlpipe(udev, 0), |
| 903 | 0x01, |
| 904 | USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 905 | 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); |
| 906 | if (ret < 0) |
| 907 | PDEBUG(D_ERR, "write failed"); |
| 908 | } |
| 909 | |
| 910 | static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg) |
| 911 | { |
| 912 | struct usb_device *udev = gspca_dev->dev; |
| 913 | int ret; |
| 914 | |
| 915 | ret = usb_control_msg(udev, |
| 916 | usb_rcvctrlpipe(udev, 0), |
| 917 | 0x01, |
| 918 | USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, |
| 919 | 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); |
| 920 | PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]); |
| 921 | if (ret < 0) |
| 922 | PDEBUG(D_ERR, "read failed"); |
| 923 | return gspca_dev->usb_buf[0]; |
| 924 | } |
| 925 | |
| 926 | /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7. |
| 927 | * (direction and output)? */ |
| 928 | static void ov534_set_led(struct gspca_dev *gspca_dev, int status) |
| 929 | { |
| 930 | u8 data; |
| 931 | |
| 932 | PDEBUG(D_CONF, "led status: %d", status); |
| 933 | |
| 934 | data = ov534_reg_read(gspca_dev, 0x21); |
| 935 | data |= 0x80; |
| 936 | ov534_reg_write(gspca_dev, 0x21, data); |
| 937 | |
| 938 | data = ov534_reg_read(gspca_dev, 0x23); |
| 939 | if (status) |
| 940 | data |= 0x80; |
| 941 | else |
| 942 | data &= ~0x80; |
| 943 | |
| 944 | ov534_reg_write(gspca_dev, 0x23, data); |
| 945 | |
| 946 | if (!status) { |
| 947 | data = ov534_reg_read(gspca_dev, 0x21); |
| 948 | data &= ~0x80; |
| 949 | ov534_reg_write(gspca_dev, 0x21, data); |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | static int sccb_check_status(struct gspca_dev *gspca_dev) |
| 954 | { |
| 955 | u8 data; |
| 956 | int i; |
| 957 | |
| 958 | for (i = 0; i < 5; i++) { |
| 959 | data = ov534_reg_read(gspca_dev, OV534_REG_STATUS); |
| 960 | |
| 961 | switch (data) { |
| 962 | case 0x00: |
| 963 | return 1; |
| 964 | case 0x04: |
| 965 | return 0; |
| 966 | case 0x03: |
| 967 | break; |
| 968 | default: |
| 969 | PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5", |
| 970 | data, i + 1); |
| 971 | } |
| 972 | } |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val) |
| 977 | { |
| 978 | PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val); |
| 979 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); |
| 980 | ov534_reg_write(gspca_dev, OV534_REG_WRITE, val); |
| 981 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3); |
| 982 | |
| 983 | if (!sccb_check_status(gspca_dev)) |
| 984 | PDEBUG(D_ERR, "sccb_reg_write failed"); |
| 985 | } |
| 986 | |
| 987 | static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg) |
| 988 | { |
| 989 | ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); |
| 990 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2); |
| 991 | if (!sccb_check_status(gspca_dev)) |
| 992 | PDEBUG(D_ERR, "sccb_reg_read failed 1"); |
| 993 | |
| 994 | ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2); |
| 995 | if (!sccb_check_status(gspca_dev)) |
| 996 | PDEBUG(D_ERR, "sccb_reg_read failed 2"); |
| 997 | |
| 998 | return ov534_reg_read(gspca_dev, OV534_REG_READ); |
| 999 | } |
| 1000 | |
| 1001 | /* output a bridge sequence (reg - val) */ |
| 1002 | static void reg_w_array(struct gspca_dev *gspca_dev, |
| 1003 | const u8 (*data)[2], int len) |
| 1004 | { |
| 1005 | while (--len >= 0) { |
| 1006 | ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]); |
| 1007 | data++; |
| 1008 | } |
| 1009 | } |
| 1010 | |
| 1011 | /* output a sensor sequence (reg - val) */ |
| 1012 | static void sccb_w_array(struct gspca_dev *gspca_dev, |
| 1013 | const u8 (*data)[2], int len) |
| 1014 | { |
| 1015 | while (--len >= 0) { |
| 1016 | if ((*data)[0] != 0xff) { |
| 1017 | sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]); |
| 1018 | } else { |
| 1019 | sccb_reg_read(gspca_dev, (*data)[1]); |
| 1020 | sccb_reg_write(gspca_dev, 0xff, 0x00); |
| 1021 | } |
| 1022 | data++; |
| 1023 | } |
| 1024 | } |
| 1025 | |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1026 | /* set framerate */ |
| 1027 | static void ov534_set_frame_rate(struct gspca_dev *gspca_dev) |
| 1028 | { |
| 1029 | struct sd *sd = (struct sd *) gspca_dev; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1030 | int i; |
| 1031 | struct rate_s { |
| 1032 | u8 fps; |
| 1033 | u8 r11; |
| 1034 | u8 r0d; |
| 1035 | u8 re5; |
| 1036 | }; |
| 1037 | const struct rate_s *r; |
| 1038 | static const struct rate_s rate_0[] = { /* 640x480 */ |
| 1039 | {60, 0x01, 0xc1, 0x04}, |
| 1040 | {50, 0x01, 0x41, 0x02}, |
| 1041 | {40, 0x02, 0xc1, 0x04}, |
| 1042 | {30, 0x04, 0x81, 0x02}, |
| 1043 | {15, 0x03, 0x41, 0x04}, |
| 1044 | }; |
| 1045 | static const struct rate_s rate_1[] = { /* 320x240 */ |
| 1046 | {125, 0x02, 0x81, 0x02}, |
| 1047 | {100, 0x02, 0xc1, 0x04}, |
| 1048 | {75, 0x03, 0xc1, 0x04}, |
| 1049 | {60, 0x04, 0xc1, 0x04}, |
| 1050 | {50, 0x02, 0x41, 0x04}, |
| 1051 | {40, 0x03, 0x41, 0x04}, |
| 1052 | {30, 0x04, 0x41, 0x04}, |
| 1053 | }; |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1054 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1055 | if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) { |
| 1056 | r = rate_0; |
| 1057 | i = ARRAY_SIZE(rate_0); |
| 1058 | } else { |
| 1059 | r = rate_1; |
| 1060 | i = ARRAY_SIZE(rate_1); |
| 1061 | } |
| 1062 | while (--i > 0) { |
| 1063 | if (sd->frame_rate >= r->fps) |
| 1064 | break; |
| 1065 | r++; |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1066 | } |
| 1067 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1068 | sccb_reg_write(gspca_dev, 0x11, r->r11); |
| 1069 | sccb_reg_write(gspca_dev, 0x0d, r->r0d); |
| 1070 | ov534_reg_write(gspca_dev, 0xe5, r->re5); |
| 1071 | |
| 1072 | PDEBUG(D_PROBE, "frame_rate: %d", r->fps); |
| 1073 | } |
| 1074 | |
| 1075 | /* ov772x controls */ |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1076 | static void setbrightness(struct gspca_dev *gspca_dev) |
| 1077 | { |
| 1078 | struct sd *sd = (struct sd *) gspca_dev; |
| 1079 | |
| 1080 | sccb_reg_write(gspca_dev, 0x9B, sd->brightness); |
| 1081 | } |
| 1082 | |
| 1083 | static void setcontrast(struct gspca_dev *gspca_dev) |
| 1084 | { |
| 1085 | struct sd *sd = (struct sd *) gspca_dev; |
| 1086 | |
| 1087 | sccb_reg_write(gspca_dev, 0x9C, sd->contrast); |
| 1088 | } |
| 1089 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1090 | static void setgain(struct gspca_dev *gspca_dev) |
| 1091 | { |
| 1092 | struct sd *sd = (struct sd *) gspca_dev; |
| 1093 | u8 val; |
| 1094 | |
| 1095 | val = sd->gain; |
| 1096 | switch (val & 0x30) { |
| 1097 | case 0x00: |
| 1098 | val &= 0x0f; |
| 1099 | break; |
| 1100 | case 0x10: |
| 1101 | val &= 0x0f; |
| 1102 | val |= 0x30; |
| 1103 | break; |
| 1104 | case 0x20: |
| 1105 | val &= 0x0f; |
| 1106 | val |= 0x70; |
| 1107 | break; |
| 1108 | default: |
| 1109 | /* case 0x30: */ |
| 1110 | val &= 0x0f; |
| 1111 | val |= 0xf0; |
| 1112 | break; |
| 1113 | } |
| 1114 | sccb_reg_write(gspca_dev, 0x00, val); |
| 1115 | } |
| 1116 | |
| 1117 | static void setexposure(struct gspca_dev *gspca_dev) |
| 1118 | { |
| 1119 | struct sd *sd = (struct sd *) gspca_dev; |
| 1120 | u8 val; |
| 1121 | |
| 1122 | val = sd->exposure; |
| 1123 | sccb_reg_write(gspca_dev, 0x08, val >> 7); |
| 1124 | sccb_reg_write(gspca_dev, 0x10, val << 1); |
| 1125 | } |
| 1126 | |
| 1127 | static void setredblc(struct gspca_dev *gspca_dev) |
| 1128 | { |
| 1129 | struct sd *sd = (struct sd *) gspca_dev; |
| 1130 | |
| 1131 | sccb_reg_write(gspca_dev, 0x43, sd->redblc); |
| 1132 | } |
| 1133 | |
| 1134 | static void setblueblc(struct gspca_dev *gspca_dev) |
| 1135 | { |
| 1136 | struct sd *sd = (struct sd *) gspca_dev; |
| 1137 | |
| 1138 | sccb_reg_write(gspca_dev, 0x42, sd->blueblc); |
| 1139 | } |
| 1140 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1141 | static void sethue(struct gspca_dev *gspca_dev) |
| 1142 | { |
| 1143 | struct sd *sd = (struct sd *) gspca_dev; |
| 1144 | |
| 1145 | sccb_reg_write(gspca_dev, 0x01, sd->hue); |
| 1146 | } |
| 1147 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1148 | static void setautogain(struct gspca_dev *gspca_dev) |
| 1149 | { |
| 1150 | struct sd *sd = (struct sd *) gspca_dev; |
| 1151 | |
| 1152 | if (sd->autogain) { |
| 1153 | sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */ |
| 1154 | sccb_reg_write(gspca_dev, 0x64, |
| 1155 | sccb_reg_read(gspca_dev, 0x64) | 0x03); |
| 1156 | } else { |
| 1157 | sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */ |
| 1158 | sccb_reg_write(gspca_dev, 0x64, |
| 1159 | sccb_reg_read(gspca_dev, 0x64) & 0xfc); |
| 1160 | } |
| 1161 | } |
| 1162 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1163 | static void setawb(struct gspca_dev *gspca_dev) |
| 1164 | { |
| 1165 | struct sd *sd = (struct sd *) gspca_dev; |
| 1166 | |
| 1167 | if (sd->awb) |
| 1168 | sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */ |
| 1169 | else |
| 1170 | sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */ |
| 1171 | } |
| 1172 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1173 | static void setsharpness(struct gspca_dev *gspca_dev) |
| 1174 | { |
| 1175 | struct sd *sd = (struct sd *) gspca_dev; |
| 1176 | u8 val; |
| 1177 | |
| 1178 | val = sd->sharpness; |
| 1179 | sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */ |
| 1180 | sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */ |
| 1181 | } |
| 1182 | |
| 1183 | static void sethflip(struct gspca_dev *gspca_dev) |
| 1184 | { |
| 1185 | struct sd *sd = (struct sd *) gspca_dev; |
| 1186 | |
| 1187 | if (sd->hflip == 0) |
| 1188 | sccb_reg_write(gspca_dev, 0x0c, |
| 1189 | sccb_reg_read(gspca_dev, 0x0c) | 0x40); |
| 1190 | else |
| 1191 | sccb_reg_write(gspca_dev, 0x0c, |
| 1192 | sccb_reg_read(gspca_dev, 0x0c) & 0xbf); |
| 1193 | } |
| 1194 | |
| 1195 | static void setvflip(struct gspca_dev *gspca_dev) |
| 1196 | { |
| 1197 | struct sd *sd = (struct sd *) gspca_dev; |
| 1198 | |
| 1199 | if (sd->vflip == 0) |
| 1200 | sccb_reg_write(gspca_dev, 0x0c, |
| 1201 | sccb_reg_read(gspca_dev, 0x0c) | 0x80); |
| 1202 | else |
| 1203 | sccb_reg_write(gspca_dev, 0x0c, |
| 1204 | sccb_reg_read(gspca_dev, 0x0c) & 0x7f); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1205 | } |
Jim Paris | 47dfd21 | 2008-12-04 04:28:27 -0300 | [diff] [blame] | 1206 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1207 | /* this function is called at probe time */ |
| 1208 | static int sd_config(struct gspca_dev *gspca_dev, |
| 1209 | const struct usb_device_id *id) |
| 1210 | { |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1211 | struct sd *sd = (struct sd *) gspca_dev; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1212 | struct cam *cam; |
| 1213 | |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1214 | sd->sensor = id->driver_info; |
| 1215 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1216 | cam = &gspca_dev->cam; |
| 1217 | |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 1218 | if (sd->sensor == SENSOR_OV772X) { |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 1219 | cam->cam_mode = vga_yuyv_mode; |
| 1220 | cam->nmodes = ARRAY_SIZE(vga_yuyv_mode); |
| 1221 | |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 1222 | cam->bulk = 1; |
| 1223 | cam->bulk_size = 16384; |
| 1224 | cam->bulk_nurbs = 2; |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 1225 | } else { /* ov965x */ |
| 1226 | cam->cam_mode = vga_jpeg_mode; |
| 1227 | cam->nmodes = ARRAY_SIZE(vga_jpeg_mode); |
Jean-Francois Moine | 6929dc6 | 2009-04-21 13:45:56 -0300 | [diff] [blame] | 1228 | } |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1229 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1230 | sd->frame_rate = 30; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1231 | |
| 1232 | sd->brightness = BRIGHTNESS_DEF; |
| 1233 | sd->contrast = CONTRAST_DEF; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1234 | sd->gain = GAIN_DEF; |
| 1235 | sd->exposure = EXPO_DEF; |
| 1236 | sd->redblc = RED_BALANCE_DEF; |
| 1237 | sd->blueblc = BLUE_BALANCE_DEF; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1238 | sd->hue = HUE_DEF; |
| 1239 | #if AUTOGAIN_DEF != 0 |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1240 | sd->autogain = AUTOGAIN_DEF; |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1241 | #endif |
| 1242 | #if AWB_DEF != 0 |
| 1243 | sd->awb = AWB_DEF |
| 1244 | #endif |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1245 | sd->sharpness = SHARPNESS_DEF; |
| 1246 | #if HFLIP_DEF != 0 |
| 1247 | sd->hflip = HFLIP_DEF; |
| 1248 | #endif |
| 1249 | #if VFLIP_DEF != 0 |
| 1250 | sd->vflip = VFLIP_DEF; |
| 1251 | #endif |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | /* this function is called at probe and resume time */ |
| 1256 | static int sd_init(struct gspca_dev *gspca_dev) |
| 1257 | { |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1258 | struct sd *sd = (struct sd *) gspca_dev; |
| 1259 | u16 sensor_id; |
| 1260 | static const u8 sensor_addr[2] = { |
| 1261 | 0x42, /* 0 SENSOR_OV772X */ |
| 1262 | 0x60, /* 1 SENSOR_OV965X */ |
| 1263 | }; |
| 1264 | |
| 1265 | /* reset bridge */ |
| 1266 | ov534_reg_write(gspca_dev, 0xe7, 0x3a); |
| 1267 | ov534_reg_write(gspca_dev, 0xe0, 0x08); |
| 1268 | msleep(100); |
| 1269 | |
| 1270 | /* initialize the sensor address */ |
| 1271 | ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, |
| 1272 | sensor_addr[sd->sensor]); |
| 1273 | |
| 1274 | /* reset sensor */ |
| 1275 | sccb_reg_write(gspca_dev, 0x12, 0x80); |
| 1276 | msleep(10); |
| 1277 | |
| 1278 | /* probe the sensor */ |
| 1279 | sccb_reg_read(gspca_dev, 0x0a); |
| 1280 | sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8; |
| 1281 | sccb_reg_read(gspca_dev, 0x0b); |
| 1282 | sensor_id |= sccb_reg_read(gspca_dev, 0x0b); |
| 1283 | PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id); |
| 1284 | |
| 1285 | /* initialize */ |
| 1286 | switch (sd->sensor) { |
| 1287 | case SENSOR_OV772X: |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1288 | reg_w_array(gspca_dev, bridge_init_ov772x, |
| 1289 | ARRAY_SIZE(bridge_init_ov772x)); |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1290 | ov534_set_led(gspca_dev, 1); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1291 | sccb_w_array(gspca_dev, sensor_init_ov772x, |
| 1292 | ARRAY_SIZE(sensor_init_ov772x)); |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1293 | ov534_reg_write(gspca_dev, 0xe0, 0x09); |
| 1294 | ov534_set_led(gspca_dev, 0); |
| 1295 | ov534_set_frame_rate(gspca_dev); |
| 1296 | break; |
| 1297 | default: |
| 1298 | /* case SENSOR_OV965X: */ |
| 1299 | reg_w_array(gspca_dev, bridge_init_ov965x, |
| 1300 | ARRAY_SIZE(bridge_init_ov965x)); |
| 1301 | sccb_w_array(gspca_dev, sensor_init_ov965x, |
| 1302 | ARRAY_SIZE(sensor_init_ov965x)); |
| 1303 | reg_w_array(gspca_dev, bridge_init_ov965x_2, |
| 1304 | ARRAY_SIZE(bridge_init_ov965x_2)); |
| 1305 | sccb_w_array(gspca_dev, sensor_init_ov965x_2, |
| 1306 | ARRAY_SIZE(sensor_init_ov965x_2)); |
| 1307 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
| 1308 | ov534_reg_write(gspca_dev, 0xe0, 0x01); |
| 1309 | ov534_set_led(gspca_dev, 0); |
| 1310 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
| 1311 | } |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1312 | |
| 1313 | return 0; |
| 1314 | } |
| 1315 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1316 | static int sd_start_ov772x(struct gspca_dev *gspca_dev) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1317 | { |
Jean-Francois Moine | 191d0e7 | 2009-05-22 04:16:42 -0300 | [diff] [blame] | 1318 | int mode; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1319 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1320 | mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; |
| 1321 | if (mode != 0) { /* 320x240 */ |
| 1322 | reg_w_array(gspca_dev, bridge_start_ov772x_qvga, |
| 1323 | ARRAY_SIZE(bridge_start_ov772x_qvga)); |
| 1324 | sccb_w_array(gspca_dev, sensor_start_ov772x_qvga, |
| 1325 | ARRAY_SIZE(sensor_start_ov772x_qvga)); |
| 1326 | } else { /* 640x480 */ |
| 1327 | reg_w_array(gspca_dev, bridge_start_ov772x_vga, |
| 1328 | ARRAY_SIZE(bridge_start_ov772x_vga)); |
| 1329 | sccb_w_array(gspca_dev, sensor_start_ov772x_vga, |
| 1330 | ARRAY_SIZE(sensor_start_ov772x_vga)); |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1331 | } |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1332 | ov534_set_frame_rate(gspca_dev); |
| 1333 | |
| 1334 | setautogain(gspca_dev); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1335 | setawb(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1336 | setgain(gspca_dev); |
| 1337 | setredblc(gspca_dev); |
| 1338 | setblueblc(gspca_dev); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1339 | sethue(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1340 | setexposure(gspca_dev); |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1341 | setbrightness(gspca_dev); |
| 1342 | setcontrast(gspca_dev); |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1343 | setsharpness(gspca_dev); |
| 1344 | setvflip(gspca_dev); |
| 1345 | sethflip(gspca_dev); |
| 1346 | |
| 1347 | ov534_set_led(gspca_dev, 1); |
| 1348 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1349 | return 0; |
| 1350 | } |
| 1351 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1352 | static int sd_start_ov965x(struct gspca_dev *gspca_dev) |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1353 | { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1354 | int mode; |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1355 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1356 | sccb_w_array(gspca_dev, sensor_start_ov965x, |
| 1357 | ARRAY_SIZE(sensor_start_ov965x)); |
| 1358 | reg_w_array(gspca_dev, bridge_start_ov965x, |
| 1359 | ARRAY_SIZE(bridge_start_ov965x)); |
| 1360 | |
| 1361 | mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; |
| 1362 | if (mode != 0) { /* 320x240 */ |
| 1363 | reg_w_array(gspca_dev, bridge_start_ov965x_cif, |
| 1364 | ARRAY_SIZE(bridge_start_ov965x_cif)); |
| 1365 | sccb_w_array(gspca_dev, sensor_start_ov965x_cif, |
| 1366 | ARRAY_SIZE(sensor_start_ov965x_cif)); |
| 1367 | } else { /* 640x480 */ |
| 1368 | reg_w_array(gspca_dev, bridge_start_ov965x_vga, |
| 1369 | ARRAY_SIZE(bridge_start_ov965x_vga)); |
| 1370 | sccb_w_array(gspca_dev, sensor_start_ov965x_vga, |
| 1371 | ARRAY_SIZE(sensor_start_ov965x_vga)); |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1372 | } |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1373 | sccb_w_array(gspca_dev, sensor_start_ov965x_2, |
| 1374 | ARRAY_SIZE(sensor_start_ov965x_2)); |
| 1375 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
| 1376 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
| 1377 | ov534_set_led(gspca_dev, 1); |
| 1378 | return 0; |
| 1379 | } |
| 1380 | |
| 1381 | static void sd_stopN_ov772x(struct gspca_dev *gspca_dev) |
| 1382 | { |
| 1383 | ov534_reg_write(gspca_dev, 0xe0, 0x09); |
| 1384 | ov534_set_led(gspca_dev, 0); |
| 1385 | } |
| 1386 | |
| 1387 | static void sd_stopN_ov965x(struct gspca_dev *gspca_dev) |
| 1388 | { |
| 1389 | ov534_reg_write(gspca_dev, 0xe0, 0x01); |
| 1390 | ov534_set_led(gspca_dev, 0); |
| 1391 | ov534_reg_write(gspca_dev, 0xe0, 0x00); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1392 | } |
| 1393 | |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 1394 | /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ |
| 1395 | #define UVC_STREAM_EOH (1 << 7) |
| 1396 | #define UVC_STREAM_ERR (1 << 6) |
| 1397 | #define UVC_STREAM_STI (1 << 5) |
| 1398 | #define UVC_STREAM_RES (1 << 4) |
| 1399 | #define UVC_STREAM_SCR (1 << 3) |
| 1400 | #define UVC_STREAM_PTS (1 << 2) |
| 1401 | #define UVC_STREAM_EOF (1 << 1) |
| 1402 | #define UVC_STREAM_FID (1 << 0) |
| 1403 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1404 | static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, |
| 1405 | __u8 *data, int len) |
| 1406 | { |
Jean-Francois Moine | 8c25205 | 2008-12-04 05:06:08 -0300 | [diff] [blame] | 1407 | struct sd *sd = (struct sd *) gspca_dev; |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 1408 | __u32 this_pts; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1409 | u16 this_fid; |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 1410 | int remaining_len = len; |
Jean-Francois Moine | c874f3a | 2009-06-12 03:20:46 -0300 | [diff] [blame] | 1411 | int payload_len; |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 1412 | |
Jean-Francois Moine | c874f3a | 2009-06-12 03:20:46 -0300 | [diff] [blame] | 1413 | payload_len = gspca_dev->cam.bulk ? 2048 : 2040; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1414 | do { |
Jean-Francois Moine | c874f3a | 2009-06-12 03:20:46 -0300 | [diff] [blame] | 1415 | len = min(remaining_len, payload_len); |
Jim Paris | 0f7a50b | 2008-12-10 05:45:14 -0300 | [diff] [blame] | 1416 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1417 | /* Payloads are prefixed with a UVC-style header. We |
| 1418 | consider a frame to start when the FID toggles, or the PTS |
| 1419 | changes. A frame ends when EOF is set, and we've received |
| 1420 | the correct number of bytes. */ |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1421 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1422 | /* Verify UVC header. Header length is always 12 */ |
| 1423 | if (data[0] != 12 || len < 12) { |
| 1424 | PDEBUG(D_PACK, "bad header"); |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 1425 | goto discard; |
| 1426 | } |
| 1427 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1428 | /* Check errors */ |
| 1429 | if (data[1] & UVC_STREAM_ERR) { |
| 1430 | PDEBUG(D_PACK, "payload error"); |
| 1431 | goto discard; |
Jean-Francois Moine | 3481c19 | 2009-03-19 06:05:06 -0300 | [diff] [blame] | 1432 | } |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 1433 | |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1434 | /* Extract PTS and FID */ |
| 1435 | if (!(data[1] & UVC_STREAM_PTS)) { |
| 1436 | PDEBUG(D_PACK, "PTS not present"); |
| 1437 | goto discard; |
| 1438 | } |
| 1439 | this_pts = (data[5] << 24) | (data[4] << 16) |
| 1440 | | (data[3] << 8) | data[2]; |
| 1441 | this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0; |
| 1442 | |
| 1443 | /* If PTS or FID has changed, start a new frame. */ |
| 1444 | if (this_pts != sd->last_pts || this_fid != sd->last_fid) { |
Jean-Francois Moine | ed47119 | 2009-04-23 13:52:27 -0300 | [diff] [blame] | 1445 | if (gspca_dev->last_packet_type == INTER_PACKET) |
| 1446 | frame = gspca_frame_add(gspca_dev, |
| 1447 | LAST_PACKET, frame, |
| 1448 | NULL, 0); |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1449 | sd->last_pts = this_pts; |
| 1450 | sd->last_fid = this_fid; |
Jean-Francois Moine | ed47119 | 2009-04-23 13:52:27 -0300 | [diff] [blame] | 1451 | gspca_frame_add(gspca_dev, FIRST_PACKET, frame, |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1452 | data + 12, len - 12); |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1453 | /* If this packet is marked as EOF, end the frame */ |
Jean-Francois Moine | ed47119 | 2009-04-23 13:52:27 -0300 | [diff] [blame] | 1454 | } else if (data[1] & UVC_STREAM_EOF) { |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1455 | sd->last_pts = 0; |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1456 | frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, |
Jean-Francois Moine | ed47119 | 2009-04-23 13:52:27 -0300 | [diff] [blame] | 1457 | data + 12, len - 12); |
| 1458 | } else { |
| 1459 | |
| 1460 | /* Add the data from this payload */ |
| 1461 | gspca_frame_add(gspca_dev, INTER_PACKET, frame, |
| 1462 | data + 12, len - 12); |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | /* Done this payload */ |
| 1466 | goto scan_next; |
Jim Paris | fb13922 | 2008-12-04 04:52:40 -0300 | [diff] [blame] | 1467 | |
| 1468 | discard: |
Jean-Francois Moine | 84fbdf8 | 2009-03-19 06:12:59 -0300 | [diff] [blame] | 1469 | /* Discard data until a new frame starts. */ |
| 1470 | gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0); |
| 1471 | |
| 1472 | scan_next: |
| 1473 | remaining_len -= len; |
| 1474 | data += len; |
| 1475 | } while (remaining_len > 0); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1476 | } |
| 1477 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1478 | /* ov772x controls */ |
| 1479 | static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) |
| 1480 | { |
| 1481 | struct sd *sd = (struct sd *) gspca_dev; |
| 1482 | |
| 1483 | sd->gain = val; |
| 1484 | if (gspca_dev->streaming) |
| 1485 | setgain(gspca_dev); |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) |
| 1490 | { |
| 1491 | struct sd *sd = (struct sd *) gspca_dev; |
| 1492 | |
| 1493 | *val = sd->gain; |
| 1494 | return 0; |
| 1495 | } |
| 1496 | |
| 1497 | static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) |
| 1498 | { |
| 1499 | struct sd *sd = (struct sd *) gspca_dev; |
| 1500 | |
| 1501 | sd->exposure = val; |
| 1502 | if (gspca_dev->streaming) |
| 1503 | setexposure(gspca_dev); |
| 1504 | return 0; |
| 1505 | } |
| 1506 | |
| 1507 | static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) |
| 1508 | { |
| 1509 | struct sd *sd = (struct sd *) gspca_dev; |
| 1510 | |
| 1511 | *val = sd->exposure; |
| 1512 | return 0; |
| 1513 | } |
| 1514 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1515 | static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) |
| 1516 | { |
| 1517 | struct sd *sd = (struct sd *) gspca_dev; |
| 1518 | |
| 1519 | sd->brightness = val; |
| 1520 | if (gspca_dev->streaming) |
| 1521 | setcontrast(gspca_dev); |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
| 1525 | static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) |
| 1526 | { |
| 1527 | struct sd *sd = (struct sd *) gspca_dev; |
| 1528 | |
| 1529 | *val = sd->brightness; |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) |
| 1534 | { |
| 1535 | struct sd *sd = (struct sd *) gspca_dev; |
| 1536 | |
| 1537 | sd->contrast = val; |
| 1538 | if (gspca_dev->streaming) |
| 1539 | setcontrast(gspca_dev); |
| 1540 | return 0; |
| 1541 | } |
| 1542 | |
| 1543 | static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) |
| 1544 | { |
| 1545 | struct sd *sd = (struct sd *) gspca_dev; |
| 1546 | |
| 1547 | *val = sd->contrast; |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1551 | static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val) |
| 1552 | { |
| 1553 | struct sd *sd = (struct sd *) gspca_dev; |
| 1554 | |
| 1555 | sd->redblc = val; |
| 1556 | if (gspca_dev->streaming) |
| 1557 | setredblc(gspca_dev); |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val) |
| 1562 | { |
| 1563 | struct sd *sd = (struct sd *) gspca_dev; |
| 1564 | |
| 1565 | *val = sd->redblc; |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
| 1569 | static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val) |
| 1570 | { |
| 1571 | struct sd *sd = (struct sd *) gspca_dev; |
| 1572 | |
| 1573 | sd->blueblc = val; |
| 1574 | if (gspca_dev->streaming) |
| 1575 | setblueblc(gspca_dev); |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
| 1579 | static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val) |
| 1580 | { |
| 1581 | struct sd *sd = (struct sd *) gspca_dev; |
| 1582 | |
| 1583 | *val = sd->blueblc; |
| 1584 | return 0; |
| 1585 | } |
| 1586 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1587 | static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val) |
| 1588 | { |
| 1589 | struct sd *sd = (struct sd *) gspca_dev; |
| 1590 | |
| 1591 | sd->hue = val; |
| 1592 | if (gspca_dev->streaming) |
| 1593 | sethue(gspca_dev); |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
| 1597 | static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val) |
| 1598 | { |
| 1599 | struct sd *sd = (struct sd *) gspca_dev; |
| 1600 | |
| 1601 | *val = sd->hue; |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1605 | static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) |
| 1606 | { |
| 1607 | struct sd *sd = (struct sd *) gspca_dev; |
| 1608 | |
| 1609 | sd->autogain = val; |
| 1610 | if (gspca_dev->streaming) |
| 1611 | setautogain(gspca_dev); |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
| 1615 | static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) |
| 1616 | { |
| 1617 | struct sd *sd = (struct sd *) gspca_dev; |
| 1618 | |
| 1619 | *val = sd->autogain; |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
Jean-Francois Moine | b014f94 | 2009-11-11 14:28:53 -0300 | [diff] [blame^] | 1623 | static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val) |
| 1624 | { |
| 1625 | struct sd *sd = (struct sd *) gspca_dev; |
| 1626 | |
| 1627 | sd->awb = val; |
| 1628 | if (gspca_dev->streaming) |
| 1629 | setawb(gspca_dev); |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
| 1633 | static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val) |
| 1634 | { |
| 1635 | struct sd *sd = (struct sd *) gspca_dev; |
| 1636 | |
| 1637 | *val = sd->awb; |
| 1638 | return 0; |
| 1639 | } |
| 1640 | |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1641 | static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) |
| 1642 | { |
| 1643 | struct sd *sd = (struct sd *) gspca_dev; |
| 1644 | |
| 1645 | sd->sharpness = val; |
| 1646 | if (gspca_dev->streaming) |
| 1647 | setsharpness(gspca_dev); |
| 1648 | return 0; |
| 1649 | } |
| 1650 | |
| 1651 | static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) |
| 1652 | { |
| 1653 | struct sd *sd = (struct sd *) gspca_dev; |
| 1654 | |
| 1655 | *val = sd->sharpness; |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
| 1659 | static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) |
| 1660 | { |
| 1661 | struct sd *sd = (struct sd *) gspca_dev; |
| 1662 | |
| 1663 | sd->hflip = val; |
| 1664 | if (gspca_dev->streaming) |
| 1665 | sethflip(gspca_dev); |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
| 1669 | static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 1670 | { |
| 1671 | struct sd *sd = (struct sd *) gspca_dev; |
| 1672 | |
| 1673 | *val = sd->hflip; |
| 1674 | return 0; |
| 1675 | } |
| 1676 | |
| 1677 | static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) |
| 1678 | { |
| 1679 | struct sd *sd = (struct sd *) gspca_dev; |
| 1680 | |
| 1681 | sd->vflip = val; |
| 1682 | if (gspca_dev->streaming) |
| 1683 | setvflip(gspca_dev); |
| 1684 | return 0; |
| 1685 | } |
| 1686 | |
| 1687 | static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) |
| 1688 | { |
| 1689 | struct sd *sd = (struct sd *) gspca_dev; |
| 1690 | |
| 1691 | *val = sd->vflip; |
| 1692 | return 0; |
| 1693 | } |
| 1694 | |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1695 | /* get stream parameters (framerate) */ |
Jean-Francois Moine | 5c1a15a | 2008-12-21 15:02:54 -0300 | [diff] [blame] | 1696 | static int sd_get_streamparm(struct gspca_dev *gspca_dev, |
| 1697 | struct v4l2_streamparm *parm) |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1698 | { |
| 1699 | struct v4l2_captureparm *cp = &parm->parm.capture; |
| 1700 | struct v4l2_fract *tpf = &cp->timeperframe; |
| 1701 | struct sd *sd = (struct sd *) gspca_dev; |
| 1702 | |
| 1703 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1704 | return -EINVAL; |
| 1705 | |
| 1706 | cp->capability |= V4L2_CAP_TIMEPERFRAME; |
| 1707 | tpf->numerator = 1; |
| 1708 | tpf->denominator = sd->frame_rate; |
| 1709 | |
| 1710 | return 0; |
| 1711 | } |
| 1712 | |
| 1713 | /* set stream parameters (framerate) */ |
Jean-Francois Moine | 5c1a15a | 2008-12-21 15:02:54 -0300 | [diff] [blame] | 1714 | static int sd_set_streamparm(struct gspca_dev *gspca_dev, |
| 1715 | struct v4l2_streamparm *parm) |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1716 | { |
| 1717 | struct v4l2_captureparm *cp = &parm->parm.capture; |
| 1718 | struct v4l2_fract *tpf = &cp->timeperframe; |
| 1719 | struct sd *sd = (struct sd *) gspca_dev; |
| 1720 | |
| 1721 | if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
| 1722 | return -EINVAL; |
| 1723 | |
| 1724 | /* Set requested framerate */ |
| 1725 | sd->frame_rate = tpf->denominator / tpf->numerator; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1726 | if (gspca_dev->streaming) |
| 1727 | ov534_set_frame_rate(gspca_dev); |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1728 | |
| 1729 | /* Return the actual framerate */ |
| 1730 | tpf->numerator = 1; |
| 1731 | tpf->denominator = sd->frame_rate; |
| 1732 | |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1736 | /* sub-driver description */ |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1737 | static const struct sd_desc sd_desc_ov772x = { |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1738 | .name = MODULE_NAME, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1739 | .ctrls = sd_ctrls_ov772x, |
| 1740 | .nctrls = ARRAY_SIZE(sd_ctrls_ov772x), |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1741 | .config = sd_config, |
| 1742 | .init = sd_init, |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1743 | .start = sd_start_ov772x, |
| 1744 | .stopN = sd_stopN_ov772x, |
| 1745 | .pkt_scan = sd_pkt_scan, |
| 1746 | .get_streamparm = sd_get_streamparm, |
| 1747 | .set_streamparm = sd_set_streamparm, |
| 1748 | }; |
| 1749 | |
| 1750 | static const struct sd_desc sd_desc_ov965x = { |
| 1751 | .name = MODULE_NAME, |
| 1752 | .ctrls = sd_ctrls_ov965x, |
| 1753 | .nctrls = ARRAY_SIZE(sd_ctrls_ov965x), |
| 1754 | .config = sd_config, |
| 1755 | .init = sd_init, |
| 1756 | .start = sd_start_ov965x, |
| 1757 | .stopN = sd_stopN_ov965x, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1758 | .pkt_scan = sd_pkt_scan, |
Jim Paris | 11d9f25 | 2008-12-10 06:06:20 -0300 | [diff] [blame] | 1759 | .get_streamparm = sd_get_streamparm, |
| 1760 | .set_streamparm = sd_set_streamparm, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1761 | }; |
| 1762 | |
| 1763 | /* -- module initialisation -- */ |
| 1764 | static const __devinitdata struct usb_device_id device_table[] = { |
Jean-Francois Moine | 2ce949e | 2009-03-19 06:15:21 -0300 | [diff] [blame] | 1765 | {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X}, |
| 1766 | {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X}, |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1767 | {} |
| 1768 | }; |
| 1769 | |
| 1770 | MODULE_DEVICE_TABLE(usb, device_table); |
| 1771 | |
| 1772 | /* -- device connect -- */ |
| 1773 | static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) |
| 1774 | { |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1775 | return gspca_dev_probe(intf, id, |
| 1776 | id->driver_info == SENSOR_OV772X |
| 1777 | ? &sd_desc_ov772x |
| 1778 | : &sd_desc_ov965x, |
| 1779 | sizeof(struct sd), |
| 1780 | THIS_MODULE); |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | static struct usb_driver sd_driver = { |
| 1784 | .name = MODULE_NAME, |
| 1785 | .id_table = device_table, |
| 1786 | .probe = sd_probe, |
| 1787 | .disconnect = gspca_disconnect, |
| 1788 | #ifdef CONFIG_PM |
| 1789 | .suspend = gspca_suspend, |
| 1790 | .resume = gspca_resume, |
| 1791 | #endif |
| 1792 | }; |
| 1793 | |
| 1794 | /* -- module insert / remove -- */ |
| 1795 | static int __init sd_mod_init(void) |
| 1796 | { |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 1797 | int ret; |
Jean-Francois Moine | 189d92a | 2009-11-11 07:46:28 -0300 | [diff] [blame] | 1798 | |
Alexey Klimov | f69e952 | 2009-01-01 13:02:07 -0300 | [diff] [blame] | 1799 | ret = usb_register(&sd_driver); |
| 1800 | if (ret < 0) |
Alexey Klimov | e6b1484 | 2009-01-01 13:04:58 -0300 | [diff] [blame] | 1801 | return ret; |
Antonio Ospite | fbb4c6d | 2008-11-22 05:23:39 -0300 | [diff] [blame] | 1802 | PDEBUG(D_PROBE, "registered"); |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | static void __exit sd_mod_exit(void) |
| 1807 | { |
| 1808 | usb_deregister(&sd_driver); |
| 1809 | PDEBUG(D_PROBE, "deregistered"); |
| 1810 | } |
| 1811 | |
| 1812 | module_init(sd_mod_init); |
| 1813 | module_exit(sd_mod_exit); |