blob: 4fa525668cb70ab0377d2d255b6829e7fd520f0f [file] [log] [blame]
Greg Kroah-Hartman5de363b2019-04-02 15:32:01 +02001// SPDX-License-Identifier: GPL-2.0
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +01002/*
3 * drivers/base/power/generic_ops.c - Generic PM callbacks for subsystems
4 *
5 * Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +01006 */
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +01007#include <linux/pm.h>
8#include <linux/pm_runtime.h>
Paul Gortmaker1b6bc322011-05-27 07:12:15 -04009#include <linux/export.h>
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010010
Ulf Hansson717e5d42013-12-10 14:37:41 +010011#ifdef CONFIG_PM
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010012/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010013 * pm_generic_runtime_suspend - Generic runtime suspend callback for subsystems.
14 * @dev: Device to suspend.
15 *
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,
Aaro Koskinen6675bc02010-11-25 23:41:19 +010018 * return 0.
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010019 */
20int pm_generic_runtime_suspend(struct device *dev)
21{
22 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
23 int ret;
24
Ohad Ben-Cohen05aa55d2010-09-09 00:46:16 +020025 ret = pm && pm->runtime_suspend ? pm->runtime_suspend(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010026
27 return ret;
28}
29EXPORT_SYMBOL_GPL(pm_generic_runtime_suspend);
30
31/**
32 * pm_generic_runtime_resume - Generic runtime resume callback for subsystems.
33 * @dev: Device to resume.
34 *
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,
Aaro Koskinen6675bc02010-11-25 23:41:19 +010037 * return 0.
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010038 */
39int pm_generic_runtime_resume(struct device *dev)
40{
41 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
42 int ret;
43
Ohad Ben-Cohen05aa55d2010-09-09 00:46:16 +020044 ret = pm && pm->runtime_resume ? pm->runtime_resume(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010045
46 return ret;
47}
48EXPORT_SYMBOL_GPL(pm_generic_runtime_resume);
Ulf Hansson717e5d42013-12-10 14:37:41 +010049#endif /* CONFIG_PM */
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010050
51#ifdef CONFIG_PM_SLEEP
52/**
Rafael J. Wysocki6538df82011-05-17 23:26:21 +020053 * pm_generic_prepare - Generic routine preparing a device for power transition.
54 * @dev: Device to prepare.
55 *
56 * Prepare a device for a system-wide power transition.
57 */
58int pm_generic_prepare(struct device *dev)
59{
60 struct device_driver *drv = dev->driver;
61 int ret = 0;
62
63 if (drv && drv->pm && drv->pm->prepare)
64 ret = drv->pm->prepare(dev);
65
66 return ret;
67}
68
69/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +020070 * pm_generic_suspend_noirq - Generic suspend_noirq callback for subsystems.
71 * @dev: Device to suspend.
72 */
73int pm_generic_suspend_noirq(struct device *dev)
74{
Rafael J. Wysockie470d062012-01-29 20:38:41 +010075 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
76
77 return pm && pm->suspend_noirq ? pm->suspend_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +020078}
79EXPORT_SYMBOL_GPL(pm_generic_suspend_noirq);
80
81/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +010082 * pm_generic_suspend_late - Generic suspend_late callback for subsystems.
83 * @dev: Device to suspend.
84 */
85int pm_generic_suspend_late(struct device *dev)
86{
87 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
88
89 return pm && pm->suspend_late ? pm->suspend_late(dev) : 0;
90}
91EXPORT_SYMBOL_GPL(pm_generic_suspend_late);
92
93/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010094 * pm_generic_suspend - Generic suspend callback for subsystems.
95 * @dev: Device to suspend.
96 */
97int pm_generic_suspend(struct device *dev)
98{
Rafael J. Wysockie470d062012-01-29 20:38:41 +010099 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
100
101 return pm && pm->suspend ? pm->suspend(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100102}
103EXPORT_SYMBOL_GPL(pm_generic_suspend);
104
105/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200106 * pm_generic_freeze_noirq - Generic freeze_noirq callback for subsystems.
107 * @dev: Device to freeze.
108 */
109int pm_generic_freeze_noirq(struct device *dev)
110{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100111 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
112
113 return pm && pm->freeze_noirq ? pm->freeze_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200114}
115EXPORT_SYMBOL_GPL(pm_generic_freeze_noirq);
116
117/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100118 * pm_generic_freeze_late - Generic freeze_late callback for subsystems.
119 * @dev: Device to freeze.
120 */
121int pm_generic_freeze_late(struct device *dev)
122{
123 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
124
125 return pm && pm->freeze_late ? pm->freeze_late(dev) : 0;
126}
127EXPORT_SYMBOL_GPL(pm_generic_freeze_late);
128
129/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100130 * pm_generic_freeze - Generic freeze callback for subsystems.
131 * @dev: Device to freeze.
132 */
133int pm_generic_freeze(struct device *dev)
134{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100135 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
136
137 return pm && pm->freeze ? pm->freeze(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100138}
139EXPORT_SYMBOL_GPL(pm_generic_freeze);
140
141/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200142 * pm_generic_poweroff_noirq - Generic poweroff_noirq callback for subsystems.
143 * @dev: Device to handle.
144 */
145int pm_generic_poweroff_noirq(struct device *dev)
146{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100147 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
148
149 return pm && pm->poweroff_noirq ? pm->poweroff_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200150}
151EXPORT_SYMBOL_GPL(pm_generic_poweroff_noirq);
152
153/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100154 * pm_generic_poweroff_late - Generic poweroff_late callback for subsystems.
155 * @dev: Device to handle.
156 */
157int pm_generic_poweroff_late(struct device *dev)
158{
159 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
160
161 return pm && pm->poweroff_late ? pm->poweroff_late(dev) : 0;
162}
163EXPORT_SYMBOL_GPL(pm_generic_poweroff_late);
164
165/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100166 * pm_generic_poweroff - Generic poweroff callback for subsystems.
167 * @dev: Device to handle.
168 */
169int pm_generic_poweroff(struct device *dev)
170{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100171 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
172
173 return pm && pm->poweroff ? pm->poweroff(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100174}
175EXPORT_SYMBOL_GPL(pm_generic_poweroff);
176
177/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200178 * pm_generic_thaw_noirq - Generic thaw_noirq callback for subsystems.
179 * @dev: Device to thaw.
180 */
181int pm_generic_thaw_noirq(struct device *dev)
182{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100183 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
184
185 return pm && pm->thaw_noirq ? pm->thaw_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200186}
187EXPORT_SYMBOL_GPL(pm_generic_thaw_noirq);
188
189/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100190 * pm_generic_thaw_early - Generic thaw_early callback for subsystems.
191 * @dev: Device to thaw.
192 */
193int pm_generic_thaw_early(struct device *dev)
194{
195 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
196
197 return pm && pm->thaw_early ? pm->thaw_early(dev) : 0;
198}
199EXPORT_SYMBOL_GPL(pm_generic_thaw_early);
200
201/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100202 * pm_generic_thaw - Generic thaw callback for subsystems.
203 * @dev: Device to thaw.
204 */
205int pm_generic_thaw(struct device *dev)
206{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100207 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
208
209 return pm && pm->thaw ? pm->thaw(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100210}
211EXPORT_SYMBOL_GPL(pm_generic_thaw);
212
213/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200214 * pm_generic_resume_noirq - Generic resume_noirq callback for subsystems.
215 * @dev: Device to resume.
216 */
217int pm_generic_resume_noirq(struct device *dev)
218{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100219 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
220
221 return pm && pm->resume_noirq ? pm->resume_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200222}
223EXPORT_SYMBOL_GPL(pm_generic_resume_noirq);
224
225/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100226 * pm_generic_resume_early - Generic resume_early callback for subsystems.
227 * @dev: Device to resume.
228 */
229int pm_generic_resume_early(struct device *dev)
230{
231 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
232
233 return pm && pm->resume_early ? pm->resume_early(dev) : 0;
234}
235EXPORT_SYMBOL_GPL(pm_generic_resume_early);
236
237/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100238 * pm_generic_resume - Generic resume callback for subsystems.
239 * @dev: Device to resume.
240 */
241int pm_generic_resume(struct device *dev)
242{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100243 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
244
245 return pm && pm->resume ? pm->resume(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100246}
247EXPORT_SYMBOL_GPL(pm_generic_resume);
248
249/**
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200250 * pm_generic_restore_noirq - Generic restore_noirq callback for subsystems.
251 * @dev: Device to restore.
252 */
253int pm_generic_restore_noirq(struct device *dev)
254{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100255 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
256
257 return pm && pm->restore_noirq ? pm->restore_noirq(dev) : 0;
Rafael J. Wysockie5291922011-07-01 22:12:59 +0200258}
259EXPORT_SYMBOL_GPL(pm_generic_restore_noirq);
260
261/**
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100262 * pm_generic_restore_early - Generic restore_early callback for subsystems.
263 * @dev: Device to resume.
264 */
265int pm_generic_restore_early(struct device *dev)
266{
267 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
268
269 return pm && pm->restore_early ? pm->restore_early(dev) : 0;
270}
271EXPORT_SYMBOL_GPL(pm_generic_restore_early);
272
273/**
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100274 * pm_generic_restore - Generic restore callback for subsystems.
275 * @dev: Device to restore.
276 */
277int pm_generic_restore(struct device *dev)
278{
Rafael J. Wysockie470d062012-01-29 20:38:41 +0100279 const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
280
281 return pm && pm->restore ? pm->restore(dev) : 0;
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100282}
283EXPORT_SYMBOL_GPL(pm_generic_restore);
Rafael J. Wysocki6538df82011-05-17 23:26:21 +0200284
285/**
Geert Uytterhoeven9accff52014-03-24 21:37:03 +0100286 * pm_generic_complete - Generic routine completing a device power transition.
Rafael J. Wysocki6538df82011-05-17 23:26:21 +0200287 * @dev: Device to handle.
288 *
289 * Complete a device power transition during a system-wide power transition.
290 */
291void pm_generic_complete(struct device *dev)
292{
293 struct device_driver *drv = dev->driver;
294
295 if (drv && drv->pm && drv->pm->complete)
296 drv->pm->complete(dev);
Rafael J. Wysocki6538df82011-05-17 23:26:21 +0200297}
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100298#endif /* CONFIG_PM_SLEEP */