xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/focaltech_touch_ft5436/focaltech_core.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * FocalTech TouchScreen driver.
4  *
5  * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved.
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  */
17 /*****************************************************************************
18 *
19 * File Name: focaltech_core.h
20 
21 * Author: Focaltech Driver Team
22 *
23 * Created: 2016-08-08
24 *
25 * Abstract:
26 *
27 * Reference:
28 *
29 *****************************************************************************/
30 
31 #ifndef __LINUX_FOCALTECH_CORE_H__
32 #define __LINUX_FOCALTECH_CORE_H__
33 /*****************************************************************************
34 * Included header files
35 *****************************************************************************/
36 #include <linux/kernel.h>
37 #include <linux/device.h>
38 #include <linux/i2c.h>
39 #include <linux/spi/spi.h>
40 #include <linux/input.h>
41 #include <linux/input/mt.h>
42 #include <linux/interrupt.h>
43 #include <linux/irq.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <linux/vmalloc.h>
47 #include <linux/gpio.h>
48 #include <linux/regulator/consumer.h>
49 #include <linux/uaccess.h>
50 #include <linux/firmware.h>
51 #include <linux/debugfs.h>
52 #include <linux/mutex.h>
53 #include <linux/workqueue.h>
54 #include <linux/wait.h>
55 #include <linux/time.h>
56 #include <linux/jiffies.h>
57 #include <linux/fs.h>
58 #include <linux/proc_fs.h>
59 #include <linux/version.h>
60 #include <linux/types.h>
61 #include <linux/sched.h>
62 #include <linux/kthread.h>
63 #include <linux/dma-mapping.h>
64 #include "focaltech_common.h"
65 #include "../tp_suspend.h"
66 
67 /*****************************************************************************
68 * Private constant and macro definitions using #define
69 *****************************************************************************/
70 #define FTS_MAX_POINTS_SUPPORT              10 /* constant value, can't be changed */
71 #define FTS_MAX_KEYS                        4
72 #define FTS_KEY_DIM                         10
73 #define FTS_ONE_TCH_LEN                     6
74 #define FTS_TOUCH_DATA_LEN  (FTS_MAX_POINTS_SUPPORT * FTS_ONE_TCH_LEN + 3)
75 
76 #define FTS_GESTURE_POINTS_MAX              6
77 #define FTS_GESTURE_DATA_LEN               (FTS_GESTURE_POINTS_MAX * 4 + 4)
78 
79 #define FTS_MAX_ID                          0x0A
80 #define FTS_TOUCH_X_H_POS                   3
81 #define FTS_TOUCH_X_L_POS                   4
82 #define FTS_TOUCH_Y_H_POS                   5
83 #define FTS_TOUCH_Y_L_POS                   6
84 #define FTS_TOUCH_PRE_POS                   7
85 #define FTS_TOUCH_AREA_POS                  8
86 #define FTS_TOUCH_POINT_NUM                 2
87 #define FTS_TOUCH_EVENT_POS                 3
88 #define FTS_TOUCH_ID_POS                    5
89 #define FTS_COORDS_ARR_SIZE                 4
90 #define FTS_X_MIN_DISPLAY_DEFAULT           0
91 #define FTS_Y_MIN_DISPLAY_DEFAULT           0
92 #define FTS_X_MAX_DISPLAY_DEFAULT           720
93 #define FTS_Y_MAX_DISPLAY_DEFAULT           1280
94 
95 #define FTS_TOUCH_DOWN                      0
96 #define FTS_TOUCH_UP                        1
97 #define FTS_TOUCH_CONTACT                   2
98 #define EVENT_DOWN(flag)                    ((FTS_TOUCH_DOWN == flag) || (FTS_TOUCH_CONTACT == flag))
99 #define EVENT_UP(flag)                      (FTS_TOUCH_UP == flag)
100 #define EVENT_NO_DOWN(data)                 (!data->point_num)
101 
102 #define FTX_MAX_COMPATIBLE_TYPE             4
103 #define FTX_MAX_COMMMAND_LENGTH             16
104 
105 
106 /*****************************************************************************
107 * Private enumerations, structures and unions using typedef
108 *****************************************************************************/
109 struct ftxxxx_proc {
110     struct proc_dir_entry *proc_entry;
111     u8 opmode;
112     u8 cmd_len;
113     u8 cmd[FTX_MAX_COMMMAND_LENGTH];
114 };
115 
116 struct fts_ts_platform_data {
117     int irq_gpio;
118     u32 irq_gpio_flags;
119     int reset_gpio;
120     u32 reset_gpio_flags;
121     int pwr_gpio;
122     u32 pwr_gpio_flags;
123     bool have_key;
124     u32 key_number;
125     u32 keys[FTS_MAX_KEYS];
126     u32 key_y_coords[FTS_MAX_KEYS];
127     u32 key_x_coords[FTS_MAX_KEYS];
128     u32 x_max;
129     u32 y_max;
130     u32 x_min;
131     u32 y_min;
132     u32 max_touch_number;
133 };
134 
135 struct ts_event {
136     int x;      /*x coordinate */
137     int y;      /*y coordinate */
138     int p;      /* pressure */
139     int flag;   /* touch event flag: 0 -- down; 1-- up; 2 -- contact */
140     int id;     /*touch ID */
141     int area;
142 };
143 
144 struct fts_ts_data {
145     struct i2c_client *client;
146     struct spi_device *spi;
147     struct device *dev;
148     struct input_dev *input_dev;
149     struct fts_ts_platform_data *pdata;
150     struct ts_ic_info ic_info;
151     struct workqueue_struct *ts_workqueue;
152     struct work_struct fwupg_work;
153     struct delayed_work esdcheck_work;
154     struct delayed_work prc_work;
155     struct work_struct resume_work;
156     struct ftxxxx_proc proc;
157     spinlock_t irq_lock;
158     struct mutex report_mutex;
159     struct mutex bus_lock;
160     int irq;
161     int log_level;
162     int fw_is_running;      /* confirm fw is running when using spi:default 0 */
163     int dummy_byte;
164     bool suspended;
165     bool fw_loading;
166     bool irq_disabled;
167     bool power_disabled;
168     bool glove_mode;
169     bool cover_mode;
170     bool charger_mode;
171     bool gesture_mode;      /* gesture enable or disable, default: disable */
172     /* multi-touch */
173     struct ts_event *events;
174     u8 *bus_tx_buf;
175     u8 *bus_rx_buf;
176     u8 *point_buf;
177     int pnt_buf_size;
178     int touchs;
179     int key_state;
180     int touch_point;
181     int point_num;
182     struct regulator *vdd;
183     struct regulator *vcc_i2c;
184 #if FTS_PINCTRL_EN
185     struct pinctrl *pinctrl;
186     struct pinctrl_state *pins_active;
187     struct pinctrl_state *pins_suspend;
188     struct pinctrl_state *pins_release;
189 #endif
190 #if defined(CONFIG_FB)
191     struct  tp_device  tp;
192 #elif defined(CONFIG_HAS_EARLYSUSPEND)
193     struct early_suspend early_suspend;
194 #endif
195 };
196 
197 /*****************************************************************************
198 * Global variable or extern global variabls/functions
199 *****************************************************************************/
200 extern struct fts_ts_data *fts_data;
201 
202 /* communication interface */
203 int fts_read(u8 *cmd, u32 cmdlen, u8 *data, u32 datalen);
204 int fts_read_reg(u8 addr, u8 *value);
205 int fts_write(u8 *writebuf, u32 writelen);
206 int fts_write_reg(u8 addr, u8 value);
207 void fts_hid2std(void);
208 int fts_bus_init(struct fts_ts_data *ts_data);
209 int fts_bus_exit(struct fts_ts_data *ts_data);
210 
211 /* Gesture functions */
212 int fts_gesture_init(struct fts_ts_data *ts_data);
213 int fts_gesture_exit(struct fts_ts_data *ts_data);
214 void fts_gesture_recovery(struct fts_ts_data *ts_data);
215 int fts_gesture_readdata(struct fts_ts_data *ts_data, u8 *data);
216 int fts_gesture_suspend(struct fts_ts_data *ts_data);
217 int fts_gesture_resume(struct fts_ts_data *ts_data);
218 
219 /* Apk and functions */
220 int fts_create_apk_debug_channel(struct fts_ts_data *);
221 void fts_release_apk_debug_channel(struct fts_ts_data *);
222 
223 /* ADB functions */
224 int fts_create_sysfs(struct fts_ts_data *ts_data);
225 int fts_remove_sysfs(struct fts_ts_data *ts_data);
226 
227 /* ESD */
228 #if FTS_ESDCHECK_EN
229 int fts_esdcheck_init(struct fts_ts_data *ts_data);
230 int fts_esdcheck_exit(struct fts_ts_data *ts_data);
231 int fts_esdcheck_switch(bool enable);
232 int fts_esdcheck_proc_busy(bool proc_debug);
233 int fts_esdcheck_set_intr(bool intr);
234 int fts_esdcheck_suspend(void);
235 int fts_esdcheck_resume(void);
236 #endif
237 
238 
239 /* Point Report Check*/
240 #if FTS_POINT_REPORT_CHECK_EN
241 int fts_point_report_check_init(struct fts_ts_data *ts_data);
242 int fts_point_report_check_exit(struct fts_ts_data *ts_data);
243 void fts_prc_queue_work(struct fts_ts_data *ts_data);
244 #endif
245 
246 /* FW upgrade */
247 int fts_fwupg_init(struct fts_ts_data *ts_data);
248 int fts_fwupg_exit(struct fts_ts_data *ts_data);
249 int fts_upgrade_bin(char *fw_name, bool force);
250 int fts_enter_test_environment(bool test_state);
251 
252 /* Other */
253 int fts_reset_proc(int hdelayms);
254 int fts_wait_tp_to_valid(void);
255 void fts_release_all_finger(void);
256 void fts_tp_state_recovery(struct fts_ts_data *ts_data);
257 int fts_ex_mode_init(struct fts_ts_data *ts_data);
258 int fts_ex_mode_exit(struct fts_ts_data *ts_data);
259 int fts_ex_mode_recovery(struct fts_ts_data *ts_data);
260 
261 void fts_irq_disable(void);
262 void fts_irq_enable(void);
263 #endif /* __LINUX_FOCALTECH_CORE_H__ */
264