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;
813 #ifdef CONFIG_MACH_RK_FAC
814 struct tp_platform_data *pdata = client->dev.platform_data;
818 printk("[GSLX680] Enter %s\n", __func__);
821 ts->dd = &devices[ts->device_id];
823 if (ts->device_id == 0) {
824 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
825 ts->dd->touch_index = 0;
828 ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL);
829 if (!ts->touch_data) {
830 pr_err("%s: Unable to allocate memory\n", __func__);
835 input_device = input_allocate_device();
838 goto error_alloc_dev;
841 ts->input = input_device;
842 input_device->name = GSLX680_I2C_NAME;
843 input_device->id.bustype = BUS_I2C;
844 input_device->dev.parent = &client->dev;
845 input_set_drvdata(input_device, ts);
847 #ifdef REPORT_DATA_ANDROID_4_0
848 __set_bit(EV_ABS, input_device->evbit);
849 __set_bit(EV_KEY, input_device->evbit);
850 __set_bit(EV_REP, input_device->evbit);
851 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
852 input_mt_init_slots(input_device, (MAX_CONTACTS+1));
854 input_set_abs_params(input_device,ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0);
855 set_bit(EV_ABS, input_device->evbit);
856 set_bit(EV_KEY, input_device->evbit);
859 #ifdef HAVE_TOUCH_KEY
860 input_device->evbit[0] = BIT_MASK(EV_KEY);
861 for (i = 0; i < MAX_KEY_NUM; i++)
862 set_bit(key_array[i], input_device->keybit);
865 set_bit(ABS_MT_POSITION_X, input_device->absbit);
866 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
867 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
868 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
869 #ifdef CONFIG_MACH_RK_FAC
870 input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0);
871 input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, pdata->y_max, 0, 0);
873 input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
874 input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
876 input_set_abs_params(input_device,ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
877 input_set_abs_params(input_device,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
879 client->irq = ts->irq; //IRQ_PORT,
881 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
883 dev_err(&client->dev, "Could not create workqueue\n");
884 goto error_wq_create;
886 flush_workqueue(ts->wq);
888 INIT_WORK(&ts->work, gsl_ts_xy_worker);
890 rc = input_register_device(input_device);
892 goto error_unreg_device;
897 destroy_workqueue(ts->wq);
899 input_free_device(input_device);
901 kfree(ts->touch_data);
906 #include <linux/regulator/rk29-pwm-regulator.h>
907 #include <linux/mfd/tps65910.h>
908 static void set_tp_power(bool flag)
910 struct regulator *ldo=NULL;
911 ldo = regulator_get(NULL, "vaux33");
914 printk("set_tp_power ldo is null\n");
918 regulator_set_voltage(ldo, 3300000, 3300000);
919 regulator_enable(ldo);
923 regulator_disable(ldo);
929 static int gsl_ts_suspend(struct device *dev)
931 struct gsl_ts *ts = dev_get_drvdata(dev);
932 printk("I'am in gsl_ts_suspend() start\n");
933 flush_workqueue(ts->wq);
935 printk( "gsl_ts_suspend () : delete gsl_timer\n");
936 del_timer(&ts->gsl_timer);
938 disable_irq_nosync(ts->irq);
939 gslX680_shutdown_low();
943 static int gsl_ts_resume(struct device *dev)
945 struct gsl_ts *ts = dev_get_drvdata(dev);
947 printk("I'am in gsl_ts_resume() start\n");
948 gslX680_shutdown_high();
950 reset_chip(ts->client);
951 startup_chip(ts->client);
952 check_mem_data(ts->client);
955 reset_chip(ts->client);
956 startup_chip(ts->client);
958 reset_chip(ts->client);
959 startup_chip(ts->client);
961 printk( "gsl_ts_resume () : add gsl_timer\n");
962 init_timer(&ts->gsl_timer);
963 ts->gsl_timer.expires = jiffies + 3 * HZ;
964 ts->gsl_timer.function = &gsl_timer_handle;
965 ts->gsl_timer.data = (unsigned long)ts;
966 add_timer(&ts->gsl_timer);
969 for(i=1;i<=MAX_CONTACTS;i++){
970 if(0!= id_state_old_flag[i])
972 #ifdef REPORT_DATA_ANDROID_4_0
973 input_mt_slot(ts->input, i);
974 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
975 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
976 input_sync(ts->input);
980 id_state_old_flag[i] = id_state_flag[i]=0;
988 #ifdef CONFIG_HAS_EARLYSUSPEND
989 static void gsl_ts_early_suspend(struct early_suspend *h)
991 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
992 gsl_ts_suspend(&ts->client->dev);
995 static void gsl_ts_late_resume(struct early_suspend *h)
997 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
998 gsl_ts_resume(&ts->client->dev);
1002 static int __devinit gsl_ts_probe(struct i2c_client *client,
1003 const struct i2c_device_id *id)
1005 #ifdef CONFIG_MACH_RK_FAC
1006 struct tp_platform_data *pdata = client->dev.platform_data;
1008 struct ts_hw_data *pdata = client->dev.platform_data;
1013 printk("GSLX680 Enter %s\n", __func__);
1014 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1015 dev_err(&client->dev, "I2C functionality not supported\n");
1019 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
1022 printk("==kzalloc success=\n");
1024 ts->client = client;
1025 ts->device_id = id->driver_data;
1027 #ifdef CONFIG_MACH_RK_FAC
1028 ts->reset_gpio = pdata->reset_pin; //lizhengwei
1029 ts->irq= gpio_to_irq(pdata->irq_pin); //lizhengwei
1031 ts->reset_gpio = pdata->reset_gpio; //lizhengwei
1032 ts->irq= gpio_to_irq(pdata->touch_en_gpio); //lizhengwei
1035 ts_global_reset_pin=ts->reset_gpio;
1037 i2c_set_clientdata(client, ts);
1039 if (pdata->init_platform_hw)
1040 pdata->init_platform_hw();
1042 rc = gsl_ts_init_ts(client, ts);
1044 dev_err(&client->dev, "GSLX680 init failed\n");
1045 goto error_mutex_destroy;
1048 init_chip(ts->client);
1049 check_mem_data(ts->client);
1051 rc= request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING, client->name, ts);
1053 printk( "gsl_probe: request irq failed\n");
1054 goto error_req_irq_fail;
1062 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
1065 pr_info("gslx680 I2C transfer error!\n");
1066 goto error_req_irq_fail;
1073 printk( "gsl_ts_probe () : add gsl_timer\n");
1075 init_timer(&ts->gsl_timer);
1076 ts->gsl_timer.expires = jiffies + 3 * HZ; //¶¨Ê±3 ÃëÖÓ
1077 ts->gsl_timer.function = &gsl_timer_handle;
1078 ts->gsl_timer.data = (unsigned long)ts;
1079 add_timer(&ts->gsl_timer);
1082 /* create debug attribute */
1083 //rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable);
1085 #ifdef CONFIG_HAS_EARLYSUSPEND
1086 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1087 ts->early_suspend.suspend = gsl_ts_early_suspend;
1088 ts->early_suspend.resume = gsl_ts_late_resume;
1089 register_early_suspend(&ts->early_suspend);
1092 printk("[GSLX680] End %s\n", __func__);
1096 //exit_set_irq_mode:
1098 free_irq(ts->irq, ts);
1100 error_mutex_destroy:
1101 input_free_device(ts->input);
1106 static int __devexit gsl_ts_remove(struct i2c_client *client)
1108 struct gsl_ts *ts = i2c_get_clientdata(client);
1109 printk("==gsl_ts_remove=\n");
1111 #ifdef CONFIG_HAS_EARLYSUSPEND
1112 unregister_early_suspend(&ts->early_suspend);
1115 device_init_wakeup(&client->dev, 0);
1116 cancel_work_sync(&ts->work);
1117 free_irq(ts->irq, ts);
1118 destroy_workqueue(ts->wq);
1119 input_unregister_device(ts->input);
1121 //device_remove_file(&ts->input->dev, &dev_attr_debug_enable);
1123 kfree(ts->touch_data);
1129 static const struct i2c_device_id gsl_ts_id[] = {
1130 {GSLX680_I2C_NAME, 0},
1133 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1136 static struct i2c_driver gsl_ts_driver = {
1138 .name = GSLX680_I2C_NAME,
1139 .owner = THIS_MODULE,
1141 #ifndef CONFIG_HAS_EARLYSUSPEND
1142 .suspend = gsl_ts_suspend,
1143 .resume = gsl_ts_resume,
1145 .probe = gsl_ts_probe,
1146 .remove = __devexit_p(gsl_ts_remove),
1147 .id_table = gsl_ts_id,
1150 static int __init gsl_ts_init(void)
1153 printk("==gsl_ts_init==\n");
1154 ret = i2c_add_driver(&gsl_ts_driver);
1155 printk("ret=%d\n",ret);
1158 static void __exit gsl_ts_exit(void)
1160 printk("==gsl_ts_exit==\n");
1161 i2c_del_driver(&gsl_ts_driver);
1165 module_init(gsl_ts_init);
1166 module_exit(gsl_ts_exit);
1168 MODULE_LICENSE("GPL");
1169 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1170 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1171 MODULE_ALIAS("platform:gsl_ts");