Commit af7e8d07 authored by Quentin Schulz's avatar Quentin Schulz Committed by Sebastian Reichel

power: supply: axp20x_usb_power: add function to get max current

To prepare for a new PMIC, factor out the code responsible of returning
the maximum current to axp20x_get_current_max.
Signed-off-by: default avatarQuentin Schulz <quentin.schulz@bootlin.com>
Signed-off-by: default avatarChen-Yu Tsai <wens@csie.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 97ec136e
...@@ -102,6 +102,35 @@ static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) ...@@ -102,6 +102,35 @@ static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power)
return false; return false;
} }
static int axp20x_get_current_max(struct axp20x_usb_power *power, int *val)
{
unsigned int v;
int ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v);
if (ret)
return ret;
switch (v & AXP20X_VBUS_CLIMIT_MASK) {
case AXP20X_VBUS_CLIMIT_100mA:
if (power->axp20x_id == AXP221_ID)
*val = -1; /* No 100mA limit */
else
*val = 100000;
break;
case AXP20X_VBUS_CLIMIT_500mA:
*val = 500000;
break;
case AXP20X_VBUS_CLIMIT_900mA:
*val = 900000;
break;
case AXP20X_VBUS_CLIMIT_NONE:
*val = -1;
break;
}
return 0;
}
static int axp20x_usb_power_get_property(struct power_supply *psy, static int axp20x_usb_power_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val) enum power_supply_property psp, union power_supply_propval *val)
{ {
...@@ -140,28 +169,7 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, ...@@ -140,28 +169,7 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
val->intval = ret * 1700; /* 1 step = 1.7 mV */ val->intval = ret * 1700; /* 1 step = 1.7 mV */
return 0; return 0;
case POWER_SUPPLY_PROP_CURRENT_MAX: case POWER_SUPPLY_PROP_CURRENT_MAX:
ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); return axp20x_get_current_max(power, &val->intval);
if (ret)
return ret;
switch (v & AXP20X_VBUS_CLIMIT_MASK) {
case AXP20X_VBUS_CLIMIT_100mA:
if (power->axp20x_id == AXP221_ID)
val->intval = -1; /* No 100mA limit */
else
val->intval = 100000;
break;
case AXP20X_VBUS_CLIMIT_500mA:
val->intval = 500000;
break;
case AXP20X_VBUS_CLIMIT_900mA:
val->intval = 900000;
break;
case AXP20X_VBUS_CLIMIT_NONE:
val->intval = -1;
break;
}
return 0;
case POWER_SUPPLY_PROP_CURRENT_NOW: case POWER_SUPPLY_PROP_CURRENT_NOW:
if (IS_ENABLED(CONFIG_AXP20X_ADC)) { if (IS_ENABLED(CONFIG_AXP20X_ADC)) {
ret = iio_read_channel_processed(power->vbus_i, ret = iio_read_channel_processed(power->vbus_i,
......
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