xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/focaltech_touch/focaltech_core.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * FocalTech TouchScreen driver.
4  *
5  * Copyright (c) 2012-2018, 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/i2c.h>
37 #include <linux/input.h>
38 #include <linux/input/mt.h>
39 #include <linux/slab.h>
40 #include <linux/interrupt.h>
41 #include <linux/delay.h>
42 #include <linux/kernel.h>
43 #include <linux/module.h>
44 #include <linux/gpio.h>
45 #include <linux/of_gpio.h>
46 #include <linux/regulator/consumer.h>
47 #include <linux/firmware.h>
48 #include <linux/debugfs.h>
49 #include <linux/mutex.h>
50 #include <linux/wait.h>
51 #include <linux/time.h>
52 #include <linux/workqueue.h>
53 #include <linux/fs.h>
54 #include <linux/proc_fs.h>
55 #include <linux/uaccess.h>
56 #include <linux/version.h>
57 #include <linux/types.h>
58 #include <linux/sched.h>
59 #include <linux/kthread.h>
60 #include <linux/init.h>
61 #include <linux/cdev.h>
62 #include <linux/device.h>
63 #include <linux/mount.h>
64 #include <linux/netdevice.h>
65 #include <linux/unistd.h>
66 #include <linux/ioctl.h>
67 #include <linux/vmalloc.h>
68 #include "focaltech_common.h"
69 
70 /*****************************************************************************
71 * Private constant and macro definitions using #define
72 *****************************************************************************/
73 #define FTS_MAX_POINTS_SUPPORT              10 /* constant value, can't be changed */
74 #define FTS_MAX_KEYS                        4
75 #define FTS_KEY_WIDTH                       50
76 #define FTS_ONE_TCH_LEN                     6
77 
78 #define FTS_MAX_ID                          0x0A
79 #define FTS_TOUCH_X_H_POS                   3
80 #define FTS_TOUCH_X_L_POS                   4
81 #define FTS_TOUCH_Y_H_POS                   5
82 #define FTS_TOUCH_Y_L_POS                   6
83 #define FTS_TOUCH_PRE_POS                   7
84 #define FTS_TOUCH_AREA_POS                  8
85 #define FTS_TOUCH_POINT_NUM                 2
86 #define FTS_TOUCH_EVENT_POS                 3
87 #define FTS_TOUCH_ID_POS                    5
88 #define FTS_COORDS_ARR_SIZE                 4
89 #define FTS_X_MIN_DISPLAY_DEFAULT           0
90 #define FTS_Y_MIN_DISPLAY_DEFAULT           0
91 #define FTS_X_MAX_DISPLAY_DEFAULT           1600
92 #define FTS_Y_MAX_DISPLAY_DEFAULT           2176
93 
94 #define FTS_TOUCH_DOWN                      0
95 #define FTS_TOUCH_UP                        1
96 #define FTS_TOUCH_CONTACT                   2
97 #define EVENT_DOWN(flag)                    ((FTS_TOUCH_DOWN == flag) || (FTS_TOUCH_CONTACT == flag))
98 #define EVENT_UP(flag)                      (FTS_TOUCH_UP == flag)
99 #define EVENT_NO_DOWN(data)                 (!data->point_num)
100 #define KEY_EN(data)                        (data->pdata->have_key)
101 #define TOUCH_IS_KEY(y, key_y)              (y == key_y)
102 #define TOUCH_IN_RANGE(val, key_val, half)  ((val > (key_val - half)) && (val < (key_val + half)))
103 #define TOUCH_IN_KEY(x, key_x)              TOUCH_IN_RANGE(x, key_x, FTS_KEY_WIDTH)
104 
105 #define FTX_MAX_COMPATIBLE_TYPE             4
106 
107 /*****************************************************************************
108 * Private enumerations, structures and unions using typedef
109 *****************************************************************************/
110 struct fts_ts_platform_data {
111     u32 irq_gpio;
112     u32 irq_gpio_flags;
113     u32 reset_gpio;
114     u32 reset_gpio_flags;
115     bool have_key;
116     u32 key_number;
117     u32 keys[FTS_MAX_KEYS];
118     u32 key_y_coord;
119     u32 key_x_coords[FTS_MAX_KEYS];
120     u32 x_max;
121     u32 y_max;
122     u32 x_min;
123     u32 y_min;
124     u32 max_touch_number;
125 };
126 
127 struct ts_event {
128     int x; /*x coordinate */
129     int y; /*y coordinate */
130     int p; /* pressure */
131     int flag; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */
132     int id;   /*touch ID */
133     int area;
134 };
135 
136 struct fts_ts_data {
137     struct i2c_client *client;
138     struct input_dev *input_dev;
139     struct fts_ts_platform_data *pdata;
140     struct ts_ic_info ic_info;
141     struct workqueue_struct *ts_workqueue;
142     struct work_struct fwupg_work;
143     struct delayed_work esdcheck_work;
144     struct delayed_work prc_work;
145     struct work_struct resume_work;
146     struct regulator *vdd;
147     struct regulator *vcc_i2c;
148     spinlock_t irq_lock;
149     struct mutex report_mutex;
150     int irq;
151     bool suspended;
152     bool fw_loading;
153     bool irq_disabled;
154     bool power_disabled;
155     /* multi-touch */
156     struct ts_event *events;
157     u8 *point_buf;
158     int pnt_buf_size;
159     int touchs;
160     bool key_down;
161     int touch_point;
162     int point_num;
163     struct proc_dir_entry *proc;
164     u8 proc_opmode;
165 #if FTS_PINCTRL_EN
166     struct pinctrl *pinctrl;
167     struct pinctrl_state *pins_active;
168     struct pinctrl_state *pins_suspend;
169     struct pinctrl_state *pins_release;
170 #endif
171 #if defined(CONFIG_FB)
172     struct notifier_block fb_notif;
173 #elif defined(CONFIG_HAS_EARLYSUSPEND)
174     struct early_suspend early_suspend;
175 #endif
176 };
177 
178 /*****************************************************************************
179 * Global variable or extern global variabls/functions
180 *****************************************************************************/
181 extern struct fts_ts_data *fts_data;
182 
183 /* i2c communication*/
184 int fts_i2c_write_reg(struct i2c_client *client, u8 regaddr, u8 regvalue);
185 int fts_i2c_read_reg(struct i2c_client *client, u8 regaddr, u8 *regvalue);
186 int fts_i2c_read(struct i2c_client *client, char *writebuf, int writelen, char *readbuf, int readlen);
187 int fts_i2c_write(struct i2c_client *client, char *writebuf, int writelen);
188 void fts_i2c_hid2std(struct i2c_client *client);
189 int fts_i2c_init(void);
190 int fts_i2c_exit(void);
191 
192 /* Gesture functions */
193 #if FTS_GESTURE_EN
194 int fts_gesture_init(struct fts_ts_data *ts_data);
195 int fts_gesture_exit(struct i2c_client *client);
196 void fts_gesture_recovery(struct i2c_client *client);
197 int fts_gesture_readdata(struct fts_ts_data *ts_data);
198 int fts_gesture_suspend(struct i2c_client *i2c_client);
199 int fts_gesture_resume(struct i2c_client *client);
200 #endif
201 
202 /* Apk and functions */
203 #if FTS_APK_NODE_EN
204 int fts_create_apk_debug_channel(struct fts_ts_data *);
205 void fts_release_apk_debug_channel(struct fts_ts_data *);
206 #endif
207 
208 /* ADB functions */
209 #if FTS_SYSFS_NODE_EN
210 int fts_create_sysfs(struct i2c_client *client);
211 int fts_remove_sysfs(struct i2c_client *client);
212 #endif
213 
214 /* ESD */
215 #if FTS_ESDCHECK_EN
216 int fts_esdcheck_init(struct fts_ts_data *ts_data);
217 int fts_esdcheck_exit(struct fts_ts_data *ts_data);
218 int fts_esdcheck_switch(bool enable);
219 int fts_esdcheck_proc_busy(bool proc_debug);
220 int fts_esdcheck_set_intr(bool intr);
221 int fts_esdcheck_suspend(void);
222 int fts_esdcheck_resume(void);
223 #endif
224 
225 /* Production test */
226 #if FTS_TEST_EN
227 int fts_test_init(struct i2c_client *client);
228 int fts_test_exit(struct i2c_client *client);
229 #endif
230 
231 /* Point Report Check*/
232 #if FTS_POINT_REPORT_CHECK_EN
233 int fts_point_report_check_init(struct fts_ts_data *ts_data);
234 int fts_point_report_check_exit(struct fts_ts_data *ts_data);
235 void fts_prc_queue_work(struct fts_ts_data *ts_data);
236 #endif
237 
238 /* FW upgrade */
239 int fts_upgrade_bin(struct i2c_client *client, char *fw_name, bool force);
240 int fts_fwupg_init(struct fts_ts_data *ts_data);
241 int fts_fwupg_exit(struct fts_ts_data *ts_data);
242 
243 /* Other */
244 int fts_reset_proc(int hdelayms);
245 int fts_wait_tp_to_valid(struct i2c_client *client);
246 void fts_tp_state_recovery(struct i2c_client *client);
247 int fts_ex_mode_init(struct i2c_client *client);
248 int fts_ex_mode_exit(struct i2c_client *client);
249 int fts_ex_mode_recovery(struct i2c_client *client);
250 
251 void fts_irq_disable(void);
252 void fts_irq_enable(void);
253 
254 #endif /* __LINUX_FOCALTECH_CORE_H__ */
255