Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/proc_fs.h> |
| 2 | #include <linux/seq_file.h> |
Paul Gortmaker | 214f2c9 | 2011-10-26 16:22:14 -0400 | [diff] [blame] | 3 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/suspend.h> |
| 5 | #include <linux/bcd.h> |
| 6 | #include <asm/uaccess.h> |
| 7 | |
| 8 | #include <acpi/acpi_bus.h> |
| 9 | #include <acpi/acpi_drivers.h> |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "sleep.h" |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
Len Brown | 43532c8 | 2007-07-24 02:16:50 -0400 | [diff] [blame] | 14 | |
| 15 | /* |
| 16 | * this file provides support for: |
Len Brown | 43532c8 | 2007-07-24 02:16:50 -0400 | [diff] [blame] | 17 | * /proc/acpi/wakeup |
| 18 | */ |
| 19 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 20 | ACPI_MODULE_NAME("sleep") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static int |
| 23 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) |
| 24 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 25 | struct list_head *node, *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 27 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 29 | mutex_lock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 31 | struct acpi_device *dev = |
| 32 | container_of(node, struct acpi_device, wakeup_list); |
Lan Tianyu | 1033f90 | 2012-08-17 14:44:09 +0800 | [diff] [blame] | 33 | struct acpi_device_physical_node *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | if (!dev->wakeup.flags.valid) |
| 36 | continue; |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 37 | |
Lan Tianyu | 1033f90 | 2012-08-17 14:44:09 +0800 | [diff] [blame] | 38 | seq_printf(seq, "%s\t S%d\t", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 39 | dev->pnp.bus_id, |
Lan Tianyu | 1033f90 | 2012-08-17 14:44:09 +0800 | [diff] [blame] | 40 | (u32) dev->wakeup.sleep_state); |
David Brownell | 8aa5559 | 2007-04-25 15:20:10 -0400 | [diff] [blame] | 41 | |
Rafael J. Wysocki | 623cf33 | 2013-08-06 02:26:22 +0200 | [diff] [blame] | 42 | mutex_lock(&dev->physical_node_lock); |
| 43 | |
Andreas Fleig | 65ab96f | 2013-01-27 14:17:55 +0000 | [diff] [blame] | 44 | if (!dev->physical_node_count) { |
Lan Tianyu | 1033f90 | 2012-08-17 14:44:09 +0800 | [diff] [blame] | 45 | seq_printf(seq, "%c%-8s\n", |
Andreas Fleig | 65ab96f | 2013-01-27 14:17:55 +0000 | [diff] [blame] | 46 | dev->wakeup.flags.run_wake ? '*' : ' ', |
| 47 | device_may_wakeup(&dev->dev) ? |
| 48 | "enabled" : "disabled"); |
| 49 | } else { |
Lan Tianyu | 1033f90 | 2012-08-17 14:44:09 +0800 | [diff] [blame] | 50 | struct device *ldev; |
| 51 | list_for_each_entry(entry, &dev->physical_node_list, |
| 52 | node) { |
| 53 | ldev = get_device(entry->dev); |
| 54 | if (!ldev) |
| 55 | continue; |
| 56 | |
| 57 | if (&entry->node != |
| 58 | dev->physical_node_list.next) |
| 59 | seq_printf(seq, "\t\t"); |
| 60 | |
| 61 | seq_printf(seq, "%c%-8s %s:%s\n", |
| 62 | dev->wakeup.flags.run_wake ? '*' : ' ', |
| 63 | (device_may_wakeup(&dev->dev) || |
| 64 | (ldev && device_may_wakeup(ldev))) ? |
| 65 | "enabled" : "disabled", |
| 66 | ldev->bus ? ldev->bus->name : |
| 67 | "no-bus", dev_name(ldev)); |
| 68 | put_device(ldev); |
| 69 | } |
| 70 | } |
Rafael J. Wysocki | 623cf33 | 2013-08-06 02:26:22 +0200 | [diff] [blame] | 71 | |
| 72 | mutex_unlock(&dev->physical_node_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 74 | mutex_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
Rafael J. Wysocki | 76acae0 | 2008-10-03 15:23:49 -0700 | [diff] [blame] | 78 | static void physical_device_enable_wakeup(struct acpi_device *adev) |
| 79 | { |
Lan Tianyu | 1033f90 | 2012-08-17 14:44:09 +0800 | [diff] [blame] | 80 | struct acpi_device_physical_node *entry; |
Rafael J. Wysocki | 76acae0 | 2008-10-03 15:23:49 -0700 | [diff] [blame] | 81 | |
Rafael J. Wysocki | 623cf33 | 2013-08-06 02:26:22 +0200 | [diff] [blame] | 82 | mutex_lock(&adev->physical_node_lock); |
| 83 | |
Lan Tianyu | 1033f90 | 2012-08-17 14:44:09 +0800 | [diff] [blame] | 84 | list_for_each_entry(entry, |
| 85 | &adev->physical_node_list, node) |
| 86 | if (entry->dev && device_can_wakeup(entry->dev)) { |
| 87 | bool enable = !device_may_wakeup(entry->dev); |
| 88 | device_set_wakeup_enable(entry->dev, enable); |
| 89 | } |
Rafael J. Wysocki | 623cf33 | 2013-08-06 02:26:22 +0200 | [diff] [blame] | 90 | |
| 91 | mutex_unlock(&adev->physical_node_lock); |
Rafael J. Wysocki | 76acae0 | 2008-10-03 15:23:49 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | static ssize_t |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 95 | acpi_system_write_wakeup_device(struct file *file, |
| 96 | const char __user * buffer, |
| 97 | size_t count, loff_t * ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | struct list_head *node, *next; |
| 100 | char strbuf[5]; |
| 101 | char str[5] = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Cyril Roelandt | 05bce79 | 2012-11-22 23:20:31 +0100 | [diff] [blame] | 103 | if (count > 4) |
| 104 | count = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Cyril Roelandt | 05bce79 | 2012-11-22 23:20:31 +0100 | [diff] [blame] | 106 | if (copy_from_user(strbuf, buffer, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return -EFAULT; |
Cyril Roelandt | 05bce79 | 2012-11-22 23:20:31 +0100 | [diff] [blame] | 108 | strbuf[count] = '\0'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | sscanf(strbuf, "%s", str); |
| 110 | |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 111 | mutex_lock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 113 | struct acpi_device *dev = |
| 114 | container_of(node, struct acpi_device, wakeup_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | if (!dev->wakeup.flags.valid) |
| 116 | continue; |
| 117 | |
| 118 | if (!strncmp(dev->pnp.bus_id, str, 4)) { |
Rafael J. Wysocki | f2b56bc | 2011-01-06 23:34:22 +0100 | [diff] [blame] | 119 | if (device_can_wakeup(&dev->dev)) { |
| 120 | bool enable = !device_may_wakeup(&dev->dev); |
| 121 | device_set_wakeup_enable(&dev->dev, enable); |
| 122 | } else { |
| 123 | physical_device_enable_wakeup(dev); |
| 124 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | break; |
| 126 | } |
| 127 | } |
Shaohua Li | 9090589 | 2009-04-07 10:24:29 +0800 | [diff] [blame] | 128 | mutex_unlock(&acpi_device_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | return count; |
| 130 | } |
| 131 | |
| 132 | static int |
| 133 | acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file) |
| 134 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | return single_open(file, acpi_system_wakeup_device_seq_show, |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 136 | PDE_DATA(inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Arjan van de Ven | d750803 | 2006-07-04 13:06:00 -0400 | [diff] [blame] | 139 | static const struct file_operations acpi_system_wakeup_device_fops = { |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 140 | .owner = THIS_MODULE, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | .open = acpi_system_wakeup_device_open_fs, |
| 142 | .read = seq_read, |
| 143 | .write = acpi_system_write_wakeup_device, |
| 144 | .llseek = seq_lseek, |
| 145 | .release = single_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Bjorn Helgaas | 9cee43e | 2009-03-24 16:50:14 -0600 | [diff] [blame] | 148 | int __init acpi_sleep_proc_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
Pavel Machek | c65ade4 | 2005-08-05 00:37:45 -0400 | [diff] [blame] | 150 | /* 'wakeup device' [R/W] */ |
Denis V. Lunev | cf7acfa | 2008-04-29 01:02:27 -0700 | [diff] [blame] | 151 | proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR, |
| 152 | acpi_root_dir, &acpi_system_wakeup_device_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | return 0; |
| 155 | } |