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
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 | 350 +++++++++++++++++++++++++++++++++++++++++++
19 3 files changed, 363 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 @@ -598,3 +598,15 @@ config USB_OCTEON_OHCI
25 config USB_OCTEON2_COMMON
27 default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI
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 @@ -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
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 +#define BCMA_CORE_SIZE 0x1000
81 +struct bcma_hcd_device {
82 + struct platform_device *ehci_dev;
83 + struct platform_device *ohci_dev;
86 +/* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
87 +static void bcma_hcd_init_chip(struct bcma_device *dev)
92 + * USB 2.0 special considerations:
94 + * 1. Since the core supports both OHCI and EHCI functions, it must
95 + * only be reset once.
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.
101 + if (!bcma_core_is_enabled(dev)) {
102 + bcma_core_enable(dev, 0);
104 + if (dev->id.rev >= 5) {
105 + /* Enable Misc PLL */
106 + tmp = bcma_read32(dev, 0x1e0);
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");
112 + /* Take out of resets */
113 + bcma_write32(dev, 0x200, 0x4ff);
115 + bcma_write32(dev, 0x200, 0x6ff);
118 + /* Make sure digital and AFE are locked in USB PHY */
119 + bcma_write32(dev, 0x524, 0x6b);
121 + tmp = bcma_read32(dev, 0x524);
123 + bcma_write32(dev, 0x524, 0xab);
125 + tmp = bcma_read32(dev, 0x524);
127 + bcma_write32(dev, 0x524, 0x2b);
129 + tmp = bcma_read32(dev, 0x524);
131 + bcma_write32(dev, 0x524, 0x10ab);
133 + tmp = bcma_read32(dev, 0x524);
135 + if (bcma_wait_bits(dev, 0x528, 0xc000, 10000, 1))
137 + "USB20H mdio_rddata 0x%08x\n", tmp);
139 + bcma_write32(dev, 0x528, 0x80000000);
140 + tmp = bcma_read32(dev, 0x314);
142 + bcma_write32(dev, 0x200, 0x7ff);
145 + /* Take USB and HSIC out of non-driving modes */
146 + bcma_write32(dev, 0x510, 0);
148 + bcma_write32(dev, 0x200, 0x7ff);
153 +#ifdef CONFIG_BCMA_DRIVER_MIPS
154 + /* Work around for 4716 failures. */
155 + if (dev->bus->chipinfo.id == 0x4716) {
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) */
166 + /* Change Shim mdio control reg to fix host not acking at
170 + bcma_write32(dev, 0x524, 0x1); /* write sel to enable */
173 + bcma_write32(dev, 0x524, tmp);
175 + bcma_write32(dev, 0x524, 0x4ab);
177 + tmp = bcma_read32(dev, 0x528);
178 + bcma_write32(dev, 0x528, 0x80000000);
181 +#endif /* CONFIG_BCMA_DRIVER_MIPS */
184 +static struct platform_device *bcma_hcd_create_pdev(struct bcma_device *dev,
185 + char *name, u32 addr)
187 + struct platform_device *hci_dev;
188 + struct resource *hci_res;
191 + hci_res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
193 + return ERR_PTR(-ENOMEM);
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;
199 + hci_res[1].start = dev->irq;
200 + hci_res[1].flags = IORESOURCE_IRQ;
202 + hci_dev = platform_device_alloc(name, 0);
206 + hci_dev->dev.parent = &dev->dev;
207 + hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
209 + ret = platform_device_add_resources(hci_dev, hci_res, 2);
213 + ret = platform_device_add(hci_dev);
217 + platform_device_put(hci_dev);
218 + return ERR_PTR(ret);
224 +static int bcma_hcd_probe(struct bcma_device *dev)
228 + struct bcma_hcd_device *usb_dev;
230 + /* USBcores are only connected on embedded devices. */
231 + chipid_top = (dev->bus->chipinfo.id & 0xFF00);
232 + if (chipid_top != 0x4700 && chipid_top != 0x5300)
235 + /* TODO: Probably need checks here; is the core connected? */
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;
241 + usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
245 + bcma_hcd_init_chip(dev);
247 + usb_dev->ohci_dev = bcma_hcd_create_pdev(dev, "ohci-platform",
249 + if (IS_ERR(usb_dev->ohci_dev)) {
250 + err = PTR_ERR(usb_dev->ohci_dev);
251 + goto err_free_usb_dev;
254 + usb_dev->ehci_dev = bcma_hcd_create_pdev(dev, "ehci-platform",
256 + if (IS_ERR(usb_dev->ehci_dev)) {
257 + err = PTR_ERR(usb_dev->ehci_dev);
258 + goto err_unregister_ohci_dev;
262 + bcma_set_drvdata(dev, usb_dev);
265 +err_unregister_ohci_dev:
266 + platform_device_unregister(usb_dev->ohci_dev);
272 +static void bcma_hcd_remove(struct bcma_device *dev)
274 + struct bcma_hcd_device *usb_dev;
275 + struct platform_device *ohci_dev;
276 + struct platform_device *ehci_dev;
278 + usb_dev = bcma_get_drvdata(dev);
282 + ohci_dev = usb_dev->ohci_dev;
283 + ehci_dev = usb_dev->ehci_dev;
286 + platform_device_unregister(ohci_dev);
289 + platform_device_unregister(ehci_dev);
292 + bcma_core_disable(dev, 0);
295 +static void bcma_hcd_shutdown(struct bcma_device *dev)
297 + bcma_core_disable(dev, 0);
302 +static int bcma_hcd_suspend(struct bcma_device *dev, pm_message_t state)
304 + bcma_core_disable(dev, 0);
309 +static int bcma_hcd_resume(struct bcma_device *dev)
311 + bcma_core_enable(dev, 0);
316 +#else /* !CONFIG_PM */
317 +#define bcma_hcd_suspend NULL
318 +#define bcma_hcd_resume NULL
319 +#endif /* CONFIG_PM */
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),
325 +MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);
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,
337 +static int __init bcma_hcd_init(void)
339 + return bcma_driver_register(&bcma_hcd_driver);
341 +module_init(bcma_hcd_init);
343 +static void __exit bcma_hcd_exit(void)
345 + bcma_driver_unregister(&bcma_hcd_driver);
347 +module_exit(bcma_hcd_exit);