2017-09-04 10:27:51

by Mohandass, Divagar

[permalink] [raw]
Subject: [PATCH v6 0/3] enable eeprom "size" property and runtime pm

This series adds support for eeprom "size" property which will be read by the
driver for eeprom size. The existing ACPI has a different default size which
can be overridden with a DSD property value provided by the platform FW.

This series also adds support for runtime PM. The eeprom driver currently
did not have support for runtime PM and the device was kept in D0 throughout.

[v1]
- Add support for eeprom "size" property.
- Add runtime PM support to the driver.

[v2]
- Improved the patch subject.

[v3]
- Addressed comments from Sakari Ailus.
- Improved patch description.
- Improved pm support patch.

[v4]
- Improved runtime pm support.
- Addressed comments from Sakari Ailus.

[v5]
- Addressed comments from Sakari Ailus.
- Improved error handling for PM support.

[v6]
- Addressed comments from Sakari Ailus.

Divagar Mohandass (3):
dt-bindings: add eeprom "size" property
eeprom: at24: add support to fetch eeprom device property "size"
eeprom: at24: enable runtime pm support

.../devicetree/bindings/eeprom/eeprom.txt | 2 ++
drivers/misc/eeprom/at24.c | 42 ++++++++++++++++++++++
2 files changed, 44 insertions(+)

--
1.9.1


2017-09-04 10:27:58

by Mohandass, Divagar

[permalink] [raw]
Subject: [PATCH v6 1/3] dt-bindings: add eeprom "size" property

This adds eeprom "size" as optional property for i2c eeproms.
The "size" property allows explicitly specifying the size of the
EEPROM chip in bytes.

Signed-off-by: Divagar Mohandass <[email protected]>
Acked-by: Rob Herring <[email protected]>
---
Documentation/devicetree/bindings/eeprom/eeprom.txt | 2 ++
1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/eeprom/eeprom.txt b/Documentation/devicetree/bindings/eeprom/eeprom.txt
index 5696eb5..1436569 100644
--- a/Documentation/devicetree/bindings/eeprom/eeprom.txt
+++ b/Documentation/devicetree/bindings/eeprom/eeprom.txt
@@ -32,6 +32,8 @@ Optional properties:

- read-only: this parameterless property disables writes to the eeprom

+ - size: total eeprom size in bytes
+
Example:

eeprom@52 {
--
1.9.1

2017-09-04 10:28:11

by Mohandass, Divagar

[permalink] [raw]
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Currently the device is kept in D0, there is an opportunity
to save power by enabling runtime pm.

Device can be daisy chained from PMIC and we can't rely on I2C core
for auto resume/suspend. Driver will decide when to resume/suspend.

Signed-off-by: Divagar Mohandass <[email protected]>
---
drivers/misc/eeprom/at24.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 2199c42..d718a7a 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -24,6 +24,7 @@
#include <linux/i2c.h>
#include <linux/nvmem-provider.h>
#include <linux/platform_data/at24.h>
+#include <linux/pm_runtime.h>

/*
* I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
@@ -501,11 +502,21 @@ static ssize_t at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
static int at24_read(void *priv, unsigned int off, void *val, size_t count)
{
struct at24_data *at24 = priv;
+ struct i2c_client *client;
char *buf = val;
+ int ret;

if (unlikely(!count))
return count;

+ client = at24_translate_offset(at24, &off);
+
+ ret = pm_runtime_get_sync(&client->dev);
+ if (ret < 0) {
+ pm_runtime_put_noidle(&client->dev);
+ return ret;
+ }
+
/*
* Read data from chip, protecting against concurrent updates
* from this host, but not from other I2C masters.
@@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)
status = at24->read_func(at24, buf, off, count);
if (status < 0) {
mutex_unlock(&at24->lock);
+ pm_runtime_put(&client->dev);
return status;
}
buf += status;
@@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned int off, void *val, size_t count)

mutex_unlock(&at24->lock);

+ pm_runtime_put(&client->dev);
+
return 0;
}

static int at24_write(void *priv, unsigned int off, void *val, size_t count)
{
struct at24_data *at24 = priv;
+ struct i2c_client *client;
char *buf = val;
+ int ret;

if (unlikely(!count))
return -EINVAL;

+ client = at24_translate_offset(at24, &off);
+
+ ret = pm_runtime_get_sync(&client->dev);
+ if (ret < 0) {
+ pm_runtime_put_noidle(&client->dev);
+ return ret;
+ }
+
/*
* Write data to chip, protecting against concurrent updates
* from this host, but not from other I2C masters.
@@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)
status = at24->write_func(at24, buf, off, count);
if (status < 0) {
mutex_unlock(&at24->lock);
+ pm_runtime_put(&client->dev);
return status;
}
buf += status;
@@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned int off, void *val, size_t count)

mutex_unlock(&at24->lock);

+ pm_runtime_put(&client->dev);
+
return 0;
}

@@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)

i2c_set_clientdata(client, at24);

+ /* enable runtime pm */
+ pm_runtime_get_noresume(&client->dev);
+ pm_runtime_set_active(&client->dev);
+ pm_runtime_enable(&client->dev);
+
/*
* Perform a one-byte test read to verify that the
* chip is functional.
*/
err = at24_read(at24, 0, &test_byte, 1);
+ pm_runtime_put(&client->dev);
if (err) {
err = -ENODEV;
goto err_clients;
@@ -795,6 +828,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (at24->client[i])
i2c_unregister_device(at24->client[i]);

+ pm_runtime_disable(&client->dev);
+
return err;
}

@@ -810,6 +845,9 @@ static int at24_remove(struct i2c_client *client)
for (i = 1; i < at24->num_addresses; i++)
i2c_unregister_device(at24->client[i]);

+ pm_runtime_disable(&client->dev);
+ pm_runtime_set_suspended(&client->dev);
+
return 0;
}

--
1.9.1

2017-09-04 10:28:21

by Mohandass, Divagar

[permalink] [raw]
Subject: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"

Obtain the size of the EEPROM chip from DT if the "size" property is
specified for the device.

Signed-off-by: Divagar Mohandass <[email protected]>
---
drivers/misc/eeprom/at24.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 764ff5df..2199c42 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -570,6 +570,10 @@ static void at24_get_pdata(struct device *dev, struct at24_platform_data *chip)
if (device_property_present(dev, "read-only"))
chip->flags |= AT24_FLAG_READONLY;

+ err = device_property_read_u32(dev, "size", &val);
+ if (!err)
+ chip->byte_len = val;
+
err = device_property_read_u32(dev, "pagesize", &val);
if (!err) {
chip->page_size = val;
--
1.9.1

2017-09-05 13:48:29

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v6 0/3] enable eeprom "size" property and runtime pm

Hi Divagar,

On Mon, Sep 04, 2017 at 03:58:45PM +0530, Divagar Mohandass wrote:
> This series adds support for eeprom "size" property which will be read by the
> driver for eeprom size. The existing ACPI has a different default size which
> can be overridden with a DSD property value provided by the platform FW.
>
> This series also adds support for runtime PM. The eeprom driver currently
> did not have support for runtime PM and the device was kept in D0 throughout.
>
> [v1]
> - Add support for eeprom "size" property.
> - Add runtime PM support to the driver.
>
> [v2]
> - Improved the patch subject.
>
> [v3]
> - Addressed comments from Sakari Ailus.
> - Improved patch description.
> - Improved pm support patch.
>
> [v4]
> - Improved runtime pm support.
> - Addressed comments from Sakari Ailus.
>
> [v5]
> - Addressed comments from Sakari Ailus.
> - Improved error handling for PM support.
>
> [v6]
> - Addressed comments from Sakari Ailus.
>
> Divagar Mohandass (3):
> dt-bindings: add eeprom "size" property
> eeprom: at24: add support to fetch eeprom device property "size"
> eeprom: at24: enable runtime pm support
>
> .../devicetree/bindings/eeprom/eeprom.txt | 2 ++
> drivers/misc/eeprom/at24.c | 42 ++++++++++++++++++++++
> 2 files changed, 44 insertions(+)

Thanks for the update!

For the set:

Reviewed-by: Sakari Ailus <[email protected]>

--
Kind regards,

Sakari Ailus
e-mail: [email protected]

2017-09-20 03:51:42

by Mani, Rajmohan

[permalink] [raw]
Subject: RE: [PATCH v6 0/3] enable eeprom "size" property and runtime pm

Adding Tomasz...

> -----Original Message-----
> From: Sakari Ailus [mailto:[email protected]]
> Sent: Tuesday, September 05, 2017 6:48 AM
> To: Mohandass, Divagar <[email protected]>
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected]; linux-
> [email protected]; Mani, Rajmohan <[email protected]>
> Subject: Re: [PATCH v6 0/3] enable eeprom "size" property and runtime pm
>
> Hi Divagar,
>
> On Mon, Sep 04, 2017 at 03:58:45PM +0530, Divagar Mohandass wrote:
> > This series adds support for eeprom "size" property which will be read
> > by the driver for eeprom size. The existing ACPI has a different
> > default size which can be overridden with a DSD property value provided by
> the platform FW.
> >
> > This series also adds support for runtime PM. The eeprom driver
> > currently did not have support for runtime PM and the device was kept in D0
> throughout.
> >
> > [v1]
> > - Add support for eeprom "size" property.
> > - Add runtime PM support to the driver.
> >
> > [v2]
> > - Improved the patch subject.
> >
> > [v3]
> > - Addressed comments from Sakari Ailus.
> > - Improved patch description.
> > - Improved pm support patch.
> >
> > [v4]
> > - Improved runtime pm support.
> > - Addressed comments from Sakari Ailus.
> >
> > [v5]
> > - Addressed comments from Sakari Ailus.
> > - Improved error handling for PM support.
> >
> > [v6]
> > - Addressed comments from Sakari Ailus.
> >
> > Divagar Mohandass (3):
> > dt-bindings: add eeprom "size" property
> > eeprom: at24: add support to fetch eeprom device property "size"
> > eeprom: at24: enable runtime pm support
> >
> > .../devicetree/bindings/eeprom/eeprom.txt | 2 ++
> > drivers/misc/eeprom/at24.c | 42 ++++++++++++++++++++++
> > 2 files changed, 44 insertions(+)
>
> Thanks for the update!
>
> For the set:
>
> Reviewed-by: Sakari Ailus <[email protected]>
>
> --
> Kind regards,
>
> Sakari Ailus
> e-mail: [email protected]

2017-09-20 03:52:16

by Mani, Rajmohan

[permalink] [raw]
Subject: RE: [PATCH v6 1/3] dt-bindings: add eeprom "size" property

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: [email protected]; [email protected]; [email protected];
> [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]; Mani, Rajmohan <[email protected]>;
> Mohandass, Divagar <[email protected]>
> Subject: [PATCH v6 1/3] dt-bindings: add eeprom "size" property
>
> This adds eeprom "size" as optional property for i2c eeproms.
> The "size" property allows explicitly specifying the size of the EEPROM chip in
> bytes.
>
> Signed-off-by: Divagar Mohandass <[email protected]>
> Acked-by: Rob Herring <[email protected]>
> ---
> Documentation/devicetree/bindings/eeprom/eeprom.txt | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/eeprom/eeprom.txt
> b/Documentation/devicetree/bindings/eeprom/eeprom.txt
> index 5696eb5..1436569 100644
> --- a/Documentation/devicetree/bindings/eeprom/eeprom.txt
> +++ b/Documentation/devicetree/bindings/eeprom/eeprom.txt
> @@ -32,6 +32,8 @@ Optional properties:
>
> - read-only: this parameterless property disables writes to the eeprom
>
> + - size: total eeprom size in bytes
> +
> Example:
>
> eeprom@52 {
> --
> 1.9.1

2017-09-20 03:52:39

by Mani, Rajmohan

[permalink] [raw]
Subject: RE: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: [email protected]; [email protected]; [email protected];
> [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]; Mani, Rajmohan <[email protected]>;
> Mohandass, Divagar <[email protected]>
> Subject: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device
> property "size"
>
> Obtain the size of the EEPROM chip from DT if the "size" property is specified
> for the device.
>
> Signed-off-by: Divagar Mohandass <[email protected]>
> ---
> drivers/misc/eeprom/at24.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index
> 764ff5df..2199c42 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -570,6 +570,10 @@ static void at24_get_pdata(struct device *dev, struct
> at24_platform_data *chip)
> if (device_property_present(dev, "read-only"))
> chip->flags |= AT24_FLAG_READONLY;
>
> + err = device_property_read_u32(dev, "size", &val);
> + if (!err)
> + chip->byte_len = val;
> +
> err = device_property_read_u32(dev, "pagesize", &val);
> if (!err) {
> chip->page_size = val;
> --
> 1.9.1

2017-09-20 03:52:58

by Mani, Rajmohan

[permalink] [raw]
Subject: RE: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: [email protected]; [email protected]; [email protected];
> [email protected]
> Cc: [email protected]; [email protected]; linux-
> [email protected]; Mani, Rajmohan <[email protected]>;
> Mohandass, Divagar <[email protected]>
> Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>
> Currently the device is kept in D0, there is an opportunity to save power by
> enabling runtime pm.
>
> Device can be daisy chained from PMIC and we can't rely on I2C core for auto
> resume/suspend. Driver will decide when to resume/suspend.
>
> Signed-off-by: Divagar Mohandass <[email protected]>
> ---
> drivers/misc/eeprom/at24.c | 38
> ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 38 insertions(+)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index
> 2199c42..d718a7a 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -24,6 +24,7 @@
> #include <linux/i2c.h>
> #include <linux/nvmem-provider.h>
> #include <linux/platform_data/at24.h>
> +#include <linux/pm_runtime.h>
>
> /*
> * I2C EEPROMs from most vendors are inexpensive and mostly
> interchangeable.
> @@ -501,11 +502,21 @@ static ssize_t at24_eeprom_write_i2c(struct
> at24_data *at24, const char *buf, static int at24_read(void *priv, unsigned int
> off, void *val, size_t count) {
> struct at24_data *at24 = priv;
> + struct i2c_client *client;
> char *buf = val;
> + int ret;
>
> if (unlikely(!count))
> return count;
>
> + client = at24_translate_offset(at24, &off);
> +
> + ret = pm_runtime_get_sync(&client->dev);
> + if (ret < 0) {
> + pm_runtime_put_noidle(&client->dev);
> + return ret;
> + }
> +
> /*
> * Read data from chip, protecting against concurrent updates
> * from this host, but not from other I2C masters.
> @@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned int off, void
> *val, size_t count)
> status = at24->read_func(at24, buf, off, count);
> if (status < 0) {
> mutex_unlock(&at24->lock);
> + pm_runtime_put(&client->dev);
> return status;
> }
> buf += status;
> @@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned int off, void
> *val, size_t count)
>
> mutex_unlock(&at24->lock);
>
> + pm_runtime_put(&client->dev);
> +
> return 0;
> }
>
> static int at24_write(void *priv, unsigned int off, void *val, size_t count) {
> struct at24_data *at24 = priv;
> + struct i2c_client *client;
> char *buf = val;
> + int ret;
>
> if (unlikely(!count))
> return -EINVAL;
>
> + client = at24_translate_offset(at24, &off);
> +
> + ret = pm_runtime_get_sync(&client->dev);
> + if (ret < 0) {
> + pm_runtime_put_noidle(&client->dev);
> + return ret;
> + }
> +
> /*
> * Write data to chip, protecting against concurrent updates
> * from this host, but not from other I2C masters.
> @@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned int off, void
> *val, size_t count)
> status = at24->write_func(at24, buf, off, count);
> if (status < 0) {
> mutex_unlock(&at24->lock);
> + pm_runtime_put(&client->dev);
> return status;
> }
> buf += status;
> @@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned int off, void
> *val, size_t count)
>
> mutex_unlock(&at24->lock);
>
> + pm_runtime_put(&client->dev);
> +
> return 0;
> }
>
> @@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
> struct i2c_device_id *id)
>
> i2c_set_clientdata(client, at24);
>
> + /* enable runtime pm */
> + pm_runtime_get_noresume(&client->dev);
> + pm_runtime_set_active(&client->dev);
> + pm_runtime_enable(&client->dev);
> +
> /*
> * Perform a one-byte test read to verify that the
> * chip is functional.
> */
> err = at24_read(at24, 0, &test_byte, 1);
> + pm_runtime_put(&client->dev);
> if (err) {
> err = -ENODEV;
> goto err_clients;
> @@ -795,6 +828,8 @@ static int at24_probe(struct i2c_client *client, const
> struct i2c_device_id *id)
> if (at24->client[i])
> i2c_unregister_device(at24->client[i]);
>
> + pm_runtime_disable(&client->dev);
> +
> return err;
> }
>
> @@ -810,6 +845,9 @@ static int at24_remove(struct i2c_client *client)
> for (i = 1; i < at24->num_addresses; i++)
> i2c_unregister_device(at24->client[i]);
>
> + pm_runtime_disable(&client->dev);
> + pm_runtime_set_suspended(&client->dev);
> +
> return 0;
> }
>
> --
> 1.9.1

2017-09-20 03:56:36

by Tomasz Figa

[permalink] [raw]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Thanks Raj.

Let me post my comments inline.

On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
<[email protected]> wrote:
> Adding Tomasz...
>
>> -----Original Message-----
>> From: Mohandass, Divagar
>> Sent: Monday, September 04, 2017 3:29 AM
>> To: [email protected]; [email protected]; [email protected];
>> [email protected]
>> Cc: [email protected]; [email protected]; linux-
>> [email protected]; Mani, Rajmohan <[email protected]>;
>> Mohandass, Divagar <[email protected]>
>> Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>>
>> Currently the device is kept in D0, there is an opportunity to save power by
>> enabling runtime pm.
>>
>> Device can be daisy chained from PMIC and we can't rely on I2C core for auto
>> resume/suspend. Driver will decide when to resume/suspend.
>>
>> Signed-off-by: Divagar Mohandass <[email protected]>
>> ---
>> drivers/misc/eeprom/at24.c | 38
>> ++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 38 insertions(+)
>>
>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index
>> 2199c42..d718a7a 100644
>> --- a/drivers/misc/eeprom/at24.c
>> +++ b/drivers/misc/eeprom/at24.c
>> @@ -24,6 +24,7 @@
>> #include <linux/i2c.h>
>> #include <linux/nvmem-provider.h>
>> #include <linux/platform_data/at24.h>
>> +#include <linux/pm_runtime.h>
>>
>> /*
>> * I2C EEPROMs from most vendors are inexpensive and mostly
>> interchangeable.
>> @@ -501,11 +502,21 @@ static ssize_t at24_eeprom_write_i2c(struct
>> at24_data *at24, const char *buf, static int at24_read(void *priv, unsigned int
>> off, void *val, size_t count) {
>> struct at24_data *at24 = priv;
>> + struct i2c_client *client;
>> char *buf = val;
>> + int ret;
>>
>> if (unlikely(!count))
>> return count;
>>
>> + client = at24_translate_offset(at24, &off);
>> +
>> + ret = pm_runtime_get_sync(&client->dev);
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(&client->dev);
>> + return ret;
>> + }
>> +
>> /*
>> * Read data from chip, protecting against concurrent updates
>> * from this host, but not from other I2C masters.
>> @@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned int off, void
>> *val, size_t count)
>> status = at24->read_func(at24, buf, off, count);
>> if (status < 0) {
>> mutex_unlock(&at24->lock);
>> + pm_runtime_put(&client->dev);
>> return status;
>> }
>> buf += status;
>> @@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned int off, void
>> *val, size_t count)
>>
>> mutex_unlock(&at24->lock);
>>
>> + pm_runtime_put(&client->dev);
>> +
>> return 0;
>> }
>>
>> static int at24_write(void *priv, unsigned int off, void *val, size_t count) {
>> struct at24_data *at24 = priv;
>> + struct i2c_client *client;
>> char *buf = val;
>> + int ret;
>>
>> if (unlikely(!count))
>> return -EINVAL;
>>
>> + client = at24_translate_offset(at24, &off);
>> +
>> + ret = pm_runtime_get_sync(&client->dev);
>> + if (ret < 0) {
>> + pm_runtime_put_noidle(&client->dev);
>> + return ret;
>> + }
>> +
>> /*
>> * Write data to chip, protecting against concurrent updates
>> * from this host, but not from other I2C masters.
>> @@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned int off, void
>> *val, size_t count)
>> status = at24->write_func(at24, buf, off, count);
>> if (status < 0) {
>> mutex_unlock(&at24->lock);
>> + pm_runtime_put(&client->dev);
>> return status;
>> }
>> buf += status;
>> @@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned int off, void
>> *val, size_t count)
>>
>> mutex_unlock(&at24->lock);
>>
>> + pm_runtime_put(&client->dev);
>> +
>> return 0;
>> }
>>
>> @@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
>> struct i2c_device_id *id)
>>
>> i2c_set_clientdata(client, at24);
>>
>> + /* enable runtime pm */
>> + pm_runtime_get_noresume(&client->dev);
>> + pm_runtime_set_active(&client->dev);
>> + pm_runtime_enable(&client->dev);

Do we need this get_noresume/set_active dance? I remember it was for
some reason needed for PCI devices, but I don't see why for I2C
anything else than just pm_runtime_enable() would be necessary.

Also, we enable runtime PM, but we don't provide any callbacks. If
there is no callback in any level of the hierarchy, NULL would be
returned in [3], making [2] return -ENOSYS and [1] fail. The behavior
depends on subsystem and whether the device is attached to a
pm_domain. In our particular case I'd guess the device would be in an
ACPI pm_domain and that would work, but the driver is generic and must
work in any cases.

[1] http://elixir.free-electrons.com/linux/v4.4.88/source/drivers/base/power/runtime.c#L738
[2] http://elixir.free-electrons.com/linux/v4.4.88/source/drivers/base/power/runtime.c#L364
[3] http://elixir.free-electrons.com/linux/v4.4.88/source/drivers/base/power/runtime.c#L19

Best regards,
Tomasz

2017-09-20 08:45:29

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Hi Tomasz,

On Wed, Sep 20, 2017 at 12:56:09PM +0900, Tomasz Figa wrote:
> Thanks Raj.
>
> Let me post my comments inline.
>
> On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
> <[email protected]> wrote:
> > Adding Tomasz...
> >
> >> -----Original Message-----
> >> From: Mohandass, Divagar
> >> Sent: Monday, September 04, 2017 3:29 AM
> >> To: [email protected]; [email protected]; [email protected];
> >> [email protected]
> >> Cc: [email protected]; [email protected]; linux-
> >> [email protected]; Mani, Rajmohan <[email protected]>;
> >> Mohandass, Divagar <[email protected]>
> >> Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
> >>
> >> Currently the device is kept in D0, there is an opportunity to save power by
> >> enabling runtime pm.
> >>
> >> Device can be daisy chained from PMIC and we can't rely on I2C core for auto
> >> resume/suspend. Driver will decide when to resume/suspend.
> >>
> >> Signed-off-by: Divagar Mohandass <[email protected]>
> >> ---
> >> drivers/misc/eeprom/at24.c | 38
> >> ++++++++++++++++++++++++++++++++++++++
> >> 1 file changed, 38 insertions(+)
> >>
> >> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index
> >> 2199c42..d718a7a 100644
> >> --- a/drivers/misc/eeprom/at24.c
> >> +++ b/drivers/misc/eeprom/at24.c
> >> @@ -24,6 +24,7 @@
> >> #include <linux/i2c.h>
> >> #include <linux/nvmem-provider.h>
> >> #include <linux/platform_data/at24.h>
> >> +#include <linux/pm_runtime.h>
> >>
> >> /*
> >> * I2C EEPROMs from most vendors are inexpensive and mostly
> >> interchangeable.
> >> @@ -501,11 +502,21 @@ static ssize_t at24_eeprom_write_i2c(struct
> >> at24_data *at24, const char *buf, static int at24_read(void *priv, unsigned int
> >> off, void *val, size_t count) {
> >> struct at24_data *at24 = priv;
> >> + struct i2c_client *client;
> >> char *buf = val;
> >> + int ret;
> >>
> >> if (unlikely(!count))
> >> return count;
> >>
> >> + client = at24_translate_offset(at24, &off);
> >> +
> >> + ret = pm_runtime_get_sync(&client->dev);
> >> + if (ret < 0) {
> >> + pm_runtime_put_noidle(&client->dev);
> >> + return ret;
> >> + }
> >> +
> >> /*
> >> * Read data from chip, protecting against concurrent updates
> >> * from this host, but not from other I2C masters.
> >> @@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned int off, void
> >> *val, size_t count)
> >> status = at24->read_func(at24, buf, off, count);
> >> if (status < 0) {
> >> mutex_unlock(&at24->lock);
> >> + pm_runtime_put(&client->dev);
> >> return status;
> >> }
> >> buf += status;
> >> @@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned int off, void
> >> *val, size_t count)
> >>
> >> mutex_unlock(&at24->lock);
> >>
> >> + pm_runtime_put(&client->dev);
> >> +
> >> return 0;
> >> }
> >>
> >> static int at24_write(void *priv, unsigned int off, void *val, size_t count) {
> >> struct at24_data *at24 = priv;
> >> + struct i2c_client *client;
> >> char *buf = val;
> >> + int ret;
> >>
> >> if (unlikely(!count))
> >> return -EINVAL;
> >>
> >> + client = at24_translate_offset(at24, &off);
> >> +
> >> + ret = pm_runtime_get_sync(&client->dev);
> >> + if (ret < 0) {
> >> + pm_runtime_put_noidle(&client->dev);
> >> + return ret;
> >> + }
> >> +
> >> /*
> >> * Write data to chip, protecting against concurrent updates
> >> * from this host, but not from other I2C masters.
> >> @@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned int off, void
> >> *val, size_t count)
> >> status = at24->write_func(at24, buf, off, count);
> >> if (status < 0) {
> >> mutex_unlock(&at24->lock);
> >> + pm_runtime_put(&client->dev);
> >> return status;
> >> }
> >> buf += status;
> >> @@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned int off, void
> >> *val, size_t count)
> >>
> >> mutex_unlock(&at24->lock);
> >>
> >> + pm_runtime_put(&client->dev);
> >> +
> >> return 0;
> >> }
> >>
> >> @@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
> >> struct i2c_device_id *id)
> >>
> >> i2c_set_clientdata(client, at24);
> >>
> >> + /* enable runtime pm */
> >> + pm_runtime_get_noresume(&client->dev);
> >> + pm_runtime_set_active(&client->dev);
> >> + pm_runtime_enable(&client->dev);
>
> Do we need this get_noresume/set_active dance? I remember it was for
> some reason needed for PCI devices, but I don't see why for I2C
> anything else than just pm_runtime_enable() would be necessary.

You specifically do not need (all) this for PCI devices, but AFAIU for I?C
devices you do. The runtime PM status of a device is disabled by default
and the use count is zero, but on ACPI based systems the device is still
powered on.

>
> Also, we enable runtime PM, but we don't provide any callbacks. If
> there is no callback in any level of the hierarchy, NULL would be
> returned in [3], making [2] return -ENOSYS and [1] fail. The behavior
> depends on subsystem and whether the device is attached to a
> pm_domain. In our particular case I'd guess the device would be in an
> ACPI pm_domain and that would work, but the driver is generic and must
> work in any cases.

Agreed.

Cc Mika, too.

--
Regards,

Sakari Ailus
e-mail: [email protected]

2017-09-20 08:59:49

by Tomasz Figa

[permalink] [raw]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

On Wed, Sep 20, 2017 at 5:45 PM, [email protected]
<[email protected]> wrote:
> Hi Tomasz,
>
> On Wed, Sep 20, 2017 at 12:56:09PM +0900, Tomasz Figa wrote:
>> Thanks Raj.
>>
>> Let me post my comments inline.
>>
>> On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
>> <[email protected]> wrote:
>> > Adding Tomasz...
>> >
>> >> -----Original Message-----
>> >> From: Mohandass, Divagar
>> >> Sent: Monday, September 04, 2017 3:29 AM
>> >> To: [email protected]; [email protected]; [email protected];
>> >> [email protected]
>> >> Cc: [email protected]; [email protected]; linux-
>> >> [email protected]; Mani, Rajmohan <[email protected]>;
>> >> Mohandass, Divagar <[email protected]>
>> >> Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>> >>
>> >> Currently the device is kept in D0, there is an opportunity to save power by
>> >> enabling runtime pm.
>> >>
>> >> Device can be daisy chained from PMIC and we can't rely on I2C core for auto
>> >> resume/suspend. Driver will decide when to resume/suspend.
>> >>
>> >> Signed-off-by: Divagar Mohandass <[email protected]>
>> >> ---
>> >> drivers/misc/eeprom/at24.c | 38
>> >> ++++++++++++++++++++++++++++++++++++++
>> >> 1 file changed, 38 insertions(+)
>> >>
>> >> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index
>> >> 2199c42..d718a7a 100644
>> >> --- a/drivers/misc/eeprom/at24.c
>> >> +++ b/drivers/misc/eeprom/at24.c
>> >> @@ -24,6 +24,7 @@
>> >> #include <linux/i2c.h>
>> >> #include <linux/nvmem-provider.h>
>> >> #include <linux/platform_data/at24.h>
>> >> +#include <linux/pm_runtime.h>
>> >>
>> >> /*
>> >> * I2C EEPROMs from most vendors are inexpensive and mostly
>> >> interchangeable.
>> >> @@ -501,11 +502,21 @@ static ssize_t at24_eeprom_write_i2c(struct
>> >> at24_data *at24, const char *buf, static int at24_read(void *priv, unsigned int
>> >> off, void *val, size_t count) {
>> >> struct at24_data *at24 = priv;
>> >> + struct i2c_client *client;
>> >> char *buf = val;
>> >> + int ret;
>> >>
>> >> if (unlikely(!count))
>> >> return count;
>> >>
>> >> + client = at24_translate_offset(at24, &off);
>> >> +
>> >> + ret = pm_runtime_get_sync(&client->dev);
>> >> + if (ret < 0) {
>> >> + pm_runtime_put_noidle(&client->dev);
>> >> + return ret;
>> >> + }
>> >> +
>> >> /*
>> >> * Read data from chip, protecting against concurrent updates
>> >> * from this host, but not from other I2C masters.
>> >> @@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned int off, void
>> >> *val, size_t count)
>> >> status = at24->read_func(at24, buf, off, count);
>> >> if (status < 0) {
>> >> mutex_unlock(&at24->lock);
>> >> + pm_runtime_put(&client->dev);
>> >> return status;
>> >> }
>> >> buf += status;
>> >> @@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned int off, void
>> >> *val, size_t count)
>> >>
>> >> mutex_unlock(&at24->lock);
>> >>
>> >> + pm_runtime_put(&client->dev);
>> >> +
>> >> return 0;
>> >> }
>> >>
>> >> static int at24_write(void *priv, unsigned int off, void *val, size_t count) {
>> >> struct at24_data *at24 = priv;
>> >> + struct i2c_client *client;
>> >> char *buf = val;
>> >> + int ret;
>> >>
>> >> if (unlikely(!count))
>> >> return -EINVAL;
>> >>
>> >> + client = at24_translate_offset(at24, &off);
>> >> +
>> >> + ret = pm_runtime_get_sync(&client->dev);
>> >> + if (ret < 0) {
>> >> + pm_runtime_put_noidle(&client->dev);
>> >> + return ret;
>> >> + }
>> >> +
>> >> /*
>> >> * Write data to chip, protecting against concurrent updates
>> >> * from this host, but not from other I2C masters.
>> >> @@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned int off, void
>> >> *val, size_t count)
>> >> status = at24->write_func(at24, buf, off, count);
>> >> if (status < 0) {
>> >> mutex_unlock(&at24->lock);
>> >> + pm_runtime_put(&client->dev);
>> >> return status;
>> >> }
>> >> buf += status;
>> >> @@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned int off, void
>> >> *val, size_t count)
>> >>
>> >> mutex_unlock(&at24->lock);
>> >>
>> >> + pm_runtime_put(&client->dev);
>> >> +
>> >> return 0;
>> >> }
>> >>
>> >> @@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
>> >> struct i2c_device_id *id)
>> >>
>> >> i2c_set_clientdata(client, at24);
>> >>
>> >> + /* enable runtime pm */
>> >> + pm_runtime_get_noresume(&client->dev);
>> >> + pm_runtime_set_active(&client->dev);
>> >> + pm_runtime_enable(&client->dev);
>>
>> Do we need this get_noresume/set_active dance? I remember it was for
>> some reason needed for PCI devices, but I don't see why for I2C
>> anything else than just pm_runtime_enable() would be necessary.
>
> You specifically do not need (all) this for PCI devices, but AFAIU for I涎
> devices you do. The runtime PM status of a device is disabled by default
> and the use count is zero, but on ACPI based systems the device is still
> powered on.

Okay, so _get_noresume() and _set_active() would do the thing for ACPI
indeed, but not sure about other platforms. Perhaps _enable(),
_get_sync() would be more general?

Bets regards,
Tomasz

2017-09-20 09:32:27

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Hi Tomasz,

On Wed, Sep 20, 2017 at 05:59:18PM +0900, Tomasz Figa wrote:
> On Wed, Sep 20, 2017 at 5:45 PM, [email protected]
> <[email protected]> wrote:
> > Hi Tomasz,
> >
> > On Wed, Sep 20, 2017 at 12:56:09PM +0900, Tomasz Figa wrote:
> >> Thanks Raj.
> >>
> >> Let me post my comments inline.
> >>
> >> On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
> >> <[email protected]> wrote:
> >> > Adding Tomasz...
> >> >
> >> >> -----Original Message-----
> >> >> From: Mohandass, Divagar
> >> >> Sent: Monday, September 04, 2017 3:29 AM
> >> >> To: [email protected]; [email protected]; [email protected];
> >> >> [email protected]
> >> >> Cc: [email protected]; [email protected]; linux-
> >> >> [email protected]; Mani, Rajmohan <[email protected]>;
> >> >> Mohandass, Divagar <[email protected]>
> >> >> Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
> >> >>
> >> >> Currently the device is kept in D0, there is an opportunity to save power by
> >> >> enabling runtime pm.
> >> >>
> >> >> Device can be daisy chained from PMIC and we can't rely on I2C core for auto
> >> >> resume/suspend. Driver will decide when to resume/suspend.
> >> >>
> >> >> Signed-off-by: Divagar Mohandass <[email protected]>
> >> >> ---
> >> >> drivers/misc/eeprom/at24.c | 38
> >> >> ++++++++++++++++++++++++++++++++++++++
> >> >> 1 file changed, 38 insertions(+)
> >> >>
> >> >> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index
> >> >> 2199c42..d718a7a 100644
> >> >> --- a/drivers/misc/eeprom/at24.c
> >> >> +++ b/drivers/misc/eeprom/at24.c
> >> >> @@ -24,6 +24,7 @@
> >> >> #include <linux/i2c.h>
> >> >> #include <linux/nvmem-provider.h>
> >> >> #include <linux/platform_data/at24.h>
> >> >> +#include <linux/pm_runtime.h>
> >> >>
> >> >> /*
> >> >> * I2C EEPROMs from most vendors are inexpensive and mostly
> >> >> interchangeable.
> >> >> @@ -501,11 +502,21 @@ static ssize_t at24_eeprom_write_i2c(struct
> >> >> at24_data *at24, const char *buf, static int at24_read(void *priv, unsigned int
> >> >> off, void *val, size_t count) {
> >> >> struct at24_data *at24 = priv;
> >> >> + struct i2c_client *client;
> >> >> char *buf = val;
> >> >> + int ret;
> >> >>
> >> >> if (unlikely(!count))
> >> >> return count;
> >> >>
> >> >> + client = at24_translate_offset(at24, &off);
> >> >> +
> >> >> + ret = pm_runtime_get_sync(&client->dev);
> >> >> + if (ret < 0) {
> >> >> + pm_runtime_put_noidle(&client->dev);
> >> >> + return ret;
> >> >> + }
> >> >> +
> >> >> /*
> >> >> * Read data from chip, protecting against concurrent updates
> >> >> * from this host, but not from other I2C masters.
> >> >> @@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned int off, void
> >> >> *val, size_t count)
> >> >> status = at24->read_func(at24, buf, off, count);
> >> >> if (status < 0) {
> >> >> mutex_unlock(&at24->lock);
> >> >> + pm_runtime_put(&client->dev);
> >> >> return status;
> >> >> }
> >> >> buf += status;
> >> >> @@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned int off, void
> >> >> *val, size_t count)
> >> >>
> >> >> mutex_unlock(&at24->lock);
> >> >>
> >> >> + pm_runtime_put(&client->dev);
> >> >> +
> >> >> return 0;
> >> >> }
> >> >>
> >> >> static int at24_write(void *priv, unsigned int off, void *val, size_t count) {
> >> >> struct at24_data *at24 = priv;
> >> >> + struct i2c_client *client;
> >> >> char *buf = val;
> >> >> + int ret;
> >> >>
> >> >> if (unlikely(!count))
> >> >> return -EINVAL;
> >> >>
> >> >> + client = at24_translate_offset(at24, &off);
> >> >> +
> >> >> + ret = pm_runtime_get_sync(&client->dev);
> >> >> + if (ret < 0) {
> >> >> + pm_runtime_put_noidle(&client->dev);
> >> >> + return ret;
> >> >> + }
> >> >> +
> >> >> /*
> >> >> * Write data to chip, protecting against concurrent updates
> >> >> * from this host, but not from other I2C masters.
> >> >> @@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned int off, void
> >> >> *val, size_t count)
> >> >> status = at24->write_func(at24, buf, off, count);
> >> >> if (status < 0) {
> >> >> mutex_unlock(&at24->lock);
> >> >> + pm_runtime_put(&client->dev);
> >> >> return status;
> >> >> }
> >> >> buf += status;
> >> >> @@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned int off, void
> >> >> *val, size_t count)
> >> >>
> >> >> mutex_unlock(&at24->lock);
> >> >>
> >> >> + pm_runtime_put(&client->dev);
> >> >> +
> >> >> return 0;
> >> >> }
> >> >>
> >> >> @@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
> >> >> struct i2c_device_id *id)
> >> >>
> >> >> i2c_set_clientdata(client, at24);
> >> >>
> >> >> + /* enable runtime pm */
> >> >> + pm_runtime_get_noresume(&client->dev);
> >> >> + pm_runtime_set_active(&client->dev);
> >> >> + pm_runtime_enable(&client->dev);
> >>
> >> Do we need this get_noresume/set_active dance? I remember it was for
> >> some reason needed for PCI devices, but I don't see why for I2C
> >> anything else than just pm_runtime_enable() would be necessary.
> >
> > You specifically do not need (all) this for PCI devices, but AFAIU for I涎
> > devices you do. The runtime PM status of a device is disabled by default
> > and the use count is zero, but on ACPI based systems the device is still
> > powered on.
>
> Okay, so _get_noresume() and _set_active() would do the thing for ACPI
> indeed, but not sure about other platforms. Perhaps _enable(),
> _get_sync() would be more general?

What I ended up doing in e.g. the smiapp driver was to explicitly power the
device on first and then enable runtime PM. (See
drivers/media/i2c/smiapp/smiapp-core.c .) This approach works even if
CONFIG_PM is disabled, both on DT and ACPI.

--
Regards,

Sakari Ailus
e-mail: [email protected]

2017-09-22 16:11:44

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"

On Wed, Sep 20, 2017 at 6:52 AM, Mani, Rajmohan <[email protected]> wrote:
> Adding Tomasz...

Please, don't top post.
Better to resend entire series with all stakeholders included.

>> Obtain the size of the EEPROM chip from DT if the "size" property is specified
>> for the device.
>>

I guess it lacks
Suggested-by: Andy Shevchenko <[email protected]>

Other than that, looks good to me!

Reviewed-by: Andy Shevchenko <[email protected]>


Wolfram, the binding is ACKed by Rob and this one is in a good shape.
Moreover, it seems like a demand for the property since some IoT stuff
would like to use the driver on ACPI enabled platforms with different
sizes.

Can you go ahead and apply first two patches? It would be really appreciated.

>> Signed-off-by: Divagar Mohandass <[email protected]>
>> ---
>> drivers/misc/eeprom/at24.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c index
>> 764ff5df..2199c42 100644
>> --- a/drivers/misc/eeprom/at24.c
>> +++ b/drivers/misc/eeprom/at24.c
>> @@ -570,6 +570,10 @@ static void at24_get_pdata(struct device *dev, struct
>> at24_platform_data *chip)
>> if (device_property_present(dev, "read-only"))
>> chip->flags |= AT24_FLAG_READONLY;
>>
>> + err = device_property_read_u32(dev, "size", &val);
>> + if (!err)
>> + chip->byte_len = val;
>> +
>> err = device_property_read_u32(dev, "pagesize", &val);
>> if (!err) {
>> chip->page_size = val;
>> --
>> 1.9.1
>



--
With Best Regards,
Andy Shevchenko

2017-09-26 05:29:22

by Mohandass, Divagar

[permalink] [raw]
Subject: RE: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"

Hi Andy,

Sorry missed the 'Suggested-by' tag. Can I resend the v6 with this change, so that Wolfram can pick these patches ?

---
^Divagar

>-----Original Message-----
>From: Andy Shevchenko [mailto:[email protected]]
>Sent: Friday, September 22, 2017 9:42 PM
>To: Mani, Rajmohan <[email protected]>
>Cc: Mohandass, Divagar <[email protected]>;
>[email protected]; [email protected]; [email protected];
>[email protected]; [email protected]; [email protected];
>[email protected]; [email protected]
>Subject: Re: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom
>device property "size"
>
>On Wed, Sep 20, 2017 at 6:52 AM, Mani, Rajmohan
><[email protected]> wrote:
>> Adding Tomasz...
>
>Please, don't top post.
>Better to resend entire series with all stakeholders included.
>
>>> Obtain the size of the EEPROM chip from DT if the "size" property is
>>> specified for the device.
>>>
>
>I guess it lacks
>Suggested-by: Andy Shevchenko <[email protected]>
>
>Other than that, looks good to me!
>
>Reviewed-by: Andy Shevchenko <[email protected]>
>
>
>Wolfram, the binding is ACKed by Rob and this one is in a good shape.
>Moreover, it seems like a demand for the property since some IoT stuff
>would like to use the driver on ACPI enabled platforms with different sizes.
>
>Can you go ahead and apply first two patches? It would be really appreciated.
>
>>> Signed-off-by: Divagar Mohandass <[email protected]>
>>> ---
>>> drivers/misc/eeprom/at24.c | 4 ++++
>>> 1 file changed, 4 insertions(+)
>>>
>>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
>>> index
>>> 764ff5df..2199c42 100644
>>> --- a/drivers/misc/eeprom/at24.c
>>> +++ b/drivers/misc/eeprom/at24.c
>>> @@ -570,6 +570,10 @@ static void at24_get_pdata(struct device *dev,
>>> struct at24_platform_data *chip)
>>> if (device_property_present(dev, "read-only"))
>>> chip->flags |= AT24_FLAG_READONLY;
>>>
>>> + err = device_property_read_u32(dev, "size", &val);
>>> + if (!err)
>>> + chip->byte_len = val;
>>> +
>>> err = device_property_read_u32(dev, "pagesize", &val);
>>> if (!err) {
>>> chip->page_size = val;
>>> --
>>> 1.9.1
>>
>
>
>
>--
>With Best Regards,
>Andy Shevchenko

2017-09-26 05:29:34

by Mohandass, Divagar

[permalink] [raw]
Subject: RE: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Hi Sakari & Tomas,

Are you ok with the current revision, let me know if any changes are needed.

---
^Divagar

>-----Original Message-----
>From: [email protected] [mailto:[email protected]]
>Sent: Wednesday, September 20, 2017 3:02 PM
>To: Tomasz Figa <[email protected]>
>Cc: Mani, Rajmohan <[email protected]>; Mohandass, Divagar
><[email protected]>; [email protected];
>[email protected]; [email protected]; [email protected];
>[email protected]; [email protected];
>[email protected]
>Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>
>Hi Tomasz,
>
>On Wed, Sep 20, 2017 at 05:59:18PM +0900, Tomasz Figa wrote:
>> On Wed, Sep 20, 2017 at 5:45 PM, [email protected]
>> <[email protected]> wrote:
>> > Hi Tomasz,
>> >
>> > On Wed, Sep 20, 2017 at 12:56:09PM +0900, Tomasz Figa wrote:
>> >> Thanks Raj.
>> >>
>> >> Let me post my comments inline.
>> >>
>> >> On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
>> >> <[email protected]> wrote:
>> >> > Adding Tomasz...
>> >> >
>> >> >> -----Original Message-----
>> >> >> From: Mohandass, Divagar
>> >> >> Sent: Monday, September 04, 2017 3:29 AM
>> >> >> To: [email protected]; [email protected]; wsa@the-
>dreams.de;
>> >> >> [email protected]
>> >> >> Cc: [email protected]; [email protected];
>> >> >> linux- [email protected]; Mani, Rajmohan
>> >> >> <[email protected]>; Mohandass, Divagar
>> >> >> <[email protected]>
>> >> >> Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>> >> >>
>> >> >> Currently the device is kept in D0, there is an opportunity to
>> >> >> save power by enabling runtime pm.
>> >> >>
>> >> >> Device can be daisy chained from PMIC and we can't rely on I2C
>> >> >> core for auto resume/suspend. Driver will decide when to
>resume/suspend.
>> >> >>
>> >> >> Signed-off-by: Divagar Mohandass <[email protected]>
>> >> >> ---
>> >> >> drivers/misc/eeprom/at24.c | 38
>> >> >> ++++++++++++++++++++++++++++++++++++++
>> >> >> 1 file changed, 38 insertions(+)
>> >> >>
>> >> >> diff --git a/drivers/misc/eeprom/at24.c
>> >> >> b/drivers/misc/eeprom/at24.c index 2199c42..d718a7a 100644
>> >> >> --- a/drivers/misc/eeprom/at24.c
>> >> >> +++ b/drivers/misc/eeprom/at24.c
>> >> >> @@ -24,6 +24,7 @@
>> >> >> #include <linux/i2c.h>
>> >> >> #include <linux/nvmem-provider.h> #include
>> >> >> <linux/platform_data/at24.h>
>> >> >> +#include <linux/pm_runtime.h>
>> >> >>
>> >> >> /*
>> >> >> * I2C EEPROMs from most vendors are inexpensive and mostly
>> >> >> interchangeable.
>> >> >> @@ -501,11 +502,21 @@ static ssize_t
>> >> >> at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
>> >> >> static int at24_read(void *priv, unsigned int off, void *val, size_t
>count) {
>> >> >> struct at24_data *at24 = priv;
>> >> >> + struct i2c_client *client;
>> >> >> char *buf = val;
>> >> >> + int ret;
>> >> >>
>> >> >> if (unlikely(!count))
>> >> >> return count;
>> >> >>
>> >> >> + client = at24_translate_offset(at24, &off);
>> >> >> +
>> >> >> + ret = pm_runtime_get_sync(&client->dev);
>> >> >> + if (ret < 0) {
>> >> >> + pm_runtime_put_noidle(&client->dev);
>> >> >> + return ret;
>> >> >> + }
>> >> >> +
>> >> >> /*
>> >> >> * Read data from chip, protecting against concurrent updates
>> >> >> * from this host, but not from other I2C masters.
>> >> >> @@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned
>> >> >> int off, void *val, size_t count)
>> >> >> status = at24->read_func(at24, buf, off, count);
>> >> >> if (status < 0) {
>> >> >> mutex_unlock(&at24->lock);
>> >> >> + pm_runtime_put(&client->dev);
>> >> >> return status;
>> >> >> }
>> >> >> buf += status;
>> >> >> @@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned
>> >> >> int off, void *val, size_t count)
>> >> >>
>> >> >> mutex_unlock(&at24->lock);
>> >> >>
>> >> >> + pm_runtime_put(&client->dev);
>> >> >> +
>> >> >> return 0;
>> >> >> }
>> >> >>
>> >> >> static int at24_write(void *priv, unsigned int off, void *val, size_t
>count) {
>> >> >> struct at24_data *at24 = priv;
>> >> >> + struct i2c_client *client;
>> >> >> char *buf = val;
>> >> >> + int ret;
>> >> >>
>> >> >> if (unlikely(!count))
>> >> >> return -EINVAL;
>> >> >>
>> >> >> + client = at24_translate_offset(at24, &off);
>> >> >> +
>> >> >> + ret = pm_runtime_get_sync(&client->dev);
>> >> >> + if (ret < 0) {
>> >> >> + pm_runtime_put_noidle(&client->dev);
>> >> >> + return ret;
>> >> >> + }
>> >> >> +
>> >> >> /*
>> >> >> * Write data to chip, protecting against concurrent updates
>> >> >> * from this host, but not from other I2C masters.
>> >> >> @@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned
>> >> >> int off, void *val, size_t count)
>> >> >> status = at24->write_func(at24, buf, off, count);
>> >> >> if (status < 0) {
>> >> >> mutex_unlock(&at24->lock);
>> >> >> + pm_runtime_put(&client->dev);
>> >> >> return status;
>> >> >> }
>> >> >> buf += status;
>> >> >> @@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned
>> >> >> int off, void *val, size_t count)
>> >> >>
>> >> >> mutex_unlock(&at24->lock);
>> >> >>
>> >> >> + pm_runtime_put(&client->dev);
>> >> >> +
>> >> >> return 0;
>> >> >> }
>> >> >>
>> >> >> @@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client
>> >> >> *client, const struct i2c_device_id *id)
>> >> >>
>> >> >> i2c_set_clientdata(client, at24);
>> >> >>
>> >> >> + /* enable runtime pm */
>> >> >> + pm_runtime_get_noresume(&client->dev);
>> >> >> + pm_runtime_set_active(&client->dev);
>> >> >> + pm_runtime_enable(&client->dev);
>> >>
>> >> Do we need this get_noresume/set_active dance? I remember it was
>> >> for some reason needed for PCI devices, but I don't see why for I2C
>> >> anything else than just pm_runtime_enable() would be necessary.
>> >
>> > You specifically do not need (all) this for PCI devices, but AFAIU
>> > for I涎
>> > devices you do. The runtime PM status of a device is disabled by
>> > default and the use count is zero, but on ACPI based systems the
>> > device is still powered on.
>>
>> Okay, so _get_noresume() and _set_active() would do the thing for ACPI
>> indeed, but not sure about other platforms. Perhaps _enable(),
>> _get_sync() would be more general?
>
>What I ended up doing in e.g. the smiapp driver was to explicitly power the
>device on first and then enable runtime PM. (See
>drivers/media/i2c/smiapp/smiapp-core.c .) This approach works even if
>CONFIG_PM is disabled, both on DT and ACPI.
>
>--
>Regards,
>
>Sakari Ailus
>e-mail: [email protected]

2017-09-26 05:34:04

by Tomasz Figa

[permalink] [raw]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

[+Rafael, Ulf]

On Tue, Sep 26, 2017 at 2:29 PM, Mohandass, Divagar
<[email protected]> wrote:
> Hi Sakari & Tomas,
>
> Are you ok with the current revision, let me know if any changes are needed.

Nope, my concerns have not been addressed, but we need someone from
the PM world to clarify how we should do this to work on all
platforms.

Best regards,
Tomasz

P.S. Please avoid top-posting on mailing lists, it is considered bad manner.

>
> ---
> ^Divagar
>
>>-----Original Message-----
>>From: [email protected] [mailto:[email protected]]
>>Sent: Wednesday, September 20, 2017 3:02 PM
>>To: Tomasz Figa <[email protected]>
>>Cc: Mani, Rajmohan <[email protected]>; Mohandass, Divagar
>><[email protected]>; [email protected];
>>[email protected]; [email protected]; [email protected];
>>[email protected]; [email protected];
>>[email protected]
>>Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>>
>>Hi Tomasz,
>>
>>On Wed, Sep 20, 2017 at 05:59:18PM +0900, Tomasz Figa wrote:
>>> On Wed, Sep 20, 2017 at 5:45 PM, [email protected]
>>> <[email protected]> wrote:
>>> > Hi Tomasz,
>>> >
>>> > On Wed, Sep 20, 2017 at 12:56:09PM +0900, Tomasz Figa wrote:
>>> >> Thanks Raj.
>>> >>
>>> >> Let me post my comments inline.
>>> >>
>>> >> On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
>>> >> <[email protected]> wrote:
>>> >> > Adding Tomasz...
>>> >> >
>>> >> >> -----Original Message-----
>>> >> >> From: Mohandass, Divagar
>>> >> >> Sent: Monday, September 04, 2017 3:29 AM
>>> >> >> To: [email protected]; [email protected]; wsa@the-
>>dreams.de;
>>> >> >> [email protected]
>>> >> >> Cc: [email protected]; [email protected];
>>> >> >> linux- [email protected]; Mani, Rajmohan
>>> >> >> <[email protected]>; Mohandass, Divagar
>>> >> >> <[email protected]>
>>> >> >> Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>>> >> >>
>>> >> >> Currently the device is kept in D0, there is an opportunity to
>>> >> >> save power by enabling runtime pm.
>>> >> >>
>>> >> >> Device can be daisy chained from PMIC and we can't rely on I2C
>>> >> >> core for auto resume/suspend. Driver will decide when to
>>resume/suspend.
>>> >> >>
>>> >> >> Signed-off-by: Divagar Mohandass <[email protected]>
>>> >> >> ---
>>> >> >> drivers/misc/eeprom/at24.c | 38
>>> >> >> ++++++++++++++++++++++++++++++++++++++
>>> >> >> 1 file changed, 38 insertions(+)
>>> >> >>
>>> >> >> diff --git a/drivers/misc/eeprom/at24.c
>>> >> >> b/drivers/misc/eeprom/at24.c index 2199c42..d718a7a 100644
>>> >> >> --- a/drivers/misc/eeprom/at24.c
>>> >> >> +++ b/drivers/misc/eeprom/at24.c
>>> >> >> @@ -24,6 +24,7 @@
>>> >> >> #include <linux/i2c.h>
>>> >> >> #include <linux/nvmem-provider.h> #include
>>> >> >> <linux/platform_data/at24.h>
>>> >> >> +#include <linux/pm_runtime.h>
>>> >> >>
>>> >> >> /*
>>> >> >> * I2C EEPROMs from most vendors are inexpensive and mostly
>>> >> >> interchangeable.
>>> >> >> @@ -501,11 +502,21 @@ static ssize_t
>>> >> >> at24_eeprom_write_i2c(struct at24_data *at24, const char *buf,
>>> >> >> static int at24_read(void *priv, unsigned int off, void *val, size_t
>>count) {
>>> >> >> struct at24_data *at24 = priv;
>>> >> >> + struct i2c_client *client;
>>> >> >> char *buf = val;
>>> >> >> + int ret;
>>> >> >>
>>> >> >> if (unlikely(!count))
>>> >> >> return count;
>>> >> >>
>>> >> >> + client = at24_translate_offset(at24, &off);
>>> >> >> +
>>> >> >> + ret = pm_runtime_get_sync(&client->dev);
>>> >> >> + if (ret < 0) {
>>> >> >> + pm_runtime_put_noidle(&client->dev);
>>> >> >> + return ret;
>>> >> >> + }
>>> >> >> +
>>> >> >> /*
>>> >> >> * Read data from chip, protecting against concurrent updates
>>> >> >> * from this host, but not from other I2C masters.
>>> >> >> @@ -518,6 +529,7 @@ static int at24_read(void *priv, unsigned
>>> >> >> int off, void *val, size_t count)
>>> >> >> status = at24->read_func(at24, buf, off, count);
>>> >> >> if (status < 0) {
>>> >> >> mutex_unlock(&at24->lock);
>>> >> >> + pm_runtime_put(&client->dev);
>>> >> >> return status;
>>> >> >> }
>>> >> >> buf += status;
>>> >> >> @@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned
>>> >> >> int off, void *val, size_t count)
>>> >> >>
>>> >> >> mutex_unlock(&at24->lock);
>>> >> >>
>>> >> >> + pm_runtime_put(&client->dev);
>>> >> >> +
>>> >> >> return 0;
>>> >> >> }
>>> >> >>
>>> >> >> static int at24_write(void *priv, unsigned int off, void *val, size_t
>>count) {
>>> >> >> struct at24_data *at24 = priv;
>>> >> >> + struct i2c_client *client;
>>> >> >> char *buf = val;
>>> >> >> + int ret;
>>> >> >>
>>> >> >> if (unlikely(!count))
>>> >> >> return -EINVAL;
>>> >> >>
>>> >> >> + client = at24_translate_offset(at24, &off);
>>> >> >> +
>>> >> >> + ret = pm_runtime_get_sync(&client->dev);
>>> >> >> + if (ret < 0) {
>>> >> >> + pm_runtime_put_noidle(&client->dev);
>>> >> >> + return ret;
>>> >> >> + }
>>> >> >> +
>>> >> >> /*
>>> >> >> * Write data to chip, protecting against concurrent updates
>>> >> >> * from this host, but not from other I2C masters.
>>> >> >> @@ -550,6 +574,7 @@ static int at24_write(void *priv, unsigned
>>> >> >> int off, void *val, size_t count)
>>> >> >> status = at24->write_func(at24, buf, off, count);
>>> >> >> if (status < 0) {
>>> >> >> mutex_unlock(&at24->lock);
>>> >> >> + pm_runtime_put(&client->dev);
>>> >> >> return status;
>>> >> >> }
>>> >> >> buf += status;
>>> >> >> @@ -559,6 +584,8 @@ static int at24_write(void *priv, unsigned
>>> >> >> int off, void *val, size_t count)
>>> >> >>
>>> >> >> mutex_unlock(&at24->lock);
>>> >> >>
>>> >> >> + pm_runtime_put(&client->dev);
>>> >> >> +
>>> >> >> return 0;
>>> >> >> }
>>> >> >>
>>> >> >> @@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client
>>> >> >> *client, const struct i2c_device_id *id)
>>> >> >>
>>> >> >> i2c_set_clientdata(client, at24);
>>> >> >>
>>> >> >> + /* enable runtime pm */
>>> >> >> + pm_runtime_get_noresume(&client->dev);
>>> >> >> + pm_runtime_set_active(&client->dev);
>>> >> >> + pm_runtime_enable(&client->dev);
>>> >>
>>> >> Do we need this get_noresume/set_active dance? I remember it was
>>> >> for some reason needed for PCI devices, but I don't see why for I2C
>>> >> anything else than just pm_runtime_enable() would be necessary.
>>> >
>>> > You specifically do not need (all) this for PCI devices, but AFAIU
>>> > for I涎
>>> > devices you do. The runtime PM status of a device is disabled by
>>> > default and the use count is zero, but on ACPI based systems the
>>> > device is still powered on.
>>>
>>> Okay, so _get_noresume() and _set_active() would do the thing for ACPI
>>> indeed, but not sure about other platforms. Perhaps _enable(),
>>> _get_sync() would be more general?
>>
>>What I ended up doing in e.g. the smiapp driver was to explicitly power the
>>device on first and then enable runtime PM. (See
>>drivers/media/i2c/smiapp/smiapp-core.c .) This approach works even if
>>CONFIG_PM is disabled, both on DT and ACPI.
>>
>>--
>>Regards,
>>
>>Sakari Ailus
>>e-mail: [email protected]