1 /*
2 * drivers/input/touchscreen/gslX680.c
3 *
4 * Copyright (c) 2012 Shanghai Basewin
5 * Guan Yuwei<guanyuwei@basewin.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12 #include <linux/module.h>
13 #include <linux/delay.h>
14 #include <linux/device.h>
15 #include <linux/hrtimer.h>
16 #include <linux/i2c.h>
17 #include <linux/input.h>
18 #include <linux/interrupt.h>
19 #include <linux/io.h>
20 #include <linux/platform_device.h>
21 #include <linux/async.h>
22 #include <linux/irq.h>
23 #include <linux/workqueue.h>
24 #include <linux/proc_fs.h>
25 #include <linux/input/mt.h>
26 #include <linux/gpio.h>
27 #include <linux/version.h>
28 #include <linux/slab.h>
29 #include <linux/of_gpio.h>
30 #include <linux/regulator/consumer.h>
31 #include "../tp_suspend.h"
32 #include "rockchip_gslX680_88v.h"
33 #include "rockchip_gsl3670.h"
34
35 #define REPORT_DATA_ANDROID_4_0
36
37 #define SLEEP_CLEAR_POINT
38 #ifdef FILTER_POINT
39 #define FILTER_MAX 9
40 #endif
41
42 #define GSLX680_I2C_NAME "gslX680-d708"
43 #define GSLX680_I2C_ADDR 0x40
44
45 #define GSL_DATA_REG 0x80
46 #define GSL_STATUS_REG 0xe0
47 #define GSL_PAGE_REG 0xf0
48
49 #define PRESS_MAX 255
50 #define MAX_FINGERS 5
51 #define MAX_CONTACTS 10
52 #define DMA_TRANS_LEN 0x20
53 #ifdef GSL_MONITOR
54 static struct delayed_work gsl_monitor_work;
55 static struct workqueue_struct *gsl_monitor_workqueue;
56 static u8 int_1st[4] = {0};
57 static u8 int_2nd[4] = {0};
58 static char dac_counter;
59 static char b0_counter;
60 static char bc_counter;
61 static char i2c_lock_flag;
62 #endif
63
64 /* Will@20150707 + click tp can wake up lcd when lcd suspend. */
65 /* if define enable this function */
66 /* #define BND_GESTURE */
67 #ifdef BND_GESTURE
68 extern void rk_send_wakeup_key(void);
69 static int gsl_lcd_flag = -1;
70 static int gsl_gesture_flag = -1;
71 #endif
72 #define TPD_PROC_DEBUG
73 #ifdef TPD_PROC_DEBUG
74 #include <linux/proc_fs.h>
75 #include <linux/uaccess.h>
76 #define GSL_CONFIG_PROC_FILE "gsl_config"
77 #define CONFIG_LEN 31
78 static char gsl_read[CONFIG_LEN];
79 static u8 gsl_data_proc[8] = {0};
80 static u8 gsl_proc_flag;
81 #endif
82
83 static struct i2c_client *gsl_client;
84 int g_wake_pin;
85 /* EXPORT_SYNBOL(g_wake_pin); */
86 #ifdef HAVE_TOUCH_KEY
87 static u16 key;
88 static int key_state_flag;
89 struct key_data {
90 u16 key;
91 u16 x_min;
92 u16 x_max;
93 u16 y_min;
94 u16 y_max;
95 };
96
97 const u16 key_array[] = {
98 KEY_BACK,
99 KEY_HOME,
100 KEY_MENU,
101 KEY_SEARCH,
102 };
103 #define MAX_KEY_NUM (sizeof(key_array)/sizeof(key_array[0]))
104
105 struct key_data gsl_key_data[MAX_KEY_NUM] = {
106 {KEY_BACK, 2048, 2048, 2048, 2048},
107 {KEY_HOME, 2048, 2048, 2048, 2048},
108 {KEY_MENU, 2048, 2048, 2048, 2048},
109 {KEY_SEARCH, 2048, 2048, 2048, 2048},
110 };
111 #endif
112
113 struct gsl_ts_data {
114 u8 x_index;
115 u8 y_index;
116 u8 z_index;
117 u8 id_index;
118 u8 touch_index;
119 u8 data_reg;
120 u8 status_reg;
121 u8 data_size;
122 u8 touch_bytes;
123 u8 update_data;
124 u8 touch_meta_data;
125 u8 finger_size;
126 };
127
128 static struct gsl_ts_data devices[] = {
129 {
130 .x_index = 6,
131 .y_index = 4,
132 .z_index = 5,
133 .id_index = 7,
134 .data_reg = GSL_DATA_REG,
135 .status_reg = GSL_STATUS_REG,
136 .update_data = 0x4,
137 .touch_bytes = 4,
138 .touch_meta_data = 4,
139 .finger_size = 70,
140 },
141 };
142
143 struct gsl_ts {
144 struct i2c_client *client;
145 struct input_dev *input;
146 struct work_struct work;
147 struct workqueue_struct *wq;
148 struct gsl_ts_data *dd;
149 u8 *touch_data;
150 u8 device_id;
151 int irq;
152 int irq_pin;
153 int wake_pin;
154 struct tp_device tp;
155 int screen_max_x;
156 int screen_max_y;
157 #if defined(CONFIG_HAS_EARLYSUSPEND)
158 struct early_suspend early_suspend;
159 #endif
160 struct regulator *rst;
161 };
162
163 #ifdef GSL_DEBUG
164 #define print_info(fmt, args...) \
165 do { \
166 printk(fmt, ##args); \
167 } while (0)
168 #else
169 #define print_info(fmt, args...)
170 #endif
171
172 static u32 id_sign[MAX_CONTACTS + 1] = {0};
173 static u8 id_state_flag[MAX_CONTACTS + 1] = {0};
174 static u8 id_state_old_flag[MAX_CONTACTS + 1] = {0};
175 static u16 x_old[MAX_CONTACTS + 1] = {0};
176 static u16 y_old[MAX_CONTACTS + 1] = {0};
177 static u16 x_new;
178 static u16 y_new;
179 static int revert_x;
180 static int revert_y = 1;
181 static int revert_xy = 1;
182 static u8 chip_type;
183 static u8 is_noid_version = 1;
184
185 int is_zet62xx;
186
gslX680_shutdown_low(void)187 static int gslX680_shutdown_low(void)
188 {
189 if (g_wake_pin != 0) {
190 gpio_direction_output(g_wake_pin, 0);
191 }
192
193 return 0;
194 }
195
196
gslX680_shutdown_high(void)197 static int gslX680_shutdown_high(void)
198 {
199 if (g_wake_pin != 0) {
200 gpio_direction_output(g_wake_pin, 1);
201 }
202
203 return 0;
204 }
205
join_bytes(u8 a,u8 b)206 static inline u16 join_bytes(u8 a, u8 b)
207 {
208 u16 ab = 0;
209 ab = ab | a;
210 ab = ab << 8 | b;
211 return ab;
212 }
213
gsl_write_interface(struct i2c_client * client,const u8 reg,u8 * buf,u32 num)214 static u32 gsl_write_interface(struct i2c_client *client, const u8 reg, u8 *buf, u32 num)
215 {
216 struct i2c_msg xfer_msg[1];
217
218 buf[0] = reg;
219
220 xfer_msg[0].addr = client->addr;
221 xfer_msg[0].len = num + 1;
222 xfer_msg[0].flags = client->flags & I2C_M_TEN;
223 xfer_msg[0].buf = buf;
224
225 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
226 }
227
gsl_ts_write(struct i2c_client * client,u8 addr,u8 * pdata,int datalen)228 static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata, int datalen)
229 {
230 int ret = 0;
231 u8 tmp_buf[128];
232 unsigned int bytelen = 0;
233 if (datalen > 125) {
234 printk("%s too big datalen = %d!\n", __func__, datalen);
235 return -1;
236 }
237
238 tmp_buf[0] = addr;
239 bytelen++;
240
241 if (datalen != 0 && pdata != NULL) {
242 memcpy(&tmp_buf[bytelen], pdata, datalen);
243 bytelen += datalen;
244 }
245
246 ret = i2c_master_send(client, tmp_buf, bytelen);
247 return ret;
248 }
249
gsl_ts_read(struct i2c_client * client,u8 addr,u8 * pdata,unsigned int datalen)250 static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata, unsigned int datalen)
251 {
252 int ret = 0;
253
254 if (datalen > 126) {
255 printk("%s too big datalen = %d!\n", __func__, datalen);
256 return -1;
257 }
258
259 ret = gsl_ts_write(client, addr, NULL, 0);
260 if (ret < 0) {
261 printk("%s set data address fail!\n", __func__);
262 return ret;
263 }
264
265 return i2c_master_recv(client, pdata, datalen);
266 }
267
fw2buf(u8 * buf,const u32 * fw)268 static __inline__ void fw2buf(u8 *buf, const u32 *fw)
269 {
270 u32 *u32_buf = (int *)buf;
271 *u32_buf = *fw;
272 }
273
gsl_load_fw(struct i2c_client * client)274 static void gsl_load_fw(struct i2c_client *client)
275 {
276 u8 buf[DMA_TRANS_LEN*4 + 1] = {0};
277 u8 send_flag = 1;
278 u8 *cur = buf + 1;
279 u32 source_line = 0;
280 u32 source_len;
281 const struct fw_data *ptr_fw;
282 int ret = 0;
283 int error_count = 0;
284
285 printk("=============gsl_load_fw start==============\n");
286
287 printk(" Enter gsl1680f \n");
288 ptr_fw = GSL1680F_FW;
289 source_len = ARRAY_SIZE(GSL1680F_FW);
290
291 for (source_line = 0; source_line < source_len; source_line++) {
292 /* init page trans, set the page val */
293 if (GSL_PAGE_REG == ptr_fw[source_line].offset) {
294 fw2buf(cur, &ptr_fw[source_line].val);
295 ret = gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
296 if (ret != 0) {
297 error_count++;
298 }
299 send_flag = 1;
300 } else {
301 if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
302 buf[0] = (u8)ptr_fw[source_line].offset;
303
304 fw2buf(cur, &ptr_fw[source_line].val);
305 cur += 4;
306
307 if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20)) {
308 ret = gsl_write_interface(client, buf[0], buf, cur - buf - 1);
309 if (ret != 0) {
310 error_count++;
311 }
312
313 cur = buf + 1;
314 }
315 if (error_count >= 20)
316 return;
317 send_flag++;
318 }
319 }
320
321 printk("=============gsl_load_fw end==============\n");
322
323 }
324
test_i2c(struct i2c_client * client)325 static int test_i2c(struct i2c_client *client)
326 {
327 u8 read_buf = 0;
328 u8 write_buf = 0x12;
329 int ret, rc = 1;
330
331 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
332 if (ret < 0)
333 rc--;
334 else
335 printk("I read reg 0xf0 is %x\n", read_buf);
336
337 msleep(2);
338 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
339 if (ret >= 0)
340 printk("I write reg 0xf0 0x12\n");
341
342 msleep(2);
343 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
344 if (ret < 0)
345 rc--;
346 else
347 printk("I read reg 0xf0 is 0x%x\n", read_buf);
348
349 return rc;
350 }
351
startup_chip(struct i2c_client * client)352 static void startup_chip(struct i2c_client *client)
353 {
354 u8 tmp = 0x00;
355 if (2 == is_noid_version) {
356 gsl_DataInit(gsl_config_data_id_1680f);
357 }
358
359 if (1 == is_noid_version) {
360 gsl_DataInit(gsl_config_data_id);
361 }
362
363 gsl_ts_write(client, 0xe0, &tmp, 1);
364 msleep(10);
365 }
366
reset_chip(struct i2c_client * client)367 static void reset_chip(struct i2c_client *client)
368 {
369 u8 tmp = 0x88;
370 u8 buf[4] = {0x00};
371
372 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
373 msleep(20);
374 tmp = 0x04;
375 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
376 msleep(10);
377
378 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
379 msleep(10);
380 }
381
clr_reg(struct i2c_client * client)382 static void clr_reg(struct i2c_client *client)
383 {
384 u8 write_buf[4] = {0};
385
386 write_buf[0] = 0x88;
387 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
388 msleep(20);
389 write_buf[0] = 0x03; /*jzx@20131109 for old tp ic control.*/
390 gsl_ts_write(client, 0x80, &write_buf[0], 1);
391 msleep(5);
392 write_buf[0] = 0x04;
393 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
394 msleep(5);
395 write_buf[0] = 0x00;
396 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
397 msleep(20);
398 }
399
init_chip(struct i2c_client * client)400 static void init_chip(struct i2c_client *client)
401 {
402 int rc;
403 gslX680_shutdown_low();
404 msleep(20);
405 gslX680_shutdown_high();
406 msleep(20);
407
408 rc = test_i2c(client);
409 if (rc < 0) {
410 printk("------ GslX680 test_i2c error, now touch id is Zet62xx ------\n");
411 is_zet62xx = 1;
412 return;
413 }
414 clr_reg(client);
415 reset_chip(client);
416 reset_chip(client);
417 clr_reg(client);
418 reset_chip(client);
419 gsl_load_fw(client);
420 startup_chip(client);
421 reset_chip(client);
422 startup_chip(client);
423 }
424
check_mem_data(struct i2c_client * client)425 static void check_mem_data(struct i2c_client *client)
426 {
427 u8 read_buf[4] = {0};
428
429 msleep(30);
430 gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf));
431
432 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a) {
433 print_info("#########check mem read 0xb0 = %x %x %x %x #########\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
434 init_chip(client);
435 }
436 }
437 #ifdef TPD_PROC_DEBUG
char_to_int(char ch)438 static int char_to_int(char ch)
439 {
440 if (ch >= '0' && ch <= '9')
441 return (ch - '0');
442 else
443 return (ch - 'a' + 10);
444 }
445
446 /* static int gsl_config_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) */
gsl_config_read_proc(struct seq_file * m,void * v)447 static int gsl_config_read_proc(struct seq_file *m, void *v)
448 {
449 /* char *ptr = page; */
450 char temp_data[5] = {0};
451 unsigned int tmp = 0;
452
453 if ('v' == gsl_read[0] && 's' == gsl_read[1]) {
454 #ifdef GSL_NOID_VERSION
455 tmp = gsl_version_id();
456 #else
457 tmp = 0x20121215;
458 #endif
459 /* ptr += sprintf(ptr,"version:%x\n",tmp); */
460 seq_printf(m, "version:%x\n", tmp);
461 } else if ('r' == gsl_read[0] && 'e' == gsl_read[1]) {
462 if ('i' == gsl_read[3]) {
463 #ifdef GSL_NOID_VERSION
464 tmp = (gsl_data_proc[5] << 8) | gsl_data_proc[4];
465 /*ptr +=sprintf(ptr,"gsl_config_data_id[%d] = ",tmp);*/
466 seq_printf(m, "gsl_config_data_id[%d] = ", tmp);
467 if (tmp >= 0 && tmp < 512) {
468 /* ptr +=sprintf(ptr,"%d\n",gsl_config_data_id[tmp]); */
469 seq_printf(m, "%d\n", gsl_config_data_id[tmp]);
470 }
471 #endif
472 } else {
473 i2c_smbus_write_i2c_block_data(gsl_client, 0xf0, 4, &gsl_data_proc[4]);
474 if (gsl_data_proc[0] < 0x80)
475 i2c_smbus_read_i2c_block_data(gsl_client, gsl_data_proc[0], 4, temp_data);
476 i2c_smbus_read_i2c_block_data(gsl_client, gsl_data_proc[0], 4, temp_data);
477 /*
478 ptr +=sprintf(ptr,"offset : {0x%02x,0x",gsl_data_proc[0]);
479 ptr +=sprintf(ptr,"%02x",temp_data[3]);
480 ptr +=sprintf(ptr,"%02x",temp_data[2]);
481 ptr +=sprintf(ptr,"%02x",temp_data[1]);
482 ptr +=sprintf(ptr,"%02x};\n",temp_data[0]); */
483 seq_printf(m, "offset : {0x%02x,0x", gsl_data_proc[0]);
484 seq_printf(m, "%02x", temp_data[3]);
485 seq_printf(m, "%02x", temp_data[2]);
486 seq_printf(m, "%02x", temp_data[1]);
487 seq_printf(m, "%02x};\n", temp_data[0]);
488 }
489 }
490 /* *eof = 1;
491 return (ptr - page); */
492 return 0;
493 }
gsl_config_write_proc(struct file * file,const char * buffer,size_t count,loff_t * data)494 static int gsl_config_write_proc(struct file *file, const char *buffer, size_t count, loff_t *data)
495 {
496 u8 buf[8] = {0};
497 char temp_buf[CONFIG_LEN];
498 char *path_buf;
499 int tmp = 0;
500 int tmp1 = 0;
501 print_info("[tp-gsl][%s] \n", __func__);
502 if (count > 512) {
503 print_info("size not match [%d:%ld]\n", CONFIG_LEN, count);
504 return -EFAULT;
505 }
506 path_buf = kzalloc(count, GFP_KERNEL);
507 if (!path_buf) {
508 printk("alloc path_buf memory error \n");
509 }
510 if (copy_from_user(path_buf, buffer, count)) {
511 print_info("copy from user fail\n");
512 goto exit_write_proc_out;
513 }
514 memcpy(temp_buf, path_buf, (count < CONFIG_LEN ? count : CONFIG_LEN));
515 print_info("[tp-gsl][%s][%s]\n", __func__, temp_buf);
516
517 buf[3] = char_to_int(temp_buf[14]) << 4 | char_to_int(temp_buf[15]);
518 buf[2] = char_to_int(temp_buf[16]) << 4 | char_to_int(temp_buf[17]);
519 buf[1] = char_to_int(temp_buf[18]) << 4 | char_to_int(temp_buf[19]);
520 buf[0] = char_to_int(temp_buf[20]) << 4 | char_to_int(temp_buf[21]);
521
522 buf[7] = char_to_int(temp_buf[5]) << 4 | char_to_int(temp_buf[6]);
523 buf[6] = char_to_int(temp_buf[7]) << 4 | char_to_int(temp_buf[8]);
524 buf[5] = char_to_int(temp_buf[9]) << 4 | char_to_int(temp_buf[10]);
525 buf[4] = char_to_int(temp_buf[11]) << 4 | char_to_int(temp_buf[12]);
526 if ('v' == temp_buf[0] && 's' == temp_buf[1]) {
527 memcpy(gsl_read, temp_buf, 4);
528 printk("gsl version\n");
529 } else if ('s' == temp_buf[0] && 't' == temp_buf[1]) {
530 gsl_proc_flag = 1;
531 reset_chip(gsl_client);
532 } else if ('e' == temp_buf[0] && 'n' == temp_buf[1]) {
533 msleep(20);
534 reset_chip(gsl_client);
535 startup_chip(gsl_client);
536 #ifdef GSL_NOID_VERSION
537 gsl_DataInit(gsl_config_data_id);
538 #endif
539 gsl_proc_flag = 0;
540 } else if ('r' == temp_buf[0] && 'e' == temp_buf[1]) {
541 memcpy(gsl_read, temp_buf, 4);
542 memcpy(gsl_data_proc, buf, 8);
543 } else if ('w' == temp_buf[0] && 'r' == temp_buf[1]) {
544 gsl_ts_write(gsl_client, buf[4], buf, 4);
545 }
546 #ifdef GSL_NOID_VERSION
547 else if ('i' == temp_buf[0] && 'd' == temp_buf[1]) {
548 tmp1 = (buf[7] << 24) | (buf[6] << 16) | (buf[5] << 8) | buf[4];
549 tmp = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
550
551 if (tmp1 >= 0 && tmp1 < 512) {
552 gsl_config_data_id[tmp1] = tmp;
553 }
554 }
555 #endif
556
557 exit_write_proc_out:
558 kfree(path_buf);
559 return count;
560 }
561
gsl_server_list_open(struct inode * inode,struct file * file)562 static int gsl_server_list_open(struct inode *inode, struct file *file)
563 {
564 return single_open(file, gsl_config_read_proc, NULL);
565 }
566
567 static const struct file_operations gsl_seq_fops = {
568 .open = gsl_server_list_open,
569 .read = seq_read,
570 .release = single_release,
571 .write = gsl_config_write_proc,
572 .owner = THIS_MODULE,
573 };
574 #endif
575 /* Will@20130514 - */
576
577 #ifdef FILTER_POINT
filter_point(u16 x,u16 y,u8 id)578 static void filter_point(u16 x, u16 y, u8 id)
579 {
580 u16 x_err = 0;
581 u16 y_err = 0;
582 u16 filter_step_x = 0, filter_step_y = 0;
583
584 id_sign[id] = id_sign[id] + 1;
585 if (id_sign[id] == 1) {
586 x_old[id] = x;
587 y_old[id] = y;
588 }
589
590 x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x);
591 y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y);
592
593 if ((x_err > FILTER_MAX && y_err > FILTER_MAX / 3) || (x_err > FILTER_MAX / 3 && y_err > FILTER_MAX)) {
594 filter_step_x = x_err;
595 filter_step_y = y_err;
596 } else {
597 if (x_err > FILTER_MAX)
598 filter_step_x = x_err;
599 if (y_err > FILTER_MAX)
600 filter_step_y = y_err;
601 }
602
603 if (x_err <= 2 * FILTER_MAX && y_err <= 2 * FILTER_MAX) {
604 filter_step_x >>= 2;
605 filter_step_y >>= 2;
606 } else if (x_err <= 3 * FILTER_MAX && y_err <= 3 * FILTER_MAX) {
607 filter_step_x >>= 1;
608 filter_step_y >>= 1;
609 } else if (x_err <= 4 * FILTER_MAX && y_err <= 4 * FILTER_MAX) {
610 filter_step_x = filter_step_x * 3 / 4;
611 filter_step_y = filter_step_y * 3 / 4;
612 }
613
614 x_new = x > x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] - filter_step_x);
615 y_new = y > y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] - filter_step_y);
616
617 x_old[id] = x_new;
618 y_old[id] = y_new;
619 }
620 #else
record_point(u16 x,u16 y,u8 id)621 static void record_point(u16 x, u16 y, u8 id)
622 {
623 u16 x_err = 0;
624 u16 y_err = 0;
625
626 id_sign[id] = id_sign[id] + 1;
627
628 if (id_sign[id] == 1) {
629 x_old[id] = x;
630 y_old[id] = y;
631 }
632
633 x = (x_old[id] + x) / 2;
634 y = (y_old[id] + y) / 2;
635
636 if (x > x_old[id]) {
637 x_err = x - x_old[id];
638 } else {
639 x_err = x_old[id] - x;
640 }
641
642 if (y > y_old[id]) {
643 y_err = y - y_old[id];
644 } else {
645 y_err = y_old[id] - y;
646 }
647
648 if ((x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3)) {
649 x_new = x;
650 x_old[id] = x;
651 y_new = y;
652 y_old[id] = y;
653 } else {
654 if (x_err > 3) {
655 x_new = x;
656 x_old[id] = x;
657 } else
658 x_new = x_old[id];
659 if (y_err > 3) {
660 y_new = y;
661 y_old[id] = y;
662 } else
663 y_new = y_old[id];
664 }
665
666 if (id_sign[id] == 1) {
667 x_new = x_old[id];
668 y_new = y_old[id];
669 }
670 }
671 #endif
672
673 #ifdef HAVE_TOUCH_KEY
report_key(struct gsl_ts * ts,u16 x,u16 y)674 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
675 {
676 u16 i = 0;
677
678 for (i = 0; i < MAX_KEY_NUM; i++) {
679 if ((gsl_key_data[i].x_min < x) && (x < gsl_key_data[i].x_max) && (gsl_key_data[i].y_min < y) && (y < gsl_key_data[i].y_max)) {
680 key = gsl_key_data[i].key;
681 input_report_key(ts->input, key, 1);
682 input_sync(ts->input);
683 key_state_flag = 1;
684 break;
685 }
686 }
687 }
688 #endif
689
report_data(struct gsl_ts * ts,u16 x,u16 y,u8 pressure,u8 id)690 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
691 {
692 if (revert_xy)
693 swap(x, y);
694 if (revert_x)
695 x = ts->screen_max_x - x;
696 if (revert_y)
697 y = ts->screen_max_y - y;
698
699 print_info("#####id=%d,x=%d,y=%d######\n", id, x, y);
700 print_info("#####revert_xy=%d,revert_x=%d,revert_y=%d######\n", revert_xy, revert_x, revert_y);
701
702 if (x > ts->screen_max_x || y > ts->screen_max_y) {
703 #ifdef HAVE_TOUCH_KEY
704 report_key(ts, x, y);
705 #endif
706 return;
707 }
708 #ifdef BND_GESTURE
709 print_info("\n gsl_lcd_flag = %d ---- gsl_gesture_flag = %d \n\n", gsl_lcd_flag, gsl_gesture_flag);
710 if (1 == gsl_lcd_flag && 1 == gsl_gesture_flag) {
711 print_info("auto wake up lcd\n");
712 rk_send_wakeup_key();
713 } else {
714 gsl_gesture_flag = 0;
715 }
716 #endif
717 #ifdef REPORT_DATA_ANDROID_4_0
718 input_mt_slot(ts->input, id);
719 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
720 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
721 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
722 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
723 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
724 #else
725 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
726 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
727 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
728 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
729 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
730 input_mt_sync(ts->input);
731 #endif
732 }
733
gslX680_ts_worker(struct work_struct * work)734 static void gslX680_ts_worker(struct work_struct *work)
735 {
736
737 int rc, i;
738 u8 id, touches/*, read_buf[4] = {0}*/;
739 u16 x, y;
740
741 struct gsl_touch_info cinfo = { { 0 } };
742 u32 tmp1 = 0;
743 u8 buf[4] = {0};
744
745 struct gsl_ts *ts = container_of(work, struct gsl_ts, work);
746
747 print_info("=====gslX680_ts_worker=====\n");
748
749 #ifdef TPD_PROC_DEBUG
750 if (gsl_proc_flag == 1)
751 goto schedule;
752 #endif
753 #ifdef GSL_MONITOR
754 if (i2c_lock_flag != 0)
755 goto i2c_lock_schedule;
756 else
757 i2c_lock_flag = 1;
758 #endif
759
760 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
761 if (rc < 0) {
762 dev_err(&ts->client->dev, "read failed\n");
763 goto schedule;
764 }
765
766 touches = ts->touch_data[ts->dd->touch_index];
767 print_info("-----touches: %d -----\n", touches);
768
769 if (is_noid_version) {
770 cinfo.finger_num = touches;
771 print_info("tp-gsl finger_num = %d\n", cinfo.finger_num);
772 for (i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i++) {
773 cinfo.x[i] = join_bytes((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
774 ts->touch_data[ts->dd->x_index + 4 * i]);
775 cinfo.y[i] = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
776 ts->touch_data[ts->dd->y_index + 4 * i]);
777 print_info("tp-gsl x = %d y = %d \n", cinfo.x[i], cinfo.y[i]);
778 }
779 cinfo.finger_num = (ts->touch_data[3] << 24) | (ts->touch_data[2] << 16)
780 | (ts->touch_data[1] << 8) | (ts->touch_data[0]);
781 gsl_alg_id_main(&cinfo);
782 tmp1 = gsl_mask_tiaoping();
783 print_info("[tp-gsl] tmp1=%x\n", tmp1);
784 if (tmp1 > 0 && tmp1 < 0xffffffff) {
785 buf[0] = 0xa;
786 buf[1] = 0;
787 buf[2] = 0;
788 buf[3] = 0;
789 gsl_ts_write(gsl_client, 0xf0, buf, 4);
790 buf[0] = (u8)(tmp1 & 0xff);
791 buf[1] = (u8)((tmp1>>8) & 0xff);
792 buf[2] = (u8)((tmp1>>16) & 0xff);
793 buf[3] = (u8)((tmp1>>24) & 0xff);
794 printk("tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x,buf[3]=%02x\n",
795 tmp1, buf[0], buf[1], buf[2], buf[3]);
796 gsl_ts_write(gsl_client, 0x8, buf, 4);
797 }
798 touches = cinfo.finger_num;
799 }
800
801 for (i = 1; i <= MAX_CONTACTS; i++) {
802 if (touches == 0)
803 id_sign[i] = 0;
804 id_state_flag[i] = 0;
805 }
806 for (i = 0; i < (touches > MAX_FINGERS ? MAX_FINGERS : touches); i++) {
807 if (is_noid_version) {
808 id = cinfo.id[i];
809 x = cinfo.x[i];
810 y = cinfo.y[i];
811 } else {
812 x = join_bytes((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
813 ts->touch_data[ts->dd->x_index + 4 * i]);
814 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
815 ts->touch_data[ts->dd->y_index + 4 * i]);
816 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
817 }
818
819 if (1 <= id && id <= MAX_CONTACTS) {
820 #ifdef FILTER_POINT
821 filter_point(x, y, id);
822 #else
823 record_point(x, y, id);
824 #endif
825 report_data(ts, x_new, y_new, 10, id);
826 id_state_flag[id] = 1;
827 }
828 }
829 for (i = 1; i <= MAX_CONTACTS; i++) {
830 if ((0 == touches) || ((0 != id_state_old_flag[i]) && (0 == id_state_flag[i]))) {
831 #ifdef REPORT_DATA_ANDROID_4_0
832 input_mt_slot(ts->input, i);
833 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
834 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
835 #endif
836 id_sign[i] = 0;
837 }
838 id_state_old_flag[i] = id_state_flag[i];
839 }
840 #ifndef REPORT_DATA_ANDROID_4_0
841 if (0 == touches) {
842 input_mt_sync(ts->input);
843 #ifdef HAVE_TOUCH_KEY
844 if (key_state_flag) {
845 input_report_key(ts->input, key, 0);
846 input_sync(ts->input);
847 key_state_flag = 0;
848 }
849 #endif
850 }
851 #endif
852 input_sync(ts->input);
853
854 schedule:
855 #ifdef GSL_MONITOR
856 i2c_lock_flag = 0;
857 i2c_lock_schedule:
858 #endif
859 enable_irq(ts->irq);
860 }
861
862 #ifdef GSL_MONITOR
gsl_monitor_worker(struct work_struct * work)863 static void gsl_monitor_worker(struct work_struct *work)
864 {
865 u8 write_buf[4] = {0};
866 u8 read_buf[4] = {0};
867 char init_chip_flag = 0;
868
869 print_info("----------------gsl_monitor_worker-----------------\n");
870
871 #ifdef TPD_PROC_DEBUG
872 if (gsl_proc_flag == 1) {
873 return;
874 }
875 #endif
876
877 if (i2c_lock_flag != 0)
878 goto queue_monitor_work;
879 else
880 i2c_lock_flag = 1;
881
882 gsl_ts_read(gsl_client, 0xb0, read_buf, 4);
883 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a)
884 b0_counter++;
885 else
886 b0_counter = 0;
887
888 if (b0_counter > 1) {
889 printk("======read 0xb0: %x %x %x %x ======\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
890 init_chip_flag = 1;
891 b0_counter = 0;
892 goto queue_monitor_init_chip;
893 }
894
895 gsl_ts_read(gsl_client, 0xb4, read_buf, 4);
896 int_2nd[3] = int_1st[3];
897 int_2nd[2] = int_1st[2];
898 int_2nd[1] = int_1st[1];
899 int_2nd[0] = int_1st[0];
900 int_1st[3] = read_buf[3];
901 int_1st[2] = read_buf[2];
902 int_1st[1] = read_buf[1];
903 int_1st[0] = read_buf[0];
904
905 if (int_1st[3] == int_2nd[3] && int_1st[2] == int_2nd[2] && int_1st[1] == int_2nd[1] && int_1st[0] == int_2nd[0]) {
906 printk("======int_1st: %x %x %x %x , int_2nd: %x %x %x %x ======\n", int_1st[3], int_1st[2], int_1st[1], int_1st[0], int_2nd[3], int_2nd[2], int_2nd[1], int_2nd[0]);
907 init_chip_flag = 1;
908 goto queue_monitor_init_chip;
909 }
910
911 #if 1
912 gsl_ts_read(gsl_client, 0xbc, read_buf, 4);
913 if (read_buf[3] != 0 || read_buf[2] != 0 || read_buf[1] != 0 || read_buf[0] != 0)
914 bc_counter++;
915 else
916 bc_counter = 0;
917 if (bc_counter > 1) {
918 printk("======read 0xbc: %x %x %x %x======\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
919 init_chip_flag = 1;
920 bc_counter = 0;
921 }
922 #else
923 write_buf[3] = 0x01;
924 write_buf[2] = 0xfe;
925 write_buf[1] = 0x10;
926 write_buf[0] = 0x00;
927 gsl_ts_write(gsl_client, 0xf0, write_buf, 4);
928 gsl_ts_read(gsl_client, 0x10, read_buf, 4);
929 gsl_ts_read(gsl_client, 0x10, read_buf, 4);
930
931 if (read_buf[3] < 10 && read_buf[2] < 10 && read_buf[1] < 10 && read_buf[0] < 10)
932 dac_counter++;
933 else
934 dac_counter = 0;
935
936 if (dac_counter > 1) {
937 printk("======read DAC1_0: %x %x %x %x ======\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
938 init_chip_flag = 1;
939 dac_counter = 0;
940 }
941 #endif
942 queue_monitor_init_chip:
943 if (init_chip_flag) {
944 #ifdef GSLX680_COMPATIBLE
945 judge_chip_type(gsl_client);
946 #endif
947 init_chip(gsl_client);
948 reset_chip(gsl_client);
949 startup_chip(gsl_client);
950 check_mem_data(gsl_client);
951 }
952
953 i2c_lock_flag = 0;
954
955 queue_monitor_work:
956 queue_delayed_work(gsl_monitor_workqueue, &gsl_monitor_work, 100);
957 }
958 #endif
959
gsl_ts_irq(int irq,void * dev_id)960 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
961 {
962 struct gsl_ts *ts = dev_id;
963
964 print_info("========gslX680 Interrupt=========\n");
965 #ifdef BND_GESTURE
966 if (1 == gsl_lcd_flag)
967 gsl_gesture_flag = 1;
968 #endif
969 disable_irq_nosync(ts->irq);
970
971 if (!work_pending(&ts->work)) {
972 queue_work(ts->wq, &ts->work);
973 }
974
975 return IRQ_HANDLED;
976 }
977
gsl_ts_init_ts(struct i2c_client * client,struct gsl_ts * ts)978 static int gsl_ts_init_ts(struct i2c_client *client, struct gsl_ts *ts)
979 {
980 struct input_dev *input_device;
981 int rc = 0;
982
983 printk("[GSLX680] Enter %s\n", __func__);
984
985 ts->dd = &devices[ts->device_id];
986
987 if (ts->device_id == 0) {
988 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
989 ts->dd->touch_index = 0;
990 }
991
992 ts->touch_data = devm_kzalloc(&client->dev, ts->dd->data_size, GFP_KERNEL);
993 if (!ts->touch_data) {
994 pr_err("%s: Unable to allocate memory\n", __func__);
995 return -ENOMEM;
996 }
997
998 input_device = input_allocate_device();
999 if (!input_device) {
1000 rc = -ENOMEM;
1001 goto error_alloc_dev;
1002 }
1003
1004 ts->input = input_device;
1005 input_device->name = GSLX680_I2C_NAME;
1006 input_device->id.bustype = BUS_I2C;
1007 input_device->dev.parent = &client->dev;
1008 input_set_drvdata(input_device, ts);
1009
1010 #ifdef REPORT_DATA_ANDROID_4_0
1011 __set_bit(EV_ABS, input_device->evbit);
1012 __set_bit(EV_KEY, input_device->evbit);
1013 __set_bit(EV_REP, input_device->evbit);
1014 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1015 input_mt_init_slots(input_device, (MAX_CONTACTS+1), 0);
1016 #else
1017 input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0);
1018 set_bit(EV_ABS, input_device->evbit);
1019 set_bit(EV_KEY, input_device->evbit);
1020 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1021 input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1022 #endif
1023
1024 #ifdef HAVE_TOUCH_KEY
1025 input_device->evbit[0] = BIT_MASK(EV_KEY);
1026 for (i = 0; i < MAX_KEY_NUM; i++)
1027 set_bit(key_array[i], input_device->keybit);
1028 #endif
1029
1030 set_bit(ABS_MT_POSITION_X, input_device->absbit);
1031 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
1032 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
1033 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
1034
1035 input_set_abs_params(input_device, ABS_MT_POSITION_X, 0, ts->screen_max_x, 0, 0);
1036 input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0, ts->screen_max_y, 0, 0);
1037 input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
1038 input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
1039
1040 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
1041 if (!ts->wq) {
1042 dev_err(&client->dev, "Could not create workqueue\n");
1043 goto error_wq_create;
1044 }
1045 flush_workqueue(ts->wq);
1046
1047 INIT_WORK(&ts->work, gslX680_ts_worker);
1048
1049 rc = input_register_device(input_device);
1050 if (rc)
1051 goto error_unreg_device;
1052
1053 return 0;
1054 error_unreg_device:
1055 destroy_workqueue(ts->wq);
1056 error_wq_create:
1057 input_free_device(input_device);
1058 error_alloc_dev:
1059 return rc;
1060 }
1061
gsl_ts_suspend(struct device * dev)1062 static int gsl_ts_suspend(struct device *dev)
1063 {
1064 struct gsl_ts *ts = dev_get_drvdata(dev);
1065 int i;
1066 int tmp = 0;
1067
1068 #ifdef GSL_NOID_VERSION
1069 tmp = gsl_version_id();
1070 #endif
1071
1072 #ifdef TPD_PROC_DEBUG
1073 if (gsl_proc_flag == 1) {
1074 return -1;
1075 }
1076 #endif
1077
1078 #ifdef GSL_MONITOR
1079 cancel_delayed_work_sync(&gsl_monitor_work);
1080 #endif
1081 /*
1082 #ifdef BND_GESTURE
1083 // disable_irq_nosync(ts->irq);
1084 #else
1085 disable_irq_nosync(ts->irq);
1086 #endif*/
1087
1088 #ifdef BND_GESTURE
1089 /* gslX680_shutdown_low(); */
1090 #else
1091 gslX680_shutdown_low();
1092 #endif
1093
1094 #ifdef SLEEP_CLEAR_POINT
1095 msleep(10);
1096 #ifdef REPORT_DATA_ANDROID_4_0
1097 for (i = 1; i <= MAX_CONTACTS; i++) {
1098 input_mt_slot(ts->input, i);
1099 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1100 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1101 }
1102 #else
1103 input_mt_sync(ts->input);
1104 #endif
1105 input_sync(ts->input);
1106 msleep(10);
1107 report_data(ts, 1, 1, 10, 1);
1108 input_sync(ts->input);
1109 #endif
1110
1111 return 0;
1112 }
1113
gsl_ts_resume(struct device * dev)1114 static int gsl_ts_resume(struct device *dev)
1115 {
1116 struct gsl_ts *ts = dev_get_drvdata(dev);
1117 int i;
1118
1119 #ifdef TPD_PROC_DEBUG
1120 if (gsl_proc_flag == 1) {
1121 return -1;
1122 }
1123 #endif
1124
1125 if ((!IS_ERR(ts->rst)) && regulator_is_enabled(ts->rst) > 0)
1126 regulator_disable(ts->rst);
1127 gslX680_shutdown_high();
1128 msleep(20);
1129 reset_chip(ts->client);
1130 startup_chip(ts->client);
1131 check_mem_data(ts->client);
1132
1133 #ifdef SLEEP_CLEAR_POINT
1134 #ifdef REPORT_DATA_ANDROID_4_0
1135 for (i = 1 ; i <= MAX_CONTACTS; i++) {
1136 input_mt_slot(ts->input, i);
1137 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1138 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1139 }
1140 #else
1141 input_mt_sync(ts->input);
1142 #endif
1143 input_sync(ts->input);
1144 #endif
1145 #ifdef GSL_MONITOR
1146 queue_delayed_work(gsl_monitor_workqueue, &gsl_monitor_work, 300);
1147 #endif
1148 /*
1149 #ifdef BND_GESTURE
1150 enable_irq(ts->irq);
1151 #else
1152 enable_irq(ts->irq);
1153 #endif*/
1154
1155 return 0;
1156 }
1157
1158 #if 1
gsl_ts_early_suspend(struct tp_device * tp_d)1159 static int gsl_ts_early_suspend(struct tp_device *tp_d)
1160 {
1161 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1162 #ifdef BND_GESTURE
1163 gsl_lcd_flag = 1;
1164 #endif
1165 return gsl_ts_suspend(&ts->client->dev);
1166 }
1167
gsl_ts_late_resume(struct tp_device * tp_d)1168 static int gsl_ts_late_resume(struct tp_device *tp_d)
1169 {
1170 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1171 #ifdef BND_GESTURE
1172 gsl_lcd_flag = 0;
1173 gsl_gesture_flag = 0;
1174 #endif
1175 return gsl_ts_resume(&ts->client->dev);
1176 }
1177 #endif
1178
judge_chip_type(struct i2c_client * client)1179 void judge_chip_type(struct i2c_client *client)
1180 {
1181 u8 read_buf[4] = {0};
1182 msleep(100);
1183 gsl_ts_read(client, 0xfc, read_buf, 4);
1184 printk("read 0xfc = %x %x %x %x\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
1185
1186 if (read_buf[2] != 0x91 && read_buf[2] != 0x88 && read_buf[2] != 0x82) {
1187 msleep(100);
1188 gsl_ts_read(client, 0xfc, read_buf, 4);
1189 printk("read 0xfc = %x %x %x %x\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
1190 }
1191
1192 if (read_buf[2] == 0x91) {
1193 chip_type = 2;
1194 is_noid_version = 1;
1195 }
1196 #ifdef GSL1680F_COMPATIBLE
1197 else if ((read_buf[3]&0xf0) == 0xb0 && read_buf[2] == 0x82) {
1198 chip_type = 3;
1199 is_noid_version = 2;
1200 }
1201 #endif
1202 #ifdef GSL1680E_COMPATIBLE
1203 else if (read_buf[2] == 0x82) {
1204 chip_type = 1;
1205 is_noid_version = 0;
1206 }
1207 #endif
1208 else {
1209 chip_type = 0;
1210 is_noid_version = 0;
1211 }
1212 }
gsl_ts_probe(struct i2c_client * client,const struct i2c_device_id * id)1213 static int gsl_ts_probe(struct i2c_client *client,
1214 const struct i2c_device_id *id)
1215 {
1216 struct gsl_ts *ts;
1217 int rc;
1218 struct device_node *np = client->dev.of_node;
1219 enum of_gpio_flags wake_flags;
1220
1221 printk("GSLX680 Enter %s\n", __func__);
1222 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1223 dev_err(&client->dev, "I2C functionality not supported\n");
1224 return -ENODEV;
1225 }
1226
1227 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
1228 if (!ts)
1229 return -ENOMEM;
1230
1231 ts->client = client;
1232 i2c_set_clientdata(client, ts);
1233 ts->device_id = id->driver_data;
1234
1235 of_property_read_u32(np, "screen_max_x", &(ts->screen_max_x));
1236 of_property_read_u32(np, "screen_max_y", &(ts->screen_max_y));
1237 of_property_read_u32(np, "revert_x", &revert_x);
1238 of_property_read_u32(np, "revert_y", &revert_y);
1239
1240 ts->irq_pin = of_get_named_gpio_flags(np, "touch-gpio", 0, NULL);
1241 ts->wake_pin = of_get_named_gpio_flags(np, "wake-gpio", 0, &wake_flags);
1242 if (gpio_is_valid(ts->wake_pin)) {
1243 rc = devm_gpio_request_one(&client->dev, ts->wake_pin, (wake_flags & OF_GPIO_ACTIVE_LOW) ? GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, "gslX680 wake pin");
1244 if (rc != 0) {
1245 dev_err(&client->dev, "gslX680 wake pin error\n");
1246 return -EIO;
1247 }
1248 g_wake_pin = ts->wake_pin;
1249 } else {
1250 dev_info(&client->dev, "wake pin invalid\n");
1251 }
1252 if (!gpio_is_valid(ts->irq_pin)) {
1253 dev_info(&client->dev, "irq pin invalid\n");
1254 goto error_mutex_destroy;
1255 }
1256
1257 ts->rst = devm_regulator_get(&client->dev, "rst");
1258 if (IS_ERR(ts->rst)) {
1259 dev_err(&client->dev, "failed to get regulator, %ld\n",
1260 PTR_ERR(ts->rst));
1261 }
1262
1263 rc = gsl_ts_init_ts(client, ts);
1264 if (rc < 0) {
1265 dev_err(&client->dev, "GSLX680 init failed\n");
1266 goto error_mutex_destroy;
1267 }
1268
1269 gsl_client = client;
1270
1271 /* gslX680_init();
1272 gpio_set_value(ts->irq_pin,1);
1273 msleep(20); */
1274 gslX680_shutdown_low();
1275 msleep(20);
1276 gslX680_shutdown_high();
1277 msleep(20);
1278 judge_chip_type(ts->client);
1279
1280 init_chip(ts->client);
1281 check_mem_data(ts->client);
1282
1283 ts->irq = gpio_to_irq(ts->irq_pin);
1284 if (ts->irq) {
1285 rc = devm_request_threaded_irq(&client->dev, ts->irq, NULL, gsl_ts_irq, IRQF_TRIGGER_RISING | IRQF_ONESHOT, client->name, ts);
1286 if (rc != 0) {
1287 printk(KERN_ALERT "Cannot allocate ts INT!ERRNO:%d\n", rc);
1288 goto error_req_irq_fail;
1289 }
1290 disable_irq(ts->irq);
1291 } else {
1292 printk("gslx680 irq req fail\n");
1293 goto error_req_irq_fail;
1294 }
1295 enable_irq(ts->irq);
1296 /* create debug attribute */
1297 /* rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable); */
1298 ts->tp.tp_resume = gsl_ts_late_resume;
1299 ts->tp.tp_suspend = gsl_ts_early_suspend;
1300 tp_register_fb(&ts->tp);
1301
1302 #ifdef CONFIG_HAS_EARLYSUSPEND
1303 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1304 ts->early_suspend.suspend = gsl_ts_early_suspend;
1305 ts->early_suspend.resume = gsl_ts_late_resume;
1306 register_early_suspend(&ts->early_suspend);
1307 #endif
1308
1309 #ifdef GSL_MONITOR
1310
1311 INIT_DELAYED_WORK(&gsl_monitor_work, gsl_monitor_worker);
1312 gsl_monitor_workqueue = create_singlethread_workqueue("gsl_monitor_workqueue");
1313 queue_delayed_work(gsl_monitor_workqueue, &gsl_monitor_work, 1000);
1314 #endif
1315
1316 #ifdef TPD_PROC_DEBUG
1317 proc_create(GSL_CONFIG_PROC_FILE, 0644, NULL, &gsl_seq_fops);
1318 gsl_proc_flag = 0;
1319 #endif
1320 if (1 == is_zet62xx) {
1321 printk(" touch id is zet62xx,so free gpio!\n");
1322 gpio_free(g_wake_pin);
1323 free_irq(ts->irq, ts);
1324 }
1325 printk("[GSLX680] End %s\n", __func__);
1326
1327 return 0;
1328
1329 error_req_irq_fail:
1330 free_irq(ts->irq, ts);
1331
1332 error_mutex_destroy:
1333 input_free_device(ts->input);
1334 return rc;
1335 }
1336
gsl_ts_remove(struct i2c_client * client)1337 static int gsl_ts_remove(struct i2c_client *client)
1338 {
1339 struct gsl_ts *ts = i2c_get_clientdata(client);
1340
1341 #ifdef CONFIG_HAS_EARLYSUSPEND
1342 unregister_early_suspend(&ts->early_suspend);
1343 #endif
1344
1345 #ifdef GSL_MONITOR
1346 cancel_delayed_work_sync(&gsl_monitor_work);
1347 destroy_workqueue(gsl_monitor_workqueue);
1348 #endif
1349
1350 device_init_wakeup(&client->dev, 0);
1351 cancel_work_sync(&ts->work);
1352 free_irq(ts->irq, ts);
1353 destroy_workqueue(ts->wq);
1354 input_unregister_device(ts->input);
1355 return 0;
1356 }
1357
1358 static const struct i2c_device_id gsl_ts_id[] = {
1359 {GSLX680_I2C_NAME, 0},
1360 {}
1361 };
1362 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1363
1364 static struct i2c_driver gsl_ts_driver = {
1365 .driver = {
1366 .name = GSLX680_I2C_NAME,
1367 .owner = THIS_MODULE,
1368 },
1369 .probe = gsl_ts_probe,
1370 .remove = gsl_ts_remove,
1371 .id_table = gsl_ts_id,
1372 };
1373
gsl_ts_init(void)1374 static int __init gsl_ts_init(void)
1375 {
1376 int ret;
1377 ret = i2c_add_driver(&gsl_ts_driver);
1378 return ret;
1379 }
1380
gsl_ts_exit(void)1381 static void __exit gsl_ts_exit(void)
1382 {
1383 i2c_del_driver(&gsl_ts_driver);
1384 return;
1385 }
1386
1387 module_init(gsl_ts_init);
1388 module_exit(gsl_ts_exit);
1389
1390 MODULE_LICENSE("GPL");
1391 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1392 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1393 MODULE_ALIAS("platform:gsl_ts");
1394