aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/platform_device.h5
-rw-r--r--include/linux/pm.h115
-rw-r--r--include/linux/pm_runtime.h114
3 files changed, 229 insertions, 5 deletions
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 8dc5123b6305..3c6675c2444b 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -22,6 +22,9 @@ struct platform_device {
22 struct resource * resource; 22 struct resource * resource;
23 23
24 struct platform_device_id *id_entry; 24 struct platform_device_id *id_entry;
25
26 /* arch specific additions */
27 struct pdev_archdata archdata;
25}; 28};
26 29
27#define platform_get_device_id(pdev) ((pdev)->id_entry) 30#define platform_get_device_id(pdev) ((pdev)->id_entry)
@@ -57,8 +60,6 @@ struct platform_driver {
57 int (*remove)(struct platform_device *); 60 int (*remove)(struct platform_device *);
58 void (*shutdown)(struct platform_device *); 61 void (*shutdown)(struct platform_device *);
59 int (*suspend)(struct platform_device *, pm_message_t state); 62 int (*suspend)(struct platform_device *, pm_message_t state);
60 int (*suspend_late)(struct platform_device *, pm_message_t state);
61 int (*resume_early)(struct platform_device *);
62 int (*resume)(struct platform_device *); 63 int (*resume)(struct platform_device *);
63 struct device_driver driver; 64 struct device_driver driver;
64 struct platform_device_id *id_table; 65 struct platform_device_id *id_table;
diff --git a/include/linux/pm.h b/include/linux/pm.h
index b3f74764a586..3b7e04b95bd2 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -22,6 +22,10 @@
22#define _LINUX_PM_H 22#define _LINUX_PM_H
23 23
24#include <linux/list.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>
25 29
26/* 30/*
27 * Callbacks for platform drivers to implement. 31 * Callbacks for platform drivers to implement.
@@ -165,6 +169,28 @@ typedef struct pm_message {
165 * It is allowed to unregister devices while the above callbacks are being 169 * It is allowed to unregister devices while the above callbacks are being
166 * executed. However, it is not allowed to unregister a device from within any 170 * executed. However, it is not allowed to unregister a device from within any
167 * of its own callbacks. 171 * of its own callbacks.
172 *
173 * There also are the following callbacks related to run-time power management
174 * of devices:
175 *
176 * @runtime_suspend: Prepare the device for a condition in which it won't be
177 * able to communicate with the CPU(s) and RAM due to power management.
178 * This need not mean that the device should be put into a low power state.
179 * For example, if the device is behind a link which is about to be turned
180 * off, the device may remain at full power. If the device does go to low
181 * power and if device_may_wakeup(dev) is true, remote wake-up (i.e., a
182 * hardware mechanism allowing the device to request a change of its power
183 * state, such as PCI PME) should 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.
168 */ 194 */
169 195
170struct dev_pm_ops { 196struct dev_pm_ops {
@@ -182,8 +208,25 @@ struct dev_pm_ops {
182 int (*thaw_noirq)(struct device *dev); 208 int (*thaw_noirq)(struct device *dev);
183 int (*poweroff_noirq)(struct device *dev); 209 int (*poweroff_noirq)(struct device *dev);
184 int (*restore_noirq)(struct device *dev); 210 int (*restore_noirq)(struct device *dev);
211 int (*runtime_suspend)(struct device *dev);
212 int (*runtime_resume)(struct device *dev);
213 int (*runtime_idle)(struct device *dev);
185}; 214};
186 215
216/*
217 * Use this if you want to use the same suspend and resume callbacks for suspend
218 * to RAM and hibernation.
219 */
220#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \
221struct dev_pm_ops name = { \
222 .suspend = suspend_fn, \
223 .resume = resume_fn, \
224 .freeze = suspend_fn, \
225 .thaw = resume_fn, \
226 .poweroff = suspend_fn, \
227 .restore = resume_fn, \
228}
229
187/** 230/**
188 * PM_EVENT_ messages 231 * PM_EVENT_ messages
189 * 232 *
@@ -315,14 +358,80 @@ enum dpm_state {
315 DPM_OFF_IRQ, 358 DPM_OFF_IRQ,
316}; 359};
317 360
361/**
362 * Device run-time power management status.
363 *
364 * These status labels are used internally by the PM core to indicate the
365 * current status of a device with respect to the PM core operations. They do
366 * not reflect the actual power state of the device or its status as seen by the
367 * driver.
368 *
369 * RPM_ACTIVE Device is fully operational. Indicates that the device
370 * bus type's ->runtime_resume() callback has completed
371 * successfully.
372 *
373 * RPM_SUSPENDED Device bus type's ->runtime_suspend() callback has
374 * completed successfully. The device is regarded as
375 * suspended.
376 *
377 * RPM_RESUMING Device bus type's ->runtime_resume() callback is being
378 * executed.
379 *
380 * RPM_SUSPENDING Device bus type's ->runtime_suspend() callback is being
381 * executed.
382 */
383
384enum rpm_status {
385 RPM_ACTIVE = 0,
386 RPM_RESUMING,
387 RPM_SUSPENDED,
388 RPM_SUSPENDING,
389};
390
391/**
392 * Device run-time power management request types.
393 *
394 * RPM_REQ_NONE Do nothing.
395 *
396 * RPM_REQ_IDLE Run the device bus type's ->runtime_idle() callback
397 *
398 * RPM_REQ_SUSPEND Run the device bus type's ->runtime_suspend() callback
399 *
400 * RPM_REQ_RESUME Run the device bus type's ->runtime_resume() callback
401 */
402
403enum rpm_request {
404 RPM_REQ_NONE = 0,
405 RPM_REQ_IDLE,
406 RPM_REQ_SUSPEND,
407 RPM_REQ_RESUME,
408};
409
318struct dev_pm_info { 410struct dev_pm_info {
319 pm_message_t power_state; 411 pm_message_t power_state;
320 unsigned can_wakeup:1; 412 unsigned int can_wakeup:1;
321 unsigned should_wakeup:1; 413 unsigned int should_wakeup:1;
322 enum dpm_state status; /* Owned by the PM core */ 414 enum dpm_state status; /* Owned by the PM core */
323#ifdef CONFIG_PM_SLEEP 415#ifdef CONFIG_PM_SLEEP
324 struct list_head entry; 416 struct list_head entry;
325#endif 417#endif
418#ifdef CONFIG_PM_RUNTIME
419 struct timer_list suspend_timer;
420 unsigned long timer_expires;
421 struct work_struct work;
422 wait_queue_head_t wait_queue;
423 spinlock_t lock;
424 atomic_t usage_count;
425 atomic_t child_count;
426 unsigned int disable_depth:3;
427 unsigned int ignore_children:1;
428 unsigned int idle_notification:1;
429 unsigned int request_pending:1;
430 unsigned int deferred_resume:1;
431 enum rpm_request request;
432 enum rpm_status runtime_status;
433 int runtime_error;
434#endif
326}; 435};
327 436
328/* 437/*
diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
new file mode 100644
index 000000000000..44087044910f
--- /dev/null
+++ b/include/linux/pm_runtime.h
@@ -0,0 +1,114 @@
1/*
2 * pm_runtime.h - Device run-time power management helper functions.
3 *
4 * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>
5 *
6 * This file is released under the GPLv2.
7 */
8
9#ifndef _LINUX_PM_RUNTIME_H
10#define _LINUX_PM_RUNTIME_H
11
12#include <linux/device.h>
13#include <linux/pm.h>
14
15#ifdef CONFIG_PM_RUNTIME
16
17extern struct workqueue_struct *pm_wq;
18
19extern int pm_runtime_idle(struct device *dev);
20extern int pm_runtime_suspend(struct device *dev);
21extern int pm_runtime_resume(struct device *dev);
22extern int pm_request_idle(struct device *dev);
23extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
24extern int pm_request_resume(struct device *dev);
25extern int __pm_runtime_get(struct device *dev, bool sync);
26extern int __pm_runtime_put(struct device *dev, bool sync);
27extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
28extern int pm_runtime_barrier(struct device *dev);
29extern void pm_runtime_enable(struct device *dev);
30extern void __pm_runtime_disable(struct device *dev, bool check_resume);
31
32static inline bool pm_children_suspended(struct device *dev)
33{
34 return dev->power.ignore_children
35 || !atomic_read(&dev->power.child_count);
36}
37
38static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
39{
40 dev->power.ignore_children = enable;
41}
42
43static inline void pm_runtime_get_noresume(struct device *dev)
44{
45 atomic_inc(&dev->power.usage_count);
46}
47
48static inline void pm_runtime_put_noidle(struct device *dev)
49{
50 atomic_add_unless(&dev->power.usage_count, -1, 0);
51}
52
53#else /* !CONFIG_PM_RUNTIME */
54
55static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; }
56static inline int pm_runtime_suspend(struct device *dev) { return -ENOSYS; }
57static inline int pm_runtime_resume(struct device *dev) { return 0; }
58static inline int pm_request_idle(struct device *dev) { return -ENOSYS; }
59static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
60{
61 return -ENOSYS;
62}
63static inline int pm_request_resume(struct device *dev) { return 0; }
64static inline int __pm_runtime_get(struct device *dev, bool sync) { return 1; }
65static inline int __pm_runtime_put(struct device *dev, bool sync) { return 0; }
66static inline int __pm_runtime_set_status(struct device *dev,
67 unsigned int status) { return 0; }
68static inline int pm_runtime_barrier(struct device *dev) { return 0; }
69static inline void pm_runtime_enable(struct device *dev) {}
70static inline void __pm_runtime_disable(struct device *dev, bool c) {}
71
72static inline bool pm_children_suspended(struct device *dev) { return false; }
73static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
74static inline void pm_runtime_get_noresume(struct device *dev) {}
75static inline void pm_runtime_put_noidle(struct device *dev) {}
76
77#endif /* !CONFIG_PM_RUNTIME */
78
79static inline int pm_runtime_get(struct device *dev)
80{
81 return __pm_runtime_get(dev, false);
82}
83
84static inline int pm_runtime_get_sync(struct device *dev)
85{
86 return __pm_runtime_get(dev, true);
87}
88
89static inline int pm_runtime_put(struct device *dev)
90{
91 return __pm_runtime_put(dev, false);
92}
93
94static inline int pm_runtime_put_sync(struct device *dev)
95{
96 return __pm_runtime_put(dev, true);
97}
98
99static inline int pm_runtime_set_active(struct device *dev)
100{
101 return __pm_runtime_set_status(dev, RPM_ACTIVE);
102}
103
104static inline void pm_runtime_set_suspended(struct device *dev)
105{
106 __pm_runtime_set_status(dev, RPM_SUSPENDED);
107}
108
109static inline void pm_runtime_disable(struct device *dev)
110{
111 __pm_runtime_disable(dev, true);
112}
113
114#endif