2 * Broadcom specific Advanced Microcontroller Bus
3 * Broadcom USB-core driver (BCMA bus glue)
5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
7 * Based on ssb-ohci driver
8 * Copyright 2007 Michael Buesch <m@bues.ch>
10 * Derived from the OHCI-PCI driver
11 * Copyright 1999 Roman Weissgaerber
12 * Copyright 2000-2002 David Brownell
13 * Copyright 1999 Linus Torvalds
14 * Copyright 1999 Gregory P. Smith
16 * Derived from the USBcore related parts of Broadcom-SB
17 * Copyright 2005-2011 Broadcom Corporation
19 * Licensed under the GNU/GPL. See COPYING for details.
21 #include <linux/bcma/bcma.h>
22 #include <linux/delay.h>
23 #include <linux/platform_device.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/usb/ehci_pdriver.h>
27 #include <linux/usb/ohci_pdriver.h>
29 MODULE_AUTHOR("Hauke Mehrtens");
30 MODULE_DESCRIPTION("Common USB driver for BCMA Bus");
31 MODULE_LICENSE("GPL");
33 struct bcma_hcd_device {
34 struct platform_device *ehci_dev;
35 struct platform_device *ohci_dev;
38 /* Wait for bitmask in a register to get set or cleared.
39 * timeout is in units of ten-microseconds.
41 static int bcma_wait_bits(struct bcma_device *dev, u16 reg, u32 bitmask,
47 for (i = 0; i < timeout; i++) {
48 val = bcma_read32(dev, reg);
49 if ((val & bitmask) == bitmask)
57 static void __devinit bcma_hcd_4716wa(struct bcma_device *dev)
59 #ifdef CONFIG_BCMA_DRIVER_MIPS
60 /* Work around for 4716 failures. */
61 if (dev->bus->chipinfo.id == 0x4716) {
64 tmp = bcma_cpu_clock(&dev->bus->drv_mips);
66 tmp = 0x1846b; /* set CDR to 0x11(fast) */
67 else if (tmp == 453000000)
68 tmp = 0x1046b; /* set CDR to 0x10(slow) */
72 /* Change Shim mdio control reg to fix host not acking at
76 bcma_write32(dev, 0x524, 0x1); /* write sel to enable */
79 bcma_write32(dev, 0x524, tmp);
81 bcma_write32(dev, 0x524, 0x4ab);
83 bcma_read32(dev, 0x528);
84 bcma_write32(dev, 0x528, 0x80000000);
87 #endif /* CONFIG_BCMA_DRIVER_MIPS */
90 /* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
91 static void __devinit bcma_hcd_init_chip(struct bcma_device *dev)
96 * USB 2.0 special considerations:
98 * 1. Since the core supports both OHCI and EHCI functions, it must
101 * 2. In addition to the standard SI reset sequence, the Host Control
102 * Register must be programmed to bring the USB core and various
103 * phy components out of reset.
105 if (!bcma_core_is_enabled(dev)) {
106 bcma_core_enable(dev, 0);
108 if (dev->id.rev >= 5) {
109 /* Enable Misc PLL */
110 tmp = bcma_read32(dev, 0x1e0);
112 bcma_write32(dev, 0x1e0, tmp);
113 if (bcma_wait_bits(dev, 0x1e0, 1 << 24, 100))
114 printk(KERN_EMERG "Failed to enable misc PPL!\n");
116 /* Take out of resets */
117 bcma_write32(dev, 0x200, 0x4ff);
119 bcma_write32(dev, 0x200, 0x6ff);
122 /* Make sure digital and AFE are locked in USB PHY */
123 bcma_write32(dev, 0x524, 0x6b);
125 tmp = bcma_read32(dev, 0x524);
127 bcma_write32(dev, 0x524, 0xab);
129 tmp = bcma_read32(dev, 0x524);
131 bcma_write32(dev, 0x524, 0x2b);
133 tmp = bcma_read32(dev, 0x524);
135 bcma_write32(dev, 0x524, 0x10ab);
137 tmp = bcma_read32(dev, 0x524);
139 if (bcma_wait_bits(dev, 0x528, 0xc000, 10000)) {
140 tmp = bcma_read32(dev, 0x528);
142 "USB20H mdio_rddata 0x%08x\n", tmp);
144 bcma_write32(dev, 0x528, 0x80000000);
145 tmp = bcma_read32(dev, 0x314);
147 bcma_write32(dev, 0x200, 0x7ff);
150 /* Take USB and HSIC out of non-driving modes */
151 bcma_write32(dev, 0x510, 0);
153 bcma_write32(dev, 0x200, 0x7ff);
158 bcma_hcd_4716wa(dev);
162 static const struct usb_ehci_pdata ehci_pdata = {
165 static const struct usb_ohci_pdata ohci_pdata = {
168 static struct platform_device * __devinit
169 bcma_hcd_create_pdev(struct bcma_device *dev, bool ohci, u32 addr)
171 struct platform_device *hci_dev;
172 struct resource hci_res[2];
175 memset(hci_res, 0, sizeof(hci_res));
177 hci_res[0].start = addr;
178 hci_res[0].end = hci_res[0].start + 0x1000 - 1;
179 hci_res[0].flags = IORESOURCE_MEM;
181 hci_res[1].start = dev->irq;
182 hci_res[1].flags = IORESOURCE_IRQ;
184 hci_dev = platform_device_alloc(ohci ? "ohci-platform" :
185 "ehci-platform" , 0);
189 hci_dev->dev.parent = &dev->dev;
190 hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
192 ret = platform_device_add_resources(hci_dev, hci_res,
193 ARRAY_SIZE(hci_res));
197 ret = platform_device_add_data(hci_dev, &ohci_pdata,
200 ret = platform_device_add_data(hci_dev, &ehci_pdata,
204 ret = platform_device_add(hci_dev);
211 platform_device_put(hci_dev);
215 static int __devinit bcma_hcd_probe(struct bcma_device *dev)
220 struct bcma_hcd_device *usb_dev;
221 struct bcma_chipinfo *chipinfo;
223 chipinfo = &dev->bus->chipinfo;
224 /* USBcores are only connected on embedded devices. */
225 chipid_top = (chipinfo->id & 0xFF00);
226 if (chipid_top != 0x4700 && chipid_top != 0x5300)
229 /* TODO: Probably need checks here; is the core connected? */
231 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
232 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
235 usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
239 bcma_hcd_init_chip(dev);
241 /* In AI chips EHCI is addrspace 0, OHCI is 1 */
242 ohci_addr = dev->addr1;
243 if ((chipinfo->id == 0x5357 || chipinfo->id == 0x4749)
244 && chipinfo->rev == 0)
245 ohci_addr = 0x18009000;
247 usb_dev->ohci_dev = bcma_hcd_create_pdev(dev, true, ohci_addr);
248 if (IS_ERR(usb_dev->ohci_dev)) {
249 err = PTR_ERR(usb_dev->ohci_dev);
250 goto err_free_usb_dev;
253 usb_dev->ehci_dev = bcma_hcd_create_pdev(dev, false, dev->addr);
254 if (IS_ERR(usb_dev->ehci_dev)) {
255 err = PTR_ERR(usb_dev->ehci_dev);
256 goto err_unregister_ohci_dev;
259 bcma_set_drvdata(dev, usb_dev);
262 err_unregister_ohci_dev:
263 platform_device_unregister(usb_dev->ohci_dev);
269 static void __devexit bcma_hcd_remove(struct bcma_device *dev)
271 struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
272 struct platform_device *ohci_dev = usb_dev->ohci_dev;
273 struct platform_device *ehci_dev = usb_dev->ehci_dev;
276 platform_device_unregister(ohci_dev);
278 platform_device_unregister(ehci_dev);
280 bcma_core_disable(dev, 0);
283 static void bcma_hcd_shutdown(struct bcma_device *dev)
285 bcma_core_disable(dev, 0);
290 static int bcma_hcd_suspend(struct bcma_device *dev)
292 bcma_core_disable(dev, 0);
297 static int bcma_hcd_resume(struct bcma_device *dev)
299 bcma_core_enable(dev, 0);
304 #else /* !CONFIG_PM */
305 #define bcma_hcd_suspend NULL
306 #define bcma_hcd_resume NULL
307 #endif /* CONFIG_PM */
309 static const struct bcma_device_id bcma_hcd_table[] __devinitconst = {
310 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_USB20_HOST, BCMA_ANY_REV, BCMA_ANY_CLASS),
313 MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);
315 static struct bcma_driver bcma_hcd_driver = {
316 .name = KBUILD_MODNAME,
317 .id_table = bcma_hcd_table,
318 .probe = bcma_hcd_probe,
319 .remove = __devexit_p(bcma_hcd_remove),
320 .shutdown = bcma_hcd_shutdown,
321 .suspend = bcma_hcd_suspend,
322 .resume = bcma_hcd_resume,
325 static int __init bcma_hcd_init(void)
327 return bcma_driver_register(&bcma_hcd_driver);
329 module_init(bcma_hcd_init);
331 static void __exit bcma_hcd_exit(void)
333 bcma_driver_unregister(&bcma_hcd_driver);
335 module_exit(bcma_hcd_exit);