]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
power: supply: axp20x_usb_power: add input-current-limit-microamp
authorChris Morgan <macromorgan@hotmail.com>
Wed, 21 Aug 2024 21:54:47 +0000 (16:54 -0500)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 27 Aug 2024 16:12:25 +0000 (18:12 +0200)
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>
drivers/power/supply/axp20x_usb_power.c

index cd9e92f2ce71ff3ca184409fe8e63aa7e15abe96..69fbb5861934b940994467b50b1edec08d8b3017 100644 (file)
@@ -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);