1 From ca6cf64a68b93bef63167ef8692efedcc1d6769c Mon Sep 17 00:00:00 2001
2 From: Akinobu Mita <akinobu.mita@gmail.com>
3 Date: Sun, 17 Feb 2019 10:17:47 -0500
4 Subject: media: ov7740: fix runtime pm initialization
6 [ Upstream commit 12aceee1f412c3ddc7750155fec06c906f14ab51 ]
8 The runtime PM of this device is enabled after v4l2_ctrl_handler_setup(),
9 and this makes this device's runtime PM usage count a negative value.
11 The ov7740_set_ctrl() tries to do something only if the device's runtime
12 PM usage counter is nonzero.
16 if (!pm_runtime_get_if_in_use(&client->dev))
21 pm_runtime_put(&client->dev);
26 However, the ov7740_set_ctrl() is called by v4l2_ctrl_handler_setup()
27 while the runtime PM of this device is not yet enabled. In this case,
28 the pm_runtime_get_if_in_use() returns -EINVAL (!= 0).
30 Therefore we can't bail out of this function and the usage count is
31 decreased by pm_runtime_put() without increment.
33 This fixes this problem by enabling the runtime PM of this device before
34 v4l2_ctrl_handler_setup() so that the ov7740_set_ctrl() is always called
35 when the runtime PM is enabled.
37 Cc: Wenyou Yang <wenyou.yang@microchip.com>
38 Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
39 Tested-by: Eugen Hristev <eugen.hristev@microchip.com>
40 Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
41 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
42 Signed-off-by: Sasha Levin <sashal@kernel.org>
44 drivers/media/i2c/ov7740.c | 7 +++++--
45 1 file changed, 5 insertions(+), 2 deletions(-)
47 diff --git a/drivers/media/i2c/ov7740.c b/drivers/media/i2c/ov7740.c
48 index 605f3e25ad82..f5a1ee90a6c5 100644
49 --- a/drivers/media/i2c/ov7740.c
50 +++ b/drivers/media/i2c/ov7740.c
51 @@ -1101,6 +1101,9 @@ static int ov7740_probe(struct i2c_client *client,
55 + pm_runtime_set_active(&client->dev);
56 + pm_runtime_enable(&client->dev);
58 ret = ov7740_detect(ov7740);
61 @@ -1123,8 +1126,6 @@ static int ov7740_probe(struct i2c_client *client,
63 goto error_async_register;
65 - pm_runtime_set_active(&client->dev);
66 - pm_runtime_enable(&client->dev);
67 pm_runtime_idle(&client->dev);
70 @@ -1134,6 +1135,8 @@ error_async_register:
72 ov7740_free_controls(ov7740);
74 + pm_runtime_disable(&client->dev);
75 + pm_runtime_set_suspended(&client->dev);
76 ov7740_set_power(ov7740, 0);
77 media_entity_cleanup(&ov7740->subdev.entity);