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