kernel: update to kernel version 3.0.1
[openwrt.git] / target / linux / brcm47xx / patches-3.0 / 022-USB-Add-ehci-ssb-driver.patch
1 --- a/drivers/usb/host/Kconfig
2 +++ b/drivers/usb/host/Kconfig
3 @@ -230,6 +230,19 @@ config USB_OXU210HP_HCD
4 To compile this driver as a module, choose M here: the
5 module will be called oxu210hp-hcd.
6
7 +config USB_EHCI_HCD_SSB
8 + bool "EHCI support for Broadcom SSB EHCI core"
9 + depends on USB_EHCI_HCD && (SSB = y || SSB = USB_EHCI_HCD) && EXPERIMENTAL
10 + default n
11 + ---help---
12 + Support for the Sonics Silicon Backplane (SSB) attached
13 + Broadcom USB EHCI core.
14 +
15 + This device is present in some embedded devices with
16 + Broadcom based SSB bus.
17 +
18 + If unsure, say N.
19 +
20 config USB_ISP116X_HCD
21 tristate "ISP116X HCD support"
22 depends on USB
23 --- a/drivers/usb/host/ehci-hcd.c
24 +++ b/drivers/usb/host/ehci-hcd.c
25 @@ -1284,9 +1284,14 @@ MODULE_LICENSE ("GPL");
26 #define PLATFORM_DRIVER ehci_grlib_driver
27 #endif
28
29 +#ifdef CONFIG_USB_EHCI_HCD_SSB
30 +#include "ehci-ssb.c"
31 +#define SSB_EHCI_DRIVER ssb_ehci_driver
32 +#endif
33 +
34 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
35 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
36 - !defined(XILINX_OF_PLATFORM_DRIVER)
37 + !defined(XILINX_OF_PLATFORM_DRIVER) && !defined(SSB_EHCI_DRIVER)
38 #error "missing bus glue for ehci-hcd"
39 #endif
40
41 @@ -1346,10 +1351,20 @@ static int __init ehci_hcd_init(void)
42 if (retval < 0)
43 goto clean4;
44 #endif
45 +
46 +#ifdef SSB_EHCI_DRIVER
47 + retval = ssb_driver_register(&SSB_EHCI_DRIVER);
48 + if (retval < 0)
49 + goto clean5;
50 +#endif
51 return retval;
52
53 +#ifdef SSB_EHCI_DRIVER
54 + /* ssb_driver_unregister(&SSB_EHCI_DRIVER); */
55 +clean5:
56 +#endif
57 #ifdef XILINX_OF_PLATFORM_DRIVER
58 - /* platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER); */
59 + platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
60 clean4:
61 #endif
62 #ifdef OF_PLATFORM_DRIVER
63 @@ -1380,6 +1395,9 @@ module_init(ehci_hcd_init);
64
65 static void __exit ehci_hcd_cleanup(void)
66 {
67 +#ifdef SSB_EHCI_DRIVER
68 + ssb_driver_unregister(&SSB_EHCI_DRIVER);
69 +#endif
70 #ifdef XILINX_OF_PLATFORM_DRIVER
71 platform_driver_unregister(&XILINX_OF_PLATFORM_DRIVER);
72 #endif
73 --- /dev/null
74 +++ b/drivers/usb/host/ehci-ssb.c
75 @@ -0,0 +1,255 @@
76 +/*
77 + * Sonics Silicon Backplane
78 + * Broadcom USB-core EHCI driver (SSB bus glue)
79 + *
80 + * Copyright 2007 Steven Brown <sbrown@cortland.com>
81 + * Copyright 2010 Hauke Mehrtens <hauke@hauke-m.de>
82 + *
83 + * Derived from the OHCI-SSB driver
84 + * Copyright 2007 Michael Buesch <mb@bu3sch.de>
85 + *
86 + * Derived from the EHCI-PCI driver
87 + * Copyright (c) 2000-2004 by David Brownell
88 + *
89 + * Derived from the OHCI-PCI driver
90 + * Copyright 1999 Roman Weissgaerber
91 + * Copyright 2000-2002 David Brownell
92 + * Copyright 1999 Linus Torvalds
93 + * Copyright 1999 Gregory P. Smith
94 + *
95 + * Derived from the USBcore related parts of Broadcom-SB
96 + * Copyright 2005 Broadcom Corporation
97 + *
98 + * Licensed under the GNU/GPL. See COPYING for details.
99 + */
100 +#include <linux/ssb/ssb.h>
101 +
102 +
103 +struct ssb_ehci_device {
104 + struct ehci_hcd ehci; /* _must_ be at the beginning. */
105 +};
106 +
107 +static inline
108 +struct ssb_ehci_device *hcd_to_ssb_ehci(struct usb_hcd *hcd)
109 +{
110 + return (struct ssb_ehci_device *)(hcd->hcd_priv);
111 +}
112 +
113 +static int ssb_ehci_reset(struct usb_hcd *hcd)
114 +{
115 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
116 + int err;
117 +
118 + ehci->caps = hcd->regs;
119 + ehci->regs = hcd->regs +
120 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
121 +
122 + dbg_hcs_params(ehci, "reset");
123 + dbg_hcc_params(ehci, "reset");
124 +
125 + ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
126 +
127 + err = ehci_halt(ehci);
128 +
129 + if (err)
130 + return err;
131 +
132 + err = ehci_init(hcd);
133 +
134 + if (err)
135 + return err;
136 +
137 + ehci_reset(ehci);
138 +
139 + return err;
140 +}
141 +
142 +static const struct hc_driver ssb_ehci_hc_driver = {
143 + .description = "ssb-usb-ehci",
144 + .product_desc = "SSB EHCI Controller",
145 + .hcd_priv_size = sizeof(struct ssb_ehci_device),
146 +
147 + .irq = ehci_irq,
148 + .flags = HCD_MEMORY | HCD_USB2,
149 +
150 + .reset = ssb_ehci_reset,
151 + .start = ehci_run,
152 + .stop = ehci_stop,
153 + .shutdown = ehci_shutdown,
154 +
155 + .urb_enqueue = ehci_urb_enqueue,
156 + .urb_dequeue = ehci_urb_dequeue,
157 + .endpoint_disable = ehci_endpoint_disable,
158 + .endpoint_reset = ehci_endpoint_reset,
159 +
160 + .get_frame_number = ehci_get_frame,
161 +
162 + .hub_status_data = ehci_hub_status_data,
163 + .hub_control = ehci_hub_control,
164 +#if defined(CONFIG_PM)
165 + .bus_suspend = ehci_bus_suspend,
166 + .bus_resume = ehci_bus_resume,
167 +#endif
168 + .relinquish_port = ehci_relinquish_port,
169 + .port_handed_over = ehci_port_handed_over,
170 +
171 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
172 +};
173 +
174 +static void ssb_ehci_detach(struct ssb_device *dev)
175 +{
176 + struct usb_hcd *hcd = ssb_get_drvdata(dev);
177 +
178 + if (hcd->driver->shutdown)
179 + hcd->driver->shutdown(hcd);
180 + usb_remove_hcd(hcd);
181 + iounmap(hcd->regs);
182 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
183 + usb_put_hcd(hcd);
184 + ssb_device_disable(dev, 0);
185 +}
186 +
187 +static int ssb_ehci_attach(struct ssb_device *dev)
188 +{
189 + struct ssb_ehci_device *ehcidev;
190 + struct usb_hcd *hcd;
191 + int err = -ENOMEM;
192 + u32 tmp;
193 +
194 + if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
195 + dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
196 + return -EOPNOTSUPP;
197 +
198 + /*
199 + * USB 2.0 special considerations:
200 + *
201 + * In addition to the standard SSB reset sequence, the Host Control
202 + * Register must be programmed to bring the USB core and various phy
203 + * components out of reset.
204 + */
205 + ssb_device_enable(dev, 0);
206 + ssb_write32(dev, 0x200, 0x7ff);
207 +
208 + /* Change Flush control reg */
209 + tmp = ssb_read32(dev, 0x400);
210 + tmp &= ~8;
211 + ssb_write32(dev, 0x400, tmp);
212 + tmp = ssb_read32(dev, 0x400);
213 +
214 + /* Change Shim control reg */
215 + tmp = ssb_read32(dev, 0x304);
216 + tmp &= ~0x100;
217 + ssb_write32(dev, 0x304, tmp);
218 + tmp = ssb_read32(dev, 0x304);
219 +
220 + udelay(1);
221 +
222 + /* Work around for 5354 failures */
223 + if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) {
224 + /* Change syn01 reg */
225 + tmp = 0x00fe00fe;
226 + ssb_write32(dev, 0x894, tmp);
227 +
228 + /* Change syn03 reg */
229 + tmp = ssb_read32(dev, 0x89c);
230 + tmp |= 0x1;
231 + ssb_write32(dev, 0x89c, tmp);
232 + }
233 +
234 + hcd = usb_create_hcd(&ssb_ehci_hc_driver, dev->dev,
235 + dev_name(dev->dev));
236 + if (!hcd)
237 + goto err_dev_disable;
238 +
239 + ehcidev = hcd_to_ssb_ehci(hcd);
240 + tmp = ssb_read32(dev, SSB_ADMATCH0);
241 + hcd->rsrc_start = ssb_admatch_base(tmp) + 0x800; /* ehci core offset */
242 + hcd->rsrc_len = 0x100; /* ehci reg block size */
243 + /*
244 + * start & size modified per sbutils.c
245 + */
246 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
247 + if (!hcd->regs)
248 + goto err_put_hcd;
249 + err = usb_add_hcd(hcd, dev->irq, IRQF_DISABLED | IRQF_SHARED);
250 + if (err)
251 + goto err_iounmap;
252 +
253 + ssb_set_drvdata(dev, hcd);
254 +
255 + return err;
256 +
257 +err_iounmap:
258 + iounmap(hcd->regs);
259 +err_put_hcd:
260 + usb_put_hcd(hcd);
261 +err_dev_disable:
262 + ssb_device_disable(dev, 0);
263 + return err;
264 +}
265 +
266 +static int ssb_ehci_probe(struct ssb_device *dev,
267 + const struct ssb_device_id *id)
268 +{
269 + int err;
270 + u16 chipid_top;
271 +
272 + /* USBcores are only connected on embedded devices. */
273 + chipid_top = (dev->bus->chip_id & 0xFF00);
274 + if (chipid_top != 0x4700 && chipid_top != 0x5300)
275 + return -ENODEV;
276 +
277 + /* TODO: Probably need checks here; is the core connected? */
278 +
279 + if (usb_disabled())
280 + return -ENODEV;
281 +
282 + err = ssb_ehci_attach(dev);
283 +
284 + return err;
285 +}
286 +
287 +static void ssb_ehci_remove(struct ssb_device *dev)
288 +{
289 + ssb_ehci_detach(dev);
290 +}
291 +
292 +#ifdef CONFIG_PM
293 +
294 +static int ssb_ehci_suspend(struct ssb_device *dev, pm_message_t state)
295 +{
296 + ssb_device_disable(dev, 0);
297 +
298 + return 0;
299 +}
300 +
301 +static int ssb_ehci_resume(struct ssb_device *dev)
302 +{
303 + struct usb_hcd *hcd = ssb_get_drvdata(dev);
304 + struct ssb_ehci_device *ehcidev = hcd_to_ssb_ehci(hcd);
305 +
306 + ssb_device_enable(dev, 0);
307 +
308 + ehci_finish_controller_resume(hcd);
309 + return 0;
310 +}
311 +
312 +#else /* !CONFIG_PM */
313 +#define ssb_ehci_suspend NULL
314 +#define ssb_ehci_resume NULL
315 +#endif /* CONFIG_PM */
316 +
317 +static const struct ssb_device_id ssb_ehci_table[] = {
318 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV),
319 + SSB_DEVTABLE_END
320 +};
321 +MODULE_DEVICE_TABLE(ssb, ssb_ehci_table);
322 +
323 +static struct ssb_driver ssb_ehci_driver = {
324 + .name = KBUILD_MODNAME,
325 + .id_table = ssb_ehci_table,
326 + .probe = ssb_ehci_probe,
327 + .remove = ssb_ehci_remove,
328 + .suspend = ssb_ehci_suspend,
329 + .resume = ssb_ehci_resume,
330 +};
This page took 0.064257 seconds and 5 git commands to generate.