1f7710e382fda561654d44ab5554fcd714c47408
[openwrt/staging/stintel.git] /
1 From 29e3826878f43cd88414824be055cf5fcd57ab23 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 29 Apr 2020 17:25:56 +0100
4 Subject: [PATCH] media: i2c: ov5647: Set V4L2_SUBDEV_FL_HAS_EVENTS
5 flag
6
7 The ov5647 subdev can generate control events, therefore set
8 the V4L2_SUBDEV_FL_HAS_EVENTS flag.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 drivers/media/i2c/ov5647.c | 29 +++++++++++++++++++++++++++--
13 1 file changed, 27 insertions(+), 2 deletions(-)
14
15 --- a/drivers/media/i2c/ov5647.c
16 +++ b/drivers/media/i2c/ov5647.c
17 @@ -90,6 +90,8 @@ struct ov5647_mode {
18 struct v4l2_rect crop;
19
20 u64 pixel_rate;
21 + /* HTS as defined in the register set (0x380C/0x380D) */
22 + int hts;
23
24 struct regval_list *reg_list;
25 unsigned int num_regs;
26 @@ -106,6 +108,7 @@ struct ov5647 {
27 unsigned int flags;
28 struct v4l2_ctrl_handler ctrls;
29 struct v4l2_ctrl *pixel_rate;
30 + struct v4l2_ctrl *hblank;
31 bool write_mode_regs;
32 };
33
34 @@ -605,6 +608,7 @@ static struct ov5647_mode supported_mode
35 .height = 960,
36 },
37 .pixel_rate = 77291670,
38 + .hts = 1896,
39 ov5647_640x480_8bit,
40 ARRAY_SIZE(ov5647_640x480_8bit)
41 },
42 @@ -629,6 +633,7 @@ static struct ov5647_mode supported_mode
43 .height = 1944
44 },
45 .pixel_rate = 87500000,
46 + .hts = 2844,
47 ov5647_2592x1944_10bit,
48 ARRAY_SIZE(ov5647_2592x1944_10bit)
49 },
50 @@ -651,6 +656,7 @@ static struct ov5647_mode supported_mode
51 .height = 1080,
52 },
53 .pixel_rate = 81666700,
54 + .hts = 2416,
55 ov5647_1080p30_10bit,
56 ARRAY_SIZE(ov5647_1080p30_10bit)
57 },
58 @@ -672,6 +678,7 @@ static struct ov5647_mode supported_mode
59 .height = 1944,
60 },
61 .pixel_rate = 81666700,
62 + .hts = 1896,
63 ov5647_2x2binned_10bit,
64 ARRAY_SIZE(ov5647_2x2binned_10bit)
65 },
66 @@ -694,6 +701,7 @@ static struct ov5647_mode supported_mode
67 .height = 1920,
68 },
69 .pixel_rate = 55000000,
70 + .hts = 1852,
71 ov5647_640x480_10bit,
72 ARRAY_SIZE(ov5647_640x480_10bit)
73 },
74 @@ -1168,6 +1176,8 @@ static int ov5647_set_fmt(struct v4l2_su
75 * If we have changed modes, write the I2C register list on
76 * a stream_on().
77 */
78 + int hblank;
79 +
80 if (state->mode != mode)
81 state->write_mode_regs = true;
82 state->mode = mode;
83 @@ -1176,6 +1186,9 @@ static int ov5647_set_fmt(struct v4l2_su
84 mode->pixel_rate,
85 mode->pixel_rate, 1,
86 mode->pixel_rate);
87 + hblank = mode->hts - mode->format.width;
88 + __v4l2_ctrl_modify_range(state->hblank, hblank, hblank, 1,
89 + hblank);
90 }
91
92 mutex_unlock(&state->lock);
93 @@ -1395,6 +1408,9 @@ static int ov5647_s_ctrl(struct v4l2_ctr
94 case V4L2_CID_PIXEL_RATE:
95 /* Read-only, but we adjust it based on mode. */
96 break;
97 + case V4L2_CID_HBLANK:
98 + /* Read-only, but we adjust it based on mode. */
99 + break;
100 default:
101 dev_info(&client->dev,
102 "ctrl(id:0x%x,val:0x%x) is not handled\n",
103 @@ -1419,6 +1435,7 @@ static int ov5647_probe(struct i2c_clien
104 struct device_node *np = client->dev.of_node;
105 u32 xclk_freq;
106 struct v4l2_ctrl *ctrl;
107 + int hblank;
108
109 sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
110 if (!sensor)
111 @@ -1452,7 +1469,7 @@ static int ov5647_probe(struct i2c_clien
112 mutex_init(&sensor->lock);
113
114 /* Initialise controls. */
115 - v4l2_ctrl_handler_init(&sensor->ctrls, 6);
116 + v4l2_ctrl_handler_init(&sensor->ctrls, 7);
117 v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
118 V4L2_CID_AUTOGAIN,
119 0, /* min */
120 @@ -1495,6 +1512,13 @@ static int ov5647_probe(struct i2c_clien
121 sensor->mode->pixel_rate, 1,
122 sensor->mode->pixel_rate);
123
124 + /* By default, HBLANK is read only, but it does change per mode */
125 + hblank = sensor->mode->hts - sensor->mode->format.width;
126 + sensor->hblank = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
127 + V4L2_CID_HBLANK, hblank, hblank, 1,
128 + hblank);
129 + sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
130 +
131 if (sensor->ctrls.error) {
132 ret = sensor->ctrls.error;
133 dev_err(&client->dev, "%s control init failed (%d)\n",
134 @@ -1509,7 +1533,8 @@ static int ov5647_probe(struct i2c_clien
135 sd = &sensor->sd;
136 v4l2_i2c_subdev_init(sd, client, &ov5647_subdev_ops);
137 sensor->sd.internal_ops = &ov5647_subdev_internal_ops;
138 - sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
139 + sensor->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE |
140 + V4L2_SUBDEV_FL_HAS_EVENTS;
141
142 sensor->pad.flags = MEDIA_PAD_FL_SOURCE;
143 sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;