aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-07-22 16:36:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-22 16:36:52 -0400
commit7100e505b76b4e2efd88b2459d1a932214e29f8a (patch)
treea8eae8687dc1511c89463b1eb93c8349a7471ab3 /drivers
parentcb47c1831fa406c964468b259f2082c16cc3f757 (diff)
parent75a4161a58dd157a2bd2dc8e9986e45b62ac46cf (diff)
Merge tag 'pm-for-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull power management updates from Rafael Wysocki: - ACPI conversion to PM handling based on struct dev_pm_ops. - Conversion of a number of platform drivers to PM handling based on struct dev_pm_ops and removal of empty legacy PM callbacks from a couple of PCI drivers. - Suspend-to-both for in-kernel hibernation from Bojan Smojver. - cpuidle fixes and cleanups from ShuoX Liu, Daniel Lezcano and Preeti Murthy. - cpufreq bug fixes from Jonghwa Lee and Stephen Boyd. - Suspend and hibernate fixes from Srivatsa Bhat and Colin Cross. - Generic PM domains framework updates. - RTC CMOS wakeup signaling update from Paul Fox. - sparse warnings fixes from Sachin Kamat. - Build warnings fixes for the generic PM domains framework and PM sysfs code. - sysfs switch for printing device suspend times from Sameer Nanda. - Documentation fix from Oskar Schirmer. * tag 'pm-for-3.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (70 commits) cpufreq: Fix sysfs deadlock with concurrent hotplug/frequency switch EXYNOS: bugfix on retrieving old_index from freqs.old PM / Sleep: call early resume handlers when suspend_noirq fails PM / QoS: Use NULL pointer instead of plain integer in qos.c PM / QoS: Use NULL pointer instead of plain integer in pm_qos.h PM / Sleep: Require CAP_BLOCK_SUSPEND to use wake_lock/wake_unlock PM / Sleep: Add missing static storage class specifiers in main.c cpuilde / ACPI: remove time from acpi_processor_cx structure cpuidle / ACPI: remove usage from acpi_processor_cx structure cpuidle / ACPI : remove latency_ticks from acpi_processor_cx structure rtc-cmos: report wakeups from interrupt handler PM / Sleep: Fix build warning in sysfs.c for CONFIG_PM_SLEEP unset PM / Domains: Fix build warning for CONFIG_PM_RUNTIME unset olpc-xo15-sci: Use struct dev_pm_ops for power management PM / Domains: Replace plain integer with NULL pointer in domain.c file PM / Domains: Add missing static storage class specifier in domain.c file PM / crypto / ux500: Use struct dev_pm_ops for power management PM / IPMI: Remove empty legacy PCI PM callbacks tpm_nsc: Use struct dev_pm_ops for power management tpm_tis: Use struct dev_pm_ops for power management ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/ac.c17
-rw-r--r--drivers/acpi/battery.c15
-rw-r--r--drivers/acpi/button.c9
-rw-r--r--drivers/acpi/fan.c21
-rw-r--r--drivers/acpi/power.c12
-rw-r--r--drivers/acpi/processor_driver.c13
-rw-r--r--drivers/acpi/processor_idle.c43
-rw-r--r--drivers/acpi/sbs.c10
-rw-r--r--drivers/acpi/scan.c22
-rw-r--r--drivers/acpi/thermal.c17
-rw-r--r--drivers/base/power/domain.c342
-rw-r--r--drivers/base/power/main.c26
-rw-r--r--drivers/base/power/qos.c2
-rw-r--r--drivers/base/power/sysfs.c4
-rw-r--r--drivers/block/mg_disk.c13
-rw-r--r--drivers/char/hw_random/omap-rng.c13
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c16
-rw-r--r--drivers/char/sonypi.c13
-rw-r--r--drivers/char/tpm/tpm.c2
-rw-r--r--drivers/char/tpm/tpm.h2
-rw-r--r--drivers/char/tpm/tpm_atmel.c12
-rw-r--r--drivers/char/tpm/tpm_nsc.c13
-rw-r--r--drivers/char/tpm/tpm_tis.c18
-rw-r--r--drivers/cpufreq/cpufreq.c35
-rw-r--r--drivers/cpufreq/exynos-cpufreq.c14
-rw-r--r--drivers/cpuidle/cpuidle.c18
-rw-r--r--drivers/cpuidle/driver.c29
-rw-r--r--drivers/cpuidle/governors/menu.c6
-rw-r--r--drivers/cpuidle/sysfs.c21
-rw-r--r--drivers/crypto/ux500/cryp/cryp_core.c39
-rw-r--r--drivers/crypto/ux500/hash/hash_core.c33
-rw-r--r--drivers/hwmon/acpi_power_meter.c13
-rw-r--r--drivers/idle/intel_idle.c41
-rw-r--r--drivers/platform/x86/acer-wmi.c10
-rw-r--r--drivers/platform/x86/classmate-laptop.c13
-rw-r--r--drivers/platform/x86/fujitsu-tablet.c8
-rw-r--r--drivers/platform/x86/hdaps.c6
-rw-r--r--drivers/platform/x86/hp_accel.c15
-rw-r--r--drivers/platform/x86/intel_ips.c17
-rw-r--r--drivers/platform/x86/intel_mid_thermal.c16
-rw-r--r--drivers/platform/x86/msi-laptop.c7
-rw-r--r--drivers/platform/x86/panasonic-laptop.c16
-rw-r--r--drivers/platform/x86/sony-laptop.c20
-rw-r--r--drivers/platform/x86/thinkpad_acpi.c23
-rw-r--r--drivers/platform/x86/toshiba_acpi.c15
-rw-r--r--drivers/platform/x86/toshiba_bluetooth.c10
-rw-r--r--drivers/platform/x86/xo15-ebook.c8
-rw-r--r--drivers/rtc/rtc-cmos.c1
48 files changed, 665 insertions, 424 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index 6512b20aeccd..ff9f6bd48301 100644
--- a/drivers/acpi/ac.c
+++ b/drivers/acpi/ac.c
@@ -61,7 +61,6 @@ static int acpi_ac_open_fs(struct inode *inode, struct file *file);
61 61
62static int acpi_ac_add(struct acpi_device *device); 62static int acpi_ac_add(struct acpi_device *device);
63static int acpi_ac_remove(struct acpi_device *device, int type); 63static int acpi_ac_remove(struct acpi_device *device, int type);
64static int acpi_ac_resume(struct acpi_device *device);
65static void acpi_ac_notify(struct acpi_device *device, u32 event); 64static void acpi_ac_notify(struct acpi_device *device, u32 event);
66 65
67static const struct acpi_device_id ac_device_ids[] = { 66static const struct acpi_device_id ac_device_ids[] = {
@@ -70,6 +69,9 @@ static const struct acpi_device_id ac_device_ids[] = {
70}; 69};
71MODULE_DEVICE_TABLE(acpi, ac_device_ids); 70MODULE_DEVICE_TABLE(acpi, ac_device_ids);
72 71
72static int acpi_ac_resume(struct device *dev);
73static SIMPLE_DEV_PM_OPS(acpi_ac_pm, NULL, acpi_ac_resume);
74
73static struct acpi_driver acpi_ac_driver = { 75static struct acpi_driver acpi_ac_driver = {
74 .name = "ac", 76 .name = "ac",
75 .class = ACPI_AC_CLASS, 77 .class = ACPI_AC_CLASS,
@@ -78,9 +80,9 @@ static struct acpi_driver acpi_ac_driver = {
78 .ops = { 80 .ops = {
79 .add = acpi_ac_add, 81 .add = acpi_ac_add,
80 .remove = acpi_ac_remove, 82 .remove = acpi_ac_remove,
81 .resume = acpi_ac_resume,
82 .notify = acpi_ac_notify, 83 .notify = acpi_ac_notify,
83 }, 84 },
85 .drv.pm = &acpi_ac_pm,
84}; 86};
85 87
86struct acpi_ac { 88struct acpi_ac {
@@ -309,13 +311,18 @@ static int acpi_ac_add(struct acpi_device *device)
309 return result; 311 return result;
310} 312}
311 313
312static int acpi_ac_resume(struct acpi_device *device) 314static int acpi_ac_resume(struct device *dev)
313{ 315{
314 struct acpi_ac *ac; 316 struct acpi_ac *ac;
315 unsigned old_state; 317 unsigned old_state;
316 if (!device || !acpi_driver_data(device)) 318
319 if (!dev)
317 return -EINVAL; 320 return -EINVAL;
318 ac = acpi_driver_data(device); 321
322 ac = acpi_driver_data(to_acpi_device(dev));
323 if (!ac)
324 return -EINVAL;
325
319 old_state = ac->state; 326 old_state = ac->state;
320 if (acpi_ac_get_state(ac)) 327 if (acpi_ac_get_state(ac))
321 return 0; 328 return 0;
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 7dd3f9fb9f3f..023f9c8534d0 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1044,17 +1044,24 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
1044} 1044}
1045 1045
1046/* this is needed to learn about changes made in suspended state */ 1046/* this is needed to learn about changes made in suspended state */
1047static int acpi_battery_resume(struct acpi_device *device) 1047static int acpi_battery_resume(struct device *dev)
1048{ 1048{
1049 struct acpi_battery *battery; 1049 struct acpi_battery *battery;
1050 if (!device) 1050
1051 if (!dev)
1051 return -EINVAL; 1052 return -EINVAL;
1052 battery = acpi_driver_data(device); 1053
1054 battery = acpi_driver_data(to_acpi_device(dev));
1055 if (!battery)
1056 return -EINVAL;
1057
1053 battery->update_time = 0; 1058 battery->update_time = 0;
1054 acpi_battery_update(battery); 1059 acpi_battery_update(battery);
1055 return 0; 1060 return 0;
1056} 1061}
1057 1062
1063static SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume);
1064
1058static struct acpi_driver acpi_battery_driver = { 1065static struct acpi_driver acpi_battery_driver = {
1059 .name = "battery", 1066 .name = "battery",
1060 .class = ACPI_BATTERY_CLASS, 1067 .class = ACPI_BATTERY_CLASS,
@@ -1062,10 +1069,10 @@ static struct acpi_driver acpi_battery_driver = {
1062 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 1069 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1063 .ops = { 1070 .ops = {
1064 .add = acpi_battery_add, 1071 .add = acpi_battery_add,
1065 .resume = acpi_battery_resume,
1066 .remove = acpi_battery_remove, 1072 .remove = acpi_battery_remove,
1067 .notify = acpi_battery_notify, 1073 .notify = acpi_battery_notify,
1068 }, 1074 },
1075 .drv.pm = &acpi_battery_pm,
1069}; 1076};
1070 1077
1071static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie) 1078static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie)
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index d27d072472f9..79d4c22f7a6d 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -76,19 +76,21 @@ MODULE_DEVICE_TABLE(acpi, button_device_ids);
76 76
77static int acpi_button_add(struct acpi_device *device); 77static int acpi_button_add(struct acpi_device *device);
78static int acpi_button_remove(struct acpi_device *device, int type); 78static int acpi_button_remove(struct acpi_device *device, int type);
79static int acpi_button_resume(struct acpi_device *device);
80static void acpi_button_notify(struct acpi_device *device, u32 event); 79static void acpi_button_notify(struct acpi_device *device, u32 event);
81 80
81static int acpi_button_resume(struct device *dev);
82static SIMPLE_DEV_PM_OPS(acpi_button_pm, NULL, acpi_button_resume);
83
82static struct acpi_driver acpi_button_driver = { 84static struct acpi_driver acpi_button_driver = {
83 .name = "button", 85 .name = "button",
84 .class = ACPI_BUTTON_CLASS, 86 .class = ACPI_BUTTON_CLASS,
85 .ids = button_device_ids, 87 .ids = button_device_ids,
86 .ops = { 88 .ops = {
87 .add = acpi_button_add, 89 .add = acpi_button_add,
88 .resume = acpi_button_resume,
89 .remove = acpi_button_remove, 90 .remove = acpi_button_remove,
90 .notify = acpi_button_notify, 91 .notify = acpi_button_notify,
91 }, 92 },
93 .drv.pm = &acpi_button_pm,
92}; 94};
93 95
94struct acpi_button { 96struct acpi_button {
@@ -308,8 +310,9 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
308 } 310 }
309} 311}
310 312
311static int acpi_button_resume(struct acpi_device *device) 313static int acpi_button_resume(struct device *dev)
312{ 314{
315 struct acpi_device *device = to_acpi_device(dev);
313 struct acpi_button *button = acpi_driver_data(device); 316 struct acpi_button *button = acpi_driver_data(device);
314 317
315 if (button->type == ACPI_BUTTON_TYPE_LID) 318 if (button->type == ACPI_BUTTON_TYPE_LID)
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c
index 0f0356ca1a9e..669d9ee80d16 100644
--- a/drivers/acpi/fan.c
+++ b/drivers/acpi/fan.c
@@ -46,8 +46,6 @@ MODULE_LICENSE("GPL");
46 46
47static int acpi_fan_add(struct acpi_device *device); 47static int acpi_fan_add(struct acpi_device *device);
48static int acpi_fan_remove(struct acpi_device *device, int type); 48static int acpi_fan_remove(struct acpi_device *device, int type);
49static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state);
50static int acpi_fan_resume(struct acpi_device *device);
51 49
52static const struct acpi_device_id fan_device_ids[] = { 50static const struct acpi_device_id fan_device_ids[] = {
53 {"PNP0C0B", 0}, 51 {"PNP0C0B", 0},
@@ -55,6 +53,10 @@ static const struct acpi_device_id fan_device_ids[] = {
55}; 53};
56MODULE_DEVICE_TABLE(acpi, fan_device_ids); 54MODULE_DEVICE_TABLE(acpi, fan_device_ids);
57 55
56static int acpi_fan_suspend(struct device *dev);
57static int acpi_fan_resume(struct device *dev);
58static SIMPLE_DEV_PM_OPS(acpi_fan_pm, acpi_fan_suspend, acpi_fan_resume);
59
58static struct acpi_driver acpi_fan_driver = { 60static struct acpi_driver acpi_fan_driver = {
59 .name = "fan", 61 .name = "fan",
60 .class = ACPI_FAN_CLASS, 62 .class = ACPI_FAN_CLASS,
@@ -62,9 +64,8 @@ static struct acpi_driver acpi_fan_driver = {
62 .ops = { 64 .ops = {
63 .add = acpi_fan_add, 65 .add = acpi_fan_add,
64 .remove = acpi_fan_remove, 66 .remove = acpi_fan_remove,
65 .suspend = acpi_fan_suspend,
66 .resume = acpi_fan_resume,
67 }, 67 },
68 .drv.pm = &acpi_fan_pm,
68}; 69};
69 70
70/* thermal cooling device callbacks */ 71/* thermal cooling device callbacks */
@@ -183,24 +184,24 @@ static int acpi_fan_remove(struct acpi_device *device, int type)
183 return 0; 184 return 0;
184} 185}
185 186
186static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state) 187static int acpi_fan_suspend(struct device *dev)
187{ 188{
188 if (!device) 189 if (!dev)
189 return -EINVAL; 190 return -EINVAL;
190 191
191 acpi_bus_set_power(device->handle, ACPI_STATE_D0); 192 acpi_bus_set_power(to_acpi_device(dev)->handle, ACPI_STATE_D0);
192 193
193 return AE_OK; 194 return AE_OK;
194} 195}
195 196
196static int acpi_fan_resume(struct acpi_device *device) 197static int acpi_fan_resume(struct device *dev)
197{ 198{
198 int result; 199 int result;
199 200
200 if (!device) 201 if (!dev)
201 return -EINVAL; 202 return -EINVAL;
202 203
203 result = acpi_bus_update_power(device->handle, NULL); 204 result = acpi_bus_update_power(to_acpi_device(dev)->handle, NULL);
204 if (result) 205 if (result)
205 printk(KERN_ERR PREFIX "Error updating fan power state\n"); 206 printk(KERN_ERR PREFIX "Error updating fan power state\n");
206 207
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index dd6d6a3c6780..894d45c6bc67 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -60,7 +60,6 @@ ACPI_MODULE_NAME("power");
60 60
61static int acpi_power_add(struct acpi_device *device); 61static int acpi_power_add(struct acpi_device *device);
62static int acpi_power_remove(struct acpi_device *device, int type); 62static int acpi_power_remove(struct acpi_device *device, int type);
63static int acpi_power_resume(struct acpi_device *device);
64 63
65static const struct acpi_device_id power_device_ids[] = { 64static const struct acpi_device_id power_device_ids[] = {
66 {ACPI_POWER_HID, 0}, 65 {ACPI_POWER_HID, 0},
@@ -68,6 +67,9 @@ static const struct acpi_device_id power_device_ids[] = {
68}; 67};
69MODULE_DEVICE_TABLE(acpi, power_device_ids); 68MODULE_DEVICE_TABLE(acpi, power_device_ids);
70 69
70static int acpi_power_resume(struct device *dev);
71static SIMPLE_DEV_PM_OPS(acpi_power_pm, NULL, acpi_power_resume);
72
71static struct acpi_driver acpi_power_driver = { 73static struct acpi_driver acpi_power_driver = {
72 .name = "power", 74 .name = "power",
73 .class = ACPI_POWER_CLASS, 75 .class = ACPI_POWER_CLASS,
@@ -75,8 +77,8 @@ static struct acpi_driver acpi_power_driver = {
75 .ops = { 77 .ops = {
76 .add = acpi_power_add, 78 .add = acpi_power_add,
77 .remove = acpi_power_remove, 79 .remove = acpi_power_remove,
78 .resume = acpi_power_resume,
79 }, 80 },
81 .drv.pm = &acpi_power_pm,
80}; 82};
81 83
82/* 84/*
@@ -771,14 +773,16 @@ static int acpi_power_remove(struct acpi_device *device, int type)
771 return 0; 773 return 0;
772} 774}
773 775
774static int acpi_power_resume(struct acpi_device *device) 776static int acpi_power_resume(struct device *dev)
775{ 777{
776 int result = 0, state; 778 int result = 0, state;
779 struct acpi_device *device;
777 struct acpi_power_resource *resource; 780 struct acpi_power_resource *resource;
778 781
779 if (!device) 782 if (!dev)
780 return -EINVAL; 783 return -EINVAL;
781 784
785 device = to_acpi_device(dev);
782 resource = acpi_driver_data(device); 786 resource = acpi_driver_data(device);
783 if (!resource) 787 if (!resource)
784 return -EINVAL; 788 return -EINVAL;
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 0734086537b8..7048b97853e0 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -93,6 +93,9 @@ static const struct acpi_device_id processor_device_ids[] = {
93}; 93};
94MODULE_DEVICE_TABLE(acpi, processor_device_ids); 94MODULE_DEVICE_TABLE(acpi, processor_device_ids);
95 95
96static SIMPLE_DEV_PM_OPS(acpi_processor_pm,
97 acpi_processor_suspend, acpi_processor_resume);
98
96static struct acpi_driver acpi_processor_driver = { 99static struct acpi_driver acpi_processor_driver = {
97 .name = "processor", 100 .name = "processor",
98 .class = ACPI_PROCESSOR_CLASS, 101 .class = ACPI_PROCESSOR_CLASS,
@@ -100,10 +103,9 @@ static struct acpi_driver acpi_processor_driver = {
100 .ops = { 103 .ops = {
101 .add = acpi_processor_add, 104 .add = acpi_processor_add,
102 .remove = acpi_processor_remove, 105 .remove = acpi_processor_remove,
103 .suspend = acpi_processor_suspend,
104 .resume = acpi_processor_resume,
105 .notify = acpi_processor_notify, 106 .notify = acpi_processor_notify,
106 }, 107 },
108 .drv.pm = &acpi_processor_pm,
107}; 109};
108 110
109#define INSTALL_NOTIFY_HANDLER 1 111#define INSTALL_NOTIFY_HANDLER 1
@@ -427,18 +429,11 @@ static int acpi_cpu_soft_notify(struct notifier_block *nfb,
427 * Initialize missing things 429 * Initialize missing things
428 */ 430 */
429 if (pr->flags.need_hotplug_init) { 431 if (pr->flags.need_hotplug_init) {
430 struct cpuidle_driver *idle_driver =
431 cpuidle_get_driver();
432
433 printk(KERN_INFO "Will online and init hotplugged " 432 printk(KERN_INFO "Will online and init hotplugged "
434 "CPU: %d\n", pr->id); 433 "CPU: %d\n", pr->id);
435 WARN(acpi_processor_start(pr), "Failed to start CPU:" 434 WARN(acpi_processor_start(pr), "Failed to start CPU:"
436 " %d\n", pr->id); 435 " %d\n", pr->id);
437 pr->flags.need_hotplug_init = 0; 436 pr->flags.need_hotplug_init = 0;
438 if (idle_driver && !strcmp(idle_driver->name,
439 "intel_idle")) {
440 intel_idle_cpu_init(pr->id);
441 }
442 /* Normal CPU soft online event */ 437 /* Normal CPU soft online event */
443 } else { 438 } else {
444 acpi_processor_ppc_has_changed(pr, 0); 439 acpi_processor_ppc_has_changed(pr, 0);
diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
index 47a8caa89dbe..e589c1985248 100644
--- a/drivers/acpi/processor_idle.c
+++ b/drivers/acpi/processor_idle.c
@@ -221,10 +221,6 @@ static void lapic_timer_state_broadcast(struct acpi_processor *pr,
221 221
222#endif 222#endif
223 223
224/*
225 * Suspend / resume control
226 */
227static int acpi_idle_suspend;
228static u32 saved_bm_rld; 224static u32 saved_bm_rld;
229 225
230static void acpi_idle_bm_rld_save(void) 226static void acpi_idle_bm_rld_save(void)
@@ -241,23 +237,15 @@ static void acpi_idle_bm_rld_restore(void)
241 acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, saved_bm_rld); 237 acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, saved_bm_rld);
242} 238}
243 239
244int acpi_processor_suspend(struct acpi_device * device, pm_message_t state) 240int acpi_processor_suspend(struct device *dev)
245{ 241{
246 if (acpi_idle_suspend == 1)
247 return 0;
248
249 acpi_idle_bm_rld_save(); 242 acpi_idle_bm_rld_save();
250 acpi_idle_suspend = 1;
251 return 0; 243 return 0;
252} 244}
253 245
254int acpi_processor_resume(struct acpi_device * device) 246int acpi_processor_resume(struct device *dev)
255{ 247{
256 if (acpi_idle_suspend == 0)
257 return 0;
258
259 acpi_idle_bm_rld_restore(); 248 acpi_idle_bm_rld_restore();
260 acpi_idle_suspend = 0;
261 return 0; 249 return 0;
262} 250}
263 251
@@ -595,7 +583,6 @@ static void acpi_processor_power_verify_c3(struct acpi_processor *pr,
595 */ 583 */
596 cx->valid = 1; 584 cx->valid = 1;
597 585
598 cx->latency_ticks = cx->latency;
599 /* 586 /*
600 * On older chipsets, BM_RLD needs to be set 587 * On older chipsets, BM_RLD needs to be set
601 * in order for Bus Master activity to wake the 588 * in order for Bus Master activity to wake the
@@ -628,7 +615,6 @@ static int acpi_processor_power_verify(struct acpi_processor *pr)
628 if (!cx->address) 615 if (!cx->address)
629 break; 616 break;
630 cx->valid = 1; 617 cx->valid = 1;
631 cx->latency_ticks = cx->latency; /* Normalize latency */
632 break; 618 break;
633 619
634 case ACPI_STATE_C3: 620 case ACPI_STATE_C3:
@@ -763,11 +749,6 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
763 749
764 local_irq_disable(); 750 local_irq_disable();
765 751
766 if (acpi_idle_suspend) {
767 local_irq_enable();
768 cpu_relax();
769 return -EBUSY;
770 }
771 752
772 lapic_timer_state_broadcast(pr, cx, 1); 753 lapic_timer_state_broadcast(pr, cx, 1);
773 kt1 = ktime_get_real(); 754 kt1 = ktime_get_real();
@@ -779,7 +760,6 @@ static int acpi_idle_enter_c1(struct cpuidle_device *dev,
779 dev->last_residency = (int)idle_time; 760 dev->last_residency = (int)idle_time;
780 761
781 local_irq_enable(); 762 local_irq_enable();
782 cx->usage++;
783 lapic_timer_state_broadcast(pr, cx, 0); 763 lapic_timer_state_broadcast(pr, cx, 0);
784 764
785 return index; 765 return index;
@@ -838,11 +818,6 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
838 818
839 local_irq_disable(); 819 local_irq_disable();
840 820
841 if (acpi_idle_suspend) {
842 local_irq_enable();
843 cpu_relax();
844 return -EBUSY;
845 }
846 821
847 if (cx->entry_method != ACPI_CSTATE_FFH) { 822 if (cx->entry_method != ACPI_CSTATE_FFH) {
848 current_thread_info()->status &= ~TS_POLLING; 823 current_thread_info()->status &= ~TS_POLLING;
@@ -887,10 +862,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
887 if (cx->entry_method != ACPI_CSTATE_FFH) 862 if (cx->entry_method != ACPI_CSTATE_FFH)
888 current_thread_info()->status |= TS_POLLING; 863 current_thread_info()->status |= TS_POLLING;
889 864
890 cx->usage++;
891
892 lapic_timer_state_broadcast(pr, cx, 0); 865 lapic_timer_state_broadcast(pr, cx, 0);
893 cx->time += idle_time;
894 return index; 866 return index;
895} 867}
896 868
@@ -928,8 +900,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
928 drv, drv->safe_state_index); 900 drv, drv->safe_state_index);
929 } else { 901 } else {
930 local_irq_disable(); 902 local_irq_disable();
931 if (!acpi_idle_suspend) 903 acpi_safe_halt();
932 acpi_safe_halt();
933 local_irq_enable(); 904 local_irq_enable();
934 return -EBUSY; 905 return -EBUSY;
935 } 906 }
@@ -937,11 +908,6 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
937 908
938 local_irq_disable(); 909 local_irq_disable();
939 910
940 if (acpi_idle_suspend) {
941 local_irq_enable();
942 cpu_relax();
943 return -EBUSY;
944 }
945 911
946 if (cx->entry_method != ACPI_CSTATE_FFH) { 912 if (cx->entry_method != ACPI_CSTATE_FFH) {
947 current_thread_info()->status &= ~TS_POLLING; 913 current_thread_info()->status &= ~TS_POLLING;
@@ -1014,10 +980,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
1014 if (cx->entry_method != ACPI_CSTATE_FFH) 980 if (cx->entry_method != ACPI_CSTATE_FFH)
1015 current_thread_info()->status |= TS_POLLING; 981 current_thread_info()->status |= TS_POLLING;
1016 982
1017 cx->usage++;
1018
1019 lapic_timer_state_broadcast(pr, cx, 0); 983 lapic_timer_state_broadcast(pr, cx, 0);
1020 cx->time += idle_time;
1021 return index; 984 return index;
1022} 985}
1023 986
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 6e36d0c0057c..c0b9aa5faf4c 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -988,16 +988,18 @@ static void acpi_sbs_rmdirs(void)
988#endif 988#endif
989} 989}
990 990
991static int acpi_sbs_resume(struct acpi_device *device) 991static int acpi_sbs_resume(struct device *dev)
992{ 992{
993 struct acpi_sbs *sbs; 993 struct acpi_sbs *sbs;
994 if (!device) 994 if (!dev)
995 return -EINVAL; 995 return -EINVAL;
996 sbs = device->driver_data; 996 sbs = to_acpi_device(dev)->driver_data;
997 acpi_sbs_callback(sbs); 997 acpi_sbs_callback(sbs);
998 return 0; 998 return 0;
999} 999}
1000 1000
1001static SIMPLE_DEV_PM_OPS(acpi_sbs_pm, NULL, acpi_sbs_resume);
1002
1001static struct acpi_driver acpi_sbs_driver = { 1003static struct acpi_driver acpi_sbs_driver = {
1002 .name = "sbs", 1004 .name = "sbs",
1003 .class = ACPI_SBS_CLASS, 1005 .class = ACPI_SBS_CLASS,
@@ -1005,8 +1007,8 @@ static struct acpi_driver acpi_sbs_driver = {
1005 .ops = { 1007 .ops = {
1006 .add = acpi_sbs_add, 1008 .add = acpi_sbs_add,
1007 .remove = acpi_sbs_remove, 1009 .remove = acpi_sbs_remove,
1008 .resume = acpi_sbs_resume,
1009 }, 1010 },
1011 .drv.pm = &acpi_sbs_pm,
1010}; 1012};
1011 1013
1012static int __init acpi_sbs_init(void) 1014static int __init acpi_sbs_init(void)
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index c8a1f3b68110..fdda49336560 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -290,26 +290,6 @@ static void acpi_device_release(struct device *dev)
290 kfree(acpi_dev); 290 kfree(acpi_dev);
291} 291}
292 292
293static int acpi_device_suspend(struct device *dev, pm_message_t state)
294{
295 struct acpi_device *acpi_dev = to_acpi_device(dev);
296 struct acpi_driver *acpi_drv = acpi_dev->driver;
297
298 if (acpi_drv && acpi_drv->ops.suspend)
299 return acpi_drv->ops.suspend(acpi_dev, state);
300 return 0;
301}
302
303static int acpi_device_resume(struct device *dev)
304{
305 struct acpi_device *acpi_dev = to_acpi_device(dev);
306 struct acpi_driver *acpi_drv = acpi_dev->driver;
307
308 if (acpi_drv && acpi_drv->ops.resume)
309 return acpi_drv->ops.resume(acpi_dev);
310 return 0;
311}
312
313static int acpi_bus_match(struct device *dev, struct device_driver *drv) 293static int acpi_bus_match(struct device *dev, struct device_driver *drv)
314{ 294{
315 struct acpi_device *acpi_dev = to_acpi_device(dev); 295 struct acpi_device *acpi_dev = to_acpi_device(dev);
@@ -441,8 +421,6 @@ static int acpi_device_remove(struct device * dev)
441 421
442struct bus_type acpi_bus_type = { 422struct bus_type acpi_bus_type = {
443 .name = "acpi", 423 .name = "acpi",
444 .suspend = acpi_device_suspend,
445 .resume = acpi_device_resume,
446 .match = acpi_bus_match, 424 .match = acpi_bus_match,
447 .probe = acpi_device_probe, 425 .probe = acpi_device_probe,
448 .remove = acpi_device_remove, 426 .remove = acpi_device_remove,
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 7dbebea1ec31..21dd4c268aef 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -98,7 +98,6 @@ MODULE_PARM_DESC(psv, "Disable or override all passive trip points.");
98 98
99static int acpi_thermal_add(struct acpi_device *device); 99static int acpi_thermal_add(struct acpi_device *device);
100static int acpi_thermal_remove(struct acpi_device *device, int type); 100static int acpi_thermal_remove(struct acpi_device *device, int type);
101static int acpi_thermal_resume(struct acpi_device *device);
102static void acpi_thermal_notify(struct acpi_device *device, u32 event); 101static void acpi_thermal_notify(struct acpi_device *device, u32 event);
103 102
104static const struct acpi_device_id thermal_device_ids[] = { 103static const struct acpi_device_id thermal_device_ids[] = {
@@ -107,6 +106,9 @@ static const struct acpi_device_id thermal_device_ids[] = {
107}; 106};
108MODULE_DEVICE_TABLE(acpi, thermal_device_ids); 107MODULE_DEVICE_TABLE(acpi, thermal_device_ids);
109 108
109static int acpi_thermal_resume(struct device *dev);
110static SIMPLE_DEV_PM_OPS(acpi_thermal_pm, NULL, acpi_thermal_resume);
111
110static struct acpi_driver acpi_thermal_driver = { 112static struct acpi_driver acpi_thermal_driver = {
111 .name = "thermal", 113 .name = "thermal",
112 .class = ACPI_THERMAL_CLASS, 114 .class = ACPI_THERMAL_CLASS,
@@ -114,9 +116,9 @@ static struct acpi_driver acpi_thermal_driver = {
114 .ops = { 116 .ops = {
115 .add = acpi_thermal_add, 117 .add = acpi_thermal_add,
116 .remove = acpi_thermal_remove, 118 .remove = acpi_thermal_remove,
117 .resume = acpi_thermal_resume,
118 .notify = acpi_thermal_notify, 119 .notify = acpi_thermal_notify,
119 }, 120 },
121 .drv.pm = &acpi_thermal_pm,
120}; 122};
121 123
122struct acpi_thermal_state { 124struct acpi_thermal_state {
@@ -1041,16 +1043,17 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1041 return 0; 1043 return 0;
1042} 1044}
1043 1045
1044static int acpi_thermal_resume(struct acpi_device *device) 1046static int acpi_thermal_resume(struct device *dev)
1045{ 1047{
1046 struct acpi_thermal *tz = NULL; 1048 struct acpi_thermal *tz;
1047 int i, j, power_state, result; 1049 int i, j, power_state, result;
1048 1050
1049 1051 if (!dev)
1050 if (!device || !acpi_driver_data(device))
1051 return -EINVAL; 1052 return -EINVAL;
1052 1053
1053 tz = acpi_driver_data(device); 1054 tz = acpi_driver_data(to_acpi_device(dev));
1055 if (!tz)
1056 return -EINVAL;
1054 1057
1055 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { 1058 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1056 if (!(&tz->trips.active[i])) 1059 if (!(&tz->trips.active[i]))
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 83aa694a8efe..ba3487c9835b 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -75,19 +75,6 @@ static int genpd_start_dev(struct generic_pm_domain *genpd, struct device *dev)
75 start_latency_ns, "start"); 75 start_latency_ns, "start");
76} 76}
77 77
78static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev)
79{
80 return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev,
81 save_state_latency_ns, "state save");
82}
83
84static int genpd_restore_dev(struct generic_pm_domain *genpd, struct device *dev)
85{
86 return GENPD_DEV_TIMED_CALLBACK(genpd, int, restore_state, dev,
87 restore_state_latency_ns,
88 "state restore");
89}
90
91static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd) 78static bool genpd_sd_counter_dec(struct generic_pm_domain *genpd)
92{ 79{
93 bool ret = false; 80 bool ret = false;
@@ -139,6 +126,19 @@ static void genpd_set_active(struct generic_pm_domain *genpd)
139 genpd->status = GPD_STATE_ACTIVE; 126 genpd->status = GPD_STATE_ACTIVE;
140} 127}
141 128
129static void genpd_recalc_cpu_exit_latency(struct generic_pm_domain *genpd)
130{
131 s64 usecs64;
132
133 if (!genpd->cpu_data)
134 return;
135
136 usecs64 = genpd->power_on_latency_ns;
137 do_div(usecs64, NSEC_PER_USEC);
138 usecs64 += genpd->cpu_data->saved_exit_latency;
139 genpd->cpu_data->idle_state->exit_latency = usecs64;
140}
141
142/** 142/**
143 * __pm_genpd_poweron - Restore power to a given PM domain and its masters. 143 * __pm_genpd_poweron - Restore power to a given PM domain and its masters.
144 * @genpd: PM domain to power up. 144 * @genpd: PM domain to power up.
@@ -146,7 +146,7 @@ static void genpd_set_active(struct generic_pm_domain *genpd)
146 * Restore power to @genpd and all of its masters so that it is possible to 146 * Restore power to @genpd and all of its masters so that it is possible to
147 * resume a device belonging to it. 147 * resume a device belonging to it.
148 */ 148 */
149int __pm_genpd_poweron(struct generic_pm_domain *genpd) 149static int __pm_genpd_poweron(struct generic_pm_domain *genpd)
150 __releases(&genpd->lock) __acquires(&genpd->lock) 150 __releases(&genpd->lock) __acquires(&genpd->lock)
151{ 151{
152 struct gpd_link *link; 152 struct gpd_link *link;
@@ -176,6 +176,13 @@ int __pm_genpd_poweron(struct generic_pm_domain *genpd)
176 return 0; 176 return 0;
177 } 177 }
178 178
179 if (genpd->cpu_data) {
180 cpuidle_pause_and_lock();
181 genpd->cpu_data->idle_state->disabled = true;
182 cpuidle_resume_and_unlock();
183 goto out;
184 }
185
179 /* 186 /*
180 * The list is guaranteed not to change while the loop below is being 187 * The list is guaranteed not to change while the loop below is being
181 * executed, unless one of the masters' .power_on() callbacks fiddles 188 * executed, unless one of the masters' .power_on() callbacks fiddles
@@ -215,6 +222,7 @@ int __pm_genpd_poweron(struct generic_pm_domain *genpd)
215 if (elapsed_ns > genpd->power_on_latency_ns) { 222 if (elapsed_ns > genpd->power_on_latency_ns) {
216 genpd->power_on_latency_ns = elapsed_ns; 223 genpd->power_on_latency_ns = elapsed_ns;
217 genpd->max_off_time_changed = true; 224 genpd->max_off_time_changed = true;
225 genpd_recalc_cpu_exit_latency(genpd);
218 if (genpd->name) 226 if (genpd->name)
219 pr_warning("%s: Power-on latency exceeded, " 227 pr_warning("%s: Power-on latency exceeded, "
220 "new value %lld ns\n", genpd->name, 228 "new value %lld ns\n", genpd->name,
@@ -222,6 +230,7 @@ int __pm_genpd_poweron(struct generic_pm_domain *genpd)
222 } 230 }
223 } 231 }
224 232
233 out:
225 genpd_set_active(genpd); 234 genpd_set_active(genpd);
226 235
227 return 0; 236 return 0;
@@ -251,6 +260,19 @@ int pm_genpd_poweron(struct generic_pm_domain *genpd)
251 260
252#ifdef CONFIG_PM_RUNTIME 261#ifdef CONFIG_PM_RUNTIME
253 262
263static int genpd_save_dev(struct generic_pm_domain *genpd, struct device *dev)
264{
265 return GENPD_DEV_TIMED_CALLBACK(genpd, int, save_state, dev,
266 save_state_latency_ns, "state save");
267}
268
269static int genpd_restore_dev(struct generic_pm_domain *genpd, struct device *dev)
270{
271 return GENPD_DEV_TIMED_CALLBACK(genpd, int, restore_state, dev,
272 restore_state_latency_ns,
273 "state restore");
274}
275
254static int genpd_dev_pm_qos_notifier(struct notifier_block *nb, 276static int genpd_dev_pm_qos_notifier(struct notifier_block *nb,
255 unsigned long val, void *ptr) 277 unsigned long val, void *ptr)
256{ 278{
@@ -275,7 +297,7 @@ static int genpd_dev_pm_qos_notifier(struct notifier_block *nb,
275 297
276 pdd = dev->power.subsys_data ? 298 pdd = dev->power.subsys_data ?
277 dev->power.subsys_data->domain_data : NULL; 299 dev->power.subsys_data->domain_data : NULL;
278 if (pdd) { 300 if (pdd && pdd->dev) {
279 to_gpd_data(pdd)->td.constraint_changed = true; 301 to_gpd_data(pdd)->td.constraint_changed = true;
280 genpd = dev_to_genpd(dev); 302 genpd = dev_to_genpd(dev);
281 } else { 303 } else {
@@ -339,19 +361,16 @@ static void __pm_genpd_restore_device(struct pm_domain_data *pdd,
339{ 361{
340 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd); 362 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
341 struct device *dev = pdd->dev; 363 struct device *dev = pdd->dev;
364 bool need_restore = gpd_data->need_restore;
342 365
343 if (!gpd_data->need_restore) 366 gpd_data->need_restore = false;
344 return;
345
346 mutex_unlock(&genpd->lock); 367 mutex_unlock(&genpd->lock);
347 368
348 genpd_start_dev(genpd, dev); 369 genpd_start_dev(genpd, dev);
349 genpd_restore_dev(genpd, dev); 370 if (need_restore)
350 genpd_stop_dev(genpd, dev); 371 genpd_restore_dev(genpd, dev);
351 372
352 mutex_lock(&genpd->lock); 373 mutex_lock(&genpd->lock);
353
354 gpd_data->need_restore = false;
355} 374}
356 375
357/** 376/**
@@ -458,6 +477,21 @@ static int pm_genpd_poweroff(struct generic_pm_domain *genpd)
458 } 477 }
459 } 478 }
460 479
480 if (genpd->cpu_data) {
481 /*
482 * If cpu_data is set, cpuidle should turn the domain off when
483 * the CPU in it is idle. In that case we don't decrement the
484 * subdomain counts of the master domains, so that power is not
485 * removed from the current domain prematurely as a result of
486 * cutting off the masters' power.
487 */
488 genpd->status = GPD_STATE_POWER_OFF;
489 cpuidle_pause_and_lock();
490 genpd->cpu_data->idle_state->disabled = false;
491 cpuidle_resume_and_unlock();
492 goto out;
493 }
494
461 if (genpd->power_off) { 495 if (genpd->power_off) {
462 ktime_t time_start; 496 ktime_t time_start;
463 s64 elapsed_ns; 497 s64 elapsed_ns;
@@ -595,7 +629,7 @@ static int pm_genpd_runtime_resume(struct device *dev)
595 629
596 /* If power.irq_safe, the PM domain is never powered off. */ 630 /* If power.irq_safe, the PM domain is never powered off. */
597 if (dev->power.irq_safe) 631 if (dev->power.irq_safe)
598 goto out; 632 return genpd_start_dev(genpd, dev);
599 633
600 mutex_lock(&genpd->lock); 634 mutex_lock(&genpd->lock);
601 ret = __pm_genpd_poweron(genpd); 635 ret = __pm_genpd_poweron(genpd);
@@ -628,9 +662,6 @@ static int pm_genpd_runtime_resume(struct device *dev)
628 wake_up_all(&genpd->status_wait_queue); 662 wake_up_all(&genpd->status_wait_queue);
629 mutex_unlock(&genpd->lock); 663 mutex_unlock(&genpd->lock);
630 664
631 out:
632 genpd_start_dev(genpd, dev);
633
634 return 0; 665 return 0;
635} 666}
636 667
@@ -1235,6 +1266,27 @@ static void pm_genpd_complete(struct device *dev)
1235 1266
1236#endif /* CONFIG_PM_SLEEP */ 1267#endif /* CONFIG_PM_SLEEP */
1237 1268
1269static struct generic_pm_domain_data *__pm_genpd_alloc_dev_data(struct device *dev)
1270{
1271 struct generic_pm_domain_data *gpd_data;
1272
1273 gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL);
1274 if (!gpd_data)
1275 return NULL;
1276
1277 mutex_init(&gpd_data->lock);
1278 gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier;
1279 dev_pm_qos_add_notifier(dev, &gpd_data->nb);
1280 return gpd_data;
1281}
1282
1283static void __pm_genpd_free_dev_data(struct device *dev,
1284 struct generic_pm_domain_data *gpd_data)
1285{
1286 dev_pm_qos_remove_notifier(dev, &gpd_data->nb);
1287 kfree(gpd_data);
1288}
1289
1238/** 1290/**
1239 * __pm_genpd_add_device - Add a device to an I/O PM domain. 1291 * __pm_genpd_add_device - Add a device to an I/O PM domain.
1240 * @genpd: PM domain to add the device to. 1292 * @genpd: PM domain to add the device to.
@@ -1244,7 +1296,7 @@ static void pm_genpd_complete(struct device *dev)
1244int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev, 1296int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1245 struct gpd_timing_data *td) 1297 struct gpd_timing_data *td)
1246{ 1298{
1247 struct generic_pm_domain_data *gpd_data; 1299 struct generic_pm_domain_data *gpd_data_new, *gpd_data = NULL;
1248 struct pm_domain_data *pdd; 1300 struct pm_domain_data *pdd;
1249 int ret = 0; 1301 int ret = 0;
1250 1302
@@ -1253,14 +1305,10 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1253 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev)) 1305 if (IS_ERR_OR_NULL(genpd) || IS_ERR_OR_NULL(dev))
1254 return -EINVAL; 1306 return -EINVAL;
1255 1307
1256 gpd_data = kzalloc(sizeof(*gpd_data), GFP_KERNEL); 1308 gpd_data_new = __pm_genpd_alloc_dev_data(dev);
1257 if (!gpd_data) 1309 if (!gpd_data_new)
1258 return -ENOMEM; 1310 return -ENOMEM;
1259 1311
1260 mutex_init(&gpd_data->lock);
1261 gpd_data->nb.notifier_call = genpd_dev_pm_qos_notifier;
1262 dev_pm_qos_add_notifier(dev, &gpd_data->nb);
1263
1264 genpd_acquire_lock(genpd); 1312 genpd_acquire_lock(genpd);
1265 1313
1266 if (genpd->prepared_count > 0) { 1314 if (genpd->prepared_count > 0) {
@@ -1274,35 +1322,42 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1274 goto out; 1322 goto out;
1275 } 1323 }
1276 1324
1325 ret = dev_pm_get_subsys_data(dev);
1326 if (ret)
1327 goto out;
1328
1277 genpd->device_count++; 1329 genpd->device_count++;
1278 genpd->max_off_time_changed = true; 1330 genpd->max_off_time_changed = true;
1279 1331
1280 dev_pm_get_subsys_data(dev);
1281
1282 mutex_lock(&gpd_data->lock);
1283 spin_lock_irq(&dev->power.lock); 1332 spin_lock_irq(&dev->power.lock);
1333
1284 dev->pm_domain = &genpd->domain; 1334 dev->pm_domain = &genpd->domain;
1285 dev->power.subsys_data->domain_data = &gpd_data->base; 1335 if (dev->power.subsys_data->domain_data) {
1286 gpd_data->base.dev = dev; 1336 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
1287 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); 1337 } else {
1288 gpd_data->need_restore = genpd->status == GPD_STATE_POWER_OFF; 1338 gpd_data = gpd_data_new;
1339 dev->power.subsys_data->domain_data = &gpd_data->base;
1340 }
1341 gpd_data->refcount++;
1289 if (td) 1342 if (td)
1290 gpd_data->td = *td; 1343 gpd_data->td = *td;
1291 1344
1345 spin_unlock_irq(&dev->power.lock);
1346
1347 mutex_lock(&gpd_data->lock);
1348 gpd_data->base.dev = dev;
1349 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
1350 gpd_data->need_restore = genpd->status == GPD_STATE_POWER_OFF;
1292 gpd_data->td.constraint_changed = true; 1351 gpd_data->td.constraint_changed = true;
1293 gpd_data->td.effective_constraint_ns = -1; 1352 gpd_data->td.effective_constraint_ns = -1;
1294 spin_unlock_irq(&dev->power.lock);
1295 mutex_unlock(&gpd_data->lock); 1353 mutex_unlock(&gpd_data->lock);
1296 1354
1297 genpd_release_lock(genpd);
1298
1299 return 0;
1300
1301 out: 1355 out:
1302 genpd_release_lock(genpd); 1356 genpd_release_lock(genpd);
1303 1357
1304 dev_pm_qos_remove_notifier(dev, &gpd_data->nb); 1358 if (gpd_data != gpd_data_new)
1305 kfree(gpd_data); 1359 __pm_genpd_free_dev_data(dev, gpd_data_new);
1360
1306 return ret; 1361 return ret;
1307} 1362}
1308 1363
@@ -1348,6 +1403,7 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,
1348{ 1403{
1349 struct generic_pm_domain_data *gpd_data; 1404 struct generic_pm_domain_data *gpd_data;
1350 struct pm_domain_data *pdd; 1405 struct pm_domain_data *pdd;
1406 bool remove = false;
1351 int ret = 0; 1407 int ret = 0;
1352 1408
1353 dev_dbg(dev, "%s()\n", __func__); 1409 dev_dbg(dev, "%s()\n", __func__);
@@ -1368,22 +1424,28 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,
1368 genpd->max_off_time_changed = true; 1424 genpd->max_off_time_changed = true;
1369 1425
1370 spin_lock_irq(&dev->power.lock); 1426 spin_lock_irq(&dev->power.lock);
1427
1371 dev->pm_domain = NULL; 1428 dev->pm_domain = NULL;
1372 pdd = dev->power.subsys_data->domain_data; 1429 pdd = dev->power.subsys_data->domain_data;
1373 list_del_init(&pdd->list_node); 1430 list_del_init(&pdd->list_node);
1374 dev->power.subsys_data->domain_data = NULL; 1431 gpd_data = to_gpd_data(pdd);
1432 if (--gpd_data->refcount == 0) {
1433 dev->power.subsys_data->domain_data = NULL;
1434 remove = true;
1435 }
1436
1375 spin_unlock_irq(&dev->power.lock); 1437 spin_unlock_irq(&dev->power.lock);
1376 1438
1377 gpd_data = to_gpd_data(pdd);
1378 mutex_lock(&gpd_data->lock); 1439 mutex_lock(&gpd_data->lock);
1379 pdd->dev = NULL; 1440 pdd->dev = NULL;
1380 mutex_unlock(&gpd_data->lock); 1441 mutex_unlock(&gpd_data->lock);
1381 1442
1382 genpd_release_lock(genpd); 1443 genpd_release_lock(genpd);
1383 1444
1384 dev_pm_qos_remove_notifier(dev, &gpd_data->nb);
1385 kfree(gpd_data);
1386 dev_pm_put_subsys_data(dev); 1445 dev_pm_put_subsys_data(dev);
1446 if (remove)
1447 __pm_genpd_free_dev_data(dev, gpd_data);
1448
1387 return 0; 1449 return 0;
1388 1450
1389 out: 1451 out:
@@ -1541,33 +1603,52 @@ int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
1541 * @dev: Device to add the callbacks to. 1603 * @dev: Device to add the callbacks to.
1542 * @ops: Set of callbacks to add. 1604 * @ops: Set of callbacks to add.
1543 * @td: Timing data to add to the device along with the callbacks (optional). 1605 * @td: Timing data to add to the device along with the callbacks (optional).
1606 *
1607 * Every call to this routine should be balanced with a call to
1608 * __pm_genpd_remove_callbacks() and they must not be nested.
1544 */ 1609 */
1545int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops, 1610int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops,
1546 struct gpd_timing_data *td) 1611 struct gpd_timing_data *td)
1547{ 1612{
1548 struct pm_domain_data *pdd; 1613 struct generic_pm_domain_data *gpd_data_new, *gpd_data = NULL;
1549 int ret = 0; 1614 int ret = 0;
1550 1615
1551 if (!(dev && dev->power.subsys_data && ops)) 1616 if (!(dev && ops))
1552 return -EINVAL; 1617 return -EINVAL;
1553 1618
1619 gpd_data_new = __pm_genpd_alloc_dev_data(dev);
1620 if (!gpd_data_new)
1621 return -ENOMEM;
1622
1554 pm_runtime_disable(dev); 1623 pm_runtime_disable(dev);
1555 device_pm_lock(); 1624 device_pm_lock();
1556 1625
1557 pdd = dev->power.subsys_data->domain_data; 1626 ret = dev_pm_get_subsys_data(dev);
1558 if (pdd) { 1627 if (ret)
1559 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd); 1628 goto out;
1560 1629
1561 gpd_data->ops = *ops; 1630 spin_lock_irq(&dev->power.lock);
1562 if (td) 1631
1563 gpd_data->td = *td; 1632 if (dev->power.subsys_data->domain_data) {
1633 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
1564 } else { 1634 } else {
1565 ret = -EINVAL; 1635 gpd_data = gpd_data_new;
1636 dev->power.subsys_data->domain_data = &gpd_data->base;
1566 } 1637 }
1638 gpd_data->refcount++;
1639 gpd_data->ops = *ops;
1640 if (td)
1641 gpd_data->td = *td;
1642
1643 spin_unlock_irq(&dev->power.lock);
1567 1644
1645 out:
1568 device_pm_unlock(); 1646 device_pm_unlock();
1569 pm_runtime_enable(dev); 1647 pm_runtime_enable(dev);
1570 1648
1649 if (gpd_data != gpd_data_new)
1650 __pm_genpd_free_dev_data(dev, gpd_data_new);
1651
1571 return ret; 1652 return ret;
1572} 1653}
1573EXPORT_SYMBOL_GPL(pm_genpd_add_callbacks); 1654EXPORT_SYMBOL_GPL(pm_genpd_add_callbacks);
@@ -1576,10 +1657,13 @@ EXPORT_SYMBOL_GPL(pm_genpd_add_callbacks);
1576 * __pm_genpd_remove_callbacks - Remove PM domain callbacks from a given device. 1657 * __pm_genpd_remove_callbacks - Remove PM domain callbacks from a given device.
1577 * @dev: Device to remove the callbacks from. 1658 * @dev: Device to remove the callbacks from.
1578 * @clear_td: If set, clear the device's timing data too. 1659 * @clear_td: If set, clear the device's timing data too.
1660 *
1661 * This routine can only be called after pm_genpd_add_callbacks().
1579 */ 1662 */
1580int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td) 1663int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
1581{ 1664{
1582 struct pm_domain_data *pdd; 1665 struct generic_pm_domain_data *gpd_data = NULL;
1666 bool remove = false;
1583 int ret = 0; 1667 int ret = 0;
1584 1668
1585 if (!(dev && dev->power.subsys_data)) 1669 if (!(dev && dev->power.subsys_data))
@@ -1588,24 +1672,118 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
1588 pm_runtime_disable(dev); 1672 pm_runtime_disable(dev);
1589 device_pm_lock(); 1673 device_pm_lock();
1590 1674
1591 pdd = dev->power.subsys_data->domain_data; 1675 spin_lock_irq(&dev->power.lock);
1592 if (pdd) {
1593 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
1594 1676
1595 gpd_data->ops = (struct gpd_dev_ops){ 0 }; 1677 if (dev->power.subsys_data->domain_data) {
1678 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
1679 gpd_data->ops = (struct gpd_dev_ops){ NULL };
1596 if (clear_td) 1680 if (clear_td)
1597 gpd_data->td = (struct gpd_timing_data){ 0 }; 1681 gpd_data->td = (struct gpd_timing_data){ 0 };
1682
1683 if (--gpd_data->refcount == 0) {
1684 dev->power.subsys_data->domain_data = NULL;
1685 remove = true;
1686 }
1598 } else { 1687 } else {
1599 ret = -EINVAL; 1688 ret = -EINVAL;
1600 } 1689 }
1601 1690
1691 spin_unlock_irq(&dev->power.lock);
1692
1602 device_pm_unlock(); 1693 device_pm_unlock();
1603 pm_runtime_enable(dev); 1694 pm_runtime_enable(dev);
1604 1695
1605 return ret; 1696 if (ret)
1697 return ret;
1698
1699 dev_pm_put_subsys_data(dev);
1700 if (remove)
1701 __pm_genpd_free_dev_data(dev, gpd_data);
1702
1703 return 0;
1606} 1704}
1607EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks); 1705EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks);
1608 1706
1707int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
1708{
1709 struct cpuidle_driver *cpuidle_drv;
1710 struct gpd_cpu_data *cpu_data;
1711 struct cpuidle_state *idle_state;
1712 int ret = 0;
1713
1714 if (IS_ERR_OR_NULL(genpd) || state < 0)
1715 return -EINVAL;
1716
1717 genpd_acquire_lock(genpd);
1718
1719 if (genpd->cpu_data) {
1720 ret = -EEXIST;
1721 goto out;
1722 }
1723 cpu_data = kzalloc(sizeof(*cpu_data), GFP_KERNEL);
1724 if (!cpu_data) {
1725 ret = -ENOMEM;
1726 goto out;
1727 }
1728 cpuidle_drv = cpuidle_driver_ref();
1729 if (!cpuidle_drv) {
1730 ret = -ENODEV;
1731 goto out;
1732 }
1733 if (cpuidle_drv->state_count <= state) {
1734 ret = -EINVAL;
1735 goto err;
1736 }
1737 idle_state = &cpuidle_drv->states[state];
1738 if (!idle_state->disabled) {
1739 ret = -EAGAIN;
1740 goto err;
1741 }
1742 cpu_data->idle_state = idle_state;
1743 cpu_data->saved_exit_latency = idle_state->exit_latency;
1744 genpd->cpu_data = cpu_data;
1745 genpd_recalc_cpu_exit_latency(genpd);
1746
1747 out:
1748 genpd_release_lock(genpd);
1749 return ret;
1750
1751 err:
1752 cpuidle_driver_unref();
1753 goto out;
1754}
1755
1756int genpd_detach_cpuidle(struct generic_pm_domain *genpd)
1757{
1758 struct gpd_cpu_data *cpu_data;
1759 struct cpuidle_state *idle_state;
1760 int ret = 0;
1761
1762 if (IS_ERR_OR_NULL(genpd))
1763 return -EINVAL;
1764
1765 genpd_acquire_lock(genpd);
1766
1767 cpu_data = genpd->cpu_data;
1768 if (!cpu_data) {
1769 ret = -ENODEV;
1770 goto out;
1771 }
1772 idle_state = cpu_data->idle_state;
1773 if (!idle_state->disabled) {
1774 ret = -EAGAIN;
1775 goto out;
1776 }
1777 idle_state->exit_latency = cpu_data->saved_exit_latency;
1778 cpuidle_driver_unref();
1779 genpd->cpu_data = NULL;
1780 kfree(cpu_data);
1781
1782 out:
1783 genpd_release_lock(genpd);
1784 return ret;
1785}
1786
1609/* Default device callbacks for generic PM domains. */ 1787/* Default device callbacks for generic PM domains. */
1610 1788
1611/** 1789/**
@@ -1615,16 +1793,24 @@ EXPORT_SYMBOL_GPL(__pm_genpd_remove_callbacks);
1615static int pm_genpd_default_save_state(struct device *dev) 1793static int pm_genpd_default_save_state(struct device *dev)
1616{ 1794{
1617 int (*cb)(struct device *__dev); 1795 int (*cb)(struct device *__dev);
1618 struct device_driver *drv = dev->driver;
1619 1796
1620 cb = dev_gpd_data(dev)->ops.save_state; 1797 cb = dev_gpd_data(dev)->ops.save_state;
1621 if (cb) 1798 if (cb)
1622 return cb(dev); 1799 return cb(dev);
1623 1800
1624 if (drv && drv->pm && drv->pm->runtime_suspend) 1801 if (dev->type && dev->type->pm)
1625 return drv->pm->runtime_suspend(dev); 1802 cb = dev->type->pm->runtime_suspend;
1803 else if (dev->class && dev->class->pm)
1804 cb = dev->class->pm->runtime_suspend;
1805 else if (dev->bus && dev->bus->pm)
1806 cb = dev->bus->pm->runtime_suspend;
1807 else
1808 cb = NULL;
1626 1809
1627 return 0; 1810 if (!cb && dev->driver && dev->driver->pm)
1811 cb = dev->driver->pm->runtime_suspend;
1812
1813 return cb ? cb(dev) : 0;
1628} 1814}
1629 1815
1630/** 1816/**
@@ -1634,16 +1820,24 @@ static int pm_genpd_default_save_state(struct device *dev)
1634static int pm_genpd_default_restore_state(struct device *dev) 1820static int pm_genpd_default_restore_state(struct device *dev)
1635{ 1821{
1636 int (*cb)(struct device *__dev); 1822 int (*cb)(struct device *__dev);
1637 struct device_driver *drv = dev->driver;
1638 1823
1639 cb = dev_gpd_data(dev)->ops.restore_state; 1824 cb = dev_gpd_data(dev)->ops.restore_state;
1640 if (cb) 1825 if (cb)
1641 return cb(dev); 1826 return cb(dev);
1642 1827
1643 if (drv && drv->pm && drv->pm->runtime_resume) 1828 if (dev->type && dev->type->pm)
1644 return drv->pm->runtime_resume(dev); 1829 cb = dev->type->pm->runtime_resume;
1830 else if (dev->class && dev->class->pm)
1831 cb = dev->class->pm->runtime_resume;
1832 else if (dev->bus && dev->bus->pm)
1833 cb = dev->bus->pm->runtime_resume;
1834 else
1835 cb = NULL;
1645 1836
1646 return 0; 1837 if (!cb && dev->driver && dev->driver->pm)
1838 cb = dev->driver->pm->runtime_resume;
1839
1840 return cb ? cb(dev) : 0;
1647} 1841}
1648 1842
1649#ifdef CONFIG_PM_SLEEP 1843#ifdef CONFIG_PM_SLEEP
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 9cb845e49334..0113adc310dc 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -28,7 +28,7 @@
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/async.h> 29#include <linux/async.h>
30#include <linux/suspend.h> 30#include <linux/suspend.h>
31 31#include <linux/cpuidle.h>
32#include "../base.h" 32#include "../base.h"
33#include "power.h" 33#include "power.h"
34 34
@@ -45,10 +45,10 @@ typedef int (*pm_callback_t)(struct device *);
45 */ 45 */
46 46
47LIST_HEAD(dpm_list); 47LIST_HEAD(dpm_list);
48LIST_HEAD(dpm_prepared_list); 48static LIST_HEAD(dpm_prepared_list);
49LIST_HEAD(dpm_suspended_list); 49static LIST_HEAD(dpm_suspended_list);
50LIST_HEAD(dpm_late_early_list); 50static LIST_HEAD(dpm_late_early_list);
51LIST_HEAD(dpm_noirq_list); 51static LIST_HEAD(dpm_noirq_list);
52 52
53struct suspend_stats suspend_stats; 53struct suspend_stats suspend_stats;
54static DEFINE_MUTEX(dpm_list_mtx); 54static DEFINE_MUTEX(dpm_list_mtx);
@@ -166,7 +166,7 @@ static ktime_t initcall_debug_start(struct device *dev)
166{ 166{
167 ktime_t calltime = ktime_set(0, 0); 167 ktime_t calltime = ktime_set(0, 0);
168 168
169 if (initcall_debug) { 169 if (pm_print_times_enabled) {
170 pr_info("calling %s+ @ %i, parent: %s\n", 170 pr_info("calling %s+ @ %i, parent: %s\n",
171 dev_name(dev), task_pid_nr(current), 171 dev_name(dev), task_pid_nr(current),
172 dev->parent ? dev_name(dev->parent) : "none"); 172 dev->parent ? dev_name(dev->parent) : "none");
@@ -181,7 +181,7 @@ static void initcall_debug_report(struct device *dev, ktime_t calltime,
181{ 181{
182 ktime_t delta, rettime; 182 ktime_t delta, rettime;
183 183
184 if (initcall_debug) { 184 if (pm_print_times_enabled) {
185 rettime = ktime_get(); 185 rettime = ktime_get();
186 delta = ktime_sub(rettime, calltime); 186 delta = ktime_sub(rettime, calltime);
187 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev), 187 pr_info("call %s+ returned %d after %Ld usecs\n", dev_name(dev),
@@ -467,6 +467,7 @@ static void dpm_resume_noirq(pm_message_t state)
467 mutex_unlock(&dpm_list_mtx); 467 mutex_unlock(&dpm_list_mtx);
468 dpm_show_time(starttime, state, "noirq"); 468 dpm_show_time(starttime, state, "noirq");
469 resume_device_irqs(); 469 resume_device_irqs();
470 cpuidle_resume();
470} 471}
471 472
472/** 473/**
@@ -867,6 +868,7 @@ static int dpm_suspend_noirq(pm_message_t state)
867 ktime_t starttime = ktime_get(); 868 ktime_t starttime = ktime_get();
868 int error = 0; 869 int error = 0;
869 870
871 cpuidle_pause();
870 suspend_device_irqs(); 872 suspend_device_irqs();
871 mutex_lock(&dpm_list_mtx); 873 mutex_lock(&dpm_list_mtx);
872 while (!list_empty(&dpm_late_early_list)) { 874 while (!list_empty(&dpm_late_early_list)) {
@@ -989,8 +991,16 @@ static int dpm_suspend_late(pm_message_t state)
989int dpm_suspend_end(pm_message_t state) 991int dpm_suspend_end(pm_message_t state)
990{ 992{
991 int error = dpm_suspend_late(state); 993 int error = dpm_suspend_late(state);
994 if (error)
995 return error;
996
997 error = dpm_suspend_noirq(state);
998 if (error) {
999 dpm_resume_early(state);
1000 return error;
1001 }
992 1002
993 return error ? : dpm_suspend_noirq(state); 1003 return 0;
994} 1004}
995EXPORT_SYMBOL_GPL(dpm_suspend_end); 1005EXPORT_SYMBOL_GPL(dpm_suspend_end);
996 1006
diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c
index fd849a2c4fa8..74a67e0019a2 100644
--- a/drivers/base/power/qos.c
+++ b/drivers/base/power/qos.c
@@ -462,7 +462,7 @@ EXPORT_SYMBOL_GPL(dev_pm_qos_add_ancestor_request);
462static void __dev_pm_qos_drop_user_request(struct device *dev) 462static void __dev_pm_qos_drop_user_request(struct device *dev)
463{ 463{
464 dev_pm_qos_remove_request(dev->power.pq_req); 464 dev_pm_qos_remove_request(dev->power.pq_req);
465 dev->power.pq_req = 0; 465 dev->power.pq_req = NULL;
466} 466}
467 467
468/** 468/**
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 48be2ad4dd2c..b91dc6f1e914 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -474,6 +474,8 @@ static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL);
474 474
475#endif 475#endif
476 476
477#ifdef CONFIG_PM_SLEEP
478
477static ssize_t async_show(struct device *dev, struct device_attribute *attr, 479static ssize_t async_show(struct device *dev, struct device_attribute *attr,
478 char *buf) 480 char *buf)
479{ 481{
@@ -500,6 +502,8 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
500} 502}
501 503
502static DEVICE_ATTR(async, 0644, async_show, async_store); 504static DEVICE_ATTR(async, 0644, async_show, async_store);
505
506#endif
503#endif /* CONFIG_PM_ADVANCED_DEBUG */ 507#endif /* CONFIG_PM_ADVANCED_DEBUG */
504 508
505static struct attribute *power_attrs[] = { 509static struct attribute *power_attrs[] = {
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index 76fa3deaee84..1788f491e0fb 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -780,9 +780,9 @@ static const struct block_device_operations mg_disk_ops = {
780 .getgeo = mg_getgeo 780 .getgeo = mg_getgeo
781}; 781};
782 782
783static int mg_suspend(struct platform_device *plat_dev, pm_message_t state) 783static int mg_suspend(struct device *dev)
784{ 784{
785 struct mg_drv_data *prv_data = plat_dev->dev.platform_data; 785 struct mg_drv_data *prv_data = dev->platform_data;
786 struct mg_host *host = prv_data->host; 786 struct mg_host *host = prv_data->host;
787 787
788 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) 788 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
@@ -804,9 +804,9 @@ static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
804 return 0; 804 return 0;
805} 805}
806 806
807static int mg_resume(struct platform_device *plat_dev) 807static int mg_resume(struct device *dev)
808{ 808{
809 struct mg_drv_data *prv_data = plat_dev->dev.platform_data; 809 struct mg_drv_data *prv_data = dev->platform_data;
810 struct mg_host *host = prv_data->host; 810 struct mg_host *host = prv_data->host;
811 811
812 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) 812 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD))
@@ -825,6 +825,8 @@ static int mg_resume(struct platform_device *plat_dev)
825 return 0; 825 return 0;
826} 826}
827 827
828static SIMPLE_DEV_PM_OPS(mg_pm, mg_suspend, mg_resume);
829
828static int mg_probe(struct platform_device *plat_dev) 830static int mg_probe(struct platform_device *plat_dev)
829{ 831{
830 struct mg_host *host; 832 struct mg_host *host;
@@ -1074,11 +1076,10 @@ static int mg_remove(struct platform_device *plat_dev)
1074static struct platform_driver mg_disk_driver = { 1076static struct platform_driver mg_disk_driver = {
1075 .probe = mg_probe, 1077 .probe = mg_probe,
1076 .remove = mg_remove, 1078 .remove = mg_remove,
1077 .suspend = mg_suspend,
1078 .resume = mg_resume,
1079 .driver = { 1079 .driver = {
1080 .name = MG_DEV_NAME, 1080 .name = MG_DEV_NAME,
1081 .owner = THIS_MODULE, 1081 .owner = THIS_MODULE,
1082 .pm = &mg_pm,
1082 } 1083 }
1083}; 1084};
1084 1085
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 1412565c01af..d706bd0e9e80 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -162,22 +162,24 @@ static int __exit omap_rng_remove(struct platform_device *pdev)
162 162
163#ifdef CONFIG_PM 163#ifdef CONFIG_PM
164 164
165static int omap_rng_suspend(struct platform_device *pdev, pm_message_t message) 165static int omap_rng_suspend(struct device *dev)
166{ 166{
167 omap_rng_write_reg(RNG_MASK_REG, 0x0); 167 omap_rng_write_reg(RNG_MASK_REG, 0x0);
168 return 0; 168 return 0;
169} 169}
170 170
171static int omap_rng_resume(struct platform_device *pdev) 171static int omap_rng_resume(struct device *dev)
172{ 172{
173 omap_rng_write_reg(RNG_MASK_REG, 0x1); 173 omap_rng_write_reg(RNG_MASK_REG, 0x1);
174 return 0; 174 return 0;
175} 175}
176 176
177static SIMPLE_DEV_PM_OPS(omap_rng_pm, omap_rng_suspend, omap_rng_resume);
178#define OMAP_RNG_PM (&omap_rng_pm)
179
177#else 180#else
178 181
179#define omap_rng_suspend NULL 182#define OMAP_RNG_PM NULL
180#define omap_rng_resume NULL
181 183
182#endif 184#endif
183 185
@@ -188,11 +190,10 @@ static struct platform_driver omap_rng_driver = {
188 .driver = { 190 .driver = {
189 .name = "omap_rng", 191 .name = "omap_rng",
190 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
193 .pm = OMAP_RNG_PM,
191 }, 194 },
192 .probe = omap_rng_probe, 195 .probe = omap_rng_probe,
193 .remove = __exit_p(omap_rng_remove), 196 .remove = __exit_p(omap_rng_remove),
194 .suspend = omap_rng_suspend,
195 .resume = omap_rng_resume
196}; 197};
197 198
198static int __init omap_rng_init(void) 199static int __init omap_rng_init(void)
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 1e638fff40ea..83f85cf7fb1b 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -2503,18 +2503,6 @@ static void __devexit ipmi_pci_remove(struct pci_dev *pdev)
2503 cleanup_one_si(info); 2503 cleanup_one_si(info);
2504} 2504}
2505 2505
2506#ifdef CONFIG_PM
2507static int ipmi_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2508{
2509 return 0;
2510}
2511
2512static int ipmi_pci_resume(struct pci_dev *pdev)
2513{
2514 return 0;
2515}
2516#endif
2517
2518static struct pci_device_id ipmi_pci_devices[] = { 2506static struct pci_device_id ipmi_pci_devices[] = {
2519 { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) }, 2507 { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
2520 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) }, 2508 { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) },
@@ -2527,10 +2515,6 @@ static struct pci_driver ipmi_pci_driver = {
2527 .id_table = ipmi_pci_devices, 2515 .id_table = ipmi_pci_devices,
2528 .probe = ipmi_pci_probe, 2516 .probe = ipmi_pci_probe,
2529 .remove = __devexit_p(ipmi_pci_remove), 2517 .remove = __devexit_p(ipmi_pci_remove),
2530#ifdef CONFIG_PM
2531 .suspend = ipmi_pci_suspend,
2532 .resume = ipmi_pci_resume,
2533#endif
2534}; 2518};
2535#endif /* CONFIG_PCI */ 2519#endif /* CONFIG_PCI */
2536 2520
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index 45713f0e7d61..f87780502b41 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -1459,7 +1459,7 @@ static int __devexit sonypi_remove(struct platform_device *dev)
1459#ifdef CONFIG_PM 1459#ifdef CONFIG_PM
1460static int old_camera_power; 1460static int old_camera_power;
1461 1461
1462static int sonypi_suspend(struct platform_device *dev, pm_message_t state) 1462static int sonypi_suspend(struct device *dev)
1463{ 1463{
1464 old_camera_power = sonypi_device.camera_power; 1464 old_camera_power = sonypi_device.camera_power;
1465 sonypi_disable(); 1465 sonypi_disable();
@@ -1467,14 +1467,16 @@ static int sonypi_suspend(struct platform_device *dev, pm_message_t state)
1467 return 0; 1467 return 0;
1468} 1468}
1469 1469
1470static int sonypi_resume(struct platform_device *dev) 1470static int sonypi_resume(struct device *dev)
1471{ 1471{
1472 sonypi_enable(old_camera_power); 1472 sonypi_enable(old_camera_power);
1473 return 0; 1473 return 0;
1474} 1474}
1475
1476static SIMPLE_DEV_PM_OPS(sonypi_pm, sonypi_suspend, sonypi_resume);
1477#define SONYPI_PM (&sonypi_pm)
1475#else 1478#else
1476#define sonypi_suspend NULL 1479#define SONYPI_PM NULL
1477#define sonypi_resume NULL
1478#endif 1480#endif
1479 1481
1480static void sonypi_shutdown(struct platform_device *dev) 1482static void sonypi_shutdown(struct platform_device *dev)
@@ -1486,12 +1488,11 @@ static struct platform_driver sonypi_driver = {
1486 .driver = { 1488 .driver = {
1487 .name = "sonypi", 1489 .name = "sonypi",
1488 .owner = THIS_MODULE, 1490 .owner = THIS_MODULE,
1491 .pm = SONYPI_PM,
1489 }, 1492 },
1490 .probe = sonypi_probe, 1493 .probe = sonypi_probe,
1491 .remove = __devexit_p(sonypi_remove), 1494 .remove = __devexit_p(sonypi_remove),
1492 .shutdown = sonypi_shutdown, 1495 .shutdown = sonypi_shutdown,
1493 .suspend = sonypi_suspend,
1494 .resume = sonypi_resume,
1495}; 1496};
1496 1497
1497static struct platform_device *sonypi_platform_device; 1498static struct platform_device *sonypi_platform_device;
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index ad7c7320dd1b..ae43ac55fc1e 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -1274,7 +1274,7 @@ static struct tpm_input_header savestate_header = {
1274 * We are about to suspend. Save the TPM state 1274 * We are about to suspend. Save the TPM state
1275 * so that it can be restored. 1275 * so that it can be restored.
1276 */ 1276 */
1277int tpm_pm_suspend(struct device *dev, pm_message_t pm_state) 1277int tpm_pm_suspend(struct device *dev)
1278{ 1278{
1279 struct tpm_chip *chip = dev_get_drvdata(dev); 1279 struct tpm_chip *chip = dev_get_drvdata(dev);
1280 struct tpm_cmd_t cmd; 1280 struct tpm_cmd_t cmd;
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index b1c5280ac159..917f727e6740 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -299,7 +299,7 @@ extern ssize_t tpm_write(struct file *, const char __user *, size_t,
299 loff_t *); 299 loff_t *);
300extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *); 300extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
301extern void tpm_remove_hardware(struct device *); 301extern void tpm_remove_hardware(struct device *);
302extern int tpm_pm_suspend(struct device *, pm_message_t); 302extern int tpm_pm_suspend(struct device *);
303extern int tpm_pm_resume(struct device *); 303extern int tpm_pm_resume(struct device *);
304extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long, 304extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long,
305 wait_queue_head_t *); 305 wait_queue_head_t *);
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index c64a1bc65349..678d57019dc4 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -168,22 +168,14 @@ static void atml_plat_remove(void)
168 } 168 }
169} 169}
170 170
171static int tpm_atml_suspend(struct platform_device *dev, pm_message_t msg) 171static SIMPLE_DEV_PM_OPS(tpm_atml_pm, tpm_pm_suspend, tpm_pm_resume);
172{
173 return tpm_pm_suspend(&dev->dev, msg);
174}
175 172
176static int tpm_atml_resume(struct platform_device *dev)
177{
178 return tpm_pm_resume(&dev->dev);
179}
180static struct platform_driver atml_drv = { 173static struct platform_driver atml_drv = {
181 .driver = { 174 .driver = {
182 .name = "tpm_atmel", 175 .name = "tpm_atmel",
183 .owner = THIS_MODULE, 176 .owner = THIS_MODULE,
177 .pm = &tpm_atml_pm,
184 }, 178 },
185 .suspend = tpm_atml_suspend,
186 .resume = tpm_atml_resume,
187}; 179};
188 180
189static int __init init_atmel(void) 181static int __init init_atmel(void)
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 4d2464871ada..640c9a427b59 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -274,22 +274,13 @@ static void tpm_nsc_remove(struct device *dev)
274 } 274 }
275} 275}
276 276
277static int tpm_nsc_suspend(struct platform_device *dev, pm_message_t msg) 277static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
278{
279 return tpm_pm_suspend(&dev->dev, msg);
280}
281
282static int tpm_nsc_resume(struct platform_device *dev)
283{
284 return tpm_pm_resume(&dev->dev);
285}
286 278
287static struct platform_driver nsc_drv = { 279static struct platform_driver nsc_drv = {
288 .suspend = tpm_nsc_suspend,
289 .resume = tpm_nsc_resume,
290 .driver = { 280 .driver = {
291 .name = "tpm_nsc", 281 .name = "tpm_nsc",
292 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
283 .pm = &tpm_nsc_pm,
293 }, 284 },
294}; 285};
295 286
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index d2a70cae76df..89682fa8801e 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -750,7 +750,7 @@ static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
750 750
751static int tpm_tis_pnp_suspend(struct pnp_dev *dev, pm_message_t msg) 751static int tpm_tis_pnp_suspend(struct pnp_dev *dev, pm_message_t msg)
752{ 752{
753 return tpm_pm_suspend(&dev->dev, msg); 753 return tpm_pm_suspend(&dev->dev);
754} 754}
755 755
756static int tpm_tis_pnp_resume(struct pnp_dev *dev) 756static int tpm_tis_pnp_resume(struct pnp_dev *dev)
@@ -806,27 +806,25 @@ module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
806 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); 806 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
807MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe"); 807MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
808#endif 808#endif
809static int tpm_tis_suspend(struct platform_device *dev, pm_message_t msg)
810{
811 return tpm_pm_suspend(&dev->dev, msg);
812}
813 809
814static int tpm_tis_resume(struct platform_device *dev) 810static int tpm_tis_resume(struct device *dev)
815{ 811{
816 struct tpm_chip *chip = dev_get_drvdata(&dev->dev); 812 struct tpm_chip *chip = dev_get_drvdata(dev);
817 813
818 if (chip->vendor.irq) 814 if (chip->vendor.irq)
819 tpm_tis_reenable_interrupts(chip); 815 tpm_tis_reenable_interrupts(chip);
820 816
821 return tpm_pm_resume(&dev->dev); 817 return tpm_pm_resume(dev);
822} 818}
819
820static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
821
823static struct platform_driver tis_drv = { 822static struct platform_driver tis_drv = {
824 .driver = { 823 .driver = {
825 .name = "tpm_tis", 824 .name = "tpm_tis",
826 .owner = THIS_MODULE, 825 .owner = THIS_MODULE,
826 .pm = &tpm_tis_pm,
827 }, 827 },
828 .suspend = tpm_tis_suspend,
829 .resume = tpm_tis_resume,
830}; 828};
831 829
832static struct platform_device *pdev; 830static struct platform_device *pdev;
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 7f2f149ae40f..fb8a5279c5d8 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -138,7 +138,7 @@ void disable_cpufreq(void)
138static LIST_HEAD(cpufreq_governor_list); 138static LIST_HEAD(cpufreq_governor_list);
139static DEFINE_MUTEX(cpufreq_governor_mutex); 139static DEFINE_MUTEX(cpufreq_governor_mutex);
140 140
141struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) 141static struct cpufreq_policy *__cpufreq_cpu_get(unsigned int cpu, bool sysfs)
142{ 142{
143 struct cpufreq_policy *data; 143 struct cpufreq_policy *data;
144 unsigned long flags; 144 unsigned long flags;
@@ -162,7 +162,7 @@ struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
162 if (!data) 162 if (!data)
163 goto err_out_put_module; 163 goto err_out_put_module;
164 164
165 if (!kobject_get(&data->kobj)) 165 if (!sysfs && !kobject_get(&data->kobj))
166 goto err_out_put_module; 166 goto err_out_put_module;
167 167
168 spin_unlock_irqrestore(&cpufreq_driver_lock, flags); 168 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
@@ -175,16 +175,35 @@ err_out_unlock:
175err_out: 175err_out:
176 return NULL; 176 return NULL;
177} 177}
178
179struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
180{
181 return __cpufreq_cpu_get(cpu, false);
182}
178EXPORT_SYMBOL_GPL(cpufreq_cpu_get); 183EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
179 184
185static struct cpufreq_policy *cpufreq_cpu_get_sysfs(unsigned int cpu)
186{
187 return __cpufreq_cpu_get(cpu, true);
188}
180 189
181void cpufreq_cpu_put(struct cpufreq_policy *data) 190static void __cpufreq_cpu_put(struct cpufreq_policy *data, bool sysfs)
182{ 191{
183 kobject_put(&data->kobj); 192 if (!sysfs)
193 kobject_put(&data->kobj);
184 module_put(cpufreq_driver->owner); 194 module_put(cpufreq_driver->owner);
185} 195}
196
197void cpufreq_cpu_put(struct cpufreq_policy *data)
198{
199 __cpufreq_cpu_put(data, false);
200}
186EXPORT_SYMBOL_GPL(cpufreq_cpu_put); 201EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
187 202
203static void cpufreq_cpu_put_sysfs(struct cpufreq_policy *data)
204{
205 __cpufreq_cpu_put(data, true);
206}
188 207
189/********************************************************************* 208/*********************************************************************
190 * EXTERNALLY AFFECTING FREQUENCY CHANGES * 209 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
@@ -617,7 +636,7 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
617 struct cpufreq_policy *policy = to_policy(kobj); 636 struct cpufreq_policy *policy = to_policy(kobj);
618 struct freq_attr *fattr = to_attr(attr); 637 struct freq_attr *fattr = to_attr(attr);
619 ssize_t ret = -EINVAL; 638 ssize_t ret = -EINVAL;
620 policy = cpufreq_cpu_get(policy->cpu); 639 policy = cpufreq_cpu_get_sysfs(policy->cpu);
621 if (!policy) 640 if (!policy)
622 goto no_policy; 641 goto no_policy;
623 642
@@ -631,7 +650,7 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
631 650
632 unlock_policy_rwsem_read(policy->cpu); 651 unlock_policy_rwsem_read(policy->cpu);
633fail: 652fail:
634 cpufreq_cpu_put(policy); 653 cpufreq_cpu_put_sysfs(policy);
635no_policy: 654no_policy:
636 return ret; 655 return ret;
637} 656}
@@ -642,7 +661,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
642 struct cpufreq_policy *policy = to_policy(kobj); 661 struct cpufreq_policy *policy = to_policy(kobj);
643 struct freq_attr *fattr = to_attr(attr); 662 struct freq_attr *fattr = to_attr(attr);
644 ssize_t ret = -EINVAL; 663 ssize_t ret = -EINVAL;
645 policy = cpufreq_cpu_get(policy->cpu); 664 policy = cpufreq_cpu_get_sysfs(policy->cpu);
646 if (!policy) 665 if (!policy)
647 goto no_policy; 666 goto no_policy;
648 667
@@ -656,7 +675,7 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
656 675
657 unlock_policy_rwsem_write(policy->cpu); 676 unlock_policy_rwsem_write(policy->cpu);
658fail: 677fail:
659 cpufreq_cpu_put(policy); 678 cpufreq_cpu_put_sysfs(policy);
660no_policy: 679no_policy:
661 return ret; 680 return ret;
662} 681}
diff --git a/drivers/cpufreq/exynos-cpufreq.c b/drivers/cpufreq/exynos-cpufreq.c
index b243a7ee01f6..af2d81e10f71 100644
--- a/drivers/cpufreq/exynos-cpufreq.c
+++ b/drivers/cpufreq/exynos-cpufreq.c
@@ -62,8 +62,18 @@ static int exynos_target(struct cpufreq_policy *policy,
62 goto out; 62 goto out;
63 } 63 }
64 64
65 if (cpufreq_frequency_table_target(policy, freq_table, 65 /*
66 freqs.old, relation, &old_index)) { 66 * The policy max have been changed so that we cannot get proper
67 * old_index with cpufreq_frequency_table_target(). Thus, ignore
68 * policy and get the index from the raw freqeuncy table.
69 */
70 for (old_index = 0;
71 freq_table[old_index].frequency != CPUFREQ_TABLE_END;
72 old_index++)
73 if (freq_table[old_index].frequency == freqs.old)
74 break;
75
76 if (freq_table[old_index].frequency == CPUFREQ_TABLE_END) {
67 ret = -EINVAL; 77 ret = -EINVAL;
68 goto out; 78 goto out;
69 } 79 }
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index d90519cec880..d6a533e68e0f 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -201,6 +201,22 @@ void cpuidle_resume_and_unlock(void)
201 201
202EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock); 202EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock);
203 203
204/* Currently used in suspend/resume path to suspend cpuidle */
205void cpuidle_pause(void)
206{
207 mutex_lock(&cpuidle_lock);
208 cpuidle_uninstall_idle_handler();
209 mutex_unlock(&cpuidle_lock);
210}
211
212/* Currently used in suspend/resume path to resume cpuidle */
213void cpuidle_resume(void)
214{
215 mutex_lock(&cpuidle_lock);
216 cpuidle_install_idle_handler();
217 mutex_unlock(&cpuidle_lock);
218}
219
204/** 220/**
205 * cpuidle_wrap_enter - performs timekeeping and irqen around enter function 221 * cpuidle_wrap_enter - performs timekeeping and irqen around enter function
206 * @dev: pointer to a valid cpuidle_device object 222 * @dev: pointer to a valid cpuidle_device object
@@ -265,7 +281,7 @@ static void poll_idle_init(struct cpuidle_driver *drv)
265 state->power_usage = -1; 281 state->power_usage = -1;
266 state->flags = 0; 282 state->flags = 0;
267 state->enter = poll_idle; 283 state->enter = poll_idle;
268 state->disable = 0; 284 state->disabled = false;
269} 285}
270#else 286#else
271static void poll_idle_init(struct cpuidle_driver *drv) {} 287static void poll_idle_init(struct cpuidle_driver *drv) {}
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 40cd3f3024df..58bf3b1ac9c4 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -16,6 +16,7 @@
16 16
17static struct cpuidle_driver *cpuidle_curr_driver; 17static struct cpuidle_driver *cpuidle_curr_driver;
18DEFINE_SPINLOCK(cpuidle_driver_lock); 18DEFINE_SPINLOCK(cpuidle_driver_lock);
19int cpuidle_driver_refcount;
19 20
20static void __cpuidle_register_driver(struct cpuidle_driver *drv) 21static void __cpuidle_register_driver(struct cpuidle_driver *drv)
21{ 22{
@@ -89,8 +90,34 @@ void cpuidle_unregister_driver(struct cpuidle_driver *drv)
89 } 90 }
90 91
91 spin_lock(&cpuidle_driver_lock); 92 spin_lock(&cpuidle_driver_lock);
92 cpuidle_curr_driver = NULL; 93
94 if (!WARN_ON(cpuidle_driver_refcount > 0))
95 cpuidle_curr_driver = NULL;
96
93 spin_unlock(&cpuidle_driver_lock); 97 spin_unlock(&cpuidle_driver_lock);
94} 98}
95 99
96EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); 100EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
101
102struct cpuidle_driver *cpuidle_driver_ref(void)
103{
104 struct cpuidle_driver *drv;
105
106 spin_lock(&cpuidle_driver_lock);
107
108 drv = cpuidle_curr_driver;
109 cpuidle_driver_refcount++;
110
111 spin_unlock(&cpuidle_driver_lock);
112 return drv;
113}
114
115void cpuidle_driver_unref(void)
116{
117 spin_lock(&cpuidle_driver_lock);
118
119 if (!WARN_ON(cpuidle_driver_refcount <= 0))
120 cpuidle_driver_refcount--;
121
122 spin_unlock(&cpuidle_driver_lock);
123}
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 06335756ea14..5b1f2c372c1f 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -281,7 +281,8 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
281 * unless the timer is happening really really soon. 281 * unless the timer is happening really really soon.
282 */ 282 */
283 if (data->expected_us > 5 && 283 if (data->expected_us > 5 &&
284 drv->states[CPUIDLE_DRIVER_STATE_START].disable == 0) 284 !drv->states[CPUIDLE_DRIVER_STATE_START].disabled &&
285 dev->states_usage[CPUIDLE_DRIVER_STATE_START].disable == 0)
285 data->last_state_idx = CPUIDLE_DRIVER_STATE_START; 286 data->last_state_idx = CPUIDLE_DRIVER_STATE_START;
286 287
287 /* 288 /*
@@ -290,8 +291,9 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev)
290 */ 291 */
291 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) { 292 for (i = CPUIDLE_DRIVER_STATE_START; i < drv->state_count; i++) {
292 struct cpuidle_state *s = &drv->states[i]; 293 struct cpuidle_state *s = &drv->states[i];
294 struct cpuidle_state_usage *su = &dev->states_usage[i];
293 295
294 if (s->disable) 296 if (s->disabled || su->disable)
295 continue; 297 continue;
296 if (s->target_residency > data->predicted_us) 298 if (s->target_residency > data->predicted_us)
297 continue; 299 continue;
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index 88032b4dc6d2..5f809e337b89 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -217,7 +217,8 @@ struct cpuidle_state_attr {
217 struct attribute attr; 217 struct attribute attr;
218 ssize_t (*show)(struct cpuidle_state *, \ 218 ssize_t (*show)(struct cpuidle_state *, \
219 struct cpuidle_state_usage *, char *); 219 struct cpuidle_state_usage *, char *);
220 ssize_t (*store)(struct cpuidle_state *, const char *, size_t); 220 ssize_t (*store)(struct cpuidle_state *, \
221 struct cpuidle_state_usage *, const char *, size_t);
221}; 222};
222 223
223#define define_one_state_ro(_name, show) \ 224#define define_one_state_ro(_name, show) \
@@ -233,21 +234,22 @@ static ssize_t show_state_##_name(struct cpuidle_state *state, \
233 return sprintf(buf, "%u\n", state->_name);\ 234 return sprintf(buf, "%u\n", state->_name);\
234} 235}
235 236
236#define define_store_state_function(_name) \ 237#define define_store_state_ull_function(_name) \
237static ssize_t store_state_##_name(struct cpuidle_state *state, \ 238static ssize_t store_state_##_name(struct cpuidle_state *state, \
239 struct cpuidle_state_usage *state_usage, \
238 const char *buf, size_t size) \ 240 const char *buf, size_t size) \
239{ \ 241{ \
240 long value; \ 242 unsigned long long value; \
241 int err; \ 243 int err; \
242 if (!capable(CAP_SYS_ADMIN)) \ 244 if (!capable(CAP_SYS_ADMIN)) \
243 return -EPERM; \ 245 return -EPERM; \
244 err = kstrtol(buf, 0, &value); \ 246 err = kstrtoull(buf, 0, &value); \
245 if (err) \ 247 if (err) \
246 return err; \ 248 return err; \
247 if (value) \ 249 if (value) \
248 state->disable = 1; \ 250 state_usage->_name = 1; \
249 else \ 251 else \
250 state->disable = 0; \ 252 state_usage->_name = 0; \
251 return size; \ 253 return size; \
252} 254}
253 255
@@ -273,8 +275,8 @@ define_show_state_ull_function(usage)
273define_show_state_ull_function(time) 275define_show_state_ull_function(time)
274define_show_state_str_function(name) 276define_show_state_str_function(name)
275define_show_state_str_function(desc) 277define_show_state_str_function(desc)
276define_show_state_function(disable) 278define_show_state_ull_function(disable)
277define_store_state_function(disable) 279define_store_state_ull_function(disable)
278 280
279define_one_state_ro(name, show_state_name); 281define_one_state_ro(name, show_state_name);
280define_one_state_ro(desc, show_state_desc); 282define_one_state_ro(desc, show_state_desc);
@@ -318,10 +320,11 @@ static ssize_t cpuidle_state_store(struct kobject *kobj,
318{ 320{
319 int ret = -EIO; 321 int ret = -EIO;
320 struct cpuidle_state *state = kobj_to_state(kobj); 322 struct cpuidle_state *state = kobj_to_state(kobj);
323 struct cpuidle_state_usage *state_usage = kobj_to_state_usage(kobj);
321 struct cpuidle_state_attr *cattr = attr_to_stateattr(attr); 324 struct cpuidle_state_attr *cattr = attr_to_stateattr(attr);
322 325
323 if (cattr->store) 326 if (cattr->store)
324 ret = cattr->store(state, buf, size); 327 ret = cattr->store(state, state_usage, buf, size);
325 328
326 return ret; 329 return ret;
327} 330}
diff --git a/drivers/crypto/ux500/cryp/cryp_core.c b/drivers/crypto/ux500/cryp/cryp_core.c
index 7cac12793a4b..1c307e1b840c 100644
--- a/drivers/crypto/ux500/cryp/cryp_core.c
+++ b/drivers/crypto/ux500/cryp/cryp_core.c
@@ -1661,27 +1661,26 @@ static void ux500_cryp_shutdown(struct platform_device *pdev)
1661 1661
1662} 1662}
1663 1663
1664static int ux500_cryp_suspend(struct platform_device *pdev, pm_message_t state) 1664static int ux500_cryp_suspend(struct device *dev)
1665{ 1665{
1666 int ret; 1666 int ret;
1667 struct platform_device *pdev = to_platform_device(dev);
1667 struct cryp_device_data *device_data; 1668 struct cryp_device_data *device_data;
1668 struct resource *res_irq; 1669 struct resource *res_irq;
1669 struct cryp_ctx *temp_ctx = NULL; 1670 struct cryp_ctx *temp_ctx = NULL;
1670 1671
1671 dev_dbg(&pdev->dev, "[%s]", __func__); 1672 dev_dbg(dev, "[%s]", __func__);
1672 1673
1673 /* Handle state? */ 1674 /* Handle state? */
1674 device_data = platform_get_drvdata(pdev); 1675 device_data = platform_get_drvdata(pdev);
1675 if (!device_data) { 1676 if (!device_data) {
1676 dev_err(&pdev->dev, "[%s]: platform_get_drvdata() failed!", 1677 dev_err(dev, "[%s]: platform_get_drvdata() failed!", __func__);
1677 __func__);
1678 return -ENOMEM; 1678 return -ENOMEM;
1679 } 1679 }
1680 1680
1681 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1681 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1682 if (!res_irq) 1682 if (!res_irq)
1683 dev_err(&pdev->dev, "[%s]: IORESOURCE_IRQ, unavailable", 1683 dev_err(dev, "[%s]: IORESOURCE_IRQ, unavailable", __func__);
1684 __func__);
1685 else 1684 else
1686 disable_irq(res_irq->start); 1685 disable_irq(res_irq->start);
1687 1686
@@ -1692,32 +1691,32 @@ static int ux500_cryp_suspend(struct platform_device *pdev, pm_message_t state)
1692 1691
1693 if (device_data->current_ctx == ++temp_ctx) { 1692 if (device_data->current_ctx == ++temp_ctx) {
1694 if (down_interruptible(&driver_data.device_allocation)) 1693 if (down_interruptible(&driver_data.device_allocation))
1695 dev_dbg(&pdev->dev, "[%s]: down_interruptible() " 1694 dev_dbg(dev, "[%s]: down_interruptible() failed",
1696 "failed", __func__); 1695 __func__);
1697 ret = cryp_disable_power(&pdev->dev, device_data, false); 1696 ret = cryp_disable_power(dev, device_data, false);
1698 1697
1699 } else 1698 } else
1700 ret = cryp_disable_power(&pdev->dev, device_data, true); 1699 ret = cryp_disable_power(dev, device_data, true);
1701 1700
1702 if (ret) 1701 if (ret)
1703 dev_err(&pdev->dev, "[%s]: cryp_disable_power()", __func__); 1702 dev_err(dev, "[%s]: cryp_disable_power()", __func__);
1704 1703
1705 return ret; 1704 return ret;
1706} 1705}
1707 1706
1708static int ux500_cryp_resume(struct platform_device *pdev) 1707static int ux500_cryp_resume(struct device *dev)
1709{ 1708{
1710 int ret = 0; 1709 int ret = 0;
1710 struct platform_device *pdev = to_platform_device(dev);
1711 struct cryp_device_data *device_data; 1711 struct cryp_device_data *device_data;
1712 struct resource *res_irq; 1712 struct resource *res_irq;
1713 struct cryp_ctx *temp_ctx = NULL; 1713 struct cryp_ctx *temp_ctx = NULL;
1714 1714
1715 dev_dbg(&pdev->dev, "[%s]", __func__); 1715 dev_dbg(dev, "[%s]", __func__);
1716 1716
1717 device_data = platform_get_drvdata(pdev); 1717 device_data = platform_get_drvdata(pdev);
1718 if (!device_data) { 1718 if (!device_data) {
1719 dev_err(&pdev->dev, "[%s]: platform_get_drvdata() failed!", 1719 dev_err(dev, "[%s]: platform_get_drvdata() failed!", __func__);
1720 __func__);
1721 return -ENOMEM; 1720 return -ENOMEM;
1722 } 1721 }
1723 1722
@@ -1730,11 +1729,10 @@ static int ux500_cryp_resume(struct platform_device *pdev)
1730 if (!device_data->current_ctx) 1729 if (!device_data->current_ctx)
1731 up(&driver_data.device_allocation); 1730 up(&driver_data.device_allocation);
1732 else 1731 else
1733 ret = cryp_enable_power(&pdev->dev, device_data, true); 1732 ret = cryp_enable_power(dev, device_data, true);
1734 1733
1735 if (ret) 1734 if (ret)
1736 dev_err(&pdev->dev, "[%s]: cryp_enable_power() failed!", 1735 dev_err(dev, "[%s]: cryp_enable_power() failed!", __func__);
1737 __func__);
1738 else { 1736 else {
1739 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 1737 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
1740 if (res_irq) 1738 if (res_irq)
@@ -1744,15 +1742,16 @@ static int ux500_cryp_resume(struct platform_device *pdev)
1744 return ret; 1742 return ret;
1745} 1743}
1746 1744
1745static SIMPLE_DEV_PM_OPS(ux500_cryp_pm, ux500_cryp_suspend, ux500_cryp_resume);
1746
1747static struct platform_driver cryp_driver = { 1747static struct platform_driver cryp_driver = {
1748 .probe = ux500_cryp_probe, 1748 .probe = ux500_cryp_probe,
1749 .remove = ux500_cryp_remove, 1749 .remove = ux500_cryp_remove,
1750 .shutdown = ux500_cryp_shutdown, 1750 .shutdown = ux500_cryp_shutdown,
1751 .suspend = ux500_cryp_suspend,
1752 .resume = ux500_cryp_resume,
1753 .driver = { 1751 .driver = {
1754 .owner = THIS_MODULE, 1752 .owner = THIS_MODULE,
1755 .name = "cryp1" 1753 .name = "cryp1"
1754 .pm = &ux500_cryp_pm,
1756 } 1755 }
1757}; 1756};
1758 1757
diff --git a/drivers/crypto/ux500/hash/hash_core.c b/drivers/crypto/ux500/hash/hash_core.c
index 6dbb9ec709a3..08d5032cb564 100644
--- a/drivers/crypto/ux500/hash/hash_core.c
+++ b/drivers/crypto/ux500/hash/hash_core.c
@@ -1894,19 +1894,17 @@ static void ux500_hash_shutdown(struct platform_device *pdev)
1894 1894
1895/** 1895/**
1896 * ux500_hash_suspend - Function that suspends the hash device. 1896 * ux500_hash_suspend - Function that suspends the hash device.
1897 * @pdev: The platform device. 1897 * @dev: Device to suspend.
1898 * @state: -
1899 */ 1898 */
1900static int ux500_hash_suspend(struct platform_device *pdev, pm_message_t state) 1899static int ux500_hash_suspend(struct device *dev)
1901{ 1900{
1902 int ret; 1901 int ret;
1903 struct hash_device_data *device_data; 1902 struct hash_device_data *device_data;
1904 struct hash_ctx *temp_ctx = NULL; 1903 struct hash_ctx *temp_ctx = NULL;
1905 1904
1906 device_data = platform_get_drvdata(pdev); 1905 device_data = dev_get_drvdata(dev);
1907 if (!device_data) { 1906 if (!device_data) {
1908 dev_err(&pdev->dev, "[%s] platform_get_drvdata() failed!", 1907 dev_err(dev, "[%s] platform_get_drvdata() failed!", __func__);
1909 __func__);
1910 return -ENOMEM; 1908 return -ENOMEM;
1911 } 1909 }
1912 1910
@@ -1917,33 +1915,32 @@ static int ux500_hash_suspend(struct platform_device *pdev, pm_message_t state)
1917 1915
1918 if (device_data->current_ctx == ++temp_ctx) { 1916 if (device_data->current_ctx == ++temp_ctx) {
1919 if (down_interruptible(&driver_data.device_allocation)) 1917 if (down_interruptible(&driver_data.device_allocation))
1920 dev_dbg(&pdev->dev, "[%s]: down_interruptible() " 1918 dev_dbg(dev, "[%s]: down_interruptible() failed",
1921 "failed", __func__); 1919 __func__);
1922 ret = hash_disable_power(device_data, false); 1920 ret = hash_disable_power(device_data, false);
1923 1921
1924 } else 1922 } else
1925 ret = hash_disable_power(device_data, true); 1923 ret = hash_disable_power(device_data, true);
1926 1924
1927 if (ret) 1925 if (ret)
1928 dev_err(&pdev->dev, "[%s]: hash_disable_power()", __func__); 1926 dev_err(dev, "[%s]: hash_disable_power()", __func__);
1929 1927
1930 return ret; 1928 return ret;
1931} 1929}
1932 1930
1933/** 1931/**
1934 * ux500_hash_resume - Function that resume the hash device. 1932 * ux500_hash_resume - Function that resume the hash device.
1935 * @pdev: The platform device. 1933 * @dev: Device to resume.
1936 */ 1934 */
1937static int ux500_hash_resume(struct platform_device *pdev) 1935static int ux500_hash_resume(struct device *dev)
1938{ 1936{
1939 int ret = 0; 1937 int ret = 0;
1940 struct hash_device_data *device_data; 1938 struct hash_device_data *device_data;
1941 struct hash_ctx *temp_ctx = NULL; 1939 struct hash_ctx *temp_ctx = NULL;
1942 1940
1943 device_data = platform_get_drvdata(pdev); 1941 device_data = dev_get_drvdata(dev);
1944 if (!device_data) { 1942 if (!device_data) {
1945 dev_err(&pdev->dev, "[%s] platform_get_drvdata() failed!", 1943 dev_err(dev, "[%s] platform_get_drvdata() failed!", __func__);
1946 __func__);
1947 return -ENOMEM; 1944 return -ENOMEM;
1948 } 1945 }
1949 1946
@@ -1958,21 +1955,21 @@ static int ux500_hash_resume(struct platform_device *pdev)
1958 ret = hash_enable_power(device_data, true); 1955 ret = hash_enable_power(device_data, true);
1959 1956
1960 if (ret) 1957 if (ret)
1961 dev_err(&pdev->dev, "[%s]: hash_enable_power() failed!", 1958 dev_err(dev, "[%s]: hash_enable_power() failed!", __func__);
1962 __func__);
1963 1959
1964 return ret; 1960 return ret;
1965} 1961}
1966 1962
1963static SIMPLE_DEV_PM_OPS(ux500_hash_pm, ux500_hash_suspend, ux500_hash_resume);
1964
1967static struct platform_driver hash_driver = { 1965static struct platform_driver hash_driver = {
1968 .probe = ux500_hash_probe, 1966 .probe = ux500_hash_probe,
1969 .remove = ux500_hash_remove, 1967 .remove = ux500_hash_remove,
1970 .shutdown = ux500_hash_shutdown, 1968 .shutdown = ux500_hash_shutdown,
1971 .suspend = ux500_hash_suspend,
1972 .resume = ux500_hash_resume,
1973 .driver = { 1969 .driver = {
1974 .owner = THIS_MODULE, 1970 .owner = THIS_MODULE,
1975 .name = "hash1", 1971 .name = "hash1",
1972 .pm = &ux500_hash_pm,
1976 } 1973 }
1977}; 1974};
1978 1975
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 34ad5a27a7e9..e3fcf8146834 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -929,20 +929,25 @@ static int acpi_power_meter_remove(struct acpi_device *device, int type)
929 return 0; 929 return 0;
930} 930}
931 931
932static int acpi_power_meter_resume(struct acpi_device *device) 932static int acpi_power_meter_resume(struct device *dev)
933{ 933{
934 struct acpi_power_meter_resource *resource; 934 struct acpi_power_meter_resource *resource;
935 935
936 if (!device || !acpi_driver_data(device)) 936 if (!dev)
937 return -EINVAL;
938
939 resource = acpi_driver_data(to_acpi_device(dev));
940 if (!resource)
937 return -EINVAL; 941 return -EINVAL;
938 942
939 resource = acpi_driver_data(device);
940 free_capabilities(resource); 943 free_capabilities(resource);
941 read_capabilities(resource); 944 read_capabilities(resource);
942 945
943 return 0; 946 return 0;
944} 947}
945 948
949static SIMPLE_DEV_PM_OPS(acpi_power_meter_pm, NULL, acpi_power_meter_resume);
950
946static struct acpi_driver acpi_power_meter_driver = { 951static struct acpi_driver acpi_power_meter_driver = {
947 .name = "power_meter", 952 .name = "power_meter",
948 .class = ACPI_POWER_METER_CLASS, 953 .class = ACPI_POWER_METER_CLASS,
@@ -950,9 +955,9 @@ static struct acpi_driver acpi_power_meter_driver = {
950 .ops = { 955 .ops = {
951 .add = acpi_power_meter_add, 956 .add = acpi_power_meter_add,
952 .remove = acpi_power_meter_remove, 957 .remove = acpi_power_meter_remove,
953 .resume = acpi_power_meter_resume,
954 .notify = acpi_power_meter_notify, 958 .notify = acpi_power_meter_notify,
955 }, 959 },
960 .drv.pm = &acpi_power_meter_pm,
956}; 961};
957 962
958/* Module init/exit routines */ 963/* Module init/exit routines */
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index d0f59c3f87ef..fe95d5464a02 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -96,6 +96,7 @@ static const struct idle_cpu *icpu;
96static struct cpuidle_device __percpu *intel_idle_cpuidle_devices; 96static struct cpuidle_device __percpu *intel_idle_cpuidle_devices;
97static int intel_idle(struct cpuidle_device *dev, 97static int intel_idle(struct cpuidle_device *dev,
98 struct cpuidle_driver *drv, int index); 98 struct cpuidle_driver *drv, int index);
99static int intel_idle_cpu_init(int cpu);
99 100
100static struct cpuidle_state *cpuidle_state_table; 101static struct cpuidle_state *cpuidle_state_table;
101 102
@@ -302,22 +303,35 @@ static void __setup_broadcast_timer(void *arg)
302 clockevents_notify(reason, &cpu); 303 clockevents_notify(reason, &cpu);
303} 304}
304 305
305static int setup_broadcast_cpuhp_notify(struct notifier_block *n, 306static int cpu_hotplug_notify(struct notifier_block *n,
306 unsigned long action, void *hcpu) 307 unsigned long action, void *hcpu)
307{ 308{
308 int hotcpu = (unsigned long)hcpu; 309 int hotcpu = (unsigned long)hcpu;
310 struct cpuidle_device *dev;
309 311
310 switch (action & 0xf) { 312 switch (action & 0xf) {
311 case CPU_ONLINE: 313 case CPU_ONLINE:
312 smp_call_function_single(hotcpu, __setup_broadcast_timer, 314
313 (void *)true, 1); 315 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
316 smp_call_function_single(hotcpu, __setup_broadcast_timer,
317 (void *)true, 1);
318
319 /*
320 * Some systems can hotplug a cpu at runtime after
321 * the kernel has booted, we have to initialize the
322 * driver in this case
323 */
324 dev = per_cpu_ptr(intel_idle_cpuidle_devices, hotcpu);
325 if (!dev->registered)
326 intel_idle_cpu_init(hotcpu);
327
314 break; 328 break;
315 } 329 }
316 return NOTIFY_OK; 330 return NOTIFY_OK;
317} 331}
318 332
319static struct notifier_block setup_broadcast_notifier = { 333static struct notifier_block cpu_hotplug_notifier = {
320 .notifier_call = setup_broadcast_cpuhp_notify, 334 .notifier_call = cpu_hotplug_notify,
321}; 335};
322 336
323static void auto_demotion_disable(void *dummy) 337static void auto_demotion_disable(void *dummy)
@@ -405,10 +419,10 @@ static int intel_idle_probe(void)
405 419
406 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */ 420 if (boot_cpu_has(X86_FEATURE_ARAT)) /* Always Reliable APIC Timer */
407 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE; 421 lapic_timer_reliable_states = LAPIC_TIMER_ALWAYS_RELIABLE;
408 else { 422 else
409 on_each_cpu(__setup_broadcast_timer, (void *)true, 1); 423 on_each_cpu(__setup_broadcast_timer, (void *)true, 1);
410 register_cpu_notifier(&setup_broadcast_notifier); 424
411 } 425 register_cpu_notifier(&cpu_hotplug_notifier);
412 426
413 pr_debug(PREFIX "v" INTEL_IDLE_VERSION 427 pr_debug(PREFIX "v" INTEL_IDLE_VERSION
414 " model 0x%X\n", boot_cpu_data.x86_model); 428 " model 0x%X\n", boot_cpu_data.x86_model);
@@ -494,7 +508,7 @@ static int intel_idle_cpuidle_driver_init(void)
494 * allocate, initialize, register cpuidle_devices 508 * allocate, initialize, register cpuidle_devices
495 * @cpu: cpu/core to initialize 509 * @cpu: cpu/core to initialize
496 */ 510 */
497int intel_idle_cpu_init(int cpu) 511static int intel_idle_cpu_init(int cpu)
498{ 512{
499 int cstate; 513 int cstate;
500 struct cpuidle_device *dev; 514 struct cpuidle_device *dev;
@@ -539,7 +553,6 @@ int intel_idle_cpu_init(int cpu)
539 553
540 return 0; 554 return 0;
541} 555}
542EXPORT_SYMBOL_GPL(intel_idle_cpu_init);
543 556
544static int __init intel_idle_init(void) 557static int __init intel_idle_init(void)
545{ 558{
@@ -581,10 +594,10 @@ static void __exit intel_idle_exit(void)
581 intel_idle_cpuidle_devices_uninit(); 594 intel_idle_cpuidle_devices_uninit();
582 cpuidle_unregister_driver(&intel_idle_driver); 595 cpuidle_unregister_driver(&intel_idle_driver);
583 596
584 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE) { 597
598 if (lapic_timer_reliable_states != LAPIC_TIMER_ALWAYS_RELIABLE)
585 on_each_cpu(__setup_broadcast_timer, (void *)false, 1); 599 on_each_cpu(__setup_broadcast_timer, (void *)false, 1);
586 unregister_cpu_notifier(&setup_broadcast_notifier); 600 unregister_cpu_notifier(&cpu_hotplug_notifier);
587 }
588 601
589 return; 602 return;
590} 603}
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index ce875dc365e5..c8f40c9c0428 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -1877,8 +1877,7 @@ static int acer_platform_remove(struct platform_device *device)
1877 return 0; 1877 return 0;
1878} 1878}
1879 1879
1880static int acer_platform_suspend(struct platform_device *dev, 1880static int acer_suspend(struct device *dev)
1881pm_message_t state)
1882{ 1881{
1883 u32 value; 1882 u32 value;
1884 struct acer_data *data = &interface->data; 1883 struct acer_data *data = &interface->data;
@@ -1900,7 +1899,7 @@ pm_message_t state)
1900 return 0; 1899 return 0;
1901} 1900}
1902 1901
1903static int acer_platform_resume(struct platform_device *device) 1902static int acer_resume(struct device *dev)
1904{ 1903{
1905 struct acer_data *data = &interface->data; 1904 struct acer_data *data = &interface->data;
1906 1905
@@ -1916,6 +1915,8 @@ static int acer_platform_resume(struct platform_device *device)
1916 return 0; 1915 return 0;
1917} 1916}
1918 1917
1918static SIMPLE_DEV_PM_OPS(acer_pm, acer_suspend, acer_resume);
1919
1919static void acer_platform_shutdown(struct platform_device *device) 1920static void acer_platform_shutdown(struct platform_device *device)
1920{ 1921{
1921 struct acer_data *data = &interface->data; 1922 struct acer_data *data = &interface->data;
@@ -1931,11 +1932,10 @@ static struct platform_driver acer_platform_driver = {
1931 .driver = { 1932 .driver = {
1932 .name = "acer-wmi", 1933 .name = "acer-wmi",
1933 .owner = THIS_MODULE, 1934 .owner = THIS_MODULE,
1935 .pm = &acer_pm,
1934 }, 1936 },
1935 .probe = acer_platform_probe, 1937 .probe = acer_platform_probe,
1936 .remove = acer_platform_remove, 1938 .remove = acer_platform_remove,
1937 .suspend = acer_platform_suspend,
1938 .resume = acer_platform_resume,
1939 .shutdown = acer_platform_shutdown, 1939 .shutdown = acer_platform_shutdown,
1940}; 1940};
1941 1941
diff --git a/drivers/platform/x86/classmate-laptop.c b/drivers/platform/x86/classmate-laptop.c
index 94f93b621d7b..e2230a2b2f8e 100644
--- a/drivers/platform/x86/classmate-laptop.c
+++ b/drivers/platform/x86/classmate-laptop.c
@@ -362,15 +362,18 @@ static int cmpc_tablet_remove(struct acpi_device *acpi, int type)
362 return cmpc_remove_acpi_notify_device(acpi); 362 return cmpc_remove_acpi_notify_device(acpi);
363} 363}
364 364
365static int cmpc_tablet_resume(struct acpi_device *acpi) 365static int cmpc_tablet_resume(struct device *dev)
366{ 366{
367 struct input_dev *inputdev = dev_get_drvdata(&acpi->dev); 367 struct input_dev *inputdev = dev_get_drvdata(dev);
368
368 unsigned long long val = 0; 369 unsigned long long val = 0;
369 if (ACPI_SUCCESS(cmpc_get_tablet(acpi->handle, &val))) 370 if (ACPI_SUCCESS(cmpc_get_tablet(to_acpi_device(dev)->handle, &val)))
370 input_report_switch(inputdev, SW_TABLET_MODE, !val); 371 input_report_switch(inputdev, SW_TABLET_MODE, !val);
371 return 0; 372 return 0;
372} 373}
373 374
375static SIMPLE_DEV_PM_OPS(cmpc_tablet_pm, NULL, cmpc_tablet_resume);
376
374static const struct acpi_device_id cmpc_tablet_device_ids[] = { 377static const struct acpi_device_id cmpc_tablet_device_ids[] = {
375 {CMPC_TABLET_HID, 0}, 378 {CMPC_TABLET_HID, 0},
376 {"", 0} 379 {"", 0}
@@ -384,9 +387,9 @@ static struct acpi_driver cmpc_tablet_acpi_driver = {
384 .ops = { 387 .ops = {
385 .add = cmpc_tablet_add, 388 .add = cmpc_tablet_add,
386 .remove = cmpc_tablet_remove, 389 .remove = cmpc_tablet_remove,
387 .resume = cmpc_tablet_resume,
388 .notify = cmpc_tablet_handler, 390 .notify = cmpc_tablet_handler,
389 } 391 },
392 .drv.pm = &cmpc_tablet_pm,
390}; 393};
391 394
392 395
diff --git a/drivers/platform/x86/fujitsu-tablet.c b/drivers/platform/x86/fujitsu-tablet.c
index da267eae8ba8..d2e41735a47b 100644
--- a/drivers/platform/x86/fujitsu-tablet.c
+++ b/drivers/platform/x86/fujitsu-tablet.c
@@ -440,12 +440,14 @@ static int __devexit acpi_fujitsu_remove(struct acpi_device *adev, int type)
440 return 0; 440 return 0;
441} 441}
442 442
443static int acpi_fujitsu_resume(struct acpi_device *adev) 443static int acpi_fujitsu_resume(struct device *dev)
444{ 444{
445 fujitsu_reset(); 445 fujitsu_reset();
446 return 0; 446 return 0;
447} 447}
448 448
449static SIMPLE_DEV_PM_OPS(acpi_fujitsu_pm, NULL, acpi_fujitsu_resume);
450
449static struct acpi_driver acpi_fujitsu_driver = { 451static struct acpi_driver acpi_fujitsu_driver = {
450 .name = MODULENAME, 452 .name = MODULENAME,
451 .class = "hotkey", 453 .class = "hotkey",
@@ -453,8 +455,8 @@ static struct acpi_driver acpi_fujitsu_driver = {
453 .ops = { 455 .ops = {
454 .add = acpi_fujitsu_add, 456 .add = acpi_fujitsu_add,
455 .remove = acpi_fujitsu_remove, 457 .remove = acpi_fujitsu_remove,
456 .resume = acpi_fujitsu_resume, 458 },
457 } 459 .drv.pm = &acpi_fujitsu_pm,
458}; 460};
459 461
460static int __init fujitsu_module_init(void) 462static int __init fujitsu_module_init(void)
diff --git a/drivers/platform/x86/hdaps.c b/drivers/platform/x86/hdaps.c
index 24a3ae065f1b..d9ab6f64dcec 100644
--- a/drivers/platform/x86/hdaps.c
+++ b/drivers/platform/x86/hdaps.c
@@ -305,17 +305,19 @@ static int hdaps_probe(struct platform_device *dev)
305 return 0; 305 return 0;
306} 306}
307 307
308static int hdaps_resume(struct platform_device *dev) 308static int hdaps_resume(struct device *dev)
309{ 309{
310 return hdaps_device_init(); 310 return hdaps_device_init();
311} 311}
312 312
313static SIMPLE_DEV_PM_OPS(hdaps_pm, NULL, hdaps_resume);
314
313static struct platform_driver hdaps_driver = { 315static struct platform_driver hdaps_driver = {
314 .probe = hdaps_probe, 316 .probe = hdaps_probe,
315 .resume = hdaps_resume,
316 .driver = { 317 .driver = {
317 .name = "hdaps", 318 .name = "hdaps",
318 .owner = THIS_MODULE, 319 .owner = THIS_MODULE,
320 .pm = &hdaps_pm,
319 }, 321 },
320}; 322};
321 323
diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
index 22b2dfa73148..f4d91154ad67 100644
--- a/drivers/platform/x86/hp_accel.c
+++ b/drivers/platform/x86/hp_accel.c
@@ -353,20 +353,22 @@ static int lis3lv02d_remove(struct acpi_device *device, int type)
353 353
354 354
355#ifdef CONFIG_PM 355#ifdef CONFIG_PM
356static int lis3lv02d_suspend(struct acpi_device *device, pm_message_t state) 356static int lis3lv02d_suspend(struct device *dev)
357{ 357{
358 /* make sure the device is off when we suspend */ 358 /* make sure the device is off when we suspend */
359 lis3lv02d_poweroff(&lis3_dev); 359 lis3lv02d_poweroff(&lis3_dev);
360 return 0; 360 return 0;
361} 361}
362 362
363static int lis3lv02d_resume(struct acpi_device *device) 363static int lis3lv02d_resume(struct device *dev)
364{ 364{
365 return lis3lv02d_poweron(&lis3_dev); 365 return lis3lv02d_poweron(&lis3_dev);
366} 366}
367
368static SIMPLE_DEV_PM_OPS(hp_accel_pm, lis3lv02d_suspend, lis3lv02d_resume);
369#define HP_ACCEL_PM (&hp_accel_pm)
367#else 370#else
368#define lis3lv02d_suspend NULL 371#define HP_ACCEL_PM NULL
369#define lis3lv02d_resume NULL
370#endif 372#endif
371 373
372/* For the HP MDPS aka 3D Driveguard */ 374/* For the HP MDPS aka 3D Driveguard */
@@ -377,9 +379,8 @@ static struct acpi_driver lis3lv02d_driver = {
377 .ops = { 379 .ops = {
378 .add = lis3lv02d_add, 380 .add = lis3lv02d_add,
379 .remove = lis3lv02d_remove, 381 .remove = lis3lv02d_remove,
380 .suspend = lis3lv02d_suspend, 382 },
381 .resume = lis3lv02d_resume, 383 .drv.pm = HP_ACCEL_PM,
382 }
383}; 384};
384 385
385static int __init lis3lv02d_init_module(void) 386static int __init lis3lv02d_init_module(void)
diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c
index 9af4257d4901..5051aa970e0a 100644
--- a/drivers/platform/x86/intel_ips.c
+++ b/drivers/platform/x86/intel_ips.c
@@ -1719,21 +1719,6 @@ static void ips_remove(struct pci_dev *dev)
1719 dev_dbg(&dev->dev, "IPS driver removed\n"); 1719 dev_dbg(&dev->dev, "IPS driver removed\n");
1720} 1720}
1721 1721
1722#ifdef CONFIG_PM
1723static int ips_suspend(struct pci_dev *dev, pm_message_t state)
1724{
1725 return 0;
1726}
1727
1728static int ips_resume(struct pci_dev *dev)
1729{
1730 return 0;
1731}
1732#else
1733#define ips_suspend NULL
1734#define ips_resume NULL
1735#endif /* CONFIG_PM */
1736
1737static void ips_shutdown(struct pci_dev *dev) 1722static void ips_shutdown(struct pci_dev *dev)
1738{ 1723{
1739} 1724}
@@ -1743,8 +1728,6 @@ static struct pci_driver ips_pci_driver = {
1743 .id_table = ips_id_table, 1728 .id_table = ips_id_table,
1744 .probe = ips_probe, 1729 .probe = ips_probe,
1745 .remove = ips_remove, 1730 .remove = ips_remove,
1746 .suspend = ips_suspend,
1747 .resume = ips_resume,
1748 .shutdown = ips_shutdown, 1731 .shutdown = ips_shutdown,
1749}; 1732};
1750 1733
diff --git a/drivers/platform/x86/intel_mid_thermal.c b/drivers/platform/x86/intel_mid_thermal.c
index 5ae9cd9c7e6e..ea7422f6fa03 100644
--- a/drivers/platform/x86/intel_mid_thermal.c
+++ b/drivers/platform/x86/intel_mid_thermal.c
@@ -418,23 +418,23 @@ static struct thermal_device_info *initialize_sensor(int index)
418 418
419/** 419/**
420 * mid_thermal_resume - resume routine 420 * mid_thermal_resume - resume routine
421 * @pdev: platform device structure 421 * @dev: device structure
422 * 422 *
423 * mid thermal resume: re-initializes the adc. Can sleep. 423 * mid thermal resume: re-initializes the adc. Can sleep.
424 */ 424 */
425static int mid_thermal_resume(struct platform_device *pdev) 425static int mid_thermal_resume(struct device *dev)
426{ 426{
427 return mid_initialize_adc(&pdev->dev); 427 return mid_initialize_adc(dev);
428} 428}
429 429
430/** 430/**
431 * mid_thermal_suspend - suspend routine 431 * mid_thermal_suspend - suspend routine
432 * @pdev: platform device structure 432 * @dev: device structure
433 * 433 *
434 * mid thermal suspend implements the suspend functionality 434 * mid thermal suspend implements the suspend functionality
435 * by stopping the ADC. Can sleep. 435 * by stopping the ADC. Can sleep.
436 */ 436 */
437static int mid_thermal_suspend(struct platform_device *pdev, pm_message_t mesg) 437static int mid_thermal_suspend(struct device *dev)
438{ 438{
439 /* 439 /*
440 * This just stops the ADC and does not disable it. 440 * This just stops the ADC and does not disable it.
@@ -444,6 +444,9 @@ static int mid_thermal_suspend(struct platform_device *pdev, pm_message_t mesg)
444 return configure_adc(0); 444 return configure_adc(0);
445} 445}
446 446
447static SIMPLE_DEV_PM_OPS(mid_thermal_pm,
448 mid_thermal_suspend, mid_thermal_resume);
449
447/** 450/**
448 * read_curr_temp - reads the current temperature and stores in temp 451 * read_curr_temp - reads the current temperature and stores in temp
449 * @temp: holds the current temperature value after reading 452 * @temp: holds the current temperature value after reading
@@ -557,10 +560,9 @@ static struct platform_driver mid_thermal_driver = {
557 .driver = { 560 .driver = {
558 .name = DRIVER_NAME, 561 .name = DRIVER_NAME,
559 .owner = THIS_MODULE, 562 .owner = THIS_MODULE,
563 .pm = &mid_thermal_pm,
560 }, 564 },
561 .probe = mid_thermal_probe, 565 .probe = mid_thermal_probe,
562 .suspend = mid_thermal_suspend,
563 .resume = mid_thermal_resume,
564 .remove = __devexit_p(mid_thermal_remove), 566 .remove = __devexit_p(mid_thermal_remove),
565 .id_table = therm_id_table, 567 .id_table = therm_id_table,
566}; 568};
diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
index bb5132128b33..f64441844317 100644
--- a/drivers/platform/x86/msi-laptop.c
+++ b/drivers/platform/x86/msi-laptop.c
@@ -85,7 +85,8 @@
85#define MSI_STANDARD_EC_TOUCHPAD_ADDRESS 0xe4 85#define MSI_STANDARD_EC_TOUCHPAD_ADDRESS 0xe4
86#define MSI_STANDARD_EC_TOUCHPAD_MASK (1 << 4) 86#define MSI_STANDARD_EC_TOUCHPAD_MASK (1 << 4)
87 87
88static int msi_laptop_resume(struct platform_device *device); 88static int msi_laptop_resume(struct device *device);
89static SIMPLE_DEV_PM_OPS(msi_laptop_pm, NULL, msi_laptop_resume);
89 90
90#define MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS 0x2f 91#define MSI_STANDARD_EC_DEVICES_EXISTS_ADDRESS 0x2f
91 92
@@ -437,8 +438,8 @@ static struct platform_driver msipf_driver = {
437 .driver = { 438 .driver = {
438 .name = "msi-laptop-pf", 439 .name = "msi-laptop-pf",
439 .owner = THIS_MODULE, 440 .owner = THIS_MODULE,
441 .pm = &msi_laptop_pm,
440 }, 442 },
441 .resume = msi_laptop_resume,
442}; 443};
443 444
444static struct platform_device *msipf_device; 445static struct platform_device *msipf_device;
@@ -752,7 +753,7 @@ err_bluetooth:
752 return retval; 753 return retval;
753} 754}
754 755
755static int msi_laptop_resume(struct platform_device *device) 756static int msi_laptop_resume(struct device *device)
756{ 757{
757 u8 data; 758 u8 data;
758 int result; 759 int result;
diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index ffff8b4b4949..24480074bcf0 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -177,7 +177,6 @@ enum SINF_BITS { SINF_NUM_BATTERIES = 0,
177 177
178static int acpi_pcc_hotkey_add(struct acpi_device *device); 178static int acpi_pcc_hotkey_add(struct acpi_device *device);
179static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type); 179static int acpi_pcc_hotkey_remove(struct acpi_device *device, int type);
180static int acpi_pcc_hotkey_resume(struct acpi_device *device);
181static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event); 180static void acpi_pcc_hotkey_notify(struct acpi_device *device, u32 event);
182 181
183static const struct acpi_device_id pcc_device_ids[] = { 182static const struct acpi_device_id pcc_device_ids[] = {
@@ -189,6 +188,9 @@ static const struct acpi_device_id pcc_device_ids[] = {
189}; 188};
190MODULE_DEVICE_TABLE(acpi, pcc_device_ids); 189MODULE_DEVICE_TABLE(acpi, pcc_device_ids);
191 190
191static int acpi_pcc_hotkey_resume(struct device *dev);
192static SIMPLE_DEV_PM_OPS(acpi_pcc_hotkey_pm, NULL, acpi_pcc_hotkey_resume);
193
192static struct acpi_driver acpi_pcc_driver = { 194static struct acpi_driver acpi_pcc_driver = {
193 .name = ACPI_PCC_DRIVER_NAME, 195 .name = ACPI_PCC_DRIVER_NAME,
194 .class = ACPI_PCC_CLASS, 196 .class = ACPI_PCC_CLASS,
@@ -196,9 +198,9 @@ static struct acpi_driver acpi_pcc_driver = {
196 .ops = { 198 .ops = {
197 .add = acpi_pcc_hotkey_add, 199 .add = acpi_pcc_hotkey_add,
198 .remove = acpi_pcc_hotkey_remove, 200 .remove = acpi_pcc_hotkey_remove,
199 .resume = acpi_pcc_hotkey_resume,
200 .notify = acpi_pcc_hotkey_notify, 201 .notify = acpi_pcc_hotkey_notify,
201 }, 202 },
203 .drv.pm = &acpi_pcc_hotkey_pm,
202}; 204};
203 205
204static const struct key_entry panasonic_keymap[] = { 206static const struct key_entry panasonic_keymap[] = {
@@ -538,11 +540,15 @@ static void acpi_pcc_destroy_input(struct pcc_acpi *pcc)
538 540
539/* kernel module interface */ 541/* kernel module interface */
540 542
541static int acpi_pcc_hotkey_resume(struct acpi_device *device) 543static int acpi_pcc_hotkey_resume(struct device *dev)
542{ 544{
543 struct pcc_acpi *pcc = acpi_driver_data(device); 545 struct pcc_acpi *pcc;
546
547 if (!dev)
548 return -EINVAL;
544 549
545 if (device == NULL || pcc == NULL) 550 pcc = acpi_driver_data(to_acpi_device(dev));
551 if (!pcc)
546 return -EINVAL; 552 return -EINVAL;
547 553
548 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n", 554 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Sticky mode restore: %d\n",
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index d456ff0c73b7..9363969ad07a 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -1477,7 +1477,7 @@ static void sony_nc_function_resume(void)
1477 &result); 1477 &result);
1478} 1478}
1479 1479
1480static int sony_nc_resume(struct acpi_device *device) 1480static int sony_nc_resume(struct device *dev)
1481{ 1481{
1482 struct sony_nc_value *item; 1482 struct sony_nc_value *item;
1483 acpi_handle handle; 1483 acpi_handle handle;
@@ -1509,6 +1509,8 @@ static int sony_nc_resume(struct acpi_device *device)
1509 return 0; 1509 return 0;
1510} 1510}
1511 1511
1512static SIMPLE_DEV_PM_OPS(sony_nc_pm, NULL, sony_nc_resume);
1513
1512static void sony_nc_rfkill_cleanup(void) 1514static void sony_nc_rfkill_cleanup(void)
1513{ 1515{
1514 int i; 1516 int i;
@@ -2770,9 +2772,9 @@ static struct acpi_driver sony_nc_driver = {
2770 .ops = { 2772 .ops = {
2771 .add = sony_nc_add, 2773 .add = sony_nc_add,
2772 .remove = sony_nc_remove, 2774 .remove = sony_nc_remove,
2773 .resume = sony_nc_resume,
2774 .notify = sony_nc_notify, 2775 .notify = sony_nc_notify,
2775 }, 2776 },
2777 .drv.pm = &sony_nc_pm,
2776}; 2778};
2777 2779
2778/*********** SPIC (SNY6001) Device ***********/ 2780/*********** SPIC (SNY6001) Device ***********/
@@ -4285,19 +4287,22 @@ err_free_resources:
4285 return result; 4287 return result;
4286} 4288}
4287 4289
4288static int sony_pic_suspend(struct acpi_device *device, pm_message_t state) 4290static int sony_pic_suspend(struct device *dev)
4289{ 4291{
4290 if (sony_pic_disable(device)) 4292 if (sony_pic_disable(to_acpi_device(dev)))
4291 return -ENXIO; 4293 return -ENXIO;
4292 return 0; 4294 return 0;
4293} 4295}
4294 4296
4295static int sony_pic_resume(struct acpi_device *device) 4297static int sony_pic_resume(struct device *dev)
4296{ 4298{
4297 sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq); 4299 sony_pic_enable(to_acpi_device(dev),
4300 spic_dev.cur_ioport, spic_dev.cur_irq);
4298 return 0; 4301 return 0;
4299} 4302}
4300 4303
4304static SIMPLE_DEV_PM_OPS(sony_pic_pm, sony_pic_suspend, sony_pic_resume);
4305
4301static const struct acpi_device_id sony_pic_device_ids[] = { 4306static const struct acpi_device_id sony_pic_device_ids[] = {
4302 {SONY_PIC_HID, 0}, 4307 {SONY_PIC_HID, 0},
4303 {"", 0}, 4308 {"", 0},
@@ -4311,9 +4316,8 @@ static struct acpi_driver sony_pic_driver = {
4311 .ops = { 4316 .ops = {
4312 .add = sony_pic_add, 4317 .add = sony_pic_add,
4313 .remove = sony_pic_remove, 4318 .remove = sony_pic_remove,
4314 .suspend = sony_pic_suspend,
4315 .resume = sony_pic_resume,
4316 }, 4319 },
4320 .drv.pm = &sony_pic_pm,
4317}; 4321};
4318 4322
4319static struct dmi_system_id __initdata sonypi_dmi_table[] = { 4323static struct dmi_system_id __initdata sonypi_dmi_table[] = {
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 8b5610d88418..d5fd4a1193f8 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -277,7 +277,7 @@ struct ibm_struct {
277 int (*write) (char *); 277 int (*write) (char *);
278 void (*exit) (void); 278 void (*exit) (void);
279 void (*resume) (void); 279 void (*resume) (void);
280 void (*suspend) (pm_message_t state); 280 void (*suspend) (void);
281 void (*shutdown) (void); 281 void (*shutdown) (void);
282 282
283 struct list_head all_drivers; 283 struct list_head all_drivers;
@@ -922,8 +922,7 @@ static struct input_dev *tpacpi_inputdev;
922static struct mutex tpacpi_inputdev_send_mutex; 922static struct mutex tpacpi_inputdev_send_mutex;
923static LIST_HEAD(tpacpi_all_drivers); 923static LIST_HEAD(tpacpi_all_drivers);
924 924
925static int tpacpi_suspend_handler(struct platform_device *pdev, 925static int tpacpi_suspend_handler(struct device *dev)
926 pm_message_t state)
927{ 926{
928 struct ibm_struct *ibm, *itmp; 927 struct ibm_struct *ibm, *itmp;
929 928
@@ -931,13 +930,13 @@ static int tpacpi_suspend_handler(struct platform_device *pdev,
931 &tpacpi_all_drivers, 930 &tpacpi_all_drivers,
932 all_drivers) { 931 all_drivers) {
933 if (ibm->suspend) 932 if (ibm->suspend)
934 (ibm->suspend)(state); 933 (ibm->suspend)();
935 } 934 }
936 935
937 return 0; 936 return 0;
938} 937}
939 938
940static int tpacpi_resume_handler(struct platform_device *pdev) 939static int tpacpi_resume_handler(struct device *dev)
941{ 940{
942 struct ibm_struct *ibm, *itmp; 941 struct ibm_struct *ibm, *itmp;
943 942
@@ -951,6 +950,9 @@ static int tpacpi_resume_handler(struct platform_device *pdev)
951 return 0; 950 return 0;
952} 951}
953 952
953static SIMPLE_DEV_PM_OPS(tpacpi_pm,
954 tpacpi_suspend_handler, tpacpi_resume_handler);
955
954static void tpacpi_shutdown_handler(struct platform_device *pdev) 956static void tpacpi_shutdown_handler(struct platform_device *pdev)
955{ 957{
956 struct ibm_struct *ibm, *itmp; 958 struct ibm_struct *ibm, *itmp;
@@ -967,9 +969,8 @@ static struct platform_driver tpacpi_pdriver = {
967 .driver = { 969 .driver = {
968 .name = TPACPI_DRVR_NAME, 970 .name = TPACPI_DRVR_NAME,
969 .owner = THIS_MODULE, 971 .owner = THIS_MODULE,
972 .pm = &tpacpi_pm,
970 }, 973 },
971 .suspend = tpacpi_suspend_handler,
972 .resume = tpacpi_resume_handler,
973 .shutdown = tpacpi_shutdown_handler, 974 .shutdown = tpacpi_shutdown_handler,
974}; 975};
975 976
@@ -3758,7 +3759,7 @@ static void hotkey_notify(struct ibm_struct *ibm, u32 event)
3758 } 3759 }
3759} 3760}
3760 3761
3761static void hotkey_suspend(pm_message_t state) 3762static void hotkey_suspend(void)
3762{ 3763{
3763 /* Do these on suspend, we get the events on early resume! */ 3764 /* Do these on suspend, we get the events on early resume! */
3764 hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE; 3765 hotkey_wakeup_reason = TP_ACPI_WAKEUP_NONE;
@@ -6329,7 +6330,7 @@ static int __init brightness_init(struct ibm_init_struct *iibm)
6329 return 0; 6330 return 0;
6330} 6331}
6331 6332
6332static void brightness_suspend(pm_message_t state) 6333static void brightness_suspend(void)
6333{ 6334{
6334 tpacpi_brightness_checkpoint_nvram(); 6335 tpacpi_brightness_checkpoint_nvram();
6335} 6336}
@@ -6748,7 +6749,7 @@ static struct snd_kcontrol_new volume_alsa_control_mute __devinitdata = {
6748 .get = volume_alsa_mute_get, 6749 .get = volume_alsa_mute_get,
6749}; 6750};
6750 6751
6751static void volume_suspend(pm_message_t state) 6752static void volume_suspend(void)
6752{ 6753{
6753 tpacpi_volume_checkpoint_nvram(); 6754 tpacpi_volume_checkpoint_nvram();
6754} 6755}
@@ -8107,7 +8108,7 @@ static void fan_exit(void)
8107 flush_workqueue(tpacpi_wq); 8108 flush_workqueue(tpacpi_wq);
8108} 8109}
8109 8110
8110static void fan_suspend(pm_message_t state) 8111static void fan_suspend(void)
8111{ 8112{
8112 int rc; 8113 int rc;
8113 8114
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index dab10f6edcd4..c13ba5bac93f 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -1296,10 +1296,9 @@ static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
1296 } 1296 }
1297} 1297}
1298 1298
1299static int toshiba_acpi_suspend(struct acpi_device *acpi_dev, 1299static int toshiba_acpi_suspend(struct device *device)
1300 pm_message_t state)
1301{ 1300{
1302 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 1301 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
1303 u32 result; 1302 u32 result;
1304 1303
1305 if (dev->hotkey_dev) 1304 if (dev->hotkey_dev)
@@ -1308,9 +1307,9 @@ static int toshiba_acpi_suspend(struct acpi_device *acpi_dev,
1308 return 0; 1307 return 0;
1309} 1308}
1310 1309
1311static int toshiba_acpi_resume(struct acpi_device *acpi_dev) 1310static int toshiba_acpi_resume(struct device *device)
1312{ 1311{
1313 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); 1312 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
1314 u32 result; 1313 u32 result;
1315 1314
1316 if (dev->hotkey_dev) 1315 if (dev->hotkey_dev)
@@ -1319,6 +1318,9 @@ static int toshiba_acpi_resume(struct acpi_device *acpi_dev)
1319 return 0; 1318 return 0;
1320} 1319}
1321 1320
1321static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
1322 toshiba_acpi_suspend, toshiba_acpi_resume);
1323
1322static struct acpi_driver toshiba_acpi_driver = { 1324static struct acpi_driver toshiba_acpi_driver = {
1323 .name = "Toshiba ACPI driver", 1325 .name = "Toshiba ACPI driver",
1324 .owner = THIS_MODULE, 1326 .owner = THIS_MODULE,
@@ -1328,9 +1330,8 @@ static struct acpi_driver toshiba_acpi_driver = {
1328 .add = toshiba_acpi_add, 1330 .add = toshiba_acpi_add,
1329 .remove = toshiba_acpi_remove, 1331 .remove = toshiba_acpi_remove,
1330 .notify = toshiba_acpi_notify, 1332 .notify = toshiba_acpi_notify,
1331 .suspend = toshiba_acpi_suspend,
1332 .resume = toshiba_acpi_resume,
1333 }, 1333 },
1334 .drv.pm = &toshiba_acpi_pm,
1334}; 1335};
1335 1336
1336static int __init toshiba_acpi_init(void) 1337static int __init toshiba_acpi_init(void)
diff --git a/drivers/platform/x86/toshiba_bluetooth.c b/drivers/platform/x86/toshiba_bluetooth.c
index 5fb7186694df..715a43cb5e3c 100644
--- a/drivers/platform/x86/toshiba_bluetooth.c
+++ b/drivers/platform/x86/toshiba_bluetooth.c
@@ -34,7 +34,6 @@ MODULE_LICENSE("GPL");
34static int toshiba_bt_rfkill_add(struct acpi_device *device); 34static int toshiba_bt_rfkill_add(struct acpi_device *device);
35static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type); 35static int toshiba_bt_rfkill_remove(struct acpi_device *device, int type);
36static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event); 36static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event);
37static int toshiba_bt_resume(struct acpi_device *device);
38 37
39static const struct acpi_device_id bt_device_ids[] = { 38static const struct acpi_device_id bt_device_ids[] = {
40 { "TOS6205", 0}, 39 { "TOS6205", 0},
@@ -42,6 +41,9 @@ static const struct acpi_device_id bt_device_ids[] = {
42}; 41};
43MODULE_DEVICE_TABLE(acpi, bt_device_ids); 42MODULE_DEVICE_TABLE(acpi, bt_device_ids);
44 43
44static int toshiba_bt_resume(struct device *dev);
45static SIMPLE_DEV_PM_OPS(toshiba_bt_pm, NULL, toshiba_bt_resume);
46
45static struct acpi_driver toshiba_bt_rfkill_driver = { 47static struct acpi_driver toshiba_bt_rfkill_driver = {
46 .name = "Toshiba BT", 48 .name = "Toshiba BT",
47 .class = "Toshiba", 49 .class = "Toshiba",
@@ -50,9 +52,9 @@ static struct acpi_driver toshiba_bt_rfkill_driver = {
50 .add = toshiba_bt_rfkill_add, 52 .add = toshiba_bt_rfkill_add,
51 .remove = toshiba_bt_rfkill_remove, 53 .remove = toshiba_bt_rfkill_remove,
52 .notify = toshiba_bt_rfkill_notify, 54 .notify = toshiba_bt_rfkill_notify,
53 .resume = toshiba_bt_resume,
54 }, 55 },
55 .owner = THIS_MODULE, 56 .owner = THIS_MODULE,
57 .drv.pm = &toshiba_bt_pm,
56}; 58};
57 59
58 60
@@ -88,9 +90,9 @@ static void toshiba_bt_rfkill_notify(struct acpi_device *device, u32 event)
88 toshiba_bluetooth_enable(device->handle); 90 toshiba_bluetooth_enable(device->handle);
89} 91}
90 92
91static int toshiba_bt_resume(struct acpi_device *device) 93static int toshiba_bt_resume(struct device *dev)
92{ 94{
93 return toshiba_bluetooth_enable(device->handle); 95 return toshiba_bluetooth_enable(to_acpi_device(dev)->handle);
94} 96}
95 97
96static int toshiba_bt_rfkill_add(struct acpi_device *device) 98static int toshiba_bt_rfkill_add(struct acpi_device *device)
diff --git a/drivers/platform/x86/xo15-ebook.c b/drivers/platform/x86/xo15-ebook.c
index fad153dc0355..849c07c13bf6 100644
--- a/drivers/platform/x86/xo15-ebook.c
+++ b/drivers/platform/x86/xo15-ebook.c
@@ -77,11 +77,13 @@ static void ebook_switch_notify(struct acpi_device *device, u32 event)
77 } 77 }
78} 78}
79 79
80static int ebook_switch_resume(struct acpi_device *device) 80static int ebook_switch_resume(struct device *dev)
81{ 81{
82 return ebook_send_state(device); 82 return ebook_send_state(to_acpi_device(dev));
83} 83}
84 84
85static SIMPLE_DEV_PM_OPS(ebook_switch_pm, NULL, ebook_switch_resume);
86
85static int ebook_switch_add(struct acpi_device *device) 87static int ebook_switch_add(struct acpi_device *device)
86{ 88{
87 struct ebook_switch *button; 89 struct ebook_switch *button;
@@ -161,10 +163,10 @@ static struct acpi_driver xo15_ebook_driver = {
161 .ids = ebook_device_ids, 163 .ids = ebook_device_ids,
162 .ops = { 164 .ops = {
163 .add = ebook_switch_add, 165 .add = ebook_switch_add,
164 .resume = ebook_switch_resume,
165 .remove = ebook_switch_remove, 166 .remove = ebook_switch_remove,
166 .notify = ebook_switch_notify, 167 .notify = ebook_switch_notify,
167 }, 168 },
169 .drv.pm = &ebook_switch_pm,
168}; 170};
169 171
170static int __init xo15_ebook_init(void) 172static int __init xo15_ebook_init(void)
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 4267789ca995..132333d75408 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -568,6 +568,7 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
568 hpet_mask_rtc_irq_bit(RTC_AIE); 568 hpet_mask_rtc_irq_bit(RTC_AIE);
569 569
570 CMOS_READ(RTC_INTR_FLAGS); 570 CMOS_READ(RTC_INTR_FLAGS);
571 pm_wakeup_event(cmos_rtc.dev, 0);
571 } 572 }
572 spin_unlock(&rtc_lock); 573 spin_unlock(&rtc_lock);
573 574