]> git.sur5r.net Git - u-boot/commitdiff
usb: xhci-dwc3: Refractor PHY operations into separate function
authorVignesh R <vigneshr@ti.com>
Wed, 7 Mar 2018 09:20:09 +0000 (14:50 +0530)
committerMarek Vasut <marex@denx.de>
Sat, 17 Mar 2018 02:19:08 +0000 (03:19 +0100)
Refractor PHY get/init/poweron and PHY poweroff/exit operations into
separate function so that its easy to support multiple PHYs.

Signed-off-by: Vignesh R <vigneshr@ti.com>
drivers/usb/host/xhci-dwc3.c

index cf1986bebd07cc8cb047d8c1ff48024f3934f6f0..e61a04eeb8a8e87018697b1cd762707eb8435d66 100644 (file)
@@ -112,39 +112,69 @@ void dwc3_set_fladj(struct dwc3 *dwc3_reg, u32 val)
 }
 
 #ifdef CONFIG_DM_USB
-static int xhci_dwc3_probe(struct udevice *dev)
+static int xhci_dwc3_setup_phy(struct udevice *dev, int index, struct phy *phy)
 {
-       struct xhci_dwc3_platdata *plat = dev_get_platdata(dev);
-       struct xhci_hcor *hcor;
-       struct xhci_hccr *hccr;
-       struct dwc3 *dwc3_reg;
-       enum usb_dr_mode dr_mode;
-       int ret;
-
-       hccr = (struct xhci_hccr *)((uintptr_t)dev_read_addr(dev));
-       hcor = (struct xhci_hcor *)((uintptr_t)hccr +
-                       HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
+       int ret = 0;
 
-       ret = generic_phy_get_by_index(dev, 0, &plat->usb_phy);
+       ret = generic_phy_get_by_index(dev, index, phy);
        if (ret) {
                if (ret != -ENOENT) {
                        pr_err("Failed to get USB PHY for %s\n", dev->name);
                        return ret;
                }
        } else {
-               ret = generic_phy_init(&plat->usb_phy);
+               ret = generic_phy_init(phy);
                if (ret) {
                        pr_err("Can't init USB PHY for %s\n", dev->name);
                        return ret;
                }
-
-               ret = generic_phy_power_on(&plat->usb_phy);
+               ret = generic_phy_power_on(phy);
                if (ret) {
                        pr_err("Can't power on USB PHY for %s\n", dev->name);
+                       generic_phy_exit(phy);
                        return ret;
                }
        }
 
+       return 0;
+}
+
+static int xhci_dwc3_shutdown_phy(struct phy *phy)
+{
+       int ret = 0;
+
+       if (generic_phy_valid(phy)) {
+               ret = generic_phy_power_off(phy);
+               if (ret)
+                       return ret;
+
+               ret = generic_phy_exit(phy);
+               if (ret)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int xhci_dwc3_probe(struct udevice *dev)
+{
+       struct xhci_dwc3_platdata *plat = dev_get_platdata(dev);
+       struct xhci_hcor *hcor;
+       struct xhci_hccr *hccr;
+       struct dwc3 *dwc3_reg;
+       enum usb_dr_mode dr_mode;
+       int ret;
+
+       hccr = (struct xhci_hccr *)((uintptr_t)dev_read_addr(dev));
+       hcor = (struct xhci_hcor *)((uintptr_t)hccr +
+                       HC_LENGTH(xhci_readl(&(hccr)->cr_capbase)));
+
+       ret = xhci_dwc3_setup_phy(dev, 0, &plat->usb_phy);
+       if (ret) {
+               pr_err("Failed to setup USB PHY for %s\n", dev->name);
+               return ret;
+       }
+
        dwc3_reg = (struct dwc3 *)((char *)(hccr) + DWC3_REG_OFFSET);
 
        dwc3_core_init(dwc3_reg);
@@ -164,19 +194,10 @@ static int xhci_dwc3_remove(struct udevice *dev)
        struct xhci_dwc3_platdata *plat = dev_get_platdata(dev);
        int ret;
 
-       if (generic_phy_valid(&plat->usb_phy)) {
-               ret = generic_phy_power_off(&plat->usb_phy);
-               if (ret) {
-                       pr_err("Can't poweroff USB PHY for %s\n", dev->name);
-                       return ret;
-               }
+       ret = xhci_dwc3_shutdown_phy(&plat->usb_phy);
+       if (ret)
+               pr_err("Can't shutdown USB PHY for %s\n", dev->name);
 
-               ret = generic_phy_exit(&plat->usb_phy);
-               if (ret) {
-                       pr_err("Can't deinit USB PHY for %s\n", dev->name);
-                       return ret;
-               }
-       }
 
        return xhci_deregister(dev);
 }