static int dwc3_suspend(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); unsigned long flags; spin_lock_irqsave(&dwc->lock, flags); switch (dwc->dr_mode) { case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_OTG: dwc3_gadget_suspend(dwc); /* FALLTHROUGH */ case USB_DR_MODE_HOST: default: dwc3_event_buffers_cleanup(dwc); break; } dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL); spin_unlock_irqrestore(&dwc->lock, flags); usb_phy_shutdown(dwc->usb3_phy); usb_phy_shutdown(dwc->usb2_phy); phy_exit(dwc->usb2_generic_phy); phy_exit(dwc->usb3_generic_phy); usb_phy_set_suspend(dwc->usb2_phy, 1); usb_phy_set_suspend(dwc->usb3_phy, 1); WARN_ON(phy_power_off(dwc->usb2_generic_phy) < 0); WARN_ON(phy_power_off(dwc->usb3_generic_phy) < 0); pinctrl_pm_select_sleep_state(dev); return 0; }
static int dwc3_suspend(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); unsigned long flags; spin_lock_irqsave(&dwc->lock, flags); switch (dwc->dr_mode) { case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_OTG: dwc3_gadget_suspend(dwc); /* FALLTHROUGH */ case USB_DR_MODE_HOST: default: /* do nothing */ break; } dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL); spin_unlock_irqrestore(&dwc->lock, flags); usb_phy_shutdown(dwc->usb3_phy); usb_phy_shutdown(dwc->usb2_phy); phy_exit(dwc->usb2_generic_phy); phy_exit(dwc->usb3_generic_phy); return 0; }
static int dra7xx_pcie_resume_noirq(struct device *dev) { struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev); int phy_count = dra7xx->phy_count; int ret; int i; for (i = 0; i < phy_count; i++) { ret = phy_init(dra7xx->phy[i]); if (ret < 0) goto err_phy; ret = phy_power_on(dra7xx->phy[i]); if (ret < 0) { phy_exit(dra7xx->phy[i]); goto err_phy; } } return 0; err_phy: while (--i >= 0) { phy_power_off(dra7xx->phy[i]); phy_exit(dra7xx->phy[i]); } return ret; }
static void dwc3_core_exit(struct dwc3 *dwc) { dwc3_free_scratch_buffers(dwc); usb_phy_shutdown(dwc->usb2_phy); usb_phy_shutdown(dwc->usb3_phy); phy_exit(dwc->usb2_generic_phy); phy_exit(dwc->usb3_generic_phy); }
/** * dwc3_core_soft_reset - Issues core soft reset and PHY reset * @dwc: pointer to our context structure */ static int dwc3_core_soft_reset(struct dwc3 *dwc) { u32 reg; int retries = 1000; int ret; usb_phy_init(dwc->usb2_phy); usb_phy_init(dwc->usb3_phy); ret = phy_init(dwc->usb2_generic_phy); if (ret < 0) return ret; ret = phy_init(dwc->usb3_generic_phy); if (ret < 0) { phy_exit(dwc->usb2_generic_phy); return ret; } /* * We're resetting only the device side because, if we're in host mode, * XHCI driver will reset the host block. If dwc3 was configured for * host-only mode, then we can return early. */ if (dwc->dr_mode == USB_DR_MODE_HOST || dwc->is_hibernated == true) return 0; if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST) return 0; reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg |= DWC3_DCTL_CSFTRST; dwc3_writel(dwc->regs, DWC3_DCTL, reg); do { reg = dwc3_readl(dwc->regs, DWC3_DCTL); if (!(reg & DWC3_DCTL_CSFTRST)) goto done; udelay(1); } while (--retries); phy_exit(dwc->usb3_generic_phy); phy_exit(dwc->usb2_generic_phy); return -ETIMEDOUT; done: /* * For DWC_usb31 controller, once DWC3_DCTL_CSFTRST bit is cleared, * we must wait at least 50ms before accessing the PHY domain * (synchronization delay). DWC_usb31 programming guide section 1.3.2. */ if (dwc3_is_usb31(dwc)) msleep(50); return 0; }
static void dwc3_core_exit(struct dwc3 *dwc) { dwc3_event_buffers_cleanup(dwc); usb_phy_shutdown(dwc->usb2_phy); usb_phy_shutdown(dwc->usb3_phy); phy_exit(dwc->usb2_generic_phy); phy_exit(dwc->usb3_generic_phy); usb_phy_set_suspend(dwc->usb2_phy, 1); usb_phy_set_suspend(dwc->usb3_phy, 1); phy_power_off(dwc->usb2_generic_phy); phy_power_off(dwc->usb3_generic_phy); }
static void dwc3_core_exit(struct dwc3 *dwc) { usb_phy_shutdown(dwc->usb2_phy); usb_phy_shutdown(dwc->usb3_phy); phy_exit(dwc->usb2_generic_phy); phy_exit(dwc->usb3_generic_phy); usb_phy_set_suspend(dwc->usb2_phy, 1); usb_phy_set_suspend(dwc->usb3_phy, 1); phy_power_off(dwc->usb2_generic_phy); phy_power_off(dwc->usb3_generic_phy); clk_bulk_disable(dwc->num_clks, dwc->clks); clk_bulk_unprepare(dwc->num_clks, dwc->clks); reset_control_assert(dwc->reset); }
static int ohci_da8xx_enable(struct usb_hcd *hcd) { struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); int ret; ret = clk_prepare_enable(da8xx_ohci->usb11_clk); if (ret) return ret; ret = phy_init(da8xx_ohci->usb11_phy); if (ret) goto err_phy_init; ret = phy_power_on(da8xx_ohci->usb11_phy); if (ret) goto err_phy_power_on; return 0; err_phy_power_on: phy_exit(da8xx_ohci->usb11_phy); err_phy_init: clk_disable_unprepare(da8xx_ohci->usb11_clk); return ret; }
static int __dwc2_lowlevel_hw_disable(struct dwc2_hsotg *hsotg) { struct platform_device *pdev = to_platform_device(hsotg->dev); int ret = 0; if (hsotg->uphy) { usb_phy_shutdown(hsotg->uphy); } else if (hsotg->plat && hsotg->plat->phy_exit) { ret = hsotg->plat->phy_exit(pdev, hsotg->plat->phy_type); } else { ret = phy_exit(hsotg->phy); if (ret == 0) ret = phy_power_off(hsotg->phy); } if (ret) return ret; if (hsotg->clk) clk_disable_unprepare(hsotg->clk); ret = regulator_bulk_disable(ARRAY_SIZE(hsotg->supplies), hsotg->supplies); return ret; }
static int da8xx_musb_init(struct musb *musb) { struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); void __iomem *reg_base = musb->ctrl_base; u32 rev; int ret = -ENODEV; musb->mregs += DA8XX_MENTOR_CORE_OFFSET; ret = clk_prepare_enable(glue->clk); if (ret) { dev_err(glue->dev, "failed to enable clock\n"); return ret; } /* Returns zero if e.g. not clocked */ rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG); if (!rev) goto fail; musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); if (IS_ERR_OR_NULL(musb->xceiv)) { ret = -EPROBE_DEFER; goto fail; } setup_timer(&otg_workaround, otg_timer, (unsigned long)musb); /* Reset the controller */ musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); /* Start the on-chip PHY and its PLL. */ ret = phy_init(glue->phy); if (ret) { dev_err(glue->dev, "Failed to init phy.\n"); goto fail; } ret = phy_power_on(glue->phy); if (ret) { dev_err(glue->dev, "Failed to power on phy.\n"); goto err_phy_power_on; } msleep(5); /* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */ pr_debug("DA8xx OTG revision %08x, control %02x\n", rev, musb_readb(reg_base, DA8XX_USB_CTRL_REG)); musb->isr = da8xx_musb_interrupt; return 0; err_phy_power_on: phy_exit(glue->phy); fail: clk_disable_unprepare(glue->clk); return ret; }
static void ohci_da8xx_disable(struct usb_hcd *hcd) { struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd); phy_power_off(da8xx_ohci->usb11_phy); phy_exit(da8xx_ohci->usb11_phy); clk_disable_unprepare(da8xx_ohci->usb11_clk); }
static int omap2430_musb_exit(struct musb *musb) { del_timer_sync(&musb_idle_timer); omap2430_low_level_exit(musb); phy_exit(musb->phy); return 0; }
static int ssusb_phy_exit(struct ssusb_mtk *ssusb) { int i; for (i = 0; i < ssusb->num_phys; i++) phy_exit(ssusb->phys[i]); return 0; }
static int xhci_mtk_phy_exit(struct xhci_hcd_mtk *mtk) { int i; for (i = 0; i < mtk->num_phys; i++) phy_exit(mtk->phys[i]); return 0; }
int iproc_pcie_remove(struct iproc_pcie *pcie) { pci_stop_root_bus(pcie->root_bus); pci_remove_root_bus(pcie->root_bus); phy_power_off(pcie->phy); phy_exit(pcie->phy); return 0; }
static int histb_pcie_remove(struct platform_device *pdev) { struct histb_pcie *hipcie = platform_get_drvdata(pdev); histb_pcie_host_disable(hipcie); if (hipcie->phy) phy_exit(hipcie->phy); return 0; }
/** * ahci_platform_disable_resources - Disable platform resources * @hpriv: host private area to store config values * * This function disables all ahci_platform managed resources in the * following order: * 1) Phy * 2) Clocks (through ahci_platform_disable_clks) * 3) Regulator */ void ahci_platform_disable_resources(struct ahci_host_priv *hpriv) { if (hpriv->phy) { phy_power_off(hpriv->phy); phy_exit(hpriv->phy); } ahci_platform_disable_clks(hpriv); if (hpriv->target_pwr) regulator_disable(hpriv->target_pwr); }
static int dsps_musb_exit(struct musb *musb) { struct device *dev = musb->controller; struct dsps_glue *glue = dev_get_drvdata(dev->parent); del_timer_sync(&musb->dev_timer); phy_power_off(musb->phy); phy_exit(musb->phy); debugfs_remove_recursive(glue->dbgfs_root); return 0; }
static int dra7xx_pcie_suspend_noirq(struct device *dev) { struct dra7xx_pcie *dra7xx = dev_get_drvdata(dev); int count = dra7xx->phy_count; while (count--) { phy_power_off(dra7xx->phy[count]); phy_exit(dra7xx->phy[count]); } return 0; }
static int ehci_platform_power_on(struct platform_device *dev) { struct usb_hcd *hcd = platform_get_drvdata(dev); struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); int clk, ret, phy_num; for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) { ret = clk_prepare_enable(priv->clks[clk]); if (ret) goto err_disable_clks; } for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { if (priv->phys[phy_num]) { ret = phy_init(priv->phys[phy_num]); if (ret) goto err_exit_phy; ret = phy_power_on(priv->phys[phy_num]); if (ret) { phy_exit(priv->phys[phy_num]); goto err_exit_phy; } } } return 0; err_exit_phy: while (--phy_num >= 0) { if (priv->phys[phy_num]) { phy_power_off(priv->phys[phy_num]); phy_exit(priv->phys[phy_num]); } } err_disable_clks: while (--clk >= 0) clk_disable_unprepare(priv->clks[clk]); return ret; }
/** * dwc3_core_soft_reset - Issues core soft reset and PHY reset * @dwc: pointer to our context structure */ static int dwc3_core_soft_reset(struct dwc3 *dwc) { u32 reg; int ret; /* Before Resetting PHY, put Core in Reset */ reg = dwc3_readl(dwc->regs, DWC3_GCTL); reg |= DWC3_GCTL_CORESOFTRESET; dwc3_writel(dwc->regs, DWC3_GCTL, reg); /* Assert USB3 PHY reset */ reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST; dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); /* Assert USB2 PHY reset */ reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST; dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); usb_phy_init(dwc->usb2_phy); usb_phy_init(dwc->usb3_phy); ret = phy_init(dwc->usb2_generic_phy); if (ret < 0) return ret; ret = phy_init(dwc->usb3_generic_phy); if (ret < 0) { phy_exit(dwc->usb2_generic_phy); return ret; } mdelay(100); /* Clear USB3 PHY reset */ reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST; dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); /* Clear USB2 PHY reset */ reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST; dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); mdelay(100); /* After PHYs are stable we can take Core out of reset state */ reg = dwc3_readl(dwc->regs, DWC3_GCTL); reg &= ~DWC3_GCTL_CORESOFTRESET; dwc3_writel(dwc->regs, DWC3_GCTL, reg); return 0; }
static int omap2430_musb_exit(struct musb *musb) { struct device *dev = musb->controller; struct omap2430_glue *glue = dev_get_drvdata(dev->parent); omap2430_low_level_exit(musb); phy_power_off(musb->phy); phy_exit(musb->phy); musb->phy = NULL; cancel_work_sync(&glue->omap_musb_mailbox_work); return 0; }
static int da8xx_musb_exit(struct musb *musb) { struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent); del_timer_sync(&otg_workaround); phy_power_off(glue->phy); phy_exit(glue->phy); clk_disable_unprepare(glue->clk); usb_put_phy(musb->xceiv); return 0; }
static int st_ehci_platform_power_on(struct platform_device *dev) { struct usb_hcd *hcd = platform_get_drvdata(dev); struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); int clk, ret; ret = reset_control_deassert(priv->pwr); if (ret) return ret; ret = reset_control_deassert(priv->rst); if (ret) goto err_assert_power; /* some SoCs don't have a dedicated 48Mhz clock, but those that do need the rate to be explicitly set */ if (priv->clk48) { ret = clk_set_rate(priv->clk48, 48000000); if (ret) goto err_assert_reset; } for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) { ret = clk_prepare_enable(priv->clks[clk]); if (ret) goto err_disable_clks; } ret = phy_init(priv->phy); if (ret) goto err_disable_clks; ret = phy_power_on(priv->phy); if (ret) goto err_exit_phy; return 0; err_exit_phy: phy_exit(priv->phy); err_disable_clks: while (--clk >= 0) clk_disable_unprepare(priv->clks[clk]); err_assert_reset: reset_control_assert(priv->rst); err_assert_power: reset_control_assert(priv->pwr); return ret; }
static void ehci_platform_power_off(struct platform_device *dev) { struct usb_hcd *hcd = platform_get_drvdata(dev); struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); int clk, phy_num; for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { phy_power_off(priv->phys[phy_num]); phy_exit(priv->phys[phy_num]); } for (clk = EHCI_MAX_CLKS - 1; clk >= 0; clk--) if (priv->clks[clk]) clk_disable_unprepare(priv->clks[clk]); }
static int dwc3_resume(struct device *dev) { struct dwc3 *dwc = dev_get_drvdata(dev); unsigned long flags; int ret; pinctrl_pm_select_default_state(dev); usb_phy_init(dwc->usb3_phy); usb_phy_init(dwc->usb2_phy); ret = phy_init(dwc->usb2_generic_phy); if (ret < 0) return ret; ret = phy_init(dwc->usb3_generic_phy); if (ret < 0) goto err_usb2phy_init; spin_lock_irqsave(&dwc->lock, flags); dwc3_event_buffers_setup(dwc); dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl); switch (dwc->dr_mode) { case USB_DR_MODE_PERIPHERAL: case USB_DR_MODE_OTG: dwc3_gadget_resume(dwc); /* FALLTHROUGH */ case USB_DR_MODE_HOST: default: /* do nothing */ break; } spin_unlock_irqrestore(&dwc->lock, flags); pm_runtime_disable(dev); pm_runtime_set_active(dev); pm_runtime_enable(dev); return 0; err_usb2phy_init: phy_exit(dwc->usb2_generic_phy); return ret; }
static int xhci_mtk_phy_init(struct xhci_hcd_mtk *mtk) { int i; int ret; for (i = 0; i < mtk->num_phys; i++) { ret = phy_init(mtk->phys[i]); if (ret) goto exit_phy; } return 0; exit_phy: for (; i > 0; i--) phy_exit(mtk->phys[i - 1]); return ret; }
static int ssusb_phy_init(struct ssusb_mtk *ssusb) { int i; int ret; for (i = 0; i < ssusb->num_phys; i++) { ret = phy_init(ssusb->phys[i]); if (ret) goto exit_phy; } return 0; exit_phy: for (; i > 0; i--) phy_exit(ssusb->phys[i - 1]); return ret; }
static int __exit dra7xx_pcie_remove(struct platform_device *pdev) { struct dra7xx_pcie *dra7xx = platform_get_drvdata(pdev); struct pcie_port *pp = &dra7xx->pp; struct device *dev = &pdev->dev; int count = dra7xx->phy_count; if (pp->irq_domain) irq_domain_remove(pp->irq_domain); pm_runtime_put(dev); pm_runtime_disable(dev); while (count--) { phy_power_off(dra7xx->phy[count]); phy_exit(dra7xx->phy[count]); } return 0; }
static int omap2430_runtime_suspend(struct device *dev) { struct omap2430_glue *glue = dev_get_drvdata(dev); struct musb *musb = glue_to_musb(glue); if (!musb) return 0; musb->context.otg_interfsel = musb_readl(musb->mregs, OTG_INTERFSEL); omap2430_low_level_exit(musb); phy_power_off(musb->phy); phy_exit(musb->phy); return 0; }