fts_aoi_event.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 and
  7. * only version 2 as published by the Free Software Foundation.
  8. *
  9. */
  10. #include <linux/device.h>
  11. #include <linux/i2c.h>
  12. #include "fts.h"
  13. static ssize_t touch_event_show(struct device *dev,
  14. struct device_attribute *attr, char *buf)
  15. {
  16. return 0;
  17. }
  18. ssize_t aoi_set_store(struct device *dev, struct device_attribute *attr,
  19. const char *buf, size_t count)
  20. {
  21. int ret;
  22. struct i2c_client *client = to_i2c_client(dev);
  23. struct fts_ts_info *info = i2c_get_clientdata(client);
  24. int left, top, right, bottom;
  25. ret = sscanf(buf, "%d %d %d %d", &left, &top, &right, &bottom);
  26. if (ret != 4)
  27. return -EINVAL;
  28. if (right > X_AXIS_MAX)
  29. right = X_AXIS_MAX;
  30. if (bottom > Y_AXIS_MAX)
  31. bottom = Y_AXIS_MAX;
  32. if (left < 0 || left > X_AXIS_MAX || right < 0 ||
  33. top > Y_AXIS_MAX || bottom < 0)
  34. return -EINVAL;
  35. if (left >= right || top >= bottom) {
  36. info->aoi_left = 0;
  37. info->aoi_top = 0;
  38. info->aoi_right = 0;
  39. info->aoi_bottom = 0;
  40. info->aoi_notify_enabled = false;
  41. return count;
  42. }
  43. info->aoi_left = left;
  44. info->aoi_top = top;
  45. info->aoi_right = right;
  46. info->aoi_bottom = bottom;
  47. info->aoi_notify_enabled = true;
  48. return count;
  49. }
  50. static ssize_t aoi_set_show(struct device *dev,
  51. struct device_attribute *attr, char *buf)
  52. {
  53. struct i2c_client *client = to_i2c_client(dev);
  54. struct fts_ts_info *info = i2c_get_clientdata(client);
  55. size_t len = 0;
  56. len = scnprintf(buf + len, PAGE_SIZE,
  57. "%d %d %d %d",
  58. info->aoi_left,
  59. info->aoi_top,
  60. info->aoi_right,
  61. info->aoi_bottom);
  62. return len;
  63. }
  64. static ssize_t power_set_store(struct device *dev,
  65. struct device_attribute *attr, const char *buf, size_t count)
  66. {
  67. int enable;
  68. if (kstrtoint(buf, 10, &enable))
  69. return -EINVAL;
  70. return count;
  71. }
  72. static DEVICE_ATTR_RO(touch_event);
  73. static DEVICE_ATTR_RW(aoi_set);
  74. static DEVICE_ATTR_WO(power_set);
  75. static struct attribute *aoi_cmd_attributes[] = {
  76. &dev_attr_touch_event.attr,
  77. &dev_attr_aoi_set.attr,
  78. &dev_attr_power_set.attr,
  79. NULL,
  80. };
  81. struct attribute_group aoi_cmd_attr_group = {
  82. .attrs = aoi_cmd_attributes,
  83. };
  84. static ssize_t enable_store(struct device *dev,
  85. struct device_attribute *attr, const char *buf, size_t count)
  86. {
  87. struct fts_ts_info *info = dev_get_drvdata(dev);
  88. int enable;
  89. if (kstrtoint(buf, 10, &enable))
  90. return -EINVAL;
  91. if (!enable && info->aoi_notify_enabled) {
  92. info->aoi_left = 0;
  93. info->aoi_top = 0;
  94. info->aoi_right = 0;
  95. info->aoi_bottom = 0;
  96. info->aoi_notify_enabled = false;
  97. } else {
  98. info->aoi_left = 0;
  99. info->aoi_top = 0;
  100. info->aoi_right = X_AXIS_MAX;
  101. info->aoi_bottom = Y_AXIS_MAX;
  102. info->aoi_notify_enabled = true;
  103. }
  104. return count;
  105. }
  106. static ssize_t enable_show(struct device *dev,
  107. struct device_attribute *attr, char *buf)
  108. {
  109. struct fts_ts_info *info = dev_get_drvdata(dev);
  110. size_t len = 0;
  111. len = scnprintf(buf, PAGE_SIZE,
  112. "%d",
  113. info->aoi_notify_enabled);
  114. return len;
  115. }
  116. static DEVICE_ATTR_RW(enable);
  117. static struct attribute *aoi_enable_attributes[] = {
  118. &dev_attr_aoi_set.attr,
  119. &dev_attr_enable.attr,
  120. NULL,
  121. };
  122. struct attribute_group aoi_enable_attr_group = {
  123. .attrs = aoi_enable_attributes,
  124. };