diff mbox series

[v2,1/4] power: supply: mm8013: fix "not charging" detection

Message ID 20240303-power_supply-charge_behaviour_prop-v2-1-8ebb0a7c2409@weissschuh.net (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series power: supply: core: align charge_behaviour format with docs | expand

Commit Message

Thomas Weißschuh March 3, 2024, 3:31 p.m. UTC
The charge_behaviours property is meant as a control-knob that can be
changed by the user.

Page 23 of [0] which documents the flag CHG_INH as follows:

  CHG_INH : Charge Inhibit      When the current is more than or equal to charge
                                threshold current,
                                charge inhibit temperature (upper/lower limit) :1
                                charge permission temperature or the current is
                                less than charge threshold current :0

So this is pure read-only information which is better represented as
POWER_SUPPLY_STATUS_NOT_CHARGING.

[0] https://product.minebeamitsumi.com/en/product/category/ics/battery/fuel_gauge/parts/download/__icsFiles/afieldfile/2023/07/12/1_download_01_12.pdf

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 drivers/power/supply/mm8013.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

Comments

Sebastian Reichel March 6, 2024, 12:25 a.m. UTC | #1
Hi,

On Sun, Mar 03, 2024 at 04:31:13PM +0100, Thomas Weißschuh wrote:
> The charge_behaviours property is meant as a control-knob that can be
> changed by the user.
> 
> Page 23 of [0] which documents the flag CHG_INH as follows:
> 
>   CHG_INH : Charge Inhibit      When the current is more than or equal to charge
>                                 threshold current,
>                                 charge inhibit temperature (upper/lower limit) :1
>                                 charge permission temperature or the current is
>                                 less than charge threshold current :0
> 
> So this is pure read-only information which is better represented as
> POWER_SUPPLY_STATUS_NOT_CHARGING.
> 
> [0] https://product.minebeamitsumi.com/en/product/category/ics/battery/fuel_gauge/parts/download/__icsFiles/afieldfile/2023/07/12/1_download_01_12.pdf
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---

I queued this with 

Fixes: e39257cde7e8 ("power: supply: mm8013: Add more properties")

-- Sebastian

>  drivers/power/supply/mm8013.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/power/supply/mm8013.c b/drivers/power/supply/mm8013.c
> index caa272b03564..20c1651ca38e 100644
> --- a/drivers/power/supply/mm8013.c
> +++ b/drivers/power/supply/mm8013.c
> @@ -71,7 +71,6 @@ static int mm8013_checkdevice(struct mm8013_chip *chip)
>  
>  static enum power_supply_property mm8013_battery_props[] = {
>  	POWER_SUPPLY_PROP_CAPACITY,
> -	POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
>  	POWER_SUPPLY_PROP_CHARGE_FULL,
>  	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
>  	POWER_SUPPLY_PROP_CHARGE_NOW,
> @@ -103,16 +102,6 @@ static int mm8013_get_property(struct power_supply *psy,
>  
>  		val->intval = regval;
>  		break;
> -	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
> -		ret = regmap_read(chip->regmap, REG_FLAGS, &regval);
> -		if (ret < 0)
> -			return ret;
> -
> -		if (regval & MM8013_FLAG_CHG_INH)
> -			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE;
> -		else
> -			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
> -		break;
>  	case POWER_SUPPLY_PROP_CHARGE_FULL:
>  		ret = regmap_read(chip->regmap, REG_FULL_CHARGE_CAPACITY, &regval);
>  		if (ret < 0)
> @@ -187,6 +176,8 @@ static int mm8013_get_property(struct power_supply *psy,
>  
>  		if (regval & MM8013_FLAG_DSG)
>  			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
> +		else if (regval & MM8013_FLAG_CHG_INH)
> +			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
>  		else if (regval & MM8013_FLAG_CHG)
>  			val->intval = POWER_SUPPLY_STATUS_CHARGING;
>  		else if (regval & MM8013_FLAG_FC)
> 
> -- 
> 2.44.0
>
Hans de Goede March 27, 2024, 10:36 a.m. UTC | #2
Hi,

On 3/3/24 4:31 PM, Thomas Weißschuh wrote:
> The charge_behaviours property is meant as a control-knob that can be
> changed by the user.
> 
> Page 23 of [0] which documents the flag CHG_INH as follows:
> 
>   CHG_INH : Charge Inhibit      When the current is more than or equal to charge
>                                 threshold current,
>                                 charge inhibit temperature (upper/lower limit) :1
>                                 charge permission temperature or the current is
>                                 less than charge threshold current :0
> 
> So this is pure read-only information which is better represented as
> POWER_SUPPLY_STATUS_NOT_CHARGING.
> 
> [0] https://product.minebeamitsumi.com/en/product/category/ics/battery/fuel_gauge/parts/download/__icsFiles/afieldfile/2023/07/12/1_download_01_12.pdf
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Thanks, patch looks good to me:

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

Regards,

Hans



> ---
>  drivers/power/supply/mm8013.c | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/power/supply/mm8013.c b/drivers/power/supply/mm8013.c
> index caa272b03564..20c1651ca38e 100644
> --- a/drivers/power/supply/mm8013.c
> +++ b/drivers/power/supply/mm8013.c
> @@ -71,7 +71,6 @@ static int mm8013_checkdevice(struct mm8013_chip *chip)
>  
>  static enum power_supply_property mm8013_battery_props[] = {
>  	POWER_SUPPLY_PROP_CAPACITY,
> -	POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
>  	POWER_SUPPLY_PROP_CHARGE_FULL,
>  	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
>  	POWER_SUPPLY_PROP_CHARGE_NOW,
> @@ -103,16 +102,6 @@ static int mm8013_get_property(struct power_supply *psy,
>  
>  		val->intval = regval;
>  		break;
> -	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
> -		ret = regmap_read(chip->regmap, REG_FLAGS, &regval);
> -		if (ret < 0)
> -			return ret;
> -
> -		if (regval & MM8013_FLAG_CHG_INH)
> -			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE;
> -		else
> -			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
> -		break;
>  	case POWER_SUPPLY_PROP_CHARGE_FULL:
>  		ret = regmap_read(chip->regmap, REG_FULL_CHARGE_CAPACITY, &regval);
>  		if (ret < 0)
> @@ -187,6 +176,8 @@ static int mm8013_get_property(struct power_supply *psy,
>  
>  		if (regval & MM8013_FLAG_DSG)
>  			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
> +		else if (regval & MM8013_FLAG_CHG_INH)
> +			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
>  		else if (regval & MM8013_FLAG_CHG)
>  			val->intval = POWER_SUPPLY_STATUS_CHARGING;
>  		else if (regval & MM8013_FLAG_FC)
>
Konrad Dybcio March 27, 2024, 8:48 p.m. UTC | #3
On 3.03.2024 4:31 PM, Thomas Weißschuh wrote:
> The charge_behaviours property is meant as a control-knob that can be
> changed by the user.
> 
> Page 23 of [0] which documents the flag CHG_INH as follows:
> 
>   CHG_INH : Charge Inhibit      When the current is more than or equal to charge
>                                 threshold current,
>                                 charge inhibit temperature (upper/lower limit) :1
>                                 charge permission temperature or the current is
>                                 less than charge threshold current :0
> 
> So this is pure read-only information which is better represented as
> POWER_SUPPLY_STATUS_NOT_CHARGING.
> 
> [0] https://product.minebeamitsumi.com/en/product/category/ics/battery/fuel_gauge/parts/download/__icsFiles/afieldfile/2023/07/12/1_download_01_12.pdf
> 
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---

The patch is now queued, so I won't leave any additional tags,
but thanks for taking care of this, Thomas!

Konrad
diff mbox series

Patch

diff --git a/drivers/power/supply/mm8013.c b/drivers/power/supply/mm8013.c
index caa272b03564..20c1651ca38e 100644
--- a/drivers/power/supply/mm8013.c
+++ b/drivers/power/supply/mm8013.c
@@ -71,7 +71,6 @@  static int mm8013_checkdevice(struct mm8013_chip *chip)
 
 static enum power_supply_property mm8013_battery_props[] = {
 	POWER_SUPPLY_PROP_CAPACITY,
-	POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR,
 	POWER_SUPPLY_PROP_CHARGE_FULL,
 	POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
 	POWER_SUPPLY_PROP_CHARGE_NOW,
@@ -103,16 +102,6 @@  static int mm8013_get_property(struct power_supply *psy,
 
 		val->intval = regval;
 		break;
-	case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
-		ret = regmap_read(chip->regmap, REG_FLAGS, &regval);
-		if (ret < 0)
-			return ret;
-
-		if (regval & MM8013_FLAG_CHG_INH)
-			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE;
-		else
-			val->intval = POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO;
-		break;
 	case POWER_SUPPLY_PROP_CHARGE_FULL:
 		ret = regmap_read(chip->regmap, REG_FULL_CHARGE_CAPACITY, &regval);
 		if (ret < 0)
@@ -187,6 +176,8 @@  static int mm8013_get_property(struct power_supply *psy,
 
 		if (regval & MM8013_FLAG_DSG)
 			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
+		else if (regval & MM8013_FLAG_CHG_INH)
+			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
 		else if (regval & MM8013_FLAG_CHG)
 			val->intval = POWER_SUPPLY_STATUS_CHARGING;
 		else if (regval & MM8013_FLAG_FC)