2 * drivers/input/touchscreen/gsl3673.c
4 * Copyright (c) 2012 Shanghai Basewin
5 * Guan Yuwei<guanyuwei@basewin.com>
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.
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>
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>
28 #include "tp_suspend.h"
29 #include <linux/of_gpio.h>
32 #define TP2680A_ID 0x88
33 #define TP2680B_ID 0x82
34 #ifdef GSLX680_COMPATIBLE
35 static char chip_type;
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
44 #if defined(CONFIG_TP_3680_YTG_G10077_F1)
45 #include "gsl3680b_hw1088.h"
46 #define TP_SIZE_2560X1600
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
55 #if defined(CONFIG_BOARD_TYPE_TAB8010_8d)
58 #elif defined(CONFIG_TP_3680_TAB106)
59 #include "gsl3680_tab106.h"
60 #define TP_SIZE_1366X768
62 #elif defined(CONFIG_TOUCHSCREEN_GSL3673)
65 #include "gsl3680b_zm97f.h"
66 #define HAVE_TOUCH_KEY
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
88 #define SCREEN_MAX_X 2048
89 #define SCREEN_MAX_Y 1536
91 #define REPORT_DATA_ANDROID_4_0
92 #define SLEEP_CLEAR_POINT
98 #define GSL3673_I2C_NAME "gsl3673"
99 #define GSL3673_I2C_ADDR 0x40
101 #define GSL_DATA_REG 0x80
102 #define GSL_STATUS_REG 0xe0
103 #define GSL_PAGE_REG 0xf0
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;
115 #define PRESS_MAX 255
116 #define MAX_FINGERS 10
117 #define MAX_CONTACTS 10
118 #define DMA_TRANS_LEN 0x20
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;
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
135 #ifdef HAVE_TOUCH_KEY
137 static int key_state_flag;
146 const u16 key_array[] = {
153 #define MAX_KEY_NUM ARRAY_SIZE(key_array)
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},
178 static struct gsl_ts_data devices[] = {
184 .data_reg = GSL_DATA_REG,
185 .status_reg = GSL_STATUS_REG,
188 .touch_meta_data = 4,
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;
207 #define print_info(fmt, args...) \
209 printk(fmt, ##args); \
212 #define print_info(fmt, args...)
215 static u32 id_sign[MAX_CONTACTS + 1] = {0};
216 static u8 id_state_flag[MAX_CONTACTS + 1] = {0};
217 static u8 id_state_old_flag[MAX_CONTACTS + 1] = {0};
218 static u16 x_old[MAX_CONTACTS + 1] = {0};
219 static u16 y_old[MAX_CONTACTS + 1] = {0};
223 static int gsl3673_init(void)
225 struct device_node *np = gsl_client->dev.of_node;
226 enum of_gpio_flags rst_flags;
227 unsigned long irq_flags;
229 this_ts->irq = of_get_named_gpio_flags(np, "irq_gpio_number", 0,
230 (enum of_gpio_flags *)&irq_flags);
231 this_ts->rst = of_get_named_gpio_flags(np, "rst_gpio_number", 0,
233 if (devm_gpio_request(&this_ts->client->dev, this_ts->rst, NULL) != 0) {
234 dev_err(&this_ts->client->dev, "gpio_request this_ts->rst error\n");
237 gpio_direction_output(this_ts->rst, 0);
238 gpio_set_value(this_ts->rst, 1);
242 static int gsl3673_shutdown_low(void)
244 if (this_ts->rst > 1)
245 gpio_set_value(this_ts->rst, 0);
249 static int gsl3673_shutdown_high(void)
251 if (this_ts->rst > 1)
252 gpio_set_value(this_ts->rst, 1);
256 static inline u16 join_bytes(u8 a, u8 b)
265 static u32 gsl_write_interface(struct i2c_client *client, const u8 reg,
268 struct i2c_msg xfer_msg[1];
271 xfer_msg[0].addr = client->addr;
272 xfer_msg[0].len = num + 1;
273 xfer_msg[0].flags = client->flags & I2C_M_TEN;
274 xfer_msg[0].buf = buf;
276 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
279 static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata,
284 unsigned int bytelen = 0;
287 print_info("%s too big datalen = %d!\n", __func__, datalen);
292 if (datalen != 0 && pdata != NULL) {
293 memcpy(&tmp_buf[bytelen], pdata, datalen);
296 ret = i2c_master_send(client, tmp_buf, bytelen);
300 static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata,
301 unsigned int datalen)
306 print_info("%s too big datalen = %d!\n", __func__, datalen);
309 ret = gsl_ts_write(client, addr, NULL, 0);
311 print_info("%s set data address fail!\n", __func__);
314 return i2c_master_recv(client, pdata, datalen);
317 #ifdef GSLX680_COMPATIBLE
318 static void judge_chip_type(struct i2c_client *client)
320 u8 read_buf[4] = {0};
323 gsl_ts_read(client, 0xfc, read_buf, sizeof(read_buf));
324 if (read_buf[2] != 0x36 && read_buf[2] != 0x88) {
326 gsl_ts_read(client, 0xfc, read_buf, sizeof(read_buf));
328 print_info("leaf ggggg buf0 =%x %x %x %x\n",
329 read_buf[0], read_buf[1], read_buf[2], read_buf[3]);
330 chip_type = read_buf[2];
334 static inline void fw2buf(u8 *buf, const u32 *fw)
336 u32 *u32_buf = (int *)buf;
340 static void gsl_load_fw(struct i2c_client *client)
342 u8 buf[DMA_TRANS_LEN * 4 + 1] = {0};
347 struct fw_data const *ptr_fw;
349 #ifdef GSLX680_COMPATIBLE
350 if (chip_type == TP2680A_ID) {
351 ptr_fw = GSL2680A_FW;
352 source_len = ARRAY_SIZE(GSL2680A_FW);
354 ptr_fw = GSL2680B_FW;
355 source_len = ARRAY_SIZE(GSL2680B_FW);
359 source_len = ARRAY_SIZE(GSL3673_FW);
361 for (source_line = 0; source_line < source_len; source_line++) {
362 if (ptr_fw[source_line].offset == GSL_PAGE_REG) {
363 fw2buf(cur, &ptr_fw[source_line].val);
364 gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
367 if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
368 buf[0] = (u8)ptr_fw[source_line].offset;
369 fw2buf(cur, &ptr_fw[source_line].val);
371 if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20)) {
372 gsl_write_interface(client, buf[0], buf, cur - buf - 1);
380 static int test_i2c(struct i2c_client *client)
386 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
390 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
392 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
398 static void startup_chip(struct i2c_client *client)
402 #ifdef GSL_NOID_VERSION
403 gsl_DataInit(gsl_config_data_id_3673);
405 gsl_ts_write(client, 0xe0, &tmp, 1);
409 static void reset_chip(struct i2c_client *client)
414 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
417 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
419 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
423 static void clr_reg(struct i2c_client *client)
425 u8 write_buf[4] = {0};
428 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
431 gsl_ts_write(client, 0x80, &write_buf[0], 1);
434 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
437 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
441 static int init_chip(struct i2c_client *client)
445 gsl3673_shutdown_low();
447 gsl3673_shutdown_high();
449 rc = test_i2c(client);
451 print_info("------GSL3673 test_i2c error------\n");
457 startup_chip(client);
459 startup_chip(client);
463 static int check_mem_data(struct i2c_client *client)
465 u8 read_buf[4] = {0};
469 gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf));
470 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] !=
471 0x5a || read_buf[0] != 0x5a) {
472 print_info("#########check mem read 0xb0 = %x %x %x %x #########\n",
473 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
474 rc = init_chip(client);
481 #ifdef TPD_PROC_DEBUG
482 static int char_to_int(char ch)
484 if (ch >= '0' && ch <= '9')
487 return (ch - 'a' + 10);
490 static int gsl_config_read_proc(struct seq_file *m, void *v)
492 char temp_data[5] = {0};
493 unsigned int tmp = 0;
495 if ('v' == gsl_read[0] && 's' == gsl_read[1]) {
496 #ifdef GSL_NOID_VERSION
497 tmp = gsl_version_id();
501 seq_printf(m, "version:%x\n", tmp);
502 } else if ('r' == gsl_read[0] && 'e' == gsl_read[1]) {
503 if ('i' == gsl_read[3]) {
504 #ifdef GSL_NOID_VERSION
505 tmp = (gsl_data_proc[5] << 8) | gsl_data_proc[4];
506 seq_printf(m, "gsl_config_data_id_3673[%d] = ", tmp);
507 if (tmp >= 0 && tmp < ARRAY_SIZE(gsl_config_data_id_3673))
508 seq_printf(m, "%d\n", gsl_config_data_id_3673[tmp]);
511 gsl_ts_write(gsl_client, 0Xf0, &gsl_data_proc[4], 4);
512 if (gsl_data_proc[0] < 0x80)
513 gsl_ts_read(gsl_client, gsl_data_proc[0], temp_data, 4);
514 gsl_ts_read(gsl_client, gsl_data_proc[0], temp_data, 4);
515 seq_printf(m, "offset : {0x%02x,0x", gsl_data_proc[0]);
516 seq_printf(m, "%02x", temp_data[3]);
517 seq_printf(m, "%02x", temp_data[2]);
518 seq_printf(m, "%02x", temp_data[1]);
519 seq_printf(m, "%02x};\n", temp_data[0]);
525 static ssize_t gsl_config_write_proc(struct file *file, const char *buffer,
526 size_t count, loff_t *data)
529 char temp_buf[CONFIG_LEN];
535 print_info("size not match [%d:%ld]\n", CONFIG_LEN, count);
538 path_buf = kzalloc(count, GFP_KERNEL);
540 print_info("alloc path_buf memory error\n");
541 if (copy_from_user(path_buf, buffer, count)) {
542 print_info("copy from user fail\n");
543 goto exit_write_proc_out;
545 memcpy(temp_buf, path_buf, (count < CONFIG_LEN ? count : CONFIG_LEN));
546 buf[3] = char_to_int(temp_buf[14]) << 4 | char_to_int(temp_buf[15]);
547 buf[2] = char_to_int(temp_buf[16]) << 4 | char_to_int(temp_buf[17]);
548 buf[1] = char_to_int(temp_buf[18]) << 4 | char_to_int(temp_buf[19]);
549 buf[0] = char_to_int(temp_buf[20]) << 4 | char_to_int(temp_buf[21]);
550 buf[7] = char_to_int(temp_buf[5]) << 4 | char_to_int(temp_buf[6]);
551 buf[6] = char_to_int(temp_buf[7]) << 4 | char_to_int(temp_buf[8]);
552 buf[5] = char_to_int(temp_buf[9]) << 4 | char_to_int(temp_buf[10]);
553 buf[4] = char_to_int(temp_buf[11]) << 4 | char_to_int(temp_buf[12]);
554 if ('v' == temp_buf[0] && 's' == temp_buf[1]) {
555 memcpy(gsl_read, temp_buf, 4);
556 print_info("gsl version\n");
557 } else if ('s' == temp_buf[0] && 't' == temp_buf[1]) {
559 reset_chip(gsl_client);
560 } else if ('e' == temp_buf[0] && 'n' == temp_buf[1]) {
562 reset_chip(gsl_client);
563 startup_chip(gsl_client);
565 } else if ('r' == temp_buf[0] && 'e' == temp_buf[1]) {
566 memcpy(gsl_read, temp_buf, 4);
567 memcpy(gsl_data_proc, buf, 8);
568 } else if ('w' == temp_buf[0] && 'r' == temp_buf[1]) {
569 gsl_ts_write(gsl_client, buf[4], buf, 4);
571 #ifdef GSL_NOID_VERSION
572 else if ('i' == temp_buf[0] && 'd' == temp_buf[1]) {
573 tmp1 = (buf[7] << 24) | (buf[6] << 16) | (buf[5] << 8) | buf[4];
574 tmp = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
575 if (tmp1 >= 0 && tmp1 < ARRAY_SIZE(gsl_config_data_id_3673))
576 gsl_config_data_id_3673[tmp1] = tmp;
584 static int gsl_server_list_open(struct inode *inode, struct file *file)
586 return single_open(file, gsl_config_read_proc, NULL);
589 static const struct file_operations gsl_seq_fops = {
590 .open = gsl_server_list_open,
592 .release = single_release,
593 .write = gsl_config_write_proc,
594 .owner = THIS_MODULE,
599 static void filter_point(u16 x, u16 y, u8 id)
603 u16 filter_step_x = 0, filter_step_y = 0;
605 id_sign[id] = id_sign[id] + 1;
606 if (id_sign[id] == 1) {
610 x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x);
611 y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y);
612 if ((x_err > FILTER_MAX && y_err > FILTER_MAX / 3) ||
613 (x_err > FILTER_MAX / 3 && y_err > FILTER_MAX)) {
614 filter_step_x = x_err;
615 filter_step_y = y_err;
617 if (x_err > FILTER_MAX)
618 filter_step_x = x_err;
619 if (y_err > FILTER_MAX)
620 filter_step_y = y_err;
622 if (x_err <= 2 * FILTER_MAX && y_err <= 2 * FILTER_MAX) {
625 } else if (x_err <= 3 * FILTER_MAX && y_err <= 3 * FILTER_MAX) {
628 } else if (x_err <= 4 * FILTER_MAX && y_err <= 4 * FILTER_MAX) {
629 filter_step_x = filter_step_x * 3 / 4;
630 filter_step_y = filter_step_y * 3 / 4;
632 x_new = x > x_old[id] ? (x_old[id] + filter_step_x)
633 : (x_old[id] - filter_step_x);
634 y_new = y > y_old[id] ? (y_old[id] + filter_step_y)
635 : (y_old[id] - filter_step_y);
641 static void record_point(u16 x, u16 y, u8 id)
646 id_sign[id] = id_sign[id] + 1;
647 if (id_sign[id] == 1) {
651 x = (x_old[id] + x) / 2;
652 y = (y_old[id] + y) / 2;
654 x_err = x - x_old[id];
656 x_err = x_old[id] - x;
658 y_err = y - y_old[id];
660 y_err = y_old[id] - y;
661 if ((x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3)) {
680 if (id_sign[id] == 1) {
687 #ifdef HAVE_TOUCH_KEY
688 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
692 for (i = 0; i < MAX_KEY_NUM; i++) {
693 if ((gsl_key_data[i].x_min < x) && (x < gsl_key_data[i].x_max)
694 && (gsl_key_data[i].y_min < y)
695 && (y < gsl_key_data[i].y_max)) {
696 key = gsl_key_data[i].key;
697 input_report_key(ts->input, key, 1);
698 input_sync(ts->input);
706 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
711 if (x > SCREEN_MAX_X || y > SCREEN_MAX_Y) {
712 #ifdef HAVE_TOUCH_KEY
713 report_key(ts, x, y);
717 #ifdef REPORT_DATA_ANDROID_4_0
718 input_mt_slot(ts->input, id);
719 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
720 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
722 input_report_abs(ts->input, ABS_MT_POSITION_X, SCREEN_MAX_X - x);
724 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
727 input_report_abs(ts->input, ABS_MT_POSITION_Y, (SCREEN_MAX_Y - y));
729 input_report_abs(ts->input, ABS_MT_POSITION_Y, (y));
731 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
733 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
734 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
735 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
736 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
737 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
738 input_mt_sync(ts->input);
742 static void gsl3673_ts_worker(struct work_struct *work)
748 #ifdef GSL_NOID_VERSION
751 struct gsl_touch_info cinfo;
754 struct gsl_ts *ts = container_of(work, struct gsl_ts, work);
755 #ifdef TPD_PROC_DEBUG
756 if (gsl_proc_flag == 1)
760 if (i2c_lock_flag != 0)
761 goto i2c_lock_schedule;
765 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
767 dev_err(&ts->client->dev, "read failed\n");
770 touches = ts->touch_data[ts->dd->touch_index];
771 #ifdef GSL_NOID_VERSION
772 cinfo.finger_num = touches;
773 for (i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i++) {
774 cinfo.x[i] = join_bytes((ts->touch_data[ts->dd->x_index +
775 4 * i + 1] & 0xf), ts->touch_data[ts->dd->x_index + 4 * i]);
776 cinfo.y[i] = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
777 ts->touch_data[ts->dd->y_index + 4 * i]);
778 cinfo.id[i] = ((ts->touch_data[ts->dd->x_index + 4 * i + 1]
781 cinfo.finger_num = (ts->touch_data[3] << 24) | (ts->touch_data[2] << 16)
782 | (ts->touch_data[1] << 8) | (ts->touch_data[0]);
783 gsl_alg_id_main(&cinfo);
784 tmp1 = gsl_mask_tiaoping();
785 if (tmp1 > 0 && tmp1 < 0xffffffff) {
790 gsl_ts_write(ts->client, 0xf0, buf, 4);
791 buf[0] = (u8)(tmp1 & 0xff);
792 buf[1] = (u8)((tmp1 >> 8) & 0xff);
793 buf[2] = (u8)((tmp1 >> 16) & 0xff);
794 buf[3] = (u8)((tmp1 >> 24) & 0xff);
796 "tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x,buf[3]=%02x\n",
797 tmp1, buf[0], buf[1], buf[2], buf[3]);
798 gsl_ts_write(ts->client, 0x8, buf, 4);
800 touches = cinfo.finger_num;
802 for (i = 1; i <= MAX_CONTACTS; i++) {
805 id_state_flag[i] = 0;
807 for (i = 0; i < (touches > MAX_FINGERS ? MAX_FINGERS : touches); i++) {
808 #ifdef GSL_NOID_VERSION
813 x = join_bytes((ts->touch_data[ts->dd->x_index + 4 * i + 1]
814 & 0xf), ts->touch_data[ts->dd->x_index + 4 * i]);
815 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
816 ts->touch_data[ts->dd->y_index + 4 * i]);
817 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
819 if (id >= 1 && id <= MAX_CONTACTS) {
821 filter_point(x, y, id);
823 record_point(x, y, id);
825 report_data(ts, x_new, y_new, 10, id);
826 id_state_flag[id] = 1;
829 for (i = 1; i <= MAX_CONTACTS; i++) {
830 if ((touches == 0) || ((id_state_old_flag[i] != 0) &&
831 (id_state_flag[i] == 0))) {
832 #ifdef REPORT_DATA_ANDROID_4_0
833 input_mt_slot(ts->input, i);
834 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
835 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
839 id_state_old_flag[i] = id_state_flag[i];
842 #ifdef HAVE_TOUCH_KEY
843 if (key_state_flag && touches == 0) {
844 input_report_key(ts->input, key, 0);
845 input_sync(ts->input);
850 input_sync(ts->input);
860 static void gsl_monitor_worker(struct work_struct *work)
862 u8 read_buf[4] = {0};
863 char init_chip_flag = 0;
866 if (i2c_lock_flag != 0)
870 gsl_ts_read(gsl_client, 0xb0, read_buf, 4);
871 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a ||
872 read_buf[1] != 0x5a || read_buf[0] != 0x5a)
876 if (b0_counter > 1) {
877 print_info("======read 0xb0: %x %x %x %x ======\n",
878 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
882 gsl_ts_read(gsl_client, 0xb4, read_buf, 4);
883 int_2nd[3] = int_1st[3];
884 int_2nd[2] = int_1st[2];
885 int_2nd[1] = int_1st[1];
886 int_2nd[0] = int_1st[0];
887 int_1st[3] = read_buf[3];
888 int_1st[2] = read_buf[2];
889 int_1st[1] = read_buf[1];
890 int_1st[0] = read_buf[0];
891 if (int_1st[3] == int_2nd[3] && int_1st[2] == int_2nd[2] &&
892 int_1st[1] == int_2nd[1] && int_1st[0] == int_2nd[0]) {
894 "======int_1st: %x %x %x %x ,int_2nd: %x %x %x %x ======\n",
895 int_1st[3], int_1st[2], int_1st[1], int_1st[0],
896 int_2nd[3], int_2nd[2], int_2nd[1], int_2nd[0]);
899 gsl_ts_read(gsl_client, 0xbc, read_buf, 4);
900 if (read_buf[3] != 0 || read_buf[2] != 0 ||
901 read_buf[1] != 0 || read_buf[0] != 0)
905 if (bc_counter > 1) {
906 print_info("======read 0xbc: %x %x %x %x======\n",
907 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
911 if (init_chip_flag) {
912 rc = init_chip(gsl_client);
920 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
922 struct gsl_ts *ts = (struct gsl_ts *)dev_id;
924 disable_irq_nosync(ts->irq);
925 if (!work_pending(&ts->work))
926 queue_work(ts->wq, &ts->work);
930 static int gsl3673_ts_init(struct i2c_client *client, struct gsl_ts *ts)
932 struct input_dev *input_device;
934 #ifdef HAVE_TOUCH_KEY
938 ts->dd = &devices[ts->device_id];
939 if (ts->device_id == 0) {
940 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes +
941 ts->dd->touch_meta_data;
942 ts->dd->touch_index = 0;
944 ts->touch_data = devm_kzalloc(&client->dev,
945 ts->dd->data_size, GFP_KERNEL);
948 input_device = devm_input_allocate_device(&ts->client->dev);
952 ts->input = input_device;
953 input_device->name = GSL3673_I2C_NAME;
954 input_device->id.bustype = BUS_I2C;
955 input_device->dev.parent = &client->dev;
956 input_set_drvdata(input_device, ts);
957 #ifdef HAVE_TOUCH_KEY
958 for (i = 0; i < MAX_KEY_NUM; i++) {
959 input_device->evbit[i] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY);
960 set_bit(key_array[i], input_device->keybit);
963 #ifdef REPORT_DATA_ANDROID_4_0
964 __set_bit(EV_ABS, input_device->evbit);
965 __set_bit(EV_KEY, input_device->evbit);
966 __set_bit(EV_REP, input_device->evbit);
967 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
968 input_mt_init_slots(input_device, (MAX_CONTACTS + 1), 0);
970 input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0,
971 (MAX_CONTACTS + 1), 0, 0);
972 set_bit(EV_ABS, input_device->evbit);
973 set_bit(EV_KEY, input_device->evbit);
974 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
975 input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
977 set_bit(ABS_MT_POSITION_X, input_device->absbit);
978 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
979 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
980 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
981 input_set_abs_params(input_device, ABS_MT_POSITION_X, 0,
983 input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0,
985 input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0,
987 input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
988 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
990 dev_err(&client->dev, "gsl Could not create workqueue\n");
993 flush_workqueue(ts->wq);
994 INIT_WORK(&ts->work, gsl3673_ts_worker);
995 rc = input_register_device(input_device);
997 goto error_unreg_device;
1000 destroy_workqueue(ts->wq);
1004 static int gsl_ts_suspend(struct device *dev)
1006 struct gsl_ts *ts = dev_get_drvdata(dev);
1010 cancel_delayed_work_sync(&gsl_monitor_work);
1012 disable_irq_nosync(ts->irq);
1013 gsl3673_shutdown_low();
1014 #ifdef SLEEP_CLEAR_POINT
1016 #ifdef REPORT_DATA_ANDROID_4_0
1017 for (i = 1; i <= MAX_CONTACTS; i++) {
1018 input_mt_slot(ts->input, i);
1019 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1020 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1023 input_mt_sync(ts->input);
1025 input_sync(ts->input);
1027 report_data(ts, 1, 1, 10, 1);
1028 input_sync(ts->input);
1033 static int gsl_ts_resume(struct device *dev)
1035 struct gsl_ts *ts = dev_get_drvdata(dev);
1039 gsl3673_shutdown_high();
1041 reset_chip(ts->client);
1042 startup_chip(ts->client);
1043 rc = check_mem_data(ts->client);
1046 #ifdef SLEEP_CLEAR_POINT
1047 #ifdef REPORT_DATA_ANDROID_4_0
1048 for (i = 1; i <= MAX_CONTACTS; i++) {
1049 input_mt_slot(ts->input, i);
1050 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1051 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1054 input_mt_sync(ts->input);
1056 input_sync(ts->input);
1059 queue_delayed_work(gsl_monitor_workqueue, &gsl_monitor_work, 300);
1061 disable_irq_nosync(ts->irq);
1062 enable_irq(ts->irq);
1066 static int gsl_ts_early_suspend(struct tp_device *tp_d)
1068 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1070 gsl_ts_suspend(&ts->client->dev);
1074 static int gsl_ts_late_resume(struct tp_device *tp_d)
1076 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1079 rc = gsl_ts_resume(&ts->client->dev);
1083 static int gsl_ts_probe(struct i2c_client *client,
1084 const struct i2c_device_id *id)
1088 #if defined CONFIG_BOARD_TYPE_ZM1128CE
1089 axp_gpio_set_io(PMU_GPIO_NUM, 1);
1092 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1093 dev_err(&client->dev, "gsl I2C functionality not supported\n");
1096 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
1099 ts->tp.tp_resume = gsl_ts_late_resume;
1100 ts->tp.tp_suspend = gsl_ts_early_suspend;
1101 tp_register_fb(&ts->tp);
1102 ts->client = client;
1103 i2c_set_clientdata(client, ts);
1105 gsl_client = client;
1107 rc = gsl3673_ts_init(client, ts);
1109 dev_err(&client->dev, "gsl GSL3673 init failed\n");
1110 goto error_mutex_destroy;
1112 #ifdef GSLX680_COMPATIBLE
1113 judge_chip_type(client);
1115 rc = init_chip(ts->client);
1117 dev_err(&client->dev, "gsl_probe: init_chip failed\n");
1118 goto error_init_chip_fail;
1120 check_mem_data(ts->client);
1121 client->irq = gpio_to_irq(ts->irq);
1122 rc = devm_request_irq(&client->dev, client->irq, gsl_ts_irq,
1123 IRQF_TRIGGER_RISING, client->name, ts);
1125 dev_err(&client->dev, "gsl_probe: request irq failed\n");
1129 INIT_DELAYED_WORK(&gsl_monitor_work, gsl_monitor_worker);
1130 gsl_monitor_workqueue = create_singlethread_workqueue
1131 ("gsl_monitor_workqueue");
1132 queue_delayed_work(gsl_monitor_workqueue, &gsl_monitor_work, 1000);
1134 #ifdef TPD_PROC_DEBUG
1135 proc_create(GSL_CONFIG_PROC_FILE, 0644, NULL, &gsl_seq_fops);
1139 error_init_chip_fail:
1140 error_mutex_destroy:
1141 tp_unregister_fb(&ts->tp);
1145 static int gsl_ts_remove(struct i2c_client *client)
1147 struct gsl_ts *ts = i2c_get_clientdata(client);
1150 cancel_delayed_work_sync(&gsl_monitor_work);
1151 destroy_workqueue(gsl_monitor_workqueue);
1153 device_init_wakeup(&client->dev, 0);
1154 cancel_work_sync(&ts->work);
1155 destroy_workqueue(ts->wq);
1159 static const struct of_device_id gsl_ts_ids[] = {
1160 {.compatible = "GSL,GSL3673"},
1164 static const struct i2c_device_id gsl_ts_id[] = {
1165 {GSL3673_I2C_NAME, 0},
1169 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1171 static struct i2c_driver gsl_ts_driver = {
1173 .name = GSL3673_I2C_NAME,
1174 .owner = THIS_MODULE,
1175 .of_match_table = of_match_ptr(gsl_ts_ids),
1177 .probe = gsl_ts_probe,
1178 .remove = gsl_ts_remove,
1179 .id_table = gsl_ts_id,
1182 static int __init gsl_ts_init(void)
1184 return i2c_add_driver(&gsl_ts_driver);
1187 static void __exit gsl_ts_exit(void)
1189 i2c_del_driver(&gsl_ts_driver);
1192 module_init(gsl_ts_init);
1193 module_exit(gsl_ts_exit);
1195 MODULE_LICENSE("GPL");
1196 MODULE_DESCRIPTION("GSL3673 touchscreen controller driver");
1197 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1198 MODULE_ALIAS("platform:gsl_ts");