1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L 354f38fcaSMauro Carvalho Chehab 454f38fcaSMauro Carvalho Chehab.. _VIDIOC_SUBDEV_G_FMT: 554f38fcaSMauro Carvalho Chehab 654f38fcaSMauro Carvalho Chehab********************************************** 754f38fcaSMauro Carvalho Chehabioctl VIDIOC_SUBDEV_G_FMT, VIDIOC_SUBDEV_S_FMT 854f38fcaSMauro Carvalho Chehab********************************************** 954f38fcaSMauro Carvalho Chehab 1054f38fcaSMauro Carvalho ChehabName 1154f38fcaSMauro Carvalho Chehab==== 1254f38fcaSMauro Carvalho Chehab 1354f38fcaSMauro Carvalho ChehabVIDIOC_SUBDEV_G_FMT - VIDIOC_SUBDEV_S_FMT - Get or set the data format on a subdev pad 1454f38fcaSMauro Carvalho Chehab 1554f38fcaSMauro Carvalho ChehabSynopsis 1654f38fcaSMauro Carvalho Chehab======== 1754f38fcaSMauro Carvalho Chehab 18407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_SUBDEV_G_FMT 1954f38fcaSMauro Carvalho Chehab 20407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_SUBDEV_G_FMT, struct v4l2_subdev_format *argp)`` 2154f38fcaSMauro Carvalho Chehab 22407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_SUBDEV_S_FMT 23407e84cdSMauro Carvalho Chehab 24407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_SUBDEV_S_FMT, struct v4l2_subdev_format *argp)`` 2554f38fcaSMauro Carvalho Chehab 2654f38fcaSMauro Carvalho ChehabArguments 2754f38fcaSMauro Carvalho Chehab========= 2854f38fcaSMauro Carvalho Chehab 2954f38fcaSMauro Carvalho Chehab``fd`` 30407e84cdSMauro Carvalho Chehab File descriptor returned by :c:func:`open()`. 3154f38fcaSMauro Carvalho Chehab 3254f38fcaSMauro Carvalho Chehab``argp`` 3354f38fcaSMauro Carvalho Chehab Pointer to struct :c:type:`v4l2_subdev_format`. 3454f38fcaSMauro Carvalho Chehab 3554f38fcaSMauro Carvalho ChehabDescription 3654f38fcaSMauro Carvalho Chehab=========== 3754f38fcaSMauro Carvalho Chehab 3854f38fcaSMauro Carvalho ChehabThese ioctls are used to negotiate the frame format at specific subdev 3954f38fcaSMauro Carvalho Chehabpads in the image pipeline. 4054f38fcaSMauro Carvalho Chehab 4154f38fcaSMauro Carvalho ChehabTo retrieve the current format applications set the ``pad`` field of a 4254f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_subdev_format` to the desired 4354f38fcaSMauro Carvalho Chehabpad number as reported by the media API and the ``which`` field to 4454f38fcaSMauro Carvalho Chehab``V4L2_SUBDEV_FORMAT_ACTIVE``. When they call the 4554f38fcaSMauro Carvalho Chehab``VIDIOC_SUBDEV_G_FMT`` ioctl with a pointer to this structure the 4654f38fcaSMauro Carvalho Chehabdriver fills the members of the ``format`` field. 4754f38fcaSMauro Carvalho Chehab 4854f38fcaSMauro Carvalho ChehabTo change the current format applications set both the ``pad`` and 4954f38fcaSMauro Carvalho Chehab``which`` fields and all members of the ``format`` field. When they call 5054f38fcaSMauro Carvalho Chehabthe ``VIDIOC_SUBDEV_S_FMT`` ioctl with a pointer to this structure the 5154f38fcaSMauro Carvalho Chehabdriver verifies the requested format, adjusts it based on the hardware 5254f38fcaSMauro Carvalho Chehabcapabilities and configures the device. Upon return the struct 5354f38fcaSMauro Carvalho Chehab:c:type:`v4l2_subdev_format` contains the current 5454f38fcaSMauro Carvalho Chehabformat as would be returned by a ``VIDIOC_SUBDEV_G_FMT`` call. 5554f38fcaSMauro Carvalho Chehab 5654f38fcaSMauro Carvalho ChehabApplications can query the device capabilities by setting the ``which`` 5754f38fcaSMauro Carvalho Chehabto ``V4L2_SUBDEV_FORMAT_TRY``. When set, 'try' formats are not applied 5854f38fcaSMauro Carvalho Chehabto the device by the driver, but are changed exactly as active formats 5954f38fcaSMauro Carvalho Chehaband stored in the sub-device file handle. Two applications querying the 6054f38fcaSMauro Carvalho Chehabsame sub-device would thus not interact with each other. 6154f38fcaSMauro Carvalho Chehab 6254f38fcaSMauro Carvalho ChehabFor instance, to try a format at the output pad of a sub-device, 6354f38fcaSMauro Carvalho Chehabapplications would first set the try format at the sub-device input with 6454f38fcaSMauro Carvalho Chehabthe ``VIDIOC_SUBDEV_S_FMT`` ioctl. They would then either retrieve the 6554f38fcaSMauro Carvalho Chehabdefault format at the output pad with the ``VIDIOC_SUBDEV_G_FMT`` ioctl, 6654f38fcaSMauro Carvalho Chehabor set the desired output pad format with the ``VIDIOC_SUBDEV_S_FMT`` 6754f38fcaSMauro Carvalho Chehabioctl and check the returned value. 6854f38fcaSMauro Carvalho Chehab 6954f38fcaSMauro Carvalho ChehabTry formats do not depend on active formats, but can depend on the 7054f38fcaSMauro Carvalho Chehabcurrent links configuration or sub-device controls value. For instance, 7154f38fcaSMauro Carvalho Chehaba low-pass noise filter might crop pixels at the frame boundaries, 7254f38fcaSMauro Carvalho Chehabmodifying its output frame size. 7354f38fcaSMauro Carvalho Chehab 743fb0ee8bSJacopo MondiIf the subdev device node has been registered in read-only mode, calls to 753fb0ee8bSJacopo Mondi``VIDIOC_SUBDEV_S_FMT`` are only valid if the ``which`` field is set to 763fb0ee8bSJacopo Mondi``V4L2_SUBDEV_FORMAT_TRY``, otherwise an error is returned and the errno 773fb0ee8bSJacopo Mondivariable is set to ``-EPERM``. 783fb0ee8bSJacopo Mondi 7954f38fcaSMauro Carvalho ChehabDrivers must not return an error solely because the requested format 8054f38fcaSMauro Carvalho Chehabdoesn't match the device capabilities. They must instead modify the 8154f38fcaSMauro Carvalho Chehabformat to match what the hardware can provide. The modified format 8254f38fcaSMauro Carvalho Chehabshould be as close as possible to the original request. 8354f38fcaSMauro Carvalho Chehab 84fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 8554f38fcaSMauro Carvalho Chehab 8654f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_subdev_format 8754f38fcaSMauro Carvalho Chehab 8854f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_subdev_format 8954f38fcaSMauro Carvalho Chehab :header-rows: 0 9054f38fcaSMauro Carvalho Chehab :stub-columns: 0 9154f38fcaSMauro Carvalho Chehab :widths: 1 1 2 9254f38fcaSMauro Carvalho Chehab 9354f38fcaSMauro Carvalho Chehab * - __u32 9454f38fcaSMauro Carvalho Chehab - ``pad`` 9554f38fcaSMauro Carvalho Chehab - Pad number as reported by the media controller API. 9654f38fcaSMauro Carvalho Chehab * - __u32 9754f38fcaSMauro Carvalho Chehab - ``which`` 9854f38fcaSMauro Carvalho Chehab - Format to modified, from enum 9954f38fcaSMauro Carvalho Chehab :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`. 10054f38fcaSMauro Carvalho Chehab * - struct :c:type:`v4l2_mbus_framefmt` 10154f38fcaSMauro Carvalho Chehab - ``format`` 10254f38fcaSMauro Carvalho Chehab - Definition of an image format, see :c:type:`v4l2_mbus_framefmt` for 10354f38fcaSMauro Carvalho Chehab details. 10454f38fcaSMauro Carvalho Chehab * - __u32 105*2f91e10eSTomi Valkeinen - ``stream`` 106*2f91e10eSTomi Valkeinen - Stream identifier. 107*2f91e10eSTomi Valkeinen * - __u32 108*2f91e10eSTomi Valkeinen - ``reserved``\ [7] 10954f38fcaSMauro Carvalho Chehab - Reserved for future extensions. Applications and drivers must set 11054f38fcaSMauro Carvalho Chehab the array to zero. 11154f38fcaSMauro Carvalho Chehab 11254f38fcaSMauro Carvalho Chehab 113fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}| 11454f38fcaSMauro Carvalho Chehab 11554f38fcaSMauro Carvalho Chehab.. _v4l2-subdev-format-whence: 11654f38fcaSMauro Carvalho Chehab 11754f38fcaSMauro Carvalho Chehab.. flat-table:: enum v4l2_subdev_format_whence 11854f38fcaSMauro Carvalho Chehab :header-rows: 0 11954f38fcaSMauro Carvalho Chehab :stub-columns: 0 12054f38fcaSMauro Carvalho Chehab :widths: 3 1 4 12154f38fcaSMauro Carvalho Chehab 12254f38fcaSMauro Carvalho Chehab * - V4L2_SUBDEV_FORMAT_TRY 12354f38fcaSMauro Carvalho Chehab - 0 12454f38fcaSMauro Carvalho Chehab - Try formats, used for querying device capabilities. 12554f38fcaSMauro Carvalho Chehab * - V4L2_SUBDEV_FORMAT_ACTIVE 12654f38fcaSMauro Carvalho Chehab - 1 12754f38fcaSMauro Carvalho Chehab - Active formats, applied to the hardware. 12854f38fcaSMauro Carvalho Chehab 12954f38fcaSMauro Carvalho ChehabReturn Value 13054f38fcaSMauro Carvalho Chehab============ 13154f38fcaSMauro Carvalho Chehab 13254f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set 13354f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the 13454f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter. 13554f38fcaSMauro Carvalho Chehab 13654f38fcaSMauro Carvalho ChehabEBUSY 13754f38fcaSMauro Carvalho Chehab The format can't be changed because the pad is currently busy. This 13854f38fcaSMauro Carvalho Chehab can be caused, for instance, by an active video stream on the pad. 13954f38fcaSMauro Carvalho Chehab The ioctl must not be retried without performing another action to 14054f38fcaSMauro Carvalho Chehab fix the problem first. Only returned by ``VIDIOC_SUBDEV_S_FMT`` 14154f38fcaSMauro Carvalho Chehab 14254f38fcaSMauro Carvalho ChehabEINVAL 14354f38fcaSMauro Carvalho Chehab The struct :c:type:`v4l2_subdev_format` 14454f38fcaSMauro Carvalho Chehab ``pad`` references a non-existing pad, or the ``which`` field 14554f38fcaSMauro Carvalho Chehab references a non-existing format. 14654f38fcaSMauro Carvalho Chehab 1473fb0ee8bSJacopo MondiEPERM 1483fb0ee8bSJacopo Mondi The ``VIDIOC_SUBDEV_S_FMT`` ioctl has been called on a read-only subdevice 1493fb0ee8bSJacopo Mondi and the ``which`` field is set to ``V4L2_SUBDEV_FORMAT_ACTIVE``. 15054f38fcaSMauro Carvalho Chehab 15154f38fcaSMauro Carvalho Chehab============ 15254f38fcaSMauro Carvalho Chehab 15354f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set 15454f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the 15554f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter. 156