[RFC 09/17] usb/ehci: add generic hcd add function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This generic add function could be used by platform drivers.

Signed-off-by: Sebastian Andrzej Siewior <sebastian@xxxxxxxxxxxxx>
---
 drivers/usb/host/Makefile        |    1 +
 drivers/usb/host/ehci-platform.c |   70 ++++++++++++++++++++++++++++++++++++++
 drivers/usb/host/ehci.h          |    4 ++
 3 files changed, 75 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/host/ehci-platform.c

diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 82679f3..29f5abc 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_USB_WHCI_HCD)	+= whci/
 obj-$(CONFIG_PCI)		+= pci-quirks.o
 
 ehci-hcd-y	:= ehci.o
+ehci-hcd-y	+= ehci-platform.o
 ehci-hcd-$(CONFIG_PCI)	+= ehci-pci.o
 ehci-hcd-$(CONFIG_PPC_PS3)	+= ehci-ps3.o
 ehci-hcd-$(CONFIG_USB_EHCI_HCD_PPC_OF)	+= ehci-ppc-of.o
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
new file mode 100644
index 0000000..d9d3351
--- /dev/null
+++ b/drivers/usb/host/ehci-platform.c
@@ -0,0 +1,70 @@
+#include <linux/usb/hcd.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+#include "ehci.h"
+
+struct usb_hcd *ehci_hcd_plat_add(struct platform_device *pdev,
+		const struct hc_driver *hc_drv)
+{
+	struct usb_hcd *hcd;
+	struct resource *res;
+	int ret;
+	int irq;
+
+	if (usb_disabled())
+		return ERR_PTR(-ENODEV);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return ERR_PTR(irq);
+
+	hcd = usb_create_hcd(hc_drv, &pdev->dev, dev_name(&pdev->dev));
+	if (!hcd) {
+		ret = -ENOMEM;
+		goto err_create_hcd;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		ret = -ENODEV;
+		goto err_get_res;
+	}
+
+	hcd->rsrc_start = res->start;
+	hcd->rsrc_len = resource_size(res);
+	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
+				hc_drv->description)) {
+		ret = -EBUSY;
+		goto err_get_res;
+	}
+
+	hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
+	if (hcd->regs == NULL) {
+		dev_dbg(&pdev->dev, "error mapping memory\n");
+		ret = -ENOMEM;
+		goto err_iomap;
+	}
+
+	ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
+	if (ret)
+		goto err_add_hcd;
+
+	return hcd;
+
+err_add_hcd:
+	iounmap(hcd->regs);
+err_iomap:
+	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+err_get_res:
+	usb_put_hcd(hcd);
+err_create_hcd:
+	return ERR_PTR(ret);
+}
+
+void ehci_hcd_plat_cleanup(struct platform_device *pdev, struct usb_hcd *hcd)
+{
+	usb_remove_hcd(hcd);
+	iounmap(hcd->regs);
+	release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
+	usb_put_hcd(hcd);
+}
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 35fc8ce..bde996d 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -789,6 +789,10 @@ void ehci_work(struct ehci_hcd *ehci);
 int ehci_lpm_set_da(struct ehci_hcd *ehci, int dev_addr, int port_num);
 int ehci_lpm_check(struct ehci_hcd *ehci, int port);
 
+struct usb_hcd *ehci_hcd_plat_add(struct platform_device *pdev,
+		const struct hc_driver *hc_drv);
+void ehci_hcd_plat_cleanup(struct platform_device *pdev, struct usb_hcd *hcd);
+
 #ifdef CONFIG_PCI
 int ehci_register_pci(void);
 void ehci_unregister_pci(void);
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux