----------------------------------------------------------------------------------------------------------------------------
开发板 :NanoPC-T4
开发板eMMC
:16GB
LPDDR3
:4GB
显示屏 :15.6
英寸HDMI
接口显示屏u-boot
:2023.04
linux
:6.3
----------------------------------------------------------------------------------------------------------------------------
一、触摸屏接口分类
触摸屏主要包括电阻触摸屏和电容触摸屏,这个我们在《linux
驱动移植-LCD
触摸屏设备驱动》中已经详细介绍了,这里不再重复介绍。
在《linux
驱动移植-LCD
触摸屏设备驱动》这篇文章中我们介绍了SoC
S3C2440
触摸屏驱动的实现,对于S3C2440
来说,其只支持四线电阻触摸屏。在测试时我们使用的LCD
型号为LCD-T35(TD035STEB4)
,其4线连接在S3C2440
的AIN4~AIN7
引脚上,通过AIN4~AIN7
引脚来接收模拟输入信号。
在驱动程序中,我们通过接收触摸屏按下/松开中断,在中断处理程序中获取ADC
采样值,计算X/Y
坐标,并上报坐标、点击等事件。
当前市面上使用的触摸屏一般都使用了I2C
接口,当然也有SPI
、USB
等接口。同时支持多点触摸,那什么是多点触摸呢?
顾名思义,多点触摸技术指的是允许用户同时通过多个手指来控制图形界面的一种技术,与多点触摸技术相对应的当然就是单点触摸。
1.1 I2C
接口触摸屏
首先,需要了解I2C
触摸屏的工作原理。I2C
触摸屏是一种通过I2C
接口连接到SoC
的输入设备,它的工作原理类似于普通的触摸屏。一般来言,I2C触摸屏
内部驱动板都会有一个触摸IC
,比如FT5426
;
- 此芯片一端连接触摸屏的模拟信号,对触摸动作采样然后
AD
转换; - 另一端通过
I2C
连接SoC
,即将AD
转换后的数据通过I2C
接口发给SoC
;
对于I2C
接口触摸屏来说:
-
所谓的触摸驱动本质上就是
I2C
设备驱动; -
触摸
IC
提供了中断信号引脚,当检测到触摸信息后就会触发中断,那么就要在中断处理程序里来读取触摸信息;得到的是触摸位置绝对信息以及触摸屏是否有按下;
1.2 USB
接口触摸屏
现在我手里有一个NanoPC-T4
开发板,同时还有一个15.6
英寸HDMI
接口显示屏,并且该显示屏支持Type-C
十点触摸。因此我的目标,就是移植USB
触摸屏驱动到内核6.3
版本上。
首先,需要了解usb
触摸屏的工作原理。USB
触摸屏是一种通过USB
接口连接到SoC
的输入设备,它的工作原理类似于普通的触摸屏。一般来言,USB
触摸屏内部驱动板都会有一个USB
芯片;
- 此芯片一端连接触摸屏的模拟信号,对触摸动作采样然后AD转换;
- 另一端通过
USB
连接SoC
,即将AD
转换后的数据通过USB
接口发给SoC
;
在linux
内核中,USB HID transport layer
驱动程序实现了USB
接口的HID
设备,其中包括USB
接口的keyboards
(键盘)、mice
(鼠标)、joysticks
(摇杆)、graphic tablets
(绘图板)、触摸屏等其他的。具体来说,它会通过USB
总线获取来自触摸屏的数据,并将其转换为标准的输入事件(例如按键、鼠标移动等),然后将其传递给系统。
二、多点触摸
2.1 多点触摸协议
在linux
内核中有一份详细的文档介绍了多点电容触摸协议,位置在Documentation/input/multi-touch-protocol.rst
,多点触摸协议又简称MT
协议,MT
协议又分为:
TypeA
:适用于触摸点不能被区分或者跟踪触摸设备,此类型的设备上报原始数据,这种类型用得比较少;TypeB
:适用于触摸点能够被硬件追踪并区分触摸点的触摸设备,两次相同的触摸数据不上报,而是缓存在slot
对象中,且通过slot
更新某一个触摸点的信息;FT5626
就属于才类型,一般的多点触摸IC
都有此能力。
2.2 多点触摸事件
触摸点的信息是通过一系列ABS_MT
事件上报给linux
内核,只有ABS_MT
事件用于多点触摸,ABS_MT
事件定义在文件include/uapi/linux/input-event-codes.h
中,相关定义为:
/*
* 0x2e is reserved and should not be used in input drivers.
* It was used by HID as ABS_MISC+6 and userspace needs to detect if
* the next ABS_* event is correct or is just ABS_MISC + n.
* We define here ABS_RESERVED so userspace can rely on it and detect
* the situation described above.
*/
#define ABS_RESERVED 0x2e
#define ABS_MT_SLOT 0x2f /* MT slot being modified */
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
#define ABS_MT_POSITION_X 0x35 /* Center X touch position */
#define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */
#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
#define ABS_MT_DISTANCE 0x3b /* Contact hover distance */
#define ABS_MT_TOOL_X 0x3c /* Center X tool position */
#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */
其中:
ABS_MT_SLOT
:上报触摸点ID
;ABS_MT_TRACKING_ID
:为触摸点分配ID
,用于轨迹跟踪;ABS_MT_POSITION_X
:上报触摸点X
轴坐标信息;ABS_MT_POSITION_Y
:上报触摸点Y
轴坐标信息;ABS_MT_TOUCH_MAJOR
:上报触摸区域长轴信息(触点椭圆形);ABS_MT_WIDTH_MAJOR
:上报触摸区域短轴信息(触点椭圆形);
2.2.1 TYPE A
TYPE A
上报方式:
ABS_MT_POSITION_X x[0] // 第一个点X轴坐标
ABS_MT_POSITION_Y y[0] // 第一个点Y轴坐标
SYN_MT_REPORT // 点与点之间使用
ABS_MT_POSITION_X x[1] // 第二个点X轴坐标
ABS_MT_POSITION_Y y[1] // 第二个点Y轴坐标
SYN_MT_REPORT // 点与点之间使用
SYN_REPORT //同步事件
(1) 上报触摸点的X
轴坐标和Y
轴坐标,通过 input_report_abs
函数来完成,此函数原型如下所示:
static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value)
{
input_event(dev, EV_ABS, code, value);
}
(2) 对于TYPE A
类型的设备,通过input_mt_sync
函数来隔离不同的触摸点数据信息,此函数原型如下所示:
tatic inline void input_mt_sync(struct input_dev *dev)
{
input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
}
此函数只有1个参数,类型为input_dev
,用于指定具体的input_dev
设备,input_mt_sync
函数会触发同步事件SYN_MT_REPORT
事件码,此事件会通知接收者获取当前触摸数据,并且准备接收下一个触摸点数据。
(3) 当所有的触摸点坐标都上传完毕以后就得发送SYN_REPORT
事件,使用input_sync
函数来完成;
static inline void input_sync(struct input_dev *dev)
{
input_event(dev, EV_SYN, SYN_REPORT, 0);
}
2.2.2 TYPE B
TYPE B
上报方式:
ABS_MT_SLOT 0 // 上报触摸点序号
ABS_MT_TRACKING_ID 45 // 为触摸点分配ID
ABS_MT_POSITION_X x[0] // 上报触摸点X轴坐标信息
ABS_MT_POSITION_Y y[0] // 上报触摸点Y轴坐标信息
ABS_MT_SLOT 1 // 以下同上
ABS_MT_TRACKING_ID 46
ABS_MT_POSITION_X x[1]
ABS_MT_POSITION_Y y[1]
SYN_REPORT // 同步事件
(1) 对于TYPE B
类型的设备,上报触摸点信息的时候需要通过input_mt_slot
函数来区分是哪一个触摸点,此函数原型如下所示:
static inline void input_mt_slot(struct input_dev *dev, int slot)
{
input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
}
此函数只有2个参数:
- 第一个参数为
input_dev
设备; - 第二个参数
slot
用于指定当前上报的是哪个触摸点的信息;
input_mt_slot
函数会触发绝对位移事件ABS_MT_SLOT
事件码,此事件会告诉接收者当前正在更新的是哪个触摸点(slot
)的数据。
(2) 根据Type B
的要求,每个slot
必须关联一个ABS_MT_TRACKING_ID
,通过修改slot
关联的 ABS_MT_TRACKING_ID
来完成对触摸点的添加、替换或删除。具体用到的函数就是 input_mt_report_slot_state
;
bool input_mt_report_slot_state(struct input_dev *dev,
unsigned int tool_type, bool active);
如果是添加一个新的触摸点,那么此函数的第三个参数active
要设置为true
, linux
内核会自动分配一个 ABS_MT_TRACKING_ID
值,不需要用户去指定具体的 ABS_MT_TRACKING_ID
值。
三、测试
本节实验是在《Rockchip RK3399
-USB
调试》文章的基础上进行的,因此需要先参考这篇文章进行内核和设备树的配置。
3.1 配置设备树
由于我们的触摸屏为Type C
接口,而我们使用的开发板NanoPC-T4
只有1个USB3.0 Type-C
接口,因此我们需要将这个接口配置为HOST
(主机)。
USB3.0 Type-C
接口对应的USB
控制器为USB3.0/2.0 OTG0(DWC3/xHCI)
、对应的USB PHY
为USB3.0 Type-C PHY0
和USB2.0 OTG PHY0
;
因此对应的设备树配置,包括USB3.0/2.0 OTG0(DWC3/xHCI)
控制器设备树配置和USB3.0 Type-C PHY
0、USB2.0 OTG PHY0
设备树配置。
3.1.1 控制器配置
(1) USB3.0/2.0 OTG0(DWC3/xHCI)
控制器设备节点usbdrd3_0
,定义在arch/arm64/boot/dts/rockchip/rk3399.dtsi
;
usbdrd3_0: usb@fe800000 {
compatible = "rockchip,rk3399-dwc3";
#address-cells = <2>;
#size-cells = <2>;
ranges;
clocks = <&cru SCLK_USB3OTG0_REF>, <&cru SCLK_USB3OTG0_SUSPEND>,
<&cru ACLK_USB3OTG0>, <&cru ACLK_USB3_RKSOC_AXI_PERF>,
<&cru ACLK_USB3>, <&cru ACLK_USB3_GRF>;
clock-names = "ref_clk", "suspend_clk",
"bus_clk", "aclk_usb3_rksoc_axi_perf",
"aclk_usb3", "grf_clk";
resets = <&cru SRST_A_USB3_OTG0>;
reset-names = "usb3-otg";
status = "disabled";
usbdrd_dwc3_0: usb@fe800000 {
compatible = "snps,dwc3";
reg = <0x0 0xfe800000 0x0 0x100000>;
interrupts = ;
clocks = <&cru SCLK_USB3OTG0_REF>, <&cru ACLK_USB3OTG0>,
<&cru SCLK_USB3OTG0_SUSPEND>;
clock-names = "ref", "bus_early", "suspend";
dr_mode = "otg";
phys = <&u2phy0_otg>, <&tcphy0_usb3>;
phy-names = "usb2-phy", "usb3-phy";
phy_type = "utmi_wide";
snps,dis_enblslpm_quirk;
snps,dis-u2-freeclk-exists-quirk;
snps,dis_u2_susphy_quirk;
snps,dis-del-phy-power-chg-quirk;
snps,dis-tx-ipgap-linecheck-quirk;
power-domains = <&power RK3399_PD_USB3>;
status = "disabled";
};
};
3.1.2 PHY
配置
(1) USB3.0 Type-C PHY0
设备节点tcphy0_usb3
,定义在arch/arm64/boot/dts/rockchip/rk3399.dtsi
;
tcphy0: phy@ff7c0000 {
compatible = "rockchip,rk3399-typec-phy";
reg = <0x0 0xff7c0000 0x0 0x40000>;
clocks = <&cru SCLK_UPHY0_TCPDCORE>,
<&cru SCLK_UPHY0_TCPDPHY_REF>;
clock-names = "tcpdcore", "tcpdphy-ref";
assigned-clocks = <&cru SCLK_UPHY0_TCPDCORE>;
assigned-clock-rates = <50000000>;
power-domains = <&power RK3399_PD_TCPD0>;
resets = <&cru SRST_UPHY0>,
<&cru SRST_UPHY0_PIPE_L00>,
<&cru SRST_P_UPHY0_TCPHY>;
reset-names = "uphy", "uphy-pipe", "uphy-tcphy";
rockchip,grf = <&grf>;
status = "disabled";
tcphy0_dp: dp-port {
#phy-cells = <0>;
};
tcphy0_usb3: usb3-port {
#phy-cells = <0>;
};
};
(2) USB2.0 OTG PHY0
设备节点u2phy0_otg
,定义在arch/arm64/boot/dts/rockchip/rk3399.dtsi
;
u2phy0: usb2phy@e450 {
compatible = "rockchip,rk3399-usb2phy";
reg = <0xe450 0x10>;
clocks = <&cru SCLK_USB2PHY0_REF>;
clock-names = "phyclk";
#clock-cells = <0>;
clock-output-names = "clk_usbphy0_480m";
status = "disabled";
u2phy0_host: host-port {
#phy-cells = <0>;
interrupts = ;
interrupt-names = "linestate";
status = "disabled";
};
u2phy0_otg: otg-port {
#phy-cells = <0>;
interrupts = ,
,
;
interrupt-names = "otg-bvalid", "otg-id",
"linestate";
status = "disabled";
};
};
3.1.3 电源配置
(1) USB2.0 PHY0
芯片三路电源依次为VCCA0V9_S3
、VCCA1V8_S3
、VCC3V3_S3
;
在arch/arm64/boot/dts/rockchip/rk3399-evb.dts
配置vcc3v3_s3
设备节点;
&i2c0 {
......
rk808: pmic@1b {
......
regulators {
......
vcc3v3_s3: SWITCH_REG1 {
regulator-always-on;
regulator-boot-on;
regulator-name = "vcc3v3_s3";
regulator-state-mem {
regulator-off-in-suspend;
};
};
......
};
};
};
完整的rk808
设备节点配置参考:rk808
驱动配置。
(2) USB3.0 Type-C PHY0
芯片三路电源和USB2.0 PHY0
芯片三路电源一样。
(3) USB3.0 Type-C
接口电源VBUS_TYPEC
由RT9724GQW
提供的,其输入端为VCC5V0_SYS
。由GPIO4_D2
引脚使能,高电平有效;
在arch/arm64/boot/dts/rockchip/rk3399-evb.dts
配置vbus_typec
;
vcc5v0_sys: vcc5v0-sys {
compatible = "regulator-fixed";
regulator-name = "vcc5v0_sys";
regulator-always-on;
regulator-boot-on;
regulator-min-microvolt = <5000000>;
regulator-max-microvolt = <5000000>;
};
vbus_typec: vbus-typec {
compatible = "regulator-fixed";
enable-active-high;
gpio = <&gpio4 RK_PD2 GPIO_ACTIVE_HIGH>;
pinctrl-names = "default";
pinctrl-0 = <&vbus_typec_en>;
regulator-name = "vbus_typec";
vin-supply = <&vcc5v0_sys>;
};
由于vbus_typec
节点配置了default
状态对应的引脚配置节点为vbus_typec_en
,因此需要在pinctrl
节点下增加引脚配置节点vbus_typec_en
,这个节点在fusb
配置中介绍。
3.1.4 使能
下面介绍的都是配置在arch/arm64/boot/dts/rockchip/rk3399-evb.dts
文件。
(1) 使能usbdrd3_0
:
通过dr_mode
属性设置USB
控制器的模式:
/* Configurate and Enable USB3.0/2.0 OTG Controller notifier */
&usbdrd3_0 {
status = "okay";
};
&usbdrd_dwc3_0 {
/* 配置dr_mode为host */
dr_mode = "host";
status = "okay";
};
(2) 使能tcphy0_usb3
;
/* Enable USB3.0 PHY */
&tcphy0 {
status = "okay";
};
&tcphy0_usb3{
status = "okay";
};
(3) 使能u2phy0_otg
,同时配置USB2.0 OTG PHY0 phy-supply
属性,用于控制USB
电源VBUS
;
/* Enable USB2.0 PHY */
&u2phy0 {
status = "okay";
};
&u2phy0_otg {
phy-supply = <&vbus_typec>;
status = "okay";
};
3.2 编译内核
在linux
内核根目录下执行如下命令进行编译内核:
root@zhengyang:/work/sambashare/rk3399/linux-6.3# make -j8
u-boot-2023.04
路径下的mkimage
工具拷贝过来,然后在命令行使用mkimage
工具编译即可:
root@zhengyang:/work/sambashare/rk3399/linux-6.3# cp ../u-boot-2023.04/tools/mkimage ./
root@zhengyang:/work/sambashare/rk3399/linux-6.3# ./mkimage -f kernel.its kernel.itb
3.3 通过tftp
烧录内核
给开发板上电,同时连接上网线,进入uboot
命令行。我们将内核拷贝到tftp
文件目录:
root@zhengyang:/work/sambashare/rk3399/linux-6.3# cp kernel.itb /work/tftpboot/
接着给开发板上电。通过uboot
命令行将kernel.itb
下到内存地址0x10000000
处:
=> tftp 0x10000000 kernel.itb
通过mmc write
命令将内核镜像烧录到eMMC
第0x8000
个扇区处:
=> mmc erase 0x8000 0xA000
=> mmc write 0x10000000 0x8000 0xA000
3.4 启动内核
开发板在没有接任何USB
设备的情况下,我们重新启动开发板,输出有关USB
的信息如下:
[ 0.749841] usbcore: registered new interface driver usbfs
[ 0.755938] usbcore: registered new interface driver hub
[ 0.761854] usbcore: registered new device driver usb
[ 1.771643] xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
[ 1.772051] ehci-platform fe380000.usb: EHCI Host Controller
[ 1.772053] ehci-platform fe3c0000.usb: EHCI Host Controller
[ 1.772074] ohci-platform fe3a0000.usb: Generic Platform OHCI controller
[ 1.772077] ohci-platform fe3e0000.usb: Generic Platform OHCI controller
[ 1.772112] ehci-platform fe3c0000.usb: new USB bus registered, assigned bus number 1
[ 1.772113] ohci-platform fe3a0000.usb: new USB bus registered, assigned bus number 2
[ 1.772115] ohci-platform fe3e0000.usb: new USB bus registered, assigned bus number 3
[ 1.772299] ehci-platform fe3c0000.usb: irq 50, io mem 0xfe3c0000
[ 1.772331] ohci-platform fe3a0000.usb: irq 52, io mem 0xfe3a0000
[ 1.772355] ohci-platform fe3e0000.usb: irq 51, io mem 0xfe3e0000
[ 1.777983] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 4
[ 1.784574] ehci-platform fe380000.usb: new USB bus registered, assigned bus number 5
[ 1.788235] ehci-platform fe3c0000.usb: USB 2.0 started, EHCI 1.00
[ 1.788667] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.03
[ 1.788684] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.788696] usb usb1: Product: EHCI Host Controller
[ 1.788705] usb usb1: Manufacturer: Linux 6.3.0 ehci_hcd
[ 1.788714] usb usb1: SerialNumber: fe3c0000.usb
[ 1.789559] hub 1-0:1.0: USB hub found
[ 1.789617] hub 1-0:1.0: 1 port detected
[ 1.790801] xhci-hcd xhci-hcd.0.auto: hcc params 0x0220fe64 hci version 0x110 quirks 0x0000000002010010
[ 1.798361] ehci-platform fe380000.usb: irq 49, io mem 0xfe380000
[ 1.805744] xhci-hcd xhci-hcd.0.auto: irq 47, io mem 0xfe800000
[ 1.828031] ehci-platform fe380000.usb: USB 2.0 started, EHCI 1.00
[ 1.832194] xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
[ 1.832255] usb usb2: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.03
[ 1.832274] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.832286] usb usb2: Product: Generic Platform OHCI controller
[ 1.832296] usb usb2: Manufacturer: Linux 6.3.0 ohci_hcd
[ 1.832305] usb usb2: SerialNumber: fe3a0000.usb
[ 1.833034] hub 2-0:1.0: USB hub found
[ 1.833084] hub 2-0:1.0: 1 port detected
[ 1.833904] usb usb3: New USB device found, idVendor=1d6b, idProduct=0001, bcdDevice= 6.03
[ 1.833923] usb usb3: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 1.833935] usb usb3: Product: Generic Platform OHCI controller
[ 1.833945] usb usb3: Manufacturer: Linux 6.3.0 ohci_hcd
[ 1.833954] usb usb3: SerialNumber: fe3e0000.usb
[ 1.834695] hub 3-0:1.0: USB hub found
[ 1.834773] hub 3-0:1.0: 1 port detected
[ 1.839038] usb usb5: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.03
[ 2.052886] usb usb5: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.060998] usb usb5: Product: EHCI Host Controller
[ 2.066475] usb usb5: Manufacturer: Linux 6.3.0 ehci_hcd
[ 2.072436] usb usb5: SerialNumber: fe380000.usb
[ 2.078219] hub 5-0:1.0: USB hub found
[ 2.082470] hub 5-0:1.0: 1 port detected
[ 2.087244] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 6
[ 2.095854] xhci-hcd xhci-hcd.0.auto: Host supports USB 3.0 SuperSpeed
[ 2.103325] usb usb4: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.03
[ 2.112608] usb usb4: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.120709] usb usb4: Product: xHCI Host Controller
[ 2.126187] usb usb4: Manufacturer: Linux 6.3.0 xhci-hcd
[ 2.132144] usb usb4: SerialNumber: xhci-hcd.0.auto
[ 2.138144] hub 4-0:1.0: USB hub found
[ 2.142400] hub 4-0:1.0: 1 port detected
[ 2.147199] usb usb6: We don't know the algorithms for LPM for this host, disabling LPM.
[ 2.156396] usb usb6: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 6.03
[ 2.165669] usb usb6: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.173775] usb usb6: Product: xHCI Host Controller
[ 2.179247] usb usb6: Manufacturer: Linux 6.3.0 xhci-hcd
[ 2.185193] usb usb6: SerialNumber: xhci-hcd.0.auto
[ 2.191194] hub 6-0:1.0: USB hub found
[ 2.195446] hub 6-0:1.0: 1 port detected
[ 2.200468] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[ 2.206755] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 7
[ 2.215471] xhci-hcd xhci-hcd.1.auto: hcc params 0x0220fe64 hci version 0x110 quirks 0x0000000002010010
[ 2.226150] xhci-hcd xhci-hcd.1.auto: irq 48, io mem 0xfe900000
[ 2.232991] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[ 2.239157] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 8
[ 2.247834] xhci-hcd xhci-hcd.1.auto: Host supports USB 3.0 SuperSpeed
[ 2.255304] usb usb7: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.03
[ 2.264660] usb usb7: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.272772] usb usb7: Product: xHCI Host Controller
[ 2.278246] usb usb7: Manufacturer: Linux 6.3.0 xhci-hcd
[ 2.284289] usb usb7: SerialNumber: xhci-hcd.1.auto
[ 2.290317] hub 7-0:1.0: USB hub found
[ 2.294578] hub 7-0:1.0: 1 port detected
[ 2.299388] usb usb8: We don't know the algorithms for LPM for this host, disabling LPM.
[ 2.308570] usb usb8: New USB device found, idVendor=1d6b, idProduct=0003, bcdDevice= 6.03
[ 2.317842] usb usb8: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.325949] usb usb8: Product: xHCI Host Controller
[ 2.331420] usb usb8: Manufacturer: Linux 6.3.0 xhci-hcd
[ 2.337375] usb usb8: SerialNumber: xhci-hcd.1.auto
[ 2.343353] hub 8-0:1.0: USB hub found
[ 2.347610] hub 8-0:1.0: 1 port detected
[ 2.353592] usbcore: registered new interface driver usb-storage
[ 2.360482] usbcore: registered new interface driver pl2303
[ 2.366775] usbserial: USB Serial support registered for pl2303
[ 2.377212] usbcore: registered new interface driver usbtouchscreen
[ 3.525771] usbcore: registered new interface driver uvcvideo
[ 3.628391] usbcore: registered new interface driver usbhid
[ 3.628400] usbhid: USB HID core driver
[ 3.643290] usbcore: registered new interface driver snd-usb-audio
从上面日志上可以看到总共注册了8个USB
总线,编号依次从1~8。
3.4.1 触摸屏测试
使用Type C
连接线,将开发板USB3.0 Type-C
接口与USB
触摸屏连接起来,如下图所示:
在内核日志中,找到USB
触摸屏信息的日志:
[ 686.727914] usb 4-1: new full-speed USB device number 2 using xhci-hcd
[ 686.880023] usb 4-1: New USB device found, idVendor=222a, idProduct=0001, bcdDevice= 1.00
[ 686.880062] usb 4-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 686.880078] usb 4-1: Product: SingWon-CTP-V1.18A
[ 686.880091] usb 4-1: Manufacturer: UsbHID
[ 686.880103] usb 4-1: SerialNumber: 6F6A099B1133
[ 686.921769] input: UsbHID SingWon-CTP-V1.18A as /devices/platform/usb@fe800000/fe800000.usb/xhci-hcd.0.auto/usb4/4-1/4-1:1.0/0003:222A:0001.0001/input/input1
[ 686.922432] hid-generic 0003:222A:0001.0001: input: USB HID v1.11 Device [UsbHID SingWon-CTP-V1.18A] on usb-xhci-hcd.0.auto-1/input0
[ 686.929435] input: UsbHID SingWon-CTP-V1.18A as /devices/platform/usb@fe800000/fe800000.usb/xhci-hcd.0.auto/usb4/4-1/4-1:1.1/0003:222A:0001.0002/input/input2
[ 686.989106] hid-generic 0003:222A:0001.0002: input: USB HID v1.12 Keyboard [UsbHID SingWon-CTP-V1.18A] on usb-xhci-hcd.0.auto-1/input1
此时可以在ubuntu
桌面系统测试触摸屏,可以发现触摸屏可以正常实用。
USB
触摸屏工作在全速模式下,xHCI
控制器,USB1.1
通信协议,使用的USB
总线编号为4,设备编号为2。
3.4.2 USB3.0/2.0 OTG调试接口
以USB3.0/2.0 OTG0(DWC3/xHCI)
控制器为例,对应设备节点usbdrd3_0: usb@fe800000
:
root@rk3399:~# ll /sys/kernel/debug/usb/
-r--r--r-- 1 root root 0 Jan 1 1970 devices
drwxr-xr-x 4 root root 0 Jan 1 1970 ehci/
drwxr-xr-x 2 root root 0 Jan 1 1970 fe800000.usb/
drwxr-xr-x 2 root root 0 Jan 1 1970 fe900000.usb/
drwxr-xr-x 2 root root 0 Jan 1 1970 fusb302-4-0022/
drwxr-xr-x 4 root root 0 Jan 1 1970 ohci/
drwxr-xr-x 2 root root 0 Jan 1 1970 tcpm-4-0022/
drwxr-xr-x 2 root root 0 Jan 1 1970 uvcvideo/
drwxr-xr-x 4 root root 0 Jan 1 1970 xhci/
root@rk3399:~# ll /sys/kernel/debug/usb/fe800000.usb/
-rw-r--r-- 1 root root 0 Jan 1 1970 link_state
-rw-r--r-- 1 root root 0 Jan 1 1970 lsp_dump
-rw-r--r-- 1 root root 0 Jan 1 1970 mode
-r--r--r-- 1 root root 0 Jan 1 1970 regdump
-rw-r--r-- 1 root root 0 Jan 1 1970 testmode
其中:
link_state
:打印DWC3
的链路状态;regdump
:打印DWC3
控制器的寄存器状态信息;mode
:打印DWC3
的工作模式;testmode
:设置DWC3
进HighSpeed
的测试模式,用于眼图测试;
此外,DWC3
控制器驱动还实现了基于内核trace
框架的tracepoint
,支持动态使能并保存DWC3
驱动关键信息。
我们可以查看USB3.0/2.0 OTG0
控制器的工作模式:
root@rk3399:/# cat /sys/kernel/debug/usb/fe800000.usb/mode
host
可以看到USB3.0/2.0 OTG0
控制器工作在HOST
(主机)模式。
参考文章
[1] linux
驱动移植-usb
鼠标接口驱动
[2] usb4
-配置usb
触摸屏
[3] 138.多点电容触摸协议基本概念