media: rcar-vin: Add check that input interface and format are valid
authorNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Wed, 16 Mar 2022 14:48:39 +0000 (15:48 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 13 May 2022 09:02:18 +0000 (11:02 +0200)
Add a check to make sure the input interface (CSI-2 or parallel) allow
for the requested input bus format. If not inform the user and error out
rather then try to continue with incorrect settings.

While at it add the missing define for RGB666 that is not yet supported
in the driver but we can preemptively check for it in this context
already.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/renesas/rcar-vin/rcar-dma.c

index 2272f1c96aafd72a916ef384fe0d7b387cb0109c..6644b498929d16fc2ed90209d800cad8162f4f11 100644 (file)
@@ -77,6 +77,7 @@
 
 /* Register bit fields for R-Car VIN */
 /* Video n Main Control Register bits */
+#define VNMC_INF_MASK          (7 << 16)
 #define VNMC_DPINE             (1 << 27) /* Gen3 specific */
 #define VNMC_SCLE              (1 << 26) /* Gen3 specific */
 #define VNMC_FOC               (1 << 21)
@@ -88,6 +89,7 @@
 #define VNMC_INF_RAW8          (4 << 16)
 #define VNMC_INF_YUV16         (5 << 16)
 #define VNMC_INF_RGB888                (6 << 16)
+#define VNMC_INF_RGB666                (7 << 16)
 #define VNMC_VUP               (1 << 10)
 #define VNMC_IM_ODD            (0 << 3)
 #define VNMC_IM_ODD_EVEN       (1 << 3)
@@ -707,6 +709,29 @@ static int rvin_setup(struct rvin_dev *vin)
                break;
        }
 
+       /* Make sure input interface and input format is valid. */
+       if (vin->info->model == RCAR_GEN3) {
+               switch (vnmc & VNMC_INF_MASK) {
+               case VNMC_INF_YUV8_BT656:
+               case VNMC_INF_YUV10_BT656:
+               case VNMC_INF_YUV16:
+               case VNMC_INF_RGB666:
+                       if (vin->is_csi) {
+                               vin_err(vin, "Invalid setting in MIPI CSI2\n");
+                               return -EINVAL;
+                       }
+                       break;
+               case VNMC_INF_RAW8:
+                       if (!vin->is_csi) {
+                               vin_err(vin, "Invalid setting in Digital Pins\n");
+                               return -EINVAL;
+                       }
+                       break;
+               default:
+                       break;
+               }
+       }
+
        /* Enable VSYNC Field Toggle mode after one VSYNC input */
        if (vin->info->model == RCAR_GEN3)
                dmr2 = VNDMR2_FTEV;