build/patch/kernel/archive/sunxi-6.1/patches.megous/power-supply-axp20x-usb-power-Don-t-require-exact-values-for-in.patch

83 lines
1.8 KiB
Diff

From 3d4beb8874c9ac3b56a2696c57e4a52cd86c1df2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Jirman?= <megi@xff.cz>
Date: Mon, 30 Nov 2020 05:58:12 +0100
Subject: [PATCH 210/389] power: supply: axp20x-usb-power: Don't require exact
values for input current limit
Available values are not enumerable, and usb type-c driver needs
to set lower or equal current limits after PD negotiation.
Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
drivers/power/supply/axp20x_usb_power.c | 47 +++++++++----------------
1 file changed, 17 insertions(+), 30 deletions(-)
diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c
index 7b4db148a219..7218131a851f 100644
--- a/drivers/power/supply/axp20x_usb_power.c
+++ b/drivers/power/supply/axp20x_usb_power.c
@@ -449,43 +449,30 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power,
return -EINVAL;
}
+static const unsigned axp813_input_current_limits_table[] = {
+ 100000,
+ 500000,
+ 900000,
+ 1500000,
+ 2000000,
+ 2500000,
+ 3000000,
+ 3500000,
+ 4000000,
+};
+
static int
axp813_usb_power_set_input_current_limit(struct axp20x_usb_power *power,
int intval)
{
unsigned int reg;
- switch (intval) {
- case 100000:
- reg = 0;
- break;
- case 500000:
- reg = 1;
- break;
- case 900000:
- reg = 2;
- break;
- case 1500000:
- reg = 3;
- break;
- case 2000000:
- reg = 4;
- break;
- case 2500000:
- reg = 5;
- break;
- case 3000000:
- reg = 6;
- break;
- case 3500000:
- reg = 7;
- break;
- case 4000000:
- reg = 8;
- break;
- default:
+ if (intval < 100000)
return -EINVAL;
- }
+
+ for (reg = ARRAY_SIZE(axp813_input_current_limits_table) - 1; reg > 0; reg--)
+ if (intval >= axp813_input_current_limits_table[reg])
+ break;
return regmap_update_bits(power->regmap,
AXP813_CHRG_CTRL3,
--
2.35.3