Skip to content

Commit d1b2509

Browse files
Marek Vasutsre
authored andcommitted
power: supply: bq25890: Factor out chip state update
Pull the chip state and ADC conversion update functionality out into separate function, so it can be reused elsewhere in the driver. This is a preparatory patch, no functional change. Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-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 5dd4826 commit d1b2509

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

drivers/power/supply/bq25890_charger.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -454,27 +454,36 @@ static int bq25890_get_vbus_voltage(struct bq25890_device *bq)
454454
return bq25890_find_val(ret, TBL_VBUSV);
455455
}
456456

457-
static int bq25890_power_supply_get_property(struct power_supply *psy,
458-
enum power_supply_property psp,
459-
union power_supply_propval *val)
457+
static void bq25890_update_state(struct bq25890_device *bq,
458+
enum power_supply_property psp,
459+
struct bq25890_state *state)
460460
{
461-
struct bq25890_device *bq = power_supply_get_drvdata(psy);
462-
struct bq25890_state state;
463461
bool do_adc_conv;
464462
int ret;
465463

466464
mutex_lock(&bq->lock);
467465
/* update state in case we lost an interrupt */
468466
__bq25890_handle_irq(bq);
469-
state = bq->state;
470-
do_adc_conv = !state.online && bq25890_is_adc_property(psp);
467+
*state = bq->state;
468+
do_adc_conv = !state->online && bq25890_is_adc_property(psp);
471469
if (do_adc_conv)
472470
bq25890_field_write(bq, F_CONV_START, 1);
473471
mutex_unlock(&bq->lock);
474472

475473
if (do_adc_conv)
476474
regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START],
477475
ret, !ret, 25000, 1000000);
476+
}
477+
478+
static int bq25890_power_supply_get_property(struct power_supply *psy,
479+
enum power_supply_property psp,
480+
union power_supply_propval *val)
481+
{
482+
struct bq25890_device *bq = power_supply_get_drvdata(psy);
483+
struct bq25890_state state;
484+
int ret;
485+
486+
bq25890_update_state(bq, psp, &state);
478487

479488
switch (psp) {
480489
case POWER_SUPPLY_PROP_STATUS:

0 commit comments

Comments
 (0)