• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* drivers/input/touchscreen/gt9xx.h
2  *
3  * 2010 - 2013 Goodix Technology.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be a reference
11  * to you, when you are integrating the GOODiX's CTP IC into your system,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  */
17 
18 #ifndef _GOODIX_GT9XX_H_
19 #define _GOODIX_GT9XX_H_
20 
21 #include <linux/kernel.h>
22 #include <linux/hrtimer.h>
23 #include <linux/i2c.h>
24 #include <linux/input.h>
25 #include <linux/module.h>
26 #include <linux/delay.h>
27 #include <linux/i2c.h>
28 #include <linux/proc_fs.h>
29 #include <linux/string.h>
30 #include <linux/uaccess.h>
31 #include <linux/vmalloc.h>
32 #include <linux/interrupt.h>
33 #include <linux/io.h>
34 #include <linux/of_gpio.h>
35 #include <linux/gpio.h>
36 #include <linux/slab.h>
37 #include "../tp_suspend.h"
38 
39 //#include <mach/gpio.h>
40 //#include <linux/earlysuspend.h>
41 
42 #define CONFIG_8_9  0
43 #define DEBUG_SWITCH  0
44 
45 //***************************PART1:ON/OFF define*******************************
46 #define GTP_CUSTOM_CFG        0
47 #if CONFIG_8_9
48 #define GTP_CHANGE_X2Y        1
49 #define GTP_X_REVERSE_ENABLE	0
50 #define GTP_Y_REVERSE_ENABLE	1
51 #else
52 #define GTP_CHANGE_X2Y        1
53 #define GTP_X_REVERSE_ENABLE	1
54 #define GTP_Y_REVERSE_ENABLE	0
55 #endif
56 #define GTP_DRIVER_SEND_CFG   1
57 #define GTP_HAVE_TOUCH_KEY    0
58 #define GTP_POWER_CTRL_SLEEP  0
59 
60 #if defined(CONFIG_CHROME_PLATFORMS)
61 #define GTP_ICS_SLOT_REPORT   1
62 #else
63 #define GTP_ICS_SLOT_REPORT   0
64 #endif
65 
66 #define GTP_AUTO_UPDATE       0    // auto update fw by .bin file as default
67 #define GTP_HEADER_FW_UPDATE  0    // auto update fw by gtp_default_FW in gt9xx_firmware.h, function together with GTP_AUTO_UPDATE
68 #define GTP_AUTO_UPDATE_CFG   0    // auto update config by .cfg file, function together with GTP_AUTO_UPDATE
69 
70 #define GTP_COMPATIBLE_MODE   1    /* compatible with GT9XXF */
71 
72 #define GTP_CREATE_WR_NODE    0
73 #define GTP_ESD_PROTECT       0    // esd protection with a cycle of 2 seconds
74 
75 #define GTP_WITH_PEN          0
76 #define GTP_PEN_HAVE_BUTTON   0    // active pen has buttons, function together with GTP_WITH_PEN
77 
78 #define GTP_GESTURE_WAKEUP    0    // gesture wakeup
79 
80 #define GTP_DEBUG_ON          1
81 #define GTP_DEBUG_ARRAY_ON    0
82 #define GTP_DEBUG_FUNC_ON     0
83 
84 /* init use fixed clk num */
85 /* if open, u8 p_main_clk[6] = {69,69,69,69,69,167}; */
86 #define GTP_USE_FIXED_CLK     1
87 
88 #define PEN_DOWN 1
89 #define PEN_RELEASE 0
90 #define PEN_DOWN_UP 2 //fjp
91 
92 #if GTP_COMPATIBLE_MODE
93 typedef enum
94 {
95     CHIP_TYPE_GT9  = 0,
96     CHIP_TYPE_GT9F = 1,
97     CHIP_TYPE_GT9110 = 2,
98 } CHIP_TYPE_T;
99 #endif
100 
101 struct goodix_ts_data {
102     spinlock_t irq_lock;
103     struct i2c_client *client;
104     struct input_dev  *input_dev;
105     struct hrtimer timer;
106     struct work_struct  work;
107     //struct early_suspend early_suspend;
108     s32 irq_is_disable;
109     s32 use_irq;
110     u16 abs_x_max;
111     u16 abs_y_max;
112     u8  max_touch_num;
113     u8  int_trigger_type;
114     u8  green_wake_mode;
115     u8  enter_update;
116     u8  gtp_is_suspend;
117     u8  gtp_rawdiff_mode;
118     u8  gtp_cfg_len;
119     u8  fixed_cfg;
120     u8  fw_error;
121     u8  pnl_init_error;
122 	u8 cfg_file_num;
123 //add struct tp_device by Sam
124     struct  tp_device  tp;
125 
126     //add by Daniel(yc)
127     int irq;
128     int irq_pin;
129     int pwr_pin;
130     int rst_pin;
131     int tp_select_pin;
132     int rst_val;
133 	u8 pendown;
134     unsigned long irq_flags;
135 
136 #if GTP_WITH_PEN
137     struct input_dev *pen_dev;
138 #endif
139 
140 #if GTP_ESD_PROTECT
141     spinlock_t esd_lock;
142     u8  esd_running;
143     s32 clk_tick_cnt;
144 #endif
145 
146 #if GTP_COMPATIBLE_MODE
147     u16 bak_ref_len;
148     s32 ref_chk_fs_times;
149     s32 clk_chk_fs_times;
150     CHIP_TYPE_T chip_type;
151     u8 rqst_processing;
152     u8 is_950;
153 #endif
154     struct regulator *tp_regulator;
155 };
156 
157 extern u16 show_len;
158 extern u16 total_len;
159 
160 
161 //*************************** PART2:TODO define **********************************
162 // STEP_1(REQUIRED): Define Configuration Information Group(s)
163 // Sensor_ID Map:
164 /* sensor_opt1 sensor_opt2 Sensor_ID
165     GND         GND         0
166     VDDIO       GND         1
167     NC          GND         2
168     GND         NC/300K     3
169     VDDIO       NC/300K     4
170     NC          NC/300K     5
171 */
172 // TODO: define your own default or for Sensor_ID == 0 config here.
173 // The predefined one is just a sample config, which is not suitable for your tp in most cases.
174 /*
175 #define CTP_CFG_GROUP1 {\
176     0x46,0xE0,0x01,0x56,0x03,0x02,0xF1,0x01,0x02,0x44,\
177     0x00,0x04,0x46,0x32,0x03,0x00,0x00,0x00,0x00,0x00,\
178     0x00,0x11,0x04,0x26,0x01,0x74,0x77,0x05,0x00,0x88,\
179     0x64,0x0F,0xD0,0x07,0x05,0x07,0x00,0xDA,0x01,0x1D,\
180     0x00,0x01,0x08,0x08,0x33,0x33,0x5D,0xAA,0x00,0x00,\
181     0x00,0x32,0x96,0x54,0xC5,0x03,0x02,0x00,0x00,0x01,\
182     0xC8,0x38,0x00,0xA0,0x45,0x00,0x91,0x57,0x00,0x80,\
183     0x6C,0x00,0x61,0x87,0x00,0x61,0x10,0x0B,0x08,0x00,\
184     0x51,0x40,0x30,0xFF,0xFF,0x00,0x04,0x00,0x00,0x1E,\
185     0x0A,0x00,0x06,0x0B,0x09,0x0F,0x08,0x07,0x01,0x03,\
186     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
187     0x00,0x00,0x00,0x03,0x02,0x05,0x04,0x07,0x06,0x09,\
188     0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0xFF,0xFF,\
189     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,\
190     0x00,0x00,0x08,0x09,0x0A,0x0D,0x0E,0xFF,0xFF,0xFF,\
191     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,\
192     0x00,0x00,0x00,0xFF,0x0B,0x0C,0xFF,0xFF,0xFF,0xFF,\
193     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\
194     0xFF,0xFF,0xFF,0xFF,0x6C,0xB2,0xB2,0x6C,0xFF,0x00,\
195     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,\
196     0x8C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
197     0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
198     0x00,0x00,0x00,0x00,0x00,0x00,0xF6,0x01\
199     }
200 */
201 
202 /*
203 //WGJ10187_GT9271_Config_20140623_104014_0X41.cfg
204 #define CTP_CFG_GROUP1 {\
205     0x41,0xB0,0x04,0x80,0x07,0x05,0xF5,0x00,0x01,0x08,0x28,0x0F,0x64,0x32,0x03, \
206     0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x16,0x19,0x1E,0x14,0x8F,0x2F,0x99, \
207     0x41,0x43,0x15,0x0E,0x00,0x00,0x00,0x22,0x03,0x1D,0x00,0x00,0x00,0x00,0x00, \
208     0x00,0x00,0x00,0x00,0x06,0x00,0x2D,0x62,0x94,0xC5,0x02,0x07,0x17,0x00,0x04, \
209     0x92,0x30,0x00,0x86,0x39,0x00,0x7F,0x42,0x00,0x79,0x4D,0x00,0x74,0x5A,0x00, \
210     0x74,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \
211     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \
212     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x17,0x16,0x15,0x14,0x11,0x10,0x0F,0x0E, \
213     0x0D,0x0C,0x09,0x08,0x07,0x06,0x05,0x04,0x01,0x00,0xFF,0xFF,0x00,0x00,0x00, \
214     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x04,0x06,0x07,0x08,0x0A,0x0C, \
215     0x0D,0x0F,0x10,0x11,0x12,0x13,0x14,0x29,0x28,0x27,0x26,0x25,0x24,0x23,0x22, \
216     0x21,0x20,0x1F,0x1E,0x1C,0x1B,0x19,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, \
217     0x00,0x00,0x00,0x00,0x3D,0x01 \
218     }
219 */
220 
221 //WGJ10187_GT9271_Config_20140623_104014_0X41.cfg
222 #define CTP_CFG_GROUP1 {\
223     0x41,0x80,0x07,0xB0,0x04,0x0A,0x05,0x00,0x01,0x08,0x28,0x0F,0x50,0x32,0x03, \
224     0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x8F,0x2F,0x99, \
225     0x2B,0x2D,0x31,0x0D,0x00,0x00,0x00,0x01,0x03,0x1D,0x00,0x00,0x00,0x00,0x00, \
226     0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x55,0x94,0xC5,0x02,0x07,0x00,0x00,0x00, \
227     0x8C,0x26,0x00,0x7B,0x2D,0x00,0x6C,0x36,0x00,0x61,0x41,0x00,0x58,0x4E,0x00, \
228     0x58,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \
229     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, \
230     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x05,0x06,0x07,0x08,0x09, \
231     0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x14,0x15,0x16,0x17,0xFF,0xFF,0x00,0x00,0x00, \
232     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x13,0x12,0x11,0x10,0x0F,0x0D,0x0C, \
233     0x0A,0x08,0x07,0x06,0x04,0x02,0x00,0x19,0x1B,0x1C,0x1E,0x1F,0x20,0x21,0x22, \
234     0x23,0x24,0x25,0x26,0x27,0x28,0x29,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00, \
235     0x00,0x00,0x00,0x00,0xB5,0x01 \
236     }
237 
238 // TODO: define your config for Sensor_ID == 1 here, if needed
239 #define CTP_CFG_GROUP2 {\
240     }
241 
242 // TODO: define your config for Sensor_ID == 2 here, if needed
243 #define CTP_CFG_GROUP3 {\
244     }
245 
246 // TODO: define your config for Sensor_ID == 3 here, if needed
247 #define CTP_CFG_GROUP4 {\
248 }
249 // TODO: define your config for Sensor_ID == 4 here, if needed
250 #define CTP_CFG_GROUP5 {\
251     }
252 
253 // TODO: define your config for Sensor_ID == 5 here, if needed
254 #define CTP_CFG_GROUP6 {\
255     }
256 
257 // STEP_2(REQUIRED): Customize your I/O ports & I/O operations
258 /*
259 #define GTP_RST_PORT    S5PV210_GPJ3(6)
260 #define GTP_INT_PORT    S5PV210_GPH1(3)
261 #define GTP_INT_IRQ     gpio_to_irq(GTP_INT_PORT)
262 #define GTP_INT_CFG     S3C_GPIO_SFN(0xF)
263 
264 #define GTP_GPIO_AS_INPUT(pin)          do{\
265                                             gpio_direction_input(pin);\
266                                             s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);\
267                                         }while(0)
268 #define GTP_GPIO_AS_INT(pin)            do{\
269                                             GTP_GPIO_AS_INPUT(pin);\
270                                             s3c_gpio_cfgpin(pin, GTP_INT_CFG);\
271                                         }while(0)
272 */
273 #define GTP_GPIO_GET_VALUE(pin)         gpio_get_value(pin)
274 #define GTP_GPIO_OUTPUT(pin,level)      gpio_direction_output(pin,level)
275 #define GTP_GPIO_REQUEST(pin, label)    gpio_request(pin, label)
276 #define GTP_GPIO_FREE(pin)              gpio_free(pin)
277 #define GTP_IRQ_TAB                     {IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, IRQ_TYPE_LEVEL_LOW, IRQ_TYPE_LEVEL_HIGH}
278 
279 // STEP_3(optional): Specify your special config info if needed
280 #if GTP_CUSTOM_CFG
281   #define GTP_MAX_HEIGHT   800
282   #define GTP_MAX_WIDTH    480
283   #define GTP_INT_TRIGGER  0            // 0: Rising 1: Falling
284 #else
285   #define GTP_MAX_HEIGHT   4096
286   #define GTP_MAX_WIDTH    4096
287   #define GTP_INT_TRIGGER  1
288 #endif
289 #define GTP_MAX_TOUCH         10
290 
291 // STEP_4(optional): If keys are available and reported as keys, config your key info here
292 #if GTP_HAVE_TOUCH_KEY
293     #define GTP_KEY_TAB  {KEY_MENU, KEY_HOME, KEY_BACK}
294 #endif
295 
296 //***************************PART3:OTHER define*********************************
297 #define GTP_DRIVER_VERSION          "V2.2<2014/01/14>"
298 #define GTP_I2C_NAME                "Goodix-TS"
299 #define GT91XX_CONFIG_PROC_FILE     "gt9xx_config"
300 #define GTP_POLL_TIME         10
301 #define GTP_ADDR_LENGTH       2
302 #define GTP_CONFIG_MIN_LENGTH 186
303 #define GTP_CONFIG_MAX_LENGTH 240
304 #define FAIL                  0
305 #define SUCCESS               1
306 #define SWITCH_OFF            0
307 #define SWITCH_ON             1
308 
309 //******************** For GT9XXF Start **********************//
310 #define GTP_REG_BAK_REF                 0x99D0
311 #define GTP_REG_MAIN_CLK                0x8020
312 #define GTP_REG_CHIP_TYPE               0x8000
313 #define GTP_REG_HAVE_KEY                0x804E
314 #define GTP_REG_MATRIX_DRVNUM           0x8069
315 #define GTP_REG_MATRIX_SENNUM           0x806A
316 
317 #define GTP_FL_FW_BURN              0x00
318 #define GTP_FL_ESD_RECOVERY         0x01
319 #define GTP_FL_READ_REPAIR          0x02
320 
321 #define GTP_BAK_REF_SEND                0
322 #define GTP_BAK_REF_STORE               1
323 #define CFG_LOC_DRVA_NUM                29
324 #define CFG_LOC_DRVB_NUM                30
325 #define CFG_LOC_SENS_NUM                31
326 
327 #define GTP_CHK_FW_MAX                  40
328 #define GTP_CHK_FS_MNT_MAX              300
329 #define GTP_BAK_REF_PATH                "/data/gtp_ref.bin"
330 #define GTP_MAIN_CLK_PATH               "/data/gtp_clk.bin"
331 #define GTP_RQST_CONFIG                 0x01
332 #define GTP_RQST_BAK_REF                0x02
333 #define GTP_RQST_RESET                  0x03
334 #define GTP_RQST_MAIN_CLOCK             0x04
335 #define GTP_RQST_RESPONDED              0x00
336 #define GTP_RQST_IDLE                   0xFF
337 
338 //******************** For GT9XXF End **********************//
339 // Registers define
340 #define GTP_READ_COOR_ADDR    0x814E
341 #define GTP_REG_SLEEP         0x8040
342 #define GTP_REG_SENSOR_ID     0x814A
343 #define GTP_REG_CONFIG_DATA   0x8047
344 #define GTP_REG_VERSION       0x8140
345 
346 #define RESOLUTION_LOC        3
347 #define TRIGGER_LOC           8
348 
349 #define CFG_GROUP_LEN(p_cfg_grp)  (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0]))
350 
351 // Log define
352 #define GTP_ERROR(fmt,arg...)          printk("<<-GTP-ERROR->> "fmt"\n",##arg)
353 #if DEBUG_SWITCH
354 #define GTP_INFO(fmt,arg...)           printk("<<-GTP-INFO->> "fmt"\n",##arg)
355 #define GTP_DEBUG(fmt,arg...)          do{\
356                                          if(GTP_DEBUG_ON)\
357                                          printk("<<-GTP-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
358                                        }while(0)
359 #define GTP_DEBUG_ARRAY(array, num)    do{\
360                                          s32 i;\
361                                          u8* a = array;\
362                                          if(GTP_DEBUG_ARRAY_ON)\
363                                          {\
364                                             printk("<<-GTP-DEBUG-ARRAY->>\n");\
365                                             for (i = 0; i < (num); i++)\
366                                             {\
367                                                 printk("%02x   ", (a)[i]);\
368                                                 if ((i + 1 ) %10 == 0)\
369                                                 {\
370                                                     printk("\n");\
371                                                 }\
372                                             }\
373                                             printk("\n");\
374                                         }\
375                                        }while(0)
376 #define GTP_DEBUG_FUNC()               do{\
377                                          if(GTP_DEBUG_FUNC_ON)\
378                                          printk("     <<-GTP-FUNC->>       Func:%s@Line:%d\n",__func__,__LINE__);\
379                                        }while(0)
380 
381 #else
382 #define GTP_INFO(fmt,arg...)
383 #define GTP_DEBUG(fmt,arg...)
384 #define GTP_DEBUG_ARRAY(array, num)
385 #define GTP_DEBUG_FUNC()
386 #endif
387 #define GTP_SWAP(x, y)                 do{\
388                                          typeof(x) z = x;\
389                                          x = y;\
390                                          y = z;\
391                                        }while (0)
392 
393 //*****************************End of Part III********************************
394 #endif /* _GOODIX_GT9XX_H_ */
395