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