예제 #1
0
static int ehci_platform_remove(struct platform_device *dev)
{
	struct usb_hcd *hcd = platform_get_drvdata(dev);
	struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
	struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
	int clk;

	usb_remove_hcd(hcd);

	if (pdata->power_off)
		pdata->power_off(dev);

	if (priv->rst)
		reset_control_assert(priv->rst);

	for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++)
		clk_put(priv->clks[clk]);

	usb_put_hcd(hcd);

	if (pdata == &ehci_platform_defaults)
		dev->dev.platform_data = NULL;

	return 0;
}
예제 #2
0
static int st_ehci_platform_power_on(struct platform_device *dev)
{
    struct usb_hcd *hcd = platform_get_drvdata(dev);
    struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
    int clk, ret;

    ret = reset_control_deassert(priv->pwr);
    if (ret)
        return ret;

    ret = reset_control_deassert(priv->rst);
    if (ret)
        goto err_assert_power;

    /* some SoCs don't have a dedicated 48Mhz clock, but those that do
       need the rate to be explicitly set */
    if (priv->clk48) {
        ret = clk_set_rate(priv->clk48, 48000000);
        if (ret)
            goto err_assert_reset;
    }

    for (clk = 0; clk < USB_MAX_CLKS && priv->clks[clk]; clk++) {
        ret = clk_prepare_enable(priv->clks[clk]);
        if (ret)
            goto err_disable_clks;
    }

    ret = phy_init(priv->phy);
    if (ret)
        goto err_disable_clks;

    ret = phy_power_on(priv->phy);
    if (ret)
        goto err_exit_phy;

    return 0;

err_exit_phy:
    phy_exit(priv->phy);
err_disable_clks:
    while (--clk >= 0)
        clk_disable_unprepare(priv->clks[clk]);
err_assert_reset:
    reset_control_assert(priv->rst);
err_assert_power:
    reset_control_assert(priv->pwr);

    return ret;
}
예제 #3
0
static void ehci_platform_power_off(struct platform_device *dev)
{
	struct usb_hcd *hcd = platform_get_drvdata(dev);
	struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
	int clk, phy_num;

	for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
		phy_power_off(priv->phys[phy_num]);
		phy_exit(priv->phys[phy_num]);
	}

	for (clk = EHCI_MAX_CLKS - 1; clk >= 0; clk--)
		if (priv->clks[clk])
			clk_disable_unprepare(priv->clks[clk]);
}
예제 #4
0
static int ehci_platform_resume(struct device *dev)
{
	struct usb_hcd *hcd = dev_get_drvdata(dev);
	struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
	struct platform_device *pdev =
		container_of(dev, struct platform_device, dev);
	struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);

	if (pdata->power_on) {
		int err = pdata->power_on(pdev);
		if (err < 0)
			return err;
	}

	ehci_resume(hcd, priv->reset_on_resume);
	return 0;
}
예제 #5
0
static void st_ehci_platform_power_off(struct platform_device *dev)
{
    struct usb_hcd *hcd = platform_get_drvdata(dev);
    struct st_ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
    int clk;

    reset_control_assert(priv->pwr);

    reset_control_assert(priv->rst);

    phy_power_off(priv->phy);

    phy_exit(priv->phy);

    for (clk = USB_MAX_CLKS - 1; clk >= 0; clk--)
        if (priv->clks[clk])
            clk_disable_unprepare(priv->clks[clk]);

}
예제 #6
0
static int ehci_platform_power_on(struct platform_device *dev)
{
	struct usb_hcd *hcd = platform_get_drvdata(dev);
	struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
	int clk, ret, phy_num;

	for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) {
		ret = clk_prepare_enable(priv->clks[clk]);
		if (ret)
			goto err_disable_clks;
	}

	for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
		if (priv->phys[phy_num]) {
			ret = phy_init(priv->phys[phy_num]);
			if (ret)
				goto err_exit_phy;
			ret = phy_power_on(priv->phys[phy_num]);
			if (ret) {
				phy_exit(priv->phys[phy_num]);
				goto err_exit_phy;
			}
		}
	}

	return 0;

err_exit_phy:
	while (--phy_num >= 0) {
		if (priv->phys[phy_num]) {
			phy_power_off(priv->phys[phy_num]);
			phy_exit(priv->phys[phy_num]);
		}
	}
err_disable_clks:
	while (--clk >= 0)
		clk_disable_unprepare(priv->clks[clk]);

	return ret;
}
예제 #7
0
static int ehci_platform_resume(struct device *dev)
{
	struct usb_hcd *hcd = dev_get_drvdata(dev);
	struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
	struct platform_device *pdev = to_platform_device(dev);
	struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
	struct device *companion_dev;

	if (pdata->power_on) {
		int err = pdata->power_on(pdev);
		if (err < 0)
			return err;
	}

	companion_dev = usb_of_get_companion_dev(hcd->self.controller);
	if (companion_dev) {
		device_pm_wait_for_dev(hcd->self.controller, companion_dev);
		put_device(companion_dev);
	}

	ehci_resume(hcd, priv->reset_on_resume);
	return 0;
}
예제 #8
0
static int ehci_platform_probe(struct platform_device *dev)
{
	struct usb_hcd *hcd;
	struct resource *res_mem;
	struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
	struct ehci_platform_priv *priv;
	struct ehci_hcd *ehci;
	int err, irq, phy_num, clk = 0;

	if (usb_disabled())
		return -ENODEV;

	/*
	 * Use reasonable defaults so platforms don't have to provide these
	 * with DT probing on ARM.
	 */
	if (!pdata)
		pdata = &ehci_platform_defaults;

	err = dma_coerce_mask_and_coherent(&dev->dev,
		pdata->dma_mask_64 ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32));
	if (err)
		return err;

	irq = platform_get_irq(dev, 0);
	if (irq < 0) {
		dev_err(&dev->dev, "no irq provided");
		return irq;
	}

	hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
			     dev_name(&dev->dev));
	if (!hcd)
		return -ENOMEM;

	platform_set_drvdata(dev, hcd);
	dev->dev.platform_data = pdata;
	priv = hcd_to_ehci_priv(hcd);
	ehci = hcd_to_ehci(hcd);

	if (pdata == &ehci_platform_defaults && dev->dev.of_node) {
		if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
			ehci->big_endian_mmio = 1;

		if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
			ehci->big_endian_desc = 1;

		if (of_property_read_bool(dev->dev.of_node, "big-endian"))
			ehci->big_endian_mmio = ehci->big_endian_desc = 1;

		if (of_property_read_bool(dev->dev.of_node,
					  "needs-reset-on-resume"))
			priv->reset_on_resume = true;

		if (of_property_read_bool(dev->dev.of_node,
					  "has-transaction-translator"))
			hcd->has_tt = 1;

		priv->num_phys = of_count_phandle_with_args(dev->dev.of_node,
				"phys", "#phy-cells");

		if (priv->num_phys > 0) {
			priv->phys = devm_kcalloc(&dev->dev, priv->num_phys,
					    sizeof(struct phy *), GFP_KERNEL);
			if (!priv->phys)
				return -ENOMEM;
		} else
			priv->num_phys = 0;

		for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
			priv->phys[phy_num] = devm_of_phy_get_by_index(
					&dev->dev, dev->dev.of_node, phy_num);
			if (IS_ERR(priv->phys[phy_num])) {
				err = PTR_ERR(priv->phys[phy_num]);
					goto err_put_hcd;
			}
		}

		for (clk = 0; clk < EHCI_MAX_CLKS; clk++) {
			priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
			if (IS_ERR(priv->clks[clk])) {
				err = PTR_ERR(priv->clks[clk]);
				if (err == -EPROBE_DEFER)
					goto err_put_clks;
				priv->clks[clk] = NULL;
				break;
			}
		}
	}

	priv->rst = devm_reset_control_get_optional(&dev->dev, NULL);
	if (IS_ERR(priv->rst)) {
		err = PTR_ERR(priv->rst);
		if (err == -EPROBE_DEFER)
			goto err_put_clks;
		priv->rst = NULL;
	} else {
		err = reset_control_deassert(priv->rst);
		if (err)
			goto err_put_clks;
	}

	if (pdata->big_endian_desc)
		ehci->big_endian_desc = 1;
	if (pdata->big_endian_mmio)
		ehci->big_endian_mmio = 1;
	if (pdata->has_tt)
		hcd->has_tt = 1;
	if (pdata->reset_on_resume)
		priv->reset_on_resume = true;

#ifndef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
	if (ehci->big_endian_mmio) {
		dev_err(&dev->dev,
			"Error: CONFIG_USB_EHCI_BIG_ENDIAN_MMIO not set\n");
		err = -EINVAL;
		goto err_reset;
	}
#endif
#ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC
	if (ehci->big_endian_desc) {
		dev_err(&dev->dev,
			"Error: CONFIG_USB_EHCI_BIG_ENDIAN_DESC not set\n");
		err = -EINVAL;
		goto err_reset;
	}
#endif

	if (pdata->power_on) {
		err = pdata->power_on(dev);
		if (err < 0)
			goto err_reset;
	}

	res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
	hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
	if (IS_ERR(hcd->regs)) {
		err = PTR_ERR(hcd->regs);
		goto err_power;
	}
	hcd->rsrc_start = res_mem->start;
	hcd->rsrc_len = resource_size(res_mem);

	err = usb_add_hcd(hcd, irq, IRQF_SHARED);
	if (err)
		goto err_power;

	device_wakeup_enable(hcd->self.controller);
	platform_set_drvdata(dev, hcd);

	return err;

err_power:
	if (pdata->power_off)
		pdata->power_off(dev);
err_reset:
	if (priv->rst)
		reset_control_assert(priv->rst);
err_put_clks:
	while (--clk >= 0)
		clk_put(priv->clks[clk]);
err_put_hcd:
	if (pdata == &ehci_platform_defaults)
		dev->dev.platform_data = NULL;

	usb_put_hcd(hcd);

	return err;
}
예제 #9
0
static int st_ehci_platform_probe(struct platform_device *dev)
{
    struct usb_hcd *hcd;
    struct resource *res_mem;
    struct usb_ehci_pdata *pdata = &ehci_platform_defaults;
    struct st_ehci_platform_priv *priv;
    struct ehci_hcd *ehci;
    int err, irq, clk = 0;

    if (usb_disabled())
        return -ENODEV;

    irq = platform_get_irq(dev, 0);
    if (irq < 0) {
        dev_err(&dev->dev, "no irq provided");
        return irq;
    }
    res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
    if (!res_mem) {
        dev_err(&dev->dev, "no memory resource provided");
        return -ENXIO;
    }

    hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
                         dev_name(&dev->dev));
    if (!hcd)
        return -ENOMEM;

    platform_set_drvdata(dev, hcd);
    dev->dev.platform_data = pdata;
    priv = hcd_to_ehci_priv(hcd);
    ehci = hcd_to_ehci(hcd);

    priv->phy = devm_phy_get(&dev->dev, "usb");
    if (IS_ERR(priv->phy)) {
        err = PTR_ERR(priv->phy);
        goto err_put_hcd;
    }

    for (clk = 0; clk < USB_MAX_CLKS; clk++) {
        priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
        if (IS_ERR(priv->clks[clk])) {
            err = PTR_ERR(priv->clks[clk]);
            if (err == -EPROBE_DEFER)
                goto err_put_clks;
            priv->clks[clk] = NULL;
            break;
        }
    }

    /* some SoCs don't have a dedicated 48Mhz clock, but those that
       do need the rate to be explicitly set */
    priv->clk48 = devm_clk_get(&dev->dev, "clk48");
    if (IS_ERR(priv->clk48)) {
        dev_info(&dev->dev, "48MHz clk not found\n");
        priv->clk48 = NULL;
    }

    priv->pwr = devm_reset_control_get_optional(&dev->dev, "power");
    if (IS_ERR(priv->pwr)) {
        err = PTR_ERR(priv->pwr);
        if (err == -EPROBE_DEFER)
            goto err_put_clks;
        priv->pwr = NULL;
    }

    priv->rst = devm_reset_control_get_optional(&dev->dev, "softreset");
    if (IS_ERR(priv->rst)) {
        err = PTR_ERR(priv->rst);
        if (err == -EPROBE_DEFER)
            goto err_put_clks;
        priv->rst = NULL;
    }

    if (pdata->power_on) {
        err = pdata->power_on(dev);
        if (err < 0)
            goto err_put_clks;
    }

    hcd->rsrc_start = res_mem->start;
    hcd->rsrc_len = resource_size(res_mem);

    hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
    if (IS_ERR(hcd->regs)) {
        err = PTR_ERR(hcd->regs);
        goto err_put_clks;
    }

    err = usb_add_hcd(hcd, irq, IRQF_SHARED);
    if (err)
        goto err_put_clks;

    device_wakeup_enable(hcd->self.controller);
    platform_set_drvdata(dev, hcd);

    return err;

err_put_clks:
    while (--clk >= 0)
        clk_put(priv->clks[clk]);
err_put_hcd:
    if (pdata == &ehci_platform_defaults)
        dev->dev.platform_data = NULL;

    usb_put_hcd(hcd);

    return err;
}