Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chris Morgan and committed by
Sebastian Reichel
6934da72 6f5cdb7e

+22
+22
drivers/power/supply/axp20x_usb_power.c
··· 80 80 struct iio_channel *vbus_v; 81 81 struct iio_channel *vbus_i; 82 82 struct delayed_work vbus_detect; 83 + int max_input_cur; 83 84 unsigned int old_status; 84 85 unsigned int online; 85 86 unsigned int num_irqs; ··· 323 322 324 323 if (intval == -1) 325 324 return -EINVAL; 325 + 326 + if (power->max_input_cur && (intval > power->max_input_cur)) { 327 + dev_warn(power->dev, 328 + "reqested current %d clamped to max current %d\n", 329 + intval, power->max_input_cur); 330 + intval = power->max_input_cur; 331 + } 326 332 327 333 /* 328 334 * BC1.2 detection can cause a race condition if we try to set a current ··· 669 661 return 0; 670 662 } 671 663 664 + /* Optionally allow users to specify a maximum charging current. */ 665 + static void axp20x_usb_power_parse_dt(struct device *dev, 666 + struct axp20x_usb_power *power) 667 + { 668 + int ret; 669 + 670 + ret = device_property_read_u32(dev, "input-current-limit-microamp", 671 + &power->max_input_cur); 672 + if (ret) 673 + dev_dbg(dev, "%s() no input-current-limit specified\n", __func__); 674 + } 675 + 672 676 static int axp20x_usb_power_probe(struct platform_device *pdev) 673 677 { 674 678 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); ··· 716 696 axp_data->curr_lim_fld); 717 697 if (IS_ERR(power->curr_lim_fld)) 718 698 return PTR_ERR(power->curr_lim_fld); 699 + 700 + axp20x_usb_power_parse_dt(&pdev->dev, power); 719 701 720 702 ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, 721 703 axp_data->vbus_valid_bit,