Staging: netwave: delete the driver
[linux/fpc-iii.git] / drivers / base / power / generic_ops.c
blob4b29d4981253a22d8386b50dd74ca1a046ca6682
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>
12 #ifdef CONFIG_PM_RUNTIME
13 /**
14 * pm_generic_runtime_idle - Generic runtime idle callback for subsystems.
15 * @dev: Device to handle.
17 * If PM operations are defined for the @dev's driver and they include
18 * ->runtime_idle(), execute it and return its error code, if nonzero.
19 * Otherwise, execute pm_runtime_suspend() for the device and return 0.
21 int pm_generic_runtime_idle(struct device *dev)
23 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
25 if (pm && pm->runtime_idle) {
26 int ret = pm->runtime_idle(dev);
27 if (ret)
28 return ret;
31 pm_runtime_suspend(dev);
32 return 0;
34 EXPORT_SYMBOL_GPL(pm_generic_runtime_idle);
36 /**
37 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
38 * @dev: Device to suspend.
40 * If PM operations are defined for the @dev's driver and they include
41 * ->runtime_suspend(), execute it and return its error code. Otherwise,
42 * return -EINVAL.
44 int pm_generic_runtime_suspend(struct device *dev)
46 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
47 int ret;
49 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : -EINVAL;
51 return ret;
53 EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
55 /**
56 * pm_generic_runtime_resume - Generic runtime resume callback for subsystems.
57 * @dev: Device to resume.
59 * If PM operations are defined for the @dev's driver and they include
60 * ->runtime_resume(), execute it and return its error code. Otherwise,
61 * return -EINVAL.
63 int pm_generic_runtime_resume(struct device *dev)
65 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
66 int ret;
68 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : -EINVAL;
70 return ret;
72 EXPORT_SYMBOL_GPL(pm_generic_runtime_resume);
73 #endif /* CONFIG_PM_RUNTIME */
75 #ifdef CONFIG_PM_SLEEP
76 /**
77 * __pm_generic_call - Generic suspend/freeze/poweroff/thaw subsystem callback.
78 * @dev: Device to handle.
79 * @event: PM transition of the system under way.
81 * If the device has not been suspended at run time, execute the
82 * suspend/freeze/poweroff/thaw callback provided by its driver, if defined, and
83 * return its error code. Otherwise, return zero.
85 static int __pm_generic_call(struct device *dev, int event)
87 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
88 int (*callback)(struct device *);
90 if (!pm || pm_runtime_suspended(dev))
91 return 0;
93 switch (event) {
94 case PM_EVENT_SUSPEND:
95 callback = pm->suspend;
96 break;
97 case PM_EVENT_FREEZE:
98 callback = pm->freeze;
99 break;
100 case PM_EVENT_HIBERNATE:
101 callback = pm->poweroff;
102 break;
103 case PM_EVENT_THAW:
104 callback = pm->thaw;
105 break;
106 default:
107 callback = NULL;
108 break;
111 return callback ? callback(dev) : 0;
115 * pm_generic_suspend - Generic suspend callback for subsystems.
116 * @dev: Device to suspend.
118 int pm_generic_suspend(struct device *dev)
120 return __pm_generic_call(dev, PM_EVENT_SUSPEND);
122 EXPORT_SYMBOL_GPL(pm_generic_suspend);
125 * pm_generic_freeze - Generic freeze callback for subsystems.
126 * @dev: Device to freeze.
128 int pm_generic_freeze(struct device *dev)
130 return __pm_generic_call(dev, PM_EVENT_FREEZE);
132 EXPORT_SYMBOL_GPL(pm_generic_freeze);
135 * pm_generic_poweroff - Generic poweroff callback for subsystems.
136 * @dev: Device to handle.
138 int pm_generic_poweroff(struct device *dev)
140 return __pm_generic_call(dev, PM_EVENT_HIBERNATE);
142 EXPORT_SYMBOL_GPL(pm_generic_poweroff);
145 * pm_generic_thaw - Generic thaw callback for subsystems.
146 * @dev: Device to thaw.
148 int pm_generic_thaw(struct device *dev)
150 return __pm_generic_call(dev, PM_EVENT_THAW);
152 EXPORT_SYMBOL_GPL(pm_generic_thaw);
155 * __pm_generic_resume - Generic resume/restore callback for subsystems.
156 * @dev: Device to handle.
157 * @event: PM transition of the system under way.
159 * Execute the resume/resotre callback provided by the @dev's driver, if
160 * defined. If it returns 0, change the device's runtime PM status to 'active'.
161 * Return the callback's error code.
163 static int __pm_generic_resume(struct device *dev, int event)
165 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
166 int (*callback)(struct device *);
167 int ret;
169 if (!pm)
170 return 0;
172 switch (event) {
173 case PM_EVENT_RESUME:
174 callback = pm->resume;
175 break;
176 case PM_EVENT_RESTORE:
177 callback = pm->restore;
178 break;
179 default:
180 callback = NULL;
181 break;
184 if (!callback)
185 return 0;
187 ret = callback(dev);
188 if (!ret) {
189 pm_runtime_disable(dev);
190 pm_runtime_set_active(dev);
191 pm_runtime_enable(dev);
194 return ret;
198 * pm_generic_resume - Generic resume callback for subsystems.
199 * @dev: Device to resume.
201 int pm_generic_resume(struct device *dev)
203 return __pm_generic_resume(dev, PM_EVENT_RESUME);
205 EXPORT_SYMBOL_GPL(pm_generic_resume);
208 * pm_generic_restore - Generic restore callback for subsystems.
209 * @dev: Device to restore.
211 int pm_generic_restore(struct device *dev)
213 return __pm_generic_resume(dev, PM_EVENT_RESTORE);
215 EXPORT_SYMBOL_GPL(pm_generic_restore);
216 #endif /* CONFIG_PM_SLEEP */
218 struct dev_pm_ops generic_subsys_pm_ops = {
219 #ifdef CONFIG_PM_SLEEP
220 .suspend = pm_generic_suspend,
221 .resume = pm_generic_resume,
222 .freeze = pm_generic_freeze,
223 .thaw = pm_generic_thaw,
224 .poweroff = pm_generic_poweroff,
225 .restore = pm_generic_restore,
226 #endif
227 #ifdef CONFIG_PM_RUNTIME
228 .runtime_suspend = pm_generic_runtime_suspend,
229 .runtime_resume = pm_generic_runtime_resume,
230 .runtime_idle = pm_generic_runtime_idle,
231 #endif
233 EXPORT_SYMBOL_GPL(generic_subsys_pm_ops);