usb: dwc_otg_310: add rk3288 usb otg support
[firefly-linux-kernel-4.4.55.git] / drivers / usb / dwc_otg_310 / dwc_otg_driver.c
old mode 100755 (executable)
new mode 100644 (file)
index 58abce5..9905a39
@@ -68,6 +68,7 @@ static const char dwc_host20_driver_name[] = "usb20_host";
 static const char dwc_otg20_driver_name[] = "usb20_otg";
 
 dwc_otg_device_t *g_otgdev;
+void *dwc_otg_dev;
 
 extern int pcd_init(struct platform_device *_dev);
 extern int otg20_hcd_init(struct platform_device *_dev);
@@ -385,6 +386,7 @@ void dwc_otg_force_device(dwc_otg_core_if_t *core_if)
        local_irq_save(flags);
 
        if (core_if->op_state == B_PERIPHERAL) {
+               local_irq_restore(flags);
                printk
                    ("dwc_otg_force_device,already in B_PERIPHERAL,everest\n");
                return;
@@ -915,6 +917,7 @@ static int host20_driver_remove(struct platform_device *_dev)
 }
 
 static const struct of_device_id usb20_host_of_match[] = {
+#ifdef CONFIG_ARM
        {
         .compatible = "rockchip,rk3188_usb20_host",
         .data = &usb20host_pdata_rk3188,
@@ -931,6 +934,7 @@ static const struct of_device_id usb20_host_of_match[] = {
         .compatible = "rockchip,rk3126_usb20_host",
         .data = &usb20host_pdata_rk3126,
         },
+#endif
        {},
 };
 
@@ -1158,18 +1162,16 @@ static void dwc_otg_driver_shutdown(struct platform_device *_dev)
        dwc_otg_core_if_t *core_if = otg_dev->core_if;
        struct dwc_otg_platform_data *pldata = otg_dev->pldata;
        dctl_data_t dctl = {.d32 = 0 };
+       dwc_otg_pcd_t *pcd = core_if->otg_dev->pcd;
 
        DWC_PRINTF("%s: disconnect USB %s mode\n", __func__,
                   dwc_otg_is_host_mode(core_if) ? "host" : "device");
 
-       if (pldata->dwc_otg_uart_mode != NULL)
-               pldata->dwc_otg_uart_mode(pldata, PHY_USB_MODE);
-       if (pldata->phy_suspend != NULL)
-               pldata->phy_suspend(pldata, USB_PHY_ENABLED);
        if (dwc_otg_is_host_mode(core_if)) {
                if (core_if->hcd_cb && core_if->hcd_cb->stop)
                        core_if->hcd_cb->stop(core_if->hcd_cb_p);
        } else {
+               cancel_delayed_work_sync(&pcd->check_vbus_work);
                /* soft disconnect */
                dctl.d32 =
                    DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
@@ -1180,6 +1182,11 @@ static void dwc_otg_driver_shutdown(struct platform_device *_dev)
        /* Clear any pending interrupts */
        DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
 
+       if (pldata->dwc_otg_uart_mode != NULL)
+               pldata->dwc_otg_uart_mode(pldata, PHY_USB_MODE);
+       if (pldata->phy_suspend != NULL)
+               pldata->phy_suspend(pldata, USB_PHY_ENABLED);
+
 }
 
 /**
@@ -1285,6 +1292,7 @@ static int otg20_driver_remove(struct platform_device *_dev)
 }
 
 static const struct of_device_id usb20_otg_of_match[] = {
+#ifdef CONFIG_ARM
        {
         .compatible = "rockchip,rk3188_usb20_otg",
         .data = &usb20otg_pdata_rk3188,
@@ -1301,10 +1309,13 @@ static const struct of_device_id usb20_otg_of_match[] = {
         .compatible = "rockchip,rk3126_usb20_otg",
         .data = &usb20otg_pdata_rk3126,
         },
+#endif
+#ifdef CONFIG_ARM64
        {
-        .compatible = "rockchip,rk3368_usb20_otg",
+        .compatible = "rockchip,rk3368-usb",
         .data = &usb20otg_pdata_rk3368,
         },
+#endif
        { },
 };
 
@@ -1410,6 +1421,7 @@ static int otg20_driver_probe(struct platform_device *_dev)
         */
 
        g_otgdev = dwc_otg_device;
+       dwc_otg_dev = (struct device *)&_dev->dev;
        pldata->privdata = dwc_otg_device;
        dwc_otg_device->pldata = pldata;
 
@@ -1520,7 +1532,8 @@ static int otg20_driver_probe(struct platform_device *_dev)
         * perform initial actions required for Internal ADP logic.
         */
        if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
-               if (pldata->phy_status == USB_PHY_ENABLED) {
+               if (dwc_otg_device->core_if->usb_mode == USB_MODE_NORMAL &&
+                   pldata->phy_status == USB_PHY_ENABLED) {
                        pldata->phy_suspend(pldata, USB_PHY_SUSPEND);
                        udelay(3);
                        pldata->clock_enable(pldata, 0);
@@ -1608,10 +1621,14 @@ static struct platform_driver dwc_otg_driver = {
 void rk_usb_power_up(void)
 {
        struct dwc_otg_platform_data *pldata_otg;
+#ifdef CONFIG_USB20_HOST
        struct dwc_otg_platform_data *pldata_host;
+#endif
+#ifdef CONFIG_USB_EHCI_RK
        struct rkehci_platform_data *pldata_ehci;
+#endif
 
-       if (cpu_is_rk3288()) {
+       if (is_rk3288_usb()) {
 #ifdef CONFIG_RK_USB_UART
                /* enable USB bypass UART function  */
                writel_relaxed(0x00c00000 | usb_to_uart_status,
@@ -1662,10 +1679,14 @@ void rk_usb_power_up(void)
 void rk_usb_power_down(void)
 {
        struct dwc_otg_platform_data *pldata_otg;
+#ifdef CONFIG_USB20_HOST
        struct dwc_otg_platform_data *pldata_host;
+#endif
+#ifdef CONFIG_USB_EHCI_RK
        struct rkehci_platform_data *pldata_ehci;
+#endif
 
-       if (cpu_is_rk3288()) {
+       if (is_rk3288_usb()) {
 #ifdef CONFIG_RK_USB_UART
                /* disable USB bypass UART function */
                usb_to_uart_status =