summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSakari Ailus <sakari.ailus@linux.intel.com>2018-02-08 06:25:20 -0500
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2018-03-21 11:20:24 -0400
commit894de53b4938f6e4eb5dd0435c60cc87b5747855 (patch)
treec2eb847dca9906e15dcfbb78518580a0f6107e51
parent227b183dcbcc430a6ce29518d3b24d481597e87d (diff)
media: ov5670: Use v4l2_find_nearest_size
Use v4l2_find_nearest_size instead of a driver specific function to find nearest matching size. Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r--drivers/media/i2c/ov5670.c33
1 files changed, 2 insertions, 31 deletions
diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c
index 9f9196568eb8..556a95c30781 100644
--- a/drivers/media/i2c/ov5670.c
+++ b/drivers/media/i2c/ov5670.c
@@ -2180,36 +2180,6 @@ static int ov5670_enum_frame_size(struct v4l2_subdev *sd,
return 0;
}
-/* Calculate resolution distance */
-static int ov5670_get_reso_dist(const struct ov5670_mode *mode,
- struct v4l2_mbus_framefmt *framefmt)
-{
- return abs(mode->width - framefmt->width) +
- abs(mode->height - framefmt->height);
-}
-
-/* Find the closest supported resolution to the requested resolution */
-static const struct ov5670_mode *ov5670_find_best_fit(
- struct ov5670 *ov5670,
- struct v4l2_subdev_format *fmt)
-{
- struct v4l2_mbus_framefmt *framefmt = &fmt->format;
- int dist;
- int cur_best_fit = 0;
- int cur_best_fit_dist = -1;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
- dist = ov5670_get_reso_dist(&supported_modes[i], framefmt);
- if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) {
- cur_best_fit_dist = dist;
- cur_best_fit = i;
- }
- }
-
- return &supported_modes[cur_best_fit];
-}
-
static void ov5670_update_pad_format(const struct ov5670_mode *mode,
struct v4l2_subdev_format *fmt)
{
@@ -2259,7 +2229,8 @@ static int ov5670_set_pad_format(struct v4l2_subdev *sd,
fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
- mode = ov5670_find_best_fit(ov5670, fmt);
+ mode = v4l2_find_nearest_size(supported_modes, width, height,
+ fmt->format.width, fmt->format.height);
ov5670_update_pad_format(mode, fmt);
if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
*v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;