This is an automatic generated email to let you know that the following patch 
were queued:

Subject: media: ov2680: Add ov2680_fill_format() helper function
Author:  Hans de Goede <hdego...@redhat.com>
Date:    Thu Aug 3 11:33:21 2023 +0200

Add a ov2680_fill_format() helper function and use this everywhere were
a v4l2_mbus_framefmt struct needs to be filled in so that the driver always
fills it consistently.

This is a preparation patch for fixing ov2680_set_fmt()
which == V4L2_SUBDEV_FORMAT_TRY calls not properly filling in
the passed in v4l2_mbus_framefmt struct.

Note that for ov2680_init_cfg() this now simply always fills
the try_fmt struct of the passed in sd_state. This is correct because
ov2680_init_cfg() is never called with a NULL sd_state so the old
sd_state check is not necessary.

Fixes: 3ee47cad3e69 ("media: ov2680: Add Omnivision OV2680 sensor driver")
Acked-by: Rui Miguel Silva <rmf...@gmail.com>
Reviewed-by: Daniel Scally <dan.sca...@ideasonboard.com>
Signed-off-by: Hans de Goede <hdego...@redhat.com>
Signed-off-by: Sakari Ailus <sakari.ai...@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mche...@kernel.org>

 drivers/media/i2c/ov2680.c | 49 +++++++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

---

diff --git a/drivers/media/i2c/ov2680.c b/drivers/media/i2c/ov2680.c
index e6e14743ba1e..f2eb8d85a7e4 100644
--- a/drivers/media/i2c/ov2680.c
+++ b/drivers/media/i2c/ov2680.c
@@ -54,6 +54,9 @@
 #define OV2680_WIDTH_MAX               1600
 #define OV2680_HEIGHT_MAX              1200
 
+#define OV2680_DEFAULT_WIDTH                   800
+#define OV2680_DEFAULT_HEIGHT                  600
+
 enum ov2680_mode_id {
        OV2680_MODE_QUXGA_800_600,
        OV2680_MODE_720P_1280_720,
@@ -315,7 +318,8 @@ static void ov2680_power_down(struct ov2680_dev *sensor)
        usleep_range(5000, 10000);
 }
 
-static void ov2680_set_bayer_order(struct ov2680_dev *sensor)
+static void ov2680_set_bayer_order(struct ov2680_dev *sensor,
+                                  struct v4l2_mbus_framefmt *fmt)
 {
        int hv_flip = 0;
 
@@ -325,7 +329,19 @@ static void ov2680_set_bayer_order(struct ov2680_dev 
*sensor)
        if (sensor->ctrls.hflip && sensor->ctrls.hflip->val)
                hv_flip += 2;
 
-       sensor->fmt.code = ov2680_hv_flip_bayer_order[hv_flip];
+       fmt->code = ov2680_hv_flip_bayer_order[hv_flip];
+}
+
+static void ov2680_fill_format(struct ov2680_dev *sensor,
+                              struct v4l2_mbus_framefmt *fmt,
+                              unsigned int width, unsigned int height)
+{
+       memset(fmt, 0, sizeof(*fmt));
+       fmt->width = width;
+       fmt->height = height;
+       fmt->field = V4L2_FIELD_NONE;
+       fmt->colorspace = V4L2_COLORSPACE_SRGB;
+       ov2680_set_bayer_order(sensor, fmt);
 }
 
 static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 val)
@@ -340,7 +356,7 @@ static int ov2680_set_vflip(struct ov2680_dev *sensor, s32 
val)
        if (ret < 0)
                return ret;
 
-       ov2680_set_bayer_order(sensor);
+       ov2680_set_bayer_order(sensor, &sensor->fmt);
        return 0;
 }
 
@@ -356,7 +372,7 @@ static int ov2680_set_hflip(struct ov2680_dev *sensor, s32 
val)
        if (ret < 0)
                return ret;
 
-       ov2680_set_bayer_order(sensor);
+       ov2680_set_bayer_order(sensor, &sensor->fmt);
        return 0;
 }
 
@@ -614,10 +630,7 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,
                goto unlock;
        }
 
-       fmt->width = mode->width;
-       fmt->height = mode->height;
-       fmt->code = sensor->fmt.code;
-       fmt->colorspace = sensor->fmt.colorspace;
+       ov2680_fill_format(sensor, fmt, mode->width, mode->height);
 
        sensor->current_mode = mode;
        sensor->fmt = format->format;
@@ -632,16 +645,11 @@ unlock:
 static int ov2680_init_cfg(struct v4l2_subdev *sd,
                           struct v4l2_subdev_state *sd_state)
 {
-       struct v4l2_subdev_format fmt = {
-               .which = sd_state ? V4L2_SUBDEV_FORMAT_TRY
-               : V4L2_SUBDEV_FORMAT_ACTIVE,
-               .format = {
-                       .width = 800,
-                       .height = 600,
-               }
-       };
+       struct ov2680_dev *sensor = to_ov2680_dev(sd);
 
-       return ov2680_set_fmt(sd, sd_state, &fmt);
+       ov2680_fill_format(sensor, &sd_state->pads[0].try_fmt,
+                          OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT);
+       return 0;
 }
 
 static int ov2680_enum_frame_size(struct v4l2_subdev *sd,
@@ -740,11 +748,8 @@ static int ov2680_mode_init(struct ov2680_dev *sensor)
        const struct ov2680_mode_info *init_mode;
 
        /* set initial mode */
-       sensor->fmt.code = MEDIA_BUS_FMT_SBGGR10_1X10;
-       sensor->fmt.width = 800;
-       sensor->fmt.height = 600;
-       sensor->fmt.field = V4L2_FIELD_NONE;
-       sensor->fmt.colorspace = V4L2_COLORSPACE_SRGB;
+       ov2680_fill_format(sensor, &sensor->fmt,
+                          OV2680_DEFAULT_WIDTH, OV2680_DEFAULT_HEIGHT);
 
        sensor->frame_interval.denominator = OV2680_FRAME_RATE;
        sensor->frame_interval.numerator = 1;

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to