^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2013 Matthew Garrett <mjg59@srcf.ucam.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static ssize_t irst_show_wakeup_events(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct acpi_device *acpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) unsigned long long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) status = acpi_evaluate_integer(acpi->handle, "GFFS", NULL, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) return sprintf(buf, "%lld\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static ssize_t irst_store_wakeup_events(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct acpi_device *acpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) error = kstrtoul(buf, 0, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) status = acpi_execute_simple_method(acpi->handle, "SFFS", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static struct device_attribute irst_wakeup_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .attr = { .name = "wakeup_events", .mode = 0600 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .show = irst_show_wakeup_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .store = irst_store_wakeup_events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static ssize_t irst_show_wakeup_time(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct acpi_device *acpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned long long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) status = acpi_evaluate_integer(acpi->handle, "GFTV", NULL, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return sprintf(buf, "%lld\n", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static ssize_t irst_store_wakeup_time(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct acpi_device *acpi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) unsigned long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) acpi = to_acpi_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) error = kstrtoul(buf, 0, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) status = acpi_execute_simple_method(acpi->handle, "SFTV", value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static struct device_attribute irst_timeout_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .attr = { .name = "wakeup_time", .mode = 0600 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .show = irst_show_wakeup_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .store = irst_store_wakeup_time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int irst_add(struct acpi_device *acpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) error = device_create_file(&acpi->dev, &irst_timeout_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) error = device_create_file(&acpi->dev, &irst_wakeup_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) device_remove_file(&acpi->dev, &irst_timeout_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int irst_remove(struct acpi_device *acpi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) device_remove_file(&acpi->dev, &irst_wakeup_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) device_remove_file(&acpi->dev, &irst_timeout_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static const struct acpi_device_id irst_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {"INT3392", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {"", 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static struct acpi_driver irst_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .name = "intel_rapid_start",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .class = "intel_rapid_start",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .ids = irst_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .add = irst_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .remove = irst_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) module_acpi_driver(irst_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) MODULE_DEVICE_TABLE(acpi, irst_ids);