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 40*f2b56bc8SRafael J. Wysocki || sleep_state > (u32) dev->wakeup.sleep_state 41*f2b56bc8SRafael J. Wysocki || !(device_may_wakeup(&dev->dev) 42*f2b56bc8SRafael J. Wysocki || dev->wakeup.prepare_count)) 4395b482a8SLen Brown continue; 449630bdd9SRafael J. Wysocki 45*f2b56bc8SRafael J. Wysocki if (device_may_wakeup(&dev->dev)) 4678f5f023SRafael J. Wysocki acpi_enable_wakeup_device_power(dev, sleep_state); 4778f5f023SRafael J. Wysocki 489630bdd9SRafael J. Wysocki /* The wake-up power should have been enabled already. */ 49e8b6f970SRafael J. Wysocki acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number, 50e8b6f970SRafael J. Wysocki ACPI_GPE_ENABLE); 5195b482a8SLen Brown } 5295b482a8SLen Brown } 5395b482a8SLen Brown 5495b482a8SLen Brown /** 5578f5f023SRafael J. Wysocki * acpi_disable_wakeup_devices - Disable devices' wakeup capability. 569630bdd9SRafael J. Wysocki * @sleep_state: ACPI system sleep state. 5795b482a8SLen Brown */ 5878f5f023SRafael J. Wysocki void acpi_disable_wakeup_devices(u8 sleep_state) 5995b482a8SLen Brown { 6095b482a8SLen Brown struct list_head *node, *next; 6195b482a8SLen Brown 6295b482a8SLen Brown list_for_each_safe(node, next, &acpi_wakeup_device_list) { 6395b482a8SLen Brown struct acpi_device *dev = 6495b482a8SLen Brown container_of(node, struct acpi_device, wakeup_list); 6595b482a8SLen Brown 66e8b6f970SRafael J. Wysocki if (!dev->wakeup.flags.valid 67*f2b56bc8SRafael J. Wysocki || sleep_state > (u32) dev->wakeup.sleep_state 68*f2b56bc8SRafael J. Wysocki || !(device_may_wakeup(&dev->dev) 69*f2b56bc8SRafael J. Wysocki || dev->wakeup.prepare_count)) 7095b482a8SLen Brown continue; 7195b482a8SLen Brown 72e8b6f970SRafael J. Wysocki acpi_gpe_wakeup(dev->wakeup.gpe_device, dev->wakeup.gpe_number, 73e8b6f970SRafael J. Wysocki ACPI_GPE_DISABLE); 74e8b6f970SRafael J. Wysocki 75*f2b56bc8SRafael J. Wysocki if (device_may_wakeup(&dev->dev)) 7695b482a8SLen Brown acpi_disable_wakeup_device_power(dev); 7795b482a8SLen Brown } 7895b482a8SLen Brown } 7995b482a8SLen Brown 80201b8c65SBjorn Helgaas int __init acpi_wakeup_device_init(void) 8195b482a8SLen Brown { 8295b482a8SLen Brown struct list_head *node, *next; 8395b482a8SLen Brown 849090589dSShaohua Li mutex_lock(&acpi_device_lock); 8595b482a8SLen Brown list_for_each_safe(node, next, &acpi_wakeup_device_list) { 8695b482a8SLen Brown struct acpi_device *dev = container_of(node, 8795b482a8SLen Brown struct acpi_device, 8895b482a8SLen Brown wakeup_list); 89*f2b56bc8SRafael J. Wysocki if (device_can_wakeup(&dev->dev)) 90*f2b56bc8SRafael J. Wysocki device_set_wakeup_enable(&dev->dev, true); 9195b482a8SLen Brown } 929090589dSShaohua Li mutex_unlock(&acpi_device_lock); 9395b482a8SLen Brown return 0; 9495b482a8SLen Brown } 95