diff options
author | Yuanjiang Yu <yuanjiang.yu@unisoc.com> | 2019-07-31 06:00:25 -0400 |
---|---|---|
committer | Sebastian Reichel <sebastian.reichel@collabora.com> | 2019-09-02 16:49:49 -0400 |
commit | 7384b0e7668f722fcf7abe56f61a7212debd0180 (patch) | |
tree | ddc1fa4eea24ad54b3c71ea2258a30d2f302336d | |
parent | 168e68d072756d631a210342d0429c969501b7cf (diff) |
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>
-rw-r--r-- | drivers/power/supply/sc27xx_fuel_gauge.c | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c index db7d07d5dae9..6a29f00aec48 100644 --- a/drivers/power/supply/sc27xx_fuel_gauge.c +++ b/drivers/power/supply/sc27xx_fuel_gauge.c | |||
@@ -326,8 +326,6 @@ static int sc27xx_fgu_set_clbcnt(struct sc27xx_fgu_data *data, int clbcnt) | |||
326 | { | 326 | { |
327 | int ret; | 327 | int ret; |
328 | 328 | ||
329 | clbcnt *= SC27XX_FGU_SAMPLE_HZ; | ||
330 | |||
331 | ret = regmap_update_bits(data->regmap, | 329 | ret = regmap_update_bits(data->regmap, |
332 | data->base + SC27XX_FGU_CLBCNT_SETL, | 330 | data->base + SC27XX_FGU_CLBCNT_SETL, |
333 | SC27XX_FGU_CLBCNT_MASK, clbcnt); | 331 | SC27XX_FGU_CLBCNT_MASK, clbcnt); |
@@ -362,7 +360,6 @@ static int sc27xx_fgu_get_clbcnt(struct sc27xx_fgu_data *data, int *clb_cnt) | |||
362 | 360 | ||
363 | *clb_cnt = ccl & SC27XX_FGU_CLBCNT_MASK; | 361 | *clb_cnt = ccl & SC27XX_FGU_CLBCNT_MASK; |
364 | *clb_cnt |= (cch & SC27XX_FGU_CLBCNT_MASK) << SC27XX_FGU_CLBCNT_SHIFT; | 362 | *clb_cnt |= (cch & SC27XX_FGU_CLBCNT_MASK) << SC27XX_FGU_CLBCNT_SHIFT; |
365 | *clb_cnt /= SC27XX_FGU_SAMPLE_HZ; | ||
366 | 363 | ||
367 | return 0; | 364 | return 0; |
368 | } | 365 | } |
@@ -380,10 +377,10 @@ static int sc27xx_fgu_get_capacity(struct sc27xx_fgu_data *data, int *cap) | |||
380 | 377 | ||
381 | /* | 378 | /* |
382 | * Convert coulomb counter to delta capacity (mAh), and set multiplier | 379 | * Convert coulomb counter to delta capacity (mAh), and set multiplier |
383 | * as 100 to improve the precision. | 380 | * as 10 to improve the precision. |
384 | */ | 381 | */ |
385 | temp = DIV_ROUND_CLOSEST(delta_clbcnt, 360); | 382 | temp = DIV_ROUND_CLOSEST(delta_clbcnt * 10, 36 * SC27XX_FGU_SAMPLE_HZ); |
386 | temp = sc27xx_fgu_adc_to_current(data, temp); | 383 | temp = sc27xx_fgu_adc_to_current(data, temp / 1000); |
387 | 384 | ||
388 | /* | 385 | /* |
389 | * Convert to capacity percent of the battery total capacity, | 386 | * Convert to capacity percent of the battery total capacity, |
@@ -790,7 +787,7 @@ static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity) | |||
790 | * Convert current capacity (mAh) to coulomb counter according to the | 787 | * Convert current capacity (mAh) to coulomb counter according to the |
791 | * formula: 1 mAh =3.6 coulomb. | 788 | * formula: 1 mAh =3.6 coulomb. |
792 | */ | 789 | */ |
793 | return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc, 10); | 790 | return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc * SC27XX_FGU_SAMPLE_HZ, 10); |
794 | } | 791 | } |
795 | 792 | ||
796 | static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data) | 793 | static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data) |