intel-rst.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. struct acpi_object_list input;
  48. union acpi_object param;
  49. acpi_status status;
  50. unsigned long value;
  51. int error;
  52. acpi = to_acpi_device(dev);
  53. error = kstrtoul(buf, 0, &value);
  54. if (error)
  55. return error;
  56. param.type = ACPI_TYPE_INTEGER;
  57. param.integer.value = value;
  58. input.count = 1;
  59. input.pointer = &param;
  60. status = acpi_evaluate_object(acpi->handle, "SFFS", &input, NULL);
  61. if (!ACPI_SUCCESS(status))
  62. return -EINVAL;
  63. return count;
  64. }
  65. static struct device_attribute irst_wakeup_attr = {
  66. .attr = { .name = "wakeup_events", .mode = 0600 },
  67. .show = irst_show_wakeup_events,
  68. .store = irst_store_wakeup_events
  69. };
  70. static ssize_t irst_show_wakeup_time(struct device *dev,
  71. struct device_attribute *attr, char *buf)
  72. {
  73. struct acpi_device *acpi;
  74. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  75. union acpi_object *result;
  76. acpi_status status;
  77. acpi = to_acpi_device(dev);
  78. status = acpi_evaluate_object(acpi->handle, "GFTV", NULL, &output);
  79. if (!ACPI_SUCCESS(status))
  80. return -EINVAL;
  81. result = output.pointer;
  82. if (result->type != ACPI_TYPE_INTEGER) {
  83. kfree(result);
  84. return -EINVAL;
  85. }
  86. return sprintf(buf, "%lld\n", result->integer.value);
  87. }
  88. static ssize_t irst_store_wakeup_time(struct device *dev,
  89. struct device_attribute *attr,
  90. const char *buf, size_t count)
  91. {
  92. struct acpi_device *acpi;
  93. struct acpi_object_list input;
  94. union acpi_object param;
  95. acpi_status status;
  96. unsigned long value;
  97. int error;
  98. acpi = to_acpi_device(dev);
  99. error = kstrtoul(buf, 0, &value);
  100. if (error)
  101. return error;
  102. param.type = ACPI_TYPE_INTEGER;
  103. param.integer.value = value;
  104. input.count = 1;
  105. input.pointer = &param;
  106. status = acpi_evaluate_object(acpi->handle, "SFTV", &input, NULL);
  107. if (!ACPI_SUCCESS(status))
  108. return -EINVAL;
  109. return count;
  110. }
  111. static struct device_attribute irst_timeout_attr = {
  112. .attr = { .name = "wakeup_time", .mode = 0600 },
  113. .show = irst_show_wakeup_time,
  114. .store = irst_store_wakeup_time
  115. };
  116. static int irst_add(struct acpi_device *acpi)
  117. {
  118. int error = 0;
  119. error = device_create_file(&acpi->dev, &irst_timeout_attr);
  120. if (error)
  121. goto out;
  122. error = device_create_file(&acpi->dev, &irst_wakeup_attr);
  123. if (error)
  124. goto out_timeout;
  125. return 0;
  126. out_timeout:
  127. device_remove_file(&acpi->dev, &irst_timeout_attr);
  128. out:
  129. return error;
  130. }
  131. static int irst_remove(struct acpi_device *acpi)
  132. {
  133. device_remove_file(&acpi->dev, &irst_wakeup_attr);
  134. device_remove_file(&acpi->dev, &irst_timeout_attr);
  135. return 0;
  136. }
  137. static const struct acpi_device_id irst_ids[] = {
  138. {"INT3392", 0},
  139. {"", 0}
  140. };
  141. static struct acpi_driver irst_driver = {
  142. .owner = THIS_MODULE,
  143. .name = "intel_rapid_start",
  144. .class = "intel_rapid_start",
  145. .ids = irst_ids,
  146. .ops = {
  147. .add = irst_add,
  148. .remove = irst_remove,
  149. },
  150. };
  151. module_acpi_driver(irst_driver);
  152. MODULE_DEVICE_TABLE(acpi, irst_ids);