ixp4xx: add support for linux 3.3.1
[openwrt.git] / target / linux / brcm47xx / patches-3.0 / 0030-USB-OHCI-Add-a-generic-platform-device-driver.patch
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
5
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.
10
11 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
12 ---
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
18
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.
24  
25 +config USB_OHCI_HCD_PLATFORM
26 +       bool "OHCI driver for a platform device"
27 +       depends on USB_OHCI_HCD && EXPERIMENTAL
28 +       default n
29 +       ---help---
30 +         Adds an OHCI host driver for a generic platform device, which
31 +         provieds a memory space and an irq.
32 +
33 +         If unsure, say N.
34 +
35  config USB_OHCI_BIG_ENDIAN_DESC
36         bool
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
42  #endif
43  
44 +#ifdef CONFIG_USB_OHCI_HCD_PLATFORM
45 +#include "ohci-platform.c"
46 +#define PLATFORM_OHCI_DRIVER   ohci_platform_driver
47 +#endif
48 +
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"
60  #endif
61  
62 @@ -1204,9 +1210,19 @@ static int __init ohci_hcd_mod_init(void
63                 goto error_tmio;
64  #endif
65  
66 +#ifdef PLATFORM_OHCI_DRIVER
67 +       retval = platform_driver_register(&PLATFORM_OHCI_DRIVER);
68 +       if (retval)
69 +               goto error_platform;
70 +#endif
71 +
72         return retval;
73  
74         /* Error path */
75 +#ifdef PLATFORM_OHCI_DRIVER
76 +       platform_driver_unregister(&PLATFORM_OHCI_DRIVER);
77 + error_platform:
78 +#endif
79  #ifdef TMIO_OHCI_DRIVER
80         platform_driver_unregister(&TMIO_OHCI_DRIVER);
81   error_tmio:
82 @@ -1260,6 +1276,9 @@ module_init(ohci_hcd_mod_init);
83  
84  static void __exit ohci_hcd_mod_exit(void)
85  {
86 +#ifdef PLATFORM_OHCI_DRIVER
87 +       platform_driver_unregister(&PLATFORM_OHCI_DRIVER);
88 +#endif
89  #ifdef TMIO_OHCI_DRIVER
90         platform_driver_unregister(&TMIO_OHCI_DRIVER);
91  #endif
92 --- /dev/null
93 +++ b/drivers/usb/host/ohci-platform.c
94 @@ -0,0 +1,197 @@
95 +/*
96 + * Generic platform ohci driver
97 + *
98 + * Copyright 2007 Michael Buesch <m@bues.ch>
99 + * Copyright 2011 Hauke Mehrtens <hauke@hauke-m.de>
100 + *
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
106 + *
107 + * Licensed under the GNU/GPL. See COPYING for details.
108 + */
109 +#include <linux/platform_device.h>
110 +
111 +static int ohci_platform_reset(struct usb_hcd *hcd)
112 +{
113 +       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
114 +       int err;
115 +
116 +       ohci_hcd_init(ohci);
117 +       err = ohci_init(ohci);
118 +
119 +       return err;
120 +}
121 +
122 +static int ohci_platform_start(struct usb_hcd *hcd)
123 +{
124 +       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
125 +       int err;
126 +
127 +       err = ohci_run(ohci);
128 +       if (err < 0) {
129 +               ohci_err(ohci, "can't start\n");
130 +               ohci_stop(hcd);
131 +       }
132 +
133 +       return err;
134 +}
135 +
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),
140 +
141 +       .irq                    = ohci_irq,
142 +       .flags                  = HCD_MEMORY | HCD_USB11,
143 +
144 +       .reset                  = ohci_platform_reset,
145 +       .start                  = ohci_platform_start,
146 +       .stop                   = ohci_stop,
147 +       .shutdown               = ohci_shutdown,
148 +
149 +       .urb_enqueue            = ohci_urb_enqueue,
150 +       .urb_dequeue            = ohci_urb_dequeue,
151 +       .endpoint_disable       = ohci_endpoint_disable,
152 +
153 +       .get_frame_number       = ohci_get_frame,
154 +
155 +       .hub_status_data        = ohci_hub_status_data,
156 +       .hub_control            = ohci_hub_control,
157 +#ifdef CONFIG_PM
158 +       .bus_suspend            = ohci_bus_suspend,
159 +       .bus_resume             = ohci_bus_resume,
160 +#endif
161 +
162 +       .start_port_reset       = ohci_start_port_reset,
163 +};
164 +
165 +static int ohci_platform_attach(struct platform_device *dev)
166 +{
167 +       struct usb_hcd *hcd;
168 +       struct resource *res_irq, *res_mem;
169 +       int err = -ENOMEM;
170 +
171 +       hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
172 +                       dev_name(&dev->dev));
173 +       if (!hcd)
174 +               goto err_return;
175 +
176 +       res_irq = platform_get_resource(dev, IORESOURCE_IRQ, 0);
177 +       if (!res_irq) {
178 +               err = -ENXIO;
179 +               goto err_return;
180 +       }
181 +       res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
182 +       if (!res_mem) {
183 +               err = -ENXIO;
184 +               goto err_return;
185 +       }
186 +       hcd->rsrc_start = res_mem->start;
187 +       hcd->rsrc_len = res_mem->end - res_mem->start + 1;
188 +
189 +       hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
190 +       if (!hcd->regs)
191 +               goto err_put_hcd;
192 +       err = usb_add_hcd(hcd, res_irq->start, IRQF_SHARED);
193 +       if (err)
194 +               goto err_iounmap;
195 +
196 +       platform_set_drvdata(dev, hcd);
197 +
198 +       return err;
199 +
200 +err_iounmap:
201 +       iounmap(hcd->regs);
202 +err_put_hcd:
203 +       usb_put_hcd(hcd);
204 +err_return:
205 +       return err;
206 +}
207 +
208 +static int ohci_platform_probe(struct platform_device *dev)
209 +{
210 +       int err;
211 +
212 +       if (usb_disabled())
213 +               return -ENODEV;
214 +
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(). */
219 +
220 +       err = ohci_platform_attach(dev);
221 +
222 +       return err;
223 +}
224 +
225 +static int ohci_platform_remove(struct platform_device *dev)
226 +{
227 +       struct usb_hcd *hcd;
228 +
229 +       hcd = platform_get_drvdata(dev);
230 +       if (!hcd)
231 +               return -ENODEV;
232 +
233 +       usb_remove_hcd(hcd);
234 +       iounmap(hcd->regs);
235 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
236 +       usb_put_hcd(hcd);
237 +
238 +       return 0;
239 +}
240 +
241 +static void ohci_platform_shutdown(struct platform_device *dev)
242 +{
243 +       struct usb_hcd *hcd;
244 +
245 +       hcd = platform_get_drvdata(dev);
246 +       if (!hcd)
247 +               return;
248 +
249 +       if (hcd->driver->shutdown)
250 +               hcd->driver->shutdown(hcd);
251 +}
252 +
253 +#ifdef CONFIG_PM
254 +
255 +static int ohci_platform_suspend(struct platform_device *dev,
256 +                                pm_message_t state)
257 +{
258 +
259 +       return 0;
260 +}
261 +
262 +static int ohci_platform_resume(struct platform_device *dev)
263 +{
264 +       struct usb_hcd *hcd = platform_get_drvdata(dev);
265 +
266 +       ohci_finish_controller_resume(hcd);
267 +       return 0;
268 +}
269 +
270 +#else /* !CONFIG_PM */
271 +#define ohci_platform_suspend  NULL
272 +#define ohci_platform_resume   NULL
273 +#endif /* CONFIG_PM */
274 +
275 +static const struct platform_device_id ohci_platform_table[] = {
276 +       { "ohci-platform", 0 },
277 +       { }
278 +};
279 +MODULE_DEVICE_TABLE(platform, ohci_platform_table);
280 +
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,
288 +       .driver         = {
289 +               .name   = "ohci-platform",
290 +       }
291 +};