From: Philipp Tomsich <philipp.toms...@theobroma-systems.com>

Allwinner a64 has a shared PHY for MUSB and USB-OTG-HCI,
so add function to select the PHY route.

Signed-off-by: Philipp Tomsich <philipp.toms...@theobroma-systems.com>
[jagan: reworked for remove func support]
Signed-off-by: Jagan Teki <ja...@amarulasolutions.com>
---
 drivers/usb/musb-new/sunxi.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c
index 2e22497..45ddf20 100644
--- a/drivers/usb/musb-new/sunxi.c
+++ b/drivers/usb/musb-new/sunxi.c
@@ -45,6 +45,9 @@
 #define  USBC_REG_o_PHYCTL     0x0404
 #define  USBC_REG_o_PHYBIST    0x0408
 #define  USBC_REG_o_PHYTUNE    0x040c
+#if defined(CONFIG_MACH_SUN50I)
+#define        SUNXI_OTG_PHY_CFG       0x0420
+#endif
 
 #define  USBC_REG_o_VEND0      0x0043
 
@@ -162,6 +165,16 @@ static void USBC_ConfigFIFO_Base(void)
        writel(reg_value, SUNXI_SRAMC_BASE + 0x04);
 }
 
+#if defined(CONFIG_MACH_SUN50I)
+static void USBC_SelectPhyToDevice(__iomem void *base, bool routePHYtoOTG)
+{
+       /* The OTG and HCI0 controllers share a single PHY in the A64.
+        * Select either 'to OTG' (1) or 'to HCI' (0).
+        */
+       clrsetbits_le32(base + SUNXI_OTG_PHY_CFG, 1, routePHYtoOTG ? 1 : 0);
+}
+#endif
+
 /******************************************************************************
  * Needed for the DFU polling magic
  
******************************************************************************/
@@ -267,6 +280,9 @@ static int sunxi_musb_init(struct musb *musb)
        setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
 #endif
        sunxi_usb_phy_init(0);
+#if defined(CONFIG_MACH_SUN50I)
+       USBC_SelectPhyToDevice(musb->mregs, true);
+#endif
 
        USBC_ConfigFIFO_Base();
        USBC_EnableDpDmPullUp(musb->mregs);
@@ -342,6 +358,9 @@ static int musb_usb_remove(struct udevice *dev)
        musb_stop(host->host);
 
        sunxi_usb_phy_exit(0);
+#if defined(CONFIG_MACH_SUN50I)
+       USBC_SelectPhyToDevice(host->host->mregs, false);
+#endif
 #ifdef CONFIG_SUNXI_GEN_SUN6I
        clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
 #endif
-- 
2.7.4

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to