Andy Shevchenko | bd7c586 | 2018-09-26 18:27:40 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2013 Matthew Garrett <mjg59@srcf.ucam.org> |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 4 | */ |
| 5 | |
Andy Shevchenko | 5f4ad6a | 2018-09-26 18:27:14 +0300 | [diff] [blame] | 6 | #include <linux/acpi.h> |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 7 | #include <linux/module.h> |
| 8 | #include <linux/slab.h> |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 9 | |
| 10 | MODULE_LICENSE("GPL"); |
| 11 | |
| 12 | static ssize_t irst_show_wakeup_events(struct device *dev, |
| 13 | struct device_attribute *attr, |
| 14 | char *buf) |
| 15 | { |
| 16 | struct acpi_device *acpi; |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame] | 17 | unsigned long long value; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 18 | acpi_status status; |
| 19 | |
| 20 | acpi = to_acpi_device(dev); |
| 21 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame] | 22 | status = acpi_evaluate_integer(acpi->handle, "GFFS", NULL, &value); |
Peter Ujfalusi | d46a764 | 2014-09-17 00:13:55 +0300 | [diff] [blame] | 23 | if (ACPI_FAILURE(status)) |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 24 | return -EINVAL; |
| 25 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame] | 26 | return sprintf(buf, "%lld\n", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | static 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 Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 34 | 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 Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 41 | if (error) |
| 42 | return error; |
| 43 | |
Zhang Rui | b92f7a9 | 2013-09-03 08:31:53 +0800 | [diff] [blame] | 44 | status = acpi_execute_simple_method(acpi->handle, "SFFS", value); |
Peter Ujfalusi | d46a764 | 2014-09-17 00:13:55 +0300 | [diff] [blame] | 45 | if (ACPI_FAILURE(status)) |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 46 | return -EINVAL; |
| 47 | |
| 48 | return count; |
| 49 | } |
| 50 | |
| 51 | static 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 | |
| 57 | static ssize_t irst_show_wakeup_time(struct device *dev, |
| 58 | struct device_attribute *attr, char *buf) |
| 59 | { |
| 60 | struct acpi_device *acpi; |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame] | 61 | unsigned long long value; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 62 | acpi_status status; |
| 63 | |
| 64 | acpi = to_acpi_device(dev); |
| 65 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame] | 66 | status = acpi_evaluate_integer(acpi->handle, "GFTV", NULL, &value); |
Peter Ujfalusi | d46a764 | 2014-09-17 00:13:55 +0300 | [diff] [blame] | 67 | if (ACPI_FAILURE(status)) |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 68 | return -EINVAL; |
| 69 | |
Zhang Rui | c7c878a | 2013-09-03 08:32:13 +0800 | [diff] [blame] | 70 | return sprintf(buf, "%lld\n", value); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static 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 Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 78 | 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 Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 85 | if (error) |
| 86 | return error; |
| 87 | |
Zhang Rui | b92f7a9 | 2013-09-03 08:31:53 +0800 | [diff] [blame] | 88 | status = acpi_execute_simple_method(acpi->handle, "SFTV", value); |
Peter Ujfalusi | d46a764 | 2014-09-17 00:13:55 +0300 | [diff] [blame] | 89 | if (ACPI_FAILURE(status)) |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 90 | return -EINVAL; |
| 91 | |
| 92 | return count; |
| 93 | } |
| 94 | |
| 95 | static 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 | |
| 101 | static int irst_add(struct acpi_device *acpi) |
| 102 | { |
Peter Ujfalusi | a3d3c53 | 2014-09-17 00:13:56 +0300 | [diff] [blame] | 103 | int error; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 104 | |
| 105 | error = device_create_file(&acpi->dev, &irst_timeout_attr); |
Peter Ujfalusi | a3d3c53 | 2014-09-17 00:13:56 +0300 | [diff] [blame] | 106 | if (unlikely(error)) |
| 107 | return error; |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 108 | |
| 109 | error = device_create_file(&acpi->dev, &irst_wakeup_attr); |
Peter Ujfalusi | a3d3c53 | 2014-09-17 00:13:56 +0300 | [diff] [blame] | 110 | if (unlikely(error)) |
| 111 | device_remove_file(&acpi->dev, &irst_timeout_attr); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 112 | |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 113 | return error; |
| 114 | } |
| 115 | |
| 116 | static 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 | |
| 124 | static const struct acpi_device_id irst_ids[] = { |
| 125 | {"INT3392", 0}, |
| 126 | {"", 0} |
| 127 | }; |
| 128 | |
| 129 | static 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 Yongjun | 2ff1af7 | 2013-07-17 09:55:25 +0800 | [diff] [blame] | 140 | module_acpi_driver(irst_driver); |
Matthew Garrett | 34a956d | 2013-07-02 18:41:03 -0400 | [diff] [blame] | 141 | |
| 142 | MODULE_DEVICE_TABLE(acpi, irst_ids); |