Blame view

drivers/acpi/wakeup.c 2.68 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
  /*
   * wakeup.c - support wakeup devices
   * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
   */
  
  #include <linux/init.h>
  #include <linux/acpi.h>
  #include <acpi/acpi_drivers.h>
  #include <linux/kernel.h>
  #include <linux/types.h>
e60cc7a6f   Bjorn Helgaas   ACPI: move privat...
11
12
  
  #include "internal.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include "sleep.h"
9090589d8   Shaohua Li   ACPI: convert acp...
14
15
16
17
18
  /*
   * We didn't lock acpi_device_lock in the file, because it invokes oops in
   * suspend/resume and isn't really required as this is called in S-state. At
   * that time, there is no device hotplug
   **/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  #define _COMPONENT		ACPI_SYSTEM_COMPONENT
4be44fcd3   Len Brown   [ACPI] Lindent al...
20
  ACPI_MODULE_NAME("wakeup_devices")
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  /**
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
23
   * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
9630bdd9b   Rafael J. Wysocki   ACPI: Use GPE ref...
24
25
   * @sleep_state: ACPI system sleep state.
   *
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
26
27
28
   * Enable wakeup device power of devices with the state.enable flag set and set
   * the wakeup enable mask bits in the GPE registers that correspond to wakeup
   * devices.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
   */
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
30
  void acpi_enable_wakeup_devices(u8 sleep_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
32
  	struct list_head *node, *next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
  	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
9b0393308   Alexey Starikovskiy   ACPI: Hibernate e...
35
36
  		struct acpi_device *dev =
  			container_of(node, struct acpi_device, wakeup_list);
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
37

e8b6f9701   Rafael J. Wysocki   ACPICA: Introduce...
38
  		if (!dev->wakeup.flags.valid
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
39
40
41
  		    || sleep_state > (u32) dev->wakeup.sleep_state
  		    || !(device_may_wakeup(&dev->dev)
  		        || dev->wakeup.prepare_count))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  			continue;
9630bdd9b   Rafael J. Wysocki   ACPI: Use GPE ref...
43

f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
44
  		if (device_may_wakeup(&dev->dev))
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
45
  			acpi_enable_wakeup_device_power(dev, sleep_state);
9630bdd9b   Rafael J. Wysocki   ACPI: Use GPE ref...
46
  		/* The wake-up power should have been enabled already. */
3a37898d5   Lin Ming   ACPICA: Rename so...
47
  		acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
e8b6f9701   Rafael J. Wysocki   ACPICA: Introduce...
48
  				ACPI_GPE_ENABLE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
52
  }
  
  /**
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
53
   * acpi_disable_wakeup_devices - Disable devices' wakeup capability.
9630bdd9b   Rafael J. Wysocki   ACPI: Use GPE ref...
54
   * @sleep_state: ACPI system sleep state.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
   */
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
56
  void acpi_disable_wakeup_devices(u8 sleep_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
58
  	struct list_head *node, *next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
9b0393308   Alexey Starikovskiy   ACPI: Hibernate e...
61
62
  		struct acpi_device *dev =
  			container_of(node, struct acpi_device, wakeup_list);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63

e8b6f9701   Rafael J. Wysocki   ACPICA: Introduce...
64
  		if (!dev->wakeup.flags.valid
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
65
66
67
  		    || sleep_state > (u32) dev->wakeup.sleep_state
  		    || !(device_may_wakeup(&dev->dev)
  		        || dev->wakeup.prepare_count))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
68
  			continue;
3a37898d5   Lin Ming   ACPICA: Rename so...
69
  		acpi_set_gpe_wake_mask(dev->wakeup.gpe_device, dev->wakeup.gpe_number,
e8b6f9701   Rafael J. Wysocki   ACPICA: Introduce...
70
  				ACPI_GPE_DISABLE);
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
71
  		if (device_may_wakeup(&dev->dev))
e8b6f9701   Rafael J. Wysocki   ACPICA: Introduce...
72
  			acpi_disable_wakeup_device_power(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
  }
201b8c655   Bjorn Helgaas   ACPI: call acpi_w...
75
  int __init acpi_wakeup_device_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
77
  	struct list_head *node, *next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78

9090589d8   Shaohua Li   ACPI: convert acp...
79
  	mutex_lock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
  	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
81
82
83
  		struct acpi_device *dev = container_of(node,
  						       struct acpi_device,
  						       wakeup_list);
2a5d24286   Rafael J. Wysocki   ACPI / Wakeup: En...
84
85
86
87
  		if (device_can_wakeup(&dev->dev)) {
  			/* Button GPEs are supposed to be always enabled. */
  			acpi_enable_gpe(dev->wakeup.gpe_device,
  					dev->wakeup.gpe_number);
f2b56bc80   Rafael J. Wysocki   ACPI / PM: Use de...
88
  			device_set_wakeup_enable(&dev->dev, true);
2a5d24286   Rafael J. Wysocki   ACPI / Wakeup: En...
89
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  	}
9090589d8   Shaohua Li   ACPI: convert acp...
91
  	mutex_unlock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
  	return 0;
  }