Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 1 | /* |
| 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> |
| 23 | #include <acpi/acpi_drivers.h> |
| 24 | |
| 25 | MODULE_LICENSE("GPL"); |
| 26 | |
| 27 | static ssize_t irst_show_wakeup_events(struct device *dev, |
| 28 | struct device_attribute *attr, |
| 29 | char *buf) |
| 30 | { |
| 31 | struct acpi_device *acpi; |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame^] | 32 | unsigned long long value; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 33 | acpi_status status; |
| 34 | |
| 35 | acpi = to_acpi_device(dev); |
| 36 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame^] | 37 | status = acpi_evaluate_integer(acpi->handle, "GFFS", NULL, &value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 38 | if (!ACPI_SUCCESS(status)) |
| 39 | return -EINVAL; |
| 40 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame^] | 41 | return sprintf(buf, "%lld\n", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static 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 Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 49 | 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 Rui | b92f7a9 | 2013-09-03 08:31:53 +0800 | [diff] [blame] | 60 | status = acpi_execute_simple_method(acpi->handle, "SFFS", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 61 | |
| 62 | if (!ACPI_SUCCESS(status)) |
| 63 | return -EINVAL; |
| 64 | |
| 65 | return count; |
| 66 | } |
| 67 | |
| 68 | static 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 | |
| 74 | static ssize_t irst_show_wakeup_time(struct device *dev, |
| 75 | struct device_attribute *attr, char *buf) |
| 76 | { |
| 77 | struct acpi_device *acpi; |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame^] | 78 | unsigned long long value; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 79 | acpi_status status; |
| 80 | |
| 81 | acpi = to_acpi_device(dev); |
| 82 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame^] | 83 | status = acpi_evaluate_integer(acpi->handle, "GFTV", NULL, &value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 84 | if (!ACPI_SUCCESS(status)) |
| 85 | return -EINVAL; |
| 86 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame^] | 87 | return sprintf(buf, "%lld\n", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static 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 Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 95 | 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 Rui | b92f7a9 | 2013-09-03 08:31:53 +0800 | [diff] [blame] | 106 | status = acpi_execute_simple_method(acpi->handle, "SFTV", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 107 | |
| 108 | if (!ACPI_SUCCESS(status)) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | return count; |
| 112 | } |
| 113 | |
| 114 | static 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 | |
| 120 | static int irst_add(struct acpi_device *acpi) |
| 121 | { |
| 122 | int error = 0; |
| 123 | |
| 124 | error = device_create_file(&acpi->dev, &irst_timeout_attr); |
| 125 | if (error) |
| 126 | goto out; |
| 127 | |
| 128 | error = device_create_file(&acpi->dev, &irst_wakeup_attr); |
| 129 | if (error) |
| 130 | goto out_timeout; |
| 131 | |
| 132 | return 0; |
| 133 | |
| 134 | out_timeout: |
| 135 | device_remove_file(&acpi->dev, &irst_timeout_attr); |
| 136 | out: |
| 137 | return error; |
| 138 | } |
| 139 | |
| 140 | static int irst_remove(struct acpi_device *acpi) |
| 141 | { |
| 142 | device_remove_file(&acpi->dev, &irst_wakeup_attr); |
| 143 | device_remove_file(&acpi->dev, &irst_timeout_attr); |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static const struct acpi_device_id irst_ids[] = { |
| 149 | {"INT3392", 0}, |
| 150 | {"", 0} |
| 151 | }; |
| 152 | |
| 153 | static struct acpi_driver irst_driver = { |
| 154 | .owner = THIS_MODULE, |
| 155 | .name = "intel_rapid_start", |
| 156 | .class = "intel_rapid_start", |
| 157 | .ids = irst_ids, |
| 158 | .ops = { |
| 159 | .add = irst_add, |
| 160 | .remove = irst_remove, |
| 161 | }, |
| 162 | }; |
| 163 | |
Wei Yongjun | 2ff1af7 | 2013-07-17 09:55:25 +0800 | [diff] [blame] | 164 | module_acpi_driver(irst_driver); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 165 | |
| 166 | MODULE_DEVICE_TABLE(acpi, irst_ids); |