diff mbox series

[U-Boot,04/16] phy: usbphyc: move vdda1v1 and vdda1v8 in phy_init

Message ID 1553870544-15734-5-git-send-email-patrick.delaunay@st.com
State Accepted
Commit e1904abc1bf90e9b382042a45d645d3dd6fbe8b0
Delegated to: Lukasz Majewski
Headers show
Series usb: convert dwc2 gadget to driver model, used in stm32mp1 | expand

Commit Message

Patrick DELAUNAY March 29, 2019, 2:42 p.m. UTC
vdda1v1 and vdda1v8 are used by the PLL.
Both need to be enabled before starting the PLL.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 drivers/phy/phy-stm32-usbphyc.c | 60 +++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 29 deletions(-)
diff mbox series

Patch

diff --git a/drivers/phy/phy-stm32-usbphyc.c b/drivers/phy/phy-stm32-usbphyc.c
index 617c5a0..54363cd 100644
--- a/drivers/phy/phy-stm32-usbphyc.c
+++ b/drivers/phy/phy-stm32-usbphyc.c
@@ -60,7 +60,8 @@  struct stm32_usbphyc {
 	} phys[MAX_PHYS];
 };
 
-void stm32_usbphyc_get_pll_params(u32 clk_rate, struct pll_params *pll_params)
+static void stm32_usbphyc_get_pll_params(u32 clk_rate,
+					 struct pll_params *pll_params)
 {
 	unsigned long long fvco, ndiv, frac;
 
@@ -153,6 +154,18 @@  static int stm32_usbphyc_phy_init(struct phy *phy)
 	if (pllen && stm32_usbphyc_is_init(usbphyc))
 		goto initialized;
 
+	if (usbphyc->vdda1v1) {
+		ret = regulator_set_enable(usbphyc->vdda1v1, true);
+		if (ret)
+			return ret;
+	}
+
+	if (usbphyc->vdda1v8) {
+		ret = regulator_set_enable(usbphyc->vdda1v8, true);
+		if (ret)
+			return ret;
+	}
+
 	if (pllen) {
 		clrbits_le32(usbphyc->base + STM32_USBPHYC_PLL, PLLEN);
 		udelay(PLL_PWR_DOWN_TIME_US);
@@ -183,6 +196,7 @@  static int stm32_usbphyc_phy_exit(struct phy *phy)
 {
 	struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev);
 	struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + phy->id;
+	int ret;
 
 	pr_debug("%s phy ID = %lu\n", __func__, phy->id);
 	usbphyc_phy->init = false;
@@ -202,30 +216,30 @@  static int stm32_usbphyc_phy_exit(struct phy *phy)
 	if (readl(usbphyc->base + STM32_USBPHYC_PLL) & PLLEN)
 		return -EIO;
 
-	return 0;
-}
-
-static int stm32_usbphyc_phy_power_on(struct phy *phy)
-{
-	struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev);
-	struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + phy->id;
-	int ret;
-
-	pr_debug("%s phy ID = %lu\n", __func__, phy->id);
 	if (usbphyc->vdda1v1) {
-		ret = regulator_set_enable(usbphyc->vdda1v1, true);
+		ret = regulator_set_enable(usbphyc->vdda1v1, false);
 		if (ret)
 			return ret;
 	}
 
 	if (usbphyc->vdda1v8) {
-		ret = regulator_set_enable(usbphyc->vdda1v8, true);
+		ret = regulator_set_enable(usbphyc->vdda1v8, false);
 		if (ret)
 			return ret;
 	}
 
-	if (usbphyc->vdd) {
-		ret = regulator_set_enable(usbphyc->vdd, true);
+	return 0;
+}
+
+static int stm32_usbphyc_phy_power_on(struct phy *phy)
+{
+	struct stm32_usbphyc *usbphyc = dev_get_priv(phy->dev);
+	struct stm32_usbphyc_phy *usbphyc_phy = usbphyc->phys + phy->id;
+	int ret;
+
+	pr_debug("%s phy ID = %lu\n", __func__, phy->id);
+	if (usbphyc_phy->vdd) {
+		ret = regulator_set_enable(usbphyc_phy->vdd, true);
 		if (ret)
 			return ret;
 	}
@@ -247,20 +261,8 @@  static int stm32_usbphyc_phy_power_off(struct phy *phy)
 	if (stm32_usbphyc_is_powered(usbphyc))
 		return 0;
 
-	if (usbphyc->vdda1v1) {
-		ret = regulator_set_enable(usbphyc->vdda1v1, false);
-		if (ret)
-			return ret;
-	}
-
-	if (usbphyc->vdda1v8) {
-		ret = regulator_set_enable(usbphyc->vdda1v8, false);
-		if (ret)
-			return ret;
-	}
-
-	if (usbphyc->vdd) {
-		ret = regulator_set_enable(usbphyc->vdd, false);
+	if (usbphyc_phy->vdd) {
+		ret = regulator_set_enable(usbphyc_phy->vdd, false);
 		if (ret)
 			return ret;
 	}