bcm27xx: 6.1: add kernel patches
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-6.1 / 950-0658-media-i2c-imx290-Fix-the-pixel-rate-at-148.5Mpix-s.patch
1 From 5003200e5b6e1485515fe18aa5031769930e465e Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 16 Feb 2023 00:29:54 +0200
4 Subject: [PATCH] media: i2c: imx290: Fix the pixel rate at 148.5Mpix/s
5
6 Should be upstream commit 4381df0c756f
7
8 The datasheet lists the link frequency changes between
9 1080p and 720p modes. This is correct that the link frequency
10 changes as measured on an oscilloscope.
11
12 Link frequency is not necessarily the same as pixel rate.
13
14 The datasheet gives standard configurations for 1080p and 720p
15 modes at a number of frame rates.
16 Looking at the 1080p mode it gives:
17 HMAX = 0x898 = 2200
18 VMAX = 0x465 = 1125
19 2200 * 1125 * 60fps = 148.5MPix/s
20
21 Looking at the 720p mode it gives:
22 HMAX = 0xce4 = 3300
23 VMAX = 0x2ee = 750
24 3300 * 750 * 60fps = 148.5Mpix/s
25
26 This driver currently scales the pixel rate proportionally to the
27 link frequency, however the above shows that this is not the
28 correct thing to do, and currently all frame rate and exposure
29 calculations give incorrect results.
30
31 Correctly report the pixel rate as being 148.5MPix/s under any
32 mode.
33
34 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
35 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
36 Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
37 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
38 ---
39 drivers/media/i2c/imx290.c | 16 +++++-----------
40 1 file changed, 5 insertions(+), 11 deletions(-)
41
42 --- a/drivers/media/i2c/imx290.c
43 +++ b/drivers/media/i2c/imx290.c
44 @@ -110,6 +110,8 @@
45
46 #define IMX290_VMAX_DEFAULT 1125
47
48 +#define IMX290_PIXEL_RATE 148500000
49 +
50 /*
51 * The IMX290 pixel array is organized as follows:
52 *
53 @@ -208,7 +210,6 @@ struct imx290 {
54
55 struct v4l2_ctrl_handler ctrls;
56 struct v4l2_ctrl *link_freq;
57 - struct v4l2_ctrl *pixel_rate;
58 struct v4l2_ctrl *hblank;
59 struct v4l2_ctrl *vblank;
60 };
61 @@ -674,15 +675,8 @@ static void imx290_ctrl_update(struct im
62 {
63 unsigned int hblank = mode->hmax - mode->width;
64 unsigned int vblank = IMX290_VMAX_DEFAULT - mode->height;
65 - s64 link_freq = imx290_link_freqs_ptr(imx290)[mode->link_freq_index];
66 - u64 pixel_rate;
67 -
68 - /* pixel rate = link_freq * 2 * nr_of_lanes / bits_per_sample */
69 - pixel_rate = link_freq * 2 * imx290->nlanes;
70 - do_div(pixel_rate, imx290_format_info(imx290, format->code)->bpp);
71
72 __v4l2_ctrl_s_ctrl(imx290->link_freq, mode->link_freq_index);
73 - __v4l2_ctrl_s_ctrl_int64(imx290->pixel_rate, pixel_rate);
74
75 __v4l2_ctrl_modify_range(imx290->hblank, hblank, hblank, 1, hblank);
76 __v4l2_ctrl_modify_range(imx290->vblank, vblank, vblank, 1, vblank);
77 @@ -732,9 +726,9 @@ static int imx290_ctrl_init(struct imx29
78 if (imx290->link_freq)
79 imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
80
81 - imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
82 - V4L2_CID_PIXEL_RATE,
83 - 1, INT_MAX, 1, 1);
84 + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, V4L2_CID_PIXEL_RATE,
85 + IMX290_PIXEL_RATE, IMX290_PIXEL_RATE, 1,
86 + IMX290_PIXEL_RATE);
87
88 v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops,
89 V4L2_CID_TEST_PATTERN,