ov2680.c (e521b9cc1a49de677f4fc65909ce4877fbf7b113) | ov2680.c (6d6849b2203f3244b575ba01d3e41ee19aa2cadf) |
---|---|
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. --- 40 unchanged lines hidden (view full) --- 49 50#define OV2680_REG_VALUE_8BIT 1 51#define OV2680_REG_VALUE_16BIT 2 52#define OV2680_REG_VALUE_24BIT 3 53 54#define OV2680_WIDTH_MAX 1600 55#define OV2680_HEIGHT_MAX 1200 56 | 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. --- 40 unchanged lines hidden (view full) --- 49 50#define OV2680_REG_VALUE_8BIT 1 51#define OV2680_REG_VALUE_16BIT 2 52#define OV2680_REG_VALUE_24BIT 3 53 54#define OV2680_WIDTH_MAX 1600 55#define OV2680_HEIGHT_MAX 1200 56 |
57#define OV2680_DEFAULT_WIDTH 800 58#define OV2680_DEFAULT_HEIGHT 600 59 |
|
57enum ov2680_mode_id { 58 OV2680_MODE_QUXGA_800_600, 59 OV2680_MODE_720P_1280_720, 60 OV2680_MODE_UXGA_1600_1200, 61 OV2680_MODE_MAX, 62}; 63 64struct reg_value { --- 245 unchanged lines hidden (view full) --- 310{ 311 if (!sensor->reset_gpio) 312 return; 313 314 gpiod_set_value(sensor->reset_gpio, 1); 315 usleep_range(5000, 10000); 316} 317 | 60enum ov2680_mode_id { 61 OV2680_MODE_QUXGA_800_600, 62 OV2680_MODE_720P_1280_720, 63 OV2680_MODE_UXGA_1600_1200, 64 OV2680_MODE_MAX, 65}; 66 67struct reg_value { --- 245 unchanged lines hidden (view full) --- 313{ 314 if (!sensor->reset_gpio) 315 return; 316 317 gpiod_set_value(sensor->reset_gpio, 1); 318 usleep_range(5000, 10000); 319} 320 |
318static void ov2680_set_bayer_order(struct ov2680_dev *sensor) | 321static void ov2680_set_bayer_order(struct ov2680_dev *sensor, 322 struct v4l2_mbus_framefmt *fmt) |
319{ 320 int hv_flip = 0; 321 322 if (sensor->ctrls.vflip && sensor->ctrls.vflip->val) 323 hv_flip += 1; 324 325 if (sensor->ctrls.hflip && sensor->ctrls.hflip->val) 326 hv_flip += 2; 327 | 323{ 324 int hv_flip = 0; 325 326 if (sensor->ctrls.vflip && sensor->ctrls.vflip->val) 327 hv_flip += 1; 328 329 if (sensor->ctrls.hflip && sensor->ctrls.hflip->val) 330 hv_flip += 2; 331 |
328 sensor->fmt.code = ov2680_hv_flip_bayer_order[hv_flip]; | 332 fmt->code = ov2680_hv_flip_bayer_order[hv_flip]; |
329} 330 | 333} 334 |
335static void ov2680_fill_format(struct ov2680_dev *sensor, 336 struct v4l2_mbus_framefmt *fmt, 337 unsigned int width, unsigned int height) 338{ 339 memset(fmt, 0, sizeof(*fmt)); 340 fmt->width = width; 341 fmt->height = height; 342 fmt->field = V4L2_FIELD_NONE; 343 fmt->colorspace = V4L2_COLORSPACE_SRGB; 344 ov2680_set_bayer_order(sensor, fmt); 345} 346 |
|
331static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val) 332{ 333 int ret; 334 335 if (sensor->is_streaming) 336 return -EBUSY; 337 338 ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT1, 339 BIT(2), val ? BIT(2) : 0); 340 if (ret < 0) 341 return ret; 342 | 347static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val) 348{ 349 int ret; 350 351 if (sensor->is_streaming) 352 return -EBUSY; 353 354 ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT1, 355 BIT(2), val ? BIT(2) : 0); 356 if (ret < 0) 357 return ret; 358 |
343 ov2680_set_bayer_order(sensor); | 359 ov2680_set_bayer_order(sensor, &sensor->fmt); |
344 return 0; 345} 346 347static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val) 348{ 349 int ret; 350 351 if (sensor->is_streaming) 352 return -EBUSY; 353 354 ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT2, 355 BIT(2), val ? BIT(2) : 0); 356 if (ret < 0) 357 return ret; 358 | 360 return 0; 361} 362 363static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val) 364{ 365 int ret; 366 367 if (sensor->is_streaming) 368 return -EBUSY; 369 370 ret = ov2680_mod_reg(sensor, OV2680_REG_FORMAT2, 371 BIT(2), val ? BIT(2) : 0); 372 if (ret < 0) 373 return ret; 374 |
359 ov2680_set_bayer_order(sensor); | 375 ov2680_set_bayer_order(sensor, &sensor->fmt); |
360 return 0; 361} 362 363static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value) 364{ 365 int ret; 366 367 if (!value) --- 241 unchanged lines hidden (view full) --- 609 610 mutex_lock(&sensor->lock); 611 612 if (sensor->is_streaming) { 613 ret = -EBUSY; 614 goto unlock; 615 } 616 | 376 return 0; 377} 378 379static int ov2680_test_pattern_set(struct ov2680_dev *sensor, int value) 380{ 381 int ret; 382 383 if (!value) --- 241 unchanged lines hidden (view full) --- 625 626 mutex_lock(&sensor->lock); 627 628 if (sensor->is_streaming) { 629 ret = -EBUSY; 630 goto unlock; 631 } 632 |
617 fmt->width = mode->width; 618 fmt->height = mode->height; 619 fmt->code = sensor->fmt.code; 620 fmt->colorspace = sensor->fmt.colorspace; | 633 ov2680_fill_format(sensor, fmt, mode->width, mode->height); |
621 622 sensor->current_mode = mode; 623 sensor->fmt = format->format; 624 sensor->mode_pending_changes = true; 625 626unlock: 627 mutex_unlock(&sensor->lock); 628 629 return ret; 630} 631 632static int ov2680_init_cfg(struct v4l2_subdev *sd, 633 struct v4l2_subdev_state *sd_state) 634{ | 634 635 sensor->current_mode = mode; 636 sensor->fmt = format->format; 637 sensor->mode_pending_changes = true; 638 639unlock: 640 mutex_unlock(&sensor->lock); 641 642 return ret; 643} 644 645static int ov2680_init_cfg(struct v4l2_subdev *sd, 646 struct v4l2_subdev_state *sd_state) 647{ |
635 struct v4l2_subdev_format fmt = { 636 .which = sd_state ? V4L2_SUBDEV_FORMAT_TRY 637 : V4L2_SUBDEV_FORMAT_ACTIVE, 638 .format = { 639 .width = 800, 640 .height = 600, 641 } 642 }; | 648 struct ov2680_dev *sensor = to_ov2680_dev(sd); |
643 | 649 |
644 return ov2680_set_fmt(sd, sd_state, &fmt); | 650 ov2680_fill_format(sensor, &sd_state->pads[0].try_fmt, 651 OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT); 652 return 0; |
645} 646 647static int ov2680_enum_frame_size(struct v4l2_subdev *sd, 648 struct v4l2_subdev_state *sd_state, 649 struct v4l2_subdev_frame_size_enum *fse) 650{ 651 int index = fse->index; 652 --- 82 unchanged lines hidden (view full) --- 735 .pad = &ov2680_pad_ops, 736}; 737 738static int ov2680_mode_init(struct ov2680_dev *sensor) 739{ 740 const struct ov2680_mode_info *init_mode; 741 742 /* set initial mode */ | 653} 654 655static int ov2680_enum_frame_size(struct v4l2_subdev *sd, 656 struct v4l2_subdev_state *sd_state, 657 struct v4l2_subdev_frame_size_enum *fse) 658{ 659 int index = fse->index; 660 --- 82 unchanged lines hidden (view full) --- 743 .pad = &ov2680_pad_ops, 744}; 745 746static int ov2680_mode_init(struct ov2680_dev *sensor) 747{ 748 const struct ov2680_mode_info *init_mode; 749 750 /* set initial mode */ |
743 sensor->fmt.code = MEDIA_BUS_FMT_SBGGR10_1X10; 744 sensor->fmt.width = 800; 745 sensor->fmt.height = 600; 746 sensor->fmt.field = V4L2_FIELD_NONE; 747 sensor->fmt.colorspace = V4L2_COLORSPACE_SRGB; | 751 ov2680_fill_format(sensor, &sensor->fmt, 752 OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT); |
748 749 sensor->frame_interval.denominator = OV2680_FRAME_RATE; 750 sensor->frame_interval.numerator = 1; 751 752 init_mode = &ov2680_mode_init_data; 753 754 sensor->current_mode = init_mode; 755 --- 241 unchanged lines hidden --- | 753 754 sensor->frame_interval.denominator = OV2680_FRAME_RATE; 755 sensor->frame_interval.numerator = 1; 756 757 init_mode = &ov2680_mode_init_data; 758 759 sensor->current_mode = init_mode; 760 --- 241 unchanged lines hidden --- |