]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
media: atomisp: Add atomisp_s_sensor_power() helper
authorHans de Goede <hdegoede@redhat.com>
Thu, 11 Apr 2024 17:42:16 +0000 (18:42 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 26 Apr 2024 09:44:53 +0000 (10:44 +0100)
Since the atomisp driver only supports 1 stream / only has 1 asd now,
there is no longer a need to track which stream owns the sensor.

So the asd owner-pointer of struct atomisp_input_subdev can be dropped,
replace this with a simple camera_on boolean and add a new
atomisp_s_sensor_power() helper which takes care of avoiding unbalanced
s_power() subdev calls as well as takes care of handling the special
-ENOIOCTLCMD return for subdevs which don't implement s_power().

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_fops.c
drivers/staging/media/atomisp/pci/atomisp_internal.h
drivers/staging/media/atomisp/pci/atomisp_ioctl.c

index 3a56cf68b688ecd5feff513585aaf957250b69ea..6b8ff9f1ae638d9f869a038e873a3c0b09e9ebf2 100644 (file)
@@ -3722,6 +3722,23 @@ apply_min_padding:
        *padding_h = max_t(u32, *padding_h, min_pad_h);
 }
 
+int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on)
+{
+       int ret;
+
+       if (isp->inputs[input].camera_on == on)
+               return 0;
+
+       ret = v4l2_subdev_call(isp->inputs[input].camera, core, s_power, on);
+       if (ret && ret != -ENOIOCTLCMD) {
+               dev_err(isp->dev, "Error setting sensor power %d: %d\n", on, ret);
+               return ret;
+       }
+
+       isp->inputs[input].camera_on = on;
+       return 0;
+}
+
 static int atomisp_set_sensor_crop_and_fmt(struct atomisp_device *isp,
                                           struct v4l2_mbus_framefmt *ffmt,
                                           int which)
index b8cd957eebdc21cc0a6f04b39bfc358398d3a0f2..2676236ee01547ddadbc4700927a568ad50ddd5f 100644 (file)
@@ -241,6 +241,9 @@ int atomisp_compare_grid(struct atomisp_sub_device *asd,
 void atomisp_get_padding(struct atomisp_device *isp, u32 width, u32 height,
                         u32 *padding_w, u32 *padding_h);
 
+/* Set sensor power (no-op if already on/off) */
+int atomisp_s_sensor_power(struct atomisp_device *isp, unsigned int input, bool on);
+
 /* 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 4dba6120af391f8e0b89d22847e255624aa68c93..b464a6bd0bad462af271fe3cf6e7107f4d5bc9cc 100644 (file)
@@ -445,12 +445,8 @@ const struct vb2_ops atomisp_vb2_ops = {
 
 static void atomisp_dev_init_struct(struct atomisp_device *isp)
 {
-       unsigned int i;
-
        isp->isp_fatal_error = false;
 
-       for (i = 0; i < isp->input_cnt; i++)
-               isp->inputs[i].asd = NULL;
        /*
         * For Merrifield, frequency is scalable.
         * After boot-up, the default frequency is 200MHz.
@@ -584,15 +580,7 @@ static int atomisp_release(struct file *file)
        atomisp_css_free_stat_buffers(asd);
        atomisp_free_internal_buffers(asd);
 
-       if (isp->inputs[asd->input_curr].asd == asd) {
-               ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
-                                      core, s_power, 0);
-               if (ret && ret != -ENOIOCTLCMD)
-                       dev_warn(isp->dev, "Failed to power-off sensor\n");
-
-               /* clear the asd field to show this camera is not used */
-               isp->inputs[asd->input_curr].asd = NULL;
-       }
+       atomisp_s_sensor_power(isp, asd->input_curr, 0);
 
        atomisp_destroy_pipes_stream(asd);
 
index d6e86d013be93b19292c37e4d4f7656c7b26e6e6..02fffa7f65e16fcb9f387def14df6daf99743a27 100644 (file)
@@ -127,17 +127,13 @@ struct atomisp_input_subdev {
        u32 code; /* MEDIA_BUS_FMT_* */
        bool binning_support;
        bool crop_support;
+       bool camera_on;
        struct v4l2_subdev *camera;
        /* Sensor rects for sensors which support crop */
        struct v4l2_rect native_rect;
        struct v4l2_rect active_rect;
        /* Sensor state for which == V4L2_SUBDEV_FORMAT_TRY calls */
        struct v4l2_subdev_state *try_sd_state;
-       /*
-        * To show this resource is used by
-        * which stream, in ISP multiple stream mode
-        */
-       struct atomisp_sub_device *asd;
 };
 
 enum atomisp_dfs_mode {
index d602bda134f9984d291b3895ae65a9984d14ea58..be1f3f2ee63e34a0882a9df975967e17b5d4f150 100644 (file)
@@ -469,28 +469,15 @@ static int atomisp_s_input(struct file *file, void *fh, unsigned int input)
        }
 
        /* power off the current owned sensor, as it is not used this time */
-       if (isp->inputs[asd->input_curr].asd == asd &&
-           asd->input_curr != input) {
-               ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera,
-                                      core, s_power, 0);
-               if (ret && ret != -ENOIOCTLCMD)
-                       dev_warn(isp->dev,
-                                "Failed to power-off sensor\n");
-               /* clear the asd field to show this camera is not used */
-               isp->inputs[asd->input_curr].asd = NULL;
-       }
+       if (input != isp->asd.input_curr)
+               atomisp_s_sensor_power(isp, isp->asd.input_curr, 0);
 
        /* powe on the new sensor */
-       ret = v4l2_subdev_call(isp->inputs[input].camera, core, s_power, 1);
-       if (ret && ret != -ENOIOCTLCMD) {
-               dev_err(isp->dev, "Failed to power-on sensor\n");
+       ret = atomisp_s_sensor_power(isp, input, 1);
+       if (ret)
                return ret;
-       }
 
        asd->input_curr = input;
-       /* mark this camera is used by the current stream */
-       isp->inputs[input].asd = asd;
-
        return 0;
 }