1 From 0da055d81f77272ebc41d4c2cd5f533aa9025cc7 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/30] USB: Add driver for the bcma bus
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.
14 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
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
22 --- a/drivers/usb/host/Kconfig
23 +++ b/drivers/usb/host/Kconfig
24 @@ -618,3 +618,15 @@ config USB_PXA168_EHCI
26 Enable support for Marvell PXA168 SoC's on-chip EHCI
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
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
40 --- a/drivers/usb/host/Makefile
41 +++ b/drivers/usb/host/Makefile
42 @@ -37,3 +37,4 @@ obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd
43 obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
44 obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
45 obj-$(CONFIG_MIPS_ALCHEMY) += alchemy-common.o
46 +obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o
48 +++ b/drivers/usb/host/bcma-hcd.c
51 + * Broadcom specific Advanced Microcontroller Bus
52 + * Broadcom USB-core driver (BCMA bus glue)
54 + * Copyright 2011 Hauke Mehrtens <hauke@hauke-m.de>
56 + * Based on ssb-ohci driver
57 + * Copyright 2007 Michael Buesch <m@bues.ch>
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
65 + * Derived from the USBcore related parts of Broadcom-SB
66 + * Copyright 2005-2011 Broadcom Corporation
68 + * Licensed under the GNU/GPL. See COPYING for details.
70 +#include <linux/bcma/bcma.h>
71 +#include <linux/delay.h>
72 +#include <linux/platform_device.h>
73 +#include <linux/module.h>
75 +MODULE_AUTHOR("Hauke Mehrtens");
76 +MODULE_DESCRIPTION("Common USB driver for BCMA Bus");
77 +MODULE_LICENSE("GPL");
79 +struct bcma_hcd_device {
80 + struct platform_device *ehci_dev;
81 + struct platform_device *ohci_dev;
84 +static void __devinit bcma_hcd_4716wa(struct bcma_device *dev)
86 +#ifdef CONFIG_BCMA_DRIVER_MIPS
87 + /* Work around for 4716 failures. */
88 + if (dev->bus->chipinfo.id == 0x4716) {
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) */
99 + /* Change Shim mdio control reg to fix host not acking at
103 + bcma_write32(dev, 0x524, 0x1); /* write sel to enable */
106 + bcma_write32(dev, 0x524, tmp);
108 + bcma_write32(dev, 0x524, 0x4ab);
110 + bcma_read32(dev, 0x528);
111 + bcma_write32(dev, 0x528, 0x80000000);
114 +#endif /* CONFIG_BCMA_DRIVER_MIPS */
117 +/* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
118 +static void __devinit bcma_hcd_init_chip(struct bcma_device *dev)
123 + * USB 2.0 special considerations:
125 + * 1. Since the core supports both OHCI and EHCI functions, it must
126 + * only be reset once.
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.
132 + if (!bcma_core_is_enabled(dev)) {
133 + bcma_core_enable(dev, 0);
135 + if (dev->id.rev >= 5) {
136 + /* Enable Misc PLL */
137 + tmp = bcma_read32(dev, 0x1e0);
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");
143 + /* Take out of resets */
144 + bcma_write32(dev, 0x200, 0x4ff);
146 + bcma_write32(dev, 0x200, 0x6ff);
149 + /* Make sure digital and AFE are locked in USB PHY */
150 + bcma_write32(dev, 0x524, 0x6b);
152 + tmp = bcma_read32(dev, 0x524);
154 + bcma_write32(dev, 0x524, 0xab);
156 + tmp = bcma_read32(dev, 0x524);
158 + bcma_write32(dev, 0x524, 0x2b);
160 + tmp = bcma_read32(dev, 0x524);
162 + bcma_write32(dev, 0x524, 0x10ab);
164 + tmp = bcma_read32(dev, 0x524);
166 + if (bcma_wait_bits(dev, 0x528, 0xc000, 10000, 1)) {
167 + tmp = bcma_read32(dev, 0x528);
169 + "USB20H mdio_rddata 0x%08x\n", tmp);
171 + bcma_write32(dev, 0x528, 0x80000000);
172 + tmp = bcma_read32(dev, 0x314);
174 + bcma_write32(dev, 0x200, 0x7ff);
177 + /* Take USB and HSIC out of non-driving modes */
178 + bcma_write32(dev, 0x510, 0);
180 + bcma_write32(dev, 0x200, 0x7ff);
185 + bcma_hcd_4716wa(dev);
189 +static struct platform_device * __devinit
190 +bcma_hcd_create_pdev(struct bcma_device *dev, char *name, u32 addr)
192 + struct platform_device *hci_dev;
193 + struct resource hci_res[2];
196 + memset(hci_res, 0, sizeof(hci_res));
198 + hci_res[0].start = addr;
199 + hci_res[0].end = hci_res[0].start + 0x1000 - 1;
200 + hci_res[0].flags = IORESOURCE_MEM;
202 + hci_res[1].start = dev->irq;
203 + hci_res[1].flags = IORESOURCE_IRQ;
205 + hci_dev = platform_device_alloc(name, 0);
209 + hci_dev->dev.parent = &dev->dev;
210 + hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
212 + ret = platform_device_add_resources(hci_dev, hci_res,
213 + ARRAY_SIZE(hci_res));
217 + ret = platform_device_add(hci_dev);
220 + platform_device_put(hci_dev);
221 + return ERR_PTR(ret);
227 +static int __devinit bcma_hcd_probe(struct bcma_device *dev)
232 + struct bcma_hcd_device *usb_dev;
233 + struct bcma_chipinfo *chipinfo;
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)
241 + /* TODO: Probably need checks here; is the core connected? */
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;
247 + usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
251 + bcma_hcd_init_chip(dev);
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;
259 + usb_dev->ohci_dev = bcma_hcd_create_pdev(dev, "ohci-platform",
261 + if (IS_ERR(usb_dev->ohci_dev)) {
262 + err = PTR_ERR(usb_dev->ohci_dev);
263 + goto err_free_usb_dev;
266 + usb_dev->ehci_dev = bcma_hcd_create_pdev(dev, "ehci-platform",
268 + if (IS_ERR(usb_dev->ehci_dev)) {
269 + err = PTR_ERR(usb_dev->ehci_dev);
270 + goto err_unregister_ohci_dev;
273 + bcma_set_drvdata(dev, usb_dev);
276 +err_unregister_ohci_dev:
277 + platform_device_unregister(usb_dev->ohci_dev);
283 +static void __devexit bcma_hcd_remove(struct bcma_device *dev)
285 + struct bcma_hcd_device *usb_dev;
286 + struct platform_device *ohci_dev;
287 + struct platform_device *ehci_dev;
289 + usb_dev = bcma_get_drvdata(dev);
293 + ohci_dev = usb_dev->ohci_dev;
294 + ehci_dev = usb_dev->ehci_dev;
297 + platform_device_unregister(ohci_dev);
300 + platform_device_unregister(ehci_dev);
303 + bcma_core_disable(dev, 0);
306 +static void bcma_hcd_shutdown(struct bcma_device *dev)
308 + bcma_core_disable(dev, 0);
313 +static int bcma_hcd_suspend(struct bcma_device *dev, pm_message_t state)
315 + bcma_core_disable(dev, 0);
320 +static int bcma_hcd_resume(struct bcma_device *dev)
322 + bcma_core_enable(dev, 0);
327 +#else /* !CONFIG_PM */
328 +#define bcma_hcd_suspend NULL
329 +#define bcma_hcd_resume NULL
330 +#endif /* CONFIG_PM */
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),
336 +MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);
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,
348 +static int __init bcma_hcd_init(void)
350 + return bcma_driver_register(&bcma_hcd_driver);
352 +module_init(bcma_hcd_init);
354 +static void __exit bcma_hcd_exit(void)
356 + bcma_driver_unregister(&bcma_hcd_driver);
358 +module_exit(bcma_hcd_exit);