ACPI: introduce helper function acpi_execute_simple_method()
authorJiang Liu <jiang.liu@huawei.com>
Fri, 28 Jun 2013 16:24:39 +0000 (00:24 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sun, 14 Jul 2013 23:33:10 +0000 (01:33 +0200)
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>
drivers/acpi/battery.c
drivers/acpi/bus.c
drivers/acpi/power.c
drivers/acpi/sleep.c
drivers/acpi/thermal.c
drivers/acpi/utils.c
drivers/acpi/video.c
include/acpi/acpi_bus.h

index a7627166e18b36acc2c4338bd2f10aeb044a0710..74669ac4c615afd4f96e2a96e3ca116d758899ed 100644 (file)
@@ -525,18 +525,14 @@ static int acpi_battery_get_state(struct acpi_battery *battery)
 static int acpi_battery_set_alarm(struct acpi_battery *battery)
 {
        acpi_status status = 0;
-       union acpi_object arg0 = { .type = ACPI_TYPE_INTEGER };
-       struct acpi_object_list arg_list = { 1, &arg0 };
 
        if (!acpi_battery_present(battery) ||
            !test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags))
                return -ENODEV;
 
-       arg0.integer.value = battery->alarm;
-
        mutex_lock(&battery->lock);
-       status = acpi_evaluate_object(battery->device->handle, "_BTP",
-                                &arg_list, NULL);
+       status = acpi_execute_simple_method(battery->device->handle, "_BTP",
+                                           battery->alarm);
        mutex_unlock(&battery->lock);
 
        if (ACPI_FAILURE(status))
index a5bb33bab4485307f7969b19ff9d9ea9cb3f67e2..a5a032e2344ec513be756380fe04abb08acc7ba2 100644 (file)
@@ -593,8 +593,6 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data)
 static int __init acpi_bus_init_irq(void)
 {
        acpi_status status;
-       union acpi_object arg = { ACPI_TYPE_INTEGER };
-       struct acpi_object_list arg_list = { 1, &arg };
        char *message = NULL;
 
 
@@ -623,9 +621,7 @@ static int __init acpi_bus_init_irq(void)
 
        printk(KERN_INFO PREFIX "Using %s for interrupt routing\n", message);
 
-       arg.integer.value = acpi_irq_model;
-
-       status = acpi_evaluate_object(NULL, "\\_PIC", &arg_list, NULL);
+       status = acpi_execute_simple_method(NULL, "\\_PIC", acpi_irq_model);
        if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
                ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PIC"));
                return -ENODEV;
index 5c28c894c0fc204925f489fdf988a01abb74bc88..1460c88a7c0eca3f8db4492cc15de42c169e4c63 100644 (file)
@@ -637,9 +637,7 @@ int acpi_device_sleep_wake(struct acpi_device *dev,
        }
 
        /* Execute _PSW */
-       arg_list.count = 1;
-       in_arg[0].integer.value = enable;
-       status = acpi_evaluate_object(dev->handle, "_PSW", &arg_list, NULL);
+       status = acpi_execute_simple_method(dev->handle, "_PSW", enable);
        if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
                printk(KERN_ERR PREFIX "_PSW execution failed\n");
                dev->wakeup.flags.valid = 0;
index 187ab61889e6da5fab9312e987a620a4cb212280..81b0f03d97db75a66fa649ec6ce505f5c0a6afb8 100644 (file)
@@ -31,12 +31,9 @@ static u8 sleep_states[ACPI_S_STATE_COUNT];
 
 static void acpi_sleep_tts_switch(u32 acpi_state)
 {
-       union acpi_object in_arg = { ACPI_TYPE_INTEGER };
-       struct acpi_object_list arg_list = { 1, &in_arg };
-       acpi_status status = AE_OK;
+       acpi_status status;
 
-       in_arg.integer.value = acpi_state;
-       status = acpi_evaluate_object(NULL, "\\_TTS", &arg_list, NULL);
+       status = acpi_execute_simple_method(NULL, "\\_TTS", acpi_state);
        if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
                /*
                 * OS can't evaluate the _TTS object correctly. Some warning
index a33821ca3895e672a32d1d145aca7108751667e5..94523c79dc5f2ff7115d34b050fff17bc58e70e7 100644 (file)
@@ -239,26 +239,16 @@ static int acpi_thermal_get_polling_frequency(struct acpi_thermal *tz)
 
 static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
 {
-       acpi_status status = AE_OK;
-       union acpi_object arg0 = { ACPI_TYPE_INTEGER };
-       struct acpi_object_list arg_list = { 1, &arg0 };
-       acpi_handle handle = NULL;
-
-
        if (!tz)
                return -EINVAL;
 
-       status = acpi_get_handle(tz->device->handle, "_SCP", &handle);
-       if (ACPI_FAILURE(status)) {
+       if (!acpi_has_method(tz->device->handle, "_SCP")) {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "_SCP not present\n"));
                return -ENODEV;
-       }
-
-       arg0.integer.value = mode;
-
-       status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
-       if (ACPI_FAILURE(status))
+       } else if (ACPI_FAILURE(acpi_execute_simple_method(tz->device->handle,
+                                                          "_SCP", mode))) {
                return -ENODEV;
+       }
 
        return 0;
 }
index b08d97376f8498ac5f558f8dddb541f0813e3ff9..87b85882b5dfea4b49d19963cae68a4b68c11f88 100644 (file)
@@ -510,3 +510,15 @@ bool acpi_has_method(acpi_handle handle, char *name)
        return ACPI_SUCCESS(acpi_get_handle(handle, name, &tmp));
 }
 EXPORT_SYMBOL(acpi_has_method);
+
+acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
+                                      u64 arg)
+{
+       union acpi_object obj = { .type = ACPI_TYPE_INTEGER };
+       struct acpi_object_list arg_list = { .count = 1, .pointer = &obj, };
+
+       obj.integer.value = arg;
+
+       return acpi_evaluate_object(handle, method, &arg_list, NULL);
+}
+EXPORT_SYMBOL(acpi_execute_simple_method);
index a84533e67b9d02b1e0e595a08d5707bb7670d82b..b862c7f7494197164387a614df9eb74562173515 100644 (file)
@@ -353,14 +353,10 @@ static int
 acpi_video_device_lcd_set_level(struct acpi_video_device *device, int level)
 {
        int status;
-       union acpi_object arg0 = { ACPI_TYPE_INTEGER };
-       struct acpi_object_list args = { 1, &arg0 };
        int state;
 
-       arg0.integer.value = level;
-
-       status = acpi_evaluate_object(device->dev->handle, "_BCM",
-                                     &args, NULL);
+       status = acpi_execute_simple_method(device->dev->handle,
+                                           "_BCM", level);
        if (ACPI_FAILURE(status)) {
                ACPI_ERROR((AE_INFO, "Evaluating _BCM failed"));
                return -EIO;
@@ -628,18 +624,15 @@ static int
 acpi_video_bus_DOS(struct acpi_video_bus *video, int bios_flag, int lcd_flag)
 {
        acpi_status status;
-       union acpi_object arg0 = { ACPI_TYPE_INTEGER };
-       struct acpi_object_list args = { 1, &arg0 };
 
        if (!video->cap._DOS)
                return 0;
 
        if (bios_flag < 0 || bios_flag > 3 || lcd_flag < 0 || lcd_flag > 1)
                return -EINVAL;
-       arg0.integer.value = (lcd_flag << 2) | bios_flag;
-       video->dos_setting = arg0.integer.value;
-       status = acpi_evaluate_object(video->device->handle, "_DOS",
-               &args, NULL);
+       video->dos_setting = (lcd_flag << 2) | bios_flag;
+       status = acpi_execute_simple_method(video->device->handle, "_DOS",
+                                           (lcd_flag << 2) | bios_flag);
        if (ACPI_FAILURE(status))
                return -EIO;
 
index 62b2811bade44ccc67ead204d83f7e35fac5e743..e3862587b9dee1c29b95c5566a154785c8847da8 100644 (file)
@@ -58,6 +58,8 @@ acpi_status
 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
 
 bool acpi_has_method(acpi_handle handle, char *name);
+acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
+                                      u64 arg);
 
 #ifdef CONFIG_ACPI