[PATCH v12 08/86] media: v4l: uapi: Add a control for color pattern flipping effect

Sakari Ailus
2026-04-09T20:15:30Z

Add a bitmask control (V4L2_CID_CFA_PATTERN_FLIP) to tell whether flipping
results in a change in the sensor's Color Filter Array (CFA) pattern,
separately horizontally and vertically. The information is essential for
raw formats when using generic raw mbus codes.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
.../media/v4l/ext-ctrls-image-source.rst | 12 ++++++++++++
drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++
include/uapi/linux/v4l2-controls.h | 6 ++++++
3 files changed, 20 insertions(+)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst
index 2328ac99e97a..f3e4428c4bf1 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst
@@ -138,3 +138,15 @@ Image Source Control IDs
the top-left and bottom-right pixels, a blue filter in the top-right
pixel, and a red filter in the bottom-left pixel.
- 3
+
+``V4L2_CID_CFA_PATTERN_FLIP (bitmask)``
+ This control determines whether the horizontal or vertical flipping controls
+ (V4L2_CID_HFLIP and V4L2_CID_VFLIP) have an effect on the pixel order of the
+ output color pattern. Macros ``V4L2_CFA_PATTERN_FLIP_HORIZONTAL`` and
+ ``V4L2_CFA_PATTERN_FLIP_VERTICAL`` define bitmasks for both bits. If either
+ horizontal or vertical bit is set, the readout pattern order is that of the
+ reversed readout. ``V4L2_CFA_PATTERN_FLIP_BOTH`` for setting both
+ ``V4L2_CFA_PATTERN_FLIP_HORIZONTAL`` and ``V4L2_CFA_PATTERN_FLIP_VERTICAL``
+ is provided as well.
+
+ This is a read-only control.
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index 4fafc7a3c233..32a4b1b3fc0e 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -1158,6 +1158,7 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_TEST_PATTERN_GREENB: return "Green (Blue) Pixel Value";
case V4L2_CID_NOTIFY_GAINS: return "Notify Gains";
case V4L2_CID_CFA_PATTERN: return "Color Filter Array Pattern";
+ case V4L2_CID_CFA_PATTERN_FLIP: return "CFA Pattern Flip";

/* Image processing controls */
/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1489,6 +1490,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
*type = V4L2_CTRL_TYPE_BITMASK;
break;
case V4L2_CID_CONFIG_MODEL:
+ case V4L2_CID_CFA_PATTERN_FLIP:
*flags |= V4L2_CTRL_FLAG_READ_ONLY;
*type = V4L2_CTRL_TYPE_BITMASK;
break;
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index 78c6fc69b1c1..d5cedb28a564 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -1241,6 +1241,12 @@ enum v4l2_jpeg_chroma_subsampling {
#define V4L2_CFA_PATTERN_BGGR 2U
#define V4L2_CFA_PATTERN_GBRG 3U

+#define V4L2_CID_CFA_PATTERN_FLIP (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 11)
+#define V4L2_CFA_PATTERN_FLIP_HORIZONTAL (1U << 0)
+#define V4L2_CFA_PATTERN_FLIP_VERTICAL (1U << 1)
+#define V4L2_CFA_PATTERN_FLIP_BOTH \
+ (V4L2_CFA_PATTERN_FLIP_HORIZONTAL | V4L2_CFA_PATTERN_FLIP_VERTICAL)
+

/* Image processing controls */

--
2.47.3