The PHY device tree node may reference a regulator via vbus-supply that
needs to be switched by software.

Linux already supported this binding, so implement it for barebox as well.

Unlike the Linux driver, we do not treat a missing regulator as hard
error for backwards compatibility reasons. Instead, we just print a
warning and move along:

- If we have a driver, then on deep probe systems, this should always
  succeed anyway.

- If we do not have a driver and are on deep probe system, the VBUS is
  powered on already, then the warning can be suppressed by
  barebox,allow-dummy-supply in the provider node.

- If the user is not on a deep probe system, they should either patch
  out vbus-supply or enable deep probe.

Reported-by: Holger Assmann <[email protected]>
Signed-off-by: Ahmad Fatoum <[email protected]>
---
 drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c 
b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
index 1349ca922c70..414d21241496 100644
--- a/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
+++ b/drivers/phy/freescale/phy-fsl-imx8mq-usb.c
@@ -5,6 +5,7 @@
 #include <driver.h>
 #include <errno.h>
 #include <init.h>
+#include <regulator.h>
 #include <io.h>
 #include <linux/bitfield.h>
 #include <linux/clk.h>
@@ -40,6 +41,7 @@ struct imx8mq_usb_phy {
        struct phy *phy;
        struct clk *clk;
        void __iomem *base;
+       struct regulator *vbus;
 };
 
 static int imx8mq_usb_phy_init(struct phy *phy)
@@ -109,6 +111,11 @@ static int imx8mp_usb_phy_init(struct phy *phy)
 static int imx8mq_phy_power_on(struct phy *phy)
 {
        struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy);
+       int ret;
+
+       ret = regulator_enable(imx_phy->vbus);
+       if (ret)
+               return ret;
 
        return clk_enable(imx_phy->clk);
 }
@@ -118,6 +125,7 @@ static int imx8mq_phy_power_off(struct phy *phy)
        struct imx8mq_usb_phy *imx_phy = phy_get_drvdata(phy);
 
        clk_disable(imx_phy->clk);
+       regulator_disable(imx_phy->vbus);
 
        return 0;
 }
@@ -177,6 +185,12 @@ static int imx8mq_usb_phy_probe(struct device *dev)
        if (IS_ERR(imx_phy->phy))
                return PTR_ERR(imx_phy->phy);
 
+       imx_phy->vbus = regulator_get(dev, "vbus");
+       if (IS_ERR(imx_phy->vbus)) {
+               imx_phy->vbus = NULL;
+               dev_warn(dev, "Failed to get 'vbus' regulator (ignored).\n");
+       }
+
        phy_set_drvdata(imx_phy->phy, imx_phy);
 
        phy_provider = of_phy_provider_register(dev, imx8mq_usb_phy_xlate);
-- 
2.47.3


Reply via email to