phy: stm32: manage optional vbus regulator on phy_power_on/off
authorAmelie Delaunay <amelie.delaunay@foss.st.com>
Mon, 17 May 2021 12:08:21 +0000 (14:08 +0200)
committerVinod Koul <vkoul@kernel.org>
Mon, 31 May 2021 08:38:58 +0000 (14:08 +0530)
This patch adds support for optional vbus regulator.
It is managed on phy_power_on/off calls and may be needed for host mode.

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

index c184f4e..3e491df 100644 (file)
@@ -57,6 +57,7 @@ struct pll_params {
 struct stm32_usbphyc_phy {
        struct phy *phy;
        struct stm32_usbphyc *usbphyc;
+       struct regulator *vbus;
        u32 index;
        bool active;
 };
@@ -291,9 +292,31 @@ static int stm32_usbphyc_phy_exit(struct phy *phy)
        return stm32_usbphyc_pll_disable(usbphyc);
 }
 
+static int stm32_usbphyc_phy_power_on(struct phy *phy)
+{
+       struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
+
+       if (usbphyc_phy->vbus)
+               return regulator_enable(usbphyc_phy->vbus);
+
+       return 0;
+}
+
+static int stm32_usbphyc_phy_power_off(struct phy *phy)
+{
+       struct stm32_usbphyc_phy *usbphyc_phy = phy_get_drvdata(phy);
+
+       if (usbphyc_phy->vbus)
+               return regulator_disable(usbphyc_phy->vbus);
+
+       return 0;
+}
+
 static const struct phy_ops stm32_usbphyc_phy_ops = {
        .init = stm32_usbphyc_phy_init,
        .exit = stm32_usbphyc_phy_exit,
+       .power_on = stm32_usbphyc_phy_power_on,
+       .power_off = stm32_usbphyc_phy_power_off,
        .owner = THIS_MODULE,
 };
 
@@ -519,6 +542,14 @@ static int stm32_usbphyc_probe(struct platform_device *pdev)
                usbphyc->phys[port]->index = index;
                usbphyc->phys[port]->active = false;
 
+               usbphyc->phys[port]->vbus = devm_regulator_get_optional(&phy->dev, "vbus");
+               if (IS_ERR(usbphyc->phys[port]->vbus)) {
+                       ret = PTR_ERR(usbphyc->phys[port]->vbus);
+                       if (ret == -EPROBE_DEFER)
+                               goto put_child;
+                       usbphyc->phys[port]->vbus = NULL;
+               }
+
                port++;
        }