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.
13 #include <linux/module.h>
14 #include <linux/delay.h>
15 #include <linux/device.h>
16 #include <linux/hrtimer.h>
17 #include <linux/i2c.h>
18 #include <linux/input.h>
19 #include <linux/interrupt.h>
21 #include <linux/platform_device.h>
22 #include <linux/async.h>
23 #include <linux/irq.h>
24 #include <linux/workqueue.h>
25 #include <linux/proc_fs.h>
26 #include <linux/input/mt.h>
28 #include <linux/version.h>
29 #include <linux/slab.h>
30 #include <linux/of_gpio.h>
31 #include "tp_suspend.h"
33 #include "gslx680_pad.h"
34 #include <linux/wakelock.h>
36 #define REPORT_DATA_ANDROID_4_0
37 #define SLEEP_CLEAR_POINT
38 //#define FILTER_POINT
43 #define GSLX680_I2C_NAME "gslX680-pad"
44 #define GSLX680_I2C_ADDR 0x40
49 #define GSL_DATA_REG 0x80
50 #define GSL_STATUS_REG 0xe0
51 #define GSL_PAGE_REG 0xf0
53 #define TPD_PROC_DEBUG
55 #include <linux/proc_fs.h>
56 #include <asm/uaccess.h>
57 #include <linux/seq_file.h> //lzk
58 //static struct proc_dir_entry *gsl_config_proc = NULL;
59 #define GSL_CONFIG_PROC_FILE "gsl_config"
61 static char gsl_read[CONFIG_LEN];
62 static u8 gsl_data_proc[8] = {0};
63 static u8 gsl_proc_flag = 0;
68 #define MAX_FINGERS 10
69 #define MAX_CONTACTS 10
70 #define DMA_TRANS_LEN 0x20
71 static struct i2c_client *gsl_client = NULL;
88 static struct gsl_ts_data devices[] = {
94 .data_reg = GSL_DATA_REG,
95 .status_reg = GSL_STATUS_REG,
104 struct i2c_client *client;
105 struct input_dev *input;
106 struct work_struct work;
107 struct workqueue_struct *wq;
108 struct gsl_ts_data *dd;
120 #define print_info(fmt, args...) \
122 printk(fmt, ##args); \
125 #define print_info(fmt, args...)
129 static u32 id_sign[MAX_CONTACTS+1] = {0};
130 static u8 id_state_flag[MAX_CONTACTS+1] = {0};
131 static u8 id_state_old_flag[MAX_CONTACTS+1] = {0};
132 static u16 x_old[MAX_CONTACTS+1] = {0};
133 static u16 y_old[MAX_CONTACTS+1] = {0};
134 static u16 x_new = 0;
135 static u16 y_new = 0;
139 static int gslX680_init(void)
141 gpio_set_value(g_wake_pin,1);
142 gpio_set_value(g_irq_pin,1);
146 static int gslX680_shutdown_low(void)
150 gpio_direction_output(g_wake_pin, 0);
151 gpio_set_value(g_wake_pin,0);
156 static int gslX680_shutdown_high(void)
160 gpio_direction_output(g_wake_pin, 0);
161 gpio_set_value(g_wake_pin,1);
166 static inline u16 join_bytes(u8 a, u8 b)
174 static u32 gsl_write_interface(struct i2c_client *client, const u8 reg, u8 *buf, u32 num)
176 struct i2c_msg xfer_msg[1];
180 xfer_msg[0].addr = client->addr;
181 xfer_msg[0].len = num + 1;
182 xfer_msg[0].flags = client->flags & I2C_M_TEN;
183 xfer_msg[0].buf = buf;
184 //xfer_msg[0].scl_rate = 400*1000; //RK3066 RK2926 I2C±¨´íʱ´ò¿ªÕâ¸ö
186 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
189 static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata, int datalen)
193 unsigned int bytelen = 0;
196 dev_err(&client->dev,"%s too big datalen = %d!\n", __func__, datalen);
203 if (datalen != 0 && pdata != NULL)
205 memcpy(&tmp_buf[bytelen], pdata, datalen);
209 ret = i2c_master_send(client, tmp_buf, bytelen);
213 static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata, unsigned int datalen)
219 dev_err(&client->dev, "%s too big datalen = %d!\n", __func__, datalen);
223 ret = gsl_ts_write(client, addr, NULL, 0);
226 dev_err(&client->dev, "%s set data address fail!\n", __func__);
230 return i2c_master_recv(client, pdata, datalen);
233 static __inline__ void fw2buf(u8 *buf, const u32 *fw)
235 u32 *u32_buf = (int *)buf;
239 static void gsl_load_fw(struct i2c_client *client)
241 u8 buf[DMA_TRANS_LEN*4 + 1] = {0};
246 struct fw_data *ptr_fw;
249 source_len = ARRAY_SIZE(GSLX680_FW);
251 for (source_line = 0; source_line < source_len; source_line++)
253 /* init page trans, set the page val */
254 if (GSL_PAGE_REG == ptr_fw[source_line].offset)
256 fw2buf(cur, &ptr_fw[source_line].val);
257 gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
258 //i2c_smbus_write_i2c_block_data(client, GSL_PAGE_REG,4, buf);
263 if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
264 buf[0] = (u8)ptr_fw[source_line].offset;
266 fw2buf(cur, &ptr_fw[source_line].val);
269 if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
271 gsl_write_interface(client, buf[0], buf, cur - buf - 1);
272 //i2c_smbus_write_i2c_block_data(client, buf[0], cur - buf - 1, buf);
281 static int test_i2c(struct i2c_client *client)
287 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
291 dev_info(&client->dev, "I read reg 0xf0 is %x\n", read_buf);
294 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
296 dev_info(&client->dev, "I write reg 0xf0 0x12\n");
299 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
303 dev_info(&client->dev, "I read reg 0xf0 is 0x%x\n", read_buf);
309 static void startup_chip(struct i2c_client *client)
313 #ifdef GSL_NOID_VERSION
314 gsl_DataInit(gsl_config_data_id);
316 gsl_ts_write(client, 0xe0, &tmp, 1);
319 static void reset_chip(struct i2c_client *client)
324 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
327 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
329 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
332 static void clr_reg(struct i2c_client *client)
334 u8 write_buf[4] = {0};
337 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
340 gsl_ts_write(client, 0x80, &write_buf[0], 1);
343 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
346 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
350 static void init_chip(struct i2c_client *client)
353 gslX680_shutdown_low();
355 gslX680_shutdown_high();
356 gpio_set_value(g_irq_pin,1);
358 rc = test_i2c(client);
361 dev_err(&client->dev, "------gslX680 test_i2c error------\n");
367 startup_chip(client);
369 startup_chip(client);
372 static void check_mem_data(struct i2c_client *client)
374 u8 read_buf[4] = {0};
376 gsl_ts_read(client,0xb0, read_buf, sizeof(read_buf));
378 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a)
380 dev_info(&client->dev, "#########check mem read 0xb0 = %x %x %x %x #########\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
386 #ifdef TPD_PROC_DEBUG
387 static int char_to_int(char ch)
389 if(ch>='0' && ch<='9')
396 static int gsl_read_interface(struct i2c_client *client, u8 reg, u8 *buf, u32 num)
401 //mutex_lock(&gsl_i2c_lock);
404 temp = (temp+8)&0x5c;
405 i2c_master_send(client,&temp,1);
406 err = i2c_master_recv(client,&buf[0],4);
409 i2c_master_send(client,&temp,1);
410 err = i2c_master_recv(client,&buf[0],4);
412 i2c_master_send(client,®,1);
413 err = i2c_master_recv(client,&buf[0],num);
414 //mutex_unlock(&gsl_i2c_lock);
418 static int gsl_config_read_proc(struct seq_file *m,void *v)
421 char temp_data[5] = {0};
424 if('v'==gsl_read[0]&&'s'==gsl_read[1])
426 #ifdef GSL_NOID_VERSION
427 tmp=gsl_version_id();
431 seq_printf(m,"version:%x\n",tmp);
433 else if('r'==gsl_read[0]&&'e'==gsl_read[1])
437 #ifdef GSL_NOID_VERSION
438 tmp=(gsl_data_proc[5]<<8) | gsl_data_proc[4];
443 gsl_ts_write(gsl_client,0xf0,&gsl_data_proc[4],4);
444 gsl_read_interface(gsl_client,gsl_data_proc[0],temp_data,4);
445 seq_printf(m,"offset : {0x%02x,0x",gsl_data_proc[0]);
446 seq_printf(m,"%02x",temp_data[3]);
447 seq_printf(m,"%02x",temp_data[2]);
448 seq_printf(m,"%02x",temp_data[1]);
449 seq_printf(m,"%02x};\n",temp_data[0]);
455 ssize_t gsl_config_write_proc(struct file *file, const char *buffer, size_t count, loff_t *data)
458 char temp_buf[CONFIG_LEN];
462 print_info("[tp-gsl][%s] \n",__func__);
465 pr_err("size not match [%d:%ld]\n", CONFIG_LEN, count);
468 path_buf=kzalloc(count,GFP_KERNEL);
471 pr_err("alloc path_buf memory error \n");
473 if(copy_from_user(path_buf, buffer, count))
475 pr_err("copy from user fail\n");
476 goto exit_write_proc_out;
478 memcpy(temp_buf,path_buf,(count<CONFIG_LEN?count:CONFIG_LEN));
480 buf[3]=char_to_int(temp_buf[14])<<4 | char_to_int(temp_buf[15]);
481 buf[2]=char_to_int(temp_buf[16])<<4 | char_to_int(temp_buf[17]);
482 buf[1]=char_to_int(temp_buf[18])<<4 | char_to_int(temp_buf[19]);
483 buf[0]=char_to_int(temp_buf[20])<<4 | char_to_int(temp_buf[21]);
485 buf[7]=char_to_int(temp_buf[5])<<4 | char_to_int(temp_buf[6]);
486 buf[6]=char_to_int(temp_buf[7])<<4 | char_to_int(temp_buf[8]);
487 buf[5]=char_to_int(temp_buf[9])<<4 | char_to_int(temp_buf[10]);
488 buf[4]=char_to_int(temp_buf[11])<<4 | char_to_int(temp_buf[12]);
489 if('v'==temp_buf[0]&& 's'==temp_buf[1])//version //vs
491 memcpy(gsl_read,temp_buf,4);
493 else if('s'==temp_buf[0]&& 't'==temp_buf[1])//start //st
496 reset_chip(gsl_client);
498 else if('e'==temp_buf[0]&&'n'==temp_buf[1])//end //en
501 reset_chip(gsl_client);
502 startup_chip(gsl_client);
505 else if('r'==temp_buf[0]&&'e'==temp_buf[1])//read buf //
507 memcpy(gsl_read,temp_buf,4);
508 memcpy(gsl_data_proc,buf,8);
510 else if('w'==temp_buf[0]&&'r'==temp_buf[1])//write buf
512 gsl_ts_write(gsl_client,buf[4],buf,4);
514 #ifdef GSL_NOID_VERSION
515 else if('i'==temp_buf[0]&&'d'==temp_buf[1])//write id config //
517 tmp1=(buf[7]<<24)|(buf[6]<<16)|(buf[5]<<8)|buf[4];
518 tmp=(buf[3]<<24)|(buf[2]<<16)|(buf[1]<<8)|buf[0];
519 if(tmp1>=0 && tmp1<ARRAY_SIZE(gsl_config_data_id))
521 gsl_config_data_id[tmp1] = tmp;
530 static int gsl_server_list_open(struct inode *inode,struct file *file)
532 return single_open(file,gsl_config_read_proc,NULL);
534 static const struct file_operations gsl_seq_fops = {
535 .open = gsl_server_list_open,
537 .release = single_release,
538 .write = gsl_config_write_proc,
539 .owner = THIS_MODULE,
544 static void filter_point(u16 x, u16 y , u8 id)
548 u16 filter_step_x = 0, filter_step_y = 0;
550 id_sign[id] = id_sign[id] + 1;
557 x_err = x > x_old[id] ? (x -x_old[id]) : (x_old[id] - x);
558 y_err = y > y_old[id] ? (y -y_old[id]) : (y_old[id] - y);
560 if( (x_err > FILTER_MAX && y_err > FILTER_MAX/3) || (x_err > FILTER_MAX/3 && y_err > FILTER_MAX) )
562 filter_step_x = x_err;
563 filter_step_y = y_err;
567 if(x_err > FILTER_MAX)
568 filter_step_x = x_err;
569 if(y_err> FILTER_MAX)
570 filter_step_y = y_err;
573 if(x_err <= 2*FILTER_MAX && y_err <= 2*FILTER_MAX)
578 else if(x_err <= 3*FILTER_MAX && y_err <= 3*FILTER_MAX)
583 else if(x_err <= 4*FILTER_MAX && y_err <= 4*FILTER_MAX)
585 filter_step_x = filter_step_x*3/4;
586 filter_step_y = filter_step_y*3/4;
589 x_new = x > x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] - filter_step_x);
590 y_new = y > y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] - filter_step_y);
596 static void record_point(u16 x, u16 y , u8 id)
601 id_sign[id]=id_sign[id]+1;
608 x = (x_old[id] + x)/2;
609 y = (y_old[id] + y)/2;
625 if( (x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3) ){
626 x_new = x; x_old[id] = x;
627 y_new = y; y_old[id] = y;
631 x_new = x; x_old[id] = x;
636 y_new = y; y_old[id] = y;
650 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
655 if(x > ts->screen_max_x || y > ts->screen_max_y)
661 x = ts->screen_max_x-x-1;
663 y = ts->screen_max_y-y-1;
664 #ifdef REPORT_DATA_ANDROID_4_0
665 input_mt_slot(ts->input, id);
666 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
667 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
668 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
669 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
670 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
672 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
673 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
674 input_report_abs(ts->input, ABS_MT_POSITION_X,x);
675 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
676 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
677 input_mt_sync(ts->input);
681 static void gslX680_ts_worker(struct work_struct *work)
686 #ifdef GSL_NOID_VERSION
689 struct gsl_touch_info cinfo = {{0}};
691 struct gsl_ts *ts = container_of(work, struct gsl_ts,work);
693 #ifdef TPD_PROC_DEBUG
694 if(gsl_proc_flag == 1)
698 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
701 dev_err(&ts->client->dev, "read failed\n");
702 reset_chip(ts->client);
703 startup_chip(ts->client);
707 touches = ts->touch_data[ts->dd->touch_index];
708 #ifdef GSL_NOID_VERSION
709 cinfo.finger_num = touches;
710 for(i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i ++)
712 cinfo.x[i] = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
713 ts->touch_data[ts->dd->x_index + 4 * i]);
714 cinfo.y[i] = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
715 ts->touch_data[ts->dd->y_index + 4 * i ]);
716 cinfo.id[i] = ((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf0)>>4);
718 cinfo.finger_num=(ts->touch_data[3]<<24)|(ts->touch_data[2]<<16)
719 |(ts->touch_data[1]<<8)|(ts->touch_data[0]);
720 gsl_alg_id_main(&cinfo);
721 tmp1=gsl_mask_tiaoping();
722 if(tmp1>0&&tmp1<0xffffffff)
724 buf[0]=0xa;buf[1]=0;buf[2]=0;buf[3]=0;
725 gsl_ts_write(ts->client,0xf0,buf,4);
726 buf[0]=(u8)(tmp1 & 0xff);
727 buf[1]=(u8)((tmp1>>8) & 0xff);
728 buf[2]=(u8)((tmp1>>16) & 0xff);
729 buf[3]=(u8)((tmp1>>24) & 0xff);
730 gsl_ts_write(ts->client,0x8,buf,4);
732 touches = cinfo.finger_num;
735 for(i = 1; i <= MAX_CONTACTS; i ++)
739 id_state_flag[i] = 0;
741 for(i= 0;i < (touches > MAX_FINGERS ? MAX_FINGERS : touches);i ++)
743 #ifdef GSL_NOID_VERSION
751 x = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
752 ts->touch_data[ts->dd->x_index + 4 * i]);
753 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
754 ts->touch_data[ts->dd->y_index + 4 * i ]);
755 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
759 if(1 <=id && id <= MAX_CONTACTS)
762 filter_point(x, y ,id);
764 record_point(x, y , id);
766 report_data(ts, x_new, y_new, 10, id);
767 id_state_flag[id] = 1;
770 for(i = 1; i <= MAX_CONTACTS; i ++)
772 if( (0 == touches) || ((0 != id_state_old_flag[i]) && (0 == id_state_flag[i])) )
774 #ifdef REPORT_DATA_ANDROID_4_0
775 input_mt_slot(ts->input, i);
776 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
777 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
781 id_state_old_flag[i] = id_state_flag[i];
785 #ifndef REPORT_DATA_ANDROID_4_0
786 input_mt_sync(ts->input);
789 input_sync(ts->input);
796 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
798 struct gsl_ts *ts = dev_id;
800 disable_irq_nosync(ts->irq);
802 if (!work_pending(&ts->work))
804 queue_work(ts->wq, &ts->work);
811 static int gslX680_ts_init(struct i2c_client *client, struct gsl_ts *ts)
813 struct input_dev *input_device;
816 ts->dd = &devices[ts->device_id];
818 if (ts->device_id == 0) {
819 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
820 ts->dd->touch_index = 0;
823 ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL);
824 if (!ts->touch_data) {
825 pr_err("%s: Unable to allocate memory\n", __func__);
829 input_device = input_allocate_device();
832 goto error_alloc_dev;
835 ts->input = input_device;
836 input_device->name = GSLX680_I2C_NAME;
837 input_device->id.bustype = BUS_I2C;
838 input_device->dev.parent = &client->dev;
839 input_set_drvdata(input_device, ts);
841 #ifdef REPORT_DATA_ANDROID_4_0
842 __set_bit(EV_ABS, input_device->evbit);
843 __set_bit(EV_KEY, input_device->evbit);
844 __set_bit(EV_REP, input_device->evbit);
845 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
846 input_mt_init_slots(input_device, (MAX_CONTACTS+1),0);
848 input_set_abs_params(input_device,ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0);
849 set_bit(EV_ABS, input_device->evbit);
850 set_bit(EV_KEY, input_device->evbit);
851 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
852 input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
855 set_bit(ABS_MT_POSITION_X, input_device->absbit);
856 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
857 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
858 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
860 input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, ts->screen_max_x, 0, 0);
861 input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, ts->screen_max_y, 0, 0);
862 input_set_abs_params(input_device,ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
863 input_set_abs_params(input_device,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
865 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
867 dev_err(&client->dev, "Could not create workqueue\n");
868 goto error_wq_create;
870 flush_workqueue(ts->wq);
871 INIT_WORK(&ts->work, gslX680_ts_worker);
872 rc = input_register_device(input_device);
874 goto error_unreg_device;
878 destroy_workqueue(ts->wq);
880 input_free_device(input_device);
882 kfree(ts->touch_data);
886 static int gsl_ts_suspend(struct device *dev)
888 struct gsl_ts *ts = dev_get_drvdata(dev);
889 #ifdef REPORT_DATA_ANDROID_4_0
893 disable_irq_nosync(ts->irq);
894 gslX680_shutdown_low();
896 #ifdef SLEEP_CLEAR_POINT
898 #ifdef REPORT_DATA_ANDROID_4_0
899 for(i = 1; i <= MAX_CONTACTS ;i ++)
901 input_mt_slot(ts->input, i);
902 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
903 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
906 input_mt_sync(ts->input);
908 input_sync(ts->input);
910 report_data(ts, 1, 1, 10, 1);
911 input_sync(ts->input);
917 static int gsl_ts_resume(struct device *dev)
919 struct gsl_ts *ts = dev_get_drvdata(dev);
920 #ifdef REPORT_DATA_ANDROID_4_0
923 gslX680_shutdown_high();
925 reset_chip(ts->client);
926 startup_chip(ts->client);
927 check_mem_data(ts->client);
928 check_mem_data(ts->client);
930 #ifdef SLEEP_CLEAR_POINT
931 #ifdef REPORT_DATA_ANDROID_4_0
932 for(i =1;i<=MAX_CONTACTS;i++)
934 input_mt_slot(ts->input, i);
935 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
936 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
939 input_mt_sync(ts->input);
941 input_sync(ts->input);
947 static int gsl_ts_probe(struct i2c_client *client,
948 const struct i2c_device_id *id)
950 struct device_node *np = client->dev.of_node;
951 enum of_gpio_flags wake_flags, irq_flags;
955 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
956 dev_err(&client->dev, "I2C functionality not supported\n");
960 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
965 i2c_set_clientdata(client, ts);
966 ts->device_id = id->driver_data;
969 of_property_read_u32(np,"screen_max_x",&(ts->screen_max_x));
970 of_property_read_u32(np,"screen_max_y",&(ts->screen_max_y));
972 dev_info(&ts->client->dev, "[tp-gsl] screen_max_x =[%d] \n",ts->screen_max_x);
973 dev_info(&ts->client->dev, "[tp-gsl] screen_max_y =[%d] \n",ts->screen_max_y);
975 ts->irq_pin=of_get_named_gpio_flags(np, "touch-gpio", 0, &irq_flags);
976 ts->wake_pin=of_get_named_gpio_flags(np, "reset-gpio", 0, &wake_flags);
978 if (gpio_is_valid(ts->wake_pin)) {
979 rc = devm_gpio_request_one(&ts->client->dev, ts->wake_pin, (wake_flags & OF_GPIO_ACTIVE_LOW) ? GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, "gslX680 wake pin");
981 dev_err(&ts->client->dev, "gslX680 wake pin error\n");
984 g_wake_pin = ts->wake_pin;
986 dev_info(&ts->client->dev, "wake pin invalid\n");
988 if (gpio_is_valid(ts->irq_pin)) {
989 rc = devm_gpio_request_one(&ts->client->dev, ts->irq_pin, (irq_flags & OF_GPIO_ACTIVE_LOW) ? GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH, "gslX680 irq pin");
991 dev_err(&ts->client->dev, "gslX680 irq pin error\n");
994 g_irq_pin = ts->irq_pin;
996 dev_info(&ts->client->dev, "irq pin invalid\n");
1000 rc = gslX680_ts_init(client, ts);
1002 dev_err(&client->dev, "GSLX680 init failed\n");
1003 goto error_mutex_destroy;
1006 gsl_client = client;
1007 init_chip(ts->client);
1008 check_mem_data(ts->client);
1010 ts->irq=gpio_to_irq(ts->irq_pin); //If not defined in client
1013 rc = devm_request_threaded_irq(&client->dev, ts->irq, NULL, gsl_ts_irq, irq_flags | IRQF_ONESHOT, client->name, ts);
1015 dev_err(&client->dev, "Cannot allocate ts INT!ERRNO:%d\n", rc);
1016 goto error_req_irq_fail;
1018 disable_irq(ts->irq);
1022 dev_err(&client->dev, "gsl x680 irq req fail\n");
1023 goto error_req_irq_fail;
1026 /* create debug attribute */
1027 #ifdef TPD_PROC_DEBUG
1028 proc_create(GSL_CONFIG_PROC_FILE,0666,NULL,&gsl_seq_fops);
1032 gpio_set_value(ts->irq_pin, 0);
1033 enable_irq(ts->irq);
1037 //exit_set_irq_mode:
1039 free_irq(ts->irq, ts);
1041 error_mutex_destroy:
1042 input_free_device(ts->input);
1047 static int gsl_ts_remove(struct i2c_client *client)
1049 struct gsl_ts *ts = i2c_get_clientdata(client);
1051 device_init_wakeup(&client->dev, 0);
1052 cancel_work_sync(&ts->work);
1053 free_irq(ts->irq, ts);
1054 destroy_workqueue(ts->wq);
1055 input_unregister_device(ts->input);
1057 kfree(ts->touch_data);
1063 static struct of_device_id gsl_ts_ids[] = {
1064 {.compatible = "gslX680-pad"},
1068 static const struct i2c_device_id gsl_ts_id[] = {
1069 {GSLX680_I2C_NAME, 0},
1072 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1074 static const struct dev_pm_ops gsl_pm_ops = {
1075 .suspend = gsl_ts_suspend,
1076 .resume = gsl_ts_resume,
1079 static struct i2c_driver gsl_ts_driver = {
1081 .name = GSLX680_I2C_NAME,
1082 .owner = THIS_MODULE,
1083 .of_match_table = of_match_ptr(gsl_ts_ids),
1086 .probe = gsl_ts_probe,
1087 .remove = gsl_ts_remove,
1088 .id_table = gsl_ts_id,
1091 static int __init gsl_ts_init(void)
1094 ret = i2c_add_driver(&gsl_ts_driver);
1097 static void __exit gsl_ts_exit(void)
1099 i2c_del_driver(&gsl_ts_driver);
1103 module_init(gsl_ts_init);
1104 module_exit(gsl_ts_exit);
1106 MODULE_LICENSE("GPL");
1107 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1108 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1109 MODULE_ALIAS("platform:gsl_ts");