media: atomisp: Ensure CSI-receiver[x] -> ISP links correctly reflect current sensor
authorHans de Goede <hdegoede@redhat.com>
Thu, 11 Apr 2024 20:21:37 +0000 (21:21 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 26 Apr 2024 09:50:54 +0000 (10:50 +0100)
Add a new atomisp_setup_input_links() helper which ensures that
the CSI-receiver -> ISP link for input_curr is marked as enabled and
the other CSI-receiver -> ISP links are disabled.

And call this helper from atomisp_register_device_nodes() for the initial
setup and from atomisp_select_input() for runtime input_curr changes.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/staging/media/atomisp/pci/atomisp_cmd.c
drivers/staging/media/atomisp/pci/atomisp_cmd.h
drivers/staging/media/atomisp/pci/atomisp_ioctl.c
drivers/staging/media/atomisp/pci/atomisp_v4l2.c

index 6c93bab17955248de8c6807d378f1dc1208f6069..b273234dc439e4a0c8d2d67ea76d572c3778fe45 100644 (file)
@@ -3755,9 +3755,43 @@ int atomisp_select_input(struct atomisp_device *isp, unsigned int input)
        if (input != input_orig)
                atomisp_s_sensor_power(isp, input_orig, 0);
 
+       atomisp_setup_input_links(isp);
        return 0;
 }
 
+/*
+ * Ensure the CSI-receiver -> ISP link for input_curr is marked as enabled and
+ * the other CSI-receiver -> ISP links are disabled.
+ */
+void atomisp_setup_input_links(struct atomisp_device *isp)
+{
+       struct media_link *link;
+
+       lockdep_assert_held(&isp->media_dev.graph_mutex);
+
+       for (int i = 0; i < ATOMISP_CAMERA_NR_PORTS; i++) {
+               link = media_entity_find_link(
+                               &isp->csi2_port[i].subdev.entity.pads[CSI2_PAD_SOURCE],
+                               &isp->asd.subdev.entity.pads[ATOMISP_SUBDEV_PAD_SINK]);
+               if (!link) {
+                       dev_err(isp->dev, "Error cannot find CSI2-port[%d] -> ISP link\n", i);
+                       continue; /* Should never happen */
+               }
+
+               /*
+                * Modify the flags directly, calling media_entity_setup_link()
+                * will end up calling atomisp_link_setup() which calls this
+                * function again leading to endless recursion.
+                */
+               if (isp->sensor_subdevs[i] == isp->inputs[isp->asd.input_curr].camera)
+                       link->flags |= MEDIA_LNK_FL_ENABLED;
+               else
+                       link->flags &= ~MEDIA_LNK_FL_ENABLED;
+
+               link->reverse->flags = link->flags;
+       }
+}
+
 static int atomisp_set_sensor_crop_and_fmt(struct atomisp_device *isp,
                                           struct v4l2_mbus_framefmt *ffmt,
                                           int which)
index f302763b7b2fc0ec05beea013bb1d7cc828f48e2..03703eed86fadb26def25bf437739d20ae33d95c 100644 (file)
@@ -247,6 +247,9 @@ int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool
 /* Select which sensor to use, must be called with a valid input */
 int atomisp_select_input(struct atomisp_device *isp, unsigned int input);
 
+/* Setup media-controller links to reflect input_curr setting */
+void atomisp_setup_input_links(struct atomisp_device *isp);
+
 /* This function looks up the closest available resolution. */
 int atomisp_try_fmt(struct atomisp_device *isp, struct v4l2_pix_format *f,
                    const struct atomisp_format_bridge **fmt_ret,
index 1f8d44900a82145cf26cbf8f5f98f51fd23b50a2..c16942051cfb2d2a9404ef08d7e6fb3c951fc4ae 100644 (file)
@@ -461,7 +461,11 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
        if (ret)
                return ret;
 
-       return atomisp_select_input(isp, input);
+       mutex_lock(&isp->media_dev.graph_mutex);
+       ret = atomisp_select_input(isp, input);
+       mutex_unlock(&isp->media_dev.graph_mutex);
+
+       return ret;
 }
 
 /*
index 1d7d38e2f90409b45f4edbc2ecca96ac39dda867..1008a709b589adc487462682f3628e7c298330c3 100644 (file)
@@ -1085,6 +1085,10 @@ int atomisp_register_device_nodes(struct atomisp_device *isp)
                dev_warn(isp->dev, "too many atomisp inputs, TPG ignored.\n");
        }
 
+       mutex_lock(&isp->media_dev.graph_mutex);
+       atomisp_setup_input_links(isp);
+       mutex_unlock(&isp->media_dev.graph_mutex);
+
        isp->asd.video_out.vdev.v4l2_dev = &isp->v4l2_dev;
        isp->asd.video_out.vdev.device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
        err = video_register_device(&isp->asd.video_out.vdev, VFL_TYPE_VIDEO, -1);