Blame view

drivers/acpi/wakeup.c 2.65 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
  /*
   * wakeup.c - support wakeup devices
   * Copyright (C) 2004 Li Shaohua <shaohua.li@intel.com>
   */
  
  #include <linux/init.h>
  #include <linux/acpi.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
  #include <linux/kernel.h>
  #include <linux/types.h>
e60cc7a6f   Bjorn Helgaas   ACPI: move privat...
10
11
  
  #include "internal.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
  #include "sleep.h"
9090589d8   Shaohua Li   ACPI: convert acp...
13
14
15
16
17
  /*
   * 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
18
  #define _COMPONENT		ACPI_SYSTEM_COMPONENT
4be44fcd3   Len Brown   [ACPI] Lindent al...
19
  ACPI_MODULE_NAME("wakeup_devices")
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  /**
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
22
   * acpi_enable_wakeup_devices - Enable wake-up device GPEs.
9630bdd9b   Rafael J. Wysocki   ACPI: Use GPE ref...
23
24
   * @sleep_state: ACPI system sleep state.
   *
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
25
26
27
   * 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
28
   */
78f5f0231   Rafael J. Wysocki   ACPI / Wakeup: Si...
29
  void acpi_enable_wakeup_devices(u8 sleep_state)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  {
4be44fcd3   Len Brown   [ACPI] Lindent al...
31
  	struct list_head *node, *next;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32

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

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

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

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

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

9090589d8   Shaohua Li   ACPI: convert acp...
78
  	mutex_lock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  	list_for_each_safe(node, next, &acpi_wakeup_device_list) {
4be44fcd3   Len Brown   [ACPI] Lindent al...
80
81
82
  		struct acpi_device *dev = container_of(node,
  						       struct acpi_device,
  						       wakeup_list);
2a5d24286   Rafael J. Wysocki   ACPI / Wakeup: En...
83
84
85
86
  		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...
87
  			device_set_wakeup_enable(&dev->dev, true);
2a5d24286   Rafael J. Wysocki   ACPI / Wakeup: En...
88
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
  	}
9090589d8   Shaohua Li   ACPI: convert acp...
90
  	mutex_unlock(&acpi_device_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
92
  	return 0;
  }