Commit 6934da72 authored by Chris Morgan's avatar Chris Morgan Committed by Sebastian Reichel

power: supply: axp20x_usb_power: add input-current-limit-microamp

Allow users to specify a maximum input current for the device. Some
devices allow up to 3.25A of input current (such as the AXP717), which
may be too much for some implementations.
Signed-off-by: default avatarChris Morgan <macromorgan@hotmail.com>
Acked-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240821215456.962564-7-macroalpha82@gmail.comSigned-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent 6f5cdb7e
...@@ -80,6 +80,7 @@ struct axp20x_usb_power { ...@@ -80,6 +80,7 @@ struct axp20x_usb_power {
struct iio_channel *vbus_v; struct iio_channel *vbus_v;
struct iio_channel *vbus_i; struct iio_channel *vbus_i;
struct delayed_work vbus_detect; struct delayed_work vbus_detect;
int max_input_cur;
unsigned int old_status; unsigned int old_status;
unsigned int online; unsigned int online;
unsigned int num_irqs; unsigned int num_irqs;
...@@ -323,6 +324,13 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow ...@@ -323,6 +324,13 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow
if (intval == -1) if (intval == -1)
return -EINVAL; return -EINVAL;
if (power->max_input_cur && (intval > power->max_input_cur)) {
dev_warn(power->dev,
"reqested current %d clamped to max current %d\n",
intval, power->max_input_cur);
intval = power->max_input_cur;
}
/* /*
* BC1.2 detection can cause a race condition if we try to set a current * BC1.2 detection can cause a race condition if we try to set a current
* limit while it's in progress. When it finishes it will overwrite the * limit while it's in progress. When it finishes it will overwrite the
...@@ -661,6 +669,18 @@ static int axp20x_regmap_field_alloc_optional(struct device *dev, ...@@ -661,6 +669,18 @@ static int axp20x_regmap_field_alloc_optional(struct device *dev,
return 0; return 0;
} }
/* Optionally allow users to specify a maximum charging current. */
static void axp20x_usb_power_parse_dt(struct device *dev,
struct axp20x_usb_power *power)
{
int ret;
ret = device_property_read_u32(dev, "input-current-limit-microamp",
&power->max_input_cur);
if (ret)
dev_dbg(dev, "%s() no input-current-limit specified\n", __func__);
}
static int axp20x_usb_power_probe(struct platform_device *pdev) static int axp20x_usb_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);
...@@ -697,6 +717,8 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) ...@@ -697,6 +717,8 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
if (IS_ERR(power->curr_lim_fld)) if (IS_ERR(power->curr_lim_fld))
return PTR_ERR(power->curr_lim_fld); return PTR_ERR(power->curr_lim_fld);
axp20x_usb_power_parse_dt(&pdev->dev, power);
ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap,
axp_data->vbus_valid_bit, axp_data->vbus_valid_bit,
&power->vbus_valid_bit); &power->vbus_valid_bit);
......
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