adjust usb phy suspend and clockgate sequence
authoryangkai <yangkai@ubuntu-fs>
Thu, 17 Feb 2011 08:57:02 +0000 (16:57 +0800)
committeryangkai <yangkai@ubuntu-fs>
Thu, 17 Feb 2011 08:57:02 +0000 (16:57 +0800)
drivers/usb/dwc_otg/dwc_otg_cil.c
drivers/usb/dwc_otg/dwc_otg_driver.c
drivers/usb/dwc_otg/dwc_otg_hcd.c
drivers/usb/dwc_otg/dwc_otg_pcd.c

index 0d8042b6e16f16e9dc82c7912bc12a423fd59e54..4c20f6ba3a2672c17b71019c50e597b76c1819e6 100755 (executable)
@@ -3336,8 +3336,13 @@ void dwc_otg_dump_flags(dwc_otg_core_if_t *_core_if)
        DWC_PRINT("core_if->usb_mode = %x\n",_core_if->usb_mode);
        DWC_PRINT("core_if->usb_wakeup = %x\n",_core_if->usb_wakeup);
 }
+
+#ifdef CONFIG_DWC_OTG_DEVICE_ONLY
+extern void dwc_otg_pcd_stop(dwc_otg_pcd_t *_pcd);
+#endif
 int dwc_debug(dwc_otg_core_if_t *core_if, int flag)
 {
+    dctl_data_t dctl = {.d32=0};
        //dwc_otg_core_if_t *core_if = dwc_core_if;
        #ifdef CONFIG_DWC_OTG_DEVICE_ONLY
         dwc_otg_pcd_t * pcd;
@@ -3354,6 +3359,12 @@ int dwc_debug(dwc_otg_core_if_t *core_if, int flag)
                    otg_dev = core_if->otg_dev;
                    pcd = otg_dev->pcd;
                    pcd->vbus_status = 0;
+            pcd->conn_status = 0;
+                   pcd->conn_en = 0;
+            dctl.d32 = dwc_read_reg32( &core_if->dev_if->dev_global_regs->dctl );
+            dctl.b.sftdiscon = 1;
+            dwc_write_reg32( &core_if->dev_if->dev_global_regs->dctl, dctl.d32 );
+            dwc_otg_pcd_stop(pcd);
                #endif
                        break;
                case 3:
@@ -3372,6 +3383,12 @@ int dwc_debug(dwc_otg_core_if_t *core_if, int flag)
                        dwc_otg_dump_flags(core_if);
                        break;
                case 8:
+               #ifdef CONFIG_DWC_OTG_DEVICE_ONLY
+                   otg_dev = core_if->otg_dev;
+                   pcd = otg_dev->pcd;
+                   //pcd->vbus_status = 0;
+                   pcd->conn_en = 1;
+               #endif
                        break;
                case 9:
                        dwc_otg_dump_flags(core_if);
index 987794f7fe95cd85b5442fc2f9743bb08fde06cb..54cd562390d9bf59a64e6cab2867370582a22dfb 100755 (executable)
@@ -361,20 +361,20 @@ static ssize_t dwc_otg_enable_store( struct device *_dev,
         if (_core_if->hcd_cb && _core_if->hcd_cb->stop) {
                 _core_if->hcd_cb->stop( _core_if->hcd_cb->p );
         }
-        clk_disable(otg_dev->phyclk);
-        clk_disable(otg_dev->ahbclk);
         if (_core_if->hcd_cb && _core_if->hcd_cb->suspend) {
                 _core_if->hcd_cb->suspend( _core_if->hcd_cb->p, val);
         }
+        clk_disable(otg_dev->phyclk);
+        clk_disable(otg_dev->ahbclk);
        }
        else if(val == 1)
        {
            DWC_PRINT("enable host controller:%s\n",pdev->name);
+        clk_enable(otg_dev->phyclk);
+        clk_enable(otg_dev->ahbclk);
         if (_core_if->hcd_cb && _core_if->hcd_cb->suspend) {
                 _core_if->hcd_cb->suspend( _core_if->hcd_cb->p, val);
         }
-        clk_enable(otg_dev->phyclk);
-        clk_enable(otg_dev->ahbclk);
         mdelay(5);
         if (_core_if->hcd_cb && _core_if->hcd_cb->start) {
                 _core_if->hcd_cb->start( _core_if->hcd_cb->p );
@@ -929,21 +929,65 @@ static __devinit int dwc_otg_driver_probe(struct platform_device *pdev)
        int32_t regval;
     struct clk *ahbclk,*phyclk,*busclk;
     unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON);
-       /*
-        *Enable usb phy
-        */
+    
+    
     regval = * otg_phy_con1;
-    regval |= (0x01<<2);
-    regval |= (0x01<<3);    // exit suspend.
-    regval &= ~(0x01<<2);
 #ifndef CONFIG_USB11_HOST
+       /*
+        * disable usb host 1.1 controller if not support
+        */
+    phyclk = clk_get(NULL, "uhost");
+    if (IS_ERR(phyclk)) {
+            retval = PTR_ERR(phyclk);
+            DWC_ERROR("can't get UHOST clock\n");
+           goto fail;
+    }
+    clk_enable(phyclk);
+    
+    ahbclk = clk_get(NULL, "hclk_uhost");
+    if (IS_ERR(ahbclk)) {
+            retval = PTR_ERR(ahbclk);
+            DWC_ERROR("can't get UHOST ahb bus clock\n");
+           goto fail;
+    }
+    clk_enable(ahbclk);
+    
        regval |= (0x01<<28);
+       
+    *otg_phy_con1 = regval;
+    
+    clk_disable(phyclk);
+    clk_disable(ahbclk);
 #endif
 #ifndef CONFIG_USB20_HOST
+       /*
+        * disable usb host 2.0 phy if not support
+        */
+    phyclk = clk_get(NULL, "otgphy1");
+    if (IS_ERR(phyclk)) {
+            retval = PTR_ERR(phyclk);
+            DWC_ERROR("can't get USBPHY1 clock\n");
+           goto fail;
+    }
+    clk_enable(phyclk);
+    
+    ahbclk = clk_get(NULL, "usbotg1");
+    if (IS_ERR(ahbclk)) {
+            retval = PTR_ERR(ahbclk);
+            DWC_ERROR("can't get USBOTG1 ahb bus clock\n");
+           goto fail;
+    }
+    clk_enable(ahbclk);
+    
     regval &= ~(0x01<<14);    // exit suspend.
     regval |= (0x01<<13);    // software control
-#endif
+
     *otg_phy_con1 = regval;
+    
+    clk_disable(phyclk);
+    clk_disable(ahbclk);
+#endif
+
     #if 0
     otgreg = ioremap(RK2818_USBOTG_PHYS,RK2818_USBOTG_SIZE);
     DWC_PRINT("otgreg 0x%x",otgreg);
@@ -988,6 +1032,15 @@ static __devinit int dwc_otg_driver_probe(struct platform_device *pdev)
     }
     clk_enable(ahbclk);
     
+       /*
+        * Enable usb phy 0
+        */
+    regval = * otg_phy_con1;
+    regval |= (0x01<<2);
+    regval |= (0x01<<3);    // exit suspend.
+    regval &= ~(0x01<<2);
+    *otg_phy_con1 = regval;
+    
        dwc_otg_device->phyclk = phyclk;
        dwc_otg_device->ahbclk = ahbclk;
        dwc_otg_device->busclk = busclk;
index 226a06ab59444f0ad619953f1df117d87d5747ec..5271b33000ae054cc0658876ebf1eb5b1c3bcd42 100755 (executable)
@@ -104,6 +104,7 @@ static int dwc_otg_hcd_suspend(struct usb_hcd *hcd)
                 core_if->hcd_cb->suspend( core_if->hcd_cb->p, 0);
         }
     }
+    udelay(1);
     clk_disable(core_if->otg_dev->phyclk);
     clk_disable(core_if->otg_dev->ahbclk);
     //power off
index 0451addf8dc0eb11865384492399014744f94ea2..1ade6b05a809a32d7d26e85f175dd6e231d3fa27 100755 (executable)
@@ -1552,6 +1552,7 @@ int rk28_usb_suspend( int exitsuspend )
         pcd->phy_suspend = 1;
         *otg_phy_con1 |= (0x01<<2);
         *otg_phy_con1 &= ~(0x01<<3);    // enter suspend.
+        udelay(1);
         clk_disable(pcd->otg_dev->phyclk);
         clk_disable(pcd->otg_dev->ahbclk);
         //*otg_phy_con1 &= ~(0x01<<2);