| 1 | |
| 2 | #include <linux/proc_fs.h>
|
| 3 | #include <linux/seq_file.h>
|
| 4 | #include <linux/string_choices.h>
|
| 5 | #include <linux/suspend.h>
|
| 6 | #include <linux/bcd.h>
|
| 7 | #include <linux/acpi.h>
|
| 8 | #include <linux/uaccess.h>
|
| 9 |
|
| 10 | #include "sleep.h"
|
| 11 | #include "internal.h"
|
| 12 |
|
| 13 | |
| 14 | * this file provides support for:
|
| 15 | * /proc/acpi/wakeup
|
| 16 |
|
| 17 |
|
| 18 | static int
|
| 19 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
|
| 20 | {
|
| 21 | struct acpi_device *dev, *tmp;
|
| 22 |
|
| 23 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
|
| 24 |
|
| 25 | mutex_lock(&acpi_device_lock);
|
| 26 | list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
|
| 27 | wakeup_list) {
|
| 28 | struct acpi_device_physical_node *entry;
|
| 29 |
|
| 30 | if (!dev->wakeup.flags.valid)
|
| 31 | continue;
|
| 32 |
|
| 33 | seq_printf(seq, "%s\t S%llu\t",
|
| 34 | dev->pnp.bus_id,
|
| 35 | dev->wakeup.sleep_state);
|
| 36 |
|
| 37 | mutex_lock(&dev->physical_node_lock);
|
| 38 |
|
| 39 | if (!dev->physical_node_count) {
|
| 40 | seq_printf(seq, "%c%-8s\n",
|
| 41 | dev->wakeup.flags.valid ? '*' : ' ',
|
| 42 | str_enabled_disabled(device_may_wakeup(&dev->dev)));
|
| 43 | } else {
|
| 44 | struct device *ldev;
|
| 45 | list_for_each_entry(entry, &dev->physical_node_list,
|
| 46 | node) {
|
| 47 | ldev = get_device(entry->dev);
|
| 48 | if (!ldev)
|
| 49 | continue;
|
| 50 |
|
| 51 | if (&entry->node !=
|
| 52 | dev->physical_node_list.next)
|
| 53 | seq_printf(seq, "\t\t");
|
| 54 |
|
| 55 | seq_printf(seq, "%c%-8s %s:%s\n",
|
| 56 | dev->wakeup.flags.valid ? '*' : ' ',
|
| 57 | str_enabled_disabled(device_may_wakeup(ldev) ||
|
| 58 | device_may_wakeup(&dev->dev)),
|
| 59 | ldev->bus ? ldev->bus->name :
|
| 60 | "no-bus", dev_name(ldev));
|
| 61 | put_device(ldev);
|
| 62 | }
|
| 63 | }
|
| 64 |
|
| 65 | mutex_unlock(&dev->physical_node_lock);
|
| 66 | }
|
| 67 | mutex_unlock(&acpi_device_lock);
|
| 68 | return 0;
|
| 69 | }
|
| 70 |
|
| 71 | static void physical_device_enable_wakeup(struct acpi_device *adev)
|
| 72 | {
|
| 73 | struct acpi_device_physical_node *entry;
|
| 74 |
|
| 75 | mutex_lock(&adev->physical_node_lock);
|
| 76 |
|
| 77 | list_for_each_entry(entry,
|
| 78 | &adev->physical_node_list, node)
|
| 79 | if (entry->dev && device_can_wakeup(entry->dev)) {
|
| 80 | bool enable = !device_may_wakeup(entry->dev);
|
| 81 | device_set_wakeup_enable(entry->dev, enable);
|
| 82 | }
|
| 83 |
|
| 84 | mutex_unlock(&adev->physical_node_lock);
|
| 85 | }
|
| 86 |
|
| 87 | static ssize_t
|
| 88 | acpi_system_write_wakeup_device(struct file *file,
|
| 89 | const char __user * buffer,
|
| 90 | size_t count, loff_t * ppos)
|
| 91 | {
|
| 92 | struct acpi_device *dev, *tmp;
|
| 93 | char strbuf[5];
|
| 94 | char str[5] = "";
|
| 95 |
|
| 96 | if (count > 4)
|
| 97 | count = 4;
|
| 98 |
|
| 99 | if (copy_from_user(strbuf, buffer, count))
|
| 100 | return -EFAULT;
|
| 101 | strbuf[count] = '\0';
|
| 102 | sscanf(strbuf, "%s", str);
|
| 103 |
|
| 104 | mutex_lock(&acpi_device_lock);
|
| 105 | list_for_each_entry_safe(dev, tmp, &acpi_wakeup_device_list,
|
| 106 | wakeup_list) {
|
| 107 | if (!dev->wakeup.flags.valid)
|
| 108 | continue;
|
| 109 |
|
| 110 | if (!strncmp(dev->pnp.bus_id, str, 4)) {
|
| 111 | if (device_can_wakeup(&dev->dev)) {
|
| 112 | bool enable = !device_may_wakeup(&dev->dev);
|
| 113 | device_set_wakeup_enable(&dev->dev, enable);
|
| 114 | } else {
|
| 115 | physical_device_enable_wakeup(dev);
|
| 116 | }
|
| 117 | break;
|
| 118 | }
|
| 119 | }
|
| 120 | mutex_unlock(&acpi_device_lock);
|
| 121 | return count;
|
| 122 | }
|
| 123 |
|
| 124 | static int
|
| 125 | acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
|
| 126 | {
|
| 127 | return single_open(file, acpi_system_wakeup_device_seq_show,
|
| 128 | pde_data(inode));
|
| 129 | }
|
| 130 |
|
| 131 | static const struct proc_ops acpi_system_wakeup_device_proc_ops = {
|
| 132 | .proc_open = acpi_system_wakeup_device_open_fs,
|
| 133 | .proc_read = seq_read,
|
| 134 | .proc_write = acpi_system_write_wakeup_device,
|
| 135 | .proc_lseek = seq_lseek,
|
| 136 | .proc_release = single_release,
|
| 137 | };
|
| 138 |
|
| 139 | void __init acpi_sleep_proc_init(void)
|
| 140 | {
|
| 141 |
|
| 142 | proc_create("wakeup", 0644, acpi_root_dir, &acpi_system_wakeup_device_proc_ops);
|
| 143 | }
|