[RFC net-next 2/8] subdev: Introduce pm callbacks

From: Parav Pandit
Date: Fri Mar 01 2019 - 00:38:13 EST


Keep power management callbacks in place to optionally notify drivers
who register them.

Signed-off-by: Parav Pandit <parav@xxxxxxxxxxxx>
---
drivers/subdev/subdev_main.c | 59 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)

diff --git a/drivers/subdev/subdev_main.c b/drivers/subdev/subdev_main.c
index 4aabcaa..e213331 100644
--- a/drivers/subdev/subdev_main.c
+++ b/drivers/subdev/subdev_main.c
@@ -23,10 +23,69 @@ static int subdev_bus_match(struct device *dev, struct device_driver *drv)
return 0;
}

+static int subdev_pm_prepare(struct device *dev)
+{
+ if (dev->driver->pm && dev->driver->pm->prepare)
+ return dev->driver->pm->prepare(dev);
+ return 0;
+}
+
+static void subdev_pm_complete(struct device *dev)
+{
+ if (dev->driver->pm && dev->driver->pm->complete)
+ dev->driver->pm->complete(dev);
+}
+
+static int subdev_pm_suspend(struct device *dev)
+{
+ if (dev->driver->pm && dev->driver->pm->suspend)
+ return dev->driver->pm->suspend(dev);
+ return 0;
+}
+
+static int subdev_pm_suspend_late(struct device *dev)
+{
+ if (dev->driver->pm && dev->driver->pm->suspend_late)
+ return dev->driver->pm->suspend_late(dev);
+ return 0;
+}
+
+static int subdev_pm_resume(struct device *dev)
+{
+ if (dev->driver->pm && dev->driver->pm->resume)
+ return dev->driver->pm->resume(dev);
+ return 0;
+}
+
+static int subdev_pm_freeze(struct device *dev)
+{
+ if (dev->driver->pm && dev->driver->pm->freeze)
+ return dev->driver->pm->freeze(dev);
+ return 0;
+}
+
+static int subdev_pm_freeze_late(struct device *dev)
+{
+ if (dev->driver->pm && dev->driver->pm->freeze_late)
+ return dev->driver->pm->freeze_late(dev);
+ return 0;
+}
+
+static const struct dev_pm_ops subdev_dev_pm_ops = {
+ .prepare = subdev_pm_prepare,
+ .complete = subdev_pm_complete,
+ .suspend = subdev_pm_suspend,
+ .suspend_late = subdev_pm_suspend_late,
+ .resume = subdev_pm_resume,
+ .freeze = subdev_pm_freeze,
+ .freeze_late = subdev_pm_freeze_late,
+};
+
static struct bus_type subdev_bus_type = {
.dev_name = "subdev",
.name = "subdev",
.match = subdev_bus_match,
+ .pm = &subdev_dev_pm_ops,
};

int __subdev_register_driver(struct subdev_driver *drv, struct module *owner,
--
1.8.3.1