back_tap.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright (C) 2024, Samsung Electronics Co. Ltd. All Rights Reserved.
  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. */
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include "adsp.h"
  18. #define NAME "Back Tap"
  19. #define VENDOR "Samsung"
  20. /* 1: Double Tap
  21. * 2: Triple Tap
  22. * 3: Double and Triple Tap
  23. */
  24. static int backtap_type = 3;
  25. static int backtap_thd;
  26. static ssize_t backtap_name_show(struct device *dev,
  27. struct device_attribute *attr, char *buf)
  28. {
  29. return snprintf(buf, PAGE_SIZE, "%s\n", NAME);
  30. }
  31. static ssize_t backtap_vendor_show(struct device *dev,
  32. struct device_attribute *attr, char *buf)
  33. {
  34. return snprintf(buf, PAGE_SIZE, "%s\n", VENDOR);
  35. }
  36. static ssize_t backtap_peak_thd_show(struct device *dev,
  37. struct device_attribute *attr, char *buf)
  38. {
  39. pr_info("[FACTORY] %s: Curr THD %d\n", __func__, backtap_thd);
  40. return snprintf(buf, PAGE_SIZE, "%d\n", backtap_thd);
  41. }
  42. static ssize_t backtap_peak_thd_store(struct device *dev,
  43. struct device_attribute *attr, const char *buf, size_t size)
  44. {
  45. struct adsp_data *data = dev_get_drvdata(dev);
  46. int cnt = 0;
  47. int msg_buf;
  48. int ret = 0;
  49. ret = kstrtoint(buf, 10, &msg_buf);
  50. if (ret < 0) {
  51. pr_err("[FACTORY] %s: kstrtoint fail\n", __func__);
  52. return -EINVAL;
  53. }
  54. if (msg_buf < 0 || msg_buf > 2) {
  55. pr_err("[FACTORY] %s: Invalid value\n", __func__);
  56. return -EINVAL;
  57. }
  58. pr_info("[FACTORY] %s: msg_buf = %d\n", __func__, msg_buf);
  59. mutex_lock(&data->backtap_factory_mutex);
  60. adsp_unicast(&msg_buf, sizeof(int),
  61. MSG_BACKTAP, 0, MSG_TYPE_SET_THRESHOLD);
  62. while (!(data->ready_flag[MSG_TYPE_SET_THRESHOLD] & 1 << MSG_BACKTAP) &&
  63. cnt++ < TIMEOUT_CNT)
  64. usleep_range(500, 550);
  65. data->ready_flag[MSG_TYPE_SET_THRESHOLD] &= ~(1 << MSG_BACKTAP);
  66. if (cnt >= TIMEOUT_CNT)
  67. pr_err("[FACTORY] %s: Timeout!!!\n", __func__);
  68. else
  69. backtap_thd = data->msg_buf[MSG_BACKTAP][0];
  70. pr_info("[FACTORY] %s: New THD %d\n", __func__, backtap_thd);
  71. mutex_unlock(&data->backtap_factory_mutex);
  72. return size;
  73. }
  74. static ssize_t backtap_type_show(struct device *dev,
  75. struct device_attribute *attr, char *buf)
  76. {
  77. pr_info("[FACTORY] %s: Curr Type %d\n", __func__, backtap_type);
  78. return snprintf(buf, PAGE_SIZE, "%d\n", backtap_type);
  79. }
  80. static ssize_t backtap_type_store(struct device *dev,
  81. struct device_attribute *attr, const char *buf, size_t size)
  82. {
  83. struct adsp_data *data = dev_get_drvdata(dev);
  84. int cnt = 0;
  85. int msg_buf;
  86. int ret = 0;
  87. ret = kstrtoint(buf, 10, &msg_buf);
  88. if (ret < 0) {
  89. pr_err("[FACTORY] %s: kstrtoint fail\n", __func__);
  90. return -EINVAL;
  91. }
  92. if (msg_buf <= 0 || msg_buf >= 4) {
  93. pr_err("[FACTORY] %s: Invalid value\n", __func__);
  94. return -EINVAL;
  95. }
  96. pr_info("[FACTORY] %s: msg_buf = %d\n", __func__, msg_buf);
  97. mutex_lock(&data->backtap_factory_mutex);
  98. adsp_unicast(&msg_buf, sizeof(int),
  99. MSG_BACKTAP, 0, MSG_TYPE_OPTION_DEFINE);
  100. while (!(data->ready_flag[MSG_TYPE_OPTION_DEFINE] & 1 << MSG_BACKTAP) &&
  101. cnt++ < TIMEOUT_CNT)
  102. usleep_range(500, 550);
  103. data->ready_flag[MSG_TYPE_OPTION_DEFINE] &= ~(1 << MSG_BACKTAP);
  104. if (cnt >= TIMEOUT_CNT)
  105. pr_err("[FACTORY] %s: Timeout!!!\n", __func__);
  106. else
  107. backtap_type = data->msg_buf[MSG_BACKTAP][0];
  108. pr_info("[FACTORY] %s: New Type %d\n", __func__, backtap_type);
  109. mutex_unlock(&data->backtap_factory_mutex);
  110. return size;
  111. }
  112. static DEVICE_ATTR(name, 0444, backtap_name_show, NULL);
  113. static DEVICE_ATTR(vendor, 0444, backtap_vendor_show, NULL);
  114. static DEVICE_ATTR(backtap_peak_thd, 0660, backtap_peak_thd_show, backtap_peak_thd_store);
  115. static DEVICE_ATTR(backtap_type, 0660, backtap_type_show, backtap_type_store);
  116. static struct device_attribute *backtap_attrs[] = {
  117. &dev_attr_name,
  118. &dev_attr_vendor,
  119. &dev_attr_backtap_peak_thd,
  120. &dev_attr_backtap_type,
  121. NULL,
  122. };
  123. int __init backtap_factory_init(void)
  124. {
  125. adsp_factory_register(MSG_BACKTAP, backtap_attrs);
  126. pr_info("[FACTORY] %s\n", __func__);
  127. return 0;
  128. }
  129. void __exit backtap_factory_exit(void)
  130. {
  131. adsp_factory_unregister(MSG_BACKTAP);
  132. pr_info("[FACTORY] %s\n", __func__);
  133. }