media: imx5/6/7: csi: Mark a bound video mux as a CSI mux
authorSteve Longerbeam <slongerbeam@gmail.com>
Fri, 1 May 2020 17:15:52 +0000 (19:15 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 18 May 2020 12:29:35 +0000 (14:29 +0200)
For i.MX5/6, if the bound subdev is a video mux, it must be one of the
CSI muxes, and for i.MX7, the bound subdev must always be a CSI mux.

So if the bound subdev is a video mux, mark it as a CSI mux with a new
group id IMX_MEDIA_GRP_ID_CSI_MUX.

In the process use the new group id in csi_get_upstream_endpoint(), and
do some cleanup in that function for better readability.

Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/imx/imx-media-csi.c
drivers/staging/media/imx/imx-media.h
drivers/staging/media/imx/imx7-media-csi.c

index a051a06..6cfbe67 100644 (file)
@@ -165,7 +165,6 @@ static int csi_get_upstream_endpoint(struct csi_priv *priv,
                                     struct v4l2_fwnode_endpoint *ep)
 {
        struct device_node *endpoint, *port;
-       struct media_entity *src;
        struct v4l2_subdev *sd;
        struct media_pad *pad;
 
@@ -176,30 +175,33 @@ static int csi_get_upstream_endpoint(struct csi_priv *priv,
                return -EPIPE;
 
        sd = priv->src_sd;
-       src = &sd->entity;
 
-       if (src->function == MEDIA_ENT_F_VID_MUX) {
+       switch (sd->grp_id) {
+       case IMX_MEDIA_GRP_ID_CSI_MUX:
                /*
-                * CSI is connected directly to video mux, skip up to
+                * CSI is connected directly to CSI mux, skip up to
                 * CSI-2 receiver if it is in the path, otherwise stay
-                * with video mux.
+                * with the CSI mux.
                 */
-               sd = imx_media_pipeline_subdev(src, IMX_MEDIA_GRP_ID_CSI2,
+               sd = imx_media_pipeline_subdev(&sd->entity,
+                                              IMX_MEDIA_GRP_ID_CSI2,
                                               true);
-               if (!IS_ERR(sd))
-                       src = &sd->entity;
+               if (IS_ERR(sd))
+                       sd = priv->src_sd;
+               break;
+       case IMX_MEDIA_GRP_ID_CSI2:
+               break;
+       default:
+               /*
+                * the source is neither the CSI mux nor the CSI-2 receiver,
+                * get the source pad directly upstream from CSI itself.
+                */
+               sd = &priv->sd;
+               break;
        }
 
-       /*
-        * If the source is neither the video mux nor the CSI-2 receiver,
-        * get the source pad directly upstream from CSI itself.
-        */
-       if (src->function != MEDIA_ENT_F_VID_MUX &&
-           sd->grp_id != IMX_MEDIA_GRP_ID_CSI2)
-               src = &priv->sd.entity;
-
-       /* get source pad of entity directly upstream from src */
-       pad = imx_media_pipeline_pad(src, 0, 0, true);
+       /* get source pad of entity directly upstream from sd */
+       pad = imx_media_pipeline_pad(&sd->entity, 0, 0, true);
        if (!pad)
                return -ENODEV;
 
@@ -1906,6 +1908,13 @@ static int imx_csi_notify_bound(struct v4l2_async_notifier *notifier,
        struct csi_priv *priv = notifier_to_dev(notifier);
        struct media_pad *sink = &priv->sd.entity.pads[CSI_SINK_PAD];
 
+       /*
+        * If the subdev is a video mux, it must be one of the CSI
+        * muxes. Mark it as such via its group id.
+        */
+       if (sd->entity.function == MEDIA_ENT_F_VID_MUX)
+               sd->grp_id = IMX_MEDIA_GRP_ID_CSI_MUX;
+
        return v4l2_create_fwnode_links_to_pad(sd, sink);
 }
 
index ca36bec..b5b7d32 100644 (file)
@@ -311,5 +311,6 @@ void imx_media_csc_scaler_device_unregister(struct imx_media_video_dev *vdev);
 #define IMX_MEDIA_GRP_ID_IPU_IC_PRP    BIT(13)
 #define IMX_MEDIA_GRP_ID_IPU_IC_PRPENC BIT(14)
 #define IMX_MEDIA_GRP_ID_IPU_IC_PRPVF  BIT(15)
+#define IMX_MEDIA_GRP_ID_CSI_MUX       BIT(16)
 
 #endif
index 69f7abb..a3f3df9 100644 (file)
@@ -1164,6 +1164,13 @@ static int imx7_csi_notify_bound(struct v4l2_async_notifier *notifier,
        struct imx7_csi *csi = imx7_csi_notifier_to_dev(notifier);
        struct media_pad *sink = &csi->sd.entity.pads[IMX7_CSI_PAD_SINK];
 
+       /* The bound subdev must always be the CSI mux */
+       if (WARN_ON(sd->entity.function != MEDIA_ENT_F_VID_MUX))
+               return -ENXIO;
+
+       /* Mark it as such via its group id */
+       sd->grp_id = IMX_MEDIA_GRP_ID_CSI_MUX;
+
        return v4l2_create_fwnode_links_to_pad(sd, sink);
 }