Skip to contentSkip to conversation

i2c: Factor out runtime suspend checks from PM operations

PATCH In review Mark Brown 4 participants 11 messages Dec 30, 2010 – Jan 13, 2011

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 i2c: Factor out runtime suspend checks from PM operations

When devices use dev_pm_ops the I2C API is implementing standard functionality for integration with runtime PM and for checking for the presence of a per device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

---
 drivers/i2c/i2c-core.c |   68 ++++++++++++++---------------------------------
 1 files changed, 20 insertions(+), 48 deletions(-)
drivers/i2c/i2c-core.c +20 -48
index 6b4cc56..6793c51 100644
@@ -196,88 +196,60 @@ static int i2c_device_pm_suspend(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 
-	if (pm) {
-		if (pm_runtime_suspended(dev))
-			return 0;
-		else
-			return pm->suspend ? pm->suspend(dev) : 0;
-	}
-
-	return i2c_legacy_suspend(dev, PMSG_SUSPEND);
+	if (pm)
+		return pm_generic_suspend(dev);
+	else
+		return i2c_legacy_suspend(dev, PMSG_SUSPEND);
 }
 
 static int i2c_device_pm_resume(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
-	int ret;
 
 	if (pm)
-		ret = pm->resume ? pm->resume(dev) : 0;
+		return pm_generic_resume(dev);
 	else
-		ret = i2c_legacy_resume(dev);
-
-	return ret;
+		return i2c_legacy_resume(dev);
 }
 
 static int i2c_device_pm_freeze(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 
-	if (pm) {
-		if (pm_runtime_suspended(dev))
-			return 0;
-		else
-			return pm->freeze ? pm->freeze(dev) : 0;
-	}
-
-	return i2c_legacy_suspend(dev, PMSG_FREEZE);
+	if (pm)
+		return pm_generic_freeze(dev);
+	else
+		return i2c_legacy_suspend(dev, PMSG_FREEZE);
 }
 
 static int i2c_device_pm_thaw(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 
-	if (pm) {
-		if (pm_runtime_suspended(dev))
-			return 0;
-		else
-			return pm->thaw ? pm->thaw(dev) : 0;
-	}
-
-	return i2c_legacy_resume(dev);
+	if (pm)
+		return pm_generic_thaw(dev);
+	else
+		return i2c_legacy_resume(dev);
 }
 
 static int i2c_device_pm_poweroff(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 
-	if (pm) {
-		if (pm_runtime_suspended(dev))
-			return 0;
-		else
-			return pm->poweroff ? pm->poweroff(dev) : 0;
-	}
-
-	return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
+	if (pm)
+		return pm_generic_poweroff(dev);
+	else
+		return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
 }
 
 static int i2c_device_pm_restore(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
-	int ret;
 
 	if (pm)
-		ret = pm->restore ? pm->restore(dev) : 0;
+		return pm_generic_restore(dev);
 	else
-		ret = i2c_legacy_resume(dev);
-
-	if (!ret) {
-		pm_runtime_disable(dev);
-		pm_runtime_set_active(dev);
-		pm_runtime_enable(dev);
-	}
-
-	return ret;
+		return i2c_legacy_resume(dev);
 }
 #else /* !CONFIG_PM_SLEEP */
 #define i2c_device_pm_suspend	NULL
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 18 lines · Mark Brown

When devices use dev_pm_ops the I2C API is implementing standard functionality for integration with runtime PM and for checking for the presence of a per device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

---
 drivers/i2c/i2c-core.c |   68 ++++++++++++++---------------------------------
 1 files changed, 20 insertions(+), 48 deletions(-)
drivers/i2c/i2c-core.c +0 -0
index 6b4cc56..6793c51 100644
@@ -196,88 +196,60 @@ static int i2c_device_pm_suspend(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 

drivers/i2c/i2c-core.c static int i2c_device_pm_suspend(struct device *dev) · line 200

Quoted 10 lines
drivers/i2c/i2c-core.c +2 -8
-	if (pm) {
-		if (pm_runtime_suspended(dev))
-			return 0;
-		else
-			return pm->suspend ? pm->suspend(dev) : 0;
-	}
-
-	return i2c_legacy_suspend(dev, PMSG_SUSPEND);
+	if (pm)
+		return pm_generic_suspend(dev);

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

author
#2 lore raw
Quoted 6 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

#3 lore raw
Quoted 6 lines · Mark Brown
Quoted 4 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

Quoted 6 lines
Quoted 1 line

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

I would take it, but I'm still waiting for a word from Jean.

Thanks,
Rafael

#4 lore raw

Hi Rafael,

Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Mark Brown
Quoted 4 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

I would take it, but I'm still waiting for a word from Jean.

Sorry for the long silence, I was on vacation. I've just applied this patch, and I will send it to Linus tomorrow.

Signature · 1 line
Jean Delvare
#5 lore raw
Quoted 17 lines · Jean Delvare

Hi Rafael,

Quoted 14 lines · Rafael J. Wysocki
Quoted 12 lines · Mark Brown
Quoted 6 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

Quoted 4 lines
Quoted 1 line

I would take it, but I'm still waiting for a word from Jean.

Sorry for the long silence, I was on vacation. I've just applied this patch, and I will send it to Linus tomorrow.

Great, thanks!

Rafael

#6 lore raw
In reply to Jean Delvare
Quoted 17 lines · Jean Delvare

Hi Rafael,

Quoted 14 lines · Rafael J. Wysocki
Quoted 12 lines · Mark Brown
Quoted 6 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

Quoted 4 lines
Quoted 1 line

I would take it, but I'm still waiting for a word from Jean.

Sorry for the long silence, I was on vacation. I've just applied this patch, and I will send it to Linus tomorrow.

Great, thanks!

Rafael

#7 lore raw
In reply to Rafael J. Wysocki

Hi Rafael,

Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Mark Brown
Quoted 4 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

I would take it, but I'm still waiting for a word from Jean.

Sorry for the long silence, I was on vacation. I've just applied this patch, and I will send it to Linus tomorrow.

Signature · 1 line
Jean Delvare
#8 lore raw
In reply to Mark Brown
Quoted 6 lines · Mark Brown
Quoted 4 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

Quoted 6 lines
Quoted 1 line

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

I would take it, but I'm still waiting for a word from Jean.

Thanks,
Rafael

author
#9 lore raw
In reply to Abhijeet Dharmapurikar
Quoted 6 lines · Abhijeet Dharmapurikar
Quoted 2 lines · Mark Brown

device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

Yes, there's a patch in -next for this already so this patch would need to either wait for later in the merge window or go in via the PM tree with the preceeding one (the original version of this patch was posted as part of a series with the export patch).

#10 lore raw
In reply to Mark Brown
Quoted 18 lines · Mark Brown

When devices use dev_pm_ops the I2C API is implementing standard functionality for integration with runtime PM and for checking for the presence of a per device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.

---
 drivers/i2c/i2c-core.c |   68 ++++++++++++++---------------------------------
 1 files changed, 20 insertions(+), 48 deletions(-)
drivers/i2c/i2c-core.c +0 -0
index 6b4cc56..6793c51 100644
@@ -196,88 +196,60 @@ static int i2c_device_pm_suspend(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 

drivers/i2c/i2c-core.c static int i2c_device_pm_suspend(struct device *dev) · line 200

Quoted 10 lines
drivers/i2c/i2c-core.c +2 -8
-	if (pm) {
-		if (pm_runtime_suspended(dev))
-			return 0;
-		else
-			return pm->suspend ? pm->suspend(dev) : 0;
-	}
-
-	return i2c_legacy_suspend(dev, PMSG_SUSPEND);
+	if (pm)
+		return pm_generic_suspend(dev);

pm_generic_suspend() and others needs to be externed in linux/pm_runtime.h?

--
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.