1 From b39adeae5b06e40699c174ed78ca7c45b8d7976f Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 26 Nov 2011 21:20:54 +0100
4 Subject: [PATCH 17/21] USB: OHCI: 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 OHCI controller works like a PCI controller. It will be
9 used for the Broadcom bcma and ssb USB OHCI controller.
11 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
13 drivers/usb/host/Kconfig | 10 ++
14 drivers/usb/host/ohci-hcd.c | 21 ++++-
15 drivers/usb/host/ohci-platform.c | 197 ++++++++++++++++++++++++++++++++++++++
16 3 files changed, 227 insertions(+), 1 deletions(-)
17 create mode 100644 drivers/usb/host/ohci-platform.c
19 --- a/drivers/usb/host/Kconfig
20 +++ b/drivers/usb/host/Kconfig
21 @@ -378,6 +378,16 @@ config USB_CNS3XXX_OHCI
22 Enable support for the CNS3XXX SOC's on-chip OHCI controller.
23 It is needed for low-speed USB 1.0 device support.
25 +config USB_OHCI_HCD_PLATFORM
26 + bool "OHCI driver for a platform device"
27 + depends on USB_OHCI_HCD && EXPERIMENTAL
30 + Adds an OHCI 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/ohci-hcd.c
39 +++ b/drivers/usb/host/ohci-hcd.c
40 @@ -1111,6 +1111,11 @@ MODULE_LICENSE ("GPL");
41 #define PLATFORM_DRIVER ohci_hcd_ath79_driver
44 +#ifdef CONFIG_USB_OHCI_HCD_PLATFORM
45 +#include "ohci-platform.c"
46 +#define PLATFORM_OHCI_DRIVER ohci_platform_driver
49 #if !defined(PCI_DRIVER) && \
50 !defined(PLATFORM_DRIVER) && \
51 !defined(OMAP1_PLATFORM_DRIVER) && \
52 @@ -1120,7 +1125,8 @@ MODULE_LICENSE ("GPL");
53 !defined(PS3_SYSTEM_BUS_DRIVER) && \
54 !defined(SM501_OHCI_DRIVER) && \
55 !defined(TMIO_OHCI_DRIVER) && \
56 - !defined(SSB_OHCI_DRIVER)
57 + !defined(SSB_OHCI_DRIVER) && \
58 + !defined(PLATFORM_OHCI_DRIVER)
59 #error "missing bus glue for ohci-hcd"
62 @@ -1204,9 +1210,19 @@ static int __init ohci_hcd_mod_init(void
66 +#ifdef PLATFORM_OHCI_DRIVER
67 + retval = platform_driver_register(&PLATFORM_OHCI_DRIVER);
69 + goto error_platform;
75 +#ifdef PLATFORM_OHCI_DRIVER
76 + platform_driver_unregister(&PLATFORM_OHCI_DRIVER);
79 #ifdef TMIO_OHCI_DRIVER
80 platform_driver_unregister(&TMIO_OHCI_DRIVER);
82 @@ -1260,6 +1276,9 @@ module_init(ohci_hcd_mod_init);
84 static void __exit ohci_hcd_mod_exit(void)
86 +#ifdef PLATFORM_OHCI_DRIVER
87 + platform_driver_unregister(&PLATFORM_OHCI_DRIVER);
89 #ifdef TMIO_OHCI_DRIVER
90 platform_driver_unregister(&TMIO_OHCI_DRIVER);
93 +++ b/drivers/usb/host/ohci-platform.c
96 + * Generic platform ohci driver
98 + * Copyright 2007 Michael Buesch <m@bues.ch>
99 + * Copyright 2011 Hauke Mehrtens <hauke@hauke-m.de>
101 + * Derived from the OHCI-PCI driver
102 + * Copyright 1999 Roman Weissgaerber
103 + * Copyright 2000-2002 David Brownell
104 + * Copyright 1999 Linus Torvalds
105 + * Copyright 1999 Gregory P. Smith
107 + * Licensed under the GNU/GPL. See COPYING for details.
109 +#include <linux/platform_device.h>
111 +static int ohci_platform_reset(struct usb_hcd *hcd)
113 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
116 + ohci_hcd_init(ohci);
117 + err = ohci_init(ohci);
122 +static int ohci_platform_start(struct usb_hcd *hcd)
124 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
127 + err = ohci_run(ohci);
129 + ohci_err(ohci, "can't start\n");
136 +static const struct hc_driver ohci_platform_hc_driver = {
137 + .description = "platform-usb-ohci",
138 + .product_desc = "Generic Platform OHCI Controller",
139 + .hcd_priv_size = sizeof(struct ohci_hcd),
142 + .flags = HCD_MEMORY | HCD_USB11,
144 + .reset = ohci_platform_reset,
145 + .start = ohci_platform_start,
147 + .shutdown = ohci_shutdown,
149 + .urb_enqueue = ohci_urb_enqueue,
150 + .urb_dequeue = ohci_urb_dequeue,
151 + .endpoint_disable = ohci_endpoint_disable,
153 + .get_frame_number = ohci_get_frame,
155 + .hub_status_data = ohci_hub_status_data,
156 + .hub_control = ohci_hub_control,
158 + .bus_suspend = ohci_bus_suspend,
159 + .bus_resume = ohci_bus_resume,
162 + .start_port_reset = ohci_start_port_reset,
165 +static int ohci_platform_attach(struct platform_device *dev)
167 + struct usb_hcd *hcd;
168 + struct resource *res_irq, *res_mem;
171 + hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
172 + dev_name(&dev->dev));
176 + res_irq = platform_get_resource(dev, IORESOURCE_IRQ, 0);
181 + res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
186 + hcd->rsrc_start = res_mem->start;
187 + hcd->rsrc_len = res_mem->end - res_mem->start + 1;
189 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
192 + err = usb_add_hcd(hcd, res_irq->start, IRQF_SHARED);
196 + platform_set_drvdata(dev, hcd);
201 + iounmap(hcd->regs);
208 +static int ohci_platform_probe(struct platform_device *dev)
212 + if (usb_disabled())
215 + /* We currently always attach BCMA_DEV_USB11_HOSTDEV
216 + * as HOST OHCI. If we want to attach it as Client device,
217 + * we must branch here and call into the (yet to
218 + * be written) Client mode driver. Same for remove(). */
220 + err = ohci_platform_attach(dev);
225 +static int ohci_platform_remove(struct platform_device *dev)
227 + struct usb_hcd *hcd;
229 + hcd = platform_get_drvdata(dev);
233 + usb_remove_hcd(hcd);
234 + iounmap(hcd->regs);
235 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
241 +static void ohci_platform_shutdown(struct platform_device *dev)
243 + struct usb_hcd *hcd;
245 + hcd = platform_get_drvdata(dev);
249 + if (hcd->driver->shutdown)
250 + hcd->driver->shutdown(hcd);
255 +static int ohci_platform_suspend(struct platform_device *dev,
256 + pm_message_t state)
262 +static int ohci_platform_resume(struct platform_device *dev)
264 + struct usb_hcd *hcd = platform_get_drvdata(dev);
266 + ohci_finish_controller_resume(hcd);
270 +#else /* !CONFIG_PM */
271 +#define ohci_platform_suspend NULL
272 +#define ohci_platform_resume NULL
273 +#endif /* CONFIG_PM */
275 +static const struct platform_device_id ohci_platform_table[] = {
276 + { "ohci-platform", 0 },
279 +MODULE_DEVICE_TABLE(platform, ohci_platform_table);
281 +static struct platform_driver ohci_platform_driver = {
282 + .id_table = ohci_platform_table,
283 + .probe = ohci_platform_probe,
284 + .remove = ohci_platform_remove,
285 + .shutdown = ohci_platform_shutdown,
286 + .suspend = ohci_platform_suspend,
287 + .resume = ohci_platform_resume,
289 + .name = "ohci-platform",