Skip to content

Commit 7f5cda0

Browse files
author
Al Stone
committed
power: supply: Static data for Samsung batteries
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2071846 Tested: This is one of a series of patch sets to enable Arm SystemReady IR support in the kernel for NXP i.MX8 platforms. This set updates the power subsystem. This set has been tested via simple boot tests and the CI loop. commit c8aee3f Author: Linus Walleij <linus.walleij@linaro.org> Date: Sat Feb 26 00:28:00 2022 +0100 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> (cherry picked from commit c8aee3f) Signed-off-by: Al Stone <ahs3@redhat.com>
1 parent d591b50 commit 7f5cda0

File tree

5 files changed

+974
-27
lines changed

5 files changed

+974
-27
lines changed

drivers/power/supply/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ config BATTERY_OLPC
181181
help
182182
Say Y to enable support for the battery on the OLPC laptop.
183183

184+
config BATTERY_SAMSUNG_SDI
185+
bool "Samsung SDI batteries"
186+
help
187+
Say Y to enable support for Samsung SDI battery data.
188+
These batteries are used in Samsung mobile phones.
189+
184190
config BATTERY_TOSA
185191
tristate "Sharp SL-6000 (tosa) battery"
186192
depends on MACH_TOSA && MFD_TC6393XB && TOUCHSCREEN_WM97XX

drivers/power/supply/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ obj-$(CONFIG_BATTERY_GOLDFISH) += goldfish_battery.o
3434
obj-$(CONFIG_BATTERY_LEGO_EV3) += lego_ev3_battery.o
3535
obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o
3636
obj-$(CONFIG_BATTERY_OLPC) += olpc_battery.o
37+
obj-$(CONFIG_BATTERY_SAMSUNG_SDI) += samsung-sdi-battery.o
3738
obj-$(CONFIG_BATTERY_TOSA) += tosa_battery.o
3839
obj-$(CONFIG_BATTERY_COLLIE) += collie_battery.o
3940
obj-$(CONFIG_BATTERY_INGENIC) += ingenic-battery.o

drivers/power/supply/power_supply_core.c

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/thermal.h>
2424
#include <linux/fixp-arith.h>
2525
#include "power_supply.h"
26+
#include "samsung-sdi-battery.h"
2627

2728
/* exported for the APM Power driver, APM emulation */
2829
struct class *power_supply_class;
@@ -578,9 +579,42 @@ int power_supply_get_battery_info(struct power_supply *psy,
578579
const __be32 *list;
579580
u32 min_max[2];
580581

582+
if (psy->of_node) {
583+
battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
584+
if (!battery_np)
585+
return -ENODEV;
586+
587+
fwnode = fwnode_handle_get(of_fwnode_handle(battery_np));
588+
} else {
589+
err = fwnode_property_get_reference_args(
590+
dev_fwnode(psy->dev.parent),
591+
"monitored-battery", NULL, 0, 0, &args);
592+
if (err)
593+
return err;
594+
595+
fwnode = args.fwnode;
596+
}
597+
598+
err = fwnode_property_read_string(fwnode, "compatible", &value);
599+
if (err)
600+
goto out_put_node;
601+
602+
603+
/* Try static batteries first */
604+
err = samsung_sdi_battery_get_info(&psy->dev, value, &info);
605+
if (!err)
606+
goto out_ret_pointer;
607+
608+
if (strcmp("simple-battery", value)) {
609+
err = -ENODEV;
610+
goto out_put_node;
611+
}
612+
581613
info = devm_kmalloc(&psy->dev, sizeof(*info), GFP_KERNEL);
582-
if (!info)
583-
return -ENOMEM;
614+
if (!info) {
615+
err = -ENOMEM;
616+
goto out_put_node;
617+
}
584618

585619
info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
586620
info->energy_full_design_uwh = -EINVAL;
@@ -617,31 +651,6 @@ int power_supply_get_battery_info(struct power_supply *psy,
617651
info->ocv_table_size[index] = -EINVAL;
618652
}
619653

620-
if (psy->of_node) {
621-
battery_np = of_parse_phandle(psy->of_node, "monitored-battery", 0);
622-
if (!battery_np)
623-
return -ENODEV;
624-
625-
fwnode = fwnode_handle_get(of_fwnode_handle(battery_np));
626-
} else {
627-
err = fwnode_property_get_reference_args(
628-
dev_fwnode(psy->dev.parent),
629-
"monitored-battery", NULL, 0, 0, &args);
630-
if (err)
631-
return err;
632-
633-
fwnode = args.fwnode;
634-
}
635-
636-
err = fwnode_property_read_string(fwnode, "compatible", &value);
637-
if (err)
638-
goto out_put_node;
639-
640-
if (strcmp("simple-battery", value)) {
641-
err = -ENODEV;
642-
goto out_put_node;
643-
}
644-
645654
/* The property and field names below must correspond to elements
646655
* in enum power_supply_property. For reasoning, see
647656
* Documentation/power/power_supply_class.rst.

0 commit comments

Comments
 (0)