[PATCH v12 41/86] media: uapi: Add generic CSI-2 raw pixelformats for 16, 20, 24 and 28 bpp

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

Add generic raw pixelformats for bit depths 16, 20, 24 and 28. These
formats are CSI-2 packed, apart from the 16-bit and 24-bit formats.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
.../media/v4l/pixfmt-raw-generic.rst | 212 +++++++++++++++++-
drivers/media/v4l2-core/v4l2-ioctl.c | 4 +
include/uapi/linux/videodev2.h | 4 +
3 files changed, 217 insertions(+), 3 deletions(-)

diff --git a/Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst b/Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst
index 708aa17b80b0..1992a797ce50 100644
--- a/Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst
+++ b/Documentation/userspace-api/media/v4l/pixfmt-raw-generic.rst
@@ -1,8 +1,8 @@
.. SPDX-License-Identifier: GPL-2.0 OR GFDL-1.1-no-invariants-or-later

-************************************************************************************************************************************
-V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE')
-************************************************************************************************************************************
+**********************************************************************************************************************************************************************************************************************************************************************
+V4L2_PIX_FMT_RAW_8 ('RAW8'), V4L2_PIX_FMT_RAW_CSI2_10 ('RACA'), V4L2_PIX_FMT_RAW_CSI2_12 ('RACC'), V4L2_PIX_FMT_RAW_CSI2_14 ('RACE'), V4L2_PIX_FMT_RAW_16 ('RAWG'), V4L2_PIX_FMT_RAW_CSI2_20 ('RACK'), V4L2_PIX_FMT_RAW_24 ('RAWO'), V4L2_PIX_FMT_RAW_CSI2_28 ('RACS')
+**********************************************************************************************************************************************************************************************************************************************************************

Generic line-based raw image data formats
@@ -175,3 +175,209 @@ Each cell is one byte. "P" denotes a pixel.
P\ :sub:`11 bits 5--2` (bits 3--0)
- P\ :sub:`31 bits 5--0` (bits 7--2),
P\ :sub:`21 bits 5--4` (bits 1--0)
+
+.. _v4l2-pix-fmt-raw-16:
+
+V4L2_PIX_FMT_RAW_16
+-------------------
+
+V4L2_PIX_FMT_RAW_16 contains 16-bit image data, with each two consecutive
+bytes forming a pixel value. This format is typically used by CSI-2 receivers
+with a source that transmits MEDIA_BUS_FMT_RAW_16 and the CSI-2 receiver writes
+the received data to memory as-is.
+
+The packing of the data follows the MIPI CSI-2 specification.
+
+**Byte Order Of V4L2_PIX_FMT_RAW_16.**
+Each cell is one byte. "P" denotes a pixel.
+
+.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|
+
+.. flat-table:: Sample 4x2 Image Frame
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 12 8 8 8 8 8 8 8 8
+
+ * - start + 0:
+ - P\ :sub:`00 bits 15--8`
+ - P\ :sub:`00 bits 7--0`
+ - P\ :sub:`10 bits 15--8`
+ - P\ :sub:`10 bits 7--0`
+ - P\ :sub:`20 bits 15--8`
+ - P\ :sub:`20 bits 7--0`
+ - P\ :sub:`30 bits 15--8`
+ - P\ :sub:`30 bits 7--0`
+ * - start + 8:
+ - P\ :sub:`01 bits 15--8`
+ - P\ :sub:`01 bits 7--0`
+ - P\ :sub:`11 bits 15--8`
+ - P\ :sub:`11 bits 7--0`
+ - P\ :sub:`21 bits 15--8`
+ - P\ :sub:`21 bits 7--0`
+ - P\ :sub:`31 bits 15--8`
+ - P\ :sub:`31 bits 7--0`
+
+.. _v4l2-pix-fmt-raw-csi2-20:
+
+V4L2_PIX_FMT_RAW_CSI2_20
+------------------------
+
+V4L2_PIX_FMT_RAW_CSI2_20 contains 20-bit packed image data, with four bytes
+containing the top 8 bits of two pixels followed by lowest 4 bits of the pixels
+packed into one byte. This format is typically used by CSI-2 receivers with a
+source that transmits MEDIA_BUS_FMT_RAW_20 and the CSI-2 receiver writes the
+received data to memory as-is.
+
+The packing of the data follows the MIPI CSI-2 specification.
+
+**Byte Order Of V4L2_PIX_FMT_RAW_CSI2_20.**
+Each cell is one byte. "P" denotes a pixel.
+
+.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{2cm}
+
+.. flat-table:: Sample 4x2 Image Frame
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 12 8 8 8 8 8 8 8 8 8 8
+
+ * - start + 0:
+ - P\ :sub:`00 bits 19--12`
+ - P\ :sub:`00 bits 11--4`
+ - P\ :sub:`10 bits 19--12`
+ - P\ :sub:`10 bits 11--4`
+ - P\ :sub:`10 bits 3--0` (bits 7--4),
+ P\ :sub:`00 bits 3--0` (bits 3--0)
+ - P\ :sub:`20 bits 19--12`
+ - P\ :sub:`20 bits 11--4`
+ - P\ :sub:`30 bits 19--12`
+ - P\ :sub:`30 bits 11--4`
+ - P\ :sub:`30 bits 3--0` (bits 7--4),
+ P\ :sub:`20 bits 3--0` (bits 3--0)
+ * - start + 10:
+ - P\ :sub:`01 bits 19--12`
+ - P\ :sub:`01 bits 11--4`
+ - P\ :sub:`11 bits 19--12`
+ - P\ :sub:`11 bits 11--4`
+ - P\ :sub:`11 bits 3--0` (bits 7--4),
+ P\ :sub:`01 bits 3--0` (bits 3--0)
+ - P\ :sub:`21 bits 19--12`
+ - P\ :sub:`21 bits 11--4`
+ - P\ :sub:`31 bits 19--12`
+ - P\ :sub:`31 bits 11--4`
+ - P\ :sub:`31 bits 3--0` (bits 7--4),
+ P\ :sub:`21 bits 3--0` (bits 3--0)
+
+.. _v4l2-pix-fmt-raw-24:
+
+V4L2_PIX_FMT_RAW_24
+-------------------
+
+V4L2_PIX_FMT_RAW_24 contains 24-bit packed image data, with each three bytes
+containing the value of one pixel. This format is typically used by CSI-2
+receivers with a source that transmits MEDIA_BUS_FMT_RAW_24 and the CSI-2
+receiver writes the received data to memory as-is.
+
+The packing of the data follows the MIPI CSI-2 specification.
+
+**Byte Order Of V4L2_PIX_FMT_RAW_24.**
+Each cell is one byte. "P" denotes a pixel.
+
+.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}|p{1.2cm}|p{.8cm}|p{.8cm}|
+
+.. flat-table:: Sample 4x2 Image Frame
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 12 8 8 8 8 8 8 8 8 8 8 8 8
+
+ * - start + 0:
+ - P\ :sub:`00 bits 23--16`
+ - P\ :sub:`00 bits 15--8`
+ - P\ :sub:`00 bits 7--0`
+ - P\ :sub:`10 bits 23--16`
+ - P\ :sub:`10 bits 15--8`
+ - P\ :sub:`10 bits 7--0`
+ - P\ :sub:`20 bits 23--16`
+ - P\ :sub:`20 bits 15--8`
+ - P\ :sub:`20 bits 7--0`
+ - P\ :sub:`30 bits 23--16`
+ - P\ :sub:`30 bits 15--8`
+ - P\ :sub:`30 bits 7--0`
+ * - start + 12:
+ - P\ :sub:`01 bits 23--16`
+ - P\ :sub:`01 bits 15--8`
+ - P\ :sub:`01 bits 7--0`
+ - P\ :sub:`11 bits 23--16`
+ - P\ :sub:`11 bits 15--8`
+ - P\ :sub:`11 bits 7--0`
+ - P\ :sub:`21 bits 23--16`
+ - P\ :sub:`21 bits 15--8`
+ - P\ :sub:`21 bits 7--0`
+ - P\ :sub:`31 bits 23--16`
+ - P\ :sub:`31 bits 15--8`
+ - P\ :sub:`31 bits 7--0`
+
+.. _v4l2-pix-fmt-raw-csi2-28:
+
+V4L2_PIX_FMT_RAW_CSI2_28
+------------------------
+
+V4L2_PIX_FMT_RAW_CSI2_28 contains 28-bit packed image data, with four bytes
+containing the top 8 bits of two pixels followed by lowest 4 bits of the pixels
+packed into one byte. This format is typically used by CSI-2 receivers with a
+source that transmits MEDIA_BUS_FMT_RAW_28 and the CSI-2 receiver writes the
+received data to memory as-is.
+
+The packing of the data follows the MIPI CSI-2 specification.
+
+**Byte Order Of V4L2_PIX_FMT_RAW_CSI2_28.**
+Each cell is one byte. "P" denotes a pixel.
+
+.. tabularcolumns:: |p{2.4cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}|p{1.2cm}
+
+.. flat-table:: Sample 4x2 Image Frame
+ :header-rows: 0
+ :stub-columns: 0
+ :widths: 12 8 8 8 8 8 8 8 8 8 8 8 8 8 8
+
+ * - start + 0:
+ - P\ :sub:`00 bits 27--20`
+ - P\ :sub:`00 bits 13--6`
+ - P\ :sub:`10 bits 27--20`
+ - P\ :sub:`10 bits 13--6`
+ - P\ :sub:`00 bits 19--14` (bits 7--2),
+ P\ :sub:`00 bits 1--0` (bits 1--0)
+ - P\ :sub:`00 bits 5--2` (bits 7--4),
+ P\ :sub:`10 bits 17--14` (bits 3--0)
+ - P\ :sub:`10 bits 19--18` (bits 7--6),
+ P\ :sub:`10 bits 5--0` (bits 5--0)
+ - P\ :sub:`20 bits 27--20`
+ - P\ :sub:`20 bits 13--6`
+ - P\ :sub:`30 bits 27--20`
+ - P\ :sub:`30 bits 13--6`
+ - P\ :sub:`20 bits 19--14` (bits 7--2),
+ P\ :sub:`20 bits 1--0` (bits 1--0)
+ - P\ :sub:`20 bits 5--2` (bits 7--4),
+ P\ :sub:`30 bits 17--14` (bits 3--0)
+ - P\ :sub:`30 bits 19--18` (bits 7--6),
+ P\ :sub:`30 bits 5--0` (bits 5--0)
+ * - start + 14:
+ - P\ :sub:`01 bits 27--20`
+ - P\ :sub:`01 bits 13--6`
+ - P\ :sub:`11 bits 27--20`
+ - P\ :sub:`11 bits 13--6`
+ - P\ :sub:`01 bits 19--14` (bits 7--2),
+ P\ :sub:`01 bits 1--0` (bits 1--0)
+ - P\ :sub:`01 bits 5--2` (bits 7--4),
+ P\ :sub:`11 bits 17--14` (bits 3--0)
+ - P\ :sub:`11 bits 19--18` (bits 7--6),
+ P\ :sub:`11 bits 5--0` (bits 5--0)
+ - P\ :sub:`21 bits 27--20`
+ - P\ :sub:`21 bits 13--6`
+ - P\ :sub:`31 bits 27--20`
+ - P\ :sub:`31 bits 13--6`
+ - P\ :sub:`21 bits 19--14` (bits 7--2),
+ P\ :sub:`21 bits 1--0` (bits 1--0)
+ - P\ :sub:`21 bits 5--2` (bits 7--4),
+ P\ :sub:`31 bits 17--14` (bits 3--0)
+ - P\ :sub:`31 bits 19--18` (bits 7--6),
+ P\ :sub:`31 bits 5--0` (bits 5--0)
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 8e99cdefead3..9e2d18fe1056 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1438,6 +1438,10 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
case V4L2_PIX_FMT_RAW_CSI2_10: descr = "10-bit Raw, CSI-2 Packed"; break;
case V4L2_PIX_FMT_RAW_CSI2_12: descr = "12-bit Raw, CSI-2 Packed"; break;
case V4L2_PIX_FMT_RAW_CSI2_14: descr = "14-bit Raw, CSI-2 Packed"; break;
+ case V4L2_PIX_FMT_RAW_16: descr = "16-bit Raw"; break;
+ case V4L2_PIX_FMT_RAW_CSI2_20: descr = "20-bit Raw, CSI-2 Packed"; break;
+ case V4L2_PIX_FMT_RAW_24: descr = "24-bit Raw"; break;
+ case V4L2_PIX_FMT_RAW_CSI2_28: descr = "28-bit Raw, CSI-2 Packed"; break;
case V4L2_PIX_FMT_RAW_CRU20: descr = "14-bit Raw CRU Packed"; break;
case V4L2_PIX_FMT_SN9C20X_I420: descr = "GSPCA SN9C20X I420"; break;
case V4L2_PIX_FMT_SPCA501: descr = "GSPCA SPCA501"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index 3ba872deeeb9..db172ecb131b 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -750,6 +750,10 @@ struct v4l2_pix_format {
#define V4L2_PIX_FMT_RAW_CSI2_10 v4l2_fourcc('R', 'A', 'C', 'A')
#define V4L2_PIX_FMT_RAW_CSI2_12 v4l2_fourcc('R', 'A', 'C', 'C')
#define V4L2_PIX_FMT_RAW_CSI2_14 v4l2_fourcc('R', 'A', 'C', 'E')
+#define V4L2_PIX_FMT_RAW_16 v4l2_fourcc('R', 'A', 'W', 'G')
+#define V4L2_PIX_FMT_RAW_CSI2_20 v4l2_fourcc('R', 'A', 'C', 'K')
+#define V4L2_PIX_FMT_RAW_24 v4l2_fourcc('R', 'A', 'W', 'O')
+#define V4L2_PIX_FMT_RAW_CSI2_28 v4l2_fourcc('R', 'A', 'C', 'S')

/* HSV formats */
#define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3')
--
2.47.3