imagebuilder: fix parallel building (closes #11117)
[openwrt.git] / target / linux / brcm47xx / patches-3.2 / 185-USB-Add-driver-for-the-ssb-bus.patch
1 From 1840ddf07a452e640549fbd82e2f570da28e377f Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 26 Nov 2011 21:35:17 +0100
4 Subject: [PATCH 185/186] USB: Add driver for the ssb bus
5
6 This adds a USB driver using the generic platform device driver for the
7 USB controller found on the Broadcom ssb bus. The ssb bus just
8 exposes one device which serves the OHCI and the EHCI controller at the
9 same time. This driver probes for this USB controller and creates and
10 registers two new platform devices which will be probed by the new
11 generic platform device driver. This makes it possible to use the EHCI
12 and the OCHI controller on the ssb bus at the same time.
13
14 The old ssb OHCI USB driver will be removed in the next step as this
15 driver also provide an OHCI driver and an EHCI for the cores supporting
16 it.
17
18 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
19 ---
20 drivers/usb/host/Kconfig | 12 ++
21 drivers/usb/host/Makefile | 1 +
22 drivers/usb/host/ssb-hcd.c | 273 ++++++++++++++++++++++++++++++++++++++++++++
23 3 files changed, 286 insertions(+), 0 deletions(-)
24 create mode 100644 drivers/usb/host/ssb-hcd.c
25
26 --- a/drivers/usb/host/Kconfig
27 +++ b/drivers/usb/host/Kconfig
28 @@ -630,3 +630,15 @@ config USB_HCD_BCMA
29 for ehci and ohci.
30
31 If unsure, say N.
32 +
33 +config USB_HCD_SSB
34 + tristate "SSB usb host driver"
35 + depends on SSB && EXPERIMENTAL
36 + select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
37 + select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
38 + help
39 + Enbale support for the EHCI and OCHI host controller on an bcma bus.
40 + It converts the bcma driver into two platform device drivers
41 + for ehci and ohci.
42 +
43 + If unsure, say N.
44 --- a/drivers/usb/host/Makefile
45 +++ b/drivers/usb/host/Makefile
46 @@ -38,3 +38,4 @@ obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-m
47 obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
48 obj-$(CONFIG_MIPS_ALCHEMY) += alchemy-common.o
49 obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o
50 +obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o
51 --- /dev/null
52 +++ b/drivers/usb/host/ssb-hcd.c
53 @@ -0,0 +1,273 @@
54 +/*
55 + * Sonics Silicon Backplane
56 + * Broadcom USB-core driver (SSB bus glue)
57 + *
58 + * Copyright 2011 Hauke Mehrtens <hauke@hauke-m.de>
59 + *
60 + * Based on ssb-ohci driver
61 + * Copyright 2007 Michael Buesch <m@bues.ch>
62 + *
63 + * Derived from the OHCI-PCI driver
64 + * Copyright 1999 Roman Weissgaerber
65 + * Copyright 2000-2002 David Brownell
66 + * Copyright 1999 Linus Torvalds
67 + * Copyright 1999 Gregory P. Smith
68 + *
69 + * Derived from the USBcore related parts of Broadcom-SB
70 + * Copyright 2005-2011 Broadcom Corporation
71 + *
72 + * Licensed under the GNU/GPL. See COPYING for details.
73 + */
74 +#include <linux/ssb/ssb.h>
75 +#include <linux/delay.h>
76 +#include <linux/platform_device.h>
77 +#include <linux/module.h>
78 +#include <linux/usb/hci_driver.h>
79 +
80 +MODULE_AUTHOR("Hauke Mehrtens");
81 +MODULE_DESCRIPTION("Common USB driver for SSB Bus");
82 +MODULE_LICENSE("GPL");
83 +
84 +#define SSB_HCD_TMSLOW_HOSTMODE (1 << 29)
85 +
86 +struct ssb_hcd_device {
87 + struct platform_device *ehci_dev;
88 + struct platform_device *ohci_dev;
89 +
90 + u32 enable_flags;
91 +};
92 +
93 +static void __devinit ssb_hcd_5354wa(struct ssb_device *dev)
94 +{
95 +#ifdef CONFIG_SSB_DRIVER_MIPS
96 + /* Work around for 5354 failures */
97 + if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) {
98 + /* Change syn01 reg */
99 + ssb_write32(dev, 0x894, 0x00fe00fe);
100 +
101 + /* Change syn03 reg */
102 + ssb_write32(dev, 0x89c, ssb_read32(dev, 0x89c) | 0x1);
103 + }
104 +#endif
105 +}
106 +
107 +static void __devinit ssb_hcd_usb20wa(struct ssb_device *dev)
108 +{
109 + if (dev->id.coreid == SSB_DEV_USB20_HOST) {
110 + /*
111 + * USB 2.0 special considerations:
112 + *
113 + * In addition to the standard SSB reset sequence, the Host
114 + * Control Register must be programmed to bring the USB core
115 + * and various phy components out of reset.
116 + */
117 + ssb_write32(dev, 0x200, 0x7ff);
118 +
119 + /* Change Flush control reg */
120 + ssb_write32(dev, 0x400, ssb_read32(dev, 0x400) & ~8);
121 + ssb_read32(dev, 0x400);
122 +
123 + /* Change Shim control reg */
124 + ssb_write32(dev, 0x304, ssb_read32(dev, 0x304) & ~0x100);
125 + ssb_read32(dev, 0x304);
126 +
127 + udelay(1);
128 +
129 + ssb_hcd_5354wa(dev);
130 + }
131 +}
132 +
133 +/* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
134 +static u32 __devinit ssb_hcd_init_chip(struct ssb_device *dev)
135 +{
136 + u32 flags = 0;
137 +
138 + if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
139 + /* Put the device into host-mode. */
140 + flags |= SSB_HCD_TMSLOW_HOSTMODE;
141 +
142 + ssb_device_enable(dev, flags);
143 +
144 + ssb_hcd_usb20wa(dev);
145 +
146 + return flags;
147 +}
148 +
149 +static const struct usb_hci_pdata p_data = {
150 + .flags = USB_HCI_PDATA_PORT_POWER_SET,
151 + .power_set_is_on = 1,
152 +};
153 +
154 +static struct platform_device * __devinit
155 +ssb_hcd_create_pdev(struct ssb_device *dev, char *name, u32 addr, u32 len)
156 +{
157 + struct platform_device *hci_dev;
158 + struct resource hci_res[2];
159 + int ret = -ENOMEM;
160 +
161 + memset(hci_res, 0, sizeof(hci_res));
162 +
163 + hci_res[0].start = addr;
164 + hci_res[0].end = hci_res[0].start + len - 1;
165 + hci_res[0].flags = IORESOURCE_MEM;
166 +
167 + hci_res[1].start = dev->irq;
168 + hci_res[1].flags = IORESOURCE_IRQ;
169 +
170 + hci_dev = platform_device_alloc(name, 0);
171 + if (!hci_dev)
172 + return NULL;
173 +
174 + hci_dev->dev.parent = dev->dev;
175 + hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
176 +
177 + ret = platform_device_add_resources(hci_dev, hci_res,
178 + ARRAY_SIZE(hci_res));
179 + if (ret)
180 + goto err_alloc;
181 + ret = platform_device_add_data(hci_dev, &p_data, sizeof(p_data));
182 + if (ret)
183 + goto err_alloc;
184 + ret = platform_device_add(hci_dev);
185 + if (ret)
186 + goto err_alloc;
187 +
188 + return hci_dev;
189 +
190 +err_alloc:
191 + platform_device_put(hci_dev);
192 + return ERR_PTR(ret);
193 +}
194 +
195 +static int __devinit ssb_hcd_probe(struct ssb_device *dev,
196 + const struct ssb_device_id *id)
197 +{
198 + int err, tmp;
199 + int start, len;
200 + u16 chipid_top;
201 + u16 coreid = dev->id.coreid;
202 + struct ssb_hcd_device *usb_dev;
203 +
204 + /* USBcores are only connected on embedded devices. */
205 + chipid_top = (dev->bus->chip_id & 0xFF00);
206 + if (chipid_top != 0x4700 && chipid_top != 0x5300)
207 + return -ENODEV;
208 +
209 + /* TODO: Probably need checks here; is the core connected? */
210 +
211 + if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
212 + dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
213 + return -EOPNOTSUPP;
214 +
215 + usb_dev = kzalloc(sizeof(struct ssb_hcd_device), GFP_KERNEL);
216 + if (!usb_dev)
217 + return -ENOMEM;
218 +
219 + /* We currently always attach SSB_DEV_USB11_HOSTDEV
220 + * as HOST OHCI. If we want to attach it as Client device,
221 + * we must branch here and call into the (yet to
222 + * be written) Client mode driver. Same for remove(). */
223 + usb_dev->enable_flags = ssb_hcd_init_chip(dev);
224 +
225 + tmp = ssb_read32(dev, SSB_ADMATCH0);
226 +
227 + start = ssb_admatch_base(tmp);
228 + len = (coreid == SSB_DEV_USB20_HOST) ? 0x800 : ssb_admatch_size(tmp);
229 + usb_dev->ohci_dev = ssb_hcd_create_pdev(dev, "ohci-platform", start,
230 + len);
231 + if (IS_ERR(usb_dev->ohci_dev)) {
232 + err = PTR_ERR(usb_dev->ohci_dev);
233 + goto err_free_usb_dev;
234 + }
235 +
236 + if (coreid == SSB_DEV_USB20_HOST) {
237 + start = ssb_admatch_base(tmp) + 0x800; /* ehci core offset */
238 + usb_dev->ehci_dev = ssb_hcd_create_pdev(dev, "ehci-platform",
239 + start, len);
240 + if (IS_ERR(usb_dev->ehci_dev)) {
241 + err = PTR_ERR(usb_dev->ehci_dev);
242 + goto err_unregister_ohci_dev;
243 + }
244 + }
245 +
246 + ssb_set_drvdata(dev, usb_dev);
247 + return 0;
248 +
249 +err_unregister_ohci_dev:
250 + platform_device_unregister(usb_dev->ohci_dev);
251 +err_free_usb_dev:
252 + kfree(usb_dev);
253 + return err;
254 +}
255 +
256 +static void __devexit ssb_hcd_remove(struct ssb_device *dev)
257 +{
258 + struct ssb_hcd_device *usb_dev = ssb_get_drvdata(dev);
259 + struct platform_device *ohci_dev = usb_dev->ohci_dev;
260 + struct platform_device *ehci_dev = usb_dev->ehci_dev;
261 +
262 + if (ohci_dev)
263 + platform_device_unregister(ohci_dev);
264 + if (ehci_dev)
265 + platform_device_unregister(ehci_dev);
266 +
267 + ssb_device_disable(dev, 0);
268 +}
269 +
270 +static void __devexit ssb_hcd_shutdown(struct ssb_device *dev)
271 +{
272 + ssb_device_disable(dev, 0);
273 +}
274 +
275 +#ifdef CONFIG_PM
276 +
277 +static int ssb_hcd_suspend(struct ssb_device *dev, pm_message_t state)
278 +{
279 + ssb_device_disable(dev, 0);
280 +
281 + return 0;
282 +}
283 +
284 +static int ssb_hcd_resume(struct ssb_device *dev)
285 +{
286 + struct ssb_hcd_device *usb_dev = ssb_get_drvdata(dev);
287 +
288 + ssb_device_enable(dev, usb_dev->enable_flags);
289 +
290 + return 0;
291 +}
292 +
293 +#else /* !CONFIG_PM */
294 +#define ssb_hcd_suspend NULL
295 +#define ssb_hcd_resume NULL
296 +#endif /* CONFIG_PM */
297 +
298 +static const struct ssb_device_id ssb_hcd_table[] __devinitconst = {
299 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
300 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
301 + SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV),
302 + SSB_DEVTABLE_END
303 +};
304 +MODULE_DEVICE_TABLE(ssb, ssb_hcd_table);
305 +
306 +static struct ssb_driver ssb_hcd_driver = {
307 + .name = KBUILD_MODNAME,
308 + .id_table = ssb_hcd_table,
309 + .probe = ssb_hcd_probe,
310 + .remove = __devexit_p(ssb_hcd_remove),
311 + .shutdown = ssb_hcd_shutdown,
312 + .suspend = ssb_hcd_suspend,
313 + .resume = ssb_hcd_resume,
314 +};
315 +
316 +static int __init ssb_hcd_init(void)
317 +{
318 + return ssb_driver_register(&ssb_hcd_driver);
319 +}
320 +module_init(ssb_hcd_init);
321 +
322 +static void __exit ssb_hcd_exit(void)
323 +{
324 + ssb_driver_unregister(&ssb_hcd_driver);
325 +}
326 +module_exit(ssb_hcd_exit);
This page took 0.069343 seconds and 5 git commands to generate.