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 | ||
13 | #include <linux/mmprofile.h> | |
14 | #include <linux/device.h> | |
15 | #include <linux/proc_fs.h> /*proc*/ | |
16 | extern struct tpd_device *tpd; | |
17 | #ifdef VELOCITY_CUSTOM | |
18 | extern int tpd_v_magnify_x; | |
19 | extern int tpd_v_magnify_y; | |
20 | #endif | |
21 | static int tpd_flag = 0; | |
22 | static int tpd_halt = 0; | |
23 | static int tpd_eint_mode=1; | |
24 | static int tpd_polling_time=50; | |
25 | static DECLARE_WAIT_QUEUE_HEAD(waiter); | |
26 | static DEFINE_MUTEX(i2c_access); | |
27 | ||
28 | #ifdef TPD_HAVE_BUTTON | |
29 | static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS; | |
30 | static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM; | |
31 | #endif | |
32 | ||
33 | #if GTP_HAVE_TOUCH_KEY | |
34 | const u16 touch_key_array[] = TPD_KEYS; | |
35 | //#define GTP_MAX_KEY_NUM ( sizeof( touch_key_array )/sizeof( touch_key_array[0] ) ) | |
36 | struct touch_vitual_key_map_t | |
37 | { | |
38 | int point_x; | |
39 | int point_y; | |
40 | }; | |
41 | static struct touch_vitual_key_map_t touch_key_point_maping_array[]=GTP_KEY_MAP_ARRAY; | |
42 | #endif | |
43 | ||
44 | #if (defined(TPD_WARP_START) && defined(TPD_WARP_END)) | |
45 | static int tpd_wb_start_local[TPD_WARP_CNT] = TPD_WARP_START; | |
46 | static int tpd_wb_end_local[TPD_WARP_CNT] = TPD_WARP_END; | |
47 | #endif | |
48 | ||
49 | #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION)) | |
50 | //static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX; | |
51 | //static int tpd_def_calmat_local[8] = TPD_CALIBRATION_MATRIX; | |
52 | static int tpd_def_calmat_local_normal[8] = TPD_CALIBRATION_MATRIX_ROTATION_NORMAL; | |
53 | static int tpd_def_calmat_local_factory[8] = TPD_CALIBRATION_MATRIX_ROTATION_FACTORY; | |
54 | #endif | |
55 | ||
56 | s32 gtp_send_cfg(struct i2c_client *client); | |
57 | static void tpd_eint_interrupt_handler(void); | |
58 | static int touch_event_handler(void *unused); | |
59 | static int tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id); | |
60 | static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info); | |
61 | static int tpd_i2c_remove(struct i2c_client *client); | |
62 | static void tpd_on(void); | |
63 | static void tpd_off(void); | |
64 | ||
65 | #if GTP_CREATE_WR_NODE | |
66 | extern s32 init_wr_node(struct i2c_client *); | |
67 | extern void uninit_wr_node(void); | |
68 | #endif | |
69 | ||
70 | #ifdef GTP_CHARGER_DETECT | |
71 | extern bool upmu_get_pchr_chrdet(void); | |
72 | #define TPD_CHARGER_CHECK_CIRCLE 50 | |
73 | static struct delayed_work gtp_charger_check_work; | |
74 | static struct workqueue_struct *gtp_charger_check_workqueue = NULL; | |
75 | static void gtp_charger_check_func(struct work_struct *); | |
76 | static u8 gtp_charger_mode = 0; | |
77 | #endif | |
78 | ||
79 | #if GTP_ESD_PROTECT | |
80 | #define TPD_ESD_CHECK_CIRCLE 2000 | |
81 | static struct delayed_work gtp_esd_check_work; | |
82 | static struct workqueue_struct *gtp_esd_check_workqueue = NULL; | |
83 | static void gtp_esd_check_func(struct work_struct *); | |
84 | #endif | |
85 | ||
86 | #ifdef TPD_PROXIMITY | |
87 | #define TPD_PROXIMITY_VALID_REG 0x814E | |
88 | #define TPD_PROXIMITY_ENABLE_REG 0x8042 | |
89 | static u8 tpd_proximity_flag = 0; | |
90 | static u8 tpd_proximity_detect = 1;//0-->close ; 1--> far away | |
91 | #endif | |
92 | ||
93 | #ifndef GTP_REG_REFRESH_RATE | |
94 | #define GTP_REG_REFRESH_RATE 0x8056 | |
95 | #endif | |
96 | ||
97 | struct i2c_client *i2c_client_point = NULL; | |
98 | static const struct i2c_device_id tpd_i2c_id[] = {{"gt9xx", 0}, {}}; | |
99 | static unsigned short force[] = {0, 0xBA, I2C_CLIENT_END, I2C_CLIENT_END}; | |
100 | static const unsigned short *const forces[] = { force, NULL }; | |
101 | //static struct i2c_client_address_data addr_data = { .forces = forces,}; | |
102 | static struct i2c_board_info __initdata i2c_tpd = { I2C_BOARD_INFO("gt9xx", (0xBA >> 1))}; | |
103 | static struct i2c_driver tpd_i2c_driver = | |
104 | { | |
105 | .probe = tpd_i2c_probe, | |
106 | .remove = tpd_i2c_remove, | |
107 | .detect = tpd_i2c_detect, | |
108 | .driver.name = "gt9xx", | |
109 | .id_table = tpd_i2c_id, | |
110 | .address_list = (const unsigned short *) forces, | |
111 | }; | |
112 | ||
113 | static u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] | |
114 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
115 | #ifdef GTP_CHARGER_DETECT | |
116 | static u8 config_charger[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] | |
117 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
118 | #endif | |
119 | #pragma pack(1) | |
120 | typedef struct | |
121 | { | |
122 | u16 pid; //product id // | |
123 | u16 vid; //version id // | |
124 | } st_tpd_info; | |
125 | #pragma pack() | |
126 | ||
127 | st_tpd_info tpd_info; | |
128 | u8 int_type = 0; | |
129 | u32 abs_x_max = 0; | |
130 | u32 abs_y_max = 0; | |
131 | u8 gtp_rawdiff_mode = 0; | |
132 | u8 cfg_len = 0; | |
133 | ||
134 | /* proc file system */ | |
135 | s32 i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len); | |
136 | s32 i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len); | |
137 | static struct proc_dir_entry *gt91xx_config_proc = NULL; | |
138 | ||
139 | /******************************************************* | |
140 | Function: | |
141 | Write refresh rate | |
142 | ||
143 | Input: | |
144 | rate: refresh rate N (Duration=5+N ms, N=0~15) | |
145 | ||
146 | Output: | |
147 | Executive outcomes.0---succeed. | |
148 | *******************************************************/ | |
149 | static u8 gtp_set_refresh_rate(u8 rate) | |
150 | { | |
151 | u8 buf[3] = {GTP_REG_REFRESH_RATE>>8, GTP_REG_REFRESH_RATE& 0xff, rate}; | |
152 | ||
153 | if (rate > 0xf) | |
154 | { | |
155 | GTP_ERROR("Refresh rate is over range (%d)", rate); | |
156 | return FAIL; | |
157 | } | |
158 | ||
159 | GTP_INFO("Refresh rate change to %d", rate); | |
160 | return gtp_i2c_write(i2c_client_point, buf, sizeof(buf)); | |
161 | } | |
162 | ||
163 | /******************************************************* | |
164 | Function: | |
165 | Get refresh rate | |
166 | ||
167 | Output: | |
168 | Refresh rate or error code | |
169 | *******************************************************/ | |
170 | static u8 gtp_get_refresh_rate(void) | |
171 | { | |
172 | int ret; | |
173 | ||
174 | u8 buf[3] = {GTP_REG_REFRESH_RATE>>8, GTP_REG_REFRESH_RATE& 0xff}; | |
175 | ret = gtp_i2c_read(i2c_client_point, buf, sizeof(buf)); | |
176 | if (ret < 0) | |
177 | return ret; | |
178 | ||
179 | GTP_INFO("Refresh rate is %d", buf[GTP_ADDR_LENGTH]); | |
180 | return buf[GTP_ADDR_LENGTH]; | |
181 | } | |
182 | ||
183 | //============================================================= | |
184 | static ssize_t show_refresh_rate(struct device *dev,struct device_attribute *attr, char *buf) | |
185 | { | |
186 | int ret = gtp_get_refresh_rate(); | |
187 | if (ret < 0) | |
188 | return 0; | |
189 | else | |
190 | return sprintf(buf, "%d\n", ret); | |
191 | } | |
192 | static ssize_t store_refresh_rate(struct device *dev,struct device_attribute *attr, const char *buf, size_t size) | |
193 | { | |
194 | //u32 rate = 0; | |
195 | gtp_set_refresh_rate(simple_strtoul(buf, NULL, 16)); | |
196 | return size; | |
197 | } | |
198 | static DEVICE_ATTR(tpd_refresh_rate, 0664, show_refresh_rate, store_refresh_rate); | |
199 | ||
200 | static struct device_attribute *gt9xx_attrs[] = | |
201 | { | |
202 | &dev_attr_tpd_refresh_rate, | |
203 | }; | |
204 | //============================================================= | |
205 | ||
206 | static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info) | |
207 | { | |
208 | strcpy(info->type, "mtk-tpd"); | |
209 | return 0; | |
210 | } | |
211 | ||
212 | #ifdef TPD_PROXIMITY | |
213 | static s32 tpd_get_ps_value(void) | |
214 | { | |
215 | return tpd_proximity_detect; | |
216 | } | |
217 | ||
218 | static s32 tpd_enable_ps(s32 enable) | |
219 | { | |
220 | u8 state; | |
221 | s32 ret = -1; | |
222 | ||
223 | if (enable) | |
224 | { | |
225 | state = 1; | |
226 | tpd_proximity_flag = 1; | |
227 | GTP_INFO("TPD proximity function to be on."); | |
228 | } | |
229 | else | |
230 | { | |
231 | state = 0; | |
232 | tpd_proximity_flag = 0; | |
233 | GTP_INFO("TPD proximity function to be off."); | |
234 | } | |
235 | ||
236 | ret = i2c_write_bytes(i2c_client_point, TPD_PROXIMITY_ENABLE_REG, &state, 1); | |
237 | ||
238 | if (ret < 0) | |
239 | { | |
240 | GTP_ERROR("TPD %s proximity cmd failed.", state ? "enable" : "disable"); | |
241 | return ret; | |
242 | } | |
243 | ||
244 | GTP_INFO("TPD proximity function %s success.", state ? "enable" : "disable"); | |
245 | return 0; | |
246 | } | |
247 | ||
248 | s32 tpd_ps_operate(void *self, u32 command, void *buff_in, s32 size_in, | |
249 | void *buff_out, s32 size_out, s32 *actualout) | |
250 | { | |
251 | s32 err = 0; | |
252 | s32 value; | |
253 | hwm_sensor_data *sensor_data; | |
254 | ||
255 | switch (command) | |
256 | { | |
257 | case SENSOR_DELAY: | |
258 | if ((buff_in == NULL) || (size_in < sizeof(int))) | |
259 | { | |
260 | GTP_ERROR("Set delay parameter error!"); | |
261 | err = -EINVAL; | |
262 | } | |
263 | ||
264 | // Do nothing | |
265 | break; | |
266 | ||
267 | case SENSOR_ENABLE: | |
268 | if ((buff_in == NULL) || (size_in < sizeof(int))) | |
269 | { | |
270 | GTP_ERROR("Enable sensor parameter error!"); | |
271 | err = -EINVAL; | |
272 | } | |
273 | else | |
274 | { | |
275 | value = *(int *)buff_in; | |
276 | err = tpd_enable_ps(value); | |
277 | } | |
278 | ||
279 | break; | |
280 | ||
281 | case SENSOR_GET_DATA: | |
282 | if ((buff_out == NULL) || (size_out < sizeof(hwm_sensor_data))) | |
283 | { | |
284 | GTP_ERROR("Get sensor data parameter error!"); | |
285 | err = -EINVAL; | |
286 | } | |
287 | else | |
288 | { | |
289 | sensor_data = (hwm_sensor_data *)buff_out; | |
290 | sensor_data->values[0] = tpd_get_ps_value(); | |
291 | sensor_data->value_divide = 1; | |
292 | sensor_data->status = SENSOR_STATUS_ACCURACY_MEDIUM; | |
293 | } | |
294 | ||
295 | break; | |
296 | ||
297 | default: | |
298 | GTP_ERROR("proxmy sensor operate function no this parameter %d!", command); | |
299 | err = -1; | |
300 | break; | |
301 | } | |
302 | ||
303 | return err; | |
304 | } | |
305 | #endif | |
306 | ||
307 | static int gt91xx_config_read_proc(struct file *file, char *buffer, size_t count, loff_t *ppos) | |
308 | { | |
309 | char *page = NULL; | |
310 | char *ptr = NULL; | |
311 | char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0}; | |
312 | int i, len, err = -1; | |
313 | ||
314 | page = kmalloc(PAGE_SIZE, GFP_KERNEL); | |
315 | if (!page) | |
316 | { | |
317 | kfree(page); | |
318 | return -ENOMEM; | |
319 | } | |
320 | ||
321 | ptr = page; | |
322 | ptr += sprintf(ptr, "==== GT9XX config init value====\n"); | |
323 | ||
324 | for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++) | |
325 | { | |
326 | ptr += sprintf(ptr, "0x%02X ", config[i + 2]); | |
327 | ||
328 | if (i % 8 == 7) | |
329 | ptr += sprintf(ptr, "\n"); | |
330 | } | |
331 | ||
332 | ptr += sprintf(ptr, "\n"); | |
333 | ||
334 | ptr += sprintf(ptr, "==== GT9XX config real value====\n"); | |
335 | i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, temp_data, GTP_CONFIG_MAX_LENGTH); | |
336 | ||
337 | for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++) | |
338 | { | |
339 | ptr += sprintf(ptr, "0x%02X ", temp_data[i]); | |
340 | ||
341 | if (i % 8 == 7) | |
342 | ptr += sprintf(ptr, "\n"); | |
343 | } | |
344 | /* Touch PID & VID */ | |
345 | ptr += sprintf(ptr, "\n"); | |
346 | ptr += sprintf(ptr, "==== GT9XX Version ID ====\n"); | |
347 | i2c_read_bytes(i2c_client_point, GTP_REG_VERSION, temp_data, 6); | |
348 | 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]); | |
349 | ptr += sprintf(ptr, "Driver VID: 0x%02X%02X\n", gtp_default_FW[12], gtp_default_FW[13]); | |
350 | i2c_read_bytes(i2c_client_point, 0x41E4, temp_data, 1); | |
351 | ptr += sprintf(ptr, "Boot status 0x%X\n", temp_data[0]); | |
352 | ||
353 | /* Touch Status and Clock Gate */ | |
354 | ptr += sprintf(ptr, "\n"); | |
355 | ptr += sprintf(ptr, "==== Touch Status and Clock Gate ====\n"); | |
356 | ptr += sprintf(ptr, "status: 1: on, 0 :off\n"); | |
357 | ptr += sprintf(ptr, "status:%d\n", (tpd_halt+1)&0x1); | |
358 | ||
359 | ||
360 | len = ptr - page; | |
361 | if(*ppos >= len) | |
362 | { | |
363 | kfree(page); | |
364 | return 0; | |
365 | } | |
366 | err = copy_to_user(buffer,(char *)page,len); | |
367 | *ppos += len; | |
368 | if(err) | |
369 | { | |
370 | kfree(page); | |
371 | return err; | |
372 | } | |
373 | kfree(page); | |
374 | return len; | |
375 | ||
376 | //return (ptr - page); | |
377 | } | |
378 | ||
379 | static int gt91xx_config_write_proc(struct file *file, const char *buffer, size_t count, loff_t *ppos) | |
380 | { | |
381 | s32 ret = 0; | |
382 | char temp[25] = {0}; // for store special format cmd | |
383 | char mode_str[15] = {0}; | |
384 | unsigned int mode; | |
385 | u8 buf[1]; | |
386 | ||
387 | GTP_DEBUG("write count %ld\n", (unsigned long)count); | |
388 | ||
389 | if (count > GTP_CONFIG_MAX_LENGTH) | |
390 | { | |
391 | GTP_ERROR("size not match [%d:%ld]", GTP_CONFIG_MAX_LENGTH, (unsigned long)count); | |
392 | return -EFAULT; | |
393 | } | |
394 | ||
395 | /**********************************************/ | |
396 | /* for store special format cmd */ | |
397 | if (copy_from_user(temp, buffer, sizeof(temp))) | |
398 | { | |
399 | GTP_ERROR("copy from user fail 2"); | |
400 | return -EFAULT; | |
401 | } | |
402 | sscanf(temp, "%s %d", (char *)&mode_str, &mode); | |
403 | ||
404 | /***********POLLING/EINT MODE switch****************/ | |
405 | if(strcmp(mode_str, "polling") == 0) | |
406 | { | |
407 | if(mode>=10&&mode<=200) | |
408 | { | |
409 | GTP_INFO("Switch to polling mode, polling time is %d",mode); | |
410 | tpd_eint_mode=0; | |
411 | tpd_polling_time=mode; | |
412 | tpd_flag = 1; | |
413 | wake_up_interruptible(&waiter); | |
414 | } | |
415 | else | |
416 | { | |
417 | GTP_INFO("Wrong polling time, please set between 10~200ms"); | |
418 | } | |
419 | return count; | |
420 | } | |
421 | if(strcmp(mode_str, "eint") == 0) | |
422 | { | |
423 | GTP_INFO("Switch to eint mode"); | |
424 | tpd_eint_mode=1; | |
425 | return count; | |
426 | } | |
427 | /**********************************************/ | |
428 | if(strcmp(mode_str, "switch") == 0) | |
429 | { | |
430 | if(mode == 0)// turn off | |
431 | tpd_off(); | |
432 | else if(mode == 1)//turn on | |
433 | tpd_on(); | |
434 | else | |
435 | GTP_ERROR("error mode :%d", mode); | |
436 | return count; | |
437 | } | |
438 | //force clear config | |
439 | if(strcmp(mode_str, "clear_config") == 0) | |
440 | { | |
441 | GTP_INFO("Force clear config"); | |
442 | buf[0] = 0x10; | |
443 | ret = i2c_write_bytes(i2c_client_point, GTP_REG_SLEEP, buf, 1); | |
444 | return count; | |
445 | } | |
446 | ||
447 | if (copy_from_user(&config[2], buffer, count)) | |
448 | { | |
449 | GTP_ERROR("copy from user fail"); | |
450 | return -EFAULT; | |
451 | } | |
452 | ||
453 | /***********clk operate reseved****************/ | |
454 | /**********************************************/ | |
455 | ret = gtp_send_cfg(i2c_client_point); | |
456 | abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; | |
457 | abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; | |
458 | int_type = (config[TRIGGER_LOC]) & 0x03; | |
459 | ||
460 | if (ret < 0) | |
461 | { | |
462 | GTP_ERROR("send config failed."); | |
463 | } | |
464 | ||
465 | return count; | |
466 | } | |
467 | ||
468 | int i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len) | |
469 | { | |
470 | u8 buffer[GTP_ADDR_LENGTH]; | |
471 | u16 left = len; | |
472 | u16 offset = 0; | |
473 | ||
474 | struct i2c_msg msg[2] = | |
475 | { | |
476 | { | |
477 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
478 | //.addr = (client->addr &I2C_MASK_FLAG), | |
479 | //.ext_flag = I2C_ENEXT_FLAG, | |
480 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
481 | .flags = 0, | |
482 | .buf = buffer, | |
483 | .len = GTP_ADDR_LENGTH, | |
484 | .timing = I2C_MASTER_CLOCK | |
485 | }, | |
486 | { | |
487 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
488 | //.addr = (client->addr &I2C_MASK_FLAG), | |
489 | //.ext_flag = I2C_ENEXT_FLAG, | |
490 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
491 | .flags = I2C_M_RD, | |
492 | .timing = I2C_MASTER_CLOCK | |
493 | }, | |
494 | }; | |
495 | ||
496 | if (rxbuf == NULL) | |
497 | return -1; | |
498 | ||
499 | GTP_DEBUG("i2c_read_bytes to device %02X address %04X len %d", client->addr, addr, len); | |
500 | ||
501 | while (left > 0) | |
502 | { | |
503 | buffer[0] = ((addr + offset) >> 8) & 0xFF; | |
504 | buffer[1] = (addr + offset) & 0xFF; | |
505 | ||
506 | msg[1].buf = &rxbuf[offset]; | |
507 | ||
508 | if (left > MAX_TRANSACTION_LENGTH) | |
509 | { | |
510 | msg[1].len = MAX_TRANSACTION_LENGTH; | |
511 | left -= MAX_TRANSACTION_LENGTH; | |
512 | offset += MAX_TRANSACTION_LENGTH; | |
513 | } | |
514 | else | |
515 | { | |
516 | msg[1].len = left; | |
517 | left = 0; | |
518 | } | |
519 | ||
520 | if (i2c_transfer(client->adapter, &msg[0], 2) != 2) | |
521 | { | |
522 | GTP_ERROR("I2C read 0x%X length=%d failed", addr + offset, len); | |
523 | return -1; | |
524 | } | |
525 | } | |
526 | ||
527 | return 0; | |
528 | } | |
529 | ||
530 | s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len) | |
531 | { | |
532 | s32 ret = -1; | |
533 | u16 addr = (buf[0] << 8) + buf[1]; | |
534 | ||
535 | ret = i2c_read_bytes(client, addr, &buf[2], len - 2); | |
536 | ||
537 | if (!ret) | |
538 | { | |
539 | return 2; | |
540 | } | |
541 | else | |
542 | { | |
543 | gtp_reset_guitar(client, 20); | |
544 | return ret; | |
545 | } | |
546 | } | |
547 | ||
548 | int i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *txbuf, int len) | |
549 | { | |
550 | u8 buffer[MAX_TRANSACTION_LENGTH]; | |
551 | u16 left = len; | |
552 | u16 offset = 0; | |
553 | ||
554 | struct i2c_msg msg = | |
555 | { | |
556 | .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)), | |
557 | //.addr = (client->addr &I2C_MASK_FLAG), | |
558 | //.ext_flag = I2C_ENEXT_FLAG, | |
559 | //.addr = ((client->addr &I2C_MASK_FLAG) | (I2C_PUSHPULL_FLAG)), | |
560 | .flags = 0, | |
561 | .buf = buffer, | |
562 | .timing = I2C_MASTER_CLOCK, | |
563 | }; | |
564 | ||
565 | ||
566 | if (txbuf == NULL) | |
567 | return -1; | |
568 | ||
569 | GTP_DEBUG("i2c_write_bytes to device %02X address %04X len %d", client->addr, addr, len); | |
570 | ||
571 | while (left > 0) | |
572 | { | |
573 | buffer[0] = ((addr + offset) >> 8) & 0xFF; | |
574 | buffer[1] = (addr + offset) & 0xFF; | |
575 | ||
576 | if (left > MAX_I2C_TRANSFER_SIZE) | |
577 | { | |
578 | memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], MAX_I2C_TRANSFER_SIZE); | |
579 | msg.len = MAX_TRANSACTION_LENGTH; | |
580 | left -= MAX_I2C_TRANSFER_SIZE; | |
581 | offset += MAX_I2C_TRANSFER_SIZE; | |
582 | } | |
583 | else | |
584 | { | |
585 | memcpy(&buffer[GTP_ADDR_LENGTH], &txbuf[offset], left); | |
586 | msg.len = left + GTP_ADDR_LENGTH; | |
587 | left = 0; | |
588 | } | |
589 | ||
590 | //GTP_DEBUG("byte left %d offset %d", left, offset); | |
591 | ||
592 | if (i2c_transfer(client->adapter, &msg, 1) != 1) | |
593 | { | |
594 | GTP_ERROR("I2C write 0x%X%X length=%d failed", buffer[0], buffer[1], len); | |
595 | return -1; | |
596 | } | |
597 | } | |
598 | ||
599 | return 0; | |
600 | } | |
601 | ||
602 | s32 gtp_i2c_write(struct i2c_client *client, u8 *buf, s32 len) | |
603 | { | |
604 | s32 ret = -1; | |
605 | u16 addr = (buf[0] << 8) + buf[1]; | |
606 | ||
607 | ret = i2c_write_bytes(client, addr, &buf[2], len - 2); | |
608 | ||
609 | if (!ret) | |
610 | { | |
611 | return 1; | |
612 | } | |
613 | else | |
614 | { | |
615 | gtp_reset_guitar(client, 20); | |
616 | return ret; | |
617 | } | |
618 | } | |
619 | ||
620 | ||
621 | ||
622 | /******************************************************* | |
623 | Function: | |
624 | Send config Function. | |
625 | ||
626 | Input: | |
627 | client: i2c client. | |
628 | ||
629 | Output: | |
630 | Executive outcomes.0--success,non-0--fail. | |
631 | *******************************************************/ | |
632 | s32 gtp_send_cfg(struct i2c_client *client) | |
633 | { | |
634 | s32 ret = 0; | |
635 | #if GTP_DRIVER_SEND_CFG | |
636 | s32 retry = 0; | |
637 | ||
638 | for (retry = 0; retry < 5; retry++) | |
639 | { | |
640 | #ifdef GTP_CHARGER_DETECT | |
641 | ||
642 | if (gtp_charger_mode == 1) | |
643 | { | |
644 | GTP_DEBUG("Write charger config"); | |
645 | ret = gtp_i2c_write(client, config_charger , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
646 | } | |
647 | else | |
648 | { | |
649 | GTP_DEBUG("Write normal config"); | |
650 | ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
651 | } | |
652 | ||
653 | #else | |
654 | ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
655 | #endif | |
656 | ||
657 | ||
658 | if (ret > 0) | |
659 | { | |
660 | break; | |
661 | } | |
662 | } | |
663 | ||
664 | #endif | |
665 | ||
666 | return ret; | |
667 | } | |
668 | ||
669 | /******************************************************* | |
670 | Function: | |
671 | Read goodix touchscreen version function. | |
672 | ||
673 | Input: | |
674 | client: i2c client struct. | |
675 | version:address to store version info | |
676 | ||
677 | Output: | |
678 | Executive outcomes.0---succeed. | |
679 | *******************************************************/ | |
680 | s32 gtp_read_version(struct i2c_client *client, u16 *version) | |
681 | { | |
682 | s32 ret = -1; | |
683 | s32 i; | |
684 | u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff}; | |
685 | ||
686 | GTP_DEBUG_FUNC(); | |
687 | ||
688 | ret = gtp_i2c_read(client, buf, sizeof(buf)); | |
689 | ||
690 | if (ret < 0) | |
691 | { | |
692 | GTP_ERROR("GTP read version failed"); | |
693 | return ret; | |
694 | } | |
695 | ||
696 | if (version) | |
697 | { | |
698 | *version = (buf[7] << 8) | buf[6]; | |
699 | } | |
700 | ||
701 | tpd_info.vid = *version; | |
702 | tpd_info.pid = 0x00; | |
703 | ||
704 | //for gt9xx series | |
705 | for (i = 0; i < 3; i++) | |
706 | { | |
707 | if (buf[i + 2] < 0x30)break; | |
708 | ||
709 | tpd_info.pid |= ((buf[i + 2] - 0x30) << ((2 - i) * 4)); | |
710 | } | |
711 | ||
712 | GTP_INFO("IC VERSION:%c%c%c_%02x%02x", | |
713 | buf[2], buf[3], buf[4], buf[7], buf[6]); | |
714 | ||
715 | return ret; | |
716 | } | |
717 | /******************************************************* | |
718 | Function: | |
719 | GTP initialize function. | |
720 | ||
721 | Input: | |
722 | client: i2c client private struct. | |
723 | ||
724 | Output: | |
725 | Executive outcomes.0---succeed. | |
726 | *******************************************************/ | |
727 | static s32 gtp_init_panel(struct i2c_client *client) | |
728 | { | |
729 | s32 ret = -1; | |
730 | ||
731 | #if GTP_DRIVER_SEND_CFG | |
732 | s32 i; | |
733 | u8 check_sum = 0; | |
734 | u8 rd_cfg_buf[16]; | |
735 | ||
736 | u8 cfg_info_group1[] = CTP_CFG_GROUP1; | |
737 | u8 cfg_info_group2[] = CTP_CFG_GROUP2; | |
738 | u8 cfg_info_group3[] = CTP_CFG_GROUP3; | |
739 | u8 *send_cfg_buf[3] = {cfg_info_group1, cfg_info_group2, cfg_info_group3}; | |
740 | #ifdef GTP_CHARGER_DETECT | |
741 | u8 cfg_info_group1_charger[] = CTP_CFG_GROUP1_CHARGER; | |
742 | u8 cfg_info_group2_charger[] = CTP_CFG_GROUP2_CHARGER; | |
743 | u8 cfg_info_group3_charger[] = CTP_CFG_GROUP3_CHARGER; | |
744 | u8 *send_cfg_buf_charger[3] = {cfg_info_group1_charger, cfg_info_group2_charger, cfg_info_group3_charger}; | |
745 | #endif | |
746 | u8 cfg_info_len[3] = {sizeof(cfg_info_group1) / sizeof(cfg_info_group1[0]), | |
747 | sizeof(cfg_info_group2) / sizeof(cfg_info_group2[0]), | |
748 | sizeof(cfg_info_group3) / sizeof(cfg_info_group3[0]) | |
749 | }; | |
750 | ||
751 | for (i = 0; i < 3; i++) | |
752 | { | |
753 | if (cfg_info_len[i] > cfg_len) | |
754 | { | |
755 | cfg_len = cfg_info_len[i]; | |
756 | } | |
757 | } | |
758 | ||
759 | 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); | |
760 | ||
761 | if ((!cfg_info_len[1]) && (!cfg_info_len[2])) | |
762 | { | |
763 | rd_cfg_buf[GTP_ADDR_LENGTH] = 0; | |
764 | } | |
765 | else | |
766 | { | |
767 | rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8; | |
768 | rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff; | |
769 | ret = gtp_i2c_read(client, rd_cfg_buf, 3); | |
770 | ||
771 | if (ret < 0) | |
772 | { | |
773 | GTP_ERROR("Read SENSOR ID failed,default use group1 config!"); | |
774 | rd_cfg_buf[GTP_ADDR_LENGTH] = 0; | |
775 | goto out; | |
776 | } | |
777 | ||
778 | rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x03; | |
779 | } | |
780 | ||
781 | GTP_INFO("SENSOR ID:%d", rd_cfg_buf[GTP_ADDR_LENGTH]); | |
782 | memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); | |
783 | memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[rd_cfg_buf[GTP_ADDR_LENGTH]], cfg_len); | |
784 | #ifdef GTP_CHARGER_DETECT | |
785 | memset(&config_charger[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); | |
786 | memcpy(&config_charger[GTP_ADDR_LENGTH], send_cfg_buf_charger[rd_cfg_buf[GTP_ADDR_LENGTH]], cfg_len); | |
787 | #endif | |
788 | ||
789 | #if GTP_CUSTOM_CFG | |
790 | config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH; | |
791 | config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH >> 8); | |
792 | config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT; | |
793 | config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT >> 8); | |
794 | ||
795 | if (GTP_INT_TRIGGER == 0) //RISING | |
796 | { | |
797 | config[TRIGGER_LOC] &= 0xfe; | |
798 | } | |
799 | else if (GTP_INT_TRIGGER == 1) //FALLING | |
800 | { | |
801 | config[TRIGGER_LOC] |= 0x01; | |
802 | } | |
803 | ||
804 | #endif //endif GTP_CUSTOM_CFG | |
805 | ||
806 | check_sum = 0; | |
807 | ||
808 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
809 | { | |
810 | check_sum += config[i]; | |
811 | } | |
812 | ||
813 | config[cfg_len] = (~check_sum) + 1; | |
814 | #ifdef GTP_CHARGER_DETECT | |
815 | check_sum = 0; | |
816 | ||
817 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
818 | { | |
819 | check_sum += config_charger[i]; | |
820 | } | |
821 | ||
822 | config_charger[cfg_len] = (~check_sum) + 1; | |
823 | #endif | |
824 | #else //else DRIVER NEED NOT SEND CONFIG | |
825 | ||
826 | if (cfg_len == 0) | |
827 | { | |
828 | cfg_len = GTP_CONFIG_MAX_LENGTH; | |
829 | } | |
830 | ||
831 | ret = gtp_i2c_read(client, config, cfg_len + GTP_ADDR_LENGTH); | |
832 | ||
833 | if (ret < 0) | |
834 | { | |
835 | GTP_ERROR("GTP read resolution & max_touch_num failed, use default value!"); | |
836 | abs_x_max = GTP_MAX_WIDTH; | |
837 | abs_y_max = GTP_MAX_HEIGHT; | |
838 | int_type = GTP_INT_TRIGGER; | |
839 | goto out; | |
840 | } | |
841 | ||
842 | #endif //endif GTP_DRIVER_SEND_CFG | |
843 | ||
844 | abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; | |
845 | abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; | |
846 | int_type = (config[TRIGGER_LOC]) & 0x03; | |
847 | ||
848 | if ((!abs_x_max) || (!abs_y_max)) | |
849 | { | |
850 | GTP_ERROR("GTP resolution & max_touch_num invalid, use default value!"); | |
851 | abs_x_max = GTP_MAX_WIDTH; | |
852 | abs_y_max = GTP_MAX_HEIGHT; | |
853 | } | |
854 | ||
855 | ret = gtp_send_cfg(client); | |
856 | ||
857 | if (ret < 0) | |
858 | { | |
859 | GTP_ERROR("Send config error."); | |
860 | goto out; | |
861 | } | |
862 | ||
863 | GTP_DEBUG("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x", abs_x_max, abs_y_max, int_type); | |
864 | ||
865 | msleep(10); | |
866 | out: | |
867 | return ret; | |
868 | } | |
869 | ||
870 | static s8 gtp_i2c_test(struct i2c_client *client) | |
871 | { | |
872 | ||
873 | u8 retry = 0; | |
874 | s8 ret = -1; | |
875 | u32 hw_info = 0; | |
876 | ||
877 | GTP_DEBUG_FUNC(); | |
878 | ||
879 | while (retry++ < 5) | |
880 | { | |
881 | ret = i2c_read_bytes(client, GTP_REG_HW_INFO, (u8 *)&hw_info, sizeof(hw_info)); | |
882 | ||
883 | if ((!ret) && (hw_info == 0x00900600)) //20121212 | |
884 | { | |
885 | return ret; | |
886 | } | |
887 | ||
888 | GTP_ERROR("GTP_REG_HW_INFO : %08X", hw_info); | |
889 | GTP_ERROR("GTP i2c test failed time %d.", retry); | |
890 | msleep(10); | |
891 | } | |
892 | ||
893 | return -1; | |
894 | } | |
895 | ||
896 | /******************************************************* | |
897 | Function: | |
898 | Set INT pin as input for FW sync. | |
899 | ||
900 | Note: | |
901 | If the INT is high, It means there is pull up resistor attached on the INT pin. | |
902 | Pull low the INT pin manaully for FW sync. | |
903 | *******************************************************/ | |
904 | void gtp_int_sync() | |
905 | { | |
906 | GTP_DEBUG("There is pull up resisitor attached on the INT pin~!"); | |
907 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
908 | msleep(50); | |
909 | GTP_GPIO_AS_INT(GTP_INT_PORT); | |
910 | } | |
911 | ||
912 | void gtp_reset_guitar(struct i2c_client *client, s32 ms) | |
913 | { | |
914 | GTP_INFO("GTP RESET!"); | |
915 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
916 | msleep(ms); | |
917 | GTP_GPIO_OUTPUT(GTP_INT_PORT, client->addr == 0x14); | |
918 | msleep(2); | |
919 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 1); | |
920 | msleep(6); | |
921 | gtp_int_sync(); | |
922 | ||
923 | return; | |
924 | } | |
925 | ||
926 | static int tpd_power_on(struct i2c_client *client) | |
927 | { | |
928 | int ret = 0; | |
929 | int reset_count = 0; | |
930 | ||
931 | reset_proc: | |
932 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
933 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
934 | msleep(10); | |
935 | //power on, need confirm with SA | |
936 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
937 | hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_3000, "TP"); | |
938 | #else | |
939 | hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_3300, "TP"); | |
940 | #endif | |
941 | #ifdef TPD_POWER_SOURCE_1800 | |
942 | hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP"); | |
943 | #endif | |
944 | ||
945 | gtp_reset_guitar(client, 20); | |
946 | GTP_ERROR("GTP_INT_PORT:0x%x, GTP_RST_PORT:0x%x", GTP_INT_PORT, GTP_RST_PORT); | |
947 | ret = gtp_i2c_test(client); | |
948 | ||
949 | if (ret < 0) | |
950 | { | |
951 | GTP_ERROR("I2C communication ERROR!"); | |
952 | ||
953 | if (reset_count < TPD_MAX_RESET_COUNT) | |
954 | { | |
955 | reset_count++; | |
956 | goto reset_proc; | |
957 | } | |
958 | else | |
959 | { | |
960 | goto out; | |
961 | } | |
962 | } | |
963 | ||
964 | #if GTP_FW_DOWNLOAD | |
965 | ret = gup_init_fw_proc(client); | |
966 | ||
967 | if (ret < 0) | |
968 | { | |
969 | GTP_ERROR("Create fw download thread error."); | |
970 | } | |
971 | ||
972 | #endif | |
973 | out: | |
974 | return ret; | |
975 | } | |
976 | ||
977 | #ifdef MTK_CTP_RESET_CONFIG | |
978 | static int tpd_clear_config(void *unused) | |
979 | { | |
980 | int ret=0, check_sum=0; | |
981 | u8 temp_data = 0, i=0; | |
982 | u8 config_1st[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] | |
983 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
984 | ||
985 | GTP_INFO("Clear Config Begin......"); | |
986 | msleep(10000); //wait main thread to be completed | |
987 | ||
988 | ret = i2c_read_bytes(i2c_client_point, GTP_REG_CONFIG_DATA, &temp_data, 1); | |
989 | if (ret < 0) | |
990 | { | |
991 | GTP_ERROR("GTP read config failed!"); | |
992 | return -1; | |
993 | } | |
994 | ||
995 | GTP_INFO("IC config version: 0x%x; Driver config version: 0x%x",temp_data, config[GTP_ADDR_LENGTH]); | |
996 | if((temp_data<(u8)0x5A)&&(temp_data>config[GTP_ADDR_LENGTH])) | |
997 | { | |
998 | memset(&config_1st[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); | |
999 | memcpy(&config_1st[GTP_ADDR_LENGTH], &config[GTP_ADDR_LENGTH], cfg_len); | |
1000 | config_1st[GTP_ADDR_LENGTH] = 0; | |
1001 | check_sum = 0; | |
1002 | ||
1003 | for (i = GTP_ADDR_LENGTH; i < cfg_len; i++) | |
1004 | { | |
1005 | check_sum += config_1st[i]; | |
1006 | } | |
1007 | ||
1008 | config_1st[cfg_len] = (~check_sum) + 1; | |
1009 | ret = gtp_i2c_write(i2c_client_point, config_1st , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); | |
1010 | if (ret < 0) | |
1011 | { | |
1012 | GTP_ERROR("GTP write 00 config failed!"); | |
1013 | }else | |
1014 | { | |
1015 | GTP_INFO("Force clear cfg done"); | |
1016 | } | |
1017 | }else | |
1018 | { | |
1019 | GTP_INFO("No need clear cfg"); | |
1020 | } | |
1021 | return 0; | |
1022 | } | |
1023 | #endif | |
1024 | ||
1025 | static const struct file_operations gt_upgrade_proc_fops = { | |
1026 | .write = gt91xx_config_write_proc, | |
1027 | .read = gt91xx_config_read_proc | |
1028 | }; | |
1029 | ||
1030 | ||
1031 | static s32 tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) | |
1032 | { | |
1033 | s32 err = 0; | |
1034 | s32 ret = 0; | |
1035 | u16 version_info; | |
1036 | struct task_struct *thread = NULL; | |
1037 | #if 0 //GTP_HAVE_TOUCH_KEY | |
1038 | s32 idx = 0; | |
1039 | #endif | |
1040 | #ifdef TPD_PROXIMITY | |
1041 | struct hwmsen_object obj_ps; | |
1042 | #endif | |
1043 | ||
1044 | i2c_client_point = client; | |
1045 | ret = tpd_power_on(client); | |
1046 | ||
1047 | if (ret < 0) | |
1048 | { | |
1049 | GTP_ERROR("I2C communication ERROR!"); | |
1050 | goto out; | |
1051 | } | |
1052 | ||
1053 | #ifdef MTK_CTP_RESET_CONFIG | |
1054 | thread = kthread_run(tpd_clear_config, 0, "mtk-tpd-clear-config"); | |
1055 | if (IS_ERR(thread)) | |
1056 | { | |
1057 | err = PTR_ERR(thread); | |
1058 | GTP_INFO(TPD_DEVICE " failed to create kernel thread for clearing config: %d", err); | |
1059 | } | |
1060 | thread = NULL; | |
1061 | #endif | |
1062 | ||
1063 | #if GTP_AUTO_UPDATE | |
1064 | ret = gup_init_update_proc(client); | |
1065 | ||
1066 | if (ret < 0) | |
1067 | { | |
1068 | GTP_ERROR("Create update thread error."); | |
1069 | goto out; | |
1070 | } | |
1071 | ||
1072 | #endif | |
1073 | ||
1074 | ||
1075 | ||
1076 | #ifdef VELOCITY_CUSTOM | |
1077 | tpd_v_magnify_x = TPD_VELOCITY_CUSTOM_X; | |
1078 | tpd_v_magnify_y = TPD_VELOCITY_CUSTOM_Y; | |
1079 | ||
1080 | #endif | |
1081 | ||
1082 | ret = gtp_read_version(client, &version_info); | |
1083 | ||
1084 | if (ret < 0) | |
1085 | { | |
1086 | GTP_ERROR("Read version failed."); | |
1087 | goto out; | |
1088 | } | |
1089 | ||
1090 | ret = gtp_init_panel(client); | |
1091 | ||
1092 | if (ret < 0) | |
1093 | { | |
1094 | GTP_ERROR("GTP init panel failed."); | |
1095 | goto out; | |
1096 | } | |
1097 | GTP_DEBUG("gtp_init_panel success"); | |
1098 | // Create proc file system | |
1099 | gt91xx_config_proc = proc_create(GT91XX_CONFIG_PROC_FILE, 0660, NULL, >_upgrade_proc_fops); | |
1100 | ||
1101 | if (gt91xx_config_proc == NULL) | |
1102 | { | |
1103 | GTP_ERROR("create_proc_entry %s failed", GT91XX_CONFIG_PROC_FILE); | |
1104 | goto out; | |
1105 | } | |
1106 | ||
1107 | #if GTP_CREATE_WR_NODE | |
1108 | init_wr_node(client); | |
1109 | #endif | |
1110 | ||
1111 | thread = kthread_run(touch_event_handler, 0, TPD_DEVICE); | |
1112 | ||
1113 | if (IS_ERR(thread)) | |
1114 | { | |
1115 | err = PTR_ERR(thread); | |
1116 | GTP_ERROR(TPD_DEVICE " failed to create kernel thread: %d", err); | |
1117 | goto out; | |
1118 | } | |
1119 | ||
1120 | #if 0//GTP_HAVE_TOUCH_KEY | |
1121 | ||
1122 | for (idx = 0; idx < TPD_KEY_COUNT; idx++) | |
1123 | { | |
1124 | input_set_capability(tpd->dev, EV_KEY, touch_key_array[idx]); | |
1125 | } | |
1126 | ||
1127 | #endif | |
1128 | ||
1129 | if (!int_type) //EINTF_TRIGGER | |
1130 | { | |
1131 | mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_RISING, tpd_eint_interrupt_handler, 0); | |
1132 | } | |
1133 | else | |
1134 | { | |
1135 | mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_FALLING, tpd_eint_interrupt_handler, 0);// disable auto-unmask | |
1136 | } | |
1137 | ||
1138 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1139 | ||
1140 | #ifdef TPD_PROXIMITY | |
1141 | //obj_ps.self = cm3623_obj; | |
1142 | obj_ps.polling = 0; //0--interrupt mode;1--polling mode; | |
1143 | obj_ps.sensor_operate = tpd_ps_operate; | |
1144 | ||
1145 | if ((err = hwmsen_attach(ID_PROXIMITY, &obj_ps))) | |
1146 | { | |
1147 | GTP_ERROR("hwmsen attach fail, return:%d.", err); | |
1148 | } | |
1149 | ||
1150 | #endif | |
1151 | ||
1152 | #if GTP_ESD_PROTECT | |
1153 | INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func); | |
1154 | gtp_esd_check_workqueue = create_workqueue("gtp_esd_check"); | |
1155 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, TPD_ESD_CHECK_CIRCLE); | |
1156 | #endif | |
1157 | ||
1158 | #ifdef GTP_CHARGER_DETECT | |
1159 | INIT_DELAYED_WORK(>p_charger_check_work, gtp_charger_check_func); | |
1160 | gtp_charger_check_workqueue = create_workqueue("gtp_charger_check"); | |
1161 | queue_delayed_work(gtp_charger_check_workqueue, >p_charger_check_work, TPD_CHARGER_CHECK_CIRCLE); | |
1162 | #endif | |
1163 | tpd_load_status = 1; | |
1164 | ||
1165 | GTP_INFO("%s, success run Done", __FUNCTION__); | |
1166 | return 0; | |
1167 | out: | |
1168 | return -1; | |
1169 | } | |
1170 | ||
1171 | static void tpd_eint_interrupt_handler(void) | |
1172 | { | |
1173 | TPD_DEBUG_PRINT_INT; | |
1174 | tpd_flag = 1; | |
1175 | wake_up_interruptible(&waiter); | |
1176 | } | |
1177 | static int tpd_i2c_remove(struct i2c_client *client) | |
1178 | { | |
1179 | #if GTP_CREATE_WR_NODE | |
1180 | uninit_wr_node(); | |
1181 | #endif | |
1182 | ||
1183 | #if GTP_ESD_PROTECT | |
1184 | destroy_workqueue(gtp_esd_check_workqueue); | |
1185 | #endif | |
1186 | ||
1187 | #if GTP_ESD_PROTECT | |
1188 | destroy_workqueue(gtp_charger_check_workqueue); | |
1189 | #endif | |
1190 | return 0; | |
1191 | } | |
1192 | #ifdef GTP_CHARGER_DETECT | |
1193 | static void gtp_charger_check_func(struct work_struct *work) | |
1194 | { | |
1195 | int cur_charger_state; | |
1196 | cur_charger_state = upmu_get_pchr_chrdet(); | |
1197 | ||
1198 | GTP_DEBUG("Charger mode = %d", cur_charger_state); | |
1199 | ||
1200 | if (gtp_charger_mode != cur_charger_state) | |
1201 | { | |
1202 | GTP_DEBUG("Charger state change detected~!"); | |
1203 | GTP_DEBUG("Charger mode = %d", cur_charger_state); | |
1204 | gtp_charger_mode = cur_charger_state; | |
1205 | gtp_send_cfg(i2c_client_point); | |
1206 | } | |
1207 | ||
1208 | if (!tpd_halt) | |
1209 | { | |
1210 | queue_delayed_work(gtp_charger_check_workqueue, >p_charger_check_work, TPD_CHARGER_CHECK_CIRCLE); | |
1211 | } | |
1212 | ||
1213 | return; | |
1214 | } | |
1215 | #endif | |
1216 | ||
1217 | #if GTP_ESD_PROTECT | |
1218 | static void force_reset_guitar(void) | |
1219 | { | |
1220 | s32 i; | |
1221 | s32 ret; | |
1222 | ||
1223 | GTP_INFO("force_reset_guitar"); | |
1224 | ||
1225 | //Power off TP | |
1226 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1227 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
1228 | #else | |
1229 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
1230 | #endif | |
1231 | #ifdef TPD_POWER_SOURCE_1800 | |
1232 | hwPowerDown(TPD_POWER_SOURCE_1800, "TP"); | |
1233 | #endif | |
1234 | msleep(30); | |
1235 | //Power on TP | |
1236 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1237 | hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_3000, "TP"); | |
1238 | #else | |
1239 | hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_3300, "TP"); | |
1240 | #endif | |
1241 | #ifdef TPD_POWER_SOURCE_1800 | |
1242 | hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP"); | |
1243 | #endif | |
1244 | msleep(30); | |
1245 | for (i = 0; i < 5; i++) | |
1246 | { | |
1247 | //Reset Guitar | |
1248 | gtp_reset_guitar(i2c_client_point, 20); | |
1249 | ||
1250 | //Send config | |
1251 | ret = gtp_send_cfg(i2c_client_point); | |
1252 | ||
1253 | if (ret < 0) | |
1254 | { | |
1255 | continue; | |
1256 | } | |
1257 | ||
1258 | break; | |
1259 | } | |
1260 | ||
1261 | } | |
1262 | ||
1263 | static void gtp_esd_check_func(struct work_struct *work) | |
1264 | { | |
1265 | int i; | |
1266 | int ret = -1; | |
1267 | u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; | |
1268 | ||
1269 | if (tpd_halt) | |
1270 | { | |
1271 | return; | |
1272 | } | |
1273 | ||
1274 | for (i = 0; i < 3; i++) | |
1275 | { | |
1276 | ret = gtp_i2c_read(i2c_client_point, test, 3); | |
1277 | ||
1278 | if (ret > 0) | |
1279 | { | |
1280 | break; | |
1281 | } | |
1282 | } | |
1283 | ||
1284 | if (i >= 3) | |
1285 | { | |
1286 | force_reset_guitar(); | |
1287 | } | |
1288 | ||
1289 | if (!tpd_halt) | |
1290 | { | |
1291 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, TPD_ESD_CHECK_CIRCLE); | |
1292 | } | |
1293 | ||
1294 | return; | |
1295 | } | |
1296 | #endif | |
1297 | static int tpd_history_x=0, tpd_history_y=0; | |
1298 | static void tpd_down(s32 x, s32 y, s32 size, s32 id) | |
1299 | { | |
1300 | if ((!size) && (!id)) | |
1301 | { | |
1302 | input_report_abs(tpd->dev, ABS_MT_PRESSURE, 100); | |
1303 | input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 100); | |
1304 | } | |
1305 | else | |
1306 | { | |
1307 | input_report_abs(tpd->dev, ABS_MT_PRESSURE, size); | |
1308 | input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, size); | |
1309 | /* track id Start 0 */ | |
1310 | input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, id); | |
1311 | } | |
1312 | ||
1313 | input_report_key(tpd->dev, BTN_TOUCH, 1); | |
1314 | input_report_abs(tpd->dev, ABS_MT_POSITION_X, x); | |
1315 | input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y); | |
1316 | input_mt_sync(tpd->dev); | |
1317 | TPD_DEBUG_SET_TIME; | |
1318 | TPD_EM_PRINT(x, y, x, y, id, 1); | |
1319 | tpd_history_x=x; | |
1320 | tpd_history_y=y; | |
1321 | ||
1322 | MMProfileLogEx(MMP_TouchPanelEvent, MMProfileFlagPulse, 1, x+y); | |
1323 | #ifdef TPD_HAVE_BUTTON | |
1324 | ||
1325 | if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode()) | |
1326 | { | |
1327 | tpd_button(x, y, 1); | |
1328 | } | |
1329 | ||
1330 | #endif | |
1331 | } | |
1332 | ||
1333 | static void tpd_up(s32 x, s32 y, s32 id) | |
1334 | { | |
1335 | //input_report_abs(tpd->dev, ABS_MT_PRESSURE, 0); | |
1336 | input_report_key(tpd->dev, BTN_TOUCH, 0); | |
1337 | //input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 0); | |
1338 | input_mt_sync(tpd->dev); | |
1339 | TPD_DEBUG_SET_TIME; | |
1340 | TPD_EM_PRINT(tpd_history_x, tpd_history_y, tpd_history_x, tpd_history_y, id, 0); | |
1341 | tpd_history_x=0; | |
1342 | tpd_history_y=0; | |
1343 | MMProfileLogEx(MMP_TouchPanelEvent, MMProfileFlagPulse, 0, x+y); | |
1344 | ||
1345 | #ifdef TPD_HAVE_BUTTON | |
1346 | ||
1347 | if (FACTORY_BOOT == get_boot_mode() || RECOVERY_BOOT == get_boot_mode()) | |
1348 | { | |
1349 | tpd_button(x, y, 0); | |
1350 | } | |
1351 | ||
1352 | #endif | |
1353 | } | |
1354 | ||
1355 | /*Coordination mapping*/ | |
1356 | static void tpd_calibrate_driver(int *x, int *y) | |
1357 | { | |
1358 | int tx; | |
1359 | ||
1360 | GTP_DEBUG("Call tpd_calibrate of this driver ..\n"); | |
1361 | ||
1362 | tx = ( (tpd_def_calmat[0] * (*x)) + (tpd_def_calmat[1] * (*y)) + (tpd_def_calmat[2]) ) >> 12; | |
1363 | *y = ( (tpd_def_calmat[3] * (*x)) + (tpd_def_calmat[4] * (*y)) + (tpd_def_calmat[5]) ) >> 12; | |
1364 | *x = tx; | |
1365 | } | |
1366 | ||
1367 | static int touch_event_handler(void *unused) | |
1368 | { | |
1369 | struct sched_param param = { .sched_priority = RTPM_PRIO_TPD }; | |
1370 | u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0}; | |
1371 | u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF}; | |
1372 | u8 touch_num = 0; | |
1373 | u8 finger = 0; | |
1374 | static u8 pre_touch = 0; | |
1375 | static u8 pre_key = 0; | |
1376 | u8 key_value = 0; | |
1377 | u8 *coor_data = NULL; | |
1378 | s32 input_x = 0; | |
1379 | s32 input_y = 0; | |
1380 | s32 input_w = 0; | |
1381 | s32 id = 0; | |
1382 | s32 i = 0; | |
1383 | s32 ret = -1; | |
1384 | #ifdef TPD_PROXIMITY | |
1385 | s32 err = 0; | |
1386 | hwm_sensor_data sensor_data; | |
1387 | u8 proximity_status; | |
1388 | #endif | |
1389 | #if GTP_CHANGE_X2Y | |
1390 | s32 temp; | |
1391 | #endif | |
1392 | ||
1393 | sched_setscheduler(current, SCHED_RR, ¶m); | |
1394 | ||
1395 | do | |
1396 | { | |
1397 | set_current_state(TASK_INTERRUPTIBLE); | |
1398 | if(tpd_eint_mode) | |
1399 | { | |
1400 | wait_event_interruptible(waiter, tpd_flag != 0); | |
1401 | tpd_flag = 0; | |
1402 | } | |
1403 | else | |
1404 | { | |
1405 | msleep(tpd_polling_time); | |
1406 | } | |
1407 | set_current_state(TASK_RUNNING); | |
1408 | ||
1409 | mutex_lock(&i2c_access); | |
1410 | ||
1411 | if (tpd_halt) | |
1412 | { | |
1413 | mutex_unlock(&i2c_access); | |
1414 | GTP_DEBUG("return for interrupt after suspend... "); | |
1415 | continue; | |
1416 | } | |
1417 | ||
1418 | ret = gtp_i2c_read(i2c_client_point, point_data, 12); | |
1419 | ||
1420 | if (ret < 0) | |
1421 | { | |
1422 | GTP_ERROR("I2C transfer error. errno:%d ", ret); | |
1423 | goto exit_work_func; | |
1424 | } | |
1425 | ||
1426 | finger = point_data[GTP_ADDR_LENGTH]; | |
1427 | ||
1428 | if ((finger & 0x80) == 0) | |
1429 | { | |
1430 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1431 | mutex_unlock(&i2c_access); | |
1432 | GTP_ERROR("buffer not ready"); | |
1433 | continue; | |
1434 | } | |
1435 | ||
1436 | #ifdef TPD_PROXIMITY | |
1437 | ||
1438 | if (tpd_proximity_flag == 1) | |
1439 | { | |
1440 | proximity_status = point_data[GTP_ADDR_LENGTH]; | |
1441 | GTP_DEBUG("REG INDEX[0x814E]:0x%02X", proximity_status); | |
1442 | ||
1443 | if (proximity_status & 0x60) //proximity or large touch detect,enable hwm_sensor. | |
1444 | { | |
1445 | tpd_proximity_detect = 0; | |
1446 | //sensor_data.values[0] = 0; | |
1447 | } | |
1448 | else | |
1449 | { | |
1450 | tpd_proximity_detect = 1; | |
1451 | //sensor_data.values[0] = 1; | |
1452 | } | |
1453 | ||
1454 | //get raw data | |
1455 | GTP_DEBUG(" ps change"); | |
1456 | GTP_DEBUG("PROXIMITY STATUS:0x%02X", tpd_proximity_detect); | |
1457 | //map and store data to hwm_sensor_data | |
1458 | sensor_data.values[0] = tpd_get_ps_value(); | |
1459 | sensor_data.value_divide = 1; | |
1460 | sensor_data.status = SENSOR_STATUS_ACCURACY_MEDIUM; | |
1461 | //report to the up-layer | |
1462 | ret = hwmsen_get_interrupt_data(ID_PROXIMITY, &sensor_data); | |
1463 | ||
1464 | if (ret) | |
1465 | { | |
1466 | GTP_ERROR("Call hwmsen_get_interrupt_data fail = %d", err); | |
1467 | } | |
1468 | } | |
1469 | ||
1470 | #endif | |
1471 | ||
1472 | touch_num = finger & 0x0f; | |
1473 | ||
1474 | if (touch_num > GTP_MAX_TOUCH) | |
1475 | { | |
1476 | GTP_ERROR("Bad number of fingers!"); | |
1477 | goto exit_work_func; | |
1478 | } | |
1479 | ||
1480 | if (touch_num > 1) | |
1481 | { | |
1482 | u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff}; | |
1483 | ||
1484 | ret = gtp_i2c_read(i2c_client_point, buf, 2 + 8 * (touch_num - 1)); | |
1485 | memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1)); | |
1486 | } | |
1487 | #if GTP_HAVE_TOUCH_KEY | |
1488 | key_value = point_data[3 + 8 * touch_num]; | |
1489 | ||
1490 | if (key_value || pre_key) | |
1491 | { | |
1492 | for (i = 0; i < TPD_KEY_COUNT; i++) | |
1493 | { | |
1494 | //input_report_key(tpd->dev, touch_key_array[i], key_value & (0x01 << i)); | |
1495 | if( key_value&(0x01<<i) ) //key=1 menu ;key=2 home; key =4 back; | |
1496 | { | |
1497 | input_x =touch_key_point_maping_array[i].point_x; | |
1498 | input_y = touch_key_point_maping_array[i].point_y; | |
1499 | GTP_DEBUG("button =%d %d",input_x,input_y); | |
1500 | ||
1501 | tpd_down( input_x, input_y, 0, 0); | |
1502 | } | |
1503 | } | |
1504 | ||
1505 | if((pre_key!=0)&&(key_value ==0)) | |
1506 | { | |
1507 | tpd_up( 0, 0, 0); | |
1508 | } | |
1509 | ||
1510 | touch_num = 0; | |
1511 | pre_touch = 0; | |
1512 | } | |
1513 | ||
1514 | #endif | |
1515 | pre_key = key_value; | |
1516 | ||
1517 | GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger); | |
1518 | ||
1519 | if (touch_num) | |
1520 | { | |
1521 | for (i = 0; i < touch_num; i++) | |
1522 | { | |
1523 | coor_data = &point_data[i * 8 + 3]; | |
1524 | ||
1525 | id = coor_data[0]&0x0F; | |
1526 | input_x = coor_data[1] | coor_data[2] << 8; | |
1527 | input_y = coor_data[3] | coor_data[4] << 8; | |
1528 | input_w = coor_data[5] | coor_data[6] << 8; | |
1529 | ||
1530 | GTP_DEBUG("Original touch point : [X:%04d, Y:%04d]", input_x, input_y); | |
1531 | ||
1532 | input_x = TPD_WARP_X(abs_x_max, input_x); | |
1533 | input_y = TPD_WARP_Y(abs_y_max, input_y); | |
1534 | tpd_calibrate_driver(&input_x, &input_y); | |
1535 | ||
1536 | GTP_DEBUG("Touch point after calibration: [X:%04d, Y:%04d]", input_x, input_y); | |
1537 | ||
1538 | #if GTP_CHANGE_X2Y | |
1539 | temp = input_x; | |
1540 | input_x = input_y; | |
1541 | input_y = temp; | |
1542 | #endif | |
1543 | ||
1544 | tpd_down(input_x, input_y, input_w, id); | |
1545 | } | |
1546 | } | |
1547 | else if (pre_touch) | |
1548 | { | |
1549 | GTP_DEBUG("Touch Release!"); | |
1550 | tpd_up(0, 0, 0); | |
1551 | } | |
1552 | else | |
1553 | { | |
1554 | GTP_DEBUG("Additional Eint!"); | |
1555 | } | |
1556 | pre_touch = touch_num; | |
1557 | //input_report_key(tpd->dev, BTN_TOUCH, (touch_num || key_value)); | |
1558 | ||
1559 | if (tpd != NULL && tpd->dev != NULL) | |
1560 | { | |
1561 | input_sync(tpd->dev); | |
1562 | } | |
1563 | ||
1564 | exit_work_func: | |
1565 | ||
1566 | if (!gtp_rawdiff_mode) | |
1567 | { | |
1568 | ret = gtp_i2c_write(i2c_client_point, end_cmd, 3); | |
1569 | ||
1570 | if (ret < 0) | |
1571 | { | |
1572 | GTP_INFO("I2C write end_cmd error!"); | |
1573 | } | |
1574 | } | |
1575 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1576 | mutex_unlock(&i2c_access); | |
1577 | ||
1578 | } | |
1579 | while (!kthread_should_stop()); | |
1580 | ||
1581 | return 0; | |
1582 | } | |
1583 | ||
1584 | static int tpd_local_init(void) | |
1585 | { | |
1586 | ||
1587 | if (i2c_add_driver(&tpd_i2c_driver) != 0) | |
1588 | { | |
1589 | GTP_INFO("unable to add i2c driver."); | |
1590 | return -1; | |
1591 | } | |
1592 | ||
1593 | if (tpd_load_status == 0) //if(tpd_load_status == 0) // disable auto load touch driver for linux3.0 porting | |
1594 | { | |
1595 | GTP_INFO("add error touch panel driver."); | |
1596 | i2c_del_driver(&tpd_i2c_driver); | |
1597 | return -1; | |
1598 | } | |
1599 | input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, (GTP_MAX_TOUCH-1), 0, 0); | |
1600 | #ifdef TPD_HAVE_BUTTON | |
1601 | tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data | |
1602 | #endif | |
1603 | ||
1604 | #if (defined(TPD_WARP_START) && defined(TPD_WARP_END)) | |
1605 | TPD_DO_WARP = 1; | |
1606 | memcpy(tpd_wb_start, tpd_wb_start_local, TPD_WARP_CNT * 4); | |
1607 | memcpy(tpd_wb_end, tpd_wb_start_local, TPD_WARP_CNT * 4); | |
1608 | #endif | |
1609 | ||
1610 | #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION)) | |
1611 | //memcpy(tpd_calmat, tpd_def_calmat_local, 8 * 4); | |
1612 | //memcpy(tpd_def_calmat, tpd_def_calmat_local, 8 * 4); | |
1613 | if (FACTORY_BOOT == get_boot_mode()) | |
1614 | { | |
1615 | TPD_DEBUG("Factory mode is detected! \n"); | |
1616 | memcpy(tpd_calmat, tpd_def_calmat_local_factory, 8 * 4); | |
1617 | memcpy(tpd_def_calmat, tpd_def_calmat_local_factory, 8 * 4); | |
1618 | } | |
1619 | else | |
1620 | { | |
1621 | TPD_DEBUG("Normal mode is detected! \n"); | |
1622 | memcpy(tpd_calmat, tpd_def_calmat_local_normal, 8 * 4); | |
1623 | memcpy(tpd_def_calmat, tpd_def_calmat_local_normal, 8 * 4); | |
1624 | } | |
1625 | #endif | |
1626 | ||
1627 | // set vendor string | |
1628 | tpd->dev->id.vendor = 0x00; | |
1629 | tpd->dev->id.product = tpd_info.pid; | |
1630 | tpd->dev->id.version = tpd_info.vid; | |
1631 | ||
1632 | GTP_INFO("end %s, %d", __FUNCTION__, __LINE__); | |
1633 | tpd_type_cap = 1; | |
1634 | ||
1635 | return 0; | |
1636 | } | |
1637 | ||
1638 | ||
1639 | /******************************************************* | |
1640 | Function: | |
1641 | Eter sleep function. | |
1642 | ||
1643 | Input: | |
1644 | client:i2c_client. | |
1645 | ||
1646 | Output: | |
1647 | Executive outcomes.0--success,non-0--fail. | |
1648 | *******************************************************/ | |
1649 | static s8 gtp_enter_sleep(struct i2c_client *client) | |
1650 | { | |
1651 | s8 ret = -1; | |
1652 | #if !GTP_POWER_CTRL_SLEEP | |
1653 | s8 retry = 0; | |
1654 | u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5}; | |
1655 | ||
1656 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
1657 | msleep(5); | |
1658 | ||
1659 | while (retry++ < 5) | |
1660 | { | |
1661 | ret = gtp_i2c_write(client, i2c_control_buf, 3); | |
1662 | ||
1663 | if (ret > 0) | |
1664 | { | |
1665 | GTP_INFO("GTP enter sleep!"); | |
1666 | return ret; | |
1667 | } | |
1668 | ||
1669 | msleep(10); | |
1670 | } | |
1671 | ||
1672 | #else | |
1673 | ||
1674 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); | |
1675 | msleep(5); | |
1676 | ||
1677 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1678 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
1679 | #else | |
1680 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
1681 | #endif | |
1682 | #ifdef TPD_POWER_SOURCE_1800 | |
1683 | hwPowerDown(TPD_POWER_SOURCE_1800, "TP"); | |
1684 | #endif | |
1685 | ||
1686 | GTP_INFO("GTP enter sleep!"); | |
1687 | return 0; | |
1688 | ||
1689 | #endif | |
1690 | GTP_ERROR("GTP send sleep cmd failed."); | |
1691 | return ret; | |
1692 | } | |
1693 | ||
1694 | /******************************************************* | |
1695 | Function: | |
1696 | Wakeup from sleep mode Function. | |
1697 | ||
1698 | Input: | |
1699 | client:i2c_client. | |
1700 | ||
1701 | Output: | |
1702 | Executive outcomes.0--success,non-0--fail. | |
1703 | *******************************************************/ | |
1704 | static s8 gtp_wakeup_sleep(struct i2c_client *client) | |
1705 | { | |
1706 | u8 retry = 0; | |
1707 | s8 ret = -1; | |
1708 | ||
1709 | ||
1710 | GTP_INFO("GTP wakeup begin."); | |
1711 | #if GTP_POWER_CTRL_SLEEP | |
1712 | ||
1713 | while (retry++ < 5) | |
1714 | { | |
1715 | ret = tpd_power_on(client); | |
1716 | ||
1717 | if (ret < 0) | |
1718 | { | |
1719 | GTP_ERROR("I2C Power on ERROR!"); | |
1720 | } | |
1721 | ||
1722 | ret = gtp_send_cfg(client); | |
1723 | ||
1724 | if (ret > 0) | |
1725 | { | |
1726 | GTP_DEBUG("Wakeup sleep send config success."); | |
1727 | return ret; | |
1728 | } | |
1729 | } | |
1730 | ||
1731 | #else | |
1732 | ||
1733 | while (retry++ < 10) | |
1734 | { | |
1735 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 1); | |
1736 | msleep(5); | |
1737 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); | |
1738 | msleep(5); | |
1739 | ret = gtp_i2c_test(client); | |
1740 | ||
1741 | if (ret >= 0) | |
1742 | { | |
1743 | gtp_int_sync(); | |
1744 | return ret; | |
1745 | } | |
1746 | ||
1747 | gtp_reset_guitar(client, 20); | |
1748 | } | |
1749 | ||
1750 | #endif | |
1751 | ||
1752 | GTP_ERROR("GTP wakeup sleep failed."); | |
1753 | return ret; | |
1754 | } | |
1755 | /* Function to manage low power suspend */ | |
1756 | static void tpd_suspend(struct early_suspend *h) | |
1757 | { | |
1758 | s32 ret = -1; | |
1759 | mutex_lock(&i2c_access); | |
1760 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
1761 | tpd_halt = 1; | |
1762 | mutex_unlock(&i2c_access); | |
1763 | ||
1764 | ret = gtp_enter_sleep(i2c_client_point); | |
1765 | if (ret < 0) | |
1766 | { | |
1767 | GTP_ERROR("GTP early suspend failed."); | |
1768 | } | |
1769 | ||
1770 | #if GTP_ESD_PROTECT | |
1771 | cancel_delayed_work_sync(>p_esd_check_work); | |
1772 | #endif | |
1773 | ||
1774 | #ifdef GTP_CHARGER_DETECT | |
1775 | cancel_delayed_work_sync(>p_charger_check_work); | |
1776 | #endif | |
1777 | #ifdef TPD_PROXIMITY | |
1778 | ||
1779 | if (tpd_proximity_flag == 1) | |
1780 | { | |
1781 | return ; | |
1782 | } | |
1783 | ||
1784 | #endif | |
1785 | } | |
1786 | ||
1787 | /* Function to manage power-on resume */ | |
1788 | static void tpd_resume(struct early_suspend *h) | |
1789 | { | |
1790 | s32 ret = -1; | |
1791 | ||
1792 | ret = gtp_wakeup_sleep(i2c_client_point); | |
1793 | ||
1794 | if (ret < 0) | |
1795 | { | |
1796 | GTP_ERROR("GTP later resume failed."); | |
1797 | } | |
1798 | ||
1799 | GTP_INFO("GTP wakeup sleep."); | |
1800 | ||
1801 | mutex_lock(&i2c_access); | |
1802 | tpd_halt = 0; | |
1803 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1804 | mutex_unlock(&i2c_access); | |
1805 | ||
1806 | #ifdef TPD_PROXIMITY | |
1807 | if (tpd_proximity_flag == 1) | |
1808 | { | |
1809 | return ; | |
1810 | } | |
1811 | #endif | |
1812 | ||
1813 | #if GTP_ESD_PROTECT | |
1814 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, TPD_ESD_CHECK_CIRCLE); | |
1815 | #endif | |
1816 | ||
1817 | #ifdef GTP_CHARGER_DETECT | |
1818 | queue_delayed_work(gtp_charger_check_workqueue, >p_charger_check_work, TPD_CHARGER_CHECK_CIRCLE); | |
1819 | #endif | |
1820 | ||
1821 | } | |
1822 | ||
1823 | static void tpd_off(void) | |
1824 | { | |
1825 | ||
1826 | #ifdef TPD_POWER_SOURCE_CUSTOM | |
1827 | hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP"); | |
1828 | #else | |
1829 | hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP"); | |
1830 | #endif | |
1831 | #ifdef TPD_POWER_SOURCE_1800 | |
1832 | hwPowerDown(TPD_POWER_SOURCE_1800, "TP"); | |
1833 | #endif | |
1834 | GTP_INFO("GTP enter sleep!"); | |
1835 | ||
1836 | tpd_halt = 1; | |
1837 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
1838 | } | |
1839 | ||
1840 | static void tpd_on(void) | |
1841 | { | |
1842 | s32 ret = -1, retry = 0; | |
1843 | ||
1844 | while (retry++ < 5) | |
1845 | { | |
1846 | ret = tpd_power_on(i2c_client_point); | |
1847 | ||
1848 | if (ret < 0) | |
1849 | { | |
1850 | GTP_ERROR("I2C Power on ERROR!"); | |
1851 | } | |
1852 | ||
1853 | ret = gtp_send_cfg(i2c_client_point); | |
1854 | ||
1855 | if (ret > 0) | |
1856 | { | |
1857 | GTP_DEBUG("Wakeup sleep send config success."); | |
1858 | } | |
1859 | } | |
1860 | if (ret < 0) | |
1861 | { | |
1862 | GTP_ERROR("GTP later resume failed."); | |
1863 | } | |
1864 | ||
1865 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
1866 | tpd_halt = 0; | |
1867 | } | |
1868 | static struct tpd_driver_t tpd_device_driver = | |
1869 | { | |
1870 | .tpd_device_name = "gt9xx", | |
1871 | .tpd_local_init = tpd_local_init, | |
1872 | .suspend = tpd_suspend, | |
1873 | .resume = tpd_resume, | |
1874 | #ifdef TPD_HAVE_BUTTON | |
1875 | .tpd_have_button = 1, | |
1876 | #else | |
1877 | .tpd_have_button = 0, | |
1878 | #endif | |
1879 | .attrs = { | |
1880 | .attr = gt9xx_attrs, | |
1881 | .num = ARRAY_SIZE(gt9xx_attrs), | |
1882 | }, | |
1883 | }; | |
1884 | ||
1885 | /* called when loaded into kernel */ | |
1886 | static int __init tpd_driver_init(void) | |
1887 | { | |
1888 | GTP_INFO("MediaTek gt91xx touch panel driver init"); | |
1889 | #if defined(TPD_I2C_NUMBER) | |
1890 | i2c_register_board_info(TPD_I2C_NUMBER, &i2c_tpd, 1); | |
1891 | #else | |
1892 | i2c_register_board_info(0, &i2c_tpd, 1); | |
1893 | #endif | |
1894 | if (tpd_driver_add(&tpd_device_driver) < 0) | |
1895 | GTP_INFO("add generic driver failed"); | |
1896 | ||
1897 | return 0; | |
1898 | } | |
1899 | ||
1900 | /* should never be called */ | |
1901 | static void __exit tpd_driver_exit(void) | |
1902 | { | |
1903 | GTP_INFO("MediaTek gt91xx touch panel driver exit"); | |
1904 | //input_unregister_device(tpd->dev); | |
1905 | tpd_driver_remove(&tpd_device_driver); | |
1906 | } | |
1907 | ||
1908 | module_init(tpd_driver_init); | |
1909 | module_exit(tpd_driver_exit); | |
1910 |