intel-rst.c 3.0 KB

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