1 From e14032e74f63afc123d631d4475b057221b2de60 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 11 Jun 2020 18:19:13 +0100
4 Subject: [PATCH] media: i2c: imx290: Add exposure control to the
7 Adds support for V4L2_CID_EXPOSURE so that userspace can control
8 the sensor exposure time.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 drivers/media/i2c/imx290.c | 35 +++++++++++++++++++++++++++++++++++
13 1 file changed, 35 insertions(+)
15 --- a/drivers/media/i2c/imx290.c
16 +++ b/drivers/media/i2c/imx290.c
17 @@ -45,6 +45,10 @@ enum imx290_clk_index {
18 #define IMX290_HMAX_MIN_2LANE 4400 /* Min of 4400 pixels = 30fps */
19 #define IMX290_HMAX_MIN_4LANE 2200 /* Min of 2200 pixels = 60fps */
20 #define IMX290_HMAX_MAX 0xffff
22 +#define IMX290_EXPOSURE_MIN 2
23 +#define IMX290_EXPOSURE_STEP 1
24 +#define IMX290_EXPOSURE_LOW 0x3020
25 #define IMX290_PGCTRL 0x308c
26 #define IMX290_PHY_LANE_NUM 0x3407
27 #define IMX290_CSI_LANE_MODE 0x3443
28 @@ -103,6 +107,7 @@ struct imx290 {
29 struct v4l2_ctrl *pixel_rate;
30 struct v4l2_ctrl *hblank;
31 struct v4l2_ctrl *vblank;
32 + struct v4l2_ctrl *exposure;
36 @@ -529,6 +534,20 @@ static int imx290_set_gain(struct imx290
40 +static int imx290_set_exposure(struct imx290 *imx290, u32 value)
42 + u32 exposure = (imx290->current_mode->height + imx290->vblank->val) -
46 + ret = imx290_write_buffered_reg(imx290, IMX290_EXPOSURE_LOW, 3,
49 + dev_err(imx290->dev, "Unable to write exposure\n");
54 static int imx290_set_hmax(struct imx290 *imx290, u32 val)
56 u32 hmax = val + imx290->current_mode->width;
57 @@ -590,6 +609,9 @@ static int imx290_set_ctrl(struct v4l2_c
59 ret = imx290_set_gain(imx290, ctrl->val);
61 + case V4L2_CID_EXPOSURE:
62 + ret = imx290_set_exposure(imx290, ctrl->val);
65 ret = imx290_set_hmax(imx290, ctrl->val);
67 @@ -764,6 +786,12 @@ static int imx290_set_fmt(struct v4l2_su
68 IMX290_VMAX_MAX - mode->height,
70 mode->vmax - mode->height);
71 + if (imx290->exposure)
72 + __v4l2_ctrl_modify_range(imx290->exposure,
73 + mode->vmax - mode->height,
75 + IMX290_EXPOSURE_STEP,
79 *format = fmt->format;
80 @@ -1178,6 +1206,13 @@ static int imx290_probe(struct i2c_clien
81 IMX290_VMAX_MAX - mode->height, 1,
82 mode->vmax - mode->height);
84 + imx290->exposure = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
86 + IMX290_EXPOSURE_MIN,
88 + IMX290_EXPOSURE_STEP,
92 v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,