diff mbox

[v1.1,5/5] smiapp: Implement support for autosuspend

Message ID 1474374598-32451-1-git-send-email-sakari.ailus@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sakari Ailus Sept. 20, 2016, 12:29 p.m. UTC
Delay suspending the device by 1000 ms by default.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---

since v1:

- Increment usage count before register write using
  pm_runtime_get_noresume(), and decrement it before returning. This
  avoids a serialisation problem with autosuspend.

 drivers/media/i2c/smiapp/smiapp-core.c | 10 +++++++---
 drivers/media/i2c/smiapp/smiapp-regs.c | 21 +++++++++++++++------
 2 files changed, 22 insertions(+), 9 deletions(-)

Comments

Sebastian Reichel Sept. 23, 2016, 12:14 a.m. UTC | #1
Hi,

On Tue, Sep 20, 2016 at 03:29:58PM +0300, Sakari Ailus wrote:
> Delay suspending the device by 1000 ms by default.
> 
> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> ---
> 
> since v1:
> 
> - Increment usage count before register write using
>   pm_runtime_get_noresume(), and decrement it before returning. This
>   avoids a serialisation problem with autosuspend.
> 
>  drivers/media/i2c/smiapp/smiapp-core.c | 10 +++++++---
>  drivers/media/i2c/smiapp/smiapp-regs.c | 21 +++++++++++++++------
>  2 files changed, 22 insertions(+), 9 deletions(-)

Reviewed-By: Sebastian Reichel <sre@kernel.org>

-- Sebastian
Sakari Ailus Sept. 23, 2016, 11:13 a.m. UTC | #2
Sebastian Reichel wrote:
> Hi,
>
> On Tue, Sep 20, 2016 at 03:29:58PM +0300, Sakari Ailus wrote:
>> Delay suspending the device by 1000 ms by default.
>>
>> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
>> ---
>>
>> since v1:
>>
>> - Increment usage count before register write using
>>    pm_runtime_get_noresume(), and decrement it before returning. This
>>    avoids a serialisation problem with autosuspend.
>>
>>   drivers/media/i2c/smiapp/smiapp-core.c | 10 +++++++---
>>   drivers/media/i2c/smiapp/smiapp-regs.c | 21 +++++++++++++++------
>>   2 files changed, 22 insertions(+), 9 deletions(-)
>
> Reviewed-By: Sebastian Reichel <sre@kernel.org>

Danke schön! :-)
diff mbox

Patch

diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index f1c95bf..77c0a26 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -1556,7 +1556,8 @@  static int smiapp_set_stream(struct v4l2_subdev *subdev, int enable)
 		rval = smiapp_stop_streaming(sensor);
 		sensor->streaming = false;
 
-		pm_runtime_put(&client->dev);
+		pm_runtime_mark_last_busy(&client->dev);
+		pm_runtime_put_autosuspend(&client->dev);
 	}
 
 	return rval;
@@ -2324,7 +2325,8 @@  smiapp_sysfs_nvm_read(struct device *dev, struct device_attribute *attr,
 			dev_err(&client->dev, "nvm read failed\n");
 			return -ENODEV;
 		}
-		pm_runtime_put(&client->dev);
+		pm_runtime_mark_last_busy(&client->dev);
+		pm_runtime_put_autosuspend(&client->dev);
 	}
 	/*
 	 * NVM is still way below a PAGE_SIZE, so we can safely
@@ -3052,7 +3054,9 @@  static int smiapp_probe(struct i2c_client *client,
 	if (rval < 0)
 		goto out_media_entity_cleanup;
 
-	pm_runtime_put(&client->dev);
+	pm_runtime_set_autosuspend_delay(&client->dev, 1000);
+	pm_runtime_use_autosuspend(&client->dev);
+	pm_runtime_put_autosuspend(&client->dev);
 
 	return 0;
 
diff --git a/drivers/media/i2c/smiapp/smiapp-regs.c b/drivers/media/i2c/smiapp/smiapp-regs.c
index a9c7baf..ef15478 100644
--- a/drivers/media/i2c/smiapp/smiapp-regs.c
+++ b/drivers/media/i2c/smiapp/smiapp-regs.c
@@ -290,16 +290,25 @@  int smiapp_write_no_quirk(struct smiapp_sensor *sensor, u32 reg, u32 val)
 int smiapp_write(struct smiapp_sensor *sensor, u32 reg, u32 val)
 {
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
-	int rval;
+	int rval = 0;
+
+	pm_runtime_get_noresume(&client->dev);
 
 	if (pm_runtime_suspended(&client->dev))
-		return 0;
+		goto out;
 
 	rval = smiapp_call_quirk(sensor, reg_access, true, &reg, &val);
-	if (rval == -ENOIOCTLCMD)
-		return 0;
+	if (rval == -ENOIOCTLCMD) {
+		rval = 0;
+		goto out;
+	}
 	if (rval < 0)
-		return rval;
+		goto out;
+
+	rval = smiapp_write_no_quirk(sensor, reg, val);
+
+out:
+	pm_runtime_put_autosuspend(&client->dev);
 
-	return smiapp_write_no_quirk(sensor, reg, val);
+	return rval;
 }