From: wlf Date: Thu, 27 Mar 2014 01:48:58 +0000 (+0800) Subject: USB: Support OTG force host and force device function. X-Git-Tag: firefly_0821_release~5794 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=af67fe985f496c042afda217184a58aa8bd556c6;p=firefly-linux-kernel-4.4.55.git USB: Support OTG force host and force device function. --- diff --git a/arch/arm/boot/dts/rk3188.dtsi b/arch/arm/boot/dts/rk3188.dtsi index 0030a2965f2d..d7842bd4e798 100755 --- a/arch/arm/boot/dts/rk3188.dtsi +++ b/arch/arm/boot/dts/rk3188.dtsi @@ -755,6 +755,8 @@ interrupts = ; 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 { diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi index 98366b2308af..181ca0244c8e 100755 --- a/arch/arm/boot/dts/rk3288.dtsi +++ b/arch/arm/boot/dts/rk3288.dtsi @@ -908,6 +908,8 @@ interrupts = ; /*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 { diff --git a/drivers/usb/dwc_otg_310/dwc_otg_driver.c b/drivers/usb/dwc_otg_310/dwc_otg_driver.c index 2afbb32cfc73..8095bf852472 100755 --- a/drivers/usb/dwc_otg_310/dwc_otg_driver.c +++ b/drivers/usb/dwc_otg_310/dwc_otg_driver.c @@ -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 diff --git a/drivers/usb/dwc_otg_310/dwc_otg_hcd_linux.c b/drivers/usb/dwc_otg_310/dwc_otg_hcd_linux.c index a5dadd24c980..af3d96f8b9a2 100755 --- a/drivers/usb/dwc_otg_310/dwc_otg_hcd_linux.c +++ b/drivers/usb/dwc_otg_310/dwc_otg_hcd_linux.c @@ -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); diff --git a/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c b/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c index 83e3d4c35949..2b6266d67c92 100755 --- a/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c +++ b/drivers/usb/dwc_otg_310/dwc_otg_pcd_linux.c @@ -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