From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Thu, 10 Nov 2022 20:05:58 +0100
Subject: power: supply: axp20x-battery: Add support for
 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN

Report total battery capacity.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/power/supply/axp20x_battery.c | 20 ++++++++--
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
index 2c77a2b1da76..cc79c75a7ba5 100644
--- a/drivers/power/supply/axp20x_battery.c
+++ b/drivers/power/supply/axp20x_battery.c
@@ -85,6 +85,7 @@ struct axp20x_batt_ps {
 	/* Maximum constant charge current */
 	unsigned int max_ccc;
 	const struct axp_data	*data;
+	struct power_supply_battery_info *info;
 };
 
 static int axp20x_battery_get_max_voltage(struct axp20x_batt_ps *axp20x_batt,
@@ -370,6 +371,16 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
 		val->intval *= 1000;
 		break;
 
+	case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
+		val->intval = 0;
+		if (axp20x_batt->info)
+			val->intval = axp20x_batt->info->energy_full_design_uwh;
+		return 0;
+
+	case POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN:
+		val->intval = 0;
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -563,6 +574,8 @@ static enum power_supply_property axp20x_battery_props[] = {
 	POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
 	POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
 	POWER_SUPPLY_PROP_CAPACITY,
+	POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
+	POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN,
 };
 
 static int axp20x_battery_prop_writeable(struct power_supply *psy,
@@ -703,7 +716,6 @@ static int axp20x_power_probe(struct platform_device *pdev)
 	struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
 	struct axp20x_batt_ps *axp20x_batt;
 	struct power_supply_config psy_cfg = {};
-	struct power_supply_battery_info *info;
 	struct device *dev = &pdev->dev;
 	const struct axp_irq_data *irq_data;
 	int irq, ret;
@@ -760,9 +772,9 @@ static int axp20x_power_probe(struct platform_device *pdev)
 
 	axp20x_batt->health = POWER_SUPPLY_HEALTH_GOOD;
 
-	if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
-		int vmin = info->voltage_min_design_uv;
-		int ccc = info->constant_charge_current_max_ua;
+	if (!power_supply_get_battery_info(axp20x_batt->batt, &axp20x_batt->info)) {
+		int vmin = axp20x_batt->info->voltage_min_design_uv;
+		int ccc = axp20x_batt->info->constant_charge_current_max_ua;
 
 		if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt,
 							      vmin))
-- 
Armbian

