aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/power/main.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-06-12 16:17:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-12 16:17:27 -0400
commit947ec0b0c1e7e80eef4fe64f7763a06d0cf04d2e (patch)
tree29547b6975d58c3b252f08dc6c2dbda3b9adfa88 /drivers/base/power/main.c
parentc53567ad4528b6efefc3fc22a354d20f6226a098 (diff)
parent5818a6e2519b34cd6d0220d89f5729ab2725e1bf (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/suspend-2.6: PM: Add empty suspend/resume device irq functions PM/Hibernate: Move NVS routines into a seperate file (v2). PM/Hibernate: Rename disk.c to hibernate.c PM: Separate suspend to RAM functionality from core Driver Core: Rework platform suspend/resume, print warning PM: Remove device_type suspend()/resume() PM/Hibernate: Move memory shrinking to snapshot.c (rev. 2) PM/Suspend: Do not shrink memory before suspend PM: Remove bus_type suspend_late()/resume_early() V2 PM core: rename suspend and resume functions PM: Rename device_power_down/up() PM: Remove unused asm/suspend.h x86: unify power/cpu_(32|64).c x86: unify power/cpu_(32|64) copyright notes x86: unify power/cpu_(32|64) regarding restoring processor state x86: unify power/cpu_(32|64) regarding saving processor state x86: unify power/cpu_(32|64) global variables x86: unify power/cpu_(32|64) headers PM: Warn if interrupts are enabled during suspend-resume of sysdevs PM/ACPI/x86: Fix sparse warning in arch/x86/kernel/acpi/sleep.c
Diffstat (limited to 'drivers/base/power/main.c')
-rw-r--r--drivers/base/power/main.c94
1 files changed, 34 insertions, 60 deletions
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 3e4bc699bc0f..fae725458981 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -315,13 +315,13 @@ static void pm_dev_err(struct device *dev, pm_message_t state, char *info,
315/*------------------------- Resume routines -------------------------*/ 315/*------------------------- Resume routines -------------------------*/
316 316
317/** 317/**
318 * resume_device_noirq - Power on one device (early resume). 318 * device_resume_noirq - Power on one device (early resume).
319 * @dev: Device. 319 * @dev: Device.
320 * @state: PM transition of the system being carried out. 320 * @state: PM transition of the system being carried out.
321 * 321 *
322 * Must be called with interrupts disabled. 322 * Must be called with interrupts disabled.
323 */ 323 */
324static int resume_device_noirq(struct device *dev, pm_message_t state) 324static int device_resume_noirq(struct device *dev, pm_message_t state)
325{ 325{
326 int error = 0; 326 int error = 0;
327 327
@@ -334,9 +334,6 @@ static int resume_device_noirq(struct device *dev, pm_message_t state)
334 if (dev->bus->pm) { 334 if (dev->bus->pm) {
335 pm_dev_dbg(dev, state, "EARLY "); 335 pm_dev_dbg(dev, state, "EARLY ");
336 error = pm_noirq_op(dev, dev->bus->pm, state); 336 error = pm_noirq_op(dev, dev->bus->pm, state);
337 } else if (dev->bus->resume_early) {
338 pm_dev_dbg(dev, state, "legacy EARLY ");
339 error = dev->bus->resume_early(dev);
340 } 337 }
341 End: 338 End:
342 TRACE_RESUME(error); 339 TRACE_RESUME(error);
@@ -344,16 +341,16 @@ static int resume_device_noirq(struct device *dev, pm_message_t state)
344} 341}
345 342
346/** 343/**
347 * dpm_power_up - Power on all regular (non-sysdev) devices. 344 * dpm_resume_noirq - Power on all regular (non-sysdev) devices.
348 * @state: PM transition of the system being carried out. 345 * @state: PM transition of the system being carried out.
349 * 346 *
350 * Execute the appropriate "noirq resume" callback for all devices marked 347 * Call the "noirq" resume handlers for all devices marked as
351 * as DPM_OFF_IRQ. 348 * DPM_OFF_IRQ and enable device drivers to receive interrupts.
352 * 349 *
353 * Must be called under dpm_list_mtx. Device drivers should not receive 350 * Must be called under dpm_list_mtx. Device drivers should not receive
354 * interrupts while it's being executed. 351 * interrupts while it's being executed.
355 */ 352 */
356static void dpm_power_up(pm_message_t state) 353void dpm_resume_noirq(pm_message_t state)
357{ 354{
358 struct device *dev; 355 struct device *dev;
359 356
@@ -363,33 +360,21 @@ static void dpm_power_up(pm_message_t state)
363 int error; 360 int error;
364 361
365 dev->power.status = DPM_OFF; 362 dev->power.status = DPM_OFF;
366 error = resume_device_noirq(dev, state); 363 error = device_resume_noirq(dev, state);
367 if (error) 364 if (error)
368 pm_dev_err(dev, state, " early", error); 365 pm_dev_err(dev, state, " early", error);
369 } 366 }
370 mutex_unlock(&dpm_list_mtx); 367 mutex_unlock(&dpm_list_mtx);
371}
372
373/**
374 * device_power_up - Turn on all devices that need special attention.
375 * @state: PM transition of the system being carried out.
376 *
377 * Call the "early" resume handlers and enable device drivers to receive
378 * interrupts.
379 */
380void device_power_up(pm_message_t state)
381{
382 dpm_power_up(state);
383 resume_device_irqs(); 368 resume_device_irqs();
384} 369}
385EXPORT_SYMBOL_GPL(device_power_up); 370EXPORT_SYMBOL_GPL(dpm_resume_noirq);
386 371
387/** 372/**
388 * resume_device - Restore state for one device. 373 * device_resume - Restore state for one device.
389 * @dev: Device. 374 * @dev: Device.
390 * @state: PM transition of the system being carried out. 375 * @state: PM transition of the system being carried out.
391 */ 376 */
392static int resume_device(struct device *dev, pm_message_t state) 377static int device_resume(struct device *dev, pm_message_t state)
393{ 378{
394 int error = 0; 379 int error = 0;
395 380
@@ -414,9 +399,6 @@ static int resume_device(struct device *dev, pm_message_t state)
414 if (dev->type->pm) { 399 if (dev->type->pm) {
415 pm_dev_dbg(dev, state, "type "); 400 pm_dev_dbg(dev, state, "type ");
416 error = pm_op(dev, dev->type->pm, state); 401 error = pm_op(dev, dev->type->pm, state);
417 } else if (dev->type->resume) {
418 pm_dev_dbg(dev, state, "legacy type ");
419 error = dev->type->resume(dev);
420 } 402 }
421 if (error) 403 if (error)
422 goto End; 404 goto End;
@@ -462,7 +444,7 @@ static void dpm_resume(pm_message_t state)
462 dev->power.status = DPM_RESUMING; 444 dev->power.status = DPM_RESUMING;
463 mutex_unlock(&dpm_list_mtx); 445 mutex_unlock(&dpm_list_mtx);
464 446
465 error = resume_device(dev, state); 447 error = device_resume(dev, state);
466 448
467 mutex_lock(&dpm_list_mtx); 449 mutex_lock(&dpm_list_mtx);
468 if (error) 450 if (error)
@@ -480,11 +462,11 @@ static void dpm_resume(pm_message_t state)
480} 462}
481 463
482/** 464/**
483 * complete_device - Complete a PM transition for given device 465 * device_complete - Complete a PM transition for given device
484 * @dev: Device. 466 * @dev: Device.
485 * @state: PM transition of the system being carried out. 467 * @state: PM transition of the system being carried out.
486 */ 468 */
487static void complete_device(struct device *dev, pm_message_t state) 469static void device_complete(struct device *dev, pm_message_t state)
488{ 470{
489 down(&dev->sem); 471 down(&dev->sem);
490 472
@@ -527,7 +509,7 @@ static void dpm_complete(pm_message_t state)
527 dev->power.status = DPM_ON; 509 dev->power.status = DPM_ON;
528 mutex_unlock(&dpm_list_mtx); 510 mutex_unlock(&dpm_list_mtx);
529 511
530 complete_device(dev, state); 512 device_complete(dev, state);
531 513
532 mutex_lock(&dpm_list_mtx); 514 mutex_lock(&dpm_list_mtx);
533 } 515 }
@@ -540,19 +522,19 @@ static void dpm_complete(pm_message_t state)
540} 522}
541 523
542/** 524/**
543 * device_resume - Restore state of each device in system. 525 * dpm_resume_end - Restore state of each device in system.
544 * @state: PM transition of the system being carried out. 526 * @state: PM transition of the system being carried out.
545 * 527 *
546 * Resume all the devices, unlock them all, and allow new 528 * Resume all the devices, unlock them all, and allow new
547 * devices to be registered once again. 529 * devices to be registered once again.
548 */ 530 */
549void device_resume(pm_message_t state) 531void dpm_resume_end(pm_message_t state)
550{ 532{
551 might_sleep(); 533 might_sleep();
552 dpm_resume(state); 534 dpm_resume(state);
553 dpm_complete(state); 535 dpm_complete(state);
554} 536}
555EXPORT_SYMBOL_GPL(device_resume); 537EXPORT_SYMBOL_GPL(dpm_resume_end);
556 538
557 539
558/*------------------------- Suspend routines -------------------------*/ 540/*------------------------- Suspend routines -------------------------*/
@@ -577,13 +559,13 @@ static pm_message_t resume_event(pm_message_t sleep_state)
577} 559}
578 560
579/** 561/**
580 * suspend_device_noirq - Shut down one device (late suspend). 562 * device_suspend_noirq - Shut down one device (late suspend).
581 * @dev: Device. 563 * @dev: Device.
582 * @state: PM transition of the system being carried out. 564 * @state: PM transition of the system being carried out.
583 * 565 *
584 * This is called with interrupts off and only a single CPU running. 566 * This is called with interrupts off and only a single CPU running.
585 */ 567 */
586static int suspend_device_noirq(struct device *dev, pm_message_t state) 568static int device_suspend_noirq(struct device *dev, pm_message_t state)
587{ 569{
588 int error = 0; 570 int error = 0;
589 571
@@ -593,24 +575,20 @@ static int suspend_device_noirq(struct device *dev, pm_message_t state)
593 if (dev->bus->pm) { 575 if (dev->bus->pm) {
594 pm_dev_dbg(dev, state, "LATE "); 576 pm_dev_dbg(dev, state, "LATE ");
595 error = pm_noirq_op(dev, dev->bus->pm, state); 577 error = pm_noirq_op(dev, dev->bus->pm, state);
596 } else if (dev->bus->suspend_late) {
597 pm_dev_dbg(dev, state, "legacy LATE ");
598 error = dev->bus->suspend_late(dev, state);
599 suspend_report_result(dev->bus->suspend_late, error);
600 } 578 }
601 return error; 579 return error;
602} 580}
603 581
604/** 582/**
605 * device_power_down - Shut down special devices. 583 * dpm_suspend_noirq - Power down all regular (non-sysdev) devices.
606 * @state: PM transition of the system being carried out. 584 * @state: PM transition of the system being carried out.
607 * 585 *
608 * Prevent device drivers from receiving interrupts and call the "late" 586 * Prevent device drivers from receiving interrupts and call the "noirq"
609 * suspend handlers. 587 * suspend handlers.
610 * 588 *
611 * Must be called under dpm_list_mtx. 589 * Must be called under dpm_list_mtx.
612 */ 590 */
613int device_power_down(pm_message_t state) 591int dpm_suspend_noirq(pm_message_t state)
614{ 592{
615 struct device *dev; 593 struct device *dev;
616 int error = 0; 594 int error = 0;
@@ -618,7 +596,7 @@ int device_power_down(pm_message_t state)
618 suspend_device_irqs(); 596 suspend_device_irqs();
619 mutex_lock(&dpm_list_mtx); 597 mutex_lock(&dpm_list_mtx);
620 list_for_each_entry_reverse(dev, &dpm_list, power.entry) { 598 list_for_each_entry_reverse(dev, &dpm_list, power.entry) {
621 error = suspend_device_noirq(dev, state); 599 error = device_suspend_noirq(dev, state);
622 if (error) { 600 if (error) {
623 pm_dev_err(dev, state, " late", error); 601 pm_dev_err(dev, state, " late", error);
624 break; 602 break;
@@ -627,17 +605,17 @@ int device_power_down(pm_message_t state)
627 } 605 }
628 mutex_unlock(&dpm_list_mtx); 606 mutex_unlock(&dpm_list_mtx);
629 if (error) 607 if (error)
630 device_power_up(resume_event(state)); 608 dpm_resume_noirq(resume_event(state));
631 return error; 609 return error;
632} 610}
633EXPORT_SYMBOL_GPL(device_power_down); 611EXPORT_SYMBOL_GPL(dpm_suspend_noirq);
634 612
635/** 613/**
636 * suspend_device - Save state of one device. 614 * device_suspend - Save state of one device.
637 * @dev: Device. 615 * @dev: Device.
638 * @state: PM transition of the system being carried out. 616 * @state: PM transition of the system being carried out.
639 */ 617 */
640static int suspend_device(struct device *dev, pm_message_t state) 618static int device_suspend(struct device *dev, pm_message_t state)
641{ 619{
642 int error = 0; 620 int error = 0;
643 621
@@ -660,10 +638,6 @@ static int suspend_device(struct device *dev, pm_message_t state)
660 if (dev->type->pm) { 638 if (dev->type->pm) {
661 pm_dev_dbg(dev, state, "type "); 639 pm_dev_dbg(dev, state, "type ");
662 error = pm_op(dev, dev->type->pm, state); 640 error = pm_op(dev, dev->type->pm, state);
663 } else if (dev->type->suspend) {
664 pm_dev_dbg(dev, state, "legacy type ");
665 error = dev->type->suspend(dev, state);
666 suspend_report_result(dev->type->suspend, error);
667 } 641 }
668 if (error) 642 if (error)
669 goto End; 643 goto End;
@@ -704,7 +678,7 @@ static int dpm_suspend(pm_message_t state)
704 get_device(dev); 678 get_device(dev);
705 mutex_unlock(&dpm_list_mtx); 679 mutex_unlock(&dpm_list_mtx);
706 680
707 error = suspend_device(dev, state); 681 error = device_suspend(dev, state);
708 682
709 mutex_lock(&dpm_list_mtx); 683 mutex_lock(&dpm_list_mtx);
710 if (error) { 684 if (error) {
@@ -723,11 +697,11 @@ static int dpm_suspend(pm_message_t state)
723} 697}
724 698
725/** 699/**
726 * prepare_device - Execute the ->prepare() callback(s) for given device. 700 * device_prepare - Execute the ->prepare() callback(s) for given device.
727 * @dev: Device. 701 * @dev: Device.
728 * @state: PM transition of the system being carried out. 702 * @state: PM transition of the system being carried out.
729 */ 703 */
730static int prepare_device(struct device *dev, pm_message_t state) 704static int device_prepare(struct device *dev, pm_message_t state)
731{ 705{
732 int error = 0; 706 int error = 0;
733 707
@@ -781,7 +755,7 @@ static int dpm_prepare(pm_message_t state)
781 dev->power.status = DPM_PREPARING; 755 dev->power.status = DPM_PREPARING;
782 mutex_unlock(&dpm_list_mtx); 756 mutex_unlock(&dpm_list_mtx);
783 757
784 error = prepare_device(dev, state); 758 error = device_prepare(dev, state);
785 759
786 mutex_lock(&dpm_list_mtx); 760 mutex_lock(&dpm_list_mtx);
787 if (error) { 761 if (error) {
@@ -807,12 +781,12 @@ static int dpm_prepare(pm_message_t state)
807} 781}
808 782
809/** 783/**
810 * device_suspend - Save state and stop all devices in system. 784 * dpm_suspend_start - Save state and stop all devices in system.
811 * @state: PM transition of the system being carried out. 785 * @state: PM transition of the system being carried out.
812 * 786 *
813 * Prepare and suspend all devices. 787 * Prepare and suspend all devices.
814 */ 788 */
815int device_suspend(pm_message_t state) 789int dpm_suspend_start(pm_message_t state)
816{ 790{
817 int error; 791 int error;
818 792
@@ -822,7 +796,7 @@ int device_suspend(pm_message_t state)
822 error = dpm_suspend(state); 796 error = dpm_suspend(state);
823 return error; 797 return error;
824} 798}
825EXPORT_SYMBOL_GPL(device_suspend); 799EXPORT_SYMBOL_GPL(dpm_suspend_start);
826 800
827void __suspend_report_result(const char *function, void *fn, int ret) 801void __suspend_report_result(const char *function, void *fn, int ret)
828{ 802{