高通电池管理基于qpnp-vm-bms电压模式
- 2019 年 10 月 10 日
- 笔记
CV:Constant Voltage恒压 SMMB charger:Switch-ModeBattery Charger and Boost peripheral开关模式电池充电器和升压外围设备 OCV:Open circuitvoltage EOC:End OfCharge充电结束 UUC:UnusableCapacity不可用电量
对应的源代码文件为kerneldriverspowerqpnp-vm-bms.c,高通QPNP电压模式的PMIC电池管理系统(Qualcomm'sQPNP Voltage-Mode(VM) PMIC Battery Management System),提供接口给客户端来读取电池相关属性,它的主要功能是基于周期性采样VBAT(vattery voltage)来计算SOC(state ofcharge)
下面学习kernelDocumentationdevicetreebindingspowerqpnp-vm-bms.txt
父节点需要的属性如下
见kernelarcharmbootdtsqcommsm-pm8909.dtsi文件的pm8909_bms: qcom,vmbms节点
- compatible : Must be "qcom,qpnp-vm-bms" for the BM driver. - reg :Offset and length of the PMIC peripheral register map.
比如reg = <0x4000 0x100>;
- interrupts : The interrupt mappings. The format should be <slave-id peripheral-idinterrupt-number>.
比如
interrupts = <0x0 0x40 0x0>, <0x00x40 0x3>, <0x00x40 0x4>, <0x00x40 0x5>;
- interrupt-names : names for the mappedbms interrupt Thefollowing interrupts are required: 0: leave CV state离开恒压状态 1: enter CV state 2: good ocv generated 3: ocv_thr 4: fifo update 5: fsm state changed
比如
interrupt-names = "leave_cv", "ocv_thr", "fifo_update_done", "fsm_state_change";
此外,可选的子节点可包含:
- qcom,batt-pres-status : A subnode with aregister address for the SMBB batteryinterface's BATT_PRES_STATUS register. If this node is added,then the BMS will try to detect offmode battery removal viathe battery interface's offmode battery removal circuit.
这是带有一个关于SMMB电池接口寄存器BATT_PRES_STATUS地址的子节点,如果增加了此节点,BMS将会尝试通过电池接口的offmode电池接插电路检测offmode电池接插
例如
qcom,batt-pres-status@1208 { reg= <0x1208 0x1>; };
电池曲线:
- qcom,battery-data : A phandle to a nodecontaining the available batterydata profiles.See the batterydata bindings documentation for more details.
此节点的值是一个phandle,它指向一个包含有效电池曲线数据的节点,详见kernelDocumentationdevicetreebindingsbatterydatabatterydata.txt
在kernelarcharmbootdtsqcommsm8909-qrd-skue.dtsi中定义 / { qrd_batterydata:qcom,battery-data { qcom,rpull-up-kohm= <0>; qcom,vref-batt-therm= <1800000>; #include"batterydata-qrd-skue-4v35-2000mah.dtsi" }; };
&pm8909_bms { status= "okay"; qcom,resume-soc= <95>; qcom,use-reported-soc; qcom,force-bms-active-on-charger; qcom,battery-data = <&qrd_batterydata>; };
父节点需要的属性
- qcom,v-cutoff-uv : cutoff voltage wherethe battery is considered dead in micro-volts(微伏).
关机电压,用于计算SOC,如修改关机电压,除了修改这里,还需要修改电池曲线数据的qcom,v-cutoff-uv,其实最好是用电池曲线数据里的。
比如qcom,v-cutoff-uv = <3400000>;
- qcom,max-voltage-uv : maximum voltage forthe battery in micro-volts.
电池最大的电压,单位为毫伏,比如qcom,max-voltage-uv =<4200000>;
- qcom,r-conn-mohm : connector resistancein milli-ohms.
连接器电阻,如qcom,r-conn-mohm = <0>;
- qcom,shutdown-soc-valid-limit : If theocv upon restart is within this distanceof the shutdown ocv, the BMS will try to force thenew SoC to the old one to provide charge continuity. Thatis to say, if(abs(shutdown-soc - current-soc) < limit) thenuse old SoC.
如qcom,shutdown-soc-valid-limit =<100>;
- qcom,low-soc-calculate-soc-threshold :The SoC threshold for when theperiodic calculate_soc work speeds up. This ensures SoCis updated in userspace constantly when we are near shutdown.
当SOC低于此阈值,calculate_soc缩短工作周期,这样可以在接近关机的时候不断地更新用户空间的SOC。如qcom,low-soc-calculate-soc-threshold =<15>;
- qcom,low-voltage-threshold : The batteryvoltage threshold in micro-volts for whenthe BMS tries to wake up and hold a wakelock to ensurea clean shutdown.
低压阈值,用于关机,当达到此值BMS尝试唤醒和持有唤醒锁来保证一个干净的关机。如qcom,low-voltage-threshold = <3450000>;
- qcom,low-voltage-calculate-soc-ms : Thetime period between subsequent SoCrecalculations when the current voltage is below qcom,low-voltagethreshold. This takes precedence over qcom,low-soc-calculate-soc-ms.
当电池电压低于qcom,low-voltage threshold,随后重新计算soc的时间周期,者优先于qcom,low-soc-calculate-soc-ms,如qcom,low-voltage-calculate-soc-ms = <1000>;。
- qcom,low-soc-calculate-soc-ms : The timeperiod between subsequent SoCrecalculations when the current SoC is below qcom,low-soc-calculate-soc-threshold.This takes precedenceover qcom,calculate-soc-ms.
当前SOC低于qcom,low-soc-calculate-soc-threshold时,随后重新计算SOC的时间周期,这优先于qcom,calculate-soc-ms,如low-soc-calculate-soc-ms = <5000>;
- qcom,calculate-soc-ms : The time periodbetween subsequent SoC recalculationswhen the current SoC is above or equal qcom,low-soc-calculate-soc-threshold.
当前SOC>= qcom,low-soc-calculate-soc-threshold时的计算soc的时间周期。如qcom,calculate-soc-ms =<20000>;
- qcom,volatge-soc-timeout-ms : The timeoutperiod after which the module starts reportingvolage based SOC and does not use the VMBMS algorithmfor SOC calculation.
如果没有使用VMBMS算法来计算SOC,模块在此时间后基于SOC来报告电压。如qcom,volatge-soc-timeout-ms =<60000>;
- qcom,bms-vadc: Corresponding VADCdevice's phandle.
相应的VADC设备的phandle,qcom,bms-vadc = <&pm8909_vadc>;
- qcom,bms-adc_tm: Corresponding ADC_TMdevice's phandle to set recurring measurements andreceive notifications for vbatt.
相应ADC_TM设备的phandle,用于设置循环测量和接受vbatt的通知。如qcom,bms-adc_tm =<&pm8909_adc_tm>;
- qcom,pmic-revid : Phandle pointing to therevision peripheral node.
指向revision外围节点的phandle,如qcom,pmic-revid = <&pm8909_revid>;
Parent node Optional properties
父节点可选属性
- qcom,s1-sample-interval-ms: The samplingrate in ms of the accumulator in state S1.(i.e) the rate at which the accumulator is being filledwith vbat samples. Minimum value = 0 and Maximumvalue = 2550ms.
- qcom,s2-sample-interval-ms: The samplingrate in ms of the accumulator in state S2.(i.e) the rate at which the accumulator is being filledwith vbat samples. Minimum value = 0 and Maximumvalue = 2550ms.
- qcom,s1-sample-count: The number ofsamples to be accululated for one FIFO in stateS1. Possible values are – 0, 4, 8, 16, 32, 64, 128, 256.
- qcom,s2-sample-count: The number ofsamples to be accululated for one FIFO in stateS2. Possible values are – 0, 4, 8, 16, 32, 64, 128, 256.
- qcom,s1-fifo-legth: Number of FIFO's to be filled in state S1, togenerate thefifo_update_done interrupt. Possile values – 0 to 8
- qcom,s2-fifo-legth: Number of FIFO's to be filled in state S2, togenerate thefifo_update_done interrupt. Possible values- 0 to 8
上面几个可选属性没有用到就不描述了。
- qcom,force-s3-on-suspend : Bool propertyto force the BMS into S3 (sleep) state whileentering into system suspend.
如有此项,当系统休眠时此属性强迫BMS进入S3(sleep)状态。
- qcom,force-bms-active-on-charger: Boolproperty to keep BMS FSM active ifcharger is present.
只要充电器在,保证BMS FSM激活状态。
- qcom,report-charger-eoc : Bool propertyto indicate if BMS needs to indicate EOCto charger.
指示BMS需要通知EOC(充电结束)给充电器
- qcom,ignore-shutdown-soc: A boolean thatcontrols whether BMS will tryto force the startup SoC to be the same as the shutdownSoC. Defining it will make BMS ignore the shutdownSoC.
控制BMS是否尝试去强迫启动时SOC和关机SOC一样,如果定义此项将使BMS忽略关机SOC,这意味着开机时不会用上次关机SOC,一般情况下都需要这样,所以没有采用此属性
- qcom,use-voltage-soc : A boolean thatcontrols whether BMS will use voltage-basedSoC instead of a coulomb counter based one.Voltage-based SoC will not guarantee linearity.
BMS根据此项的值来决定是否采用基于电压的SOC来替代基于库伦电量计的方式,基于电压的SOC不保证线性性。
- qcom,disable-bms : Bool property to disable the VMBMS hardware module. Enablethis property if BMS is not supported or an external fuelgauge is used.
此属性用于关闭VM BMS硬件模块,在不支持BMS或是使用一个外部电量计时使能此属性。
- qcom,s3-ocv-tolerence-uv : The S3 stateOCV tolerence threshold in uV. The LSBvalue is 300uV and maximum value is 76500uV.
S3状态OCV相容阈值,最低值是300uV和最大值是76500uV。
- qcom,low-soc-fifo-length : The fifolength (of S2 STATE) to be used at lower SOCs.If this value is not specified the system uses defaultlenght.
低SOC时S2状态FIFO长度,如果没有指定则系统采用默认长度,这里为qcom,low-soc-fifo-length= <2>;
- qcom,resume-soc: Capacity in percent at which charging should resume whena fully charged battery drops below this level.
当充满的电池百分比低于此值,则重新开始充电。如qcom,resume-soc =<99>;
- qcom,low-temp-threshold : The temperaturethreshold below which the IBAT averagingand UUC smoothening is disabled. This value isin deci-degrees centigrade. If not specified it defaultsto 0.
当温度阈值低于此值,禁用IBAT求取平均值和UUC(不可用电量)平滑功能,如没指定默认为0,我们这里没有指定。
- qcom,ibat-avg-samples : The number ofsamples to be averaged for IBAT estimation.If not specified it defaults to 16. Thepossible values are 1 to 16.
IBAT平均值估算的采用次数,如没有指定默认为16,有效值1~16,我们没有指定。
- qcom,batt-aging-comp : A boolean thatdefines if battery aging compensation isenabled.
定义此项表示使能电池老化补偿,但我没有用到,建议使用。
- qcom,use-reported-soc : Bool property toenable the reported_soc logic. To enablethis feature, qcom,resume-soc must be defined as aproper value. The BMS is also required to control the charging,discharging and recharging.
此项使能reported_soc逻辑,而且要定义qcom,resume-soc为一个合适的值,BMS也需要控制充电、停止充电和重新充电。高通给出的代码默认是定义qcom,use-reported-soc,但我们核心板厂家注释掉此项,并增加qcom,report-charger-eoc
qcom,batt-pres-status节点需要的属性值
- reg : offset and length of the PMIC LBCbattery interface BATT_PRES_STATUS register
如
qcom,batt-pres-status@1208 { reg= <0x1208 0x1>; };
qcom,qpnp-chg-pres节点需要的属性
- reg : offset and length of the PMIC LBCcharger interafce CHARGER_OPTION register.
如
qcom,qpnp-chg-pres@1008 { reg= <0x1008 0x1>; };