Skip to content

Commit 7319d57

Browse files
Jacopo Mondimchehab
authored andcommitted
media: i2c: imx219: Simplify format assignment
The set_fmt and init_cfg functions both fills a v4l2_mbus_framefmt instance, passing in the mode and the media bus code. While set_fmt uses function helpers, init_cfg open-codes the assignments. Simplify the format initialization by moving it to a common helper. Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-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>
1 parent e8a5b1d commit 7319d57

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

drivers/media/i2c/imx219.c

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,20 @@ static const struct v4l2_ctrl_ops imx219_ctrl_ops = {
670670
.s_ctrl = imx219_set_ctrl,
671671
};
672672

673+
static void imx219_update_pad_format(struct imx219 *imx219,
674+
const struct imx219_mode *mode,
675+
struct v4l2_mbus_framefmt *fmt, u32 code)
676+
{
677+
/* Bayer order varies with flips */
678+
fmt->code = imx219_get_format_code(imx219, code);
679+
fmt->width = mode->width;
680+
fmt->height = mode->height;
681+
fmt->field = V4L2_FIELD_NONE;
682+
fmt->colorspace = V4L2_COLORSPACE_RAW;
683+
fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
684+
fmt->xfer_func = V4L2_XFER_FUNC_NONE;
685+
}
686+
673687
static int imx219_init_cfg(struct v4l2_subdev *sd,
674688
struct v4l2_subdev_state *state)
675689
{
@@ -679,15 +693,8 @@ static int imx219_init_cfg(struct v4l2_subdev *sd,
679693

680694
/* Initialize try_fmt */
681695
format = v4l2_subdev_get_pad_format(sd, state, 0);
682-
format->width = supported_modes[0].width;
683-
format->height = supported_modes[0].height;
684-
format->code = imx219_get_format_code(imx219,
685-
MEDIA_BUS_FMT_SRGGB10_1X10);
686-
format->field = V4L2_FIELD_NONE;
687-
format->colorspace = V4L2_COLORSPACE_RAW;
688-
format->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(format->colorspace);
689-
format->quantization = V4L2_QUANTIZATION_FULL_RANGE;
690-
format->xfer_func = V4L2_XFER_FUNC_NONE;
696+
imx219_update_pad_format(imx219, &supported_modes[0], format,
697+
MEDIA_BUS_FMT_SRGGB10_1X10);
691698

692699
/* Initialize crop rectangle. */
693700
crop = v4l2_subdev_get_pad_crop(sd, state, 0);
@@ -735,23 +742,6 @@ static int imx219_enum_frame_size(struct v4l2_subdev *sd,
735742
return 0;
736743
}
737744

738-
static void imx219_reset_colorspace(struct v4l2_mbus_framefmt *fmt)
739-
{
740-
fmt->colorspace = V4L2_COLORSPACE_RAW;
741-
fmt->quantization = V4L2_QUANTIZATION_FULL_RANGE;
742-
fmt->xfer_func = V4L2_XFER_FUNC_NONE;
743-
}
744-
745-
static void imx219_update_pad_format(struct imx219 *imx219,
746-
const struct imx219_mode *mode,
747-
struct v4l2_subdev_format *fmt)
748-
{
749-
fmt->format.width = mode->width;
750-
fmt->format.height = mode->height;
751-
fmt->format.field = V4L2_FIELD_NONE;
752-
imx219_reset_colorspace(&fmt->format);
753-
}
754-
755745
static int imx219_set_pad_format(struct v4l2_subdev *sd,
756746
struct v4l2_subdev_state *sd_state,
757747
struct v4l2_subdev_format *fmt)
@@ -768,15 +758,13 @@ static int imx219_set_pad_format(struct v4l2_subdev *sd,
768758
if (i >= ARRAY_SIZE(imx219_mbus_formats))
769759
i = 0;
770760

771-
/* Bayer order varies with flips */
772-
fmt->format.code = imx219_get_format_code(imx219, imx219_mbus_formats[i]);
773-
774761
mode = v4l2_find_nearest_size(supported_modes,
775762
ARRAY_SIZE(supported_modes),
776763
width, height,
777764
fmt->format.width, fmt->format.height);
778765

779-
imx219_update_pad_format(imx219, mode, fmt);
766+
imx219_update_pad_format(imx219, mode, &fmt->format,
767+
imx219_mbus_formats[i]);
780768
format = v4l2_subdev_get_pad_format(sd, sd_state, 0);
781769

782770
if (imx219->mode == mode && format->code == fmt->format.code)

0 commit comments

Comments
 (0)