Skip to contentSkip to conversation

ARM: dts: keystone-k2g: Add I2C support for 66AK2G

PATCH Superseded Franklin S Cooper Jr 3 participants 7 messages Sep 8, 2017 – Sep 12, 2017

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover ARM: dts: keystone-k2g: Add I2C support for 66AK2G

Add I2C support to 66AK2G. Primary requirement is to add PM Runtime support to the driver.

This has been tested on following platforms by performing simple i2c test such as i2c detect and reading on board i2c devices:
K2G GP evm
OMAPL138
K2L GP EVM

and boot tested on:
K2E GP EVM
K2HK GP EVM

Version 2 changes:
Moved ordering of pm runtime calls

Version 3 changes:
Dropped first patch since it was pulled in.
Remove clk = NULL statements
Fix error path

Franklin S Cooper Jr (2):
i2c: davinci: Add PM Runtime Support
dt-bindings: i2c: i2c-davinci: Update binding for 66AK2Gx pwr dm
property

 .../devicetree/bindings/i2c/i2c-davinci.txt        | 12 ++++
 drivers/i2c/busses/i2c-davinci.c                   | 64 ++++++++++++++++++----
 2 files changed, 65 insertions(+), 11 deletions(-)
Signature · 1 line
2.9.4.dirty
#1 lore raw

PATCH v3 1/2 i2c: davinci: Add PM Runtime Support

66AK2G has I2C instances that are not apart of the ALWAYS_ON power domain like other Keystone 2 SoCs and OMAPL138. Therefore, pm_runtime is required to insure the power domain used by the specific I2C instance is properly turned on along with its functional clock.

---
Version 3 changes:
Remove several statements that set clk to NULL
Fix error path

 drivers/i2c/busses/i2c-davinci.c | 64 +++++++++++++++++++++++++++++++++-------
 1 file changed, 53 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-davinci.c +53 -11
index b8c4353..57612cb 100644
@@ -36,6 +36,7 @@
 #include <linux/gpio.h>
 #include <linux/of_device.h>
 #include <linux/platform_data/i2c-davinci.h>
+#include <linux/pm_runtime.h>
 
 /* ----- global defines ----------------------------------------------- */
 
@@ -122,6 +123,9 @@
 /* set the SDA GPIO low */
 #define DAVINCI_I2C_DCLR_PDCLR1	BIT(1)
 
+/* timeout for pm runtime autosuspend */
+#define DAVINCI_I2C_PM_TIMEOUT	1000	/* ms */
+
 struct davinci_i2c_dev {
 	struct device           *dev;
 	void __iomem		*base;
@@ -541,10 +545,17 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 
 	dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
 
+	ret = pm_runtime_get_sync(dev->dev);
+	if (ret < 0) {
+		dev_err(dev->dev, "Failed to runtime_get device: %d\n", ret);
+		pm_runtime_put_noidle(dev->dev);
+		return ret;
+	}
+
 	ret = i2c_davinci_wait_bus_not_busy(dev);
 	if (ret < 0) {
 		dev_warn(dev->dev, "timeout waiting for bus ready\n");
-		return ret;
+		goto out;
 	}
 
 	for (i = 0; i < num; i++) {
@@ -552,14 +563,19 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 		dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num,
 			ret);
 		if (ret < 0)
-			return ret;
+			goto out;
 	}
 
+	ret = num;
 #ifdef CONFIG_CPU_FREQ
 	complete(&dev->xfr_complete);
 #endif
 
-	return num;
+out:
+	pm_runtime_mark_last_busy(dev->dev);
+	pm_runtime_put_autosuspend(dev->dev);
+
+	return ret;
 }
 
 static u32 i2c_davinci_func(struct i2c_adapter *adap)
@@ -599,6 +615,9 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
 	int count = 0;
 	u16 w;
 
+	if (pm_runtime_suspended(dev->dev))
+		return IRQ_NONE;
+
 	while ((stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG))) {
 		dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
 		if (count++ == 100) {
@@ -802,12 +821,22 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk))
 		return PTR_ERR(dev->clk);
-	clk_prepare_enable(dev->clk);
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	dev->base = devm_ioremap_resource(&pdev->dev, mem);
 	if (IS_ERR(dev->base)) {
-		r = PTR_ERR(dev->base);
+		return PTR_ERR(dev->base);
+	}
+
+	pm_runtime_set_autosuspend_delay(dev->dev,
+					 DAVINCI_I2C_PM_TIMEOUT);
+	pm_runtime_use_autosuspend(dev->dev);
+
+	pm_runtime_enable(dev->dev);
+
+	r = pm_runtime_get_sync(dev->dev);
+	if (r < 0) {
+		dev_err(dev->dev, "failed to runtime_get device: %d\n", r);
 		goto err_unuse_clocks;
 	}
 
@@ -849,27 +878,40 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	if (r)
 		goto err_unuse_clocks;
 
+	pm_runtime_mark_last_busy(dev->dev);
+	pm_runtime_put_autosuspend(dev->dev);
+
 	return 0;
 
 err_unuse_clocks:
-	clk_disable_unprepare(dev->clk);
-	dev->clk = NULL;
+	pm_runtime_dont_use_autosuspend(dev->dev);
+	pm_runtime_put_sync(dev->dev);
+	pm_runtime_disable(dev->dev);
+
 	return r;
 }
 
 static int davinci_i2c_remove(struct platform_device *pdev)
 {
 	struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
+	int ret;
 
 	i2c_davinci_cpufreq_deregister(dev);
 
 	i2c_del_adapter(&dev->adapter);
 
-	clk_disable_unprepare(dev->clk);
-	dev->clk = NULL;
+	ret = pm_runtime_get_sync(&pdev->dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(&pdev->dev);
+		return ret;
+	}
 
 	davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
 
+	pm_runtime_dont_use_autosuspend(dev->dev);
+	pm_runtime_put_sync(dev->dev);
+	pm_runtime_disable(dev->dev);
+
 	return 0;
 }
 
@@ -880,7 +922,6 @@ static int davinci_i2c_suspend(struct device *dev)
 
 	/* put I2C into reset */
 	davinci_i2c_reset_ctrl(i2c_dev, 0);
-	clk_disable_unprepare(i2c_dev->clk);
 
 	return 0;
 }
@@ -889,7 +930,6 @@ static int davinci_i2c_resume(struct device *dev)
 {
 	struct davinci_i2c_dev *i2c_dev = dev_get_drvdata(dev);
 
-	clk_prepare_enable(i2c_dev->clk);
 	/* take I2C out of reset */
 	davinci_i2c_reset_ctrl(i2c_dev, 1);
 
@@ -899,6 +939,8 @@ static int davinci_i2c_resume(struct device *dev)
 static const struct dev_pm_ops davinci_i2c_pm = {
 	.suspend        = davinci_i2c_suspend,
 	.resume         = davinci_i2c_resume,
+	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
+				      pm_runtime_force_resume)
 };
 
 #define davinci_i2c_pm_ops (&davinci_i2c_pm)
Signature · 1 line
2.9.4.dirty
#6 lore raw

PATCH v3 2/2 dt-bindings: i2c: i2c-davinci: Update binding for 66AK2Gx pwr dm property

In reply to Franklin S Cooper Jr

Add pm-domains property which is required for 66AK2Gx. Also document 66AK2G unique clocks property usage.

---
 Documentation/devicetree/bindings/i2c/i2c-davinci.txt | 12 ++++++++++++
 1 file changed, 12 insertions(+)
Documentation/devicetree/bindings/i2c/i2c-davinci.txt +12 -0
index 5b123e0..64e6e65 100644
@@ -6,6 +6,18 @@ davinci/keystone i2c interface contains.
 Required properties:
 - compatible: "ti,davinci-i2c" or "ti,keystone-i2c";
 - reg : Offset and length of the register set for the device
+- clocks: I2C functional clock phandle.
+	  For 66AK2G this property should be set per binding,
+	  Documentation/devicetree/bindings/clock/ti,sci-clk.txt
+
+SoC-specific Required Properties:
+
+The following are mandatory properties for Keystone 2 66AK2G SoCs only:
+
+- power-domains:	Should contain a phandle to a PM domain provider node
+			and an args specifier containing the I2C device id
+			value. This property is as per the binding,
+			Documentation/devicetree/bindings/soc/ti/sci-pm-domain.txt
 
 Recommended properties :
 - interrupts : standard interrupt property.
Signature · 1 line
2.9.4.dirty
#2 lore raw

Re: [PATCH v3 1/2] i2c: davinci: Add PM Runtime Support

In reply to Franklin S Cooper Jr
Quoted 2 lines · Franklin S Cooper Jr

66AK2G has I2C instances that are not apart of the ALWAYS_ON power domain like other Keystone 2 SoCs and OMAPL138. Therefore, pm_runtime

unlike ?

Quoted 25 lines

is required to insure the power domain used by the specific I2C instance is properly turned on along with its functional clock.

---
Version 3 changes:
Remove several statements that set clk to NULL
Fix error path

 drivers/i2c/busses/i2c-davinci.c | 64 +++++++++++++++++++++++++++++++++-------
 1 file changed, 53 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-davinci.c +3 -2
@@ -802,12 +821,22 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk))
 		return PTR_ERR(dev->clk);
-	clk_prepare_enable(dev->clk);
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	dev->base = devm_ioremap_resource(&pdev->dev, mem);
 	if (IS_ERR(dev->base)) {
-		r = PTR_ERR(dev->base);
+		return PTR_ERR(dev->base);
+	}
+

drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct platform_device *pdev) · line 840

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +9 -0
+	pm_runtime_set_autosuspend_delay(dev->dev,
+					 DAVINCI_I2C_PM_TIMEOUT);
+	pm_runtime_use_autosuspend(dev->dev);
+
+	pm_runtime_enable(dev->dev);
+
+	r = pm_runtime_get_sync(dev->dev);
+	if (r < 0) {
+		dev_err(dev->dev, "failed to runtime_get device: %d\n", r);
 		goto err_unuse_clocks;

You end up doing a pm_runtime_put_sync() on failure here, instead of pm_runtime_put_noidle() like rest of the patch.

May be handle this failure here instead of relying on the goto path.

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +3 -0
 	}
 
@@ -849,27 +878,40 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	if (r)
 		goto err_unuse_clocks;
 
+	pm_runtime_mark_last_busy(dev->dev);
+	pm_runtime_put_autosuspend(dev->dev);
+
 	return 0;

drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct platform_device *pdev) · line 892

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +4 -2
 
 err_unuse_clocks:
-	clk_disable_unprepare(dev->clk);
-	dev->clk = NULL;
+	pm_runtime_dont_use_autosuspend(dev->dev);
+	pm_runtime_put_sync(dev->dev);
+	pm_runtime_disable(dev->dev);
+
 	return r;
 }

Thanks,
Sekhar

#3 lore raw

Re: [PATCH v3 1/2] i2c: davinci: Add PM Runtime Support

Quoted 45 lines · Sekhar Nori
Quoted 2 lines · Franklin S Cooper Jr

66AK2G has I2C instances that are not apart of the ALWAYS_ON power domain like other Keystone 2 SoCs and OMAPL138. Therefore, pm_runtime

unlike ?

Quoted 25 lines

is required to insure the power domain used by the specific I2C instance is properly turned on along with its functional clock.

---
Version 3 changes:
Remove several statements that set clk to NULL
Fix error path

 drivers/i2c/busses/i2c-davinci.c | 64 +++++++++++++++++++++++++++++++++-------
 1 file changed, 53 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-davinci.c +3 -2
@@ -802,12 +821,22 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	dev->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk))
 		return PTR_ERR(dev->clk);
-	clk_prepare_enable(dev->clk);
 
 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	dev->base = devm_ioremap_resource(&pdev->dev, mem);
 	if (IS_ERR(dev->base)) {
-		r = PTR_ERR(dev->base);
+		return PTR_ERR(dev->base);
+	}
+

drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct platform_device *pdev) · line 840

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +9 -0
+	pm_runtime_set_autosuspend_delay(dev->dev,
+					 DAVINCI_I2C_PM_TIMEOUT);
+	pm_runtime_use_autosuspend(dev->dev);
+
+	pm_runtime_enable(dev->dev);
+
+	r = pm_runtime_get_sync(dev->dev);
+	if (r < 0) {
+		dev_err(dev->dev, "failed to runtime_get device: %d\n", r);
 		goto err_unuse_clocks;

You end up doing a pm_runtime_put_sync() on failure here, instead of pm_runtime_put_noidle() like rest of the patch.

Quoted 1 line

May be handle this failure here instead of relying on the goto path.

Ok

Quoted 25 lines
Quoted 11 lines
drivers/i2c/busses/i2c-davinci.c +3 -0
 	}
 
@@ -849,27 +878,40 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	if (r)
 		goto err_unuse_clocks;
 
+	pm_runtime_mark_last_busy(dev->dev);
+	pm_runtime_put_autosuspend(dev->dev);
+
 	return 0;

drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct platform_device *pdev) · line 892

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +4 -2
 
 err_unuse_clocks:
-	clk_disable_unprepare(dev->clk);
-	dev->clk = NULL;
+	pm_runtime_dont_use_autosuspend(dev->dev);
+	pm_runtime_put_sync(dev->dev);
+	pm_runtime_disable(dev->dev);
+
 	return r;
 }

Thanks,
Sekhar

#4 lore raw

Re: [PATCH v3 1/2] i2c: davinci: Add PM Runtime Support

Quoted 48 lines · Franklin S Cooper Jr
Quoted 45 lines · Sekhar Nori
Quoted 2 lines · Franklin S Cooper Jr

66AK2G has I2C instances that are not apart of the ALWAYS_ON power domain like other Keystone 2 SoCs and OMAPL138. Therefore, pm_runtime

unlike ?

Quoted 25 lines

is required to insure the power domain used by the specific I2C instance is properly turned on along with its functional clock.

---
Version 3 changes:
Remove several statements that set clk to NULL
Fix error path

  drivers/i2c/busses/i2c-davinci.c | 64 +++++++++++++++++++++++++++++++++-------
  1 file changed, 53 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-davinci.c +3 -2
@@ -802,12 +821,22 @@ static int davinci_i2c_probe(struct platform_device *pdev)
  	dev->clk = devm_clk_get(&pdev->dev, NULL);
  	if (IS_ERR(dev->clk))
  		return PTR_ERR(dev->clk);
-	clk_prepare_enable(dev->clk);
 
  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	dev->base = devm_ioremap_resource(&pdev->dev, mem);
  	if (IS_ERR(dev->base)) {
-		r = PTR_ERR(dev->base);
+		return PTR_ERR(dev->base);
+	}
+

drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct platform_device *pdev) · line 840

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +9 -0
+	pm_runtime_set_autosuspend_delay(dev->dev,
+					 DAVINCI_I2C_PM_TIMEOUT);
+	pm_runtime_use_autosuspend(dev->dev);
+
+	pm_runtime_enable(dev->dev);
+
+	r = pm_runtime_get_sync(dev->dev);
+	if (r < 0) {
+		dev_err(dev->dev, "failed to runtime_get device: %d\n", r);
  		goto err_unuse_clocks;

You end up doing a pm_runtime_put_sync() on failure here, instead of pm_runtime_put_noidle() like rest of the patch.

Quoted 3 lines
Quoted 1 line

May be handle this failure here instead of relying on the goto path.

Ok

I think, it's not necessary - pm_runtime_put_sync() can be used in this case
(and used the same way in many other drivers).
In case, of failure in this place - pm_runtime_put_sync() will just decrement usage counter.

Quoted 25 lines
Quoted 25 lines
Quoted 11 lines
drivers/i2c/busses/i2c-davinci.c +3 -0
  	}
 
@@ -849,27 +878,40 @@ static int davinci_i2c_probe(struct platform_device *pdev)
  	if (r)
  		goto err_unuse_clocks;
 
+	pm_runtime_mark_last_busy(dev->dev);
+	pm_runtime_put_autosuspend(dev->dev);
+
  	return 0;

drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct platform_device *pdev) · line 892

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +4 -2
 
  err_unuse_clocks:
-	clk_disable_unprepare(dev->clk);
-	dev->clk = NULL;
+	pm_runtime_dont_use_autosuspend(dev->dev);
+	pm_runtime_put_sync(dev->dev);
+	pm_runtime_disable(dev->dev);
+
  	return r;
  }

Thanks,
Sekhar

Signature · 2 lines
regards,
-grygorii
#5 lore raw

Re: [PATCH v3 1/2] i2c: davinci: Add PM Runtime Support

Quoted 51 lines · Grygorii Strashko
Quoted 48 lines · Franklin S Cooper Jr
Quoted 45 lines · Sekhar Nori
Quoted 2 lines · Franklin S Cooper Jr

66AK2G has I2C instances that are not apart of the ALWAYS_ON power domain like other Keystone 2 SoCs and OMAPL138. Therefore, pm_runtime

unlike ?

Quoted 25 lines

is required to insure the power domain used by the specific I2C instance is properly turned on along with its functional clock.

---
Version 3 changes:
Remove several statements that set clk to NULL
Fix error path

  drivers/i2c/busses/i2c-davinci.c | 64 +++++++++++++++++++++++++++++++++-------
  1 file changed, 53 insertions(+), 11 deletions(-)
drivers/i2c/busses/i2c-davinci.c +3 -2
@@ -802,12 +821,22 @@ static int davinci_i2c_probe(struct platform_device *pdev)
  	dev->clk = devm_clk_get(&pdev->dev, NULL);
  	if (IS_ERR(dev->clk))
  		return PTR_ERR(dev->clk);
-	clk_prepare_enable(dev->clk);
 
  	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  	dev->base = devm_ioremap_resource(&pdev->dev, mem);
  	if (IS_ERR(dev->base)) {
-		r = PTR_ERR(dev->base);
+		return PTR_ERR(dev->base);
+	}
+

drivers/i2c/busses/i2c-davinci.c static int davinci_i2c_probe(struct platform_device *pdev) · line 840

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +9 -0
+	pm_runtime_set_autosuspend_delay(dev->dev,
+					 DAVINCI_I2C_PM_TIMEOUT);
+	pm_runtime_use_autosuspend(dev->dev);
+
+	pm_runtime_enable(dev->dev);
+
+	r = pm_runtime_get_sync(dev->dev);
+	if (r < 0) {
+		dev_err(dev->dev, "failed to runtime_get device: %d\n", r);
  		goto err_unuse_clocks;

You end up doing a pm_runtime_put_sync() on failure here, instead of pm_runtime_put_noidle() like rest of the patch.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

May be handle this failure here instead of relying on the goto path.

Ok

I think, it's not necessary - pm_runtime_put_sync() can be used in this case
(and used the same way in many other drivers).
In case, of failure in this place - pm_runtime_put_sync() will just decrement usage counter.

Can you please explain why this is the case? At least on DA850, I see the runtime_idle callback invoked from rpm_idle() if pm_runtime_put_sync() is used in the failure path.

Thanks
Sekhar