Skip to content

Commit

Permalink
media: ov2680: Add ov2680_fill_format() helper function
Browse files Browse the repository at this point in the history
[ Upstream commit 6d6849b ]

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: 3ee47ca ("media: ov2680: Add Omnivision OV2680 sensor driver")
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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
jwrdegoede authored and gregkh committed Sep 13, 2023
1 parent 90fbf01 commit 0790c09
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions drivers/media/i2c/ov2680.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -632,16 +645,11 @@ static int ov2680_set_fmt(struct v4l2_subdev *sd,
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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0790c09

Please sign in to comment.