media: ov2680: Add ov2680_mode struct
authorHans de Goede <hdegoede@redhat.com>
Thu, 3 Aug 2023 09:33:35 +0000 (11:33 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Mon, 14 Aug 2023 18:27:57 +0000 (20:27 +0200)
Add an ov2680_mode struct to group together mode related state.

For now this only contains the v4l2_mbus_framefmt and
the frame_interval.

This is a preparation patch for moving to calculating the per mode
settings, which will store more info in the new ov2680_mode struct.

Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/i2c/ov2680.c

index e7d2e55..76f97d0 100644 (file)
@@ -101,6 +101,11 @@ struct ov2680_ctrls {
        struct v4l2_ctrl *test_pattern;
 };
 
+struct ov2680_mode {
+       struct v4l2_mbus_framefmt       fmt;
+       struct v4l2_fract               frame_interval;
+};
+
 struct ov2680_dev {
        struct device                   *dev;
        struct regmap                   *regmap;
@@ -118,8 +123,7 @@ struct ov2680_dev {
        bool                            is_streaming;
 
        struct ov2680_ctrls             ctrls;
-       struct v4l2_mbus_framefmt       fmt;
-       struct v4l2_fract               frame_interval;
+       struct ov2680_mode              mode;
 
        const struct ov2680_mode_info   *current_mode;
 };
@@ -338,7 +342,7 @@ static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val)
        if (ret < 0)
                return ret;
 
-       ov2680_set_bayer_order(sensor, &sensor->fmt);
+       ov2680_set_bayer_order(sensor, &sensor->mode.fmt);
        return 0;
 }
 
@@ -354,7 +358,7 @@ static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 val)
        if (ret < 0)
                return ret;
 
-       ov2680_set_bayer_order(sensor, &sensor->fmt);
+       ov2680_set_bayer_order(sensor, &sensor->mode.fmt);
        return 0;
 }
 
@@ -467,7 +471,7 @@ static int ov2680_s_g_frame_interval(struct v4l2_subdev *sd,
        struct ov2680_dev *sensor = to_ov2680_dev(sd);
 
        mutex_lock(&sensor->lock);
-       fi->interval = sensor->frame_interval;
+       fi->interval = sensor->mode.frame_interval;
        mutex_unlock(&sensor->lock);
 
        return 0;
@@ -515,7 +519,7 @@ static int ov2680_enum_mbus_code(struct v4l2_subdev *sd,
        if (code->pad != 0 || code->index != 0)
                return -EINVAL;
 
-       code->code = sensor->fmt.code;
+       code->code = sensor->mode.fmt.code;
 
        return 0;
 }
@@ -536,7 +540,7 @@ static int ov2680_get_fmt(struct v4l2_subdev *sd,
                fmt = v4l2_subdev_get_try_format(&sensor->sd, sd_state,
                                                 format->pad);
        } else {
-               fmt = &sensor->fmt;
+               fmt = &sensor->mode.fmt;
        }
 
        format->format = *fmt;
@@ -582,7 +586,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,
        }
 
        sensor->current_mode = mode;
-       sensor->fmt = format->format;
+       sensor->mode.fmt = format->format;
 
 unlock:
        mutex_unlock(&sensor->lock);
@@ -640,7 +644,7 @@ static int ov2680_enum_frame_interval(struct v4l2_subdev *sd,
        if (fie->index || !ov2680_valid_frame_size(fie))
                return -EINVAL;
 
-       fie->interval = sensor->frame_interval;
+       fie->interval = sensor->mode.frame_interval;
 
        return 0;
 }
@@ -653,7 +657,7 @@ static int ov2680_s_ctrl(struct v4l2_ctrl *ctrl)
 
        /* Only apply changes to the controls if the device is powered up */
        if (!pm_runtime_get_if_in_use(sensor->sd.dev)) {
-               ov2680_set_bayer_order(sensor, &sensor->fmt);
+               ov2680_set_bayer_order(sensor, &sensor->mode.fmt);
                return 0;
        }
 
@@ -711,11 +715,11 @@ static int ov2680_mode_init(struct ov2680_dev *sensor)
        const struct ov2680_mode_info *init_mode;
 
        /* set initial mode */
-       ov2680_fill_format(sensor, &sensor->fmt,
+       ov2680_fill_format(sensor, &sensor->mode.fmt,
                           OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT);
 
-       sensor->frame_interval.denominator = OV2680_FRAME_RATE;
-       sensor->frame_interval.numerator = 1;
+       sensor->mode.frame_interval.denominator = OV2680_FRAME_RATE;
+       sensor->mode.frame_interval.numerator = 1;
 
        init_mode = &ov2680_mode_init_data;