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 #include <linux/module.h>
13*4882a593Smuzhiyun #include <linux/delay.h>
14*4882a593Smuzhiyun #include <linux/hrtimer.h>
15*4882a593Smuzhiyun #include <linux/i2c.h>
16*4882a593Smuzhiyun #include <linux/input.h>
17*4882a593Smuzhiyun #include <linux/interrupt.h>
18*4882a593Smuzhiyun #include <linux/io.h>
19*4882a593Smuzhiyun #include <linux/platform_device.h>
20*4882a593Smuzhiyun #include <linux/async.h>
21*4882a593Smuzhiyun #include <linux/gpio.h>
22*4882a593Smuzhiyun #include <asm/irq.h>
23*4882a593Smuzhiyun #include <linux/slab.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 //#include "rockchip_gslX680_rk3168.h"
29*4882a593Smuzhiyun #include "tp_suspend.h"
30*4882a593Smuzhiyun #include "gslx680.h"
31*4882a593Smuzhiyun #include <linux/of_gpio.h>
32*4882a593Smuzhiyun #include <linux/wakelock.h>
33*4882a593Smuzhiyun #include <linux/of_platform.h>
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #define GSL_DEBUG
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun /*
38*4882a593Smuzhiyun struct fw_data
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun u32 offset : 8;
41*4882a593Smuzhiyun u32 : 0;
42*4882a593Smuzhiyun u32 val;
43*4882a593Smuzhiyun };
44*4882a593Smuzhiyun */
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun #define RK_GEAR_TOUCH
47*4882a593Smuzhiyun #define REPORT_DATA_ANDROID_4_0
48*4882a593Smuzhiyun #define HAVE_TOUCH_KEY
49*4882a593Smuzhiyun //#define SLEEP_CLEAR_POINT
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun //#define FILTER_POINT
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun #ifdef FILTER_POINT
54*4882a593Smuzhiyun #define FILTER_MAX 9 //6
55*4882a593Smuzhiyun #endif
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun #define GSLX680_I2C_NAME "gslX680"
58*4882a593Smuzhiyun #define GSLX680_I2C_ADDR 0x40
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun //#define IRQ_PORT RK2928_PIN1_PB0//RK30_PIN1_PB7
61*4882a593Smuzhiyun //#define WAKE_PORT RK30_PIN0_PA1//RK30_PIN0_PB6
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun #define GSL_DATA_REG 0x80
64*4882a593Smuzhiyun #define GSL_STATUS_REG 0xe0
65*4882a593Smuzhiyun #define GSL_PAGE_REG 0xf0
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun #define TPD_PROC_DEBUG
68*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
69*4882a593Smuzhiyun #include <linux/proc_fs.h>
70*4882a593Smuzhiyun #include <linux/uaccess.h>
71*4882a593Smuzhiyun #include <linux/seq_file.h>
72*4882a593Smuzhiyun //static struct proc_dir_entry *gsl_config_proc = NULL;
73*4882a593Smuzhiyun #define GSL_CONFIG_PROC_FILE "gsl_config"
74*4882a593Smuzhiyun #define CONFIG_LEN 31
75*4882a593Smuzhiyun static char gsl_read[CONFIG_LEN];
76*4882a593Smuzhiyun static u8 gsl_data_proc[8] = { 0 };
77*4882a593Smuzhiyun static u8 gsl_proc_flag = 0;
78*4882a593Smuzhiyun static struct i2c_client *i2c_client = NULL;
79*4882a593Smuzhiyun #endif
80*4882a593Smuzhiyun #define GSL_MONITOR
81*4882a593Smuzhiyun #define PRESS_MAX 255
82*4882a593Smuzhiyun #define MAX_FINGERS 10
83*4882a593Smuzhiyun #define MAX_CONTACTS 10
84*4882a593Smuzhiyun #define DMA_TRANS_LEN 0x20
85*4882a593Smuzhiyun #ifdef GSL_MONITOR
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun #ifdef RK_GEAR_TOUCH
88*4882a593Smuzhiyun static int g_istouch=0;
89*4882a593Smuzhiyun #endif
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun static struct workqueue_struct *gsl_monitor_workqueue = NULL;
92*4882a593Smuzhiyun static u8 int_1st[4] = { 0 };
93*4882a593Smuzhiyun static u8 int_2nd[4] = { 0 };
94*4882a593Smuzhiyun //static char dac_counter = 0;
95*4882a593Smuzhiyun static char b0_counter = 0;
96*4882a593Smuzhiyun static char bc_counter = 0;
97*4882a593Smuzhiyun static char i2c_lock_flag = 0;
98*4882a593Smuzhiyun #endif
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun #define WRITE_I2C_SPEED (350*1000)
101*4882a593Smuzhiyun #define I2C_SPEED (200*1000)
102*4882a593Smuzhiyun #define CLOSE_TP_POWER 0
103*4882a593Smuzhiyun //add by yuandan
104*4882a593Smuzhiyun //#define HAVE_CLICK_TIMER
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun #ifdef HAVE_CLICK_TIMER
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun static struct workqueue_struct *gsl_timer_workqueue = NULL;
109*4882a593Smuzhiyun bool send_key = false;
110*4882a593Smuzhiyun struct semaphore my_sem;
111*4882a593Smuzhiyun #endif
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun #ifdef HAVE_TOUCH_KEY
114*4882a593Smuzhiyun static u16 key = 0;
115*4882a593Smuzhiyun static int key_state_flag = 0;
116*4882a593Smuzhiyun struct key_data {
117*4882a593Smuzhiyun u16 key;
118*4882a593Smuzhiyun u16 x_min;
119*4882a593Smuzhiyun u16 x_max;
120*4882a593Smuzhiyun u16 y_min;
121*4882a593Smuzhiyun u16 y_max;
122*4882a593Smuzhiyun };
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun const u16 key_array[] = {
125*4882a593Smuzhiyun KEY_LEFT,
126*4882a593Smuzhiyun KEY_RIGHT,
127*4882a593Smuzhiyun KEY_UP,
128*4882a593Smuzhiyun KEY_DOWN,
129*4882a593Smuzhiyun KEY_ENTER,
130*4882a593Smuzhiyun };
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun #define MAX_KEY_NUM (sizeof(key_array)/sizeof(key_array[0]))
133*4882a593Smuzhiyun //add by yuandan
134*4882a593Smuzhiyun static int key_x[512];
135*4882a593Smuzhiyun static int key_y[512];
136*4882a593Smuzhiyun static int key_count;
137*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
138*4882a593Smuzhiyun static const struct key_data gsl_key_data[MAX_KEY_NUM] = {
139*4882a593Smuzhiyun {KEY_BACK, 550, 650, 1400, 1600},
140*4882a593Smuzhiyun {KEY_HOMEPAGE, 350, 450, 1400, 1600},
141*4882a593Smuzhiyun {KEY_MENU, 150, 250, 1400, 1600},
142*4882a593Smuzhiyun {KEY_SEARCH, 2048, 2048, 2048, 2048},
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun #endif
145*4882a593Smuzhiyun #endif
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun struct gsl_ts_data {
148*4882a593Smuzhiyun u8 x_index;
149*4882a593Smuzhiyun u8 y_index;
150*4882a593Smuzhiyun u8 z_index;
151*4882a593Smuzhiyun u8 id_index;
152*4882a593Smuzhiyun u8 touch_index;
153*4882a593Smuzhiyun u8 data_reg;
154*4882a593Smuzhiyun u8 status_reg;
155*4882a593Smuzhiyun u8 data_size;
156*4882a593Smuzhiyun u8 touch_bytes;
157*4882a593Smuzhiyun u8 update_data;
158*4882a593Smuzhiyun u8 touch_meta_data;
159*4882a593Smuzhiyun u8 finger_size;
160*4882a593Smuzhiyun };
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun static struct gsl_ts_data devices[] = {
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun .x_index = 6,
165*4882a593Smuzhiyun .y_index = 4,
166*4882a593Smuzhiyun .z_index = 5,
167*4882a593Smuzhiyun .id_index = 7,
168*4882a593Smuzhiyun .data_reg = GSL_DATA_REG,
169*4882a593Smuzhiyun .status_reg = GSL_STATUS_REG,
170*4882a593Smuzhiyun .update_data = 0x4,
171*4882a593Smuzhiyun .touch_bytes = 4,
172*4882a593Smuzhiyun .touch_meta_data = 4,
173*4882a593Smuzhiyun .finger_size = 70,
174*4882a593Smuzhiyun },
175*4882a593Smuzhiyun };
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun struct gsl_ts_cfg {
178*4882a593Smuzhiyun struct fw_data *fw_ptr;
179*4882a593Smuzhiyun unsigned int fw_size;
180*4882a593Smuzhiyun enum gsl_quirk quirks;
181*4882a593Smuzhiyun unsigned int *cfg_id;
182*4882a593Smuzhiyun int max_x;
183*4882a593Smuzhiyun int max_y;
184*4882a593Smuzhiyun bool x_pol;
185*4882a593Smuzhiyun bool y_pol;
186*4882a593Smuzhiyun };
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun struct gsl_ts {
189*4882a593Smuzhiyun struct i2c_client *client;
190*4882a593Smuzhiyun struct input_dev *input;
191*4882a593Smuzhiyun struct work_struct work;
192*4882a593Smuzhiyun struct workqueue_struct *wq;
193*4882a593Smuzhiyun struct gsl_ts_data *dd;
194*4882a593Smuzhiyun int flag_irq_is_disable;
195*4882a593Smuzhiyun spinlock_t irq_lock;
196*4882a593Smuzhiyun u8 *touch_data;
197*4882a593Smuzhiyun u8 device_id;
198*4882a593Smuzhiyun int irq;
199*4882a593Smuzhiyun int rst;
200*4882a593Smuzhiyun struct delayed_work gsl_monitor_work;
201*4882a593Smuzhiyun #if defined(CONFIG_HAS_EARLYSUSPEND)
202*4882a593Smuzhiyun struct early_suspend early_suspend;
203*4882a593Smuzhiyun #endif
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun #if defined (HAVE_CLICK_TIMER)
206*4882a593Smuzhiyun struct work_struct click_work;
207*4882a593Smuzhiyun #endif
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun struct tp_device tp;
210*4882a593Smuzhiyun struct pinctrl *pinctrl;
211*4882a593Smuzhiyun struct pinctrl_state *pins_default;
212*4882a593Smuzhiyun struct pinctrl_state *pins_sleep;
213*4882a593Smuzhiyun struct pinctrl_state *pins_inactive;
214*4882a593Smuzhiyun const struct gsl_ts_cfg *ts_cfg;
215*4882a593Smuzhiyun };
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun #ifdef GSL_DEBUG
218*4882a593Smuzhiyun #define print_info(fmt, args...) printk(fmt, ##args);
219*4882a593Smuzhiyun #else
220*4882a593Smuzhiyun #define print_info(fmt, args...)
221*4882a593Smuzhiyun #endif
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun static u32 id_sign[MAX_CONTACTS + 1] = { 0 };
224*4882a593Smuzhiyun static u8 id_state_flag[MAX_CONTACTS + 1] = { 0 };
225*4882a593Smuzhiyun static u8 id_state_old_flag[MAX_CONTACTS + 1] = { 0 };
226*4882a593Smuzhiyun static u16 x_old[MAX_CONTACTS + 1] = { 0 };
227*4882a593Smuzhiyun static u16 y_old[MAX_CONTACTS + 1] = { 0 };
228*4882a593Smuzhiyun static u16 x_new = 0;
229*4882a593Smuzhiyun static u16 y_new = 0;
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun static const struct gsl_ts_cfg gslx680_vr_cfg = {
232*4882a593Smuzhiyun .fw_ptr = GSLX680_FW,
233*4882a593Smuzhiyun .fw_size = ARRAY_SIZE(GSLX680_FW),
234*4882a593Smuzhiyun .quirks = GSL_QUIRK_VR,
235*4882a593Smuzhiyun .cfg_id = gsl_config_data_id,
236*4882a593Smuzhiyun .max_x = SCREEN_MAX_X,
237*4882a593Smuzhiyun .max_y = SCREEN_MAX_Y,
238*4882a593Smuzhiyun .x_pol = false,
239*4882a593Smuzhiyun .y_pol = false,
240*4882a593Smuzhiyun };
241*4882a593Smuzhiyun
242*4882a593Smuzhiyun static const struct gsl_ts_cfg gslx680_tve_cfg = {
243*4882a593Smuzhiyun .fw_ptr = GSLX680_FW_TVE,
244*4882a593Smuzhiyun .fw_size = ARRAY_SIZE(GSLX680_FW_TVE),
245*4882a593Smuzhiyun .quirks = GSL_QUIRK_TVE,
246*4882a593Smuzhiyun .cfg_id = gsl_tve_cfg_id,
247*4882a593Smuzhiyun .max_x = SCREEN_MAX_X_TVE,
248*4882a593Smuzhiyun .max_y = SCREEN_MAX_Y_TVE,
249*4882a593Smuzhiyun .x_pol = true,
250*4882a593Smuzhiyun .y_pol = true,
251*4882a593Smuzhiyun };
252*4882a593Smuzhiyun
gslx680_set_pinctrl_state(struct gsl_ts * ts,struct pinctrl_state * state)253*4882a593Smuzhiyun int gslx680_set_pinctrl_state(struct gsl_ts *ts, struct pinctrl_state *state)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun int ret = 0;
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (!IS_ERR(state)) {
258*4882a593Smuzhiyun ret = pinctrl_select_state(ts->pinctrl, state);
259*4882a593Smuzhiyun if (ret)
260*4882a593Smuzhiyun printk("could not set pins \n");
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun return ret;
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun
gslX680_init(struct gsl_ts * ts)266*4882a593Smuzhiyun static int gslX680_init(struct gsl_ts *ts)
267*4882a593Smuzhiyun {
268*4882a593Smuzhiyun struct device_node *np = ts->client->dev.of_node;
269*4882a593Smuzhiyun int err = 0;
270*4882a593Smuzhiyun int ret = 0;
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun ts->irq = of_get_named_gpio_flags(np, "touch-gpio", 0, NULL);
273*4882a593Smuzhiyun ts->rst = of_get_named_gpio_flags(np, "reset-gpio", 0, NULL);
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun //msleep(20);
276*4882a593Smuzhiyun #if 0 //#if defined (CONFIG_BOARD_ZM71C)||defined (CONFIG_BOARD_ZM72CP) ||
277*4882a593Smuzhiyun defined(CONFIG_BOARD_ZM726C) || defined(CONFIG_BOARD_ZM726CE)
278*4882a593Smuzhiyun if (gpio_request(ts->rst, NULL) != 0) {
279*4882a593Smuzhiyun gpio_free(ts->rst);
280*4882a593Smuzhiyun printk("gslX680_init gpio_request error\n");
281*4882a593Smuzhiyun return -EIO;
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun #endif
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun /* pinctrl */
286*4882a593Smuzhiyun ts->pinctrl = devm_pinctrl_get(&ts->client->dev);
287*4882a593Smuzhiyun if (IS_ERR(ts->pinctrl)) {
288*4882a593Smuzhiyun ret = PTR_ERR(ts->pinctrl);
289*4882a593Smuzhiyun //goto out;
290*4882a593Smuzhiyun }
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun ts->pins_default =
293*4882a593Smuzhiyun pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_DEFAULT);
294*4882a593Smuzhiyun //if (IS_ERR(ts->pins_default))
295*4882a593Smuzhiyun // dev_err(&client->dev, "could not get default pinstate\n");
296*4882a593Smuzhiyun
297*4882a593Smuzhiyun ts->pins_sleep = pinctrl_lookup_state(ts->pinctrl, PINCTRL_STATE_SLEEP);
298*4882a593Smuzhiyun //if (IS_ERR(ts->pins_sleep))
299*4882a593Smuzhiyun // dev_err(&client->dev, "could not get sleep pinstate\n");
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun ts->pins_inactive = pinctrl_lookup_state(ts->pinctrl, "inactive");
302*4882a593Smuzhiyun //if (IS_ERR(ts->pins_inactive))
303*4882a593Smuzhiyun // dev_err(&client->dev, "could not get inactive pinstate\n");
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun err = gpio_request(ts->rst, "tp reset");
306*4882a593Smuzhiyun if (err) {
307*4882a593Smuzhiyun printk("gslx680 reset gpio request failed.\n");
308*4882a593Smuzhiyun return -1;
309*4882a593Smuzhiyun }
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun gslx680_set_pinctrl_state(ts, ts->pins_default);
312*4882a593Smuzhiyun gpio_direction_output(ts->rst, 1);
313*4882a593Smuzhiyun gpio_set_value(ts->rst, 1);
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun return 0;
316*4882a593Smuzhiyun }
317*4882a593Smuzhiyun
gslX680_shutdown_low(struct gsl_ts * ts)318*4882a593Smuzhiyun static int gslX680_shutdown_low(struct gsl_ts *ts)
319*4882a593Smuzhiyun {
320*4882a593Smuzhiyun printk("gsl gslX680_shutdown_low\n");
321*4882a593Smuzhiyun gpio_direction_output(ts->rst, 0);
322*4882a593Smuzhiyun gpio_set_value(ts->rst, 0);
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun return 0;
325*4882a593Smuzhiyun }
326*4882a593Smuzhiyun
gslX680_shutdown_high(struct gsl_ts * ts)327*4882a593Smuzhiyun static int gslX680_shutdown_high(struct gsl_ts *ts)
328*4882a593Smuzhiyun {
329*4882a593Smuzhiyun printk("gsl gslX680_shutdown_high\n");
330*4882a593Smuzhiyun gpio_direction_output(ts->rst, 1);
331*4882a593Smuzhiyun gpio_set_value(ts->rst, 1);
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun return 0;
334*4882a593Smuzhiyun }
335*4882a593Smuzhiyun
join_bytes(u8 a,u8 b)336*4882a593Smuzhiyun static inline u16 join_bytes(u8 a, u8 b)
337*4882a593Smuzhiyun {
338*4882a593Smuzhiyun u16 ab = 0;
339*4882a593Smuzhiyun
340*4882a593Smuzhiyun ab = ab | a;
341*4882a593Smuzhiyun ab = ab << 8 | b;
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun return ab;
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /*
347*4882a593Smuzhiyun static u32 gsl_read_interface(struct i2c_client *client,
348*4882a593Smuzhiyun u8 reg, u8 *buf, u32 num)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun struct i2c_msg xfer_msg[2];
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun xfer_msg[0].addr = client->addr;
353*4882a593Smuzhiyun xfer_msg[0].len = 1;
354*4882a593Smuzhiyun xfer_msg[0].flags = client->flags & I2C_M_TEN;
355*4882a593Smuzhiyun xfer_msg[0].buf = ®
356*4882a593Smuzhiyun xfer_msg[0].scl_rate=300*1000;
357*4882a593Smuzhiyun
358*4882a593Smuzhiyun xfer_msg[1].addr = client->addr;
359*4882a593Smuzhiyun xfer_msg[1].len = num;
360*4882a593Smuzhiyun xfer_msg[1].flags |= I2C_M_RD;
361*4882a593Smuzhiyun xfer_msg[1].buf = buf;
362*4882a593Smuzhiyun xfer_msg[1].scl_rate=300*1000;
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun if (reg < 0x80) {
365*4882a593Smuzhiyun i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
366*4882a593Smuzhiyun msleep(5);
367*4882a593Smuzhiyun }
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) \
370*4882a593Smuzhiyun == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
371*4882a593Smuzhiyun }
372*4882a593Smuzhiyun */
373*4882a593Smuzhiyun
gsl_write_interface(struct i2c_client * client,const u8 reg,u8 * buf,u32 num)374*4882a593Smuzhiyun static u32 gsl_write_interface(struct i2c_client *client,
375*4882a593Smuzhiyun const u8 reg, u8 *buf, u32 num)
376*4882a593Smuzhiyun {
377*4882a593Smuzhiyun struct i2c_msg xfer_msg[1];
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun buf[0] = reg;
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun xfer_msg[0].addr = client->addr;
382*4882a593Smuzhiyun xfer_msg[0].len = num + 1;
383*4882a593Smuzhiyun xfer_msg[0].flags = client->flags & I2C_M_TEN;
384*4882a593Smuzhiyun xfer_msg[0].buf = buf;
385*4882a593Smuzhiyun //xfer_msg[0].scl_rate = 100 * 1000;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun
gsl_ts_write(struct i2c_client * client,u8 addr,u8 * pdata,int datalen)390*4882a593Smuzhiyun static int gsl_ts_write(struct i2c_client *client,
391*4882a593Smuzhiyun u8 addr, u8 *pdata, int datalen)
392*4882a593Smuzhiyun {
393*4882a593Smuzhiyun int ret = 0;
394*4882a593Smuzhiyun u8 tmp_buf[128];
395*4882a593Smuzhiyun unsigned int bytelen = 0;
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun if (datalen > 125) {
398*4882a593Smuzhiyun printk("%s too big datalen = %d!\n", __func__, datalen);
399*4882a593Smuzhiyun return -1;
400*4882a593Smuzhiyun }
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun tmp_buf[0] = addr;
403*4882a593Smuzhiyun bytelen++;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun if (datalen != 0 && pdata != NULL) {
406*4882a593Smuzhiyun memcpy(&tmp_buf[bytelen], pdata, datalen);
407*4882a593Smuzhiyun bytelen += datalen;
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun ret = i2c_master_send(client, tmp_buf, bytelen);
411*4882a593Smuzhiyun return ret;
412*4882a593Smuzhiyun }
413*4882a593Smuzhiyun
gsl_ts_read(struct i2c_client * client,u8 addr,u8 * pdata,unsigned int datalen)414*4882a593Smuzhiyun static int gsl_ts_read(struct i2c_client *client, u8 addr,
415*4882a593Smuzhiyun u8 *pdata, unsigned int datalen)
416*4882a593Smuzhiyun {
417*4882a593Smuzhiyun int ret = 0;
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun if (datalen > 126) {
420*4882a593Smuzhiyun printk("%s too big datalen = %d!\n", __func__, datalen);
421*4882a593Smuzhiyun return -1;
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun ret = gsl_ts_write(client, addr, NULL, 0);
425*4882a593Smuzhiyun if (ret < 0) {
426*4882a593Smuzhiyun printk("%s set data address fail!\n", __func__);
427*4882a593Smuzhiyun return ret;
428*4882a593Smuzhiyun }
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun return i2c_master_recv(client, pdata, datalen);
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
fw2buf(u8 * buf,const u32 * fw)433*4882a593Smuzhiyun static __inline__ void fw2buf(u8 *buf, const u32 *fw)
434*4882a593Smuzhiyun {
435*4882a593Smuzhiyun u32 *u32_buf = (int *)buf;
436*4882a593Smuzhiyun *u32_buf = *fw;
437*4882a593Smuzhiyun }
438*4882a593Smuzhiyun
gsl_load_fw(struct i2c_client * client)439*4882a593Smuzhiyun static void gsl_load_fw(struct i2c_client *client)
440*4882a593Smuzhiyun {
441*4882a593Smuzhiyun u8 buf[DMA_TRANS_LEN * 4 + 1] = { 0 };
442*4882a593Smuzhiyun u8 send_flag = 1;
443*4882a593Smuzhiyun u8 *cur = buf + 1;
444*4882a593Smuzhiyun u32 source_line = 0;
445*4882a593Smuzhiyun u32 source_len;
446*4882a593Smuzhiyun //u8 read_buf[4] = {0};
447*4882a593Smuzhiyun struct gsl_ts *ts =
448*4882a593Smuzhiyun (struct gsl_ts *)i2c_get_clientdata(client);
449*4882a593Smuzhiyun struct fw_data const *ptr_fw = ts->ts_cfg->fw_ptr;
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun source_len = ts->ts_cfg->fw_size;
452*4882a593Smuzhiyun
453*4882a593Smuzhiyun for (source_line = 0; source_line < source_len; source_line++) {
454*4882a593Smuzhiyun /* init page trans, set the page val */
455*4882a593Smuzhiyun if (GSL_PAGE_REG == ptr_fw[source_line].offset) {
456*4882a593Smuzhiyun fw2buf(cur, &ptr_fw[source_line].val);
457*4882a593Smuzhiyun gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
458*4882a593Smuzhiyun send_flag = 1;
459*4882a593Smuzhiyun } else {
460*4882a593Smuzhiyun if (1 ==
461*4882a593Smuzhiyun send_flag % (DMA_TRANS_LEN <
462*4882a593Smuzhiyun 0x20 ? DMA_TRANS_LEN : 0x20))
463*4882a593Smuzhiyun buf[0] = (u8) ptr_fw[source_line].offset;
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun fw2buf(cur, &ptr_fw[source_line].val);
466*4882a593Smuzhiyun cur += 4;
467*4882a593Smuzhiyun
468*4882a593Smuzhiyun if (0 ==
469*4882a593Smuzhiyun send_flag % (DMA_TRANS_LEN <
470*4882a593Smuzhiyun 0x20 ? DMA_TRANS_LEN : 0x20)) {
471*4882a593Smuzhiyun gsl_write_interface(client, buf[0], buf,
472*4882a593Smuzhiyun cur - buf - 1);
473*4882a593Smuzhiyun cur = buf + 1;
474*4882a593Smuzhiyun }
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun send_flag++;
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun }
480*4882a593Smuzhiyun
test_i2c(struct i2c_client * client)481*4882a593Smuzhiyun static int test_i2c(struct i2c_client *client)
482*4882a593Smuzhiyun {
483*4882a593Smuzhiyun u8 read_buf = 0;
484*4882a593Smuzhiyun u8 write_buf = 0x12;
485*4882a593Smuzhiyun int ret, rc = 1;
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
488*4882a593Smuzhiyun if (ret < 0)
489*4882a593Smuzhiyun rc--;
490*4882a593Smuzhiyun else
491*4882a593Smuzhiyun printk("gsl I read reg 0xf0 is %x\n", read_buf);
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun msleep(2);
494*4882a593Smuzhiyun ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf));
495*4882a593Smuzhiyun if (ret >= 0)
496*4882a593Smuzhiyun printk("gsl I write reg 0xf0 0x12\n");
497*4882a593Smuzhiyun
498*4882a593Smuzhiyun msleep(2);
499*4882a593Smuzhiyun ret = gsl_ts_read(client, 0xf0, &read_buf, sizeof(read_buf));
500*4882a593Smuzhiyun if (ret < 0)
501*4882a593Smuzhiyun rc--;
502*4882a593Smuzhiyun else
503*4882a593Smuzhiyun printk("gsl I read reg 0xf0 is 0x%x\n", read_buf);
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun return rc;
506*4882a593Smuzhiyun }
startup_chip(struct i2c_client * client)507*4882a593Smuzhiyun static void startup_chip(struct i2c_client *client)
508*4882a593Smuzhiyun {
509*4882a593Smuzhiyun struct gsl_ts *ts =
510*4882a593Smuzhiyun (struct gsl_ts *)i2c_get_clientdata(client);
511*4882a593Smuzhiyun u8 tmp = 0x00;
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun printk("gsl startup_chip\n");
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
516*4882a593Smuzhiyun gsl_DataInit(ts->ts_cfg->cfg_id);
517*4882a593Smuzhiyun #endif
518*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &tmp, 1);
519*4882a593Smuzhiyun mdelay(10);
520*4882a593Smuzhiyun }
521*4882a593Smuzhiyun
reset_chip(struct i2c_client * client)522*4882a593Smuzhiyun static void reset_chip(struct i2c_client *client)
523*4882a593Smuzhiyun {
524*4882a593Smuzhiyun u8 tmp = 0x88;
525*4882a593Smuzhiyun u8 buf[4] = { 0x00 };
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun printk("gsl reset_chip\n");
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
530*4882a593Smuzhiyun mdelay(20);
531*4882a593Smuzhiyun tmp = 0x04;
532*4882a593Smuzhiyun gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
533*4882a593Smuzhiyun mdelay(10);
534*4882a593Smuzhiyun gsl_ts_write(client, 0xbc, buf, sizeof(buf));
535*4882a593Smuzhiyun mdelay(10);
536*4882a593Smuzhiyun }
537*4882a593Smuzhiyun
clr_reg(struct i2c_client * client)538*4882a593Smuzhiyun static void clr_reg(struct i2c_client *client)
539*4882a593Smuzhiyun {
540*4882a593Smuzhiyun u8 write_buf[4] = { 0 };
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun write_buf[0] = 0x88;
543*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &write_buf[0], 1);
544*4882a593Smuzhiyun mdelay(20);
545*4882a593Smuzhiyun write_buf[0] = 0x03;
546*4882a593Smuzhiyun gsl_ts_write(client, 0x80, &write_buf[0], 1);
547*4882a593Smuzhiyun mdelay(5);
548*4882a593Smuzhiyun write_buf[0] = 0x04;
549*4882a593Smuzhiyun gsl_ts_write(client, 0xe4, &write_buf[0], 1);
550*4882a593Smuzhiyun mdelay(5);
551*4882a593Smuzhiyun write_buf[0] = 0x00;
552*4882a593Smuzhiyun gsl_ts_write(client, 0xe0, &write_buf[0], 1);
553*4882a593Smuzhiyun mdelay(20);
554*4882a593Smuzhiyun }
555*4882a593Smuzhiyun
init_chip(struct i2c_client * client,struct gsl_ts * ts)556*4882a593Smuzhiyun static void init_chip(struct i2c_client *client, struct gsl_ts *ts)
557*4882a593Smuzhiyun {
558*4882a593Smuzhiyun int rc;
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun printk("gsl init_chip\n");
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun gslX680_shutdown_low(ts);
563*4882a593Smuzhiyun mdelay(20);
564*4882a593Smuzhiyun gslX680_shutdown_high(ts);
565*4882a593Smuzhiyun mdelay(20);
566*4882a593Smuzhiyun rc = test_i2c(client);
567*4882a593Smuzhiyun if (rc < 0) {
568*4882a593Smuzhiyun printk("gslX680 test_i2c error\n");
569*4882a593Smuzhiyun return;
570*4882a593Smuzhiyun }
571*4882a593Smuzhiyun clr_reg(client);
572*4882a593Smuzhiyun reset_chip(client);
573*4882a593Smuzhiyun gsl_load_fw(client);
574*4882a593Smuzhiyun startup_chip(client);
575*4882a593Smuzhiyun reset_chip(client);
576*4882a593Smuzhiyun startup_chip(client);
577*4882a593Smuzhiyun }
578*4882a593Smuzhiyun
check_mem_data(struct i2c_client * client,struct gsl_ts * ts)579*4882a593Smuzhiyun static void check_mem_data(struct i2c_client *client, struct gsl_ts *ts)
580*4882a593Smuzhiyun {
581*4882a593Smuzhiyun u8 read_buf[4] = { 0 };
582*4882a593Smuzhiyun
583*4882a593Smuzhiyun mdelay(30);
584*4882a593Smuzhiyun gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf));
585*4882a593Smuzhiyun if (read_buf[3] != 0x5a || read_buf[2] != 0x5a ||
586*4882a593Smuzhiyun read_buf[1] != 0x5a || read_buf[0] != 0x5a) {
587*4882a593Smuzhiyun init_chip(client, ts);
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun }
590*4882a593Smuzhiyun
591*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
char_to_int(char ch)592*4882a593Smuzhiyun static int char_to_int(char ch)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun if (ch >= '0' && ch <= '9')
595*4882a593Smuzhiyun return (ch - '0');
596*4882a593Smuzhiyun else
597*4882a593Smuzhiyun return (ch - 'a' + 10);
598*4882a593Smuzhiyun }
599*4882a593Smuzhiyun
gsl_config_read_proc(struct seq_file * m,void * v)600*4882a593Smuzhiyun static int gsl_config_read_proc(struct seq_file *m, void *v)
601*4882a593Smuzhiyun {
602*4882a593Smuzhiyun //char *ptr = page;
603*4882a593Smuzhiyun char temp_data[5] = { 0 };
604*4882a593Smuzhiyun unsigned int tmp = 0;
605*4882a593Smuzhiyun //unsigned int *ptr_fw;
606*4882a593Smuzhiyun struct gsl_ts *ts =
607*4882a593Smuzhiyun (struct gsl_ts *)i2c_get_clientdata(i2c_client);
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun if ('v' == gsl_read[0] && 's' == gsl_read[1]) {
610*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
611*4882a593Smuzhiyun tmp = gsl_version_id();
612*4882a593Smuzhiyun #else
613*4882a593Smuzhiyun tmp = 0x20121215;
614*4882a593Smuzhiyun #endif
615*4882a593Smuzhiyun seq_printf(m, "version:%x\n", tmp);
616*4882a593Smuzhiyun } else if ('r' == gsl_read[0] && 'e' == gsl_read[1]) {
617*4882a593Smuzhiyun if ('i' == gsl_read[3]) {
618*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
619*4882a593Smuzhiyun /* tmp=(gsl_data_proc[5]<<8) | gsl_data_proc[4];
620*4882a593Smuzhiyun seq_printf(m,"gsl_config_data_id[%d] = ",tmp);
621*4882a593Smuzhiyun if(tmp>=0&&tmp<gsl_cfg_table[gsl_cfg_index].data_size)
622*4882a593Smuzhiyun seq_printf(m,"%d\n",gsl_cfg_table[gsl_cfg_index].data_id[tmp]); */
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun tmp = (gsl_data_proc[5] << 8) | gsl_data_proc[4];
625*4882a593Smuzhiyun seq_printf(m, "gsl_config_data_id[%d] = ", tmp);
626*4882a593Smuzhiyun if (tmp >= 0 && tmp < 512)
627*4882a593Smuzhiyun seq_printf(m, "%d\n", ts->ts_cfg->cfg_id[tmp]);
628*4882a593Smuzhiyun #endif
629*4882a593Smuzhiyun } else {
630*4882a593Smuzhiyun i2c_smbus_write_i2c_block_data(i2c_client, 0xf0, 4,
631*4882a593Smuzhiyun &gsl_data_proc[4]);
632*4882a593Smuzhiyun if (gsl_data_proc[0] < 0x80)
633*4882a593Smuzhiyun i2c_smbus_read_i2c_block_data(i2c_client,
634*4882a593Smuzhiyun gsl_data_proc[0],
635*4882a593Smuzhiyun 4, temp_data);
636*4882a593Smuzhiyun i2c_smbus_read_i2c_block_data(i2c_client,
637*4882a593Smuzhiyun gsl_data_proc[0], 4,
638*4882a593Smuzhiyun temp_data);
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun seq_printf(m, "offset : {0x%02x,0x", gsl_data_proc[0]);
641*4882a593Smuzhiyun seq_printf(m, "%02x", temp_data[3]);
642*4882a593Smuzhiyun seq_printf(m, "%02x", temp_data[2]);
643*4882a593Smuzhiyun seq_printf(m, "%02x", temp_data[1]);
644*4882a593Smuzhiyun seq_printf(m, "%02x};\n", temp_data[0]);
645*4882a593Smuzhiyun }
646*4882a593Smuzhiyun }
647*4882a593Smuzhiyun return 0;
648*4882a593Smuzhiyun }
gsl_config_write_proc(struct file * file,const char * buffer,size_t count,loff_t * data)649*4882a593Smuzhiyun static ssize_t gsl_config_write_proc(struct file *file, const char *buffer,
650*4882a593Smuzhiyun size_t count, loff_t *data)
651*4882a593Smuzhiyun {
652*4882a593Smuzhiyun u8 buf[8] = { 0 };
653*4882a593Smuzhiyun char temp_buf[CONFIG_LEN];
654*4882a593Smuzhiyun char *path_buf;
655*4882a593Smuzhiyun int tmp = 0;
656*4882a593Smuzhiyun int tmp1 = 0;
657*4882a593Smuzhiyun struct gsl_ts *ts =
658*4882a593Smuzhiyun (struct gsl_ts *)i2c_get_clientdata(i2c_client);
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun print_info("[tp-gsl][%s] \n", __func__);
661*4882a593Smuzhiyun if (count > 512) {
662*4882a593Smuzhiyun //print_info("size not match [%d:%d]\n", CONFIG_LEN, count);
663*4882a593Smuzhiyun return -EFAULT;
664*4882a593Smuzhiyun }
665*4882a593Smuzhiyun path_buf = kzalloc(count, GFP_KERNEL);
666*4882a593Smuzhiyun if (!path_buf) {
667*4882a593Smuzhiyun printk("alloc path_buf memory error \n");
668*4882a593Smuzhiyun }
669*4882a593Smuzhiyun if (copy_from_user(path_buf, buffer, count)) {
670*4882a593Smuzhiyun print_info("copy from user fail\n");
671*4882a593Smuzhiyun goto exit_write_proc_out;
672*4882a593Smuzhiyun }
673*4882a593Smuzhiyun memcpy(temp_buf, path_buf, (count < CONFIG_LEN ? count : CONFIG_LEN));
674*4882a593Smuzhiyun print_info("[tp-gsl][%s][%s]\n", __func__, temp_buf);
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun buf[3] = char_to_int(temp_buf[14]) << 4 | char_to_int(temp_buf[15]);
677*4882a593Smuzhiyun buf[2] = char_to_int(temp_buf[16]) << 4 | char_to_int(temp_buf[17]);
678*4882a593Smuzhiyun buf[1] = char_to_int(temp_buf[18]) << 4 | char_to_int(temp_buf[19]);
679*4882a593Smuzhiyun buf[0] = char_to_int(temp_buf[20]) << 4 | char_to_int(temp_buf[21]);
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun buf[7] = char_to_int(temp_buf[5]) << 4 | char_to_int(temp_buf[6]);
682*4882a593Smuzhiyun buf[6] = char_to_int(temp_buf[7]) << 4 | char_to_int(temp_buf[8]);
683*4882a593Smuzhiyun buf[5] = char_to_int(temp_buf[9]) << 4 | char_to_int(temp_buf[10]);
684*4882a593Smuzhiyun buf[4] = char_to_int(temp_buf[11]) << 4 | char_to_int(temp_buf[12]);
685*4882a593Smuzhiyun if ('v' == temp_buf[0] && 's' == temp_buf[1]) {
686*4882a593Smuzhiyun //version //vs
687*4882a593Smuzhiyun memcpy(gsl_read, temp_buf, 4);
688*4882a593Smuzhiyun printk("gsl version\n");
689*4882a593Smuzhiyun } else if ('s' == temp_buf[0] && 't' == temp_buf[1]) {
690*4882a593Smuzhiyun //start //st
691*4882a593Smuzhiyun gsl_proc_flag = 1;
692*4882a593Smuzhiyun reset_chip(i2c_client);
693*4882a593Smuzhiyun } else if ('e' == temp_buf[0] && 'n' == temp_buf[1]) {
694*4882a593Smuzhiyun //end //en
695*4882a593Smuzhiyun mdelay(20);
696*4882a593Smuzhiyun reset_chip(i2c_client);
697*4882a593Smuzhiyun startup_chip(i2c_client);
698*4882a593Smuzhiyun gsl_proc_flag = 0;
699*4882a593Smuzhiyun } else if ('r' == temp_buf[0] && 'e' == temp_buf[1]) {
700*4882a593Smuzhiyun //read buf //
701*4882a593Smuzhiyun memcpy(gsl_read, temp_buf, 4);
702*4882a593Smuzhiyun memcpy(gsl_data_proc, buf, 8);
703*4882a593Smuzhiyun } else if ('w' == temp_buf[0] && 'r' == temp_buf[1]) {
704*4882a593Smuzhiyun //write buf
705*4882a593Smuzhiyun i2c_smbus_write_i2c_block_data(i2c_client, buf[4], 4, buf);
706*4882a593Smuzhiyun }
707*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
708*4882a593Smuzhiyun else if ('i' == temp_buf[0] && 'd' == temp_buf[1]) {
709*4882a593Smuzhiyun //write id config //
710*4882a593Smuzhiyun tmp1 = (buf[7] << 24) | (buf[6] << 16) | (buf[5] << 8) | buf[4];
711*4882a593Smuzhiyun tmp = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun if (tmp1 >= 0 && tmp1 < 512) {
714*4882a593Smuzhiyun ts->ts_cfg->cfg_id[tmp1] = tmp;
715*4882a593Smuzhiyun }
716*4882a593Smuzhiyun }
717*4882a593Smuzhiyun #endif
718*4882a593Smuzhiyun exit_write_proc_out:
719*4882a593Smuzhiyun kfree(path_buf);
720*4882a593Smuzhiyun return count;
721*4882a593Smuzhiyun }
722*4882a593Smuzhiyun
gsl_server_list_open(struct inode * inode,struct file * file)723*4882a593Smuzhiyun static int gsl_server_list_open(struct inode *inode, struct file *file)
724*4882a593Smuzhiyun {
725*4882a593Smuzhiyun return single_open(file, gsl_config_read_proc, NULL);
726*4882a593Smuzhiyun }
727*4882a593Smuzhiyun static const struct file_operations gsl_seq_fops = {
728*4882a593Smuzhiyun .open = gsl_server_list_open,
729*4882a593Smuzhiyun .read = seq_read,
730*4882a593Smuzhiyun .release = single_release,
731*4882a593Smuzhiyun .write = gsl_config_write_proc,
732*4882a593Smuzhiyun .owner = THIS_MODULE,
733*4882a593Smuzhiyun };
734*4882a593Smuzhiyun
735*4882a593Smuzhiyun #endif
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun #ifdef FILTER_POINT
filter_point(u16 x,u16 y,u8 id)738*4882a593Smuzhiyun static void filter_point(u16 x, u16 y, u8 id)
739*4882a593Smuzhiyun {
740*4882a593Smuzhiyun u16 x_err = 0;
741*4882a593Smuzhiyun u16 y_err = 0;
742*4882a593Smuzhiyun u16 filter_step_x = 0, filter_step_y = 0;
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun id_sign[id] = id_sign[id] + 1;
745*4882a593Smuzhiyun if (id_sign[id] == 1) {
746*4882a593Smuzhiyun x_old[id] = x;
747*4882a593Smuzhiyun y_old[id] = y;
748*4882a593Smuzhiyun }
749*4882a593Smuzhiyun
750*4882a593Smuzhiyun x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x);
751*4882a593Smuzhiyun y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y);
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun if ((x_err > FILTER_MAX && y_err > FILTER_MAX / 3) ||
754*4882a593Smuzhiyun (x_err > FILTER_MAX / 3 && y_err > FILTER_MAX)) {
755*4882a593Smuzhiyun filter_step_x = x_err;
756*4882a593Smuzhiyun filter_step_y = y_err;
757*4882a593Smuzhiyun } else {
758*4882a593Smuzhiyun if (x_err > FILTER_MAX)
759*4882a593Smuzhiyun filter_step_x = x_err;
760*4882a593Smuzhiyun if (y_err > FILTER_MAX)
761*4882a593Smuzhiyun filter_step_y = y_err;
762*4882a593Smuzhiyun }
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun if (x_err <= 2 * FILTER_MAX && y_err <= 2 * FILTER_MAX) {
765*4882a593Smuzhiyun filter_step_x >>= 2;
766*4882a593Smuzhiyun filter_step_y >>= 2;
767*4882a593Smuzhiyun } else if (x_err <= 3 * FILTER_MAX && y_err <= 3 * FILTER_MAX) {
768*4882a593Smuzhiyun filter_step_x >>= 1;
769*4882a593Smuzhiyun filter_step_y >>= 1;
770*4882a593Smuzhiyun } else if (x_err <= 4 * FILTER_MAX && y_err <= 4 * FILTER_MAX) {
771*4882a593Smuzhiyun filter_step_x = filter_step_x * 3 / 4;
772*4882a593Smuzhiyun filter_step_y = filter_step_y * 3 / 4;
773*4882a593Smuzhiyun }
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun x_new =
776*4882a593Smuzhiyun x >
777*4882a593Smuzhiyun x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] -
778*4882a593Smuzhiyun filter_step_x);
779*4882a593Smuzhiyun y_new =
780*4882a593Smuzhiyun y >
781*4882a593Smuzhiyun y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] -
782*4882a593Smuzhiyun filter_step_y);
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun x_old[id] = x_new;
785*4882a593Smuzhiyun y_old[id] = y_new;
786*4882a593Smuzhiyun }
787*4882a593Smuzhiyun #else
record_point(u16 x,u16 y,u8 id)788*4882a593Smuzhiyun static void record_point(u16 x, u16 y, u8 id)
789*4882a593Smuzhiyun {
790*4882a593Smuzhiyun u16 x_err = 0;
791*4882a593Smuzhiyun u16 y_err = 0;
792*4882a593Smuzhiyun
793*4882a593Smuzhiyun id_sign[id] = id_sign[id] + 1;
794*4882a593Smuzhiyun
795*4882a593Smuzhiyun if (id_sign[id] == 1) {
796*4882a593Smuzhiyun x_old[id] = x;
797*4882a593Smuzhiyun y_old[id] = y;
798*4882a593Smuzhiyun }
799*4882a593Smuzhiyun
800*4882a593Smuzhiyun x = (x_old[id] + x) / 2;
801*4882a593Smuzhiyun y = (y_old[id] + y) / 2;
802*4882a593Smuzhiyun
803*4882a593Smuzhiyun if (x > x_old[id]) {
804*4882a593Smuzhiyun x_err = x - x_old[id];
805*4882a593Smuzhiyun } else {
806*4882a593Smuzhiyun x_err = x_old[id] - x;
807*4882a593Smuzhiyun }
808*4882a593Smuzhiyun
809*4882a593Smuzhiyun if (y > y_old[id]) {
810*4882a593Smuzhiyun y_err = y - y_old[id];
811*4882a593Smuzhiyun } else {
812*4882a593Smuzhiyun y_err = y_old[id] - y;
813*4882a593Smuzhiyun }
814*4882a593Smuzhiyun
815*4882a593Smuzhiyun if ((x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3)) {
816*4882a593Smuzhiyun x_new = x;
817*4882a593Smuzhiyun x_old[id] = x;
818*4882a593Smuzhiyun y_new = y;
819*4882a593Smuzhiyun y_old[id] = y;
820*4882a593Smuzhiyun } else {
821*4882a593Smuzhiyun if (x_err > 3) {
822*4882a593Smuzhiyun x_new = x;
823*4882a593Smuzhiyun x_old[id] = x;
824*4882a593Smuzhiyun } else {
825*4882a593Smuzhiyun x_new = x_old[id];
826*4882a593Smuzhiyun }
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun if (y_err > 3) {
829*4882a593Smuzhiyun y_new = y;
830*4882a593Smuzhiyun y_old[id] = y;
831*4882a593Smuzhiyun } else {
832*4882a593Smuzhiyun y_new = y_old[id];
833*4882a593Smuzhiyun }
834*4882a593Smuzhiyun }
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun if (id_sign[id] == 1) {
837*4882a593Smuzhiyun x_new = x_old[id];
838*4882a593Smuzhiyun y_new = y_old[id];
839*4882a593Smuzhiyun }
840*4882a593Smuzhiyun }
841*4882a593Smuzhiyun #endif
842*4882a593Smuzhiyun
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
845*4882a593Smuzhiyun #ifdef HAVE_TOUCH_KEY
report_key(struct gsl_ts * ts,u16 x,u16 y)846*4882a593Smuzhiyun static void report_key(struct gsl_ts *ts, u16 x, u16 y)
847*4882a593Smuzhiyun {
848*4882a593Smuzhiyun u16 i = 0;
849*4882a593Smuzhiyun
850*4882a593Smuzhiyun for (i = 0; i < MAX_KEY_NUM; i++) {
851*4882a593Smuzhiyun if ((gsl_key_data[i].x_min < x)
852*4882a593Smuzhiyun && (x < gsl_key_data[i].x_max)
853*4882a593Smuzhiyun && (gsl_key_data[i].y_min < y)
854*4882a593Smuzhiyun && (y < gsl_key_data[i].y_max)) {
855*4882a593Smuzhiyun key = gsl_key_data[i].key;
856*4882a593Smuzhiyun input_report_key(ts->input, key, 1);
857*4882a593Smuzhiyun input_sync(ts->input);
858*4882a593Smuzhiyun key_state_flag = 1;
859*4882a593Smuzhiyun break;
860*4882a593Smuzhiyun }
861*4882a593Smuzhiyun }
862*4882a593Smuzhiyun }
863*4882a593Smuzhiyun #endif
864*4882a593Smuzhiyun #endif
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun #ifdef RK_GEAR_TOUCH
report_data(struct gsl_ts * ts,u16 x,u16 y,u8 pressure,u8 id)867*4882a593Smuzhiyun static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
868*4882a593Smuzhiyun {
869*4882a593Smuzhiyun #ifdef RK_GEAR_TOUCH
870*4882a593Smuzhiyun int delt_x,delt_y;
871*4882a593Smuzhiyun static int old_x=0, old_y=0;
872*4882a593Smuzhiyun #endif
873*4882a593Smuzhiyun int max_x = ts->ts_cfg->max_x;
874*4882a593Smuzhiyun int max_y = ts->ts_cfg->max_y;
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun //#ifndef SWAP_XY
877*4882a593Smuzhiyun // swap(x, y);
878*4882a593Smuzhiyun //#endif
879*4882a593Smuzhiyun //printk("#####id=%d,x=%d,y=%d######\n",id,x,y);
880*4882a593Smuzhiyun
881*4882a593Smuzhiyun if (x > max_x || y > max_y) {
882*4882a593Smuzhiyun #ifdef HAVE_TOUCH_KEY
883*4882a593Smuzhiyun //report_key(ts, x, y);
884*4882a593Smuzhiyun //printk("#####report_key x=%d,y=%d######\n",x,y);
885*4882a593Smuzhiyun #endif
886*4882a593Smuzhiyun return;
887*4882a593Smuzhiyun }
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun /*
890*4882a593Smuzhiyun input_mt_slot(ts->input_dev, id);
891*4882a593Smuzhiyun input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
892*4882a593Smuzhiyun input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
893*4882a593Smuzhiyun input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
894*4882a593Smuzhiyun input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
895*4882a593Smuzhiyun input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
896*4882a593Smuzhiyun */
897*4882a593Smuzhiyun
898*4882a593Smuzhiyun #ifdef RK_GEAR_TOUCH
899*4882a593Smuzhiyun if (ts->ts_cfg->quirks == GSL_QUIRK_VR) {
900*4882a593Smuzhiyun if (g_istouch == 0) {
901*4882a593Smuzhiyun g_istouch = 1;
902*4882a593Smuzhiyun input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
903*4882a593Smuzhiyun input_report_key(ts->input, 0x110, 1);
904*4882a593Smuzhiyun input_sync(ts->input);
905*4882a593Smuzhiyun }
906*4882a593Smuzhiyun delt_x = (int)x - old_x;
907*4882a593Smuzhiyun delt_y = (int)y - old_y;
908*4882a593Smuzhiyun delt_x /= 10;
909*4882a593Smuzhiyun delt_y /= 10;
910*4882a593Smuzhiyun input_report_rel(ts->input, REL_Y, -delt_x);
911*4882a593Smuzhiyun input_report_rel(ts->input, REL_X, -delt_y);
912*4882a593Smuzhiyun input_sync(ts->input);
913*4882a593Smuzhiyun old_x = x;
914*4882a593Smuzhiyun old_y = y;
915*4882a593Smuzhiyun return;
916*4882a593Smuzhiyun }
917*4882a593Smuzhiyun #endif
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
920*4882a593Smuzhiyun //printk("#####REPORT_DATA_ANDROID_4_0######\n");
921*4882a593Smuzhiyun input_mt_slot(ts->input, id);
922*4882a593Smuzhiyun //input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
923*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, 1);
924*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
925*4882a593Smuzhiyun if (ts->ts_cfg->x_pol)
926*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_X, max_x - x);
927*4882a593Smuzhiyun else
928*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_X, x);
929*4882a593Smuzhiyun if (ts->ts_cfg->y_pol)
930*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_Y, (max_y - y));
931*4882a593Smuzhiyun else
932*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_Y, (y));
933*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
934*4882a593Smuzhiyun #else
935*4882a593Smuzhiyun //printk("#####nonono REPORT_DATA_ANDROID_4_0######\n");
936*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
937*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
938*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_X, x);
939*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
940*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
941*4882a593Smuzhiyun input_mt_sync(ts->input);
942*4882a593Smuzhiyun #endif
943*4882a593Smuzhiyun }
944*4882a593Smuzhiyun #endif
945*4882a593Smuzhiyun
glsx680_ts_irq_disable(struct gsl_ts * ts)946*4882a593Smuzhiyun void glsx680_ts_irq_disable(struct gsl_ts *ts)
947*4882a593Smuzhiyun {
948*4882a593Smuzhiyun unsigned long irqflags;
949*4882a593Smuzhiyun
950*4882a593Smuzhiyun spin_lock_irqsave(&ts->irq_lock, irqflags);
951*4882a593Smuzhiyun if (!ts->flag_irq_is_disable) {
952*4882a593Smuzhiyun disable_irq_nosync(ts->client->irq);
953*4882a593Smuzhiyun ts->flag_irq_is_disable = 1;
954*4882a593Smuzhiyun }
955*4882a593Smuzhiyun spin_unlock_irqrestore(&ts->irq_lock, irqflags);
956*4882a593Smuzhiyun }
957*4882a593Smuzhiyun
glsx680_ts_irq_enable(struct gsl_ts * ts)958*4882a593Smuzhiyun void glsx680_ts_irq_enable(struct gsl_ts *ts)
959*4882a593Smuzhiyun {
960*4882a593Smuzhiyun unsigned long irqflags = 0;
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun spin_lock_irqsave(&ts->irq_lock, irqflags);
963*4882a593Smuzhiyun if (ts->flag_irq_is_disable) {
964*4882a593Smuzhiyun enable_irq(ts->client->irq);
965*4882a593Smuzhiyun ts->flag_irq_is_disable = 0;
966*4882a593Smuzhiyun }
967*4882a593Smuzhiyun spin_unlock_irqrestore(&ts->irq_lock, irqflags);
968*4882a593Smuzhiyun }
969*4882a593Smuzhiyun
gslX680_ts_worker(struct work_struct * work)970*4882a593Smuzhiyun static void gslX680_ts_worker(struct work_struct *work)
971*4882a593Smuzhiyun {
972*4882a593Smuzhiyun int rc, i;
973*4882a593Smuzhiyun u8 id, touches;
974*4882a593Smuzhiyun u16 x, y;
975*4882a593Smuzhiyun
976*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
977*4882a593Smuzhiyun u32 tmp1;
978*4882a593Smuzhiyun u8 buf[4] = { 0 };
979*4882a593Smuzhiyun struct gsl_touch_info cinfo;
980*4882a593Smuzhiyun #endif
981*4882a593Smuzhiyun
982*4882a593Smuzhiyun struct gsl_ts *ts = container_of(work, struct gsl_ts, work);
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
985*4882a593Smuzhiyun if (gsl_proc_flag == 1)
986*4882a593Smuzhiyun goto schedule;
987*4882a593Smuzhiyun #endif
988*4882a593Smuzhiyun
989*4882a593Smuzhiyun #ifdef GSL_MONITOR
990*4882a593Smuzhiyun if (i2c_lock_flag != 0)
991*4882a593Smuzhiyun goto i2c_lock_schedule;
992*4882a593Smuzhiyun else
993*4882a593Smuzhiyun i2c_lock_flag = 1;
994*4882a593Smuzhiyun #endif
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
997*4882a593Smuzhiyun if (rc < 0) {
998*4882a593Smuzhiyun dev_err(&ts->client->dev, "read failed\n");
999*4882a593Smuzhiyun goto schedule;
1000*4882a593Smuzhiyun }
1001*4882a593Smuzhiyun
1002*4882a593Smuzhiyun touches = ts->touch_data[ts->dd->touch_index];
1003*4882a593Smuzhiyun //print_info("-----touches: %d -----\n", touches);
1004*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
1005*4882a593Smuzhiyun
1006*4882a593Smuzhiyun cinfo.finger_num = touches;
1007*4882a593Smuzhiyun //print_info("tp-gsl finger_num = %d\n",cinfo.finger_num);
1008*4882a593Smuzhiyun for (i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i++) {
1009*4882a593Smuzhiyun cinfo.x[i] =
1010*4882a593Smuzhiyun join_bytes((ts->
1011*4882a593Smuzhiyun touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
1012*4882a593Smuzhiyun ts->touch_data[ts->dd->x_index + 4 * i]);
1013*4882a593Smuzhiyun cinfo.y[i] =
1014*4882a593Smuzhiyun join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
1015*4882a593Smuzhiyun ts->touch_data[ts->dd->y_index + 4 * i]);
1016*4882a593Smuzhiyun cinfo.id[i] =
1017*4882a593Smuzhiyun ((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf0) >> 4);
1018*4882a593Smuzhiyun /*print_info("tp-gsl before: x[%d] = %d, y[%d] = %d,
1019*4882a593Smuzhiyun id[%d] = %d \n",i,cinfo.x[i],i,cinfo.y[i],i,cinfo.id[i]);*/
1020*4882a593Smuzhiyun }
1021*4882a593Smuzhiyun cinfo.finger_num = (ts->touch_data[3] << 24) | (ts->touch_data[2] << 16)
1022*4882a593Smuzhiyun | (ts->touch_data[1] << 8) | (ts->touch_data[0]);
1023*4882a593Smuzhiyun gsl_alg_id_main(&cinfo);
1024*4882a593Smuzhiyun tmp1 = gsl_mask_tiaoping();
1025*4882a593Smuzhiyun //print_info("[tp-gsl] tmp1 = %x\n", tmp1);
1026*4882a593Smuzhiyun if (tmp1 > 0 && tmp1 < 0xffffffff) {
1027*4882a593Smuzhiyun buf[0] = 0xa;
1028*4882a593Smuzhiyun buf[1] = 0;
1029*4882a593Smuzhiyun buf[2] = 0;
1030*4882a593Smuzhiyun buf[3] = 0;
1031*4882a593Smuzhiyun gsl_ts_write(ts->client, 0xf0, buf, 4);
1032*4882a593Smuzhiyun buf[0] = (u8) (tmp1 & 0xff);
1033*4882a593Smuzhiyun buf[1] = (u8) ((tmp1 >> 8) & 0xff);
1034*4882a593Smuzhiyun buf[2] = (u8) ((tmp1 >> 16) & 0xff);
1035*4882a593Smuzhiyun buf[3] = (u8) ((tmp1 >> 24) & 0xff);
1036*4882a593Smuzhiyun print_info("tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x, \
1037*4882a593Smuzhiyun buf[3]=%02x\n", tmp1, buf[0], buf[1], buf[2], buf[3]);
1038*4882a593Smuzhiyun gsl_ts_write(ts->client, 0x8, buf, 4);
1039*4882a593Smuzhiyun }
1040*4882a593Smuzhiyun touches = cinfo.finger_num;
1041*4882a593Smuzhiyun #endif
1042*4882a593Smuzhiyun
1043*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1044*4882a593Smuzhiyun if (touches == 0)
1045*4882a593Smuzhiyun id_sign[i] = 0;
1046*4882a593Smuzhiyun id_state_flag[i] = 0;
1047*4882a593Smuzhiyun }
1048*4882a593Smuzhiyun for (i = 0; i < (touches > MAX_FINGERS ? MAX_FINGERS : touches); i++) {
1049*4882a593Smuzhiyun #ifdef GSL_NOID_VERSION
1050*4882a593Smuzhiyun id = cinfo.id[i];
1051*4882a593Smuzhiyun x = cinfo.x[i];
1052*4882a593Smuzhiyun y = cinfo.y[i];
1053*4882a593Smuzhiyun #else
1054*4882a593Smuzhiyun x = join_bytes((ts->
1055*4882a593Smuzhiyun touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
1056*4882a593Smuzhiyun ts->touch_data[ts->dd->x_index + 4 * i]);
1057*4882a593Smuzhiyun y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
1058*4882a593Smuzhiyun ts->touch_data[ts->dd->y_index + 4 * i]);
1059*4882a593Smuzhiyun id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
1060*4882a593Smuzhiyun #endif
1061*4882a593Smuzhiyun
1062*4882a593Smuzhiyun if (1 <= id && id <= MAX_CONTACTS) {
1063*4882a593Smuzhiyun #ifdef FILTER_POINT
1064*4882a593Smuzhiyun filter_point(x, y, id);
1065*4882a593Smuzhiyun #else
1066*4882a593Smuzhiyun record_point(x, y, id);
1067*4882a593Smuzhiyun #endif
1068*4882a593Smuzhiyun #ifdef RK_GEAR_TOUCH
1069*4882a593Smuzhiyun report_data(ts, x_new, y_new, 10, id);
1070*4882a593Smuzhiyun #endif
1071*4882a593Smuzhiyun if (key_count < 512) {
1072*4882a593Smuzhiyun key_x[key_count] = x_new;
1073*4882a593Smuzhiyun key_y[key_count] = y_new;
1074*4882a593Smuzhiyun key_count++;
1075*4882a593Smuzhiyun /*printk("test in key store in here,
1076*4882a593Smuzhiyun x_new is %d , y_new is %d ,
1077*4882a593Smuzhiyun key_count is %d \n", x_new ,y_new,key_count);*/
1078*4882a593Smuzhiyun }
1079*4882a593Smuzhiyun id_state_flag[id] = 1;
1080*4882a593Smuzhiyun }
1081*4882a593Smuzhiyun }
1082*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1083*4882a593Smuzhiyun if ((0 == touches)
1084*4882a593Smuzhiyun || ((0 != id_state_old_flag[i])
1085*4882a593Smuzhiyun && (0 == id_state_flag[i]))) {
1086*4882a593Smuzhiyun #ifdef RK_GEAR_TOUCH
1087*4882a593Smuzhiyun if (g_istouch == 1){
1088*4882a593Smuzhiyun g_istouch = 0;
1089*4882a593Smuzhiyun input_event(ts->input, EV_MSC, MSC_SCAN, 0x90001);
1090*4882a593Smuzhiyun input_report_key(ts->input, 0x110, 0);
1091*4882a593Smuzhiyun input_sync(ts->input);
1092*4882a593Smuzhiyun }
1093*4882a593Smuzhiyun g_istouch = 0;
1094*4882a593Smuzhiyun #endif
1095*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1096*4882a593Smuzhiyun input_mt_slot(ts->input, i);
1097*4882a593Smuzhiyun //input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1098*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER,
1099*4882a593Smuzhiyun false);
1100*4882a593Smuzhiyun #endif
1101*4882a593Smuzhiyun id_sign[i] = 0;
1102*4882a593Smuzhiyun }
1103*4882a593Smuzhiyun id_state_old_flag[i] = id_state_flag[i];
1104*4882a593Smuzhiyun }
1105*4882a593Smuzhiyun
1106*4882a593Smuzhiyun if (0 == touches) {
1107*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1108*4882a593Smuzhiyun #ifndef RK_GEAR_TOUCH
1109*4882a593Smuzhiyun //input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, 0);
1110*4882a593Smuzhiyun //input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 0);
1111*4882a593Smuzhiyun //input_mt_sync(ts->input);
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun int temp_x = 0;
1114*4882a593Smuzhiyun int temp_y = 0;
1115*4882a593Smuzhiyun temp_x =
1116*4882a593Smuzhiyun (((key_x[key_count - 1] - key_x[0]) >
1117*4882a593Smuzhiyun 0) ? (key_x[key_count - 1] - key_x[0])
1118*4882a593Smuzhiyun : (key_x[0] - key_x[key_count - 1]));
1119*4882a593Smuzhiyun temp_y =
1120*4882a593Smuzhiyun (((key_y[key_count - 1] - key_y[0]) >
1121*4882a593Smuzhiyun 0) ? (key_y[key_count - 1] - key_y[0])
1122*4882a593Smuzhiyun : (key_y[0] - key_y[key_count - 1]));
1123*4882a593Smuzhiyun if (key_count <= 512) {
1124*4882a593Smuzhiyun if (temp_x > temp_y) {
1125*4882a593Smuzhiyun if ((key_x[key_count - 1] - key_x[0]) > 100) {
1126*4882a593Smuzhiyun printk(" send up key \n");
1127*4882a593Smuzhiyun input_report_key(ts->input,
1128*4882a593Smuzhiyun key_array[2], 1);
1129*4882a593Smuzhiyun input_sync(ts->input);
1130*4882a593Smuzhiyun input_report_key(ts->input,
1131*4882a593Smuzhiyun key_array[2], 0);
1132*4882a593Smuzhiyun input_sync(ts->input);
1133*4882a593Smuzhiyun } else if ((key_x[0] - key_x[key_count - 1]) >
1134*4882a593Smuzhiyun 100) {
1135*4882a593Smuzhiyun printk(" send down key \n");
1136*4882a593Smuzhiyun input_report_key(ts->input,
1137*4882a593Smuzhiyun key_array[3], 1);
1138*4882a593Smuzhiyun input_sync(ts->input);
1139*4882a593Smuzhiyun input_report_key(ts->input,
1140*4882a593Smuzhiyun key_array[3], 0);
1141*4882a593Smuzhiyun input_sync(ts->input);
1142*4882a593Smuzhiyun }
1143*4882a593Smuzhiyun } else if (temp_x <= temp_y) {
1144*4882a593Smuzhiyun if ((key_y[key_count - 1] - key_y[0]) > 100) {
1145*4882a593Smuzhiyun printk(" send left key \n");
1146*4882a593Smuzhiyun input_report_key(ts->input,
1147*4882a593Smuzhiyun key_array[0], 1);
1148*4882a593Smuzhiyun input_sync(ts->input);
1149*4882a593Smuzhiyun input_report_key(ts->input,
1150*4882a593Smuzhiyun key_array[0], 0);
1151*4882a593Smuzhiyun input_sync(ts->input);
1152*4882a593Smuzhiyun } else if ((key_y[0] - key_y[key_count - 1]) >
1153*4882a593Smuzhiyun 100) {
1154*4882a593Smuzhiyun printk(" send right key \n");
1155*4882a593Smuzhiyun input_report_key(ts->input,
1156*4882a593Smuzhiyun key_array[1], 1);
1157*4882a593Smuzhiyun input_sync(ts->input);
1158*4882a593Smuzhiyun input_report_key(ts->input,
1159*4882a593Smuzhiyun key_array[1], 0);
1160*4882a593Smuzhiyun input_sync(ts->input);
1161*4882a593Smuzhiyun }
1162*4882a593Smuzhiyun }
1163*4882a593Smuzhiyun /*printk(" key_x[key_count -1], key_x[0],
1164*4882a593Smuzhiyun key_y[key_count -1], key_y[0] is %d ,%d , %d , %d\n",
1165*4882a593Smuzhiyun key_x[key_count -1], key_x[0], key_y[key_count -1],
1166*4882a593Smuzhiyun key_y[0]);*/
1167*4882a593Smuzhiyun if ((key_x[key_count - 1] - key_x[0] < 50)
1168*4882a593Smuzhiyun && (key_x[key_count - 1] - key_x[0] >= -50)
1169*4882a593Smuzhiyun && (key_y[key_count - 1] - key_y[0] < 50)
1170*4882a593Smuzhiyun && (key_y[key_count - 1] - key_y[0] >= -50)
1171*4882a593Smuzhiyun && (key_x[0] != 0) && (key_y[0] != 0)) {
1172*4882a593Smuzhiyun //queue_work(gsl_timer_workqueue,&ts->click_work);
1173*4882a593Smuzhiyun //printk(" send enter2 key by yuandan \n");
1174*4882a593Smuzhiyun //if(send_key)
1175*4882a593Smuzhiyun // {
1176*4882a593Smuzhiyun printk(" send enter key \n");
1177*4882a593Smuzhiyun input_report_key(ts->input, key_array[4], 1);
1178*4882a593Smuzhiyun input_sync(ts->input);
1179*4882a593Smuzhiyun input_report_key(ts->input, key_array[4], 0);
1180*4882a593Smuzhiyun input_sync(ts->input);
1181*4882a593Smuzhiyun // }else
1182*4882a593Smuzhiyun // {
1183*4882a593Smuzhiyun //down(&my_sem);
1184*4882a593Smuzhiyun // send_key = true;
1185*4882a593Smuzhiyun //up(&my_sem);
1186*4882a593Smuzhiyun // }
1187*4882a593Smuzhiyun }
1188*4882a593Smuzhiyun } else if (key_count > 512) {
1189*4882a593Smuzhiyun if (temp_x > temp_y) {
1190*4882a593Smuzhiyun if ((key_x[511] - key_x[0]) > 100) {
1191*4882a593Smuzhiyun printk(" send up key \n");
1192*4882a593Smuzhiyun input_report_key(ts->input,
1193*4882a593Smuzhiyun key_array[2], 1);
1194*4882a593Smuzhiyun input_sync(ts->input);
1195*4882a593Smuzhiyun input_report_key(ts->input,
1196*4882a593Smuzhiyun key_array[2], 0);
1197*4882a593Smuzhiyun input_sync(ts->input);
1198*4882a593Smuzhiyun } else if ((key_x[0] - key_x[511]) > 100) {
1199*4882a593Smuzhiyun printk(" send down key \n");
1200*4882a593Smuzhiyun input_report_key(ts->input,
1201*4882a593Smuzhiyun key_array[3], 1);
1202*4882a593Smuzhiyun input_sync(ts->input);
1203*4882a593Smuzhiyun input_report_key(ts->input,
1204*4882a593Smuzhiyun key_array[3], 0);
1205*4882a593Smuzhiyun input_sync(ts->input);
1206*4882a593Smuzhiyun }
1207*4882a593Smuzhiyun } else if (temp_x <= temp_y) {
1208*4882a593Smuzhiyun
1209*4882a593Smuzhiyun if ((key_y[511] - key_y[0]) > 100) {
1210*4882a593Smuzhiyun printk(" send left key \n");
1211*4882a593Smuzhiyun input_report_key(ts->input,
1212*4882a593Smuzhiyun key_array[0], 1);
1213*4882a593Smuzhiyun input_sync(ts->input);
1214*4882a593Smuzhiyun input_report_key(ts->input,
1215*4882a593Smuzhiyun key_array[0], 0);
1216*4882a593Smuzhiyun input_sync(ts->input);
1217*4882a593Smuzhiyun } else if ((key_y[0] - key_y[511]) > 100) {
1218*4882a593Smuzhiyun printk(" send right key \n");
1219*4882a593Smuzhiyun input_report_key(ts->input,
1220*4882a593Smuzhiyun key_array[1], 1);
1221*4882a593Smuzhiyun input_sync(ts->input);
1222*4882a593Smuzhiyun input_report_key(ts->input,
1223*4882a593Smuzhiyun key_array[1], 0);
1224*4882a593Smuzhiyun input_sync(ts->input);
1225*4882a593Smuzhiyun }
1226*4882a593Smuzhiyun }
1227*4882a593Smuzhiyun }
1228*4882a593Smuzhiyun memset(key_y, 0, sizeof(int) * 512);
1229*4882a593Smuzhiyun memset(key_x, 0, sizeof(int) * 512);
1230*4882a593Smuzhiyun key_count = 0;
1231*4882a593Smuzhiyun #endif
1232*4882a593Smuzhiyun #endif
1233*4882a593Smuzhiyun #ifdef HAVE_TOUCH_KEY
1234*4882a593Smuzhiyun if (key_state_flag) {
1235*4882a593Smuzhiyun input_report_key(ts->input, key, 0);
1236*4882a593Smuzhiyun input_sync(ts->input);
1237*4882a593Smuzhiyun key_state_flag = 0;
1238*4882a593Smuzhiyun }
1239*4882a593Smuzhiyun #endif
1240*4882a593Smuzhiyun
1241*4882a593Smuzhiyun }
1242*4882a593Smuzhiyun
1243*4882a593Smuzhiyun input_sync(ts->input);
1244*4882a593Smuzhiyun
1245*4882a593Smuzhiyun schedule:
1246*4882a593Smuzhiyun #ifdef GSL_MONITOR
1247*4882a593Smuzhiyun i2c_lock_flag = 0;
1248*4882a593Smuzhiyun i2c_lock_schedule:
1249*4882a593Smuzhiyun #endif
1250*4882a593Smuzhiyun glsx680_ts_irq_enable(ts);
1251*4882a593Smuzhiyun
1252*4882a593Smuzhiyun }
1253*4882a593Smuzhiyun
1254*4882a593Smuzhiyun #ifdef HAVE_CLICK_TIMER
1255*4882a593Smuzhiyun
click_timer_worker(struct work_struct * work)1256*4882a593Smuzhiyun static void click_timer_worker(struct work_struct *work)
1257*4882a593Smuzhiyun {
1258*4882a593Smuzhiyun while (true) {
1259*4882a593Smuzhiyun mdelay(500);
1260*4882a593Smuzhiyun //down(&my_sem);
1261*4882a593Smuzhiyun send_key = false;
1262*4882a593Smuzhiyun //up(&my_sem);
1263*4882a593Smuzhiyun }
1264*4882a593Smuzhiyun }
1265*4882a593Smuzhiyun
1266*4882a593Smuzhiyun #endif
1267*4882a593Smuzhiyun
1268*4882a593Smuzhiyun #ifdef GSL_MONITOR
gsl_monitor_worker(struct work_struct * work)1269*4882a593Smuzhiyun static void gsl_monitor_worker(struct work_struct *work)
1270*4882a593Smuzhiyun {
1271*4882a593Smuzhiyun //u8 write_buf[4] = {0};
1272*4882a593Smuzhiyun u8 read_buf[4] = { 0 };
1273*4882a593Smuzhiyun char init_chip_flag = 0;
1274*4882a593Smuzhiyun
1275*4882a593Smuzhiyun //print_info("gsl_monitor_worker\n");
1276*4882a593Smuzhiyun struct gsl_ts *ts =
1277*4882a593Smuzhiyun container_of(work, struct gsl_ts, gsl_monitor_work.work);
1278*4882a593Smuzhiyun if (i2c_lock_flag != 0) {
1279*4882a593Smuzhiyun i2c_lock_flag = 1;
1280*4882a593Smuzhiyun }
1281*4882a593Smuzhiyun //goto queue_monitor_work;
1282*4882a593Smuzhiyun else
1283*4882a593Smuzhiyun i2c_lock_flag = 1;
1284*4882a593Smuzhiyun
1285*4882a593Smuzhiyun //gsl_ts_read(ts->client, 0x80, read_buf, 4);
1286*4882a593Smuzhiyun /*printk("======read 0x80: %x %x %x %x ======tony0geshu\n",
1287*4882a593Smuzhiyun read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1288*4882a593Smuzhiyun
1289*4882a593Smuzhiyun gsl_ts_read(ts->client, 0xb0, read_buf, 4);
1290*4882a593Smuzhiyun if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a
1291*4882a593Smuzhiyun || read_buf[0] != 0x5a)
1292*4882a593Smuzhiyun b0_counter++;
1293*4882a593Smuzhiyun else
1294*4882a593Smuzhiyun b0_counter = 0;
1295*4882a593Smuzhiyun
1296*4882a593Smuzhiyun if (b0_counter > 1) {
1297*4882a593Smuzhiyun /*printk("======read 0xb0: %x %x %x %x ======\n",
1298*4882a593Smuzhiyun read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1299*4882a593Smuzhiyun init_chip_flag = 1;
1300*4882a593Smuzhiyun b0_counter = 0;
1301*4882a593Smuzhiyun }
1302*4882a593Smuzhiyun
1303*4882a593Smuzhiyun gsl_ts_read(ts->client, 0xb4, read_buf, 4);
1304*4882a593Smuzhiyun int_2nd[3] = int_1st[3];
1305*4882a593Smuzhiyun int_2nd[2] = int_1st[2];
1306*4882a593Smuzhiyun int_2nd[1] = int_1st[1];
1307*4882a593Smuzhiyun int_2nd[0] = int_1st[0];
1308*4882a593Smuzhiyun int_1st[3] = read_buf[3];
1309*4882a593Smuzhiyun int_1st[2] = read_buf[2];
1310*4882a593Smuzhiyun int_1st[1] = read_buf[1];
1311*4882a593Smuzhiyun int_1st[0] = read_buf[0];
1312*4882a593Smuzhiyun
1313*4882a593Smuzhiyun /*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1314*4882a593Smuzhiyun int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1315*4882a593Smuzhiyun int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1316*4882a593Smuzhiyun
1317*4882a593Smuzhiyun if (int_1st[3] == int_2nd[3] && int_1st[2] == int_2nd[2]
1318*4882a593Smuzhiyun && int_1st[1] == int_2nd[1] && int_1st[0] == int_2nd[0]) {
1319*4882a593Smuzhiyun /*printk("int_1st: %x %x %x %x , int_2nd: %x %x %x %x\n",
1320*4882a593Smuzhiyun int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1321*4882a593Smuzhiyun int_2nd[3], int_2nd[2],int_2nd[1],int_2nd[0]);*/
1322*4882a593Smuzhiyun init_chip_flag = 1;
1323*4882a593Smuzhiyun //goto queue_monitor_init_chip;
1324*4882a593Smuzhiyun }
1325*4882a593Smuzhiyun
1326*4882a593Smuzhiyun gsl_ts_read(ts->client, 0xbc, read_buf, 4);
1327*4882a593Smuzhiyun if (read_buf[3] != 0 || read_buf[2] != 0 || read_buf[1] != 0
1328*4882a593Smuzhiyun || read_buf[0] != 0)
1329*4882a593Smuzhiyun bc_counter++;
1330*4882a593Smuzhiyun else
1331*4882a593Smuzhiyun bc_counter = 0;
1332*4882a593Smuzhiyun if (bc_counter > 1) {
1333*4882a593Smuzhiyun /*printk("======read 0xbc: %x %x %x %x======\n",
1334*4882a593Smuzhiyun read_buf[3], read_buf[2], read_buf[1], read_buf[0]);*/
1335*4882a593Smuzhiyun init_chip_flag = 1;
1336*4882a593Smuzhiyun bc_counter = 0;
1337*4882a593Smuzhiyun }
1338*4882a593Smuzhiyun
1339*4882a593Smuzhiyun /*
1340*4882a593Smuzhiyun write_buf[3] = 0x01;
1341*4882a593Smuzhiyun write_buf[2] = 0xfe;
1342*4882a593Smuzhiyun write_buf[1] = 0x10;
1343*4882a593Smuzhiyun write_buf[0] = 0x00;
1344*4882a593Smuzhiyun gsl_ts_write(ts->client, 0xf0, write_buf, 4);
1345*4882a593Smuzhiyun gsl_ts_read(ts->client, 0x10, read_buf, 4);
1346*4882a593Smuzhiyun gsl_ts_read(ts->client, 0x10, read_buf, 4);
1347*4882a593Smuzhiyun
1348*4882a593Smuzhiyun if(read_buf[3] < 10
1349*4882a593Smuzhiyun && read_buf[2] < 10
1350*4882a593Smuzhiyun && read_buf[1] < 10
1351*4882a593Smuzhiyun && read_buf[0] < 10)
1352*4882a593Smuzhiyun dac_counter ++;
1353*4882a593Smuzhiyun else
1354*4882a593Smuzhiyun dac_counter = 0;
1355*4882a593Smuzhiyun
1356*4882a593Smuzhiyun if(dac_counter > 1)
1357*4882a593Smuzhiyun {
1358*4882a593Smuzhiyun printk("read DAC1_0: %x %x %x %x\n",
1359*4882a593Smuzhiyun read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
1360*4882a593Smuzhiyun init_chip_flag = 1;
1361*4882a593Smuzhiyun dac_counter = 0;
1362*4882a593Smuzhiyun }
1363*4882a593Smuzhiyun */
1364*4882a593Smuzhiyun //queue_monitor_init_chip:
1365*4882a593Smuzhiyun if (init_chip_flag)
1366*4882a593Smuzhiyun init_chip(ts->client, ts);
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun i2c_lock_flag = 0;
1369*4882a593Smuzhiyun
1370*4882a593Smuzhiyun //queue_monitor_work:
1371*4882a593Smuzhiyun //queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 100);
1372*4882a593Smuzhiyun }
1373*4882a593Smuzhiyun #endif
1374*4882a593Smuzhiyun
gsl_ts_irq(int irq,void * dev_id)1375*4882a593Smuzhiyun static irqreturn_t gsl_ts_irq(int irq, void *dev_id)
1376*4882a593Smuzhiyun {
1377*4882a593Smuzhiyun ///struct gsl_ts *ts = dev_id;
1378*4882a593Smuzhiyun struct gsl_ts *ts = (struct gsl_ts *)dev_id;
1379*4882a593Smuzhiyun //print_info("========gslX680 Interrupt=========\n");
1380*4882a593Smuzhiyun
1381*4882a593Smuzhiyun glsx680_ts_irq_disable(ts);
1382*4882a593Smuzhiyun
1383*4882a593Smuzhiyun if (!work_pending(&ts->work)) {
1384*4882a593Smuzhiyun queue_work(ts->wq, &ts->work);
1385*4882a593Smuzhiyun }
1386*4882a593Smuzhiyun
1387*4882a593Smuzhiyun return IRQ_HANDLED;
1388*4882a593Smuzhiyun
1389*4882a593Smuzhiyun }
1390*4882a593Smuzhiyun
gslX680_ts_init(struct i2c_client * client,struct gsl_ts * ts)1391*4882a593Smuzhiyun static int gslX680_ts_init(struct i2c_client *client, struct gsl_ts *ts)
1392*4882a593Smuzhiyun {
1393*4882a593Smuzhiyun struct input_dev *input_device;
1394*4882a593Smuzhiyun int rc = 0;
1395*4882a593Smuzhiyun int i = 0;
1396*4882a593Smuzhiyun int max_x = ts->ts_cfg->max_x;
1397*4882a593Smuzhiyun int max_y = ts->ts_cfg->max_y;
1398*4882a593Smuzhiyun
1399*4882a593Smuzhiyun printk("[GSLX680] Enter %s\n", __func__);
1400*4882a593Smuzhiyun
1401*4882a593Smuzhiyun ts->dd = &devices[ts->device_id];
1402*4882a593Smuzhiyun
1403*4882a593Smuzhiyun if (ts->device_id == 0) {
1404*4882a593Smuzhiyun ts->dd->data_size =
1405*4882a593Smuzhiyun MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data;
1406*4882a593Smuzhiyun ts->dd->touch_index = 0;
1407*4882a593Smuzhiyun }
1408*4882a593Smuzhiyun
1409*4882a593Smuzhiyun ts->touch_data =
1410*4882a593Smuzhiyun devm_kzalloc(&client->dev, ts->dd->data_size, GFP_KERNEL);
1411*4882a593Smuzhiyun if (!ts->touch_data) {
1412*4882a593Smuzhiyun pr_err("%s: Unable to allocate memory\n", __func__);
1413*4882a593Smuzhiyun return -ENOMEM;
1414*4882a593Smuzhiyun }
1415*4882a593Smuzhiyun
1416*4882a593Smuzhiyun input_device = devm_input_allocate_device(&ts->client->dev);
1417*4882a593Smuzhiyun if (!input_device) {
1418*4882a593Smuzhiyun rc = -ENOMEM;
1419*4882a593Smuzhiyun goto init_err_ret;
1420*4882a593Smuzhiyun }
1421*4882a593Smuzhiyun
1422*4882a593Smuzhiyun ts->input = input_device;
1423*4882a593Smuzhiyun input_device->name = GSLX680_I2C_NAME;
1424*4882a593Smuzhiyun input_device->id.bustype = BUS_I2C;
1425*4882a593Smuzhiyun input_device->dev.parent = &client->dev;
1426*4882a593Smuzhiyun input_set_drvdata(input_device, ts);
1427*4882a593Smuzhiyun
1428*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1429*4882a593Smuzhiyun __set_bit(EV_ABS, input_device->evbit);
1430*4882a593Smuzhiyun __set_bit(EV_KEY, input_device->evbit);
1431*4882a593Smuzhiyun __set_bit(EV_REP, input_device->evbit);
1432*4882a593Smuzhiyun __set_bit(EV_SYN, input_device->evbit);
1433*4882a593Smuzhiyun __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1434*4882a593Smuzhiyun __set_bit(MT_TOOL_FINGER, input_device->keybit);
1435*4882a593Smuzhiyun input_mt_init_slots(input_device, (MAX_CONTACTS + 1), 0);
1436*4882a593Smuzhiyun #else
1437*4882a593Smuzhiyun input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0,
1438*4882a593Smuzhiyun (MAX_CONTACTS + 1), 0, 0);
1439*4882a593Smuzhiyun set_bit(EV_ABS, input_device->evbit);
1440*4882a593Smuzhiyun set_bit(EV_KEY, input_device->evbit);
1441*4882a593Smuzhiyun __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1442*4882a593Smuzhiyun input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1443*4882a593Smuzhiyun #endif
1444*4882a593Smuzhiyun
1445*4882a593Smuzhiyun #ifdef HAVE_TOUCH_KEY
1446*4882a593Smuzhiyun input_device->evbit[0] = BIT_MASK(EV_KEY);
1447*4882a593Smuzhiyun /*input_device->evbit[0] = BIT_MASK(EV_SYN)
1448*4882a593Smuzhiyun | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);*/
1449*4882a593Smuzhiyun for (i = 0; i < MAX_KEY_NUM; i++)
1450*4882a593Smuzhiyun set_bit(key_array[i], input_device->keybit);
1451*4882a593Smuzhiyun #endif
1452*4882a593Smuzhiyun
1453*4882a593Smuzhiyun #ifdef RK_GEAR_TOUCH
1454*4882a593Smuzhiyun set_bit(EV_REL, input_device->evbit);
1455*4882a593Smuzhiyun input_set_capability(input_device, EV_REL, REL_X);
1456*4882a593Smuzhiyun input_set_capability(input_device, EV_REL, REL_Y);
1457*4882a593Smuzhiyun input_set_capability(input_device, EV_MSC, MSC_SCAN);
1458*4882a593Smuzhiyun input_set_capability(input_device, EV_KEY, 0x110);
1459*4882a593Smuzhiyun #endif
1460*4882a593Smuzhiyun
1461*4882a593Smuzhiyun set_bit(ABS_MT_POSITION_X, input_device->absbit);
1462*4882a593Smuzhiyun set_bit(ABS_MT_POSITION_Y, input_device->absbit);
1463*4882a593Smuzhiyun set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
1464*4882a593Smuzhiyun set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
1465*4882a593Smuzhiyun
1466*4882a593Smuzhiyun input_set_abs_params(input_device, ABS_MT_POSITION_X, 0, max_x,
1467*4882a593Smuzhiyun 0, 0);
1468*4882a593Smuzhiyun input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0, max_y,
1469*4882a593Smuzhiyun 0, 0);
1470*4882a593Smuzhiyun input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0,
1471*4882a593Smuzhiyun 0);
1472*4882a593Smuzhiyun input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
1473*4882a593Smuzhiyun
1474*4882a593Smuzhiyun //client->irq = IRQ_PORT;
1475*4882a593Smuzhiyun //ts->irq = client->irq;
1476*4882a593Smuzhiyun
1477*4882a593Smuzhiyun ts->wq = create_singlethread_workqueue("kworkqueue_ts");
1478*4882a593Smuzhiyun if (!ts->wq) {
1479*4882a593Smuzhiyun dev_err(&client->dev, "gsl Could not create workqueue\n");
1480*4882a593Smuzhiyun goto init_err_ret;
1481*4882a593Smuzhiyun }
1482*4882a593Smuzhiyun flush_workqueue(ts->wq);
1483*4882a593Smuzhiyun
1484*4882a593Smuzhiyun INIT_WORK(&ts->work, gslX680_ts_worker);
1485*4882a593Smuzhiyun
1486*4882a593Smuzhiyun rc = input_register_device(input_device);
1487*4882a593Smuzhiyun if (rc)
1488*4882a593Smuzhiyun goto error_unreg_device;
1489*4882a593Smuzhiyun
1490*4882a593Smuzhiyun return 0;
1491*4882a593Smuzhiyun
1492*4882a593Smuzhiyun error_unreg_device:
1493*4882a593Smuzhiyun destroy_workqueue(ts->wq);
1494*4882a593Smuzhiyun init_err_ret:
1495*4882a593Smuzhiyun return rc;
1496*4882a593Smuzhiyun }
1497*4882a593Smuzhiyun
1498*4882a593Smuzhiyun #if 0
1499*4882a593Smuzhiyun static int gsl_ts_suspend(struct i2c_client *dev, pm_message_t mesg)
1500*4882a593Smuzhiyun {
1501*4882a593Smuzhiyun #if 0
1502*4882a593Smuzhiyun struct gsl_ts *ts = dev_get_drvdata(dev);
1503*4882a593Smuzhiyun
1504*4882a593Smuzhiyun printk("I'am in gsl_ts_suspend() start\n");
1505*4882a593Smuzhiyun
1506*4882a593Smuzhiyun #ifdef GSL_MONITOR
1507*4882a593Smuzhiyun printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1508*4882a593Smuzhiyun cancel_delayed_work_sync(&ts->gsl_monitor_work);
1509*4882a593Smuzhiyun #endif
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun #ifdef HAVE_CLICK_TIMER
1512*4882a593Smuzhiyun //cancel_work_sync(&ts->click_work);
1513*4882a593Smuzhiyun #endif
1514*4882a593Smuzhiyun disable_irq_nosync(ts->irq);
1515*4882a593Smuzhiyun
1516*4882a593Smuzhiyun gslX680_shutdown_low(ts);
1517*4882a593Smuzhiyun
1518*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
1519*4882a593Smuzhiyun mdelay(10);
1520*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1521*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1522*4882a593Smuzhiyun input_mt_slot(ts->input, i);
1523*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1524*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1525*4882a593Smuzhiyun }
1526*4882a593Smuzhiyun #else
1527*4882a593Smuzhiyun input_mt_sync(ts->input);
1528*4882a593Smuzhiyun #endif
1529*4882a593Smuzhiyun input_sync(ts->input);
1530*4882a593Smuzhiyun mdelay(10);
1531*4882a593Smuzhiyun report_data(ts, 1, 1, 10, 1);
1532*4882a593Smuzhiyun input_sync(ts->input);
1533*4882a593Smuzhiyun #endif
1534*4882a593Smuzhiyun
1535*4882a593Smuzhiyun #endif
1536*4882a593Smuzhiyun return 0;
1537*4882a593Smuzhiyun }
1538*4882a593Smuzhiyun #endif
1539*4882a593Smuzhiyun
1540*4882a593Smuzhiyun #if 0
1541*4882a593Smuzhiyun static int gsl_ts_resume(struct i2c_client *dev)
1542*4882a593Smuzhiyun {
1543*4882a593Smuzhiyun #if 0
1544*4882a593Smuzhiyun struct gsl_ts *ts = dev_get_drvdata(dev);
1545*4882a593Smuzhiyun
1546*4882a593Smuzhiyun printk("I'am in gsl_ts_resume() start\n");
1547*4882a593Smuzhiyun
1548*4882a593Smuzhiyun gslX680_shutdown_high(ts);
1549*4882a593Smuzhiyun msleep(20);
1550*4882a593Smuzhiyun reset_chip(ts->client);
1551*4882a593Smuzhiyun startup_chip(ts->client);
1552*4882a593Smuzhiyun check_mem_data(ts->client, ts);
1553*4882a593Smuzhiyun
1554*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
1555*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1556*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1557*4882a593Smuzhiyun input_mt_slot(ts->input, i);
1558*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1559*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1560*4882a593Smuzhiyun }
1561*4882a593Smuzhiyun #else
1562*4882a593Smuzhiyun input_mt_sync(ts->input);
1563*4882a593Smuzhiyun #endif
1564*4882a593Smuzhiyun input_sync(ts->input);
1565*4882a593Smuzhiyun #endif
1566*4882a593Smuzhiyun #ifdef GSL_MONITOR
1567*4882a593Smuzhiyun printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1568*4882a593Smuzhiyun queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1569*4882a593Smuzhiyun #endif
1570*4882a593Smuzhiyun
1571*4882a593Smuzhiyun #ifdef HAVE_CLICK_TIMER
1572*4882a593Smuzhiyun //queue_work(gsl_timer_workqueue,&ts->click_work);
1573*4882a593Smuzhiyun #endif
1574*4882a593Smuzhiyun
1575*4882a593Smuzhiyun disable_irq_nosync(ts->irq);
1576*4882a593Smuzhiyun enable_irq(ts->irq);
1577*4882a593Smuzhiyun #endif
1578*4882a593Smuzhiyun
1579*4882a593Smuzhiyun return 0;
1580*4882a593Smuzhiyun }
1581*4882a593Smuzhiyun #endif
1582*4882a593Smuzhiyun
gsl_ts_early_suspend(struct tp_device * tp_d)1583*4882a593Smuzhiyun static int gsl_ts_early_suspend(struct tp_device *tp_d)
1584*4882a593Smuzhiyun {
1585*4882a593Smuzhiyun struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1586*4882a593Smuzhiyun printk("[GSLX680] Enter %s\n", __func__);
1587*4882a593Smuzhiyun //gsl_ts_suspend(&ts->client->dev);
1588*4882a593Smuzhiyun #ifdef GSL_MONITOR
1589*4882a593Smuzhiyun printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1590*4882a593Smuzhiyun cancel_delayed_work_sync(&ts->gsl_monitor_work);
1591*4882a593Smuzhiyun #endif
1592*4882a593Smuzhiyun
1593*4882a593Smuzhiyun glsx680_ts_irq_disable(ts);
1594*4882a593Smuzhiyun cancel_work_sync(&ts->work);
1595*4882a593Smuzhiyun
1596*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
1597*4882a593Smuzhiyun msleep(10);
1598*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1599*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1600*4882a593Smuzhiyun input_mt_slot(ts->input, i);
1601*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1602*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1603*4882a593Smuzhiyun }
1604*4882a593Smuzhiyun #else
1605*4882a593Smuzhiyun input_mt_sync(ts->input);
1606*4882a593Smuzhiyun #endif
1607*4882a593Smuzhiyun input_sync(ts->input);
1608*4882a593Smuzhiyun msleep(10);
1609*4882a593Smuzhiyun report_data(ts, 1, 1, 10, 1);
1610*4882a593Smuzhiyun input_sync(ts->input);
1611*4882a593Smuzhiyun #endif
1612*4882a593Smuzhiyun gslX680_shutdown_low(ts);
1613*4882a593Smuzhiyun return 0;
1614*4882a593Smuzhiyun }
1615*4882a593Smuzhiyun
gsl_ts_late_resume(struct tp_device * tp_d)1616*4882a593Smuzhiyun static int gsl_ts_late_resume(struct tp_device *tp_d)
1617*4882a593Smuzhiyun {
1618*4882a593Smuzhiyun struct gsl_ts *ts = container_of(tp_d, struct gsl_ts, tp);
1619*4882a593Smuzhiyun printk("[GSLX680] Enter %s\n", __func__);
1620*4882a593Smuzhiyun //gsl_ts_resume(&ts->client->dev);
1621*4882a593Smuzhiyun
1622*4882a593Smuzhiyun printk("I'am in gsl_ts_resume() start\n");
1623*4882a593Smuzhiyun
1624*4882a593Smuzhiyun gslX680_shutdown_high(ts);
1625*4882a593Smuzhiyun msleep(20);
1626*4882a593Smuzhiyun reset_chip(ts->client);
1627*4882a593Smuzhiyun startup_chip(ts->client);
1628*4882a593Smuzhiyun check_mem_data(ts->client, ts);
1629*4882a593Smuzhiyun
1630*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
1631*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1632*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1633*4882a593Smuzhiyun input_mt_slot(ts->input, i);
1634*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1635*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1636*4882a593Smuzhiyun }
1637*4882a593Smuzhiyun #else
1638*4882a593Smuzhiyun input_mt_sync(ts->input);
1639*4882a593Smuzhiyun #endif
1640*4882a593Smuzhiyun input_sync(ts->input);
1641*4882a593Smuzhiyun #endif
1642*4882a593Smuzhiyun #ifdef GSL_MONITOR
1643*4882a593Smuzhiyun printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1644*4882a593Smuzhiyun queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1645*4882a593Smuzhiyun #endif
1646*4882a593Smuzhiyun glsx680_ts_irq_enable(ts);
1647*4882a593Smuzhiyun
1648*4882a593Smuzhiyun return 0;
1649*4882a593Smuzhiyun }
1650*4882a593Smuzhiyun
1651*4882a593Smuzhiyun #ifdef CONFIG_HAS_EARLYSUSPEND
1652*4882a593Smuzhiyun
gsl_ts_early_suspend(struct early_suspend * h)1653*4882a593Smuzhiyun static void gsl_ts_early_suspend(struct early_suspend *h)
1654*4882a593Smuzhiyun {
1655*4882a593Smuzhiyun struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1656*4882a593Smuzhiyun printk("[GSLX680] Enter %s\n", __func__);
1657*4882a593Smuzhiyun //gsl_ts_suspend(&ts->client->dev);
1658*4882a593Smuzhiyun #ifdef GSL_MONITOR
1659*4882a593Smuzhiyun printk("gsl_ts_suspend () : cancel gsl_monitor_work\n");
1660*4882a593Smuzhiyun cancel_delayed_work_sync(&ts->gsl_monitor_work);
1661*4882a593Smuzhiyun #endif
1662*4882a593Smuzhiyun
1663*4882a593Smuzhiyun glsx680_ts_irq_disable(ts);
1664*4882a593Smuzhiyun cancel_work_sync(&ts->work);
1665*4882a593Smuzhiyun
1666*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
1667*4882a593Smuzhiyun msleep(10);
1668*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1669*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1670*4882a593Smuzhiyun input_mt_slot(ts->input, i);
1671*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1672*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1673*4882a593Smuzhiyun }
1674*4882a593Smuzhiyun #else
1675*4882a593Smuzhiyun input_mt_sync(ts->input);
1676*4882a593Smuzhiyun #endif
1677*4882a593Smuzhiyun input_sync(ts->input);
1678*4882a593Smuzhiyun msleep(10);
1679*4882a593Smuzhiyun report_data(ts, 1, 1, 10, 1);
1680*4882a593Smuzhiyun input_sync(ts->input);
1681*4882a593Smuzhiyun #endif
1682*4882a593Smuzhiyun gslX680_shutdown_low(ts);
1683*4882a593Smuzhiyun return 0;
1684*4882a593Smuzhiyun }
1685*4882a593Smuzhiyun
gsl_ts_late_resume(struct early_suspend * h)1686*4882a593Smuzhiyun static void gsl_ts_late_resume(struct early_suspend *h)
1687*4882a593Smuzhiyun {
1688*4882a593Smuzhiyun struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend);
1689*4882a593Smuzhiyun printk("[GSLX680] Enter %s\n", __func__);
1690*4882a593Smuzhiyun //gsl_ts_resume(&ts->client->dev);
1691*4882a593Smuzhiyun int i;
1692*4882a593Smuzhiyun
1693*4882a593Smuzhiyun printk("I'am in gsl_ts_resume() start\n");
1694*4882a593Smuzhiyun
1695*4882a593Smuzhiyun gslX680_shutdown_high(ts);
1696*4882a593Smuzhiyun msleep(20);
1697*4882a593Smuzhiyun reset_chip(ts->client);
1698*4882a593Smuzhiyun startup_chip(ts->client);
1699*4882a593Smuzhiyun check_mem_data(ts->client, ts);
1700*4882a593Smuzhiyun
1701*4882a593Smuzhiyun #ifdef SLEEP_CLEAR_POINT
1702*4882a593Smuzhiyun #ifdef REPORT_DATA_ANDROID_4_0
1703*4882a593Smuzhiyun for (i = 1; i <= MAX_CONTACTS; i++) {
1704*4882a593Smuzhiyun input_mt_slot(ts->input, i);
1705*4882a593Smuzhiyun input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1706*4882a593Smuzhiyun input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
1707*4882a593Smuzhiyun }
1708*4882a593Smuzhiyun #else
1709*4882a593Smuzhiyun input_mt_sync(ts->input);
1710*4882a593Smuzhiyun #endif
1711*4882a593Smuzhiyun input_sync(ts->input);
1712*4882a593Smuzhiyun #endif
1713*4882a593Smuzhiyun #ifdef GSL_MONITOR
1714*4882a593Smuzhiyun printk("gsl_ts_resume () : queue gsl_monitor_work\n");
1715*4882a593Smuzhiyun queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 300);
1716*4882a593Smuzhiyun #endif
1717*4882a593Smuzhiyun glsx680_ts_irq_enable(ts);
1718*4882a593Smuzhiyun
1719*4882a593Smuzhiyun }
1720*4882a593Smuzhiyun #endif
1721*4882a593Smuzhiyun
1722*4882a593Smuzhiyun //static struct wake_lock touch_wakelock;
1723*4882a593Smuzhiyun
1724*4882a593Smuzhiyun static const struct of_device_id gsl_ts_ids[] = {
1725*4882a593Smuzhiyun { .compatible = "gslX680", .data = &gslx680_vr_cfg },
1726*4882a593Smuzhiyun { .compatible = "gslX680_tve", .data = &gslx680_tve_cfg },
1727*4882a593Smuzhiyun {}
1728*4882a593Smuzhiyun };
1729*4882a593Smuzhiyun
gsl_ts_probe(struct i2c_client * client,const struct i2c_device_id * id)1730*4882a593Smuzhiyun static int gsl_ts_probe(struct i2c_client *client,
1731*4882a593Smuzhiyun const struct i2c_device_id *id)
1732*4882a593Smuzhiyun {
1733*4882a593Smuzhiyun const struct of_device_id *match;
1734*4882a593Smuzhiyun struct gsl_ts *ts;
1735*4882a593Smuzhiyun int rc;
1736*4882a593Smuzhiyun
1737*4882a593Smuzhiyun printk("GSLX680 Enter %s\n", __func__);
1738*4882a593Smuzhiyun //wake_lock_init(&touch_wakelock, WAKE_LOCK_SUSPEND, "touch");
1739*4882a593Smuzhiyun //wake_lock(&touch_wakelock); //system do not enter deep sleep
1740*4882a593Smuzhiyun if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1741*4882a593Smuzhiyun dev_err(&client->dev, "gsl I2C functionality not supported\n");
1742*4882a593Smuzhiyun return -ENODEV;
1743*4882a593Smuzhiyun }
1744*4882a593Smuzhiyun
1745*4882a593Smuzhiyun ts = devm_kzalloc(&client->dev, sizeof(*ts), GFP_KERNEL);
1746*4882a593Smuzhiyun if (!ts)
1747*4882a593Smuzhiyun return -ENOMEM;
1748*4882a593Smuzhiyun
1749*4882a593Smuzhiyun match = of_match_device(of_match_ptr(gsl_ts_ids), &client->dev);
1750*4882a593Smuzhiyun if (!match)
1751*4882a593Smuzhiyun return -EINVAL;
1752*4882a593Smuzhiyun
1753*4882a593Smuzhiyun ts->ts_cfg = (const struct gsl_ts_cfg *)match->data;
1754*4882a593Smuzhiyun
1755*4882a593Smuzhiyun ts->tp.tp_suspend = gsl_ts_early_suspend;
1756*4882a593Smuzhiyun ts->tp.tp_resume = gsl_ts_late_resume;
1757*4882a593Smuzhiyun tp_register_fb(&ts->tp);
1758*4882a593Smuzhiyun
1759*4882a593Smuzhiyun ts->client = client;
1760*4882a593Smuzhiyun i2c_set_clientdata(client, ts);
1761*4882a593Smuzhiyun //ts->device_id = id->driver_data;
1762*4882a593Smuzhiyun
1763*4882a593Smuzhiyun gslX680_init(ts);
1764*4882a593Smuzhiyun rc = gslX680_ts_init(client, ts);
1765*4882a593Smuzhiyun if (rc < 0) {
1766*4882a593Smuzhiyun dev_err(&client->dev, "gsl GSLX680 init failed\n");
1767*4882a593Smuzhiyun goto porbe_err_ret;
1768*4882a593Smuzhiyun }
1769*4882a593Smuzhiyun //#ifdef GSLX680_COMPATIBLE
1770*4882a593Smuzhiyun // judge_chip_type(client);
1771*4882a593Smuzhiyun //#endif
1772*4882a593Smuzhiyun //printk("##################### probe [2]chip_type=%c .\n",chip_type);
1773*4882a593Smuzhiyun init_chip(ts->client, ts);
1774*4882a593Smuzhiyun check_mem_data(ts->client, ts);
1775*4882a593Smuzhiyun spin_lock_init(&ts->irq_lock);
1776*4882a593Smuzhiyun client->irq = gpio_to_irq(ts->irq);
1777*4882a593Smuzhiyun rc = request_irq(client->irq, gsl_ts_irq, IRQF_TRIGGER_RISING,
1778*4882a593Smuzhiyun client->name, ts);
1779*4882a593Smuzhiyun if (rc < 0) {
1780*4882a593Smuzhiyun printk("gsl_probe: request irq failed\n");
1781*4882a593Smuzhiyun goto porbe_err_ret;
1782*4882a593Smuzhiyun }
1783*4882a593Smuzhiyun
1784*4882a593Smuzhiyun /* create debug attribute */
1785*4882a593Smuzhiyun //rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable);
1786*4882a593Smuzhiyun
1787*4882a593Smuzhiyun #ifdef CONFIG_HAS_EARLYSUSPEND
1788*4882a593Smuzhiyun
1789*4882a593Smuzhiyun ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1790*4882a593Smuzhiyun //ts->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1;
1791*4882a593Smuzhiyun ts->early_suspend.suspend = gsl_ts_early_suspend;
1792*4882a593Smuzhiyun ts->early_suspend.resume = gsl_ts_late_resume;
1793*4882a593Smuzhiyun register_early_suspend(&ts->early_suspend);
1794*4882a593Smuzhiyun #endif
1795*4882a593Smuzhiyun
1796*4882a593Smuzhiyun #ifdef GSL_MONITOR
1797*4882a593Smuzhiyun
1798*4882a593Smuzhiyun INIT_DELAYED_WORK(&ts->gsl_monitor_work, gsl_monitor_worker);
1799*4882a593Smuzhiyun gsl_monitor_workqueue =
1800*4882a593Smuzhiyun create_singlethread_workqueue("gsl_monitor_workqueue");
1801*4882a593Smuzhiyun queue_delayed_work(gsl_monitor_workqueue, &ts->gsl_monitor_work, 1000);
1802*4882a593Smuzhiyun #endif
1803*4882a593Smuzhiyun
1804*4882a593Smuzhiyun #ifdef HAVE_CLICK_TIMER
1805*4882a593Smuzhiyun sema_init(&my_sem, 1);
1806*4882a593Smuzhiyun INIT_WORK(&ts->click_work, click_timer_worker);
1807*4882a593Smuzhiyun gsl_timer_workqueue = create_singlethread_workqueue("click_timer");
1808*4882a593Smuzhiyun queue_work(gsl_timer_workqueue, &ts->click_work);
1809*4882a593Smuzhiyun #endif
1810*4882a593Smuzhiyun
1811*4882a593Smuzhiyun #ifdef TPD_PROC_DEBUG
1812*4882a593Smuzhiyun #if 0
1813*4882a593Smuzhiyun gsl_config_proc = create_proc_entry(GSL_CONFIG_PROC_FILE, 0666, NULL);
1814*4882a593Smuzhiyun printk("[tp-gsl] [%s] gsl_config_proc = %x \n", __func__,
1815*4882a593Smuzhiyun gsl_config_proc);
1816*4882a593Smuzhiyun if (gsl_config_proc == NULL) {
1817*4882a593Smuzhiyun print_info("create_proc_entry %s failed\n",
1818*4882a593Smuzhiyun GSL_CONFIG_PROC_FILE);
1819*4882a593Smuzhiyun } else {
1820*4882a593Smuzhiyun gsl_config_proc->read_proc = gsl_config_read_proc;
1821*4882a593Smuzhiyun gsl_config_proc->write_proc = gsl_config_write_proc;
1822*4882a593Smuzhiyun }
1823*4882a593Smuzhiyun #else
1824*4882a593Smuzhiyun i2c_client = client;
1825*4882a593Smuzhiyun proc_create(GSL_CONFIG_PROC_FILE, 0666, NULL, &gsl_seq_fops);
1826*4882a593Smuzhiyun #endif
1827*4882a593Smuzhiyun gsl_proc_flag = 0;
1828*4882a593Smuzhiyun #endif
1829*4882a593Smuzhiyun //disable_irq_nosync(->irq);
1830*4882a593Smuzhiyun printk("[GSLX680] End %s\n", __func__);
1831*4882a593Smuzhiyun
1832*4882a593Smuzhiyun return 0;
1833*4882a593Smuzhiyun
1834*4882a593Smuzhiyun porbe_err_ret:
1835*4882a593Smuzhiyun return rc;
1836*4882a593Smuzhiyun }
1837*4882a593Smuzhiyun
gsl_ts_remove(struct i2c_client * client)1838*4882a593Smuzhiyun static int gsl_ts_remove(struct i2c_client *client)
1839*4882a593Smuzhiyun {
1840*4882a593Smuzhiyun struct gsl_ts *ts = i2c_get_clientdata(client);
1841*4882a593Smuzhiyun
1842*4882a593Smuzhiyun #ifdef CONFIG_HAS_EARLYSUSPEND
1843*4882a593Smuzhiyun unregister_early_suspend(&ts->early_suspend);
1844*4882a593Smuzhiyun #endif
1845*4882a593Smuzhiyun
1846*4882a593Smuzhiyun #ifdef GSL_MONITOR
1847*4882a593Smuzhiyun cancel_delayed_work_sync(&ts->gsl_monitor_work);
1848*4882a593Smuzhiyun destroy_workqueue(gsl_monitor_workqueue);
1849*4882a593Smuzhiyun #endif
1850*4882a593Smuzhiyun
1851*4882a593Smuzhiyun #ifdef HAVE_CLICK_TIMER
1852*4882a593Smuzhiyun cancel_work_sync(&ts->click_work);
1853*4882a593Smuzhiyun destroy_workqueue(gsl_timer_workqueue);
1854*4882a593Smuzhiyun #endif
1855*4882a593Smuzhiyun
1856*4882a593Smuzhiyun device_init_wakeup(&client->dev, 0);
1857*4882a593Smuzhiyun cancel_work_sync(&ts->work);
1858*4882a593Smuzhiyun free_irq(ts->client->irq, ts);
1859*4882a593Smuzhiyun destroy_workqueue(ts->wq);
1860*4882a593Smuzhiyun //device_remove_file(&ts->input->dev, &dev_attr_debug_enable);
1861*4882a593Smuzhiyun
1862*4882a593Smuzhiyun return 0;
1863*4882a593Smuzhiyun }
1864*4882a593Smuzhiyun
1865*4882a593Smuzhiyun static const struct i2c_device_id gsl_ts_id[] = {
1866*4882a593Smuzhiyun {GSLX680_I2C_NAME, 0},
1867*4882a593Smuzhiyun {}
1868*4882a593Smuzhiyun };
1869*4882a593Smuzhiyun
1870*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
1871*4882a593Smuzhiyun
1872*4882a593Smuzhiyun static struct i2c_driver gsl_ts_driver = {
1873*4882a593Smuzhiyun .driver = {
1874*4882a593Smuzhiyun .name = GSLX680_I2C_NAME,
1875*4882a593Smuzhiyun .owner = THIS_MODULE,
1876*4882a593Smuzhiyun .of_match_table = of_match_ptr(gsl_ts_ids),
1877*4882a593Smuzhiyun },
1878*4882a593Smuzhiyun #if 0 //ndef CONFIG_HAS_EARLYSUSPEND
1879*4882a593Smuzhiyun .suspend = gsl_ts_suspend,
1880*4882a593Smuzhiyun .resume = gsl_ts_resume,
1881*4882a593Smuzhiyun #endif
1882*4882a593Smuzhiyun .probe = gsl_ts_probe,
1883*4882a593Smuzhiyun .remove = gsl_ts_remove,
1884*4882a593Smuzhiyun .id_table = gsl_ts_id,
1885*4882a593Smuzhiyun };
1886*4882a593Smuzhiyun
gsl_ts_init(void)1887*4882a593Smuzhiyun static int __init gsl_ts_init(void)
1888*4882a593Smuzhiyun {
1889*4882a593Smuzhiyun int ret;
1890*4882a593Smuzhiyun ret = i2c_add_driver(&gsl_ts_driver);
1891*4882a593Smuzhiyun return ret;
1892*4882a593Smuzhiyun }
gsl_ts_exit(void)1893*4882a593Smuzhiyun static void __exit gsl_ts_exit(void)
1894*4882a593Smuzhiyun {
1895*4882a593Smuzhiyun i2c_del_driver(&gsl_ts_driver);
1896*4882a593Smuzhiyun return;
1897*4882a593Smuzhiyun }
1898*4882a593Smuzhiyun
1899*4882a593Smuzhiyun module_init(gsl_ts_init);
1900*4882a593Smuzhiyun module_exit(gsl_ts_exit);
1901*4882a593Smuzhiyun
1902*4882a593Smuzhiyun MODULE_LICENSE("GPL");
1903*4882a593Smuzhiyun MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
1904*4882a593Smuzhiyun MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com");
1905*4882a593Smuzhiyun MODULE_ALIAS("platform:gsl_ts");
1906