blob: 96a92db83cad863ac286ce2249b573bb7c1085a6 [file] [log] [blame]
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +01001/*
2 * drivers/base/power/generic_ops.c - Generic PM callbacks for subsystems
3 *
4 * Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
5 *
6 * This file is released under the GPLv2.
7 */
8
9#include <linux/pm.h>
10#include <linux/pm_runtime.h>
Paul Gortmaker1b6bc322011-05-27 07:12:15 -040011#include <linux/export.h>
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010012
Ulf Hansson717e5d42013-12-10 14:37:41 +010013#ifdef CONFIG_PM
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010014/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010015 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
16 * @dev: Device to suspend.
17 *
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,
Aaro Koskinen6675bc02010-11-25 23:41:19 +010020 * return 0.
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010021 */
22int pm_generic_runtime_suspend(struct device *dev)
23{
24 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
25 int ret;
26
Ohad Ben-Cohen05aa55d2010-09-09 00:46:16 +020027 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010028
29 return ret;
30}
31EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
32
33/**
34 * pm_generic_runtime_resume - Generic runtime resume callback for subsystems.
35 * @dev: Device to resume.
36 *
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,
Aaro Koskinen6675bc02010-11-25 23:41:19 +010039 * return 0.
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010040 */
41int pm_generic_runtime_resume(struct device *dev)
42{
43 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
44 int ret;
45
Ohad Ben-Cohen05aa55d2010-09-09 00:46:16 +020046 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010047
48 return ret;
49}
50EXPORT_SYMBOL_GPL(pm_generic_runtime_resume);
Ulf Hansson717e5d42013-12-10 14:37:41 +010051#endif /* CONFIG_PM */
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010052
53#ifdef CONFIG_PM_SLEEP
54/**
Rafael J. Wysocki6538df82011-05-17 23:26:21 +020055 * pm_generic_prepare - Generic routine preparing a device for power transition.
56 * @dev: Device to prepare.
57 *
58 * Prepare a device for a system-wide power transition.
59 */
60int pm_generic_prepare(struct device *dev)
61{
62 struct device_driver *drv = dev->driver;
63 int ret = 0;
64
65 if (drv && drv->pm && drv->pm->prepare)
66 ret = drv->pm->prepare(dev);
67
68 return ret;
69}
70
71/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +020072 * pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems.
73 * @dev: Device to suspend.
74 */
75int pm_generic_suspend_noirq(struct device *dev)
76{
Rafael J. Wysockie470d062012-01-29 20:38:41 +010077 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
78
79 return pm && pm->suspend_noirq ? pm->suspend_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +020080}
81EXPORT_SYMBOL_GPL(pm_generic_suspend_noirq);
82
83/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +010084 * pm_generic_suspend_late - Generic suspend_late callback for subsystems.
85 * @dev: Device to suspend.
86 */
87int pm_generic_suspend_late(struct device *dev)
88{
89 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
90
91 return pm && pm->suspend_late ? pm->suspend_late(dev) : 0;
92}
93EXPORT_SYMBOL_GPL(pm_generic_suspend_late);
94
95/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010096 * pm_generic_suspend - Generic suspend callback for subsystems.
97 * @dev: Device to suspend.
98 */
99int pm_generic_suspend(struct device *dev)
100{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100101 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
102
103 return pm && pm->suspend ? pm->suspend(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100104}
105EXPORT_SYMBOL_GPL(pm_generic_suspend);
106
107/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200108 * pm_generic_freeze_noirq - Generic freeze_noirq callback for subsystems.
109 * @dev: Device to freeze.
110 */
111int pm_generic_freeze_noirq(struct device *dev)
112{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100113 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
114
115 return pm && pm->freeze_noirq ? pm->freeze_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200116}
117EXPORT_SYMBOL_GPL(pm_generic_freeze_noirq);
118
119/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100120 * pm_generic_freeze_late - Generic freeze_late callback for subsystems.
121 * @dev: Device to freeze.
122 */
123int pm_generic_freeze_late(struct device *dev)
124{
125 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
126
127 return pm && pm->freeze_late ? pm->freeze_late(dev) : 0;
128}
129EXPORT_SYMBOL_GPL(pm_generic_freeze_late);
130
131/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100132 * pm_generic_freeze - Generic freeze callback for subsystems.
133 * @dev: Device to freeze.
134 */
135int pm_generic_freeze(struct device *dev)
136{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100137 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
138
139 return pm && pm->freeze ? pm->freeze(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100140}
141EXPORT_SYMBOL_GPL(pm_generic_freeze);
142
143/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200144 * pm_generic_poweroff_noirq - Generic poweroff_noirq callback for subsystems.
145 * @dev: Device to handle.
146 */
147int pm_generic_poweroff_noirq(struct device *dev)
148{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100149 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
150
151 return pm && pm->poweroff_noirq ? pm->poweroff_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200152}
153EXPORT_SYMBOL_GPL(pm_generic_poweroff_noirq);
154
155/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100156 * pm_generic_poweroff_late - Generic poweroff_late callback for subsystems.
157 * @dev: Device to handle.
158 */
159int pm_generic_poweroff_late(struct device *dev)
160{
161 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
162
163 return pm && pm->poweroff_late ? pm->poweroff_late(dev) : 0;
164}
165EXPORT_SYMBOL_GPL(pm_generic_poweroff_late);
166
167/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100168 * pm_generic_poweroff - Generic poweroff callback for subsystems.
169 * @dev: Device to handle.
170 */
171int pm_generic_poweroff(struct device *dev)
172{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100173 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
174
175 return pm && pm->poweroff ? pm->poweroff(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100176}
177EXPORT_SYMBOL_GPL(pm_generic_poweroff);
178
179/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200180 * pm_generic_thaw_noirq - Generic thaw_noirq callback for subsystems.
181 * @dev: Device to thaw.
182 */
183int pm_generic_thaw_noirq(struct device *dev)
184{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100185 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
186
187 return pm && pm->thaw_noirq ? pm->thaw_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200188}
189EXPORT_SYMBOL_GPL(pm_generic_thaw_noirq);
190
191/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100192 * pm_generic_thaw_early - Generic thaw_early callback for subsystems.
193 * @dev: Device to thaw.
194 */
195int pm_generic_thaw_early(struct device *dev)
196{
197 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
198
199 return pm && pm->thaw_early ? pm->thaw_early(dev) : 0;
200}
201EXPORT_SYMBOL_GPL(pm_generic_thaw_early);
202
203/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100204 * pm_generic_thaw - Generic thaw callback for subsystems.
205 * @dev: Device to thaw.
206 */
207int pm_generic_thaw(struct device *dev)
208{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100209 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
210
211 return pm && pm->thaw ? pm->thaw(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100212}
213EXPORT_SYMBOL_GPL(pm_generic_thaw);
214
215/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200216 * pm_generic_resume_noirq - Generic resume_noirq callback for subsystems.
217 * @dev: Device to resume.
218 */
219int pm_generic_resume_noirq(struct device *dev)
220{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100221 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
222
223 return pm && pm->resume_noirq ? pm->resume_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200224}
225EXPORT_SYMBOL_GPL(pm_generic_resume_noirq);
226
227/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100228 * pm_generic_resume_early - Generic resume_early callback for subsystems.
229 * @dev: Device to resume.
230 */
231int pm_generic_resume_early(struct device *dev)
232{
233 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
234
235 return pm && pm->resume_early ? pm->resume_early(dev) : 0;
236}
237EXPORT_SYMBOL_GPL(pm_generic_resume_early);
238
239/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100240 * pm_generic_resume - Generic resume callback for subsystems.
241 * @dev: Device to resume.
242 */
243int pm_generic_resume(struct device *dev)
244{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100245 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
246
247 return pm && pm->resume ? pm->resume(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100248}
249EXPORT_SYMBOL_GPL(pm_generic_resume);
250
251/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200252 * pm_generic_restore_noirq - Generic restore_noirq callback for subsystems.
253 * @dev: Device to restore.
254 */
255int pm_generic_restore_noirq(struct device *dev)
256{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100257 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
258
259 return pm && pm->restore_noirq ? pm->restore_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200260}
261EXPORT_SYMBOL_GPL(pm_generic_restore_noirq);
262
263/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100264 * pm_generic_restore_early - Generic restore_early callback for subsystems.
265 * @dev: Device to resume.
266 */
267int pm_generic_restore_early(struct device *dev)
268{
269 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
270
271 return pm && pm->restore_early ? pm->restore_early(dev) : 0;
272}
273EXPORT_SYMBOL_GPL(pm_generic_restore_early);
274
275/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100276 * pm_generic_restore - Generic restore callback for subsystems.
277 * @dev: Device to restore.
278 */
279int pm_generic_restore(struct device *dev)
280{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100281 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
282
283 return pm && pm->restore ? pm->restore(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100284}
285EXPORT_SYMBOL_GPL(pm_generic_restore);
Rafael J. Wysocki6538df82011-05-17 23:26:21 +0200286
287/**
Geert Uytterhoeven9accff52014-03-24 21:37:03 +0100288 * pm_generic_complete - Generic routine completing a device power transition.
Rafael J. Wysocki6538df82011-05-17 23:26:21 +0200289 * @dev: Device to handle.
290 *
291 * Complete a device power transition during a system-wide power transition.
292 */
293void pm_generic_complete(struct device *dev)
294{
295 struct device_driver *drv = dev->driver;
296
297 if (drv && drv->pm && drv->pm->complete)
298 drv->pm->complete(dev);
299
300 /*
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.
303 */
Ulf Hanssonaf939332013-04-12 09:41:06 +0000304 pm_request_idle(dev);
Rafael J. Wysocki6538df82011-05-17 23:26:21 +0200305}
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100306#endif /* CONFIG_PM_SLEEP */