]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
phy: Add generic_{setup,shutdown}_phy() helpers
authorPatrice Chotard <patrice.chotard@foss.st.com>
Tue, 6 Sep 2022 06:15:26 +0000 (08:15 +0200)
committerMarek Vasut <marex@denx.de>
Mon, 10 Oct 2022 16:08:18 +0000 (18:08 +0200)
In drivers usb/host/{ehci,ohci}-generic.c, {ehci,ohci}_setup_phy() and
{ehci,ohci}_shutdown_phy() shares 95% of common code.
Factorize this code in new generic_{setup,shudown}_phy() functions.

Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Simon Glass <sjg@chromium.org>
drivers/phy/phy-uclass.c
include/generic-phy.h

index 8b84da3ce0da48bb87418916d34dad77fae96037..3fef5135a9cbe8df97b6438550f4ffa7adabcf95 100644 (file)
@@ -455,6 +455,48 @@ int generic_phy_power_off_bulk(struct phy_bulk *bulk)
        return ret;
 }
 
+int generic_setup_phy(struct udevice *dev, struct phy *phy, int index)
+{
+       int ret = 0;
+
+       if (!phy)
+               return 0;
+
+       ret = generic_phy_get_by_index(dev, index, phy);
+       if (ret) {
+               if (ret != -ENOENT)
+                       return ret;
+       } else {
+               ret = generic_phy_init(phy);
+               if (ret)
+                       return ret;
+
+               ret = generic_phy_power_on(phy);
+               if (ret)
+                       ret = generic_phy_exit(phy);
+       }
+
+       return ret;
+}
+
+int generic_shutdown_phy(struct phy *phy)
+{
+       int ret = 0;
+
+       if (!phy)
+               return 0;
+
+       if (generic_phy_valid(phy)) {
+               ret = generic_phy_power_off(phy);
+               if (ret)
+                       return ret;
+
+               ret = generic_phy_exit(phy);
+       }
+
+       return ret;
+}
+
 UCLASS_DRIVER(phy) = {
        .id             = UCLASS_PHY,
        .name           = "phy",
index d40ce589b6450f6198a2f9ed1dd1bbb1c72537dc..f8eddeff67aeb0e52332879d887b7c6544c21cd4 100644 (file)
@@ -342,6 +342,26 @@ int generic_phy_power_on_bulk(struct phy_bulk *bulk);
  */
 int generic_phy_power_off_bulk(struct phy_bulk *bulk);
 
+/**
+ * generic_setup_phy() - Get, initialize and power on phy.
+ *
+ * @dev:       The consumer device.
+ * @phy:       A pointer to the PHY port
+ * @index:     The index in the list of available PHYs
+ *
+ * Return: 0 if OK, or negative error code.
+ */
+int generic_setup_phy(struct udevice *dev, struct phy *phy, int index);
+
+/**
+ * generic_shutdown_phy() - Power off and de-initialize phy.
+ *
+ * @phy:       A pointer to the PHY port.
+ *
+ * Return: 0 if OK, or negative error code.
+ */
+int generic_shutdown_phy(struct phy *phy);
+
 #else /* CONFIG_PHY */
 
 static inline int generic_phy_init(struct phy *phy)
@@ -407,6 +427,16 @@ static inline int generic_phy_power_off_bulk(struct phy_bulk *bulk)
        return 0;
 }
 
+static inline int generic_setup_phy(struct udevice *dev, struct phy *phy, int index)
+{
+       return 0;
+}
+
+static inline int generic_shutdown_phy(struct phy *phy)
+{
+       return 0;
+}
+
 #endif /* CONFIG_PHY */
 
 /**