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