aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-5.4/950-0643-media-bcm2835-unicam-Add-support-for-mulitple-device.patch
blob: 315feff5d3dd6c1d227405ca7d8a1f16d2435b34 (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
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
From b466d74b45466b417e364c85c7fce71e9fc3fc7c Mon Sep 17 00:00:00 2001
From: Naushir Patuck <naush@raspberrypi.com>
Date: Tue, 7 Apr 2020 10:42:14 +0100
Subject: [PATCH] media: bcm2835-unicam: Add support for mulitple
 device nodes.

Move device node specific state out of the device state structure and
into a new node structure.  This separation will be needed for future
changes where we will add an embedded data node to the driver to work
alongside the existing image data node.

Currently only use a single image node, so this commit does not add
any functional changes.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 .../media/platform/bcm2835/bcm2835-unicam.c   | 484 ++++++++++--------
 1 file changed, 283 insertions(+), 201 deletions(-)

--- a/drivers/media/platform/bcm2835/bcm2835-unicam.c
+++ b/drivers/media/platform/bcm2835/bcm2835-unicam.c
@@ -109,7 +109,8 @@ MODULE_PARM_DESC(debug, "Debug level 0-3
 /* Define a nominal minimum image size */
 #define MIN_WIDTH	16
 #define MIN_HEIGHT	16
-
+/* Maximum number of simulataneous streams Uncaim can handle. */
+#define MAX_NODES	2
 /*
  * struct unicam_fmt - Unicam media bus format information
  * @pixelformat: V4L2 pixel format FCC identifier. 0 if n/a.
@@ -346,11 +347,37 @@ struct unicam_cfg {
 
 #define MAX_POSSIBLE_PIX_FMTS (ARRAY_SIZE(formats))
 
-struct unicam_device {
-	/* V4l2 specific parameters */
+struct unicam_node {
+	bool registered;
+	unsigned int pad_id;
+	/* Pointer pointing to current v4l2_buffer */
+	struct unicam_buffer *cur_frm;
+	/* Pointer pointing to next v4l2_buffer */
+	struct unicam_buffer *next_frm;
+	/* video capture */
+	const struct unicam_fmt *fmt;
+	/* Used to store current pixel format */
+	struct v4l2_format v_fmt;
+	/* Used to store current mbus frame format */
+	struct v4l2_mbus_framefmt m_fmt;
+	/* Buffer queue used in video-buf */
+	struct vb2_queue buffer_queue;
+	/* Queue of filled frames */
+	struct unicam_dmaqueue dma_queue;
+	/* IRQ lock for DMA queue */
+	spinlock_t dma_queue_lock;
+	/* lock used to access this structure */
+	struct mutex lock;
 	/* Identifies video device for this channel */
 	struct video_device video_dev;
+	/* Pointer to the parent handle */
+	struct unicam_device *dev;
+	struct media_pad pad;
 	struct v4l2_ctrl_handler ctrl_handler;
+};
+
+struct unicam_device {
+	/* V4l2 specific parameters */
 
 	struct v4l2_fwnode_endpoint endpoint;
 
@@ -363,7 +390,6 @@ struct unicam_device {
 	/* V4l2 device */
 	struct v4l2_device v4l2_dev;
 	struct media_device mdev;
-	struct media_pad pad;
 
 	/* parent device */
 	struct platform_device *pdev;
@@ -378,18 +404,6 @@ struct unicam_device {
 	/* current input at the sub device */
 	int current_input;
 
-	/* Pointer pointing to current v4l2_buffer */
-	struct unicam_buffer *cur_frm;
-	/* Pointer pointing to next v4l2_buffer */
-	struct unicam_buffer *next_frm;
-
-	/* video capture */
-	const struct unicam_fmt	*fmt;
-	/* Used to store current pixel format */
-	struct v4l2_format v_fmt;
-	/* Used to store current mbus frame format */
-	struct v4l2_mbus_framefmt m_fmt;
-
 	unsigned int virtual_channel;
 	enum v4l2_mbus_type bus_type;
 	/*
@@ -401,20 +415,10 @@ struct unicam_device {
 	unsigned int active_data_lanes;
 
 	struct v4l2_rect crop;
-
-	/* Currently selected input on subdev */
-	int input;
-
-	/* Buffer queue used in video-buf */
-	struct vb2_queue buffer_queue;
-	/* Queue of filled frames */
-	struct unicam_dmaqueue dma_queue;
-	/* IRQ lock for DMA queue */
-	spinlock_t dma_queue_lock;
-	/* lock used to access this structure */
-	struct mutex lock;
 	/* Flag to denote that we are processing buffers */
 	int streaming;
+
+	struct unicam_node node[MAX_NODES];
 };
 
 /* Hardware access */
@@ -526,10 +530,11 @@ static inline unsigned int bytes_per_lin
 }
 
 static int __subdev_get_format(struct unicam_device *dev,
-			       struct v4l2_mbus_framefmt *fmt)
+			       struct v4l2_mbus_framefmt *fmt, int pad_id)
 {
 	struct v4l2_subdev_format sd_fmt = {
 		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
+		.pad = pad_id
 	};
 	int ret;
 
@@ -598,29 +603,30 @@ static int unicam_calc_format_size_bpl(s
 	return 0;
 }
 
-static int unicam_reset_format(struct unicam_device *dev)
+static int unicam_reset_format(struct unicam_node *node)
 {
+	struct unicam_device *dev = node->dev;
 	struct v4l2_mbus_framefmt mbus_fmt;
 	int ret;
 
-	ret = __subdev_get_format(dev, &mbus_fmt);
+	ret = __subdev_get_format(dev, &mbus_fmt, node->pad_id);
 	if (ret) {
 		unicam_err(dev, "Failed to get_format - ret %d\n", ret);
 		return ret;
 	}
 
-	if (mbus_fmt.code != dev->fmt->code) {
+	if (mbus_fmt.code != dev->node[0].fmt->code) {
 		unicam_err(dev, "code mismatch - fmt->code %08x, mbus_fmt.code %08x\n",
-			   dev->fmt->code, mbus_fmt.code);
+			   dev->node[0].fmt->code, mbus_fmt.code);
 		return ret;
 	}
 
-	v4l2_fill_pix_format(&dev->v_fmt.fmt.pix, &mbus_fmt);
-	dev->v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	v4l2_fill_pix_format(&dev->node[0].v_fmt.fmt.pix, &mbus_fmt);
+	dev->node[0].v_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
-	unicam_calc_format_size_bpl(dev, dev->fmt, &dev->v_fmt);
+	unicam_calc_format_size_bpl(dev, dev->node[0].fmt, &dev->node[0].v_fmt);
 
-	dev->m_fmt = mbus_fmt;
+	dev->node[0].m_fmt = mbus_fmt;
 
 	return 0;
 }
@@ -635,14 +641,14 @@ static void unicam_wr_dma_addr(struct un
 
 	reg_write(&dev->cfg, UNICAM_IBSA0, dmaaddr);
 	reg_write(&dev->cfg, UNICAM_IBEA0,
-		  dmaaddr + dev->v_fmt.fmt.pix.sizeimage);
+		  dmaaddr + dev->node[0].v_fmt.fmt.pix.sizeimage);
 }
 
 static inline unsigned int unicam_get_lines_done(struct unicam_device *dev)
 {
 	dma_addr_t start_addr, cur_addr;
-	unsigned int stride = dev->v_fmt.fmt.pix.bytesperline;
-	struct unicam_buffer *frm = dev->cur_frm;
+	unsigned int stride = dev->node[0].v_fmt.fmt.pix.bytesperline;
+	struct unicam_buffer *frm = dev->node[0].cur_frm;
 
 	if (!frm)
 		return 0;
@@ -654,12 +660,12 @@ static inline unsigned int unicam_get_li
 
 static inline void unicam_schedule_next_buffer(struct unicam_device *dev)
 {
-	struct unicam_dmaqueue *dma_q = &dev->dma_queue;
+	struct unicam_dmaqueue *dma_q = &dev->node[0].dma_queue;
 	struct unicam_buffer *buf;
 	dma_addr_t addr;
 
 	buf = list_entry(dma_q->active.next, struct unicam_buffer, list);
-	dev->next_frm = buf;
+	dev->node[0].next_frm = buf;
 	list_del(&buf->list);
 
 	addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0);
@@ -668,11 +674,11 @@ static inline void unicam_schedule_next_
 
 static inline void unicam_process_buffer_complete(struct unicam_device *dev)
 {
-	dev->cur_frm->vb.field = dev->m_fmt.field;
-	dev->cur_frm->vb.sequence = dev->sequence++;
+	dev->node[0].cur_frm->vb.field = dev->node[0].m_fmt.field;
+	dev->node[0].cur_frm->vb.sequence = dev->sequence++;
 
-	vb2_buffer_done(&dev->cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE);
-	dev->cur_frm = dev->next_frm;
+	vb2_buffer_done(&dev->node[0].cur_frm->vb.vb2_buf, VB2_BUF_STATE_DONE);
+	dev->node[0].cur_frm = dev->node[0].next_frm;
 }
 
 /*
@@ -687,7 +693,7 @@ static irqreturn_t unicam_isr(int irq, v
 {
 	struct unicam_device *unicam = (struct unicam_device *)dev;
 	struct unicam_cfg *cfg = &unicam->cfg;
-	struct unicam_dmaqueue *dma_q = &unicam->dma_queue;
+	struct unicam_dmaqueue *dma_q = &unicam->node[0].dma_queue;
 	unsigned int lines_done = unicam_get_lines_done(dev);
 	unsigned int sequence = unicam->sequence;
 	int ista, sta;
@@ -720,8 +726,9 @@ static irqreturn_t unicam_isr(int irq, v
 		 * Timestamp is to be when the first data byte was captured,
 		 * aka frame start.
 		 */
-		if (unicam->cur_frm)
-			unicam->cur_frm->vb.vb2_buf.timestamp = ktime_get_ns();
+		if (unicam->node[0].cur_frm)
+			unicam->node[0].cur_frm->vb.vb2_buf.timestamp =
+				ktime_get_ns();
 	}
 	if (ista & UNICAM_FEI || sta & UNICAM_PI0) {
 		/*
@@ -729,7 +736,8 @@ static irqreturn_t unicam_isr(int irq, v
 		 * stop the peripheral. Overwrite the frame we've just
 		 * captured instead.
 		 */
-		if (unicam->cur_frm && unicam->cur_frm != unicam->next_frm)
+		if (unicam->node[0].cur_frm &&
+		    unicam->node[0].cur_frm != unicam->node[0].next_frm)
 			unicam_process_buffer_complete(unicam);
 	}
 
@@ -738,11 +746,11 @@ static irqreturn_t unicam_isr(int irq, v
 	 * already started.
 	 */
 	if (ista & (UNICAM_FSI | UNICAM_LCI) && !(ista & UNICAM_FEI)) {
-		spin_lock(&unicam->dma_queue_lock);
+		spin_lock(&unicam->node[0].dma_queue_lock);
 		if (!list_empty(&dma_q->active) &&
-		    unicam->cur_frm == unicam->next_frm)
+		    unicam->node[0].cur_frm == unicam->node[0].next_frm)
 			unicam_schedule_next_buffer(unicam);
-		spin_unlock(&unicam->dma_queue_lock);
+		spin_unlock(&unicam->node[0].dma_queue_lock);
 	}
 
 	if (reg_read(&unicam->cfg, UNICAM_ICTL) & UNICAM_FCM) {
@@ -756,7 +764,8 @@ static irqreturn_t unicam_isr(int irq, v
 static int unicam_querycap(struct file *file, void *priv,
 			   struct v4l2_capability *cap)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	strlcpy(cap->driver, UNICAM_MODULE_NAME, sizeof(cap->driver));
 	strlcpy(cap->card, UNICAM_MODULE_NAME, sizeof(cap->card));
@@ -770,7 +779,8 @@ static int unicam_querycap(struct file *
 static int unicam_enum_fmt_vid_cap(struct file *file, void  *priv,
 				   struct v4l2_fmtdesc *f)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	struct v4l2_subdev_mbus_code_enum mbus_code;
 	const struct unicam_fmt *fmt = NULL;
 	int index = 0;
@@ -815,9 +825,9 @@ static int unicam_enum_fmt_vid_cap(struc
 static int unicam_g_fmt_vid_cap(struct file *file, void *priv,
 				struct v4l2_format *f)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
 
-	*f = dev->v_fmt;
+	*f = node->v_fmt;
 
 	return 0;
 }
@@ -859,9 +869,11 @@ const struct unicam_fmt *get_first_suppo
 static int unicam_try_fmt_vid_cap(struct file *file, void *priv,
 				  struct v4l2_format *f)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	struct v4l2_subdev_format sd_fmt = {
 		.which = V4L2_SUBDEV_FORMAT_TRY,
+		.pad = 0
 	};
 	struct v4l2_mbus_framefmt *mbus_fmt = &sd_fmt.format;
 	const struct unicam_fmt *fmt;
@@ -939,8 +951,9 @@ static int unicam_try_fmt_vid_cap(struct
 static int unicam_s_fmt_vid_cap(struct file *file, void *priv,
 				struct v4l2_format *f)
 {
-	struct unicam_device *dev = video_drvdata(file);
-	struct vb2_queue *q = &dev->buffer_queue;
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
+	struct vb2_queue *q = &node->buffer_queue;
 	struct v4l2_mbus_framefmt mbus_fmt = {0};
 	const struct unicam_fmt *fmt;
 	int ret;
@@ -985,17 +998,18 @@ static int unicam_s_fmt_vid_cap(struct f
 		return -EINVAL;
 	}
 
-	dev->fmt = fmt;
-	dev->v_fmt.fmt.pix.pixelformat = f->fmt.pix.pixelformat;
-	dev->v_fmt.fmt.pix.bytesperline = f->fmt.pix.bytesperline;
-	unicam_reset_format(dev);
-
-	unicam_dbg(3, dev, "%s %dx%d, mbus_fmt 0x%08X, V4L2 pix 0x%08X.\n",
-		   __func__, dev->v_fmt.fmt.pix.width,
-		   dev->v_fmt.fmt.pix.height, mbus_fmt.code,
-		   dev->v_fmt.fmt.pix.pixelformat);
+	node->fmt = fmt;
+	node->v_fmt.fmt.pix.pixelformat = f->fmt.pix.pixelformat;
+	node->v_fmt.fmt.pix.bytesperline = f->fmt.pix.bytesperline;
+	unicam_reset_format(node);
+
+	unicam_dbg(3, dev,
+		   "%s %dx%d, mbus_fmt 0x%08X, V4L2 pix 0x%08X.\n",
+		   __func__, node->v_fmt.fmt.pix.width,
+		   node->v_fmt.fmt.pix.height, mbus_fmt.code,
+		   node->v_fmt.fmt.pix.pixelformat);
 
-	*f = dev->v_fmt;
+	*f = node->v_fmt;
 
 	return 0;
 }
@@ -1006,8 +1020,9 @@ static int unicam_queue_setup(struct vb2
 			      unsigned int sizes[],
 			      struct device *alloc_devs[])
 {
-	struct unicam_device *dev = vb2_get_drv_priv(vq);
-	unsigned int size = dev->v_fmt.fmt.pix.sizeimage;
+	struct unicam_node *node = vb2_get_drv_priv(vq);
+	struct unicam_device *dev = node->dev;
+	unsigned int size = node->v_fmt.fmt.pix.sizeimage;
 
 	if (vq->num_buffers + *nbuffers < 3)
 		*nbuffers = 3 - vq->num_buffers;
@@ -1029,15 +1044,16 @@ static int unicam_queue_setup(struct vb2
 
 static int unicam_buffer_prepare(struct vb2_buffer *vb)
 {
-	struct unicam_device *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct unicam_node *node = vb2_get_drv_priv(vb->vb2_queue);
+	struct unicam_device *dev = node->dev;
 	struct unicam_buffer *buf = container_of(vb, struct unicam_buffer,
 					      vb.vb2_buf);
 	unsigned long size;
 
-	if (WARN_ON(!dev->fmt))
+	if (WARN_ON(!node->fmt))
 		return -EINVAL;
 
-	size = dev->v_fmt.fmt.pix.sizeimage;
+	size = node->v_fmt.fmt.pix.sizeimage;
 	if (vb2_plane_size(vb, 0) < size) {
 		unicam_err(dev, "data will not fit into plane (%lu < %lu)\n",
 			   vb2_plane_size(vb, 0), size);
@@ -1050,15 +1066,15 @@ static int unicam_buffer_prepare(struct
 
 static void unicam_buffer_queue(struct vb2_buffer *vb)
 {
-	struct unicam_device *dev = vb2_get_drv_priv(vb->vb2_queue);
+	struct unicam_node *node = vb2_get_drv_priv(vb->vb2_queue);
 	struct unicam_buffer *buf = container_of(vb, struct unicam_buffer,
 					      vb.vb2_buf);
-	struct unicam_dmaqueue *dma_queue = &dev->dma_queue;
+	struct unicam_dmaqueue *dma_queue = &node->dma_queue;
 	unsigned long flags = 0;
 
-	spin_lock_irqsave(&dev->dma_queue_lock, flags);
+	spin_lock_irqsave(&node->dma_queue_lock, flags);
 	list_add_tail(&buf->list, &dma_queue->active);
-	spin_unlock_irqrestore(&dev->dma_queue_lock, flags);
+	spin_unlock_irqrestore(&node->dma_queue_lock, flags);
 }
 
 static void unicam_set_packing_config(struct unicam_device *dev)
@@ -1066,11 +1082,12 @@ static void unicam_set_packing_config(st
 	int pack, unpack;
 	u32 val;
 
-	if (dev->v_fmt.fmt.pix.pixelformat == dev->fmt->fourcc) {
+	if (dev->node[0].v_fmt.fmt.pix.pixelformat ==
+	    dev->node[0].fmt->fourcc) {
 		unpack = UNICAM_PUM_NONE;
 		pack = UNICAM_PPM_NONE;
 	} else {
-		switch (dev->fmt->depth) {
+		switch (dev->node[0].fmt->depth) {
 		case 8:
 			unpack = UNICAM_PUM_UNPACK8;
 			break;
@@ -1108,17 +1125,17 @@ static void unicam_cfg_image_id(struct u
 	if (dev->bus_type == V4L2_MBUS_CSI2_DPHY) {
 		/* CSI2 mode */
 		reg_write(cfg, UNICAM_IDI0,
-			  (dev->virtual_channel << 6) | dev->fmt->csi_dt);
+			(dev->virtual_channel << 6) | dev->node[0].fmt->csi_dt);
 	} else {
 		/* CCP2 mode */
-		reg_write(cfg, UNICAM_IDI0, (0x80 | dev->fmt->csi_dt));
+		reg_write(cfg, UNICAM_IDI0, (0x80 | dev->node[0].fmt->csi_dt));
 	}
 }
 
 static void unicam_start_rx(struct unicam_device *dev, unsigned long addr)
 {
 	struct unicam_cfg *cfg = &dev->cfg;
-	int line_int_freq = dev->v_fmt.fmt.pix.height >> 2;
+	int line_int_freq = dev->node[0].v_fmt.fmt.pix.height >> 2;
 	unsigned int i;
 	u32 val;
 
@@ -1266,7 +1283,8 @@ static void unicam_start_rx(struct unica
 		reg_write(cfg, UNICAM_DAT3, val);
 	}
 
-	reg_write(&dev->cfg, UNICAM_IBLS, dev->v_fmt.fmt.pix.bytesperline);
+	reg_write(&dev->cfg, UNICAM_IBLS,
+		  dev->node[0].v_fmt.fmt.pix.bytesperline);
 	unicam_wr_dma_addr(dev, addr);
 	unicam_set_packing_config(dev);
 	unicam_cfg_image_id(dev);
@@ -1327,21 +1345,22 @@ static void unicam_disable(struct unicam
 
 static int unicam_start_streaming(struct vb2_queue *vq, unsigned int count)
 {
-	struct unicam_device *dev = vb2_get_drv_priv(vq);
-	struct unicam_dmaqueue *dma_q = &dev->dma_queue;
+	struct unicam_node *node = vb2_get_drv_priv(vq);
+	struct unicam_device *dev = node->dev;
+	struct unicam_dmaqueue *dma_q = &node->dma_queue;
 	struct unicam_buffer *buf, *tmp;
 	unsigned long addr = 0;
 	unsigned long flags;
 	int ret;
 
-	spin_lock_irqsave(&dev->dma_queue_lock, flags);
+	spin_lock_irqsave(&node->dma_queue_lock, flags);
 	buf = list_entry(dma_q->active.next, struct unicam_buffer, list);
-	dev->cur_frm = buf;
-	dev->next_frm = buf;
+	node->cur_frm = buf;
+	node->next_frm = buf;
 	list_del(&buf->list);
-	spin_unlock_irqrestore(&dev->dma_queue_lock, flags);
+	spin_unlock_irqrestore(&node->dma_queue_lock, flags);
 
-	addr = vb2_dma_contig_plane_dma_addr(&dev->cur_frm->vb.vb2_buf, 0);
+	addr = vb2_dma_contig_plane_dma_addr(&node->cur_frm->vb.vb2_buf, 0);
 	dev->sequence = 0;
 
 	ret = unicam_runtime_get(dev);
@@ -1411,20 +1430,21 @@ err_release_buffers:
 		list_del(&buf->list);
 		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
 	}
-	if (dev->cur_frm != dev->next_frm)
-		vb2_buffer_done(&dev->next_frm->vb.vb2_buf,
+	if (node->cur_frm != node->next_frm)
+		vb2_buffer_done(&node->next_frm->vb.vb2_buf,
 				VB2_BUF_STATE_QUEUED);
-	vb2_buffer_done(&dev->cur_frm->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
-	dev->next_frm = NULL;
-	dev->cur_frm = NULL;
+	vb2_buffer_done(&node->cur_frm->vb.vb2_buf, VB2_BUF_STATE_QUEUED);
+	node->next_frm = NULL;
+	node->cur_frm = NULL;
 
 	return ret;
 }
 
 static void unicam_stop_streaming(struct vb2_queue *vq)
 {
-	struct unicam_device *dev = vb2_get_drv_priv(vq);
-	struct unicam_dmaqueue *dma_q = &dev->dma_queue;
+	struct unicam_node *node = vb2_get_drv_priv(vq);
+	struct unicam_device *dev = node->dev;
+	struct unicam_dmaqueue *dma_q = &node->dma_queue;
 	struct unicam_buffer *buf, *tmp;
 	unsigned long flags;
 
@@ -1434,22 +1454,24 @@ static void unicam_stop_streaming(struct
 	unicam_disable(dev);
 
 	/* Release all active buffers */
-	spin_lock_irqsave(&dev->dma_queue_lock, flags);
+	spin_lock_irqsave(&node->dma_queue_lock, flags);
 	list_for_each_entry_safe(buf, tmp, &dma_q->active, list) {
 		list_del(&buf->list);
 		vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
 	}
 
-	if (dev->cur_frm == dev->next_frm) {
-		vb2_buffer_done(&dev->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR);
+	if (node->cur_frm == node->next_frm) {
+		vb2_buffer_done(&node->cur_frm->vb.vb2_buf,
+				VB2_BUF_STATE_ERROR);
 	} else {
-		vb2_buffer_done(&dev->cur_frm->vb.vb2_buf, VB2_BUF_STATE_ERROR);
-		vb2_buffer_done(&dev->next_frm->vb.vb2_buf,
+		vb2_buffer_done(&node->cur_frm->vb.vb2_buf,
+				VB2_BUF_STATE_ERROR);
+		vb2_buffer_done(&node->next_frm->vb.vb2_buf,
 				VB2_BUF_STATE_ERROR);
 	}
-	dev->cur_frm = NULL;
-	dev->next_frm = NULL;
-	spin_unlock_irqrestore(&dev->dma_queue_lock, flags);
+	node->cur_frm = NULL;
+	node->next_frm = NULL;
+	spin_unlock_irqrestore(&node->dma_queue_lock, flags);
 
 	clk_disable_unprepare(dev->clock);
 	unicam_runtime_put(dev);
@@ -1458,7 +1480,8 @@ static void unicam_stop_streaming(struct
 static int unicam_enum_input(struct file *file, void *priv,
 			     struct v4l2_input *inp)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	if (inp->index != 0)
 		return -EINVAL;
@@ -1506,21 +1529,24 @@ static int unicam_s_input(struct file *f
 static int unicam_querystd(struct file *file, void *priv,
 			   v4l2_std_id *std)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, video, querystd, std);
 }
 
 static int unicam_g_std(struct file *file, void *priv, v4l2_std_id *std)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, video, g_std, std);
 }
 
 static int unicam_s_std(struct file *file, void *priv, v4l2_std_id std)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	int ret;
 	v4l2_std_id current_std;
 
@@ -1531,29 +1557,31 @@ static int unicam_s_std(struct file *fil
 	if (std == current_std)
 		return 0;
 
-	if (vb2_is_busy(&dev->buffer_queue))
+	if (vb2_is_busy(&node->buffer_queue))
 		return -EBUSY;
 
 	ret = v4l2_subdev_call(dev->sensor, video, s_std, std);
 
 	/* Force recomputation of bytesperline */
-	dev->v_fmt.fmt.pix.bytesperline = 0;
+	node->v_fmt.fmt.pix.bytesperline = 0;
 
-	unicam_reset_format(dev);
+	unicam_reset_format(node);
 
 	return ret;
 }
 
 static int unicam_s_edid(struct file *file, void *priv, struct v4l2_edid *edid)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, pad, set_edid, edid);
 }
 
 static int unicam_g_edid(struct file *file, void *priv, struct v4l2_edid *edid)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, pad, get_edid, edid);
 }
@@ -1561,7 +1589,8 @@ static int unicam_g_edid(struct file *fi
 static int unicam_enum_framesizes(struct file *file, void *priv,
 				  struct v4l2_frmsizeenum *fsize)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	const struct unicam_fmt *fmt;
 	struct v4l2_subdev_frame_size_enum fse;
 	int ret;
@@ -1596,7 +1625,8 @@ static int unicam_enum_framesizes(struct
 static int unicam_enum_frameintervals(struct file *file, void *priv,
 				      struct v4l2_frmivalenum *fival)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	const struct unicam_fmt *fmt;
 	struct v4l2_subdev_frame_interval_enum fie = {
 		.index = fival->index,
@@ -1624,14 +1654,16 @@ static int unicam_enum_frameintervals(st
 
 static int unicam_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_g_parm_cap(video_devdata(file), dev->sensor, a);
 }
 
 static int unicam_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_s_parm_cap(video_devdata(file), dev->sensor, a);
 }
@@ -1639,7 +1671,8 @@ static int unicam_s_parm(struct file *fi
 static int unicam_g_dv_timings(struct file *file, void *priv,
 			       struct v4l2_dv_timings *timings)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, video, g_dv_timings, timings);
 }
@@ -1647,7 +1680,8 @@ static int unicam_g_dv_timings(struct fi
 static int unicam_s_dv_timings(struct file *file, void *priv,
 			       struct v4l2_dv_timings *timings)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	struct v4l2_dv_timings current_timings;
 	int ret;
 
@@ -1657,15 +1691,15 @@ static int unicam_s_dv_timings(struct fi
 	if (v4l2_match_dv_timings(timings, &current_timings, 0, false))
 		return 0;
 
-	if (vb2_is_busy(&dev->buffer_queue))
+	if (vb2_is_busy(&node->buffer_queue))
 		return -EBUSY;
 
 	ret = v4l2_subdev_call(dev->sensor, video, s_dv_timings, timings);
 
 	/* Force recomputation of bytesperline */
-	dev->v_fmt.fmt.pix.bytesperline = 0;
+	node->v_fmt.fmt.pix.bytesperline = 0;
 
-	unicam_reset_format(dev);
+	unicam_reset_format(node);
 
 	return ret;
 }
@@ -1673,7 +1707,8 @@ static int unicam_s_dv_timings(struct fi
 static int unicam_query_dv_timings(struct file *file, void *priv,
 				   struct v4l2_dv_timings *timings)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, video, query_dv_timings, timings);
 }
@@ -1681,7 +1716,8 @@ static int unicam_query_dv_timings(struc
 static int unicam_enum_dv_timings(struct file *file, void *priv,
 				  struct v4l2_enum_dv_timings *timings)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, pad, enum_dv_timings, timings);
 }
@@ -1689,7 +1725,8 @@ static int unicam_enum_dv_timings(struct
 static int unicam_dv_timings_cap(struct file *file, void *priv,
 				 struct v4l2_dv_timings_cap *cap)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 
 	return v4l2_subdev_call(dev->sensor, pad, dv_timings_cap, cap);
 }
@@ -1707,7 +1744,8 @@ static int unicam_subscribe_event(struct
 
 static int unicam_log_status(struct file *file, void *fh)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	struct unicam_cfg *cfg = &dev->cfg;
 	u32 reg;
 
@@ -1716,10 +1754,10 @@ static int unicam_log_status(struct file
 
 	unicam_info(dev, "-----Receiver status-----\n");
 	unicam_info(dev, "V4L2 width/height:   %ux%u\n",
-		    dev->v_fmt.fmt.pix.width, dev->v_fmt.fmt.pix.height);
-	unicam_info(dev, "Mediabus format:     %08x\n", dev->fmt->code);
+		    node->v_fmt.fmt.pix.width, node->v_fmt.fmt.pix.height);
+	unicam_info(dev, "Mediabus format:     %08x\n", node->fmt->code);
 	unicam_info(dev, "V4L2 format:         %08x\n",
-		    dev->v_fmt.fmt.pix.pixelformat);
+		    node->v_fmt.fmt.pix.pixelformat);
 	reg = reg_read(&dev->cfg, UNICAM_IPIPE);
 	unicam_info(dev, "Unpacking/packing:   %u / %u\n",
 		    get_field(reg, UNICAM_PUM_MASK),
@@ -1744,7 +1782,7 @@ static void unicam_notify(struct v4l2_su
 
 	switch (notification) {
 	case V4L2_DEVICE_NOTIFY_EVENT:
-		v4l2_event_queue(&dev->video_dev, arg);
+		v4l2_event_queue(&dev->node[0].video_dev, arg);
 		break;
 	default:
 		break;
@@ -1767,10 +1805,11 @@ static const struct vb2_ops unicam_video
  */
 static int unicam_open(struct file *file)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	int ret;
 
-	mutex_lock(&dev->lock);
+	mutex_lock(&node->lock);
 
 	ret = v4l2_fh_open(file);
 	if (ret) {
@@ -1790,18 +1829,19 @@ static int unicam_open(struct file *file
 	ret = 0;
 
 unlock:
-	mutex_unlock(&dev->lock);
+	mutex_unlock(&node->lock);
 	return ret;
 }
 
 static int unicam_release(struct file *file)
 {
-	struct unicam_device *dev = video_drvdata(file);
+	struct unicam_node *node = video_drvdata(file);
+	struct unicam_device *dev = node->dev;
 	struct v4l2_subdev *sd = dev->sensor;
 	bool fh_singular;
 	int ret;
 
-	mutex_lock(&dev->lock);
+	mutex_lock(&node->lock);
 
 	fh_singular = v4l2_fh_is_singular_file(file);
 
@@ -1810,7 +1850,7 @@ static int unicam_release(struct file *f
 	if (fh_singular)
 		v4l2_subdev_call(sd, core, s_power, 0);
 
-	mutex_unlock(&dev->lock);
+	mutex_unlock(&node->lock);
 
 	return ret;
 }
@@ -1892,7 +1932,8 @@ unicam_async_bound(struct v4l2_async_not
 	return 0;
 }
 
-static int unicam_probe_complete(struct unicam_device *unicam)
+static int register_node(struct unicam_device *unicam, struct unicam_node *node,
+			 enum v4l2_buf_type type, int pad_id)
 {
 	struct video_device *vdev;
 	struct vb2_queue *q;
@@ -1900,15 +1941,7 @@ static int unicam_probe_complete(struct
 	const struct unicam_fmt *fmt;
 	int ret;
 
-	v4l2_set_subdev_hostdata(unicam->sensor, unicam);
-
-	unicam->v4l2_dev.notify = unicam_notify;
-
-	unicam->sensor_config = v4l2_subdev_alloc_pad_config(unicam->sensor);
-	if (!unicam->sensor_config)
-		return -ENOMEM;
-
-	ret = __subdev_get_format(unicam, &mbus_fmt);
+	ret = __subdev_get_format(unicam, &mbus_fmt, pad_id);
 	if (ret) {
 		unicam_err(unicam, "Failed to get_format - ret %d\n", ret);
 		return ret;
@@ -1938,14 +1971,15 @@ static int unicam_probe_complete(struct
 			return -EINVAL;
 	}
 
-	unicam->fmt = fmt;
+	node->pad_id = pad_id;
+	node->fmt = fmt;
 	if (fmt->fourcc)
-		unicam->v_fmt.fmt.pix.pixelformat = fmt->fourcc;
+		node->v_fmt.fmt.pix.pixelformat = fmt->fourcc;
 	else
-		unicam->v_fmt.fmt.pix.pixelformat = fmt->repacked_fourcc;
+		node->v_fmt.fmt.pix.pixelformat = fmt->repacked_fourcc;
 
 	/* Read current subdev format */
-	unicam_reset_format(unicam);
+	unicam_reset_format(node);
 
 	if (v4l2_subdev_has_op(unicam->sensor, video, s_std)) {
 		v4l2_std_id tvnorms;
@@ -1962,27 +1996,30 @@ static int unicam_probe_complete(struct
 				       g_tvnorms, &tvnorms);
 		if (WARN_ON(ret))
 			return -EINVAL;
-		unicam->video_dev.tvnorms |= tvnorms;
+		node->video_dev.tvnorms |= tvnorms;
 	}
 
-	spin_lock_init(&unicam->dma_queue_lock);
-	mutex_init(&unicam->lock);
+	spin_lock_init(&node->dma_queue_lock);
+	mutex_init(&node->lock);
 
-	/* Add controls from the subdevice */
-	ret = v4l2_ctrl_add_handler(&unicam->ctrl_handler,
-				    unicam->sensor->ctrl_handler, NULL, true);
-	if (ret < 0)
-		return ret;
+	if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+		/* Add controls from the subdevice */
+		ret = v4l2_ctrl_add_handler(&node->ctrl_handler,
+					    unicam->sensor->ctrl_handler, NULL,
+					    true);
+		if (ret < 0)
+			return ret;
+	}
 
-	q = &unicam->buffer_queue;
-	q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	q = &node->buffer_queue;
+	q->type = type;
 	q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
-	q->drv_priv = unicam;
+	q->drv_priv = node;
 	q->ops = &unicam_video_qops;
 	q->mem_ops = &vb2_dma_contig_memops;
 	q->buf_struct_size = sizeof(struct unicam_buffer);
 	q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
-	q->lock = &unicam->lock;
+	q->lock = &node->lock;
 	q->min_buffers_needed = 2;
 	q->dev = &unicam->pdev->dev;
 
@@ -1992,9 +2029,9 @@ static int unicam_probe_complete(struct
 		return ret;
 	}
 
-	INIT_LIST_HEAD(&unicam->dma_queue.active);
+	INIT_LIST_HEAD(&node->dma_queue.active);
 
-	vdev = &unicam->video_dev;
+	vdev = &node->video_dev;
 	strlcpy(vdev->name, UNICAM_MODULE_NAME, sizeof(vdev->name));
 	vdev->release = video_device_release_empty;
 	vdev->fops = &unicam_fops;
@@ -2002,69 +2039,113 @@ static int unicam_probe_complete(struct
 	vdev->v4l2_dev = &unicam->v4l2_dev;
 	vdev->vfl_dir = VFL_DIR_RX;
 	vdev->queue = q;
-	vdev->lock = &unicam->lock;
+	vdev->lock = &node->lock;
 	vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
 			    V4L2_CAP_READWRITE;
-
 	/* If the source has no controls then remove our ctrl handler. */
-	if (list_empty(&unicam->ctrl_handler.ctrls))
+	if (list_empty(&node->ctrl_handler.ctrls))
 		unicam->v4l2_dev.ctrl_handler = NULL;
 
-	video_set_drvdata(vdev, unicam);
+	node->dev = unicam;
+	video_set_drvdata(vdev, node);
 	vdev->entity.flags |= MEDIA_ENT_FL_DEFAULT;
 
 	if (!v4l2_subdev_has_op(unicam->sensor, video, s_std)) {
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_S_STD);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_G_STD);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_ENUMSTD);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_S_STD);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_G_STD);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_ENUMSTD);
 	}
 	if (!v4l2_subdev_has_op(unicam->sensor, video, querystd))
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_QUERYSTD);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_QUERYSTD);
 	if (!v4l2_subdev_has_op(unicam->sensor, video, s_dv_timings)) {
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_S_EDID);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_G_EDID);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_DV_TIMINGS_CAP);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_G_DV_TIMINGS);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_S_DV_TIMINGS);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_ENUM_DV_TIMINGS);
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_QUERY_DV_TIMINGS);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_S_EDID);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_G_EDID);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_DV_TIMINGS_CAP);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_G_DV_TIMINGS);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_S_DV_TIMINGS);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_ENUM_DV_TIMINGS);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_QUERY_DV_TIMINGS);
 	}
 	if (!v4l2_subdev_has_op(unicam->sensor, pad, enum_frame_interval))
-		v4l2_disable_ioctl(&unicam->video_dev,
+		v4l2_disable_ioctl(&node->video_dev,
 				   VIDIOC_ENUM_FRAMEINTERVALS);
 	if (!v4l2_subdev_has_op(unicam->sensor, video, g_frame_interval))
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_G_PARM);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_G_PARM);
 	if (!v4l2_subdev_has_op(unicam->sensor, video, s_frame_interval))
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_S_PARM);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_S_PARM);
 
 	if (!v4l2_subdev_has_op(unicam->sensor, pad, enum_frame_size))
-		v4l2_disable_ioctl(&unicam->video_dev, VIDIOC_ENUM_FRAMESIZES);
+		v4l2_disable_ioctl(&node->video_dev, VIDIOC_ENUM_FRAMESIZES);
 
 	ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
 	if (ret) {
 		unicam_err(unicam, "Unable to register video device.\n");
 		return ret;
 	}
+	node->registered = true;
 
-	ret = v4l2_device_register_ro_subdev_nodes(&unicam->v4l2_dev);
+	ret = media_create_pad_link(&unicam->sensor->entity,
+				    0, &node->video_dev.entity, 0,
+				    MEDIA_LNK_FL_ENABLED |
+				    MEDIA_LNK_FL_IMMUTABLE);
+	if (ret)
+		unicam_err(unicam, "Unable to create pad links.\n");
+
+	return ret;
+}
+
+static void unregister_nodes(struct unicam_device *unicam)
+{
+	if (unicam->node[0].registered) {
+		video_unregister_device(&unicam->node[0].video_dev);
+		unicam->node[0].registered = false;
+	}
+	if (unicam->node[1].registered) {
+		video_unregister_device(&unicam->node[1].video_dev);
+		unicam->node[1].registered = false;
+	}
+}
+
+static int unicam_probe_complete(struct unicam_device *unicam)
+{
+	int ret;
+
+	v4l2_set_subdev_hostdata(unicam->sensor, unicam);
+
+	unicam->v4l2_dev.notify = unicam_notify;
+
+	unicam->sensor_config = v4l2_subdev_alloc_pad_config(unicam->sensor);
+	if (!unicam->sensor_config)
+		return -ENOMEM;
+
+	ret = register_node(unicam, &unicam->node[0],
+			    V4L2_BUF_TYPE_VIDEO_CAPTURE, 0);
 	if (ret) {
-		unicam_err(unicam,
-			   "Unable to register subdev nodes.\n");
-		video_unregister_device(&unicam->video_dev);
-		return ret;
+		unicam_err(unicam, "Unable to register subdev node 0.\n");
+		goto unregister;
+	}
+	if (unicam->sensor->entity.num_pads >= 2) {
+		ret = register_node(unicam, &unicam->node[1],
+				    V4L2_BUF_TYPE_META_CAPTURE, 1);
+		if (ret) {
+			unicam_err(unicam,
+				   "Unable to register subdev node 1.\n");
+			goto unregister;
+		}
 	}
 
-	ret = media_create_pad_link(&unicam->sensor->entity, 0,
-				    &unicam->video_dev.entity, 0,
-				    MEDIA_LNK_FL_ENABLED |
-				    MEDIA_LNK_FL_IMMUTABLE);
+	ret = v4l2_device_register_ro_subdev_nodes(&unicam->v4l2_dev);
 	if (ret) {
-		unicam_err(unicam, "Unable to create pad links.\n");
-		video_unregister_device(&unicam->video_dev);
-		return ret;
+		unicam_err(unicam, "Unable to register subdev nodes.\n");
+		goto unregister;
 	}
 
 	return 0;
+
+unregister:
+	unregister_nodes(unicam);
+
+	return ret;
 }
 
 static int unicam_async_complete(struct v4l2_async_notifier *notifier)
@@ -2274,7 +2355,8 @@ static int unicam_probe(struct platform_
 		 pdev->dev.driver->name, dev_name(&pdev->dev));
 	unicam->mdev.hw_revision = 1;
 
-	media_entity_pads_init(&unicam->video_dev.entity, 1, &unicam->pad);
+	media_entity_pads_init(&unicam->node[0].video_dev.entity, 1,
+			       &unicam->node[0].pad);
 	media_device_init(&unicam->mdev);
 
 	unicam->v4l2_dev.mdev = &unicam->mdev;
@@ -2294,7 +2376,7 @@ static int unicam_probe(struct platform_
 	}
 
 	/* Reserve space for the controls */
-	hdl = &unicam->ctrl_handler;
+	hdl = &unicam->node[0].ctrl_handler;
 	ret = v4l2_ctrl_handler_init(hdl, 16);
 	if (ret < 0)
 		goto media_unregister;
@@ -2335,9 +2417,9 @@ static int unicam_remove(struct platform
 	pm_runtime_disable(&pdev->dev);
 
 	v4l2_async_notifier_unregister(&unicam->notifier);
-	v4l2_ctrl_handler_free(&unicam->ctrl_handler);
+	v4l2_ctrl_handler_free(&unicam->node[0].ctrl_handler);
 	v4l2_device_unregister(&unicam->v4l2_dev);
-	video_unregister_device(&unicam->video_dev);
+	unregister_nodes(unicam);
 	if (unicam->sensor_config)
 		v4l2_subdev_free_pad_config(unicam->sensor_config);
 	media_device_unregister(&unicam->mdev);