Skip to contentSkip to conversation

enable eeprom "size" property and runtime pm

PATCH Superseded Divagar Mohandass 5 participants 22 messages Sep 4, 2017 – Oct 10, 2017

Subsystems (3)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover enable eeprom "size" property and runtime pm

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

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

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

[v2]
- Improved the patch subject.

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

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

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

[v6]
- Addressed comments from Sakari Ailus.

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

 .../devicetree/bindings/eeprom/eeprom.txt          |  2 ++
 drivers/misc/eeprom/at24.c                         | 42 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)
Signature · 1 line
1.9.1
#1 lore raw

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.

---
 Documentation/devicetree/bindings/eeprom/eeprom.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/eeprom/eeprom.txt +2 -0
index 5696eb5..1436569 100644
@@ -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 {
Signature · 1 line
1.9.1
#7 lore raw

PATCH v6 3/3 eeprom: at24: enable runtime pm support

In reply to 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.

---
 drivers/misc/eeprom/at24.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/misc/eeprom/at24.c +38 -0
index 2199c42..d718a7a 100644
@@ -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;
 }
 
Signature · 1 line
1.9.1
#3 lore raw

PATCH v6 2/3 eeprom: at24: add support to fetch eeprom device property "size"

In reply to Divagar Mohandass

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

---
 drivers/misc/eeprom/at24.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/misc/eeprom/at24.c +4 -0
index 764ff5df..2199c42 100644
@@ -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;
Signature · 1 line
1.9.1
Reviewed-by on the v6 series
#20 lore raw
In reply to Divagar Mohandass

Hi Divagar,

Quoted 30 lines · 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.

Quoted 8 lines

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:

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]
#21 lore raw

Adding Tomasz...

Quoted 57 lines

-----Original Message-----
From: Sakari Ailus [mailto:[email protected]]
Sent: Tuesday, September 05, 2017 6:48 AM
To: Mohandass, Divagar <[email protected]>
Cc: [email protected]; [email protected]; wsa-z923LK4zBo2bacvFa/[email protected]; [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>
Subject: Re: [PATCH v6 0/3] enable eeprom "size" property and runtime pm

Hi Divagar,

Quoted 3 lines · 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.

Quoted 3 lines

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.

Quoted 24 lines

[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.

Quoted 8 lines

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:

Quoted 7 lines

--
Kind regards,

Sakari Ailus
e-mail: [email protected]

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

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

In reply to Divagar Mohandass

Adding Tomasz...

Quoted 35 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; wsa-z923LK4zBo2bacvFa/[email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 1/3] dt-bindings: add eeprom "size" property

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

---
 Documentation/devicetree/bindings/eeprom/eeprom.txt | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/eeprom/eeprom.txt +2 -1
index 5696eb5..1436569 100644
@@ -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 {
--
Quoted 1 line

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

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

In reply to Divagar Mohandass

Adding Tomasz...

Quoted 34 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; wsa-z923LK4zBo2bacvFa/[email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device
property "size"

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

---
 drivers/misc/eeprom/at24.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/misc/eeprom/at24.c index renamed from drivers/misc/eeprom/at24.c +0 -0

764ff5df..2199c42 100644

drivers/misc/eeprom/at24.c +4 -0
@@ -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) {
Quoted 3 lines

chip->page_size = val;
--
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

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

In reply to Divagar Mohandass

Adding Tomasz...

Quoted 156 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

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

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

---
 drivers/misc/eeprom/at24.c | 38
++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/misc/eeprom/at24.c index renamed from drivers/misc/eeprom/at24.c +0 -0

2199c42..d718a7a 100644

drivers/misc/eeprom/at24.c +1 -0
@@ -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.

drivers/misc/eeprom/at24.c +0 -0
@@ -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) {

drivers/misc/eeprom/at24.c +11 -0
 	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;
 		}
drivers/misc/eeprom/at24.c +13 -0
 		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;
 		}
drivers/misc/eeprom/at24.c +8 -0
 		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;
drivers/misc/eeprom/at24.c +5 -1
 		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

#9 lore raw

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

Thanks Raj.

Let me post my comments inline.

Quoted 120 lines · Rajmohan

Adding Tomasz...

Quoted 118 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; wsa-z923LK4zBo2bacvFa/[email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

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

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

---
 drivers/misc/eeprom/at24.c | 38
++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/misc/eeprom/at24.c index renamed from drivers/misc/eeprom/at24.c +0 -0

2199c42..d718a7a 100644

drivers/misc/eeprom/at24.c +1 -0
@@ -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.

drivers/misc/eeprom/at24.c +0 -0
@@ -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;
drivers/misc/eeprom/at24.c +11 -0
+     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;
drivers/misc/eeprom/at24.c +13 -0
@@ -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;
drivers/misc/eeprom/at24.c +2 -0
@@ -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)
 
Quoted 6 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 6 lines
drivers/misc/eeprom/at24.c +4 -0
      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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

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

Hi Tomasz,

Quoted 128 lines · Tomasz Figa

Thanks Raj.

Let me post my comments inline.

Quoted 122 lines · Rajmohan

Adding Tomasz...

Quoted 120 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

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

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

---
 drivers/misc/eeprom/at24.c | 38
++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/misc/eeprom/at24.c index renamed from drivers/misc/eeprom/at24.c +0 -0

2199c42..d718a7a 100644

drivers/misc/eeprom/at24.c +1 -0
@@ -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.

drivers/misc/eeprom/at24.c +0 -0
@@ -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;
drivers/misc/eeprom/at24.c +11 -0
+     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;
drivers/misc/eeprom/at24.c +13 -0
@@ -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;
drivers/misc/eeprom/at24.c +2 -0
@@ -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);
 
Quoted 8 lines
Quoted 4 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 4 lines
drivers/misc/eeprom/at24.c +4 -0
+     /* 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.

Quoted 8 lines

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.

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: [email protected]
#11 lore raw

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

Quoted 140 lines · On Wed, Sep 20, 2017 at 5:45 PM, [email protected] <[email protected]>…

Hi Tomasz,

Quoted 128 lines · Tomasz Figa

Thanks Raj.

Let me post my comments inline.

Quoted 122 lines · Rajmohan

Adding Tomasz...

Quoted 120 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

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

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

---
 drivers/misc/eeprom/at24.c | 38
++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/misc/eeprom/at24.c index renamed from drivers/misc/eeprom/at24.c +0 -0

2199c42..d718a7a 100644

drivers/misc/eeprom/at24.c +1 -0
@@ -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.

drivers/misc/eeprom/at24.c +0 -0
@@ -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;
drivers/misc/eeprom/at24.c +11 -0
+     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;
drivers/misc/eeprom/at24.c +13 -0
@@ -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;
drivers/misc/eeprom/at24.c +2 -0
@@ -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);
 
Quoted 8 lines
Quoted 4 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 4 lines
drivers/misc/eeprom/at24.c +4 -0
+     /* 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.

Quoted 4 lines

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

#12 lore raw

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

Hi Tomasz,

Quoted 142 lines · Tomasz Figa
Quoted 140 lines · On Wed, Sep 20, 2017 at 5:45 PM, [email protected] <[email protected]>…

Hi Tomasz,

Quoted 136 lines · Tomasz Figa

Thanks Raj.

Let me post my comments inline.

Quoted 120 lines · Rajmohan

Adding Tomasz...

Quoted 118 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

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

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

---
 drivers/misc/eeprom/at24.c | 38
++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/misc/eeprom/at24.c index renamed from drivers/misc/eeprom/at24.c +0 -0

2199c42..d718a7a 100644

drivers/misc/eeprom/at24.c +1 -0
@@ -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.

drivers/misc/eeprom/at24.c +0 -0
@@ -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;
drivers/misc/eeprom/at24.c +11 -0
+     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;
drivers/misc/eeprom/at24.c +13 -0
@@ -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;
drivers/misc/eeprom/at24.c +2 -0
@@ -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)
 
Quoted 6 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 6 lines
drivers/misc/eeprom/at24.c +4 -0
      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.

Quoted 8 lines
Quoted 4 lines

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.

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: [email protected]
Reviewed-by
#5 lore raw

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

In reply to Mani, Rajmohan
Quoted 1 line · Rajmohan

Adding Tomasz...

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

Quoted 3 lines
Quoted 3 lines

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

I guess it lacks

Other than that, looks good to me!

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.

Quoted 24 lines
Quoted 23 lines
---
 drivers/misc/eeprom/at24.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/misc/eeprom/at24.c index renamed from drivers/misc/eeprom/at24.c +0 -0

764ff5df..2199c42 100644

drivers/misc/eeprom/at24.c +4 -0
@@ -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

Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw

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

Hi Andy,

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

---
^Divagar

Quoted 67 lines

-----Original Message-----
From: Andy Shevchenko [mailto:[email protected]]
Sent: Friday, September 22, 2017 9:42 PM
To: Mani, Rajmohan <[email protected]>
Cc: Mohandass, Divagar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 2/3] eeprom: at24: add support to fetch eeprom device property "size"

Quoted 1 line · Rajmohan

Adding Tomasz...

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

Quoted 3 lines
Quoted 3 lines

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

I guess it lacks

Other than that, looks good to me!

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.

Quoted 15 lines
Quoted 15 lines
---
 drivers/misc/eeprom/at24.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/misc/eeprom/at24.c +0 -0

index
764ff5df..2199c42 100644

drivers/misc/eeprom/at24.c +0 -0
@@ -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;
 
Quoted 10 lines
Quoted 9 lines
drivers/misc/eeprom/at24.c +4 -0
+     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

#13 lore raw

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

In reply to [email protected]

Hi Sakari & Tomas,

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

---
^Divagar

Quoted 181 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 3:02 PM
To: Tomasz Figa <[email protected]>
Cc: Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Hi Tomasz,

Quoted 9 lines · Tomasz Figa
Quoted 7 lines · On Wed, Sep 20, 2017 at 5:45 PM, [email protected] <[email protected]>…

Hi Tomasz,

Quoted 4 lines · Tomasz Figa

Thanks Raj.

Let me post my comments inline.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Rajmohan

Adding Tomasz...

Quoted 4 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; wsa@the-

dreams.de;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

[email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
---
 drivers/misc/eeprom/at24.c | 38
++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
(quoted diff) +0 -0

b/drivers/misc/eeprom/at24.c index 2199c42..d718a7a 100644

drivers/misc/eeprom/at24.c +0 -0
@@ -24,6 +24,7 @@
 #include <linux/i2c.h>
 #include <linux/nvmem-provider.h>  #include

<linux/platform_data/at24.h>
+#include <linux/pm_runtime.h>

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

/*
* I2C EEPROMs from most vendors are inexpensive and mostly
interchangeable.

drivers/misc/eeprom/at24.c +0 -0
@@ -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) {

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
      struct at24_data *at24 = priv;
drivers/misc/eeprom/at24.c +11 -0
+     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;
drivers/misc/eeprom/at24.c +0 -0
@@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned
 int off, void *val, size_t count)
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/misc/eeprom/at24.c static int at24_read(void *priv, unsigned int off, void *val, size_t count)

Quoted 8 lines
drivers/misc/eeprom/at24.c +2 -0
      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) {

Quoted 58 lines
Quoted 52 lines
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
drivers/misc/eeprom/at24.c +11 -0
      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;
drivers/misc/eeprom/at24.c +2 -0
@@ -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);
 
Quoted 8 lines
Quoted 4 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 4 lines
drivers/misc/eeprom/at24.c +4 -0
+     /* 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.

Quoted 5 lines

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.

Quoted 3 lines

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

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

--
Regards,

Sakari Ailus
e-mail: [email protected]

#14 lore raw

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

[+Rafael, Ulf]

Quoted 3 lines · Divagar

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.

Quoted 185 lines

---
^Divagar

Quoted 181 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, September 20, 2017 3:02 PM
To: Tomasz Figa <[email protected]>
Cc: Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>; [email protected]; [email protected]; wsa-z923LK4zBo2bacvFa/[email protected]; [email protected]; [email protected]; [email protected]; mika.westerberg-VuQAYsv1563Yd54FQh9/[email protected]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Hi Tomasz,

Quoted 9 lines · Tomasz Figa
Quoted 7 lines · On Wed, Sep 20, 2017 at 5:45 PM, [email protected]…

Hi Tomasz,

Quoted 4 lines · Tomasz Figa

Thanks Raj.

Let me post my comments inline.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines · Rajmohan

Adding Tomasz...

Quoted 4 lines

-----Original Message-----
From: Mohandass, Divagar
Sent: Monday, September 04, 2017 3:29 AM
To: [email protected]; [email protected]; wsa@the-

dreams.de;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

[email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>
Subject: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
---
 drivers/misc/eeprom/at24.c | 38
++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
(quoted diff) +0 -0

b/drivers/misc/eeprom/at24.c index 2199c42..d718a7a 100644

drivers/misc/eeprom/at24.c +0 -0
@@ -24,6 +24,7 @@
 #include <linux/i2c.h>
 #include <linux/nvmem-provider.h>  #include

<linux/platform_data/at24.h>
+#include <linux/pm_runtime.h>

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

/*
* I2C EEPROMs from most vendors are inexpensive and mostly
interchangeable.

drivers/misc/eeprom/at24.c +0 -0
@@ -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) {

Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
      struct at24_data *at24 = priv;
drivers/misc/eeprom/at24.c +11 -0
+     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;
drivers/misc/eeprom/at24.c +0 -0
@@ -527,17 +539,29 @@ static int at24_read(void *priv, unsigned
 int off, void *val, size_t count)
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/misc/eeprom/at24.c static int at24_read(void *priv, unsigned · line 548

Quoted 8 lines
drivers/misc/eeprom/at24.c +2 -0
      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) {

Quoted 58 lines
Quoted 52 lines
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
drivers/misc/eeprom/at24.c +11 -0
      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;
drivers/misc/eeprom/at24.c +2 -0
@@ -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);
 
Quoted 8 lines
Quoted 4 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client · line 777

Quoted 4 lines
drivers/misc/eeprom/at24.c +4 -0
+     /* 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.

Quoted 5 lines

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.

Quoted 3 lines

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

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

--
Regards,

Sakari Ailus
e-mail: [email protected]

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#15 lore raw

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

In reply to [email protected]

Hi Tomasz,

Quoted 19 lines · On Wed, Sep 20, 2017 at 12:32:22PM +0300, [email protected] wrote:
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/misc/eeprom/at24.c +0 -0
@@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
 struct i2c_device_id *id)
 
      i2c_set_clientdata(client, at24);
 
Quoted 8 lines
Quoted 4 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 4 lines
drivers/misc/eeprom/at24.c +4 -0
+     /* 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.

Quoted 8 lines
Quoted 3 lines

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.

Signature · 4 lines
Regards,

Sakari Ailus
e-mail: [email protected]
#18 lore raw

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

In reply to [email protected]
Quoted 28 lines · On Wed, Sep 20, 2017 at 11:45:20AM +0300, [email protected] wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/misc/eeprom/at24.c +0 -0
@@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
 struct i2c_device_id *id)
 
      i2c_set_clientdata(client, at24);
 
Quoted 8 lines
Quoted 4 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 4 lines
drivers/misc/eeprom/at24.c +4 -0
+     /* 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.

Quoted 8 lines

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.

Quoted 1 line

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.

Signature · 4 lines
Kind regards,

Sakari Ailus
e-mail: [email protected]
#16 lore raw

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

In reply to [email protected]

Hi Tomasz,

Quoted 38 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, October 03, 2017 7:21 PM
To: Tomasz Figa <[email protected]>
Cc: Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Hi Tomasz,

Quoted 24 lines · On Wed, Sep 20, 2017 at 12:32:22PM +0300, [email protected] wrote:
Quoted 23 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client
 *client, const struct i2c_device_id *id)
 
      i2c_set_clientdata(client, at24);
 
Quoted 8 lines
Quoted 4 lines

Review static int at24_probe(struct i2c_client · line 777

Quoted 4 lines
(quoted diff) +4 -0
+     /* 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.

Quoted 5 lines

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?

Quoted 8 lines
Quoted 4 lines

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.

Quoted 12 lines

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: [email protected]

#19 lore raw

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

In reply to [email protected]
Quoted 38 lines · On Tue, Oct 3, 2017 at 11:23 PM, [email protected] <[email protected]>…
Quoted 28 lines · On Wed, Sep 20, 2017 at 11:45:20AM +0300, [email protected] wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/misc/eeprom/at24.c +0 -0
@@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client *client, const
 struct i2c_device_id *id)
 
      i2c_set_clientdata(client, at24);
 
Quoted 8 lines
Quoted 4 lines

drivers/misc/eeprom/at24.c static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 776

Quoted 4 lines
drivers/misc/eeprom/at24.c +4 -0
+     /* 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.

Quoted 8 lines

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.

Quoted 1 line

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.

Quoted 7 lines

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

#17 lore raw

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

In reply to Mohandass, Divagar
Quoted 45 lines · Divagar

Hi Tomasz,

Quoted 43 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Tuesday, October 03, 2017 7:21 PM
To: Tomasz Figa <[email protected]>
Cc: Mani, Rajmohan <[email protected]>; Mohandass, Divagar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v6 3/3] eeprom: at24: enable runtime pm support

Hi Tomasz,

Quoted 28 lines · On Wed, Sep 20, 2017 at 12:32:22PM +0300, [email protected] wrote:
Quoted 20 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -0
@@ -743,11 +770,17 @@ static int at24_probe(struct i2c_client
 *client, const struct i2c_device_id *id)
 
      i2c_set_clientdata(client, at24);
 
Quoted 8 lines
Quoted 4 lines

Review static int at24_probe(struct i2c_client · line 777

Quoted 4 lines
(quoted diff) +4 -0
+     /* 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.

Quoted 5 lines

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.

Quoted 3 lines

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.

Quoted 6 lines
Quoted 3 lines

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