GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / include / linux / pm.h
blobf51d72510a518f8ecf5ff2d14d59c14c0066c601
1 /*
2 * pm.h - Power management interface
4 * Copyright (C) 2000 Andrew Henroid
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.
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.
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
21 #ifndef _LINUX_PM_H
22 #define _LINUX_PM_H
24 #include <linux/list.h>
25 #include <linux/workqueue.h>
26 #include <linux/spinlock.h>
27 #include <linux/wait.h>
28 #include <linux/timer.h>
29 #include <linux/completion.h>
32 * Callbacks for platform drivers to implement.
34 extern void (*pm_idle)(void);
35 extern void (*pm_power_off)(void);
36 extern void (*pm_power_off_prepare)(void);
39 * Device power management
42 struct device;
44 typedef struct pm_message {
45 int event;
46 } pm_message_t;
49 struct dev_pm_ops {
50 int (*prepare)(struct device *dev);
51 void (*complete)(struct device *dev);
52 int (*suspend)(struct device *dev);
53 int (*resume)(struct device *dev);
54 int (*freeze)(struct device *dev);
55 int (*thaw)(struct device *dev);
56 int (*poweroff)(struct device *dev);
57 int (*restore)(struct device *dev);
58 int (*suspend_noirq)(struct device *dev);
59 int (*resume_noirq)(struct device *dev);
60 int (*freeze_noirq)(struct device *dev);
61 int (*thaw_noirq)(struct device *dev);
62 int (*poweroff_noirq)(struct device *dev);
63 int (*restore_noirq)(struct device *dev);
64 int (*runtime_suspend)(struct device *dev);
65 int (*runtime_resume)(struct device *dev);
66 int (*runtime_idle)(struct device *dev);
69 #ifdef CONFIG_PM_SLEEP
70 #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
71 .suspend = suspend_fn, \
72 .resume = resume_fn, \
73 .freeze = suspend_fn, \
74 .thaw = resume_fn, \
75 .poweroff = suspend_fn, \
76 .restore = resume_fn,
77 #else
78 #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
79 #endif
81 #ifdef CONFIG_PM_RUNTIME
82 #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
83 .runtime_suspend = suspend_fn, \
84 .runtime_resume = resume_fn, \
85 .runtime_idle = idle_fn,
86 #else
87 #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
88 #endif
91 * Use this if you want to use the same suspend and resume callbacks for suspend
92 * to RAM and hibernation.
94 #define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
95 const struct dev_pm_ops name = { \
96 SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
100 * Use this for defining a set of PM operations to be used in all situations
101 * (sustem suspend, hibernation or runtime PM).
103 #define UNIVERSAL_DEV_PM_OPS(name, suspend_fn, resume_fn, idle_fn) \
104 const struct dev_pm_ops name = { \
105 SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
106 SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
110 * Use this for subsystems (bus types, device types, device classes) that don't
111 * need any special suspend/resume handling in addition to invoking the PM
112 * callbacks provided by device drivers supporting both the system sleep PM and
113 * runtime PM, make the pm member point to generic_subsys_pm_ops.
115 #ifdef CONFIG_PM_OPS
116 extern struct dev_pm_ops generic_subsys_pm_ops;
117 #define GENERIC_SUBSYS_PM_OPS (&generic_subsys_pm_ops)
118 #else
119 #define GENERIC_SUBSYS_PM_OPS NULL
120 #endif
123 * PM_EVENT_ messages
125 * The following PM_EVENT_ messages are defined for the internal use of the PM
126 * core, in order to provide a mechanism allowing the high level suspend and
127 * hibernation code to convey the necessary information to the device PM core
128 * code:
130 * ON No transition.
132 * FREEZE System is going to hibernate, call ->prepare() and ->freeze()
133 * for all devices.
135 * SUSPEND System is going to suspend, call ->prepare() and ->suspend()
136 * for all devices.
138 * HIBERNATE Hibernation image has been saved, call ->prepare() and
139 * ->poweroff() for all devices.
141 * QUIESCE Contents of main memory are going to be restored from a (loaded)
142 * hibernation image, call ->prepare() and ->freeze() for all
143 * devices.
145 * RESUME System is resuming, call ->resume() and ->complete() for all
146 * devices.
148 * THAW Hibernation image has been created, call ->thaw() and
149 * ->complete() for all devices.
151 * RESTORE Contents of main memory have been restored from a hibernation
152 * image, call ->restore() and ->complete() for all devices.
154 * RECOVER Creation of a hibernation image or restoration of the main
155 * memory contents from a hibernation image has failed, call
156 * ->thaw() and ->complete() for all devices.
158 * The following PM_EVENT_ messages are defined for internal use by
159 * kernel subsystems. They are never issued by the PM core.
161 * USER_SUSPEND Manual selective suspend was issued by userspace.
163 * USER_RESUME Manual selective resume was issued by userspace.
165 * REMOTE_WAKEUP Remote-wakeup request was received from the device.
167 * AUTO_SUSPEND Automatic (device idle) runtime suspend was
168 * initiated by the subsystem.
170 * AUTO_RESUME Automatic (device needed) runtime resume was
171 * requested by a driver.
174 #define PM_EVENT_ON 0x0000
175 #define PM_EVENT_FREEZE 0x0001
176 #define PM_EVENT_SUSPEND 0x0002
177 #define PM_EVENT_HIBERNATE 0x0004
178 #define PM_EVENT_QUIESCE 0x0008
179 #define PM_EVENT_RESUME 0x0010
180 #define PM_EVENT_THAW 0x0020
181 #define PM_EVENT_RESTORE 0x0040
182 #define PM_EVENT_RECOVER 0x0080
183 #define PM_EVENT_USER 0x0100
184 #define PM_EVENT_REMOTE 0x0200
185 #define PM_EVENT_AUTO 0x0400
187 #define PM_EVENT_SLEEP (PM_EVENT_SUSPEND | PM_EVENT_HIBERNATE)
188 #define PM_EVENT_USER_SUSPEND (PM_EVENT_USER | PM_EVENT_SUSPEND)
189 #define PM_EVENT_USER_RESUME (PM_EVENT_USER | PM_EVENT_RESUME)
190 #define PM_EVENT_REMOTE_RESUME (PM_EVENT_REMOTE | PM_EVENT_RESUME)
191 #define PM_EVENT_AUTO_SUSPEND (PM_EVENT_AUTO | PM_EVENT_SUSPEND)
192 #define PM_EVENT_AUTO_RESUME (PM_EVENT_AUTO | PM_EVENT_RESUME)
194 #define PMSG_ON ((struct pm_message){ .event = PM_EVENT_ON, })
195 #define PMSG_FREEZE ((struct pm_message){ .event = PM_EVENT_FREEZE, })
196 #define PMSG_QUIESCE ((struct pm_message){ .event = PM_EVENT_QUIESCE, })
197 #define PMSG_SUSPEND ((struct pm_message){ .event = PM_EVENT_SUSPEND, })
198 #define PMSG_HIBERNATE ((struct pm_message){ .event = PM_EVENT_HIBERNATE, })
199 #define PMSG_RESUME ((struct pm_message){ .event = PM_EVENT_RESUME, })
200 #define PMSG_THAW ((struct pm_message){ .event = PM_EVENT_THAW, })
201 #define PMSG_RESTORE ((struct pm_message){ .event = PM_EVENT_RESTORE, })
202 #define PMSG_RECOVER ((struct pm_message){ .event = PM_EVENT_RECOVER, })
203 #define PMSG_USER_SUSPEND ((struct pm_message) \
204 { .event = PM_EVENT_USER_SUSPEND, })
205 #define PMSG_USER_RESUME ((struct pm_message) \
206 { .event = PM_EVENT_USER_RESUME, })
207 #define PMSG_REMOTE_RESUME ((struct pm_message) \
208 { .event = PM_EVENT_REMOTE_RESUME, })
209 #define PMSG_AUTO_SUSPEND ((struct pm_message) \
210 { .event = PM_EVENT_AUTO_SUSPEND, })
211 #define PMSG_AUTO_RESUME ((struct pm_message) \
212 { .event = PM_EVENT_AUTO_RESUME, })
215 * Device power management states
217 * These state labels are used internally by the PM core to indicate the current
218 * status of a device with respect to the PM core operations.
220 * DPM_ON Device is regarded as operational. Set this way
221 * initially and when ->complete() is about to be called.
222 * Also set when ->prepare() fails.
224 * DPM_PREPARING Device is going to be prepared for a PM transition. Set
225 * when ->prepare() is about to be called.
227 * DPM_RESUMING Device is going to be resumed. Set when ->resume(),
228 * ->thaw(), or ->restore() is about to be called.
230 * DPM_SUSPENDING Device has been prepared for a power transition. Set
231 * when ->prepare() has just succeeded.
233 * DPM_OFF Device is regarded as inactive. Set immediately after
234 * ->suspend(), ->freeze(), or ->poweroff() has succeeded.
235 * Also set when ->resume()_noirq, ->thaw_noirq(), or
236 * ->restore_noirq() is about to be called.
238 * DPM_OFF_IRQ Device is in a "deep sleep". Set immediately after
239 * ->suspend_noirq(), ->freeze_noirq(), or
240 * ->poweroff_noirq() has just succeeded.
243 enum dpm_state {
244 DPM_INVALID,
245 DPM_ON,
246 DPM_PREPARING,
247 DPM_RESUMING,
248 DPM_SUSPENDING,
249 DPM_OFF,
250 DPM_OFF_IRQ,
254 * Device run-time power management status.
256 * These status labels are used internally by the PM core to indicate the
257 * current status of a device with respect to the PM core operations. They do
258 * not reflect the actual power state of the device or its status as seen by the
259 * driver.
261 * RPM_ACTIVE Device is fully operational. Indicates that the device
262 * bus type's ->runtime_resume() callback has completed
263 * successfully.
265 * RPM_SUSPENDED Device bus type's ->runtime_suspend() callback has
266 * completed successfully. The device is regarded as
267 * suspended.
269 * RPM_RESUMING Device bus type's ->runtime_resume() callback is being
270 * executed.
272 * RPM_SUSPENDING Device bus type's ->runtime_suspend() callback is being
273 * executed.
276 enum rpm_status {
277 RPM_ACTIVE = 0,
278 RPM_RESUMING,
279 RPM_SUSPENDED,
280 RPM_SUSPENDING,
284 * Device run-time power management request types.
286 * RPM_REQ_NONE Do nothing.
288 * RPM_REQ_IDLE Run the device bus type's ->runtime_idle() callback
290 * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback
292 * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback
295 enum rpm_request {
296 RPM_REQ_NONE = 0,
297 RPM_REQ_IDLE,
298 RPM_REQ_SUSPEND,
299 RPM_REQ_RESUME,
302 struct dev_pm_info {
303 pm_message_t power_state;
304 unsigned int can_wakeup:1;
305 unsigned int should_wakeup:1;
306 unsigned async_suspend:1;
307 enum dpm_state status; /* Owned by the PM core */
308 #ifdef CONFIG_PM_SLEEP
309 struct list_head entry;
310 struct completion completion;
311 unsigned long wakeup_count;
312 #endif
313 #ifdef CONFIG_PM_RUNTIME
314 struct timer_list suspend_timer;
315 unsigned long timer_expires;
316 struct work_struct work;
317 wait_queue_head_t wait_queue;
318 spinlock_t lock;
319 atomic_t usage_count;
320 atomic_t child_count;
321 unsigned int disable_depth:3;
322 unsigned int ignore_children:1;
323 unsigned int idle_notification:1;
324 unsigned int request_pending:1;
325 unsigned int deferred_resume:1;
326 unsigned int run_wake:1;
327 unsigned int runtime_auto:1;
328 enum rpm_request request;
329 enum rpm_status runtime_status;
330 int runtime_error;
331 unsigned long active_jiffies;
332 unsigned long suspended_jiffies;
333 unsigned long accounting_timestamp;
334 #endif
337 extern void update_pm_runtime_accounting(struct device *dev);
341 * The PM_EVENT_ messages are also used by drivers implementing the legacy
342 * suspend framework, based on the ->suspend() and ->resume() callbacks common
343 * for suspend and hibernation transitions, according to the rules below.
346 /* Necessary, because several drivers use PM_EVENT_PRETHAW */
347 #define PM_EVENT_PRETHAW PM_EVENT_QUIESCE
350 * One transition is triggered by resume(), after a suspend() call; the
351 * message is implicit:
353 * ON Driver starts working again, responding to hardware events
354 * and software requests. The hardware may have gone through
355 * a power-off reset, or it may have maintained state from the
356 * previous suspend() which the driver will rely on while
357 * resuming. On most platforms, there are no restrictions on
358 * availability of resources like clocks during resume().
360 * Other transitions are triggered by messages sent using suspend(). All
361 * these transitions quiesce the driver, so that I/O queues are inactive.
362 * That commonly entails turning off IRQs and DMA; there may be rules
363 * about how to quiesce that are specific to the bus or the device's type.
364 * (For example, network drivers mark the link state.) Other details may
365 * differ according to the message:
367 * SUSPEND Quiesce, enter a low power device state appropriate for
368 * the upcoming system state (such as PCI_D3hot), and enable
369 * wakeup events as appropriate.
371 * HIBERNATE Enter a low power device state appropriate for the hibernation
372 * state (eg. ACPI S4) and enable wakeup events as appropriate.
374 * FREEZE Quiesce operations so that a consistent image can be saved;
375 * but do NOT otherwise enter a low power device state, and do
376 * NOT emit system wakeup events.
378 * PRETHAW Quiesce as if for FREEZE; additionally, prepare for restoring
379 * the system from a snapshot taken after an earlier FREEZE.
380 * Some drivers will need to reset their hardware state instead
381 * of preserving it, to ensure that it's never mistaken for the
382 * state which that earlier snapshot had set up.
384 * A minimally power-aware driver treats all messages as SUSPEND, fully
385 * reinitializes its device during resume() -- whether or not it was reset
386 * during the suspend/resume cycle -- and can't issue wakeup events.
388 * More power-aware drivers may also use low power states at runtime as
389 * well as during system sleep states like PM_SUSPEND_STANDBY. They may
390 * be able to use wakeup events to exit from runtime low-power states,
391 * or from system low-power states such as standby or suspend-to-RAM.
394 #ifdef CONFIG_PM_SLEEP
395 extern void device_pm_lock(void);
396 extern int sysdev_resume(void);
397 extern void dpm_resume_noirq(pm_message_t state);
398 extern void dpm_resume_end(pm_message_t state);
400 extern void device_pm_unlock(void);
401 extern int sysdev_suspend(pm_message_t state);
402 extern int dpm_suspend_noirq(pm_message_t state);
403 extern int dpm_suspend_start(pm_message_t state);
405 extern void __suspend_report_result(const char *function, void *fn, int ret);
407 #define suspend_report_result(fn, ret) \
408 do { \
409 __suspend_report_result(__func__, fn, ret); \
410 } while (0)
412 extern void device_pm_wait_for_dev(struct device *sub, struct device *dev);
414 /* drivers/base/power/wakeup.c */
415 extern void pm_wakeup_event(struct device *dev, unsigned int msec);
416 extern void pm_stay_awake(struct device *dev);
417 extern void pm_relax(void);
418 #else /* !CONFIG_PM_SLEEP */
420 #define device_pm_lock() do {} while (0)
421 #define device_pm_unlock() do {} while (0)
423 static inline int dpm_suspend_start(pm_message_t state)
425 return 0;
428 #define suspend_report_result(fn, ret) do {} while (0)
430 static inline void device_pm_wait_for_dev(struct device *a, struct device *b) {}
432 static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
433 static inline void pm_stay_awake(struct device *dev) {}
434 static inline void pm_relax(void) {}
435 #endif /* !CONFIG_PM_SLEEP */
437 /* How to reorder dpm_list after device_move() */
438 enum dpm_order {
439 DPM_ORDER_NONE,
440 DPM_ORDER_DEV_AFTER_PARENT,
441 DPM_ORDER_PARENT_BEFORE_DEV,
442 DPM_ORDER_DEV_LAST,
446 * Global Power Management flags
447 * Used to keep APM and ACPI from both being active
449 extern unsigned int pm_flags;
451 #define PM_APM 1
452 #define PM_ACPI 2
454 #endif /* _LINUX_PM_H */