diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2021-11-20 16:53:18 +0100 |
---|---|---|
committer | Sebastian Reichel <sebastian.reichel@collabora.com> | 2021-11-22 17:16:25 +0100 |
commit | 2a5f41830aadc2d7f4145eae49381133da5df2a3 (patch) | |
tree | 292edd94a9347125058f1d634c92434780dc84a6 /drivers/power/supply/ab8500_fg.c | |
parent | power: supply: ab8500: Standardize technology (diff) | |
download | linux-2a5f41830aadc2d7f4145eae49381133da5df2a3.tar.xz linux-2a5f41830aadc2d7f4145eae49381133da5df2a3.zip |
power: supply: ab8500: Standardize voltages
The nominal voltage in this charge driver corresponds to
both the voltage_min_design_uv and voltage_max_design_uv
of struct power_supply_battery_info so assign both if this
is undefined.
The overcharge max voltage (when the charger should cut off)
is migrated at the same time so we move both voltages to
struct power_supply_battery_info.
Adjust the code to deal directly with the microvolt values
instead of converting them to millivolts.
Add *_uv suffixes for clarity and to make sure we have
changed all code sites using this member.
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.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index c6237c4f4721..ab6141faa798 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -157,7 +157,7 @@ struct inst_curr_result_list { * @node: a list of AB8500 FGs, hence prepared for reentrance * @irq holds the CCEOC interrupt number * @vbat: Battery voltage in mV - * @vbat_nom: Nominal battery voltage in mV + * @vbat_nom_uv: Nominal battery voltage in uV * @inst_curr: Instantenous battery current in mA * @avg_curr: Average battery current in mA * @bat_temp battery temperature @@ -199,7 +199,7 @@ struct ab8500_fg { struct list_head node; int irq; int vbat; - int vbat_nom; + int vbat_nom_uv; int inst_curr; int avg_curr; int bat_temp; @@ -1013,11 +1013,16 @@ static int ab8500_fg_convert_mah_to_uwh(struct ab8500_fg *di, int cap_mah) u64 div_res; u32 div_rem; - div_res = ((u64) cap_mah) * ((u64) di->vbat_nom); - div_rem = do_div(div_res, 1000); + /* + * Capacity is in milli ampere hours (10^-3)Ah + * Nominal voltage is in microvolts (10^-6)V + * divide by 1000000 after multiplication to get to mWh + */ + div_res = ((u64) cap_mah) * ((u64) di->vbat_nom_uv); + div_rem = do_div(div_res, 1000000); /* Make sure to round upwards if necessary */ - if (div_rem >= 1000 / 2) + if (div_rem >= 1000000 / 2) div_res++; return (int) div_res; @@ -2247,7 +2252,8 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data) di->bat_cap.max_mah = di->bat_cap.max_mah_design; - di->vbat_nom = b->nominal_voltage; + di->vbat_nom_uv = + di->bm->bi.voltage_max_design_uv; } if (ret.intval) @@ -3078,8 +3084,7 @@ static int ab8500_fg_probe(struct platform_device *pdev) 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 = di->bm->bat_type->nominal_voltage; + di->vbat_nom_uv = di->bm->bi.voltage_max_design_uv; di->init_capacity = true; |