1 /* 2 * Copyright (c) 2017 Intel Corporation. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License version 6 * 2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 */ 14 15 #include <linux/acpi.h> 16 #include <linux/i2c.h> 17 #include <linux/module.h> 18 #include <linux/pm_runtime.h> 19 #include <media/v4l2-ctrls.h> 20 #include <media/v4l2-device.h> 21 22 #define OV5670_REG_CHIP_ID 0x300a 23 #define OV5670_CHIP_ID 0x005670 24 25 #define OV5670_REG_MODE_SELECT 0x0100 26 #define OV5670_MODE_STANDBY 0x00 27 #define OV5670_MODE_STREAMING 0x01 28 29 #define OV5670_REG_SOFTWARE_RST 0x0103 30 #define OV5670_SOFTWARE_RST 0x01 31 32 /* vertical-timings from sensor */ 33 #define OV5670_REG_VTS 0x380e 34 #define OV5670_VTS_30FPS 0x0808 /* default for 30 fps */ 35 #define OV5670_VTS_MAX 0xffff 36 #define OV5670_VBLANK_MIN 56 37 38 /* horizontal-timings from sensor */ 39 #define OV5670_REG_HTS 0x380c 40 #define OV5670_DEF_PPL 3360 /* Default pixels per line */ 41 42 /* Exposure controls from sensor */ 43 #define OV5670_REG_EXPOSURE 0x3500 44 #define OV5670_EXPOSURE_MIN 4 45 #define OV5670_EXPOSURE_STEP 1 46 47 /* Analog gain controls from sensor */ 48 #define OV5670_REG_ANALOG_GAIN 0x3508 49 #define ANALOG_GAIN_MIN 0 50 #define ANALOG_GAIN_MAX 8191 51 #define ANALOG_GAIN_STEP 1 52 #define ANALOG_GAIN_DEFAULT 128 53 54 /* Digital gain controls from sensor */ 55 #define OV5670_REG_R_DGTL_GAIN 0x5032 56 #define OV5670_REG_G_DGTL_GAIN 0x5034 57 #define OV5670_REG_B_DGTL_GAIN 0x5036 58 #define OV5670_DGTL_GAIN_MIN 0 59 #define OV5670_DGTL_GAIN_MAX 4095 60 #define OV5670_DGTL_GAIN_STEP 1 61 #define OV5670_DGTL_GAIN_DEFAULT 1024 62 63 /* Test Pattern Control */ 64 #define OV5670_REG_TEST_PATTERN 0x4303 65 #define OV5670_TEST_PATTERN_ENABLE BIT(3) 66 #define OV5670_REG_TEST_PATTERN_CTRL 0x4320 67 68 #define OV5670_REG_VALUE_08BIT 1 69 #define OV5670_REG_VALUE_16BIT 2 70 #define OV5670_REG_VALUE_24BIT 3 71 72 /* Initial number of frames to skip to avoid possible garbage */ 73 #define OV5670_NUM_OF_SKIP_FRAMES 2 74 75 struct ov5670_reg { 76 u16 address; 77 u8 val; 78 }; 79 80 struct ov5670_reg_list { 81 u32 num_of_regs; 82 const struct ov5670_reg *regs; 83 }; 84 85 struct ov5670_link_freq_config { 86 u32 pixel_rate; 87 const struct ov5670_reg_list reg_list; 88 }; 89 90 struct ov5670_mode { 91 /* Frame width in pixels */ 92 u32 width; 93 94 /* Frame height in pixels */ 95 u32 height; 96 97 /* Vertical timining size */ 98 u32 vts; 99 100 /* Link frequency needed for this resolution */ 101 u32 link_freq_index; 102 103 /* Sensor register settings for this resolution */ 104 const struct ov5670_reg_list reg_list; 105 }; 106 107 static const struct ov5670_reg mipi_data_rate_840mbps[] = { 108 {0x0300, 0x04}, 109 {0x0301, 0x00}, 110 {0x0302, 0x84}, 111 {0x0303, 0x00}, 112 {0x0304, 0x03}, 113 {0x0305, 0x01}, 114 {0x0306, 0x01}, 115 {0x030a, 0x00}, 116 {0x030b, 0x00}, 117 {0x030c, 0x00}, 118 {0x030d, 0x26}, 119 {0x030e, 0x00}, 120 {0x030f, 0x06}, 121 {0x0312, 0x01}, 122 {0x3031, 0x0a}, 123 }; 124 125 static const struct ov5670_reg mode_2592x1944_regs[] = { 126 {0x3000, 0x00}, 127 {0x3002, 0x21}, 128 {0x3005, 0xf0}, 129 {0x3007, 0x00}, 130 {0x3015, 0x0f}, 131 {0x3018, 0x32}, 132 {0x301a, 0xf0}, 133 {0x301b, 0xf0}, 134 {0x301c, 0xf0}, 135 {0x301d, 0xf0}, 136 {0x301e, 0xf0}, 137 {0x3030, 0x00}, 138 {0x3031, 0x0a}, 139 {0x303c, 0xff}, 140 {0x303e, 0xff}, 141 {0x3040, 0xf0}, 142 {0x3041, 0x00}, 143 {0x3042, 0xf0}, 144 {0x3106, 0x11}, 145 {0x3500, 0x00}, 146 {0x3501, 0x80}, 147 {0x3502, 0x00}, 148 {0x3503, 0x04}, 149 {0x3504, 0x03}, 150 {0x3505, 0x83}, 151 {0x3508, 0x04}, 152 {0x3509, 0x00}, 153 {0x350e, 0x04}, 154 {0x350f, 0x00}, 155 {0x3510, 0x00}, 156 {0x3511, 0x02}, 157 {0x3512, 0x00}, 158 {0x3601, 0xc8}, 159 {0x3610, 0x88}, 160 {0x3612, 0x48}, 161 {0x3614, 0x5b}, 162 {0x3615, 0x96}, 163 {0x3621, 0xd0}, 164 {0x3622, 0x00}, 165 {0x3623, 0x00}, 166 {0x3633, 0x13}, 167 {0x3634, 0x13}, 168 {0x3635, 0x13}, 169 {0x3636, 0x13}, 170 {0x3645, 0x13}, 171 {0x3646, 0x82}, 172 {0x3650, 0x00}, 173 {0x3652, 0xff}, 174 {0x3655, 0x20}, 175 {0x3656, 0xff}, 176 {0x365a, 0xff}, 177 {0x365e, 0xff}, 178 {0x3668, 0x00}, 179 {0x366a, 0x07}, 180 {0x366e, 0x10}, 181 {0x366d, 0x00}, 182 {0x366f, 0x80}, 183 {0x3700, 0x28}, 184 {0x3701, 0x10}, 185 {0x3702, 0x3a}, 186 {0x3703, 0x19}, 187 {0x3704, 0x10}, 188 {0x3705, 0x00}, 189 {0x3706, 0x66}, 190 {0x3707, 0x08}, 191 {0x3708, 0x34}, 192 {0x3709, 0x40}, 193 {0x370a, 0x01}, 194 {0x370b, 0x1b}, 195 {0x3714, 0x24}, 196 {0x371a, 0x3e}, 197 {0x3733, 0x00}, 198 {0x3734, 0x00}, 199 {0x373a, 0x05}, 200 {0x373b, 0x06}, 201 {0x373c, 0x0a}, 202 {0x373f, 0xa0}, 203 {0x3755, 0x00}, 204 {0x3758, 0x00}, 205 {0x375b, 0x0e}, 206 {0x3766, 0x5f}, 207 {0x3768, 0x00}, 208 {0x3769, 0x22}, 209 {0x3773, 0x08}, 210 {0x3774, 0x1f}, 211 {0x3776, 0x06}, 212 {0x37a0, 0x88}, 213 {0x37a1, 0x5c}, 214 {0x37a7, 0x88}, 215 {0x37a8, 0x70}, 216 {0x37aa, 0x88}, 217 {0x37ab, 0x48}, 218 {0x37b3, 0x66}, 219 {0x37c2, 0x04}, 220 {0x37c5, 0x00}, 221 {0x37c8, 0x00}, 222 {0x3800, 0x00}, 223 {0x3801, 0x0c}, 224 {0x3802, 0x00}, 225 {0x3803, 0x04}, 226 {0x3804, 0x0a}, 227 {0x3805, 0x33}, 228 {0x3806, 0x07}, 229 {0x3807, 0xa3}, 230 {0x3808, 0x0a}, 231 {0x3809, 0x20}, 232 {0x380a, 0x07}, 233 {0x380b, 0x98}, 234 {0x380c, 0x06}, 235 {0x380d, 0x90}, 236 {0x380e, 0x08}, 237 {0x380f, 0x08}, 238 {0x3811, 0x04}, 239 {0x3813, 0x02}, 240 {0x3814, 0x01}, 241 {0x3815, 0x01}, 242 {0x3816, 0x00}, 243 {0x3817, 0x00}, 244 {0x3818, 0x00}, 245 {0x3819, 0x00}, 246 {0x3820, 0x84}, 247 {0x3821, 0x46}, 248 {0x3822, 0x48}, 249 {0x3826, 0x00}, 250 {0x3827, 0x08}, 251 {0x382a, 0x01}, 252 {0x382b, 0x01}, 253 {0x3830, 0x08}, 254 {0x3836, 0x02}, 255 {0x3837, 0x00}, 256 {0x3838, 0x10}, 257 {0x3841, 0xff}, 258 {0x3846, 0x48}, 259 {0x3861, 0x00}, 260 {0x3862, 0x04}, 261 {0x3863, 0x06}, 262 {0x3a11, 0x01}, 263 {0x3a12, 0x78}, 264 {0x3b00, 0x00}, 265 {0x3b02, 0x00}, 266 {0x3b03, 0x00}, 267 {0x3b04, 0x00}, 268 {0x3b05, 0x00}, 269 {0x3c00, 0x89}, 270 {0x3c01, 0xab}, 271 {0x3c02, 0x01}, 272 {0x3c03, 0x00}, 273 {0x3c04, 0x00}, 274 {0x3c05, 0x03}, 275 {0x3c06, 0x00}, 276 {0x3c07, 0x05}, 277 {0x3c0c, 0x00}, 278 {0x3c0d, 0x00}, 279 {0x3c0e, 0x00}, 280 {0x3c0f, 0x00}, 281 {0x3c40, 0x00}, 282 {0x3c41, 0xa3}, 283 {0x3c43, 0x7d}, 284 {0x3c45, 0xd7}, 285 {0x3c47, 0xfc}, 286 {0x3c50, 0x05}, 287 {0x3c52, 0xaa}, 288 {0x3c54, 0x71}, 289 {0x3c56, 0x80}, 290 {0x3d85, 0x17}, 291 {0x3f03, 0x00}, 292 {0x3f0a, 0x00}, 293 {0x3f0b, 0x00}, 294 {0x4001, 0x60}, 295 {0x4009, 0x0d}, 296 {0x4020, 0x00}, 297 {0x4021, 0x00}, 298 {0x4022, 0x00}, 299 {0x4023, 0x00}, 300 {0x4024, 0x00}, 301 {0x4025, 0x00}, 302 {0x4026, 0x00}, 303 {0x4027, 0x00}, 304 {0x4028, 0x00}, 305 {0x4029, 0x00}, 306 {0x402a, 0x00}, 307 {0x402b, 0x00}, 308 {0x402c, 0x00}, 309 {0x402d, 0x00}, 310 {0x402e, 0x00}, 311 {0x402f, 0x00}, 312 {0x4040, 0x00}, 313 {0x4041, 0x03}, 314 {0x4042, 0x00}, 315 {0x4043, 0x7A}, 316 {0x4044, 0x00}, 317 {0x4045, 0x7A}, 318 {0x4046, 0x00}, 319 {0x4047, 0x7A}, 320 {0x4048, 0x00}, 321 {0x4049, 0x7A}, 322 {0x4307, 0x30}, 323 {0x4500, 0x58}, 324 {0x4501, 0x04}, 325 {0x4502, 0x40}, 326 {0x4503, 0x10}, 327 {0x4508, 0xaa}, 328 {0x4509, 0xaa}, 329 {0x450a, 0x00}, 330 {0x450b, 0x00}, 331 {0x4600, 0x01}, 332 {0x4601, 0x03}, 333 {0x4700, 0xa4}, 334 {0x4800, 0x4c}, 335 {0x4816, 0x53}, 336 {0x481f, 0x40}, 337 {0x4837, 0x13}, 338 {0x5000, 0x56}, 339 {0x5001, 0x01}, 340 {0x5002, 0x28}, 341 {0x5004, 0x0c}, 342 {0x5006, 0x0c}, 343 {0x5007, 0xe0}, 344 {0x5008, 0x01}, 345 {0x5009, 0xb0}, 346 {0x5901, 0x00}, 347 {0x5a01, 0x00}, 348 {0x5a03, 0x00}, 349 {0x5a04, 0x0c}, 350 {0x5a05, 0xe0}, 351 {0x5a06, 0x09}, 352 {0x5a07, 0xb0}, 353 {0x5a08, 0x06}, 354 {0x5e00, 0x00}, 355 {0x3734, 0x40}, 356 {0x5b00, 0x01}, 357 {0x5b01, 0x10}, 358 {0x5b02, 0x01}, 359 {0x5b03, 0xdb}, 360 {0x3d8c, 0x71}, 361 {0x3d8d, 0xea}, 362 {0x4017, 0x08}, 363 {0x3618, 0x2a}, 364 {0x5780, 0x3e}, 365 {0x5781, 0x0f}, 366 {0x5782, 0x44}, 367 {0x5783, 0x02}, 368 {0x5784, 0x01}, 369 {0x5785, 0x01}, 370 {0x5786, 0x00}, 371 {0x5787, 0x04}, 372 {0x5788, 0x02}, 373 {0x5789, 0x0f}, 374 {0x578a, 0xfd}, 375 {0x578b, 0xf5}, 376 {0x578c, 0xf5}, 377 {0x578d, 0x03}, 378 {0x578e, 0x08}, 379 {0x578f, 0x0c}, 380 {0x5790, 0x08}, 381 {0x5791, 0x06}, 382 {0x5792, 0x00}, 383 {0x5793, 0x52}, 384 {0x5794, 0xa3}, 385 {0x3503, 0x00} 386 }; 387 388 static const struct ov5670_reg mode_1296x972_regs[] = { 389 {0x3000, 0x00}, 390 {0x3002, 0x21}, 391 {0x3005, 0xf0}, 392 {0x3007, 0x00}, 393 {0x3015, 0x0f}, 394 {0x3018, 0x32}, 395 {0x301a, 0xf0}, 396 {0x301b, 0xf0}, 397 {0x301c, 0xf0}, 398 {0x301d, 0xf0}, 399 {0x301e, 0xf0}, 400 {0x3030, 0x00}, 401 {0x3031, 0x0a}, 402 {0x303c, 0xff}, 403 {0x303e, 0xff}, 404 {0x3040, 0xf0}, 405 {0x3041, 0x00}, 406 {0x3042, 0xf0}, 407 {0x3106, 0x11}, 408 {0x3500, 0x00}, 409 {0x3501, 0x80}, 410 {0x3502, 0x00}, 411 {0x3503, 0x04}, 412 {0x3504, 0x03}, 413 {0x3505, 0x83}, 414 {0x3508, 0x07}, 415 {0x3509, 0x80}, 416 {0x350e, 0x04}, 417 {0x350f, 0x00}, 418 {0x3510, 0x00}, 419 {0x3511, 0x02}, 420 {0x3512, 0x00}, 421 {0x3601, 0xc8}, 422 {0x3610, 0x88}, 423 {0x3612, 0x48}, 424 {0x3614, 0x5b}, 425 {0x3615, 0x96}, 426 {0x3621, 0xd0}, 427 {0x3622, 0x00}, 428 {0x3623, 0x00}, 429 {0x3633, 0x13}, 430 {0x3634, 0x13}, 431 {0x3635, 0x13}, 432 {0x3636, 0x13}, 433 {0x3645, 0x13}, 434 {0x3646, 0x82}, 435 {0x3650, 0x00}, 436 {0x3652, 0xff}, 437 {0x3655, 0x20}, 438 {0x3656, 0xff}, 439 {0x365a, 0xff}, 440 {0x365e, 0xff}, 441 {0x3668, 0x00}, 442 {0x366a, 0x07}, 443 {0x366e, 0x08}, 444 {0x366d, 0x00}, 445 {0x366f, 0x80}, 446 {0x3700, 0x28}, 447 {0x3701, 0x10}, 448 {0x3702, 0x3a}, 449 {0x3703, 0x19}, 450 {0x3704, 0x10}, 451 {0x3705, 0x00}, 452 {0x3706, 0x66}, 453 {0x3707, 0x08}, 454 {0x3708, 0x34}, 455 {0x3709, 0x40}, 456 {0x370a, 0x01}, 457 {0x370b, 0x1b}, 458 {0x3714, 0x24}, 459 {0x371a, 0x3e}, 460 {0x3733, 0x00}, 461 {0x3734, 0x00}, 462 {0x373a, 0x05}, 463 {0x373b, 0x06}, 464 {0x373c, 0x0a}, 465 {0x373f, 0xa0}, 466 {0x3755, 0x00}, 467 {0x3758, 0x00}, 468 {0x375b, 0x0e}, 469 {0x3766, 0x5f}, 470 {0x3768, 0x00}, 471 {0x3769, 0x22}, 472 {0x3773, 0x08}, 473 {0x3774, 0x1f}, 474 {0x3776, 0x06}, 475 {0x37a0, 0x88}, 476 {0x37a1, 0x5c}, 477 {0x37a7, 0x88}, 478 {0x37a8, 0x70}, 479 {0x37aa, 0x88}, 480 {0x37ab, 0x48}, 481 {0x37b3, 0x66}, 482 {0x37c2, 0x04}, 483 {0x37c5, 0x00}, 484 {0x37c8, 0x00}, 485 {0x3800, 0x00}, 486 {0x3801, 0x0c}, 487 {0x3802, 0x00}, 488 {0x3803, 0x04}, 489 {0x3804, 0x0a}, 490 {0x3805, 0x33}, 491 {0x3806, 0x07}, 492 {0x3807, 0xa3}, 493 {0x3808, 0x05}, 494 {0x3809, 0x10}, 495 {0x380a, 0x03}, 496 {0x380b, 0xcc}, 497 {0x380c, 0x06}, 498 {0x380d, 0x90}, 499 {0x380e, 0x08}, 500 {0x380f, 0x08}, 501 {0x3811, 0x04}, 502 {0x3813, 0x04}, 503 {0x3814, 0x03}, 504 {0x3815, 0x01}, 505 {0x3816, 0x00}, 506 {0x3817, 0x00}, 507 {0x3818, 0x00}, 508 {0x3819, 0x00}, 509 {0x3820, 0x94}, 510 {0x3821, 0x47}, 511 {0x3822, 0x48}, 512 {0x3826, 0x00}, 513 {0x3827, 0x08}, 514 {0x382a, 0x03}, 515 {0x382b, 0x01}, 516 {0x3830, 0x08}, 517 {0x3836, 0x02}, 518 {0x3837, 0x00}, 519 {0x3838, 0x10}, 520 {0x3841, 0xff}, 521 {0x3846, 0x48}, 522 {0x3861, 0x00}, 523 {0x3862, 0x04}, 524 {0x3863, 0x06}, 525 {0x3a11, 0x01}, 526 {0x3a12, 0x78}, 527 {0x3b00, 0x00}, 528 {0x3b02, 0x00}, 529 {0x3b03, 0x00}, 530 {0x3b04, 0x00}, 531 {0x3b05, 0x00}, 532 {0x3c00, 0x89}, 533 {0x3c01, 0xab}, 534 {0x3c02, 0x01}, 535 {0x3c03, 0x00}, 536 {0x3c04, 0x00}, 537 {0x3c05, 0x03}, 538 {0x3c06, 0x00}, 539 {0x3c07, 0x05}, 540 {0x3c0c, 0x00}, 541 {0x3c0d, 0x00}, 542 {0x3c0e, 0x00}, 543 {0x3c0f, 0x00}, 544 {0x3c40, 0x00}, 545 {0x3c41, 0xa3}, 546 {0x3c43, 0x7d}, 547 {0x3c45, 0xd7}, 548 {0x3c47, 0xfc}, 549 {0x3c50, 0x05}, 550 {0x3c52, 0xaa}, 551 {0x3c54, 0x71}, 552 {0x3c56, 0x80}, 553 {0x3d85, 0x17}, 554 {0x3f03, 0x00}, 555 {0x3f0a, 0x00}, 556 {0x3f0b, 0x00}, 557 {0x4001, 0x60}, 558 {0x4009, 0x05}, 559 {0x4020, 0x00}, 560 {0x4021, 0x00}, 561 {0x4022, 0x00}, 562 {0x4023, 0x00}, 563 {0x4024, 0x00}, 564 {0x4025, 0x00}, 565 {0x4026, 0x00}, 566 {0x4027, 0x00}, 567 {0x4028, 0x00}, 568 {0x4029, 0x00}, 569 {0x402a, 0x00}, 570 {0x402b, 0x00}, 571 {0x402c, 0x00}, 572 {0x402d, 0x00}, 573 {0x402e, 0x00}, 574 {0x402f, 0x00}, 575 {0x4040, 0x00}, 576 {0x4041, 0x03}, 577 {0x4042, 0x00}, 578 {0x4043, 0x7A}, 579 {0x4044, 0x00}, 580 {0x4045, 0x7A}, 581 {0x4046, 0x00}, 582 {0x4047, 0x7A}, 583 {0x4048, 0x00}, 584 {0x4049, 0x7A}, 585 {0x4307, 0x30}, 586 {0x4500, 0x58}, 587 {0x4501, 0x04}, 588 {0x4502, 0x48}, 589 {0x4503, 0x10}, 590 {0x4508, 0x55}, 591 {0x4509, 0x55}, 592 {0x450a, 0x00}, 593 {0x450b, 0x00}, 594 {0x4600, 0x00}, 595 {0x4601, 0x81}, 596 {0x4700, 0xa4}, 597 {0x4800, 0x4c}, 598 {0x4816, 0x53}, 599 {0x481f, 0x40}, 600 {0x4837, 0x13}, 601 {0x5000, 0x56}, 602 {0x5001, 0x01}, 603 {0x5002, 0x28}, 604 {0x5004, 0x0c}, 605 {0x5006, 0x0c}, 606 {0x5007, 0xe0}, 607 {0x5008, 0x01}, 608 {0x5009, 0xb0}, 609 {0x5901, 0x00}, 610 {0x5a01, 0x00}, 611 {0x5a03, 0x00}, 612 {0x5a04, 0x0c}, 613 {0x5a05, 0xe0}, 614 {0x5a06, 0x09}, 615 {0x5a07, 0xb0}, 616 {0x5a08, 0x06}, 617 {0x5e00, 0x00}, 618 {0x3734, 0x40}, 619 {0x5b00, 0x01}, 620 {0x5b01, 0x10}, 621 {0x5b02, 0x01}, 622 {0x5b03, 0xdb}, 623 {0x3d8c, 0x71}, 624 {0x3d8d, 0xea}, 625 {0x4017, 0x10}, 626 {0x3618, 0x2a}, 627 {0x5780, 0x3e}, 628 {0x5781, 0x0f}, 629 {0x5782, 0x44}, 630 {0x5783, 0x02}, 631 {0x5784, 0x01}, 632 {0x5785, 0x01}, 633 {0x5786, 0x00}, 634 {0x5787, 0x04}, 635 {0x5788, 0x02}, 636 {0x5789, 0x0f}, 637 {0x578a, 0xfd}, 638 {0x578b, 0xf5}, 639 {0x578c, 0xf5}, 640 {0x578d, 0x03}, 641 {0x578e, 0x08}, 642 {0x578f, 0x0c}, 643 {0x5790, 0x08}, 644 {0x5791, 0x04}, 645 {0x5792, 0x00}, 646 {0x5793, 0x52}, 647 {0x5794, 0xa3}, 648 {0x3503, 0x00} 649 }; 650 651 static const struct ov5670_reg mode_648x486_regs[] = { 652 {0x3000, 0x00}, 653 {0x3002, 0x21}, 654 {0x3005, 0xf0}, 655 {0x3007, 0x00}, 656 {0x3015, 0x0f}, 657 {0x3018, 0x32}, 658 {0x301a, 0xf0}, 659 {0x301b, 0xf0}, 660 {0x301c, 0xf0}, 661 {0x301d, 0xf0}, 662 {0x301e, 0xf0}, 663 {0x3030, 0x00}, 664 {0x3031, 0x0a}, 665 {0x303c, 0xff}, 666 {0x303e, 0xff}, 667 {0x3040, 0xf0}, 668 {0x3041, 0x00}, 669 {0x3042, 0xf0}, 670 {0x3106, 0x11}, 671 {0x3500, 0x00}, 672 {0x3501, 0x80}, 673 {0x3502, 0x00}, 674 {0x3503, 0x04}, 675 {0x3504, 0x03}, 676 {0x3505, 0x83}, 677 {0x3508, 0x04}, 678 {0x3509, 0x00}, 679 {0x350e, 0x04}, 680 {0x350f, 0x00}, 681 {0x3510, 0x00}, 682 {0x3511, 0x02}, 683 {0x3512, 0x00}, 684 {0x3601, 0xc8}, 685 {0x3610, 0x88}, 686 {0x3612, 0x48}, 687 {0x3614, 0x5b}, 688 {0x3615, 0x96}, 689 {0x3621, 0xd0}, 690 {0x3622, 0x00}, 691 {0x3623, 0x04}, 692 {0x3633, 0x13}, 693 {0x3634, 0x13}, 694 {0x3635, 0x13}, 695 {0x3636, 0x13}, 696 {0x3645, 0x13}, 697 {0x3646, 0x82}, 698 {0x3650, 0x00}, 699 {0x3652, 0xff}, 700 {0x3655, 0x20}, 701 {0x3656, 0xff}, 702 {0x365a, 0xff}, 703 {0x365e, 0xff}, 704 {0x3668, 0x00}, 705 {0x366a, 0x07}, 706 {0x366e, 0x08}, 707 {0x366d, 0x00}, 708 {0x366f, 0x80}, 709 {0x3700, 0x28}, 710 {0x3701, 0x10}, 711 {0x3702, 0x3a}, 712 {0x3703, 0x19}, 713 {0x3704, 0x10}, 714 {0x3705, 0x00}, 715 {0x3706, 0x66}, 716 {0x3707, 0x08}, 717 {0x3708, 0x34}, 718 {0x3709, 0x40}, 719 {0x370a, 0x01}, 720 {0x370b, 0x1b}, 721 {0x3714, 0x24}, 722 {0x371a, 0x3e}, 723 {0x3733, 0x00}, 724 {0x3734, 0x00}, 725 {0x373a, 0x05}, 726 {0x373b, 0x06}, 727 {0x373c, 0x0a}, 728 {0x373f, 0xa0}, 729 {0x3755, 0x00}, 730 {0x3758, 0x00}, 731 {0x375b, 0x0e}, 732 {0x3766, 0x5f}, 733 {0x3768, 0x00}, 734 {0x3769, 0x22}, 735 {0x3773, 0x08}, 736 {0x3774, 0x1f}, 737 {0x3776, 0x06}, 738 {0x37a0, 0x88}, 739 {0x37a1, 0x5c}, 740 {0x37a7, 0x88}, 741 {0x37a8, 0x70}, 742 {0x37aa, 0x88}, 743 {0x37ab, 0x48}, 744 {0x37b3, 0x66}, 745 {0x37c2, 0x04}, 746 {0x37c5, 0x00}, 747 {0x37c8, 0x00}, 748 {0x3800, 0x00}, 749 {0x3801, 0x0c}, 750 {0x3802, 0x00}, 751 {0x3803, 0x04}, 752 {0x3804, 0x0a}, 753 {0x3805, 0x33}, 754 {0x3806, 0x07}, 755 {0x3807, 0xa3}, 756 {0x3808, 0x02}, 757 {0x3809, 0x88}, 758 {0x380a, 0x01}, 759 {0x380b, 0xe6}, 760 {0x380c, 0x06}, 761 {0x380d, 0x90}, 762 {0x380e, 0x08}, 763 {0x380f, 0x08}, 764 {0x3811, 0x04}, 765 {0x3813, 0x02}, 766 {0x3814, 0x07}, 767 {0x3815, 0x01}, 768 {0x3816, 0x00}, 769 {0x3817, 0x00}, 770 {0x3818, 0x00}, 771 {0x3819, 0x00}, 772 {0x3820, 0x94}, 773 {0x3821, 0xc6}, 774 {0x3822, 0x48}, 775 {0x3826, 0x00}, 776 {0x3827, 0x08}, 777 {0x382a, 0x07}, 778 {0x382b, 0x01}, 779 {0x3830, 0x08}, 780 {0x3836, 0x02}, 781 {0x3837, 0x00}, 782 {0x3838, 0x10}, 783 {0x3841, 0xff}, 784 {0x3846, 0x48}, 785 {0x3861, 0x00}, 786 {0x3862, 0x04}, 787 {0x3863, 0x06}, 788 {0x3a11, 0x01}, 789 {0x3a12, 0x78}, 790 {0x3b00, 0x00}, 791 {0x3b02, 0x00}, 792 {0x3b03, 0x00}, 793 {0x3b04, 0x00}, 794 {0x3b05, 0x00}, 795 {0x3c00, 0x89}, 796 {0x3c01, 0xab}, 797 {0x3c02, 0x01}, 798 {0x3c03, 0x00}, 799 {0x3c04, 0x00}, 800 {0x3c05, 0x03}, 801 {0x3c06, 0x00}, 802 {0x3c07, 0x05}, 803 {0x3c0c, 0x00}, 804 {0x3c0d, 0x00}, 805 {0x3c0e, 0x00}, 806 {0x3c0f, 0x00}, 807 {0x3c40, 0x00}, 808 {0x3c41, 0xa3}, 809 {0x3c43, 0x7d}, 810 {0x3c45, 0xd7}, 811 {0x3c47, 0xfc}, 812 {0x3c50, 0x05}, 813 {0x3c52, 0xaa}, 814 {0x3c54, 0x71}, 815 {0x3c56, 0x80}, 816 {0x3d85, 0x17}, 817 {0x3f03, 0x00}, 818 {0x3f0a, 0x00}, 819 {0x3f0b, 0x00}, 820 {0x4001, 0x60}, 821 {0x4009, 0x05}, 822 {0x4020, 0x00}, 823 {0x4021, 0x00}, 824 {0x4022, 0x00}, 825 {0x4023, 0x00}, 826 {0x4024, 0x00}, 827 {0x4025, 0x00}, 828 {0x4026, 0x00}, 829 {0x4027, 0x00}, 830 {0x4028, 0x00}, 831 {0x4029, 0x00}, 832 {0x402a, 0x00}, 833 {0x402b, 0x00}, 834 {0x402c, 0x00}, 835 {0x402d, 0x00}, 836 {0x402e, 0x00}, 837 {0x402f, 0x00}, 838 {0x4040, 0x00}, 839 {0x4041, 0x03}, 840 {0x4042, 0x00}, 841 {0x4043, 0x7A}, 842 {0x4044, 0x00}, 843 {0x4045, 0x7A}, 844 {0x4046, 0x00}, 845 {0x4047, 0x7A}, 846 {0x4048, 0x00}, 847 {0x4049, 0x7A}, 848 {0x4307, 0x30}, 849 {0x4500, 0x58}, 850 {0x4501, 0x04}, 851 {0x4502, 0x40}, 852 {0x4503, 0x10}, 853 {0x4508, 0x55}, 854 {0x4509, 0x55}, 855 {0x450a, 0x02}, 856 {0x450b, 0x00}, 857 {0x4600, 0x00}, 858 {0x4601, 0x40}, 859 {0x4700, 0xa4}, 860 {0x4800, 0x4c}, 861 {0x4816, 0x53}, 862 {0x481f, 0x40}, 863 {0x4837, 0x13}, 864 {0x5000, 0x56}, 865 {0x5001, 0x01}, 866 {0x5002, 0x28}, 867 {0x5004, 0x0c}, 868 {0x5006, 0x0c}, 869 {0x5007, 0xe0}, 870 {0x5008, 0x01}, 871 {0x5009, 0xb0}, 872 {0x5901, 0x00}, 873 {0x5a01, 0x00}, 874 {0x5a03, 0x00}, 875 {0x5a04, 0x0c}, 876 {0x5a05, 0xe0}, 877 {0x5a06, 0x09}, 878 {0x5a07, 0xb0}, 879 {0x5a08, 0x06}, 880 {0x5e00, 0x00}, 881 {0x3734, 0x40}, 882 {0x5b00, 0x01}, 883 {0x5b01, 0x10}, 884 {0x5b02, 0x01}, 885 {0x5b03, 0xdb}, 886 {0x3d8c, 0x71}, 887 {0x3d8d, 0xea}, 888 {0x4017, 0x10}, 889 {0x3618, 0x2a}, 890 {0x5780, 0x3e}, 891 {0x5781, 0x0f}, 892 {0x5782, 0x44}, 893 {0x5783, 0x02}, 894 {0x5784, 0x01}, 895 {0x5785, 0x01}, 896 {0x5786, 0x00}, 897 {0x5787, 0x04}, 898 {0x5788, 0x02}, 899 {0x5789, 0x0f}, 900 {0x578a, 0xfd}, 901 {0x578b, 0xf5}, 902 {0x578c, 0xf5}, 903 {0x578d, 0x03}, 904 {0x578e, 0x08}, 905 {0x578f, 0x0c}, 906 {0x5790, 0x08}, 907 {0x5791, 0x06}, 908 {0x5792, 0x00}, 909 {0x5793, 0x52}, 910 {0x5794, 0xa3}, 911 {0x3503, 0x00} 912 }; 913 914 static const struct ov5670_reg mode_2560x1440_regs[] = { 915 {0x3000, 0x00}, 916 {0x3002, 0x21}, 917 {0x3005, 0xf0}, 918 {0x3007, 0x00}, 919 {0x3015, 0x0f}, 920 {0x3018, 0x32}, 921 {0x301a, 0xf0}, 922 {0x301b, 0xf0}, 923 {0x301c, 0xf0}, 924 {0x301d, 0xf0}, 925 {0x301e, 0xf0}, 926 {0x3030, 0x00}, 927 {0x3031, 0x0a}, 928 {0x303c, 0xff}, 929 {0x303e, 0xff}, 930 {0x3040, 0xf0}, 931 {0x3041, 0x00}, 932 {0x3042, 0xf0}, 933 {0x3106, 0x11}, 934 {0x3500, 0x00}, 935 {0x3501, 0x80}, 936 {0x3502, 0x00}, 937 {0x3503, 0x04}, 938 {0x3504, 0x03}, 939 {0x3505, 0x83}, 940 {0x3508, 0x04}, 941 {0x3509, 0x00}, 942 {0x350e, 0x04}, 943 {0x350f, 0x00}, 944 {0x3510, 0x00}, 945 {0x3511, 0x02}, 946 {0x3512, 0x00}, 947 {0x3601, 0xc8}, 948 {0x3610, 0x88}, 949 {0x3612, 0x48}, 950 {0x3614, 0x5b}, 951 {0x3615, 0x96}, 952 {0x3621, 0xd0}, 953 {0x3622, 0x00}, 954 {0x3623, 0x00}, 955 {0x3633, 0x13}, 956 {0x3634, 0x13}, 957 {0x3635, 0x13}, 958 {0x3636, 0x13}, 959 {0x3645, 0x13}, 960 {0x3646, 0x82}, 961 {0x3650, 0x00}, 962 {0x3652, 0xff}, 963 {0x3655, 0x20}, 964 {0x3656, 0xff}, 965 {0x365a, 0xff}, 966 {0x365e, 0xff}, 967 {0x3668, 0x00}, 968 {0x366a, 0x07}, 969 {0x366e, 0x10}, 970 {0x366d, 0x00}, 971 {0x366f, 0x80}, 972 {0x3700, 0x28}, 973 {0x3701, 0x10}, 974 {0x3702, 0x3a}, 975 {0x3703, 0x19}, 976 {0x3704, 0x10}, 977 {0x3705, 0x00}, 978 {0x3706, 0x66}, 979 {0x3707, 0x08}, 980 {0x3708, 0x34}, 981 {0x3709, 0x40}, 982 {0x370a, 0x01}, 983 {0x370b, 0x1b}, 984 {0x3714, 0x24}, 985 {0x371a, 0x3e}, 986 {0x3733, 0x00}, 987 {0x3734, 0x00}, 988 {0x373a, 0x05}, 989 {0x373b, 0x06}, 990 {0x373c, 0x0a}, 991 {0x373f, 0xa0}, 992 {0x3755, 0x00}, 993 {0x3758, 0x00}, 994 {0x375b, 0x0e}, 995 {0x3766, 0x5f}, 996 {0x3768, 0x00}, 997 {0x3769, 0x22}, 998 {0x3773, 0x08}, 999 {0x3774, 0x1f}, 1000 {0x3776, 0x06}, 1001 {0x37a0, 0x88}, 1002 {0x37a1, 0x5c}, 1003 {0x37a7, 0x88}, 1004 {0x37a8, 0x70}, 1005 {0x37aa, 0x88}, 1006 {0x37ab, 0x48}, 1007 {0x37b3, 0x66}, 1008 {0x37c2, 0x04}, 1009 {0x37c5, 0x00}, 1010 {0x37c8, 0x00}, 1011 {0x3800, 0x00}, 1012 {0x3801, 0x0c}, 1013 {0x3802, 0x00}, 1014 {0x3803, 0x04}, 1015 {0x3804, 0x0a}, 1016 {0x3805, 0x33}, 1017 {0x3806, 0x07}, 1018 {0x3807, 0xa3}, 1019 {0x3808, 0x0a}, 1020 {0x3809, 0x00}, 1021 {0x380a, 0x05}, 1022 {0x380b, 0xa0}, 1023 {0x380c, 0x06}, 1024 {0x380d, 0x90}, 1025 {0x380e, 0x08}, 1026 {0x380f, 0x08}, 1027 {0x3811, 0x04}, 1028 {0x3813, 0x02}, 1029 {0x3814, 0x01}, 1030 {0x3815, 0x01}, 1031 {0x3816, 0x00}, 1032 {0x3817, 0x00}, 1033 {0x3818, 0x00}, 1034 {0x3819, 0x00}, 1035 {0x3820, 0x84}, 1036 {0x3821, 0x46}, 1037 {0x3822, 0x48}, 1038 {0x3826, 0x00}, 1039 {0x3827, 0x08}, 1040 {0x382a, 0x01}, 1041 {0x382b, 0x01}, 1042 {0x3830, 0x08}, 1043 {0x3836, 0x02}, 1044 {0x3837, 0x00}, 1045 {0x3838, 0x10}, 1046 {0x3841, 0xff}, 1047 {0x3846, 0x48}, 1048 {0x3861, 0x00}, 1049 {0x3862, 0x04}, 1050 {0x3863, 0x06}, 1051 {0x3a11, 0x01}, 1052 {0x3a12, 0x78}, 1053 {0x3b00, 0x00}, 1054 {0x3b02, 0x00}, 1055 {0x3b03, 0x00}, 1056 {0x3b04, 0x00}, 1057 {0x3b05, 0x00}, 1058 {0x3c00, 0x89}, 1059 {0x3c01, 0xab}, 1060 {0x3c02, 0x01}, 1061 {0x3c03, 0x00}, 1062 {0x3c04, 0x00}, 1063 {0x3c05, 0x03}, 1064 {0x3c06, 0x00}, 1065 {0x3c07, 0x05}, 1066 {0x3c0c, 0x00}, 1067 {0x3c0d, 0x00}, 1068 {0x3c0e, 0x00}, 1069 {0x3c0f, 0x00}, 1070 {0x3c40, 0x00}, 1071 {0x3c41, 0xa3}, 1072 {0x3c43, 0x7d}, 1073 {0x3c45, 0xd7}, 1074 {0x3c47, 0xfc}, 1075 {0x3c50, 0x05}, 1076 {0x3c52, 0xaa}, 1077 {0x3c54, 0x71}, 1078 {0x3c56, 0x80}, 1079 {0x3d85, 0x17}, 1080 {0x3f03, 0x00}, 1081 {0x3f0a, 0x00}, 1082 {0x3f0b, 0x00}, 1083 {0x4001, 0x60}, 1084 {0x4009, 0x0d}, 1085 {0x4020, 0x00}, 1086 {0x4021, 0x00}, 1087 {0x4022, 0x00}, 1088 {0x4023, 0x00}, 1089 {0x4024, 0x00}, 1090 {0x4025, 0x00}, 1091 {0x4026, 0x00}, 1092 {0x4027, 0x00}, 1093 {0x4028, 0x00}, 1094 {0x4029, 0x00}, 1095 {0x402a, 0x00}, 1096 {0x402b, 0x00}, 1097 {0x402c, 0x00}, 1098 {0x402d, 0x00}, 1099 {0x402e, 0x00}, 1100 {0x402f, 0x00}, 1101 {0x4040, 0x00}, 1102 {0x4041, 0x03}, 1103 {0x4042, 0x00}, 1104 {0x4043, 0x7A}, 1105 {0x4044, 0x00}, 1106 {0x4045, 0x7A}, 1107 {0x4046, 0x00}, 1108 {0x4047, 0x7A}, 1109 {0x4048, 0x00}, 1110 {0x4049, 0x7A}, 1111 {0x4307, 0x30}, 1112 {0x4500, 0x58}, 1113 {0x4501, 0x04}, 1114 {0x4502, 0x40}, 1115 {0x4503, 0x10}, 1116 {0x4508, 0xaa}, 1117 {0x4509, 0xaa}, 1118 {0x450a, 0x00}, 1119 {0x450b, 0x00}, 1120 {0x4600, 0x01}, 1121 {0x4601, 0x00}, 1122 {0x4700, 0xa4}, 1123 {0x4800, 0x4c}, 1124 {0x4816, 0x53}, 1125 {0x481f, 0x40}, 1126 {0x4837, 0x13}, 1127 {0x5000, 0x56}, 1128 {0x5001, 0x01}, 1129 {0x5002, 0x28}, 1130 {0x5004, 0x0c}, 1131 {0x5006, 0x0c}, 1132 {0x5007, 0xe0}, 1133 {0x5008, 0x01}, 1134 {0x5009, 0xb0}, 1135 {0x5901, 0x00}, 1136 {0x5a01, 0x00}, 1137 {0x5a03, 0x00}, 1138 {0x5a04, 0x0c}, 1139 {0x5a05, 0xe0}, 1140 {0x5a06, 0x09}, 1141 {0x5a07, 0xb0}, 1142 {0x5a08, 0x06}, 1143 {0x5e00, 0x00}, 1144 {0x3734, 0x40}, 1145 {0x5b00, 0x01}, 1146 {0x5b01, 0x10}, 1147 {0x5b02, 0x01}, 1148 {0x5b03, 0xdb}, 1149 {0x3d8c, 0x71}, 1150 {0x3d8d, 0xea}, 1151 {0x4017, 0x08}, 1152 {0x3618, 0x2a}, 1153 {0x5780, 0x3e}, 1154 {0x5781, 0x0f}, 1155 {0x5782, 0x44}, 1156 {0x5783, 0x02}, 1157 {0x5784, 0x01}, 1158 {0x5785, 0x01}, 1159 {0x5786, 0x00}, 1160 {0x5787, 0x04}, 1161 {0x5788, 0x02}, 1162 {0x5789, 0x0f}, 1163 {0x578a, 0xfd}, 1164 {0x578b, 0xf5}, 1165 {0x578c, 0xf5}, 1166 {0x578d, 0x03}, 1167 {0x578e, 0x08}, 1168 {0x578f, 0x0c}, 1169 {0x5790, 0x08}, 1170 {0x5791, 0x06}, 1171 {0x5792, 0x00}, 1172 {0x5793, 0x52}, 1173 {0x5794, 0xa3} 1174 }; 1175 1176 static const struct ov5670_reg mode_1280x720_regs[] = { 1177 {0x3000, 0x00}, 1178 {0x3002, 0x21}, 1179 {0x3005, 0xf0}, 1180 {0x3007, 0x00}, 1181 {0x3015, 0x0f}, 1182 {0x3018, 0x32}, 1183 {0x301a, 0xf0}, 1184 {0x301b, 0xf0}, 1185 {0x301c, 0xf0}, 1186 {0x301d, 0xf0}, 1187 {0x301e, 0xf0}, 1188 {0x3030, 0x00}, 1189 {0x3031, 0x0a}, 1190 {0x303c, 0xff}, 1191 {0x303e, 0xff}, 1192 {0x3040, 0xf0}, 1193 {0x3041, 0x00}, 1194 {0x3042, 0xf0}, 1195 {0x3106, 0x11}, 1196 {0x3500, 0x00}, 1197 {0x3501, 0x80}, 1198 {0x3502, 0x00}, 1199 {0x3503, 0x04}, 1200 {0x3504, 0x03}, 1201 {0x3505, 0x83}, 1202 {0x3508, 0x04}, 1203 {0x3509, 0x00}, 1204 {0x350e, 0x04}, 1205 {0x350f, 0x00}, 1206 {0x3510, 0x00}, 1207 {0x3511, 0x02}, 1208 {0x3512, 0x00}, 1209 {0x3601, 0xc8}, 1210 {0x3610, 0x88}, 1211 {0x3612, 0x48}, 1212 {0x3614, 0x5b}, 1213 {0x3615, 0x96}, 1214 {0x3621, 0xd0}, 1215 {0x3622, 0x00}, 1216 {0x3623, 0x00}, 1217 {0x3633, 0x13}, 1218 {0x3634, 0x13}, 1219 {0x3635, 0x13}, 1220 {0x3636, 0x13}, 1221 {0x3645, 0x13}, 1222 {0x3646, 0x82}, 1223 {0x3650, 0x00}, 1224 {0x3652, 0xff}, 1225 {0x3655, 0x20}, 1226 {0x3656, 0xff}, 1227 {0x365a, 0xff}, 1228 {0x365e, 0xff}, 1229 {0x3668, 0x00}, 1230 {0x366a, 0x07}, 1231 {0x366e, 0x08}, 1232 {0x366d, 0x00}, 1233 {0x366f, 0x80}, 1234 {0x3700, 0x28}, 1235 {0x3701, 0x10}, 1236 {0x3702, 0x3a}, 1237 {0x3703, 0x19}, 1238 {0x3704, 0x10}, 1239 {0x3705, 0x00}, 1240 {0x3706, 0x66}, 1241 {0x3707, 0x08}, 1242 {0x3708, 0x34}, 1243 {0x3709, 0x40}, 1244 {0x370a, 0x01}, 1245 {0x370b, 0x1b}, 1246 {0x3714, 0x24}, 1247 {0x371a, 0x3e}, 1248 {0x3733, 0x00}, 1249 {0x3734, 0x00}, 1250 {0x373a, 0x05}, 1251 {0x373b, 0x06}, 1252 {0x373c, 0x0a}, 1253 {0x373f, 0xa0}, 1254 {0x3755, 0x00}, 1255 {0x3758, 0x00}, 1256 {0x375b, 0x0e}, 1257 {0x3766, 0x5f}, 1258 {0x3768, 0x00}, 1259 {0x3769, 0x22}, 1260 {0x3773, 0x08}, 1261 {0x3774, 0x1f}, 1262 {0x3776, 0x06}, 1263 {0x37a0, 0x88}, 1264 {0x37a1, 0x5c}, 1265 {0x37a7, 0x88}, 1266 {0x37a8, 0x70}, 1267 {0x37aa, 0x88}, 1268 {0x37ab, 0x48}, 1269 {0x37b3, 0x66}, 1270 {0x37c2, 0x04}, 1271 {0x37c5, 0x00}, 1272 {0x37c8, 0x00}, 1273 {0x3800, 0x00}, 1274 {0x3801, 0x0c}, 1275 {0x3802, 0x00}, 1276 {0x3803, 0x04}, 1277 {0x3804, 0x0a}, 1278 {0x3805, 0x33}, 1279 {0x3806, 0x07}, 1280 {0x3807, 0xa3}, 1281 {0x3808, 0x05}, 1282 {0x3809, 0x00}, 1283 {0x380a, 0x02}, 1284 {0x380b, 0xd0}, 1285 {0x380c, 0x06}, 1286 {0x380d, 0x90}, 1287 {0x380e, 0x08}, 1288 {0x380f, 0x08}, 1289 {0x3811, 0x04}, 1290 {0x3813, 0x02}, 1291 {0x3814, 0x03}, 1292 {0x3815, 0x01}, 1293 {0x3816, 0x00}, 1294 {0x3817, 0x00}, 1295 {0x3818, 0x00}, 1296 {0x3819, 0x00}, 1297 {0x3820, 0x94}, 1298 {0x3821, 0x47}, 1299 {0x3822, 0x48}, 1300 {0x3826, 0x00}, 1301 {0x3827, 0x08}, 1302 {0x382a, 0x03}, 1303 {0x382b, 0x01}, 1304 {0x3830, 0x08}, 1305 {0x3836, 0x02}, 1306 {0x3837, 0x00}, 1307 {0x3838, 0x10}, 1308 {0x3841, 0xff}, 1309 {0x3846, 0x48}, 1310 {0x3861, 0x00}, 1311 {0x3862, 0x04}, 1312 {0x3863, 0x06}, 1313 {0x3a11, 0x01}, 1314 {0x3a12, 0x78}, 1315 {0x3b00, 0x00}, 1316 {0x3b02, 0x00}, 1317 {0x3b03, 0x00}, 1318 {0x3b04, 0x00}, 1319 {0x3b05, 0x00}, 1320 {0x3c00, 0x89}, 1321 {0x3c01, 0xab}, 1322 {0x3c02, 0x01}, 1323 {0x3c03, 0x00}, 1324 {0x3c04, 0x00}, 1325 {0x3c05, 0x03}, 1326 {0x3c06, 0x00}, 1327 {0x3c07, 0x05}, 1328 {0x3c0c, 0x00}, 1329 {0x3c0d, 0x00}, 1330 {0x3c0e, 0x00}, 1331 {0x3c0f, 0x00}, 1332 {0x3c40, 0x00}, 1333 {0x3c41, 0xa3}, 1334 {0x3c43, 0x7d}, 1335 {0x3c45, 0xd7}, 1336 {0x3c47, 0xfc}, 1337 {0x3c50, 0x05}, 1338 {0x3c52, 0xaa}, 1339 {0x3c54, 0x71}, 1340 {0x3c56, 0x80}, 1341 {0x3d85, 0x17}, 1342 {0x3f03, 0x00}, 1343 {0x3f0a, 0x00}, 1344 {0x3f0b, 0x00}, 1345 {0x4001, 0x60}, 1346 {0x4009, 0x05}, 1347 {0x4020, 0x00}, 1348 {0x4021, 0x00}, 1349 {0x4022, 0x00}, 1350 {0x4023, 0x00}, 1351 {0x4024, 0x00}, 1352 {0x4025, 0x00}, 1353 {0x4026, 0x00}, 1354 {0x4027, 0x00}, 1355 {0x4028, 0x00}, 1356 {0x4029, 0x00}, 1357 {0x402a, 0x00}, 1358 {0x402b, 0x00}, 1359 {0x402c, 0x00}, 1360 {0x402d, 0x00}, 1361 {0x402e, 0x00}, 1362 {0x402f, 0x00}, 1363 {0x4040, 0x00}, 1364 {0x4041, 0x03}, 1365 {0x4042, 0x00}, 1366 {0x4043, 0x7A}, 1367 {0x4044, 0x00}, 1368 {0x4045, 0x7A}, 1369 {0x4046, 0x00}, 1370 {0x4047, 0x7A}, 1371 {0x4048, 0x00}, 1372 {0x4049, 0x7A}, 1373 {0x4307, 0x30}, 1374 {0x4500, 0x58}, 1375 {0x4501, 0x04}, 1376 {0x4502, 0x48}, 1377 {0x4503, 0x10}, 1378 {0x4508, 0x55}, 1379 {0x4509, 0x55}, 1380 {0x450a, 0x00}, 1381 {0x450b, 0x00}, 1382 {0x4600, 0x00}, 1383 {0x4601, 0x80}, 1384 {0x4700, 0xa4}, 1385 {0x4800, 0x4c}, 1386 {0x4816, 0x53}, 1387 {0x481f, 0x40}, 1388 {0x4837, 0x13}, 1389 {0x5000, 0x56}, 1390 {0x5001, 0x01}, 1391 {0x5002, 0x28}, 1392 {0x5004, 0x0c}, 1393 {0x5006, 0x0c}, 1394 {0x5007, 0xe0}, 1395 {0x5008, 0x01}, 1396 {0x5009, 0xb0}, 1397 {0x5901, 0x00}, 1398 {0x5a01, 0x00}, 1399 {0x5a03, 0x00}, 1400 {0x5a04, 0x0c}, 1401 {0x5a05, 0xe0}, 1402 {0x5a06, 0x09}, 1403 {0x5a07, 0xb0}, 1404 {0x5a08, 0x06}, 1405 {0x5e00, 0x00}, 1406 {0x3734, 0x40}, 1407 {0x5b00, 0x01}, 1408 {0x5b01, 0x10}, 1409 {0x5b02, 0x01}, 1410 {0x5b03, 0xdb}, 1411 {0x3d8c, 0x71}, 1412 {0x3d8d, 0xea}, 1413 {0x4017, 0x10}, 1414 {0x3618, 0x2a}, 1415 {0x5780, 0x3e}, 1416 {0x5781, 0x0f}, 1417 {0x5782, 0x44}, 1418 {0x5783, 0x02}, 1419 {0x5784, 0x01}, 1420 {0x5785, 0x01}, 1421 {0x5786, 0x00}, 1422 {0x5787, 0x04}, 1423 {0x5788, 0x02}, 1424 {0x5789, 0x0f}, 1425 {0x578a, 0xfd}, 1426 {0x578b, 0xf5}, 1427 {0x578c, 0xf5}, 1428 {0x578d, 0x03}, 1429 {0x578e, 0x08}, 1430 {0x578f, 0x0c}, 1431 {0x5790, 0x08}, 1432 {0x5791, 0x06}, 1433 {0x5792, 0x00}, 1434 {0x5793, 0x52}, 1435 {0x5794, 0xa3}, 1436 {0x3503, 0x00} 1437 }; 1438 1439 static const struct ov5670_reg mode_640x360_regs[] = { 1440 {0x3000, 0x00}, 1441 {0x3002, 0x21}, 1442 {0x3005, 0xf0}, 1443 {0x3007, 0x00}, 1444 {0x3015, 0x0f}, 1445 {0x3018, 0x32}, 1446 {0x301a, 0xf0}, 1447 {0x301b, 0xf0}, 1448 {0x301c, 0xf0}, 1449 {0x301d, 0xf0}, 1450 {0x301e, 0xf0}, 1451 {0x3030, 0x00}, 1452 {0x3031, 0x0a}, 1453 {0x303c, 0xff}, 1454 {0x303e, 0xff}, 1455 {0x3040, 0xf0}, 1456 {0x3041, 0x00}, 1457 {0x3042, 0xf0}, 1458 {0x3106, 0x11}, 1459 {0x3500, 0x00}, 1460 {0x3501, 0x80}, 1461 {0x3502, 0x00}, 1462 {0x3503, 0x04}, 1463 {0x3504, 0x03}, 1464 {0x3505, 0x83}, 1465 {0x3508, 0x04}, 1466 {0x3509, 0x00}, 1467 {0x350e, 0x04}, 1468 {0x350f, 0x00}, 1469 {0x3510, 0x00}, 1470 {0x3511, 0x02}, 1471 {0x3512, 0x00}, 1472 {0x3601, 0xc8}, 1473 {0x3610, 0x88}, 1474 {0x3612, 0x48}, 1475 {0x3614, 0x5b}, 1476 {0x3615, 0x96}, 1477 {0x3621, 0xd0}, 1478 {0x3622, 0x00}, 1479 {0x3623, 0x04}, 1480 {0x3633, 0x13}, 1481 {0x3634, 0x13}, 1482 {0x3635, 0x13}, 1483 {0x3636, 0x13}, 1484 {0x3645, 0x13}, 1485 {0x3646, 0x82}, 1486 {0x3650, 0x00}, 1487 {0x3652, 0xff}, 1488 {0x3655, 0x20}, 1489 {0x3656, 0xff}, 1490 {0x365a, 0xff}, 1491 {0x365e, 0xff}, 1492 {0x3668, 0x00}, 1493 {0x366a, 0x07}, 1494 {0x366e, 0x08}, 1495 {0x366d, 0x00}, 1496 {0x366f, 0x80}, 1497 {0x3700, 0x28}, 1498 {0x3701, 0x10}, 1499 {0x3702, 0x3a}, 1500 {0x3703, 0x19}, 1501 {0x3704, 0x10}, 1502 {0x3705, 0x00}, 1503 {0x3706, 0x66}, 1504 {0x3707, 0x08}, 1505 {0x3708, 0x34}, 1506 {0x3709, 0x40}, 1507 {0x370a, 0x01}, 1508 {0x370b, 0x1b}, 1509 {0x3714, 0x24}, 1510 {0x371a, 0x3e}, 1511 {0x3733, 0x00}, 1512 {0x3734, 0x00}, 1513 {0x373a, 0x05}, 1514 {0x373b, 0x06}, 1515 {0x373c, 0x0a}, 1516 {0x373f, 0xa0}, 1517 {0x3755, 0x00}, 1518 {0x3758, 0x00}, 1519 {0x375b, 0x0e}, 1520 {0x3766, 0x5f}, 1521 {0x3768, 0x00}, 1522 {0x3769, 0x22}, 1523 {0x3773, 0x08}, 1524 {0x3774, 0x1f}, 1525 {0x3776, 0x06}, 1526 {0x37a0, 0x88}, 1527 {0x37a1, 0x5c}, 1528 {0x37a7, 0x88}, 1529 {0x37a8, 0x70}, 1530 {0x37aa, 0x88}, 1531 {0x37ab, 0x48}, 1532 {0x37b3, 0x66}, 1533 {0x37c2, 0x04}, 1534 {0x37c5, 0x00}, 1535 {0x37c8, 0x00}, 1536 {0x3800, 0x00}, 1537 {0x3801, 0x0c}, 1538 {0x3802, 0x00}, 1539 {0x3803, 0x04}, 1540 {0x3804, 0x0a}, 1541 {0x3805, 0x33}, 1542 {0x3806, 0x07}, 1543 {0x3807, 0xa3}, 1544 {0x3808, 0x02}, 1545 {0x3809, 0x80}, 1546 {0x380a, 0x01}, 1547 {0x380b, 0x68}, 1548 {0x380c, 0x06}, 1549 {0x380d, 0x90}, 1550 {0x380e, 0x08}, 1551 {0x380f, 0x08}, 1552 {0x3811, 0x04}, 1553 {0x3813, 0x02}, 1554 {0x3814, 0x07}, 1555 {0x3815, 0x01}, 1556 {0x3816, 0x00}, 1557 {0x3817, 0x00}, 1558 {0x3818, 0x00}, 1559 {0x3819, 0x00}, 1560 {0x3820, 0x94}, 1561 {0x3821, 0xc6}, 1562 {0x3822, 0x48}, 1563 {0x3826, 0x00}, 1564 {0x3827, 0x08}, 1565 {0x382a, 0x07}, 1566 {0x382b, 0x01}, 1567 {0x3830, 0x08}, 1568 {0x3836, 0x02}, 1569 {0x3837, 0x00}, 1570 {0x3838, 0x10}, 1571 {0x3841, 0xff}, 1572 {0x3846, 0x48}, 1573 {0x3861, 0x00}, 1574 {0x3862, 0x04}, 1575 {0x3863, 0x06}, 1576 {0x3a11, 0x01}, 1577 {0x3a12, 0x78}, 1578 {0x3b00, 0x00}, 1579 {0x3b02, 0x00}, 1580 {0x3b03, 0x00}, 1581 {0x3b04, 0x00}, 1582 {0x3b05, 0x00}, 1583 {0x3c00, 0x89}, 1584 {0x3c01, 0xab}, 1585 {0x3c02, 0x01}, 1586 {0x3c03, 0x00}, 1587 {0x3c04, 0x00}, 1588 {0x3c05, 0x03}, 1589 {0x3c06, 0x00}, 1590 {0x3c07, 0x05}, 1591 {0x3c0c, 0x00}, 1592 {0x3c0d, 0x00}, 1593 {0x3c0e, 0x00}, 1594 {0x3c0f, 0x00}, 1595 {0x3c40, 0x00}, 1596 {0x3c41, 0xa3}, 1597 {0x3c43, 0x7d}, 1598 {0x3c45, 0xd7}, 1599 {0x3c47, 0xfc}, 1600 {0x3c50, 0x05}, 1601 {0x3c52, 0xaa}, 1602 {0x3c54, 0x71}, 1603 {0x3c56, 0x80}, 1604 {0x3d85, 0x17}, 1605 {0x3f03, 0x00}, 1606 {0x3f0a, 0x00}, 1607 {0x3f0b, 0x00}, 1608 {0x4001, 0x60}, 1609 {0x4009, 0x05}, 1610 {0x4020, 0x00}, 1611 {0x4021, 0x00}, 1612 {0x4022, 0x00}, 1613 {0x4023, 0x00}, 1614 {0x4024, 0x00}, 1615 {0x4025, 0x00}, 1616 {0x4026, 0x00}, 1617 {0x4027, 0x00}, 1618 {0x4028, 0x00}, 1619 {0x4029, 0x00}, 1620 {0x402a, 0x00}, 1621 {0x402b, 0x00}, 1622 {0x402c, 0x00}, 1623 {0x402d, 0x00}, 1624 {0x402e, 0x00}, 1625 {0x402f, 0x00}, 1626 {0x4040, 0x00}, 1627 {0x4041, 0x03}, 1628 {0x4042, 0x00}, 1629 {0x4043, 0x7A}, 1630 {0x4044, 0x00}, 1631 {0x4045, 0x7A}, 1632 {0x4046, 0x00}, 1633 {0x4047, 0x7A}, 1634 {0x4048, 0x00}, 1635 {0x4049, 0x7A}, 1636 {0x4307, 0x30}, 1637 {0x4500, 0x58}, 1638 {0x4501, 0x04}, 1639 {0x4502, 0x40}, 1640 {0x4503, 0x10}, 1641 {0x4508, 0x55}, 1642 {0x4509, 0x55}, 1643 {0x450a, 0x02}, 1644 {0x450b, 0x00}, 1645 {0x4600, 0x00}, 1646 {0x4601, 0x40}, 1647 {0x4700, 0xa4}, 1648 {0x4800, 0x4c}, 1649 {0x4816, 0x53}, 1650 {0x481f, 0x40}, 1651 {0x4837, 0x13}, 1652 {0x5000, 0x56}, 1653 {0x5001, 0x01}, 1654 {0x5002, 0x28}, 1655 {0x5004, 0x0c}, 1656 {0x5006, 0x0c}, 1657 {0x5007, 0xe0}, 1658 {0x5008, 0x01}, 1659 {0x5009, 0xb0}, 1660 {0x5901, 0x00}, 1661 {0x5a01, 0x00}, 1662 {0x5a03, 0x00}, 1663 {0x5a04, 0x0c}, 1664 {0x5a05, 0xe0}, 1665 {0x5a06, 0x09}, 1666 {0x5a07, 0xb0}, 1667 {0x5a08, 0x06}, 1668 {0x5e00, 0x00}, 1669 {0x3734, 0x40}, 1670 {0x5b00, 0x01}, 1671 {0x5b01, 0x10}, 1672 {0x5b02, 0x01}, 1673 {0x5b03, 0xdb}, 1674 {0x3d8c, 0x71}, 1675 {0x3d8d, 0xea}, 1676 {0x4017, 0x10}, 1677 {0x3618, 0x2a}, 1678 {0x5780, 0x3e}, 1679 {0x5781, 0x0f}, 1680 {0x5782, 0x44}, 1681 {0x5783, 0x02}, 1682 {0x5784, 0x01}, 1683 {0x5785, 0x01}, 1684 {0x5786, 0x00}, 1685 {0x5787, 0x04}, 1686 {0x5788, 0x02}, 1687 {0x5789, 0x0f}, 1688 {0x578a, 0xfd}, 1689 {0x578b, 0xf5}, 1690 {0x578c, 0xf5}, 1691 {0x578d, 0x03}, 1692 {0x578e, 0x08}, 1693 {0x578f, 0x0c}, 1694 {0x5790, 0x08}, 1695 {0x5791, 0x06}, 1696 {0x5792, 0x00}, 1697 {0x5793, 0x52}, 1698 {0x5794, 0xa3}, 1699 {0x3503, 0x00} 1700 }; 1701 1702 static const char * const ov5670_test_pattern_menu[] = { 1703 "Disabled", 1704 "Vertical Color Bar Type 1", 1705 }; 1706 1707 /* Supported link frequencies */ 1708 #define OV5670_LINK_FREQ_420MHZ 420000000 1709 #define OV5670_LINK_FREQ_420MHZ_INDEX 0 1710 static const struct ov5670_link_freq_config link_freq_configs[] = { 1711 { 1712 /* pixel_rate = link_freq * 2 * nr_of_lanes / bits_per_sample */ 1713 .pixel_rate = (OV5670_LINK_FREQ_420MHZ * 2 * 2) / 10, 1714 .reg_list = { 1715 .num_of_regs = ARRAY_SIZE(mipi_data_rate_840mbps), 1716 .regs = mipi_data_rate_840mbps, 1717 } 1718 } 1719 }; 1720 1721 static const s64 link_freq_menu_items[] = { 1722 OV5670_LINK_FREQ_420MHZ 1723 }; 1724 1725 /* 1726 * OV5670 sensor supports following resolutions with full FOV: 1727 * 4:3 ==> {2592x1944, 1296x972, 648x486} 1728 * 16:9 ==> {2560x1440, 1280x720, 640x360} 1729 */ 1730 static const struct ov5670_mode supported_modes[] = { 1731 { 1732 .width = 2592, 1733 .height = 1944, 1734 .vts = OV5670_VTS_30FPS, 1735 .reg_list = { 1736 .num_of_regs = ARRAY_SIZE(mode_2592x1944_regs), 1737 .regs = mode_2592x1944_regs, 1738 }, 1739 .link_freq_index = OV5670_LINK_FREQ_420MHZ_INDEX, 1740 }, 1741 { 1742 .width = 1296, 1743 .height = 972, 1744 .vts = OV5670_VTS_30FPS, 1745 .reg_list = { 1746 .num_of_regs = ARRAY_SIZE(mode_1296x972_regs), 1747 .regs = mode_1296x972_regs, 1748 }, 1749 .link_freq_index = OV5670_LINK_FREQ_420MHZ_INDEX, 1750 }, 1751 { 1752 .width = 648, 1753 .height = 486, 1754 .vts = OV5670_VTS_30FPS, 1755 .reg_list = { 1756 .num_of_regs = ARRAY_SIZE(mode_648x486_regs), 1757 .regs = mode_648x486_regs, 1758 }, 1759 .link_freq_index = OV5670_LINK_FREQ_420MHZ_INDEX, 1760 }, 1761 { 1762 .width = 2560, 1763 .height = 1440, 1764 .vts = OV5670_VTS_30FPS, 1765 .reg_list = { 1766 .num_of_regs = ARRAY_SIZE(mode_2560x1440_regs), 1767 .regs = mode_2560x1440_regs, 1768 }, 1769 .link_freq_index = OV5670_LINK_FREQ_420MHZ_INDEX, 1770 }, 1771 { 1772 .width = 1280, 1773 .height = 720, 1774 .vts = OV5670_VTS_30FPS, 1775 .reg_list = { 1776 .num_of_regs = ARRAY_SIZE(mode_1280x720_regs), 1777 .regs = mode_1280x720_regs, 1778 }, 1779 .link_freq_index = OV5670_LINK_FREQ_420MHZ_INDEX, 1780 }, 1781 { 1782 .width = 640, 1783 .height = 360, 1784 .vts = OV5670_VTS_30FPS, 1785 .reg_list = { 1786 .num_of_regs = ARRAY_SIZE(mode_640x360_regs), 1787 .regs = mode_640x360_regs, 1788 }, 1789 .link_freq_index = OV5670_LINK_FREQ_420MHZ_INDEX, 1790 } 1791 }; 1792 1793 struct ov5670 { 1794 struct v4l2_subdev sd; 1795 struct media_pad pad; 1796 1797 struct v4l2_ctrl_handler ctrl_handler; 1798 /* V4L2 Controls */ 1799 struct v4l2_ctrl *link_freq; 1800 struct v4l2_ctrl *pixel_rate; 1801 struct v4l2_ctrl *vblank; 1802 struct v4l2_ctrl *hblank; 1803 struct v4l2_ctrl *exposure; 1804 1805 /* Current mode */ 1806 const struct ov5670_mode *cur_mode; 1807 1808 /* To serialize asynchronus callbacks */ 1809 struct mutex mutex; 1810 1811 /* Streaming on/off */ 1812 bool streaming; 1813 }; 1814 1815 #define to_ov5670(_sd) container_of(_sd, struct ov5670, sd) 1816 1817 /* Read registers up to 4 at a time */ 1818 static int ov5670_read_reg(struct ov5670 *ov5670, u16 reg, unsigned int len, 1819 u32 *val) 1820 { 1821 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 1822 struct i2c_msg msgs[2]; 1823 u8 *data_be_p; 1824 u32 data_be = 0; 1825 u16 reg_addr_be = cpu_to_be16(reg); 1826 int ret; 1827 1828 if (len > 4) 1829 return -EINVAL; 1830 1831 data_be_p = (u8 *)&data_be; 1832 /* Write register address */ 1833 msgs[0].addr = client->addr; 1834 msgs[0].flags = 0; 1835 msgs[0].len = 2; 1836 msgs[0].buf = (u8 *)®_addr_be; 1837 1838 /* Read data from register */ 1839 msgs[1].addr = client->addr; 1840 msgs[1].flags = I2C_M_RD; 1841 msgs[1].len = len; 1842 msgs[1].buf = &data_be_p[4 - len]; 1843 1844 ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 1845 if (ret != ARRAY_SIZE(msgs)) 1846 return -EIO; 1847 1848 *val = be32_to_cpu(data_be); 1849 1850 return 0; 1851 } 1852 1853 /* Write registers up to 4 at a time */ 1854 static int ov5670_write_reg(struct ov5670 *ov5670, u16 reg, unsigned int len, 1855 u32 val) 1856 { 1857 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 1858 int buf_i; 1859 int val_i; 1860 u8 buf[6]; 1861 u8 *val_p; 1862 1863 if (len > 4) 1864 return -EINVAL; 1865 1866 buf[0] = reg >> 8; 1867 buf[1] = reg & 0xff; 1868 1869 val = cpu_to_be32(val); 1870 val_p = (u8 *)&val; 1871 buf_i = 2; 1872 val_i = 4 - len; 1873 1874 while (val_i < 4) 1875 buf[buf_i++] = val_p[val_i++]; 1876 1877 if (i2c_master_send(client, buf, len + 2) != len + 2) 1878 return -EIO; 1879 1880 return 0; 1881 } 1882 1883 /* Write a list of registers */ 1884 static int ov5670_write_regs(struct ov5670 *ov5670, 1885 const struct ov5670_reg *regs, unsigned int len) 1886 { 1887 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 1888 unsigned int i; 1889 int ret; 1890 1891 for (i = 0; i < len; i++) { 1892 ret = ov5670_write_reg(ov5670, regs[i].address, 1, regs[i].val); 1893 if (ret) { 1894 dev_err_ratelimited( 1895 &client->dev, 1896 "Failed to write reg 0x%4.4x. error = %d\n", 1897 regs[i].address, ret); 1898 1899 return ret; 1900 } 1901 } 1902 1903 return 0; 1904 } 1905 1906 static int ov5670_write_reg_list(struct ov5670 *ov5670, 1907 const struct ov5670_reg_list *r_list) 1908 { 1909 return ov5670_write_regs(ov5670, r_list->regs, r_list->num_of_regs); 1910 } 1911 1912 /* Open sub-device */ 1913 static int ov5670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) 1914 { 1915 struct ov5670 *ov5670 = to_ov5670(sd); 1916 struct v4l2_mbus_framefmt *try_fmt = 1917 v4l2_subdev_get_try_format(sd, fh->pad, 0); 1918 1919 mutex_lock(&ov5670->mutex); 1920 1921 /* Initialize try_fmt */ 1922 try_fmt->width = ov5670->cur_mode->width; 1923 try_fmt->height = ov5670->cur_mode->height; 1924 try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10; 1925 try_fmt->field = V4L2_FIELD_NONE; 1926 1927 /* No crop or compose */ 1928 mutex_unlock(&ov5670->mutex); 1929 1930 return 0; 1931 } 1932 1933 static int ov5670_update_digital_gain(struct ov5670 *ov5670, u32 d_gain) 1934 { 1935 int ret; 1936 1937 ret = ov5670_write_reg(ov5670, OV5670_REG_R_DGTL_GAIN, 1938 OV5670_REG_VALUE_16BIT, d_gain); 1939 if (ret) 1940 return ret; 1941 1942 ret = ov5670_write_reg(ov5670, OV5670_REG_G_DGTL_GAIN, 1943 OV5670_REG_VALUE_16BIT, d_gain); 1944 if (ret) 1945 return ret; 1946 1947 return ov5670_write_reg(ov5670, OV5670_REG_B_DGTL_GAIN, 1948 OV5670_REG_VALUE_16BIT, d_gain); 1949 } 1950 1951 static int ov5670_enable_test_pattern(struct ov5670 *ov5670, u32 pattern) 1952 { 1953 u32 val; 1954 int ret; 1955 1956 /* Set the bayer order that we support */ 1957 ret = ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN_CTRL, 1958 OV5670_REG_VALUE_08BIT, 0); 1959 if (ret) 1960 return ret; 1961 1962 ret = ov5670_read_reg(ov5670, OV5670_REG_TEST_PATTERN, 1963 OV5670_REG_VALUE_08BIT, &val); 1964 if (ret) 1965 return ret; 1966 1967 if (pattern) 1968 val |= OV5670_TEST_PATTERN_ENABLE; 1969 else 1970 val &= ~OV5670_TEST_PATTERN_ENABLE; 1971 1972 return ov5670_write_reg(ov5670, OV5670_REG_TEST_PATTERN, 1973 OV5670_REG_VALUE_08BIT, val); 1974 } 1975 1976 /* Initialize control handlers */ 1977 static int ov5670_set_ctrl(struct v4l2_ctrl *ctrl) 1978 { 1979 struct ov5670 *ov5670 = container_of(ctrl->handler, 1980 struct ov5670, ctrl_handler); 1981 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 1982 s64 max; 1983 int ret = 0; 1984 1985 /* Propagate change of current control to all related controls */ 1986 switch (ctrl->id) { 1987 case V4L2_CID_VBLANK: 1988 /* Update max exposure while meeting expected vblanking */ 1989 max = ov5670->cur_mode->height + ctrl->val - 8; 1990 __v4l2_ctrl_modify_range(ov5670->exposure, 1991 ov5670->exposure->minimum, max, 1992 ov5670->exposure->step, max); 1993 break; 1994 } 1995 1996 /* V4L2 controls values will be applied only when power is already up */ 1997 if (pm_runtime_get_if_in_use(&client->dev) <= 0) 1998 return 0; 1999 2000 switch (ctrl->id) { 2001 case V4L2_CID_ANALOGUE_GAIN: 2002 ret = ov5670_write_reg(ov5670, OV5670_REG_ANALOG_GAIN, 2003 OV5670_REG_VALUE_16BIT, ctrl->val); 2004 break; 2005 case V4L2_CID_DIGITAL_GAIN: 2006 ret = ov5670_update_digital_gain(ov5670, ctrl->val); 2007 break; 2008 case V4L2_CID_EXPOSURE: 2009 /* 4 least significant bits of expsoure are fractional part */ 2010 ret = ov5670_write_reg(ov5670, OV5670_REG_EXPOSURE, 2011 OV5670_REG_VALUE_24BIT, ctrl->val << 4); 2012 break; 2013 case V4L2_CID_VBLANK: 2014 /* Update VTS that meets expected vertical blanking */ 2015 ret = ov5670_write_reg(ov5670, OV5670_REG_VTS, 2016 OV5670_REG_VALUE_16BIT, 2017 ov5670->cur_mode->height + ctrl->val); 2018 break; 2019 case V4L2_CID_HBLANK: 2020 /* Update HTS that meets expected horizontal blanking */ 2021 ret = ov5670_write_reg(ov5670, OV5670_REG_HTS, 2022 OV5670_REG_VALUE_16BIT, 2023 (ov5670->cur_mode->width + 2024 ctrl->val) / 2); 2025 break; 2026 case V4L2_CID_TEST_PATTERN: 2027 ret = ov5670_enable_test_pattern(ov5670, ctrl->val); 2028 break; 2029 default: 2030 dev_info(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n", 2031 __func__, ctrl->id, ctrl->val); 2032 break; 2033 } 2034 2035 pm_runtime_put(&client->dev); 2036 2037 return ret; 2038 } 2039 2040 static const struct v4l2_ctrl_ops ov5670_ctrl_ops = { 2041 .s_ctrl = ov5670_set_ctrl, 2042 }; 2043 2044 /* Initialize control handlers */ 2045 static int ov5670_init_controls(struct ov5670 *ov5670) 2046 { 2047 struct v4l2_ctrl_handler *ctrl_hdlr; 2048 s64 vblank_max; 2049 s64 vblank_def; 2050 s64 exposure_max; 2051 int ret; 2052 2053 ctrl_hdlr = &ov5670->ctrl_handler; 2054 ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8); 2055 if (ret) 2056 return ret; 2057 2058 ctrl_hdlr->lock = &ov5670->mutex; 2059 ov5670->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr, 2060 &ov5670_ctrl_ops, 2061 V4L2_CID_LINK_FREQ, 2062 0, 0, link_freq_menu_items); 2063 if (ov5670->link_freq) 2064 ov5670->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; 2065 2066 /* By default, V4L2_CID_PIXEL_RATE is read only */ 2067 ov5670->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, 2068 V4L2_CID_PIXEL_RATE, 0, 2069 link_freq_configs[0].pixel_rate, 2070 1, 2071 link_freq_configs[0].pixel_rate); 2072 2073 vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height; 2074 vblank_def = ov5670->cur_mode->vts - ov5670->cur_mode->height; 2075 ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, 2076 V4L2_CID_VBLANK, OV5670_VBLANK_MIN, 2077 vblank_max, 1, vblank_def); 2078 2079 ov5670->hblank = v4l2_ctrl_new_std( 2080 ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_HBLANK, 2081 OV5670_DEF_PPL - ov5670->cur_mode->width, 2082 OV5670_DEF_PPL - ov5670->cur_mode->width, 1, 2083 OV5670_DEF_PPL - ov5670->cur_mode->width); 2084 2085 /* Get min, max, step, default from sensor */ 2086 v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_ANALOGUE_GAIN, 2087 ANALOG_GAIN_MIN, ANALOG_GAIN_MAX, ANALOG_GAIN_STEP, 2088 ANALOG_GAIN_DEFAULT); 2089 2090 /* Digital gain */ 2091 v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, V4L2_CID_DIGITAL_GAIN, 2092 OV5670_DGTL_GAIN_MIN, OV5670_DGTL_GAIN_MAX, 2093 OV5670_DGTL_GAIN_STEP, OV5670_DGTL_GAIN_DEFAULT); 2094 2095 /* Get min, max, step, default from sensor */ 2096 exposure_max = ov5670->cur_mode->vts - 8; 2097 ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, 2098 V4L2_CID_EXPOSURE, 2099 OV5670_EXPOSURE_MIN, 2100 exposure_max, OV5670_EXPOSURE_STEP, 2101 exposure_max); 2102 2103 v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &ov5670_ctrl_ops, 2104 V4L2_CID_TEST_PATTERN, 2105 ARRAY_SIZE(ov5670_test_pattern_menu) - 1, 2106 0, 0, ov5670_test_pattern_menu); 2107 2108 if (ctrl_hdlr->error) { 2109 ret = ctrl_hdlr->error; 2110 goto error; 2111 } 2112 2113 ov5670->sd.ctrl_handler = ctrl_hdlr; 2114 2115 return 0; 2116 2117 error: 2118 v4l2_ctrl_handler_free(ctrl_hdlr); 2119 2120 return ret; 2121 } 2122 2123 static int ov5670_enum_mbus_code(struct v4l2_subdev *sd, 2124 struct v4l2_subdev_pad_config *cfg, 2125 struct v4l2_subdev_mbus_code_enum *code) 2126 { 2127 /* Only one bayer order GRBG is supported */ 2128 if (code->index > 0) 2129 return -EINVAL; 2130 2131 code->code = MEDIA_BUS_FMT_SGRBG10_1X10; 2132 2133 return 0; 2134 } 2135 2136 static int ov5670_enum_frame_size(struct v4l2_subdev *sd, 2137 struct v4l2_subdev_pad_config *cfg, 2138 struct v4l2_subdev_frame_size_enum *fse) 2139 { 2140 if (fse->index >= ARRAY_SIZE(supported_modes)) 2141 return -EINVAL; 2142 2143 if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10) 2144 return -EINVAL; 2145 2146 fse->min_width = supported_modes[fse->index].width; 2147 fse->max_width = fse->min_width; 2148 fse->min_height = supported_modes[fse->index].height; 2149 fse->max_height = fse->min_height; 2150 2151 return 0; 2152 } 2153 2154 /* Calculate resolution distance */ 2155 static int ov5670_get_reso_dist(const struct ov5670_mode *mode, 2156 struct v4l2_mbus_framefmt *framefmt) 2157 { 2158 return abs(mode->width - framefmt->width) + 2159 abs(mode->height - framefmt->height); 2160 } 2161 2162 /* Find the closest supported resolution to the requested resolution */ 2163 static const struct ov5670_mode *ov5670_find_best_fit( 2164 struct ov5670 *ov5670, 2165 struct v4l2_subdev_format *fmt) 2166 { 2167 struct v4l2_mbus_framefmt *framefmt = &fmt->format; 2168 int dist; 2169 int cur_best_fit = 0; 2170 int cur_best_fit_dist = -1; 2171 int i; 2172 2173 for (i = 0; i < ARRAY_SIZE(supported_modes); i++) { 2174 dist = ov5670_get_reso_dist(&supported_modes[i], framefmt); 2175 if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) { 2176 cur_best_fit_dist = dist; 2177 cur_best_fit = i; 2178 } 2179 } 2180 2181 return &supported_modes[cur_best_fit]; 2182 } 2183 2184 static void ov5670_update_pad_format(const struct ov5670_mode *mode, 2185 struct v4l2_subdev_format *fmt) 2186 { 2187 fmt->format.width = mode->width; 2188 fmt->format.height = mode->height; 2189 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; 2190 fmt->format.field = V4L2_FIELD_NONE; 2191 } 2192 2193 static int ov5670_do_get_pad_format(struct ov5670 *ov5670, 2194 struct v4l2_subdev_pad_config *cfg, 2195 struct v4l2_subdev_format *fmt) 2196 { 2197 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) 2198 fmt->format = *v4l2_subdev_get_try_format(&ov5670->sd, cfg, 2199 fmt->pad); 2200 else 2201 ov5670_update_pad_format(ov5670->cur_mode, fmt); 2202 2203 return 0; 2204 } 2205 2206 static int ov5670_get_pad_format(struct v4l2_subdev *sd, 2207 struct v4l2_subdev_pad_config *cfg, 2208 struct v4l2_subdev_format *fmt) 2209 { 2210 struct ov5670 *ov5670 = to_ov5670(sd); 2211 int ret; 2212 2213 mutex_lock(&ov5670->mutex); 2214 ret = ov5670_do_get_pad_format(ov5670, cfg, fmt); 2215 mutex_unlock(&ov5670->mutex); 2216 2217 return ret; 2218 } 2219 2220 static int ov5670_set_pad_format(struct v4l2_subdev *sd, 2221 struct v4l2_subdev_pad_config *cfg, 2222 struct v4l2_subdev_format *fmt) 2223 { 2224 struct ov5670 *ov5670 = to_ov5670(sd); 2225 const struct ov5670_mode *mode; 2226 s32 vblank_def; 2227 s32 h_blank; 2228 2229 mutex_lock(&ov5670->mutex); 2230 2231 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10; 2232 2233 mode = ov5670_find_best_fit(ov5670, fmt); 2234 ov5670_update_pad_format(mode, fmt); 2235 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) { 2236 *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format; 2237 } else { 2238 ov5670->cur_mode = mode; 2239 __v4l2_ctrl_s_ctrl(ov5670->link_freq, mode->link_freq_index); 2240 __v4l2_ctrl_s_ctrl_int64( 2241 ov5670->pixel_rate, 2242 link_freq_configs[mode->link_freq_index].pixel_rate); 2243 /* Update limits and set FPS to default */ 2244 vblank_def = ov5670->cur_mode->vts - ov5670->cur_mode->height; 2245 __v4l2_ctrl_modify_range( 2246 ov5670->vblank, OV5670_VBLANK_MIN, 2247 OV5670_VTS_MAX - ov5670->cur_mode->height, 1, 2248 vblank_def); 2249 __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def); 2250 h_blank = OV5670_DEF_PPL - ov5670->cur_mode->width; 2251 __v4l2_ctrl_modify_range(ov5670->hblank, h_blank, h_blank, 1, 2252 h_blank); 2253 } 2254 2255 mutex_unlock(&ov5670->mutex); 2256 2257 return 0; 2258 } 2259 2260 static int ov5670_get_skip_frames(struct v4l2_subdev *sd, u32 *frames) 2261 { 2262 *frames = OV5670_NUM_OF_SKIP_FRAMES; 2263 2264 return 0; 2265 } 2266 2267 /* Prepare streaming by writing default values and customized values */ 2268 static int ov5670_start_streaming(struct ov5670 *ov5670) 2269 { 2270 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2271 const struct ov5670_reg_list *reg_list; 2272 int link_freq_index; 2273 int ret; 2274 2275 /* Get out of from software reset */ 2276 ret = ov5670_write_reg(ov5670, OV5670_REG_SOFTWARE_RST, 2277 OV5670_REG_VALUE_08BIT, OV5670_SOFTWARE_RST); 2278 if (ret) { 2279 dev_err(&client->dev, "%s failed to set powerup registers\n", 2280 __func__); 2281 return ret; 2282 } 2283 2284 /* Setup PLL */ 2285 link_freq_index = ov5670->cur_mode->link_freq_index; 2286 reg_list = &link_freq_configs[link_freq_index].reg_list; 2287 ret = ov5670_write_reg_list(ov5670, reg_list); 2288 if (ret) { 2289 dev_err(&client->dev, "%s failed to set plls\n", __func__); 2290 return ret; 2291 } 2292 2293 /* Apply default values of current mode */ 2294 reg_list = &ov5670->cur_mode->reg_list; 2295 ret = ov5670_write_reg_list(ov5670, reg_list); 2296 if (ret) { 2297 dev_err(&client->dev, "%s failed to set mode\n", __func__); 2298 return ret; 2299 } 2300 2301 ret = __v4l2_ctrl_handler_setup(ov5670->sd.ctrl_handler); 2302 if (ret) 2303 return ret; 2304 2305 /* Write stream on list */ 2306 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT, 2307 OV5670_REG_VALUE_08BIT, OV5670_MODE_STREAMING); 2308 if (ret) { 2309 dev_err(&client->dev, "%s failed to set stream\n", __func__); 2310 return ret; 2311 } 2312 2313 ov5670->streaming = true; 2314 2315 return 0; 2316 } 2317 2318 static int ov5670_stop_streaming(struct ov5670 *ov5670) 2319 { 2320 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2321 int ret; 2322 2323 ret = ov5670_write_reg(ov5670, OV5670_REG_MODE_SELECT, 2324 OV5670_REG_VALUE_08BIT, OV5670_MODE_STANDBY); 2325 if (ret) 2326 dev_err(&client->dev, "%s failed to set stream\n", __func__); 2327 2328 ov5670->streaming = false; 2329 2330 /* Return success even if it was an error, as there is nothing the 2331 * caller can do about it. 2332 */ 2333 return 0; 2334 } 2335 2336 static int ov5670_set_stream(struct v4l2_subdev *sd, int enable) 2337 { 2338 struct ov5670 *ov5670 = to_ov5670(sd); 2339 struct i2c_client *client = v4l2_get_subdevdata(sd); 2340 int ret = 0; 2341 2342 mutex_lock(&ov5670->mutex); 2343 if (ov5670->streaming == enable) 2344 goto unlock_and_return; 2345 2346 if (enable) { 2347 ret = pm_runtime_get_sync(&client->dev); 2348 if (ret < 0) { 2349 pm_runtime_put_noidle(&client->dev); 2350 goto unlock_and_return; 2351 } 2352 2353 ret = ov5670_start_streaming(ov5670); 2354 if (ret) 2355 goto error; 2356 } else { 2357 ret = ov5670_stop_streaming(ov5670); 2358 pm_runtime_put(&client->dev); 2359 } 2360 goto unlock_and_return; 2361 2362 error: 2363 pm_runtime_put(&client->dev); 2364 2365 unlock_and_return: 2366 mutex_unlock(&ov5670->mutex); 2367 2368 return ret; 2369 } 2370 2371 static int __maybe_unused ov5670_suspend(struct device *dev) 2372 { 2373 struct i2c_client *client = to_i2c_client(dev); 2374 struct v4l2_subdev *sd = i2c_get_clientdata(client); 2375 struct ov5670 *ov5670 = to_ov5670(sd); 2376 2377 if (ov5670->streaming) 2378 ov5670_stop_streaming(ov5670); 2379 2380 return 0; 2381 } 2382 2383 static int __maybe_unused ov5670_resume(struct device *dev) 2384 { 2385 struct i2c_client *client = to_i2c_client(dev); 2386 struct v4l2_subdev *sd = i2c_get_clientdata(client); 2387 struct ov5670 *ov5670 = to_ov5670(sd); 2388 int ret; 2389 2390 if (ov5670->streaming) { 2391 ret = ov5670_start_streaming(ov5670); 2392 if (ret) { 2393 ov5670_stop_streaming(ov5670); 2394 return ret; 2395 } 2396 } 2397 2398 return 0; 2399 } 2400 2401 /* Verify chip ID */ 2402 static int ov5670_identify_module(struct ov5670 *ov5670) 2403 { 2404 struct i2c_client *client = v4l2_get_subdevdata(&ov5670->sd); 2405 int ret; 2406 u32 val; 2407 2408 ret = ov5670_read_reg(ov5670, OV5670_REG_CHIP_ID, 2409 OV5670_REG_VALUE_24BIT, &val); 2410 if (ret) 2411 return ret; 2412 2413 if (val != OV5670_CHIP_ID) { 2414 dev_err(&client->dev, "chip id mismatch: %x!=%x\n", 2415 OV5670_CHIP_ID, val); 2416 return -ENXIO; 2417 } 2418 2419 return 0; 2420 } 2421 2422 static const struct v4l2_subdev_video_ops ov5670_video_ops = { 2423 .s_stream = ov5670_set_stream, 2424 }; 2425 2426 static const struct v4l2_subdev_pad_ops ov5670_pad_ops = { 2427 .enum_mbus_code = ov5670_enum_mbus_code, 2428 .get_fmt = ov5670_get_pad_format, 2429 .set_fmt = ov5670_set_pad_format, 2430 .enum_frame_size = ov5670_enum_frame_size, 2431 }; 2432 2433 static const struct v4l2_subdev_sensor_ops ov5670_sensor_ops = { 2434 .g_skip_frames = ov5670_get_skip_frames, 2435 }; 2436 2437 static const struct v4l2_subdev_ops ov5670_subdev_ops = { 2438 .video = &ov5670_video_ops, 2439 .pad = &ov5670_pad_ops, 2440 .sensor = &ov5670_sensor_ops, 2441 }; 2442 2443 static const struct media_entity_operations ov5670_subdev_entity_ops = { 2444 .link_validate = v4l2_subdev_link_validate, 2445 }; 2446 2447 static const struct v4l2_subdev_internal_ops ov5670_internal_ops = { 2448 .open = ov5670_open, 2449 }; 2450 2451 static int ov5670_probe(struct i2c_client *client) 2452 { 2453 struct ov5670 *ov5670; 2454 const char *err_msg; 2455 u32 input_clk = 0; 2456 int ret; 2457 2458 device_property_read_u32(&client->dev, "clock-frequency", &input_clk); 2459 if (input_clk != 19200000) 2460 return -EINVAL; 2461 2462 ov5670 = devm_kzalloc(&client->dev, sizeof(*ov5670), GFP_KERNEL); 2463 if (!ov5670) { 2464 ret = -ENOMEM; 2465 err_msg = "devm_kzalloc() error"; 2466 goto error_print; 2467 } 2468 2469 /* Initialize subdev */ 2470 v4l2_i2c_subdev_init(&ov5670->sd, client, &ov5670_subdev_ops); 2471 2472 /* Check module identity */ 2473 ret = ov5670_identify_module(ov5670); 2474 if (ret) { 2475 err_msg = "ov5670_identify_module() error"; 2476 goto error_print; 2477 } 2478 2479 mutex_init(&ov5670->mutex); 2480 2481 /* Set default mode to max resolution */ 2482 ov5670->cur_mode = &supported_modes[0]; 2483 2484 ret = ov5670_init_controls(ov5670); 2485 if (ret) { 2486 err_msg = "ov5670_init_controls() error"; 2487 goto error_mutex_destroy; 2488 } 2489 2490 ov5670->sd.internal_ops = &ov5670_internal_ops; 2491 ov5670->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; 2492 ov5670->sd.entity.ops = &ov5670_subdev_entity_ops; 2493 ov5670->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; 2494 2495 /* Source pad initialization */ 2496 ov5670->pad.flags = MEDIA_PAD_FL_SOURCE; 2497 ret = media_entity_pads_init(&ov5670->sd.entity, 1, &ov5670->pad); 2498 if (ret) { 2499 err_msg = "media_entity_pads_init() error"; 2500 goto error_handler_free; 2501 } 2502 2503 /* Async register for subdev */ 2504 ret = v4l2_async_register_subdev(&ov5670->sd); 2505 if (ret < 0) { 2506 err_msg = "v4l2_async_register_subdev() error"; 2507 goto error_entity_cleanup; 2508 } 2509 2510 ov5670->streaming = false; 2511 2512 /* 2513 * Device is already turned on by i2c-core with ACPI domain PM. 2514 * Enable runtime PM and turn off the device. 2515 */ 2516 pm_runtime_get_noresume(&client->dev); 2517 pm_runtime_set_active(&client->dev); 2518 pm_runtime_enable(&client->dev); 2519 pm_runtime_put(&client->dev); 2520 2521 return 0; 2522 2523 error_entity_cleanup: 2524 media_entity_cleanup(&ov5670->sd.entity); 2525 2526 error_handler_free: 2527 v4l2_ctrl_handler_free(ov5670->sd.ctrl_handler); 2528 2529 error_mutex_destroy: 2530 mutex_destroy(&ov5670->mutex); 2531 2532 error_print: 2533 dev_err(&client->dev, "%s: %s %d\n", __func__, err_msg, ret); 2534 2535 return ret; 2536 } 2537 2538 static int ov5670_remove(struct i2c_client *client) 2539 { 2540 struct v4l2_subdev *sd = i2c_get_clientdata(client); 2541 struct ov5670 *ov5670 = to_ov5670(sd); 2542 2543 v4l2_async_unregister_subdev(sd); 2544 media_entity_cleanup(&sd->entity); 2545 v4l2_ctrl_handler_free(sd->ctrl_handler); 2546 mutex_destroy(&ov5670->mutex); 2547 2548 /* 2549 * Disable runtime PM but keep the device turned on. 2550 * i2c-core with ACPI domain PM will turn off the device. 2551 */ 2552 pm_runtime_get_sync(&client->dev); 2553 pm_runtime_disable(&client->dev); 2554 pm_runtime_set_suspended(&client->dev); 2555 pm_runtime_put_noidle(&client->dev); 2556 2557 return 0; 2558 } 2559 2560 static const struct dev_pm_ops ov5670_pm_ops = { 2561 SET_SYSTEM_SLEEP_PM_OPS(ov5670_suspend, ov5670_resume) 2562 }; 2563 2564 #ifdef CONFIG_ACPI 2565 static const struct acpi_device_id ov5670_acpi_ids[] = { 2566 {"INT3479"}, 2567 { /* sentinel */ } 2568 }; 2569 2570 MODULE_DEVICE_TABLE(acpi, ov5670_acpi_ids); 2571 #endif 2572 2573 static struct i2c_driver ov5670_i2c_driver = { 2574 .driver = { 2575 .name = "ov5670", 2576 .pm = &ov5670_pm_ops, 2577 .acpi_match_table = ACPI_PTR(ov5670_acpi_ids), 2578 }, 2579 .probe_new = ov5670_probe, 2580 .remove = ov5670_remove, 2581 }; 2582 2583 module_i2c_driver(ov5670_i2c_driver); 2584 2585 MODULE_AUTHOR("Rapolu, Chiranjeevi <chiranjeevi.rapolu@intel.com>"); 2586 MODULE_AUTHOR("Yang, Hyungwoo <hyungwoo.yang@intel.com>"); 2587 MODULE_DESCRIPTION("Omnivision ov5670 sensor driver"); 2588 MODULE_LICENSE("GPL v2"); 2589