Skip to contentSkip to conversation

PM: Prototype the pm_generic_ operations

PATCH Applied Mark Brown 3 participants 19 messages Dec 20, 2010 – Dec 24, 2010

Subsystems (5)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/2 PM: Prototype the pm_generic_ operations

The pm_generic_ operations are all exported but are not prototyped in any header file for direct use. Do so.

---
 include/linux/pm.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
include/linux/pm.h +7 -0
index 40f3f45..f7b5bed 100644
@@ -610,4 +610,11 @@ extern unsigned int	pm_flags;
 #define PM_APM	1
 #define PM_ACPI	2
 
+int pm_generic_suspend(struct device *dev);
+int pm_generic_resume(struct device *dev);
+int pm_generic_freeze(struct device *dev);
+int pm_generic_thaw(struct device *dev);
+int pm_generic_restore(struct device *dev);
+int pm_generic_poweroff(struct device *dev);
+
 #endif /* _LINUX_PM_H */
Signature · 1 line
1.7.2.3
author
#1 lore raw

PATCH 2/2 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 |   57 ++++++++++++++++--------------------------------
 1 files changed, 19 insertions(+), 38 deletions(-)
drivers/i2c/i2c-core.c +19 -38
index 6b4cc56..4478557 100644
@@ -196,69 +196,50 @@ 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)
@@ -267,7 +248,7 @@ static int i2c_device_pm_restore(struct device *dev)
 	int ret;
 
 	if (pm)
-		ret = pm->restore ? pm->restore(dev) : 0;
+		ret = pm_generic_restore(dev);
 	else
 		ret = i2c_legacy_resume(dev);
 
Signature · 1 line
1.7.2.3
#2 lore raw

Re: [linux-pm] [PATCH 2/2] i2c: Factor out runtime suspend checks from PM operations

Quoted 9 lines · Mark Brown

 static int i2c_device_pm_restore(struct device *dev)

drivers/i2c/i2c-core.c +1 -1
@@ -267,7 +248,7 @@ static int i2c_device_pm_restore(struct device *dev)
        int ret;
 
        if (pm)
-               ret = pm->restore ? pm->restore(dev) : 0;
+               ret = pm_generic_restore(dev);

       else
               ret = i2c_legacy_resume(dev);

The full function is:

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;
	else
		ret = i2c_legacy_resume(dev);

	if (!ret) {
		pm_runtime_disable(dev);
		pm_runtime_set_active(dev);
		pm_runtime_enable(dev);
	}

	return ret;
}

Shouldn't you be deleting the pm_runtime_* stuff from here? There is already done in pm_generic_restore() iff the callback exists and returns zero.

author
#3 lore raw

Re: [linux-pm] [PATCH 2/2] i2c: Factor out runtime suspend checks from PM operations

Quoted 3 lines · Rabin Vincent

Shouldn't you be deleting the pm_runtime_* stuff from here? There is already done in pm_generic_restore() iff the callback exists and returns zero.

I guess; it's not clear why this is being done by the bus at all or how it interacts with the legacy stuff.

#4 lore raw

Re: [linux-pm] [PATCH 2/2] i2c: Factor out runtime suspend checks from PM operations

Quoted 8 lines · Mark Brown
Quoted 3 lines · Rabin Vincent

Shouldn't you be deleting the pm_runtime_* stuff from here? There is already done in pm_generic_restore() iff the callback exists and returns zero.

I guess; it's not clear why this is being done by the bus at all or how it interacts with the legacy stuff.

It is done, because when the driver's ->resume() or ->restore() brings the device up (which should have happened if it returned 0), we need to mark the device as "active" for runtime PM.

Since __pm_generic_resume() does that, it's not necessary to do it in the bus type callbacks (in the "legacy" case we known that runtime PM is not supported).

Thanks,
Rafael

#5 lore raw

Re: [PATCH 2/2] i2c: Factor out runtime suspend checks from PM operations

In reply to Mark Brown
Quoted 8 lines · Mark Brown
Quoted 3 lines · Rabin Vincent

Shouldn't you be deleting the pm_runtime_* stuff from here? There is already done in pm_generic_restore() iff the callback exists and returns zero.

I guess; it's not clear why this is being done by the bus at all or how it interacts with the legacy stuff.

It is done, because when the driver's ->resume() or ->restore() brings the device up (which should have happened if it returned 0), we need to mark the device as "active" for runtime PM.

Since __pm_generic_resume() does that, it's not necessary to do it in the bus type callbacks (in the "legacy" case we known that runtime PM is not supported).

Thanks,
Rafael

author
#6 lore raw

Re: [PATCH 2/2] i2c: Factor out runtime suspend checks from PM operations

In reply to Rabin Vincent
Quoted 3 lines · Rabin Vincent

Shouldn't you be deleting the pm_runtime_* stuff from here? There is already done in pm_generic_restore() iff the callback exists and returns zero.

I guess; it's not clear why this is being done by the bus at all or how it interacts with the legacy stuff.

#7 lore raw

Re: [PATCH 2/2] i2c: Factor out runtime suspend checks from PM operations

In reply to Mark Brown
Quoted 9 lines · Mark Brown

 static int i2c_device_pm_restore(struct device *dev)

drivers/i2c/i2c-core.c +1 -1
@@ -267,7 +248,7 @@ static int i2c_device_pm_restore(struct device *dev)
        int ret;
 
        if (pm)
-               ret = pm->restore ? pm->restore(dev) : 0;
+               ret = pm_generic_restore(dev);

       else
               ret = i2c_legacy_resume(dev);

The full function is:

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;
	else
		ret = i2c_legacy_resume(dev);

	if (!ret) {
		pm_runtime_disable(dev);
		pm_runtime_set_active(dev);
		pm_runtime_enable(dev);
	}

	return ret;
}

Shouldn't you be deleting the pm_runtime_* stuff from here? There is already done in pm_generic_restore() iff the callback exists and returns zero.

author
#8 lore raw

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

In reply to 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 |   57 ++++++++++++++++--------------------------------
 1 files changed, 19 insertions(+), 38 deletions(-)
drivers/i2c/i2c-core.c +19 -38
index 6b4cc56..4478557 100644
@@ -196,69 +196,50 @@ 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)
@@ -267,7 +248,7 @@ static int i2c_device_pm_restore(struct device *dev)
 	int ret;
 
 	if (pm)
-		ret = pm->restore ? pm->restore(dev) : 0;
+		ret = pm_generic_restore(dev);
 	else
 		ret = i2c_legacy_resume(dev);
 
Signature · 1 line
1.7.2.3
#9 lore raw
In reply to Mark Brown
Quoted 4 lines · Mark Brown

The pm_generic_ operations are all exported but are not prototyped in any header file for direct use. Do so.

I'd take this one, but the second one depends on it.

I can take both if Jean agrees.

Thanks,
Rafael

Quoted 21 lines
---
 include/linux/pm.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
include/linux/pm.h +7 -0
index 40f3f45..f7b5bed 100644
@@ -610,4 +610,11 @@ extern unsigned int	pm_flags;
 #define PM_APM	1
 #define PM_ACPI	2
 
+int pm_generic_suspend(struct device *dev);
+int pm_generic_resume(struct device *dev);
+int pm_generic_freeze(struct device *dev);
+int pm_generic_thaw(struct device *dev);
+int pm_generic_restore(struct device *dev);
+int pm_generic_poweroff(struct device *dev);
+
 #endif /* _LINUX_PM_H */
author
#10 lore raw
Quoted 3 lines · Rafael J. Wysocki

I'd take this one, but the second one depends on it.

I can take both if Jean agrees.

Given the nearness of the merge window another option is to apply this one now and punt the I2C one until 2.6.38, I guess?

#11 lore raw
Quoted 8 lines · Mark Brown
Quoted 3 lines · Rafael J. Wysocki

I'd take this one, but the second one depends on it.

I can take both if Jean agrees.

Given the nearness of the merge window another option is to apply this one now and punt the I2C one until 2.6.38, I guess?

Except that I don't have any more fixes for 2.6.37 pending and this one isn't really a fix. :-)

If there's anything else I should push to Linus before 2.6.37, I'll include this patch in the pull request. Otherwise I think it shoul go in during the merge window.

Thanks,
Rafael

author
#12 lore raw
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines · Mark Brown

Given the nearness of the merge window another option is to apply this one now and punt the I2C one until 2.6.38, I guess?

Except that I don't have any more fixes for 2.6.37 pending and this one isn't really a fix. :-)

Oh, sorry - I mean during the merge window rather than for 2.6.37.

author
#13 lore raw
In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines · Mark Brown

Given the nearness of the merge window another option is to apply this one now and punt the I2C one until 2.6.38, I guess?

Except that I don't have any more fixes for 2.6.37 pending and this one isn't really a fix. :-)

Oh, sorry - I mean during the merge window rather than for 2.6.37.

#14 lore raw
In reply to Mark Brown
Quoted 8 lines · Mark Brown
Quoted 3 lines · Rafael J. Wysocki

I'd take this one, but the second one depends on it.

I can take both if Jean agrees.

Given the nearness of the merge window another option is to apply this one now and punt the I2C one until 2.6.38, I guess?

Except that I don't have any more fixes for 2.6.37 pending and this one isn't really a fix. :-)

If there's anything else I should push to Linus before 2.6.37, I'll include this patch in the pull request. Otherwise I think it shoul go in during the merge window.

Thanks,
Rafael

author
#15 lore raw
In reply to Rafael J. Wysocki
Quoted 3 lines · Rafael J. Wysocki

I'd take this one, but the second one depends on it.

I can take both if Jean agrees.

Given the nearness of the merge window another option is to apply this one now and punt the I2C one until 2.6.38, I guess?

#16 lore raw
In reply to Mark Brown
Quoted 4 lines · Mark Brown

The pm_generic_ operations are all exported but are not prototyped in any header file for direct use. Do so.

I'd take this one, but the second one depends on it.

I can take both if Jean agrees.

Thanks,
Rafael

Quoted 21 lines
---
 include/linux/pm.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
include/linux/pm.h +7 -0
index 40f3f45..f7b5bed 100644
@@ -610,4 +610,11 @@ extern unsigned int	pm_flags;
 #define PM_APM	1
 #define PM_ACPI	2
 
+int pm_generic_suspend(struct device *dev);
+int pm_generic_resume(struct device *dev);
+int pm_generic_freeze(struct device *dev);
+int pm_generic_thaw(struct device *dev);
+int pm_generic_restore(struct device *dev);
+int pm_generic_poweroff(struct device *dev);
+
 #endif /* _LINUX_PM_H */
#17 lore raw
In reply to Mark Brown
Quoted 4 lines · Mark Brown

The pm_generic_ operations are all exported but are not prototyped in any header file for direct use. Do so.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

Quoted 21 lines
---
 include/linux/pm.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
include/linux/pm.h +7 -0
index 40f3f45..f7b5bed 100644
@@ -610,4 +610,11 @@ extern unsigned int	pm_flags;
 #define PM_APM	1
 #define PM_ACPI	2
 
+int pm_generic_suspend(struct device *dev);
+int pm_generic_resume(struct device *dev);
+int pm_generic_freeze(struct device *dev);
+int pm_generic_thaw(struct device *dev);
+int pm_generic_restore(struct device *dev);
+int pm_generic_poweroff(struct device *dev);
+
 #endif /* _LINUX_PM_H */
#18 lore raw
In reply to Mark Brown
Quoted 4 lines · Mark Brown

The pm_generic_ operations are all exported but are not prototyped in any header file for direct use. Do so.

Applied to suspend-2.6/linux-next.

Thanks,
Rafael

Quoted 21 lines
---
 include/linux/pm.h |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
include/linux/pm.h +7 -0
index 40f3f45..f7b5bed 100644
@@ -610,4 +610,11 @@ extern unsigned int	pm_flags;
 #define PM_APM	1
 #define PM_ACPI	2
 
+int pm_generic_suspend(struct device *dev);
+int pm_generic_resume(struct device *dev);
+int pm_generic_freeze(struct device *dev);
+int pm_generic_thaw(struct device *dev);
+int pm_generic_restore(struct device *dev);
+int pm_generic_poweroff(struct device *dev);
+
 #endif /* _LINUX_PM_H */