sec_cmd.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* SPDX-License-Identifier: GPL-2.0
  2. * Copyright (C) 2022 Samsung Electronics Co., Ltd.
  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 version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef _SEC_CMD_H_
  9. #define _SEC_CMD_H_
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/slab.h>
  13. #include <linux/device.h>
  14. #include <linux/workqueue.h>
  15. #include <linux/stat.h>
  16. #include <linux/err.h>
  17. #include <linux/input.h>
  18. #include <linux/sched/clock.h>
  19. #include <linux/uaccess.h>
  20. #if IS_ENABLED(CONFIG_DRV_SAMSUNG)
  21. #include <linux/sec_class.h>
  22. #endif
  23. #if !IS_ENABLED(CONFIG_SEC_FACTORY)
  24. #define USE_SEC_CMD_QUEUE
  25. #include <linux/kfifo.h>
  26. #endif
  27. #define SEC_CLASS_DEVT_TSP 10
  28. #define SEC_CLASS_DEVT_TKEY 11
  29. #define SEC_CLASS_DEVT_WACOM 12
  30. #define SEC_CLASS_DEVT_SIDEKEY 13
  31. #define SEC_CLASS_DEV_NAME_TSP "tsp"
  32. #define SEC_CLASS_DEV_NAME_TKEY "sec_touchkey"
  33. #define SEC_CLASS_DEV_NAME_WACOM "sec_epen"
  34. #define SEC_CLASS_DEV_NAME_SIDEKEY "sec_sidekey"
  35. #define SEC_CLASS_DEVT_TSP1 15
  36. #define SEC_CLASS_DEVT_TSP2 16
  37. #define SEC_CLASS_DEV_NAME_TSP1 "tsp1"
  38. #define SEC_CLASS_DEV_NAME_TSP2 "tsp2"
  39. #define SEC_CMD(name, func) .cmd_name = name, .cmd_func = func
  40. #define SEC_CMD_H(name, func) .cmd_name = name, .cmd_func = func, .cmd_log = 1
  41. #define SEC_CMD_V2(name, func, force_func, use_cases, wait_result) \
  42. .cmd_name = name, .cmd_func = func, .cmd_func_forced = force_func, \
  43. .cmd_use_cases = use_cases, .wait_read_result = wait_result
  44. #define SEC_CMD_V2_H(name, func, force_func, use_cases, wait_result) \
  45. .cmd_name = name, .cmd_func = func, .cmd_func_forced = force_func, \
  46. .cmd_use_cases = use_cases, .wait_read_result = wait_result, .cmd_log = 1
  47. #define SEC_CMD_BUF_SIZE (4096 - 1)
  48. #define SEC_CMD_STR_LEN 256
  49. #define SEC_CMD_RESULT_STR_LEN (4096 - 1)
  50. #define SEC_CMD_RESULT_STR_LEN_EXPAND (SEC_CMD_RESULT_STR_LEN * 6)
  51. #define SEC_CMD_PARAM_NUM 8
  52. #define WAIT_RESULT true
  53. #define EXIT_RESULT false
  54. struct sec_cmd {
  55. struct list_head list;
  56. const char *cmd_name;
  57. void (*cmd_func)(void *device_data);
  58. int (*cmd_func_forced)(void *device_data);
  59. /*
  60. * cmd_use_cases using as below
  61. * 1 : call function, 0 : no call
  62. * first bit(1<<0) CHECK_POWEROFF
  63. * second bit(1<<1) CHECK_LPMODE
  64. * third bit(1<<2) CHECK_POWERON
  65. */
  66. int cmd_use_cases;
  67. bool wait_read_result;
  68. int cmd_log;
  69. bool not_support_cmds;
  70. };
  71. enum sec_cmd_status_uevent_type {
  72. STATUS_TYPE_WET = 0,
  73. STATUS_TYPE_NOISE,
  74. STATUS_TYPE_FREQ,
  75. };
  76. enum SEC_CMD_STATUS {
  77. SEC_CMD_STATUS_WAITING = 0,
  78. SEC_CMD_STATUS_RUNNING, // = 1
  79. SEC_CMD_STATUS_OK, // = 2
  80. SEC_CMD_STATUS_FAIL, // = 3
  81. SEC_CMD_STATUS_EXPAND, // = 4
  82. SEC_CMD_STATUS_NOT_APPLICABLE, // = 5
  83. };
  84. #define INPUT_CMD_RESULT_NOT_EXIT 0
  85. #define INPUT_CMD_RESULT_NEED_EXIT 1
  86. #define input_cmd_result(cmd_state_parm, need_exit) \
  87. ({ \
  88. if (need_exit == INPUT_CMD_RESULT_NEED_EXIT) { \
  89. if (cmd_state_parm == SEC_CMD_STATUS_OK) \
  90. snprintf(buff, sizeof(buff), "OK"); \
  91. else if (cmd_state_parm == SEC_CMD_STATUS_FAIL) \
  92. snprintf(buff, sizeof(buff), "NG"); \
  93. else if (cmd_state_parm == SEC_CMD_STATUS_NOT_APPLICABLE) \
  94. snprintf(buff, sizeof(buff), "NA"); \
  95. } \
  96. sec_cmd_set_cmd_result(sec, buff, strnlen(buff, sizeof(buff))); \
  97. sec->cmd_state = cmd_state_parm; \
  98. if (need_exit == INPUT_CMD_RESULT_NEED_EXIT) \
  99. sec_cmd_set_cmd_exit(sec); \
  100. input_info(true, ptsp, "%s: %s\n", __func__, buff); \
  101. })
  102. #ifdef USE_SEC_CMD_QUEUE
  103. #define SEC_CMD_MAX_QUEUE 10
  104. struct command {
  105. char cmd[SEC_CMD_STR_LEN];
  106. };
  107. #endif
  108. struct sec_cmd_data {
  109. struct device *fac_dev;
  110. struct device *dev;
  111. struct list_head cmd_list_head;
  112. u8 cmd_state;
  113. char cmd[SEC_CMD_STR_LEN];
  114. int cmd_param[SEC_CMD_PARAM_NUM];
  115. char *cmd_result;
  116. int cmd_result_expand;
  117. int cmd_result_expand_count;
  118. int cmd_buffer_size;
  119. atomic_t cmd_is_running;
  120. struct mutex cmd_lock;
  121. struct mutex fs_lock;
  122. #ifdef USE_SEC_CMD_QUEUE
  123. struct kfifo cmd_queue;
  124. struct mutex fifo_lock;
  125. struct delayed_work cmd_work;
  126. struct mutex wait_lock;
  127. struct completion cmd_result_done;
  128. #endif
  129. bool wait_cmd_result_done;
  130. int item_count;
  131. char cmd_result_all[SEC_CMD_RESULT_STR_LEN];
  132. u8 cmd_all_factory_state;
  133. struct attribute_group *vendor_attr_group;
  134. };
  135. void sec_cmd_set_cmd_exit(struct sec_cmd_data *data);
  136. void sec_cmd_set_default_result(struct sec_cmd_data *data);
  137. void sec_cmd_set_cmd_result(struct sec_cmd_data *data, char *buff, int len);
  138. void sec_cmd_set_cmd_result_all(struct sec_cmd_data *data, char *buff, int len, char *item);
  139. int sec_cmd_init(struct sec_cmd_data *data, struct device *dev, struct sec_cmd *cmds,
  140. int len, int devt, struct attribute_group *vendor_attr_group);
  141. int sec_cmd_init_without_platdata(struct sec_cmd_data *data, struct sec_cmd *cmds,
  142. int len, int devt, struct attribute_group *vendor_attr_group);
  143. void sec_cmd_exit(struct sec_cmd_data *data, int devt);
  144. void sec_cmd_send_event_to_user(struct sec_cmd_data *data, char *test, char *result);
  145. void sec_cmd_send_status_uevent(struct sec_cmd_data *data, enum sec_cmd_status_uevent_type type, int value);
  146. void sec_cmd_send_gesture_uevent(struct sec_cmd_data *data, int type, int x, int y);
  147. #endif /* _SEC_CMD_H_ */