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");
		ret = -EINVAL;
		goto err1;
	}

	control_usb->hclk_usb_peri = hclk_usb_peri;
	clk_prepare_enable(hclk_usb_peri);

	phyclk480m_parent = devm_clk_get(&pdev->dev, "usbphy2_480m");
	if (IS_ERR(phyclk480m_parent)) {
		dev_err(&pdev->dev, "Failed to get usbphy2_480m\n");
		goto err2;
	}

	phyclk_480m = devm_clk_get(&pdev->dev, "usbphy_480m");
	if (IS_ERR(phyclk_480m)) {
		dev_err(&pdev->dev, "Failed to get usbphy_480m\n");
		goto err2;
	}

	clk_set_parent(phyclk_480m, phyclk480m_parent);

	ret = usb_grf_ioremap(pdev);
	if(ret){
		dev_err(&pdev->dev, "Failed to ioremap usb grf\n");
		goto err2;
	}

#ifdef CONFIG_USB20_OTG
	if(usb20otg_get_status(USB_STATUS_BVABLID)){
		rk_usb_charger_status = USB_BC_TYPE_SDP;
		schedule_delayed_work(&control_usb->usb_charger_det_work, HZ/10);
	}
#endif

	ret = otg_irq_detect_init(pdev);
	if (ret < 0)
		goto err2;

	return 0;

err2:
	clk_disable_unprepare(hclk_usb_peri);
err1:
	return ret;
}
static int dwc_otg_control_usb_probe(struct platform_device *pdev)
{
	struct clk *hclk_usb_peri;
	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");
		ret = -EINVAL;
		goto err1;
	}

	control_usb->hclk_usb_peri = hclk_usb_peri;
	clk_prepare_enable(hclk_usb_peri);

#ifdef CONFIG_USB20_OTG
	if (usb20otg_get_status(USB_STATUS_BVABLID))
		schedule_delayed_work(&control_usb->usb_charger_det_work,
				      HZ / 10);
#endif

	ret = otg_irq_detect_init(pdev);
	if (ret < 0)
		goto err2;

	return 0;

err2:
	clk_disable_unprepare(hclk_usb_peri);
err1:
	return ret;
}
static int dwc_otg_control_usb_probe(struct platform_device *pdev)
{
    struct device *dev = &pdev->dev;
    struct device_node *np = dev->of_node;
    struct clk *hclk_usb_peri;
    struct regmap *grf;
    int gpio, ret = 0;

    control_usb = devm_kzalloc(dev, sizeof(*control_usb), GFP_KERNEL);
    if (!control_usb) {
        dev_err(&pdev->dev, "Unable to alloc memory for control usb\n");
        return -ENOMEM;
    }

    /* Init regmap GRF */
    grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf");
    if (IS_ERR(grf)) {
        dev_err(&pdev->dev, "Missing rockchip,grf property\n");
        return PTR_ERR(grf);
    }
    control_usb->grf = grf;

    /* Init Vbus-drv GPIOs */
    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");
        return -ENOMEM;
    }

    gpio = of_get_named_gpio(np, "host_drv_gpio", 0);
    control_usb->host_gpios->gpio = gpio;

    if (gpio_is_valid(gpio)) {
        if (devm_gpio_request(&pdev->dev, gpio, "usb_host_drv")) {
            dev_err(&pdev->dev,
                    "Failed to request GPIO%d for host_drv\n",
                    gpio);
            return -EINVAL;
        }
        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");
        return -ENOMEM;
    }

    gpio = of_get_named_gpio(np, "otg_drv_gpio", 0);
    control_usb->otg_gpios->gpio = gpio;

    if (gpio_is_valid(gpio)) {
        if (devm_gpio_request(&pdev->dev, gpio, "usb_otg_drv")) {
            dev_err(&pdev->dev,
                    "failed to request GPIO%d for otg_drv\n", gpio);
            return -EINVAL;
        }
        gpio_direction_output(control_usb->otg_gpios->gpio, 0);
    }


    control_usb->remote_wakeup = of_property_read_bool(np,
                                 "rockchip,remote_wakeup");
    control_usb->usb_irq_wakeup = of_property_read_bool(np,
                                  "rockchip,usb_irq_wakeup");

    /* Init hclk_usb_peri */
    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");
        return PTR_ERR(hclk_usb_peri);
    }
    control_usb->hclk_usb_peri = hclk_usb_peri;
    clk_prepare_enable(hclk_usb_peri);

#ifdef CONFIG_USB20_OTG
    INIT_DELAYED_WORK(&control_usb->usb_charger_det_work,
                      usb_battery_charger_detect_work);

    if (usb20otg_get_status(USB_STATUS_BVABLID))
        schedule_delayed_work(&control_usb->usb_charger_det_work,
                              HZ / 10);
#endif

    ret = otg_irq_detect_init(pdev);
    if (ret < 0)
        goto err;

    return 0;

err:
    clk_disable_unprepare(hclk_usb_peri);
    return ret;
}