diff mbox series

[1/2] power: supply: bq25890: Factor out chip state update

Message ID 20221109221504.79562-1-marex@denx.de
State Superseded
Headers show
Series [1/2] power: supply: bq25890: Factor out chip state update | expand

Commit Message

Marek Vasut Nov. 9, 2022, 10:15 p.m. UTC
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.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Hans de Goede <hdegoede@redhat.com>
Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
Cc: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/bq25890_charger.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

Comments

Hans de Goede Nov. 19, 2022, 1:49 p.m. UTC | #1
Hi,

On 11/9/22 23:15, Marek Vasut wrote:
> 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.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
> Cc: Hans de Goede <hdegoede@redhat.com>
> Cc: Sebastian Reichel <sebastian.reichel@collabora.com>
> Cc: Sebastian Reichel <sre@kernel.org>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> ---
>  drivers/power/supply/bq25890_charger.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
> index f0362dcb935e9..676eb66374e01 100644
> --- a/drivers/power/supply/bq25890_charger.c
> +++ b/drivers/power/supply/bq25890_charger.c
> @@ -454,20 +454,18 @@ static int bq25890_get_vbus_voltage(struct bq25890_device *bq)
>  	return bq25890_find_val(ret, TBL_VBUSV);
>  }
>  
> -static int bq25890_power_supply_get_property(struct power_supply *psy,
> -					     enum power_supply_property psp,
> -					     union power_supply_propval *val)
> +static void bq25890_update_state(struct bq25890_device *bq,
> +				 enum power_supply_property psp,
> +				 struct bq25890_state *state)
>  {
> -	struct bq25890_device *bq = power_supply_get_drvdata(psy);
> -	struct bq25890_state state;
>  	bool do_adc_conv;
>  	int ret;
>  
>  	mutex_lock(&bq->lock);
>  	/* update state in case we lost an interrupt */
>  	__bq25890_handle_irq(bq);
> -	state = bq->state;
> -	do_adc_conv = !state.online && bq25890_is_adc_property(psp);
> +	*state = bq->state;
> +	do_adc_conv = !state->online && bq25890_is_adc_property(psp);
>  	if (do_adc_conv)
>  		bq25890_field_write(bq, F_CONV_START, 1);
>  	mutex_unlock(&bq->lock);
> @@ -475,6 +473,17 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
>  	if (do_adc_conv)
>  		regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START],
>  			ret, !ret, 25000, 1000000);
> +}
> +
> +static int bq25890_power_supply_get_property(struct power_supply *psy,
> +					     enum power_supply_property psp,
> +					     union power_supply_propval *val)
> +{
> +	struct bq25890_device *bq = power_supply_get_drvdata(psy);
> +	struct bq25890_state state;
> +	int ret;
> +
> +	bq25890_update_state(bq, psp, &state);
>  
>  	switch (psp) {
>  	case POWER_SUPPLY_PROP_STATUS:
diff mbox series

Patch

diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index f0362dcb935e9..676eb66374e01 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -454,20 +454,18 @@  static int bq25890_get_vbus_voltage(struct bq25890_device *bq)
 	return bq25890_find_val(ret, TBL_VBUSV);
 }
 
-static int bq25890_power_supply_get_property(struct power_supply *psy,
-					     enum power_supply_property psp,
-					     union power_supply_propval *val)
+static void bq25890_update_state(struct bq25890_device *bq,
+				 enum power_supply_property psp,
+				 struct bq25890_state *state)
 {
-	struct bq25890_device *bq = power_supply_get_drvdata(psy);
-	struct bq25890_state state;
 	bool do_adc_conv;
 	int ret;
 
 	mutex_lock(&bq->lock);
 	/* update state in case we lost an interrupt */
 	__bq25890_handle_irq(bq);
-	state = bq->state;
-	do_adc_conv = !state.online && bq25890_is_adc_property(psp);
+	*state = bq->state;
+	do_adc_conv = !state->online && bq25890_is_adc_property(psp);
 	if (do_adc_conv)
 		bq25890_field_write(bq, F_CONV_START, 1);
 	mutex_unlock(&bq->lock);
@@ -475,6 +473,17 @@  static int bq25890_power_supply_get_property(struct power_supply *psy,
 	if (do_adc_conv)
 		regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START],
 			ret, !ret, 25000, 1000000);
+}
+
+static int bq25890_power_supply_get_property(struct power_supply *psy,
+					     enum power_supply_property psp,
+					     union power_supply_propval *val)
+{
+	struct bq25890_device *bq = power_supply_get_drvdata(psy);
+	struct bq25890_state state;
+	int ret;
+
+	bq25890_update_state(bq, psp, &state);
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_STATUS: