Skip to content

Commit

Permalink
power: supply: Static data for Samsung batteries
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Walleij authored and Sebastian Reichel committed Mar 4, 2022
1 parent bc5d4a2 commit c8aee3f
Show file tree
Hide file tree
Showing 5 changed files with 974 additions and 27 deletions.
6 changes: 6 additions & 0 deletions drivers/power/supply/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ config BATTERY_OLPC
help
Say Y to enable support for the battery on the OLPC laptop.

config BATTERY_SAMSUNG_SDI
bool "Samsung SDI batteries"
help
Say Y to enable support for Samsung SDI battery data.
These batteries are used in Samsung mobile phones.

config BATTERY_TOSA
tristate "Sharp SL-6000 (tosa) battery"
depends on MACH_TOSA && MFD_TC6393XB && TOUCHSCREEN_WM97XX
Expand Down
1 change: 1 addition & 0 deletions drivers/power/supply/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ obj-$(CONFIG_BATTERY_GOLDFISH) += goldfish_battery.o
obj-$(CONFIG_BATTERY_LEGO_EV3) += lego_ev3_battery.o
obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o
obj-$(CONFIG_BATTERY_SAMSUNG_SDI) += samsung-sdi-battery.o
obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o
obj-$(CONFIG_BATTERY_COLLIE) += collie_battery.o
obj-$(CONFIG_BATTERY_INGENIC) += ingenic-battery.o
Expand Down
63 changes: 36 additions & 27 deletions drivers/power/supply/power_supply_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit c8aee3f

Please sign in to comment.