Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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