input_booster.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. #ifndef _INPUT_BOOSTER_H_
  2. #define _INPUT_BOOSTER_H_
  3. #include <linux/pm_qos.h>
  4. #include <linux/of.h>
  5. #include <linux/cpufreq.h>
  6. #include <linux/kernel.h>
  7. #include <linux/workqueue.h>
  8. #include <linux/input.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #if IS_ENABLED(CONFIG_SOC_EXYNOS2100) || \
  12. IS_ENABLED(CONFIG_ARCH_LAHAINA) || \
  13. IS_ENABLED(CONFIG_ARCH_WAIPIO)
  14. #include <linux/interconnect.h>
  15. #endif//CONFIG_SOC_EXYNOS2100 || CONFIG_ARCH_LAHAINA
  16. #if IS_ENABLED(CONFIG_MACH_MT6739)
  17. #include <linux/slab.h>
  18. #endif//CONFIG_MACH_MT6739
  19. #pragma GCC diagnostic ignored "-Wunused-variable"
  20. #pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
  21. #define USE_HMP_BOOST (IS_ENABLED(CONFIG_SCHED_WALT))
  22. #ifndef ITAG
  23. #define ITAG " [Input Booster] "
  24. #endif
  25. #define pr_booster(format, ...) { \
  26. if (debug_flag) \
  27. printk(ITAG format, ## __VA_ARGS__); \
  28. }
  29. #define IB_EVENT_TOUCH_BOOSTER 1
  30. #define MAX_MULTI_TOUCH_EVENTS 10
  31. #define MAX_IB_COUNT 100
  32. #define MAX_EVENT_COUNT 1024
  33. #define MAX_EVENTS (MAX_MULTI_TOUCH_EVENTS * 10)
  34. #define INPUT_BOOSTER_NULL -1
  35. #define INIT_ZERO 0
  36. #define DEFAULT_LEVEL 0
  37. #define INPUT_LEVEL 2
  38. //+++++++++++++++++++++++++++++++++++++++++++++++ STRUCT & VARIABLE FOR SYSFS +++++++++++++++++++++++++++++++++++++++++++++++//
  39. #define SYSFS_CLASS(_ATTR_, _ARGU_, _COUNT_) \
  40. ssize_t input_booster_sysfs_class_show_##_ATTR_(struct class *dev, struct class_attribute *attr, char *buf) \
  41. { \
  42. ssize_t ret; \
  43. unsigned int enable_event; \
  44. unsigned int debug_level; \
  45. unsigned int sendevent; \
  46. unsigned int ib_mode_state; \
  47. enable_event = enable_event_booster; \
  48. debug_level = debug_flag; \
  49. sendevent = send_ev_enable; \
  50. if (IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MODE)) \
  51. ib_mode_state = u_ib_mode; \
  52. ret = sprintf _ARGU_; \
  53. pr_booster("[Input Booster8] %s buf : %s\n", __func__, buf); \
  54. return ret; \
  55. } \
  56. ssize_t input_booster_sysfs_class_store_##_ATTR_(struct class *dev, struct class_attribute *attr, const char *buf, size_t count) \
  57. { \
  58. unsigned int enable_event[1] = {0}; \
  59. unsigned int debug_level[1] = {0}; \
  60. unsigned int sendevent[1] = {0}; \
  61. unsigned int ib_mode_state[1] = {0}; \
  62. enable_event[0] = enable_event_booster; \
  63. debug_level[0] = debug_flag; \
  64. sendevent[0] = send_ev_enable; \
  65. if (IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MODE)) \
  66. ib_mode_state[0] = u_ib_mode; \
  67. sscanf _ARGU_; \
  68. send_ev_enable = sendevent[0]; \
  69. debug_flag = debug_level[0]; \
  70. if (IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MODE)) \
  71. u_ib_mode = ib_mode_state[0] >= num_of_mode ? u_ib_mode : ib_mode_state[0]; \
  72. enable_event_booster = enable_event[0]; \
  73. pr_booster("[Input Booster8] %s buf : %s\n", __func__, buf); \
  74. if (sscanf _ARGU_ != _COUNT_) { \
  75. return count; \
  76. } \
  77. return count; \
  78. } \
  79. static struct class_attribute class_attr_##_ATTR_ = __ATTR(_ATTR_, S_IRUGO | S_IWUSR, input_booster_sysfs_class_show_##_ATTR_, input_booster_sysfs_class_store_##_ATTR_);
  80. #define HEAD_TAIL_SYSFS_DEVICE(_ATTR_) \
  81. ssize_t input_booster_sysfs_device_show_##_ATTR_(struct device *dev, struct device_attribute *attr, char *buf) \
  82. { \
  83. int i = 0; \
  84. ssize_t ret = 0; \
  85. ssize_t return_value = 0; \
  86. struct t_ib_device_tree *ib_dt = dev_get_drvdata(dev); \
  87. if (ib_dt == NULL) { \
  88. return return_value; \
  89. } \
  90. ret = sprintf(buf, "%d", ib_dt->_ATTR_##_time); \
  91. return_value += ret; \
  92. buf = buf + ret; \
  93. if (allowed_resources == NULL) { \
  94. return return_value; \
  95. } \
  96. for (i = 0; i < allowed_res_count; ++i) { \
  97. pr_booster("[Input Booster8] show i : %d, %s\n", i, #_ATTR_); \
  98. ret = sprintf(buf, " %d", ib_dt->res[allowed_resources[i]]._ATTR_##_value); \
  99. buf = buf + ret; \
  100. return_value += ret; \
  101. } \
  102. ret = sprintf(buf, "\n"); \
  103. buf = buf + ret; \
  104. return_value += ret; \
  105. return return_value; \
  106. } \
  107. ssize_t input_booster_sysfs_device_store_##_ATTR_(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
  108. { \
  109. struct t_ib_device_tree *ib_dt = dev_get_drvdata(dev); \
  110. int time = 0; \
  111. int values[MAX_RES_COUNT + 1] = {0,}; \
  112. int i = 0; \
  113. int offset = 0; \
  114. int dataCnt = 0; \
  115. pr_booster("[Input Booster8] %s buf : %s\n", __func__, buf); \
  116. if (ib_dt == NULL) \
  117. return count; \
  118. if (!sscanf(buf, "%d%n", &time, &offset)) { \
  119. pr_booster("### Keep this format : [time cpu_freq hmp_boost ddr_freq lpm_bias] (Ex: 200 1171200 2 1017 5###\n"); \
  120. return count; \
  121. } \
  122. buf += offset; \
  123. if (allowed_resources == NULL) { \
  124. return count; \
  125. } \
  126. for (i = 0; i < allowed_res_count; ++i) { \
  127. if (!sscanf(buf, "%d%n", &values[allowed_resources[i]], &offset)) { \
  128. pr_booster("### Keep this format : [time cpu_freq hmp_boost ddr_freq lpm_bias] (Ex: 200 1171200 2 1017 5###\n"); \
  129. return count; \
  130. } \
  131. dataCnt++; \
  132. buf += offset; \
  133. } \
  134. if (sscanf(buf, "%d", &values[i])) { \
  135. pr_booster("### Keep this format : [time cpu_freq hmp_boost ddr_freq lpm_bias] (Ex: 200 1171200 2 1017 5###\n"); \
  136. return count; \
  137. } \
  138. ib_dt->_ATTR_##_time = time; \
  139. for (i = 0; i < allowed_res_count; ++i) { \
  140. ib_dt->res[allowed_resources[i]]._ATTR_##_value = values[allowed_resources[i]]; \
  141. } \
  142. return count; \
  143. } \
  144. DEVICE_ATTR(_ATTR_, S_IRUGO | S_IWUSR, input_booster_sysfs_device_show_##_ATTR_, input_booster_sysfs_device_store_##_ATTR_);
  145. #define LEVEL_SYSFS_DEVICE(_ATTR_) \
  146. ssize_t input_booster_sysfs_device_show_##_ATTR_(struct device *dev, struct device_attribute *attr, char *buf) \
  147. { \
  148. ssize_t ret = 0; \
  149. ret += sprintf(buf, "%d\n", level_value); \
  150. return ret; \
  151. } \
  152. ssize_t input_booster_sysfs_device_store_##_ATTR_(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
  153. { \
  154. int level; \
  155. sscanf(buf, "%d", &level); \
  156. if (level < 0 || level > 2) { \
  157. pr_booster("### Keep this format : greater than 0, and less than 3\n"); \
  158. return count; \
  159. } \
  160. pr_booster("[Input Booster8] %s buf : %s\n", __func__, buf); \
  161. level_value = level; \
  162. return count; \
  163. } \
  164. DEVICE_ATTR(_ATTR_, S_IRUGO | S_IWUSR, input_booster_sysfs_device_show_##_ATTR_, input_booster_sysfs_device_store_##_ATTR_);
  165. #define INIT_SYSFS_CLASS(_CLASS_) { \
  166. ret = class_create_file(sysfs_class, &class_attr_##_CLASS_); \
  167. if (ret) { \
  168. pr_booster("[Input Booster] Failed to create class\n"); \
  169. class_destroy(sysfs_class); \
  170. return; \
  171. } \
  172. }
  173. //---------------------------------------------- STRUCT & VARIABLE FOR SYSFS ----------------------------------------------//
  174. #define TYPE_BITS 8
  175. #define CODE_BITS 12
  176. enum ib_flag_on_off {
  177. FLAG_OFF = 0,
  178. FLAG_ON
  179. };
  180. enum booster_head_or_tail {
  181. IB_HEAD = 0,
  182. IB_TAIL,
  183. IB_MAX
  184. };
  185. enum booster_mode_on_off {
  186. BOOSTER_OFF = 0,
  187. BOOSTER_ON,
  188. };
  189. enum {
  190. NONE_TYPE_DEVICE = -1,
  191. KEY = 0,
  192. TOUCH_KEY,
  193. TOUCH,
  194. MULTI_TOUCH,
  195. KEYBOARD,
  196. MOUSE,
  197. MOUSH_WHEEL,
  198. HOVER,
  199. SPEN,
  200. MAX_DEVICE_TYPE_NUM
  201. };
  202. struct t_ib_trigger {
  203. int key_id;
  204. int event_type;
  205. int dev_type;
  206. struct work_struct ib_trigger_work;
  207. };
  208. struct ib_event_data {
  209. struct input_value *vals;
  210. int evt_cnt;
  211. };
  212. struct ib_event_work {
  213. struct input_value vals[MAX_EVENT_COUNT];
  214. int evt_cnt;
  215. struct work_struct evdev_work;
  216. };
  217. struct t_ib_info {
  218. int key_id;
  219. int uniq_id;
  220. int press_flag;
  221. int rel_flag;
  222. int isHeadFinished;
  223. struct t_ib_device_tree *ib_dt;
  224. struct list_head list;
  225. struct work_struct ib_state_work[IB_MAX];
  226. struct delayed_work ib_timeout_work[IB_MAX];
  227. struct mutex lock;
  228. };
  229. struct t_ib_target {
  230. int uniq_id;
  231. long value;
  232. struct list_head list;
  233. };
  234. struct t_ib_res_info {
  235. int res_id;
  236. const char *label;
  237. int head_value;
  238. int tail_value;
  239. };
  240. struct t_ib_device_tree {
  241. const char *label;
  242. int type;
  243. int head_time;
  244. int tail_time;
  245. struct t_ib_res_info *res;
  246. };
  247. #if IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MODE)
  248. struct t_ib_boost_mode {
  249. const char *label;
  250. int type;
  251. struct t_ib_device_tree *dt;
  252. int dt_count;
  253. unsigned int dt_mask;
  254. int type_to_idx_table[MAX_DEVICE_TYPE_NUM];
  255. };
  256. #endif
  257. struct t_ddr_info {
  258. long mHz;
  259. long bps;
  260. };
  261. void trigger_input_booster(struct work_struct *work);
  262. void press_state_func(struct work_struct *work);
  263. void press_timeout_func(struct work_struct *work);
  264. void release_state_func(struct work_struct *work);
  265. void release_timeout_func(struct work_struct *work);
  266. unsigned int create_uniq_id(int type, int code, int slot);
  267. void input_booster_init(void);
  268. void input_booster_exit(void);
  269. #if IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MODE)
  270. void init_sysfs_device(struct class *sysfs_class, struct device* pdev, struct t_ib_device_tree *ib_dt);
  271. #else
  272. void init_sysfs_device(struct class *sysfs_class, struct t_ib_device_tree *ib_dt);
  273. #endif
  274. #if IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_QC) || \
  275. IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_SLSI) || \
  276. IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MTK)
  277. void ib_release_booster(long *rel_flags);
  278. void ib_set_booster(long *qos_values);
  279. int input_booster_init_vendor(void);
  280. void input_booster_exit_vendor(void);
  281. extern int sched_set_boost(int type);
  282. extern int ib_notifier_register(struct notifier_block *nb);
  283. extern int ib_notifier_unregister(struct notifier_block *nb);
  284. #endif
  285. int set_freq_limit(unsigned long id, unsigned int freq);
  286. #if IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_QC)
  287. extern void update_hyst_times_kernel(u64 ib_value);
  288. enum booster_res_type {
  289. CPUFREQ = 0,
  290. DDRFREQ,
  291. HMPBOOST,
  292. LPMBIAS,
  293. MAX_RES_COUNT
  294. };
  295. #elif IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_SLSI)
  296. enum booster_res_type {
  297. CLUSTER2 = 0,
  298. CLUSTER1,
  299. CLUSTER0,
  300. MIF,
  301. INT,
  302. HMPBOOST,
  303. UCC,
  304. MAX_RES_COUNT
  305. };
  306. #elif IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MTK)
  307. enum booster_res_type {
  308. CPUFREQ = 0,
  309. DDRFREQ,
  310. SCHEDBOOST,
  311. MAX_RES_COUNT
  312. };
  313. #endif
  314. extern int *cpu_cluster_policy;
  315. extern int *allowed_resources;
  316. extern int *release_val;
  317. extern int allowed_res_count;
  318. extern int max_resource_count;
  319. extern int max_cluster_count;
  320. extern int ib_init_succeed;
  321. extern unsigned int debug_flag;
  322. extern unsigned int enable_event_booster;
  323. #if IS_ENABLED(CONFIG_SEC_INPUT_BOOSTER_MODE)
  324. extern unsigned int u_ib_mode;
  325. #endif
  326. extern int trigger_cnt;
  327. // @ ib_trigger : input trigger starts input booster in evdev.c.
  328. extern struct t_ib_trigger *ib_trigger;
  329. // @evdev_mt_slot : save the number of inputed touch slot.
  330. extern int evdev_mt_slot;
  331. // @evdev_mt_event[] : save count of each boooter's events.
  332. extern int evdev_mt_event[MAX_DEVICE_TYPE_NUM];
  333. #endif // _INPUT_BOOSTER_H_