59c83e034e01332f3838cc698a3c1dd18ce58fdd
[openwrt/staging/ansuel.git] /
1 From f46108f6b967602e60505ae0198709467668dc83 Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Sun, 16 Oct 2022 09:15:21 +0300
4 Subject: [PATCH] media: i2c: imx290: Factor out format retrieval to
5 separate function
6
7 Upstream commit b25537efeea9
8
9 The driver duplicates the same pattern to access the try or active
10 format in multiple locations. Factor it out to a separate function.
11
12 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
13 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
14 ---
15 drivers/media/i2c/imx290.c | 24 ++++++++++++++----------
16 1 file changed, 14 insertions(+), 10 deletions(-)
17
18 --- a/drivers/media/i2c/imx290.c
19 +++ b/drivers/media/i2c/imx290.c
20 @@ -519,6 +519,16 @@ static const struct v4l2_ctrl_ops imx290
21 .s_ctrl = imx290_set_ctrl,
22 };
23
24 +static struct v4l2_mbus_framefmt *
25 +imx290_get_pad_format(struct imx290 *imx290, struct v4l2_subdev_state *state,
26 + u32 which)
27 +{
28 + if (which == V4L2_SUBDEV_FORMAT_ACTIVE)
29 + return &imx290->current_format;
30 + else
31 + return v4l2_subdev_get_try_format(&imx290->sd, state, 0);
32 +}
33 +
34 static int imx290_enum_mbus_code(struct v4l2_subdev *sd,
35 struct v4l2_subdev_state *sd_state,
36 struct v4l2_subdev_mbus_code_enum *code)
37 @@ -562,12 +572,7 @@ static int imx290_get_fmt(struct v4l2_su
38
39 mutex_lock(&imx290->lock);
40
41 - if (fmt->which == V4L2_SUBDEV_FORMAT_TRY)
42 - framefmt = v4l2_subdev_get_try_format(&imx290->sd, sd_state,
43 - fmt->pad);
44 - else
45 - framefmt = &imx290->current_format;
46 -
47 + framefmt = imx290_get_pad_format(imx290, sd_state, fmt->which);
48 fmt->format = *framefmt;
49
50 mutex_unlock(&imx290->lock);
51 @@ -627,10 +632,9 @@ static int imx290_set_fmt(struct v4l2_su
52 fmt->format.code = imx290_formats[i].code;
53 fmt->format.field = V4L2_FIELD_NONE;
54
55 - if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
56 - format = v4l2_subdev_get_try_format(sd, sd_state, fmt->pad);
57 - } else {
58 - format = &imx290->current_format;
59 + format = imx290_get_pad_format(imx290, sd_state, fmt->which);
60 +
61 + if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
62 imx290->current_mode = mode;
63 imx290->bpp = imx290_formats[i].bpp;
64