Skip to content

Commit 7cfd33d

Browse files
Yuanjiang Yusre
authored andcommitted
power: supply: sc27xx: Add POWER_SUPPLY_PROP_CALIBRATE attribute
Add the 'POWER_SUPPLY_PROP_CALIBRATE' attribute to allow chareger manager to calibrate the battery capacity. Signed-off-by: Yuanjiang Yu <[email protected]> Signed-off-by: Baolin Wang <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 5806652 commit 7cfd33d

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

drivers/power/supply/sc27xx_fuel_gauge.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ struct sc27xx_fgu_data {
111111
static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity);
112112
static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data,
113113
int cap, bool int_mode);
114+
static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap);
114115

115116
static const char * const sc27xx_charger_supply_name[] = {
116117
"sc2731_charger",
@@ -610,17 +611,25 @@ static int sc27xx_fgu_set_property(struct power_supply *psy,
610611
struct sc27xx_fgu_data *data = power_supply_get_drvdata(psy);
611612
int ret;
612613

613-
if (psp != POWER_SUPPLY_PROP_CAPACITY)
614-
return -EINVAL;
615-
616614
mutex_lock(&data->lock);
617615

618-
ret = sc27xx_fgu_save_last_cap(data, val->intval);
616+
switch (psp) {
617+
case POWER_SUPPLY_PROP_CAPACITY:
618+
ret = sc27xx_fgu_save_last_cap(data, val->intval);
619+
if (ret < 0)
620+
dev_err(data->dev, "failed to save battery capacity\n");
621+
break;
619622

620-
mutex_unlock(&data->lock);
623+
case POWER_SUPPLY_PROP_CALIBRATE:
624+
sc27xx_fgu_adjust_cap(data, val->intval);
625+
ret = 0;
626+
break;
621627

622-
if (ret < 0)
623-
dev_err(data->dev, "failed to save battery capacity\n");
628+
default:
629+
ret = -EINVAL;
630+
}
631+
632+
mutex_unlock(&data->lock);
624633

625634
return ret;
626635
}
@@ -635,7 +644,8 @@ static void sc27xx_fgu_external_power_changed(struct power_supply *psy)
635644
static int sc27xx_fgu_property_is_writeable(struct power_supply *psy,
636645
enum power_supply_property psp)
637646
{
638-
return psp == POWER_SUPPLY_PROP_CAPACITY;
647+
return psp == POWER_SUPPLY_PROP_CAPACITY ||
648+
psp == POWER_SUPPLY_PROP_CALIBRATE;
639649
}
640650

641651
static enum power_supply_property sc27xx_fgu_props[] = {
@@ -651,6 +661,7 @@ static enum power_supply_property sc27xx_fgu_props[] = {
651661
POWER_SUPPLY_PROP_CURRENT_AVG,
652662
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
653663
POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
664+
POWER_SUPPLY_PROP_CALIBRATE,
654665
};
655666

656667
static const struct power_supply_desc sc27xx_fgu_desc = {

0 commit comments

Comments
 (0)