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>
44 //#define RK_GEAR_TOUCH
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;
185 struct delayed_work gsl_monitor_work;
186 #if defined(CONFIG_HAS_EARLYSUSPEND)
187 struct early_suspend early_suspend;
190 #if defined (HAVE_CLICK_TIMER)
191 struct work_struct click_work;
195 struct pinctrl *pinctrl;
196 struct pinctrl_state *pins_default;
197 struct pinctrl_state *pins_sleep;
198 struct pinctrl_state *pins_inactive;
202 #define print_info(fmt, args...) printk(fmt, ##args);
204 #define print_info(fmt, args...)
207 static u32 id_sign[MAX_CONTACTS + 1] = { 0 };
208 static u8 id_state_flag[MAX_CONTACTS + 1] = { 0 };
209 static u8 id_state_old_flag[MAX_CONTACTS + 1] = { 0 };
210 static u16 x_old[MAX_CONTACTS + 1] = { 0 };
211 static u16 y_old[MAX_CONTACTS + 1] = { 0 };
212 static u16 x_new = 0;
213 static u16 y_new = 0;
215 int gslx680_set_pinctrl_state(struct gsl_ts *ts, struct pinctrl_state *state)
219 if (!IS_ERR(state)) {
220 ret = pinctrl_select_state(ts->pinctrl, state);
222 printk("could not set pins \n");
228 static int gslX680_init(struct gsl_ts *ts)
230 struct device_node *np = ts->client->dev.of_node;
234 ts->irq = of_get_named_gpio_flags(np, "touch-gpio", 0, NULL);
235 ts->rst = of_get_named_gpio_flags(np, "reset-gpio", 0, NULL);
238 #if 0 //#if defined (CONFIG_BOARD_ZM71C)||defined (CONFIG_BOARD_ZM72CP) ||
239 defined(CONFIG_BOARD_ZM726C) || defined(CONFIG_BOARD_ZM726CE)
240 if (gpio_request(ts->rst, NULL) != 0) {
242 printk("gslX680_init gpio_request error\n");
248 ts->pinctrl = devm_pinctrl_get(&ts->client->dev);
249 if (IS_ERR(ts->pinctrl)) {
250 ret = PTR_ERR(ts->pinctrl);
255 pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_DEFAULT);
256 //if (IS_ERR(ts->pins_default))
257 // dev_err(&client->dev, "could not get default pinstate\n");
259 ts->pins_sleep = pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_SLEEP);
260 //if (IS_ERR(ts->pins_sleep))
261 // dev_err(&client->dev, "could not get sleep pinstate\n");
263 ts->pins_inactive = pinctrl_lookup_state(ts->pinctrl, "inactive");
264 //if (IS_ERR(ts->pins_inactive))
265 // dev_err(&client->dev, "could not get inactive pinstate\n");
267 err = gpio_request(ts->rst, "tp reset");
269 printk("gslx680 reset gpio request failed.\n");
273 gslx680_set_pinctrl_state(ts, ts->pins_default);
274 gpio_direction_output(ts->rst, 1);
275 gpio_set_value(ts->rst, 1);
280 static int gslX680_shutdown_low(struct gsl_ts *ts)
282 printk("gsl gslX680_shutdown_low\n");
283 gpio_direction_output(ts->rst, 0);
284 gpio_set_value(ts->rst, 0);
289 static int gslX680_shutdown_high(struct gsl_ts *ts)
291 printk("gsl gslX680_shutdown_high\n");
292 gpio_direction_output(ts->rst, 1);
293 gpio_set_value(ts->rst, 1);
298 static inline u16 join_bytes(u8 a, u8 b)
309 static u32 gsl_read_interface(struct i2c_client *client,
310 u8 reg, u8 *buf, u32 num)
312 struct i2c_msg xfer_msg[2];
314 xfer_msg[0].addr = client->addr;
316 xfer_msg[0].flags = client->flags & I2C_M_TEN;
317 xfer_msg[0].buf = ®
318 xfer_msg[0].scl_rate=300*1000;
320 xfer_msg[1].addr = client->addr;
321 xfer_msg[1].len = num;
322 xfer_msg[1].flags |= I2C_M_RD;
323 xfer_msg[1].buf = buf;
324 xfer_msg[1].scl_rate=300*1000;
327 i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
331 return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) \
332 == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
336 static u32 gsl_write_interface(struct i2c_client *client,
337 const u8 reg, u8 *buf, u32 num)
339 struct i2c_msg xfer_msg[1];
343 xfer_msg[0].addr = client->addr;
344 xfer_msg[0].len = num + 1;
345 xfer_msg[0].flags = client->flags & I2C_M_TEN;
346 xfer_msg[0].buf = buf;
347 //xfer_msg[0].scl_rate = 100 * 1000;
349 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
352 static int gsl_ts_write(struct i2c_client *client,
353 u8 addr, u8 *pdata, int datalen)
357 unsigned int bytelen = 0;
360 printk("%s too big datalen = %d!\n", __func__, datalen);
367 if (datalen != 0 && pdata != NULL) {
368 memcpy(&tmp_buf[bytelen], pdata, datalen);
372 ret = i2c_master_send(client, tmp_buf, bytelen);
376 static int gsl_ts_read(struct i2c_client *client, u8 addr,
377 u8 *pdata, unsigned int datalen)
382 printk("%s too big datalen = %d!\n", __func__, datalen);
386 ret = gsl_ts_write(client, addr, NULL, 0);
388 printk("%s set data address fail!\n", __func__);
392 return i2c_master_recv(client, pdata, datalen);
395 static __inline__ void fw2buf(u8 *buf, const u32 *fw)
397 u32 *u32_buf = (int *)buf;
401 static void gsl_load_fw(struct i2c_client *client)
403 u8 buf[DMA_TRANS_LEN * 4 + 1] = { 0 };
408 //u8 read_buf[4] = {0};
409 struct fw_data const *ptr_fw;
412 source_len = ARRAY_SIZE(GSLX680_FW);
414 for (source_line = 0; source_line < source_len; source_line++) {
415 /* init page trans, set the page val */
416 if (GSL_PAGE_REG == ptr_fw[source_line].offset) {
417 fw2buf(cur, &ptr_fw[source_line].val);
418 gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
422 send_flag % (DMA_TRANS_LEN <
423 0x20 ? DMA_TRANS_LEN : 0x20))
424 buf[0] = (u8) ptr_fw[source_line].offset;
426 fw2buf(cur, &ptr_fw[source_line].val);
430 send_flag % (DMA_TRANS_LEN <
431 0x20 ? DMA_TRANS_LEN : 0x20)) {
432 gsl_write_interface(client, buf[0], buf,
442 static int test_i2c(struct i2c_client *client)
448 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
452 printk("gsl I read reg 0xf0 is %x\n", read_buf);
455 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
457 printk("gsl I write reg 0xf0 0x12\n");
460 ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
464 printk("gsl I read reg 0xf0 is 0x%x\n", read_buf);
468 static void startup_chip(struct i2c_client *client)
472 printk("gsl startup_chip\n");
474 #ifdef GSL_NOID_VERSION
475 gsl_DataInit(gsl_config_data_id);
477 gsl_ts_write(client, 0xe0, &tmp, 1);
481 static void reset_chip(struct i2c_client *client)
484 u8 buf[4] = { 0x00 };
486 printk("gsl reset_chip\n");
488 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
491 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
493 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
497 static void clr_reg(struct i2c_client *client)
499 u8 write_buf[4] = { 0 };
502 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
505 gsl_ts_write(client, 0x80, &write_buf[0], 1);
508 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
511 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
515 static void init_chip(struct i2c_client *client, struct gsl_ts *ts)
519 printk("gsl init_chip\n");
521 gslX680_shutdown_low(ts);
523 gslX680_shutdown_high(ts);
525 rc = test_i2c(client);
527 printk("gslX680 test_i2c error\n");
533 startup_chip(client);
535 startup_chip(client);
538 static void check_mem_data(struct i2c_client *client, struct gsl_ts *ts)
540 u8 read_buf[4] = { 0 };
543 gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf));
544 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a ||
545 read_buf[1] != 0x5a || read_buf[0] != 0x5a) {
546 init_chip(client, ts);
550 #ifdef TPD_PROC_DEBUG
551 static int char_to_int(char ch)
553 if (ch >= '0' && ch <= '9')
556 return (ch - 'a' + 10);
559 static int gsl_config_read_proc(struct seq_file *m, void *v)
562 char temp_data[5] = { 0 };
563 unsigned int tmp = 0;
564 //unsigned int *ptr_fw;
566 if ('v' == gsl_read[0] && 's' == gsl_read[1]) {
567 #ifdef GSL_NOID_VERSION
568 tmp = gsl_version_id();
572 seq_printf(m, "version:%x\n", tmp);
573 } else if ('r' == gsl_read[0] && 'e' == gsl_read[1]) {
574 if ('i' == gsl_read[3]) {
575 #ifdef GSL_NOID_VERSION
576 /* tmp=(gsl_data_proc[5]<<8) | gsl_data_proc[4];
577 seq_printf(m,"gsl_config_data_id[%d] = ",tmp);
578 if(tmp>=0&&tmp<gsl_cfg_table[gsl_cfg_index].data_size)
579 seq_printf(m,"%d\n",gsl_cfg_table[gsl_cfg_index].data_id[tmp]); */
581 tmp = (gsl_data_proc[5] << 8) | gsl_data_proc[4];
582 seq_printf(m, "gsl_config_data_id[%d] = ", tmp);
583 if (tmp >= 0 && tmp < 512)
584 seq_printf(m, "%d\n", gsl_config_data_id[tmp]);
587 i2c_smbus_write_i2c_block_data(i2c_client, 0xf0, 4,
589 if (gsl_data_proc[0] < 0x80)
590 i2c_smbus_read_i2c_block_data(i2c_client,
593 i2c_smbus_read_i2c_block_data(i2c_client,
597 seq_printf(m, "offset : {0x%02x,0x", gsl_data_proc[0]);
598 seq_printf(m, "%02x", temp_data[3]);
599 seq_printf(m, "%02x", temp_data[2]);
600 seq_printf(m, "%02x", temp_data[1]);
601 seq_printf(m, "%02x};\n", temp_data[0]);
606 static ssize_t gsl_config_write_proc(struct file *file, const char *buffer,
607 size_t count, loff_t *data)
610 char temp_buf[CONFIG_LEN];
615 print_info("[tp-gsl][%s] \n", __func__);
617 //print_info("size not match [%d:%d]\n", CONFIG_LEN, count);
620 path_buf = kzalloc(count, GFP_KERNEL);
622 printk("alloc path_buf memory error \n");
624 if (copy_from_user(path_buf, buffer, count)) {
625 print_info("copy from user fail\n");
626 goto exit_write_proc_out;
628 memcpy(temp_buf, path_buf, (count < CONFIG_LEN ? count : CONFIG_LEN));
629 print_info("[tp-gsl][%s][%s]\n", __func__, temp_buf);
631 buf[3] = char_to_int(temp_buf[14]) << 4 | char_to_int(temp_buf[15]);
632 buf[2] = char_to_int(temp_buf[16]) << 4 | char_to_int(temp_buf[17]);
633 buf[1] = char_to_int(temp_buf[18]) << 4 | char_to_int(temp_buf[19]);
634 buf[0] = char_to_int(temp_buf[20]) << 4 | char_to_int(temp_buf[21]);
636 buf[7] = char_to_int(temp_buf[5]) << 4 | char_to_int(temp_buf[6]);
637 buf[6] = char_to_int(temp_buf[7]) << 4 | char_to_int(temp_buf[8]);
638 buf[5] = char_to_int(temp_buf[9]) << 4 | char_to_int(temp_buf[10]);
639 buf[4] = char_to_int(temp_buf[11]) << 4 | char_to_int(temp_buf[12]);
640 if ('v' == temp_buf[0] && 's' == temp_buf[1]) {
642 memcpy(gsl_read, temp_buf, 4);
643 printk("gsl version\n");
644 } else if ('s' == temp_buf[0] && 't' == temp_buf[1]) {
647 reset_chip(i2c_client);
648 } else if ('e' == temp_buf[0] && 'n' == temp_buf[1]) {
651 reset_chip(i2c_client);
652 startup_chip(i2c_client);
654 } else if ('r' == temp_buf[0] && 'e' == temp_buf[1]) {
656 memcpy(gsl_read, temp_buf, 4);
657 memcpy(gsl_data_proc, buf, 8);
658 } else if ('w' == temp_buf[0] && 'r' == temp_buf[1]) {
660 i2c_smbus_write_i2c_block_data(i2c_client, buf[4], 4, buf);
662 #ifdef GSL_NOID_VERSION
663 else if ('i' == temp_buf[0] && 'd' == temp_buf[1]) {
665 tmp1 = (buf[7] << 24) | (buf[6] << 16) | (buf[5] << 8) | buf[4];
666 tmp = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
668 if (tmp1 >= 0 && tmp1 < 512) {
669 gsl_config_data_id[tmp1] = tmp;
678 static int gsl_server_list_open(struct inode *inode, struct file *file)
680 return single_open(file, gsl_config_read_proc, NULL);
682 static const struct file_operations gsl_seq_fops = {
683 .open = gsl_server_list_open,
685 .release = single_release,
686 .write = gsl_config_write_proc,
687 .owner = THIS_MODULE,
693 static void filter_point(u16 x, u16 y, u8 id)
697 u16 filter_step_x = 0, filter_step_y = 0;
699 id_sign[id] = id_sign[id] + 1;
700 if (id_sign[id] == 1) {
705 x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x);
706 y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y);
708 if ((x_err > FILTER_MAX && y_err > FILTER_MAX / 3) ||
709 (x_err > FILTER_MAX / 3 && y_err > FILTER_MAX)) {
710 filter_step_x = x_err;
711 filter_step_y = y_err;
713 if (x_err > FILTER_MAX)
714 filter_step_x = x_err;
715 if (y_err > FILTER_MAX)
716 filter_step_y = y_err;
719 if (x_err <= 2 * FILTER_MAX && y_err <= 2 * FILTER_MAX) {
722 } else if (x_err <= 3 * FILTER_MAX && y_err <= 3 * FILTER_MAX) {
725 } else if (x_err <= 4 * FILTER_MAX && y_err <= 4 * FILTER_MAX) {
726 filter_step_x = filter_step_x * 3 / 4;
727 filter_step_y = filter_step_y * 3 / 4;
732 x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] -
736 y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] -
743 static void record_point(u16 x, u16 y, u8 id)
748 id_sign[id] = id_sign[id] + 1;
750 if (id_sign[id] == 1) {
755 x = (x_old[id] + x) / 2;
756 y = (y_old[id] + y) / 2;
759 x_err = x - x_old[id];
761 x_err = x_old[id] - x;
765 y_err = y - y_old[id];
767 y_err = y_old[id] - y;
770 if ((x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3)) {
791 if (id_sign[id] == 1) {
799 #ifdef SLEEP_CLEAR_POINT
800 #ifdef HAVE_TOUCH_KEY
801 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
805 for (i = 0; i < MAX_KEY_NUM; i++) {
806 if ((gsl_key_data[i].x_min < x)
807 && (x < gsl_key_data[i].x_max)
808 && (gsl_key_data[i].y_min < y)
809 && (y < gsl_key_data[i].y_max)) {
810 key = gsl_key_data[i].key;
811 input_report_key(ts->input, key, 1);
812 input_sync(ts->input);
822 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
826 static int old_x=0, old_y=0;
831 //printk("#####id=%d,x=%d,y=%d######\n",id,x,y);
833 if (x > SCREEN_MAX_X || y > SCREEN_MAX_Y) {
834 #ifdef HAVE_TOUCH_KEY
835 //report_key(ts, x, y);
836 //printk("#####report_key x=%d,y=%d######\n",x,y);
842 input_mt_slot(ts->input_dev, id);
843 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
844 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
845 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
846 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
847 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
852 input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
853 input_report_key(ts->input, 0x110, 1);
854 input_sync(ts->input);
856 delt_x = (int)x - old_x;
857 delt_y = (int)y - old_y;
860 input_report_rel(ts->input, REL_Y, -delt_x);
861 input_report_rel(ts->input, REL_X, -delt_y);
862 input_sync(ts->input);
868 #ifdef REPORT_DATA_ANDROID_4_0
869 //printk("#####REPORT_DATA_ANDROID_4_0######\n");
870 input_mt_slot(ts->input, id);
871 //input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
872 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 1);
873 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
875 input_report_abs(ts->input, ABS_MT_POSITION_X, SCREEN_MAX_X - x);
877 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
880 input_report_abs(ts->input, ABS_MT_POSITION_Y, (SCREEN_MAX_Y - y));
882 input_report_abs(ts->input, ABS_MT_POSITION_Y, (y));
884 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
886 //printk("#####nonono REPORT_DATA_ANDROID_4_0######\n");
887 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
888 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
889 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
890 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
891 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
892 input_mt_sync(ts->input);
897 static void gslX680_ts_worker(struct work_struct *work)
903 #ifdef GSL_NOID_VERSION
906 struct gsl_touch_info cinfo;
909 struct gsl_ts *ts = container_of(work, struct gsl_ts, work);
911 #ifdef TPD_PROC_DEBUG
912 if (gsl_proc_flag == 1)
917 if (i2c_lock_flag != 0)
918 goto i2c_lock_schedule;
923 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
925 dev_err(&ts->client->dev, "read failed\n");
929 touches = ts->touch_data[ts->dd->touch_index];
930 //print_info("-----touches: %d -----\n", touches);
931 #ifdef GSL_NOID_VERSION
933 cinfo.finger_num = touches;
934 //print_info("tp-gsl finger_num = %d\n",cinfo.finger_num);
935 for (i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i++) {
938 touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
939 ts->touch_data[ts->dd->x_index + 4 * i]);
941 join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
942 ts->touch_data[ts->dd->y_index + 4 * i]);
944 ((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf0) >> 4);
945 /*print_info("tp-gsl before: x[%d] = %d, y[%d] = %d,
946 id[%d] = %d \n",i,cinfo.x[i],i,cinfo.y[i],i,cinfo.id[i]);*/
948 cinfo.finger_num = (ts->touch_data[3] << 24) | (ts->touch_data[2] << 16)
949 | (ts->touch_data[1] << 8) | (ts->touch_data[0]);
950 gsl_alg_id_main(&cinfo);
951 tmp1 = gsl_mask_tiaoping();
952 //print_info("[tp-gsl] tmp1 = %x\n", tmp1);
953 if (tmp1 > 0 && tmp1 < 0xffffffff) {
958 gsl_ts_write(ts->client, 0xf0, buf, 4);
959 buf[0] = (u8) (tmp1 & 0xff);
960 buf[1] = (u8) ((tmp1 >> 8) & 0xff);
961 buf[2] = (u8) ((tmp1 >> 16) & 0xff);
962 buf[3] = (u8) ((tmp1 >> 24) & 0xff);
963 print_info("tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x, \
964 buf[3]=%02x\n", tmp1, buf[0], buf[1], buf[2], buf[3]);
965 gsl_ts_write(ts->client, 0x8, buf, 4);
967 touches = cinfo.finger_num;
970 for (i = 1; i <= MAX_CONTACTS; i++) {
973 id_state_flag[i] = 0;
975 for (i = 0; i < (touches > MAX_FINGERS ? MAX_FINGERS : touches); i++) {
976 #ifdef GSL_NOID_VERSION
982 touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
983 ts->touch_data[ts->dd->x_index + 4 * i]);
984 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
985 ts->touch_data[ts->dd->y_index + 4 * i]);
986 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
989 if (1 <= id && id <= MAX_CONTACTS) {
991 filter_point(x, y, id);
993 record_point(x, y, id);
996 report_data(ts, x_new, y_new, 10, id);
998 if (key_count <= 512) {
999 key_x[key_count] = x_new;
1000 key_y[key_count] = y_new;
1002 /*printk("test in key store in here,
1003 x_new is %d , y_new is %d ,
1004 key_count is %d \n", x_new ,y_new,key_count);*/
1006 id_state_flag[id] = 1;
1009 for (i = 1; i <= MAX_CONTACTS; i++) {
1011 || ((0 != id_state_old_flag[i])
1012 && (0 == id_state_flag[i]))) {
1013 #ifdef RK_GEAR_TOUCH
1014 if (g_istouch == 1){
1016 input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
1017 input_report_key(ts->input, 0x110, 0);
1018 input_sync(ts->input);
1022 #ifdef REPORT_DATA_ANDROID_4_0
1023 input_mt_slot(ts->input, i);
1024 //input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1025 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER,
1030 id_state_old_flag[i] = id_state_flag[i];
1034 #ifdef REPORT_DATA_ANDROID_4_0
1035 #ifndef RK_GEAR_TOUCH
1036 //input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, 0);
1037 //input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 0);
1038 //input_mt_sync(ts->input);
1043 (((key_x[key_count - 1] - key_x[0]) >
1044 0) ? (key_x[key_count - 1] - key_x[0])
1045 : (key_x[0] - key_x[key_count - 1]));
1047 (((key_y[key_count - 1] - key_y[0]) >
1048 0) ? (key_y[key_count - 1] - key_y[0])
1049 : (key_y[0] - key_y[key_count - 1]));
1050 if (key_count <= 512) {
1051 if (temp_x > temp_y) {
1052 if ((key_x[key_count - 1] - key_x[0]) > 100) {
1053 printk(" send up key \n");
1054 input_report_key(ts->input,
1056 input_sync(ts->input);
1057 input_report_key(ts->input,
1059 input_sync(ts->input);
1060 } else if ((key_x[0] - key_x[key_count - 1]) >
1062 printk(" send down key \n");
1063 input_report_key(ts->input,
1065 input_sync(ts->input);
1066 input_report_key(ts->input,
1068 input_sync(ts->input);
1070 } else if (temp_x <= temp_y) {
1071 if ((key_y[key_count - 1] - key_y[0]) > 100) {
1072 printk(" send left key \n");
1073 input_report_key(ts->input,
1075 input_sync(ts->input);
1076 input_report_key(ts->input,
1078 input_sync(ts->input);
1079 } else if ((key_y[0] - key_y[key_count - 1]) >
1081 printk(" send right key \n");
1082 input_report_key(ts->input,
1084 input_sync(ts->input);
1085 input_report_key(ts->input,
1087 input_sync(ts->input);
1090 /*printk(" key_x[key_count -1], key_x[0],
1091 key_y[key_count -1], key_y[0] is %d ,%d , %d , %d\n",
1092 key_x[key_count -1], key_x[0], key_y[key_count -1],
1094 if ((key_x[key_count - 1] - key_x[0] < 50)
1095 && (key_x[key_count - 1] - key_x[0] >= -50)
1096 && (key_y[key_count - 1] - key_y[0] < 50)
1097 && (key_y[key_count - 1] - key_y[0] >= -50)
1098 && (key_x[0] != 0) && (key_y[0] != 0)) {
1099 //queue_work(gsl_timer_workqueue,&ts->click_work);
1100 //printk(" send enter2 key by yuandan \n");
1103 printk(" send enter key \n");
1104 input_report_key(ts->input, key_array[4], 1);
1105 input_sync(ts->input);
1106 input_report_key(ts->input, key_array[4], 0);
1107 input_sync(ts->input);
1115 } else if (key_count > 512) {
1116 if (temp_x > temp_y) {
1117 if ((key_x[511] - key_x[0]) > 100) {
1118 printk(" send up key \n");
1119 input_report_key(ts->input,
1121 input_sync(ts->input);
1122 input_report_key(ts->input,
1124 input_sync(ts->input);
1125 } else if ((key_x[0] - key_x[511]) > 100) {
1126 printk(" send down key \n");
1127 input_report_key(ts->input,
1129 input_sync(ts->input);
1130 input_report_key(ts->input,
1132 input_sync(ts->input);
1134 } else if (temp_x <= temp_y) {
1136 if ((key_y[511] - key_y[0]) > 100) {
1137 printk(" send left key \n");
1138 input_report_key(ts->input,
1140 input_sync(ts->input);
1141 input_report_key(ts->input,
1143 input_sync(ts->input);
1144 } else if ((key_y[0] - key_y[511]) > 100) {
1145 printk(" send right key \n");
1146 input_report_key(ts->input,
1148 input_sync(ts->input);
1149 input_report_key(ts->input,
1151 input_sync(ts->input);
1155 memset(key_y, 0, sizeof(int) * 512);
1156 memset(key_x, 0, sizeof(int) * 512);
1160 #ifdef HAVE_TOUCH_KEY
1161 if (key_state_flag) {
1162 input_report_key(ts->input, key, 0);
1163 input_sync(ts->input);
1170 input_sync(ts->input);
1177 enable_irq(ts->irq);
1181 #ifdef HAVE_CLICK_TIMER
1183 static void click_timer_worker(struct work_struct *work)
1196 static void gsl_monitor_worker(struct work_struct *work)
1198 //u8 write_buf[4] = {0};
1199 u8 read_buf[4] = { 0 };
1200 char init_chip_flag = 0;
1202 //print_info("gsl_monitor_worker\n");
1204 container_of(work, struct gsl_ts, gsl_monitor_work.work);
1205 if (i2c_lock_flag != 0) {
1208 //goto queue_monitor_work;
1212 //gsl_ts_read(ts->client, 0x80, read_buf, 4);
1213 /*printk("======read 0x80: %x %x %x %x ======tony0geshu\n",
1214 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1216 gsl_ts_read(ts->client, 0xb0, read_buf, 4);
1217 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a
1218 || read_buf[0] != 0x5a)
1223 if (b0_counter > 1) {
1224 /*printk("======read 0xb0: %x %x %x %x ======\n",
1225 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1230 gsl_ts_read(ts->client, 0xb4, read_buf, 4);
1231 int_2nd[3] = int_1st[3];
1232 int_2nd[2] = int_1st[2];
1233 int_2nd[1] = int_1st[1];
1234 int_2nd[0] = int_1st[0];
1235 int_1st[3] = read_buf[3];
1236 int_1st[2] = read_buf[2];
1237 int_1st[1] = read_buf[1];
1238 int_1st[0] = read_buf[0];
1240 /*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1241 int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1242 int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1244 if (int_1st[3] == int_2nd[3] && int_1st[2] == int_2nd[2]
1245 && int_1st[1] == int_2nd[1] && int_1st[0] == int_2nd[0]) {
1246 /*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1247 int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1248 int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1250 //goto queue_monitor_init_chip;
1253 gsl_ts_read(ts->client, 0xbc, read_buf, 4);
1254 if (read_buf[3] != 0 || read_buf[2] != 0 || read_buf[1] != 0
1255 || read_buf[0] != 0)
1259 if (bc_counter > 1) {
1260 /*printk("======read 0xbc: %x %x %x %x======\n",
1261 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1267 write_buf[3] = 0x01;
1268 write_buf[2] = 0xfe;
1269 write_buf[1] = 0x10;
1270 write_buf[0] = 0x00;
1271 gsl_ts_write(ts->client, 0xf0, write_buf, 4);
1272 gsl_ts_read(ts->client, 0x10, read_buf, 4);
1273 gsl_ts_read(ts->client, 0x10, read_buf, 4);
1278 && read_buf[0] < 10)
1285 printk("read DAC1_0: %x %x %x %x\n",
1286 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
1291 //queue_monitor_init_chip:
1293 init_chip(ts->client, ts);
1297 //queue_monitor_work:
1298 //queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 100);
1302 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
1304 ///struct gsl_ts *ts = dev_id;
1305 struct gsl_ts *ts = (struct gsl_ts *)dev_id;
1306 //print_info("========gslX680 Interrupt=========\n");
1308 disable_irq_nosync(ts->irq);
1310 if (!work_pending(&ts->work)) {
1311 queue_work(ts->wq, &ts->work);
1318 static int gslX680_ts_init(struct i2c_client *client, struct gsl_ts *ts)
1320 struct input_dev *input_device;
1324 printk("[GSLX680] Enter %s\n", __func__);
1326 ts->dd = &devices[ts->device_id];
1328 if (ts->device_id == 0) {
1330 MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
1331 ts->dd->touch_index = 0;
1335 devm_kzalloc(&client->dev, ts->dd->data_size, GFP_KERNEL);
1336 if (!ts->touch_data) {
1337 pr_err("%s: Unable to allocate memory\n", __func__);
1341 input_device = devm_input_allocate_device(&ts->client->dev);
1342 if (!input_device) {
1347 ts->input = input_device;
1348 input_device->name = GSLX680_I2C_NAME;
1349 input_device->id.bustype = BUS_I2C;
1350 input_device->dev.parent = &client->dev;
1351 input_set_drvdata(input_device, ts);
1353 #ifdef REPORT_DATA_ANDROID_4_0
1354 __set_bit(EV_ABS, input_device->evbit);
1355 __set_bit(EV_KEY, input_device->evbit);
1356 __set_bit(EV_REP, input_device->evbit);
1357 __set_bit(EV_SYN, input_device->evbit);
1358 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1359 __set_bit(MT_TOOL_FINGER, input_device->keybit);
1360 input_mt_init_slots(input_device, (MAX_CONTACTS + 1), 0);
1362 input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0,
1363 (MAX_CONTACTS + 1), 0, 0);
1364 set_bit(EV_ABS, input_device->evbit);
1365 set_bit(EV_KEY, input_device->evbit);
1366 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1367 input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1370 #ifdef HAVE_TOUCH_KEY
1371 input_device->evbit[0] = BIT_MASK(EV_KEY);
1372 /*input_device->evbit[0] = BIT_MASK(EV_SYN)
1373 | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);*/
1374 for (i = 0; i < MAX_KEY_NUM; i++)
1375 set_bit(key_array[i], input_device->keybit);
1378 #ifdef RK_GEAR_TOUCH
1379 set_bit(EV_REL, input_device->evbit);
1380 input_set_capability(input_device, EV_REL, REL_X);
1381 input_set_capability(input_device, EV_REL, REL_Y);
1382 input_set_capability(input_device, EV_MSC, MSC_SCAN);
1383 input_set_capability(input_device, EV_KEY, 0x110);
1386 set_bit(ABS_MT_POSITION_X, input_device->absbit);
1387 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
1388 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
1389 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
1391 input_set_abs_params(input_device, ABS_MT_POSITION_X, 0, SCREEN_MAX_X,
1393 input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y,
1395 input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0,
1397 input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
1399 //client->irq = IRQ_PORT;
1400 //ts->irq = client->irq;
1402 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
1404 dev_err(&client->dev, "gsl Could not create workqueue\n");
1407 flush_workqueue(ts->wq);
1409 INIT_WORK(&ts->work, gslX680_ts_worker);
1411 rc = input_register_device(input_device);
1413 goto error_unreg_device;
1418 destroy_workqueue(ts->wq);
1424 static int gsl_ts_suspend(struct i2c_client *dev, pm_message_t mesg)
1427 struct gsl_ts *ts = dev_get_drvdata(dev);
1429 printk("I'am in gsl_ts_suspend() start\n");
1432 printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1433 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1436 #ifdef HAVE_CLICK_TIMER
1437 //cancel_work_sync(&ts->click_work);
1439 disable_irq_nosync(ts->irq);
1441 gslX680_shutdown_low(ts);
1443 #ifdef SLEEP_CLEAR_POINT
1445 #ifdef REPORT_DATA_ANDROID_4_0
1446 for (i = 1; i <= MAX_CONTACTS; i++) {
1447 input_mt_slot(ts->input, i);
1448 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1449 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1452 input_mt_sync(ts->input);
1454 input_sync(ts->input);
1456 report_data(ts, 1, 1, 10, 1);
1457 input_sync(ts->input);
1466 static int gsl_ts_resume(struct i2c_client *dev)
1469 struct gsl_ts *ts = dev_get_drvdata(dev);
1471 printk("I'am in gsl_ts_resume() start\n");
1473 gslX680_shutdown_high(ts);
1475 reset_chip(ts->client);
1476 startup_chip(ts->client);
1477 check_mem_data(ts->client, ts);
1479 #ifdef SLEEP_CLEAR_POINT
1480 #ifdef REPORT_DATA_ANDROID_4_0
1481 for (i = 1; i <= MAX_CONTACTS; i++) {
1482 input_mt_slot(ts->input, i);
1483 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1484 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1487 input_mt_sync(ts->input);
1489 input_sync(ts->input);
1492 printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1493 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1496 #ifdef HAVE_CLICK_TIMER
1497 //queue_work(gsl_timer_workqueue,&ts->click_work);
1500 disable_irq_nosync(ts->irq);
1501 enable_irq(ts->irq);
1508 static int gsl_ts_early_suspend(struct tp_device *tp_d)
1510 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1511 printk("[GSLX680] Enter %s\n", __func__);
1512 //gsl_ts_suspend(&ts->client->dev);
1514 printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1515 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1518 disable_irq_nosync(ts->irq);
1520 #ifdef SLEEP_CLEAR_POINT
1522 #ifdef REPORT_DATA_ANDROID_4_0
1523 for (i = 1; i <= MAX_CONTACTS; i++) {
1524 input_mt_slot(ts->input, i);
1525 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1526 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1529 input_mt_sync(ts->input);
1531 input_sync(ts->input);
1533 report_data(ts, 1, 1, 10, 1);
1534 input_sync(ts->input);
1536 gslX680_shutdown_low(ts);
1540 static int gsl_ts_late_resume(struct tp_device *tp_d)
1542 struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1543 printk("[GSLX680] Enter %s\n", __func__);
1544 //gsl_ts_resume(&ts->client->dev);
1546 printk("I'am in gsl_ts_resume() start\n");
1548 gslX680_shutdown_high(ts);
1550 reset_chip(ts->client);
1551 startup_chip(ts->client);
1552 check_mem_data(ts->client, ts);
1554 #ifdef SLEEP_CLEAR_POINT
1555 #ifdef REPORT_DATA_ANDROID_4_0
1556 for (i = 1; i <= MAX_CONTACTS; i++) {
1557 input_mt_slot(ts->input, i);
1558 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1559 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1562 input_mt_sync(ts->input);
1564 input_sync(ts->input);
1567 printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1568 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1570 disable_irq_nosync(ts->irq);
1571 enable_irq(ts->irq);
1576 #ifdef CONFIG_HAS_EARLYSUSPEND
1578 static void gsl_ts_early_suspend(struct early_suspend *h)
1580 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1581 printk("[GSLX680] Enter %s\n", __func__);
1582 //gsl_ts_suspend(&ts->client->dev);
1584 printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1585 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1588 disable_irq_nosync(ts->irq);
1590 #ifdef SLEEP_CLEAR_POINT
1592 #ifdef REPORT_DATA_ANDROID_4_0
1593 for (i = 1; i <= MAX_CONTACTS; i++) {
1594 input_mt_slot(ts->input, i);
1595 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1596 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1599 input_mt_sync(ts->input);
1601 input_sync(ts->input);
1603 report_data(ts, 1, 1, 10, 1);
1604 input_sync(ts->input);
1606 gslX680_shutdown_low(ts);
1610 static void gsl_ts_late_resume(struct early_suspend *h)
1612 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1613 printk("[GSLX680] Enter %s\n", __func__);
1614 //gsl_ts_resume(&ts->client->dev);
1617 printk("I'am in gsl_ts_resume() start\n");
1619 gslX680_shutdown_high(ts);
1621 reset_chip(ts->client);
1622 startup_chip(ts->client);
1623 check_mem_data(ts->client, ts);
1625 #ifdef SLEEP_CLEAR_POINT
1626 #ifdef REPORT_DATA_ANDROID_4_0
1627 for (i = 1; i <= MAX_CONTACTS; i++) {
1628 input_mt_slot(ts->input, i);
1629 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1630 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1633 input_mt_sync(ts->input);
1635 input_sync(ts->input);
1638 printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1639 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1641 disable_irq_nosync(ts->irq);
1642 enable_irq(ts->irq);
1646 //static struct wake_lock touch_wakelock;
1648 static int gsl_ts_probe(struct i2c_client *client,
1649 const struct i2c_device_id *id)
1654 printk("GSLX680 Enter %s\n", __func__);
1655 //wake_lock_init(&touch_wakelock, WAKE_LOCK_SUSPEND, "touch");
1656 //wake_lock(&touch_wakelock); //system do not enter deep sleep
1657 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1658 dev_err(&client->dev, "gsl I2C functionality not supported\n");
1662 ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
1666 ts->tp.tp_suspend = gsl_ts_early_suspend;
1667 ts->tp.tp_resume = gsl_ts_late_resume;
1668 tp_register_fb(&ts->tp);
1670 ts->client = client;
1671 i2c_set_clientdata(client, ts);
1672 //ts->device_id = id->driver_data;
1675 rc = gslX680_ts_init(client, ts);
1677 dev_err(&client->dev, "gsl GSLX680 init failed\n");
1680 //#ifdef GSLX680_COMPATIBLE
1681 // judge_chip_type(client);
1683 //printk("##################### probe [2]chip_type=%c .\n",chip_type);
1684 init_chip(ts->client, ts);
1685 check_mem_data(ts->client, ts);
1687 client->irq = gpio_to_irq(ts->irq);
1688 rc = request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING,
1691 printk("gsl_probe: request irq failed\n");
1695 /* create debug attribute */
1696 //rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable);
1698 #ifdef CONFIG_HAS_EARLYSUSPEND
1700 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1701 //ts->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1;
1702 ts->early_suspend.suspend = gsl_ts_early_suspend;
1703 ts->early_suspend.resume = gsl_ts_late_resume;
1704 register_early_suspend(&ts->early_suspend);
1709 INIT_DELAYED_WORK(&ts->gsl_monitor_work, gsl_monitor_worker);
1710 gsl_monitor_workqueue =
1711 create_singlethread_workqueue("gsl_monitor_workqueue");
1712 queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 1000);
1715 #ifdef HAVE_CLICK_TIMER
1716 sema_init(&my_sem, 1);
1717 INIT_WORK(&ts->click_work, click_timer_worker);
1718 gsl_timer_workqueue = create_singlethread_workqueue("click_timer");
1719 queue_work(gsl_timer_workqueue, &ts->click_work);
1722 #ifdef TPD_PROC_DEBUG
1724 gsl_config_proc = create_proc_entry(GSL_CONFIG_PROC_FILE, 0666, NULL);
1725 printk("[tp-gsl] [%s] gsl_config_proc = %x \n", __func__,
1727 if (gsl_config_proc == NULL) {
1728 print_info("create_proc_entry %s failed\n",
1729 GSL_CONFIG_PROC_FILE);
1731 gsl_config_proc->read_proc = gsl_config_read_proc;
1732 gsl_config_proc->write_proc = gsl_config_write_proc;
1735 i2c_client = client;
1736 proc_create(GSL_CONFIG_PROC_FILE, 0666, NULL, &gsl_seq_fops);
1740 //disable_irq_nosync(->irq);
1741 printk("[GSLX680] End %s\n", __func__);
1749 static int gsl_ts_remove(struct i2c_client *client)
1751 struct gsl_ts *ts = i2c_get_clientdata(client);
1753 #ifdef CONFIG_HAS_EARLYSUSPEND
1754 unregister_early_suspend(&ts->early_suspend);
1758 cancel_delayed_work_sync(&ts->gsl_monitor_work);
1759 destroy_workqueue(gsl_monitor_workqueue);
1762 #ifdef HAVE_CLICK_TIMER
1763 cancel_work_sync(&ts->click_work);
1764 destroy_workqueue(gsl_timer_workqueue);
1767 device_init_wakeup(&client->dev, 0);
1768 cancel_work_sync(&ts->work);
1769 free_irq(ts->irq, ts);
1770 destroy_workqueue(ts->wq);
1771 //device_remove_file(&ts->input->dev, &dev_attr_debug_enable);
1776 static struct of_device_id gsl_ts_ids[] = {
1777 {.compatible = "gslX680"},
1781 static const struct i2c_device_id gsl_ts_id[] = {
1782 {GSLX680_I2C_NAME, 0},
1786 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1788 static struct i2c_driver gsl_ts_driver = {
1790 .name = GSLX680_I2C_NAME,
1791 .owner = THIS_MODULE,
1792 .of_match_table = of_match_ptr(gsl_ts_ids),
1794 #if 0 //ndef CONFIG_HAS_EARLYSUSPEND
1795 .suspend = gsl_ts_suspend,
1796 .resume = gsl_ts_resume,
1798 .probe = gsl_ts_probe,
1799 .remove = gsl_ts_remove,
1800 .id_table = gsl_ts_id,
1803 static int __init gsl_ts_init(void)
1806 ret = i2c_add_driver(&gsl_ts_driver);
1809 static void __exit gsl_ts_exit(void)
1811 i2c_del_driver(&gsl_ts_driver);
1815 module_init(gsl_ts_init);
1816 module_exit(gsl_ts_exit);
1818 MODULE_LICENSE("GPL");
1819 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1820 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1821 MODULE_ALIAS("platform:gsl_ts");