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: Chris Morgan <macromorgan@hotmail.com> Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Link: https://lore.kernel.org/r/20240821215456.962564-7-macroalpha82@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>pull/958/head
parent
6f5cdb7ec8
commit
6934da720a
|
|
@ -80,6 +80,7 @@ struct axp20x_usb_power {
|
|||
struct iio_channel *vbus_v;
|
||||
struct iio_channel *vbus_i;
|
||||
struct delayed_work vbus_detect;
|
||||
int max_input_cur;
|
||||
unsigned int old_status;
|
||||
unsigned int online;
|
||||
unsigned int num_irqs;
|
||||
|
|
@ -323,6 +324,13 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow
|
|||
if (intval == -1)
|
||||
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
|
||||
* 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,
|
|||
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)
|
||||
{
|
||||
struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
|
||||
|
|
@ -697,6 +717,8 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
|
|||
if (IS_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,
|
||||
axp_data->vbus_valid_bit,
|
||||
&power->vbus_valid_bit);
|
||||
|
|
|
|||
Loading…
Reference in New Issue