[PATCH v7 08/12] media: tw9900: use runtime PM autosuspend

From: Matthew Laux

Date: Fri Nov 20 2026 - 22:56:36 EST


Each runtime resume enables the supply, toggles reset, rewrites the
init table and waits 300 ms for the horizontal sync PLL to lock. Without
autosuspend, a typical chain of s_routing, polling g_input_status,
querystd, and s_stream would suspend and repower the device each
operation, which adds ~350 ms per call and discards the signal lock.

Use autosuspend with a 1sec delay so that closely spaced operations
share a single power-up.

Signed-off-by: Matthew Laux <matthew.laux@xxxxxxxxx>
---
drivers/media/i2c/tw9900.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/media/i2c/tw9900.c b/drivers/media/i2c/tw9900.c
index b2b754e898c2..b2c30e84acb8 100644
--- a/drivers/media/i2c/tw9900.c
+++ b/drivers/media/i2c/tw9900.c
@@ -68,6 +68,7 @@
#define TW9900_STD_AUTO 7

#define TW9900_VIDEO_POLL_TRIES 20
+#define TW9900_AUTOSUSPEND_DELAY_MS 1000

struct regval {
u8 addr;
@@ -346,7 +347,7 @@ static int tw9900_s_stream(struct v4l2_subdev *sd, int on)

mutex_unlock(&tw9900->mutex);

- pm_runtime_put(&client->dev);
+ pm_runtime_put_autosuspend(&client->dev);

return ret;
}
@@ -355,7 +356,7 @@ static int tw9900_s_stream(struct v4l2_subdev *sd, int on)

err_unlock:
mutex_unlock(&tw9900->mutex);
- pm_runtime_put(&client->dev);
+ pm_runtime_put_autosuspend(&client->dev);

return ret;
}
@@ -532,7 +533,7 @@ static int tw9900_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)

out_unlock:
mutex_unlock(&tw9900->mutex);
- pm_runtime_put(&tw9900->client->dev);
+ pm_runtime_put_autosuspend(&tw9900->client->dev);

return ret;
}
@@ -568,7 +569,7 @@ static int tw9900_g_input_status(struct v4l2_subdev *sd, u32 *status)
ret = tw9900_read_reg(tw9900->client, TW9900_REG_CHIP_STATUS);
mutex_unlock(&tw9900->mutex);

- pm_runtime_put(&tw9900->client->dev);
+ pm_runtime_put_autosuspend(&tw9900->client->dev);

if (ret < 0)
return ret;
@@ -623,7 +624,7 @@ static int tw9900_check_id(struct tw9900 *tw9900,
ret = tw9900_read_reg(client, TW9900_REG_CHIP_ID);
mutex_unlock(&tw9900->mutex);

- pm_runtime_put(&tw9900->client->dev);
+ pm_runtime_put_autosuspend(&tw9900->client->dev);

if (ret < 0)
return ret;
@@ -712,6 +713,7 @@ static int tw9900_runtime_suspend(struct device *dev)

static void tw9900_pm_cleanup(struct device *dev)
{
+ pm_runtime_dont_use_autosuspend(dev);
pm_runtime_disable(dev);
if (!pm_runtime_status_suspended(dev))
tw9900_runtime_suspend(dev);
@@ -782,6 +784,8 @@ static int tw9900_probe(struct i2c_client *client)
goto err_free_handler;

pm_runtime_set_suspended(dev);
+ pm_runtime_set_autosuspend_delay(dev, TW9900_AUTOSUSPEND_DELAY_MS);
+ pm_runtime_use_autosuspend(dev);
pm_runtime_enable(dev);

ret = tw9900_check_id(tw9900, client);
--
2.47.3