[PATCH v2 11/11] power: supply: max17042: report time to full (max17055 & max77759)

André Draszik posted 11 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v2 11/11] power: supply: max17042: report time to full (max17055 & max77759)
Posted by André Draszik 1 month, 1 week ago
Report the remaining time to full as calculated by the firmware for
devices that implement this.
Similar to time to empty, the reported value is only meaningful when
charging, i.e. if it is != U16_MAX.

Signed-off-by: André Draszik <andre.draszik@linaro.org>

---
v2:
- limit to max17055 & max77759, the datasheet for max17047 and max17050
  describes the register as 'reserved'. I was mislead by the comment
  and enum ordering in max17042_battery.h
- report as POWER_SUPPLY_PROP_TIME_TO_FULL_NOW (not _AVG). The max17050
  datasheet is a bit clearer than the max77759 one on that.
---
 drivers/power/supply/max17042_battery.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
index 89909b140cf9..770d806033b9 100644
--- a/drivers/power/supply/max17042_battery.c
+++ b/drivers/power/supply/max17042_battery.c
@@ -89,6 +89,7 @@ static enum power_supply_property max17042_battery_props[] = {
 	POWER_SUPPLY_PROP_HEALTH,
 	POWER_SUPPLY_PROP_SCOPE,
 	POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
+	POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
 	// these two have to be at the end on the list
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 	POWER_SUPPLY_PROP_CURRENT_AVG,
@@ -447,6 +448,21 @@ static int max17042_get_property(struct power_supply *psy,
 		if (data == U16_MAX)
 			return -ENODATA;
 
+		val->intval = data * 5625 / 1000;
+		break;
+	case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
+		if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX17055 &&
+		    chip->chip_type != MAXIM_DEVICE_TYPE_MAX77759)
+			return -EINVAL;
+
+		ret = regmap_read(map, MAX17055_TTF, &data);
+		if (ret < 0)
+			return ret;
+
+		/* when discharging, the value is not meaningful */
+		if (data == U16_MAX)
+			return -ENODATA;
+
 		val->intval = data * 5625 / 1000;
 		break;
 	default:

-- 
2.53.0.473.g4a7958ca14-goog

Re: [PATCH v2 11/11] power: supply: max17042: report time to full (max17055 & max77759)
Posted by Peter Griffin 1 month, 1 week ago
On Fri, 27 Feb 2026 at 07:15, André Draszik <andre.draszik@linaro.org> wrote:
>
> Report the remaining time to full as calculated by the firmware for
> devices that implement this.
> Similar to time to empty, the reported value is only meaningful when
> charging, i.e. if it is != U16_MAX.
>
> Signed-off-by: André Draszik <andre.draszik@linaro.org>
>
> ---

Reviewed-by: Peter Griffin <peter.griffin@linaro.org>

> v2:
> - limit to max17055 & max77759, the datasheet for max17047 and max17050
>   describes the register as 'reserved'. I was mislead by the comment
>   and enum ordering in max17042_battery.h
> - report as POWER_SUPPLY_PROP_TIME_TO_FULL_NOW (not _AVG). The max17050
>   datasheet is a bit clearer than the max77759 one on that.
> ---
>  drivers/power/supply/max17042_battery.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c
> index 89909b140cf9..770d806033b9 100644
> --- a/drivers/power/supply/max17042_battery.c
> +++ b/drivers/power/supply/max17042_battery.c
> @@ -89,6 +89,7 @@ static enum power_supply_property max17042_battery_props[] = {
>         POWER_SUPPLY_PROP_HEALTH,
>         POWER_SUPPLY_PROP_SCOPE,
>         POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
> +       POWER_SUPPLY_PROP_TIME_TO_FULL_NOW,
>         // these two have to be at the end on the list
>         POWER_SUPPLY_PROP_CURRENT_NOW,
>         POWER_SUPPLY_PROP_CURRENT_AVG,
> @@ -447,6 +448,21 @@ static int max17042_get_property(struct power_supply *psy,
>                 if (data == U16_MAX)
>                         return -ENODATA;
>
> +               val->intval = data * 5625 / 1000;
> +               break;
> +       case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
> +               if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX17055 &&
> +                   chip->chip_type != MAXIM_DEVICE_TYPE_MAX77759)
> +                       return -EINVAL;
> +
> +               ret = regmap_read(map, MAX17055_TTF, &data);
> +               if (ret < 0)
> +                       return ret;
> +
> +               /* when discharging, the value is not meaningful */
> +               if (data == U16_MAX)
> +                       return -ENODATA;
> +
>                 val->intval = data * 5625 / 1000;
>                 break;
>         default:
>
> --
> 2.53.0.473.g4a7958ca14-goog
>