From 275d53445858fa5e94c5e2a7397662cc9da6126e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Jirman?= <megi@xff.cz>
Date: Tue, 9 Jun 2020 22:00:36 +0200
Subject: [PATCH 274/463] regulator: axp20x: Turn N_VBUSEN to input on
 x-powers,sense-vbus-en

When x-powers,sense-vbus-en is present on the PMIC DT node, force
the N_VBUSEN to be an input. This is necessary on boards that
have N_VBUSEN connected to VBUS enabling switch to make PMIC
not charge when the board is generating VBUS voltage itself.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 .../arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dts | 4 ++++
 drivers/regulator/axp20x-regulator.c                      | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dts b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dts
index 4e7e237cb46aa..bdca3e118ee48 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dts
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone-1.2.dts
@@ -15,6 +15,10 @@ wifi_pwrseq: wifi-pwrseq {
 	};
 };
 
+&axp803 {
+	x-powers,sense-vbus-en;
+};
+
 &backlight {
 	power-supply = <&reg_ldo_io0>;
 	/*
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 7af0f1bf83cd2..59474b74ccff5 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -1706,6 +1706,14 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
 						&aldo1_name);
 	}
 
+	if (!drivevbus &&
+	    of_property_read_bool(pdev->dev.parent->of_node, "x-powers,sense-vbus-en")) {
+		/* make N_VBUSEN an input */
+		regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
+				   AXP22X_MISC_N_VBUSEN_FUNC,
+				   AXP22X_MISC_N_VBUSEN_FUNC);
+	}
+
 	if (drivevbus) {
 		struct regulator_desc *new_desc;
 		bool drivevbus_vin = false;
-- 
2.46.0

