1 From d28f7567b1043aec24558bd72dc10983db25f25c Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Mon, 16 Jan 2023 15:44:40 +0100
4 Subject: [PATCH] media: i2c: imx290: Factor out control update code to
7 Upstream commit a7941da37c43
9 Move the control update code to a separate function to group it with all
10 the control-related code and make imx290_set_fmt() more readable.
12 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
13 Reviewed-by: Alexander Stein <alexander.stein@ew.tq-group.com>
14 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
15 Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
17 drivers/media/i2c/imx290.c | 43 ++++++++++++++++++++------------------
18 1 file changed, 23 insertions(+), 20 deletions(-)
20 --- a/drivers/media/i2c/imx290.c
21 +++ b/drivers/media/i2c/imx290.c
22 @@ -639,6 +639,28 @@ static const char * const imx290_test_pa
23 "000/555h Toggle Pattern",
26 +static void imx290_ctrl_update(struct imx290 *imx290,
27 + const struct imx290_mode *mode)
29 + unsigned int hblank = mode->hmax - mode->width;
30 + unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height;
33 + * This function may be called from imx290_set_fmt() before controls
34 + * get created by imx290_ctrl_init(). Return immediately in that case.
36 + if (!imx290->ctrls.lock)
39 + __v4l2_ctrl_s_ctrl(imx290->link_freq,
40 + imx290_get_link_freq_index(imx290));
41 + __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate,
42 + imx290_calc_pixel_rate(imx290));
44 + __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank);
45 + __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank);
48 static int imx290_ctrl_init(struct imx290 *imx290)
50 struct v4l2_fwnode_device_properties props;
51 @@ -904,26 +926,7 @@ static int imx290_set_fmt(struct v4l2_su
52 imx290->current_mode = mode;
53 imx290->bpp = imx290_formats[i].bpp;
55 - if (imx290->link_freq)
56 - __v4l2_ctrl_s_ctrl(imx290->link_freq,
57 - imx290_get_link_freq_index(imx290));
58 - if (imx290->pixel_rate)
59 - __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate,
60 - imx290_calc_pixel_rate(imx290));
62 - if (imx290->hblank) {
63 - unsigned int hblank = mode->hmax - mode->width;
65 - __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank,
69 - if (imx290->vblank) {
70 - unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height;
72 - __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank,
75 + imx290_ctrl_update(imx290, mode);
78 *format = fmt->format;