]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/usb/musb-new/sunxi.c
sunxi: musb: Move vbus check to sunxi_musb_enable
[karo-tx-uboot.git] / drivers / usb / musb-new / sunxi.c
index 90aaec60d51e2a1dde5da5fd13ba87561baa1681..ee018c7e6e76751248962430f54bf8bec59b8d80 100644 (file)
@@ -22,8 +22,9 @@
  */
 #include <common.h>
 #include <asm/arch/cpu.h>
+#include <asm/arch/clock.h>
 #include <asm/arch/gpio.h>
-#include <asm/arch/usbc.h>
+#include <asm/arch/usb_phy.h>
 #include <asm-generic/gpio.h>
 #include "linux-compat.h"
 #include "musb_core.h"
@@ -104,16 +105,6 @@ static void USBC_EnableIdPullUp(__iomem void *base)
        musb_writel(base, USBC_REG_o_ISCR, reg_val);
 }
 
-static void USBC_DisableIdPullUp(__iomem void *base)
-{
-       u32 reg_val;
-
-       reg_val = musb_readl(base, USBC_REG_o_ISCR);
-       reg_val &= ~(1 << USBC_BP_ISCR_ID_PULLUP_EN);
-       reg_val = USBC_WakeUp_ClearChangeDetect(reg_val);
-       musb_writel(base, USBC_REG_o_ISCR, reg_val);
-}
-
 static void USBC_EnableDpDmPullUp(__iomem void *base)
 {
        u32 reg_val;
@@ -124,34 +115,35 @@ static void USBC_EnableDpDmPullUp(__iomem void *base)
        musb_writel(base, USBC_REG_o_ISCR, reg_val);
 }
 
-static void USBC_DisableDpDmPullUp(__iomem void *base)
+static void USBC_ForceIdToLow(__iomem void *base)
 {
        u32 reg_val;
 
        reg_val = musb_readl(base, USBC_REG_o_ISCR);
-       reg_val &= ~(1 << USBC_BP_ISCR_DPDM_PULLUP_EN);
+       reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_ID);
+       reg_val |= (0x02 << USBC_BP_ISCR_FORCE_ID);
        reg_val = USBC_WakeUp_ClearChangeDetect(reg_val);
        musb_writel(base, USBC_REG_o_ISCR, reg_val);
 }
 
-static void USBC_ForceIdToLow(__iomem void *base)
+static void USBC_ForceIdToHigh(__iomem void *base)
 {
        u32 reg_val;
 
        reg_val = musb_readl(base, USBC_REG_o_ISCR);
        reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_ID);
-       reg_val |= (0x02 << USBC_BP_ISCR_FORCE_ID);
+       reg_val |= (0x03 << USBC_BP_ISCR_FORCE_ID);
        reg_val = USBC_WakeUp_ClearChangeDetect(reg_val);
        musb_writel(base, USBC_REG_o_ISCR, reg_val);
 }
 
-static void USBC_ForceIdToHigh(__iomem void *base)
+static void USBC_ForceVbusValidToLow(__iomem void *base)
 {
        u32 reg_val;
 
        reg_val = musb_readl(base, USBC_REG_o_ISCR);
-       reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_ID);
-       reg_val |= (0x03 << USBC_BP_ISCR_FORCE_ID);
+       reg_val &= ~(0x03 << USBC_BP_ISCR_FORCE_VBUS_VALID);
+       reg_val |= (0x02 << USBC_BP_ISCR_FORCE_VBUS_VALID);
        reg_val = USBC_WakeUp_ClearChangeDetect(reg_val);
        musb_writel(base, USBC_REG_o_ISCR, reg_val);
 }
@@ -204,85 +196,65 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void *__hci)
        return retval;
 }
 
-static void sunxi_musb_enable(struct musb *musb)
+/* musb_core does not call enable / disable in a balanced manner <sigh> */
+static bool enabled = false;
+
+static int sunxi_musb_enable(struct musb *musb)
 {
+       int ret;
+
        pr_debug("%s():\n", __func__);
 
+       if (enabled)
+               return 0;
+
        /* select PIO mode */
        musb_writeb(musb->mregs, USBC_REG_o_VEND0, 0);
 
        if (is_host_enabled(musb)) {
-               /* port power on */
-               sunxi_usbc_vbus_enable(0);
+               ret = sunxi_usb_phy_vbus_detect(0);
+               if (ret) {
+                       printf("A charger is plugged into the OTG: ");
+                       return -ENODEV;
+               }
+               sunxi_usb_phy_power_on(0); /* port power on */
        }
+
+       USBC_ForceVbusValidToHigh(musb->mregs);
+
+       enabled = true;
+       return 0;
 }
 
 static void sunxi_musb_disable(struct musb *musb)
 {
        pr_debug("%s():\n", __func__);
 
-       /* Put the controller back in a pristane state for "usb reset" */
-       if (musb->is_active) {
-               sunxi_usbc_disable(0);
-               sunxi_usbc_enable(0);
-               musb->is_active = 0;
-       }
+       if (!enabled)
+               return;
+
+       if (is_host_enabled(musb))
+               sunxi_usb_phy_power_off(0); /* port power off */
+
+       USBC_ForceVbusValidToLow(musb->mregs);
+       mdelay(200); /* Wait for the current session to timeout */
+
+       enabled = false;
 }
 
 static int sunxi_musb_init(struct musb *musb)
 {
-       int err;
+       struct sunxi_ccm_reg *ccm = (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
 
        pr_debug("%s():\n", __func__);
 
-       if (is_host_enabled(musb)) {
-               int vbus_det = sunxi_name_to_gpio(CONFIG_USB0_VBUS_DET);
-
-#ifdef AXP_VBUS_DETECT
-               if (!strcmp(CONFIG_USB0_VBUS_DET, "axp_vbus_detect")) {
-                       err = axp_get_vbus();
-                       if (err < 0)
-                               return err;
-               } else {
-#endif
-                       if (vbus_det == -1) {
-                               eprintf("Error invalid Vusb-det pin\n");
-                               return -EINVAL;
-                       }
-
-                       err = gpio_request(vbus_det, "vbus0_det");
-                       if (err)
-                               return err;
-
-                       err = gpio_direction_input(vbus_det);
-                       if (err) {
-                               gpio_free(vbus_det);
-                               return err;
-                       }
-
-                       err = gpio_get_value(vbus_det);
-                       if (err < 0) {
-                               gpio_free(vbus_det);
-                               return -EIO;
-                       }
-
-                       gpio_free(vbus_det);
-#ifdef AXP_VBUS_DETECT
-               }
-#endif
-
-               if (err) {
-                       eprintf("Error: A charger is plugged into the OTG\n");
-                       return -EIO;
-               }
-       }
-
-       err = sunxi_usbc_request_resources(0);
-       if (err)
-               return err;
-
        musb->isr = sunxi_musb_interrupt;
-       sunxi_usbc_enable(0);
+
+       setbits_le32(&ccm->ahb_gate0, 1 << AHB_GATE_OFFSET_USB0);
+#ifdef CONFIG_SUNXI_GEN_SUN6I
+       setbits_le32(&ccm->ahb_reset0_cfg, 1 << AHB_GATE_OFFSET_USB0);
+#endif
+       sunxi_usb_phy_init(0);
 
        USBC_ConfigFIFO_Base();
        USBC_EnableDpDmPullUp(musb->mregs);
@@ -300,22 +272,8 @@ static int sunxi_musb_init(struct musb *musb)
        return 0;
 }
 
-static int sunxi_musb_exit(struct musb *musb)
-{
-       pr_debug("%s():\n", __func__);
-
-       USBC_DisableDpDmPullUp(musb->mregs);
-       USBC_DisableIdPullUp(musb->mregs);
-       sunxi_usbc_vbus_disable(0);
-       sunxi_usbc_disable(0);
-
-       return sunxi_usbc_free_resources(0);
-}
-
 const struct musb_platform_ops sunxi_musb_ops = {
        .init           = sunxi_musb_init,
-       .exit           = sunxi_musb_exit,
-
        .enable         = sunxi_musb_enable,
        .disable        = sunxi_musb_disable,
 };