sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / base / power / generic_ops.c
blob07c3c4a9522d4e6bec1f0f540bd38f8c1ce6ed00
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>
12 #include <linux/suspend.h>
14 #ifdef CONFIG_PM
15 /**
16 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
17 * @dev: Device to suspend.
19 * If PM operations are defined for the @dev's driver and they include
20 * ->runtime_suspend(), execute it and return its error code. Otherwise,
21 * return 0.
23 int pm_generic_runtime_suspend(struct device *dev)
25 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
26 int ret;
28 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0;
30 return ret;
32 EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
34 /**
35 * pm_generic_runtime_resume - Generic runtime resume callback for subsystems.
36 * @dev: Device to resume.
38 * If PM operations are defined for the @dev's driver and they include
39 * ->runtime_resume(), execute it and return its error code. Otherwise,
40 * return 0.
42 int pm_generic_runtime_resume(struct device *dev)
44 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
45 int ret;
47 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0;
49 return ret;
51 EXPORT_SYMBOL_GPL(pm_generic_runtime_resume);
52 #endif /* CONFIG_PM */
54 #ifdef CONFIG_PM_SLEEP
55 /**
56 * pm_generic_prepare - Generic routine preparing a device for power transition.
57 * @dev: Device to prepare.
59 * Prepare a device for a system-wide power transition.
61 int pm_generic_prepare(struct device *dev)
63 struct device_driver *drv = dev->driver;
64 int ret = 0;
66 if (drv && drv->pm && drv->pm->prepare)
67 ret = drv->pm->prepare(dev);
69 return ret;
72 /**
73 * pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems.
74 * @dev: Device to suspend.
76 int pm_generic_suspend_noirq(struct device *dev)
78 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
80 return pm && pm->suspend_noirq ? pm->suspend_noirq(dev) : 0;
82 EXPORT_SYMBOL_GPL(pm_generic_suspend_noirq);
84 /**
85 * pm_generic_suspend_late - Generic suspend_late callback for subsystems.
86 * @dev: Device to suspend.
88 int pm_generic_suspend_late(struct device *dev)
90 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
92 return pm && pm->suspend_late ? pm->suspend_late(dev) : 0;
94 EXPORT_SYMBOL_GPL(pm_generic_suspend_late);
96 /**
97 * pm_generic_suspend - Generic suspend callback for subsystems.
98 * @dev: Device to suspend.
100 int pm_generic_suspend(struct device *dev)
102 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
104 return pm && pm->suspend ? pm->suspend(dev) : 0;
106 EXPORT_SYMBOL_GPL(pm_generic_suspend);
109 * pm_generic_freeze_noirq - Generic freeze_noirq callback for subsystems.
110 * @dev: Device to freeze.
112 int pm_generic_freeze_noirq(struct device *dev)
114 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
116 return pm && pm->freeze_noirq ? pm->freeze_noirq(dev) : 0;
118 EXPORT_SYMBOL_GPL(pm_generic_freeze_noirq);
121 * pm_generic_freeze_late - Generic freeze_late callback for subsystems.
122 * @dev: Device to freeze.
124 int pm_generic_freeze_late(struct device *dev)
126 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
128 return pm && pm->freeze_late ? pm->freeze_late(dev) : 0;
130 EXPORT_SYMBOL_GPL(pm_generic_freeze_late);
133 * pm_generic_freeze - Generic freeze callback for subsystems.
134 * @dev: Device to freeze.
136 int pm_generic_freeze(struct device *dev)
138 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
140 return pm && pm->freeze ? pm->freeze(dev) : 0;
142 EXPORT_SYMBOL_GPL(pm_generic_freeze);
145 * pm_generic_poweroff_noirq - Generic poweroff_noirq callback for subsystems.
146 * @dev: Device to handle.
148 int pm_generic_poweroff_noirq(struct device *dev)
150 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
152 return pm && pm->poweroff_noirq ? pm->poweroff_noirq(dev) : 0;
154 EXPORT_SYMBOL_GPL(pm_generic_poweroff_noirq);
157 * pm_generic_poweroff_late - Generic poweroff_late callback for subsystems.
158 * @dev: Device to handle.
160 int pm_generic_poweroff_late(struct device *dev)
162 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
164 return pm && pm->poweroff_late ? pm->poweroff_late(dev) : 0;
166 EXPORT_SYMBOL_GPL(pm_generic_poweroff_late);
169 * pm_generic_poweroff - Generic poweroff callback for subsystems.
170 * @dev: Device to handle.
172 int pm_generic_poweroff(struct device *dev)
174 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
176 return pm && pm->poweroff ? pm->poweroff(dev) : 0;
178 EXPORT_SYMBOL_GPL(pm_generic_poweroff);
181 * pm_generic_thaw_noirq - Generic thaw_noirq callback for subsystems.
182 * @dev: Device to thaw.
184 int pm_generic_thaw_noirq(struct device *dev)
186 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
188 return pm && pm->thaw_noirq ? pm->thaw_noirq(dev) : 0;
190 EXPORT_SYMBOL_GPL(pm_generic_thaw_noirq);
193 * pm_generic_thaw_early - Generic thaw_early callback for subsystems.
194 * @dev: Device to thaw.
196 int pm_generic_thaw_early(struct device *dev)
198 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
200 return pm && pm->thaw_early ? pm->thaw_early(dev) : 0;
202 EXPORT_SYMBOL_GPL(pm_generic_thaw_early);
205 * pm_generic_thaw - Generic thaw callback for subsystems.
206 * @dev: Device to thaw.
208 int pm_generic_thaw(struct device *dev)
210 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
212 return pm && pm->thaw ? pm->thaw(dev) : 0;
214 EXPORT_SYMBOL_GPL(pm_generic_thaw);
217 * pm_generic_resume_noirq - Generic resume_noirq callback for subsystems.
218 * @dev: Device to resume.
220 int pm_generic_resume_noirq(struct device *dev)
222 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
224 return pm && pm->resume_noirq ? pm->resume_noirq(dev) : 0;
226 EXPORT_SYMBOL_GPL(pm_generic_resume_noirq);
229 * pm_generic_resume_early - Generic resume_early callback for subsystems.
230 * @dev: Device to resume.
232 int pm_generic_resume_early(struct device *dev)
234 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
236 return pm && pm->resume_early ? pm->resume_early(dev) : 0;
238 EXPORT_SYMBOL_GPL(pm_generic_resume_early);
241 * pm_generic_resume - Generic resume callback for subsystems.
242 * @dev: Device to resume.
244 int pm_generic_resume(struct device *dev)
246 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
248 return pm && pm->resume ? pm->resume(dev) : 0;
250 EXPORT_SYMBOL_GPL(pm_generic_resume);
253 * pm_generic_restore_noirq - Generic restore_noirq callback for subsystems.
254 * @dev: Device to restore.
256 int pm_generic_restore_noirq(struct device *dev)
258 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
260 return pm && pm->restore_noirq ? pm->restore_noirq(dev) : 0;
262 EXPORT_SYMBOL_GPL(pm_generic_restore_noirq);
265 * pm_generic_restore_early - Generic restore_early callback for subsystems.
266 * @dev: Device to resume.
268 int pm_generic_restore_early(struct device *dev)
270 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
272 return pm && pm->restore_early ? pm->restore_early(dev) : 0;
274 EXPORT_SYMBOL_GPL(pm_generic_restore_early);
277 * pm_generic_restore - Generic restore callback for subsystems.
278 * @dev: Device to restore.
280 int pm_generic_restore(struct device *dev)
282 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
284 return pm && pm->restore ? pm->restore(dev) : 0;
286 EXPORT_SYMBOL_GPL(pm_generic_restore);
289 * pm_generic_complete - Generic routine completing a device power transition.
290 * @dev: Device to handle.
292 * Complete a device power transition during a system-wide power transition.
294 void pm_generic_complete(struct device *dev)
296 struct device_driver *drv = dev->driver;
298 if (drv && drv->pm && drv->pm->complete)
299 drv->pm->complete(dev);
303 * pm_complete_with_resume_check - Complete a device power transition.
304 * @dev: Device to handle.
306 * Complete a device power transition during a system-wide power transition and
307 * optionally schedule a runtime resume of the device if the system resume in
308 * progress has been initated by the platform firmware and the device had its
309 * power.direct_complete flag set.
311 void pm_complete_with_resume_check(struct device *dev)
313 pm_generic_complete(dev);
315 * If the device had been runtime-suspended before the system went into
316 * the sleep state it is going out of and it has never been resumed till
317 * now, resume it in case the firmware powered it up.
319 if (dev->power.direct_complete && pm_resume_via_firmware())
320 pm_request_resume(dev);
322 EXPORT_SYMBOL_GPL(pm_complete_with_resume_check);
323 #endif /* CONFIG_PM_SLEEP */