summaryrefslogtreecommitdiffstats
path: root/bsp/meta-rcar/meta-rcar-gen3-adas/recipes-kernel/linux/linux-renesas/0387-media-soc_camera-Add-events-support.patch
blob: bb2ab7de03120a349658fa998c5a955702a53529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
From 6e47c1eba7112dfcd5f7c07103a99e1e09a150bd Mon Sep 17 00:00:00 2001
From: Andrey Dolnikov <andrey.dolnikov@cogentembedded.com>
Date: Thu, 17 Jan 2019 17:48:53 +0300
Subject: [PATCH 207/211] media: soc_camera: Add events support

---
 drivers/media/platform/soc_camera/rcar_isp.c       |  2 +-
 drivers/media/platform/soc_camera/rcar_vin.c       |  2 +-
 .../platform/soc_camera/sh_mobile_ceu_camera.c     |  2 +-
 drivers/media/platform/soc_camera/soc_camera.c     | 88 ++++++++++++++--------
 include/media/soc_camera.h                         |  4 +
 5 files changed, 65 insertions(+), 33 deletions(-)

diff --git a/drivers/media/platform/soc_camera/rcar_isp.c b/drivers/media/platform/soc_camera/rcar_isp.c
index 1127c7d..e7c2801 100644
--- a/drivers/media/platform/soc_camera/rcar_isp.c
+++ b/drivers/media/platform/soc_camera/rcar_isp.c
@@ -1549,7 +1549,7 @@ static int rcar_isp_try_fmt(struct soc_camera_device *icd,
 
 static unsigned int rcar_isp_poll(struct file *file, poll_table *pt)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	return vb2_poll(&icd->vb2_vidq, file, pt);
 }
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index bcc1cfd..9051590 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -2723,7 +2723,7 @@ static int rcar_vin_try_fmt(struct soc_camera_device *icd,
 
 static unsigned int rcar_vin_poll(struct file *file, poll_table *pt)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	return vb2_poll(&icd->vb2_vidq, file, pt);
 }
diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
index 9180a1d..564d7e8 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -1560,7 +1560,7 @@ static int sh_mobile_ceu_set_liveselection(struct soc_camera_device *icd,
 
 static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	return vb2_poll(&icd->vb2_vidq, file, pt);
 }
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index cd2a135..7e5ca15 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -289,7 +289,7 @@ static int soc_camera_try_fmt(struct soc_camera_device *icd,
 static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
 				      struct v4l2_format *f)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	WARN_ON(priv != file->private_data);
 
@@ -304,7 +304,7 @@ static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv,
 static int soc_camera_enum_input(struct file *file, void *priv,
 				 struct v4l2_input *inp)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	if (inp->index != 0)
 		return -EINVAL;
@@ -334,7 +334,7 @@ static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)
 
 static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id a)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
 
 	return v4l2_subdev_call(sd, video, s_std, a);
@@ -342,7 +342,7 @@ static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id a)
 
 static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
 
 	return v4l2_subdev_call(sd, video, g_std, a);
@@ -351,7 +351,7 @@ static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a)
 static int soc_camera_enum_framesizes(struct file *file, void *fh,
 					 struct v4l2_frmsizeenum *fsize)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	return ici->ops->enum_framesizes(icd, fsize);
@@ -361,7 +361,7 @@ static int soc_camera_reqbufs(struct file *file, void *priv,
 			      struct v4l2_requestbuffers *p)
 {
 	int ret;
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	WARN_ON(priv != file->private_data);
 
@@ -377,7 +377,7 @@ static int soc_camera_reqbufs(struct file *file, void *priv,
 static int soc_camera_querybuf(struct file *file, void *priv,
 			       struct v4l2_buffer *p)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	WARN_ON(priv != file->private_data);
 
@@ -387,7 +387,7 @@ static int soc_camera_querybuf(struct file *file, void *priv,
 static int soc_camera_qbuf(struct file *file, void *priv,
 			   struct v4l2_buffer *p)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	WARN_ON(priv != file->private_data);
 
@@ -400,7 +400,7 @@ static int soc_camera_qbuf(struct file *file, void *priv,
 static int soc_camera_dqbuf(struct file *file, void *priv,
 			    struct v4l2_buffer *p)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	WARN_ON(priv != file->private_data);
 
@@ -413,7 +413,7 @@ static int soc_camera_dqbuf(struct file *file, void *priv,
 static int soc_camera_create_bufs(struct file *file, void *priv,
 			    struct v4l2_create_buffers *create)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	int ret;
 
 	if (icd->streamer && icd->streamer != file)
@@ -428,7 +428,7 @@ static int soc_camera_create_bufs(struct file *file, void *priv,
 static int soc_camera_prepare_buf(struct file *file, void *priv,
 				  struct v4l2_buffer *b)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	return vb2_prepare_buf(&icd->vb2_vidq, b);
 }
@@ -436,7 +436,7 @@ static int soc_camera_prepare_buf(struct file *file, void *priv,
 static int soc_camera_expbuf(struct file *file, void *priv,
 			     struct v4l2_exportbuffer *p)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 
 	if (icd->streamer && icd->streamer != file)
 		return -EBUSY;
@@ -632,6 +632,7 @@ static int soc_camera_open(struct file *file)
 		return -ENODEV;
 	}
 
+	v4l2_fh_open(file);
 	icd = video_get_drvdata(vdev);
 	ici = to_soc_camera_host(icd->parent);
 
@@ -708,7 +709,6 @@ static int soc_camera_open(struct file *file)
 	}
 	mutex_unlock(&ici->host_lock);
 
-	file->private_data = icd;
 	dev_dbg(icd->pdev, "camera device open\n");
 
 	return 0;
@@ -736,14 +736,19 @@ static int soc_camera_open(struct file *file)
 
 static int soc_camera_close(struct file *file)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
+	struct v4l2_event ev;
 
 	mutex_lock(&ici->host_lock);
 	if (icd->streamer == file) {
 		if (ici->ops->init_videobuf2)
 			vb2_queue_release(&icd->vb2_vidq);
 		icd->streamer = NULL;
+
+		memset(&ev, 0, sizeof(ev));
+		ev.type = V4L2_EVENT_EOS;
+		v4l2_event_queue(icd->vdev, &ev);
 	}
 	icd->use_count--;
 	if (!icd->use_count) {
@@ -755,6 +760,8 @@ static int soc_camera_close(struct file *file)
 		soc_camera_remove_device(icd);
 	}
 
+	v4l2_fh_release(file);
+
 	mutex_unlock(&ici->host_lock);
 
 	module_put(ici->ops->owner);
@@ -767,7 +774,7 @@ static int soc_camera_close(struct file *file)
 static ssize_t soc_camera_read(struct file *file, char __user *buf,
 			       size_t count, loff_t *ppos)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	dev_dbg(icd->pdev, "read called, buf %p\n", buf);
@@ -783,7 +790,7 @@ static ssize_t soc_camera_read(struct file *file, char __user *buf,
 
 static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	int err;
 
@@ -807,12 +814,14 @@ static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
 
 static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	unsigned res = POLLERR;
 
+/*
 	if (icd->streamer != file)
 		return POLLERR;
+*/
 
 	mutex_lock(&ici->host_lock);
 	res = ici->ops->poll(file, pt);
@@ -833,7 +842,7 @@ static const struct v4l2_file_operations soc_camera_fops = {
 static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
 				    struct v4l2_format *f)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	int ret;
 
 	WARN_ON(priv != file->private_data);
@@ -862,7 +871,7 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
 static int soc_camera_enum_fmt_vid_cap(struct file *file, void  *priv,
 				       struct v4l2_fmtdesc *f)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	const struct soc_mbus_pixelfmt *format;
 
 	WARN_ON(priv != file->private_data);
@@ -881,7 +890,7 @@ static int soc_camera_enum_fmt_vid_cap(struct file *file, void  *priv,
 static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
 				    struct v4l2_format *f)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct v4l2_pix_format *pix = &f->fmt.pix;
 
 	WARN_ON(priv != file->private_data);
@@ -904,7 +913,7 @@ static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv,
 static int soc_camera_querycap(struct file *file, void  *priv,
 			       struct v4l2_capability *cap)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	WARN_ON(priv != file->private_data);
@@ -916,8 +925,9 @@ static int soc_camera_querycap(struct file *file, void  *priv,
 static int soc_camera_streamon(struct file *file, void *priv,
 			       enum v4l2_buf_type i)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+	struct v4l2_event ev;
 	int ret;
 
 	WARN_ON(priv != file->private_data);
@@ -933,14 +943,19 @@ static int soc_camera_streamon(struct file *file, void *priv,
 	if (!ret)
 		v4l2_subdev_call(sd, video, s_stream, 1);
 
+	memset(&ev, 0, sizeof(ev));
+	ev.type = V4L2_EVENT_SOC_START_STREAM;
+	v4l2_event_queue(icd->vdev, &ev);
+
 	return ret;
 }
 
 static int soc_camera_streamoff(struct file *file, void *priv,
 				enum v4l2_buf_type i)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+	struct v4l2_event ev;
 	int ret;
 
 	WARN_ON(priv != file->private_data);
@@ -959,13 +974,17 @@ static int soc_camera_streamoff(struct file *file, void *priv,
 
 	v4l2_subdev_call(sd, video, s_stream, 0);
 
+	memset(&ev, 0, sizeof(ev));
+	ev.type = V4L2_EVENT_EOS;
+	v4l2_event_queue(icd->vdev, &ev);
+
 	return ret;
 }
 
 static int soc_camera_g_selection(struct file *file, void *fh,
 				  struct v4l2_selection *s)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	/* With a wrong type no need to try to fall back to cropping */
@@ -978,7 +997,7 @@ static int soc_camera_g_selection(struct file *file, void *fh,
 static int soc_camera_s_selection(struct file *file, void *fh,
 				  struct v4l2_selection *s)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 	int ret;
 
@@ -1023,7 +1042,7 @@ static int soc_camera_s_selection(struct file *file, void *fh,
 static int soc_camera_g_parm(struct file *file, void *fh,
 			     struct v4l2_streamparm *a)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	if (ici->ops->get_parm)
@@ -1035,7 +1054,7 @@ static int soc_camera_g_parm(struct file *file, void *fh,
 static int soc_camera_s_parm(struct file *file, void *fh,
 			     struct v4l2_streamparm *a)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	if (ici->ops->set_parm)
@@ -1047,7 +1066,7 @@ static int soc_camera_s_parm(struct file *file, void *fh,
 static int soc_camera_g_edid(struct file *file, void *fh,
 			     struct v4l2_edid *edid)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	if (ici->ops->get_edid)
@@ -1060,7 +1079,7 @@ static int soc_camera_g_edid(struct file *file, void *fh,
 static int soc_camera_g_register(struct file *file, void *priv,
 				 struct v4l2_dbg_register *reg)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	if (ici->ops->get_register)
@@ -1072,7 +1091,7 @@ static int soc_camera_g_register(struct file *file, void *priv,
 static int soc_camera_s_register(struct file *file, void *priv,
 				 const struct v4l2_dbg_register *reg)
 {
-	struct soc_camera_device *icd = file->private_data;
+	struct soc_camera_device *icd = video_drvdata(file);
 	struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
 
 	if (ici->ops->set_register)
@@ -2040,6 +2059,13 @@ static int soc_camera_device_register(struct soc_camera_device *icd)
 	return 0;
 }
 
+static int soc_camera_subscribe_event(struct v4l2_fh *fh,
+                         const struct v4l2_event_subscription *sub)
+{
+	/* Just subscribe any event */
+	return v4l2_event_subscribe(fh, sub, 16, NULL);
+}
+
 static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
 	.vidioc_querycap	 = soc_camera_querycap,
 	.vidioc_try_fmt_vid_cap  = soc_camera_try_fmt_vid_cap,
@@ -2070,6 +2096,8 @@ static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
 	.vidioc_g_register	= soc_camera_g_register,
 	.vidioc_s_register	= soc_camera_s_register,
 #endif
+	.vidioc_subscribe_event		= soc_camera_subscribe_event,
+	.vidioc_unsubscribe_event	= v4l2_event_unsubscribe,
 };
 
 static int video_dev_create(struct soc_camera_device *icd)
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
index 2e44f96..53c650d 100644
--- a/include/media/soc_camera.h
+++ b/include/media/soc_camera.h
@@ -21,6 +21,10 @@
 #include <media/v4l2-async.h>
 #include <media/v4l2-ctrls.h>
 #include <media/v4l2-device.h>
+#include <media/v4l2-event.h>
+
+#define V4L2_EVENT_SOC_START_STREAM	(V4L2_EVENT_PRIVATE_START + 1)
+#define V4L2_EVENT_SOC_PRIVATE_START	(V4L2_EVENT_PRIVATE_START + 1)
 
 struct file;
 struct soc_camera_desc;
-- 
2.7.4