Commit c371d449 authored by Hans de Goede's avatar Hans de Goede Committed by Sebastian Reichel

power: supply: axp288_fuel_gauge: Only read PWR_OP_MODE, FG_LOW_CAP_REG regs once

Accessing registers on the AXP288 is quite expensive, so we should avoid
doing unnecessary accesses.

The FG_LOW_CAP_REG never changes underneath us, so we only need to read
it once. Devices with an AXP288 do not have user-replace (let alone
hot-swappable) batteries and the only bit we care about in the
PWR_OP_MODE register is the CHRG_STAT_BAT_PRESENT bit, so we can get
away with only reading the PWR_OP_MODE register once too.

Note that the FG_LOW_CAP_REG is not marked volatile in the regmap, so we
were effectively already reading it once. This change makes this explicit,
this is done as preparation of a further patch which moves all remaining
register accesses in fuel_gauge_get_property() out of that function.
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 7eef3e66
...@@ -111,6 +111,8 @@ struct axp288_fg_info { ...@@ -111,6 +111,8 @@ struct axp288_fg_info {
struct mutex lock; struct mutex lock;
int status; int status;
int max_volt; int max_volt;
int pwr_op;
int low_cap;
struct dentry *debug_file; struct dentry *debug_file;
}; };
...@@ -336,11 +338,7 @@ static int fuel_gauge_get_property(struct power_supply *ps, ...@@ -336,11 +338,7 @@ static int fuel_gauge_get_property(struct power_supply *ps,
val->intval = PROP_CURR(value); val->intval = PROP_CURR(value);
break; break;
case POWER_SUPPLY_PROP_PRESENT: case POWER_SUPPLY_PROP_PRESENT:
ret = fuel_gauge_reg_readb(info, AXP20X_PWR_OP_MODE); if (info->pwr_op & CHRG_STAT_BAT_PRESENT)
if (ret < 0)
goto fuel_gauge_read_err;
if (ret & CHRG_STAT_BAT_PRESENT)
val->intval = 1; val->intval = 1;
else else
val->intval = 0; val->intval = 0;
...@@ -355,10 +353,7 @@ static int fuel_gauge_get_property(struct power_supply *ps, ...@@ -355,10 +353,7 @@ static int fuel_gauge_get_property(struct power_supply *ps,
val->intval = (ret & FG_REP_CAP_VAL_MASK); val->intval = (ret & FG_REP_CAP_VAL_MASK);
break; break;
case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN: case POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN:
ret = fuel_gauge_reg_readb(info, AXP288_FG_LOW_CAP_REG); val->intval = (info->low_cap & 0x0f);
if (ret < 0)
goto fuel_gauge_read_err;
val->intval = (ret & 0x0f);
break; break;
case POWER_SUPPLY_PROP_TECHNOLOGY: case POWER_SUPPLY_PROP_TECHNOLOGY:
val->intval = POWER_SUPPLY_TECHNOLOGY_LION; val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
...@@ -398,7 +393,7 @@ static int fuel_gauge_set_property(struct power_supply *ps, ...@@ -398,7 +393,7 @@ static int fuel_gauge_set_property(struct power_supply *ps,
const union power_supply_propval *val) const union power_supply_propval *val)
{ {
struct axp288_fg_info *info = power_supply_get_drvdata(ps); struct axp288_fg_info *info = power_supply_get_drvdata(ps);
int ret = 0; int new_low_cap, ret = 0;
mutex_lock(&info->lock); mutex_lock(&info->lock);
switch (prop) { switch (prop) {
...@@ -407,12 +402,12 @@ static int fuel_gauge_set_property(struct power_supply *ps, ...@@ -407,12 +402,12 @@ static int fuel_gauge_set_property(struct power_supply *ps,
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
ret = fuel_gauge_reg_readb(info, AXP288_FG_LOW_CAP_REG); new_low_cap = info->low_cap;
if (ret < 0) new_low_cap &= 0xf0;
break; new_low_cap |= (val->intval & 0xf);
ret &= 0xf0; ret = fuel_gauge_reg_writeb(info, AXP288_FG_LOW_CAP_REG, new_low_cap);
ret |= (val->intval & 0xf); if (ret == 0)
ret = fuel_gauge_reg_writeb(info, AXP288_FG_LOW_CAP_REG, ret); info->low_cap = new_low_cap;
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -695,6 +690,16 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev) ...@@ -695,6 +690,16 @@ static int axp288_fuel_gauge_probe(struct platform_device *pdev)
break; break;
} }
ret = fuel_gauge_reg_readb(info, AXP20X_PWR_OP_MODE);
if (ret < 0)
goto out_free_iio_chan;
info->pwr_op = ret;
ret = fuel_gauge_reg_readb(info, AXP288_FG_LOW_CAP_REG);
if (ret < 0)
goto out_free_iio_chan;
info->low_cap = ret;
psy_cfg.drv_data = info; psy_cfg.drv_data = info;
info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg); info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg);
if (IS_ERR(info->bat)) { if (IS_ERR(info->bat)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment