1 #include <linux/proc_fs.h>
2 #include <linux/seq_file.h>
3 #include <linux/export.h>
4 #include <linux/suspend.h>
6 #include <linux/acpi.h>
7 #include <asm/uaccess.h>
12 #define _COMPONENT ACPI_SYSTEM_COMPONENT
15 * this file provides support for:
19 ACPI_MODULE_NAME("sleep")
22 acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
24 struct list_head *node, *next;
26 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
28 mutex_lock(&acpi_device_lock);
29 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
30 struct acpi_device *dev =
31 container_of(node, struct acpi_device, wakeup_list);
32 struct acpi_device_physical_node *entry;
34 if (!dev->wakeup.flags.valid)
37 seq_printf(seq, "%s\t S%d\t",
39 (u32) dev->wakeup.sleep_state);
41 mutex_lock(&dev->physical_node_lock);
43 if (!dev->physical_node_count) {
44 seq_printf(seq, "%c%-8s\n",
45 dev->wakeup.flags.run_wake ? '*' : ' ',
46 device_may_wakeup(&dev->dev) ?
47 "enabled" : "disabled");
50 list_for_each_entry(entry, &dev->physical_node_list,
52 ldev = get_device(entry->dev);
57 dev->physical_node_list.next)
58 seq_printf(seq, "\t\t");
60 seq_printf(seq, "%c%-8s %s:%s\n",
61 dev->wakeup.flags.run_wake ? '*' : ' ',
62 (device_may_wakeup(&dev->dev) ||
63 device_may_wakeup(ldev)) ?
64 "enabled" : "disabled",
65 ldev->bus ? ldev->bus->name :
66 "no-bus", dev_name(ldev));
71 mutex_unlock(&dev->physical_node_lock);
73 mutex_unlock(&acpi_device_lock);
77 static void physical_device_enable_wakeup(struct acpi_device *adev)
79 struct acpi_device_physical_node *entry;
81 mutex_lock(&adev->physical_node_lock);
83 list_for_each_entry(entry,
84 &adev->physical_node_list, node)
85 if (entry->dev && device_can_wakeup(entry->dev)) {
86 bool enable = !device_may_wakeup(entry->dev);
87 device_set_wakeup_enable(entry->dev, enable);
90 mutex_unlock(&adev->physical_node_lock);
94 acpi_system_write_wakeup_device(struct file *file,
95 const char __user * buffer,
96 size_t count, loff_t * ppos)
98 struct list_head *node, *next;
105 if (copy_from_user(strbuf, buffer, count))
107 strbuf[count] = '\0';
108 sscanf(strbuf, "%s", str);
110 mutex_lock(&acpi_device_lock);
111 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
112 struct acpi_device *dev =
113 container_of(node, struct acpi_device, wakeup_list);
114 if (!dev->wakeup.flags.valid)
117 if (!strncmp(dev->pnp.bus_id, str, 4)) {
118 if (device_can_wakeup(&dev->dev)) {
119 bool enable = !device_may_wakeup(&dev->dev);
120 device_set_wakeup_enable(&dev->dev, enable);
122 physical_device_enable_wakeup(dev);
127 mutex_unlock(&acpi_device_lock);
132 acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
134 return single_open(file, acpi_system_wakeup_device_seq_show,
138 static const struct file_operations acpi_system_wakeup_device_fops = {
139 .owner = THIS_MODULE,
140 .open = acpi_system_wakeup_device_open_fs,
142 .write = acpi_system_write_wakeup_device,
144 .release = single_release,
147 int __init acpi_sleep_proc_init(void)
149 /* 'wakeup device' [R/W] */
150 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
151 acpi_root_dir, &acpi_system_wakeup_device_fops);