MENU

Qualcomm Msm835平台充电功能的开发与调试

March 17, 2020 • 转载自Randy Zhang,ARM World

平台充电相关代码:

835平台kernel充电相关代码:

  • driver/power/supply/qcom/qpnp-fg-gen3.c 电池电量相关驱动代码
  • driver/power/supply/qcom/battery.c 电池充电相关代码
  • driver/power/supply/qcom/qpnp-smb2.c  高通充电控制相关代码
  • driver/power/supply/qcom/smb-lib.c 高通充电控制相关代码
  • arch/arm/boot/dts/qcom/msm8998-mtp.dtsi 电池曲线配置
  • arch/arm/boot/dts/qcom/msm-pmi8998.dtsi 关于 pmi8998 相关的配置

关机充电的系统相关代码:

  • ap/system/core/healthd/  关机充电的总体架构,
  • ap/device/qcom/common/healthd/    关机充电平台相关的屏幕显示,指示灯控制灯具体函数的实现。

835平台UEFI 充电相关代码:

  • boot_images/QcomPkg/Library/ChargerLib
  • boot_images/QcomPkg/Drivers/QcomChargerDxe ChargerLib 和QcomChargerDxe 目录下的代码提供UEFI充电和电量相关函数
  • boot_images/QcomPkg/Drivers/PmicDxe UEFI PMIC相关函数
  • boot_images /QcomPkg/Application/QcomChargerApp QcomChargerApp是UEFI充电的总体流程。QcomChargerApp.c文件中,EFI_STATUS QcomChargerApp_Entry()是入口函数。调用如下相关的函数,直到充电到阈值。

    Status |= QcomChargerApp_Initialize(ChargingAction);
    if(EFI_SUCCESS == Status)
    {
        Status |= QcomChargerApp_MonitorCharging();
        Status |= QcomChargerApp_PostProcessing();
    }
    

835平台电池曲线:

电池曲线大体内容如下:

qcom,3055372_goertek_falconaec_3950mah_averaged_masterslave_aug21st2017 {
    qcom, = <24>;
    qcom,max-voltage-uv = <4350000>;       //电池最大充电电压
    qcom,fg-cc-cv-threshold-mv = <4340>;   //恒流到恒压充电
    qcom,fastchg-current-ma = <3000>;      //电池的最大充电电流
    qcom,nom-batt-capacity-mah = <3950>;   //电池容量
    qcom,batt-id-kohm = <100>;             //电池的ID 阻抗
    qcom,battery-beta = <3435>;
    qcom,battery-type = "3055372_goertek_falconaec_3950mah_averaged_masterslave_aug21st2017";
    qcom,checksum = <0x0F66>;
    qcom,gui-version = "PMI8998GUI - 2.0.0.58";
    qcom,fg-profile-data = [ 
        94 1F 9E 05
        64 0A 5B 06
        7A 1D 77 F5
        EF 0B DF 14
        8B 18 E5 22
        B2 45 7E 52
        5B 00 00 00
        0F 00 00 00]

kernel 电池曲线的提交:

在msm8998-mtp.dtsi文件中,定义调用哪个电池曲线,如下代码调用了fg-gen3-batterydata-goertek-3950mah.dtsi 中的电池曲线。在高通调试电池曲线后,给的文件提交到arch/arm/boot/dts/qcom/目录下,修改#include”“,调用相应的曲线。

&vendor {
    mtp_batterydata: qcom,battery-data {
        qcom,batt-id-range-pct = <15>;
        #include "fg-gen3-batterydata-goertek-3950mah.dtsi"
    };
};
&pmi8998_fg {
    qcom,battery-data = <&mtp_batterydata>;
};

XBL 关于充电曲线的提交:

高通调完电池曲线,在给的文件中有.csv的文件。把此文件重命名为BATTERY.PROVISION,替换路径 boot_imagesQcomPkgDriversQcomChargerDxeBATTERY.PROVISION下的高通原始文件。

充电相关调试方法

  1. 通过adb 查看spmi8998 相关寄存器

下面的实例如何dump FG BATT_SOC 相关寄存器:

/sys/kernel/debug/regmap/spmi0-02 # echo 0xFF > count
/sys/kernel/debug/regmap/spmi0-02 # echo 0x4000 > address
/sys/kernel/debug/regmap/spmi0-02 # cat data

充电时,通过串口打印充电相关参数的命令如下

当测试充电时,通过串口设置如下命令,可以10秒钟,上传一次当前电量、充电电流、充电电压、充电状态、充电温度、充电类型。

while true;do 
echo "capacity : `cat /sys/class/power_supply/battery/capacity`";
echo "current_now : `cat /sys/class/power_supply/battery/current_now`";
echo "voltage_now : `cat /sys/class/power_supply/battery/voltage_now`";
echo "status : `cat /sys/class/power_supply/battery/status`";
echo "temp : `cat /sys/class/power_supply/battery/temp`";
echo "chg_type : `cat /sys/class/power_supply/battery/charge_type`";
echo "date : `date`";sleep 10;echo =====;
done

关于充电相关的 sys 节点:

/sys/class/power_supply/battery

充电温度控制相关修改:

835平台充电电压、电流根据温度设置如下图形所示:

qualcomm-msm8998-charging.png

设置4个温度点,五个区间分别为cold、cool、normal 、 warm 、hot, 此4个温度点寄存器地址如下:

0x00004162    FG_BATT_INFO_JEITA_TOO_COLD
0x00004163    FG_BATT_INFO_JEITA_COLD
0x00004164    FG_BATT_INFO_JEITA_HOT
0x00004165    FG_BATT_INFO_JEITA_TOO_HOT

此四个温度默认值为: 0 、5 、45、50度。可以通过如下程序修改:

#define DEFAULT_BATT_TEMP_COLD          -5
#define DEFAULT_BATT_TEMP_COOL          0
#define DEFAULT_BATT_TEMP_WARM          50
#define DEFAULT_BATT_TEMP_HOT           55

也可通过 如下dtsi 修改:

&pmi8998_fg {
    qcom,battery-data = <&mtp_batterydata>;
    qcom,fg-jeita-thresholds = <-5 0 50 55>;
 };

当在cold和hot区间时,电池不充电,当在cool和warm区间时,电池的充电电压,充电电流为JEITA_FVCOMP和JEITA_CCCOMP。 此两个值分别在如下寄存器中设置: | 0x00001091 | SCHG8998_CHGR_JEITA_FVCOMP_CFG | 寄存器默认值为:0x0E, 默认电压为:4.35 – 0.105 = 4.25 附近。 | 0x00001092 | SCHG8998_CHGR_JEITA_CCCOMP_CFG | 寄存器默认值为:0x28, 默认电流为:3A – 1A = 2A 如果需要修改此区间的充电电压、充电电流修改相应的寄存器即可。

835平台充电相关配置参数

qcom,fg-chg-term-current = <200>;
充电截止电流, 当电流小于此值时,充电结束。系统默认值为 100ma

qcom,fg-sys-term-current = <(-250)>; 系统截止电流,当充电电流大于此值时,电量为 100%。 系统默认值为 -125ma。

qcom,fg-recharge-voltage = <4250>; / example only 4.25V / 系统低于此阈值时,自动充电,此值默认为 4250 mv

CV戴在头上不充电的节点和相关代码: 不充电设置:

echo 1 > /sys/kernel/debug/qpnp-smbcharger/disable_chg

充电设置:

echo 0 > /sys/kernel/debug/qpnp-smbcharger/disable_chg

kernel/msm-4.4/drivers/power/supply/qcom/qpnp-smb2.c文件中添加如下相关代码:

rc = vote(chip->chg_disable_votable, USER_VOTER, val, 0);

参考文档:

  • 80-P2484-74_MSM8998 Linux Android PMIC Fuel Gauge Software.pdf
  • 80-VT310-138_Understanding PMI8998 Fuel Gauge.pdf
  • 80-p1087-2x_b_pmi8998_hardware_register_description.pdf
  • 80-p2484-42_a_uefi_pmic_software_user_guide.pdf