1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/proc_fs.h>
3 #include <linux/seq_file.h>
4 #include <linux/export.h>
5 #include <linux/suspend.h>
7 #include <linux/acpi.h>
8 #include <linux/uaccess.h>
14 * this file provides support for:
19 acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
21 struct acpi_device *dev, *tmp;
23 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
25 mutex_lock(&acpi_device_lock);
26 list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
28 struct acpi_device_physical_node *entry;
30 if (!dev->wakeup.flags.valid)
33 seq_printf(seq, "%s\t S%d\t",
35 (u32) dev->wakeup.sleep_state);
37 mutex_lock(&dev->physical_node_lock);
39 if (!dev->physical_node_count) {
40 seq_printf(seq, "%c%-8s\n",
41 dev->wakeup.flags.valid ? '*' : ' ',
42 device_may_wakeup(&dev->dev) ?
43 "enabled" : "disabled");
46 list_for_each_entry(entry, &dev->physical_node_list,
48 ldev = get_device(entry->dev);
53 dev->physical_node_list.next)
54 seq_printf(seq, "\t\t");
56 seq_printf(seq, "%c%-8s %s:%s\n",
57 dev->wakeup.flags.valid ? '*' : ' ',
58 (device_may_wakeup(&dev->dev) ||
59 device_may_wakeup(ldev)) ?
60 "enabled" : "disabled",
61 ldev->bus ? ldev->bus->name :
62 "no-bus", dev_name(ldev));
67 mutex_unlock(&dev->physical_node_lock);
69 mutex_unlock(&acpi_device_lock);
73 static void physical_device_enable_wakeup(struct acpi_device *adev)
75 struct acpi_device_physical_node *entry;
77 mutex_lock(&adev->physical_node_lock);
79 list_for_each_entry(entry,
80 &adev->physical_node_list, node)
81 if (entry->dev && device_can_wakeup(entry->dev)) {
82 bool enable = !device_may_wakeup(entry->dev);
83 device_set_wakeup_enable(entry->dev, enable);
86 mutex_unlock(&adev->physical_node_lock);
90 acpi_system_write_wakeup_device(struct file *file,
91 const char __user * buffer,
92 size_t count, loff_t * ppos)
94 struct acpi_device *dev, *tmp;
101 if (copy_from_user(strbuf, buffer, count))
103 strbuf[count] = '\0';
104 sscanf(strbuf, "%s", str);
106 mutex_lock(&acpi_device_lock);
107 list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
109 if (!dev->wakeup.flags.valid)
112 if (!strncmp(dev->pnp.bus_id, str, 4)) {
113 if (device_can_wakeup(&dev->dev)) {
114 bool enable = !device_may_wakeup(&dev->dev);
115 device_set_wakeup_enable(&dev->dev, enable);
117 physical_device_enable_wakeup(dev);
122 mutex_unlock(&acpi_device_lock);
127 acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
129 return single_open(file, acpi_system_wakeup_device_seq_show,
133 static const struct proc_ops acpi_system_wakeup_device_proc_ops = {
134 .proc_open = acpi_system_wakeup_device_open_fs,
135 .proc_read = seq_read,
136 .proc_write = acpi_system_write_wakeup_device,
137 .proc_lseek = seq_lseek,
138 .proc_release = single_release,
141 void __init acpi_sleep_proc_init(void)
143 /* 'wakeup device' [R/W] */
144 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
145 acpi_root_dir, &acpi_system_wakeup_device_proc_ops);