fts.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * FTS Capacitive touch screen controller (FingerTipS)
  4. *
  5. * Copyright (C) 2016-2019, STMicroelectronics Limited.
  6. * Authors: AMG(Analog Mems Group) <[email protected]>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License version 2 as published by
  11. * the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef _LINUX_FTS_I2C_H_
  22. #define _LINUX_FTS_I2C_H_
  23. /*#include <linux/wakelock.h>*/
  24. #include <linux/pm_wakeup.h>
  25. #include <linux/timekeeping.h>
  26. #include <linux/gunyah/gh_irq_lend.h>
  27. #include "fts_lib/ftsSoftware.h"
  28. #include "fts_lib/ftsHardware.h"
  29. #include "fts_lib/ftsGesture.h"
  30. #define FTS_POWER_ON 1
  31. #define FTS_POWER_OFF 0
  32. /****************** CONFIGURATION SECTION ******************/
  33. /**** CODE CONFIGURATION ****/
  34. #define FTS_TS_DRV_NAME "fts"
  35. #define FTS_TS_DRV_VERSION "4.2.14" /* version */
  36. /*#define SCRIPTLESS*/ /*allow to work in scriptless mode with the GUI*/
  37. #ifdef SCRIPTLESS
  38. #define SCRIPTLESS_DEBUG
  39. /**
  40. * uncomment this macro definition to print debug
  41. * message for script less support
  42. */
  43. #endif
  44. #define DRIVER_TEST
  45. /* #define FW_H_FILE */ /*include the FW as header file*/
  46. #ifdef FW_H_FILE
  47. #define FW_SIZE_NAME myArray_size
  48. #define FW_ARRAY_NAME myArray
  49. #endif
  50. /*#define LIMITS_H_FILE*/ /*include the limits file as header file*/
  51. #ifdef LIMITS_H_FILE
  52. #define LIMITS_SIZE_NAME myArray2_size
  53. #define LIMITS_ARRAY_NAME myArray2
  54. #endif
  55. /**** END ****/
  56. /**** FEATURES USED IN THE IC ***/
  57. /* #define PHONE_KEY enable the keys */
  58. #define PHONE_GESTURE /*allow to use the gestures*/
  59. #ifdef PHONE_GESTURE
  60. #define USE_GESTURE_MASK
  61. #define USE_CUSTOM_GESTURES
  62. #endif
  63. #define USE_ONE_FILE_NODE
  64. /*allow to enable/disable all the features just using one file node*/
  65. #define EDGE_REJ
  66. /*allow edge rej feature (comment to disable)*/
  67. #define CORNER_REJ
  68. /*allow corn rej feature (comment to disable)*/
  69. #define EDGE_PALM_REJ
  70. /*allow edge palm rej feature (comment to disable)*/
  71. #define CHARGER_MODE
  72. /*allow charger mode feature (comment to disable)*/
  73. #define GLOVE_MODE
  74. /*allow glove mode feature (comment to disable)*/
  75. #define VR_MODE
  76. /*allow vr mode feature (comment to disable)*/
  77. #define COVER_MODE
  78. /*allow cover mode feature (comment to disable)*/
  79. #define STYLUS_MODE
  80. /*allow stylus mode feature (comment to disable)*/
  81. #define USE_NOISE_PARAM
  82. /*set noise params during resume (comment to disable)*/
  83. /**** END ****/
  84. /**** PANEL SPECIFICATION ****/
  85. #define X_AXIS_MAX 1440
  86. #define X_AXIS_MIN 0
  87. #define Y_AXIS_MAX 2880
  88. #define Y_AXIS_MIN 0
  89. #define PRESSURE_MIN 0
  90. #define PRESSURE_MAX 127
  91. #define TOUCH_ID_MAX 10
  92. #define AREA_MIN PRESSURE_MIN
  93. #define AREA_MAX PRESSURE_MAX
  94. /**** END ****/
  95. /*********************************************************/
  96. /* Flash programming */
  97. #define INIT_FLAG_CNT 3
  98. /* KEYS */
  99. #define KEY1 0x02
  100. #define KEY2 0x01
  101. #define KEY3 0x04
  102. /*
  103. * Configuration mode
  104. */
  105. /**
  106. * bitmask which can assume the value defined as
  107. * features in ftsSoftware.h or the following values
  108. */
  109. #define MODE_NOTHING 0x00000000
  110. #define MODE_SENSEON 0x10000000
  111. #define MODE_SENSEOFF 0x20000000
  112. #define FEAT_GESTURE 0x40000000
  113. /*
  114. * Status Event Field:
  115. * id of command that triggered the event
  116. */
  117. #define FTS_FLASH_WRITE_CONFIG 0x03
  118. #define FTS_FLASH_WRITE_COMP_MEMORY 0x04
  119. #define FTS_FORCE_CAL_SELF_MUTUAL 0x05
  120. #define FTS_FORCE_CAL_SELF 0x06
  121. #define FTS_WATER_MODE_ON 0x07
  122. #define FTS_WATER_MODE_OFF 0x08
  123. #define EXP_FN_WORK_DELAY_MS 1000
  124. #define CMD_STR_LEN 32
  125. #define I2C_DATA_MAX_LEN 32
  126. #ifdef SCRIPTLESS
  127. /*
  128. * I2C Command Read/Write Function
  129. */
  130. #define CMD_RESULT_STR_LEN 2048
  131. #endif
  132. #define TSP_BUF_SIZE 4096
  133. #define PINCTRL_STATE_ACTIVE "pmx_ts_active"
  134. #define PINCTRL_STATE_SUSPEND "pmx_ts_suspend"
  135. #define PINCTRL_STATE_RELEASE "pmx_ts_release"
  136. /*add by guchong*/
  137. #ifdef PHONE_GESTURE
  138. extern u16 gesture_coordinates_x[GESTURE_COORDS_REPORT_MAX];
  139. extern u16 gesture_coordinates_y[GESTURE_COORDS_REPORT_MAX];
  140. extern int gesture_coords_reported;
  141. extern struct mutex gestureMask_mutex;
  142. #endif
  143. struct fts_i2c_platform_data {
  144. bool x_flip;
  145. bool y_flip;
  146. int (*power)(bool on);
  147. int irq_gpio;
  148. int reset_gpio;
  149. const char *pwr_reg_name;
  150. const char *bus_reg_name;
  151. bool pwr_on_suspend;
  152. };
  153. /*
  154. * Forward declaration
  155. */
  156. struct fts_ts_info;
  157. /*
  158. * Dispatch event handler
  159. */
  160. struct event_dispatch_handler_t {
  161. void (*handler)(struct fts_ts_info *info, unsigned char *data);
  162. };
  163. enum trusted_touch_mode_config {
  164. TRUSTED_TOUCH_VM_MODE,
  165. TRUSTED_TOUCH_MODE_NONE
  166. };
  167. #ifdef CONFIG_ST_TRUSTED_TOUCH
  168. #define TRUSTED_TOUCH_MEM_LABEL 0x7
  169. struct trusted_touch_vm_info {
  170. enum gh_irq_label irq_label;
  171. enum gh_vm_names vm_name;
  172. u32 hw_irq;
  173. gh_memparcel_handle_t vm_mem_handle;
  174. u32 *iomem_bases;
  175. u32 *iomem_sizes;
  176. u32 iomem_list_size;
  177. void *mem_cookie;
  178. #ifdef CONFIG_ARCH_QTI_VM
  179. atomic_t tvm_owns_iomem;
  180. atomic_t tvm_owns_irq;
  181. #else
  182. atomic_t pvm_owns_iomem;
  183. atomic_t pvm_owns_irq;
  184. #endif
  185. };
  186. #endif
  187. /*
  188. * struct fts_ts_info - FTS capacitive touch screen device information
  189. * @dev: Pointer to the structure device
  190. * @client: I2C client structure
  191. * @input_dev Input device structure
  192. * @work Work thread
  193. * @event_wq Event queue for work thread
  194. * @event_dispatch_table Event dispatch table handlers
  195. * @attrs SysFS attributes
  196. * @mode Device operating mode (bitmask)
  197. * @touch_id Bitmask for touch id (mapped to input slots)
  198. * @stylus_id Bitmask for tracking the stylus touches
  199. * (mapped using the touchId)
  200. * @timer Timer when operating in polling mode
  201. * @power Power on/off routine
  202. * @bdata HW info retrived from device tree
  203. * @pwr_reg DVDD power regulator
  204. * @bus_reg AVDD power regulator
  205. * @resume_bit Indicate if screen off/on
  206. * @fwupdate_stat Store the result of a fw update triggered by the host
  207. * @notifier Used for be notified from a suspend/resume event
  208. * @notifier_cookie saved cookie during panel event notification
  209. * @sensor_sleep true susped was called, false resume was called
  210. * @wakelock Wake Lock struct
  211. * @input_report_mutex mutex for handling the pressure of keys
  212. * @series of switches to store the enabling status of a particular
  213. * feature from the host
  214. */
  215. struct fts_ts_info {
  216. struct device *dev;
  217. struct i2c_client *client;
  218. struct input_dev *input_dev;
  219. struct work_struct work;
  220. struct work_struct suspend_work;
  221. struct work_struct resume_work;
  222. struct workqueue_struct *event_wq;
  223. struct delayed_work fwu_work;
  224. struct workqueue_struct *fwu_workqueue;
  225. struct completion cmd_done;
  226. struct pinctrl *ts_pinctrl;
  227. struct pinctrl_state *pinctrl_state_active;
  228. struct pinctrl_state *pinctrl_state_suspend;
  229. struct pinctrl_state *pinctrl_state_release;
  230. struct event_dispatch_handler_t *event_dispatch_table;
  231. struct attribute_group attrs;
  232. unsigned int mode;
  233. unsigned long touch_id;
  234. #ifdef STYLUS_MODE
  235. unsigned long stylus_id;
  236. #endif
  237. #ifdef FTS_USE_POLLING_MODE
  238. struct hrtimer timer;
  239. #endif
  240. #ifdef SCRIPTLESS
  241. /*I2C cmd*/
  242. struct device *i2c_cmd_dev;
  243. char cmd_read_result[CMD_RESULT_STR_LEN];
  244. char cmd_wr_result[CMD_RESULT_STR_LEN];
  245. char cmd_write_result[20];
  246. #endif
  247. #ifdef DRIVER_TEST
  248. struct device *test_cmd_dev;
  249. #endif
  250. int (*power)(bool on);
  251. struct fts_i2c_platform_data *bdata;
  252. struct regulator *pwr_reg;
  253. struct regulator *bus_reg;
  254. int resume_bit;
  255. int fwupdate_stat;
  256. struct notifier_block notifier;
  257. void *notifier_cookie;
  258. bool sensor_sleep;
  259. struct wakeup_source *wakeup_source;
  260. /* input lock */
  261. struct mutex input_report_mutex;
  262. /*switches for features*/
  263. unsigned int gesture_enabled;
  264. unsigned int glove_enabled;
  265. unsigned int charger_enabled;
  266. unsigned int stylus_enabled;
  267. unsigned int vr_enabled;
  268. unsigned int cover_enabled;
  269. unsigned int edge_rej_enabled;
  270. unsigned int corner_rej_enabled;
  271. unsigned int edge_palm_rej_enabled;
  272. uint8_t *i2c_data;
  273. uint8_t i2c_data_len;
  274. struct device *aoi_cmd_dev;
  275. bool aoi_notify_enabled;
  276. bool aoi_wake_on_suspend;
  277. /* aoi region */
  278. struct class *aoi_class;
  279. struct device *aoi_dev;
  280. int aoi_left;
  281. int aoi_top;
  282. int aoi_bottom;
  283. int aoi_right;
  284. #ifdef CONFIG_ST_TRUSTED_TOUCH
  285. struct trusted_touch_vm_info *vm_info;
  286. struct mutex fts_clk_io_ctrl_mutex;
  287. const char *touch_environment;
  288. struct completion trusted_touch_powerdown;
  289. struct completion resource_checkpoint;
  290. struct clk *core_clk;
  291. struct clk *iface_clk;
  292. atomic_t trusted_touch_initialized;
  293. atomic_t trusted_touch_enabled;
  294. atomic_t delayed_vm_probe_pending;
  295. atomic_t trusted_touch_mode;
  296. #endif
  297. };
  298. extern struct chipInfo ftsInfo;
  299. int fts_chip_powercycle(struct fts_ts_info *info);
  300. int fts_chip_powercycle2(struct fts_ts_info *info, unsigned long sleep);
  301. void release_all_touches(struct fts_ts_info *info);
  302. /*int fts_get_fw_version(struct fts_ts_info *info);*/
  303. /*extern unsigned int le_to_uint(const unsigned char *ptr);*/
  304. /*extern unsigned int be_to_uint(const unsigned char *ptr);*/
  305. extern int input_register_notifier_client(struct notifier_block *nb);
  306. extern int input_unregister_notifier_client(struct notifier_block *nb);
  307. extern struct attribute_group aoi_cmd_attr_group;
  308. extern struct attribute_group aoi_enable_attr_group;
  309. #ifdef SCRIPTLESS
  310. extern struct attribute_group i2c_cmd_attr_group;
  311. #endif
  312. #ifdef DRIVER_TEST
  313. extern struct attribute_group test_cmd_attr_group;
  314. #endif
  315. #endif