0001
0002 #include <linux/proc_fs.h>
0003 #include <linux/seq_file.h>
0004 #include <linux/export.h>
0005 #include <linux/suspend.h>
0006 #include <linux/bcd.h>
0007 #include <linux/acpi.h>
0008 #include <linux/uaccess.h>
0009
0010 #include "sleep.h"
0011 #include "internal.h"
0012
0013
0014
0015
0016
0017
0018 static int
0019 acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
0020 {
0021 struct acpi_device *dev, *tmp;
0022
0023 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
0024
0025 mutex_lock(&acpi_device_lock);
0026 list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
0027 wakeup_list) {
0028 struct acpi_device_physical_node *entry;
0029
0030 if (!dev->wakeup.flags.valid)
0031 continue;
0032
0033 seq_printf(seq, "%s\t S%d\t",
0034 dev->pnp.bus_id,
0035 (u32) dev->wakeup.sleep_state);
0036
0037 mutex_lock(&dev->physical_node_lock);
0038
0039 if (!dev->physical_node_count) {
0040 seq_printf(seq, "%c%-8s\n",
0041 dev->wakeup.flags.valid ? '*' : ' ',
0042 device_may_wakeup(&dev->dev) ?
0043 "enabled" : "disabled");
0044 } else {
0045 struct device *ldev;
0046 list_for_each_entry(entry, &dev->physical_node_list,
0047 node) {
0048 ldev = get_device(entry->dev);
0049 if (!ldev)
0050 continue;
0051
0052 if (&entry->node !=
0053 dev->physical_node_list.next)
0054 seq_printf(seq, "\t\t");
0055
0056 seq_printf(seq, "%c%-8s %s:%s\n",
0057 dev->wakeup.flags.valid ? '*' : ' ',
0058 (device_may_wakeup(&dev->dev) ||
0059 device_may_wakeup(ldev)) ?
0060 "enabled" : "disabled",
0061 ldev->bus ? ldev->bus->name :
0062 "no-bus", dev_name(ldev));
0063 put_device(ldev);
0064 }
0065 }
0066
0067 mutex_unlock(&dev->physical_node_lock);
0068 }
0069 mutex_unlock(&acpi_device_lock);
0070 return 0;
0071 }
0072
0073 static void physical_device_enable_wakeup(struct acpi_device *adev)
0074 {
0075 struct acpi_device_physical_node *entry;
0076
0077 mutex_lock(&adev->physical_node_lock);
0078
0079 list_for_each_entry(entry,
0080 &adev->physical_node_list, node)
0081 if (entry->dev && device_can_wakeup(entry->dev)) {
0082 bool enable = !device_may_wakeup(entry->dev);
0083 device_set_wakeup_enable(entry->dev, enable);
0084 }
0085
0086 mutex_unlock(&adev->physical_node_lock);
0087 }
0088
0089 static ssize_t
0090 acpi_system_write_wakeup_device(struct file *file,
0091 const char __user * buffer,
0092 size_t count, loff_t * ppos)
0093 {
0094 struct acpi_device *dev, *tmp;
0095 char strbuf[5];
0096 char str[5] = "";
0097
0098 if (count > 4)
0099 count = 4;
0100
0101 if (copy_from_user(strbuf, buffer, count))
0102 return -EFAULT;
0103 strbuf[count] = '\0';
0104 sscanf(strbuf, "%s", str);
0105
0106 mutex_lock(&acpi_device_lock);
0107 list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
0108 wakeup_list) {
0109 if (!dev->wakeup.flags.valid)
0110 continue;
0111
0112 if (!strncmp(dev->pnp.bus_id, str, 4)) {
0113 if (device_can_wakeup(&dev->dev)) {
0114 bool enable = !device_may_wakeup(&dev->dev);
0115 device_set_wakeup_enable(&dev->dev, enable);
0116 } else {
0117 physical_device_enable_wakeup(dev);
0118 }
0119 break;
0120 }
0121 }
0122 mutex_unlock(&acpi_device_lock);
0123 return count;
0124 }
0125
0126 static int
0127 acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
0128 {
0129 return single_open(file, acpi_system_wakeup_device_seq_show,
0130 pde_data(inode));
0131 }
0132
0133 static const struct proc_ops acpi_system_wakeup_device_proc_ops = {
0134 .proc_open = acpi_system_wakeup_device_open_fs,
0135 .proc_read = seq_read,
0136 .proc_write = acpi_system_write_wakeup_device,
0137 .proc_lseek = seq_lseek,
0138 .proc_release = single_release,
0139 };
0140
0141 void __init acpi_sleep_proc_init(void)
0142 {
0143
0144 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
0145 acpi_root_dir, &acpi_system_wakeup_device_proc_ops);
0146 }