精华内容
下载资源
问答
  • 信捷TP触摸屏软件.rar

    2019-10-14 11:47:55
    信捷TP触摸屏软件rar,信捷TP触摸屏软件
  • 信捷TP触摸屏软件

    2021-03-24 05:43:50
    介绍了关于信捷TP触摸屏软件的详细说明,提供人机界面软件的技术资料的下载。
  • 介绍了关于信捷TP触摸屏高级功能指令应用的详细说明,提供信捷的技术资料的下载。
  • TP触摸屏主机端调试指南
  • 触摸屏\TH_TP触摸屏C语言编程.pdf
  • TPTH 触摸屏 C 函数功能块 用户手册 信捷科技电子有限公司 资料编号HC 10 20110421 2C6 目 录 前言. 1 1 函数功能块制作. 2 2 函数功能块说明 . 4 2.1书写方式 . 4 2.2函数类型 . 4 2.3预定义数据类型. 5 2.4预定...
  • 西门子TP触摸屏启动语言设置为英语

    千次阅读 2020-03-12 16:36:00
    选择左侧项目树---语言和资源---项目语言 然后在常规界面勾选英语(美国) ...触摸屏启动后显示语言变为英语 想要变回中文 要回到项目语言中去掉英文的勾 如果有双语切换需求再勾上并到运行系统设置中启动下。 ...

    选择左侧项目树---语言和资源---项目语言

    然后在常规界面勾选英语(美国)

     

     

    回到左侧项目树  选择运行系统设置 --- 语言字体 ---启用英语 这个时候模拟就会显示英文  

    触摸屏启动后显示语言变为英语

    想要变回中文 要回到项目语言中去掉英文的勾 如果有双语切换需求再勾上并到运行系统设置中启动下。

    展开全文
  • 调试的是一个10.1寸的,首先在DTS中添加 &i2c1 { status = "okay"; gt9xx: gt9xx@5d { compatible = "goodix,gt9xx"; reg = <0x5d>; touch-gpio = <&gpio0 RK_PA5 IRQ_TYPE_LEVEL_HIGH&...

    调试的是一个10.1寸的屏,首先在DTS中添加

    &i2c1 {
    	status = "okay";
    	gt9xx: gt9xx@5d {
    		compatible = "goodix,gt9xx";
    		reg = <0x5d>;
    		touch-gpio = <&gpio0 RK_PA5 IRQ_TYPE_LEVEL_HIGH>;
    		reset-gpio = <&gpio0 RK_PB4 GPIO_ACTIVE_HIGH>;
    		max-x = <1280>;
    		max-y = <800>;
    		tp-size = <101>;
    		tp-supply = <&vcc_3v0>;
    		status = "okay";
    	};
    };
    

    当触摸的x和y不对时修改驱动的对应内容:

    if (val == 89) {
    	m89or101 = TRUE;
    	gtp_change_x2y = TRUE;
    	gtp_x_reverse = FALSE;
    	gtp_y_reverse = TRUE;
    } else if (val == 101) {
    	m89or101 = FALSE;
    	gtp_change_x2y = FALSE;
    	gtp_x_reverse = TRUE;
    	gtp_y_reverse = FALSE;
    } else if (val == 911) {
    	m89or101 = FALSE;
    	bgt911 = TRUE;
    	gtp_change_x2y = TRUE;
    	gtp_x_reverse = FALSE;
    	gtp_y_reverse = FALSE;
    } else if (val == 970) {
    	m89or101 = FALSE;
    	bgt911 = FALSE;
    	bgt970 = TRUE;
    	gtp_change_x2y = FALSE;
    	gtp_x_reverse = FALSE;
    	gtp_y_reverse = FALSE;
    } else if (val == 910) {
    	m89or101 = FALSE;
    	bgt911 = FALSE;
    	bgt970 = FALSE;
    	bgt910 = TRUE;
    	gtp_change_x2y = TRUE;
    	gtp_x_reverse = FALSE;
    	gtp_y_reverse = TRUE;
    }
    

    驱动内容:

    /* drivers/input/touchscreen/gt9xx.c
     * 
     * 2010 - 2013 Goodix Technology.
     * 
     * This program is free software; you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation; either version 2 of the License, or
     * (at your option) any later version.
     * 
     * This program is distributed in the hope that it will be a reference 
     * to you, when you are integrating the GOODiX's CTP IC into your system, 
     * but WITHOUT ANY WARRANTY; without even the implied warranty of 
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
     * General Public License for more details.
     * 
     * Version: 2.2
     * Authors: andrew@goodix.com, meta@goodix.com
     * Release Date: 2014/01/14
     * Revision record:
     *      V1.0:   
     *          first Release. By Andrew, 2012/08/31 
     *      V1.2:
     *          modify gtp_reset_guitar,slot report,tracking_id & 0x0F. By Andrew, 2012/10/15
     *      V1.4:
     *          modify gt9xx_update.c. By Andrew, 2012/12/12
     *      V1.6: 
     *          1. new heartbeat/esd_protect mechanism(add external watchdog)
     *          2. doze mode, sliding wakeup 
     *          3. 3 more cfg_group(GT9 Sensor_ID: 0~5) 
     *          3. config length verification
     *          4. names & comments
     *                  By Meta, 2013/03/11
     *      V1.8:
     *          1. pen/stylus identification 
     *          2. read double check & fixed config support
     *          3. new esd & slide wakeup optimization
     *                  By Meta, 2013/06/08
     *      V2.0:
     *          1. compatible with GT9XXF
     *          2. send config after resume
     *                  By Meta, 2013/08/06
     *      V2.2:
     *          1. gt9xx_config for debug
     *          2. gesture wakeup
     *          3. pen separate input device, active-pen button support
     *          4. coordinates & keys optimization
     *                  By Meta, 2014/01/14
     */
    
    #include <linux/irq.h>
    #include "gt9xx.h"
    #include "gt9xx_cfg.h"
    #include <linux/regulator/consumer.h>
    
    #if GTP_ICS_SLOT_REPORT
        #include <linux/input/mt.h>
    #endif
    
    static u8 m89or101 = TRUE;
    static u8 bgt911 = FALSE;
    static u8 bgt970 = FALSE;
    static u8 bgt910 = FALSE;
    static u8 gtp_change_x2y = TRUE;
    static u8 gtp_x_reverse = FALSE;
    static u8 gtp_y_reverse = TRUE;
    
    static const char *goodix_ts_name = "goodix-ts";
    static struct workqueue_struct *goodix_wq;
    struct i2c_client * i2c_connect_client = NULL; 
    u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]
                    = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
    
    #if GTP_HAVE_TOUCH_KEY
        static const u16 touch_key_array[] = GTP_KEY_TAB;
        #define GTP_MAX_KEY_NUM  (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
        
    #if GTP_DEBUG_ON
        static const int  key_codes[] = {KEY_HOME, KEY_BACK, KEY_MENU, KEY_SEARCH};
        static const char *key_names[] = {"Key_Home", "Key_Back", "Key_Menu", "Key_Search"};
    #endif
        
    #endif
    
    static s8 gtp_i2c_test(struct i2c_client *client);
    void gtp_reset_guitar(struct i2c_client *client, s32 ms);
    s32 gtp_send_cfg(struct i2c_client *client);
    void gtp_int_sync(s32 ms, struct goodix_ts_data *ts);
    
    static ssize_t gt91xx_config_read_proc(struct file *, char __user *, size_t, loff_t *);
    static ssize_t gt91xx_config_write_proc(struct file *, const char __user *, size_t, loff_t *);
    
    static struct proc_dir_entry *gt91xx_config_proc = NULL;
    static const struct file_operations config_proc_ops = {
        .owner = THIS_MODULE,
        .read = gt91xx_config_read_proc,
        .write = gt91xx_config_write_proc,
    };
    
    #if GTP_CREATE_WR_NODE
    extern s32 init_wr_node(struct i2c_client*);
    extern void uninit_wr_node(void);
    #endif
    
    #if GTP_AUTO_UPDATE
    extern u8 gup_init_update_proc(struct goodix_ts_data *);
    #endif
    
    #if GTP_ESD_PROTECT
    static struct delayed_work gtp_esd_check_work;
    static struct workqueue_struct * gtp_esd_check_workqueue = NULL;
    static void gtp_esd_check_func(struct work_struct *);
    static s32 gtp_init_ext_watchdog(struct i2c_client *client);
    void gtp_esd_switch(struct i2c_client *, s32);
    #endif
    
    //*********** For GT9XXF Start **********//
    #if GTP_COMPATIBLE_MODE
    extern s32 i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *buf, s32 len);
    extern s32 i2c_write_bytes(struct i2c_client *client, u16 addr, u8 *buf, s32 len);
    extern s32 gup_clk_calibration(void);
    extern s32 gup_fw_download_proc(void *dir, u8 dwn_mode);
    extern u8 gup_check_fs_mounted(char *path_name);
    
    void gtp_recovery_reset(struct i2c_client *client);
    static s32 gtp_esd_recovery(struct i2c_client *client);
    s32 gtp_fw_startup(struct i2c_client *client);
    static s32 gtp_main_clk_proc(struct goodix_ts_data *ts);
    static s32 gtp_bak_ref_proc(struct goodix_ts_data *ts, u8 mode);
    
    #endif
    //********** For GT9XXF End **********//
    
    #if GTP_GESTURE_WAKEUP
    typedef enum
    {
        DOZE_DISABLED = 0,
        DOZE_ENABLED = 1,
        DOZE_WAKEUP = 2,
    }DOZE_T;
    static DOZE_T doze_status = DOZE_DISABLED;
    static s8 gtp_enter_doze(struct goodix_ts_data *ts);
    #endif
    
    u8 grp_cfg_version = 0;
    
    /*******************************************************
    Function:
        Read data from the i2c slave device.
    Input:
        client:     i2c device.
        buf[0~1]:   read start address.
        buf[2~len-1]:   read data buffer.
        len:    GTP_ADDR_LENGTH + read bytes count
    Output:
        numbers of i2c_msgs to transfer: 
          2: succeed, otherwise: failed
    *********************************************************/
    s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len)
    {
        struct i2c_msg msgs[2];
        s32 ret=-1;
        s32 retries = 0;
    
        GTP_DEBUG_FUNC();
    
        msgs[0].flags = !I2C_M_RD;
        msgs[0].addr  = client->addr;
        msgs[0].len   = GTP_ADDR_LENGTH;
        msgs[0].buf   = &buf[0];
    #ifdef CONFIG_I2C_ROCKCHIP_COMPAT
        msgs[0].scl_rate=200 * 1000;
        //msgs[0].scl_rate = 300 * 1000;    // for Rockchip, etc.
    #endif
        msgs[1].flags = I2C_M_RD;
        msgs[1].addr  = client->addr;
        msgs[1].len   = len - GTP_ADDR_LENGTH;
        msgs[1].buf   = &buf[GTP_ADDR_LENGTH];
    #ifdef CONFIG_I2C_ROCKCHIP_COMPAT
        msgs[1].scl_rate=200 * 1000;
        //msgs[1].scl_rate = 300 * 1000;    // for Rockchip, etc.
    #endif
    
        while(retries < 5)
        {
            ret = i2c_transfer(client->adapter, msgs, 2);
            if(ret == 2)break;
            retries++;
        }
        if((retries >= 5))
        {
        #if GTP_COMPATIBLE_MODE
            struct goodix_ts_data *ts = i2c_get_clientdata(client);
        #endif
        
        #if GTP_GESTURE_WAKEUP
            // reset chip would quit doze mode
            if (DOZE_ENABLED == doze_status)
            {
                return ret;
            }
        #endif
            GTP_ERROR("I2C Read: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
        #if GTP_COMPATIBLE_MODE
            if (CHIP_TYPE_GT9F == ts->chip_type)
            { 
                gtp_recovery_reset(client);
            }
            else
        #endif
            {
                gtp_reset_guitar(client, 10);  
            }
        }
        return ret;
    }
    
    
    
    /*******************************************************
    Function:
        Write data to the i2c slave device.
    Input:
        client:     i2c device.
        buf[0~1]:   write start address.
        buf[2~len-1]:   data buffer
        len:    GTP_ADDR_LENGTH + write bytes count
    Output:
        numbers of i2c_msgs to transfer: 
            1: succeed, otherwise: failed
    *********************************************************/
    s32 gtp_i2c_write(struct i2c_client *client,u8 *buf,s32 len)
    {
        struct i2c_msg msg;
        s32 ret = -1;
        s32 retries = 0;
    
        GTP_DEBUG_FUNC();
    
        msg.flags = !I2C_M_RD;
        msg.addr  = client->addr;
        msg.len   = len;
        msg.buf   = buf;
    #ifdef CONFIG_I2C_ROCKCHIP_COMPAT
        msg.scl_rate=200 * 1000;
        //msg.scl_rate = 300 * 1000;    // for Rockchip, etc
    #endif
        while(retries < 5)
        {
            ret = i2c_transfer(client->adapter, &msg, 1);
            if (ret == 1)break;
            retries++;
        }
        if((retries >= 5))
        {
        #if GTP_COMPATIBLE_MODE
            struct goodix_ts_data *ts = i2c_get_clientdata(client);
        #endif
        
        #if GTP_GESTURE_WAKEUP
            if (DOZE_ENABLED == doze_status)
            {
                return ret;
            }
        #endif
            GTP_ERROR("I2C Write: 0x%04X, %d bytes failed, errcode: %d! Process reset.", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
        #if GTP_COMPATIBLE_MODE
            if (CHIP_TYPE_GT9F == ts->chip_type)
            { 
                gtp_recovery_reset(client);
            }
            else
        #endif
            {
                gtp_reset_guitar(client, 10);  
            }
        }
        return ret;
    }
    
    
    /*******************************************************
    Function:
        i2c read twice, compare the results
    Input:
        client:  i2c device
        addr:    operate address
        rxbuf:   read data to store, if compare successful
        len:     bytes to read
    Output:
        FAIL:    read failed
        SUCCESS: read successful
    *********************************************************/
    s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len)
    {
        u8 buf[16] = {0};
        u8 confirm_buf[16] = {0};
        u8 retry = 0;
        
        while (retry++ < 3)
        {
            memset(buf, 0xAA, 16);
            buf[0] = (u8)(addr >> 8);
            buf[1] = (u8)(addr & 0xFF);
            gtp_i2c_read(client, buf, len + 2);
            
            memset(confirm_buf, 0xAB, 16);
            confirm_buf[0] = (u8)(addr >> 8);
            confirm_buf[1] = (u8)(addr & 0xFF);
            gtp_i2c_read(client, confirm_buf, len + 2);
            
            if (!memcmp(buf, confirm_buf, len+2))
            {
                memcpy(rxbuf, confirm_buf+2, len);
                return SUCCESS;
            }
        }    
        GTP_ERROR("I2C read 0x%04X, %d bytes, double check failed!", addr, len);
        return FAIL;
    }
    
    /*******************************************************
    Function:
        Send config.
    Input:
        client: i2c device.
    Output:
        result of i2c write operation. 
            1: succeed, otherwise: failed
    *********************************************************/
    
    s32 gtp_send_cfg(struct i2c_client *client)
    {
        s32 ret = 2;
    
    #if GTP_DRIVER_SEND_CFG
        s32 retry = 0;
        struct goodix_ts_data *ts = i2c_get_clientdata(client);
    
        if (ts->fixed_cfg)
        {
            GTP_INFO("Ic fixed config, no config sent!");
            return 0;
        }
        else if (ts->pnl_init_error)
        {
            GTP_INFO("Error occured in init_panel, no config sent");
            return 0;
        }
        
        GTP_INFO("Driver send config.");
        for (retry = 0; retry < 5; retry++)
        {
            ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH);
            if (ret > 0)
            {
                break;
            }
        }
    #endif
        return ret;
    }
    /*******************************************************
    Function:
        Disable irq function
    Input:
        ts: goodix i2c_client private data
    Output:
        None.
    *********************************************************/
    void gtp_irq_disable(struct goodix_ts_data *ts)
    {
        unsigned long irqflags;
    
        GTP_DEBUG_FUNC();
    
        spin_lock_irqsave(&ts->irq_lock, irqflags);
        if (!ts->irq_is_disable)
        {
            ts->irq_is_disable = 1; 
            disable_irq_nosync(ts->client->irq);
        }
        spin_unlock_irqrestore(&ts->irq_lock, irqflags);
    }
    
    /*******************************************************
    Function:
        Enable irq function
    Input:
        ts: goodix i2c_client private data
    Output:
        None.
    *********************************************************/
    void gtp_irq_enable(struct goodix_ts_data *ts)
    {
        unsigned long irqflags = 0;
    
        GTP_DEBUG_FUNC();
        
        spin_lock_irqsave(&ts->irq_lock, irqflags);
        if (ts->irq_is_disable) 
        {
            enable_irq(ts->client->irq);
            ts->irq_is_disable = 0; 
        }
        spin_unlock_irqrestore(&ts->irq_lock, irqflags);
    }
    
    
    /*******************************************************
    Function:
        Report touch point event 
    Input:
        ts: goodix i2c_client private data
        id: trackId
        x:  input x coordinate
        y:  input y coordinate
        w:  input pressure
    Output:
        None.
    *********************************************************/
    static void gtp_touch_down(struct goodix_ts_data* ts,s32 id,s32 x,s32 y,s32 w)
    {
    	if (gtp_change_x2y)
    		GTP_SWAP(x, y);
    
    	//if (!bgt911 && !bgt970) {
    		if (gtp_x_reverse)
    			x = ts->abs_x_max - x;
    
    		if (gtp_y_reverse)
    			y = ts->abs_y_max - y;
    	//}
    
    #if GTP_ICS_SLOT_REPORT
        input_mt_slot(ts->input_dev, id);
        input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
        input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
        input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
        input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
    #else
        input_report_key(ts->input_dev, BTN_TOUCH, 1);
        input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
        input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
        input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
        input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
        input_mt_sync(ts->input_dev);
    #endif
    
        //printk("ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
    }
    
    /*******************************************************
    Function:
        Report touch release event
    Input:
        ts: goodix i2c_client private data
    Output:
        None.
    *********************************************************/
    static void gtp_touch_up(struct goodix_ts_data* ts, s32 id)
    {
    #if GTP_ICS_SLOT_REPORT
        input_mt_slot(ts->input_dev, id);
        input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1);
        GTP_DEBUG("Touch id[%2d] release!", id);
    #else
        input_report_key(ts->input_dev, BTN_TOUCH, 0);
    #endif
    }
    
    #if GTP_WITH_PEN
    
    static void gtp_pen_init(struct goodix_ts_data *ts)
    {
        s32 ret = 0;
        
        GTP_INFO("Request input device for pen/stylus.");
        
        ts->pen_dev = input_allocate_device();
        if (ts->pen_dev == NULL)
        {
            GTP_ERROR("Failed to allocate input device for pen/stylus.");
            return;
        }
        
        ts->pen_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
        
    #if GTP_ICS_SLOT_REPORT
        input_mt_init_slots(ts->pen_dev, 16, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
    #else
        ts->pen_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
    #endif
    
        set_bit(BTN_TOOL_PEN, ts->pen_dev->keybit);
        set_bit(INPUT_PROP_DIRECT, ts->pen_dev->propbit);
        //set_bit(INPUT_PROP_POINTER, ts->pen_dev->propbit);
        
    #if GTP_PEN_HAVE_BUTTON
        input_set_capability(ts->pen_dev, EV_KEY, BTN_STYLUS);
        input_set_capability(ts->pen_dev, EV_KEY, BTN_STYLUS2);
    #endif
    
        input_set_abs_params(ts->pen_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);
        input_set_abs_params(ts->pen_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);
        input_set_abs_params(ts->pen_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
        input_set_abs_params(ts->pen_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
        input_set_abs_params(ts->pen_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
        
        ts->pen_dev->name = "goodix-pen";
        ts->pen_dev->id.bustype = BUS_I2C;
        
        ret = input_register_device(ts->pen_dev);
        if (ret)
        {
            GTP_ERROR("Register %s input device failed", ts->pen_dev->name);
            return;
        }
    }
    
    static void gtp_pen_down(s32 x, s32 y, s32 w, s32 id)
    {
        struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
    
    	if (gtp_change_x2y)
    		GTP_SWAP(x, y);
    
        
        input_report_key(ts->pen_dev, BTN_TOOL_PEN, 1);
    #if GTP_ICS_SLOT_REPORT
        input_mt_slot(ts->pen_dev, id);
        input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, id);
        input_report_abs(ts->pen_dev, ABS_MT_POSITION_X, x);
        input_report_abs(ts->pen_dev, ABS_MT_POSITION_Y, y);
        input_report_abs(ts->pen_dev, ABS_MT_PRESSURE, w);
        input_report_abs(ts->pen_dev, ABS_MT_TOUCH_MAJOR, w);
    #else
        input_report_key(ts->pen_dev, BTN_TOUCH, 1);
        input_report_abs(ts->pen_dev, ABS_MT_POSITION_X, x);
        input_report_abs(ts->pen_dev, ABS_MT_POSITION_Y, y);
        input_report_abs(ts->pen_dev, ABS_MT_PRESSURE, w);
        input_report_abs(ts->pen_dev, ABS_MT_TOUCH_MAJOR, w);
        input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, id);
        input_mt_sync(ts->pen_dev);
    #endif
        GTP_DEBUG("(%d)(%d, %d)[%d]", id, x, y, w);
    }
    
    static void gtp_pen_up(s32 id)
    {
        struct goodix_ts_data *ts = i2c_get_clientdata(i2c_connect_client);
        
        input_report_key(ts->pen_dev, BTN_TOOL_PEN, 0);
        
    #if GTP_ICS_SLOT_REPORT
        input_mt_slot(ts->pen_dev, id);
        input_report_abs(ts->pen_dev, ABS_MT_TRACKING_ID, -1);
    #else
        
        input_report_key(ts->pen_dev, BTN_TOUCH, 0);
    #endif
    
    }
    #endif
    
    /*******************************************************
    Function:
        Goodix touchscreen work function
    Input:
        work: work struct of goodix_workqueue
    Output:
        None.
    *********************************************************/
    static void goodix_ts_work_func(struct work_struct *work)
    {
        u8  end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0};
        u8  point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF};
        u8  touch_num = 0;
        u8  finger = 0;
        static u16 pre_touch = 0;
        static u8 pre_key = 0;
    #if GTP_WITH_PEN
        u8 pen_active = 0;
        static u8 pre_pen = 0;
    #endif
        u8  key_value = 0;
        u8* coor_data = NULL;
        s32 input_x = 0;
        s32 input_y = 0;
        s32 input_w = 0;
        s32 id = 0;
        s32 i  = 0;
        s32 ret = -1;
        struct goodix_ts_data *ts = NULL;
    
    #if GTP_COMPATIBLE_MODE
        u8 rqst_buf[3] = {0x80, 0x43};  // for GT9XXF
    #endif
    
    #if GTP_GESTURE_WAKEUP
        u8 doze_buf[3] = {0x81, 0x4B};
    #endif
    
        GTP_DEBUG_FUNC();
        ts = container_of(work, struct goodix_ts_data, work);
        if (ts->enter_update)
        {
            return;
        }
    #if GTP_GESTURE_WAKEUP
        if (DOZE_ENABLED == doze_status)
        {               
            ret = gtp_i2c_read(i2c_connect_client, doze_buf, 3);
            GTP_DEBUG("0x814B = 0x%02X", doze_buf[2]);
            if (ret > 0)
            {     
                if ((doze_buf[2] == 'a') || (doze_buf[2] == 'b') || (doze_buf[2] == 'c') ||
                    (doze_buf[2] == 'd') || (doze_buf[2] == 'e') || (doze_buf[2] == 'g') || 
                    (doze_buf[2] == 'h') || (doze_buf[2] == 'm') || (doze_buf[2] == 'o') ||
                    (doze_buf[2] == 'q') || (doze_buf[2] == 's') || (doze_buf[2] == 'v') || 
                    (doze_buf[2] == 'w') || (doze_buf[2] == 'y') || (doze_buf[2] == 'z') ||
                    (doze_buf[2] == 0x5E) /* ^ */
                    )
                {
                    if (doze_buf[2] != 0x5E)
                    {
                        GTP_INFO("Wakeup by gesture(%c), light up the screen!", doze_buf[2]);
                    }
                    else
                    {
                        GTP_INFO("Wakeup by gesture(^), light up the screen!");
                    }
                    doze_status = DOZE_WAKEUP;
                    input_report_key(ts->input_dev, KEY_POWER, 1);
                    input_sync(ts->input_dev);
                    input_report_key(ts->input_dev, KEY_POWER, 0);
                    input_sync(ts->input_dev);
                    // clear 0x814B
                    doze_buf[2] = 0x00;
                    gtp_i2c_write(i2c_connect_client, doze_buf, 3);
    			}
    			else if ( (doze_buf[2] == 0xAA) || (doze_buf[2] == 0xBB) ||
    				(doze_buf[2] == 0xAB) || (doze_buf[2] == 0xBA) )
                {
                    char *direction[4] = {"Right", "Down", "Up", "Left"};
                    u8 type = ((doze_buf[2] & 0x0F) - 0x0A) + (((doze_buf[2] >> 4) & 0x0F) - 0x0A) * 2;
                    
                    GTP_INFO("%s slide to light up the screen!", direction[type]);
                    doze_status = DOZE_WAKEUP;
                    input_report_key(ts->input_dev, KEY_POWER, 1);
                    input_sync(ts->input_dev);
                    input_report_key(ts->input_dev, KEY_POWER, 0);
                    input_sync(ts->input_dev);
                    // clear 0x814B
                    doze_buf[2] = 0x00;
                    gtp_i2c_write(i2c_connect_client, doze_buf, 3);
                }
                else if (0xCC == doze_buf[2])
                {
                    GTP_INFO("Double click to light up the screen!");
                    doze_status = DOZE_WAKEUP;
                    input_report_key(ts->input_dev, KEY_POWER, 1);
                    input_sync(ts->input_dev);
                    input_report_key(ts->input_dev, KEY_POWER, 0);
                    input_sync(ts->input_dev);
                    // clear 0x814B
                    doze_buf[2] = 0x00;
                    gtp_i2c_write(i2c_connect_client, doze_buf, 3);
                }
                else
                {
                    // clear 0x814B
                    doze_buf[2] = 0x00;
                    gtp_i2c_write(i2c_connect_client, doze_buf, 3);
                    gtp_enter_doze(ts);
                }
            }
            if (ts->use_irq)
            {
                gtp_irq_enable(ts);
            }
            return;
        }
    #endif
    
        ret = gtp_i2c_read(ts->client, point_data, 12);
        if (ret < 0)
        {
            GTP_ERROR("I2C transfer error. errno:%d\n ", ret);
            if (ts->use_irq)
            {
                gtp_irq_enable(ts);
            }
            return;
        }
        
        finger = point_data[GTP_ADDR_LENGTH];
    
    #if GTP_COMPATIBLE_MODE
        // GT9XXF
        if ((finger == 0x00) && (CHIP_TYPE_GT9F == ts->chip_type))     // request arrived
        {
            ret = gtp_i2c_read(ts->client, rqst_buf, 3);
            if (ret < 0)
            {
               GTP_ERROR("Read request status error!");
               goto exit_work_func;
            } 
            
            switch (rqst_buf[2])
            {
            case GTP_RQST_CONFIG:
                GTP_INFO("Request for config.");
                ret = gtp_send_cfg(ts->client);
                if (ret < 0)
                {
                    GTP_ERROR("Request for config unresponded!");
                }
                else
                {
                    rqst_buf[2] = GTP_RQST_RESPONDED;
                    gtp_i2c_write(ts->client, rqst_buf, 3);
                    GTP_INFO("Request for config responded!");
                }
                break;
                
            case GTP_RQST_BAK_REF:
    			/*
                GTP_INFO("Request for backup reference.");
                ts->rqst_processing = 1;
                ret = gtp_bak_ref_proc(ts, GTP_BAK_REF_SEND);
                if (SUCCESS == ret)
                {
                    rqst_buf[2] = GTP_RQST_RESPONDED;
                    gtp_i2c_write(ts->client, rqst_buf, 3);
                    ts->rqst_processing = 0;
                    GTP_INFO("Request for backup reference responded!");
                }
                else
                {
                    GTP_ERROR("Requeset for backup reference unresponed!");
                }
    			*/
                break;
                
            case GTP_RQST_RESET:
                GTP_INFO("Request for reset.");
                gtp_recovery_reset(ts->client);
                break;
                
            case GTP_RQST_MAIN_CLOCK:
                GTP_INFO("Request for main clock.");
                ts->rqst_processing = 1;
                ret = gtp_main_clk_proc(ts);
                if (FAIL == ret)
                {
                    GTP_ERROR("Request for main clock unresponded!");
                }
                else
                {
                    GTP_INFO("Request for main clock responded!");
                    rqst_buf[2] = GTP_RQST_RESPONDED;
                    gtp_i2c_write(ts->client, rqst_buf, 3);
                    ts->rqst_processing = 0;
                    ts->clk_chk_fs_times = 0;
                }
                break;
                
            default:
                GTP_INFO("Undefined request: 0x%02X", rqst_buf[2]);
                rqst_buf[2] = GTP_RQST_RESPONDED;  
                gtp_i2c_write(ts->client, rqst_buf, 3);
                break;
            }
        }
    #endif
        if (finger == 0x00)
        {
            if (ts->use_irq)
            {
                gtp_irq_enable(ts);
            }
            return;
        }
    
        if((finger & 0x80) == 0)
        {
            goto exit_work_func;
        }
    
        touch_num = finger & 0x0f;
        if (touch_num > GTP_MAX_TOUCH)
        {
            goto exit_work_func;
        }
    
        if (touch_num > 1)
        {
            u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff};
    
            ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1)); 
            memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
        }
    
    #if (GTP_HAVE_TOUCH_KEY || GTP_PEN_HAVE_BUTTON)
        key_value = point_data[3 + 8 * touch_num];
        
        if(key_value || pre_key)
        {
        #if GTP_PEN_HAVE_BUTTON
            if (key_value == 0x40)
            {
                GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Down.");
                input_report_key(ts->pen_dev, BTN_STYLUS, 1);
                input_report_key(ts->pen_dev, BTN_STYLUS2, 1);
                pen_active = 1;
            }
            else if (key_value == 0x10)
            {
                GTP_DEBUG("BTN_STYLUS Down, BTN_STYLUS2 Up.");
                input_report_key(ts->pen_dev, BTN_STYLUS, 1);
                input_report_key(ts->pen_dev, BTN_STYLUS2, 0);
                pen_active = 1;
            }
            else if (key_value == 0x20)
            {
                GTP_DEBUG("BTN_STYLUS Up, BTN_STYLUS2 Down.");
                input_report_key(ts->pen_dev, BTN_STYLUS, 0);
                input_report_key(ts->pen_dev, BTN_STYLUS2, 1);
                pen_active = 1;
            }
            else
            {
                GTP_DEBUG("BTN_STYLUS & BTN_STYLUS2 Up.");
                input_report_key(ts->pen_dev, BTN_STYLUS, 0);
                input_report_key(ts->pen_dev, BTN_STYLUS2, 0);
                if ( (pre_key == 0x40) || (pre_key == 0x20) ||
                     (pre_key == 0x10) 
                   )
                {
                    pen_active = 1;
                }
            }
            if (pen_active)
            {
                touch_num = 0;      // shield pen point
                //pre_touch = 0;    // clear last pen status
            }
        #endif
        
        #if GTP_HAVE_TOUCH_KEY
            if (!pre_touch)
            {
                for (i = 0; i < GTP_MAX_KEY_NUM; i++)
                {
                #if GTP_DEBUG_ON
                    for (ret = 0; ret < 4; ++ret)
                    {
                        if (key_codes[ret] == touch_key_array[i])
                        {
                            GTP_DEBUG("Key: %s %s", key_names[ret], (key_value & (0x01 << i)) ? "Down" : "Up");
                            break;
                        }
                    }
                #endif
                    input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01<<i));   
                }
                touch_num = 0;  // shield fingers
            }
        #endif
        }
    #endif
        pre_key = key_value;
    
        GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger);
    
    #if GTP_ICS_SLOT_REPORT
    
    #if GTP_WITH_PEN
        if (pre_pen && (touch_num == 0))
        {
            GTP_DEBUG("Pen touch UP(Slot)!");
            gtp_pen_up(0);
            pen_active = 1;
            pre_pen = 0;
        }
    #endif
        if (pre_touch || touch_num)
        {
            s32 pos = 0;
            u16 touch_index = 0;
            u8 report_num = 0;
            coor_data = &point_data[3];
            
            if(touch_num)
            {
                id = coor_data[pos] & 0x0F;
            
            #if GTP_WITH_PEN
                id = coor_data[pos];
                if ((id & 0x80))  
                {
                    GTP_DEBUG("Pen touch DOWN(Slot)!");
                    input_x  = coor_data[pos + 1] | (coor_data[pos + 2] << 8);
                    input_y  = coor_data[pos + 3] | (coor_data[pos + 4] << 8);
                    input_w  = coor_data[pos + 5] | (coor_data[pos + 6] << 8);
                    
                    gtp_pen_down(input_x, input_y, input_w, 0);
                    pre_pen = 1;
                    pre_touch = 0;
                    pen_active = 1;
                }    
            #endif
            
                touch_index |= (0x01<<id);
            }
            
            GTP_DEBUG("id = %d,touch_index = 0x%x, pre_touch = 0x%x\n",id, touch_index,pre_touch);
            for (i = 0; i < GTP_MAX_TOUCH; i++)
            {
            #if GTP_WITH_PEN
                if (pre_pen == 1)
                {
                    break;
                }
            #endif
            
                if ((touch_index & (0x01<<i)))
                {
                    input_x  = coor_data[pos + 1] | (coor_data[pos + 2] << 8);
                    input_y  = coor_data[pos + 3] | (coor_data[pos + 4] << 8);
                    input_w  = coor_data[pos + 5] | (coor_data[pos + 6] << 8);
    
                    gtp_touch_down(ts, id, input_x, input_y, input_w);
                    pre_touch |= 0x01 << i;
                    
                    report_num++;
                    if (report_num < touch_num)
                    {
                        pos += 8;
                        id = coor_data[pos] & 0x0F;
                        touch_index |= (0x01<<id);
                    }
                }
                else
                {
                    gtp_touch_up(ts, i);
                    pre_touch &= ~(0x01 << i);
                }
            }
        }
    #else   //end if GTP_ICS_SLOT_REPORT
    
        if (touch_num)
        {
            for (i = 0; i < touch_num; i++)
            {
                coor_data = &point_data[i * 8 + 3];
    
                id = coor_data[0] & 0x0F;
                input_x  = coor_data[1] | (coor_data[2] << 8);
                input_y  = coor_data[3] | (coor_data[4] << 8);
                input_w  = coor_data[5] | (coor_data[6] << 8);
            
            #if GTP_WITH_PEN
                id = coor_data[0];
                if (id & 0x80)
                {
                    GTP_DEBUG("Pen touch DOWN!");
                    gtp_pen_down(input_x, input_y, input_w, 0);
                    pre_pen = 1;
                    pen_active = 1;
                    break;
                }
                else
            #endif
                {
                    gtp_touch_down(ts, id, input_x, input_y, input_w);
                }
            }
        }
        else if (pre_touch)
        {
        #if GTP_WITH_PEN
            if (pre_pen == 1)
            {
                GTP_DEBUG("Pen touch UP!");
                gtp_pen_up(0);
                pre_pen = 0;
                pen_active = 1;
            }
            else
        #endif
            {
                GTP_DEBUG("Touch Release!");
                gtp_touch_up(ts, 0);
            }
        }
    
        pre_touch = touch_num;
    #endif
    
    #if GTP_WITH_PEN
        if (pen_active)
        {
            pen_active = 0;
            input_sync(ts->pen_dev);
        }
        else
    #endif
        {
            input_sync(ts->input_dev);
        }
    
    exit_work_func:
        if(!ts->gtp_rawdiff_mode)
        {
            ret = gtp_i2c_write(ts->client, end_cmd, 3);
            if (ret < 0)
            {
                GTP_INFO("I2C write end_cmd error!");
            }
        }
        if (ts->use_irq)
        {
            gtp_irq_enable(ts);
        }
    }
    
    /*******************************************************
    Function:
        Timer interrupt service routine for polling mode.
    Input:
        timer: timer struct pointer
    Output:
        Timer work mode. 
            HRTIMER_NORESTART: no restart mode
    *********************************************************/
    static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer)
    {
        struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer);
    
        GTP_DEBUG_FUNC();
    
        queue_work(goodix_wq, &ts->work);
        hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME+6)*1000000), HRTIMER_MODE_REL);
        return HRTIMER_NORESTART;
    }
    
    /*******************************************************
    Function:
        External interrupt service routine for interrupt mode.
    Input:
        irq:  interrupt number.
        dev_id: private data pointer
    Output:
        Handle Result.
            IRQ_HANDLED: interrupt handled successfully
    *********************************************************/
    static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
    {
        struct goodix_ts_data *ts = dev_id;
    
        GTP_DEBUG_FUNC();
     
        gtp_irq_disable(ts);
    
        queue_work(goodix_wq, &ts->work);
        
        return IRQ_HANDLED;
    }
    /*******************************************************
    Function:
        Synchronization.
    Input:
        ms: synchronization time in millisecond.
    Output:
        None.
    *******************************************************/
    void gtp_int_sync(s32 ms, struct goodix_ts_data *ts)
    {
        GTP_GPIO_OUTPUT(ts->irq_pin, 0);
        msleep(ms);
        //GTP_GPIO_AS_INT(GTP_INT_PORT);
        gpio_direction_input(ts->irq_pin);
        //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
        //s3c_gpio_cfgpin(pin, GTP_INT_CFG);
    }
    
    
    /*******************************************************
    Function:
        Reset chip.
    Input:
        ms: reset time in millisecond
    Output:
        None.
    *******************************************************/
    void gtp_reset_guitar(struct i2c_client *client, s32 ms)
    {
        struct goodix_ts_data *ts = i2c_get_clientdata(client);
    
        GTP_DEBUG_FUNC();
        GTP_INFO("Guitar reset");
        GTP_GPIO_OUTPUT(ts->rst_pin, 0);   // begin select I2C slave addr
        msleep(ms);                         // T2: > 10ms
        // HIGH: 0x28/0x29, LOW: 0xBA/0xBB
        GTP_GPIO_OUTPUT(ts->irq_pin, client->addr == 0x14);
    
        msleep(2);                          // T3: > 100us
        GTP_GPIO_OUTPUT(ts->rst_pin, 1);
        
        msleep(6);                          // T4: > 5ms
    
        //GTP_GPIO_AS_INPUT(GTP_RST_PORT);    // end select I2C slave addr
        gpio_direction_input(ts->rst_pin);
        //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
    
    #if GTP_COMPATIBLE_MODE
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            return;
        }
    #endif
    
        gtp_int_sync(50, ts);  
    #if GTP_ESD_PROTECT
        gtp_init_ext_watchdog(client);
    #endif
    }
    
    #if GTP_GESTURE_WAKEUP
    /*******************************************************
    Function:
        Enter doze mode for sliding wakeup.
    Input:
        ts: goodix tp private data
    Output:
        1: succeed, otherwise failed
    *******************************************************/
    static s8 gtp_enter_doze(struct goodix_ts_data *ts)
    {
        s8 ret = -1;
        s8 retry = 0;
        u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 8};
    
        GTP_DEBUG_FUNC();
    
        GTP_DEBUG("Entering gesture mode.");
        while(retry++ < 5)
        {
            i2c_control_buf[0] = 0x80;
            i2c_control_buf[1] = 0x46;
            ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
            if (ret < 0)
            {
                GTP_DEBUG("failed to set doze flag into 0x8046, %d", retry);
                continue;
            }
            i2c_control_buf[0] = 0x80;
            i2c_control_buf[1] = 0x40;
            ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
            if (ret > 0)
            {
                doze_status = DOZE_ENABLED;
                GTP_INFO("Gesture mode enabled.");
                return ret;
            }
            msleep(10);
        }
        GTP_ERROR("GTP send gesture cmd failed.");
        return ret;
    }
    #else 
    /*******************************************************
    Function:
        Enter sleep mode.
    Input:
        ts: private data.
    Output:
        Executive outcomes.
           1: succeed, otherwise failed.
    *******************************************************/
    static s8 gtp_enter_sleep(struct goodix_ts_data * ts)
    {
        s8 ret = -1;
        s8 retry = 0;
        u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5};
    #if GTP_COMPATIBLE_MODE
        u8 status_buf[3] = {0x80, 0x44};
    #endif
        
        GTP_DEBUG_FUNC();
        
    #if GTP_COMPATIBLE_MODE
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            // GT9XXF: host interact with ic
            ret = gtp_i2c_read(ts->client, status_buf, 3);
            if (ret < 0)
            {
                GTP_ERROR("failed to get backup-reference status");
            }
            
            if (status_buf[2] & 0x80)
            {
                ret = gtp_bak_ref_proc(ts, GTP_BAK_REF_STORE);
                if (FAIL == ret)
                {
                    GTP_ERROR("failed to store bak_ref");
                }
            }
        }
    #endif
    
        GTP_GPIO_OUTPUT(ts->irq_pin, 0);
        msleep(5);
        
        while(retry++ < 5)
        {
            ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);
            if (ret > 0)
            {
                GTP_INFO("GTP enter sleep!");
                
                return ret;
            }
            msleep(10);
        }
        GTP_ERROR("GTP send sleep cmd failed.");
        return ret;
    }
    #endif 
    /*******************************************************
    Function:
        Wakeup from sleep.
    Input:
        ts: private data.
    Output:
        Executive outcomes.
            >0: succeed, otherwise: failed.
    *******************************************************/
    static s8 gtp_wakeup_sleep(struct goodix_ts_data * ts)
    {
        u8 retry = 0;
        s8 ret = -1;
        
        GTP_DEBUG_FUNC();
    
    #if GTP_COMPATIBLE_MODE
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            u8 opr_buf[3] = {0x41, 0x80};
            
            GTP_GPIO_OUTPUT(ts->irq_pin, 1);
            msleep(5);
        
            for (retry = 0; retry < 10; ++retry)
            {
                // hold ss51 & dsp
                opr_buf[2] = 0x0C;
                ret = gtp_i2c_write(ts->client, opr_buf, 3);
                if (FAIL == ret)
                {
                    GTP_ERROR("failed to hold ss51 & dsp!");
                    continue;
                }
                opr_buf[2] = 0x00;
                ret = gtp_i2c_read(ts->client, opr_buf, 3);
                if (FAIL == ret)
                {
                    GTP_ERROR("failed to get ss51 & dsp status!");
                    continue;
                }
                if (0x0C != opr_buf[2])
                {
                    GTP_DEBUG("ss51 & dsp not been hold, %d", retry+1);
                    continue;
                }
                GTP_DEBUG("ss51 & dsp confirmed hold");
                
                ret = gtp_fw_startup(ts->client);
                if (FAIL == ret)
                {
                    GTP_ERROR("failed to startup GT9XXF, process recovery");
                    gtp_esd_recovery(ts->client);
                }
                break;
            }
            if (retry >= 10)
            {
                GTP_ERROR("failed to wakeup, processing esd recovery");
                gtp_esd_recovery(ts->client);
            }
            else
            {
                GTP_INFO("GT9XXF gtp wakeup success");
            }
            return ret;
        }
    #endif
    
    #if GTP_POWER_CTRL_SLEEP
        while(retry++ < 5)
        {
            gtp_reset_guitar(ts->client, 20);
            
            GTP_INFO("GTP wakeup sleep.");
            return 1;
        }
    #else
        while(retry++ < 10)
        {
        #if GTP_GESTURE_WAKEUP
            if (DOZE_WAKEUP != doze_status)  
            {
                GTP_INFO("Powerkey wakeup.");
            }
            else   
            {
                GTP_INFO("Gesture wakeup.");
            }
            doze_status = DOZE_DISABLED;
            gtp_irq_disable(ts);
            gtp_reset_guitar(ts->client, 10);
            gtp_irq_enable(ts);
            
        #else
            GTP_GPIO_OUTPUT(ts->irq_pin, 1);
            msleep(5);
        #endif
        
            ret = gtp_i2c_test(ts->client);
            if (ret > 0)
            {
                GTP_INFO("GTP wakeup sleep.");
                
            #if (!GTP_GESTURE_WAKEUP)
                {
                    gtp_int_sync(25, ts);
                #if GTP_ESD_PROTECT
                    gtp_init_ext_watchdog(ts->client);
                #endif
                }
            #endif
                
                return ret;
            }
            gtp_reset_guitar(ts->client, 20);
        }
    #endif
    
        GTP_ERROR("GTP wakeup sleep failed.");
        return ret;
    }
    #if GTP_DRIVER_SEND_CFG
    static s32 gtp_get_info(struct goodix_ts_data *ts)
    {
        u8 opr_buf[6] = {0};
        s32 ret = 0;
        
        //ts->abs_x_max = GTP_MAX_WIDTH;
        //ts->abs_y_max = GTP_MAX_HEIGHT;
    
        ts->int_trigger_type = GTP_INT_TRIGGER;
            
        opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+1) >> 8);
        opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+1) & 0xFF);
        
        ret = gtp_i2c_read(ts->client, opr_buf, 6);
        if (ret < 0)
        {
            return FAIL;
        }
        
        ts->abs_x_max = (opr_buf[3] << 8) + opr_buf[2];
        ts->abs_y_max = (opr_buf[5] << 8) + opr_buf[4];
        
        opr_buf[0] = (u8)((GTP_REG_CONFIG_DATA+6) >> 8);
        opr_buf[1] = (u8)((GTP_REG_CONFIG_DATA+6) & 0xFF);
        
        ret = gtp_i2c_read(ts->client, opr_buf, 3);
        if (ret < 0)
        {
            return FAIL;
        }
        ts->int_trigger_type = opr_buf[2] & 0x03;
        
        GTP_INFO("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",
                ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
        
        return SUCCESS;    
    }
    #endif 
    
    /*******************************************************
    Function:
        Initialize gtp.
    Input:
        ts: goodix private data
    Output:
        Executive outcomes.
            0: succeed, otherwise: failed
    *******************************************************/
    static s32 gtp_init_panel(struct goodix_ts_data *ts)
    {
        s32 ret = -1;
    #if GTP_DRIVER_SEND_CFG
        s32 i = 0;
        u8 check_sum = 0;
        u8 opr_buf[16] = {0};
        u8 sensor_id = 0;
    
        u8 cfg_info_group2[] = CTP_CFG_GROUP2;
        u8 cfg_info_group3[] = CTP_CFG_GROUP3;
        u8 cfg_info_group4[] = CTP_CFG_GROUP4;
        u8 cfg_info_group5[] = CTP_CFG_GROUP5;
        u8 cfg_info_group6[] = CTP_CFG_GROUP6;
        u8 *send_cfg_buf[] = {gtp_dat_10_1, cfg_info_group2, cfg_info_group3,
                                cfg_info_group4, cfg_info_group5, cfg_info_group6};
        u8 cfg_info_len[] = { CFG_GROUP_LEN(gtp_dat_10_1),
                                  CFG_GROUP_LEN(cfg_info_group2),
                                  CFG_GROUP_LEN(cfg_info_group3),
                                  CFG_GROUP_LEN(cfg_info_group4),
                                  CFG_GROUP_LEN(cfg_info_group5),
                                  CFG_GROUP_LEN(cfg_info_group6)};;
        
        GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
       
        if(m89or101){
    	    if (ts->cfg_file_num) {
    		    send_cfg_buf[0] = gtp_dat_8_9_1;
    		    cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_8_9_1);
    	    } else {
    		    send_cfg_buf[0] = gtp_dat_8_9;
    		    cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_8_9);
    	    }
        }
        
        if (bgt911) {
        	send_cfg_buf[0] = gtp_dat_gt11;
    		cfg_info_len[0] =  CFG_GROUP_LEN(gtp_dat_gt11);
        }
    
    	if (bgt970) {
    		send_cfg_buf[0] = gtp_dat_9_7;
    		cfg_info_len[0] = CFG_GROUP_LEN(gtp_dat_9_7);
    	}
    
    	if (bgt910) {
    		send_cfg_buf[0] = gtp_dat_7;
    		cfg_info_len[0] = CFG_GROUP_LEN(gtp_dat_7);
    	}
    
        GTP_DEBUG_FUNC();
        GTP_DEBUG("Config Groups\' Lengths: %d, %d, %d, %d, %d, %d", 
            cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], cfg_info_len[3],
            cfg_info_len[4], cfg_info_len[5]);
    
        
    #if GTP_COMPATIBLE_MODE
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            ts->fw_error = 0;
        }
        else
    #endif
        {
            ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1);
            if (SUCCESS == ret) 
            {
                if (opr_buf[0] != 0xBE)
                {
                    ts->fw_error = 1;
                    GTP_ERROR("Firmware error, no config sent!");
                    return -1;
                }
            }
        }
    
        if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && 
            (!cfg_info_len[3]) && (!cfg_info_len[4]) && 
            (!cfg_info_len[5]))
        {
            sensor_id = 0; 
        }
        else
        {
        #if GTP_COMPATIBLE_MODE
            msleep(50);
        #endif
            ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1);
            if (SUCCESS == ret)
            {
                if (sensor_id >= 0x06)
                {
                    GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id);
                    ts->pnl_init_error = 1;
                    return -1;
                }
            }
            else
            {
                GTP_ERROR("Failed to get sensor_id, No config sent!");
                ts->pnl_init_error = 1;
                return -1;
            }
            GTP_INFO("Sensor_ID: %d", sensor_id);
        }
        ts->gtp_cfg_len = cfg_info_len[sensor_id];
        GTP_INFO("CTP_CONFIG_GROUP%d used, config length: %d", sensor_id + 1, ts->gtp_cfg_len);
        
        if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH)
        {
            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);
            ts->pnl_init_error = 1;
            return -1;
        }
    
    #if GTP_COMPATIBLE_MODE
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            ts->fixed_cfg = 0;
        }
        else
    #endif
        {
            ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1);
            
            if (ret == SUCCESS)
            {
                GTP_DEBUG("CFG_GROUP%d Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X", sensor_id+1, 
                            send_cfg_buf[sensor_id][0], send_cfg_buf[sensor_id][0], opr_buf[0], opr_buf[0]);
                
                if (opr_buf[0] < 90)    
                {
                    GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
                    grp_cfg_version = send_cfg_buf[sensor_id][0];       // backup group config version
                    send_cfg_buf[sensor_id][0] = 0x00;
                    ts->fixed_cfg = 0;
                }
                else        // treated as fixed config, not send config
                {
                    GTP_INFO("Ic fixed config with config version(%d, 0x%02X)", opr_buf[0], opr_buf[0]);
                    ts->fixed_cfg = 1;
                    gtp_get_info(ts);
                    return 0;
                }
            }
            else
            {
                GTP_ERROR("Failed to get ic config version!No config sent!");
                return -1;
            }
        }
        
        memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
        memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len);
    
    #if GTP_CUSTOM_CFG
        config[RESOLUTION_LOC]     = (u8)GTP_MAX_WIDTH;
        config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);
        config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;
        config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);
        
        if (GTP_INT_TRIGGER == 0)  //RISING
        {
            config[TRIGGER_LOC] &= 0xfe; 
        }
        else if (GTP_INT_TRIGGER == 1)  //FALLING
        {
            config[TRIGGER_LOC] |= 0x01;
        }
    #endif  // GTP_CUSTOM_CFG
        
        check_sum = 0;
        for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
        {
            check_sum += config[i];
        }
        config[ts->gtp_cfg_len] = (~check_sum) + 1;
    
    #else // driver not send config
    
        ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;
        ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);
        if (ret < 0)
        {
            GTP_ERROR("Read Config Failed, Using Default Resolution & INT Trigger!");
            //ts->abs_x_max = GTP_MAX_WIDTH;
            //ts->abs_y_max = GTP_MAX_HEIGHT;
            ts->int_trigger_type = GTP_INT_TRIGGER;
        }
        
    #endif // GTP_DRIVER_SEND_CFG
    
        if ((ts->abs_x_max == 0) && (ts->abs_y_max == 0))
        {
            ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
            ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
            ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03; 
            GTP_INFO("  <%s>_%d    <%d, %d>\n", __func__, __LINE__, ts->abs_x_max, ts->abs_y_max);
        }
        GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
    #if GTP_COMPATIBLE_MODE
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            u8 sensor_num = 0;
            u8 driver_num = 0;
            u8 have_key = 0;
            
            have_key = (config[GTP_REG_HAVE_KEY - GTP_REG_CONFIG_DATA + 2] & 0x01);
            
            if (1 == ts->is_950)
            {
                driver_num = config[GTP_REG_MATRIX_DRVNUM - GTP_REG_CONFIG_DATA + 2];
                sensor_num = config[GTP_REG_MATRIX_SENNUM - GTP_REG_CONFIG_DATA + 2];
                if (have_key)
                {
                    driver_num--;
                }
                ts->bak_ref_len = (driver_num * (sensor_num - 1) + 2) * 2 * 6;
            }
            else
            {
                driver_num = (config[CFG_LOC_DRVA_NUM] & 0x1F) + (config[CFG_LOC_DRVB_NUM]&0x1F);
                if (have_key)
                {
                    driver_num--;
                }
                sensor_num = (config[CFG_LOC_SENS_NUM] & 0x0F) + ((config[CFG_LOC_SENS_NUM] >> 4) & 0x0F);
                ts->bak_ref_len = (driver_num * (sensor_num - 2) + 2) * 2;
            }
        
            GTP_INFO("Drv * Sen: %d * %d(key: %d), X_MAX: %d, Y_MAX: %d, TRIGGER: 0x%02x",
               driver_num, sensor_num, have_key, ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
            return 0;
        }
        else
    #endif
        {
        #if GTP_DRIVER_SEND_CFG
            GTP_INFO("  <%s>_%d \n", __func__, __LINE__);
            ret = gtp_send_cfg(ts->client);
            if (ret < 0)
            {
                GTP_ERROR("Send config error.");
            }
            // set config version to CTP_CFG_GROUP, for resume to send config
            config[GTP_ADDR_LENGTH] = grp_cfg_version;
            check_sum = 0;
            for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
            {
                check_sum += config[i];
            }
            config[ts->gtp_cfg_len] = (~check_sum) + 1;
        #endif
            //printk("X_MAX: %d, Y_MAX: %d, TRIGGER: 0x%02x\n", ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);
        }
        
        msleep(10);
        return 0;
    }
    
    
    static ssize_t gt91xx_config_read_proc(struct file *file, char __user *page, size_t size, loff_t *ppos)
    {
        char *ptr = page;
    	u8 temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0x80, 0x47};
        int i;
        
        if (*ppos)
        {
            return 0;
        }
        ptr += sprintf(ptr, "==== GT9XX config init value====\n");
    
        for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
        {
            ptr += sprintf(ptr, "0x%02X ", config[i + 2]);
    
            if (i % 8 == 7)
                ptr += sprintf(ptr, "\n");
        }
    
        ptr += sprintf(ptr, "\n");
    
        ptr += sprintf(ptr, "==== GT9XX config real value====\n");
        gtp_i2c_read(i2c_connect_client, temp_data, GTP_CONFIG_MAX_LENGTH + 2);
        for (i = 0 ; i < GTP_CONFIG_MAX_LENGTH ; i++)
        {
            ptr += sprintf(ptr, "0x%02X ", temp_data[i+2]);
    
            if (i % 8 == 7)
                ptr += sprintf(ptr, "\n");
        }
        *ppos += ptr - page;
        return (ptr - page);
    }
    
    static ssize_t gt91xx_config_write_proc(struct file *filp, const char __user *buffer, size_t count, loff_t *off)
    {
        s32 ret = 0;
    
        if (count > GTP_CONFIG_MAX_LENGTH)
        {
            GTP_ERROR("size not match [%d:%zu]\n", GTP_CONFIG_MAX_LENGTH, count);
            return -EFAULT;
        }
    
        if (copy_from_user(&config[2], buffer, count))
        {
            GTP_ERROR("copy from user fail\n");
            return -EFAULT;
        }
    
        ret = gtp_send_cfg(i2c_connect_client);
    
        if (ret < 0)
        {
            GTP_ERROR("send config failed.");
        }
    
        return count;
    }
    /*******************************************************
    Function:
        Read chip version.
    Input:
        client:  i2c device
        version: buffer to keep ic firmware version
    Output:
        read operation return.
            2: succeed, otherwise: failed
    *******************************************************/
    s32 gtp_read_version(struct i2c_client *client, u16* version)
    {
        s32 ret = -1;
        u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};
    
        GTP_DEBUG_FUNC();
    
        ret = gtp_i2c_read(client, buf, sizeof(buf));
        if (ret < 0)
        {
            GTP_ERROR("GTP read version failed");
            return ret;
        }
    
        if (version)
        {
            *version = (buf[7] << 8) | buf[6];
        }
        if (buf[5] == 0x00)
        {
            GTP_INFO("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);
        }
        else
        {
            GTP_INFO("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
        }
        return ret;
    }
    
    /*******************************************************
    Function:
        I2c test Function.
    Input:
        client:i2c client.
    Output:
        Executive outcomes.
            2: succeed, otherwise failed.
    *******************************************************/
    static s8 gtp_i2c_test(struct i2c_client *client)
    {
        u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};
        u8 retry = 0;
        s8 ret = -1;
      
        GTP_DEBUG_FUNC();
      
        while(retry++ < 5)
        {
            ret = gtp_i2c_read(client, test, 3);
            if (ret > 0)
            {
                return ret;
            }
            GTP_ERROR("GTP i2c test failed time %d.",retry);
            msleep(10);
        }
        return ret;
    }
    
    /*******************************************************
    Function:
        Request gpio(INT & RST) ports.
    Input:
        ts: private data.
    Output:
        Executive outcomes.
            >= 0: succeed, < 0: failed
    *******************************************************/
    static s8 gtp_request_io_port(struct goodix_ts_data *ts)
    {
        s32 ret = 0;
    
        GTP_DEBUG_FUNC();
    /*
        ret = GTP_GPIO_REQUEST(ts->tp_select_pin, "GTP_tp_select_PORT");
        if (ret < 0) 
        {
            GTP_ERROR("1Failed to request GPIO:%d, ERRNO:%d",(s32)ts->tp_select_pin, ret);
            return -ENODEV;
        }
        else
        {
        	gpio_direction_input(ts->tp_select_pin);
        }
    */
        ret = GTP_GPIO_REQUEST(ts->rst_pin, "GTP_RST_PORT");
        if (ret < 0) 
        {
            GTP_ERROR("2Failed to request GPIO:%d, ERRNO:%d",(s32)ts->rst_pin, ret);
    		GTP_GPIO_FREE(ts->rst_pin);
            return -ENODEV;
        }
        
        ret = GTP_GPIO_REQUEST(ts->irq_pin, "GTP_INT_IRQ");
        if (ret < 0) 
        {
            GTP_ERROR("3Failed to request GPIO:%d, ERRNO:%d", (s32)ts->irq_pin, ret);
    		GTP_GPIO_FREE(ts->irq_pin);
            return -ENODEV;
        }
        else
        {
            //GTP_GPIO_AS_INT(GTP_INT_PORT);  
            gpio_direction_input(ts->irq_pin);
            //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
            //s3c_gpio_cfgpin(pin, GTP_INT_CFG);
            
            //ts->client->irq = ts->irq_pin;
        }
    
        //GTP_GPIO_AS_INPUT(ts->rst_pin);
        gpio_direction_input(ts->rst_pin);
        //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
    
        gtp_reset_guitar(ts->client, 20);
    
        return ret;
    }
    
    /*******************************************************
    Function:
        Request interrupt.
    Input:
        ts: private data.
    Output:
        Executive outcomes.
            0: succeed, -1: failed.
    *******************************************************/
    static s8 gtp_request_irq(struct goodix_ts_data *ts)
    {
        s32 ret = -1;
    
        GTP_DEBUG_FUNC();
        GTP_DEBUG("INT trigger type:%x", ts->int_trigger_type);
        
        ts->irq=gpio_to_irq(ts->irq_pin);       //If not defined in client
        if (ts->irq)
        {
            ts->client->irq = ts->irq;
            ret = devm_request_threaded_irq(&(ts->client->dev), ts->irq, NULL, 
                goodix_ts_irq_handler, ts->irq_flags | IRQF_ONESHOT /*irq_table[ts->int_trigger_type]*/, 
                ts->client->name, ts);
            if (ret != 0) {
                GTP_ERROR("Cannot allocate ts INT!ERRNO:%d\n", ret);
                goto test_pit;
            }
            //gtp_irq_disable(ts->irq);
            GTP_INFO("  <%s>_%d     ts->irq=%d   ret = %d\n", __func__, __LINE__, ts->irq, ret);
        }else{
            GTP_ERROR("   ts->irq  error \n");
            ret = 1;
            goto test_pit;
        }
    /*
        ret  = request_irq(ts->client->irq, 
                           goodix_ts_irq_handler,
                           irq_table[ts->int_trigger_type],
                           ts->client->name,
                           ts);
    */                       
    test_pit:
        if (ret)
        {
            GTP_ERROR("Request IRQ failed!ERRNO:%d.", ret);
            //GTP_GPIO_AS_INPUT(GTP_INT_PORT);
            gpio_direction_input(ts->irq_pin);
            //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
            
            GTP_GPIO_FREE(ts->irq_pin);
    
            hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
            ts->timer.function = goodix_ts_timer_handler;
            hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
            return -1;
        }
        else 
        {
            GTP_INFO("  <%s>_%d     ts->irq=%d   ret = %d\n", __func__, __LINE__, ts->irq, ret);
            gtp_irq_disable(ts);
            ts->use_irq = 1;
            return 0;
        }
    }
    
    /*******************************************************
    Function:
        Early suspend function.
    Input:
        h: early_suspend struct.
    Output:
        None.
    *******************************************************/
    static int goodix_ts_early_suspend(struct tp_device *tp_d)
    {
        struct goodix_ts_data *ts;
        s8 ret = -1;
        int reg = 0;
    
        ts = container_of(tp_d, struct goodix_ts_data, tp);
        GTP_DEBUG_FUNC();
    
        GTP_INFO("System suspend.");
    
        ts->gtp_is_suspend = 1;
    #if GTP_ESD_PROTECT
        gtp_esd_switch(ts->client, SWITCH_OFF);
    #endif
    
    #if GTP_GESTURE_WAKEUP
        ret = gtp_enter_doze(ts);
    #else
        if (ts->use_irq)
        {
            gtp_irq_disable(ts);
        }
        else
        {
            hrtimer_cancel(&ts->timer);
        }
        ret = gtp_enter_sleep(ts);
    #endif
        if (ret < 0)
        {
            printk("GTP early suspend failed.");
        }
        // to avoid waking up while not sleeping
        //  delay 48 + 10ms to ensure reliability
        msleep(58);
    
    	reg = regulator_disable(ts->tp_regulator);
    	if (reg < 0)
    		GTP_ERROR("failed to disable tp regulator\n");
    	msleep(20);
    	return 0;
    }
    
    /*******************************************************
    Function:
        Late resume function.
    Input:
        h: early_suspend struct.
    Output:
        None.
    *******************************************************/
    static int goodix_ts_early_resume(struct tp_device *tp_d)
    {
        struct goodix_ts_data *ts;
        s8 ret = -1;
        int reg = 0;
        ts = container_of(tp_d, struct goodix_ts_data, tp);
        GTP_DEBUG_FUNC();
    
        GTP_INFO("System resume.");
    
    	reg = regulator_enable(ts->tp_regulator);
    	if (reg < 0)
    		GTP_ERROR("failed to enable tp regulator\n");
    	msleep(10);
    
        ret = gtp_wakeup_sleep(ts);
    
    #if GTP_GESTURE_WAKEUP
        doze_status = DOZE_DISABLED;
    #endif
    
        if (ret < 0)
        {
            GTP_ERROR("GTP later resume failed.");
        }
    #if (GTP_COMPATIBLE_MODE)
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            // do nothing
        }
        else
    #endif
        {
            gtp_send_cfg(ts->client);
        }
    
        if (ts->use_irq)
        {
            gtp_irq_enable(ts);
        }
        else
        {
            hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
        }
    
        ts->gtp_is_suspend = 0;
    #if GTP_ESD_PROTECT
        gtp_esd_switch(ts->client, SWITCH_ON);
    #endif
    
    	return 0;
    }
    
    /*******************************************************
    Function:
        Request input device Function.
    Input:
        ts:private data.
    Output:
        Executive outcomes.
            0: succeed, otherwise: failed.
    *******************************************************/
    static s8 gtp_request_input_dev(struct i2c_client *client,
                                    struct goodix_ts_data *ts)
    {
        s8 ret = -1;
        s8 phys[32];
    #if GTP_HAVE_TOUCH_KEY
        u8 index = 0;
    #endif
        GTP_DEBUG_FUNC();
      
        ts->input_dev = devm_input_allocate_device(&client->dev);
        if (ts->input_dev == NULL)
        {
            GTP_ERROR("Failed to allocate input device.");
            return -ENOMEM;
        }
    
        ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;
    #if GTP_ICS_SLOT_REPORT
        input_mt_init_slots(ts->input_dev, 16, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);     // in case of "out of memory"
    #else
        ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
    #endif
        __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
    
    #if GTP_HAVE_TOUCH_KEY
        for (index = 0; index < GTP_MAX_KEY_NUM; index++)
        {
            input_set_capability(ts->input_dev, EV_KEY, touch_key_array[index]);  
        }
    #endif
    
    #if GTP_GESTURE_WAKEUP
        input_set_capability(ts->input_dev, EV_KEY, KEY_POWER);
    #endif 
    
    	if (gtp_change_x2y)
    		GTP_SWAP(ts->abs_x_max, ts->abs_y_max);
    
    #if defined(CONFIG_CHROME_PLATFORMS)
        input_set_abs_params(ts->input_dev, ABS_X, 0, ts->abs_x_max, 0, 0);
        input_set_abs_params(ts->input_dev, ABS_Y, 0, ts->abs_y_max, 0, 0);
    #endif
        input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);
        input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);
        input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
        input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
        input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);
    
        sprintf(phys, "input/ts");
        ts->input_dev->name = goodix_ts_name;
        ts->input_dev->phys = phys;
        ts->input_dev->id.bustype = BUS_I2C;
        ts->input_dev->id.vendor = 0xDEAD;
        ts->input_dev->id.product = 0xBEEF;
        ts->input_dev->id.version = 10427;
        
        ret = input_register_device(ts->input_dev);
        if (ret)
        {
            GTP_ERROR("Register %s input device failed", ts->input_dev->name);
            return -ENODEV;
        }
        
        ts->tp.tp_resume = goodix_ts_early_resume;
        ts->tp.tp_suspend = goodix_ts_early_suspend;
        tp_register_fb(&ts->tp);
    
    #if GTP_WITH_PEN
        gtp_pen_init(ts);
    #endif
    
        return 0;
    }
    
    //************** For GT9XXF Start *************//
    #if GTP_COMPATIBLE_MODE
    
    s32 gtp_fw_startup(struct i2c_client *client)
    {
        u8 opr_buf[4];
        s32 ret = 0;
        struct goodix_ts_data *ts = i2c_get_clientdata(client);
        //init sw WDT
    	opr_buf[0] = 0xAA;
    	ret = i2c_write_bytes(client, 0x8041, opr_buf, 1);
        if (ret < 0)
        {
            return FAIL;
        }
        
        //release SS51 & DSP
        opr_buf[0] = 0x00;
        ret = i2c_write_bytes(client, 0x4180, opr_buf, 1);
        if (ret < 0)
        {
            return FAIL;
        }
        //int sync
        gtp_int_sync(25, ts);  
        
        //check fw run status
        ret = i2c_read_bytes(client, 0x8041, opr_buf, 1);
        if (ret < 0)
        {
            return FAIL;
        }
        if(0xAA == opr_buf[0])
        {
            GTP_ERROR("IC works abnormally,startup failed.");
            return FAIL;
        }
        else
        {
            GTP_INFO("IC works normally, Startup success.");
            opr_buf[0] = 0xAA;
            i2c_write_bytes(client, 0x8041, opr_buf, 1);
            return SUCCESS;
        }
    }
    
    static s32 gtp_esd_recovery(struct i2c_client *client)
    {
        s32 retry = 0;
        s32 ret = 0;
        struct goodix_ts_data *ts;
        
        ts = i2c_get_clientdata(client);
        
        gtp_irq_disable(ts);
        
        GTP_INFO("GT9XXF esd recovery mode");
        for (retry = 0; retry < 5; retry++)
        {
            ret = gup_fw_download_proc(NULL, GTP_FL_ESD_RECOVERY); 
            if (FAIL == ret)
            {
                GTP_ERROR("esd recovery failed %d", retry+1);
                continue;
            }
            ret = gtp_fw_startup(ts->client);
            if (FAIL == ret)
            {
                GTP_ERROR("GT9XXF start up failed %d", retry+1);
                continue;
            }
            break;
        }
        gtp_irq_enable(ts);
        
        if (retry >= 5)
        {
            GTP_ERROR("failed to esd recovery");
            return FAIL;
        }
        
        GTP_INFO("Esd recovery successful");
        return SUCCESS;
    }
    
    void gtp_recovery_reset(struct i2c_client *client)
    {
    #if GTP_ESD_PROTECT
        gtp_esd_switch(client, SWITCH_OFF);
    #endif
        GTP_DEBUG_FUNC();
        
        gtp_esd_recovery(client); 
        
    #if GTP_ESD_PROTECT
        gtp_esd_switch(client, SWITCH_ON);
    #endif
    }
    
    static s32 gtp_bak_ref_proc(struct goodix_ts_data *ts, u8 mode)
    {
        s32 ret = 0;
        s32 i = 0;
        s32 j = 0;
        u16 ref_sum = 0;
        u16 learn_cnt = 0;
        u16 chksum = 0;
        s32 ref_seg_len = 0;
        s32 ref_grps = 0;
        struct file *ref_filp = NULL;
        u8 *p_bak_ref;
        
        ret = gup_check_fs_mounted("/data");
        if (FAIL == ret)
        {
            ts->ref_chk_fs_times++;
            GTP_DEBUG("Ref check /data times/MAX_TIMES: %d / %d", ts->ref_chk_fs_times, GTP_CHK_FS_MNT_MAX);
            if (ts->ref_chk_fs_times < GTP_CHK_FS_MNT_MAX)
            {
                msleep(50);
                GTP_INFO("/data not mounted.");
                return FAIL;
            }
            GTP_INFO("check /data mount timeout...");
        }
        else
        {
            GTP_INFO("/data mounted!!!(%d/%d)", ts->ref_chk_fs_times, GTP_CHK_FS_MNT_MAX);
        }
        
    	p_bak_ref = kzalloc(ts->bak_ref_len, GFP_KERNEL);
        
        if (NULL == p_bak_ref)
        {
            GTP_ERROR("Allocate memory for p_bak_ref failed!");
            return FAIL;
        }
        
        if (ts->is_950)
        {
            ref_seg_len = ts->bak_ref_len / 6;
            ref_grps = 6;
        }
        else
        {
            ref_seg_len = ts->bak_ref_len;
            ref_grps = 1;
        }
        ref_filp = filp_open(GTP_BAK_REF_PATH, O_RDWR | O_CREAT, 0666);
        if (IS_ERR(ref_filp))
        { 
            GTP_ERROR("Failed to open/create %s.", GTP_BAK_REF_PATH);
            if (GTP_BAK_REF_SEND == mode)
            {
                goto bak_ref_default;
            }
            else
            {
                goto bak_ref_exit;
            }
        }
        
        switch (mode)
        {
        case GTP_BAK_REF_SEND:
            GTP_INFO("Send backup-reference");
            ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
            ret = ref_filp->f_op->read(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
            if (ret < 0)
            {
                GTP_ERROR("failed to read bak_ref info from file, sending defualt bak_ref");
                goto bak_ref_default;
            }
            for (j = 0; j < ref_grps; ++j)
            {
                ref_sum = 0;
                for (i = 0; i < (ref_seg_len); i += 2)
                {
                    ref_sum += (p_bak_ref[i + j * ref_seg_len] << 8) + p_bak_ref[i+1 + j * ref_seg_len];
                }
                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]);
                chksum = (p_bak_ref[j * ref_seg_len + ref_seg_len -2] << 8) + (p_bak_ref[j * ref_seg_len + ref_seg_len -1]);
                GTP_DEBUG("learn count = %d", learn_cnt);
                GTP_DEBUG("chksum = %d", chksum);
                GTP_DEBUG("ref_sum = 0x%04X", ref_sum & 0xFFFF);
                // Sum(1~ref_seg_len) == 1
                if (1 != ref_sum)
                {
                    GTP_INFO("wrong chksum for bak_ref, reset to 0x00 bak_ref");
                    memset(&p_bak_ref[j * ref_seg_len], 0, ref_seg_len);
                    p_bak_ref[ref_seg_len + j * ref_seg_len - 1] = 0x01;
                }
                else
                {
                    if (j == (ref_grps - 1))
                    {
                        GTP_INFO("backup-reference data in %s used", GTP_BAK_REF_PATH);
                    }
                }
            }
            ret = i2c_write_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
            if (FAIL == ret)
            {
                GTP_ERROR("failed to send bak_ref because of iic comm error");
                goto bak_ref_exit;
            }
            break;
            
        case GTP_BAK_REF_STORE:
            GTP_INFO("Store backup-reference");
            ret = i2c_read_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
            if (ret < 0)
            {
                GTP_ERROR("failed to read bak_ref info, sending default back-reference");
                goto bak_ref_default;
            }
            ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
            ref_filp->f_op->write(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
            break;
            
        default:
            GTP_ERROR("invalid backup-reference request");
            break;
        }
        ret = SUCCESS;
        goto bak_ref_exit;
    
    bak_ref_default:
        
        for (j = 0; j < ref_grps; ++j)
        {
            memset(&p_bak_ref[j * ref_seg_len], 0, ref_seg_len);
            p_bak_ref[j * ref_seg_len + ref_seg_len - 1] = 0x01;  // checksum = 1     
        }
        ret = i2c_write_bytes(ts->client, GTP_REG_BAK_REF, p_bak_ref, ts->bak_ref_len);
        if (!IS_ERR(ref_filp))
        {
            GTP_INFO("write backup-reference data into %s", GTP_BAK_REF_PATH);
            ref_filp->f_op->llseek(ref_filp, 0, SEEK_SET);
            ref_filp->f_op->write(ref_filp, (char*)p_bak_ref, ts->bak_ref_len, &ref_filp->f_pos);
        }
        if (ret == FAIL)
        {
            GTP_ERROR("failed to load the default backup reference");
        }
        
    bak_ref_exit:
        
        if (p_bak_ref)
        {
            kfree(p_bak_ref);
        }
        if (ref_filp && !IS_ERR(ref_filp))
        {
            filp_close(ref_filp, NULL);
        }
        return ret;
    }
    
    
    static s32 gtp_verify_main_clk(u8 *p_main_clk)
    {
        u8 chksum = 0;
        u8 main_clock = p_main_clk[0];
        s32 i = 0;
        
        if (main_clock < 50 || main_clock > 120)    
        {
            return FAIL;
        }
        
        for (i = 0; i < 5; ++i)
        {
            if (main_clock != p_main_clk[i])
            {
                return FAIL;
            }
            chksum += p_main_clk[i];
        }
        chksum += p_main_clk[5];
        if ( (chksum) == 0)
        {
            return SUCCESS;
        }
        else
        {
            return FAIL;
        }
    }
    
    static s32 gtp_main_clk_proc(struct goodix_ts_data *ts)
    {
    	s32 ret = 0;
    	s32 i = 0;
    	s32 clk_chksum = 0;
    	struct file *clk_filp = NULL;
    
    	#if GTP_USE_FIXED_CLK
    	u8 p_main_clk[6] = {69, 69, 69, 69, 69, 167};
    	#else
    	u8 p_main_clk[6] = {0};
    	#endif
    
    	#if GTP_USE_FIXED_CLK
    	/*
    	 * here check kernel /data is not same as android /data,
    	 * so modify it to reduce fw download
    	 */
    	ret = gtp_verify_main_clk(p_main_clk);
    	if (ret == FAIL) {
    		GTP_ERROR("main clock data verify error");
    	} else {
    		GTP_INFO("main clock data used fix freq: %d", p_main_clk[0]);
    		goto update_main_clk;
    	}
    	#else
        ret = gup_check_fs_mounted("/data");
        if (FAIL == ret)
        {
            ts->clk_chk_fs_times++;
            GTP_DEBUG("Clock check /data times/MAX_TIMES: %d / %d", ts->clk_chk_fs_times, GTP_CHK_FS_MNT_MAX);
            if (ts->clk_chk_fs_times < GTP_CHK_FS_MNT_MAX)
            {
                msleep(50);
                GTP_INFO("/data not mounted.");
                return FAIL;
            }
            GTP_INFO("Check /data mount timeout!");
        }
        else
        {
            GTP_INFO("/data mounted!!!(%d/%d)", ts->clk_chk_fs_times, GTP_CHK_FS_MNT_MAX);
        }
        
        clk_filp = filp_open(GTP_MAIN_CLK_PATH, O_RDWR | O_CREAT, 0666);
        if (IS_ERR(clk_filp))
        {
            GTP_ERROR("%s is unavailable, calculate main clock", GTP_MAIN_CLK_PATH);
        }
        else
        {
            clk_filp->f_op->llseek(clk_filp, 0, SEEK_SET);
            clk_filp->f_op->read(clk_filp, (char *)p_main_clk, 6, &clk_filp->f_pos);
           
            ret = gtp_verify_main_clk(p_main_clk);
            if (FAIL == ret)
            {
                // recalculate main clock & rewrite main clock data to file
                GTP_ERROR("main clock data in %s is wrong, recalculate main clock", GTP_MAIN_CLK_PATH);
            }
            else
            { 
                GTP_INFO("main clock data in %s used, main clock freq: %d", GTP_MAIN_CLK_PATH, p_main_clk[0]);
                filp_close(clk_filp, NULL);
                goto update_main_clk;
            }
        }
    	#endif
        
    #if GTP_ESD_PROTECT
        gtp_esd_switch(ts->client, SWITCH_OFF);
    #endif
        ret = gup_clk_calibration();
        gtp_esd_recovery(ts->client);
        
    #if GTP_ESD_PROTECT
        gtp_esd_switch(ts->client, SWITCH_ON);
    #endif
    
        GTP_INFO("calibrate main clock: %d", ret);
        if (ret < 50 || ret > 120)
        {
            GTP_ERROR("wrong main clock: %d", ret);
            goto exit_main_clk;
        }
        
        // Sum{0x8020~0x8025} = 0
        for (i = 0; i < 5; ++i)
        {
            p_main_clk[i] = ret;
            clk_chksum += p_main_clk[i];
        }
        p_main_clk[5] = 0 - clk_chksum;
        
        if (!IS_ERR(clk_filp))
        {
            GTP_DEBUG("write main clock data into %s", GTP_MAIN_CLK_PATH);
            clk_filp->f_op->llseek(clk_filp, 0, SEEK_SET);
            clk_filp->f_op->write(clk_filp, (char *)p_main_clk, 6, &clk_filp->f_pos);
            filp_close(clk_filp, NULL);
        }
        
    update_main_clk:
        ret = i2c_write_bytes(ts->client, GTP_REG_MAIN_CLK, p_main_clk, 6);
        if (FAIL == ret)
        {
            GTP_ERROR("update main clock failed!");
            return FAIL;
        }
        return SUCCESS;
        
    exit_main_clk:
        if (!IS_ERR(clk_filp))
        {
            filp_close(clk_filp, NULL);
        }
        return FAIL;
    }
    
    
    s32 gtp_gt9xxf_init(struct i2c_client *client)
    {
        s32 ret = 0;
        
        ret = gup_fw_download_proc(NULL, GTP_FL_FW_BURN); 
        if (FAIL == ret)
        {
            return FAIL;
        }
        
        ret = gtp_fw_startup(client);
        if (FAIL == ret)
        {
            return FAIL;
        }
        return SUCCESS;
    }
    
    void gtp_get_chip_type(struct goodix_ts_data *ts)
    {
        u8 opr_buf[10] = {0x00};
        s32 ret = 0;
        
        msleep(10);
        
        ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CHIP_TYPE, opr_buf, 10);
        
        if (FAIL == ret)
        {
            GTP_ERROR("Failed to get chip-type, set chip type default: GOODIX_GT9");
            ts->chip_type = CHIP_TYPE_GT9;
            return;
        }
        
        if (!memcmp(opr_buf, "GOODIX_GT9", 10))
        {
            ts->chip_type = CHIP_TYPE_GT9;
        }
        else // GT9XXF
        {
            ts->chip_type = CHIP_TYPE_GT9F;
        }
        GTP_INFO("Chip Type: %s", (ts->chip_type == CHIP_TYPE_GT9) ? "GOODIX_GT9" : "GOODIX_GT9F");
    }
    
    #endif
    //************* For GT9XXF End ************//
    
    /*******************************************************
    Function:
        I2c probe.
    Input:
        client: i2c device struct.
        id: device id.
    Output:
        Executive outcomes. 
            0: succeed.
    *******************************************************/
    static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
    {
        s32 ret = -1;
        struct goodix_ts_data *ts;
        u16 version_info;
        
        struct device_node *np = client->dev.of_node;
        enum of_gpio_flags rst_flags, pwr_flags;
        u32 val;
    	printk("%s() start\n", __func__);
    
        
        GTP_DEBUG_FUNC();
        
        //do NOT remove these logs
        GTP_INFO("GTP Driver Version: %s", GTP_DRIVER_VERSION);
        GTP_INFO("GTP I2C Address: 0x%02x", client->addr);
    
        i2c_connect_client = client;
        
        if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 
        {
            GTP_ERROR("I2C check functionality failed.");
            return -ENODEV;
        }
        ts = kzalloc(sizeof(*ts), GFP_KERNEL);
        if (ts == NULL)
        {
            GTP_ERROR("Alloc GFP_KERNEL memory failed.");
            return -ENOMEM;
        }
        
        memset(ts, 0, sizeof(*ts));
        
        if (!np) {
        	dev_err(&client->dev, "no device tree\n");
        	return -EINVAL;
        }
        if (of_property_read_u32(np, "tp-size", &val)) {
        	dev_err(&client->dev, "no max-x defined\n");
        	return -EINVAL;
        }
    
    	if (val == 89) {
    		m89or101 = TRUE;
    		gtp_change_x2y = TRUE;
    		gtp_x_reverse = FALSE;
    		gtp_y_reverse = TRUE;
    	} else if (val == 101) {
    		m89or101 = FALSE;
    		gtp_change_x2y = TRUE;
    		gtp_x_reverse = TRUE;
    		gtp_y_reverse = TRUE;
    	} else if (val == 911) {
    		m89or101 = FALSE;
    		bgt911 = TRUE;
    		gtp_change_x2y = TRUE;
    		gtp_x_reverse = FALSE;
    		gtp_y_reverse = FALSE;
    	} else if (val == 970) {
    		m89or101 = FALSE;
    		bgt911 = FALSE;
    		bgt970 = TRUE;
    		gtp_change_x2y = FALSE;
    		gtp_x_reverse = FALSE;
    		gtp_y_reverse = FALSE;
    	} else if (val == 910) {
    		m89or101 = FALSE;
    		bgt911 = FALSE;
    		bgt970 = FALSE;
    		bgt910 = TRUE;
    		gtp_change_x2y = TRUE;
    		gtp_x_reverse = FALSE;
    		gtp_y_reverse = TRUE;
    	}
    
    	ts->tp_regulator = devm_regulator_get(&client->dev, "tp");
    	if (IS_ERR(ts->tp_regulator)) {
    		dev_err(&client->dev, "failed to get regulator, %ld\n",
    			PTR_ERR(ts->tp_regulator));
    		return PTR_ERR(ts->tp_regulator);
    	}
    
    	ret = regulator_enable(ts->tp_regulator);
    	if (ret < 0)
    		GTP_ERROR("failed to enable tp regulator\n");
    	msleep(20);
    
        ts->irq_pin = of_get_named_gpio_flags(np, "touch-gpio", 0, (enum of_gpio_flags *)(&ts->irq_flags));
        ts->rst_pin = of_get_named_gpio_flags(np, "reset-gpio", 0, &rst_flags);
        ts->pwr_pin = of_get_named_gpio_flags(np, "power-gpio", 0, &pwr_flags);
        //ts->tp_select_pin = of_get_named_gpio_flags(np, "tp-select-gpio", 0, &tp_select_flags);
        if (of_property_read_u32(np, "max-x", &val)) {
        	dev_err(&client->dev, "no max-x defined\n");
        	return -EINVAL;
        }
        //ts->abs_x_max = val;
        if (of_property_read_u32(np, "max-y", &val)) {
        	dev_err(&client->dev, "no max-y defined\n");
        	return -EINVAL;
        }
        //ts->abs_y_max = val;
        if (of_property_read_u32(np, "configfile-num", &val)) {
    	    ts->cfg_file_num = 0;
        } else {
    	    ts->cfg_file_num = val;
        }
        ts->pendown =PEN_RELEASE;
        ts->client = client;
        
        
        INIT_WORK(&ts->work, goodix_ts_work_func);
        ts->client = client;
        spin_lock_init(&ts->irq_lock);          // 2.6.39 later
        // ts->irq_lock = SPIN_LOCK_UNLOCKED;   // 2.6.39 & before
    #if GTP_ESD_PROTECT
        ts->clk_tick_cnt = 2 * HZ;      // HZ: clock ticks in 1 second generated by system
        GTP_DEBUG("Clock ticks for an esd cycle: %d", ts->clk_tick_cnt);  
        spin_lock_init(&ts->esd_lock);
        // ts->esd_lock = SPIN_LOCK_UNLOCKED;
    #endif
    
        i2c_set_clientdata(client, ts);
        
        ts->gtp_rawdiff_mode = 0;
    
        ret = gtp_request_io_port(ts);
        if (ret < 0)
        {
            GTP_ERROR("GTP request IO port failed.");
            //return ret;
            goto probe_init_error_requireio;
        }
    /*
        if(gpio_get_value(ts->tp_select_pin))//WGJ
        {
        	printk("tp 11111111111111111111111111111 WGJ\n\n");
    		gtp_x_reverse = FALSE;
    		gtp_y_reverse = TRUE;
        }
        else//DPT
        {
        	printk("tp 00000000000000000000000000000 DPT\n\n");
    		gtp_x_reverse = TRUE;//FALSE;
    		gtp_y_reverse = TRUE;
        }
     */
    #if GTP_COMPATIBLE_MODE
        gtp_get_chip_type(ts);
        
        if (CHIP_TYPE_GT9F == ts->chip_type)
        {
            ret = gtp_gt9xxf_init(ts->client);
            if (FAIL == ret)
            {
                GTP_INFO("Failed to init GT9XXF.");
            }
        }
    #endif
    
        ret = gtp_i2c_test(client);
        if (ret < 0)
        {
            printk("<%s>_%d    I2C communication ERROR!\n", __func__, __LINE__);
            goto probe_init_error;
        }
    
        ret = gtp_read_version(client, &version_info);
        if (ret < 0)
        {
            GTP_ERROR("Read version failed.");
        }
        
        ret = gtp_init_panel(ts);
        if (ret < 0)
        {
            GTP_ERROR("GTP init panel failed.");
            //ts->abs_x_max = GTP_MAX_WIDTH;
            //ts->abs_y_max = GTP_MAX_HEIGHT;
            ts->int_trigger_type = GTP_INT_TRIGGER;
        }
        
        // Create proc file system
    	gt91xx_config_proc = proc_create(GT91XX_CONFIG_PROC_FILE, 0664, NULL, &config_proc_ops);
        if (gt91xx_config_proc == NULL)
        {
            GTP_ERROR("create_proc_entry %s failed\n", GT91XX_CONFIG_PROC_FILE);
        }
        else
        {
            GTP_INFO("create proc entry %s success", GT91XX_CONFIG_PROC_FILE);
        }
        
    #if GTP_AUTO_UPDATE
        ret = gup_init_update_proc(ts);
        if (ret < 0)
        {
            GTP_ERROR("Create update thread error.");
        }
    #endif
    
        ret = gtp_request_input_dev(client, ts);
        if (ret < 0)
        {
            GTP_ERROR("GTP request input dev failed");
        }
        ret = gtp_request_irq(ts); 
        if (ret < 0)
        {
            GTP_INFO("GTP works in polling mode.");
        }
        else
        {
            GTP_INFO("GTP works in interrupt mode.");
        }
    
        if (ts->use_irq)
        {
            gtp_irq_enable(ts);
        }
        
    #if GTP_CREATE_WR_NODE
        init_wr_node(client);
    #endif
       
    #if GTP_ESD_PROTECT
        gtp_esd_switch(client, SWITCH_ON);
    #endif
        return 0;
    
    probe_init_error:
        printk("   <%s>_%d  prob error !!!!!!!!!!!!!!!\n", __func__, __LINE__);    
        tp_unregister_fb(&ts->tp);
        GTP_GPIO_FREE(ts->rst_pin);
        GTP_GPIO_FREE(ts->irq_pin);
    probe_init_error_requireio:
        tp_unregister_fb(&ts->tp); 
        kfree(ts);
        return ret;
    }
    
    
    /*******************************************************
    Function:
        Goodix touchscreen driver release function.
    Input:
        client: i2c device struct.
    Output:
        Executive outcomes. 0---succeed.
    *******************************************************/
    static int goodix_ts_remove(struct i2c_client *client)
    {
        struct goodix_ts_data *ts = i2c_get_clientdata(client);
        
        tp_unregister_fb(&ts->tp);
    
        GTP_DEBUG_FUNC();
    
    #if GTP_CREATE_WR_NODE
        uninit_wr_node();
    #endif
    
    #if GTP_ESD_PROTECT
        destroy_workqueue(gtp_esd_check_workqueue);
    #endif
    
        if (ts) 
        {
            if (ts->use_irq)
            {
                //GTP_GPIO_AS_INPUT(GTP_INT_PORT);
                
                gpio_direction_input(ts->irq_pin);
                //s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
                
                GTP_GPIO_FREE(ts->irq_pin);
                free_irq(client->irq, ts);
            }
            else
            {
                hrtimer_cancel(&ts->timer);
            }
    		GTP_INFO("GTP driver removing...");
    		i2c_set_clientdata(client, NULL);
    		input_unregister_device(ts->input_dev);
    		kfree(ts);
    	}
    
        return 0;
    }
    
    
    
    
    
    #if GTP_ESD_PROTECT
    s32 gtp_i2c_read_no_rst(struct i2c_client *client, u8 *buf, s32 len)
    {
        struct i2c_msg msgs[2];
        s32 ret=-1;
        s32 retries = 0;
    
        GTP_DEBUG_FUNC();
    
        msgs[0].flags = !I2C_M_RD;
        msgs[0].addr  = client->addr;
        msgs[0].len   = GTP_ADDR_LENGTH;
        msgs[0].buf   = &buf[0];
        //msgs[0].scl_rate = 300 * 1000;    // for Rockchip, etc.
        
        msgs[1].flags = I2C_M_RD;
        msgs[1].addr  = client->addr;
        msgs[1].len   = len - GTP_ADDR_LENGTH;
        msgs[1].buf   = &buf[GTP_ADDR_LENGTH];
        //msgs[1].scl_rate = 300 * 1000;
    
        while(retries < 5)
        {
            ret = i2c_transfer(client->adapter, msgs, 2);
            if(ret == 2)break;
            retries++;
        }
        if ((retries >= 5))
        {    
            GTP_ERROR("I2C Read: 0x%04X, %d bytes failed, errcode: %d!", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
        }
        return ret;
    }
    
    s32 gtp_i2c_write_no_rst(struct i2c_client *client,u8 *buf,s32 len)
    {
        struct i2c_msg msg;
        s32 ret = -1;
        s32 retries = 0;
    
        GTP_DEBUG_FUNC();
    
        msg.flags = !I2C_M_RD;
        msg.addr  = client->addr;
        msg.len   = len;
        msg.buf   = buf;
        //msg.scl_rate = 300 * 1000;    // for Rockchip, etc
    
        while(retries < 5)
        {
            ret = i2c_transfer(client->adapter, &msg, 1);
            if (ret == 1)break;
            retries++;
        }
        if((retries >= 5))
        {
            GTP_ERROR("I2C Write: 0x%04X, %d bytes failed, errcode: %d!", (((u16)(buf[0] << 8)) | buf[1]), len-2, ret);
        }
        return ret;
    }
    /*******************************************************
    Function:
        switch on & off esd delayed work
    Input:
        client:  i2c device
        on:      SWITCH_ON / SWITCH_OFF
    Output:
        void
    *********************************************************/
    void gtp_esd_switch(struct i2c_client *client, s32 on)
    {
        struct goodix_ts_data *ts;
        
        ts = i2c_get_clientdata(client);
        spin_lock(&ts->esd_lock);
        
        if (SWITCH_ON == on)     // switch on esd 
        {
            if (!ts->esd_running)
            {
                ts->esd_running = 1;
                spin_unlock(&ts->esd_lock);
                GTP_INFO("Esd started");
                queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, ts->clk_tick_cnt);
            }
            else
            {
                spin_unlock(&ts->esd_lock);
            }
        }
        else    // switch off esd
        {
            if (ts->esd_running)
            {
                ts->esd_running = 0;
                spin_unlock(&ts->esd_lock);
                GTP_INFO("Esd cancelled");
                cancel_delayed_work_sync(&gtp_esd_check_work);
            }
            else
            {
                spin_unlock(&ts->esd_lock);
            }
        }
    }
    
    /*******************************************************
    Function:
        Initialize external watchdog for esd protect
    Input:
        client:  i2c device.
    Output:
        result of i2c write operation. 
            1: succeed, otherwise: failed
    *********************************************************/
    static s32 gtp_init_ext_watchdog(struct i2c_client *client)
    {
        u8 opr_buffer[3] = {0x80, 0x41, 0xAA};
        GTP_DEBUG("[Esd]Init external watchdog");
        return gtp_i2c_write_no_rst(client, opr_buffer, 3);
    }
    
    /*******************************************************
    Function:
        Esd protect function.
        External watchdog added by meta, 2013/03/07
    Input:
        work: delayed work
    Output:
        None.
    *******************************************************/
    static void gtp_esd_check_func(struct work_struct *work)
    {
        s32 i;
        s32 ret = -1;
        struct goodix_ts_data *ts = NULL;
        u8 esd_buf[5] = {0x80, 0x40};
        
        GTP_DEBUG_FUNC();
       
        ts = i2c_get_clientdata(i2c_connect_client);
    
        if (ts->gtp_is_suspend)
        {
            GTP_INFO("Esd suspended!");
            return;
        }
        
        for (i = 0; i < 3; i++)
        {
            ret = gtp_i2c_read_no_rst(ts->client, esd_buf, 4);
            
            GTP_DEBUG("[Esd]0x8040 = 0x%02X, 0x8041 = 0x%02X", esd_buf[2], esd_buf[3]);
            if ((ret < 0))
            {
                // IIC communication problem
                continue;
            }
            else
            { 
                if ((esd_buf[2] == 0xAA) || (esd_buf[3] != 0xAA))
                {
                    // IC works abnormally..
                    u8 chk_buf[4] = {0x80, 0x40};
                    
                    gtp_i2c_read_no_rst(ts->client, chk_buf, 4);
                    
                    GTP_DEBUG("[Check]0x8040 = 0x%02X, 0x8041 = 0x%02X", chk_buf[2], chk_buf[3]);
                    
                    if ((chk_buf[2] == 0xAA) || (chk_buf[3] != 0xAA))
                    {
                        i = 3;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                else 
                {
                    // IC works normally, Write 0x8040 0xAA, feed the dog
                    esd_buf[2] = 0xAA; 
                    gtp_i2c_write_no_rst(ts->client, esd_buf, 3);
                    break;
                }
            }
        }
        if (i >= 3)
        {
        #if GTP_COMPATIBLE_MODE
            if (CHIP_TYPE_GT9F == ts->chip_type)
            {        
                if (ts->rqst_processing)
                {
                    GTP_INFO("Request processing, no esd recovery");
                }
                else
                {
                    GTP_ERROR("IC working abnormally! Process esd recovery.");
                    esd_buf[0] = 0x42;
                    esd_buf[1] = 0x26;
                    esd_buf[2] = 0x01;
                    esd_buf[3] = 0x01;
                    esd_buf[4] = 0x01;
                    gtp_i2c_write_no_rst(ts->client, esd_buf, 5);
                    msleep(50);
                    gtp_esd_recovery(ts->client);
                }
            }
            else
        #endif
            {
                GTP_ERROR("IC working abnormally! Process reset guitar.");
                esd_buf[0] = 0x42;
                esd_buf[1] = 0x26;
                esd_buf[2] = 0x01;
                esd_buf[3] = 0x01;
                esd_buf[4] = 0x01;
                gtp_i2c_write_no_rst(ts->client, esd_buf, 5);
                msleep(50);
                gtp_reset_guitar(ts->client, 50);
                msleep(50);
                gtp_send_cfg(ts->client);
            }
        }
    
        if(!ts->gtp_is_suspend)
        {
            queue_delayed_work(gtp_esd_check_workqueue, &gtp_esd_check_work, ts->clk_tick_cnt);
        }
        else
        {
            GTP_INFO("Esd suspended!");
        }
        return;
    }
    #endif
    
    static const struct i2c_device_id goodix_ts_id[] = {
        { GTP_I2C_NAME, 0 },
        { }
    };
    
    static struct of_device_id goodix_ts_dt_ids[] = {
        { .compatible = "goodix,gt9xx" },
        { }
    };
    
    static struct i2c_driver goodix_ts_driver = {
        .probe      = goodix_ts_probe,
        .remove     = goodix_ts_remove,
        .id_table   = goodix_ts_id,
        .driver = {
            .name     = GTP_I2C_NAME,
    	 .of_match_table = of_match_ptr(goodix_ts_dt_ids),
        },
    };
    
    /*******************************************************    
    Function:
        Driver Install function.
    Input:
        None.
    Output:
        Executive Outcomes. 0---succeed.
    ********************************************************/
    static int goodix_ts_init(void)
    {
        s32 ret;
    
        GTP_DEBUG_FUNC();   
        GTP_INFO("GTP driver installing...");
        goodix_wq = create_singlethread_workqueue("goodix_wq");
        if (!goodix_wq)
        {
            GTP_ERROR("Creat workqueue failed.");
            return -ENOMEM;
        }
    #if GTP_ESD_PROTECT
        INIT_DELAYED_WORK(&gtp_esd_check_work, gtp_esd_check_func);
        gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
    #endif
        ret = i2c_add_driver(&goodix_ts_driver);
        return ret; 
    }
    
    /*******************************************************    
    Function:
        Driver uninstall function.
    Input:
        None.
    Output:
        Executive Outcomes. 0---succeed.
    ********************************************************/
    static void goodix_ts_exit(void)
    {
        GTP_DEBUG_FUNC();
        GTP_INFO("GTP driver exited.");
        i2c_del_driver(&goodix_ts_driver);
        if (goodix_wq)
        {
            destroy_workqueue(goodix_wq);
        }
    }
    //late_initcall(goodix_ts_init);
    module_init(goodix_ts_init);
    
    module_exit(goodix_ts_exit);
    
    MODULE_DESCRIPTION("GTP Series Driver");
    MODULE_LICENSE("GPL");
    

    开机打印log

    [    1.463610] goodix_ts_probe() start
    [    1.571710] usb 2-1: new high-speed USB device number 2 using ehci-platform
    [    1.615445] input: goodix-ts as /devices/platform/ff190000.i2c/i2c-1/1-005d/input/input2
    [    1.616221] rk3x-i2c ff190000.i2c: Initialized RK3xxx I2C bus at ffffff800959c000
    
     - [ ] List item
    
    [    1.617528] rk3x-i2c ff1a0000.i2c: Initialized RK3xxx I2C bus at ffffff800959e000
    
    展开全文
  • MTK平台tp触摸屏驱动分析

    千次阅读 2016-08-24 14:57:03
    转自... 本博文将讲解基于Goodix触控芯片的tp驱动程序。如有不足之处,敬请指出。 初始化 static int __init tpd_driver_init(void) { GTP_INFO("MediaTek gt91xx touch panel driver init\n


    转自http://m.blog.csdn.net/article/details?id=51362009

    本博文将讲解基于Goodix触控芯片的tp驱动程序。如有不足之处,敬请指出。

    初始化

    static int __init tpd_driver_init(void)
    {
        GTP_INFO("MediaTek gt91xx touch panel driver init\n");
    #if defined(TPD_I2C_NUMBER) 
        i2c_register_board_info(TPD_I2C_NUMBER, &i2c_tpd, 1);
    #else
        i2c_register_board_info(0, &i2c_tpd, 1);
    #endif
        if (tpd_driver_add(&tpd_device_driver) < 0)
            GTP_INFO("add generic driver failed\n");
    
        return 0;
    }



    tpd_driver_init中主要做了两件事情:


    1、注册一个i2c设备



    i2c_register_board_info在 kernel\drivers\i2c\i2c-boardinfo.c 中定义。


    对应的函数说明如下:

    i2c_register_board_info - statically declare I2C devices 
    * @busnum: identifies the bus to which these devices belong 
    * @info: vector of i2c device descriptors 
    * @len: how many descriptors in the vector; may be zero to reserve 
    * the specified bus number.

    因此我们可知道: 

    TPD_I2C_NUMBER表示的是当前注册的i2c设备是在哪个总线上面,需要查看硬件连接图; 


    i2c_tpd表示的是该i2c设备的描述,包括设备名”gt9xx”和i2c的设备地址“(0xBA >> 1)”

    static struct i2c_board_info __initdata i2c_tpd = { I2C_BOARD_INFO("gt9xx", (0xBA >> 1))};
    • 1

    2、添加一个驱动到静态数组tpd_driver_list数组中


    if (tpd_driver_add(&tpd_device_driver) < 0)
            GTP_INFO("add generic driver failed\n");
    • 1
    • 2


    其中tpd_device_driver的定义为:

    static struct tpd_driver_t tpd_device_driver =
    {
        .tpd_device_name = "gt9xx",
        .tpd_local_init = tpd_local_init,
        .suspend = tpd_suspend,
        .resume = tpd_resume,
    #ifdef TPD_HAVE_BUTTON
        .tpd_have_button = 1,
    #else
        .tpd_have_button = 0,
    #endif
    };


    这几个选项都是必须的。

    其中的tpd_device_name不能为”generic”,那样的话就会识别为R-Touch(推测此处表示为电阻屏),被保存到tpd_driver_li

    st[0]中。否则为C-Touch(推测此处表示为电容屏),保存到tpd_driver_list的非0位置处。在TP驱动中要自己实现这几个函数的所有

    内容。

    tpd_local_init()

    static int tpd_local_init(void)
    {
    #if GTP_ESD_PROTECT
        clk_tick_cnt = 2 * HZ;   // HZ: clock ticks in 1 second generated by system
        GTP_DEBUG("Clock ticks for an esd cycle: %d", clk_tick_cnt);
        INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func);
        gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");
        spin_lock_init(&esd_lock);          // 2.6.39 & later
        // esd_lock = SPIN_LOCK_UNLOCKED;   // 2.6.39 & before
    #endif
    
    #if GTP_SUPPORT_I2C_DMA
        tpd->dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
        gpDMABuf_va = (u8 *)dma_alloc_coherent(&tpd->dev->dev, GTP_DMA_MAX_TRANSACTION_LENGTH, &gpDMABuf_pa, GFP_KERNEL);
        if(!gpDMABuf_va)
        {
            GTP_INFO("[Error] Allocate DMA I2C Buffer failed!\n");
        }
        memset(gpDMABuf_va, 0, GTP_DMA_MAX_TRANSACTION_LENGTH);
    #endif
        if (i2c_add_driver(&tpd_i2c_driver) != 0)
        {
            GTP_INFO("unable to add i2c driver.\n");
            return -1;
        }
    
        if (tpd_load_status == 0) //if(tpd_load_status == 0) // disable auto load touch driver for linux3.0 porting
        {
            GTP_INFO("add error touch panel driver.\n");
            i2c_del_driver(&tpd_i2c_driver);
            return -1;
        }
        input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, (GTP_MAX_TOUCH-1), 0, 0);
    
    #ifdef TPD_HAVE_BUTTON
         if (FACTORY_BOOT == get_boot_mode()|| RECOVERY_BOOT == get_boot_mode())  // cty 2014-08-14
         {
            tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local_factory, tpd_keys_dim_local);// initialize tpd button data
         }
         else
         {
            tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data
        }
    #endif
    
    #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
        TPD_DO_WARP = 1;
        memcpy(tpd_wb_start, tpd_wb_start_local, TPD_WARP_CNT * 4);
        memcpy(tpd_wb_end, tpd_wb_start_local, TPD_WARP_CNT * 4);
    #endif
    
    #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
        memcpy(tpd_calmat, tpd_def_calmat_local, 8 * 4);
        memcpy(tpd_def_calmat, tpd_def_calmat_local, 8 * 4);
    #endif
    
        // set vendor string
        tpd->dev->id.vendor = 0x00;
        tpd->dev->id.product = tpd_info.pid;
        tpd->dev->id.version = tpd_info.vid;
    
        GTP_INFO("end %s, %d\n", __FUNCTION__, __LINE__);
        tpd_type_cap = 1;
    
        return 0;
    }


    该函数主要做以下几项工作:

    1、GTP_ESD_PROTECT

    为ESD防护机制。

    2、GTP_SUPPORT_I2C_DMA

    主要是申请I2C DMA的空间,由gpDMABuf_va指向。

     
    tpd->dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);表示这个设备能寻址的物理地址的范

    围为DMA_BIT_MASK(32),这个值相当于0xffffffffUL。关于这个成员的解释可以参见 linux下platform_device中的dma_mask与co

    herent_dma_mask。 接下来的dma_alloc_coherent()申请DMA空间。返回值为gpDMABuf_va表示虚拟地址,以及返回gp

    DMABuf_pa表示DMA实际物理地址。至于这两个怎么用还不是很懂。详见:Dynamic DMA mapping using the generic device


    3、注册i2c设备驱动

    if (i2c_add_driver(&tpd_i2c_driver) != 0)
    {
        GTP_INFO("unable to add i2c driver.\n");
        return -1;
    }
    if (tpd_load_status == 0) //if(tpd_load_status == 0) // disable auto load touch driver for linux3.0 porting
    {
        GTP_INFO("add error touch panel driver.\n");
        i2c_del_driver(&tpd_i2c_driver);
        return -1;
    }

    probe探测到总线上的设备并把设备和驱动建立连接以完成设备的初始化。这个中间会调用tpd_i2c_driver中的tpd_i2c_probe()来完成初始化工作。

    static struct i2c_driver tpd_i2c_driver =
    {
        .probe = tpd_i2c_probe,
        .remove = tpd_i2c_remove,
        .detect = tpd_i2c_detect,
        .driver.name = "b_gt9xx_hotknot",
        .id_table = tpd_i2c_id,
        .address_list = (const unsigned short *) forces,
    };


    这里面的内容都要自己去实现,特别是tpd_i2c_probe()。如果tpd_i2c_probe()中初始化设备全部完成,则要置位全局变量t

    pd_load_status为1标记成功初始化,否则的话匹配失败需要调用i2c_del_driver()删除已注册的驱动。

    4、设置input设备tpd->dev支持的最大手指触摸个数


    input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, (GTP_MAX_TOUCH-1), 0, 0);
    • 1


    input设备tpd->dev的申请以及定义和初始化的内容都在mtk_tpd.c这个文件中的tpd_probe()函数实现了。推测之所以没有一起初始化的ABS_MT_TRACKING_ID的内容是因为每个触控IC的原厂软件实现最大的触摸个数都不太一样,所以这里需要根据情况自己设定。

    5、按键的初始化


    #ifdef TPD_HAVE_BUTTON
    if (FACTORY_BOOT == get_boot_mode()|| RECOVERY_BOOT == get_boot_mode())  // cty 2014-08-14
    {
       tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local_factory, tpd_keys_dim_local);// initialize tpd button data
    }
    else
    {
       tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data
    }
    #endif


    tpd_button_setting()函数的内容非常简单,就是将数组tpd_keys_local[TPD_KEY_COUNT]t

    pd_keys_dim_local[TPD_KEY_COUNT][4]拷贝给tpd_keystpd_keys_dim。这两个变量

    用于tpd_button_init()的初始化创建virtual keys。数组内容要根据TP的分辨率来确定按键的位置。需要根据不同分辨率来确定按键的个数、按键名

    称、按键的坐标范围。

    #define TPD_KEY_COUNT   3
    #define TPD_KEYS        { KEY_BACK, KEY_HOMEPAGE,KEY_MENU}
    #define TPD_KEYS_FACTORY    {KEY_BACK , KEY_HOME,KEY_MENU}
    #define TPD_KEYS_DIM            {{100,1500,50,30},{270,1500,50,30},{450,1500,50,30}}
    
    #ifdef TPD_HAVE_BUTTON
    static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS;
    static int tpd_keys_local_factory[TPD_KEY_COUNT] = TPD_KEYS_FACTORY;
    static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM;
    #endif


    tp button也是和其它触摸事件一样,以坐标形式的input_event进行上报。在初始化时会通过tpd_button_setting()函数根据定义在tpd_custom_XXX.h文件中的配置信息将虚拟按键的坐标信息写在/sys/board_properties/virtualkeys.mtk-tpd中。工作时,tp driver将按下的点的坐标进行上报,Android上层会读取sys中的按键配置信息,再判断上报的坐标是否属于某个按键的坐标范围,以此将坐标信息转化为具体的按键键值。 详见android 虚拟按键是通过哪种机制上报的?

    MTK虚拟按键的实现在tpd_button.c中实现,具体内容详见Android tp的虚拟按键(virtual key)处理

    6、设置input设备tpd->dev的信息

    // set vendor string
    tpd->dev->id.vendor = 0x00;
    tpd->dev->id.product = tpd_info.pid;
    tpd->dev->id.version = tpd_info.vid;


    其中tpd_info的信息是在tpd_i2c_probe()中调用gtp_read_version()获取到的。

    7、设置TP类型为电容屏


    tpd_type_cap = 1;
    • 1

    从变量字面上的意思来看是设置标记TP为电容屏,至于还有何作用还不得而知。

    tpd_i2c_probe()

    static s32 tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
    {
        s32 err = 0;
        s32 ret = 0;
        u16 version_info;
        #if GTP_HAVE_TOUCH_KEY
        s32 idx = 0;
        #endif
    
        #ifdef TPD_PROXIMITY
        struct hwmsen_object obj_ps;
        #endif
    
        i2c_client_point = client;
        ret = tpd_power_on(client);
    
        if (ret < 0)
        {
            GTP_ERROR("I2C communication ERROR!");
            goto out;
        }
    
        #ifdef VELOCITY_CUSTOM
        tpd_v_magnify_x = TPD_VELOCITY_CUSTOM_X;
        tpd_v_magnify_y = TPD_VELOCITY_CUSTOM_Y;
        #endif
    
        ret = gtp_read_version(client, &version_info);
    
        if (ret < 0)
        {
            GTP_ERROR("Read version failed.");
            goto out;
        }    
    
        ret = gtp_init_panel(client);
    
        if (ret < 0)
        {
            GTP_ERROR("GTP init panel failed.");
            //goto out;
        }
    
        // Create proc file system
        gt91xx_config_proc = proc_create(GT91XX_CONFIG_PROC_FILE, 0660, NULL, >_upgrade_proc_fops);
        if (gt91xx_config_proc == NULL)
        {
            GTP_ERROR("create_proc_entry %s failed\n", GT91XX_CONFIG_PROC_FILE);
            goto out;
        }
    
    
        #if GTP_CREATE_WR_NODE
        init_wr_node(client);
        #endif
    
        thread = kthread_run(touch_event_handler, 0, TPD_DEVICE);
    
        if (IS_ERR(thread))
        {
            err = PTR_ERR(thread);
            GTP_INFO(TPD_DEVICE " failed to create kernel thread: %d\n", err);
            goto out;
        }
    
    
        #if GTP_HAVE_TOUCH_KEY
        for (idx = 0; idx < GTP_MAX_KEY_NUM; idx++)
        {
            input_set_capability(tpd->dev, EV_KEY, touch_key_array[idx]);
        }
        #endif
    
        #if GTP_GESTURE_WAKEUP
        //input_set_capability(tpd->dev, EV_KEY, KEY_POWER);
        #endif
    
        #if GTP_WITH_PEN
        // pen support
        __set_bit(BTN_TOOL_PEN, tpd->dev->keybit);
        __set_bit(INPUT_PROP_DIRECT, tpd->dev->propbit);
        //__set_bit(INPUT_PROP_POINTER, tpd->dev->propbit); // 20130722
        #endif
    
        // set INT mode
        mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_EINT);
        mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN);
        mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_DISABLE);
    
        msleep(50);
    
        mt_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM, 0);
    
        if (!int_type)  //EINTF_TRIGGER
        {
            mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_RISING, tpd_eint_interrupt_handler, 1);
        }
        else
        {
            mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_FALLING, tpd_eint_interrupt_handler, 1);
        }
    
        mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
    
    
        #if GTP_AUTO_UPDATE
        ret = gup_init_update_proc(client);
    
        if (ret < 0)
        {
            GTP_ERROR("Create update thread error.");
        }
        #endif
    
        #ifdef TPD_PROXIMITY
        //obj_ps.self = cm3623_obj;
        obj_ps.polling = 0;         //0--interrupt mode;1--polling mode;
        obj_ps.sensor_operate = tpd_ps_operate;
    
        if ((err = hwmsen_attach(ID_PROXIMITY, &obj_ps)))
        {
            GTP_ERROR("hwmsen attach fail, return:%d.", err);
        }
    
        #endif
    
        #if GTP_ESD_PROTECT
        gtp_esd_switch(client, SWITCH_ON);
        #endif
    
        tpd_load_status = 1;
    
        return 0;
    out:
        return -1;
    }


    一般来说,TP驱动probe()函数中一般会做以下几个工作:

    1、TPD_PROXIMITY

    在多数情况下,通话的时候,脸部靠近会自动息屏,脸部拿开会自动亮屏,这个功能主要由接近传感器Proximity Sensor(简称PS)实现。但是有时候在方案设计中,为了省下一颗光感,往往要求触控ic支持此功能。当TP感应上半部分有多数差值到达门限,就会认定脸部靠近,会置对应的标记为在某个寄存器中,驱动中读取该标记位判断是否亮屏或者暗屏。

    所有与接近感应功能对应的code使用宏TPD_PROXIMITY进行控制: 
    (1)、创建 hwsen 对象以及实现其内容

    #ifdef TPD_PROXIMITY
       struct hwmsen_object obj_ps;
    #endif
    
    #ifdef TPD_PROXIMITY
       //obj_ps.self = cm3623_obj;
       obj_ps.polling = 0;         //0--interrupt mode;1--polling mode;
       obj_ps.sensor_operate = tpd_ps_operate;
    
       if ((err = hwmsen_attach(ID_PROXIMITY, &obj_ps)))
       {
           GTP_ERROR("hwmsen attach fail, return:%d.", err);
       }
    
    #endif

    MTK代码里使用了一个hwmsensor模块控制所有的sensor。 
    代码路径:mediatek/kernel/drivers/hwmon/hwmsen/hwmsen_dev.c,编译成hwmsen_dev.o,系统起来后会生成/dev/hwmsensor设备。 使用sensor_operate()接口管理所有sensor驱动,向上提供hwmsen_unlocked_ioctl()接口,再往下就是具体的sensor驱动代码了,根据MTK的驱动结构完成senor_operate()接口并调用hwmsen_dev.c里的hwmsen_attach()函数,把sensor_operate()接口加到hwmsen_dev的列表里,这样hwmsen_dev里就能调用所有sensor的sensor_operate()函数。 
    详见Android Sensor学习这篇文章。

    obj_ps.polling = 0;
    • 1

    标记此sensor工作在中断模式下而不是轮询方式,通过中断上报数据。

    obj_ps.sensor_operate = tpd_ps_operate; 
    • 1

    主要实现获取通话时候的状态信息并根据此状态信息判断是否上报接近或者远离动作。

    hwmsen_attach(ID_PROXIMITY, &obj_ps)
    • 1

    这是将接近感应传感器设备驱动添加到 hwmsen device 中。 


    (2)、实现tpd_ps_operate()内容 


    创建两个全局变量:

    #ifdef TPD_PROXIMITY
    static s32 tpd_get_ps_value(void)
    {
        return tpd_proximity_detect;
    }
    
    // 判断是否打开接近感应功能
    static s32 tpd_enable_ps(s32 enable)
    {
        u8  state;
        s32 ret = -1;
    
        if (enable)
        {
            state = 1;
            tpd_proximity_flag = 1;
            GTP_INFO("TPD proximity function to be on.");
        }
        else
        {
            state = 0;
            tpd_proximity_flag = 0;
            GTP_INFO("TPD proximity function to be off.");
        }
    
        ret = i2c_write_bytes(i2c_client_point, TPD_PROXIMITY_ENABLE_REG, &state, 1);
    
        if (ret < 0)
        {
            GTP_ERROR("TPD %s proximity cmd failed.", state ? "enable" : "disable");
            return ret;
        }
    
        GTP_INFO("TPD proximity function %s success.", state ? "enable" : "disable");
        return 0;
    }
    
    s32 tpd_ps_operate(void *self, u32 command, void *buff_in, s32 size_in,void *buff_out, s32 size_out, s32 *actualout)
    {
        s32 err = 0;
        s32 value;
        hwm_sensor_data *sensor_data;
    
        switch (command)
        {
            case SENSOR_DELAY:
                if ((buff_in == NULL) || (size_in < sizeof(int)))
                {
                    GTP_ERROR("Set delay parameter error!");
                    err = -EINVAL;
                }
    
                // Do nothing
                break;
    
            case SENSOR_ENABLE:
                if ((buff_in == NULL) || (size_in < sizeof(int)))
                {
                    GTP_ERROR("Enable sensor parameter error!");
                    err = -EINVAL;
                }
                else
                {
                    value = *(int *)buff_in;
                    err = tpd_enable_ps(value);  // 获取是否在通话的状态并赋值给tpd_proximity_flag 
                }
    
                break;
    
            case SENSOR_GET_DATA:
                if ((buff_out == NULL) || (size_out < sizeof(hwm_sensor_data)))
                {
                    GTP_ERROR("Get sensor data parameter error!");
                    err = -EINVAL;
                }
                else
                {
                    sensor_data = (hwm_sensor_data *)buff_out;
                    sensor_data->values[0] = tpd_get_ps_value();  // 将检测到的接近或者远离的状态tpd_proximity_detect发送出去
                    sensor_data->value_divide = 1;
                    sensor_data->status = SENSOR_STATUS_ACCURACY_MEDIUM;
                }
                break;
    
            default:
                GTP_ERROR("proxmy sensor operate function no this parameter %d!\n", command);
                err = -1;
                break;
        }
    
        return err;
    }
    #endif



    当通话的时候,会调用tpd_ps_operate()进入case SENSOR_ENABLE:将通话的标记作为参数传给tpd_enabl

    e_ps(value),这个函数很简单,就是赋值给变量tpd_proximity_flag该变量标记此时是否需要打开接近感应功能。如果需要

    打开接近感应功能,需往ic对应的寄存器写入某个对应的值。当检测到接近全局变量tpd_proximity_detect会置为0;当检测到远离,tpd

    _proximity_detect会置为1。


    case SENSOR_GET_DATA:中会上报检测到的接近或者远离的状态(tpd_proximity_detect为0或者为1)。不过在

    中断的内核进程中touch_event_handler()也有一段同样的code。不知道是走哪个流程的。

    #ifdef TPD_PROXIMITY
        if (tpd_proximity_flag == 1)
        {
            proximity_status = point_data[GTP_ADDR_LENGTH];
            GTP_DEBUG("REG INDEX[0x814E]:0x%02X\n", proximity_status);
    
            if (proximity_status & 0x60)  //proximity or large touch detect,enable hwm_sensor.
            {
                tpd_proximity_detect = 0;
                //sensor_data.values[0] = 0;
            }
            else
            {
                tpd_proximity_detect = 1;
                //sensor_data.values[0] = 1;
            }
    
            //get raw data
            GTP_DEBUG(" ps change\n");
            GTP_DEBUG("PROXIMITY STATUS:0x%02X\n", tpd_proximity_detect);
            //map and store data to hwm_sensor_data
            sensor_data.values[0] = tpd_get_ps_value();
            sensor_data.value_divide = 1;
            sensor_data.status = SENSOR_STATUS_ACCURACY_MEDIUM;
            //report to the up-layer
            ret = hwmsen_get_interrupt_data(ID_PROXIMITY, &sensor_data); // 通过中断的方式将接近或者远离的状态上报给 PROXIMITY sensor
    
            if (ret)
            {
                GTP_ERROR("Call hwmsen_get_interrupt_data fail = %d\n", err);
            }
        }
    #endif


    注意,如果是检测到在通话中且脸部接近的动作的时候,此时应该要屏蔽上报坐标的功能。

    (3)、亮屏、暗屏 
    暗屏和亮屏的动作也会调用tpd_suspend()tpd_resume()。一般suspend的时候ic要进入休眠模式且关闭中断刷新工作队列等工作。

    在resume的时候要唤醒ic,使能中断以及其他工作。如果是由于通话中接近或者远离导致suspend或者resume都不必做这些工作,只需要直接返回。因为此时要求ic还要能够

    正常工作。

    2、tpd_power_on()

    在这个函数里面,主要做了三件事:

    1、给ic上电

    #ifdef MT6573
        // power on CTP
        mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO);
        mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT);
        mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ONE);
    
    #else   // ( defined(MT6575) || defined(MT6577) || defined(MT6589) )
    
        #ifdef TPD_POWER_SOURCE_CUSTOM
            hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_2800, "TP");
        #else
            hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_2800, "TP");
        #endif
        #ifdef TPD_POWER_SOURCE_1800
            hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP");
        #endif
    
    #endif


    关于上电的动作可参考MTK Android Driver:PMIC

    2、复位ic

    void gtp_reset_guitar(struct i2c_client *client, s32 ms)
    {
        GTP_INFO("GTP RESET!\n");
        GTP_GPIO_OUTPUT(GTP_RST_PORT, 0);
        msleep(ms);
        GTP_GPIO_OUTPUT(GTP_INT_PORT, client->addr == 0x14);
    
        msleep(2);
        GTP_GPIO_OUTPUT(GTP_RST_PORT, 1);
    
        msleep(6);                      //must >= 6ms
    
    #if GTP_COMPATIBLE_MODE
        if (CHIP_TYPE_GT9F == gtp_chip_type)
        {
            return;
        }
    #endif
    
        gtp_int_sync(100);  // for dbl-system
    #if GTP_ESD_PROTECT
        gtp_init_ext_watchdog(i2c_client_point);
    #endif
    }


    复位ic就是讲ic上的RST脚设为输出拉低再拉高。MTK的tp驱动程序需要涉及对ic三个引脚的操作:EN(使能或VDD脚)、RST(复位脚)、EINT(外部中断脚)。这三个引脚对应的宏固定为:

    GPIO_CTP_EN_PIN
    GPIO_CTP_RST_PIN
    GPIO_CTP_EINT_PIN
    • 1
    • 2
    • 3

    这几个宏在以下路径中的文件进行配置对应的GPIO口 
    alps\mediatek\dct\DrvGen.exe 
    alps\mediatek\custom\project\kernel\dct\dct\codegen.dws 配置

    3、测试I2C是否通

    static s8 gtp_i2c_test(struct i2c_client *client);
    • 1

    测试i2c是否通信成功,需要用到i2c的读写接口,至于接口函数怎么写,可以参照这篇文章待定

    3、初始化ic

    接下来就是通过i2c读写接口初始化ic了。

    s32 gtp_read_version(struct i2c_client *client, u16 *version);
    static s32 gtp_init_panel(struct i2c_client *client);
    • 1
    • 2

    至于初始化的内容会放到一个全局的数组之中,这项工作一般都要FAE来完成。

    4、创建内核线程

    thread = kthread_run(touch_event_handler, 0, TPD_DEVICE);
    
    if (IS_ERR(thread))
    {
        err = PTR_ERR(thread);
        GTP_INFO(TPD_DEVICE " failed to create kernel thread: %d\n", err);
        goto out;
    }


    创建名为TPD_DEVICE线程thread是为了处理中断来临之后读取坐标、上报坐标、手势识别、按键等等信息。判断thread是否有效需要用

    IS_ERR()来判断,而不是简单的使用(thread == NULL)判断,详见Linux内核多线程(一)

    其主要内容如下:

    static int touch_event_handler(void *unused)
    {
        struct sched_param param = { .sched_priority = RTPM_PRIO_TPD };
    
        sched_setscheduler(current, SCHED_RR, ¶m); // 调度策略和调度参数分别设置为param指向的sched_param结构中指定的policy和参数
        do
        {
            set_current_state(TASK_INTERRUPTIBLE); // 设置当前线程可被打断
            if(tpd_eint_mode)  // 标记采用轮询方式还是中断方式,此处为中断方式
            {
                wait_event_interruptible(waiter, tpd_flag != 0); // 此处等待waiter被唤醒,只有当tpd_flag不为1且wake_up waite才会去执行。可知这两个条件都在中断服务子程序去置位了
                tpd_flag = 0; // 判断是否有中断的标记
            }
            else
            {
                msleep(tpd_polling_time);
            }       
            set_current_state(TASK_RUNNING);// 标记当前线程正执行
            mutex_lock(&i2c_access);
    
            // 此处添加你的工作
    
            mutex_unlock(&i2c_access);
    
        } while (!kthread_should_stop());
    
    return 0;
    }

    • 28


    对于wait_event_interruptible()可以参照wait_event_interruptible 使用方法 


    写这个内容好着急啊,很多知识点都没有很深入的了解,只能参照网上说的来进行解释。

    5、申请中断服务子程序

    // set INT mode
    mt_set_gpio_mode(GPIO_CTP_EINT_PIN,GPIO_CTP_EINT_PIN_M_EINT);
    mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN);
    mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN,GPIO_PULL_DISABLE);
    
    msleep(50);
    
    mt_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM, 0);
    
    if (!int_type)  //EINTF_TRIGGER
    {
        mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_RISING, tpd_eint_interrupt_handler, 1);
    }
    else
    {
        mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, EINTF_TRIGGER_FALLING, tpd_eint_interrupt_handler, 1);
    }
    
    mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); // 关闭中断使能,probe完毕之后会打开中断使能


    CUST_EINT_TOUCH_PANEL_NUM为分配给触摸ic的中断号,在alps\mediatek\custom\project\kernel\dct\dct\cust_eint.h 中定义; 


    设置中断的触发方式 为上升沿或者下降沿(需要根据ic的功能设置);GPIO的相关功能可参照MTK6577+Android之GPIO驱动简介 


    设置中断服务子程序static void tpd_eint_interrupt_handler(void) 


    这个函数的内容很简单,就是置位tpd_flag变量和wake_up waiter.

    static void tpd_eint_interrupt_handler(void)
    {
        TPD_DEBUG_PRINT_INT;
    
        tpd_flag = 1;
    
        wake_up_interruptible(&waiter);
    }



    至此,tpd_i2c_probe()的所有内容都已实现,接下来就是等待ic给中断然后读取坐标等信息了。

    tpd_down()和tpd_up()

    这两个函数通过input子系统上报坐标以及上报手指抬起的动作。关于input子系统,我根据自己的理解写了待定

    tpd_suspend()和tpd_resume()

    关于休眠和唤醒的内容根据ic的特性设置。如休眠的时候需要关闭中断、配置进入休眠模式。唤醒的时候唤醒ic,使能中断等。

    展开全文
  • TP 相关引脚DTS中的定义 我们这个项目TP复位引脚是GPIO158,中断引脚是GPIO1,由下图原理图知道我们的TP挂载在I2c0上,3.3v的供电电压是有PMIC 2.8V供电电压通过i2c电平转换过来的,所以供电电压需要配置pmic 2.8v ...

    TP 相关引脚DTS中的定义
    我们这个项目TP复位引脚是GPIO158,中断引脚是GPIO1,由下图原理图知道我们的TP挂载在I2c0上,3.3v的供电电压是有PMIC 2.8V供电电压通过i2c电平转换过来的,所以供电电压需要配置pmic 2.8v

    在这里插入图片描述

     

    /* TOUCH start */
    &touch {
        tpd-resolution = <800 1280>;//分辨率
        use-tpd-button = <0>;//如果TP有待按键。则定义值为1
        tpd-key-num = <3>;//按键的数量
        tpd-key-local= <139 172 158 0>;//按键的编码,一般为KEY_MENU,KEY_HOMEPAGE,KEY_BACK的键值
        tpd-key-dim-local = <90 883 100 40 230 883 100 40 370 883 100 40 0 0 0 0>;//按键的布局信息,包含按键的宽度,高度,中心点的坐标
        tpd-max-touch-num = <5>;//支持的最大触摸点数
        tpd-filter-enable = <0>; //fae suggest this change to improve effect
        tpd-filter-pixel-density = <146>;
        tpd-filter-custom-prameters = <0 0 0 0 0 0 0 0 0 0 0 0>;
        tpd-filter-custom-speed = <0 0 0>;
        pinctrl-names = "default", "state_eint_as_int", "state_eint_output0", "state_eint_output1",
            "state_rst_output0", "state_rst_output1";
        pinctrl-0 = <&ctp_pins_default>;
        pinctrl-1 = <&ctp_pins_eint_as_int>;
        pinctrl-2 = <&ctp_pins_eint_output0>;
        pinctrl-3 = <&ctp_pins_eint_output1>;
        pinctrl-4 = <&ctp_pins_rst_output0>;
        pinctrl-5 = <&ctp_pins_rst_output1>;
        status = "okay";
    };
    &pio {
        ctp_pins_default: eint0default {
        };
        ctp_pins_eint_as_int: eint@0 {
            pins_cmd_dat {
                pins = <PINMUX_GPIO1__FUNC_GPIO1>;
                slew-rate = <0>;
                bias-disable;
            };
        };
        ctp_pins_eint_output0: eintoutput0 {
            pins_cmd_dat {
                pins = <PINMUX_GPIO1__FUNC_GPIO1>;
                slew-rate = <1>;
                output-low;
            };
        };
        ctp_pins_eint_output1: eintoutput1 {
            pins_cmd_dat {
                pins = <PINMUX_GPIO1__FUNC_GPIO1>;
                slew-rate = <1>;
                output-high;
            };
        };
        ctp_pins_rst_output0: rstoutput0 {
            pins_cmd_dat {
                pins = <PINMUX_GPIO158__FUNC_GPIO158>;
                slew-rate = <1>;
                output-low;
            };
        };
        ctp_pins_rst_output1: rstoutput1 {
            pins_cmd_dat {
                pins = <PINMUX_GPIO158__FUNC_GPIO158>;
                slew-rate = <1>;
                output-high;
            };
        };
    };
    /* TOUCH end */
    &i2c0 {
            status = "okay";


            goodix_touch@5e {
                    compatible = "mediatek,goodix_touch"; //用于匹配GT9xx这个TP驱动
                    
                    reg = <0x5e>;//GT9xx I2c的地址
                    interrupt-parent = <&pio>; //中断脚
                    interrupts = <1 IRQ_TYPE_EDGE_RISING 1 0>;//中断模式是上升沿触发
                    //vtouch-supply = <&mt_pmic_vldo28_ldo_reg>; //原生MTK节点TP 2.8V PMIC供电
                    reg-tp-supply = <&mt_pmic_vldo28_ldo_reg>; //由于我们代码上修改了TP 2.8V PMIC供电节点获取是以reg-tp-supply这个字符获取的原生的是由vtouch-supply这个获取的
                    rst-gpio = <&pio 158 0>;//TP的复位引脚
                    int-gpio = <&pio 1 0>;//TP的中断引脚
                    
                    status = "okay";
                };
        }

    驱动流程表:

    TP驱动的注册 :mtk_tpd.c

    注册成功后调用probe探测方法

    在这里插入图片描述

    probe方法里实现的动作,注册TP设备,获取TP dts相关信息,为TP设备申请内核内存空间,分配一个输入设备

    在这里插入图片描述

    特定TP的注册在这里插入图片描述

    创建一个TP回调函数,用于TP 在LCD亮屏和灭屏时调用

     

    在这里插入图片描述

    如果是cap TP驱动则进行初始化

    在这里插入图片描述

    最后实现input设备注册,把设备加入input设备链表,生成“dev/input/eventx”节点,和进行虚拟按键初始化以及一些TP属性的创建

    在这里插入图片描述

    int tpd_get_gpio_info 这个函数是获取Tp dts节点信息就是获取中断和复位引脚的状态

    在这里插入图片描述

    ** touch_resume_workqueue_callback该函数主要是用于判断LCD是亮屏还是灭屏通过调用回调函数 tpd_fb_notifier_callback通知TP是否工作**

    在这里插入图片描述

    回调函数tpd_fb_notifier_callback接受到通知后,通知TP是否工作

    在这里插入图片描述

    tpd_create_attributes这个函数是创建TP的一些系统属性

    在这里插入图片描述

    特定TP驱动的初始化:我这里用汇顶GT9xx驱动为例: gt9xx_driver.c
    首先获取i2c0上的gt9xx驱动设备节点的dts信息,然后注册 i2c0上的 gt9xx 汇顶TP驱动到TP驱动链表中

    在这里插入图片描述

    void tpd_get_dts_info(void)该函数是获取touch tp节点的信息

    在这里插入图片描述

    在这里插入图片描述

    void tpd_get_dts_info(void)该函数从touch tp节点的信息获取dts信息

    在这里插入图片描述

     

    int tpd_driver_add该函数会添加新的TP驱动到TP驱动链表中,即会把GT9xx添加到TP驱动链表中

    在这里插入图片描述

    当新TP驱动tpd_device_driver添加成功会调用tpd_local_init这个本地方法

    在这里插入图片描述

    TP本地方法里实现了esd防静电检测队列的创建,TP相关电压检测队列的创建,分配DMA i2c对象,我们封装的TP2.8V供电接口还是就是原生的2.8v供电接口

    在这里插入图片描述

    下来本地方法里会注册I2c从设备驱动,如果注册失败tpd_load_status 值会为0,同时进行按键和虚拟按键的初始化,以及记录TP供应商的一些信息

    在这里插入图片描述

    注册gt9xx tp驱动,调用probe探测方法

    在这里插入图片描述

    ** tpd_i2c_probe探测方法里实现了获取平台数据,获取int中断和rst复位引脚的状态以及I2c上电通信,我们添加的初始化接口,通过I2c通信的读接口读取TP固件信息**

    在这里插入图片描述

    接下来会初始化TP固件参数,增加了我们自定义的TP方向的接口,以及创建TP节点信息,初始化写进去的参数,创建一条内核线程,如果有虚拟按键,就初始化虚拟按键

    在这里插入图片描述

    最后,探测方法里还实现按键初始化,TP中断的使能,esd防静电开启,创建一条用于更新TP固件的线程,实现远离和靠近屏幕是TP的唤醒功能

    在这里插入图片描述

    最终如果探测方法里的动作都实现了,会记录tpd_load_status = 1,表示gt9xx TP驱动成功注册

    在这里插入图片描述

     

    of_get_gt9xx_platform_data这个函数获取int中断和rst复位引脚信息

    在这里插入图片描述

     

    static int gtp_get_gpio_res(void)该函数是配置int中断和rst复位引脚

    在这里插入图片描述

     

    tpd_power_on函数是上电,下载TP固件

    在这里插入图片描述

     

    tpd_power_on函数接下来上电并下载TP固件成功,同时测试i2c是否上电通信成功

    在这里插入图片描述

    gtp_read_version这个函数是通过i2c读取TP固件版本信息

    在这里插入图片描述

     

    gtp_init_panel初始化TP厂商给的TP参数在这里插入图片描述

     

    TP参数

    在这里插入图片描述

     

    gt91xx_config_proc = proc_create(GT91XX_CONFIG_PROC_FILE, 0660, NULL, &gt_upgrade_proc_fops);这个在创建节点时会使用到两个操作方法进行

    在这里插入图片描述

     

    gt_upgrade_proc_fops里面定义了读和写方法

    在这里插入图片描述

     

    创建了中断核心线程thread = kthread_run(touch_event_handler, 0, TPD_DEVICE);

    在这里插入图片描述

    touch_event_handler中断核心线程主要是实现抬手和按压事件的上报

    在这里插入图片描述

    在这里插入图片描述

     

    展开全文
  • TP 相关引脚DTS中的定义我们这个项目TP复位引脚是GPIO158,中断引脚是GPIO1,由下图原理图知道我们的TP挂载在I2c0上,3.3v的供电电压是有PMIC 2.8V供电电压通过i2c电平转换过来的,所以供电电压需要配置pmic 2.8v ...
  • TPIS触摸屏编程

    2018-10-21 16:50:37
    TPIS触摸屏编程技巧和操作应用的文档,能增加对触摸屏了解
  • 介绍了关于信捷TP系列触摸屏用户手册的详细说明,提供信捷的技术资料的下载。
  • 天任(TRE)TP系列触摸屏选型手册.pdf 介绍了关于天任(TRE)TP系列触摸屏选型手册的详细说明,提供触摸屏的技术资料的下载。
  • 介绍了关于TP系列触摸屏应用之连接面板打印机的详细说明,提供触摸屏的技术资料的下载。
  • 西门子触摸屏TP700 三维模型,STEP格式可以用SolidWorks打开
  • 信捷TP系列触摸屏软件TWin v2.68版rar,信捷TP系列触摸屏软件TWin v2.68版
  • TP系列触摸屏软件TWin v2.68.rarrar,TP系列触摸屏软件TWin v2.68.rar
  • 天任(TRE)TP系列触摸屏选型手册pdf,天任(TRE)TP系列触摸屏选型手册
  • 介绍了关于信捷TP系列触摸屏应用案例(一)的详细说明,提供信捷的技术资料的下载。
  • 信捷TP系列触摸屏编辑软件TWinV2.78
  • 天任 TP系列触摸屏通过USB直连线下载的驱动程序rar,天任 TP系列触摸屏通过USB直连线下载的驱动程序
  • TH、TP系列触摸屏用户手册提高篇之三(自定义通讯协议).pdf 介绍了关于TH、TP系列触摸屏用户手册提高篇之三(自定义通讯协议)的详细说明,提供触摸屏的技术资料的下载。
  • TH、TP系列触摸屏用户手册提高篇之三(自定义通讯协议)pdf,TH、TP系列触摸屏用户手册提高篇之三(自定义通讯协议)
  • 触摸屏TP277可以放数据库吗?具体的脚本命令是什么?问题补充:在电脑进行调试时可以读取数据,但将程序传送给TP277后,触摸屏不访问数据库。DimConStringConString="Provide=MSDASQL;DRIVER=SQLServer;SERVER=10.8....
  • 西门子OP-TP-MP触摸屏面板维修西门子OP-TP-MP触摸屏面板维修

空空如也

空空如也

1 2 3 4 5 ... 18
收藏数 343
精华内容 137
关键字:

tp触摸屏