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