Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: v4l2: extend the CSC API to subdevice.

This patch extends the CSC API in video devices to be supported
also on sub-devices. The flag V4L2_MBUS_FRAMEFMT_SET_CSC set by
the application when calling VIDIOC_SUBDEV_S_FMT ioctl.
The flags:

V4L2_SUBDEV_MBUS_CODE_CSC_COLORSPACE,
V4L2_SUBDEV_MBUS_CODE_CSC_XFER_FUNC,
V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC/V4L2_SUBDEV_MBUS_CODE_CSC_HSV_ENC
V4L2_SUBDEV_MBUS_CODE_CSC_QUANTIZATION

are set by the driver in the VIDIOC_SUBDEV_ENUM_MBUS_CODE ioctl.

New 'flags' fields were added to the structs
v4l2_subdev_mbus_code_enum, v4l2_mbus_framefmt which are borrowed
from the 'reserved' field

The patch also replaces the 'ycbcr_enc' field in
'struct v4l2_mbus_framefmt' with a union that includes 'hsv_enc'

Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Dafna Hirschfeld and committed by
Mauro Carvalho Chehab
62aacfa9 2f491463

+157 -14
+85 -10
Documentation/userspace-api/media/v4l/subdev-formats.rst
··· 34 34 :ref:`field-order` for details. 35 35 * - __u32 36 36 - ``colorspace`` 37 - - Image colorspace, from enum 38 - :c:type:`v4l2_colorspace`. See 39 - :ref:`colorspaces` for details. 37 + - Image colorspace, from enum :c:type:`v4l2_colorspace`. 38 + Must be set by the driver for subdevices. If the application sets the 39 + flag ``V4L2_MBUS_FRAMEFMT_SET_CSC`` then the application can set this 40 + field on the source pad to request a specific colorspace for the media 41 + bus data. If the driver cannot handle the requested conversion, it will 42 + return another supported colorspace. The driver indicates that colorspace 43 + conversion is supported by setting the flag 44 + V4L2_SUBDEV_MBUS_CODE_CSC_COLORSPACE in the corresponding struct 45 + :c:type:`v4l2_subdev_mbus_code_enum` during enumeration. 46 + See :ref:`v4l2-subdev-mbus-code-flags`. 47 + * - union { 48 + - (anonymous) 40 49 * - __u16 41 50 - ``ycbcr_enc`` 42 51 - Y'CbCr encoding, from enum :c:type:`v4l2_ycbcr_encoding`. 43 52 This information supplements the ``colorspace`` and must be set by 44 - the driver for capture streams and by the application for output 45 - streams, see :ref:`colorspaces`. 53 + the driver for subdevices, see :ref:`colorspaces`. If the application 54 + sets the flag ``V4L2_MBUS_FRAMEFMT_SET_CSC`` then the application can set 55 + this field on a source pad to request a specific Y'CbCr encoding 56 + for the media bus data. If the driver cannot handle the requested 57 + conversion, it will return another supported encoding. 58 + This field is ignored for HSV media bus formats. The driver indicates 59 + that ycbcr_enc conversion is supported by setting the flag 60 + V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC in the corresponding struct 61 + :c:type:`v4l2_subdev_mbus_code_enum` during enumeration. 62 + See :ref:`v4l2-subdev-mbus-code-flags`. 63 + * - __u16 64 + - ``hsv_enc`` 65 + - HSV encoding, from enum :c:type:`v4l2_hsv_encoding`. 66 + This information supplements the ``colorspace`` and must be set by 67 + the driver for subdevices, see :ref:`colorspaces`. If the application 68 + sets the flag ``V4L2_MBUS_FRAMEFMT_SET_CSC`` then the application can set 69 + this field on a source pad to request a specific HSV encoding 70 + for the media bus data. If the driver cannot handle the requested 71 + conversion, it will return another supported encoding. 72 + This field is ignored for Y'CbCr media bus formats. The driver indicates 73 + that hsv_enc conversion is supported by setting the flag 74 + V4L2_SUBDEV_MBUS_CODE_CSC_HSV_ENC in the corresponding struct 75 + :c:type:`v4l2_subdev_mbus_code_enum` during enumeration. 76 + See :ref:`v4l2-subdev-mbus-code-flags` 77 + * - } 78 + - 46 79 * - __u16 47 80 - ``quantization`` 48 81 - Quantization range, from enum :c:type:`v4l2_quantization`. 49 82 This information supplements the ``colorspace`` and must be set by 50 - the driver for capture streams and by the application for output 51 - streams, see :ref:`colorspaces`. 83 + the driver for subdevices, see :ref:`colorspaces`. If the application 84 + sets the flag ``V4L2_MBUS_FRAMEFMT_SET_CSC`` then the application can set 85 + this field on a source pad to request a specific quantization 86 + for the media bus data. If the driver cannot handle the requested 87 + conversion, it will return another supported quantization. 88 + The driver indicates that quantization conversion is supported by 89 + setting the flag V4L2_SUBDEV_MBUS_CODE_CSC_QUANTIZATION in the 90 + corresponding struct :c:type:`v4l2_subdev_mbus_code_enum` 91 + during enumeration. See :ref:`v4l2-subdev-mbus-code-flags`. 92 + 52 93 * - __u16 53 94 - ``xfer_func`` 54 95 - Transfer function, from enum :c:type:`v4l2_xfer_func`. 55 96 This information supplements the ``colorspace`` and must be set by 56 - the driver for capture streams and by the application for output 57 - streams, see :ref:`colorspaces`. 97 + the driver for subdevices, see :ref:`colorspaces`. If the application 98 + sets the flag ``V4L2_MBUS_FRAMEFMT_SET_CSC`` then the application can set 99 + this field on a source pad to request a specific transfer 100 + function for the media bus data. If the driver cannot handle the requested 101 + conversion, it will return another supported transfer function. 102 + The driver indicates that the transfer function conversion is supported by 103 + setting the flag V4L2_SUBDEV_MBUS_CODE_CSC_XFER_FUNC in the 104 + corresponding struct :c:type:`v4l2_subdev_mbus_code_enum` 105 + during enumeration. See :ref:`v4l2-subdev-mbus-code-flags`. 58 106 * - __u16 59 - - ``reserved``\ [11] 107 + - ``flags`` 108 + - flags See: :ref:v4l2-mbus-framefmt-flags 109 + * - __u16 110 + - ``reserved``\ [10] 60 111 - Reserved for future extensions. Applications and drivers must set 61 112 the array to zero. 62 113 114 + .. _v4l2-mbus-framefmt-flags: 115 + 116 + .. flat-table:: v4l2_mbus_framefmt Flags 117 + :header-rows: 0 118 + :stub-columns: 0 119 + :widths: 3 1 4 120 + 121 + * .. _`mbus-framefmt-set-csc`: 122 + 123 + - ``V4L2_MBUS_FRAMEFMT_SET_CSC`` 124 + - 0x0001 125 + - Set by the application. It is only used for source pads and is 126 + ignored for sink pads. If set, then request the subdevice to do 127 + colorspace conversion from the received colorspace to the requested 128 + colorspace values. If the colorimetry field (``colorspace``, ``xfer_func``, 129 + ``ycbcr_enc``, ``hsv_enc`` or ``quantization``) is set to ``*_DEFAULT``, 130 + then that colorimetry setting will remain unchanged from what was received. 131 + So in order to change the quantization, only the ``quantization`` field shall 132 + be set to non default value (``V4L2_QUANTIZATION_FULL_RANGE`` or 133 + ``V4L2_QUANTIZATION_LIM_RANGE``) and all other colorimetry fields shall 134 + be set to ``*_DEFAULT``. 135 + 136 + To check which conversions are supported by the hardware for the current 137 + media bus frame format, see :ref:`v4l2-subdev-mbus-code-flags`. 63 138 64 139 65 140 .. _v4l2-mbus-pixelcode:
+50 -1
Documentation/userspace-api/media/v4l/vidioc-subdev-enum-mbus-code.rst
··· 72 72 - Media bus format codes to be enumerated, from enum 73 73 :ref:`v4l2_subdev_format_whence <v4l2-subdev-format-whence>`. 74 74 * - __u32 75 - - ``reserved``\ [8] 75 + - ``flags`` 76 + - See :ref:`v4l2-subdev-mbus-code-flags` 77 + * - __u32 78 + - ``reserved``\ [7] 76 79 - Reserved for future extensions. Applications and drivers must set 77 80 the array to zero. 78 81 82 + 83 + 84 + .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{7.7cm}| 85 + 86 + .. _v4l2-subdev-mbus-code-flags: 87 + 88 + .. flat-table:: Subdev Media Bus Code Enumerate Flags 89 + :header-rows: 0 90 + :stub-columns: 0 91 + :widths: 1 1 2 92 + 93 + * - V4L2_SUBDEV_MBUS_CODE_CSC_COLORSPACE 94 + - 0x00000001 95 + - The driver allows the application to try to change the default colorspace 96 + encoding. The application can ask to configure the colorspace of the 97 + subdevice when calling the :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` 98 + ioctl with :ref:`V4L2_MBUS_FRAMEFMT_SET_CSC <mbus-framefmt-set-csc>` set. 99 + See :ref:`v4l2-mbus-format` on how to do this. 100 + * - V4L2_SUBDEV_MBUS_CODE_CSC_XFER_FUNC 101 + - 0x00000002 102 + - The driver allows the application to try to change the default transform function. 103 + The application can ask to configure the transform function of 104 + the subdevice when calling the :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` 105 + ioctl with :ref:`V4L2_MBUS_FRAMEFMT_SET_CSC <mbus-framefmt-set-csc>` set. 106 + See :ref:`v4l2-mbus-format` on how to do this. 107 + * - V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC 108 + - 0x00000004 109 + - The driver allows the application to try to change the default Y'CbCr 110 + encoding. The application can ask to configure the Y'CbCr encoding of the 111 + subdevice when calling the :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` 112 + ioctl with :ref:`V4L2_MBUS_FRAMEFMT_SET_CSC <mbus-framefmt-set-csc>` set. 113 + See :ref:`v4l2-mbus-format` on how to do this. 114 + * - V4L2_SUBDEV_MBUS_CODE_CSC_HSV_ENC 115 + - 0x00000004 116 + - The driver allows the application to try to change the default HSV 117 + encoding. The application can ask to configure the HSV encoding of the 118 + subdevice when calling the :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` 119 + ioctl with :ref:`V4L2_MBUS_FRAMEFMT_SET_CSC <mbus-framefmt-set-csc>` set. 120 + See :ref:`v4l2-mbus-format` on how to do this. 121 + * - V4L2_SUBDEV_MBUS_CODE_CSC_QUANTIZATION 122 + - 0x00000008 123 + - The driver allows the application to try to change the default 124 + quantization. The application can ask to configure the quantization of 125 + the subdevice when calling the :ref:`VIDIOC_SUBDEV_S_FMT <VIDIOC_SUBDEV_G_FMT>` 126 + ioctl with :ref:`V4L2_MBUS_FRAMEFMT_SET_CSC <mbus-framefmt-set-csc>` set. 127 + See :ref:`v4l2-mbus-format` on how to do this. 79 128 80 129 Return Value 81 130 ============
+13 -2
include/uapi/linux/v4l2-mediabus.h
··· 16 16 #include <linux/types.h> 17 17 #include <linux/videodev2.h> 18 18 19 + #define V4L2_MBUS_FRAMEFMT_SET_CSC 0x0001 20 + 19 21 /** 20 22 * struct v4l2_mbus_framefmt - frame format on the media bus 21 23 * @width: image width ··· 26 24 * @field: used interlacing type (from enum v4l2_field) 27 25 * @colorspace: colorspace of the data (from enum v4l2_colorspace) 28 26 * @ycbcr_enc: YCbCr encoding of the data (from enum v4l2_ycbcr_encoding) 27 + * @hsv_enc: HSV encoding of the data (from enum v4l2_hsv_encoding) 29 28 * @quantization: quantization of the data (from enum v4l2_quantization) 30 29 * @xfer_func: transfer function of the data (from enum v4l2_xfer_func) 30 + * @flags: flags (V4L2_MBUS_FRAMEFMT_*) 31 + * @reserved: reserved bytes that can be later used 31 32 */ 32 33 struct v4l2_mbus_framefmt { 33 34 __u32 width; ··· 38 33 __u32 code; 39 34 __u32 field; 40 35 __u32 colorspace; 41 - __u16 ycbcr_enc; 36 + union { 37 + /* enum v4l2_ycbcr_encoding */ 38 + __u16 ycbcr_enc; 39 + /* enum v4l2_hsv_encoding */ 40 + __u16 hsv_enc; 41 + }; 42 42 __u16 quantization; 43 43 __u16 xfer_func; 44 - __u16 reserved[11]; 44 + __u16 flags; 45 + __u16 reserved[10]; 45 46 }; 46 47 47 48 #ifndef __KERNEL__
+9 -1
include/uapi/linux/v4l2-subdev.h
··· 65 65 __u32 reserved[8]; 66 66 }; 67 67 68 + #define V4L2_SUBDEV_MBUS_CODE_CSC_COLORSPACE 0x00000001 69 + #define V4L2_SUBDEV_MBUS_CODE_CSC_XFER_FUNC 0x00000002 70 + #define V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC 0x00000004 71 + #define V4L2_SUBDEV_MBUS_CODE_CSC_HSV_ENC V4L2_SUBDEV_MBUS_CODE_CSC_YCBCR_ENC 72 + #define V4L2_SUBDEV_MBUS_CODE_CSC_QUANTIZATION 0x00000008 73 + 68 74 /** 69 75 * struct v4l2_subdev_mbus_code_enum - Media bus format enumeration 70 76 * @pad: pad number, as reported by the media API 71 77 * @index: format index during enumeration 72 78 * @code: format code (MEDIA_BUS_FMT_ definitions) 73 79 * @which: format type (from enum v4l2_subdev_format_whence) 80 + * @flags: flags set by the driver, (V4L2_SUBDEV_MBUS_CODE_*) 74 81 */ 75 82 struct v4l2_subdev_mbus_code_enum { 76 83 __u32 pad; 77 84 __u32 index; 78 85 __u32 code; 79 86 __u32 which; 80 - __u32 reserved[8]; 87 + __u32 flags; 88 + __u32 reserved[7]; 81 89 }; 82 90 83 91 /**