1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Omnivision OV2680 CMOS Image Sensor driver 4 * 5 * Copyright (C) 2018 Linaro Ltd 6 * 7 * Based on OV5640 Sensor Driver 8 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved. 9 * Copyright (C) 2014-2017 Mentor Graphics Inc. 10 * 11 */ 12 13 #include <linux/clk.h> 14 #include <linux/delay.h> 15 #include <linux/err.h> 16 #include <linux/gpio/consumer.h> 17 #include <linux/i2c.h> 18 #include <linux/init.h> 19 #include <linux/mod_devicetable.h> 20 #include <linux/module.h> 21 #include <linux/pm_runtime.h> 22 #include <linux/regmap.h> 23 #include <linux/regulator/consumer.h> 24 25 #include <media/v4l2-cci.h> 26 #include <media/v4l2-common.h> 27 #include <media/v4l2-ctrls.h> 28 #include <media/v4l2-fwnode.h> 29 #include <media/v4l2-subdev.h> 30 31 #define OV2680_CHIP_ID 0x2680 32 33 #define OV2680_REG_STREAM_CTRL CCI_REG8(0x0100) 34 #define OV2680_REG_SOFT_RESET CCI_REG8(0x0103) 35 36 #define OV2680_REG_CHIP_ID CCI_REG16(0x300a) 37 #define OV2680_REG_SC_CMMN_SUB_ID CCI_REG8(0x302a) 38 #define OV2680_REG_PLL_MULTIPLIER CCI_REG16(0x3081) 39 40 #define OV2680_REG_EXPOSURE_PK CCI_REG24(0x3500) 41 #define OV2680_REG_R_MANUAL CCI_REG8(0x3503) 42 #define OV2680_REG_GAIN_PK CCI_REG16(0x350a) 43 44 #define OV2680_REG_SENSOR_CTRL_0A CCI_REG8(0x370a) 45 46 #define OV2680_REG_HORIZONTAL_START CCI_REG16(0x3800) 47 #define OV2680_REG_VERTICAL_START CCI_REG16(0x3802) 48 #define OV2680_REG_HORIZONTAL_END CCI_REG16(0x3804) 49 #define OV2680_REG_VERTICAL_END CCI_REG16(0x3806) 50 #define OV2680_REG_HORIZONTAL_OUTPUT_SIZE CCI_REG16(0x3808) 51 #define OV2680_REG_VERTICAL_OUTPUT_SIZE CCI_REG16(0x380a) 52 #define OV2680_REG_TIMING_HTS CCI_REG16(0x380c) 53 #define OV2680_REG_TIMING_VTS CCI_REG16(0x380e) 54 #define OV2680_REG_ISP_X_WIN CCI_REG16(0x3810) 55 #define OV2680_REG_ISP_Y_WIN CCI_REG16(0x3812) 56 #define OV2680_REG_X_INC CCI_REG8(0x3814) 57 #define OV2680_REG_Y_INC CCI_REG8(0x3815) 58 #define OV2680_REG_FORMAT1 CCI_REG8(0x3820) 59 #define OV2680_REG_FORMAT2 CCI_REG8(0x3821) 60 61 #define OV2680_REG_ISP_CTRL00 CCI_REG8(0x5080) 62 63 #define OV2680_REG_X_WIN CCI_REG16(0x5704) 64 #define OV2680_REG_Y_WIN CCI_REG16(0x5706) 65 66 #define OV2680_FRAME_RATE 30 67 68 #define OV2680_NATIVE_WIDTH 1616 69 #define OV2680_NATIVE_HEIGHT 1216 70 #define OV2680_NATIVE_START_LEFT 0 71 #define OV2680_NATIVE_START_TOP 0 72 #define OV2680_ACTIVE_WIDTH 1600 73 #define OV2680_ACTIVE_HEIGHT 1200 74 #define OV2680_ACTIVE_START_LEFT 8 75 #define OV2680_ACTIVE_START_TOP 8 76 #define OV2680_MIN_CROP_WIDTH 2 77 #define OV2680_MIN_CROP_HEIGHT 2 78 79 /* Fixed pre-div of 1/2 */ 80 #define OV2680_PLL_PREDIV0 2 81 82 /* Pre-div configurable through reg 0x3080, left at its default of 0x02 : 1/2 */ 83 #define OV2680_PLL_PREDIV 2 84 85 /* 66MHz pixel clock: 66MHz / 1704 * 1294 = 30fps */ 86 #define OV2680_PIXELS_PER_LINE 1704 87 #define OV2680_LINES_PER_FRAME 1294 88 89 /* If possible send 16 extra rows / lines to the ISP as padding */ 90 #define OV2680_END_MARGIN 16 91 92 /* Max exposure time is VTS - 8 */ 93 #define OV2680_INTEGRATION_TIME_MARGIN 8 94 95 #define OV2680_DEFAULT_WIDTH 800 96 #define OV2680_DEFAULT_HEIGHT 600 97 98 /* For enum_frame_size() full-size + binned-/quarter-size */ 99 #define OV2680_FRAME_SIZES 2 100 101 static const char * const ov2680_supply_name[] = { 102 "DOVDD", 103 "DVDD", 104 "AVDD", 105 }; 106 107 #define OV2680_NUM_SUPPLIES ARRAY_SIZE(ov2680_supply_name) 108 109 enum { 110 OV2680_19_2_MHZ, 111 OV2680_24_MHZ, 112 }; 113 114 static const unsigned long ov2680_xvclk_freqs[] = { 115 [OV2680_19_2_MHZ] = 19200000, 116 [OV2680_24_MHZ] = 24000000, 117 }; 118 119 static const u8 ov2680_pll_multipliers[] = { 120 [OV2680_19_2_MHZ] = 69, 121 [OV2680_24_MHZ] = 55, 122 }; 123 124 struct ov2680_ctrls { 125 struct v4l2_ctrl_handler handler; 126 struct v4l2_ctrl *exposure; 127 struct v4l2_ctrl *gain; 128 struct v4l2_ctrl *hflip; 129 struct v4l2_ctrl *vflip; 130 struct v4l2_ctrl *test_pattern; 131 struct v4l2_ctrl *link_freq; 132 struct v4l2_ctrl *pixel_rate; 133 }; 134 135 struct ov2680_mode { 136 struct v4l2_rect crop; 137 struct v4l2_mbus_framefmt fmt; 138 struct v4l2_fract frame_interval; 139 bool binning; 140 u16 h_start; 141 u16 v_start; 142 u16 h_end; 143 u16 v_end; 144 u16 h_output_size; 145 u16 v_output_size; 146 u16 hts; 147 u16 vts; 148 }; 149 150 struct ov2680_dev { 151 struct device *dev; 152 struct regmap *regmap; 153 struct v4l2_subdev sd; 154 155 struct media_pad pad; 156 struct clk *xvclk; 157 u32 xvclk_freq; 158 u8 pll_mult; 159 s64 link_freq[1]; 160 u64 pixel_rate; 161 struct regulator_bulk_data supplies[OV2680_NUM_SUPPLIES]; 162 163 struct gpio_desc *pwdn_gpio; 164 struct mutex lock; /* protect members */ 165 166 bool is_streaming; 167 168 struct ov2680_ctrls ctrls; 169 struct ov2680_mode mode; 170 }; 171 172 static const struct v4l2_rect ov2680_default_crop = { 173 .left = OV2680_ACTIVE_START_LEFT, 174 .top = OV2680_ACTIVE_START_TOP, 175 .width = OV2680_ACTIVE_WIDTH, 176 .height = OV2680_ACTIVE_HEIGHT, 177 }; 178 179 static const char * const test_pattern_menu[] = { 180 "Disabled", 181 "Color Bars", 182 "Random Data", 183 "Square", 184 "Black Image", 185 }; 186 187 static const int ov2680_hv_flip_bayer_order[] = { 188 MEDIA_BUS_FMT_SBGGR10_1X10, 189 MEDIA_BUS_FMT_SGRBG10_1X10, 190 MEDIA_BUS_FMT_SGBRG10_1X10, 191 MEDIA_BUS_FMT_SRGGB10_1X10, 192 }; 193 194 static const struct reg_sequence ov2680_global_setting[] = { 195 /* MIPI PHY, 0x10 -> 0x1c enable bp_c_hs_en_lat and bp_d_hs_en_lat */ 196 {0x3016, 0x1c}, 197 198 /* R MANUAL set exposure and gain to manual (hw does not do auto) */ 199 {0x3503, 0x03}, 200 201 /* Analog control register tweaks */ 202 {0x3603, 0x39}, /* Reset value 0x99 */ 203 {0x3604, 0x24}, /* Reset value 0x74 */ 204 {0x3621, 0x37}, /* Reset value 0x44 */ 205 206 /* Sensor control register tweaks */ 207 {0x3701, 0x64}, /* Reset value 0x61 */ 208 {0x3705, 0x3c}, /* Reset value 0x21 */ 209 {0x370c, 0x50}, /* Reset value 0x10 */ 210 {0x370d, 0xc0}, /* Reset value 0x00 */ 211 {0x3718, 0x88}, /* Reset value 0x80 */ 212 213 /* PSRAM tweaks */ 214 {0x3781, 0x80}, /* Reset value 0x00 */ 215 {0x3784, 0x0c}, /* Reset value 0x00, based on OV2680_R1A_AM10.ovt */ 216 {0x3789, 0x60}, /* Reset value 0x50 */ 217 218 /* BLC CTRL00 0x01 -> 0x81 set avg_weight to 8 */ 219 {0x4000, 0x81}, 220 221 /* Set black level compensation range to 0 - 3 (default 0 - 11) */ 222 {0x4008, 0x00}, 223 {0x4009, 0x03}, 224 225 /* VFIFO R2 0x00 -> 0x02 set Frame reset enable */ 226 {0x4602, 0x02}, 227 228 /* MIPI ctrl CLK PREPARE MIN change from 0x26 (38) -> 0x36 (54) */ 229 {0x481f, 0x36}, 230 231 /* MIPI ctrl CLK LPX P MIN change from 0x32 (50) -> 0x36 (54) */ 232 {0x4825, 0x36}, 233 234 /* R ISP CTRL2 0x20 -> 0x30, set sof_sel bit */ 235 {0x5002, 0x30}, 236 237 /* 238 * Window CONTROL 0x00 -> 0x01, enable manual window control, 239 * this is necessary for full size flip and mirror support. 240 */ 241 {0x5708, 0x01}, 242 243 /* 244 * DPC CTRL0 0x14 -> 0x3e, set enable_tail, enable_3x3_cluster 245 * and enable_general_tail bits based OV2680_R1A_AM10.ovt. 246 */ 247 {0x5780, 0x3e}, 248 249 /* DPC MORE CONNECTION CASE THRE 0x0c (12) -> 0x02 (2) */ 250 {0x5788, 0x02}, 251 252 /* DPC GAIN LIST1 0x0f (15) -> 0x08 (8) */ 253 {0x578e, 0x08}, 254 255 /* DPC GAIN LIST2 0x3f (63) -> 0x0c (12) */ 256 {0x578f, 0x0c}, 257 258 /* DPC THRE RATIO 0x04 (4) -> 0x00 (0) */ 259 {0x5792, 0x00}, 260 }; 261 262 static struct ov2680_dev *to_ov2680_dev(struct v4l2_subdev *sd) 263 { 264 return container_of(sd, struct ov2680_dev, sd); 265 } 266 267 static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl) 268 { 269 return &container_of(ctrl->handler, struct ov2680_dev, 270 ctrls.handler)->sd; 271 } 272 273 static void ov2680_power_up(struct ov2680_dev *sensor) 274 { 275 if (!sensor->pwdn_gpio) 276 return; 277 278 gpiod_set_value(sensor->pwdn_gpio, 0); 279 usleep_range(5000, 10000); 280 } 281 282 static void ov2680_power_down(struct ov2680_dev *sensor) 283 { 284 if (!sensor->pwdn_gpio) 285 return; 286 287 gpiod_set_value(sensor->pwdn_gpio, 1); 288 usleep_range(5000, 10000); 289 } 290 291 static void ov2680_set_bayer_order(struct ov2680_dev *sensor, 292 struct v4l2_mbus_framefmt *fmt) 293 { 294 int hv_flip = 0; 295 296 if (sensor->ctrls.vflip && sensor->ctrls.vflip->val) 297 hv_flip += 1; 298 299 if (sensor->ctrls.hflip && sensor->ctrls.hflip->val) 300 hv_flip += 2; 301 302 fmt->code = ov2680_hv_flip_bayer_order[hv_flip]; 303 } 304 305 static struct v4l2_mbus_framefmt * 306 __ov2680_get_pad_format(struct ov2680_dev *sensor, 307 struct v4l2_subdev_state *state, 308 unsigned int pad, 309 enum v4l2_subdev_format_whence which) 310 { 311 if (which == V4L2_SUBDEV_FORMAT_TRY) 312 return v4l2_subdev_state_get_format(state, pad); 313 314 return &sensor->mode.fmt; 315 } 316 317 static struct v4l2_rect * 318 __ov2680_get_pad_crop(struct ov2680_dev *sensor, 319 struct v4l2_subdev_state *state, 320 unsigned int pad, 321 enum v4l2_subdev_format_whence which) 322 { 323 if (which == V4L2_SUBDEV_FORMAT_TRY) 324 return v4l2_subdev_state_get_crop(state, pad); 325 326 return &sensor->mode.crop; 327 } 328 329 static void ov2680_fill_format(struct ov2680_dev *sensor, 330 struct v4l2_mbus_framefmt *fmt, 331 unsigned int width, unsigned int height) 332 { 333 memset(fmt, 0, sizeof(*fmt)); 334 fmt->width = width; 335 fmt->height = height; 336 fmt->field = V4L2_FIELD_NONE; 337 fmt->colorspace = V4L2_COLORSPACE_SRGB; 338 ov2680_set_bayer_order(sensor, fmt); 339 } 340 341 static void ov2680_calc_mode(struct ov2680_dev *sensor) 342 { 343 int width = sensor->mode.fmt.width; 344 int height = sensor->mode.fmt.height; 345 int orig_width = width; 346 int orig_height = height; 347 348 if (width <= (sensor->mode.crop.width / 2) && 349 height <= (sensor->mode.crop.height / 2)) { 350 sensor->mode.binning = true; 351 width *= 2; 352 height *= 2; 353 } else { 354 sensor->mode.binning = false; 355 } 356 357 sensor->mode.h_start = (sensor->mode.crop.left + 358 (sensor->mode.crop.width - width) / 2) & ~1; 359 sensor->mode.v_start = (sensor->mode.crop.top + 360 (sensor->mode.crop.height - height) / 2) & ~1; 361 sensor->mode.h_end = 362 min(sensor->mode.h_start + width + OV2680_END_MARGIN - 1, 363 OV2680_NATIVE_WIDTH - 1); 364 sensor->mode.v_end = 365 min(sensor->mode.v_start + height + OV2680_END_MARGIN - 1, 366 OV2680_NATIVE_HEIGHT - 1); 367 sensor->mode.h_output_size = orig_width; 368 sensor->mode.v_output_size = orig_height; 369 sensor->mode.hts = OV2680_PIXELS_PER_LINE; 370 sensor->mode.vts = OV2680_LINES_PER_FRAME; 371 } 372 373 static int ov2680_set_mode(struct ov2680_dev *sensor) 374 { 375 u8 sensor_ctrl_0a, inc, fmt1, fmt2; 376 int ret = 0; 377 378 if (sensor->mode.binning) { 379 sensor_ctrl_0a = 0x23; 380 inc = 0x31; 381 fmt1 = 0xc2; 382 fmt2 = 0x01; 383 } else { 384 sensor_ctrl_0a = 0x21; 385 inc = 0x11; 386 fmt1 = 0xc0; 387 fmt2 = 0x00; 388 } 389 390 cci_write(sensor->regmap, OV2680_REG_SENSOR_CTRL_0A, 391 sensor_ctrl_0a, &ret); 392 cci_write(sensor->regmap, OV2680_REG_HORIZONTAL_START, 393 sensor->mode.h_start, &ret); 394 cci_write(sensor->regmap, OV2680_REG_VERTICAL_START, 395 sensor->mode.v_start, &ret); 396 cci_write(sensor->regmap, OV2680_REG_HORIZONTAL_END, 397 sensor->mode.h_end, &ret); 398 cci_write(sensor->regmap, OV2680_REG_VERTICAL_END, 399 sensor->mode.v_end, &ret); 400 cci_write(sensor->regmap, OV2680_REG_HORIZONTAL_OUTPUT_SIZE, 401 sensor->mode.h_output_size, &ret); 402 cci_write(sensor->regmap, OV2680_REG_VERTICAL_OUTPUT_SIZE, 403 sensor->mode.v_output_size, &ret); 404 cci_write(sensor->regmap, OV2680_REG_TIMING_HTS, 405 sensor->mode.hts, &ret); 406 cci_write(sensor->regmap, OV2680_REG_TIMING_VTS, 407 sensor->mode.vts, &ret); 408 cci_write(sensor->regmap, OV2680_REG_ISP_X_WIN, 0, &ret); 409 cci_write(sensor->regmap, OV2680_REG_ISP_Y_WIN, 0, &ret); 410 cci_write(sensor->regmap, OV2680_REG_X_INC, inc, &ret); 411 cci_write(sensor->regmap, OV2680_REG_Y_INC, inc, &ret); 412 cci_write(sensor->regmap, OV2680_REG_X_WIN, 413 sensor->mode.h_output_size, &ret); 414 cci_write(sensor->regmap, OV2680_REG_Y_WIN, 415 sensor->mode.v_output_size, &ret); 416 cci_write(sensor->regmap, OV2680_REG_FORMAT1, fmt1, &ret); 417 cci_write(sensor->regmap, OV2680_REG_FORMAT2, fmt2, &ret); 418 419 return ret; 420 } 421 422 static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val) 423 { 424 int ret; 425 426 if (sensor->is_streaming) 427 return -EBUSY; 428 429 ret = cci_update_bits(sensor->regmap, OV2680_REG_FORMAT1, 430 BIT(2), val ? BIT(2) : 0, NULL); 431 if (ret < 0) 432 return ret; 433 434 ov2680_set_bayer_order(sensor, &sensor->mode.fmt); 435 return 0; 436 } 437 438 static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val) 439 { 440 int ret; 441 442 if (sensor->is_streaming) 443 return -EBUSY; 444 445 ret = cci_update_bits(sensor->regmap, OV2680_REG_FORMAT2, 446 BIT(2), val ? BIT(2) : 0, NULL); 447 if (ret < 0) 448 return ret; 449 450 ov2680_set_bayer_order(sensor, &sensor->mode.fmt); 451 return 0; 452 } 453 454 static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value) 455 { 456 int ret = 0; 457 458 if (!value) 459 return cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00, 460 BIT(7), 0, NULL); 461 462 cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00, 463 0x03, value - 1, &ret); 464 cci_update_bits(sensor->regmap, OV2680_REG_ISP_CTRL00, 465 BIT(7), BIT(7), &ret); 466 467 return ret; 468 } 469 470 static int ov2680_gain_set(struct ov2680_dev *sensor, u32 gain) 471 { 472 return cci_write(sensor->regmap, OV2680_REG_GAIN_PK, gain, NULL); 473 } 474 475 static int ov2680_exposure_set(struct ov2680_dev *sensor, u32 exp) 476 { 477 return cci_write(sensor->regmap, OV2680_REG_EXPOSURE_PK, exp << 4, 478 NULL); 479 } 480 481 static int ov2680_stream_enable(struct ov2680_dev *sensor) 482 { 483 int ret; 484 485 ret = cci_write(sensor->regmap, OV2680_REG_PLL_MULTIPLIER, 486 sensor->pll_mult, NULL); 487 if (ret < 0) 488 return ret; 489 490 ret = regmap_multi_reg_write(sensor->regmap, 491 ov2680_global_setting, 492 ARRAY_SIZE(ov2680_global_setting)); 493 if (ret < 0) 494 return ret; 495 496 ret = ov2680_set_mode(sensor); 497 if (ret < 0) 498 return ret; 499 500 /* Restore value of all ctrls */ 501 ret = __v4l2_ctrl_handler_setup(&sensor->ctrls.handler); 502 if (ret < 0) 503 return ret; 504 505 return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 1, NULL); 506 } 507 508 static int ov2680_stream_disable(struct ov2680_dev *sensor) 509 { 510 return cci_write(sensor->regmap, OV2680_REG_STREAM_CTRL, 0, NULL); 511 } 512 513 static int ov2680_power_off(struct ov2680_dev *sensor) 514 { 515 clk_disable_unprepare(sensor->xvclk); 516 ov2680_power_down(sensor); 517 regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies); 518 return 0; 519 } 520 521 static int ov2680_power_on(struct ov2680_dev *sensor) 522 { 523 int ret; 524 525 ret = regulator_bulk_enable(OV2680_NUM_SUPPLIES, sensor->supplies); 526 if (ret < 0) { 527 dev_err(sensor->dev, "failed to enable regulators: %d\n", ret); 528 return ret; 529 } 530 531 if (!sensor->pwdn_gpio) { 532 ret = cci_write(sensor->regmap, OV2680_REG_SOFT_RESET, 0x01, 533 NULL); 534 if (ret != 0) { 535 dev_err(sensor->dev, "sensor soft reset failed\n"); 536 goto err_disable_regulators; 537 } 538 usleep_range(1000, 2000); 539 } else { 540 ov2680_power_down(sensor); 541 ov2680_power_up(sensor); 542 } 543 544 ret = clk_prepare_enable(sensor->xvclk); 545 if (ret < 0) 546 goto err_disable_regulators; 547 548 return 0; 549 550 err_disable_regulators: 551 regulator_bulk_disable(OV2680_NUM_SUPPLIES, sensor->supplies); 552 return ret; 553 } 554 555 static int ov2680_s_g_frame_interval(struct v4l2_subdev *sd, 556 struct v4l2_subdev_frame_interval *fi) 557 { 558 struct ov2680_dev *sensor = to_ov2680_dev(sd); 559 560 mutex_lock(&sensor->lock); 561 fi->interval = sensor->mode.frame_interval; 562 mutex_unlock(&sensor->lock); 563 564 return 0; 565 } 566 567 static int ov2680_s_stream(struct v4l2_subdev *sd, int enable) 568 { 569 struct ov2680_dev *sensor = to_ov2680_dev(sd); 570 int ret = 0; 571 572 mutex_lock(&sensor->lock); 573 574 if (sensor->is_streaming == !!enable) 575 goto unlock; 576 577 if (enable) { 578 ret = pm_runtime_resume_and_get(sensor->sd.dev); 579 if (ret < 0) 580 goto unlock; 581 582 ret = ov2680_stream_enable(sensor); 583 if (ret < 0) { 584 pm_runtime_put(sensor->sd.dev); 585 goto unlock; 586 } 587 } else { 588 ret = ov2680_stream_disable(sensor); 589 pm_runtime_put(sensor->sd.dev); 590 } 591 592 sensor->is_streaming = !!enable; 593 594 unlock: 595 mutex_unlock(&sensor->lock); 596 597 return ret; 598 } 599 600 static int ov2680_enum_mbus_code(struct v4l2_subdev *sd, 601 struct v4l2_subdev_state *sd_state, 602 struct v4l2_subdev_mbus_code_enum *code) 603 { 604 struct ov2680_dev *sensor = to_ov2680_dev(sd); 605 606 if (code->index != 0) 607 return -EINVAL; 608 609 code->code = sensor->mode.fmt.code; 610 611 return 0; 612 } 613 614 static int ov2680_get_fmt(struct v4l2_subdev *sd, 615 struct v4l2_subdev_state *sd_state, 616 struct v4l2_subdev_format *format) 617 { 618 struct ov2680_dev *sensor = to_ov2680_dev(sd); 619 struct v4l2_mbus_framefmt *fmt; 620 621 fmt = __ov2680_get_pad_format(sensor, sd_state, format->pad, 622 format->which); 623 624 mutex_lock(&sensor->lock); 625 format->format = *fmt; 626 mutex_unlock(&sensor->lock); 627 628 return 0; 629 } 630 631 static int ov2680_set_fmt(struct v4l2_subdev *sd, 632 struct v4l2_subdev_state *sd_state, 633 struct v4l2_subdev_format *format) 634 { 635 struct ov2680_dev *sensor = to_ov2680_dev(sd); 636 struct v4l2_mbus_framefmt *try_fmt; 637 const struct v4l2_rect *crop; 638 unsigned int width, height; 639 int ret = 0; 640 641 crop = __ov2680_get_pad_crop(sensor, sd_state, format->pad, 642 format->which); 643 644 /* Limit set_fmt max size to crop width / height */ 645 width = clamp_val(ALIGN(format->format.width, 2), 646 OV2680_MIN_CROP_WIDTH, crop->width); 647 height = clamp_val(ALIGN(format->format.height, 2), 648 OV2680_MIN_CROP_HEIGHT, crop->height); 649 650 ov2680_fill_format(sensor, &format->format, width, height); 651 652 if (format->which == V4L2_SUBDEV_FORMAT_TRY) { 653 try_fmt = v4l2_subdev_state_get_format(sd_state, 0); 654 *try_fmt = format->format; 655 return 0; 656 } 657 658 mutex_lock(&sensor->lock); 659 660 if (sensor->is_streaming) { 661 ret = -EBUSY; 662 goto unlock; 663 } 664 665 sensor->mode.fmt = format->format; 666 ov2680_calc_mode(sensor); 667 668 unlock: 669 mutex_unlock(&sensor->lock); 670 671 return ret; 672 } 673 674 static int ov2680_get_selection(struct v4l2_subdev *sd, 675 struct v4l2_subdev_state *state, 676 struct v4l2_subdev_selection *sel) 677 { 678 struct ov2680_dev *sensor = to_ov2680_dev(sd); 679 680 switch (sel->target) { 681 case V4L2_SEL_TGT_CROP: 682 mutex_lock(&sensor->lock); 683 sel->r = *__ov2680_get_pad_crop(sensor, state, sel->pad, 684 sel->which); 685 mutex_unlock(&sensor->lock); 686 break; 687 case V4L2_SEL_TGT_NATIVE_SIZE: 688 case V4L2_SEL_TGT_CROP_BOUNDS: 689 sel->r.top = 0; 690 sel->r.left = 0; 691 sel->r.width = OV2680_NATIVE_WIDTH; 692 sel->r.height = OV2680_NATIVE_HEIGHT; 693 break; 694 case V4L2_SEL_TGT_CROP_DEFAULT: 695 sel->r = ov2680_default_crop; 696 break; 697 default: 698 return -EINVAL; 699 } 700 701 return 0; 702 } 703 704 static int ov2680_set_selection(struct v4l2_subdev *sd, 705 struct v4l2_subdev_state *state, 706 struct v4l2_subdev_selection *sel) 707 { 708 struct ov2680_dev *sensor = to_ov2680_dev(sd); 709 struct v4l2_mbus_framefmt *format; 710 struct v4l2_rect *crop; 711 struct v4l2_rect rect; 712 713 if (sel->target != V4L2_SEL_TGT_CROP) 714 return -EINVAL; 715 716 /* 717 * Clamp the boundaries of the crop rectangle to the size of the sensor 718 * pixel array. Align to multiples of 2 to ensure Bayer pattern isn't 719 * disrupted. 720 */ 721 rect.left = clamp_val(ALIGN(sel->r.left, 2), 722 OV2680_NATIVE_START_LEFT, OV2680_NATIVE_WIDTH); 723 rect.top = clamp_val(ALIGN(sel->r.top, 2), 724 OV2680_NATIVE_START_TOP, OV2680_NATIVE_HEIGHT); 725 rect.width = clamp_val(ALIGN(sel->r.width, 2), 726 OV2680_MIN_CROP_WIDTH, OV2680_NATIVE_WIDTH); 727 rect.height = clamp_val(ALIGN(sel->r.height, 2), 728 OV2680_MIN_CROP_HEIGHT, OV2680_NATIVE_HEIGHT); 729 730 /* Make sure the crop rectangle isn't outside the bounds of the array */ 731 rect.width = min_t(unsigned int, rect.width, 732 OV2680_NATIVE_WIDTH - rect.left); 733 rect.height = min_t(unsigned int, rect.height, 734 OV2680_NATIVE_HEIGHT - rect.top); 735 736 crop = __ov2680_get_pad_crop(sensor, state, sel->pad, sel->which); 737 738 mutex_lock(&sensor->lock); 739 if (rect.width != crop->width || rect.height != crop->height) { 740 /* 741 * Reset the output image size if the crop rectangle size has 742 * been modified. 743 */ 744 format = __ov2680_get_pad_format(sensor, state, sel->pad, 745 sel->which); 746 format->width = rect.width; 747 format->height = rect.height; 748 } 749 750 *crop = rect; 751 mutex_unlock(&sensor->lock); 752 753 sel->r = rect; 754 755 return 0; 756 } 757 758 static int ov2680_init_state(struct v4l2_subdev *sd, 759 struct v4l2_subdev_state *sd_state) 760 { 761 struct ov2680_dev *sensor = to_ov2680_dev(sd); 762 763 *v4l2_subdev_state_get_crop(sd_state, 0) = ov2680_default_crop; 764 765 ov2680_fill_format(sensor, v4l2_subdev_state_get_format(sd_state, 0), 766 OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT); 767 return 0; 768 } 769 770 static int ov2680_enum_frame_size(struct v4l2_subdev *sd, 771 struct v4l2_subdev_state *sd_state, 772 struct v4l2_subdev_frame_size_enum *fse) 773 { 774 struct ov2680_dev *sensor = to_ov2680_dev(sd); 775 struct v4l2_rect *crop; 776 777 if (fse->index >= OV2680_FRAME_SIZES) 778 return -EINVAL; 779 780 crop = __ov2680_get_pad_crop(sensor, sd_state, fse->pad, fse->which); 781 if (!crop) 782 return -EINVAL; 783 784 fse->min_width = crop->width / (fse->index + 1); 785 fse->min_height = crop->height / (fse->index + 1); 786 fse->max_width = fse->min_width; 787 fse->max_height = fse->min_height; 788 789 return 0; 790 } 791 792 static bool ov2680_valid_frame_size(struct v4l2_subdev *sd, 793 struct v4l2_subdev_state *sd_state, 794 struct v4l2_subdev_frame_interval_enum *fie) 795 { 796 struct v4l2_subdev_frame_size_enum fse = { 797 .pad = fie->pad, 798 .which = fie->which, 799 }; 800 int i; 801 802 for (i = 0; i < OV2680_FRAME_SIZES; i++) { 803 fse.index = i; 804 805 if (ov2680_enum_frame_size(sd, sd_state, &fse)) 806 return false; 807 808 if (fie->width == fse.min_width && 809 fie->height == fse.min_height) 810 return true; 811 } 812 813 return false; 814 } 815 816 static int ov2680_enum_frame_interval(struct v4l2_subdev *sd, 817 struct v4l2_subdev_state *sd_state, 818 struct v4l2_subdev_frame_interval_enum *fie) 819 { 820 struct ov2680_dev *sensor = to_ov2680_dev(sd); 821 822 /* Only 1 framerate */ 823 if (fie->index || !ov2680_valid_frame_size(sd, sd_state, fie)) 824 return -EINVAL; 825 826 fie->interval = sensor->mode.frame_interval; 827 828 return 0; 829 } 830 831 static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl) 832 { 833 struct v4l2_subdev *sd = ctrl_to_sd(ctrl); 834 struct ov2680_dev *sensor = to_ov2680_dev(sd); 835 int ret; 836 837 /* Only apply changes to the controls if the device is powered up */ 838 if (!pm_runtime_get_if_in_use(sensor->sd.dev)) { 839 ov2680_set_bayer_order(sensor, &sensor->mode.fmt); 840 return 0; 841 } 842 843 switch (ctrl->id) { 844 case V4L2_CID_ANALOGUE_GAIN: 845 ret = ov2680_gain_set(sensor, ctrl->val); 846 break; 847 case V4L2_CID_EXPOSURE: 848 ret = ov2680_exposure_set(sensor, ctrl->val); 849 break; 850 case V4L2_CID_VFLIP: 851 ret = ov2680_set_vflip(sensor, ctrl->val); 852 break; 853 case V4L2_CID_HFLIP: 854 ret = ov2680_set_hflip(sensor, ctrl->val); 855 break; 856 case V4L2_CID_TEST_PATTERN: 857 ret = ov2680_test_pattern_set(sensor, ctrl->val); 858 break; 859 default: 860 ret = -EINVAL; 861 break; 862 } 863 864 pm_runtime_put(sensor->sd.dev); 865 return ret; 866 } 867 868 static const struct v4l2_ctrl_ops ov2680_ctrl_ops = { 869 .s_ctrl = ov2680_s_ctrl, 870 }; 871 872 static const struct v4l2_subdev_video_ops ov2680_video_ops = { 873 .g_frame_interval = ov2680_s_g_frame_interval, 874 .s_frame_interval = ov2680_s_g_frame_interval, 875 .s_stream = ov2680_s_stream, 876 }; 877 878 static const struct v4l2_subdev_pad_ops ov2680_pad_ops = { 879 .enum_mbus_code = ov2680_enum_mbus_code, 880 .enum_frame_size = ov2680_enum_frame_size, 881 .enum_frame_interval = ov2680_enum_frame_interval, 882 .get_fmt = ov2680_get_fmt, 883 .set_fmt = ov2680_set_fmt, 884 .get_selection = ov2680_get_selection, 885 .set_selection = ov2680_set_selection, 886 }; 887 888 static const struct v4l2_subdev_ops ov2680_subdev_ops = { 889 .video = &ov2680_video_ops, 890 .pad = &ov2680_pad_ops, 891 }; 892 893 static const struct v4l2_subdev_internal_ops ov2680_internal_ops = { 894 .init_state = ov2680_init_state, 895 }; 896 897 static int ov2680_mode_init(struct ov2680_dev *sensor) 898 { 899 /* set initial mode */ 900 sensor->mode.crop = ov2680_default_crop; 901 ov2680_fill_format(sensor, &sensor->mode.fmt, 902 OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT); 903 ov2680_calc_mode(sensor); 904 905 sensor->mode.frame_interval.denominator = OV2680_FRAME_RATE; 906 sensor->mode.frame_interval.numerator = 1; 907 908 return 0; 909 } 910 911 static int ov2680_v4l2_register(struct ov2680_dev *sensor) 912 { 913 struct i2c_client *client = to_i2c_client(sensor->dev); 914 const struct v4l2_ctrl_ops *ops = &ov2680_ctrl_ops; 915 struct ov2680_ctrls *ctrls = &sensor->ctrls; 916 struct v4l2_ctrl_handler *hdl = &ctrls->handler; 917 int exp_max = OV2680_LINES_PER_FRAME - OV2680_INTEGRATION_TIME_MARGIN; 918 int ret = 0; 919 920 v4l2_i2c_subdev_init(&sensor->sd, client, &ov2680_subdev_ops); 921 sensor->sd.internal_ops = &ov2680_internal_ops; 922 923 sensor->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE; 924 sensor->pad.flags = MEDIA_PAD_FL_SOURCE; 925 sensor->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR; 926 927 ret = media_entity_pads_init(&sensor->sd.entity, 1, &sensor->pad); 928 if (ret < 0) 929 return ret; 930 931 v4l2_ctrl_handler_init(hdl, 5); 932 933 hdl->lock = &sensor->lock; 934 935 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0); 936 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0); 937 938 ctrls->test_pattern = v4l2_ctrl_new_std_menu_items(hdl, 939 &ov2680_ctrl_ops, V4L2_CID_TEST_PATTERN, 940 ARRAY_SIZE(test_pattern_menu) - 1, 941 0, 0, test_pattern_menu); 942 943 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE, 944 0, exp_max, 1, exp_max); 945 946 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_ANALOGUE_GAIN, 947 0, 1023, 1, 250); 948 949 ctrls->link_freq = v4l2_ctrl_new_int_menu(hdl, NULL, V4L2_CID_LINK_FREQ, 950 0, 0, sensor->link_freq); 951 ctrls->pixel_rate = v4l2_ctrl_new_std(hdl, NULL, V4L2_CID_PIXEL_RATE, 952 0, sensor->pixel_rate, 953 1, sensor->pixel_rate); 954 955 if (hdl->error) { 956 ret = hdl->error; 957 goto cleanup_entity; 958 } 959 960 ctrls->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; 961 ctrls->hflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT; 962 ctrls->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; 963 964 sensor->sd.ctrl_handler = hdl; 965 966 ret = v4l2_async_register_subdev(&sensor->sd); 967 if (ret < 0) 968 goto cleanup_entity; 969 970 return 0; 971 972 cleanup_entity: 973 media_entity_cleanup(&sensor->sd.entity); 974 v4l2_ctrl_handler_free(hdl); 975 976 return ret; 977 } 978 979 static int ov2680_get_regulators(struct ov2680_dev *sensor) 980 { 981 int i; 982 983 for (i = 0; i < OV2680_NUM_SUPPLIES; i++) 984 sensor->supplies[i].supply = ov2680_supply_name[i]; 985 986 return devm_regulator_bulk_get(sensor->dev, 987 OV2680_NUM_SUPPLIES, sensor->supplies); 988 } 989 990 static int ov2680_check_id(struct ov2680_dev *sensor) 991 { 992 u64 chip_id, rev; 993 int ret = 0; 994 995 cci_read(sensor->regmap, OV2680_REG_CHIP_ID, &chip_id, &ret); 996 cci_read(sensor->regmap, OV2680_REG_SC_CMMN_SUB_ID, &rev, &ret); 997 if (ret < 0) { 998 dev_err(sensor->dev, "failed to read chip id\n"); 999 return ret; 1000 } 1001 1002 if (chip_id != OV2680_CHIP_ID) { 1003 dev_err(sensor->dev, "chip id: 0x%04llx does not match expected 0x%04x\n", 1004 chip_id, OV2680_CHIP_ID); 1005 return -ENODEV; 1006 } 1007 1008 dev_info(sensor->dev, "sensor_revision id = 0x%llx, rev= %lld\n", 1009 chip_id, rev & 0x0f); 1010 1011 return 0; 1012 } 1013 1014 static int ov2680_parse_dt(struct ov2680_dev *sensor) 1015 { 1016 struct v4l2_fwnode_endpoint bus_cfg = { 1017 .bus_type = V4L2_MBUS_CSI2_DPHY, 1018 }; 1019 struct device *dev = sensor->dev; 1020 struct fwnode_handle *ep_fwnode; 1021 struct gpio_desc *gpio; 1022 unsigned int rate = 0; 1023 int i, ret; 1024 1025 /* 1026 * Sometimes the fwnode graph is initialized by the bridge driver. 1027 * Bridge drivers doing this may also add GPIO mappings, wait for this. 1028 */ 1029 ep_fwnode = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL); 1030 if (!ep_fwnode) 1031 return dev_err_probe(dev, -EPROBE_DEFER, 1032 "waiting for fwnode graph endpoint\n"); 1033 1034 ret = v4l2_fwnode_endpoint_alloc_parse(ep_fwnode, &bus_cfg); 1035 fwnode_handle_put(ep_fwnode); 1036 if (ret) 1037 return ret; 1038 1039 /* 1040 * The pin we want is named XSHUTDN in the datasheet. Linux sensor 1041 * drivers have standardized on using "powerdown" as con-id name 1042 * for powerdown or shutdown pins. Older DTB files use "reset", 1043 * so fallback to that if there is no "powerdown" pin. 1044 */ 1045 gpio = devm_gpiod_get_optional(dev, "powerdown", GPIOD_OUT_HIGH); 1046 if (!gpio) 1047 gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 1048 1049 ret = PTR_ERR_OR_ZERO(gpio); 1050 if (ret < 0) { 1051 dev_dbg(dev, "error while getting reset gpio: %d\n", ret); 1052 goto out_free_bus_cfg; 1053 } 1054 1055 sensor->pwdn_gpio = gpio; 1056 1057 sensor->xvclk = devm_clk_get_optional(dev, "xvclk"); 1058 if (IS_ERR(sensor->xvclk)) { 1059 ret = dev_err_probe(dev, PTR_ERR(sensor->xvclk), 1060 "xvclk clock missing or invalid\n"); 1061 goto out_free_bus_cfg; 1062 } 1063 1064 /* 1065 * We could have either a 24MHz or 19.2MHz clock rate from either DT or 1066 * ACPI... but we also need to support the weird IPU3 case which will 1067 * have an external clock AND a clock-frequency property. Check for the 1068 * clock-frequency property and if found, set that rate if we managed 1069 * to acquire a clock. This should cover the ACPI case. If the system 1070 * uses devicetree then the configured rate should already be set, so 1071 * we can just read it. 1072 */ 1073 ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", 1074 &rate); 1075 if (ret && !sensor->xvclk) { 1076 dev_err_probe(dev, ret, "invalid clock config\n"); 1077 goto out_free_bus_cfg; 1078 } 1079 1080 if (!ret && sensor->xvclk) { 1081 ret = clk_set_rate(sensor->xvclk, rate); 1082 if (ret) { 1083 dev_err_probe(dev, ret, "failed to set clock rate\n"); 1084 goto out_free_bus_cfg; 1085 } 1086 } 1087 1088 sensor->xvclk_freq = rate ?: clk_get_rate(sensor->xvclk); 1089 1090 for (i = 0; i < ARRAY_SIZE(ov2680_xvclk_freqs); i++) { 1091 if (sensor->xvclk_freq == ov2680_xvclk_freqs[i]) 1092 break; 1093 } 1094 1095 if (i == ARRAY_SIZE(ov2680_xvclk_freqs)) { 1096 ret = dev_err_probe(dev, -EINVAL, 1097 "unsupported xvclk frequency %d Hz\n", 1098 sensor->xvclk_freq); 1099 goto out_free_bus_cfg; 1100 } 1101 1102 sensor->pll_mult = ov2680_pll_multipliers[i]; 1103 1104 sensor->link_freq[0] = sensor->xvclk_freq / OV2680_PLL_PREDIV0 / 1105 OV2680_PLL_PREDIV * sensor->pll_mult; 1106 1107 /* CSI-2 is double data rate, bus-format is 10 bpp */ 1108 sensor->pixel_rate = sensor->link_freq[0] * 2; 1109 do_div(sensor->pixel_rate, 10); 1110 1111 /* Verify bus cfg */ 1112 if (bus_cfg.bus.mipi_csi2.num_data_lanes != 1) { 1113 ret = dev_err_probe(dev, -EINVAL, 1114 "only a 1-lane CSI2 config is supported"); 1115 goto out_free_bus_cfg; 1116 } 1117 1118 for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) 1119 if (bus_cfg.link_frequencies[i] == sensor->link_freq[0]) 1120 break; 1121 1122 if (bus_cfg.nr_of_link_frequencies == 0 || 1123 bus_cfg.nr_of_link_frequencies == i) { 1124 ret = dev_err_probe(dev, -EINVAL, 1125 "supported link freq %lld not found\n", 1126 sensor->link_freq[0]); 1127 goto out_free_bus_cfg; 1128 } 1129 1130 out_free_bus_cfg: 1131 v4l2_fwnode_endpoint_free(&bus_cfg); 1132 return ret; 1133 } 1134 1135 static int ov2680_probe(struct i2c_client *client) 1136 { 1137 struct device *dev = &client->dev; 1138 struct ov2680_dev *sensor; 1139 int ret; 1140 1141 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); 1142 if (!sensor) 1143 return -ENOMEM; 1144 1145 sensor->dev = &client->dev; 1146 1147 sensor->regmap = devm_cci_regmap_init_i2c(client, 16); 1148 if (IS_ERR(sensor->regmap)) 1149 return PTR_ERR(sensor->regmap); 1150 1151 ret = ov2680_parse_dt(sensor); 1152 if (ret < 0) 1153 return ret; 1154 1155 ret = ov2680_mode_init(sensor); 1156 if (ret < 0) 1157 return ret; 1158 1159 ret = ov2680_get_regulators(sensor); 1160 if (ret < 0) { 1161 dev_err(dev, "failed to get regulators\n"); 1162 return ret; 1163 } 1164 1165 mutex_init(&sensor->lock); 1166 1167 /* 1168 * Power up and verify the chip now, so that if runtime pm is 1169 * disabled the chip is left on and streaming will work. 1170 */ 1171 ret = ov2680_power_on(sensor); 1172 if (ret < 0) 1173 goto lock_destroy; 1174 1175 ret = ov2680_check_id(sensor); 1176 if (ret < 0) 1177 goto err_powerdown; 1178 1179 pm_runtime_set_active(&client->dev); 1180 pm_runtime_get_noresume(&client->dev); 1181 pm_runtime_enable(&client->dev); 1182 1183 ret = ov2680_v4l2_register(sensor); 1184 if (ret < 0) 1185 goto err_pm_runtime; 1186 1187 pm_runtime_set_autosuspend_delay(&client->dev, 1000); 1188 pm_runtime_use_autosuspend(&client->dev); 1189 pm_runtime_put_autosuspend(&client->dev); 1190 1191 return 0; 1192 1193 err_pm_runtime: 1194 pm_runtime_disable(&client->dev); 1195 pm_runtime_put_noidle(&client->dev); 1196 err_powerdown: 1197 ov2680_power_off(sensor); 1198 lock_destroy: 1199 dev_err(dev, "ov2680 init fail: %d\n", ret); 1200 mutex_destroy(&sensor->lock); 1201 1202 return ret; 1203 } 1204 1205 static void ov2680_remove(struct i2c_client *client) 1206 { 1207 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1208 struct ov2680_dev *sensor = to_ov2680_dev(sd); 1209 1210 v4l2_async_unregister_subdev(&sensor->sd); 1211 mutex_destroy(&sensor->lock); 1212 media_entity_cleanup(&sensor->sd.entity); 1213 v4l2_ctrl_handler_free(&sensor->ctrls.handler); 1214 1215 /* 1216 * Disable runtime PM. In case runtime PM is disabled in the kernel, 1217 * make sure to turn power off manually. 1218 */ 1219 pm_runtime_disable(&client->dev); 1220 if (!pm_runtime_status_suspended(&client->dev)) 1221 ov2680_power_off(sensor); 1222 pm_runtime_set_suspended(&client->dev); 1223 } 1224 1225 static int ov2680_suspend(struct device *dev) 1226 { 1227 struct v4l2_subdev *sd = dev_get_drvdata(dev); 1228 struct ov2680_dev *sensor = to_ov2680_dev(sd); 1229 1230 if (sensor->is_streaming) 1231 ov2680_stream_disable(sensor); 1232 1233 return ov2680_power_off(sensor); 1234 } 1235 1236 static int ov2680_resume(struct device *dev) 1237 { 1238 struct v4l2_subdev *sd = dev_get_drvdata(dev); 1239 struct ov2680_dev *sensor = to_ov2680_dev(sd); 1240 int ret; 1241 1242 ret = ov2680_power_on(sensor); 1243 if (ret < 0) 1244 goto stream_disable; 1245 1246 if (sensor->is_streaming) { 1247 ret = ov2680_stream_enable(sensor); 1248 if (ret < 0) 1249 goto stream_disable; 1250 } 1251 1252 return 0; 1253 1254 stream_disable: 1255 ov2680_stream_disable(sensor); 1256 sensor->is_streaming = false; 1257 1258 return ret; 1259 } 1260 1261 static DEFINE_RUNTIME_DEV_PM_OPS(ov2680_pm_ops, ov2680_suspend, ov2680_resume, 1262 NULL); 1263 1264 static const struct of_device_id ov2680_dt_ids[] = { 1265 { .compatible = "ovti,ov2680" }, 1266 { /* sentinel */ }, 1267 }; 1268 MODULE_DEVICE_TABLE(of, ov2680_dt_ids); 1269 1270 static const struct acpi_device_id ov2680_acpi_ids[] = { 1271 { "OVTI2680" }, 1272 { /* sentinel */ } 1273 }; 1274 MODULE_DEVICE_TABLE(acpi, ov2680_acpi_ids); 1275 1276 static struct i2c_driver ov2680_i2c_driver = { 1277 .driver = { 1278 .name = "ov2680", 1279 .pm = pm_sleep_ptr(&ov2680_pm_ops), 1280 .of_match_table = ov2680_dt_ids, 1281 .acpi_match_table = ov2680_acpi_ids, 1282 }, 1283 .probe = ov2680_probe, 1284 .remove = ov2680_remove, 1285 }; 1286 module_i2c_driver(ov2680_i2c_driver); 1287 1288 MODULE_AUTHOR("Rui Miguel Silva <rui.silva@linaro.org>"); 1289 MODULE_DESCRIPTION("OV2680 CMOS Image Sensor driver"); 1290 MODULE_LICENSE("GPL v2"); 1291