Skip to content

Commit 3e9544f

Browse files
committed
power: supply: sbs-battery: Improve POWER_SUPPLY_PROP_TECHNOLOGY support
This reads the battery chemistry from the battery chip instead of incorrectly hardcoding the type to be Li-Ion. Reviewed-by: Emil Velikov <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 8ce6ee4 commit 3e9544f

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

drivers/power/supply/sbs-battery.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum {
4343
REG_DESIGN_CAPACITY_CHARGE,
4444
REG_DESIGN_VOLTAGE_MIN,
4545
REG_DESIGN_VOLTAGE_MAX,
46+
REG_CHEMISTRY,
4647
REG_MANUFACTURER,
4748
REG_MODEL_NAME,
4849
};
@@ -133,7 +134,9 @@ static const struct chip_data {
133134
[REG_MANUFACTURER] =
134135
SBS_DATA(POWER_SUPPLY_PROP_MANUFACTURER, 0x20, 0, 65535),
135136
[REG_MODEL_NAME] =
136-
SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535)
137+
SBS_DATA(POWER_SUPPLY_PROP_MODEL_NAME, 0x21, 0, 65535),
138+
[REG_CHEMISTRY] =
139+
SBS_DATA(POWER_SUPPLY_PROP_TECHNOLOGY, 0x22, 0, 65535)
137140
};
138141

139142
static enum power_supply_property sbs_properties[] = {
@@ -185,6 +188,7 @@ struct sbs_info {
185188

186189
static char model_name[I2C_SMBUS_BLOCK_MAX + 1];
187190
static char manufacturer[I2C_SMBUS_BLOCK_MAX + 1];
191+
static char chemistry[I2C_SMBUS_BLOCK_MAX + 1];
188192
static bool force_load;
189193

190194
static int sbs_update_presence(struct sbs_info *chip, bool is_present)
@@ -636,6 +640,38 @@ static int sbs_get_property_index(struct i2c_client *client,
636640
return -EINVAL;
637641
}
638642

643+
static int sbs_get_chemistry(struct i2c_client *client,
644+
union power_supply_propval *val)
645+
{
646+
enum power_supply_property psp = POWER_SUPPLY_PROP_TECHNOLOGY;
647+
int ret;
648+
649+
ret = sbs_get_property_index(client, psp);
650+
if (ret < 0)
651+
return ret;
652+
653+
ret = sbs_get_battery_string_property(client, ret, psp,
654+
chemistry);
655+
if (ret < 0)
656+
return ret;
657+
658+
if (!strncasecmp(chemistry, "LION", 4))
659+
val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
660+
else if (!strncasecmp(chemistry, "LiP", 3))
661+
val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;
662+
else if (!strncasecmp(chemistry, "NiCd", 4))
663+
val->intval = POWER_SUPPLY_TECHNOLOGY_NiCd;
664+
else if (!strncasecmp(chemistry, "NiMH", 4))
665+
val->intval = POWER_SUPPLY_TECHNOLOGY_NiMH;
666+
else
667+
val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN;
668+
669+
if (val->intval == POWER_SUPPLY_TECHNOLOGY_UNKNOWN)
670+
dev_warn(&client->dev, "Unknown chemistry: %s\n", chemistry);
671+
672+
return 0;
673+
}
674+
639675
static int sbs_get_property(struct power_supply *psy,
640676
enum power_supply_property psp,
641677
union power_supply_propval *val)
@@ -673,7 +709,10 @@ static int sbs_get_property(struct power_supply *psy,
673709
break;
674710

675711
case POWER_SUPPLY_PROP_TECHNOLOGY:
676-
val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
712+
ret = sbs_get_chemistry(client, val);
713+
if (ret < 0)
714+
break;
715+
677716
goto done; /* don't trigger power_supply_changed()! */
678717

679718
case POWER_SUPPLY_PROP_ENERGY_NOW:

0 commit comments

Comments
 (0)