xref: /openbmc/linux/include/linux/pm.h (revision 7ca81109)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  *  pm.h - Power management interface
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  *  Copyright (C) 2000 Andrew Henroid
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #ifndef _LINUX_PM_H
91da177e4SLinus Torvalds #define _LINUX_PM_H
101da177e4SLinus Torvalds 
110ae101fdSPaul Cercueil #include <linux/export.h>
121da177e4SLinus Torvalds #include <linux/list.h>
135e928f77SRafael J. Wysocki #include <linux/workqueue.h>
145e928f77SRafael J. Wysocki #include <linux/spinlock.h>
155e928f77SRafael J. Wysocki #include <linux/wait.h>
165e928f77SRafael J. Wysocki #include <linux/timer.h>
178234f673SVincent Guittot #include <linux/hrtimer.h>
185af84b82SRafael J. Wysocki #include <linux/completion.h>
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds /*
211da177e4SLinus Torvalds  * Callbacks for platform drivers to implement.
221da177e4SLinus Torvalds  */
231da177e4SLinus Torvalds extern void (*pm_power_off)(void);
241da177e4SLinus Torvalds 
25f43f627dSJesse Barnes struct device; /* we have a circular dep with device.h */
26f43f627dSJesse Barnes #ifdef CONFIG_VT_CONSOLE_SLEEP
27f43f627dSJesse Barnes extern void pm_vt_switch_required(struct device *dev, bool required);
28f43f627dSJesse Barnes extern void pm_vt_switch_unregister(struct device *dev);
29f43f627dSJesse Barnes #else
pm_vt_switch_required(struct device * dev,bool required)30f43f627dSJesse Barnes static inline void pm_vt_switch_required(struct device *dev, bool required)
31f43f627dSJesse Barnes {
32f43f627dSJesse Barnes }
pm_vt_switch_unregister(struct device * dev)33f43f627dSJesse Barnes static inline void pm_vt_switch_unregister(struct device *dev)
34f43f627dSJesse Barnes {
35f43f627dSJesse Barnes }
36f43f627dSJesse Barnes #endif /* CONFIG_VT_CONSOLE_SLEEP */
37f43f627dSJesse Barnes 
389ea4dcf4SDan Williams #ifdef CONFIG_CXL_SUSPEND
399ea4dcf4SDan Williams bool cxl_mem_active(void);
409ea4dcf4SDan Williams #else
cxl_mem_active(void)419ea4dcf4SDan Williams static inline bool cxl_mem_active(void)
429ea4dcf4SDan Williams {
439ea4dcf4SDan Williams 	return false;
449ea4dcf4SDan Williams }
459ea4dcf4SDan Williams #endif
469ea4dcf4SDan Williams 
471da177e4SLinus Torvalds /*
481da177e4SLinus Torvalds  * Device power management
491da177e4SLinus Torvalds  */
501da177e4SLinus Torvalds 
511da177e4SLinus Torvalds 
527490e442SAlan Stern #ifdef CONFIG_PM
537490e442SAlan Stern extern const char power_group_name[];		/* = "power" */
547490e442SAlan Stern #else
557490e442SAlan Stern #define power_group_name	NULL
567490e442SAlan Stern #endif
577490e442SAlan Stern 
58ca078baeSPavel Machek typedef struct pm_message {
59ca078baeSPavel Machek 	int event;
60ca078baeSPavel Machek } pm_message_t;
611da177e4SLinus Torvalds 
621eede070SRafael J. Wysocki /**
634d29b2e5SRafael J. Wysocki  * struct dev_pm_ops - device PM callbacks.
641eede070SRafael J. Wysocki  *
65f7bc83d8SRafael J. Wysocki  * @prepare: The principal role of this callback is to prevent new children of
66f7bc83d8SRafael J. Wysocki  *	the device from being registered after it has returned (the driver's
67f7bc83d8SRafael J. Wysocki  *	subsystem and generally the rest of the kernel is supposed to prevent
68f7bc83d8SRafael J. Wysocki  *	new calls to the probe method from being made too once @prepare() has
69f7bc83d8SRafael J. Wysocki  *	succeeded).  If @prepare() detects a situation it cannot handle (e.g.
70f7bc83d8SRafael J. Wysocki  *	registration of a child already in progress), it may return -EAGAIN, so
71f7bc83d8SRafael J. Wysocki  *	that the PM core can execute it once again (e.g. after a new child has
72f7bc83d8SRafael J. Wysocki  *	been registered) to recover from the race condition.
73f7bc83d8SRafael J. Wysocki  *	This method is executed for all kinds of suspend transitions and is
74f7bc83d8SRafael J. Wysocki  *	followed by one of the suspend callbacks: @suspend(), @freeze(), or
75aae4518bSRafael J. Wysocki  *	@poweroff().  If the transition is a suspend to memory or standby (that
76aae4518bSRafael J. Wysocki  *	is, not related to hibernation), the return value of @prepare() may be
77aae4518bSRafael J. Wysocki  *	used to indicate to the PM core to leave the device in runtime suspend
78aae4518bSRafael J. Wysocki  *	if applicable.  Namely, if @prepare() returns a positive number, the PM
79aae4518bSRafael J. Wysocki  *	core will understand that as a declaration that the device appears to be
80aae4518bSRafael J. Wysocki  *	runtime-suspended and it may be left in that state during the entire
81aae4518bSRafael J. Wysocki  *	transition and during the subsequent resume if all of its descendants
82aae4518bSRafael J. Wysocki  *	are left in runtime suspend too.  If that happens, @complete() will be
83aae4518bSRafael J. Wysocki  *	executed directly after @prepare() and it must ensure the proper
84aae4518bSRafael J. Wysocki  *	functioning of the device after the system resume.
85aae4518bSRafael J. Wysocki  *	The PM core executes subsystem-level @prepare() for all devices before
86aae4518bSRafael J. Wysocki  *	starting to invoke suspend callbacks for any of them, so generally
87aae4518bSRafael J. Wysocki  *	devices may be assumed to be functional or to respond to runtime resume
88aae4518bSRafael J. Wysocki  *	requests while @prepare() is being executed.  However, device drivers
89aae4518bSRafael J. Wysocki  *	may NOT assume anything about the availability of user space at that
90aae4518bSRafael J. Wysocki  *	time and it is NOT valid to request firmware from within @prepare()
91aae4518bSRafael J. Wysocki  *	(it's too late to do that).  It also is NOT valid to allocate
92f7bc83d8SRafael J. Wysocki  *	substantial amounts of memory from @prepare() in the GFP_KERNEL mode.
93f7bc83d8SRafael J. Wysocki  *	[To work around these limitations, drivers may register suspend and
94f7bc83d8SRafael J. Wysocki  *	hibernation notifiers to be executed before the freezing of tasks.]
951eede070SRafael J. Wysocki  *
961eede070SRafael J. Wysocki  * @complete: Undo the changes made by @prepare().  This method is executed for
971eede070SRafael J. Wysocki  *	all kinds of resume transitions, following one of the resume callbacks:
981eede070SRafael J. Wysocki  *	@resume(), @thaw(), @restore().  Also called if the state transition
99f7bc83d8SRafael J. Wysocki  *	fails before the driver's suspend callback: @suspend(), @freeze() or
100f7bc83d8SRafael J. Wysocki  *	@poweroff(), can be executed (e.g. if the suspend callback fails for one
1011eede070SRafael J. Wysocki  *	of the other devices that the PM core has unsuccessfully attempted to
1021eede070SRafael J. Wysocki  *	suspend earlier).
103f7bc83d8SRafael J. Wysocki  *	The PM core executes subsystem-level @complete() after it has executed
104aae4518bSRafael J. Wysocki  *	the appropriate resume callbacks for all devices.  If the corresponding
105aae4518bSRafael J. Wysocki  *	@prepare() at the beginning of the suspend transition returned a
106aae4518bSRafael J. Wysocki  *	positive number and the device was left in runtime suspend (without
107aae4518bSRafael J. Wysocki  *	executing any suspend and resume callbacks for it), @complete() will be
108aae4518bSRafael J. Wysocki  *	the only callback executed for the device during resume.  In that case,
109aae4518bSRafael J. Wysocki  *	@complete() must be prepared to do whatever is necessary to ensure the
110aae4518bSRafael J. Wysocki  *	proper functioning of the device after the system resume.  To this end,
111aae4518bSRafael J. Wysocki  *	@complete() can check the power.direct_complete flag of the device to
112aae4518bSRafael J. Wysocki  *	learn whether (unset) or not (set) the previous suspend and resume
113aae4518bSRafael J. Wysocki  *	callbacks have been executed for it.
1141eede070SRafael J. Wysocki  *
1151eede070SRafael J. Wysocki  * @suspend: Executed before putting the system into a sleep state in which the
116f7bc83d8SRafael J. Wysocki  *	contents of main memory are preserved.  The exact action to perform
117f7bc83d8SRafael J. Wysocki  *	depends on the device's subsystem (PM domain, device type, class or bus
118f7bc83d8SRafael J. Wysocki  *	type), but generally the device must be quiescent after subsystem-level
119f7bc83d8SRafael J. Wysocki  *	@suspend() has returned, so that it doesn't do any I/O or DMA.
120f7bc83d8SRafael J. Wysocki  *	Subsystem-level @suspend() is executed for all devices after invoking
121f7bc83d8SRafael J. Wysocki  *	subsystem-level @prepare() for all of them.
1221eede070SRafael J. Wysocki  *
123cf579dfbSRafael J. Wysocki  * @suspend_late: Continue operations started by @suspend().  For a number of
124cf579dfbSRafael J. Wysocki  *	devices @suspend_late() may point to the same callback routine as the
125cf579dfbSRafael J. Wysocki  *	runtime suspend callback.
126cf579dfbSRafael J. Wysocki  *
1271eede070SRafael J. Wysocki  * @resume: Executed after waking the system up from a sleep state in which the
128f7bc83d8SRafael J. Wysocki  *	contents of main memory were preserved.  The exact action to perform
129f7bc83d8SRafael J. Wysocki  *	depends on the device's subsystem, but generally the driver is expected
130f7bc83d8SRafael J. Wysocki  *	to start working again, responding to hardware events and software
131f7bc83d8SRafael J. Wysocki  *	requests (the device itself may be left in a low-power state, waiting
132f7bc83d8SRafael J. Wysocki  *	for a runtime resume to occur).  The state of the device at the time its
133f7bc83d8SRafael J. Wysocki  *	driver's @resume() callback is run depends on the platform and subsystem
134f7bc83d8SRafael J. Wysocki  *	the device belongs to.  On most platforms, there are no restrictions on
135f7bc83d8SRafael J. Wysocki  *	availability of resources like clocks during @resume().
136f7bc83d8SRafael J. Wysocki  *	Subsystem-level @resume() is executed for all devices after invoking
137f7bc83d8SRafael J. Wysocki  *	subsystem-level @resume_noirq() for all of them.
1381eede070SRafael J. Wysocki  *
139cf579dfbSRafael J. Wysocki  * @resume_early: Prepare to execute @resume().  For a number of devices
140cf579dfbSRafael J. Wysocki  *	@resume_early() may point to the same callback routine as the runtime
141cf579dfbSRafael J. Wysocki  *	resume callback.
142cf579dfbSRafael J. Wysocki  *
1431eede070SRafael J. Wysocki  * @freeze: Hibernation-specific, executed before creating a hibernation image.
144f7bc83d8SRafael J. Wysocki  *	Analogous to @suspend(), but it should not enable the device to signal
145f7bc83d8SRafael J. Wysocki  *	wakeup events or change its power state.  The majority of subsystems
146f7bc83d8SRafael J. Wysocki  *	(with the notable exception of the PCI bus type) expect the driver-level
147f7bc83d8SRafael J. Wysocki  *	@freeze() to save the device settings in memory to be used by @restore()
148f7bc83d8SRafael J. Wysocki  *	during the subsequent resume from hibernation.
149f7bc83d8SRafael J. Wysocki  *	Subsystem-level @freeze() is executed for all devices after invoking
150f7bc83d8SRafael J. Wysocki  *	subsystem-level @prepare() for all of them.
1511eede070SRafael J. Wysocki  *
152cf579dfbSRafael J. Wysocki  * @freeze_late: Continue operations started by @freeze().  Analogous to
153cf579dfbSRafael J. Wysocki  *	@suspend_late(), but it should not enable the device to signal wakeup
154cf579dfbSRafael J. Wysocki  *	events or change its power state.
155cf579dfbSRafael J. Wysocki  *
1561eede070SRafael J. Wysocki  * @thaw: Hibernation-specific, executed after creating a hibernation image OR
157f7bc83d8SRafael J. Wysocki  *	if the creation of an image has failed.  Also executed after a failing
1581eede070SRafael J. Wysocki  *	attempt to restore the contents of main memory from such an image.
1591eede070SRafael J. Wysocki  *	Undo the changes made by the preceding @freeze(), so the device can be
1601eede070SRafael J. Wysocki  *	operated in the same way as immediately before the call to @freeze().
161f7bc83d8SRafael J. Wysocki  *	Subsystem-level @thaw() is executed for all devices after invoking
162f7bc83d8SRafael J. Wysocki  *	subsystem-level @thaw_noirq() for all of them.  It also may be executed
163f7bc83d8SRafael J. Wysocki  *	directly after @freeze() in case of a transition error.
1641eede070SRafael J. Wysocki  *
165cf579dfbSRafael J. Wysocki  * @thaw_early: Prepare to execute @thaw().  Undo the changes made by the
166cf579dfbSRafael J. Wysocki  *	preceding @freeze_late().
167cf579dfbSRafael J. Wysocki  *
1681eede070SRafael J. Wysocki  * @poweroff: Hibernation-specific, executed after saving a hibernation image.
169f7bc83d8SRafael J. Wysocki  *	Analogous to @suspend(), but it need not save the device's settings in
170f7bc83d8SRafael J. Wysocki  *	memory.
171f7bc83d8SRafael J. Wysocki  *	Subsystem-level @poweroff() is executed for all devices after invoking
172f7bc83d8SRafael J. Wysocki  *	subsystem-level @prepare() for all of them.
1731eede070SRafael J. Wysocki  *
174cf579dfbSRafael J. Wysocki  * @poweroff_late: Continue operations started by @poweroff().  Analogous to
175cf579dfbSRafael J. Wysocki  *	@suspend_late(), but it need not save the device's settings in memory.
176cf579dfbSRafael J. Wysocki  *
1771eede070SRafael J. Wysocki  * @restore: Hibernation-specific, executed after restoring the contents of main
178f7bc83d8SRafael J. Wysocki  *	memory from a hibernation image, analogous to @resume().
1791eede070SRafael J. Wysocki  *
180cf579dfbSRafael J. Wysocki  * @restore_early: Prepare to execute @restore(), analogous to @resume_early().
181cf579dfbSRafael J. Wysocki  *
182f7bc83d8SRafael J. Wysocki  * @suspend_noirq: Complete the actions started by @suspend().  Carry out any
183f7bc83d8SRafael J. Wysocki  *	additional operations required for suspending the device that might be
184f7bc83d8SRafael J. Wysocki  *	racing with its driver's interrupt handler, which is guaranteed not to
185f7bc83d8SRafael J. Wysocki  *	run while @suspend_noirq() is being executed.
186f7bc83d8SRafael J. Wysocki  *	It generally is expected that the device will be in a low-power state
187f7bc83d8SRafael J. Wysocki  *	(appropriate for the target system sleep state) after subsystem-level
188f7bc83d8SRafael J. Wysocki  *	@suspend_noirq() has returned successfully.  If the device can generate
189f7bc83d8SRafael J. Wysocki  *	system wakeup signals and is enabled to wake up the system, it should be
190f7bc83d8SRafael J. Wysocki  *	configured to do so at that time.  However, depending on the platform
191cf579dfbSRafael J. Wysocki  *	and device's subsystem, @suspend() or @suspend_late() may be allowed to
192cf579dfbSRafael J. Wysocki  *	put the device into the low-power state and configure it to generate
193cf579dfbSRafael J. Wysocki  *	wakeup signals, in which case it generally is not necessary to define
194cf579dfbSRafael J. Wysocki  *	@suspend_noirq().
1951eede070SRafael J. Wysocki  *
196f7bc83d8SRafael J. Wysocki  * @resume_noirq: Prepare for the execution of @resume() by carrying out any
197f7bc83d8SRafael J. Wysocki  *	operations required for resuming the device that might be racing with
198f7bc83d8SRafael J. Wysocki  *	its driver's interrupt handler, which is guaranteed not to run while
199f7bc83d8SRafael J. Wysocki  *	@resume_noirq() is being executed.
2001eede070SRafael J. Wysocki  *
201f7bc83d8SRafael J. Wysocki  * @freeze_noirq: Complete the actions started by @freeze().  Carry out any
202f7bc83d8SRafael J. Wysocki  *	additional operations required for freezing the device that might be
203f7bc83d8SRafael J. Wysocki  *	racing with its driver's interrupt handler, which is guaranteed not to
204f7bc83d8SRafael J. Wysocki  *	run while @freeze_noirq() is being executed.
205cf579dfbSRafael J. Wysocki  *	The power state of the device should not be changed by either @freeze(),
206cf579dfbSRafael J. Wysocki  *	or @freeze_late(), or @freeze_noirq() and it should not be configured to
207cf579dfbSRafael J. Wysocki  *	signal system wakeup by any of these callbacks.
2081eede070SRafael J. Wysocki  *
209f7bc83d8SRafael J. Wysocki  * @thaw_noirq: Prepare for the execution of @thaw() by carrying out any
210f7bc83d8SRafael J. Wysocki  *	operations required for thawing the device that might be racing with its
211f7bc83d8SRafael J. Wysocki  *	driver's interrupt handler, which is guaranteed not to run while
212f7bc83d8SRafael J. Wysocki  *	@thaw_noirq() is being executed.
2131eede070SRafael J. Wysocki  *
214f7bc83d8SRafael J. Wysocki  * @poweroff_noirq: Complete the actions started by @poweroff().  Analogous to
215f7bc83d8SRafael J. Wysocki  *	@suspend_noirq(), but it need not save the device's settings in memory.
2161eede070SRafael J. Wysocki  *
217f7bc83d8SRafael J. Wysocki  * @restore_noirq: Prepare for the execution of @restore() by carrying out any
218f7bc83d8SRafael J. Wysocki  *	operations required for thawing the device that might be racing with its
219f7bc83d8SRafael J. Wysocki  *	driver's interrupt handler, which is guaranteed not to run while
220f7bc83d8SRafael J. Wysocki  *	@restore_noirq() is being executed.  Analogous to @resume_noirq().
2211eede070SRafael J. Wysocki  *
2225e928f77SRafael J. Wysocki  * @runtime_suspend: Prepare the device for a condition in which it won't be
2235e928f77SRafael J. Wysocki  *	able to communicate with the CPU(s) and RAM due to power management.
224f7bc83d8SRafael J. Wysocki  *	This need not mean that the device should be put into a low-power state.
2255e928f77SRafael J. Wysocki  *	For example, if the device is behind a link which is about to be turned
2265e928f77SRafael J. Wysocki  *	off, the device may remain at full power.  If the device does go to low
227f7bc83d8SRafael J. Wysocki  *	power and is capable of generating runtime wakeup events, remote wakeup
228f7bc83d8SRafael J. Wysocki  *	(i.e., a hardware mechanism allowing the device to request a change of
229f7bc83d8SRafael J. Wysocki  *	its power state via an interrupt) should be enabled for it.
2305e928f77SRafael J. Wysocki  *
2315e928f77SRafael J. Wysocki  * @runtime_resume: Put the device into the fully active state in response to a
232f7bc83d8SRafael J. Wysocki  *	wakeup event generated by hardware or at the request of software.  If
233f7bc83d8SRafael J. Wysocki  *	necessary, put the device into the full-power state and restore its
2345e928f77SRafael J. Wysocki  *	registers, so that it is fully operational.
2355e928f77SRafael J. Wysocki  *
236f7bc83d8SRafael J. Wysocki  * @runtime_idle: Device appears to be inactive and it might be put into a
237651665dbSGeert Uytterhoeven  *	low-power state if all of the necessary conditions are satisfied.
238651665dbSGeert Uytterhoeven  *	Check these conditions, and return 0 if it's appropriate to let the PM
239651665dbSGeert Uytterhoeven  *	core queue a suspend request for the device.
240f7bc83d8SRafael J. Wysocki  *
2414d29b2e5SRafael J. Wysocki  * Several device power state transitions are externally visible, affecting
2424d29b2e5SRafael J. Wysocki  * the state of pending I/O queues and (for drivers that touch hardware)
2434d29b2e5SRafael J. Wysocki  * interrupts, wakeups, DMA, and other hardware state.  There may also be
2444d29b2e5SRafael J. Wysocki  * internal transitions to various low-power modes which are transparent
2454d29b2e5SRafael J. Wysocki  * to the rest of the driver stack (such as a driver that's ON gating off
2464d29b2e5SRafael J. Wysocki  * clocks which are not in active use).
247f7bc83d8SRafael J. Wysocki  *
2484d29b2e5SRafael J. Wysocki  * The externally visible transitions are handled with the help of callbacks
2494d29b2e5SRafael J. Wysocki  * included in this structure in such a way that, typically, two levels of
2504d29b2e5SRafael J. Wysocki  * callbacks are involved.  First, the PM core executes callbacks provided by PM
2514d29b2e5SRafael J. Wysocki  * domains, device types, classes and bus types.  They are the subsystem-level
2524d29b2e5SRafael J. Wysocki  * callbacks expected to execute callbacks provided by device drivers, although
2534d29b2e5SRafael J. Wysocki  * they may choose not to do that.  If the driver callbacks are executed, they
2544d29b2e5SRafael J. Wysocki  * have to collaborate with the subsystem-level callbacks to achieve the goals
2554d29b2e5SRafael J. Wysocki  * appropriate for the given system transition, given transition phase and the
2564d29b2e5SRafael J. Wysocki  * subsystem the device belongs to.
2574d29b2e5SRafael J. Wysocki  *
2584d29b2e5SRafael J. Wysocki  * All of the above callbacks, except for @complete(), return error codes.
2594d29b2e5SRafael J. Wysocki  * However, the error codes returned by @resume(), @thaw(), @restore(),
2604d29b2e5SRafael J. Wysocki  * @resume_noirq(), @thaw_noirq(), and @restore_noirq(), do not cause the PM
2614d29b2e5SRafael J. Wysocki  * core to abort the resume transition during which they are returned.  The
2624d29b2e5SRafael J. Wysocki  * error codes returned in those cases are only printed to the system logs for
2634d29b2e5SRafael J. Wysocki  * debugging purposes.  Still, it is recommended that drivers only return error
2644d29b2e5SRafael J. Wysocki  * codes from their resume methods in case of an unrecoverable failure (i.e.
2654d29b2e5SRafael J. Wysocki  * when the device being handled refuses to resume and becomes unusable) to
2664d29b2e5SRafael J. Wysocki  * allow the PM core to be modified in the future, so that it can avoid
2674d29b2e5SRafael J. Wysocki  * attempting to handle devices that failed to resume and their children.
2684d29b2e5SRafael J. Wysocki  *
2694d29b2e5SRafael J. Wysocki  * It is allowed to unregister devices while the above callbacks are being
2704d29b2e5SRafael J. Wysocki  * executed.  However, a callback routine MUST NOT try to unregister the device
2714d29b2e5SRafael J. Wysocki  * it was called for, although it may unregister children of that device (for
2724d29b2e5SRafael J. Wysocki  * example, if it detects that a child was unplugged while the system was
2734d29b2e5SRafael J. Wysocki  * asleep).
2744d29b2e5SRafael J. Wysocki  *
2754d29b2e5SRafael J. Wysocki  * There also are callbacks related to runtime power management of devices.
2764d29b2e5SRafael J. Wysocki  * Again, as a rule these callbacks are executed by the PM core for subsystems
2774d29b2e5SRafael J. Wysocki  * (PM domains, device types, classes and bus types) and the subsystem-level
2784d29b2e5SRafael J. Wysocki  * callbacks are expected to invoke the driver callbacks.  Moreover, the exact
2794d29b2e5SRafael J. Wysocki  * actions to be performed by a device driver's callbacks generally depend on
2804d29b2e5SRafael J. Wysocki  * the platform and subsystem the device belongs to.
2814d29b2e5SRafael J. Wysocki  *
282151f4e2bSMauro Carvalho Chehab  * Refer to Documentation/power/runtime_pm.rst for more information about the
2834d29b2e5SRafael J. Wysocki  * role of the @runtime_suspend(), @runtime_resume() and @runtime_idle()
2844d29b2e5SRafael J. Wysocki  * callbacks in device runtime power management.
2851eede070SRafael J. Wysocki  */
286adf09493SRafael J. Wysocki struct dev_pm_ops {
287adf09493SRafael J. Wysocki 	int (*prepare)(struct device *dev);
288adf09493SRafael J. Wysocki 	void (*complete)(struct device *dev);
289adf09493SRafael J. Wysocki 	int (*suspend)(struct device *dev);
290adf09493SRafael J. Wysocki 	int (*resume)(struct device *dev);
291adf09493SRafael J. Wysocki 	int (*freeze)(struct device *dev);
292adf09493SRafael J. Wysocki 	int (*thaw)(struct device *dev);
293adf09493SRafael J. Wysocki 	int (*poweroff)(struct device *dev);
294adf09493SRafael J. Wysocki 	int (*restore)(struct device *dev);
295cf579dfbSRafael J. Wysocki 	int (*suspend_late)(struct device *dev);
296cf579dfbSRafael J. Wysocki 	int (*resume_early)(struct device *dev);
297cf579dfbSRafael J. Wysocki 	int (*freeze_late)(struct device *dev);
298cf579dfbSRafael J. Wysocki 	int (*thaw_early)(struct device *dev);
299cf579dfbSRafael J. Wysocki 	int (*poweroff_late)(struct device *dev);
300cf579dfbSRafael J. Wysocki 	int (*restore_early)(struct device *dev);
3011eede070SRafael J. Wysocki 	int (*suspend_noirq)(struct device *dev);
3021eede070SRafael J. Wysocki 	int (*resume_noirq)(struct device *dev);
3031eede070SRafael J. Wysocki 	int (*freeze_noirq)(struct device *dev);
3041eede070SRafael J. Wysocki 	int (*thaw_noirq)(struct device *dev);
3051eede070SRafael J. Wysocki 	int (*poweroff_noirq)(struct device *dev);
3061eede070SRafael J. Wysocki 	int (*restore_noirq)(struct device *dev);
3075e928f77SRafael J. Wysocki 	int (*runtime_suspend)(struct device *dev);
3085e928f77SRafael J. Wysocki 	int (*runtime_resume)(struct device *dev);
3095e928f77SRafael J. Wysocki 	int (*runtime_idle)(struct device *dev);
3101eede070SRafael J. Wysocki };
3111eede070SRafael J. Wysocki 
3121a3c7bb0SPaul Cercueil #define SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
3131a3c7bb0SPaul Cercueil 	.suspend = pm_sleep_ptr(suspend_fn), \
3141a3c7bb0SPaul Cercueil 	.resume = pm_sleep_ptr(resume_fn), \
3151a3c7bb0SPaul Cercueil 	.freeze = pm_sleep_ptr(suspend_fn), \
3161a3c7bb0SPaul Cercueil 	.thaw = pm_sleep_ptr(resume_fn), \
3171a3c7bb0SPaul Cercueil 	.poweroff = pm_sleep_ptr(suspend_fn), \
3181a3c7bb0SPaul Cercueil 	.restore = pm_sleep_ptr(resume_fn),
3191a3c7bb0SPaul Cercueil 
3201a3c7bb0SPaul Cercueil #define LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
3211a3c7bb0SPaul Cercueil 	.suspend_late = pm_sleep_ptr(suspend_fn), \
3221a3c7bb0SPaul Cercueil 	.resume_early = pm_sleep_ptr(resume_fn), \
3231a3c7bb0SPaul Cercueil 	.freeze_late = pm_sleep_ptr(suspend_fn), \
3241a3c7bb0SPaul Cercueil 	.thaw_early = pm_sleep_ptr(resume_fn), \
3251a3c7bb0SPaul Cercueil 	.poweroff_late = pm_sleep_ptr(suspend_fn), \
3261a3c7bb0SPaul Cercueil 	.restore_early = pm_sleep_ptr(resume_fn),
3271a3c7bb0SPaul Cercueil 
3281a3c7bb0SPaul Cercueil #define NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
3291a3c7bb0SPaul Cercueil 	.suspend_noirq = pm_sleep_ptr(suspend_fn), \
3301a3c7bb0SPaul Cercueil 	.resume_noirq = pm_sleep_ptr(resume_fn), \
3311a3c7bb0SPaul Cercueil 	.freeze_noirq = pm_sleep_ptr(suspend_fn), \
3321a3c7bb0SPaul Cercueil 	.thaw_noirq = pm_sleep_ptr(resume_fn), \
3331a3c7bb0SPaul Cercueil 	.poweroff_noirq = pm_sleep_ptr(suspend_fn), \
3341a3c7bb0SPaul Cercueil 	.restore_noirq = pm_sleep_ptr(resume_fn),
3351a3c7bb0SPaul Cercueil 
3361a3c7bb0SPaul Cercueil #define RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
3371a3c7bb0SPaul Cercueil 	.runtime_suspend = suspend_fn, \
3381a3c7bb0SPaul Cercueil 	.runtime_resume = resume_fn, \
3391a3c7bb0SPaul Cercueil 	.runtime_idle = idle_fn,
3401a3c7bb0SPaul Cercueil 
341d690b2cdSRafael J. Wysocki #ifdef CONFIG_PM_SLEEP
342d690b2cdSRafael J. Wysocki #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
3431a3c7bb0SPaul Cercueil 	SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
344d690b2cdSRafael J. Wysocki #else
345d690b2cdSRafael J. Wysocki #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
346d690b2cdSRafael J. Wysocki #endif
347d690b2cdSRafael J. Wysocki 
348f78c4cffSUlf Hansson #ifdef CONFIG_PM_SLEEP
349f78c4cffSUlf Hansson #define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
3501a3c7bb0SPaul Cercueil 	LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
351f78c4cffSUlf Hansson #else
352f78c4cffSUlf Hansson #define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
353f78c4cffSUlf Hansson #endif
354f78c4cffSUlf Hansson 
355020af89aSGrygorii Strashko #ifdef CONFIG_PM_SLEEP
356020af89aSGrygorii Strashko #define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
3571a3c7bb0SPaul Cercueil 	NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
358020af89aSGrygorii Strashko #else
359020af89aSGrygorii Strashko #define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
360020af89aSGrygorii Strashko #endif
361020af89aSGrygorii Strashko 
3626ed23b80SRafael J. Wysocki #ifdef CONFIG_PM
363d690b2cdSRafael J. Wysocki #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
3641a3c7bb0SPaul Cercueil 	RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
365d690b2cdSRafael J. Wysocki #else
366d690b2cdSRafael J. Wysocki #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
367d690b2cdSRafael J. Wysocki #endif
368d690b2cdSRafael J. Wysocki 
3690ae101fdSPaul Cercueil #define _DEFINE_DEV_PM_OPS(name, \
3700ae101fdSPaul Cercueil 			   suspend_fn, resume_fn, \
3710ae101fdSPaul Cercueil 			   runtime_suspend_fn, runtime_resume_fn, idle_fn) \
3720ae101fdSPaul Cercueil const struct dev_pm_ops name = { \
3730ae101fdSPaul Cercueil 	SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
3740ae101fdSPaul Cercueil 	RUNTIME_PM_OPS(runtime_suspend_fn, runtime_resume_fn, idle_fn) \
3750ae101fdSPaul Cercueil }
3760ae101fdSPaul Cercueil 
377*7ca81109SRaag Jadav #define _EXPORT_PM_OPS(name, license, ns)				\
37834e1ed18SPaul Cercueil 	const struct dev_pm_ops name;					\
3798ed7e33aSMasahiro Yamada 	__EXPORT_SYMBOL(name, license, ns);				\
38034e1ed18SPaul Cercueil 	const struct dev_pm_ops name
381*7ca81109SRaag Jadav 
382*7ca81109SRaag Jadav #define _DISCARD_PM_OPS(name, license, ns)				\
383*7ca81109SRaag Jadav 	static __maybe_unused const struct dev_pm_ops __static_##name
384*7ca81109SRaag Jadav 
385*7ca81109SRaag Jadav #ifdef CONFIG_PM
386*7ca81109SRaag Jadav #define _EXPORT_DEV_PM_OPS(name, license, ns)		_EXPORT_PM_OPS(name, license, ns)
38741a337b4SRichard Fitzgerald #define EXPORT_PM_FN_GPL(name)				EXPORT_SYMBOL_GPL(name)
38841a337b4SRichard Fitzgerald #define EXPORT_PM_FN_NS_GPL(name, ns)			EXPORT_SYMBOL_NS_GPL(name, ns)
3890ae101fdSPaul Cercueil #else
390*7ca81109SRaag Jadav #define _EXPORT_DEV_PM_OPS(name, license, ns)		_DISCARD_PM_OPS(name, license, ns)
39141a337b4SRichard Fitzgerald #define EXPORT_PM_FN_GPL(name)
39241a337b4SRichard Fitzgerald #define EXPORT_PM_FN_NS_GPL(name, ns)
3930ae101fdSPaul Cercueil #endif
3940ae101fdSPaul Cercueil 
395*7ca81109SRaag Jadav #ifdef CONFIG_PM_SLEEP
396*7ca81109SRaag Jadav #define _EXPORT_DEV_SLEEP_PM_OPS(name, license, ns)	_EXPORT_PM_OPS(name, license, ns)
397*7ca81109SRaag Jadav #else
398*7ca81109SRaag Jadav #define _EXPORT_DEV_SLEEP_PM_OPS(name, license, ns)	_DISCARD_PM_OPS(name, license, ns)
399*7ca81109SRaag Jadav #endif
400*7ca81109SRaag Jadav 
40134e1ed18SPaul Cercueil #define EXPORT_DEV_PM_OPS(name)				_EXPORT_DEV_PM_OPS(name, "", "")
402ddb5cdbaSMasahiro Yamada #define EXPORT_GPL_DEV_PM_OPS(name)			_EXPORT_DEV_PM_OPS(name, "GPL", "")
40334e1ed18SPaul Cercueil #define EXPORT_NS_DEV_PM_OPS(name, ns)			_EXPORT_DEV_PM_OPS(name, "", #ns)
404ddb5cdbaSMasahiro Yamada #define EXPORT_NS_GPL_DEV_PM_OPS(name, ns)		_EXPORT_DEV_PM_OPS(name, "GPL", #ns)
40534e1ed18SPaul Cercueil 
406*7ca81109SRaag Jadav #define EXPORT_DEV_SLEEP_PM_OPS(name)			_EXPORT_DEV_SLEEP_PM_OPS(name, "", "")
407*7ca81109SRaag Jadav #define EXPORT_GPL_DEV_SLEEP_PM_OPS(name)		_EXPORT_DEV_SLEEP_PM_OPS(name, "GPL", "")
408*7ca81109SRaag Jadav #define EXPORT_NS_DEV_SLEEP_PM_OPS(name, ns)		_EXPORT_DEV_SLEEP_PM_OPS(name, "", #ns)
409*7ca81109SRaag Jadav #define EXPORT_NS_GPL_DEV_SLEEP_PM_OPS(name, ns)	_EXPORT_DEV_SLEEP_PM_OPS(name, "GPL", #ns)
410*7ca81109SRaag Jadav 
4119d62ec6cSAlbin Tonnerre /*
4129d62ec6cSAlbin Tonnerre  * Use this if you want to use the same suspend and resume callbacks for suspend
4139d62ec6cSAlbin Tonnerre  * to RAM and hibernation.
4140ae101fdSPaul Cercueil  *
4150ae101fdSPaul Cercueil  * If the underlying dev_pm_ops struct symbol has to be exported, use
4160ae101fdSPaul Cercueil  * EXPORT_SIMPLE_DEV_PM_OPS() or EXPORT_GPL_SIMPLE_DEV_PM_OPS() instead.
4179d62ec6cSAlbin Tonnerre  */
4181a3c7bb0SPaul Cercueil #define DEFINE_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4190ae101fdSPaul Cercueil 	_DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL)
4200ae101fdSPaul Cercueil 
4210ae101fdSPaul Cercueil #define EXPORT_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
422*7ca81109SRaag Jadav 	EXPORT_DEV_SLEEP_PM_OPS(name) = { \
42334e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
42434e1ed18SPaul Cercueil 	}
4250ae101fdSPaul Cercueil #define EXPORT_GPL_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
426*7ca81109SRaag Jadav 	EXPORT_GPL_DEV_SLEEP_PM_OPS(name) = { \
42734e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
42834e1ed18SPaul Cercueil 	}
429a8e2512eSJonathan Cameron #define EXPORT_NS_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn, ns)	\
430*7ca81109SRaag Jadav 	EXPORT_NS_DEV_SLEEP_PM_OPS(name, ns) = { \
43134e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
43234e1ed18SPaul Cercueil 	}
433a8e2512eSJonathan Cameron #define EXPORT_NS_GPL_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn, ns)	\
434*7ca81109SRaag Jadav 	EXPORT_NS_GPL_DEV_SLEEP_PM_OPS(name, ns) = { \
43534e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
43634e1ed18SPaul Cercueil 	}
4379d62ec6cSAlbin Tonnerre 
4383f4b3251SPaul Cercueil /* Deprecated. Use DEFINE_SIMPLE_DEV_PM_OPS() instead. */
4393f4b3251SPaul Cercueil #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4403f4b3251SPaul Cercueil const struct dev_pm_ops __maybe_unused name = { \
4413f4b3251SPaul Cercueil 	SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
4423f4b3251SPaul Cercueil }
4433f4b3251SPaul Cercueil 
444d690b2cdSRafael J. Wysocki /*
445d690b2cdSRafael J. Wysocki  * Use this for defining a set of PM operations to be used in all situations
4463e54d151SLad, Prabhakar  * (system suspend, hibernation or runtime PM).
447c4882525SRafael J. Wysocki  * NOTE: In general, system suspend callbacks, .suspend() and .resume(), should
448c4882525SRafael J. Wysocki  * be different from the corresponding runtime PM callbacks, .runtime_suspend(),
449c4882525SRafael J. Wysocki  * and .runtime_resume(), because .runtime_suspend() always works on an already
450c4882525SRafael J. Wysocki  * quiescent device, while .suspend() should assume that the device may be doing
451c4882525SRafael J. Wysocki  * something when it is called (it should ensure that the device will be
452c4882525SRafael J. Wysocki  * quiescent after it has returned).  Therefore it's better to point the "late"
453c4882525SRafael J. Wysocki  * suspend and "early" resume callback pointers, .suspend_late() and
454c4882525SRafael J. Wysocki  * .resume_early(), to the same routines as .runtime_suspend() and
455c4882525SRafael J. Wysocki  * .runtime_resume(), respectively (and analogously for hibernation).
4563f4b3251SPaul Cercueil  *
4579d861919SPaul Cercueil  * Deprecated. You most likely don't want this macro. Use
4589d861919SPaul Cercueil  * DEFINE_RUNTIME_DEV_PM_OPS() instead.
459d690b2cdSRafael J. Wysocki  */
460d690b2cdSRafael J. Wysocki #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
461756a64ceSPaul Cercueil const struct dev_pm_ops __maybe_unused name = { \
462d690b2cdSRafael J. Wysocki 	SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
463d690b2cdSRafael J. Wysocki 	SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
464d690b2cdSRafael J. Wysocki }
465d690b2cdSRafael J. Wysocki 
4662a6c0b47SAndy Shevchenko /*
4672a6c0b47SAndy Shevchenko  * Use this if you want to have the suspend and resume callbacks be called
4682a6c0b47SAndy Shevchenko  * with IRQs disabled.
4692a6c0b47SAndy Shevchenko  */
4702a6c0b47SAndy Shevchenko #define DEFINE_NOIRQ_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4712a6c0b47SAndy Shevchenko const struct dev_pm_ops name = { \
4722a6c0b47SAndy Shevchenko 	NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
4732a6c0b47SAndy Shevchenko }
4742a6c0b47SAndy Shevchenko 
475c06ef740SPaul Cercueil #define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))
4761a3c7bb0SPaul Cercueil #define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), (_ptr))
4777a82e97aSPaul Cercueil 
4784d29b2e5SRafael J. Wysocki /*
4791eede070SRafael J. Wysocki  * PM_EVENT_ messages
4801eede070SRafael J. Wysocki  *
4811eede070SRafael J. Wysocki  * The following PM_EVENT_ messages are defined for the internal use of the PM
4821eede070SRafael J. Wysocki  * core, in order to provide a mechanism allowing the high level suspend and
4831eede070SRafael J. Wysocki  * hibernation code to convey the necessary information to the device PM core
4841eede070SRafael J. Wysocki  * code:
4851eede070SRafael J. Wysocki  *
4861eede070SRafael J. Wysocki  * ON		No transition.
4871eede070SRafael J. Wysocki  *
4881eede070SRafael J. Wysocki  * FREEZE	System is going to hibernate, call ->prepare() and ->freeze()
4891eede070SRafael J. Wysocki  *		for all devices.
4901eede070SRafael J. Wysocki  *
4911eede070SRafael J. Wysocki  * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
4921eede070SRafael J. Wysocki  *		for all devices.
4931eede070SRafael J. Wysocki  *
4941eede070SRafael J. Wysocki  * HIBERNATE	Hibernation image has been saved, call ->prepare() and
4951eede070SRafael J. Wysocki  *		->poweroff() for all devices.
4961eede070SRafael J. Wysocki  *
4971eede070SRafael J. Wysocki  * QUIESCE	Contents of main memory are going to be restored from a (loaded)
4981eede070SRafael J. Wysocki  *		hibernation image, call ->prepare() and ->freeze() for all
4991eede070SRafael J. Wysocki  *		devices.
5001eede070SRafael J. Wysocki  *
5011eede070SRafael J. Wysocki  * RESUME	System is resuming, call ->resume() and ->complete() for all
5021eede070SRafael J. Wysocki  *		devices.
5031eede070SRafael J. Wysocki  *
5041eede070SRafael J. Wysocki  * THAW		Hibernation image has been created, call ->thaw() and
5051eede070SRafael J. Wysocki  *		->complete() for all devices.
5061eede070SRafael J. Wysocki  *
5071eede070SRafael J. Wysocki  * RESTORE	Contents of main memory have been restored from a hibernation
5081eede070SRafael J. Wysocki  *		image, call ->restore() and ->complete() for all devices.
5091eede070SRafael J. Wysocki  *
5101eede070SRafael J. Wysocki  * RECOVER	Creation of a hibernation image or restoration of the main
5111eede070SRafael J. Wysocki  *		memory contents from a hibernation image has failed, call
5121eede070SRafael J. Wysocki  *		->thaw() and ->complete() for all devices.
5138111d1b5SAlan Stern  *
5148111d1b5SAlan Stern  * The following PM_EVENT_ messages are defined for internal use by
5158111d1b5SAlan Stern  * kernel subsystems.  They are never issued by the PM core.
5168111d1b5SAlan Stern  *
5178111d1b5SAlan Stern  * USER_SUSPEND		Manual selective suspend was issued by userspace.
5188111d1b5SAlan Stern  *
5198111d1b5SAlan Stern  * USER_RESUME		Manual selective resume was issued by userspace.
5208111d1b5SAlan Stern  *
5218111d1b5SAlan Stern  * REMOTE_WAKEUP	Remote-wakeup request was received from the device.
5228111d1b5SAlan Stern  *
5238111d1b5SAlan Stern  * AUTO_SUSPEND		Automatic (device idle) runtime suspend was
5248111d1b5SAlan Stern  *			initiated by the subsystem.
5258111d1b5SAlan Stern  *
5268111d1b5SAlan Stern  * AUTO_RESUME		Automatic (device needed) runtime resume was
5278111d1b5SAlan Stern  *			requested by a driver.
5281eede070SRafael J. Wysocki  */
5291eede070SRafael J. Wysocki 
5301a9a9152SRafael J. Wysocki #define PM_EVENT_INVALID	(-1)
5311eede070SRafael J. Wysocki #define PM_EVENT_ON		0x0000
5321eede070SRafael J. Wysocki #define PM_EVENT_FREEZE		0x0001
5331eede070SRafael J. Wysocki #define PM_EVENT_SUSPEND	0x0002
5341eede070SRafael J. Wysocki #define PM_EVENT_HIBERNATE	0x0004
5351eede070SRafael J. Wysocki #define PM_EVENT_QUIESCE	0x0008
5361eede070SRafael J. Wysocki #define PM_EVENT_RESUME		0x0010
5371eede070SRafael J. Wysocki #define PM_EVENT_THAW		0x0020
5381eede070SRafael J. Wysocki #define PM_EVENT_RESTORE	0x0040
5391eede070SRafael J. Wysocki #define PM_EVENT_RECOVER	0x0080
5408111d1b5SAlan Stern #define PM_EVENT_USER		0x0100
5418111d1b5SAlan Stern #define PM_EVENT_REMOTE		0x0200
5428111d1b5SAlan Stern #define PM_EVENT_AUTO		0x0400
5431eede070SRafael J. Wysocki 
5441eede070SRafael J. Wysocki #define PM_EVENT_SLEEP		(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
5458111d1b5SAlan Stern #define PM_EVENT_USER_SUSPEND	(PM_EVENT_USER | PM_EVENT_SUSPEND)
5468111d1b5SAlan Stern #define PM_EVENT_USER_RESUME	(PM_EVENT_USER | PM_EVENT_RESUME)
5477f4f5d45SAlan Stern #define PM_EVENT_REMOTE_RESUME	(PM_EVENT_REMOTE | PM_EVENT_RESUME)
5488111d1b5SAlan Stern #define PM_EVENT_AUTO_SUSPEND	(PM_EVENT_AUTO | PM_EVENT_SUSPEND)
5498111d1b5SAlan Stern #define PM_EVENT_AUTO_RESUME	(PM_EVENT_AUTO | PM_EVENT_RESUME)
5501eede070SRafael J. Wysocki 
5511a9a9152SRafael J. Wysocki #define PMSG_INVALID	((struct pm_message){ .event = PM_EVENT_INVALID, })
5528111d1b5SAlan Stern #define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
5531eede070SRafael J. Wysocki #define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
5541eede070SRafael J. Wysocki #define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
5551eede070SRafael J. Wysocki #define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
5561eede070SRafael J. Wysocki #define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
5571eede070SRafael J. Wysocki #define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
5581eede070SRafael J. Wysocki #define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
5591eede070SRafael J. Wysocki #define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
5601eede070SRafael J. Wysocki #define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
5617f4f5d45SAlan Stern #define PMSG_USER_SUSPEND	((struct pm_message) \
5628111d1b5SAlan Stern 					{ .event = PM_EVENT_USER_SUSPEND, })
5637f4f5d45SAlan Stern #define PMSG_USER_RESUME	((struct pm_message) \
5648111d1b5SAlan Stern 					{ .event = PM_EVENT_USER_RESUME, })
5657f4f5d45SAlan Stern #define PMSG_REMOTE_RESUME	((struct pm_message) \
5668111d1b5SAlan Stern 					{ .event = PM_EVENT_REMOTE_RESUME, })
5677f4f5d45SAlan Stern #define PMSG_AUTO_SUSPEND	((struct pm_message) \
5688111d1b5SAlan Stern 					{ .event = PM_EVENT_AUTO_SUSPEND, })
5697f4f5d45SAlan Stern #define PMSG_AUTO_RESUME	((struct pm_message) \
5708111d1b5SAlan Stern 					{ .event = PM_EVENT_AUTO_RESUME, })
5711eede070SRafael J. Wysocki 
5725b1b0b81SAlan Stern #define PMSG_IS_AUTO(msg)	(((msg).event & PM_EVENT_AUTO) != 0)
5735b1b0b81SAlan Stern 
5744d29b2e5SRafael J. Wysocki /*
5755e928f77SRafael J. Wysocki  * Device run-time power management status.
5765e928f77SRafael J. Wysocki  *
5775e928f77SRafael J. Wysocki  * These status labels are used internally by the PM core to indicate the
5785e928f77SRafael J. Wysocki  * current status of a device with respect to the PM core operations.  They do
5795e928f77SRafael J. Wysocki  * not reflect the actual power state of the device or its status as seen by the
5805e928f77SRafael J. Wysocki  * driver.
5815e928f77SRafael J. Wysocki  *
5825e928f77SRafael J. Wysocki  * RPM_ACTIVE		Device is fully operational.  Indicates that the device
5835e928f77SRafael J. Wysocki  *			bus type's ->runtime_resume() callback has completed
5845e928f77SRafael J. Wysocki  *			successfully.
5855e928f77SRafael J. Wysocki  *
5865e928f77SRafael J. Wysocki  * RPM_SUSPENDED	Device bus type's ->runtime_suspend() callback has
5875e928f77SRafael J. Wysocki  *			completed successfully.  The device is regarded as
5885e928f77SRafael J. Wysocki  *			suspended.
5895e928f77SRafael J. Wysocki  *
5905e928f77SRafael J. Wysocki  * RPM_RESUMING		Device bus type's ->runtime_resume() callback is being
5915e928f77SRafael J. Wysocki  *			executed.
5925e928f77SRafael J. Wysocki  *
5935e928f77SRafael J. Wysocki  * RPM_SUSPENDING	Device bus type's ->runtime_suspend() callback is being
5945e928f77SRafael J. Wysocki  *			executed.
5955e928f77SRafael J. Wysocki  */
5965e928f77SRafael J. Wysocki 
5975e928f77SRafael J. Wysocki enum rpm_status {
598c24efa67SRafael J. Wysocki 	RPM_INVALID = -1,
5995e928f77SRafael J. Wysocki 	RPM_ACTIVE = 0,
6005e928f77SRafael J. Wysocki 	RPM_RESUMING,
6015e928f77SRafael J. Wysocki 	RPM_SUSPENDED,
6025e928f77SRafael J. Wysocki 	RPM_SUSPENDING,
6035e928f77SRafael J. Wysocki };
6045e928f77SRafael J. Wysocki 
6054d29b2e5SRafael J. Wysocki /*
6065e928f77SRafael J. Wysocki  * Device run-time power management request types.
6075e928f77SRafael J. Wysocki  *
6085e928f77SRafael J. Wysocki  * RPM_REQ_NONE		Do nothing.
6095e928f77SRafael J. Wysocki  *
6105e928f77SRafael J. Wysocki  * RPM_REQ_IDLE		Run the device bus type's ->runtime_idle() callback
6115e928f77SRafael J. Wysocki  *
6125e928f77SRafael J. Wysocki  * RPM_REQ_SUSPEND	Run the device bus type's ->runtime_suspend() callback
6135e928f77SRafael J. Wysocki  *
61415bcb91dSAlan Stern  * RPM_REQ_AUTOSUSPEND	Same as RPM_REQ_SUSPEND, but not until the device has
61515bcb91dSAlan Stern  *			been inactive for as long as power.autosuspend_delay
61615bcb91dSAlan Stern  *
6175e928f77SRafael J. Wysocki  * RPM_REQ_RESUME	Run the device bus type's ->runtime_resume() callback
6185e928f77SRafael J. Wysocki  */
6195e928f77SRafael J. Wysocki 
6205e928f77SRafael J. Wysocki enum rpm_request {
6215e928f77SRafael J. Wysocki 	RPM_REQ_NONE = 0,
6225e928f77SRafael J. Wysocki 	RPM_REQ_IDLE,
6235e928f77SRafael J. Wysocki 	RPM_REQ_SUSPEND,
62415bcb91dSAlan Stern 	RPM_REQ_AUTOSUSPEND,
6255e928f77SRafael J. Wysocki 	RPM_REQ_RESUME,
6265e928f77SRafael J. Wysocki };
6275e928f77SRafael J. Wysocki 
628074037ecSRafael J. Wysocki struct wakeup_source;
6294990d4feSTony Lindgren struct wake_irq;
63000e7c295SUlf Hansson struct pm_domain_data;
6314605ab65SRafael J. Wysocki 
6325c095a0eSRafael J. Wysocki struct pm_subsys_data {
6335c095a0eSRafael J. Wysocki 	spinlock_t lock;
634ef27bed1SRafael J. Wysocki 	unsigned int refcount;
6355c095a0eSRafael J. Wysocki #ifdef CONFIG_PM_CLK
6360bfa0820SNicolas Pitre 	unsigned int clock_op_might_sleep;
6370bfa0820SNicolas Pitre 	struct mutex clock_mutex;
6385c095a0eSRafael J. Wysocki 	struct list_head clock_list;
6395c095a0eSRafael J. Wysocki #endif
6404605ab65SRafael J. Wysocki #ifdef CONFIG_PM_GENERIC_DOMAINS
641cd0ea672SRafael J. Wysocki 	struct pm_domain_data *domain_data;
6424605ab65SRafael J. Wysocki #endif
6435c095a0eSRafael J. Wysocki };
6445c095a0eSRafael J. Wysocki 
64508810a41SRafael J. Wysocki /*
64608810a41SRafael J. Wysocki  * Driver flags to control system suspend/resume behavior.
64708810a41SRafael J. Wysocki  *
64808810a41SRafael J. Wysocki  * These flags can be set by device drivers at the probe time.  They need not be
64908810a41SRafael J. Wysocki  * cleared by the drivers as the driver core will take care of that.
65008810a41SRafael J. Wysocki  *
651e0751556SRafael J. Wysocki  * NO_DIRECT_COMPLETE: Do not apply direct-complete optimization to the device.
6522fff3f73SRafael J. Wysocki  * SMART_PREPARE: Take the driver ->prepare callback return value into account.
6532fff3f73SRafael J. Wysocki  * SMART_SUSPEND: Avoid resuming the device from runtime suspend.
6542fff3f73SRafael J. Wysocki  * MAY_SKIP_RESUME: Allow driver "noirq" and "early" callbacks to be skipped.
65508810a41SRafael J. Wysocki  *
6562fff3f73SRafael J. Wysocki  * See Documentation/driver-api/pm/devices.rst for details.
65708810a41SRafael J. Wysocki  */
658e0751556SRafael J. Wysocki #define DPM_FLAG_NO_DIRECT_COMPLETE	BIT(0)
65908810a41SRafael J. Wysocki #define DPM_FLAG_SMART_PREPARE		BIT(1)
6600eab11c9SRafael J. Wysocki #define DPM_FLAG_SMART_SUSPEND		BIT(2)
6612a3f3475SRafael J. Wysocki #define DPM_FLAG_MAY_SKIP_RESUME	BIT(3)
66208810a41SRafael J. Wysocki 
6631eede070SRafael J. Wysocki struct dev_pm_info {
6641eede070SRafael J. Wysocki 	pm_message_t		power_state;
6655e928f77SRafael J. Wysocki 	unsigned int		can_wakeup:1;
666b8c76f6aSRafael J. Wysocki 	unsigned int		async_suspend:1;
6679ed98953SRafael J. Wysocki 	bool			in_dpm_list:1;	/* Owned by the PM core */
668f76b168bSAlan Stern 	bool			is_prepared:1;	/* Owned by the PM core */
6696d0e0e84SAlan Stern 	bool			is_suspended:1;	/* Ditto */
6703d2699bcSLiu, Chuansheng 	bool			is_noirq_suspended:1;
6713d2699bcSLiu, Chuansheng 	bool			is_late_suspended:1;
67285945c28SSudeep Holla 	bool			no_pm:1;
673bed2b42dSRafael J. Wysocki 	bool			early_init:1;	/* Owned by the PM core */
674aae4518bSRafael J. Wysocki 	bool			direct_complete:1;	/* Owned by the PM core */
67508810a41SRafael J. Wysocki 	u32			driver_flags;
676074037ecSRafael J. Wysocki 	spinlock_t		lock;
6771eede070SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP
6781eede070SRafael J. Wysocki 	struct list_head	entry;
6795af84b82SRafael J. Wysocki 	struct completion	completion;
680074037ecSRafael J. Wysocki 	struct wakeup_source	*wakeup;
6814ca46ff3SRafael J. Wysocki 	bool			wakeup_path:1;
682feb70af0SRafael J. Wysocki 	bool			syscore:1;
683aa8e54b5STomeu Vizoso 	bool			no_pm_callbacks:1;	/* Owned by the PM core */
6840d4b54c6SRafael J. Wysocki 	unsigned int		must_resume:1;	/* Owned by the PM core */
6850d4b54c6SRafael J. Wysocki 	unsigned int		may_skip_resume:1;	/* Set by subsystems */
686805bdaecSRafael J. Wysocki #else
687805bdaecSRafael J. Wysocki 	unsigned int		should_wakeup:1;
6881eede070SRafael J. Wysocki #endif
689d30d819dSRafael J. Wysocki #ifdef CONFIG_PM
6908234f673SVincent Guittot 	struct hrtimer		suspend_timer;
6916b61d49aSGrygorii Strashko 	u64			timer_expires;
6925e928f77SRafael J. Wysocki 	struct work_struct	work;
6935e928f77SRafael J. Wysocki 	wait_queue_head_t	wait_queue;
6944990d4feSTony Lindgren 	struct wake_irq		*wakeirq;
6955e928f77SRafael J. Wysocki 	atomic_t		usage_count;
6965e928f77SRafael J. Wysocki 	atomic_t		child_count;
6975e928f77SRafael J. Wysocki 	unsigned int		disable_depth:3;
6985e928f77SRafael J. Wysocki 	unsigned int		idle_notification:1;
6995e928f77SRafael J. Wysocki 	unsigned int		request_pending:1;
7005e928f77SRafael J. Wysocki 	unsigned int		deferred_resume:1;
701c745253eSTony Lindgren 	unsigned int		needs_force_resume:1;
70253823639SRafael J. Wysocki 	unsigned int		runtime_auto:1;
703372a12edSUlf Hansson 	bool			ignore_children:1;
7047490e442SAlan Stern 	unsigned int		no_callbacks:1;
705c7b61de5SAlan Stern 	unsigned int		irq_safe:1;
70615bcb91dSAlan Stern 	unsigned int		use_autosuspend:1;
70715bcb91dSAlan Stern 	unsigned int		timer_autosuspends:1;
708e823407fSMing Lei 	unsigned int		memalloc_noio:1;
709baa8809fSRafael J. Wysocki 	unsigned int		links_count;
7105e928f77SRafael J. Wysocki 	enum rpm_request	request;
7115e928f77SRafael J. Wysocki 	enum rpm_status		runtime_status;
712c24efa67SRafael J. Wysocki 	enum rpm_status		last_status;
7135e928f77SRafael J. Wysocki 	int			runtime_error;
71415bcb91dSAlan Stern 	int			autosuspend_delay;
7158234f673SVincent Guittot 	u64			last_busy;
716a08c2a5aSThara Gopinath 	u64			active_time;
717a08c2a5aSThara Gopinath 	u64			suspended_time;
718a08c2a5aSThara Gopinath 	u64			accounting_timestamp;
7195e928f77SRafael J. Wysocki #endif
7205c095a0eSRafael J. Wysocki 	struct pm_subsys_data	*subsys_data;  /* Owned by the subsystem. */
7212d984ad1SRafael J. Wysocki 	void (*set_latency_tolerance)(struct device *, s32);
7225f986c59SRafael J. Wysocki 	struct dev_pm_qos	*qos;
7231eede070SRafael J. Wysocki };
7241eede070SRafael J. Wysocki 
725ef27bed1SRafael J. Wysocki extern int dev_pm_get_subsys_data(struct device *dev);
7261e95e3b2SUlf Hansson extern void dev_pm_put_subsys_data(struct device *dev);
7278d4b9d1bSArjan van de Ven 
7284d29b2e5SRafael J. Wysocki /**
7294d29b2e5SRafael J. Wysocki  * struct dev_pm_domain - power management domain representation.
730e90d5532SRafael J. Wysocki  *
7314d29b2e5SRafael J. Wysocki  * @ops: Power management operations associated with this domain.
732ca765a8cSUlf Hansson  * @start: Called when a user needs to start the device via the domain.
733e90d5532SRafael J. Wysocki  * @detach: Called when removing a device from the domain.
734e90d5532SRafael J. Wysocki  * @activate: Called before executing probe routines for bus types and drivers.
735e90d5532SRafael J. Wysocki  * @sync: Called after successful driver probe.
736e90d5532SRafael J. Wysocki  * @dismiss: Called after unsuccessful driver probe and after driver removal.
7374d29b2e5SRafael J. Wysocki  *
7384d29b2e5SRafael J. Wysocki  * Power domains provide callbacks that are executed during system suspend,
7394d29b2e5SRafael J. Wysocki  * hibernation, system resume and during runtime PM transitions instead of
7404d29b2e5SRafael J. Wysocki  * subsystem-level and driver-level callbacks.
7417538e3dbSRafael J. Wysocki  */
742564b905aSRafael J. Wysocki struct dev_pm_domain {
7437538e3dbSRafael J. Wysocki 	struct dev_pm_ops	ops;
744ca765a8cSUlf Hansson 	int (*start)(struct device *dev);
745c3099a52SUlf Hansson 	void (*detach)(struct device *dev, bool power_off);
746e90d5532SRafael J. Wysocki 	int (*activate)(struct device *dev);
747e90d5532SRafael J. Wysocki 	void (*sync)(struct device *dev);
748e90d5532SRafael J. Wysocki 	void (*dismiss)(struct device *dev);
7497538e3dbSRafael J. Wysocki };
7508d4b9d1bSArjan van de Ven 
7511eede070SRafael J. Wysocki /*
7521eede070SRafael J. Wysocki  * The PM_EVENT_ messages are also used by drivers implementing the legacy
7531eede070SRafael J. Wysocki  * suspend framework, based on the ->suspend() and ->resume() callbacks common
7541eede070SRafael J. Wysocki  * for suspend and hibernation transitions, according to the rules below.
7551eede070SRafael J. Wysocki  */
7561eede070SRafael J. Wysocki 
7571eede070SRafael J. Wysocki /* Necessary, because several drivers use PM_EVENT_PRETHAW */
7581eede070SRafael J. Wysocki #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
7591eede070SRafael J. Wysocki 
7601eede070SRafael J. Wysocki /*
76182bb67f2SDavid Brownell  * One transition is triggered by resume(), after a suspend() call; the
76282bb67f2SDavid Brownell  * message is implicit:
76382bb67f2SDavid Brownell  *
76482bb67f2SDavid Brownell  * ON		Driver starts working again, responding to hardware events
76582bb67f2SDavid Brownell  *		and software requests.  The hardware may have gone through
76682bb67f2SDavid Brownell  *		a power-off reset, or it may have maintained state from the
76782bb67f2SDavid Brownell  *		previous suspend() which the driver will rely on while
76882bb67f2SDavid Brownell  *		resuming.  On most platforms, there are no restrictions on
76982bb67f2SDavid Brownell  *		availability of resources like clocks during resume().
77082bb67f2SDavid Brownell  *
77182bb67f2SDavid Brownell  * Other transitions are triggered by messages sent using suspend().  All
77282bb67f2SDavid Brownell  * these transitions quiesce the driver, so that I/O queues are inactive.
77382bb67f2SDavid Brownell  * That commonly entails turning off IRQs and DMA; there may be rules
77482bb67f2SDavid Brownell  * about how to quiesce that are specific to the bus or the device's type.
77582bb67f2SDavid Brownell  * (For example, network drivers mark the link state.)  Other details may
77682bb67f2SDavid Brownell  * differ according to the message:
77782bb67f2SDavid Brownell  *
77882bb67f2SDavid Brownell  * SUSPEND	Quiesce, enter a low power device state appropriate for
77982bb67f2SDavid Brownell  *		the upcoming system state (such as PCI_D3hot), and enable
78082bb67f2SDavid Brownell  *		wakeup events as appropriate.
78182bb67f2SDavid Brownell  *
7823a2d5b70SRafael J. Wysocki  * HIBERNATE	Enter a low power device state appropriate for the hibernation
7833a2d5b70SRafael J. Wysocki  *		state (eg. ACPI S4) and enable wakeup events as appropriate.
7843a2d5b70SRafael J. Wysocki  *
78582bb67f2SDavid Brownell  * FREEZE	Quiesce operations so that a consistent image can be saved;
78682bb67f2SDavid Brownell  *		but do NOT otherwise enter a low power device state, and do
78782bb67f2SDavid Brownell  *		NOT emit system wakeup events.
78882bb67f2SDavid Brownell  *
78982bb67f2SDavid Brownell  * PRETHAW	Quiesce as if for FREEZE; additionally, prepare for restoring
79082bb67f2SDavid Brownell  *		the system from a snapshot taken after an earlier FREEZE.
79182bb67f2SDavid Brownell  *		Some drivers will need to reset their hardware state instead
79282bb67f2SDavid Brownell  *		of preserving it, to ensure that it's never mistaken for the
79382bb67f2SDavid Brownell  *		state which that earlier snapshot had set up.
79482bb67f2SDavid Brownell  *
79582bb67f2SDavid Brownell  * A minimally power-aware driver treats all messages as SUSPEND, fully
79682bb67f2SDavid Brownell  * reinitializes its device during resume() -- whether or not it was reset
79782bb67f2SDavid Brownell  * during the suspend/resume cycle -- and can't issue wakeup events.
79882bb67f2SDavid Brownell  *
79982bb67f2SDavid Brownell  * More power-aware drivers may also use low power states at runtime as
80082bb67f2SDavid Brownell  * well as during system sleep states like PM_SUSPEND_STANDBY.  They may
80182bb67f2SDavid Brownell  * be able to use wakeup events to exit from runtime low-power states,
80282bb67f2SDavid Brownell  * or from system low-power states such as standby or suspend-to-RAM.
8031da177e4SLinus Torvalds  */
8041da177e4SLinus Torvalds 
805296699deSRafael J. Wysocki #ifdef CONFIG_PM_SLEEP
806d47d81c0SRafael J. Wysocki extern void device_pm_lock(void);
807cf579dfbSRafael J. Wysocki extern void dpm_resume_start(pm_message_t state);
808d1616302SAlan Stern extern void dpm_resume_end(pm_message_t state);
8092a8a8ce6SRafael J. Wysocki extern void dpm_resume_noirq(pm_message_t state);
8102a8a8ce6SRafael J. Wysocki extern void dpm_resume_early(pm_message_t state);
81191e7c75bSRafael J. Wysocki extern void dpm_resume(pm_message_t state);
81291e7c75bSRafael J. Wysocki extern void dpm_complete(pm_message_t state);
8131da177e4SLinus Torvalds 
8141eede070SRafael J. Wysocki extern void device_pm_unlock(void);
815cf579dfbSRafael J. Wysocki extern int dpm_suspend_end(pm_message_t state);
816d1616302SAlan Stern extern int dpm_suspend_start(pm_message_t state);
8172a8a8ce6SRafael J. Wysocki extern int dpm_suspend_noirq(pm_message_t state);
8182a8a8ce6SRafael J. Wysocki extern int dpm_suspend_late(pm_message_t state);
81991e7c75bSRafael J. Wysocki extern int dpm_suspend(pm_message_t state);
82091e7c75bSRafael J. Wysocki extern int dpm_prepare(pm_message_t state);
8210ac85241SDavid Brownell 
822a759de69SYoungjin Jang extern void __suspend_report_result(const char *function, struct device *dev, void *fn, int ret);
82302669492SAndrew Morton 
824a759de69SYoungjin Jang #define suspend_report_result(dev, fn, ret)				\
82502669492SAndrew Morton 	do {								\
826a759de69SYoungjin Jang 		__suspend_report_result(__func__, dev, fn, ret);	\
82702669492SAndrew Morton 	} while (0)
8289a7834d0SAndrew Morton 
829098dff73SRafael J. Wysocki extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
830dfe3212eSMing Lei extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
8316538df80SRafael J. Wysocki 
8326538df80SRafael J. Wysocki extern int pm_generic_prepare(struct device *dev);
833e470d066SRafael J. Wysocki extern int pm_generic_suspend_late(struct device *dev);
834e5291928SRafael J. Wysocki extern int pm_generic_suspend_noirq(struct device *dev);
8356538df80SRafael J. Wysocki extern int pm_generic_suspend(struct device *dev);
836e470d066SRafael J. Wysocki extern int pm_generic_resume_early(struct device *dev);
837e5291928SRafael J. Wysocki extern int pm_generic_resume_noirq(struct device *dev);
8386538df80SRafael J. Wysocki extern int pm_generic_resume(struct device *dev);
839e5291928SRafael J. Wysocki extern int pm_generic_freeze_noirq(struct device *dev);
840e470d066SRafael J. Wysocki extern int pm_generic_freeze_late(struct device *dev);
8416538df80SRafael J. Wysocki extern int pm_generic_freeze(struct device *dev);
842e5291928SRafael J. Wysocki extern int pm_generic_thaw_noirq(struct device *dev);
843e470d066SRafael J. Wysocki extern int pm_generic_thaw_early(struct device *dev);
8446538df80SRafael J. Wysocki extern int pm_generic_thaw(struct device *dev);
845e5291928SRafael J. Wysocki extern int pm_generic_restore_noirq(struct device *dev);
846e470d066SRafael J. Wysocki extern int pm_generic_restore_early(struct device *dev);
8476538df80SRafael J. Wysocki extern int pm_generic_restore(struct device *dev);
848e5291928SRafael J. Wysocki extern int pm_generic_poweroff_noirq(struct device *dev);
849e470d066SRafael J. Wysocki extern int pm_generic_poweroff_late(struct device *dev);
8506538df80SRafael J. Wysocki extern int pm_generic_poweroff(struct device *dev);
8516538df80SRafael J. Wysocki extern void pm_generic_complete(struct device *dev);
8526538df80SRafael J. Wysocki 
85376c70cb5SRafael J. Wysocki extern bool dev_pm_skip_resume(struct device *dev);
854fa2bfeadSRafael J. Wysocki extern bool dev_pm_skip_suspend(struct device *dev);
855c4b65157SRafael J. Wysocki 
856d288e47cSAlan Stern #else /* !CONFIG_PM_SLEEP */
857d288e47cSAlan Stern 
858ffa6a705SCornelia Huck #define device_pm_lock() do {} while (0)
859ffa6a705SCornelia Huck #define device_pm_unlock() do {} while (0)
860ffa6a705SCornelia Huck 
dpm_suspend_start(pm_message_t state)861d1616302SAlan Stern static inline int dpm_suspend_start(pm_message_t state)
862d288e47cSAlan Stern {
863d288e47cSAlan Stern 	return 0;
864d288e47cSAlan Stern }
865d288e47cSAlan Stern 
866a759de69SYoungjin Jang #define suspend_report_result(dev, fn, ret)	do {} while (0)
867d288e47cSAlan Stern 
device_pm_wait_for_dev(struct device * a,struct device * b)868098dff73SRafael J. Wysocki static inline int device_pm_wait_for_dev(struct device *a, struct device *b)
869098dff73SRafael J. Wysocki {
870098dff73SRafael J. Wysocki 	return 0;
871098dff73SRafael J. Wysocki }
8726538df80SRafael J. Wysocki 
dpm_for_each_dev(void * data,void (* fn)(struct device *,void *))873dfe3212eSMing Lei static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *))
874dfe3212eSMing Lei {
875dfe3212eSMing Lei }
876dfe3212eSMing Lei 
8776538df80SRafael J. Wysocki #define pm_generic_prepare		NULL
8780a9efc4dSUlf Hansson #define pm_generic_suspend_late		NULL
8790a9efc4dSUlf Hansson #define pm_generic_suspend_noirq	NULL
8806538df80SRafael J. Wysocki #define pm_generic_suspend		NULL
8810a9efc4dSUlf Hansson #define pm_generic_resume_early		NULL
8820a9efc4dSUlf Hansson #define pm_generic_resume_noirq		NULL
8836538df80SRafael J. Wysocki #define pm_generic_resume		NULL
8840a9efc4dSUlf Hansson #define pm_generic_freeze_noirq		NULL
8850a9efc4dSUlf Hansson #define pm_generic_freeze_late		NULL
8866538df80SRafael J. Wysocki #define pm_generic_freeze		NULL
8870a9efc4dSUlf Hansson #define pm_generic_thaw_noirq		NULL
8880a9efc4dSUlf Hansson #define pm_generic_thaw_early		NULL
8896538df80SRafael J. Wysocki #define pm_generic_thaw			NULL
8900a9efc4dSUlf Hansson #define pm_generic_restore_noirq	NULL
8910a9efc4dSUlf Hansson #define pm_generic_restore_early	NULL
8926538df80SRafael J. Wysocki #define pm_generic_restore		NULL
8930a9efc4dSUlf Hansson #define pm_generic_poweroff_noirq	NULL
8940a9efc4dSUlf Hansson #define pm_generic_poweroff_late	NULL
8956538df80SRafael J. Wysocki #define pm_generic_poweroff		NULL
8966538df80SRafael J. Wysocki #define pm_generic_complete		NULL
897d288e47cSAlan Stern #endif /* !CONFIG_PM_SLEEP */
8980ac85241SDavid Brownell 
899ffa6a705SCornelia Huck /* How to reorder dpm_list after device_move() */
900ffa6a705SCornelia Huck enum dpm_order {
901ffa6a705SCornelia Huck 	DPM_ORDER_NONE,
902ffa6a705SCornelia Huck 	DPM_ORDER_DEV_AFTER_PARENT,
903ffa6a705SCornelia Huck 	DPM_ORDER_PARENT_BEFORE_DEV,
904ffa6a705SCornelia Huck 	DPM_ORDER_DEV_LAST,
905ffa6a705SCornelia Huck };
906ffa6a705SCornelia Huck 
9071da177e4SLinus Torvalds #endif /* _LINUX_PM_H */
908