From: Linus Walleij <linus.walleij@linaro.org>
To: Sebastian Reichel <sre@kernel.org>, Marcus Cooper <codekipper@gmail.com>
Cc: linux-pm@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH 04/11] power: supply: ab8500_fg: Break loop for measurement
Date: Thu, 27 Jan 2022 02:12:29 +0100 [thread overview]
Message-ID: <20220127011236.332687-5-linus.walleij@linaro.org> (raw)
In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org>
In the Samsung code tree we find that it can happen that this
measurement loop goes on for a long time, and it seems like a
good idea to break it after 70 iterations if it goes on for
too long.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/power/supply/ab8500_fg.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
index 236fd9f9d6f1..29896f09fd17 100644
--- a/drivers/power/supply/ab8500_fg.c
+++ b/drivers/power/supply/ab8500_fg.c
@@ -45,6 +45,7 @@
#define SEC_TO_SAMPLE(S) (S * 4)
#define NBR_AVG_SAMPLES 20
+#define WAIT_FOR_INST_CURRENT_MAX 70
#define LOW_BAT_CHECK_INTERVAL (HZ / 16) /* 62.5 ms */
@@ -926,10 +927,18 @@ static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di)
vbat_uv += ab8500_fg_bat_voltage(di);
i++;
usleep_range(5000, 6000);
- } while (!ab8500_fg_inst_curr_done(di));
+ } while (!ab8500_fg_inst_curr_done(di) &&
+ i <= WAIT_FOR_INST_CURRENT_MAX);
+
+ if (i > WAIT_FOR_INST_CURRENT_MAX) {
+ dev_err(di->dev,
+ "TIMEOUT: return capacity based on uncompensated measurement of VBAT\n");
+ goto calc_cap;
+ }
ab8500_fg_inst_curr_finalize(di, &di->inst_curr_ua);
+calc_cap:
di->vbat_uv = vbat_uv / i;
res = ab8500_fg_battery_resistance(di);
--
2.34.1
next prev parent reply other threads:[~2022-01-27 1:14 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-27 1:12 [PATCH 00/11] AB8500 charging fixes Linus Walleij
2022-01-27 1:12 ` [PATCH 01/11] power: supply: ab8500: Drop BATCTRL thermal mode Linus Walleij
2022-01-27 1:12 ` [PATCH 02/11] power: supply: ab8500: Swap max and overvoltage Linus Walleij
2022-01-27 1:12 ` [PATCH 03/11] power: supply: ab8500: Integrate thermal zone Linus Walleij
2022-01-27 1:12 ` Linus Walleij [this message]
2022-01-27 1:12 ` [PATCH 05/11] power: supply: ab8500_fg: Break out load compensated voltage Linus Walleij
2022-01-27 22:31 ` kernel test robot
2022-01-27 1:12 ` [PATCH 06/11] power: supply: ab8500_fg: Safeguard " Linus Walleij
2022-01-27 1:12 ` [PATCH 07/11] power: supply: ab8500_fg: Drop useless parameter Linus Walleij
2022-01-27 1:12 ` [PATCH 08/11] power: supply: ab8500_chargalg: Drop charging step Linus Walleij
2022-01-27 1:12 ` [PATCH 09/11] power: supply: ab8500_chargalg: Drop enable/disable sysfs Linus Walleij
2022-01-27 1:12 ` [PATCH 10/11] power: supply: ab8500_charger: Restrict ADC retrieveal Linus Walleij
2022-01-27 1:12 ` [PATCH 11/11] power: supply: ab8500_charger: Fix VBAT interval check Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220127011236.332687-5-linus.walleij@linaro.org \
--to=linus.walleij@linaro.org \
--cc=codekipper@gmail.com \
--cc=linux-pm@vger.kernel.org \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.