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