power: supply: ab8500: Standardize design capacity
authorLinus Walleij <linus.walleij@linaro.org>
Sat, 20 Nov 2021 15:53:16 +0000 (16:53 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 22 Nov 2021 16:16:25 +0000 (17:16 +0100)
Now that we know that we have only one battery type to
deal with we can proceed to transfer properties to
struct power_supply_battery_info.

The designed capacity for the battery was in a custom field
of the custom battery type in mAh, transfer this to the
standard charge_full_design_uah property in
struct power_supply_battery_info and augment the code
accordingly.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/ab8500-bm.h
drivers/power/supply/ab8500_bmdata.c
drivers/power/supply/ab8500_fg.c

index 99ada7f08ec775d3c55535d81d78507eef808a10..a5cae9288274999d23fd99b602f232107dd70d99 100644 (file)
@@ -375,7 +375,6 @@ struct ab8500_maxim_parameters {
  * @name:                      battery technology
  * @resis_high:                        battery upper resistance limit
  * @resis_low:                 battery lower resistance limit
- * @charge_full_design:                Maximum battery capacity in mAh
  * @nominal_voltage:           Nominal voltage of the battery in mV
  * @termination_vol:           max voltage upto which battery can be charged
  * @termination_curr           battery charging termination current in mA
@@ -404,7 +403,6 @@ struct ab8500_battery_type {
        int name;
        int resis_high;
        int resis_low;
-       int charge_full_design;
        int nominal_voltage;
        int termination_vol;
        int termination_curr;
index 5db13b026d812a89861af073b74fa5d52ec9655a..2d328d3007a94d5f51f04d0003e1a7148e4a7048 100644 (file)
@@ -85,7 +85,6 @@ static struct ab8500_battery_type bat_type_thermistor_unknown = {
        .resis_high = 0,
        .resis_low = 0,
        .battery_resistance = 300,
-       .charge_full_design = 612,
        .nominal_voltage = 3700,
        .termination_vol = 4050,
        .termination_curr = 200,
@@ -189,6 +188,10 @@ int ab8500_bm_of_probe(struct power_supply *psy,
                return ret;
        }
 
+       /* Fill in defaults for any data missing from the device tree */
+       if (bi->charge_full_design_uah < 0)
+               /* The default capacity is 612 mAh for unknown batteries */
+               bi->charge_full_design_uah = 612000;
        if (bi->temp_min == INT_MIN)
                bi->temp_min = AB8500_TEMP_UNDER;
        if (bi->temp_max == INT_MAX)
index 2013db0118ee3f92ac434b67886610a525ed5238..4f8b3a76c56527eace7158b161b3138ea04321f7 100644 (file)
@@ -38,7 +38,6 @@
 
 #include "ab8500-bm.h"
 
-#define MILLI_TO_MICRO                 1000
 #define FG_LSB_IN_MA                   1627
 #define QLSB_NANO_AMP_HOURS_X10                1071
 #define INS_CURR_TIMEOUT               (3 * HZ)
@@ -2243,8 +2242,7 @@ 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 =
-                                               MILLI_TO_MICRO *
-                                               b->charge_full_design;
+                                               di->bm->bi.charge_full_design_uah;
 
                                        di->bat_cap.max_mah =
                                                di->bat_cap.max_mah_design;
@@ -3078,9 +3076,7 @@ static int ab8500_fg_probe(struct platform_device *pdev)
        psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
        psy_cfg.drv_data = di;
 
-       di->bat_cap.max_mah_design = MILLI_TO_MICRO *
-               di->bm->bat_type->charge_full_design;
-
+       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;