From: Hans de Goede <hdegoede@redhat.com>
To: Sebastian Reichel <sre@kernel.org>, Marek Vasut <marex@denx.de>
Cc: Hans de Goede <hdegoede@redhat.com>, linux-pm@vger.kernel.org
Subject: [PATCH 06/10] power: supply: bq25890: Fix setting of F_CONV_RATE rate when disabling HiZ mode
Date: Sun, 27 Nov 2022 19:02:29 +0100 [thread overview]
Message-ID: <20221127180233.103678-7-hdegoede@redhat.com> (raw)
In-Reply-To: <20221127180233.103678-1-hdegoede@redhat.com>
The recent "power: supply: bq25890: Add HiZ mode support" change
leaves F_CONV_RATE rate unset when disabling HiZ mode (setting
POWER_SUPPLY_PROP_ONLINE to 1) while a charger is connected.
Separate the resetting HiZ mode when necessary because of a charger
(re)plug event into its own if which runs first.
And fix the setting of F_CONV_RATE rate by adding helper variables for
the old and new F_CONV_RATE state which check both the online and hiz bits
and then compare the helper variables to see if a F_CONV_RATE update is
necessary.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
drivers/power/supply/bq25890_charger.c | 41 +++++++++++---------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 2dffc5df0969..bd6858231271 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -795,6 +795,7 @@ static int bq25890_get_chip_state(struct bq25890_device *bq,
static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq)
{
+ bool adc_conv_rate, new_adc_conv_rate;
struct bq25890_state new_state;
int ret;
@@ -805,33 +806,25 @@ static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq)
if (!memcmp(&bq->state, &new_state, sizeof(new_state)))
return IRQ_NONE;
- /* power removed or HiZ */
- if ((!new_state.online || new_state.hiz) && bq->state.online) {
- /* disable ADC */
- ret = bq25890_field_write(bq, F_CONV_RATE, 0);
+ /*
+ * Restore HiZ bit in case it was set by user. The chip does not retain
+ * this bit on cable replug, hence the bit must be reset manually here.
+ */
+ if (new_state.online && !bq->state.online && bq->force_hiz) {
+ ret = bq25890_field_write(bq, F_EN_HIZ, bq->force_hiz);
if (ret < 0)
goto error;
- } else if (new_state.online && !bq->state.online) {
- /*
- * Restore HiZ bit in case it was set by user.
- * The chip does not retain this bit once the
- * cable is re-plugged, hence the bit must be
- * reset manually here.
- */
- if (bq->force_hiz) {
- ret = bq25890_field_write(bq, F_EN_HIZ, bq->force_hiz);
- if (ret < 0)
- goto error;
- new_state.hiz = 1;
- }
+ new_state.hiz = 1;
+ }
- if (!new_state.hiz) {
- /* power inserted and not HiZ */
- /* enable ADC, to have control of charge current/voltage */
- ret = bq25890_field_write(bq, F_CONV_RATE, 1);
- if (ret < 0)
- goto error;
- }
+ /* Should period ADC sampling be enabled? */
+ adc_conv_rate = bq->state.online && !bq->state.hiz;
+ new_adc_conv_rate = new_state.online && !new_state.hiz;
+
+ if (new_adc_conv_rate != adc_conv_rate) {
+ ret = bq25890_field_write(bq, F_CONV_RATE, new_adc_conv_rate);
+ if (ret < 0)
+ goto error;
}
bq->state = new_state;
--
2.38.1
next prev parent reply other threads:[~2022-11-27 18:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-27 18:02 [PATCH 00/10] power: supply: bq25890: Fixes for 6.2 + further work for 6.3 Hans de Goede
2022-11-27 18:02 ` [PATCH 01/10] power: supply: bq25890: Only use pdata->regulator_init_data for vbus Hans de Goede
2022-11-27 21:16 ` Marek Vasut
2022-11-27 23:30 ` Sebastian Reichel
2022-11-27 18:02 ` [PATCH 02/10] power: supply: bq25890: Ensure pump_express_work is cancelled on remove Hans de Goede
2022-11-27 21:17 ` Marek Vasut
2022-11-27 23:17 ` Sebastian Reichel
2022-11-28 7:20 ` Hans de Goede
2022-11-27 18:02 ` [PATCH 03/10] power: supply: bq25890: Fix usb-notifier probe and remove races Hans de Goede
2022-11-27 21:19 ` Marek Vasut
2022-11-27 18:02 ` [PATCH 04/10] power: supply: bq25890: Factor out chip state update Hans de Goede
2022-11-27 18:02 ` [PATCH 05/10] power: supply: bq25890: Add HiZ mode support Hans de Goede
2022-11-27 18:02 ` Hans de Goede [this message]
2022-11-27 21:24 ` [PATCH 06/10] power: supply: bq25890: Fix setting of F_CONV_RATE rate when disabling HiZ mode Marek Vasut
2022-11-27 18:02 ` [PATCH 07/10] power: supply: bq25890: Always take HiZ mode into account for ADC rate Hans de Goede
2022-11-27 21:25 ` Marek Vasut
2022-11-27 18:02 ` [PATCH 08/10] power: supply: bq25890: Support boards with more then one charger IC Hans de Goede
2022-11-27 21:27 ` Marek Vasut
2022-11-27 18:02 ` [PATCH 09/10] power: supply: bq25890: Add support for having a secondary " Hans de Goede
2022-11-27 21:33 ` Marek Vasut
2022-11-27 18:02 ` [PATCH 10/10] power: supply: bq25890: Add new linux,iinlim-percentage property Hans de Goede
2022-11-27 21:34 ` Marek Vasut
2022-11-28 9:16 ` Hans de Goede
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=20221127180233.103678-7-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=linux-pm@vger.kernel.org \
--cc=marex@denx.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox