195b482a8SLen Brown /* 295b482a8SLen Brown * wakeup.c - support wakeup devices 395b482a8SLen Brown * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com> 495b482a8SLen Brown */ 595b482a8SLen Brown 695b482a8SLen Brown #include <linux/init.h> 795b482a8SLen Brown #include <linux/acpi.h> 895b482a8SLen Brown #include <acpi/acpi_drivers.h> 995b482a8SLen Brown #include <linux/kernel.h> 1095b482a8SLen Brown #include <linux/types.h> 11e60cc7a6SBjorn Helgaas 12e60cc7a6SBjorn Helgaas #include "internal.h" 1395b482a8SLen Brown #include "sleep.h" 1495b482a8SLen Brown 159090589dSShaohua Li /* 169090589dSShaohua Li * We didn't lock acpi_device_lock in the file, because it invokes oops in 179090589dSShaohua Li * suspend/resume and isn't really required as this is called in S-state. At 189090589dSShaohua Li * that time, there is no device hotplug 199090589dSShaohua Li **/ 2095b482a8SLen Brown #define _COMPONENT ACPI_SYSTEM_COMPONENT 2195b482a8SLen Brown ACPI_MODULE_NAME("wakeup_devices") 2295b482a8SLen Brown 2395b482a8SLen Brown /** 2478f5f023SRafael J. Wysocki * acpi_enable_wakeup_devices - Enable wake-up device GPEs. 259630bdd9SRafael J. Wysocki * @sleep_state: ACPI system sleep state. 269630bdd9SRafael J. Wysocki * 2778f5f023SRafael J. Wysocki * Enable wakeup device power of devices with the state.enable flag set and set 2878f5f023SRafael J. Wysocki * the wakeup enable mask bits in the GPE registers that correspond to wakeup 2978f5f023SRafael J. Wysocki * devices. 3095b482a8SLen Brown */ 3178f5f023SRafael J. Wysocki void acpi_enable_wakeup_devices(u8 sleep_state) 3295b482a8SLen Brown { 3395b482a8SLen Brown struct list_head *node, *next; 3495b482a8SLen Brown 3595b482a8SLen Brown list_for_each_safe(node, next, &acpi_wakeup_device_list) { 3695b482a8SLen Brown struct acpi_device *dev = 3795b482a8SLen Brown container_of(node, struct acpi_device, wakeup_list); 3895b482a8SLen Brown 39e8b6f970SRafael J. Wysocki if (!dev->wakeup.flags.valid 40e8b6f970SRafael J. Wysocki || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count) 419630bdd9SRafael J. Wysocki || sleep_state > (u32) dev->wakeup.sleep_state) 4295b482a8SLen Brown continue; 439630bdd9SRafael J. Wysocki 4478f5f023SRafael J. Wysocki if (dev->wakeup.state.enabled) 4578f5f023SRafael J. Wysocki acpi_enable_wakeup_device_power(dev, sleep_state); 4678f5f023SRafael J. Wysocki 479630bdd9SRafael J. Wysocki /* The wake-up power should have been enabled already. */ 48*3a37898dSLin Ming acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number, 49e8b6f970SRafael J. Wysocki ACPI_GPE_ENABLE); 5095b482a8SLen Brown } 5195b482a8SLen Brown } 5295b482a8SLen Brown 5395b482a8SLen Brown /** 5478f5f023SRafael J. Wysocki * acpi_disable_wakeup_devices - Disable devices' wakeup capability. 559630bdd9SRafael J. Wysocki * @sleep_state: ACPI system sleep state. 5695b482a8SLen Brown */ 5778f5f023SRafael J. Wysocki void acpi_disable_wakeup_devices(u8 sleep_state) 5895b482a8SLen Brown { 5995b482a8SLen Brown struct list_head *node, *next; 6095b482a8SLen Brown 6195b482a8SLen Brown list_for_each_safe(node, next, &acpi_wakeup_device_list) { 6295b482a8SLen Brown struct acpi_device *dev = 6395b482a8SLen Brown container_of(node, struct acpi_device, wakeup_list); 6495b482a8SLen Brown 65e8b6f970SRafael J. Wysocki if (!dev->wakeup.flags.valid 66e8b6f970SRafael J. Wysocki || !(dev->wakeup.state.enabled || dev->wakeup.prepare_count) 679630bdd9SRafael J. Wysocki || (sleep_state > (u32) dev->wakeup.sleep_state)) 6895b482a8SLen Brown continue; 6995b482a8SLen Brown 70*3a37898dSLin Ming acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number, 71e8b6f970SRafael J. Wysocki ACPI_GPE_DISABLE); 72e8b6f970SRafael J. Wysocki 73e8b6f970SRafael J. Wysocki if (dev->wakeup.state.enabled) 7495b482a8SLen Brown acpi_disable_wakeup_device_power(dev); 7595b482a8SLen Brown } 7695b482a8SLen Brown } 7795b482a8SLen Brown 78201b8c65SBjorn Helgaas int __init acpi_wakeup_device_init(void) 7995b482a8SLen Brown { 8095b482a8SLen Brown struct list_head *node, *next; 8195b482a8SLen Brown 829090589dSShaohua Li mutex_lock(&acpi_device_lock); 8395b482a8SLen Brown list_for_each_safe(node, next, &acpi_wakeup_device_list) { 8495b482a8SLen Brown struct acpi_device *dev = container_of(node, 8595b482a8SLen Brown struct acpi_device, 8695b482a8SLen Brown wakeup_list); 87cb1cb178SRafael J. Wysocki if (dev->wakeup.flags.always_enabled) 8895b482a8SLen Brown dev->wakeup.state.enabled = 1; 8995b482a8SLen Brown } 909090589dSShaohua Li mutex_unlock(&acpi_device_lock); 9195b482a8SLen Brown return 0; 9295b482a8SLen Brown } 93