Linux 3.12.39
[linux/fpc-iii.git] / drivers / platform / x86 / intel-rst.c
blob41b740cb28bca8743ea282bbf2fb5639a2f4266c
1 /*
2 * Copyright 2013 Matthew Garrett <mjg59@srcf.ucam.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <acpi/acpi_drivers.h>
25 MODULE_LICENSE("GPL");
27 static ssize_t irst_show_wakeup_events(struct device *dev,
28 struct device_attribute *attr,
29 char *buf)
31 struct acpi_device *acpi;
32 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
33 union acpi_object *result;
34 acpi_status status;
36 acpi = to_acpi_device(dev);
38 status = acpi_evaluate_object(acpi->handle, "GFFS", NULL, &output);
39 if (!ACPI_SUCCESS(status))
40 return -EINVAL;
42 result = output.pointer;
44 if (result->type != ACPI_TYPE_INTEGER) {
45 kfree(result);
46 return -EINVAL;
49 return sprintf(buf, "%lld\n", result->integer.value);
52 static ssize_t irst_store_wakeup_events(struct device *dev,
53 struct device_attribute *attr,
54 const char *buf, size_t count)
56 struct acpi_device *acpi;
57 struct acpi_object_list input;
58 union acpi_object param;
59 acpi_status status;
60 unsigned long value;
61 int error;
63 acpi = to_acpi_device(dev);
65 error = kstrtoul(buf, 0, &value);
67 if (error)
68 return error;
70 param.type = ACPI_TYPE_INTEGER;
71 param.integer.value = value;
73 input.count = 1;
74 input.pointer = &param;
76 status = acpi_evaluate_object(acpi->handle, "SFFS", &input, NULL);
78 if (!ACPI_SUCCESS(status))
79 return -EINVAL;
81 return count;
84 static struct device_attribute irst_wakeup_attr = {
85 .attr = { .name = "wakeup_events", .mode = 0600 },
86 .show = irst_show_wakeup_events,
87 .store = irst_store_wakeup_events
90 static ssize_t irst_show_wakeup_time(struct device *dev,
91 struct device_attribute *attr, char *buf)
93 struct acpi_device *acpi;
94 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
95 union acpi_object *result;
96 acpi_status status;
98 acpi = to_acpi_device(dev);
100 status = acpi_evaluate_object(acpi->handle, "GFTV", NULL, &output);
101 if (!ACPI_SUCCESS(status))
102 return -EINVAL;
104 result = output.pointer;
106 if (result->type != ACPI_TYPE_INTEGER) {
107 kfree(result);
108 return -EINVAL;
111 return sprintf(buf, "%lld\n", result->integer.value);
114 static ssize_t irst_store_wakeup_time(struct device *dev,
115 struct device_attribute *attr,
116 const char *buf, size_t count)
118 struct acpi_device *acpi;
119 struct acpi_object_list input;
120 union acpi_object param;
121 acpi_status status;
122 unsigned long value;
123 int error;
125 acpi = to_acpi_device(dev);
127 error = kstrtoul(buf, 0, &value);
129 if (error)
130 return error;
132 param.type = ACPI_TYPE_INTEGER;
133 param.integer.value = value;
135 input.count = 1;
136 input.pointer = &param;
138 status = acpi_evaluate_object(acpi->handle, "SFTV", &input, NULL);
140 if (!ACPI_SUCCESS(status))
141 return -EINVAL;
143 return count;
146 static struct device_attribute irst_timeout_attr = {
147 .attr = { .name = "wakeup_time", .mode = 0600 },
148 .show = irst_show_wakeup_time,
149 .store = irst_store_wakeup_time
152 static int irst_add(struct acpi_device *acpi)
154 int error = 0;
156 error = device_create_file(&acpi->dev, &irst_timeout_attr);
157 if (error)
158 goto out;
160 error = device_create_file(&acpi->dev, &irst_wakeup_attr);
161 if (error)
162 goto out_timeout;
164 return 0;
166 out_timeout:
167 device_remove_file(&acpi->dev, &irst_timeout_attr);
168 out:
169 return error;
172 static int irst_remove(struct acpi_device *acpi)
174 device_remove_file(&acpi->dev, &irst_wakeup_attr);
175 device_remove_file(&acpi->dev, &irst_timeout_attr);
177 return 0;
180 static const struct acpi_device_id irst_ids[] = {
181 {"INT3392", 0},
182 {"", 0}
185 static struct acpi_driver irst_driver = {
186 .owner = THIS_MODULE,
187 .name = "intel_rapid_start",
188 .class = "intel_rapid_start",
189 .ids = irst_ids,
190 .ops = {
191 .add = irst_add,
192 .remove = irst_remove,
196 module_acpi_driver(irst_driver);
198 MODULE_DEVICE_TABLE(acpi, irst_ids);