usb: ehci: Make the PHY handling generic
authorMarek Vasut <marek.vasut+renesas@gmail.com>
Wed, 8 Aug 2018 12:29:55 +0000 (14:29 +0200)
committerMarek Vasut <marex@denx.de>
Tue, 28 Aug 2018 09:00:18 +0000 (11:00 +0200)
Pull out the EHCI PHY functions into the ehci-hcd.c to let other
EHCI drivers use them.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
drivers/usb/host/ehci-generic.c
drivers/usb/host/ehci-hcd.c
drivers/usb/host/ehci.h

index 5a56f66cfaa6ff942e108f933d32cef2b4e21231..cc2f33826a3bf19a545960843f2c4597a2cd8946 100644 (file)
@@ -26,56 +26,6 @@ struct generic_ehci {
        int reset_count;
 };
 
-static int ehci_setup_phy(struct udevice *dev, int index)
-{
-       struct generic_ehci *priv = dev_get_priv(dev);
-       int ret;
-
-       ret = generic_phy_get_by_index(dev, index, &priv->phy);
-       if (ret) {
-               if (ret != -ENOENT) {
-                       dev_err(dev, "failed to get usb phy\n");
-                       return ret;
-               }
-       } else {
-               ret = generic_phy_init(&priv->phy);
-               if (ret) {
-                       dev_err(dev, "failed to init usb phy\n");
-                       return ret;
-               }
-
-               ret = generic_phy_power_on(&priv->phy);
-               if (ret) {
-                       dev_err(dev, "failed to power on usb phy\n");
-                       return generic_phy_exit(&priv->phy);
-               }
-       }
-
-       return 0;
-}
-
-static int ehci_shutdown_phy(struct udevice *dev)
-{
-       struct generic_ehci *priv = dev_get_priv(dev);
-       int ret = 0;
-
-       if (generic_phy_valid(&priv->phy)) {
-               ret = generic_phy_power_off(&priv->phy);
-               if (ret) {
-                       dev_err(dev, "failed to power off usb phy\n");
-                       return ret;
-               }
-
-               ret = generic_phy_exit(&priv->phy);
-               if (ret) {
-                       dev_err(dev, "failed to power off usb phy\n");
-                       return ret;
-               }
-       }
-
-       return 0;
-}
-
 static int ehci_usb_probe(struct udevice *dev)
 {
        struct generic_ehci *priv = dev_get_priv(dev);
@@ -145,7 +95,7 @@ static int ehci_usb_probe(struct udevice *dev)
                }
        }
 
-       err = ehci_setup_phy(dev, 0);
+       err = ehci_setup_phy(dev, &priv->phy, 0);
        if (err)
                goto reset_err;
 
@@ -160,7 +110,7 @@ static int ehci_usb_probe(struct udevice *dev)
        return 0;
 
 phy_err:
-       ret = ehci_shutdown_phy(dev);
+       ret = ehci_shutdown_phy(dev, &priv->phy);
        if (ret)
                dev_err(dev, "failed to shutdown usb phy\n");
 
@@ -185,7 +135,7 @@ static int ehci_usb_remove(struct udevice *dev)
        if (ret)
                return ret;
 
-       ret = ehci_shutdown_phy(dev);
+       ret = ehci_shutdown_phy(dev, &priv->phy);
        if (ret)
                return ret;
 
index 663f748ffcc3c849f48234c583e13dfb0b683038..199b3a8b264d98e62c601e2127873265801c9fa6 100644 (file)
@@ -1675,3 +1675,69 @@ struct dm_usb_ops ehci_usb_ops = {
 };
 
 #endif
+
+#ifdef CONFIG_PHY
+int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index)
+{
+       int ret;
+
+       if (!phy)
+               return 0;
+
+       ret = generic_phy_get_by_index(dev, index, phy);
+       if (ret) {
+               if (ret != -ENOENT) {
+                       dev_err(dev, "failed to get usb phy\n");
+                       return ret;
+               }
+       } else {
+               ret = generic_phy_init(phy);
+               if (ret) {
+                       dev_err(dev, "failed to init usb phy\n");
+                       return ret;
+               }
+
+               ret = generic_phy_power_on(phy);
+               if (ret) {
+                       dev_err(dev, "failed to power on usb phy\n");
+                       return generic_phy_exit(phy);
+               }
+       }
+
+       return 0;
+}
+
+int ehci_shutdown_phy(struct udevice *dev, struct phy *phy)
+{
+       int ret = 0;
+
+       if (!phy)
+               return 0;
+
+       if (generic_phy_valid(phy)) {
+               ret = generic_phy_power_off(phy);
+               if (ret) {
+                       dev_err(dev, "failed to power off usb phy\n");
+                       return ret;
+               }
+
+               ret = generic_phy_exit(phy);
+               if (ret) {
+                       dev_err(dev, "failed to power off usb phy\n");
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+#else
+int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index)
+{
+       return 0;
+}
+
+int ehci_shutdown_phy(struct udevice *dev, struct phy *phy)
+{
+       return 0;
+}
+#endif
index 07de472f912339ee59077ca0385831811e590aee..7945016624da55dd15f9a0d0ab2a3454ad3a9d3e 100644 (file)
@@ -9,6 +9,7 @@
 #define USB_EHCI_H
 
 #include <usb.h>
+#include <generic-phy.h>
 
 /* Section 2.2.3 - N_PORTS */
 #define MAX_HC_PORTS           15
@@ -288,4 +289,8 @@ int ehci_register(struct udevice *dev, struct ehci_hccr *hccr,
 int ehci_deregister(struct udevice *dev);
 extern struct dm_usb_ops ehci_usb_ops;
 
+/* EHCI PHY functions */
+int ehci_setup_phy(struct udevice *dev, struct phy *phy, int index);
+int ehci_shutdown_phy(struct udevice *dev, struct phy *phy);
+
 #endif /* USB_EHCI_H */