Exemple #1
0
static int ohci_hcd_tmio_drv_remove(struct platform_device *dev)
{
	struct usb_hcd *hcd = platform_get_drvdata(dev);
	struct tmio_hcd *tmio = hcd_to_tmio(hcd);
	const struct mfd_cell *cell = mfd_get_cell(dev);

	usb_remove_hcd(hcd);
	tmio_stop_hc(dev);
	if (cell->disable)
		cell->disable(dev);
	dma_release_declared_memory(&dev->dev);
	iounmap(hcd->regs);
	iounmap(tmio->ccr);
	usb_put_hcd(hcd);

	return 0;
}
static int __devinit ohci_hcd_tmio_drv_probe(struct platform_device *dev)
{
    const struct mfd_cell *cell = mfd_get_cell(dev);
    struct resource *regs = platform_get_resource(dev, IORESOURCE_MEM, 0);
    struct resource *config = platform_get_resource(dev, IORESOURCE_MEM, 1);
    struct resource *sram = platform_get_resource(dev, IORESOURCE_MEM, 2);
    int irq = platform_get_irq(dev, 0);
    struct tmio_hcd *tmio;
    struct ohci_hcd *ohci;
    struct usb_hcd *hcd;
    int ret;

    if (usb_disabled())
        return -ENODEV;

    if (!cell)
        return -EINVAL;

    hcd = usb_create_hcd(&ohci_tmio_hc_driver, &dev->dev, dev_name(&dev->dev));
    if (!hcd) {
        ret = -ENOMEM;
        goto err_usb_create_hcd;
    }

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

    tmio = hcd_to_tmio(hcd);

    spin_lock_init(&tmio->lock);

    tmio->ccr = ioremap(config->start, resource_size(config));
    if (!tmio->ccr) {
        ret = -ENOMEM;
        goto err_ioremap_ccr;
    }

    hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
    if (!hcd->regs) {
        ret = -ENOMEM;
        goto err_ioremap_regs;
    }

    if (!dma_declare_coherent_memory(&dev->dev, sram->start,
                                     sram->start,
                                     resource_size(sram),
                                     DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE)) {
        ret = -EBUSY;
        goto err_dma_declare;
    }

    if (cell->enable) {
        ret = cell->enable(dev);
        if (ret)
            goto err_enable;
    }

    tmio_start_hc(dev);
    ohci = hcd_to_ohci(hcd);
    ohci_hcd_init(ohci);

    ret = usb_add_hcd(hcd, irq, 0);
    if (ret)
        goto err_add_hcd;

    if (ret == 0)
        return ret;

    usb_remove_hcd(hcd);

err_add_hcd:
    tmio_stop_hc(dev);
    if (cell->disable)
        cell->disable(dev);
err_enable:
    dma_release_declared_memory(&dev->dev);
err_dma_declare:
    iounmap(hcd->regs);
err_ioremap_regs:
    iounmap(tmio->ccr);
err_ioremap_ccr:
    usb_put_hcd(hcd);
err_usb_create_hcd:

    return ret;
}