From e4ffd1f5898bf07ec4bcdbe38d545cd5c66694a7 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sun, 4 Sep 2022 23:27:30 +0200
Subject: [PATCH 392/484] 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 c64214701d00..2a885bbe45dd 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts
@@ -141,6 +141,50 @@
 		regulator-boot-on;
 	};
 
+	vcc5v0_sys: regulator-vcc5v0-host {
+		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: regulator-vcc5v0-typec {
+		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: regulator-vcc3v3-sys {
 		compatible = "regulator-fixed";
 		regulator-name = "vcc3v3_sys";
@@ -293,6 +337,7 @@
 		vcc7-supply = <&vcc3v3_sys>;
 		vcc8-supply = <&vcc_sys>;
 		vcc9-supply = <&vcc3v3_sys>;
+		usb-supply = <&vcc5v0_typec>;
 
 		regulators {
 			vdd_cpu_l: DCDC_REG1 {
@@ -424,6 +469,21 @@
 					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.49.0

