USB: move usb drv gpios from dtsi to dts.
authorwlf <wulf@rock-chips.com>
Thu, 24 Apr 2014 09:28:27 +0000 (17:28 +0800)
committerwlf <wulf@rock-chips.com>
Thu, 24 Apr 2014 09:28:27 +0000 (17:28 +0800)
arch/arm/boot/dts/rk3288-chrome.dts
arch/arm/boot/dts/rk3288-p977.dts
arch/arm/boot/dts/rk3288-tb.dts
arch/arm/boot/dts/rk3288-tesco.dts
arch/arm/boot/dts/rk3288.dtsi
drivers/usb/dwc_otg_310/usbdev_rk32.c

index 5c7a5f9aec4f7a8cc568425a21bae2762a2f8ce1..c671aaacf1e00574db78f6cab9405cde0ce58a66 100755 (executable)
                };
        };
 
+       usb_control {
+               compatible = "rockchip,rk3288-usb-control";
+
+               host_drv_gpio = <&gpio0 GPIO_B6 GPIO_ACTIVE_LOW>;
+               otg_drv_gpio = <&gpio0 GPIO_B4 GPIO_ACTIVE_LOW>;
+
+               rockchip,remote_wakeup;
+               rockchip,usb_irq_wakeup;
+       };
 };
 
 &gmac {
index e82ca37645a9edce886f1bf3728064bae706e1d3..6cfec70142178d2147338ea295c320f9557bd3e0 100755 (executable)
                        };
                };
        };
+
+       usb_control {
+               compatible = "rockchip,rk3288-usb-control";
+
+               otg_drv_gpio = <&gpio0 GPIO_B4 GPIO_ACTIVE_LOW>;
+
+               rockchip,remote_wakeup;
+               rockchip,usb_irq_wakeup;
+       };
 };
 &pinctrl {
        gpio0_gpio {
index bdbc65357ad2d39caa6e6a97bef14b5973a3073b..d6c3d2e3eccd2264a335779e44b12617b540263b 100755 (executable)
                };
        };
 
+       usb_control {
+               compatible = "rockchip,rk3288-usb-control";
+
+               host_drv_gpio = <&gpio0 GPIO_B6 GPIO_ACTIVE_LOW>;
+               otg_drv_gpio = <&gpio0 GPIO_B4 GPIO_ACTIVE_LOW>;
+
+               rockchip,remote_wakeup;
+               rockchip,usb_irq_wakeup;
+       };
 };
 
 &gmac {
index 3303bc63fd3e88d54f960d5e81b7d0ee391939f5..f29835c77cda352cc65d52ca07cbcbb98ad1f598 100755 (executable)
                };
        };
 
+       usb_control {
+               compatible = "rockchip,rk3288-usb-control";
+
+               host_drv_gpio = <&gpio0 GPIO_B6 GPIO_ACTIVE_LOW>;
+               otg_drv_gpio = <&gpio0 GPIO_B4 GPIO_ACTIVE_LOW>;
+
+               rockchip,remote_wakeup;
+               rockchip,usb_irq_wakeup;
+       };
 };
 
 &gmac {
index 6f79218d9fd72999fd91a9f48b19d4742dbcaae8..78f9ff6b94a4c2f46b1b7251541d418ea03901b1 100755 (executable)
                interrupt-names = "otg_id", "otg_bvalid",
                           "otg_linestate", "host0_linestate",
                           "host1_linestate";
-               gpios = <&gpio0 GPIO_B6 GPIO_ACTIVE_LOW>,/*HOST_VBUS_DRV*/
-                       <&gpio0 GPIO_B4 GPIO_ACTIVE_LOW>;/*OTG_VBUS_DRV*/
                clocks = <&clk_gates7 9>, <&usbphy_480m>,
                  <&otgphy1_480m>, <&otgphy2_480m>;
                clock-names = "hclk_usb_peri", "usbphy_480m",
                       "usbphy1_480m", "usbphy2_480m";
-               rockchip,remote_wakeup;
-               rockchip,usb_irq_wakeup;
 
                usb_bc{
                        compatible = "synopsys,phy";
index 52b643fc3fdd8eee09a86a2977fa037864e3b4cc..35fe365f5aa6f16d36ac2413b0ac043ceddd8642 100755 (executable)
@@ -19,8 +19,10 @@ static void usb20otg_hw_init(void)
 
        /* other haredware init,include:
         * DRV_VBUS GPIO init */
-       if(gpio_get_value(control_usb->otg_gpios->gpio)){
-               gpio_set_value(control_usb->otg_gpios->gpio, 0);
+       if(gpio_is_valid(control_usb->otg_gpios->gpio)){
+               if(gpio_get_value(control_usb->otg_gpios->gpio)){
+                       gpio_set_value(control_usb->otg_gpios->gpio, 0);
+               }
        }
 }
 
@@ -149,9 +151,11 @@ static void dwc_otg_uart_mode(void* pdata, int enter_usb_uart_mode)
 static void usb20otg_power_enable(int enable)
 {
        if(0 == enable){//disable otg_drv power
-               gpio_set_value(control_usb->otg_gpios->gpio, 0);
+               if(gpio_is_valid(control_usb->otg_gpios->gpio))
+                       gpio_set_value(control_usb->otg_gpios->gpio, 0);
        }else if(1 == enable){//enable otg_drv power
-               gpio_set_value(control_usb->otg_gpios->gpio, 1);
+               if(gpio_is_valid(control_usb->otg_gpios->gpio))
+                       gpio_set_value(control_usb->otg_gpios->gpio, 1);
        }
 }
 
@@ -188,8 +192,10 @@ static void usb20host_hw_init(void)
 
        /* other haredware init,include:
         * DRV_VBUS GPIO init */
-       if(!gpio_get_value(control_usb->host_gpios->gpio)){
-               gpio_set_value(control_usb->host_gpios->gpio, 1);
+       if(gpio_is_valid(control_usb->host_gpios->gpio)){
+               if(!gpio_get_value(control_usb->host_gpios->gpio)){
+                       gpio_set_value(control_usb->host_gpios->gpio, 1);
+               }
        }
 }
 
@@ -308,7 +314,8 @@ static void usb20host_power_enable(int enable)
        if(0 == enable){//disable host_drv power
                //do not disable power in default
        }else if(1 == enable){//enable host_drv power
-               gpio_set_value(control_usb->host_gpios->gpio, 1);
+               if(gpio_is_valid(control_usb->host_gpios->gpio))
+                       gpio_set_value(control_usb->host_gpios->gpio, 1);
        }
 }
 
@@ -436,8 +443,10 @@ 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);
+       if(gpio_is_valid(control_usb->host_gpios->gpio)){
+               if(!gpio_get_value(control_usb->host_gpios->gpio)){
+                       gpio_set_value(control_usb->host_gpios->gpio, 1);
+               }
        }
 }
 
@@ -562,8 +571,10 @@ 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);
+       if(gpio_is_valid(control_usb->host_gpios->gpio)){
+               if(!gpio_get_value(control_usb->host_gpios->gpio)){
+                       gpio_set_value(control_usb->host_gpios->gpio, 1);
+               }
        }
 }
 
@@ -903,27 +914,26 @@ static int usb_grf_ioremap(struct platform_device *pdev)
 
 #ifdef CONFIG_OF
 
-static const struct of_device_id dwc_otg_control_usb_id_table[] = {
+static const struct of_device_id rk_usb_control_id_table[] = {
        {
-               .compatible = "rockchip,rk3288-dwc-control-usb",
+               .compatible = "rockchip,rk3288-usb-control",
        },
        { },
 };
 
 #endif
 
-static int dwc_otg_control_usb_probe(struct platform_device *pdev)
+static int rk_usb_control_probe(struct platform_device *pdev)
 {
        int gpio, err;
        struct device_node *np = pdev->dev.of_node;
-       struct clk* hclk_usb_peri, *phyclk_480m, *phyclk480m_parent;
        int ret = 0;
 
        control_usb = devm_kzalloc(&pdev->dev, sizeof(*control_usb),GFP_KERNEL);
        if (!control_usb) {
                dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
                ret =  -ENOMEM;
-               goto err1;
+               goto out;
        }
 
        control_usb->chip_id = RK3288_USB_CTLR;
@@ -934,6 +944,96 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev)
 
        INIT_DELAYED_WORK(&control_usb->usb_charger_det_work, usb_battery_charger_detect_work);
 
+
+       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 out;
+       }
+
+       gpio =  of_get_named_gpio(np, "host_drv_gpio", 0);
+       control_usb->host_gpios->gpio = gpio;
+
+       if(!gpio_is_valid(gpio)){
+               dev_err(&pdev->dev, "invalid host gpio%d\n", gpio);
+       }else{
+               err = devm_gpio_request(&pdev->dev, gpio, "host_drv_gpio");
+               if (err) {
+                       dev_err(&pdev->dev,
+                               "failed to request GPIO%d for host_drv\n",
+                               gpio);
+                       ret = err;
+                       goto out;
+               }
+               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 out;
+       }
+
+       gpio =  of_get_named_gpio(np, "otg_drv_gpio", 0);
+       control_usb->otg_gpios->gpio = gpio;
+
+       if(!gpio_is_valid(gpio)){
+               dev_err(&pdev->dev, "invalid otg gpio%d\n", gpio);
+       }else{
+               err = devm_gpio_request(&pdev->dev, gpio, "otg_drv_gpio");
+               if (err) {
+                       dev_err(&pdev->dev,
+                               "failed to request GPIO%d for otg_drv\n",
+                               gpio);
+                       ret = err;
+                       goto out;
+               }
+               gpio_direction_output(control_usb->otg_gpios->gpio, 0);
+       }
+
+out:
+       return ret;
+}
+
+static int rk_usb_control_remove(struct platform_device *pdev)
+{
+       return 0;
+}
+
+static struct platform_driver rk_usb_control_driver = {
+       .probe          = rk_usb_control_probe,
+       .remove         = rk_usb_control_remove,
+       .driver         = {
+               .name   = "rk3288-usb-control",
+               .owner  = THIS_MODULE,
+               .of_match_table = of_match_ptr(rk_usb_control_id_table),
+       },
+};
+
+#ifdef CONFIG_OF
+
+static const struct of_device_id dwc_otg_control_usb_id_table[] = {
+       {
+               .compatible = "rockchip,rk3288-dwc-control-usb",
+       },
+       { },
+};
+
+#endif
+
+static int dwc_otg_control_usb_probe(struct platform_device *pdev)
+{
+       struct clk* hclk_usb_peri, *phyclk_480m, *phyclk480m_parent;
+       int ret = 0;
+
+       if (!control_usb) {
+               dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
+               ret =  -ENOMEM;
+               goto err1;
+       }
+
        hclk_usb_peri = devm_clk_get(&pdev->dev, "hclk_usb_peri");
        if (IS_ERR(hclk_usb_peri)) {
                dev_err(&pdev->dev, "Failed to get hclk_usb_peri\n");
@@ -964,54 +1064,6 @@ static int dwc_otg_control_usb_probe(struct platform_device *pdev)
                goto err2;
        }
 
-       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)){
-               dev_err(&pdev->dev, "invalid host gpio%d\n", gpio);
-               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,
-                       "failed to request GPIO%d for host_drv\n",
-                       gpio);
-               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)){
-               dev_err(&pdev->dev, "invalid otg gpio%d\n", gpio);
-               ret = -EINVAL;
-               goto err2;
-       }
-       control_usb->otg_gpios->gpio = gpio;
-       err = devm_gpio_request(&pdev->dev, gpio, "otg_drv_gpio");
-       if (err) {
-               dev_err(&pdev->dev,
-                       "failed to request GPIO%d for otg_drv\n",
-                       gpio);
-               ret = err;
-               goto err2;
-       }
-       gpio_direction_output(control_usb->otg_gpios->gpio, 0);
-
 #ifdef CONFIG_USB20_OTG
        if(usb20otg_get_status(USB_STATUS_BVABLID)){
                rk_usb_charger_status = USB_BC_TYPE_SDP;
@@ -1049,13 +1101,28 @@ static struct platform_driver dwc_otg_control_usb_driver = {
 
 static int __init dwc_otg_control_usb_init(void)
 {
-       return platform_driver_register(&dwc_otg_control_usb_driver);
+       int retval = 0;
+
+       retval = platform_driver_register(&rk_usb_control_driver);
+       if (retval < 0) {
+               printk(KERN_ERR "%s retval=%d\n", __func__, retval);
+               return retval;
+       }
+
+       retval = platform_driver_register(&dwc_otg_control_usb_driver);
+
+       if (retval < 0) {
+               printk(KERN_ERR "%s retval=%d\n", __func__, retval);
+               return retval;
+       }
+       return retval;
 }
 
 subsys_initcall(dwc_otg_control_usb_init);
 
 static void __exit dwc_otg_control_usb_exit(void)
 {
+       platform_driver_unregister(&rk_usb_control_driver);
        platform_driver_unregister(&dwc_otg_control_usb_driver);
 }