1 From e947a531a5c6a61fc568dc6a502543e1145efc29 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 29 Apr 2020 12:25:13 +0100
4 Subject: [PATCH] media: i2c: ov5647: Support V4L2_CID_PIXEL_RATE
6 Clients need to know the pixel rate in order to compute exposure
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 drivers/media/i2c/ov5647.c | 31 +++++++++++++++++++++++++++----
13 1 file changed, 27 insertions(+), 4 deletions(-)
15 --- a/drivers/media/i2c/ov5647.c
16 +++ b/drivers/media/i2c/ov5647.c
17 @@ -89,6 +89,8 @@ struct ov5647_mode {
18 /* Analog crop rectangle. */
19 struct v4l2_rect crop;
23 struct regval_list *reg_list;
24 unsigned int num_regs;
26 @@ -103,6 +105,7 @@ struct ov5647 {
27 struct gpio_desc *pwdn;
29 struct v4l2_ctrl_handler ctrls;
30 + struct v4l2_ctrl *pixel_rate;
34 @@ -601,6 +604,7 @@ static struct ov5647_mode supported_mode
38 + .pixel_rate = 77291670,
40 ARRAY_SIZE(ov5647_640x480_8bit)
42 @@ -624,6 +628,7 @@ static struct ov5647_mode supported_mode
46 + .pixel_rate = 87500000,
47 ov5647_2592x1944_10bit,
48 ARRAY_SIZE(ov5647_2592x1944_10bit)
50 @@ -645,6 +650,7 @@ static struct ov5647_mode supported_mode
54 + .pixel_rate = 81666700,
56 ARRAY_SIZE(ov5647_1080p30_10bit)
58 @@ -665,6 +671,7 @@ static struct ov5647_mode supported_mode
62 + .pixel_rate = 81666700,
63 ov5647_2x2binned_10bit,
64 ARRAY_SIZE(ov5647_2x2binned_10bit)
66 @@ -686,6 +693,7 @@ static struct ov5647_mode supported_mode
70 + .pixel_rate = 55000000,
72 ARRAY_SIZE(ov5647_640x480_10bit)
74 @@ -1163,6 +1171,11 @@ static int ov5647_set_fmt(struct v4l2_su
75 if (state->mode != mode)
76 state->write_mode_regs = true;
79 + __v4l2_ctrl_modify_range(state->pixel_rate,
81 + mode->pixel_rate, 1,
85 mutex_unlock(&state->lock);
86 @@ -1379,6 +1392,9 @@ static int ov5647_s_ctrl(struct v4l2_ctr
87 case V4L2_CID_EXPOSURE:
88 ret = ov5647_s_exposure(sd, ctrl->val);
90 + case V4L2_CID_PIXEL_RATE:
91 + /* Read-only, but we adjust it based on mode. */
94 dev_info(&client->dev,
95 "ctrl(id:0x%x,val:0x%x) is not handled\n",
96 @@ -1436,7 +1452,7 @@ static int ov5647_probe(struct i2c_clien
97 mutex_init(&sensor->lock);
99 /* Initialise controls. */
100 - v4l2_ctrl_handler_init(&sensor->ctrls, 3);
101 + v4l2_ctrl_handler_init(&sensor->ctrls, 6);
102 v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
105 @@ -1469,6 +1485,16 @@ static int ov5647_probe(struct i2c_clien
106 32); /* default, 32 = 2.0x */
107 ctrl->flags |= V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
109 + /* Set the default mode before we init the subdev */
110 + sensor->mode = OV5647_DEFAULT_MODE;
112 + /* By default, PIXEL_RATE is read only, but it does change per mode */
113 + sensor->pixel_rate = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
114 + V4L2_CID_PIXEL_RATE,
115 + sensor->mode->pixel_rate,
116 + sensor->mode->pixel_rate, 1,
117 + sensor->mode->pixel_rate);
119 if (sensor->ctrls.error) {
120 ret = sensor->ctrls.error;
121 dev_err(&client->dev, "%s control init failed (%d)\n",
122 @@ -1477,9 +1503,6 @@ static int ov5647_probe(struct i2c_clien
124 sensor->sd.ctrl_handler = &sensor->ctrls;
126 - /* Set the default mode before we init the subdev */
127 - sensor->mode = OV5647_DEFAULT_MODE;
129 /* Write out the register set over I2C on stream-on. */
130 sensor->write_mode_regs = true;