USB: Support OTG force host and force device function.
authorwlf <wulf@rock-chips.com>
Thu, 27 Mar 2014 01:48:58 +0000 (09:48 +0800)
committerwlf <wulf@rock-chips.com>
Thu, 27 Mar 2014 01:48:58 +0000 (09:48 +0800)
arch/arm/boot/dts/rk3188.dtsi
arch/arm/boot/dts/rk3288.dtsi
drivers/usb/dwc_otg_310/dwc_otg_driver.c
drivers/usb/dwc_otg_310/dwc_otg_hcd_linux.c
drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c

index 0030a2965f2dc5fe8774230acfa15af2b3cc629a..d7842bd4e798c28c4c2ba1413f9353cdfc0e8e74 100755 (executable)
                interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>;
                clocks = <&clk_gates1 5>, <&clk_gates5 13>;
                clock-names = "clk_usbphy0", "hclk_usb0";
+               /*0 - Normal, 1 - Force Host, 2 - Force Device*/
+               rockchip,usb-mode = <0>;
        };
 
        usb1: usb@101c0000 {
index 98366b2308afbc1d52481faf0fc16ae310777750..181ca0244c8e0cd070d2b7991d2a329d3e2c5e2f 100755 (executable)
                interrupts = <GIC_SPI 23 IRQ_TYPE_LEVEL_HIGH>;
                /*clocks = <&clk_gates13 4>, <&clk_gates7 4>;*/
                /*clock-names = "clk_usbphy0", "hclk_usb0";*/
+               /*0 - Normal, 1 - Force Host, 2 - Force Device*/
+               rockchip,usb-mode = <0>;
        };
 
        usb1: usb@ff540000 {
index 2afbb32cfc734ca219c5118e188f12cb9c4f5dea..8095bf8524721068744610ef33d36dce9eebf807 100755 (executable)
@@ -1340,6 +1340,7 @@ static int otg20_driver_probe(struct platform_device *_dev)
 {
        int retval = 0;
        int irq;
+       uint32_t val;
        struct resource *res_base;
        dwc_otg_device_t *dwc_otg_device;
        struct device           *dev = &_dev->dev;
@@ -1491,7 +1492,15 @@ static int otg20_driver_probe(struct platform_device *_dev)
         * we do core soft reset after connection detected.
         */
        dwc_otg_core_init_no_reset(dwc_otg_device->core_if);
-       dwc_otg_device->core_if->usb_mode = 0;// TODO: Can be read from Device-Tree
+
+       /* set otg mode
+        * 0 - USB_MODE_NORMAL
+        * 1 - USB_MODE_FORCE_HOST
+        * 2 - USB_MODE_FORCE_DEVICE
+        */
+       of_property_read_u32(node, "rockchip,usb-mode", &val);
+       dwc_otg_device->core_if->usb_mode = val;
+
 #ifndef DWC_HOST_ONLY
        /*
         * Initialize the PCD
index a5dadd24c980b5c85fd601f543e5b6fef8085392..af3d96f8b9a20b2e8b67fc40a94ee43fff244769 100755 (executable)
@@ -517,7 +517,8 @@ int otg20_hcd_init( struct platform_device *_dev )
 
        dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
        dwc_otg_hcd->host_enabled = 1;
-       if(dwc_otg_is_host_mode(otg_dev->core_if)){
+       if(dwc_otg_is_host_mode(otg_dev->core_if) ||
+         (otg_dev->core_if->usb_mode == USB_MODE_FORCE_HOST)){
                dwc_otg_hcd->connect_detect_timer.function = otg20_hcd_connect_detect;
                dwc_otg_hcd->connect_detect_timer.data = (unsigned long)(dwc_otg_hcd);
                init_timer( &dwc_otg_hcd->connect_detect_timer);
index 83e3d4c359496d10cffa51356a191731c3cad8d0..2b6266d67c92ddc265de9c1f92683d3fb9323c96 100755 (executable)
@@ -1638,7 +1638,8 @@ static void dwc_otg_pcd_work_init(dwc_otg_pcd_t *pcd, struct platform_device *de
 
        wake_lock_init(&pcd->wake_lock, WAKE_LOCK_SUSPEND, "usb_pcd");
     
-       if(dwc_otg_is_device_mode(pcd->core_if)){
+       if(dwc_otg_is_device_mode(pcd->core_if) &&
+         (otg_dev->core_if->usb_mode != USB_MODE_FORCE_HOST)){
 #ifdef CONFIG_RK_USB_UART        
                if(pldata->get_status(USB_STATUS_BVABLID)){
                        //enter usb phy mode