该系列文章总目录链接与各部分简介: Android Qcom USB Driver学习(零)
因为要看usb charging的问题,所以需要补充一下battery的相关知识,算是入门吧
(1)VBATT_VSNS_P (2)BAT_THERM (3)I2C_SDA (4)I2C_SCL (5)VBATT_VSNS_M
(1)BATT_ID 没接在电池上,外部下拉的100k电阻,如果电池电压不同还是能做区分的,当然battery-id不一定非得使用adc去读取,既然battery是基于i2c的设备,就一定能做到区分,通过power_supply_desc的get_property的方式同样可以客制化获取电池区分信息包含id。
玩转移远SC60 Android开发板------(5)充电和电池管理
VBAT_THERM 引脚若不连接,则会导致不开机、电池不能充电、电池电量显示错误等故障。
如果客户使用的电池没有热敏电阻,或者客户使用电源适配器对模块进行供电,则只需连接VBAT 和GND。
此时为防止系统误判电池不存在而导致无法开机,客户应该将VBAT_THERM 引脚通过一个47KΩ的电阻连接到GND。
可充电电池在不断的循环充电和放电过程中可能会导致电池温度的过高,导致电池原始性能下降,所以需要监控电池温度保持电池性能。
QPNP: Qualcomm Plug and Play(The input can be supplied to the device via either a DC or USB path. Output paths are
the VPH_PWR rail via the buck and a reverse boost feature on VCHG.)
power/supply/qcom/qpnp-qg.c -> iio/inkern.c -> (batt-therm - chip->batt_therm_chan)
&pmi632_qg{
io-channels = <&pmi632_vadc ADC_BAT_THERM_PU1>, //SCALE_HW_CALIB_BATT_THERM_30K
<&pmi632_vadc ADC_BAT_ID_PU2>;
io-channel-names = "batt-therm", "batt-id";
}
&pmi632_charger{
qcom,connector-internal-pull-kohm = <30>; //write register BATIF_ADC_INTERNAL_PULL_UP_REG 电池ntc电阻
}
power/supply/qcom/qg-util.c -> iio/inkern.c -> qcom-spmi-adc5.c(pmi632) -> qpnp-vadc-common.c
qg_get_battery_temp(batt-therm_chan) -> read_raw -> adc_read_raw(based on kernel iio/iio_info) -> lux_table_30(vadc_map_pt)
依据电池spec去修改30k对应的lux_table_30的vadc_map_pt表
DalVAdc.c -> VAdc_DeviceInit -> VADC_BSP 获取vadcbsptype = VAdcBspPMI455(vadc_props.xml)
VAdcSettings.c -> gVAdcChannelsPMI455 (vadc channel)
/* BATT_THERM_PU_30K (BAT_THERM pin) */
{
.pszName = ADC_INPUT_BATT_THERM_PU_30K,
.uAdcHardwareChannel = 0x2a,
.eSettlingDelay = VADC_SETTLING_DELAY_100_US,
.eAverageMode = VADC_AVERAGE_1_SAMPLE,
.eDecimationRatio = VADC_DECIMATION_RATIO_1024,
.eCalMethod = VADC_CAL_METHOD_RATIOMETRIC,
.scalingFactor = {1, 1}, /* {num, den} */
.eScalingMethod = VADC_SCALE_THERMISTOR,
.uPullUp = 30000,
.pIntTable = &gVAdcSysThermTable, //vadc map表
},
pm_get_adc_code_of_battery_temp + ADC_INPUT_BATT_THERM_PU_30K 获取电池温度
&pmi632_qg {
qcom,battery-data = <&mtp_batterydata>;
}
power/supply/qcom/qpnp-qg.c -> iio/inkern.c -> (batt-id - chip->batt_id_chan)
-> get_batt_id_ohm(batt_id_chan) -> qg_load_battery_profile(qcom,battery-data)
-> of_batterydata_get_best_profile
通过iio读取adc的值获得battery-id,可用于区分battery-data(可以是大容量小容量区分),battery-id可误差率(qcom,batt-id-range-pct)
电池ID引脚内部的阻值qcom,batt-id-kohm = <100>,另外可通过qcom,battery-type来寻找最佳的profile
pm_sbl_get_batt_id + PM_BATT_ID_PU_30K + adc_read 同样通过adc对应的阻值通道读取值
battery id在XBL阶段中不一定能用到,所以有可能就是fake batteryid
JEITA(Japan Electronics and Information Technology Industries Association)旨在低温和高温下提高锂离子电池充电的安全性
锂电池充电领域大多遵循了JEITA标准,JEITA成为了充电规范的一个代名词。
Dead battery recovery takes place in two stages – XBL and UEFI
Dead Battery -> Weak Battery -> Good Battery
SBL1 XBL Core HLOS
在DRR init之前必需PMIC init,DDR初始化之后通过(PIL peripheral image loading)加载各subsystem的镜像例如modem_a(ADSP CDSP…)
sbl1_hw_pre_ddr_init: (1)pm_device_init (2)pm_driver_init (3) pm_sbl_chg_init
(1)
pm_device_init没有研究过,也是一些初始化
(2)
pm_sbl_boot_oem.c -> pm_driver_post_init (通过write register的方法来配置jeita)
err_flag |= pm_comm_write_byte(0x2 , 0x1094, 0x0F, 0x0); //warm 45
err_flag |= pm_comm_write_byte(0x2 , 0x1095, 0xDC, 0x0); //warm 45
依据各项目ic pmic的datasheet找到对应寄存器进行修改
(3)
pm_config_target.c -> strcut sbl_schg_specific_data (charger parameters chg_param_ptr)
包括usb输出电流(USBIN Input Current Limit),开机电压(bootup_battery_theshold_mv),jeita限制(Enable/Disable JEITA Hard Temp Limit Check in SBL)等等
pm_sbl_schg_specific_data_type
sbl_schg_specific_data[1] =
{
{
//Configuration Value, Enable config
{PM_SCHG_BATIF_LOW_BATTERY_THRESH_3P2, PM_DISABLE_CONFIG }, //Vlowbatt Threshold
{PM_SCHG_BATIF_LOW_BATTERY_THRESH_2P8, PM_ENABLE_CONFIG }, //APSD rerun Vlowbatt Threshold
{70, PM_ENABLE_CONFIG }, //Fg skin hot threshold: valid range is -30 to 97 degree C
{80, PM_ENABLE_CONFIG }, //Fg skin too hot threshold: valid range is -30 to 97 degree C
{80, PM_ENABLE_CONFIG }, //Fg charge hot threshold: valid range is -30 to 97 degree C
{90, PM_ENABLE_CONFIG }, //Fg charge too hot threshold: valid range is -30 to 97 degree C
{TRUE, PM_DISABLE_CONFIG }, //Use BATID and/or THERM pin for battery missing detection
{{TRUE, PM_SCHG_MISC_SNARL_WDOG_TMOUT_62P5MS, PM_SCHG_MISC_BARK_WDOG_TMOUT_128S, PM_SCHG_MISC_BITE_WDOG_TMOUT_8S}, PM_ENABLE_CONFIG }, //Enable/Disable and Timeout WDog Config
{2000, PM_ENABLE_CONFIG }, //FAST Charging Current
{300, PM_ENABLE_CONFIG }, //PRE Charge Current
{4400, PM_ENABLE_CONFIG }, //Float Voltage
{2500, PM_ENABLE_CONFIG }, //USBIN Input Current Limit
{1000, PM_DISABLE_CONFIG }, //DCIN Input Current Limit
{6750, 8250, PM_ENABLE_CONFIG }, //Fake battery detection range: Battery will be detected as fake battery if BATT ID in this range. unit: Ohms
{2000, 14000}, //Debug Board detect: BATT_ID PD Resistor ADC Min/Max Read Value range; unit: Ohms
PM_BATT_ID_PU_30K, //battery ID pull up resistor value
3300, //bootup_battery_theshold_mv
3300, //wipowr bootup battery thesholdmv
2800, //apsd_reset_threshold_mv: APSD reset only applicable if initial Vbatt level is less than this threshold
2800, //apsd_reset_theshold_no_uvlo_mv: Used if last reset reason is NOT UVLO
3200, //apsd_reset_theshold_uvlo_mv: Used if last reset reason is UVLO
TRUE, //Enable/Disable JEITA Hard Temp Limit Check in SBL
TRUE, //dbc_usb_500_mode
TRUE, //Verbose SBL CHG UART logging
1, //Pmic index of charger
}
};
pm_sbl_boot.c -> pm_app_chgr.c -> pm_sbl_config_chg_parameters ↓↓↓
pm_sbl_boot.c -> pm_app_chgr.c -> pm_sbl_chg_check_weak_battery_status
应用上述的chg_param_ptr, 在weak battery的状态下不会开机(即SBL Charging in progress....) + 闪红灯(Toggle Red LED)
QcomChargerConfig_VbattTh.cfg
BootToHLOSThresholdInMv = 3300
JeitaHardColdLimit = 0
JeitaSoftColdLimit = 10
JeitaSoftHotLimit = 45
JeitaHardHotLimit = 60
QcomChargerPlatform.c -> ChargerPlatform_ReadCfgParams -> ChargerPlatform_Init
if (CurrentBatteryStatus.BatteryVoltage >= gThresholdVbatt)
*pActionType = EFI_QCOM_CHARGER_ACTION_GOOD_TO_BOOT;
qcom,fastchg-current-ma = <2000>; //最大快充电流
/* COOL = 10 degc, WARM = 40 degC*/ //jeita配置
qcom,jeita-soft-thresholds = <0x2ed8 0x1045>; <SOFT_COLD_ADC_CODE, SOFT_HOT_ADC_CODE>
/* COLD = 0 degC, HOT = 45 degC*/
qcom,jeita-hard-thresholds = <0x3e3d 0x0D85>; <HARD_COLD_ADC_CODE, HARD_HOT_ADC_CODE>
qcom,jeita-fcc-ranges = < //各jeita范围内电流
0 100 800000
101 400 2000000
401 450 2000000>;
qcom,jeita-fv-ranges = < //各jeita范围内电压
0 100 4180000
101 400 4350000
401 450 4350000>;
(1) Trickle-charge < 2.1V 45mA
(2) Preconditioning(precharge) > 2.1V + PRE Charge Current
(3) Constant current(fast charge) < Float Voltage + Fast Charging Current
(4) Constatnt voltage(taper charge) = Float Voltage
Chargint phase的配置还是发生在SBL1/XBL阶段,在高通平台上除了(1)Trigckle_charge都是可配置的,配置可见上述sbl_schg_specific_data
pm_sbl_boot.c -> pm_app_chgr.c -> pm_sbl_config_chg_parameters
-> pm_schg_chgr_set_charge_current(PRE Charge Current(2))
-> pm_schg_chgr_set_charge_current(FAST Charging Current(3))
-> pm_schg_chgr_set_float_volt(Float Voltage(4))