sec_input.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* drivers/input/sec_input/sec_input.h
  3. *
  4. * Core file for Samsung input device driver
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _SEC_INPUT_H_
  11. #define _SEC_INPUT_H_
  12. #if IS_ENABLED(CONFIG_SEC_KUNIT)
  13. #include <kunit/test.h>
  14. #include <kunit/mock.h>
  15. #endif
  16. #include <asm/unaligned.h>
  17. #include <linux/completion.h>
  18. #include <linux/ctype.h>
  19. #include <linux/delay.h>
  20. #include <linux/firmware.h>
  21. #include <linux/fs.h>
  22. #include <linux/gpio.h>
  23. #include <linux/hrtimer.h>
  24. #include <linux/i2c.h>
  25. #include <linux/input.h>
  26. #include <linux/input/mt.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/io.h>
  29. #include <linux/irq.h>
  30. #include <linux/kernel.h>
  31. #include <linux/limits.h>
  32. #include <linux/module.h>
  33. #include <linux/of_gpio.h>
  34. #include <linux/platform_device.h>
  35. #include <linux/regulator/consumer.h>
  36. #include <linux/slab.h>
  37. #include <linux/sysfs.h>
  38. #include <linux/time.h>
  39. #include <linux/uaccess.h>
  40. #include <linux/vmalloc.h>
  41. #include <linux/pm_wakeup.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/power_supply.h>
  44. #include <linux/proc_fs.h>
  45. #include <linux/version.h>
  46. #include <linux/rtc.h>
  47. #if IS_ENABLED(CONFIG_INPUT_SEC_TRUSTED_TOUCH)
  48. #include "sec_trusted_touch.h"
  49. #endif
  50. #if IS_ENABLED(CONFIG_INPUT_SEC_SECURE_TOUCH)
  51. #include "sec_secure_touch.h"
  52. #endif
  53. #define SECURE_TOUCH_ENABLE 1
  54. #define SECURE_TOUCH_DISABLE 0
  55. #if IS_ENABLED(CONFIG_SEC_ABC)
  56. #include <linux/sti/abc_common.h>
  57. #endif
  58. #include <linux/notifier.h>
  59. #if IS_ENABLED(CONFIG_VBUS_NOTIFIER)
  60. #include <linux/vbus_notifier.h>
  61. #if IS_ENABLED(CONFIG_USB_TYPEC_MANAGER_NOTIFIER)
  62. #include <linux/usb/typec/manager/usb_typec_manager_notifier.h>
  63. #endif
  64. #endif
  65. #if (KERNEL_VERSION(5, 14, 0) <= LINUX_VERSION_CODE)
  66. #include <linux/devm-helpers.h>
  67. #define SEC_INPUT_INIT_WORK(dev, work, func) devm_work_autocancel(dev, work, func)
  68. #else
  69. #define SEC_INPUT_INIT_WORK(dev, work, func) INIT_WORK(work, func)
  70. #endif
  71. #include "sec_cmd.h"
  72. #include "sec_tclm_v2.h"
  73. #include "sec_input_multi_dev.h"
  74. #if IS_ENABLED(CONFIG_TOUCHSCREEN_DUMP_MODE)
  75. #include "sec_tsp_dumpkey.h"
  76. #endif
  77. #if (KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE)
  78. #define sec_input_proc_ops(ops_owner, ops_name, read_fn, write_fn) \
  79. const struct proc_ops ops_name = { \
  80. .proc_read = read_fn, \
  81. .proc_write = write_fn, \
  82. .proc_lseek = generic_file_llseek, \
  83. }
  84. #else
  85. #define sec_input_proc_ops(ops_owner, ops_name, read_fn, write_fn) \
  86. const struct file_operations ops_name = { \
  87. .owner = ops_owner, \
  88. .read = read_fn, \
  89. .write = write_fn, \
  90. .llseek = generic_file_llseek, \
  91. }
  92. #endif
  93. /*
  94. * sys/class/sec/tsp/support_feature
  95. * bit value should be made a promise with InputFramework.
  96. */
  97. #define INPUT_FEATURE_ENABLE_SETTINGS_AOT (1 << 0) /* Double tap wakeup settings */
  98. #define INPUT_FEATURE_ENABLE_PRESSURE (1 << 1) /* homekey pressure */
  99. //#define INPUT_FEATURE_ENABLE_SYNC_RR120 (1 << 2) /* UNUSED: sync reportrate 120hz */
  100. #define INPUT_FEATURE_ENABLE_VRR (1 << 3) /* variable refresh rate (support 240hz) */
  101. #define INPUT_FEATURE_SUPPORT_WIRELESS_TX (1 << 4) /* enable call wireless cmd during wireless power sharing */
  102. #define INPUT_FEATURE_ENABLE_SYSINPUT_ENABLED (1 << 5) /* resume/suspend called by system input service */
  103. #define INPUT_FEATURE_ENABLE_PROX_LP_SCAN_ENABLED (1 << 6) /* prox_lp_scan_mode called by system input service */
  104. #define INPUT_FEATURE_SUPPORT_OPEN_SHORT_TEST (1 << 8) /* open/short test support */
  105. #define INPUT_FEATURE_SUPPORT_MIS_CALIBRATION_TEST (1 << 9) /* mis-calibration test support */
  106. #define INPUT_FEATURE_ENABLE_MULTI_CALIBRATION (1 << 10) /* multi calibration support */
  107. #define INPUT_FEATURE_SUPPORT_INPUT_MONITOR (1 << 16) /* input monitor support */
  108. #define INPUT_FEATURE_SUPPORT_MOTION_PALM (1 << 20) /* rawdata motion control: palm */
  109. #define INPUT_FEATURE_SUPPORT_MOTION_AIVF (1 << 21) /* rawdata motion control: aivf */
  110. /*
  111. * sec Log
  112. */
  113. #define SECLOG "[sec_input]"
  114. #define INPUT_LOG_BUF_SIZE 512
  115. #define INPUT_TCLM_LOG_BUF_SIZE 64
  116. #define INPUT_DEBUG_INFO_SIZE 1024
  117. #if IS_ENABLED(CONFIG_SEC_DEBUG_TSP_LOG)
  118. #include "sec_tsp_log.h"
  119. #define input_dbg(mode, dev, fmt, ...) \
  120. ({ \
  121. static char input_log_buf[INPUT_LOG_BUF_SIZE]; \
  122. dev_dbg(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  123. if (mode) { \
  124. if (dev) \
  125. snprintf(input_log_buf, sizeof(input_log_buf), "%s %s %d:%s", \
  126. dev_driver_string(dev), dev_name(dev), \
  127. current->pid, current->comm); \
  128. else \
  129. snprintf(input_log_buf, sizeof(input_log_buf), "NULL %d:%s", \
  130. current->pid, current->comm); \
  131. sec_debug_tsp_log_msg(input_log_buf, fmt, ## __VA_ARGS__); \
  132. } \
  133. })
  134. #define input_info(mode, dev, fmt, ...) \
  135. ({ \
  136. static char input_log_buf[INPUT_LOG_BUF_SIZE]; \
  137. dev_info(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  138. if (mode) { \
  139. if (dev) \
  140. snprintf(input_log_buf, sizeof(input_log_buf), "%s %s %d:%s", \
  141. dev_driver_string(dev), dev_name(dev), \
  142. current->pid, current->comm); \
  143. else \
  144. snprintf(input_log_buf, sizeof(input_log_buf), "NULL %d:%s", \
  145. current->pid, current->comm); \
  146. sec_debug_tsp_log_msg(input_log_buf, fmt, ## __VA_ARGS__); \
  147. } \
  148. })
  149. #define input_err(mode, dev, fmt, ...) \
  150. ({ \
  151. static char input_log_buf[INPUT_LOG_BUF_SIZE]; \
  152. dev_err(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  153. if (mode) { \
  154. if (dev) \
  155. snprintf(input_log_buf, sizeof(input_log_buf), "%s %s %d:%s", \
  156. dev_driver_string(dev), dev_name(dev), \
  157. current->pid, current->comm); \
  158. else \
  159. snprintf(input_log_buf, sizeof(input_log_buf), "NULL %d:%s", \
  160. current->pid, current->comm); \
  161. sec_debug_tsp_log_msg(input_log_buf, fmt, ## __VA_ARGS__); \
  162. } \
  163. })
  164. #define input_fail_hist(mode, dev, fmt, ...) \
  165. ({ \
  166. static char input_log_buf[INPUT_LOG_BUF_SIZE]; \
  167. dev_info(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  168. if (mode) { \
  169. if (dev) \
  170. snprintf(input_log_buf, sizeof(input_log_buf), "%s %s %d:%s", \
  171. dev_driver_string(dev), dev_name(dev), \
  172. current->pid, current->comm); \
  173. else \
  174. snprintf(input_log_buf, sizeof(input_log_buf), "NULL %d:%s", \
  175. current->pid, current->comm); \
  176. sec_debug_tsp_log_msg(input_log_buf, fmt, ## __VA_ARGS__); \
  177. sec_debug_tsp_fail_hist(input_log_buf, fmt, ## __VA_ARGS__); \
  178. } \
  179. })
  180. #define input_raw_info_d(dev_count, dev, fmt, ...) \
  181. ({ \
  182. static char input_log_buf[INPUT_LOG_BUF_SIZE]; \
  183. dev_info(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  184. if (dev) \
  185. snprintf(input_log_buf, sizeof(input_log_buf), "%s %s", \
  186. dev_driver_string(dev), dev_name(dev)); \
  187. else \
  188. snprintf(input_log_buf, sizeof(input_log_buf), "NULL"); \
  189. sec_debug_tsp_log_msg(input_log_buf, fmt, ## __VA_ARGS__); \
  190. sec_debug_tsp_raw_data_msg(dev_count, input_log_buf, fmt, ## __VA_ARGS__); \
  191. })
  192. #define input_raw_info(mode, dev, fmt, ...) \
  193. ({ \
  194. if (mode) { \
  195. input_raw_info_d(0, dev, fmt, ## __VA_ARGS__); \
  196. } else { \
  197. dev_info(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  198. } \
  199. })
  200. #define input_raw_data_clear_by_device(mode) sec_tsp_raw_data_clear(mode)
  201. #define input_raw_data_clear() sec_tsp_raw_data_clear(0)
  202. #define input_log_fix() sec_tsp_log_fix()
  203. #else
  204. #define input_dbg(mode, dev, fmt, ...) \
  205. ({ \
  206. dev_dbg(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  207. })
  208. #define input_info(mode, dev, fmt, ...) \
  209. ({ \
  210. dev_info(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  211. })
  212. #define input_err(mode, dev, fmt, ...) \
  213. ({ \
  214. dev_err(dev, SECLOG " " fmt, ## __VA_ARGS__); \
  215. })
  216. #define input_fail_hist(mode, dev, fmt, ...) input_err(mode, dev, fmt, ## __VA_ARGS__)
  217. #define input_raw_info_d(dev_count, dev, fmt, ...) input_info(true, dev, fmt, ## __VA_ARGS__)
  218. #define input_raw_info(mode, dev, fmt, ...) input_info(mode, dev, fmt, ## __VA_ARGS__)
  219. #define input_log_fix() {}
  220. #define input_raw_data_clear_by_device(mode) {}
  221. #define input_raw_data_clear() {}
  222. #endif
  223. /*
  224. * for input_event_codes.h
  225. */
  226. #define KEY_HOT 252
  227. #define KEY_WAKEUP_UNLOCK 253 /* Wake-up to recent view, ex: AOP */
  228. #define KEY_RECENT 254
  229. #define KEY_WATCH 550 /* Premium watch: 2finger double tap */
  230. #define BTN_PALM 0x118 /* palm flag */
  231. #define BTN_LARGE_PALM 0x119 /* large palm flag */
  232. #define KEY_BLACK_UI_GESTURE 0x1c7
  233. #define KEY_APPSELECT 0x244 /* AL Select Task/Application */
  234. #define KEY_EMERGENCY 0x2a0
  235. #define KEY_INT_CANCEL 0x2be /* for touch event skip */
  236. #define KEY_DEX_ON 0x2bd
  237. #define KEY_WINK 0x2bf /* Intelligence Key */
  238. #define KEY_APPS 0x2c1 /* APPS key */
  239. #define KEY_SIP 0x2c2 /* Sip key */
  240. #define KEY_SETTING 0x2c5 /* Setting */
  241. #define KEY_SFINDER 0x2c6 /* Sfinder key */
  242. #define KEY_SHARE 0x2c9 /* keyboard share */
  243. #define KEY_FN_LOCK 0x2ca /* fn_lock key */
  244. #define KEY_FN_UNLOCK 0x2cb /* fn_unlock key */
  245. #define ABS_MT_CUSTOM 0x3e /* custom event */
  246. #if (KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE)
  247. #define SW_PEN_INSERT 0x0f /* set = pen insert, remove */
  248. #else
  249. #define SW_PEN_INSERT 0x13 /* set = pen insert, remove */
  250. #endif
  251. #define EXYNOS_DISPLAY_INPUT_NOTIFIER ((IS_ENABLED(CONFIG_EXYNOS_DPU30) || IS_ENABLED(CONFIG_DRM_SAMSUNG_DPU)) && IS_ENABLED(CONFIG_PANEL_NOTIFY))
  252. enum grip_write_mode {
  253. G_NONE = 0,
  254. G_SET_EDGE_HANDLER = 1,
  255. G_SET_EDGE_ZONE = 2,
  256. G_SET_NORMAL_MODE = 4,
  257. G_SET_LANDSCAPE_MODE = 8,
  258. G_CLR_LANDSCAPE_MODE = 16,
  259. };
  260. enum grip_set_data {
  261. ONLY_EDGE_HANDLER = 0,
  262. GRIP_ALL_DATA = 1,
  263. };
  264. enum external_noise_mode {
  265. EXT_NOISE_MODE_NONE = 0,
  266. EXT_NOISE_MODE_MONITOR = 1, /* for dex mode */
  267. EXT_NOISE_MODE_MAX, /* add new mode above this line */
  268. };
  269. enum wireless_charger_param {
  270. TYPE_WIRELESS_CHARGER_NONE = 0,
  271. TYPE_WIRELESS_CHARGER = 1,
  272. TYPE_WIRELESS_BATTERY_PACK = 3,
  273. };
  274. enum charger_param {
  275. TYPE_WIRE_CHARGER_NONE = 0,
  276. TYPE_WIRE_CHARGER = 1,
  277. };
  278. enum set_temperature_state {
  279. SEC_INPUT_SET_TEMPERATURE_NORMAL = 0,
  280. SEC_INPUT_SET_TEMPERATURE_IN_IRQ,
  281. SEC_INPUT_SET_TEMPERATURE_FORCE,
  282. };
  283. /* FACTORY TEST RESULT SAVING FUNCTION
  284. * bit 3 ~ 0 : OCTA Assy
  285. * bit 7 ~ 4 : OCTA module
  286. * param[0] : OCTA modue(1) / OCTA Assy(2)
  287. * param[1] : TEST NONE(0) / TEST FAIL(1) / TEST PASS(2) : 2 bit
  288. */
  289. #define TEST_OCTA_MODULE 1
  290. #define TEST_OCTA_ASSAY 2
  291. #define TEST_OCTA_NONE 0
  292. #define TEST_OCTA_FAIL 1
  293. #define TEST_OCTA_PASS 2
  294. /*
  295. * write 0xE4 [ 11 | 10 | 01 | 00 ]
  296. * MSB <-------------------> LSB
  297. * read 0xE4
  298. * mapping sequnce : LSB -> MSB
  299. * struct sec_ts_test_result {
  300. * * assy : front + OCTA assay
  301. * * module : only OCTA
  302. * union {
  303. * struct {
  304. * u8 assy_count:2; -> 00
  305. * u8 assy_result:2; -> 01
  306. * u8 module_count:2; -> 10
  307. * u8 module_result:2; -> 11
  308. * } __attribute__ ((packed));
  309. * unsigned char data[1];
  310. * };
  311. *};
  312. */
  313. struct sec_ts_test_result {
  314. union {
  315. struct {
  316. u8 assy_count:2;
  317. u8 assy_result:2;
  318. u8 module_count:2;
  319. u8 module_result:2;
  320. } __attribute__ ((packed));
  321. unsigned char data[1];
  322. };
  323. };
  324. enum sponge_event_type {
  325. SPONGE_EVENT_TYPE_SPAY = 0x04,
  326. SPONGE_EVENT_TYPE_SINGLE_TAP = 0x08,
  327. SPONGE_EVENT_TYPE_AOD_PRESS = 0x09,
  328. SPONGE_EVENT_TYPE_AOD_LONGPRESS = 0x0A,
  329. SPONGE_EVENT_TYPE_AOD_DOUBLETAB = 0x0B,
  330. SPONGE_EVENT_TYPE_AOD_HOMEKEY_PRESS = 0x0C,
  331. SPONGE_EVENT_TYPE_AOD_HOMEKEY_RELEASE = 0x0D,
  332. SPONGE_EVENT_TYPE_AOD_HOMEKEY_RELEASE_NO_HAPTIC = 0x0E,
  333. SPONGE_EVENT_TYPE_FOD_PRESS = 0x0F,
  334. SPONGE_EVENT_TYPE_FOD_RELEASE = 0x10,
  335. SPONGE_EVENT_TYPE_FOD_OUT = 0x11,
  336. SPONGE_EVENT_TYPE_LONG_PRESS = 0x12,
  337. SPONGE_EVENT_TYPE_TSP_SCAN_UNBLOCK = 0xE1,
  338. SPONGE_EVENT_TYPE_TSP_SCAN_BLOCK = 0xE2,
  339. };
  340. enum proximity_event_type {
  341. PROX_EVENT_TYPE_NP_FAR = 0,
  342. PROX_EVENT_TYPE_NP_SENSITIVE_CLOSE = 1,
  343. PROX_EVENT_TYPE_NP_ENOUGH_CLOSE = 2,
  344. PROX_EVENT_TYPE_NP_STRONG_CLOSE = 3,
  345. PROX_EVENT_TYPE_LP_CLOSE = 4,
  346. PROX_EVENT_TYPE_LP_FAR = 5,
  347. PROX_EVENT_TYPE_POCKET_RELEASE = 10,
  348. PROX_EVENT_TYPE_POCKET_PRESS = 11,
  349. PROX_EVENT_TYPE_LIGHTSENSOR_RELEASE = 20,
  350. PROX_EVENT_TYPE_LIGHTSENSOR_PRESS = 21,
  351. };
  352. /* SEC_TS_DEBUG : Print event contents */
  353. #define SEC_TS_DEBUG_PRINT_ALLEVENT 0x01
  354. #define SEC_TS_DEBUG_PRINT_ONEEVENT 0x02
  355. #define SEC_TS_DEBUG_PRINT_READ_CMD 0x04
  356. #define SEC_TS_DEBUG_PRINT_WRITE_CMD 0x08
  357. #define CMD_RESULT_WORD_LEN 10
  358. #define SEC_TS_I2C_RETRY_CNT 3
  359. #define SEC_TS_WAIT_RETRY_CNT 100
  360. #define SEC_TS_LOCATION_DETECT_SIZE 6
  361. #define SEC_TS_SUPPORT_TOUCH_COUNT 10
  362. #define SEC_TS_GESTURE_REPORT_BUFF_SIZE 20
  363. /* SPONGE MODE 0x00 */
  364. #define SEC_TS_MODE_SPONGE_SWIPE (1 << 1)
  365. #define SEC_TS_MODE_SPONGE_AOD (1 << 2)
  366. #define SEC_TS_MODE_SPONGE_SINGLE_TAP (1 << 3)
  367. #define SEC_TS_MODE_SPONGE_PRESS (1 << 4)
  368. #define SEC_TS_MODE_SPONGE_DOUBLETAP_TO_WAKEUP (1 << 5)
  369. #define SEC_TS_MODE_SPONGE_TWO_FINGER_DOUBLETAP (1 << 7)
  370. #define SEC_TS_MODE_SPONGE_VVC (1 << 8)
  371. /* SPONGE MODE 0x01 */
  372. #define SEC_TS_MODE_SPONGE_INF_DUMP_CLEAR (1 << 0)
  373. #define SEC_TS_MODE_SPONGE_INF_DUMP (1 << 1)
  374. /*SPONGE library parameters*/
  375. #define SEC_TS_MAX_SPONGE_DUMP_BUFFER 512
  376. #define SEC_TS_SPONGE_DUMP_EVENT_MASK 0x7F
  377. #define SEC_TS_SPONGE_DUMP_INF_MASK 0x80
  378. #define SEC_TS_SPONGE_DUMP_INF_SHIFT 7
  379. /* SEC_TS SPONGE OPCODE COMMAND */
  380. #define SEC_TS_CMD_SPONGE_DUMP_FLUSH 0x01
  381. #define SEC_TS_CMD_SPONGE_AOD_ACTIVE_INFO 0x0A
  382. #define SEC_TS_CMD_SPONGE_OFFSET_UTC 0x10
  383. #define SEC_TS_CMD_SPONGE_PRESS_PROPERTY 0x14
  384. #define SEC_TS_CMD_SPONGE_FOD_INFO 0x15
  385. #define SEC_TS_CMD_SPONGE_FOD_POSITION 0x19
  386. #define SEC_TS_CMD_SPONGE_GET_INFO 0x90
  387. #define SEC_TS_CMD_SPONGE_WRITE_PARAM 0x91
  388. #define SEC_TS_CMD_SPONGE_READ_PARAM 0x92
  389. #define SEC_TS_CMD_SPONGE_NOTIFY_PACKET 0x93
  390. #define SEC_TS_CMD_SPONGE_LP_DUMP 0xF0
  391. #define SEC_TS_CMD_SPONGE_LP_DUMP_CUR_IDX 0xF2
  392. #define SEC_TS_CMD_SPONGE_LP_DUMP_EVENT 0xF4
  393. #define SEC_INPUT_DEFAULT_AVDD_NAME "tsp_avdd_ldo"
  394. #define SEC_INPUT_DEFAULT_DVDD_NAME "tsp_io_ldo"
  395. #define SEC_TS_MAX_FW_PATH 64
  396. #define TSP_EXTERNAL_FW "tsp.bin"
  397. #define TSP_EXTERNAL_FW_SIGNED "tsp_signed.bin"
  398. #define TSP_SPU_FW_SIGNED "/TSP/ffu_tsp.bin"
  399. enum fw_version_index {
  400. SEC_INPUT_FW_IC_VER = 0,
  401. SEC_INPUT_FW_VER_PROJECT_ID,
  402. SEC_INPUT_FW_MODULE_VER,
  403. SEC_INPUT_FW_VER,
  404. SEC_INPUT_FW_INDEX_MAX,
  405. };
  406. #if IS_ENABLED(CONFIG_SEC_ABC)
  407. #define SEC_ABC_SEND_EVENT_TYPE "MODULE=tsp@WARN=tsp_int_fault"
  408. #define SEC_ABC_SEND_EVENT_TYPE_SUB "MODULE=tsp_sub@WARN=tsp_int_fault"
  409. #define SEC_ABC_SEND_EVENT_TYPE_WACOM_DIGITIZER_NOT_CONNECTED "MODULE=wacom@WARN=digitizer_not_connected"
  410. #endif
  411. enum display_state {
  412. DISPLAY_STATE_SERVICE_SHUTDOWN = -1,
  413. DISPLAY_STATE_NONE = 0,
  414. DISPLAY_STATE_OFF,
  415. DISPLAY_STATE_ON,
  416. DISPLAY_STATE_DOZE,
  417. DISPLAY_STATE_DOZE_SUSPEND,
  418. DISPLAY_STATE_LPM_OFF = 20,
  419. DISPLAY_STATE_FORCE_OFF,
  420. DISPLAY_STATE_FORCE_ON,
  421. };
  422. enum display_event {
  423. DISPLAY_EVENT_EARLY = 0,
  424. DISPLAY_EVENT_LATE,
  425. };
  426. /*If you want to add mode, please check "MODE_TO_CHECK_BIT" as well.*/
  427. enum power_mode {
  428. SEC_INPUT_STATE_POWER_OFF = 0,
  429. SEC_INPUT_STATE_LPM,
  430. SEC_INPUT_STATE_POWER_ON
  431. };
  432. #define CHECK_POWEROFF (1 << SEC_INPUT_STATE_POWER_OFF)
  433. #define CHECK_LPMODE (1 << SEC_INPUT_STATE_LPM)
  434. #define CHECK_POWERON (1 << SEC_INPUT_STATE_POWER_ON)
  435. #define CHECK_ON_LP (CHECK_POWERON | CHECK_LPMODE)
  436. #define CHECK_ALL (CHECK_POWERON | CHECK_LPMODE | CHECK_POWEROFF)
  437. #define MODE_TO_CHECK_BIT(x) (1 << x)
  438. enum switch_system_mode {
  439. TO_TOUCH_MODE = 0,
  440. TO_LOWPOWER_MODE = 1,
  441. };
  442. enum sec_ts_cover_id {
  443. SEC_TS_FLIP_COVER = 0,
  444. SEC_TS_SVIEW_COVER,
  445. SEC_TS_NONE,
  446. SEC_TS_SVIEW_CHARGER_COVER,
  447. SEC_TS_HEALTH_COVER,
  448. SEC_TS_S_CHARGER_COVER,
  449. SEC_TS_S_VIEW_WALLET_COVER,
  450. SEC_TS_LED_COVER,
  451. SEC_TS_CLEAR_COVER,
  452. SEC_TS_KEYBOARD_KOR_COVER,
  453. SEC_TS_KEYBOARD_US_COVER = 10,
  454. SEC_TS_NEON_COVER,
  455. SEC_TS_ALCANTARA_COVER,
  456. SEC_TS_GAMEPACK_COVER,
  457. SEC_TS_LED_BACK_COVER,
  458. SEC_TS_CLEAR_SIDE_VIEW_COVER,
  459. SEC_TS_MINI_SVIEW_WALLET_COVER,
  460. SEC_TS_CLEAR_CAMERA_VIEW_COVER,
  461. SEC_TS_MONTBLANC_COVER = 100,
  462. SEC_TS_NFC_SMART_COVER = 255,
  463. };
  464. #define TEST_MODE_MIN_MAX false
  465. #define TEST_MODE_ALL_NODE true
  466. #define TEST_MODE_READ_FRAME false
  467. #define TEST_MODE_READ_CHANNEL true
  468. enum offset_fac_position {
  469. OFFSET_FAC_NOSAVE = 0, // FW index 0
  470. OFFSET_FAC_SUB = 1, // FW Index 2
  471. OFFSET_FAC_MAIN = 2, // FW Index 3
  472. OFFSET_FAC_SVC = 3, // FW Index 4
  473. };
  474. enum offset_fw_position {
  475. OFFSET_FW_NOSAVE = 0,
  476. OFFSET_FW_SDC = 1,
  477. OFFSET_FW_SUB = 2,
  478. OFFSET_FW_MAIN = 3,
  479. OFFSET_FW_SVC = 4,
  480. };
  481. enum offset_fac_data_type {
  482. OFFSET_FAC_DATA_NO = 0,
  483. OFFSET_FAC_DATA_CM = 1,
  484. OFFSET_FAC_DATA_CM2 = 2,
  485. OFFSET_FAC_DATA_CM3 = 3,
  486. OFFSET_FAC_DATA_MISCAL = 5,
  487. OFFSET_FAC_DATA_SELF_FAIL = 7,
  488. };
  489. enum sec_input_notify_t {
  490. NOTIFIER_NOTHING = 0,
  491. NOTIFIER_MAIN_TOUCH_ON,
  492. NOTIFIER_MAIN_TOUCH_OFF,
  493. NOTIFIER_SUB_TOUCH_ON,
  494. NOTIFIER_SUB_TOUCH_OFF,
  495. NOTIFIER_SECURE_TOUCH_ENABLE, /* secure touch is enabled */
  496. NOTIFIER_SECURE_TOUCH_DISABLE, /* secure touch is disabled */
  497. NOTIFIER_TSP_BLOCKING_REQUEST, /* wacom called tsp block enable */
  498. NOTIFIER_TSP_BLOCKING_RELEASE, /* wacom called tsp block disable */
  499. NOTIFIER_WACOM_PEN_CHARGING_FINISHED, /* to tsp: pen charging finished */
  500. NOTIFIER_WACOM_PEN_CHARGING_STARTED, /* to tsp: pen charging started */
  501. NOTIFIER_WACOM_PEN_INSERT, /* to tsp: pen is inserted */
  502. NOTIFIER_WACOM_PEN_REMOVE, /* to tsp: pen is removed */
  503. NOTIFIER_WACOM_PEN_HOVER_IN, /* to tsp: pen hover is in */
  504. NOTIFIER_WACOM_PEN_HOVER_OUT, /* to tsp: pen hover is out */
  505. NOTIFIER_LCD_VRR_LFD_LOCK_REQUEST, /* to LCD: set LFD min lock */
  506. NOTIFIER_LCD_VRR_LFD_LOCK_RELEASE, /* to LCD: unset LFD min lock */
  507. NOTIFIER_LCD_VRR_LFD_OFF_REQUEST, /* to LCD: set LFD OFF */
  508. NOTIFIER_LCD_VRR_LFD_OFF_RELEASE, /* to LCD: unset LFD OFF */
  509. NOTIFIER_TSP_ESD_INTERRUPT,
  510. NOTIFIER_WACOM_SAVING_MODE_ON, /* to tsp: multi spen enable cmd on */
  511. NOTIFIER_WACOM_SAVING_MODE_OFF, /* to tsp: multi spen enable cmd off */
  512. NOTIFIER_WACOM_KEYBOARDCOVER_FLIP_OPEN,
  513. NOTIFIER_WACOM_KEYBOARDCOVER_FLIP_CLOSE,
  514. NOTIFIER_VALUE_MAX,
  515. };
  516. enum notify_set_scan_mode {
  517. DISABLE_TSP_SCAN_BLOCK = 0,
  518. ENABLE_TSP_SCAN_BLOCK = 1,
  519. ENABLE_SPEN_CHARGING_MODE = 2,
  520. DISABLE_SPEN_CHARGING_MODE = 3,
  521. ENABLE_SPEN_IN = 4,
  522. ENABLE_SPEN_OUT = 5,
  523. };
  524. enum coord_action {
  525. SEC_TS_COORDINATE_ACTION_NONE = 0,
  526. SEC_TS_COORDINATE_ACTION_PRESS = 1,
  527. SEC_TS_COORDINATE_ACTION_MOVE = 2,
  528. SEC_TS_COORDINATE_ACTION_RELEASE = 3,
  529. SEC_TS_COORDINATE_ACTION_FORCE_RELEASE = 4,
  530. };
  531. #define SEC_TS_LFD_CTRL_LOCK_TIME 500 /* msec */
  532. #define SEC_TS_WAKE_LOCK_TIME 500 /* msec */
  533. enum lfd_lock_ctrl {
  534. SEC_TS_LFD_CTRL_LOCK = 0,
  535. SEC_TS_LFD_CTRL_UNLOCK,
  536. };
  537. enum notify_tsp_type {
  538. MAIN_TOUCHSCREEN = 0,
  539. SUB_TOUCHSCREEN,
  540. };
  541. enum sec_ts_error {
  542. SEC_SKIP = 1,
  543. SEC_SUCCESS = 0,
  544. SEC_ERROR = -1,
  545. };
  546. struct sec_input_grip_data {
  547. u8 edgehandler_direction;
  548. int edgehandler_start_y;
  549. int edgehandler_end_y;
  550. u16 edge_range;
  551. u8 deadzone_up_x;
  552. u8 deadzone_dn_x;
  553. int deadzone_y;
  554. u8 deadzone_dn2_x;
  555. int deadzone_dn_y;
  556. u8 landscape_mode;
  557. int landscape_edge;
  558. u16 landscape_deadzone;
  559. u16 landscape_top_deadzone;
  560. u16 landscape_bottom_deadzone;
  561. u16 landscape_top_gripzone;
  562. u16 landscape_bottom_gripzone;
  563. };
  564. struct sec_input_notify_data {
  565. u8 dual_policy;
  566. };
  567. struct sec_ts_coordinate {
  568. u8 id;
  569. u8 ttype;
  570. u8 action;
  571. u16 x;
  572. u16 y;
  573. u16 p_x;
  574. u16 p_y;
  575. u8 z;
  576. u8 hover_flag;
  577. u8 glove_flag;
  578. u8 touch_height;
  579. u16 mcount;
  580. u8 major;
  581. u8 minor;
  582. bool palm;
  583. int palm_count;
  584. u8 left_event;
  585. u8 noise_level;
  586. u8 max_strength;
  587. u8 hover_id_num;
  588. u8 noise_status;
  589. u8 freq_id;
  590. u8 fod_debug;
  591. };
  592. struct sec_ts_aod_data {
  593. u16 rect_data[4];
  594. u16 active_area[3];
  595. };
  596. struct sec_ts_fod_data {
  597. bool set_val;
  598. u16 rect_data[4];
  599. u8 vi_x;
  600. u8 vi_y;
  601. u8 vi_size;
  602. u8 vi_data[SEC_CMD_STR_LEN];
  603. u8 vi_event;
  604. u8 press_prop;
  605. };
  606. enum sec_ts_fod_vi_method {
  607. CMD_SYSFS = 0,
  608. CMD_IRQ = 1,
  609. };
  610. #define SEC_INPUT_HW_PARAM_SIZE 512
  611. struct sec_ts_hw_param_data {
  612. unsigned char ito_test[4];
  613. bool check_multi;
  614. unsigned int multi_count;
  615. unsigned int wet_count;
  616. unsigned int noise_count;
  617. unsigned int comm_err_count;
  618. unsigned int checksum_result;
  619. unsigned int all_finger_count;
  620. unsigned int all_aod_tap_count;
  621. unsigned int all_spay_count;
  622. int mode_change_failed_count;
  623. int ic_reset_count;
  624. };
  625. struct sec_ts_plat_data {
  626. struct device *dev;
  627. struct input_dev *input_dev;
  628. struct input_dev *input_dev_pad;
  629. struct input_dev *input_dev_proximity;
  630. struct sec_input_multi_device *multi_dev;
  631. struct sec_cmd_data *sec;
  632. int max_x;
  633. int max_y;
  634. int x_node_num;
  635. int y_node_num;
  636. unsigned int irq_gpio;
  637. u32 irq_flag;
  638. int gpio_spi_cs;
  639. int i2c_burstmax;
  640. int bringup;
  641. u32 area_indicator;
  642. u32 area_navigation;
  643. u32 area_edge;
  644. char location[SEC_TS_LOCATION_DETECT_SIZE];
  645. u8 prox_power_off;
  646. bool power_enabled;
  647. struct sec_ts_coordinate coord[SEC_TS_SUPPORT_TOUCH_COUNT];
  648. struct sec_ts_coordinate prev_coord[SEC_TS_SUPPORT_TOUCH_COUNT];
  649. bool fill_slot;
  650. int touch_count;
  651. unsigned int palm_flag;
  652. bool blocking_palm;
  653. atomic_t touch_noise_status;
  654. atomic_t touch_pre_noise_status;
  655. int gesture_id;
  656. int gesture_x;
  657. int gesture_y;
  658. struct sec_ts_fod_data fod_data;
  659. struct sec_ts_aod_data aod_data;
  660. const char *firmware_name;
  661. struct regulator *dvdd;
  662. struct regulator *avdd;
  663. char ic_vendor_name[3];
  664. u8 img_version_of_ic[SEC_INPUT_FW_INDEX_MAX];
  665. u8 img_version_of_bin[SEC_INPUT_FW_INDEX_MAX];
  666. struct pinctrl *pinctrl;
  667. int (*pinctrl_configure)(struct device *dev, bool on);
  668. int (*power)(struct device *dev, bool on);
  669. int (*start_device)(void *data);
  670. int (*stop_device)(void *data);
  671. int (*lpmode)(void *data, u8 mode);
  672. void (*init)(void *data);
  673. int (*stui_tsp_enter)(void);
  674. int (*stui_tsp_exit)(void);
  675. int (*stui_tsp_type)(void);
  676. int (*probe)(struct device *dev);
  677. int (*enable)(struct device *dev);
  678. int (*disable)(struct device *dev);
  679. struct mutex enable_mutex;
  680. union power_supply_propval psy_value;
  681. struct power_supply *psy;
  682. u8 tsp_temperature_data;
  683. bool tsp_temperature_data_skip;
  684. int (*set_temperature)(struct device *dev, u8 temperature_data);
  685. struct sec_input_grip_data grip_data;
  686. void (*set_grip_data)(struct device *dev, u8 flag);
  687. atomic_t enabled;
  688. atomic_t power_state;
  689. atomic_t shutdown_called;
  690. u16 touch_functions;
  691. u16 ic_status;
  692. u8 lowpower_mode;
  693. u8 sponge_mode;
  694. u8 external_noise_mode;
  695. u8 touchable_area;
  696. u8 ed_enable;
  697. u8 pocket_mode;
  698. u8 lightsensor_detect;
  699. u8 fod_lp_mode;
  700. int cover_type;
  701. u8 wirelesscharger_mode;
  702. bool force_wirelesscharger_mode;
  703. int wet_mode;
  704. int noise_mode; /* for debug app */
  705. int freq_id; /* for debug app */
  706. int low_sensitivity_mode;
  707. bool regulator_boot_on;
  708. bool support_dex;
  709. bool support_ear_detect;
  710. atomic_t secure_enabled;
  711. atomic_t secure_pending_irqs;
  712. struct completion secure_powerdown;
  713. struct completion secure_interrupt;
  714. int ss_touch_num;
  715. #if IS_ENABLED(CONFIG_INPUT_SEC_TRUSTED_TOUCH)
  716. struct sec_trusted_touch *pvm;
  717. #endif
  718. #define SEC_INPUT_IRQ_ENABLE 0
  719. #define SEC_INPUT_IRQ_DISABLE 1
  720. #define SEC_INPUT_IRQ_DISABLE_NOSYNC 2
  721. int irq;
  722. atomic_t irq_enabled;
  723. struct mutex irq_lock;
  724. struct device *bus_master;
  725. bool support_fod;
  726. bool support_fod_lp_mode;
  727. bool enable_settings_aot;
  728. bool support_refresh_rate_mode;
  729. bool support_vrr;
  730. bool support_open_short_test;
  731. bool support_mis_calibration_test;
  732. bool support_wireless_tx;
  733. bool support_lightsensor_detect;
  734. bool support_input_monitor;
  735. int support_sensor_hall;
  736. int support_rawdata_map_num;
  737. int dump_ic_ver;
  738. bool disable_vsync_scan;
  739. bool chip_on_board;
  740. bool enable_sysinput_enabled;
  741. bool support_rawdata;
  742. bool support_rawdata_motion_aivf;
  743. bool support_rawdata_motion_palm;
  744. bool not_support_io_ldo;
  745. bool not_support_vdd;
  746. bool sense_off_when_cover_closed;
  747. bool not_support_temp_noti;
  748. bool support_vbus_notifier;
  749. bool support_gesture_uevent;
  750. bool support_always_on;
  751. bool prox_lp_scan_enabled;
  752. int always_lpm;
  753. bool work_queue_probe_enabled;
  754. bool first_booting_disabled;
  755. int work_queue_probe_delay;
  756. struct work_struct probe_work;
  757. struct workqueue_struct *probe_workqueue;
  758. struct work_struct irq_work;
  759. struct workqueue_struct *irq_workqueue;
  760. struct completion resume_done;
  761. struct wakeup_source *sec_ws;
  762. struct sec_ts_hw_param_data hw_param;
  763. struct delayed_work interrupt_notify_work;
  764. int (*set_charger_mode)(struct device *dev, bool on);
  765. bool charger_flag;
  766. struct work_struct vbus_notifier_work;
  767. struct workqueue_struct *vbus_notifier_workqueue;
  768. struct notifier_block vbus_nb;
  769. struct notifier_block ccic_nb;
  770. bool otg_flag;
  771. u32 print_info_cnt_release;
  772. u32 print_info_cnt_open;
  773. };
  774. struct sec_ts_secure_data {
  775. int (*stui_tsp_enter)(void);
  776. int (*stui_tsp_exit)(void);
  777. int (*stui_tsp_type)(void);
  778. };
  779. #ifdef TCLM_CONCEPT
  780. int sec_tclm_data_read(struct i2c_client *client, int address);
  781. int sec_tclm_data_write(struct i2c_client *client, int address);
  782. int sec_tclm_execute_force_calibration(struct i2c_client *client, int cal_mode);
  783. #endif
  784. #if IS_ENABLED(CONFIG_DISPLAY_SAMSUNG)
  785. extern int get_lcd_attached(char *mode);
  786. #endif
  787. #if IS_ENABLED(CONFIG_EXYNOS_DPU30) || IS_ENABLED(CONFIG_MCD_PANEL) || IS_ENABLED(CONFIG_USDM_PANEL)
  788. extern int get_lcd_info(char *arg);
  789. #endif
  790. #if IS_ENABLED(CONFIG_SMCDSD_PANEL)
  791. extern unsigned int lcdtype;
  792. #endif
  793. void sec_input_utc_marker(struct device *dev, const char *annotation);
  794. bool sec_input_cmp_ic_status(struct device *dev, int check_bit);
  795. bool sec_input_need_ic_off(struct sec_ts_plat_data *pdata);
  796. bool sec_check_secure_trusted_mode_status(struct sec_ts_plat_data *pdata);
  797. int sec_input_get_lcd_id(struct device *dev);
  798. void sec_input_probe_work_remove(struct sec_ts_plat_data *pdata);
  799. int sec_input_handler_start(struct device *dev);
  800. void sec_delay(unsigned int ms);
  801. int sec_input_set_temperature(struct device *dev, int state);
  802. void sec_input_set_grip_type(struct device *dev, u8 set_type);
  803. int sec_input_store_grip_data(struct device *dev, int *cmd_param);
  804. int sec_input_check_cover_type(struct device *dev);
  805. void sec_input_set_fod_info(struct device *dev, int vi_x, int vi_y, int vi_size, int vi_event);
  806. ssize_t sec_input_get_fod_info(struct device *dev, char *buf);
  807. bool sec_input_set_fod_rect(struct device *dev, int *rect_data);
  808. int sec_input_check_wirelesscharger_mode(struct device *dev, int mode, int force);
  809. ssize_t sec_input_get_common_hw_param(struct sec_ts_plat_data *pdata, char *buf);
  810. void sec_input_clear_common_hw_param(struct sec_ts_plat_data *pdata);
  811. void sec_input_print_info(struct device *dev, struct sec_tclm_data *tdata);
  812. void sec_input_proximity_report(struct device *dev, int data);
  813. void sec_input_gesture_report(struct device *dev, int id, int x, int y);
  814. void sec_input_coord_event_fill_slot(struct device *dev, int t_id);
  815. void sec_input_coord_event_sync_slot(struct device *dev);
  816. void sec_input_release_all_finger(struct device *dev);
  817. int sec_input_device_register(struct device *dev, void *data);
  818. void sec_tclm_parse_dt(struct device *dev, struct sec_tclm_data *tdata);
  819. int sec_input_parse_dt(struct device *dev);
  820. int sec_input_multi_device_parse_dt(struct device *dev);
  821. void sec_input_support_feature_parse_dt(struct device *dev);
  822. int sec_input_check_fw_name_incell(struct device *dev, const char **firmware_name, const char **firmware_name_mp);
  823. int sec_input_pinctrl_configure(struct device *dev, bool on);
  824. int sec_input_power(struct device *dev, bool on);
  825. void sec_input_register_vbus_notifier(struct device *dev);
  826. void sec_input_unregister_vbus_notifier(struct device *dev);
  827. void sec_input_register_notify(struct notifier_block *nb, notifier_fn_t notifier_call, int priority);
  828. void sec_input_unregister_notify(struct notifier_block *nb);
  829. int sec_input_notify(struct notifier_block *nb, unsigned long noti, void *v);
  830. int sec_input_self_request_notify(struct notifier_block *nb);
  831. int sec_input_enable_device(struct device *dev);
  832. int sec_input_disable_device(struct device *dev);
  833. void stui_tsp_init(int (*stui_tsp_enter)(void), int (*stui_tsp_exit)(void), int (*stui_tsp_type)(void));
  834. int stui_tsp_enter(void);
  835. int stui_tsp_exit(void);
  836. int stui_tsp_type(void);
  837. void sec_input_forced_enable_irq(int irq);
  838. #endif