aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Lindgren <tony@atomide.com>2019-04-07 14:12:51 -0400
committerSebastian Reichel <sre@kernel.org>2019-04-15 16:52:52 -0400
commit35439b7ab2dbd458377efaa979820360f4951784 (patch)
tree97b459a2ba7d98248dc9c1a72a9f6a4c9a3f04a2
parentc68b901ac4fa969db8917b6a9f9b40524a690d20 (diff)
power: supply: cpcap-battery: Fix coulomb counter calibration register use
The coulomb counter calibration is not CCO, it's CCM. And the CCM is nine bits wide signed register, so let's use sign_extend32() for it. Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-rw-r--r--drivers/power/supply/cpcap-battery.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index a9e4952e9c12..c8c893de00fd 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -84,7 +84,7 @@ struct cpcap_battery_config {
84struct cpcap_coulomb_counter_data { 84struct cpcap_coulomb_counter_data {
85 s32 sample; /* 24 or 32 bits */ 85 s32 sample; /* 24 or 32 bits */
86 s32 accumulator; 86 s32 accumulator;
87 s16 offset; /* 10-bits */ 87 s16 offset; /* 9 bits */
88}; 88};
89 89
90enum cpcap_battery_state { 90enum cpcap_battery_state {
@@ -224,8 +224,6 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
224 if (!divider) 224 if (!divider)
225 return 0; 225 return 0;
226 226
227 offset &= 0x7ff; /* 10-bits, signed */
228
229 switch (ddata->vendor) { 227 switch (ddata->vendor) {
230 case CPCAP_VENDOR_ST: 228 case CPCAP_VENDOR_ST:
231 cc_lsb = 95374; /* μAms per LSB */ 229 cc_lsb = 95374; /* μAms per LSB */
@@ -318,12 +316,12 @@ cpcap_battery_read_accumulated(struct cpcap_battery_ddata *ddata,
318 ccd->accumulator = ((s16)buf[3]) << 16; 316 ccd->accumulator = ((s16)buf[3]) << 16;
319 ccd->accumulator |= buf[2]; 317 ccd->accumulator |= buf[2];
320 318
321 /* Offset value CPCAP_REG_CCO */ 319 /*
322 ccd->offset = buf[5]; 320 * Coulomb counter calibration offset is CPCAP_REG_CCM,
323 321 * REG_CCO seems unused
324 /* Adjust offset based on mode value CPCAP_REG_CCM? */ 322 */
325 if (buf[4] >= 0x200) 323 ccd->offset = buf[4];
326 ccd->offset |= 0xfc00; 324 ccd->offset = sign_extend32(ccd->offset, 9);
327 325
328 return cpcap_battery_cc_to_uah(ddata, 326 return cpcap_battery_cc_to_uah(ddata,
329 ccd->sample, 327 ccd->sample,