Commit 4413f9e9 authored by Hans de Goede's avatar Hans de Goede Committed by Sebastian Reichel

power: supply: bq25890: Fix setting of F_CONV_RATE rate when disabling HiZ mode

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 {}" block 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.
Reviewed-by: default avatarMarek Vasut <marex@denx.de>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent c688e0c4
...@@ -795,6 +795,7 @@ static int bq25890_get_chip_state(struct bq25890_device *bq, ...@@ -795,6 +795,7 @@ static int bq25890_get_chip_state(struct bq25890_device *bq,
static irqreturn_t __bq25890_handle_irq(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; struct bq25890_state new_state;
int ret; int ret;
...@@ -805,33 +806,25 @@ static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq) ...@@ -805,33 +806,25 @@ static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq)
if (!memcmp(&bq->state, &new_state, sizeof(new_state))) if (!memcmp(&bq->state, &new_state, sizeof(new_state)))
return IRQ_NONE; return IRQ_NONE;
/* power removed or HiZ */ /*
if ((!new_state.online || new_state.hiz) && bq->state.online) { * Restore HiZ bit in case it was set by user. The chip does not retain
/* disable ADC */ * this bit on cable replug, hence the bit must be reset manually here.
ret = bq25890_field_write(bq, F_CONV_RATE, 0); */
if (new_state.online && !bq->state.online && bq->force_hiz) {
ret = bq25890_field_write(bq, F_EN_HIZ, bq->force_hiz);
if (ret < 0) if (ret < 0)
goto error; goto error;
} else if (new_state.online && !bq->state.online) { new_state.hiz = 1;
/* }
* 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;
}
if (!new_state.hiz) { /* Should period ADC sampling be enabled? */
/* power inserted and not HiZ */ adc_conv_rate = bq->state.online && !bq->state.hiz;
/* enable ADC, to have control of charge current/voltage */ new_adc_conv_rate = new_state.online && !new_state.hiz;
ret = bq25890_field_write(bq, F_CONV_RATE, 1);
if (ret < 0) if (new_adc_conv_rate != adc_conv_rate) {
goto error; ret = bq25890_field_write(bq, F_CONV_RATE, new_adc_conv_rate);
} if (ret < 0)
goto error;
} }
bq->state = new_state; bq->state = new_state;
......
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