1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * drivers/input/touchscreen/gslX680.c
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (c) 2012 Shanghai Basewin
5*4882a593Smuzhiyun * Guan Yuwei<guanyuwei@basewin.com>
6*4882a593Smuzhiyun *
7*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
8*4882a593Smuzhiyun * it under the terms of the GNU General Public License version 2 as
9*4882a593Smuzhiyun * published by the Free Software Foundation.
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/module.h>
14*4882a593Smuzhiyun #include <linux/delay.h>
15*4882a593Smuzhiyun #include <linux/device.h>
16*4882a593Smuzhiyun #include <linux/hrtimer.h>
17*4882a593Smuzhiyun #include <linux/i2c.h>
18*4882a593Smuzhiyun #include <linux/input.h>
19*4882a593Smuzhiyun #include <linux/interrupt.h>
20*4882a593Smuzhiyun #include <linux/io.h>
21*4882a593Smuzhiyun #include <linux/platform_device.h>
22*4882a593Smuzhiyun #include <linux/async.h>
23*4882a593Smuzhiyun #include <linux/irq.h>
24*4882a593Smuzhiyun #include <linux/uaccess.h>
25*4882a593Smuzhiyun #include <linux/workqueue.h>
26*4882a593Smuzhiyun #include <linux/proc_fs.h>
27*4882a593Smuzhiyun #include <linux/input/mt.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include <linux/version.h>
30*4882a593Smuzhiyun #include <linux/slab.h>
31*4882a593Smuzhiyun #include <linux/of_gpio.h>
32*4882a593Smuzhiyun #include "tp_suspend.h"
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #include "gslx680_pad.h"
35*4882a593Smuzhiyun #include <linux/wakelock.h>
36*4882a593Smuzhiyun //#define GSL_DEBUG
37*4882a593Smuzhiyun #define REPORT_DATA_ANDROID_4_0
38*4882a593Smuzhiyun //#define SLEEP_CLEAR_POINT
39*4882a593Smuzhiyun //#define FILTER_POINT
40*4882a593Smuzhiyun #ifdef FILTER_POINT
41*4882a593Smuzhiyun #define FILTER_MAX 9
42*4882a593Smuzhiyun #endif
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun #define GSLX680_I2C_NAME "gslX680-pad"
45*4882a593Smuzhiyun #define GSLX680_I2C_ADDR 0x40
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun int g_wake_pin=0;
48*4882a593Smuzhiyun int g_irq_pin=0;
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun #define GSL_DATA_REG 0x80
51*4882a593Smuzhiyun #define GSL_STATUS_REG 0xe0
52*4882a593Smuzhiyun #define GSL_PAGE_REG 0xf0
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun #define TPD_PROC_DEBUG
55*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
56*4882a593Smuzhiyun #include <linux/proc_fs.h>
57*4882a593Smuzhiyun #include <linux/uaccess.h>
58*4882a593Smuzhiyun #include <linux/seq_file.h> //lzk
59*4882a593Smuzhiyun //static struct proc_dir_entry *gsl_config_proc = NULL;
60*4882a593Smuzhiyun #define GSL_CONFIG_PROC_FILE "gsl_config"
61*4882a593Smuzhiyun #define CONFIG_LEN 31
62*4882a593Smuzhiyun static char gsl_read[CONFIG_LEN];
63*4882a593Smuzhiyun static u8 gsl_data_proc[8] = {0};
64*4882a593Smuzhiyun static u8 gsl_proc_flag = 0;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun #endif
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #define PRESS_MAX 255
69*4882a593Smuzhiyun #define MAX_FINGERS 10
70*4882a593Smuzhiyun #define MAX_CONTACTS 10
71*4882a593Smuzhiyun #define DMA_TRANS_LEN 0x20
72*4882a593Smuzhiyun static struct i2c_client *gsl_client = NULL;
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun struct gsl_ts_data {
75*4882a593Smuzhiyun u8 x_index;
76*4882a593Smuzhiyun u8 y_index;
77*4882a593Smuzhiyun u8 z_index;
78*4882a593Smuzhiyun u8 id_index;
79*4882a593Smuzhiyun u8 touch_index;
80*4882a593Smuzhiyun u8 data_reg;
81*4882a593Smuzhiyun u8 status_reg;
82*4882a593Smuzhiyun u8 data_size;
83*4882a593Smuzhiyun u8 touch_bytes;
84*4882a593Smuzhiyun u8 update_data;
85*4882a593Smuzhiyun u8 touch_meta_data;
86*4882a593Smuzhiyun u8 finger_size;
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun static struct gsl_ts_data devices[] = {
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun .x_index = 6,
92*4882a593Smuzhiyun .y_index = 4,
93*4882a593Smuzhiyun .z_index = 5,
94*4882a593Smuzhiyun .id_index = 7,
95*4882a593Smuzhiyun .data_reg = GSL_DATA_REG,
96*4882a593Smuzhiyun .status_reg = GSL_STATUS_REG,
97*4882a593Smuzhiyun .update_data = 0x4,
98*4882a593Smuzhiyun .touch_bytes = 4,
99*4882a593Smuzhiyun .touch_meta_data = 4,
100*4882a593Smuzhiyun .finger_size = 70,
101*4882a593Smuzhiyun },
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun struct gsl_ts {
105*4882a593Smuzhiyun struct i2c_client *client;
106*4882a593Smuzhiyun struct input_dev *input;
107*4882a593Smuzhiyun struct work_struct work;
108*4882a593Smuzhiyun struct workqueue_struct *wq;
109*4882a593Smuzhiyun struct gsl_ts_data *dd;
110*4882a593Smuzhiyun u8 *touch_data;
111*4882a593Smuzhiyun u8 device_id;
112*4882a593Smuzhiyun int irq;
113*4882a593Smuzhiyun int irq_pin;
114*4882a593Smuzhiyun int wake_pin;
115*4882a593Smuzhiyun struct tp_device tp;
116*4882a593Smuzhiyun int screen_max_x;
117*4882a593Smuzhiyun int screen_max_y;
118*4882a593Smuzhiyun struct gsl_touch_chip_info *gsl_chip_info;
119*4882a593Smuzhiyun struct work_struct download_fw_work;
120*4882a593Smuzhiyun struct work_struct resume_work;
121*4882a593Smuzhiyun };
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun #ifdef GSL_DEBUG
124*4882a593Smuzhiyun #define print_info(fmt, args...) \
125*4882a593Smuzhiyun do{ \
126*4882a593Smuzhiyun printk(fmt, ##args); \
127*4882a593Smuzhiyun }while(0)
128*4882a593Smuzhiyun #else
129*4882a593Smuzhiyun #define print_info(fmt, args...)
130*4882a593Smuzhiyun #endif
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun static u32 id_sign[MAX_CONTACTS+1] = {0};
134*4882a593Smuzhiyun static u8 id_state_flag[MAX_CONTACTS+1] = {0};
135*4882a593Smuzhiyun static u8 id_state_old_flag[MAX_CONTACTS+1] = {0};
136*4882a593Smuzhiyun static u16 x_old[MAX_CONTACTS+1] = {0};
137*4882a593Smuzhiyun static u16 y_old[MAX_CONTACTS+1] = {0};
138*4882a593Smuzhiyun static u16 x_new = 0;
139*4882a593Smuzhiyun static u16 y_new = 0;
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun static struct gsl_touch_chip_info gsl_chip_info[] = {
142*4882a593Smuzhiyun {GSL680,GSLX680_FW,ARRAY_SIZE(GSLX680_FW),gsl_config_data_id,ARRAY_SIZE(gsl_config_data_id)},
143*4882a593Smuzhiyun {GSL3676,GSL3675B_FW_HK,ARRAY_SIZE(GSL3675B_FW_HK),gsl3678_config_data_id,ARRAY_SIZE(gsl3678_config_data_id)},
144*4882a593Smuzhiyun };
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun
gslX680_init(void)147*4882a593Smuzhiyun static int gslX680_init(void)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun gpio_set_value(g_wake_pin,1);
150*4882a593Smuzhiyun gpio_set_value(g_irq_pin,1);
151*4882a593Smuzhiyun return 0;
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun
gslX680_shutdown_low(void)154*4882a593Smuzhiyun static int gslX680_shutdown_low(void)
155*4882a593Smuzhiyun {
156*4882a593Smuzhiyun if(g_wake_pin !=0)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun gpio_direction_output(g_wake_pin, 0);
159*4882a593Smuzhiyun gpio_set_value(g_wake_pin,0);
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun return 0;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun
gslX680_shutdown_high(void)164*4882a593Smuzhiyun static int gslX680_shutdown_high(void)
165*4882a593Smuzhiyun {
166*4882a593Smuzhiyun if(g_wake_pin !=0)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun gpio_direction_output(g_wake_pin, 0);
169*4882a593Smuzhiyun gpio_set_value(g_wake_pin,1);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun return 0;
172*4882a593Smuzhiyun }
173*4882a593Smuzhiyun
join_bytes(u8 a,u8 b)174*4882a593Smuzhiyun static inline u16 join_bytes(u8 a, u8 b)
175*4882a593Smuzhiyun {
176*4882a593Smuzhiyun u16 ab = 0;
177*4882a593Smuzhiyun ab = ab | a;
178*4882a593Smuzhiyun ab = ab << 8 | b;
179*4882a593Smuzhiyun return ab;
180*4882a593Smuzhiyun }
181*4882a593Smuzhiyun
gsl_write_interface(struct i2c_client * client,const u8 reg,u8 * buf,u32 num)182*4882a593Smuzhiyun static u32 gsl_write_interface(struct i2c_client *client, const u8 reg, u8 *buf, u32 num)
183*4882a593Smuzhiyun {
184*4882a593Smuzhiyun struct i2c_msg xfer_msg[1];
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun buf[0] = reg;
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun xfer_msg[0].addr = client->addr;
189*4882a593Smuzhiyun xfer_msg[0].len = num + 1;
190*4882a593Smuzhiyun xfer_msg[0].flags = client->flags & I2C_M_TEN;
191*4882a593Smuzhiyun xfer_msg[0].buf = buf;
192*4882a593Smuzhiyun //xfer_msg[0].scl_rate = 400*1000; //RK3066 RK2926 I2C±¨´íʱ´ò¿ªÕâ¸ö
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
195*4882a593Smuzhiyun }
196*4882a593Smuzhiyun
gsl_ts_write(struct i2c_client * client,u8 addr,u8 * pdata,int datalen)197*4882a593Smuzhiyun static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata, int datalen)
198*4882a593Smuzhiyun {
199*4882a593Smuzhiyun int ret = 0;
200*4882a593Smuzhiyun u8 tmp_buf[128];
201*4882a593Smuzhiyun unsigned int bytelen = 0;
202*4882a593Smuzhiyun if (datalen > 125)
203*4882a593Smuzhiyun {
204*4882a593Smuzhiyun dev_err(&client->dev,"%s too big datalen = %d!\n", __func__, datalen);
205*4882a593Smuzhiyun return -1;
206*4882a593Smuzhiyun }
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun tmp_buf[0] = addr;
209*4882a593Smuzhiyun bytelen++;
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun if (datalen != 0 && pdata != NULL)
212*4882a593Smuzhiyun {
213*4882a593Smuzhiyun memcpy(&tmp_buf[bytelen], pdata, datalen);
214*4882a593Smuzhiyun bytelen += datalen;
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun ret = i2c_master_send(client, tmp_buf, bytelen);
218*4882a593Smuzhiyun return ret;
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
gsl_ts_read(struct i2c_client * client,u8 addr,u8 * pdata,unsigned int datalen)221*4882a593Smuzhiyun static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata, unsigned int datalen)
222*4882a593Smuzhiyun {
223*4882a593Smuzhiyun int ret = 0;
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun if (datalen > 126)
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun dev_err(&client->dev, "%s too big datalen = %d!\n", __func__, datalen);
228*4882a593Smuzhiyun return -1;
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun ret = gsl_ts_write(client, addr, NULL, 0);
232*4882a593Smuzhiyun if (ret < 0)
233*4882a593Smuzhiyun {
234*4882a593Smuzhiyun dev_err(&client->dev, "%s set data address fail!\n", __func__);
235*4882a593Smuzhiyun return ret;
236*4882a593Smuzhiyun }
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun return i2c_master_recv(client, pdata, datalen);
239*4882a593Smuzhiyun }
240*4882a593Smuzhiyun
fw2buf(u8 * buf,const u32 * fw)241*4882a593Smuzhiyun static __inline__ void fw2buf(u8 *buf, const u32 *fw)
242*4882a593Smuzhiyun {
243*4882a593Smuzhiyun u32 *u32_buf = (int *)buf;
244*4882a593Smuzhiyun *u32_buf = *fw;
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun
gsl_load_fw(struct i2c_client * client)247*4882a593Smuzhiyun static void gsl_load_fw(struct i2c_client *client)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun u8 buf[DMA_TRANS_LEN*4 + 1] = {0};
250*4882a593Smuzhiyun u8 send_flag = 1;
251*4882a593Smuzhiyun u8 *cur = buf + 1;
252*4882a593Smuzhiyun u32 source_line = 0;
253*4882a593Smuzhiyun u32 source_len;
254*4882a593Smuzhiyun struct gsl_ts *ts = i2c_get_clientdata(gsl_client);
255*4882a593Smuzhiyun struct fw_data *ptr_fw;
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun ptr_fw = ts->gsl_chip_info->ptr_fw;
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun source_len = ts->gsl_chip_info->ptr_fw_len;
260*4882a593Smuzhiyun for (source_line = 0; source_line < source_len; source_line++)
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun /* init page trans, set the page val */
263*4882a593Smuzhiyun if (GSL_PAGE_REG == ptr_fw[source_line].offset)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun fw2buf(cur, &ptr_fw[source_line].val);
266*4882a593Smuzhiyun gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
267*4882a593Smuzhiyun //i2c_smbus_write_i2c_block_data(client, GSL_PAGE_REG,4, buf);
268*4882a593Smuzhiyun send_flag = 1;
269*4882a593Smuzhiyun }
270*4882a593Smuzhiyun else
271*4882a593Smuzhiyun {
272*4882a593Smuzhiyun if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
273*4882a593Smuzhiyun buf[0] = (u8)ptr_fw[source_line].offset;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun fw2buf(cur, &ptr_fw[source_line].val);
276*4882a593Smuzhiyun cur += 4;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20))
279*4882a593Smuzhiyun {
280*4882a593Smuzhiyun gsl_write_interface(client, buf[0], buf, cur - buf - 1);
281*4882a593Smuzhiyun //i2c_smbus_write_i2c_block_data(client, buf[0], cur - buf - 1, buf);
282*4882a593Smuzhiyun cur = buf + 1;
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun send_flag++;
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun }
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun
test_i2c(struct i2c_client * client)290*4882a593Smuzhiyun static int test_i2c(struct i2c_client *client)
291*4882a593Smuzhiyun {
292*4882a593Smuzhiyun u8 read_buf = 0;
293*4882a593Smuzhiyun u8 write_buf = 0x12;
294*4882a593Smuzhiyun int ret, rc = 1;
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
297*4882a593Smuzhiyun if (ret < 0)
298*4882a593Smuzhiyun rc --;
299*4882a593Smuzhiyun else
300*4882a593Smuzhiyun dev_info(&client->dev, "I read reg 0xf0 is %x\n", read_buf);
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun mdelay(2);
303*4882a593Smuzhiyun ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
304*4882a593Smuzhiyun if(ret >= 0 )
305*4882a593Smuzhiyun dev_info(&client->dev, "I write reg 0xf0 0x12\n");
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun mdelay(2);
308*4882a593Smuzhiyun ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) );
309*4882a593Smuzhiyun if(ret < 0 )
310*4882a593Smuzhiyun rc --;
311*4882a593Smuzhiyun else
312*4882a593Smuzhiyun dev_info(&client->dev, "I read reg 0xf0 is 0x%x\n", read_buf);
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun return rc;
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun
startup_chip(struct i2c_client * client)318*4882a593Smuzhiyun static void startup_chip(struct i2c_client *client)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun u8 tmp = 0x00;
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
323*4882a593Smuzhiyun struct gsl_ts *ts = i2c_get_clientdata(client);
324*4882a593Smuzhiyun gsl_DataInit(ts->gsl_chip_info->conf_in);
325*4882a593Smuzhiyun #endif
326*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &tmp, 1);
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun
reset_chip(struct i2c_client * client)329*4882a593Smuzhiyun static void reset_chip(struct i2c_client *client)
330*4882a593Smuzhiyun {
331*4882a593Smuzhiyun u8 tmp = 0x88;
332*4882a593Smuzhiyun u8 buf[4] = {0x00};
333*4882a593Smuzhiyun
334*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
335*4882a593Smuzhiyun mdelay(5);
336*4882a593Smuzhiyun tmp = 0x04;
337*4882a593Smuzhiyun gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
338*4882a593Smuzhiyun mdelay(5);
339*4882a593Smuzhiyun gsl_ts_write(client, 0xbc, buf, sizeof(buf));
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun
clr_reg(struct i2c_client * client)342*4882a593Smuzhiyun static void clr_reg(struct i2c_client *client)
343*4882a593Smuzhiyun {
344*4882a593Smuzhiyun u8 write_buf[4] = {0};
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun write_buf[0] = 0x88;
347*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &write_buf[0], 1);
348*4882a593Smuzhiyun msleep(20);
349*4882a593Smuzhiyun write_buf[0] = 0x03;
350*4882a593Smuzhiyun gsl_ts_write(client, 0x80, &write_buf[0], 1);
351*4882a593Smuzhiyun msleep(5);
352*4882a593Smuzhiyun write_buf[0] = 0x04;
353*4882a593Smuzhiyun gsl_ts_write(client, 0xe4, &write_buf[0], 1);
354*4882a593Smuzhiyun msleep(5);
355*4882a593Smuzhiyun write_buf[0] = 0x00;
356*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &write_buf[0], 1);
357*4882a593Smuzhiyun msleep(20);
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun
init_chip(struct i2c_client * client)360*4882a593Smuzhiyun static void init_chip(struct i2c_client *client)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun int rc;
363*4882a593Smuzhiyun struct gsl_ts *ts = i2c_get_clientdata(client);
364*4882a593Smuzhiyun
365*4882a593Smuzhiyun gslX680_shutdown_low();
366*4882a593Smuzhiyun mdelay(20);
367*4882a593Smuzhiyun gslX680_shutdown_high();
368*4882a593Smuzhiyun gpio_set_value(g_irq_pin,1);
369*4882a593Smuzhiyun msleep(20);
370*4882a593Smuzhiyun rc = test_i2c(client);
371*4882a593Smuzhiyun if(rc < 0)
372*4882a593Smuzhiyun {
373*4882a593Smuzhiyun dev_err(&client->dev, "------gslX680 test_i2c error------\n");
374*4882a593Smuzhiyun return;
375*4882a593Smuzhiyun }
376*4882a593Smuzhiyun queue_work(ts->wq, &ts->download_fw_work);
377*4882a593Smuzhiyun }
378*4882a593Smuzhiyun
check_mem_data(struct i2c_client * client)379*4882a593Smuzhiyun static void check_mem_data(struct i2c_client *client)
380*4882a593Smuzhiyun {
381*4882a593Smuzhiyun u8 read_buf[4] = {0};
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun gsl_ts_read(client,0xb0, read_buf, sizeof(read_buf));
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a)
386*4882a593Smuzhiyun {
387*4882a593Smuzhiyun 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]);
388*4882a593Smuzhiyun init_chip(client);
389*4882a593Smuzhiyun }
390*4882a593Smuzhiyun }
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
char_to_int(char ch)394*4882a593Smuzhiyun static int char_to_int(char ch)
395*4882a593Smuzhiyun {
396*4882a593Smuzhiyun if(ch>='0' && ch<='9')
397*4882a593Smuzhiyun return (ch-'0');
398*4882a593Smuzhiyun else
399*4882a593Smuzhiyun return (ch-'a'+10);
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun
gsl_read_interface(struct i2c_client * client,u8 reg,u8 * buf,u32 num)403*4882a593Smuzhiyun static int gsl_read_interface(struct i2c_client *client, u8 reg, u8 *buf, u32 num)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun int err = 0;
407*4882a593Smuzhiyun u8 temp = reg;
408*4882a593Smuzhiyun //mutex_lock(&gsl_i2c_lock);
409*4882a593Smuzhiyun if(temp < 0x80)
410*4882a593Smuzhiyun {
411*4882a593Smuzhiyun temp = (temp+8)&0x5c;
412*4882a593Smuzhiyun i2c_master_send(client,&temp,1);
413*4882a593Smuzhiyun err = i2c_master_recv(client,&buf[0],4);
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun temp = reg;
416*4882a593Smuzhiyun i2c_master_send(client,&temp,1);
417*4882a593Smuzhiyun err = i2c_master_recv(client,&buf[0],4);
418*4882a593Smuzhiyun }
419*4882a593Smuzhiyun i2c_master_send(client,®,1);
420*4882a593Smuzhiyun err = i2c_master_recv(client,&buf[0],num);
421*4882a593Smuzhiyun //mutex_unlock(&gsl_i2c_lock);
422*4882a593Smuzhiyun return err;
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun
gsl_config_read_proc(struct seq_file * m,void * v)425*4882a593Smuzhiyun static int gsl_config_read_proc(struct seq_file *m,void *v)
426*4882a593Smuzhiyun {
427*4882a593Smuzhiyun //char *ptr = page;
428*4882a593Smuzhiyun char temp_data[5] = {0};
429*4882a593Smuzhiyun unsigned int tmp=0;
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun if('v'==gsl_read[0]&&'s'==gsl_read[1])
432*4882a593Smuzhiyun {
433*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
434*4882a593Smuzhiyun tmp=gsl_version_id();
435*4882a593Smuzhiyun #else
436*4882a593Smuzhiyun tmp=0x20121215;
437*4882a593Smuzhiyun #endif
438*4882a593Smuzhiyun seq_printf(m,"version:%x\n",tmp);
439*4882a593Smuzhiyun }
440*4882a593Smuzhiyun else if('r'==gsl_read[0]&&'e'==gsl_read[1])
441*4882a593Smuzhiyun {
442*4882a593Smuzhiyun if('i'==gsl_read[3])
443*4882a593Smuzhiyun {
444*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
445*4882a593Smuzhiyun tmp=(gsl_data_proc[5]<<8) | gsl_data_proc[4];
446*4882a593Smuzhiyun #endif
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun else
449*4882a593Smuzhiyun {
450*4882a593Smuzhiyun gsl_ts_write(gsl_client,0xf0,&gsl_data_proc[4],4);
451*4882a593Smuzhiyun gsl_read_interface(gsl_client,gsl_data_proc[0],temp_data,4);
452*4882a593Smuzhiyun seq_printf(m,"offset : {0x%02x,0x",gsl_data_proc[0]);
453*4882a593Smuzhiyun seq_printf(m,"%02x",temp_data[3]);
454*4882a593Smuzhiyun seq_printf(m,"%02x",temp_data[2]);
455*4882a593Smuzhiyun seq_printf(m,"%02x",temp_data[1]);
456*4882a593Smuzhiyun seq_printf(m,"%02x};\n",temp_data[0]);
457*4882a593Smuzhiyun }
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun return 0;
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
gsl_config_write_proc(struct file * file,const char * buffer,size_t count,loff_t * data)462*4882a593Smuzhiyun ssize_t gsl_config_write_proc(struct file *file, const char *buffer, size_t count, loff_t *data)
463*4882a593Smuzhiyun {
464*4882a593Smuzhiyun u8 buf[8] = {0};
465*4882a593Smuzhiyun char temp_buf[CONFIG_LEN];
466*4882a593Smuzhiyun char *path_buf;
467*4882a593Smuzhiyun int tmp = 0;
468*4882a593Smuzhiyun int tmp1 = 0;
469*4882a593Smuzhiyun struct gsl_ts *ts = i2c_get_clientdata(gsl_client);
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun print_info("[tp-gsl][%s] \n",__func__);
472*4882a593Smuzhiyun if(count > 512)
473*4882a593Smuzhiyun {
474*4882a593Smuzhiyun pr_err("size not match [%d:%ld]\n", CONFIG_LEN, count);
475*4882a593Smuzhiyun return -EFAULT;
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun path_buf=kzalloc(count,GFP_KERNEL);
478*4882a593Smuzhiyun if(!path_buf)
479*4882a593Smuzhiyun {
480*4882a593Smuzhiyun pr_err("alloc path_buf memory error \n");
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun if(copy_from_user(path_buf, buffer, count))
483*4882a593Smuzhiyun {
484*4882a593Smuzhiyun pr_err("copy from user fail\n");
485*4882a593Smuzhiyun goto exit_write_proc_out;
486*4882a593Smuzhiyun }
487*4882a593Smuzhiyun memcpy(temp_buf,path_buf,(count<CONFIG_LEN?count:CONFIG_LEN));
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun buf[3]=char_to_int(temp_buf[14])<<4 | char_to_int(temp_buf[15]);
490*4882a593Smuzhiyun buf[2]=char_to_int(temp_buf[16])<<4 | char_to_int(temp_buf[17]);
491*4882a593Smuzhiyun buf[1]=char_to_int(temp_buf[18])<<4 | char_to_int(temp_buf[19]);
492*4882a593Smuzhiyun buf[0]=char_to_int(temp_buf[20])<<4 | char_to_int(temp_buf[21]);
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun buf[7]=char_to_int(temp_buf[5])<<4 | char_to_int(temp_buf[6]);
495*4882a593Smuzhiyun buf[6]=char_to_int(temp_buf[7])<<4 | char_to_int(temp_buf[8]);
496*4882a593Smuzhiyun buf[5]=char_to_int(temp_buf[9])<<4 | char_to_int(temp_buf[10]);
497*4882a593Smuzhiyun buf[4]=char_to_int(temp_buf[11])<<4 | char_to_int(temp_buf[12]);
498*4882a593Smuzhiyun if('v'==temp_buf[0]&& 's'==temp_buf[1])//version //vs
499*4882a593Smuzhiyun {
500*4882a593Smuzhiyun memcpy(gsl_read,temp_buf,4);
501*4882a593Smuzhiyun }
502*4882a593Smuzhiyun else if('s'==temp_buf[0]&& 't'==temp_buf[1])//start //st
503*4882a593Smuzhiyun {
504*4882a593Smuzhiyun gsl_proc_flag = 1;
505*4882a593Smuzhiyun reset_chip(gsl_client);
506*4882a593Smuzhiyun }
507*4882a593Smuzhiyun else if('e'==temp_buf[0]&&'n'==temp_buf[1])//end //en
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun msleep(20);
510*4882a593Smuzhiyun reset_chip(gsl_client);
511*4882a593Smuzhiyun startup_chip(gsl_client);
512*4882a593Smuzhiyun gsl_proc_flag = 0;
513*4882a593Smuzhiyun }
514*4882a593Smuzhiyun else if('r'==temp_buf[0]&&'e'==temp_buf[1])//read buf //
515*4882a593Smuzhiyun {
516*4882a593Smuzhiyun memcpy(gsl_read,temp_buf,4);
517*4882a593Smuzhiyun memcpy(gsl_data_proc,buf,8);
518*4882a593Smuzhiyun }
519*4882a593Smuzhiyun else if('w'==temp_buf[0]&&'r'==temp_buf[1])//write buf
520*4882a593Smuzhiyun {
521*4882a593Smuzhiyun gsl_ts_write(gsl_client,buf[4],buf,4);
522*4882a593Smuzhiyun }
523*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
524*4882a593Smuzhiyun else if('i'==temp_buf[0]&&'d'==temp_buf[1])//write id config //
525*4882a593Smuzhiyun {
526*4882a593Smuzhiyun tmp1=(buf[7]<<24)|(buf[6]<<16)|(buf[5]<<8)|buf[4];
527*4882a593Smuzhiyun tmp=(buf[3]<<24)|(buf[2]<<16)|(buf[1]<<8)|buf[0];
528*4882a593Smuzhiyun if(tmp1>=0 && tmp1<ts->gsl_chip_info->conf_in_len)
529*4882a593Smuzhiyun {
530*4882a593Smuzhiyun ts->gsl_chip_info->conf_in[tmp1] = tmp;
531*4882a593Smuzhiyun }
532*4882a593Smuzhiyun }
533*4882a593Smuzhiyun #endif
534*4882a593Smuzhiyun exit_write_proc_out:
535*4882a593Smuzhiyun kfree(path_buf);
536*4882a593Smuzhiyun return count;
537*4882a593Smuzhiyun }
538*4882a593Smuzhiyun
gsl_server_list_open(struct inode * inode,struct file * file)539*4882a593Smuzhiyun static int gsl_server_list_open(struct inode *inode,struct file *file)
540*4882a593Smuzhiyun {
541*4882a593Smuzhiyun return single_open(file,gsl_config_read_proc,NULL);
542*4882a593Smuzhiyun }
543*4882a593Smuzhiyun static const struct proc_ops gsl_seq_fops = {
544*4882a593Smuzhiyun .proc_open = gsl_server_list_open,
545*4882a593Smuzhiyun .proc_read = seq_read,
546*4882a593Smuzhiyun .proc_release = single_release,
547*4882a593Smuzhiyun .proc_write = gsl_config_write_proc,
548*4882a593Smuzhiyun };
549*4882a593Smuzhiyun #endif
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun #ifdef FILTER_POINT
filter_point(u16 x,u16 y,u8 id)552*4882a593Smuzhiyun static void filter_point(u16 x, u16 y , u8 id)
553*4882a593Smuzhiyun {
554*4882a593Smuzhiyun u16 x_err =0;
555*4882a593Smuzhiyun u16 y_err =0;
556*4882a593Smuzhiyun u16 filter_step_x = 0, filter_step_y = 0;
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun id_sign[id] = id_sign[id] + 1;
559*4882a593Smuzhiyun if(id_sign[id] == 1)
560*4882a593Smuzhiyun {
561*4882a593Smuzhiyun x_old[id] = x;
562*4882a593Smuzhiyun y_old[id] = y;
563*4882a593Smuzhiyun }
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun x_err = x > x_old[id] ? (x -x_old[id]) : (x_old[id] - x);
566*4882a593Smuzhiyun y_err = y > y_old[id] ? (y -y_old[id]) : (y_old[id] - y);
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun if( (x_err > FILTER_MAX && y_err > FILTER_MAX/3) || (x_err > FILTER_MAX/3 && y_err > FILTER_MAX) )
569*4882a593Smuzhiyun {
570*4882a593Smuzhiyun filter_step_x = x_err;
571*4882a593Smuzhiyun filter_step_y = y_err;
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun else
574*4882a593Smuzhiyun {
575*4882a593Smuzhiyun if(x_err > FILTER_MAX)
576*4882a593Smuzhiyun filter_step_x = x_err;
577*4882a593Smuzhiyun if(y_err> FILTER_MAX)
578*4882a593Smuzhiyun filter_step_y = y_err;
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun if(x_err <= 2*FILTER_MAX && y_err <= 2*FILTER_MAX)
582*4882a593Smuzhiyun {
583*4882a593Smuzhiyun filter_step_x >>= 2;
584*4882a593Smuzhiyun filter_step_y >>= 2;
585*4882a593Smuzhiyun }
586*4882a593Smuzhiyun else if(x_err <= 3*FILTER_MAX && y_err <= 3*FILTER_MAX)
587*4882a593Smuzhiyun {
588*4882a593Smuzhiyun filter_step_x >>= 1;
589*4882a593Smuzhiyun filter_step_y >>= 1;
590*4882a593Smuzhiyun }
591*4882a593Smuzhiyun else if(x_err <= 4*FILTER_MAX && y_err <= 4*FILTER_MAX)
592*4882a593Smuzhiyun {
593*4882a593Smuzhiyun filter_step_x = filter_step_x*3/4;
594*4882a593Smuzhiyun filter_step_y = filter_step_y*3/4;
595*4882a593Smuzhiyun }
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun x_new = x > x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] - filter_step_x);
598*4882a593Smuzhiyun y_new = y > y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] - filter_step_y);
599*4882a593Smuzhiyun
600*4882a593Smuzhiyun x_old[id] = x_new;
601*4882a593Smuzhiyun y_old[id] = y_new;
602*4882a593Smuzhiyun }
603*4882a593Smuzhiyun #else
record_point(u16 x,u16 y,u8 id)604*4882a593Smuzhiyun static void record_point(u16 x, u16 y , u8 id)
605*4882a593Smuzhiyun {
606*4882a593Smuzhiyun u16 x_err =0;
607*4882a593Smuzhiyun u16 y_err =0;
608*4882a593Smuzhiyun return;
609*4882a593Smuzhiyun id_sign[id]=id_sign[id]+1;
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun if(id_sign[id]==1){
612*4882a593Smuzhiyun x_old[id]=x;
613*4882a593Smuzhiyun y_old[id]=y;
614*4882a593Smuzhiyun }
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun x = (x_old[id] + x)/2;
617*4882a593Smuzhiyun y = (y_old[id] + y)/2;
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun if(x>x_old[id]){
620*4882a593Smuzhiyun x_err=x -x_old[id];
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun else{
623*4882a593Smuzhiyun x_err=x_old[id]-x;
624*4882a593Smuzhiyun }
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun if(y>y_old[id]){
627*4882a593Smuzhiyun y_err=y -y_old[id];
628*4882a593Smuzhiyun }
629*4882a593Smuzhiyun else{
630*4882a593Smuzhiyun y_err=y_old[id]-y;
631*4882a593Smuzhiyun }
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun if( (x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3) ){
634*4882a593Smuzhiyun x_new = x; x_old[id] = x;
635*4882a593Smuzhiyun y_new = y; y_old[id] = y;
636*4882a593Smuzhiyun }
637*4882a593Smuzhiyun else{
638*4882a593Smuzhiyun if(x_err > 3){
639*4882a593Smuzhiyun x_new = x; x_old[id] = x;
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun else
642*4882a593Smuzhiyun x_new = x_old[id];
643*4882a593Smuzhiyun if(y_err> 3){
644*4882a593Smuzhiyun y_new = y; y_old[id] = y;
645*4882a593Smuzhiyun }
646*4882a593Smuzhiyun else
647*4882a593Smuzhiyun y_new = y_old[id];
648*4882a593Smuzhiyun }
649*4882a593Smuzhiyun
650*4882a593Smuzhiyun if(id_sign[id]==1){
651*4882a593Smuzhiyun x_new= x_old[id];
652*4882a593Smuzhiyun y_new= y_old[id];
653*4882a593Smuzhiyun }
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun }
656*4882a593Smuzhiyun #endif
657*4882a593Smuzhiyun
report_data(struct gsl_ts * ts,u16 x,u16 y,u8 pressure,u8 id)658*4882a593Smuzhiyun static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
659*4882a593Smuzhiyun {
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun if(revert_xy)
662*4882a593Smuzhiyun swap(x, y);
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun if(x > ts->screen_max_x || y > ts->screen_max_y)
665*4882a593Smuzhiyun {
666*4882a593Smuzhiyun return;
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun if(revert_x)
670*4882a593Smuzhiyun x = ts->screen_max_x-x;
671*4882a593Smuzhiyun if(revert_y) {
672*4882a593Smuzhiyun y = ts->screen_max_y-y;
673*4882a593Smuzhiyun }
674*4882a593Smuzhiyun
675*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
676*4882a593Smuzhiyun input_mt_slot(ts->input, id);
677*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
678*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
679*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_X, x);
680*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
681*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
682*4882a593Smuzhiyun #else
683*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
684*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
685*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_X,x);
686*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
687*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
688*4882a593Smuzhiyun input_mt_sync(ts->input);
689*4882a593Smuzhiyun #endif
690*4882a593Smuzhiyun }
691*4882a593Smuzhiyun
gslX680_ts_worker(struct work_struct * work)692*4882a593Smuzhiyun static void gslX680_ts_worker(struct work_struct *work)
693*4882a593Smuzhiyun {
694*4882a593Smuzhiyun int rc, i;
695*4882a593Smuzhiyun u8 id, touches;
696*4882a593Smuzhiyun u16 x, y;
697*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
698*4882a593Smuzhiyun unsigned int tmp1;
699*4882a593Smuzhiyun u8 buf[4] = {0};
700*4882a593Smuzhiyun struct gsl_touch_info cinfo = {{0}};
701*4882a593Smuzhiyun #endif
702*4882a593Smuzhiyun struct gsl_ts *ts = container_of(work, struct gsl_ts,work);
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
705*4882a593Smuzhiyun if(gsl_proc_flag == 1)
706*4882a593Smuzhiyun goto schedule;
707*4882a593Smuzhiyun #endif
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
710*4882a593Smuzhiyun if (rc < 0)
711*4882a593Smuzhiyun {
712*4882a593Smuzhiyun dev_err(&ts->client->dev, "read failed\n");
713*4882a593Smuzhiyun reset_chip(ts->client);
714*4882a593Smuzhiyun startup_chip(ts->client);
715*4882a593Smuzhiyun goto schedule;
716*4882a593Smuzhiyun }
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun touches = ts->touch_data[ts->dd->touch_index];
719*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
720*4882a593Smuzhiyun cinfo.finger_num = touches;
721*4882a593Smuzhiyun for(i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i ++)
722*4882a593Smuzhiyun {
723*4882a593Smuzhiyun cinfo.x[i] = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
724*4882a593Smuzhiyun ts->touch_data[ts->dd->x_index + 4 * i]);
725*4882a593Smuzhiyun cinfo.y[i] = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
726*4882a593Smuzhiyun ts->touch_data[ts->dd->y_index + 4 * i ]);
727*4882a593Smuzhiyun cinfo.id[i] = ((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf0)>>4);
728*4882a593Smuzhiyun }
729*4882a593Smuzhiyun cinfo.finger_num=(ts->touch_data[3]<<24)|(ts->touch_data[2]<<16)
730*4882a593Smuzhiyun |(ts->touch_data[1]<<8)|(ts->touch_data[0]);
731*4882a593Smuzhiyun gsl_alg_id_main(&cinfo);
732*4882a593Smuzhiyun tmp1=gsl_mask_tiaoping();
733*4882a593Smuzhiyun if(tmp1>0&&tmp1<0xffffffff)
734*4882a593Smuzhiyun {
735*4882a593Smuzhiyun buf[0]=0xa;buf[1]=0;buf[2]=0;buf[3]=0;
736*4882a593Smuzhiyun gsl_ts_write(ts->client,0xf0,buf,4);
737*4882a593Smuzhiyun buf[0]=(u8)(tmp1 & 0xff);
738*4882a593Smuzhiyun buf[1]=(u8)((tmp1>>8) & 0xff);
739*4882a593Smuzhiyun buf[2]=(u8)((tmp1>>16) & 0xff);
740*4882a593Smuzhiyun buf[3]=(u8)((tmp1>>24) & 0xff);
741*4882a593Smuzhiyun gsl_ts_write(ts->client,0x8,buf,4);
742*4882a593Smuzhiyun }
743*4882a593Smuzhiyun touches = cinfo.finger_num;
744*4882a593Smuzhiyun #endif
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun for(i = 1; i <= MAX_CONTACTS; i ++)
747*4882a593Smuzhiyun {
748*4882a593Smuzhiyun if(touches == 0)
749*4882a593Smuzhiyun id_sign[i] = 0;
750*4882a593Smuzhiyun id_state_flag[i] = 0;
751*4882a593Smuzhiyun }
752*4882a593Smuzhiyun for(i= 0;i < (touches > MAX_FINGERS ? MAX_FINGERS : touches);i ++)
753*4882a593Smuzhiyun {
754*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
755*4882a593Smuzhiyun {
756*4882a593Smuzhiyun id = cinfo.id[i];
757*4882a593Smuzhiyun x = cinfo.x[i];
758*4882a593Smuzhiyun y = cinfo.y[i];
759*4882a593Smuzhiyun }
760*4882a593Smuzhiyun #else
761*4882a593Smuzhiyun {
762*4882a593Smuzhiyun x = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
763*4882a593Smuzhiyun ts->touch_data[ts->dd->x_index + 4 * i]);
764*4882a593Smuzhiyun y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
765*4882a593Smuzhiyun ts->touch_data[ts->dd->y_index + 4 * i ]);
766*4882a593Smuzhiyun id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
767*4882a593Smuzhiyun }
768*4882a593Smuzhiyun #endif
769*4882a593Smuzhiyun if(1 <=id && id <= MAX_CONTACTS)
770*4882a593Smuzhiyun {
771*4882a593Smuzhiyun #ifdef FILTER_POINT
772*4882a593Smuzhiyun filter_point(x, y ,id);
773*4882a593Smuzhiyun #else
774*4882a593Smuzhiyun record_point(x, y , id);
775*4882a593Smuzhiyun #endif
776*4882a593Smuzhiyun //report_data(ts, x_new, y_new, 10, id);
777*4882a593Smuzhiyun report_data(ts, x, y, 10, id);
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun id_state_flag[id] = 1;
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun }
782*4882a593Smuzhiyun for(i = 1; i <= MAX_CONTACTS; i ++)
783*4882a593Smuzhiyun {
784*4882a593Smuzhiyun if( (0 == touches) || ((0 != id_state_old_flag[i]) && (0 == id_state_flag[i])) )
785*4882a593Smuzhiyun {
786*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
787*4882a593Smuzhiyun input_mt_slot(ts->input, i);
788*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
789*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
790*4882a593Smuzhiyun #endif
791*4882a593Smuzhiyun id_sign[i]=0;
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun id_state_old_flag[i] = id_state_flag[i];
794*4882a593Smuzhiyun }
795*4882a593Smuzhiyun if(0 == touches)
796*4882a593Smuzhiyun {
797*4882a593Smuzhiyun #ifndef REPORT_DATA_ANDROID_4_0
798*4882a593Smuzhiyun input_mt_sync(ts->input);
799*4882a593Smuzhiyun #endif
800*4882a593Smuzhiyun }
801*4882a593Smuzhiyun input_sync(ts->input);
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun schedule:
804*4882a593Smuzhiyun enable_irq(ts->irq);
805*4882a593Smuzhiyun
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun
gsl_ts_irq(int irq,void * dev_id)808*4882a593Smuzhiyun static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
809*4882a593Smuzhiyun {
810*4882a593Smuzhiyun struct gsl_ts *ts = dev_id;
811*4882a593Smuzhiyun
812*4882a593Smuzhiyun disable_irq_nosync(ts->irq);
813*4882a593Smuzhiyun
814*4882a593Smuzhiyun if (!work_pending(&ts->work))
815*4882a593Smuzhiyun {
816*4882a593Smuzhiyun queue_work(ts->wq, &ts->work);
817*4882a593Smuzhiyun }
818*4882a593Smuzhiyun
819*4882a593Smuzhiyun return IRQ_HANDLED;
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun }
822*4882a593Smuzhiyun
gslX680_ts_init(struct i2c_client * client,struct gsl_ts * ts)823*4882a593Smuzhiyun static int gslX680_ts_init(struct i2c_client *client, struct gsl_ts *ts)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun struct input_dev *input_device;
826*4882a593Smuzhiyun int rc = 0;
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun ts->dd = &devices[ts->device_id];
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun if (ts->device_id == 0) {
831*4882a593Smuzhiyun ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
832*4882a593Smuzhiyun ts->dd->touch_index = 0;
833*4882a593Smuzhiyun }
834*4882a593Smuzhiyun
835*4882a593Smuzhiyun ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL);
836*4882a593Smuzhiyun if (!ts->touch_data) {
837*4882a593Smuzhiyun pr_err("%s: Unable to allocate memory\n", __func__);
838*4882a593Smuzhiyun return -ENOMEM;
839*4882a593Smuzhiyun }
840*4882a593Smuzhiyun
841*4882a593Smuzhiyun input_device = input_allocate_device();
842*4882a593Smuzhiyun if (!input_device) {
843*4882a593Smuzhiyun rc = -ENOMEM;
844*4882a593Smuzhiyun goto error_alloc_dev;
845*4882a593Smuzhiyun }
846*4882a593Smuzhiyun
847*4882a593Smuzhiyun ts->input = input_device;
848*4882a593Smuzhiyun input_device->name = GSLX680_I2C_NAME;
849*4882a593Smuzhiyun input_device->id.bustype = BUS_I2C;
850*4882a593Smuzhiyun input_device->dev.parent = &client->dev;
851*4882a593Smuzhiyun input_set_drvdata(input_device, ts);
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
854*4882a593Smuzhiyun __set_bit(EV_ABS, input_device->evbit);
855*4882a593Smuzhiyun __set_bit(EV_KEY, input_device->evbit);
856*4882a593Smuzhiyun __set_bit(EV_REP, input_device->evbit);
857*4882a593Smuzhiyun __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
858*4882a593Smuzhiyun input_mt_init_slots(input_device, (MAX_CONTACTS+1),0);
859*4882a593Smuzhiyun #else
860*4882a593Smuzhiyun input_set_abs_params(input_device,ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0);
861*4882a593Smuzhiyun set_bit(EV_ABS, input_device->evbit);
862*4882a593Smuzhiyun set_bit(EV_KEY, input_device->evbit);
863*4882a593Smuzhiyun __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
864*4882a593Smuzhiyun input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
865*4882a593Smuzhiyun #endif
866*4882a593Smuzhiyun
867*4882a593Smuzhiyun set_bit(ABS_MT_POSITION_X, input_device->absbit);
868*4882a593Smuzhiyun set_bit(ABS_MT_POSITION_Y, input_device->absbit);
869*4882a593Smuzhiyun set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
870*4882a593Smuzhiyun set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
871*4882a593Smuzhiyun
872*4882a593Smuzhiyun input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, ts->screen_max_x, 0, 0);
873*4882a593Smuzhiyun input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, ts->screen_max_y, 0, 0);
874*4882a593Smuzhiyun input_set_abs_params(input_device,ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
875*4882a593Smuzhiyun input_set_abs_params(input_device,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
876*4882a593Smuzhiyun
877*4882a593Smuzhiyun ts->wq = create_singlethread_workqueue("kworkqueue_ts");
878*4882a593Smuzhiyun if (!ts->wq) {
879*4882a593Smuzhiyun dev_err(&client->dev, "Could not create workqueue\n");
880*4882a593Smuzhiyun goto error_wq_create;
881*4882a593Smuzhiyun }
882*4882a593Smuzhiyun flush_workqueue(ts->wq);
883*4882a593Smuzhiyun INIT_WORK(&ts->work, gslX680_ts_worker);
884*4882a593Smuzhiyun rc = input_register_device(input_device);
885*4882a593Smuzhiyun if (rc)
886*4882a593Smuzhiyun goto error_unreg_device;
887*4882a593Smuzhiyun return 0;
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun error_unreg_device:
890*4882a593Smuzhiyun destroy_workqueue(ts->wq);
891*4882a593Smuzhiyun error_wq_create:
892*4882a593Smuzhiyun input_free_device(input_device);
893*4882a593Smuzhiyun error_alloc_dev:
894*4882a593Smuzhiyun kfree(ts->touch_data);
895*4882a593Smuzhiyun return rc;
896*4882a593Smuzhiyun }
897*4882a593Smuzhiyun
gsl_ts_suspend(struct device * dev)898*4882a593Smuzhiyun static int gsl_ts_suspend(struct device *dev)
899*4882a593Smuzhiyun {
900*4882a593Smuzhiyun struct gsl_ts *ts = dev_get_drvdata(dev);
901*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
902*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
903*4882a593Smuzhiyun int i;
904*4882a593Smuzhiyun #endif
905*4882a593Smuzhiyun #endif
906*4882a593Smuzhiyun
907*4882a593Smuzhiyun disable_irq_nosync(ts->irq);
908*4882a593Smuzhiyun gslX680_shutdown_low();
909*4882a593Smuzhiyun
910*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
911*4882a593Smuzhiyun msleep(10);
912*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
913*4882a593Smuzhiyun for(i = 1; i <= MAX_CONTACTS ;i ++)
914*4882a593Smuzhiyun {
915*4882a593Smuzhiyun input_mt_slot(ts->input, i);
916*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
917*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
918*4882a593Smuzhiyun }
919*4882a593Smuzhiyun #else
920*4882a593Smuzhiyun input_mt_sync(ts->input);
921*4882a593Smuzhiyun #endif
922*4882a593Smuzhiyun input_sync(ts->input);
923*4882a593Smuzhiyun msleep(10);
924*4882a593Smuzhiyun report_data(ts, 1, 1, 10, 1);
925*4882a593Smuzhiyun input_sync(ts->input);
926*4882a593Smuzhiyun #endif
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun return 0;
929*4882a593Smuzhiyun }
930*4882a593Smuzhiyun
gsl_ts_resume(struct device * dev)931*4882a593Smuzhiyun static int gsl_ts_resume(struct device *dev)
932*4882a593Smuzhiyun {
933*4882a593Smuzhiyun struct gsl_ts *ts = dev_get_drvdata(dev);
934*4882a593Smuzhiyun
935*4882a593Smuzhiyun queue_work(ts->wq, &ts->resume_work);
936*4882a593Smuzhiyun
937*4882a593Smuzhiyun return 0;
938*4882a593Smuzhiyun }
939*4882a593Smuzhiyun
gsl_ts_early_suspend(struct tp_device * tp_d)940*4882a593Smuzhiyun static int gsl_ts_early_suspend(struct tp_device *tp_d)
941*4882a593Smuzhiyun {
942*4882a593Smuzhiyun struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun gsl_ts_suspend(&ts->client->dev);
945*4882a593Smuzhiyun
946*4882a593Smuzhiyun return 0;
947*4882a593Smuzhiyun }
948*4882a593Smuzhiyun
gsl_ts_late_resume(struct tp_device * tp_d)949*4882a593Smuzhiyun static int gsl_ts_late_resume(struct tp_device *tp_d)
950*4882a593Smuzhiyun {
951*4882a593Smuzhiyun struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun gsl_ts_resume(&ts->client->dev);
954*4882a593Smuzhiyun
955*4882a593Smuzhiyun return 0;
956*4882a593Smuzhiyun }
957*4882a593Smuzhiyun
gsl_download_fw_work(struct work_struct * work)958*4882a593Smuzhiyun static void gsl_download_fw_work(struct work_struct *work)
959*4882a593Smuzhiyun {
960*4882a593Smuzhiyun struct gsl_ts *ts = dev_get_drvdata(&gsl_client->dev);
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun clr_reg(ts->client);
963*4882a593Smuzhiyun reset_chip(ts->client);
964*4882a593Smuzhiyun gsl_load_fw(ts->client);
965*4882a593Smuzhiyun startup_chip(ts->client);
966*4882a593Smuzhiyun reset_chip(ts->client);
967*4882a593Smuzhiyun startup_chip(ts->client);
968*4882a593Smuzhiyun }
969*4882a593Smuzhiyun
gsl_resume_work(struct work_struct * work)970*4882a593Smuzhiyun static void gsl_resume_work(struct work_struct *work)
971*4882a593Smuzhiyun {
972*4882a593Smuzhiyun struct gsl_ts *ts = dev_get_drvdata(&gsl_client->dev);
973*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
974*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
975*4882a593Smuzhiyun int i;
976*4882a593Smuzhiyun #endif
977*4882a593Smuzhiyun #endif
978*4882a593Smuzhiyun gslX680_shutdown_high();
979*4882a593Smuzhiyun msleep(20);
980*4882a593Smuzhiyun //reset_chip(ts->client);
981*4882a593Smuzhiyun //startup_chip(ts->client);
982*4882a593Smuzhiyun check_mem_data(ts->client);
983*4882a593Smuzhiyun check_mem_data(ts->client);
984*4882a593Smuzhiyun
985*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
986*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
987*4882a593Smuzhiyun for(i =1;i<=MAX_CONTACTS;i++)
988*4882a593Smuzhiyun {
989*4882a593Smuzhiyun input_mt_slot(ts->input, i);
990*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
991*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
992*4882a593Smuzhiyun }
993*4882a593Smuzhiyun #else
994*4882a593Smuzhiyun input_mt_sync(ts->input);
995*4882a593Smuzhiyun #endif
996*4882a593Smuzhiyun input_sync(ts->input);
997*4882a593Smuzhiyun #endif
998*4882a593Smuzhiyun enable_irq(ts->irq);
999*4882a593Smuzhiyun }
1000*4882a593Smuzhiyun
gsl_ts_probe(struct i2c_client * client,const struct i2c_device_id * id)1001*4882a593Smuzhiyun static int gsl_ts_probe(struct i2c_client *client,
1002*4882a593Smuzhiyun const struct i2c_device_id *id)
1003*4882a593Smuzhiyun {
1004*4882a593Smuzhiyun struct device_node *np = client->dev.of_node;
1005*4882a593Smuzhiyun enum of_gpio_flags wake_flags, irq_flags;
1006*4882a593Smuzhiyun struct gsl_ts *ts;
1007*4882a593Smuzhiyun int rc;
1008*4882a593Smuzhiyun int gsl_chip_id = 0;
1009*4882a593Smuzhiyun int i,ret;
1010*4882a593Smuzhiyun
1011*4882a593Smuzhiyun printk("GSLX680 Enter %s\n", __func__);
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1014*4882a593Smuzhiyun dev_err(&client->dev, "I2C functionality not supported\n");
1015*4882a593Smuzhiyun return -ENODEV;
1016*4882a593Smuzhiyun }
1017*4882a593Smuzhiyun
1018*4882a593Smuzhiyun ts = kzalloc(sizeof(*ts), GFP_KERNEL);
1019*4882a593Smuzhiyun if (!ts)
1020*4882a593Smuzhiyun return -ENOMEM;
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun ts->client = client;
1023*4882a593Smuzhiyun i2c_set_clientdata(client, ts);
1024*4882a593Smuzhiyun ts->device_id = id->driver_data;
1025*4882a593Smuzhiyun
1026*4882a593Smuzhiyun
1027*4882a593Smuzhiyun of_property_read_u32(np,"screen_max_x",&(ts->screen_max_x));
1028*4882a593Smuzhiyun of_property_read_u32(np,"screen_max_y",&(ts->screen_max_y));
1029*4882a593Smuzhiyun
1030*4882a593Smuzhiyun dev_info(&ts->client->dev, "[tp-gsl] screen_max_x =[%d] \n",ts->screen_max_x);
1031*4882a593Smuzhiyun dev_info(&ts->client->dev, "[tp-gsl] screen_max_y =[%d] \n",ts->screen_max_y);
1032*4882a593Smuzhiyun
1033*4882a593Smuzhiyun of_property_read_u32(np, "revert_x", &revert_x);
1034*4882a593Smuzhiyun of_property_read_u32(np, "revert_y", &revert_y);
1035*4882a593Smuzhiyun of_property_read_u32(np, "revert_xy", &revert_xy);
1036*4882a593Smuzhiyun
1037*4882a593Smuzhiyun dev_info(&ts->client->dev, "[tp-gsl] revert_x =[%d] \n",revert_x);
1038*4882a593Smuzhiyun dev_info(&ts->client->dev, "[tp-gsl] revert_y =[%d] \n",revert_y);
1039*4882a593Smuzhiyun dev_info(&ts->client->dev, "[tp-gsl] revert_xy =[%d] \n",revert_xy);
1040*4882a593Smuzhiyun
1041*4882a593Smuzhiyun ts->irq_pin=of_get_named_gpio_flags(np, "touch-gpio", 0, &irq_flags);
1042*4882a593Smuzhiyun ts->wake_pin=of_get_named_gpio_flags(np, "reset-gpio", 0, &wake_flags);
1043*4882a593Smuzhiyun
1044*4882a593Smuzhiyun ret = of_property_read_u32(np, "chip_id", &gsl_chip_id);
1045*4882a593Smuzhiyun if (ret)
1046*4882a593Smuzhiyun gsl_chip_id = GSL680;
1047*4882a593Smuzhiyun
1048*4882a593Smuzhiyun dev_info(&ts->client->dev, "[tp-gsl] gsl_chip_id =[%d] \n",gsl_chip_id);
1049*4882a593Smuzhiyun for (i=0; i<ARRAY_SIZE(gsl_chip_info); i++) {
1050*4882a593Smuzhiyun if (gsl_chip_info[i].chip_id == gsl_chip_id) {
1051*4882a593Smuzhiyun ts->gsl_chip_info = &gsl_chip_info[i];
1052*4882a593Smuzhiyun break;
1053*4882a593Smuzhiyun }
1054*4882a593Smuzhiyun }
1055*4882a593Smuzhiyun
1056*4882a593Smuzhiyun if (gpio_is_valid(ts->wake_pin)) {
1057*4882a593Smuzhiyun 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");
1058*4882a593Smuzhiyun if (rc != 0) {
1059*4882a593Smuzhiyun dev_err(&ts->client->dev, "gslX680 wake pin error\n");
1060*4882a593Smuzhiyun return -EIO;
1061*4882a593Smuzhiyun }
1062*4882a593Smuzhiyun g_wake_pin = ts->wake_pin;
1063*4882a593Smuzhiyun } else {
1064*4882a593Smuzhiyun dev_info(&ts->client->dev, "wake pin invalid\n");
1065*4882a593Smuzhiyun }
1066*4882a593Smuzhiyun if (gpio_is_valid(ts->irq_pin)) {
1067*4882a593Smuzhiyun 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");
1068*4882a593Smuzhiyun if (rc != 0) {
1069*4882a593Smuzhiyun dev_err(&ts->client->dev, "gslX680 irq pin error\n");
1070*4882a593Smuzhiyun return -EIO;
1071*4882a593Smuzhiyun }
1072*4882a593Smuzhiyun g_irq_pin = ts->irq_pin;
1073*4882a593Smuzhiyun } else {
1074*4882a593Smuzhiyun dev_info(&ts->client->dev, "irq pin invalid\n");
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun
1077*4882a593Smuzhiyun INIT_WORK(&ts->download_fw_work, gsl_download_fw_work);
1078*4882a593Smuzhiyun INIT_WORK(&ts->resume_work, gsl_resume_work);
1079*4882a593Smuzhiyun
1080*4882a593Smuzhiyun gslX680_init();
1081*4882a593Smuzhiyun rc = gslX680_ts_init(client, ts);
1082*4882a593Smuzhiyun if (rc < 0) {
1083*4882a593Smuzhiyun dev_err(&client->dev, "GSLX680 init failed\n");
1084*4882a593Smuzhiyun goto error_mutex_destroy;
1085*4882a593Smuzhiyun }
1086*4882a593Smuzhiyun
1087*4882a593Smuzhiyun gsl_client = client;
1088*4882a593Smuzhiyun init_chip(ts->client);
1089*4882a593Smuzhiyun check_mem_data(ts->client);
1090*4882a593Smuzhiyun
1091*4882a593Smuzhiyun ts->irq=gpio_to_irq(ts->irq_pin); //If not defined in client
1092*4882a593Smuzhiyun if (ts->irq)
1093*4882a593Smuzhiyun {
1094*4882a593Smuzhiyun rc = devm_request_threaded_irq(&client->dev, ts->irq, NULL, gsl_ts_irq, irq_flags | IRQF_ONESHOT, client->name, ts);
1095*4882a593Smuzhiyun if (rc != 0) {
1096*4882a593Smuzhiyun dev_err(&client->dev, "Cannot allocate ts INT!ERRNO:%d\n", rc);
1097*4882a593Smuzhiyun goto error_req_irq_fail;
1098*4882a593Smuzhiyun }
1099*4882a593Smuzhiyun disable_irq(ts->irq);
1100*4882a593Smuzhiyun }
1101*4882a593Smuzhiyun else
1102*4882a593Smuzhiyun {
1103*4882a593Smuzhiyun dev_err(&client->dev, "gsl x680 irq req fail\n");
1104*4882a593Smuzhiyun goto error_req_irq_fail;
1105*4882a593Smuzhiyun }
1106*4882a593Smuzhiyun
1107*4882a593Smuzhiyun /* create debug attribute */
1108*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
1109*4882a593Smuzhiyun proc_create(GSL_CONFIG_PROC_FILE,0666,NULL,&gsl_seq_fops);
1110*4882a593Smuzhiyun gsl_proc_flag = 0;
1111*4882a593Smuzhiyun #endif
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun gpio_set_value(ts->irq_pin, 0);
1114*4882a593Smuzhiyun enable_irq(ts->irq);
1115*4882a593Smuzhiyun
1116*4882a593Smuzhiyun ts->tp.tp_resume = gsl_ts_late_resume;
1117*4882a593Smuzhiyun ts->tp.tp_suspend = gsl_ts_early_suspend;
1118*4882a593Smuzhiyun tp_register_fb(&ts->tp);
1119*4882a593Smuzhiyun
1120*4882a593Smuzhiyun return 0;
1121*4882a593Smuzhiyun
1122*4882a593Smuzhiyun //exit_set_irq_mode:
1123*4882a593Smuzhiyun error_req_irq_fail:
1124*4882a593Smuzhiyun free_irq(ts->irq, ts);
1125*4882a593Smuzhiyun
1126*4882a593Smuzhiyun error_mutex_destroy:
1127*4882a593Smuzhiyun input_free_device(ts->input);
1128*4882a593Smuzhiyun kfree(ts);
1129*4882a593Smuzhiyun return rc;
1130*4882a593Smuzhiyun }
1131*4882a593Smuzhiyun
gsl_ts_remove(struct i2c_client * client)1132*4882a593Smuzhiyun static int gsl_ts_remove(struct i2c_client *client)
1133*4882a593Smuzhiyun {
1134*4882a593Smuzhiyun struct gsl_ts *ts = i2c_get_clientdata(client);
1135*4882a593Smuzhiyun
1136*4882a593Smuzhiyun device_init_wakeup(&client->dev, 0);
1137*4882a593Smuzhiyun cancel_work_sync(&ts->work);
1138*4882a593Smuzhiyun free_irq(ts->irq, ts);
1139*4882a593Smuzhiyun destroy_workqueue(ts->wq);
1140*4882a593Smuzhiyun input_unregister_device(ts->input);
1141*4882a593Smuzhiyun
1142*4882a593Smuzhiyun kfree(ts->touch_data);
1143*4882a593Smuzhiyun kfree(ts);
1144*4882a593Smuzhiyun
1145*4882a593Smuzhiyun return 0;
1146*4882a593Smuzhiyun }
1147*4882a593Smuzhiyun
1148*4882a593Smuzhiyun static struct of_device_id gsl_ts_ids[] = {
1149*4882a593Smuzhiyun {.compatible = "gslX680-pad"},
1150*4882a593Smuzhiyun {}
1151*4882a593Smuzhiyun };
1152*4882a593Smuzhiyun
1153*4882a593Smuzhiyun static const struct i2c_device_id gsl_ts_id[] = {
1154*4882a593Smuzhiyun {GSLX680_I2C_NAME, 0},
1155*4882a593Smuzhiyun {}
1156*4882a593Smuzhiyun };
1157*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1158*4882a593Smuzhiyun
1159*4882a593Smuzhiyun #if !defined(CONFIG_DRM_FBDEV_EMULATION) && defined(CONFIG_PM)
1160*4882a593Smuzhiyun static const struct dev_pm_ops gsl_pm_ops = {
1161*4882a593Smuzhiyun .suspend = gsl_ts_suspend,
1162*4882a593Smuzhiyun .resume = gsl_ts_resume,
1163*4882a593Smuzhiyun };
1164*4882a593Smuzhiyun #endif
1165*4882a593Smuzhiyun
1166*4882a593Smuzhiyun static struct i2c_driver gsl_ts_driver = {
1167*4882a593Smuzhiyun .driver = {
1168*4882a593Smuzhiyun .name = GSLX680_I2C_NAME,
1169*4882a593Smuzhiyun .owner = THIS_MODULE,
1170*4882a593Smuzhiyun .of_match_table = of_match_ptr(gsl_ts_ids),
1171*4882a593Smuzhiyun #if !defined(CONFIG_DRM_FBDEV_EMULATION) && defined(CONFIG_PM)
1172*4882a593Smuzhiyun .pm = &gsl_pm_ops,
1173*4882a593Smuzhiyun #endif
1174*4882a593Smuzhiyun },
1175*4882a593Smuzhiyun .probe = gsl_ts_probe,
1176*4882a593Smuzhiyun .remove = gsl_ts_remove,
1177*4882a593Smuzhiyun .id_table = gsl_ts_id,
1178*4882a593Smuzhiyun };
1179*4882a593Smuzhiyun
gsl_ts_init(void)1180*4882a593Smuzhiyun static int __init gsl_ts_init(void)
1181*4882a593Smuzhiyun {
1182*4882a593Smuzhiyun int ret;
1183*4882a593Smuzhiyun ret = i2c_add_driver(&gsl_ts_driver);
1184*4882a593Smuzhiyun return ret;
1185*4882a593Smuzhiyun }
gsl_ts_exit(void)1186*4882a593Smuzhiyun static void __exit gsl_ts_exit(void)
1187*4882a593Smuzhiyun {
1188*4882a593Smuzhiyun i2c_del_driver(&gsl_ts_driver);
1189*4882a593Smuzhiyun return;
1190*4882a593Smuzhiyun }
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun module_init(gsl_ts_init);
1193*4882a593Smuzhiyun module_exit(gsl_ts_exit);
1194*4882a593Smuzhiyun
1195*4882a593Smuzhiyun MODULE_LICENSE("GPL");
1196*4882a593Smuzhiyun MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1197*4882a593Smuzhiyun MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1198*4882a593Smuzhiyun MODULE_ALIAS("platform:gsl_ts");
1199