media: rzg2l-cru: Refactor ICnDMR register configuration
authorLad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Fri, 18 Oct 2024 13:34:43 +0000 (14:34 +0100)
committerHans Verkuil <hverkuil@xs4all.nl>
Tue, 22 Oct 2024 09:31:28 +0000 (11:31 +0200)
Refactor the ICnDMR register configuration in
`rzg2l_cru_initialize_image_conv()` by adding a new member `icndmr` in the
`rzg2l_cru_ip_format` structure.

Suggested-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Link: https://lore.kernel.org/r/20241018133446.223516-21-prabhakar.mahadev-lad.rj@bp.renesas.com
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
drivers/media/platform/renesas/rzg2l-cru/rzg2l-cru.h
drivers/media/platform/renesas/rzg2l-cru/rzg2l-ip.c
drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c

index 327516272e531ba909733a9a8b4fe626cfda2869..c40754732576de2908523d052fa1eebb56fe7d13 100644 (file)
@@ -31,6 +31,8 @@
 #define RZG2L_CRU_MIN_INPUT_HEIGHT     240
 #define RZG2L_CRU_MAX_INPUT_HEIGHT     4095
 
+#define ICnDMR_YCMODE_UYVY             (1 << 4)
+
 enum rzg2l_csi2_pads {
        RZG2L_CRU_IP_SINK = 0,
        RZG2L_CRU_IP_SOURCE,
@@ -67,12 +69,14 @@ struct rzg2l_cru_ip {
  * @code: Media bus code
  * @datatype: MIPI CSI2 data type
  * @format: 4CC format identifier (V4L2_PIX_FMT_*)
+ * @icndmr: ICnDMR register value
  * @bpp: bytes per pixel
  */
 struct rzg2l_cru_ip_format {
        u32 code;
        u32 datatype;
        u32 format;
+       u32 icndmr;
        u8 bpp;
 };
 
index 07859c89be77996b2f41d3e7f86a4ad450149d65..ad470de440ad5a00e2a5a721ff183a100fdd39a0 100644 (file)
@@ -16,6 +16,7 @@ static const struct rzg2l_cru_ip_format rzg2l_cru_ip_formats[] = {
                .datatype = MIPI_CSI2_DT_YUV422_8B,
                .format = V4L2_PIX_FMT_UYVY,
                .bpp = 2,
+               .icndmr = ICnDMR_YCMODE_UYVY,
        },
 };
 
index df6114cbe5c77d055411de74ce8c7df6318adaa9..a686a5cd4f594126468057ef1208fbce89a1383c 100644 (file)
@@ -88,7 +88,6 @@
 
 /* CRU Data Output Mode Register */
 #define ICnDMR                         0x26c
-#define ICnDMR_YCMODE_UYVY             (1 << 4)
 
 #define RZG2L_TIMEOUT_MS               100
 #define RZG2L_RETRIES                  10
@@ -279,18 +278,15 @@ static int rzg2l_cru_initialize_image_conv(struct rzg2l_cru_dev *cru,
                                           u8 csi_vc)
 {
        const struct v4l2_format_info *src_finfo, *dst_finfo;
+       const struct rzg2l_cru_ip_format *cru_video_fmt;
        const struct rzg2l_cru_ip_format *cru_ip_fmt;
-       u32 icndmr;
 
        cru_ip_fmt = rzg2l_cru_ip_code_to_fmt(ip_sd_fmt->code);
        rzg2l_cru_csi2_setup(cru, cru_ip_fmt, csi_vc);
 
        /* Output format */
-       switch (cru->format.pixelformat) {
-       case V4L2_PIX_FMT_UYVY:
-               icndmr = ICnDMR_YCMODE_UYVY;
-               break;
-       default:
+       cru_video_fmt = rzg2l_cru_ip_format_to_fmt(cru->format.pixelformat);
+       if (!cru_video_fmt) {
                dev_err(cru->dev, "Invalid pixelformat (0x%x)\n",
                        cru->format.pixelformat);
                return -EINVAL;
@@ -308,7 +304,7 @@ static int rzg2l_cru_initialize_image_conv(struct rzg2l_cru_dev *cru,
                                rzg2l_cru_read(cru, ICnMC) & (~ICnMC_CSCTHR));
 
        /* Set output data format */
-       rzg2l_cru_write(cru, ICnDMR, icndmr);
+       rzg2l_cru_write(cru, ICnDMR, cru_video_fmt->icndmr);
 
        return 0;
 }