intel-rst.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 <acpi/acpi_drivers.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. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  29. union acpi_object *result;
  30. acpi_status status;
  31. acpi = to_acpi_device(dev);
  32. status = acpi_evaluate_object(acpi->handle, "GFFS", NULL, &output);
  33. if (!ACPI_SUCCESS(status))
  34. return -EINVAL;
  35. result = output.pointer;
  36. if (result->type != ACPI_TYPE_INTEGER) {
  37. kfree(result);
  38. return -EINVAL;
  39. }
  40. return sprintf(buf, "%lld\n", result->integer.value);
  41. }
  42. static ssize_t irst_store_wakeup_events(struct device *dev,
  43. struct device_attribute *attr,
  44. const char *buf, size_t count)
  45. {
  46. struct acpi_device *acpi;
  47. acpi_status status;
  48. unsigned long value;
  49. int error;
  50. acpi = to_acpi_device(dev);
  51. error = kstrtoul(buf, 0, &value);
  52. if (error)
  53. return error;
  54. status = acpi_execute_simple_method(acpi->handle, "SFFS", value);
  55. if (!ACPI_SUCCESS(status))
  56. return -EINVAL;
  57. return count;
  58. }
  59. static struct device_attribute irst_wakeup_attr = {
  60. .attr = { .name = "wakeup_events", .mode = 0600 },
  61. .show = irst_show_wakeup_events,
  62. .store = irst_store_wakeup_events
  63. };
  64. static ssize_t irst_show_wakeup_time(struct device *dev,
  65. struct device_attribute *attr, char *buf)
  66. {
  67. struct acpi_device *acpi;
  68. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  69. union acpi_object *result;
  70. acpi_status status;
  71. acpi = to_acpi_device(dev);
  72. status = acpi_evaluate_object(acpi->handle, "GFTV", NULL, &output);
  73. if (!ACPI_SUCCESS(status))
  74. return -EINVAL;
  75. result = output.pointer;
  76. if (result->type != ACPI_TYPE_INTEGER) {
  77. kfree(result);
  78. return -EINVAL;
  79. }
  80. return sprintf(buf, "%lld\n", result->integer.value);
  81. }
  82. static ssize_t irst_store_wakeup_time(struct device *dev,
  83. struct device_attribute *attr,
  84. const char *buf, size_t count)
  85. {
  86. struct acpi_device *acpi;
  87. acpi_status status;
  88. unsigned long value;
  89. int error;
  90. acpi = to_acpi_device(dev);
  91. error = kstrtoul(buf, 0, &value);
  92. if (error)
  93. return error;
  94. status = acpi_execute_simple_method(acpi->handle, "SFTV", value);
  95. if (!ACPI_SUCCESS(status))
  96. return -EINVAL;
  97. return count;
  98. }
  99. static struct device_attribute irst_timeout_attr = {
  100. .attr = { .name = "wakeup_time", .mode = 0600 },
  101. .show = irst_show_wakeup_time,
  102. .store = irst_store_wakeup_time
  103. };
  104. static int irst_add(struct acpi_device *acpi)
  105. {
  106. int error = 0;
  107. error = device_create_file(&acpi->dev, &irst_timeout_attr);
  108. if (error)
  109. goto out;
  110. error = device_create_file(&acpi->dev, &irst_wakeup_attr);
  111. if (error)
  112. goto out_timeout;
  113. return 0;
  114. out_timeout:
  115. device_remove_file(&acpi->dev, &irst_timeout_attr);
  116. out:
  117. return error;
  118. }
  119. static int irst_remove(struct acpi_device *acpi)
  120. {
  121. device_remove_file(&acpi->dev, &irst_wakeup_attr);
  122. device_remove_file(&acpi->dev, &irst_timeout_attr);
  123. return 0;
  124. }
  125. static const struct acpi_device_id irst_ids[] = {
  126. {"INT3392", 0},
  127. {"", 0}
  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. module_acpi_driver(irst_driver);
  140. MODULE_DEVICE_TABLE(acpi, irst_ids);