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; |
| 32 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 33 | union acpi_object *result; |
| 34 | acpi_status status; |
| 35 | |
| 36 | acpi = to_acpi_device(dev); |
| 37 | |
| 38 | status = acpi_evaluate_object(acpi->handle, "GFFS", NULL, &output); |
| 39 | if (!ACPI_SUCCESS(status)) |
| 40 | return -EINVAL; |
| 41 | |
| 42 | result = output.pointer; |
| 43 | |
| 44 | if (result->type != ACPI_TYPE_INTEGER) { |
| 45 | kfree(result); |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | |
| 49 | return sprintf(buf, "%lld\n", result->integer.value); |
| 50 | } |
| 51 | |
| 52 | static ssize_t irst_store_wakeup_events(struct device *dev, |
| 53 | struct device_attribute *attr, |
| 54 | const char *buf, size_t count) |
| 55 | { |
| 56 | struct acpi_device *acpi; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 57 | acpi_status status; |
| 58 | unsigned long value; |
| 59 | int error; |
| 60 | |
| 61 | acpi = to_acpi_device(dev); |
| 62 | |
| 63 | error = kstrtoul(buf, 0, &value); |
| 64 | |
| 65 | if (error) |
| 66 | return error; |
| 67 | |
Zhang Rui | b92f7a9 | 2013-09-03 08:31:53 +0800 | [diff] [blame^] | 68 | status = acpi_execute_simple_method(acpi->handle, "SFFS", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 69 | |
| 70 | if (!ACPI_SUCCESS(status)) |
| 71 | return -EINVAL; |
| 72 | |
| 73 | return count; |
| 74 | } |
| 75 | |
| 76 | static struct device_attribute irst_wakeup_attr = { |
| 77 | .attr = { .name = "wakeup_events", .mode = 0600 }, |
| 78 | .show = irst_show_wakeup_events, |
| 79 | .store = irst_store_wakeup_events |
| 80 | }; |
| 81 | |
| 82 | static ssize_t irst_show_wakeup_time(struct device *dev, |
| 83 | struct device_attribute *attr, char *buf) |
| 84 | { |
| 85 | struct acpi_device *acpi; |
| 86 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 87 | union acpi_object *result; |
| 88 | acpi_status status; |
| 89 | |
| 90 | acpi = to_acpi_device(dev); |
| 91 | |
| 92 | status = acpi_evaluate_object(acpi->handle, "GFTV", NULL, &output); |
| 93 | if (!ACPI_SUCCESS(status)) |
| 94 | return -EINVAL; |
| 95 | |
| 96 | result = output.pointer; |
| 97 | |
| 98 | if (result->type != ACPI_TYPE_INTEGER) { |
| 99 | kfree(result); |
| 100 | return -EINVAL; |
| 101 | } |
| 102 | |
| 103 | return sprintf(buf, "%lld\n", result->integer.value); |
| 104 | } |
| 105 | |
| 106 | static ssize_t irst_store_wakeup_time(struct device *dev, |
| 107 | struct device_attribute *attr, |
| 108 | const char *buf, size_t count) |
| 109 | { |
| 110 | struct acpi_device *acpi; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 111 | acpi_status status; |
| 112 | unsigned long value; |
| 113 | int error; |
| 114 | |
| 115 | acpi = to_acpi_device(dev); |
| 116 | |
| 117 | error = kstrtoul(buf, 0, &value); |
| 118 | |
| 119 | if (error) |
| 120 | return error; |
| 121 | |
Zhang Rui | b92f7a9 | 2013-09-03 08:31:53 +0800 | [diff] [blame^] | 122 | status = acpi_execute_simple_method(acpi->handle, "SFTV", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 123 | |
| 124 | if (!ACPI_SUCCESS(status)) |
| 125 | return -EINVAL; |
| 126 | |
| 127 | return count; |
| 128 | } |
| 129 | |
| 130 | static struct device_attribute irst_timeout_attr = { |
| 131 | .attr = { .name = "wakeup_time", .mode = 0600 }, |
| 132 | .show = irst_show_wakeup_time, |
| 133 | .store = irst_store_wakeup_time |
| 134 | }; |
| 135 | |
| 136 | static int irst_add(struct acpi_device *acpi) |
| 137 | { |
| 138 | int error = 0; |
| 139 | |
| 140 | error = device_create_file(&acpi->dev, &irst_timeout_attr); |
| 141 | if (error) |
| 142 | goto out; |
| 143 | |
| 144 | error = device_create_file(&acpi->dev, &irst_wakeup_attr); |
| 145 | if (error) |
| 146 | goto out_timeout; |
| 147 | |
| 148 | return 0; |
| 149 | |
| 150 | out_timeout: |
| 151 | device_remove_file(&acpi->dev, &irst_timeout_attr); |
| 152 | out: |
| 153 | return error; |
| 154 | } |
| 155 | |
| 156 | static int irst_remove(struct acpi_device *acpi) |
| 157 | { |
| 158 | device_remove_file(&acpi->dev, &irst_wakeup_attr); |
| 159 | device_remove_file(&acpi->dev, &irst_timeout_attr); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | static const struct acpi_device_id irst_ids[] = { |
| 165 | {"INT3392", 0}, |
| 166 | {"", 0} |
| 167 | }; |
| 168 | |
| 169 | static struct acpi_driver irst_driver = { |
| 170 | .owner = THIS_MODULE, |
| 171 | .name = "intel_rapid_start", |
| 172 | .class = "intel_rapid_start", |
| 173 | .ids = irst_ids, |
| 174 | .ops = { |
| 175 | .add = irst_add, |
| 176 | .remove = irst_remove, |
| 177 | }, |
| 178 | }; |
| 179 | |
Wei Yongjun | 2ff1af7 | 2013-07-17 09:55:25 +0800 | [diff] [blame] | 180 | module_acpi_driver(irst_driver); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 181 | |
| 182 | MODULE_DEVICE_TABLE(acpi, irst_ids); |