pm.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * pm.h - Power management interface
  3. *
  4. * Copyright (C) 2000 Andrew Henroid
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef _LINUX_PM_H
  21. #define _LINUX_PM_H
  22. #include <linux/list.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/wait.h>
  26. #include <linux/timer.h>
  27. #include <linux/completion.h>
  28. /*
  29. * Callbacks for platform drivers to implement.
  30. */
  31. extern void (*pm_idle)(void);
  32. extern void (*pm_power_off)(void);
  33. extern void (*pm_power_off_prepare)(void);
  34. /*
  35. * Device power management
  36. */
  37. struct device;
  38. #ifdef CONFIG_PM
  39. extern const char power_group_name[]; /* = "power" */
  40. #else
  41. #define power_group_name NULL
  42. #endif
  43. typedef struct pm_message {
  44. int event;
  45. } pm_message_t;
  46. /**
  47. * struct dev_pm_ops - device PM callbacks
  48. *
  49. * Several driver power state transitions are externally visible, affecting
  50. * the state of pending I/O queues and (for drivers that touch hardware)
  51. * interrupts, wakeups, DMA, and other hardware state. There may also be
  52. * internal transitions to various low power modes, which are transparent
  53. * to the rest of the driver stack (such as a driver that's ON gating off
  54. * clocks which are not in active use).
  55. *
  56. * The externally visible transitions are handled with the help of the following
  57. * callbacks included in this structure:
  58. *
  59. * @prepare: Prepare the device for the upcoming transition, but do NOT change
  60. * its hardware state. Prevent new children of the device from being
  61. * registered after @prepare() returns (the driver's subsystem and
  62. * generally the rest of the kernel is supposed to prevent new calls to the
  63. * probe method from being made too once @prepare() has succeeded). If
  64. * @prepare() detects a situation it cannot handle (e.g. registration of a
  65. * child already in progress), it may return -EAGAIN, so that the PM core
  66. * can execute it once again (e.g. after the new child has been registered)
  67. * to recover from the race condition. This method is executed for all
  68. * kinds of suspend transitions and is followed by one of the suspend
  69. * callbacks: @suspend(), @freeze(), or @poweroff().
  70. * The PM core executes @prepare() for all devices before starting to
  71. * execute suspend callbacks for any of them, so drivers may assume all of
  72. * the other devices to be present and functional while @prepare() is being
  73. * executed. In particular, it is safe to make GFP_KERNEL memory
  74. * allocations from within @prepare(). However, drivers may NOT assume
  75. * anything about the availability of the user space at that time and it
  76. * is not correct to request firmware from within @prepare() (it's too
  77. * late to do that). [To work around this limitation, drivers may
  78. * register suspend and hibernation notifiers that are executed before the
  79. * freezing of tasks.]
  80. *
  81. * @complete: Undo the changes made by @prepare(). This method is executed for
  82. * all kinds of resume transitions, following one of the resume callbacks:
  83. * @resume(), @thaw(), @restore(). Also called if the state transition
  84. * fails before the driver's suspend callback (@suspend(), @freeze(),
  85. * @poweroff()) can be executed (e.g. if the suspend callback fails for one
  86. * of the other devices that the PM core has unsuccessfully attempted to
  87. * suspend earlier).
  88. * The PM core executes @complete() after it has executed the appropriate
  89. * resume callback for all devices.
  90. *
  91. * @suspend: Executed before putting the system into a sleep state in which the
  92. * contents of main memory are preserved. Quiesce the device, put it into
  93. * a low power state appropriate for the upcoming system state (such as
  94. * PCI_D3hot), and enable wakeup events as appropriate.
  95. *
  96. * @resume: Executed after waking the system up from a sleep state in which the
  97. * contents of main memory were preserved. Put the device into the
  98. * appropriate state, according to the information saved in memory by the
  99. * preceding @suspend(). The driver starts working again, responding to
  100. * hardware events and software requests. The hardware may have gone
  101. * through a power-off reset, or it may have maintained state from the
  102. * previous suspend() which the driver may rely on while resuming. On most
  103. * platforms, there are no restrictions on availability of resources like
  104. * clocks during @resume().
  105. *
  106. * @freeze: Hibernation-specific, executed before creating a hibernation image.
  107. * Quiesce operations so that a consistent image can be created, but do NOT
  108. * otherwise put the device into a low power device state and do NOT emit
  109. * system wakeup events. Save in main memory the device settings to be
  110. * used by @restore() during the subsequent resume from hibernation or by
  111. * the subsequent @thaw(), if the creation of the image or the restoration
  112. * of main memory contents from it fails.
  113. *
  114. * @thaw: Hibernation-specific, executed after creating a hibernation image OR
  115. * if the creation of the image fails. Also executed after a failing
  116. * attempt to restore the contents of main memory from such an image.
  117. * Undo the changes made by the preceding @freeze(), so the device can be
  118. * operated in the same way as immediately before the call to @freeze().
  119. *
  120. * @poweroff: Hibernation-specific, executed after saving a hibernation image.
  121. * Quiesce the device, put it into a low power state appropriate for the
  122. * upcoming system state (such as PCI_D3hot), and enable wakeup events as
  123. * appropriate.
  124. *
  125. * @restore: Hibernation-specific, executed after restoring the contents of main
  126. * memory from a hibernation image. Driver starts working again,
  127. * responding to hardware events and software requests. Drivers may NOT
  128. * make ANY assumptions about the hardware state right prior to @restore().
  129. * On most platforms, there are no restrictions on availability of
  130. * resources like clocks during @restore().
  131. *
  132. * @suspend_noirq: Complete the operations of ->suspend() by carrying out any
  133. * actions required for suspending the device that need interrupts to be
  134. * disabled
  135. *
  136. * @resume_noirq: Prepare for the execution of ->resume() by carrying out any
  137. * actions required for resuming the device that need interrupts to be
  138. * disabled
  139. *
  140. * @freeze_noirq: Complete the operations of ->freeze() by carrying out any
  141. * actions required for freezing the device that need interrupts to be
  142. * disabled
  143. *
  144. * @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any
  145. * actions required for thawing the device that need interrupts to be
  146. * disabled
  147. *
  148. * @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any
  149. * actions required for handling the device that need interrupts to be
  150. * disabled
  151. *
  152. * @restore_noirq: Prepare for the execution of ->restore() by carrying out any
  153. * actions required for restoring the operations of the device that need
  154. * interrupts to be disabled
  155. *
  156. * All of the above callbacks, except for @complete(), return error codes.
  157. * However, the error codes returned by the resume operations, @resume(),
  158. * @thaw(), @restore(), @resume_noirq(), @thaw_noirq(), and @restore_noirq() do
  159. * not cause the PM core to abort the resume transition during which they are
  160. * returned. The error codes returned in that cases are only printed by the PM
  161. * core to the system logs for debugging purposes. Still, it is recommended
  162. * that drivers only return error codes from their resume methods in case of an
  163. * unrecoverable failure (i.e. when the device being handled refuses to resume
  164. * and becomes unusable) to allow us to modify the PM core in the future, so
  165. * that it can avoid attempting to handle devices that failed to resume and
  166. * their children.
  167. *
  168. * It is allowed to unregister devices while the above callbacks are being
  169. * executed. However, it is not allowed to unregister a device from within any
  170. * of its own callbacks.
  171. *
  172. * There also are the following callbacks related to run-time power management
  173. * of devices:
  174. *
  175. * @runtime_suspend: Prepare the device for a condition in which it won't be
  176. * able to communicate with the CPU(s) and RAM due to power management.
  177. * This need not mean that the device should be put into a low power state.
  178. * For example, if the device is behind a link which is about to be turned
  179. * off, the device may remain at full power. If the device does go to low
  180. * power and is capable of generating run-time wake-up events, remote
  181. * wake-up (i.e., a hardware mechanism allowing the device to request a
  182. * change of its power state via a wake-up event, such as PCI PME) should
  183. * be enabled for it.
  184. *
  185. * @runtime_resume: Put the device into the fully active state in response to a
  186. * wake-up event generated by hardware or at the request of software. If
  187. * necessary, put the device into the full power state and restore its
  188. * registers, so that it is fully operational.
  189. *
  190. * @runtime_idle: Device appears to be inactive and it might be put into a low
  191. * power state if all of the necessary conditions are satisfied. Check
  192. * these conditions and handle the device as appropriate, possibly queueing
  193. * a suspend request for it. The return value is ignored by the PM core.
  194. */
  195. struct dev_pm_ops {
  196. int (*prepare)(struct device *dev);
  197. void (*complete)(struct device *dev);
  198. int (*suspend)(struct device *dev);
  199. int (*resume)(struct device *dev);
  200. int (*freeze)(struct device *dev);
  201. int (*thaw)(struct device *dev);
  202. int (*poweroff)(struct device *dev);
  203. int (*restore)(struct device *dev);
  204. int (*suspend_noirq)(struct device *dev);
  205. int (*resume_noirq)(struct device *dev);
  206. int (*freeze_noirq)(struct device *dev);
  207. int (*thaw_noirq)(struct device *dev);
  208. int (*poweroff_noirq)(struct device *dev);
  209. int (*restore_noirq)(struct device *dev);
  210. int (*runtime_suspend)(struct device *dev);
  211. int (*runtime_resume)(struct device *dev);
  212. int (*runtime_idle)(struct device *dev);
  213. };
  214. #ifdef CONFIG_PM_SLEEP
  215. #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  216. .suspend = suspend_fn, \
  217. .resume = resume_fn, \
  218. .freeze = suspend_fn, \
  219. .thaw = resume_fn, \
  220. .poweroff = suspend_fn, \
  221. .restore = resume_fn,
  222. #else
  223. #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
  224. #endif
  225. #ifdef CONFIG_PM_RUNTIME
  226. #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
  227. .runtime_suspend = suspend_fn, \
  228. .runtime_resume = resume_fn, \
  229. .runtime_idle = idle_fn,
  230. #else
  231. #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
  232. #endif
  233. /*
  234. * Use this if you want to use the same suspend and resume callbacks for suspend
  235. * to RAM and hibernation.
  236. */
  237. #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
  238. const struct dev_pm_ops name = { \
  239. SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  240. }
  241. /*
  242. * Use this for defining a set of PM operations to be used in all situations
  243. * (sustem suspend, hibernation or runtime PM).
  244. */
  245. #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
  246. const struct dev_pm_ops name = { \
  247. SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
  248. SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
  249. }
  250. /*
  251. * Use this for subsystems (bus types, device types, device classes) that don't
  252. * need any special suspend/resume handling in addition to invoking the PM
  253. * callbacks provided by device drivers supporting both the system sleep PM and
  254. * runtime PM, make the pm member point to generic_subsys_pm_ops.
  255. */
  256. #ifdef CONFIG_PM
  257. extern struct dev_pm_ops generic_subsys_pm_ops;
  258. #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
  259. #else
  260. #define GENERIC_SUBSYS_PM_OPS NULL
  261. #endif
  262. /**
  263. * PM_EVENT_ messages
  264. *
  265. * The following PM_EVENT_ messages are defined for the internal use of the PM
  266. * core, in order to provide a mechanism allowing the high level suspend and
  267. * hibernation code to convey the necessary information to the device PM core
  268. * code:
  269. *
  270. * ON No transition.
  271. *
  272. * FREEZE System is going to hibernate, call ->prepare() and ->freeze()
  273. * for all devices.
  274. *
  275. * SUSPEND System is going to suspend, call ->prepare() and ->suspend()
  276. * for all devices.
  277. *
  278. * HIBERNATE Hibernation image has been saved, call ->prepare() and
  279. * ->poweroff() for all devices.
  280. *
  281. * QUIESCE Contents of main memory are going to be restored from a (loaded)
  282. * hibernation image, call ->prepare() and ->freeze() for all
  283. * devices.
  284. *
  285. * RESUME System is resuming, call ->resume() and ->complete() for all
  286. * devices.
  287. *
  288. * THAW Hibernation image has been created, call ->thaw() and
  289. * ->complete() for all devices.
  290. *
  291. * RESTORE Contents of main memory have been restored from a hibernation
  292. * image, call ->restore() and ->complete() for all devices.
  293. *
  294. * RECOVER Creation of a hibernation image or restoration of the main
  295. * memory contents from a hibernation image has failed, call
  296. * ->thaw() and ->complete() for all devices.
  297. *
  298. * The following PM_EVENT_ messages are defined for internal use by
  299. * kernel subsystems. They are never issued by the PM core.
  300. *
  301. * USER_SUSPEND Manual selective suspend was issued by userspace.
  302. *
  303. * USER_RESUME Manual selective resume was issued by userspace.
  304. *
  305. * REMOTE_WAKEUP Remote-wakeup request was received from the device.
  306. *
  307. * AUTO_SUSPEND Automatic (device idle) runtime suspend was
  308. * initiated by the subsystem.
  309. *
  310. * AUTO_RESUME Automatic (device needed) runtime resume was
  311. * requested by a driver.
  312. */
  313. #define PM_EVENT_ON 0x0000
  314. #define PM_EVENT_FREEZE 0x0001
  315. #define PM_EVENT_SUSPEND 0x0002
  316. #define PM_EVENT_HIBERNATE 0x0004
  317. #define PM_EVENT_QUIESCE 0x0008
  318. #define PM_EVENT_RESUME 0x0010
  319. #define PM_EVENT_THAW 0x0020
  320. #define PM_EVENT_RESTORE 0x0040
  321. #define PM_EVENT_RECOVER 0x0080
  322. #define PM_EVENT_USER 0x0100
  323. #define PM_EVENT_REMOTE 0x0200
  324. #define PM_EVENT_AUTO 0x0400
  325. #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
  326. #define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
  327. #define PM_EVENT_USER_RESUME (PM_EVENT_USER | PM_EVENT_RESUME)
  328. #define PM_EVENT_REMOTE_RESUME (PM_EVENT_REMOTE | PM_EVENT_RESUME)
  329. #define PM_EVENT_AUTO_SUSPEND (PM_EVENT_AUTO | PM_EVENT_SUSPEND)
  330. #define PM_EVENT_AUTO_RESUME (PM_EVENT_AUTO | PM_EVENT_RESUME)
  331. #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
  332. #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
  333. #define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
  334. #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
  335. #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
  336. #define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, })
  337. #define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, })
  338. #define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, })
  339. #define PMSG_RECOVER ((struct pm_message){ .event = PM_EVENT_RECOVER, })
  340. #define PMSG_USER_SUSPEND ((struct pm_message) \
  341. { .event = PM_EVENT_USER_SUSPEND, })
  342. #define PMSG_USER_RESUME ((struct pm_message) \
  343. { .event = PM_EVENT_USER_RESUME, })
  344. #define PMSG_REMOTE_RESUME ((struct pm_message) \
  345. { .event = PM_EVENT_REMOTE_RESUME, })
  346. #define PMSG_AUTO_SUSPEND ((struct pm_message) \
  347. { .event = PM_EVENT_AUTO_SUSPEND, })
  348. #define PMSG_AUTO_RESUME ((struct pm_message) \
  349. { .event = PM_EVENT_AUTO_RESUME, })
  350. /**
  351. * Device run-time power management status.
  352. *
  353. * These status labels are used internally by the PM core to indicate the
  354. * current status of a device with respect to the PM core operations. They do
  355. * not reflect the actual power state of the device or its status as seen by the
  356. * driver.
  357. *
  358. * RPM_ACTIVE Device is fully operational. Indicates that the device
  359. * bus type's ->runtime_resume() callback has completed
  360. * successfully.
  361. *
  362. * RPM_SUSPENDED Device bus type's ->runtime_suspend() callback has
  363. * completed successfully. The device is regarded as
  364. * suspended.
  365. *
  366. * RPM_RESUMING Device bus type's ->runtime_resume() callback is being
  367. * executed.
  368. *
  369. * RPM_SUSPENDING Device bus type's ->runtime_suspend() callback is being
  370. * executed.
  371. */
  372. enum rpm_status {
  373. RPM_ACTIVE = 0,
  374. RPM_RESUMING,
  375. RPM_SUSPENDED,
  376. RPM_SUSPENDING,
  377. };
  378. /**
  379. * Device run-time power management request types.
  380. *
  381. * RPM_REQ_NONE Do nothing.
  382. *
  383. * RPM_REQ_IDLE Run the device bus type's ->runtime_idle() callback
  384. *
  385. * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback
  386. *
  387. * RPM_REQ_AUTOSUSPEND Same as RPM_REQ_SUSPEND, but not until the device has
  388. * been inactive for as long as power.autosuspend_delay
  389. *
  390. * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback
  391. */
  392. enum rpm_request {
  393. RPM_REQ_NONE = 0,
  394. RPM_REQ_IDLE,
  395. RPM_REQ_SUSPEND,
  396. RPM_REQ_AUTOSUSPEND,
  397. RPM_REQ_RESUME,
  398. };
  399. struct wakeup_source;
  400. struct dev_pm_info {
  401. pm_message_t power_state;
  402. unsigned int can_wakeup:1;
  403. unsigned int async_suspend:1;
  404. unsigned int in_suspend:1; /* Owned by the PM core */
  405. spinlock_t lock;
  406. #ifdef CONFIG_PM_SLEEP
  407. struct list_head entry;
  408. struct completion completion;
  409. struct wakeup_source *wakeup;
  410. #else
  411. unsigned int should_wakeup:1;
  412. #endif
  413. #ifdef CONFIG_PM_RUNTIME
  414. struct timer_list suspend_timer;
  415. unsigned long timer_expires;
  416. struct work_struct work;
  417. wait_queue_head_t wait_queue;
  418. atomic_t usage_count;
  419. atomic_t child_count;
  420. unsigned int disable_depth:3;
  421. unsigned int ignore_children:1;
  422. unsigned int idle_notification:1;
  423. unsigned int request_pending:1;
  424. unsigned int deferred_resume:1;
  425. unsigned int run_wake:1;
  426. unsigned int runtime_auto:1;
  427. unsigned int no_callbacks:1;
  428. unsigned int irq_safe:1;
  429. unsigned int use_autosuspend:1;
  430. unsigned int timer_autosuspends:1;
  431. enum rpm_request request;
  432. enum rpm_status runtime_status;
  433. int runtime_error;
  434. int autosuspend_delay;
  435. unsigned long last_busy;
  436. unsigned long active_jiffies;
  437. unsigned long suspended_jiffies;
  438. unsigned long accounting_timestamp;
  439. void *subsys_data; /* Owned by the subsystem. */
  440. #endif
  441. };
  442. extern void update_pm_runtime_accounting(struct device *dev);
  443. /*
  444. * Power domains provide callbacks that are executed during system suspend,
  445. * hibernation, system resume and during runtime PM transitions along with
  446. * subsystem-level and driver-level callbacks.
  447. */
  448. struct dev_power_domain {
  449. struct dev_pm_ops ops;
  450. };
  451. /*
  452. * The PM_EVENT_ messages are also used by drivers implementing the legacy
  453. * suspend framework, based on the ->suspend() and ->resume() callbacks common
  454. * for suspend and hibernation transitions, according to the rules below.
  455. */
  456. /* Necessary, because several drivers use PM_EVENT_PRETHAW */
  457. #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
  458. /*
  459. * One transition is triggered by resume(), after a suspend() call; the
  460. * message is implicit:
  461. *
  462. * ON Driver starts working again, responding to hardware events
  463. * and software requests. The hardware may have gone through
  464. * a power-off reset, or it may have maintained state from the
  465. * previous suspend() which the driver will rely on while
  466. * resuming. On most platforms, there are no restrictions on
  467. * availability of resources like clocks during resume().
  468. *
  469. * Other transitions are triggered by messages sent using suspend(). All
  470. * these transitions quiesce the driver, so that I/O queues are inactive.
  471. * That commonly entails turning off IRQs and DMA; there may be rules
  472. * about how to quiesce that are specific to the bus or the device's type.
  473. * (For example, network drivers mark the link state.) Other details may
  474. * differ according to the message:
  475. *
  476. * SUSPEND Quiesce, enter a low power device state appropriate for
  477. * the upcoming system state (such as PCI_D3hot), and enable
  478. * wakeup events as appropriate.
  479. *
  480. * HIBERNATE Enter a low power device state appropriate for the hibernation
  481. * state (eg. ACPI S4) and enable wakeup events as appropriate.
  482. *
  483. * FREEZE Quiesce operations so that a consistent image can be saved;
  484. * but do NOT otherwise enter a low power device state, and do
  485. * NOT emit system wakeup events.
  486. *
  487. * PRETHAW Quiesce as if for FREEZE; additionally, prepare for restoring
  488. * the system from a snapshot taken after an earlier FREEZE.
  489. * Some drivers will need to reset their hardware state instead
  490. * of preserving it, to ensure that it's never mistaken for the
  491. * state which that earlier snapshot had set up.
  492. *
  493. * A minimally power-aware driver treats all messages as SUSPEND, fully
  494. * reinitializes its device during resume() -- whether or not it was reset
  495. * during the suspend/resume cycle -- and can't issue wakeup events.
  496. *
  497. * More power-aware drivers may also use low power states at runtime as
  498. * well as during system sleep states like PM_SUSPEND_STANDBY. They may
  499. * be able to use wakeup events to exit from runtime low-power states,
  500. * or from system low-power states such as standby or suspend-to-RAM.
  501. */
  502. #ifdef CONFIG_PM_SLEEP
  503. extern void device_pm_lock(void);
  504. extern void dpm_resume_noirq(pm_message_t state);
  505. extern void dpm_resume_end(pm_message_t state);
  506. extern void dpm_resume(pm_message_t state);
  507. extern void dpm_complete(pm_message_t state);
  508. extern void device_pm_unlock(void);
  509. extern int dpm_suspend_noirq(pm_message_t state);
  510. extern int dpm_suspend_start(pm_message_t state);
  511. extern int dpm_suspend(pm_message_t state);
  512. extern int dpm_prepare(pm_message_t state);
  513. extern void __suspend_report_result(const char *function, void *fn, int ret);
  514. #define suspend_report_result(fn, ret) \
  515. do { \
  516. __suspend_report_result(__func__, fn, ret); \
  517. } while (0)
  518. extern int device_pm_wait_for_dev(struct device *sub, struct device *dev);
  519. #else /* !CONFIG_PM_SLEEP */
  520. #define device_pm_lock() do {} while (0)
  521. #define device_pm_unlock() do {} while (0)
  522. static inline int dpm_suspend_start(pm_message_t state)
  523. {
  524. return 0;
  525. }
  526. #define suspend_report_result(fn, ret) do {} while (0)
  527. static inline int device_pm_wait_for_dev(struct device *a, struct device *b)
  528. {
  529. return 0;
  530. }
  531. #endif /* !CONFIG_PM_SLEEP */
  532. /* How to reorder dpm_list after device_move() */
  533. enum dpm_order {
  534. DPM_ORDER_NONE,
  535. DPM_ORDER_DEV_AFTER_PARENT,
  536. DPM_ORDER_PARENT_BEFORE_DEV,
  537. DPM_ORDER_DEV_LAST,
  538. };
  539. extern int pm_generic_suspend(struct device *dev);
  540. extern int pm_generic_resume(struct device *dev);
  541. extern int pm_generic_freeze(struct device *dev);
  542. extern int pm_generic_thaw(struct device *dev);
  543. extern int pm_generic_restore(struct device *dev);
  544. extern int pm_generic_poweroff(struct device *dev);
  545. #endif /* _LINUX_PM_H */