Skip to content

Commit

Permalink
power: supply: axp288_charger: Do not cache input current limit value
Browse files Browse the repository at this point in the history
The hardware may change this underneath us.

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
  • Loading branch information
Hans de Goede authored and Sebastian Reichel committed Jan 8, 2018
1 parent c28185b commit d1ce7e5
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions drivers/power/supply/axp288_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ struct axp288_chrg_info {
struct work_struct work;
} cable;

int inlmt;
int cc;
int cv;
int max_cc;
Expand Down Expand Up @@ -217,6 +216,37 @@ static inline int axp288_charger_set_cv(struct axp288_chrg_info *info, int cv)
return ret;
}

static int axp288_charger_get_vbus_inlmt(struct axp288_chrg_info *info)
{
unsigned int val;
int ret;

ret = regmap_read(info->regmap, AXP20X_CHRG_BAK_CTRL, &val);
if (ret < 0)
return ret;

val >>= CHRG_VBUS_ILIM_BIT_POS;
switch (val) {
case CHRG_VBUS_ILIM_100MA:
return 100000;
case CHRG_VBUS_ILIM_500MA:
return 500000;
case CHRG_VBUS_ILIM_900MA:
return 900000;
case CHRG_VBUS_ILIM_1500MA:
return 1500000;
case CHRG_VBUS_ILIM_2000MA:
return 2000000;
case CHRG_VBUS_ILIM_2500MA:
return 2500000;
case CHRG_VBUS_ILIM_3000MA:
return 3000000;
default:
dev_warn(&info->pdev->dev, "Unknown ilim reg val: %d\n", val);
return 0;
}
}

static inline int axp288_charger_set_vbus_inlmt(struct axp288_chrg_info *info,
int inlmt)
{
Expand All @@ -225,34 +255,25 @@ static inline int axp288_charger_set_vbus_inlmt(struct axp288_chrg_info *info,

if (inlmt <= ILIM_100MA) {
reg_val = CHRG_VBUS_ILIM_100MA;
inlmt = ILIM_100MA;
} else if (inlmt <= ILIM_500MA) {
reg_val = CHRG_VBUS_ILIM_500MA;
inlmt = ILIM_500MA;
} else if (inlmt <= ILIM_900MA) {
reg_val = CHRG_VBUS_ILIM_900MA;
inlmt = ILIM_900MA;
} else if (inlmt <= ILIM_1500MA) {
reg_val = CHRG_VBUS_ILIM_1500MA;
inlmt = ILIM_1500MA;
} else if (inlmt <= ILIM_2000MA) {
reg_val = CHRG_VBUS_ILIM_2000MA;
inlmt = ILIM_2000MA;
} else if (inlmt <= ILIM_2500MA) {
reg_val = CHRG_VBUS_ILIM_2500MA;
inlmt = ILIM_2500MA;
} else {
reg_val = CHRG_VBUS_ILIM_3000MA;
inlmt = ILIM_3000MA;
}

reg_val = reg_val << CHRG_VBUS_ILIM_BIT_POS;

ret = regmap_update_bits(info->regmap, AXP20X_CHRG_BAK_CTRL,
CHRG_VBUS_ILIM_MASK, reg_val);
if (ret >= 0)
info->inlmt = inlmt;
else
if (ret < 0)
dev_err(&info->pdev->dev, "charger BAK control %d\n", ret);

return ret;
Expand Down Expand Up @@ -428,7 +449,10 @@ static int axp288_charger_usb_get_property(struct power_supply *psy,
val->intval = info->max_cv * 1000;
break;
case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT:
val->intval = info->inlmt * 1000;
ret = axp288_charger_get_vbus_inlmt(info);
if (ret < 0)
return ret;
val->intval = ret;
break;
default:
return -EINVAL;
Expand Down

0 comments on commit d1ce7e5

Please sign in to comment.