oops. accidentally committed the wrong patch version
[openwrt.git] / target / linux / brcm47xx / patches-2.6.23 / 230-ohci-ssb.patch
1 From: Michael Buesch <mb@bu3sch.de>
2 Date: Wed, 10 Oct 2007 06:47:17 +0000 (-0700)
3 Subject: USB: ohci SSB bus glue
4 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Fralf%2Flinux.git;a=commitdiff_plain;h=c604e851486eabcbeb73e984279d436ce121fd5d
5
6 USB: ohci SSB bus glue
7
8 This adds SSB bus glue for the USB OHCI HCD.
9
10 Signed-off-by: Michael Buesch <mb@bu3sch.de>
11 Signed-off-by: John W. Linville <linville@tuxdriver.com>
12 Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
14 ---
15
16 Index: linux-2.6.23.17/drivers/usb/host/Kconfig
17 ===================================================================
18 --- linux-2.6.23.17.orig/drivers/usb/host/Kconfig
19 +++ linux-2.6.23.17/drivers/usb/host/Kconfig
20 @@ -154,6 +154,19 @@ config USB_OHCI_HCD_PCI
21 Enables support for PCI-bus plug-in USB controller cards.
22 If unsure, say Y.
23
24 +config USB_OHCI_HCD_SSB
25 + bool "OHCI support for Broadcom SSB OHCI core"
26 + depends on USB_OHCI_HCD && SSB && EXPERIMENTAL
27 + default n
28 + ---help---
29 + Support for the Sonics Silicon Backplane (SSB) attached
30 + Broadcom USB OHCI core.
31 +
32 + This device is present in some embedded devices with
33 + Broadcom based SSB bus.
34 +
35 + If unsure, say N.
36 +
37 config USB_OHCI_BIG_ENDIAN_DESC
38 bool
39 depends on USB_OHCI_HCD
40 Index: linux-2.6.23.17/drivers/usb/host/ohci-hcd.c
41 ===================================================================
42 --- linux-2.6.23.17.orig/drivers/usb/host/ohci-hcd.c
43 +++ linux-2.6.23.17/drivers/usb/host/ohci-hcd.c
44 @@ -926,11 +926,17 @@ MODULE_LICENSE ("GPL");
45 #define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
46 #endif
47
48 +#ifdef CONFIG_USB_OHCI_HCD_SSB
49 +#include "ohci-ssb.c"
50 +#define SSB_OHCI_DRIVER ssb_ohci_driver
51 +#endif
52 +
53 #if !defined(PCI_DRIVER) && \
54 !defined(PLATFORM_DRIVER) && \
55 !defined(OF_PLATFORM_DRIVER) && \
56 !defined(SA1111_DRIVER) && \
57 - !defined(PS3_SYSTEM_BUS_DRIVER)
58 + !defined(PS3_SYSTEM_BUS_DRIVER) && \
59 + !defined(SSB_OHCI_DRIVER)
60 #error "missing bus glue for ohci-hcd"
61 #endif
62
63 @@ -975,10 +981,20 @@ static int __init ohci_hcd_mod_init(void
64 goto error_pci;
65 #endif
66
67 +#ifdef SSB_OHCI_DRIVER
68 + retval = ssb_driver_register(&SSB_OHCI_DRIVER);
69 + if (retval)
70 + goto error_ssb;
71 +#endif
72 +
73 return retval;
74
75 /* Error path */
76 +#ifdef SSB_OHCI_DRIVER
77 + error_ssb:
78 +#endif
79 #ifdef PCI_DRIVER
80 + pci_unregister_driver(&PCI_DRIVER);
81 error_pci:
82 #endif
83 #ifdef SA1111_DRIVER
84 @@ -1003,6 +1019,9 @@ module_init(ohci_hcd_mod_init);
85
86 static void __exit ohci_hcd_mod_exit(void)
87 {
88 +#ifdef SSB_OHCI_DRIVER
89 + ssb_driver_unregister(&SSB_OHCI_DRIVER);
90 +#endif
91 #ifdef PCI_DRIVER
92 pci_unregister_driver(&PCI_DRIVER);
93 #endif
94 Index: linux-2.6.23.17/drivers/usb/host/ohci-ssb.c
95 ===================================================================
96 --- /dev/null
97 +++ linux-2.6.23.17/drivers/usb/host/ohci-ssb.c
98 @@ -0,0 +1,247 @@
99 +/*
100 + * Sonics Silicon Backplane
101 + * Broadcom USB-core OHCI driver
102 + *
103 + * Copyright 2007 Michael Buesch <mb@bu3sch.de>
104 + *
105 + * Derived from the OHCI-PCI driver
106 + * Copyright 1999 Roman Weissgaerber
107 + * Copyright 2000-2002 David Brownell
108 + * Copyright 1999 Linus Torvalds
109 + * Copyright 1999 Gregory P. Smith
110 + *
111 + * Derived from the USBcore related parts of Broadcom-SB
112 + * Copyright 2005 Broadcom Corporation
113 + *
114 + * Licensed under the GNU/GPL. See COPYING for details.
115 + */
116 +#include <linux/ssb/ssb.h>
117 +
118 +
119 +#define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29)
120 +
121 +struct ssb_ohci_device {
122 + struct ohci_hcd ohci; /* _must_ be at the beginning. */
123 +
124 + u32 enable_flags;
125 +};
126 +
127 +static inline
128 +struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd)
129 +{
130 + return (struct ssb_ohci_device *)(hcd->hcd_priv);
131 +}
132 +
133 +
134 +static int ssb_ohci_reset(struct usb_hcd *hcd)
135 +{
136 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
137 + struct ohci_hcd *ohci = &ohcidev->ohci;
138 + int err;
139 +
140 + ohci_hcd_init(ohci);
141 + err = ohci_init(ohci);
142 +
143 + return err;
144 +}
145 +
146 +static int ssb_ohci_start(struct usb_hcd *hcd)
147 +{
148 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
149 + struct ohci_hcd *ohci = &ohcidev->ohci;
150 + int err;
151 +
152 + err = ohci_run(ohci);
153 + if (err < 0) {
154 + ohci_err(ohci, "can't start\n");
155 + ohci_stop(hcd);
156 + }
157 +
158 + return err;
159 +}
160 +
161 +#ifdef CONFIG_PM
162 +static int ssb_ohci_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
163 +{
164 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
165 + struct ohci_hcd *ohci = &ohcidev->ohci;
166 + unsigned long flags;
167 +
168 + spin_lock_irqsave(&ohci->lock, flags);
169 +
170 + ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable);
171 + ohci_readl(ohci, &ohci->regs->intrdisable); /* commit write */
172 +
173 + /* make sure snapshot being resumed re-enumerates everything */
174 + if (message.event == PM_EVENT_PRETHAW)
175 + ohci_usb_reset(ohci);
176 +
177 + clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
178 +
179 + spin_unlock_irqrestore(&ohci->lock, flags);
180 + return 0;
181 +}
182 +
183 +static int ssb_ohci_hcd_resume(struct usb_hcd *hcd)
184 +{
185 + set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
186 + usb_hcd_resume_root_hub(hcd);
187 + return 0;
188 +}
189 +#endif /* CONFIG_PM */
190 +
191 +static const struct hc_driver ssb_ohci_hc_driver = {
192 + .description = "ssb-usb-ohci",
193 + .product_desc = "SSB OHCI Controller",
194 + .hcd_priv_size = sizeof(struct ssb_ohci_device),
195 +
196 + .irq = ohci_irq,
197 + .flags = HCD_MEMORY | HCD_USB11,
198 +
199 + .reset = ssb_ohci_reset,
200 + .start = ssb_ohci_start,
201 + .stop = ohci_stop,
202 + .shutdown = ohci_shutdown,
203 +
204 +#ifdef CONFIG_PM
205 + .suspend = ssb_ohci_hcd_suspend,
206 + .resume = ssb_ohci_hcd_resume,
207 +#endif
208 +
209 + .urb_enqueue = ohci_urb_enqueue,
210 + .urb_dequeue = ohci_urb_dequeue,
211 + .endpoint_disable = ohci_endpoint_disable,
212 +
213 + .get_frame_number = ohci_get_frame,
214 +
215 + .hub_status_data = ohci_hub_status_data,
216 + .hub_control = ohci_hub_control,
217 + .hub_irq_enable = ohci_rhsc_enable,
218 + .bus_suspend = ohci_bus_suspend,
219 + .bus_resume = ohci_bus_resume,
220 +
221 + .start_port_reset = ohci_start_port_reset,
222 +};
223 +
224 +static void ssb_ohci_detach(struct ssb_device *dev)
225 +{
226 + struct usb_hcd *hcd = ssb_get_drvdata(dev);
227 +
228 + usb_remove_hcd(hcd);
229 + iounmap(hcd->regs);
230 + usb_put_hcd(hcd);
231 + ssb_device_disable(dev, 0);
232 +}
233 +
234 +static int ssb_ohci_attach(struct ssb_device *dev)
235 +{
236 + struct ssb_ohci_device *ohcidev;
237 + struct usb_hcd *hcd;
238 + int err = -ENOMEM;
239 + u32 tmp, flags = 0;
240 +
241 + if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
242 + flags |= SSB_OHCI_TMSLOW_HOSTMODE;
243 +
244 + ssb_device_enable(dev, flags);
245 +
246 + hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
247 + dev->dev->bus_id);
248 + if (!hcd)
249 + goto err_dev_disable;
250 + ohcidev = hcd_to_ssb_ohci(hcd);
251 + ohcidev->enable_flags = flags;
252 +
253 + tmp = ssb_read32(dev, SSB_ADMATCH0);
254 + hcd->rsrc_start = ssb_admatch_base(tmp);
255 + hcd->rsrc_len = ssb_admatch_size(tmp);
256 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
257 + if (!hcd->regs)
258 + goto err_put_hcd;
259 + err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
260 + if (err)
261 + goto err_iounmap;
262 +
263 + ssb_set_drvdata(dev, hcd);
264 +
265 + return err;
266 +
267 +err_iounmap:
268 + iounmap(hcd->regs);
269 +err_put_hcd:
270 + usb_put_hcd(hcd);
271 +err_dev_disable:
272 + ssb_device_disable(dev, flags);
273 + return err;
274 +}
275 +
276 +static int ssb_ohci_probe(struct ssb_device *dev,
277 + const struct ssb_device_id *id)
278 +{
279 + int err;
280 + u16 chipid_top;
281 +
282 + /* USBcores are only connected on embedded devices. */
283 + chipid_top = (dev->bus->chip_id & 0xFF00);
284 + if (chipid_top != 0x4700 && chipid_top != 0x5300)
285 + return -ENODEV;
286 +
287 + /* TODO: Probably need checks here; is the core connected? */
288 +
289 + if (usb_disabled())
290 + return -ENODEV;
291 +
292 + /* We currently always attach SSB_DEV_USB11_HOSTDEV
293 + * as HOST OHCI. If we want to attach it as Client device,
294 + * we must branch here and call into the (yet to
295 + * be written) Client mode driver. Same for remove(). */
296 +
297 + err = ssb_ohci_attach(dev);
298 +
299 + return err;
300 +}
301 +
302 +static void ssb_ohci_remove(struct ssb_device *dev)
303 +{
304 + ssb_ohci_detach(dev);
305 +}
306 +
307 +#ifdef CONFIG_PM
308 +
309 +static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
310 +{
311 + ssb_device_disable(dev, 0);
312 +
313 + return 0;
314 +}
315 +
316 +static int ssb_ohci_resume(struct ssb_device *dev)
317 +{
318 + struct usb_hcd *hcd = ssb_get_drvdata(dev);
319 + struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
320 +
321 + ssb_device_enable(dev, ohcidev->enable_flags);
322 +
323 + return 0;
324 +}
325 +
326 +#else /* !CONFIG_PM */
327 +#define ssb_ohci_suspend NULL
328 +#define ssb_ohci_resume NULL
329 +#endif /* CONFIG_PM */
330 +
331 +static const struct ssb_device_id ssb_ohci_table[] = {
332 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
333 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
334 + SSB_DEVTABLE_END
335 +};
336 +MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
337 +
338 +static struct ssb_driver ssb_ohci_driver = {
339 + .name = KBUILD_MODNAME,
340 + .id_table = ssb_ohci_table,
341 + .probe = ssb_ohci_probe,
342 + .remove = ssb_ohci_remove,
343 + .suspend = ssb_ohci_suspend,
344 + .resume = ssb_ohci_resume,
345 +};
This page took 0.060994 seconds and 5 git commands to generate.