media: ov01a10: Enable runtime PM before registering async sub-device
authorBingbu Cao <bingbu.cao@intel.com>
Wed, 22 Nov 2023 09:46:07 +0000 (17:46 +0800)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Mon, 4 Dec 2023 10:21:46 +0000 (11:21 +0100)
As the sensor device maybe accessible right after its async sub-device is
registered, such as ipu-bridge will try to power up sensor by sensor's
client device's runtime PM from the async notifier callback, if runtime PM
is not enabled, it will fail.

So runtime PM should be ready before its async sub-device is registered
and accessible by others.

It also sets the runtime PM status to active as the sensor was turned
on by i2c-core.

Fixes: 0827b58dabff ("media: i2c: add ov01a10 image sensor driver")
Cc: stable@vger.kernel.org
Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/i2c/ov01a10.c

index 7cca9294ea31e938820ebb9edab65544eb2958e6..5606437f37d0ece8632c7307487fc30d4906cb80 100644 (file)
@@ -862,6 +862,7 @@ static void ov01a10_remove(struct i2c_client *client)
        v4l2_ctrl_handler_free(sd->ctrl_handler);
 
        pm_runtime_disable(&client->dev);
+       pm_runtime_set_suspended(&client->dev);
 }
 
 static int ov01a10_probe(struct i2c_client *client)
@@ -909,17 +910,26 @@ static int ov01a10_probe(struct i2c_client *client)
                goto err_media_entity_cleanup;
        }
 
+       /*
+        * Device is already turned on by i2c-core with ACPI domain PM.
+        * Enable runtime PM and turn off the device.
+        */
+       pm_runtime_set_active(&client->dev);
+       pm_runtime_enable(dev);
+       pm_runtime_idle(dev);
+
        ret = v4l2_async_register_subdev_sensor(&ov01a10->sd);
        if (ret < 0) {
                dev_err(dev, "Failed to register subdev: %d\n", ret);
-               goto err_media_entity_cleanup;
+               goto err_pm_disable;
        }
 
-       pm_runtime_enable(dev);
-       pm_runtime_idle(dev);
-
        return 0;
 
+err_pm_disable:
+       pm_runtime_disable(dev);
+       pm_runtime_set_suspended(&client->dev);
+
 err_media_entity_cleanup:
        media_entity_cleanup(&ov01a10->sd.entity);