]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.1/power-supply-cpcap-battery-fix-signed-counter-sample.patch
Drop watchdog patch
[thirdparty/kernel/stable-queue.git] / queue-5.1 / power-supply-cpcap-battery-fix-signed-counter-sample.patch
1 From 84bf8b2d1a4818c56dbe5df58e2315438779a7a0 Mon Sep 17 00:00:00 2001
2 From: Tony Lindgren <tony@atomide.com>
3 Date: Sun, 7 Apr 2019 11:12:50 -0700
4 Subject: power: supply: cpcap-battery: Fix signed counter sample register
5
6 [ Upstream commit c68b901ac4fa969db8917b6a9f9b40524a690d20 ]
7
8 The accumulator sample register is signed 32-bits wide register on
9 droid 4. And only the earlier version of cpcap has a signed 24-bits
10 wide register. We're currently passing it around as unsigned, so
11 let's fix that and use sign_extend32() for the earlier revision.
12
13 Signed-off-by: Tony Lindgren <tony@atomide.com>
14 Acked-by: Pavel Machek <pavel@ucw.cz>
15 Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
16 Signed-off-by: Sasha Levin <sashal@kernel.org>
17 ---
18 drivers/power/supply/cpcap-battery.c | 11 ++++++-----
19 1 file changed, 6 insertions(+), 5 deletions(-)
20
21 diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
22 index 6887870ba32c..453baa8f7d73 100644
23 --- a/drivers/power/supply/cpcap-battery.c
24 +++ b/drivers/power/supply/cpcap-battery.c
25 @@ -82,7 +82,7 @@ struct cpcap_battery_config {
26 };
27
28 struct cpcap_coulomb_counter_data {
29 - s32 sample; /* 24-bits */
30 + s32 sample; /* 24 or 32 bits */
31 s32 accumulator;
32 s16 offset; /* 10-bits */
33 };
34 @@ -213,7 +213,7 @@ static int cpcap_battery_get_current(struct cpcap_battery_ddata *ddata)
35 * TI or ST coulomb counter in the PMIC.
36 */
37 static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
38 - u32 sample, s32 accumulator,
39 + s32 sample, s32 accumulator,
40 s16 offset, u32 divider)
41 {
42 s64 acc;
43 @@ -224,7 +224,6 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
44 if (!divider)
45 return 0;
46
47 - sample &= 0xffffff; /* 24-bits, unsigned */
48 offset &= 0x7ff; /* 10-bits, signed */
49
50 switch (ddata->vendor) {
51 @@ -259,7 +258,7 @@ static int cpcap_battery_cc_raw_div(struct cpcap_battery_ddata *ddata,
52
53 /* 3600000μAms = 1μAh */
54 static int cpcap_battery_cc_to_uah(struct cpcap_battery_ddata *ddata,
55 - u32 sample, s32 accumulator,
56 + s32 sample, s32 accumulator,
57 s16 offset)
58 {
59 return cpcap_battery_cc_raw_div(ddata, sample,
60 @@ -268,7 +267,7 @@ static int cpcap_battery_cc_to_uah(struct cpcap_battery_ddata *ddata,
61 }
62
63 static int cpcap_battery_cc_to_ua(struct cpcap_battery_ddata *ddata,
64 - u32 sample, s32 accumulator,
65 + s32 sample, s32 accumulator,
66 s16 offset)
67 {
68 return cpcap_battery_cc_raw_div(ddata, sample,
69 @@ -312,6 +311,8 @@ cpcap_battery_read_accumulated(struct cpcap_battery_ddata *ddata,
70 /* Sample value CPCAP_REG_CCS1 & 2 */
71 ccd->sample = (buf[1] & 0x0fff) << 16;
72 ccd->sample |= buf[0];
73 + if (ddata->vendor == CPCAP_VENDOR_TI)
74 + ccd->sample = sign_extend32(24, ccd->sample);
75
76 /* Accumulator value CPCAP_REG_CCA1 & 2 */
77 ccd->accumulator = ((s16)buf[3]) << 16;
78 --
79 2.20.1
80