]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
media: atomisp: Add atomisp_select_input() helper
authorHans de Goede <hdegoede@redhat.com>
Thu, 11 Apr 2024 17:56:47 +0000 (18:56 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 26 Apr 2024 09:48:40 +0000 (10:48 +0100)
When switching input/sensor the s_power() callback must be called
for old sensor drivers to power on the new sensor and power off
the previous sensor.

atomisp_s_input() already does this but atomisp_link_setup()
did not do this.

Add a new atomisp_select_input() helper which does this and use this
in both atomisp_s_input() and atomisp_link_setup() for consistent
behavior.

Also make atomisp_link_setup() turn the sensor back off when
a link gets disabled.

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_subdev.c

index 83a15a2d358e8e0a2a24b1cebbcf38180d8c9388..6c93bab17955248de8c6807d378f1dc1208f6069 100644 (file)
@@ -3739,6 +3739,25 @@ int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool
        return 0;
 }
 
+int atomisp_select_input(struct atomisp_device *isp, unsigned int input)
+{
+       unsigned int input_orig = isp->asd.input_curr;
+       int ret;
+
+       /* Power on new sensor */
+       ret = atomisp_s_sensor_power(isp, input, 1);
+       if (ret)
+               return ret;
+
+       isp->asd.input_curr = input;
+
+       /* Power off previous sensor */
+       if (input != input_orig)
+               atomisp_s_sensor_power(isp, input_orig, 0);
+
+       return 0;
+}
+
 static int atomisp_set_sensor_crop_and_fmt(struct atomisp_device *isp,
                                           struct v4l2_mbus_framefmt *ffmt,
                                           int which)
index 2676236ee01547ddadbc4700927a568ad50ddd5f..f302763b7b2fc0ec05beea013bb1d7cc828f48e2 100644 (file)
@@ -244,6 +244,9 @@ void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
 /* Set sensor power (no-op if already on/off) */
 int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on);
 
+/* Select which sensor to use, must be called with a valid input */
+int atomisp_select_input(struct atomisp_device *isp, unsigned int input);
+
 /* 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 be1f3f2ee63e34a0882a9df975967e17b5d4f150..b3ad53449cb84e5861c587200c4cf5eb3ed58974 100644 (file)
@@ -449,7 +449,6 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
        struct video_device *vdev = video_devdata(file);
        struct atomisp_device *isp = video_get_drvdata(vdev);
        struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev);
-       struct atomisp_sub_device *asd = pipe->asd;
        struct v4l2_subdev *camera = NULL;
        int ret;
 
@@ -468,17 +467,7 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
                return -EINVAL;
        }
 
-       /* power off the current owned sensor, as it is not used this time */
-       if (input != isp->asd.input_curr)
-               atomisp_s_sensor_power(isp, isp->asd.input_curr, 0);
-
-       /* powe on the new sensor */
-       ret = atomisp_s_sensor_power(isp, input, 1);
-       if (ret)
-               return ret;
-
-       asd->input_curr = input;
-       return 0;
+       return atomisp_select_input(isp, input);
 }
 
 /*
index c36aae69d6f7696e00030abfd36311dfea0fb60d..aabffd6a424d6f0c6d7a8fef930acc7ca84c94aa 100644 (file)
@@ -663,9 +663,6 @@ static int atomisp_link_setup(struct media_entity *entity,
                return -EINVAL;
        }
 
-       /* Ignore disables, input_curr should only be updated on enables */
-       if (!(flags & MEDIA_LNK_FL_ENABLED))
-               return 0;
 
        for (i = 0; i < isp->input_cnt; i++) {
                if (isp->inputs[i].camera == isp->sensor_subdevs[csi_idx])
@@ -679,11 +676,17 @@ static int atomisp_link_setup(struct media_entity *entity,
 
        mutex_lock(&isp->mutex);
        ret = atomisp_pipe_check(&asd->video_out, true);
-       if (ret == 0)
-               asd->input_curr = i;
        mutex_unlock(&isp->mutex);
+       if (ret)
+               return ret;
 
-       return ret;
+       /* Turn off the sensor on link disable */
+       if (!(flags & MEDIA_LNK_FL_ENABLED)) {
+               atomisp_s_sensor_power(isp, i, 0);
+               return 0;
+       }
+
+       return atomisp_select_input(isp, i);
 }
 
 static const struct media_entity_operations isp_subdev_media_ops = {