]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ACPI: introduce two helper functions for _EJ0 and _LCK
authorJiang Liu <jiang.liu@huawei.com>
Fri, 28 Jun 2013 16:24:40 +0000 (00:24 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Sun, 14 Jul 2013 23:33:10 +0000 (01:33 +0200)
Introduce two helper functions, acpi_evaluate_ej0() and
acpi_evaluate_lck(), that will execute the _EJ0 and _LCK ACPI
control methods, respectively, and use them to simplify the
ACPI scan 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/scan.c
drivers/acpi/utils.c
include/acpi/acpi_bus.h

index ada0b4cf2ba5d4b19cf7e27edca3fd306ad06cf4..4c25c3b7ef811467fa88e8eb2f75e8067f7123d9 100644 (file)
@@ -193,8 +193,6 @@ static acpi_status acpi_bus_online_companions(acpi_handle handle, u32 lvl,
 static int acpi_scan_hot_remove(struct acpi_device *device)
 {
        acpi_handle handle = device->handle;
-       struct acpi_object_list arg_list;
-       union acpi_object arg;
        struct device *errdev;
        acpi_status status;
        unsigned long long sta;
@@ -257,32 +255,15 @@ static int acpi_scan_hot_remove(struct acpi_device *device)
        put_device(&device->dev);
        device = NULL;
 
-       if (acpi_has_method(handle, "_LCK")) {
-               arg_list.count = 1;
-               arg_list.pointer = &arg;
-               arg.type = ACPI_TYPE_INTEGER;
-               arg.integer.value = 0;
-               acpi_evaluate_object(handle, "_LCK", &arg_list, NULL);
-       }
-
-       arg_list.count = 1;
-       arg_list.pointer = &arg;
-       arg.type = ACPI_TYPE_INTEGER;
-       arg.integer.value = 1;
-
+       acpi_evaluate_lck(handle, 0);
        /*
         * TBD: _EJD support.
         */
-       status = acpi_evaluate_object(handle, "_EJ0", &arg_list, NULL);
-       if (ACPI_FAILURE(status)) {
-               if (status == AE_NOT_FOUND) {
-                       return -ENODEV;
-               } else {
-                       acpi_handle_warn(handle, "Eject failed (0x%x)\n",
-                                                               status);
-                       return -EIO;
-               }
-       }
+       status = acpi_evaluate_ej0(handle);
+       if (status == AE_NOT_FOUND)
+               return -ENODEV;
+       else if (ACPI_FAILURE(status))
+               return -EIO;
 
        /*
         * Verify if eject was indeed successful.  If not, log an error
index 87b85882b5dfea4b49d19963cae68a4b68c11f88..552248b0005b01a241ab511e52eef08a1c15d244 100644 (file)
@@ -522,3 +522,46 @@ acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
        return acpi_evaluate_object(handle, method, &arg_list, NULL);
 }
 EXPORT_SYMBOL(acpi_execute_simple_method);
+
+/**
+ * acpi_evaluate_ej0: Evaluate _EJ0 method for hotplug operations
+ * @handle: ACPI device handle
+ *
+ * Evaluate device's _EJ0 method for hotplug operations.
+ */
+acpi_status acpi_evaluate_ej0(acpi_handle handle)
+{
+       acpi_status status;
+
+       status = acpi_execute_simple_method(handle, "_EJ0", 1);
+       if (status == AE_NOT_FOUND)
+               acpi_handle_warn(handle, "No _EJ0 support for device\n");
+       else if (ACPI_FAILURE(status))
+               acpi_handle_warn(handle, "Eject failed (0x%x)\n", status);
+
+       return status;
+}
+
+/**
+ * acpi_evaluate_lck: Evaluate _LCK method to lock/unlock device
+ * @handle: ACPI device handle
+ * @lock: lock device if non-zero, otherwise unlock device
+ *
+ * Evaluate device's _LCK method if present to lock/unlock device
+ */
+acpi_status acpi_evaluate_lck(acpi_handle handle, int lock)
+{
+       acpi_status status;
+
+       status = acpi_execute_simple_method(handle, "_LCK", !!lock);
+       if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
+               if (lock)
+                       acpi_handle_warn(handle,
+                               "Locking device failed (0x%x)\n", status);
+               else
+                       acpi_handle_warn(handle,
+                               "Unlocking device failed (0x%x)\n", status);
+       }
+
+       return status;
+}
index e3862587b9dee1c29b95c5566a154785c8847da8..f499157b04e885d5e863a86f45bc47936a4cff2e 100644 (file)
@@ -60,6 +60,8 @@ 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);
+acpi_status acpi_evaluate_ej0(acpi_handle handle);
+acpi_status acpi_evaluate_lck(acpi_handle handle, int lock);
 
 #ifdef CONFIG_ACPI