bcm27xx: 6.1: add kernel patches
[openwrt/staging/nbd.git] / target / linux / bcm27xx / patches-6.1 / 950-0597-media-i2c-imx296-Add-helper-for-hblank-control.patch
1 From 6b0cce78e4c84189c93ad0fbad7b8d08439135d4 Mon Sep 17 00:00:00 2001
2 From: Naushir Patuck <naush@raspberrypi.com>
3 Date: Tue, 14 Mar 2023 12:56:14 +0000
4 Subject: [PATCH] media: i2c: imx296: Add helper for hblank control
5
6 Add a helper function to setup the horizontal blanking control. Update
7 the control limits on set_format as the horizontal blanking time must
8 remain constant regardless of sensor output width.
9
10 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
11 ---
12 drivers/media/i2c/imx296.c | 44 ++++++++++++++++++++++++++------------
13 1 file changed, 30 insertions(+), 14 deletions(-)
14
15 --- a/drivers/media/i2c/imx296.c
16 +++ b/drivers/media/i2c/imx296.c
17 @@ -384,10 +384,36 @@ static const struct v4l2_ctrl_ops imx296
18 .s_ctrl = imx296_s_ctrl,
19 };
20
21 +static void imx296_setup_hblank(struct imx296 *sensor, unsigned int width)
22 +{
23 + /*
24 + * Horizontal blanking is controlled through the HMAX register, which
25 + * contains a line length in contains a line length in units of an
26 + * internal 74.25 MHz clock derived from the INCLK. The HMAX value is
27 + * currently fixed to 1100, convert it to a number of pixels based on
28 + * the nominal pixel rate.
29 + *
30 + * Horizontal blanking is fixed, regardless of the crop width, so
31 + * ensure the hblank limits are adjusted to account for this.
32 + */
33 + unsigned int hblank = 1100 * 1188000000ULL / 10 / 74250000 - width;
34 +
35 + if (!sensor->hblank) {
36 + sensor->hblank = v4l2_ctrl_new_std(&sensor->ctrls,
37 + &imx296_ctrl_ops,
38 + V4L2_CID_HBLANK, hblank,
39 + hblank, 1, hblank);
40 + if (sensor->hblank)
41 + sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
42 + } else {
43 + __v4l2_ctrl_modify_range(sensor->hblank, hblank, hblank, 1,
44 + hblank);
45 + }
46 +}
47 +
48 static int imx296_ctrls_init(struct imx296 *sensor)
49 {
50 struct v4l2_fwnode_device_properties props;
51 - unsigned int hblank;
52 int ret;
53
54 ret = v4l2_fwnode_device_parse(sensor->dev, &props);
55 @@ -402,19 +428,7 @@ static int imx296_ctrls_init(struct imx2
56 V4L2_CID_ANALOGUE_GAIN, IMX296_GAIN_MIN,
57 IMX296_GAIN_MAX, 1, IMX296_GAIN_MIN);
58
59 - /*
60 - * Horizontal blanking is controlled through the HMAX register, which
61 - * contains a line length in INCK clock units. The INCK frequency is
62 - * fixed to 74.25 MHz. The HMAX value is currently fixed to 1100,
63 - * convert it to a number of pixels based on the nominal pixel rate.
64 - */
65 - hblank = 1100 * 1188000000ULL / 10 / 74250000
66 - - IMX296_PIXEL_ARRAY_WIDTH;
67 - sensor->hblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx296_ctrl_ops,
68 - V4L2_CID_HBLANK, hblank, hblank, 1,
69 - hblank);
70 - if (sensor->hblank)
71 - sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
72 + imx296_setup_hblank(sensor, IMX296_PIXEL_ARRAY_WIDTH);
73
74 sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx296_ctrl_ops,
75 V4L2_CID_VBLANK, 30,
76 @@ -739,6 +753,8 @@ static int imx296_set_format(struct v4l2
77 format->height = crop->height;
78 }
79
80 + imx296_setup_hblank(sensor, format->width);
81 +
82 format->code = sensor->mono ? MEDIA_BUS_FMT_Y10_1X10
83 : MEDIA_BUS_FMT_SBGGR10_1X10;
84 format->field = V4L2_FIELD_NONE;