aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi')
-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/glue.c4
-rw-r--r--drivers/acpi/pci_root.c2
-rw-r--r--drivers/acpi/power.c14
-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/sleep.c26
-rw-r--r--drivers/acpi/thermal.c17
13 files changed, 98 insertions, 115 deletions
diff --git a/drivers/acpi/ac.c b/drivers/acpi/ac.c
index d1fcbc0f6cbc..ac7034129f3f 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 {
@@ -311,13 +313,18 @@ static int acpi_ac_add(struct acpi_device *device)
311 return result; 313 return result;
312} 314}
313 315
314static int acpi_ac_resume(struct acpi_device *device) 316static int acpi_ac_resume(struct device *dev)
315{ 317{
316 struct acpi_ac *ac; 318 struct acpi_ac *ac;
317 unsigned old_state; 319 unsigned old_state;
318 if (!device || !acpi_driver_data(device)) 320
321 if (!dev)
319 return -EINVAL; 322 return -EINVAL;
320 ac = acpi_driver_data(device); 323
324 ac = acpi_driver_data(to_acpi_device(dev));
325 if (!ac)
326 return -EINVAL;
327
321 old_state = ac->state; 328 old_state = ac->state;
322 if (acpi_ac_get_state(ac)) 329 if (acpi_ac_get_state(ac))
323 return 0; 330 return 0;
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 5662d64e6733..ff2c876ec412 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -1053,17 +1053,24 @@ static int acpi_battery_remove(struct acpi_device *device, int type)
1053} 1053}
1054 1054
1055/* this is needed to learn about changes made in suspended state */ 1055/* this is needed to learn about changes made in suspended state */
1056static int acpi_battery_resume(struct acpi_device *device) 1056static int acpi_battery_resume(struct device *dev)
1057{ 1057{
1058 struct acpi_battery *battery; 1058 struct acpi_battery *battery;
1059 if (!device) 1059
1060 if (!dev)
1060 return -EINVAL; 1061 return -EINVAL;
1061 battery = acpi_driver_data(device); 1062
1063 battery = acpi_driver_data(to_acpi_device(dev));
1064 if (!battery)
1065 return -EINVAL;
1066
1062 battery->update_time = 0; 1067 battery->update_time = 0;
1063 acpi_battery_update(battery); 1068 acpi_battery_update(battery);
1064 return 0; 1069 return 0;
1065} 1070}
1066 1071
1072static SIMPLE_DEV_PM_OPS(acpi_battery_pm, NULL, acpi_battery_resume);
1073
1067static struct acpi_driver acpi_battery_driver = { 1074static struct acpi_driver acpi_battery_driver = {
1068 .name = "battery", 1075 .name = "battery",
1069 .class = ACPI_BATTERY_CLASS, 1076 .class = ACPI_BATTERY_CLASS,
@@ -1071,10 +1078,10 @@ static struct acpi_driver acpi_battery_driver = {
1071 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, 1078 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1072 .ops = { 1079 .ops = {
1073 .add = acpi_battery_add, 1080 .add = acpi_battery_add,
1074 .resume = acpi_battery_resume,
1075 .remove = acpi_battery_remove, 1081 .remove = acpi_battery_remove,
1076 .notify = acpi_battery_notify, 1082 .notify = acpi_battery_notify,
1077 }, 1083 },
1084 .drv.pm = &acpi_battery_pm,
1078}; 1085};
1079 1086
1080static void __init acpi_battery_init_async(void *unused, async_cookie_t cookie) 1087static 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/glue.c b/drivers/acpi/glue.c
index 1564e0927c21..243ee85e4d2e 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -39,6 +39,7 @@ int register_acpi_bus_type(struct acpi_bus_type *type)
39 } 39 }
40 return -ENODEV; 40 return -ENODEV;
41} 41}
42EXPORT_SYMBOL_GPL(register_acpi_bus_type);
42 43
43int unregister_acpi_bus_type(struct acpi_bus_type *type) 44int unregister_acpi_bus_type(struct acpi_bus_type *type)
44{ 45{
@@ -54,6 +55,7 @@ int unregister_acpi_bus_type(struct acpi_bus_type *type)
54 } 55 }
55 return -ENODEV; 56 return -ENODEV;
56} 57}
58EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
57 59
58static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type) 60static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
59{ 61{
@@ -69,7 +71,6 @@ static struct acpi_bus_type *acpi_get_bus_type(struct bus_type *type)
69 up_read(&bus_type_sem); 71 up_read(&bus_type_sem);
70 return ret; 72 return ret;
71} 73}
72EXPORT_SYMBOL_GPL(register_acpi_bus_type);
73 74
74static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle) 75static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
75{ 76{
@@ -86,7 +87,6 @@ static int acpi_find_bridge_device(struct device *dev, acpi_handle * handle)
86 up_read(&bus_type_sem); 87 up_read(&bus_type_sem);
87 return ret; 88 return ret;
88} 89}
89EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
90 90
91/* Get device's handler per its address under its parent */ 91/* Get device's handler per its address under its parent */
92struct acpi_find_child { 92struct acpi_find_child {
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 7aff6312ce7c..ec54014c321c 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -505,6 +505,8 @@ static int __devinit acpi_pci_root_add(struct acpi_device *device)
505 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS); 505 strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
506 device->driver_data = root; 506 device->driver_data = root;
507 507
508 root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle);
509
508 /* 510 /*
509 * All supported architectures that use ACPI have support for 511 * All supported architectures that use ACPI have support for
510 * PCI domains, so we indicate this in _OSC support capabilities. 512 * PCI domains, so we indicate this in _OSC support capabilities.
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index dd6d6a3c6780..215ecd097408 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/*
@@ -390,6 +392,7 @@ void acpi_power_resource_unregister_device(struct device *dev, acpi_handle handl
390 __acpi_power_resource_unregister_device(dev, 392 __acpi_power_resource_unregister_device(dev,
391 list->handles[i]); 393 list->handles[i]);
392} 394}
395EXPORT_SYMBOL_GPL(acpi_power_resource_unregister_device);
393 396
394static int __acpi_power_resource_register_device( 397static int __acpi_power_resource_register_device(
395 struct acpi_power_managed_device *powered_device, acpi_handle handle) 398 struct acpi_power_managed_device *powered_device, acpi_handle handle)
@@ -460,6 +463,7 @@ no_power_resource:
460 printk(KERN_WARNING PREFIX "Invalid Power Resource to register!"); 463 printk(KERN_WARNING PREFIX "Invalid Power Resource to register!");
461 return -ENODEV; 464 return -ENODEV;
462} 465}
466EXPORT_SYMBOL_GPL(acpi_power_resource_register_device);
463 467
464/** 468/**
465 * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in 469 * acpi_device_sleep_wake - execute _DSW (Device Sleep Wake) or (deprecated in
@@ -771,14 +775,16 @@ static int acpi_power_remove(struct acpi_device *device, int type)
771 return 0; 775 return 0;
772} 776}
773 777
774static int acpi_power_resume(struct acpi_device *device) 778static int acpi_power_resume(struct device *dev)
775{ 779{
776 int result = 0, state; 780 int result = 0, state;
781 struct acpi_device *device;
777 struct acpi_power_resource *resource; 782 struct acpi_power_resource *resource;
778 783
779 if (!device) 784 if (!dev)
780 return -EINVAL; 785 return -EINVAL;
781 786
787 device = to_acpi_device(dev);
782 resource = acpi_driver_data(device); 788 resource = acpi_driver_data(device);
783 if (!resource) 789 if (!resource)
784 return -EINVAL; 790 return -EINVAL;
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index 971c45474703..ff8e04f2fab4 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 9837c9c4f009..ad3730b4038b 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 148556a8f0f2..d1ecca2b641a 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -330,26 +330,6 @@ static void acpi_device_release(struct device *dev)
330 kfree(acpi_dev); 330 kfree(acpi_dev);
331} 331}
332 332
333static int acpi_device_suspend(struct device *dev, pm_message_t state)
334{
335 struct acpi_device *acpi_dev = to_acpi_device(dev);
336 struct acpi_driver *acpi_drv = acpi_dev->driver;
337
338 if (acpi_drv && acpi_drv->ops.suspend)
339 return acpi_drv->ops.suspend(acpi_dev, state);
340 return 0;
341}
342
343static int acpi_device_resume(struct device *dev)
344{
345 struct acpi_device *acpi_dev = to_acpi_device(dev);
346 struct acpi_driver *acpi_drv = acpi_dev->driver;
347
348 if (acpi_drv && acpi_drv->ops.resume)
349 return acpi_drv->ops.resume(acpi_dev);
350 return 0;
351}
352
353static int acpi_bus_match(struct device *dev, struct device_driver *drv) 333static int acpi_bus_match(struct device *dev, struct device_driver *drv)
354{ 334{
355 struct acpi_device *acpi_dev = to_acpi_device(dev); 335 struct acpi_device *acpi_dev = to_acpi_device(dev);
@@ -481,8 +461,6 @@ static int acpi_device_remove(struct device * dev)
481 461
482struct bus_type acpi_bus_type = { 462struct bus_type acpi_bus_type = {
483 .name = "acpi", 463 .name = "acpi",
484 .suspend = acpi_device_suspend,
485 .resume = acpi_device_resume,
486 .match = acpi_bus_match, 464 .match = acpi_bus_match,
487 .probe = acpi_device_probe, 465 .probe = acpi_device_probe,
488 .remove = acpi_device_remove, 466 .remove = acpi_device_remove,
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 23a53c013f1e..7a7a9c929247 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -716,8 +716,9 @@ int acpi_suspend(u32 acpi_state)
716 * @dev: device to examine; its driver model wakeup flags control 716 * @dev: device to examine; its driver model wakeup flags control
717 * whether it should be able to wake up the system 717 * whether it should be able to wake up the system
718 * @d_min_p: used to store the upper limit of allowed states range 718 * @d_min_p: used to store the upper limit of allowed states range
719 * Return value: preferred power state of the device on success, -ENODEV on 719 * @d_max_in: specify the lowest allowed states
720 * failure (ie. if there's no 'struct acpi_device' for @dev) 720 * Return value: preferred power state of the device on success, -ENODEV
721 * (ie. if there's no 'struct acpi_device' for @dev) or -EINVAL on failure
721 * 722 *
722 * Find the lowest power (highest number) ACPI device power state that 723 * Find the lowest power (highest number) ACPI device power state that
723 * device @dev can be in while the system is in the sleep state represented 724 * device @dev can be in while the system is in the sleep state represented
@@ -732,13 +733,15 @@ int acpi_suspend(u32 acpi_state)
732 * via @wake. 733 * via @wake.
733 */ 734 */
734 735
735int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p) 736int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p, int d_max_in)
736{ 737{
737 acpi_handle handle = DEVICE_ACPI_HANDLE(dev); 738 acpi_handle handle = DEVICE_ACPI_HANDLE(dev);
738 struct acpi_device *adev; 739 struct acpi_device *adev;
739 char acpi_method[] = "_SxD"; 740 char acpi_method[] = "_SxD";
740 unsigned long long d_min, d_max; 741 unsigned long long d_min, d_max;
741 742
743 if (d_max_in < ACPI_STATE_D0 || d_max_in > ACPI_STATE_D3)
744 return -EINVAL;
742 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) { 745 if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &adev))) {
743 printk(KERN_DEBUG "ACPI handle has no context!\n"); 746 printk(KERN_DEBUG "ACPI handle has no context!\n");
744 return -ENODEV; 747 return -ENODEV;
@@ -746,8 +749,10 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
746 749
747 acpi_method[2] = '0' + acpi_target_sleep_state; 750 acpi_method[2] = '0' + acpi_target_sleep_state;
748 /* 751 /*
749 * If the sleep state is S0, we will return D3, but if the device has 752 * If the sleep state is S0, the lowest limit from ACPI is D3,
750 * _S0W, we will use the value from _S0W 753 * but if the device has _S0W, we will use the value from _S0W
754 * as the lowest limit from ACPI. Finally, we will constrain
755 * the lowest limit with the specified one.
751 */ 756 */
752 d_min = ACPI_STATE_D0; 757 d_min = ACPI_STATE_D0;
753 d_max = ACPI_STATE_D3; 758 d_max = ACPI_STATE_D3;
@@ -791,10 +796,20 @@ int acpi_pm_device_sleep_state(struct device *dev, int *d_min_p)
791 } 796 }
792 } 797 }
793 798
799 if (d_max_in < d_min)
800 return -EINVAL;
794 if (d_min_p) 801 if (d_min_p)
795 *d_min_p = d_min; 802 *d_min_p = d_min;
803 /* constrain d_max with specified lowest limit (max number) */
804 if (d_max > d_max_in) {
805 for (d_max = d_max_in; d_max > d_min; d_max--) {
806 if (adev->power.states[d_max].flags.valid)
807 break;
808 }
809 }
796 return d_max; 810 return d_max;
797} 811}
812EXPORT_SYMBOL(acpi_pm_device_sleep_state);
798#endif /* CONFIG_PM */ 813#endif /* CONFIG_PM */
799 814
800#ifdef CONFIG_PM_SLEEP 815#ifdef CONFIG_PM_SLEEP
@@ -831,6 +846,7 @@ int acpi_pm_device_run_wake(struct device *phys_dev, bool enable)
831 846
832 return 0; 847 return 0;
833} 848}
849EXPORT_SYMBOL(acpi_pm_device_run_wake);
834 850
835/** 851/**
836 * acpi_pm_device_sleep_wake - enable or disable the system wake-up 852 * acpi_pm_device_sleep_wake - enable or disable the system wake-up
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 8275e7b06962..9fe90e9fecb5 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 {
@@ -1039,16 +1041,17 @@ static int acpi_thermal_remove(struct acpi_device *device, int type)
1039 return 0; 1041 return 0;
1040} 1042}
1041 1043
1042static int acpi_thermal_resume(struct acpi_device *device) 1044static int acpi_thermal_resume(struct device *dev)
1043{ 1045{
1044 struct acpi_thermal *tz = NULL; 1046 struct acpi_thermal *tz;
1045 int i, j, power_state, result; 1047 int i, j, power_state, result;
1046 1048
1047 1049 if (!dev)
1048 if (!device || !acpi_driver_data(device))
1049 return -EINVAL; 1050 return -EINVAL;
1050 1051
1051 tz = acpi_driver_data(device); 1052 tz = acpi_driver_data(to_acpi_device(dev));
1053 if (!tz)
1054 return -EINVAL;
1052 1055
1053 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { 1056 for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
1054 if (!(&tz->trips.active[i])) 1057 if (!(&tz->trips.active[i]))