x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / base / power / generic_ops.c
blob5ee030a864f9266bb6c8ea18dd897e736fd2727c
1 /*
2 * drivers/base/power/generic_ops.c - Generic PM callbacks for subsystems
4 * Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
6 * This file is released under the GPLv2.
7 */
9 #include <linux/pm.h>
10 #include <linux/pm_runtime.h>
11 #include <linux/export.h>
13 #ifdef CONFIG_PM_RUNTIME
14 /**
15 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
16 * @dev: Device to suspend.
18 * If PM operations are defined for the @dev's driver and they include
19 * ->runtime_suspend(), execute it and return its error code. Otherwise,
20 * return 0.
22 int pm_generic_runtime_suspend(struct device *dev)
24 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
25 int ret;
27 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0;
29 return ret;
31 EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
33 /**
34 * pm_generic_runtime_resume - Generic runtime resume callback for subsystems.
35 * @dev: Device to resume.
37 * If PM operations are defined for the @dev's driver and they include
38 * ->runtime_resume(), execute it and return its error code. Otherwise,
39 * return 0.
41 int pm_generic_runtime_resume(struct device *dev)
43 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
44 int ret;
46 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0;
48 return ret;
50 EXPORT_SYMBOL_GPL(pm_generic_runtime_resume);
51 #endif /* CONFIG_PM_RUNTIME */
53 #ifdef CONFIG_PM_SLEEP
54 /**
55 * pm_generic_prepare - Generic routine preparing a device for power transition.
56 * @dev: Device to prepare.
58 * Prepare a device for a system-wide power transition.
60 int pm_generic_prepare(struct device *dev)
62 struct device_driver *drv = dev->driver;
63 int ret = 0;
65 if (drv && drv->pm && drv->pm->prepare)
66 ret = drv->pm->prepare(dev);
68 return ret;
71 /**
72 * pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems.
73 * @dev: Device to suspend.
75 int pm_generic_suspend_noirq(struct device *dev)
77 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
79 return pm && pm->suspend_noirq ? pm->suspend_noirq(dev) : 0;
81 EXPORT_SYMBOL_GPL(pm_generic_suspend_noirq);
83 /**
84 * pm_generic_suspend_late - Generic suspend_late callback for subsystems.
85 * @dev: Device to suspend.
87 int pm_generic_suspend_late(struct device *dev)
89 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
91 return pm && pm->suspend_late ? pm->suspend_late(dev) : 0;
93 EXPORT_SYMBOL_GPL(pm_generic_suspend_late);
95 /**
96 * pm_generic_suspend - Generic suspend callback for subsystems.
97 * @dev: Device to suspend.
99 int pm_generic_suspend(struct device *dev)
101 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
103 return pm && pm->suspend ? pm->suspend(dev) : 0;
105 EXPORT_SYMBOL_GPL(pm_generic_suspend);
108 * pm_generic_freeze_noirq - Generic freeze_noirq callback for subsystems.
109 * @dev: Device to freeze.
111 int pm_generic_freeze_noirq(struct device *dev)
113 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
115 return pm && pm->freeze_noirq ? pm->freeze_noirq(dev) : 0;
117 EXPORT_SYMBOL_GPL(pm_generic_freeze_noirq);
120 * pm_generic_freeze_late - Generic freeze_late callback for subsystems.
121 * @dev: Device to freeze.
123 int pm_generic_freeze_late(struct device *dev)
125 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
127 return pm && pm->freeze_late ? pm->freeze_late(dev) : 0;
129 EXPORT_SYMBOL_GPL(pm_generic_freeze_late);
132 * pm_generic_freeze - Generic freeze callback for subsystems.
133 * @dev: Device to freeze.
135 int pm_generic_freeze(struct device *dev)
137 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
139 return pm && pm->freeze ? pm->freeze(dev) : 0;
141 EXPORT_SYMBOL_GPL(pm_generic_freeze);
144 * pm_generic_poweroff_noirq - Generic poweroff_noirq callback for subsystems.
145 * @dev: Device to handle.
147 int pm_generic_poweroff_noirq(struct device *dev)
149 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
151 return pm && pm->poweroff_noirq ? pm->poweroff_noirq(dev) : 0;
153 EXPORT_SYMBOL_GPL(pm_generic_poweroff_noirq);
156 * pm_generic_poweroff_late - Generic poweroff_late callback for subsystems.
157 * @dev: Device to handle.
159 int pm_generic_poweroff_late(struct device *dev)
161 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
163 return pm && pm->poweroff_late ? pm->poweroff_late(dev) : 0;
165 EXPORT_SYMBOL_GPL(pm_generic_poweroff_late);
168 * pm_generic_poweroff - Generic poweroff callback for subsystems.
169 * @dev: Device to handle.
171 int pm_generic_poweroff(struct device *dev)
173 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
175 return pm && pm->poweroff ? pm->poweroff(dev) : 0;
177 EXPORT_SYMBOL_GPL(pm_generic_poweroff);
180 * pm_generic_thaw_noirq - Generic thaw_noirq callback for subsystems.
181 * @dev: Device to thaw.
183 int pm_generic_thaw_noirq(struct device *dev)
185 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
187 return pm && pm->thaw_noirq ? pm->thaw_noirq(dev) : 0;
189 EXPORT_SYMBOL_GPL(pm_generic_thaw_noirq);
192 * pm_generic_thaw_early - Generic thaw_early callback for subsystems.
193 * @dev: Device to thaw.
195 int pm_generic_thaw_early(struct device *dev)
197 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
199 return pm && pm->thaw_early ? pm->thaw_early(dev) : 0;
201 EXPORT_SYMBOL_GPL(pm_generic_thaw_early);
204 * pm_generic_thaw - Generic thaw callback for subsystems.
205 * @dev: Device to thaw.
207 int pm_generic_thaw(struct device *dev)
209 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
211 return pm && pm->thaw ? pm->thaw(dev) : 0;
213 EXPORT_SYMBOL_GPL(pm_generic_thaw);
216 * pm_generic_resume_noirq - Generic resume_noirq callback for subsystems.
217 * @dev: Device to resume.
219 int pm_generic_resume_noirq(struct device *dev)
221 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
223 return pm && pm->resume_noirq ? pm->resume_noirq(dev) : 0;
225 EXPORT_SYMBOL_GPL(pm_generic_resume_noirq);
228 * pm_generic_resume_early - Generic resume_early callback for subsystems.
229 * @dev: Device to resume.
231 int pm_generic_resume_early(struct device *dev)
233 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
235 return pm && pm->resume_early ? pm->resume_early(dev) : 0;
237 EXPORT_SYMBOL_GPL(pm_generic_resume_early);
240 * pm_generic_resume - Generic resume callback for subsystems.
241 * @dev: Device to resume.
243 int pm_generic_resume(struct device *dev)
245 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
247 return pm && pm->resume ? pm->resume(dev) : 0;
249 EXPORT_SYMBOL_GPL(pm_generic_resume);
252 * pm_generic_restore_noirq - Generic restore_noirq callback for subsystems.
253 * @dev: Device to restore.
255 int pm_generic_restore_noirq(struct device *dev)
257 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
259 return pm && pm->restore_noirq ? pm->restore_noirq(dev) : 0;
261 EXPORT_SYMBOL_GPL(pm_generic_restore_noirq);
264 * pm_generic_restore_early - Generic restore_early callback for subsystems.
265 * @dev: Device to resume.
267 int pm_generic_restore_early(struct device *dev)
269 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
271 return pm && pm->restore_early ? pm->restore_early(dev) : 0;
273 EXPORT_SYMBOL_GPL(pm_generic_restore_early);
276 * pm_generic_restore - Generic restore callback for subsystems.
277 * @dev: Device to restore.
279 int pm_generic_restore(struct device *dev)
281 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
283 return pm && pm->restore ? pm->restore(dev) : 0;
285 EXPORT_SYMBOL_GPL(pm_generic_restore);
288 * pm_generic_complete - Generic routine competing a device power transition.
289 * @dev: Device to handle.
291 * Complete a device power transition during a system-wide power transition.
293 void pm_generic_complete(struct device *dev)
295 struct device_driver *drv = dev->driver;
297 if (drv && drv->pm && drv->pm->complete)
298 drv->pm->complete(dev);
301 * Let runtime PM try to suspend devices that haven't been in use before
302 * going into the system-wide sleep state we're resuming from.
304 pm_request_idle(dev);
306 #endif /* CONFIG_PM_SLEEP */