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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
From c54b8d2fc79c684deacc81a94f6baa1cb56c62be Mon Sep 17 00:00:00 2001
From: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Date: Wed, 27 Sep 2023 17:18:09 +0300
Subject: [PATCH] media: rp1: cfe: Dual purpose video nodes
The RP1 CSI-2 DMA can capture both video and metadata just fine, but at
the moment the video nodes are only set to support either video or
metadata.
Make the changes to support both video and metadata. This mostly means
tracking both video format and metadata format separately for each video
node, and using vb2_queue_change_type() to change the vb2 queue type
when needed.
Briefly, this means that the user can get/set both video and meta
formats to a single video node. The vb2 queue buffer type will be
changed when the user calls REQBUFS or CREATE_BUFS ioctls. This buffer
type will be then used as the "mode" for the video node when the user
starts the streaming, and based on that either the video or the meta
format will be used.
A bunch of macros are added (node_supports_xxx()), which tell if a node
can support a particular mode, whereas the existing macros
(is_xxx_node()) will tell if the node is currently in a particular mode.
Note that the latter will only work correctly between the start of the
streaming and the end of the streaming, and thus should be only used in
those code paths.
However, as the userspace (libcamera) does not support dual purpose
video nodes, for the time being let's keep the second video node as
V4L2_CAP_META_CAPTURE only to keep the userspace working.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
---
.../media/platform/raspberrypi/rp1_cfe/cfe.c | 271 ++++++++++++------
1 file changed, 182 insertions(+), 89 deletions(-)
--- a/drivers/media/platform/raspberrypi/rp1_cfe/cfe.c
+++ b/drivers/media/platform/raspberrypi/rp1_cfe/cfe.c
@@ -116,7 +116,7 @@ const struct v4l2_mbus_framefmt cfe_defa
enum node_ids {
/* CSI2 HW output nodes first. */
CSI2_CH0,
- CSI2_CH1_EMBEDDED,
+ CSI2_CH1,
CSI2_CH2,
CSI2_CH3,
/* FE only nodes from here on. */
@@ -130,8 +130,7 @@ enum node_ids {
struct node_description {
unsigned int id;
const char *name;
- enum v4l2_buf_type buf_type;
- unsigned int cap;
+ unsigned int caps;
unsigned int pad_flags;
unsigned int link_pad;
};
@@ -140,58 +139,55 @@ struct node_description {
static const struct node_description node_desc[NUM_NODES] = {
[CSI2_CH0] = {
.name = "csi2_ch0",
- .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
- .cap = V4L2_CAP_VIDEO_CAPTURE,
+ .caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_META_CAPTURE,
.pad_flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = CSI2_NUM_CHANNELS + 0
},
- /* This node is assigned for the embedded data channel! */
- [CSI2_CH1_EMBEDDED] = {
+ /*
+ * TODO: This node should be named "csi2_ch1" and the caps should be set
+ * to both video and meta capture. However, to keep compatibility with
+ * the current libcamera, keep the name as "embedded" and support
+ * only meta capture.
+ */
+ [CSI2_CH1] = {
.name = "embedded",
- .buf_type = V4L2_BUF_TYPE_META_CAPTURE,
- .cap = V4L2_CAP_META_CAPTURE,
+ .caps = V4L2_CAP_META_CAPTURE,
.pad_flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = CSI2_NUM_CHANNELS + 1
},
[CSI2_CH2] = {
.name = "csi2_ch2",
- .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
- .cap = V4L2_CAP_META_CAPTURE,
+ .caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_META_CAPTURE,
.pad_flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = CSI2_NUM_CHANNELS + 2
},
[CSI2_CH3] = {
.name = "csi2_ch3",
- .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
- .cap = V4L2_CAP_META_CAPTURE,
+ .caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_META_CAPTURE,
.pad_flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = CSI2_NUM_CHANNELS + 3
},
[FE_OUT0] = {
.name = "fe_image0",
- .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
- .cap = V4L2_CAP_VIDEO_CAPTURE,
+ .caps = V4L2_CAP_VIDEO_CAPTURE,
.pad_flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = FE_OUTPUT0_PAD
},
[FE_OUT1] = {
.name = "fe_image1",
- .buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
- .cap = V4L2_CAP_VIDEO_CAPTURE,
+ .caps = V4L2_CAP_VIDEO_CAPTURE,
.pad_flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = FE_OUTPUT1_PAD
},
[FE_STATS] = {
.name = "fe_stats",
- .buf_type = V4L2_BUF_TYPE_META_CAPTURE,
- .cap = V4L2_CAP_META_CAPTURE,
+ .caps = V4L2_CAP_META_CAPTURE,
.pad_flags = MEDIA_PAD_FL_SINK | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = FE_STATS_PAD
},
[FE_CONFIG] = {
.name = "fe_config",
- .buf_type = V4L2_BUF_TYPE_META_OUTPUT,
- .cap = V4L2_CAP_META_OUTPUT,
+ .caps = V4L2_CAP_META_OUTPUT,
.pad_flags = MEDIA_PAD_FL_SOURCE | MEDIA_PAD_FL_MUST_CONNECT,
.link_pad = FE_CONFIG_PAD
},
@@ -200,17 +196,29 @@ static const struct node_description nod
#define is_fe_node(node) (((node)->id) >= FE_OUT0)
#define is_csi2_node(node) (!is_fe_node(node))
+#define node_supports_image_output(node) \
+ (!!(node_desc[(node)->id].caps & V4L2_CAP_VIDEO_CAPTURE))
+#define node_supports_meta_output(node) \
+ (!!(node_desc[(node)->id].caps & V4L2_CAP_META_CAPTURE))
+#define node_supports_image_input(node) \
+ (!!(node_desc[(node)->id].caps & V4L2_CAP_VIDEO_OUTPUT))
+#define node_supports_meta_input(node) \
+ (!!(node_desc[(node)->id].caps & V4L2_CAP_META_OUTPUT))
+#define node_supports_image(node) \
+ (node_supports_image_output(node) || node_supports_image_input(node))
+#define node_supports_meta(node) \
+ (node_supports_meta_output(node) || node_supports_meta_input(node))
+
#define is_image_output_node(node) \
- (node_desc[(node)->id].buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+ ((node)->buffer_queue.type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
#define is_image_input_node(node) \
- (node_desc[(node)->id].buf_type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+ ((node)->buffer_queue.type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
#define is_image_node(node) \
(is_image_output_node(node) || is_image_input_node(node))
-
#define is_meta_output_node(node) \
- (node_desc[(node)->id].buf_type == V4L2_BUF_TYPE_META_CAPTURE)
+ ((node)->buffer_queue.type == V4L2_BUF_TYPE_META_CAPTURE)
#define is_meta_input_node(node) \
- (node_desc[(node)->id].buf_type == V4L2_BUF_TYPE_META_OUTPUT)
+ ((node)->buffer_queue.type == V4L2_BUF_TYPE_META_OUTPUT)
#define is_meta_node(node) \
(is_meta_output_node(node) || is_meta_input_node(node))
@@ -250,7 +258,9 @@ struct cfe_node {
/* Pointer pointing to next v4l2_buffer */
struct cfe_buffer *next_frm;
/* Used to store current pixel format */
- struct v4l2_format fmt;
+ struct v4l2_format vid_fmt;
+ /* Used to store current meta format */
+ struct v4l2_format meta_fmt;
/* Buffer queue used in video-buf */
struct vb2_queue buffer_queue;
/* Queue of filled frames */
@@ -433,20 +443,21 @@ static int format_show(struct seq_file *
seq_printf(s, "\nNode %u (%s) state: 0x%lx\n", i,
node_desc[i].name, state);
- if (is_image_node(node))
+ if (node_supports_image(node))
seq_printf(s, "format: " V4L2_FOURCC_CONV " 0x%x\n"
"resolution: %ux%u\nbpl: %u\nsize: %u\n",
- V4L2_FOURCC_CONV_ARGS(node->fmt.fmt.pix.pixelformat),
- node->fmt.fmt.pix.pixelformat,
- node->fmt.fmt.pix.width,
- node->fmt.fmt.pix.height,
- node->fmt.fmt.pix.bytesperline,
- node->fmt.fmt.pix.sizeimage);
- else
+ V4L2_FOURCC_CONV_ARGS(node->vid_fmt.fmt.pix.pixelformat),
+ node->vid_fmt.fmt.pix.pixelformat,
+ node->vid_fmt.fmt.pix.width,
+ node->vid_fmt.fmt.pix.height,
+ node->vid_fmt.fmt.pix.bytesperline,
+ node->vid_fmt.fmt.pix.sizeimage);
+
+ if (node_supports_meta(node))
seq_printf(s, "format: " V4L2_FOURCC_CONV " 0x%x\nsize: %u\n",
- V4L2_FOURCC_CONV_ARGS(node->fmt.fmt.meta.dataformat),
- node->fmt.fmt.meta.dataformat,
- node->fmt.fmt.meta.buffersize);
+ V4L2_FOURCC_CONV_ARGS(node->meta_fmt.fmt.meta.dataformat),
+ node->meta_fmt.fmt.meta.dataformat,
+ node->meta_fmt.fmt.meta.buffersize);
}
return 0;
@@ -571,11 +582,11 @@ static void cfe_schedule_next_csi2_job(s
node_desc[node->id].name, &buf->vb.vb2_buf);
if (is_meta_node(node)) {
- size = node->fmt.fmt.meta.buffersize;
+ size = node->meta_fmt.fmt.meta.buffersize;
stride = 0;
} else {
- size = node->fmt.fmt.pix.sizeimage;
- stride = node->fmt.fmt.pix.bytesperline;
+ size = node->vid_fmt.fmt.pix.sizeimage;
+ stride = node->vid_fmt.fmt.pix.bytesperline;
}
addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
@@ -867,10 +878,10 @@ static void cfe_start_channel(struct cfe
width = source_fmt->width;
height = source_fmt->height;
- if (node->fmt.fmt.pix.pixelformat ==
+ if (node->vid_fmt.fmt.pix.pixelformat ==
fmt->remap[CFE_REMAP_16BIT])
mode = CSI2_MODE_REMAP;
- else if (node->fmt.fmt.pix.pixelformat ==
+ else if (node->vid_fmt.fmt.pix.pixelformat ==
fmt->remap[CFE_REMAP_COMPRESSED]) {
mode = CSI2_MODE_COMPRESSED;
csi2_set_compression(&cfe->csi2, node->id,
@@ -884,7 +895,7 @@ static void cfe_start_channel(struct cfe
/* Auto arm */
false,
/* Pack bytes */
- node->id == CSI2_CH1_EMBEDDED ? true : false,
+ is_meta_node(node) ? true : false,
width, height);
}
@@ -947,10 +958,11 @@ static int cfe_queue_setup(struct vb2_qu
{
struct cfe_node *node = vb2_get_drv_priv(vq);
struct cfe_device *cfe = node->cfe;
- unsigned int size = is_image_node(node) ? node->fmt.fmt.pix.sizeimage :
- node->fmt.fmt.meta.buffersize;
+ unsigned int size = is_image_node(node) ? node->vid_fmt.fmt.pix.sizeimage :
+ node->meta_fmt.fmt.meta.buffersize;
- cfe_dbg("%s: [%s]\n", __func__, node_desc[node->id].name);
+ cfe_dbg("%s: [%s] type:%u\n", __func__, node_desc[node->id].name,
+ node->buffer_queue.type);
if (vq->num_buffers + *nbuffers < 3)
*nbuffers = 3 - vq->num_buffers;
@@ -979,8 +991,8 @@ static int cfe_buffer_prepare(struct vb2
cfe_dbg_verbose("%s: [%s] buffer:%p\n", __func__,
node_desc[node->id].name, vb);
- size = is_image_node(node) ? node->fmt.fmt.pix.sizeimage :
- node->fmt.fmt.meta.buffersize;
+ size = is_image_node(node) ? node->vid_fmt.fmt.pix.sizeimage :
+ node->meta_fmt.fmt.meta.buffersize;
if (vb2_plane_size(vb, 0) < size) {
cfe_err("data will not fit into plane (%lu < %lu)\n",
vb2_plane_size(vb, 0), size);
@@ -995,8 +1007,8 @@ static int cfe_buffer_prepare(struct vb2
memcpy(&b->config, addr, sizeof(struct pisp_fe_config));
return pisp_fe_validate_config(&cfe->fe, &b->config,
- &cfe->node[FE_OUT0].fmt,
- &cfe->node[FE_OUT1].fmt);
+ &cfe->node[FE_OUT0].vid_fmt,
+ &cfe->node[FE_OUT1].vid_fmt);
}
return 0;
@@ -1256,7 +1268,7 @@ static int cfe_enum_fmt_vid_cap(struct f
struct cfe_device *cfe = node->cfe;
unsigned int i, j;
- if (!is_image_output_node(node))
+ if (!node_supports_image_output(node))
return -EINVAL;
cfe_dbg("%s: [%s]\n", __func__, node_desc[node->id].name);
@@ -1292,10 +1304,10 @@ static int cfe_g_fmt(struct file *file,
cfe_dbg("%s: [%s]\n", __func__, node_desc[node->id].name);
- if (f->type != node->buffer_queue.type)
+ if (!node_supports_image(node))
return -EINVAL;
- *f = node->fmt;
+ *f = node->vid_fmt;
return 0;
}
@@ -1310,7 +1322,7 @@ static int try_fmt_vid_cap(struct cfe_no
f->fmt.pix.width, f->fmt.pix.height,
V4L2_FOURCC_CONV_ARGS(f->fmt.pix.pixelformat));
- if (!is_image_output_node(node))
+ if (!node_supports_image_output(node))
return -EINVAL;
/*
@@ -1351,11 +1363,11 @@ static int cfe_s_fmt_vid_cap(struct file
if (ret)
return ret;
- node->fmt = *f;
+ node->vid_fmt = *f;
cfe_dbg("%s: Set %ux%u, V4L2 pix " V4L2_FOURCC_CONV "\n", __func__,
- node->fmt.fmt.pix.width, node->fmt.fmt.pix.height,
- V4L2_FOURCC_CONV_ARGS(node->fmt.fmt.pix.pixelformat));
+ node->vid_fmt.fmt.pix.width, node->vid_fmt.fmt.pix.height,
+ V4L2_FOURCC_CONV_ARGS(node->vid_fmt.fmt.pix.pixelformat));
return 0;
}
@@ -1379,11 +1391,11 @@ static int cfe_enum_fmt_meta(struct file
cfe_dbg("%s: [%s]\n", __func__, node_desc[node->id].name);
- if (!is_meta_node(node) || f->index != 0)
+ if (!node_supports_meta(node) || f->index != 0)
return -EINVAL;
switch (node->id) {
- case CSI2_CH1_EMBEDDED:
+ case CSI2_CH0...CSI2_CH3:
f->pixelformat = V4L2_META_FMT_SENSOR_DATA;
return 0;
case FE_STATS:
@@ -1399,8 +1411,11 @@ static int cfe_enum_fmt_meta(struct file
static int try_fmt_meta(struct cfe_node *node, struct v4l2_format *f)
{
+ if (!node_supports_meta(node))
+ return -EINVAL;
+
switch (node->id) {
- case CSI2_CH1_EMBEDDED:
+ case CSI2_CH0...CSI2_CH3:
f->fmt.meta.dataformat = V4L2_META_FMT_SENSOR_DATA;
if (!f->fmt.meta.buffersize)
f->fmt.meta.buffersize = DEFAULT_EMBEDDED_SIZE;
@@ -1422,6 +1437,21 @@ static int try_fmt_meta(struct cfe_node
return -EINVAL;
}
+static int cfe_g_fmt_meta(struct file *file, void *priv, struct v4l2_format *f)
+{
+ struct cfe_node *node = video_drvdata(file);
+ struct cfe_device *cfe = node->cfe;
+
+ cfe_dbg("%s: [%s]\n", __func__, node_desc[node->id].name);
+
+ if (!node_supports_meta(node))
+ return -EINVAL;
+
+ *f = node->meta_fmt;
+
+ return 0;
+}
+
static int cfe_s_fmt_meta(struct file *file, void *priv, struct v4l2_format *f)
{
struct cfe_node *node = video_drvdata(file);
@@ -1434,17 +1464,17 @@ static int cfe_s_fmt_meta(struct file *f
if (vb2_is_busy(q))
return -EBUSY;
- if (f->type != node->buffer_queue.type)
+ if (!node_supports_meta(node))
return -EINVAL;
ret = try_fmt_meta(node, f);
if (ret)
return ret;
- node->fmt = *f;
+ node->meta_fmt = *f;
cfe_dbg("%s: Set " V4L2_FOURCC_CONV "\n", __func__,
- V4L2_FOURCC_CONV_ARGS(node->fmt.fmt.meta.dataformat));
+ V4L2_FOURCC_CONV_ARGS(node->meta_fmt.fmt.meta.dataformat));
return 0;
}
@@ -1491,6 +1521,52 @@ static int cfe_enum_framesizes(struct fi
return 0;
}
+static int cfe_vb2_ioctl_reqbufs(struct file *file, void *priv,
+ struct v4l2_requestbuffers *p)
+{
+ struct video_device *vdev = video_devdata(file);
+ struct cfe_node *node = video_get_drvdata(vdev);
+ struct cfe_device *cfe = node->cfe;
+ int ret;
+
+ cfe_dbg("%s: [%s] type:%u\n", __func__, node_desc[node->id].name,
+ p->type);
+
+ if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
+ p->type != V4L2_BUF_TYPE_META_CAPTURE &&
+ p->type != V4L2_BUF_TYPE_META_OUTPUT)
+ return -EINVAL;
+
+ ret = vb2_queue_change_type(vdev->queue, p->type);
+ if (ret)
+ return ret;
+
+ return vb2_ioctl_reqbufs(file, priv, p);
+}
+
+static int cfe_vb2_ioctl_create_bufs(struct file *file, void *priv,
+ struct v4l2_create_buffers *p)
+{
+ struct video_device *vdev = video_devdata(file);
+ struct cfe_node *node = video_get_drvdata(vdev);
+ struct cfe_device *cfe = node->cfe;
+ int ret;
+
+ cfe_dbg("%s: [%s] type:%u\n", __func__, node_desc[node->id].name,
+ p->format.type);
+
+ if (p->format.type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
+ p->format.type != V4L2_BUF_TYPE_META_CAPTURE &&
+ p->format.type != V4L2_BUF_TYPE_META_OUTPUT)
+ return -EINVAL;
+
+ ret = vb2_queue_change_type(vdev->queue, p->format.type);
+ if (ret)
+ return ret;
+
+ return vb2_ioctl_create_bufs(file, priv, p);
+}
+
static int cfe_subscribe_event(struct v4l2_fh *fh,
const struct v4l2_event_subscription *sub)
{
@@ -1498,12 +1574,13 @@ static int cfe_subscribe_event(struct v4
switch (sub->type) {
case V4L2_EVENT_FRAME_SYNC:
- if (!is_image_output_node(node))
+ if (!node_supports_image_output(node))
break;
return v4l2_event_subscribe(fh, sub, 2, NULL);
case V4L2_EVENT_SOURCE_CHANGE:
- if (is_meta_input_node(node))
+ if (!node_supports_image_output(node) &&
+ !node_supports_meta_output(node))
break;
return v4l2_event_subscribe(fh, sub, 4, NULL);
@@ -1520,19 +1597,19 @@ static const struct v4l2_ioctl_ops cfe_i
.vidioc_try_fmt_vid_cap = cfe_try_fmt_vid_cap,
.vidioc_enum_fmt_meta_cap = cfe_enum_fmt_meta,
- .vidioc_g_fmt_meta_cap = cfe_g_fmt,
+ .vidioc_g_fmt_meta_cap = cfe_g_fmt_meta,
.vidioc_s_fmt_meta_cap = cfe_s_fmt_meta,
.vidioc_try_fmt_meta_cap = cfe_try_fmt_meta,
.vidioc_enum_fmt_meta_out = cfe_enum_fmt_meta,
- .vidioc_g_fmt_meta_out = cfe_g_fmt,
+ .vidioc_g_fmt_meta_out = cfe_g_fmt_meta,
.vidioc_s_fmt_meta_out = cfe_s_fmt_meta,
.vidioc_try_fmt_meta_out = cfe_try_fmt_meta,
.vidioc_enum_framesizes = cfe_enum_framesizes,
- .vidioc_reqbufs = vb2_ioctl_reqbufs,
- .vidioc_create_bufs = vb2_ioctl_create_bufs,
+ .vidioc_reqbufs = cfe_vb2_ioctl_reqbufs,
+ .vidioc_create_bufs = cfe_vb2_ioctl_create_bufs,
.vidioc_prepare_buf = vb2_ioctl_prepare_buf,
.vidioc_querybuf = vb2_ioctl_querybuf,
.vidioc_qbuf = vb2_ioctl_qbuf,
@@ -1610,7 +1687,7 @@ static int cfe_video_link_validate(struc
}
if (is_image_output_node(node)) {
- struct v4l2_pix_format *pix_fmt = &node->fmt.fmt.pix;
+ struct v4l2_pix_format *pix_fmt = &node->vid_fmt.fmt.pix;
const struct cfe_fmt *fmt = NULL;
unsigned int i;
@@ -1636,8 +1713,8 @@ static int cfe_video_link_validate(struc
ret = -EINVAL;
goto out;
}
- } else if (node->id == CSI2_CH1_EMBEDDED) {
- struct v4l2_meta_format *meta_fmt = &node->fmt.fmt.meta;
+ } else if (is_csi2_node(node) && is_meta_output_node(node)) {
+ struct v4l2_meta_format *meta_fmt = &node->meta_fmt.fmt.meta;
if (source_fmt->width * source_fmt->height !=
meta_fmt->buffersize ||
@@ -1698,15 +1775,17 @@ static int cfe_video_link_notify(struct
if (link->source->entity != csi2)
return 0;
- if (link->sink->index != 0)
+ if (link->sink->entity != fe)
return 0;
- if (link->source->index == node_desc[CSI2_CH1_EMBEDDED].link_pad)
+ if (link->sink->index != 0)
return 0;
cfe->fe_csi2_channel = -1;
- if (link->sink->entity == fe && (link->flags & MEDIA_LNK_FL_ENABLED)) {
+ if (link->flags & MEDIA_LNK_FL_ENABLED) {
if (link->source->index == node_desc[CSI2_CH0].link_pad)
cfe->fe_csi2_channel = CSI2_CH0;
+ else if (link->source->index == node_desc[CSI2_CH1].link_pad)
+ cfe->fe_csi2_channel = CSI2_CH1;
else if (link->source->index == node_desc[CSI2_CH2].link_pad)
cfe->fe_csi2_channel = CSI2_CH2;
else if (link->source->index == node_desc[CSI2_CH3].link_pad)
@@ -1763,30 +1842,42 @@ static int cfe_register_node(struct cfe_
node->cfe = cfe;
node->id = id;
- if (is_image_node(node)) {
+ if (node_supports_image(node)) {
+ if (node_supports_image_output(node))
+ node->vid_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ else
+ node->vid_fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+
fmt = find_format_by_code(cfe_default_format.code);
if (!fmt) {
cfe_err("Failed to find format code\n");
return -EINVAL;
}
- node->fmt.fmt.pix.pixelformat = fmt->fourcc;
- v4l2_fill_pix_format(&node->fmt.fmt.pix, &cfe_default_format);
+ node->vid_fmt.fmt.pix.pixelformat = fmt->fourcc;
+ v4l2_fill_pix_format(&node->vid_fmt.fmt.pix, &cfe_default_format);
- ret = try_fmt_vid_cap(node, &node->fmt);
+ ret = try_fmt_vid_cap(node, &node->vid_fmt);
if (ret)
return ret;
- } else {
- ret = try_fmt_meta(node, &node->fmt);
+ }
+
+ if (node_supports_meta(node)) {
+ if (node_supports_meta_output(node))
+ node->meta_fmt.type = V4L2_BUF_TYPE_META_CAPTURE;
+ else
+ node->meta_fmt.type = V4L2_BUF_TYPE_META_OUTPUT;
+
+ ret = try_fmt_meta(node, &node->meta_fmt);
if (ret)
return ret;
}
- node->fmt.type = node_desc[id].buf_type;
mutex_init(&node->lock);
q = &node->buffer_queue;
- q->type = node_desc[id].buf_type;
+ q->type = node_supports_image(node) ? node->vid_fmt.type :
+ node->meta_fmt.type;
q->io_modes = VB2_MMAP | VB2_DMABUF;
q->drv_priv = node;
q->ops = &cfe_video_qops;
@@ -1812,11 +1903,13 @@ static int cfe_register_node(struct cfe_
vdev->ioctl_ops = &cfe_ioctl_ops;
vdev->entity.ops = &cfe_media_entity_ops;
vdev->v4l2_dev = &cfe->v4l2_dev;
- vdev->vfl_dir = (is_image_output_node(node) || is_meta_output_node(node))
- ? VFL_DIR_RX : VFL_DIR_TX;
+ vdev->vfl_dir = (node_supports_image_output(node) ||
+ node_supports_meta_output(node)) ?
+ VFL_DIR_RX :
+ VFL_DIR_TX;
vdev->queue = q;
vdev->lock = &node->lock;
- vdev->device_caps = node_desc[id].cap;
+ vdev->device_caps = node_desc[id].caps;
vdev->device_caps |= V4L2_CAP_STREAMING | V4L2_CAP_IO_MC;
/* Define the device names */
@@ -1829,7 +1922,7 @@ static int cfe_register_node(struct cfe_
node->pad.flags = node_desc[id].pad_flags;
media_entity_pads_init(&vdev->entity, 1, &node->pad);
- if (is_meta_node(node)) {
+ if (!node_supports_image(node)) {
v4l2_disable_ioctl(&node->video_dev,
VIDIOC_ENUM_FRAMEINTERVALS);
v4l2_disable_ioctl(&node->video_dev,
@@ -1907,7 +2000,7 @@ static int cfe_link_node_pads(struct cfe
if (ret)
return ret;
- if (node->id != CSI2_CH1_EMBEDDED) {
+ if (node_supports_image(node)) {
/* CSI2 channel # -> FE Input */
ret = media_create_pad_link(&cfe->csi2.sd.entity,
node_desc[i].link_pad,
|