linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Enable sensor's runtime PM before registering async sub-dev
@ 2023-11-22  9:30 bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 1/4] media: imx355: Enable runtime PM before registering async sub-device bingbu.cao
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bingbu.cao @ 2023-11-22  9:30 UTC (permalink / raw)
  To: linux-media, sakari.ailus; +Cc: hdegoede, bingbu.cao, bingbu.cao

From: Bingbu Cao <bingbu.cao@intel.com>

Following Sakari's patch:
<URL:https://lore.kernel.org/linux-media/20231102090752.1418132-1-sakari.ailus@linux.intel.com/>

The sensor device maybe accessible right after its async sub-device is
registered, so runtime PM should be ready before its async sub-device
is registered.

---
v2->v3: fix ov01a10 driver to set the runtime pm status to be active
	also add pm_runtime_set_suspended() into .remove
v1->v2: move pm_runtime_idle() together with pm_runtime_enable()
---

Bingbu Cao (4):
  media: imx355: Enable runtime PM before registering async sub-device
  media: ov01a10: Enable runtime PM before registering async sub-device
  media: ov13b10: Enable runtime PM before registering async sub-device
  media: ov9734: Enable runtime PM before registering async sub-device

 drivers/media/i2c/imx355.c  | 12 +++++++-----
 drivers/media/i2c/ov01a10.c | 18 ++++++++++++++----
 drivers/media/i2c/ov13b10.c | 14 +++++++++-----
 drivers/media/i2c/ov9734.c  | 19 +++++++++++--------
 4 files changed, 41 insertions(+), 22 deletions(-)

-- 
2.42.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/4] media: imx355: Enable runtime PM before registering async sub-device
  2023-11-22  9:30 [PATCH v3 0/4] Enable sensor's runtime PM before registering async sub-dev bingbu.cao
@ 2023-11-22  9:30 ` bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 2/4] media: ov01a10: " bingbu.cao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: bingbu.cao @ 2023-11-22  9:30 UTC (permalink / raw)
  To: linux-media, sakari.ailus; +Cc: hdegoede, bingbu.cao, bingbu.cao

From: Bingbu Cao <bingbu.cao@intel.com>

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.

Fixes: df0b5c4a7ddd ("media: add imx355 camera sensor driver")
Cc: stable@vger.kernel.org
Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/i2c/imx355.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/imx355.c b/drivers/media/i2c/imx355.c
index 9c79ae8dc842..059a41b7eefc 100644
--- a/drivers/media/i2c/imx355.c
+++ b/drivers/media/i2c/imx355.c
@@ -1788,10 +1788,6 @@ static int imx355_probe(struct i2c_client *client)
 		goto error_handler_free;
 	}
 
-	ret = v4l2_async_register_subdev_sensor(&imx355->sd);
-	if (ret < 0)
-		goto error_media_entity;
-
 	/*
 	 * Device is already turned on by i2c-core with ACPI domain PM.
 	 * Enable runtime PM and turn off the device.
@@ -1800,9 +1796,15 @@ static int imx355_probe(struct i2c_client *client)
 	pm_runtime_enable(&client->dev);
 	pm_runtime_idle(&client->dev);
 
+	ret = v4l2_async_register_subdev_sensor(&imx355->sd);
+	if (ret < 0)
+		goto error_media_entity_runtime_pm;
+
 	return 0;
 
-error_media_entity:
+error_media_entity_runtime_pm:
+	pm_runtime_disable(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
 	media_entity_cleanup(&imx355->sd.entity);
 
 error_handler_free:
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/4] media: ov01a10: Enable runtime PM before registering async sub-device
  2023-11-22  9:30 [PATCH v3 0/4] Enable sensor's runtime PM before registering async sub-dev bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 1/4] media: imx355: Enable runtime PM before registering async sub-device bingbu.cao
@ 2023-11-22  9:30 ` bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 3/4] media: ov13b10: " bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 4/4] media: ov9734: " bingbu.cao
  3 siblings, 0 replies; 5+ messages in thread
From: bingbu.cao @ 2023-11-22  9:30 UTC (permalink / raw)
  To: linux-media, sakari.ailus; +Cc: hdegoede, bingbu.cao, bingbu.cao

From: Bingbu Cao <bingbu.cao@intel.com>

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>
---
 drivers/media/i2c/ov01a10.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/media/i2c/ov01a10.c b/drivers/media/i2c/ov01a10.c
index 2b9e1b3a3bf4..9afe9bf50334 100644
--- a/drivers/media/i2c/ov01a10.c
+++ b/drivers/media/i2c/ov01a10.c
@@ -907,6 +907,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)
@@ -953,17 +954,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);
 
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 3/4] media: ov13b10: Enable runtime PM before registering async sub-device
  2023-11-22  9:30 [PATCH v3 0/4] Enable sensor's runtime PM before registering async sub-dev bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 1/4] media: imx355: Enable runtime PM before registering async sub-device bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 2/4] media: ov01a10: " bingbu.cao
@ 2023-11-22  9:30 ` bingbu.cao
  2023-11-22  9:30 ` [PATCH v3 4/4] media: ov9734: " bingbu.cao
  3 siblings, 0 replies; 5+ messages in thread
From: bingbu.cao @ 2023-11-22  9:30 UTC (permalink / raw)
  To: linux-media, sakari.ailus; +Cc: hdegoede, bingbu.cao, bingbu.cao

From: Bingbu Cao <bingbu.cao@intel.com>

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.

Fixes: 7ee850546822 ("media: Add sensor driver support for the ov13b10 camera.")
Cc: stable@vger.kernel.org
Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/i2c/ov13b10.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/ov13b10.c b/drivers/media/i2c/ov13b10.c
index dbc642c5995b..f28a79c16a43 100644
--- a/drivers/media/i2c/ov13b10.c
+++ b/drivers/media/i2c/ov13b10.c
@@ -1536,24 +1536,27 @@ static int ov13b10_probe(struct i2c_client *client)
 		goto error_handler_free;
 	}
 
-	ret = v4l2_async_register_subdev_sensor(&ov13b->sd);
-	if (ret < 0)
-		goto error_media_entity;
 
 	/*
 	 * Device is already turned on by i2c-core with ACPI domain PM.
 	 * Enable runtime PM and turn off the device.
 	 */
-
 	/* Set the device's state to active if it's in D0 state. */
 	if (full_power)
 		pm_runtime_set_active(&client->dev);
 	pm_runtime_enable(&client->dev);
 	pm_runtime_idle(&client->dev);
 
+	ret = v4l2_async_register_subdev_sensor(&ov13b->sd);
+	if (ret < 0)
+		goto error_media_entity_runtime_pm;
+
 	return 0;
 
-error_media_entity:
+error_media_entity_runtime_pm:
+	pm_runtime_disable(&client->dev);
+	if (full_power)
+		pm_runtime_set_suspended(&client->dev);
 	media_entity_cleanup(&ov13b->sd.entity);
 
 error_handler_free:
@@ -1576,6 +1579,7 @@ static void ov13b10_remove(struct i2c_client *client)
 	ov13b10_free_controls(ov13b);
 
 	pm_runtime_disable(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
 }
 
 static DEFINE_RUNTIME_DEV_PM_OPS(ov13b10_pm_ops, ov13b10_suspend,
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 4/4] media: ov9734: Enable runtime PM before registering async sub-device
  2023-11-22  9:30 [PATCH v3 0/4] Enable sensor's runtime PM before registering async sub-dev bingbu.cao
                   ` (2 preceding siblings ...)
  2023-11-22  9:30 ` [PATCH v3 3/4] media: ov13b10: " bingbu.cao
@ 2023-11-22  9:30 ` bingbu.cao
  3 siblings, 0 replies; 5+ messages in thread
From: bingbu.cao @ 2023-11-22  9:30 UTC (permalink / raw)
  To: linux-media, sakari.ailus; +Cc: hdegoede, bingbu.cao, bingbu.cao

From: Bingbu Cao <bingbu.cao@intel.com>

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.

Fixes: d3f863a63fe4 ("media: i2c: Add ov9734 image sensor driver")
Cc: stable@vger.kernel.org
Signed-off-by: Bingbu Cao <bingbu.cao@intel.com>
---
 drivers/media/i2c/ov9734.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/ov9734.c b/drivers/media/i2c/ov9734.c
index b6244772bc59..b36fc0fedad4 100644
--- a/drivers/media/i2c/ov9734.c
+++ b/drivers/media/i2c/ov9734.c
@@ -939,6 +939,7 @@ static void ov9734_remove(struct i2c_client *client)
 	media_entity_cleanup(&sd->entity);
 	v4l2_ctrl_handler_free(sd->ctrl_handler);
 	pm_runtime_disable(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
 	mutex_destroy(&ov9734->mutex);
 }
 
@@ -984,13 +985,6 @@ static int ov9734_probe(struct i2c_client *client)
 		goto probe_error_v4l2_ctrl_handler_free;
 	}
 
-	ret = v4l2_async_register_subdev_sensor(&ov9734->sd);
-	if (ret < 0) {
-		dev_err(&client->dev, "failed to register V4L2 subdev: %d",
-			ret);
-		goto probe_error_media_entity_cleanup;
-	}
-
 	/*
 	 * Device is already turned on by i2c-core with ACPI domain PM.
 	 * Enable runtime PM and turn off the device.
@@ -999,9 +993,18 @@ static int ov9734_probe(struct i2c_client *client)
 	pm_runtime_enable(&client->dev);
 	pm_runtime_idle(&client->dev);
 
+	ret = v4l2_async_register_subdev_sensor(&ov9734->sd);
+	if (ret < 0) {
+		dev_err(&client->dev, "failed to register V4L2 subdev: %d",
+			ret);
+		goto probe_error_media_entity_cleanup_pm;
+	}
+
 	return 0;
 
-probe_error_media_entity_cleanup:
+probe_error_media_entity_cleanup_pm:
+	pm_runtime_disable(&client->dev);
+	pm_runtime_set_suspended(&client->dev);
 	media_entity_cleanup(&ov9734->sd.entity);
 
 probe_error_v4l2_ctrl_handler_free:
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-22  9:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-22  9:30 [PATCH v3 0/4] Enable sensor's runtime PM before registering async sub-dev bingbu.cao
2023-11-22  9:30 ` [PATCH v3 1/4] media: imx355: Enable runtime PM before registering async sub-device bingbu.cao
2023-11-22  9:30 ` [PATCH v3 2/4] media: ov01a10: " bingbu.cao
2023-11-22  9:30 ` [PATCH v3 3/4] media: ov13b10: " bingbu.cao
2023-11-22  9:30 ` [PATCH v3 4/4] media: ov9734: " bingbu.cao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).