From 6b1be50ce58332a375f9563658203d909d07874d Mon Sep 17 00:00:00 2001 From: wlf Date: Thu, 20 Mar 2014 09:57:04 +0800 Subject: [PATCH] USB: Modify EHCI & OHCI clk and gpio. --- arch/arm/boot/dts/rk3288.dtsi | 30 +++++--- drivers/usb/dwc_otg_310/usbdev_rk30.c | 26 ++++++- drivers/usb/dwc_otg_310/usbdev_rk32.c | 98 ++++++++++++++++++++++++++- 3 files changed, 137 insertions(+), 17 deletions(-) diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi index e7e0af21ac6d..e05e50b7fd9d 100755 --- a/arch/arm/boot/dts/rk3288.dtsi +++ b/arch/arm/boot/dts/rk3288.dtsi @@ -868,20 +868,28 @@ /*clock-names = "clk_usbphy1", "hclk_usb1";*/ }; - usb2: usb@ff520000 { - compatible = "rockchip,rk3288_rk_ohci_host"; - reg = <0xff520000 0x20000>; - interrupts = ; + usb2: usb@ff500000 { + compatible = "rockchip,rk3288_usbhs_host"; + reg = <0xff500000 0x40000>; /*clocks = <&clk_gates13 6>, <&clk_gates7 7>;*/ /*clock-names = "clk_usbphy2", "hclk_usb2";*/ - }; + #address-cells = <1>; + #size-cells = <1>; + ranges; - usb3: usb@ff500000 { - compatible = "rockchip,rk3288_rk_ehci_host"; - reg = <0xff500000 0x20000>; - interrupts = ; - /*clocks = <&clk_gates13 6>, <&clk_gates7 7>;*/ - /*clock-names = "clk_usbphy3", "hclk_usb3";*/ + ehci: ehci@ff500000 { + compatible = "rockchip,rk3288_rk_ehci_host"; + reg = <0xff500000 0x20000>; + interrupt-parent = <&gic>; + interrupts = ; + }; + + ohci: ohci@ff520000 { + compatible = "rockchip,rk3288_rk_ohci_host"; + reg = <0xff520000 0x20000>; + interrupt-parent = <&gic>; + interrupts = ; + }; }; hsic: hsic@ff5c0000 { diff --git a/drivers/usb/dwc_otg_310/usbdev_rk30.c b/drivers/usb/dwc_otg_310/usbdev_rk30.c index f4913a0af9fe..6fb727f8a563 100755 --- a/drivers/usb/dwc_otg_310/usbdev_rk30.c +++ b/drivers/usb/dwc_otg_310/usbdev_rk30.c @@ -21,7 +21,9 @@ static void usb20otg_hw_init(void) /* other haredware init,include: * DRV_VBUS GPIO init */ - gpio_direction_output(control_usb->otg_gpios->gpio, 0); + if(gpio_get_value(control_usb->otg_gpios->gpio)){ + gpio_set_value(control_usb->otg_gpios->gpio, 0); + } } static void usb20otg_phy_suspend(void* pdata, int suspend) @@ -166,8 +168,9 @@ static void usb20host_hw_init(void) /* other haredware init,include: * DRV_VBUS GPIO init */ - gpio_direction_output(control_usb->host_gpios->gpio, 1); - + if(!gpio_get_value(control_usb->host_gpios->gpio)){ + gpio_set_value(control_usb->host_gpios->gpio, 1); + } } static void usb20host_phy_suspend(void* pdata, int suspend) @@ -540,7 +543,13 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev) goto err2; } + /* init host gpio */ control_usb->host_gpios = devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL); + if(!control_usb->host_gpios){ + dev_err(&pdev->dev, "unable to alloc memory for host_gpios\n"); + ret = -ENOMEM; + goto err2; + } gpio = of_get_named_gpio(np, "gpios", 0); if(!gpio_is_valid(gpio)){ @@ -548,7 +557,9 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev) ret = -EINVAL; goto err2; } + control_usb->host_gpios->gpio = gpio; + err = devm_gpio_request(&pdev->dev, gpio, "host_drv_gpio"); if (err) { dev_err(&pdev->dev, @@ -557,8 +568,15 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev) ret = err; goto err2; } + gpio_direction_output(control_usb->host_gpios->gpio, 1); + /* init otg gpio */ control_usb->otg_gpios = devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL); + if(!control_usb->otg_gpios){ + dev_err(&pdev->dev, "unable to alloc memory for otg_gpios\n"); + ret = -ENOMEM; + goto err2; + } gpio = of_get_named_gpio(np, "gpios", 1); if(!gpio_is_valid(gpio)){ @@ -575,6 +593,8 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev) ret = err; goto err2; } + gpio_direction_output(control_usb->otg_gpios->gpio, 0); + ret = otg_irq_detect_init(pdev); if (ret < 0) goto err2; diff --git a/drivers/usb/dwc_otg_310/usbdev_rk32.c b/drivers/usb/dwc_otg_310/usbdev_rk32.c index 965699214879..103bbfa59f0c 100755 --- a/drivers/usb/dwc_otg_310/usbdev_rk32.c +++ b/drivers/usb/dwc_otg_310/usbdev_rk32.c @@ -19,8 +19,9 @@ static void usb20otg_hw_init(void) /* other haredware init,include: * DRV_VBUS GPIO init */ -// gpio_direction_output(control_usb->otg_gpios->gpio, 0); - + /*if(gpio_get_value(control_usb->otg_gpios->gpio)){ + gpio_set_value(control_usb->otg_gpios->gpio, 0); + }*/ } static void usb20otg_phy_suspend(void* pdata, int suspend) @@ -166,7 +167,9 @@ static void usb20host_hw_init(void) /* other haredware init,include: * DRV_VBUS GPIO init */ -// gpio_direction_output(control_usb->host_gpios->gpio, 1); + /*if(!gpio_get_value(control_usb->host_gpios->gpio)){ + gpio_set_value(control_usb->host_gpios->gpio, 1); + }*/ } static void usb20host_phy_suspend(void* pdata, int suspend) @@ -387,17 +390,54 @@ struct rkehci_platform_data rkhsic_pdata_rk3288 = { #ifdef CONFIG_USB_EHCI_RK static void rk_ehci_hw_init(void) { + /* usb phy config init */ + /* DRV_VBUS GPIO init */ + /*if(!gpio_get_value(control_usb->host_gpios->gpio)){ + gpio_set_value(control_usb->host_gpios->gpio, 1); + }*/ } static void rk_ehci_clock_init(void* pdata) { +/* + struct rkehci_platform_data *usbpdata=pdata; + struct clk* ahbclk,*phyclk; + + ahbclk = of_clk_get_by_name(of_get_parent(usbpdata->dev.of_node), "hclk_usb2"); + if (IS_ERR(ahbclk)) { + dev_err(usbpdata->dev, "Failed to get hclk_usb2\n"); + return; + } + + phyclk = of_clk_get_by_name(of_get_parent(usbpdata->dev.of_node), "clk_usbphy2"); + if (IS_ERR(phyclk)) { + dev_err(usbpdata->dev, "Failed to get clk_usbphy2\n"); + return; + } + usbpdata->phyclk = phyclk; + usbpdata->ahbclk = ahbclk; +*/ } static void rk_ehci_clock_enable(void* pdata, int enable) { +/* + struct rkehci_platform_data *usbpdata=pdata; + if(enable == usbpdata->clk_status) + return; + if(enable){ + clk_prepare_enable(usbpdata->ahbclk); + clk_prepare_enable(usbpdata->phyclk); + usbpdata->clk_status = 1; + }else{ + clk_disable_unprepare(usbpdata->ahbclk); + clk_disable_unprepare(usbpdata->phyclk); + usbpdata->clk_status = 0; + } +*/ } static void rk_ehci_soft_reset(void) @@ -419,14 +459,54 @@ struct rkehci_platform_data rkehci_pdata_rk3288 = { #ifdef CONFIG_USB_OHCI_HCD_RK static void rk_ohci_hw_init(void) { + /* usb phy config init */ + + /* DRV_VBUS GPIO init */ + /*if(!gpio_get_value(control_usb->host_gpios->gpio)){ + gpio_set_value(control_usb->host_gpios->gpio, 1); + }*/ } static void rk_ohci_clock_init(void* pdata) { +/* + struct rkehci_platform_data *usbpdata=pdata; + struct clk* ahbclk,*phyclk; + + ahbclk = of_clk_get_by_name(of_get_parent(usbpdata->dev.of_node), "hclk_usb2"); + if (IS_ERR(ahbclk)) { + dev_err(usbpdata->dev, "Failed to get hclk_usb2\n"); + return; + } + + phyclk = of_clk_get_by_name(of_get_parent(usbpdata->dev.of_node), "clk_usbphy2"); + if (IS_ERR(phyclk)) { + dev_err(usbpdata->dev, "Failed to get clk_usbphy2\n"); + return; + } + + usbpdata->phyclk = phyclk; + usbpdata->ahbclk = ahbclk; +*/ } static void rk_ohci_clock_enable(void* pdata, int enable) { +/* + struct rkehci_platform_data *usbpdata=pdata; + + if(enable == usbpdata->clk_status) + return; + if(enable){ + clk_prepare_enable(usbpdata->ahbclk); + clk_prepare_enable(usbpdata->phyclk); + usbpdata->clk_status = 1; + }else{ + clk_disable_unprepare(usbpdata->ahbclk); + clk_disable_unprepare(usbpdata->phyclk); + usbpdata->clk_status = 0; + } +*/ } static void rk_ohci_soft_reset(void) @@ -767,6 +847,11 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev) } /* control_usb->host_gpios = devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL); + if(!control_usb->host_gpios){ + dev_err(&pdev->dev, "unable to alloc memory for host_gpios\n"); + ret = -ENOMEM; + goto err2; + } gpio = of_get_named_gpio(np, "gpios", 0); if(!gpio_is_valid(gpio)){ @@ -783,8 +868,14 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev) ret = err; goto err2; } + gpio_direction_output(control_usb->host_gpios->gpio, 1); control_usb->otg_gpios = devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL); + if(!control_usb->otg_gpios){ + dev_err(&pdev->dev, "unable to alloc memory for otg_gpios\n"); + ret = -ENOMEM; + goto err2; + } gpio = of_get_named_gpio(np, "gpios", 1); if(!gpio_is_valid(gpio)){ @@ -801,6 +892,7 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev) ret = err; goto err2; } + gpio_direction_output(control_usb->otg_gpios->gpio, 0); */ /* disable for debug ret = otg_irq_detect_init(pdev); -- 2.34.1