diff options
author | Jiang Liu <jiang.liu@huawei.com> | 2013-06-28 12:24:39 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-07-14 19:33:10 -0400 |
commit | 0db98202605c3d32e023d43c30b5bd878f520976 (patch) | |
tree | 7aec122f45db5c6b6c2f046ccf1eb9fa160fb616 | |
parent | 952c63e9512b63220886105cfc791507046fa39a (diff) |
ACPI: introduce helper function acpi_execute_simple_method()
Introduce helper function acpi_execute_simple_method() and use it in
a number of places to simplify code.
[rjw: Changelog]
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/acpi/battery.c | 8 | ||||
-rw-r--r-- | drivers/acpi/bus.c | 6 | ||||
-rw-r--r-- | drivers/acpi/power.c | 4 | ||||
-rw-r--r-- | drivers/acpi/sleep.c | 7 | ||||
-rw-r--r-- | drivers/acpi/thermal.c | 18 | ||||
-rw-r--r-- | drivers/acpi/utils.c | 12 | ||||
-rw-r--r-- | drivers/acpi/video.c | 17 | ||||
-rw-r--r-- | include/acpi/acpi_bus.h | 2 |
8 files changed, 29 insertions, 45 deletions
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index a7627166e18b..74669ac4c615 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c | |||
@@ -525,18 +525,14 @@ static int acpi_battery_get_state(struct acpi_battery *battery) | |||
525 | static int acpi_battery_set_alarm(struct acpi_battery *battery) | 525 | static int acpi_battery_set_alarm(struct acpi_battery *battery) |
526 | { | 526 | { |
527 | acpi_status status = 0; | 527 | acpi_status status = 0; |
528 | union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER }; | ||
529 | struct acpi_object_list arg_list = { 1, &arg0 }; | ||
530 | 528 | ||
531 | if (!acpi_battery_present(battery) || | 529 | if (!acpi_battery_present(battery) || |
532 | !test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags)) | 530 | !test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags)) |
533 | return -ENODEV; | 531 | return -ENODEV; |
534 | 532 | ||
535 | arg0.integer.value = battery->alarm; | ||
536 | |||
537 | mutex_lock(&battery->lock); | 533 | mutex_lock(&battery->lock); |
538 | status = acpi_evaluate_object(battery->device->handle, "_BTP", | 534 | status = acpi_execute_simple_method(battery->device->handle, "_BTP", |
539 | &arg_list, NULL); | 535 | battery->alarm); |
540 | mutex_unlock(&battery->lock); | 536 | mutex_unlock(&battery->lock); |
541 | 537 | ||
542 | if (ACPI_FAILURE(status)) | 538 | if (ACPI_FAILURE(status)) |
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index a5bb33bab448..a5a032e2344e 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -593,8 +593,6 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) | |||
593 | static int __init acpi_bus_init_irq(void) | 593 | static int __init acpi_bus_init_irq(void) |
594 | { | 594 | { |
595 | acpi_status status; | 595 | acpi_status status; |
596 | union acpi_object arg = { ACPI_TYPE_INTEGER }; | ||
597 | struct acpi_object_list arg_list = { 1, &arg }; | ||
598 | char *message = NULL; | 596 | char *message = NULL; |
599 | 597 | ||
600 | 598 | ||
@@ -623,9 +621,7 @@ static int __init acpi_bus_init_irq(void) | |||
623 | 621 | ||
624 | printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); | 622 | printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message); |
625 | 623 | ||
626 | arg.integer.value = acpi_irq_model; | 624 | status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model); |
627 | |||
628 | status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL); | ||
629 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | 625 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { |
630 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC")); | 626 | ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC")); |
631 | return -ENODEV; | 627 | return -ENODEV; |
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c index 5c28c894c0fc..1460c88a7c0e 100644 --- a/drivers/acpi/power.c +++ b/drivers/acpi/power.c | |||
@@ -637,9 +637,7 @@ int acpi_device_sleep_wake(struct acpi_device *dev, | |||
637 | } | 637 | } |
638 | 638 | ||
639 | /* Execute _PSW */ | 639 | /* Execute _PSW */ |
640 | arg_list.count = 1; | 640 | status = acpi_execute_simple_method(dev->handle, "_PSW", enable); |
641 | in_arg[0].integer.value = enable; | ||
642 | status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL); | ||
643 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { | 641 | if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { |
644 | printk(KERN_ERR PREFIX "_PSW execution failed\n"); | 642 | printk(KERN_ERR PREFIX "_PSW execution failed\n"); |
645 | dev->wakeup.flags.valid = 0; | 643 | dev->wakeup.flags.valid = 0; |
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 187ab61889e6..81b0f03d97db 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c | |||
@@ -31,12 +31,9 @@ static u8 sleep_states[ACPI_S_STATE_COUNT]; | |||
31 | 31 | ||
32 | static void acpi_sleep_tts_switch(u32 acpi_state) | 32 | static void acpi_sleep_tts_switch(u32 acpi_state) |
33 | { | 33 | { |
34 | union acpi_object in_arg = { ACPI_TYPE_INTEGER }; | 34 | acpi_status status; |
35 | struct acpi_object_list arg_list = { 1, &in_arg }; | ||
36 | acpi_status status = AE_OK; | ||
37 | 35 | ||
38 | in_arg.integer.value = acpi_state; | 36 | status = acpi_execute_simple_method(NULL, "\\_TTS", acpi_state); |
39 | status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL); | ||
40 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { | 37 | if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { |
41 | /* | 38 | /* |
42 | * OS can't evaluate the _TTS object correctly. Some warning | 39 | * OS can't evaluate the _TTS object correctly. Some warning |
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index a33821ca3895..94523c79dc5f 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c | |||
@@ -239,26 +239,16 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz) | |||
239 | 239 | ||
240 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) | 240 | static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode) |
241 | { | 241 | { |
242 | acpi_status status = AE_OK; | ||
243 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | ||
244 | struct acpi_object_list arg_list = { 1, &arg0 }; | ||
245 | acpi_handle handle = NULL; | ||
246 | |||
247 | |||
248 | if (!tz) | 242 | if (!tz) |
249 | return -EINVAL; | 243 | return -EINVAL; |
250 | 244 | ||
251 | status = acpi_get_handle(tz->device->handle, "_SCP", &handle); | 245 | if (!acpi_has_method(tz->device->handle, "_SCP")) { |
252 | if (ACPI_FAILURE(status)) { | ||
253 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); | 246 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n")); |
254 | return -ENODEV; | 247 | return -ENODEV; |
255 | } | 248 | } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle, |
256 | 249 | "_SCP", mode))) { | |
257 | arg0.integer.value = mode; | ||
258 | |||
259 | status = acpi_evaluate_object(handle, NULL, &arg_list, NULL); | ||
260 | if (ACPI_FAILURE(status)) | ||
261 | return -ENODEV; | 250 | return -ENODEV; |
251 | } | ||
262 | 252 | ||
263 | return 0; | 253 | return 0; |
264 | } | 254 | } |
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c index b08d97376f84..87b85882b5df 100644 --- a/drivers/acpi/utils.c +++ b/drivers/acpi/utils.c | |||
@@ -510,3 +510,15 @@ bool acpi_has_method(acpi_handle handle, char *name) | |||
510 | return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp)); | 510 | return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp)); |
511 | } | 511 | } |
512 | EXPORT_SYMBOL(acpi_has_method); | 512 | EXPORT_SYMBOL(acpi_has_method); |
513 | |||
514 | acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, | ||
515 | u64 arg) | ||
516 | { | ||
517 | union acpi_object obj = { .type = ACPI_TYPE_INTEGER }; | ||
518 | struct acpi_object_list arg_list = { .count = 1, .pointer = &obj, }; | ||
519 | |||
520 | obj.integer.value = arg; | ||
521 | |||
522 | return acpi_evaluate_object(handle, method, &arg_list, NULL); | ||
523 | } | ||
524 | EXPORT_SYMBOL(acpi_execute_simple_method); | ||
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c index a84533e67b9d..b862c7f74941 100644 --- a/drivers/acpi/video.c +++ b/drivers/acpi/video.c | |||
@@ -353,14 +353,10 @@ static int | |||
353 | acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) | 353 | acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level) |
354 | { | 354 | { |
355 | int status; | 355 | int status; |
356 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | ||
357 | struct acpi_object_list args = { 1, &arg0 }; | ||
358 | int state; | 356 | int state; |
359 | 357 | ||
360 | arg0.integer.value = level; | 358 | status = acpi_execute_simple_method(device->dev->handle, |
361 | 359 | "_BCM", level); | |
362 | status = acpi_evaluate_object(device->dev->handle, "_BCM", | ||
363 | &args, NULL); | ||
364 | if (ACPI_FAILURE(status)) { | 360 | if (ACPI_FAILURE(status)) { |
365 | ACPI_ERROR((AE_INFO, "Evaluating _BCM failed")); | 361 | ACPI_ERROR((AE_INFO, "Evaluating _BCM failed")); |
366 | return -EIO; | 362 | return -EIO; |
@@ -628,18 +624,15 @@ static int | |||
628 | acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) | 624 | acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag) |
629 | { | 625 | { |
630 | acpi_status status; | 626 | acpi_status status; |
631 | union acpi_object arg0 = { ACPI_TYPE_INTEGER }; | ||
632 | struct acpi_object_list args = { 1, &arg0 }; | ||
633 | 627 | ||
634 | if (!video->cap._DOS) | 628 | if (!video->cap._DOS) |
635 | return 0; | 629 | return 0; |
636 | 630 | ||
637 | if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) | 631 | if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1) |
638 | return -EINVAL; | 632 | return -EINVAL; |
639 | arg0.integer.value = (lcd_flag << 2) | bios_flag; | 633 | video->dos_setting = (lcd_flag << 2) | bios_flag; |
640 | video->dos_setting = arg0.integer.value; | 634 | status = acpi_execute_simple_method(video->device->handle, "_DOS", |
641 | status = acpi_evaluate_object(video->device->handle, "_DOS", | 635 | (lcd_flag << 2) | bios_flag); |
642 | &args, NULL); | ||
643 | if (ACPI_FAILURE(status)) | 636 | if (ACPI_FAILURE(status)) |
644 | return -EIO; | 637 | return -EIO; |
645 | 638 | ||
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 62b2811bade4..e3862587b9de 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h | |||
@@ -58,6 +58,8 @@ acpi_status | |||
58 | acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld); | 58 | acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld); |
59 | 59 | ||
60 | bool acpi_has_method(acpi_handle handle, char *name); | 60 | bool acpi_has_method(acpi_handle handle, char *name); |
61 | acpi_status acpi_execute_simple_method(acpi_handle handle, char *method, | ||
62 | u64 arg); | ||
61 | 63 | ||
62 | #ifdef CONFIG_ACPI | 64 | #ifdef CONFIG_ACPI |
63 | 65 | ||