Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Yuanjiang Yu and committed by
Sebastian Reichel
7cfd33d9 58066527

+19 -8
+19 -8
drivers/power/supply/sc27xx_fuel_gauge.c
··· 111 111 static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity); 112 112 static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data, 113 113 int cap, bool int_mode); 114 + static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap); 114 115 115 116 static const char * const sc27xx_charger_supply_name[] = { 116 117 "sc2731_charger", ··· 611 610 struct sc27xx_fgu_data *data = power_supply_get_drvdata(psy); 612 611 int ret; 613 612 614 - if (psp != POWER_SUPPLY_PROP_CAPACITY) 615 - return -EINVAL; 616 - 617 613 mutex_lock(&data->lock); 618 614 619 - ret = sc27xx_fgu_save_last_cap(data, val->intval); 615 + switch (psp) { 616 + case POWER_SUPPLY_PROP_CAPACITY: 617 + ret = sc27xx_fgu_save_last_cap(data, val->intval); 618 + if (ret < 0) 619 + dev_err(data->dev, "failed to save battery capacity\n"); 620 + break; 621 + 622 + case POWER_SUPPLY_PROP_CALIBRATE: 623 + sc27xx_fgu_adjust_cap(data, val->intval); 624 + ret = 0; 625 + break; 626 + 627 + default: 628 + ret = -EINVAL; 629 + } 620 630 621 631 mutex_unlock(&data->lock); 622 - 623 - if (ret < 0) 624 - dev_err(data->dev, "failed to save battery capacity\n"); 625 632 626 633 return ret; 627 634 } ··· 644 635 static int sc27xx_fgu_property_is_writeable(struct power_supply *psy, 645 636 enum power_supply_property psp) 646 637 { 647 - return psp == POWER_SUPPLY_PROP_CAPACITY; 638 + return psp == POWER_SUPPLY_PROP_CAPACITY || 639 + psp == POWER_SUPPLY_PROP_CALIBRATE; 648 640 } 649 641 650 642 static enum power_supply_property sc27xx_fgu_props[] = { ··· 661 651 POWER_SUPPLY_PROP_CURRENT_AVG, 662 652 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 663 653 POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, 654 + POWER_SUPPLY_PROP_CALIBRATE, 664 655 }; 665 656 666 657 static const struct power_supply_desc sc27xx_fgu_desc = {