Commit c59b3bad authored by Tony Lindgren's avatar Tony Lindgren Committed by Sebastian Reichel

power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64

We can simplify cpcap_battery_cc_raw_div() with div_s64.

Cc: Merlijn Wajer <merlijn@wizzup.org>
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 458f5c8c
...@@ -33,8 +33,6 @@ ...@@ -33,8 +33,6 @@
#include <linux/iio/types.h> #include <linux/iio/types.h>
#include <linux/mfd/motorola-cpcap.h> #include <linux/mfd/motorola-cpcap.h>
#include <asm/div64.h>
/* /*
* Register bit defines for CPCAP_REG_BPEOL. Some of these seem to * Register bit defines for CPCAP_REG_BPEOL. Some of these seem to
* map to MC13783UG.pdf "Table 5-19. Register 13, Power Control 0" * map to MC13783UG.pdf "Table 5-19. Register 13, Power Control 0"
...@@ -219,28 +217,17 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata, ...@@ -219,28 +217,17 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
s16 offset, u32 divider) s16 offset, u32 divider)
{ {
s64 acc; s64 acc;
u64 tmp;
int avg_current;
if (!divider) if (!divider)
return 0; return 0;
acc = accumulator; acc = accumulator;
acc = acc - ((s64)sample * offset); acc -= (s64)sample * offset;
acc *= ddata->cc_lsb;
if (acc >= 0) acc *= -1;
tmp = acc; acc = div_s64(acc, divider);
else
tmp = acc * -1;
tmp = tmp * ddata->cc_lsb; return acc;
do_div(tmp, divider);
avg_current = tmp;
if (acc >= 0)
return -avg_current;
else
return avg_current;
} }
/* 3600000μAms = 1μAh */ /* 3600000μAms = 1μAh */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment