usb: dwc3: use the phy bulk API to get phys
authorChunfeng Yun <chunfeng.yun@mediatek.com>
Sat, 2 May 2020 09:35:13 +0000 (11:35 +0200)
committerMarek Vasut <marek.vasut+renesas@gmail.com>
Sat, 2 May 2020 10:32:28 +0000 (12:32 +0200)
Get a group of phys by the phy bulk API

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Reviewed-by: Weijie Gao <weijie.gao@mediatek.com>
drivers/usb/dwc3/core.c
drivers/usb/dwc3/dwc3-generic.c
drivers/usb/host/xhci-dwc3.c
include/dwc3-uboot.h

index 4ec3f6df6a9a8130704e47c73bc193ea2e3c2bc4..a8982bdc0946285c7cd7f2b74c00cd386910665f 100644 (file)
@@ -838,87 +838,32 @@ MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
 
 #if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB)
-int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys)
+int dwc3_setup_phy(struct udevice *dev, struct phy_bulk *phys)
 {
-       int i, ret, count;
-       struct phy *usb_phys;
-
-       /* Return if no phy declared */
-       if (!dev_read_prop(dev, "phys", NULL))
-               return 0;
-       count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
-       if (count <= 0)
-               return count;
-
-       usb_phys = devm_kcalloc(dev, count, sizeof(struct phy),
-                               GFP_KERNEL);
-       if (!usb_phys)
-               return -ENOMEM;
-
-       for (i = 0; i < count; i++) {
-               ret = generic_phy_get_by_index(dev, i, &usb_phys[i]);
-               if (ret && ret != -ENOENT) {
-                       pr_err("Failed to get USB PHY%d for %s\n",
-                              i, dev->name);
-                       return ret;
-               }
-       }
-
-       for (i = 0; i < count; i++) {
-               ret = generic_phy_init(&usb_phys[i]);
-               if (ret) {
-                       pr_err("Can't init USB PHY%d for %s\n",
-                              i, dev->name);
-                       goto phys_init_err;
-               }
-       }
-
-       for (i = 0; i < count; i++) {
-               ret = generic_phy_power_on(&usb_phys[i]);
-               if (ret) {
-                       pr_err("Can't power USB PHY%d for %s\n",
-                              i, dev->name);
-                       goto phys_poweron_err;
-               }
-       }
-
-       *array = usb_phys;
-       *num_phys =  count;
-       return 0;
-
-phys_poweron_err:
-       for (i = count - 1; i >= 0; i--)
-               generic_phy_power_off(&usb_phys[i]);
+       int ret;
 
-       for (i = 0; i < count; i++)
-               generic_phy_exit(&usb_phys[i]);
+       ret = generic_phy_get_bulk(dev, phys);
+       if (ret)
+               return ret;
 
-       return ret;
+       ret = generic_phy_init_bulk(phys);
+       if (ret)
+               return ret;
 
-phys_init_err:
-       for (; i >= 0; i--)
-               generic_phy_exit(&usb_phys[i]);
+       ret = generic_phy_power_on_bulk(phys);
+       if (ret)
+               generic_phy_exit_bulk(phys);
 
        return ret;
 }
 
-int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys)
+int dwc3_shutdown_phy(struct udevice *dev, struct phy_bulk *phys)
 {
-       int i, ret;
-
-       for (i = 0; i < num_phys; i++) {
-               if (!generic_phy_valid(&usb_phys[i]))
-                       continue;
-
-               ret = generic_phy_power_off(&usb_phys[i]);
-               ret |= generic_phy_exit(&usb_phys[i]);
-               if (ret) {
-                       pr_err("Can't shutdown USB PHY%d for %s\n",
-                              i, dev->name);
-               }
-       }
+       int ret;
 
-       return 0;
+       ret = generic_phy_power_off_bulk(phys);
+       ret |= generic_phy_exit_bulk(phys);
+       return ret;
 }
 #endif
 
index febcfc0f54c48e80ba932c351de1565ab3d7b60f..eabd53a36dc9e85bf1c2319b60e9ab2daa8011da 100644 (file)
@@ -33,8 +33,7 @@ struct dwc3_generic_plat {
 struct dwc3_generic_priv {
        void *base;
        struct dwc3 dwc3;
-       struct phy *phys;
-       int num_phys;
+       struct phy_bulk phys;
 };
 
 struct dwc3_generic_host_priv {
@@ -56,7 +55,7 @@ static int dwc3_generic_probe(struct udevice *dev,
        dwc3_of_parse(dwc3);
 #endif
 
-       rc = dwc3_setup_phy(dev, &priv->phys, &priv->num_phys);
+       rc = dwc3_setup_phy(dev, &priv->phys);
        if (rc)
                return rc;
 
@@ -79,7 +78,7 @@ static int dwc3_generic_remove(struct udevice *dev,
        struct dwc3 *dwc3 = &priv->dwc3;
 
        dwc3_remove(dwc3);
-       dwc3_shutdown_phy(dev, priv->phys, priv->num_phys);
+       dwc3_shutdown_phy(dev, &priv->phys);
        unmap_physmem(dwc3->regs, MAP_NOCACHE);
 
        return 0;
index 9fcfa39d4b5afdac9be67d91172e6b838f8b4913..563db1a4260508a4100be763cac8de624a19ad8e 100644 (file)
@@ -19,8 +19,7 @@
 #include <linux/usb/otg.h>
 
 struct xhci_dwc3_platdata {
-       struct phy *usb_phys;
-       int num_phys;
+       struct phy_bulk *usb_phys;
 };
 
 void dwc3_set_mode(struct dwc3 *dwc3_reg, u32 mode)
@@ -125,7 +124,7 @@ static int xhci_dwc3_probe(struct udevice *dev)
        hcor = (struct xhci_hcor *)((uintptr_t)hccr +
                        HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
 
-       ret = dwc3_setup_phy(dev, &plat->usb_phys, &plat->num_phys);
+       ret = dwc3_setup_phy(dev, plat->usb_phys);
        if (ret && (ret != -ENOTSUPP))
                return ret;
 
@@ -168,7 +167,7 @@ static int xhci_dwc3_remove(struct udevice *dev)
 {
        struct xhci_dwc3_platdata *plat = dev_get_platdata(dev);
 
-       dwc3_shutdown_phy(dev, plat->usb_phys, plat->num_phys);
+       dwc3_shutdown_phy(dev, plat->usb_phys);
 
        return xhci_deregister(dev);
 }
index 3c9e204cf0705bfdd6aed4e8e2fbf765ce9e82e1..ce835fd1b2b11ec7fe018d9b2081ba8d8c04480a 100644 (file)
@@ -9,6 +9,7 @@
 #ifndef __DWC3_UBOOT_H_
 #define __DWC3_UBOOT_H_
 
+#include <generic-phy.h>
 #include <linux/usb/otg.h>
 #include <linux/usb/phy.h>
 
@@ -43,17 +44,15 @@ void dwc3_uboot_handle_interrupt(int index);
 
 struct phy;
 #if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB)
-int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys);
-int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys);
+int dwc3_setup_phy(struct udevice *dev, struct phy_bulk *phys);
+int dwc3_shutdown_phy(struct udevice *dev, struct phy_bulk *phys);
 #else
-static inline int dwc3_setup_phy(struct udevice *dev, struct phy **array,
-                                int *num_phys)
+static inline int dwc3_setup_phy(struct udevice *dev, struct phy_bulk *phys)
 {
        return -ENOTSUPP;
 }
 
-static inline int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys,
-                                   int num_phys)
+static inline int dwc3_shutdown_phy(struct udevice *dev, struct phy_bulk *phys)
 {
        return -ENOTSUPP;
 }