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