From 601e528e513ad53138c262ed5ac8d9a82a6ab29d Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sun, 4 Sep 2022 23:27:30 +0200
Subject: [PATCH 278/389] arm64: dts: rk3399-pinephone-pro: Add 5V power supply

Enable 5V power supply used by some devices on the board.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 .../dts/rockchip/rk3399-pinephone-pro.dts     | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
index 782316ad512b..472699d5af9b 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
@@ -158,6 +158,50 @@ vcc_sys: vcc-sys-regulator {
 		regulator-boot-on;
 	};
 
+	vcc5v0_sys: vcc5v0-host-regulator {
+		compatible = "regulator-fixed";
+		regulator-name = "vcc5v0_sys";
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-always-on;
+		regulator-boot-on;
+		vin-supply = <&boost_otg>;
+
+		regulator-state-mem {
+			regulator-on-in-suspend;
+		};
+	};
+
+	/*
+	 * This is not a regulator. GPIO0_A6 is used to force enable VCC_SYS <->
+	 * VBAT+ Q7 switch that helps boost the RK818's power path's current carrying
+	 * capacity when operating the phone from the battery in case VBUS_TYPEC
+	 * has 5V provided by the phone itself and not by the external power
+	 * supply. (this happens in USB host mode)
+	 *
+	 * GPIO0_A6 low: Q7 is enabled if there's 0V on VBUS_TYPEC (phone is not
+	 *               powered from external power supply)
+	 * GPIO0_A6 high: Q7 is enabled no matter what
+	 *
+	 * GPIO0_A6 must be high when the phone is providing VBUS_TYPEC power.
+	 * This keeps the power path boost enabled for all cases when the phone
+	 * runs from the battery.
+	 *
+	 * In other words, GPIO0_A6 is used to override the automatic disabling
+	 * of Q7 when VBUS_TYPEC has 5V in USB host mode.
+	 */
+	vcc5v0_typec: vcc5v0-typec-regulator {
+		compatible = "regulator-fixed";
+		enable-active-high;
+		gpio = <&gpio0 RK_PA6 GPIO_ACTIVE_HIGH>;
+		pinctrl-names = "default";
+		pinctrl-0 = <&vcc5v0_typec_en>;
+		regulator-min-microvolt = <5000000>;
+		regulator-max-microvolt = <5000000>;
+		regulator-name = "vcc5v0_typec";
+		vin-supply = <&boost_otg>;
+	};
+
 	vcc3v3_sys: vcc3v3-sys-regulator {
 		compatible = "regulator-fixed";
 		regulator-name = "vcc3v3_sys";
@@ -276,6 +320,7 @@ rk818: pmic@1c {
 		vcc7-supply = <&vcc3v3_sys>;
 		vcc8-supply = <&vcc_sys>;
 		vcc9-supply = <&vcc3v3_sys>;
+		usb-supply = <&vcc5v0_typec>;
 
 		regulators {
 			vdd_cpu_l: DCDC_REG1 {
@@ -407,6 +452,21 @@ regulator-state-mem {
 					regulator-on-in-suspend;
 				};
 			};
+
+			boost_otg: DCDC_BOOST {
+				regulator-name = "boost_otg";
+				regulator-always-on;
+				regulator-boot-on;
+				regulator-min-microvolt = <5000000>;
+				regulator-max-microvolt = <5000000>;
+				regulator-state-mem {
+					regulator-on-in-suspend;
+				};
+			};
+
+			otg_switch: OTG_SWITCH {
+				regulator-name = "otg_switch";
+			};
 		};
 
 		/*
-- 
2.35.3

