blob: 7344d841f4d98d17810b5f6bdbee8965415af6e5 [file] [log] [blame]
Matthew Garrett34a956d2013-07-02 18:41:03 -04001/*
2 * Copyright 2013 Matthew Garrett <mjg59@srcf.ucam.org>
3 *
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.
8 *
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.
13 *
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.
17 */
18
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/slab.h>
Lv Zheng8b484632013-12-03 08:49:16 +080023#include <linux/acpi.h>
Matthew Garrett34a956d2013-07-02 18:41:03 -040024
25MODULE_LICENSE("GPL");
26
27static ssize_t irst_show_wakeup_events(struct device *dev,
28 struct device_attribute *attr,
29 char *buf)
30{
31 struct acpi_device *acpi;
Zhang Ruic7c878a2013-09-03 08:32:13 +080032 unsigned long long value;
Matthew Garrett34a956d2013-07-02 18:41:03 -040033 acpi_status status;
34
35 acpi = to_acpi_device(dev);
36
Zhang Ruic7c878a2013-09-03 08:32:13 +080037 status = acpi_evaluate_integer(acpi->handle, "GFFS", NULL, &value);
Peter Ujfalusid46a7642014-09-17 00:13:55 +030038 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -040039 return -EINVAL;
40
Zhang Ruic7c878a2013-09-03 08:32:13 +080041 return sprintf(buf, "%lld\n", value);
Matthew Garrett34a956d2013-07-02 18:41:03 -040042}
43
44static ssize_t irst_store_wakeup_events(struct device *dev,
45 struct device_attribute *attr,
46 const char *buf, size_t count)
47{
48 struct acpi_device *acpi;
Matthew Garrett34a956d2013-07-02 18:41:03 -040049 acpi_status status;
50 unsigned long value;
51 int error;
52
53 acpi = to_acpi_device(dev);
54
55 error = kstrtoul(buf, 0, &value);
56
57 if (error)
58 return error;
59
Zhang Ruib92f7a92013-09-03 08:31:53 +080060 status = acpi_execute_simple_method(acpi->handle, "SFFS", value);
Matthew Garrett34a956d2013-07-02 18:41:03 -040061
Peter Ujfalusid46a7642014-09-17 00:13:55 +030062 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -040063 return -EINVAL;
64
65 return count;
66}
67
68static struct device_attribute irst_wakeup_attr = {
69 .attr = { .name = "wakeup_events", .mode = 0600 },
70 .show = irst_show_wakeup_events,
71 .store = irst_store_wakeup_events
72};
73
74static ssize_t irst_show_wakeup_time(struct device *dev,
75 struct device_attribute *attr, char *buf)
76{
77 struct acpi_device *acpi;
Zhang Ruic7c878a2013-09-03 08:32:13 +080078 unsigned long long value;
Matthew Garrett34a956d2013-07-02 18:41:03 -040079 acpi_status status;
80
81 acpi = to_acpi_device(dev);
82
Zhang Ruic7c878a2013-09-03 08:32:13 +080083 status = acpi_evaluate_integer(acpi->handle, "GFTV", NULL, &value);
Peter Ujfalusid46a7642014-09-17 00:13:55 +030084 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -040085 return -EINVAL;
86
Zhang Ruic7c878a2013-09-03 08:32:13 +080087 return sprintf(buf, "%lld\n", value);
Matthew Garrett34a956d2013-07-02 18:41:03 -040088}
89
90static ssize_t irst_store_wakeup_time(struct device *dev,
91 struct device_attribute *attr,
92 const char *buf, size_t count)
93{
94 struct acpi_device *acpi;
Matthew Garrett34a956d2013-07-02 18:41:03 -040095 acpi_status status;
96 unsigned long value;
97 int error;
98
99 acpi = to_acpi_device(dev);
100
101 error = kstrtoul(buf, 0, &value);
102
103 if (error)
104 return error;
105
Zhang Ruib92f7a92013-09-03 08:31:53 +0800106 status = acpi_execute_simple_method(acpi->handle, "SFTV", value);
Matthew Garrett34a956d2013-07-02 18:41:03 -0400107
Peter Ujfalusid46a7642014-09-17 00:13:55 +0300108 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -0400109 return -EINVAL;
110
111 return count;
112}
113
114static struct device_attribute irst_timeout_attr = {
115 .attr = { .name = "wakeup_time", .mode = 0600 },
116 .show = irst_show_wakeup_time,
117 .store = irst_store_wakeup_time
118};
119
120static int irst_add(struct acpi_device *acpi)
121{
Peter Ujfalusia3d3c532014-09-17 00:13:56 +0300122 int error;
Matthew Garrett34a956d2013-07-02 18:41:03 -0400123
124 error = device_create_file(&acpi->dev, &irst_timeout_attr);
Peter Ujfalusia3d3c532014-09-17 00:13:56 +0300125 if (unlikely(error))
126 return error;
Matthew Garrett34a956d2013-07-02 18:41:03 -0400127
128 error = device_create_file(&acpi->dev, &irst_wakeup_attr);
Peter Ujfalusia3d3c532014-09-17 00:13:56 +0300129 if (unlikely(error))
130 device_remove_file(&acpi->dev, &irst_timeout_attr);
Matthew Garrett34a956d2013-07-02 18:41:03 -0400131
Matthew Garrett34a956d2013-07-02 18:41:03 -0400132 return error;
133}
134
135static int irst_remove(struct acpi_device *acpi)
136{
137 device_remove_file(&acpi->dev, &irst_wakeup_attr);
138 device_remove_file(&acpi->dev, &irst_timeout_attr);
139
140 return 0;
141}
142
143static const struct acpi_device_id irst_ids[] = {
144 {"INT3392", 0},
145 {"", 0}
146};
147
148static struct acpi_driver irst_driver = {
149 .owner = THIS_MODULE,
150 .name = "intel_rapid_start",
151 .class = "intel_rapid_start",
152 .ids = irst_ids,
153 .ops = {
154 .add = irst_add,
155 .remove = irst_remove,
156 },
157};
158
Wei Yongjun2ff1af72013-07-17 09:55:25 +0800159module_acpi_driver(irst_driver);
Matthew Garrett34a956d2013-07-02 18:41:03 -0400160
161MODULE_DEVICE_TABLE(acpi, irst_ids);