xref: /OK3568_Linux_fs/kernel/include/linux/pm.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  pm.h - Power management interface
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 2000 Andrew Henroid
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef _LINUX_PM_H
9*4882a593Smuzhiyun #define _LINUX_PM_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/list.h>
12*4882a593Smuzhiyun #include <linux/workqueue.h>
13*4882a593Smuzhiyun #include <linux/spinlock.h>
14*4882a593Smuzhiyun #include <linux/wait.h>
15*4882a593Smuzhiyun #include <linux/timer.h>
16*4882a593Smuzhiyun #include <linux/hrtimer.h>
17*4882a593Smuzhiyun #include <linux/completion.h>
18*4882a593Smuzhiyun #include <linux/android_kabi.h>
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun  * Callbacks for platform drivers to implement.
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun extern void (*pm_power_off)(void);
24*4882a593Smuzhiyun extern void (*pm_power_off_prepare)(void);
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun struct device; /* we have a circular dep with device.h */
27*4882a593Smuzhiyun #ifdef CONFIG_VT_CONSOLE_SLEEP
28*4882a593Smuzhiyun extern void pm_vt_switch_required(struct device *dev, bool required);
29*4882a593Smuzhiyun extern void pm_vt_switch_unregister(struct device *dev);
30*4882a593Smuzhiyun #else
pm_vt_switch_required(struct device * dev,bool required)31*4882a593Smuzhiyun static inline void pm_vt_switch_required(struct device *dev, bool required)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun }
pm_vt_switch_unregister(struct device * dev)34*4882a593Smuzhiyun static inline void pm_vt_switch_unregister(struct device *dev)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun #endif /* CONFIG_VT_CONSOLE_SLEEP */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * Device power management
41*4882a593Smuzhiyun  */
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun struct device;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun #ifdef CONFIG_PM
46*4882a593Smuzhiyun extern const char power_group_name[];		/* = "power" */
47*4882a593Smuzhiyun #else
48*4882a593Smuzhiyun #define power_group_name	NULL
49*4882a593Smuzhiyun #endif
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun typedef struct pm_message {
52*4882a593Smuzhiyun 	int event;
53*4882a593Smuzhiyun } pm_message_t;
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun /**
56*4882a593Smuzhiyun  * struct dev_pm_ops - device PM callbacks.
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  * @prepare: The principal role of this callback is to prevent new children of
59*4882a593Smuzhiyun  *	the device from being registered after it has returned (the driver's
60*4882a593Smuzhiyun  *	subsystem and generally the rest of the kernel is supposed to prevent
61*4882a593Smuzhiyun  *	new calls to the probe method from being made too once @prepare() has
62*4882a593Smuzhiyun  *	succeeded).  If @prepare() detects a situation it cannot handle (e.g.
63*4882a593Smuzhiyun  *	registration of a child already in progress), it may return -EAGAIN, so
64*4882a593Smuzhiyun  *	that the PM core can execute it once again (e.g. after a new child has
65*4882a593Smuzhiyun  *	been registered) to recover from the race condition.
66*4882a593Smuzhiyun  *	This method is executed for all kinds of suspend transitions and is
67*4882a593Smuzhiyun  *	followed by one of the suspend callbacks: @suspend(), @freeze(), or
68*4882a593Smuzhiyun  *	@poweroff().  If the transition is a suspend to memory or standby (that
69*4882a593Smuzhiyun  *	is, not related to hibernation), the return value of @prepare() may be
70*4882a593Smuzhiyun  *	used to indicate to the PM core to leave the device in runtime suspend
71*4882a593Smuzhiyun  *	if applicable.  Namely, if @prepare() returns a positive number, the PM
72*4882a593Smuzhiyun  *	core will understand that as a declaration that the device appears to be
73*4882a593Smuzhiyun  *	runtime-suspended and it may be left in that state during the entire
74*4882a593Smuzhiyun  *	transition and during the subsequent resume if all of its descendants
75*4882a593Smuzhiyun  *	are left in runtime suspend too.  If that happens, @complete() will be
76*4882a593Smuzhiyun  *	executed directly after @prepare() and it must ensure the proper
77*4882a593Smuzhiyun  *	functioning of the device after the system resume.
78*4882a593Smuzhiyun  *	The PM core executes subsystem-level @prepare() for all devices before
79*4882a593Smuzhiyun  *	starting to invoke suspend callbacks for any of them, so generally
80*4882a593Smuzhiyun  *	devices may be assumed to be functional or to respond to runtime resume
81*4882a593Smuzhiyun  *	requests while @prepare() is being executed.  However, device drivers
82*4882a593Smuzhiyun  *	may NOT assume anything about the availability of user space at that
83*4882a593Smuzhiyun  *	time and it is NOT valid to request firmware from within @prepare()
84*4882a593Smuzhiyun  *	(it's too late to do that).  It also is NOT valid to allocate
85*4882a593Smuzhiyun  *	substantial amounts of memory from @prepare() in the GFP_KERNEL mode.
86*4882a593Smuzhiyun  *	[To work around these limitations, drivers may register suspend and
87*4882a593Smuzhiyun  *	hibernation notifiers to be executed before the freezing of tasks.]
88*4882a593Smuzhiyun  *
89*4882a593Smuzhiyun  * @complete: Undo the changes made by @prepare().  This method is executed for
90*4882a593Smuzhiyun  *	all kinds of resume transitions, following one of the resume callbacks:
91*4882a593Smuzhiyun  *	@resume(), @thaw(), @restore().  Also called if the state transition
92*4882a593Smuzhiyun  *	fails before the driver's suspend callback: @suspend(), @freeze() or
93*4882a593Smuzhiyun  *	@poweroff(), can be executed (e.g. if the suspend callback fails for one
94*4882a593Smuzhiyun  *	of the other devices that the PM core has unsuccessfully attempted to
95*4882a593Smuzhiyun  *	suspend earlier).
96*4882a593Smuzhiyun  *	The PM core executes subsystem-level @complete() after it has executed
97*4882a593Smuzhiyun  *	the appropriate resume callbacks for all devices.  If the corresponding
98*4882a593Smuzhiyun  *	@prepare() at the beginning of the suspend transition returned a
99*4882a593Smuzhiyun  *	positive number and the device was left in runtime suspend (without
100*4882a593Smuzhiyun  *	executing any suspend and resume callbacks for it), @complete() will be
101*4882a593Smuzhiyun  *	the only callback executed for the device during resume.  In that case,
102*4882a593Smuzhiyun  *	@complete() must be prepared to do whatever is necessary to ensure the
103*4882a593Smuzhiyun  *	proper functioning of the device after the system resume.  To this end,
104*4882a593Smuzhiyun  *	@complete() can check the power.direct_complete flag of the device to
105*4882a593Smuzhiyun  *	learn whether (unset) or not (set) the previous suspend and resume
106*4882a593Smuzhiyun  *	callbacks have been executed for it.
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * @suspend: Executed before putting the system into a sleep state in which the
109*4882a593Smuzhiyun  *	contents of main memory are preserved.  The exact action to perform
110*4882a593Smuzhiyun  *	depends on the device's subsystem (PM domain, device type, class or bus
111*4882a593Smuzhiyun  *	type), but generally the device must be quiescent after subsystem-level
112*4882a593Smuzhiyun  *	@suspend() has returned, so that it doesn't do any I/O or DMA.
113*4882a593Smuzhiyun  *	Subsystem-level @suspend() is executed for all devices after invoking
114*4882a593Smuzhiyun  *	subsystem-level @prepare() for all of them.
115*4882a593Smuzhiyun  *
116*4882a593Smuzhiyun  * @suspend_late: Continue operations started by @suspend().  For a number of
117*4882a593Smuzhiyun  *	devices @suspend_late() may point to the same callback routine as the
118*4882a593Smuzhiyun  *	runtime suspend callback.
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  * @resume: Executed after waking the system up from a sleep state in which the
121*4882a593Smuzhiyun  *	contents of main memory were preserved.  The exact action to perform
122*4882a593Smuzhiyun  *	depends on the device's subsystem, but generally the driver is expected
123*4882a593Smuzhiyun  *	to start working again, responding to hardware events and software
124*4882a593Smuzhiyun  *	requests (the device itself may be left in a low-power state, waiting
125*4882a593Smuzhiyun  *	for a runtime resume to occur).  The state of the device at the time its
126*4882a593Smuzhiyun  *	driver's @resume() callback is run depends on the platform and subsystem
127*4882a593Smuzhiyun  *	the device belongs to.  On most platforms, there are no restrictions on
128*4882a593Smuzhiyun  *	availability of resources like clocks during @resume().
129*4882a593Smuzhiyun  *	Subsystem-level @resume() is executed for all devices after invoking
130*4882a593Smuzhiyun  *	subsystem-level @resume_noirq() for all of them.
131*4882a593Smuzhiyun  *
132*4882a593Smuzhiyun  * @resume_early: Prepare to execute @resume().  For a number of devices
133*4882a593Smuzhiyun  *	@resume_early() may point to the same callback routine as the runtime
134*4882a593Smuzhiyun  *	resume callback.
135*4882a593Smuzhiyun  *
136*4882a593Smuzhiyun  * @freeze: Hibernation-specific, executed before creating a hibernation image.
137*4882a593Smuzhiyun  *	Analogous to @suspend(), but it should not enable the device to signal
138*4882a593Smuzhiyun  *	wakeup events or change its power state.  The majority of subsystems
139*4882a593Smuzhiyun  *	(with the notable exception of the PCI bus type) expect the driver-level
140*4882a593Smuzhiyun  *	@freeze() to save the device settings in memory to be used by @restore()
141*4882a593Smuzhiyun  *	during the subsequent resume from hibernation.
142*4882a593Smuzhiyun  *	Subsystem-level @freeze() is executed for all devices after invoking
143*4882a593Smuzhiyun  *	subsystem-level @prepare() for all of them.
144*4882a593Smuzhiyun  *
145*4882a593Smuzhiyun  * @freeze_late: Continue operations started by @freeze().  Analogous to
146*4882a593Smuzhiyun  *	@suspend_late(), but it should not enable the device to signal wakeup
147*4882a593Smuzhiyun  *	events or change its power state.
148*4882a593Smuzhiyun  *
149*4882a593Smuzhiyun  * @thaw: Hibernation-specific, executed after creating a hibernation image OR
150*4882a593Smuzhiyun  *	if the creation of an image has failed.  Also executed after a failing
151*4882a593Smuzhiyun  *	attempt to restore the contents of main memory from such an image.
152*4882a593Smuzhiyun  *	Undo the changes made by the preceding @freeze(), so the device can be
153*4882a593Smuzhiyun  *	operated in the same way as immediately before the call to @freeze().
154*4882a593Smuzhiyun  *	Subsystem-level @thaw() is executed for all devices after invoking
155*4882a593Smuzhiyun  *	subsystem-level @thaw_noirq() for all of them.  It also may be executed
156*4882a593Smuzhiyun  *	directly after @freeze() in case of a transition error.
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * @thaw_early: Prepare to execute @thaw().  Undo the changes made by the
159*4882a593Smuzhiyun  *	preceding @freeze_late().
160*4882a593Smuzhiyun  *
161*4882a593Smuzhiyun  * @poweroff: Hibernation-specific, executed after saving a hibernation image.
162*4882a593Smuzhiyun  *	Analogous to @suspend(), but it need not save the device's settings in
163*4882a593Smuzhiyun  *	memory.
164*4882a593Smuzhiyun  *	Subsystem-level @poweroff() is executed for all devices after invoking
165*4882a593Smuzhiyun  *	subsystem-level @prepare() for all of them.
166*4882a593Smuzhiyun  *
167*4882a593Smuzhiyun  * @poweroff_late: Continue operations started by @poweroff().  Analogous to
168*4882a593Smuzhiyun  *	@suspend_late(), but it need not save the device's settings in memory.
169*4882a593Smuzhiyun  *
170*4882a593Smuzhiyun  * @restore: Hibernation-specific, executed after restoring the contents of main
171*4882a593Smuzhiyun  *	memory from a hibernation image, analogous to @resume().
172*4882a593Smuzhiyun  *
173*4882a593Smuzhiyun  * @restore_early: Prepare to execute @restore(), analogous to @resume_early().
174*4882a593Smuzhiyun  *
175*4882a593Smuzhiyun  * @suspend_noirq: Complete the actions started by @suspend().  Carry out any
176*4882a593Smuzhiyun  *	additional operations required for suspending the device that might be
177*4882a593Smuzhiyun  *	racing with its driver's interrupt handler, which is guaranteed not to
178*4882a593Smuzhiyun  *	run while @suspend_noirq() is being executed.
179*4882a593Smuzhiyun  *	It generally is expected that the device will be in a low-power state
180*4882a593Smuzhiyun  *	(appropriate for the target system sleep state) after subsystem-level
181*4882a593Smuzhiyun  *	@suspend_noirq() has returned successfully.  If the device can generate
182*4882a593Smuzhiyun  *	system wakeup signals and is enabled to wake up the system, it should be
183*4882a593Smuzhiyun  *	configured to do so at that time.  However, depending on the platform
184*4882a593Smuzhiyun  *	and device's subsystem, @suspend() or @suspend_late() may be allowed to
185*4882a593Smuzhiyun  *	put the device into the low-power state and configure it to generate
186*4882a593Smuzhiyun  *	wakeup signals, in which case it generally is not necessary to define
187*4882a593Smuzhiyun  *	@suspend_noirq().
188*4882a593Smuzhiyun  *
189*4882a593Smuzhiyun  * @resume_noirq: Prepare for the execution of @resume() by carrying out any
190*4882a593Smuzhiyun  *	operations required for resuming the device that might be racing with
191*4882a593Smuzhiyun  *	its driver's interrupt handler, which is guaranteed not to run while
192*4882a593Smuzhiyun  *	@resume_noirq() is being executed.
193*4882a593Smuzhiyun  *
194*4882a593Smuzhiyun  * @freeze_noirq: Complete the actions started by @freeze().  Carry out any
195*4882a593Smuzhiyun  *	additional operations required for freezing the device that might be
196*4882a593Smuzhiyun  *	racing with its driver's interrupt handler, which is guaranteed not to
197*4882a593Smuzhiyun  *	run while @freeze_noirq() is being executed.
198*4882a593Smuzhiyun  *	The power state of the device should not be changed by either @freeze(),
199*4882a593Smuzhiyun  *	or @freeze_late(), or @freeze_noirq() and it should not be configured to
200*4882a593Smuzhiyun  *	signal system wakeup by any of these callbacks.
201*4882a593Smuzhiyun  *
202*4882a593Smuzhiyun  * @thaw_noirq: Prepare for the execution of @thaw() by carrying out any
203*4882a593Smuzhiyun  *	operations required for thawing the device that might be racing with its
204*4882a593Smuzhiyun  *	driver's interrupt handler, which is guaranteed not to run while
205*4882a593Smuzhiyun  *	@thaw_noirq() is being executed.
206*4882a593Smuzhiyun  *
207*4882a593Smuzhiyun  * @poweroff_noirq: Complete the actions started by @poweroff().  Analogous to
208*4882a593Smuzhiyun  *	@suspend_noirq(), but it need not save the device's settings in memory.
209*4882a593Smuzhiyun  *
210*4882a593Smuzhiyun  * @restore_noirq: Prepare for the execution of @restore() by carrying out any
211*4882a593Smuzhiyun  *	operations required for thawing the device that might be racing with its
212*4882a593Smuzhiyun  *	driver's interrupt handler, which is guaranteed not to run while
213*4882a593Smuzhiyun  *	@restore_noirq() is being executed.  Analogous to @resume_noirq().
214*4882a593Smuzhiyun  *
215*4882a593Smuzhiyun  * @runtime_suspend: Prepare the device for a condition in which it won't be
216*4882a593Smuzhiyun  *	able to communicate with the CPU(s) and RAM due to power management.
217*4882a593Smuzhiyun  *	This need not mean that the device should be put into a low-power state.
218*4882a593Smuzhiyun  *	For example, if the device is behind a link which is about to be turned
219*4882a593Smuzhiyun  *	off, the device may remain at full power.  If the device does go to low
220*4882a593Smuzhiyun  *	power and is capable of generating runtime wakeup events, remote wakeup
221*4882a593Smuzhiyun  *	(i.e., a hardware mechanism allowing the device to request a change of
222*4882a593Smuzhiyun  *	its power state via an interrupt) should be enabled for it.
223*4882a593Smuzhiyun  *
224*4882a593Smuzhiyun  * @runtime_resume: Put the device into the fully active state in response to a
225*4882a593Smuzhiyun  *	wakeup event generated by hardware or at the request of software.  If
226*4882a593Smuzhiyun  *	necessary, put the device into the full-power state and restore its
227*4882a593Smuzhiyun  *	registers, so that it is fully operational.
228*4882a593Smuzhiyun  *
229*4882a593Smuzhiyun  * @runtime_idle: Device appears to be inactive and it might be put into a
230*4882a593Smuzhiyun  *	low-power state if all of the necessary conditions are satisfied.
231*4882a593Smuzhiyun  *	Check these conditions, and return 0 if it's appropriate to let the PM
232*4882a593Smuzhiyun  *	core queue a suspend request for the device.
233*4882a593Smuzhiyun  *
234*4882a593Smuzhiyun  * Several device power state transitions are externally visible, affecting
235*4882a593Smuzhiyun  * the state of pending I/O queues and (for drivers that touch hardware)
236*4882a593Smuzhiyun  * interrupts, wakeups, DMA, and other hardware state.  There may also be
237*4882a593Smuzhiyun  * internal transitions to various low-power modes which are transparent
238*4882a593Smuzhiyun  * to the rest of the driver stack (such as a driver that's ON gating off
239*4882a593Smuzhiyun  * clocks which are not in active use).
240*4882a593Smuzhiyun  *
241*4882a593Smuzhiyun  * The externally visible transitions are handled with the help of callbacks
242*4882a593Smuzhiyun  * included in this structure in such a way that, typically, two levels of
243*4882a593Smuzhiyun  * callbacks are involved.  First, the PM core executes callbacks provided by PM
244*4882a593Smuzhiyun  * domains, device types, classes and bus types.  They are the subsystem-level
245*4882a593Smuzhiyun  * callbacks expected to execute callbacks provided by device drivers, although
246*4882a593Smuzhiyun  * they may choose not to do that.  If the driver callbacks are executed, they
247*4882a593Smuzhiyun  * have to collaborate with the subsystem-level callbacks to achieve the goals
248*4882a593Smuzhiyun  * appropriate for the given system transition, given transition phase and the
249*4882a593Smuzhiyun  * subsystem the device belongs to.
250*4882a593Smuzhiyun  *
251*4882a593Smuzhiyun  * All of the above callbacks, except for @complete(), return error codes.
252*4882a593Smuzhiyun  * However, the error codes returned by @resume(), @thaw(), @restore(),
253*4882a593Smuzhiyun  * @resume_noirq(), @thaw_noirq(), and @restore_noirq(), do not cause the PM
254*4882a593Smuzhiyun  * core to abort the resume transition during which they are returned.  The
255*4882a593Smuzhiyun  * error codes returned in those cases are only printed to the system logs for
256*4882a593Smuzhiyun  * debugging purposes.  Still, it is recommended that drivers only return error
257*4882a593Smuzhiyun  * codes from their resume methods in case of an unrecoverable failure (i.e.
258*4882a593Smuzhiyun  * when the device being handled refuses to resume and becomes unusable) to
259*4882a593Smuzhiyun  * allow the PM core to be modified in the future, so that it can avoid
260*4882a593Smuzhiyun  * attempting to handle devices that failed to resume and their children.
261*4882a593Smuzhiyun  *
262*4882a593Smuzhiyun  * It is allowed to unregister devices while the above callbacks are being
263*4882a593Smuzhiyun  * executed.  However, a callback routine MUST NOT try to unregister the device
264*4882a593Smuzhiyun  * it was called for, although it may unregister children of that device (for
265*4882a593Smuzhiyun  * example, if it detects that a child was unplugged while the system was
266*4882a593Smuzhiyun  * asleep).
267*4882a593Smuzhiyun  *
268*4882a593Smuzhiyun  * There also are callbacks related to runtime power management of devices.
269*4882a593Smuzhiyun  * Again, as a rule these callbacks are executed by the PM core for subsystems
270*4882a593Smuzhiyun  * (PM domains, device types, classes and bus types) and the subsystem-level
271*4882a593Smuzhiyun  * callbacks are expected to invoke the driver callbacks.  Moreover, the exact
272*4882a593Smuzhiyun  * actions to be performed by a device driver's callbacks generally depend on
273*4882a593Smuzhiyun  * the platform and subsystem the device belongs to.
274*4882a593Smuzhiyun  *
275*4882a593Smuzhiyun  * Refer to Documentation/power/runtime_pm.rst for more information about the
276*4882a593Smuzhiyun  * role of the @runtime_suspend(), @runtime_resume() and @runtime_idle()
277*4882a593Smuzhiyun  * callbacks in device runtime power management.
278*4882a593Smuzhiyun  */
279*4882a593Smuzhiyun struct dev_pm_ops {
280*4882a593Smuzhiyun 	int (*prepare)(struct device *dev);
281*4882a593Smuzhiyun 	void (*complete)(struct device *dev);
282*4882a593Smuzhiyun 	int (*suspend)(struct device *dev);
283*4882a593Smuzhiyun 	int (*resume)(struct device *dev);
284*4882a593Smuzhiyun 	int (*freeze)(struct device *dev);
285*4882a593Smuzhiyun 	int (*thaw)(struct device *dev);
286*4882a593Smuzhiyun 	int (*poweroff)(struct device *dev);
287*4882a593Smuzhiyun 	int (*restore)(struct device *dev);
288*4882a593Smuzhiyun 	int (*suspend_late)(struct device *dev);
289*4882a593Smuzhiyun 	int (*resume_early)(struct device *dev);
290*4882a593Smuzhiyun 	int (*freeze_late)(struct device *dev);
291*4882a593Smuzhiyun 	int (*thaw_early)(struct device *dev);
292*4882a593Smuzhiyun 	int (*poweroff_late)(struct device *dev);
293*4882a593Smuzhiyun 	int (*restore_early)(struct device *dev);
294*4882a593Smuzhiyun 	int (*suspend_noirq)(struct device *dev);
295*4882a593Smuzhiyun 	int (*resume_noirq)(struct device *dev);
296*4882a593Smuzhiyun 	int (*freeze_noirq)(struct device *dev);
297*4882a593Smuzhiyun 	int (*thaw_noirq)(struct device *dev);
298*4882a593Smuzhiyun 	int (*poweroff_noirq)(struct device *dev);
299*4882a593Smuzhiyun 	int (*restore_noirq)(struct device *dev);
300*4882a593Smuzhiyun 	int (*runtime_suspend)(struct device *dev);
301*4882a593Smuzhiyun 	int (*runtime_resume)(struct device *dev);
302*4882a593Smuzhiyun 	int (*runtime_idle)(struct device *dev);
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
305*4882a593Smuzhiyun };
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
308*4882a593Smuzhiyun #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
309*4882a593Smuzhiyun 	.suspend = suspend_fn, \
310*4882a593Smuzhiyun 	.resume = resume_fn, \
311*4882a593Smuzhiyun 	.freeze = suspend_fn, \
312*4882a593Smuzhiyun 	.thaw = resume_fn, \
313*4882a593Smuzhiyun 	.poweroff = suspend_fn, \
314*4882a593Smuzhiyun 	.restore = resume_fn,
315*4882a593Smuzhiyun #else
316*4882a593Smuzhiyun #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
317*4882a593Smuzhiyun #endif
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
320*4882a593Smuzhiyun #define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
321*4882a593Smuzhiyun 	.suspend_late = suspend_fn, \
322*4882a593Smuzhiyun 	.resume_early = resume_fn, \
323*4882a593Smuzhiyun 	.freeze_late = suspend_fn, \
324*4882a593Smuzhiyun 	.thaw_early = resume_fn, \
325*4882a593Smuzhiyun 	.poweroff_late = suspend_fn, \
326*4882a593Smuzhiyun 	.restore_early = resume_fn,
327*4882a593Smuzhiyun #else
328*4882a593Smuzhiyun #define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
329*4882a593Smuzhiyun #endif
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
332*4882a593Smuzhiyun #define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
333*4882a593Smuzhiyun 	.suspend_noirq = suspend_fn, \
334*4882a593Smuzhiyun 	.resume_noirq = resume_fn, \
335*4882a593Smuzhiyun 	.freeze_noirq = suspend_fn, \
336*4882a593Smuzhiyun 	.thaw_noirq = resume_fn, \
337*4882a593Smuzhiyun 	.poweroff_noirq = suspend_fn, \
338*4882a593Smuzhiyun 	.restore_noirq = resume_fn,
339*4882a593Smuzhiyun #else
340*4882a593Smuzhiyun #define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
341*4882a593Smuzhiyun #endif
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun #ifdef CONFIG_PM
344*4882a593Smuzhiyun #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
345*4882a593Smuzhiyun 	.runtime_suspend = suspend_fn, \
346*4882a593Smuzhiyun 	.runtime_resume = resume_fn, \
347*4882a593Smuzhiyun 	.runtime_idle = idle_fn,
348*4882a593Smuzhiyun #else
349*4882a593Smuzhiyun #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
350*4882a593Smuzhiyun #endif
351*4882a593Smuzhiyun 
352*4882a593Smuzhiyun /*
353*4882a593Smuzhiyun  * Use this if you want to use the same suspend and resume callbacks for suspend
354*4882a593Smuzhiyun  * to RAM and hibernation.
355*4882a593Smuzhiyun  */
356*4882a593Smuzhiyun #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
357*4882a593Smuzhiyun const struct dev_pm_ops __maybe_unused name = { \
358*4882a593Smuzhiyun 	SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun /*
362*4882a593Smuzhiyun  * Use this for defining a set of PM operations to be used in all situations
363*4882a593Smuzhiyun  * (system suspend, hibernation or runtime PM).
364*4882a593Smuzhiyun  * NOTE: In general, system suspend callbacks, .suspend() and .resume(), should
365*4882a593Smuzhiyun  * be different from the corresponding runtime PM callbacks, .runtime_suspend(),
366*4882a593Smuzhiyun  * and .runtime_resume(), because .runtime_suspend() always works on an already
367*4882a593Smuzhiyun  * quiescent device, while .suspend() should assume that the device may be doing
368*4882a593Smuzhiyun  * something when it is called (it should ensure that the device will be
369*4882a593Smuzhiyun  * quiescent after it has returned).  Therefore it's better to point the "late"
370*4882a593Smuzhiyun  * suspend and "early" resume callback pointers, .suspend_late() and
371*4882a593Smuzhiyun  * .resume_early(), to the same routines as .runtime_suspend() and
372*4882a593Smuzhiyun  * .runtime_resume(), respectively (and analogously for hibernation).
373*4882a593Smuzhiyun  */
374*4882a593Smuzhiyun #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
375*4882a593Smuzhiyun const struct dev_pm_ops __maybe_unused name = { \
376*4882a593Smuzhiyun 	SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
377*4882a593Smuzhiyun 	SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun 
380*4882a593Smuzhiyun #ifdef CONFIG_PM
381*4882a593Smuzhiyun #define pm_ptr(_ptr) (_ptr)
382*4882a593Smuzhiyun #else
383*4882a593Smuzhiyun #define pm_ptr(_ptr) NULL
384*4882a593Smuzhiyun #endif
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun /*
387*4882a593Smuzhiyun  * PM_EVENT_ messages
388*4882a593Smuzhiyun  *
389*4882a593Smuzhiyun  * The following PM_EVENT_ messages are defined for the internal use of the PM
390*4882a593Smuzhiyun  * core, in order to provide a mechanism allowing the high level suspend and
391*4882a593Smuzhiyun  * hibernation code to convey the necessary information to the device PM core
392*4882a593Smuzhiyun  * code:
393*4882a593Smuzhiyun  *
394*4882a593Smuzhiyun  * ON		No transition.
395*4882a593Smuzhiyun  *
396*4882a593Smuzhiyun  * FREEZE	System is going to hibernate, call ->prepare() and ->freeze()
397*4882a593Smuzhiyun  *		for all devices.
398*4882a593Smuzhiyun  *
399*4882a593Smuzhiyun  * SUSPEND	System is going to suspend, call ->prepare() and ->suspend()
400*4882a593Smuzhiyun  *		for all devices.
401*4882a593Smuzhiyun  *
402*4882a593Smuzhiyun  * HIBERNATE	Hibernation image has been saved, call ->prepare() and
403*4882a593Smuzhiyun  *		->poweroff() for all devices.
404*4882a593Smuzhiyun  *
405*4882a593Smuzhiyun  * QUIESCE	Contents of main memory are going to be restored from a (loaded)
406*4882a593Smuzhiyun  *		hibernation image, call ->prepare() and ->freeze() for all
407*4882a593Smuzhiyun  *		devices.
408*4882a593Smuzhiyun  *
409*4882a593Smuzhiyun  * RESUME	System is resuming, call ->resume() and ->complete() for all
410*4882a593Smuzhiyun  *		devices.
411*4882a593Smuzhiyun  *
412*4882a593Smuzhiyun  * THAW		Hibernation image has been created, call ->thaw() and
413*4882a593Smuzhiyun  *		->complete() for all devices.
414*4882a593Smuzhiyun  *
415*4882a593Smuzhiyun  * RESTORE	Contents of main memory have been restored from a hibernation
416*4882a593Smuzhiyun  *		image, call ->restore() and ->complete() for all devices.
417*4882a593Smuzhiyun  *
418*4882a593Smuzhiyun  * RECOVER	Creation of a hibernation image or restoration of the main
419*4882a593Smuzhiyun  *		memory contents from a hibernation image has failed, call
420*4882a593Smuzhiyun  *		->thaw() and ->complete() for all devices.
421*4882a593Smuzhiyun  *
422*4882a593Smuzhiyun  * The following PM_EVENT_ messages are defined for internal use by
423*4882a593Smuzhiyun  * kernel subsystems.  They are never issued by the PM core.
424*4882a593Smuzhiyun  *
425*4882a593Smuzhiyun  * USER_SUSPEND		Manual selective suspend was issued by userspace.
426*4882a593Smuzhiyun  *
427*4882a593Smuzhiyun  * USER_RESUME		Manual selective resume was issued by userspace.
428*4882a593Smuzhiyun  *
429*4882a593Smuzhiyun  * REMOTE_WAKEUP	Remote-wakeup request was received from the device.
430*4882a593Smuzhiyun  *
431*4882a593Smuzhiyun  * AUTO_SUSPEND		Automatic (device idle) runtime suspend was
432*4882a593Smuzhiyun  *			initiated by the subsystem.
433*4882a593Smuzhiyun  *
434*4882a593Smuzhiyun  * AUTO_RESUME		Automatic (device needed) runtime resume was
435*4882a593Smuzhiyun  *			requested by a driver.
436*4882a593Smuzhiyun  */
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun #define PM_EVENT_INVALID	(-1)
439*4882a593Smuzhiyun #define PM_EVENT_ON		0x0000
440*4882a593Smuzhiyun #define PM_EVENT_FREEZE		0x0001
441*4882a593Smuzhiyun #define PM_EVENT_SUSPEND	0x0002
442*4882a593Smuzhiyun #define PM_EVENT_HIBERNATE	0x0004
443*4882a593Smuzhiyun #define PM_EVENT_QUIESCE	0x0008
444*4882a593Smuzhiyun #define PM_EVENT_RESUME		0x0010
445*4882a593Smuzhiyun #define PM_EVENT_THAW		0x0020
446*4882a593Smuzhiyun #define PM_EVENT_RESTORE	0x0040
447*4882a593Smuzhiyun #define PM_EVENT_RECOVER	0x0080
448*4882a593Smuzhiyun #define PM_EVENT_USER		0x0100
449*4882a593Smuzhiyun #define PM_EVENT_REMOTE		0x0200
450*4882a593Smuzhiyun #define PM_EVENT_AUTO		0x0400
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun #define PM_EVENT_SLEEP		(PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
453*4882a593Smuzhiyun #define PM_EVENT_USER_SUSPEND	(PM_EVENT_USER | PM_EVENT_SUSPEND)
454*4882a593Smuzhiyun #define PM_EVENT_USER_RESUME	(PM_EVENT_USER | PM_EVENT_RESUME)
455*4882a593Smuzhiyun #define PM_EVENT_REMOTE_RESUME	(PM_EVENT_REMOTE | PM_EVENT_RESUME)
456*4882a593Smuzhiyun #define PM_EVENT_AUTO_SUSPEND	(PM_EVENT_AUTO | PM_EVENT_SUSPEND)
457*4882a593Smuzhiyun #define PM_EVENT_AUTO_RESUME	(PM_EVENT_AUTO | PM_EVENT_RESUME)
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun #define PMSG_INVALID	((struct pm_message){ .event = PM_EVENT_INVALID, })
460*4882a593Smuzhiyun #define PMSG_ON		((struct pm_message){ .event = PM_EVENT_ON, })
461*4882a593Smuzhiyun #define PMSG_FREEZE	((struct pm_message){ .event = PM_EVENT_FREEZE, })
462*4882a593Smuzhiyun #define PMSG_QUIESCE	((struct pm_message){ .event = PM_EVENT_QUIESCE, })
463*4882a593Smuzhiyun #define PMSG_SUSPEND	((struct pm_message){ .event = PM_EVENT_SUSPEND, })
464*4882a593Smuzhiyun #define PMSG_HIBERNATE	((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
465*4882a593Smuzhiyun #define PMSG_RESUME	((struct pm_message){ .event = PM_EVENT_RESUME, })
466*4882a593Smuzhiyun #define PMSG_THAW	((struct pm_message){ .event = PM_EVENT_THAW, })
467*4882a593Smuzhiyun #define PMSG_RESTORE	((struct pm_message){ .event = PM_EVENT_RESTORE, })
468*4882a593Smuzhiyun #define PMSG_RECOVER	((struct pm_message){ .event = PM_EVENT_RECOVER, })
469*4882a593Smuzhiyun #define PMSG_USER_SUSPEND	((struct pm_message) \
470*4882a593Smuzhiyun 					{ .event = PM_EVENT_USER_SUSPEND, })
471*4882a593Smuzhiyun #define PMSG_USER_RESUME	((struct pm_message) \
472*4882a593Smuzhiyun 					{ .event = PM_EVENT_USER_RESUME, })
473*4882a593Smuzhiyun #define PMSG_REMOTE_RESUME	((struct pm_message) \
474*4882a593Smuzhiyun 					{ .event = PM_EVENT_REMOTE_RESUME, })
475*4882a593Smuzhiyun #define PMSG_AUTO_SUSPEND	((struct pm_message) \
476*4882a593Smuzhiyun 					{ .event = PM_EVENT_AUTO_SUSPEND, })
477*4882a593Smuzhiyun #define PMSG_AUTO_RESUME	((struct pm_message) \
478*4882a593Smuzhiyun 					{ .event = PM_EVENT_AUTO_RESUME, })
479*4882a593Smuzhiyun 
480*4882a593Smuzhiyun #define PMSG_IS_AUTO(msg)	(((msg).event & PM_EVENT_AUTO) != 0)
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun /*
483*4882a593Smuzhiyun  * Device run-time power management status.
484*4882a593Smuzhiyun  *
485*4882a593Smuzhiyun  * These status labels are used internally by the PM core to indicate the
486*4882a593Smuzhiyun  * current status of a device with respect to the PM core operations.  They do
487*4882a593Smuzhiyun  * not reflect the actual power state of the device or its status as seen by the
488*4882a593Smuzhiyun  * driver.
489*4882a593Smuzhiyun  *
490*4882a593Smuzhiyun  * RPM_ACTIVE		Device is fully operational.  Indicates that the device
491*4882a593Smuzhiyun  *			bus type's ->runtime_resume() callback has completed
492*4882a593Smuzhiyun  *			successfully.
493*4882a593Smuzhiyun  *
494*4882a593Smuzhiyun  * RPM_SUSPENDED	Device bus type's ->runtime_suspend() callback has
495*4882a593Smuzhiyun  *			completed successfully.  The device is regarded as
496*4882a593Smuzhiyun  *			suspended.
497*4882a593Smuzhiyun  *
498*4882a593Smuzhiyun  * RPM_RESUMING		Device bus type's ->runtime_resume() callback is being
499*4882a593Smuzhiyun  *			executed.
500*4882a593Smuzhiyun  *
501*4882a593Smuzhiyun  * RPM_SUSPENDING	Device bus type's ->runtime_suspend() callback is being
502*4882a593Smuzhiyun  *			executed.
503*4882a593Smuzhiyun  */
504*4882a593Smuzhiyun 
505*4882a593Smuzhiyun enum rpm_status {
506*4882a593Smuzhiyun 	RPM_ACTIVE = 0,
507*4882a593Smuzhiyun 	RPM_RESUMING,
508*4882a593Smuzhiyun 	RPM_SUSPENDED,
509*4882a593Smuzhiyun 	RPM_SUSPENDING,
510*4882a593Smuzhiyun };
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun /*
513*4882a593Smuzhiyun  * Device run-time power management request types.
514*4882a593Smuzhiyun  *
515*4882a593Smuzhiyun  * RPM_REQ_NONE		Do nothing.
516*4882a593Smuzhiyun  *
517*4882a593Smuzhiyun  * RPM_REQ_IDLE		Run the device bus type's ->runtime_idle() callback
518*4882a593Smuzhiyun  *
519*4882a593Smuzhiyun  * RPM_REQ_SUSPEND	Run the device bus type's ->runtime_suspend() callback
520*4882a593Smuzhiyun  *
521*4882a593Smuzhiyun  * RPM_REQ_AUTOSUSPEND	Same as RPM_REQ_SUSPEND, but not until the device has
522*4882a593Smuzhiyun  *			been inactive for as long as power.autosuspend_delay
523*4882a593Smuzhiyun  *
524*4882a593Smuzhiyun  * RPM_REQ_RESUME	Run the device bus type's ->runtime_resume() callback
525*4882a593Smuzhiyun  */
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun enum rpm_request {
528*4882a593Smuzhiyun 	RPM_REQ_NONE = 0,
529*4882a593Smuzhiyun 	RPM_REQ_IDLE,
530*4882a593Smuzhiyun 	RPM_REQ_SUSPEND,
531*4882a593Smuzhiyun 	RPM_REQ_AUTOSUSPEND,
532*4882a593Smuzhiyun 	RPM_REQ_RESUME,
533*4882a593Smuzhiyun };
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun struct wakeup_source;
536*4882a593Smuzhiyun struct wake_irq;
537*4882a593Smuzhiyun struct pm_domain_data;
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun struct pm_subsys_data {
540*4882a593Smuzhiyun 	spinlock_t lock;
541*4882a593Smuzhiyun 	unsigned int refcount;
542*4882a593Smuzhiyun #ifdef CONFIG_PM_CLK
543*4882a593Smuzhiyun 	struct list_head clock_list;
544*4882a593Smuzhiyun #endif
545*4882a593Smuzhiyun #ifdef CONFIG_PM_GENERIC_DOMAINS
546*4882a593Smuzhiyun 	struct pm_domain_data *domain_data;
547*4882a593Smuzhiyun #endif
548*4882a593Smuzhiyun };
549*4882a593Smuzhiyun 
550*4882a593Smuzhiyun /*
551*4882a593Smuzhiyun  * Driver flags to control system suspend/resume behavior.
552*4882a593Smuzhiyun  *
553*4882a593Smuzhiyun  * These flags can be set by device drivers at the probe time.  They need not be
554*4882a593Smuzhiyun  * cleared by the drivers as the driver core will take care of that.
555*4882a593Smuzhiyun  *
556*4882a593Smuzhiyun  * NO_DIRECT_COMPLETE: Do not apply direct-complete optimization to the device.
557*4882a593Smuzhiyun  * SMART_PREPARE: Take the driver ->prepare callback return value into account.
558*4882a593Smuzhiyun  * SMART_SUSPEND: Avoid resuming the device from runtime suspend.
559*4882a593Smuzhiyun  * MAY_SKIP_RESUME: Allow driver "noirq" and "early" callbacks to be skipped.
560*4882a593Smuzhiyun  *
561*4882a593Smuzhiyun  * See Documentation/driver-api/pm/devices.rst for details.
562*4882a593Smuzhiyun  */
563*4882a593Smuzhiyun #define DPM_FLAG_NO_DIRECT_COMPLETE	BIT(0)
564*4882a593Smuzhiyun #define DPM_FLAG_SMART_PREPARE		BIT(1)
565*4882a593Smuzhiyun #define DPM_FLAG_SMART_SUSPEND		BIT(2)
566*4882a593Smuzhiyun #define DPM_FLAG_MAY_SKIP_RESUME	BIT(3)
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun struct dev_pm_info {
569*4882a593Smuzhiyun 	pm_message_t		power_state;
570*4882a593Smuzhiyun 	unsigned int		can_wakeup:1;
571*4882a593Smuzhiyun 	unsigned int		async_suspend:1;
572*4882a593Smuzhiyun 	bool			in_dpm_list:1;	/* Owned by the PM core */
573*4882a593Smuzhiyun 	bool			is_prepared:1;	/* Owned by the PM core */
574*4882a593Smuzhiyun 	bool			is_suspended:1;	/* Ditto */
575*4882a593Smuzhiyun 	bool			is_noirq_suspended:1;
576*4882a593Smuzhiyun 	bool			is_late_suspended:1;
577*4882a593Smuzhiyun 	bool			no_pm:1;
578*4882a593Smuzhiyun 	bool			early_init:1;	/* Owned by the PM core */
579*4882a593Smuzhiyun 	bool			direct_complete:1;	/* Owned by the PM core */
580*4882a593Smuzhiyun 	u32			driver_flags;
581*4882a593Smuzhiyun 	spinlock_t		lock;
582*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
583*4882a593Smuzhiyun 	struct list_head	entry;
584*4882a593Smuzhiyun 	struct completion	completion;
585*4882a593Smuzhiyun 	struct wakeup_source	*wakeup;
586*4882a593Smuzhiyun 	bool			wakeup_path:1;
587*4882a593Smuzhiyun 	bool			syscore:1;
588*4882a593Smuzhiyun 	bool			no_pm_callbacks:1;	/* Owned by the PM core */
589*4882a593Smuzhiyun 	unsigned int		must_resume:1;	/* Owned by the PM core */
590*4882a593Smuzhiyun 	unsigned int		may_skip_resume:1;	/* Set by subsystems */
591*4882a593Smuzhiyun #else
592*4882a593Smuzhiyun 	unsigned int		should_wakeup:1;
593*4882a593Smuzhiyun #endif
594*4882a593Smuzhiyun #ifdef CONFIG_PM
595*4882a593Smuzhiyun 	struct hrtimer		suspend_timer;
596*4882a593Smuzhiyun 	u64			timer_expires;
597*4882a593Smuzhiyun 	struct work_struct	work;
598*4882a593Smuzhiyun 	wait_queue_head_t	wait_queue;
599*4882a593Smuzhiyun 	struct wake_irq		*wakeirq;
600*4882a593Smuzhiyun 	atomic_t		usage_count;
601*4882a593Smuzhiyun 	atomic_t		child_count;
602*4882a593Smuzhiyun 	unsigned int		disable_depth:3;
603*4882a593Smuzhiyun 	unsigned int		idle_notification:1;
604*4882a593Smuzhiyun 	unsigned int		request_pending:1;
605*4882a593Smuzhiyun 	unsigned int		deferred_resume:1;
606*4882a593Smuzhiyun 	unsigned int		needs_force_resume:1;
607*4882a593Smuzhiyun 	unsigned int		runtime_auto:1;
608*4882a593Smuzhiyun 	bool			ignore_children:1;
609*4882a593Smuzhiyun 	unsigned int		no_callbacks:1;
610*4882a593Smuzhiyun 	unsigned int		irq_safe:1;
611*4882a593Smuzhiyun 	unsigned int		use_autosuspend:1;
612*4882a593Smuzhiyun 	unsigned int		timer_autosuspends:1;
613*4882a593Smuzhiyun 	unsigned int		memalloc_noio:1;
614*4882a593Smuzhiyun 	unsigned int		links_count;
615*4882a593Smuzhiyun 	enum rpm_request	request;
616*4882a593Smuzhiyun 	enum rpm_status		runtime_status;
617*4882a593Smuzhiyun 	int			runtime_error;
618*4882a593Smuzhiyun 	int			autosuspend_delay;
619*4882a593Smuzhiyun 	u64			last_busy;
620*4882a593Smuzhiyun 	u64			active_time;
621*4882a593Smuzhiyun 	u64			suspended_time;
622*4882a593Smuzhiyun 	u64			accounting_timestamp;
623*4882a593Smuzhiyun #endif
624*4882a593Smuzhiyun 	struct pm_subsys_data	*subsys_data;  /* Owned by the subsystem. */
625*4882a593Smuzhiyun 	void (*set_latency_tolerance)(struct device *, s32);
626*4882a593Smuzhiyun 	struct dev_pm_qos	*qos;
627*4882a593Smuzhiyun 
628*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
629*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
630*4882a593Smuzhiyun };
631*4882a593Smuzhiyun 
632*4882a593Smuzhiyun extern int dev_pm_get_subsys_data(struct device *dev);
633*4882a593Smuzhiyun extern void dev_pm_put_subsys_data(struct device *dev);
634*4882a593Smuzhiyun 
635*4882a593Smuzhiyun /**
636*4882a593Smuzhiyun  * struct dev_pm_domain - power management domain representation.
637*4882a593Smuzhiyun  *
638*4882a593Smuzhiyun  * @ops: Power management operations associated with this domain.
639*4882a593Smuzhiyun  * @start: Called when a user needs to start the device via the domain.
640*4882a593Smuzhiyun  * @detach: Called when removing a device from the domain.
641*4882a593Smuzhiyun  * @activate: Called before executing probe routines for bus types and drivers.
642*4882a593Smuzhiyun  * @sync: Called after successful driver probe.
643*4882a593Smuzhiyun  * @dismiss: Called after unsuccessful driver probe and after driver removal.
644*4882a593Smuzhiyun  *
645*4882a593Smuzhiyun  * Power domains provide callbacks that are executed during system suspend,
646*4882a593Smuzhiyun  * hibernation, system resume and during runtime PM transitions instead of
647*4882a593Smuzhiyun  * subsystem-level and driver-level callbacks.
648*4882a593Smuzhiyun  */
649*4882a593Smuzhiyun struct dev_pm_domain {
650*4882a593Smuzhiyun 	struct dev_pm_ops	ops;
651*4882a593Smuzhiyun 	int (*start)(struct device *dev);
652*4882a593Smuzhiyun 	void (*detach)(struct device *dev, bool power_off);
653*4882a593Smuzhiyun 	int (*activate)(struct device *dev);
654*4882a593Smuzhiyun 	void (*sync)(struct device *dev);
655*4882a593Smuzhiyun 	void (*dismiss)(struct device *dev);
656*4882a593Smuzhiyun 
657*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
658*4882a593Smuzhiyun };
659*4882a593Smuzhiyun 
660*4882a593Smuzhiyun /*
661*4882a593Smuzhiyun  * The PM_EVENT_ messages are also used by drivers implementing the legacy
662*4882a593Smuzhiyun  * suspend framework, based on the ->suspend() and ->resume() callbacks common
663*4882a593Smuzhiyun  * for suspend and hibernation transitions, according to the rules below.
664*4882a593Smuzhiyun  */
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun /* Necessary, because several drivers use PM_EVENT_PRETHAW */
667*4882a593Smuzhiyun #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
668*4882a593Smuzhiyun 
669*4882a593Smuzhiyun /*
670*4882a593Smuzhiyun  * One transition is triggered by resume(), after a suspend() call; the
671*4882a593Smuzhiyun  * message is implicit:
672*4882a593Smuzhiyun  *
673*4882a593Smuzhiyun  * ON		Driver starts working again, responding to hardware events
674*4882a593Smuzhiyun  *		and software requests.  The hardware may have gone through
675*4882a593Smuzhiyun  *		a power-off reset, or it may have maintained state from the
676*4882a593Smuzhiyun  *		previous suspend() which the driver will rely on while
677*4882a593Smuzhiyun  *		resuming.  On most platforms, there are no restrictions on
678*4882a593Smuzhiyun  *		availability of resources like clocks during resume().
679*4882a593Smuzhiyun  *
680*4882a593Smuzhiyun  * Other transitions are triggered by messages sent using suspend().  All
681*4882a593Smuzhiyun  * these transitions quiesce the driver, so that I/O queues are inactive.
682*4882a593Smuzhiyun  * That commonly entails turning off IRQs and DMA; there may be rules
683*4882a593Smuzhiyun  * about how to quiesce that are specific to the bus or the device's type.
684*4882a593Smuzhiyun  * (For example, network drivers mark the link state.)  Other details may
685*4882a593Smuzhiyun  * differ according to the message:
686*4882a593Smuzhiyun  *
687*4882a593Smuzhiyun  * SUSPEND	Quiesce, enter a low power device state appropriate for
688*4882a593Smuzhiyun  *		the upcoming system state (such as PCI_D3hot), and enable
689*4882a593Smuzhiyun  *		wakeup events as appropriate.
690*4882a593Smuzhiyun  *
691*4882a593Smuzhiyun  * HIBERNATE	Enter a low power device state appropriate for the hibernation
692*4882a593Smuzhiyun  *		state (eg. ACPI S4) and enable wakeup events as appropriate.
693*4882a593Smuzhiyun  *
694*4882a593Smuzhiyun  * FREEZE	Quiesce operations so that a consistent image can be saved;
695*4882a593Smuzhiyun  *		but do NOT otherwise enter a low power device state, and do
696*4882a593Smuzhiyun  *		NOT emit system wakeup events.
697*4882a593Smuzhiyun  *
698*4882a593Smuzhiyun  * PRETHAW	Quiesce as if for FREEZE; additionally, prepare for restoring
699*4882a593Smuzhiyun  *		the system from a snapshot taken after an earlier FREEZE.
700*4882a593Smuzhiyun  *		Some drivers will need to reset their hardware state instead
701*4882a593Smuzhiyun  *		of preserving it, to ensure that it's never mistaken for the
702*4882a593Smuzhiyun  *		state which that earlier snapshot had set up.
703*4882a593Smuzhiyun  *
704*4882a593Smuzhiyun  * A minimally power-aware driver treats all messages as SUSPEND, fully
705*4882a593Smuzhiyun  * reinitializes its device during resume() -- whether or not it was reset
706*4882a593Smuzhiyun  * during the suspend/resume cycle -- and can't issue wakeup events.
707*4882a593Smuzhiyun  *
708*4882a593Smuzhiyun  * More power-aware drivers may also use low power states at runtime as
709*4882a593Smuzhiyun  * well as during system sleep states like PM_SUSPEND_STANDBY.  They may
710*4882a593Smuzhiyun  * be able to use wakeup events to exit from runtime low-power states,
711*4882a593Smuzhiyun  * or from system low-power states such as standby or suspend-to-RAM.
712*4882a593Smuzhiyun  */
713*4882a593Smuzhiyun 
714*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
715*4882a593Smuzhiyun extern void device_pm_lock(void);
716*4882a593Smuzhiyun extern void dpm_resume_start(pm_message_t state);
717*4882a593Smuzhiyun extern void dpm_resume_end(pm_message_t state);
718*4882a593Smuzhiyun extern void dpm_resume_noirq(pm_message_t state);
719*4882a593Smuzhiyun extern void dpm_resume_early(pm_message_t state);
720*4882a593Smuzhiyun extern void dpm_resume(pm_message_t state);
721*4882a593Smuzhiyun extern void dpm_complete(pm_message_t state);
722*4882a593Smuzhiyun 
723*4882a593Smuzhiyun extern void device_pm_unlock(void);
724*4882a593Smuzhiyun extern int dpm_suspend_end(pm_message_t state);
725*4882a593Smuzhiyun extern int dpm_suspend_start(pm_message_t state);
726*4882a593Smuzhiyun extern int dpm_suspend_noirq(pm_message_t state);
727*4882a593Smuzhiyun extern int dpm_suspend_late(pm_message_t state);
728*4882a593Smuzhiyun extern int dpm_suspend(pm_message_t state);
729*4882a593Smuzhiyun extern int dpm_prepare(pm_message_t state);
730*4882a593Smuzhiyun 
731*4882a593Smuzhiyun extern void __suspend_report_result(const char *function, void *fn, int ret);
732*4882a593Smuzhiyun 
733*4882a593Smuzhiyun #define suspend_report_result(fn, ret)					\
734*4882a593Smuzhiyun 	do {								\
735*4882a593Smuzhiyun 		__suspend_report_result(__func__, fn, ret);		\
736*4882a593Smuzhiyun 	} while (0)
737*4882a593Smuzhiyun 
738*4882a593Smuzhiyun extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
739*4882a593Smuzhiyun extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *));
740*4882a593Smuzhiyun 
741*4882a593Smuzhiyun extern int pm_generic_prepare(struct device *dev);
742*4882a593Smuzhiyun extern int pm_generic_suspend_late(struct device *dev);
743*4882a593Smuzhiyun extern int pm_generic_suspend_noirq(struct device *dev);
744*4882a593Smuzhiyun extern int pm_generic_suspend(struct device *dev);
745*4882a593Smuzhiyun extern int pm_generic_resume_early(struct device *dev);
746*4882a593Smuzhiyun extern int pm_generic_resume_noirq(struct device *dev);
747*4882a593Smuzhiyun extern int pm_generic_resume(struct device *dev);
748*4882a593Smuzhiyun extern int pm_generic_freeze_noirq(struct device *dev);
749*4882a593Smuzhiyun extern int pm_generic_freeze_late(struct device *dev);
750*4882a593Smuzhiyun extern int pm_generic_freeze(struct device *dev);
751*4882a593Smuzhiyun extern int pm_generic_thaw_noirq(struct device *dev);
752*4882a593Smuzhiyun extern int pm_generic_thaw_early(struct device *dev);
753*4882a593Smuzhiyun extern int pm_generic_thaw(struct device *dev);
754*4882a593Smuzhiyun extern int pm_generic_restore_noirq(struct device *dev);
755*4882a593Smuzhiyun extern int pm_generic_restore_early(struct device *dev);
756*4882a593Smuzhiyun extern int pm_generic_restore(struct device *dev);
757*4882a593Smuzhiyun extern int pm_generic_poweroff_noirq(struct device *dev);
758*4882a593Smuzhiyun extern int pm_generic_poweroff_late(struct device *dev);
759*4882a593Smuzhiyun extern int pm_generic_poweroff(struct device *dev);
760*4882a593Smuzhiyun extern void pm_generic_complete(struct device *dev);
761*4882a593Smuzhiyun 
762*4882a593Smuzhiyun extern bool dev_pm_skip_resume(struct device *dev);
763*4882a593Smuzhiyun extern bool dev_pm_skip_suspend(struct device *dev);
764*4882a593Smuzhiyun 
765*4882a593Smuzhiyun #else /* !CONFIG_PM_SLEEP */
766*4882a593Smuzhiyun 
767*4882a593Smuzhiyun #define device_pm_lock() do {} while (0)
768*4882a593Smuzhiyun #define device_pm_unlock() do {} while (0)
769*4882a593Smuzhiyun 
dpm_suspend_start(pm_message_t state)770*4882a593Smuzhiyun static inline int dpm_suspend_start(pm_message_t state)
771*4882a593Smuzhiyun {
772*4882a593Smuzhiyun 	return 0;
773*4882a593Smuzhiyun }
774*4882a593Smuzhiyun 
775*4882a593Smuzhiyun #define suspend_report_result(fn, ret)		do {} while (0)
776*4882a593Smuzhiyun 
device_pm_wait_for_dev(struct device * a,struct device * b)777*4882a593Smuzhiyun static inline int device_pm_wait_for_dev(struct device *a, struct device *b)
778*4882a593Smuzhiyun {
779*4882a593Smuzhiyun 	return 0;
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun 
dpm_for_each_dev(void * data,void (* fn)(struct device *,void *))782*4882a593Smuzhiyun static inline void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *))
783*4882a593Smuzhiyun {
784*4882a593Smuzhiyun }
785*4882a593Smuzhiyun 
786*4882a593Smuzhiyun #define pm_generic_prepare		NULL
787*4882a593Smuzhiyun #define pm_generic_suspend_late		NULL
788*4882a593Smuzhiyun #define pm_generic_suspend_noirq	NULL
789*4882a593Smuzhiyun #define pm_generic_suspend		NULL
790*4882a593Smuzhiyun #define pm_generic_resume_early		NULL
791*4882a593Smuzhiyun #define pm_generic_resume_noirq		NULL
792*4882a593Smuzhiyun #define pm_generic_resume		NULL
793*4882a593Smuzhiyun #define pm_generic_freeze_noirq		NULL
794*4882a593Smuzhiyun #define pm_generic_freeze_late		NULL
795*4882a593Smuzhiyun #define pm_generic_freeze		NULL
796*4882a593Smuzhiyun #define pm_generic_thaw_noirq		NULL
797*4882a593Smuzhiyun #define pm_generic_thaw_early		NULL
798*4882a593Smuzhiyun #define pm_generic_thaw			NULL
799*4882a593Smuzhiyun #define pm_generic_restore_noirq	NULL
800*4882a593Smuzhiyun #define pm_generic_restore_early	NULL
801*4882a593Smuzhiyun #define pm_generic_restore		NULL
802*4882a593Smuzhiyun #define pm_generic_poweroff_noirq	NULL
803*4882a593Smuzhiyun #define pm_generic_poweroff_late	NULL
804*4882a593Smuzhiyun #define pm_generic_poweroff		NULL
805*4882a593Smuzhiyun #define pm_generic_complete		NULL
806*4882a593Smuzhiyun #endif /* !CONFIG_PM_SLEEP */
807*4882a593Smuzhiyun 
808*4882a593Smuzhiyun /* How to reorder dpm_list after device_move() */
809*4882a593Smuzhiyun enum dpm_order {
810*4882a593Smuzhiyun 	DPM_ORDER_NONE,
811*4882a593Smuzhiyun 	DPM_ORDER_DEV_AFTER_PARENT,
812*4882a593Smuzhiyun 	DPM_ORDER_PARENT_BEFORE_DEV,
813*4882a593Smuzhiyun 	DPM_ORDER_DEV_LAST,
814*4882a593Smuzhiyun };
815*4882a593Smuzhiyun 
816*4882a593Smuzhiyun #endif /* _LINUX_PM_H */
817