Skip to contentSkip to conversation

of/platform: Implement support for dev_pm_ops

PATCH In review Anton Vorontsov 3 participants 7 messages Oct 12, 2009 – Oct 14, 2009 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 of/platform: Implement support for dev_pm_ops

Linux power management subsystem supports vast amount of new PM callbacks that are crucial for proper suspend and hibernation support in drivers.

This patch implements support for dev_pm_ops, preserving support for legacy callbacks.

---
 drivers/of/platform.c |  305 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 290 insertions(+), 15 deletions(-)
drivers/of/platform.c +290 -15
index 298de0f..d58ade1 100644
@@ -65,47 +65,322 @@ static int of_platform_device_remove(struct device *dev)
 	return 0;
 }
 
-static int of_platform_device_suspend(struct device *dev, pm_message_t state)
+static void of_platform_device_shutdown(struct device *dev)
 {
 	struct of_device *of_dev = to_of_device(dev);
 	struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
-	int error = 0;
 
-	if (dev->driver && drv->suspend)
-		error = drv->suspend(of_dev, state);
-	return error;
+	if (dev->driver && drv->shutdown)
+		drv->shutdown(of_dev);
 }
 
-static int of_platform_device_resume(struct device * dev)
+#ifdef CONFIG_PM_SLEEP
+
+static int of_platform_legacy_suspend(struct device *dev, pm_message_t mesg)
 {
 	struct of_device *of_dev = to_of_device(dev);
 	struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
-	int error = 0;
+	int ret = 0;
 
-	if (dev->driver && drv->resume)
-		error = drv->resume(of_dev);
-	return error;
+	if (dev->driver && drv->suspend)
+		ret = drv->suspend(of_dev, mesg);
+	return ret;
 }
 
-static void of_platform_device_shutdown(struct device *dev)
+static int of_platform_legacy_resume(struct device *dev)
 {
 	struct of_device *of_dev = to_of_device(dev);
 	struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
+	int ret = 0;
 
-	if (dev->driver && drv->shutdown)
-		drv->shutdown(of_dev);
+	if (dev->driver && drv->resume)
+		ret = drv->resume(of_dev);
+	return ret;
+}
+
+static int of_platform_pm_prepare(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (drv && drv->pm && drv->pm->prepare)
+		ret = drv->pm->prepare(dev);
+
+	return ret;
+}
+
+static void of_platform_pm_complete(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+
+	if (drv && drv->pm && drv->pm->complete)
+		drv->pm->complete(dev);
+}
+
+#ifdef CONFIG_SUSPEND
+
+static int of_platform_pm_suspend(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->suspend)
+			ret = drv->pm->suspend(dev);
+	} else {
+		ret = of_platform_legacy_suspend(dev, PMSG_SUSPEND);
+	}
+
+	return ret;
 }
 
+static int of_platform_pm_suspend_noirq(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->suspend_noirq)
+			ret = drv->pm->suspend_noirq(dev);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_resume(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->resume)
+			ret = drv->pm->resume(dev);
+	} else {
+		ret = of_platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_resume_noirq(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->resume_noirq)
+			ret = drv->pm->resume_noirq(dev);
+	}
+
+	return ret;
+}
+
+#else /* !CONFIG_SUSPEND */
+
+#define of_platform_pm_suspend		NULL
+#define of_platform_pm_resume		NULL
+#define of_platform_pm_suspend_noirq	NULL
+#define of_platform_pm_resume_noirq	NULL
+
+#endif /* !CONFIG_SUSPEND */
+
+#ifdef CONFIG_HIBERNATION
+
+static int of_platform_pm_freeze(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->freeze)
+			ret = drv->pm->freeze(dev);
+	} else {
+		ret = of_platform_legacy_suspend(dev, PMSG_FREEZE);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_freeze_noirq(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->freeze_noirq)
+			ret = drv->pm->freeze_noirq(dev);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_thaw(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->thaw)
+			ret = drv->pm->thaw(dev);
+	} else {
+		ret = of_platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_thaw_noirq(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->thaw_noirq)
+			ret = drv->pm->thaw_noirq(dev);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_poweroff(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->poweroff)
+			ret = drv->pm->poweroff(dev);
+	} else {
+		ret = of_platform_legacy_suspend(dev, PMSG_HIBERNATE);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_poweroff_noirq(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->poweroff_noirq)
+			ret = drv->pm->poweroff_noirq(dev);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_restore(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->restore)
+			ret = drv->pm->restore(dev);
+	} else {
+		ret = of_platform_legacy_resume(dev);
+	}
+
+	return ret;
+}
+
+static int of_platform_pm_restore_noirq(struct device *dev)
+{
+	struct device_driver *drv = dev->driver;
+	int ret = 0;
+
+	if (!drv)
+		return 0;
+
+	if (drv->pm) {
+		if (drv->pm->restore_noirq)
+			ret = drv->pm->restore_noirq(dev);
+	}
+
+	return ret;
+}
+
+#else /* !CONFIG_HIBERNATION */
+
+#define of_platform_pm_freeze		NULL
+#define of_platform_pm_thaw		NULL
+#define of_platform_pm_poweroff		NULL
+#define of_platform_pm_restore		NULL
+#define of_platform_pm_freeze_noirq	NULL
+#define of_platform_pm_thaw_noirq		NULL
+#define of_platform_pm_poweroff_noirq	NULL
+#define of_platform_pm_restore_noirq	NULL
+
+#endif /* !CONFIG_HIBERNATION */
+
+static struct dev_pm_ops of_platform_dev_pm_ops = {
+	.prepare = of_platform_pm_prepare,
+	.complete = of_platform_pm_complete,
+	.suspend = of_platform_pm_suspend,
+	.resume = of_platform_pm_resume,
+	.freeze = of_platform_pm_freeze,
+	.thaw = of_platform_pm_thaw,
+	.poweroff = of_platform_pm_poweroff,
+	.restore = of_platform_pm_restore,
+	.suspend_noirq = of_platform_pm_suspend_noirq,
+	.resume_noirq = of_platform_pm_resume_noirq,
+	.freeze_noirq = of_platform_pm_freeze_noirq,
+	.thaw_noirq = of_platform_pm_thaw_noirq,
+	.poweroff_noirq = of_platform_pm_poweroff_noirq,
+	.restore_noirq = of_platform_pm_restore_noirq,
+};
+
+#define OF_PLATFORM_PM_OPS_PTR	(&of_platform_dev_pm_ops)
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define OF_PLATFORM_PM_OPS_PTR	NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
 int of_bus_type_init(struct bus_type *bus, const char *name)
 {
 	bus->name = name;
 	bus->match = of_platform_bus_match;
 	bus->probe = of_platform_device_probe;
 	bus->remove = of_platform_device_remove;
-	bus->suspend = of_platform_device_suspend;
-	bus->resume = of_platform_device_resume;
 	bus->shutdown = of_platform_device_shutdown;
 	bus->dev_attrs = of_platform_device_attrs;
+	bus->pm = OF_PLATFORM_PM_OPS_PTR;
 	return bus_register(bus);
 }
 
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 8 lines · Anton Vorontsov

Linux power management subsystem supports vast amount of new PM callbacks that are crucial for proper suspend and hibernation support in drivers.

This patch implements support for dev_pm_ops, preserving support for legacy callbacks.

Hmmm... I'm not very familiar with the PM callbacks, but change doesn't look right to me. In particular, a lot of these new hooks don't do anything remotely of_platform bus specific. For example, of_platform_pm_prepare() checks if there is drv, drv->pm, and drv->pm->prepare. If all are true, then it calls drv->pm->prepare(). I see that the platform bus platform_pm_prepare() function is absolutely identical. I haven't looked, but I wouldn't be surprised if other busses do the same.

I think these simple pm ops should be made library functions that platform, of_platform and other simple busses can just populate their pm ops structure with.

g.

Quoted 349 lines

---
 drivers/of/platform.c |  305 ++++++++++++++++++++++++++++++++++++++++++++++---

 1 files changed, 290 insertions(+), 15 deletions(-)
drivers/of/platform.c +290 -16
index 298de0f..d58ade1 100644
@@ -65,47 +65,322 @@ static int of_platform_device_remove(struct device *dev)
        return 0;
  }
 
-static int of_platform_device_suspend(struct device *dev, pm_message_t state)
+static void of_platform_device_shutdown(struct device *dev)
  {
        struct of_device *of_dev = to_of_device(dev);
        struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
-       int error = 0;
 
-       if (dev->driver && drv->suspend)
-               error = drv->suspend(of_dev, state);
-       return error;
+       if (dev->driver && drv->shutdown)
+               drv->shutdown(of_dev);
  }
 
-static int of_platform_device_resume(struct device * dev)
+#ifdef CONFIG_PM_SLEEP
+
+static int of_platform_legacy_suspend(struct device *dev, pm_message_t mesg)
  {
        struct of_device *of_dev = to_of_device(dev);
        struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
-       int error = 0;
+       int ret = 0;
 
-       if (dev->driver && drv->resume)
-               error = drv->resume(of_dev);
-       return error;
+       if (dev->driver && drv->suspend)
+               ret = drv->suspend(of_dev, mesg);
+       return ret;
  }
 
-static void of_platform_device_shutdown(struct device *dev)
+static int of_platform_legacy_resume(struct device *dev)
  {
        struct of_device *of_dev = to_of_device(dev);
        struct of_platform_driver *drv = to_of_platform_driver(dev->driver);
+       int ret = 0;
 
-       if (dev->driver && drv->shutdown)
-               drv->shutdown(of_dev);
+       if (dev->driver && drv->resume)
+               ret = drv->resume(of_dev);
+       return ret;
+}
+
+static int of_platform_pm_prepare(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (drv && drv->pm && drv->pm->prepare)
+               ret = drv->pm->prepare(dev);
+
+       return ret;
+}
+
+static void of_platform_pm_complete(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+
+       if (drv && drv->pm && drv->pm->complete)
+               drv->pm->complete(dev);
+}
+
+#ifdef CONFIG_SUSPEND
+
+static int of_platform_pm_suspend(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->suspend)
+                       ret = drv->pm->suspend(dev);
+       } else {
+               ret = of_platform_legacy_suspend(dev, PMSG_SUSPEND);
+       }
+
+       return ret;
  }
 
+static int of_platform_pm_suspend_noirq(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->suspend_noirq)
+                       ret = drv->pm->suspend_noirq(dev);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_resume(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->resume)
+                       ret = drv->pm->resume(dev);
+       } else {
+               ret = of_platform_legacy_resume(dev);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_resume_noirq(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->resume_noirq)
+                       ret = drv->pm->resume_noirq(dev);
+       }
+
+       return ret;
+}
+
+#else /* !CONFIG_SUSPEND */
+
+#define of_platform_pm_suspend         NULL
+#define of_platform_pm_resume          NULL
+#define of_platform_pm_suspend_noirq   NULL
+#define of_platform_pm_resume_noirq    NULL
+
+#endif /* !CONFIG_SUSPEND */
+
+#ifdef CONFIG_HIBERNATION
+
+static int of_platform_pm_freeze(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->freeze)
+                       ret = drv->pm->freeze(dev);
+       } else {
+               ret = of_platform_legacy_suspend(dev, PMSG_FREEZE);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_freeze_noirq(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->freeze_noirq)
+                       ret = drv->pm->freeze_noirq(dev);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_thaw(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->thaw)
+                       ret = drv->pm->thaw(dev);
+       } else {
+               ret = of_platform_legacy_resume(dev);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_thaw_noirq(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->thaw_noirq)
+                       ret = drv->pm->thaw_noirq(dev);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_poweroff(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->poweroff)
+                       ret = drv->pm->poweroff(dev);
+       } else {
+               ret = of_platform_legacy_suspend(dev, PMSG_HIBERNATE);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_poweroff_noirq(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->poweroff_noirq)
+                       ret = drv->pm->poweroff_noirq(dev);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_restore(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->restore)
+                       ret = drv->pm->restore(dev);
+       } else {
+               ret = of_platform_legacy_resume(dev);
+       }
+
+       return ret;
+}
+
+static int of_platform_pm_restore_noirq(struct device *dev)
+{
+       struct device_driver *drv = dev->driver;
+       int ret = 0;
+
+       if (!drv)
+               return 0;
+
+       if (drv->pm) {
+               if (drv->pm->restore_noirq)
+                       ret = drv->pm->restore_noirq(dev);
+       }
+
+       return ret;
+}
+
+#else /* !CONFIG_HIBERNATION */
+
+#define of_platform_pm_freeze          NULL
+#define of_platform_pm_thaw            NULL
+#define of_platform_pm_poweroff                NULL
+#define of_platform_pm_restore         NULL
+#define of_platform_pm_freeze_noirq    NULL
+#define of_platform_pm_thaw_noirq              NULL
+#define of_platform_pm_poweroff_noirq  NULL
+#define of_platform_pm_restore_noirq   NULL
+
+#endif /* !CONFIG_HIBERNATION */
+
+static struct dev_pm_ops of_platform_dev_pm_ops = {
+       .prepare = of_platform_pm_prepare,
+       .complete = of_platform_pm_complete,
+       .suspend = of_platform_pm_suspend,
+       .resume = of_platform_pm_resume,
+       .freeze = of_platform_pm_freeze,
+       .thaw = of_platform_pm_thaw,
+       .poweroff = of_platform_pm_poweroff,
+       .restore = of_platform_pm_restore,
+       .suspend_noirq = of_platform_pm_suspend_noirq,
+       .resume_noirq = of_platform_pm_resume_noirq,
+       .freeze_noirq = of_platform_pm_freeze_noirq,
+       .thaw_noirq = of_platform_pm_thaw_noirq,
+       .poweroff_noirq = of_platform_pm_poweroff_noirq,
+       .restore_noirq = of_platform_pm_restore_noirq,
+};
+
+#define OF_PLATFORM_PM_OPS_PTR (&of_platform_dev_pm_ops)
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define OF_PLATFORM_PM_OPS_PTR NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
  int of_bus_type_init(struct bus_type *bus, const char *name)
  {
        bus->name = name;
        bus->match = of_platform_bus_match;
        bus->probe = of_platform_device_probe;
        bus->remove = of_platform_device_remove;
-       bus->suspend = of_platform_device_suspend;
-       bus->resume = of_platform_device_resume;
        bus->shutdown = of_platform_device_shutdown;
        bus->dev_attrs = of_platform_device_attrs;
+       bus->pm = OF_PLATFORM_PM_OPS_PTR;
        return bus_register(bus);
  }
 
--

1.6.3.3

Signature · 2 lines
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
#2 lore raw
In reply to Anton Vorontsov
Quoted 8 lines · Anton Vorontsov

Linux power management subsystem supports vast amount of new PM callbacks that are crucial for proper suspend and hibernation support in drivers.

This patch implements support for dev_pm_ops, preserving support for legacy callbacks.

Hmmm... I'm not very familiar with the PM callbacks, but change doesn't look right to me. In particular, a lot of these new hooks don't do anything remotely of_platform bus specific. For example, of_platform_pm_prepare() checks if there is drv, drv->pm, and drv->pm->prepare. If all are true, then it calls drv->pm->prepare(). I see that the platform bus platform_pm_prepare() function is absolutely identical. I haven't looked, but I wouldn't be surprised if other busses do the same.

I think these simple pm ops should be made library functions that platform, of_platform and other simple busses can just populate their pm ops structure with.

g.

Quoted 2 lines

---
=A0drivers/of/platform.c | =A0305 +++++++++++++++++++++++++++++++++++++++=

+++++++---

drivers/of/platform.c static int of_platform_device_remove(struct device *=

Quoted 7 lines

=A01 files changed, 290 insertions(+), 15 deletions(-)

drivers/of/platform.c +0 -0
index 298de0f..d58ade1 100644
@@ -65,47 +65,322 @@ static int of_platform_device_remove(struct device *=

dev)

drivers/of/platform.c static int of_platform_device_remove(struct device *= · line 68

Quoted 4 lines
drivers/of/platform.c +0 -1
 =A0 =A0 =A0 =A0return 0;
 =A0}
 
-static int of_platform_device_suspend(struct device *dev, pm_message_t s=

tate)

Quoted 4 lines
drivers/of/platform.c +1 -0
+static void of_platform_device_shutdown(struct device *dev)
 =A0{
 =A0 =A0 =A0 =A0struct of_device *of_dev =3D to_of_device(dev);

=A0 =A0 =A0 =A0struct of_platform_driver *drv =3D to_of_platform_driver(d=

ev->driver);

drivers/of/platform.c static int of_platform_device_remove(struct device *dev)

Quoted 13 lines

- =A0 =A0 =A0 int error =3D 0;

- =A0 =A0 =A0 if (dev->driver && drv->suspend)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 error =3D drv->suspend(of_dev, state);
- =A0 =A0 =A0 return error;
+ =A0 =A0 =A0 if (dev->driver && drv->shutdown)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 drv->shutdown(of_dev);
=A0}

drivers/of/platform.c +3 -1
-static int of_platform_device_resume(struct device * dev)
+#ifdef CONFIG_PM_SLEEP
+
+static int of_platform_legacy_suspend(struct device *dev, pm_message_t m=

esg)

Quoted 3 lines

=A0{
=A0 =A0 =A0 =A0struct of_device *of_dev =3D to_of_device(dev); =A0 =A0 =A0 =A0struct of_platform_driver *drv =3D to_of_platform_driver(d=

ev->driver);

Quoted 13 lines

- =A0 =A0 =A0 int error =3D 0;
+ =A0 =A0 =A0 int ret =3D 0;

- =A0 =A0 =A0 if (dev->driver && drv->resume)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 error =3D drv->resume(of_dev);
- =A0 =A0 =A0 return error;
+ =A0 =A0 =A0 if (dev->driver && drv->suspend)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->suspend(of_dev, mesg);
+ =A0 =A0 =A0 return ret;
=A0}

drivers/of/platform.c +1 -1
-static void of_platform_device_shutdown(struct device *dev)
+static int of_platform_legacy_resume(struct device *dev)
Quoted 3 lines

=A0{
=A0 =A0 =A0 =A0struct of_device *of_dev =3D to_of_device(dev); =A0 =A0 =A0 =A0struct of_platform_driver *drv =3D to_of_platform_driver(d=

ev->driver);

Quoted 31 lines

+ =A0 =A0 =A0 int ret =3D 0;

- =A0 =A0 =A0 if (dev->driver && drv->shutdown)
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 drv->shutdown(of_dev);
+ =A0 =A0 =A0 if (dev->driver && drv->resume)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->resume(of_dev);
+ =A0 =A0 =A0 return ret;

drivers/of/platform.c +24 -0
+}
+
+static int of_platform_pm_prepare(struct device *dev)
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (drv && drv->pm && drv->pm->prepare)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->prepare(dev);
+
+ =A0 =A0 =A0 return ret;
+}
+
+static void of_platform_pm_complete(struct device *dev)
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+
+ =A0 =A0 =A0 if (drv && drv->pm && drv->pm->complete)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 drv->pm->complete(dev);
+}
+
+#ifdef CONFIG_SUSPEND
+
+static int of_platform_pm_suspend(struct device *dev)

drivers/of/platform.c static int of_platform_device_remove(struct device *dev)

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->suspend)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->suspend(de=

v);

Quoted 2 lines

+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_platform_legacy_suspend(dev, PMS=

G_SUSPEND);

Quoted 6 lines

+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 return ret;
=A0}

drivers/of/platform.c +1 -0
+static int of_platform_pm_suspend_noirq(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->suspend_noirq)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->suspend_no=

irq(dev);

Quoted 6 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +5 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_resume(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->resume)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->resume(dev=

);

Quoted 8 lines

+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_platform_legacy_resume(dev);
+ =A0 =A0 =A0 }

drivers/of/platform.c +5 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_resume_noirq(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->resume_noirq)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->resume_noi=

rq(dev);

Quoted 17 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +16 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+#else /* !CONFIG_SUSPEND */
+
+#define of_platform_pm_suspend =A0 =A0 =A0 =A0 NULL
+#define of_platform_pm_resume =A0 =A0 =A0 =A0 =A0NULL
+#define of_platform_pm_suspend_noirq =A0 NULL
+#define of_platform_pm_resume_noirq =A0 =A0NULL
+
+#endif /* !CONFIG_SUSPEND */
+
+#ifdef CONFIG_HIBERNATION
+
+static int of_platform_pm_freeze(struct device *dev)

drivers/of/platform.c static int of_platform_device_remove(struct device *dev)

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->freeze)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->freeze(dev=

);

Quoted 2 lines

+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_platform_legacy_suspend(dev, PMS=

G_FREEZE);

Quoted 6 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +5 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_freeze_noirq(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->freeze_noirq)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->freeze_noi=

rq(dev);

Quoted 24 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +23 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_thaw(struct device *dev)
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->thaw)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->thaw(dev);
+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_platform_legacy_resume(dev);
+ =A0 =A0 =A0 }
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_thaw_noirq(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->thaw_noirq)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->thaw_noirq=

(dev);

Quoted 6 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +5 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_poweroff(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->poweroff)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->poweroff(d=

ev);

Quoted 2 lines

+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_platform_legacy_suspend(dev, PMS=

G_HIBERNATE);

Quoted 6 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +5 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_poweroff_noirq(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->poweroff_noirq)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->poweroff_n=

oirq(dev);

Quoted 6 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +5 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_restore(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->restore)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->restore(de=

v);

Quoted 8 lines

+ =A0 =A0 =A0 } else {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D of_platform_legacy_resume(dev);
+ =A0 =A0 =A0 }

drivers/of/platform.c +5 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+static int of_platform_pm_restore_noirq(struct device *dev)

drivers/of/platform.c

Quoted 10 lines
drivers/of/platform.c +10 -0
+{
+ =A0 =A0 =A0 struct device_driver *drv =3D dev->driver;
+ =A0 =A0 =A0 int ret =3D 0;
+
+ =A0 =A0 =A0 if (!drv)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 0;
+
+ =A0 =A0 =A0 if (drv->pm) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (drv->pm->restore_noirq)
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ret =3D drv->pm->restore_no=

irq(dev);

Quoted 57 lines

+ =A0 =A0 =A0 }

drivers/of/platform.c +42 -0
+
+ =A0 =A0 =A0 return ret;
+}
+
+#else /* !CONFIG_HIBERNATION */
+
+#define of_platform_pm_freeze =A0 =A0 =A0 =A0 =A0NULL
+#define of_platform_pm_thaw =A0 =A0 =A0 =A0 =A0 =A0NULL
+#define of_platform_pm_poweroff =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0NULL
+#define of_platform_pm_restore =A0 =A0 =A0 =A0 NULL
+#define of_platform_pm_freeze_noirq =A0 =A0NULL
+#define of_platform_pm_thaw_noirq =A0 =A0 =A0 =A0 =A0 =A0 =A0NULL
+#define of_platform_pm_poweroff_noirq =A0NULL
+#define of_platform_pm_restore_noirq =A0 NULL
+
+#endif /* !CONFIG_HIBERNATION */
+
+static struct dev_pm_ops of_platform_dev_pm_ops =3D {
+ =A0 =A0 =A0 .prepare =3D of_platform_pm_prepare,
+ =A0 =A0 =A0 .complete =3D of_platform_pm_complete,
+ =A0 =A0 =A0 .suspend =3D of_platform_pm_suspend,
+ =A0 =A0 =A0 .resume =3D of_platform_pm_resume,
+ =A0 =A0 =A0 .freeze =3D of_platform_pm_freeze,
+ =A0 =A0 =A0 .thaw =3D of_platform_pm_thaw,
+ =A0 =A0 =A0 .poweroff =3D of_platform_pm_poweroff,
+ =A0 =A0 =A0 .restore =3D of_platform_pm_restore,
+ =A0 =A0 =A0 .suspend_noirq =3D of_platform_pm_suspend_noirq,
+ =A0 =A0 =A0 .resume_noirq =3D of_platform_pm_resume_noirq,
+ =A0 =A0 =A0 .freeze_noirq =3D of_platform_pm_freeze_noirq,
+ =A0 =A0 =A0 .thaw_noirq =3D of_platform_pm_thaw_noirq,
+ =A0 =A0 =A0 .poweroff_noirq =3D of_platform_pm_poweroff_noirq,
+ =A0 =A0 =A0 .restore_noirq =3D of_platform_pm_restore_noirq,
+};
+
+#define OF_PLATFORM_PM_OPS_PTR (&of_platform_dev_pm_ops)
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define OF_PLATFORM_PM_OPS_PTR NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+

=A0int of_bus_type_init(struct bus_type *bus, const char *name) =A0{
=A0 =A0 =A0 =A0bus->name =3D name;
=A0 =A0 =A0 =A0bus->match =3D of_platform_bus_match; =A0 =A0 =A0 =A0bus->probe =3D of_platform_device_probe; =A0 =A0 =A0 =A0bus->remove =3D of_platform_device_remove;
- =A0 =A0 =A0 bus->suspend =3D of_platform_device_suspend;
- =A0 =A0 =A0 bus->resume =3D of_platform_device_resume; =A0 =A0 =A0 =A0bus->shutdown =3D of_platform_device_shutdown; =A0 =A0 =A0 =A0bus->dev_attrs =3D of_platform_device_attrs;
+ =A0 =A0 =A0 bus->pm =3D OF_PLATFORM_PM_OPS_PTR;
=A0 =A0 =A0 =A0return bus_register(bus);
=A0}

Quoted 3 lines

--
1.6.3.3

--=20
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

#3 lore raw
Quoted 20 lines · Grant Likely
Quoted 8 lines · Anton Vorontsov

Linux power management subsystem supports vast amount of new PM callbacks that are crucial for proper suspend and hibernation support in drivers.

This patch implements support for dev_pm_ops, preserving support for legacy callbacks.

Hmmm... I'm not very familiar with the PM callbacks, but change doesn't look right to me. In particular, a lot of these new hooks don't do anything remotely of_platform bus specific. For example, of_platform_pm_prepare() checks if there is drv, drv->pm, and drv->pm->prepare. If all are true, then it calls drv->pm->prepare(). I see that the platform bus platform_pm_prepare() function is absolutely identical. I haven't looked, but I wouldn't be surprised if other busses do the same.

Quoted 3 lines

I think these simple pm ops should be made library functions that platform, of_platform and other simple busses can just populate their pm ops structure with.

Some hooks can be made as library functions, but some can't (for example that do of_plaform_driver->suspend(), as opposite to of_platform_driver->driver.suspend(), i.e. the legacy hooks). Also, if you look into PCI bus hooks, you'll see that these hooks aren't pure proxies for drivers, they do real work, so they won't like to reuse or share anything.

For OF platfrom bus, we can share these functions with platform:

of_platform_pm_suspend_noirq
of_platform_pm_resume_noirq
of_platform_pm_freeze_noirq
of_platform_pm_thaw_noirq
of_platform_pm_poweroff_noirq
of_platform_pm_restore_noirq

These we cannot share:

of_platform_pm_suspend
of_platform_pm_resume
of_platform_pm_freeze
of_platform_pm_thaw
of_platform_pm_poweroff
of_platform_pm_restore

I agree that there is some room for improvements in general (e.g. merging platform and of_platform devices/drivers), but it's not as easy as you would like to think. Let's make it in a separate step that don't stop real features from being implemented (e.g. hibernate).

For the six functions that we can reuse I can prepare a cleanup patch that we can merge via -mm, or it can just sit and collect needed acks and can be merged via any tree. But please, no cross-tree dependencies for the cruicial features.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#4 lore raw
In reply to Grant Likely
Quoted 20 lines · Grant Likely
Quoted 8 lines · Anton Vorontsov

Linux power management subsystem supports vast amount of new PM callbacks that are crucial for proper suspend and hibernation support in drivers.

This patch implements support for dev_pm_ops, preserving support for legacy callbacks.

Hmmm... I'm not very familiar with the PM callbacks, but change doesn't look right to me. In particular, a lot of these new hooks don't do anything remotely of_platform bus specific. For example, of_platform_pm_prepare() checks if there is drv, drv->pm, and drv->pm->prepare. If all are true, then it calls drv->pm->prepare(). I see that the platform bus platform_pm_prepare() function is absolutely identical. I haven't looked, but I wouldn't be surprised if other busses do the same.

Quoted 3 lines

I think these simple pm ops should be made library functions that platform, of_platform and other simple busses can just populate their pm ops structure with.

Some hooks can be made as library functions, but some can't (for example that do of_plaform_driver->suspend(), as opposite to of_platform_driver->driver.suspend(), i.e. the legacy hooks). Also, if you look into PCI bus hooks, you'll see that these hooks aren't pure proxies for drivers, they do real work, so they won't like to reuse or share anything.

For OF platfrom bus, we can share these functions with platform:

of_platform_pm_suspend_noirq
of_platform_pm_resume_noirq
of_platform_pm_freeze_noirq
of_platform_pm_thaw_noirq
of_platform_pm_poweroff_noirq
of_platform_pm_restore_noirq

These we cannot share:

of_platform_pm_suspend
of_platform_pm_resume
of_platform_pm_freeze
of_platform_pm_thaw
of_platform_pm_poweroff
of_platform_pm_restore

I agree that there is some room for improvements in general (e.g. merging platform and of_platform devices/drivers), but it's not as easy as you would like to think. Let's make it in a separate step that don't stop real features from being implemented (e.g. hibernate).

For the six functions that we can reuse I can prepare a cleanup patch that we can merge via -mm, or it can just sit and collect needed acks and can be merged via any tree. But please, no cross-tree dependencies for the cruicial features.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#5 lore raw
Quoted 10 lines · Anton Vorontsov

I agree that there is some room for improvements in general (e.g. merging platform and of_platform devices/drivers), but it's not as easy as you would like to think. Let's make it in a separate step that don't stop real features from being implemented (e.g. hibernate).

For the six functions that we can reuse I can prepare a cleanup patch that we can merge via -mm, or it can just sit and collect needed acks and can be merged via any tree. But please, no cross-tree dependencies for the cruicial features.

I agree. I'll take the patch for now.

In the long run, I'm all for killing of_platform if we can find a "proper" way to replace it with platform.

IE. With dev_archdata, any device carries the of device node, so of_platform doesn't really buy us much anymore.

We could even "default" by populating platform device resources with standard-parsing of "reg" properties etc...

So for devices who don't actually need anything more, we may get away re-using platform devices as-is, all we would need is some kind of conversion table or such to map OF match to platform dev names, or maybe a secondary match table in the drivers themselves.

Anyway, that's an old discussion, something we still need to sort out...

Ben.

#6 lore raw
In reply to Anton Vorontsov
Quoted 10 lines · Anton Vorontsov

I agree that there is some room for improvements in general (e.g. merging platform and of_platform devices/drivers), but it's not as easy as you would like to think. Let's make it in a separate step that don't stop real features from being implemented (e.g. hibernate).

For the six functions that we can reuse I can prepare a cleanup patch that we can merge via -mm, or it can just sit and collect needed acks and can be merged via any tree. But please, no cross-tree dependencies for the cruicial features.

I agree. I'll take the patch for now.

In the long run, I'm all for killing of_platform if we can find a "proper" way to replace it with platform.

IE. With dev_archdata, any device carries the of device node, so of_platform doesn't really buy us much anymore.

We could even "default" by populating platform device resources with standard-parsing of "reg" properties etc...

So for devices who don't actually need anything more, we may get away re-using platform devices as-is, all we would need is some kind of conversion table or such to map OF match to platform dev names, or maybe a secondary match table in the drivers themselves.

Anyway, that's an old discussion, something we still need to sort out...

Ben.