1 From 58cb4180d3da2c3c096427ff77b967f217bd2f8d Mon Sep 17 00:00:00 2001
2 From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
3 Date: Mon, 16 Jan 2023 15:44:42 +0100
4 Subject: [PATCH] media: i2c: imx290: Pass format and mode to
5 imx290_calc_pixel_rate()
7 Upstream commit 31b54a422b3f
9 Avoid accessing the imx290 current_format and current_mode fields in
10 imx290_calc_pixel_rate() to prepare for the removal of those fields.
11 Among the two callers of the function, imx290_ctrl_update() has an
12 explicit mode pointer already, and we can also give it a format pointer.
15 While at it, inline the imx290_get_link_freq() function in
16 imx290_calc_pixel_rate() as it is only called there.
18 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
19 Reviewed-by: Alexander Stein <alexander.stein@ew.tq-group.com>
20 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
21 Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
23 drivers/media/i2c/imx290.c | 22 ++++++++--------------
24 1 file changed, 8 insertions(+), 14 deletions(-)
26 --- a/drivers/media/i2c/imx290.c
27 +++ b/drivers/media/i2c/imx290.c
28 @@ -547,21 +547,14 @@ static int imx290_write_current_format(s
32 -static s64 imx290_get_link_freq(struct imx290 *imx290)
33 +static u64 imx290_calc_pixel_rate(struct imx290 *imx290,
34 + const struct imx290_mode *mode)
36 - u8 index = imx290->current_mode->link_freq_index;
38 - return *(imx290_link_freqs_ptr(imx290) + index);
41 -static u64 imx290_calc_pixel_rate(struct imx290 *imx290)
43 - s64 link_freq = imx290_get_link_freq(imx290);
44 - u8 nlanes = imx290->nlanes;
45 + s64 link_freq = imx290_link_freqs_ptr(imx290)[mode->link_freq_index];
48 /* pixel rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
49 - pixel_rate = link_freq * 2 * nlanes;
50 + pixel_rate = link_freq * 2 * imx290->nlanes;
51 do_div(pixel_rate, imx290->bpp);
54 @@ -649,7 +642,7 @@ static void imx290_ctrl_update(struct im
56 __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index);
57 __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate,
58 - imx290_calc_pixel_rate(imx290));
59 + imx290_calc_pixel_rate(imx290, mode));
61 __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank);
62 __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank);
63 @@ -659,6 +652,7 @@ static int imx290_ctrl_init(struct imx29
65 struct v4l2_fwnode_device_properties props;
70 ret = v4l2_fwnode_device_parse(imx290->dev, &props);
71 @@ -696,10 +690,10 @@ static int imx290_ctrl_init(struct imx29
72 if (imx290->link_freq)
73 imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
75 + pixel_rate = imx290_calc_pixel_rate(imx290, imx290->current_mode);
76 imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
79 - imx290_calc_pixel_rate(imx290));
80 + 1, INT_MAX, 1, pixel_rate);
82 v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops,
83 V4L2_CID_TEST_PATTERN,