summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuanjiang Yu <yuanjiang.yu@unisoc.com>2019-07-31 06:00:28 -0400
committerSebastian Reichel <sebastian.reichel@collabora.com>2019-09-02 17:00:20 -0400
commit7cfd33d997a4c320b6bbce5e9592230dae1e73d2 (patch)
tree49a416b7affa56bcc87eccb0b72dc1bf8165cd37
parent580665279fb6a16eb119ec80a5be1b3ec7a641a0 (diff)
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 <yuanjiang.yu@unisoc.com> Signed-off-by: Baolin Wang <baolin.wang@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-rw-r--r--drivers/power/supply/sc27xx_fuel_gauge.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/drivers/power/supply/sc27xx_fuel_gauge.c b/drivers/power/supply/sc27xx_fuel_gauge.c
index 6071671caaa9..bc8f5bda5762 100644
--- a/drivers/power/supply/sc27xx_fuel_gauge.c
+++ b/drivers/power/supply/sc27xx_fuel_gauge.c
@@ -111,6 +111,7 @@ struct sc27xx_fgu_data {
111static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity); 111static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity);
112static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data, 112static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data,
113 int cap, bool int_mode); 113 int cap, bool int_mode);
114static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap);
114 115
115static const char * const sc27xx_charger_supply_name[] = { 116static const char * const sc27xx_charger_supply_name[] = {
116 "sc2731_charger", 117 "sc2731_charger",
@@ -610,17 +611,25 @@ static int sc27xx_fgu_set_property(struct power_supply *psy,
610 struct sc27xx_fgu_data *data = power_supply_get_drvdata(psy); 611 struct sc27xx_fgu_data *data = power_supply_get_drvdata(psy);
611 int ret; 612 int ret;
612 613
613 if (psp != POWER_SUPPLY_PROP_CAPACITY)
614 return -EINVAL;
615
616 mutex_lock(&data->lock); 614 mutex_lock(&data->lock);
617 615
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;
619 622
620 mutex_unlock(&data->lock); 623 case POWER_SUPPLY_PROP_CALIBRATE:
624 sc27xx_fgu_adjust_cap(data, val->intval);
625 ret = 0;
626 break;
621 627
622 if (ret < 0) 628 default:
623 dev_err(data->dev, "failed to save battery capacity\n"); 629 ret = -EINVAL;
630 }
631
632 mutex_unlock(&data->lock);
624 633
625 return ret; 634 return ret;
626} 635}
@@ -635,7 +644,8 @@ static void sc27xx_fgu_external_power_changed(struct power_supply *psy)
635static int sc27xx_fgu_property_is_writeable(struct power_supply *psy, 644static int sc27xx_fgu_property_is_writeable(struct power_supply *psy,
636 enum power_supply_property psp) 645 enum power_supply_property psp)
637{ 646{
638 return psp == POWER_SUPPLY_PROP_CAPACITY; 647 return psp == POWER_SUPPLY_PROP_CAPACITY ||
648 psp == POWER_SUPPLY_PROP_CALIBRATE;
639} 649}
640 650
641static enum power_supply_property sc27xx_fgu_props[] = { 651static enum power_supply_property sc27xx_fgu_props[] = {
@@ -651,6 +661,7 @@ static enum power_supply_property sc27xx_fgu_props[] = {
651 POWER_SUPPLY_PROP_CURRENT_AVG, 661 POWER_SUPPLY_PROP_CURRENT_AVG,
652 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 662 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
653 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 663 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
664 POWER_SUPPLY_PROP_CALIBRATE,
654}; 665};
655 666
656static const struct power_supply_desc sc27xx_fgu_desc = { 667static const struct power_supply_desc sc27xx_fgu_desc = {