1 /*
2 * drivers/input/touchscreen/gslX680.c
3 *
4 * Copyright (c) 2012 Shanghai Basewin
5 * Guan Yuwei<guanyuwei@basewin.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * history:
12 * mbgalex@163.com_2013-07-16_14:12
13 * add tp for Q790 OGS project ,tp modules is EC8031-01
14 */
15
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/input.h>
19 #include <linux/interrupt.h>
20 #include <linux/i2c.h>
21 #include <linux/delay.h>
22 #include <linux/fs.h>
23 #include <linux/jiffies.h>
24 #include <linux/cdev.h>
25 #include <linux/uaccess.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/firmware.h>
28
29 #include <linux/pm_runtime.h>
30
31
32 #include <linux/input/mt.h>
33
34 #include <linux/i2c.h>
35 #include <linux/input.h>
36
37 #include <linux/delay.h>
38 #include <linux/interrupt.h>
39 #include <linux/errno.h>
40 #include <linux/kernel.h>
41 #include <linux/module.h>
42 #include <linux/slab.h>
43 #include <linux/platform_device.h>
44 #include <linux/async.h>
45 #include <linux/hrtimer.h>
46 #include <linux/init.h>
47 #include <linux/ioport.h>
48 #include <asm/irq.h>
49 #include <linux/io.h>
50 #include <linux/device.h>
51
52 #include <linux/gpio.h>
53
54 #include "../../init-input.h"
55
56 #include "gslX680.h"
57
58 /* open for debug */
59 /*
60 #ifdef pr_debug
61 #undef pr_debug
62 #define pr_debug pr_info
63 #endif
64 */
65
66 struct gslX680_fw_array {
67 char name[64];
68 unsigned int size;
69 const struct fw_data *fw;
70 } gslx680_fw_grp;
71
72 unsigned int *gslX680_config_data;
73 static int ldo_state;
74
75
76 #ifdef TPD_PROC_DEBUG
77 #include <linux/proc_fs.h>
78 #include <linux/uaccess.h>
79 static struct proc_dir_entry *gsl_config_proc;
80 #define GSL_CONFIG_PROC_FILE "gsl_config"
81 #define CONFIG_LEN 31
82 static char gsl_read[CONFIG_LEN];
83 static u8 gsl_data_proc[8] = {0};
84 static u8 gsl_proc_flag;
85 static unsigned int gsl_config_data_id[256];
86 #endif
87
88 #define GSL_DATA_REG 0x80
89 #define GSL_STATUS_REG 0xe0
90 #define GSL_PAGE_REG 0xf0
91
92 #define PRESS_MAX 255
93 #define MAX_FINGERS 5
94 #define MAX_CONTACTS 10
95 #define DMA_TRANS_LEN 0x20
96
97 #define PHO_CFG2_OFFSET (0X104)
98 #define PHO_DAT_OFFSET (0X10C)
99 #define PHO_PULL1_OFFSET (0X11C)
100 #define GPIOF_CON 0x7f0080a0
101 #define GPIOF_DAT 0x7f0080a4
102 #define GPIOF_PUD 0x7f0080a8
103
104 #define GSL_NOID_VERSION
105 #ifdef GSL_MONITOR
106 static struct delayed_work gsl_monitor_work;
107 static struct workqueue_struct *gsl_monitor_workqueue;
108 static char int_1st[4] = {0};
109 static char int_2nd[4] = {0};
110 #endif
111
112 static struct input_dev *gDevice;
113
114 #ifdef HAVE_TOUCH_KEY
115 static u16 key;
116 static int key_state_flag;
117 struct key_data {
118 u16 key;
119 u16 x_min;
120 u16 x_max;
121 u16 y_min;
122 u16 y_max;
123 };
124
125 const u16 key_array[] = {
126 KEY_BACK,
127 KEY_HOME,
128 KEY_MENU,
129 KEY_SEARCH,
130 };
131 #define MAX_KEY_NUM (ARRAY_SIZE(key_array))
132
133 struct key_data gsl_key_data[MAX_KEY_NUM] = {
134 {KEY_BACK, 816, 836, 115, 125},
135 {KEY_HOME, 816, 836, 259, 269},
136 {KEY_MENU, 816, 836, 398, 410},
137 {KEY_SEARCH, 2048, 2048, 2048, 2048},
138 };
139 #endif
140
141 struct gsl_ts_data {
142 u8 x_index;
143 u8 y_index;
144 u8 z_index;
145 u8 id_index;
146 u8 touch_index;
147 u8 data_reg;
148 u8 status_reg;
149 u8 data_size;
150 u8 touch_bytes;
151 u8 update_data;
152 u8 touch_meta_data;
153 u8 finger_size;
154 };
155
156 static struct gsl_ts_data devices[] = {
157 {
158 .x_index = 6,
159 .y_index = 4,
160 .z_index = 5,
161 .id_index = 7,
162 .data_reg = GSL_DATA_REG,
163 .status_reg = GSL_STATUS_REG,
164 .update_data = 0x4,
165 .touch_bytes = 4,
166 .touch_meta_data = 4,
167 .finger_size = 70,
168 },
169 };
170
171 struct gsl_ts {
172 struct i2c_client *client;
173 struct input_dev *input;
174 struct work_struct work;
175 struct workqueue_struct *wq;
176 struct gsl_ts_data *dd;
177 u8 *touch_data;
178 u8 device_id;
179 u8 prev_touches;
180 bool is_suspended;
181 bool is_runtime_suspend;
182 bool try_to_runtime_suspend;
183 bool try_to_runtime_resume;
184 bool int_pending;
185 struct mutex sus_lock;
186 int irq;
187 #ifdef GSL_TIMER
188 struct timer_list gsl_timer;
189 #endif
190
191 };
192
193 static u32 id_sign[MAX_CONTACTS+1] = {0};
194 static u8 id_state_flag[MAX_CONTACTS+1] = {0};
195 static u8 id_state_old_flag[MAX_CONTACTS+1] = {0};
196 static u16 x_old[MAX_CONTACTS+1] = {0};
197 static u16 y_old[MAX_CONTACTS+1] = {0};
198 static u16 x_new;
199 static u16 y_new;
200
201 /* specific tp related macro: need be configured for specific tp */
202
203 #define GSLX680_I2C_NAME "gslX680"
204
205 #define CTP_IRQ_NUMBER (config_info.int_number)
206 #define CTP_IRQ_MODE (IRQF_TRIGGER_FALLING)
207 #define CTP_NAME GSLX680_I2C_NAME
208 #define SCREEN_MAX_X (screen_max_x)
209 #define SCREEN_MAX_Y (screen_max_y)
210
211 static const char *fwname;
212
213
214 #define GSLX680_I2C_ADDR 0x40
215
216 #define GSL_MONITOR_TIMER_ENABLE 1
217 #ifdef GSL_TIMER
218 #undef GSL_MONITOR_TIMER_ENABLE
219 #define GSL_MONITOR_TIMER_ENABLE 0
220 #endif
221
222 #if GSL_MONITOR_TIMER_ENABLE
223 static int gTestMonitor;
224 struct timer_list monitor_timer;
225 static void glsX680_monitor_events(struct work_struct *work);
226 static DECLARE_WORK(glsX680_monitor_work, glsX680_monitor_events);
227 #endif
228
229 static int screen_max_x;
230 static int screen_max_y;
231 static int revert_x_flag;
232 static int revert_y_flag;
233 static int exchange_x_y_flag;
234
235 struct ctp_config_info config_info = {
236 .input_type = CTP_TYPE,
237 .name = NULL,
238 .int_number = 0,
239 };
240
241 static __u32 twi_id;
242
243 static const unsigned short normal_i2c[2] = {GSLX680_I2C_ADDR, I2C_CLIENT_END};
244 static int ctp_get_system_config(void);
245 static void glsX680_init_events(struct work_struct *work);
246 static void glsX680_resume_events(struct work_struct *work);
247 static void glsX680_idle_events(struct work_struct *work);
248 struct workqueue_struct *gslX680_wq;
249 struct workqueue_struct *gslX680_resume_wq;
250 static DECLARE_WORK(glsX680_init_work, glsX680_init_events);
251 static DECLARE_WORK(glsX680_resume_work, glsX680_resume_events);
252 static DECLARE_WORK(glsX680_idle_work, glsX680_idle_events);
253 struct i2c_client *glsX680_i2c;
254 struct gsl_ts *ts_init;
255
256
ctp_i2c_write_bytes(struct i2c_client * client,uint8_t * data,uint16_t len)257 int ctp_i2c_write_bytes(struct i2c_client *client, uint8_t *data, uint16_t len)
258 {
259 struct i2c_msg msg;
260 int ret = -1;
261
262 msg.flags = !I2C_M_RD;
263 msg.addr = client->addr;
264 msg.len = len;
265 msg.buf = data;
266
267 ret = i2c_transfer(client->adapter, &msg, 1);
268
269 return ret;
270 }
271
ctp_i2c_test(struct i2c_client * client)272 bool ctp_i2c_test(struct i2c_client *client)
273 {
274 int ret, retry;
275 uint8_t test_data[1] = {0};
276
277 for (retry = 0; retry < 12; retry++) {
278 ret = ctp_i2c_write_bytes(client, test_data, 1);
279 if (ret == 1)
280 break;
281 msleep(50);
282 }
283
284 return ret == 1 ? true : false;
285 }
286
ctp_detect(struct i2c_client * client,struct i2c_board_info * info)287 static int ctp_detect(struct i2c_client *client, struct i2c_board_info *info)
288 {
289 struct i2c_adapter *adapter = client->adapter;
290 int ret = -ENODEV;
291
292 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
293 return ret;
294
295 if (twi_id == adapter->nr) {
296 pr_info("%s: addr= %x\n", __func__, client->addr);
297 if (ctp_i2c_test(client) != 0) {
298 ret = 0;
299 pr_info("I2C connection success!\n");
300 strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
301 } else
302 pr_info("%s:I2C connection might be something wrong\n",
303 __func__);
304 }
305 return ret;
306 }
307 /**
308 * ctp_print_info - sysconfig print function
309 * return value:
310 *
311 */
ctp_print_info(struct ctp_config_info info)312 static void ctp_print_info(struct ctp_config_info info)
313 {
314 pr_debug("info.ctp_used:%d\n", info.ctp_used);
315 pr_debug("info.ctp_name:%s\n", info.name);
316 pr_debug("info.twi_id:%d\n", info.twi_id);
317 pr_debug("info.screen_max_x:%d\n", info.screen_max_x);
318 pr_debug("info.screen_max_y:%d\n", info.screen_max_y);
319 pr_debug("info.revert_x_flag:%d\n", info.revert_x_flag);
320 pr_debug("info.revert_y_flag:%d\n", info.revert_y_flag);
321 pr_debug("info.exchange_x_y_flag:%d\n", info.exchange_x_y_flag);
322 pr_debug("info.irq_gpio_number:%d\n", info.irq_gpio.gpio);
323 pr_debug("info.wakeup_gpio_number:%d\n", info.wakeup_gpio.gpio);
324 }
325
326 /**
327 * ctp_wakeup - function
328 *
329 */
ctp_wakeup(int status,int ms)330 static int ctp_wakeup(int status, int ms)
331 {
332 pr_debug("***CTP*** %s:status:%d,ms = %d\n", __func__, status, ms);
333
334 if (status == 0) {
335
336 if (ms == 0) {
337 __gpio_set_value(config_info.wakeup_gpio.gpio, 0);
338 } else {
339 __gpio_set_value(config_info.wakeup_gpio.gpio, 0);
340 msleep(ms);
341 __gpio_set_value(config_info.wakeup_gpio.gpio, 1);
342 }
343 }
344 if (status == 1) {
345 if (ms == 0) {
346 __gpio_set_value(config_info.wakeup_gpio.gpio, 1);
347 } else {
348 __gpio_set_value(config_info.wakeup_gpio.gpio, 1);
349 msleep(ms);
350 __gpio_set_value(config_info.wakeup_gpio.gpio, 0);
351 }
352 }
353 usleep_range(5000, 6000);
354
355 return 0;
356 }
357
gslX680_chip_init(void)358 static int gslX680_chip_init(void)
359 {
360 ctp_wakeup(1, 0);
361 msleep(20);
362 return 0;
363 }
364
gslX680_shutdown_low(void)365 static int gslX680_shutdown_low(void)
366 {
367 ctp_wakeup(0, 0);
368 return 0;
369 }
370
gslX680_shutdown_high(void)371 static int gslX680_shutdown_high(void)
372 {
373 ctp_wakeup(1, 0);
374 return 0;
375 }
376
join_bytes(u8 a,u8 b)377 static inline u16 join_bytes(u8 a, u8 b)
378 {
379 u16 ab = 0;
380
381 ab = ab | a;
382 ab = ab << 8 | b;
383 return ab;
384 }
385
386 #if 0
387 static u32 gsl_read_interface(struct i2c_client *client, u8 reg, u8 *buf, u32 num)
388 {
389 struct i2c_msg xfer_msg[2];
390
391 xfer_msg[0].addr = client->addr;
392 xfer_msg[0].len = 1;
393 xfer_msg[0].flags = client->flags & I2C_M_TEN;
394 xfer_msg[0].buf = ®
395
396 xfer_msg[1].addr = client->addr;
397 xfer_msg[1].len = num;
398 xfer_msg[1].flags |= I2C_M_RD;
399 xfer_msg[1].buf = buf;
400
401 if (reg < 0x80) {
402 i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
403 usleep_range(5000, 6000);
404 }
405
406 return i2c_transfer(client->adapter, xfer_msg,
407 ARRAY_SIZE(xfer_msg)) == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
408 }
409 #endif
410
gsl_write_interface(struct i2c_client * client,const u8 reg,u8 * buf,u32 num)411 static u32 gsl_write_interface(struct i2c_client *client, const u8 reg,
412 u8 *buf, u32 num)
413 {
414 struct i2c_msg xfer_msg[1];
415
416 buf[0] = reg;
417
418 xfer_msg[0].addr = client->addr;
419 xfer_msg[0].len = num + 1;
420 xfer_msg[0].flags = client->flags & I2C_M_TEN;
421 xfer_msg[0].buf = buf;
422
423 return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT;
424 }
425
gsl_ts_write(struct i2c_client * client,u8 addr,u8 * pdata,int datalen)426 static int gsl_ts_write(struct i2c_client *client, u8 addr,
427 u8 *pdata, int datalen)
428 {
429 int ret = 0;
430 u8 tmp_buf[128];
431 unsigned int bytelen = 0;
432
433 if (datalen > 125) {
434 pr_err("%s too big datalen = %d!\n", __func__, datalen);
435 return -1;
436 }
437
438 tmp_buf[0] = addr;
439 bytelen++;
440
441 if (datalen != 0 && pdata != NULL) {
442 memcpy(&tmp_buf[bytelen], pdata, datalen);
443 bytelen += datalen;
444 }
445
446 ret = i2c_master_send(client, tmp_buf, bytelen);
447
448 return ret;
449 }
450
gsl_ts_read(struct i2c_client * client,u8 addr,u8 * pdata,unsigned int datalen)451 static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata,
452 unsigned int datalen)
453 {
454 int ret = 0;
455
456 if (datalen > 126) {
457 pr_err("%s too big datalen = %d!\n", __func__, datalen);
458 return -1;
459 }
460
461 ret = gsl_ts_write(client, addr, NULL, 0);
462 if (ret < 0) {
463 pr_err("%s set data address fail!\n", __func__);
464 return ret;
465 }
466
467 return i2c_master_recv(client, pdata, datalen);
468 }
469
gslX680_reg_show(struct device * dev,struct device_attribute * attr,char * buf)470 static ssize_t gslX680_reg_show(
471 struct device *dev,
472 struct device_attribute *attr,
473 char *buf)
474 {
475 u8 mem_buf[4] = {0};
476 u8 int_buf[4] = {0};
477 u8 power_buf[4] = {0};
478 u8 point_buf = 0;
479
480 gsl_ts_read(ts_init->client, 0xb0, mem_buf, sizeof(mem_buf));
481 pr_debug("check mem read 0xb0 = %x %x %x %x\n",
482 mem_buf[3], mem_buf[2], mem_buf[1], mem_buf[0]);
483 gsl_ts_read(ts_init->client, 0xb4, int_buf, sizeof(int_buf));
484 pr_debug("int num read 0xb4 = %d\n",
485 (int_buf[3]<<24) | (int_buf[2]<<16)
486 | (int_buf[1]<<8) | int_buf[0]);
487 gsl_ts_read(ts_init->client, 0xbc, power_buf, sizeof(power_buf));
488 pr_debug("power check read 0xbc = %4x\n",
489 (power_buf[3]<<24) | (power_buf[2]<<16)
490 | (power_buf[1]<<8) | power_buf[0]);
491 gsl_ts_read(ts_init->client, 0x80, &point_buf, 1);
492 pr_debug("point count read 0x80 = %d\n", point_buf);
493
494 return sprintf(buf, "[check mem read = 0x%4x ] [int num read = %d ] [power check read = 0x%4x ] [point count read = %d ]\n",
495 (mem_buf[3]<<24) | (mem_buf[2]<<16) | (mem_buf[1]<<8) | mem_buf[0],
496 (int_buf[3]<<24) | (int_buf[2]<<16) | (int_buf[1]<<8) | int_buf[0],
497 (power_buf[3]<<24) | (power_buf[2]<<16) | (power_buf[1]<<8)
498 | power_buf[0], point_buf);
499 }
500
501 static DEVICE_ATTR(debug_reg, 0444, gslX680_reg_show, NULL);
502
fw2buf(u8 * buf,const u32 * fw)503 static inline void fw2buf(u8 *buf, const u32 *fw)
504 {
505 u32 *u32_buf = (int *)buf;
506 *u32_buf = *fw;
507 }
508
gsl_getfw_from_file(void)509 static int gsl_getfw_from_file(void)
510 {
511 u32 size = 0;
512 u32 len;
513 int err;
514 int idx = 0;
515 const u8 *data;
516 const struct firmware *fw = NULL;
517 char fw_name[128];
518
519 pr_debug("==================getfw from file==================\n");
520
521 snprintf(fw_name, 128, "gsl_firmware/%s.bin", config_info.name);
522
523 err = request_firmware_direct(&fw, fw_name, config_info.dev);
524 if (err) {
525 pr_err("can not get fw from file %s\n", fw_name);
526 return -1;
527 }
528 len = fw->size;
529 data = fw->data;
530
531 // read gslx680_fw_grp.fw size
532 memcpy(&size, &data[idx], sizeof(size));
533 gslx680_fw_grp.size = size;
534 gslx680_fw_grp.fw = kmalloc(size * sizeof (struct fw_data), GFP_KERNEL);
535 if (!gslx680_fw_grp.fw) {
536 pr_err("gslx680_fw_grp.fw malloc failed\n");
537 return -1;
538 }
539 idx += sizeof(size);
540 // read gslx680_fw_grp.fw
541 memcpy((void *)gslx680_fw_grp.fw, &data[idx], size * sizeof (struct fw_data));
542 idx += (size * sizeof(struct fw_data));
543 size = 0;
544 // read gslX680_config_data size
545 memcpy(&size, &data[idx], sizeof(size));
546 idx += sizeof(size);
547 gslX680_config_data = kmalloc(size * sizeof(unsigned int), GFP_KERNEL);
548 if (!gslX680_config_data) {
549 pr_err("gslX680_config_data malloc failed\n");
550 return -1;
551 }
552 memcpy(gslX680_config_data, &data[idx], size * sizeof(unsigned int));
553 idx += (size * sizeof(unsigned int));
554
555 // read gslx680_fw_grp.name size
556 memcpy(&size, &data[idx], sizeof(size));
557 idx += sizeof(size);
558 // read gslx680_fw_grp.name
559 memcpy(gslx680_fw_grp.name, &data[idx], size);
560 idx += size;
561 size = 0;
562 if (idx != len) {
563 err = -1;
564 pr_err("data size is not match fw size: data size = %d, fw size = %u\n", idx, len);
565 }
566 if (strcmp(gslx680_fw_grp.name, config_info.name)) {
567 err = -1;
568 pr_err("firmware name not match, fw name = %s, config name = %s\n", gslx680_fw_grp.name, config_info.name);
569 }
570
571 release_firmware(fw);
572
573 return err;
574 }
575
576
gsl_load_fw(struct i2c_client * client)577 static void gsl_load_fw(struct i2c_client *client)
578 {
579 u8 buf[DMA_TRANS_LEN*4 + 1] = {0};
580 u8 send_flag = 1;
581 u8 *cur = buf + 1;
582 u32 source_line = 0;
583 u32 source_len;
584 const struct fw_data *ptr_fw;
585
586 pr_debug("=============gsl_load_fw start==============\n");
587
588 ptr_fw = gslx680_fw_grp.fw;
589 source_len = gslx680_fw_grp.size;
590
591 for (source_line = 0; source_line < source_len; source_line++) {
592 /* init page trans, set the page val */
593 if (ptr_fw[source_line].offset == GSL_PAGE_REG) {
594 fw2buf(cur, &ptr_fw[source_line].val);
595 gsl_write_interface(client, GSL_PAGE_REG, buf, 4);
596 send_flag = 1;
597 } else {
598 if (send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20) == 1)
599 buf[0] = (u8)ptr_fw[source_line].offset;
600
601 fw2buf(cur, &ptr_fw[source_line].val);
602 cur += 4;
603
604 if (send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20) == 0) {
605 gsl_write_interface(client, buf[0],
606 buf, cur - buf - 1);
607 cur = buf + 1;
608 }
609 send_flag++;
610 }
611 }
612
613 pr_debug("=============gsl_load_fw end==============\n");
614 }
615
startup_chip(struct i2c_client * client)616 static void startup_chip(struct i2c_client *client)
617 {
618 u8 tmp = 0x00;
619
620 #ifdef GSL_NOID_VERSION
621 gsl_DataInit(gslX680_config_data);
622 #endif
623 gsl_ts_write(client, 0xe0, &tmp, 1);
624 usleep_range(10000, 11000);
625 }
626
reset_chip(struct i2c_client * client)627 static void reset_chip(struct i2c_client *client)
628 {
629 u8 tmp = 0x88;
630 u8 buf[4] = {0x00};
631
632 gslX680_shutdown_low();
633 usleep_range(10000, 11000);
634 gslX680_shutdown_high();
635 usleep_range(10000, 11000);
636 gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp));
637 usleep_range(10000, 11000);
638
639 tmp = 0x04;
640 gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp));
641 usleep_range(10000, 11000);
642 gsl_ts_write(client, 0xbc, buf, sizeof(buf));
643 usleep_range(10000, 11000);
644 }
645
clr_reg(struct i2c_client * client)646 static void clr_reg(struct i2c_client *client)
647 {
648 u8 write_buf[4] = {0};
649
650 write_buf[0] = 0x88;
651 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
652 msleep(20);
653 write_buf[0] = 0x03;
654 gsl_ts_write(client, 0x80, &write_buf[0], 1);
655 usleep_range(5000, 6000);
656 write_buf[0] = 0x04;
657 gsl_ts_write(client, 0xe4, &write_buf[0], 1);
658 usleep_range(5000, 6000);
659 write_buf[0] = 0x00;
660 gsl_ts_write(client, 0xe0, &write_buf[0], 1);
661 msleep(20);
662 }
663
init_chip(struct i2c_client * client)664 static void init_chip(struct i2c_client *client)
665 {
666 gslX680_shutdown_low();
667 msleep(50);
668 gslX680_shutdown_high();
669 msleep(30);
670 clr_reg(client);
671 reset_chip(client);
672 gsl_load_fw(client);
673 startup_chip(client);
674 reset_chip(client);
675 startup_chip(client);
676 }
677
_check_chip_state(struct i2c_client * client)678 static bool _check_chip_state(struct i2c_client *client)
679 {
680 u8 read_buf[4] = {0};
681 gsl_ts_read(client, 0xb0, read_buf, sizeof(read_buf));
682
683 pr_debug("#########check mem read 0xb0 = %x %x %x %x #########\n",
684 read_buf[3], read_buf[2], read_buf[1], read_buf[0]);
685
686 if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a ||
687 read_buf[0] != 0x5a) {
688 return false;
689 }
690 return true;
691 }
692
check_chip_state(struct i2c_client * client)693 static bool check_chip_state(struct i2c_client *client)
694 {
695 static int retry;
696 bool ret;
697
698 if (retry > 3) {
699 printk("check_chip_state failed more times, not retry it!!");
700 retry = 0;
701 return true;
702 }
703 ret = _check_chip_state(client);
704 if (ret) {
705 retry = 0;
706 } else {
707 retry++;
708 }
709 return ret;
710 }
711
check_mem_data(struct i2c_client * client)712 static void check_mem_data(struct i2c_client *client)
713 {
714 /*if(gsl_chipType_new == 1) */
715 if (ts_init->is_suspended != false ||
716 ts_init->is_runtime_suspend != false)
717 msleep(30);
718
719 if (!_check_chip_state(client))
720 init_chip(client);
721 }
722 #ifdef STRETCH_FRAME
stretch_frame(u16 * x,u16 * y)723 static void stretch_frame(u16 *x, u16 *y)
724 {
725 u16 temp_x = *x;
726 u16 temp_y = *y;
727 u16 temp_0, temp_1, temp_2;
728
729 if (temp_x < X_STRETCH_MAX + X_STRETCH_CUST) {
730 temp_0 = temp_1 = temp_2 = 0;
731 temp_0 = X_STRETCH_MAX + X_STRETCH_CUST - temp_x;
732 temp_0 = temp_0 > X_STRETCH_CUST ? X_STRETCH_CUST : temp_0;
733 temp_0 = temp_0*(100 + X_RATIO_CUST)/100;
734 if (temp_x < X_STRETCH_MAX) {
735 temp_1 = X_STRETCH_MAX - temp_x;
736 temp_1 = temp_1 > X_STRETCH_MAX/4 ? X_STRETCH_MAX/4 : temp_1;
737 temp_1 = temp_1*(100 + 2*XL_RATIO_1)/100;
738 }
739 if (temp_x < 3*X_STRETCH_MAX/4) {
740 temp_2 = 3*X_STRETCH_MAX/4 - temp_x;
741 temp_2 = temp_2*(100 + 2*XL_RATIO_2)/100;
742 }
743 *x = (temp_0 + temp_1 + temp_2) < (X_STRETCH_MAX +
744 X_STRETCH_CUST) ? ((X_STRETCH_MAX +
745 X_STRETCH_CUST) - (temp_0 + temp_1 + temp_2)) : 1;
746 } else if (temp_x > (CTP_MAX_X - X_STRETCH_MAX - X_STRETCH_CUST)) {
747 temp_0 = temp_1 = temp_2 = 0;
748 temp_0 = temp_x - (CTP_MAX_X - X_STRETCH_MAX - X_STRETCH_CUST);
749 temp_0 = temp_0 > X_STRETCH_CUST ? X_STRETCH_CUST : temp_0;
750 temp_0 = temp_0*(100 + X_RATIO_CUST)/100;
751 if (temp_x > (CTP_MAX_X - X_STRETCH_MAX)) {
752 temp_1 = temp_x - (CTP_MAX_X - X_STRETCH_MAX);
753 temp_1 = temp_1 > X_STRETCH_MAX/4 ? X_STRETCH_MAX/4 : temp_1;
754 temp_1 = temp_1*(100 + 2*XR_RATIO_1)/100;
755 }
756 if (temp_x > (CTP_MAX_X - 3*X_STRETCH_MAX/4)) {
757 temp_2 = temp_x - (CTP_MAX_X - 3*X_STRETCH_MAX/4);
758 temp_2 = temp_2*(100 + 2*XR_RATIO_2)/100;
759 }
760 *x = (temp_0 + temp_1 + temp_2) < (X_STRETCH_MAX +
761 X_STRETCH_CUST) ? ((CTP_MAX_X - X_STRETCH_MAX -
762 X_STRETCH_CUST) + (temp_0 + temp_1 +
763 temp_2)) : (CTP_MAX_X - 1);
764 }
765
766 if (temp_y < Y_STRETCH_MAX + Y_STRETCH_CUST) {
767 temp_0 = temp_1 = temp_2 = 0;
768 temp_0 = Y_STRETCH_MAX + Y_STRETCH_CUST - temp_y;
769 temp_0 = temp_0 > Y_STRETCH_CUST ? Y_STRETCH_CUST : temp_0;
770 temp_0 = temp_0*(100 + Y_RATIO_CUST)/100;
771 if (temp_y < Y_STRETCH_MAX) {
772 temp_1 = Y_STRETCH_MAX - temp_y;
773 temp_1 = temp_1 > Y_STRETCH_MAX/4 ? Y_STRETCH_MAX/4 : temp_1;
774 temp_1 = temp_1*(100 + 2*YL_RATIO_1)/100;
775 }
776 if (temp_y < 3*Y_STRETCH_MAX/4) {
777 temp_2 = 3*Y_STRETCH_MAX/4 - temp_y;
778 temp_2 = temp_2*(100 + 2*YL_RATIO_2)/100;
779 }
780 *y = (temp_0 + temp_1 + temp_2) < (Y_STRETCH_MAX +
781 Y_STRETCH_CUST) ? ((Y_STRETCH_MAX +
782 Y_STRETCH_CUST) - (temp_0 +
783 temp_1 + temp_2)) : 1;
784 } else if (temp_y > (CTP_MAX_Y - Y_STRETCH_MAX - Y_STRETCH_CUST)) {
785 temp_0 = temp_1 = temp_2 = 0;
786 temp_0 = temp_y - (CTP_MAX_Y - Y_STRETCH_MAX - Y_STRETCH_CUST);
787 temp_0 = temp_0 > Y_STRETCH_CUST ? Y_STRETCH_CUST : temp_0;
788 temp_0 = temp_0*(100 + Y_RATIO_CUST)/100;
789 if (temp_y > (CTP_MAX_Y - Y_STRETCH_MAX)) {
790 temp_1 = temp_y - (CTP_MAX_Y - Y_STRETCH_MAX);
791 temp_1 = temp_1 > Y_STRETCH_MAX/4 ? Y_STRETCH_MAX/4 : temp_1;
792 temp_1 = temp_1*(100 + 2*YR_RATIO_1)/100;
793 }
794 if (temp_y > (CTP_MAX_Y - 3*Y_STRETCH_MAX/4)) {
795 temp_2 = temp_y - (CTP_MAX_Y - 3*Y_STRETCH_MAX/4);
796 temp_2 = temp_2*(100 + 2*YR_RATIO_2)/100;
797 }
798 *y = (temp_0 + temp_1 + temp_2) < (Y_STRETCH_MAX +
799 Y_STRETCH_CUST) ? ((CTP_MAX_Y - Y_STRETCH_MAX -
800 Y_STRETCH_CUST) + (temp_0 + temp_1 +
801 temp_2)) : (CTP_MAX_Y - 1);
802 }
803 }
804 #endif
805
806 #ifdef FILTER_POINT
filter_point(u16 x,u16 y,u8 id)807 static void filter_point(u16 x, u16 y, u8 id)
808 {
809 u16 x_err = 0;
810 u16 y_err = 0;
811 u16 filter_step_x = 0, filter_step_y = 0;
812
813 id_sign[id] = id_sign[id] + 1;
814 if (id_sign[id] == 1) {
815 x_old[id] = x;
816 y_old[id] = y;
817 }
818
819 x_err = x > x_old[id] ? (x - x_old[id]) : (x_old[id] - x);
820 y_err = y > y_old[id] ? (y - y_old[id]) : (y_old[id] - y);
821
822 if ((x_err > FILTER_MAX && y_err > FILTER_MAX/3) ||
823 (x_err > FILTER_MAX/3 && y_err > FILTER_MAX)) {
824 filter_step_x = x_err;
825 filter_step_y = y_err;
826 } else {
827 if (x_err > FILTER_MAX)
828 filter_step_x = x_err;
829 if (y_err > FILTER_MAX)
830 filter_step_y = y_err;
831 }
832
833 if (x_err <= 2*FILTER_MAX && y_err <= 2*FILTER_MAX) {
834 filter_step_x >>= 2;
835 filter_step_y >>= 2;
836 } else if (x_err <= 3*FILTER_MAX && y_err <= 3*FILTER_MAX) {
837 filter_step_x >>= 1;
838 filter_step_y >>= 1;
839 } else if (x_err <= 4*FILTER_MAX && y_err <= 4*FILTER_MAX) {
840 filter_step_x = filter_step_x*3/4;
841 filter_step_y = filter_step_y*3/4;
842 }
843
844 x_new = x > x_old[id] ? (x_old[id] + filter_step_x) : (x_old[id] -
845 filter_step_x);
846 y_new = y > y_old[id] ? (y_old[id] + filter_step_y) : (y_old[id] -
847 filter_step_y);
848
849 x_old[id] = x_new;
850 y_old[id] = y_new;
851 }
852 #else
853
record_point(u16 x,u16 y,u8 id)854 static void record_point(u16 x, u16 y, u8 id)
855 {
856 u16 x_err = 0;
857 u16 y_err = 0;
858
859 id_sign[id] = id_sign[id]+1;
860
861 if (id_sign[id] == 1) {
862 x_old[id] = x;
863 y_old[id] = y;
864 }
865
866 x = (x_old[id] + x)/2;
867 y = (y_old[id] + y)/2;
868
869 if (x > x_old[id])
870 x_err = x - x_old[id];
871 else
872 x_err = x_old[id]-x;
873
874 if (y > y_old[id])
875 y_err = y - y_old[id];
876 else
877 y_err = y_old[id]-y;
878
879 if ((x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3)) {
880 x_new = x; x_old[id] = x;
881 y_new = y; y_old[id] = y;
882 } else {
883 if (x_err > 3) {
884 x_new = x;
885 x_old[id] = x;
886 } else
887 x_new = x_old[id];
888
889 if (y_err > 3) {
890 y_new = y;
891 y_old[id] = y;
892 } else
893 y_new = y_old[id];
894 }
895
896 if (id_sign[id] == 1) {
897 x_new = x_old[id];
898 y_new = y_old[id];
899 }
900
901 }
902 #endif
903 #ifdef TPD_PROC_DEBUG
char_to_int(char ch)904 static int char_to_int(char ch)
905 {
906 if (ch >= '0' && ch <= '9')
907 return (ch-'0');
908 else
909 return (ch-'a'+10);
910 }
911
912 /* static int gsl_config_read_proc(char *page, char **start, off_t off,
913 * int count, int *eof, void *data)
914 */
gsl_config_read_proc(struct seq_file * m,void * v)915 static int gsl_config_read_proc(struct seq_file *m, void *v)
916 {
917 /* char *ptr = page; */
918 char temp_data[5] = {0};
919 unsigned int tmp = 0;
920 unsigned int *ptr_fw;
921
922 if ('v' == gsl_read[0] && 's' == gsl_read[1]) {
923 #ifdef GSL_NOID_VERSION
924 tmp = gsl_version_id();
925 #else
926 tmp = 0x20121215;
927 #endif
928 /* ptr += sprintf(ptr,"version:%x\n",tmp); */
929 seq_printf(m, "version:%x\n", tmp);
930 } else if ('r' == gsl_read[0] && 'e' == gsl_read[1]) {
931 if ('i' == gsl_read[3]) {
932 #ifdef GSL_NOID_VERSION
933 tmp = (gsl_data_proc[5]<<8) | gsl_data_proc[4];
934 /* ptr +=sprintf(ptr,"gsl_config_data_id[%u] = ",tmp); */
935 seq_printf(m, "gsl_config_data_id[%u] = ", tmp);
936 if (tmp >= 0 && tmp < 512)
937 /*gslX680_config_data*/
938 /*ptr +=sprintf(ptr,"%d\n",gsl_config_data_id[tmp]); */
939 seq_printf(m, "%d\n", gsl_config_data_id[tmp]);
940 #endif
941 } else {
942 gsl_ts_write(glsX680_i2c, 0xf0, &gsl_data_proc[4], 4);
943 gsl_read_interface(glsX680_i2c, gsl_data_proc[0],
944 temp_data, 4);
945 /*ptr +=sprintf(ptr, "offset : {0x%02x, 0x", gsl_data_proc[0]);*/
946 /*ptr +=sprintf(ptr, "%02x", temp_data[3]);*/
947 /*ptr +=sprintf(ptr, "%02x", temp_data[2]);*/
948 /*ptr +=sprintf(ptr, "%02x", temp_data[1]);*/
949 /*ptr +=sprintf(ptr, "%02x};\n", temp_data[0]);*/
950 seq_printf(m, "offset : {0x%02x,0x", gsl_data_proc[0]);
951 seq_printf(m, "%02x", temp_data[3]);
952 seq_printf(m, "%02x", temp_data[2]);
953 seq_printf(m, "%02x", temp_data[1]);
954 seq_printf(m, "%02x};\n", temp_data[0]);
955 }
956 }
957 /*eof = 1;*/
958 /*return (ptr - page);*/
959 return 0;
960 }
gsl_config_write_proc(struct file * file,const char * buffer,unsigned long count,void * data)961 static int gsl_config_write_proc(struct file *file, const char *buffer,
962 unsigned long count, void *data)
963 {
964 u8 buf[8] = {0};
965 int tmp = 0;
966 int tmp1 = 0;
967
968
969 if (count > CONFIG_LEN) {
970 pr_err("size not match [%d:%ld]\n", CONFIG_LEN, count);
971 return -EFAULT;
972 }
973
974 if (copy_from_user(gsl_read, buffer,
975 (count < CONFIG_LEN?count:CONFIG_LEN))) {
976 pr_err("copy from user fail\n");
977 return -EFAULT;
978 }
979 pr_debug("[tp-gsl][%s][%s]\n", __func__, gsl_read);
980
981 buf[3] = char_to_int(gsl_read[14])<<4 | char_to_int(gsl_read[15]);
982 buf[2] = char_to_int(gsl_read[16])<<4 | char_to_int(gsl_read[17]);
983 buf[1] = char_to_int(gsl_read[18])<<4 | char_to_int(gsl_read[19]);
984 buf[0] = char_to_int(gsl_read[20])<<4 | char_to_int(gsl_read[21]);
985
986 buf[7] = char_to_int(gsl_read[5])<<4 | char_to_int(gsl_read[6]);
987 buf[6] = char_to_int(gsl_read[7])<<4 | char_to_int(gsl_read[8]);
988 buf[5] = char_to_int(gsl_read[9])<<4 | char_to_int(gsl_read[10]);
989 buf[4] = char_to_int(gsl_read[11])<<4 | char_to_int(gsl_read[12]);
990 if ('v' == gsl_read[0] && 's' == gsl_read[1])
991 pr_debug("gsl version\n");
992
993 else if ('s' == gsl_read[0] && 't' == gsl_read[1]) {
994 gsl_proc_flag = 1;
995 reset_chip(glsX680_i2c);
996 } else if ('e' == gsl_read[0] && 'n' == gsl_read[1]) {
997 msleep(20);
998 reset_chip(glsX680_i2c);
999 startup_chip(glsX680_i2c);
1000
1001 #ifdef GSL_NOID_VERSION
1002 gsl_DataInit(gslX680_config_data);
1003 #endif
1004 gsl_proc_flag = 0;
1005 } else if ('r' == gsl_read[0] && 'e' == gsl_read[1])
1006 memcpy(gsl_data_proc, buf, 8);
1007 else if ('w' == gsl_read[0] && 'r' == gsl_read[1])
1008 gsl_ts_write(glsX680_i2c, buf[4], buf, 4);
1009
1010 #ifdef GSL_NOID_VERSION
1011 else if ('i' == gsl_read[0] && 'd' == gsl_read[1]) {
1012 tmp1 = (buf[7]<<24) | (buf[6]<<16) | (buf[5]<<8) | buf[4];
1013 tmp = (buf[3]<<24) | (buf[2]<<16) | (buf[1]<<8) | buf[0];
1014 if (tmp1 >= 0 && tmp1 < 512)
1015 gslX680_config_data[tmp1] = tmp;
1016 }
1017 #endif
1018 return count;
1019 }
gsl_server_list_open(struct inode * inode,struct file * file)1020 static int gsl_server_list_open(struct inode *inode, struct file *file)
1021 {
1022 return single_open(file, gsl_config_read_proc, NULL);
1023 }
1024 static const struct file_operations gsl_seq_fops = {
1025 .open = gsl_server_list_open,
1026 .read = seq_read,
1027 .release = single_release,
1028 .write = gsl_config_write_proc,
1029 .owner = THIS_MODULE,
1030 };
1031 #endif
1032 #ifdef HAVE_TOUCH_KEY
report_key(struct gsl_ts * ts,u16 x,u16 y)1033 static void report_key(struct gsl_ts *ts, u16 x, u16 y)
1034 {
1035 u16 i = 0;
1036
1037 for (i = 0; i < MAX_KEY_NUM; i++) {
1038 if ((gsl_key_data[i].x_min < x) &&
1039 (x < gsl_key_data[i].x_max) &&
1040 (gsl_key_data[i].y_min < y) &&
1041 (y < gsl_key_data[i].y_max)) {
1042 key = gsl_key_data[i].key;
1043 pr_debug("key=%d\n", key);
1044 input_report_key(ts->input, key, 1);
1045 input_sync(ts->input);
1046 key_state_flag = 1;
1047 break;
1048 }
1049 }
1050 }
1051 #endif
1052
report_data(struct gsl_ts * ts,u16 x,u16 y,u8 pressure,u8 id)1053 static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id)
1054 {
1055 pr_debug("source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, pressure);
1056 if (exchange_x_y_flag == 1)
1057 swap(x, y);
1058
1059 if (revert_x_flag == 1)
1060 x = SCREEN_MAX_X - x;
1061
1062 if (revert_y_flag == 1)
1063 y = SCREEN_MAX_Y - y;
1064
1065 pr_debug("report data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, pressure);
1066
1067 if (x > SCREEN_MAX_X || y > SCREEN_MAX_Y) {
1068 #ifdef HAVE_TOUCH_KEY
1069
1070 report_key(ts, x, y);
1071
1072 #endif
1073 return;
1074 }
1075
1076 #ifdef REPORT_DATA_ANDROID_4_0
1077 input_mt_slot(ts->input, id);
1078 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
1079 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
1080 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
1081 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
1082 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
1083 #else
1084 input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
1085 input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure);
1086 input_report_abs(ts->input, ABS_MT_POSITION_X, x);
1087 input_report_abs(ts->input, ABS_MT_POSITION_Y, y);
1088 input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1);
1089 input_mt_sync(ts->input);
1090 #endif
1091 }
1092
1093
process_gslX680_data(struct gsl_ts * ts)1094 static void process_gslX680_data(struct gsl_ts *ts)
1095 {
1096 u8 id, touches;
1097 u16 x, y;
1098 int i = 0;
1099 #ifdef GSL_NOID_VERSION
1100 struct gsl_touch_info cinfo;
1101 #endif
1102 touches = ts->touch_data[ts->dd->touch_index];
1103 #ifdef GSL_NOID_VERSION
1104 cinfo.finger_num = touches;
1105 pr_debug("tp-gsl finger_num = %d\n", cinfo.finger_num);
1106 for (i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i++) {
1107 cinfo.x[i] = join_bytes((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf),
1108 ts->touch_data[ts->dd->x_index + 4 * i]);
1109 cinfo.y[i] = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
1110 ts->touch_data[ts->dd->y_index + 4 * i]);
1111 }
1112 cinfo.finger_num = ts->touch_data[0] | (ts->touch_data[1]<<8) |
1113 (ts->touch_data[2]<<16) | (ts->touch_data[3]<<24);
1114 gsl_alg_id_main(&cinfo);
1115 pr_debug("tp-gsl finger_num = %d\n", cinfo.finger_num);
1116 #if 0
1117 tmp1 = gsl_mask_tiaoping();
1118 if (tmp1 > 0 && tmp1 < 0xffffffff) {
1119 buf[0] = 0xa;
1120 buf[1] = 0;
1121 buf[2] = 0;
1122 buf[3] = 0;
1123 gsl_ts_write(ts->client, 0xf0, buf, 4);
1124 buf[0] = (u8)(tmp1 & 0xff);
1125 buf[1] = (u8)((tmp1>>8) & 0xff);
1126 buf[2] = (u8)((tmp1>>16) & 0xff);
1127 buf[3] = (u8)((tmp1>>24) & 0xff);
1128 pr_debug("tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x,buf[3]=%02x\n",
1129 tmp1, buf[0], buf[1], buf[2], buf[3]);
1130 gsl_write_interface(ts->client, 0x8, buf, 4);
1131 }
1132 #endif
1133 touches = cinfo.finger_num;
1134 input_report_key(ts->input, BTN_TOUCH, (touches > 0 ? 1 : 0));
1135 #endif
1136 for (i = 1; i <= MAX_CONTACTS; i++) {
1137 if (touches == 0)
1138 id_sign[i] = 0;
1139 id_state_flag[i] = 0;
1140 }
1141 for (i = 0; i < (touches > MAX_FINGERS ? MAX_FINGERS : touches); i++) {
1142 #ifdef GSL_NOID_VERSION
1143 id = cinfo.id[i];
1144 x = cinfo.x[i];
1145 y = cinfo.y[i];
1146 #else
1147 x = join_bytes((ts->touch_data[ts->dd->x_index+4*i+1] & 0xf),
1148 ts->touch_data[ts->dd->x_index + 4 * i]);
1149 y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1],
1150 ts->touch_data[ts->dd->y_index + 4 * i]);
1151 id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4;
1152 #endif
1153 if (1 <= id && id <= MAX_CONTACTS) {
1154 #ifdef STRETCH_FRAME
1155 stretch_frame(&x, &y);
1156
1157 #endif
1158 #ifdef FILTER_POINT
1159 filter_point(x, y, id);
1160 #else
1161 record_point(x, y, id);
1162 #endif
1163 report_data(ts, x_new, y_new, 10, id);
1164 id_state_flag[id] = 1;
1165 }
1166 }
1167
1168
1169 for (i = 1; i <= MAX_CONTACTS ; i++) {
1170 if ((touches == 0) || ((id_state_old_flag[i] != 0) &&
1171 (id_state_flag[i] == 0))) {
1172 #ifdef REPORT_DATA_ANDROID_4_0
1173 input_mt_slot(ts->input, i);
1174 input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1);
1175 input_mt_report_slot_state(ts->input, MT_TOOL_FINGER,
1176 false);
1177 #endif
1178 id_sign[i] = 0;
1179 }
1180 id_state_old_flag[i] = id_state_flag[i];
1181 }
1182 #ifndef REPORT_DATA_ANDROID_4_0
1183 if (touches == 0) {
1184 #ifdef HAVE_TOUCH_KEY
1185 if (key_state_flag) {
1186 input_report_key(ts->input, key, 0);
1187 input_sync(ts->input);
1188 key_state_flag = 0;
1189 }
1190 #endif
1191 }
1192 #endif
1193 input_sync(ts->input);
1194 ts->prev_touches = touches;
1195 }
1196
1197
gsl_ts_xy_worker(struct work_struct * work)1198 static void gsl_ts_xy_worker(struct work_struct *work)
1199 {
1200 int rc;
1201 u8 read_buf[4] = {0};
1202 struct gsl_ts *ts = container_of(work, struct gsl_ts, work);
1203 #ifndef GSL_TIMER
1204 int ret;
1205
1206 input_set_int_enable(&(config_info.input_type), 0);
1207 #endif
1208 pr_debug("---gsl_ts_xy_worker---\n");
1209 #ifdef TPD_PROC_DEBUG
1210 if (gsl_proc_flag == 1)
1211 goto schedule;
1212 #endif
1213 /* read data from DATA_REG */
1214 rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size);
1215 pr_debug("---touches: %d ---\n", ts->touch_data[0]);
1216 if (rc < 0) {
1217 dev_err(&ts->client->dev, "read failed\n");
1218 goto schedule;
1219 }
1220
1221 if (ts->touch_data[ts->dd->touch_index] == 0xff)
1222 goto schedule;
1223
1224 rc = gsl_ts_read(ts->client, 0xbc, read_buf, sizeof(read_buf));
1225 if (rc < 0) {
1226 dev_err(&ts->client->dev, "read 0xbc failed\n");
1227 goto schedule;
1228 }
1229 pr_debug("reg %x : %x %x %x %x\n", 0xbc, read_buf[3],
1230 read_buf[2], read_buf[1], read_buf[0]);
1231 if (read_buf[3] == 0 && read_buf[2] == 0 && read_buf[1] == 0 &&
1232 read_buf[0] == 0){
1233 process_gslX680_data(ts);
1234 } else {
1235 if (!_check_chip_state(glsX680_i2c)) {
1236 printk("gslX680 gsl_ts_xy_worker fail and check state fialed!!!\n");
1237 }
1238 }
1239
1240 schedule:
1241 #ifndef GSL_TIMER
1242 ret = input_set_int_enable(&(config_info.input_type), 1);
1243 if (ret < 0)
1244 printk("%s irq enable failed\n", __func__);
1245 #endif
1246 }
1247
1248
1249 #ifdef GSL_MONITOR
gsl_monitor_worker(struct work_struct * work)1250 static void gsl_monitor_worker(struct work_struct *work)
1251 {
1252 char read_buf[4] = {0};
1253
1254 pr_debug("-----------gsl_monitor_worker----------\n");
1255
1256 gsl_ts_read(glsX680_i2c, 0xb4, read_buf, 4);
1257 int_2nd[3] = int_1st[3];
1258 int_2nd[2] = int_1st[2];
1259 int_2nd[1] = int_1st[1];
1260 int_2nd[0] = int_1st[0];
1261 int_1st[3] = read_buf[3];
1262 int_1st[2] = read_buf[2];
1263 int_1st[1] = read_buf[1];
1264 int_1st[0] = read_buf[0];
1265
1266 if (int_1st[3] == int_2nd[3] && int_1st[2] == int_2nd[2] &&
1267 int_1st[1] == int_2nd[1] && int_1st[0] == int_2nd[0]) {
1268 pr_debug("===int_1st:%x %x %x %x , int_2nd:%x %x %x %x===\n",
1269 int_1st[3], int_1st[2], int_1st[1], int_1st[0],
1270 int_2nd[3], int_2nd[2], int_2nd[1], int_2nd[0]);
1271 init_chip(glsX680_i2c);
1272 }
1273 queue_delayed_work(gsl_monitor_workqueue, &gsl_monitor_work, 300);
1274 }
1275 #endif
1276
1277
gsl_ts_irq(int irq,void * dev_id)1278 irqreturn_t gsl_ts_irq(int irq, void *dev_id)
1279 {
1280 struct gsl_ts *ts = (struct gsl_ts *)dev_id;
1281
1282 pr_debug("==========GSLX680 Interrupt============\n");
1283 queue_work(ts->wq, &ts->work);
1284 #ifdef GSL_TIMER
1285 mod_timer(&ts->gsl_timer, jiffies + msecs_to_jiffies(30));
1286 #endif
1287 return IRQ_HANDLED;
1288 }
1289
1290 #if GSL_MONITOR_TIMER_ENABLE
glsX680_monitor_events(struct work_struct * work)1291 static void glsX680_monitor_events(struct work_struct *work)
1292 {
1293 if (!_check_chip_state(glsX680_i2c) || gTestMonitor == 1) {
1294 printk("gsl_monitor_timer_handle check failed, reinit chip!!\n");
1295 input_set_int_enable(&(config_info.input_type), 0);
1296 cancel_work_sync(&ts_init->work);
1297 queue_work(gslX680_resume_wq, &glsX680_resume_work);
1298 gTestMonitor = 0;
1299 } else {
1300 pr_debug("gsl_monitor_timer_handle check success!!!\n");
1301 del_timer(&monitor_timer);
1302 monitor_timer.expires = jiffies + msecs_to_jiffies(3000);
1303 add_timer(&monitor_timer);
1304 }
1305 }
gsl_monitor_timer_handle(struct timer_list * timer)1306 static void gsl_monitor_timer_handle(struct timer_list *timer)
1307 {
1308 queue_work(ts_init->wq, &glsX680_monitor_work);
1309 }
1310 #endif
1311
1312 #ifdef GSL_TIMER
gsl_timer_handle(unsigned long data)1313 static void gsl_timer_handle(unsigned long data)
1314 {
1315 struct gsl_ts *ts = (struct gsl_ts *)data;
1316
1317 #ifdef GSL_DEBUG
1318 pr_debug("----------------gsl_timer_handle-----------------\n");
1319 #endif
1320 ret = input_set_int_enable(&(config_info.input_type), 1);
1321 if (ret < 0)
1322 pr_debug("%s irq disable failed\n", __func__);
1323 check_mem_data(ts->client);
1324 ts->gsl_timer.expires = jiffies + 3 * HZ;
1325 add_timer(&ts->gsl_timer);
1326 }
1327 #endif
1328
gsl_ts_init_ts(struct i2c_client * client,struct gsl_ts * ts)1329 static int gsl_ts_init_ts(struct i2c_client *client, struct gsl_ts *ts)
1330 {
1331 struct input_dev *input_device;
1332 int rc = 0;
1333 #ifdef HAVE_TOUCH_KEY
1334 int i = 0;
1335 #endif
1336 pr_debug("[GSLX680] Enter %s\n", __func__);
1337 ts->dd = &devices[ts->device_id];
1338
1339 if (ts->device_id == 0) {
1340 ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes +
1341 ts->dd->touch_meta_data;
1342 ts->dd->touch_index = 0;
1343 }
1344
1345 ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL);
1346
1347 ts->prev_touches = 0;
1348
1349 input_device = input_allocate_device();
1350 if (!input_device) {
1351 rc = -ENOMEM;
1352 goto error_alloc_dev;
1353 }
1354
1355 ts->input = input_device;
1356 input_device->name = GSLX680_I2C_NAME;
1357 input_device->id.bustype = BUS_I2C;
1358 input_device->dev.parent = &client->dev;
1359 input_set_drvdata(input_device, ts);
1360
1361 #ifdef REPORT_DATA_ANDROID_4_0
1362 __set_bit(EV_ABS, input_device->evbit);
1363 __set_bit(EV_KEY, input_device->evbit);
1364 __set_bit(EV_REP, input_device->evbit);
1365 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1366 input_mt_init_slots(input_device, (MAX_CONTACTS+1));
1367 #else
1368 input_set_abs_params(input_device, ABS_MT_TRACKING_ID, 0,
1369 (MAX_CONTACTS+1), 0, 0);
1370 set_bit(EV_ABS, input_device->evbit);
1371 set_bit(EV_KEY, input_device->evbit);
1372 __set_bit(INPUT_PROP_DIRECT, input_device->propbit);
1373 input_device->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
1374 #endif
1375 #ifdef HAVE_TOUCH_KEY
1376 for (i = 0; i < MAX_KEY_NUM; i++)
1377 set_bit(key_array[i] & KEY_MAX, input_device->keybit);
1378
1379 #endif
1380
1381 set_bit(ABS_MT_POSITION_X, input_device->absbit);
1382 set_bit(ABS_MT_POSITION_Y, input_device->absbit);
1383 set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit);
1384 set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit);
1385
1386 input_set_abs_params(input_device, ABS_MT_POSITION_X, 0,
1387 SCREEN_MAX_X, 0, 0);
1388 input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0,
1389 SCREEN_MAX_Y, 0, 0);
1390 input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0,
1391 PRESS_MAX, 0, 0);
1392 input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
1393
1394 ts->wq = create_singlethread_workqueue("kworkqueue_ts");
1395 if (!ts->wq) {
1396 dev_err(&client->dev, "Could not create workqueue\n");
1397 goto error_wq_create;
1398 }
1399 flush_workqueue(ts->wq);
1400
1401 INIT_WORK(&ts->work, gsl_ts_xy_worker);
1402
1403 rc = input_register_device(input_device);
1404 if (rc)
1405 goto error_unreg_device;
1406
1407 return 0;
1408
1409 error_unreg_device:
1410 destroy_workqueue(ts->wq);
1411 error_wq_create:
1412 input_free_device(input_device);
1413 error_alloc_dev:
1414 kfree(ts->touch_data);
1415 return rc;
1416 }
1417
glsX680_resume_events(struct work_struct * work)1418 static void glsX680_resume_events(struct work_struct *work)
1419 {
1420 #ifndef GSL_TIMER
1421 int ret;
1422 #endif
1423 #if GSL_MONITOR_TIMER_ENABLE
1424 del_timer(&monitor_timer);
1425 #endif
1426 while (true) {
1427 gslX680_shutdown_low();
1428 if (ldo_state) {
1429 input_set_power_enable(&(config_info.input_type), 0);
1430 ldo_state--;
1431 msleep(200);
1432 } else {
1433 msleep(10);
1434 }
1435 input_set_power_enable(&(config_info.input_type), 1);
1436 ldo_state++;
1437 gslX680_shutdown_high();
1438 usleep_range(10000, 11000);
1439 reset_chip(glsX680_i2c);
1440 startup_chip(glsX680_i2c);
1441 check_mem_data(glsX680_i2c);
1442 #ifndef GSL_TIMER
1443 if (check_chip_state(glsX680_i2c)) {
1444 ret = input_set_int_enable(&(config_info.input_type), 1);
1445 if (ret < 0)
1446 pr_debug("%s irq disable failed\n", __func__);
1447 printk("gslX680_resume_events success!!!\n");
1448 #if GSL_MONITOR_TIMER_ENABLE
1449 del_timer(&monitor_timer);
1450 monitor_timer.expires = jiffies + msecs_to_jiffies(3000);
1451 add_timer(&monitor_timer);
1452 #endif
1453 return;
1454 } else {
1455 printk("glsX680_resume_events failed, retry!!!!\n");
1456 }
1457 #endif
1458 }
1459 }
1460
1461 static unsigned long idle_data;
1462 static unsigned long idle_next_data;
1463 #if IS_ENABLED(CONFIG_PM)
gsl_ts_suspend(struct device * dev)1464 static int gsl_ts_suspend(struct device *dev)
1465 {
1466 #ifndef GSL_TIMER
1467 int ret;
1468 #endif
1469 struct gsl_ts *ts = dev_get_drvdata(dev);
1470
1471 pr_debug("%s,start\n", __func__);
1472 #if GSL_MONITOR_TIMER_ENABLE
1473 del_timer(&monitor_timer);
1474 cancel_work_sync(&glsX680_monitor_work);
1475 #endif
1476 cancel_work_sync(&glsX680_resume_work);
1477 cancel_work_sync(&glsX680_idle_work);
1478 flush_workqueue(gslX680_resume_wq);
1479 #if GSL_MONITOR_TIMER_ENABLE
1480 del_timer(&monitor_timer);
1481 cancel_work_sync(&glsX680_monitor_work);
1482 #endif
1483 /*if already do runtime suspend,and try to do suspend,then return*/
1484 if (pm_runtime_suspended(dev)) {
1485 pr_debug("do suspend\n");
1486 ts->is_suspended = true;
1487 return 0;
1488 }
1489
1490 #ifdef GSL_TIMER
1491 pr_debug("gsl_ts_suspend () : delete gsl_timer\n");
1492 del_timer(&ts->gsl_timer);
1493 #endif
1494
1495 #ifndef GSL_TIMER
1496 ret = input_set_int_enable(&(config_info.input_type), 0);
1497 if (ret < 0)
1498 printk("%s irq disable failed\n", __func__);
1499 #endif
1500 flush_workqueue(gslX680_resume_wq);
1501 cancel_work_sync(&ts->work);
1502 flush_workqueue(ts->wq);
1503 gslX680_shutdown_low();
1504
1505 if (ts->try_to_runtime_suspend) {
1506 pr_debug("do runtime_suspend\n");
1507 ts->is_runtime_suspend = true;
1508 } else {
1509 pr_debug("do suspend\n");
1510 ts->is_suspended = true;
1511 }
1512 input_set_power_enable(&(config_info.input_type), 0);
1513 ldo_state--;
1514 pr_info("gslX680 suspend finished");
1515 return 0;
1516 }
1517
gsl_ts_resume(struct device * dev)1518 static int gsl_ts_resume(struct device *dev)
1519 {
1520 struct gsl_ts *ts = dev_get_drvdata(dev);
1521
1522 if (ts->is_runtime_suspend && ts->is_suspended) {
1523 pr_debug("do resume\n");
1524 ts->is_suspended = false;
1525 return 0;
1526 }
1527 pr_debug("I'am in gsl_ts_resume() start\n");
1528 cancel_work_sync(&ts->work);
1529 #if GSL_MONITOR_TIMER_ENABLE
1530 cancel_work_sync(&glsX680_monitor_work);
1531 #endif
1532 flush_workqueue(ts->wq);
1533 queue_work(gslX680_resume_wq, &glsX680_resume_work);
1534
1535 if (ts->try_to_runtime_suspend && ts->is_runtime_suspend &&
1536 !ts->is_suspended) {
1537 pr_debug("do runtime_resume\n");
1538 ts->try_to_runtime_suspend = false;
1539 ts->is_runtime_suspend = false;
1540 } else if (ts->is_suspended) {
1541 pr_debug("do resume\n");
1542 ts->is_suspended = false;
1543 }
1544
1545 #ifdef GSL_TIMER
1546 pr_debug("gsl_ts_resume () : add gsl_timer\n");
1547 init_timer(&ts->gsl_timer);
1548 ts->gsl_timer.expires = jiffies + 3 * HZ;
1549 ts->gsl_timer.function = &gsl_timer_handle;
1550 ts->gsl_timer.data = (unsigned long)ts;
1551 add_timer(&ts->gsl_timer);
1552 #endif
1553 pr_info("gslX680 resume finished");
1554 return 0;
1555 }
1556 #endif
1557
1558
glsX680_init_events(struct work_struct * work)1559 static void glsX680_init_events(struct work_struct *work)
1560 {
1561 int ret = 0;
1562
1563 gslX680_chip_init();
1564 init_chip(glsX680_i2c);
1565 check_mem_data(glsX680_i2c);
1566
1567 #ifndef GSL_TIMER
1568 config_info.dev = &(ts_init->input->dev);
1569 ret = input_request_int(&(config_info.input_type), gsl_ts_irq,
1570 CTP_IRQ_MODE, ts_init);
1571 if (ret)
1572 printk("glsX680_init_events: request irq failed\n");
1573 #else
1574 pr_debug("add gsl_timer\n");
1575 init_timer(&ts_init->gsl_timer);
1576 ts_init->gsl_timer.expires = jiffies + msecs_to_jiffies(500);
1577 ts_init->gsl_timer.function = &gsl_ts_irq;
1578 ts_init->gsl_timer.data = (unsigned long)ts_init;
1579 add_timer(&ts_init->gsl_timer);
1580 #endif
1581 #if GSL_MONITOR_TIMER_ENABLE
1582 monitor_timer.expires = jiffies + msecs_to_jiffies(3000);;
1583 add_timer(&monitor_timer);
1584 #endif
1585 }
1586
1587 static unsigned long data_save;
1588
gsl_enable_show(struct device * dev,struct device_attribute * attr,char * buf)1589 static ssize_t gsl_enable_show(struct device *dev,
1590 struct device_attribute *attr, char *buf)
1591 {
1592 return sprintf(buf, "%d\n", (int)data_save);
1593 }
1594
runtime_suspend_show(struct class * cls,struct class_attribute * attr,char * buf)1595 static ssize_t runtime_suspend_show(struct class *cls,
1596 struct class_attribute *attr, char *buf)
1597 {
1598 return sprintf(buf, "%d\n", (int)data_save);
1599 }
gsl_enable_store_l(const char * buf)1600 static ssize_t gsl_enable_store_l(const char *buf)
1601 {
1602 int error;
1603 //struct input_dev *input = to_input_dev(dev);
1604 struct i2c_client *client = input_get_drvdata(gDevice);
1605
1606 error = kstrtoul(buf, 10, &data_save);
1607 if (error)
1608 return error;
1609 if (data_save == 0 && !ts_init->is_runtime_suspend) {
1610 pr_info("gslX680 go to runtime_suspend\n");
1611 ts_init->try_to_runtime_suspend = true;
1612 pm_runtime_put(&client->dev);
1613 } else if (data_save == 1 && ts_init->is_runtime_suspend) {
1614 pr_info("gslX680 go to runtime_resume\n");
1615 pm_runtime_get_sync(&client->dev);
1616 }
1617 return 0;
1618 }
1619
gsl_enable_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1620 static ssize_t gsl_enable_store(struct device *dev,
1621 struct device_attribute *attr,
1622 const char *buf, size_t count)
1623 {
1624 int error = gsl_enable_store_l(buf);
1625
1626 if (error)
1627 return error;
1628 return count;
1629 }
1630
runtime_suspend_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1631 static ssize_t runtime_suspend_store(struct class *cls,
1632 struct class_attribute *attr,
1633 const char *buf, size_t count)
1634 {
1635 int error = gsl_enable_store_l(buf);
1636
1637 if (error)
1638 return error;
1639 return count;
1640 }
1641
gsl_idle_enable_show(struct device * dev,struct device_attribute * attr,char * buf)1642 static ssize_t gsl_idle_enable_show(struct device *dev,
1643 struct device_attribute *attr, char *buf)
1644 {
1645 return sprintf(buf, "%d\n", (int)idle_data);
1646 }
1647
tp_idle_show(struct class * cls,struct class_attribute * attr,char * buf)1648 static ssize_t tp_idle_show(struct class *cls,
1649 struct class_attribute *attr, char *buf)
1650 {
1651 return sprintf(buf, "%d\n", (int)idle_data);
1652 }
1653
tp_state_show(struct class * cls,struct class_attribute * attr,char * buf)1654 static ssize_t tp_state_show(struct class *cls,
1655 struct class_attribute *attr, char *buf)
1656 {
1657 return sprintf(buf, "%d\n", _check_chip_state(glsX680_i2c));
1658 }
1659
glsX680_idle_events(struct work_struct * work)1660 static void glsX680_idle_events(struct work_struct *work)
1661 {
1662 if (idle_next_data == 1 && idle_data == 0) {
1663 input_set_int_enable(&(config_info.input_type), 0);
1664 idle_data = 1;
1665 #if GSL_MONITOR_TIMER_ENABLE
1666 del_timer(&monitor_timer);
1667 cancel_work_sync(&glsX680_monitor_work);
1668 #endif
1669 cancel_work_sync(&glsX680_resume_work);
1670 msleep(10);
1671 pr_info("gslX680 go to idle\n");
1672 gslX680_shutdown_low();
1673 } else if (idle_next_data == 0 && idle_data == 1) {
1674 #if GSL_MONITOR_TIMER_ENABLE
1675 del_timer(&monitor_timer);
1676 cancel_work_sync(&glsX680_monitor_work);
1677 #endif
1678 pr_info("gslX680 go to active\n");
1679 reset_chip(glsX680_i2c);
1680 startup_chip(glsX680_i2c);
1681 msleep(10);
1682 input_set_int_enable_force(&(config_info.input_type), 1);
1683 idle_data = 0;
1684 #if GSL_MONITOR_TIMER_ENABLE
1685 monitor_timer.expires = jiffies + msecs_to_jiffies(3000);
1686 del_timer(&monitor_timer);
1687 add_timer(&monitor_timer);
1688 #endif
1689 }
1690 }
1691
gsl_idle_enable_store_l(const char * buf)1692 static ssize_t gsl_idle_enable_store_l(const char *buf)
1693 {
1694 int error;
1695
1696 error = kstrtoul(buf, 10, &idle_next_data);
1697 if (error)
1698 return error;
1699 if (idle_next_data != idle_data) {
1700 queue_work(gslX680_resume_wq, &glsX680_idle_work);
1701 }
1702 return 0;
1703 }
1704
gsl_idle_enable_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)1705 static ssize_t gsl_idle_enable_store(struct device *dev,
1706 struct device_attribute *attr,
1707 const char *buf, size_t count)
1708 {
1709 int error = gsl_idle_enable_store_l(buf);
1710
1711 if (error)
1712 return error;
1713 return count;
1714 }
1715
tp_idle_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1716 static ssize_t tp_idle_store(struct class *cls,
1717 struct class_attribute *attr,
1718 const char *buf, size_t count)
1719 {
1720 int error = gsl_idle_enable_store_l(buf);
1721
1722 if (error)
1723 return error;
1724 return count;
1725 }
1726
screen_width_show(struct class * cls,struct class_attribute * attr,char * buf)1727 static ssize_t screen_width_show(struct class *cls,
1728 struct class_attribute *attr, char *buf)
1729 {
1730 return sprintf(buf, "%d\n", (int)screen_max_x);
1731 }
1732
screen_width_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1733 static ssize_t screen_width_store(struct class *cls,
1734 struct class_attribute *attr,
1735 const char *buf, size_t count)
1736 {
1737 int error;
1738 int val;
1739 error = kstrtoint(buf, 10, &val);
1740 if (error)
1741 return error;
1742 screen_max_x = val;
1743 return count;
1744 }
1745
screen_height_show(struct class * cls,struct class_attribute * attr,char * buf)1746 static ssize_t screen_height_show(struct class *cls,
1747 struct class_attribute *attr, char *buf)
1748 {
1749 return sprintf(buf, "%d\n", (int)screen_max_y);
1750 }
1751
screen_height_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1752 static ssize_t screen_height_store(struct class *cls,
1753 struct class_attribute *attr,
1754 const char *buf, size_t count)
1755 {
1756 int error;
1757 int val;
1758 error = kstrtoint(buf, 10, &val);
1759 if (error)
1760 return error;
1761 screen_max_y = val;
1762 return count;
1763 }
1764
screen_revert_x_show(struct class * cls,struct class_attribute * attr,char * buf)1765 static ssize_t screen_revert_x_show(struct class *cls,
1766 struct class_attribute *attr, char *buf)
1767 {
1768 return sprintf(buf, "%d\n", (int)revert_x_flag);
1769 }
1770
screen_revert_x_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1771 static ssize_t screen_revert_x_store(struct class *cls,
1772 struct class_attribute *attr,
1773 const char *buf, size_t count)
1774 {
1775 int error;
1776 int val;
1777 error = kstrtoint(buf, 10, &val);
1778 if (error || (val != 0 && val != 1))
1779 return error;
1780 revert_x_flag = val;
1781 return count;
1782 }
1783
screen_revert_y_show(struct class * cls,struct class_attribute * attr,char * buf)1784 static ssize_t screen_revert_y_show(struct class *cls,
1785 struct class_attribute *attr, char *buf)
1786 {
1787 return sprintf(buf, "%d\n", (int)revert_y_flag);
1788 }
1789
screen_revert_y_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1790 static ssize_t screen_revert_y_store(struct class *cls,
1791 struct class_attribute *attr,
1792 const char *buf, size_t count)
1793 {
1794 int error;
1795 int val;
1796 error = kstrtoint(buf, 10, &val);
1797 if (error || (val != 0 && val != 1))
1798 return error;
1799 revert_y_flag = val;
1800 return count;
1801 }
1802
screen_exchange_xy_show(struct class * cls,struct class_attribute * attr,char * buf)1803 static ssize_t screen_exchange_xy_show(struct class *cls,
1804 struct class_attribute *attr, char *buf)
1805 {
1806 return sprintf(buf, "%d\n", (int)exchange_x_y_flag);
1807 }
1808
screen_exchange_xy_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1809 static ssize_t screen_exchange_xy_store(struct class *cls,
1810 struct class_attribute *attr,
1811 const char *buf, size_t count)
1812 {
1813 int error;
1814 int val;
1815 error = kstrtoint(buf, 10, &val);
1816 if (error || (val != 0 && val != 1))
1817 return error;
1818 exchange_x_y_flag = val;
1819 return count;
1820 }
1821
1822 #if GSL_MONITOR_TIMER_ENABLE
tp_monitor_store(struct class * cls,struct class_attribute * attr,const char * buf,size_t count)1823 static ssize_t tp_monitor_store(struct class *cls,
1824 struct class_attribute *attr,
1825 const char *buf, size_t count)
1826 {
1827 gTestMonitor = 1;
1828 queue_work(gslX680_resume_wq, &glsX680_monitor_work);
1829
1830 return count;
1831 }
1832 #endif
1833 static DEVICE_ATTR(runtime_suspend, S_IRUGO | S_IWUSR | S_IWGRP,
1834 gsl_enable_show, gsl_enable_store);
1835
1836 static DEVICE_ATTR(tp_idle, S_IRUGO | S_IWUSR | S_IWGRP,
1837 gsl_idle_enable_show, gsl_idle_enable_store);
1838
1839 static struct attribute *gsl_attributes[] = {
1840 &dev_attr_runtime_suspend.attr,
1841 &dev_attr_tp_idle.attr,
1842 NULL
1843 };
1844
1845
1846 static CLASS_ATTR_RW(runtime_suspend);
1847 static CLASS_ATTR_RW(tp_idle);
1848 static CLASS_ATTR_RO(tp_state);
1849 #if GSL_MONITOR_TIMER_ENABLE
1850 static CLASS_ATTR_WO(tp_monitor);
1851 #endif
1852 static CLASS_ATTR_RW(screen_width);
1853 static CLASS_ATTR_RW(screen_height);
1854 static CLASS_ATTR_RW(screen_revert_x);
1855 static CLASS_ATTR_RW(screen_revert_y);
1856 static CLASS_ATTR_RW(screen_exchange_xy);
1857
1858 static struct attribute_group gsl_attr_group = {
1859 .attrs = gsl_attributes,
1860 };
1861
1862 static struct attribute *ctp_class_attrs[] = {
1863 &class_attr_runtime_suspend.attr,
1864 &class_attr_tp_idle.attr,
1865 &class_attr_tp_state.attr,
1866 #if GSL_MONITOR_TIMER_ENABLE
1867 &class_attr_tp_monitor.attr,
1868 #endif
1869 &class_attr_screen_width.attr,
1870 &class_attr_screen_height.attr,
1871 &class_attr_screen_revert_x.attr,
1872 &class_attr_screen_revert_y.attr,
1873 &class_attr_screen_exchange_xy.attr,
1874 NULL
1875 };
1876
1877 ATTRIBUTE_GROUPS(ctp_class);
1878
1879 static struct class ctp_class = {
1880 .name = "ctp",
1881 .owner = THIS_MODULE,
1882 .class_groups = ctp_class_groups,
1883 };
1884
startup(void)1885 static int startup(void)
1886 {
1887 int ret = 0;
1888 pr_debug("*******************************************\n");
1889 if (input_sensor_startup(&(config_info.input_type))) {
1890 pr_err("%s: ctp_startup err.\n", __func__);
1891 return 0;
1892 } else {
1893 ret = input_sensor_init(&(config_info.input_type));
1894 if (ret != 0)
1895 pr_debug("%s:ctp_ops.init err.\n", __func__);
1896 }
1897 if (config_info.ctp_used == 0) {
1898 pr_debug("*** ctp_used set to 0 !\n");
1899 pr_debug("if use ctp,please put the sys_config.fex ctp_used set to 1.\n");
1900 return 0;
1901 }
1902 if (!ctp_get_system_config()) {
1903 pr_err("%s:read config fail!\n", __func__);
1904 return 0;
1905 }
1906
1907 input_set_power_enable(&(config_info.input_type), 1);
1908 ldo_state++;
1909 msleep(20);
1910 ctp_wakeup(1, 0);
1911 return 1;
1912 }
1913
gsl_ts_probe(struct i2c_client * client,const struct i2c_device_id * id)1914 static int gsl_ts_probe(struct i2c_client *client,
1915 const struct i2c_device_id *id)
1916 {
1917 struct gsl_ts *ts;
1918 int rc = 0;
1919 int ret = 0;
1920
1921 pr_debug("GSLX680 Enter %s\n", __func__);
1922 if (config_info.dev == NULL)
1923 config_info.dev = &client->dev;
1924 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1925 dev_err(&client->dev, "I2C functionality not supported\n");
1926 return -ENODEV;
1927 }
1928
1929 pr_debug("%s:fwname:%s\n", __func__, fwname);
1930 ret = gsl_getfw_from_file();
1931 if (ret != 0) {
1932 return -1;
1933 }
1934
1935 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
1936
1937 gslX680_resume_wq = create_singlethread_workqueue("gslX680_resume");
1938 if (gslX680_resume_wq == NULL) {
1939 pr_err("create gslX680_resume_wq fail!\n");
1940 return -ENOMEM;
1941 }
1942
1943 glsX680_i2c = client;
1944 ts->client = client;
1945 i2c_set_clientdata(client, ts);
1946 ts->device_id = id->driver_data;
1947
1948 ts->is_suspended = false;
1949 ts->is_runtime_suspend = false;
1950 ts->int_pending = false;
1951 mutex_init(&ts->sus_lock);
1952
1953 rc = gsl_ts_init_ts(client, ts);
1954 if (rc < 0) {
1955 dev_err(&client->dev, "GSLX680 init failed\n");
1956 goto error_mutex_destroy;
1957 }
1958 ts_init = ts;
1959 gslX680_wq = create_singlethread_workqueue("gslX680_init");
1960 if (gslX680_wq == NULL) {
1961 pr_err("create gslX680_wq fail!\n");
1962 return -ENOMEM;
1963 }
1964
1965 #if GSL_MONITOR_TIMER_ENABLE
1966 timer_setup(&monitor_timer, NULL, 0);
1967 monitor_timer.expires = jiffies + msecs_to_jiffies(3000);;
1968 monitor_timer.function = &gsl_monitor_timer_handle;
1969 #endif
1970
1971 queue_work(gslX680_wq, &glsX680_init_work);
1972
1973 device_create_file(&ts->input->dev, &dev_attr_debug_reg);
1974 device_enable_async_suspend(&client->dev);
1975
1976 input_set_drvdata(ts->input, client);
1977 gDevice = ts->input;
1978
1979 ret = sysfs_create_group(&ts->input->dev.kobj, &gsl_attr_group);
1980 if (ret < 0) {
1981 dev_err(&client->dev, "gsl: sysfs_create_group err\n");
1982 goto error_mutex_destroy;
1983 }
1984
1985 pm_runtime_set_active(&client->dev);
1986 pm_runtime_get(&client->dev);
1987 pm_runtime_enable(&client->dev);
1988
1989 #ifdef TPD_PROC_DEBUG
1990 #if 0
1991 gsl_config_proc = create_proc_entry(GSL_CONFIG_PROC_FILE, 0664, NULL);
1992 if (gsl_config_proc == NULL) {
1993 pr_debug("create_proc_entry %s failed\n", GSL_CONFIG_PROC_FILE);
1994 } else {
1995 gsl_config_proc->read_proc = gsl_config_read_proc;
1996 gsl_config_proc->write_proc = gsl_config_write_proc;
1997 }
1998 #else
1999 proc_create(GSL_CONFIG_PROC_FILE, 0664, NULL, &gsl_seq_fops);
2000 #endif
2001 gsl_proc_flag = 0;
2002 #endif
2003
2004 #ifdef GSL_MONITOR
2005 pr_debug("gsl_ts_probe () : queue gsl_monitor_workqueue\n");
2006
2007 INIT_DELAYED_WORK(&gsl_monitor_work, gsl_monitor_worker);
2008 gsl_monitor_workqueue = create_singlethread_workqueue("gsl_monitor_workqueue");
2009 queue_delayed_work(gsl_monitor_workqueue, &gsl_monitor_work, 1000);
2010 #endif
2011 class_register(&ctp_class);
2012 return 0;
2013
2014 error_mutex_destroy:
2015 mutex_destroy(&ts->sus_lock);
2016 input_free_device(ts->input);
2017 kfree(ts);
2018 return rc;
2019 }
2020
gsl_ts_remove(struct i2c_client * client)2021 static int gsl_ts_remove(struct i2c_client *client)
2022 {
2023 struct gsl_ts *ts = i2c_get_clientdata(client);
2024
2025 pr_debug("==gsl_ts_remove=\n");
2026
2027 class_unregister(&ctp_class);
2028 pm_runtime_disable(&client->dev);
2029 pm_runtime_set_suspended(&client->dev);
2030 sysfs_remove_group(&ts->input->dev.kobj, &gsl_attr_group);
2031
2032 device_remove_file(&ts->input->dev, &dev_attr_debug_reg);
2033 #ifdef GSL_MONITOR
2034 cancel_delayed_work_sync(&gsl_monitor_work);
2035 destroy_workqueue(gsl_monitor_workqueue);
2036 #endif
2037
2038 device_init_wakeup(&client->dev, 0);
2039 cancel_work_sync(&ts->work);
2040 cancel_work_sync(&glsX680_init_work);
2041 cancel_work_sync(&glsX680_resume_work);
2042 cancel_work_sync(&glsX680_idle_work);
2043
2044 #ifndef GSL_TIMER
2045 input_free_int(&(config_info.input_type), ts);
2046 #else
2047 del_timer(&ts->gsl_timer);
2048 #endif
2049 #if GSL_MONITOR_TIMER_ENABLE
2050 del_timer(&monitor_timer);
2051 #endif
2052 destroy_workqueue(ts->wq);
2053 destroy_workqueue(gslX680_wq);
2054 destroy_workqueue(gslX680_resume_wq);
2055 input_unregister_device(ts->input);
2056 mutex_destroy(&ts->sus_lock);
2057 kfree(ts->touch_data);
2058 kfree(ts);
2059
2060 return 0;
2061 }
2062 static const struct of_device_id gsl_of_match[] = {
2063 {.compatible = "allwinner,gslX680"},
2064 {},
2065 };
2066 static const struct i2c_device_id gsl_ts_id[] = {
2067 {GSLX680_I2C_NAME, 0},
2068 {}
2069 };
2070 MODULE_DEVICE_TABLE(i2c, gsl_ts_id);
2071
2072 static UNIVERSAL_DEV_PM_OPS(gsl_pm_ops, gsl_ts_suspend,
2073 gsl_ts_resume, NULL);
2074
2075 #define GSL_PM_OPS (&gsl_pm_ops)
2076
2077 static struct i2c_driver gsl_ts_driver = {
2078 .class = I2C_CLASS_HWMON,
2079 .driver = {
2080 .of_match_table = gsl_of_match,
2081 .name = GSLX680_I2C_NAME,
2082 .owner = THIS_MODULE,
2083 .pm = GSL_PM_OPS,
2084 },
2085 .probe = gsl_ts_probe,
2086 .remove = gsl_ts_remove,
2087 .id_table = gsl_ts_id,
2088 .address_list = normal_i2c,
2089 };
ctp_get_system_config(void)2090 static int ctp_get_system_config(void)
2091 {
2092 ctp_print_info(config_info);
2093 fwname = config_info.name;
2094
2095 twi_id = config_info.twi_id;
2096 screen_max_x = config_info.screen_max_x;
2097 screen_max_y = config_info.screen_max_y;
2098 revert_x_flag = config_info.revert_x_flag;
2099 revert_y_flag = config_info.revert_y_flag;
2100 exchange_x_y_flag = config_info.exchange_x_y_flag;
2101 if ((screen_max_x == 0) || (screen_max_y == 0)) {
2102 pr_err("%s:read config error!\n", __func__);
2103 return 0;
2104 }
2105
2106 return 1;
2107 }
gsl_ts_init(void)2108 static int __init gsl_ts_init(void)
2109 {
2110 int ret = -1;
2111
2112 if (startup() != 1)
2113 return -1;
2114 if (!config_info.isI2CClient)
2115 gsl_ts_driver.detect = ctp_detect;
2116 ret = i2c_add_driver(&gsl_ts_driver);
2117 if (ret < 0) {
2118 printk("add gslX680 i2c driver failed\n");
2119 }
2120 return ret;
2121 }
2122
gsl_ts_exit(void)2123 static void __exit gsl_ts_exit(void)
2124 {
2125 pr_debug("==gsl_ts_exit==\n");
2126 i2c_del_driver(&gsl_ts_driver);
2127 input_sensor_free(&(config_info.input_type));
2128 }
2129
2130 module_init(gsl_ts_init);
2131 module_exit(gsl_ts_exit);
2132 MODULE_LICENSE("GPL");
2133 MODULE_DESCRIPTION("GSLX680 touchscreen controller driver");
2134 MODULE_AUTHOR("allwinner");
2135 MODULE_VERSION("1.0.5");
2136 MODULE_ALIAS("platform:gsl_ts");
2137