aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/power/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/power/main.c')
-rw-r--r--drivers/base/power/main.c98
1 files changed, 38 insertions, 60 deletions
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 69b4ddb7de3..fae72545898 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,50 +341,40 @@ 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
357 mutex_lock(&dpm_list_mtx);
360 list_for_each_entry(dev, &dpm_list, power.entry) 358 list_for_each_entry(dev, &dpm_list, power.entry)
361 if (dev->power.status > DPM_OFF) { 359 if (dev->power.status > DPM_OFF) {
362 int error; 360 int error;
363 361
364 dev->power.status = DPM_OFF; 362 dev->power.status = DPM_OFF;
365 error = resume_device_noirq(dev, state); 363 error = device_resume_noirq(dev, state);
366 if (error) 364 if (error)
367 pm_dev_err(dev, state, " early", error); 365 pm_dev_err(dev, state, " early", error);
368 } 366 }
369} 367 mutex_unlock(&dpm_list_mtx);
370
371/**
372 * device_power_up - Turn on all devices that need special attention.
373 * @state: PM transition of the system being carried out.
374 *
375 * Call the "early" resume handlers and enable device drivers to receive
376 * interrupts.
377 */
378void device_power_up(pm_message_t state)
379{
380 dpm_power_up(state);
381 resume_device_irqs(); 368 resume_device_irqs();
382} 369}
383EXPORT_SYMBOL_GPL(device_power_up); 370EXPORT_SYMBOL_GPL(dpm_resume_noirq);
384 371
385/** 372/**
386 * resume_device - Restore state for one device. 373 * device_resume - Restore state for one device.
387 * @dev: Device. 374 * @dev: Device.
388 * @state: PM transition of the system being carried out. 375 * @state: PM transition of the system being carried out.
389 */ 376 */
390static int resume_device(struct device *dev, pm_message_t state) 377static int device_resume(struct device *dev, pm_message_t state)
391{ 378{
392 int error = 0; 379 int error = 0;
393 380
@@ -412,9 +399,6 @@ static int resume_device(struct device *dev, pm_message_t state)
412 if (dev->type->pm) { 399 if (dev->type->pm) {
413 pm_dev_dbg(dev, state, "type "); 400 pm_dev_dbg(dev, state, "type ");
414 error = pm_op(dev, dev->type->pm, state); 401 error = pm_op(dev, dev->type->pm, state);
415 } else if (dev->type->resume) {
416 pm_dev_dbg(dev, state, "legacy type ");
417 error = dev->type->resume(dev);
418 } 402 }
419 if (error) 403 if (error)
420 goto End; 404 goto End;
@@ -460,7 +444,7 @@ static void dpm_resume(pm_message_t state)
460 dev->power.status = DPM_RESUMING; 444 dev->power.status = DPM_RESUMING;
461 mutex_unlock(&dpm_list_mtx); 445 mutex_unlock(&dpm_list_mtx);
462 446
463 error = resume_device(dev, state); 447 error = device_resume(dev, state);
464 448
465 mutex_lock(&dpm_list_mtx); 449 mutex_lock(&dpm_list_mtx);
466 if (error) 450 if (error)
@@ -478,11 +462,11 @@ static void dpm_resume(pm_message_t state)
478} 462}
479 463
480/** 464/**
481 * complete_device - Complete a PM transition for given device 465 * device_complete - Complete a PM transition for given device
482 * @dev: Device. 466 * @dev: Device.
483 * @state: PM transition of the system being carried out. 467 * @state: PM transition of the system being carried out.
484 */ 468 */
485static void complete_device(struct device *dev, pm_message_t state) 469static void device_complete(struct device *dev, pm_message_t state)
486{ 470{
487 down(&dev->sem); 471 down(&dev->sem);
488 472
@@ -525,7 +509,7 @@ static void dpm_complete(pm_message_t state)
525 dev->power.status = DPM_ON; 509 dev->power.status = DPM_ON;
526 mutex_unlock(&dpm_list_mtx); 510 mutex_unlock(&dpm_list_mtx);
527 511
528 complete_device(dev, state); 512 device_complete(dev, state);
529 513
530 mutex_lock(&dpm_list_mtx); 514 mutex_lock(&dpm_list_mtx);
531 } 515 }
@@ -538,19 +522,19 @@ static void dpm_complete(pm_message_t state)
538} 522}
539 523
540/** 524/**
541 * device_resume - Restore state of each device in system. 525 * dpm_resume_end - Restore state of each device in system.
542 * @state: PM transition of the system being carried out. 526 * @state: PM transition of the system being carried out.
543 * 527 *
544 * Resume all the devices, unlock them all, and allow new 528 * Resume all the devices, unlock them all, and allow new
545 * devices to be registered once again. 529 * devices to be registered once again.
546 */ 530 */
547void device_resume(pm_message_t state) 531void dpm_resume_end(pm_message_t state)
548{ 532{
549 might_sleep(); 533 might_sleep();
550 dpm_resume(state); 534 dpm_resume(state);
551 dpm_complete(state); 535 dpm_complete(state);
552} 536}
553EXPORT_SYMBOL_GPL(device_resume); 537EXPORT_SYMBOL_GPL(dpm_resume_end);
554 538
555 539
556/*------------------------- Suspend routines -------------------------*/ 540/*------------------------- Suspend routines -------------------------*/
@@ -575,13 +559,13 @@ static pm_message_t resume_event(pm_message_t sleep_state)
575} 559}
576 560
577/** 561/**
578 * suspend_device_noirq - Shut down one device (late suspend). 562 * device_suspend_noirq - Shut down one device (late suspend).
579 * @dev: Device. 563 * @dev: Device.
580 * @state: PM transition of the system being carried out. 564 * @state: PM transition of the system being carried out.
581 * 565 *
582 * 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.
583 */ 567 */
584static int suspend_device_noirq(struct device *dev, pm_message_t state) 568static int device_suspend_noirq(struct device *dev, pm_message_t state)
585{ 569{
586 int error = 0; 570 int error = 0;
587 571
@@ -591,49 +575,47 @@ static int suspend_device_noirq(struct device *dev, pm_message_t state)
591 if (dev->bus->pm) { 575 if (dev->bus->pm) {
592 pm_dev_dbg(dev, state, "LATE "); 576 pm_dev_dbg(dev, state, "LATE ");
593 error = pm_noirq_op(dev, dev->bus->pm, state); 577 error = pm_noirq_op(dev, dev->bus->pm, state);
594 } else if (dev->bus->suspend_late) {
595 pm_dev_dbg(dev, state, "legacy LATE ");
596 error = dev->bus->suspend_late(dev, state);
597 suspend_report_result(dev->bus->suspend_late, error);
598 } 578 }
599 return error; 579 return error;
600} 580}
601 581
602/** 582/**
603 * device_power_down - Shut down special devices. 583 * dpm_suspend_noirq - Power down all regular (non-sysdev) devices.
604 * @state: PM transition of the system being carried out. 584 * @state: PM transition of the system being carried out.
605 * 585 *
606 * Prevent device drivers from receiving interrupts and call the "late" 586 * Prevent device drivers from receiving interrupts and call the "noirq"
607 * suspend handlers. 587 * suspend handlers.
608 * 588 *
609 * Must be called under dpm_list_mtx. 589 * Must be called under dpm_list_mtx.
610 */ 590 */
611int device_power_down(pm_message_t state) 591int dpm_suspend_noirq(pm_message_t state)
612{ 592{
613 struct device *dev; 593 struct device *dev;
614 int error = 0; 594 int error = 0;
615 595
616 suspend_device_irqs(); 596 suspend_device_irqs();
597 mutex_lock(&dpm_list_mtx);
617 list_for_each_entry_reverse(dev, &dpm_list, power.entry) { 598 list_for_each_entry_reverse(dev, &dpm_list, power.entry) {
618 error = suspend_device_noirq(dev, state); 599 error = device_suspend_noirq(dev, state);
619 if (error) { 600 if (error) {
620 pm_dev_err(dev, state, " late", error); 601 pm_dev_err(dev, state, " late", error);
621 break; 602 break;
622 } 603 }
623 dev->power.status = DPM_OFF_IRQ; 604 dev->power.status = DPM_OFF_IRQ;
624 } 605 }
606 mutex_unlock(&dpm_list_mtx);
625 if (error) 607 if (error)
626 device_power_up(resume_event(state)); 608 dpm_resume_noirq(resume_event(state));
627 return error; 609 return error;
628} 610}
629EXPORT_SYMBOL_GPL(device_power_down); 611EXPORT_SYMBOL_GPL(dpm_suspend_noirq);
630 612
631/** 613/**
632 * suspend_device - Save state of one device. 614 * device_suspend - Save state of one device.
633 * @dev: Device. 615 * @dev: Device.
634 * @state: PM transition of the system being carried out. 616 * @state: PM transition of the system being carried out.
635 */ 617 */
636static int suspend_device(struct device *dev, pm_message_t state) 618static int device_suspend(struct device *dev, pm_message_t state)
637{ 619{
638 int error = 0; 620 int error = 0;
639 621
@@ -656,10 +638,6 @@ static int suspend_device(struct device *dev, pm_message_t state)
656 if (dev->type->pm) { 638 if (dev->type->pm) {
657 pm_dev_dbg(dev, state, "type "); 639 pm_dev_dbg(dev, state, "type ");
658 error = pm_op(dev, dev->type->pm, state); 640 error = pm_op(dev, dev->type->pm, state);
659 } else if (dev->type->suspend) {
660 pm_dev_dbg(dev, state, "legacy type ");
661 error = dev->type->suspend(dev, state);
662 suspend_report_result(dev->type->suspend, error);
663 } 641 }
664 if (error) 642 if (error)
665 goto End; 643 goto End;
@@ -700,7 +678,7 @@ static int dpm_suspend(pm_message_t state)
700 get_device(dev); 678 get_device(dev);
701 mutex_unlock(&dpm_list_mtx); 679 mutex_unlock(&dpm_list_mtx);
702 680
703 error = suspend_device(dev, state); 681 error = device_suspend(dev, state);
704 682
705 mutex_lock(&dpm_list_mtx); 683 mutex_lock(&dpm_list_mtx);
706 if (error) { 684 if (error) {
@@ -719,11 +697,11 @@ static int dpm_suspend(pm_message_t state)
719} 697}
720 698
721/** 699/**
722 * prepare_device - Execute the ->prepare() callback(s) for given device. 700 * device_prepare - Execute the ->prepare() callback(s) for given device.
723 * @dev: Device. 701 * @dev: Device.
724 * @state: PM transition of the system being carried out. 702 * @state: PM transition of the system being carried out.
725 */ 703 */
726static int prepare_device(struct device *dev, pm_message_t state) 704static int device_prepare(struct device *dev, pm_message_t state)
727{ 705{
728 int error = 0; 706 int error = 0;
729 707
@@ -777,7 +755,7 @@ static int dpm_prepare(pm_message_t state)
777 dev->power.status = DPM_PREPARING; 755 dev->power.status = DPM_PREPARING;
778 mutex_unlock(&dpm_list_mtx); 756 mutex_unlock(&dpm_list_mtx);
779 757
780 error = prepare_device(dev, state); 758 error = device_prepare(dev, state);
781 759
782 mutex_lock(&dpm_list_mtx); 760 mutex_lock(&dpm_list_mtx);
783 if (error) { 761 if (error) {
@@ -803,12 +781,12 @@ static int dpm_prepare(pm_message_t state)
803} 781}
804 782
805/** 783/**
806 * device_suspend - Save state and stop all devices in system. 784 * dpm_suspend_start - Save state and stop all devices in system.
807 * @state: PM transition of the system being carried out. 785 * @state: PM transition of the system being carried out.
808 * 786 *
809 * Prepare and suspend all devices. 787 * Prepare and suspend all devices.
810 */ 788 */
811int device_suspend(pm_message_t state) 789int dpm_suspend_start(pm_message_t state)
812{ 790{
813 int error; 791 int error;
814 792
@@ -818,7 +796,7 @@ int device_suspend(pm_message_t state)
818 error = dpm_suspend(state); 796 error = dpm_suspend(state);
819 return error; 797 return error;
820} 798}
821EXPORT_SYMBOL_GPL(device_suspend); 799EXPORT_SYMBOL_GPL(dpm_suspend_start);
822 800
823void __suspend_report_result(const char *function, void *fn, int ret) 801void __suspend_report_result(const char *function, void *fn, int ret)
824{ 802{