BC v1.2充电规范
Battery Charging Specification
USB port 如何识别不同的Charger类型
USB Charger类型
USB_SDP_CHARGER | POWER_SUPPLY_TYPE_USB ( Standard Downstream Port ) | USB Charger |
---|---|---|
USB_CDP_CHARGER | POWER_SUPPLY_TYPE_USB_CDP ( Charging Downstream Port ) | USB Charger |
USB_ACA_DOCK_CHARGER | POWER_SUPPLY_TYPE_USB_ACA ( Accessory Charger Adapters ) | USB Charger |
USB_ACA_A_CHARGER | POWER_SUPPLY_TYPE_USB_ACA ( Accessory Charger Adapters ) | USB Charger |
USB_ACA_B_CHARGER | POWER_SUPPLY_TYPE_USB_ACA ( Accessory Charger Adapters ) | USB Charger |
USB_ACA_C_CHARGER | POWER_SUPPLY_TYPE_USB_ACA ( Accessory Charger Adapters ) | USB Charger |
USB_DCP_CHARGER | POWER_SUPPLY_TYPE_USB_DCP ( Dedicated Charging Port ) | AC Charger |
USB_PROPRIETARY_CHARGER | POWER_SUPPLY_TYPE_USB_DCP ( Dedicated Charging Port ) | AC Charger |
DCP
Dedicated Charging Port就是wall adapter or AC charger。平时用的连到220v插座的充电器。不能枚举USB设备,可以供(4.75v< VCHG <5.25v)的稳定电压和(0.5A <IDCP <5A)的充电电流。DCP在内部将D+和D-短接。
ACA
Accessory Charger Adapter,PD设备连接到OTG port上,连接到Accessory Port上的外设能正常的使用USB信号和OTG设备进行通信,charger port仅标识为充电口口,并且需要指示何时给OTG和Accessory ports进行供电,ACA这种还没很了解。
CDP
Charging Downstream Port就是大电流充电端口,其实就是特殊USB口,它可以提供1.5A ~ 5A的大电流充电。 没连通外设时,当CDP检测到D+线上的电压VDAT_REF (Data Detect Voltage 0.25V ~ 0.4V)< VDP < VLGC (Logic Threshold 0.8V ~ 2V)后,会在D-线上输出VDM_SRC (0.5v ~ 0.7v);从外设联通时起,CDP将不再把电压VDM_SRC输出到D-上,直到外设断开联通。
SDP
Standard Downstream Port是标准的DS Port,通常是值电脑的USB口,是遵循USB2.0规范的host或hub的朝下端口。支持USB1.1(100 mA), USB2.0(100 mA/500mA) 和 USB 3.0(150 mA/900 mA),D+ and D- 一般内部下拉电阻14.25-24.8欧姆。
Other
除此以上遵循USB BC 1.2 specification,其实还有两类Other charging port (OCP) ,具有专有 D+/D- 充电配置的非标准充电器,USB 充电规范 1.2 未涵盖的端口。 这些充电器具有与普通 DCP 相似的电流能力。 D+ 和 D- 连接到Vbus 通过电阻分压器提供固定电压电平以及 Floating charger ,D+ 和 D- 浮动的非标准充电器, Type-C允许使用这种类型的充电器规格,只要它具有 Type-C 插座或系留电缆。
高通检测流程
高通平台的电池充电是被PMIC或者外部的充电芯片所控制。它必须知到充电器类型和最大充电电流。
充电类型
(1)DCD:DP上有150mV(= 10uA x 15K欧姆下拉电阻)的电压,DM上电压为0,
这是一个硬件检测模块,用于帮助检测 USB数据线已与另一端的引脚接触,与FLOAT类型有关
DCD机制向D+提供的电流源,可用定时器替代,但DCD能尽快检测数据线的连接,不必等待定时器超时,
DCD(data contact detect)的检测机制等待时间是可编程的通常是300ms 或者 600 ms。
(2)Primary Det(DP发起检测DM):
DP上加载0.6V电压,DM上电压为0,充电器类型是SDP
DP上加载0.6V电压,DM上电压为0.6V,进入Secondary Det
(3)Secondary Det(DM发起检测DP):
DM上加载0.8V电压,DP上电压为0,充电器类型是CDP
DM上加载0.8V电压,DP上电压为0.8V,充电器类型是DCP
kernel/msm-4.19/drivers/usb/phy/phy-msm-usb.c
kernel/msm-4.19/drivers/power/supply/qcom/qpnp-smb5.c
msm_otg_probe
INIT_WORK(&motg->sm_work, msm_otg_sm_work);
OTG_STATE_UNDEFINED
OTG_STATE_B_IDLE
msm_otg_start_host(otg, 1);
OTG_STATE_A_HOST
or
msm_otg_start_peripheral(otg, 1);
OTG_STATE_B_PERIPHERAL;
INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work);
USB_CHG_STATE_IN_PROGRESS // 正在检测中
USB_CHG_STATE_WAIT_FOR_DCD
USB_CHG_STATE_DCD_DONE
msm_chg_check_primary_det //区分 SDP和DCP/CDP or SDP和FLOAT
USB_CHG_STATE_DETECTED //检测完毕状态
or
USB_CHG_STATE_PRIMARY_DONE
msm_chg_check_secondary_det //区分DCP和CDP
USB_CHG_STATE_SECONDARY_DONE
USB_CHG_STATE_DETECTED //检测完毕状态
kernel/msm-4.19/drivers/usb/phy/phy-msm-usb.c
float类型检测应该主要跟硬件有关,在DCD Done阶段, 如USB数据线不短路并悬空,当连接上拉和下拉时,电压不符标准
case USB_CHG_STATE_DCD_DONE:
...
vout = msm_chg_check_primary_det(motg);
line_state = readl_relaxed(USB_PORTSC) & PORTSC_LS;
dm_vlgc = line_state & PORTSC_LS_DM;
if (vout && !dm_vlgc) { /* VDAT_REF < DM < VLGC */
if (line_state) { /* DP > VLGC */
motg->chg_type = USB_NONCOMPLIANT_CHARGER;
motg->chg_state = USB_CHG_STATE_DETECTED;
} else {
msm_chg_enable_secondary_det(motg);
delay = MSM_CHG_SECONDARY_DET_TIME;
motg->chg_state = USB_CHG_STATE_PRIMARY_DONE;
}
} else { /* DM < VDAT_REF || DM > VLGC */
if (line_state) /* DP > VLGC or/and DM > VLGC */
motg->chg_type = USB_NONCOMPLIANT_CHARGER;
else if (!dcd && floated_charger_enable)
motg->chg_type = USB_FLOATED_CHARGER;
else
motg->chg_type = USB_SDP_CHARGER;
motg->chg_state = USB_CHG_STATE_DETECTED;
}
break;
充电电流
kernel/msm-4.19/drivers/power/supply/qcom/qpnp-smb5.c
kernel/msm-4.19/drivers/power/supply/qcom/smb5-lib.c
static const struct power_supply_desc usb_psy_desc = {
.name = "usb",
.type = POWER_SUPPLY_TYPE_USB_PD,
.properties = smb5_usb_props,
.num_properties = ARRAY_SIZE(smb5_usb_props),
.get_property = smb5_usb_get_prop,
.set_property = smb5_usb_set_prop,
.property_is_writeable = smb5_usb_prop_is_writeable,
};
smb5_usb_get_prop
smblib_get_charge_current(chg, &val->intval);
smblib_get_apsd_result //smblib_apsd_results = usb charger type SDP/CDP/DCP
smb5_usb_set_prop
smblib_set_prop_pd_active
update_sw_icl_max(chg, apsd->pst);
/* rp-std or legacy, USB BC 1.2 */
switch (pst) {
case POWER_SUPPLY_TYPE_USB:
/*
* USB_PSY will vote to increase the current to 500/900mA once
* enumeration is done.
*/
if (!is_client_vote_enabled(chg->usb_icl_votable,
USB_PSY_VOTER)) {
/* if flash is active force 500mA */
vote(chg->usb_icl_votable, USB_PSY_VOTER, true,
is_flash_active(chg) ?
SDP_CURRENT_UA : SDP_100_MA);
}
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, false, 0);
break;
case POWER_SUPPLY_TYPE_USB_CDP:
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true,
CDP_CURRENT_UA);
break;
case POWER_SUPPLY_TYPE_USB_DCP:
rp_ua = get_rp_based_dcp_current(chg, typec_mode);
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true, rp_ua);
break;
case POWER_SUPPLY_TYPE_USB_FLOAT:
/*
* limit ICL to 100mA, the USB driver will enumerate to check
* if this is a SDP and appropriately set the current
*/
smblib_info(chg, "debug float set to %d uA\n", chg->dcp_icl_ua);
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true,
chg->dcp_icl_ua);
break;
case POWER_SUPPLY_TYPE_UNKNOWN:
default:
vote(chg->usb_icl_votable, SW_ICL_MAX_VOTER, true,
SDP_100_MA);
break;
}
}
标签:usb,chg,Charger,Driver,STATE,msm,Qcom,Android,USB
From: https://www.cnblogs.com/linhaostudy/p/18361878