phy: stm32: ensure pll is disabled before phys creation
authorAmelie Delaunay <amelie.delaunay@foss.st.com>
Tue, 5 Jan 2021 09:05:23 +0000 (10:05 +0100)
committerVinod Koul <vkoul@kernel.org>
Wed, 13 Jan 2021 15:10:21 +0000 (20:40 +0530)
To ensure a good balancing of regulators, force PLL disable either by
reset or by clearing the PLLEN bit.
If waiting the powerdown pulse delay isn't enough, return -EPROBE_DEFER
instead of polling the PLLEN bit, which will be low at the next probe.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Link: https://lore.kernel.org/r/20210105090525.23164-5-amelie.delaunay@foss.st.com
Signed-off-by: Vinod Koul <vkoul@kernel.org>
drivers/phy/st/phy-stm32-usbphyc.c

index 8ef97c8..33367a3 100644 (file)
@@ -8,7 +8,7 @@
 #include <linux/bitfield.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
-#include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
@@ -334,7 +334,7 @@ static int stm32_usbphyc_probe(struct platform_device *pdev)
        struct device *dev = &pdev->dev;
        struct device_node *child, *np = dev->of_node;
        struct phy_provider *phy_provider;
-       u32 version;
+       u32 pllen, version;
        int ret, port = 0;
 
        usbphyc = devm_kzalloc(dev, sizeof(*usbphyc), GFP_KERNEL);
@@ -366,6 +366,19 @@ static int stm32_usbphyc_probe(struct platform_device *pdev)
                ret = PTR_ERR(usbphyc->rst);
                if (ret == -EPROBE_DEFER)
                        goto clk_disable;
+
+               stm32_usbphyc_clr_bits(usbphyc->base + STM32_USBPHYC_PLL, PLLEN);
+       }
+
+       /*
+        * Wait for minimum width of powerdown pulse (ENABLE = Low):
+        * we have to ensure the PLL is disabled before phys initialization.
+        */
+       if (readl_relaxed_poll_timeout(usbphyc->base + STM32_USBPHYC_PLL,
+                                      pllen, !(pllen & PLLEN), 5, 50)) {
+               dev_warn(usbphyc->dev, "PLL not reset\n");
+               ret = -EPROBE_DEFER;
+               goto clk_disable;
        }
 
        usbphyc->switch_setup = -EINVAL;