Commit 8f01c45a authored by Sebastian Reichel's avatar Sebastian Reichel

Merge tag 'psy-mfd-axp813-immutable-for-v4.21-signed' into psy-next

Immutable branch between mfd and power-supply for driver
changes related to axp813.
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parents a95761d6 7693b564
...@@ -4,6 +4,7 @@ Required Properties: ...@@ -4,6 +4,7 @@ Required Properties:
- compatible: One of: - compatible: One of:
"x-powers,axp202-ac-power-supply" "x-powers,axp202-ac-power-supply"
"x-powers,axp221-ac-power-supply" "x-powers,axp221-ac-power-supply"
"x-powers,axp813-ac-power-supply"
This node is a subnode of the axp20x PMIC. This node is a subnode of the axp20x PMIC.
...@@ -13,6 +14,8 @@ reading ADC channels from the AXP20X ADC. ...@@ -13,6 +14,8 @@ reading ADC channels from the AXP20X ADC.
The AXP22X is only able to tell if an AC power supply is present and The AXP22X is only able to tell if an AC power supply is present and
usable. usable.
AXP813/AXP803 are able to limit current and supply voltage
Example: Example:
&axp209 { &axp209 {
......
...@@ -27,6 +27,16 @@ ...@@ -27,6 +27,16 @@
#define AXP20X_PWR_STATUS_ACIN_PRESENT BIT(7) #define AXP20X_PWR_STATUS_ACIN_PRESENT BIT(7)
#define AXP20X_PWR_STATUS_ACIN_AVAIL BIT(6) #define AXP20X_PWR_STATUS_ACIN_AVAIL BIT(6)
#define AXP813_VHOLD_MASK GENMASK(5, 3)
#define AXP813_VHOLD_UV_TO_BIT(x) ((((x) / 100000) - 40) << 3)
#define AXP813_VHOLD_REG_TO_UV(x) \
(((((x) & AXP813_VHOLD_MASK) >> 3) + 40) * 100000)
#define AXP813_CURR_LIMIT_MASK GENMASK(2, 0)
#define AXP813_CURR_LIMIT_UA_TO_BIT(x) (((x) / 500000) - 3)
#define AXP813_CURR_LIMIT_REG_TO_UA(x) \
((((x) & AXP813_CURR_LIMIT_MASK) + 3) * 500000)
#define DRVNAME "axp20x-ac-power-supply" #define DRVNAME "axp20x-ac-power-supply"
struct axp20x_ac_power { struct axp20x_ac_power {
...@@ -102,6 +112,57 @@ static int axp20x_ac_power_get_property(struct power_supply *psy, ...@@ -102,6 +112,57 @@ static int axp20x_ac_power_get_property(struct power_supply *psy,
return 0; return 0;
case POWER_SUPPLY_PROP_VOLTAGE_MIN:
ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, &reg);
if (ret)
return ret;
val->intval = AXP813_VHOLD_REG_TO_UV(reg);
return 0;
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, &reg);
if (ret)
return ret;
val->intval = AXP813_CURR_LIMIT_REG_TO_UA(reg);
/* AXP813 datasheet defines values 11x as 4000mA */
if (val->intval > 4000000)
val->intval = 4000000;
return 0;
default:
return -EINVAL;
}
return -EINVAL;
}
static int axp813_ac_power_set_property(struct power_supply *psy,
enum power_supply_property psp,
const union power_supply_propval *val)
{
struct axp20x_ac_power *power = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_VOLTAGE_MIN:
if (val->intval < 4000000 || val->intval > 4700000)
return -EINVAL;
return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL,
AXP813_VHOLD_MASK,
AXP813_VHOLD_UV_TO_BIT(val->intval));
case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
if (val->intval < 1500000 || val->intval > 4000000)
return -EINVAL;
return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL,
AXP813_CURR_LIMIT_MASK,
AXP813_CURR_LIMIT_UA_TO_BIT(val->intval));
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -109,6 +170,13 @@ static int axp20x_ac_power_get_property(struct power_supply *psy, ...@@ -109,6 +170,13 @@ static int axp20x_ac_power_get_property(struct power_supply *psy,
return -EINVAL; return -EINVAL;
} }
static int axp813_ac_power_prop_writeable(struct power_supply *psy,
enum power_supply_property psp)
{
return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN ||
psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT;
}
static enum power_supply_property axp20x_ac_power_properties[] = { static enum power_supply_property axp20x_ac_power_properties[] = {
POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_PRESENT,
...@@ -123,6 +191,14 @@ static enum power_supply_property axp22x_ac_power_properties[] = { ...@@ -123,6 +191,14 @@ static enum power_supply_property axp22x_ac_power_properties[] = {
POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_ONLINE,
}; };
static enum power_supply_property axp813_ac_power_properties[] = {
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_VOLTAGE_MIN,
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
};
static const struct power_supply_desc axp20x_ac_power_desc = { static const struct power_supply_desc axp20x_ac_power_desc = {
.name = "axp20x-ac", .name = "axp20x-ac",
.type = POWER_SUPPLY_TYPE_MAINS, .type = POWER_SUPPLY_TYPE_MAINS,
...@@ -139,6 +215,16 @@ static const struct power_supply_desc axp22x_ac_power_desc = { ...@@ -139,6 +215,16 @@ static const struct power_supply_desc axp22x_ac_power_desc = {
.get_property = axp20x_ac_power_get_property, .get_property = axp20x_ac_power_get_property,
}; };
static const struct power_supply_desc axp813_ac_power_desc = {
.name = "axp813-ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.properties = axp813_ac_power_properties,
.num_properties = ARRAY_SIZE(axp813_ac_power_properties),
.property_is_writeable = axp813_ac_power_prop_writeable,
.get_property = axp20x_ac_power_get_property,
.set_property = axp813_ac_power_set_property,
};
struct axp_data { struct axp_data {
const struct power_supply_desc *power_desc; const struct power_supply_desc *power_desc;
bool acin_adc; bool acin_adc;
...@@ -154,6 +240,11 @@ static const struct axp_data axp22x_data = { ...@@ -154,6 +240,11 @@ static const struct axp_data axp22x_data = {
.acin_adc = false, .acin_adc = false,
}; };
static const struct axp_data axp813_data = {
.power_desc = &axp813_ac_power_desc,
.acin_adc = false,
};
static int axp20x_ac_power_probe(struct platform_device *pdev) static int axp20x_ac_power_probe(struct platform_device *pdev)
{ {
struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
...@@ -234,6 +325,9 @@ static const struct of_device_id axp20x_ac_power_match[] = { ...@@ -234,6 +325,9 @@ static const struct of_device_id axp20x_ac_power_match[] = {
}, { }, {
.compatible = "x-powers,axp221-ac-power-supply", .compatible = "x-powers,axp221-ac-power-supply",
.data = &axp22x_data, .data = &axp22x_data,
}, {
.compatible = "x-powers,axp813-ac-power-supply",
.data = &axp813_data,
}, { /* sentinel */ } }, { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, axp20x_ac_power_match); MODULE_DEVICE_TABLE(of, axp20x_ac_power_match);
......
...@@ -266,6 +266,7 @@ enum axp20x_variants { ...@@ -266,6 +266,7 @@ enum axp20x_variants {
#define AXP288_RT_BATT_V_H 0xa0 #define AXP288_RT_BATT_V_H 0xa0
#define AXP288_RT_BATT_V_L 0xa1 #define AXP288_RT_BATT_V_L 0xa1
#define AXP813_ACIN_PATH_CTRL 0x3a
#define AXP813_ADC_RATE 0x85 #define AXP813_ADC_RATE 0x85
/* Fuel Gauge */ /* Fuel Gauge */
......
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