首页 > 其他分享 >USB TCPM

USB TCPM

时间:2024-09-01 12:52:27浏览次数:9  
标签:RESET USB HARD SNK TCPM state AMS change

USB TCPM(Type-C Port Manager)的主要作用是管理 USB Type-C 端口的连接和电源传输协议(USB Power Delivery, PD),确保设备正确识别、协商和切换数据传输和电源供应的角色。TCPM 在 USB Type-C 连接中起到关键管理作用,主要职责包括:

  1. 管理 USB Type-C 插拔检测:检测设备的插入和拔出事件,识别连接器的方向(翻转)和线缆类型,并做出相应的配置调整。

  2. 协商电力传输:与 USB PD 控制器(如 TCPC)配合,通过 PD 协议与对端设备协商电力供应,确定电压和电流等级,并动态调整电力配置以匹配设备的需求。

  3. 角色管理:决定设备在 USB 连接中的角色(主机或设备、供电方或受电方),并根据连接情况和协议协商结果,动态切换这些角色。

  4. 配合 PD 控制器(TCPC):TCPM 通常与 TCPC(Type-C Port Controller)协同工作。TCPC 是具体实现 PD 协议硬件通信的控制器,而 TCPM 作为软件部分,负责控制 TCPC 和处理高层的协议逻辑。

  5. 安全和错误处理:监控连接状态,处理异常情况(如过流、短路、异常拔插),确保连接的安全性和稳定性。

通过 TCPM 的管理,可以实现 USB Type-C 设备之间的智能互操作,确保数据传输和电力传输的安全、灵活和高效。

tcpm的工作细节

在我们平时工作中adb使用typec口,来进行调试是常有的事情,那么在typec插上的一瞬间是就是通过tcpm来建立最初的联系,然后通知到dwc3和gadget来进行交互的,后面的工作就完全交给dwc3那边进行处理。

可以从/sys/kernel/debug/usb/tcpm-xxx下,抓取一份tcpm的log,这里抓取了一份RK平台,从开机到adb数据线设备插拔的过程log,来分析整个数据流程:

	1. 一些重要参数的初始化值
	port->port_type = TYPEC_PORT_DRP
	port->prefer_role = TYPEC_SINK
	port->data_role = TYPEC_DEVICE;
	port->pwr_role = TYPEC_SINK;
	port->try_role = TYPEC_SINK;

	port->state = SNK_UNATTACHED
	port->vbus_never_low = false
	port->pd_capable = false
	tcpm_rp_cc(port) = TYPEC_CC_RP_3_0

	2. 一些重要参数的变动
	port->vbus_present = false -> _tcpm_pd_vbus_on() -> ture
	port->vbus_vsafe0v = true -> _tcpm_pd_vbus_on() -> false

	3. 状态机转变state的整个调用流程
	tcpm_set_state -> kthread_queue_work(port->wq, &port->state_machine) 
	--> tcpm_state_machine_work -> run_state_machine

	4. 抓取到的整个数据流程包含tcpm初始化,插入/拔出adb数据线
	rk3568_s:/sys/kernel/debug/usb/tcpm-0-004e # cat log
	// 开机时启动后,初始阶段的log
	[    3.169614] init extcon finished
	[    3.173249] Setting usb_comm capable false
	[    3.174716] Setting voltage/current limit 0 mV 0 mA
	[    3.174728] polarity 0
	[    3.176800] Requesting mux state 0, usb-role 0, orientation 0
	[    3.178567] state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
	[    3.179503] CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
	[    3.179510] state change SNK_UNATTACHED -> PORT_RESET [rev1 NONE_AMS]
	[    3.179520] 0-004e: registered
	[    3.179530] Setting usb_comm capable false
	[    3.181007] Setting voltage/current limit 0 mV 0 mA
	[    3.181023] polarity 0
	[    3.183097] Requesting mux state 0, usb-role 0, orientation 0
	[    3.184351] cc:=0
	[    3.185144] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
	[    3.185154] state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
	[    3.185159] state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
	[    3.185163] Start toggling
	[    3.185831] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]

	//插入typec后,tcpm的log,其中"======>" 这种箭头的打印是我本人加的
	[   53.680304][  T152] =================> tcpci_irq -> status[0x02]
	[   53.681360] VBUS on
	[   53.705497][  T152] =================> tcpci_irq -> status[0x01]
	[   53.706613] CC1: 0 -> 3, CC2: 0 -> 0 [state TOGGLING, polarity 0, connected]
	[   53.706627] state change TOGGLING -> SNK_ATTACH_WAIT [rev1 NONE_AMS]
	[   53.706644] pending state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED @ 200 ms [rev1 NONE_AMS]
	[   53.906677] state change SNK_ATTACH_WAIT -> SNK_DEBOUNCED [delayed 200 ms]
	[   53.906691] state change SNK_DEBOUNCED -> SNK_ATTACHED [rev1 NONE_AMS]
	[   53.906695] polarity 0
	[   53.908791][  T151] emdoor: tcpm_set_polarity typec positive
	[   53.908862] Requesting mux state 1, usb-role 2, orientation 1
	[   53.909477][  T151] husb311 0-004e: CC connected in CC1 as UFP
	[   53.909744] state change SNK_ATTACHED -> SNK_STARTUP [rev1 NONE_AMS]
	[   53.909755] state change SNK_STARTUP -> SNK_DISCOVERY [rev3 NONE_AMS]
	[   53.909759] Setting voltage/current limit 5000 mV 0 mA
	[   53.909775] vbus=0 charge:=1
	[   53.910560] state change SNK_DISCOVERY -> SNK_WAIT_CAPABILITIES [rev3 NONE_AMS]
	[   53.910951] pending state change SNK_WAIT_CAPABILITIES -> HARD_RESET_SEND @ 310 ms [rev3 NONE_AMS]
	[   54.221059] state change SNK_WAIT_CAPABILITIES -> HARD_RESET_SEND [delayed 310 ms]
	[   54.221080] AMS HARD_RESET start
	[   54.221083] PD TX, type: 0x5
	[   54.223648][  T152] =================> tcpci_irq -> status[0x50]
	[   54.223737] PD TX complete, status: 0
	[   54.223819] state change HARD_RESET_SEND -> HARD_RESET_START [rev3 HARD_RESET]
	[   54.225211] state change HARD_RESET_START -> SNK_HARD_RESET_SINK_OFF [rev3 HARD_RESET]
	[   54.225235] vconn:=0
	[   54.225747] Requesting mux state 1, usb-role 2, orientation 1
	[   54.226346] pending state change SNK_HARD_RESET_SINK_OFF -> SNK_HARD_RESET_SINK_ON @ 650 ms [rev3 HARD_RESET]
	[   54.876427] state change SNK_HARD_RESET_SINK_OFF -> SNK_HARD_RESET_SINK_ON [delayed 650 ms]
	[   54.876447] AMS HARD_RESET finished
	[   54.876850] state change SNK_HARD_RESET_SINK_ON -> SNK_STARTUP [rev3 NONE_AMS]
	[   54.876871] state change SNK_STARTUP -> SNK_DISCOVERY [rev3 NONE_AMS]
	[   54.876875] Setting voltage/current limit 5000 mV 0 mA
	[   54.876896] state change SNK_DISCOVERY -> SNK_WAIT_CAPABILITIES [rev3 NONE_AMS]
	[   54.877264] pending state change SNK_WAIT_CAPABILITIES -> HARD_RESET_SEND @ 310 ms [rev3 NONE_AMS]
	[   55.187319] state change SNK_WAIT_CAPABILITIES -> HARD_RESET_SEND [delayed 310 ms]
	[   55.187339] AMS HARD_RESET start
	[   55.187343] PD TX, type: 0x5
	[   55.189910][  T152] =================> tcpci_irq -> status[0x50]
	[   55.189982] PD TX complete, status: 0
	[   55.190020] state change HARD_RESET_SEND -> HARD_RESET_START [rev3 HARD_RESET]
	[   55.191474] state change HARD_RESET_START -> SNK_HARD_RESET_SINK_OFF [rev3 HARD_RESET]
	[   55.191494] vconn:=0
	[   55.192023] Requesting mux state 1, usb-role 2, orientation 1
	[   55.192727] pending state change SNK_HARD_RESET_SINK_OFF -> SNK_HARD_RESET_SINK_ON @ 650 ms [rev3 HARD_RESET]
	[   55.842808] state change SNK_HARD_RESET_SINK_OFF -> SNK_HARD_RESET_SINK_ON [delayed 650 ms]
	[   55.842828] AMS HARD_RESET finished
	[   55.843201] state change SNK_HARD_RESET_SINK_ON -> SNK_STARTUP [rev3 NONE_AMS]
	[   55.843214] state change SNK_STARTUP -> SNK_DISCOVERY [rev3 NONE_AMS]
	[   55.843217] Setting voltage/current limit 5000 mV 0 mA
	[   55.843238] state change SNK_DISCOVERY -> SNK_WAIT_CAPABILITIES [rev3 NONE_AMS]
	[   55.843604] pending state change SNK_WAIT_CAPABILITIES -> SNK_READY @ 310 ms [rev3 NONE_AMS]
	[   56.153719] state change SNK_WAIT_CAPABILITIES -> SNK_READY [delayed 310 ms]

	// 拔出typec时,tcpm的打印
	[ 2087.027300][  T152] =================> tcpci_irq -> status[0x01]
	[ 2087.028556] CC1: 3 -> 0, CC2: 0 -> 0 [state SNK_READY, polarity 0, disconnected]
	[ 2087.028574] state change SNK_READY -> SNK_UNATTACHED [rev3 NONE_AMS]
	[ 2087.028585] disable BIST MODE TESTDATA
	[ 2087.029540] Setting usb_comm capable false
	[ 2087.031079] Setting voltage/current limit 0 mV 0 mA
	[ 2087.031116] polarity 0
	[ 2087.033294][  T151] emdoor: tcpm_set_polarity typec positive
	[ 2087.033323] Requesting mux state 0, usb-role 0, orientation 0
	[ 2087.034933] Start toggling
	[ 2087.035701] state change SNK_UNATTACHED -> TOGGLING [rev3 NONE_AMS]
	[ 2087.046906][  T152] =================> tcpci_irq -> status[0x02]
	[ 2087.048083] VBUS off
	[ 2087.048095] VBUS VSAFE0V

从log内,进一步分析整个tcpm的运行流程,总结了出如下流程图:
image

同样关于插入的过程也总结了如下流程图:
image

标签:RESET,USB,HARD,SNK,TCPM,state,AMS,change
From: https://www.cnblogs.com/linhaostudy/p/18391198

相关文章

  • USB相关的sysfs文件
    前言在sysfs文件系统下,查看USB设备,看到一些乱七八糟的设备显示,它们都是什么呢?今天来介绍一下。root@ATK-IMX6U:~#ls/sys/bus/usb/devices/1-0:1.01-11-1.11-1:1.01-1.1:1.01-1.1:1.11-1.31-1.3:1.01-1.3:1.1usb1目录内容详解usb1usb1表示该 SOC......
  • Android Qcom USB Driver学习(十四)
    UDC-GadgetUDC:(USBDeviceController)用于管理和控制USB设备与主机之间的通信。Gadget:Android在此层实现了adb,mtp(MediaTransferProtocol媒体传输协议),mass_storage等。早期的USB只支持单一的gadget设备,使用场景较为简单,随后加入了compositeframework,用来支持多个function......
  • Android Qcom USB Driver学习(十三)
    DPMDevicePolicyManagerdealswiththeUSBPowerDeliveryresourcesusedbyoneormoreportsonthebasisofthelocaldevicepolicythebasisofthelocaldevicepolicy.OPMOSPolicyManageroperatingSoftwarethatinterfaceswiththePPMPPMPlatfor......
  • Android Qcom USB Driver学习(十二)
    keypad在suspend的过程中导致Android无法进入suspend的问题,导致整体功耗过高,其实是主机都没有进入睡眠,通过以下打log的方式最终定位到问题,pmicvbus输出的时候会有reverseboost所以pmic侧的功耗也会有增加,当pmic电量低的时候会触发uvlo导致vbus上的电断开,需要需要的话,我们可以降......
  • linux下UsbMon-WireShark之USB协议抓取分析
    usbmon配置使用usbmon抓包分的,是需要内核开启CONFIG_USB_MON=m,重新编译内核,编译ko:makeARCH=arm64CROSS_COMPILE=aarch64-himix100-linux-CONFIG_USB_MON=mM=./drivers/usb/modules设备挂载debugfs,加载ko:mount-tdebugfsdebugfs/sys/kernel/debug/insmod......
  • Windows下使用Wireshark分析USB通信
    WireShark中对USB数据捕获可以监视与主机连接的usb数据.usb设备是三段地址描述,例如1.15.1,第一个是总线,第二个是设备地址,第三个是端口.USB数据抓包分析这些是鼠标的数据包包抓包内容键盘数据包,按下一个键后抓到的数据包,查询usb标准,对照后是a。......
  • USB设置之间通信
    在电脑上连接的USB设备之间,通常不能直接通信。USB(通用串行总线)是一种主从结构的总线系统,其中只有一个USB主机(通常是电脑),而其他连接的设备都作为从机。在这种结构中,设备之间的通信必须通过USB主机进行转发,即设备不能直接与其他设备交换数据或信号。USB主机负责控制和管理所有连接......
  • Q: USB无线网卡搜不到路由器WiFi,但也能搜索到少部分信号。
    原因分析:一般在路由器的配置的无线信道是自动,路由器的2.4G频段有13个左右交叠的信道。由于USB无线网卡的设置信道区间可能不在无线信道范围内,导致无线网卡搜索不到对应wifi。解决问题:鼠标右键点击任务栏上的网络图标,点击“打开网络和Internet设置”,在弹出的设置窗口左边选择......
  • Android Qcom USB Driver学习(十一)
    基于TI的FirmwareUpdate固件升级的流程分析usbapplictionlayers的数据USBProtocolPackage①/②maptocheckpasswordcorrectPackageFormat:Byte[0]=ReportIdByte[1]=ValidLength(0x21=33)Byte[2]=BSLCoreCommands(0x11RXPassword)Byte[3]=Val......
  • USB 逻辑分析仪分析丢包怎么分析(lecroy USB 逻辑分析仪)
    使用LeCroyUSB逻辑分析仪分析USB数据传输中的丢包现象,通常涉及以下步骤:1.设置触发条件在LeCroyUSB逻辑分析仪中,设置适当的触发条件来捕获数据包丢失的场景。常见的触发条件可以包括:特定的PID(PacketIdentifier)值,如DATA0或DATA1。错误类型,如CRCError(循环冗余......