Merge tag 'v3.10.55' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / mach-mt8127 / tcl8127_tb_c_l / touchpanel / tpd_custom_gt9xx.h
1 #ifndef TPD_CUSTOM_GT9XX_H__
2 #define TPD_CUSTOM_GT9XX_H__
3
4 #include <linux/hrtimer.h>
5 #include <linux/string.h>
6 #include <linux/vmalloc.h>
7 //#include <linux/io.h>
8
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/delay.h>
12 #include <linux/i2c.h>
13 #include <linux/input.h>
14 #include <linux/slab.h>
15 #include <linux/gpio.h>
16 #include <linux/sched.h>
17 #include <linux/kthread.h>
18 #include <linux/bitops.h>
19 #include <linux/kernel.h>
20 #include <linux/delay.h>
21 #include <linux/byteorder/generic.h>
22 #ifdef CONFIG_HAS_EARLYSUSPEND
23 #include <linux/earlysuspend.h>
24 #endif
25 #include <linux/interrupt.h>
26 #include <linux/time.h>
27 #include <linux/rtpm_prio.h>
28
29 #include <linux/proc_fs.h>
30 #include <asm/uaccess.h>
31
32 #include <mach/mt_pm_ldo.h>
33 #include <mach/mt_typedefs.h>
34 #include <mach/mt_boot.h>
35
36 #include <cust_eint.h>
37 #include <linux/jiffies.h>
38
39 /* Pre-defined definition */
40
41 #define TPD_KEY_COUNT 4
42 #define key_1 60,850 //auto define
43 #define key_2 180,850
44 #define key_3 300,850
45 #define key_4 420,850
46
47 #define TPD_KEYS {KEY_BACK, KEY_HOME, KEY_MENU, KEY_SEARCH}
48 #define TPD_KEYS_DIM {{key_1,50,30},{key_2,50,30},{key_3,50,30},{key_4,50,30}}
49
50 struct goodix_ts_data
51 {
52 spinlock_t irq_lock;
53 struct i2c_client *client;
54 struct input_dev *input_dev;
55 struct hrtimer timer;
56 struct work_struct work;
57 struct early_suspend early_suspend;
58 s32 irq_is_disable;
59 s32 use_irq;
60 u16 abs_x_max;
61 u16 abs_y_max;
62 u8 max_touch_num;
63 u8 int_trigger_type;
64 u8 green_wake_mode;
65 u8 chip_type;
66 u8 enter_update;
67 u8 gtp_is_suspend;
68 u8 gtp_rawdiff_mode;
69 };
70
71 extern u16 show_len;
72 extern u16 total_len;
73 extern u8 gtp_rawdiff_mode;
74 extern u8 load_fw_process;
75
76 extern int tpd_halt;
77 extern s32 gtp_send_cfg(struct i2c_client *client);
78 extern void gtp_reset_guitar(struct i2c_client *client, s32 ms);
79 extern void gtp_int_sync(s32 ms);
80 extern u8 gup_init_update_proc(struct i2c_client *client);
81 extern u8 gup_init_fw_proc(struct i2c_client *client);
82 extern void mt_eint_unmask(unsigned int line);
83 extern void mt_eint_mask(unsigned int line);
84 extern s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len);
85 extern s32 gtp_i2c_write(struct i2c_client *client, u8 *buf, s32 len);
86 extern int i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len);
87 extern int i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len);
88 extern s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len);
89 extern u8 wait_hotknot_state;
90 extern u8 got_hotknot_state;
91 extern u8 got_hotknot_extra_state;
92 extern u8 hotknot_paired_flag;
93 extern wait_queue_head_t bp_waiter;
94 extern s32 gup_load_hotknot_system(void);
95
96 extern unsigned char gtp_default_FW[];
97 extern unsigned char gtp_default_FW_fl[];
98 //***************************PART1:ON/OFF define*******************************
99 #define GTP_CUSTOM_CFG 0
100 #define GTP_DRIVER_SEND_CFG 1 //driver send config to TP on intilization (for no config built in TP flash)
101 #define GTP_HAVE_TOUCH_KEY 0
102 #define GTP_POWER_CTRL_SLEEP 1 //turn off power on suspend
103 #define GTP_AUTO_UPDATE 1 //update FW to TP FLASH
104 #define GTP_CHANGE_X2Y 0 //set for se1
105 #define GTP_HEADER_FW_UPDATE 1 // auto updated fw by gtp_default_FW in gt9xx_firmware.h, function together with GTP_AUTO_UDPATE
106 #define GTP_AUTO_UPDATE_CFG 0 // auto update config by .cfg file, function together with GTP_AUTO_UPDATE
107
108 #define GTP_SUPPORT_I2C_DMA 1 // if gt9xxf, better enable it if hardware platform supported
109 #define GTP_COMPATIBLE_MODE 1 // compatible with GT9XXF
110
111 #define GTP_CREATE_WR_NODE 1
112 #define GTP_ESD_PROTECT 0 // esd protection with a cycle of 2 seconds
113 #define GUP_USE_HEADER_FILE 0
114 #define GTP_FW_DOWNLOAD 0 //update FW to TP SRAM
115 //#define GTP_CHARGER_DETECT
116
117 #define GTP_CONFIG_MIN_LENGTH 186
118 #define GTP_CONFIG_MAX_LENGTH 240
119 #define GTP_CHARGER_SWITCH 0 // charger plugin & plugout detect
120 #define GTP_WITH_PEN 0
121 #define GTP_SLIDE_WAKEUP 0
122 #define GTP_DBL_CLK_WAKEUP 0 // double-click wakup, function together with GTP_SLIDE_WAKEUP
123 #define HOTKNOT_BLOCK_RW 0
124
125 //#define TPD_PROXIMITY
126 //#define TPD_HAVE_BUTTON //report key as coordinate,Vibration feedback
127 //#define TPD_WARP_X
128 //#define TPD_WARP_Y
129
130 #define GTP_DEBUG_ON 0
131 #define GTP_DEBUG_ARRAY_ON 0
132 #define GTP_DEBUG_FUNC_ON 0
133
134 #define CFG_GROUP_LEN(p_cfg_grp) (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0]))
135 #define FLASHLESS_FLASH_WORKROUND 0
136
137 #if GTP_COMPATIBLE_MODE
138 extern void force_reset_guitar(void);
139 #endif
140 //***************************PART2:TODO define**********************************
141 //STEP_1(REQUIRED):Change config table.
142 /*TODO: puts the config info corresponded to your TP here, the following is just
143 a sample config, send this config should cause the chip cannot work normally*/
144 #define CTP_CFG_GROUP1 {\
145 0x42,0x20,0x03,0x00,0x05,0x05,0x38,0x06,\
146 0x01,0x88,0x28,0x07,0x55,0x37,0x03,0x04,\
147 0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x17,\
148 0x19,0x20,0x14,0x8C,0x2E,0x0E,0x2B,0x29,\
149 0xA0,0x0B,0x00,0x00,0x00,0x99,0x03,0x1D,\
150 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
151 0x00,0x00,0x00,0x1A,0x42,0x94,0xC5,0x02,\
152 0x05,0x00,0x00,0x04,0xB4,0x1C,0x00,0x97,\
153 0x22,0x00,0x80,0x29,0x00,0x6C,0x32,0x00,\
154 0x5D,0x3C,0x00,0x5D,0x00,0x00,0x00,0x00,\
155 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
156 0x00,0x00,0x00,0x28,0x28,0x03,0x06,0x00,\
157 0x31,0x85,0x0D,0x00,0x00,0x00,0x00,0x00,\
158 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
159 0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,\
160 0x12,0x14,0x16,0x18,0x1A,0x1C,0x00,0x00,\
161 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
162 0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x18,\
163 0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x24,\
164 0x26,0x28,0x29,0x2A,0x00,0x02,0x04,0x06,\
165 0x08,0x0A,0x0C,0x0F,0x10,0x12,0x13,0x14,\
166 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
167 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
168 0x60,0x01\
169 }
170
171 //default config for K82
172
173 #define CTP_CFG_GROUP1_CHARGER {\
174 }
175
176 //TODO puts your group2 config info here,if need.
177 #define CTP_CFG_GROUP2 {\
178 }
179
180 //TODO puts your group2 config info here,if need.
181 #define CTP_CFG_GROUP2_CHARGER {\
182 }
183
184 //TODO puts your group3 config info here,if need.
185 #define CTP_CFG_GROUP3 {\
186 }
187
188 //TODO puts your group3 config info here,if need.
189 #define CTP_CFG_GROUP3_CHARGER {\
190 }
191
192 // TODO: define your config for Sensor_ID == 3 here, if needed
193 #define CTP_CFG_GROUP4 {\
194 }
195
196 // TODO: define your config for Sensor_ID == 4 here, if needed
197 #define CTP_CFG_GROUP5 {\
198 }
199
200 // TODO: define your config for Sensor_ID == 5 here, if needed
201 #define CTP_CFG_GROUP6 {\
202 }
203
204
205 //STEP_2(REQUIRED):Change I/O define & I/O operation mode.
206 #define GTP_RST_PORT GPIO_CTP_RST_PIN
207 #define GTP_INT_PORT GPIO_CTP_EINT_PIN
208
209 #define GTP_GPIO_AS_INPUT(pin) do{\
210 if(pin == GPIO_CTP_EINT_PIN)\
211 mt_set_gpio_mode(pin, GPIO_CTP_EINT_PIN_M_GPIO);\
212 else\
213 mt_set_gpio_mode(pin, GPIO_CTP_RST_PIN_M_GPIO);\
214 mt_set_gpio_dir(pin, GPIO_DIR_IN);\
215 mt_set_gpio_pull_enable(pin, GPIO_PULL_DISABLE);\
216 }while(0)
217 #define GTP_GPIO_AS_INT(pin) do{\
218 mt_set_gpio_mode(pin, GPIO_CTP_EINT_PIN_M_EINT);\
219 mt_set_gpio_dir(pin, GPIO_DIR_IN);\
220 mt_set_gpio_pull_enable(pin, GPIO_PULL_DISABLE);\
221 }while(0)
222 #define GTP_GPIO_GET_VALUE(pin) mt_get_gpio_in(pin)
223 #define GTP_GPIO_OUTPUT(pin,level) do{\
224 if(pin == GPIO_CTP_EINT_PIN)\
225 mt_set_gpio_mode(pin, GPIO_CTP_EINT_PIN_M_GPIO);\
226 else\
227 mt_set_gpio_mode(pin, GPIO_CTP_RST_PIN_M_GPIO);\
228 mt_set_gpio_dir(pin, GPIO_DIR_OUT);\
229 mt_set_gpio_out(pin, level);\
230 }while(0)
231 #define GTP_GPIO_REQUEST(pin, label) gpio_request(pin, label)
232 #define GTP_GPIO_FREE(pin) gpio_free(pin)
233 #define GTP_IRQ_TAB {IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, IRQ_TYPE_LEVEL_LOW, IRQ_TYPE_LEVEL_HIGH}
234
235 //STEP_3(optional):Custom set some config by themself,if need.
236 #if GTP_CUSTOM_CFG
237 #define GTP_MAX_HEIGHT 800
238 #define GTP_MAX_WIDTH 480
239 #define GTP_INT_TRIGGER 0 //0:Rising 1:Falling
240 #else
241 #define GTP_MAX_HEIGHT 1280
242 #define GTP_MAX_WIDTH 800
243 #define GTP_INT_TRIGGER 1
244 #endif
245 #define GTP_MAX_TOUCH 5
246
247 #define TPD_POWER_SOURCE_CUSTOM MT65XX_POWER_LDO_VGP6 //MT6323_POWER_LDO_VGP1
248 #define VELOCITY_CUSTOM
249 #define TPD_VELOCITY_CUSTOM_X 15
250 #define TPD_VELOCITY_CUSTOM_Y 15
251
252 //STEP_4(optional):If this project have touch key,Set touch key config.
253 #if GTP_HAVE_TOUCH_KEY
254 #define GTP_KEY_TAB {KEY_MENU, KEY_HOME, KEY_BACK, KEY_SEND}
255 #endif
256
257 //***************************PART3:OTHER define*********************************
258 #define GTP_DRIVER_VERSION "V2.1<2014/01/10>"
259 #define GTP_I2C_NAME "Goodix-TS"
260 #define GT91XX_CONFIG_PROC_FILE "gt9xx_config"
261 #define GTP_POLL_TIME 10
262 #define GTP_ADDR_LENGTH 2
263 #define GTP_CONFIG_MIN_LENGTH 186
264 #define GTP_CONFIG_MAX_LENGTH 240
265 #define FAIL 0
266 #define SUCCESS 1
267 #define SWITCH_OFF 0
268 #define SWITCH_ON 1
269
270 //******************** For GT9XXF Start **********************//
271 #if GTP_COMPATIBLE_MODE
272 typedef enum
273 {
274 CHIP_TYPE_GT9 = 0,
275 CHIP_TYPE_GT9F = 1,
276 } CHIP_TYPE_T;
277 #endif
278
279 #define GTP_REG_MATRIX_DRVNUM 0x8069
280 #define GTP_REG_MATRIX_SENNUM 0x806A
281 #define GTP_REG_RQST 0x8043
282 #define GTP_REG_BAK_REF 0x99D0
283 #define GTP_REG_MAIN_CLK 0x8020
284 #define GTP_REG_CHIP_TYPE 0x8000
285 #define GTP_REG_HAVE_KEY 0x804E
286 #define GTP_REG_HN_STATE 0xAB10
287
288 #define GTP_FL_FW_BURN 0x00
289 #define GTP_FL_ESD_RECOVERY 0x01
290 #define GTP_FL_READ_REPAIR 0x02
291
292 #define GTP_BAK_REF_SEND 0
293 #define GTP_BAK_REF_STORE 1
294 #define CFG_LOC_DRVA_NUM 29
295 #define CFG_LOC_DRVB_NUM 30
296 #define CFG_LOC_SENS_NUM 31
297
298 #define GTP_CHK_FW_MAX 1000
299 #define GTP_CHK_FS_MNT_MAX 300
300 #define GTP_BAK_REF_PATH "/data/gtp_ref.bin"
301 #define GTP_MAIN_CLK_PATH "/data/gtp_clk.bin"
302 #define GTP_RQST_CONFIG 0x01
303 #define GTP_RQST_BAK_REF 0x02
304 #define GTP_RQST_RESET 0x03
305 #define GTP_RQST_MAIN_CLOCK 0x04
306 #define GTP_RQST_HOTKNOT_CODE 0x20
307 #define GTP_RQST_RESPONDED 0x00
308 #define GTP_RQST_IDLE 0xFF
309
310 #define HN_DEVICE_PAIRED 0x80
311 #define HN_MASTER_DEPARTED 0x40
312 #define HN_SLAVE_DEPARTED 0x20
313 #define HN_MASTER_SEND 0x10
314 #define HN_SLAVE_RECEIVED 0x08
315
316
317 //******************** For GT9XXF End **********************//
318
319 //Register define
320 #define GTP_READ_COOR_ADDR 0x814E
321 #define GTP_REG_SLEEP 0x8040
322 #define GTP_REG_SENSOR_ID 0x814A
323 #define GTP_REG_CONFIG_DATA 0x8047
324 #define GTP_REG_VERSION 0x8140
325 #define GTP_REG_HW_INFO 0x4220
326 #define GTP_REG_REFRESH_RATE 0x8056
327
328 #define RESOLUTION_LOC 3
329 #define TRIGGER_LOC 8
330
331
332 #define GTP_DMA_MAX_TRANSACTION_LENGTH 255 // for DMA mode
333 #define GTP_DMA_MAX_I2C_TRANSFER_SIZE (GTP_DMA_MAX_TRANSACTION_LENGTH - GTP_ADDR_LENGTH)
334 #define MAX_TRANSACTION_LENGTH 8
335 #define TPD_I2C_NUMBER 1
336 #define I2C_MASTER_CLOCK 300
337 #define MAX_I2C_TRANSFER_SIZE (MAX_TRANSACTION_LENGTH - GTP_ADDR_LENGTH)
338 #define TPD_MAX_RESET_COUNT 3
339 //#define TPD_CALIBRATION_MATRIX {962,0,0,0,1600,0,0,0};
340 #define TPD_CALIBRATION_MATRIX_ROTATION_NORMAL {0,2559,0,-6557,0,5238784,0,0};
341 #define TPD_CALIBRATION_MATRIX_ROTATION_FACTORY {0,2559,0,-6557,0,5238784,0,0};
342
343
344 #define TPD_RESET_ISSUE_WORKAROUND
345 #define TPD_HAVE_CALIBRATION
346 #define TPD_NO_GPIO
347 #define TPD_RESET_ISSUE_WORKAROUND
348
349 #ifdef TPD_WARP_X
350 #undef TPD_WARP_X
351 #define TPD_WARP_X(x_max, x) ( x_max - 1 - x )
352 #else
353 #define TPD_WARP_X(x_max, x) x
354 #endif
355
356 #ifdef TPD_WARP_Y
357 #undef TPD_WARP_Y
358 #define TPD_WARP_Y(y_max, y) ( y_max - 1 - y )
359 #else
360 #define TPD_WARP_Y(y_max, y) y
361 #endif
362
363 //Log define
364 #define GTP_INFO(fmt,arg...) printk("<<-GTP-INFO->> "fmt"\n",##arg)
365 #define GTP_ERROR(fmt,arg...) printk("<<-GTP-ERROR->> "fmt"\n",##arg)
366 #define GTP_DEBUG(fmt,arg...) do{\
367 if(GTP_DEBUG_ON)\
368 printk("<<-GTP-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
369 }while(0)
370 #define GTP_DEBUG_ARRAY(array, num) do{\
371 s32 i;\
372 u8* a = array;\
373 if(GTP_DEBUG_ARRAY_ON)\
374 {\
375 printk("<<-GTP-DEBUG-ARRAY->>\n");\
376 for (i = 0; i < (num); i++)\
377 {\
378 printk("%02x ", (a)[i]);\
379 if ((i + 1 ) %10 == 0)\
380 {\
381 printk("\n");\
382 }\
383 }\
384 printk("\n");\
385 }\
386 }while(0)
387 #define GTP_DEBUG_FUNC() do{\
388 if(GTP_DEBUG_FUNC_ON)\
389 printk("<<-GTP-FUNC->> Func:%s@Line:%d\n",__func__,__LINE__);\
390 }while(0)
391 #define GTP_SWAP(x, y) do{\
392 typeof(x) z = x;\
393 x = y;\
394 y = z;\
395 }while (0)
396
397 //****************************PART4:UPDATE define*******************************
398 //Error no
399 #define ERROR_NO_FILE 2 //ENOENT
400 #define ERROR_FILE_READ 23 //ENFILE
401 #define ERROR_FILE_TYPE 21 //EISDIR
402 #define ERROR_GPIO_REQUEST 4 //EINTR
403 #define ERROR_I2C_TRANSFER 5 //EIO
404 #define ERROR_NO_RESPONSE 16 //EBUSY
405 #define ERROR_TIMEOUT 110 //ETIMEDOUT
406
407 //*****************************End of Part III********************************
408
409 #endif /* TPD_CUSTOM_GT9XX_H__ */