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>
30 #include "rockchip_gslX680_rk3168.h"
34 #define REPORT_DATA_ANDROID_4_0
36 //#define HAVE_TOUCH_KEY
38 #define GSLX680_I2C_NAME "gslX680"
39 #define GSLX680_I2C_ADDR 0x40
41 #define IRQ_PORT RK2928_PIN1_PB0
42 #define WAKE_PORT RK2928_PIN0_PD3
44 #define GSL_DATA_REG 0x80
45 #define GSL_STATUS_REG 0xe0
46 #define GSL_PAGE_REG 0xf0
50 #define MAX_CONTACTS 10
51 #define DMA_TRANS_LEN 0x20
52 //#define FILTER_POINT
57 #define WRITE_I2C_SPEED 350*1000
58 #define I2C_SPEED 200*1000
60 //ÐÝÃßʱÊÇ·ñÐèÒª¹Ø±ÕTPµçÔ´
61 //Ò쳣ʱÊÇ·ñÐèÒª¹Ø±ÕµçÔ´
62 #define CLOSE_TP_POWER 1
65 static void set_tp_power(bool flag);
70 static int key_state_flag = 0;
81 const u16 key_array[]={
87 #define MAX_KEY_NUM (sizeof(key_array)/sizeof(key_array[0]))
89 struct key_data gsl_key_data[MAX_KEY_NUM] = {
90 {KEY_BACK, 2048, 2048, 2048, 2048},
91 {KEY_HOME, 2048, 2048, 2048, 2048},
92 {KEY_MENU, 2048, 2048, 2048, 2048},
93 {KEY_SEARCH, 2048, 2048, 2048, 2048},
112 static struct gsl_ts_data devices[] = {
118 .data_reg = GSL_DATA_REG,
119 .status_reg = GSL_STATUS_REG,
122 .touch_meta_data = 4,
128 struct i2c_client *client;
129 struct input_dev *input;
130 struct work_struct work;
131 struct workqueue_struct *wq;
132 struct gsl_ts_data *dd;
135 // uint32_t gpio_irq;
137 #if defined(CONFIG_HAS_EARLYSUSPEND)
138 struct early_suspend early_suspend;
141 struct timer_list gsl_timer;
143 int reset_gpio; //lizhengwei
148 #define print_info(fmt, args...) \
150 printk(fmt, ##args); \
153 #define print_info(fmt, args...)
156 static int ts_global_reset_pin; //lizhengwei add
158 static u32 id_sign[MAX_CONTACTS+1] = {0};
159 static u8 id_state_flag[MAX_CONTACTS+1] = {0};
160 static u8 id_state_old_flag[MAX_CONTACTS+1] = {0};
161 static u16 x_old[MAX_CONTACTS+1] = {0};
162 static u16 y_old[MAX_CONTACTS+1] = {0};
163 static u16 x_new = 0;
164 static u16 y_new = 0;
166 static int gslX680_chip_init(void)
169 gpio_free(WAKE_PORT);
170 if (gpio_request(WAKE_PORT, "gslx680 wake")) {
171 printk("pjf gpio_request(WAKE_PORT) error\n");
172 goto exit_alloc_gpio_wake_failed;
175 gpio_direction_output(WAKE_PORT, 0);
176 gpio_set_value(WAKE_PORT,GPIO_HIGH);
180 if (gpio_request(IRQ_PORT, "gslx680 irq")) {
181 printk("pjf gpio_request(IRQ_PORT) error\n");
182 goto exit_alloc_gpio_irg_failed;
185 gpio_pull_updown(IRQ_PORT, 1);
190 exit_alloc_gpio_irg_failed:
192 exit_alloc_gpio_wake_failed:
193 gpio_free(WAKE_PORT);
197 static int gslX680_shutdown_low(void)
199 gpio_direction_output(ts_global_reset_pin, GPIO_LOW);
200 gpio_set_value(ts_global_reset_pin,GPIO_LOW);
204 static int gslX680_shutdown_high(void)
206 gpio_direction_output(ts_global_reset_pin, GPIO_HIGH);
207 gpio_set_value(ts_global_reset_pin,GPIO_HIGH);
211 static int gslX680_shutdown_realse(void)
213 gpio_direction_input(ts_global_reset_pin);
217 static inline u16 join_bytes(u8 a, u8 b)
225 static u32 gsl_read_interface(struct i2c_client *client, u8 reg, u8 *buf, u32 num)
227 struct i2c_msg xfer_msg[2];
229 xfer_msg[0].addr = client->addr;
231 xfer_msg[0].flags = client->flags & I2C_M_TEN;
232 xfer_msg[0].buf = ®
233 xfer_msg[0].scl_rate = I2C_SPEED;
235 xfer_msg[1].addr = client->addr;
236 xfer_msg[1].len = num;
237 xfer_msg[1].flags |= I2C_M_RD;
238 xfer_msg[1].buf = buf;
239 xfer_msg[1].scl_rate = I2C_SPEED;
242 i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
246 return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
249 static u32 gsl_write_interface(struct i2c_client *client, const u8 reg, u8 *buf, u32 num)
251 struct i2c_msg xfer_msg[1];
255 xfer_msg[0].addr = client->addr;
256 xfer_msg[0].len = num + 1;
257 xfer_msg[0].flags = client->flags & I2C_M_TEN;
258 xfer_msg[0].buf = buf;
259 xfer_msg[0].scl_rate = WRITE_I2C_SPEED;
261 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
264 static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata, int datalen)
268 unsigned int bytelen = 0;
271 printk("%s too big datalen = %d!\n", __func__, datalen);
278 if (datalen != 0 && pdata != NULL)
280 memcpy(&tmp_buf[bytelen], pdata, datalen);
284 ret = i2c_master_normal_send(client, tmp_buf, bytelen,I2C_SPEED);
288 static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata, unsigned int datalen)
294 printk("%s too big datalen = %d!\n", __func__, datalen);
298 ret = gsl_ts_write(client, addr, NULL, 0);
301 printk("%s set data address fail!\n", __func__);
305 return i2c_master_normal_recv(client, pdata, datalen,I2C_SPEED);
309 static __inline__ void fw2buf(u8 *buf, const u32 *fw)
311 u32 *u32_buf = (int *)buf;
315 static void gsl_load_fw(struct i2c_client *client)
317 u8 buf[DMA_TRANS_LEN*4 + 1] = {0};
322 u8 read_buf[4] = {0};
323 struct fw_data *ptr_fw;
325 printk("=============gsl_load_fw start==============\n");
327 #ifdef GSL1680E_COMPATIBLE
329 gsl_ts_read(client, 0xfc, read_buf, 4);
330 //printk("read 0xfc = %x %x %x %x\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
332 if(read_buf[2] != 0x82 && read_buf[2] != 0x88)
335 gsl_ts_read(client, 0xfc, read_buf, 4);
336 //printk("read 0xfc = %x %x %x %x\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
339 if(read_buf[2] == 0x82)
341 ptr_fw = GSL1680E_FW;
342 source_len = ARRAY_SIZE(GSL1680E_FW);
348 source_len = ARRAY_SIZE(GSLX680_FW);
351 for (source_line = 0; source_line < source_len; source_line++)
353 /* init page trans, set the page val */
354 if (GSL_PAGE_REG == ptr_fw[source_line].offset)
356 fw2buf(cur, &ptr_fw[source_line].val);
357 gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
362 if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
363 buf[0] = (u8)ptr_fw[source_line].offset;
365 fw2buf(cur, &ptr_fw[source_line].val);
368 if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
370 gsl_write_interface(client, buf[0], buf, cur - buf - 1);
378 printk("=============gsl_load_fw end==============\n");
383 static void test_i2c(struct i2c_client *client)
388 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
391 pr_info("I2C transfer error!\n");
395 pr_info("I read reg 0xf0 is %x\n", read_buf);
399 ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
402 pr_info("I2C transfer error!\n");
406 pr_info("I write reg 0xf0 0x12\n");
410 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
413 pr_info("I2C transfer error!\n");
417 pr_info("I read reg 0xf0 is 0x%x\n", read_buf);
424 static void startup_chip(struct i2c_client *client)
432 gsl_ts_write(client, 0xf0, buf, sizeof(buf));
437 gsl_ts_write(client, 0x04, buf, sizeof(buf));
439 gsl_ts_write(client, 0xe0, &tmp, 1);
443 static void reset_chip(struct i2c_client *client)
448 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
451 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
453 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
457 static void clr_reg(struct i2c_client *client)
459 u8 write_buf[4] = {0};
462 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
465 gsl_ts_write(client, 0x80, &write_buf[0], 1);
468 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
471 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
475 static void init_chip(struct i2c_client *client)
477 gslX680_shutdown_low();
479 gslX680_shutdown_high();
484 startup_chip(client);
486 startup_chip(client);
489 static void check_mem_data(struct i2c_client *client)
491 u8 read_buf[4] = {0};
494 gsl_ts_read(client,0xb0, read_buf, sizeof(read_buf));
495 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a)
497 printk("#########check mem read 0xb0 = %x %x %x %x #########\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
509 static void filter_point(u16 x, u16 y , u8 id)
513 u16 filter_step_x = 0, filter_step_y = 0;
515 id_sign[id] = id_sign[id] + 1;
522 x_err = x > x_old[id] ? (x -x_old[id]) : (x_old[id] - x);
523 y_err = y > y_old[id] ? (y -y_old[id]) : (y_old[id] - y);
525 if( (x_err > FILTER_MAX && y_err > FILTER_MAX/3) || (x_err > FILTER_MAX/3 && y_err > FILTER_MAX) )
527 filter_step_x = x_err;
528 filter_step_y = y_err;
532 if(x_err > FILTER_MAX)
533 filter_step_x = x_err;
534 if(y_err> FILTER_MAX)
535 filter_step_y = y_err;
538 if(x_err <= 2*FILTER_MAX && y_err <= 2*FILTER_MAX)
543 else if(x_err <= 3*FILTER_MAX && y_err <= 3*FILTER_MAX)
548 else if(x_err <= 4*FILTER_MAX && y_err <= 4*FILTER_MAX)
550 filter_step_x = filter_step_x*3/4;
551 filter_step_y = filter_step_y*3/4;
553 x_new = x > x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] - filter_step_x);
554 y_new = y > y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] - filter_step_y);
561 static void record_point(u16 x, u16 y , u8 id)
566 id_sign[id]=id_sign[id]+1;
573 x = (x_old[id] + x)/2;
574 y = (y_old[id] + y)/2;
590 if( (x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3) ){
591 x_new = x; x_old[id] = x;
592 y_new = y; y_old[id] = y;
596 x_new = x; x_old[id] = x;
601 y_new = y; y_old[id] = y;
615 #ifdef HAVE_TOUCH_KEY
616 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
620 for(i = 0; i < MAX_KEY_NUM; i++)
622 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))
624 key = gsl_key_data[i].key;
625 input_report_key(ts->input, key, 1);
626 input_sync(ts->input);
634 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
638 print_info("#####id=%d,x=%d,y=%d######\n",id,x,y);
640 if(x > SCREEN_MAX_X || y > SCREEN_MAX_Y)
642 #ifdef HAVE_TOUCH_KEY
648 #ifdef REPORT_DATA_ANDROID_4_0
649 input_mt_slot(ts->input, id);
650 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
651 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
652 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
653 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
654 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
656 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
657 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
658 input_report_abs(ts->input, ABS_MT_POSITION_X,x);
659 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
660 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
661 input_mt_sync(ts->input);
665 static void process_gslX680_data(struct gsl_ts *ts)
671 touches = ts->touch_data[ts->dd->touch_index];
672 for(i=1;i<=MAX_CONTACTS;i++)
676 id_state_flag[i] = 0;
678 for(i= 0;i < (touches > MAX_FINGERS ? MAX_FINGERS : touches);i ++)
680 x = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
681 ts->touch_data[ts->dd->x_index + 4 * i]);
682 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
683 ts->touch_data[ts->dd->y_index + 4 * i ]);
684 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
686 if(1 <=id && id <= MAX_CONTACTS)
689 filter_point(x, y ,id);
691 record_point(x, y , id);
693 report_data(ts, x_new, y_new, 50, id);
694 id_state_flag[id] = 1;
697 for(i=1;i<=MAX_CONTACTS;i++)
699 if( (0 == touches) || ((0 != id_state_old_flag[i]) && (0 == id_state_flag[i])) )
701 #ifdef REPORT_DATA_ANDROID_4_0
702 input_mt_slot(ts->input, i);
703 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
704 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
708 id_state_old_flag[i] = id_state_flag[i];
710 #ifndef REPORT_DATA_ANDROID_4_0
713 input_mt_sync(ts->input);
714 #ifdef HAVE_TOUCH_KEY
717 input_report_key(ts->input, key, 0);
718 input_sync(ts->input);
724 input_sync(ts->input);
728 static void gsl_ts_xy_worker(struct work_struct *work)
731 u8 read_buf[4] = {0};
733 struct gsl_ts *ts = container_of(work, struct gsl_ts,work);
735 print_info("---gsl_ts_xy_worker---\n");
736 /* read data from DATA_REG */
737 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
738 print_info("---touches: %d ---\n",ts->touch_data[0]);
742 dev_err(&ts->client->dev, "read failed\n");
746 if (ts->touch_data[ts->dd->touch_index] == 0xff) {
750 rc = gsl_ts_read( ts->client, 0xbc, read_buf, sizeof(read_buf));
753 dev_err(&ts->client->dev, "read 0xbc failed\n");
756 print_info("//////// reg %x : %x %x %x %x\n",0xbc, read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
758 if (read_buf[3] == 0 && read_buf[2] == 0 && read_buf[1] == 0 && read_buf[0] == 0)
760 process_gslX680_data(ts);
764 reset_chip(ts->client);
765 startup_chip(ts->client);
773 static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
775 struct gsl_ts *ts = dev_id;
777 print_info("==========GSLX680 Interrupt============\n");
779 disable_irq_nosync(ts->irq);
781 if (!work_pending(&ts->work))
783 queue_work(ts->wq, &ts->work);
791 static void gsl_timer_handle(unsigned long data)
793 struct gsl_ts *ts = (struct gsl_ts *)data;
796 printk("----------------gsl_timer_handle-----------------\n");
799 disable_irq_nosync(ts->irq);
800 check_mem_data(ts->client);
801 ts->gsl_timer.expires = jiffies + 3 * HZ;
802 add_timer(&ts->gsl_timer);
808 static int gsl_ts_init_ts(struct i2c_client *client, struct gsl_ts *ts)
810 struct input_dev *input_device;
811 #ifdef CONFIG_MACH_RK_FAC
812 struct tp_platform_data *pdata = client->dev.platform_data;
816 printk("[GSLX680] Enter %s\n", __func__);
819 ts->dd = &devices[ts->device_id];
821 if (ts->device_id == 0) {
822 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
823 ts->dd->touch_index = 0;
826 ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL);
827 if (!ts->touch_data) {
828 pr_err("%s: Unable to allocate memory\n", __func__);
833 input_device = input_allocate_device();
836 goto error_alloc_dev;
839 ts->input = input_device;
840 input_device->name = GSLX680_I2C_NAME;
841 input_device->id.bustype = BUS_I2C;
842 input_device->dev.parent = &client->dev;
843 input_set_drvdata(input_device, ts);
845 #ifdef REPORT_DATA_ANDROID_4_0
846 __set_bit(EV_ABS, input_device->evbit);
847 __set_bit(EV_KEY, input_device->evbit);
848 __set_bit(EV_REP, input_device->evbit);
849 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
850 input_mt_init_slots(input_device, (MAX_CONTACTS+1));
852 input_set_abs_params(input_device,ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0);
853 set_bit(EV_ABS, input_device->evbit);
854 set_bit(EV_KEY, input_device->evbit);
857 #ifdef HAVE_TOUCH_KEY
858 input_device->evbit[0] = BIT_MASK(EV_KEY);
859 for (i = 0; i < MAX_KEY_NUM; i++)
860 set_bit(key_array[i], input_device->keybit);
863 set_bit(ABS_MT_POSITION_X, input_device->absbit);
864 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
865 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
866 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
867 #ifdef CONFIG_MACH_RK_FAC
868 input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0);
869 input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, pdata->y_max, 0, 0);
871 input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
872 input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
874 input_set_abs_params(input_device,ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
875 input_set_abs_params(input_device,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
877 client->irq = ts->irq; //IRQ_PORT,
879 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
881 dev_err(&client->dev, "Could not create workqueue\n");
882 goto error_wq_create;
884 flush_workqueue(ts->wq);
886 INIT_WORK(&ts->work, gsl_ts_xy_worker);
888 rc = input_register_device(input_device);
890 goto error_unreg_device;
895 destroy_workqueue(ts->wq);
897 input_free_device(input_device);
899 kfree(ts->touch_data);
904 #include <linux/regulator/rk29-pwm-regulator.h>
905 #include <linux/mfd/tps65910.h>
906 static void set_tp_power(bool flag)
908 struct regulator *ldo=NULL;
909 ldo = regulator_get(NULL, "vaux33");
912 printk("set_tp_power ldo is null\n");
916 regulator_set_voltage(ldo, 3300000, 3300000);
917 regulator_enable(ldo);
921 regulator_disable(ldo);
927 static int gsl_ts_suspend(struct device *dev)
929 struct gsl_ts *ts = dev_get_drvdata(dev);
930 printk("I'am in gsl_ts_suspend() start\n");
931 flush_workqueue(ts->wq);
933 printk( "gsl_ts_suspend () : delete gsl_timer\n");
934 del_timer(&ts->gsl_timer);
936 disable_irq_nosync(ts->irq);
937 gslX680_shutdown_low();
941 static int gsl_ts_resume(struct device *dev)
943 struct gsl_ts *ts = dev_get_drvdata(dev);
945 printk("I'am in gsl_ts_resume() start\n");
946 gslX680_shutdown_high();
948 reset_chip(ts->client);
949 startup_chip(ts->client);
950 check_mem_data(ts->client);
953 reset_chip(ts->client);
954 startup_chip(ts->client);
956 reset_chip(ts->client);
957 startup_chip(ts->client);
959 printk( "gsl_ts_resume () : add gsl_timer\n");
960 init_timer(&ts->gsl_timer);
961 ts->gsl_timer.expires = jiffies + 3 * HZ;
962 ts->gsl_timer.function = &gsl_timer_handle;
963 ts->gsl_timer.data = (unsigned long)ts;
964 add_timer(&ts->gsl_timer);
967 for(i=1;i<=MAX_CONTACTS;i++){
968 if(0!= id_state_old_flag[i])
970 #ifdef REPORT_DATA_ANDROID_4_0
971 input_mt_slot(ts->input, i);
972 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
973 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
974 input_sync(ts->input);
978 id_state_old_flag[i] = id_state_flag[i]=0;
986 #ifdef CONFIG_HAS_EARLYSUSPEND
987 static void gsl_ts_early_suspend(struct early_suspend *h)
989 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
990 gsl_ts_suspend(&ts->client->dev);
993 static void gsl_ts_late_resume(struct early_suspend *h)
995 struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
996 gsl_ts_resume(&ts->client->dev);
1000 static int __devinit gsl_ts_probe(struct i2c_client *client,
1001 const struct i2c_device_id *id)
1003 #ifdef CONFIG_MACH_RK_FAC
1004 struct tp_platform_data *pdata = client->dev.platform_data;
1006 struct ts_hw_data *pdata = client->dev.platform_data;
1011 printk("GSLX680 Enter %s\n", __func__);
1012 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1013 dev_err(&client->dev, "I2C functionality not supported\n");
1017 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
1020 printk("==kzalloc success=\n");
1022 ts->client = client;
1023 ts->device_id = id->driver_data;
1025 #ifdef CONFIG_MACH_RK_FAC
1026 ts->reset_gpio = pdata->reset_pin; //lizhengwei
1027 ts->irq= gpio_to_irq(pdata->irq_pin); //lizhengwei
1029 ts->reset_gpio = pdata->reset_gpio; //lizhengwei
1030 ts->irq= gpio_to_irq(pdata->touch_en_gpio); //lizhengwei
1033 ts_global_reset_pin=ts->reset_gpio;
1035 i2c_set_clientdata(client, ts);
1037 if (pdata->init_platform_hw)
1038 pdata->init_platform_hw();
1040 rc = gsl_ts_init_ts(client, ts);
1042 dev_err(&client->dev, "GSLX680 init failed\n");
1043 goto error_mutex_destroy;
1046 init_chip(ts->client);
1047 check_mem_data(ts->client);
1049 rc= request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING, client->name, ts);
1051 printk( "gsl_probe: request irq failed\n");
1052 goto error_req_irq_fail;
1060 ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
1063 pr_info("gslx680 I2C transfer error!\n");
1064 goto error_req_irq_fail;
1071 printk( "gsl_ts_probe () : add gsl_timer\n");
1073 init_timer(&ts->gsl_timer);
1074 ts->gsl_timer.expires = jiffies + 3 * HZ; //¶¨Ê±3 ÃëÖÓ
1075 ts->gsl_timer.function = &gsl_timer_handle;
1076 ts->gsl_timer.data = (unsigned long)ts;
1077 add_timer(&ts->gsl_timer);
1080 /* create debug attribute */
1081 //rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable);
1083 #ifdef CONFIG_HAS_EARLYSUSPEND
1084 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1085 ts->early_suspend.suspend = gsl_ts_early_suspend;
1086 ts->early_suspend.resume = gsl_ts_late_resume;
1087 register_early_suspend(&ts->early_suspend);
1090 printk("[GSLX680] End %s\n", __func__);
1094 //exit_set_irq_mode:
1096 free_irq(ts->irq, ts);
1098 error_mutex_destroy:
1099 input_free_device(ts->input);
1104 static int __devexit gsl_ts_remove(struct i2c_client *client)
1106 struct gsl_ts *ts = i2c_get_clientdata(client);
1107 printk("==gsl_ts_remove=\n");
1109 #ifdef CONFIG_HAS_EARLYSUSPEND
1110 unregister_early_suspend(&ts->early_suspend);
1113 device_init_wakeup(&client->dev, 0);
1114 cancel_work_sync(&ts->work);
1115 free_irq(ts->irq, ts);
1116 destroy_workqueue(ts->wq);
1117 input_unregister_device(ts->input);
1119 //device_remove_file(&ts->input->dev, &dev_attr_debug_enable);
1121 kfree(ts->touch_data);
1127 static const struct i2c_device_id gsl_ts_id[] = {
1128 {GSLX680_I2C_NAME, 0},
1131 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1134 static struct i2c_driver gsl_ts_driver = {
1136 .name = GSLX680_I2C_NAME,
1137 .owner = THIS_MODULE,
1139 #ifndef CONFIG_HAS_EARLYSUSPEND
1140 .suspend = gsl_ts_suspend,
1141 .resume = gsl_ts_resume,
1143 .probe = gsl_ts_probe,
1144 .remove = __devexit_p(gsl_ts_remove),
1145 .id_table = gsl_ts_id,
1148 static int __init gsl_ts_init(void)
1151 printk("==gsl_ts_init==\n");
1152 ret = i2c_add_driver(&gsl_ts_driver);
1153 printk("ret=%d\n",ret);
1156 static void __exit gsl_ts_exit(void)
1158 printk("==gsl_ts_exit==\n");
1159 i2c_del_driver(&gsl_ts_driver);
1163 module_init(gsl_ts_init);
1164 module_exit(gsl_ts_exit);
1166 MODULE_LICENSE("GPL");
1167 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1168 MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1169 MODULE_ALIAS("platform:gsl_ts");