RK3568 android11 realizes dual-channel I2C touch --GT9xx

1. Introduction to GT911 touch screen

  1. Its interface type is I2C, and the power supply voltage and communication voltage are both 3.3V. This capacitive touch screen has a built-in pull-up resistor, which means that there is no need to set a pull-up resistor at the interface between our development board and the touch screen.
  2. Regarding the line sequence, it is also GT911, and different batches of devices have different line sequences. Please confirm with the manufacturer for details.

2. DTS configuration

Debugging dual I2C touch, the two TPs are of the same model (gt911). The dts file configuration is mainly the I2C communication information between the CPU and the touch screen. View the hardware schematic diagram and the two TPs are mounted under different I2C.

TP1(i2c1):
Insert image description in
TP2(i2c3):
Insert image description here

&i2c1 {
    
    
        status = "okay";

        gt1x: gt1x@14 {
    
    
                status = "okay";
                compatible = "goodix,gt9xx";
                reg = <0x14>;
                pinctrl-names = "default";
                pinctrl-0 = <&touch_gpio>;
                reset-gpio = <&gpio0 RK_PB6 GPIO_ACTIVE_HIGH>;//复位脚
                touch-gpio = <&gpio0 RK_PB5 IRQ_TYPE_LEVEL_LOW>;//中断脚
                max-x = <1920>;
                max-y = <1080>;
                tp-size = <0>;
        };
};

&i2c3 {
    
    
        status = "okay";

        gt1x@14 {
    
    
            status = "okay";
            compatible = "goodix,gt9xx_extend";
            reg = <0x14>;
            pinctrl-names = "default";
            pinctrl-0 = <&extend_touch_gpio>;
            extend_reset-gpio = <&gpio3 RK_PA4 GPIO_ACTIVE_HIGH>;
            extend_touch-gpio = <&gpio3 RK_PA3 IRQ_TYPE_LEVEL_LOW>;
            max-x = <1920>;
            max-y = <1080>;
            tp-size = <0>;
        };
};

&pinctrl {
    
    

        touch {
    
    
                touch_gpio: touch-gpio {
    
    
                        rockchip,pins =
                                <0 RK_PB5 RK_FUNC_GPIO &pcfg_pull_up>,
                                <0 RK_PB6 RK_FUNC_GPIO &pcfg_pull_none>;
                };
                extend_touch_gpio:extend-touch-gpio{
    
    
                        rockchip,pins =
                                <3 RK_PA4 RK_FUNC_GPIO &pcfg_pull_up>,
                                <3 RK_PA3 RK_FUNC_GPIO &pcfg_pull_none>;
                };
        };
};

3. Driver file configuration

There are mainly 3 files related to the driver (这里以TP1的驱动为例):

1,gt9xx.c

static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) //入口函数
{
    
    
    ...

    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

    ...

}

In this function, you can see that the information configured in the previous dts is read. The configuration name in the dts must be consistent with the one in this code;

2,gt9xx.h

There are several macros in the header file, which are related to debugging printing. Turning on these printings can help us locate some problems during our adaptation process.

#define DEBUG_SWITCH 0
#define GTP_DEBUG_ON          0
#define GTP_DEBUG_FUNC_ON     0
//这几个打印默认是关闭的,可以置1打开

3. cfg file

The cfg file is the initialization instruction of the touch screen. After power-on, the CPU writes these instructions to the touch screen chip through I2C.
The cfg file is configured in gt9xx_cfg.h. You can check and determine which array the driver specifically references.

#ifndef _GOODIX_GT9XX_CFG_H_
#define _GOODIX_GT9XX_CFG_H_

/* CFG for GT911 */
u8 gtp_dat_gt11[] = {
    
    
    /* <1200, 1920>*/
    #include "WGJ89006B_GT911_Config_20140625_085816_0X43.cfg"
};

u8 gtp_dat_8_9[] = {
    
    
    /* TODO:Puts your update firmware data here! */
    /* <1920, 1200> 8.9 */
    /* #include "WGJ89006B_GT9271_Config_20140625_085816_0X41.cfg" */
    /* #include "WGJ10162_GT9271_Config_20140820_182456.cfg" */
    #include "WGJ10162B_GT9271_1060_Config_20140821_1341110X42.cfg"
};

u8 gtp_dat_8_9_1[] = {
    
    
    #include "GT9271_Config_20170526.cfg"
};

u8 gtp_dat_9_7[] = {
    
    
    /* <1536, 2048> 9.7 */
    #include "GT9110P_Config_20160217_1526_2048_97.cfg"
};

u8 gtp_dat_10_1[] = {
    
    
    /* TODO:Puts your update firmware data here! */
    /* <1200, 1920> 10.1 */
    #include "WGJ10187_GT9271_Config_20140623_104014_0X41.cfg"
};

u8 gtp_dat_7[] = {
    
    
    /* TODO:Puts your update firmware data here! */
    /* <1024, 600> 7.0 */
    #include "WGJ10187_GT910_Config_20140623_104014_0X41.cfg"
};

#endif /* _GOODIX_GT9XX_CFG_H_ */

4. Driver transplantation

a. Copy the driver (gt9xx) provided by the original factory to the following folder:

./kernel/drivers/input/touchscreen

b. Then modify the Makefile and Kconfig in the touchscreen directory. What is defined in this Makefile is which platform's touch screen driver is to be compiled.

kernel/drivers/input/touchscreen/Makefile中添加:
obj-$(CONFIG_TOUCHSCREEN_GT9XX)                += gt9xx/
obj-$(CONFIG_TOUCHSCREEN_GT9XX_EXTEND)         += gt9xx_extend/


------------------------------------------------------------------------
kernel/drivers/input/touchscreen/Kconfig中添加:
source "drivers/input/touchscreen/gt9xx/Kconfig"
source "drivers/input/touchscreen/gt9xx_extend/Kconfig"

c. Load the driver in the kernel:

kernel/arch/arm64/configs/rockchip_defconfig中添加:
CONFIG_TOUCHSCREEN_GT9XX=y
CONFIG_TOUCHSCREEN_GT9XX_EXTEND=y

注: 实现双I2C触摸,两份驱动可以使用一样的。即 将TP1的驱动复制一份出来给TP2使用,复制之后改匹配的字段,这时编译会出现冲突,然后把两份驱动中冲突的部分重命名,之后编译通过即可(判断驱动生效可以看文件夹下是否有对应的.o文件生成)。

5. Main and secondary screen touch configuration

a. A macro named GTP_I2C_NAME is defined in the gt9xx.h header file, and its value is "Goodix-TS", which is used to identify the I2C device name and can be used to distinguish the main and secondary screens.

#define GTP_I2C_NAME                "Goodix-TS"

---------------------------------------------------------------------
复制给副屏使用的驱动可以修改NAME用来区分主屏,如下:
#define GTP_I2C_NAME                "Goodix-TS_extend"

b. The system adds the input device configuration file (.idc file Input Device Configuration).

主屏 Goodix-TS.idc:
device.internal = 1

----------------------------------------------------------------------
副屏 Goodix-TS_extend.idc:
device.internal = 0

c. Copy the above two idc files in the mk file to the system system/usr/idc/ directory.

PRODUCT_COPY_FILES += \
    $(LOCAL_PATH)/Goodix-TS.idc:system/usr/idc/Goodix-TS.idc \
    $(LOCAL_PATH)/Goodix-TS_extend.idc:system/usr/idc/Goodix-TS_extend.idc

After compiling the system firmware upgrade, dual I2C touch can control the main and secondary screens normally.


4. Debugging

1>. Looking at the kernel print log when powering on, the prints related to the touch screen all start with the following keywords:

<<-GTP-INFO->>
<<-GTP-DEBUG->>
<<-GTP-ERROR->>

adb shell dmesg | grep GTP can filter touch screen related printing.
2>. The way to check the working status is to look at the interrupt statistics:

cat /proc/interrupts

If the driver loads successfully, you can see the statistical information of gt9xx and gt9xx_extend in the listed information. This information records the number of times these interruptions occur. Usually when we interact with the touch screen, many interruptions can occur.

Guess you like

Origin blog.csdn.net/weixin_45639314/article/details/134650770