Skip to contentSkip to conversation

i2c: busses: tegra: Add suspend-resume support

PATCH Superseded Bitan Biswas 2 participants 7 messages May 30, 2019 – Jun 6, 2019

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: busses: tegra: Add suspend-resume support

Post suspend I2C registers have power on reset values. Before any transfer initialize I2C registers to prevent I2C transfer timeout and implement suspend and resume callbacks needed. Fix below errors post suspend:

1) Tegra I2C transfer timeout during jetson tx2 resume:

[   27.520613] pca953x 1-0074: calling pca953x_resume+0x0/0x1b0 @ 2939, parent: i2c-1
[   27.633623] tegra-i2c 3160000.i2c: i2c transfer timed out
[   27.639162] pca953x 1-0074: Unable to sync registers 0x3-0x5. -110
[   27.645336] pca953x 1-0074: Failed to sync GPIO dir registers: -110
[   27.651596] PM: dpm_run_callback(): pca953x_resume+0x0/0x1b0 returns -110
[   27.658375] pca953x 1-0074: pca953x_resume+0x0/0x1b0 returned -110 after 127152 usecs
[   27.666194] PM: Device 1-0074 failed to resume: error -110

2) Tegra I2C transfer timeout error on jetson Xavier post resume.

---
 drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +24 -0
index ebaa78d..f6a377f 100644
@@ -1687,9 +1687,33 @@ static int tegra_i2c_remove(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_PM_SLEEP
+static int tegra_i2c_suspend(struct device *dev)
+{
+	struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+
+	i2c_mark_adapter_suspended(&i2c_dev->adapter);
+
+	return 0;
+}
+
+static int tegra_i2c_resume(struct device *dev)
+{
+	struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+	int ret;
+
+	i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+	ret = tegra_i2c_init(i2c_dev, false);
+	i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+	if (!ret)
+		i2c_mark_adapter_resumed(&i2c_dev->adapter);
+
+       return ret;
+}
+
 static const struct dev_pm_ops tegra_i2c_pm = {
 	SET_RUNTIME_PM_OPS(tegra_i2c_runtime_suspend, tegra_i2c_runtime_resume,
 			   NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(tegra_i2c_suspend, tegra_i2c_resume)
 };
 #define TEGRA_I2C_PM	(&tegra_i2c_pm)
 #else
Signature · 1 line
2.7.4
#1 lore raw

30.05.2019 8:55, Bitan Biswas пишет:

Quoted 37 lines

Post suspend I2C registers have power on reset values. Before any transfer initialize I2C registers to prevent I2C transfer timeout and implement suspend and resume callbacks needed. Fix below errors post suspend:

1) Tegra I2C transfer timeout during jetson tx2 resume:

[   27.520613] pca953x 1-0074: calling pca953x_resume+0x0/0x1b0 @ 2939, parent: i2c-1
[   27.633623] tegra-i2c 3160000.i2c: i2c transfer timed out
[   27.639162] pca953x 1-0074: Unable to sync registers 0x3-0x5. -110
[   27.645336] pca953x 1-0074: Failed to sync GPIO dir registers: -110
[   27.651596] PM: dpm_run_callback(): pca953x_resume+0x0/0x1b0 returns -110
[   27.658375] pca953x 1-0074: pca953x_resume+0x0/0x1b0 returned -110 after 127152 usecs
[   27.666194] PM: Device 1-0074 failed to resume: error -110

2) Tegra I2C transfer timeout error on jetson Xavier post resume.

---
 drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +7 -0
index ebaa78d..f6a377f 100644
@@ -1687,9 +1687,33 @@ static int tegra_i2c_remove(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_PM_SLEEP
+static int tegra_i2c_suspend(struct device *dev)
+{
+	struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+
+	i2c_mark_adapter_suspended(&i2c_dev->adapter);
+
+	return 0;

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct platform_device *pdev) · line 1706

Quoted 10 lines
drivers/i2c/busses/i2c-tegra.c +10 -0
+}
+
+static int tegra_i2c_resume(struct device *dev)
+{
+	struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+	int ret;
+
+	i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+	ret = tegra_i2c_init(i2c_dev, false);
+	i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);

Why the locking is needed here?

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct platform_device *pdev) · line 1710

Quoted 4 lines
drivers/i2c/busses/i2c-tegra.c +4 -0
+	if (!ret)
+		i2c_mark_adapter_resumed(&i2c_dev->adapter);
+
+       return ret;

A very minor nit.. will be a bit more straightforward to write this as:

	int err;

	err = tegra_i2c_init(i2c_dev, false);
	if (err)
		return err;

	i2c_mark_adapter_resumed(&i2c_dev->adapter);

	return 0;

It is always cleaner to return 0 on success.

--
Dmitry

#2 lore raw
Quoted 42 lines · Dmitry Osipenko

30.05.2019 8:55, Bitan Biswas пишет:

Quoted 41 lines

Post suspend I2C registers have power on reset values. Before any transfer initialize I2C registers to prevent I2C transfer timeout and implement suspend and resume callbacks needed. Fix below errors post suspend:

1) Tegra I2C transfer timeout during jetson tx2 resume:

[   27.520613] pca953x 1-0074: calling pca953x_resume+0x0/0x1b0 @ 2939, parent: i2c-1
[   27.633623] tegra-i2c 3160000.i2c: i2c transfer timed out
[   27.639162] pca953x 1-0074: Unable to sync registers 0x3-0x5. -110
[   27.645336] pca953x 1-0074: Failed to sync GPIO dir registers: -110
[   27.651596] PM: dpm_run_callback(): pca953x_resume+0x0/0x1b0 returns -110
[   27.658375] pca953x 1-0074: pca953x_resume+0x0/0x1b0 returned -110 after 127152 usecs
[   27.666194] PM: Device 1-0074 failed to resume: error -110

2) Tegra I2C transfer timeout error on jetson Xavier post resume.

---
  drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++
  1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +11 -0
index ebaa78d..f6a377f 100644
@@ -1687,9 +1687,33 @@ static int tegra_i2c_remove(struct platform_device *pdev)
  }
 
  #ifdef CONFIG_PM_SLEEP
+static int tegra_i2c_suspend(struct device *dev)
+{
+	struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+
+	i2c_mark_adapter_suspended(&i2c_dev->adapter);
+
+	return 0;
+}
+
+static int tegra_i2c_resume(struct device *dev)
+{
Quoted 8 lines

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct platform_device *pdev) · line 1706

Quoted 6 lines
drivers/i2c/busses/i2c-tegra.c +6 -0
+	struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+	int ret;
+
+	i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+	ret = tegra_i2c_init(i2c_dev, false);
+	i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);

Why the locking is needed here?

async resume could result in stress test issues if some client accesses the i2c instance. This ensures the i2c instance is locked till the initialization is complete.

Quoted 18 lines

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct platform_device *pdev) · line 1710

Quoted 5 lines
drivers/i2c/busses/i2c-tegra.c +4 -0
+	if (!ret)
+		i2c_mark_adapter_resumed(&i2c_dev->adapter);
+
+       return ret;

A very minor nit.. will be a bit more straightforward to write this as:

	int err;

	err = tegra_i2c_init(i2c_dev, false);
	if (err)
		return err;

	i2c_mark_adapter_resumed(&i2c_dev->adapter);

	return 0;
Quoted 1 line

It is always cleaner to return 0 on success.

Thanks. I shall update the section in patch as per this suggestion.

-regards,
Bitan

#3 lore raw

31.05.2019 11:50, Bitan Biswas пишет:

Quoted 58 lines · Dmitry Osipenko
Quoted 46 lines

30.05.2019 8:55, Bitan Biswas пишет:

Quoted 45 lines

Post suspend I2C registers have power on reset values. Before any transfer initialize I2C registers to prevent I2C transfer timeout and implement suspend and resume callbacks needed. Fix below errors post suspend:

1) Tegra I2C transfer timeout during jetson tx2 resume:

[   27.520613] pca953x 1-0074: calling pca953x_resume+0x0/0x1b0 @ 2939, parent: i2c-1
[   27.633623] tegra-i2c 3160000.i2c: i2c transfer timed out [   27.639162] pca953x 1-0074: Unable to sync registers 0x3-0x5. -110 [   27.645336] pca953x 1-0074: Failed to sync GPIO dir registers: -110 [   27.651596] PM: dpm_run_callback(): pca953x_resume+0x0/0x1b0 returns -110
[   27.658375] pca953x 1-0074: pca953x_resume+0x0/0x1b0 returned -110 after 127152 usecs
[   27.666194] PM: Device 1-0074 failed to resume: error -110

2) Tegra I2C transfer timeout error on jetson Xavier post resume.

---
  drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++

  1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +11 -0
index ebaa78d..f6a377f 100644
@@ -1687,9 +1687,33 @@ static int tegra_i2c_remove(struct
 platform_device *pdev)
   }
     #ifdef CONFIG_PM_SLEEP
+static int tegra_i2c_suspend(struct device *dev)
+{
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+
+    i2c_mark_adapter_suspended(&i2c_dev->adapter);
+
+    return 0;
+}
+
+static int tegra_i2c_resume(struct device *dev)
+{
Quoted 8 lines

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct platform_device *pdev) · line 1706

Quoted 6 lines
drivers/i2c/busses/i2c-tegra.c +6 -0
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+    int ret;
+
+    i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+    ret = tegra_i2c_init(i2c_dev, false);
+    i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);

Why the locking is needed here?

Quoted 3 lines

async resume could result in stress test issues if some client accesses the i2c instance. This ensures the i2c instance is locked till the initialization is complete.

1) This doesn't make much sense.. if client could access I2C during of tegra_i2c_init execution, then what stops it to perform the access before the lock is taken?

2) The whole point of the i2c_mark_adapter_* API is to catch those faulty clients that have a broken suspend-resume sequence. Client will get a -ESHUTDOWN on trying to issue I2C transfer while controller is marked as suspended.

3) Please don't use async suspend-resume where it doesn't make sense.

Corollary: you should drop the locking because it doesn't do anything useful.

#4 lore raw
Quoted 59 lines · Dmitry Osipenko

31.05.2019 11:50, Bitan Biswas пишет:

Quoted 58 lines · Dmitry Osipenko
Quoted 54 lines

30.05.2019 8:55, Bitan Biswas пишет:

Quoted 41 lines

Post suspend I2C registers have power on reset values. Before any transfer initialize I2C registers to prevent I2C transfer timeout and implement suspend and resume callbacks needed. Fix below errors post suspend:

1) Tegra I2C transfer timeout during jetson tx2 resume:

[   27.520613] pca953x 1-0074: calling pca953x_resume+0x0/0x1b0 @ 2939, parent: i2c-1
[   27.633623] tegra-i2c 3160000.i2c: i2c transfer timed out [   27.639162] pca953x 1-0074: Unable to sync registers 0x3-0x5. -110 [   27.645336] pca953x 1-0074: Failed to sync GPIO dir registers: -110 [   27.651596] PM: dpm_run_callback(): pca953x_resume+0x0/0x1b0 returns -110
[   27.658375] pca953x 1-0074: pca953x_resume+0x0/0x1b0 returned -110 after 127152 usecs
[   27.666194] PM: Device 1-0074 failed to resume: error -110

2) Tegra I2C transfer timeout error on jetson Xavier post resume.

---
   drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++
   1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +7 -0
index ebaa78d..f6a377f 100644
@@ -1687,9 +1687,33 @@ static int tegra_i2c_remove(struct
 platform_device *pdev)
   }
     #ifdef CONFIG_PM_SLEEP
+static int tegra_i2c_suspend(struct device *dev)
+{
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+
+    i2c_mark_adapter_suspended(&i2c_dev->adapter);
+
+    return 0;

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct · line 1706

Quoted 10 lines
drivers/i2c/busses/i2c-tegra.c +10 -0
+}
+
+static int tegra_i2c_resume(struct device *dev)
+{
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+    int ret;
+
+    i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+    ret = tegra_i2c_init(i2c_dev, false);
+    i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);

Why the locking is needed here?

Quoted 7 lines
Quoted 3 lines

async resume could result in stress test issues if some client accesses the i2c instance. This ensures the i2c instance is locked till the initialization is complete.

1) This doesn't make much sense.. if client could access I2C during of tegra_i2c_init execution, then what stops it to perform the access before the lock is taken?

Client resumes will start after I2C instance resume because of driver dependency. Since lock is the first call in i2c-tegra I believe I2C calls of client will not start.

Quoted 5 lines

2) The whole point of the i2c_mark_adapter_* API is to catch those faulty clients that have a broken suspend-resume sequence. Client will get a -ESHUTDOWN on trying to issue I2C transfer while controller is marked as suspended.

i2c lock bus calls were used in the resume callback implementation that was reverted few months back. Hence, these were added in this patch which should be more like a revert-of-revert .

But I feel probably your point also makes sense. Old resume callback did not have i2c_mark_adapter_* calls. Based on the i2c_adapter_mark_* API documentation it should be taking care that core i2c calls from client are not started. I plan to update the patch and remove the lock-unlock guards in resume callback.

Quoted 2 lines

3) Please don't use async suspend-resume where it doesn't make sense.

This is a system wide setting. /sys/power/pm_async by default is 1 and there is no driver specific change in this patch to choose async suspend-resume.

Quoted 4 lines

Corollary: you should drop the locking because it doesn't do anything useful.

I did some basic suspend resume tests and do not see any problems removing the i2c_lock_bus call you pointed out.

-Thanks,
Bitan

#5 lore raw

06.06.2019 8:43, Bitan Biswas пишет:

Quoted 66 lines · Dmitry Osipenko
Quoted 63 lines

31.05.2019 11:50, Bitan Biswas пишет:

Quoted 61 lines · Dmitry Osipenko
Quoted 46 lines

30.05.2019 8:55, Bitan Biswas пишет:

Quoted 45 lines

Post suspend I2C registers have power on reset values. Before any transfer initialize I2C registers to prevent I2C transfer timeout and implement suspend and resume callbacks needed. Fix below errors post suspend:

1) Tegra I2C transfer timeout during jetson tx2 resume:

[   27.520613] pca953x 1-0074: calling pca953x_resume+0x0/0x1b0 @ 2939, parent: i2c-1
[   27.633623] tegra-i2c 3160000.i2c: i2c transfer timed out [   27.639162] pca953x 1-0074: Unable to sync registers 0x3-0x5. -110 [   27.645336] pca953x 1-0074: Failed to sync GPIO dir registers: -110 [   27.651596] PM: dpm_run_callback(): pca953x_resume+0x0/0x1b0 returns -110
[   27.658375] pca953x 1-0074: pca953x_resume+0x0/0x1b0 returned -110 after 127152 usecs
[   27.666194] PM: Device 1-0074 failed to resume: error -110

2) Tegra I2C transfer timeout error on jetson Xavier post resume.

---
   drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++

   1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +11 -0
index ebaa78d..f6a377f 100644
@@ -1687,9 +1687,33 @@ static int tegra_i2c_remove(struct
 platform_device *pdev)
    }
      #ifdef CONFIG_PM_SLEEP
+static int tegra_i2c_suspend(struct device *dev)
+{
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+
+    i2c_mark_adapter_suspended(&i2c_dev->adapter);
+
+    return 0;
+}
+
+static int tegra_i2c_resume(struct device *dev)
+{
Quoted 8 lines

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct platform_device *pdev) · line 1706

Quoted 6 lines
drivers/i2c/busses/i2c-tegra.c +6 -0
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+    int ret;
+
+    i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+    ret = tegra_i2c_init(i2c_dev, false);
+    i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);

Why the locking is needed here?

async resume could result in stress test issues if some client accesses the i2c instance. This ensures the i2c instance is locked till the initialization is complete.

Quoted 6 lines
Quoted 3 lines

1) This doesn't make much sense.. if client could access I2C during of tegra_i2c_init execution, then what stops it to perform the access before the lock is taken?

Client resumes will start after I2C instance resume because of driver dependency. Since lock is the first call in i2c-tegra I believe I2C calls of client will not start.

You're incorrectly assuming that client can start resuming in the middle of the controller's resume process. I2C client's resume won't start until tegra_i2c_resume() is finished completely. That is because child drivers are resumed only after theirs parent is ready and this is guaranteed by the drivers core.

#6 lore raw
Quoted 74 lines · Dmitry Osipenko

06.06.2019 8:43, Bitan Biswas пишет:

Quoted 66 lines · Dmitry Osipenko
Quoted 63 lines

31.05.2019 11:50, Bitan Biswas пишет:

Quoted 61 lines · Dmitry Osipenko
Quoted 46 lines

30.05.2019 8:55, Bitan Biswas пишет:

Quoted 45 lines

Post suspend I2C registers have power on reset values. Before any transfer initialize I2C registers to prevent I2C transfer timeout and implement suspend and resume callbacks needed. Fix below errors post suspend:

1) Tegra I2C transfer timeout during jetson tx2 resume:

[   27.520613] pca953x 1-0074: calling pca953x_resume+0x0/0x1b0 @ 2939, parent: i2c-1
[   27.633623] tegra-i2c 3160000.i2c: i2c transfer timed out [   27.639162] pca953x 1-0074: Unable to sync registers 0x3-0x5. -110 [   27.645336] pca953x 1-0074: Failed to sync GPIO dir registers: -110 [   27.651596] PM: dpm_run_callback(): pca953x_resume+0x0/0x1b0 returns -110
[   27.658375] pca953x 1-0074: pca953x_resume+0x0/0x1b0 returned -110 after 127152 usecs
[   27.666194] PM: Device 1-0074 failed to resume: error -110

2) Tegra I2C transfer timeout error on jetson Xavier post resume.

---
    drivers/i2c/busses/i2c-tegra.c | 24 ++++++++++++++++++++++++
    1 file changed, 24 insertions(+)
drivers/i2c/busses/i2c-tegra.c +11 -0
index ebaa78d..f6a377f 100644
@@ -1687,9 +1687,33 @@ static int tegra_i2c_remove(struct
 platform_device *pdev)
    }
      #ifdef CONFIG_PM_SLEEP
+static int tegra_i2c_suspend(struct device *dev)
+{
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+
+    i2c_mark_adapter_suspended(&i2c_dev->adapter);
+
+    return 0;
+}
+
+static int tegra_i2c_resume(struct device *dev)
+{
Quoted 8 lines

drivers/i2c/busses/i2c-tegra.c static int tegra_i2c_remove(struct platform_device *pdev) · line 1706

Quoted 6 lines
drivers/i2c/busses/i2c-tegra.c +6 -0
+    struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
+    int ret;
+
+    i2c_lock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);
+    ret = tegra_i2c_init(i2c_dev, false);
+    i2c_unlock_bus(&i2c_dev->adapter, I2C_LOCK_ROOT_ADAPTER);

Why the locking is needed here?

async resume could result in stress test issues if some client accesses the i2c instance. This ensures the i2c instance is locked till the initialization is complete.

Quoted 6 lines
Quoted 3 lines

1) This doesn't make much sense.. if client could access I2C during of tegra_i2c_init execution, then what stops it to perform the access before the lock is taken?

Client resumes will start after I2C instance resume because of driver dependency. Since lock is the first call in i2c-tegra I believe I2C calls of client will not start.

Quoted 6 lines

You're incorrectly assuming that client can start resuming in the middle of the controller's resume process. I2C client's resume won't start until tegra_i2c_resume() is finished completely. That is because child drivers are resumed only after theirs parent is ready and this is guaranteed by the drivers core.

Agreed.

-regards,
Bitan