All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/3] enable eeprom "size" property and runtime pm
@ 2017-09-04 10:28 ` Divagar Mohandass
  0 siblings, 0 replies; 29+ messages in thread
From: Divagar Mohandass @ 2017-09-04 10:28 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wsa, sakari.ailus
  Cc: devicetree, linux-i2c, linux-kernel, rajmohan.mani, Divagar Mohandass

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

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

* [PATCH v6 0/3] enable eeprom "size" property and runtime pm
@ 2017-09-04 10:28 ` Divagar Mohandass
  0 siblings, 0 replies; 29+ messages in thread
From: Divagar Mohandass @ 2017-09-04 10:28 UTC (permalink / raw)
  To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	wsa-z923LK4zBo2bacvFa/9K2g, sakari.ailus-X3B1VOXEql0
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w, Divagar Mohandass

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

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v6 1/3] dt-bindings: add eeprom "size" property
  2017-09-04 10:28 ` Divagar Mohandass
  (?)
@ 2017-09-04 10:28 ` Divagar Mohandass
  2017-09-20  3:52     ` Mani, Rajmohan
  -1 siblings, 1 reply; 29+ messages in thread
From: Divagar Mohandass @ 2017-09-04 10:28 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wsa, sakari.ailus
  Cc: devicetree, linux-i2c, linux-kernel, rajmohan.mani, Divagar Mohandass

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 <divagar.mohandass@intel.com>
Acked-by: Rob Herring <robh@kernel.org>
---
 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

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

* [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"
  2017-09-04 10:28 ` Divagar Mohandass
  (?)
  (?)
@ 2017-09-04 10:28 ` Divagar Mohandass
  2017-09-20  3:52     ` Mani, Rajmohan
  -1 siblings, 1 reply; 29+ messages in thread
From: Divagar Mohandass @ 2017-09-04 10:28 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wsa, sakari.ailus
  Cc: devicetree, linux-i2c, linux-kernel, rajmohan.mani, Divagar Mohandass

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

Signed-off-by: Divagar Mohandass <divagar.mohandass@intel.com>
---
 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

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

* [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-04 10:28 ` Divagar Mohandass
                   ` (2 preceding siblings ...)
  (?)
@ 2017-09-04 10:28 ` Divagar Mohandass
  2017-09-20  3:52   ` Mani, Rajmohan
  -1 siblings, 1 reply; 29+ messages in thread
From: Divagar Mohandass @ 2017-09-04 10:28 UTC (permalink / raw)
  To: robh+dt, mark.rutland, wsa, sakari.ailus
  Cc: devicetree, linux-i2c, linux-kernel, rajmohan.mani, Divagar Mohandass

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 <divagar.mohandass@intel.com>
---
 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

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

* Re: [PATCH v6 0/3] enable eeprom "size" property and runtime pm
  2017-09-04 10:28 ` Divagar Mohandass
                   ` (3 preceding siblings ...)
  (?)
@ 2017-09-05 13:48 ` Sakari Ailus
  2017-09-20  3:51     ` Mani, Rajmohan
  -1 siblings, 1 reply; 29+ messages in thread
From: Sakari Ailus @ 2017-09-05 13:48 UTC (permalink / raw)
  To: Divagar Mohandass
  Cc: robh+dt, mark.rutland, wsa, devicetree, linux-i2c, linux-kernel,
	rajmohan.mani

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 <sakari.ailus@linux.intel.com>

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi

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

* RE: [PATCH v6 0/3] enable eeprom "size" property and runtime pm
@ 2017-09-20  3:51     ` Mani, Rajmohan
  0 siblings, 0 replies; 29+ messages in thread
From: Mani, Rajmohan @ 2017-09-20  3:51 UTC (permalink / raw)
  To: Sakari Ailus, Mohandass, Divagar
  Cc: robh+dt, mark.rutland, wsa, devicetree, linux-i2c, linux-kernel, tfiga

Adding Tomasz...

> -----Original Message-----
> From: Sakari Ailus [mailto:sakari.ailus@iki.fi]
> Sent: Tuesday, September 05, 2017 6:48 AM
> To: Mohandass, Divagar <divagar.mohandass@intel.com>
> Cc: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
> devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>
> 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 <sakari.ailus@linux.intel.com>
> 
> --
> Kind regards,
> 
> Sakari Ailus
> e-mail: sakari.ailus@iki.fi

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

* RE: [PATCH v6 0/3] enable eeprom "size" property and runtime pm
@ 2017-09-20  3:51     ` Mani, Rajmohan
  0 siblings, 0 replies; 29+ messages in thread
From: Mani, Rajmohan @ 2017-09-20  3:51 UTC (permalink / raw)
  To: Sakari Ailus, Mohandass, Divagar
  Cc: robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	wsa-z923LK4zBo2bacvFa/9K2g, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	tfiga-F7+t8E8rja9g9hUCZPvPmw

Adding Tomasz...

> -----Original Message-----
> From: Sakari Ailus [mailto:sakari.ailus-X3B1VOXEql0@public.gmane.org]
> Sent: Tuesday, September 05, 2017 6:48 AM
> To: Mohandass, Divagar <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Cc: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org; mark.rutland-5wv7dgnIgG8@public.gmane.org; wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org;
> devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-
> kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; Mani, Rajmohan <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> 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 <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> 
> --
> Kind regards,
> 
> Sakari Ailus
> e-mail: sakari.ailus-X3B1VOXEql0@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [PATCH v6 1/3] dt-bindings: add eeprom "size" property
@ 2017-09-20  3:52     ` Mani, Rajmohan
  0 siblings, 0 replies; 29+ messages in thread
From: Mani, Rajmohan @ 2017-09-20  3:52 UTC (permalink / raw)
  To: Mohandass, Divagar, robh+dt, mark.rutland, wsa, sakari.ailus
  Cc: devicetree, linux-i2c, linux-kernel, tfiga

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
> sakari.ailus@iki.fi
> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>;
> Mohandass, Divagar <divagar.mohandass@intel.com>
> 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 <divagar.mohandass@intel.com>
> Acked-by: Rob Herring <robh@kernel.org>
> ---
>  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

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

* RE: [PATCH v6 1/3] dt-bindings: add eeprom "size" property
@ 2017-09-20  3:52     ` Mani, Rajmohan
  0 siblings, 0 replies; 29+ messages in thread
From: Mani, Rajmohan @ 2017-09-20  3:52 UTC (permalink / raw)
  To: Mohandass, Divagar, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, wsa-z923LK4zBo2bacvFa/9K2g,
	sakari.ailus-X3B1VOXEql0
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	tfiga-F7+t8E8rja9g9hUCZPvPmw

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org; mark.rutland-5wv7dgnIgG8@public.gmane.org; wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org;
> sakari.ailus-X3B1VOXEql0@public.gmane.org
> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-
> kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; Mani, Rajmohan <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>;
> Mohandass, Divagar <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> 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 <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Acked-by: Rob Herring <robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
> ---
>  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

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"
@ 2017-09-20  3:52     ` Mani, Rajmohan
  0 siblings, 0 replies; 29+ messages in thread
From: Mani, Rajmohan @ 2017-09-20  3:52 UTC (permalink / raw)
  To: Mohandass, Divagar, robh+dt, mark.rutland, wsa, sakari.ailus
  Cc: devicetree, linux-i2c, linux-kernel, tfiga

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
> sakari.ailus@iki.fi
> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>;
> Mohandass, Divagar <divagar.mohandass@intel.com>
> 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 <divagar.mohandass@intel.com>
> ---
>  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

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

* RE: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"
@ 2017-09-20  3:52     ` Mani, Rajmohan
  0 siblings, 0 replies; 29+ messages in thread
From: Mani, Rajmohan @ 2017-09-20  3:52 UTC (permalink / raw)
  To: Mohandass, Divagar, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, wsa-z923LK4zBo2bacvFa/9K2g,
	sakari.ailus-X3B1VOXEql0
  Cc: devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	tfiga-F7+t8E8rja9g9hUCZPvPmw

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org; mark.rutland-5wv7dgnIgG8@public.gmane.org; wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org;
> sakari.ailus-X3B1VOXEql0@public.gmane.org
> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-
> kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; Mani, Rajmohan <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>;
> Mohandass, Divagar <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> 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 <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
>  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

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-04 10:28 ` [PATCH v6 3/3] eeprom: at24: enable runtime pm support Divagar Mohandass
@ 2017-09-20  3:52   ` Mani, Rajmohan
  2017-09-20  3:56       ` Tomasz Figa
  0 siblings, 1 reply; 29+ messages in thread
From: Mani, Rajmohan @ 2017-09-20  3:52 UTC (permalink / raw)
  To: Mohandass, Divagar, robh+dt, mark.rutland, wsa, sakari.ailus
  Cc: devicetree, linux-i2c, linux-kernel, tfiga

Adding Tomasz...

> -----Original Message-----
> From: Mohandass, Divagar
> Sent: Monday, September 04, 2017 3:29 AM
> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
> sakari.ailus@iki.fi
> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>;
> Mohandass, Divagar <divagar.mohandass@intel.com>
> 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 <divagar.mohandass@intel.com>
> ---
>  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

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
@ 2017-09-20  3:56       ` Tomasz Figa
  0 siblings, 0 replies; 29+ messages in thread
From: Tomasz Figa @ 2017-09-20  3:56 UTC (permalink / raw)
  To: Mani, Rajmohan
  Cc: Mohandass, Divagar, robh+dt, mark.rutland, wsa, sakari.ailus,
	devicetree, linux-i2c, linux-kernel

Thanks Raj.

Let me post my comments inline.

On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
<rajmohan.mani@intel.com> wrote:
> Adding Tomasz...
>
>> -----Original Message-----
>> From: Mohandass, Divagar
>> Sent: Monday, September 04, 2017 3:29 AM
>> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
>> sakari.ailus@iki.fi
>> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
>> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>;
>> Mohandass, Divagar <divagar.mohandass@intel.com>
>> 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 <divagar.mohandass@intel.com>
>> ---
>>  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

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
@ 2017-09-20  3:56       ` Tomasz Figa
  0 siblings, 0 replies; 29+ messages in thread
From: Tomasz Figa @ 2017-09-20  3:56 UTC (permalink / raw)
  To: Mani, Rajmohan
  Cc: Mohandass, Divagar, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, wsa-z923LK4zBo2bacvFa/9K2g,
	sakari.ailus-X3B1VOXEql0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

Thanks Raj.

Let me post my comments inline.

On Wed, Sep 20, 2017 at 12:52 PM, Mani, Rajmohan
<rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:
> Adding Tomasz...
>
>> -----Original Message-----
>> From: Mohandass, Divagar
>> Sent: Monday, September 04, 2017 3:29 AM
>> To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org; mark.rutland-5wv7dgnIgG8@public.gmane.org; wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org;
>> sakari.ailus-X3B1VOXEql0@public.gmane.org
>> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-
>> kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; Mani, Rajmohan <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>;
>> Mohandass, Divagar <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>> 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 <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>> ---
>>  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
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-20  3:56       ` Tomasz Figa
  (?)
@ 2017-09-20  8:45       ` sakari.ailus
  2017-09-20  8:59         ` Tomasz Figa
  2017-10-03 14:23         ` sakari.ailus
  -1 siblings, 2 replies; 29+ messages in thread
From: sakari.ailus @ 2017-09-20  8:45 UTC (permalink / raw)
  To: Tomasz Figa
  Cc: Mani, Rajmohan, Mohandass, Divagar, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg

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
> <rajmohan.mani@intel.com> wrote:
> > Adding Tomasz...
> >
> >> -----Original Message-----
> >> From: Mohandass, Divagar
> >> Sent: Monday, September 04, 2017 3:29 AM
> >> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
> >> sakari.ailus@iki.fi
> >> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
> >> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>;
> >> Mohandass, Divagar <divagar.mohandass@intel.com>
> >> 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 <divagar.mohandass@intel.com>
> >> ---
> >>  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: sakari.ailus@iki.fi

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-20  8:45       ` sakari.ailus
@ 2017-09-20  8:59         ` Tomasz Figa
  2017-09-20  9:32           ` sakari.ailus
  2017-10-03 14:23         ` sakari.ailus
  1 sibling, 1 reply; 29+ messages in thread
From: Tomasz Figa @ 2017-09-20  8:59 UTC (permalink / raw)
  To: sakari.ailus
  Cc: Mani, Rajmohan, Mohandass, Divagar, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg

On Wed, Sep 20, 2017 at 5:45 PM, sakari.ailus@iki.fi
<sakari.ailus@iki.fi> 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
>> <rajmohan.mani@intel.com> wrote:
>> > Adding Tomasz...
>> >
>> >> -----Original Message-----
>> >> From: Mohandass, Divagar
>> >> Sent: Monday, September 04, 2017 3:29 AM
>> >> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
>> >> sakari.ailus@iki.fi
>> >> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
>> >> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>;
>> >> Mohandass, Divagar <divagar.mohandass@intel.com>
>> >> 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 <divagar.mohandass@intel.com>
>> >> ---
>> >>  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

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-20  8:59         ` Tomasz Figa
@ 2017-09-20  9:32           ` sakari.ailus
  2017-09-26  5:29             ` Mohandass, Divagar
  2017-10-03 13:51             ` sakari.ailus
  0 siblings, 2 replies; 29+ messages in thread
From: sakari.ailus @ 2017-09-20  9:32 UTC (permalink / raw)
  To: Tomasz Figa
  Cc: Mani, Rajmohan, Mohandass, Divagar, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg

Hi Tomasz,

On Wed, Sep 20, 2017 at 05:59:18PM +0900, Tomasz Figa wrote:
> On Wed, Sep 20, 2017 at 5:45 PM, sakari.ailus@iki.fi
> <sakari.ailus@iki.fi> 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
> >> <rajmohan.mani@intel.com> wrote:
> >> > Adding Tomasz...
> >> >
> >> >> -----Original Message-----
> >> >> From: Mohandass, Divagar
> >> >> Sent: Monday, September 04, 2017 3:29 AM
> >> >> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
> >> >> sakari.ailus@iki.fi
> >> >> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org; linux-
> >> >> kernel@vger.kernel.org; Mani, Rajmohan <rajmohan.mani@intel.com>;
> >> >> Mohandass, Divagar <divagar.mohandass@intel.com>
> >> >> 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 <divagar.mohandass@intel.com>
> >> >> ---
> >> >>  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: sakari.ailus@iki.fi

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

* Re: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"
@ 2017-09-22 16:11       ` Andy Shevchenko
  0 siblings, 0 replies; 29+ messages in thread
From: Andy Shevchenko @ 2017-09-22 16:11 UTC (permalink / raw)
  To: Mani, Rajmohan
  Cc: Mohandass, Divagar, robh+dt, mark.rutland, wsa, sakari.ailus,
	devicetree, linux-i2c, linux-kernel, tfiga

On Wed, Sep 20, 2017 at 6:52 AM, Mani, Rajmohan <rajmohan.mani@intel.com> 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 <andriy.shevchenko@linux.intel.com>

Other than that, looks good to me!

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>


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 <divagar.mohandass@intel.com>
>> ---
>>  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

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

* Re: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"
@ 2017-09-22 16:11       ` Andy Shevchenko
  0 siblings, 0 replies; 29+ messages in thread
From: Andy Shevchenko @ 2017-09-22 16:11 UTC (permalink / raw)
  To: Mani, Rajmohan
  Cc: Mohandass, Divagar, robh+dt-DgEjT+Ai2ygdnm+yROfE0A,
	mark.rutland-5wv7dgnIgG8, wsa-z923LK4zBo2bacvFa/9K2g,
	sakari.ailus-X3B1VOXEql0, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	tfiga-F7+t8E8rja9g9hUCZPvPmw

On Wed, Sep 20, 2017 at 6:52 AM, Mani, Rajmohan <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 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 <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>

Other than that, looks good to me!

Reviewed-by: Andy Shevchenko <andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>


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 <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>> ---
>>  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
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* RE: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"
  2017-09-22 16:11       ` Andy Shevchenko
  (?)
@ 2017-09-26  5:29       ` Mohandass, Divagar
  -1 siblings, 0 replies; 29+ messages in thread
From: Mohandass, Divagar @ 2017-09-26  5:29 UTC (permalink / raw)
  To: Andy Shevchenko, Mani, Rajmohan
  Cc: robh+dt, mark.rutland, wsa, sakari.ailus, devicetree, linux-i2c,
	linux-kernel, tfiga

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:andy.shevchenko@gmail.com]
>Sent: Friday, September 22, 2017 9:42 PM
>To: Mani, Rajmohan <rajmohan.mani@intel.com>
>Cc: Mohandass, Divagar <divagar.mohandass@intel.com>;
>robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-dreams.de;
>sakari.ailus@iki.fi; devicetree@vger.kernel.org; linux-i2c@vger.kernel.org;
>linux-kernel@vger.kernel.org; tfiga@chromium.org
>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
><rajmohan.mani@intel.com> 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 <andriy.shevchenko@linux.intel.com>
>
>Other than that, looks good to me!
>
>Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
>
>
>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 <divagar.mohandass@intel.com>
>>> ---
>>>  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

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

* RE: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-20  9:32           ` sakari.ailus
@ 2017-09-26  5:29             ` Mohandass, Divagar
  2017-09-26  5:33                 ` Tomasz Figa
  2017-10-03 13:51             ` sakari.ailus
  1 sibling, 1 reply; 29+ messages in thread
From: Mohandass, Divagar @ 2017-09-26  5:29 UTC (permalink / raw)
  To: sakari.ailus, Tomasz Figa
  Cc: Mani, Rajmohan, robh+dt, mark.rutland, wsa, devicetree,
	linux-i2c, linux-kernel, mika.westerberg

Hi Sakari & Tomas,

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

---
^Divagar

>-----Original Message-----
>From: sakari.ailus@iki.fi [mailto:sakari.ailus@iki.fi]
>Sent: Wednesday, September 20, 2017 3:02 PM
>To: Tomasz Figa <tfiga@chromium.org>
>Cc: Mani, Rajmohan <rajmohan.mani@intel.com>; Mohandass, Divagar
><divagar.mohandass@intel.com>; robh+dt@kernel.org;
>mark.rutland@arm.com; wsa@the-dreams.de; devicetree@vger.kernel.org;
>linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org;
>mika.westerberg@linux.intel.com
>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, sakari.ailus@iki.fi
>> <sakari.ailus@iki.fi> 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
>> >> <rajmohan.mani@intel.com> wrote:
>> >> > Adding Tomasz...
>> >> >
>> >> >> -----Original Message-----
>> >> >> From: Mohandass, Divagar
>> >> >> Sent: Monday, September 04, 2017 3:29 AM
>> >> >> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-
>dreams.de;
>> >> >> sakari.ailus@iki.fi
>> >> >> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org;
>> >> >> linux- kernel@vger.kernel.org; Mani, Rajmohan
>> >> >> <rajmohan.mani@intel.com>; Mohandass, Divagar
>> >> >> <divagar.mohandass@intel.com>
>> >> >> 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 <divagar.mohandass@intel.com>
>> >> >> ---
>> >> >>  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: sakari.ailus@iki.fi

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
@ 2017-09-26  5:33                 ` Tomasz Figa
  0 siblings, 0 replies; 29+ messages in thread
From: Tomasz Figa @ 2017-09-26  5:33 UTC (permalink / raw)
  To: Mohandass, Divagar
  Cc: sakari.ailus, Mani, Rajmohan, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg,
	Rafael J. Wysocki, Ulf Hansson

[+Rafael, Ulf]

On Tue, Sep 26, 2017 at 2:29 PM, Mohandass, Divagar
<divagar.mohandass@intel.com> 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: sakari.ailus@iki.fi [mailto:sakari.ailus@iki.fi]
>>Sent: Wednesday, September 20, 2017 3:02 PM
>>To: Tomasz Figa <tfiga@chromium.org>
>>Cc: Mani, Rajmohan <rajmohan.mani@intel.com>; Mohandass, Divagar
>><divagar.mohandass@intel.com>; robh+dt@kernel.org;
>>mark.rutland@arm.com; wsa@the-dreams.de; devicetree@vger.kernel.org;
>>linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org;
>>mika.westerberg@linux.intel.com
>>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, sakari.ailus@iki.fi
>>> <sakari.ailus@iki.fi> 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
>>> >> <rajmohan.mani@intel.com> wrote:
>>> >> > Adding Tomasz...
>>> >> >
>>> >> >> -----Original Message-----
>>> >> >> From: Mohandass, Divagar
>>> >> >> Sent: Monday, September 04, 2017 3:29 AM
>>> >> >> To: robh+dt@kernel.org; mark.rutland@arm.com; wsa@the-
>>dreams.de;
>>> >> >> sakari.ailus@iki.fi
>>> >> >> Cc: devicetree@vger.kernel.org; linux-i2c@vger.kernel.org;
>>> >> >> linux- kernel@vger.kernel.org; Mani, Rajmohan
>>> >> >> <rajmohan.mani@intel.com>; Mohandass, Divagar
>>> >> >> <divagar.mohandass@intel.com>
>>> >> >> 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 <divagar.mohandass@intel.com>
>>> >> >> ---
>>> >> >>  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: sakari.ailus@iki.fi

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
@ 2017-09-26  5:33                 ` Tomasz Figa
  0 siblings, 0 replies; 29+ messages in thread
From: Tomasz Figa @ 2017-09-26  5:33 UTC (permalink / raw)
  To: Mohandass, Divagar
  Cc: sakari.ailus-X3B1VOXEql0, Mani, Rajmohan,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	wsa-z923LK4zBo2bacvFa/9K2g, devicetree-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	mika.westerberg-VuQAYsv1563Yd54FQh9/CA, Rafael J. Wysocki,
	Ulf Hansson

[+Rafael, Ulf]

On Tue, Sep 26, 2017 at 2:29 PM, Mohandass, Divagar
<divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> 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: sakari.ailus-X3B1VOXEql0@public.gmane.org [mailto:sakari.ailus-X3B1VOXEql0@public.gmane.org]
>>Sent: Wednesday, September 20, 2017 3:02 PM
>>To: Tomasz Figa <tfiga-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>>Cc: Mani, Rajmohan <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>; Mohandass, Divagar
>><divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>; robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org;
>>mark.rutland-5wv7dgnIgG8@public.gmane.org; wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org; devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org;
>>linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org;
>>mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
>>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, sakari.ailus-X3B1VOXEql0@public.gmane.org
>>> <sakari.ailus-X3B1VOXEql0@public.gmane.org> 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
>>> >> <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:
>>> >> > Adding Tomasz...
>>> >> >
>>> >> >> -----Original Message-----
>>> >> >> From: Mohandass, Divagar
>>> >> >> Sent: Monday, September 04, 2017 3:29 AM
>>> >> >> To: robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org; mark.rutland-5wv7dgnIgG8@public.gmane.org; wsa@the-
>>dreams.de;
>>> >> >> sakari.ailus-X3B1VOXEql0@public.gmane.org
>>> >> >> Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org;
>>> >> >> linux- kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; Mani, Rajmohan
>>> >> >> <rajmohan.mani-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>; Mohandass, Divagar
>>> >> >> <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>>> >> >> 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 <divagar.mohandass-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>>> >> >> ---
>>> >> >>  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: sakari.ailus-X3B1VOXEql0@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-20  9:32           ` sakari.ailus
  2017-09-26  5:29             ` Mohandass, Divagar
@ 2017-10-03 13:51             ` sakari.ailus
  2017-10-09  3:14               ` Mohandass, Divagar
  1 sibling, 1 reply; 29+ messages in thread
From: sakari.ailus @ 2017-10-03 13:51 UTC (permalink / raw)
  To: Tomasz Figa
  Cc: Mani, Rajmohan, Mohandass, Divagar, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg, linux-pm

Hi Tomasz,

On Wed, Sep 20, 2017 at 12:32:22PM +0300, sakari.ailus@iki.fi wrote:
> > >> >> @@ -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.

pm_runtime_get_noresume() + pm_runtime_put() can be replaced by a single
pm_runtime_idle() call (where pm_runtime_put() was). pm_runtime_enable() is
required to enable runtime PM for a device.

pm_runtime_allow() may be omitted but then to make the runtime PM framework
to make the power state transitions this needs to be configured from the
user space --- which I don't think is intended.

Cc linux-pm, too.

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-09-20  8:45       ` sakari.ailus
  2017-09-20  8:59         ` Tomasz Figa
@ 2017-10-03 14:23         ` sakari.ailus
  2017-10-10  3:54           ` Tomasz Figa
  1 sibling, 1 reply; 29+ messages in thread
From: sakari.ailus @ 2017-10-03 14:23 UTC (permalink / raw)
  To: Tomasz Figa
  Cc: Mani, Rajmohan, Mohandass, Divagar, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg, linux-pm

On Wed, Sep 20, 2017 at 11:45:20AM +0300, sakari.ailus@iki.fi wrote:
> > >> @@ -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.

I looked at the code and what actually happens here is the runtime_suspend
and runtime_resume callbacks aren't set is that the first pm_runtime_put()
call itself succeeds because checking the the runtime_suspend callback will
be done in the work queue function. This leaves the device in RPM_ACTIVE
state, which I don't think is a problem since the driver did not have
explicit functions to control the device power state.

Further pm_runtime_put() and pm_runtime_get() calls will succeed because
the device is in RPM_ACTIVE state.

So I see no reason to set the callbacks if they would not actually control
regulators, clocks or GPIOs required by the device.

Cc linux-pm.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi

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

* RE: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-10-03 13:51             ` sakari.ailus
@ 2017-10-09  3:14               ` Mohandass, Divagar
  2017-10-10  3:55                 ` Tomasz Figa
  0 siblings, 1 reply; 29+ messages in thread
From: Mohandass, Divagar @ 2017-10-09  3:14 UTC (permalink / raw)
  To: 'sakari.ailus@iki.fi', Tomasz Figa
  Cc: Mani, Rajmohan, robh+dt, mark.rutland, wsa, devicetree,
	linux-i2c, linux-kernel, mika.westerberg, linux-pm

Hi Tomasz,

>-----Original Message-----
>From: sakari.ailus@iki.fi [mailto:sakari.ailus@iki.fi]
>Sent: Tuesday, October 03, 2017 7:21 PM
>To: Tomasz Figa <tfiga@chromium.org>
>Cc: Mani, Rajmohan <rajmohan.mani@intel.com>; Mohandass, Divagar
><divagar.mohandass@intel.com>; robh+dt@kernel.org;
>mark.rutland@arm.com; wsa@the-dreams.de; devicetree@vger.kernel.org;
>linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org;
>mika.westerberg@linux.intel.com; linux-pm@vger.kernel.org
>Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>
>Hi Tomasz,
>
>On Wed, Sep 20, 2017 at 12:32:22PM +0300, sakari.ailus@iki.fi wrote:
>> > >> >> @@ -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.
>
>pm_runtime_get_noresume() + pm_runtime_put() can be replaced by a single
>pm_runtime_idle() call (where pm_runtime_put() was). pm_runtime_enable()
>is required to enable runtime PM for a device.

Verified the change suggested by Sakari. 
Let me know I can send a updated patch version with this change.

>
>pm_runtime_allow() may be omitted but then to make the runtime PM
>framework to make the power state transitions this needs to be configured
>from the user space --- which I don't think is intended.
>
>Cc linux-pm, too.
>
>--
>Regards,
>
>Sakari Ailus
>e-mail: sakari.ailus@iki.fi

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-10-03 14:23         ` sakari.ailus
@ 2017-10-10  3:54           ` Tomasz Figa
  0 siblings, 0 replies; 29+ messages in thread
From: Tomasz Figa @ 2017-10-10  3:54 UTC (permalink / raw)
  To: sakari.ailus
  Cc: Mani, Rajmohan, Mohandass, Divagar, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg, linux-pm

On Tue, Oct 3, 2017 at 11:23 PM, sakari.ailus@iki.fi
<sakari.ailus@iki.fi> wrote:
> On Wed, Sep 20, 2017 at 11:45:20AM +0300, sakari.ailus@iki.fi wrote:
>> > >> @@ -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.
>>
>> >
>> > 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.
>
> I looked at the code and what actually happens here is the runtime_suspend
> and runtime_resume callbacks aren't set is that the first pm_runtime_put()
> call itself succeeds because checking the the runtime_suspend callback will
> be done in the work queue function. This leaves the device in RPM_ACTIVE
> state, which I don't think is a problem since the driver did not have
> explicit functions to control the device power state.
>
> Further pm_runtime_put() and pm_runtime_get() calls will succeed because
> the device is in RPM_ACTIVE state.
>
> So I see no reason to set the callbacks if they would not actually control
> regulators, clocks or GPIOs required by the device.
>
> Cc linux-pm.

Sounds reasonable. I remember seeing some problems in the past, but
looks like they may be already fixed in current upstream. Thanks for
checking this thoroughly.

Best regards,
Tomasz

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

* Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
  2017-10-09  3:14               ` Mohandass, Divagar
@ 2017-10-10  3:55                 ` Tomasz Figa
  0 siblings, 0 replies; 29+ messages in thread
From: Tomasz Figa @ 2017-10-10  3:55 UTC (permalink / raw)
  To: Mohandass, Divagar
  Cc: sakari.ailus, Mani, Rajmohan, robh+dt, mark.rutland, wsa,
	devicetree, linux-i2c, linux-kernel, mika.westerberg, linux-pm

On Mon, Oct 9, 2017 at 12:14 PM, Mohandass, Divagar
<divagar.mohandass@intel.com> wrote:
> Hi Tomasz,
>
>>-----Original Message-----
>>From: sakari.ailus@iki.fi [mailto:sakari.ailus@iki.fi]
>>Sent: Tuesday, October 03, 2017 7:21 PM
>>To: Tomasz Figa <tfiga@chromium.org>
>>Cc: Mani, Rajmohan <rajmohan.mani@intel.com>; Mohandass, Divagar
>><divagar.mohandass@intel.com>; robh+dt@kernel.org;
>>mark.rutland@arm.com; wsa@the-dreams.de; devicetree@vger.kernel.org;
>>linux-i2c@vger.kernel.org; linux-kernel@vger.kernel.org;
>>mika.westerberg@linux.intel.com; linux-pm@vger.kernel.org
>>Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support
>>
>>Hi Tomasz,
>>
>>On Wed, Sep 20, 2017 at 12:32:22PM +0300, sakari.ailus@iki.fi wrote:
>>> > >> >> @@ -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.
>>
>>pm_runtime_get_noresume() + pm_runtime_put() can be replaced by a single
>>pm_runtime_idle() call (where pm_runtime_put() was). pm_runtime_enable()
>>is required to enable runtime PM for a device.
>
> Verified the change suggested by Sakari.
> Let me know I can send a updated patch version with this change.

Okay, looks like Sakari confirmed that the driver should work fine
without callbacks, so please go ahead. Thanks for patience.

Best regards,
Tomasz

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

end of thread, other threads:[~2017-10-10  3:56 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-04 10:28 [PATCH v6 0/3] enable eeprom "size" property and runtime pm Divagar Mohandass
2017-09-04 10:28 ` Divagar Mohandass
2017-09-04 10:28 ` [PATCH v6 1/3] dt-bindings: add eeprom "size" property Divagar Mohandass
2017-09-20  3:52   ` Mani, Rajmohan
2017-09-20  3:52     ` Mani, Rajmohan
2017-09-04 10:28 ` [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size" Divagar Mohandass
2017-09-20  3:52   ` Mani, Rajmohan
2017-09-20  3:52     ` Mani, Rajmohan
2017-09-22 16:11     ` Andy Shevchenko
2017-09-22 16:11       ` Andy Shevchenko
2017-09-26  5:29       ` Mohandass, Divagar
2017-09-04 10:28 ` [PATCH v6 3/3] eeprom: at24: enable runtime pm support Divagar Mohandass
2017-09-20  3:52   ` Mani, Rajmohan
2017-09-20  3:56     ` Tomasz Figa
2017-09-20  3:56       ` Tomasz Figa
2017-09-20  8:45       ` sakari.ailus
2017-09-20  8:59         ` Tomasz Figa
2017-09-20  9:32           ` sakari.ailus
2017-09-26  5:29             ` Mohandass, Divagar
2017-09-26  5:33               ` Tomasz Figa
2017-09-26  5:33                 ` Tomasz Figa
2017-10-03 13:51             ` sakari.ailus
2017-10-09  3:14               ` Mohandass, Divagar
2017-10-10  3:55                 ` Tomasz Figa
2017-10-03 14:23         ` sakari.ailus
2017-10-10  3:54           ` Tomasz Figa
2017-09-05 13:48 ` [PATCH v6 0/3] enable eeprom "size" property and runtime pm Sakari Ailus
2017-09-20  3:51   ` Mani, Rajmohan
2017-09-20  3:51     ` Mani, Rajmohan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.