一番折腾,发现控制电池温度的代码在
drivers/power/supply/lge/extension-fg-gen3.c
根据说明,这个文件文件将包含在qpnp-fg-gen3.c的末尾
然后在里面翻到了计算电池温度的算法:
/* calculate_battery_temperature
* bias : 1st compensation by predefined diffs
* icomp : 2nd compensation by (i^2 * k)
*/
static int calculate_battery_temperature(/* @Nonnull */ struct fg_chip *chip)
{
int battemp_bias, battemp_icomp, battemp_cell = 0;
int i, temp, ichg = 0, tbl_pt = 0;
union power_supply_propval val = { 0, };
bool tbl_changed = false;
static int pre_tbl_pt = -1;
if (fg_get_battery_temp(chip, &battemp_cell)){
pr_info("get real batt therm error\n");
return LGE_FG_INITVAL;
}
if (!tcomp.load_done) {
pr_info("not ready tcomp table. raw temp=%d\n", battemp_cell);
return battemp_cell;
}
if (!tcomp.icoeff_load_done) {
pr_info("not ready icoeff. raw temp=%d\n", battemp_cell);
return battemp_cell;
}
if (tcomp.load_max > 1) {
switch (get_charging_type(chip)) {
case TCOMP_CHG_WLC_LCDOFF: tbl_pt = 1; break;
case TCOMP_CHG_WLC_LCDON: tbl_pt = 2; break;
default: tbl_pt = 0; break;
}
}
else
tbl_pt = 0;
if (pre_tbl_pt >= 0 )
if (pre_tbl_pt != tbl_pt)
tbl_changed = true;
pre_tbl_pt = tbl_pt;
/* Compensating battemp_bias */
for (i = 0; i < TCOMP_COUNT; i++) {
if (battemp_cell < tcomp.table[tbl_pt][i].temp_cell)
break;
}
if (i == 0)
battemp_bias = tcomp.table[tbl_pt][0].temp_bias;
else if (i == TCOMP_COUNT)
battemp_bias = tcomp.table[tbl_pt][TCOMP_COUNT-1].temp_bias;
else
battemp_bias =
( (tcomp.table[tbl_pt][i].temp_bias -
tcomp.table[tbl_pt][i-1].temp_bias)
* (battemp_cell - tcomp.table[tbl_pt][i-1].temp_cell)
/ (tcomp.table[tbl_pt][i].temp_cell -
tcomp.table[tbl_pt][i-1].temp_cell)
) + tcomp.table[tbl_pt][i-1].temp_bias;
/* Compensating battemp_icomp */
if (chip->batt_psy) {
if (tcomp.qnovo_charging) {
ichg = get_batt_temp_current(chip);
}
else {
if (!power_supply_get_property(
chip->batt_psy, POWER_SUPPLY_PROP_STATUS, &val)
&& val.intval == POWER_SUPPLY_STATUS_CHARGING
&& !power_supply_get_property(
chip->batt_psy, POWER_SUPPLY_PROP_CURRENT_NOW, &val)
&& val.intval < 0)
ichg = ((val.intval) / 1000);
}
} else {
pr_info("Battery is not available, %d(=%d+%d) as batt temp\n",
battemp_cell + battemp_bias, battemp_cell, battemp_bias);
}
battemp_icomp = ichg * ichg * tcomp.icoeff / 10000000;
temp = battemp_cell + battemp_bias - battemp_icomp;
if (tcomp.logging)
pr_info("Battery temperature : "
"%d = (%d)(cell) + (%d)(bias) - %d(icomp), "
"icoeff = %d, ichg = %d\n",
temp, battemp_cell, battemp_bias, battemp_icomp,
tcomp.icoeff, ichg);
if (tcomp.rise_cut || tcomp.fall_cut)
return filtered_batt_therm(tbl_changed, temp, battemp_cell);
return temp;
}
然后又一顿折腾,发现算法里面的ichg数值异常,改了半天改不明白
于是hardcode之😂
battemp_icomp = ichg * ichg * tcomp.icoeff / 10000000;
temp = battemp_cell + battemp_bias - battemp_icomp;
temp = 321;