2 * drivers/input/touchscreen/gslX680.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.
12 #include <linux/module.h>
13 #include <linux/delay.h>
14 #include <linux/hrtimer.h>
15 #include <linux/i2c.h>
16 #include <linux/input.h>
17 #include <linux/interrupt.h>
19 #include <linux/platform_device.h>
20 #include <linux/async.h>
21 #include <linux/gpio.h>
23 #include <linux/slab.h>
24 #include <linux/workqueue.h>
25 #include <linux/proc_fs.h>
26 #include <linux/input/mt.h>
27 //#include "rockchip_gslX680_rk3168.h"
28 #include "tp_suspend.h"
30 #include <linux/of_gpio.h>
31 #include <linux/wakelock.h>
45 #define REPORT_DATA_ANDROID_4_0
46 #define HAVE_TOUCH_KEY
47 //#define SLEEP_CLEAR_POINT
49 //#define FILTER_POINT
52 #define FILTER_MAX 9 //6
55 #define GSLX680_I2C_NAME "gslX680"
56 #define GSLX680_I2C_ADDR 0x40
58 //#define IRQ_PORT RK2928_PIN1_PB0//RK30_PIN1_PB7
59 //#define WAKE_PORT RK30_PIN0_PA1//RK30_PIN0_PB6
61 #define GSL_DATA_REG 0x80
62 #define GSL_STATUS_REG 0xe0
63 #define GSL_PAGE_REG 0xf0
65 #define TPD_PROC_DEBUG
67 #include <linux/proc_fs.h>
68 #include <asm/uaccess.h>
69 #include <linux/seq_file.h>
70 //static struct proc_dir_entry *gsl_config_proc = NULL;
71 #define GSL_CONFIG_PROC_FILE "gsl_config"
73 static char gsl_read[CONFIG_LEN];
74 static u8 gsl_data_proc[8] = { 0 };
75 static u8 gsl_proc_flag = 0;
76 static struct i2c_client *i2c_client = NULL;
80 #define MAX_FINGERS 10
81 #define MAX_CONTACTS 10
82 #define DMA_TRANS_LEN 0x20
86 static int g_istouch=0;
89 static struct workqueue_struct *gsl_monitor_workqueue = NULL;
90 static u8 int_1st[4] = { 0 };
91 static u8 int_2nd[4] = { 0 };
92 //static char dac_counter = 0;
93 static char b0_counter = 0;
94 static char bc_counter = 0;
95 static char i2c_lock_flag = 0;
98 #define WRITE_I2C_SPEED (350*1000)
99 #define I2C_SPEED (200*1000)
100 #define CLOSE_TP_POWER 0
102 //#define HAVE_CLICK_TIMER
104 #ifdef HAVE_CLICK_TIMER
106 static struct workqueue_struct *gsl_timer_workqueue = NULL;
107 bool send_key = false;
108 struct semaphore my_sem;
111 #ifdef HAVE_TOUCH_KEY
113 static int key_state_flag = 0;
122 const u16 key_array[] = {
130 #define MAX_KEY_NUM (sizeof(key_array)/sizeof(key_array[0]))
136 struct key_data gsl_key_data[MAX_KEY_NUM] = {
137 {KEY_BACK, 550, 650, 1400, 1600},
138 {KEY_HOMEPAGE, 350, 450, 1400, 1600},
139 {KEY_MENU, 150, 250, 1400, 1600},
140 {KEY_SEARCH, 2048, 2048, 2048, 2048},
160 static struct gsl_ts_data devices[] = {
166 .data_reg = GSL_DATA_REG,
167 .status_reg = GSL_STATUS_REG,
170 .touch_meta_data = 4,
176 struct i2c_client *client;
177 struct input_dev *input;
178 struct work_struct work;
179 struct workqueue_struct *wq;
180 struct gsl_ts_data *dd;
181 int flag_irq_is_disable;
187 struct delayed_work gsl_monitor_work;
188 #if defined(CONFIG_HAS_EARLYSUSPEND)
189 struct early_suspend early_suspend;
192 #if defined (HAVE_CLICK_TIMER)
193 struct work_struct click_work;
197 struct pinctrl *pinctrl;
198 struct pinctrl_state *pins_default;
199 struct pinctrl_state *pins_sleep;
200 struct pinctrl_state *pins_inactive;
204 #define print_info(fmt, args...) printk(fmt, ##args);
206 #define print_info(fmt, args...)
209 static u32 id_sign[MAX_CONTACTS + 1] = { 0 };
210 static u8 id_state_flag[MAX_CONTACTS + 1] = { 0 };
211 static u8 id_state_old_flag[MAX_CONTACTS + 1] = { 0 };
212 static u16 x_old[MAX_CONTACTS + 1] = { 0 };
213 static u16 y_old[MAX_CONTACTS + 1] = { 0 };
214 static u16 x_new = 0;
215 static u16 y_new = 0;
217 int gslx680_set_pinctrl_state(struct gsl_ts *ts, struct pinctrl_state *state)
221 if (!IS_ERR(state)) {
222 ret = pinctrl_select_state(ts->pinctrl, state);
224 printk("could not set pins \n");
230 static int gslX680_init(struct gsl_ts *ts)
232 struct device_node *np = ts->client->dev.of_node;
236 ts->irq = of_get_named_gpio_flags(np, "touch-gpio", 0, NULL);
237 ts->rst = of_get_named_gpio_flags(np, "reset-gpio", 0, NULL);
240 #if 0 //#if defined (CONFIG_BOARD_ZM71C)||defined (CONFIG_BOARD_ZM72CP) ||
241 defined(CONFIG_BOARD_ZM726C) || defined(CONFIG_BOARD_ZM726CE)
242 if (gpio_request(ts->rst, NULL) != 0) {
244 printk("gslX680_init gpio_request error\n");
250 ts->pinctrl = devm_pinctrl_get(&ts->client->dev);
251 if (IS_ERR(ts->pinctrl)) {
252 ret = PTR_ERR(ts->pinctrl);
257 pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_DEFAULT);
258 //if (IS_ERR(ts->pins_default))
259 // dev_err(&client->dev, "could not get default pinstate\n");
261 ts->pins_sleep = pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_SLEEP);
262 //if (IS_ERR(ts->pins_sleep))
263 // dev_err(&client->dev, "could not get sleep pinstate\n");
265 ts->pins_inactive = pinctrl_lookup_state(ts->pinctrl, "inactive");
266 //if (IS_ERR(ts->pins_inactive))
267 // dev_err(&client->dev, "could not get inactive pinstate\n");
269 err = gpio_request(ts->rst, "tp reset");
271 printk("gslx680 reset gpio request failed.\n");
275 gslx680_set_pinctrl_state(ts, ts->pins_default);
276 gpio_direction_output(ts->rst, 1);
277 gpio_set_value(ts->rst, 1);
282 static int gslX680_shutdown_low(struct gsl_ts *ts)
284 printk("gsl gslX680_shutdown_low\n");
285 gpio_direction_output(ts->rst, 0);
286 gpio_set_value(ts->rst, 0);
291 static int gslX680_shutdown_high(struct gsl_ts *ts)
293 printk("gsl gslX680_shutdown_high\n");
294 gpio_direction_output(ts->rst, 1);
295 gpio_set_value(ts->rst, 1);
300 static inline u16 join_bytes(u8 a, u8 b)
311 static u32 gsl_read_interface(struct i2c_client *client,
312 u8 reg, u8 *buf, u32 num)
314 struct i2c_msg xfer_msg[2];
316 xfer_msg[0].addr = client->addr;
318 xfer_msg[0].flags = client->flags & I2C_M_TEN;
319 xfer_msg[0].buf = ®
320 xfer_msg[0].scl_rate=300*1000;
322 xfer_msg[1].addr = client->addr;
323 xfer_msg[1].len = num;
324 xfer_msg[1].flags |= I2C_M_RD;
325 xfer_msg[1].buf = buf;
326 xfer_msg[1].scl_rate=300*1000;
329 i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
333 return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) \
334 == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
338 static u32 gsl_write_interface(struct i2c_client *client,
339 const u8 reg, u8 *buf, u32 num)
341 struct i2c_msg xfer_msg[1];
345 xfer_msg[0].addr = client->addr;
346 xfer_msg[0].len = num + 1;
347 xfer_msg[0].flags = client->flags & I2C_M_TEN;
348 xfer_msg[0].buf = buf;
349 //xfer_msg[0].scl_rate = 100 * 1000;
351 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
354 static int gsl_ts_write(struct i2c_client *client,
355 u8 addr, u8 *pdata, int datalen)
359 unsigned int bytelen = 0;
362 printk("%s too big datalen = %d!\n", __func__, datalen);
369 if (datalen != 0 && pdata != NULL) {
370 memcpy(&tmp_buf[bytelen], pdata, datalen);
374 ret = i2c_master_send(client, tmp_buf, bytelen);
378 static int gsl_ts_read(struct i2c_client *client, u8 addr,
379 u8 *pdata, unsigned int datalen)
384 printk("%s too big datalen = %d!\n", __func__, datalen);
388 ret = gsl_ts_write(client, addr, NULL, 0);
390 printk("%s set data address fail!\n", __func__);
394 return i2c_master_recv(client, pdata, datalen);
397 static __inline__ void fw2buf(u8 *buf, const u32 *fw)
399 u32 *u32_buf = (int *)buf;
403 static void gsl_load_fw(struct i2c_client *client)
405 u8 buf[DMA_TRANS_LEN * 4 + 1] = { 0 };
410 //u8 read_buf[4] = {0};
411 struct fw_data const *ptr_fw;
414 source_len = ARRAY_SIZE(GSLX680_FW);
416 for (source_line = 0; source_line < source_len; source_line++) {
417 /* init page trans, set the page val */
418 if (GSL_PAGE_REG == ptr_fw[source_line].offset) {
419 fw2buf(cur, &ptr_fw[source_line].val);
420 gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
424 send_flag % (DMA_TRANS_LEN <
425 0x20 ? DMA_TRANS_LEN : 0x20))
426 buf[0] = (u8) ptr_fw[source_line].offset;
428 fw2buf(cur, &ptr_fw[source_line].val);
432 send_flag % (DMA_TRANS_LEN <
433 0x20 ? DMA_TRANS_LEN : 0x20)) {
434 gsl_write_interface(client, buf[0], buf,
444 static int test_i2c(struct i2c_client *client)
450 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
454 printk("gsl I read reg 0xf0 is %x\n", read_buf);
457 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
459 printk("gsl I write reg 0xf0 0x12\n");
462 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
466 printk("gsl I read reg 0xf0 is 0x%x\n", read_buf);
470 static void startup_chip(struct i2c_client *client)
474 printk("gsl startup_chip\n");
476 #ifdef GSL_NOID_VERSION
477 gsl_DataInit(gsl_config_data_id);
479 gsl_ts_write(client, 0xe0, &tmp, 1);
483 static void reset_chip(struct i2c_client *client)
486 u8 buf[4] = { 0x00 };
488 printk("gsl reset_chip\n");
490 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
493 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
495 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
499 static void clr_reg(struct i2c_client *client)
501 u8 write_buf[4] = { 0 };
504 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
507 gsl_ts_write(client, 0x80, &write_buf[0], 1);
510 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
513 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
517 static void init_chip(struct i2c_client *client, struct gsl_ts *ts)
521 printk("gsl init_chip\n");
523 gslX680_shutdown_low(ts);
525 gslX680_shutdown_high(ts);
527 rc = test_i2c(client);
529 printk("gslX680 test_i2c error\n");
535 startup_chip(client);
537 startup_chip(client);
540 static void check_mem_data(struct i2c_client *client, struct gsl_ts *ts)
542 u8 read_buf[4] = { 0 };
545 gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf));
546 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a ||
547 read_buf[1] != 0x5a || read_buf[0] != 0x5a) {
548 init_chip(client, ts);
552 #ifdef TPD_PROC_DEBUG
553 static int char_to_int(char ch)
555 if (ch >= '0' && ch <= '9')
558 return (ch - 'a' + 10);
561 static int gsl_config_read_proc(struct seq_file *m, void *v)
564 char temp_data[5] = { 0 };
565 unsigned int tmp = 0;
566 //unsigned int *ptr_fw;
568 if ('v' == gsl_read[0] && 's' == gsl_read[1]) {
569 #ifdef GSL_NOID_VERSION
570 tmp = gsl_version_id();
574 seq_printf(m, "version:%x\n", tmp);
575 } else if ('r' == gsl_read[0] && 'e' == gsl_read[1]) {
576 if ('i' == gsl_read[3]) {
577 #ifdef GSL_NOID_VERSION
578 /* tmp=(gsl_data_proc[5]<<8) | gsl_data_proc[4];
579 seq_printf(m,"gsl_config_data_id[%d] = ",tmp);
580 if(tmp>=0&&tmp<gsl_cfg_table[gsl_cfg_index].data_size)
581 seq_printf(m,"%d\n",gsl_cfg_table[gsl_cfg_index].data_id[tmp]); */
583 tmp = (gsl_data_proc[5] << 8) | gsl_data_proc[4];
584 seq_printf(m, "gsl_config_data_id[%d] = ", tmp);
585 if (tmp >= 0 && tmp < 512)
586 seq_printf(m, "%d\n", gsl_config_data_id[tmp]);
589 i2c_smbus_write_i2c_block_data(i2c_client, 0xf0, 4,
591 if (gsl_data_proc[0] < 0x80)
592 i2c_smbus_read_i2c_block_data(i2c_client,
595 i2c_smbus_read_i2c_block_data(i2c_client,
599 seq_printf(m, "offset : {0x%02x,0x", gsl_data_proc[0]);
600 seq_printf(m, "%02x", temp_data[3]);
601 seq_printf(m, "%02x", temp_data[2]);
602 seq_printf(m, "%02x", temp_data[1]);
603 seq_printf(m, "%02x};\n", temp_data[0]);
608 static ssize_t gsl_config_write_proc(struct file *file, const char *buffer,
609 size_t count, loff_t *data)
612 char temp_buf[CONFIG_LEN];
617 print_info("[tp-gsl][%s] \n", __func__);
619 //print_info("size not match [%d:%d]\n", CONFIG_LEN, count);
622 path_buf = kzalloc(count, GFP_KERNEL);
624 printk("alloc path_buf memory error \n");
626 if (copy_from_user(path_buf, buffer, count)) {
627 print_info("copy from user fail\n");
628 goto exit_write_proc_out;
630 memcpy(temp_buf, path_buf, (count < CONFIG_LEN ? count : CONFIG_LEN));
631 print_info("[tp-gsl][%s][%s]\n", __func__, temp_buf);
633 buf[3] = char_to_int(temp_buf[14]) << 4 | char_to_int(temp_buf[15]);
634 buf[2] = char_to_int(temp_buf[16]) << 4 | char_to_int(temp_buf[17]);
635 buf[1] = char_to_int(temp_buf[18]) << 4 | char_to_int(temp_buf[19]);
636 buf[0] = char_to_int(temp_buf[20]) << 4 | char_to_int(temp_buf[21]);
638 buf[7] = char_to_int(temp_buf[5]) << 4 | char_to_int(temp_buf[6]);
639 buf[6] = char_to_int(temp_buf[7]) << 4 | char_to_int(temp_buf[8]);
640 buf[5] = char_to_int(temp_buf[9]) << 4 | char_to_int(temp_buf[10]);
641 buf[4] = char_to_int(temp_buf[11]) << 4 | char_to_int(temp_buf[12]);
642 if ('v' == temp_buf[0] && 's' == temp_buf[1]) {
644 memcpy(gsl_read, temp_buf, 4);
645 printk("gsl version\n");
646 } else if ('s' == temp_buf[0] && 't' == temp_buf[1]) {
649 reset_chip(i2c_client);
650 } else if ('e' == temp_buf[0] && 'n' == temp_buf[1]) {
653 reset_chip(i2c_client);
654 startup_chip(i2c_client);
656 } else if ('r' == temp_buf[0] && 'e' == temp_buf[1]) {
658 memcpy(gsl_read, temp_buf, 4);
659 memcpy(gsl_data_proc, buf, 8);
660 } else if ('w' == temp_buf[0] && 'r' == temp_buf[1]) {
662 i2c_smbus_write_i2c_block_data(i2c_client, buf[4], 4, buf);
664 #ifdef GSL_NOID_VERSION
665 else if ('i' == temp_buf[0] && 'd' == temp_buf[1]) {
667 tmp1 = (buf[7] << 24) | (buf[6] << 16) | (buf[5] << 8) | buf[4];
668 tmp = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
670 if (tmp1 >= 0 && tmp1 < 512) {
671 gsl_config_data_id[tmp1] = tmp;
680 static int gsl_server_list_open(struct inode *inode, struct file *file)
682 return single_open(file, gsl_config_read_proc, NULL);
684 static const struct file_operations gsl_seq_fops = {
685 .open = gsl_server_list_open,
687 .release = single_release,
688 .write = gsl_config_write_proc,
689 .owner = THIS_MODULE,
695 static void filter_point(u16 x, u16 y, u8 id)
699 u16 filter_step_x = 0, filter_step_y = 0;
701 id_sign[id] = id_sign[id] + 1;
702 if (id_sign[id] == 1) {
707 x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x);
708 y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y);
710 if ((x_err > FILTER_MAX && y_err > FILTER_MAX / 3) ||
711 (x_err > FILTER_MAX / 3 && y_err > FILTER_MAX)) {
712 filter_step_x = x_err;
713 filter_step_y = y_err;
715 if (x_err > FILTER_MAX)
716 filter_step_x = x_err;
717 if (y_err > FILTER_MAX)
718 filter_step_y = y_err;
721 if (x_err <= 2 * FILTER_MAX && y_err <= 2 * FILTER_MAX) {
724 } else if (x_err <= 3 * FILTER_MAX && y_err <= 3 * FILTER_MAX) {
727 } else if (x_err <= 4 * FILTER_MAX && y_err <= 4 * FILTER_MAX) {
728 filter_step_x = filter_step_x * 3 / 4;
729 filter_step_y = filter_step_y * 3 / 4;
734 x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] -
738 y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] -
745 static void record_point(u16 x, u16 y, u8 id)
750 id_sign[id] = id_sign[id] + 1;
752 if (id_sign[id] == 1) {
757 x = (x_old[id] + x) / 2;
758 y = (y_old[id] + y) / 2;
761 x_err = x - x_old[id];
763 x_err = x_old[id] - x;
767 y_err = y - y_old[id];
769 y_err = y_old[id] - y;
772 if ((x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3)) {
793 if (id_sign[id] == 1) {
801 #ifdef SLEEP_CLEAR_POINT
802 #ifdef HAVE_TOUCH_KEY
803 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
807 for (i = 0; i < MAX_KEY_NUM; i++) {
808 if ((gsl_key_data[i].x_min < x)
809 && (x < gsl_key_data[i].x_max)
810 && (gsl_key_data[i].y_min < y)
811 && (y < gsl_key_data[i].y_max)) {
812 key = gsl_key_data[i].key;
813 input_report_key(ts->input, key, 1);
814 input_sync(ts->input);
824 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
828 static int old_x=0, old_y=0;
833 //printk("#####id=%d,x=%d,y=%d######\n",id,x,y);
835 if (x > SCREEN_MAX_X || y > SCREEN_MAX_Y) {
836 #ifdef HAVE_TOUCH_KEY
837 //report_key(ts, x, y);
838 //printk("#####report_key x=%d,y=%d######\n",x,y);
844 input_mt_slot(ts->input_dev, id);
845 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
846 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
847 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
848 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
849 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
854 input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
855 input_report_key(ts->input, 0x110, 1);
856 input_sync(ts->input);
858 delt_x = (int)x - old_x;
859 delt_y = (int)y - old_y;
862 input_report_rel(ts->input, REL_Y, -delt_x);
863 input_report_rel(ts->input, REL_X, -delt_y);
864 input_sync(ts->input);
870 #ifdef REPORT_DATA_ANDROID_4_0
871 //printk("#####REPORT_DATA_ANDROID_4_0######\n");
872 input_mt_slot(ts->input, id);
873 //input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
874 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 1);
875 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
877 input_report_abs(ts->input, ABS_MT_POSITION_X, SCREEN_MAX_X - x);
879 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
882 input_report_abs(ts->input, ABS_MT_POSITION_Y, (SCREEN_MAX_Y - y));
884 input_report_abs(ts->input, ABS_MT_POSITION_Y, (y));
886 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
888 //printk("#####nonono REPORT_DATA_ANDROID_4_0######\n");
889 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
890 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
891 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
892 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
893 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
894 input_mt_sync(ts->input);
899 void glsx680_ts_irq_disable(struct gsl_ts *ts)
901 unsigned long irqflags;
903 spin_lock_irqsave(&ts->irq_lock, irqflags);
904 if (!ts->flag_irq_is_disable) {
905 disable_irq_nosync(ts->client->irq);
906 ts->flag_irq_is_disable = 1;
908 spin_unlock_irqrestore(&ts->irq_lock, irqflags);
911 void glsx680_ts_irq_enable(struct gsl_ts *ts)
913 unsigned long irqflags = 0;
915 spin_lock_irqsave(&ts->irq_lock, irqflags);
916 if (ts->flag_irq_is_disable) {
917 enable_irq(ts->client->irq);
918 ts->flag_irq_is_disable = 0;
920 spin_unlock_irqrestore(&ts->irq_lock, irqflags);
923 static void gslX680_ts_worker(struct work_struct *work)
929 #ifdef GSL_NOID_VERSION
932 struct gsl_touch_info cinfo;
935 struct gsl_ts *ts = container_of(work, struct gsl_ts, work);
937 #ifdef TPD_PROC_DEBUG
938 if (gsl_proc_flag == 1)
943 if (i2c_lock_flag != 0)
944 goto i2c_lock_schedule;
949 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
951 dev_err(&ts->client->dev, "read failed\n");
955 touches = ts->touch_data[ts->dd->touch_index];
956 //print_info("-----touches: %d -----\n", touches);
957 #ifdef GSL_NOID_VERSION
959 cinfo.finger_num = touches;
960 //print_info("tp-gsl finger_num = %d\n",cinfo.finger_num);
961 for (i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i++) {
964 touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
965 ts->touch_data[ts->dd->x_index + 4 * i]);
967 join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
968 ts->touch_data[ts->dd->y_index + 4 * i]);
970 ((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf0) >> 4);
971 /*print_info("tp-gsl before: x[%d] = %d, y[%d] = %d,
972 id[%d] = %d \n",i,cinfo.x[i],i,cinfo.y[i],i,cinfo.id[i]);*/
974 cinfo.finger_num = (ts->touch_data[3] << 24) | (ts->touch_data[2] << 16)
975 | (ts->touch_data[1] << 8) | (ts->touch_data[0]);
976 gsl_alg_id_main(&cinfo);
977 tmp1 = gsl_mask_tiaoping();
978 //print_info("[tp-gsl] tmp1 = %x\n", tmp1);
979 if (tmp1 > 0 && tmp1 < 0xffffffff) {
984 gsl_ts_write(ts->client, 0xf0, buf, 4);
985 buf[0] = (u8) (tmp1 & 0xff);
986 buf[1] = (u8) ((tmp1 >> 8) & 0xff);
987 buf[2] = (u8) ((tmp1 >> 16) & 0xff);
988 buf[3] = (u8) ((tmp1 >> 24) & 0xff);
989 print_info("tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x, \
990 buf[3]=%02x\n", tmp1, buf[0], buf[1], buf[2], buf[3]);
991 gsl_ts_write(ts->client, 0x8, buf, 4);
993 touches = cinfo.finger_num;
996 for (i = 1; i <= MAX_CONTACTS; i++) {
999 id_state_flag[i] = 0;
1001 for (i = 0; i < (touches > MAX_FINGERS ? MAX_FINGERS : touches); i++) {
1002 #ifdef GSL_NOID_VERSION
1007 x = join_bytes((ts->
1008 touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
1009 ts->touch_data[ts->dd->x_index + 4 * i]);
1010 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
1011 ts->touch_data[ts->dd->y_index + 4 * i]);
1012 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
1015 if (1 <= id && id <= MAX_CONTACTS) {
1017 filter_point(x, y, id);
1019 record_point(x, y, id);
1021 #ifdef RK_GEAR_TOUCH
1022 report_data(ts, x_new, y_new, 10, id);
1024 if (key_count <= 512) {
1025 key_x[key_count] = x_new;
1026 key_y[key_count] = y_new;
1028 /*printk("test in key store in here,
1029 x_new is %d , y_new is %d ,
1030 key_count is %d \n", x_new ,y_new,key_count);*/
1032 id_state_flag[id] = 1;
1035 for (i = 1; i <= MAX_CONTACTS; i++) {
1037 || ((0 != id_state_old_flag[i])
1038 && (0 == id_state_flag[i]))) {
1039 #ifdef RK_GEAR_TOUCH
1040 if (g_istouch == 1){
1042 input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
1043 input_report_key(ts->input, 0x110, 0);
1044 input_sync(ts->input);
1048 #ifdef REPORT_DATA_ANDROID_4_0
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,
1056 id_state_old_flag[i] = id_state_flag[i];
1060 #ifdef REPORT_DATA_ANDROID_4_0
1061 #ifndef RK_GEAR_TOUCH
1062 //input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, 0);
1063 //input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 0);
1064 //input_mt_sync(ts->input);
1069 (((key_x[key_count - 1] - key_x[0]) >
1070 0) ? (key_x[key_count - 1] - key_x[0])
1071 : (key_x[0] - key_x[key_count - 1]));
1073 (((key_y[key_count - 1] - key_y[0]) >
1074 0) ? (key_y[key_count - 1] - key_y[0])
1075 : (key_y[0] - key_y[key_count - 1]));
1076 if (key_count <= 512) {
1077 if (temp_x > temp_y) {
1078 if ((key_x[key_count - 1] - key_x[0]) > 100) {
1079 printk(" send up key \n");
1080 input_report_key(ts->input,
1082 input_sync(ts->input);
1083 input_report_key(ts->input,
1085 input_sync(ts->input);
1086 } else if ((key_x[0] - key_x[key_count - 1]) >
1088 printk(" send down key \n");
1089 input_report_key(ts->input,
1091 input_sync(ts->input);
1092 input_report_key(ts->input,
1094 input_sync(ts->input);
1096 } else if (temp_x <= temp_y) {
1097 if ((key_y[key_count - 1] - key_y[0]) > 100) {
1098 printk(" send left key \n");
1099 input_report_key(ts->input,
1101 input_sync(ts->input);
1102 input_report_key(ts->input,
1104 input_sync(ts->input);
1105 } else if ((key_y[0] - key_y[key_count - 1]) >
1107 printk(" send right key \n");
1108 input_report_key(ts->input,
1110 input_sync(ts->input);
1111 input_report_key(ts->input,
1113 input_sync(ts->input);
1116 /*printk(" key_x[key_count -1], key_x[0],
1117 key_y[key_count -1], key_y[0] is %d ,%d , %d , %d\n",
1118 key_x[key_count -1], key_x[0], key_y[key_count -1],
1120 if ((key_x[key_count - 1] - key_x[0] < 50)
1121 && (key_x[key_count - 1] - key_x[0] >= -50)
1122 && (key_y[key_count - 1] - key_y[0] < 50)
1123 && (key_y[key_count - 1] - key_y[0] >= -50)
1124 && (key_x[0] != 0) && (key_y[0] != 0)) {
1125 //queue_work(gsl_timer_workqueue,&ts->click_work);
1126 //printk(" send enter2 key by yuandan \n");
1129 printk(" send enter key \n");
1130 input_report_key(ts->input, key_array[4], 1);
1131 input_sync(ts->input);
1132 input_report_key(ts->input, key_array[4], 0);
1133 input_sync(ts->input);
1141 } else if (key_count > 512) {
1142 if (temp_x > temp_y) {
1143 if ((key_x[511] - key_x[0]) > 100) {
1144 printk(" send up key \n");
1145 input_report_key(ts->input,
1147 input_sync(ts->input);
1148 input_report_key(ts->input,
1150 input_sync(ts->input);
1151 } else if ((key_x[0] - key_x[511]) > 100) {
1152 printk(" send down key \n");
1153 input_report_key(ts->input,
1155 input_sync(ts->input);
1156 input_report_key(ts->input,
1158 input_sync(ts->input);
1160 } else if (temp_x <= temp_y) {
1162 if ((key_y[511] - key_y[0]) > 100) {
1163 printk(" send left key \n");
1164 input_report_key(ts->input,
1166 input_sync(ts->input);
1167 input_report_key(ts->input,
1169 input_sync(ts->input);
1170 } else if ((key_y[0] - key_y[511]) > 100) {
1171 printk(" send right key \n");
1172 input_report_key(ts->input,
1174 input_sync(ts->input);
1175 input_report_key(ts->input,
1177 input_sync(ts->input);
1181 memset(key_y, 0, sizeof(int) * 512);
1182 memset(key_x, 0, sizeof(int) * 512);
1186 #ifdef HAVE_TOUCH_KEY
1187 if (key_state_flag) {
1188 input_report_key(ts->input, key, 0);
1189 input_sync(ts->input);
1196 input_sync(ts->input);
1203 glsx680_ts_irq_enable(ts);
1207 #ifdef HAVE_CLICK_TIMER
1209 static void click_timer_worker(struct work_struct *work)
1222 static void gsl_monitor_worker(struct work_struct *work)
1224 //u8 write_buf[4] = {0};
1225 u8 read_buf[4] = { 0 };
1226 char init_chip_flag = 0;
1228 //print_info("gsl_monitor_worker\n");
1230 container_of(work, struct gsl_ts, gsl_monitor_work.work);
1231 if (i2c_lock_flag != 0) {
1234 //goto queue_monitor_work;
1238 //gsl_ts_read(ts->client, 0x80, read_buf, 4);
1239 /*printk("======read 0x80: %x %x %x %x ======tony0geshu\n",
1240 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1242 gsl_ts_read(ts->client, 0xb0, read_buf, 4);
1243 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a
1244 || read_buf[0] != 0x5a)
1249 if (b0_counter > 1) {
1250 /*printk("======read 0xb0: %x %x %x %x ======\n",
1251 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1256 gsl_ts_read(ts->client, 0xb4, read_buf, 4);
1257 int_2nd[3] = int_1st[3];
1258 int_2nd[2] = int_1st[2];
1259 int_2nd[1] = int_1st[1];
1260 int_2nd[0] = int_1st[0];
1261 int_1st[3] = read_buf[3];
1262 int_1st[2] = read_buf[2];
1263 int_1st[1] = read_buf[1];
1264 int_1st[0] = read_buf[0];
1266 /*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1267 int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1268 int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1270 if (int_1st[3] == int_2nd[3] && int_1st[2] == int_2nd[2]
1271 && int_1st[1] == int_2nd[1] && int_1st[0] == int_2nd[0]) {
1272 /*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1273 int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1274 int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1276 //goto queue_monitor_init_chip;
1279 gsl_ts_read(ts->client, 0xbc, read_buf, 4);
1280 if (read_buf[3] != 0 || read_buf[2] != 0 || read_buf[1] != 0
1281 || read_buf[0] != 0)
1285 if (bc_counter > 1) {
1286 /*printk("======read 0xbc: %x %x %x %x======\n",
1287 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1293 write_buf[3] = 0x01;
1294 write_buf[2] = 0xfe;
1295 write_buf[1] = 0x10;
1296 write_buf[0] = 0x00;
1297 gsl_ts_write(ts->client, 0xf0, write_buf, 4);
1298 gsl_ts_read(ts->client, 0x10, read_buf, 4);
1299 gsl_ts_read(ts->client, 0x10, read_buf, 4);
1304 && read_buf[0] < 10)
1311 printk("read DAC1_0: %x %x %x %x\n",
1312 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
1317 //queue_monitor_init_chip:
1319 init_chip(ts->client, ts);
1323 //queue_monitor_work:
1324 //queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 100);
1328 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
1330 ///struct gsl_ts *ts = dev_id;
1331 struct gsl_ts *ts = (struct gsl_ts *)dev_id;
1332 //print_info("========gslX680 Interrupt=========\n");
1334 glsx680_ts_irq_disable(ts);
1336 if (!work_pending(&ts->work)) {
1337 queue_work(ts->wq, &ts->work);
1344 static int gslX680_ts_init(struct i2c_client *client, struct gsl_ts *ts)
1346 struct input_dev *input_device;
1350 printk("[GSLX680] Enter %s\n", __func__);
1352 ts->dd = &devices[ts->device_id];
1354 if (ts->device_id == 0) {
1356 MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
1357 ts->dd->touch_index = 0;
1361 devm_kzalloc(&client->dev, ts->dd->data_size, GFP_KERNEL);
1362 if (!ts->touch_data) {
1363 pr_err("%s: Unable to allocate memory\n", __func__);
1367 input_device = devm_input_allocate_device(&ts->client->dev);
1368 if (!input_device) {
1373 ts->input = input_device;
1374 input_device->name = GSLX680_I2C_NAME;
1375 input_device->id.bustype = BUS_I2C;
1376 input_device->dev.parent = &client->dev;
1377 input_set_drvdata(input_device, ts);
1379 #ifdef REPORT_DATA_ANDROID_4_0
1380 __set_bit(EV_ABS, input_device->evbit);
1381 __set_bit(EV_KEY, input_device->evbit);
1382 __set_bit(EV_REP, input_device->evbit);
1383 __set_bit(EV_SYN, input_device->evbit);
1384 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1385 __set_bit(MT_TOOL_FINGER, input_device->keybit);
1386 input_mt_init_slots(input_device, (MAX_CONTACTS + 1), 0);
1388 input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0,
1389 (MAX_CONTACTS + 1), 0, 0);
1390 set_bit(EV_ABS, input_device->evbit);
1391 set_bit(EV_KEY, input_device->evbit);
1392 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1393 input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1396 #ifdef HAVE_TOUCH_KEY
1397 input_device->evbit[0] = BIT_MASK(EV_KEY);
1398 /*input_device->evbit[0] = BIT_MASK(EV_SYN)
1399 | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);*/
1400 for (i = 0; i < MAX_KEY_NUM; i++)
1401 set_bit(key_array[i], input_device->keybit);
1404 #ifdef RK_GEAR_TOUCH
1405 set_bit(EV_REL, input_device->evbit);
1406 input_set_capability(input_device, EV_REL, REL_X);
1407 input_set_capability(input_device, EV_REL, REL_Y);
1408 input_set_capability(input_device, EV_MSC, MSC_SCAN);
1409 input_set_capability(input_device, EV_KEY, 0x110);
1412 set_bit(ABS_MT_POSITION_X, input_device->absbit);
1413 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
1414 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
1415 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
1417 input_set_abs_params(input_device, ABS_MT_POSITION_X, 0, SCREEN_MAX_X,
1419 input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y,
1421 input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0,
1423 input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
1425 //client->irq = IRQ_PORT;
1426 //ts->irq = client->irq;
1428 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
1430 dev_err(&client->dev, "gsl Could not create workqueue\n");
1433 flush_workqueue(ts->wq);
1435 INIT_WORK(&ts->work, gslX680_ts_worker);
1437 rc = input_register_device(input_device);
1439 goto error_unreg_device;
1444 destroy_workqueue(ts->wq);
1450 static int gsl_ts_suspend(struct i2c_client *dev, pm_message_t mesg)
1453 struct gsl_ts *ts = dev_get_drvdata(dev);
1455 printk("I'am in gsl_ts_suspend() start\n");
1458 printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1459 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1462 #ifdef HAVE_CLICK_TIMER
1463 //cancel_work_sync(&ts->click_work);
1465 disable_irq_nosync(ts->irq);
1467 gslX680_shutdown_low(ts);
1469 #ifdef SLEEP_CLEAR_POINT
1471 #ifdef REPORT_DATA_ANDROID_4_0
1472 for (i = 1; i <= MAX_CONTACTS; i++) {
1473 input_mt_slot(ts->input, i);
1474 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1475 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1478 input_mt_sync(ts->input);
1480 input_sync(ts->input);
1482 report_data(ts, 1, 1, 10, 1);
1483 input_sync(ts->input);
1492 static int gsl_ts_resume(struct i2c_client *dev)
1495 struct gsl_ts *ts = dev_get_drvdata(dev);
1497 printk("I'am in gsl_ts_resume() start\n");
1499 gslX680_shutdown_high(ts);
1501 reset_chip(ts->client);
1502 startup_chip(ts->client);
1503 check_mem_data(ts->client, ts);
1505 #ifdef SLEEP_CLEAR_POINT
1506 #ifdef REPORT_DATA_ANDROID_4_0
1507 for (i = 1; i <= MAX_CONTACTS; i++) {
1508 input_mt_slot(ts->input, i);
1509 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1510 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1513 input_mt_sync(ts->input);
1515 input_sync(ts->input);
1518 printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1519 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1522 #ifdef HAVE_CLICK_TIMER
1523 //queue_work(gsl_timer_workqueue,&ts->click_work);
1526 disable_irq_nosync(ts->irq);
1527 enable_irq(ts->irq);
1534 static int gsl_ts_early_suspend(struct tp_device *tp_d)
1536 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1537 printk("[GSLX680] Enter %s\n", __func__);
1538 //gsl_ts_suspend(&ts->client->dev);
1540 printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1541 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1544 glsx680_ts_irq_disable(ts);
1545 cancel_work_sync(&ts->work);
1547 #ifdef SLEEP_CLEAR_POINT
1549 #ifdef REPORT_DATA_ANDROID_4_0
1550 for (i = 1; i <= MAX_CONTACTS; i++) {
1551 input_mt_slot(ts->input, i);
1552 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1553 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1556 input_mt_sync(ts->input);
1558 input_sync(ts->input);
1560 report_data(ts, 1, 1, 10, 1);
1561 input_sync(ts->input);
1563 gslX680_shutdown_low(ts);
1567 static int gsl_ts_late_resume(struct tp_device *tp_d)
1569 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1570 printk("[GSLX680] Enter %s\n", __func__);
1571 //gsl_ts_resume(&ts->client->dev);
1573 printk("I'am in gsl_ts_resume() start\n");
1575 gslX680_shutdown_high(ts);
1577 reset_chip(ts->client);
1578 startup_chip(ts->client);
1579 check_mem_data(ts->client, ts);
1581 #ifdef SLEEP_CLEAR_POINT
1582 #ifdef REPORT_DATA_ANDROID_4_0
1583 for (i = 1; i <= MAX_CONTACTS; i++) {
1584 input_mt_slot(ts->input, i);
1585 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1586 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1589 input_mt_sync(ts->input);
1591 input_sync(ts->input);
1594 printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1595 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1597 glsx680_ts_irq_enable(ts);
1602 #ifdef CONFIG_HAS_EARLYSUSPEND
1604 static void gsl_ts_early_suspend(struct early_suspend *h)
1606 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1607 printk("[GSLX680] Enter %s\n", __func__);
1608 //gsl_ts_suspend(&ts->client->dev);
1610 printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1611 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1614 glsx680_ts_irq_disable(ts);
1615 cancel_work_sync(&ts->work);
1617 #ifdef SLEEP_CLEAR_POINT
1619 #ifdef REPORT_DATA_ANDROID_4_0
1620 for (i = 1; i <= MAX_CONTACTS; i++) {
1621 input_mt_slot(ts->input, i);
1622 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1623 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1626 input_mt_sync(ts->input);
1628 input_sync(ts->input);
1630 report_data(ts, 1, 1, 10, 1);
1631 input_sync(ts->input);
1633 gslX680_shutdown_low(ts);
1637 static void gsl_ts_late_resume(struct early_suspend *h)
1639 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1640 printk("[GSLX680] Enter %s\n", __func__);
1641 //gsl_ts_resume(&ts->client->dev);
1644 printk("I'am in gsl_ts_resume() start\n");
1646 gslX680_shutdown_high(ts);
1648 reset_chip(ts->client);
1649 startup_chip(ts->client);
1650 check_mem_data(ts->client, ts);
1652 #ifdef SLEEP_CLEAR_POINT
1653 #ifdef REPORT_DATA_ANDROID_4_0
1654 for (i = 1; i <= MAX_CONTACTS; i++) {
1655 input_mt_slot(ts->input, i);
1656 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1657 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1660 input_mt_sync(ts->input);
1662 input_sync(ts->input);
1665 printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1666 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1668 glsx680_ts_irq_enable(ts);
1673 //static struct wake_lock touch_wakelock;
1675 static int gsl_ts_probe(struct i2c_client *client,
1676 const struct i2c_device_id *id)
1681 printk("GSLX680 Enter %s\n", __func__);
1682 //wake_lock_init(&touch_wakelock, WAKE_LOCK_SUSPEND, "touch");
1683 //wake_lock(&touch_wakelock); //system do not enter deep sleep
1684 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1685 dev_err(&client->dev, "gsl I2C functionality not supported\n");
1689 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
1693 ts->tp.tp_suspend = gsl_ts_early_suspend;
1694 ts->tp.tp_resume = gsl_ts_late_resume;
1695 tp_register_fb(&ts->tp);
1697 ts->client = client;
1698 i2c_set_clientdata(client, ts);
1699 //ts->device_id = id->driver_data;
1702 rc = gslX680_ts_init(client, ts);
1704 dev_err(&client->dev, "gsl GSLX680 init failed\n");
1707 //#ifdef GSLX680_COMPATIBLE
1708 // judge_chip_type(client);
1710 //printk("##################### probe [2]chip_type=%c .\n",chip_type);
1711 init_chip(ts->client, ts);
1712 check_mem_data(ts->client, ts);
1713 spin_lock_init(&ts->irq_lock);
1714 client->irq = gpio_to_irq(ts->irq);
1715 rc = request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING,
1718 printk("gsl_probe: request irq failed\n");
1722 /* create debug attribute */
1723 //rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable);
1725 #ifdef CONFIG_HAS_EARLYSUSPEND
1727 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1728 //ts->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1;
1729 ts->early_suspend.suspend = gsl_ts_early_suspend;
1730 ts->early_suspend.resume = gsl_ts_late_resume;
1731 register_early_suspend(&ts->early_suspend);
1736 INIT_DELAYED_WORK(&ts->gsl_monitor_work, gsl_monitor_worker);
1737 gsl_monitor_workqueue =
1738 create_singlethread_workqueue("gsl_monitor_workqueue");
1739 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 1000);
1742 #ifdef HAVE_CLICK_TIMER
1743 sema_init(&my_sem, 1);
1744 INIT_WORK(&ts->click_work, click_timer_worker);
1745 gsl_timer_workqueue = create_singlethread_workqueue("click_timer");
1746 queue_work(gsl_timer_workqueue, &ts->click_work);
1749 #ifdef TPD_PROC_DEBUG
1751 gsl_config_proc = create_proc_entry(GSL_CONFIG_PROC_FILE, 0666, NULL);
1752 printk("[tp-gsl] [%s] gsl_config_proc = %x \n", __func__,
1754 if (gsl_config_proc == NULL) {
1755 print_info("create_proc_entry %s failed\n",
1756 GSL_CONFIG_PROC_FILE);
1758 gsl_config_proc->read_proc = gsl_config_read_proc;
1759 gsl_config_proc->write_proc = gsl_config_write_proc;
1762 i2c_client = client;
1763 proc_create(GSL_CONFIG_PROC_FILE, 0666, NULL, &gsl_seq_fops);
1767 //disable_irq_nosync(->irq);
1768 printk("[GSLX680] End %s\n", __func__);
1776 static int gsl_ts_remove(struct i2c_client *client)
1778 struct gsl_ts *ts = i2c_get_clientdata(client);
1780 #ifdef CONFIG_HAS_EARLYSUSPEND
1781 unregister_early_suspend(&ts->early_suspend);
1785 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1786 destroy_workqueue(gsl_monitor_workqueue);
1789 #ifdef HAVE_CLICK_TIMER
1790 cancel_work_sync(&ts->click_work);
1791 destroy_workqueue(gsl_timer_workqueue);
1794 device_init_wakeup(&client->dev, 0);
1795 cancel_work_sync(&ts->work);
1796 free_irq(ts->client->irq, ts);
1797 destroy_workqueue(ts->wq);
1798 //device_remove_file(&ts->input->dev, &dev_attr_debug_enable);
1803 static struct of_device_id gsl_ts_ids[] = {
1804 {.compatible = "gslX680"},
1808 static const struct i2c_device_id gsl_ts_id[] = {
1809 {GSLX680_I2C_NAME, 0},
1813 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1815 static struct i2c_driver gsl_ts_driver = {
1817 .name = GSLX680_I2C_NAME,
1818 .owner = THIS_MODULE,
1819 .of_match_table = of_match_ptr(gsl_ts_ids),
1821 #if 0 //ndef CONFIG_HAS_EARLYSUSPEND
1822 .suspend = gsl_ts_suspend,
1823 .resume = gsl_ts_resume,
1825 .probe = gsl_ts_probe,
1826 .remove = gsl_ts_remove,
1827 .id_table = gsl_ts_id,
1830 static int __init gsl_ts_init(void)
1833 ret = i2c_add_driver(&gsl_ts_driver);
1836 static void __exit gsl_ts_exit(void)
1838 i2c_del_driver(&gsl_ts_driver);
1842 module_init(gsl_ts_init);
1843 module_exit(gsl_ts_exit);
1845 MODULE_LICENSE("GPL");
1846 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1847 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1848 MODULE_ALIAS("platform:gsl_ts");