]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/acpi/proc.c
ACPI / EC: Remove unused functions and add prototype declaration in internal.h
[mirror_ubuntu-zesty-kernel.git] / drivers / acpi / proc.c
CommitLineData
1da177e4
LT
1#include <linux/proc_fs.h>
2#include <linux/seq_file.h>
214f2c90 3#include <linux/export.h>
1da177e4
LT
4#include <linux/suspend.h>
5#include <linux/bcd.h>
8b48463f 6#include <linux/acpi.h>
1da177e4
LT
7#include <asm/uaccess.h>
8
1da177e4
LT
9#include "sleep.h"
10
1da177e4 11#define _COMPONENT ACPI_SYSTEM_COMPONENT
43532c8a
LB
12
13/*
14 * this file provides support for:
43532c8a
LB
15 * /proc/acpi/wakeup
16 */
17
4be44fcd 18ACPI_MODULE_NAME("sleep")
1da177e4 19
1da177e4
LT
20static int
21acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
22{
4be44fcd 23 struct list_head *node, *next;
1da177e4 24
8aa55591 25 seq_printf(seq, "Device\tS-state\t Status Sysfs node\n");
1da177e4 26
9090589d 27 mutex_lock(&acpi_device_lock);
1da177e4 28 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
4be44fcd
LB
29 struct acpi_device *dev =
30 container_of(node, struct acpi_device, wakeup_list);
1033f904 31 struct acpi_device_physical_node *entry;
1da177e4
LT
32
33 if (!dev->wakeup.flags.valid)
34 continue;
8aa55591 35
1033f904 36 seq_printf(seq, "%s\t S%d\t",
4be44fcd 37 dev->pnp.bus_id,
1033f904
LT
38 (u32) dev->wakeup.sleep_state);
39
623cf33c
RW
40 mutex_lock(&dev->physical_node_lock);
41
65ab96f6 42 if (!dev->physical_node_count) {
1033f904 43 seq_printf(seq, "%c%-8s\n",
65ab96f6
AF
44 dev->wakeup.flags.run_wake ? '*' : ' ',
45 device_may_wakeup(&dev->dev) ?
46 "enabled" : "disabled");
47 } else {
1033f904
LT
48 struct device *ldev;
49 list_for_each_entry(entry, &dev->physical_node_list,
50 node) {
51 ldev = get_device(entry->dev);
52 if (!ldev)
53 continue;
54
55 if (&entry->node !=
56 dev->physical_node_list.next)
57 seq_printf(seq, "\t\t");
58
59 seq_printf(seq, "%c%-8s %s:%s\n",
60 dev->wakeup.flags.run_wake ? '*' : ' ',
61 (device_may_wakeup(&dev->dev) ||
62 (ldev && device_may_wakeup(ldev))) ?
63 "enabled" : "disabled",
64 ldev->bus ? ldev->bus->name :
65 "no-bus", dev_name(ldev));
66 put_device(ldev);
67 }
68 }
623cf33c
RW
69
70 mutex_unlock(&dev->physical_node_lock);
1da177e4 71 }
9090589d 72 mutex_unlock(&acpi_device_lock);
1da177e4
LT
73 return 0;
74}
75
76acae04
RW
76static void physical_device_enable_wakeup(struct acpi_device *adev)
77{
1033f904 78 struct acpi_device_physical_node *entry;
76acae04 79
623cf33c
RW
80 mutex_lock(&adev->physical_node_lock);
81
1033f904
LT
82 list_for_each_entry(entry,
83 &adev->physical_node_list, node)
84 if (entry->dev && device_can_wakeup(entry->dev)) {
85 bool enable = !device_may_wakeup(entry->dev);
86 device_set_wakeup_enable(entry->dev, enable);
87 }
623cf33c
RW
88
89 mutex_unlock(&adev->physical_node_lock);
76acae04
RW
90}
91
1da177e4 92static ssize_t
4be44fcd
LB
93acpi_system_write_wakeup_device(struct file *file,
94 const char __user * buffer,
95 size_t count, loff_t * ppos)
1da177e4 96{
4be44fcd
LB
97 struct list_head *node, *next;
98 char strbuf[5];
99 char str[5] = "";
1da177e4 100
05bce79e
CR
101 if (count > 4)
102 count = 4;
1da177e4 103
05bce79e 104 if (copy_from_user(strbuf, buffer, count))
1da177e4 105 return -EFAULT;
05bce79e 106 strbuf[count] = '\0';
1da177e4
LT
107 sscanf(strbuf, "%s", str);
108
9090589d 109 mutex_lock(&acpi_device_lock);
1da177e4 110 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
4be44fcd
LB
111 struct acpi_device *dev =
112 container_of(node, struct acpi_device, wakeup_list);
1da177e4
LT
113 if (!dev->wakeup.flags.valid)
114 continue;
115
116 if (!strncmp(dev->pnp.bus_id, str, 4)) {
f2b56bc8
RW
117 if (device_can_wakeup(&dev->dev)) {
118 bool enable = !device_may_wakeup(&dev->dev);
119 device_set_wakeup_enable(&dev->dev, enable);
120 } else {
121 physical_device_enable_wakeup(dev);
122 }
1da177e4
LT
123 break;
124 }
125 }
9090589d 126 mutex_unlock(&acpi_device_lock);
1da177e4
LT
127 return count;
128}
129
130static int
131acpi_system_wakeup_device_open_fs(struct inode *inode, struct file *file)
132{
4be44fcd 133 return single_open(file, acpi_system_wakeup_device_seq_show,
d9dda78b 134 PDE_DATA(inode));
1da177e4
LT
135}
136
d7508032 137static const struct file_operations acpi_system_wakeup_device_fops = {
cf7acfab 138 .owner = THIS_MODULE,
4be44fcd
LB
139 .open = acpi_system_wakeup_device_open_fs,
140 .read = seq_read,
141 .write = acpi_system_write_wakeup_device,
142 .llseek = seq_lseek,
143 .release = single_release,
1da177e4
LT
144};
145
9cee43e0 146int __init acpi_sleep_proc_init(void)
1da177e4 147{
c65ade4d 148 /* 'wakeup device' [R/W] */
cf7acfab
DL
149 proc_create("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
150 acpi_root_dir, &acpi_system_wakeup_device_fops);
1da177e4 151
1da177e4
LT
152 return 0;
153}