]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
power: supply: cpcap-battery: pass static battery cell data from device tree
authorSvyatoslav Ryhel <clamor95@gmail.com>
Fri, 30 Jan 2026 13:40:21 +0000 (15:40 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 3 Mar 2026 22:58:08 +0000 (23:58 +0100)
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>
Reviewed-by: Tony Lindgren <tony@atomide.com>
Link: https://patch.msgid.link/20260130134021.353688-3-clamor95@gmail.com
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/cpcap-battery.c

index f58269c755095a313204ad63b8558c9316614015..7b7bdce3162fcb88f46bc3541afcbbd6ff1e430e 100644 (file)
@@ -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_unknown_data;
        }
+
+       if (ddata->psy)
+               cpcap_battery_update_battery_data(ddata);
 }
 
 /**