~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/userspace-api/media/v4l/dev-subdev.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/userspace-api/media/v4l/dev-subdev.rst (Version linux-6.12-rc7) and /Documentation/userspace-api/media/v4l/dev-subdev.rst (Version linux-5.8.18)


  1 .. SPDX-License-Identifier: GFDL-1.1-no-invari !!   1 .. Permission is granted to copy, distribute and/or modify this
                                                   >>   2 .. document under the terms of the GNU Free Documentation License,
                                                   >>   3 .. Version 1.1 or any later version published by the Free Software
                                                   >>   4 .. Foundation, with no Invariant Sections, no Front-Cover Texts
                                                   >>   5 .. and no Back-Cover Texts. A copy of the license is included at
                                                   >>   6 .. Documentation/userspace-api/media/fdl-appendix.rst.
                                                   >>   7 ..
                                                   >>   8 .. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
  2                                                     9 
  3 .. _subdev:                                        10 .. _subdev:
  4                                                    11 
  5 ********************                               12 ********************
  6 Sub-device Interface                               13 Sub-device Interface
  7 ********************                               14 ********************
  8                                                    15 
  9 The complex nature of V4L2 devices, where hard     16 The complex nature of V4L2 devices, where hardware is often made of
 10 several integrated circuits that need to inter     17 several integrated circuits that need to interact with each other in a
 11 controlled way, leads to complex V4L2 drivers.     18 controlled way, leads to complex V4L2 drivers. The drivers usually
 12 reflect the hardware model in software, and mo     19 reflect the hardware model in software, and model the different hardware
 13 components as software blocks called sub-devic     20 components as software blocks called sub-devices.
 14                                                    21 
 15 V4L2 sub-devices are usually kernel-only objec     22 V4L2 sub-devices are usually kernel-only objects. If the V4L2 driver
 16 implements the media device API, they will aut     23 implements the media device API, they will automatically inherit from
 17 media entities. Applications will be able to e     24 media entities. Applications will be able to enumerate the sub-devices
 18 and discover the hardware topology using the m     25 and discover the hardware topology using the media entities, pads and
 19 links enumeration API.                             26 links enumeration API.
 20                                                    27 
 21 In addition to make sub-devices discoverable,      28 In addition to make sub-devices discoverable, drivers can also choose to
 22 make them directly configurable by application     29 make them directly configurable by applications. When both the
 23 sub-device driver and the V4L2 device driver s     30 sub-device driver and the V4L2 device driver support this, sub-devices
 24 will feature a character device node on which      31 will feature a character device node on which ioctls can be called to
 25                                                    32 
 26 -  query, read and write sub-devices controls      33 -  query, read and write sub-devices controls
 27                                                    34 
 28 -  subscribe and unsubscribe to events and ret     35 -  subscribe and unsubscribe to events and retrieve them
 29                                                    36 
 30 -  negotiate image formats on individual pads      37 -  negotiate image formats on individual pads
 31                                                    38 
 32 -  inspect and modify internal data routing be << 
 33                                                << 
 34 Sub-device character device nodes, conventiona     39 Sub-device character device nodes, conventionally named
 35 ``/dev/v4l-subdev*``, use major number 81.         40 ``/dev/v4l-subdev*``, use major number 81.
 36                                                    41 
 37 Drivers may opt to limit the sub-device charac     42 Drivers may opt to limit the sub-device character devices to only expose
 38 operations that do not modify the device state     43 operations that do not modify the device state. In such a case the sub-devices
 39 are referred to as ``read-only`` in the rest o     44 are referred to as ``read-only`` in the rest of this documentation, and the
 40 related restrictions are documented in individ     45 related restrictions are documented in individual ioctls.
 41                                                    46 
 42                                                    47 
 43 Controls                                           48 Controls
 44 ========                                           49 ========
 45                                                    50 
 46 Most V4L2 controls are implemented by sub-devi     51 Most V4L2 controls are implemented by sub-device hardware. Drivers
 47 usually merge all controls and expose them thr     52 usually merge all controls and expose them through video device nodes.
 48 Applications can control all sub-devices throu     53 Applications can control all sub-devices through a single interface.
 49                                                    54 
 50 Complex devices sometimes implement the same c     55 Complex devices sometimes implement the same control in different pieces
 51 of hardware. This situation is common in embed     56 of hardware. This situation is common in embedded platforms, where both
 52 sensors and image processing hardware implemen     57 sensors and image processing hardware implement identical functions,
 53 such as contrast adjustment, white balance or      58 such as contrast adjustment, white balance or faulty pixels correction.
 54 As the V4L2 controls API doesn't support sever     59 As the V4L2 controls API doesn't support several identical controls in a
 55 single device, all but one of the identical co     60 single device, all but one of the identical controls are hidden.
 56                                                    61 
 57 Applications can access those hidden controls      62 Applications can access those hidden controls through the sub-device
 58 node with the V4L2 control API described in :r     63 node with the V4L2 control API described in :ref:`control`. The ioctls
 59 behave identically as when issued on V4L2 devi     64 behave identically as when issued on V4L2 device nodes, with the
 60 exception that they deal only with controls im     65 exception that they deal only with controls implemented in the
 61 sub-device.                                        66 sub-device.
 62                                                    67 
 63 Depending on the driver, those controls might      68 Depending on the driver, those controls might also be exposed through
 64 one (or several) V4L2 device nodes.                69 one (or several) V4L2 device nodes.
 65                                                    70 
 66                                                    71 
 67 Events                                             72 Events
 68 ======                                             73 ======
 69                                                    74 
 70 V4L2 sub-devices can notify applications of ev     75 V4L2 sub-devices can notify applications of events as described in
 71 :ref:`event`. The API behaves identically as w     76 :ref:`event`. The API behaves identically as when used on V4L2 device
 72 nodes, with the exception that it only deals w     77 nodes, with the exception that it only deals with events generated by
 73 the sub-device. Depending on the driver, those     78 the sub-device. Depending on the driver, those events might also be
 74 reported on one (or several) V4L2 device nodes     79 reported on one (or several) V4L2 device nodes.
 75                                                    80 
 76                                                    81 
 77 .. _pad-level-formats:                             82 .. _pad-level-formats:
 78                                                    83 
 79 Pad-level Formats                                  84 Pad-level Formats
 80 =================                                  85 =================
 81                                                    86 
 82 .. warning::                                       87 .. warning::
 83                                                    88 
 84     Pad-level formats are only applicable to v     89     Pad-level formats are only applicable to very complex devices that
 85     need to expose low-level format configurat     90     need to expose low-level format configuration to user space. Generic
 86     V4L2 applications do *not* need to use the     91     V4L2 applications do *not* need to use the API described in this
 87     section.                                       92     section.
 88                                                    93 
 89 .. note::                                          94 .. note::
 90                                                    95 
 91     For the purpose of this section, the term      96     For the purpose of this section, the term *format* means the
 92     combination of media bus data format, fram     97     combination of media bus data format, frame width and frame height.
 93                                                    98 
 94 Image formats are typically negotiated on vide     99 Image formats are typically negotiated on video capture and output
 95 devices using the format and                      100 devices using the format and
 96 :ref:`selection <VIDIOC_SUBDEV_G_SELECTION>` i    101 :ref:`selection <VIDIOC_SUBDEV_G_SELECTION>` ioctls. The driver is
 97 responsible for configuring every block in the    102 responsible for configuring every block in the video pipeline according
 98 to the requested format at the pipeline input     103 to the requested format at the pipeline input and/or output.
 99                                                   104 
100 For complex devices, such as often found in em    105 For complex devices, such as often found in embedded systems, identical
101 image sizes at the output of a pipeline can be    106 image sizes at the output of a pipeline can be achieved using different
102 hardware configurations. One such example is s    107 hardware configurations. One such example is shown on
103 :ref:`pipeline-scaling`, where image scaling c    108 :ref:`pipeline-scaling`, where image scaling can be performed on both
104 the video sensor and the host image processing    109 the video sensor and the host image processing hardware.
105                                                   110 
106                                                   111 
107 .. _pipeline-scaling:                             112 .. _pipeline-scaling:
108                                                   113 
109 .. kernel-figure:: pipeline.dot                   114 .. kernel-figure:: pipeline.dot
110     :alt:   pipeline.dot                          115     :alt:   pipeline.dot
111     :align: center                                116     :align: center
112                                                   117 
113     Image Format Negotiation on Pipelines         118     Image Format Negotiation on Pipelines
114                                                   119 
115     High quality and high speed pipeline confi    120     High quality and high speed pipeline configuration
116                                                   121 
117                                                   122 
118                                                   123 
119 The sensor scaler is usually of less quality t    124 The sensor scaler is usually of less quality than the host scaler, but
120 scaling on the sensor is required to achieve h    125 scaling on the sensor is required to achieve higher frame rates.
121 Depending on the use case (quality vs. speed),    126 Depending on the use case (quality vs. speed), the pipeline must be
122 configured differently. Applications need to c    127 configured differently. Applications need to configure the formats at
123 every point in the pipeline explicitly.           128 every point in the pipeline explicitly.
124                                                   129 
125 Drivers that implement the :ref:`media API <me    130 Drivers that implement the :ref:`media API <media-controller-intro>`
126 can expose pad-level image format configuratio    131 can expose pad-level image format configuration to applications. When
127 they do, applications can use the                 132 they do, applications can use the
128 :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT    133 :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT>` and
129 :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT    134 :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls. to
130 negotiate formats on a per-pad basis.             135 negotiate formats on a per-pad basis.
131                                                   136 
132 Applications are responsible for configuring c    137 Applications are responsible for configuring coherent parameters on the
133 whole pipeline and making sure that connected     138 whole pipeline and making sure that connected pads have compatible
134 formats. The pipeline is checked for formats m    139 formats. The pipeline is checked for formats mismatch at
135 :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` time,    140 :ref:`VIDIOC_STREAMON <VIDIOC_STREAMON>` time, and an ``EPIPE`` error
136 code is then returned if the configuration is     141 code is then returned if the configuration is invalid.
137                                                   142 
138 Pad-level image format configuration support c    143 Pad-level image format configuration support can be tested by calling
139 the :ref:`VIDIOC_SUBDEV_G_FMT` ioctl on pad       144 the :ref:`VIDIOC_SUBDEV_G_FMT` ioctl on pad
140 0. If the driver returns an ``EINVAL`` error c    145 0. If the driver returns an ``EINVAL`` error code pad-level format
141 configuration is not supported by the sub-devi    146 configuration is not supported by the sub-device.
142                                                   147 
143                                                   148 
144 Format Negotiation                                149 Format Negotiation
145 ------------------                                150 ------------------
146                                                   151 
147 Acceptable formats on pads can (and usually do    152 Acceptable formats on pads can (and usually do) depend on a number of
148 external parameters, such as formats on other     153 external parameters, such as formats on other pads, active links, or
149 even controls. Finding a combination of format    154 even controls. Finding a combination of formats on all pads in a video
150 pipeline, acceptable to both application and d    155 pipeline, acceptable to both application and driver, can't rely on
151 formats enumeration only. A format negotiation    156 formats enumeration only. A format negotiation mechanism is required.
152                                                   157 
153 Central to the format negotiation mechanism ar    158 Central to the format negotiation mechanism are the get/set format
154 operations. When called with the ``which`` arg    159 operations. When called with the ``which`` argument set to
155 :ref:`V4L2_SUBDEV_FORMAT_TRY <VIDIOC_SUBDEV_G_    160 :ref:`V4L2_SUBDEV_FORMAT_TRY <VIDIOC_SUBDEV_G_FMT>`, the
156 :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT    161 :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT>` and
157 :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT    162 :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctls operate on
158 a set of formats parameters that are not conne    163 a set of formats parameters that are not connected to the hardware
159 configuration. Modifying those 'try' formats l    164 configuration. Modifying those 'try' formats leaves the device state
160 untouched (this applies to both the software s    165 untouched (this applies to both the software state stored in the driver
161 and the hardware state stored in the device it    166 and the hardware state stored in the device itself).
162                                                   167 
163 While not kept as part of the device state, tr    168 While not kept as part of the device state, try formats are stored in
164 the sub-device file handles. A                    169 the sub-device file handles. A
165 :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT    170 :ref:`VIDIOC_SUBDEV_G_FMT <VIDIOC_SUBDEV_G_FMT>` call will return
166 the last try format set *on the same sub-devic    171 the last try format set *on the same sub-device file handle*. Several
167 applications querying the same sub-device at t    172 applications querying the same sub-device at the same time will thus not
168 interact with each other.                         173 interact with each other.
169                                                   174 
170 To find out whether a particular format is sup    175 To find out whether a particular format is supported by the device,
171 applications use the                              176 applications use the
172 :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT    177 :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` ioctl. Drivers
173 verify and, if needed, change the requested ``    178 verify and, if needed, change the requested ``format`` based on device
174 requirements and return the possibly modified     179 requirements and return the possibly modified value. Applications can
175 then choose to try a different format or accep    180 then choose to try a different format or accept the returned value and
176 continue.                                         181 continue.
177                                                   182 
178 Formats returned by the driver during a negoti    183 Formats returned by the driver during a negotiation iteration are
179 guaranteed to be supported by the device. In p    184 guaranteed to be supported by the device. In particular, drivers
180 guarantee that a returned format will not be f    185 guarantee that a returned format will not be further changed if passed
181 to an :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV    186 to an :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` call as-is
182 (as long as external parameters, such as forma    187 (as long as external parameters, such as formats on other pads or links'
183 configuration are not changed).                   188 configuration are not changed).
184                                                   189 
185 Drivers automatically propagate formats inside    190 Drivers automatically propagate formats inside sub-devices. When a try
186 or active format is set on a pad, correspondin    191 or active format is set on a pad, corresponding formats on other pads of
187 the same sub-device can be modified by the dri    192 the same sub-device can be modified by the driver. Drivers are free to
188 modify formats as required by the device. Howe    193 modify formats as required by the device. However, they should comply
189 with the following rules when possible:           194 with the following rules when possible:
190                                                   195 
191 -  Formats should be propagated from sink pads    196 -  Formats should be propagated from sink pads to source pads. Modifying
192    a format on a source pad should not modify     197    a format on a source pad should not modify the format on any sink
193    pad.                                           198    pad.
194                                                   199 
195 -  Sub-devices that scale frames using variabl    200 -  Sub-devices that scale frames using variable scaling factors should
196    reset the scale factors to default values w    201    reset the scale factors to default values when sink pads formats are
197    modified. If the 1:1 scaling ratio is suppo    202    modified. If the 1:1 scaling ratio is supported, this means that
198    source pads formats should be reset to the     203    source pads formats should be reset to the sink pads formats.
199                                                   204 
200 Formats are not propagated across links, as th    205 Formats are not propagated across links, as that would involve
201 propagating them from one sub-device file hand    206 propagating them from one sub-device file handle to another.
202 Applications must then take care to configure     207 Applications must then take care to configure both ends of every link
203 explicitly with compatible formats. Identical     208 explicitly with compatible formats. Identical formats on the two ends of
204 a link are guaranteed to be compatible. Driver    209 a link are guaranteed to be compatible. Drivers are free to accept
205 different formats matching device requirements    210 different formats matching device requirements as being compatible.
206                                                   211 
207 :ref:`sample-pipeline-config` shows a sample c    212 :ref:`sample-pipeline-config` shows a sample configuration sequence
208 for the pipeline described in :ref:`pipeline-s    213 for the pipeline described in :ref:`pipeline-scaling` (table columns
209 list entity names and pad numbers).               214 list entity names and pad numbers).
210                                                   215 
211                                                   216 
212 .. raw:: latex                                    217 .. raw:: latex
213                                                   218 
214     \begingroup                                << 
215     \scriptsize                                   219     \scriptsize
216     \setlength{\tabcolsep}{2pt}                << 
217                                                   220 
218 .. tabularcolumns:: |p{2.0cm}|p{2.1cm}|p{2.1cm !! 221 .. tabularcolumns:: |p{2.0cm}|p{2.3cm}|p{2.3cm}|p{2.3cm}|p{2.3cm}|p{2.3cm}|p{2.3cm}|
219                                                   222 
220 .. _sample-pipeline-config:                       223 .. _sample-pipeline-config:
221                                                   224 
222 .. flat-table:: Sample Pipeline Configuration     225 .. flat-table:: Sample Pipeline Configuration
223     :header-rows:  1                              226     :header-rows:  1
224     :stub-columns: 0                              227     :stub-columns: 0
225     :widths: 5 5 5 5 5 5 5                        228     :widths: 5 5 5 5 5 5 5
226                                                   229 
227     * -                                           230     * -
228       - Sensor/0                                  231       - Sensor/0
229                                                   232 
230         format                                    233         format
231       - Frontend/0                                234       - Frontend/0
232                                                   235 
233         format                                    236         format
234       - Frontend/1                                237       - Frontend/1
235                                                   238 
236         format                                    239         format
237       - Scaler/0                                  240       - Scaler/0
238                                                   241 
239         format                                    242         format
240       - Scaler/0                                  243       - Scaler/0
241                                                   244 
242         compose selection rectangle               245         compose selection rectangle
243       - Scaler/1                                  246       - Scaler/1
244                                                   247 
245         format                                    248         format
246     * - Initial state                             249     * - Initial state
247       - 2048x1536                                 250       - 2048x1536
248                                                   251 
249         SGRBG8_1X8                                252         SGRBG8_1X8
250       - (default)                                 253       - (default)
251       - (default)                                 254       - (default)
252       - (default)                                 255       - (default)
253       - (default)                                 256       - (default)
254       - (default)                                 257       - (default)
255     * - Configure frontend sink format            258     * - Configure frontend sink format
256       - 2048x1536                                 259       - 2048x1536
257                                                   260 
258         SGRBG8_1X8                                261         SGRBG8_1X8
259       - *2048x1536*                               262       - *2048x1536*
260                                                   263 
261         *SGRBG8_1X8*                              264         *SGRBG8_1X8*
262       - *2046x1534*                               265       - *2046x1534*
263                                                   266 
264         *SGRBG8_1X8*                              267         *SGRBG8_1X8*
265       - (default)                                 268       - (default)
266       - (default)                                 269       - (default)
267       - (default)                                 270       - (default)
268     * - Configure scaler sink format              271     * - Configure scaler sink format
269       - 2048x1536                                 272       - 2048x1536
270                                                   273 
271         SGRBG8_1X8                                274         SGRBG8_1X8
272       - 2048x1536                                 275       - 2048x1536
273                                                   276 
274         SGRBG8_1X8                                277         SGRBG8_1X8
275       - 2046x1534                                 278       - 2046x1534
276                                                   279 
277         SGRBG8_1X8                                280         SGRBG8_1X8
278       - *2046x1534*                               281       - *2046x1534*
279                                                   282 
280         *SGRBG8_1X8*                              283         *SGRBG8_1X8*
281       - *0,0/2046x1534*                           284       - *0,0/2046x1534*
282       - *2046x1534*                               285       - *2046x1534*
283                                                   286 
284         *SGRBG8_1X8*                              287         *SGRBG8_1X8*
285     * - Configure scaler sink compose selectio    288     * - Configure scaler sink compose selection
286       - 2048x1536                                 289       - 2048x1536
287                                                   290 
288         SGRBG8_1X8                                291         SGRBG8_1X8
289       - 2048x1536                                 292       - 2048x1536
290                                                   293 
291         SGRBG8_1X8                                294         SGRBG8_1X8
292       - 2046x1534                                 295       - 2046x1534
293                                                   296 
294         SGRBG8_1X8                                297         SGRBG8_1X8
295       - 2046x1534                                 298       - 2046x1534
296                                                   299 
297         SGRBG8_1X8                                300         SGRBG8_1X8
298       - *0,0/1280x960*                            301       - *0,0/1280x960*
299       - *1280x960*                                302       - *1280x960*
300                                                   303 
301         *SGRBG8_1X8*                              304         *SGRBG8_1X8*
302                                                   305 
303 .. raw:: latex                                    306 .. raw:: latex
304                                                   307 
305     \endgroup                                  !! 308     \normalsize
306                                                   309 
307 1. Initial state. The sensor source pad format    310 1. Initial state. The sensor source pad format is set to its native 3MP
308    size and V4L2_MBUS_FMT_SGRBG8_1X8 media bus    311    size and V4L2_MBUS_FMT_SGRBG8_1X8 media bus code. Formats on the
309    host frontend and scaler sink and source pa    312    host frontend and scaler sink and source pads have the default
310    values, as well as the compose rectangle on    313    values, as well as the compose rectangle on the scaler's sink pad.
311                                                   314 
312 2. The application configures the frontend sin    315 2. The application configures the frontend sink pad format's size to
313    2048x1536 and its media bus code to V4L2_MB    316    2048x1536 and its media bus code to V4L2_MBUS_FMT_SGRBG_1X8. The
314    driver propagates the format to the fronten    317    driver propagates the format to the frontend source pad.
315                                                   318 
316 3. The application configures the scaler sink     319 3. The application configures the scaler sink pad format's size to
317    2046x1534 and the media bus code to V4L2_MB    320    2046x1534 and the media bus code to V4L2_MBUS_FMT_SGRBG_1X8 to
318    match the frontend source size and media bu    321    match the frontend source size and media bus code. The media bus code
319    on the sink pad is set to V4L2_MBUS_FMT_SGR    322    on the sink pad is set to V4L2_MBUS_FMT_SGRBG_1X8. The driver
320    propagates the size to the compose selectio    323    propagates the size to the compose selection rectangle on the
321    scaler's sink pad, and the format to the sc    324    scaler's sink pad, and the format to the scaler source pad.
322                                                   325 
323 4. The application configures the size of the     326 4. The application configures the size of the compose selection
324    rectangle of the scaler's sink pad 1280x960    327    rectangle of the scaler's sink pad 1280x960. The driver propagates
325    the size to the scaler's source pad format.    328    the size to the scaler's source pad format.
326                                                   329 
327 When satisfied with the try results, applicati    330 When satisfied with the try results, applications can set the active
328 formats by setting the ``which`` argument to      331 formats by setting the ``which`` argument to
329 ``V4L2_SUBDEV_FORMAT_ACTIVE``. Active formats     332 ``V4L2_SUBDEV_FORMAT_ACTIVE``. Active formats are changed exactly as try
330 formats by drivers. To avoid modifying the har    333 formats by drivers. To avoid modifying the hardware state during format
331 negotiation, applications should negotiate try    334 negotiation, applications should negotiate try formats first and then
332 modify the active settings using the try forma    335 modify the active settings using the try formats returned during the
333 last negotiation iteration. This guarantees th    336 last negotiation iteration. This guarantees that the active format will
334 be applied as-is by the driver without being m    337 be applied as-is by the driver without being modified.
335                                                   338 
336                                                   339 
337 .. _v4l2-subdev-selections:                       340 .. _v4l2-subdev-selections:
338                                                   341 
339 Selections: cropping, scaling and composition     342 Selections: cropping, scaling and composition
340 ---------------------------------------------     343 ---------------------------------------------
341                                                   344 
342 Many sub-devices support cropping frames on th    345 Many sub-devices support cropping frames on their input or output pads
343 (or possible even on both). Cropping is used t    346 (or possible even on both). Cropping is used to select the area of
344 interest in an image, typically on an image se    347 interest in an image, typically on an image sensor or a video decoder.
345 It can also be used as part of digital zoom im    348 It can also be used as part of digital zoom implementations to select
346 the area of the image that will be scaled up.     349 the area of the image that will be scaled up.
347                                                   350 
348 Crop settings are defined by a crop rectangle     351 Crop settings are defined by a crop rectangle and represented in a
349 struct :c:type:`v4l2_rect` by the coordinates     352 struct :c:type:`v4l2_rect` by the coordinates of the top
350 left corner and the rectangle size. Both the c    353 left corner and the rectangle size. Both the coordinates and sizes are
351 expressed in pixels.                              354 expressed in pixels.
352                                                   355 
353 As for pad formats, drivers store try and acti    356 As for pad formats, drivers store try and active rectangles for the
354 selection targets :ref:`v4l2-selections-common    357 selection targets :ref:`v4l2-selections-common`.
355                                                   358 
356 On sink pads, cropping is applied relative to     359 On sink pads, cropping is applied relative to the current pad format.
357 The pad format represents the image size as re    360 The pad format represents the image size as received by the sub-device
358 from the previous block in the pipeline, and t    361 from the previous block in the pipeline, and the crop rectangle
359 represents the sub-image that will be transmit    362 represents the sub-image that will be transmitted further inside the
360 sub-device for processing.                        363 sub-device for processing.
361                                                   364 
362 The scaling operation changes the size of the     365 The scaling operation changes the size of the image by scaling it to new
363 dimensions. The scaling ratio isn't specified     366 dimensions. The scaling ratio isn't specified explicitly, but is implied
364 from the original and scaled image sizes. Both    367 from the original and scaled image sizes. Both sizes are represented by
365 struct :c:type:`v4l2_rect`.                       368 struct :c:type:`v4l2_rect`.
366                                                   369 
367 Scaling support is optional. When supported by    370 Scaling support is optional. When supported by a subdev, the crop
368 rectangle on the subdev's sink pad is scaled t    371 rectangle on the subdev's sink pad is scaled to the size configured
369 using the                                         372 using the
370 :ref:`VIDIOC_SUBDEV_S_SELECTION <VIDIOC_SUBDEV    373 :ref:`VIDIOC_SUBDEV_S_SELECTION <VIDIOC_SUBDEV_G_SELECTION>` IOCTL
371 using ``V4L2_SEL_TGT_COMPOSE`` selection targe    374 using ``V4L2_SEL_TGT_COMPOSE`` selection target on the same pad. If the
372 subdev supports scaling but not composing, the    375 subdev supports scaling but not composing, the top and left values are
373 not used and must always be set to zero.          376 not used and must always be set to zero.
374                                                   377 
375 On source pads, cropping is similar to sink pa    378 On source pads, cropping is similar to sink pads, with the exception
376 that the source size from which the cropping i    379 that the source size from which the cropping is performed, is the
377 COMPOSE rectangle on the sink pad. In both sin    380 COMPOSE rectangle on the sink pad. In both sink and source pads, the
378 crop rectangle must be entirely contained insi    381 crop rectangle must be entirely contained inside the source image size
379 for the crop operation.                           382 for the crop operation.
380                                                   383 
381 The drivers should always use the closest poss    384 The drivers should always use the closest possible rectangle the user
382 requests on all selection targets, unless spec    385 requests on all selection targets, unless specifically told otherwise.
383 ``V4L2_SEL_FLAG_GE`` and ``V4L2_SEL_FLAG_LE``     386 ``V4L2_SEL_FLAG_GE`` and ``V4L2_SEL_FLAG_LE`` flags may be used to round
384 the image size either up or down. :ref:`v4l2-s    387 the image size either up or down. :ref:`v4l2-selection-flags`
385                                                   388 
386                                                   389 
387 Types of selection targets                        390 Types of selection targets
388 --------------------------                        391 --------------------------
389                                                   392 
390                                                   393 
391 Actual targets                                    394 Actual targets
392 ^^^^^^^^^^^^^^                                    395 ^^^^^^^^^^^^^^
393                                                   396 
394 Actual targets (without a postfix) reflect the    397 Actual targets (without a postfix) reflect the actual hardware
395 configuration at any point of time. There is a    398 configuration at any point of time. There is a BOUNDS target
396 corresponding to every actual target.             399 corresponding to every actual target.
397                                                   400 
398                                                   401 
399 BOUNDS targets                                    402 BOUNDS targets
400 ^^^^^^^^^^^^^^                                    403 ^^^^^^^^^^^^^^
401                                                   404 
402 BOUNDS targets is the smallest rectangle that     405 BOUNDS targets is the smallest rectangle that contains all valid actual
403 rectangles. It may not be possible to set the     406 rectangles. It may not be possible to set the actual rectangle as large
404 as the BOUNDS rectangle, however. This may be     407 as the BOUNDS rectangle, however. This may be because e.g. a sensor's
405 pixel array is not rectangular but cross-shape    408 pixel array is not rectangular but cross-shaped or round. The maximum
406 size may also be smaller than the BOUNDS recta    409 size may also be smaller than the BOUNDS rectangle.
407                                                   410 
408                                                   411 
409 .. _format-propagation:                        << 
410                                                << 
411 Order of configuration and format propagation     412 Order of configuration and format propagation
412 ---------------------------------------------     413 ---------------------------------------------
413                                                   414 
414 Inside subdevs, the order of image processing     415 Inside subdevs, the order of image processing steps will always be from
415 the sink pad towards the source pad. This is a    416 the sink pad towards the source pad. This is also reflected in the order
416 in which the configuration must be performed b    417 in which the configuration must be performed by the user: the changes
417 made will be propagated to any subsequent stag    418 made will be propagated to any subsequent stages. If this behaviour is
418 not desired, the user must set ``V4L2_SEL_FLAG    419 not desired, the user must set ``V4L2_SEL_FLAG_KEEP_CONFIG`` flag. This
419 flag causes no propagation of the changes are     420 flag causes no propagation of the changes are allowed in any
420 circumstances. This may also cause the accesse    421 circumstances. This may also cause the accessed rectangle to be adjusted
421 by the driver, depending on the properties of     422 by the driver, depending on the properties of the underlying hardware.
422                                                   423 
423 The coordinates to a step always refer to the     424 The coordinates to a step always refer to the actual size of the
424 previous step. The exception to this rule is t    425 previous step. The exception to this rule is the sink compose
425 rectangle, which refers to the sink compose bo    426 rectangle, which refers to the sink compose bounds rectangle --- if it
426 is supported by the hardware.                     427 is supported by the hardware.
427                                                   428 
428 1. Sink pad format. The user configures the si    429 1. Sink pad format. The user configures the sink pad format. This format
429    defines the parameters of the image the ent    430    defines the parameters of the image the entity receives through the
430    pad for further processing.                    431    pad for further processing.
431                                                   432 
432 2. Sink pad actual crop selection. The sink pa    433 2. Sink pad actual crop selection. The sink pad crop defines the crop
433    performed to the sink pad format.              434    performed to the sink pad format.
434                                                   435 
435 3. Sink pad actual compose selection. The size    436 3. Sink pad actual compose selection. The size of the sink pad compose
436    rectangle defines the scaling ratio compare    437    rectangle defines the scaling ratio compared to the size of the sink
437    pad crop rectangle. The location of the com    438    pad crop rectangle. The location of the compose rectangle specifies
438    the location of the actual sink compose rec    439    the location of the actual sink compose rectangle in the sink compose
439    bounds rectangle.                              440    bounds rectangle.
440                                                   441 
441 4. Source pad actual crop selection. Crop on t    442 4. Source pad actual crop selection. Crop on the source pad defines crop
442    performed to the image in the sink compose     443    performed to the image in the sink compose bounds rectangle.
443                                                   444 
444 5. Source pad format. The source pad format de    445 5. Source pad format. The source pad format defines the output pixel
445    format of the subdev, as well as the other     446    format of the subdev, as well as the other parameters with the
446    exception of the image width and height. Wi    447    exception of the image width and height. Width and height are defined
447    by the size of the source pad actual crop s    448    by the size of the source pad actual crop selection.
448                                                   449 
449 Accessing any of the above rectangles not supp    450 Accessing any of the above rectangles not supported by the subdev will
450 return ``EINVAL``. Any rectangle referring to     451 return ``EINVAL``. Any rectangle referring to a previous unsupported
451 rectangle coordinates will instead refer to th    452 rectangle coordinates will instead refer to the previous supported
452 rectangle. For example, if sink crop is not su    453 rectangle. For example, if sink crop is not supported, the compose
453 selection will refer to the sink pad format di    454 selection will refer to the sink pad format dimensions instead.
454                                                   455 
455                                                   456 
456 .. _subdev-image-processing-crop:                 457 .. _subdev-image-processing-crop:
457                                                   458 
458 .. kernel-figure:: subdev-image-processing-cro    459 .. kernel-figure:: subdev-image-processing-crop.svg
459     :alt:   subdev-image-processing-crop.svg      460     :alt:   subdev-image-processing-crop.svg
460     :align: center                                461     :align: center
461                                                   462 
462     **Figure 4.5. Image processing in subdevs:    463     **Figure 4.5. Image processing in subdevs: simple crop example**
463                                                   464 
464 In the above example, the subdev supports crop    465 In the above example, the subdev supports cropping on its sink pad. To
465 configure it, the user sets the media bus form    466 configure it, the user sets the media bus format on the subdev's sink
466 pad. Now the actual crop rectangle can be set     467 pad. Now the actual crop rectangle can be set on the sink pad --- the
467 location and size of this rectangle reflect th    468 location and size of this rectangle reflect the location and size of a
468 rectangle to be cropped from the sink format.     469 rectangle to be cropped from the sink format. The size of the sink crop
469 rectangle will also be the size of the format     470 rectangle will also be the size of the format of the subdev's source
470 pad.                                              471 pad.
471                                                   472 
472                                                   473 
473 .. _subdev-image-processing-scaling-multi-sour    474 .. _subdev-image-processing-scaling-multi-source:
474                                                   475 
475 .. kernel-figure:: subdev-image-processing-sca    476 .. kernel-figure:: subdev-image-processing-scaling-multi-source.svg
476     :alt:   subdev-image-processing-scaling-mu    477     :alt:   subdev-image-processing-scaling-multi-source.svg
477     :align: center                                478     :align: center
478                                                   479 
479     **Figure 4.6. Image processing in subdevs:    480     **Figure 4.6. Image processing in subdevs: scaling with multiple sources**
480                                                   481 
481 In this example, the subdev is capable of firs    482 In this example, the subdev is capable of first cropping, then scaling
482 and finally cropping for two source pads indiv    483 and finally cropping for two source pads individually from the resulting
483 scaled image. The location of the scaled image    484 scaled image. The location of the scaled image in the cropped image is
484 ignored in sink compose target. Both of the lo    485 ignored in sink compose target. Both of the locations of the source crop
485 rectangles refer to the sink scaling rectangle    486 rectangles refer to the sink scaling rectangle, independently cropping
486 an area at location specified by the source cr    487 an area at location specified by the source crop rectangle from it.
487                                                   488 
488                                                   489 
489 .. _subdev-image-processing-full:                 490 .. _subdev-image-processing-full:
490                                                   491 
491 .. kernel-figure:: subdev-image-processing-ful    492 .. kernel-figure:: subdev-image-processing-full.svg
492     :alt:    subdev-image-processing-full.svg     493     :alt:    subdev-image-processing-full.svg
493     :align:  center                               494     :align:  center
494                                                   495 
495     **Figure 4.7. Image processing in subdevs:    496     **Figure 4.7. Image processing in subdevs: scaling and composition with multiple sinks and sources**
496                                                   497 
497 The subdev driver supports two sink pads and t    498 The subdev driver supports two sink pads and two source pads. The images
498 from both of the sink pads are individually cr    499 from both of the sink pads are individually cropped, then scaled and
499 further composed on the composition bounds rec    500 further composed on the composition bounds rectangle. From that, two
500 independent streams are cropped and sent out o    501 independent streams are cropped and sent out of the subdev from the
501 source pads.                                      502 source pads.
502                                                   503 
503                                                   504 
504 .. toctree::                                      505 .. toctree::
505     :maxdepth: 1                                  506     :maxdepth: 1
506                                                   507 
507     subdev-formats                                508     subdev-formats
508                                                << 
509 .. _subdev-routing:                            << 
510                                                << 
511 Streams, multiplexed media pads and internal r << 
512 ---------------------------------------------- << 
513                                                << 
514 Simple V4L2 sub-devices do not support multipl << 
515 and only a single stream can pass through a me << 
516 Thus each pad contains a format and selection  << 
517 single stream. A subdev can do stream processi << 
518 two or compose two streams into one, but the i << 
519 subdev are still a single stream per pad.      << 
520                                                << 
521 Some hardware, e.g. MIPI CSI-2, support multip << 
522 data streams are transmitted on the same bus,  << 
523 link connecting a transmitter source pad with  << 
524 example, a camera sensor can produce two disti << 
525 metadata stream, which are transmitted on the  << 
526 by a media link which connects the single sens << 
527 sink pad. The stream-aware receiver will de-mu << 
528 the its sink pad and allows to route them indi << 
529 pads.                                          << 
530                                                << 
531 Subdevice drivers that support multiplexed str << 
532 non-multiplexed subdev drivers. However, if th << 
533 does not support streams, then only stream 0 o << 
534 There may be additional limitations specific t << 
535                                                << 
536 Understanding streams                          << 
537 ^^^^^^^^^^^^^^^^^^^^^                          << 
538                                                << 
539 A stream is a stream of content (e.g. pixel da << 
540 the media pipeline from a source (e.g. a senso << 
541 receiver and demultiplexer in a SoC). Each med << 
542 streams from one end of the link to the other, << 
543 tables which describe how the incoming streams << 
544 source pads.                                   << 
545                                                << 
546 A stream ID is a media pad-local identifier fo << 
547 the same stream must be equal on both ends of  << 
548 a particular stream ID must exist on both side << 
549 link, but another stream ID can be used for th << 
550 of the sub-device.                             << 
551                                                << 
552 A stream at a specific point in the media pipe << 
553 sub-device and a (pad, stream) pair. For sub-d << 
554 multiplexed streams the 'stream' field is alwa << 
555                                                << 
556 Interaction between routes, streams, formats a << 
557 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ << 
558                                                << 
559 The addition of streams to the V4L2 sub-device << 
560 formats and selections from pads to (pad, stre << 
561 usual pad, also the stream ID needs to be prov << 
562 selections. The order of configuring formats a << 
563 the same as without streams (see :ref:`format- << 
564                                                << 
565 Instead of the sub-device wide merging of stre << 
566 towards all source pads, data flows for each r << 
567 other. Any number of routes from streams on si << 
568 source pads is allowed, to the extent supporte << 
569 stream on a source pad, however, only a single << 
570                                                << 
571 Any configurations of a stream within a pad, s << 
572 are independent of similar configurations on o << 
573 subject to change in the future.               << 
574                                                << 
575 Device types and routing setup                 << 
576 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                 << 
577                                                << 
578 Different kinds of sub-devices have differing  << 
579 depending on the hardware. In all cases, howev << 
580 ``V4L2_SUBDEV_STREAM_FL_ACTIVE`` flag set are  << 
581                                                << 
582 Devices generating the streams may allow enabl << 
583 routes or have a fixed routing configuration.  << 
584 declaring the routes (or declaring them withou << 
585 ``V4L2_SUBDEV_STREAM_FL_ACTIVE`` flag set) in  << 
586 disable the routes. ``VIDIOC_SUBDEV_S_ROUTING` << 
587 back to the user in the routes array, with the << 
588 flag unset.                                    << 
589                                                << 
590 Devices transporting the streams almost always << 
591 respect to routing. Typically any route betwee << 
592 pads is possible, and multiple routes (usually << 
593 be active simultaneously. For such devices, no << 
594 and user-created routes are fully replaced whe << 
595 called on the sub-device. Such newly created r << 
596 configuration for format and selection rectang << 
597                                                << 
598 Configuring streams                            << 
599 ^^^^^^^^^^^^^^^^^^^                            << 
600                                                << 
601 The configuration of the streams is done indiv << 
602 the validity of the streams between sub-device << 
603 is started.                                    << 
604                                                << 
605 There are three steps in configuring the strea << 
606                                                << 
607 1. Set up links. Connect the pads between sub- << 
608    :ref:`Media Controller API <media_controlle << 
609                                                << 
610 2. Streams. Streams are declared and their rou << 
611    routing table for the sub-device using :ref << 
612    <VIDIOC_SUBDEV_G_ROUTING>` ioctl. Note that << 
613    reset formats and selections in the sub-dev << 
614                                                << 
615 3. Configure formats and selections. Formats a << 
616    configured separately as documented for pla << 
617    :ref:`format-propagation`. The stream ID is << 
618    associated with either sink or source pads  << 
619    :ref:`VIDIOC_SUBDEV_S_ROUTING <VIDIOC_SUBDE << 
620                                                << 
621 Multiplexed streams setup example              << 
622 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^              << 
623                                                << 
624 A simple example of a multiplexed stream setup << 
625                                                << 
626 - Two identical sensors (Sensor A and Sensor B << 
627   pad (pad 0) which carries a pixel data strea << 
628                                                << 
629 - Multiplexer bridge (Bridge). The bridge has  << 
630   sensors (pads 0, 1), and one source pad (pad << 
631                                                << 
632 - Receiver in the SoC (Receiver). The receiver << 
633   connected to the bridge, and two source pads << 
634   engine. The receiver demultiplexes the incom << 
635                                                << 
636 - DMA Engines in the SoC (DMA Engine), one for << 
637   connected to a single source pad in the rece << 
638                                                << 
639 The sensors, the bridge and the receiver are m << 
640 exposed to userspace via /dev/v4l-subdevX devi << 
641 modeled as V4L2 devices, exposed to userspace  << 
642                                                << 
643 To configure this pipeline, the userspace must << 
644                                                << 
645 1. Set up media links between entities: connec << 
646    bridge to the receiver, and the receiver to << 
647    not differ from normal non-multiplexed medi << 
648                                                << 
649 2. Configure routing                           << 
650                                                << 
651 .. flat-table:: Bridge routing table           << 
652     :header-rows:  1                           << 
653                                                << 
654     * - Sink Pad/Stream                        << 
655       - Source Pad/Stream                      << 
656       - Routing Flags                          << 
657       - Comments                               << 
658     * - 0/0                                    << 
659       - 2/0                                    << 
660       - V4L2_SUBDEV_ROUTE_FL_ACTIVE            << 
661       - Pixel data stream from Sensor A        << 
662     * - 1/0                                    << 
663       - 2/1                                    << 
664       - V4L2_SUBDEV_ROUTE_FL_ACTIVE            << 
665       - Pixel data stream from Sensor B        << 
666                                                << 
667 .. flat-table:: Receiver routing table         << 
668     :header-rows:  1                           << 
669                                                << 
670     * - Sink Pad/Stream                        << 
671       - Source Pad/Stream                      << 
672       - Routing Flags                          << 
673       - Comments                               << 
674     * - 0/0                                    << 
675       - 1/0                                    << 
676       - V4L2_SUBDEV_ROUTE_FL_ACTIVE            << 
677       - Pixel data stream from Sensor A        << 
678     * - 0/1                                    << 
679       - 2/0                                    << 
680       - V4L2_SUBDEV_ROUTE_FL_ACTIVE            << 
681       - Pixel data stream from Sensor B        << 
682                                                << 
683 3. Configure formats and selections            << 
684                                                << 
685    After configuring routing, the next step is << 
686    selections for the streams. This is similar << 
687    streams, with just one exception: the ``str << 
688    to the value of the stream ID.              << 
689                                                << 
690    A common way to accomplish this is to start << 
691    the configurations along the stream towards << 
692    :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_ << 
693    stream endpoint in each sub-device.         << 
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php