RK3399觸摸不準,修改drivers中gt9xx.h的cfg

主板是friendlyarm的NanoPC-T4的主板,RK3399的主芯片,原本適配了1280 * 800的7寸屏和1920 * 1200的11寸屏。現在又想要用一款10.1寸的屏,接口都是edp,觸摸是iic。插上去屏能亮,顯示都沒問題,但是觸摸有點不準,用了一個畫圖軟件,發現橫軸的點位有點偏移,偏移不固定,線性的偏移,就是靠左邊的時候偏移大,靠右邊的時候偏移小。

我第一步就把主板的串口接到電腦,看log,很快就看到一些關鍵log,分辨率1280*800,觸摸ic是gt928,這些都對了。那問題就很明顯了,應該是cfg不對,然後找屏廠的人拿了cfg文件。

[    1.178927] <<-GTP-INFO->> GTP Driver Version: V2.4 <2014/11/28>
[    1.178940] <<-GTP-INFO->> GTP I2C Address: 0x5d
[    1.179032] <<-GTP-INFO->> Guitar reset
[    1.223737] fusb302 4-0022: CC connected in 1 as UFP
[    1.271403] <<-GTP-INFO->> IC Version: 928_1060
[    1.271447] <<-GTP-DEBUG->> [1348]Config Groups' Lengths: 186, 0, 0, 0, 0, 186
[    1.272118] <<-GTP-INFO->> Sensor_ID: 0
[    1.272128] <<-GTP-DEBUG->> [1402]Get config data from header file.
[    1.272140] <<-GTP-INFO->> Config group0 used,length: 186
[    1.272482] <<-GTP-DEBUG->> [1446]Config Version: 95, 0x5F; IC Config Version: 95, 0x5F
[    1.272497] <<-GTP-INFO->> Driver send config.
[    1.278407] <<-GTP-INFO->> X_MAX: 1280, Y_MAX: 800, TRIGGER: 0x01
[    1.290916] <<-GTP-INFO->> create proc entry gt9xx_config success
[    1.290937] <<-GTP-INFO->> Ready to run update thread.
[    1.292208] input: goodix-ts as /devices/virtual/input/input1
[    1.292345] <<-GTP-DEBUG->> [2283][update_proc]Begin update ......
[    1.292361] <<-GTP-DEBUG->> [805]Search for /data/_goodix_update_.bin, /sdcard/_goodix_update_.bin for fw update.(1/2)
[    1.292397] <<-GTP-DEBUG->> [1766]INT trigger type:1
[    1.292454] <<-GTP-DEBUG->> [842]Search for /data/_goodix_config_.cfg, /sdcard/_goodix_config_.cfg for config update.(1/2)
[    1.292457] <<-GTP-INFO->> GTP works in interrupt mode.
[    1.292464] <<-GTP-INFO->> Applied memory size:2562.
[    1.292468] <<-GTP-INFO->> I2C function: without pre and end cmd!
[    1.292477] <<-GTP-INFO->> Create proc entry success!

然後開始搭環境,下載源碼,看源碼,編譯,因爲我們只改動了kernel部分,所以只要編譯kernel.img就行了。

make ARCH=arm64 nanopi4_nougat_defconfig
make -j2 ARCH=arm64 kernel.img

其中有個東西可以提一下的,如何用最快的速度編譯,關鍵在make -jN,這個N就是你cpu的核心數,如果你不知道你的cpu核心數是多少, 可以用命令查一下

grep processor /proc/cpuinfo | awk '{field=$NF};END{print field+1}'

在改代碼的時候,發生了有意思的事情,原本進入/kernel/drivers/input/touchscreen/目錄下面,找到gt9xx目錄

root@ubuntu:/home/weijian/Android/RK3399/rk3399-nougat/kernel/drivers/input/touchscreen/gt9xx# ls
goodix_tool.c                             gt9xx_update.c
GT9110P_Config_20160217_1526_2048_97.cfg  Makefile
GT9271_Config_20170526.cfg                WGJ10162B_GT9271_1060_Config_20140821_1341110X42.cfg
GT928_Config_TR1060_1280X800_FPC_D.cfg    WGJ10162_GT9271_Config_20140820_182456.cfg
gt9xx.c                                   WGJ10187_GT9271_Config_20140623_104014_0X41.cfg
gt9xx_firmware.h                          WGJ89006B_GT911_Config_20140625_085816_0X43.cfg
gt9xx.h                                   WGJ89006B_GT9271_Config_20140625_085816_0X41.cfg

就自以爲找對了,然後就開始動手看代碼,修改代碼,發現改了無效,一臉懵逼。想了想,往GTP-INFO裏面添加自定義的關鍵代碼比如weijian等等,然後也沒打印出來。這時候纔開始看Makefile文件

#
# Makefile for the touchscreen drivers.
#

# Each configuration option enables a list of files.
……
ifndef CONFIG_TOUCHSCREEN_FE_PANELS
obj-$(CONFIG_TOUCHSCREEN_GT9XX)		+= gt9xx/
endif
……
obj-$(CONFIG_TOUCHSCREEN_FE_PANELS)	+= friendlyelec/

這才發現gt9xx目錄下的文件不一定會被編譯,需要打開CONFIG_TOUCHSCREEN_FE_PANELS,而另外friendlyelec目錄下是一定會被編譯,且該目錄同樣有gt9xx.c和gt9xx.h文件。

root@ubuntu:/home/weijian/Android/RK3399/rk3399-nougat/kernel/drivers/input/touchscreen/friendlyelec# ls
built-in.o     goodix_tool.o  gt9xx_firmware.h  gt9xx.o         gt9xx_update.o  Makefile         modules.order
goodix_tool.c  gt9xx.c        gt9xx.h           gt9xx_update.c  Kconfig         modules.builtin

這時候纔開始恍然大悟,然後修改,編譯,下載,驗證ok。
看了一點代碼,簡單說一下的觸摸驅動的流程。觸摸屏通過iic控制,驅動部分適配了5種不同的屏幕,通過讀取觸摸ic(GT928)的sensor id來判斷,適配哪個屏幕,即哪個cfg。

gt9xx.h的部分代碼,只修改了CTP_CFG_GROUP0

// TODO: define your own default or for Sensor_ID == 0 config here. 
// The predefined one is just a sample config, which is not suitable for your tp in most cases.

//#define CTP_CFG_GROUP0 {\
        /* HD101B */ \
/*      0x00,0x00,0x05,0x20,0x03,0x05,0x3D,0x00,0x01,0x08,0x28,\
        0x05,0x50,0x32,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x01,0x1A,0x1C,0x1E,0x14,0x8E,0x2E,0x88,0x20,0x1E,0x31,\
        0x0D,0x00,0x00,0x00,0x9C,0x03,0x1D,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x64,0x94,0xC5,\
        0x02,0x07,0x00,0x00,0x04,0x51,0x2C,0x00,0x4A,0x34,0x00,\
        0x44,0x3F,0x00,0x40,0x4C,0x00,0x3E,0x5B,0x00,0x3E,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x01,0x04,0x05,0x06,0x07,0x08,0x09,0x0C,\
        0x0D,0x0E,0x0F,0x10,0x11,0x14,0x15,0xFF,0xFF,0xFF,0xFF,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x02,0x04,0x06,0x07,0x08,0x0A,0x0C,0x0D,0x0F,0x10,0x11,\
        0x12,0x13,0x19,0x1B,0x1C,0x1E,0x1F,0x20,0x21,0x22,0x23,\
        0x24,0x25,0x26,0x27,0x28,0xFF,0xFF,0xFF,0xFF,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x01\
    }*/
#define CTP_CFG_GROUP0 {\
        /* 10.1 1280*800 */\
        0x5F,0x00,0x05,0x20,0x03,0x05,0x0D,0x00,0x01,0x08,0x28,\
        0x05,0x50,0x3C,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x8F,0x2F,0xAA,0x43,0x45,0x0C,\
        0x08,0x00,0x00,0x00,0x00,0x03,0x1D,0x00,0x00,0x00,0x00,\
        0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x3C,0x64,0x94,0xD5,\
        0x02,0x07,0x00,0x00,0x04,0x80,0x3F,0x00,0x7B,0x46,0x00,\
        0x73,0x4D,0x00,0x6B,0x55,0x00,0x63,0x5F,0x00,0x63,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x01,0x04,0x05,0x06,0x07,0x08,0x09,0x0C,\
        0x0D,0x0E,0x0F,0x10,0x11,0x14,0x15,0x16,0x17,0x18,0x19,\
        0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x02,0x04,0x06,0x07,0x08,0x0A,0x0C,0x0D,0x0F,0x10,0x11,\
        0x12,0x13,0x14,0x19,0x1B,0x1C,0x1E,0x1F,0x20,0x21,0x22,\
        0x23,0x24,0x25,0x26,0x27,0x28,0x29,0xFF,0xFF,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x9A,0x01\
}

// TODO: define your config for Sensor_ID == 1 here, if needed
#define CTP_CFG_GROUP1 {\
    }

// TODO: define your config for Sensor_ID == 2 here, if needed
#define CTP_CFG_GROUP2 {\
    }

// TODO: define your config for Sensor_ID == 3 here, if needed
#define CTP_CFG_GROUP3 {\
    }

// TODO: define your config for Sensor_ID == 4 here, if needed
#define CTP_CFG_GROUP4 {\
    }
    
// TODO: define your config for Sensor_ID == 5 here, if needed
#define CTP_CFG_GROUP5 {\
        /* HD702 */ \
        0x50,0x20,0x03,0x00,0x05,0x05,0x34,0x20,0x02,0x2B,0x28,\
        0x0F,0x50,0x3C,0x03,0x05,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x18,0x1A,0x1E,0x14,0x8D,0x2D,0x88,0x3A,0x37,0x33,\
        0x0F,0x00,0x00,0x00,0x02,0x02,0x2D,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x41,0x94,0xC5,\
        0x02,0x07,0x00,0x00,0x04,0xD6,0x1E,0x1E,0xB6,0x24,0x00,\
        0x9F,0x2A,0x00,0x8A,0x32,0x00,0x79,0x3B,0x00,0x79,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
        0x00,0x00,0x00,0x01,0x04,0x05,0x06,0x07,0x08,0x09,0x0C,\
        0x0D,0x0E,0x0F,0x10,0x11,0x14,0x15,0xFF,0xFF,0xFF,0xFF,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x27,\
        0x26,0x25,0x24,0x23,0x22,0x21,0x20,0x1F,0x1E,0x1C,0x1B,\
        0x19,0x13,0x12,0x11,0x10,0x0F,0x0C,0x0A,0x08,0x07,0x06,\
        0x04,0x02,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,\
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x01\
    }

GROUP1原本適配11寸屏(1920 * 1200),現在改成適配10寸屏(1280 * 800)
GROUP5適配7寸屏(1280 * 800)
其餘空着,不做適配

關鍵代碼是gt9xx.c裏面

static s32 gtp_init_panel(struct goodix_ts_data *ts)
{
……
    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);

        /* parse config data*/
#ifdef GTP_CONFIG_OF
        GTP_DEBUG("Get config data from device tree.");
        ret = gtp_parse_dt_cfg(&ts->client->dev, &config[GTP_ADDR_LENGTH], &ts->gtp_cfg_len, sensor_id);
        if (ret < 0) {
                GTP_ERROR("Failed to parse config data form device tree.");
                ts->pnl_init_error = 1;
                return -1;
        }
#else
        GTP_DEBUG("Get config data from header file.");
    if ((!cfg_info_len[1]) && (!cfg_info_len[2]) &&
        (!cfg_info_len[3]) && (!cfg_info_len[4]) &&
        (!cfg_info_len[5]))
    {
        sensor_id = 0;
    }
        ts->gtp_cfg_len = cfg_info_len[sensor_id];
        memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
        memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len);
#endif

……
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章