intel-rst.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #include <linux/init.h>
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/acpi.h>
  22. MODULE_LICENSE("GPL");
  23. static ssize_t irst_show_wakeup_events(struct device *dev,
  24. struct device_attribute *attr,
  25. char *buf)
  26. {
  27. struct acpi_device *acpi;
  28. unsigned long long value;
  29. acpi_status status;
  30. acpi = to_acpi_device(dev);
  31. status = acpi_evaluate_integer(acpi->handle, "GFFS", NULL, &value);
  32. if (ACPI_FAILURE(status))
  33. return -EINVAL;
  34. return sprintf(buf, "%lld\n", value);
  35. }
  36. static ssize_t irst_store_wakeup_events(struct device *dev,
  37. struct device_attribute *attr,
  38. const char *buf, size_t count)
  39. {
  40. struct acpi_device *acpi;
  41. acpi_status status;
  42. unsigned long value;
  43. int error;
  44. acpi = to_acpi_device(dev);
  45. error = kstrtoul(buf, 0, &value);
  46. if (error)
  47. return error;
  48. status = acpi_execute_simple_method(acpi->handle, "SFFS", value);
  49. if (ACPI_FAILURE(status))
  50. return -EINVAL;
  51. return count;
  52. }
  53. static struct device_attribute irst_wakeup_attr = {
  54. .attr = { .name = "wakeup_events", .mode = 0600 },
  55. .show = irst_show_wakeup_events,
  56. .store = irst_store_wakeup_events
  57. };
  58. static ssize_t irst_show_wakeup_time(struct device *dev,
  59. struct device_attribute *attr, char *buf)
  60. {
  61. struct acpi_device *acpi;
  62. unsigned long long value;
  63. acpi_status status;
  64. acpi = to_acpi_device(dev);
  65. status = acpi_evaluate_integer(acpi->handle, "GFTV", NULL, &value);
  66. if (ACPI_FAILURE(status))
  67. return -EINVAL;
  68. return sprintf(buf, "%lld\n", value);
  69. }
  70. static ssize_t irst_store_wakeup_time(struct device *dev,
  71. struct device_attribute *attr,
  72. const char *buf, size_t count)
  73. {
  74. struct acpi_device *acpi;
  75. acpi_status status;
  76. unsigned long value;
  77. int error;
  78. acpi = to_acpi_device(dev);
  79. error = kstrtoul(buf, 0, &value);
  80. if (error)
  81. return error;
  82. status = acpi_execute_simple_method(acpi->handle, "SFTV", value);
  83. if (ACPI_FAILURE(status))
  84. return -EINVAL;
  85. return count;
  86. }
  87. static struct device_attribute irst_timeout_attr = {
  88. .attr = { .name = "wakeup_time", .mode = 0600 },
  89. .show = irst_show_wakeup_time,
  90. .store = irst_store_wakeup_time
  91. };
  92. static int irst_add(struct acpi_device *acpi)
  93. {
  94. int error;
  95. error = device_create_file(&acpi->dev, &irst_timeout_attr);
  96. if (unlikely(error))
  97. return error;
  98. error = device_create_file(&acpi->dev, &irst_wakeup_attr);
  99. if (unlikely(error))
  100. device_remove_file(&acpi->dev, &irst_timeout_attr);
  101. return error;
  102. }
  103. static int irst_remove(struct acpi_device *acpi)
  104. {
  105. device_remove_file(&acpi->dev, &irst_wakeup_attr);
  106. device_remove_file(&acpi->dev, &irst_timeout_attr);
  107. return 0;
  108. }
  109. static const struct acpi_device_id irst_ids[] = {
  110. {"INT3392", 0},
  111. {"", 0}
  112. };
  113. static struct acpi_driver irst_driver = {
  114. .owner = THIS_MODULE,
  115. .name = "intel_rapid_start",
  116. .class = "intel_rapid_start",
  117. .ids = irst_ids,
  118. .ops = {
  119. .add = irst_add,
  120. .remove = irst_remove,
  121. },
  122. };
  123. module_acpi_driver(irst_driver);
  124. MODULE_DEVICE_TABLE(acpi, irst_ids);