media: ov5640: report correct frame rate to user
authorGuoniu.zhou <guoniu.zhou@nxp.com>
Fri, 2 Dec 2022 13:00:00 +0000 (13:00 +0000)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Tue, 6 Dec 2022 07:21:52 +0000 (07:21 +0000)
In commit 3145efcdb4d0 ("media: ov5640: Rework timings programming"),
it defines max_fps field in ov5640_mode_info structure to store maximum
frame rate supported by each mode. But in ov5640_try_frame_interval(), it
assumes the maximum frame rate supported by all modes is 60. But actually,
only VGA support it. For others, the maximum frame rate supported is 30.
So correct it by taking the maximum frame rate supported by each mode as
the initialization value of the local variable maxfps.

Signed-off-by: Guoniu.zhou <guoniu.zhou@nxp.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/i2c/ov5640.c

index 3f6d715efa823f2ff3f00ca3ff48722f407cda95..e0f908af581b831f84b04c53d067f68b8e4b597b 100644 (file)
@@ -2715,20 +2715,20 @@ static int ov5640_sensor_resume(struct device *dev)
 
 static int ov5640_try_frame_interval(struct ov5640_dev *sensor,
                                     struct v4l2_fract *fi,
-                                    u32 width, u32 height)
+                                    const struct ov5640_mode_info *mode_info)
 {
-       const struct ov5640_mode_info *mode;
+       const struct ov5640_mode_info *mode = mode_info;
        enum ov5640_frame_rate rate = OV5640_15_FPS;
        int minfps, maxfps, best_fps, fps;
        int i;
 
        minfps = ov5640_framerates[OV5640_15_FPS];
-       maxfps = ov5640_framerates[OV5640_60_FPS];
+       maxfps = ov5640_framerates[mode->max_fps];
 
        if (fi->numerator == 0) {
                fi->denominator = maxfps;
                fi->numerator = 1;
-               rate = OV5640_60_FPS;
+               rate = mode->max_fps;
                goto find_mode;
        }
 
@@ -2749,7 +2749,7 @@ static int ov5640_try_frame_interval(struct ov5640_dev *sensor,
        fi->denominator = best_fps;
 
 find_mode:
-       mode = ov5640_find_mode(sensor, width, height, false);
+       mode = ov5640_find_mode(sensor, mode->width, mode->height, false);
        return mode ? rate : -EINVAL;
 }
 
@@ -3554,6 +3554,7 @@ static int ov5640_enum_frame_interval(
        struct v4l2_subdev_frame_interval_enum *fie)
 {
        struct ov5640_dev *sensor = to_ov5640_dev(sd);
+       const struct ov5640_mode_info *mode;
        struct v4l2_fract tpf;
        int ret;
 
@@ -3562,11 +3563,14 @@ static int ov5640_enum_frame_interval(
        if (fie->index >= OV5640_NUM_FRAMERATES)
                return -EINVAL;
 
+       mode = ov5640_find_mode(sensor, fie->width, fie->height, false);
+       if (!mode)
+               return -EINVAL;
+
        tpf.numerator = 1;
        tpf.denominator = ov5640_framerates[fie->index];
 
-       ret = ov5640_try_frame_interval(sensor, &tpf,
-                                       fie->width, fie->height);
+       ret = ov5640_try_frame_interval(sensor, &tpf, mode);
        if (ret < 0)
                return -EINVAL;
 
@@ -3605,9 +3609,7 @@ static int ov5640_s_frame_interval(struct v4l2_subdev *sd,
 
        mode = sensor->current_mode;
 
-       frame_rate = ov5640_try_frame_interval(sensor, &fi->interval,
-                                              mode->width,
-                                              mode->height);
+       frame_rate = ov5640_try_frame_interval(sensor, &fi->interval, mode);
        if (frame_rate < 0) {
                /* Always return a valid frame interval value */
                fi->interval = sensor->frame_interval;