Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: sc27xx: Fix the the accuracy issue of coulomb calculation

The Spreadtrum fuel gauge will multiply by 2 for counting the coulomb
counter to improve the accuracy, which means the value saved in fuel
gauge is: coulomb counter * 2 * 1000ma_adc. Thus fix the conversion
formular to improve the accuracy of calculating the battery capacity.

Signed-off-by: Yuanjiang Yu <yuanjiang.yu@unisoc.com>
Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Yuanjiang Yu and committed by
Sebastian Reichel
7384b0e7 168e68d0

+4 -7
+4 -7
drivers/power/supply/sc27xx_fuel_gauge.c
··· 326 326 { 327 327 int ret; 328 328 329 - clbcnt *= SC27XX_FGU_SAMPLE_HZ; 330 - 331 329 ret = regmap_update_bits(data->regmap, 332 330 data->base + SC27XX_FGU_CLBCNT_SETL, 333 331 SC27XX_FGU_CLBCNT_MASK, clbcnt); ··· 360 362 361 363 *clb_cnt = ccl & SC27XX_FGU_CLBCNT_MASK; 362 364 *clb_cnt |= (cch & SC27XX_FGU_CLBCNT_MASK) << SC27XX_FGU_CLBCNT_SHIFT; 363 - *clb_cnt /= SC27XX_FGU_SAMPLE_HZ; 364 365 365 366 return 0; 366 367 } ··· 377 380 378 381 /* 379 382 * Convert coulomb counter to delta capacity (mAh), and set multiplier 380 - * as 100 to improve the precision. 383 + * as 10 to improve the precision. 381 384 */ 382 - temp = DIV_ROUND_CLOSEST(delta_clbcnt, 360); 383 - temp = sc27xx_fgu_adc_to_current(data, temp); 385 + temp = DIV_ROUND_CLOSEST(delta_clbcnt * 10, 36 * SC27XX_FGU_SAMPLE_HZ); 386 + temp = sc27xx_fgu_adc_to_current(data, temp / 1000); 384 387 385 388 /* 386 389 * Convert to capacity percent of the battery total capacity, ··· 787 790 * Convert current capacity (mAh) to coulomb counter according to the 788 791 * formula: 1 mAh =3.6 coulomb. 789 792 */ 790 - return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc, 10); 793 + return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc * SC27XX_FGU_SAMPLE_HZ, 10); 791 794 } 792 795 793 796 static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data)