Merge tag 'for-linus-20190706' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / base / power / generic_ops.c
blob4fa525668cb70ab0377d2d255b6829e7fd520f0f
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * drivers/base/power/generic_ops.c - Generic PM callbacks for subsystems
5 * Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
6 */
7 #include <linux/pm.h>
8 #include <linux/pm_runtime.h>
9 #include <linux/export.h>
11 #ifdef CONFIG_PM
12 /**
13 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
14 * @dev: Device to suspend.
16 * If PM operations are defined for the @dev's driver and they include
17 * ->runtime_suspend(), execute it and return its error code. Otherwise,
18 * return 0.
20 int pm_generic_runtime_suspend(struct device *dev)
22 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
23 int ret;
25 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0;
27 return ret;
29 EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
31 /**
32 * pm_generic_runtime_resume - Generic runtime resume callback for subsystems.
33 * @dev: Device to resume.
35 * If PM operations are defined for the @dev's driver and they include
36 * ->runtime_resume(), execute it and return its error code. Otherwise,
37 * return 0.
39 int pm_generic_runtime_resume(struct device *dev)
41 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
42 int ret;
44 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0;
46 return ret;
48 EXPORT_SYMBOL_GPL(pm_generic_runtime_resume);
49 #endif /* CONFIG_PM */
51 #ifdef CONFIG_PM_SLEEP
52 /**
53 * pm_generic_prepare - Generic routine preparing a device for power transition.
54 * @dev: Device to prepare.
56 * Prepare a device for a system-wide power transition.
58 int pm_generic_prepare(struct device *dev)
60 struct device_driver *drv = dev->driver;
61 int ret = 0;
63 if (drv && drv->pm && drv->pm->prepare)
64 ret = drv->pm->prepare(dev);
66 return ret;
69 /**
70 * pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems.
71 * @dev: Device to suspend.
73 int pm_generic_suspend_noirq(struct device *dev)
75 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
77 return pm && pm->suspend_noirq ? pm->suspend_noirq(dev) : 0;
79 EXPORT_SYMBOL_GPL(pm_generic_suspend_noirq);
81 /**
82 * pm_generic_suspend_late - Generic suspend_late callback for subsystems.
83 * @dev: Device to suspend.
85 int pm_generic_suspend_late(struct device *dev)
87 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
89 return pm && pm->suspend_late ? pm->suspend_late(dev) : 0;
91 EXPORT_SYMBOL_GPL(pm_generic_suspend_late);
93 /**
94 * pm_generic_suspend - Generic suspend callback for subsystems.
95 * @dev: Device to suspend.
97 int pm_generic_suspend(struct device *dev)
99 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
101 return pm && pm->suspend ? pm->suspend(dev) : 0;
103 EXPORT_SYMBOL_GPL(pm_generic_suspend);
106 * pm_generic_freeze_noirq - Generic freeze_noirq callback for subsystems.
107 * @dev: Device to freeze.
109 int pm_generic_freeze_noirq(struct device *dev)
111 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
113 return pm && pm->freeze_noirq ? pm->freeze_noirq(dev) : 0;
115 EXPORT_SYMBOL_GPL(pm_generic_freeze_noirq);
118 * pm_generic_freeze_late - Generic freeze_late callback for subsystems.
119 * @dev: Device to freeze.
121 int pm_generic_freeze_late(struct device *dev)
123 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
125 return pm && pm->freeze_late ? pm->freeze_late(dev) : 0;
127 EXPORT_SYMBOL_GPL(pm_generic_freeze_late);
130 * pm_generic_freeze - Generic freeze callback for subsystems.
131 * @dev: Device to freeze.
133 int pm_generic_freeze(struct device *dev)
135 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
137 return pm && pm->freeze ? pm->freeze(dev) : 0;
139 EXPORT_SYMBOL_GPL(pm_generic_freeze);
142 * pm_generic_poweroff_noirq - Generic poweroff_noirq callback for subsystems.
143 * @dev: Device to handle.
145 int pm_generic_poweroff_noirq(struct device *dev)
147 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
149 return pm && pm->poweroff_noirq ? pm->poweroff_noirq(dev) : 0;
151 EXPORT_SYMBOL_GPL(pm_generic_poweroff_noirq);
154 * pm_generic_poweroff_late - Generic poweroff_late callback for subsystems.
155 * @dev: Device to handle.
157 int pm_generic_poweroff_late(struct device *dev)
159 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
161 return pm && pm->poweroff_late ? pm->poweroff_late(dev) : 0;
163 EXPORT_SYMBOL_GPL(pm_generic_poweroff_late);
166 * pm_generic_poweroff - Generic poweroff callback for subsystems.
167 * @dev: Device to handle.
169 int pm_generic_poweroff(struct device *dev)
171 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
173 return pm && pm->poweroff ? pm->poweroff(dev) : 0;
175 EXPORT_SYMBOL_GPL(pm_generic_poweroff);
178 * pm_generic_thaw_noirq - Generic thaw_noirq callback for subsystems.
179 * @dev: Device to thaw.
181 int pm_generic_thaw_noirq(struct device *dev)
183 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
185 return pm && pm->thaw_noirq ? pm->thaw_noirq(dev) : 0;
187 EXPORT_SYMBOL_GPL(pm_generic_thaw_noirq);
190 * pm_generic_thaw_early - Generic thaw_early callback for subsystems.
191 * @dev: Device to thaw.
193 int pm_generic_thaw_early(struct device *dev)
195 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
197 return pm && pm->thaw_early ? pm->thaw_early(dev) : 0;
199 EXPORT_SYMBOL_GPL(pm_generic_thaw_early);
202 * pm_generic_thaw - Generic thaw callback for subsystems.
203 * @dev: Device to thaw.
205 int pm_generic_thaw(struct device *dev)
207 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
209 return pm && pm->thaw ? pm->thaw(dev) : 0;
211 EXPORT_SYMBOL_GPL(pm_generic_thaw);
214 * pm_generic_resume_noirq - Generic resume_noirq callback for subsystems.
215 * @dev: Device to resume.
217 int pm_generic_resume_noirq(struct device *dev)
219 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
221 return pm && pm->resume_noirq ? pm->resume_noirq(dev) : 0;
223 EXPORT_SYMBOL_GPL(pm_generic_resume_noirq);
226 * pm_generic_resume_early - Generic resume_early callback for subsystems.
227 * @dev: Device to resume.
229 int pm_generic_resume_early(struct device *dev)
231 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
233 return pm && pm->resume_early ? pm->resume_early(dev) : 0;
235 EXPORT_SYMBOL_GPL(pm_generic_resume_early);
238 * pm_generic_resume - Generic resume callback for subsystems.
239 * @dev: Device to resume.
241 int pm_generic_resume(struct device *dev)
243 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
245 return pm && pm->resume ? pm->resume(dev) : 0;
247 EXPORT_SYMBOL_GPL(pm_generic_resume);
250 * pm_generic_restore_noirq - Generic restore_noirq callback for subsystems.
251 * @dev: Device to restore.
253 int pm_generic_restore_noirq(struct device *dev)
255 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
257 return pm && pm->restore_noirq ? pm->restore_noirq(dev) : 0;
259 EXPORT_SYMBOL_GPL(pm_generic_restore_noirq);
262 * pm_generic_restore_early - Generic restore_early callback for subsystems.
263 * @dev: Device to resume.
265 int pm_generic_restore_early(struct device *dev)
267 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
269 return pm && pm->restore_early ? pm->restore_early(dev) : 0;
271 EXPORT_SYMBOL_GPL(pm_generic_restore_early);
274 * pm_generic_restore - Generic restore callback for subsystems.
275 * @dev: Device to restore.
277 int pm_generic_restore(struct device *dev)
279 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
281 return pm && pm->restore ? pm->restore(dev) : 0;
283 EXPORT_SYMBOL_GPL(pm_generic_restore);
286 * pm_generic_complete - Generic routine completing a device power transition.
287 * @dev: Device to handle.
289 * Complete a device power transition during a system-wide power transition.
291 void pm_generic_complete(struct device *dev)
293 struct device_driver *drv = dev->driver;
295 if (drv && drv->pm && drv->pm->complete)
296 drv->pm->complete(dev);
298 #endif /* CONFIG_PM_SLEEP */