1 From aa05e0048cec25719921291e8749674b8cc66fc0 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 18/21] 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 | 211 ++++++++++++++++++++++++++++++++++++++
16 3 files changed, 226 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 @@ -1312,6 +1312,11 @@ MODULE_LICENSE ("GPL");
41 #define PLATFORM_DRIVER ehci_grlib_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-2011 Hauke Mehrtens <hauke@hauke-m.de>
61 + * Derived from the ohci-ssb driver
62 + * Copyright 2007 Michael Buesch <mb@bu3sch.de>
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>
77 +static int ehci_platform_reset(struct usb_hcd *hcd)
79 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
82 + ehci->caps = hcd->regs;
83 + ehci->regs = hcd->regs +
84 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
86 + dbg_hcs_params(ehci, "reset");
87 + dbg_hcc_params(ehci, "reset");
89 + /* cache this readonly data; minimize chip reads */
90 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
92 + retval = ehci_halt(ehci);
96 + /* data structure init */
97 + retval = ehci_init(hcd);
103 + ehci_port_power(ehci, 1);
108 +static const struct hc_driver ehci_platform_hc_driver = {
109 + .description = "platform-usb-ehci",
110 + .product_desc = "Generic Platform EHCI Controller",
111 + .hcd_priv_size = sizeof(struct ehci_hcd),
114 + .flags = HCD_MEMORY | HCD_USB2,
116 + .reset = ehci_platform_reset,
119 + .shutdown = ehci_shutdown,
121 + .urb_enqueue = ehci_urb_enqueue,
122 + .urb_dequeue = ehci_urb_dequeue,
123 + .endpoint_disable = ehci_endpoint_disable,
124 + .endpoint_reset = ehci_endpoint_reset,
126 + .get_frame_number = ehci_get_frame,
128 + .hub_status_data = ehci_hub_status_data,
129 + .hub_control = ehci_hub_control,
130 +#if defined(CONFIG_PM)
131 + .bus_suspend = ehci_bus_suspend,
132 + .bus_resume = ehci_bus_resume,
134 + .relinquish_port = ehci_relinquish_port,
135 + .port_handed_over = ehci_port_handed_over,
137 + .update_device = ehci_update_device,
139 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
142 +static int ehci_platform_attach(struct platform_device *dev)
144 + struct usb_hcd *hcd;
145 + struct resource *res_irq, *res_mem;
148 + hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
149 + dev_name(&dev->dev));
153 + res_irq = platform_get_resource(dev, IORESOURCE_IRQ, 0);
158 + res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
163 + hcd->rsrc_start = res_mem->start;
164 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
167 + * start & size modified per sbutils.c
169 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
172 + err = usb_add_hcd(hcd, res_irq->start, IRQF_SHARED);
176 + platform_set_drvdata(dev, hcd);
181 + iounmap(hcd->regs);
188 +static int ehci_platform_probe(struct platform_device *dev)
192 + if (usb_disabled())
195 + err = ehci_platform_attach(dev);
200 +static int ehci_platform_remove(struct platform_device *dev)
202 + struct usb_hcd *hcd;
204 + hcd = platform_get_drvdata(dev);
208 + usb_remove_hcd(hcd);
209 + iounmap(hcd->regs);
210 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
216 +static void ehci_platform_shutdown(struct platform_device *dev)
218 + struct usb_hcd *hcd;
220 + hcd = platform_get_drvdata(dev);
224 + if (hcd->driver->shutdown)
225 + hcd->driver->shutdown(hcd);
230 +static int ehci_platform_suspend(struct platform_device *dev,
231 + pm_message_t state)
236 +static int ehci_platform_resume(struct platform_device *dev)
238 + struct usb_hcd *hcd = platform_get_drvdata(dev);
240 + ehci_finish_controller_resume(hcd);
244 +#else /* !CONFIG_PM */
245 +#define ehci_platform_suspend NULL
246 +#define ehci_platform_resume NULL
247 +#endif /* CONFIG_PM */
249 +static const struct platform_device_id ehci_platform_table[] = {
250 + { "ehci-platform", 0 },
253 +MODULE_DEVICE_TABLE(platform, ehci_platform_table);
255 +static struct platform_driver ehci_platform_driver = {
256 + .id_table = ehci_platform_table,
257 + .probe = ehci_platform_probe,
258 + .remove = ehci_platform_remove,
259 + .shutdown = ehci_platform_shutdown,
260 + .suspend = ehci_platform_suspend,
261 + .resume = ehci_platform_resume,
263 + .name = "ehci-platform",