media: ov5670: Use v4l2_find_nearest_size
authorSakari Ailus <sakari.ailus@linux.intel.com>
Thu, 8 Feb 2018 11:25:20 +0000 (06:25 -0500)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 21 Mar 2018 15:20:24 +0000 (11:20 -0400)
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>
drivers/media/i2c/ov5670.c

index 9f9196568eb863327dde07e61177469623436b1c..556a95c307814c95c4912e810dd6de91fef79d87 100644 (file)
@@ -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;