Merge branch 'gpe-regression-fixes' into release
[pandora-kernel.git] / drivers / acpi / acpica / evxfevnt.c
index d5a5efc..d97b8dc 100644 (file)
@@ -208,6 +208,44 @@ acpi_status acpi_enable_event(u32 event, u32 flags)
 
 ACPI_EXPORT_SYMBOL(acpi_enable_event)
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_clear_and_enable_gpe
+ *
+ * PARAMETERS:  gpe_event_info  - GPE to enable
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Clear the given GPE from stale events and enable it.
+ *
+ ******************************************************************************/
+static acpi_status
+acpi_clear_and_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
+{
+       acpi_status status;
+
+       /*
+        * We will only allow a GPE to be enabled if it has either an
+        * associated method (_Lxx/_Exx) or a handler. Otherwise, the
+        * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
+        * first time it fires.
+        */
+       if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
+               return_ACPI_STATUS(AE_NO_HANDLER);
+       }
+
+       /* Clear the GPE (of stale events) */
+       status = acpi_hw_clear_gpe(gpe_event_info);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
+       /* Enable the requested GPE */
+       status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
+
+       return_ACPI_STATUS(status);
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_set_gpe
@@ -249,11 +287,11 @@ acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
 
        switch (action) {
        case ACPI_GPE_ENABLE:
-               status = acpi_ev_enable_gpe(gpe_event_info);
+               status = acpi_clear_and_enable_gpe(gpe_event_info);
                break;
 
        case ACPI_GPE_DISABLE:
-               status = acpi_ev_disable_gpe(gpe_event_info);
+               status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
                break;
 
        default:
@@ -316,7 +354,11 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
 
                gpe_event_info->runtime_count++;
                if (gpe_event_info->runtime_count == 1) {
-                       status = acpi_ev_enable_gpe(gpe_event_info);
+                       status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
+                       if (ACPI_SUCCESS(status)) {
+                               status = acpi_clear_and_enable_gpe(gpe_event_info);
+                       }
+
                        if (ACPI_FAILURE(status)) {
                                gpe_event_info->runtime_count--;
                                goto unlock_and_exit;
@@ -343,7 +385,7 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
                 */
                gpe_event_info->wakeup_count++;
                if (gpe_event_info->wakeup_count == 1) {
-                       (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
+                       status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
                }
        }
 
@@ -403,7 +445,12 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type
 
                gpe_event_info->runtime_count--;
                if (!gpe_event_info->runtime_count) {
-                       status = acpi_ev_disable_gpe(gpe_event_info);
+                       status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
+                       if (ACPI_SUCCESS(status)) {
+                               status = acpi_hw_low_set_gpe(gpe_event_info,
+                                                            ACPI_GPE_DISABLE);
+                       }
+
                        if (ACPI_FAILURE(status)) {
                                gpe_event_info->runtime_count++;
                                goto unlock_and_exit;
@@ -424,7 +471,7 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type
 
                gpe_event_info->wakeup_count--;
                if (!gpe_event_info->wakeup_count) {
-                       (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
+                       status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
                }
        }