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