6bdde3a7ab632aebb4fe9fdeea2f7f130d29a244
[openwrt/staging/noltari.git] /
1 From 7048b8678ac96eb512adfb18990eff0c9b8109f5 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 30 Apr 2020 11:03:00 +0100
4 Subject: [PATCH] media: i2c: ov5647: Advertise the correct exposure
5 range
6
7 Exposure is clipped by the VTS of the mode, so needs to be updated as
8 and when this is changed.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 drivers/media/i2c/ov5647.c | 47 +++++++++++++++++++++++++++++++-------
13 1 file changed, 39 insertions(+), 8 deletions(-)
14
15 --- a/drivers/media/i2c/ov5647.c
16 +++ b/drivers/media/i2c/ov5647.c
17 @@ -84,6 +84,11 @@
18 #define OV5647_VBLANK_MIN 4
19 #define OV5647_VTS_MAX 32767
20
21 +#define OV5647_EXPOSURE_MIN 4
22 +#define OV5647_EXPOSURE_STEP 1
23 +#define OV5647_EXPOSURE_DEFAULT 1000
24 +#define OV5647_EXPOSURE_MAX 65535
25 +
26 struct regval_list {
27 u16 addr;
28 u8 data;
29 @@ -117,6 +122,7 @@ struct ov5647 {
30 struct v4l2_ctrl *pixel_rate;
31 struct v4l2_ctrl *hblank;
32 struct v4l2_ctrl *vblank;
33 + struct v4l2_ctrl *exposure;
34 bool write_mode_regs;
35 };
36
37 @@ -1202,7 +1208,7 @@ static int ov5647_set_fmt(struct v4l2_su
38 * If we have changed modes, write the I2C register list on
39 * a stream_on().
40 */
41 - int hblank;
42 + int exposure_max, exposure_def, hblank;
43
44 if (state->mode != mode)
45 state->write_mode_regs = true;
46 @@ -1223,6 +1229,15 @@ static int ov5647_set_fmt(struct v4l2_su
47 mode->vts_def - mode->format.height);
48 __v4l2_ctrl_s_ctrl(state->vblank,
49 mode->vts_def - mode->format.height);
50 +
51 + exposure_max = mode->vts_def - 4;
52 + exposure_def = (exposure_max < OV5647_EXPOSURE_DEFAULT) ?
53 + exposure_max : OV5647_EXPOSURE_DEFAULT;
54 + __v4l2_ctrl_modify_range(state->exposure,
55 + state->exposure->minimum,
56 + exposure_max,
57 + state->exposure->step,
58 + exposure_def);
59 }
60
61 mutex_unlock(&state->lock);
62 @@ -1415,6 +1430,19 @@ static int ov5647_s_ctrl(struct v4l2_ctr
63
64 /* v4l2_ctrl_lock() locks our own mutex */
65
66 + if (ctrl->id == V4L2_CID_VBLANK) {
67 + int exposure_max, exposure_def;
68 +
69 + /* Update max exposure while meeting expected vblanking */
70 + exposure_max = state->mode->format.height + ctrl->val - 4;
71 + exposure_def = (exposure_max < OV5647_EXPOSURE_DEFAULT) ?
72 + exposure_max : OV5647_EXPOSURE_DEFAULT;
73 + __v4l2_ctrl_modify_range(state->exposure,
74 + state->exposure->minimum,
75 + exposure_max, state->exposure->step,
76 + exposure_def);
77 + }
78 +
79 /*
80 * If the device is not powered up by the host driver do
81 * not apply any controls to H/W at this time. Instead
82 @@ -1472,7 +1500,7 @@ static int ov5647_probe(struct i2c_clien
83 struct v4l2_subdev *sd;
84 struct device_node *np = client->dev.of_node;
85 u32 xclk_freq;
86 - int hblank;
87 + int hblank, exposure_max, exposure_def;
88
89 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
90 if (!sensor)
91 @@ -1525,12 +1553,6 @@ static int ov5647_probe(struct i2c_clien
92 0, /* skip_mask */
93 V4L2_EXPOSURE_MANUAL); /* default */
94 v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
95 - V4L2_CID_EXPOSURE,
96 - 4, /* min lines */
97 - 65535, /* max lines (4+8+4 bits)*/
98 - 1, /* step */
99 - 1000); /* default number of lines */
100 - v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
101 V4L2_CID_ANALOGUE_GAIN,
102 16, /* min, 16 = 1.0x */
103 1023, /* max (10 bits) */
104 @@ -1540,6 +1562,15 @@ static int ov5647_probe(struct i2c_clien
105 /* Set the default mode before we init the subdev */
106 sensor->mode = OV5647_DEFAULT_MODE;
107
108 + exposure_max = sensor->mode->vts_def - 4;
109 + exposure_def = (exposure_max < OV5647_EXPOSURE_DEFAULT) ?
110 + exposure_max : OV5647_EXPOSURE_DEFAULT;
111 + sensor->exposure = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
112 + V4L2_CID_EXPOSURE,
113 + OV5647_EXPOSURE_MIN, exposure_max,
114 + OV5647_EXPOSURE_STEP,
115 + exposure_def);
116 +
117 /* By default, PIXEL_RATE is read only, but it does change per mode */
118 sensor->pixel_rate = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
119 V4L2_CID_PIXEL_RATE,