概述
根据供应商所提供的资料和驱动,通过I2C和设备树移植驱动,将驱动挂载在I2C上。
1.根据供应商提供的kernel驱动,将文件夹里的驱动文件移植到对应的文件夹
如果没有特殊需求可以直接覆盖已存在的文件。
2.设备树中在对应的i2c下添加以下内容
根据供应商提供的KERNEL驱动kernel/arch/arm/boot/dts里的omap4-panda.dts
文件获取相关的设备树节点内容,添加如下设备树节点。
本例是以全志R818为例:
twi1: twi@0x05002400{
clock-frequency = <400000>;
pinctrl-0 = <&twi1_pins_a>;
pinctrl-1 = <&twi1_pins_b>;
status = "okay";
tsc@24 {
compatible = "cy,cyttsp5_i2c_adapter";
reg = <0x24>;
/* 这里是全志的配置方式与默认的方式不同 */
/* 具体方式请自行根据平台而定*/
interrupt-parent = <&pio>;
/* 代表中断脚是gpio11下的第7脚*/
interrupts = < PL 7 IRQ_TYPE_LEVEL_HIGH>;
/* 代表中断脚是gpio2下的第6脚,2表示中断方式为high-to-low edge triggered */
/* interrupts = <6 2>;*/
/* interrupt-parent = <&gpio2>;*/
cy,adapter_id = "cyttsp5_i2c_adapter";
cy,core {
cy,name = "cyttsp5_core";
//data G23 clock H22
cy,irq_gpio = <359>; /* GPIO PL7 */
cy,rst_gpio = <161>; /* GPIO PF1 */
cy,hid_desc_register = <1>;
/*CY_CORE_FLAG_RESTORE_PARAMETERS */
cy,flags = <4>;
/* CY_CORE_EWG_NONE */
cy,easy_wakeup_gesture = <0>;
cy,btn_keys = <172 /* KEY_HOMEPAGE */
/* previously was KEY_HOME, new Android versions use KEY_HOMEPAGE */
139 /* KEY_MENU */
158 /* KEY_BACK */
217 /* KEY_SEARCH */
114 /* KEY_VOLUMEDOWN */
115 /* KEY_VOLUMEUP */
212 /* KEY_CAMERA */
116>; /* KEY_POWER */
cy,btn_keys-tag = <0>;
cy,mt {
cy,name = "cyttsp5_mt";
cy,inp_dev_name = "cyttsp5_mt";
/* CY_MT_FLAG_FLIP | CY_MT_FLAG_INV_X | CY_MT_FLAG_INV_Y */
cy,flags = <0x38>; /* 代表触摸原点位置,修改他可以修改原点位置 */
cy,abs =
/* ABS_MT_POSITION_X, CY_ABS_MIN_X, CY_ABS_MAX_X, 0, 0 */
<0x35 0 880 0 0
/* ABS_MT_POSITION_Y, CY_ABS_MIN_Y, CY_ABS_MAX_Y, 0, 0 */
0x36 0 1280 0 0
/* ABS_MT_PRESSURE, CY_ABS_MIN_P, CY_ABS_MAX_P, 0, 0 */
0x3a 0 255 0 0
/* CY_IGNORE_VALUE, CY_ABS_MIN_W, CY_ABS_MAX_W, 0, 0 */
0xffff 0 255 0 0
/* ABS_MT_TRACKING_ID, CY_ABS_MIN_T, CY_ABS_MAX_T, 0, 0 */
0x39 0 15 0 0
/* ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0 */
0x30 0 255 0 0
/* ABS_MT_TOUCH_MINOR, 0, 255, 0, 0 */
0x31 0 255 0 0
/* ABS_MT_ORIENTATION, -127, 127, 0, 0 */
0x34 0xffffff81 127 0 0
/* ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0 */
0x37 0 1 0 0
/* ABS_MT_DISTANCE, 0, 255, 0, 0 */
0x3b 0 255 0 0>;
cy,vkeys_x = <1280>;
cy,vkeys_y = <600>;
cy,virtual_keys = /* KeyCode CenterX CenterY Width Height */
/* KEY_BACK */
<158 1360 90 160 180
/* KEY_MENU */
139 1360 270 160 180
/* KEY_HOMEPAGE */
172 1360 450 160 180
/* KEY SEARCH */
217 1360 630 160 180>;
};
cy,btn {
cy,name = "cyttsp5_btn";
cy,inp_dev_name = "cyttsp5_btn";
};
cy,proximity {
cy,name = "cyttsp5_proximity";
cy,inp_dev_name = "cyttsp5_proximity";
cy,abs =
/* ABS_DISTANCE, CY_PROXIMITY_MIN_VAL, CY_PROXIMITY_MAX_VAL, 0, 0 */
<0x19 0 1 0 0>;
};
};
};
};
这里值得注意的是
twi1_pins_a
和twi1_pins_b
所对应的"twi1_scl", "twi1_sda";cy,irq_gpio
= <359>; GPIO PL7和cy,rst_gpio
= <161>; GPIO PF1 ,对应GPIO引脚配置irq
和rst
interrupt-parent
和interrupts
中断的配置在注释中有说明。cy,flags = <0x18>;
代表触摸原点位置,修改他可以修改原点位置。0x18
:适配于标准版卡,触摸正常、0x08
:左右触摸反、0x38
:上下触摸反
3.修改makefile、kconfig、kernel_menuconfig或menuconfig,将驱动编译进内核
可以直接替换目标文件:
kernel/drivers/input/touchscreen/Kconfig
kernel/drivers/input/touchscreen/Makefile
或者将cyttsp5相关的部分复制到对应文件中。
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5) += cyttsp5.o //需要Y
cyttsp5-y := cyttsp5_core.o cyttsp5_mt_common.o //默认Y
cyttsp5-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_MT_A) += cyttsp5_mta.o
cyttsp5-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_MT_B) += cyttsp5_mtb.o //需要Y
cyttsp5-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_BUTTON) += cyttsp5_btn.o //根据需要选择
cyttsp5-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PROXIMITY) += cyttsp5_proximity.o //根据需要选择
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEVICETREE_SUPPORT) += cyttsp5_devtree.o //需要Y
ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5
obj-y += cyttsp5_platform.o //默认Y
endif
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_I2C) += cyttsp5_i2c.o //需要Y
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_SPI) += cyttsp5_spi.o //根据需要选择
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEBUG_MDL) += cyttsp5_debug.o
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_LOADER) += cyttsp5_loader.o
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEVICE_ACCESS) += cyttsp5_device_access.o //根据需要选择
obj-$(CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_TEST_DEVICE_ACCESS_API) += cyttsp5_test_device_access_api.o
由于时序问题, 强烈建议选Y以此将驱动编译进内核中。
目前已经可以在getevent中看到我们的节点, 也可以通过启动log查看,并且通过cat对应节点看到触屏反应会是一堆乱码但已经证明触控可用了。
cyttsp5_i2c_adapter 1-0024: cyttsp5_init: INIT CYTTSP RST gpio=161 and IRQ gpio=359 r=0
cyttsp5_i2c_adapter 1-0024: cyttsp5_startup_: Operational mode
cyttsp5_i2c_adapter 1-0024: cyttsp5_startup_: Init report descriptor
cyttsp5_i2c_adapter 1-0024: cyttsp5 Protocol Version: 1.6
cyttsp5_i2c_adapter 1-0024: cyttsp5_startup_: Panel ID=0xff
random: fast init done
input: cyttsp5_mt as /devices/platform/soc/twi1/i2c-1/1-0024/input/input1
input: cyttsp5_btn as /devices/platform/soc/twi1/i2c-1/1-0024/input/input2
input: cyttsp5_proximity as /devices/platform/soc/twi1/i2c-1/1-0024/input/input3
cyttsp5_device_access_init: Parade TTSP Device Access Driver (Built TTDA.03.08.874312) rc=0
i2c /dev entries driver
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEVICETREE_SUPPORT=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_I2C=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_SPI=y
# CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_MT_A is not set
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_MT_B=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_BUTTON=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_PROXIMITY=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEVICE_ACCESS=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEVICE_ACCESS_API=y
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_TEST_DEVICE_ACCESS_API=y
# CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_LOADER is not set
# CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEBUG_MDL is not set
这里额外扩展:如果menuconfig中不选择Y而是M。我们需要额外的配置。
input有自己特有的.mk文件,在全志R818中的位置:package/kernel/linux/modules/input.mk
# 在其末尾添加如下配置
define KernelPackage/touchscreen-cyttsp5
SUBMENU:=$(INPUT_MODULES_MENU)
TITLE:=cyttsp5 support
FILES+=$(LINUX DIR)/drivers/input/touchscreen/cyttsp5.ko
FILES+=$(LINUX DIR)/drivers/input/touchscreen/cyttsp5_i2c.ko
FILES+=$(LINUX DIR)/drivers/input/touchscreen/cyttsp5_spi.ko
FILES+=$(LINUX DIR)/drivers/input/touchscreen/cyttsp5_device_access.ko
KCONFIG:=\
CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5=m
AUTOLOAD:=$(call AutoProbe,cyttsp5 cyttsp5_i2c cyttsp5_spi cyttsp5_device_access)
endef
define KernelPackage/touchscreen-cyttsp5/description
Enable support for cyttsp5 touchscreen port.
endef
$(eval $(call KernelPackage,touchscreen-cyttsp5))
数据的问题自行处理吧,至此结束;