Skip to content

Commit 4413f9e

Browse files
jwrdegoedesre
authored andcommitted
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: Marek Vasut <marex@denx.de> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent c688e0c commit 4413f9e

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

drivers/power/supply/bq25890_charger.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ static int bq25890_get_chip_state(struct bq25890_device *bq,
795795

796796
static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq)
797797
{
798+
bool adc_conv_rate, new_adc_conv_rate;
798799
struct bq25890_state new_state;
799800
int ret;
800801

@@ -805,33 +806,25 @@ static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq)
805806
if (!memcmp(&bq->state, &new_state, sizeof(new_state)))
806807
return IRQ_NONE;
807808

808-
/* power removed or HiZ */
809-
if ((!new_state.online || new_state.hiz) && bq->state.online) {
810-
/* disable ADC */
811-
ret = bq25890_field_write(bq, F_CONV_RATE, 0);
809+
/*
810+
* Restore HiZ bit in case it was set by user. The chip does not retain
811+
* this bit on cable replug, hence the bit must be reset manually here.
812+
*/
813+
if (new_state.online && !bq->state.online && bq->force_hiz) {
814+
ret = bq25890_field_write(bq, F_EN_HIZ, bq->force_hiz);
812815
if (ret < 0)
813816
goto error;
814-
} else if (new_state.online && !bq->state.online) {
815-
/*
816-
* Restore HiZ bit in case it was set by user.
817-
* The chip does not retain this bit once the
818-
* cable is re-plugged, hence the bit must be
819-
* reset manually here.
820-
*/
821-
if (bq->force_hiz) {
822-
ret = bq25890_field_write(bq, F_EN_HIZ, bq->force_hiz);
823-
if (ret < 0)
824-
goto error;
825-
new_state.hiz = 1;
826-
}
817+
new_state.hiz = 1;
818+
}
827819

828-
if (!new_state.hiz) {
829-
/* power inserted and not HiZ */
830-
/* enable ADC, to have control of charge current/voltage */
831-
ret = bq25890_field_write(bq, F_CONV_RATE, 1);
832-
if (ret < 0)
833-
goto error;
834-
}
820+
/* Should period ADC sampling be enabled? */
821+
adc_conv_rate = bq->state.online && !bq->state.hiz;
822+
new_adc_conv_rate = new_state.online && !new_state.hiz;
823+
824+
if (new_adc_conv_rate != adc_conv_rate) {
825+
ret = bq25890_field_write(bq, F_CONV_RATE, new_adc_conv_rate);
826+
if (ret < 0)
827+
goto error;
835828
}
836829

837830
bq->state = new_state;

0 commit comments

Comments
 (0)