| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From d6c85afca764dc32c3d7981867471fc820e07388 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 |
| 5 | driver. |
| 6 | |
| 7 | Adds support for V4L2_CID_EXPOSURE so that userspace can control |
| 8 | the sensor exposure time. |
| 9 | |
| 10 | Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com> |
| 11 | --- |
| 12 | drivers/media/i2c/imx290.c | 35 +++++++++++++++++++++++++++++++++++ |
| 13 | 1 file changed, 35 insertions(+) |
| 14 | |
| 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 |
| 21 | + |
| 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; |
| 33 | |
| 34 | struct mutex lock; |
| 35 | }; |
| 36 | @@ -529,6 +534,20 @@ static int imx290_set_gain(struct imx290 |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | +static int imx290_set_exposure(struct imx290 *imx290, u32 value) |
| 41 | +{ |
| 42 | + u32 exposure = (imx290->current_mode->height + imx290->vblank->val) - |
| 43 | + value; |
| 44 | + int ret; |
| 45 | + |
| 46 | + ret = imx290_write_buffered_reg(imx290, IMX290_EXPOSURE_LOW, 3, |
| 47 | + exposure); |
| 48 | + if (ret) |
| 49 | + dev_err(imx290->dev, "Unable to write exposure\n"); |
| 50 | + |
| 51 | + return ret; |
| 52 | +} |
| 53 | + |
| 54 | static int imx290_set_hmax(struct imx290 *imx290, u32 val) |
| 55 | { |
| 56 | u32 hmax = val + imx290->current_mode->width; |
| 57 | @@ -590,6 +609,9 @@ static int imx290_set_ctrl(struct v4l2_c |
| 58 | case V4L2_CID_GAIN: |
| 59 | ret = imx290_set_gain(imx290, ctrl->val); |
| 60 | break; |
| 61 | + case V4L2_CID_EXPOSURE: |
| 62 | + ret = imx290_set_exposure(imx290, ctrl->val); |
| 63 | + break; |
| 64 | case V4L2_CID_HBLANK: |
| 65 | ret = imx290_set_hmax(imx290, ctrl->val); |
| 66 | break; |
| 67 | @@ -764,6 +786,12 @@ static int imx290_set_fmt(struct v4l2_su |
| 68 | IMX290_VMAX_MAX - mode->height, |
| 69 | 1, |
| 70 | mode->vmax - mode->height); |
| 71 | + if (imx290->exposure) |
| 72 | + __v4l2_ctrl_modify_range(imx290->exposure, |
| 73 | + mode->vmax - mode->height, |
| 74 | + mode->vmax - 4, |
| 75 | + IMX290_EXPOSURE_STEP, |
| 76 | + mode->vmax - 4); |
| 77 | } |
| 78 | |
| 79 | *format = fmt->format; |
| 80 | @@ -1182,6 +1210,13 @@ static int imx290_probe(struct i2c_clien |
| 81 | IMX290_VMAX_MAX - mode->height, 1, |
| 82 | mode->vmax - mode->height); |
| 83 | |
| 84 | + imx290->exposure = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, |
| 85 | + V4L2_CID_EXPOSURE, |
| 86 | + IMX290_EXPOSURE_MIN, |
| 87 | + mode->vmax - 4, |
| 88 | + IMX290_EXPOSURE_STEP, |
| 89 | + mode->vmax - 4); |
| 90 | + |
| 91 | imx290->link_freq = |
| 92 | v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops, |
| 93 | V4L2_CID_LINK_FREQ, |