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