Skip to content

Commit 7384b0e

Browse files
Yuanjiang Yusre
authored andcommitted
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 <[email protected]> Signed-off-by: Baolin Wang <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 168e68d commit 7384b0e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

drivers/power/supply/sc27xx_fuel_gauge.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,6 @@ static int sc27xx_fgu_set_clbcnt(struct sc27xx_fgu_data *data, int clbcnt)
326326
{
327327
int ret;
328328

329-
clbcnt *= SC27XX_FGU_SAMPLE_HZ;
330-
331329
ret = regmap_update_bits(data->regmap,
332330
data->base + SC27XX_FGU_CLBCNT_SETL,
333331
SC27XX_FGU_CLBCNT_MASK, clbcnt);
@@ -362,7 +360,6 @@ static int sc27xx_fgu_get_clbcnt(struct sc27xx_fgu_data *data, int *clb_cnt)
362360

363361
*clb_cnt = ccl & SC27XX_FGU_CLBCNT_MASK;
364362
*clb_cnt |= (cch & SC27XX_FGU_CLBCNT_MASK) << SC27XX_FGU_CLBCNT_SHIFT;
365-
*clb_cnt /= SC27XX_FGU_SAMPLE_HZ;
366363

367364
return 0;
368365
}
@@ -380,10 +377,10 @@ static int sc27xx_fgu_get_capacity(struct sc27xx_fgu_data *data, int *cap)
380377

381378
/*
382379
* Convert coulomb counter to delta capacity (mAh), and set multiplier
383-
* as 100 to improve the precision.
380+
* as 10 to improve the precision.
384381
*/
385-
temp = DIV_ROUND_CLOSEST(delta_clbcnt, 360);
386-
temp = sc27xx_fgu_adc_to_current(data, temp);
382+
temp = DIV_ROUND_CLOSEST(delta_clbcnt * 10, 36 * SC27XX_FGU_SAMPLE_HZ);
383+
temp = sc27xx_fgu_adc_to_current(data, temp / 1000);
387384

388385
/*
389386
* 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)
790787
* Convert current capacity (mAh) to coulomb counter according to the
791788
* formula: 1 mAh =3.6 coulomb.
792789
*/
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);
794791
}
795792

796793
static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data)

0 commit comments

Comments
 (0)