Skip to content

Commit

Permalink
media: i2c: imx290: Factor out format retrieval to separate function
Browse files Browse the repository at this point in the history
The driver duplicates the same pattern to access the try or active
format in multiple locations. Factor it out to a separate function.

Signed-off-by: Laurent Pinchart <[email protected]>
Signed-off-by: Sakari Ailus <[email protected]>
  • Loading branch information
pinchartl authored and Sakari Ailus committed Oct 27, 2022
1 parent 0b274ef commit b25537e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions drivers/media/i2c/imx290.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ static const struct v4l2_ctrl_ops imx290_ctrl_ops = {
.s_ctrl = imx290_set_ctrl,
};

static struct v4l2_mbus_framefmt *
imx290_get_pad_format(struct imx290 *imx290, struct v4l2_subdev_state *state,
u32 which)
{
if (which == V4L2_SUBDEV_FORMAT_ACTIVE)
return &imx290->current_format;
else
return v4l2_subdev_get_try_format(&imx290->sd, state, 0);
}

static int imx290_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_mbus_code_enum *code)
Expand Down Expand Up @@ -562,12 +572,7 @@ static int imx290_get_fmt(struct v4l2_subdev *sd,

mutex_lock(&imx290->lock);

if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
framefmt = v4l2_subdev_get_try_format(&imx290->sd, sd_state,
fmt->pad);
else
framefmt = &imx290->current_format;

framefmt = imx290_get_pad_format(imx290, sd_state, fmt->which);
fmt->format = *framefmt;

mutex_unlock(&imx290->lock);
Expand Down Expand Up @@ -627,10 +632,9 @@ static int imx290_set_fmt(struct v4l2_subdev *sd,
fmt->format.code = imx290_formats[i].code;
fmt->format.field = V4L2_FIELD_NONE;

if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
format = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
} else {
format = &imx290->current_format;
format = imx290_get_pad_format(imx290, sd_state, fmt->which);

if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
imx290->current_mode = mode;
imx290->bpp = imx290_formats[i].bpp;

Expand Down

0 comments on commit b25537e

Please sign in to comment.