之前调试触摸屏的文章如下:
基于瑞芯微RV1109 Linux触摸屏GT911驱动调试心得
由于之前调触摸屏一直都对不上点,然后厂商又给了我新的驱动代码。但是还是没能解决问题,所以我初步怀疑是固件问题,因为驱动基本上只要写对了是不会有问题的,因此,我让厂商帮我调了一个适配触摸屏的固件,最后这个问题就解决了。厂商给过来的固件是一个.cfg文件,使用记事本的打开方式打开这个文件,发现是一个16进制的数组:
如果是老版本不支持设备树的驱动,则直接将这个文件复制到驱动目录的路径下,然后将gt9xx_cfg.h打开,将对应的配置文件包含进来即可,如下图所示:
gt9xx_cfg.h这个文件的内容:
然后将对应的cfg文件包含进对应的数组里,然后打开gt9xx.h进行配置即可:
注意,这部分详细的功能请参考屏厂给的文档进行修改。这里就不再多说了。
然而现在驱动支持设备树了以后,Linux内核设备树里配置触摸屏参数的写法是这样的:
//TP:GT911 &i2c5 { status = "okay"; goodix_ts@5d { compatible = "goodix,gt9xx"; reg = <0x5d>; goodix_irq_gpio = <&gpio2 RK_PB2 IRQ_TYPE_LEVEL_HIGH>; goodix_rst_gpio = <&gpio2 RK_PD4 GPIO_ACTIVE_HIGH>; gtp_resolution_x = <600>; gtp_resolution_y = <1024>; gtp_int_tarigger = <1>; gtp_change_x2y = <0>; gtp_overturn_x = <1>; gtp_overturn_y = <1>; gtp_send_cfg = <1>; gtp_touch_wakeup = <1>; status = "okay"; goodix,cfg-group0 = [ //old touch 41 00 04 58 02 05 7D 00 01 2F 28 0F 50 32 03 05 00 00 00 00 00 00 00 18 1A 1E 14 89 0D 0C 2C 2A 0C 08 00 00 00 82 03 1D 0A 32 05 0A 32 00 00 00 00 00 0B 1E 50 94 E5 02 08 00 00 04 A7 21 00 8B 28 00 73 31 00 62 3B 00 52 48 00 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 32 50 00 00 00 1C 1A 18 16 14 12 10 0E 0C 0A 08 06 04 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2A 29 28 26 24 22 21 20 1F 1E 1D 18 16 14 13 12 10 0F 0C 0A 08 06 FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3B 01 ]; }; };
那么,如何将上面的数组转化成goodix,cfg-group0这样的格式呢?一个简单的方法,使用记事本的方式打开,然后键盘快捷键:Ctrl+H:
通过替换的方式,将配置文件里的0x
和,
分别进行替换,最后我们得到如下这个数组:
这个方法简单粗暴!然后将这个数组替换设备树里对应的位置即可:
//TP:GT911 &i2c5 { status = "okay"; goodix_ts@5d { compatible = "goodix,gt9xx"; reg = <0x5d>; goodix_irq_gpio = <&gpio2 RK_PB2 IRQ_TYPE_LEVEL_HIGH>; goodix_rst_gpio = <&gpio2 RK_PD4 GPIO_ACTIVE_HIGH>; gtp_resolution_x = <600>; gtp_resolution_y = <1024>; gtp_int_tarigger = <1>; gtp_change_x2y = <0>; gtp_overturn_x = <1>; gtp_overturn_y = <1>; gtp_send_cfg = <1>; gtp_touch_wakeup = <1>; status = "okay"; goodix,cfg-group0 = [ 50 00 04 58 02 05 BD 00 01 08 1E 05 3C 3C 03 05 00 00 00 00 00 00 00 1A 1C 1E 14 8A 2A 0C 2A 28 EB 04 00 00 01 61 03 2C 00 01 00 00 00 00 00 00 00 00 00 14 3C 94 C5 02 08 00 00 04 B7 16 00 9F 1B 00 8B 22 00 7B 2B 00 70 36 00 70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 16 14 12 10 0E 0C 0A 08 06 04 02 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 24 22 21 20 1F 1E 1D 1C 18 16 13 12 10 0F 0A 08 06 04 02 00 FF FF FF FF FF FF FF FF FF 00 00 00 00 00 00 00 00 00 00 00 00 00 34 01 ]; }; };
注意,这里需要注意,如果要将数组烧到TP板子里的话,需要开启:
gtp_send_cfg = <1>;
这样这些数组在上电时就会被写入到触摸屏里去。在初始化代码开始时,也就是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); #ifdef GTP_CONFIG_OF //#if GTP_CONFIG_OF GTP_DEBUG("Get config data from device tree."); printk("sensor_id = %d\n",sensor_id); 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
首先会读取sensor_id,然后根据id来匹配对应的设备树里的这个数组:
/** * gtp_parse_dt_cfg - parse config data from devices tree. * @dev: device that this driver attached. * @cfg: pointer of the config array. * @cfg_len: pointer of the config length. * @sid: sensor id. * Return: 0-succeed, -1-faileds */ int gtp_parse_dt_cfg(struct device *dev, u8 *cfg, int *cfg_len, u8 sid) { struct device_node *np = dev->of_node; struct property *prop; char cfg_name[18]; //rdzkj add for compatible of different screen by sensor_id snprintf(cfg_name, sizeof(cfg_name), "goodix,cfg-group%d", sid); GTP_INFO("get %s...",cfg_name); prop = of_find_property(np, cfg_name, cfg_len); //add end if (!prop || !prop->value || *cfg_len == 0 || *cfg_len > GTP_CONFIG_MAX_LENGTH) { return -1;/* failed */ } else { memcpy(cfg, prop->value, *cfg_len); return 0; } }
最后通过判断设备树里gtp_send_cfg
是否为1,如果为1,则将这个数组发送到触摸屏芯片中,完成固件的烧写:
if (gtp_config->gtp_send_cfgs == 1) { ret = gtp_send_cfg(ts->client); if (ret < 0) { GTP_ERROR("Send config error."); } #if GTP_COMPATIBLE_MODE if (ts->chip_type != CHIP_TYPE_GT9F) #endif { if (flash_cfg_version < 90 && flash_cfg_version > drv_cfg_version) { check_sum = 0; config[GTP_ADDR_LENGTH] = drv_cfg_version; for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++) { check_sum += config[i]; } config[ts->gtp_cfg_len] = (~check_sum) + 1; } } }
通常来说,这个固件只要烧一次就行了,因此,在触摸屏量产的时候,在确定固件已经烧写正确的情况下,将设备树调整为如下:
//TP:GT911 &i2c5 { status = "okay"; goodix_ts@5d { compatible = "goodix,gt9xx"; reg = <0x5d>; goodix_irq_gpio = <&gpio2 RK_PB2 IRQ_TYPE_LEVEL_HIGH>; goodix_rst_gpio = <&gpio2 RK_PD4 GPIO_ACTIVE_HIGH>; gtp_resolution_x = <600>; gtp_resolution_y = <1024>; gtp_int_tarigger = <1>; gtp_change_x2y = <0>; gtp_overturn_x = <1>; gtp_overturn_y = <1>; gtp_touch_wakeup = <1>; status = "okay"; }; };
否则,如果刷了一个别的固件进去,触摸屏很可能就动不了了。
往期精彩
如何添加APP到Buildroot里(以瑞芯微rv1126为例)
基于瑞芯微RV1109 Linux触摸屏GT911驱动调试心得
Linux MIPI DSI LCD设备驱动开发调试细节学习笔记(一)
Linux MIPI DSI驱动调试笔记-LCD时序参数配置(三)
Linux MIPI DSI驱动调试笔记-设备树DCS格式序列之配置LCD初始化代码(二)