]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | #include <linux/proc_fs.h> |
3 | #include <linux/seq_file.h> | |
214f2c90 | 4 | #include <linux/export.h> |
1da177e4 LT |
5 | #include <linux/suspend.h> |
6 | #include <linux/bcd.h> | |
8b48463f | 7 | #include <linux/acpi.h> |
7c0f6ba6 | 8 | #include <linux/uaccess.h> |
1da177e4 | 9 | |
1da177e4 | 10 | #include "sleep.h" |
6a368751 | 11 | #include "internal.h" |
1da177e4 | 12 | |
1da177e4 | 13 | #define _COMPONENT ACPI_SYSTEM_COMPONENT |
43532c8a LB |
14 | |
15 | /* | |
16 | * this file provides support for: | |
43532c8a LB |
17 | * /proc/acpi/wakeup |
18 | */ | |
19 | ||
4be44fcd | 20 | ACPI_MODULE_NAME("sleep") |
1da177e4 | 21 | |
1da177e4 LT |
22 | static int |
23 | acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset) | |
24 | { | |
4be44fcd | 25 | struct list_head *node, *next; |
1da177e4 | 26 | |
8aa55591 | 27 | seq_printf(seq, "Device\tS-state\t Status Sysfs node\n"); |
1da177e4 | 28 | |
9090589d | 29 | mutex_lock(&acpi_device_lock); |
1da177e4 | 30 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
4be44fcd LB |
31 | struct acpi_device *dev = |
32 | container_of(node, struct acpi_device, wakeup_list); | |
1033f904 | 33 | struct acpi_device_physical_node *entry; |
1da177e4 LT |
34 | |
35 | if (!dev->wakeup.flags.valid) | |
36 | continue; | |
8aa55591 | 37 | |
1033f904 | 38 | seq_printf(seq, "%s\t S%d\t", |
4be44fcd | 39 | dev->pnp.bus_id, |
1033f904 LT |
40 | (u32) dev->wakeup.sleep_state); |
41 | ||
623cf33c RW |
42 | mutex_lock(&dev->physical_node_lock); |
43 | ||
65ab96f6 | 44 | if (!dev->physical_node_count) { |
1033f904 | 45 | seq_printf(seq, "%c%-8s\n", |
a1a66393 | 46 | dev->wakeup.flags.valid ? '*' : ' ', |
65ab96f6 AF |
47 | device_may_wakeup(&dev->dev) ? |
48 | "enabled" : "disabled"); | |
49 | } else { | |
1033f904 LT |
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", | |
a1a66393 | 62 | dev->wakeup.flags.valid ? '*' : ' ', |
1033f904 | 63 | (device_may_wakeup(&dev->dev) || |
085ca117 | 64 | device_may_wakeup(ldev)) ? |
1033f904 LT |
65 | "enabled" : "disabled", |
66 | ldev->bus ? ldev->bus->name : | |
67 | "no-bus", dev_name(ldev)); | |
68 | put_device(ldev); | |
69 | } | |
70 | } | |
623cf33c RW |
71 | |
72 | mutex_unlock(&dev->physical_node_lock); | |
1da177e4 | 73 | } |
9090589d | 74 | mutex_unlock(&acpi_device_lock); |
1da177e4 LT |
75 | return 0; |
76 | } | |
77 | ||
76acae04 RW |
78 | static void physical_device_enable_wakeup(struct acpi_device *adev) |
79 | { | |
1033f904 | 80 | struct acpi_device_physical_node *entry; |
76acae04 | 81 | |
623cf33c RW |
82 | mutex_lock(&adev->physical_node_lock); |
83 | ||
1033f904 LT |
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 | } | |
623cf33c RW |
90 | |
91 | mutex_unlock(&adev->physical_node_lock); | |
76acae04 RW |
92 | } |
93 | ||
1da177e4 | 94 | static ssize_t |
4be44fcd LB |
95 | acpi_system_write_wakeup_device(struct file *file, |
96 | const char __user * buffer, | |
97 | size_t count, loff_t * ppos) | |
1da177e4 | 98 | { |
4be44fcd LB |
99 | struct list_head *node, *next; |
100 | char strbuf[5]; | |
101 | char str[5] = ""; | |
1da177e4 | 102 | |
05bce79e CR |
103 | if (count > 4) |
104 | count = 4; | |
1da177e4 | 105 | |
05bce79e | 106 | if (copy_from_user(strbuf, buffer, count)) |
1da177e4 | 107 | return -EFAULT; |
05bce79e | 108 | strbuf[count] = '\0'; |
1da177e4 LT |
109 | sscanf(strbuf, "%s", str); |
110 | ||
9090589d | 111 | mutex_lock(&acpi_device_lock); |
1da177e4 | 112 | list_for_each_safe(node, next, &acpi_wakeup_device_list) { |
4be44fcd LB |
113 | struct acpi_device *dev = |
114 | container_of(node, struct acpi_device, wakeup_list); | |
1da177e4 LT |
115 | if (!dev->wakeup.flags.valid) |
116 | continue; | |
117 | ||
118 | if (!strncmp(dev->pnp.bus_id, str, 4)) { | |
f2b56bc8 RW |
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 | } | |
1da177e4 LT |
125 | break; |
126 | } | |
127 | } | |
9090589d | 128 | mutex_unlock(&acpi_device_lock); |
1da177e4 LT |
129 | return count; |
130 | } | |
131 | ||
132 | static int | |
133 | acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file) | |
134 | { | |
4be44fcd | 135 | return single_open(file, acpi_system_wakeup_device_seq_show, |
d9dda78b | 136 | PDE_DATA(inode)); |
1da177e4 LT |
137 | } |
138 | ||
d7508032 | 139 | static const struct file_operations acpi_system_wakeup_device_fops = { |
cf7acfab | 140 | .owner = THIS_MODULE, |
4be44fcd LB |
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, | |
1da177e4 LT |
146 | }; |
147 | ||
f934c745 | 148 | void __init acpi_sleep_proc_init(void) |
1da177e4 | 149 | { |
c65ade4d | 150 | /* 'wakeup device' [R/W] */ |
cf7acfab DL |
151 | proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR, |
152 | acpi_root_dir, &acpi_system_wakeup_device_fops); | |
1da177e4 | 153 | } |