xref: /OK3568_Linux_fs/kernel/drivers/input/touchscreen/gslx680.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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/hrtimer.h>
15 #include <linux/i2c.h>
16 #include <linux/input.h>
17 #include <linux/interrupt.h>
18 #include <linux/io.h>
19 #include <linux/platform_device.h>
20 #include <linux/async.h>
21 #include <linux/gpio.h>
22 #include <asm/irq.h>
23 #include <linux/slab.h>
24 #include <linux/uaccess.h>
25 #include <linux/workqueue.h>
26 #include <linux/proc_fs.h>
27 #include <linux/input/mt.h>
28 //#include "rockchip_gslX680_rk3168.h"
29 #include "tp_suspend.h"
30 #include "gslx680.h"
31 #include <linux/of_gpio.h>
32 #include <linux/wakelock.h>
33 #include <linux/of_platform.h>
34 
35 #define GSL_DEBUG
36 
37 /*
38 struct fw_data
39 {
40 	u32 offset : 8;
41 	u32 : 0;
42 	u32 val;
43 };
44 */
45 
46 #define RK_GEAR_TOUCH
47 #define REPORT_DATA_ANDROID_4_0
48 #define HAVE_TOUCH_KEY
49 //#define SLEEP_CLEAR_POINT
50 
51 //#define FILTER_POINT
52 
53 #ifdef FILTER_POINT
54 #define FILTER_MAX	9	//6
55 #endif
56 
57 #define GSLX680_I2C_NAME	"gslX680"
58 #define GSLX680_I2C_ADDR	0x40
59 
60 //#define IRQ_PORT	RK2928_PIN1_PB0//RK30_PIN1_PB7
61 //#define WAKE_PORT	RK30_PIN0_PA1//RK30_PIN0_PB6
62 
63 #define GSL_DATA_REG		0x80
64 #define GSL_STATUS_REG		0xe0
65 #define GSL_PAGE_REG		0xf0
66 
67 #define TPD_PROC_DEBUG
68 #ifdef TPD_PROC_DEBUG
69 #include <linux/proc_fs.h>
70 #include <linux/uaccess.h>
71 #include <linux/seq_file.h>
72 //static struct proc_dir_entry *gsl_config_proc = NULL;
73 #define GSL_CONFIG_PROC_FILE "gsl_config"
74 #define CONFIG_LEN 31
75 static char gsl_read[CONFIG_LEN];
76 static u8 gsl_data_proc[8] = { 0 };
77 static u8 gsl_proc_flag = 0;
78 static struct i2c_client *i2c_client = NULL;
79 #endif
80 #define GSL_MONITOR
81 #define PRESS_MAX		255
82 #define MAX_FINGERS		10
83 #define MAX_CONTACTS		10
84 #define DMA_TRANS_LEN		0x20
85 #ifdef GSL_MONITOR
86 
87 #ifdef RK_GEAR_TOUCH
88 static int g_istouch=0;
89 #endif
90 
91 static struct workqueue_struct *gsl_monitor_workqueue = NULL;
92 static u8 int_1st[4] = { 0 };
93 static u8 int_2nd[4] = { 0 };
94 //static char dac_counter = 0;
95 static char b0_counter = 0;
96 static char bc_counter = 0;
97 static char i2c_lock_flag = 0;
98 #endif
99 
100 #define WRITE_I2C_SPEED	(350*1000)
101 #define I2C_SPEED	(200*1000)
102 #define CLOSE_TP_POWER   0
103 //add by yuandan
104 //#define HAVE_CLICK_TIMER
105 
106 #ifdef HAVE_CLICK_TIMER
107 
108 static struct workqueue_struct *gsl_timer_workqueue = NULL;
109 bool send_key = false;
110 struct semaphore my_sem;
111 #endif
112 
113 #ifdef HAVE_TOUCH_KEY
114 static u16 key = 0;
115 static int key_state_flag = 0;
116 struct key_data {
117 	u16 key;
118 	u16 x_min;
119 	u16 x_max;
120 	u16 y_min;
121 	u16 y_max;
122 };
123 
124 const u16 key_array[] = {
125 	KEY_LEFT,
126 	KEY_RIGHT,
127 	KEY_UP,
128 	KEY_DOWN,
129 	KEY_ENTER,
130 };
131 
132 #define MAX_KEY_NUM     (sizeof(key_array)/sizeof(key_array[0]))
133 //add by yuandan
134 static int key_x[512];
135 static int key_y[512];
136 static int key_count;
137 #ifdef SLEEP_CLEAR_POINT
138 static const struct key_data gsl_key_data[MAX_KEY_NUM] = {
139 	{KEY_BACK, 550, 650, 1400, 1600},
140 	{KEY_HOMEPAGE, 350, 450, 1400, 1600},
141 	{KEY_MENU, 150, 250, 1400, 1600},
142 	{KEY_SEARCH, 2048, 2048, 2048, 2048},
143 };
144 #endif
145 #endif
146 
147 struct gsl_ts_data {
148 	u8 x_index;
149 	u8 y_index;
150 	u8 z_index;
151 	u8 id_index;
152 	u8 touch_index;
153 	u8 data_reg;
154 	u8 status_reg;
155 	u8 data_size;
156 	u8 touch_bytes;
157 	u8 update_data;
158 	u8 touch_meta_data;
159 	u8 finger_size;
160 };
161 
162 static struct gsl_ts_data devices[] = {
163 	{
164 	 .x_index = 6,
165 	 .y_index = 4,
166 	 .z_index = 5,
167 	 .id_index = 7,
168 	 .data_reg = GSL_DATA_REG,
169 	 .status_reg = GSL_STATUS_REG,
170 	 .update_data = 0x4,
171 	 .touch_bytes = 4,
172 	 .touch_meta_data = 4,
173 	 .finger_size = 70,
174 	 },
175 };
176 
177 struct gsl_ts_cfg {
178 	struct fw_data *fw_ptr;
179 	unsigned int fw_size;
180 	enum gsl_quirk quirks;
181 	unsigned int *cfg_id;
182 	int max_x;
183 	int max_y;
184 	bool x_pol;
185 	bool y_pol;
186 };
187 
188 struct gsl_ts {
189 	struct i2c_client *client;
190 	struct input_dev *input;
191 	struct work_struct work;
192 	struct workqueue_struct *wq;
193 	struct gsl_ts_data *dd;
194 	int flag_irq_is_disable;
195 	spinlock_t irq_lock;
196 	u8 *touch_data;
197 	u8 device_id;
198 	int irq;
199 	int rst;
200 	struct delayed_work gsl_monitor_work;
201 #if defined(CONFIG_HAS_EARLYSUSPEND)
202 	struct early_suspend early_suspend;
203 #endif
204 
205 #if defined (HAVE_CLICK_TIMER)
206 	struct work_struct click_work;
207 #endif
208 
209 	struct tp_device tp;
210 	struct pinctrl *pinctrl;
211 	struct pinctrl_state *pins_default;
212 	struct pinctrl_state *pins_sleep;
213 	struct pinctrl_state *pins_inactive;
214 	const struct gsl_ts_cfg *ts_cfg;
215 };
216 
217 #ifdef GSL_DEBUG
218 #define print_info(fmt, args...)	printk(fmt, ##args);
219 #else
220 #define print_info(fmt, args...)
221 #endif
222 
223 static u32 id_sign[MAX_CONTACTS + 1] = { 0 };
224 static u8 id_state_flag[MAX_CONTACTS + 1] = { 0 };
225 static u8 id_state_old_flag[MAX_CONTACTS + 1] = { 0 };
226 static u16 x_old[MAX_CONTACTS + 1] = { 0 };
227 static u16 y_old[MAX_CONTACTS + 1] = { 0 };
228 static u16 x_new = 0;
229 static u16 y_new = 0;
230 
231 static const struct gsl_ts_cfg gslx680_vr_cfg = {
232 	.fw_ptr		= GSLX680_FW,
233 	.fw_size	= ARRAY_SIZE(GSLX680_FW),
234 	.quirks		= GSL_QUIRK_VR,
235 	.cfg_id		= gsl_config_data_id,
236 	.max_x		= SCREEN_MAX_X,
237 	.max_y		= SCREEN_MAX_Y,
238 	.x_pol		= false,
239 	.y_pol		= false,
240 };
241 
242 static const struct gsl_ts_cfg gslx680_tve_cfg = {
243 	.fw_ptr		= GSLX680_FW_TVE,
244 	.fw_size	= ARRAY_SIZE(GSLX680_FW_TVE),
245 	.quirks		= GSL_QUIRK_TVE,
246 	.cfg_id		= gsl_tve_cfg_id,
247 	.max_x		= SCREEN_MAX_X_TVE,
248 	.max_y		= SCREEN_MAX_Y_TVE,
249 	.x_pol		= true,
250 	.y_pol		= true,
251 };
252 
gslx680_set_pinctrl_state(struct gsl_ts * ts,struct pinctrl_state * state)253 int gslx680_set_pinctrl_state(struct gsl_ts *ts, struct pinctrl_state *state)
254 {
255 	int ret = 0;
256 
257 	if (!IS_ERR(state)) {
258 		ret = pinctrl_select_state(ts->pinctrl, state);
259 		if (ret)
260 			printk("could not set pins \n");
261 	}
262 
263 	return ret;
264 }
265 
gslX680_init(struct gsl_ts * ts)266 static int gslX680_init(struct gsl_ts *ts)
267 {
268 	struct device_node *np = ts->client->dev.of_node;
269 	int err = 0;
270 	int ret = 0;
271 
272 	ts->irq = of_get_named_gpio_flags(np, "touch-gpio", 0, NULL);
273 	ts->rst = of_get_named_gpio_flags(np, "reset-gpio", 0, NULL);
274 
275 	//msleep(20);
276 #if 0	//#if defined (CONFIG_BOARD_ZM71C)||defined (CONFIG_BOARD_ZM72CP) ||
277 	defined(CONFIG_BOARD_ZM726C) || defined(CONFIG_BOARD_ZM726CE)
278 	    if (gpio_request(ts->rst, NULL) != 0) {
279 		gpio_free(ts->rst);
280 		printk("gslX680_init gpio_request error\n");
281 		return -EIO;
282 	}
283 #endif
284 
285 	/* pinctrl */
286 	ts->pinctrl = devm_pinctrl_get(&ts->client->dev);
287 	if (IS_ERR(ts->pinctrl)) {
288 		ret = PTR_ERR(ts->pinctrl);
289 		//goto out;
290 	}
291 
292 	ts->pins_default =
293 	    pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_DEFAULT);
294 	//if (IS_ERR(ts->pins_default))
295 	//      dev_err(&client->dev, "could not get default pinstate\n");
296 
297 	ts->pins_sleep = pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_SLEEP);
298 	//if (IS_ERR(ts->pins_sleep))
299 	//      dev_err(&client->dev, "could not get sleep pinstate\n");
300 
301 	ts->pins_inactive = pinctrl_lookup_state(ts->pinctrl, "inactive");
302 	//if (IS_ERR(ts->pins_inactive))
303 	//      dev_err(&client->dev, "could not get inactive pinstate\n");
304 
305 	err = gpio_request(ts->rst, "tp reset");
306 	if (err) {
307 		printk("gslx680 reset gpio request failed.\n");
308 		return -1;
309 	}
310 
311 	gslx680_set_pinctrl_state(ts, ts->pins_default);
312 	gpio_direction_output(ts->rst, 1);
313 	gpio_set_value(ts->rst, 1);
314 
315 	return 0;
316 }
317 
gslX680_shutdown_low(struct gsl_ts * ts)318 static int gslX680_shutdown_low(struct gsl_ts *ts)
319 {
320 	printk("gsl  gslX680_shutdown_low\n");
321 	gpio_direction_output(ts->rst, 0);
322 	gpio_set_value(ts->rst, 0);
323 
324 	return 0;
325 }
326 
gslX680_shutdown_high(struct gsl_ts * ts)327 static int gslX680_shutdown_high(struct gsl_ts *ts)
328 {
329 	printk("gsl  gslX680_shutdown_high\n");
330 	gpio_direction_output(ts->rst, 1);
331 	gpio_set_value(ts->rst, 1);
332 
333 	return 0;
334 }
335 
join_bytes(u8 a,u8 b)336 static inline u16 join_bytes(u8 a, u8 b)
337 {
338 	u16 ab = 0;
339 
340 	ab = ab | a;
341 	ab = ab << 8 | b;
342 
343 	return ab;
344 }
345 
346 /*
347 static u32 gsl_read_interface(struct i2c_client *client,
348 	u8 reg, u8 *buf, u32 num)
349 {
350 	struct i2c_msg xfer_msg[2];
351 
352 	xfer_msg[0].addr = client->addr;
353 	xfer_msg[0].len = 1;
354 	xfer_msg[0].flags = client->flags & I2C_M_TEN;
355 	xfer_msg[0].buf = &reg;
356 	xfer_msg[0].scl_rate=300*1000;
357 
358 	xfer_msg[1].addr = client->addr;
359 	xfer_msg[1].len = num;
360 	xfer_msg[1].flags |= I2C_M_RD;
361 	xfer_msg[1].buf = buf;
362 	xfer_msg[1].scl_rate=300*1000;
363 
364 	if (reg < 0x80) {
365 		i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
366 		msleep(5);
367 	}
368 
369 	return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) \
370 		== ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
371 }
372  */
373 
gsl_write_interface(struct i2c_client * client,const u8 reg,u8 * buf,u32 num)374 static u32 gsl_write_interface(struct i2c_client *client,
375 			       const u8 reg, u8 *buf, u32 num)
376 {
377 	struct i2c_msg xfer_msg[1];
378 
379 	buf[0] = reg;
380 
381 	xfer_msg[0].addr = client->addr;
382 	xfer_msg[0].len = num + 1;
383 	xfer_msg[0].flags = client->flags & I2C_M_TEN;
384 	xfer_msg[0].buf = buf;
385 	//xfer_msg[0].scl_rate = 100 * 1000;
386 
387 	return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
388 }
389 
gsl_ts_write(struct i2c_client * client,u8 addr,u8 * pdata,int datalen)390 static int gsl_ts_write(struct i2c_client *client,
391 			u8 addr, u8 *pdata, int datalen)
392 {
393 	int ret = 0;
394 	u8 tmp_buf[128];
395 	unsigned int bytelen = 0;
396 
397 	if (datalen > 125) {
398 		printk("%s too big datalen = %d!\n", __func__, datalen);
399 		return -1;
400 	}
401 
402 	tmp_buf[0] = addr;
403 	bytelen++;
404 
405 	if (datalen != 0 && pdata != NULL) {
406 		memcpy(&tmp_buf[bytelen], pdata, datalen);
407 		bytelen += datalen;
408 	}
409 
410 	ret = i2c_master_send(client, tmp_buf, bytelen);
411 	return ret;
412 }
413 
gsl_ts_read(struct i2c_client * client,u8 addr,u8 * pdata,unsigned int datalen)414 static int gsl_ts_read(struct i2c_client *client, u8 addr,
415 		       u8 *pdata, unsigned int datalen)
416 {
417 	int ret = 0;
418 
419 	if (datalen > 126) {
420 		printk("%s too big datalen = %d!\n", __func__, datalen);
421 		return -1;
422 	}
423 
424 	ret = gsl_ts_write(client, addr, NULL, 0);
425 	if (ret < 0) {
426 		printk("%s set data address fail!\n", __func__);
427 		return ret;
428 	}
429 
430 	return i2c_master_recv(client, pdata, datalen);
431 }
432 
fw2buf(u8 * buf,const u32 * fw)433 static __inline__ void fw2buf(u8 *buf, const u32 *fw)
434 {
435 	u32 *u32_buf = (int *)buf;
436 	*u32_buf = *fw;
437 }
438 
gsl_load_fw(struct i2c_client * client)439 static void gsl_load_fw(struct i2c_client *client)
440 {
441 	u8 buf[DMA_TRANS_LEN * 4 + 1] = { 0 };
442 	u8 send_flag = 1;
443 	u8 *cur = buf + 1;
444 	u32 source_line = 0;
445 	u32 source_len;
446 	//u8 read_buf[4] = {0};
447 	struct gsl_ts *ts =
448 		(struct gsl_ts *)i2c_get_clientdata(client);
449 	struct fw_data const *ptr_fw = ts->ts_cfg->fw_ptr;
450 
451 	source_len = ts->ts_cfg->fw_size;
452 
453 	for (source_line = 0; source_line < source_len; source_line++) {
454 		/* init page trans, set the page val */
455 		if (GSL_PAGE_REG == ptr_fw[source_line].offset) {
456 			fw2buf(cur, &ptr_fw[source_line].val);
457 			gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
458 			send_flag = 1;
459 		} else {
460 			if (1 ==
461 			    send_flag % (DMA_TRANS_LEN <
462 					 0x20 ? DMA_TRANS_LEN : 0x20))
463 				buf[0] = (u8) ptr_fw[source_line].offset;
464 
465 			fw2buf(cur, &ptr_fw[source_line].val);
466 			cur += 4;
467 
468 			if (0 ==
469 			    send_flag % (DMA_TRANS_LEN <
470 					 0x20 ? DMA_TRANS_LEN : 0x20)) {
471 				gsl_write_interface(client, buf[0], buf,
472 						    cur - buf - 1);
473 				cur = buf + 1;
474 			}
475 
476 			send_flag++;
477 		}
478 	}
479 }
480 
test_i2c(struct i2c_client * client)481 static int test_i2c(struct i2c_client *client)
482 {
483 	u8 read_buf = 0;
484 	u8 write_buf = 0x12;
485 	int ret, rc = 1;
486 
487 	ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
488 	if (ret < 0)
489 		rc--;
490 	else
491 		printk("gsl I read reg 0xf0 is %x\n", read_buf);
492 
493 	msleep(2);
494 	ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
495 	if (ret >= 0)
496 		printk("gsl I write reg 0xf0 0x12\n");
497 
498 	msleep(2);
499 	ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
500 	if (ret < 0)
501 		rc--;
502 	else
503 		printk("gsl I read reg 0xf0 is 0x%x\n", read_buf);
504 
505 	return rc;
506 }
startup_chip(struct i2c_client * client)507 static void startup_chip(struct i2c_client *client)
508 {
509 	struct gsl_ts *ts =
510 		(struct gsl_ts *)i2c_get_clientdata(client);
511 	u8 tmp = 0x00;
512 
513 	printk("gsl  startup_chip\n");
514 
515 #ifdef GSL_NOID_VERSION
516 	gsl_DataInit(ts->ts_cfg->cfg_id);
517 #endif
518 	gsl_ts_write(client, 0xe0, &tmp, 1);
519 	mdelay(10);
520 }
521 
reset_chip(struct i2c_client * client)522 static void reset_chip(struct i2c_client *client)
523 {
524 	u8 tmp = 0x88;
525 	u8 buf[4] = { 0x00 };
526 
527 	printk("gsl  reset_chip\n");
528 
529 	gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
530 	mdelay(20);
531 	tmp = 0x04;
532 	gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
533 	mdelay(10);
534 	gsl_ts_write(client, 0xbc, buf, sizeof(buf));
535 	mdelay(10);
536 }
537 
clr_reg(struct i2c_client * client)538 static void clr_reg(struct i2c_client *client)
539 {
540 	u8 write_buf[4] = { 0 };
541 
542 	write_buf[0] = 0x88;
543 	gsl_ts_write(client, 0xe0, &write_buf[0], 1);
544 	mdelay(20);
545 	write_buf[0] = 0x03;
546 	gsl_ts_write(client, 0x80, &write_buf[0], 1);
547 	mdelay(5);
548 	write_buf[0] = 0x04;
549 	gsl_ts_write(client, 0xe4, &write_buf[0], 1);
550 	mdelay(5);
551 	write_buf[0] = 0x00;
552 	gsl_ts_write(client, 0xe0, &write_buf[0], 1);
553 	mdelay(20);
554 }
555 
init_chip(struct i2c_client * client,struct gsl_ts * ts)556 static void init_chip(struct i2c_client *client, struct gsl_ts *ts)
557 {
558 	int rc;
559 
560 	printk("gsl  init_chip\n");
561 
562 	gslX680_shutdown_low(ts);
563 	mdelay(20);
564 	gslX680_shutdown_high(ts);
565 	mdelay(20);
566 	rc = test_i2c(client);
567 	if (rc < 0) {
568 		printk("gslX680 test_i2c error\n");
569 		return;
570 	}
571 	clr_reg(client);
572 	reset_chip(client);
573 	gsl_load_fw(client);
574 	startup_chip(client);
575 	reset_chip(client);
576 	startup_chip(client);
577 }
578 
check_mem_data(struct i2c_client * client,struct gsl_ts * ts)579 static void check_mem_data(struct i2c_client *client, struct gsl_ts *ts)
580 {
581 	u8 read_buf[4] = { 0 };
582 
583 	mdelay(30);
584 	gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf));
585 	if (read_buf[3] != 0x5a || read_buf[2] != 0x5a ||
586 		read_buf[1] != 0x5a || read_buf[0] != 0x5a) {
587 		init_chip(client, ts);
588 	}
589 }
590 
591 #ifdef TPD_PROC_DEBUG
char_to_int(char ch)592 static int char_to_int(char ch)
593 {
594 	if (ch >= '0' && ch <= '9')
595 		return (ch - '0');
596 	else
597 		return (ch - 'a' + 10);
598 }
599 
gsl_config_read_proc(struct seq_file * m,void * v)600 static int gsl_config_read_proc(struct seq_file *m, void *v)
601 {
602 	//char *ptr = page;
603 	char temp_data[5] = { 0 };
604 	unsigned int tmp = 0;
605 	//unsigned int *ptr_fw;
606 	struct gsl_ts *ts =
607 		(struct gsl_ts *)i2c_get_clientdata(i2c_client);
608 
609 	if ('v' == gsl_read[0] && 's' == gsl_read[1]) {
610 #ifdef GSL_NOID_VERSION
611 		tmp = gsl_version_id();
612 #else
613 		tmp = 0x20121215;
614 #endif
615 		seq_printf(m, "version:%x\n", tmp);
616 	} else if ('r' == gsl_read[0] && 'e' == gsl_read[1]) {
617 		if ('i' == gsl_read[3]) {
618 #ifdef GSL_NOID_VERSION
619 			/*      tmp=(gsl_data_proc[5]<<8) | gsl_data_proc[4];
620 			   seq_printf(m,"gsl_config_data_id[%d] = ",tmp);
621 			   if(tmp>=0&&tmp<gsl_cfg_table[gsl_cfg_index].data_size)
622 			   seq_printf(m,"%d\n",gsl_cfg_table[gsl_cfg_index].data_id[tmp]); */
623 
624 			tmp = (gsl_data_proc[5] << 8) | gsl_data_proc[4];
625 			seq_printf(m, "gsl_config_data_id[%d] = ", tmp);
626 			if (tmp >= 0 && tmp < 512)
627 				seq_printf(m, "%d\n", ts->ts_cfg->cfg_id[tmp]);
628 #endif
629 		} else {
630 			i2c_smbus_write_i2c_block_data(i2c_client, 0xf0, 4,
631 						       &gsl_data_proc[4]);
632 			if (gsl_data_proc[0] < 0x80)
633 				i2c_smbus_read_i2c_block_data(i2c_client,
634 							      gsl_data_proc[0],
635 							      4, temp_data);
636 			i2c_smbus_read_i2c_block_data(i2c_client,
637 						      gsl_data_proc[0], 4,
638 						      temp_data);
639 
640 			seq_printf(m, "offset : {0x%02x,0x", gsl_data_proc[0]);
641 			seq_printf(m, "%02x", temp_data[3]);
642 			seq_printf(m, "%02x", temp_data[2]);
643 			seq_printf(m, "%02x", temp_data[1]);
644 			seq_printf(m, "%02x};\n", temp_data[0]);
645 		}
646 	}
647 	return 0;
648 }
gsl_config_write_proc(struct file * file,const char * buffer,size_t count,loff_t * data)649 static ssize_t gsl_config_write_proc(struct file *file, const char *buffer,
650 				 size_t count, loff_t *data)
651 {
652 	u8 buf[8] = { 0 };
653 	char temp_buf[CONFIG_LEN];
654 	char *path_buf;
655 	int tmp = 0;
656 	int tmp1 = 0;
657 	struct gsl_ts *ts =
658 		(struct gsl_ts *)i2c_get_clientdata(i2c_client);
659 
660 	print_info("[tp-gsl][%s] \n", __func__);
661 	if (count > 512) {
662 		//print_info("size not match [%d:%d]\n", CONFIG_LEN, count);
663 		return -EFAULT;
664 	}
665 	path_buf = kzalloc(count, GFP_KERNEL);
666 	if (!path_buf) {
667 		printk("alloc path_buf memory error \n");
668 	}
669 	if (copy_from_user(path_buf, buffer, count)) {
670 		print_info("copy from user fail\n");
671 		goto exit_write_proc_out;
672 	}
673 	memcpy(temp_buf, path_buf, (count < CONFIG_LEN ? count : CONFIG_LEN));
674 	print_info("[tp-gsl][%s][%s]\n", __func__, temp_buf);
675 
676 	buf[3] = char_to_int(temp_buf[14]) << 4 | char_to_int(temp_buf[15]);
677 	buf[2] = char_to_int(temp_buf[16]) << 4 | char_to_int(temp_buf[17]);
678 	buf[1] = char_to_int(temp_buf[18]) << 4 | char_to_int(temp_buf[19]);
679 	buf[0] = char_to_int(temp_buf[20]) << 4 | char_to_int(temp_buf[21]);
680 
681 	buf[7] = char_to_int(temp_buf[5]) << 4 | char_to_int(temp_buf[6]);
682 	buf[6] = char_to_int(temp_buf[7]) << 4 | char_to_int(temp_buf[8]);
683 	buf[5] = char_to_int(temp_buf[9]) << 4 | char_to_int(temp_buf[10]);
684 	buf[4] = char_to_int(temp_buf[11]) << 4 | char_to_int(temp_buf[12]);
685 	if ('v' == temp_buf[0] && 's' == temp_buf[1]) {
686 		//version //vs
687 		memcpy(gsl_read, temp_buf, 4);
688 		printk("gsl version\n");
689 	} else if ('s' == temp_buf[0] && 't' == temp_buf[1]) {
690 		//start //st
691 		gsl_proc_flag = 1;
692 		reset_chip(i2c_client);
693 	} else if ('e' == temp_buf[0] && 'n' == temp_buf[1]) {
694 		//end //en
695 		mdelay(20);
696 		reset_chip(i2c_client);
697 		startup_chip(i2c_client);
698 		gsl_proc_flag = 0;
699 	} else if ('r' == temp_buf[0] && 'e' == temp_buf[1]) {
700 		//read buf //
701 		memcpy(gsl_read, temp_buf, 4);
702 		memcpy(gsl_data_proc, buf, 8);
703 	} else if ('w' == temp_buf[0] && 'r' == temp_buf[1]) {
704 		//write buf
705 		i2c_smbus_write_i2c_block_data(i2c_client, buf[4], 4, buf);
706 	}
707 #ifdef GSL_NOID_VERSION
708 	else if ('i' == temp_buf[0] && 'd' == temp_buf[1]) {
709 		//write id config //
710 		tmp1 = (buf[7] << 24) | (buf[6] << 16) | (buf[5] << 8) | buf[4];
711 		tmp = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
712 
713 		if (tmp1 >= 0 && tmp1 < 512) {
714 			ts->ts_cfg->cfg_id[tmp1] = tmp;
715 		}
716 	}
717 #endif
718 	exit_write_proc_out:
719 	kfree(path_buf);
720 	return count;
721 }
722 
gsl_server_list_open(struct inode * inode,struct file * file)723 static int gsl_server_list_open(struct inode *inode, struct file *file)
724 {
725 	return single_open(file, gsl_config_read_proc, NULL);
726 }
727 static const struct file_operations gsl_seq_fops = {
728 	.open = gsl_server_list_open,
729 	.read = seq_read,
730 	.release = single_release,
731 	.write = gsl_config_write_proc,
732 	.owner = THIS_MODULE,
733 };
734 
735 #endif
736 
737 #ifdef FILTER_POINT
filter_point(u16 x,u16 y,u8 id)738 static void filter_point(u16 x, u16 y, u8 id)
739 {
740 	u16 x_err = 0;
741 	u16 y_err = 0;
742 	u16 filter_step_x = 0, filter_step_y = 0;
743 
744 	id_sign[id] = id_sign[id] + 1;
745 	if (id_sign[id] == 1) {
746 		x_old[id] = x;
747 		y_old[id] = y;
748 	}
749 
750 	x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x);
751 	y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y);
752 
753 	if ((x_err > FILTER_MAX && y_err > FILTER_MAX / 3) ||
754 		(x_err > FILTER_MAX / 3 && y_err > FILTER_MAX)) {
755 		filter_step_x = x_err;
756 		filter_step_y = y_err;
757 	} else {
758 		if (x_err > FILTER_MAX)
759 			filter_step_x = x_err;
760 		if (y_err > FILTER_MAX)
761 			filter_step_y = y_err;
762 	}
763 
764 	if (x_err <= 2 * FILTER_MAX && y_err <= 2 * FILTER_MAX) {
765 		filter_step_x >>= 2;
766 		filter_step_y >>= 2;
767 	} else if (x_err <= 3 * FILTER_MAX && y_err <= 3 * FILTER_MAX) {
768 		filter_step_x >>= 1;
769 		filter_step_y >>= 1;
770 	} else if (x_err <= 4 * FILTER_MAX && y_err <= 4 * FILTER_MAX) {
771 		filter_step_x = filter_step_x * 3 / 4;
772 		filter_step_y = filter_step_y * 3 / 4;
773 	}
774 
775 	x_new =
776 	    x >
777 	    x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] -
778 						       filter_step_x);
779 	y_new =
780 	    y >
781 	    y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] -
782 						       filter_step_y);
783 
784 	x_old[id] = x_new;
785 	y_old[id] = y_new;
786 }
787 #else
record_point(u16 x,u16 y,u8 id)788 static void record_point(u16 x, u16 y, u8 id)
789 {
790 	u16 x_err = 0;
791 	u16 y_err = 0;
792 
793 	id_sign[id] = id_sign[id] + 1;
794 
795 	if (id_sign[id] == 1) {
796 		x_old[id] = x;
797 		y_old[id] = y;
798 	}
799 
800 	x = (x_old[id] + x) / 2;
801 	y = (y_old[id] + y) / 2;
802 
803 	if (x > x_old[id]) {
804 		x_err = x - x_old[id];
805 	} else {
806 		x_err = x_old[id] - x;
807 	}
808 
809 	if (y > y_old[id]) {
810 		y_err = y - y_old[id];
811 	} else {
812 		y_err = y_old[id] - y;
813 	}
814 
815 	if ((x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3)) {
816 		x_new = x;
817 		x_old[id] = x;
818 		y_new = y;
819 		y_old[id] = y;
820 	} else {
821 		if (x_err > 3) {
822 			x_new = x;
823 			x_old[id] = x;
824 		} else {
825 			x_new = x_old[id];
826 		}
827 
828 		if (y_err > 3) {
829 			y_new = y;
830 			y_old[id] = y;
831 		} else {
832 			y_new = y_old[id];
833 		}
834 	}
835 
836 	if (id_sign[id] == 1) {
837 		x_new = x_old[id];
838 		y_new = y_old[id];
839 	}
840 }
841 #endif
842 
843 
844 #ifdef SLEEP_CLEAR_POINT
845 #ifdef HAVE_TOUCH_KEY
report_key(struct gsl_ts * ts,u16 x,u16 y)846 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
847 {
848 	u16 i = 0;
849 
850 	for (i = 0; i < MAX_KEY_NUM; i++) {
851 		if ((gsl_key_data[i].x_min < x)
852 		    && (x < gsl_key_data[i].x_max)
853 		    && (gsl_key_data[i].y_min < y)
854 		    && (y < gsl_key_data[i].y_max)) {
855 			key = gsl_key_data[i].key;
856 			input_report_key(ts->input, key, 1);
857 			input_sync(ts->input);
858 			key_state_flag = 1;
859 			break;
860 		}
861 	}
862 }
863 #endif
864 #endif
865 
866 #ifdef RK_GEAR_TOUCH
report_data(struct gsl_ts * ts,u16 x,u16 y,u8 pressure,u8 id)867 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
868 {
869 #ifdef RK_GEAR_TOUCH
870 	int delt_x,delt_y;
871 	static int old_x=0, old_y=0;
872 #endif
873 	int max_x = ts->ts_cfg->max_x;
874 	int max_y = ts->ts_cfg->max_y;
875 
876 	//#ifndef SWAP_XY
877 	//      swap(x, y);
878 	//#endif
879 	//printk("#####id=%d,x=%d,y=%d######\n",id,x,y);
880 
881 	if (x > max_x || y > max_y) {
882 #ifdef HAVE_TOUCH_KEY
883 		//report_key(ts, x, y);
884 		//printk("#####report_key x=%d,y=%d######\n",x,y);
885 #endif
886 		return;
887 	}
888 
889 	/*
890 	   input_mt_slot(ts->input_dev, id);
891 	   input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
892 	   input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
893 	   input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
894 	   input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
895 	   input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
896 	 */
897 
898 #ifdef RK_GEAR_TOUCH
899 	if (ts->ts_cfg->quirks == GSL_QUIRK_VR) {
900 		if (g_istouch == 0) {
901 			g_istouch = 1;
902 			input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
903 			input_report_key(ts->input, 0x110, 1);
904 			input_sync(ts->input);
905 		}
906 		delt_x = (int)x - old_x;
907 		delt_y = (int)y - old_y;
908 		delt_x /= 10;
909 		delt_y /= 10;
910 		input_report_rel(ts->input, REL_Y, -delt_x);
911 		input_report_rel(ts->input, REL_X, -delt_y);
912 		input_sync(ts->input);
913 		old_x = x;
914 		old_y = y;
915 		return;
916 	}
917 #endif
918 
919 #ifdef REPORT_DATA_ANDROID_4_0
920 	//printk("#####REPORT_DATA_ANDROID_4_0######\n");
921 	input_mt_slot(ts->input, id);
922 	//input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
923 	input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 1);
924 	input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
925 	if (ts->ts_cfg->x_pol)
926 		input_report_abs(ts->input, ABS_MT_POSITION_X, max_x - x);
927 	else
928 		input_report_abs(ts->input, ABS_MT_POSITION_X, x);
929 	if (ts->ts_cfg->y_pol)
930 		input_report_abs(ts->input, ABS_MT_POSITION_Y, (max_y - y));
931 	else
932 		input_report_abs(ts->input, ABS_MT_POSITION_Y, (y));
933 	input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
934 #else
935 	//printk("#####nonono REPORT_DATA_ANDROID_4_0######\n");
936 	input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
937 	input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
938 	input_report_abs(ts->input, ABS_MT_POSITION_X, x);
939 	input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
940 	input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
941 	input_mt_sync(ts->input);
942 #endif
943 }
944 #endif
945 
glsx680_ts_irq_disable(struct gsl_ts * ts)946 void glsx680_ts_irq_disable(struct gsl_ts *ts)
947 {
948 	unsigned long irqflags;
949 
950 	spin_lock_irqsave(&ts->irq_lock, irqflags);
951 	if (!ts->flag_irq_is_disable) {
952 		disable_irq_nosync(ts->client->irq);
953 		ts->flag_irq_is_disable = 1;
954 	}
955 	spin_unlock_irqrestore(&ts->irq_lock, irqflags);
956 }
957 
glsx680_ts_irq_enable(struct gsl_ts * ts)958 void glsx680_ts_irq_enable(struct gsl_ts *ts)
959 {
960 	unsigned long irqflags = 0;
961 
962 	spin_lock_irqsave(&ts->irq_lock, irqflags);
963 	if (ts->flag_irq_is_disable) {
964 		enable_irq(ts->client->irq);
965 		ts->flag_irq_is_disable = 0;
966 	}
967 	spin_unlock_irqrestore(&ts->irq_lock, irqflags);
968 }
969 
gslX680_ts_worker(struct work_struct * work)970 static void gslX680_ts_worker(struct work_struct *work)
971 {
972 	int rc, i;
973 	u8 id, touches;
974 	u16 x, y;
975 
976 #ifdef GSL_NOID_VERSION
977 	u32 tmp1;
978 	u8 buf[4] = { 0 };
979 	struct gsl_touch_info cinfo;
980 #endif
981 
982 	struct gsl_ts *ts = container_of(work, struct gsl_ts, work);
983 
984 #ifdef TPD_PROC_DEBUG
985 	if (gsl_proc_flag == 1)
986 		goto schedule;
987 #endif
988 
989 #ifdef GSL_MONITOR
990 	if (i2c_lock_flag != 0)
991 		goto i2c_lock_schedule;
992 	else
993 		i2c_lock_flag = 1;
994 #endif
995 
996 	rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
997 	if (rc < 0) {
998 		dev_err(&ts->client->dev, "read failed\n");
999 		goto schedule;
1000 	}
1001 
1002 	touches = ts->touch_data[ts->dd->touch_index];
1003 	//print_info("-----touches: %d -----\n", touches);
1004 #ifdef GSL_NOID_VERSION
1005 
1006 	cinfo.finger_num = touches;
1007 	//print_info("tp-gsl  finger_num = %d\n",cinfo.finger_num);
1008 	for (i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i++) {
1009 		cinfo.x[i] =
1010 		    join_bytes((ts->
1011 				touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
1012 			       ts->touch_data[ts->dd->x_index + 4 * i]);
1013 		cinfo.y[i] =
1014 		    join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
1015 			       ts->touch_data[ts->dd->y_index + 4 * i]);
1016 		cinfo.id[i] =
1017 		    ((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf0) >> 4);
1018 		/*print_info("tp-gsl  before: x[%d] = %d, y[%d] = %d,
1019 		 id[%d] = %d \n",i,cinfo.x[i],i,cinfo.y[i],i,cinfo.id[i]);*/
1020 	}
1021 	cinfo.finger_num = (ts->touch_data[3] << 24) | (ts->touch_data[2] << 16)
1022 	    | (ts->touch_data[1] << 8) | (ts->touch_data[0]);
1023 	gsl_alg_id_main(&cinfo);
1024 	tmp1 = gsl_mask_tiaoping();
1025 	//print_info("[tp-gsl] tmp1 = %x\n", tmp1);
1026 	if (tmp1 > 0 && tmp1 < 0xffffffff) {
1027 		buf[0] = 0xa;
1028 		buf[1] = 0;
1029 		buf[2] = 0;
1030 		buf[3] = 0;
1031 		gsl_ts_write(ts->client, 0xf0, buf, 4);
1032 		buf[0] = (u8) (tmp1 & 0xff);
1033 		buf[1] = (u8) ((tmp1 >> 8) & 0xff);
1034 		buf[2] = (u8) ((tmp1 >> 16) & 0xff);
1035 		buf[3] = (u8) ((tmp1 >> 24) & 0xff);
1036 		print_info("tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x, \
1037 			buf[3]=%02x\n", tmp1, buf[0], buf[1], buf[2], buf[3]);
1038 		gsl_ts_write(ts->client, 0x8, buf, 4);
1039 	}
1040 	touches = cinfo.finger_num;
1041 #endif
1042 
1043 	for (i = 1; i <= MAX_CONTACTS; i++) {
1044 		if (touches == 0)
1045 			id_sign[i] = 0;
1046 		id_state_flag[i] = 0;
1047 	}
1048 	for (i = 0; i < (touches > MAX_FINGERS ? MAX_FINGERS : touches); i++) {
1049 #ifdef GSL_NOID_VERSION
1050 		id = cinfo.id[i];
1051 		x = cinfo.x[i];
1052 		y = cinfo.y[i];
1053 #else
1054 		x = join_bytes((ts->
1055 				touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
1056 			       ts->touch_data[ts->dd->x_index + 4 * i]);
1057 		y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
1058 			       ts->touch_data[ts->dd->y_index + 4 * i]);
1059 		id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
1060 #endif
1061 
1062 		if (1 <= id && id <= MAX_CONTACTS) {
1063 #ifdef FILTER_POINT
1064 			filter_point(x, y, id);
1065 #else
1066 			record_point(x, y, id);
1067 #endif
1068 #ifdef RK_GEAR_TOUCH
1069 			report_data(ts, x_new, y_new, 10, id);
1070 #endif
1071 			if (key_count < 512) {
1072 				key_x[key_count] = x_new;
1073 				key_y[key_count] = y_new;
1074 				key_count++;
1075 				/*printk("test in key store in here,
1076 				x_new is %d , y_new is %d ,
1077 				key_count is %d \n", x_new ,y_new,key_count);*/
1078 			}
1079 			id_state_flag[id] = 1;
1080 		}
1081 	}
1082 	for (i = 1; i <= MAX_CONTACTS; i++) {
1083 		if ((0 == touches)
1084 		    || ((0 != id_state_old_flag[i])
1085 			&& (0 == id_state_flag[i]))) {
1086 #ifdef RK_GEAR_TOUCH
1087 			if (g_istouch == 1){
1088 				g_istouch = 0;
1089 				input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
1090 				input_report_key(ts->input, 0x110, 0);
1091 				input_sync(ts->input);
1092 			}
1093 			g_istouch = 0;
1094 #endif
1095 #ifdef REPORT_DATA_ANDROID_4_0
1096 			input_mt_slot(ts->input, i);
1097 			//input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1098 			input_mt_report_slot_state(ts->input, MT_TOOL_FINGER,
1099 						   false);
1100 #endif
1101 			id_sign[i] = 0;
1102 		}
1103 		id_state_old_flag[i] = id_state_flag[i];
1104 	}
1105 
1106 	if (0 == touches) {
1107 #ifdef REPORT_DATA_ANDROID_4_0
1108 #ifndef RK_GEAR_TOUCH
1109 		//input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, 0);
1110 		//input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 0);
1111 		//input_mt_sync(ts->input);
1112 
1113 		int temp_x = 0;
1114 		int temp_y = 0;
1115 		temp_x =
1116 		    (((key_x[key_count - 1] - key_x[0]) >
1117 		      0) ? (key_x[key_count - 1] - key_x[0])
1118 		     : (key_x[0] - key_x[key_count - 1]));
1119 		temp_y =
1120 		    (((key_y[key_count - 1] - key_y[0]) >
1121 		      0) ? (key_y[key_count - 1] - key_y[0])
1122 		     : (key_y[0] - key_y[key_count - 1]));
1123 		if (key_count <= 512) {
1124 			if (temp_x > temp_y) {
1125 				if ((key_x[key_count - 1] - key_x[0]) > 100) {
1126 					printk(" send up key \n");
1127 					input_report_key(ts->input,
1128 							 key_array[2], 1);
1129 					input_sync(ts->input);
1130 					input_report_key(ts->input,
1131 							 key_array[2], 0);
1132 					input_sync(ts->input);
1133 				} else if ((key_x[0] - key_x[key_count - 1]) >
1134 					   100) {
1135 					printk(" send down key \n");
1136 					input_report_key(ts->input,
1137 							 key_array[3], 1);
1138 					input_sync(ts->input);
1139 					input_report_key(ts->input,
1140 							 key_array[3], 0);
1141 					input_sync(ts->input);
1142 				}
1143 			} else if (temp_x <= temp_y) {
1144 				if ((key_y[key_count - 1] - key_y[0]) > 100) {
1145 					printk(" send left key \n");
1146 					input_report_key(ts->input,
1147 							 key_array[0], 1);
1148 					input_sync(ts->input);
1149 					input_report_key(ts->input,
1150 							 key_array[0], 0);
1151 					input_sync(ts->input);
1152 				} else if ((key_y[0] - key_y[key_count - 1]) >
1153 					   100) {
1154 					printk(" send right key \n");
1155 					input_report_key(ts->input,
1156 							 key_array[1], 1);
1157 					input_sync(ts->input);
1158 					input_report_key(ts->input,
1159 							 key_array[1], 0);
1160 					input_sync(ts->input);
1161 				}
1162 			}
1163 			/*printk(" key_x[key_count -1],  key_x[0],
1164 			key_y[key_count -1], key_y[0] is %d ,%d , %d , %d\n",
1165 			key_x[key_count -1], key_x[0], key_y[key_count -1],
1166 			key_y[0]);*/
1167 			if ((key_x[key_count - 1] - key_x[0] < 50)
1168 			    && (key_x[key_count - 1] - key_x[0] >= -50)
1169 			    && (key_y[key_count - 1] - key_y[0] < 50)
1170 			    && (key_y[key_count - 1] - key_y[0] >= -50)
1171 			    && (key_x[0] != 0) && (key_y[0] != 0)) {
1172 				//queue_work(gsl_timer_workqueue,&ts->click_work);
1173 				//printk(" send enter2 key by yuandan \n");
1174 				//if(send_key)
1175 				//      {
1176 				printk(" send enter key \n");
1177 				input_report_key(ts->input, key_array[4], 1);
1178 				input_sync(ts->input);
1179 				input_report_key(ts->input, key_array[4], 0);
1180 				input_sync(ts->input);
1181 				//      }else
1182 				//              {
1183 				//down(&my_sem);
1184 				//                      send_key = true;
1185 				//up(&my_sem);
1186 				//              }
1187 			}
1188 		} else if (key_count > 512) {
1189 			if (temp_x > temp_y) {
1190 				if ((key_x[511] - key_x[0]) > 100) {
1191 					printk(" send up key \n");
1192 					input_report_key(ts->input,
1193 							 key_array[2], 1);
1194 					input_sync(ts->input);
1195 					input_report_key(ts->input,
1196 							 key_array[2], 0);
1197 					input_sync(ts->input);
1198 				} else if ((key_x[0] - key_x[511]) > 100) {
1199 					printk(" send down key \n");
1200 					input_report_key(ts->input,
1201 							 key_array[3], 1);
1202 					input_sync(ts->input);
1203 					input_report_key(ts->input,
1204 							 key_array[3], 0);
1205 					input_sync(ts->input);
1206 				}
1207 			} else if (temp_x <= temp_y) {
1208 
1209 				if ((key_y[511] - key_y[0]) > 100) {
1210 					printk(" send left key \n");
1211 					input_report_key(ts->input,
1212 							 key_array[0], 1);
1213 					input_sync(ts->input);
1214 					input_report_key(ts->input,
1215 							 key_array[0], 0);
1216 					input_sync(ts->input);
1217 				} else if ((key_y[0] - key_y[511]) > 100) {
1218 					printk(" send right key \n");
1219 					input_report_key(ts->input,
1220 							 key_array[1], 1);
1221 					input_sync(ts->input);
1222 					input_report_key(ts->input,
1223 							 key_array[1], 0);
1224 					input_sync(ts->input);
1225 				}
1226 			}
1227 		}
1228 		memset(key_y, 0, sizeof(int) * 512);
1229 		memset(key_x, 0, sizeof(int) * 512);
1230 		key_count = 0;
1231 #endif
1232 #endif
1233 #ifdef HAVE_TOUCH_KEY
1234 		if (key_state_flag) {
1235 			input_report_key(ts->input, key, 0);
1236 			input_sync(ts->input);
1237 			key_state_flag = 0;
1238 		}
1239 #endif
1240 
1241 	}
1242 
1243 	input_sync(ts->input);
1244 
1245       schedule:
1246 #ifdef GSL_MONITOR
1247 	i2c_lock_flag = 0;
1248       i2c_lock_schedule:
1249 #endif
1250 	glsx680_ts_irq_enable(ts);
1251 
1252 }
1253 
1254 #ifdef HAVE_CLICK_TIMER
1255 
click_timer_worker(struct work_struct * work)1256 static void click_timer_worker(struct work_struct *work)
1257 {
1258 	while (true) {
1259 		mdelay(500);
1260 		//down(&my_sem);
1261 		send_key = false;
1262 		//up(&my_sem);
1263 	}
1264 }
1265 
1266 #endif
1267 
1268 #ifdef GSL_MONITOR
gsl_monitor_worker(struct work_struct * work)1269 static void gsl_monitor_worker(struct work_struct *work)
1270 {
1271 	//u8 write_buf[4] = {0};
1272 	u8 read_buf[4] = { 0 };
1273 	char init_chip_flag = 0;
1274 
1275 	//print_info("gsl_monitor_worker\n");
1276 	struct gsl_ts *ts =
1277 	    container_of(work, struct gsl_ts, gsl_monitor_work.work);
1278 	if (i2c_lock_flag != 0) {
1279 		i2c_lock_flag = 1;
1280 	}
1281 	//goto queue_monitor_work;
1282 	else
1283 		i2c_lock_flag = 1;
1284 
1285 	//gsl_ts_read(ts->client, 0x80, read_buf, 4);
1286 	/*printk("======read 0x80: %x %x %x %x ======tony0geshu\n",
1287 	read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1288 
1289 	gsl_ts_read(ts->client, 0xb0, read_buf, 4);
1290 	if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a
1291 	    || read_buf[0] != 0x5a)
1292 		b0_counter++;
1293 	else
1294 		b0_counter = 0;
1295 
1296 	if (b0_counter > 1) {
1297 		/*printk("======read 0xb0: %x %x %x %x ======\n",
1298 		read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1299 		init_chip_flag = 1;
1300 		b0_counter = 0;
1301 	}
1302 
1303 	gsl_ts_read(ts->client, 0xb4, read_buf, 4);
1304 	int_2nd[3] = int_1st[3];
1305 	int_2nd[2] = int_1st[2];
1306 	int_2nd[1] = int_1st[1];
1307 	int_2nd[0] = int_1st[0];
1308 	int_1st[3] = read_buf[3];
1309 	int_1st[2] = read_buf[2];
1310 	int_1st[1] = read_buf[1];
1311 	int_1st[0] = read_buf[0];
1312 
1313 	/*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1314 	int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1315 	int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1316 
1317 	if (int_1st[3] == int_2nd[3] && int_1st[2] == int_2nd[2]
1318 	    && int_1st[1] == int_2nd[1] && int_1st[0] == int_2nd[0]) {
1319 		/*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1320 		int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1321 		int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1322 		init_chip_flag = 1;
1323 		//goto queue_monitor_init_chip;
1324 	}
1325 
1326 	gsl_ts_read(ts->client, 0xbc, read_buf, 4);
1327 	if (read_buf[3] != 0 || read_buf[2] != 0 || read_buf[1] != 0
1328 	    || read_buf[0] != 0)
1329 		bc_counter++;
1330 	else
1331 		bc_counter = 0;
1332 	if (bc_counter > 1) {
1333 		/*printk("======read 0xbc: %x %x %x %x======\n",
1334 		read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1335 		init_chip_flag = 1;
1336 		bc_counter = 0;
1337 	}
1338 
1339 	/*
1340 	   write_buf[3] = 0x01;
1341 	   write_buf[2] = 0xfe;
1342 	   write_buf[1] = 0x10;
1343 	   write_buf[0] = 0x00;
1344 	   gsl_ts_write(ts->client, 0xf0, write_buf, 4);
1345 	   gsl_ts_read(ts->client, 0x10, read_buf, 4);
1346 	   gsl_ts_read(ts->client, 0x10, read_buf, 4);
1347 
1348 	   if(read_buf[3] < 10
1349 	   	&& read_buf[2] < 10
1350 		&& read_buf[1] < 10
1351 		&& read_buf[0] < 10)
1352 	   dac_counter ++;
1353 	   else
1354 	   dac_counter = 0;
1355 
1356 	   if(dac_counter > 1)
1357 	   {
1358 	   printk("read DAC1_0: %x %x %x %x\n",
1359 	   	read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
1360 	   init_chip_flag = 1;
1361 	   dac_counter = 0;
1362 	   }
1363 	 */
1364 	//queue_monitor_init_chip:
1365 	if (init_chip_flag)
1366 		init_chip(ts->client, ts);
1367 
1368 	i2c_lock_flag = 0;
1369 
1370 	//queue_monitor_work:
1371 	//queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 100);
1372 }
1373 #endif
1374 
gsl_ts_irq(int irq,void * dev_id)1375 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
1376 {
1377 	///struct gsl_ts *ts = dev_id;
1378 	struct gsl_ts *ts = (struct gsl_ts *)dev_id;
1379 	//print_info("========gslX680 Interrupt=========\n");
1380 
1381 	glsx680_ts_irq_disable(ts);
1382 
1383 	if (!work_pending(&ts->work)) {
1384 		queue_work(ts->wq, &ts->work);
1385 	}
1386 
1387 	return IRQ_HANDLED;
1388 
1389 }
1390 
gslX680_ts_init(struct i2c_client * client,struct gsl_ts * ts)1391 static int gslX680_ts_init(struct i2c_client *client, struct gsl_ts *ts)
1392 {
1393 	struct input_dev *input_device;
1394 	int rc = 0;
1395 	int i = 0;
1396 	int max_x = ts->ts_cfg->max_x;
1397 	int max_y = ts->ts_cfg->max_y;
1398 
1399 	printk("[GSLX680] Enter %s\n", __func__);
1400 
1401 	ts->dd = &devices[ts->device_id];
1402 
1403 	if (ts->device_id == 0) {
1404 		ts->dd->data_size =
1405 		    MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
1406 		ts->dd->touch_index = 0;
1407 	}
1408 
1409 	ts->touch_data =
1410 	    devm_kzalloc(&client->dev, ts->dd->data_size, GFP_KERNEL);
1411 	if (!ts->touch_data) {
1412 		pr_err("%s: Unable to allocate memory\n", __func__);
1413 		return -ENOMEM;
1414 	}
1415 
1416 	input_device = devm_input_allocate_device(&ts->client->dev);
1417 	if (!input_device) {
1418 		rc = -ENOMEM;
1419 		goto init_err_ret;
1420 	}
1421 
1422 	ts->input = input_device;
1423 	input_device->name = GSLX680_I2C_NAME;
1424 	input_device->id.bustype = BUS_I2C;
1425 	input_device->dev.parent = &client->dev;
1426 	input_set_drvdata(input_device, ts);
1427 
1428 #ifdef REPORT_DATA_ANDROID_4_0
1429 	__set_bit(EV_ABS, input_device->evbit);
1430 	__set_bit(EV_KEY, input_device->evbit);
1431 	__set_bit(EV_REP, input_device->evbit);
1432 	__set_bit(EV_SYN, input_device->evbit);
1433 	__set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1434 	__set_bit(MT_TOOL_FINGER, input_device->keybit);
1435 	input_mt_init_slots(input_device, (MAX_CONTACTS + 1), 0);
1436 #else
1437 	input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0,
1438 			     (MAX_CONTACTS + 1), 0, 0);
1439 	set_bit(EV_ABS, input_device->evbit);
1440 	set_bit(EV_KEY, input_device->evbit);
1441 	__set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1442 	input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1443 #endif
1444 
1445 #ifdef HAVE_TOUCH_KEY
1446 	input_device->evbit[0] = BIT_MASK(EV_KEY);
1447 	/*input_device->evbit[0] = BIT_MASK(EV_SYN)
1448 		| BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);*/
1449 	for (i = 0; i < MAX_KEY_NUM; i++)
1450 		set_bit(key_array[i], input_device->keybit);
1451 #endif
1452 
1453 #ifdef RK_GEAR_TOUCH
1454 	set_bit(EV_REL, input_device->evbit);
1455 	input_set_capability(input_device, EV_REL, REL_X);
1456 	input_set_capability(input_device, EV_REL, REL_Y);
1457 	input_set_capability(input_device, EV_MSC, MSC_SCAN);
1458 	input_set_capability(input_device, EV_KEY, 0x110);
1459 #endif
1460 
1461 	set_bit(ABS_MT_POSITION_X, input_device->absbit);
1462 	set_bit(ABS_MT_POSITION_Y, input_device->absbit);
1463 	set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
1464 	set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
1465 
1466 	input_set_abs_params(input_device, ABS_MT_POSITION_X, 0, max_x,
1467 			     0, 0);
1468 	input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0, max_y,
1469 			     0, 0);
1470 	input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0,
1471 			     0);
1472 	input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
1473 
1474 	//client->irq = IRQ_PORT;
1475 	//ts->irq = client->irq;
1476 
1477 	ts->wq = create_singlethread_workqueue("kworkqueue_ts");
1478 	if (!ts->wq) {
1479 		dev_err(&client->dev, "gsl Could not create workqueue\n");
1480 		goto init_err_ret;
1481 	}
1482 	flush_workqueue(ts->wq);
1483 
1484 	INIT_WORK(&ts->work, gslX680_ts_worker);
1485 
1486 	rc = input_register_device(input_device);
1487 	if (rc)
1488 		goto error_unreg_device;
1489 
1490 	return 0;
1491 
1492       error_unreg_device:
1493 	destroy_workqueue(ts->wq);
1494       init_err_ret:
1495 	return rc;
1496 }
1497 
1498 #if 0
1499 static int gsl_ts_suspend(struct i2c_client *dev, pm_message_t mesg)
1500 {
1501 #if 0
1502 	struct gsl_ts *ts = dev_get_drvdata(dev);
1503 
1504 	printk("I'am in gsl_ts_suspend() start\n");
1505 
1506 #ifdef GSL_MONITOR
1507 	printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1508 	cancel_delayed_work_sync(&ts->gsl_monitor_work);
1509 #endif
1510 
1511 #ifdef HAVE_CLICK_TIMER
1512 	//cancel_work_sync(&ts->click_work);
1513 #endif
1514 	disable_irq_nosync(ts->irq);
1515 
1516 	gslX680_shutdown_low(ts);
1517 
1518 #ifdef SLEEP_CLEAR_POINT
1519 	mdelay(10);
1520 #ifdef REPORT_DATA_ANDROID_4_0
1521 	for (i = 1; i <= MAX_CONTACTS; i++) {
1522 		input_mt_slot(ts->input, i);
1523 		input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1524 		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1525 	}
1526 #else
1527 	input_mt_sync(ts->input);
1528 #endif
1529 	input_sync(ts->input);
1530 	mdelay(10);
1531 	report_data(ts, 1, 1, 10, 1);
1532 	input_sync(ts->input);
1533 #endif
1534 
1535 #endif
1536 	return 0;
1537 }
1538 #endif
1539 
1540 #if 0
1541 static int gsl_ts_resume(struct i2c_client *dev)
1542 {
1543 #if 0
1544 	struct gsl_ts *ts = dev_get_drvdata(dev);
1545 
1546 	printk("I'am in gsl_ts_resume() start\n");
1547 
1548 	gslX680_shutdown_high(ts);
1549 	msleep(20);
1550 	reset_chip(ts->client);
1551 	startup_chip(ts->client);
1552 	check_mem_data(ts->client, ts);
1553 
1554 #ifdef SLEEP_CLEAR_POINT
1555 #ifdef REPORT_DATA_ANDROID_4_0
1556 	for (i = 1; i <= MAX_CONTACTS; i++) {
1557 		input_mt_slot(ts->input, i);
1558 		input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1559 		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1560 	}
1561 #else
1562 	input_mt_sync(ts->input);
1563 #endif
1564 	input_sync(ts->input);
1565 #endif
1566 #ifdef GSL_MONITOR
1567 	printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1568 	queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1569 #endif
1570 
1571 #ifdef HAVE_CLICK_TIMER
1572 	//queue_work(gsl_timer_workqueue,&ts->click_work);
1573 #endif
1574 
1575 	disable_irq_nosync(ts->irq);
1576 	enable_irq(ts->irq);
1577 #endif
1578 
1579 	return 0;
1580 }
1581 #endif
1582 
gsl_ts_early_suspend(struct tp_device * tp_d)1583 static int gsl_ts_early_suspend(struct tp_device *tp_d)
1584 {
1585 	struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1586 	printk("[GSLX680] Enter %s\n", __func__);
1587 	//gsl_ts_suspend(&ts->client->dev);
1588 #ifdef GSL_MONITOR
1589 	printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1590 	cancel_delayed_work_sync(&ts->gsl_monitor_work);
1591 #endif
1592 
1593 	glsx680_ts_irq_disable(ts);
1594 	cancel_work_sync(&ts->work);
1595 
1596 #ifdef SLEEP_CLEAR_POINT
1597 	msleep(10);
1598 #ifdef REPORT_DATA_ANDROID_4_0
1599 	for (i = 1; i <= MAX_CONTACTS; i++) {
1600 		input_mt_slot(ts->input, i);
1601 		input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1602 		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1603 	}
1604 #else
1605 	input_mt_sync(ts->input);
1606 #endif
1607 	input_sync(ts->input);
1608 	msleep(10);
1609 	report_data(ts, 1, 1, 10, 1);
1610 	input_sync(ts->input);
1611 #endif
1612 	gslX680_shutdown_low(ts);
1613 	return 0;
1614 }
1615 
gsl_ts_late_resume(struct tp_device * tp_d)1616 static int gsl_ts_late_resume(struct tp_device *tp_d)
1617 {
1618 	struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1619 	printk("[GSLX680] Enter %s\n", __func__);
1620 	//gsl_ts_resume(&ts->client->dev);
1621 
1622 	printk("I'am in gsl_ts_resume() start\n");
1623 
1624 	gslX680_shutdown_high(ts);
1625 	msleep(20);
1626 	reset_chip(ts->client);
1627 	startup_chip(ts->client);
1628 	check_mem_data(ts->client, ts);
1629 
1630 #ifdef SLEEP_CLEAR_POINT
1631 #ifdef REPORT_DATA_ANDROID_4_0
1632 	for (i = 1; i <= MAX_CONTACTS; i++) {
1633 		input_mt_slot(ts->input, i);
1634 		input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1635 		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1636 	}
1637 #else
1638 	input_mt_sync(ts->input);
1639 #endif
1640 	input_sync(ts->input);
1641 #endif
1642 #ifdef GSL_MONITOR
1643 	printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1644 	queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1645 #endif
1646 	glsx680_ts_irq_enable(ts);
1647 
1648 	return 0;
1649 }
1650 
1651 #ifdef CONFIG_HAS_EARLYSUSPEND
1652 
gsl_ts_early_suspend(struct early_suspend * h)1653 static void gsl_ts_early_suspend(struct early_suspend *h)
1654 {
1655 	struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1656 	printk("[GSLX680] Enter %s\n", __func__);
1657 	//gsl_ts_suspend(&ts->client->dev);
1658 #ifdef GSL_MONITOR
1659 	printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1660 	cancel_delayed_work_sync(&ts->gsl_monitor_work);
1661 #endif
1662 
1663 	glsx680_ts_irq_disable(ts);
1664 	cancel_work_sync(&ts->work);
1665 
1666 #ifdef SLEEP_CLEAR_POINT
1667 	msleep(10);
1668 #ifdef REPORT_DATA_ANDROID_4_0
1669 	for (i = 1; i <= MAX_CONTACTS; i++) {
1670 		input_mt_slot(ts->input, i);
1671 		input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1672 		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1673 	}
1674 #else
1675 	input_mt_sync(ts->input);
1676 #endif
1677 	input_sync(ts->input);
1678 	msleep(10);
1679 	report_data(ts, 1, 1, 10, 1);
1680 	input_sync(ts->input);
1681 #endif
1682 	gslX680_shutdown_low(ts);
1683 	return 0;
1684 }
1685 
gsl_ts_late_resume(struct early_suspend * h)1686 static void gsl_ts_late_resume(struct early_suspend *h)
1687 {
1688 	struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1689 	printk("[GSLX680] Enter %s\n", __func__);
1690 	//gsl_ts_resume(&ts->client->dev);
1691 	int i;
1692 
1693 	printk("I'am in gsl_ts_resume() start\n");
1694 
1695 	gslX680_shutdown_high(ts);
1696 	msleep(20);
1697 	reset_chip(ts->client);
1698 	startup_chip(ts->client);
1699 	check_mem_data(ts->client, ts);
1700 
1701 #ifdef SLEEP_CLEAR_POINT
1702 #ifdef REPORT_DATA_ANDROID_4_0
1703 	for (i = 1; i <= MAX_CONTACTS; i++) {
1704 		input_mt_slot(ts->input, i);
1705 		input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1706 		input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1707 	}
1708 #else
1709 	input_mt_sync(ts->input);
1710 #endif
1711 	input_sync(ts->input);
1712 #endif
1713 #ifdef GSL_MONITOR
1714 	printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1715 	queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1716 #endif
1717 	glsx680_ts_irq_enable(ts);
1718 
1719 }
1720 #endif
1721 
1722 //static struct wake_lock touch_wakelock;
1723 
1724 static const struct of_device_id gsl_ts_ids[] = {
1725 	{ .compatible = "gslX680", .data = &gslx680_vr_cfg },
1726 	{ .compatible = "gslX680_tve", .data = &gslx680_tve_cfg },
1727 	{}
1728 };
1729 
gsl_ts_probe(struct i2c_client * client,const struct i2c_device_id * id)1730 static int gsl_ts_probe(struct i2c_client *client,
1731 			const struct i2c_device_id *id)
1732 {
1733 	const struct of_device_id *match;
1734 	struct gsl_ts *ts;
1735 	int rc;
1736 
1737 	printk("GSLX680 Enter %s\n", __func__);
1738 	//wake_lock_init(&touch_wakelock, WAKE_LOCK_SUSPEND, "touch");
1739 	//wake_lock(&touch_wakelock); //system do not enter deep sleep
1740 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1741 		dev_err(&client->dev, "gsl I2C functionality not supported\n");
1742 		return -ENODEV;
1743 	}
1744 
1745 	ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
1746 	if (!ts)
1747 		return -ENOMEM;
1748 
1749 	match = of_match_device(of_match_ptr(gsl_ts_ids), &client->dev);
1750 	if (!match)
1751 		return -EINVAL;
1752 
1753 	ts->ts_cfg  = (const struct gsl_ts_cfg *)match->data;
1754 
1755 	ts->tp.tp_suspend = gsl_ts_early_suspend;
1756 	ts->tp.tp_resume = gsl_ts_late_resume;
1757 	tp_register_fb(&ts->tp);
1758 
1759 	ts->client = client;
1760 	i2c_set_clientdata(client, ts);
1761 	//ts->device_id = id->driver_data;
1762 
1763 	gslX680_init(ts);
1764 	rc = gslX680_ts_init(client, ts);
1765 	if (rc < 0) {
1766 		dev_err(&client->dev, "gsl GSLX680 init failed\n");
1767 		goto porbe_err_ret;
1768 	}
1769 	//#ifdef GSLX680_COMPATIBLE
1770 	//      judge_chip_type(client);
1771 	//#endif
1772 	//printk("#####################  probe [2]chip_type=%c .\n",chip_type);
1773 	init_chip(ts->client, ts);
1774 	check_mem_data(ts->client, ts);
1775 	spin_lock_init(&ts->irq_lock);
1776 	client->irq = gpio_to_irq(ts->irq);
1777 	rc = request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING,
1778 			 client->name, ts);
1779 	if (rc < 0) {
1780 		printk("gsl_probe: request irq failed\n");
1781 		goto porbe_err_ret;
1782 	}
1783 
1784 	/* create debug attribute */
1785 	//rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable);
1786 
1787 #ifdef CONFIG_HAS_EARLYSUSPEND
1788 
1789 	ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1790 	//ts->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1;
1791 	ts->early_suspend.suspend = gsl_ts_early_suspend;
1792 	ts->early_suspend.resume = gsl_ts_late_resume;
1793 	register_early_suspend(&ts->early_suspend);
1794 #endif
1795 
1796 #ifdef GSL_MONITOR
1797 
1798 	INIT_DELAYED_WORK(&ts->gsl_monitor_work, gsl_monitor_worker);
1799 	gsl_monitor_workqueue =
1800 	    create_singlethread_workqueue("gsl_monitor_workqueue");
1801 	queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 1000);
1802 #endif
1803 
1804 #ifdef HAVE_CLICK_TIMER
1805 	sema_init(&my_sem, 1);
1806 	INIT_WORK(&ts->click_work, click_timer_worker);
1807 	gsl_timer_workqueue = create_singlethread_workqueue("click_timer");
1808 	queue_work(gsl_timer_workqueue, &ts->click_work);
1809 #endif
1810 
1811 #ifdef TPD_PROC_DEBUG
1812 #if 0
1813 	gsl_config_proc = create_proc_entry(GSL_CONFIG_PROC_FILE, 0666, NULL);
1814 	printk("[tp-gsl] [%s] gsl_config_proc = %x \n", __func__,
1815 	       gsl_config_proc);
1816 	if (gsl_config_proc == NULL) {
1817 		print_info("create_proc_entry %s failed\n",
1818 			   GSL_CONFIG_PROC_FILE);
1819 	} else {
1820 		gsl_config_proc->read_proc = gsl_config_read_proc;
1821 		gsl_config_proc->write_proc = gsl_config_write_proc;
1822 	}
1823 #else
1824 	i2c_client = client;
1825 	proc_create(GSL_CONFIG_PROC_FILE, 0666, NULL, &gsl_seq_fops);
1826 #endif
1827 	gsl_proc_flag = 0;
1828 #endif
1829 	//disable_irq_nosync(->irq);
1830 	printk("[GSLX680] End %s\n", __func__);
1831 
1832 	return 0;
1833 
1834       porbe_err_ret:
1835 	return rc;
1836 }
1837 
gsl_ts_remove(struct i2c_client * client)1838 static int gsl_ts_remove(struct i2c_client *client)
1839 {
1840 	struct gsl_ts *ts = i2c_get_clientdata(client);
1841 
1842 #ifdef CONFIG_HAS_EARLYSUSPEND
1843 	unregister_early_suspend(&ts->early_suspend);
1844 #endif
1845 
1846 #ifdef GSL_MONITOR
1847 	cancel_delayed_work_sync(&ts->gsl_monitor_work);
1848 	destroy_workqueue(gsl_monitor_workqueue);
1849 #endif
1850 
1851 #ifdef HAVE_CLICK_TIMER
1852 	cancel_work_sync(&ts->click_work);
1853 	destroy_workqueue(gsl_timer_workqueue);
1854 #endif
1855 
1856 	device_init_wakeup(&client->dev, 0);
1857 	cancel_work_sync(&ts->work);
1858 	free_irq(ts->client->irq, ts);
1859 	destroy_workqueue(ts->wq);
1860 	//device_remove_file(&ts->input->dev, &dev_attr_debug_enable);
1861 
1862 	return 0;
1863 }
1864 
1865 static const struct i2c_device_id gsl_ts_id[] = {
1866 	{GSLX680_I2C_NAME, 0},
1867 	{}
1868 };
1869 
1870 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1871 
1872 static struct i2c_driver gsl_ts_driver = {
1873 	.driver = {
1874 		   .name = GSLX680_I2C_NAME,
1875 		   .owner = THIS_MODULE,
1876 		   .of_match_table = of_match_ptr(gsl_ts_ids),
1877 		   },
1878 #if 0 //ndef CONFIG_HAS_EARLYSUSPEND
1879 	.suspend = gsl_ts_suspend,
1880 	.resume = gsl_ts_resume,
1881 #endif
1882 	.probe = gsl_ts_probe,
1883 	.remove = gsl_ts_remove,
1884 	.id_table = gsl_ts_id,
1885 };
1886 
gsl_ts_init(void)1887 static int __init gsl_ts_init(void)
1888 {
1889 	int ret;
1890 	ret = i2c_add_driver(&gsl_ts_driver);
1891 	return ret;
1892 }
gsl_ts_exit(void)1893 static void __exit gsl_ts_exit(void)
1894 {
1895 	i2c_del_driver(&gsl_ts_driver);
1896 	return;
1897 }
1898 
1899 module_init(gsl_ts_init);
1900 module_exit(gsl_ts_exit);
1901 
1902 MODULE_LICENSE("GPL");
1903 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1904 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1905 MODULE_ALIAS("platform:gsl_ts");
1906