3a35ac80e1511ec0dffb06a605943a2f78694f82
[openwrt.git] / target / linux / brcm47xx / patches-3.0 / 0032-USB-Add-driver-for-the-bcma-bus.patch
1 From 7151c34627b938486008cfab25bfb4e4f730a021 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/21] 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 | 350 +++++++++++++++++++++++++++++++++++++++++++
19 3 files changed, 363 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,298 @@
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 +#define BCMA_CORE_SIZE 0x1000
80 +
81 +struct bcma_hcd_device {
82 + struct platform_device *ehci_dev;
83 + struct platform_device *ohci_dev;
84 +};
85 +
86 +/* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
87 +static void bcma_hcd_init_chip(struct bcma_device *dev)
88 +{
89 + u32 tmp;
90 +
91 + /*
92 + * USB 2.0 special considerations:
93 + *
94 + * 1. Since the core supports both OHCI and EHCI functions, it must
95 + * only be reset once.
96 + *
97 + * 2. In addition to the standard SI reset sequence, the Host Control
98 + * Register must be programmed to bring the USB core and various
99 + * phy components out of reset.
100 + */
101 + if (!bcma_core_is_enabled(dev)) {
102 + bcma_core_enable(dev, 0);
103 + mdelay(10);
104 + if (dev->id.rev >= 5) {
105 + /* Enable Misc PLL */
106 + tmp = bcma_read32(dev, 0x1e0);
107 + tmp |= 0x100;
108 + bcma_write32(dev, 0x1e0, tmp);
109 + if (bcma_wait_bits(dev, 0x1e0, 1 << 24, 100, 0))
110 + printk(KERN_EMERG "Failed to enable misc PPL!\n");
111 +
112 + /* Take out of resets */
113 + bcma_write32(dev, 0x200, 0x4ff);
114 + udelay(25);
115 + bcma_write32(dev, 0x200, 0x6ff);
116 + udelay(25);
117 +
118 + /* Make sure digital and AFE are locked in USB PHY */
119 + bcma_write32(dev, 0x524, 0x6b);
120 + udelay(50);
121 + tmp = bcma_read32(dev, 0x524);
122 + udelay(50);
123 + bcma_write32(dev, 0x524, 0xab);
124 + udelay(50);
125 + tmp = bcma_read32(dev, 0x524);
126 + udelay(50);
127 + bcma_write32(dev, 0x524, 0x2b);
128 + udelay(50);
129 + tmp = bcma_read32(dev, 0x524);
130 + udelay(50);
131 + bcma_write32(dev, 0x524, 0x10ab);
132 + udelay(50);
133 + tmp = bcma_read32(dev, 0x524);
134 +
135 + if (bcma_wait_bits(dev, 0x528, 0xc000, 10000, 1))
136 + printk(KERN_EMERG
137 + "USB20H mdio_rddata 0x%08x\n", tmp);
138 +
139 + bcma_write32(dev, 0x528, 0x80000000);
140 + tmp = bcma_read32(dev, 0x314);
141 + udelay(265);
142 + bcma_write32(dev, 0x200, 0x7ff);
143 + udelay(10);
144 +
145 + /* Take USB and HSIC out of non-driving modes */
146 + bcma_write32(dev, 0x510, 0);
147 + } else {
148 + bcma_write32(dev, 0x200, 0x7ff);
149 +
150 + udelay(1);
151 + }
152 + }
153 +#ifdef CONFIG_BCMA_DRIVER_MIPS
154 + /* Work around for 4716 failures. */
155 + if (dev->bus->chipinfo.id == 0x4716) {
156 + u32 clk_freq;
157 +
158 + clk_freq = bcma_cpu_clock(&dev->bus->drv_mips);
159 + if (clk_freq >= 480000000)
160 + tmp = 0x1846b; /* set CDR to 0x11(fast) */
161 + else if (clk_freq == 453000000)
162 + tmp = 0x1046b; /* set CDR to 0x10(slow) */
163 + else
164 + tmp = 0;
165 +
166 + /* Change Shim mdio control reg to fix host not acking at
167 + * high frequencies
168 + */
169 + if (tmp) {
170 + bcma_write32(dev, 0x524, 0x1); /* write sel to enable */
171 + udelay(500);
172 +
173 + bcma_write32(dev, 0x524, tmp);
174 + udelay(500);
175 + bcma_write32(dev, 0x524, 0x4ab);
176 + udelay(500);
177 + tmp = bcma_read32(dev, 0x528);
178 + bcma_write32(dev, 0x528, 0x80000000);
179 + }
180 + }
181 +#endif /* CONFIG_BCMA_DRIVER_MIPS */
182 +}
183 +
184 +static struct platform_device *bcma_hcd_create_pdev(struct bcma_device *dev,
185 + char *name, u32 addr)
186 +{
187 + struct platform_device *hci_dev;
188 + struct resource *hci_res;
189 + int ret = -ENOMEM;
190 +
191 + hci_res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
192 + if (!hci_res)
193 + return ERR_PTR(-ENOMEM);
194 +
195 + hci_res[0].start = addr;
196 + hci_res[0].end = hci_res[0].start + BCMA_CORE_SIZE - 1;
197 + hci_res[0].flags = IORESOURCE_MEM;
198 +
199 + hci_res[1].start = dev->irq;
200 + hci_res[1].flags = IORESOURCE_IRQ;
201 +
202 + hci_dev = platform_device_alloc(name, 0);
203 + if (!hci_dev)
204 + goto err_alloc;
205 +
206 + hci_dev->dev.parent = &dev->dev;
207 + hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
208 +
209 + ret = platform_device_add_resources(hci_dev, hci_res, 2);
210 + if (ret)
211 + goto err_alloc;
212 +
213 + ret = platform_device_add(hci_dev);
214 + if (ret) {
215 +err_alloc:
216 + kfree(hci_res);
217 + platform_device_put(hci_dev);
218 + return ERR_PTR(ret);
219 + }
220 +
221 + return hci_dev;
222 +}
223 +
224 +static int bcma_hcd_probe(struct bcma_device *dev)
225 +{
226 + int err;
227 + u16 chipid_top;
228 + struct bcma_hcd_device *usb_dev;
229 +
230 + /* USBcores are only connected on embedded devices. */
231 + chipid_top = (dev->bus->chipinfo.id & 0xFF00);
232 + if (chipid_top != 0x4700 && chipid_top != 0x5300)
233 + return -ENODEV;
234 +
235 + /* TODO: Probably need checks here; is the core connected? */
236 +
237 + if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
238 + dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
239 + return -EOPNOTSUPP;
240 +
241 + usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
242 + if (!usb_dev)
243 + return -ENOMEM;
244 +
245 + bcma_hcd_init_chip(dev);
246 +
247 + usb_dev->ohci_dev = bcma_hcd_create_pdev(dev, "ohci-platform",
248 + dev->addr1);
249 + if (IS_ERR(usb_dev->ohci_dev)) {
250 + err = PTR_ERR(usb_dev->ohci_dev);
251 + goto err_free_usb_dev;
252 + }
253 +
254 + usb_dev->ehci_dev = bcma_hcd_create_pdev(dev, "ehci-platform",
255 + dev->addr);
256 + if (IS_ERR(usb_dev->ehci_dev)) {
257 + err = PTR_ERR(usb_dev->ehci_dev);
258 + goto err_unregister_ohci_dev;
259 +
260 + }
261 +
262 + bcma_set_drvdata(dev, usb_dev);
263 + return 0;
264 +
265 +err_unregister_ohci_dev:
266 + platform_device_unregister(usb_dev->ohci_dev);
267 +err_free_usb_dev:
268 + kfree(usb_dev);
269 + return err;
270 +}
271 +
272 +static void bcma_hcd_remove(struct bcma_device *dev)
273 +{
274 + struct bcma_hcd_device *usb_dev;
275 + struct platform_device *ohci_dev;
276 + struct platform_device *ehci_dev;
277 +
278 + usb_dev = bcma_get_drvdata(dev);
279 + if (!usb_dev)
280 + return;
281 +
282 + ohci_dev = usb_dev->ohci_dev;
283 + ehci_dev = usb_dev->ehci_dev;
284 +
285 + if (ohci_dev) {
286 + platform_device_unregister(ohci_dev);
287 + }
288 + if (ehci_dev) {
289 + platform_device_unregister(ehci_dev);
290 + }
291 +
292 + bcma_core_disable(dev, 0);
293 +}
294 +
295 +static void bcma_hcd_shutdown(struct bcma_device *dev)
296 +{
297 + bcma_core_disable(dev, 0);
298 +}
299 +
300 +#ifdef CONFIG_PM
301 +
302 +static int bcma_hcd_suspend(struct bcma_device *dev, pm_message_t state)
303 +{
304 + bcma_core_disable(dev, 0);
305 +
306 + return 0;
307 +}
308 +
309 +static int bcma_hcd_resume(struct bcma_device *dev)
310 +{
311 + bcma_core_enable(dev, 0);
312 +
313 + return 0;
314 +}
315 +
316 +#else /* !CONFIG_PM */
317 +#define bcma_hcd_suspend NULL
318 +#define bcma_hcd_resume NULL
319 +#endif /* CONFIG_PM */
320 +
321 +static const struct bcma_device_id bcma_hcd_table[] = {
322 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_USB20_HOST, BCMA_ANY_REV, BCMA_ANY_CLASS),
323 + BCMA_CORETABLE_END
324 +};
325 +MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);
326 +
327 +static struct bcma_driver bcma_hcd_driver = {
328 + .name = KBUILD_MODNAME,
329 + .id_table = bcma_hcd_table,
330 + .probe = bcma_hcd_probe,
331 + .remove = bcma_hcd_remove,
332 + .shutdown = bcma_hcd_shutdown,
333 + .suspend = bcma_hcd_suspend,
334 + .resume = bcma_hcd_resume,
335 +};
336 +
337 +static int __init bcma_hcd_init(void)
338 +{
339 + return bcma_driver_register(&bcma_hcd_driver);
340 +}
341 +module_init(bcma_hcd_init);
342 +
343 +static void __exit bcma_hcd_exit(void)
344 +{
345 + bcma_driver_unregister(&bcma_hcd_driver);
346 +}
347 +module_exit(bcma_hcd_exit);
This page took 0.053025 seconds and 3 git commands to generate.