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