diff options
Diffstat (limited to 'drivers/base/power/main.c')
-rw-r--r-- | drivers/base/power/main.c | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index abe3ab709e87..aa6320207745 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -426,10 +426,8 @@ static int device_resume_noirq(struct device *dev, pm_message_t state) | |||
426 | 426 | ||
427 | if (dev->pwr_domain) { | 427 | if (dev->pwr_domain) { |
428 | pm_dev_dbg(dev, state, "EARLY power domain "); | 428 | pm_dev_dbg(dev, state, "EARLY power domain "); |
429 | pm_noirq_op(dev, &dev->pwr_domain->ops, state); | 429 | error = pm_noirq_op(dev, &dev->pwr_domain->ops, state); |
430 | } | 430 | } else if (dev->type && dev->type->pm) { |
431 | |||
432 | if (dev->type && dev->type->pm) { | ||
433 | pm_dev_dbg(dev, state, "EARLY type "); | 431 | pm_dev_dbg(dev, state, "EARLY type "); |
434 | error = pm_noirq_op(dev, dev->type->pm, state); | 432 | error = pm_noirq_op(dev, dev->type->pm, state); |
435 | } else if (dev->class && dev->class->pm) { | 433 | } else if (dev->class && dev->class->pm) { |
@@ -517,7 +515,8 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
517 | 515 | ||
518 | if (dev->pwr_domain) { | 516 | if (dev->pwr_domain) { |
519 | pm_dev_dbg(dev, state, "power domain "); | 517 | pm_dev_dbg(dev, state, "power domain "); |
520 | pm_op(dev, &dev->pwr_domain->ops, state); | 518 | error = pm_op(dev, &dev->pwr_domain->ops, state); |
519 | goto End; | ||
521 | } | 520 | } |
522 | 521 | ||
523 | if (dev->type && dev->type->pm) { | 522 | if (dev->type && dev->type->pm) { |
@@ -580,11 +579,13 @@ static bool is_async(struct device *dev) | |||
580 | * Execute the appropriate "resume" callback for all devices whose status | 579 | * Execute the appropriate "resume" callback for all devices whose status |
581 | * indicates that they are suspended. | 580 | * indicates that they are suspended. |
582 | */ | 581 | */ |
583 | static void dpm_resume(pm_message_t state) | 582 | void dpm_resume(pm_message_t state) |
584 | { | 583 | { |
585 | struct device *dev; | 584 | struct device *dev; |
586 | ktime_t starttime = ktime_get(); | 585 | ktime_t starttime = ktime_get(); |
587 | 586 | ||
587 | might_sleep(); | ||
588 | |||
588 | mutex_lock(&dpm_list_mtx); | 589 | mutex_lock(&dpm_list_mtx); |
589 | pm_transition = state; | 590 | pm_transition = state; |
590 | async_error = 0; | 591 | async_error = 0; |
@@ -629,12 +630,11 @@ static void device_complete(struct device *dev, pm_message_t state) | |||
629 | { | 630 | { |
630 | device_lock(dev); | 631 | device_lock(dev); |
631 | 632 | ||
632 | if (dev->pwr_domain && dev->pwr_domain->ops.complete) { | 633 | if (dev->pwr_domain) { |
633 | pm_dev_dbg(dev, state, "completing power domain "); | 634 | pm_dev_dbg(dev, state, "completing power domain "); |
634 | dev->pwr_domain->ops.complete(dev); | 635 | if (dev->pwr_domain->ops.complete) |
635 | } | 636 | dev->pwr_domain->ops.complete(dev); |
636 | 637 | } else if (dev->type && dev->type->pm) { | |
637 | if (dev->type && dev->type->pm) { | ||
638 | pm_dev_dbg(dev, state, "completing type "); | 638 | pm_dev_dbg(dev, state, "completing type "); |
639 | if (dev->type->pm->complete) | 639 | if (dev->type->pm->complete) |
640 | dev->type->pm->complete(dev); | 640 | dev->type->pm->complete(dev); |
@@ -658,10 +658,12 @@ static void device_complete(struct device *dev, pm_message_t state) | |||
658 | * Execute the ->complete() callbacks for all devices whose PM status is not | 658 | * Execute the ->complete() callbacks for all devices whose PM status is not |
659 | * DPM_ON (this allows new devices to be registered). | 659 | * DPM_ON (this allows new devices to be registered). |
660 | */ | 660 | */ |
661 | static void dpm_complete(pm_message_t state) | 661 | void dpm_complete(pm_message_t state) |
662 | { | 662 | { |
663 | struct list_head list; | 663 | struct list_head list; |
664 | 664 | ||
665 | might_sleep(); | ||
666 | |||
665 | INIT_LIST_HEAD(&list); | 667 | INIT_LIST_HEAD(&list); |
666 | mutex_lock(&dpm_list_mtx); | 668 | mutex_lock(&dpm_list_mtx); |
667 | while (!list_empty(&dpm_prepared_list)) { | 669 | while (!list_empty(&dpm_prepared_list)) { |
@@ -690,7 +692,6 @@ static void dpm_complete(pm_message_t state) | |||
690 | */ | 692 | */ |
691 | void dpm_resume_end(pm_message_t state) | 693 | void dpm_resume_end(pm_message_t state) |
692 | { | 694 | { |
693 | might_sleep(); | ||
694 | dpm_resume(state); | 695 | dpm_resume(state); |
695 | dpm_complete(state); | 696 | dpm_complete(state); |
696 | } | 697 | } |
@@ -732,7 +733,12 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state) | |||
732 | { | 733 | { |
733 | int error; | 734 | int error; |
734 | 735 | ||
735 | if (dev->type && dev->type->pm) { | 736 | if (dev->pwr_domain) { |
737 | pm_dev_dbg(dev, state, "LATE power domain "); | ||
738 | error = pm_noirq_op(dev, &dev->pwr_domain->ops, state); | ||
739 | if (error) | ||
740 | return error; | ||
741 | } else if (dev->type && dev->type->pm) { | ||
736 | pm_dev_dbg(dev, state, "LATE type "); | 742 | pm_dev_dbg(dev, state, "LATE type "); |
737 | error = pm_noirq_op(dev, dev->type->pm, state); | 743 | error = pm_noirq_op(dev, dev->type->pm, state); |
738 | if (error) | 744 | if (error) |
@@ -749,11 +755,6 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state) | |||
749 | return error; | 755 | return error; |
750 | } | 756 | } |
751 | 757 | ||
752 | if (dev->pwr_domain) { | ||
753 | pm_dev_dbg(dev, state, "LATE power domain "); | ||
754 | pm_noirq_op(dev, &dev->pwr_domain->ops, state); | ||
755 | } | ||
756 | |||
757 | return 0; | 758 | return 0; |
758 | } | 759 | } |
759 | 760 | ||
@@ -841,21 +842,27 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
841 | goto End; | 842 | goto End; |
842 | } | 843 | } |
843 | 844 | ||
845 | if (dev->pwr_domain) { | ||
846 | pm_dev_dbg(dev, state, "power domain "); | ||
847 | error = pm_op(dev, &dev->pwr_domain->ops, state); | ||
848 | goto End; | ||
849 | } | ||
850 | |||
844 | if (dev->type && dev->type->pm) { | 851 | if (dev->type && dev->type->pm) { |
845 | pm_dev_dbg(dev, state, "type "); | 852 | pm_dev_dbg(dev, state, "type "); |
846 | error = pm_op(dev, dev->type->pm, state); | 853 | error = pm_op(dev, dev->type->pm, state); |
847 | goto Domain; | 854 | goto End; |
848 | } | 855 | } |
849 | 856 | ||
850 | if (dev->class) { | 857 | if (dev->class) { |
851 | if (dev->class->pm) { | 858 | if (dev->class->pm) { |
852 | pm_dev_dbg(dev, state, "class "); | 859 | pm_dev_dbg(dev, state, "class "); |
853 | error = pm_op(dev, dev->class->pm, state); | 860 | error = pm_op(dev, dev->class->pm, state); |
854 | goto Domain; | 861 | goto End; |
855 | } else if (dev->class->suspend) { | 862 | } else if (dev->class->suspend) { |
856 | pm_dev_dbg(dev, state, "legacy class "); | 863 | pm_dev_dbg(dev, state, "legacy class "); |
857 | error = legacy_suspend(dev, state, dev->class->suspend); | 864 | error = legacy_suspend(dev, state, dev->class->suspend); |
858 | goto Domain; | 865 | goto End; |
859 | } | 866 | } |
860 | } | 867 | } |
861 | 868 | ||
@@ -869,12 +876,6 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
869 | } | 876 | } |
870 | } | 877 | } |
871 | 878 | ||
872 | Domain: | ||
873 | if (!error && dev->pwr_domain) { | ||
874 | pm_dev_dbg(dev, state, "power domain "); | ||
875 | pm_op(dev, &dev->pwr_domain->ops, state); | ||
876 | } | ||
877 | |||
878 | End: | 879 | End: |
879 | device_unlock(dev); | 880 | device_unlock(dev); |
880 | complete_all(&dev->power.completion); | 881 | complete_all(&dev->power.completion); |
@@ -914,11 +915,13 @@ static int device_suspend(struct device *dev) | |||
914 | * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. | 915 | * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. |
915 | * @state: PM transition of the system being carried out. | 916 | * @state: PM transition of the system being carried out. |
916 | */ | 917 | */ |
917 | static int dpm_suspend(pm_message_t state) | 918 | int dpm_suspend(pm_message_t state) |
918 | { | 919 | { |
919 | ktime_t starttime = ktime_get(); | 920 | ktime_t starttime = ktime_get(); |
920 | int error = 0; | 921 | int error = 0; |
921 | 922 | ||
923 | might_sleep(); | ||
924 | |||
922 | mutex_lock(&dpm_list_mtx); | 925 | mutex_lock(&dpm_list_mtx); |
923 | pm_transition = state; | 926 | pm_transition = state; |
924 | async_error = 0; | 927 | async_error = 0; |
@@ -965,7 +968,14 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
965 | 968 | ||
966 | device_lock(dev); | 969 | device_lock(dev); |
967 | 970 | ||
968 | if (dev->type && dev->type->pm) { | 971 | if (dev->pwr_domain) { |
972 | pm_dev_dbg(dev, state, "preparing power domain "); | ||
973 | if (dev->pwr_domain->ops.prepare) | ||
974 | error = dev->pwr_domain->ops.prepare(dev); | ||
975 | suspend_report_result(dev->pwr_domain->ops.prepare, error); | ||
976 | if (error) | ||
977 | goto End; | ||
978 | } else if (dev->type && dev->type->pm) { | ||
969 | pm_dev_dbg(dev, state, "preparing type "); | 979 | pm_dev_dbg(dev, state, "preparing type "); |
970 | if (dev->type->pm->prepare) | 980 | if (dev->type->pm->prepare) |
971 | error = dev->type->pm->prepare(dev); | 981 | error = dev->type->pm->prepare(dev); |
@@ -984,13 +994,6 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
984 | if (dev->bus->pm->prepare) | 994 | if (dev->bus->pm->prepare) |
985 | error = dev->bus->pm->prepare(dev); | 995 | error = dev->bus->pm->prepare(dev); |
986 | suspend_report_result(dev->bus->pm->prepare, error); | 996 | suspend_report_result(dev->bus->pm->prepare, error); |
987 | if (error) | ||
988 | goto End; | ||
989 | } | ||
990 | |||
991 | if (dev->pwr_domain && dev->pwr_domain->ops.prepare) { | ||
992 | pm_dev_dbg(dev, state, "preparing power domain "); | ||
993 | dev->pwr_domain->ops.prepare(dev); | ||
994 | } | 997 | } |
995 | 998 | ||
996 | End: | 999 | End: |
@@ -1005,10 +1008,12 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
1005 | * | 1008 | * |
1006 | * Execute the ->prepare() callback(s) for all devices. | 1009 | * Execute the ->prepare() callback(s) for all devices. |
1007 | */ | 1010 | */ |
1008 | static int dpm_prepare(pm_message_t state) | 1011 | int dpm_prepare(pm_message_t state) |
1009 | { | 1012 | { |
1010 | int error = 0; | 1013 | int error = 0; |
1011 | 1014 | ||
1015 | might_sleep(); | ||
1016 | |||
1012 | mutex_lock(&dpm_list_mtx); | 1017 | mutex_lock(&dpm_list_mtx); |
1013 | while (!list_empty(&dpm_list)) { | 1018 | while (!list_empty(&dpm_list)) { |
1014 | struct device *dev = to_device(dpm_list.next); | 1019 | struct device *dev = to_device(dpm_list.next); |
@@ -1057,7 +1062,6 @@ int dpm_suspend_start(pm_message_t state) | |||
1057 | { | 1062 | { |
1058 | int error; | 1063 | int error; |
1059 | 1064 | ||
1060 | might_sleep(); | ||
1061 | error = dpm_prepare(state); | 1065 | error = dpm_prepare(state); |
1062 | if (!error) | 1066 | if (!error) |
1063 | error = dpm_suspend(state); | 1067 | error = dpm_suspend(state); |