记录下gt1151触摸驱动适配过程,主控为全志D1s点屏强芯。
首先要找触摸驱动源码,可以去goodix的github仓库看一看,找到了一个通用的驱代码,链接如下:
https://github.com/goodix/gt1x_driver_generic.git
下载下来后放到Tina的kernel对应驱动目录下drivers/input/touchscreen/gt1x_new,新增了一个目录gt1x_new,下面就是驱动代码以及dts的适配了。
DTS配置
先把dts配置下,配置dts就要先明确硬件引脚配置,查看硬件原理图可知我使用的是i2c2来驱动的(PD20, PD21),这个SDK里i2c被称为twi,先把对应引脚复用为i2c功能,dts修改如下:
twi2_pins_a: twi2@0 {
//pins = "PE12", "PE13";
pins = "PD20", "PD21";
function = "twi2";
drive-strength = <10>;
};
twi2_pins_b: twi2@1 {
//pins = "PE12", "PE13";
pins = "PD20", "PD21";
function = "gpio_in";
};
然后是twi2总线下面的触摸屏dts配置,官方文档有个参考例子可以借鉴下:
Optional properties
- goodix,charger-configx: chip configuration data used in charger mode, if you
hava enabled CONFIG_GTP_CHAGER_SWITCH, you need to add this property.
x stands for sendor ID. - goodix,smartcover-configx: chip configuration data used in smartcover mode, if
you have enabled CONFIG_GTP_SMARTCOVER, you need to add this property.
Example
i2c@f9927000 { /*Goodix BLSP1 QUP5 */
goodix_ts@5d {
compatible = "goodix,gt1x";
reg = <0x5d>;
interrupt-parent = <&msmgpio>;
interrupts = <17 0x2008>;
vdd_ana-supply = <&pm8226_l19>;
goodix,reset-gpio = <&msmgpio 16 0x00>;
goodix,irq-gpio = <&msmgpio 17 0x00>;
goodix,default-config0 = [
5c 00 12 11 10 11 5f 00 cc bb
22 00 11 00 00 00 00 00 00 00
...
];
goodix,charger-config2 = [
5f 00 12 11 10 11 5f 00 cc bb
23 00 11 00 00 00 00 00 00 00
...
];
/* if you have disable CONFIG_GTP_INT_SEL_SYNC,
* please add properties below.
* You should config goodix_int_pull_up node in
* the pinctrl dtsi file */
pinctrl-names = "default";
pinctrl-0 = <&goodix_int_pull_up>;
};
根据上面的例子可以得出我修改的dts配置
goodix_ts@14 {
compatible = "goodix,gt1x";
reg = <0x14>;
interrupt-parent = <&pio>;
interrupts = <PD 12 IRQ_TYPE_EDGE_FALLING>;
//vdd_ana-supply = <&pm8226_l19>;
goodix,reset-gpio = <&pio PD 13 GPIO_ACTIVE_HIGH>;
goodix,irq-gpio = <&pio PD 12 GPIO_ACTIVE_HIGH>;
goodix,default-config1 = [
46 D0 02 00 05 05 3D 14 08 80
.....
.....
//省略部分参数
];
};
vdd_ana-supply用不到就不用管了,主要是确定好i2c地址,reset-gpio 和irq-gpio引脚的配置。然后default-config数据这个是触摸屏厂商会提供的配置参数。需要注意的是default-configX,这里X的序号,需要你通过触摸加载时读取sensor id获知,现在不知道可以先注释掉default-config的配置部分,等代码调好跑起来拿到sensor id在回来加上。
驱动代码适配
打开linux内核代码
drivers/input/touchscreen/Kconfig文件末尾加上我们的触摸kconfig路径
source "drivers/input/touchscreen/gt1x_new/Kconfig
endif
drivers/input/touchscreen/Makefile文件末尾加上
obj-$(CONFIG_INPUT_TOUCHSCREEN) += gt1x_new/
在Tina根目录下使用make kernel_menuconfig来选上我们新加的触摸驱动
Device Drivers > Input device support > Touchscreens
进到里面可以做一些其他的设置
然后就可以编译了,当然第一次编译难免会遇到些报错,由于D1s是riscv架构与arm不同,所以我这里需要更改gt1x_generic.h文件里的头文件引用 #include <asm/uaccess.h>
改为#include <linux/uaccess.h>
然后再次编译即可通过。
还有一个可能的报错,在gt1x.c
文件中有一个usleep会报错,可以用msleep替换,如下:
int gt1x_power_switch(int on)
{
....
//usleep(10000);
msleep(10);
return ret;
}
看下启动log
读到的i2c从地址为0x14,sensor ID为1,这样我们前面dts里的default-configX就可以改为default-config1了,我这里已经是加好了的。
出现input2基本上就没问题了。
运行下测试工具看看是否能用,执行evtest /dev/input/event2
,
另外也可以使用getevent工具,触摸屏幕就会看到打印信息