power: supply: ab8500: Use core battery parser
authorLinus Walleij <linus.walleij@linaro.org>
Sat, 20 Nov 2021 15:53:11 +0000 (16:53 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Mon, 22 Nov 2021 16:16:25 +0000 (17:16 +0100)
This deploys the core battery DT parser to read the basic properties
of the battery. We only use very little of it as we start out, but
we will improve as we go along.

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_charger.c

index d11405b..33c7e15 100644 (file)
@@ -570,8 +570,7 @@ int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
 int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
 int ab8500_fg_inst_curr_started(struct ab8500_fg *di);
 int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
-int ab8500_bm_of_probe(struct device *dev,
-                      struct device_node *np,
+int ab8500_bm_of_probe(struct power_supply *psy,
                       struct ab8500_bm_data *bm);
 
 extern struct platform_driver ab8500_fg_driver;
index bfc1245..a515dfa 100644 (file)
@@ -488,29 +488,22 @@ struct ab8500_bm_data ab8500_bm_data = {
         .n_chg_in_curr          = ARRAY_SIZE(ab8500_charge_input_curr_map),
 };
 
-int ab8500_bm_of_probe(struct device *dev,
-                      struct device_node *np,
+int ab8500_bm_of_probe(struct power_supply *psy,
                       struct ab8500_bm_data *bm)
 {
        const struct batres_vs_temp *tmp_batres_tbl;
-       struct device_node *battery_node;
-       const char *btech;
+       struct power_supply_battery_info info;
+       struct device *dev = &psy->dev;
+       int ret;
        int i;
 
-       battery_node = of_parse_phandle(np, "monitored-battery", 0);
-       if (!battery_node) {
-               dev_err(dev, "battery node or reference missing\n");
-               return -EINVAL;
+       ret = power_supply_get_battery_info(psy, &info);
+       if (ret) {
+               dev_err(dev, "cannot retrieve battery info\n");
+               return ret;
        }
 
-       btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
-       if (!btech) {
-               dev_warn(dev, "missing property battery-name/type\n");
-               of_node_put(battery_node);
-               return -EINVAL;
-       }
-
-       if (strncmp(btech, "LION", 4) == 0) {
+       if (info.technology == POWER_SUPPLY_TECHNOLOGY_LION) {
                bm->no_maintenance  = true;
                bm->chg_unknown_bat = true;
                bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
@@ -520,8 +513,8 @@ int ab8500_bm_of_probe(struct device *dev,
                bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl     = 4200;
        }
 
-       if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
-               if (strncmp(btech, "LION", 4) == 0)
+       if (of_property_read_bool(psy->of_node, "thermistor-on-batctrl")) {
+               if (info.technology == POWER_SUPPLY_TECHNOLOGY_LION)
                        tmp_batres_tbl = temp_to_batres_tbl_9100;
                else
                        tmp_batres_tbl = temp_to_batres_tbl_thermistor;
@@ -536,7 +529,7 @@ int ab8500_bm_of_probe(struct device *dev,
        for (i = 0; i < bm->n_btypes; ++i)
                bm->bat_type[i].batres_tbl = tmp_batres_tbl;
 
-       of_node_put(battery_node);
+       power_supply_put_battery_info(psy, &info);
 
        return 0;
 }
index 15eadaf..59ca9c0 100644 (file)
@@ -3413,11 +3413,6 @@ static int ab8500_charger_probe(struct platform_device *pdev)
 
        di->bm = &ab8500_bm_data;
 
-       ret = ab8500_bm_of_probe(dev, np, di->bm);
-       if (ret) {
-               dev_err(dev, "failed to get battery information\n");
-               return ret;
-       }
        di->autopower_cfg = of_property_read_bool(np, "autopower_cfg");
 
        /* get parent data */
@@ -3490,9 +3485,11 @@ static int ab8500_charger_probe(struct platform_device *pdev)
        di->invalid_charger_detect_state = 0;
 
        /* AC and USB supply config */
+       ac_psy_cfg.of_node = np;
        ac_psy_cfg.supplied_to = supply_interface;
        ac_psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
        ac_psy_cfg.drv_data = &di->ac_chg;
+       usb_psy_cfg.of_node = np;
        usb_psy_cfg.supplied_to = supply_interface;
        usb_psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface);
        usb_psy_cfg.drv_data = &di->usb_chg;
@@ -3610,6 +3607,15 @@ static int ab8500_charger_probe(struct platform_device *pdev)
                return PTR_ERR(di->usb_chg.psy);
        }
 
+       /*
+        * Check what battery we have, since we always have the USB
+        * psy, use that as a handle.
+        */
+       ret = ab8500_bm_of_probe(di->usb_chg.psy, di->bm);
+       if (ret)
+               return dev_err_probe(dev, ret,
+                                    "failed to get battery information\n");
+
        /* Identify the connected charger types during startup */
        charger_status = ab8500_charger_detect_chargers(di, true);
        if (charger_status & AC_PW_CONN) {