All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Extend RAW format support for rzg2l-cru driver
@ 2024-12-02 14:58 Daniel Scally
  2024-12-02 14:58 ` [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats Daniel Scally
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Daniel Scally @ 2024-12-02 14:58 UTC (permalink / raw)
  To: linux-media
  Cc: hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott,
	Daniel Scally

Hi All

This series adds new pixel formats representing the 64-bit packed format that's
used by the Camera Receiver Unit in RZ/G2L and V2H SoCs. Support for capturing
those formats is then added to the rzg2l-cru driver itself.

The series is based on top of the v2 of Prabhakar's recent set titled
"media: platform: rzg2l-cru: CSI-2 and CRU enhancements"

Thanks
Dan

v2: https://lore.kernel.org/all/20241112124614.646281-1-dan.scally@ideasonboard.com/T/
v1: https://lore.kernel.org/all/20240927232729.GR12322@pendragon.ideasonboard.com/T/

Daniel Scally (5):
  media: v4l2: Add Renesas Camera Receiver Unit pixel formats
  media: platform: rzg2l-cru: Use v4l2_get_link_freq()
  media: platform: rzg2l-cru: Use v4l2_fill_pixfmt()
  media: rzg2l-cru: Support multiple mbus codes per pixel format
  media: platform: rzg2l-cru: Add support for RAW10/12/14 data

 .../userspace-api/media/v4l/pixfmt-bayer.rst  |   1 +
 .../media/v4l/pixfmt-rawnn-cru.rst            | 144 ++++++++++++++++++
 .../platform/renesas/rzg2l-cru/rzg2l-cru.h    |  10 +-
 .../platform/renesas/rzg2l-cru/rzg2l-csi2.c   |  39 +++--
 .../platform/renesas/rzg2l-cru/rzg2l-ip.c     | 108 ++++++++++---
 .../platform/renesas/rzg2l-cru/rzg2l-video.c  |   5 +-
 drivers/media/v4l2-core/v4l2-common.c         |   4 +
 drivers/media/v4l2-core/v4l2-ioctl.c          |   4 +
 include/uapi/linux/videodev2.h                |   6 +
 9 files changed, 280 insertions(+), 41 deletions(-)
 create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst

-- 
2.34.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats
  2024-12-02 14:58 [PATCH v3 0/5] Extend RAW format support for rzg2l-cru driver Daniel Scally
@ 2024-12-02 14:58 ` Daniel Scally
  2024-12-02 17:41   ` Laurent Pinchart
  2024-12-16 13:17   ` Lad, Prabhakar
  2024-12-02 14:58 ` [PATCH v3 2/5] media: platform: rzg2l-cru: Use v4l2_get_link_freq() Daniel Scally
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 11+ messages in thread
From: Daniel Scally @ 2024-12-02 14:58 UTC (permalink / raw)
  To: linux-media
  Cc: hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott,
	Daniel Scally

The Renesas Camera Receiver Unit in the RZ/V2H SoC can output RAW
data captured from an image sensor without conversion to an RGB/YUV
format. In that case the data are packed into 64-bit blocks, with a
variable amount of padding in the most significant bits depending on
the bitdepth of the data. Add new V4L2 pixel format codes for the new
formats, along with documentation to describe them.

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Changes in v3:

	- Switched from bayer-order specific formats to generic RAWnn

Changes in v2:

	- Added labels to the new formats in the documentation file
	- Added 20-bit formats

 .../userspace-api/media/v4l/pixfmt-bayer.rst  |   1 +
 .../media/v4l/pixfmt-rawnn-cru.rst            | 144 ++++++++++++++++++
 drivers/media/v4l2-core/v4l2-common.c         |   4 +
 drivers/media/v4l2-core/v4l2-ioctl.c          |   4 +
 include/uapi/linux/videodev2.h                |   6 +
 5 files changed, 159 insertions(+)
 create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst

diff --git a/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst b/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
index ed3eb432967d9..20a8aa0433047 100644
--- a/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
+++ b/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
@@ -31,3 +31,4 @@ orders. See also `the Wikipedia article on Bayer filter
     pixfmt-srggb14
     pixfmt-srggb14p
     pixfmt-srggb16
+    pixfmt-rawnn-cru
diff --git a/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst b/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
new file mode 100644
index 0000000000000..959ecc33654a1
--- /dev/null
+++ b/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
@@ -0,0 +1,144 @@
+.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
+
+.. _v4l2-pix-fmt-cru-raw10:
+.. _v4l2-pix-fmt-cru-raw12:
+.. _v4l2-pix-fmt-cru-raw14:
+.. _v4l2-pix-fmt-cru-raw20:
+
+**********************************************************************************************************************************
+V4L2_PIX_FMT_CRU_RAW10 ('CR10'), V4L2_PIX_FMT_CRU_RAW12 ('CR12'), V4L2_PIX_FMT_CRU_RAW14 ('CR14'), V4L2_PIX_FMT_CRU_RAW20 ('CR20')
+**********************************************************************************************************************************
+
+===============================================================
+Renesas RZ/V2H Camera Receiver Unit 64-bit packed pixel formats
+===============================================================
+
+| V4L2_PIX_FMT_CRU_RAW10 (CR10)
+| V4L2_PIX_FMT_CRU_RAW12 (CR12)
+| V4L2_PIX_FMT_CRU_RAW14 (CR14)
+| V4L2_PIX_FMT_CRU_RAW20 (CR20)
+
+Description
+===========
+
+These pixel formats are some of the Bayer RAW outputs for the Camera Receiver
+Unit in the Renesas RZ/V2H SoC. They are raw sRGB / Bayer formats which pack
+pixels contiguously into 64-bit units, with the 4 or 8 most significant
+bits padded.
+
+**Byte Order**
+
+.. flat-table:: RGB formats
+    :header-rows:  2
+    :stub-columns: 0
+    :widths: 36 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
+    :fill-cells:
+
+    * - :rspan:`1` Pixel Format Code
+      - :cspan:`63` Data organization
+    * - 63
+      - 62
+      - 61
+      - 60
+      - 59
+      - 58
+      - 57
+      - 56
+      - 55
+      - 54
+      - 53
+      - 52
+      - 51
+      - 50
+      - 49
+      - 48
+      - 47
+      - 46
+      - 45
+      - 44
+      - 43
+      - 42
+      - 41
+      - 40
+      - 39
+      - 38
+      - 37
+      - 36
+      - 35
+      - 34
+      - 33
+      - 32
+      - 31
+      - 30
+      - 29
+      - 28
+      - 27
+      - 26
+      - 25
+      - 24
+      - 23
+      - 22
+      - 21
+      - 20
+      - 19
+      - 18
+      - 17
+      - 16
+      - 15
+      - 14
+      - 13
+      - 12
+      - 11
+      - 10
+      - 9
+      - 8
+      - 7
+      - 6
+      - 5
+      - 4
+      - 3
+      - 2
+      - 1
+      - 0
+    * - V4L2_PIX_FMT_CRU_RAW10
+      - 0
+      - 0
+      - 0
+      - 0
+      - :cspan:`9` P5
+      - :cspan:`9` P4
+      - :cspan:`9` P3
+      - :cspan:`9` P2
+      - :cspan:`9` P1
+      - :cspan:`9` P0
+    * - V4L2_PIX_FMT_CRU_RAW12
+      - 0
+      - 0
+      - 0
+      - 0
+      - :cspan:`11` P4
+      - :cspan:`11` P3
+      - :cspan:`11` P2
+      - :cspan:`11` P1
+      - :cspan:`11` P0
+    * - V4L2_PIX_FMT_CRU_RAW14
+      - 0
+      - 0
+      - 0
+      - 0
+      - 0
+      - 0
+      - 0
+      - 0
+      - :cspan:`13` P3
+      - :cspan:`13` P2
+      - :cspan:`13` P1
+      - :cspan:`13` P0
+    * - V4L2_PIX_FMT_CRU_RAW20
+      - 0
+      - 0
+      - 0
+      - 0
+      - :cspan:`19` P2
+      - :cspan:`19` P1
+      - :cspan:`19` P0
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
index 0a2f4f0d0a073..696b33add65b8 100644
--- a/drivers/media/v4l2-core/v4l2-common.c
+++ b/drivers/media/v4l2-core/v4l2-common.c
@@ -329,10 +329,14 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
 		{ .format = V4L2_PIX_FMT_SGBRG10DPCM8,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_SGRBG10DPCM8,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_SRGGB10DPCM8,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
+		{ .format = V4L2_PIX_FMT_CRU_RAW10,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 6, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_SBGGR12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_SGBRG12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_SGRBG12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 		{ .format = V4L2_PIX_FMT_SRGGB12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
+		{ .format = V4L2_PIX_FMT_CRU_RAW12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 5, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
+		{ .format = V4L2_PIX_FMT_CRU_RAW14,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 4, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
+		{ .format = V4L2_PIX_FMT_CRU_RAW20,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 3, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
 	};
 	unsigned int i;
 
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index 0304daa8471d1..85bd068b14275 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -1409,6 +1409,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 	case V4L2_PIX_FMT_SGBRG10DPCM8:	descr = "8-bit Bayer GBGB/RGRG (DPCM)"; break;
 	case V4L2_PIX_FMT_SGRBG10DPCM8:	descr = "8-bit Bayer GRGR/BGBG (DPCM)"; break;
 	case V4L2_PIX_FMT_SRGGB10DPCM8:	descr = "8-bit Bayer RGRG/GBGB (DPCM)"; break;
+	case V4L2_PIX_FMT_CRU_RAW10:	descr = "10-bit Bayer CRU Packed"; break;
 	case V4L2_PIX_FMT_SBGGR12:	descr = "12-bit Bayer BGBG/GRGR"; break;
 	case V4L2_PIX_FMT_SGBRG12:	descr = "12-bit Bayer GBGB/RGRG"; break;
 	case V4L2_PIX_FMT_SGRBG12:	descr = "12-bit Bayer GRGR/BGBG"; break;
@@ -1417,6 +1418,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 	case V4L2_PIX_FMT_SGBRG12P:	descr = "12-bit Bayer GBGB/RGRG Packed"; break;
 	case V4L2_PIX_FMT_SGRBG12P:	descr = "12-bit Bayer GRGR/BGBG Packed"; break;
 	case V4L2_PIX_FMT_SRGGB12P:	descr = "12-bit Bayer RGRG/GBGB Packed"; break;
+	case V4L2_PIX_FMT_CRU_RAW12:	descr = "12-bit Bayer CRU Packed"; break;
 	case V4L2_PIX_FMT_SBGGR14:	descr = "14-bit Bayer BGBG/GRGR"; break;
 	case V4L2_PIX_FMT_SGBRG14:	descr = "14-bit Bayer GBGB/RGRG"; break;
 	case V4L2_PIX_FMT_SGRBG14:	descr = "14-bit Bayer GRGR/BGBG"; break;
@@ -1425,10 +1427,12 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
 	case V4L2_PIX_FMT_SGBRG14P:	descr = "14-bit Bayer GBGB/RGRG Packed"; break;
 	case V4L2_PIX_FMT_SGRBG14P:	descr = "14-bit Bayer GRGR/BGBG Packed"; break;
 	case V4L2_PIX_FMT_SRGGB14P:	descr = "14-bit Bayer RGRG/GBGB Packed"; break;
+	case V4L2_PIX_FMT_CRU_RAW14:	descr = "14-bit Bayer CRU Packed"; break;
 	case V4L2_PIX_FMT_SBGGR16:	descr = "16-bit Bayer BGBG/GRGR"; break;
 	case V4L2_PIX_FMT_SGBRG16:	descr = "16-bit Bayer GBGB/RGRG"; break;
 	case V4L2_PIX_FMT_SGRBG16:	descr = "16-bit Bayer GRGR/BGBG"; break;
 	case V4L2_PIX_FMT_SRGGB16:	descr = "16-bit Bayer RGRG/GBGB"; break;
+	case V4L2_PIX_FMT_CRU_RAW20:	descr = "14-bit Bayer CRU Packed"; break;
 	case V4L2_PIX_FMT_SN9C20X_I420:	descr = "GSPCA SN9C20X I420"; break;
 	case V4L2_PIX_FMT_SPCA501:	descr = "GSPCA SPCA501"; break;
 	case V4L2_PIX_FMT_SPCA505:	descr = "GSPCA SPCA505"; break;
diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
index e7c4dce390074..b0482b9af04f5 100644
--- a/include/uapi/linux/videodev2.h
+++ b/include/uapi/linux/videodev2.h
@@ -830,6 +830,12 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_PISP_COMP2_BGGR	v4l2_fourcc('P', 'C', '2', 'B') /* PiSP 8-bit mode 2 compressed BGGR bayer */
 #define V4L2_PIX_FMT_PISP_COMP2_MONO	v4l2_fourcc('P', 'C', '2', 'M') /* PiSP 8-bit mode 2 compressed monochrome */
 
+/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */
+#define V4L2_PIX_FMT_CRU_RAW10	v4l2_fourcc('C', 'R', '1', '0')
+#define V4L2_PIX_FMT_CRU_RAW12	v4l2_fourcc('C', 'R', '1', '2')
+#define V4L2_PIX_FMT_CRU_RAW14	v4l2_fourcc('C', 'R', '1', '4')
+#define V4L2_PIX_FMT_CRU_RAW20	v4l2_fourcc('C', 'R', '2', '0')
+
 /* SDR formats - used only for Software Defined Radio devices */
 #define V4L2_SDR_FMT_CU8          v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */
 #define V4L2_SDR_FMT_CU16LE       v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/5] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
  2024-12-02 14:58 [PATCH v3 0/5] Extend RAW format support for rzg2l-cru driver Daniel Scally
  2024-12-02 14:58 ` [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats Daniel Scally
@ 2024-12-02 14:58 ` Daniel Scally
  2024-12-03  6:26   ` kernel test robot
  2024-12-02 14:58 ` [PATCH v3 3/5] media: platform: rzg2l-cru: Use v4l2_fill_pixfmt() Daniel Scally
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Daniel Scally @ 2024-12-02 14:58 UTC (permalink / raw)
  To: linux-media
  Cc: hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott,
	Daniel Scally, Laurent Pinchart

The rzg2l_csi2_calc_mbps() function currently tries to calculate the
link frequency for a CSI2 bus using the V4L2_CID_PIXEL_RATE control
of the remote subdevice. Switch the function to v4l2_get_link_freq()
which correctly targets V4L2_CID_LINK_FREQ before falling back on
V4L2_CID_PIXEL_RATE if the former is unavailable.

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Changes in v3:

	- Fixed mbps sign

Changes in v2:

	- None

 .../platform/renesas/rzg2l-cru/rzg2l-csi2.c   | 27 ++++++++-----------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
index 881e910dce023..243a36b952cb3 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
@@ -242,28 +242,23 @@ static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)
 	const struct rzg2l_csi2_format *format;
 	const struct v4l2_mbus_framefmt *fmt;
 	struct v4l2_subdev_state *state;
-	struct v4l2_ctrl *ctrl;
-	u64 mbps;
-
-	/* Read the pixel rate control from remote. */
-	ctrl = v4l2_ctrl_find(source->ctrl_handler, V4L2_CID_PIXEL_RATE);
-	if (!ctrl) {
-		dev_err(csi2->dev, "no pixel rate control in subdev %s\n",
-			source->name);
-		return -EINVAL;
-	}
+	s64 mbps;
 
 	state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev);
 	fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK);
 	format = rzg2l_csi2_code_to_fmt(fmt->code);
 	v4l2_subdev_unlock_state(state);
 
-	/*
-	 * Calculate hsfreq in Mbps
-	 * hsfreq = (pixel_rate * bits_per_sample) / number_of_lanes
-	 */
-	mbps = v4l2_ctrl_g_ctrl_int64(ctrl) * format->bpp;
-	do_div(mbps, csi2->lanes * 1000000);
+	/* Read the link frequency from remote subdevice. */
+	mbps = v4l2_get_link_freq(source->ctrl_handler, format->bpp,
+				  csi2->lanes);
+	if (mbps < 0) {
+		dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n",
+			source->name);
+		return -EINVAL;
+	}
+
+	do_div(mbps, 1000000);
 
 	return mbps;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 3/5] media: platform: rzg2l-cru: Use v4l2_fill_pixfmt()
  2024-12-02 14:58 [PATCH v3 0/5] Extend RAW format support for rzg2l-cru driver Daniel Scally
  2024-12-02 14:58 ` [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats Daniel Scally
  2024-12-02 14:58 ` [PATCH v3 2/5] media: platform: rzg2l-cru: Use v4l2_get_link_freq() Daniel Scally
@ 2024-12-02 14:58 ` Daniel Scally
  2024-12-02 14:58 ` [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format Daniel Scally
  2024-12-02 14:58 ` [PATCH v3 5/5] media: platform: rzg2l-cru: Add support for RAW10/12/14 data Daniel Scally
  4 siblings, 0 replies; 11+ messages in thread
From: Daniel Scally @ 2024-12-02 14:58 UTC (permalink / raw)
  To: linux-media
  Cc: hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott,
	Daniel Scally, Laurent Pinchart

Rather than open-code a calculation of the format's bytesperline
and sizeimage, use the v4l2_fill_pixfmt() helper. This makes it
easier to support the CRU packed pixel formats without over
complicating the driver.

This change makes the .bpp member of struct rzg2l_cru_ip_format
superfluous - remove them.

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Tested-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Changes in v3:

	- None

Changes in v2:

	- Minor changes due to rebase

 drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h   | 2 --
 drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c    | 5 -----
 drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c | 3 +--
 3 files changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
index 8b898ce05b847..aaf85054f8842 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
@@ -68,7 +68,6 @@ struct rzg2l_cru_ip {
  * @datatype: MIPI CSI2 data type
  * @format: 4CC format identifier (V4L2_PIX_FMT_*)
  * @icndmr: ICnDMR register value
- * @bpp: bytes per pixel
  * @yuv: Flag to indicate whether the format is YUV-based.
  */
 struct rzg2l_cru_ip_format {
@@ -76,7 +75,6 @@ struct rzg2l_cru_ip_format {
 	u32 datatype;
 	u32 format;
 	u32 icndmr;
-	u8 bpp;
 	bool yuv;
 };
 
diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
index 76a2b451f1daf..399a337dbafbf 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
@@ -16,7 +16,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 		.code = MEDIA_BUS_FMT_UYVY8_1X16,
 		.datatype = MIPI_CSI2_DT_YUV422_8B,
 		.format = V4L2_PIX_FMT_UYVY,
-		.bpp = 2,
 		.icndmr = ICnDMR_YCMODE_UYVY,
 		.yuv = true,
 	},
@@ -24,7 +23,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
 		.format = V4L2_PIX_FMT_SBGGR8,
 		.datatype = MIPI_CSI2_DT_RAW8,
-		.bpp = 1,
 		.icndmr = 0,
 		.yuv = false,
 	},
@@ -32,7 +30,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 		.code = MEDIA_BUS_FMT_SGBRG8_1X8,
 		.format = V4L2_PIX_FMT_SGBRG8,
 		.datatype = MIPI_CSI2_DT_RAW8,
-		.bpp = 1,
 		.icndmr = 0,
 		.yuv = false,
 	},
@@ -40,7 +37,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 		.code = MEDIA_BUS_FMT_SGRBG8_1X8,
 		.format = V4L2_PIX_FMT_SGRBG8,
 		.datatype = MIPI_CSI2_DT_RAW8,
-		.bpp = 1,
 		.icndmr = 0,
 		.yuv = false,
 	},
@@ -48,7 +44,6 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 		.code = MEDIA_BUS_FMT_SRGGB8_1X8,
 		.format = V4L2_PIX_FMT_SRGGB8,
 		.datatype = MIPI_CSI2_DT_RAW8,
-		.bpp = 1,
 		.icndmr = 0,
 		.yuv = false,
 	},
diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
index 17a1af507a270..028b390488c84 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
@@ -711,8 +711,7 @@ static void rzg2l_cru_format_align(struct rzg2l_cru_dev *cru,
 	v4l_bound_align_image(&pix->width, 320, RZG2L_CRU_MAX_INPUT_WIDTH, 1,
 			      &pix->height, 240, RZG2L_CRU_MAX_INPUT_HEIGHT, 2, 0);
 
-	pix->bytesperline = pix->width * fmt->bpp;
-	pix->sizeimage = pix->bytesperline * pix->height;
+	v4l2_fill_pixfmt(pix, pix->pixelformat, pix->width, pix->height);
 
 	dev_dbg(cru->dev, "Format %ux%u bpl: %u size: %u\n",
 		pix->width, pix->height, pix->bytesperline, pix->sizeimage);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format
  2024-12-02 14:58 [PATCH v3 0/5] Extend RAW format support for rzg2l-cru driver Daniel Scally
                   ` (2 preceding siblings ...)
  2024-12-02 14:58 ` [PATCH v3 3/5] media: platform: rzg2l-cru: Use v4l2_fill_pixfmt() Daniel Scally
@ 2024-12-02 14:58 ` Daniel Scally
  2024-12-03 11:19   ` Laurent Pinchart
  2024-12-16 13:18   ` Lad, Prabhakar
  2024-12-02 14:58 ` [PATCH v3 5/5] media: platform: rzg2l-cru: Add support for RAW10/12/14 data Daniel Scally
  4 siblings, 2 replies; 11+ messages in thread
From: Daniel Scally @ 2024-12-02 14:58 UTC (permalink / raw)
  To: linux-media
  Cc: hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott,
	Daniel Scally

As a preliminary step for supporting the CRU pixel formats, extend
the driver such that multiple media bus codes can support each of
the output pixel formats.

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Changes in v3:

	- New patch due to changes to patch 1

 .../platform/renesas/rzg2l-cru/rzg2l-cru.h    |  8 ++-
 .../platform/renesas/rzg2l-cru/rzg2l-ip.c     | 67 +++++++++++++++----
 .../platform/renesas/rzg2l-cru/rzg2l-video.c  |  2 +-
 3 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
index aaf85054f8842..ab923bfa3becf 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
@@ -71,7 +71,11 @@ struct rzg2l_cru_ip {
  * @yuv: Flag to indicate whether the format is YUV-based.
  */
 struct rzg2l_cru_ip_format {
-	u32 code;
+	/*
+	 * RAW output formats might be produced by RAW media codes with any one
+	 * of the 4 common bayer patterns.
+	 */
+	u32 codes[4];
 	u32 datatype;
 	u32 format;
 	u32 icndmr;
@@ -169,5 +173,7 @@ struct v4l2_mbus_framefmt *rzg2l_cru_ip_get_src_fmt(struct rzg2l_cru_dev *cru);
 const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code);
 const struct rzg2l_cru_ip_format *rzg2l_cru_ip_format_to_fmt(u32 format);
 const struct rzg2l_cru_ip_format *rzg2l_cru_ip_index_to_fmt(u32 index);
+bool rzg2l_cru_ip_fmt_supports_mbus_code(const struct rzg2l_cru_ip_format *fmt,
+					 unsigned int code);
 
 #endif
diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
index 399a337dbafbf..54a79d5c13e10 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
@@ -13,35 +13,45 @@
 
 static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 	{
-		.code = MEDIA_BUS_FMT_UYVY8_1X16,
+		.codes = {
+			MEDIA_BUS_FMT_UYVY8_1X16,
+		},
 		.datatype = MIPI_CSI2_DT_YUV422_8B,
 		.format = V4L2_PIX_FMT_UYVY,
 		.icndmr = ICnDMR_YCMODE_UYVY,
 		.yuv = true,
 	},
 	{
-		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
+		.codes = {
+			MEDIA_BUS_FMT_SBGGR8_1X8,
+		},
 		.format = V4L2_PIX_FMT_SBGGR8,
 		.datatype = MIPI_CSI2_DT_RAW8,
 		.icndmr = 0,
 		.yuv = false,
 	},
 	{
-		.code = MEDIA_BUS_FMT_SGBRG8_1X8,
+		.codes = {
+			MEDIA_BUS_FMT_SGBRG8_1X8,
+		},
 		.format = V4L2_PIX_FMT_SGBRG8,
 		.datatype = MIPI_CSI2_DT_RAW8,
 		.icndmr = 0,
 		.yuv = false,
 	},
 	{
-		.code = MEDIA_BUS_FMT_SGRBG8_1X8,
+		.codes = {
+			MEDIA_BUS_FMT_SGRBG8_1X8,
+		},
 		.format = V4L2_PIX_FMT_SGRBG8,
 		.datatype = MIPI_CSI2_DT_RAW8,
 		.icndmr = 0,
 		.yuv = false,
 	},
 	{
-		.code = MEDIA_BUS_FMT_SRGGB8_1X8,
+		.codes = {
+			MEDIA_BUS_FMT_SRGGB8_1X8,
+		},
 		.format = V4L2_PIX_FMT_SRGGB8,
 		.datatype = MIPI_CSI2_DT_RAW8,
 		.icndmr = 0,
@@ -51,11 +61,14 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 
 const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code)
 {
-	unsigned int i;
+	unsigned int i, j;
 
-	for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++)
-		if (rzg2l_cru_ip_formats[i].code == code)
-			return &rzg2l_cru_ip_formats[i];
+	for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++) {
+		for (j = 0; j < ARRAY_SIZE(rzg2l_cru_ip_formats[i].codes); j++) {
+			if (rzg2l_cru_ip_formats[i].codes[j] == code)
+				return &rzg2l_cru_ip_formats[i];
+		}
+	}
 
 	return NULL;
 }
@@ -80,6 +93,17 @@ const struct rzg2l_cru_ip_format *rzg2l_cru_ip_index_to_fmt(u32 index)
 	return &rzg2l_cru_ip_formats[index];
 }
 
+bool rzg2l_cru_ip_fmt_supports_mbus_code(const struct rzg2l_cru_ip_format *fmt,
+					 unsigned int code)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_SIZE(fmt->codes); i++)
+		if (fmt->codes[i] == code)
+			return true;
+
+	return false;
+}
 struct v4l2_mbus_framefmt *rzg2l_cru_ip_get_src_fmt(struct rzg2l_cru_dev *cru)
 {
 	struct v4l2_subdev_state *state;
@@ -155,7 +179,7 @@ static int rzg2l_cru_ip_set_format(struct v4l2_subdev *sd,
 	sink_format = v4l2_subdev_state_get_format(state, fmt->pad);
 
 	if (!rzg2l_cru_ip_code_to_fmt(fmt->format.code))
-		sink_format->code = rzg2l_cru_ip_formats[0].code;
+		sink_format->code = rzg2l_cru_ip_formats[0].codes[0];
 	else
 		sink_format->code = fmt->format.code;
 
@@ -181,11 +205,26 @@ static int rzg2l_cru_ip_enum_mbus_code(struct v4l2_subdev *sd,
 				       struct v4l2_subdev_state *state,
 				       struct v4l2_subdev_mbus_code_enum *code)
 {
-	if (code->index >= ARRAY_SIZE(rzg2l_cru_ip_formats))
-		return -EINVAL;
+	unsigned int index = code->index;
+	unsigned int i, j;
 
-	code->code = rzg2l_cru_ip_formats[code->index].code;
-	return 0;
+	for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++) {
+		const struct rzg2l_cru_ip_format *fmt = &rzg2l_cru_ip_formats[i];
+
+		for (j = 0; j < ARRAY_SIZE(fmt->codes); j++) {
+			if (!fmt->codes[j])
+				continue;
+
+			if (!index) {
+				code->code = fmt->codes[j];
+				return 0;
+			}
+
+			index--;
+		}
+	}
+
+	return -EINVAL;
 }
 
 static int rzg2l_cru_ip_enum_frame_size(struct v4l2_subdev *sd,
diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
index 028b390488c84..57d1ff45ce1e9 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
@@ -891,7 +891,7 @@ static int rzg2l_cru_video_link_validate(struct media_link *link)
 	if (fmt.format.width != cru->format.width ||
 	    fmt.format.height != cru->format.height ||
 	    fmt.format.field != cru->format.field ||
-	    video_fmt->code != fmt.format.code)
+	    !rzg2l_cru_ip_fmt_supports_mbus_code(video_fmt, fmt.format.code))
 		return -EPIPE;
 
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 5/5] media: platform: rzg2l-cru: Add support for RAW10/12/14 data
  2024-12-02 14:58 [PATCH v3 0/5] Extend RAW format support for rzg2l-cru driver Daniel Scally
                   ` (3 preceding siblings ...)
  2024-12-02 14:58 ` [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format Daniel Scally
@ 2024-12-02 14:58 ` Daniel Scally
  4 siblings, 0 replies; 11+ messages in thread
From: Daniel Scally @ 2024-12-02 14:58 UTC (permalink / raw)
  To: linux-media
  Cc: hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott,
	Daniel Scally

Add support to the rzg2l-cru driver to capture 10/12/14 bit bayer
data and output it into the CRU's 64-bit packed pixel format.

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
---
Changes in v3:

	- Fewer new entries as the RAWnn pixel formats support multiple mbus
	  codes

Changes in v2:

	- Minor updates accounting for rebase

 .../platform/renesas/rzg2l-cru/rzg2l-csi2.c   | 12 +++++++
 .../platform/renesas/rzg2l-cru/rzg2l-ip.c     | 36 +++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
index 243a36b952cb3..d4b4b334d082f 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c
@@ -192,6 +192,18 @@ static const struct rzg2l_csi2_format rzg2l_csi2_formats[] = {
 	{ .code = MEDIA_BUS_FMT_SGBRG8_1X8, .bpp = 8, },
 	{ .code = MEDIA_BUS_FMT_SGRBG8_1X8, .bpp = 8, },
 	{ .code = MEDIA_BUS_FMT_SRGGB8_1X8, .bpp = 8, },
+	{ .code = MEDIA_BUS_FMT_SBGGR10_1X10, .bpp = 10, },
+	{ .code = MEDIA_BUS_FMT_SGBRG10_1X10, .bpp = 10, },
+	{ .code = MEDIA_BUS_FMT_SGRBG10_1X10, .bpp = 10, },
+	{ .code = MEDIA_BUS_FMT_SRGGB10_1X10, .bpp = 10, },
+	{ .code = MEDIA_BUS_FMT_SBGGR12_1X12, .bpp = 12, },
+	{ .code = MEDIA_BUS_FMT_SGBRG12_1X12, .bpp = 12, },
+	{ .code = MEDIA_BUS_FMT_SGRBG12_1X12, .bpp = 12, },
+	{ .code = MEDIA_BUS_FMT_SRGGB12_1X12, .bpp = 12, },
+	{ .code = MEDIA_BUS_FMT_SBGGR14_1X14, .bpp = 14, },
+	{ .code = MEDIA_BUS_FMT_SGBRG14_1X14, .bpp = 14, },
+	{ .code = MEDIA_BUS_FMT_SGRBG14_1X14, .bpp = 14, },
+	{ .code = MEDIA_BUS_FMT_SRGGB14_1X14, .bpp = 14, },
 };
 
 static inline struct rzg2l_csi2 *sd_to_csi2(struct v4l2_subdev *sd)
diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
index 54a79d5c13e10..a3432d8b54e82 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
@@ -57,6 +57,42 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
 		.icndmr = 0,
 		.yuv = false,
 	},
+	{
+		.codes = {
+			MEDIA_BUS_FMT_SBGGR10_1X10,
+			MEDIA_BUS_FMT_SGBRG10_1X10,
+			MEDIA_BUS_FMT_SGRBG10_1X10,
+			MEDIA_BUS_FMT_SRGGB10_1X10
+		},
+		.format = V4L2_PIX_FMT_CRU_RAW10,
+		.datatype = MIPI_CSI2_DT_RAW10,
+		.icndmr = 0,
+		.yuv = false,
+	},
+	{
+		.codes = {
+			MEDIA_BUS_FMT_SBGGR12_1X12,
+			MEDIA_BUS_FMT_SGBRG12_1X12,
+			MEDIA_BUS_FMT_SGRBG12_1X12,
+			MEDIA_BUS_FMT_SRGGB12_1X12
+		},
+		.format = V4L2_PIX_FMT_CRU_RAW12,
+		.datatype = MIPI_CSI2_DT_RAW12,
+		.icndmr = 0,
+		.yuv = false,
+	},
+	{
+		.codes = {
+			MEDIA_BUS_FMT_SBGGR14_1X14,
+			MEDIA_BUS_FMT_SGBRG14_1X14,
+			MEDIA_BUS_FMT_SGRBG14_1X14,
+			MEDIA_BUS_FMT_SRGGB14_1X14
+		},
+		.format = V4L2_PIX_FMT_CRU_RAW14,
+		.datatype = MIPI_CSI2_DT_RAW14,
+		.icndmr = 0,
+		.yuv = false,
+	},
 };
 
 const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats
  2024-12-02 14:58 ` [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats Daniel Scally
@ 2024-12-02 17:41   ` Laurent Pinchart
  2024-12-16 13:17   ` Lad, Prabhakar
  1 sibling, 0 replies; 11+ messages in thread
From: Laurent Pinchart @ 2024-12-02 17:41 UTC (permalink / raw)
  To: Daniel Scally
  Cc: linux-media, hverkuil-cisco, sakari.ailus,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott

Hi Dan,

Thank you for the patch.

On Mon, Dec 02, 2024 at 02:58:27PM +0000, Daniel Scally wrote:
> The Renesas Camera Receiver Unit in the RZ/V2H SoC can output RAW
> data captured from an image sensor without conversion to an RGB/YUV
> format. In that case the data are packed into 64-bit blocks, with a
> variable amount of padding in the most significant bits depending on
> the bitdepth of the data. Add new V4L2 pixel format codes for the new
> formats, along with documentation to describe them.
> 
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
> ---
> Changes in v3:
> 
> 	- Switched from bayer-order specific formats to generic RAWnn
> 
> Changes in v2:
> 
> 	- Added labels to the new formats in the documentation file
> 	- Added 20-bit formats
> 
>  .../userspace-api/media/v4l/pixfmt-bayer.rst  |   1 +
>  .../media/v4l/pixfmt-rawnn-cru.rst            | 144 ++++++++++++++++++
>  drivers/media/v4l2-core/v4l2-common.c         |   4 +
>  drivers/media/v4l2-core/v4l2-ioctl.c          |   4 +
>  include/uapi/linux/videodev2.h                |   6 +
>  5 files changed, 159 insertions(+)
>  create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
> 
> diff --git a/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst b/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
> index ed3eb432967d9..20a8aa0433047 100644
> --- a/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
> +++ b/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
> @@ -31,3 +31,4 @@ orders. See also `the Wikipedia article on Bayer filter
>      pixfmt-srggb14
>      pixfmt-srggb14p
>      pixfmt-srggb16
> +    pixfmt-rawnn-cru
> diff --git a/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst b/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
> new file mode 100644
> index 0000000000000..959ecc33654a1
> --- /dev/null
> +++ b/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
> @@ -0,0 +1,144 @@
> +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
> +
> +.. _v4l2-pix-fmt-cru-raw10:
> +.. _v4l2-pix-fmt-cru-raw12:
> +.. _v4l2-pix-fmt-cru-raw14:
> +.. _v4l2-pix-fmt-cru-raw20:
> +
> +**********************************************************************************************************************************
> +V4L2_PIX_FMT_CRU_RAW10 ('CR10'), V4L2_PIX_FMT_CRU_RAW12 ('CR12'), V4L2_PIX_FMT_CRU_RAW14 ('CR14'), V4L2_PIX_FMT_CRU_RAW20 ('CR20')
> +**********************************************************************************************************************************
> +
> +===============================================================
> +Renesas RZ/V2H Camera Receiver Unit 64-bit packed pixel formats
> +===============================================================
> +
> +| V4L2_PIX_FMT_CRU_RAW10 (CR10)
> +| V4L2_PIX_FMT_CRU_RAW12 (CR12)
> +| V4L2_PIX_FMT_CRU_RAW14 (CR14)
> +| V4L2_PIX_FMT_CRU_RAW20 (CR20)
> +
> +Description
> +===========
> +
> +These pixel formats are some of the Bayer RAW outputs for the Camera Receiver

s/Bayer // as they're "just" raw formats, not specific to the Bayer CFA
pattern.

> +Unit in the Renesas RZ/V2H SoC. They are raw sRGB / Bayer formats which pack

sRGB seems even weirder to mention here.

> +pixels contiguously into 64-bit units, with the 4 or 8 most significant
> +bits padded.
> +
> +**Byte Order**
> +
> +.. flat-table:: RGB formats

s/RGB/RAW/

> +    :header-rows:  2
> +    :stub-columns: 0
> +    :widths: 36 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
> +    :fill-cells:
> +
> +    * - :rspan:`1` Pixel Format Code
> +      - :cspan:`63` Data organization
> +    * - 63
> +      - 62
> +      - 61
> +      - 60
> +      - 59
> +      - 58
> +      - 57
> +      - 56
> +      - 55
> +      - 54
> +      - 53
> +      - 52
> +      - 51
> +      - 50
> +      - 49
> +      - 48
> +      - 47
> +      - 46
> +      - 45
> +      - 44
> +      - 43
> +      - 42
> +      - 41
> +      - 40
> +      - 39
> +      - 38
> +      - 37
> +      - 36
> +      - 35
> +      - 34
> +      - 33
> +      - 32
> +      - 31
> +      - 30
> +      - 29
> +      - 28
> +      - 27
> +      - 26
> +      - 25
> +      - 24
> +      - 23
> +      - 22
> +      - 21
> +      - 20
> +      - 19
> +      - 18
> +      - 17
> +      - 16
> +      - 15
> +      - 14
> +      - 13
> +      - 12
> +      - 11
> +      - 10
> +      - 9
> +      - 8
> +      - 7
> +      - 6
> +      - 5
> +      - 4
> +      - 3
> +      - 2
> +      - 1
> +      - 0
> +    * - V4L2_PIX_FMT_CRU_RAW10
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`9` P5
> +      - :cspan:`9` P4
> +      - :cspan:`9` P3
> +      - :cspan:`9` P2
> +      - :cspan:`9` P1
> +      - :cspan:`9` P0
> +    * - V4L2_PIX_FMT_CRU_RAW12
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`11` P4
> +      - :cspan:`11` P3
> +      - :cspan:`11` P2
> +      - :cspan:`11` P1
> +      - :cspan:`11` P0
> +    * - V4L2_PIX_FMT_CRU_RAW14
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`13` P3
> +      - :cspan:`13` P2
> +      - :cspan:`13` P1
> +      - :cspan:`13` P0
> +    * - V4L2_PIX_FMT_CRU_RAW20
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`19` P2
> +      - :cspan:`19` P1
> +      - :cspan:`19` P0
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index 0a2f4f0d0a073..696b33add65b8 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -329,10 +329,14 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
>  		{ .format = V4L2_PIX_FMT_SGBRG10DPCM8,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_SGRBG10DPCM8,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_SRGGB10DPCM8,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +		{ .format = V4L2_PIX_FMT_CRU_RAW10,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 6, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_SBGGR12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_SGBRG12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_SGRBG12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>  		{ .format = V4L2_PIX_FMT_SRGGB12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +		{ .format = V4L2_PIX_FMT_CRU_RAW12,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 5, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +		{ .format = V4L2_PIX_FMT_CRU_RAW14,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 4, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +		{ .format = V4L2_PIX_FMT_CRU_RAW20,	.pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 3, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>  	};
>  	unsigned int i;
>  
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 0304daa8471d1..85bd068b14275 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1409,6 +1409,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>  	case V4L2_PIX_FMT_SGBRG10DPCM8:	descr = "8-bit Bayer GBGB/RGRG (DPCM)"; break;
>  	case V4L2_PIX_FMT_SGRBG10DPCM8:	descr = "8-bit Bayer GRGR/BGBG (DPCM)"; break;
>  	case V4L2_PIX_FMT_SRGGB10DPCM8:	descr = "8-bit Bayer RGRG/GBGB (DPCM)"; break;
> +	case V4L2_PIX_FMT_CRU_RAW10:	descr = "10-bit Bayer CRU Packed"; break;

s/Bayer/RAW/ (or Raw)

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

>  	case V4L2_PIX_FMT_SBGGR12:	descr = "12-bit Bayer BGBG/GRGR"; break;
>  	case V4L2_PIX_FMT_SGBRG12:	descr = "12-bit Bayer GBGB/RGRG"; break;
>  	case V4L2_PIX_FMT_SGRBG12:	descr = "12-bit Bayer GRGR/BGBG"; break;
> @@ -1417,6 +1418,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>  	case V4L2_PIX_FMT_SGBRG12P:	descr = "12-bit Bayer GBGB/RGRG Packed"; break;
>  	case V4L2_PIX_FMT_SGRBG12P:	descr = "12-bit Bayer GRGR/BGBG Packed"; break;
>  	case V4L2_PIX_FMT_SRGGB12P:	descr = "12-bit Bayer RGRG/GBGB Packed"; break;
> +	case V4L2_PIX_FMT_CRU_RAW12:	descr = "12-bit Bayer CRU Packed"; break;
>  	case V4L2_PIX_FMT_SBGGR14:	descr = "14-bit Bayer BGBG/GRGR"; break;
>  	case V4L2_PIX_FMT_SGBRG14:	descr = "14-bit Bayer GBGB/RGRG"; break;
>  	case V4L2_PIX_FMT_SGRBG14:	descr = "14-bit Bayer GRGR/BGBG"; break;
> @@ -1425,10 +1427,12 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>  	case V4L2_PIX_FMT_SGBRG14P:	descr = "14-bit Bayer GBGB/RGRG Packed"; break;
>  	case V4L2_PIX_FMT_SGRBG14P:	descr = "14-bit Bayer GRGR/BGBG Packed"; break;
>  	case V4L2_PIX_FMT_SRGGB14P:	descr = "14-bit Bayer RGRG/GBGB Packed"; break;
> +	case V4L2_PIX_FMT_CRU_RAW14:	descr = "14-bit Bayer CRU Packed"; break;
>  	case V4L2_PIX_FMT_SBGGR16:	descr = "16-bit Bayer BGBG/GRGR"; break;
>  	case V4L2_PIX_FMT_SGBRG16:	descr = "16-bit Bayer GBGB/RGRG"; break;
>  	case V4L2_PIX_FMT_SGRBG16:	descr = "16-bit Bayer GRGR/BGBG"; break;
>  	case V4L2_PIX_FMT_SRGGB16:	descr = "16-bit Bayer RGRG/GBGB"; break;
> +	case V4L2_PIX_FMT_CRU_RAW20:	descr = "14-bit Bayer CRU Packed"; break;
>  	case V4L2_PIX_FMT_SN9C20X_I420:	descr = "GSPCA SN9C20X I420"; break;
>  	case V4L2_PIX_FMT_SPCA501:	descr = "GSPCA SPCA501"; break;
>  	case V4L2_PIX_FMT_SPCA505:	descr = "GSPCA SPCA505"; break;
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index e7c4dce390074..b0482b9af04f5 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -830,6 +830,12 @@ struct v4l2_pix_format {
>  #define V4L2_PIX_FMT_PISP_COMP2_BGGR	v4l2_fourcc('P', 'C', '2', 'B') /* PiSP 8-bit mode 2 compressed BGGR bayer */
>  #define V4L2_PIX_FMT_PISP_COMP2_MONO	v4l2_fourcc('P', 'C', '2', 'M') /* PiSP 8-bit mode 2 compressed monochrome */
>  
> +/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */
> +#define V4L2_PIX_FMT_CRU_RAW10	v4l2_fourcc('C', 'R', '1', '0')
> +#define V4L2_PIX_FMT_CRU_RAW12	v4l2_fourcc('C', 'R', '1', '2')
> +#define V4L2_PIX_FMT_CRU_RAW14	v4l2_fourcc('C', 'R', '1', '4')
> +#define V4L2_PIX_FMT_CRU_RAW20	v4l2_fourcc('C', 'R', '2', '0')
> +
>  /* SDR formats - used only for Software Defined Radio devices */
>  #define V4L2_SDR_FMT_CU8          v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */
>  #define V4L2_SDR_FMT_CU16LE       v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 2/5] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
  2024-12-02 14:58 ` [PATCH v3 2/5] media: platform: rzg2l-cru: Use v4l2_get_link_freq() Daniel Scally
@ 2024-12-03  6:26   ` kernel test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2024-12-03  6:26 UTC (permalink / raw)
  To: Daniel Scally, linux-media
  Cc: llvm, oe-kbuild-all, hverkuil-cisco, sakari.ailus,
	laurent.pinchart, prabhakar.mahadev-lad.rj, jacopo.mondi,
	isaac.scott, Daniel Scally, Laurent Pinchart

Hi Daniel,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linuxtv-media-pending/master]
[also build test WARNING on linus/master media-tree/master v6.13-rc1 next-20241128]
[cannot apply to sailus-media-tree/streams sailus-media-tree/master]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Daniel-Scally/media-v4l2-Add-Renesas-Camera-Receiver-Unit-pixel-formats/20241203-014151
base:   https://git.linuxtv.org/media-ci/media-pending.git master
patch link:    https://lore.kernel.org/r/20241202145831.127297-3-dan.scally%40ideasonboard.com
patch subject: [PATCH v3 2/5] media: platform: rzg2l-cru: Use v4l2_get_link_freq()
config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20241203/202412031405.75enPqVg-lkp@intel.com/config)
compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project 592c0fe55f6d9a811028b5f3507be91458ab2713)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241203/202412031405.75enPqVg-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412031405.75enPqVg-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c:10:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     548 |         val = __raw_readb(PCI_IOBASE + addr);
         |                           ~~~~~~~~~~ ^
   include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     561 |         val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
      37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
         |                                                   ^
   In file included from drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c:10:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     574 |         val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
         |                                                         ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
      35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
         |                                                   ^
   In file included from drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c:10:
   In file included from include/linux/interrupt.h:11:
   In file included from include/linux/hardirq.h:11:
   In file included from ./arch/hexagon/include/generated/asm/hardirq.h:1:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:14:
   In file included from arch/hexagon/include/asm/io.h:328:
   include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     585 |         __raw_writeb(value, PCI_IOBASE + addr);
         |                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     595 |         __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
     605 |         __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
         |                                                       ~~~~~~~~~~ ^
   In file included from drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c:21:
   In file included from include/media/v4l2-ctrls.h:14:
   In file included from include/media/media-request.h:20:
   In file included from include/media/media-device.h:16:
   In file included from include/linux/pci.h:2676:
   In file included from include/linux/dma-mapping.h:11:
   In file included from include/linux/scatterlist.h:8:
   In file included from include/linux/mm.h:2213:
   include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
     518 |         return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
         |                               ~~~~~~~~~~~ ^ ~~~
>> drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c:261:2: warning: comparison of distinct pointer types ('typeof ((mbps)) *' (aka 'long long *') and 'uint64_t *' (aka 'unsigned long long *')) [-Wcompare-distinct-pointer-types]
     261 |         do_div(mbps, 1000000);
         |         ^~~~~~~~~~~~~~~~~~~~~
   include/asm-generic/div64.h:222:28: note: expanded from macro 'do_div'
     222 |         (void)(((typeof((n)) *)0) == ((uint64_t *)0));  \
         |                ~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~
   8 warnings generated.


vim +261 drivers/media/platform/renesas/rzg2l-cru/rzg2l-csi2.c

   238	
   239	static int rzg2l_csi2_calc_mbps(struct rzg2l_csi2 *csi2)
   240	{
   241		struct v4l2_subdev *source = csi2->remote_source;
   242		const struct rzg2l_csi2_format *format;
   243		const struct v4l2_mbus_framefmt *fmt;
   244		struct v4l2_subdev_state *state;
   245		s64 mbps;
   246	
   247		state = v4l2_subdev_lock_and_get_active_state(&csi2->subdev);
   248		fmt = v4l2_subdev_state_get_format(state, RZG2L_CSI2_SINK);
   249		format = rzg2l_csi2_code_to_fmt(fmt->code);
   250		v4l2_subdev_unlock_state(state);
   251	
   252		/* Read the link frequency from remote subdevice. */
   253		mbps = v4l2_get_link_freq(source->ctrl_handler, format->bpp,
   254					  csi2->lanes);
   255		if (mbps < 0) {
   256			dev_err(csi2->dev, "can't retrieve link freq from subdev %s\n",
   257				source->name);
   258			return -EINVAL;
   259		}
   260	
 > 261		do_div(mbps, 1000000);
   262	
   263		return mbps;
   264	}
   265	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format
  2024-12-02 14:58 ` [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format Daniel Scally
@ 2024-12-03 11:19   ` Laurent Pinchart
  2024-12-16 13:18   ` Lad, Prabhakar
  1 sibling, 0 replies; 11+ messages in thread
From: Laurent Pinchart @ 2024-12-03 11:19 UTC (permalink / raw)
  To: Daniel Scally
  Cc: linux-media, hverkuil-cisco, sakari.ailus,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott

Hi Dan,

Thank you for the patch.

On Mon, Dec 02, 2024 at 02:58:30PM +0000, Daniel Scally wrote:
> As a preliminary step for supporting the CRU pixel formats, extend
> the driver such that multiple media bus codes can support each of
> the output pixel formats.
> 
> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>

> ---
> Changes in v3:
> 
> 	- New patch due to changes to patch 1
> 
>  .../platform/renesas/rzg2l-cru/rzg2l-cru.h    |  8 ++-
>  .../platform/renesas/rzg2l-cru/rzg2l-ip.c     | 67 +++++++++++++++----
>  .../platform/renesas/rzg2l-cru/rzg2l-video.c  |  2 +-
>  3 files changed, 61 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
> index aaf85054f8842..ab923bfa3becf 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
> @@ -71,7 +71,11 @@ struct rzg2l_cru_ip {
>   * @yuv: Flag to indicate whether the format is YUV-based.
>   */
>  struct rzg2l_cru_ip_format {
> -	u32 code;
> +	/*
> +	 * RAW output formats might be produced by RAW media codes with any one
> +	 * of the 4 common bayer patterns.
> +	 */
> +	u32 codes[4];
>  	u32 datatype;
>  	u32 format;
>  	u32 icndmr;
> @@ -169,5 +173,7 @@ struct v4l2_mbus_framefmt *rzg2l_cru_ip_get_src_fmt(struct rzg2l_cru_dev *cru);
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code);
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_format_to_fmt(u32 format);
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_index_to_fmt(u32 index);
> +bool rzg2l_cru_ip_fmt_supports_mbus_code(const struct rzg2l_cru_ip_format *fmt,
> +					 unsigned int code);
>  
>  #endif
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
> index 399a337dbafbf..54a79d5c13e10 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
> @@ -13,35 +13,45 @@
>  
>  static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
>  	{
> -		.code = MEDIA_BUS_FMT_UYVY8_1X16,
> +		.codes = {
> +			MEDIA_BUS_FMT_UYVY8_1X16,
> +		},
>  		.datatype = MIPI_CSI2_DT_YUV422_8B,
>  		.format = V4L2_PIX_FMT_UYVY,
>  		.icndmr = ICnDMR_YCMODE_UYVY,
>  		.yuv = true,
>  	},
>  	{
> -		.code = MEDIA_BUS_FMT_SBGGR8_1X8,
> +		.codes = {
> +			MEDIA_BUS_FMT_SBGGR8_1X8,
> +		},
>  		.format = V4L2_PIX_FMT_SBGGR8,
>  		.datatype = MIPI_CSI2_DT_RAW8,
>  		.icndmr = 0,
>  		.yuv = false,
>  	},
>  	{
> -		.code = MEDIA_BUS_FMT_SGBRG8_1X8,
> +		.codes = {
> +			MEDIA_BUS_FMT_SGBRG8_1X8,
> +		},
>  		.format = V4L2_PIX_FMT_SGBRG8,
>  		.datatype = MIPI_CSI2_DT_RAW8,
>  		.icndmr = 0,
>  		.yuv = false,
>  	},
>  	{
> -		.code = MEDIA_BUS_FMT_SGRBG8_1X8,
> +		.codes = {
> +			MEDIA_BUS_FMT_SGRBG8_1X8,
> +		},
>  		.format = V4L2_PIX_FMT_SGRBG8,
>  		.datatype = MIPI_CSI2_DT_RAW8,
>  		.icndmr = 0,
>  		.yuv = false,
>  	},
>  	{
> -		.code = MEDIA_BUS_FMT_SRGGB8_1X8,
> +		.codes = {
> +			MEDIA_BUS_FMT_SRGGB8_1X8,
> +		},
>  		.format = V4L2_PIX_FMT_SRGGB8,
>  		.datatype = MIPI_CSI2_DT_RAW8,
>  		.icndmr = 0,
> @@ -51,11 +61,14 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
>  
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code)
>  {
> -	unsigned int i;
> +	unsigned int i, j;
>  
> -	for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++)
> -		if (rzg2l_cru_ip_formats[i].code == code)
> -			return &rzg2l_cru_ip_formats[i];
> +	for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++) {
> +		for (j = 0; j < ARRAY_SIZE(rzg2l_cru_ip_formats[i].codes); j++) {
> +			if (rzg2l_cru_ip_formats[i].codes[j] == code)
> +				return &rzg2l_cru_ip_formats[i];
> +		}
> +	}
>  
>  	return NULL;
>  }
> @@ -80,6 +93,17 @@ const struct rzg2l_cru_ip_format *rzg2l_cru_ip_index_to_fmt(u32 index)
>  	return &rzg2l_cru_ip_formats[index];
>  }
>  
> +bool rzg2l_cru_ip_fmt_supports_mbus_code(const struct rzg2l_cru_ip_format *fmt,
> +					 unsigned int code)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(fmt->codes); i++)
> +		if (fmt->codes[i] == code)
> +			return true;
> +
> +	return false;
> +}
>  struct v4l2_mbus_framefmt *rzg2l_cru_ip_get_src_fmt(struct rzg2l_cru_dev *cru)
>  {
>  	struct v4l2_subdev_state *state;
> @@ -155,7 +179,7 @@ static int rzg2l_cru_ip_set_format(struct v4l2_subdev *sd,
>  	sink_format = v4l2_subdev_state_get_format(state, fmt->pad);
>  
>  	if (!rzg2l_cru_ip_code_to_fmt(fmt->format.code))
> -		sink_format->code = rzg2l_cru_ip_formats[0].code;
> +		sink_format->code = rzg2l_cru_ip_formats[0].codes[0];
>  	else
>  		sink_format->code = fmt->format.code;
>  
> @@ -181,11 +205,26 @@ static int rzg2l_cru_ip_enum_mbus_code(struct v4l2_subdev *sd,
>  				       struct v4l2_subdev_state *state,
>  				       struct v4l2_subdev_mbus_code_enum *code)
>  {
> -	if (code->index >= ARRAY_SIZE(rzg2l_cru_ip_formats))
> -		return -EINVAL;
> +	unsigned int index = code->index;
> +	unsigned int i, j;
>  
> -	code->code = rzg2l_cru_ip_formats[code->index].code;
> -	return 0;
> +	for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++) {
> +		const struct rzg2l_cru_ip_format *fmt = &rzg2l_cru_ip_formats[i];
> +
> +		for (j = 0; j < ARRAY_SIZE(fmt->codes); j++) {
> +			if (!fmt->codes[j])
> +				continue;
> +
> +			if (!index) {
> +				code->code = fmt->codes[j];
> +				return 0;
> +			}
> +
> +			index--;
> +		}
> +	}
> +
> +	return -EINVAL;
>  }
>  
>  static int rzg2l_cru_ip_enum_frame_size(struct v4l2_subdev *sd,
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> index 028b390488c84..57d1ff45ce1e9 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> @@ -891,7 +891,7 @@ static int rzg2l_cru_video_link_validate(struct media_link *link)
>  	if (fmt.format.width != cru->format.width ||
>  	    fmt.format.height != cru->format.height ||
>  	    fmt.format.field != cru->format.field ||
> -	    video_fmt->code != fmt.format.code)
> +	    !rzg2l_cru_ip_fmt_supports_mbus_code(video_fmt, fmt.format.code))
>  		return -EPIPE;
>  
>  	return 0;

-- 
Regards,

Laurent Pinchart

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats
  2024-12-02 14:58 ` [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats Daniel Scally
  2024-12-02 17:41   ` Laurent Pinchart
@ 2024-12-16 13:17   ` Lad, Prabhakar
  1 sibling, 0 replies; 11+ messages in thread
From: Lad, Prabhakar @ 2024-12-16 13:17 UTC (permalink / raw)
  To: Daniel Scally
  Cc: linux-media, hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott

On Mon, Dec 2, 2024 at 6:16 PM Daniel Scally
<dan.scally@ideasonboard.com> wrote:
>
> The Renesas Camera Receiver Unit in the RZ/V2H SoC can output RAW
> data captured from an image sensor without conversion to an RGB/YUV
> format. In that case the data are packed into 64-bit blocks, with a
> variable amount of padding in the most significant bits depending on
> the bitdepth of the data. Add new V4L2 pixel format codes for the new
> formats, along with documentation to describe them.
>
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
> ---
> Changes in v3:
>
>         - Switched from bayer-order specific formats to generic RAWnn
>
> Changes in v2:
>
>         - Added labels to the new formats in the documentation file
>         - Added 20-bit formats
>
>  .../userspace-api/media/v4l/pixfmt-bayer.rst  |   1 +
>  .../media/v4l/pixfmt-rawnn-cru.rst            | 144 ++++++++++++++++++
>  drivers/media/v4l2-core/v4l2-common.c         |   4 +
>  drivers/media/v4l2-core/v4l2-ioctl.c          |   4 +
>  include/uapi/linux/videodev2.h                |   6 +
>  5 files changed, 159 insertions(+)
>  create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Cheers,
Prabhakar

> diff --git a/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst b/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
> index ed3eb432967d9..20a8aa0433047 100644
> --- a/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
> +++ b/Documentation/userspace-api/media/v4l/pixfmt-bayer.rst
> @@ -31,3 +31,4 @@ orders. See also `the Wikipedia article on Bayer filter
>      pixfmt-srggb14
>      pixfmt-srggb14p
>      pixfmt-srggb16
> +    pixfmt-rawnn-cru
> diff --git a/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst b/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
> new file mode 100644
> index 0000000000000..959ecc33654a1
> --- /dev/null
> +++ b/Documentation/userspace-api/media/v4l/pixfmt-rawnn-cru.rst
> @@ -0,0 +1,144 @@
> +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
> +
> +.. _v4l2-pix-fmt-cru-raw10:
> +.. _v4l2-pix-fmt-cru-raw12:
> +.. _v4l2-pix-fmt-cru-raw14:
> +.. _v4l2-pix-fmt-cru-raw20:
> +
> +**********************************************************************************************************************************
> +V4L2_PIX_FMT_CRU_RAW10 ('CR10'), V4L2_PIX_FMT_CRU_RAW12 ('CR12'), V4L2_PIX_FMT_CRU_RAW14 ('CR14'), V4L2_PIX_FMT_CRU_RAW20 ('CR20')
> +**********************************************************************************************************************************
> +
> +===============================================================
> +Renesas RZ/V2H Camera Receiver Unit 64-bit packed pixel formats
> +===============================================================
> +
> +| V4L2_PIX_FMT_CRU_RAW10 (CR10)
> +| V4L2_PIX_FMT_CRU_RAW12 (CR12)
> +| V4L2_PIX_FMT_CRU_RAW14 (CR14)
> +| V4L2_PIX_FMT_CRU_RAW20 (CR20)
> +
> +Description
> +===========
> +
> +These pixel formats are some of the Bayer RAW outputs for the Camera Receiver
> +Unit in the Renesas RZ/V2H SoC. They are raw sRGB / Bayer formats which pack
> +pixels contiguously into 64-bit units, with the 4 or 8 most significant
> +bits padded.
> +
> +**Byte Order**
> +
> +.. flat-table:: RGB formats
> +    :header-rows:  2
> +    :stub-columns: 0
> +    :widths: 36 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
> +    :fill-cells:
> +
> +    * - :rspan:`1` Pixel Format Code
> +      - :cspan:`63` Data organization
> +    * - 63
> +      - 62
> +      - 61
> +      - 60
> +      - 59
> +      - 58
> +      - 57
> +      - 56
> +      - 55
> +      - 54
> +      - 53
> +      - 52
> +      - 51
> +      - 50
> +      - 49
> +      - 48
> +      - 47
> +      - 46
> +      - 45
> +      - 44
> +      - 43
> +      - 42
> +      - 41
> +      - 40
> +      - 39
> +      - 38
> +      - 37
> +      - 36
> +      - 35
> +      - 34
> +      - 33
> +      - 32
> +      - 31
> +      - 30
> +      - 29
> +      - 28
> +      - 27
> +      - 26
> +      - 25
> +      - 24
> +      - 23
> +      - 22
> +      - 21
> +      - 20
> +      - 19
> +      - 18
> +      - 17
> +      - 16
> +      - 15
> +      - 14
> +      - 13
> +      - 12
> +      - 11
> +      - 10
> +      - 9
> +      - 8
> +      - 7
> +      - 6
> +      - 5
> +      - 4
> +      - 3
> +      - 2
> +      - 1
> +      - 0
> +    * - V4L2_PIX_FMT_CRU_RAW10
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`9` P5
> +      - :cspan:`9` P4
> +      - :cspan:`9` P3
> +      - :cspan:`9` P2
> +      - :cspan:`9` P1
> +      - :cspan:`9` P0
> +    * - V4L2_PIX_FMT_CRU_RAW12
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`11` P4
> +      - :cspan:`11` P3
> +      - :cspan:`11` P2
> +      - :cspan:`11` P1
> +      - :cspan:`11` P0
> +    * - V4L2_PIX_FMT_CRU_RAW14
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`13` P3
> +      - :cspan:`13` P2
> +      - :cspan:`13` P1
> +      - :cspan:`13` P0
> +    * - V4L2_PIX_FMT_CRU_RAW20
> +      - 0
> +      - 0
> +      - 0
> +      - 0
> +      - :cspan:`19` P2
> +      - :cspan:`19` P1
> +      - :cspan:`19` P0
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index 0a2f4f0d0a073..696b33add65b8 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -329,10 +329,14 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
>                 { .format = V4L2_PIX_FMT_SGBRG10DPCM8,  .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>                 { .format = V4L2_PIX_FMT_SGRBG10DPCM8,  .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>                 { .format = V4L2_PIX_FMT_SRGGB10DPCM8,  .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 1, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +               { .format = V4L2_PIX_FMT_CRU_RAW10,     .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 6, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>                 { .format = V4L2_PIX_FMT_SBGGR12,       .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>                 { .format = V4L2_PIX_FMT_SGBRG12,       .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>                 { .format = V4L2_PIX_FMT_SGRBG12,       .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>                 { .format = V4L2_PIX_FMT_SRGGB12,       .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +               { .format = V4L2_PIX_FMT_CRU_RAW12,     .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 5, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +               { .format = V4L2_PIX_FMT_CRU_RAW14,     .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 4, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
> +               { .format = V4L2_PIX_FMT_CRU_RAW20,     .pixel_enc = V4L2_PIXEL_ENC_BAYER, .mem_planes = 1, .comp_planes = 1, .bpp = { 8, 0, 0, 0 }, .bpp_div = { 3, 1, 1, 1 }, .hdiv = 1, .vdiv = 1 },
>         };
>         unsigned int i;
>
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 0304daa8471d1..85bd068b14275 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1409,6 +1409,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>         case V4L2_PIX_FMT_SGBRG10DPCM8: descr = "8-bit Bayer GBGB/RGRG (DPCM)"; break;
>         case V4L2_PIX_FMT_SGRBG10DPCM8: descr = "8-bit Bayer GRGR/BGBG (DPCM)"; break;
>         case V4L2_PIX_FMT_SRGGB10DPCM8: descr = "8-bit Bayer RGRG/GBGB (DPCM)"; break;
> +       case V4L2_PIX_FMT_CRU_RAW10:    descr = "10-bit Bayer CRU Packed"; break;
>         case V4L2_PIX_FMT_SBGGR12:      descr = "12-bit Bayer BGBG/GRGR"; break;
>         case V4L2_PIX_FMT_SGBRG12:      descr = "12-bit Bayer GBGB/RGRG"; break;
>         case V4L2_PIX_FMT_SGRBG12:      descr = "12-bit Bayer GRGR/BGBG"; break;
> @@ -1417,6 +1418,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>         case V4L2_PIX_FMT_SGBRG12P:     descr = "12-bit Bayer GBGB/RGRG Packed"; break;
>         case V4L2_PIX_FMT_SGRBG12P:     descr = "12-bit Bayer GRGR/BGBG Packed"; break;
>         case V4L2_PIX_FMT_SRGGB12P:     descr = "12-bit Bayer RGRG/GBGB Packed"; break;
> +       case V4L2_PIX_FMT_CRU_RAW12:    descr = "12-bit Bayer CRU Packed"; break;
>         case V4L2_PIX_FMT_SBGGR14:      descr = "14-bit Bayer BGBG/GRGR"; break;
>         case V4L2_PIX_FMT_SGBRG14:      descr = "14-bit Bayer GBGB/RGRG"; break;
>         case V4L2_PIX_FMT_SGRBG14:      descr = "14-bit Bayer GRGR/BGBG"; break;
> @@ -1425,10 +1427,12 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
>         case V4L2_PIX_FMT_SGBRG14P:     descr = "14-bit Bayer GBGB/RGRG Packed"; break;
>         case V4L2_PIX_FMT_SGRBG14P:     descr = "14-bit Bayer GRGR/BGBG Packed"; break;
>         case V4L2_PIX_FMT_SRGGB14P:     descr = "14-bit Bayer RGRG/GBGB Packed"; break;
> +       case V4L2_PIX_FMT_CRU_RAW14:    descr = "14-bit Bayer CRU Packed"; break;
>         case V4L2_PIX_FMT_SBGGR16:      descr = "16-bit Bayer BGBG/GRGR"; break;
>         case V4L2_PIX_FMT_SGBRG16:      descr = "16-bit Bayer GBGB/RGRG"; break;
>         case V4L2_PIX_FMT_SGRBG16:      descr = "16-bit Bayer GRGR/BGBG"; break;
>         case V4L2_PIX_FMT_SRGGB16:      descr = "16-bit Bayer RGRG/GBGB"; break;
> +       case V4L2_PIX_FMT_CRU_RAW20:    descr = "14-bit Bayer CRU Packed"; break;
>         case V4L2_PIX_FMT_SN9C20X_I420: descr = "GSPCA SN9C20X I420"; break;
>         case V4L2_PIX_FMT_SPCA501:      descr = "GSPCA SPCA501"; break;
>         case V4L2_PIX_FMT_SPCA505:      descr = "GSPCA SPCA505"; break;
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index e7c4dce390074..b0482b9af04f5 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -830,6 +830,12 @@ struct v4l2_pix_format {
>  #define V4L2_PIX_FMT_PISP_COMP2_BGGR   v4l2_fourcc('P', 'C', '2', 'B') /* PiSP 8-bit mode 2 compressed BGGR bayer */
>  #define V4L2_PIX_FMT_PISP_COMP2_MONO   v4l2_fourcc('P', 'C', '2', 'M') /* PiSP 8-bit mode 2 compressed monochrome */
>
> +/* Renesas RZ/V2H CRU packed formats. 64-bit units with contiguous pixels */
> +#define V4L2_PIX_FMT_CRU_RAW10 v4l2_fourcc('C', 'R', '1', '0')
> +#define V4L2_PIX_FMT_CRU_RAW12 v4l2_fourcc('C', 'R', '1', '2')
> +#define V4L2_PIX_FMT_CRU_RAW14 v4l2_fourcc('C', 'R', '1', '4')
> +#define V4L2_PIX_FMT_CRU_RAW20 v4l2_fourcc('C', 'R', '2', '0')
> +
>  /* SDR formats - used only for Software Defined Radio devices */
>  #define V4L2_SDR_FMT_CU8          v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */
>  #define V4L2_SDR_FMT_CU16LE       v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */
> --
> 2.34.1
>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format
  2024-12-02 14:58 ` [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format Daniel Scally
  2024-12-03 11:19   ` Laurent Pinchart
@ 2024-12-16 13:18   ` Lad, Prabhakar
  1 sibling, 0 replies; 11+ messages in thread
From: Lad, Prabhakar @ 2024-12-16 13:18 UTC (permalink / raw)
  To: Daniel Scally
  Cc: linux-media, hverkuil-cisco, sakari.ailus, laurent.pinchart,
	prabhakar.mahadev-lad.rj, jacopo.mondi, isaac.scott

On Mon, Dec 2, 2024 at 3:51 PM Daniel Scally
<dan.scally@ideasonboard.com> wrote:
>
> As a preliminary step for supporting the CRU pixel formats, extend
> the driver such that multiple media bus codes can support each of
> the output pixel formats.
>
> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
> ---
> Changes in v3:
>
>         - New patch due to changes to patch 1
>
>  .../platform/renesas/rzg2l-cru/rzg2l-cru.h    |  8 ++-
>  .../platform/renesas/rzg2l-cru/rzg2l-ip.c     | 67 +++++++++++++++----
>  .../platform/renesas/rzg2l-cru/rzg2l-video.c  |  2 +-
>  3 files changed, 61 insertions(+), 16 deletions(-)
>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Cheers,
Prabhakar

> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
> index aaf85054f8842..ab923bfa3becf 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
> @@ -71,7 +71,11 @@ struct rzg2l_cru_ip {
>   * @yuv: Flag to indicate whether the format is YUV-based.
>   */
>  struct rzg2l_cru_ip_format {
> -       u32 code;
> +       /*
> +        * RAW output formats might be produced by RAW media codes with any one
> +        * of the 4 common bayer patterns.
> +        */
> +       u32 codes[4];
>         u32 datatype;
>         u32 format;
>         u32 icndmr;
> @@ -169,5 +173,7 @@ struct v4l2_mbus_framefmt *rzg2l_cru_ip_get_src_fmt(struct rzg2l_cru_dev *cru);
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code);
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_format_to_fmt(u32 format);
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_index_to_fmt(u32 index);
> +bool rzg2l_cru_ip_fmt_supports_mbus_code(const struct rzg2l_cru_ip_format *fmt,
> +                                        unsigned int code);
>
>  #endif
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
> index 399a337dbafbf..54a79d5c13e10 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
> @@ -13,35 +13,45 @@
>
>  static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
>         {
> -               .code = MEDIA_BUS_FMT_UYVY8_1X16,
> +               .codes = {
> +                       MEDIA_BUS_FMT_UYVY8_1X16,
> +               },
>                 .datatype = MIPI_CSI2_DT_YUV422_8B,
>                 .format = V4L2_PIX_FMT_UYVY,
>                 .icndmr = ICnDMR_YCMODE_UYVY,
>                 .yuv = true,
>         },
>         {
> -               .code = MEDIA_BUS_FMT_SBGGR8_1X8,
> +               .codes = {
> +                       MEDIA_BUS_FMT_SBGGR8_1X8,
> +               },
>                 .format = V4L2_PIX_FMT_SBGGR8,
>                 .datatype = MIPI_CSI2_DT_RAW8,
>                 .icndmr = 0,
>                 .yuv = false,
>         },
>         {
> -               .code = MEDIA_BUS_FMT_SGBRG8_1X8,
> +               .codes = {
> +                       MEDIA_BUS_FMT_SGBRG8_1X8,
> +               },
>                 .format = V4L2_PIX_FMT_SGBRG8,
>                 .datatype = MIPI_CSI2_DT_RAW8,
>                 .icndmr = 0,
>                 .yuv = false,
>         },
>         {
> -               .code = MEDIA_BUS_FMT_SGRBG8_1X8,
> +               .codes = {
> +                       MEDIA_BUS_FMT_SGRBG8_1X8,
> +               },
>                 .format = V4L2_PIX_FMT_SGRBG8,
>                 .datatype = MIPI_CSI2_DT_RAW8,
>                 .icndmr = 0,
>                 .yuv = false,
>         },
>         {
> -               .code = MEDIA_BUS_FMT_SRGGB8_1X8,
> +               .codes = {
> +                       MEDIA_BUS_FMT_SRGGB8_1X8,
> +               },
>                 .format = V4L2_PIX_FMT_SRGGB8,
>                 .datatype = MIPI_CSI2_DT_RAW8,
>                 .icndmr = 0,
> @@ -51,11 +61,14 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
>
>  const struct rzg2l_cru_ip_format *rzg2l_cru_ip_code_to_fmt(unsigned int code)
>  {
> -       unsigned int i;
> +       unsigned int i, j;
>
> -       for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++)
> -               if (rzg2l_cru_ip_formats[i].code == code)
> -                       return &rzg2l_cru_ip_formats[i];
> +       for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++) {
> +               for (j = 0; j < ARRAY_SIZE(rzg2l_cru_ip_formats[i].codes); j++) {
> +                       if (rzg2l_cru_ip_formats[i].codes[j] == code)
> +                               return &rzg2l_cru_ip_formats[i];
> +               }
> +       }
>
>         return NULL;
>  }
> @@ -80,6 +93,17 @@ const struct rzg2l_cru_ip_format *rzg2l_cru_ip_index_to_fmt(u32 index)
>         return &rzg2l_cru_ip_formats[index];
>  }
>
> +bool rzg2l_cru_ip_fmt_supports_mbus_code(const struct rzg2l_cru_ip_format *fmt,
> +                                        unsigned int code)
> +{
> +       unsigned int i;
> +
> +       for (i = 0; i < ARRAY_SIZE(fmt->codes); i++)
> +               if (fmt->codes[i] == code)
> +                       return true;
> +
> +       return false;
> +}
>  struct v4l2_mbus_framefmt *rzg2l_cru_ip_get_src_fmt(struct rzg2l_cru_dev *cru)
>  {
>         struct v4l2_subdev_state *state;
> @@ -155,7 +179,7 @@ static int rzg2l_cru_ip_set_format(struct v4l2_subdev *sd,
>         sink_format = v4l2_subdev_state_get_format(state, fmt->pad);
>
>         if (!rzg2l_cru_ip_code_to_fmt(fmt->format.code))
> -               sink_format->code = rzg2l_cru_ip_formats[0].code;
> +               sink_format->code = rzg2l_cru_ip_formats[0].codes[0];
>         else
>                 sink_format->code = fmt->format.code;
>
> @@ -181,11 +205,26 @@ static int rzg2l_cru_ip_enum_mbus_code(struct v4l2_subdev *sd,
>                                        struct v4l2_subdev_state *state,
>                                        struct v4l2_subdev_mbus_code_enum *code)
>  {
> -       if (code->index >= ARRAY_SIZE(rzg2l_cru_ip_formats))
> -               return -EINVAL;
> +       unsigned int index = code->index;
> +       unsigned int i, j;
>
> -       code->code = rzg2l_cru_ip_formats[code->index].code;
> -       return 0;
> +       for (i = 0; i < ARRAY_SIZE(rzg2l_cru_ip_formats); i++) {
> +               const struct rzg2l_cru_ip_format *fmt = &rzg2l_cru_ip_formats[i];
> +
> +               for (j = 0; j < ARRAY_SIZE(fmt->codes); j++) {
> +                       if (!fmt->codes[j])
> +                               continue;
> +
> +                       if (!index) {
> +                               code->code = fmt->codes[j];
> +                               return 0;
> +                       }
> +
> +                       index--;
> +               }
> +       }
> +
> +       return -EINVAL;
>  }
>
>  static int rzg2l_cru_ip_enum_frame_size(struct v4l2_subdev *sd,
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> index 028b390488c84..57d1ff45ce1e9 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> @@ -891,7 +891,7 @@ static int rzg2l_cru_video_link_validate(struct media_link *link)
>         if (fmt.format.width != cru->format.width ||
>             fmt.format.height != cru->format.height ||
>             fmt.format.field != cru->format.field ||
> -           video_fmt->code != fmt.format.code)
> +           !rzg2l_cru_ip_fmt_supports_mbus_code(video_fmt, fmt.format.code))
>                 return -EPIPE;
>
>         return 0;
> --
> 2.34.1
>
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-12-16 13:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-02 14:58 [PATCH v3 0/5] Extend RAW format support for rzg2l-cru driver Daniel Scally
2024-12-02 14:58 ` [PATCH v3 1/5] media: v4l2: Add Renesas Camera Receiver Unit pixel formats Daniel Scally
2024-12-02 17:41   ` Laurent Pinchart
2024-12-16 13:17   ` Lad, Prabhakar
2024-12-02 14:58 ` [PATCH v3 2/5] media: platform: rzg2l-cru: Use v4l2_get_link_freq() Daniel Scally
2024-12-03  6:26   ` kernel test robot
2024-12-02 14:58 ` [PATCH v3 3/5] media: platform: rzg2l-cru: Use v4l2_fill_pixfmt() Daniel Scally
2024-12-02 14:58 ` [PATCH v3 4/5] media: rzg2l-cru: Support multiple mbus codes per pixel format Daniel Scally
2024-12-03 11:19   ` Laurent Pinchart
2024-12-16 13:18   ` Lad, Prabhakar
2024-12-02 14:58 ` [PATCH v3 5/5] media: platform: rzg2l-cru: Add support for RAW10/12/14 data Daniel Scally

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.