brcm47xx: move and rename the patches
[openwrt.git] / target / linux / brcm47xx / patches-3.0 / 0032-USB-Add-driver-for-the-bcma-bus.patch
1 From 4ea647c5a257d57eaf230f783e54b2c0232852b8 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 26 Nov 2011 21:33:41 +0100
4 Subject: [PATCH 19/26] USB: Add driver for the bcma bus
5
6 This adds a USB driver using the generic platform device driver for the
7 USB controller found on the Broadcom bcma bus. The bcma 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 bcma bus at the same time.
13
14 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
15 ---
16 drivers/usb/host/Kconfig | 12 ++
17 drivers/usb/host/Makefile | 1 +
18 drivers/usb/host/bcma-hcd.c | 309 +++++++++++++++++++++++++++++++++++++++++++
19 3 files changed, 322 insertions(+), 0 deletions(-)
20 create mode 100644 drivers/usb/host/bcma-hcd.c
21
22 --- a/drivers/usb/host/Kconfig
23 +++ b/drivers/usb/host/Kconfig
24 @@ -598,3 +598,15 @@ config USB_OCTEON_OHCI
25 config USB_OCTEON2_COMMON
26 bool
27 default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI
28 +
29 +config USB_HCD_BCMA
30 + tristate "BCMA usb host driver"
31 + depends on BCMA && EXPERIMENTAL
32 + select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
33 + select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
34 + help
35 + Enbale support for the EHCI and OCHI host controller on an bcma bus.
36 + It converts the bcma driver into two platform device drivers
37 + for ehci and ohci.
38 +
39 + If unsure, say N.
40 --- a/drivers/usb/host/Makefile
41 +++ b/drivers/usb/host/Makefile
42 @@ -35,3 +35,4 @@ obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
43 obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
44 obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
45 obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
46 +obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o
47 --- /dev/null
48 +++ b/drivers/usb/host/bcma-hcd.c
49 @@ -0,0 +1,309 @@
50 +/*
51 + * Broadcom specific Advanced Microcontroller Bus
52 + * Broadcom USB-core driver (BCMA bus glue)
53 + *
54 + * Copyright 2011 Hauke Mehrtens <hauke@hauke-m.de>
55 + *
56 + * Based on ssb-ohci driver
57 + * Copyright 2007 Michael Buesch <m@bues.ch>
58 + *
59 + * Derived from the OHCI-PCI driver
60 + * Copyright 1999 Roman Weissgaerber
61 + * Copyright 2000-2002 David Brownell
62 + * Copyright 1999 Linus Torvalds
63 + * Copyright 1999 Gregory P. Smith
64 + *
65 + * Derived from the USBcore related parts of Broadcom-SB
66 + * Copyright 2005-2011 Broadcom Corporation
67 + *
68 + * Licensed under the GNU/GPL. See COPYING for details.
69 + */
70 +#include <linux/bcma/bcma.h>
71 +#include <linux/delay.h>
72 +#include <linux/platform_device.h>
73 +#include <linux/module.h>
74 +
75 +MODULE_AUTHOR("Hauke Mehrtens");
76 +MODULE_DESCRIPTION("Common USB driver for BCMA Bus");
77 +MODULE_LICENSE("GPL");
78 +
79 +struct bcma_hcd_device {
80 + struct platform_device *ehci_dev;
81 + struct platform_device *ohci_dev;
82 +};
83 +
84 +static void __devinit bcma_hcd_4716wa(struct bcma_device *dev)
85 +{
86 +#ifdef CONFIG_BCMA_DRIVER_MIPS
87 + /* Work around for 4716 failures. */
88 + if (dev->bus->chipinfo.id == 0x4716) {
89 + u32 tmp;
90 +
91 + tmp = bcma_cpu_clock(&dev->bus->drv_mips);
92 + if (tmp >= 480000000)
93 + tmp = 0x1846b; /* set CDR to 0x11(fast) */
94 + else if (tmp == 453000000)
95 + tmp = 0x1046b; /* set CDR to 0x10(slow) */
96 + else
97 + tmp = 0;
98 +
99 + /* Change Shim mdio control reg to fix host not acking at
100 + * high frequencies
101 + */
102 + if (tmp) {
103 + bcma_write32(dev, 0x524, 0x1); /* write sel to enable */
104 + udelay(500);
105 +
106 + bcma_write32(dev, 0x524, tmp);
107 + udelay(500);
108 + bcma_write32(dev, 0x524, 0x4ab);
109 + udelay(500);
110 + bcma_read32(dev, 0x528);
111 + bcma_write32(dev, 0x528, 0x80000000);
112 + }
113 + }
114 +#endif /* CONFIG_BCMA_DRIVER_MIPS */
115 +}
116 +
117 +/* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
118 +static void __devinit bcma_hcd_init_chip(struct bcma_device *dev)
119 +{
120 + u32 tmp;
121 +
122 + /*
123 + * USB 2.0 special considerations:
124 + *
125 + * 1. Since the core supports both OHCI and EHCI functions, it must
126 + * only be reset once.
127 + *
128 + * 2. In addition to the standard SI reset sequence, the Host Control
129 + * Register must be programmed to bring the USB core and various
130 + * phy components out of reset.
131 + */
132 + if (!bcma_core_is_enabled(dev)) {
133 + bcma_core_enable(dev, 0);
134 + mdelay(10);
135 + if (dev->id.rev >= 5) {
136 + /* Enable Misc PLL */
137 + tmp = bcma_read32(dev, 0x1e0);
138 + tmp |= 0x100;
139 + bcma_write32(dev, 0x1e0, tmp);
140 + if (bcma_wait_bits(dev, 0x1e0, 1 << 24, 100, 1))
141 + printk(KERN_EMERG "Failed to enable misc PPL!\n");
142 +
143 + /* Take out of resets */
144 + bcma_write32(dev, 0x200, 0x4ff);
145 + udelay(25);
146 + bcma_write32(dev, 0x200, 0x6ff);
147 + udelay(25);
148 +
149 + /* Make sure digital and AFE are locked in USB PHY */
150 + bcma_write32(dev, 0x524, 0x6b);
151 + udelay(50);
152 + tmp = bcma_read32(dev, 0x524);
153 + udelay(50);
154 + bcma_write32(dev, 0x524, 0xab);
155 + udelay(50);
156 + tmp = bcma_read32(dev, 0x524);
157 + udelay(50);
158 + bcma_write32(dev, 0x524, 0x2b);
159 + udelay(50);
160 + tmp = bcma_read32(dev, 0x524);
161 + udelay(50);
162 + bcma_write32(dev, 0x524, 0x10ab);
163 + udelay(50);
164 + tmp = bcma_read32(dev, 0x524);
165 +
166 + if (bcma_wait_bits(dev, 0x528, 0xc000, 10000, 1)) {
167 + tmp = bcma_read32(dev, 0x528);
168 + printk(KERN_EMERG
169 + "USB20H mdio_rddata 0x%08x\n", tmp);
170 + }
171 + bcma_write32(dev, 0x528, 0x80000000);
172 + tmp = bcma_read32(dev, 0x314);
173 + udelay(265);
174 + bcma_write32(dev, 0x200, 0x7ff);
175 + udelay(10);
176 +
177 + /* Take USB and HSIC out of non-driving modes */
178 + bcma_write32(dev, 0x510, 0);
179 + } else {
180 + bcma_write32(dev, 0x200, 0x7ff);
181 +
182 + udelay(1);
183 + }
184 +
185 + bcma_hcd_4716wa(dev);
186 + }
187 +}
188 +
189 +static struct platform_device * __devinit
190 +bcma_hcd_create_pdev(struct bcma_device *dev, char *name, u32 addr)
191 +{
192 + struct platform_device *hci_dev;
193 + struct resource hci_res[2];
194 + int ret = -ENOMEM;
195 +
196 + memset(hci_res, 0, sizeof(hci_res));
197 +
198 + hci_res[0].start = addr;
199 + hci_res[0].end = hci_res[0].start + 0x1000 - 1;
200 + hci_res[0].flags = IORESOURCE_MEM;
201 +
202 + hci_res[1].start = dev->irq;
203 + hci_res[1].flags = IORESOURCE_IRQ;
204 +
205 + hci_dev = platform_device_alloc(name, 0);
206 + if (!hci_dev)
207 + goto err_alloc;
208 +
209 + hci_dev->dev.parent = &dev->dev;
210 + hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
211 +
212 + ret = platform_device_add_resources(hci_dev, hci_res,
213 + ARRAY_SIZE(hci_res));
214 + if (ret)
215 + goto err_alloc;
216 +
217 + ret = platform_device_add(hci_dev);
218 + if (ret) {
219 +err_alloc:
220 + platform_device_put(hci_dev);
221 + return ERR_PTR(ret);
222 + }
223 +
224 + return hci_dev;
225 +}
226 +
227 +static int __devinit bcma_hcd_probe(struct bcma_device *dev)
228 +{
229 + int err;
230 + u16 chipid_top;
231 + u32 ohci_addr;
232 + struct bcma_hcd_device *usb_dev;
233 + struct bcma_chipinfo *chipinfo;
234 +
235 + chipinfo = &dev->bus->chipinfo;
236 + /* USBcores are only connected on embedded devices. */
237 + chipid_top = (chipinfo->id & 0xFF00);
238 + if (chipid_top != 0x4700 && chipid_top != 0x5300)
239 + return -ENODEV;
240 +
241 + /* TODO: Probably need checks here; is the core connected? */
242 +
243 + if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
244 + dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
245 + return -EOPNOTSUPP;
246 +
247 + usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
248 + if (!usb_dev)
249 + return -ENOMEM;
250 +
251 + bcma_hcd_init_chip(dev);
252 +
253 + /* In AI chips EHCI is addrspace 0, OHCI is 1 */
254 + ohci_addr = dev->addr1;
255 + if ((chipinfo->id == 0x5357 || chipinfo->id == 0x4749)
256 + && chipinfo->rev == 0)
257 + ohci_addr = 0x18009000;
258 +
259 + usb_dev->ohci_dev = bcma_hcd_create_pdev(dev, "ohci-platform",
260 + ohci_addr);
261 + if (IS_ERR(usb_dev->ohci_dev)) {
262 + err = PTR_ERR(usb_dev->ohci_dev);
263 + goto err_free_usb_dev;
264 + }
265 +
266 + usb_dev->ehci_dev = bcma_hcd_create_pdev(dev, "ehci-platform",
267 + dev->addr);
268 + if (IS_ERR(usb_dev->ehci_dev)) {
269 + err = PTR_ERR(usb_dev->ehci_dev);
270 + goto err_unregister_ohci_dev;
271 + }
272 +
273 + bcma_set_drvdata(dev, usb_dev);
274 + return 0;
275 +
276 +err_unregister_ohci_dev:
277 + platform_device_unregister(usb_dev->ohci_dev);
278 +err_free_usb_dev:
279 + kfree(usb_dev);
280 + return err;
281 +}
282 +
283 +static void __devexit bcma_hcd_remove(struct bcma_device *dev)
284 +{
285 + struct bcma_hcd_device *usb_dev;
286 + struct platform_device *ohci_dev;
287 + struct platform_device *ehci_dev;
288 +
289 + usb_dev = bcma_get_drvdata(dev);
290 + if (!usb_dev)
291 + return;
292 +
293 + ohci_dev = usb_dev->ohci_dev;
294 + ehci_dev = usb_dev->ehci_dev;
295 +
296 + if (ohci_dev) {
297 + platform_device_unregister(ohci_dev);
298 + }
299 + if (ehci_dev) {
300 + platform_device_unregister(ehci_dev);
301 + }
302 +
303 + bcma_core_disable(dev, 0);
304 +}
305 +
306 +static void bcma_hcd_shutdown(struct bcma_device *dev)
307 +{
308 + bcma_core_disable(dev, 0);
309 +}
310 +
311 +#ifdef CONFIG_PM
312 +
313 +static int bcma_hcd_suspend(struct bcma_device *dev, pm_message_t state)
314 +{
315 + bcma_core_disable(dev, 0);
316 +
317 + return 0;
318 +}
319 +
320 +static int bcma_hcd_resume(struct bcma_device *dev)
321 +{
322 + bcma_core_enable(dev, 0);
323 +
324 + return 0;
325 +}
326 +
327 +#else /* !CONFIG_PM */
328 +#define bcma_hcd_suspend NULL
329 +#define bcma_hcd_resume NULL
330 +#endif /* CONFIG_PM */
331 +
332 +static const struct bcma_device_id bcma_hcd_table[] __devinitconst = {
333 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_USB20_HOST, BCMA_ANY_REV, BCMA_ANY_CLASS),
334 + BCMA_CORETABLE_END
335 +};
336 +MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);
337 +
338 +static struct bcma_driver bcma_hcd_driver = {
339 + .name = KBUILD_MODNAME,
340 + .id_table = bcma_hcd_table,
341 + .probe = bcma_hcd_probe,
342 + .remove = __devexit_p(bcma_hcd_remove),
343 + .shutdown = bcma_hcd_shutdown,
344 + .suspend = bcma_hcd_suspend,
345 + .resume = bcma_hcd_resume,
346 +};
347 +
348 +static int __init bcma_hcd_init(void)
349 +{
350 + return bcma_driver_register(&bcma_hcd_driver);
351 +}
352 +module_init(bcma_hcd_init);
353 +
354 +static void __exit bcma_hcd_exit(void)
355 +{
356 + bcma_driver_unregister(&bcma_hcd_driver);
357 +}
358 +module_exit(bcma_hcd_exit);
This page took 0.055555 seconds and 5 git commands to generate.