Rockchip RK3399 - USB触摸屏接口驱动

----------------------------------------------------------------------------------------------------------------------------

开发板 :NanoPC-T4开发板eMMC16GBLPDDR34GB
显示屏 :15.6英寸HDMI接口显示屏u-boot2023.04linux6.3
----------------------------------------------------------------------------------------------------------------------------

一、触摸屏接口分类

触摸屏主要包括电阻触摸屏和电容触摸屏,这个我们在《linux驱动移植-LCD触摸屏设备驱动》中已经详细介绍了,这里不再重复介绍。

在《linux驱动移植-LCD触摸屏设备驱动》这篇文章中我们介绍了SoC S3C2440触摸屏驱动的实现,对于S3C2440来说,其只支持四线电阻触摸屏。在测试时我们使用的LCD型号为LCD-T35(TD035STEB4),其4线连接在S3C2440AIN4~AIN7引脚上,通过AIN4~AIN7引脚来接收模拟输入信号。

在驱动程序中,我们通过接收触摸屏按下/松开中断,在中断处理程序中获取ADC采样值,计算X/Y坐标,并上报坐标、点击等事件。

当前市面上使用的触摸屏一般都使用了I2C接口,当然也有SPIUSB等接口。同时支持多点触摸,那什么是多点触摸呢?

顾名思义,多点触摸技术指的是允许用户同时通过多个手指来控制图形界面的一种技术,与多点触摸技术相对应的当然就是单点触摸。

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要设置为truelinux内核会自动分配一个 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 PHYUSB3.0 Type-C PHY0USB2.0 OTG PHY0

因此对应的设备树配置,包括USB3.0/2.0 OTG0(DWC3/xHCI)控制器设备树配置和USB3.0 Type-C PHY0、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_S3VCCA1V8_S3VCC3V3_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_TYPECRT9724GQW提供的,其输入端为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命令将内核镜像烧录到eMMC0x8000个扇区处:

=> 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触摸屏连接起来,如下图所示:

Rockchip RK3399 - USB触摸屏接口驱动_第1张图片
Rockchip RK3399 - USB触摸屏接口驱动_第2张图片

在内核日志中,找到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:设置DWC3HighSpeed的测试模式,用于眼图测试;

此外,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.多点电容触摸协议基本概念

你可能感兴趣的:(单片机,嵌入式硬件)