[media] v4l: vsp1: Factorize media bus codes enumeration code
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Wed, 24 Feb 2016 23:25:42 +0000 (20:25 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Wed, 13 Apr 2016 22:06:36 +0000 (19:06 -0300)
Most of the entities can't perform format conversion and implement the
same media bus enumeration function. Factorize the code into a single
implementation.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/platform/vsp1/vsp1_bru.c
drivers/media/platform/vsp1/vsp1_entity.c
drivers/media/platform/vsp1/vsp1_entity.h
drivers/media/platform/vsp1/vsp1_lif.c
drivers/media/platform/vsp1/vsp1_lut.c
drivers/media/platform/vsp1/vsp1_sru.c
drivers/media/platform/vsp1/vsp1_uds.c

index fb32f87d4625fbbbdc23e27d95d49c5ccd66654a..b1068c018011de7c34bcb6eb11ff4710815646da 100644 (file)
@@ -76,31 +76,9 @@ static int bru_enum_mbus_code(struct v4l2_subdev *subdev,
                MEDIA_BUS_FMT_ARGB8888_1X32,
                MEDIA_BUS_FMT_AYUV8_1X32,
        };
-       struct vsp1_bru *bru = to_bru(subdev);
-
-       if (code->pad == BRU_PAD_SINK(0)) {
-               if (code->index >= ARRAY_SIZE(codes))
-                       return -EINVAL;
-
-               code->code = codes[code->index];
-       } else {
-               struct v4l2_subdev_pad_config *config;
-               struct v4l2_mbus_framefmt *format;
 
-               if (code->index)
-                       return -EINVAL;
-
-               config = vsp1_entity_get_pad_config(&bru->entity, cfg,
-                                                   code->which);
-               if (!config)
-                       return -EINVAL;
-
-               format = vsp1_entity_get_pad_format(&bru->entity, config,
-                                                   BRU_PAD_SINK(0));
-               code->code = format->code;
-       }
-
-       return 0;
+       return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes,
+                                         ARRAY_SIZE(codes));
 }
 
 static int bru_enum_frame_size(struct v4l2_subdev *subdev,
index e4d6c7a1ed77ada3e5a82635610141779a0be5b3..9e848260d85e30191be79b53b8a57010106d0672 100644 (file)
@@ -141,6 +141,52 @@ int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
        return 0;
 }
 
+/*
+ * vsp1_subdev_enum_mbus_code - Subdev pad enum_mbus_code handler
+ * @subdev: V4L2 subdevice
+ * @cfg: V4L2 subdev pad configuration
+ * @code: Media bus code enumeration
+ * @codes: Array of supported media bus codes
+ * @ncodes: Number of supported media bus codes
+ *
+ * This function implements the subdev enum_mbus_code pad operation for entities
+ * that do not support format conversion. It enumerates the given supported
+ * media bus codes on the sink pad and reports a source pad format identical to
+ * the sink pad.
+ */
+int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev,
+                              struct v4l2_subdev_pad_config *cfg,
+                              struct v4l2_subdev_mbus_code_enum *code,
+                              const unsigned int *codes, unsigned int ncodes)
+{
+       struct vsp1_entity *entity = to_vsp1_entity(subdev);
+
+       if (code->pad == 0) {
+               if (code->index >= ncodes)
+                       return -EINVAL;
+
+               code->code = codes[code->index];
+       } else {
+               struct v4l2_subdev_pad_config *config;
+               struct v4l2_mbus_framefmt *format;
+
+               /* The entity can't perform format conversion, the sink format
+                * is always identical to the source format.
+                */
+               if (code->index)
+                       return -EINVAL;
+
+               config = vsp1_entity_get_pad_config(entity, cfg, code->which);
+               if (!config)
+                       return -EINVAL;
+
+               format = vsp1_entity_get_pad_format(entity, config, 0);
+               code->code = format->code;
+       }
+
+       return 0;
+}
+
 /* -----------------------------------------------------------------------------
  * Media Operations
  */
index d2bb970e72b2304f934a26c23794aa63d5bb3d42..ab7cc498d139ddb899f913e190cb84b33ed49663 100644 (file)
@@ -130,5 +130,9 @@ void vsp1_entity_route_setup(struct vsp1_entity *source,
 int vsp1_subdev_get_pad_format(struct v4l2_subdev *subdev,
                               struct v4l2_subdev_pad_config *cfg,
                               struct v4l2_subdev_format *fmt);
+int vsp1_subdev_enum_mbus_code(struct v4l2_subdev *subdev,
+                              struct v4l2_subdev_pad_config *cfg,
+                              struct v4l2_subdev_mbus_code_enum *code,
+                              const unsigned int *codes, unsigned int ncodes);
 
 #endif /* __VSP1_ENTITY_H__ */
index 730db64bd4d3333a83f40c3bf69517f7ec89aec6..59a8017f39af4f1638d73c79eb5a26f200fb1fc7 100644 (file)
@@ -45,34 +45,9 @@ static int lif_enum_mbus_code(struct v4l2_subdev *subdev,
                MEDIA_BUS_FMT_ARGB8888_1X32,
                MEDIA_BUS_FMT_AYUV8_1X32,
        };
-       struct vsp1_lif *lif = to_lif(subdev);
-
-       if (code->pad == LIF_PAD_SINK) {
-               if (code->index >= ARRAY_SIZE(codes))
-                       return -EINVAL;
-
-               code->code = codes[code->index];
-       } else {
-               struct v4l2_subdev_pad_config *config;
-               struct v4l2_mbus_framefmt *format;
-
-               /* The LIF can't perform format conversion, the sink format is
-                * always identical to the source format.
-                */
-               if (code->index)
-                       return -EINVAL;
-
-               config = vsp1_entity_get_pad_config(&lif->entity, cfg,
-                                                   code->which);
-               if (!config)
-                       return -EINVAL;
 
-               format = vsp1_entity_get_pad_format(&lif->entity, config,
-                                                   LIF_PAD_SINK);
-               code->code = format->code;
-       }
-
-       return 0;
+       return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes,
+                                         ARRAY_SIZE(codes));
 }
 
 static int lif_enum_frame_size(struct v4l2_subdev *subdev,
index f84ee8878858dfda4293424c9f0c6ec5a305bf1f..12a069adf567086ee87c18ce1f9a3acb3c90bd63 100644 (file)
@@ -71,34 +71,9 @@ static int lut_enum_mbus_code(struct v4l2_subdev *subdev,
                MEDIA_BUS_FMT_AHSV8888_1X32,
                MEDIA_BUS_FMT_AYUV8_1X32,
        };
-       struct vsp1_lut *lut = to_lut(subdev);
-
-       if (code->pad == LUT_PAD_SINK) {
-               if (code->index >= ARRAY_SIZE(codes))
-                       return -EINVAL;
-
-               code->code = codes[code->index];
-       } else {
-               struct v4l2_subdev_pad_config *config;
-               struct v4l2_mbus_framefmt *format;
-
-               /* The LUT can't perform format conversion, the sink format is
-                * always identical to the source format.
-                */
-               if (code->index)
-                       return -EINVAL;
-
-               config = vsp1_entity_get_pad_config(&lut->entity, cfg,
-                                                   code->which);
-               if (!config)
-                       return -EINVAL;
 
-               format = vsp1_entity_get_pad_format(&lut->entity, config,
-                                                   LUT_PAD_SINK);
-               code->code = format->code;
-       }
-
-       return 0;
+       return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes,
+                                         ARRAY_SIZE(codes));
 }
 
 static int lut_enum_frame_size(struct v4l2_subdev *subdev,
index 51b017d841f5c28229366fa41c25814693dbb4ad..97ef997ae735d83afc18c35b0d13939cdd698164 100644 (file)
@@ -116,34 +116,9 @@ static int sru_enum_mbus_code(struct v4l2_subdev *subdev,
                MEDIA_BUS_FMT_ARGB8888_1X32,
                MEDIA_BUS_FMT_AYUV8_1X32,
        };
-       struct vsp1_sru *sru = to_sru(subdev);
-
-       if (code->pad == SRU_PAD_SINK) {
-               if (code->index >= ARRAY_SIZE(codes))
-                       return -EINVAL;
-
-               code->code = codes[code->index];
-       } else {
-               struct v4l2_subdev_pad_config *config;
-               struct v4l2_mbus_framefmt *format;
-
-               /* The SRU can't perform format conversion, the sink format is
-                * always identical to the source format.
-                */
-               if (code->index)
-                       return -EINVAL;
 
-               config = vsp1_entity_get_pad_config(&sru->entity, cfg,
-                                                   code->which);
-               if (!config)
-                       return -EINVAL;
-
-               format = vsp1_entity_get_pad_format(&sru->entity, config,
-                                                   SRU_PAD_SINK);
-               code->code = format->code;
-       }
-
-       return 0;
+       return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes,
+                                         ARRAY_SIZE(codes));
 }
 
 static int sru_enum_frame_size(struct v4l2_subdev *subdev,
index 59dd53c0d2be83abd01fb8a95c5f9e4a5e93221c..1875e29da184affe382a7e62b1f0229b10d41c0c 100644 (file)
@@ -119,34 +119,9 @@ static int uds_enum_mbus_code(struct v4l2_subdev *subdev,
                MEDIA_BUS_FMT_ARGB8888_1X32,
                MEDIA_BUS_FMT_AYUV8_1X32,
        };
-       struct vsp1_uds *uds = to_uds(subdev);
-
-       if (code->pad == UDS_PAD_SINK) {
-               if (code->index >= ARRAY_SIZE(codes))
-                       return -EINVAL;
-
-               code->code = codes[code->index];
-       } else {
-               struct v4l2_subdev_pad_config *config;
-               struct v4l2_mbus_framefmt *format;
-
-               config = vsp1_entity_get_pad_config(&uds->entity, cfg,
-                                                   code->which);
-               if (!config)
-                       return -EINVAL;
-
-               /* The UDS can't perform format conversion, the sink format is
-                * always identical to the source format.
-                */
-               if (code->index)
-                       return -EINVAL;
 
-               format = vsp1_entity_get_pad_format(&uds->entity, config,
-                                                   UDS_PAD_SINK);
-               code->code = format->code;
-       }
-
-       return 0;
+       return vsp1_subdev_enum_mbus_code(subdev, cfg, code, codes,
+                                         ARRAY_SIZE(codes));
 }
 
 static int uds_enum_frame_size(struct v4l2_subdev *subdev,
This page took 0.031895 seconds and 5 git commands to generate.