summaryrefslogtreecommitdiffstats
path: root/drivers/power/supply/ab8500_fg.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2021-12-15 02:01:18 +0100
committerSebastian Reichel <sebastian.reichel@collabora.com>2022-01-03 18:53:10 +0100
commit25fd330370ac40653671f323acc7fb6db27ef6fe (patch)
tree40c0e929cc130988362ff4de29df2447388bbdff /drivers/power/supply/ab8500_fg.c
parentpower: supply: ab8500: Fix the error handling path of ab8500_charger_probe() (diff)
downloadlinux-25fd330370ac40653671f323acc7fb6db27ef6fe.tar.xz
linux-25fd330370ac40653671f323acc7fb6db27ef6fe.zip
power: supply_core: Pass pointer to battery info
The function to retrieve battery info (from the device tree) assumes we have a static info struct that gets populated by calling into power_supply_get_battery_info(). This is awkward since I want to support tables of static battery info by just assigning a pointer to all info based on e.g. a compatible value in the device tree. We also have a mixture of static and dynamically allocated variables here. Bite the bullet and let power_supply_get_battery_info() allocate also the memory used for the very top level struct power_supply_battery_info container. Pass pointers around and lifecycle this with the psy device just like the stuff we allocate inside it. Change all current users over. As part of the change, initializers need to be added to some previously uninitialized fields in struct power_supply_battery_info. Reviewed-By: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power/supply/ab8500_fg.c')
-rw-r--r--drivers/power/supply/ab8500_fg.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c
index eb3e5c4ca44f..b0919a6a6587 100644
--- a/drivers/power/supply/ab8500_fg.c
+++ b/drivers/power/supply/ab8500_fg.c
@@ -852,7 +852,7 @@ static int ab8500_fg_bat_voltage(struct ab8500_fg *di)
*/
static int ab8500_fg_volt_to_capacity(struct ab8500_fg *di, int voltage_uv)
{
- struct power_supply_battery_info *bi = &di->bm->bi;
+ struct power_supply_battery_info *bi = di->bm->bi;
/* Multiply by 10 because the capacity is tracked in per mille */
return power_supply_batinfo_ocv2cap(bi, voltage_uv, di->bat_temp) * 10;
@@ -881,7 +881,7 @@ static int ab8500_fg_uncomp_volt_to_capacity(struct ab8500_fg *di)
*/
static int ab8500_fg_battery_resistance(struct ab8500_fg *di)
{
- struct power_supply_battery_info *bi = &di->bm->bi;
+ struct power_supply_battery_info *bi = di->bm->bi;
int resistance_percent = 0;
int resistance;
@@ -2140,11 +2140,13 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
struct power_supply *ext = dev_get_drvdata(dev);
const char **supplicants = (const char **)ext->supplied_to;
struct ab8500_fg *di;
+ struct power_supply_battery_info *bi;
union power_supply_propval ret;
int j;
psy = (struct power_supply *)data;
di = power_supply_get_drvdata(psy);
+ bi = di->bm->bi;
/*
* For all psy where the name of your driver
@@ -2207,8 +2209,8 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
switch (ext->desc->type) {
case POWER_SUPPLY_TYPE_BATTERY:
if (!di->flags.batt_id_received &&
- (di->bm->bi.technology !=
- POWER_SUPPLY_TECHNOLOGY_UNKNOWN)) {
+ (bi && (bi->technology !=
+ POWER_SUPPLY_TECHNOLOGY_UNKNOWN))) {
const struct ab8500_battery_type *b;
b = di->bm->bat_type;
@@ -2216,13 +2218,13 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data)
di->flags.batt_id_received = true;
di->bat_cap.max_mah_design =
- di->bm->bi.charge_full_design_uah;
+ di->bm->bi->charge_full_design_uah;
di->bat_cap.max_mah =
di->bat_cap.max_mah_design;
di->vbat_nom_uv =
- di->bm->bi.voltage_max_design_uv;
+ di->bm->bi->voltage_max_design_uv;
}
if (ret.intval)
@@ -2992,9 +2994,9 @@ static int ab8500_fg_bind(struct device *dev, struct device *master,
return -ENOMEM;
}
- di->bat_cap.max_mah_design = di->bm->bi.charge_full_design_uah;
+ di->bat_cap.max_mah_design = di->bm->bi->charge_full_design_uah;
di->bat_cap.max_mah = di->bat_cap.max_mah_design;
- di->vbat_nom_uv = di->bm->bi.voltage_max_design_uv;
+ di->vbat_nom_uv = di->bm->bi->voltage_max_design_uv;
/* Start the coulomb counter */
ab8500_fg_coulomb_counter(di, true);