summaryrefslogtreecommitdiff
path: root/drivers/power/supply/power_supply_core.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2022-02-26 00:27:57 +0100
committerSebastian Reichel <sebastian.reichel@collabora.com>2022-02-28 11:34:31 +0100
commit1f918e0fe43ec41d906e2cf96b80b15451fed7ba (patch)
tree0e2de0ee5e69c0d5c5987046c6d22d17d67e089c /drivers/power/supply/power_supply_core.c
parent0e8b903b522b5a3cb473035cea085d396dd7150a (diff)
power: supply: ab8500: Standardize BTI resistance
The Battery Type Indicator (BTI) resistor is a resistor mounted between a special terminal on the battery and ground. By sending a fixed current (such as 7mA) through this resistor and measuring the voltage over it, the resistance can be determined, and this verifies the battery type. Typical side view of the battery: o o o GND BTI +3.8V Typical example of the electrical layout: +3.8 V BTI | | | + | _______ [ ] 7kOhm ___ | | | | | GND GND By verifying this resistance before attempting to charge the battery we add an additional level of security. In some systems this is used for plug-and-play of batteries with different capacity. In other cases, this is merely used to verify that the right type of battery is connected, if several batteries have the same physical shape and can be plugged into the same slot. Sometimes this is just a surplus security mechanism. Nokia and Samsung among many other vendors are known to use these BTI resistors. Add the BTI properties to struct power_supply_battery_info and switch the AB8500 charger code over to using it. 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.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index e3d6d3ff492a..3d5047d3fe99 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -607,7 +607,9 @@ int power_supply_get_battery_info(struct power_supply *psy,
info->temp_min = INT_MIN;
info->temp_max = INT_MAX;
info->factory_internal_resistance_uohm = -EINVAL;
- info->resist_table = NULL;
+ info->resist_table = NULL;
+ info->bti_resistance_ohm = -EINVAL;
+ info->bti_resistance_tolerance = -EINVAL;
for (index = 0; index < POWER_SUPPLY_OCV_TEMP_MAX; index++) {
info->ocv_table[index] = NULL;
@@ -938,6 +940,28 @@ int power_supply_batinfo_ocv2cap(struct power_supply_battery_info *info,
}
EXPORT_SYMBOL_GPL(power_supply_batinfo_ocv2cap);
+bool power_supply_battery_bti_in_range(struct power_supply_battery_info *info,
+ int resistance)
+{
+ int low, high;
+
+ /* Nothing like this can be checked */
+ if (info->bti_resistance_ohm <= 0)
+ return false;
+
+ /* This will be extremely strict and unlikely to work */
+ if (info->bti_resistance_tolerance <= 0)
+ return (info->bti_resistance_ohm == resistance);
+
+ low = info->bti_resistance_ohm -
+ (info->bti_resistance_ohm * info->bti_resistance_tolerance) / 100;
+ high = info->bti_resistance_ohm +
+ (info->bti_resistance_ohm * info->bti_resistance_tolerance) / 100;
+
+ return ((resistance >= low) && (resistance <= high));
+}
+EXPORT_SYMBOL_GPL(power_supply_battery_bti_in_range);
+
int power_supply_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)