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
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.
10 Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
12 drivers/media/i2c/imx296.c | 44 ++++++++++++++++++++++++++------------
13 1 file changed, 30 insertions(+), 14 deletions(-)
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,
21 +static void imx296_setup_hblank(struct imx296 *sensor, unsigned int width)
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.
30 + * Horizontal blanking is fixed, regardless of the crop width, so
31 + * ensure the hblank limits are adjusted to account for this.
33 + unsigned int hblank = 1100 * 1188000000ULL / 10 / 74250000 - width;
35 + if (!sensor->hblank) {
36 + sensor->hblank = v4l2_ctrl_new_std(&sensor->ctrls,
38 + V4L2_CID_HBLANK, hblank,
41 + sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
43 + __v4l2_ctrl_modify_range(sensor->hblank, hblank, hblank, 1,
48 static int imx296_ctrls_init(struct imx296 *sensor)
50 struct v4l2_fwnode_device_properties props;
51 - unsigned int hblank;
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);
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.
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,
71 - sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
72 + imx296_setup_hblank(sensor, IMX296_PIXEL_ARRAY_WIDTH);
74 sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &imx296_ctrl_ops,
76 @@ -739,6 +753,8 @@ static int imx296_set_format(struct v4l2
77 format->height = crop->height;
80 + imx296_setup_hblank(sensor, format->width);
82 format->code = sensor->mono ? MEDIA_BUS_FMT_Y10_1X10
83 : MEDIA_BUS_FMT_SBGGR10_1X10;
84 format->field = V4L2_FIELD_NONE;