USB Type-C和PD

1 USB Type-C
1.1 电气参数
Rd:5.1kΩ
Ra:1.0kΩ
Rfrswap:5Ω,for PD 3.0 FR_Swap
fBitRate:300Kbps
Rp:Reference to the Table 1-1

Table 1-1 USB Type-C pull-up resistors

1.2 DELL USB-PD
DELL笔记本USB PD充电适配器Type-C金属头外壳对地有一只1KΩ的电阻。

2 USB-PD
2.1 Four PDOs
Fixed Supply:CV(恒压)
Battery Supply:CP(恒功率)
Variable Supply:CC(恒流)
Augmented Programmale Power Supply:PPS(APDO)

APDO:Reference to 'Table 6-22 Programmable Request Data Object';电压步长20mV,电流步长50mA。
譬如请求6V @ 2A,那么Request消息的B19…9的值为300,而B6…0的值为40。
PPS模式时,需要Sink每隔10secs发送一个Request到Src,重新协商PPS电压电流对。

Figure 2-1 APDO包格式


2.2 iPhone 8/8 Plus/X PD相关
Figure 2-2 iPhone 8 USB PD兼容性测试(CYPD2104 & BQ25890)

iPhone X整体PD快充的电源管理策略如下:
1.关机状态下不进行PD沟通,APPLE 2.4A协议生效。非APPLE 2.4A协议开机会慢一点;
2.开机后进行PD协商,依然选取PDO2,前面50%会以较高功率充电(最大不超过15W且视温度及电量自动调控功率);
3.充至50%-55%左右会降至9-11W(视温度及电量自动调控功率);
4.当温度达到一定时,iPhone X会强制降至极低的功率。待手机温度下降后以5W的功率进行后续充电;
5.充电至80%左右,选取PDO1降至5V。请注意此时依然是PD充电,只是选了5V档位减低手机端压降损耗;
6.充电至88%左右,开始进入CV段直到充满。

2.3 USB PD timers and counters
Reference to 'Table 6-53 Time Values' and 'Table 6-54 Timers' of '6.6.19 Time Values and Timers' 。

C Style Definitions:
#define PD_T_NO_RESPONSE    5000    /* 4.5 - 5.5 seconds */
#define PD_T_DB_DETECT      10000   /* 10 - 15 seconds */
#define PD_T_SEND_SOURCE_CAP    150 /* 100 - 200 ms */
#define PD_T_SENDER_RESPONSE    60  /* 24 - 30 ms, relaxed */
#define PD_T_SOURCE_ACTIVITY    45
#define PD_T_SINK_ACTIVITY  135
#define PD_T_SINK_WAIT_CAP  240
#define PD_T_PS_TRANSITION  500
#define PD_T_SRC_TRANSITION 35
#define PD_T_DRP_SNK        40
#define PD_T_DRP_SRC        30
#define PD_T_PS_SOURCE_OFF  920
#define PD_T_PS_SOURCE_ON   480
#define PD_T_PS_HARD_RESET  30
#define PD_T_SRC_RECOVER    760
#define PD_T_SRC_RECOVER_MAX    1000
#define PD_T_SRC_TURN_ON    275
#define PD_T_SAFE_0V        650
#define PD_T_VCONN_SOURCE_ON    100
#define PD_T_SINK_REQUEST   100 /* 100 ms minimum */
#define PD_T_ERROR_RECOVERY 100 /* minimum 25 is insufficient */

#define PD_T_DRP_TRY        100 /* 75 - 150 ms */
#define PD_T_DRP_TRYWAIT    600 /* 400 - 800 ms */

#define PD_T_CC_DEBOUNCE    200 /* 100 - 200 ms */
#define PD_T_PD_DEBOUNCE    20  /* 10 - 20 ms */

#define PD_N_CAPS_COUNT     (PD_T_NO_RESPONSE / PD_T_SEND_SOURCE_CAP)
#define PD_N_HARD_RESET_COUNT   2

2.4 PD SNK RDY状态时,如果SNK需要改变充电电压电流该怎么办?
Reference to USB_PD_R2_0 V1.3 ‘p358, 8.3.2.8.4.1 Sink Gets Source Capabilities’
接着双方重新协商发送消息对,如下所示:
- Get_Source_Cap
- Request(Request对象索引Object Position从1开始,而且该索引位置必定是5V Fixed PDO)
- Accept
- PS_RDY

PR_Swap时,PD双方的Rp和Rd也要交换,其他message不依赖Rp和Rd。

2.5 FR_Swap Message Sequence
1)Source(Hub)shorts Rp to ground for ~100 us to signal Sink that is needs to supply power immediately.
2)Sink(Mobile Device)supplies 5V.
3)Rp/Rd are not changed at this stage as in a normal PR_Swap.
4)Mobile device then sends an FR_Swap message to resynchronize the power system.
5)Mobile device renegotiates the power contract as needed.

2.6 USB PD PDO协商流程
Type-C SS MUX切换时间:
- 识别到Rp或者Rd连接的时候
- VDM消息进入特定模式时

Figure 2-3 USB PD Message Sequence

Figure 2-4 QC4+充电器

3 SOP_P和SOP_PP控制器
远端SOP_PP控制器的存在与否,不是靠检测出来的,而是通过先与SOP_P的通信来获知SOP_PP的控制器是否存在,如果存在,VCONN Source设备才会继续发SOP_PP的报文类型与SOP_PP控制通信。

4 Alternative Mode
4.1 DisplayPort
拆解报告:华为高清投屏连接线(CP76)
http://www.chongdiantou.com/wp/archives/27141.html

4.2 VirtualLink
Figure 4-1 VirtualLink Pin Description

5 USB-PD IC介绍
5.1 X-CUBE-USB-PD
https://github.com/st-one/X-CUBE-USB-PD

5.2 STM32软件实施USB PD协议
TX:使用SPI MOSI当作TX,RX悬空不使用,同时将SPI CLK连接到TIMER作为定时用
RX:TIMER输入捕获模式并用DMA接收数据

SPI传输数据过程中总是先发送或接收高字节数据,每个时钟周期接收器或发送器左移一位数据。对于小于16位的数据,在发送前必须左对齐,如果接收的数据小于16位,则采用软件将无效的数据位屏蔽。

MISO(DAT0):mi s əu
MOSI(CMD):m əu si
QUP:高通平台的SPI总线和I2C共用core和引脚,称为QUP(QCOM Universal Peripheral);而UART和QUP又共用引脚,并且称为BLSP

5.3 FUSB30X
Registers.Control.TOGGLE
Registers.Status.I_HARDRST
void autoVdmDiscovery(void)

6 SDM630/SDM660 Chgr Type Det Flow
6.1 CC线和VBUS中断的先后顺序是什么
USB-C to USB-A:
如果手机采用USB-C,而充电头或者PC采用标准的A口,此时假如PMIC as UFP,那么CC线的中断几乎和VBUS中断是同时的,原因是legacy cable的标准A头的做法是将一根CC线通过一个上拉电阻Rp接到VBUS上的。

USB-C to USB-C:
- 手机采用这种模式,只是在VBUS中断之前首先是CC线的探测,这个是跟BC 1.2最大的不同,传统的micro USB cable插上去后,直接就探测ID和VBUS;当用户插入一根USB-C to USB-C的cable,Type-C控制器处理CC线探测,CC线产生中断后:
- 如果PMIC as UFP,那么紧接着会有VBUS中断,然后就是APSD (BC1.2)、USB PD(包括QC4 PPS)、QC3 & QC2上场了;
- 如果PMIC as DFP,那么一般PMIC会将该状态转换成传统的micro USB ID中断,然后USB OTG驱动代码处理ID中断,或者通过extcon直接通知USB OTG驱动。

6.2 SDM630/SDM660的充电器探测流程是什么
- PMIC首先做CC线探测,如果探测到PMIC as UFP,PMIC与此同时再探测CC线是否与VBUS短接,如果VBUS和CC短接,说明插入的是legacy cable(一般指USB-A to USB-C的cable),这个时候直接禁止USB PD和QC(由于CC和VBUS短接,大电流充电会导致电流灌到CC线而可能烧毁PMIC,所以代码默认是禁止QC的);
- 上一步成立的情况下(也就是PMIC as UFP)接着做APSD探测,这里充电器类型探测结果有如下2种状况:
1)如果探测到充电器类型是DCP,接着做USB PD(包括QC4 PPS)探测,假如不支持USB PD,接着rerun_apsd()做QC3 & QC2探测,倘若QC3 & QC2探测失败,说明该电源适配器既不支持USB PD (包括QC4 PPS) 也不支持QC3 & QC2,维持在DCP正常充电状态;
2)如果充电器类型不是DCP,直接做USB PD探测。

6.3 驱动代码
高通Type-C、APSD(BC1.2)和QC的驱动代码在drivers/power下;而USB PD的代码在drivers/usb/pd下面,所以你如果把drivers/usb/pd下的代码通过Makefile屏蔽掉,发现Type-C、APSD(BC1.2)和QC3 & QC2充电器还是可以工作的;而此时用USB线连接手机和PC,会发现USB不枚举,原因是extcon的代码是集成在drivers/usb/pd下的,所以如果你既要禁止USB PD,又要让USB可以枚举,那么需要把drivers/usb/pd下的extcon代码移植到drivers/power下面。

6.4 PD消息收发何时触发中断
中断机制是Interrupt on GoodCRC(IoG),如Figure 6-1所示。
Figure 6-1 USB PD中断产生

6.5 简要说明充电器类型是DCP时探测流程的代码逻辑
以下是用户外接一个电源适配器到手机后,Type-C、APSD(BC1.2)、USB PD (包括QC4 PPS) 和QC3 & QC2的代码工作流程。

一个投票箱有多个投票client,并且对这些client制定规则。
Table 6-1 Ballot Box Rules

Table 6-2 USB-PD Ballot Box

[1] Disable USB PD negotiation by default when the Type-C cable is removed
@smb-lib.c
static void smblib_handle_typec_removal(struct smb_charger *chg)
{
    vote(chg->pd_disallowed_votable_indirect, CC_DETACHED_VOTER, true, 0);
    vote(chg->pd_disallowed_votable_indirect, HVDCP_TIMEOUT_VOTER, true, 0);
    vote(chg->pd_disallowed_votable_indirect, LEGACY_CABLE_VOTER, true, 0);
    vote(chg->pd_disallowed_votable_indirect, VBUS_CC_SHORT_VOTER, true, 0);
    [...]
}

[2] Enable USB PD (including QC4 PPS) negotiation when the Type-C cable is inserted and charger type is DCP detection timeout
@smb-lib.c
static void smblib_handle_hvdcp_check_timeout(struct smb_charger *chg,
bool rising, bool qc_charger)
{
    /* Hold off PD only until hvdcp 2.0 detection timeout */
    if (rising) {
        vote(chg->pd_disallowed_votable_indirect, HVDCP_TIMEOUT_VOTER, false,
                                                  0);
        [...]
    }
    [...]
}

[3] PD(including QC4 PPS)negotiation works now, the detection falls back to QC3 & QC2 when USB PD detection failed
@smb-lib.c
int smblib_get_prop_pd_allowed(struct smb_charger *chg,
union power_supply_propval *val)
{
    val->intval = get_effective_result(chg->pd_allowed_votable);
    return 0;
}

@smb-lib.c
int smblib_get_pe_start(struct smb_charger *chg,
union power_supply_propval *val)
{
    /*
    * hvdcp timeout voter is the last one to allow pd. Use its vote
    * to indicate start of pe engine
    */
    val->intval
        = !get_client_vote_locked(chg->pd_disallowed_votable_indirect, HVDCP_TIMEOUT_VOTER);
    return 0;
}

@policy_engine.c
static int psy_changed(struct notifier_block *nb, unsigned long evt, void *ptr)
{
    [...]
    ret = power_supply_get_property(pd->usb_psy,
                   POWER_SUPPLY_PROP_PE_START, &val);
    [...]
    /* Don't proceed if PE_START=0 as other props may still change */
    if (!val.intval && !pd->pd_connected &&
                   typec_mode != POWER_SUPPLY_TYPEC_NONE)
    return 0;
    [...]
}

7 Abbreviations
AEC-Q100:Automotive Electronics Council-Quality,汽车电子协会,主要规定汽车上IC要遵循的标准,也即是车规认证。汽车级EZ-PD CCG3PA控制器通过了AEC-Q100认证
ARC:Argonant RISC Core
CC2530:TI ChipCon2530
CCG2:Type-C Controller Generation 2
CCGP:USB Common Class Generic Parent,Linux内核类似的驱动就是usb_generic_driver
DWC2:Design Ware Controller 2,Apple的嵌入式设备,包括iPad和iPhone都是使用的DWC2
giveback:归还 - ehci_urb_done() -> usb_hcd_giveback_urb()。USB PD中的giveback(= 1)指sink会响应source的GotoMin请求,返还部分电力给source。
GRL:Granite River Labs ,美国工程测试认证实验室
halt:停车或者站住,来自于德语;USB endpoint停止运行,返回stall handshake。recovery方法:control ep接收下一次SETUP PID时,自动清除halt标志;其它ep使用clear_feature复位ep halt。
HX3C:USB Type-C Hub with PD
ISP1161:Philips' Integrated host Solution Pairs 1161,“Firms introduce USB host controllers”,https://www.eetimes.com/document.asp?doc_id=1290054
MPS:Monolithic Power Systems,美国公司
PTN5100:Part Number
Quirks:the attributes of a device that are considered to be noncompliant with expected operation
RS507L:ASEMI整流桥RS507L,4pin接口;用途有LED,手机充电器整流
SL811HS:Cypress/ScanLogic 811 Host/Slave,性能上与ISP1161(Integrated host Solution Pairs 1161)相当
TDI:TransDimension Inc.,该公司首先发明了将TT集成到EHCI RootHub中的方法,这样对于嵌入式系统来说,就省去了OHCI/UHCI的硬件,同时降低了成本,作为对该公司的纪念,Linux内核定义了宏ehci_is_TDI(ehci);产品UHC124表示USB Host Controller;收购了ARC USB技术;现已被chipidea收购,chipidea又被mips收购
TLV:TI Low Value,高性价比
TPS:TI Performance Solution
USB BH reset:Bigger Hammer or Brad Hosler,表示warm reset;you may be confused why the USB 3.0 spec calls the same type of reset "warm reset" in some places and "BH reset" in other places. "BH" reset is supposed to stand for "Big Hammer" reset, but it also stands for "Brad Hosler". Brad died shortly after the USB 3.0 bus specification was started, and they decided to name the reset after him. The suggestion was made shortly before the spec was finalized, so the wording is a bit inconsistent.
USB PD:USB 电源交付
USB PDT:USB PD Test Instrument

state和status的区别:state所指的状态,一般都是有限的、可列举的,status则是不可确定的
比如:
readyState-- 就那么四五种值
statusText-- 描述性的文字,可以任意

发布了124 篇原创文章 · 获赞 51 · 访问量 32万+

猜你喜欢

转载自blog.csdn.net/zoosenpin/article/details/73657917