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