Skip to content

Commit 6934da7

Browse files
macromorgansre
authored andcommitted
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 <[email protected]> Acked-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 6f5cdb7 commit 6934da7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/power/supply/axp20x_usb_power.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct axp20x_usb_power {
8080
struct iio_channel *vbus_v;
8181
struct iio_channel *vbus_i;
8282
struct delayed_work vbus_detect;
83+
int max_input_cur;
8384
unsigned int old_status;
8485
unsigned int online;
8586
unsigned int num_irqs;
@@ -323,6 +324,13 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow
323324
if (intval == -1)
324325
return -EINVAL;
325326

327+
if (power->max_input_cur && (intval > power->max_input_cur)) {
328+
dev_warn(power->dev,
329+
"reqested current %d clamped to max current %d\n",
330+
intval, power->max_input_cur);
331+
intval = power->max_input_cur;
332+
}
333+
326334
/*
327335
* BC1.2 detection can cause a race condition if we try to set a current
328336
* 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,
661669
return 0;
662670
}
663671

672+
/* Optionally allow users to specify a maximum charging current. */
673+
static void axp20x_usb_power_parse_dt(struct device *dev,
674+
struct axp20x_usb_power *power)
675+
{
676+
int ret;
677+
678+
ret = device_property_read_u32(dev, "input-current-limit-microamp",
679+
&power->max_input_cur);
680+
if (ret)
681+
dev_dbg(dev, "%s() no input-current-limit specified\n", __func__);
682+
}
683+
664684
static int axp20x_usb_power_probe(struct platform_device *pdev)
665685
{
666686
struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
@@ -697,6 +717,8 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
697717
if (IS_ERR(power->curr_lim_fld))
698718
return PTR_ERR(power->curr_lim_fld);
699719

720+
axp20x_usb_power_parse_dt(&pdev->dev, power);
721+
700722
ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap,
701723
axp_data->vbus_valid_bit,
702724
&power->vbus_valid_bit);

0 commit comments

Comments
 (0)