aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/power
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/power')
-rw-r--r--Documentation/power/devices.txt14
-rw-r--r--Documentation/power/opp.txt2
-rw-r--r--Documentation/power/runtime_pm.txt253
3 files changed, 178 insertions, 91 deletions
diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt
index 64565aac6e4..3384d5996be 100644
--- a/Documentation/power/devices.txt
+++ b/Documentation/power/devices.txt
@@ -506,8 +506,8 @@ routines. Nevertheless, different callback pointers are used in case there is a
506situation where it actually matters. 506situation where it actually matters.
507 507
508 508
509Device Power Domains 509Device Power Management Domains
510-------------------- 510-------------------------------
511Sometimes devices share reference clocks or other power resources. In those 511Sometimes devices share reference clocks or other power resources. In those
512cases it generally is not possible to put devices into low-power states 512cases it generally is not possible to put devices into low-power states
513individually. Instead, a set of devices sharing a power resource can be put 513individually. Instead, a set of devices sharing a power resource can be put
@@ -516,8 +516,8 @@ power resource. Of course, they also need to be put into the full-power state
516together, by turning the shared power resource on. A set of devices with this 516together, by turning the shared power resource on. A set of devices with this
517property is often referred to as a power domain. 517property is often referred to as a power domain.
518 518
519Support for power domains is provided through the pwr_domain field of struct 519Support for power domains is provided through the pm_domain field of struct
520device. This field is a pointer to an object of type struct dev_power_domain, 520device. This field is a pointer to an object of type struct dev_pm_domain,
521defined in include/linux/pm.h, providing a set of power management callbacks 521defined in include/linux/pm.h, providing a set of power management callbacks
522analogous to the subsystem-level and device driver callbacks that are executed 522analogous to the subsystem-level and device driver callbacks that are executed
523for the given device during all power transitions, instead of the respective 523for the given device during all power transitions, instead of the respective
@@ -604,7 +604,7 @@ state temporarily, for example so that its system wakeup capability can be
604disabled. This all depends on the hardware and the design of the subsystem and 604disabled. This all depends on the hardware and the design of the subsystem and
605device driver in question. 605device driver in question.
606 606
607During system-wide resume from a sleep state it's best to put devices into the 607During system-wide resume from a sleep state it's easiest to put devices into
608full-power state, as explained in Documentation/power/runtime_pm.txt. Refer to 608the full-power state, as explained in Documentation/power/runtime_pm.txt. Refer
609that document for more information regarding this particular issue as well as 609to that document for more information regarding this particular issue as well as
610for information on the device runtime power management framework in general. 610for information on the device runtime power management framework in general.
diff --git a/Documentation/power/opp.txt b/Documentation/power/opp.txt
index 5ae70a12c1e..3035d00757a 100644
--- a/Documentation/power/opp.txt
+++ b/Documentation/power/opp.txt
@@ -321,6 +321,8 @@ opp_init_cpufreq_table - cpufreq framework typically is initialized with
321 addition to CONFIG_PM as power management feature is required to 321 addition to CONFIG_PM as power management feature is required to
322 dynamically scale voltage and frequency in a system. 322 dynamically scale voltage and frequency in a system.
323 323
324opp_free_cpufreq_table - Free up the table allocated by opp_init_cpufreq_table
325
3247. Data Structures 3267. Data Structures
325================== 327==================
326Typically an SoC contains multiple voltage domains which are variable. Each 328Typically an SoC contains multiple voltage domains which are variable. Each
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt
index b24875b1ced..b0ee95e99ff 100644
--- a/Documentation/power/runtime_pm.txt
+++ b/Documentation/power/runtime_pm.txt
@@ -1,39 +1,39 @@
1Run-time Power Management Framework for I/O Devices 1Runtime Power Management Framework for I/O Devices
2 2
3(C) 2009-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. 3(C) 2009-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
4(C) 2010 Alan Stern <stern@rowland.harvard.edu> 4(C) 2010 Alan Stern <stern@rowland.harvard.edu>
5 5
61. Introduction 61. Introduction
7 7
8Support for run-time power management (run-time PM) of I/O devices is provided 8Support for runtime power management (runtime PM) of I/O devices is provided
9at the power management core (PM core) level by means of: 9at the power management core (PM core) level by means of:
10 10
11* The power management workqueue pm_wq in which bus types and device drivers can 11* The power management workqueue pm_wq in which bus types and device drivers can
12 put their PM-related work items. It is strongly recommended that pm_wq be 12 put their PM-related work items. It is strongly recommended that pm_wq be
13 used for queuing all work items related to run-time PM, because this allows 13 used for queuing all work items related to runtime PM, because this allows
14 them to be synchronized with system-wide power transitions (suspend to RAM, 14 them to be synchronized with system-wide power transitions (suspend to RAM,
15 hibernation and resume from system sleep states). pm_wq is declared in 15 hibernation and resume from system sleep states). pm_wq is declared in
16 include/linux/pm_runtime.h and defined in kernel/power/main.c. 16 include/linux/pm_runtime.h and defined in kernel/power/main.c.
17 17
18* A number of run-time PM fields in the 'power' member of 'struct device' (which 18* A number of runtime PM fields in the 'power' member of 'struct device' (which
19 is of the type 'struct dev_pm_info', defined in include/linux/pm.h) that can 19 is of the type 'struct dev_pm_info', defined in include/linux/pm.h) that can
20 be used for synchronizing run-time PM operations with one another. 20 be used for synchronizing runtime PM operations with one another.
21 21
22* Three device run-time PM callbacks in 'struct dev_pm_ops' (defined in 22* Three device runtime PM callbacks in 'struct dev_pm_ops' (defined in
23 include/linux/pm.h). 23 include/linux/pm.h).
24 24
25* A set of helper functions defined in drivers/base/power/runtime.c that can be 25* A set of helper functions defined in drivers/base/power/runtime.c that can be
26 used for carrying out run-time PM operations in such a way that the 26 used for carrying out runtime PM operations in such a way that the
27 synchronization between them is taken care of by the PM core. Bus types and 27 synchronization between them is taken care of by the PM core. Bus types and
28 device drivers are encouraged to use these functions. 28 device drivers are encouraged to use these functions.
29 29
30The run-time PM callbacks present in 'struct dev_pm_ops', the device run-time PM 30The runtime PM callbacks present in 'struct dev_pm_ops', the device runtime PM
31fields of 'struct dev_pm_info' and the core helper functions provided for 31fields of 'struct dev_pm_info' and the core helper functions provided for
32run-time PM are described below. 32runtime PM are described below.
33 33
342. Device Run-time PM Callbacks 342. Device Runtime PM Callbacks
35 35
36There are three device run-time PM callbacks defined in 'struct dev_pm_ops': 36There are three device runtime PM callbacks defined in 'struct dev_pm_ops':
37 37
38struct dev_pm_ops { 38struct dev_pm_ops {
39 ... 39 ...
@@ -54,11 +54,10 @@ referred to as subsystem-level callbacks in what follows.
54By default, the callbacks are always invoked in process context with interrupts 54By default, the callbacks are always invoked in process context with interrupts
55enabled. However, subsystems can use the pm_runtime_irq_safe() helper function 55enabled. However, subsystems can use the pm_runtime_irq_safe() helper function
56to tell the PM core that a device's ->runtime_suspend() and ->runtime_resume() 56to tell the PM core that a device's ->runtime_suspend() and ->runtime_resume()
57callbacks should be invoked in atomic context with interrupts disabled 57callbacks should be invoked in atomic context with interrupts disabled.
58(->runtime_idle() is still invoked the default way). This implies that these 58This implies that these callback routines must not block or sleep, but it also
59callback routines must not block or sleep, but it also means that the 59means that the synchronous helper functions listed at the end of Section 4 can
60synchronous helper functions listed at the end of Section 4 can be used within 60be used within an interrupt handler or in an atomic context.
61an interrupt handler or in an atomic context.
62 61
63The subsystem-level suspend callback is _entirely_ _responsible_ for handling 62The subsystem-level suspend callback is _entirely_ _responsible_ for handling
64the suspend of the device as appropriate, which may, but need not include 63the suspend of the device as appropriate, which may, but need not include
@@ -72,11 +71,11 @@ knows what to do to handle the device).
72 not mean that the device has been put into a low power state. It is 71 not mean that the device has been put into a low power state. It is
73 supposed to mean, however, that the device will not process data and will 72 supposed to mean, however, that the device will not process data and will
74 not communicate with the CPU(s) and RAM until the subsystem-level resume 73 not communicate with the CPU(s) and RAM until the subsystem-level resume
75 callback is executed for it. The run-time PM status of a device after 74 callback is executed for it. The runtime PM status of a device after
76 successful execution of the subsystem-level suspend callback is 'suspended'. 75 successful execution of the subsystem-level suspend callback is 'suspended'.
77 76
78 * If the subsystem-level suspend callback returns -EBUSY or -EAGAIN, 77 * If the subsystem-level suspend callback returns -EBUSY or -EAGAIN,
79 the device's run-time PM status is 'active', which means that the device 78 the device's runtime PM status is 'active', which means that the device
80 _must_ be fully operational afterwards. 79 _must_ be fully operational afterwards.
81 80
82 * If the subsystem-level suspend callback returns an error code different 81 * If the subsystem-level suspend callback returns an error code different
@@ -104,7 +103,7 @@ the device).
104 103
105 * Once the subsystem-level resume callback has completed successfully, the PM 104 * Once the subsystem-level resume callback has completed successfully, the PM
106 core regards the device as fully operational, which means that the device 105 core regards the device as fully operational, which means that the device
107 _must_ be able to complete I/O operations as needed. The run-time PM status 106 _must_ be able to complete I/O operations as needed. The runtime PM status
108 of the device is then 'active'. 107 of the device is then 'active'.
109 108
110 * If the subsystem-level resume callback returns an error code, the PM core 109 * If the subsystem-level resume callback returns an error code, the PM core
@@ -130,7 +129,7 @@ device in that case. The value returned by this callback is ignored by the PM
130core. 129core.
131 130
132The helper functions provided by the PM core, described in Section 4, guarantee 131The helper functions provided by the PM core, described in Section 4, guarantee
133that the following constraints are met with respect to the bus type's run-time 132that the following constraints are met with respect to the bus type's runtime
134PM callbacks: 133PM callbacks:
135 134
136(1) The callbacks are mutually exclusive (e.g. it is forbidden to execute 135(1) The callbacks are mutually exclusive (e.g. it is forbidden to execute
@@ -142,7 +141,7 @@ PM callbacks:
142 141
143(2) ->runtime_idle() and ->runtime_suspend() can only be executed for 'active' 142(2) ->runtime_idle() and ->runtime_suspend() can only be executed for 'active'
144 devices (i.e. the PM core will only execute ->runtime_idle() or 143 devices (i.e. the PM core will only execute ->runtime_idle() or
145 ->runtime_suspend() for the devices the run-time PM status of which is 144 ->runtime_suspend() for the devices the runtime PM status of which is
146 'active'). 145 'active').
147 146
148(3) ->runtime_idle() and ->runtime_suspend() can only be executed for a device 147(3) ->runtime_idle() and ->runtime_suspend() can only be executed for a device
@@ -151,7 +150,7 @@ PM callbacks:
151 flag of which is set. 150 flag of which is set.
152 151
153(4) ->runtime_resume() can only be executed for 'suspended' devices (i.e. the 152(4) ->runtime_resume() can only be executed for 'suspended' devices (i.e. the
154 PM core will only execute ->runtime_resume() for the devices the run-time 153 PM core will only execute ->runtime_resume() for the devices the runtime
155 PM status of which is 'suspended'). 154 PM status of which is 'suspended').
156 155
157Additionally, the helper functions provided by the PM core obey the following 156Additionally, the helper functions provided by the PM core obey the following
@@ -171,9 +170,9 @@ rules:
171 scheduled requests to execute the other callbacks for the same device, 170 scheduled requests to execute the other callbacks for the same device,
172 except for scheduled autosuspends. 171 except for scheduled autosuspends.
173 172
1743. Run-time PM Device Fields 1733. Runtime PM Device Fields
175 174
176The following device run-time PM fields are present in 'struct dev_pm_info', as 175The following device runtime PM fields are present in 'struct dev_pm_info', as
177defined in include/linux/pm.h: 176defined in include/linux/pm.h:
178 177
179 struct timer_list suspend_timer; 178 struct timer_list suspend_timer;
@@ -205,7 +204,7 @@ defined in include/linux/pm.h:
205 204
206 unsigned int disable_depth; 205 unsigned int disable_depth;
207 - used for disabling the helper funcions (they work normally if this is 206 - used for disabling the helper funcions (they work normally if this is
208 equal to zero); the initial value of it is 1 (i.e. run-time PM is 207 equal to zero); the initial value of it is 1 (i.e. runtime PM is
209 initially disabled for all devices) 208 initially disabled for all devices)
210 209
211 unsigned int runtime_error; 210 unsigned int runtime_error;
@@ -229,10 +228,10 @@ defined in include/linux/pm.h:
229 suspend to complete; means "start a resume as soon as you've suspended" 228 suspend to complete; means "start a resume as soon as you've suspended"
230 229
231 unsigned int run_wake; 230 unsigned int run_wake;
232 - set if the device is capable of generating run-time wake-up events 231 - set if the device is capable of generating runtime wake-up events
233 232
234 enum rpm_status runtime_status; 233 enum rpm_status runtime_status;
235 - the run-time PM status of the device; this field's initial value is 234 - the runtime PM status of the device; this field's initial value is
236 RPM_SUSPENDED, which means that each device is initially regarded by the 235 RPM_SUSPENDED, which means that each device is initially regarded by the
237 PM core as 'suspended', regardless of its real hardware status 236 PM core as 'suspended', regardless of its real hardware status
238 237
@@ -243,7 +242,7 @@ defined in include/linux/pm.h:
243 and pm_runtime_forbid() helper functions 242 and pm_runtime_forbid() helper functions
244 243
245 unsigned int no_callbacks; 244 unsigned int no_callbacks;
246 - indicates that the device does not use the run-time PM callbacks (see 245 - indicates that the device does not use the runtime PM callbacks (see
247 Section 8); it may be modified only by the pm_runtime_no_callbacks() 246 Section 8); it may be modified only by the pm_runtime_no_callbacks()
248 helper function 247 helper function
249 248
@@ -270,16 +269,16 @@ defined in include/linux/pm.h:
270 269
271All of the above fields are members of the 'power' member of 'struct device'. 270All of the above fields are members of the 'power' member of 'struct device'.
272 271
2734. Run-time PM Device Helper Functions 2724. Runtime PM Device Helper Functions
274 273
275The following run-time PM helper functions are defined in 274The following runtime PM helper functions are defined in
276drivers/base/power/runtime.c and include/linux/pm_runtime.h: 275drivers/base/power/runtime.c and include/linux/pm_runtime.h:
277 276
278 void pm_runtime_init(struct device *dev); 277 void pm_runtime_init(struct device *dev);
279 - initialize the device run-time PM fields in 'struct dev_pm_info' 278 - initialize the device runtime PM fields in 'struct dev_pm_info'
280 279
281 void pm_runtime_remove(struct device *dev); 280 void pm_runtime_remove(struct device *dev);
282 - make sure that the run-time PM of the device will be disabled after 281 - make sure that the runtime PM of the device will be disabled after
283 removing the device from device hierarchy 282 removing the device from device hierarchy
284 283
285 int pm_runtime_idle(struct device *dev); 284 int pm_runtime_idle(struct device *dev);
@@ -289,9 +288,10 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
289 288
290 int pm_runtime_suspend(struct device *dev); 289 int pm_runtime_suspend(struct device *dev);
291 - execute the subsystem-level suspend callback for the device; returns 0 on 290 - execute the subsystem-level suspend callback for the device; returns 0 on
292 success, 1 if the device's run-time PM status was already 'suspended', or 291 success, 1 if the device's runtime PM status was already 'suspended', or
293 error code on failure, where -EAGAIN or -EBUSY means it is safe to attempt 292 error code on failure, where -EAGAIN or -EBUSY means it is safe to attempt
294 to suspend the device again in future 293 to suspend the device again in future and -EACCES means that
294 'power.disable_depth' is different from 0
295 295
296 int pm_runtime_autosuspend(struct device *dev); 296 int pm_runtime_autosuspend(struct device *dev);
297 - same as pm_runtime_suspend() except that the autosuspend delay is taken 297 - same as pm_runtime_suspend() except that the autosuspend delay is taken
@@ -301,10 +301,11 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
301 301
302 int pm_runtime_resume(struct device *dev); 302 int pm_runtime_resume(struct device *dev);
303 - execute the subsystem-level resume callback for the device; returns 0 on 303 - execute the subsystem-level resume callback for the device; returns 0 on
304 success, 1 if the device's run-time PM status was already 'active' or 304 success, 1 if the device's runtime PM status was already 'active' or
305 error code on failure, where -EAGAIN means it may be safe to attempt to 305 error code on failure, where -EAGAIN means it may be safe to attempt to
306 resume the device again in future, but 'power.runtime_error' should be 306 resume the device again in future, but 'power.runtime_error' should be
307 checked additionally 307 checked additionally, and -EACCES means that 'power.disable_depth' is
308 different from 0
308 309
309 int pm_request_idle(struct device *dev); 310 int pm_request_idle(struct device *dev);
310 - submit a request to execute the subsystem-level idle callback for the 311 - submit a request to execute the subsystem-level idle callback for the
@@ -321,7 +322,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
321 device in future, where 'delay' is the time to wait before queuing up a 322 device in future, where 'delay' is the time to wait before queuing up a
322 suspend work item in pm_wq, in milliseconds (if 'delay' is zero, the work 323 suspend work item in pm_wq, in milliseconds (if 'delay' is zero, the work
323 item is queued up immediately); returns 0 on success, 1 if the device's PM 324 item is queued up immediately); returns 0 on success, 1 if the device's PM
324 run-time status was already 'suspended', or error code if the request 325 runtime status was already 'suspended', or error code if the request
325 hasn't been scheduled (or queued up if 'delay' is 0); if the execution of 326 hasn't been scheduled (or queued up if 'delay' is 0); if the execution of
326 ->runtime_suspend() is already scheduled and not yet expired, the new 327 ->runtime_suspend() is already scheduled and not yet expired, the new
327 value of 'delay' will be used as the time to wait 328 value of 'delay' will be used as the time to wait
@@ -329,7 +330,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
329 int pm_request_resume(struct device *dev); 330 int pm_request_resume(struct device *dev);
330 - submit a request to execute the subsystem-level resume callback for the 331 - submit a request to execute the subsystem-level resume callback for the
331 device (the request is represented by a work item in pm_wq); returns 0 on 332 device (the request is represented by a work item in pm_wq); returns 0 on
332 success, 1 if the device's run-time PM status was already 'active', or 333 success, 1 if the device's runtime PM status was already 'active', or
333 error code if the request hasn't been queued up 334 error code if the request hasn't been queued up
334 335
335 void pm_runtime_get_noresume(struct device *dev); 336 void pm_runtime_get_noresume(struct device *dev);
@@ -367,22 +368,32 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
367 pm_runtime_autosuspend(dev) and return its result 368 pm_runtime_autosuspend(dev) and return its result
368 369
369 void pm_runtime_enable(struct device *dev); 370 void pm_runtime_enable(struct device *dev);
370 - enable the run-time PM helper functions to run the device bus type's 371 - decrement the device's 'power.disable_depth' field; if that field is equal
371 run-time PM callbacks described in Section 2 372 to zero, the runtime PM helper functions can execute subsystem-level
373 callbacks described in Section 2 for the device
372 374
373 int pm_runtime_disable(struct device *dev); 375 int pm_runtime_disable(struct device *dev);
374 - prevent the run-time PM helper functions from running subsystem-level 376 - increment the device's 'power.disable_depth' field (if the value of that
375 run-time PM callbacks for the device, make sure that all of the pending 377 field was previously zero, this prevents subsystem-level runtime PM
376 run-time PM operations on the device are either completed or canceled; 378 callbacks from being run for the device), make sure that all of the pending
379 runtime PM operations on the device are either completed or canceled;
377 returns 1 if there was a resume request pending and it was necessary to 380 returns 1 if there was a resume request pending and it was necessary to
378 execute the subsystem-level resume callback for the device to satisfy that 381 execute the subsystem-level resume callback for the device to satisfy that
379 request, otherwise 0 is returned 382 request, otherwise 0 is returned
380 383
384 int pm_runtime_barrier(struct device *dev);
385 - check if there's a resume request pending for the device and resume it
386 (synchronously) in that case, cancel any other pending runtime PM requests
387 regarding it and wait for all runtime PM operations on it in progress to
388 complete; returns 1 if there was a resume request pending and it was
389 necessary to execute the subsystem-level resume callback for the device to
390 satisfy that request, otherwise 0 is returned
391
381 void pm_suspend_ignore_children(struct device *dev, bool enable); 392 void pm_suspend_ignore_children(struct device *dev, bool enable);
382 - set/unset the power.ignore_children flag of the device 393 - set/unset the power.ignore_children flag of the device
383 394
384 int pm_runtime_set_active(struct device *dev); 395 int pm_runtime_set_active(struct device *dev);
385 - clear the device's 'power.runtime_error' flag, set the device's run-time 396 - clear the device's 'power.runtime_error' flag, set the device's runtime
386 PM status to 'active' and update its parent's counter of 'active' 397 PM status to 'active' and update its parent's counter of 'active'
387 children as appropriate (it is only valid to use this function if 398 children as appropriate (it is only valid to use this function if
388 'power.runtime_error' is set or 'power.disable_depth' is greater than 399 'power.runtime_error' is set or 'power.disable_depth' is greater than
@@ -390,7 +401,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
390 which is not active and the 'power.ignore_children' flag of which is unset 401 which is not active and the 'power.ignore_children' flag of which is unset
391 402
392 void pm_runtime_set_suspended(struct device *dev); 403 void pm_runtime_set_suspended(struct device *dev);
393 - clear the device's 'power.runtime_error' flag, set the device's run-time 404 - clear the device's 'power.runtime_error' flag, set the device's runtime
394 PM status to 'suspended' and update its parent's counter of 'active' 405 PM status to 'suspended' and update its parent's counter of 'active'
395 children as appropriate (it is only valid to use this function if 406 children as appropriate (it is only valid to use this function if
396 'power.runtime_error' is set or 'power.disable_depth' is greater than 407 'power.runtime_error' is set or 'power.disable_depth' is greater than
@@ -400,6 +411,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
400 - return true if the device's runtime PM status is 'suspended' and its 411 - return true if the device's runtime PM status is 'suspended' and its
401 'power.disable_depth' field is equal to zero, or false otherwise 412 'power.disable_depth' field is equal to zero, or false otherwise
402 413
414 bool pm_runtime_status_suspended(struct device *dev);
415 - return true if the device's runtime PM status is 'suspended'
416
403 void pm_runtime_allow(struct device *dev); 417 void pm_runtime_allow(struct device *dev);
404 - set the power.runtime_auto flag for the device and decrease its usage 418 - set the power.runtime_auto flag for the device and decrease its usage
405 counter (used by the /sys/devices/.../power/control interface to 419 counter (used by the /sys/devices/.../power/control interface to
@@ -411,14 +425,13 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
411 effectively prevent the device from being power managed at run time) 425 effectively prevent the device from being power managed at run time)
412 426
413 void pm_runtime_no_callbacks(struct device *dev); 427 void pm_runtime_no_callbacks(struct device *dev);
414 - set the power.no_callbacks flag for the device and remove the run-time 428 - set the power.no_callbacks flag for the device and remove the runtime
415 PM attributes from /sys/devices/.../power (or prevent them from being 429 PM attributes from /sys/devices/.../power (or prevent them from being
416 added when the device is registered) 430 added when the device is registered)
417 431
418 void pm_runtime_irq_safe(struct device *dev); 432 void pm_runtime_irq_safe(struct device *dev);
419 - set the power.irq_safe flag for the device, causing the runtime-PM 433 - set the power.irq_safe flag for the device, causing the runtime-PM
420 suspend and resume callbacks (but not the idle callback) to be invoked 434 callbacks to be invoked with interrupts off
421 with interrupts disabled
422 435
423 void pm_runtime_mark_last_busy(struct device *dev); 436 void pm_runtime_mark_last_busy(struct device *dev);
424 - set the power.last_busy field to the current time 437 - set the power.last_busy field to the current time
@@ -431,7 +444,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h:
431 444
432 void pm_runtime_set_autosuspend_delay(struct device *dev, int delay); 445 void pm_runtime_set_autosuspend_delay(struct device *dev, int delay);
433 - set the power.autosuspend_delay value to 'delay' (expressed in 446 - set the power.autosuspend_delay value to 'delay' (expressed in
434 milliseconds); if 'delay' is negative then run-time suspends are 447 milliseconds); if 'delay' is negative then runtime suspends are
435 prevented 448 prevented
436 449
437 unsigned long pm_runtime_autosuspend_expiration(struct device *dev); 450 unsigned long pm_runtime_autosuspend_expiration(struct device *dev);
@@ -468,37 +481,39 @@ pm_runtime_suspend()
468pm_runtime_autosuspend() 481pm_runtime_autosuspend()
469pm_runtime_resume() 482pm_runtime_resume()
470pm_runtime_get_sync() 483pm_runtime_get_sync()
484pm_runtime_put_sync()
471pm_runtime_put_sync_suspend() 485pm_runtime_put_sync_suspend()
486pm_runtime_put_sync_autosuspend()
472 487
4735. Run-time PM Initialization, Device Probing and Removal 4885. Runtime PM Initialization, Device Probing and Removal
474 489
475Initially, the run-time PM is disabled for all devices, which means that the 490Initially, the runtime PM is disabled for all devices, which means that the
476majority of the run-time PM helper funtions described in Section 4 will return 491majority of the runtime PM helper funtions described in Section 4 will return
477-EAGAIN until pm_runtime_enable() is called for the device. 492-EAGAIN until pm_runtime_enable() is called for the device.
478 493
479In addition to that, the initial run-time PM status of all devices is 494In addition to that, the initial runtime PM status of all devices is
480'suspended', but it need not reflect the actual physical state of the device. 495'suspended', but it need not reflect the actual physical state of the device.
481Thus, if the device is initially active (i.e. it is able to process I/O), its 496Thus, if the device is initially active (i.e. it is able to process I/O), its
482run-time PM status must be changed to 'active', with the help of 497runtime PM status must be changed to 'active', with the help of
483pm_runtime_set_active(), before pm_runtime_enable() is called for the device. 498pm_runtime_set_active(), before pm_runtime_enable() is called for the device.
484 499
485However, if the device has a parent and the parent's run-time PM is enabled, 500However, if the device has a parent and the parent's runtime PM is enabled,
486calling pm_runtime_set_active() for the device will affect the parent, unless 501calling pm_runtime_set_active() for the device will affect the parent, unless
487the parent's 'power.ignore_children' flag is set. Namely, in that case the 502the parent's 'power.ignore_children' flag is set. Namely, in that case the
488parent won't be able to suspend at run time, using the PM core's helper 503parent won't be able to suspend at run time, using the PM core's helper
489functions, as long as the child's status is 'active', even if the child's 504functions, as long as the child's status is 'active', even if the child's
490run-time PM is still disabled (i.e. pm_runtime_enable() hasn't been called for 505runtime PM is still disabled (i.e. pm_runtime_enable() hasn't been called for
491the child yet or pm_runtime_disable() has been called for it). For this reason, 506the child yet or pm_runtime_disable() has been called for it). For this reason,
492once pm_runtime_set_active() has been called for the device, pm_runtime_enable() 507once pm_runtime_set_active() has been called for the device, pm_runtime_enable()
493should be called for it too as soon as reasonably possible or its run-time PM 508should be called for it too as soon as reasonably possible or its runtime PM
494status should be changed back to 'suspended' with the help of 509status should be changed back to 'suspended' with the help of
495pm_runtime_set_suspended(). 510pm_runtime_set_suspended().
496 511
497If the default initial run-time PM status of the device (i.e. 'suspended') 512If the default initial runtime PM status of the device (i.e. 'suspended')
498reflects the actual state of the device, its bus type's or its driver's 513reflects the actual state of the device, its bus type's or its driver's
499->probe() callback will likely need to wake it up using one of the PM core's 514->probe() callback will likely need to wake it up using one of the PM core's
500helper functions described in Section 4. In that case, pm_runtime_resume() 515helper functions described in Section 4. In that case, pm_runtime_resume()
501should be used. Of course, for this purpose the device's run-time PM has to be 516should be used. Of course, for this purpose the device's runtime PM has to be
502enabled earlier by calling pm_runtime_enable(). 517enabled earlier by calling pm_runtime_enable().
503 518
504If the device bus type's or driver's ->probe() callback runs 519If the device bus type's or driver's ->probe() callback runs
@@ -529,33 +544,33 @@ The user space can effectively disallow the driver of the device to power manage
529it at run time by changing the value of its /sys/devices/.../power/control 544it at run time by changing the value of its /sys/devices/.../power/control
530attribute to "on", which causes pm_runtime_forbid() to be called. In principle, 545attribute to "on", which causes pm_runtime_forbid() to be called. In principle,
531this mechanism may also be used by the driver to effectively turn off the 546this mechanism may also be used by the driver to effectively turn off the
532run-time power management of the device until the user space turns it on. 547runtime power management of the device until the user space turns it on.
533Namely, during the initialization the driver can make sure that the run-time PM 548Namely, during the initialization the driver can make sure that the runtime PM
534status of the device is 'active' and call pm_runtime_forbid(). It should be 549status of the device is 'active' and call pm_runtime_forbid(). It should be
535noted, however, that if the user space has already intentionally changed the 550noted, however, that if the user space has already intentionally changed the
536value of /sys/devices/.../power/control to "auto" to allow the driver to power 551value of /sys/devices/.../power/control to "auto" to allow the driver to power
537manage the device at run time, the driver may confuse it by using 552manage the device at run time, the driver may confuse it by using
538pm_runtime_forbid() this way. 553pm_runtime_forbid() this way.
539 554
5406. Run-time PM and System Sleep 5556. Runtime PM and System Sleep
541 556
542Run-time PM and system sleep (i.e., system suspend and hibernation, also known 557Runtime PM and system sleep (i.e., system suspend and hibernation, also known
543as suspend-to-RAM and suspend-to-disk) interact with each other in a couple of 558as suspend-to-RAM and suspend-to-disk) interact with each other in a couple of
544ways. If a device is active when a system sleep starts, everything is 559ways. If a device is active when a system sleep starts, everything is
545straightforward. But what should happen if the device is already suspended? 560straightforward. But what should happen if the device is already suspended?
546 561
547The device may have different wake-up settings for run-time PM and system sleep. 562The device may have different wake-up settings for runtime PM and system sleep.
548For example, remote wake-up may be enabled for run-time suspend but disallowed 563For example, remote wake-up may be enabled for runtime suspend but disallowed
549for system sleep (device_may_wakeup(dev) returns 'false'). When this happens, 564for system sleep (device_may_wakeup(dev) returns 'false'). When this happens,
550the subsystem-level system suspend callback is responsible for changing the 565the subsystem-level system suspend callback is responsible for changing the
551device's wake-up setting (it may leave that to the device driver's system 566device's wake-up setting (it may leave that to the device driver's system
552suspend routine). It may be necessary to resume the device and suspend it again 567suspend routine). It may be necessary to resume the device and suspend it again
553in order to do so. The same is true if the driver uses different power levels 568in order to do so. The same is true if the driver uses different power levels
554or other settings for run-time suspend and system sleep. 569or other settings for runtime suspend and system sleep.
555 570
556During system resume, devices generally should be brought back to full power, 571During system resume, the simplest approach is to bring all devices back to full
557even if they were suspended before the system sleep began. There are several 572power, even if they had been suspended before the system suspend began. There
558reasons for this, including: 573are several reasons for this, including:
559 574
560 * The device might need to switch power levels, wake-up settings, etc. 575 * The device might need to switch power levels, wake-up settings, etc.
561 576
@@ -570,18 +585,50 @@ reasons for this, including:
570 * The device might need to be reset. 585 * The device might need to be reset.
571 586
572 * Even though the device was suspended, if its usage counter was > 0 then most 587 * Even though the device was suspended, if its usage counter was > 0 then most
573 likely it would need a run-time resume in the near future anyway. 588 likely it would need a runtime resume in the near future anyway.
574
575 * Always going back to full power is simplest.
576 589
577If the device was suspended before the sleep began, then its run-time PM status 590If the device had been suspended before the system suspend began and it's
578will have to be updated to reflect the actual post-system sleep status. The way 591brought back to full power during resume, then its runtime PM status will have
579to do this is: 592to be updated to reflect the actual post-system sleep status. The way to do
593this is:
580 594
581 pm_runtime_disable(dev); 595 pm_runtime_disable(dev);
582 pm_runtime_set_active(dev); 596 pm_runtime_set_active(dev);
583 pm_runtime_enable(dev); 597 pm_runtime_enable(dev);
584 598
599The PM core always increments the runtime usage counter before calling the
600->suspend() callback and decrements it after calling the ->resume() callback.
601Hence disabling runtime PM temporarily like this will not cause any runtime
602suspend attempts to be permanently lost. If the usage count goes to zero
603following the return of the ->resume() callback, the ->runtime_idle() callback
604will be invoked as usual.
605
606On some systems, however, system sleep is not entered through a global firmware
607or hardware operation. Instead, all hardware components are put into low-power
608states directly by the kernel in a coordinated way. Then, the system sleep
609state effectively follows from the states the hardware components end up in
610and the system is woken up from that state by a hardware interrupt or a similar
611mechanism entirely under the kernel's control. As a result, the kernel never
612gives control away and the states of all devices during resume are precisely
613known to it. If that is the case and none of the situations listed above takes
614place (in particular, if the system is not waking up from hibernation), it may
615be more efficient to leave the devices that had been suspended before the system
616suspend began in the suspended state.
617
618The PM core does its best to reduce the probability of race conditions between
619the runtime PM and system suspend/resume (and hibernation) callbacks by carrying
620out the following operations:
621
622 * During system suspend it calls pm_runtime_get_noresume() and
623 pm_runtime_barrier() for every device right before executing the
624 subsystem-level .suspend() callback for it. In addition to that it calls
625 pm_runtime_disable() for every device right after executing the
626 subsystem-level .suspend() callback for it.
627
628 * During system resume it calls pm_runtime_enable() and pm_runtime_put_sync()
629 for every device right before and right after executing the subsystem-level
630 .resume() callback for it, respectively.
631
5857. Generic subsystem callbacks 6327. Generic subsystem callbacks
586 633
587Subsystems may wish to conserve code space by using the set of generic power 634Subsystems may wish to conserve code space by using the set of generic power
@@ -606,40 +653,68 @@ driver/base/power/generic_ops.c:
606 callback provided by its driver and return its result, or return 0 if not 653 callback provided by its driver and return its result, or return 0 if not
607 defined 654 defined
608 655
656 int pm_generic_suspend_noirq(struct device *dev);
657 - if pm_runtime_suspended(dev) returns "false", invoke the ->suspend_noirq()
658 callback provided by the device's driver and return its result, or return
659 0 if not defined
660
609 int pm_generic_resume(struct device *dev); 661 int pm_generic_resume(struct device *dev);
610 - invoke the ->resume() callback provided by the driver of this device and, 662 - invoke the ->resume() callback provided by the driver of this device and,
611 if successful, change the device's runtime PM status to 'active' 663 if successful, change the device's runtime PM status to 'active'
612 664
665 int pm_generic_resume_noirq(struct device *dev);
666 - invoke the ->resume_noirq() callback provided by the driver of this device
667
613 int pm_generic_freeze(struct device *dev); 668 int pm_generic_freeze(struct device *dev);
614 - if the device has not been suspended at run time, invoke the ->freeze() 669 - if the device has not been suspended at run time, invoke the ->freeze()
615 callback provided by its driver and return its result, or return 0 if not 670 callback provided by its driver and return its result, or return 0 if not
616 defined 671 defined
617 672
673 int pm_generic_freeze_noirq(struct device *dev);
674 - if pm_runtime_suspended(dev) returns "false", invoke the ->freeze_noirq()
675 callback provided by the device's driver and return its result, or return
676 0 if not defined
677
618 int pm_generic_thaw(struct device *dev); 678 int pm_generic_thaw(struct device *dev);
619 - if the device has not been suspended at run time, invoke the ->thaw() 679 - if the device has not been suspended at run time, invoke the ->thaw()
620 callback provided by its driver and return its result, or return 0 if not 680 callback provided by its driver and return its result, or return 0 if not
621 defined 681 defined
622 682
683 int pm_generic_thaw_noirq(struct device *dev);
684 - if pm_runtime_suspended(dev) returns "false", invoke the ->thaw_noirq()
685 callback provided by the device's driver and return its result, or return
686 0 if not defined
687
623 int pm_generic_poweroff(struct device *dev); 688 int pm_generic_poweroff(struct device *dev);
624 - if the device has not been suspended at run time, invoke the ->poweroff() 689 - if the device has not been suspended at run time, invoke the ->poweroff()
625 callback provided by its driver and return its result, or return 0 if not 690 callback provided by its driver and return its result, or return 0 if not
626 defined 691 defined
627 692
693 int pm_generic_poweroff_noirq(struct device *dev);
694 - if pm_runtime_suspended(dev) returns "false", run the ->poweroff_noirq()
695 callback provided by the device's driver and return its result, or return
696 0 if not defined
697
628 int pm_generic_restore(struct device *dev); 698 int pm_generic_restore(struct device *dev);
629 - invoke the ->restore() callback provided by the driver of this device and, 699 - invoke the ->restore() callback provided by the driver of this device and,
630 if successful, change the device's runtime PM status to 'active' 700 if successful, change the device's runtime PM status to 'active'
631 701
702 int pm_generic_restore_noirq(struct device *dev);
703 - invoke the ->restore_noirq() callback provided by the device's driver
704
632These functions can be assigned to the ->runtime_idle(), ->runtime_suspend(), 705These functions can be assigned to the ->runtime_idle(), ->runtime_suspend(),
633->runtime_resume(), ->suspend(), ->resume(), ->freeze(), ->thaw(), ->poweroff(), 706->runtime_resume(), ->suspend(), ->suspend_noirq(), ->resume(),
634or ->restore() callback pointers in the subsystem-level dev_pm_ops structures. 707->resume_noirq(), ->freeze(), ->freeze_noirq(), ->thaw(), ->thaw_noirq(),
708->poweroff(), ->poweroff_noirq(), ->restore(), ->restore_noirq() callback
709pointers in the subsystem-level dev_pm_ops structures.
635 710
636If a subsystem wishes to use all of them at the same time, it can simply assign 711If a subsystem wishes to use all of them at the same time, it can simply assign
637the GENERIC_SUBSYS_PM_OPS macro, defined in include/linux/pm.h, to its 712the GENERIC_SUBSYS_PM_OPS macro, defined in include/linux/pm.h, to its
638dev_pm_ops structure pointer. 713dev_pm_ops structure pointer.
639 714
640Device drivers that wish to use the same function as a system suspend, freeze, 715Device drivers that wish to use the same function as a system suspend, freeze,
641poweroff and run-time suspend callback, and similarly for system resume, thaw, 716poweroff and runtime suspend callback, and similarly for system resume, thaw,
642restore, and run-time resume, can achieve this with the help of the 717restore, and runtime resume, can achieve this with the help of the
643UNIVERSAL_DEV_PM_OPS macro defined in include/linux/pm.h (possibly setting its 718UNIVERSAL_DEV_PM_OPS macro defined in include/linux/pm.h (possibly setting its
644last argument to NULL). 719last argument to NULL).
645 720
@@ -649,7 +724,7 @@ Some "devices" are only logical sub-devices of their parent and cannot be
649power-managed on their own. (The prototype example is a USB interface. Entire 724power-managed on their own. (The prototype example is a USB interface. Entire
650USB devices can go into low-power mode or send wake-up requests, but neither is 725USB devices can go into low-power mode or send wake-up requests, but neither is
651possible for individual interfaces.) The drivers for these devices have no 726possible for individual interfaces.) The drivers for these devices have no
652need of run-time PM callbacks; if the callbacks did exist, ->runtime_suspend() 727need of runtime PM callbacks; if the callbacks did exist, ->runtime_suspend()
653and ->runtime_resume() would always return 0 without doing anything else and 728and ->runtime_resume() would always return 0 without doing anything else and
654->runtime_idle() would always call pm_runtime_suspend(). 729->runtime_idle() would always call pm_runtime_suspend().
655 730
@@ -657,7 +732,7 @@ Subsystems can tell the PM core about these devices by calling
657pm_runtime_no_callbacks(). This should be done after the device structure is 732pm_runtime_no_callbacks(). This should be done after the device structure is
658initialized and before it is registered (although after device registration is 733initialized and before it is registered (although after device registration is
659also okay). The routine will set the device's power.no_callbacks flag and 734also okay). The routine will set the device's power.no_callbacks flag and
660prevent the non-debugging run-time PM sysfs attributes from being created. 735prevent the non-debugging runtime PM sysfs attributes from being created.
661 736
662When power.no_callbacks is set, the PM core will not invoke the 737When power.no_callbacks is set, the PM core will not invoke the
663->runtime_idle(), ->runtime_suspend(), or ->runtime_resume() callbacks. 738->runtime_idle(), ->runtime_suspend(), or ->runtime_resume() callbacks.
@@ -665,7 +740,7 @@ Instead it will assume that suspends and resumes always succeed and that idle
665devices should be suspended. 740devices should be suspended.
666 741
667As a consequence, the PM core will never directly inform the device's subsystem 742As a consequence, the PM core will never directly inform the device's subsystem
668or driver about run-time power changes. Instead, the driver for the device's 743or driver about runtime power changes. Instead, the driver for the device's
669parent must take responsibility for telling the device's driver when the 744parent must take responsibility for telling the device's driver when the
670parent's power state changes. 745parent's power state changes.
671 746
@@ -676,13 +751,13 @@ A device should be put in a low-power state only when there's some reason to
676think it will remain in that state for a substantial time. A common heuristic 751think it will remain in that state for a substantial time. A common heuristic
677says that a device which hasn't been used for a while is liable to remain 752says that a device which hasn't been used for a while is liable to remain
678unused; following this advice, drivers should not allow devices to be suspended 753unused; following this advice, drivers should not allow devices to be suspended
679at run-time until they have been inactive for some minimum period. Even when 754at runtime until they have been inactive for some minimum period. Even when
680the heuristic ends up being non-optimal, it will still prevent devices from 755the heuristic ends up being non-optimal, it will still prevent devices from
681"bouncing" too rapidly between low-power and full-power states. 756"bouncing" too rapidly between low-power and full-power states.
682 757
683The term "autosuspend" is an historical remnant. It doesn't mean that the 758The term "autosuspend" is an historical remnant. It doesn't mean that the
684device is automatically suspended (the subsystem or driver still has to call 759device is automatically suspended (the subsystem or driver still has to call
685the appropriate PM routines); rather it means that run-time suspends will 760the appropriate PM routines); rather it means that runtime suspends will
686automatically be delayed until the desired period of inactivity has elapsed. 761automatically be delayed until the desired period of inactivity has elapsed.
687 762
688Inactivity is determined based on the power.last_busy field. Drivers should 763Inactivity is determined based on the power.last_busy field. Drivers should
@@ -708,6 +783,16 @@ will behave normally, not taking the autosuspend delay into account.
708Similarly, if the power.use_autosuspend field isn't set then the autosuspend 783Similarly, if the power.use_autosuspend field isn't set then the autosuspend
709helper functions will behave just like the non-autosuspend counterparts. 784helper functions will behave just like the non-autosuspend counterparts.
710 785
786Under some circumstances a driver or subsystem may want to prevent a device
787from autosuspending immediately, even though the usage counter is zero and the
788autosuspend delay time has expired. If the ->runtime_suspend() callback
789returns -EAGAIN or -EBUSY, and if the next autosuspend delay expiration time is
790in the future (as it normally would be if the callback invoked
791pm_runtime_mark_last_busy()), the PM core will automatically reschedule the
792autosuspend. The ->runtime_suspend() callback can't do this rescheduling
793itself because no suspend requests of any kind are accepted while the device is
794suspending (i.e., while the callback is running).
795
711The implementation is well suited for asynchronous use in interrupt contexts. 796The implementation is well suited for asynchronous use in interrupt contexts.
712However such use inevitably involves races, because the PM core can't 797However such use inevitably involves races, because the PM core can't
713synchronize ->runtime_suspend() callbacks with the arrival of I/O requests. 798synchronize ->runtime_suspend() callbacks with the arrival of I/O requests.