xref: /linux-6.15/include/linux/pm.h (revision 13b4f9e1)
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 
3778d74f1daSRaag 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
3818d74f1daSRaag Jadav 
3828d74f1daSRaag Jadav #define _DISCARD_PM_OPS(name, license, ns)				\
3838d74f1daSRaag Jadav 	static __maybe_unused const struct dev_pm_ops __static_##name
3848d74f1daSRaag Jadav 
3858d74f1daSRaag Jadav #ifdef CONFIG_PM
3868d74f1daSRaag Jadav #define _EXPORT_DEV_PM_OPS(name, license, ns)		_EXPORT_PM_OPS(name, license, ns)
3870ae101fdSPaul Cercueil #else
3888d74f1daSRaag Jadav #define _EXPORT_DEV_PM_OPS(name, license, ns)		_DISCARD_PM_OPS(name, license, ns)
3890ae101fdSPaul Cercueil #endif
3900ae101fdSPaul Cercueil 
3918d74f1daSRaag Jadav #ifdef CONFIG_PM_SLEEP
3928d74f1daSRaag Jadav #define _EXPORT_DEV_SLEEP_PM_OPS(name, license, ns)	_EXPORT_PM_OPS(name, license, ns)
3938d74f1daSRaag Jadav #else
3948d74f1daSRaag Jadav #define _EXPORT_DEV_SLEEP_PM_OPS(name, license, ns)	_DISCARD_PM_OPS(name, license, ns)
3958d74f1daSRaag Jadav #endif
3968d74f1daSRaag Jadav 
39734e1ed18SPaul Cercueil #define EXPORT_DEV_PM_OPS(name)				_EXPORT_DEV_PM_OPS(name, "", "")
398ddb5cdbaSMasahiro Yamada #define EXPORT_GPL_DEV_PM_OPS(name)			_EXPORT_DEV_PM_OPS(name, "GPL", "")
39934e1ed18SPaul Cercueil #define EXPORT_NS_DEV_PM_OPS(name, ns)			_EXPORT_DEV_PM_OPS(name, "", #ns)
400ddb5cdbaSMasahiro Yamada #define EXPORT_NS_GPL_DEV_PM_OPS(name, ns)		_EXPORT_DEV_PM_OPS(name, "GPL", #ns)
40134e1ed18SPaul Cercueil 
4028d74f1daSRaag Jadav #define EXPORT_DEV_SLEEP_PM_OPS(name)			_EXPORT_DEV_SLEEP_PM_OPS(name, "", "")
4038d74f1daSRaag Jadav #define EXPORT_GPL_DEV_SLEEP_PM_OPS(name)		_EXPORT_DEV_SLEEP_PM_OPS(name, "GPL", "")
4048d74f1daSRaag Jadav #define EXPORT_NS_DEV_SLEEP_PM_OPS(name, ns)		_EXPORT_DEV_SLEEP_PM_OPS(name, "", #ns)
4058d74f1daSRaag Jadav #define EXPORT_NS_GPL_DEV_SLEEP_PM_OPS(name, ns)	_EXPORT_DEV_SLEEP_PM_OPS(name, "GPL", #ns)
4068d74f1daSRaag Jadav 
4079d62ec6cSAlbin Tonnerre /*
4089d62ec6cSAlbin Tonnerre  * Use this if you want to use the same suspend and resume callbacks for suspend
4099d62ec6cSAlbin Tonnerre  * to RAM and hibernation.
4100ae101fdSPaul Cercueil  *
4110ae101fdSPaul Cercueil  * If the underlying dev_pm_ops struct symbol has to be exported, use
4120ae101fdSPaul Cercueil  * EXPORT_SIMPLE_DEV_PM_OPS() or EXPORT_GPL_SIMPLE_DEV_PM_OPS() instead.
4139d62ec6cSAlbin Tonnerre  */
4141a3c7bb0SPaul Cercueil #define DEFINE_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4150ae101fdSPaul Cercueil 	_DEFINE_DEV_PM_OPS(name, suspend_fn, resume_fn, NULL, NULL, NULL)
4160ae101fdSPaul Cercueil 
4170ae101fdSPaul Cercueil #define EXPORT_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4188d74f1daSRaag Jadav 	EXPORT_DEV_SLEEP_PM_OPS(name) = { \
41934e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
42034e1ed18SPaul Cercueil 	}
4210ae101fdSPaul Cercueil #define EXPORT_GPL_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4228d74f1daSRaag Jadav 	EXPORT_GPL_DEV_SLEEP_PM_OPS(name) = { \
42334e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
42434e1ed18SPaul Cercueil 	}
425a8e2512eSJonathan Cameron #define EXPORT_NS_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn, ns)	\
4268d74f1daSRaag Jadav 	EXPORT_NS_DEV_SLEEP_PM_OPS(name, ns) = { \
42734e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
42834e1ed18SPaul Cercueil 	}
429a8e2512eSJonathan Cameron #define EXPORT_NS_GPL_SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn, ns)	\
4308d74f1daSRaag Jadav 	EXPORT_NS_GPL_DEV_SLEEP_PM_OPS(name, ns) = { \
43134e1ed18SPaul Cercueil 		SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
43234e1ed18SPaul Cercueil 	}
4339d62ec6cSAlbin Tonnerre 
4343f4b3251SPaul Cercueil /* Deprecated. Use DEFINE_SIMPLE_DEV_PM_OPS() instead. */
4353f4b3251SPaul Cercueil #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4363f4b3251SPaul Cercueil const struct dev_pm_ops __maybe_unused name = { \
4373f4b3251SPaul Cercueil 	SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
4383f4b3251SPaul Cercueil }
4393f4b3251SPaul Cercueil 
440d690b2cdSRafael J. Wysocki /*
441d690b2cdSRafael J. Wysocki  * Use this for defining a set of PM operations to be used in all situations
4423e54d151SLad, Prabhakar  * (system suspend, hibernation or runtime PM).
443c4882525SRafael J. Wysocki  * NOTE: In general, system suspend callbacks, .suspend() and .resume(), should
444c4882525SRafael J. Wysocki  * be different from the corresponding runtime PM callbacks, .runtime_suspend(),
445c4882525SRafael J. Wysocki  * and .runtime_resume(), because .runtime_suspend() always works on an already
446c4882525SRafael J. Wysocki  * quiescent device, while .suspend() should assume that the device may be doing
447c4882525SRafael J. Wysocki  * something when it is called (it should ensure that the device will be
448c4882525SRafael J. Wysocki  * quiescent after it has returned).  Therefore it's better to point the "late"
449c4882525SRafael J. Wysocki  * suspend and "early" resume callback pointers, .suspend_late() and
450c4882525SRafael J. Wysocki  * .resume_early(), to the same routines as .runtime_suspend() and
451c4882525SRafael J. Wysocki  * .runtime_resume(), respectively (and analogously for hibernation).
4523f4b3251SPaul Cercueil  *
4539d861919SPaul Cercueil  * Deprecated. You most likely don't want this macro. Use
4549d861919SPaul Cercueil  * DEFINE_RUNTIME_DEV_PM_OPS() instead.
455d690b2cdSRafael J. Wysocki  */
456d690b2cdSRafael J. Wysocki #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
457756a64ceSPaul Cercueil const struct dev_pm_ops __maybe_unused name = { \
458d690b2cdSRafael J. Wysocki 	SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
459d690b2cdSRafael J. Wysocki 	SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
460d690b2cdSRafael J. Wysocki }
461d690b2cdSRafael J. Wysocki 
4622a6c0b47SAndy Shevchenko /*
4632a6c0b47SAndy Shevchenko  * Use this if you want to have the suspend and resume callbacks be called
4642a6c0b47SAndy Shevchenko  * with IRQs disabled.
4652a6c0b47SAndy Shevchenko  */
4662a6c0b47SAndy Shevchenko #define DEFINE_NOIRQ_DEV_PM_OPS(name, suspend_fn, resume_fn) \
4672a6c0b47SAndy Shevchenko const struct dev_pm_ops name = { \
4682a6c0b47SAndy Shevchenko 	NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
4692a6c0b47SAndy Shevchenko }
4702a6c0b47SAndy Shevchenko 
471c06ef740SPaul Cercueil #define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))
4721a3c7bb0SPaul Cercueil #define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), (_ptr))
4737a82e97aSPaul Cercueil 
4744d29b2e5SRafael J. Wysocki /*
4751eede070SRafael J. Wysocki  * PM_EVENT_ messages
4761eede070SRafael J. Wysocki  *
4771eede070SRafael J. Wysocki  * The following PM_EVENT_ messages are defined for the internal use of the PM
4781eede070SRafael J. Wysocki  * core, in order to provide a mechanism allowing the high level suspend and
4791eede070SRafael J. Wysocki  * hibernation code to convey the necessary information to the device PM core
4801eede070SRafael J. Wysocki  * code:
4811eede070SRafael J. Wysocki  *
4821eede070SRafael J. Wysocki  * ON		No transition.
4831eede070SRafael J. Wysocki  *
4841eede070SRafael J. Wysocki  * FREEZE	System is going to hibernate, call ->prepare() and ->freeze()
4851eede070SRafael J. Wysocki  *		for all devices.
4861eede070SRafael J. Wysocki  *
4871eede070SRafael J. Wysocki  * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
4881eede070SRafael J. Wysocki  *		for all devices.
4891eede070SRafael J. Wysocki  *
4901eede070SRafael J. Wysocki  * HIBERNATE	Hibernation image has been saved, call ->prepare() and
4911eede070SRafael J. Wysocki  *		->poweroff() for all devices.
4921eede070SRafael J. Wysocki  *
4931eede070SRafael J. Wysocki  * QUIESCE	Contents of main memory are going to be restored from a (loaded)
4941eede070SRafael J. Wysocki  *		hibernation image, call ->prepare() and ->freeze() for all
4951eede070SRafael J. Wysocki  *		devices.
4961eede070SRafael J. Wysocki  *
4971eede070SRafael J. Wysocki  * RESUME	System is resuming, call ->resume() and ->complete() for all
4981eede070SRafael J. Wysocki  *		devices.
4991eede070SRafael J. Wysocki  *
5001eede070SRafael J. Wysocki  * THAW		Hibernation image has been created, call ->thaw() and
5011eede070SRafael J. Wysocki  *		->complete() for all devices.
5021eede070SRafael J. Wysocki  *
5031eede070SRafael J. Wysocki  * RESTORE	Contents of main memory have been restored from a hibernation
5041eede070SRafael J. Wysocki  *		image, call ->restore() and ->complete() for all devices.
5051eede070SRafael J. Wysocki  *
5061eede070SRafael J. Wysocki  * RECOVER	Creation of a hibernation image or restoration of the main
5071eede070SRafael J. Wysocki  *		memory contents from a hibernation image has failed, call
5081eede070SRafael J. Wysocki  *		->thaw() and ->complete() for all devices.
5098111d1b5SAlan Stern  *
5108111d1b5SAlan Stern  * The following PM_EVENT_ messages are defined for internal use by
5118111d1b5SAlan Stern  * kernel subsystems.  They are never issued by the PM core.
5128111d1b5SAlan Stern  *
5138111d1b5SAlan Stern  * USER_SUSPEND		Manual selective suspend was issued by userspace.
5148111d1b5SAlan Stern  *
5158111d1b5SAlan Stern  * USER_RESUME		Manual selective resume was issued by userspace.
5168111d1b5SAlan Stern  *
5178111d1b5SAlan Stern  * REMOTE_WAKEUP	Remote-wakeup request was received from the device.
5188111d1b5SAlan Stern  *
5198111d1b5SAlan Stern  * AUTO_SUSPEND		Automatic (device idle) runtime suspend was
5208111d1b5SAlan Stern  *			initiated by the subsystem.
5218111d1b5SAlan Stern  *
5228111d1b5SAlan Stern  * AUTO_RESUME		Automatic (device needed) runtime resume was
5238111d1b5SAlan Stern  *			requested by a driver.
5241eede070SRafael J. Wysocki  */
5251eede070SRafael J. Wysocki 
5261a9a9152SRafael J. Wysocki #define PM_EVENT_INVALID	(-1)
5271eede070SRafael J. Wysocki #define PM_EVENT_ON		0x0000
5281eede070SRafael J. Wysocki #define PM_EVENT_FREEZE		0x0001
5291eede070SRafael J. Wysocki #define PM_EVENT_SUSPEND	0x0002
5301eede070SRafael J. Wysocki #define PM_EVENT_HIBERNATE	0x0004
5311eede070SRafael J. Wysocki #define PM_EVENT_QUIESCE	0x0008
5321eede070SRafael J. Wysocki #define PM_EVENT_RESUME		0x0010
5331eede070SRafael J. Wysocki #define PM_EVENT_THAW		0x0020
5341eede070SRafael J. Wysocki #define PM_EVENT_RESTORE	0x0040
5351eede070SRafael J. Wysocki #define PM_EVENT_RECOVER	0x0080
5368111d1b5SAlan Stern #define PM_EVENT_USER		0x0100
5378111d1b5SAlan Stern #define PM_EVENT_REMOTE		0x0200
5388111d1b5SAlan Stern #define PM_EVENT_AUTO		0x0400
5391eede070SRafael J. Wysocki 
5401eede070SRafael J. Wysocki #define PM_EVENT_SLEEP		(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
5418111d1b5SAlan Stern #define PM_EVENT_USER_SUSPEND	(PM_EVENT_USER | PM_EVENT_SUSPEND)
5428111d1b5SAlan Stern #define PM_EVENT_USER_RESUME	(PM_EVENT_USER | PM_EVENT_RESUME)
5437f4f5d45SAlan Stern #define PM_EVENT_REMOTE_RESUME	(PM_EVENT_REMOTE | PM_EVENT_RESUME)
5448111d1b5SAlan Stern #define PM_EVENT_AUTO_SUSPEND	(PM_EVENT_AUTO | PM_EVENT_SUSPEND)
5458111d1b5SAlan Stern #define PM_EVENT_AUTO_RESUME	(PM_EVENT_AUTO | PM_EVENT_RESUME)
5461eede070SRafael J. Wysocki 
5471a9a9152SRafael J. Wysocki #define PMSG_INVALID	((struct pm_message){ .event = PM_EVENT_INVALID, })
5488111d1b5SAlan Stern #define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
5491eede070SRafael J. Wysocki #define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
5501eede070SRafael J. Wysocki #define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
5511eede070SRafael J. Wysocki #define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
5521eede070SRafael J. Wysocki #define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
5531eede070SRafael J. Wysocki #define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
5541eede070SRafael J. Wysocki #define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
5551eede070SRafael J. Wysocki #define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
5561eede070SRafael J. Wysocki #define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
5577f4f5d45SAlan Stern #define PMSG_USER_SUSPEND	((struct pm_message) \
5588111d1b5SAlan Stern 					{ .event = PM_EVENT_USER_SUSPEND, })
5597f4f5d45SAlan Stern #define PMSG_USER_RESUME	((struct pm_message) \
5608111d1b5SAlan Stern 					{ .event = PM_EVENT_USER_RESUME, })
5617f4f5d45SAlan Stern #define PMSG_REMOTE_RESUME	((struct pm_message) \
5628111d1b5SAlan Stern 					{ .event = PM_EVENT_REMOTE_RESUME, })
5637f4f5d45SAlan Stern #define PMSG_AUTO_SUSPEND	((struct pm_message) \
5648111d1b5SAlan Stern 					{ .event = PM_EVENT_AUTO_SUSPEND, })
5657f4f5d45SAlan Stern #define PMSG_AUTO_RESUME	((struct pm_message) \
5668111d1b5SAlan Stern 					{ .event = PM_EVENT_AUTO_RESUME, })
5671eede070SRafael J. Wysocki 
5685b1b0b81SAlan Stern #define PMSG_IS_AUTO(msg)	(((msg).event & PM_EVENT_AUTO) != 0)
569d9b4067aSDuan Chenghao #define PMSG_NO_WAKEUP(msg)	(((msg).event & \
570d9b4067aSDuan Chenghao 				(PM_EVENT_FREEZE | PM_EVENT_QUIESCE)) != 0)
5714d29b2e5SRafael J. Wysocki /*
5725e928f77SRafael J. Wysocki  * Device run-time power management status.
5735e928f77SRafael J. Wysocki  *
5745e928f77SRafael J. Wysocki  * These status labels are used internally by the PM core to indicate the
5755e928f77SRafael J. Wysocki  * current status of a device with respect to the PM core operations.  They do
5765e928f77SRafael J. Wysocki  * not reflect the actual power state of the device or its status as seen by the
5775e928f77SRafael J. Wysocki  * driver.
5785e928f77SRafael J. Wysocki  *
5795e928f77SRafael J. Wysocki  * RPM_ACTIVE		Device is fully operational.  Indicates that the device
5805e928f77SRafael J. Wysocki  *			bus type's ->runtime_resume() callback has completed
5815e928f77SRafael J. Wysocki  *			successfully.
5825e928f77SRafael J. Wysocki  *
5835e928f77SRafael J. Wysocki  * RPM_SUSPENDED	Device bus type's ->runtime_suspend() callback has
5845e928f77SRafael J. Wysocki  *			completed successfully.  The device is regarded as
5855e928f77SRafael J. Wysocki  *			suspended.
5865e928f77SRafael J. Wysocki  *
5875e928f77SRafael J. Wysocki  * RPM_RESUMING		Device bus type's ->runtime_resume() callback is being
5885e928f77SRafael J. Wysocki  *			executed.
5895e928f77SRafael J. Wysocki  *
5905e928f77SRafael J. Wysocki  * RPM_SUSPENDING	Device bus type's ->runtime_suspend() callback is being
5915e928f77SRafael J. Wysocki  *			executed.
5925e928f77SRafael J. Wysocki  */
5935e928f77SRafael J. Wysocki 
5945e928f77SRafael J. Wysocki enum rpm_status {
595c24efa67SRafael J. Wysocki 	RPM_INVALID = -1,
5965e928f77SRafael J. Wysocki 	RPM_ACTIVE = 0,
5975e928f77SRafael J. Wysocki 	RPM_RESUMING,
5985e928f77SRafael J. Wysocki 	RPM_SUSPENDED,
5995e928f77SRafael J. Wysocki 	RPM_SUSPENDING,
6003e5eee14SRafael J. Wysocki 	RPM_BLOCKED,
6015e928f77SRafael J. Wysocki };
6025e928f77SRafael J. Wysocki 
6034d29b2e5SRafael J. Wysocki /*
6045e928f77SRafael J. Wysocki  * Device run-time power management request types.
6055e928f77SRafael J. Wysocki  *
6065e928f77SRafael J. Wysocki  * RPM_REQ_NONE		Do nothing.
6075e928f77SRafael J. Wysocki  *
6085e928f77SRafael J. Wysocki  * RPM_REQ_IDLE		Run the device bus type's ->runtime_idle() callback
6095e928f77SRafael J. Wysocki  *
6105e928f77SRafael J. Wysocki  * RPM_REQ_SUSPEND	Run the device bus type's ->runtime_suspend() callback
6115e928f77SRafael J. Wysocki  *
61215bcb91dSAlan Stern  * RPM_REQ_AUTOSUSPEND	Same as RPM_REQ_SUSPEND, but not until the device has
61315bcb91dSAlan Stern  *			been inactive for as long as power.autosuspend_delay
61415bcb91dSAlan Stern  *
6155e928f77SRafael J. Wysocki  * RPM_REQ_RESUME	Run the device bus type's ->runtime_resume() callback
6165e928f77SRafael J. Wysocki  */
6175e928f77SRafael J. Wysocki 
6185e928f77SRafael J. Wysocki enum rpm_request {
6195e928f77SRafael J. Wysocki 	RPM_REQ_NONE = 0,
6205e928f77SRafael J. Wysocki 	RPM_REQ_IDLE,
6215e928f77SRafael J. Wysocki 	RPM_REQ_SUSPEND,
62215bcb91dSAlan Stern 	RPM_REQ_AUTOSUSPEND,
6235e928f77SRafael J. Wysocki 	RPM_REQ_RESUME,
6245e928f77SRafael J. Wysocki };
6255e928f77SRafael J. Wysocki 
626074037ecSRafael J. Wysocki struct wakeup_source;
6274990d4feSTony Lindgren struct wake_irq;
62800e7c295SUlf Hansson struct pm_domain_data;
6294605ab65SRafael J. Wysocki 
6305c095a0eSRafael J. Wysocki struct pm_subsys_data {
6315c095a0eSRafael J. Wysocki 	spinlock_t lock;
632ef27bed1SRafael J. Wysocki 	unsigned int refcount;
6335c095a0eSRafael J. Wysocki #ifdef CONFIG_PM_CLK
6340bfa0820SNicolas Pitre 	unsigned int clock_op_might_sleep;
6350bfa0820SNicolas Pitre 	struct mutex clock_mutex;
6365c095a0eSRafael J. Wysocki 	struct list_head clock_list;
6375c095a0eSRafael J. Wysocki #endif
6384605ab65SRafael J. Wysocki #ifdef CONFIG_PM_GENERIC_DOMAINS
639cd0ea672SRafael J. Wysocki 	struct pm_domain_data *domain_data;
6404605ab65SRafael J. Wysocki #endif
6415c095a0eSRafael J. Wysocki };
6425c095a0eSRafael J. Wysocki 
64308810a41SRafael J. Wysocki /*
64408810a41SRafael J. Wysocki  * Driver flags to control system suspend/resume behavior.
64508810a41SRafael J. Wysocki  *
64608810a41SRafael J. Wysocki  * These flags can be set by device drivers at the probe time.  They need not be
64708810a41SRafael J. Wysocki  * cleared by the drivers as the driver core will take care of that.
64808810a41SRafael J. Wysocki  *
649e0751556SRafael J. Wysocki  * NO_DIRECT_COMPLETE: Do not apply direct-complete optimization to the device.
6502fff3f73SRafael J. Wysocki  * SMART_PREPARE: Take the driver ->prepare callback return value into account.
6512fff3f73SRafael J. Wysocki  * SMART_SUSPEND: Avoid resuming the device from runtime suspend.
6522fff3f73SRafael J. Wysocki  * MAY_SKIP_RESUME: Allow driver "noirq" and "early" callbacks to be skipped.
65308810a41SRafael J. Wysocki  *
6542fff3f73SRafael J. Wysocki  * See Documentation/driver-api/pm/devices.rst for details.
65508810a41SRafael J. Wysocki  */
656e0751556SRafael J. Wysocki #define DPM_FLAG_NO_DIRECT_COMPLETE	BIT(0)
65708810a41SRafael J. Wysocki #define DPM_FLAG_SMART_PREPARE		BIT(1)
6580eab11c9SRafael J. Wysocki #define DPM_FLAG_SMART_SUSPEND		BIT(2)
6592a3f3475SRafael J. Wysocki #define DPM_FLAG_MAY_SKIP_RESUME	BIT(3)
66008810a41SRafael J. Wysocki 
6611eede070SRafael J. Wysocki struct dev_pm_info {
6621eede070SRafael J. Wysocki 	pm_message_t		power_state;
663b017500aSRafael J. Wysocki 	bool			can_wakeup:1;
664b017500aSRafael J. Wysocki 	bool			async_suspend:1;
6659ed98953SRafael J. Wysocki 	bool			in_dpm_list:1;	/* Owned by the PM core */
666f76b168bSAlan Stern 	bool			is_prepared:1;	/* Owned by the PM core */
6676d0e0e84SAlan Stern 	bool			is_suspended:1;	/* Ditto */
6683d2699bcSLiu, Chuansheng 	bool			is_noirq_suspended:1;
6693d2699bcSLiu, Chuansheng 	bool			is_late_suspended:1;
67085945c28SSudeep Holla 	bool			no_pm:1;
671bed2b42dSRafael J. Wysocki 	bool			early_init:1;	/* Owned by the PM core */
672aae4518bSRafael J. Wysocki 	bool			direct_complete:1;	/* Owned by the PM core */
67308810a41SRafael J. Wysocki 	u32			driver_flags;
674074037ecSRafael J. Wysocki 	spinlock_t		lock;
6751eede070SRafael J. Wysocki #ifdef CONFIG_PM_SLEEP
6761eede070SRafael J. Wysocki 	struct list_head	entry;
6775af84b82SRafael J. Wysocki 	struct completion	completion;
678074037ecSRafael J. Wysocki 	struct wakeup_source	*wakeup;
6794ca46ff3SRafael J. Wysocki 	bool			wakeup_path:1;
680feb70af0SRafael J. Wysocki 	bool			syscore:1;
681aa8e54b5STomeu Vizoso 	bool			no_pm_callbacks:1;	/* Owned by the PM core */
682*3038b22bSRafael J. Wysocki 	bool			work_in_progress:1;	/* Owned by the PM core */
683bca84a7bSRafael J. Wysocki 	bool			smart_suspend:1;	/* Owned by the PM core */
684b017500aSRafael J. Wysocki 	bool			must_resume:1;		/* Owned by the PM core */
685b017500aSRafael J. Wysocki 	bool			may_skip_resume:1;	/* Set by subsystems */
686805bdaecSRafael J. Wysocki #else
687b017500aSRafael J. Wysocki 	bool			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;
698b017500aSRafael J. Wysocki 	bool			idle_notification:1;
699b017500aSRafael J. Wysocki 	bool			request_pending:1;
700b017500aSRafael J. Wysocki 	bool			deferred_resume:1;
701b017500aSRafael J. Wysocki 	bool			needs_force_resume:1;
702b017500aSRafael J. Wysocki 	bool			runtime_auto:1;
703372a12edSUlf Hansson 	bool			ignore_children:1;
704b017500aSRafael J. Wysocki 	bool			no_callbacks:1;
705b017500aSRafael J. Wysocki 	bool			irq_safe:1;
706b017500aSRafael J. Wysocki 	bool			use_autosuspend:1;
707b017500aSRafael J. Wysocki 	bool			timer_autosuspends:1;
708b017500aSRafael J. Wysocki 	bool			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.
7373fbc5c3bSUlf Hansson  * @set_performance_state: Called to request a new performance state.
7384d29b2e5SRafael J. Wysocki  *
7394d29b2e5SRafael J. Wysocki  * Power domains provide callbacks that are executed during system suspend,
7404d29b2e5SRafael J. Wysocki  * hibernation, system resume and during runtime PM transitions instead of
7414d29b2e5SRafael J. Wysocki  * subsystem-level and driver-level callbacks.
7427538e3dbSRafael J. Wysocki  */
743564b905aSRafael J. Wysocki struct dev_pm_domain {
7447538e3dbSRafael J. Wysocki 	struct dev_pm_ops	ops;
745ca765a8cSUlf Hansson 	int (*start)(struct device *dev);
746c3099a52SUlf Hansson 	void (*detach)(struct device *dev, bool power_off);
747e90d5532SRafael J. Wysocki 	int (*activate)(struct device *dev);
748e90d5532SRafael J. Wysocki 	void (*sync)(struct device *dev);
749e90d5532SRafael J. Wysocki 	void (*dismiss)(struct device *dev);
7503fbc5c3bSUlf Hansson 	int (*set_performance_state)(struct device *dev, unsigned int state);
7517538e3dbSRafael J. Wysocki };
7528d4b9d1bSArjan van de Ven 
7531eede070SRafael J. Wysocki /*
7541eede070SRafael J. Wysocki  * The PM_EVENT_ messages are also used by drivers implementing the legacy
7551eede070SRafael J. Wysocki  * suspend framework, based on the ->suspend() and ->resume() callbacks common
7561eede070SRafael J. Wysocki  * for suspend and hibernation transitions, according to the rules below.
7571eede070SRafael J. Wysocki  */
7581eede070SRafael J. Wysocki 
7591eede070SRafael J. Wysocki /* Necessary, because several drivers use PM_EVENT_PRETHAW */
7601eede070SRafael J. Wysocki #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
7611eede070SRafael J. Wysocki 
7621eede070SRafael J. Wysocki /*
76382bb67f2SDavid Brownell  * One transition is triggered by resume(), after a suspend() call; the
76482bb67f2SDavid Brownell  * message is implicit:
76582bb67f2SDavid Brownell  *
76682bb67f2SDavid Brownell  * ON		Driver starts working again, responding to hardware events
76782bb67f2SDavid Brownell  *		and software requests.  The hardware may have gone through
76882bb67f2SDavid Brownell  *		a power-off reset, or it may have maintained state from the
76982bb67f2SDavid Brownell  *		previous suspend() which the driver will rely on while
77082bb67f2SDavid Brownell  *		resuming.  On most platforms, there are no restrictions on
77182bb67f2SDavid Brownell  *		availability of resources like clocks during resume().
77282bb67f2SDavid Brownell  *
77382bb67f2SDavid Brownell  * Other transitions are triggered by messages sent using suspend().  All
77482bb67f2SDavid Brownell  * these transitions quiesce the driver, so that I/O queues are inactive.
77582bb67f2SDavid Brownell  * That commonly entails turning off IRQs and DMA; there may be rules
77682bb67f2SDavid Brownell  * about how to quiesce that are specific to the bus or the device's type.
77782bb67f2SDavid Brownell  * (For example, network drivers mark the link state.)  Other details may
77882bb67f2SDavid Brownell  * differ according to the message:
77982bb67f2SDavid Brownell  *
78082bb67f2SDavid Brownell  * SUSPEND	Quiesce, enter a low power device state appropriate for
78182bb67f2SDavid Brownell  *		the upcoming system state (such as PCI_D3hot), and enable
78282bb67f2SDavid Brownell  *		wakeup events as appropriate.
78382bb67f2SDavid Brownell  *
7843a2d5b70SRafael J. Wysocki  * HIBERNATE	Enter a low power device state appropriate for the hibernation
7853a2d5b70SRafael J. Wysocki  *		state (eg. ACPI S4) and enable wakeup events as appropriate.
7863a2d5b70SRafael J. Wysocki  *
78782bb67f2SDavid Brownell  * FREEZE	Quiesce operations so that a consistent image can be saved;
78882bb67f2SDavid Brownell  *		but do NOT otherwise enter a low power device state, and do
78982bb67f2SDavid Brownell  *		NOT emit system wakeup events.
79082bb67f2SDavid Brownell  *
79182bb67f2SDavid Brownell  * PRETHAW	Quiesce as if for FREEZE; additionally, prepare for restoring
79282bb67f2SDavid Brownell  *		the system from a snapshot taken after an earlier FREEZE.
79382bb67f2SDavid Brownell  *		Some drivers will need to reset their hardware state instead
79482bb67f2SDavid Brownell  *		of preserving it, to ensure that it's never mistaken for the
79582bb67f2SDavid Brownell  *		state which that earlier snapshot had set up.
79682bb67f2SDavid Brownell  *
79782bb67f2SDavid Brownell  * A minimally power-aware driver treats all messages as SUSPEND, fully
79882bb67f2SDavid Brownell  * reinitializes its device during resume() -- whether or not it was reset
79982bb67f2SDavid Brownell  * during the suspend/resume cycle -- and can't issue wakeup events.
80082bb67f2SDavid Brownell  *
80182bb67f2SDavid Brownell  * More power-aware drivers may also use low power states at runtime as
80282bb67f2SDavid Brownell  * well as during system sleep states like PM_SUSPEND_STANDBY.  They may
80382bb67f2SDavid Brownell  * be able to use wakeup events to exit from runtime low-power states,
80482bb67f2SDavid Brownell  * or from system low-power states such as standby or suspend-to-RAM.
8051da177e4SLinus Torvalds  */
8061da177e4SLinus Torvalds 
807296699deSRafael J. Wysocki #ifdef CONFIG_PM_SLEEP
808d47d81c0SRafael J. Wysocki extern void device_pm_lock(void);
809cf579dfbSRafael J. Wysocki extern void dpm_resume_start(pm_message_t state);
810d1616302SAlan Stern extern void dpm_resume_end(pm_message_t state);
8112a8a8ce6SRafael J. Wysocki extern void dpm_resume_noirq(pm_message_t state);
8122a8a8ce6SRafael J. Wysocki extern void dpm_resume_early(pm_message_t state);
81391e7c75bSRafael J. Wysocki extern void dpm_resume(pm_message_t state);
81491e7c75bSRafael J. Wysocki extern void dpm_complete(pm_message_t state);
8151da177e4SLinus Torvalds 
8161eede070SRafael J. Wysocki extern void device_pm_unlock(void);
817cf579dfbSRafael J. Wysocki extern int dpm_suspend_end(pm_message_t state);
818d1616302SAlan Stern extern int dpm_suspend_start(pm_message_t state);
8192a8a8ce6SRafael J. Wysocki extern int dpm_suspend_noirq(pm_message_t state);
8202a8a8ce6SRafael J. Wysocki extern int dpm_suspend_late(pm_message_t state);
82191e7c75bSRafael J. Wysocki extern int dpm_suspend(pm_message_t state);
82291e7c75bSRafael J. Wysocki extern int dpm_prepare(pm_message_t state);
8230ac85241SDavid Brownell 
824a759de69SYoungjin Jang extern void __suspend_report_result(const char *function, struct device *dev, void *fn, int ret);
82502669492SAndrew Morton 
826a759de69SYoungjin Jang #define suspend_report_result(dev, fn, ret)				\
82702669492SAndrew Morton 	do {								\
828a759de69SYoungjin Jang 		__suspend_report_result(__func__, dev, fn, ret);	\
82902669492SAndrew Morton 	} while (0)
8309a7834d0SAndrew Morton 
831098dff73SRafael J. Wysocki extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
832dfe3212eSMing Lei extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
8336538df80SRafael J. Wysocki 
8346538df80SRafael J. Wysocki extern int pm_generic_prepare(struct device *dev);
835e470d066SRafael J. Wysocki extern int pm_generic_suspend_late(struct device *dev);
836e5291928SRafael J. Wysocki extern int pm_generic_suspend_noirq(struct device *dev);
8376538df80SRafael J. Wysocki extern int pm_generic_suspend(struct device *dev);
838e470d066SRafael J. Wysocki extern int pm_generic_resume_early(struct device *dev);
839e5291928SRafael J. Wysocki extern int pm_generic_resume_noirq(struct device *dev);
8406538df80SRafael J. Wysocki extern int pm_generic_resume(struct device *dev);
841e5291928SRafael J. Wysocki extern int pm_generic_freeze_noirq(struct device *dev);
8426538df80SRafael J. Wysocki extern int pm_generic_freeze(struct device *dev);
843e5291928SRafael J. Wysocki extern int pm_generic_thaw_noirq(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
8856538df80SRafael J. Wysocki #define pm_generic_freeze		NULL
8860a9efc4dSUlf Hansson #define pm_generic_thaw_noirq		NULL
8876538df80SRafael J. Wysocki #define pm_generic_thaw			NULL
8880a9efc4dSUlf Hansson #define pm_generic_restore_noirq	NULL
8890a9efc4dSUlf Hansson #define pm_generic_restore_early	NULL
8906538df80SRafael J. Wysocki #define pm_generic_restore		NULL
8910a9efc4dSUlf Hansson #define pm_generic_poweroff_noirq	NULL
8920a9efc4dSUlf Hansson #define pm_generic_poweroff_late	NULL
8936538df80SRafael J. Wysocki #define pm_generic_poweroff		NULL
8946538df80SRafael J. Wysocki #define pm_generic_complete		NULL
895d288e47cSAlan Stern #endif /* !CONFIG_PM_SLEEP */
8960ac85241SDavid Brownell 
897ffa6a705SCornelia Huck /* How to reorder dpm_list after device_move() */
898ffa6a705SCornelia Huck enum dpm_order {
899ffa6a705SCornelia Huck 	DPM_ORDER_NONE,
900ffa6a705SCornelia Huck 	DPM_ORDER_DEV_AFTER_PARENT,
901ffa6a705SCornelia Huck 	DPM_ORDER_PARENT_BEFORE_DEV,
902ffa6a705SCornelia Huck 	DPM_ORDER_DEV_LAST,
903ffa6a705SCornelia Huck };
904ffa6a705SCornelia Huck 
9051da177e4SLinus Torvalds #endif /* _LINUX_PM_H */
906