Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | #include "tpd.h" |
2 | #define GUP_FW_INFO | |
3 | #include "tpd_custom_gt9xx.h" | |
4 | ||
5 | #include "cust_gpio_usage.h" | |
6 | ||
7 | #ifdef TPD_PROXIMITY | |
8 | #include <linux/hwmsensor.h> | |
9 | #include <linux/hwmsen_dev.h> | |
10 | #include <linux/sensors_io.h> | |
11 | #endif | |
12 | #if GTP_SUPPORT_I2C_DMA | |
13 | #include <linux/dma-mapping.h> | |
14 | #endif | |
15 | #include <linux/mmprofile.h> | |
16 | #include <linux/device.h> | |
17 | extern struct tpd_device *tpd; | |
18 | #ifdef VELOCITY_CUSTOM | |
19 | extern int tpd_v_magnify_x; | |
20 | extern int tpd_v_magnify_y; | |
21 | #endif | |
22 | static int tpd_flag = 0; | |
23 | int tpd_halt = 0; | |
24 | static int tpd_eint_mode=1; | |
25 | static int tpd_polling_time=50; | |
26 | static DECLARE_WAIT_QUEUE_HEAD(waiter); | |
27 | static DEFINE_MUTEX(i2c_access); | |
28 | ||
29 | #ifdef TPD_HAVE_BUTTON | |
30 | static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS; | |
31 | static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM; | |
32 | #endif | |
33 | ||
34 | #if GTP_HAVE_TOUCH_KEY | |
35 | const u16 touch_key_array[] = TPD_KEYS; | |
36 | //#define GTP_MAX_KEY_NUM ( sizeof( touch_key_array )/sizeof( touch_key_array[0] ) ) | |
37 | struct touch_vitual_key_map_t | |
38 | { | |
39 | int point_x; | |
40 | int point_y; | |
41 | }; | |
42 | static struct touch_vitual_key_map_t touch_key_point_maping_array[]=GTP_KEY_MAP_ARRAY; | |
43 | #endif | |
44 | ||
45 | #if (defined(TPD_WARP_START) && defined(TPD_WARP_END)) | |
46 | static int tpd_wb_start_local[TPD_WARP_CNT] = TPD_WARP_START; | |
47 | static int tpd_wb_end_local[TPD_WARP_CNT] = TPD_WARP_END; | |
48 | #endif | |
49 | ||
50 | #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION)) | |
51 | //static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX; | |
52 | //static int tpd_def_calmat_local[8] = TPD_CALIBRATION_MATRIX; | |
53 | static int tpd_def_calmat_local_normal[8] = TPD_CALIBRATION_MATRIX_ROTATION_NORMAL; | |
54 | static int tpd_def_calmat_local_factory[8] = TPD_CALIBRATION_MATRIX_ROTATION_FACTORY; | |
55 | #endif | |
56 | ||
57 | #if GTP_SUPPORT_I2C_DMA | |
58 | s32 i2c_dma_write(struct i2c_client *client, u16 addr, u8 *txbuf, s32 len); | |
59 | s32 i2c_dma_read(struct i2c_client *client, u16 addr, u8 *rxbuf, s32 len); | |
60 | ||
61 | static u8 *gpDMABuf_va = NULL; | |
62 | static u32 gpDMABuf_pa = NULL; | |
63 | #endif | |
64 | ||
65 | s32 gtp_send_cfg(struct i2c_client *client); | |
66 | static void tpd_eint_interrupt_handler(void); | |
67 | static int touch_event_handler(void *unused); | |
68 | static int tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id); | |
69 | static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info); | |
70 | static int tpd_i2c_remove(struct i2c_client *client); | |
71 | static void tpd_on(void); | |
72 | static void tpd_off(void); | |
73 | ||
74 | #if GTP_CREATE_WR_NODE | |
75 | extern s32 init_wr_node(struct i2c_client *); | |
76 | extern void uninit_wr_node(void); | |
77 | #endif | |
78 | ||
79 | #ifdef GTP_CHARGER_DETECT | |
80 | extern bool upmu_get_pchr_chrdet(void); | |
81 | #define TPD_CHARGER_CHECK_CIRCLE 50 | |
82 | static struct delayed_work gtp_charger_check_work; | |
83 | static struct workqueue_struct *gtp_charger_check_workqueue = NULL; | |
84 | static void gtp_charger_check_func(struct work_struct *); | |
85 | static u8 gtp_charger_mode = 0; | |
86 | #endif | |
87 | ||
88 | #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE) | |
89 | #define TPD_ESD_CHECK_CIRCLE 2000 | |
90 | static struct delayed_work gtp_esd_check_work; | |
91 | static struct workqueue_struct *gtp_esd_check_workqueue = NULL; | |
92 | static void gtp_esd_check_func(struct work_struct *); | |
93 | static void force_reset_guitar(void); | |
94 | #endif | |
95 | ||
96 | #ifdef TPD_PROXIMITY | |
97 | #define TPD_PROXIMITY_VALID_REG 0x814E | |
98 | #define TPD_PROXIMITY_ENABLE_REG 0x8042 | |
99 | static u8 tpd_proximity_flag = 0; | |
100 | static u8 tpd_proximity_detect = 1;//0-->close ; 1--> far away | |
101 | #endif | |
102 | ||
103 | #ifndef GTP_REG_REFRESH_RATE | |
104 | #define GTP_REG_REFRESH_RATE 0x8056 | |
105 | #endif | |
106 | ||
107 | struct i2c_client *i2c_client_point = NULL; | |
108 | static const struct i2c_device_id tpd_i2c_id[] = {{"gt9xx", 0}, {}}; | |
109 | static unsigned short force[] = {0, 0xBA, I2C_CLIENT_END, I2C_CLIENT_END}; | |
110 | static const unsigned short *const forces[] = { force, NULL }; | |
111 | //static struct i2c_client_address_data addr_data = { .forces = forces,}; | |
112 | static struct i2c_board_info __initdata i2c_tpd = { I2C_BOARD_INFO("gt9xx", (0xBA >> 1))}; | |
113 | static struct i2c_driver tpd_i2c_driver = | |
114 | { | |
115 | .probe = tpd_i2c_probe, | |
116 | .remove = tpd_i2c_remove, | |
117 | .detect = tpd_i2c_detect, | |
118 | .driver.name = "gt9xx", | |
119 | .id_table = tpd_i2c_id, | |
120 | .address_list = (const unsigned short *) forces, | |
121 | }; | |
122 | ||
123 | static u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] | |
124 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
125 | #ifdef GTP_CHARGER_DETECT | |
126 | static u8 config_charger[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] | |
127 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
128 | #endif | |
129 | #pragma pack(1) | |
130 | typedef struct | |
131 | { | |
132 | u16 pid; //product id // | |
133 | u16 vid; //version id // | |
134 | } st_tpd_info; | |
135 | #pragma pack() | |
136 | ||
137 | st_tpd_info tpd_info; | |
138 | u8 int_type = 0; | |
139 | u32 abs_x_max = 0; | |
140 | u32 abs_y_max = 0; | |
141 | u8 gtp_rawdiff_mode = 0; | |
142 | u8 cfg_len = 0; | |
143 | ||
144 | #if GTP_COMPATIBLE_MODE | |
145 | u8 driver_num = 0; | |
146 | u8 sensor_num = 0; | |
147 | u8 gtp_ref_retries = 0; | |
148 | u8 gtp_clk_retries = 0; | |
149 | CHIP_TYPE_T gtp_chip_type = CHIP_TYPE_GT9; | |
150 | u8 gtp_clk_buf[6]; | |
151 | u8 rqst_processing = 0; | |
152 | u8 is_950 = 0; | |
153 | u8 esd_resetting = 0; | |
154 | ||
155 | extern u8 gup_clk_calibration(void); | |
156 | extern s32 gup_fw_download_proc(void *dir, u8 dwn_mode); | |
157 | extern u8 gup_check_fs_mounted(char *path_name); | |
158 | void gtp_get_chip_type(struct i2c_client *client); | |
159 | u8 gtp_fw_startup(struct i2c_client *client); | |
160 | static u8 gtp_bak_ref_proc(struct i2c_client *client, u8 mode); | |
161 | static u8 gtp_main_clk_proc(struct i2c_client *client); | |
162 | static void gtp_recovery_reset(struct i2c_client *client); | |
163 | #endif | |
164 | ||
165 | ||
166 | /* proc file system */ | |
167 | s32 i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len); | |
168 | s32 i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len); | |
169 | static struct proc_dir_entry *gt91xx_config_proc = NULL; | |
170 | ||
171 | /******************************************************* | |
172 | Function: | |
173 | Write refresh rate | |
174 | ||
175 | Input: | |
176 | rate: refresh rate N (Duration=5+N ms, N=0~15) | |
177 | ||
178 | Output: | |
179 | Executive outcomes.0---succeed. | |
180 | *******************************************************/ | |
181 | static u8 gtp_set_refresh_rate(u8 rate) | |
182 | { | |
183 | u8 buf[3] = {GTP_REG_REFRESH_RATE>>8, GTP_REG_REFRESH_RATE& 0xff, rate}; | |
184 | ||
185 | if (rate > 0xf) | |
186 | { | |
187 | GTP_ERROR("Refresh rate is over range (%d)", rate); | |
188 | return FAIL; | |
189 | } | |
190 | ||
191 | GTP_INFO("Refresh rate change to %d", rate); | |
192 | return gtp_i2c_write(i2c_client_point, buf, sizeof(buf)); | |
193 | } | |
194 | ||
195 | /******************************************************* | |
196 | Function: | |
197 | Get refresh rate | |
198 | ||
199 | Output: | |
200 | Refresh rate or error code | |
201 | *******************************************************/ | |
202 | static u8 gtp_get_refresh_rate(void) | |
203 | { | |
204 | int ret; | |
205 | ||
206 | u8 buf[3] = {GTP_REG_REFRESH_RATE>>8, GTP_REG_REFRESH_RATE& 0xff}; | |
207 | ret = gtp_i2c_read(i2c_client_point, buf, sizeof(buf)); | |
208 | if (ret < 0) | |
209 | return ret; | |
210 | ||
211 | GTP_INFO("Refresh rate is %d", buf[GTP_ADDR_LENGTH]); | |
212 | return buf[GTP_ADDR_LENGTH]; | |
213 | } | |
214 | ||
215 | //============================================================= | |
216 | static ssize_t show_refresh_rate(struct device *dev,struct device_attribute *attr, char *buf) | |
217 | { | |
218 | int ret = gtp_get_refresh_rate(); | |
219 | if (ret < 0) | |
220 | return 0; | |
221 | else | |
222 | return sprintf(buf, "%d\n", ret); | |
223 | } | |
224 | static ssize_t store_refresh_rate(struct device *dev,struct device_attribute *attr, const char *buf, size_t size) | |
225 | { | |
226 | //u32 rate = 0; | |
227 | gtp_set_refresh_rate(simple_strtoul(buf, NULL, 16)); | |
228 | return size; | |
229 | } | |
230 | static DEVICE_ATTR(tpd_refresh_rate, 0664, show_refresh_rate, store_refresh_rate); | |
231 | ||
232 | static struct device_attribute *gt9xx_attrs[] = | |
233 | { | |
234 | &dev_attr_tpd_refresh_rate, | |
235 | }; | |
236 | //============================================================= | |
237 | ||
238 | static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info) | |
239 | { | |
240 | strcpy(info->type, "mtk-tpd"); | |
241 | return 0; | |
242 | } | |
243 | ||
244 | #ifdef TPD_PROXIMITY | |
245 | static s32 tpd_get_ps_value(void) | |
246 | { | |
247 | return tpd_proximity_detect; | |
248 | } | |
249 | ||
250 | static s32 tpd_enable_ps(s32 enable) | |
251 | { | |
252 | u8 state; | |
253 | s32 ret = -1; | |
254 | ||
255 | if (enable) | |
256 | { | |
257 | state = 1; | |
258 | tpd_proximity_flag = 1; | |
259 | GTP_INFO("TPD proximity function to be on."); | |
260 | } | |
261 | else | |
262 | { | |
263 | state = 0; | |
264 | tpd_proximity_flag = 0; | |
265 | GTP_INFO("TPD proximity function to be off."); | |
266 | } | |
267 | ||
268 | ret = i2c_write_bytes(i2c_client_point, TPD_PROXIMITY_ENABLE_REG, &state, 1); | |
269 | ||
270 | if (ret < 0) | |
271 | { | |
272 | GTP_ERROR("TPD %s proximity cmd failed.", state ? "enable" : "disable"); | |
273 | return ret; | |
274 | } | |
275 | ||
276 | GTP_INFO("TPD proximity function %s success.", state ? "enable" : "disable"); | |
277 | return 0; | |
278 | } | |
279 | ||
280 | s32 tpd_ps_operate(void *self, u32 command, void *buff_in, s32 size_in, | |
281 | void *buff_out, s32 size_out, s32 *actualout) | |
282 | { | |
283 | s32 err = 0; | |
284 | s32 value; | |
285 | hwm_sensor_data *sensor_data; | |
286 | ||
287 | switch (command) | |
288 | { | |
289 | case SENSOR_DELAY: | |
290 | if ((buff_in == NULL) || (size_in < sizeof(int))) | |
291 | { | |
292 | GTP_ERROR("Set delay parameter error!"); | |
293 | err = -EINVAL; | |
294 | } | |
295 | ||
296 | // Do nothing | |
297 | break; | |
298 | ||
299 | case SENSOR_ENABLE: | |
300 | if ((buff_in == NULL) || (size_in < sizeof(int))) | |
301 | { | |
302 | GTP_ERROR("Enable sensor parameter error!"); | |
303 | err = -EINVAL; | |
304 | } | |
305 | else | |
306 | { | |
307 | value = *(int *)buff_in; | |
308 | err = tpd_enable_ps(value); | |
309 | } | |
310 | ||
311 | break; | |
312 | ||
313 | case SENSOR_GET_DATA: | |
314 | if ((buff_out == NULL) || (size_out < sizeof(hwm_sensor_data))) | |
315 | { | |
316 | GTP_ERROR("Get sensor data parameter error!"); | |
317 | err = -EINVAL; | |
318 | } | |
319 | else | |
320 | { | |
321 | sensor_data = (hwm_sensor_data *)buff_out; | |
322 | sensor_data->values[0] = tpd_get_ps_value(); | |
323 | sensor_data->value_divide = 1; | |
324 | sensor_data->status = SENSOR_STATUS_ACCURACY_MEDIUM; | |
325 | } | |
326 | ||
327 | break; | |
328 | ||
329 | default: | |
330 | GTP_ERROR("proxmy sensor operate function no this parameter %d!", command); | |
331 | err = -1; | |
332 | break; | |
333 | } | |
334 | ||
335 | return err; | |
336 | } | |
337 | #endif | |
338 | ||
339 | static int gt91xx_config_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) | |
340 | { | |
341 | char *ptr = page; | |
342 | char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0}; | |
343 | int i; | |
344 | ||
345 | ptr += sprintf(ptr, "==== GT9XX config init value====\n"); | |
346 | ||
347 | for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++) | |
348 | { | |
349 | ptr += sprintf(ptr, "0x%02X ", config[i + 2]); | |
350 | ||
351 | if (i % 8 == 7) | |
352 | ptr += sprintf(ptr, "\n"); | |
353 | } | |
354 | ||
355 | ptr += sprintf(ptr, "\n"); | |
356 | ||
357 | ptr += sprintf(ptr, "==== GT9XX config real value====\n"); | |
358 | i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, temp_data, GTP_CONFIG_MAX_LENGTH); | |
359 | ||
360 | for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++) | |
361 | { | |
362 | ptr += sprintf(ptr, "0x%02X ", temp_data[i]); | |
363 | ||
364 | if (i % 8 == 7) | |
365 | ptr += sprintf(ptr, "\n"); | |
366 | } | |
367 | ||
368 | /* Touch PID & VID */ | |
369 | ptr += sprintf(ptr, "\n"); | |
370 | ptr += sprintf(ptr, "==== GT9XX Version ID ====\n"); | |
371 | i2c_read_bytes(i2c_client_point, GTP_REG_VERSION, temp_data, 6); | |
372 | ptr += sprintf(ptr, "Chip PID: %c%c%c VID: 0x%02X%02X\n", temp_data[0], temp_data[1], temp_data[2], temp_data[5], temp_data[4]); | |
373 | ptr += sprintf(ptr, "Driver VID: 0x%02X%02X\n", gtp_default_FW[12], gtp_default_FW[13]); | |
374 | i2c_read_bytes(i2c_client_point, 0x41E4, temp_data, 1); | |
375 | ptr += sprintf(ptr, "Boot status 0x%X\n", temp_data[0]); | |
376 | ||
377 | /* Touch Status and Clock Gate */ | |
378 | ptr += sprintf(ptr, "\n"); | |
379 | ptr += sprintf(ptr, "==== Touch Status and Clock Gate ====\n"); | |
380 | ptr += sprintf(ptr, "status: 1: on, 0 :off\n"); | |
381 | ptr += sprintf(ptr, "status:%d\n", (tpd_halt+1)&0x1); | |
382 | ||
383 | *eof = 1; | |
384 | return (ptr - page); | |
385 | } | |
386 | ||
387 | static int gt91xx_config_write_proc(struct file *file, const char *buffer, unsigned long count, void *data) | |
388 | { | |
389 | s32 ret = 0; | |
390 | char temp[25] = {0}; // for store special format cmd | |
391 | char mode_str[15] = {0}; | |
392 | unsigned int mode; | |
393 | u8 buf[1]; | |
394 | ||
395 | GTP_DEBUG("write count %ld", count); | |
396 | ||
397 | if (count > GTP_CONFIG_MAX_LENGTH) | |
398 | { | |
399 | GTP_ERROR("size not match [%d:%ld]", GTP_CONFIG_MAX_LENGTH, count); | |
400 | return -EFAULT; | |
401 | } | |
402 | ||
403 | /**********************************************/ | |
404 | /* for store special format cmd */ | |
405 | if (copy_from_user(temp, buffer, sizeof(temp))) | |
406 | { | |
407 | GTP_ERROR("copy from user fail 2"); | |
408 | return -EFAULT; | |
409 | } | |
410 | sscanf(temp, "%s %d", (char *)&mode_str, &mode); | |
411 | ||
412 | /***********POLLING/EINT MODE switch****************/ | |
413 | if(strcmp(mode_str, "polling") == 0) | |
414 | { | |
415 | if(mode>=10&&mode<=200) | |
416 | { | |
417 | GTP_INFO("Switch to polling mode, polling time is %d",mode); | |
418 | tpd_eint_mode=0; | |
419 | tpd_polling_time=mode; | |
420 | tpd_flag = 1; | |
421 | wake_up_interruptible(&waiter); | |
422 | } | |
423 | else | |
424 | { | |
425 | GTP_INFO("Wrong polling time, please set between 10~200ms"); | |
426 | } | |
427 | return count; | |
428 | } | |
429 | if(strcmp(mode_str, "eint") == 0) | |
430 | { | |
431 | GTP_INFO("Switch to eint mode"); | |
432 | tpd_eint_mode=1; | |
433 | return count; | |
434 | } | |
435 | /**********************************************/ | |
436 | if(strcmp(mode_str, "switch") == 0) | |
437 | { | |
438 | if(mode == 0)// turn off | |
439 | tpd_off(); | |
440 | else if(mode == 1)//turn on | |
441 | tpd_on(); | |
442 | else | |
443 | GTP_ERROR("error mode :%d", mode); | |
444 | return count; | |
445 | } | |
446 | //force clear config | |
447 | if(strcmp(mode_str, "clear_config") == 0) | |
448 | { | |
449 | GTP_INFO("Force clear config"); | |
450 | buf[0] = 0x10; | |
451 | ret = i2c_write_bytes(i2c_client_point, GTP_REG_SLEEP, buf, 1); | |
452 | return count; | |
453 | } | |
454 | ||
455 | if (copy_from_user(&config[2], buffer, count)) | |
456 | { | |
457 | GTP_ERROR("copy from user fail"); | |
458 | return -EFAULT; | |
459 | } | |
460 | ||
461 | /***********clk operate reseved****************/ | |
462 | /**********************************************/ | |
463 | ret = gtp_send_cfg(i2c_client_point); | |
464 | abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; | |
465 | abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; | |
466 | int_type = (config[TRIGGER_LOC]) & 0x03; | |
467 | ||
468 | if (ret < 0) | |
469 | { | |
470 | GTP_ERROR("send config failed."); | |
471 | } | |
472 | ||
473 | return count; | |
474 | } | |
475 | ||
476 | #if GTP_SUPPORT_I2C_DMA | |
477 | s32 i2c_dma_read(struct i2c_client *client, u16 addr, u8 *rxbuf, s32 len) | |
478 | { | |
479 | int ret; | |
480 | s32 retry = 0; | |
481 | u8 buffer[2]; | |
482 | ||
483 | struct i2c_msg msg[2] = | |
484 | { | |
485 | { | |
486 | .addr = (client->addr & I2C_MASK_FLAG), | |
487 | .flags = 0, | |
488 | .buf = buffer, | |
489 | .len = 2, | |
490 | .timing = I2C_MASTER_CLOCK | |
491 | }, | |
492 | { | |
493 | .addr = (client->addr & I2C_MASK_FLAG), | |
494 | .ext_flag = (client->ext_flag | I2C_ENEXT_FLAG | I2C_DMA_FLAG), | |
495 | .flags = I2C_M_RD, | |
496 | .buf = gpDMABuf_pa, | |
497 | .len = len, | |
498 | .timing = I2C_MASTER_CLOCK | |
499 | }, | |
500 | }; | |
501 | ||
502 | buffer[0] = (addr >> 8) & 0xFF; | |
503 | buffer[1] = addr & 0xFF; | |
504 | ||
505 | if (rxbuf == NULL) | |
506 | return -1; | |
507 | ||
508 | //GTP_DEBUG("dma i2c read: 0x%04X, %d bytes(s)", addr, len); | |
509 | for (retry = 0; retry < 20; ++retry) | |
510 | { | |
511 | ret = i2c_transfer(client->adapter, &msg[0], 2); | |
512 | if (ret < 0) | |
513 | { | |
514 | continue; | |
515 | } | |
516 | memcpy(rxbuf, gpDMABuf_va, len); | |
517 | return 0; | |
518 | } | |
519 | GTP_ERROR("Dma I2C Read Error: 0x%04X, %d byte(s), err-code: %d", addr, len, ret); | |
520 | return ret; | |
521 | } | |
522 | ||
523 | ||
524 | s32 i2c_dma_write(struct i2c_client *client, u16 addr, u8 *txbuf, s32 len) | |
525 | { | |
526 | int ret; | |
527 | s32 retry = 0; | |
528 | u8 *wr_buf = gpDMABuf_va; | |
529 | ||
530 | struct i2c_msg msg = | |
531 | { | |
532 | .addr = (client->addr & I2C_MASK_FLAG), | |
533 | .ext_flag = (client->ext_flag | I2C_ENEXT_FLAG | I2C_DMA_FLAG), | |
534 | .flags = 0, | |
535 | .buf = gpDMABuf_pa, | |
536 | .len = 2 + len, | |
537 | .timing = I2C_MASTER_CLOCK | |
538 | }; | |
539 | ||
540 | wr_buf[0] = (u8)((addr >> 8) & 0xFF); | |
541 | wr_buf[1] = (u8)(addr & 0xFF); | |
542 | ||
543 | if (txbuf == NULL) | |
544 | return -1; | |
545 | ||
546 | //GTP_DEBUG("dma i2c write: 0x%04X, %d bytes(s)", addr, len); | |
547 | memcpy(wr_buf+2, txbuf, len); | |
548 | for (retry = 0; retry < 20; ++retry) | |
549 | { | |
550 | ret = i2c_transfer(client->adapter, &msg, 1); | |
551 | if (ret < 0) | |
552 | { | |
553 | continue; | |
554 | } | |
555 | return 0; | |
556 | } | |
557 | GTP_ERROR("Dma I2C Write Error: 0x%04X, %d byte(s), err-code: %d", addr, len, ret); | |
558 | return ret; | |
559 | } | |
560 | ||
561 | s32 i2c_read_bytes_dma(struct i2c_client *client, u16 addr, u8 *rxbuf, s32 len) | |
562 | { | |
563 | s32 left = len; | |
564 | s32 read_len = 0; | |
565 | u8 *rd_buf = rxbuf; | |
566 | s32 ret = 0; | |
567 | ||
568 | //GTP_DEBUG("Read bytes dma: 0x%04X, %d byte(s)", addr, len); | |
569 | while (left > 0) | |
570 | { | |
571 | if (left > GTP_DMA_MAX_TRANSACTION_LENGTH) | |
572 | { | |
573 | read_len = GTP_DMA_MAX_TRANSACTION_LENGTH; | |
574 | } | |
575 | else | |
576 | { | |
577 | read_len = left; | |
578 | } | |
579 | ret = i2c_dma_read(client, addr, rd_buf, read_len); | |
580 | if (ret < 0) | |
581 | { | |
582 | GTP_ERROR("dma read failed"); | |
583 | return -1; | |
584 | } | |
585 | ||
586 | left -= read_len; | |
587 | addr += read_len; | |
588 | rd_buf += read_len; | |
589 | } | |
590 | return 0; | |
591 | } | |
592 | ||
593 | s32 i2c_write_bytes_dma(struct i2c_client *client, u16 addr, u8 *txbuf, s32 len) | |
594 | { | |
595 | ||
596 | s32 ret = 0; | |
597 | s32 write_len = 0; | |
598 | s32 left = len; | |
599 | u8 *wr_buf = txbuf; | |
600 | ||
601 | //GTP_DEBUG("Write bytes dma: 0x%04X, %d byte(s)", addr, len); | |
602 | while (left > 0) | |
603 | { | |
604 | if (left > GTP_DMA_MAX_I2C_TRANSFER_SIZE) | |
605 | { | |
606 | write_len = GTP_DMA_MAX_I2C_TRANSFER_SIZE; | |
607 | } | |
608 | else | |
609 | { | |
610 | write_len = left; | |
611 | } | |
612 | ret = i2c_dma_write(client, addr, wr_buf, write_len); | |
613 | ||
614 | if (ret < 0) | |
615 | { | |
616 | GTP_ERROR("dma i2c write failed!"); | |
617 | return -1; | |
618 | } | |
619 | ||
620 | left -= write_len; | |
621 | addr += write_len; | |
622 | wr_buf += write_len; | |
623 | } | |
624 | return 0; | |
625 | } | |
626 | #endif //GTP_SUPPORT_I2C_DMA | |
627 | ||
628 | ||
629 | int i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len) | |
630 | { | |
631 | #if GTP_SUPPORT_I2C_DMA | |
632 | return i2c_read_bytes_dma(client, addr, rxbuf, len); | |
633 | #else | |
634 | ||
635 | u8 buffer[GTP_ADDR_LENGTH]; | |
636 | u16 left = len; | |
637 | u16 offset = 0; | |
638 | ||
639 | struct i2c_msg msg[2] = | |
640 | { | |
641 | { | |
642 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
643 | //.addr = (client->addr &I2C_MASK_FLAG), | |
644 | //.ext_flag = I2C_ENEXT_FLAG, | |
645 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
646 | .flags = 0, | |
647 | .buf = buffer, | |
648 | .len = GTP_ADDR_LENGTH, | |
649 | .timing = I2C_MASTER_CLOCK | |
650 | }, | |
651 | { | |
652 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
653 | //.addr = (client->addr &I2C_MASK_FLAG), | |
654 | //.ext_flag = I2C_ENEXT_FLAG, | |
655 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
656 | .flags = I2C_M_RD, | |
657 | .timing = I2C_MASTER_CLOCK | |
658 | }, | |
659 | }; | |
660 | ||
661 | if (rxbuf == NULL) | |
662 | return -1; | |
663 | ||
664 | GTP_DEBUG("i2c_read_bytes to device %02X address %04X len %d", client->addr, addr, len); | |
665 | ||
666 | while (left > 0) | |
667 | { | |
668 | buffer[0] = ((addr + offset) >> 8) & 0xFF; | |
669 | buffer[1] = (addr + offset) & 0xFF; | |
670 | ||
671 | msg[1].buf = &rxbuf[offset]; | |
672 | ||
673 | if (left > MAX_TRANSACTION_LENGTH) | |
674 | { | |
675 | msg[1].len = MAX_TRANSACTION_LENGTH; | |
676 | left -= MAX_TRANSACTION_LENGTH; | |
677 | offset += MAX_TRANSACTION_LENGTH; | |
678 | } | |
679 | else | |
680 | { | |
681 | msg[1].len = left; | |
682 | left = 0; | |
683 | } | |
684 | ||
685 | if (i2c_transfer(client->adapter, &msg[0], 2) != 2) | |
686 | { | |
687 | GTP_ERROR("I2C read 0x%X length=%d failed", addr + offset, len); | |
688 | return -1; | |
689 | } | |
690 | } | |
691 | ||
692 | return 0; | |
693 | #endif | |
694 | } | |
695 | ||
696 | s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len) | |
697 | { | |
698 | s32 ret = -1; | |
699 | u16 addr = (buf[0] << 8) + buf[1]; | |
700 | ||
701 | ret = i2c_read_bytes(client, addr, &buf[2], len - 2); | |
702 | ||
703 | if (!ret) | |
704 | { | |
705 | return 2; | |
706 | } | |
707 | else | |
708 | { | |
709 | #if GTP_COMPATIBLE_MODE | |
710 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
711 | { | |
712 | if (1 == esd_resetting) | |
713 | { | |
714 | GTP_INFO("Esd resetting..., no recovery reset"); | |
715 | } | |
716 | else | |
717 | { | |
718 | gtp_recovery_reset(client); | |
719 | } | |
720 | } | |
721 | else | |
722 | #endif | |
723 | gtp_reset_guitar(client, 20); | |
724 | return ret; | |
725 | } | |
726 | } | |
727 | ||
728 | int i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len) | |
729 | { | |
730 | #if GTP_SUPPORT_I2C_DMA | |
731 | return i2c_write_bytes_dma(client, addr, txbuf, len); | |
732 | #else | |
733 | ||
734 | u8 buffer[MAX_TRANSACTION_LENGTH]; | |
735 | u16 left = len; | |
736 | u16 offset = 0; | |
737 | ||
738 | struct i2c_msg msg = | |
739 | { | |
740 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
741 | //.addr = (client->addr &I2C_MASK_FLAG), | |
742 | //.ext_flag = I2C_ENEXT_FLAG, | |
743 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
744 | .flags = 0, | |
745 | .buf = buffer, | |
746 | .timing = I2C_MASTER_CLOCK, | |
747 | }; | |
748 | ||
749 | ||
750 | if (txbuf == NULL) | |
751 | return -1; | |
752 | ||
753 | GTP_DEBUG("i2c_write_bytes to device %02X address %04X len %d", client->addr, addr, len); | |
754 | ||
755 | while (left > 0) | |
756 | { | |
757 | buffer[0] = ((addr + offset) >> 8) & 0xFF; | |
758 | buffer[1] = (addr + offset) & 0xFF; | |
759 | ||
760 | if (left > MAX_I2C_TRANSFER_SIZE) | |
761 | { | |
762 | memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], MAX_I2C_TRANSFER_SIZE); | |
763 | msg.len = MAX_TRANSACTION_LENGTH; | |
764 | left -= MAX_I2C_TRANSFER_SIZE; | |
765 | offset += MAX_I2C_TRANSFER_SIZE; | |
766 | } | |
767 | else | |
768 | { | |
769 | memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], left); | |
770 | msg.len = left + GTP_ADDR_LENGTH; | |
771 | left = 0; | |
772 | } | |
773 | ||
774 | //GTP_DEBUG("byte left %d offset %d", left, offset); | |
775 | ||
776 | if (i2c_transfer(client->adapter, &msg, 1) != 1) | |
777 | { | |
778 | GTP_ERROR("I2C write 0x%X%X length=%d failed", buffer[0], buffer[1], len); | |
779 | return -1; | |
780 | } | |
781 | } | |
782 | ||
783 | return 0; | |
784 | #endif | |
785 | } | |
786 | ||
787 | s32 gtp_i2c_write(struct i2c_client *client, u8 *buf, s32 len) | |
788 | { | |
789 | s32 ret = -1; | |
790 | u16 addr = (buf[0] << 8) + buf[1]; | |
791 | ||
792 | ret = i2c_write_bytes(client, addr, &buf[2], len - 2); | |
793 | ||
794 | if (!ret) | |
795 | { | |
796 | return 1; | |
797 | } | |
798 | else | |
799 | { | |
800 | #if GTP_COMPATIBLE_MODE | |
801 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
802 | { | |
803 | if (1 == esd_resetting) | |
804 | { | |
805 | GTP_INFO("Esd resetting..., no recovery reset"); | |
806 | } | |
807 | else | |
808 | { | |
809 | gtp_recovery_reset(client); | |
810 | } | |
811 | } | |
812 | else | |
813 | #endif | |
814 | gtp_reset_guitar(client, 20); | |
815 | return ret; | |
816 | } | |
817 | } | |
818 | ||
819 | s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len) | |
820 | { | |
821 | u8 buf[16] = {0}; | |
822 | u8 confirm_buf[16] = {0}; | |
823 | u8 retry = 0; | |
824 | ||
825 | while (retry++ < 3) | |
826 | { | |
827 | memset(buf, 0xAA, 16); | |
828 | buf[0] = (u8)(addr >> 8); | |
829 | buf[1] = (u8)(addr & 0xFF); | |
830 | gtp_i2c_read(client, buf, len + 2); | |
831 | ||
832 | memset(confirm_buf, 0xAB, 16); | |
833 | confirm_buf[0] = (u8)(addr >> 8); | |
834 | confirm_buf[1] = (u8)(addr & 0xFF); | |
835 | gtp_i2c_read(client, confirm_buf, len + 2); | |
836 | ||
837 | if (!memcmp(buf, confirm_buf, len+2)) | |
838 | { | |
839 | memcpy(rxbuf, confirm_buf+2, len); | |
840 | return SUCCESS; | |
841 | } | |
842 | } | |
843 | GTP_ERROR("i2c read 0x%04X, %d bytes, double check failed!", addr, len); | |
844 | return FAIL; | |
845 | } | |
846 | ||
847 | ||
848 | /******************************************************* | |
849 | Function: | |
850 | Send config Function. | |
851 | ||
852 | Input: | |
853 | client: i2c client. | |
854 | ||
855 | Output: | |
856 | Executive outcomes.0--success,non-0--fail. | |
857 | *******************************************************/ | |
858 | s32 gtp_send_cfg(struct i2c_client *client) | |
859 | { | |
860 | s32 ret = 0; | |
861 | #if GTP_DRIVER_SEND_CFG | |
862 | s32 retry = 0; | |
863 | ||
864 | for (retry = 0; retry < 5; retry++) | |
865 | { | |
866 | #ifdef GTP_CHARGER_DETECT | |
867 | ||
868 | if (gtp_charger_mode == 1) | |
869 | { | |
870 | GTP_DEBUG("Write charger config"); | |
871 | ret = gtp_i2c_write(client, config_charger , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
872 | } | |
873 | else | |
874 | { | |
875 | GTP_DEBUG("Write normal config"); | |
876 | ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
877 | } | |
878 | ||
879 | #else | |
880 | ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
881 | #endif | |
882 | ||
883 | ||
884 | if (ret > 0) | |
885 | { | |
886 | break; | |
887 | } | |
888 | } | |
889 | ||
890 | #endif | |
891 | ||
892 | return ret; | |
893 | } | |
894 | ||
895 | /******************************************************* | |
896 | Function: | |
897 | Read goodix touchscreen version function. | |
898 | ||
899 | Input: | |
900 | client: i2c client struct. | |
901 | version:address to store version info | |
902 | ||
903 | Output: | |
904 | Executive outcomes.0---succeed. | |
905 | *******************************************************/ | |
906 | s32 gtp_read_version(struct i2c_client *client, u16 *version) | |
907 | { | |
908 | s32 ret = -1; | |
909 | s32 i; | |
910 | u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff}; | |
911 | ||
912 | GTP_DEBUG_FUNC(); | |
913 | ||
914 | ret = gtp_i2c_read(client, buf, sizeof(buf)); | |
915 | ||
916 | if (ret < 0) | |
917 | { | |
918 | GTP_ERROR("GTP read version failed"); | |
919 | return ret; | |
920 | } | |
921 | ||
922 | if (version) | |
923 | { | |
924 | *version = (buf[7] << 8) | buf[6]; | |
925 | } | |
926 | ||
927 | tpd_info.vid = *version; | |
928 | tpd_info.pid = 0x00; | |
929 | ||
930 | //for gt9xx series | |
931 | for (i = 0; i < 3; i++) | |
932 | { | |
933 | if (buf[i + 2] < 0x30)break; | |
934 | ||
935 | tpd_info.pid |= ((buf[i + 2] - 0x30) << ((2 - i) * 4)); | |
936 | } | |
937 | ||
938 | GTP_INFO("IC VERSION:%c%c%c_%02x%02x", | |
939 | buf[2], buf[3], buf[4], buf[7], buf[6]); | |
940 | ||
941 | return ret; | |
942 | } | |
943 | /******************************************************* | |
944 | Function: | |
945 | GTP initialize function. | |
946 | ||
947 | Input: | |
948 | client: i2c client private struct. | |
949 | ||
950 | Output: | |
951 | Executive outcomes.0---succeed. | |
952 | *******************************************************/ | |
953 | static s32 gtp_init_panel(struct i2c_client *client) | |
954 | { | |
955 | s32 ret = 0; | |
956 | ||
957 | #if GTP_DRIVER_SEND_CFG | |
958 | s32 i; | |
959 | u8 check_sum = 0; | |
960 | u8 rd_cfg_buf[16]; | |
961 | ||
962 | u8 cfg_info_group1[] = CTP_CFG_GROUP1; | |
963 | u8 cfg_info_group2[] = CTP_CFG_GROUP2; | |
964 | u8 cfg_info_group3[] = CTP_CFG_GROUP3; | |
965 | u8 *send_cfg_buf[3] = {cfg_info_group1, cfg_info_group2, cfg_info_group3}; | |
966 | #ifdef GTP_CHARGER_DETECT | |
967 | u8 cfg_info_group1_charger[] = CTP_CFG_GROUP1_CHARGER; | |
968 | u8 cfg_info_group2_charger[] = CTP_CFG_GROUP2_CHARGER; | |
969 | u8 cfg_info_group3_charger[] = CTP_CFG_GROUP3_CHARGER; | |
970 | u8 *send_cfg_buf_charger[3] = {cfg_info_group1_charger, cfg_info_group2_charger, cfg_info_group3_charger}; | |
971 | #endif | |
972 | u8 cfg_info_len[3] = {sizeof(cfg_info_group1) / sizeof(cfg_info_group1[0]), | |
973 | sizeof(cfg_info_group2) / sizeof(cfg_info_group2[0]), | |
974 | sizeof(cfg_info_group3) / sizeof(cfg_info_group3[0]) | |
975 | }; | |
976 | ||
977 | for (i = 0; i < 3; i++) | |
978 | { | |
979 | if (cfg_info_len[i] > cfg_len) | |
980 | { | |
981 | cfg_len = cfg_info_len[i]; | |
982 | } | |
983 | } | |
984 | ||
985 | GTP_DEBUG("len1=%d,len2=%d,len3=%d,get_len=%d", cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], cfg_len); | |
986 | ||
987 | if ((!cfg_info_len[1]) && (!cfg_info_len[2])) | |
988 | { | |
989 | rd_cfg_buf[GTP_ADDR_LENGTH] = 0; | |
990 | } | |
991 | else | |
992 | { | |
993 | rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8; | |
994 | rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff; | |
995 | ret = gtp_i2c_read(client, rd_cfg_buf, 3); | |
996 | ||
997 | if (ret < 0) | |
998 | { | |
999 | GTP_ERROR("Read SENSOR ID failed,default use group1 config!"); | |
1000 | rd_cfg_buf[GTP_ADDR_LENGTH] = 0; | |
1001 | goto out; | |
1002 | } | |
1003 | ||
1004 | rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x03; | |
1005 | } | |
1006 | ||
1007 | GTP_INFO("SENSOR ID:%d", rd_cfg_buf[GTP_ADDR_LENGTH]); | |
1008 | memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); | |
1009 | memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[rd_cfg_buf[GTP_ADDR_LENGTH]], cfg_len); | |
1010 | #ifdef GTP_CHARGER_DETECT | |
1011 | memset(&config_charger[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); | |
1012 | memcpy(&config_charger[GTP_ADDR_LENGTH], send_cfg_buf_charger[rd_cfg_buf[GTP_ADDR_LENGTH]], cfg_len); | |
1013 | #endif | |
1014 | ||
1015 | #if GTP_CUSTOM_CFG | |
1016 | config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH; | |
1017 | config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH >> 8); | |
1018 | config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT; | |
1019 | config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT >> 8); | |
1020 | ||
1021 | if (GTP_INT_TRIGGER == 0) //RISING | |
1022 | { | |
1023 | config[TRIGGER_LOC] &= 0xfe; | |
1024 | } | |
1025 | else if (GTP_INT_TRIGGER == 1) //FALLING | |
1026 | { | |
1027 | config[TRIGGER_LOC] |= 0x01; | |
1028 | } | |
1029 | ||
1030 | #endif //endif GTP_CUSTOM_CFG | |
1031 | ||
1032 | check_sum = 0; | |
1033 | ||
1034 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
1035 | { | |
1036 | check_sum += config[i]; | |
1037 | } | |
1038 | ||
1039 | config[cfg_len] = (~check_sum) + 1; | |
1040 | #ifdef GTP_CHARGER_DETECT | |
1041 | check_sum = 0; | |
1042 | ||
1043 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
1044 | { | |
1045 | check_sum += config_charger[i]; | |
1046 | } | |
1047 | ||
1048 | config_charger[cfg_len] = (~check_sum) + 1; | |
1049 | #endif | |
1050 | #else //else DRIVER NEED NOT SEND CONFIG | |
1051 | ||
1052 | if (cfg_len == 0) | |
1053 | { | |
1054 | cfg_len = GTP_CONFIG_MAX_LENGTH; | |
1055 | } | |
1056 | ||
1057 | ret = gtp_i2c_read(client, config, cfg_len + GTP_ADDR_LENGTH); | |
1058 | ||
1059 | if (ret < 0) | |
1060 | { | |
1061 | GTP_ERROR("GTP read resolution & max_touch_num failed, use default value!"); | |
1062 | abs_x_max = GTP_MAX_WIDTH; | |
1063 | abs_y_max = GTP_MAX_HEIGHT; | |
1064 | int_type = GTP_INT_TRIGGER; | |
1065 | goto out; | |
1066 | } | |
1067 | ||
1068 | #endif //endif GTP_DRIVER_SEND_CFG | |
1069 | ||
1070 | abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; | |
1071 | abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; | |
1072 | int_type = (config[TRIGGER_LOC]) & 0x03; | |
1073 | ||
1074 | if ((!abs_x_max) || (!abs_y_max)) | |
1075 | { | |
1076 | GTP_ERROR("GTP resolution & max_touch_num invalid, use default value!"); | |
1077 | abs_x_max = GTP_MAX_WIDTH; | |
1078 | abs_y_max = GTP_MAX_HEIGHT; | |
1079 | } | |
1080 | ||
1081 | #if GTP_COMPATIBLE_MODE | |
1082 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1083 | { | |
1084 | u8 have_key = 0; | |
1085 | if (is_950) | |
1086 | { | |
1087 | driver_num = config[GTP_REG_MATRIX_DRVNUM - GTP_REG_CONFIG_DATA + 2]; | |
1088 | sensor_num = config[GTP_REG_MATRIX_SENNUM - GTP_REG_CONFIG_DATA + 2]; | |
1089 | } | |
1090 | else | |
1091 | { | |
1092 | driver_num = (config[CFG_LOC_DRVA_NUM]&0x1F) + (config[CFG_LOC_DRVB_NUM]&0x1F); | |
1093 | sensor_num = (config[CFG_LOC_SENS_NUM]&0x0F) + ((config[CFG_LOC_SENS_NUM]>>4)&0x0F); | |
1094 | } | |
1095 | ||
1096 | have_key = config[GTP_REG_HAVE_KEY - GTP_REG_CONFIG_DATA + 2] & 0x01; // have key or not | |
1097 | if (1 == have_key) | |
1098 | { | |
1099 | driver_num--; | |
1100 | } | |
1101 | ||
1102 | GTP_DEBUG("Driver * Sensor: %d * %d(Key: %d), X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", | |
1103 | driver_num, sensor_num, have_key, abs_x_max,abs_y_max,int_type); | |
1104 | } | |
1105 | else | |
1106 | #endif | |
1107 | { | |
1108 | ret = gtp_send_cfg(client); | |
1109 | ||
1110 | if (ret < 0) | |
1111 | { | |
1112 | GTP_ERROR("Send config error."); | |
1113 | goto out; | |
1114 | } | |
1115 | ||
1116 | GTP_DEBUG("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x", abs_x_max, abs_y_max, int_type); | |
1117 | } | |
1118 | msleep(10); | |
1119 | out: | |
1120 | return ret; | |
1121 | } | |
1122 | ||
1123 | static s8 gtp_i2c_test(struct i2c_client *client) | |
1124 | { | |
1125 | ||
1126 | u8 retry = 0; | |
1127 | s8 ret = -1; | |
1128 | u32 hw_info = 0; | |
1129 | ||
1130 | GTP_DEBUG_FUNC(); | |
1131 | ||
1132 | while (retry++ < 5) | |
1133 | { | |
1134 | ret = i2c_read_bytes(client, GTP_REG_HW_INFO, (u8 *)&hw_info, sizeof(hw_info)); | |
1135 | ||
1136 | if ((!ret) && (hw_info == 0x00900600)) //20121212 | |
1137 | { | |
1138 | return ret; | |
1139 | } | |
1140 | ||
1141 | GTP_ERROR("GTP_REG_HW_INFO : %08X", hw_info); | |
1142 | GTP_ERROR("GTP i2c test failed time %d.", retry); | |
1143 | msleep(10); | |
1144 | } | |
1145 | ||
1146 | return -1; | |
1147 | } | |
1148 | ||
1149 | /******************************************************* | |
1150 | Function: | |
1151 | Set INT pin as input for FW sync. | |
1152 | ||
1153 | Note: | |
1154 | If the INT is high, It means there is pull up resistor attached on the INT pin. | |
1155 | Pull low the INT pin manaully for FW sync. | |
1156 | *******************************************************/ | |
1157 | void gtp_int_sync(u32 ms) | |
1158 | { | |
1159 | GTP_DEBUG("There is pull up resisitor attached on the INT pin~!"); | |
1160 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
1161 | msleep(ms); | |
1162 | GTP_GPIO_AS_INT(GTP_INT_PORT); | |
1163 | } | |
1164 | ||
1165 | void gtp_reset_guitar(struct i2c_client *client, s32 ms) | |
1166 | { | |
1167 | GTP_INFO("GTP RESET!"); | |
1168 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
1169 | msleep(ms); | |
1170 | GTP_GPIO_OUTPUT(GTP_INT_PORT, client->addr == 0x14); | |
1171 | msleep(2); | |
1172 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 1); | |
1173 | msleep(6); | |
1174 | ||
1175 | #if GTP_COMPATIBLE_MODE | |
1176 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1177 | { | |
1178 | return; | |
1179 | } | |
1180 | #endif | |
1181 | ||
1182 | gtp_int_sync(50); | |
1183 | ||
1184 | return; | |
1185 | } | |
1186 | ||
1187 | static int tpd_power_on(struct i2c_client *client) | |
1188 | { | |
1189 | int ret = 0; | |
1190 | int reset_count = 0; | |
1191 | ||
1192 | reset_proc: | |
1193 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
1194 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
1195 | msleep(10); | |
1196 | //power on, need confirm with SA | |
1197 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1198 | hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_3300, "TP"); | |
1199 | #else | |
1200 | hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_3300, "TP"); | |
1201 | #endif | |
1202 | #ifdef TPD_POWER_SOURCE_1800 | |
1203 | hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP"); | |
1204 | #endif | |
1205 | ||
1206 | gtp_reset_guitar(client, 20); | |
1207 | ||
1208 | #if GTP_COMPATIBLE_MODE | |
1209 | gtp_get_chip_type(client); | |
1210 | ||
1211 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1212 | { | |
1213 | ret = gup_fw_download_proc(NULL, GTP_FL_FW_BURN); | |
1214 | ||
1215 | if(FAIL == ret) | |
1216 | { | |
1217 | GTP_ERROR("[tpd_power_on]Download fw failed."); | |
1218 | if(reset_count++ < TPD_MAX_RESET_COUNT) | |
1219 | { | |
1220 | goto reset_proc; | |
1221 | } | |
1222 | else | |
1223 | { | |
1224 | return ret; | |
1225 | } | |
1226 | } | |
1227 | ||
1228 | ret = gtp_fw_startup(client); | |
1229 | if(FAIL == ret) | |
1230 | { | |
1231 | GTP_ERROR("[tpd_power_on]Startup fw failed."); | |
1232 | if(reset_count++ < TPD_MAX_RESET_COUNT) | |
1233 | { | |
1234 | goto reset_proc; | |
1235 | } | |
1236 | else | |
1237 | { | |
1238 | return ret; | |
1239 | } | |
1240 | } | |
1241 | } | |
1242 | else | |
1243 | #endif | |
1244 | { | |
1245 | ret = gtp_i2c_test(client); | |
1246 | ||
1247 | if (ret < 0) | |
1248 | { | |
1249 | GTP_ERROR("I2C communication ERROR!"); | |
1250 | ||
1251 | if (reset_count < TPD_MAX_RESET_COUNT) | |
1252 | { | |
1253 | reset_count++; | |
1254 | goto reset_proc; | |
1255 | } | |
1256 | else | |
1257 | { | |
1258 | goto out; | |
1259 | } | |
1260 | } | |
1261 | } | |
1262 | #if GTP_FW_DOWNLOAD | |
1263 | ret = gup_init_fw_proc(client); | |
1264 | ||
1265 | if (ret < 0) | |
1266 | { | |
1267 | GTP_ERROR("Create fw download thread error."); | |
1268 | } | |
1269 | ||
1270 | #endif | |
1271 | out: | |
1272 | return ret; | |
1273 | } | |
1274 | ||
1275 | //**************** For GT9XXF Start ********************// | |
1276 | #if GTP_COMPATIBLE_MODE | |
1277 | ||
1278 | void gtp_get_chip_type(struct i2c_client *client) | |
1279 | { | |
1280 | u8 opr_buf[10] = {0x00}; | |
1281 | s32 ret = 0; | |
1282 | ||
1283 | msleep(10); | |
1284 | ||
1285 | ret = gtp_i2c_read_dbl_check(client, GTP_REG_CHIP_TYPE, opr_buf, 10); | |
1286 | ||
1287 | if (FAIL == ret) | |
1288 | { | |
1289 | GTP_ERROR("Failed to get chip-type, set chip type default: GOODIX_GT9"); | |
1290 | gtp_chip_type = CHIP_TYPE_GT9; | |
1291 | return; | |
1292 | } | |
1293 | ||
1294 | if (!memcmp(opr_buf, "GOODIX_GT9", 10)) | |
1295 | { | |
1296 | gtp_chip_type = CHIP_TYPE_GT9; | |
1297 | } | |
1298 | else // GT9XXF | |
1299 | { | |
1300 | gtp_chip_type = CHIP_TYPE_GT9F; | |
1301 | } | |
1302 | //gtp_chip_type = CHIP_TYPE_GT9F; // for test | |
1303 | GTP_INFO("Chip Type: %s", (gtp_chip_type == CHIP_TYPE_GT9) ? "GOODIX_GT9" : "GOODIX_GT9F"); | |
1304 | } | |
1305 | ||
1306 | static u8 gtp_bak_ref_proc(struct i2c_client *client, u8 mode) | |
1307 | { | |
1308 | s32 i = 0; | |
1309 | s32 j = 0; | |
1310 | s32 ret = 0; | |
1311 | struct file *flp = NULL; | |
1312 | u8 *refp = NULL; | |
1313 | u32 ref_len = 0; | |
1314 | u32 ref_seg_len = 0; | |
1315 | s32 ref_grps = 0; | |
1316 | s32 ref_chksum = 0; | |
1317 | u16 tmp = 0; | |
1318 | ||
1319 | GTP_DEBUG("[gtp_bak_ref_proc]Driver:%d,Sensor:%d.", driver_num, sensor_num); | |
1320 | ||
1321 | //check file-system mounted | |
1322 | GTP_DEBUG("[gtp_bak_ref_proc]Waiting for FS %d", gtp_ref_retries); | |
1323 | if (gup_check_fs_mounted("/data") == FAIL) | |
1324 | { | |
1325 | GTP_DEBUG("[gtp_bak_ref_proc]/data not mounted"); | |
1326 | if(gtp_ref_retries++ < GTP_CHK_FS_MNT_MAX) | |
1327 | { | |
1328 | return FAIL; | |
1329 | } | |
1330 | } | |
1331 | else | |
1332 | { | |
1333 | GTP_DEBUG("[gtp_bak_ref_proc]/data mounted !!!!"); | |
1334 | } | |
1335 | ||
1336 | if (is_950) | |
1337 | { | |
1338 | ref_seg_len = (driver_num * (sensor_num - 1) + 2) * 2; | |
1339 | ref_grps = 6; | |
1340 | ref_len = ref_seg_len * 6; // for GT950, backup-reference for six segments | |
1341 | } | |
1342 | else | |
1343 | { | |
1344 | ref_len = driver_num*(sensor_num-2)*2 + 4; | |
1345 | ref_seg_len = ref_len; | |
1346 | ref_grps = 1; | |
1347 | } | |
1348 | ||
1349 | refp = (u8 *)kzalloc(ref_len, GFP_KERNEL); | |
1350 | if(refp == NULL) | |
1351 | { | |
1352 | GTP_ERROR("[gtp_bak_ref_proc]Alloc memory for ref failed.use default ref"); | |
1353 | return FAIL; | |
1354 | } | |
1355 | memset(refp, 0, ref_len); | |
1356 | if(gtp_ref_retries >= GTP_CHK_FS_MNT_MAX) | |
1357 | { | |
1358 | for (j = 0; j < ref_grps; ++j) | |
1359 | { | |
1360 | refp[ref_seg_len + j * ref_seg_len -1] = 0x01; | |
1361 | } | |
1362 | ret = i2c_write_bytes(client, 0x99D0, refp, ref_len); | |
1363 | if(-1 == ret) | |
1364 | { | |
1365 | GTP_ERROR("[gtp_bak_ref_proc]Write ref i2c error."); | |
1366 | ret = FAIL; | |
1367 | } | |
1368 | ||
1369 | GTP_ERROR("[gtp_bak_ref_proc]Bak file or path is not exist,send default ref."); | |
1370 | ret = SUCCESS; | |
1371 | goto exit_ref_proc; | |
1372 | } | |
1373 | ||
1374 | //get ref file data | |
1375 | flp = filp_open(GTP_BAK_REF_PATH, O_RDWR | O_CREAT, 0660); | |
1376 | if (IS_ERR(flp)) | |
1377 | { | |
1378 | GTP_ERROR("[gtp_bak_ref_proc]Ref File not found!Creat ref file."); | |
1379 | //flp->f_op->llseek(flp, 0, SEEK_SET); | |
1380 | //flp->f_op->write(flp, (char *)refp, ref_len, &flp->f_pos); | |
1381 | gtp_ref_retries++; | |
1382 | ret = FAIL; | |
1383 | goto exit_ref_proc; | |
1384 | } | |
1385 | else if(GTP_BAK_REF_SEND == mode) | |
1386 | { | |
1387 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1388 | ret = flp->f_op->read(flp, (char *)refp, ref_len, &flp->f_pos); | |
1389 | if(ret < 0) | |
1390 | { | |
1391 | GTP_ERROR("[gtp_bak_ref_proc]Read ref file failed."); | |
1392 | memset(refp, 0, ref_len); | |
1393 | } | |
1394 | } | |
1395 | ||
1396 | if(GTP_BAK_REF_STORE == mode) | |
1397 | { | |
1398 | ret = i2c_read_bytes(client, 0x99D0, refp, ref_len); | |
1399 | if(-1 == ret) | |
1400 | { | |
1401 | GTP_ERROR("[gtp_bak_ref_proc]Read ref i2c error."); | |
1402 | ret = FAIL; | |
1403 | goto exit_ref_proc; | |
1404 | } | |
1405 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1406 | flp->f_op->write(flp, (char *)refp, ref_len, &flp->f_pos); | |
1407 | } | |
1408 | else | |
1409 | { | |
1410 | //checksum ref file | |
1411 | for (j = 0; j < ref_grps; ++j) | |
1412 | { | |
1413 | ref_chksum = 0; | |
1414 | for(i=0; i<ref_seg_len-2; i+=2) | |
1415 | { | |
1416 | ref_chksum += ((refp[i + j * ref_seg_len]<<8) + refp[i + 1 + j * ref_seg_len]); | |
1417 | } | |
1418 | ||
1419 | GTP_DEBUG("[gtp_bak_ref_proc]Calc ref chksum:0x%04X", ref_chksum&0xFF); | |
1420 | tmp = ref_chksum + (refp[ref_seg_len + j * ref_seg_len -2]<<8) + refp[ref_seg_len + j * ref_seg_len -1]; | |
1421 | if(1 != tmp) | |
1422 | { | |
1423 | GTP_DEBUG("[gtp_bak_ref_proc]Ref file chksum error,use default ref"); | |
1424 | memset(&refp[j * ref_seg_len], 0, ref_seg_len); | |
1425 | refp[ref_seg_len - 1 + j * ref_seg_len] = 0x01; | |
1426 | } | |
1427 | else | |
1428 | { | |
1429 | GTP_DEBUG("[gtp_bak_ref_proc]Ref file chksum success."); | |
1430 | } | |
1431 | ||
1432 | } | |
1433 | ||
1434 | ret = i2c_write_bytes(client, 0x99D0, refp, ref_len); | |
1435 | if(-1 == ret) | |
1436 | { | |
1437 | GTP_ERROR("[gtp_bak_ref_proc]Write ref i2c error."); | |
1438 | ret = FAIL; | |
1439 | goto exit_ref_proc; | |
1440 | } | |
1441 | } | |
1442 | ||
1443 | ret = SUCCESS; | |
1444 | ||
1445 | exit_ref_proc: | |
1446 | if(refp) | |
1447 | { | |
1448 | kfree(refp); | |
1449 | } | |
1450 | if(!IS_ERR(flp)) | |
1451 | { | |
1452 | filp_close(flp, NULL); | |
1453 | } | |
1454 | return ret; | |
1455 | } | |
1456 | ||
1457 | u8 gtp_fw_startup(struct i2c_client *client) | |
1458 | { | |
1459 | u8 wr_buf[4]; | |
1460 | ||
1461 | //init sw WDT | |
1462 | wr_buf[0] = 0xAA; | |
1463 | wr_buf[1] = 0xAA; | |
1464 | i2c_write_bytes(client, 0x8040, wr_buf, 2); | |
1465 | ||
1466 | //release SS51 & DSP | |
1467 | wr_buf[0] = 0x00; | |
1468 | i2c_write_bytes(client, 0x4180, wr_buf, 1); | |
1469 | ||
1470 | //int sync | |
1471 | gtp_int_sync(20); | |
1472 | ||
1473 | //check fw run status | |
1474 | i2c_read_bytes(client, 0x8041, wr_buf, 1); | |
1475 | if(0xAA == wr_buf[0]) | |
1476 | { | |
1477 | GTP_ERROR("IC works abnormally,startup failed."); | |
1478 | return FAIL; | |
1479 | } | |
1480 | else | |
1481 | { | |
1482 | GTP_DEBUG("IC works normally,Startup success."); | |
1483 | wr_buf[0] = 0xAA; | |
1484 | wr_buf[1] = 0xAA; | |
1485 | i2c_write_bytes(client, 0x8040, wr_buf, 2); | |
1486 | return SUCCESS; | |
1487 | } | |
1488 | } | |
1489 | static void gtp_recovery_reset(struct i2c_client *client) | |
1490 | { | |
1491 | #if GTP_ESD_PROTECT | |
1492 | gtp_esd_switch(client, SWITCH_OFF); | |
1493 | #endif | |
1494 | force_reset_guitar(); | |
1495 | #if GTP_ESD_PROTECT | |
1496 | gtp_esd_switch(client, SWITCH_ON); | |
1497 | #endif | |
1498 | } | |
1499 | ||
1500 | static u8 gtp_check_clk_legality(void) | |
1501 | { | |
1502 | u8 i = 0; | |
1503 | u8 clk_chksum = gtp_clk_buf[5]; | |
1504 | ||
1505 | for(i = 0; i < 5; i++) | |
1506 | { | |
1507 | if((gtp_clk_buf[i] < 50) || (gtp_clk_buf[i] > 120) || | |
1508 | (gtp_clk_buf[i] != gtp_clk_buf[0])) | |
1509 | { | |
1510 | break; | |
1511 | } | |
1512 | clk_chksum += gtp_clk_buf[i]; | |
1513 | } | |
1514 | ||
1515 | if((i == 5) && (clk_chksum == 0)) | |
1516 | { | |
1517 | GTP_INFO("Clk ram legality check success"); | |
1518 | return SUCCESS; | |
1519 | } | |
1520 | GTP_ERROR("main clock freq in clock buf is wrong"); | |
1521 | return FAIL; | |
1522 | } | |
1523 | ||
1524 | static u8 gtp_main_clk_proc(struct i2c_client *client) | |
1525 | { | |
1526 | s32 ret = 0; | |
1527 | u8 i = 0; | |
1528 | u8 clk_cal_result = 0; | |
1529 | u8 clk_chksum = 0; | |
1530 | struct file *flp = NULL; | |
1531 | ||
1532 | //check clk legality | |
1533 | ret = gtp_check_clk_legality(); | |
1534 | if(SUCCESS == ret) | |
1535 | { | |
1536 | goto send_main_clk; | |
1537 | } | |
1538 | ||
1539 | GTP_DEBUG("[gtp_main_clk_proc]Waiting for FS %d", gtp_ref_retries); | |
1540 | if (gup_check_fs_mounted("/data") == FAIL) | |
1541 | { | |
1542 | GTP_DEBUG("[gtp_main_clk_proc]/data not mounted"); | |
1543 | if(gtp_clk_retries++ < GTP_CHK_FS_MNT_MAX) | |
1544 | { | |
1545 | return FAIL; | |
1546 | } | |
1547 | else | |
1548 | { | |
1549 | GTP_ERROR("[gtp_main_clk_proc]Wait for file system timeout,need cal clk"); | |
1550 | } | |
1551 | } | |
1552 | else | |
1553 | { | |
1554 | GTP_DEBUG("[gtp_main_clk_proc]/data mounted !!!!"); | |
1555 | flp = filp_open(GTP_MAIN_CLK_PATH, O_RDWR | O_CREAT, 0660); | |
1556 | if (!IS_ERR(flp)) | |
1557 | { | |
1558 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1559 | ret = flp->f_op->read(flp, (char *)gtp_clk_buf, 6, &flp->f_pos); | |
1560 | if(ret > 0) | |
1561 | { | |
1562 | ret = gtp_check_clk_legality(); | |
1563 | if(SUCCESS == ret) | |
1564 | { | |
1565 | GTP_DEBUG("[gtp_main_clk_proc]Open & read & check clk file success."); | |
1566 | goto send_main_clk; | |
1567 | } | |
1568 | } | |
1569 | } | |
1570 | GTP_ERROR("[gtp_main_clk_proc]Check clk file failed,need cal clk"); | |
1571 | } | |
1572 | ||
1573 | //cal clk | |
1574 | #if GTP_ESD_PROTECT | |
1575 | gtp_esd_switch(client, SWITCH_OFF); | |
1576 | #endif | |
1577 | clk_cal_result = gup_clk_calibration(); | |
1578 | force_reset_guitar(); | |
1579 | GTP_DEBUG("&&&&&&&&&&clk cal result:%d", clk_cal_result); | |
1580 | ||
1581 | #if GTP_ESD_PROTECT | |
1582 | gtp_esd_switch(client, SWITCH_ON); | |
1583 | #endif | |
1584 | ||
1585 | if(clk_cal_result < 50 || clk_cal_result > 120) | |
1586 | { | |
1587 | GTP_ERROR("[gtp_main_clk_proc]cal clk result is illegitimate"); | |
1588 | ret = FAIL; | |
1589 | goto exit_clk_proc; | |
1590 | } | |
1591 | ||
1592 | for(i = 0;i < 5; i++) | |
1593 | { | |
1594 | gtp_clk_buf[i] = clk_cal_result; | |
1595 | clk_chksum += gtp_clk_buf[i]; | |
1596 | } | |
1597 | gtp_clk_buf[5] = 0 - clk_chksum; | |
1598 | ||
1599 | if (IS_ERR(flp)) | |
1600 | { | |
1601 | flp = filp_open(GTP_MAIN_CLK_PATH, O_RDWR | O_CREAT, 0660); | |
1602 | } | |
1603 | else | |
1604 | { | |
1605 | flp->f_op->llseek(flp, 0, SEEK_SET); | |
1606 | flp->f_op->write(flp, (char *)gtp_clk_buf, 6, &flp->f_pos); | |
1607 | } | |
1608 | ||
1609 | ||
1610 | send_main_clk: | |
1611 | ||
1612 | ret = i2c_write_bytes(client, 0x8020, gtp_clk_buf, 6); | |
1613 | if(-1 == ret) | |
1614 | { | |
1615 | GTP_ERROR("[gtp_main_clk_proc]send main clk i2c error!"); | |
1616 | ret = FAIL; | |
1617 | goto exit_clk_proc; | |
1618 | } | |
1619 | if (flp && !IS_ERR(flp)) | |
1620 | { | |
1621 | filp_close(flp, NULL); | |
1622 | } | |
1623 | ||
1624 | ret = SUCCESS; | |
1625 | return SUCCESS; | |
1626 | exit_clk_proc: | |
1627 | ||
1628 | if (flp && !IS_ERR(flp)) //RMT add | |
1629 | { | |
1630 | filp_close(flp, NULL); | |
1631 | } | |
1632 | return ret; | |
1633 | } | |
1634 | ||
1635 | #endif | |
1636 | //************* For GT9XXF End **********************// | |
1637 | ||
1638 | #ifdef MTK_CTP_RESET_CONFIG | |
1639 | static int tpd_clear_config(void *unused) | |
1640 | { | |
1641 | int ret=0, check_sum=0; | |
1642 | u8 temp_data = 0, i=0; | |
1643 | u8 config_1st[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] | |
1644 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
1645 | ||
1646 | GTP_INFO("Clear Config Begin......"); | |
1647 | msleep(10000); //wait main thread to be completed | |
1648 | ||
1649 | ret = i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, &temp_data, 1); | |
1650 | if (ret < 0) | |
1651 | { | |
1652 | GTP_ERROR("GTP read config failed!"); | |
1653 | return -1; | |
1654 | } | |
1655 | ||
1656 | GTP_INFO("IC config version: 0x%x; Driver config version: 0x%x",temp_data, config[GTP_ADDR_LENGTH]); | |
1657 | if((temp_data<(u8)0x5A)&&(temp_data>config[GTP_ADDR_LENGTH])) | |
1658 | { | |
1659 | memset(&config_1st[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); | |
1660 | memcpy(&config_1st[GTP_ADDR_LENGTH], &config[GTP_ADDR_LENGTH], cfg_len); | |
1661 | config_1st[GTP_ADDR_LENGTH] = 0; | |
1662 | check_sum = 0; | |
1663 | ||
1664 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
1665 | { | |
1666 | check_sum += config_1st[i]; | |
1667 | } | |
1668 | ||
1669 | config_1st[cfg_len] = (~check_sum) + 1; | |
1670 | ret = gtp_i2c_write(i2c_client_point, config_1st , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
1671 | if (ret < 0) | |
1672 | { | |
1673 | GTP_ERROR("GTP write 00 config failed!"); | |
1674 | }else | |
1675 | { | |
1676 | GTP_INFO("Force clear cfg done"); | |
1677 | } | |
1678 | }else | |
1679 | { | |
1680 | GTP_INFO("No need clear cfg"); | |
1681 | } | |
1682 | return 0; | |
1683 | } | |
1684 | #endif | |
1685 | ||
1686 | static s32 tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) | |
1687 | { | |
1688 | s32 err = 0; | |
1689 | s32 ret = 0; | |
1690 | u16 version_info; | |
1691 | struct task_struct *thread = NULL; | |
1692 | #if 0 //GTP_HAVE_TOUCH_KEY | |
1693 | s32 idx = 0; | |
1694 | #endif | |
1695 | #ifdef TPD_PROXIMITY | |
1696 | struct hwmsen_object obj_ps; | |
1697 | #endif | |
1698 | ||
1699 | i2c_client_point = client; | |
1700 | ret = tpd_power_on(client); | |
1701 | ||
1702 | if (ret < 0) | |
1703 | { | |
1704 | GTP_ERROR("I2C communication ERROR!"); | |
1705 | goto out; | |
1706 | } | |
1707 | ||
1708 | #ifdef MTK_CTP_RESET_CONFIG | |
1709 | thread = kthread_run(tpd_clear_config, 0, "mtk-tpd-clear-config"); | |
1710 | if (IS_ERR(thread)) | |
1711 | { | |
1712 | err = PTR_ERR(thread); | |
1713 | GTP_INFO(TPD_DEVICE " failed to create kernel thread for clearing config: %d", err); | |
1714 | } | |
1715 | thread = NULL; | |
1716 | #endif | |
1717 | ||
1718 | #if GTP_AUTO_UPDATE | |
1719 | ret = gup_init_update_proc(client); | |
1720 | ||
1721 | if (ret < 0) | |
1722 | { | |
1723 | GTP_ERROR("Create update thread error."); | |
1724 | goto out; | |
1725 | } | |
1726 | ||
1727 | #endif | |
1728 | ||
1729 | ||
1730 | ||
1731 | #ifdef VELOCITY_CUSTOM | |
1732 | tpd_v_magnify_x = TPD_VELOCITY_CUSTOM_X; | |
1733 | tpd_v_magnify_y = TPD_VELOCITY_CUSTOM_Y; | |
1734 | ||
1735 | #endif | |
1736 | ||
1737 | ret = gtp_read_version(client, &version_info); | |
1738 | ||
1739 | if (ret < 0) | |
1740 | { | |
1741 | GTP_ERROR("Read version failed."); | |
1742 | goto out; | |
1743 | } | |
1744 | ||
1745 | ret = gtp_init_panel(client); | |
1746 | ||
1747 | if (ret < 0) | |
1748 | { | |
1749 | GTP_ERROR("GTP init panel failed."); | |
1750 | goto out; | |
1751 | } | |
1752 | #if 0 //linux-3.10 procfs API changed | |
1753 | // Create proc file system | |
1754 | gt91xx_config_proc = create_proc_entry(GT91XX_CONFIG_PROC_FILE, 0664, NULL); | |
1755 | ||
1756 | if (gt91xx_config_proc == NULL) | |
1757 | { | |
1758 | GTP_ERROR("create_proc_entry %s failed", GT91XX_CONFIG_PROC_FILE); | |
1759 | goto out; | |
1760 | } | |
1761 | else | |
1762 | { | |
1763 | gt91xx_config_proc->read_proc = gt91xx_config_read_proc; | |
1764 | gt91xx_config_proc->write_proc = gt91xx_config_write_proc; | |
1765 | } | |
1766 | #endif | |
1767 | ||
1768 | #if GTP_CREATE_WR_NODE | |
1769 | init_wr_node(client); | |
1770 | #endif | |
1771 | ||
1772 | thread = kthread_run(touch_event_handler, 0, TPD_DEVICE); | |
1773 | ||
1774 | if (IS_ERR(thread)) | |
1775 | { | |
1776 | err = PTR_ERR(thread); | |
1777 | GTP_INFO(TPD_DEVICE " failed to create kernel thread: %d", err); | |
1778 | goto out; | |
1779 | } | |
1780 | ||
1781 | #if 0//GTP_HAVE_TOUCH_KEY | |
1782 | ||
1783 | for (idx = 0; idx < TPD_KEY_COUNT; idx++) | |
1784 | { | |
1785 | input_set_capability(tpd->dev, EV_KEY, touch_key_array[idx]); | |
1786 | } | |
1787 | ||
1788 | #endif | |
1789 | ||
1790 | msleep(50); | |
1791 | ||
1792 | if (!int_type) //EINTF_TRIGGER | |
1793 | { | |
1794 | mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_RISING, tpd_eint_interrupt_handler, 0); | |
1795 | } | |
1796 | else | |
1797 | { | |
1798 | mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_FALLING, tpd_eint_interrupt_handler, 0);// disable auto-unmask | |
1799 | } | |
1800 | ||
1801 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1802 | ||
1803 | #ifdef TPD_PROXIMITY | |
1804 | //obj_ps.self = cm3623_obj; | |
1805 | obj_ps.polling = 0; //0--interrupt mode;1--polling mode; | |
1806 | obj_ps.sensor_operate = tpd_ps_operate; | |
1807 | ||
1808 | if ((err = hwmsen_attach(ID_PROXIMITY, &obj_ps))) | |
1809 | { | |
1810 | GTP_ERROR("hwmsen attach fail, return:%d.", err); | |
1811 | } | |
1812 | ||
1813 | #endif | |
1814 | ||
1815 | #if GTP_ESD_PROTECT | |
1816 | INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func); | |
1817 | gtp_esd_check_workqueue = create_workqueue("gtp_esd_check"); | |
1818 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, TPD_ESD_CHECK_CIRCLE); | |
1819 | #endif | |
1820 | ||
1821 | #ifdef GTP_CHARGER_DETECT | |
1822 | INIT_DELAYED_WORK(>p_charger_check_work, gtp_charger_check_func); | |
1823 | gtp_charger_check_workqueue = create_workqueue("gtp_charger_check"); | |
1824 | queue_delayed_work(gtp_charger_check_workqueue, >p_charger_check_work, TPD_CHARGER_CHECK_CIRCLE); | |
1825 | #endif | |
1826 | tpd_load_status = 1; | |
1827 | ||
1828 | return 0; | |
1829 | out: | |
1830 | return -1; | |
1831 | } | |
1832 | ||
1833 | static void tpd_eint_interrupt_handler(void) | |
1834 | { | |
1835 | TPD_DEBUG_PRINT_INT; | |
1836 | tpd_flag = 1; | |
1837 | wake_up_interruptible(&waiter); | |
1838 | } | |
1839 | static int tpd_i2c_remove(struct i2c_client *client) | |
1840 | { | |
1841 | #if GTP_CREATE_WR_NODE | |
1842 | uninit_wr_node(); | |
1843 | #endif | |
1844 | ||
1845 | #if GTP_ESD_PROTECT | |
1846 | destroy_workqueue(gtp_esd_check_workqueue); | |
1847 | #endif | |
1848 | ||
1849 | #if GTP_ESD_PROTECT | |
1850 | destroy_workqueue(gtp_charger_check_workqueue); | |
1851 | #endif | |
1852 | return 0; | |
1853 | } | |
1854 | #ifdef GTP_CHARGER_DETECT | |
1855 | static void gtp_charger_check_func(struct work_struct *work) | |
1856 | { | |
1857 | int cur_charger_state; | |
1858 | cur_charger_state = upmu_get_pchr_chrdet(); | |
1859 | ||
1860 | GTP_DEBUG("Charger mode = %d", cur_charger_state); | |
1861 | ||
1862 | if (gtp_charger_mode != cur_charger_state) | |
1863 | { | |
1864 | GTP_DEBUG("Charger state change detected~!"); | |
1865 | GTP_DEBUG("Charger mode = %d", cur_charger_state); | |
1866 | gtp_charger_mode = cur_charger_state; | |
1867 | gtp_send_cfg(i2c_client_point); | |
1868 | } | |
1869 | ||
1870 | if (!tpd_halt) | |
1871 | { | |
1872 | queue_delayed_work(gtp_charger_check_workqueue, >p_charger_check_work, TPD_CHARGER_CHECK_CIRCLE); | |
1873 | } | |
1874 | ||
1875 | return; | |
1876 | } | |
1877 | #endif | |
1878 | ||
1879 | #if (GTP_ESD_PROTECT || GTP_COMPATIBLE_MODE) | |
1880 | static void force_reset_guitar(void) | |
1881 | { | |
1882 | s32 i; | |
1883 | s32 ret; | |
1884 | ||
1885 | GTP_INFO("force_reset_guitar"); | |
1886 | ||
1887 | //Power off TP | |
1888 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1889 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
1890 | #else | |
1891 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
1892 | #endif | |
1893 | #ifdef TPD_POWER_SOURCE_1800 | |
1894 | hwPowerDown(TPD_POWER_SOURCE_1800, "TP"); | |
1895 | #endif | |
1896 | msleep(30); | |
1897 | //Power on TP | |
1898 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1899 | hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_3300, "TP"); | |
1900 | #else | |
1901 | hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_3300, "TP"); | |
1902 | #endif | |
1903 | #ifdef TPD_POWER_SOURCE_1800 | |
1904 | hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP"); | |
1905 | #endif | |
1906 | msleep(30); | |
1907 | for (i = 0; i < 5; i++) | |
1908 | { | |
1909 | //Reset Guitar | |
1910 | gtp_reset_guitar(i2c_client_point, 20); | |
1911 | ||
1912 | #if GTP_COMPATIBLE_MODE | |
1913 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
1914 | { | |
1915 | //check code ram | |
1916 | ret = gup_fw_download_proc(NULL, GTP_FL_ESD_RECOVERY); | |
1917 | if(FAIL == ret) | |
1918 | { | |
1919 | GTP_ERROR("[force_reset_guitar]Check & repair fw failed."); | |
1920 | continue; | |
1921 | } | |
1922 | tpd_halt = 1; | |
1923 | //startup fw | |
1924 | ret = gtp_fw_startup(i2c_client_point); | |
1925 | if(FAIL == ret) | |
1926 | { | |
1927 | GTP_ERROR("[force_reset_guitar]Startup fw failed."); | |
1928 | continue; | |
1929 | } | |
1930 | tpd_halt = 0; | |
1931 | break; | |
1932 | } | |
1933 | else | |
1934 | #endif | |
1935 | { | |
1936 | //Send config | |
1937 | ret = gtp_send_cfg(i2c_client_point); | |
1938 | ||
1939 | if (ret < 0) | |
1940 | { | |
1941 | continue; | |
1942 | } | |
1943 | } | |
1944 | break; | |
1945 | } | |
1946 | ||
1947 | } | |
1948 | ||
1949 | static void gtp_esd_check_func(struct work_struct *work) | |
1950 | { | |
1951 | int i; | |
1952 | int ret = -1; | |
1953 | u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
1954 | ||
1955 | if (tpd_halt) | |
1956 | { | |
1957 | return; | |
1958 | } | |
1959 | ||
1960 | for (i = 0; i < 3; i++) | |
1961 | { | |
1962 | ret = gtp_i2c_read(i2c_client_point, test, 3); | |
1963 | ||
1964 | if (ret > 0) | |
1965 | { | |
1966 | break; | |
1967 | } | |
1968 | } | |
1969 | ||
1970 | if (i >= 3) | |
1971 | { | |
1972 | #if GTP_COMPATIBLE_MODE | |
1973 | if (1 == rqst_processing) | |
1974 | { | |
1975 | GTP_INFO("Request Processing, no reset guitar..."); | |
1976 | } | |
1977 | else | |
1978 | #endif | |
1979 | { | |
1980 | #if GTP_COMPATIBLE_MODE | |
1981 | esd_resetting = 1; | |
1982 | #endif | |
1983 | ||
1984 | force_reset_guitar(); | |
1985 | ||
1986 | #if GTP_COMPATIBLE_MODE | |
1987 | esd_resetting = 0; | |
1988 | #endif | |
1989 | } | |
1990 | } | |
1991 | ||
1992 | if (!tpd_halt) | |
1993 | { | |
1994 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, TPD_ESD_CHECK_CIRCLE); | |
1995 | } | |
1996 | ||
1997 | return; | |
1998 | } | |
1999 | #endif | |
2000 | static int tpd_history_x=0, tpd_history_y=0; | |
2001 | static void tpd_down(s32 x, s32 y, s32 size, s32 id) | |
2002 | { | |
2003 | if ((!size) && (!id)) | |
2004 | { | |
2005 | input_report_abs(tpd->dev, ABS_MT_PRESSURE, 100); | |
2006 | input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 100); | |
2007 | } | |
2008 | else | |
2009 | { | |
2010 | input_report_abs(tpd->dev, ABS_MT_PRESSURE, size); | |
2011 | input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, size); | |
2012 | /* track id Start 0 */ | |
2013 | input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, id); | |
2014 | } | |
2015 | ||
2016 | input_report_key(tpd->dev, BTN_TOUCH, 1); | |
2017 | input_report_abs(tpd->dev, ABS_MT_POSITION_X, x); | |
2018 | input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y); | |
2019 | input_mt_sync(tpd->dev); | |
2020 | TPD_DEBUG_SET_TIME; | |
2021 | TPD_EM_PRINT(x, y, x, y, id, 1); | |
2022 | tpd_history_x=x; | |
2023 | tpd_history_y=y; | |
2024 | ||
2025 | MMProfileLogEx(MMP_TouchPanelEvent, MMProfileFlagPulse, 1, x+y); | |
2026 | #ifdef TPD_HAVE_BUTTON | |
2027 | ||
2028 | if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode()) | |
2029 | { | |
2030 | tpd_button(x, y, 1); | |
2031 | } | |
2032 | ||
2033 | #endif | |
2034 | } | |
2035 | ||
2036 | static void tpd_up(s32 x, s32 y, s32 id) | |
2037 | { | |
2038 | //input_report_abs(tpd->dev, ABS_MT_PRESSURE, 0); | |
2039 | input_report_key(tpd->dev, BTN_TOUCH, 0); | |
2040 | //input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 0); | |
2041 | input_mt_sync(tpd->dev); | |
2042 | TPD_DEBUG_SET_TIME; | |
2043 | TPD_EM_PRINT(tpd_history_x, tpd_history_y, tpd_history_x, tpd_history_y, id, 0); | |
2044 | tpd_history_x=0; | |
2045 | tpd_history_y=0; | |
2046 | MMProfileLogEx(MMP_TouchPanelEvent, MMProfileFlagPulse, 0, x+y); | |
2047 | ||
2048 | #ifdef TPD_HAVE_BUTTON | |
2049 | ||
2050 | if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode()) | |
2051 | { | |
2052 | tpd_button(x, y, 0); | |
2053 | } | |
2054 | ||
2055 | #endif | |
2056 | } | |
2057 | ||
2058 | /*Coordination mapping*/ | |
2059 | static void tpd_calibrate_driver(int *x, int *y) | |
2060 | { | |
2061 | int tx; | |
2062 | ||
2063 | GTP_DEBUG("Call tpd_calibrate of this driver ..\n"); | |
2064 | ||
2065 | tx = ( (tpd_def_calmat[0] * (*x)) + (tpd_def_calmat[1] * (*y)) + (tpd_def_calmat[2]) ) >> 12; | |
2066 | *y = ( (tpd_def_calmat[3] * (*x)) + (tpd_def_calmat[4] * (*y)) + (tpd_def_calmat[5]) ) >> 12; | |
2067 | *x = tx; | |
2068 | } | |
2069 | ||
2070 | static int touch_event_handler(void *unused) | |
2071 | { | |
2072 | struct sched_param param = { .sched_priority = RTPM_PRIO_TPD }; | |
2073 | u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0}; | |
2074 | u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF}; | |
2075 | u8 touch_num = 0; | |
2076 | u8 finger = 0; | |
2077 | static u8 pre_touch = 0; | |
2078 | static u8 pre_key = 0; | |
2079 | u8 key_value = 0; | |
2080 | u8 *coor_data = NULL; | |
2081 | s32 input_x = 0; | |
2082 | s32 input_y = 0; | |
2083 | s32 input_w = 0; | |
2084 | s32 id = 0; | |
2085 | s32 i = 0; | |
2086 | s32 ret = -1; | |
2087 | #if GTP_COMPATIBLE_MODE | |
2088 | u8 rqst_data[3] = {(u8)(GTP_REG_RQST >> 8), (u8)(GTP_REG_RQST & 0xFF), 0}; | |
2089 | #endif | |
2090 | #ifdef TPD_PROXIMITY | |
2091 | s32 err = 0; | |
2092 | hwm_sensor_data sensor_data; | |
2093 | u8 proximity_status; | |
2094 | #endif | |
2095 | #if GTP_CHANGE_X2Y | |
2096 | s32 temp; | |
2097 | #endif | |
2098 | ||
2099 | sched_setscheduler(current, SCHED_RR, ¶m); | |
2100 | ||
2101 | do | |
2102 | { | |
2103 | set_current_state(TASK_INTERRUPTIBLE); | |
2104 | if(tpd_eint_mode) | |
2105 | { | |
2106 | wait_event_interruptible(waiter, tpd_flag != 0); | |
2107 | tpd_flag = 0; | |
2108 | } | |
2109 | else | |
2110 | { | |
2111 | msleep(tpd_polling_time); | |
2112 | } | |
2113 | set_current_state(TASK_RUNNING); | |
2114 | ||
2115 | mutex_lock(&i2c_access); | |
2116 | ||
2117 | if (tpd_halt) | |
2118 | { | |
2119 | mutex_unlock(&i2c_access); | |
2120 | GTP_DEBUG("return for interrupt after suspend... "); | |
2121 | continue; | |
2122 | } | |
2123 | ||
2124 | ret = gtp_i2c_read(i2c_client_point, point_data, 12); | |
2125 | ||
2126 | if (ret < 0) | |
2127 | { | |
2128 | GTP_ERROR("I2C transfer error. errno:%d ", ret); | |
2129 | goto exit_work_func; | |
2130 | } | |
2131 | ||
2132 | finger = point_data[GTP_ADDR_LENGTH]; | |
2133 | ||
2134 | #if GTP_COMPATIBLE_MODE | |
2135 | if ((finger == 0x00) && (CHIP_TYPE_GT9F == gtp_chip_type)) | |
2136 | { | |
2137 | ret = gtp_i2c_read(i2c_client_point, rqst_data, 3); | |
2138 | if (ret < 0) | |
2139 | { | |
2140 | GTP_ERROR("I2C transfer error. errno:%d\n ", ret); | |
2141 | goto exit_work_func; | |
2142 | } | |
2143 | switch(rqst_data[2]&0x0F) | |
2144 | { | |
2145 | case GTP_RQST_BAK_REF: | |
2146 | GTP_INFO("Request Ref."); | |
2147 | ret = gtp_bak_ref_proc(i2c_client_point, GTP_BAK_REF_SEND); | |
2148 | if(SUCCESS == ret) | |
2149 | { | |
2150 | GTP_INFO("Send ref success."); | |
2151 | rqst_data[2] = GTP_RQST_RESPONDED; | |
2152 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
2153 | } | |
2154 | goto exit_work_func; | |
2155 | case GTP_RQST_CONFIG: | |
2156 | GTP_INFO("Request Config."); | |
2157 | ret = gtp_send_cfg(i2c_client_point); | |
2158 | if (ret < 0) | |
2159 | { | |
2160 | GTP_ERROR("Send config error."); | |
2161 | } | |
2162 | else | |
2163 | { | |
2164 | GTP_INFO("Send config success."); | |
2165 | rqst_data[2] = GTP_RQST_RESPONDED; | |
2166 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
2167 | } | |
2168 | goto exit_work_func; | |
2169 | case GTP_RQST_MAIN_CLOCK: | |
2170 | GTP_INFO("Request main clock."); | |
2171 | rqst_processing = 1; | |
2172 | ret = gtp_main_clk_proc(i2c_client_point); | |
2173 | if(SUCCESS == ret) | |
2174 | { | |
2175 | GTP_INFO("Send main clk success."); | |
2176 | rqst_data[2] = GTP_RQST_RESPONDED; | |
2177 | gtp_i2c_write(i2c_client_point, rqst_data, 3); | |
2178 | rqst_processing = 0; | |
2179 | } | |
2180 | goto exit_work_func; | |
2181 | case GTP_RQST_RESET: | |
2182 | GTP_INFO("Request Reset."); | |
2183 | gtp_recovery_reset(i2c_client_point); | |
2184 | goto exit_work_func; | |
2185 | default: | |
2186 | break; | |
2187 | } | |
2188 | } | |
2189 | #endif | |
2190 | ||
2191 | ||
2192 | if ((finger & 0x80) == 0) | |
2193 | { | |
2194 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2195 | mutex_unlock(&i2c_access); | |
2196 | GTP_ERROR("buffer not ready"); | |
2197 | continue; | |
2198 | } | |
2199 | ||
2200 | #ifdef TPD_PROXIMITY | |
2201 | ||
2202 | if (tpd_proximity_flag == 1) | |
2203 | { | |
2204 | proximity_status = point_data[GTP_ADDR_LENGTH]; | |
2205 | GTP_DEBUG("REG INDEX[0x814E]:0x%02X", proximity_status); | |
2206 | ||
2207 | if (proximity_status & 0x60) //proximity or large touch detect,enable hwm_sensor. | |
2208 | { | |
2209 | tpd_proximity_detect = 0; | |
2210 | //sensor_data.values[0] = 0; | |
2211 | } | |
2212 | else | |
2213 | { | |
2214 | tpd_proximity_detect = 1; | |
2215 | //sensor_data.values[0] = 1; | |
2216 | } | |
2217 | ||
2218 | //get raw data | |
2219 | GTP_DEBUG(" ps change"); | |
2220 | GTP_DEBUG("PROXIMITY STATUS:0x%02X", tpd_proximity_detect); | |
2221 | //map and store data to hwm_sensor_data | |
2222 | sensor_data.values[0] = tpd_get_ps_value(); | |
2223 | sensor_data.value_divide = 1; | |
2224 | sensor_data.status = SENSOR_STATUS_ACCURACY_MEDIUM; | |
2225 | //report to the up-layer | |
2226 | ret = hwmsen_get_interrupt_data(ID_PROXIMITY, &sensor_data); | |
2227 | ||
2228 | if (ret) | |
2229 | { | |
2230 | GTP_ERROR("Call hwmsen_get_interrupt_data fail = %d", err); | |
2231 | } | |
2232 | } | |
2233 | ||
2234 | #endif | |
2235 | ||
2236 | touch_num = finger & 0x0f; | |
2237 | ||
2238 | if (touch_num > GTP_MAX_TOUCH) | |
2239 | { | |
2240 | GTP_ERROR("Bad number of fingers!"); | |
2241 | goto exit_work_func; | |
2242 | } | |
2243 | ||
2244 | if (touch_num > 1) | |
2245 | { | |
2246 | u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff}; | |
2247 | ||
2248 | ret = gtp_i2c_read(i2c_client_point, buf, 2 + 8 * (touch_num - 1)); | |
2249 | memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1)); | |
2250 | } | |
2251 | #if GTP_HAVE_TOUCH_KEY | |
2252 | key_value = point_data[3 + 8 * touch_num]; | |
2253 | ||
2254 | if (key_value || pre_key) | |
2255 | { | |
2256 | for (i = 0; i < TPD_KEY_COUNT; i++) | |
2257 | { | |
2258 | //input_report_key(tpd->dev, touch_key_array[i], key_value & (0x01 << i)); | |
2259 | if( key_value&(0x01<<i) ) //key=1 menu ;key=2 home; key =4 back; | |
2260 | { | |
2261 | input_x =touch_key_point_maping_array[i].point_x; | |
2262 | input_y = touch_key_point_maping_array[i].point_y; | |
2263 | GTP_DEBUG("button =%d %d",input_x,input_y); | |
2264 | ||
2265 | tpd_down( input_x, input_y, 0, 0); | |
2266 | } | |
2267 | } | |
2268 | ||
2269 | if((pre_key!=0)&&(key_value ==0)) | |
2270 | { | |
2271 | tpd_up( 0, 0, 0); | |
2272 | } | |
2273 | ||
2274 | touch_num = 0; | |
2275 | pre_touch = 0; | |
2276 | } | |
2277 | ||
2278 | #endif | |
2279 | pre_key = key_value; | |
2280 | ||
2281 | GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger); | |
2282 | ||
2283 | if (touch_num) | |
2284 | { | |
2285 | for (i = 0; i < touch_num; i++) | |
2286 | { | |
2287 | coor_data = &point_data[i * 8 + 3]; | |
2288 | ||
2289 | id = coor_data[0]&0x0F; | |
2290 | input_x = coor_data[1] | coor_data[2] << 8; | |
2291 | input_y = coor_data[3] | coor_data[4] << 8; | |
2292 | input_w = coor_data[5] | coor_data[6] << 8; | |
2293 | ||
2294 | GTP_DEBUG("Original touch point : [X:%04d, Y:%04d]", input_x, input_y); | |
2295 | ||
2296 | input_x = TPD_WARP_X(abs_x_max, input_x); | |
2297 | input_y = TPD_WARP_Y(abs_y_max, input_y); | |
2298 | tpd_calibrate_driver(&input_x, &input_y); | |
2299 | ||
2300 | GTP_DEBUG("Touch point after calibration: [X:%04d, Y:%04d]", input_x, input_y); | |
2301 | ||
2302 | #if GTP_CHANGE_X2Y | |
2303 | temp = input_x; | |
2304 | input_x = input_y; | |
2305 | input_y = temp; | |
2306 | #endif | |
2307 | ||
2308 | tpd_down(input_x, input_y, input_w, id); | |
2309 | } | |
2310 | } | |
2311 | else if (pre_touch) | |
2312 | { | |
2313 | GTP_DEBUG("Touch Release!"); | |
2314 | tpd_up(0, 0, 0); | |
2315 | } | |
2316 | else | |
2317 | { | |
2318 | GTP_DEBUG("Additional Eint!"); | |
2319 | } | |
2320 | pre_touch = touch_num; | |
2321 | //input_report_key(tpd->dev, BTN_TOUCH, (touch_num || key_value)); | |
2322 | ||
2323 | if (tpd != NULL && tpd->dev != NULL) | |
2324 | { | |
2325 | input_sync(tpd->dev); | |
2326 | } | |
2327 | ||
2328 | exit_work_func: | |
2329 | ||
2330 | if (!gtp_rawdiff_mode) | |
2331 | { | |
2332 | ret = gtp_i2c_write(i2c_client_point, end_cmd, 3); | |
2333 | ||
2334 | if (ret < 0) | |
2335 | { | |
2336 | GTP_INFO("I2C write end_cmd error!"); | |
2337 | } | |
2338 | } | |
2339 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2340 | mutex_unlock(&i2c_access); | |
2341 | ||
2342 | } | |
2343 | while (!kthread_should_stop()); | |
2344 | ||
2345 | return 0; | |
2346 | } | |
2347 | ||
2348 | static int tpd_local_init(void) | |
2349 | { | |
2350 | #if GTP_SUPPORT_I2C_DMA | |
2351 | gpDMABuf_va = (u8 *)dma_alloc_coherent(NULL, GTP_DMA_MAX_TRANSACTION_LENGTH, &gpDMABuf_pa, GFP_KERNEL); | |
2352 | if(!gpDMABuf_va){ | |
2353 | GTP_INFO("[Error] Allocate DMA I2C Buffer failed!\n"); | |
2354 | } | |
2355 | #endif | |
2356 | ||
2357 | if (i2c_add_driver(&tpd_i2c_driver) != 0) | |
2358 | { | |
2359 | GTP_INFO("unable to add i2c driver."); | |
2360 | return -1; | |
2361 | } | |
2362 | ||
2363 | if (tpd_load_status == 0) //if(tpd_load_status == 0) // disable auto load touch driver for linux3.0 porting | |
2364 | { | |
2365 | GTP_INFO("add error touch panel driver."); | |
2366 | i2c_del_driver(&tpd_i2c_driver); | |
2367 | return -1; | |
2368 | } | |
2369 | input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, (GTP_MAX_TOUCH-1), 0, 0); | |
2370 | #ifdef TPD_HAVE_BUTTON | |
2371 | tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data | |
2372 | #endif | |
2373 | ||
2374 | #if (defined(TPD_WARP_START) && defined(TPD_WARP_END)) | |
2375 | TPD_DO_WARP = 1; | |
2376 | memcpy(tpd_wb_start, tpd_wb_start_local, TPD_WARP_CNT * 4); | |
2377 | memcpy(tpd_wb_end, tpd_wb_start_local, TPD_WARP_CNT * 4); | |
2378 | #endif | |
2379 | ||
2380 | #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION)) | |
2381 | //memcpy(tpd_calmat, tpd_def_calmat_local, 8 * 4); | |
2382 | //memcpy(tpd_def_calmat, tpd_def_calmat_local, 8 * 4); | |
2383 | if (FACTORY_BOOT == get_boot_mode()) | |
2384 | { | |
2385 | TPD_DEBUG("Factory mode is detected! \n"); | |
2386 | memcpy(tpd_calmat, tpd_def_calmat_local_factory, 8 * 4); | |
2387 | memcpy(tpd_def_calmat, tpd_def_calmat_local_factory, 8 * 4); | |
2388 | } | |
2389 | else | |
2390 | { | |
2391 | TPD_DEBUG("Normal mode is detected! \n"); | |
2392 | memcpy(tpd_calmat, tpd_def_calmat_local_normal, 8 * 4); | |
2393 | memcpy(tpd_def_calmat, tpd_def_calmat_local_normal, 8 * 4); | |
2394 | } | |
2395 | #endif | |
2396 | ||
2397 | // set vendor string | |
2398 | tpd->dev->id.vendor = 0x00; | |
2399 | tpd->dev->id.product = tpd_info.pid; | |
2400 | tpd->dev->id.version = tpd_info.vid; | |
2401 | ||
2402 | GTP_INFO("end %s, %d", __FUNCTION__, __LINE__); | |
2403 | tpd_type_cap = 1; | |
2404 | ||
2405 | return 0; | |
2406 | } | |
2407 | ||
2408 | ||
2409 | /******************************************************* | |
2410 | Function: | |
2411 | Eter sleep function. | |
2412 | ||
2413 | Input: | |
2414 | client:i2c_client. | |
2415 | ||
2416 | Output: | |
2417 | Executive outcomes.0--success,non-0--fail. | |
2418 | *******************************************************/ | |
2419 | static s8 gtp_enter_sleep(struct i2c_client *client) | |
2420 | { | |
2421 | s8 ret = -1; | |
2422 | #if !GTP_POWER_CTRL_SLEEP | |
2423 | s8 retry = 0; | |
2424 | u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5}; | |
2425 | ||
2426 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
2427 | msleep(5); | |
2428 | ||
2429 | while (retry++ < 5) | |
2430 | { | |
2431 | ret = gtp_i2c_write(client, i2c_control_buf, 3); | |
2432 | ||
2433 | if (ret > 0) | |
2434 | { | |
2435 | GTP_INFO("GTP enter sleep!"); | |
2436 | return ret; | |
2437 | } | |
2438 | ||
2439 | msleep(10); | |
2440 | } | |
2441 | ||
2442 | #else | |
2443 | ||
2444 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
2445 | msleep(5); | |
2446 | ||
2447 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
2448 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
2449 | #else | |
2450 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
2451 | #endif | |
2452 | #ifdef TPD_POWER_SOURCE_1800 | |
2453 | hwPowerDown(TPD_POWER_SOURCE_1800, "TP"); | |
2454 | #endif | |
2455 | ||
2456 | GTP_INFO("GTP enter sleep!"); | |
2457 | return 0; | |
2458 | ||
2459 | #endif | |
2460 | GTP_ERROR("GTP send sleep cmd failed."); | |
2461 | return ret; | |
2462 | } | |
2463 | ||
2464 | /******************************************************* | |
2465 | Function: | |
2466 | Wakeup from sleep mode Function. | |
2467 | ||
2468 | Input: | |
2469 | client:i2c_client. | |
2470 | ||
2471 | Output: | |
2472 | Executive outcomes.0--success,non-0--fail. | |
2473 | *******************************************************/ | |
2474 | static s8 gtp_wakeup_sleep(struct i2c_client *client) | |
2475 | { | |
2476 | u8 retry = 0; | |
2477 | s8 ret = -1; | |
2478 | ||
2479 | ||
2480 | GTP_INFO("GTP wakeup begin."); | |
2481 | ||
2482 | ||
2483 | #if GTP_POWER_CTRL_SLEEP | |
2484 | ||
2485 | #if GTP_COMPATIBLE_MODE | |
2486 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
2487 | { | |
2488 | force_reset_guitar(); | |
2489 | GTP_INFO("Esd recovery wakeup."); | |
2490 | return 0; | |
2491 | } | |
2492 | #endif | |
2493 | ||
2494 | while (retry++ < 5) | |
2495 | { | |
2496 | ret = tpd_power_on(client); | |
2497 | ||
2498 | if (ret < 0) | |
2499 | { | |
2500 | GTP_ERROR("I2C Power on ERROR!"); | |
2501 | } | |
2502 | ||
2503 | ret = gtp_send_cfg(client); | |
2504 | ||
2505 | if (ret > 0) | |
2506 | { | |
2507 | GTP_DEBUG("Wakeup sleep send config success."); | |
2508 | return ret; | |
2509 | } | |
2510 | } | |
2511 | ||
2512 | #else | |
2513 | #if GTP_COMPATIBLE_MODE | |
2514 | if (CHIP_TYPE_GT9F == gtp_chip_type) | |
2515 | { | |
2516 | u8 opr_buf[2] = {0}; | |
2517 | ||
2518 | while (retry++ < 10) | |
2519 | { | |
2520 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 1); | |
2521 | msleep(5); | |
2522 | ||
2523 | ret = gtp_i2c_test(client); | |
2524 | ||
2525 | if (ret >= 0) | |
2526 | { | |
2527 | // Hold ss51 & dsp | |
2528 | opr_buf[0] = 0x0C; | |
2529 | ret = i2c_write_bytes(client, 0x4180, opr_buf, 1); | |
2530 | if (ret < 0) | |
2531 | { | |
2532 | GTP_DEBUG("Hold ss51 & dsp I2C error,retry:%d", retry); | |
2533 | continue; | |
2534 | } | |
2535 | ||
2536 | // Confirm hold | |
2537 | opr_buf[0] = 0x00; | |
2538 | ret = i2c_read_bytes(client, 0x4180, opr_buf, 1); | |
2539 | if (ret < 0) | |
2540 | { | |
2541 | GTP_DEBUG("confirm ss51 & dsp hold, I2C error,retry:%d", retry); | |
2542 | continue; | |
2543 | } | |
2544 | if (0x0C != opr_buf[0]) | |
2545 | { | |
2546 | GTP_DEBUG("ss51 & dsp not hold, val: %d, retry: %d", opr_buf[0], retry); | |
2547 | continue; | |
2548 | } | |
2549 | GTP_DEBUG("ss51 & dsp has been hold"); | |
2550 | ||
2551 | ret = gtp_fw_startup(client); | |
2552 | if (FAIL == ret) | |
2553 | { | |
2554 | GTP_ERROR("[gtp_wakeup_sleep]Startup fw failed."); | |
2555 | continue; | |
2556 | } | |
2557 | GTP_INFO("flashless wakeup sleep success"); | |
2558 | return ret; | |
2559 | } | |
2560 | force_reset_guitar(); | |
2561 | } | |
2562 | if (retry >= 10) | |
2563 | { | |
2564 | GTP_ERROR("wakeup retry timeout, process esd reset"); | |
2565 | force_reset_guitar(); | |
2566 | } | |
2567 | GTP_ERROR("GTP wakeup sleep failed."); | |
2568 | return ret; | |
2569 | } | |
2570 | #endif | |
2571 | while (retry++ < 10) | |
2572 | { | |
2573 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 1); | |
2574 | msleep(5); | |
2575 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
2576 | msleep(5); | |
2577 | ret = gtp_i2c_test(client); | |
2578 | ||
2579 | if (ret >= 0) | |
2580 | { | |
2581 | gtp_int_sync(50); | |
2582 | return ret; | |
2583 | } | |
2584 | ||
2585 | gtp_reset_guitar(client, 20); | |
2586 | } | |
2587 | ||
2588 | #endif | |
2589 | ||
2590 | GTP_ERROR("GTP wakeup sleep failed."); | |
2591 | return ret; | |
2592 | } | |
2593 | /* Function to manage low power suspend */ | |
2594 | static void tpd_suspend(struct early_suspend *h) | |
2595 | { | |
2596 | s32 ret = -1; | |
2597 | mutex_lock(&i2c_access); | |
2598 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
2599 | tpd_halt = 1; | |
2600 | mutex_unlock(&i2c_access); | |
2601 | ||
2602 | ret = gtp_enter_sleep(i2c_client_point); | |
2603 | if (ret < 0) | |
2604 | { | |
2605 | GTP_ERROR("GTP early suspend failed."); | |
2606 | } | |
2607 | ||
2608 | #if GTP_ESD_PROTECT | |
2609 | cancel_delayed_work_sync(>p_esd_check_work); | |
2610 | #endif | |
2611 | ||
2612 | #ifdef GTP_CHARGER_DETECT | |
2613 | cancel_delayed_work_sync(>p_charger_check_work); | |
2614 | #endif | |
2615 | #ifdef TPD_PROXIMITY | |
2616 | ||
2617 | if (tpd_proximity_flag == 1) | |
2618 | { | |
2619 | return ; | |
2620 | } | |
2621 | ||
2622 | #endif | |
2623 | } | |
2624 | ||
2625 | /* Function to manage power-on resume */ | |
2626 | static void tpd_resume(struct early_suspend *h) | |
2627 | { | |
2628 | s32 ret = -1; | |
2629 | ||
2630 | ret = gtp_wakeup_sleep(i2c_client_point); | |
2631 | ||
2632 | if (ret < 0) | |
2633 | { | |
2634 | GTP_ERROR("GTP later resume failed."); | |
2635 | } | |
2636 | ||
2637 | GTP_INFO("GTP wakeup sleep."); | |
2638 | ||
2639 | mutex_lock(&i2c_access); | |
2640 | tpd_halt = 0; | |
2641 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2642 | mutex_unlock(&i2c_access); | |
2643 | ||
2644 | #ifdef TPD_PROXIMITY | |
2645 | if (tpd_proximity_flag == 1) | |
2646 | { | |
2647 | return ; | |
2648 | } | |
2649 | #endif | |
2650 | ||
2651 | #if GTP_ESD_PROTECT | |
2652 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, TPD_ESD_CHECK_CIRCLE); | |
2653 | #endif | |
2654 | ||
2655 | #ifdef GTP_CHARGER_DETECT | |
2656 | queue_delayed_work(gtp_charger_check_workqueue, >p_charger_check_work, TPD_CHARGER_CHECK_CIRCLE); | |
2657 | #endif | |
2658 | ||
2659 | } | |
2660 | ||
2661 | static void tpd_off(void) | |
2662 | { | |
2663 | ||
2664 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
2665 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
2666 | #else | |
2667 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
2668 | #endif | |
2669 | #ifdef TPD_POWER_SOURCE_1800 | |
2670 | hwPowerDown(TPD_POWER_SOURCE_1800, "TP"); | |
2671 | #endif | |
2672 | GTP_INFO("GTP enter sleep!"); | |
2673 | ||
2674 | tpd_halt = 1; | |
2675 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
2676 | } | |
2677 | ||
2678 | static void tpd_on(void) | |
2679 | { | |
2680 | s32 ret = -1, retry = 0; | |
2681 | ||
2682 | while (retry++ < 5) | |
2683 | { | |
2684 | ret = tpd_power_on(i2c_client_point); | |
2685 | ||
2686 | if (ret < 0) | |
2687 | { | |
2688 | GTP_ERROR("I2C Power on ERROR!"); | |
2689 | } | |
2690 | ||
2691 | ret = gtp_send_cfg(i2c_client_point); | |
2692 | ||
2693 | if (ret > 0) | |
2694 | { | |
2695 | GTP_DEBUG("Wakeup sleep send config success."); | |
2696 | } | |
2697 | } | |
2698 | if (ret < 0) | |
2699 | { | |
2700 | GTP_ERROR("GTP later resume failed."); | |
2701 | } | |
2702 | ||
2703 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2704 | tpd_halt = 0; | |
2705 | } | |
2706 | static struct tpd_driver_t tpd_device_driver = | |
2707 | { | |
2708 | .tpd_device_name = "gt9xx", | |
2709 | .tpd_local_init = tpd_local_init, | |
2710 | .suspend = tpd_suspend, | |
2711 | .resume = tpd_resume, | |
2712 | #ifdef TPD_HAVE_BUTTON | |
2713 | .tpd_have_button = 1, | |
2714 | #else | |
2715 | .tpd_have_button = 0, | |
2716 | #endif | |
2717 | .attrs = { | |
2718 | .attr = gt9xx_attrs, | |
2719 | .num = ARRAY_SIZE(gt9xx_attrs), | |
2720 | }, | |
2721 | }; | |
2722 | ||
2723 | /* called when loaded into kernel */ | |
2724 | static int __init tpd_driver_init(void) | |
2725 | { | |
2726 | GTP_INFO("MediaTek gt91xx touch panel driver init"); | |
2727 | #if defined(TPD_I2C_NUMBER) | |
2728 | i2c_register_board_info(TPD_I2C_NUMBER, &i2c_tpd, 1); | |
2729 | #else | |
2730 | i2c_register_board_info(0, &i2c_tpd, 1); | |
2731 | #endif | |
2732 | if (tpd_driver_add(&tpd_device_driver) < 0) | |
2733 | GTP_INFO("add generic driver failed"); | |
2734 | ||
2735 | return 0; | |
2736 | } | |
2737 | ||
2738 | /* should never be called */ | |
2739 | static void __exit tpd_driver_exit(void) | |
2740 | { | |
2741 | GTP_INFO("MediaTek gt91xx touch panel driver exit"); | |
2742 | //input_unregister_device(tpd->dev); | |
2743 | tpd_driver_remove(&tpd_device_driver); | |
2744 | } | |
2745 | ||
2746 | module_init(tpd_driver_init); | |
2747 | module_exit(tpd_driver_exit); | |
2748 |