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/earlysuspend.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 <mach/gpio.h>
24 #include <mach/iomux.h>
25 #include <linux/irq.h>
26 #include <mach/board.h>
27 #include <linux/workqueue.h>
28 #include <linux/proc_fs.h>
29 #include <linux/input/mt.h>
31 #include "rk3028_gslX680_86v.h"
36 #define REPORT_DATA_ANDROID_4_0
38 //#define HAVE_TOUCH_KEY
40 #define GSLX680_I2C_NAME "gslX680"
41 #define GSLX680_I2C_ADDR 0x40
43 #define IRQ_PORT RK2928_PIN1_PB0
44 #define WAKE_PORT RK2928_PIN0_PD3
46 #define GSL_DATA_REG 0x80
47 #define GSL_STATUS_REG 0xe0
48 #define GSL_PAGE_REG 0xf0
52 #define MAX_CONTACTS 10
53 #define DMA_TRANS_LEN 0x20
54 //#define FILTER_POINT
59 #define WRITE_I2C_SPEED 350*1000
60 #define I2C_SPEED 200*1000
62 //ÐÝÃßʱÊÇ·ñÐèÒª¹Ø±ÕTPµçÔ´
63 //Ò쳣ʱÊÇ·ñÐèÒª¹Ø±ÕµçÔ´
64 #define CLOSE_TP_POWER 1
67 static void set_tp_power(bool flag);
72 static int key_state_flag = 0;
83 const u16 key_array[]={
89 #define MAX_KEY_NUM (sizeof(key_array)/sizeof(key_array[0]))
91 struct key_data gsl_key_data[MAX_KEY_NUM] = {
92 {KEY_BACK, 2048, 2048, 2048, 2048},
93 {KEY_HOME, 2048, 2048, 2048, 2048},
94 {KEY_MENU, 2048, 2048, 2048, 2048},
95 {KEY_SEARCH, 2048, 2048, 2048, 2048},
114 static struct gsl_ts_data devices[] = {
120 .data_reg = GSL_DATA_REG,
121 .status_reg = GSL_STATUS_REG,
124 .touch_meta_data = 4,
130 struct i2c_client *client;
131 struct input_dev *input;
132 struct work_struct work;
133 struct workqueue_struct *wq;
134 struct gsl_ts_data *dd;
137 // uint32_t gpio_irq;
139 #if defined(CONFIG_HAS_EARLYSUSPEND)
140 struct early_suspend early_suspend;
143 struct timer_list gsl_timer;
145 int reset_gpio; //lizhengwei
150 #define print_info(fmt, args...) \
152 printk(fmt, ##args); \
155 #define print_info(fmt, args...)
158 static int ts_global_reset_pin; //lizhengwei add
160 static u32 id_sign[MAX_CONTACTS+1] = {0};
161 static u8 id_state_flag[MAX_CONTACTS+1] = {0};
162 static u8 id_state_old_flag[MAX_CONTACTS+1] = {0};
163 static u16 x_old[MAX_CONTACTS+1] = {0};
164 static u16 y_old[MAX_CONTACTS+1] = {0};
165 static u16 x_new = 0;
166 static u16 y_new = 0;
168 static int gslX680_chip_init(void)
171 gpio_free(WAKE_PORT);
172 if (gpio_request(WAKE_PORT, "gslx680 wake")) {
173 printk("pjf gpio_request(WAKE_PORT) error\n");
174 goto exit_alloc_gpio_wake_failed;
177 gpio_direction_output(WAKE_PORT, 0);
178 gpio_set_value(WAKE_PORT,GPIO_HIGH);
182 if (gpio_request(IRQ_PORT, "gslx680 irq")) {
183 printk("pjf gpio_request(IRQ_PORT) error\n");
184 goto exit_alloc_gpio_irg_failed;
187 gpio_pull_updown(IRQ_PORT, 1);
192 exit_alloc_gpio_irg_failed:
194 exit_alloc_gpio_wake_failed:
195 gpio_free(WAKE_PORT);
199 static int gslX680_shutdown_low(void)
201 gpio_direction_output(ts_global_reset_pin, GPIO_LOW);
202 gpio_set_value(ts_global_reset_pin,GPIO_LOW);
206 static int gslX680_shutdown_high(void)
208 gpio_direction_output(ts_global_reset_pin, GPIO_HIGH);
209 gpio_set_value(ts_global_reset_pin,GPIO_HIGH);
213 static int gslX680_shutdown_realse(void)
215 gpio_direction_input(ts_global_reset_pin);
219 static inline u16 join_bytes(u8 a, u8 b)
227 static u32 gsl_read_interface(struct i2c_client *client, u8 reg, u8 *buf, u32 num)
229 struct i2c_msg xfer_msg[2];
231 xfer_msg[0].addr = client->addr;
233 xfer_msg[0].flags = client->flags & I2C_M_TEN;
234 xfer_msg[0].buf = ®
235 xfer_msg[0].scl_rate = I2C_SPEED;
237 xfer_msg[1].addr = client->addr;
238 xfer_msg[1].len = num;
239 xfer_msg[1].flags |= I2C_M_RD;
240 xfer_msg[1].buf = buf;
241 xfer_msg[1].scl_rate = I2C_SPEED;
244 i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
248 return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
251 static u32 gsl_write_interface(struct i2c_client *client, const u8 reg, u8 *buf, u32 num)
253 struct i2c_msg xfer_msg[1];
257 xfer_msg[0].addr = client->addr;
258 xfer_msg[0].len = num + 1;
259 xfer_msg[0].flags = client->flags & I2C_M_TEN;
260 xfer_msg[0].buf = buf;
261 xfer_msg[0].scl_rate = WRITE_I2C_SPEED;
263 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
266 static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata, int datalen)
270 unsigned int bytelen = 0;
273 printk("%s too big datalen = %d!\n", __func__, datalen);
280 if (datalen != 0 && pdata != NULL)
282 memcpy(&tmp_buf[bytelen], pdata, datalen);
286 ret = i2c_master_normal_send(client, tmp_buf, bytelen,I2C_SPEED);
290 static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata, unsigned int datalen)
296 printk("%s too big datalen = %d!\n", __func__, datalen);
300 ret = gsl_ts_write(client, addr, NULL, 0);
303 printk("%s set data address fail!\n", __func__);
307 return i2c_master_normal_recv(client, pdata, datalen,I2C_SPEED);
311 static __inline__ void fw2buf(u8 *buf, const u32 *fw)
313 u32 *u32_buf = (int *)buf;
317 static void gsl_load_fw(struct i2c_client *client)
319 u8 buf[DMA_TRANS_LEN*4 + 1] = {0};
324 u8 read_buf[4] = {0};
325 struct fw_data *ptr_fw;
327 printk("=============gsl_load_fw start==============\n");
329 #ifdef GSL1680E_COMPATIBLE
331 gsl_ts_read(client, 0xfc, read_buf, 4);
332 //printk("read 0xfc = %x %x %x %x\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
334 if(read_buf[2] != 0x82 && read_buf[2] != 0x88)
337 gsl_ts_read(client, 0xfc, read_buf, 4);
338 //printk("read 0xfc = %x %x %x %x\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
341 if(read_buf[2] == 0x82)
343 ptr_fw = GSL1680E_FW;
344 source_len = ARRAY_SIZE(GSL1680E_FW);
350 source_len = ARRAY_SIZE(GSLX680_FW);
353 for (source_line = 0; source_line < source_len; source_line++)
355 /* init page trans, set the page val */
356 if (GSL_PAGE_REG == ptr_fw[source_line].offset)
358 fw2buf(cur, &ptr_fw[source_line].val);
359 gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
364 if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
365 buf[0] = (u8)ptr_fw[source_line].offset;
367 fw2buf(cur, &ptr_fw[source_line].val);
370 if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
372 gsl_write_interface(client, buf[0], buf, cur - buf - 1);
380 printk("=============gsl_load_fw end==============\n");
385 static void test_i2c(struct i2c_client *client)
390 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
393 pr_info("I2C transfer error!\n");
397 pr_info("I read reg 0xf0 is %x\n", read_buf);
401 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
404 pr_info("I2C transfer error!\n");
408 pr_info("I write reg 0xf0 0x12\n");
412 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
415 pr_info("I2C transfer error!\n");
419 pr_info("I read reg 0xf0 is 0x%x\n", read_buf);
426 static void startup_chip(struct i2c_client *client)
434 gsl_ts_write(client, 0xf0, buf, sizeof(buf));
439 gsl_ts_write(client, 0x04, buf, sizeof(buf));
441 gsl_ts_write(client, 0xe0, &tmp, 1);
445 static void reset_chip(struct i2c_client *client)
450 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
453 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
455 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
459 static void clr_reg(struct i2c_client *client)
461 u8 write_buf[4] = {0};
464 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
467 gsl_ts_write(client, 0x80, &write_buf[0], 1);
470 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
473 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
477 static void init_chip(struct i2c_client *client)
479 gslX680_shutdown_low();
481 gslX680_shutdown_high();
486 startup_chip(client);
488 startup_chip(client);
491 static void check_mem_data(struct i2c_client *client)
493 u8 read_buf[4] = {0};
496 gsl_ts_read(client,0xb0, read_buf, sizeof(read_buf));
497 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a)
499 printk("#########check mem read 0xb0 = %x %x %x %x #########\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
511 static void filter_point(u16 x, u16 y , u8 id)
515 u16 filter_step_x = 0, filter_step_y = 0;
517 id_sign[id] = id_sign[id] + 1;
524 x_err = x > x_old[id] ? (x -x_old[id]) : (x_old[id] - x);
525 y_err = y > y_old[id] ? (y -y_old[id]) : (y_old[id] - y);
527 if( (x_err > FILTER_MAX && y_err > FILTER_MAX/3) || (x_err > FILTER_MAX/3 && y_err > FILTER_MAX) )
529 filter_step_x = x_err;
530 filter_step_y = y_err;
534 if(x_err > FILTER_MAX)
535 filter_step_x = x_err;
536 if(y_err> FILTER_MAX)
537 filter_step_y = y_err;
540 if(x_err <= 2*FILTER_MAX && y_err <= 2*FILTER_MAX)
545 else if(x_err <= 3*FILTER_MAX && y_err <= 3*FILTER_MAX)
550 else if(x_err <= 4*FILTER_MAX && y_err <= 4*FILTER_MAX)
552 filter_step_x = filter_step_x*3/4;
553 filter_step_y = filter_step_y*3/4;
555 x_new = x > x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] - filter_step_x);
556 y_new = y > y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] - filter_step_y);
563 static void record_point(u16 x, u16 y , u8 id)
568 id_sign[id]=id_sign[id]+1;
575 x = (x_old[id] + x)/2;
576 y = (y_old[id] + y)/2;
592 if( (x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3) ){
593 x_new = x; x_old[id] = x;
594 y_new = y; y_old[id] = y;
598 x_new = x; x_old[id] = x;
603 y_new = y; y_old[id] = y;
617 #ifdef HAVE_TOUCH_KEY
618 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
622 for(i = 0; i < MAX_KEY_NUM; i++)
624 if((gsl_key_data[i].x_min < x) && (x < gsl_key_data[i].x_max)&&(gsl_key_data[i].y_min < y) && (y < gsl_key_data[i].y_max))
626 key = gsl_key_data[i].key;
627 input_report_key(ts->input, key, 1);
628 input_sync(ts->input);
636 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
640 print_info("#####id=%d,x=%d,y=%d######\n",id,x,y);
642 if(x > SCREEN_MAX_X || y > SCREEN_MAX_Y)
644 #ifdef HAVE_TOUCH_KEY
650 #ifdef REPORT_DATA_ANDROID_4_0
651 input_mt_slot(ts->input, id);
652 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
653 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
654 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
655 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
656 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
658 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
659 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
660 input_report_abs(ts->input, ABS_MT_POSITION_X,x);
661 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
662 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
663 input_mt_sync(ts->input);
667 static void process_gslX680_data(struct gsl_ts *ts)
673 touches = ts->touch_data[ts->dd->touch_index];
674 for(i=1;i<=MAX_CONTACTS;i++)
678 id_state_flag[i] = 0;
680 for(i= 0;i < (touches > MAX_FINGERS ? MAX_FINGERS : touches);i ++)
682 x = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
683 ts->touch_data[ts->dd->x_index + 4 * i]);
684 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
685 ts->touch_data[ts->dd->y_index + 4 * i ]);
686 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
688 if(1 <=id && id <= MAX_CONTACTS)
691 filter_point(x, y ,id);
693 record_point(x, y , id);
695 report_data(ts, x_new, y_new, 50, id);
696 id_state_flag[id] = 1;
699 for(i=1;i<=MAX_CONTACTS;i++)
701 if( (0 == touches) || ((0 != id_state_old_flag[i]) && (0 == id_state_flag[i])) )
703 #ifdef REPORT_DATA_ANDROID_4_0
704 input_mt_slot(ts->input, i);
705 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
706 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
710 id_state_old_flag[i] = id_state_flag[i];
712 #ifndef REPORT_DATA_ANDROID_4_0
715 input_mt_sync(ts->input);
716 #ifdef HAVE_TOUCH_KEY
719 input_report_key(ts->input, key, 0);
720 input_sync(ts->input);
726 input_sync(ts->input);
730 static void gsl_ts_xy_worker(struct work_struct *work)
733 u8 read_buf[4] = {0};
735 struct gsl_ts *ts = container_of(work, struct gsl_ts,work);
737 print_info("---gsl_ts_xy_worker---\n");
738 /* read data from DATA_REG */
739 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
740 print_info("---touches: %d ---\n",ts->touch_data[0]);
744 dev_err(&ts->client->dev, "read failed\n");
748 if (ts->touch_data[ts->dd->touch_index] == 0xff) {
752 rc = gsl_ts_read( ts->client, 0xbc, read_buf, sizeof(read_buf));
755 dev_err(&ts->client->dev, "read 0xbc failed\n");
758 print_info("//////// reg %x : %x %x %x %x\n",0xbc, read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
760 if (read_buf[3] == 0 && read_buf[2] == 0 && read_buf[1] == 0 && read_buf[0] == 0)
762 process_gslX680_data(ts);
766 reset_chip(ts->client);
767 startup_chip(ts->client);
775 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
777 struct gsl_ts *ts = dev_id;
779 print_info("==========GSLX680 Interrupt============\n");
781 disable_irq_nosync(ts->irq);
783 if (!work_pending(&ts->work))
785 queue_work(ts->wq, &ts->work);
793 static void gsl_timer_handle(unsigned long data)
795 struct gsl_ts *ts = (struct gsl_ts *)data;
798 printk("----------------gsl_timer_handle-----------------\n");
801 disable_irq_nosync(ts->irq);
802 check_mem_data(ts->client);
803 ts->gsl_timer.expires = jiffies + 3 * HZ;
804 add_timer(&ts->gsl_timer);
810 static int gsl_ts_init_ts(struct i2c_client *client, struct gsl_ts *ts)
812 struct input_dev *input_device;
815 printk("[GSLX680] Enter %s\n", __func__);
818 ts->dd = &devices[ts->device_id];
820 if (ts->device_id == 0) {
821 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
822 ts->dd->touch_index = 0;
825 ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL);
826 if (!ts->touch_data) {
827 pr_err("%s: Unable to allocate memory\n", __func__);
832 input_device = input_allocate_device();
835 goto error_alloc_dev;
838 ts->input = input_device;
839 input_device->name = GSLX680_I2C_NAME;
840 input_device->id.bustype = BUS_I2C;
841 input_device->dev.parent = &client->dev;
842 input_set_drvdata(input_device, ts);
844 #ifdef REPORT_DATA_ANDROID_4_0
845 __set_bit(EV_ABS, input_device->evbit);
846 __set_bit(EV_KEY, input_device->evbit);
847 __set_bit(EV_REP, input_device->evbit);
848 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
849 input_mt_init_slots(input_device, (MAX_CONTACTS+1));
851 input_set_abs_params(input_device,ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0);
852 set_bit(EV_ABS, input_device->evbit);
853 set_bit(EV_KEY, input_device->evbit);
856 #ifdef HAVE_TOUCH_KEY
857 input_device->evbit[0] = BIT_MASK(EV_KEY);
858 for (i = 0; i < MAX_KEY_NUM; i++)
859 set_bit(key_array[i], input_device->keybit);
862 set_bit(ABS_MT_POSITION_X, input_device->absbit);
863 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
864 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
865 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
867 input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
868 input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
869 input_set_abs_params(input_device,ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
870 input_set_abs_params(input_device,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
872 client->irq = ts->irq; //IRQ_PORT,
874 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
876 dev_err(&client->dev, "Could not create workqueue\n");
877 goto error_wq_create;
879 flush_workqueue(ts->wq);
881 INIT_WORK(&ts->work, gsl_ts_xy_worker);
883 rc = input_register_device(input_device);
885 goto error_unreg_device;
890 destroy_workqueue(ts->wq);
892 input_free_device(input_device);
894 kfree(ts->touch_data);
899 #include <linux/regulator/rk29-pwm-regulator.h>
900 #include <linux/mfd/tps65910.h>
901 static void set_tp_power(bool flag)
903 struct regulator *ldo=NULL;
904 ldo = regulator_get(NULL, "vaux33");
907 printk("set_tp_power ldo is null\n");
911 regulator_set_voltage(ldo, 3300000, 3300000);
912 regulator_enable(ldo);
916 regulator_disable(ldo);
922 static int gsl_ts_suspend(struct device *dev)
924 struct gsl_ts *ts = dev_get_drvdata(dev);
925 printk("I'am in gsl_ts_suspend() start\n");
926 flush_workqueue(ts->wq);
928 printk( "gsl_ts_suspend () : delete gsl_timer\n");
929 del_timer(&ts->gsl_timer);
931 disable_irq_nosync(ts->irq);
932 gslX680_shutdown_low();
936 static int gsl_ts_resume(struct device *dev)
938 struct gsl_ts *ts = dev_get_drvdata(dev);
940 printk("I'am in gsl_ts_resume() start\n");
941 gslX680_shutdown_high();
943 reset_chip(ts->client);
944 startup_chip(ts->client);
945 check_mem_data(ts->client);
948 reset_chip(ts->client);
949 startup_chip(ts->client);
951 reset_chip(ts->client);
952 startup_chip(ts->client);
954 printk( "gsl_ts_resume () : add gsl_timer\n");
955 init_timer(&ts->gsl_timer);
956 ts->gsl_timer.expires = jiffies + 3 * HZ;
957 ts->gsl_timer.function = &gsl_timer_handle;
958 ts->gsl_timer.data = (unsigned long)ts;
959 add_timer(&ts->gsl_timer);
962 for(i=1;i<=MAX_CONTACTS;i++){
963 if(0!= id_state_old_flag[i])
965 #ifdef REPORT_DATA_ANDROID_4_0
966 input_mt_slot(ts->input, i);
967 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
968 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
969 input_sync(ts->input);
973 id_state_old_flag[i] = id_state_flag[i]=0;
981 #ifdef CONFIG_HAS_EARLYSUSPEND
982 static void gsl_ts_early_suspend(struct early_suspend *h)
984 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
985 gsl_ts_suspend(&ts->client->dev);
988 static void gsl_ts_late_resume(struct early_suspend *h)
990 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
991 gsl_ts_resume(&ts->client->dev);
995 static int __devinit gsl_ts_probe(struct i2c_client *client,
996 const struct i2c_device_id *id)
998 struct ts_hw_data *pdata = client->dev.platform_data;
1003 printk("GSLX680 Enter %s\n", __func__);
1004 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1005 dev_err(&client->dev, "I2C functionality not supported\n");
1009 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
1012 printk("==kzalloc success=\n");
1014 ts->client = client;
1015 ts->device_id = id->driver_data;
1017 ts->reset_gpio = pdata->reset_gpio; //lizhengwei
1018 ts->irq= gpio_to_irq(pdata->touch_en_gpio); //lizhengwei
1020 ts_global_reset_pin=ts->reset_gpio;
1022 i2c_set_clientdata(client, ts);
1024 if (pdata->init_platform_hw)
1025 pdata->init_platform_hw();
1027 rc = gsl_ts_init_ts(client, ts);
1029 dev_err(&client->dev, "GSLX680 init failed\n");
1030 goto error_mutex_destroy;
1033 init_chip(ts->client);
1034 check_mem_data(ts->client);
1036 rc= request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING, client->name, ts);
1038 printk( "gsl_probe: request irq failed\n");
1039 goto error_req_irq_fail;
1047 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
1050 pr_info("gslx680 I2C transfer error!\n");
1051 goto error_req_irq_fail;
1058 printk( "gsl_ts_probe () : add gsl_timer\n");
1060 init_timer(&ts->gsl_timer);
1061 ts->gsl_timer.expires = jiffies + 3 * HZ; //¶¨Ê±3 ÃëÖÓ
1062 ts->gsl_timer.function = &gsl_timer_handle;
1063 ts->gsl_timer.data = (unsigned long)ts;
1064 add_timer(&ts->gsl_timer);
1067 /* create debug attribute */
1068 //rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable);
1070 #ifdef CONFIG_HAS_EARLYSUSPEND
1071 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1072 ts->early_suspend.suspend = gsl_ts_early_suspend;
1073 ts->early_suspend.resume = gsl_ts_late_resume;
1074 register_early_suspend(&ts->early_suspend);
1077 printk("[GSLX680] End %s\n", __func__);
1081 //exit_set_irq_mode:
1083 free_irq(ts->irq, ts);
1085 error_mutex_destroy:
1086 input_free_device(ts->input);
1091 static int __devexit gsl_ts_remove(struct i2c_client *client)
1093 struct gsl_ts *ts = i2c_get_clientdata(client);
1094 printk("==gsl_ts_remove=\n");
1096 #ifdef CONFIG_HAS_EARLYSUSPEND
1097 unregister_early_suspend(&ts->early_suspend);
1100 device_init_wakeup(&client->dev, 0);
1101 cancel_work_sync(&ts->work);
1102 free_irq(ts->irq, ts);
1103 destroy_workqueue(ts->wq);
1104 input_unregister_device(ts->input);
1106 //device_remove_file(&ts->input->dev, &dev_attr_debug_enable);
1108 kfree(ts->touch_data);
1114 static const struct i2c_device_id gsl_ts_id[] = {
1115 {GSLX680_I2C_NAME, 0},
1118 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1121 static struct i2c_driver gsl_ts_driver = {
1123 .name = GSLX680_I2C_NAME,
1124 .owner = THIS_MODULE,
1126 #ifndef CONFIG_HAS_EARLYSUSPEND
1127 .suspend = gsl_ts_suspend,
1128 .resume = gsl_ts_resume,
1130 .probe = gsl_ts_probe,
1131 .remove = __devexit_p(gsl_ts_remove),
1132 .id_table = gsl_ts_id,
1135 static int __init gsl_ts_init(void)
1138 printk("==gsl_ts_init==\n");
1139 ret = i2c_add_driver(&gsl_ts_driver);
1140 printk("ret=%d\n",ret);
1143 static void __exit gsl_ts_exit(void)
1145 printk("==gsl_ts_exit==\n");
1146 i2c_del_driver(&gsl_ts_driver);
1150 module_init(gsl_ts_init);
1151 module_exit(gsl_ts_exit);
1153 MODULE_LICENSE("GPL");
1154 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1155 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1156 MODULE_ALIAS("platform:gsl_ts");