import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / mach-mt8127 / ttab / touchpanel / tpd_custom_gt9xx.h
1 /* Copyright Statement:
2 *
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
9 */
10 /* MediaTek Inc. (C) 2010. All rights reserved.
11 *
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
30 *
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
34 */
35
36 #ifndef TPD_CUSTOM_GT9XX_H__
37 #define TPD_CUSTOM_GT9XX_H__
38
39 #include <linux/hrtimer.h>
40 #include <linux/string.h>
41 #include <linux/vmalloc.h>
42 //#include <linux/io.h>
43
44 #include <linux/init.h>
45 #include <linux/module.h>
46 #include <linux/delay.h>
47 #include <linux/i2c.h>
48 #include <linux/input.h>
49 #include <linux/slab.h>
50 #include <linux/gpio.h>
51 #include <linux/sched.h>
52 #include <linux/kthread.h>
53 #include <linux/bitops.h>
54 #include <linux/kernel.h>
55 #include <linux/delay.h>
56 #include <linux/byteorder/generic.h>
57 #ifdef CONFIG_HAS_EARLYSUSPEND
58 #include <linux/earlysuspend.h>
59 #endif
60 #include <linux/interrupt.h>
61 #include <linux/time.h>
62 #include <linux/rtpm_prio.h>
63
64 #include <linux/proc_fs.h>
65 #include <asm/uaccess.h>
66 #ifdef MT6575
67 #include <mach/mt6575_pm_ldo.h>
68 #include <mach/mt6575_typedefs.h>
69 #include <mach/mt6575_boot.h>
70 #endif
71 #ifdef MT6577
72 #include <mach/mt6577_pm_ldo.h>
73 #include <mach/mt6577_typedefs.h>
74 #include <mach/mt6577_boot.h>
75 #endif
76 #include <mach/mt_pm_ldo.h>
77 #include <mach/mt_typedefs.h>
78 #include <mach/mt_boot.h>
79
80 #include <cust_eint.h>
81 #include <linux/jiffies.h>
82
83 /* Pre-defined definition */
84
85 #define TPD_KEY_COUNT 4
86 #define key_1 60,850 //auto define
87 #define key_2 180,850
88 #define key_3 300,850
89 #define key_4 420,850
90
91 #define TPD_KEYS {KEY_BACK, KEY_HOME, KEY_MENU, KEY_SEARCH}
92 #define TPD_KEYS_DIM {{key_1,50,30},{key_2,50,30},{key_3,50,30},{key_4,50,30}}
93
94 extern u16 show_len;
95 extern u16 total_len;
96 extern u8 gtp_rawdiff_mode;
97
98 extern int tpd_halt;
99 extern s32 gtp_send_cfg(struct i2c_client *client);
100 extern void gtp_reset_guitar(struct i2c_client *client, s32 ms);
101 extern void gtp_int_sync(s32 ms);
102 extern u8 gup_init_update_proc(struct i2c_client *client);
103 extern u8 gup_init_fw_proc(struct i2c_client *client);
104 extern void mt_eint_unmask(unsigned int line);
105 extern void mt_eint_mask(unsigned int line);
106 extern s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len);
107 extern s32 gtp_i2c_write(struct i2c_client *client,u8 *buf,s32 len);
108 extern int i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len);
109 extern int i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len);
110 extern s32 i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len);
111 extern s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len);
112
113 //***************************PART1:ON/OFF define*******************************
114 #define GTP_CUSTOM_CFG 0
115 #define GTP_DRIVER_SEND_CFG 1 // driver send config to TP in intilization
116 #define GTP_HAVE_TOUCH_KEY 0
117 #define GTP_POWER_CTRL_SLEEP 0 // turn off/on power on suspend/resume
118
119 #define GTP_AUTO_UPDATE 0 // auto updated fw by .bin file
120 #define GTP_HEADER_FW_UPDATE 0 // auto updated fw by gtp_default_FW in gt9xx_firmware.h, function together with GTP_AUTO_UDPATE
121 #define GTP_AUTO_UPDATE_CFG 0 // auto update config by .cfg file, function together with GTP_AUTO_UPDATE
122
123 #define GTP_SUPPORT_I2C_DMA 0 // if gt9xxf, better enable it if hardware platform supported
124 #define GTP_COMPATIBLE_MODE 1 // compatible with GT9XXF
125 #define GTP_FL_LITTLE_SYSTEM 0 // power off/on on suspend/resume, gt9xxf with an interim firwmare for it,
126 // function together with GTP_COMATIBLE_MODE & GTP_POWER_CTRL_SLEEP
127 #define GTP_CREATE_WR_NODE 1
128 #define GTP_ESD_PROTECT 1 // esd protection with a cycle of 2 seconds
129 #define GTP_CHARGER_SWITCH 0 // charger plugin & plugout detect
130
131 #define GTP_WITH_PEN 0
132 #define GTP_PEN_HAVE_BUTTON 0 // active pen has buttons, functions together with GTP_WITH_PEN
133
134 #define GTP_GESTURE_WAKEUP 1
135
136 //#define TPD_PROXIMITY
137 //#define TPD_HAVE_BUTTON // report key as coordinate,Vibration feedback
138 //#define TPD_WARP_X // mirrored x coordinate
139 //#define TPD_WARP_Y // mirrored y coordinate
140 #define GTP_DEBUG_ON 1
141 #define GTP_DEBUG_ARRAY_ON 0
142 #define GTP_DEBUG_FUNC_ON 0
143
144 //***************************PART2:TODO define**********************************
145 //STEP_1(REQUIRED):Change config table.
146 // Sensor_ID Map:
147 /* sensor_opt1 sensor_opt2 Sensor_ID
148 GND GND 0
149 VDDIO GND 1
150 NC GND 2
151 GND NC/300K 3
152 VDDIO NC/300K 4
153 NC NC/300K 5
154 */
155 // TODO: define your own default or for Sensor_ID == 0 config here.
156 // The predefined one is just a sample config, which is not suitable for your tp in most cases.
157 #define CTP_CFG_GROUP1 {\
158 }
159 // TODO: define your config for Sensor_ID == 1 here, if needed
160 #define CTP_CFG_GROUP2 {\
161 }
162 // TODO: define your config for Sensor_ID == 2 here, if needed
163 #define CTP_CFG_GROUP3 {\
164 }
165
166 // TODO: define your config for Sensor_ID == 3 here, if needed
167 #define CTP_CFG_GROUP4 {\
168 }
169
170 // TODO: define your config for Sensor_ID == 4 here, if needed
171 #define CTP_CFG_GROUP5 {\
172 }
173
174 // TODO: define your config for Sensor_ID == 5 here, if needed
175 #define CTP_CFG_GROUP6 {\
176 0x41,0x20,0x03,0x00,0x05,0x0A,0x05,0x20,0x01,0x0F,0x1E,\
177 0x0F,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\
178 0x00,0x00,0x00,0x00,0x00,0x8C,0x2E,0x0E,0x36,0x38,0xD3,\
179 0x07,0x00,0x00,0x02,0x9B,0x04,0x1D,0x00,0x01,0x00,0x00,\
180 0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x1E,0x66,0x94,0xC5,\
181 0x02,0x08,0x00,0x00,0x04,0xC1,0x22,0x00,0x9C,0x2B,0x00,\
182 0x7D,0x37,0x00,0x65,0x47,0x00,0x54,0x5A,0x00,0x54,0x00,\
183 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
184 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
185 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
186 0x00,0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x10,0x12,\
187 0x14,0x16,0x18,0x1A,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,\
188 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x14,\
189 0x13,0x12,0x10,0x0F,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,\
190 0x16,0x18,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x24,0x26,\
191 0x28,0x29,0x2A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
192 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
193 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
194 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
195 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
196 0x00,0x00,0x00,0x00,0x00,0x00,0xB8,0x01 \
197 }
198
199 // STEP_2(REQUIRED): Customize your I/O ports & I/O operations here
200 #define TPD_POWER_SOURCE_CUSTOM MT6323_POWER_LDO_VGP2// define your power source for tp if needed
201 #define GTP_RST_PORT GPIO_CTP_RST_PIN
202 #define GTP_INT_PORT GPIO_CTP_EINT_PIN
203
204 #define GTP_GPIO_AS_INPUT(pin) do{\
205 if(pin == GPIO_CTP_EINT_PIN)\
206 mt_set_gpio_mode(pin, GPIO_CTP_EINT_PIN_M_GPIO);\
207 else\
208 mt_set_gpio_mode(pin, GPIO_CTP_RST_PIN_M_GPIO);\
209 mt_set_gpio_dir(pin, GPIO_DIR_IN);\
210 mt_set_gpio_pull_enable(pin, GPIO_PULL_DISABLE);\
211 }while(0)
212 #define GTP_GPIO_AS_INT(pin) do{\
213 mt_set_gpio_mode(pin, GPIO_CTP_EINT_PIN_M_EINT);\
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_GET_VALUE(pin) mt_get_gpio_in(pin)
218 #define GTP_GPIO_OUTPUT(pin,level) do{\
219 if(pin == GPIO_CTP_EINT_PIN)\
220 mt_set_gpio_mode(pin, GPIO_CTP_EINT_PIN_M_GPIO);\
221 else\
222 mt_set_gpio_mode(pin, GPIO_CTP_RST_PIN_M_GPIO);\
223 mt_set_gpio_dir(pin, GPIO_DIR_OUT);\
224 mt_set_gpio_out(pin, level);\
225 }while(0)
226 #define GTP_GPIO_REQUEST(pin, label) gpio_request(pin, label)
227 #define GTP_GPIO_FREE(pin) gpio_free(pin)
228 #define GTP_IRQ_TAB {IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, IRQ_TYPE_LEVEL_LOW, IRQ_TYPE_LEVEL_HIGH}
229
230 // STEP_3(optional):Custom set some config by themself,if need.
231 #if GTP_CUSTOM_CFG
232 #define GTP_MAX_HEIGHT 800
233 #define GTP_MAX_WIDTH 480
234 #define GTP_INT_TRIGGER 0 //0:Rising 1:Falling
235 #else
236 #define GTP_MAX_HEIGHT 1280
237 #define GTP_MAX_WIDTH 800
238 #define GTP_INT_TRIGGER 1
239 #endif
240 #define GTP_MAX_TOUCH 5
241 #define VELOCITY_CUSTOM
242 #define TPD_VELOCITY_CUSTOM_X 15
243 #define TPD_VELOCITY_CUSTOM_Y 15
244
245 //STEP_4(optional):If this project have touch key,Set touch key config.
246 #if GTP_HAVE_TOUCH_KEY
247 #define GTP_KEY_TAB {KEY_MENU, KEY_HOME, KEY_BACK, KEY_SEND}
248 #endif
249
250 //***************************PART3:OTHER define*********************************
251 #define GTP_DRIVER_VERSION "V2.2.7<2014/12/26>"
252 #define GTP_I2C_NAME "Goodix-TS"
253 #define GT91XX_CONFIG_PROC_FILE "gt9xx_config"
254 #define GTP_POLL_TIME 10
255 #define GTP_ADDR_LENGTH 2
256 #define GTP_CONFIG_MIN_LENGTH 186
257 #define GTP_CONFIG_MAX_LENGTH 240
258 #define FAIL 0
259 #define SUCCESS 1
260 #define SWITCH_OFF 0
261 #define SWITCH_ON 1
262
263 #define CFG_GROUP_LEN(p_cfg_grp) (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0]))
264
265 //******************** For GT9XXF Start **********************//
266 #if GTP_COMPATIBLE_MODE
267 typedef enum
268 {
269 CHIP_TYPE_GT9 = 0,
270 CHIP_TYPE_GT9F = 1,
271 } CHIP_TYPE_T;
272 #endif
273
274 // buffer
275 #define GTP_REG_BUFFER 0xB026
276
277 #define GTP_REG_SS51_SEG_B 0xC000
278 #define GTP_REG_CHECKINFO 0xBF00
279
280 // State1
281 #define GTP_REG_STATE1 0xBF08
282 #define BUFFER_FULL 0x01
283 #define CHECK_COMPLETE 0x02
284 #define CHECK_ERROR 0x03
285 #define WAIT_CHECK 0x04 // others: invalid
286
287 // State2
288 #define GTP_REG_STATE2 0xBF07
289 #define IS_A_SEG 0x01
290 #define IS_B_SEG_FIRST 0x02
291 #define IS_B_SEG_OTHER 0x03
292 #define IS_B_SEG_LAST 0x04 // others: invalid
293
294 #define GTP_REG_MATRIX_DRVNUM 0x8069
295 #define GTP_REG_MATRIX_SENNUM 0x806A
296 #define GTP_REG_RQST 0x8043
297 #define GTP_REG_BAK_REF 0x99D0
298 #define GTP_REG_MAIN_CLK 0x8020
299 #define GTP_REG_CHIP_TYPE 0x8000
300 #define GTP_REG_HAVE_KEY 0x804E
301
302 #define GTP_FL_FW_BURN 0x00
303 #define GTP_FL_ESD_RECOVERY 0x01
304 #define GTP_FL_READ_REPAIR 0x02
305 #define GTP_FL_PWR_RESUME_BURN 0x03
306
307 #define GTP_BAK_REF_SEND 0
308 #define GTP_BAK_REF_STORE 1
309 #define GTP_HOPPING_SEND 0
310 #define GTP_HOPPING_STORE 1
311 #define CFG_LOC_DRVA_NUM 29
312 #define CFG_LOC_DRVB_NUM 30
313 #define CFG_LOC_SENS_NUM 31
314
315 #define GTP_CHK_FW_MAX 1000
316 #define GTP_CHK_FS_MNT_MAX 300
317 #define GTP_BAK_REF_PATH "/data/gtp_ref.bin"
318 #define GTP_MAIN_CLK_PATH "/data/gtp_clk.bin"
319 #define GTP_RQST_CONFIG 0x01
320 #define GTP_RQST_BAK_REF 0x02
321 #define GTP_RQST_RESET 0x03
322 #define GTP_RQST_MAIN_CLOCK 0x04
323 #define GTP_RQST_STORE_HOPPING 0x05
324 #define GTP_RQST_STORE_BAK_REF 0x06
325 #define GTP_RQST_RESPONDED 0x00
326 #define GTP_RQST_IDLE 0xFF
327
328 //******************** For GT9XXF End **********************//
329
330 //Register define
331 #define GTP_READ_COOR_ADDR 0x814E
332 #define GTP_REG_SLEEP 0x8040
333 #define GTP_REG_SENSOR_ID 0x814A
334 #define GTP_REG_CONFIG_DATA 0x8047
335 #define GTP_REG_VERSION 0x8140
336 #define GTP_REG_HW_INFO 0x4220
337
338 #define RESOLUTION_LOC 3
339 #define TRIGGER_LOC 8
340
341 #define I2C_MASTER_CLOCK 300
342 #define I2C_BUS_NUMBER 0 // I2C Bus for TP, mt6572
343 #define GTP_DMA_MAX_TRANSACTION_LENGTH 255 // for DMA mode
344 #define GTP_DMA_MAX_I2C_TRANSFER_SIZE (GTP_DMA_MAX_TRANSACTION_LENGTH - GTP_ADDR_LENGTH)
345 #define MAX_TRANSACTION_LENGTH 8
346 #define MAX_I2C_TRANSFER_SIZE (MAX_TRANSACTION_LENGTH - GTP_ADDR_LENGTH)
347 #define TPD_MAX_RESET_COUNT 3
348 #define TPD_CALIBRATION_MATRIX {962,0,0,0,1600,0,0,0};
349
350
351 #define TPD_RESET_ISSUE_WORKAROUND
352 #define TPD_HAVE_CALIBRATION
353 #define TPD_NO_GPIO
354 #define TPD_RESET_ISSUE_WORKAROUND
355
356 #ifdef TPD_WARP_X
357 #undef TPD_WARP_X
358 #define TPD_WARP_X(x_max, x) ( x_max - 1 - x )
359 #else
360 #define TPD_WARP_X(x_max, x) x
361 #endif
362
363 #ifdef TPD_WARP_Y
364 #undef TPD_WARP_Y
365 #define TPD_WARP_Y(y_max, y) ( y_max - 1 - y )
366 #else
367 #define TPD_WARP_Y(y_max, y) y
368 #endif
369
370 //Log define
371 #define GTP_INFO(fmt,arg...) printk("<<-GTP-INFO->> "fmt"\n",##arg)
372 #define GTP_ERROR(fmt,arg...) printk("<<-GTP-ERROR->> "fmt"\n",##arg)
373 #define GTP_DEBUG(fmt,arg...) do{\
374 if(GTP_DEBUG_ON)\
375 printk("<<-GTP-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\
376 }while(0)
377 #define GTP_DEBUG_ARRAY(array, num) do{\
378 s32 i;\
379 u8* a = array;\
380 if(GTP_DEBUG_ARRAY_ON)\
381 {\
382 printk("<<-GTP-DEBUG-ARRAY->>\n");\
383 for (i = 0; i < (num); i++)\
384 {\
385 printk("%02x ", (a)[i]);\
386 if ((i + 1 ) %10 == 0)\
387 {\
388 printk("\n");\
389 }\
390 }\
391 printk("\n");\
392 }\
393 }while(0)
394 #define GTP_DEBUG_FUNC() do{\
395 if(GTP_DEBUG_FUNC_ON)\
396 printk("<<-GTP-FUNC->> Func:%s@Line:%d\n",__func__,__LINE__);\
397 }while(0)
398 #define GTP_SWAP(x, y) do{\
399 typeof(x) z = x;\
400 x = y;\
401 y = z;\
402 }while (0)
403
404
405 //*****************************End of Part III********************************
406
407 #endif /* TPD_CUSTOM_GT9XX_H__ */