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) /* drivers/input/touchscreen/gt9xx.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * 2010 - 2013 Goodix Technology.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * the Free Software Foundation; either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * This program is distributed in the hope that it will be a reference 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * to you, when you are integrating the GOODiX's CTP IC into your system, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * Version: 2.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * Authors: andrew@goodix.com, meta@goodix.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * Release Date: 2014/01/14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * Revision record:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *      V1.0:   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *          first Release. By Andrew, 2012/08/31 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *      V1.2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *          modify gtp_reset_guitar,slot report,tracking_id & 0x0F. By Andrew, 2012/10/15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *      V1.4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  *          modify gt9xx_update.c. By Andrew, 2012/12/12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  *      V1.6: 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *          1. new heartbeat/esd_protect mechanism(add external watchdog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  *          2. doze mode, sliding wakeup 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  *          3. 3 more cfg_group(GT9 Sensor_ID: 0~5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  *          3. config length verification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *          4. names & comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  *                  By Meta, 2013/03/11
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  *      V1.8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *          1. pen/stylus identification 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  *          2. read double check & fixed config support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  *          3. new esd & slide wakeup optimization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  *                  By Meta, 2013/06/08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  *      V2.0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  *          1. compatible with GT9XXF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *          2. send config after resume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  *                  By Meta, 2013/08/06
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  *      V2.2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  *          1. gt9xx_config for debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  *          2. gesture wakeup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  *          3. pen separate input device, active-pen button support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  *          4. coordinates & keys optimization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  *                  By Meta, 2014/01/14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include "gt9xx.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include "gt9xx_cfg.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)     #include <linux/input/mt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static u8 m89or101 = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) static u8 bgt911 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) static u8 bgt9110 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) static u8 bgt9111 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static u8 bgt970 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static u8 bgt910 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) static u8 gtp_change_x2y = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static u8 gtp_x_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static u8 gtp_y_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static const char *goodix_ts_name = "goodix-ts";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) static struct workqueue_struct *goodix_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) struct i2c_client * i2c_connect_client = NULL; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)                 = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) #if GTP_HAVE_TOUCH_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)     static const u16 touch_key_array[] = GTP_KEY_TAB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)     #define GTP_MAX_KEY_NUM  (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) #if GTP_DEBUG_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80)     static const int  key_codes[] = {KEY_HOME, KEY_BACK, KEY_MENU, KEY_SEARCH};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)     static const char *key_names[] = {"Key_Home", "Key_Back", "Key_Menu", "Key_Search"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)     
^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) static s8 gtp_i2c_test(struct i2c_client *client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) void gtp_reset_guitar(struct i2c_client *client, s32 ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) s32 gtp_send_cfg(struct i2c_client *client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) void gtp_int_sync(s32 ms, struct goodix_ts_data *ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) static ssize_t gt91xx_config_read_proc(struct file *, char __user *, size_t, loff_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) static ssize_t gt91xx_config_write_proc(struct file *, const char __user *, size_t, loff_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static struct proc_dir_entry *gt91xx_config_proc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static const struct file_operations config_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)     .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)     .read = gt91xx_config_read_proc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)     .write = gt91xx_config_write_proc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) #if GTP_CREATE_WR_NODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) extern s32 init_wr_node(struct i2c_client*);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) extern void uninit_wr_node(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) #if GTP_AUTO_UPDATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) extern u8 gup_init_update_proc(struct goodix_ts_data *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) static struct delayed_work gtp_esd_check_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static struct workqueue_struct * gtp_esd_check_workqueue = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) static void gtp_esd_check_func(struct work_struct *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static s32 gtp_init_ext_watchdog(struct i2c_client *client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) void gtp_esd_switch(struct i2c_client *, s32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) //*********** For GT9XXF Start **********//
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) extern s32 i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *buf, s32 len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) extern s32 i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *buf, s32 len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) extern s32 gup_clk_calibration(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) extern s32 gup_fw_download_proc(void *dir, u8 dwn_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) extern u8 gup_check_fs_mounted(char *path_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) void gtp_recovery_reset(struct i2c_client *client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) static s32 gtp_esd_recovery(struct i2c_client *client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) s32 gtp_fw_startup(struct i2c_client *client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) static s32 gtp_main_clk_proc(struct goodix_ts_data *ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static s32 gtp_bak_ref_proc(struct goodix_ts_data *ts, u8 mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) //********** For GT9XXF End **********//
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) typedef enum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)     DOZE_DISABLED = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)     DOZE_ENABLED = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140)     DOZE_WAKEUP = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) }DOZE_T;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static DOZE_T doze_status = DOZE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static s8 gtp_enter_doze(struct goodix_ts_data *ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) u8 grp_cfg_version = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150)     Read data from the i2c slave device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)     client:     i2c device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153)     buf[0~1]:   read start address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154)     buf[2~len-1]:   read data buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155)     len:    GTP_ADDR_LENGTH + read bytes count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157)     numbers of i2c_msgs to transfer: 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158)       2: succeed, otherwise: failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)     struct i2c_msg msgs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)     s32 ret=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)     s32 retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)     msgs[0].flags = !I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)     msgs[0].addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)     msgs[0].len   = GTP_ADDR_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)     msgs[0].buf   = &buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) #ifdef CONFIG_I2C_ROCKCHIP_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)     msgs[0].scl_rate=200 * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)     //msgs[0].scl_rate = 300 * 1000;    // for Rockchip, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176)     msgs[1].flags = I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177)     msgs[1].addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178)     msgs[1].len   = len - GTP_ADDR_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179)     msgs[1].buf   = &buf[GTP_ADDR_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) #ifdef CONFIG_I2C_ROCKCHIP_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181)     msgs[1].scl_rate=200 * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182)     //msgs[1].scl_rate = 300 * 1000;    // for Rockchip, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185)     while(retries < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187)         ret = i2c_transfer(client->adapter, msgs, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)         if(ret == 2)break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)         retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191)     if((retries >= 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193)     #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)         struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197)     #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198)         // reset chip would quit doze mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199)         if (DOZE_ENABLED == doze_status)
^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)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204)         GTP_ERROR("I2C Read: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205)     #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206)         if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207)         { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208)             gtp_recovery_reset(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)             gtp_reset_guitar(client, 10);  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223)     Write data to the i2c slave device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225)     client:     i2c device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226)     buf[0~1]:   write start address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227)     buf[2~len-1]:   data buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228)     len:    GTP_ADDR_LENGTH + write bytes count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230)     numbers of i2c_msgs to transfer: 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231)         1: succeed, otherwise: failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) s32 gtp_i2c_write(struct i2c_client *client,u8 *buf,s32 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235)     struct i2c_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237)     s32 retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241)     msg.flags = !I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242)     msg.addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243)     msg.len   = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244)     msg.buf   = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) #ifdef CONFIG_I2C_ROCKCHIP_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246)     msg.scl_rate=200 * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247)     //msg.scl_rate = 300 * 1000;    // for Rockchip, etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249)     while(retries < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251)         ret = i2c_transfer(client->adapter, &msg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252)         if (ret == 1)break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)         retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)     if((retries >= 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)     #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)         struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)     #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)         if (DOZE_ENABLED == doze_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264)             return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267)         GTP_ERROR("I2C Write: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268)     #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269)         if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270)         { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271)             gtp_recovery_reset(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276)             gtp_reset_guitar(client, 10);  
^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)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^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) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285)     i2c read twice, compare the results
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)     client:  i2c device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)     addr:    operate address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)     rxbuf:   read data to store, if compare successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)     len:     bytes to read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)     FAIL:    read failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)     SUCCESS: read successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)     u8 buf[16] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)     u8 confirm_buf[16] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)     u8 retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301)     while (retry++ < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)         memset(buf, 0xAA, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304)         buf[0] = (u8)(addr >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305)         buf[1] = (u8)(addr & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306)         gtp_i2c_read(client, buf, len + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308)         memset(confirm_buf, 0xAB, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309)         confirm_buf[0] = (u8)(addr >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310)         confirm_buf[1] = (u8)(addr & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311)         gtp_i2c_read(client, confirm_buf, len + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313)         if (!memcmp(buf, confirm_buf, len+2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)             memcpy(rxbuf, confirm_buf+2, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316)             return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318)     }    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319)     GTP_ERROR("I2C read 0x%04X, %d bytes, double check failed!", addr, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320)     return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) }
^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) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325)     Send config.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327)     client: i2c device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329)     result of i2c write operation. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330)         1: succeed, otherwise: failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) s32 gtp_send_cfg(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335)     s32 ret = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) #if GTP_DRIVER_SEND_CFG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338)     s32 retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339)     struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341)     if (ts->fixed_cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343)         GTP_INFO("Ic fixed config, no config sent!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346)     else if (ts->pnl_init_error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)         GTP_INFO("Error occured in init_panel, no config sent");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352)     GTP_INFO("Driver send config.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353)     for (retry = 0; retry < 5; retry++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355)         ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356)         if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362)     return ret;
^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) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366)     Disable irq function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)     ts: goodix i2c_client private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) void gtp_irq_disable(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374)     unsigned long irqflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378)     spin_lock_irqsave(&ts->irq_lock, irqflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379)     if (!ts->irq_is_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381)         ts->irq_is_disable = 1; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382)         disable_irq_nosync(ts->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384)     spin_unlock_irqrestore(&ts->irq_lock, irqflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389)     Enable irq function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391)     ts: goodix i2c_client private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) void gtp_irq_enable(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397)     unsigned long irqflags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)     spin_lock_irqsave(&ts->irq_lock, irqflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)     if (ts->irq_is_disable) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)         enable_irq(ts->client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)         ts->irq_is_disable = 0; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)     spin_unlock_irqrestore(&ts->irq_lock, irqflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)     Report touch point event 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)     ts: goodix i2c_client private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)     id: trackId
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)     x:  input x coordinate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)     y:  input y coordinate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)     w:  input pressure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) static void gtp_touch_down(struct goodix_ts_data* ts,s32 id,s32 x,s32 y,s32 w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	if (gtp_change_x2y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		GTP_SWAP(x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	if (!bgt911 && !bgt970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		if (gtp_x_reverse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 			x = ts->abs_x_max - x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		if (gtp_y_reverse)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 			y = ts->abs_y_max - y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437)     input_mt_slot(ts->input_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438)     input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439)     input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440)     input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441)     input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442)     input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444)     input_report_key(ts->input_dev, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445)     input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446)     input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447)     input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448)     input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449)     input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450)     input_mt_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453)     GTP_DEBUG("ID:%d, X:%d, Y:%d, W:%d", id, x, y, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458)     Report touch release event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460)     ts: goodix i2c_client private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) static void gtp_touch_up(struct goodix_ts_data* ts, s32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)     input_mt_slot(ts->input_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468)     input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469)     GTP_DEBUG("Touch id[%2d] release!", id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471)     input_report_key(ts->input_dev, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) static void gtp_pen_init(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)     GTP_INFO("Request input device for pen/stylus.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)     ts->pen_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)     if (ts->pen_dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486)         GTP_ERROR("Failed to allocate input device for pen/stylus.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490)     ts->pen_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493)     input_mt_init_slots(ts->pen_dev, 16, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495)     ts->pen_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498)     set_bit(BTN_TOOL_PEN, ts->pen_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499)     set_bit(INPUT_PROP_DIRECT, ts->pen_dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500)     //set_bit(INPUT_PROP_POINTER, ts->pen_dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) #if GTP_PEN_HAVE_BUTTON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503)     input_set_capability(ts->pen_dev, EV_KEY, BTN_STYLUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504)     input_set_capability(ts->pen_dev, EV_KEY, BTN_STYLUS2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)     input_set_abs_params(ts->pen_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508)     input_set_abs_params(ts->pen_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509)     input_set_abs_params(ts->pen_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)     input_set_abs_params(ts->pen_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511)     input_set_abs_params(ts->pen_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513)     ts->pen_dev->name = "goodix-pen";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514)     ts->pen_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516)     ret = input_register_device(ts->pen_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517)     if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)         GTP_ERROR("Register %s input device failed", ts->pen_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)         return;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) static void gtp_pen_down(s32 x, s32 y, s32 w, s32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526)     struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	if (gtp_change_x2y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		GTP_SWAP(x, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)     input_report_key(ts->pen_dev, BTN_TOOL_PEN, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534)     input_mt_slot(ts->pen_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535)     input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536)     input_report_abs(ts->pen_dev, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537)     input_report_abs(ts->pen_dev, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538)     input_report_abs(ts->pen_dev, ABS_MT_PRESSURE, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539)     input_report_abs(ts->pen_dev, ABS_MT_TOUCH_MAJOR, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)     input_report_key(ts->pen_dev, BTN_TOUCH, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)     input_report_abs(ts->pen_dev, ABS_MT_POSITION_X, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543)     input_report_abs(ts->pen_dev, ABS_MT_POSITION_Y, y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544)     input_report_abs(ts->pen_dev, ABS_MT_PRESSURE, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545)     input_report_abs(ts->pen_dev, ABS_MT_TOUCH_MAJOR, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546)     input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547)     input_mt_sync(ts->pen_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549)     GTP_DEBUG("(%d)(%d, %d)[%d]", id, x, y, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static void gtp_pen_up(s32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554)     struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556)     input_report_key(ts->pen_dev, BTN_TOOL_PEN, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559)     input_mt_slot(ts->pen_dev, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)     input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)     input_report_key(ts->pen_dev, BTN_TOUCH, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571)     Goodix touchscreen work function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573)     work: work struct of goodix_workqueue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) static void goodix_ts_work_func(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579)     u8  end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580)     u8  point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581)     u8  touch_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582)     u8  finger = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583)     static u16 pre_touch = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)     static u8 pre_key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586)     u8 pen_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)     static u8 pre_pen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589)     u8  key_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590)     u8* coor_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591)     s32 input_x = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592)     s32 input_y = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593)     s32 input_w = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594)     s32 id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595)     s32 i  = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597)     struct goodix_ts_data *ts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600)     u8 rqst_buf[3] = {0x80, 0x43};  // for GT9XXF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604)     u8 doze_buf[3] = {0x81, 0x4B};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608)     ts = container_of(work, struct goodix_ts_data, work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609)     if (ts->enter_update)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611)         goto release_wakeup_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)     if (DOZE_ENABLED == doze_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615)     {               
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616)         ret = gtp_i2c_read(i2c_connect_client, doze_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617)         GTP_DEBUG("0x814B = 0x%02X", doze_buf[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618)         if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619)         {     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620)             if ((doze_buf[2] == 'a') || (doze_buf[2] == 'b') || (doze_buf[2] == 'c') ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621)                 (doze_buf[2] == 'd') || (doze_buf[2] == 'e') || (doze_buf[2] == 'g') || 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)                 (doze_buf[2] == 'h') || (doze_buf[2] == 'm') || (doze_buf[2] == 'o') ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623)                 (doze_buf[2] == 'q') || (doze_buf[2] == 's') || (doze_buf[2] == 'v') || 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)                 (doze_buf[2] == 'w') || (doze_buf[2] == 'y') || (doze_buf[2] == 'z') ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)                 (doze_buf[2] == 0x5E) /* ^ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626)                 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628)                 if (doze_buf[2] != 0x5E)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629)                 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630)                     GTP_INFO("Wakeup by gesture(%c), light up the screen!", doze_buf[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632)                 else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633)                 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634)                     GTP_INFO("Wakeup by gesture(^), light up the screen!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636)                 doze_status = DOZE_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637)                 input_report_key(ts->input_dev, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638)                 input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639)                 input_report_key(ts->input_dev, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640)                 input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641)                 // clear 0x814B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642)                 doze_buf[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643)                 gtp_i2c_write(i2c_connect_client, doze_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 			else if ( (doze_buf[2] == 0xAA) || (doze_buf[2] == 0xBB) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 				(doze_buf[2] == 0xAB) || (doze_buf[2] == 0xBA) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648)                 char *direction[4] = {"Right", "Down", "Up", "Left"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649)                 u8 type = ((doze_buf[2] & 0x0F) - 0x0A) + (((doze_buf[2] >> 4) & 0x0F) - 0x0A) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651)                 GTP_INFO("%s slide to light up the screen!", direction[type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652)                 doze_status = DOZE_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653)                 input_report_key(ts->input_dev, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654)                 input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655)                 input_report_key(ts->input_dev, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656)                 input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657)                 // clear 0x814B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658)                 doze_buf[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)                 gtp_i2c_write(i2c_connect_client, doze_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661)             else if (0xCC == doze_buf[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663)                 GTP_INFO("Double click to light up the screen!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664)                 doze_status = DOZE_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665)                 input_report_key(ts->input_dev, KEY_POWER, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666)                 input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667)                 input_report_key(ts->input_dev, KEY_POWER, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668)                 input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669)                 // clear 0x814B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670)                 doze_buf[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671)                 gtp_i2c_write(i2c_connect_client, doze_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675)                 // clear 0x814B
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676)                 doze_buf[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677)                 gtp_i2c_write(i2c_connect_client, doze_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678)                 gtp_enter_doze(ts);
^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 (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683)             gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685)         goto release_wakeup_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689)     ret = gtp_i2c_read(ts->client, point_data, 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692)         GTP_ERROR("I2C transfer error. errno:%d\n ", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693)         if (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695)             gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697)         goto release_wakeup_lock;
^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)     finger = point_data[GTP_ADDR_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703)     // GT9XXF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704)     if ((finger == 0x00) && (CHIP_TYPE_GT9F == ts->chip_type))     // request arrived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706)         ret = gtp_i2c_read(ts->client, rqst_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)         if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)            GTP_ERROR("Read request status error!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)            goto exit_work_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711)         } 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713)         switch (rqst_buf[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715)         case GTP_RQST_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716)             GTP_INFO("Request for config.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717)             ret = gtp_send_cfg(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718)             if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720)                 GTP_ERROR("Request for config unresponded!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724)                 rqst_buf[2] = GTP_RQST_RESPONDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725)                 gtp_i2c_write(ts->client, rqst_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726)                 GTP_INFO("Request for config responded!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730)         case GTP_RQST_BAK_REF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732)             GTP_INFO("Request for backup reference.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733)             ts->rqst_processing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734)             ret = gtp_bak_ref_proc(ts, GTP_BAK_REF_SEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735)             if (SUCCESS == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737)                 rqst_buf[2] = GTP_RQST_RESPONDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738)                 gtp_i2c_write(ts->client, rqst_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739)                 ts->rqst_processing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)                 GTP_INFO("Request for backup reference responded!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744)                 GTP_ERROR("Requeset for backup reference unresponed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749)         case GTP_RQST_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750)             GTP_INFO("Request for reset.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751)             gtp_recovery_reset(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754)         case GTP_RQST_MAIN_CLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755)             GTP_INFO("Request for main clock.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756)             ts->rqst_processing = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757)             ret = gtp_main_clk_proc(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758)             if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760)                 GTP_ERROR("Request for main clock unresponded!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)                 GTP_INFO("Request for main clock responded!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765)                 rqst_buf[2] = GTP_RQST_RESPONDED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)                 gtp_i2c_write(ts->client, rqst_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)                 ts->rqst_processing = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768)                 ts->clk_chk_fs_times = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772)         default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773)             GTP_INFO("Undefined request: 0x%02X", rqst_buf[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774)             rqst_buf[2] = GTP_RQST_RESPONDED;  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775)             gtp_i2c_write(ts->client, rqst_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780)     if (finger == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782)         if (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784)             gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786)         goto release_wakeup_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789)     if((finger & 0x80) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791)         goto exit_work_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794)     touch_num = finger & 0x0f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795)     if (touch_num > GTP_MAX_TOUCH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797)         goto exit_work_func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800)     if (touch_num > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802)         u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804)         ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1)); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805)         memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) #if (GTP_HAVE_TOUCH_KEY || GTP_PEN_HAVE_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809)     key_value = point_data[3 + 8 * touch_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811)     if(key_value || pre_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813)     #if GTP_PEN_HAVE_BUTTON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814)         if (key_value == 0x40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816)             GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Down.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817)             input_report_key(ts->pen_dev, BTN_STYLUS, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818)             input_report_key(ts->pen_dev, BTN_STYLUS2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819)             pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821)         else if (key_value == 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823)             GTP_DEBUG("BTN_STYLUS Down, BTN_STYLUS2 Up.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)             input_report_key(ts->pen_dev, BTN_STYLUS, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)             input_report_key(ts->pen_dev, BTN_STYLUS2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)             pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828)         else if (key_value == 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830)             GTP_DEBUG("BTN_STYLUS Up, BTN_STYLUS2 Down.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831)             input_report_key(ts->pen_dev, BTN_STYLUS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832)             input_report_key(ts->pen_dev, BTN_STYLUS2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833)             pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837)             GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Up.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838)             input_report_key(ts->pen_dev, BTN_STYLUS, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839)             input_report_key(ts->pen_dev, BTN_STYLUS2, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840)             if ( (pre_key == 0x40) || (pre_key == 0x20) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841)                  (pre_key == 0x10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842)                )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844)                 pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847)         if (pen_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849)             touch_num = 0;      // shield pen point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850)             //pre_touch = 0;    // clear last pen status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854)     #if GTP_HAVE_TOUCH_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855)         if (!pre_touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857)             for (i = 0; i < GTP_MAX_KEY_NUM; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859)             #if GTP_DEBUG_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860)                 for (ret = 0; ret < 4; ++ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861)                 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862)                     if (key_codes[ret] == touch_key_array[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)                     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)                         GTP_DEBUG("Key: %s %s", key_names[ret], (key_value & (0x01 << i)) ? "Down" : "Up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865)                         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866)                     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)             #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869)                 input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01<<i));   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)             touch_num = 0;  // shield fingers
^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)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876)     pre_key = key_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878)     GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883)     if (pre_pen && (touch_num == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885)         GTP_DEBUG("Pen touch UP(Slot)!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886)         gtp_pen_up(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887)         pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888)         pre_pen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891)     if (pre_touch || touch_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893)         s32 pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894)         u16 touch_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895)         u8 report_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896)         coor_data = &point_data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898)         if(touch_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)             id = coor_data[pos] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)         #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)             id = coor_data[pos];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904)             if ((id & 0x80))  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906)                 GTP_DEBUG("Pen touch DOWN(Slot)!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907)                 input_x  = coor_data[pos + 1] | (coor_data[pos + 2] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)                 input_y  = coor_data[pos + 3] | (coor_data[pos + 4] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909)                 input_w  = coor_data[pos + 5] | (coor_data[pos + 6] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911)                 gtp_pen_down(input_x, input_y, input_w, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912)                 pre_pen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)                 pre_touch = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914)                 pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915)             }    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916)         #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918)             touch_index |= (0x01<<id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921)         GTP_DEBUG("id = %d,touch_index = 0x%x, pre_touch = 0x%x\n",id, touch_index,pre_touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922)         for (i = 0; i < GTP_MAX_TOUCH; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924)         #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925)             if (pre_pen == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929)         #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931)             if ((touch_index & (0x01<<i)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933)                 input_x  = coor_data[pos + 1] | (coor_data[pos + 2] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934)                 input_y  = coor_data[pos + 3] | (coor_data[pos + 4] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935)                 input_w  = coor_data[pos + 5] | (coor_data[pos + 6] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937)                 gtp_touch_down(ts, id, input_x, input_y, input_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938)                 pre_touch |= 0x01 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940)                 report_num++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941)                 if (report_num < touch_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942)                 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943)                     pos += 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944)                     id = coor_data[pos] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945)                     touch_index |= (0x01<<id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950)                 gtp_touch_up(ts, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951)                 pre_touch &= ~(0x01 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) #else   //end if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957)     if (touch_num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959)         for (i = 0; i < touch_num; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961)             coor_data = &point_data[i * 8 + 3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963)             id = coor_data[0] & 0x0F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964)             input_x  = coor_data[1] | (coor_data[2] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965)             input_y  = coor_data[3] | (coor_data[4] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966)             input_w  = coor_data[5] | (coor_data[6] << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968)         #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969)             id = coor_data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970)             if (id & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972)                 GTP_DEBUG("Pen touch DOWN!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973)                 gtp_pen_down(input_x, input_y, input_w, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974)                 pre_pen = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975)                 pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979)         #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981)                 gtp_touch_down(ts, id, input_x, input_y, input_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985)     else if (pre_touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987)     #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988)         if (pre_pen == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990)             GTP_DEBUG("Pen touch UP!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991)             gtp_pen_up(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992)             pre_pen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993)             pen_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998)             GTP_DEBUG("Touch Release!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999)             gtp_touch_up(ts, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)     pre_touch = touch_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)     if (pen_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)         pen_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)         input_sync(ts->pen_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)         input_sync(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) exit_work_func:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)     if(!ts->gtp_rawdiff_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021)         ret = gtp_i2c_write(ts->client, end_cmd, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022)         if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)             GTP_INFO("I2C write end_cmd error!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)     if (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)         gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) release_wakeup_lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)     if (device_can_wakeup(&ts->client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)         pm_relax(&ts->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)     Timer interrupt service routine for polling mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041)     timer: timer struct pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)     Timer work mode. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)         HRTIMER_NORESTART: no restart mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048)     struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)     queue_work(goodix_wq, &ts->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053)     hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME+6)*1000000), HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)     return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)     External interrupt service routine for interrupt mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)     irq:  interrupt number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)     dev_id: private data pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064)     Handle Result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)         IRQ_HANDLED: interrupt handled successfully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)     struct goodix_ts_data *ts = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)     gtp_irq_disable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)     if (device_can_wakeup(&ts->client->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)         pm_stay_awake(&ts->client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)     queue_work(goodix_wq, &ts->work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)     return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)     Synchronization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086)     ms: synchronization time in millisecond.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) void gtp_int_sync(s32 ms, struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)     GTP_GPIO_OUTPUT(ts->irq_pin, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)     msleep(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)     //GTP_GPIO_AS_INT(GTP_INT_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)     gpio_direction_input(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)     //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)     //s3c_gpio_cfgpin(pin, GTP_INT_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) }
^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) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)     Reset chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)     ms: reset time in millisecond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) void gtp_reset_guitar(struct i2c_client *client, s32 ms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111)     struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)     GTP_INFO("Guitar reset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)     GTP_GPIO_OUTPUT(ts->rst_pin, 0);   // begin select I2C slave addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)     msleep(ms);                         // T2: > 10ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)     // HIGH: 0x28/0x29, LOW: 0xBA/0xBB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)     GTP_GPIO_OUTPUT(ts->irq_pin, client->addr == 0x14);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)     msleep(2);                          // T3: > 100us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)     GTP_GPIO_OUTPUT(ts->rst_pin, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)     msleep(6);                          // T4: > 5ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)     //GTP_GPIO_AS_INPUT(GTP_RST_PORT);    // end select I2C slave addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)     gpio_direction_input(ts->rst_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127)     //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)     }
^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)     gtp_int_sync(50, ts);  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)     gtp_init_ext_watchdog(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145)     Enter doze mode for sliding wakeup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)     ts: goodix tp private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)     1: succeed, otherwise failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) static s8 gtp_enter_doze(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)     s8 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)     s8 retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)     u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 8};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)     GTP_DEBUG("Entering gesture mode.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)     while(retry++ < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)         i2c_control_buf[0] = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)         i2c_control_buf[1] = 0x46;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)         ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165)         if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)             GTP_DEBUG("failed to set doze flag into 0x8046, %d", retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)         i2c_control_buf[0] = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)         i2c_control_buf[1] = 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)         ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)         if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)             doze_status = DOZE_ENABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)             GTP_INFO("Gesture mode enabled.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)             return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179)         msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)     GTP_ERROR("GTP send gesture cmd failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) #else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)     Enter sleep mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189)     ts: private data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)     Executive outcomes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)        1: succeed, otherwise failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) static s8 gtp_enter_sleep(struct goodix_ts_data * ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)     s8 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197)     s8 retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)     u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)     u8 status_buf[3] = {0x80, 0x44};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)         // GT9XXF: host interact with ic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)         ret = gtp_i2c_read(ts->client, status_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)         if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)             GTP_ERROR("failed to get backup-reference status");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)         if (status_buf[2] & 0x80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)             ret = gtp_bak_ref_proc(ts, GTP_BAK_REF_STORE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)             if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)                 GTP_ERROR("failed to store bak_ref");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)     GTP_GPIO_OUTPUT(ts->irq_pin, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)     msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)     while(retry++ < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)         ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)         if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)             GTP_INFO("GTP enter sleep!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236)             return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)         msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240)     GTP_ERROR("GTP send sleep cmd failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) #endif 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246)     Wakeup from sleep.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)     ts: private data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)     Executive outcomes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)         >0: succeed, otherwise: failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) static s8 gtp_wakeup_sleep(struct goodix_ts_data * ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255)     u8 retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)     s8 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)         u8 opr_buf[3] = {0x41, 0x80};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)         GTP_GPIO_OUTPUT(ts->irq_pin, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)         msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268)         for (retry = 0; retry < 10; ++retry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)             // hold ss51 & dsp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)             opr_buf[2] = 0x0C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)             ret = gtp_i2c_write(ts->client, opr_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)             if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)                 GTP_ERROR("failed to hold ss51 & dsp!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)                 continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)             opr_buf[2] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)             ret = gtp_i2c_read(ts->client, opr_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)             if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)                 GTP_ERROR("failed to get ss51 & dsp status!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)                 continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)             if (0x0C != opr_buf[2])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)                 GTP_DEBUG("ss51 & dsp not been hold, %d", retry+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288)                 continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)             GTP_DEBUG("ss51 & dsp confirmed hold");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)             ret = gtp_fw_startup(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)             if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)                 GTP_ERROR("failed to startup GT9XXF, process recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)                 gtp_esd_recovery(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)             break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)         if (retry >= 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302)             GTP_ERROR("failed to wakeup, processing esd recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303)             gtp_esd_recovery(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307)             GTP_INFO("GT9XXF gtp wakeup success");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309)         return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) #if GTP_POWER_CTRL_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314)     while(retry++ < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)         gtp_reset_guitar(ts->client, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)         GTP_INFO("GTP wakeup sleep.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)         return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)     while(retry++ < 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)     #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)         if (DOZE_WAKEUP != doze_status)  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)             GTP_INFO("Powerkey wakeup.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)         else   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)             GTP_INFO("Gesture wakeup.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)         doze_status = DOZE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334)         gtp_irq_disable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335)         gtp_reset_guitar(ts->client, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)         gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)     #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)         GTP_GPIO_OUTPUT(ts->irq_pin, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340)         msleep(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)         ret = gtp_i2c_test(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344)         if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)             GTP_INFO("GTP wakeup sleep.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348)         #if (!GTP_GESTURE_WAKEUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)                 gtp_int_sync(25, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)             #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)                 gtp_init_ext_watchdog(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)             #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355)         #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)             return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)         gtp_reset_guitar(ts->client, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)     GTP_ERROR("GTP wakeup sleep failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) #if GTP_DRIVER_SEND_CFG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) static s32 gtp_get_info(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)     u8 opr_buf[6] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)     //ts->abs_x_max = GTP_MAX_WIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373)     //ts->abs_y_max = GTP_MAX_HEIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)     ts->int_trigger_type = GTP_INT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377)     opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+1) >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)     opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+1) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380)     ret = gtp_i2c_read(ts->client, opr_buf, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)     ts->abs_x_max = (opr_buf[3] << 8) + opr_buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)     ts->abs_y_max = (opr_buf[5] << 8) + opr_buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)     opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+6) >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)     opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+6) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)     ret = gtp_i2c_read(ts->client, opr_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)     ts->int_trigger_type = opr_buf[2] & 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)     GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)             ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)     return SUCCESS;    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) #endif 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)     Initialize gtp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)     ts: goodix private data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)     Executive outcomes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)         0: succeed, otherwise: failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) static s32 gtp_init_panel(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) #if GTP_DRIVER_SEND_CFG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)     s32 i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420)     u8 check_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421)     u8 opr_buf[16] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422)     u8 sensor_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)     u8 cfg_info_group2[] = CTP_CFG_GROUP2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)     u8 cfg_info_group3[] = CTP_CFG_GROUP3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)     u8 cfg_info_group4[] = CTP_CFG_GROUP4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427)     u8 cfg_info_group5[] = CTP_CFG_GROUP5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)     u8 cfg_info_group6[] = CTP_CFG_GROUP6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429)     u8 *send_cfg_buf[] = {gtp_dat_10_1, cfg_info_group2, cfg_info_group3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)                             cfg_info_group4, cfg_info_group5, cfg_info_group6};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)     u8 cfg_info_len[] = { CFG_GROUP_LEN(gtp_dat_10_1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432)                               CFG_GROUP_LEN(cfg_info_group2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)                               CFG_GROUP_LEN(cfg_info_group3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434)                               CFG_GROUP_LEN(cfg_info_group4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435)                               CFG_GROUP_LEN(cfg_info_group5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)                               CFG_GROUP_LEN(cfg_info_group6)};;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)     GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)     if(m89or101){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	    if (ts->cfg_file_num) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		    send_cfg_buf[0] = gtp_dat_8_9_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		    cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_8_9_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	    } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		    send_cfg_buf[0] = gtp_dat_8_9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		    cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_8_9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)     if (bgt911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451)     	send_cfg_buf[0] = gtp_dat_gt11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 		cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_gt11);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455)     if (bgt9110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	    send_cfg_buf[0] = gtp_dat_gt9110;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	    cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_gt9110);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	if (bgt9111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 		send_cfg_buf[0] = gtp_dat_gt9111;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_gt9111);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	if (bgt970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 		send_cfg_buf[0] = gtp_dat_9_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		cfg_info_len[0] = CFG_GROUP_LEN(gtp_dat_9_7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	if (bgt910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 		send_cfg_buf[0] = gtp_dat_7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 		cfg_info_len[0] = CFG_GROUP_LEN(gtp_dat_7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)     GTP_DEBUG("Config Groups\' Lengths: %d, %d, %d, %d, %d, %d", 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)         cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], cfg_info_len[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)         cfg_info_len[4], cfg_info_len[5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484)         ts->fw_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489)         ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490)         if (SUCCESS == ret) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)             if (opr_buf[0] != 0xBE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494)                 ts->fw_error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495)                 GTP_ERROR("Firmware error, no config sent!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)                 return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)     if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502)         (!cfg_info_len[3]) && (!cfg_info_len[4]) && 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)         (!cfg_info_len[5]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505)         sensor_id = 0; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)     #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)         msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512)         ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)         if (SUCCESS == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)             if (sensor_id >= 0x06)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517)                 GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518)                 ts->pnl_init_error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)                 return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524)             GTP_ERROR("Failed to get sensor_id, No config sent!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525)             ts->pnl_init_error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)             return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528)         GTP_INFO("Sensor_ID: %d", sensor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530)     ts->gtp_cfg_len = cfg_info_len[sensor_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)     GTP_INFO("CTP_CONFIG_GROUP%d used, config length: %d", sensor_id + 1, ts->gtp_cfg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533)     if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)         GTP_ERROR("Config Group%d is INVALID CONFIG GROUP(Len: %d)! NO Config Sent! You need to check you header file CFG_GROUP section!", sensor_id+1, ts->gtp_cfg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)         ts->pnl_init_error = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537)         return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)         ts->fixed_cfg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)         ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)         if (ret == SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552)             GTP_DEBUG("CFG_GROUP%d Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X", sensor_id+1, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553)                         send_cfg_buf[sensor_id][0], send_cfg_buf[sensor_id][0], opr_buf[0], opr_buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555)             if (opr_buf[0] < 90)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)                 GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)                 grp_cfg_version = send_cfg_buf[sensor_id][0];       // backup group config version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559)                 send_cfg_buf[sensor_id][0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)                 ts->fixed_cfg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562)             else        // treated as fixed config, not send config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)                 GTP_INFO("Ic fixed config with config version(%d, 0x%02X)", opr_buf[0], opr_buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)                 ts->fixed_cfg = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566)                 gtp_get_info(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567)                 return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)             GTP_ERROR("Failed to get ic config version!No config sent!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573)             return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577)     memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)     memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) #if GTP_CUSTOM_CFG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581)     config[RESOLUTION_LOC]     = (u8)GTP_MAX_WIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)     config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)     config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584)     config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586)     if (GTP_INT_TRIGGER == 0)  //RISING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588)         config[TRIGGER_LOC] &= 0xfe; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)     else if (GTP_INT_TRIGGER == 1)  //FALLING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592)         config[TRIGGER_LOC] |= 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) #endif  // GTP_CUSTOM_CFG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)     check_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)     for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599)         check_sum += config[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601)     config[ts->gtp_cfg_len] = (~check_sum) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) #else // driver not send config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)     ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)     ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)         GTP_ERROR("Read Config Failed, Using Default Resolution & INT Trigger!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)         //ts->abs_x_max = GTP_MAX_WIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611)         //ts->abs_y_max = GTP_MAX_HEIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)         ts->int_trigger_type = GTP_INT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) #endif // GTP_DRIVER_SEND_CFG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)     if ((ts->abs_x_max == 0) && (ts->abs_y_max == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619)         ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620)         ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)         ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)         GTP_INFO("  <%s>_%d    <%d, %d>\n", __func__, __LINE__, ts->abs_x_max, ts->abs_y_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624)     GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)         u8 sensor_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)         u8 driver_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630)         u8 have_key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)         have_key = (config[GTP_REG_HAVE_KEY - GTP_REG_CONFIG_DATA + 2] & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634)         if (1 == ts->is_950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636)             driver_num = config[GTP_REG_MATRIX_DRVNUM - GTP_REG_CONFIG_DATA + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637)             sensor_num = config[GTP_REG_MATRIX_SENNUM - GTP_REG_CONFIG_DATA + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)             if (have_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)                 driver_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)             ts->bak_ref_len = (driver_num * (sensor_num - 1) + 2) * 2 * 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)             driver_num = (config[CFG_LOC_DRVA_NUM] & 0x1F) + (config[CFG_LOC_DRVB_NUM]&0x1F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)             if (have_key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)                 driver_num--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)             sensor_num = (config[CFG_LOC_SENS_NUM] & 0x0F) + ((config[CFG_LOC_SENS_NUM] >> 4) & 0x0F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)             ts->bak_ref_len = (driver_num * (sensor_num - 2) + 2) * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655)         GTP_INFO("Drv * Sen: %d * %d(key: %d), X_MAX: %d, Y_MAX: %d, TRIGGER: 0x%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)            driver_num, sensor_num, have_key, ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662)     #if GTP_DRIVER_SEND_CFG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663)         GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)         ret = gtp_send_cfg(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)         if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667)             GTP_ERROR("Send config error.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669)         // set config version to CTP_CFG_GROUP, for resume to send config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)         config[GTP_ADDR_LENGTH] = grp_cfg_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)         check_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672)         for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674)             check_sum += config[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)         config[ts->gtp_cfg_len] = (~check_sum) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)         GTP_INFO("X_MAX: %d, Y_MAX: %d, TRIGGER: 0x%02x", ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)     msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) static ssize_t gt91xx_config_read_proc(struct file *file, char __user *page, size_t size, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)     char *ptr = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	u8 temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0x80, 0x47};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)     int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692)     if (*ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696)     ptr += sprintf(ptr, "==== GT9XX config init value====\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698)     for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)         ptr += sprintf(ptr, "0x%02X ", config[i + 2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)         if (i % 8 == 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703)             ptr += sprintf(ptr, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706)     ptr += sprintf(ptr, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)     ptr += sprintf(ptr, "==== GT9XX config real value====\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)     gtp_i2c_read(i2c_connect_client, temp_data, GTP_CONFIG_MAX_LENGTH + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710)     for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712)         ptr += sprintf(ptr, "0x%02X ", temp_data[i+2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714)         if (i % 8 == 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)             ptr += sprintf(ptr, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)     *ppos += ptr - page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718)     return (ptr - page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) static ssize_t gt91xx_config_write_proc(struct file *filp, const char __user *buffer, size_t count, loff_t *off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725)     if (count > GTP_CONFIG_MAX_LENGTH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727)         GTP_ERROR("size not match [%d:%zu]\n", GTP_CONFIG_MAX_LENGTH, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728)         return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)     if (copy_from_user(&config[2], buffer, count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)         GTP_ERROR("copy from user fail\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734)         return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)     ret = gtp_send_cfg(i2c_connect_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)         GTP_ERROR("send config failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744)     return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)     Read chip version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750)     client:  i2c device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)     version: buffer to keep ic firmware version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753)     read operation return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754)         2: succeed, otherwise: failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) s32 gtp_read_version(struct i2c_client *client, u16* version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759)     u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)     ret = gtp_i2c_read(client, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)         GTP_ERROR("GTP read version failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767)         return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770)     if (version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772)         *version = (buf[7] << 8) | buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)     if (buf[5] == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)         GTP_INFO("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780)         GTP_INFO("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787)     I2c test Function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)     client:i2c client.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)     Executive outcomes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)         2: succeed, otherwise failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) static s8 gtp_i2c_test(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796)     u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797)     u8 retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798)     s8 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802)     while(retry++ < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804)         ret = gtp_i2c_read(client, test, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805)         if (ret > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)             return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809)         GTP_ERROR("GTP i2c test failed time %d.",retry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)         msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817)     Request gpio(INT & RST) ports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819)     ts: private data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)     Executive outcomes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822)         >= 0: succeed, < 0: failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) static s8 gtp_request_io_port(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)     ret = GTP_GPIO_REQUEST(ts->tp_select_pin, "GTP_tp_select_PORT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)     if (ret < 0) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833)         GTP_ERROR("1Failed to request GPIO:%d, ERRNO:%d",(s32)ts->tp_select_pin, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)     	gpio_direction_input(ts->tp_select_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)     ret = GTP_GPIO_REQUEST(ts->rst_pin, "GTP_RST_PORT");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842)     if (ret < 0) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)         GTP_ERROR("2Failed to request GPIO:%d, ERRNO:%d",(s32)ts->rst_pin, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		GTP_GPIO_FREE(ts->rst_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)     ret = GTP_GPIO_REQUEST(ts->irq_pin, "GTP_INT_IRQ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850)     if (ret < 0) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)         GTP_ERROR("3Failed to request GPIO:%d, ERRNO:%d", (s32)ts->irq_pin, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 		GTP_GPIO_FREE(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858)         //GTP_GPIO_AS_INT(GTP_INT_PORT);  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859)         gpio_direction_input(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860)         //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)         //s3c_gpio_cfgpin(pin, GTP_INT_CFG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863)         //ts->client->irq = ts->irq_pin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)     //GTP_GPIO_AS_INPUT(ts->rst_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867)     gpio_direction_input(ts->rst_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868)     //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870)     gtp_reset_guitar(ts->client, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877)     Request interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)     ts: private data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)     Executive outcomes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)         0: succeed, -1: failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) static s8 gtp_request_irq(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)     GTP_DEBUG("INT trigger type:%x", ts->int_trigger_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)     ts->irq=gpio_to_irq(ts->irq_pin);       //If not defined in client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892)     if (ts->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)         ts->client->irq = ts->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895)         ret = devm_request_threaded_irq(&(ts->client->dev), ts->irq, NULL, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)             goodix_ts_irq_handler, ts->irq_flags | IRQF_ONESHOT /*irq_table[ts->int_trigger_type]*/, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897)             ts->client->name, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898)         if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)             GTP_ERROR("Cannot allocate ts INT!ERRNO:%d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)             goto test_pit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)         //gtp_irq_disable(ts->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903)         GTP_INFO("  <%s>_%d     ts->irq=%d   ret = %d\n", __func__, __LINE__, ts->irq, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)     }else{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)         GTP_ERROR("   ts->irq  error \n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906)         ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)         goto test_pit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910)     ret  = request_irq(ts->client->irq, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)                        goodix_ts_irq_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912)                        irq_table[ts->int_trigger_type],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913)                        ts->client->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)                        ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) */                       
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) test_pit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)     if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919)         GTP_ERROR("Request IRQ failed!ERRNO:%d.", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920)         //GTP_GPIO_AS_INPUT(GTP_INT_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)         gpio_direction_input(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)         //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)         GTP_GPIO_FREE(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)         hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927)         ts->timer.function = goodix_ts_timer_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928)         hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929)         return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)     else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933)         GTP_INFO("  <%s>_%d     ts->irq=%d   ret = %d\n", __func__, __LINE__, ts->irq, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)         gtp_irq_disable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)         ts->use_irq = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936)         return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942)     Early suspend function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944)     h: early_suspend struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) static int goodix_ts_early_suspend(struct tp_device *tp_d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)     struct goodix_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951)     s8 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952)     int reg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)     ts = container_of(tp_d, struct goodix_ts_data, tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957)     GTP_INFO("System suspend.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959)     ts->gtp_is_suspend = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961)     gtp_esd_switch(ts->client, SWITCH_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965)     ret = gtp_enter_doze(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)     if (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)         gtp_irq_disable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973)         hrtimer_cancel(&ts->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)     ret = gtp_enter_sleep(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979)         printk("GTP early suspend failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981)     // to avoid waking up while not sleeping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)     //  delay 48 + 10ms to ensure reliability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983)     msleep(58);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 	reg = regulator_disable(ts->tp_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	if (reg < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 		GTP_ERROR("failed to disable tp regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994)     Late resume function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)     h: early_suspend struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) static int goodix_ts_early_resume(struct tp_device *tp_d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002)     struct goodix_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003)     s8 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)     int reg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005)     ts = container_of(tp_d, struct goodix_ts_data, tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008)     GTP_INFO("System resume.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	reg = regulator_enable(ts->tp_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 	if (reg < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 		GTP_ERROR("failed to enable tp regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 	msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)     ret = gtp_wakeup_sleep(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)     doze_status = DOZE_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023)         GTP_ERROR("GTP later resume failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) #if (GTP_COMPATIBLE_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028)         // do nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033)         gtp_send_cfg(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036)     if (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038)         gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)         hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045)     ts->gtp_is_suspend = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)     gtp_esd_switch(ts->client, SWITCH_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055)     Request input device Function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057)     ts:private data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)     Executive outcomes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060)         0: succeed, otherwise: failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) static s8 gtp_request_input_dev(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063)                                 struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)     s8 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066)     s8 phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) #if GTP_HAVE_TOUCH_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068)     u8 index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072)     ts->input_dev = devm_input_allocate_device(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073)     if (ts->input_dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)         GTP_ERROR("Failed to allocate input device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)     ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) #if GTP_ICS_SLOT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081)     input_mt_init_slots(ts->input_dev, 16, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);     // in case of "out of memory"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083)     ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)     __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) #if GTP_HAVE_TOUCH_KEY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)     for (index = 0; index < GTP_MAX_KEY_NUM; index++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090)         input_set_capability(ts->input_dev, EV_KEY, touch_key_array[index]);  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) #if GTP_GESTURE_WAKEUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095)     input_set_capability(ts->input_dev, EV_KEY, KEY_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) #endif 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	if (gtp_change_x2y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		GTP_SWAP(ts->abs_x_max, ts->abs_y_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) #if defined(CONFIG_CHROME_PLATFORMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)     input_set_abs_params(ts->input_dev, ABS_X, 0, ts->abs_x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)     input_set_abs_params(ts->input_dev, ABS_Y, 0, ts->abs_y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105)     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107)     input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108)     input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)     input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111)     sprintf(phys, "input/ts");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)     ts->input_dev->name = goodix_ts_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)     ts->input_dev->phys = phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)     ts->input_dev->id.bustype = BUS_I2C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115)     ts->input_dev->id.vendor = 0xDEAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116)     ts->input_dev->id.product = 0xBEEF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)     ts->input_dev->id.version = 10427;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119)     ret = input_register_device(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)     if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122)         GTP_ERROR("Register %s input device failed", ts->input_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126)     ts->tp.tp_resume = goodix_ts_early_resume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127)     ts->tp.tp_suspend = goodix_ts_early_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128)     tp_register_fb(&ts->tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) #if GTP_WITH_PEN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131)     gtp_pen_init(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) //************** For GT9XXF Start *************//
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) s32 gtp_fw_startup(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142)     u8 opr_buf[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144)     struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145)     //init sw WDT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	opr_buf[0] = 0xAA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 	ret = i2c_write_bytes(client, 0x8041, opr_buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153)     //release SS51 & DSP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154)     opr_buf[0] = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155)     ret = i2c_write_bytes(client, 0x4180, opr_buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160)     //int sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161)     gtp_int_sync(25, ts);  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163)     //check fw run status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164)     ret = i2c_read_bytes(client, 0x8041, opr_buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169)     if(0xAA == opr_buf[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171)         GTP_ERROR("IC works abnormally,startup failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)         GTP_INFO("IC works normally, Startup success.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)         opr_buf[0] = 0xAA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)         i2c_write_bytes(client, 0x8041, opr_buf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179)         return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) static s32 gtp_esd_recovery(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185)     s32 retry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187)     struct goodix_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189)     ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191)     gtp_irq_disable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193)     GTP_INFO("GT9XXF esd recovery mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194)     for (retry = 0; retry < 5; retry++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)         ret = gup_fw_download_proc(NULL, GTP_FL_ESD_RECOVERY); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197)         if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199)             GTP_ERROR("esd recovery failed %d", retry+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202)         ret = gtp_fw_startup(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203)         if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205)             GTP_ERROR("GT9XXF start up failed %d", retry+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210)     gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212)     if (retry >= 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)         GTP_ERROR("failed to esd recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)     GTP_INFO("Esd recovery successful");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219)     return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) void gtp_recovery_reset(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225)     gtp_esd_switch(client, SWITCH_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229)     gtp_esd_recovery(client); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232)     gtp_esd_switch(client, SWITCH_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) static s32 gtp_bak_ref_proc(struct goodix_ts_data *ts, u8 mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)     s32 i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240)     s32 j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)     u16 ref_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242)     u16 learn_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243)     u16 chksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244)     s32 ref_seg_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245)     s32 ref_grps = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246)     struct file *ref_filp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247)     u8 *p_bak_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)     ret = gup_check_fs_mounted("/data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)     if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)         ts->ref_chk_fs_times++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253)         GTP_DEBUG("Ref check /data times/MAX_TIMES: %d / %d", ts->ref_chk_fs_times, GTP_CHK_FS_MNT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254)         if (ts->ref_chk_fs_times < GTP_CHK_FS_MNT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256)             msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257)             GTP_INFO("/data not mounted.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258)             return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260)         GTP_INFO("check /data mount timeout...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)         GTP_INFO("/data mounted!!!(%d/%d)", ts->ref_chk_fs_times, GTP_CHK_FS_MNT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) 	p_bak_ref = kzalloc(ts->bak_ref_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)     if (NULL == p_bak_ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271)         GTP_ERROR("Allocate memory for p_bak_ref failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)     if (ts->is_950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277)         ref_seg_len = ts->bak_ref_len / 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278)         ref_grps = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282)         ref_seg_len = ts->bak_ref_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283)         ref_grps = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)     ref_filp = filp_open(GTP_BAK_REF_PATH, O_RDWR | O_CREAT, 0666);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286)     if (IS_ERR(ref_filp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)     { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)         GTP_ERROR("Failed to open/create %s.", GTP_BAK_REF_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289)         if (GTP_BAK_REF_SEND == mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291)             goto bak_ref_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)             goto bak_ref_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299)     switch (mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)     case GTP_BAK_REF_SEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302)         GTP_INFO("Send backup-reference");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303)         ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)         ret = ref_filp->f_op->read(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305)         if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307)             GTP_ERROR("failed to read bak_ref info from file, sending defualt bak_ref");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308)             goto bak_ref_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310)         for (j = 0; j < ref_grps; ++j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)             ref_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313)             for (i = 0; i < (ref_seg_len); i += 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)                 ref_sum += (p_bak_ref[i + j * ref_seg_len] << 8) + p_bak_ref[i+1 + j * ref_seg_len];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)             learn_cnt = (p_bak_ref[j * ref_seg_len + ref_seg_len -4] << 8) + (p_bak_ref[j * ref_seg_len + ref_seg_len -3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318)             chksum = (p_bak_ref[j * ref_seg_len + ref_seg_len -2] << 8) + (p_bak_ref[j * ref_seg_len + ref_seg_len -1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319)             GTP_DEBUG("learn count = %d", learn_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)             GTP_DEBUG("chksum = %d", chksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)             GTP_DEBUG("ref_sum = 0x%04X", ref_sum & 0xFFFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322)             // Sum(1~ref_seg_len) == 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)             if (1 != ref_sum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325)                 GTP_INFO("wrong chksum for bak_ref, reset to 0x00 bak_ref");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326)                 memset(&p_bak_ref[j * ref_seg_len], 0, ref_seg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327)                 p_bak_ref[ref_seg_len + j * ref_seg_len - 1] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331)                 if (j == (ref_grps - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332)                 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333)                     GTP_INFO("backup-reference data in %s used", GTP_BAK_REF_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)         ret = i2c_write_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338)         if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340)             GTP_ERROR("failed to send bak_ref because of iic comm error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341)             goto bak_ref_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345)     case GTP_BAK_REF_STORE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346)         GTP_INFO("Store backup-reference");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)         ret = i2c_read_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)         if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)             GTP_ERROR("failed to read bak_ref info, sending default back-reference");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351)             goto bak_ref_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353)         ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354)         ref_filp->f_op->write(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)     default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358)         GTP_ERROR("invalid backup-reference request");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359)         break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)     ret = SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362)     goto bak_ref_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) bak_ref_default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366)     for (j = 0; j < ref_grps; ++j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368)         memset(&p_bak_ref[j * ref_seg_len], 0, ref_seg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369)         p_bak_ref[j * ref_seg_len + ref_seg_len - 1] = 0x01;  // checksum = 1     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371)     ret = i2c_write_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372)     if (!IS_ERR(ref_filp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374)         GTP_INFO("write backup-reference data into %s", GTP_BAK_REF_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375)         ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376)         ref_filp->f_op->write(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378)     if (ret == FAIL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380)         GTP_ERROR("failed to load the default backup reference");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) bak_ref_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385)     if (p_bak_ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387)         kfree(p_bak_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389)     if (ref_filp && !IS_ERR(ref_filp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391)         filp_close(ref_filp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) static s32 gtp_verify_main_clk(u8 *p_main_clk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399)     u8 chksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)     u8 main_clock = p_main_clk[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401)     s32 i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403)     if (main_clock < 50 || main_clock > 120)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408)     for (i = 0; i < 5; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410)         if (main_clock != p_main_clk[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)             return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)         chksum += p_main_clk[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416)     chksum += p_main_clk[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)     if ( (chksum) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)         return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) static s32 gtp_main_clk_proc(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 	s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	s32 i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	s32 clk_chksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	struct file *clk_filp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	#if GTP_USE_FIXED_CLK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 	u8 p_main_clk[6] = {69, 69, 69, 69, 69, 167};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	#else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 	u8 p_main_clk[6] = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 	#endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 	#if GTP_USE_FIXED_CLK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	 * here check kernel /data is not same as android /data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 	 * so modify it to reduce fw download
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 	ret = gtp_verify_main_clk(p_main_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	if (ret == FAIL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 		GTP_ERROR("main clock data verify error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 		GTP_INFO("main clock data used fix freq: %d", p_main_clk[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 		goto update_main_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	#else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453)     ret = gup_check_fs_mounted("/data");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454)     if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456)         ts->clk_chk_fs_times++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)         GTP_DEBUG("Clock check /data times/MAX_TIMES: %d / %d", ts->clk_chk_fs_times, GTP_CHK_FS_MNT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458)         if (ts->clk_chk_fs_times < GTP_CHK_FS_MNT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)             msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461)             GTP_INFO("/data not mounted.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462)             return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464)         GTP_INFO("Check /data mount timeout!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468)         GTP_INFO("/data mounted!!!(%d/%d)", ts->clk_chk_fs_times, GTP_CHK_FS_MNT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)     clk_filp = filp_open(GTP_MAIN_CLK_PATH, O_RDWR | O_CREAT, 0666);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)     if (IS_ERR(clk_filp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474)         GTP_ERROR("%s is unavailable, calculate main clock", GTP_MAIN_CLK_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478)         clk_filp->f_op->llseek(clk_filp, 0, SEEK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479)         clk_filp->f_op->read(clk_filp, (char *)p_main_clk, 6, &clk_filp->f_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480)        
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481)         ret = gtp_verify_main_clk(p_main_clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482)         if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484)             // recalculate main clock & rewrite main clock data to file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485)             GTP_ERROR("main clock data in %s is wrong, recalculate main clock", GTP_MAIN_CLK_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488)         { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489)             GTP_INFO("main clock data in %s used, main clock freq: %d", GTP_MAIN_CLK_PATH, p_main_clk[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490)             filp_close(clk_filp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)             goto update_main_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	#endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497)     gtp_esd_switch(ts->client, SWITCH_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499)     ret = gup_clk_calibration();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500)     gtp_esd_recovery(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503)     gtp_esd_switch(ts->client, SWITCH_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506)     GTP_INFO("calibrate main clock: %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507)     if (ret < 50 || ret > 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509)         GTP_ERROR("wrong main clock: %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510)         goto exit_main_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513)     // Sum{0x8020~0x8025} = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514)     for (i = 0; i < 5; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516)         p_main_clk[i] = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517)         clk_chksum += p_main_clk[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519)     p_main_clk[5] = 0 - clk_chksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521)     if (!IS_ERR(clk_filp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523)         GTP_DEBUG("write main clock data into %s", GTP_MAIN_CLK_PATH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524)         clk_filp->f_op->llseek(clk_filp, 0, SEEK_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525)         clk_filp->f_op->write(clk_filp, (char *)p_main_clk, 6, &clk_filp->f_pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526)         filp_close(clk_filp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) update_main_clk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530)     ret = i2c_write_bytes(ts->client, GTP_REG_MAIN_CLK, p_main_clk, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531)     if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533)         GTP_ERROR("update main clock failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536)     return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) exit_main_clk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)     if (!IS_ERR(clk_filp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541)         filp_close(clk_filp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543)     return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) s32 gtp_gt9xxf_init(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551)     ret = gup_fw_download_proc(NULL, GTP_FL_FW_BURN); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552)     if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557)     ret = gtp_fw_startup(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)     if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)         return FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562)     return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) void gtp_get_chip_type(struct goodix_ts_data *ts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)     u8 opr_buf[10] = {0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568)     s32 ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570)     msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)     ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CHIP_TYPE, opr_buf, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)     if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576)         GTP_ERROR("Failed to get chip-type, set chip type default: GOODIX_GT9");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577)         ts->chip_type = CHIP_TYPE_GT9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581)     if (!memcmp(opr_buf, "GOODIX_GT9", 10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583)         ts->chip_type = CHIP_TYPE_GT9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585)     else if (bgt9110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) 	  ts->chip_type = CHIP_TYPE_GT9110;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) 	  GTP_INFO("Chip Type: GOODIX_GT9110");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589) 	  return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591)     else // GT9XXF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)         ts->chip_type = CHIP_TYPE_GT9F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595)     GTP_INFO("Chip Type: %s", (ts->chip_type == CHIP_TYPE_GT9) ? "GOODIX_GT9" : "GOODIX_GT9F");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) //************* For GT9XXF End ************//
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603)     I2c probe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605)     client: i2c device struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)     id: device id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608)     Executive outcomes. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609)         0: succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614)     struct goodix_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)     u16 version_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617)     struct device_node *np = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618)     enum of_gpio_flags rst_flags, pwr_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619)     u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) 	printk("%s() start\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625)     //do NOT remove these logs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626)     GTP_INFO("GTP Driver Version: %s", GTP_DRIVER_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627)     GTP_INFO("GTP I2C Address: 0x%02x", client->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629)     i2c_connect_client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631)     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633)         GTP_ERROR("I2C check functionality failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634)         return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636)     ts = kzalloc(sizeof(*ts), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637)     if (ts == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639)         GTP_ERROR("Alloc GFP_KERNEL memory failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643)     memset(ts, 0, sizeof(*ts));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645)     if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)     	dev_err(&client->dev, "no device tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647)     	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)     if (of_property_read_u32(np, "tp-size", &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650)     	dev_err(&client->dev, "no max-x defined\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651)     	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) 	if (val == 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) 		m89or101 = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) 		gtp_change_x2y = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) 		gtp_x_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) 		gtp_y_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) 	} else if (val == 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) 		m89or101 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) 		gtp_change_x2y = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) 		gtp_x_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) 		gtp_y_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) 	} else if (val == 911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) 		m89or101 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) 		bgt911 = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) 		gtp_change_x2y = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) 		gtp_x_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) 		gtp_y_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) 	} else if (val == 9110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) 		m89or101 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) 		bgt9110 = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) 		gtp_change_x2y = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) 		gtp_x_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) 		gtp_y_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) 	} else if (val == 9111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) 		m89or101 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) 		bgt9111 = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) 		gtp_change_x2y = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) 		gtp_x_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) 		gtp_y_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) 	} else if (val == 970) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) 		m89or101 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) 		bgt911 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) 		bgt970 = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) 		gtp_change_x2y = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) 		gtp_x_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) 		gtp_y_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) 	} else if (val == 910) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) 		m89or101 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) 		bgt911 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) 		bgt970 = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) 		bgt910 = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) 		gtp_change_x2y = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) 		gtp_x_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) 		gtp_y_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) 	ts->tp_regulator = devm_regulator_get(&client->dev, "tp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) 	if (IS_ERR(ts->tp_regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) 		dev_err(&client->dev, "failed to get regulator, %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) 			PTR_ERR(ts->tp_regulator));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) 		return PTR_ERR(ts->tp_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) 	ret = regulator_enable(ts->tp_regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) 		GTP_ERROR("failed to enable tp regulator\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) 	msleep(20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711)     ts->irq_pin = of_get_named_gpio_flags(np, "touch-gpio", 0, (enum of_gpio_flags *)(&ts->irq_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712)     ts->rst_pin = of_get_named_gpio_flags(np, "reset-gpio", 0, &rst_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713)     ts->pwr_pin = of_get_named_gpio_flags(np, "power-gpio", 0, &pwr_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714)     //ts->tp_select_pin = of_get_named_gpio_flags(np, "tp-select-gpio", 0, &tp_select_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715)     if (of_property_read_u32(np, "max-x", &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716)     	dev_err(&client->dev, "no max-x defined\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717)     	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719)     //ts->abs_x_max = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720)     if (of_property_read_u32(np, "max-y", &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721)     	dev_err(&client->dev, "no max-y defined\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722)     	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724)     //ts->abs_y_max = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725)     if (of_property_read_u32(np, "configfile-num", &val)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) 	    ts->cfg_file_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727)     } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) 	    ts->cfg_file_num = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730)     ts->pendown =PEN_RELEASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731)     ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)     INIT_WORK(&ts->work, goodix_ts_work_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735)     ts->client = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736)     spin_lock_init(&ts->irq_lock);          // 2.6.39 later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737)     // ts->irq_lock = SPIN_LOCK_UNLOCKED;   // 2.6.39 & before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739)     ts->clk_tick_cnt = 2 * HZ;      // HZ: clock ticks in 1 second generated by system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740)     GTP_DEBUG("Clock ticks for an esd cycle: %d", ts->clk_tick_cnt);  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741)     spin_lock_init(&ts->esd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742)     // ts->esd_lock = SPIN_LOCK_UNLOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745)     i2c_set_clientdata(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747)     ts->gtp_rawdiff_mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749)     ret = gtp_request_io_port(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752)         GTP_ERROR("GTP request IO port failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753)         //return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754)         goto probe_init_error_requireio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757)     if(gpio_get_value(ts->tp_select_pin))//WGJ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759)     	printk("tp 11111111111111111111111111111 WGJ\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) 		gtp_x_reverse = FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) 		gtp_y_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763)     else//DPT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765)     	printk("tp 00000000000000000000000000000 DPT\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) 		gtp_x_reverse = TRUE;//FALSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) 		gtp_y_reverse = TRUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771)     gtp_get_chip_type(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773)     if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775)         ret = gtp_gt9xxf_init(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776)         if (FAIL == ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778)             GTP_INFO("Failed to init GT9XXF.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783)     ret = gtp_i2c_test(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786)         printk("<%s>_%d    I2C communication ERROR!\n", __func__, __LINE__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787)         goto probe_init_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790)     ret = gtp_read_version(client, &version_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793)         GTP_ERROR("Read version failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796)     ret = gtp_init_panel(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799)         GTP_ERROR("GTP init panel failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800)         //ts->abs_x_max = GTP_MAX_WIDTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801)         //ts->abs_y_max = GTP_MAX_HEIGHT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802)         ts->int_trigger_type = GTP_INT_TRIGGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805)     ts->irq_flags = ts->int_trigger_type ? IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806)     // Create proc file system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) 	gt91xx_config_proc = proc_create(GT91XX_CONFIG_PROC_FILE, 0664, NULL, &config_proc_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808)     if (gt91xx_config_proc == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810)         GTP_ERROR("create_proc_entry %s failed\n", GT91XX_CONFIG_PROC_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814)         GTP_INFO("create proc entry %s success", GT91XX_CONFIG_PROC_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) #if GTP_AUTO_UPDATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818)     ret = gup_init_update_proc(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821)         GTP_ERROR("Create update thread error.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825)     ret = gtp_request_input_dev(client, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)         GTP_ERROR("GTP request input dev failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830)     ret = gtp_request_irq(ts); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831)     if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833)         GTP_INFO("GTP works in polling mode.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837)         GTP_INFO("GTP works in interrupt mode.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840)     if (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842)         gtp_irq_enable(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845)     if (of_property_read_bool(np, "wakeup-source"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847)         device_init_wakeup(&client->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848)         enable_irq_wake(ts->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) #if GTP_CREATE_WR_NODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852)     init_wr_node(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856)     gtp_esd_switch(client, SWITCH_ON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) probe_init_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)     printk("   <%s>_%d  prob error !!!!!!!!!!!!!!!\n", __func__, __LINE__);    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862)     GTP_GPIO_FREE(ts->rst_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863)     GTP_GPIO_FREE(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) probe_init_error_requireio:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865)     tp_unregister_fb(&ts->tp); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866)     kfree(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873)     Goodix touchscreen driver release function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875)     client: i2c device struct.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877)     Executive outcomes. 0---succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) static int goodix_ts_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881)     struct goodix_ts_data *ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)     tp_unregister_fb(&ts->tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) #if GTP_CREATE_WR_NODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888)     uninit_wr_node();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892)     destroy_workqueue(gtp_esd_check_workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895)     if (ts) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)         if (ts->use_irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899)             //GTP_GPIO_AS_INPUT(GTP_INT_PORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901)             gpio_direction_input(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902)             //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903)             
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904)             GTP_GPIO_FREE(ts->irq_pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)             free_irq(client->irq, ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909)             hrtimer_cancel(&ts->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) 		GTP_INFO("GTP driver removing...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) 		i2c_set_clientdata(client, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) 		input_unregister_device(ts->input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) 		kfree(ts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917)     return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) s32 gtp_i2c_read_no_rst(struct i2c_client *client, u8 *buf, s32 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927)     struct i2c_msg msgs[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928)     s32 ret=-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929)     s32 retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933)     msgs[0].flags = !I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934)     msgs[0].addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935)     msgs[0].len   = GTP_ADDR_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936)     msgs[0].buf   = &buf[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937)     //msgs[0].scl_rate = 300 * 1000;    // for Rockchip, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939)     msgs[1].flags = I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940)     msgs[1].addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941)     msgs[1].len   = len - GTP_ADDR_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942)     msgs[1].buf   = &buf[GTP_ADDR_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943)     //msgs[1].scl_rate = 300 * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945)     while(retries < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947)         ret = i2c_transfer(client->adapter, msgs, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948)         if(ret == 2)break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949)         retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951)     if ((retries >= 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952)     {    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953)         GTP_ERROR("I2C Read: 0x%04X, %d bytes failed, errcode: %d!", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) s32 gtp_i2c_write_no_rst(struct i2c_client *client,u8 *buf,s32 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960)     struct i2c_msg msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962)     s32 retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966)     msg.flags = !I2C_M_RD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967)     msg.addr  = client->addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968)     msg.len   = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969)     msg.buf   = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970)     //msg.scl_rate = 300 * 1000;    // for Rockchip, etc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972)     while(retries < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974)         ret = i2c_transfer(client->adapter, &msg, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975)         if (ret == 1)break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976)         retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978)     if((retries >= 5))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980)         GTP_ERROR("I2C Write: 0x%04X, %d bytes failed, errcode: %d!", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982)     return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986)     switch on & off esd delayed work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988)     client:  i2c device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989)     on:      SWITCH_ON / SWITCH_OFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991)     void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) void gtp_esd_switch(struct i2c_client *client, s32 on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995)     struct goodix_ts_data *ts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997)     ts = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998)     spin_lock(&ts->esd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000)     if (SWITCH_ON == on)     // switch on esd 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)         if (!ts->esd_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004)             ts->esd_running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005)             spin_unlock(&ts->esd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006)             GTP_INFO("Esd started");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007)             queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, ts->clk_tick_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011)             spin_unlock(&ts->esd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014)     else    // switch off esd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016)         if (ts->esd_running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018)             ts->esd_running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019)             spin_unlock(&ts->esd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020)             GTP_INFO("Esd cancelled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021)             cancel_delayed_work_sync(&gtp_esd_check_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025)             spin_unlock(&ts->esd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032)     Initialize external watchdog for esd protect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034)     client:  i2c device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036)     result of i2c write operation. 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037)         1: succeed, otherwise: failed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) *********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) static s32 gtp_init_ext_watchdog(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041)     u8 opr_buffer[3] = {0x80, 0x41, 0xAA};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042)     GTP_DEBUG("[Esd]Init external watchdog");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043)     return gtp_i2c_write_no_rst(client, opr_buffer, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) /*******************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048)     Esd protect function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049)     External watchdog added by meta, 2013/03/07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051)     work: delayed work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) *******************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) static void gtp_esd_check_func(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)     s32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058)     s32 ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059)     struct goodix_ts_data *ts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060)     u8 esd_buf[5] = {0x80, 0x40};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063)    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064)     ts = i2c_get_clientdata(i2c_connect_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066)     if (ts->gtp_is_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068)         GTP_INFO("Esd suspended!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069)         return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072)     for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074)         ret = gtp_i2c_read_no_rst(ts->client, esd_buf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076)         GTP_DEBUG("[Esd]0x8040 = 0x%02X, 0x8041 = 0x%02X", esd_buf[2], esd_buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077)         if ((ret < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079)             // IIC communication problem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080)             continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083)         { 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084)             if ((esd_buf[2] == 0xAA) || (esd_buf[3] != 0xAA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086)                 // IC works abnormally..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087)                 u8 chk_buf[4] = {0x80, 0x40};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089)                 gtp_i2c_read_no_rst(ts->client, chk_buf, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091)                 GTP_DEBUG("[Check]0x8040 = 0x%02X, 0x8041 = 0x%02X", chk_buf[2], chk_buf[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092)                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093)                 if ((chk_buf[2] == 0xAA) || (chk_buf[3] != 0xAA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094)                 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095)                     i = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096)                     break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098)                 else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099)                 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100)                     continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101)                 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103)             else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105)                 // IC works normally, Write 0x8040 0xAA, feed the dog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106)                 esd_buf[2] = 0xAA; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107)                 gtp_i2c_write_no_rst(ts->client, esd_buf, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108)                 break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112)     if (i >= 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114)     #if GTP_COMPATIBLE_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115)         if (CHIP_TYPE_GT9F == ts->chip_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116)         {        
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117)             if (ts->rqst_processing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119)                 GTP_INFO("Request processing, no esd recovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121)             else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123)                 GTP_ERROR("IC working abnormally! Process esd recovery.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124)                 esd_buf[0] = 0x42;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125)                 esd_buf[1] = 0x26;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126)                 esd_buf[2] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127)                 esd_buf[3] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128)                 esd_buf[4] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129)                 gtp_i2c_write_no_rst(ts->client, esd_buf, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130)                 msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131)                 gtp_esd_recovery(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132)             }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134)         else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135)     #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137)             GTP_ERROR("IC working abnormally! Process reset guitar.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138)             esd_buf[0] = 0x42;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139)             esd_buf[1] = 0x26;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140)             esd_buf[2] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141)             esd_buf[3] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142)             esd_buf[4] = 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143)             gtp_i2c_write_no_rst(ts->client, esd_buf, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144)             msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145)             gtp_reset_guitar(ts->client, 50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146)             msleep(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147)             gtp_send_cfg(ts->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151)     if(!ts->gtp_is_suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)         queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, ts->clk_tick_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157)         GTP_INFO("Esd suspended!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159)     return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) static const struct i2c_device_id goodix_ts_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164)     { GTP_I2C_NAME, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165)     { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) static struct of_device_id goodix_ts_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169)     { .compatible = "goodix,gt9xx" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170)     { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) static struct i2c_driver goodix_ts_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174)     .probe      = goodix_ts_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175)     .remove     = goodix_ts_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176)     .id_table   = goodix_ts_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177)     .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178)         .name     = GTP_I2C_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) 	 .of_match_table = of_match_ptr(goodix_ts_dt_ids),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180)     },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) /*******************************************************    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185)     Driver Install function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189)     Executive Outcomes. 0---succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) ********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) static int goodix_ts_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193)     s32 ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195)     GTP_DEBUG_FUNC();   
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196)     GTP_INFO("GTP driver installing...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197)     goodix_wq = create_singlethread_workqueue("goodix_wq");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198)     if (!goodix_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200)         GTP_ERROR("Creat workqueue failed.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201)         return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) #if GTP_ESD_PROTECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204)     INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205)     gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207)     ret = i2c_add_driver(&goodix_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208)     return ret; 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) /*******************************************************    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212) Function:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213)     Driver uninstall function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214) Input:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215)     None.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) Output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217)     Executive Outcomes. 0---succeed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) ********************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) static void goodix_ts_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221)     GTP_DEBUG_FUNC();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222)     GTP_INFO("GTP driver exited.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223)     i2c_del_driver(&goodix_ts_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224)     if (goodix_wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226)         destroy_workqueue(goodix_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227)     }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) //late_initcall(goodix_ts_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) module_init(goodix_ts_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) module_exit(goodix_ts_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234) MODULE_DESCRIPTION("GTP Series Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) MODULE_LICENSE("GPL");