Merge git://git.denx.de/u-boot-nand-flash
[oweals/u-boot.git] / drivers / usb / musb-new / sunxi.c
index a146c0861fffd5145cc3de314c37e909b20f6cff..c016a0bb544dd82a86a6a6dfe780d58c5bcc426f 100644 (file)
  *
  * This file is part of the Inventra Controller Driver for Linux.
  *
- * The Inventra Controller Driver for Linux is free software; you
- * can redistribute it and/or modify it under the terms of the GNU
- * General Public License version 2 as published by the Free Software
- * Foundation.
- *
+ * SPDX-License-Identifier:    GPL-2.0
  */
 #include <common.h>
 #include <asm/arch/cpu.h>
@@ -165,6 +161,17 @@ static void USBC_ConfigFIFO_Base(void)
        writel(reg_value, SUNXI_SRAMC_BASE + 0x04);
 }
 
+/******************************************************************************
+ * Needed for the DFU polling magic
+ ******************************************************************************/
+
+static u8 last_int_usb;
+
+bool dfu_usb_get_reset(void)
+{
+       return !!(last_int_usb & MUSB_INTR_RESET);
+}
+
 /******************************************************************************
  * MUSB Glue code
  ******************************************************************************/
@@ -176,6 +183,7 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
 
        /* read and flush interrupts */
        musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB);
+       last_int_usb = musb->int_usb;
        if (musb->int_usb)
                musb_writeb(musb->mregs, MUSB_INTRUSB, musb->int_usb);
        musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX);
@@ -193,6 +201,7 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
 
 /* musb_core does not call enable / disable in a balanced manner <sigh> */
 static bool enabled = false;
+static struct musb *sunxi_musb;
 
 static int sunxi_musb_enable(struct musb *musb)
 {
@@ -312,13 +321,15 @@ int musb_usb_probe(struct udevice *dev)
 
        priv->desc_before_addr = true;
 
-       if (!host->host) {
-               host->host = musb_init_controller(&musb_plat, NULL,
+       if (!sunxi_musb) {
+               sunxi_musb = musb_init_controller(&musb_plat, NULL,
                                                  (void *)SUNXI_USB0_BASE);
-               if (!host->host)
-                       return -EIO;
        }
 
+       host->host = sunxi_musb;
+       if (!host->host)
+               return -EIO;
+
        ret = musb_lowlevel_init(host);
        if (ret == 0)
                printf("MUSB OTG\n");
@@ -329,9 +340,16 @@ int musb_usb_probe(struct udevice *dev)
 int musb_usb_remove(struct udevice *dev)
 {
        struct musb_host_data *host = dev_get_priv(dev);
+       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
 
        musb_stop(host->host);
 
+       sunxi_usb_phy_exit(0);
+#ifdef CONFIG_SUNXI_GEN_SUN6I
+       clrbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
+#endif
+       clrbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0);
+
        return 0;
 }