Content-Security-Policy: default-src 'none'
Content-Type: text/plain; charset=UTF-8
Content-Length: 36021
Content-Disposition: inline; filename="950-0492-media-v4l-Add-definitions-for-HEVC-stateless-decodin.patch"
Last-Modified: Tue, 10 Sep 2024 18:48:19 GMT
Expires: Fri, 08 Sep 2034 18:48:19 GMT
ETag: "e08d2481eddf1983f21e291084567a3770eef33c"

From 5f6c08984a6578201fe3a2394ccb0d3a30fdf027 Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Date: Tue, 22 Oct 2019 12:26:52 -0300
Subject: [PATCH] media: v4l: Add definitions for HEVC stateless
 decoding

This introduces the required definitions for HEVC decoding support with
stateless VPUs. The controls associated to the HEVC slice format provide
the required meta-data for decoding slices extracted from the bitstream.

They are not exported to the public V4L2 API since reworking this API
will likely be needed for covering various use-cases and new hardware.

Multi-slice decoding is exposed as a valid decoding mode to match current
H.264 support but it is not yet implemented.

The interface comes with the following limitations:
* No custom quantization matrices (scaling lists);
* Support for a single temporal layer only;
* No slice entry point offsets support;
* No conformance window support;
* No VUI parameters support;
* No support for SPS extensions: range, multilayer, 3d, scc, 4 bits;
* No support for PPS extensions: range, multilayer, 3d, scc, 4 bits.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
[hverkuil-cisco@xs4all.nl: use 1ULL in flags defines in hevc-ctrls.h]
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
---
 Documentation/media/uapi/v4l/biblio.rst       |   9 +
 .../media/uapi/v4l/ext-ctrls-codec.rst        | 553 +++++++++++++++++-
 .../media/uapi/v4l/vidioc-queryctrl.rst       |  18 +
 .../media/videodev2.h.rst.exceptions          |   3 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 109 +++-
 drivers/media/v4l2-core/v4l2-ioctl.c          |   1 +
 include/media/hevc-ctrls.h                    | 212 +++++++
 include/media/v4l2-ctrls.h                    |   7 +
 8 files changed, 908 insertions(+), 4 deletions(-)
 create mode 100644 include/media/hevc-ctrls.h

--- a/Documentation/media/uapi/v4l/biblio.rst
+++ b/Documentation/media/uapi/v4l/biblio.rst
@@ -131,6 +131,15 @@ ITU-T Rec. H.264 Specification (04/2017
 
 :author:    International Telecommunication Union (http://www.itu.ch)
 
+.. _hevc:
+
+ITU H.265/HEVC
+==============
+
+:title:     ITU-T Rec. H.265 | ISO/IEC 23008-2 "High Efficiency Video Coding"
+
+:author:    International Telecommunication Union (http://www.itu.ch), International Organisation for Standardisation (http://www.iso.ch)
+
 .. _jfif:
 
 JFIF
--- a/Documentation/media/uapi/v4l/ext-ctrls-codec.rst
+++ b/Documentation/media/uapi/v4l/ext-ctrls-codec.rst
@@ -1983,9 +1983,9 @@ enum v4l2_mpeg_video_h264_hierarchical_c
       - ``reference_ts``
       - Timestamp of the V4L2 capture buffer to use as reference, used
         with B-coded and P-coded frames. The timestamp refers to the
-	``timestamp`` field in struct :c:type:`v4l2_buffer`. Use the
-	:c:func:`v4l2_timeval_to_ns()` function to convert the struct
-	:c:type:`timeval` in struct :c:type:`v4l2_buffer` to a __u64.
+        ``timestamp`` field in struct :c:type:`v4l2_buffer`. Use the
+        :c:func:`v4l2_timeval_to_ns()` function to convert the struct
+        :c:type:`timeval` in struct :c:type:`v4l2_buffer` to a __u64.
     * - __u16
       - ``frame_num``
       -
@@ -3693,3 +3693,550 @@ enum v4l2_mpeg_video_hevc_size_of_length
     Indicates whether to generate SPS and PPS at every IDR. Setting it to 0
     disables generating SPS and PPS at every IDR. Setting it to one enables
     generating SPS and PPS at every IDR.
+
+.. _v4l2-mpeg-hevc:
+
+``V4L2_CID_MPEG_VIDEO_HEVC_SPS (struct)``
+    Specifies the Sequence Parameter Set fields (as extracted from the
+    bitstream) for the associated HEVC slice data.
+    These bitstream parameters are defined according to :ref:`hevc`.
+    They are described in section 7.4.3.2 "Sequence parameter set RBSP
+    semantics" of the specification.
+
+.. c:type:: v4l2_ctrl_hevc_sps
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_sps
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u16
+      - ``pic_width_in_luma_samples``
+      -
+    * - __u16
+      - ``pic_height_in_luma_samples``
+      -
+    * - __u8
+      - ``bit_depth_luma_minus8``
+      -
+    * - __u8
+      - ``bit_depth_chroma_minus8``
+      -
+    * - __u8
+      - ``log2_max_pic_order_cnt_lsb_minus4``
+      -
+    * - __u8
+      - ``sps_max_dec_pic_buffering_minus1``
+      -
+    * - __u8
+      - ``sps_max_num_reorder_pics``
+      -
+    * - __u8
+      - ``sps_max_latency_increase_plus1``
+      -
+    * - __u8
+      - ``log2_min_luma_coding_block_size_minus3``
+      -
+    * - __u8
+      - ``log2_diff_max_min_luma_coding_block_size``
+      -
+    * - __u8
+      - ``log2_min_luma_transform_block_size_minus2``
+      -
+    * - __u8
+      - ``log2_diff_max_min_luma_transform_block_size``
+      -
+    * - __u8
+      - ``max_transform_hierarchy_depth_inter``
+      -
+    * - __u8
+      - ``max_transform_hierarchy_depth_intra``
+      -
+    * - __u8
+      - ``pcm_sample_bit_depth_luma_minus1``
+      -
+    * - __u8
+      - ``pcm_sample_bit_depth_chroma_minus1``
+      -
+    * - __u8
+      - ``log2_min_pcm_luma_coding_block_size_minus3``
+      -
+    * - __u8
+      - ``log2_diff_max_min_pcm_luma_coding_block_size``
+      -
+    * - __u8
+      - ``num_short_term_ref_pic_sets``
+      -
+    * - __u8
+      - ``num_long_term_ref_pics_sps``
+      -
+    * - __u8
+      - ``chroma_format_idc``
+      -
+    * - __u64
+      - ``flags``
+      - See :ref:`Sequence Parameter Set Flags <hevc_sps_flags>`
+
+.. _hevc_sps_flags:
+
+``Sequence Parameter Set Flags``
+
+.. cssclass:: longtable
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - ``V4L2_HEVC_SPS_FLAG_SEPARATE_COLOUR_PLANE``
+      - 0x00000001
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED``
+      - 0x00000002
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_AMP_ENABLED``
+      - 0x00000004
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_SAMPLE_ADAPTIVE_OFFSET``
+      - 0x00000008
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_PCM_ENABLED``
+      - 0x00000010
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_PCM_LOOP_FILTER_DISABLED``
+      - 0x00000020
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT``
+      - 0x00000040
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED``
+      - 0x00000080
+      -
+    * - ``V4L2_HEVC_SPS_FLAG_STRONG_INTRA_SMOOTHING_ENABLED``
+      - 0x00000100
+      -
+
+``V4L2_CID_MPEG_VIDEO_HEVC_PPS (struct)``
+    Specifies the Picture Parameter Set fields (as extracted from the
+    bitstream) for the associated HEVC slice data.
+    These bitstream parameters are defined according to :ref:`hevc`.
+    They are described in section 7.4.3.3 "Picture parameter set RBSP
+    semantics" of the specification.
+
+.. c:type:: v4l2_ctrl_hevc_pps
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_pps
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``num_extra_slice_header_bits``
+      -
+    * - __s8
+      - ``init_qp_minus26``
+      -
+    * - __u8
+      - ``diff_cu_qp_delta_depth``
+      -
+    * - __s8
+      - ``pps_cb_qp_offset``
+      -
+    * - __s8
+      - ``pps_cr_qp_offset``
+      -
+    * - __u8
+      - ``num_tile_columns_minus1``
+      -
+    * - __u8
+      - ``num_tile_rows_minus1``
+      -
+    * - __u8
+      - ``column_width_minus1[20]``
+      -
+    * - __u8
+      - ``row_height_minus1[22]``
+      -
+    * - __s8
+      - ``pps_beta_offset_div2``
+      -
+    * - __s8
+      - ``pps_tc_offset_div2``
+      -
+    * - __u8
+      - ``log2_parallel_merge_level_minus2``
+      -
+    * - __u8
+      - ``padding[4]``
+      - Applications and drivers must set this to zero.
+    * - __u64
+      - ``flags``
+      - See :ref:`Picture Parameter Set Flags <hevc_pps_flags>`
+
+.. _hevc_pps_flags:
+
+``Picture Parameter Set Flags``
+
+.. cssclass:: longtable
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - ``V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT``
+      - 0x00000001
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT``
+      - 0x00000002
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_SIGN_DATA_HIDING_ENABLED``
+      - 0x00000004
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_CABAC_INIT_PRESENT``
+      - 0x00000008
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_CONSTRAINED_INTRA_PRED``
+      - 0x00000010
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_TRANSFORM_SKIP_ENABLED``
+      - 0x00000020
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED``
+      - 0x00000040
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_PPS_SLICE_CHROMA_QP_OFFSETS_PRESENT``
+      - 0x00000080
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_WEIGHTED_PRED``
+      - 0x00000100
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_WEIGHTED_BIPRED``
+      - 0x00000200
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_TRANSQUANT_BYPASS_ENABLED``
+      - 0x00000400
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_TILES_ENABLED``
+      - 0x00000800
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED``
+      - 0x00001000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED``
+      - 0x00002000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED``
+      - 0x00004000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_OVERRIDE_ENABLED``
+      - 0x00008000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER``
+      - 0x00010000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT``
+      - 0x00020000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
+      - 0x00040000
+      -
+
+``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
+    Specifies various slice-specific parameters, especially from the NAL unit
+    header, general slice segment header and weighted prediction parameter
+    parts of the bitstream.
+    These bitstream parameters are defined according to :ref:`hevc`.
+    They are described in section 7.4.7 "General slice segment header
+    semantics" of the specification.
+
+.. c:type:: v4l2_ctrl_hevc_slice_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_slice_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u32
+      - ``bit_size``
+      - Size (in bits) of the current slice data.
+    * - __u32
+      - ``data_bit_offset``
+      - Offset (in bits) to the video data in the current slice data.
+    * - __u8
+      - ``nal_unit_type``
+      -
+    * - __u8
+      - ``nuh_temporal_id_plus1``
+      -
+    * - __u8
+      - ``slice_type``
+      -
+	(V4L2_HEVC_SLICE_TYPE_I, V4L2_HEVC_SLICE_TYPE_P or
+	V4L2_HEVC_SLICE_TYPE_B).
+    * - __u8
+      - ``colour_plane_id``
+      -
+    * - __u16
+      - ``slice_pic_order_cnt``
+      -
+    * - __u8
+      - ``num_ref_idx_l0_active_minus1``
+      -
+    * - __u8
+      - ``num_ref_idx_l1_active_minus1``
+      -
+    * - __u8
+      - ``collocated_ref_idx``
+      -
+    * - __u8
+      - ``five_minus_max_num_merge_cand``
+      -
+    * - __s8
+      - ``slice_qp_delta``
+      -
+    * - __s8
+      - ``slice_cb_qp_offset``
+      -
+    * - __s8
+      - ``slice_cr_qp_offset``
+      -
+    * - __s8
+      - ``slice_act_y_qp_offset``
+      -
+    * - __s8
+      - ``slice_act_cb_qp_offset``
+      -
+    * - __s8
+      - ``slice_act_cr_qp_offset``
+      -
+    * - __s8
+      - ``slice_beta_offset_div2``
+      -
+    * - __s8
+      - ``slice_tc_offset_div2``
+      -
+    * - __u8
+      - ``pic_struct``
+      -
+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - __u8
+      - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The list of L0 reference elements as indices in the DPB.
+    * - __u8
+      - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The list of L1 reference elements as indices in the DPB.
+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that come before
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that come after
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set.
+    * - __u8
+      - ``padding[7]``
+      - Applications and drivers must set this to zero.
+    * - struct :c:type:`v4l2_hevc_dpb_entry`
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference frames.
+    * - struct :c:type:`v4l2_hevc_pred_weight_table`
+      - ``pred_weight_table``
+      - The prediction weight coefficients for inter-picture prediction.
+    * - __u64
+      - ``flags``
+      - See :ref:`Slice Parameters Flags <hevc_slice_params_flags>`
+
+.. _hevc_slice_params_flags:
+
+``Slice Parameters Flags``
+
+.. cssclass:: longtable
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_LUMA``
+      - 0x00000001
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_CHROMA``
+      - 0x00000002
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED``
+      - 0x00000004
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_MVD_L1_ZERO``
+      - 0x00000008
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_CABAC_INIT``
+      - 0x00000010
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0``
+      - 0x00000020
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_USE_INTEGER_MV``
+      - 0x00000040
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_DEBLOCKING_FILTER_DISABLED``
+      - 0x00000080
+      -
+    * - ``V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED``
+      - 0x00000100
+      -
+
+.. c:type:: v4l2_hevc_dpb_entry
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_hevc_dpb_entry
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u64
+      - ``timestamp``
+      - Timestamp of the V4L2 capture buffer to use as reference, used
+        with B-coded and P-coded frames. The timestamp refers to the
+	``timestamp`` field in struct :c:type:`v4l2_buffer`. Use the
+	:c:func:`v4l2_timeval_to_ns()` function to convert the struct
+	:c:type:`timeval` in struct :c:type:`v4l2_buffer` to a __u64.
+    * - __u8
+      - ``rps``
+      - The reference set for the reference frame
+        (V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_BEFORE,
+        V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_AFTER or
+        V4L2_HEVC_DPB_ENTRY_RPS_LT_CURR)
+    * - __u8
+      - ``field_pic``
+      - Whether the reference is a field picture or a frame.
+    * - __u16
+      - ``pic_order_cnt[2]``
+      - The picture order count of the reference. Only the first element of the
+        array is used for frame pictures, while the first element identifies the
+        top field and the second the bottom field in field-coded pictures.
+    * - __u8
+      - ``padding[2]``
+      - Applications and drivers must set this to zero.
+
+.. c:type:: v4l2_hevc_pred_weight_table
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_hevc_pred_weight_table
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_log2_weight_denom``
+      -
+    * - __s8
+      - ``delta_chroma_log2_weight_denom``
+      -
+    * - __s8
+      - ``delta_luma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __s8
+      - ``luma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __s8
+      - ``delta_chroma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]``
+      -
+    * - __s8
+      - ``chroma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]``
+      -
+    * - __s8
+      - ``delta_luma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __s8
+      - ``luma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __s8
+      - ``delta_chroma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]``
+      -
+    * - __s8
+      - ``chroma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2]``
+      -
+    * - __u8
+      - ``padding[6]``
+      - Applications and drivers must set this to zero.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE (enum)``
+    Specifies the decoding mode to use. Currently exposes slice-based and
+    frame-based decoding but new modes might be added later on.
+    This control is used as a modifier for V4L2_PIX_FMT_HEVC_SLICE
+    pixel format. Applications that support V4L2_PIX_FMT_HEVC_SLICE
+    are required to set this control in order to specify the decoding mode
+    that is expected for the buffer.
+    Drivers may expose a single or multiple decoding modes, depending
+    on what they can support.
+
+    .. note::
+
+       This menu control is not yet part of the public kernel API and
+       it is expected to change.
+
+.. c:type:: v4l2_mpeg_video_hevc_decode_mode
+
+.. cssclass:: longtable
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - ``V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_SLICE_BASED``
+      - 0
+      - Decoding is done at the slice granularity.
+        The OUTPUT buffer must contain a single slice.
+    * - ``V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED``
+      - 1
+      - Decoding is done at the frame granularity.
+        The OUTPUT buffer must contain all slices needed to decode the
+        frame. The OUTPUT buffer must also contain both fields.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_START_CODE (enum)``
+    Specifies the HEVC slice start code expected for each slice.
+    This control is used as a modifier for V4L2_PIX_FMT_HEVC_SLICE
+    pixel format. Applications that support V4L2_PIX_FMT_HEVC_SLICE
+    are required to set this control in order to specify the start code
+    that is expected for the buffer.
+    Drivers may expose a single or multiple start codes, depending
+    on what they can support.
+
+    .. note::
+
+       This menu control is not yet part of the public kernel API and
+       it is expected to change.
+
+.. c:type:: v4l2_mpeg_video_hevc_start_code
+
+.. cssclass:: longtable
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - ``V4L2_MPEG_VIDEO_HEVC_START_CODE_NONE``
+      - 0
+      - Selecting this value specifies that HEVC slices are passed
+        to the driver without any start code.
+    * - ``V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B``
+      - 1
+      - Selecting this value specifies that HEVC slices are expected
+        to be prefixed by Annex B start codes. According to :ref:`hevc`
+        valid start codes can be 3-bytes 0x000001 or 4-bytes 0x00000001.
--- a/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
+++ b/Documentation/media/uapi/v4l/vidioc-queryctrl.rst
@@ -479,6 +479,24 @@ See also the examples in :ref:`control`.
       - n/a
       - A struct :c:type:`v4l2_ctrl_h264_decode_params`, containing H264
 	decode parameters for stateless video decoders.
+    * - ``V4L2_CTRL_TYPE_HEVC_SPS``
+      - n/a
+      - n/a
+      - n/a
+      - A struct :c:type:`v4l2_ctrl_hevc_sps`, containing HEVC Sequence
+	Parameter Set for stateless video decoders.
+    * - ``V4L2_CTRL_TYPE_HEVC_PPS``
+      - n/a
+      - n/a
+      - n/a
+      - A struct :c:type:`v4l2_ctrl_hevc_pps`, containing HEVC Picture
+	Parameter Set for stateless video decoders.
+    * - ``V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS``
+      - n/a
+      - n/a
+      - n/a
+      - A struct :c:type:`v4l2_ctrl_hevc_slice_params`, containing HEVC
+	slice parameters for stateless video decoders.
 
 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
 
--- a/Documentation/media/videodev2.h.rst.exceptions
+++ b/Documentation/media/videodev2.h.rst.exceptions
@@ -141,6 +141,9 @@ replace symbol V4L2_CTRL_TYPE_H264_PPS :
 replace symbol V4L2_CTRL_TYPE_H264_SCALING_MATRIX :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_H264_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_H264_DECODE_PARAMS :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_HEVC_SPS :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_HEVC_PPS :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_AREA :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
--- a/drivers/media/v4l2-core/v4l2-ctrls.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
@@ -567,6 +567,16 @@ const char * const *v4l2_ctrl_get_menu(u
 		"Disabled at slice boundary",
 		"NULL",
 	};
+	static const char * const hevc_decode_mode[] = {
+		"Slice-Based",
+		"Frame-Based",
+		NULL,
+	};
+	static const char * const hevc_start_code[] = {
+		"No Start Code",
+		"Annex B Start Code",
+		NULL,
+	};
 
 	switch (id) {
 	case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
@@ -688,7 +698,10 @@ const char * const *v4l2_ctrl_get_menu(u
 		return hevc_tier;
 	case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:
 		return hevc_loop_filter_mode;
-
+	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:
+		return hevc_decode_mode;
+	case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:
+		return hevc_start_code;
 	default:
 		return NULL;
 	}
@@ -958,6 +971,11 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:	return "HEVC Size of Length Field";
 	case V4L2_CID_MPEG_VIDEO_REF_NUMBER_FOR_PFRAMES:	return "Reference Frames for a P-Frame";
 	case V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR:		return "Prepend SPS and PPS to IDR";
+	case V4L2_CID_MPEG_VIDEO_HEVC_SPS:			return "HEVC Sequence Parameter Set";
+	case V4L2_CID_MPEG_VIDEO_HEVC_PPS:			return "HEVC Picture Parameter Set";
+	case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:		return "HEVC Slice Parameters";
+	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:		return "HEVC Decode Mode";
+	case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:		return "HEVC Start Code";
 
 	/* CAMERA controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1267,6 +1285,8 @@ void v4l2_ctrl_fill(u32 id, const char *
 	case V4L2_CID_MPEG_VIDEO_HEVC_SIZE_OF_LENGTH_FIELD:
 	case V4L2_CID_MPEG_VIDEO_HEVC_TIER:
 	case V4L2_CID_MPEG_VIDEO_HEVC_LOOP_FILTER_MODE:
+	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:
+	case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:
 		*type = V4L2_CTRL_TYPE_MENU;
 		break;
 	case V4L2_CID_LINK_FREQ:
@@ -1377,6 +1397,15 @@ void v4l2_ctrl_fill(u32 id, const char *
 	case V4L2_CID_MPEG_VIDEO_VP8_FRAME_HEADER:
 		*type = V4L2_CTRL_TYPE_VP8_FRAME_HEADER;
 		break;
+	case V4L2_CID_MPEG_VIDEO_HEVC_SPS:
+		*type = V4L2_CTRL_TYPE_HEVC_SPS;
+		break;
+	case V4L2_CID_MPEG_VIDEO_HEVC_PPS:
+		*type = V4L2_CTRL_TYPE_HEVC_PPS;
+		break;
+	case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:
+		*type = V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS;
+		break;
 	case V4L2_CID_UNIT_CELL_SIZE:
 		*type = V4L2_CTRL_TYPE_AREA;
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY;
@@ -1678,8 +1707,12 @@ static int std_validate_compound(const s
 {
 	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
 	struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
+	struct v4l2_ctrl_hevc_sps *p_hevc_sps;
+	struct v4l2_ctrl_hevc_pps *p_hevc_pps;
+	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
 	struct v4l2_area *area;
 	void *p = ptr.p + idx * ctrl->elem_size;
+	unsigned int i;
 
 	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
@@ -1755,11 +1788,76 @@ static int std_validate_compound(const s
 		zero_padding(p_vp8_frame_header->entropy_header);
 		zero_padding(p_vp8_frame_header->coder_state);
 		break;
+
+	case V4L2_CTRL_TYPE_HEVC_SPS:
+		p_hevc_sps = p;
+
+		if (!(p_hevc_sps->flags & V4L2_HEVC_SPS_FLAG_PCM_ENABLED)) {
+			p_hevc_sps->pcm_sample_bit_depth_luma_minus1 = 0;
+			p_hevc_sps->pcm_sample_bit_depth_chroma_minus1 = 0;
+			p_hevc_sps->log2_min_pcm_luma_coding_block_size_minus3 = 0;
+			p_hevc_sps->log2_diff_max_min_pcm_luma_coding_block_size = 0;
+		}
+
+		if (!(p_hevc_sps->flags &
+		      V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT))
+			p_hevc_sps->num_long_term_ref_pics_sps = 0;
+		break;
+
+	case V4L2_CTRL_TYPE_HEVC_PPS:
+		p_hevc_pps = p;
+
+		if (!(p_hevc_pps->flags &
+		      V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED))
+			p_hevc_pps->diff_cu_qp_delta_depth = 0;
+
+		if (!(p_hevc_pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED)) {
+			p_hevc_pps->num_tile_columns_minus1 = 0;
+			p_hevc_pps->num_tile_rows_minus1 = 0;
+			memset(&p_hevc_pps->column_width_minus1, 0,
+			       sizeof(p_hevc_pps->column_width_minus1));
+			memset(&p_hevc_pps->row_height_minus1, 0,
+			       sizeof(p_hevc_pps->row_height_minus1));
+
+			p_hevc_pps->flags &=
+				~V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED;
+		}
+
+		if (p_hevc_pps->flags &
+		    V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER) {
+			p_hevc_pps->pps_beta_offset_div2 = 0;
+			p_hevc_pps->pps_tc_offset_div2 = 0;
+		}
+
+		zero_padding(*p_hevc_pps);
+		break;
+
+	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
+		p_hevc_slice_params = p;
+
+		if (p_hevc_slice_params->num_active_dpb_entries >
+		    V4L2_HEVC_DPB_ENTRIES_NUM_MAX)
+			return -EINVAL;
+
+		zero_padding(p_hevc_slice_params->pred_weight_table);
+
+		for (i = 0; i < p_hevc_slice_params->num_active_dpb_entries;
+		     i++) {
+			struct v4l2_hevc_dpb_entry *dpb_entry =
+				&p_hevc_slice_params->dpb[i];
+
+			zero_padding(*dpb_entry);
+		}
+
+		zero_padding(*p_hevc_slice_params);
+		break;
+
 	case V4L2_CTRL_TYPE_AREA:
 		area = p;
 		if (!area->width || !area->height)
 			return -EINVAL;
 		break;
+
 	default:
 		return -EINVAL;
 	}
@@ -2434,6 +2532,15 @@ static struct v4l2_ctrl *v4l2_ctrl_new(s
 	case V4L2_CTRL_TYPE_VP8_FRAME_HEADER:
 		elem_size = sizeof(struct v4l2_ctrl_vp8_frame_header);
 		break;
+	case V4L2_CTRL_TYPE_HEVC_SPS:
+		elem_size = sizeof(struct v4l2_ctrl_hevc_sps);
+		break;
+	case V4L2_CTRL_TYPE_HEVC_PPS:
+		elem_size = sizeof(struct v4l2_ctrl_hevc_pps);
+		break;
+	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
+		elem_size = sizeof(struct v4l2_ctrl_hevc_slice_params);
+		break;
 	case V4L2_CTRL_TYPE_AREA:
 		elem_size = sizeof(struct v4l2_area);
 		break;
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1356,6 +1356,7 @@ static void v4l_fill_fmtdesc(struct v4l2
 		case V4L2_PIX_FMT_VP8_FRAME:    descr = "VP8 Frame"; break;
 		case V4L2_PIX_FMT_VP9:		descr = "VP9"; break;
 		case V4L2_PIX_FMT_HEVC:		descr = "HEVC"; break; /* aka H.265 */
+		case V4L2_PIX_FMT_HEVC_SLICE:	descr = "HEVC Parsed Slice Data"; break;
 		case V4L2_PIX_FMT_FWHT:		descr = "FWHT"; break; /* used in vicodec */
 		case V4L2_PIX_FMT_FWHT_STATELESS:	descr = "FWHT Stateless"; break; /* used in vicodec */
 		case V4L2_PIX_FMT_CPIA1:	descr = "GSPCA CPiA YUV"; break;
--- /dev/null
+++ b/include/media/hevc-ctrls.h
@@ -0,0 +1,212 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * These are the HEVC state controls for use with stateless HEVC
+ * codec drivers.
+ *
+ * It turns out that these structs are not stable yet and will undergo
+ * more changes. So keep them private until they are stable and ready to
+ * become part of the official public API.
+ */
+
+#ifndef _HEVC_CTRLS_H_
+#define _HEVC_CTRLS_H_
+
+#include <linux/videodev2.h>
+
+/* The pixel format isn't stable at the moment and will likely be renamed. */
+#define V4L2_PIX_FMT_HEVC_SLICE v4l2_fourcc('S', '2', '6', '5') /* HEVC parsed slices */
+
+#define V4L2_CID_MPEG_VIDEO_HEVC_SPS		(V4L2_CID_MPEG_BASE + 1008)
+#define V4L2_CID_MPEG_VIDEO_HEVC_PPS		(V4L2_CID_MPEG_BASE + 1009)
+#define V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS	(V4L2_CID_MPEG_BASE + 1010)
+#define V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE	(V4L2_CID_MPEG_BASE + 1015)
+#define V4L2_CID_MPEG_VIDEO_HEVC_START_CODE	(V4L2_CID_MPEG_BASE + 1016)
+
+/* enum v4l2_ctrl_type type values */
+#define V4L2_CTRL_TYPE_HEVC_SPS 0x0120
+#define V4L2_CTRL_TYPE_HEVC_PPS 0x0121
+#define V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS 0x0122
+
+enum v4l2_mpeg_video_hevc_decode_mode {
+	V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_SLICE_BASED,
+	V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+};
+
+enum v4l2_mpeg_video_hevc_start_code {
+	V4L2_MPEG_VIDEO_HEVC_START_CODE_NONE,
+	V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+};
+
+#define V4L2_HEVC_SLICE_TYPE_B	0
+#define V4L2_HEVC_SLICE_TYPE_P	1
+#define V4L2_HEVC_SLICE_TYPE_I	2
+
+#define V4L2_HEVC_SPS_FLAG_SEPARATE_COLOUR_PLANE		(1ULL << 0)
+#define V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED			(1ULL << 1)
+#define V4L2_HEVC_SPS_FLAG_AMP_ENABLED				(1ULL << 2)
+#define V4L2_HEVC_SPS_FLAG_SAMPLE_ADAPTIVE_OFFSET		(1ULL << 3)
+#define V4L2_HEVC_SPS_FLAG_PCM_ENABLED				(1ULL << 4)
+#define V4L2_HEVC_SPS_FLAG_PCM_LOOP_FILTER_DISABLED		(1ULL << 5)
+#define V4L2_HEVC_SPS_FLAG_LONG_TERM_REF_PICS_PRESENT		(1ULL << 6)
+#define V4L2_HEVC_SPS_FLAG_SPS_TEMPORAL_MVP_ENABLED		(1ULL << 7)
+#define V4L2_HEVC_SPS_FLAG_STRONG_INTRA_SMOOTHING_ENABLED	(1ULL << 8)
+
+/* The controls are not stable at the moment and will likely be reworked. */
+struct v4l2_ctrl_hevc_sps {
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Sequence parameter set */
+	__u16	pic_width_in_luma_samples;
+	__u16	pic_height_in_luma_samples;
+	__u8	bit_depth_luma_minus8;
+	__u8	bit_depth_chroma_minus8;
+	__u8	log2_max_pic_order_cnt_lsb_minus4;
+	__u8	sps_max_dec_pic_buffering_minus1;
+	__u8	sps_max_num_reorder_pics;
+	__u8	sps_max_latency_increase_plus1;
+	__u8	log2_min_luma_coding_block_size_minus3;
+	__u8	log2_diff_max_min_luma_coding_block_size;
+	__u8	log2_min_luma_transform_block_size_minus2;
+	__u8	log2_diff_max_min_luma_transform_block_size;
+	__u8	max_transform_hierarchy_depth_inter;
+	__u8	max_transform_hierarchy_depth_intra;
+	__u8	pcm_sample_bit_depth_luma_minus1;
+	__u8	pcm_sample_bit_depth_chroma_minus1;
+	__u8	log2_min_pcm_luma_coding_block_size_minus3;
+	__u8	log2_diff_max_min_pcm_luma_coding_block_size;
+	__u8	num_short_term_ref_pic_sets;
+	__u8	num_long_term_ref_pics_sps;
+	__u8	chroma_format_idc;
+
+	__u8	padding;
+
+	__u64	flags;
+};
+
+#define V4L2_HEVC_PPS_FLAG_DEPENDENT_SLICE_SEGMENT		(1ULL << 0)
+#define V4L2_HEVC_PPS_FLAG_OUTPUT_FLAG_PRESENT			(1ULL << 1)
+#define V4L2_HEVC_PPS_FLAG_SIGN_DATA_HIDING_ENABLED		(1ULL << 2)
+#define V4L2_HEVC_PPS_FLAG_CABAC_INIT_PRESENT			(1ULL << 3)
+#define V4L2_HEVC_PPS_FLAG_CONSTRAINED_INTRA_PRED		(1ULL << 4)
+#define V4L2_HEVC_PPS_FLAG_TRANSFORM_SKIP_ENABLED		(1ULL << 5)
+#define V4L2_HEVC_PPS_FLAG_CU_QP_DELTA_ENABLED			(1ULL << 6)
+#define V4L2_HEVC_PPS_FLAG_PPS_SLICE_CHROMA_QP_OFFSETS_PRESENT	(1ULL << 7)
+#define V4L2_HEVC_PPS_FLAG_WEIGHTED_PRED			(1ULL << 8)
+#define V4L2_HEVC_PPS_FLAG_WEIGHTED_BIPRED			(1ULL << 9)
+#define V4L2_HEVC_PPS_FLAG_TRANSQUANT_BYPASS_ENABLED		(1ULL << 10)
+#define V4L2_HEVC_PPS_FLAG_TILES_ENABLED			(1ULL << 11)
+#define V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED		(1ULL << 12)
+#define V4L2_HEVC_PPS_FLAG_LOOP_FILTER_ACROSS_TILES_ENABLED	(1ULL << 13)
+#define V4L2_HEVC_PPS_FLAG_PPS_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 14)
+#define V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_OVERRIDE_ENABLED	(1ULL << 15)
+#define V4L2_HEVC_PPS_FLAG_PPS_DISABLE_DEBLOCKING_FILTER	(1ULL << 16)
+#define V4L2_HEVC_PPS_FLAG_LISTS_MODIFICATION_PRESENT		(1ULL << 17)
+#define V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT (1ULL << 18)
+
+struct v4l2_ctrl_hevc_pps {
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture parameter set */
+	__u8	num_extra_slice_header_bits;
+	__s8	init_qp_minus26;
+	__u8	diff_cu_qp_delta_depth;
+	__s8	pps_cb_qp_offset;
+	__s8	pps_cr_qp_offset;
+	__u8	num_tile_columns_minus1;
+	__u8	num_tile_rows_minus1;
+	__u8	column_width_minus1[20];
+	__u8	row_height_minus1[22];
+	__s8	pps_beta_offset_div2;
+	__s8	pps_tc_offset_div2;
+	__u8	log2_parallel_merge_level_minus2;
+
+	__u8	padding[4];
+	__u64	flags;
+};
+
+#define V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_BEFORE	0x01
+#define V4L2_HEVC_DPB_ENTRY_RPS_ST_CURR_AFTER	0x02
+#define V4L2_HEVC_DPB_ENTRY_RPS_LT_CURR		0x03
+
+#define V4L2_HEVC_DPB_ENTRIES_NUM_MAX		16
+
+struct v4l2_hevc_dpb_entry {
+	__u64	timestamp;
+	__u8	rps;
+	__u8	field_pic;
+	__u16	pic_order_cnt[2];
+	__u8	padding[2];
+};
+
+struct v4l2_hevc_pred_weight_table {
+	__s8	delta_luma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__s8	luma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__s8	delta_chroma_weight_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
+	__s8	chroma_offset_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
+
+	__s8	delta_luma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__s8	luma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__s8	delta_chroma_weight_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
+	__s8	chroma_offset_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX][2];
+
+	__u8	padding[6];
+
+	__u8	luma_log2_weight_denom;
+	__s8	delta_chroma_log2_weight_denom;
+};
+
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_LUMA		(1ULL << 0)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_SAO_CHROMA		(1ULL << 1)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_TEMPORAL_MVP_ENABLED	(1ULL << 2)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_MVD_L1_ZERO			(1ULL << 3)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_CABAC_INIT			(1ULL << 4)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_COLLOCATED_FROM_L0		(1ULL << 5)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_USE_INTEGER_MV		(1ULL << 6)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_DEBLOCKING_FILTER_DISABLED (1ULL << 7)
+#define V4L2_HEVC_SLICE_PARAMS_FLAG_SLICE_LOOP_FILTER_ACROSS_SLICES_ENABLED (1ULL << 8)
+
+struct v4l2_ctrl_hevc_slice_params {
+	__u32	bit_size;
+	__u32	data_bit_offset;
+
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: NAL unit header */
+	__u8	nal_unit_type;
+	__u8	nuh_temporal_id_plus1;
+
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
+	__u8	slice_type;
+	__u8	colour_plane_id;
+	__u16	slice_pic_order_cnt;
+	__u8	num_ref_idx_l0_active_minus1;
+	__u8	num_ref_idx_l1_active_minus1;
+	__u8	collocated_ref_idx;
+	__u8	five_minus_max_num_merge_cand;
+	__s8	slice_qp_delta;
+	__s8	slice_cb_qp_offset;
+	__s8	slice_cr_qp_offset;
+	__s8	slice_act_y_qp_offset;
+	__s8	slice_act_cb_qp_offset;
+	__s8	slice_act_cr_qp_offset;
+	__s8	slice_beta_offset_div2;
+	__s8	slice_tc_offset_div2;
+
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Picture timing SEI message */
+	__u8	pic_struct;
+
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
+	__u8	num_active_dpb_entries;
+	__u8	ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+	__u8	ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+
+	__u8	num_rps_poc_st_curr_before;
+	__u8	num_rps_poc_st_curr_after;
+	__u8	num_rps_poc_lt_curr;
+
+	__u8	padding;
+
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
+	struct v4l2_hevc_dpb_entry dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
+
+	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */
+	struct v4l2_hevc_pred_weight_table pred_weight_table;
+
+	__u64	flags;
+};
+
+#endif
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -21,6 +21,7 @@
 #include <media/fwht-ctrls.h>
 #include <media/h264-ctrls.h>
 #include <media/vp8-ctrls.h>
+#include <media/hevc-ctrls.h>
 
 /* forward references */
 struct file;
@@ -50,6 +51,9 @@ struct poll_table_struct;
  * @p_h264_slice_params:	Pointer to a struct v4l2_ctrl_h264_slice_params.
  * @p_h264_decode_params:	Pointer to a struct v4l2_ctrl_h264_decode_params.
  * @p_vp8_frame_header:		Pointer to a VP8 frame header structure.
+ * @p_hevc_sps:			Pointer to an HEVC sequence parameter set structure.
+ * @p_hevc_pps:			Pointer to an HEVC picture parameter set structure.
+ * @p_hevc_slice_params:	Pointer to an HEVC slice parameters structure.
  * @p_area:			Pointer to an area.
  * @p:				Pointer to a compound value.
  */
@@ -69,6 +73,9 @@ union v4l2_ctrl_ptr {
 	struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;
 	struct v4l2_ctrl_h264_decode_params *p_h264_decode_params;
 	struct v4l2_ctrl_vp8_frame_header *p_vp8_frame_header;
+	struct v4l2_ctrl_hevc_sps *p_hevc_sps;
+	struct v4l2_ctrl_hevc_pps *p_hevc_pps;
+	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
 	struct v4l2_area *p_area;
 	void *p;
 };
32' href='#n932'>932</a>
<a id='n933' href='#n933'>933</a>
<a id='n934' href='#n934'>934</a>
<a id='n935' href='#n935'>935</a>
<a id='n936' href='#n936'>936</a>
<a id='n937' href='#n937'>937</a>
<a id='n938' href='#n938'>938</a>
<a id='n939' href='#n939'>939</a>
<a id='n940' href='#n940'>940</a>
<a id='n941' href='#n941'>941</a>
<a id='n942' href='#n942'>942</a>
<a id='n943' href='#n943'>943</a>
<a id='n944' href='#n944'>944</a>
<a id='n945' href='#n945'>945</a>
<a id='n946' href='#n946'>946</a>
<a id='n947' href='#n947'>947</a>
<a id='n948' href='#n948'>948</a>
<a id='n949' href='#n949'>949</a>
<a id='n950' href='#n950'>950</a>
<a id='n951' href='#n951'>951</a>
<a id='n952' href='#n952'>952</a>
<a id='n953' href='#n953'>953</a>
<a id='n954' href='#n954'>954</a>
<a id='n955' href='#n955'>955</a>
<a id='n956' href='#n956'>956</a>
<a id='n957' href='#n957'>957</a>
<a id='n958' href='#n958'>958</a>
<a id='n959' href='#n959'>959</a>
<a id='n960' href='#n960'>960</a>
<a id='n961' href='#n961'>961</a>
<a id='n962' href='#n962'>962</a>
<a id='n963' href='#n963'>963</a>
<a id='n964' href='#n964'>964</a>
<a id='n965' href='#n965'>965</a>
<a id='n966' href='#n966'>966</a>
<a id='n967' href='#n967'>967</a>
<a id='n968' href='#n968'>968</a>
<a id='n969' href='#n969'>969</a>
<a id='n970' href='#n970'>970</a>
<a id='n971' href='#n971'>971</a>
<a id='n972' href='#n972'>972</a>
<a id='n973' href='#n973'>973</a>
<a id='n974' href='#n974'>974</a>
<a id='n975' href='#n975'>975</a>
<a id='n976' href='#n976'>976</a>
<a id='n977' href='#n977'>977</a>
<a id='n978' href='#n978'>978</a>
<a id='n979' href='#n979'>979</a>
<a id='n980' href='#n980'>980</a>
<a id='n981' href='#n981'>981</a>
<a id='n982' href='#n982'>982</a>
<a id='n983' href='#n983'>983</a>
<a id='n984' href='#n984'>984</a>
<a id='n985' href='#n985'>985</a>
<a id='n986' href='#n986'>986</a>
<a id='n987' href='#n987'>987</a>
<a id='n988' href='#n988'>988</a>
<a id='n989' href='#n989'>989</a>
<a id='n990' href='#n990'>990</a>
<a id='n991' href='#n991'>991</a>
<a id='n992' href='#n992'>992</a>
<a id='n993' href='#n993'>993</a>
<a id='n994' href='#n994'>994</a>
<a id='n995' href='#n995'>995</a>
<a id='n996' href='#n996'>996</a>
<a id='n997' href='#n997'>997</a>
<a id='n998' href='#n998'>998</a>
<a id='n999' href='#n999'>999</a>
<a id='n1000' href='#n1000'>1000</a>
<a id='n1001' href='#n1001'>1001</a>
<a id='n1002' href='#n1002'>1002</a>
<a id='n1003' href='#n1003'>1003</a>
<a id='n1004' href='#n1004'>1004</a>
<a id='n1005' href='#n1005'>1005</a>
<a id='n1006' href='#n1006'>1006</a>
<a id='n1007' href='#n1007'>1007</a>
<a id='n1008' href='#n1008'>1008</a>
<a id='n1009' href='#n1009'>1009</a>
<a id='n1010' href='#n1010'>1010</a>
<a id='n1011' href='#n1011'>1011</a>
<a id='n1012' href='#n1012'>1012</a>
<a id='n1013' href='#n1013'>1013</a>
<a id='n1014' href='#n1014'>1014</a>
<a id='n1015' href='#n1015'>1015</a>
<a id='n1016' href='#n1016'>1016</a>
<a id='n1017' href='#n1017'>1017</a>
<a id='n1018' href='#n1018'>1018</a>
<a id='n1019' href='#n1019'>1019</a>
<a id='n1020' href='#n1020'>1020</a>
<a id='n1021' href='#n1021'>1021</a>
<a id='n1022' href='#n1022'>1022</a>
<a id='n1023' href='#n1023'>1023</a>
<a id='n1024' href='#n1024'>1024</a>
<a id='n1025' href='#n1025'>1025</a>
<a id='n1026' href='#n1026'>1026</a>
<a id='n1027' href='#n1027'>1027</a>
<a id='n1028' href='#n1028'>1028</a>
<a id='n1029' href='#n1029'>1029</a>
<a id='n1030' href='#n1030'>1030</a>
<a id='n1031' href='#n1031'>1031</a>
<a id='n1032' href='#n1032'>1032</a>
<a id='n1033' href='#n1033'>1033</a>
<a id='n1034' href='#n1034'>1034</a>
<a id='n1035' href='#n1035'>1035</a>
<a id='n1036' href='#n1036'>1036</a>
<a id='n1037' href='#n1037'>1037</a>
<a id='n1038' href='#n1038'>1038</a>
<a id='n1039' href='#n1039'>1039</a>
<a id='n1040' href='#n1040'>1040</a>
<a id='n1041' href='#n1041'>1041</a>
<a id='n1042' href='#n1042'>1042</a>
<a id='n1043' href='#n1043'>1043</a>
<a id='n1044' href='#n1044'>1044</a>
<a id='n1045' href='#n1045'>1045</a>
<a id='n1046' href='#n1046'>1046</a>
<a id='n1047' href='#n1047'>1047</a>
<a id='n1048' href='#n1048'>1048</a>
<a id='n1049' href='#n1049'>1049</a>
<a id='n1050' href='#n1050'>1050</a>
<a id='n1051' href='#n1051'>1051</a>
<a id='n1052' href='#n1052'>1052</a>
<a id='n1053' href='#n1053'>1053</a>
<a id='n1054' href='#n1054'>1054</a>
<a id='n1055' href='#n1055'>1055</a>
<a id='n1056' href='#n1056'>1056</a>
<a id='n1057' href='#n1057'>1057</a>
<a id='n1058' href='#n1058'>1058</a>
<a id='n1059' href='#n1059'>1059</a>
<a id='n1060' href='#n1060'>1060</a>
<a id='n1061' href='#n1061'>1061</a>
<a id='n1062' href='#n1062'>1062</a>
<a id='n1063' href='#n1063'>1063</a>
<a id='n1064' href='#n1064'>1064</a>
<a id='n1065' href='#n1065'>1065</a>
<a id='n1066' href='#n1066'>1066</a>
<a id='n1067' href='#n1067'>1067</a>
<a id='n1068' href='#n1068'>1068</a>
<a id='n1069' href='#n1069'>1069</a>
<a id='n1070' href='#n1070'>1070</a>
<a id='n1071' href='#n1071'>1071</a>
<a id='n1072' href='#n1072'>1072</a>
<a id='n1073' href='#n1073'>1073</a>
<a id='n1074' href='#n1074'>1074</a>
<a id='n1075' href='#n1075'>1075</a>
<a id='n1076' href='#n1076'>1076</a>
<a id='n1077' href='#n1077'>1077</a>
<a id='n1078' href='#n1078'>1078</a>
<a id='n1079' href='#n1079'>1079</a>
<a id='n1080' href='#n1080'>1080</a>
<a id='n1081' href='#n1081'>1081</a>
<a id='n1082' href='#n1082'>1082</a>
<a id='n1083' href='#n1083'>1083</a>
<a id='n1084' href='#n1084'>1084</a>
</pre></td>
<td class='lines'><pre><code><style>pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */</style><div class="highlight"><pre><span></span>From b466d74b45466b417e364c85c7fce71e9fc3fc7c Mon Sep 17 00:00:00 2001
From: Naushir Patuck &lt;naush@raspberrypi.com&gt;
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 &lt;naush@raspberrypi.com&gt;
<span class="gd">---</span>
 .../media/platform/bcm2835/bcm2835-unicam.c   | 484 ++++++++++--------
 1 file changed, 283 insertions(+), 201 deletions(-)

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