[PATCH v1 2/2] power: supply: cpcap-battery: pass static battery cell data from device tree

Svyatoslav Ryhel posted 2 patches 1 week, 3 days ago
[PATCH v1 2/2] power: supply: cpcap-battery: pass static battery cell data from device tree
Posted by Svyatoslav Ryhel 1 week, 3 days ago
Add an option to populate battery cell properties from the device tree if
the driver cannot access the battery's NVMEM.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 drivers/power/supply/cpcap-battery.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 507fdc1c866d..9e686ba20282 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -404,6 +404,30 @@ static int cpcap_battery_match_nvmem(struct device *dev, const void *data)
 		return 0;
 }
 
+static void cpcap_battery_update_battery_data(struct cpcap_battery_ddata *ddata)
+{
+	struct power_supply_battery_info *info;
+
+	if (power_supply_get_battery_info(ddata->psy, &info) < 0)
+		return;
+
+	if (info->technology > 0)
+		ddata->config.info.technology = info->technology;
+
+	if (info->voltage_max_design_uv > 0)
+		ddata->config.info.voltage_max_design = info->voltage_max_design_uv;
+
+	if (info->voltage_min_design_uv > 0)
+		ddata->config.info.voltage_min_design = info->voltage_min_design_uv;
+
+	if (info->charge_full_design_uah > 0)
+		ddata->config.info.charge_full_design = info->charge_full_design_uah;
+
+	if (info->constant_charge_voltage_max_uv > 0)
+		ddata->config.bat.constant_charge_voltage_max_uv =
+			info->constant_charge_voltage_max_uv;
+}
+
 static void cpcap_battery_detect_battery_type(struct cpcap_battery_ddata *ddata)
 {
 	struct nvmem_device *nvmem;
@@ -431,6 +455,9 @@ static void cpcap_battery_detect_battery_type(struct cpcap_battery_ddata *ddata)
 	default:
 		ddata->config = cpcap_battery_unkown_data;
 	}
+
+	if (ddata->psy)
+		cpcap_battery_update_battery_data(ddata);
 }
 
 /**
-- 
2.51.0
Re: [PATCH v1 2/2] power: supply: cpcap-battery: pass static battery cell data from device tree
Posted by Tony Lindgren 3 days, 11 hours ago
* Svyatoslav Ryhel <clamor95@gmail.com> [260130 13:40]:
> Add an option to populate battery cell properties from the device tree if
> the driver cannot access the battery's NVMEM.

Makes sense to me:

Reviewed-by: Tony Lindgren <tony@atomide.com>