diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2022-02-26 02:28:00 +0300 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2022-03-05 00:20:18 +0300 |
commit | c8aee3f41cb84a9ac3b6b5ba2e92cda6cf50d0a0 (patch) | |
tree | 9fa6f2f4855f97d6942e385e690da365ef138bcd /drivers/power/supply/power_supply_core.c | |
parent | bc5d4a24eca3bc0c6ab5dd81026265a20cabcd48 (diff) | |
download | linux-c8aee3f41cb84a9ac3b6b5ba2e92cda6cf50d0a0.tar.xz |
power: supply: Static data for Samsung batteries
If we detect a Samsung SDI battery, we return a static
struct power_supply_battery_info and avoid looking further.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power/supply/power_supply_core.c')
-rw-r--r-- | drivers/power/supply/power_supply_core.c | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index fb0b3870566e..ea02c8dcd748 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -23,6 +23,7 @@ #include <linux/thermal.h> #include <linux/fixp-arith.h> #include "power_supply.h" +#include "samsung-sdi-battery.h" /* exported for the APM Power driver, APM emulation */ struct class *power_supply_class; @@ -578,9 +579,42 @@ int power_supply_get_battery_info(struct power_supply *psy, const __be32 *list; u32 min_max[2]; + if (psy->of_node) { + battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0); + if (!battery_np) + return -ENODEV; + + fwnode = fwnode_handle_get(of_fwnode_handle(battery_np)); + } else { + err = fwnode_property_get_reference_args( + dev_fwnode(psy->dev.parent), + "monitored-battery", NULL, 0, 0, &args); + if (err) + return err; + + fwnode = args.fwnode; + } + + err = fwnode_property_read_string(fwnode, "compatible", &value); + if (err) + goto out_put_node; + + + /* Try static batteries first */ + err = samsung_sdi_battery_get_info(&psy->dev, value, &info); + if (!err) + goto out_ret_pointer; + + if (strcmp("simple-battery", value)) { + err = -ENODEV; + goto out_put_node; + } + info = devm_kmalloc(&psy->dev, sizeof(*info), GFP_KERNEL); - if (!info) - return -ENOMEM; + if (!info) { + err = -ENOMEM; + goto out_put_node; + } info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; info->energy_full_design_uwh = -EINVAL; @@ -617,31 +651,6 @@ int power_supply_get_battery_info(struct power_supply *psy, info->ocv_table_size[index] = -EINVAL; } - if (psy->of_node) { - battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0); - if (!battery_np) - return -ENODEV; - - fwnode = fwnode_handle_get(of_fwnode_handle(battery_np)); - } else { - err = fwnode_property_get_reference_args( - dev_fwnode(psy->dev.parent), - "monitored-battery", NULL, 0, 0, &args); - if (err) - return err; - - fwnode = args.fwnode; - } - - err = fwnode_property_read_string(fwnode, "compatible", &value); - if (err) - goto out_put_node; - - if (strcmp("simple-battery", value)) { - err = -ENODEV; - goto out_put_node; - } - /* The property and field names below must correspond to elements * in enum power_supply_property. For reasoning, see * Documentation/power/power_supply_class.rst. |