1 From 1be00523336ac484c52681f838dfb8a76e8531cd Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 26 Nov 2011 21:28:56 +0100
4 Subject: [PATCH 182/186] USB: EHCI: Add a generic platform device driver
6 This adds a generic driver for platform devices. It works like the PCI
7 driver and is based on it. This is for devices which do not have an own
8 bus but their EHCI controller works like a PCI controller. It will be
9 used for the Broadcom bcma and ssb USB EHCI controller.
11 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
13 drivers/usb/host/Kconfig | 10 ++
14 drivers/usb/host/ehci-hcd.c | 5 +
15 drivers/usb/host/ehci-platform.c | 199 ++++++++++++++++++++++++++++++++++++++
16 3 files changed, 214 insertions(+), 0 deletions(-)
17 create mode 100644 drivers/usb/host/ehci-platform.c
19 --- a/drivers/usb/host/Kconfig
20 +++ b/drivers/usb/host/Kconfig
21 @@ -388,6 +388,16 @@ config USB_OHCI_HCD_PLATFORM
25 +config USB_EHCI_HCD_PLATFORM
26 + bool "Generic EHCI driver for a platform device"
27 + depends on USB_EHCI_HCD && EXPERIMENTAL
30 + Adds an EHCI host driver for a generic platform device, which
31 + provieds a memory space and an irq.
35 config USB_OHCI_BIG_ENDIAN_DESC
37 depends on USB_OHCI_HCD
38 --- a/drivers/usb/host/ehci-hcd.c
39 +++ b/drivers/usb/host/ehci-hcd.c
40 @@ -1329,6 +1329,11 @@ MODULE_LICENSE ("GPL");
41 #define PLATFORM_DRIVER ehci_xls_driver
44 +#ifdef CONFIG_USB_EHCI_HCD_PLATFORM
45 +#include "ehci-platform.c"
46 +#define PLATFORM_DRIVER ehci_platform_driver
49 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
50 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
51 !defined(XILINX_OF_PLATFORM_DRIVER)
53 +++ b/drivers/usb/host/ehci-platform.c
56 + * Generic platform ehci driver
58 + * Copyright 2007 Steven Brown <sbrown@cortland.com>
59 + * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
61 + * Derived from the ohci-ssb driver
62 + * Copyright 2007 Michael Buesch <m@bues.ch>
64 + * Derived from the EHCI-PCI driver
65 + * Copyright (c) 2000-2004 by David Brownell
67 + * Derived from the ohci-pci driver
68 + * Copyright 1999 Roman Weissgaerber
69 + * Copyright 2000-2002 David Brownell
70 + * Copyright 1999 Linus Torvalds
71 + * Copyright 1999 Gregory P. Smith
73 + * Licensed under the GNU/GPL. See COPYING for details.
75 +#include <linux/platform_device.h>
76 +#include <linux/usb/hci_driver.h>
78 +static int ehci_platform_reset(struct usb_hcd *hcd)
80 + struct platform_device *pdev = to_platform_device(hcd->self.controller);
81 + struct usb_hci_pdata *pdata = pdev->dev.platform_data;
82 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
83 + int caps_offset = 0;
88 + caps_offset = pdata->caps_offset;
89 + flags = pdata->flags;
92 + if (flags & USB_HCI_PDATA_HAS_TT_SET)
93 + hcd->has_tt = pdata->has_tt;
95 + ehci->caps = hcd->regs + caps_offset;
96 + retval = ehci_setup(hcd);
100 + if (flags & USB_HCI_PDATA_PORT_POWER_SET)
101 + ehci_port_power(ehci, pdata->power_set_is_on);
106 +static const struct hc_driver ehci_platform_hc_driver = {
107 + .description = hcd_name,
108 + .product_desc = "Generic Platform EHCI Controller",
109 + .hcd_priv_size = sizeof(struct ehci_hcd),
112 + .flags = HCD_MEMORY | HCD_USB2,
114 + .reset = ehci_platform_reset,
117 + .shutdown = ehci_shutdown,
119 + .urb_enqueue = ehci_urb_enqueue,
120 + .urb_dequeue = ehci_urb_dequeue,
121 + .endpoint_disable = ehci_endpoint_disable,
122 + .endpoint_reset = ehci_endpoint_reset,
124 + .get_frame_number = ehci_get_frame,
126 + .hub_status_data = ehci_hub_status_data,
127 + .hub_control = ehci_hub_control,
128 +#if defined(CONFIG_PM)
129 + .bus_suspend = ehci_bus_suspend,
130 + .bus_resume = ehci_bus_resume,
132 + .relinquish_port = ehci_relinquish_port,
133 + .port_handed_over = ehci_port_handed_over,
135 + .update_device = ehci_update_device,
137 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
140 +static int __devinit ehci_platform_probe(struct platform_device *dev)
142 + struct usb_hcd *hcd;
143 + struct resource *res_mem;
147 + if (usb_disabled())
150 + irq = platform_get_irq(dev, 0);
152 + pr_err("no irq provieded");
155 + res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
157 + pr_err("no memory recourse provieded");
161 + hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
162 + dev_name(&dev->dev));
166 + hcd->rsrc_start = res_mem->start;
167 + hcd->rsrc_len = resource_size(res_mem);
169 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
170 + pr_err("controller already in use");
175 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
177 + goto err_release_region;
178 + err = usb_add_hcd(hcd, irq, IRQF_SHARED);
182 + platform_set_drvdata(dev, hcd);
187 + iounmap(hcd->regs);
189 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
195 +static int __devexit ehci_platform_remove(struct platform_device *dev)
197 + struct usb_hcd *hcd = platform_get_drvdata(dev);
199 + usb_remove_hcd(hcd);
200 + iounmap(hcd->regs);
201 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
203 + platform_set_drvdata(dev, NULL);
210 +static int ehci_platform_suspend(struct device *dev)
212 + struct usb_hcd *hcd = dev_get_drvdata(dev);
213 + bool wakeup = device_may_wakeup(dev);
215 + ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup);
219 +static int ehci_platform_resume(struct device *dev)
221 + struct usb_hcd *hcd = dev_get_drvdata(dev);
223 + ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
227 +#else /* !CONFIG_PM */
228 +#define ehci_platform_suspend NULL
229 +#define ehci_platform_resume NULL
230 +#endif /* CONFIG_PM */
232 +static const struct platform_device_id ehci_platform_table[] = {
233 + { "ehci-platform", 0 },
236 +MODULE_DEVICE_TABLE(platform, ehci_platform_table);
238 +static const struct dev_pm_ops ehci_platform_pm_ops = {
239 + .suspend = ehci_platform_suspend,
240 + .resume = ehci_platform_resume,
243 +static struct platform_driver ehci_platform_driver = {
244 + .id_table = ehci_platform_table,
245 + .probe = ehci_platform_probe,
246 + .remove = __devexit_p(ehci_platform_remove),
247 + .shutdown = usb_hcd_platform_shutdown,
249 + .owner = THIS_MODULE,
250 + .name = "ehci-platform",
251 + .pm = &ehci_platform_pm_ops,