blob: 3b81cb896fedff37c231ed62de5c9d859a2df3ac [file] [log] [blame]
Andy Shevchenkobd7c5862018-09-26 18:27:40 +03001// SPDX-License-Identifier: GPL-2.0+
Matthew Garrett34a956d2013-07-02 18:41:03 -04002/*
3 * Copyright 2013 Matthew Garrett <mjg59@srcf.ucam.org>
Matthew Garrett34a956d2013-07-02 18:41:03 -04004 */
5
Andy Shevchenko5f4ad6a2018-09-26 18:27:14 +03006#include <linux/acpi.h>
Matthew Garrett34a956d2013-07-02 18:41:03 -04007#include <linux/module.h>
8#include <linux/slab.h>
Matthew Garrett34a956d2013-07-02 18:41:03 -04009
10MODULE_LICENSE("GPL");
11
12static ssize_t irst_show_wakeup_events(struct device *dev,
13 struct device_attribute *attr,
14 char *buf)
15{
16 struct acpi_device *acpi;
Zhang Ruic7c878a2013-09-03 08:32:13 +080017 unsigned long long value;
Matthew Garrett34a956d2013-07-02 18:41:03 -040018 acpi_status status;
19
20 acpi = to_acpi_device(dev);
21
Zhang Ruic7c878a2013-09-03 08:32:13 +080022 status = acpi_evaluate_integer(acpi->handle, "GFFS", NULL, &value);
Peter Ujfalusid46a7642014-09-17 00:13:55 +030023 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -040024 return -EINVAL;
25
Zhang Ruic7c878a2013-09-03 08:32:13 +080026 return sprintf(buf, "%lld\n", value);
Matthew Garrett34a956d2013-07-02 18:41:03 -040027}
28
29static ssize_t irst_store_wakeup_events(struct device *dev,
30 struct device_attribute *attr,
31 const char *buf, size_t count)
32{
33 struct acpi_device *acpi;
Matthew Garrett34a956d2013-07-02 18:41:03 -040034 acpi_status status;
35 unsigned long value;
36 int error;
37
38 acpi = to_acpi_device(dev);
39
40 error = kstrtoul(buf, 0, &value);
Matthew Garrett34a956d2013-07-02 18:41:03 -040041 if (error)
42 return error;
43
Zhang Ruib92f7a92013-09-03 08:31:53 +080044 status = acpi_execute_simple_method(acpi->handle, "SFFS", value);
Peter Ujfalusid46a7642014-09-17 00:13:55 +030045 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -040046 return -EINVAL;
47
48 return count;
49}
50
51static struct device_attribute irst_wakeup_attr = {
52 .attr = { .name = "wakeup_events", .mode = 0600 },
53 .show = irst_show_wakeup_events,
54 .store = irst_store_wakeup_events
55};
56
57static ssize_t irst_show_wakeup_time(struct device *dev,
58 struct device_attribute *attr, char *buf)
59{
60 struct acpi_device *acpi;
Zhang Ruic7c878a2013-09-03 08:32:13 +080061 unsigned long long value;
Matthew Garrett34a956d2013-07-02 18:41:03 -040062 acpi_status status;
63
64 acpi = to_acpi_device(dev);
65
Zhang Ruic7c878a2013-09-03 08:32:13 +080066 status = acpi_evaluate_integer(acpi->handle, "GFTV", NULL, &value);
Peter Ujfalusid46a7642014-09-17 00:13:55 +030067 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -040068 return -EINVAL;
69
Zhang Ruic7c878a2013-09-03 08:32:13 +080070 return sprintf(buf, "%lld\n", value);
Matthew Garrett34a956d2013-07-02 18:41:03 -040071}
72
73static ssize_t irst_store_wakeup_time(struct device *dev,
74 struct device_attribute *attr,
75 const char *buf, size_t count)
76{
77 struct acpi_device *acpi;
Matthew Garrett34a956d2013-07-02 18:41:03 -040078 acpi_status status;
79 unsigned long value;
80 int error;
81
82 acpi = to_acpi_device(dev);
83
84 error = kstrtoul(buf, 0, &value);
Matthew Garrett34a956d2013-07-02 18:41:03 -040085 if (error)
86 return error;
87
Zhang Ruib92f7a92013-09-03 08:31:53 +080088 status = acpi_execute_simple_method(acpi->handle, "SFTV", value);
Peter Ujfalusid46a7642014-09-17 00:13:55 +030089 if (ACPI_FAILURE(status))
Matthew Garrett34a956d2013-07-02 18:41:03 -040090 return -EINVAL;
91
92 return count;
93}
94
95static struct device_attribute irst_timeout_attr = {
96 .attr = { .name = "wakeup_time", .mode = 0600 },
97 .show = irst_show_wakeup_time,
98 .store = irst_store_wakeup_time
99};
100
101static int irst_add(struct acpi_device *acpi)
102{
Peter Ujfalusia3d3c532014-09-17 00:13:56 +0300103 int error;
Matthew Garrett34a956d2013-07-02 18:41:03 -0400104
105 error = device_create_file(&acpi->dev, &irst_timeout_attr);
Peter Ujfalusia3d3c532014-09-17 00:13:56 +0300106 if (unlikely(error))
107 return error;
Matthew Garrett34a956d2013-07-02 18:41:03 -0400108
109 error = device_create_file(&acpi->dev, &irst_wakeup_attr);
Peter Ujfalusia3d3c532014-09-17 00:13:56 +0300110 if (unlikely(error))
111 device_remove_file(&acpi->dev, &irst_timeout_attr);
Matthew Garrett34a956d2013-07-02 18:41:03 -0400112
Matthew Garrett34a956d2013-07-02 18:41:03 -0400113 return error;
114}
115
116static int irst_remove(struct acpi_device *acpi)
117{
118 device_remove_file(&acpi->dev, &irst_wakeup_attr);
119 device_remove_file(&acpi->dev, &irst_timeout_attr);
120
121 return 0;
122}
123
124static const struct acpi_device_id irst_ids[] = {
125 {"INT3392", 0},
126 {"", 0}
127};
128
129static struct acpi_driver irst_driver = {
130 .owner = THIS_MODULE,
131 .name = "intel_rapid_start",
132 .class = "intel_rapid_start",
133 .ids = irst_ids,
134 .ops = {
135 .add = irst_add,
136 .remove = irst_remove,
137 },
138};
139
Wei Yongjun2ff1af72013-07-17 09:55:25 +0800140module_acpi_driver(irst_driver);
Matthew Garrett34a956d2013-07-02 18:41:03 -0400141
142MODULE_DEVICE_TABLE(acpi, irst_ids);