aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/Kconfig41
-rw-r--r--drivers/usb/host/Makefile2
-rw-r--r--drivers/usb/host/bcma-hcd.c335
-rw-r--r--drivers/usb/host/ehci-dbg.c6
-rw-r--r--drivers/usb/host/ehci-fsl.c44
-rw-r--r--drivers/usb/host/ehci-fsl.h13
-rw-r--r--drivers/usb/host/ehci-hcd.c45
-rw-r--r--drivers/usb/host/ehci-hub.c22
-rw-r--r--drivers/usb/host/ehci-omap.c39
-rw-r--r--drivers/usb/host/ehci-pci.c12
-rw-r--r--drivers/usb/host/ehci-platform.c6
-rw-r--r--drivers/usb/host/ehci-q.c19
-rw-r--r--drivers/usb/host/ehci-s5p.c4
-rw-r--r--drivers/usb/host/ehci-sched.c55
-rw-r--r--drivers/usb/host/ehci-sead3.c266
-rw-r--r--drivers/usb/host/ehci-sh.c8
-rw-r--r--drivers/usb/host/ehci-spear.c36
-rw-r--r--drivers/usb/host/ehci-tegra.c459
-rw-r--r--drivers/usb/host/fhci-tds.c2
-rw-r--r--drivers/usb/host/fsl-mph-dr-of.c41
-rw-r--r--drivers/usb/host/isp1760-hcd.c9
-rw-r--r--drivers/usb/host/isp1760-if.c8
-rw-r--r--drivers/usb/host/ohci-at91.c28
-rw-r--r--drivers/usb/host/ohci-au1xxx.c3
-rw-r--r--drivers/usb/host/ohci-cns3xxx.c3
-rw-r--r--drivers/usb/host/ohci-da8xx.c2
-rw-r--r--drivers/usb/host/ohci-dbg.c4
-rw-r--r--drivers/usb/host/ohci-ep93xx.c9
-rw-r--r--drivers/usb/host/ohci-exynos.c3
-rw-r--r--drivers/usb/host/ohci-hcd.c21
-rw-r--r--drivers/usb/host/ohci-nxp.c173
-rw-r--r--drivers/usb/host/ohci-omap.c10
-rw-r--r--drivers/usb/host/ohci-platform.c4
-rw-r--r--drivers/usb/host/ohci-pnx8550.c3
-rw-r--r--drivers/usb/host/ohci-ppc-of.c5
-rw-r--r--drivers/usb/host/ohci-ppc-soc.c3
-rw-r--r--drivers/usb/host/ohci-ps3.c3
-rw-r--r--drivers/usb/host/ohci-pxa27x.c3
-rw-r--r--drivers/usb/host/ohci-s3c2410.c3
-rw-r--r--drivers/usb/host/ohci-sa1111.c4
-rw-r--r--drivers/usb/host/ohci-sh.c8
-rw-r--r--drivers/usb/host/ohci-spear.c36
-rw-r--r--drivers/usb/host/ohci-ssb.c260
-rw-r--r--drivers/usb/host/ohci-tmio.c3
-rw-r--r--drivers/usb/host/ohci-xls.c3
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c13
-rw-r--r--drivers/usb/host/pci-quirks.c32
-rw-r--r--drivers/usb/host/r8a66597-hcd.c20
-rw-r--r--drivers/usb/host/ssb-hcd.c280
-rw-r--r--drivers/usb/host/xhci-hub.c41
-rw-r--r--drivers/usb/host/xhci-mem.c39
-rw-r--r--drivers/usb/host/xhci-pci.c14
-rw-r--r--drivers/usb/host/xhci-ring.c28
-rw-r--r--drivers/usb/host/xhci.c483
-rw-r--r--drivers/usb/host/xhci.h17
55 files changed, 2209 insertions, 824 deletions
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index f788eb86707..74a14f6ed34 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -65,7 +65,7 @@ config USB_EHCI_HCD
65 65
66config USB_EHCI_ROOT_HUB_TT 66config USB_EHCI_ROOT_HUB_TT
67 bool "Root Hub Transaction Translators" 67 bool "Root Hub Transaction Translators"
68 depends on USB_EHCI_HCD 68 depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST
69 ---help--- 69 ---help---
70 Some EHCI chips have vendor-specific extensions to integrate 70 Some EHCI chips have vendor-specific extensions to integrate
71 transaction translators, so that no OHCI or UHCI companion 71 transaction translators, so that no OHCI or UHCI companion
@@ -77,7 +77,7 @@ config USB_EHCI_ROOT_HUB_TT
77 77
78config USB_EHCI_TT_NEWSCHED 78config USB_EHCI_TT_NEWSCHED
79 bool "Improved Transaction Translator scheduling" 79 bool "Improved Transaction Translator scheduling"
80 depends on USB_EHCI_HCD 80 depends on USB_EHCI_HCD || USB_CHIPIDEA_HOST
81 default y 81 default y
82 ---help--- 82 ---help---
83 This changes the periodic scheduling code to fill more of the low 83 This changes the periodic scheduling code to fill more of the low
@@ -110,13 +110,14 @@ config USB_EHCI_BIG_ENDIAN_MMIO
110 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \ 110 depends on USB_EHCI_HCD && (PPC_CELLEB || PPC_PS3 || 440EPX || \
111 ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ 111 ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
112 PPC_MPC512x || CPU_CAVIUM_OCTEON || \ 112 PPC_MPC512x || CPU_CAVIUM_OCTEON || \
113 PMC_MSP || SPARC_LEON) 113 PMC_MSP || SPARC_LEON || MIPS_SEAD3)
114 default y 114 default y
115 115
116config USB_EHCI_BIG_ENDIAN_DESC 116config USB_EHCI_BIG_ENDIAN_DESC
117 bool 117 bool
118 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \ 118 depends on USB_EHCI_HCD && (440EPX || ARCH_IXP4XX || XPS_USB_HCD_XILINX || \
119 PPC_MPC512x || PMC_MSP || SPARC_LEON) 119 PPC_MPC512x || PMC_MSP || SPARC_LEON || \
120 MIPS_SEAD3)
120 default y 121 default y
121 122
122config XPS_USB_HCD_XILINX 123config XPS_USB_HCD_XILINX
@@ -291,6 +292,7 @@ config USB_OHCI_HCD
291 depends on USB && USB_ARCH_HAS_OHCI 292 depends on USB && USB_ARCH_HAS_OHCI
292 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3 293 select ISP1301_OMAP if MACH_OMAP_H2 || MACH_OMAP_H3
293 select USB_OTG_UTILS if ARCH_OMAP 294 select USB_OTG_UTILS if ARCH_OMAP
295 select USB_ISP1301 if ARCH_LPC32XX || ARCH_PNX4008
294 ---help--- 296 ---help---
295 The Open Host Controller Interface (OHCI) is a standard for accessing 297 The Open Host Controller Interface (OHCI) is a standard for accessing
296 USB 1.1 host controller hardware. It does more in hardware than Intel's 298 USB 1.1 host controller hardware. It does more in hardware than Intel's
@@ -373,10 +375,15 @@ config USB_OHCI_HCD_PCI
373 If unsure, say Y. 375 If unsure, say Y.
374 376
375config USB_OHCI_HCD_SSB 377config USB_OHCI_HCD_SSB
376 bool "OHCI support for Broadcom SSB OHCI core" 378 bool "OHCI support for Broadcom SSB OHCI core (DEPRECATED)"
377 depends on USB_OHCI_HCD && (SSB = y || SSB = USB_OHCI_HCD) && EXPERIMENTAL 379 depends on USB_OHCI_HCD && (SSB = y || SSB = USB_OHCI_HCD) && EXPERIMENTAL
380 select USB_HCD_SSB
381 select USB_OHCI_HCD_PLATFORM
378 default n 382 default n
379 ---help--- 383 ---help---
384 This option is deprecated now and the driver was removed, use
385 USB_HCD_SSB and USB_OHCI_HCD_PLATFORM instead.
386
380 Support for the Sonics Silicon Backplane (SSB) attached 387 Support for the Sonics Silicon Backplane (SSB) attached
381 Broadcom USB OHCI core. 388 Broadcom USB OHCI core.
382 389
@@ -638,3 +645,27 @@ config USB_OCTEON_OHCI
638config USB_OCTEON2_COMMON 645config USB_OCTEON2_COMMON
639 bool 646 bool
640 default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI 647 default y if USB_OCTEON_EHCI || USB_OCTEON_OHCI
648
649config USB_HCD_BCMA
650 tristate "BCMA usb host driver"
651 depends on BCMA && EXPERIMENTAL
652 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
653 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
654 help
655 Enbale support for the EHCI and OCHI host controller on an bcma bus.
656 It converts the bcma driver into two platform device drivers
657 for ehci and ohci.
658
659 If unsure, say N.
660
661config USB_HCD_SSB
662 tristate "SSB usb host driver"
663 depends on SSB && EXPERIMENTAL
664 select USB_OHCI_HCD_PLATFORM if USB_OHCI_HCD
665 select USB_EHCI_HCD_PLATFORM if USB_EHCI_HCD
666 help
667 Enbale support for the EHCI and OCHI host controller on an bcma bus.
668 It converts the bcma driver into two platform device drivers
669 for ehci and ohci.
670
671 If unsure, say N.
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index 0982bcc140b..9e0a89ced15 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -41,3 +41,5 @@ obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
41obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o 41obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
42obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o 42obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
43obj-$(CONFIG_MIPS_ALCHEMY) += alchemy-common.o 43obj-$(CONFIG_MIPS_ALCHEMY) += alchemy-common.o
44obj-$(CONFIG_USB_HCD_BCMA) += bcma-hcd.o
45obj-$(CONFIG_USB_HCD_SSB) += ssb-hcd.o
diff --git a/drivers/usb/host/bcma-hcd.c b/drivers/usb/host/bcma-hcd.c
new file mode 100644
index 00000000000..443da21d73c
--- /dev/null
+++ b/drivers/usb/host/bcma-hcd.c
@@ -0,0 +1,335 @@
1/*
2 * Broadcom specific Advanced Microcontroller Bus
3 * Broadcom USB-core driver (BCMA bus glue)
4 *
5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
6 *
7 * Based on ssb-ohci driver
8 * Copyright 2007 Michael Buesch <m@bues.ch>
9 *
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
15 *
16 * Derived from the USBcore related parts of Broadcom-SB
17 * Copyright 2005-2011 Broadcom Corporation
18 *
19 * Licensed under the GNU/GPL. See COPYING for details.
20 */
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>
28
29MODULE_AUTHOR("Hauke Mehrtens");
30MODULE_DESCRIPTION("Common USB driver for BCMA Bus");
31MODULE_LICENSE("GPL");
32
33struct bcma_hcd_device {
34 struct platform_device *ehci_dev;
35 struct platform_device *ohci_dev;
36};
37
38/* Wait for bitmask in a register to get set or cleared.
39 * timeout is in units of ten-microseconds.
40 */
41static int bcma_wait_bits(struct bcma_device *dev, u16 reg, u32 bitmask,
42 int timeout)
43{
44 int i;
45 u32 val;
46
47 for (i = 0; i < timeout; i++) {
48 val = bcma_read32(dev, reg);
49 if ((val & bitmask) == bitmask)
50 return 0;
51 udelay(10);
52 }
53
54 return -ETIMEDOUT;
55}
56
57static void __devinit bcma_hcd_4716wa(struct bcma_device *dev)
58{
59#ifdef CONFIG_BCMA_DRIVER_MIPS
60 /* Work around for 4716 failures. */
61 if (dev->bus->chipinfo.id == 0x4716) {
62 u32 tmp;
63
64 tmp = bcma_cpu_clock(&dev->bus->drv_mips);
65 if (tmp >= 480000000)
66 tmp = 0x1846b; /* set CDR to 0x11(fast) */
67 else if (tmp == 453000000)
68 tmp = 0x1046b; /* set CDR to 0x10(slow) */
69 else
70 tmp = 0;
71
72 /* Change Shim mdio control reg to fix host not acking at
73 * high frequencies
74 */
75 if (tmp) {
76 bcma_write32(dev, 0x524, 0x1); /* write sel to enable */
77 udelay(500);
78
79 bcma_write32(dev, 0x524, tmp);
80 udelay(500);
81 bcma_write32(dev, 0x524, 0x4ab);
82 udelay(500);
83 bcma_read32(dev, 0x528);
84 bcma_write32(dev, 0x528, 0x80000000);
85 }
86 }
87#endif /* CONFIG_BCMA_DRIVER_MIPS */
88}
89
90/* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
91static void __devinit bcma_hcd_init_chip(struct bcma_device *dev)
92{
93 u32 tmp;
94
95 /*
96 * USB 2.0 special considerations:
97 *
98 * 1. Since the core supports both OHCI and EHCI functions, it must
99 * only be reset once.
100 *
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.
104 */
105 if (!bcma_core_is_enabled(dev)) {
106 bcma_core_enable(dev, 0);
107 mdelay(10);
108 if (dev->id.rev >= 5) {
109 /* Enable Misc PLL */
110 tmp = bcma_read32(dev, 0x1e0);
111 tmp |= 0x100;
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");
115
116 /* Take out of resets */
117 bcma_write32(dev, 0x200, 0x4ff);
118 udelay(25);
119 bcma_write32(dev, 0x200, 0x6ff);
120 udelay(25);
121
122 /* Make sure digital and AFE are locked in USB PHY */
123 bcma_write32(dev, 0x524, 0x6b);
124 udelay(50);
125 tmp = bcma_read32(dev, 0x524);
126 udelay(50);
127 bcma_write32(dev, 0x524, 0xab);
128 udelay(50);
129 tmp = bcma_read32(dev, 0x524);
130 udelay(50);
131 bcma_write32(dev, 0x524, 0x2b);
132 udelay(50);
133 tmp = bcma_read32(dev, 0x524);
134 udelay(50);
135 bcma_write32(dev, 0x524, 0x10ab);
136 udelay(50);
137 tmp = bcma_read32(dev, 0x524);
138
139 if (bcma_wait_bits(dev, 0x528, 0xc000, 10000)) {
140 tmp = bcma_read32(dev, 0x528);
141 printk(KERN_EMERG
142 "USB20H mdio_rddata 0x%08x\n", tmp);
143 }
144 bcma_write32(dev, 0x528, 0x80000000);
145 tmp = bcma_read32(dev, 0x314);
146 udelay(265);
147 bcma_write32(dev, 0x200, 0x7ff);
148 udelay(10);
149
150 /* Take USB and HSIC out of non-driving modes */
151 bcma_write32(dev, 0x510, 0);
152 } else {
153 bcma_write32(dev, 0x200, 0x7ff);
154
155 udelay(1);
156 }
157
158 bcma_hcd_4716wa(dev);
159 }
160}
161
162static const struct usb_ehci_pdata ehci_pdata = {
163};
164
165static const struct usb_ohci_pdata ohci_pdata = {
166};
167
168static struct platform_device * __devinit
169bcma_hcd_create_pdev(struct bcma_device *dev, bool ohci, u32 addr)
170{
171 struct platform_device *hci_dev;
172 struct resource hci_res[2];
173 int ret = -ENOMEM;
174
175 memset(hci_res, 0, sizeof(hci_res));
176
177 hci_res[0].start = addr;
178 hci_res[0].end = hci_res[0].start + 0x1000 - 1;
179 hci_res[0].flags = IORESOURCE_MEM;
180
181 hci_res[1].start = dev->irq;
182 hci_res[1].flags = IORESOURCE_IRQ;
183
184 hci_dev = platform_device_alloc(ohci ? "ohci-platform" :
185 "ehci-platform" , 0);
186 if (!hci_dev)
187 return NULL;
188
189 hci_dev->dev.parent = &dev->dev;
190 hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
191
192 ret = platform_device_add_resources(hci_dev, hci_res,
193 ARRAY_SIZE(hci_res));
194 if (ret)
195 goto err_alloc;
196 if (ohci)
197 ret = platform_device_add_data(hci_dev, &ohci_pdata,
198 sizeof(ohci_pdata));
199 else
200 ret = platform_device_add_data(hci_dev, &ehci_pdata,
201 sizeof(ehci_pdata));
202 if (ret)
203 goto err_alloc;
204 ret = platform_device_add(hci_dev);
205 if (ret)
206 goto err_alloc;
207
208 return hci_dev;
209
210err_alloc:
211 platform_device_put(hci_dev);
212 return ERR_PTR(ret);
213}
214
215static int __devinit bcma_hcd_probe(struct bcma_device *dev)
216{
217 int err;
218 u16 chipid_top;
219 u32 ohci_addr;
220 struct bcma_hcd_device *usb_dev;
221 struct bcma_chipinfo *chipinfo;
222
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)
227 return -ENODEV;
228
229 /* TODO: Probably need checks here; is the core connected? */
230
231 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
232 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
233 return -EOPNOTSUPP;
234
235 usb_dev = kzalloc(sizeof(struct bcma_hcd_device), GFP_KERNEL);
236 if (!usb_dev)
237 return -ENOMEM;
238
239 bcma_hcd_init_chip(dev);
240
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;
246
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;
251 }
252
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;
257 }
258
259 bcma_set_drvdata(dev, usb_dev);
260 return 0;
261
262err_unregister_ohci_dev:
263 platform_device_unregister(usb_dev->ohci_dev);
264err_free_usb_dev:
265 kfree(usb_dev);
266 return err;
267}
268
269static void __devexit bcma_hcd_remove(struct bcma_device *dev)
270{
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;
274
275 if (ohci_dev)
276 platform_device_unregister(ohci_dev);
277 if (ehci_dev)
278 platform_device_unregister(ehci_dev);
279
280 bcma_core_disable(dev, 0);
281}
282
283static void bcma_hcd_shutdown(struct bcma_device *dev)
284{
285 bcma_core_disable(dev, 0);
286}
287
288#ifdef CONFIG_PM
289
290static int bcma_hcd_suspend(struct bcma_device *dev)
291{
292 bcma_core_disable(dev, 0);
293
294 return 0;
295}
296
297static int bcma_hcd_resume(struct bcma_device *dev)
298{
299 bcma_core_enable(dev, 0);
300
301 return 0;
302}
303
304#else /* !CONFIG_PM */
305#define bcma_hcd_suspend NULL
306#define bcma_hcd_resume NULL
307#endif /* CONFIG_PM */
308
309static 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),
311 BCMA_CORETABLE_END
312};
313MODULE_DEVICE_TABLE(bcma, bcma_hcd_table);
314
315static 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,
323};
324
325static int __init bcma_hcd_init(void)
326{
327 return bcma_driver_register(&bcma_hcd_driver);
328}
329module_init(bcma_hcd_init);
330
331static void __exit bcma_hcd_exit(void)
332{
333 bcma_driver_unregister(&bcma_hcd_driver);
334}
335module_exit(bcma_hcd_exit);
diff --git a/drivers/usb/host/ehci-dbg.c b/drivers/usb/host/ehci-dbg.c
index 680e1a31fb8..7561966fbdc 100644
--- a/drivers/usb/host/ehci-dbg.c
+++ b/drivers/usb/host/ehci-dbg.c
@@ -1025,10 +1025,8 @@ static ssize_t debug_lpm_write(struct file *file, const char __user *user_buf,
1025 if (strict_strtoul(buf + 5, 16, &hird)) 1025 if (strict_strtoul(buf + 5, 16, &hird))
1026 return -EINVAL; 1026 return -EINVAL;
1027 printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird); 1027 printk(KERN_INFO "setting hird %s %lu\n", buf + 6, hird);
1028 temp = ehci_readl(ehci, &ehci->regs->command); 1028 ehci->command = (ehci->command & ~CMD_HIRD) | (hird << 24);
1029 temp &= ~CMD_HIRD; 1029 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1030 temp |= hird << 24;
1031 ehci_writel(ehci, temp, &ehci->regs->command);
1032 } else if (strncmp(buf, "disable", 7) == 0) { 1030 } else if (strncmp(buf, "disable", 7) == 0) {
1033 if (strict_strtoul(buf + 8, 10, &port)) 1031 if (strict_strtoul(buf + 8, 10, &port))
1034 return -EINVAL; 1032 return -EINVAL;
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 3e7345172e0..43362577b54 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright 2005-2009 MontaVista Software, Inc. 2 * Copyright 2005-2009 MontaVista Software, Inc.
3 * Copyright 2008 Freescale Semiconductor, Inc. 3 * Copyright 2008,2012 Freescale Semiconductor, Inc.
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the 6 * under the terms of the GNU General Public License as published by the
@@ -150,8 +150,7 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver,
150 retval = otg_set_host(ehci->transceiver->otg, 150 retval = otg_set_host(ehci->transceiver->otg,
151 &ehci_to_hcd(ehci)->self); 151 &ehci_to_hcd(ehci)->self);
152 if (retval) { 152 if (retval) {
153 if (ehci->transceiver) 153 usb_put_transceiver(ehci->transceiver);
154 put_device(ehci->transceiver->dev);
155 goto err4; 154 goto err4;
156 } 155 }
157 } else { 156 } else {
@@ -195,7 +194,7 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
195 194
196 if (ehci->transceiver) { 195 if (ehci->transceiver) {
197 otg_set_host(ehci->transceiver->otg, NULL); 196 otg_set_host(ehci->transceiver->otg, NULL);
198 put_device(ehci->transceiver->dev); 197 usb_put_transceiver(ehci->transceiver);
199 } 198 }
200 199
201 usb_remove_hcd(hcd); 200 usb_remove_hcd(hcd);
@@ -211,19 +210,32 @@ static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
211 usb_put_hcd(hcd); 210 usb_put_hcd(hcd);
212} 211}
213 212
214static void ehci_fsl_setup_phy(struct ehci_hcd *ehci, 213static void ehci_fsl_setup_phy(struct usb_hcd *hcd,
215 enum fsl_usb2_phy_modes phy_mode, 214 enum fsl_usb2_phy_modes phy_mode,
216 unsigned int port_offset) 215 unsigned int port_offset)
217{ 216{
218 u32 portsc; 217 u32 portsc, temp;
219 struct usb_hcd *hcd = ehci_to_hcd(ehci); 218 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
220 void __iomem *non_ehci = hcd->regs; 219 void __iomem *non_ehci = hcd->regs;
220 struct device *dev = hcd->self.controller;
221 struct fsl_usb2_platform_data *pdata = dev->platform_data;
222
223 if (pdata->controller_ver < 0) {
224 dev_warn(hcd->self.controller, "Could not get controller version\n");
225 return;
226 }
221 227
222 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]); 228 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]);
223 portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW); 229 portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
224 230
225 switch (phy_mode) { 231 switch (phy_mode) {
226 case FSL_USB2_PHY_ULPI: 232 case FSL_USB2_PHY_ULPI:
233 if (pdata->controller_ver) {
234 /* controller version 1.6 or above */
235 temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
236 out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
237 USB_CTRL_USB_EN | ULPI_PHY_CLK_SEL);
238 }
227 portsc |= PORT_PTS_ULPI; 239 portsc |= PORT_PTS_ULPI;
228 break; 240 break;
229 case FSL_USB2_PHY_SERIAL: 241 case FSL_USB2_PHY_SERIAL:
@@ -233,8 +245,18 @@ static void ehci_fsl_setup_phy(struct ehci_hcd *ehci,
233 portsc |= PORT_PTS_PTW; 245 portsc |= PORT_PTS_PTW;
234 /* fall through */ 246 /* fall through */
235 case FSL_USB2_PHY_UTMI: 247 case FSL_USB2_PHY_UTMI:
248 if (pdata->controller_ver) {
249 /* controller version 1.6 or above */
250 temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
251 out_be32(non_ehci + FSL_SOC_USB_CTRL, temp |
252 UTMI_PHY_EN | USB_CTRL_USB_EN);
253 mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI PHY CLK to
254 become stable - 10ms*/
255 }
236 /* enable UTMI PHY */ 256 /* enable UTMI PHY */
237 setbits32(non_ehci + FSL_SOC_USB_CTRL, CTRL_UTMI_PHY_EN); 257 if (pdata->have_sysif_regs)
258 setbits32(non_ehci + FSL_SOC_USB_CTRL,
259 CTRL_UTMI_PHY_EN);
238 portsc |= PORT_PTS_UTMI; 260 portsc |= PORT_PTS_UTMI;
239 break; 261 break;
240 case FSL_USB2_PHY_NONE: 262 case FSL_USB2_PHY_NONE:
@@ -271,7 +293,7 @@ static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
271 293
272 if ((pdata->operating_mode == FSL_USB2_DR_HOST) || 294 if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
273 (pdata->operating_mode == FSL_USB2_DR_OTG)) 295 (pdata->operating_mode == FSL_USB2_DR_OTG))
274 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 0); 296 ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0);
275 297
276 if (pdata->operating_mode == FSL_USB2_MPH_HOST) { 298 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
277 unsigned int chip, rev, svr; 299 unsigned int chip, rev, svr;
@@ -285,9 +307,9 @@ static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
285 ehci->has_fsl_port_bug = 1; 307 ehci->has_fsl_port_bug = 1;
286 308
287 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED) 309 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
288 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 0); 310 ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0);
289 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED) 311 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
290 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 1); 312 ehci_fsl_setup_phy(hcd, pdata->phy_mode, 1);
291 } 313 }
292 314
293 if (pdata->have_sysif_regs) { 315 if (pdata->have_sysif_regs) {
diff --git a/drivers/usb/host/ehci-fsl.h b/drivers/usb/host/ehci-fsl.h
index 863fb0c080d..88403684d10 100644
--- a/drivers/usb/host/ehci-fsl.h
+++ b/drivers/usb/host/ehci-fsl.h
@@ -1,4 +1,4 @@
1/* Copyright (C) 2005-2010 Freescale Semiconductor, Inc. 1/* Copyright (C) 2005-2010,2012 Freescale Semiconductor, Inc.
2 * Copyright (c) 2005 MontaVista Software 2 * Copyright (c) 2005 MontaVista Software
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify it 4 * This program is free software; you can redistribute it and/or modify it
@@ -50,4 +50,15 @@
50#define CTRL_UTMI_PHY_EN (1<<9) 50#define CTRL_UTMI_PHY_EN (1<<9)
51#define CTRL_PHY_CLK_VALID (1 << 17) 51#define CTRL_PHY_CLK_VALID (1 << 17)
52#define SNOOP_SIZE_2GB 0x1e 52#define SNOOP_SIZE_2GB 0x1e
53
54/* control Register Bit Masks */
55#define ULPI_INT_EN (1<<0)
56#define WU_INT_EN (1<<1)
57#define USB_CTRL_USB_EN (1<<2)
58#define LINE_STATE_FILTER__EN (1<<3)
59#define KEEP_OTG_ON (1<<4)
60#define OTG_PORT (1<<5)
61#define PLL_RESET (1<<8)
62#define UTMI_PHY_EN (1<<9)
63#define ULPI_PHY_CLK_SEL (1<<10)
53#endif /* _EHCI_FSL_H */ 64#endif /* _EHCI_FSL_H */
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 806cc95317a..b100f5f9f4b 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -226,8 +226,13 @@ static int ehci_halt (struct ehci_hcd *ehci)
226 if ((temp & STS_HALT) != 0) 226 if ((temp & STS_HALT) != 0)
227 return 0; 227 return 0;
228 228
229 /*
230 * This routine gets called during probe before ehci->command
231 * has been initialized, so we can't rely on its value.
232 */
233 ehci->command &= ~CMD_RUN;
229 temp = ehci_readl(ehci, &ehci->regs->command); 234 temp = ehci_readl(ehci, &ehci->regs->command);
230 temp &= ~CMD_RUN; 235 temp &= ~(CMD_RUN | CMD_IAAD);
231 ehci_writel(ehci, temp, &ehci->regs->command); 236 ehci_writel(ehci, temp, &ehci->regs->command);
232 return handshake (ehci, &ehci->regs->status, 237 return handshake (ehci, &ehci->regs->status,
233 STS_HALT, STS_HALT, 16 * 125); 238 STS_HALT, STS_HALT, 16 * 125);
@@ -363,16 +368,14 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
363#endif 368#endif
364 369
365 /* wait for any schedule enables/disables to take effect */ 370 /* wait for any schedule enables/disables to take effect */
366 temp = ehci_readl(ehci, &ehci->regs->command) << 10; 371 temp = (ehci->command << 10) & (STS_ASS | STS_PSS);
367 temp &= STS_ASS | STS_PSS;
368 if (handshake_on_error_set_halt(ehci, &ehci->regs->status, 372 if (handshake_on_error_set_halt(ehci, &ehci->regs->status,
369 STS_ASS | STS_PSS, temp, 16 * 125)) 373 STS_ASS | STS_PSS, temp, 16 * 125))
370 return; 374 return;
371 375
372 /* then disable anything that's still active */ 376 /* then disable anything that's still active */
373 temp = ehci_readl(ehci, &ehci->regs->command); 377 ehci->command &= ~(CMD_ASE | CMD_PSE);
374 temp &= ~(CMD_ASE | CMD_IAAD | CMD_PSE); 378 ehci_writel(ehci, ehci->command, &ehci->regs->command);
375 ehci_writel(ehci, temp, &ehci->regs->command);
376 379
377 /* hardware can take 16 microframes to turn off ... */ 380 /* hardware can take 16 microframes to turn off ... */
378 handshake_on_error_set_halt(ehci, &ehci->regs->status, 381 handshake_on_error_set_halt(ehci, &ehci->regs->status,
@@ -417,9 +420,6 @@ static void ehci_iaa_watchdog(unsigned long param)
417 * CMD_IAAD when it sets STS_IAA.) 420 * CMD_IAAD when it sets STS_IAA.)
418 */ 421 */
419 cmd = ehci_readl(ehci, &ehci->regs->command); 422 cmd = ehci_readl(ehci, &ehci->regs->command);
420 if (cmd & CMD_IAAD)
421 ehci_writel(ehci, cmd & ~CMD_IAAD,
422 &ehci->regs->command);
423 423
424 /* If IAA is set here it either legitimately triggered 424 /* If IAA is set here it either legitimately triggered
425 * before we cleared IAAD above (but _way_ late, so we'll 425 * before we cleared IAAD above (but _way_ late, so we'll
@@ -858,8 +858,13 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
858 goto dead; 858 goto dead;
859 } 859 }
860 860
861 /*
862 * We don't use STS_FLR, but some controllers don't like it to
863 * remain on, so mask it out along with the other status bits.
864 */
865 masked_status = status & (INTR_MASK | STS_FLR);
866
861 /* Shared IRQ? */ 867 /* Shared IRQ? */
862 masked_status = status & INTR_MASK;
863 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) { 868 if (!masked_status || unlikely(ehci->rh_state == EHCI_RH_HALTED)) {
864 spin_unlock(&ehci->lock); 869 spin_unlock(&ehci->lock);
865 return IRQ_NONE; 870 return IRQ_NONE;
@@ -889,11 +894,8 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
889 /* complete the unlinking of some qh [4.15.2.3] */ 894 /* complete the unlinking of some qh [4.15.2.3] */
890 if (status & STS_IAA) { 895 if (status & STS_IAA) {
891 /* guard against (alleged) silicon errata */ 896 /* guard against (alleged) silicon errata */
892 if (cmd & CMD_IAAD) { 897 if (cmd & CMD_IAAD)
893 ehci_writel(ehci, cmd & ~CMD_IAAD,
894 &ehci->regs->command);
895 ehci_dbg(ehci, "IAA with IAAD still set?\n"); 898 ehci_dbg(ehci, "IAA with IAAD still set?\n");
896 }
897 if (ehci->reclaim) { 899 if (ehci->reclaim) {
898 COUNT(ehci->stats.reclaim); 900 COUNT(ehci->stats.reclaim);
899 end_unlink_async(ehci); 901 end_unlink_async(ehci);
@@ -910,7 +912,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
910 pcd_status = status; 912 pcd_status = status;
911 913
912 /* resume root hub? */ 914 /* resume root hub? */
913 if (!(cmd & CMD_RUN)) 915 if (ehci->rh_state == EHCI_RH_SUSPENDED)
914 usb_hcd_resume_root_hub(hcd); 916 usb_hcd_resume_root_hub(hcd);
915 917
916 /* get per-port change detect bits */ 918 /* get per-port change detect bits */
@@ -1243,6 +1245,13 @@ static int ehci_get_frame (struct usb_hcd *hcd)
1243} 1245}
1244 1246
1245/*-------------------------------------------------------------------------*/ 1247/*-------------------------------------------------------------------------*/
1248/*
1249 * The EHCI in ChipIdea HDRC cannot be a separate module or device,
1250 * because its registers (and irq) are shared between host/gadget/otg
1251 * functions and in order to facilitate role switching we cannot
1252 * give the ehci driver exclusive access to those.
1253 */
1254#ifndef CHIPIDEA_EHCI
1246 1255
1247MODULE_DESCRIPTION(DRIVER_DESC); 1256MODULE_DESCRIPTION(DRIVER_DESC);
1248MODULE_AUTHOR (DRIVER_AUTHOR); 1257MODULE_AUTHOR (DRIVER_AUTHOR);
@@ -1373,6 +1382,11 @@ MODULE_LICENSE ("GPL");
1373#define PLATFORM_DRIVER ehci_ls1x_driver 1382#define PLATFORM_DRIVER ehci_ls1x_driver
1374#endif 1383#endif
1375 1384
1385#ifdef CONFIG_MIPS_SEAD3
1386#include "ehci-sead3.c"
1387#define PLATFORM_DRIVER ehci_hcd_sead3_driver
1388#endif
1389
1376#ifdef CONFIG_USB_EHCI_HCD_PLATFORM 1390#ifdef CONFIG_USB_EHCI_HCD_PLATFORM
1377#include "ehci-platform.c" 1391#include "ehci-platform.c"
1378#define PLATFORM_DRIVER ehci_platform_driver 1392#define PLATFORM_DRIVER ehci_platform_driver
@@ -1496,3 +1510,4 @@ static void __exit ehci_hcd_cleanup(void)
1496} 1510}
1497module_exit(ehci_hcd_cleanup); 1511module_exit(ehci_hcd_cleanup);
1498 1512
1513#endif /* CHIPIDEA_EHCI */
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 38fe0762315..fc9e7cc6ac9 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -233,7 +233,6 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
233 /* stop schedules, clean any completed work */ 233 /* stop schedules, clean any completed work */
234 if (ehci->rh_state == EHCI_RH_RUNNING) 234 if (ehci->rh_state == EHCI_RH_RUNNING)
235 ehci_quiesce (ehci); 235 ehci_quiesce (ehci);
236 ehci->command = ehci_readl(ehci, &ehci->regs->command);
237 ehci_work(ehci); 236 ehci_work(ehci);
238 237
239 /* Unlike other USB host controller types, EHCI doesn't have 238 /* Unlike other USB host controller types, EHCI doesn't have
@@ -374,6 +373,7 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
374 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next); 373 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
375 374
376 /* restore CMD_RUN, framelist size, and irq threshold */ 375 /* restore CMD_RUN, framelist size, and irq threshold */
376 ehci->command |= CMD_RUN;
377 ehci_writel(ehci, ehci->command, &ehci->regs->command); 377 ehci_writel(ehci, ehci->command, &ehci->regs->command);
378 ehci->rh_state = EHCI_RH_RUNNING; 378 ehci->rh_state = EHCI_RH_RUNNING;
379 379
@@ -531,7 +531,8 @@ static int check_reset_complete (
531 if (ehci->has_amcc_usb23) 531 if (ehci->has_amcc_usb23)
532 set_ohci_hcfs(ehci, 1); 532 set_ohci_hcfs(ehci, 1);
533 } else { 533 } else {
534 ehci_dbg (ehci, "port %d high speed\n", index + 1); 534 ehci_dbg(ehci, "port %d reset complete, port enabled\n",
535 index + 1);
535 /* ensure 440EPx ohci controller state is suspended */ 536 /* ensure 440EPx ohci controller state is suspended */
536 if (ehci->has_amcc_usb23) 537 if (ehci->has_amcc_usb23)
537 set_ohci_hcfs(ehci, 0); 538 set_ohci_hcfs(ehci, 0);
@@ -699,6 +700,7 @@ static int ehci_hub_control (
699 goto error; 700 goto error;
700 wIndex--; 701 wIndex--;
701 temp = ehci_readl(ehci, status_reg); 702 temp = ehci_readl(ehci, status_reg);
703 temp &= ~PORT_RWC_BITS;
702 704
703 /* 705 /*
704 * Even if OWNER is set, so the port is owned by the 706 * Even if OWNER is set, so the port is owned by the
@@ -712,8 +714,7 @@ static int ehci_hub_control (
712 ehci_writel(ehci, temp & ~PORT_PE, status_reg); 714 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
713 break; 715 break;
714 case USB_PORT_FEAT_C_ENABLE: 716 case USB_PORT_FEAT_C_ENABLE:
715 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_PEC, 717 ehci_writel(ehci, temp | PORT_PEC, status_reg);
716 status_reg);
717 break; 718 break;
718 case USB_PORT_FEAT_SUSPEND: 719 case USB_PORT_FEAT_SUSPEND:
719 if (temp & PORT_RESET) 720 if (temp & PORT_RESET)
@@ -742,7 +743,7 @@ static int ehci_hub_control (
742 spin_lock_irqsave(&ehci->lock, flags); 743 spin_lock_irqsave(&ehci->lock, flags);
743 } 744 }
744 /* resume signaling for 20 msec */ 745 /* resume signaling for 20 msec */
745 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); 746 temp &= ~PORT_WAKE_BITS;
746 ehci_writel(ehci, temp | PORT_RESUME, status_reg); 747 ehci_writel(ehci, temp | PORT_RESUME, status_reg);
747 ehci->reset_done[wIndex] = jiffies 748 ehci->reset_done[wIndex] = jiffies
748 + msecs_to_jiffies(20); 749 + msecs_to_jiffies(20);
@@ -752,9 +753,8 @@ static int ehci_hub_control (
752 break; 753 break;
753 case USB_PORT_FEAT_POWER: 754 case USB_PORT_FEAT_POWER:
754 if (HCS_PPC (ehci->hcs_params)) 755 if (HCS_PPC (ehci->hcs_params))
755 ehci_writel(ehci, 756 ehci_writel(ehci, temp & ~PORT_POWER,
756 temp & ~(PORT_RWC_BITS | PORT_POWER), 757 status_reg);
757 status_reg);
758 break; 758 break;
759 case USB_PORT_FEAT_C_CONNECTION: 759 case USB_PORT_FEAT_C_CONNECTION:
760 if (ehci->has_lpm) { 760 if (ehci->has_lpm) {
@@ -762,12 +762,10 @@ static int ehci_hub_control (
762 temp &= ~PORT_LPM; 762 temp &= ~PORT_LPM;
763 temp &= ~PORT_DEV_ADDR; 763 temp &= ~PORT_DEV_ADDR;
764 } 764 }
765 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_CSC, 765 ehci_writel(ehci, temp | PORT_CSC, status_reg);
766 status_reg);
767 break; 766 break;
768 case USB_PORT_FEAT_C_OVER_CURRENT: 767 case USB_PORT_FEAT_C_OVER_CURRENT:
769 ehci_writel(ehci, (temp & ~PORT_RWC_BITS) | PORT_OCC, 768 ehci_writel(ehci, temp | PORT_OCC, status_reg);
770 status_reg);
771 break; 769 break;
772 case USB_PORT_FEAT_C_RESET: 770 case USB_PORT_FEAT_C_RESET:
773 /* GetPortStatus clears reset */ 771 /* GetPortStatus clears reset */
diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c
index bba9850f32f..a44294d1349 100644
--- a/drivers/usb/host/ehci-omap.c
+++ b/drivers/usb/host/ehci-omap.c
@@ -42,6 +42,7 @@
42#include <plat/usb.h> 42#include <plat/usb.h>
43#include <linux/regulator/consumer.h> 43#include <linux/regulator/consumer.h>
44#include <linux/pm_runtime.h> 44#include <linux/pm_runtime.h>
45#include <linux/gpio.h>
45 46
46/* EHCI Register Set */ 47/* EHCI Register Set */
47#define EHCI_INSNREG04 (0xA0) 48#define EHCI_INSNREG04 (0xA0)
@@ -191,6 +192,19 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
191 } 192 }
192 } 193 }
193 194
195 if (pdata->phy_reset) {
196 if (gpio_is_valid(pdata->reset_gpio_port[0]))
197 gpio_request_one(pdata->reset_gpio_port[0],
198 GPIOF_OUT_INIT_LOW, "USB1 PHY reset");
199
200 if (gpio_is_valid(pdata->reset_gpio_port[1]))
201 gpio_request_one(pdata->reset_gpio_port[1],
202 GPIOF_OUT_INIT_LOW, "USB2 PHY reset");
203
204 /* Hold the PHY in RESET for enough time till DIR is high */
205 udelay(10);
206 }
207
194 pm_runtime_enable(dev); 208 pm_runtime_enable(dev);
195 pm_runtime_get_sync(dev); 209 pm_runtime_get_sync(dev);
196 210
@@ -228,6 +242,19 @@ static int ehci_hcd_omap_probe(struct platform_device *pdev)
228 242
229 ehci_reset(omap_ehci); 243 ehci_reset(omap_ehci);
230 244
245 if (pdata->phy_reset) {
246 /* Hold the PHY in RESET for enough time till
247 * PHY is settled and ready
248 */
249 udelay(10);
250
251 if (gpio_is_valid(pdata->reset_gpio_port[0]))
252 gpio_set_value_cansleep(pdata->reset_gpio_port[0], 1);
253
254 if (gpio_is_valid(pdata->reset_gpio_port[1]))
255 gpio_set_value_cansleep(pdata->reset_gpio_port[1], 1);
256 }
257
231 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 258 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
232 if (ret) { 259 if (ret) {
233 dev_err(dev, "failed to add hcd with err %d\n", ret); 260 dev_err(dev, "failed to add hcd with err %d\n", ret);
@@ -259,8 +286,9 @@ err_io:
259 */ 286 */
260static int ehci_hcd_omap_remove(struct platform_device *pdev) 287static int ehci_hcd_omap_remove(struct platform_device *pdev)
261{ 288{
262 struct device *dev = &pdev->dev; 289 struct device *dev = &pdev->dev;
263 struct usb_hcd *hcd = dev_get_drvdata(dev); 290 struct usb_hcd *hcd = dev_get_drvdata(dev);
291 struct ehci_hcd_omap_platform_data *pdata = dev->platform_data;
264 292
265 usb_remove_hcd(hcd); 293 usb_remove_hcd(hcd);
266 disable_put_regulator(dev->platform_data); 294 disable_put_regulator(dev->platform_data);
@@ -269,6 +297,13 @@ static int ehci_hcd_omap_remove(struct platform_device *pdev)
269 pm_runtime_put_sync(dev); 297 pm_runtime_put_sync(dev);
270 pm_runtime_disable(dev); 298 pm_runtime_disable(dev);
271 299
300 if (pdata->phy_reset) {
301 if (gpio_is_valid(pdata->reset_gpio_port[0]))
302 gpio_free(pdata->reset_gpio_port[0]);
303
304 if (gpio_is_valid(pdata->reset_gpio_port[1]))
305 gpio_free(pdata->reset_gpio_port[1]);
306 }
272 return 0; 307 return 0;
273} 308}
274 309
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 01bb7241d6e..bc94d7bf072 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -144,6 +144,14 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
144 hcd->has_tt = 1; 144 hcd->has_tt = 1;
145 tdi_reset(ehci); 145 tdi_reset(ehci);
146 } 146 }
147 if (pdev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK) {
148 /* EHCI #1 or #2 on 6 Series/C200 Series chipset */
149 if (pdev->device == 0x1c26 || pdev->device == 0x1c2d) {
150 ehci_info(ehci, "broken D3 during system sleep on ASUS\n");
151 hcd->broken_pci_sleep = 1;
152 device_set_wakeup_capable(&pdev->dev, false);
153 }
154 }
147 break; 155 break;
148 case PCI_VENDOR_ID_TDI: 156 case PCI_VENDOR_ID_TDI:
149 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) { 157 if (pdev->device == PCI_DEVICE_ID_TDI_EHCI) {
@@ -360,7 +368,9 @@ static bool usb_is_intel_switchable_ehci(struct pci_dev *pdev)
360{ 368{
361 return pdev->class == PCI_CLASS_SERIAL_USB_EHCI && 369 return pdev->class == PCI_CLASS_SERIAL_USB_EHCI &&
362 pdev->vendor == PCI_VENDOR_ID_INTEL && 370 pdev->vendor == PCI_VENDOR_ID_INTEL &&
363 pdev->device == 0x1E26; 371 (pdev->device == 0x1E26 ||
372 pdev->device == 0x8C2D ||
373 pdev->device == 0x8C26);
364} 374}
365 375
366static void ehci_enable_xhci_companion(void) 376static void ehci_enable_xhci_companion(void)
diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index d238b4e24bb..dfe881a34ae 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -75,8 +75,6 @@ static const struct hc_driver ehci_platform_hc_driver = {
75 .relinquish_port = ehci_relinquish_port, 75 .relinquish_port = ehci_relinquish_port,
76 .port_handed_over = ehci_port_handed_over, 76 .port_handed_over = ehci_port_handed_over,
77 77
78 .update_device = ehci_update_device,
79
80 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 78 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
81}; 79};
82 80
@@ -94,12 +92,12 @@ static int __devinit ehci_platform_probe(struct platform_device *dev)
94 92
95 irq = platform_get_irq(dev, 0); 93 irq = platform_get_irq(dev, 0);
96 if (irq < 0) { 94 if (irq < 0) {
97 pr_err("no irq provieded"); 95 pr_err("no irq provided");
98 return irq; 96 return irq;
99 } 97 }
100 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); 98 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
101 if (!res_mem) { 99 if (!res_mem) {
102 pr_err("no memory recourse provieded"); 100 pr_err("no memory recourse provided");
103 return -ENXIO; 101 return -ENXIO;
104 } 102 }
105 103
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 36ca5077cdf..4378bf72bba 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -943,7 +943,8 @@ qh_make (
943 } 943 }
944 break; 944 break;
945 default: 945 default:
946 dbg ("bogus dev %p speed %d", urb->dev, urb->dev->speed); 946 ehci_dbg(ehci, "bogus dev %p speed %d\n", urb->dev,
947 urb->dev->speed);
947done: 948done:
948 qh_put (qh); 949 qh_put (qh);
949 return NULL; 950 return NULL;
@@ -981,14 +982,12 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
981 head = ehci->async; 982 head = ehci->async;
982 timer_action_done (ehci, TIMER_ASYNC_OFF); 983 timer_action_done (ehci, TIMER_ASYNC_OFF);
983 if (!head->qh_next.qh) { 984 if (!head->qh_next.qh) {
984 u32 cmd = ehci_readl(ehci, &ehci->regs->command); 985 if (!(ehci->command & CMD_ASE)) {
985
986 if (!(cmd & CMD_ASE)) {
987 /* in case a clear of CMD_ASE didn't take yet */ 986 /* in case a clear of CMD_ASE didn't take yet */
988 (void)handshake(ehci, &ehci->regs->status, 987 (void)handshake(ehci, &ehci->regs->status,
989 STS_ASS, 0, 150); 988 STS_ASS, 0, 150);
990 cmd |= CMD_ASE; 989 ehci->command |= CMD_ASE;
991 ehci_writel(ehci, cmd, &ehci->regs->command); 990 ehci_writel(ehci, ehci->command, &ehci->regs->command);
992 /* posted write need not be known to HC yet ... */ 991 /* posted write need not be known to HC yet ... */
993 } 992 }
994 } 993 }
@@ -1204,7 +1203,6 @@ static void end_unlink_async (struct ehci_hcd *ehci)
1204 1203
1205static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) 1204static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1206{ 1205{
1207 int cmd = ehci_readl(ehci, &ehci->regs->command);
1208 struct ehci_qh *prev; 1206 struct ehci_qh *prev;
1209 1207
1210#ifdef DEBUG 1208#ifdef DEBUG
@@ -1222,8 +1220,8 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1222 if (ehci->rh_state != EHCI_RH_HALTED 1220 if (ehci->rh_state != EHCI_RH_HALTED
1223 && !ehci->reclaim) { 1221 && !ehci->reclaim) {
1224 /* ... and CMD_IAAD clear */ 1222 /* ... and CMD_IAAD clear */
1225 ehci_writel(ehci, cmd & ~CMD_ASE, 1223 ehci->command &= ~CMD_ASE;
1226 &ehci->regs->command); 1224 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1227 wmb (); 1225 wmb ();
1228 // handshake later, if we need to 1226 // handshake later, if we need to
1229 timer_action_done (ehci, TIMER_ASYNC_OFF); 1227 timer_action_done (ehci, TIMER_ASYNC_OFF);
@@ -1253,8 +1251,7 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
1253 return; 1251 return;
1254 } 1252 }
1255 1253
1256 cmd |= CMD_IAAD; 1254 ehci_writel(ehci, ehci->command | CMD_IAAD, &ehci->regs->command);
1257 ehci_writel(ehci, cmd, &ehci->regs->command);
1258 (void)ehci_readl(ehci, &ehci->regs->command); 1255 (void)ehci_readl(ehci, &ehci->regs->command);
1259 iaa_watchdog_start(ehci); 1256 iaa_watchdog_start(ehci);
1260} 1257}
diff --git a/drivers/usb/host/ehci-s5p.c b/drivers/usb/host/ehci-s5p.c
index f098e2a291a..c474cec064e 100644
--- a/drivers/usb/host/ehci-s5p.c
+++ b/drivers/usb/host/ehci-s5p.c
@@ -232,6 +232,8 @@ static int s5p_ehci_suspend(struct device *dev)
232 if (pdata && pdata->phy_exit) 232 if (pdata && pdata->phy_exit)
233 pdata->phy_exit(pdev, S5P_USB_PHY_HOST); 233 pdata->phy_exit(pdev, S5P_USB_PHY_HOST);
234 234
235 clk_disable(s5p_ehci->clk);
236
235 return rc; 237 return rc;
236} 238}
237 239
@@ -243,6 +245,8 @@ static int s5p_ehci_resume(struct device *dev)
243 struct platform_device *pdev = to_platform_device(dev); 245 struct platform_device *pdev = to_platform_device(dev);
244 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data; 246 struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
245 247
248 clk_enable(s5p_ehci->clk);
249
246 if (pdata && pdata->phy_init) 250 if (pdata && pdata->phy_init)
247 pdata->phy_init(pdev, S5P_USB_PHY_HOST); 251 pdata->phy_init(pdev, S5P_USB_PHY_HOST);
248 252
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index a60679cbbf8..33182c6d1ff 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -481,7 +481,6 @@ static int tt_no_collision (
481 481
482static int enable_periodic (struct ehci_hcd *ehci) 482static int enable_periodic (struct ehci_hcd *ehci)
483{ 483{
484 u32 cmd;
485 int status; 484 int status;
486 485
487 if (ehci->periodic_sched++) 486 if (ehci->periodic_sched++)
@@ -497,8 +496,8 @@ static int enable_periodic (struct ehci_hcd *ehci)
497 return status; 496 return status;
498 } 497 }
499 498
500 cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE; 499 ehci->command |= CMD_PSE;
501 ehci_writel(ehci, cmd, &ehci->regs->command); 500 ehci_writel(ehci, ehci->command, &ehci->regs->command);
502 /* posted write ... PSS happens later */ 501 /* posted write ... PSS happens later */
503 502
504 /* make sure ehci_work scans these */ 503 /* make sure ehci_work scans these */
@@ -511,7 +510,6 @@ static int enable_periodic (struct ehci_hcd *ehci)
511 510
512static int disable_periodic (struct ehci_hcd *ehci) 511static int disable_periodic (struct ehci_hcd *ehci)
513{ 512{
514 u32 cmd;
515 int status; 513 int status;
516 514
517 if (--ehci->periodic_sched) 515 if (--ehci->periodic_sched)
@@ -537,8 +535,8 @@ static int disable_periodic (struct ehci_hcd *ehci)
537 return status; 535 return status;
538 } 536 }
539 537
540 cmd = ehci_readl(ehci, &ehci->regs->command) & ~CMD_PSE; 538 ehci->command &= ~CMD_PSE;
541 ehci_writel(ehci, cmd, &ehci->regs->command); 539 ehci_writel(ehci, ehci->command, &ehci->regs->command);
542 /* posted write ... */ 540 /* posted write ... */
543 541
544 free_cached_lists(ehci); 542 free_cached_lists(ehci);
@@ -1333,34 +1331,36 @@ sitd_slot_ok (
1333 if (mask & ~0xffff) 1331 if (mask & ~0xffff)
1334 return 0; 1332 return 0;
1335 1333
1334 /* check bandwidth */
1335 uframe %= period_uframes;
1336 frame = uframe >> 3;
1337
1338#ifdef CONFIG_USB_EHCI_TT_NEWSCHED
1339 /* The tt's fullspeed bus bandwidth must be available.
1340 * tt_available scheduling guarantees 10+% for control/bulk.
1341 */
1342 uf = uframe & 7;
1343 if (!tt_available(ehci, period_uframes >> 3,
1344 stream->udev, frame, uf, stream->tt_usecs))
1345 return 0;
1346#else
1347 /* tt must be idle for start(s), any gap, and csplit.
1348 * assume scheduling slop leaves 10+% for control/bulk.
1349 */
1350 if (!tt_no_collision(ehci, period_uframes >> 3,
1351 stream->udev, frame, mask))
1352 return 0;
1353#endif
1354
1336 /* this multi-pass logic is simple, but performance may 1355 /* this multi-pass logic is simple, but performance may
1337 * suffer when the schedule data isn't cached. 1356 * suffer when the schedule data isn't cached.
1338 */ 1357 */
1339
1340 /* check bandwidth */
1341 uframe %= period_uframes;
1342 do { 1358 do {
1343 u32 max_used; 1359 u32 max_used;
1344 1360
1345 frame = uframe >> 3; 1361 frame = uframe >> 3;
1346 uf = uframe & 7; 1362 uf = uframe & 7;
1347 1363
1348#ifdef CONFIG_USB_EHCI_TT_NEWSCHED
1349 /* The tt's fullspeed bus bandwidth must be available.
1350 * tt_available scheduling guarantees 10+% for control/bulk.
1351 */
1352 if (!tt_available (ehci, period_uframes << 3,
1353 stream->udev, frame, uf, stream->tt_usecs))
1354 return 0;
1355#else
1356 /* tt must be idle for start(s), any gap, and csplit.
1357 * assume scheduling slop leaves 10+% for control/bulk.
1358 */
1359 if (!tt_no_collision (ehci, period_uframes << 3,
1360 stream->udev, frame, mask))
1361 return 0;
1362#endif
1363
1364 /* check starts (OUT uses more than one) */ 1364 /* check starts (OUT uses more than one) */
1365 max_used = ehci->uframe_periodic_max - stream->usecs; 1365 max_used = ehci->uframe_periodic_max - stream->usecs;
1366 for (tmp = stream->raw_mask & 0xff; tmp; tmp >>= 1, uf++) { 1366 for (tmp = stream->raw_mask & 0xff; tmp; tmp >>= 1, uf++) {
@@ -2358,7 +2358,8 @@ restart:
2358 * in the previous frame for completions. 2358 * in the previous frame for completions.
2359 */ 2359 */
2360 if (q.fstn->hw_prev != EHCI_LIST_END(ehci)) { 2360 if (q.fstn->hw_prev != EHCI_LIST_END(ehci)) {
2361 dbg ("ignoring completions from FSTNs"); 2361 ehci_dbg(ehci,
2362 "ignoring completions from FSTNs\n");
2362 } 2363 }
2363 type = Q_NEXT_TYPE(ehci, q.fstn->hw_next); 2364 type = Q_NEXT_TYPE(ehci, q.fstn->hw_next);
2364 q = q.fstn->fstn_next; 2365 q = q.fstn->fstn_next;
@@ -2441,7 +2442,7 @@ restart:
2441 q = *q_p; 2442 q = *q_p;
2442 break; 2443 break;
2443 default: 2444 default:
2444 dbg ("corrupt type %d frame %d shadow %p", 2445 ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
2445 type, frame, q.ptr); 2446 type, frame, q.ptr);
2446 // BUG (); 2447 // BUG ();
2447 q.ptr = NULL; 2448 q.ptr = NULL;
diff --git a/drivers/usb/host/ehci-sead3.c b/drivers/usb/host/ehci-sead3.c
new file mode 100644
index 00000000000..cc199e87a7a
--- /dev/null
+++ b/drivers/usb/host/ehci-sead3.c
@@ -0,0 +1,266 @@
1/*
2 * MIPS CI13320A EHCI Host Controller driver
3 * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com>
4 *
5 * Copyright (C) 2012 MIPS Technologies, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/platform_device.h>
23
24static int ehci_sead3_setup(struct usb_hcd *hcd)
25{
26 int ret;
27 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
28
29 ehci->caps = hcd->regs + 0x100;
30
31#ifdef __BIG_ENDIAN
32 ehci->big_endian_mmio = 1;
33 ehci->big_endian_desc = 1;
34#endif
35
36 ret = ehci_setup(hcd);
37 if (ret)
38 return ret;
39
40 ehci->need_io_watchdog = 0;
41
42 /* Set burst length to 16 words. */
43 ehci_writel(ehci, 0x1010, &ehci->regs->reserved[1]);
44
45 return ret;
46}
47
48const struct hc_driver ehci_sead3_hc_driver = {
49 .description = hcd_name,
50 .product_desc = "SEAD-3 EHCI",
51 .hcd_priv_size = sizeof(struct ehci_hcd),
52
53 /*
54 * generic hardware linkage
55 */
56 .irq = ehci_irq,
57 .flags = HCD_MEMORY | HCD_USB2,
58
59 /*
60 * basic lifecycle operations
61 *
62 */
63 .reset = ehci_sead3_setup,
64 .start = ehci_run,
65 .stop = ehci_stop,
66 .shutdown = ehci_shutdown,
67
68 /*
69 * managing i/o requests and associated device resources
70 */
71 .urb_enqueue = ehci_urb_enqueue,
72 .urb_dequeue = ehci_urb_dequeue,
73 .endpoint_disable = ehci_endpoint_disable,
74 .endpoint_reset = ehci_endpoint_reset,
75
76 /*
77 * scheduling support
78 */
79 .get_frame_number = ehci_get_frame,
80
81 /*
82 * root hub support
83 */
84 .hub_status_data = ehci_hub_status_data,
85 .hub_control = ehci_hub_control,
86 .bus_suspend = ehci_bus_suspend,
87 .bus_resume = ehci_bus_resume,
88 .relinquish_port = ehci_relinquish_port,
89 .port_handed_over = ehci_port_handed_over,
90
91 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
92};
93
94static int ehci_hcd_sead3_drv_probe(struct platform_device *pdev)
95{
96 struct usb_hcd *hcd;
97 struct resource *res;
98 int ret;
99
100 if (usb_disabled())
101 return -ENODEV;
102
103 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
104 pr_debug("resource[1] is not IORESOURCE_IRQ");
105 return -ENOMEM;
106 }
107 hcd = usb_create_hcd(&ehci_sead3_hc_driver, &pdev->dev, "SEAD-3");
108 if (!hcd)
109 return -ENOMEM;
110
111 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
112 hcd->rsrc_start = res->start;
113 hcd->rsrc_len = resource_size(res);
114
115 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
116 pr_debug("request_mem_region failed");
117 ret = -EBUSY;
118 goto err1;
119 }
120
121 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
122 if (!hcd->regs) {
123 pr_debug("ioremap failed");
124 ret = -ENOMEM;
125 goto err2;
126 }
127
128 /* Root hub has integrated TT. */
129 hcd->has_tt = 1;
130
131 ret = usb_add_hcd(hcd, pdev->resource[1].start,
132 IRQF_SHARED);
133 if (ret == 0) {
134 platform_set_drvdata(pdev, hcd);
135 return ret;
136 }
137
138 iounmap(hcd->regs);
139err2:
140 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
141err1:
142 usb_put_hcd(hcd);
143 return ret;
144}
145
146static int ehci_hcd_sead3_drv_remove(struct platform_device *pdev)
147{
148 struct usb_hcd *hcd = platform_get_drvdata(pdev);
149
150 usb_remove_hcd(hcd);
151 iounmap(hcd->regs);
152 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
153 usb_put_hcd(hcd);
154 platform_set_drvdata(pdev, NULL);
155
156 return 0;
157}
158
159#ifdef CONFIG_PM
160static int ehci_hcd_sead3_drv_suspend(struct device *dev)
161{
162 struct usb_hcd *hcd = dev_get_drvdata(dev);
163 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
164 unsigned long flags;
165 int rc = 0;
166
167 if (time_before(jiffies, ehci->next_statechange))
168 msleep(20);
169
170 /* Root hub was already suspended. Disable irq emission and
171 * mark HW unaccessible. The PM and USB cores make sure that
172 * the root hub is either suspended or stopped.
173 */
174 ehci_prepare_ports_for_controller_suspend(ehci, device_may_wakeup(dev));
175 spin_lock_irqsave(&ehci->lock, flags);
176 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
177 (void)ehci_readl(ehci, &ehci->regs->intr_enable);
178
179 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
180 spin_unlock_irqrestore(&ehci->lock, flags);
181
182 /* could save FLADJ in case of Vaux power loss
183 * ... we'd only use it to handle clock skew
184 */
185
186 return rc;
187}
188
189static int ehci_hcd_sead3_drv_resume(struct device *dev)
190{
191 struct usb_hcd *hcd = dev_get_drvdata(dev);
192 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
193
194 /* maybe restore FLADJ. */
195
196 if (time_before(jiffies, ehci->next_statechange))
197 msleep(100);
198
199 /* Mark hardware accessible again as we are out of D3 state by now */
200 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
201
202 /* If CF is still set, we maintained PCI Vaux power.
203 * Just undo the effect of ehci_pci_suspend().
204 */
205 if (ehci_readl(ehci, &ehci->regs->configured_flag) == FLAG_CF) {
206 int mask = INTR_MASK;
207
208 ehci_prepare_ports_for_controller_resume(ehci);
209 if (!hcd->self.root_hub->do_remote_wakeup)
210 mask &= ~STS_PCD;
211 ehci_writel(ehci, mask, &ehci->regs->intr_enable);
212 ehci_readl(ehci, &ehci->regs->intr_enable);
213 return 0;
214 }
215
216 ehci_dbg(ehci, "lost power, restarting\n");
217 usb_root_hub_lost_power(hcd->self.root_hub);
218
219 /* Else reset, to cope with power loss or flush-to-storage
220 * style "resume" having let BIOS kick in during reboot.
221 */
222 (void) ehci_halt(ehci);
223 (void) ehci_reset(ehci);
224
225 /* emptying the schedule aborts any urbs */
226 spin_lock_irq(&ehci->lock);
227 if (ehci->reclaim)
228 end_unlink_async(ehci);
229 ehci_work(ehci);
230 spin_unlock_irq(&ehci->lock);
231
232 ehci_writel(ehci, ehci->command, &ehci->regs->command);
233 ehci_writel(ehci, FLAG_CF, &ehci->regs->configured_flag);
234 ehci_readl(ehci, &ehci->regs->command); /* unblock posted writes */
235
236 /* here we "know" root ports should always stay powered */
237 ehci_port_power(ehci, 1);
238
239 ehci->rh_state = EHCI_RH_SUSPENDED;
240
241 return 0;
242}
243
244static const struct dev_pm_ops sead3_ehci_pmops = {
245 .suspend = ehci_hcd_sead3_drv_suspend,
246 .resume = ehci_hcd_sead3_drv_resume,
247};
248
249#define SEAD3_EHCI_PMOPS (&sead3_ehci_pmops)
250
251#else
252#define SEAD3_EHCI_PMOPS NULL
253#endif
254
255static struct platform_driver ehci_hcd_sead3_driver = {
256 .probe = ehci_hcd_sead3_drv_probe,
257 .remove = ehci_hcd_sead3_drv_remove,
258 .shutdown = usb_hcd_platform_shutdown,
259 .driver = {
260 .name = "sead3-ehci",
261 .owner = THIS_MODULE,
262 .pm = SEAD3_EHCI_PMOPS,
263 }
264};
265
266MODULE_ALIAS("platform:sead3-ehci");
diff --git a/drivers/usb/host/ehci-sh.c b/drivers/usb/host/ehci-sh.c
index 9d9cf47d80d..ca819cdd0c5 100644
--- a/drivers/usb/host/ehci-sh.c
+++ b/drivers/usb/host/ehci-sh.c
@@ -11,6 +11,7 @@
11 */ 11 */
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/clk.h> 13#include <linux/clk.h>
14#include <linux/platform_data/ehci-sh.h>
14 15
15struct ehci_sh_priv { 16struct ehci_sh_priv {
16 struct clk *iclk, *fclk; 17 struct clk *iclk, *fclk;
@@ -100,6 +101,7 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev)
100 const struct hc_driver *driver = &ehci_sh_hc_driver; 101 const struct hc_driver *driver = &ehci_sh_hc_driver;
101 struct resource *res; 102 struct resource *res;
102 struct ehci_sh_priv *priv; 103 struct ehci_sh_priv *priv;
104 struct ehci_sh_platdata *pdata;
103 struct usb_hcd *hcd; 105 struct usb_hcd *hcd;
104 int irq, ret; 106 int irq, ret;
105 107
@@ -124,6 +126,9 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev)
124 goto fail_create_hcd; 126 goto fail_create_hcd;
125 } 127 }
126 128
129 if (pdev->dev.platform_data != NULL)
130 pdata = pdev->dev.platform_data;
131
127 /* initialize hcd */ 132 /* initialize hcd */
128 hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev, 133 hcd = usb_create_hcd(&ehci_sh_hc_driver, &pdev->dev,
129 dev_name(&pdev->dev)); 134 dev_name(&pdev->dev));
@@ -168,6 +173,9 @@ static int ehci_hcd_sh_probe(struct platform_device *pdev)
168 clk_enable(priv->fclk); 173 clk_enable(priv->fclk);
169 clk_enable(priv->iclk); 174 clk_enable(priv->iclk);
170 175
176 if (pdata && pdata->phy_init)
177 pdata->phy_init();
178
171 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 179 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
172 if (ret != 0) { 180 if (ret != 0) {
173 dev_err(&pdev->dev, "Failed to add hcd"); 181 dev_err(&pdev->dev, "Failed to add hcd");
diff --git a/drivers/usb/host/ehci-spear.c b/drivers/usb/host/ehci-spear.c
index 6e928559169..37ba8c8d2fd 100644
--- a/drivers/usb/host/ehci-spear.c
+++ b/drivers/usb/host/ehci-spear.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/jiffies.h> 15#include <linux/jiffies.h>
16#include <linux/of.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/pm.h> 18#include <linux/pm.h>
18 19
@@ -25,12 +26,12 @@ struct spear_ehci {
25 26
26static void spear_start_ehci(struct spear_ehci *ehci) 27static void spear_start_ehci(struct spear_ehci *ehci)
27{ 28{
28 clk_enable(ehci->clk); 29 clk_prepare_enable(ehci->clk);
29} 30}
30 31
31static void spear_stop_ehci(struct spear_ehci *ehci) 32static void spear_stop_ehci(struct spear_ehci *ehci)
32{ 33{
33 clk_disable(ehci->clk); 34 clk_disable_unprepare(ehci->clk);
34} 35}
35 36
36static int ehci_spear_setup(struct usb_hcd *hcd) 37static int ehci_spear_setup(struct usb_hcd *hcd)
@@ -168,6 +169,8 @@ static int ehci_spear_drv_resume(struct device *dev)
168static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend, 169static SIMPLE_DEV_PM_OPS(ehci_spear_pm_ops, ehci_spear_drv_suspend,
169 ehci_spear_drv_resume); 170 ehci_spear_drv_resume);
170 171
172static u64 spear_ehci_dma_mask = DMA_BIT_MASK(32);
173
171static int spear_ehci_hcd_drv_probe(struct platform_device *pdev) 174static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
172{ 175{
173 struct usb_hcd *hcd ; 176 struct usb_hcd *hcd ;
@@ -175,12 +178,9 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
175 struct resource *res; 178 struct resource *res;
176 struct clk *usbh_clk; 179 struct clk *usbh_clk;
177 const struct hc_driver *driver = &ehci_spear_hc_driver; 180 const struct hc_driver *driver = &ehci_spear_hc_driver;
178 int *pdata = pdev->dev.platform_data;
179 int irq, retval; 181 int irq, retval;
180 char clk_name[20] = "usbh_clk"; 182 char clk_name[20] = "usbh_clk";
181 183 static int instance = -1;
182 if (pdata == NULL)
183 return -EFAULT;
184 184
185 if (usb_disabled()) 185 if (usb_disabled())
186 return -ENODEV; 186 return -ENODEV;
@@ -191,8 +191,22 @@ static int spear_ehci_hcd_drv_probe(struct platform_device *pdev)
191 goto fail_irq_get; 191 goto fail_irq_get;
192 } 192 }
193 193
194 if (*pdata >= 0) 194 /*
195 sprintf(clk_name, "usbh.%01d_clk", *pdata); 195 * Right now device-tree probed devices don't get dma_mask set.
196 * Since shared usb code relies on it, set it here for now.
197 * Once we have dma capability bindings this can go away.
198 */
199 if (!pdev->dev.dma_mask)
200 pdev->dev.dma_mask = &spear_ehci_dma_mask;
201
202 /*
203 * Increment the device instance, when probing via device-tree
204 */
205 if (pdev->id < 0)
206 instance++;
207 else
208 instance = pdev->id;
209 sprintf(clk_name, "usbh.%01d_clk", instance);
196 210
197 usbh_clk = clk_get(NULL, clk_name); 211 usbh_clk = clk_get(NULL, clk_name);
198 if (IS_ERR(usbh_clk)) { 212 if (IS_ERR(usbh_clk)) {
@@ -277,6 +291,11 @@ static int spear_ehci_hcd_drv_remove(struct platform_device *pdev)
277 return 0; 291 return 0;
278} 292}
279 293
294static struct of_device_id spear_ehci_id_table[] __devinitdata = {
295 { .compatible = "st,spear600-ehci", },
296 { },
297};
298
280static struct platform_driver spear_ehci_hcd_driver = { 299static struct platform_driver spear_ehci_hcd_driver = {
281 .probe = spear_ehci_hcd_drv_probe, 300 .probe = spear_ehci_hcd_drv_probe,
282 .remove = spear_ehci_hcd_drv_remove, 301 .remove = spear_ehci_hcd_drv_remove,
@@ -285,6 +304,7 @@ static struct platform_driver spear_ehci_hcd_driver = {
285 .name = "spear-ehci", 304 .name = "spear-ehci",
286 .bus = &platform_bus_type, 305 .bus = &platform_bus_type,
287 .pm = &ehci_spear_pm_ops, 306 .pm = &ehci_spear_pm_ops,
307 .of_match_table = of_match_ptr(spear_ehci_id_table),
288 } 308 }
289}; 309};
290 310
diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index 73544bd440b..4a44bf83361 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -24,6 +24,7 @@
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/of.h> 25#include <linux/of.h>
26#include <linux/of_gpio.h> 26#include <linux/of_gpio.h>
27#include <linux/pm_runtime.h>
27 28
28#include <mach/usb_phy.h> 29#include <mach/usb_phy.h>
29#include <mach/iomap.h> 30#include <mach/iomap.h>
@@ -37,9 +38,7 @@ struct tegra_ehci_hcd {
37 struct clk *emc_clk; 38 struct clk *emc_clk;
38 struct usb_phy *transceiver; 39 struct usb_phy *transceiver;
39 int host_resumed; 40 int host_resumed;
40 int bus_suspended;
41 int port_resuming; 41 int port_resuming;
42 int power_down_on_bus_suspend;
43 enum tegra_usb_phy_port_speed port_speed; 42 enum tegra_usb_phy_port_speed port_speed;
44}; 43};
45 44
@@ -148,18 +147,7 @@ static int tegra_ehci_hub_control(
148 147
149 spin_lock_irqsave(&ehci->lock, flags); 148 spin_lock_irqsave(&ehci->lock, flags);
150 149
151 /* 150 if (typeReq == GetPortStatus) {
152 * In ehci_hub_control() for USB_PORT_FEAT_ENABLE clears the other bits
153 * that are write on clear, by writing back the register read value, so
154 * USB_PORT_FEAT_ENABLE is handled by masking the set on clear bits
155 */
156 if (typeReq == ClearPortFeature && wValue == USB_PORT_FEAT_ENABLE) {
157 temp = ehci_readl(ehci, status_reg) & ~PORT_RWC_BITS;
158 ehci_writel(ehci, temp & ~PORT_PE, status_reg);
159 goto done;
160 }
161
162 else if (typeReq == GetPortStatus) {
163 temp = ehci_readl(ehci, status_reg); 151 temp = ehci_readl(ehci, status_reg);
164 if (tegra->port_resuming && !(temp & PORT_SUSPEND)) { 152 if (tegra->port_resuming && !(temp & PORT_SUSPEND)) {
165 /* Resume completed, re-enable disconnect detection */ 153 /* Resume completed, re-enable disconnect detection */
@@ -175,7 +163,7 @@ static int tegra_ehci_hub_control(
175 goto done; 163 goto done;
176 } 164 }
177 165
178 temp &= ~PORT_WKCONN_E; 166 temp &= ~(PORT_RWC_BITS | PORT_WKCONN_E);
179 temp |= PORT_WKDISC_E | PORT_WKOC_E; 167 temp |= PORT_WKDISC_E | PORT_WKOC_E;
180 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg); 168 ehci_writel(ehci, temp | PORT_SUSPEND, status_reg);
181 169
@@ -273,120 +261,6 @@ static void tegra_ehci_restart(struct usb_hcd *hcd)
273 up_write(&ehci_cf_port_reset_rwsem); 261 up_write(&ehci_cf_port_reset_rwsem);
274} 262}
275 263
276static int tegra_usb_suspend(struct usb_hcd *hcd)
277{
278 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
279 struct ehci_regs __iomem *hw = tegra->ehci->regs;
280 unsigned long flags;
281
282 spin_lock_irqsave(&tegra->ehci->lock, flags);
283
284 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3;
285 ehci_halt(tegra->ehci);
286 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
287
288 spin_unlock_irqrestore(&tegra->ehci->lock, flags);
289
290 tegra_ehci_power_down(hcd);
291 return 0;
292}
293
294static int tegra_usb_resume(struct usb_hcd *hcd)
295{
296 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
297 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
298 struct ehci_regs __iomem *hw = ehci->regs;
299 unsigned long val;
300
301 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
302 tegra_ehci_power_up(hcd);
303
304 if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) {
305 /* Wait for the phy to detect new devices
306 * before we restart the controller */
307 msleep(10);
308 goto restart;
309 }
310
311 /* Force the phy to keep data lines in suspend state */
312 tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed);
313
314 /* Enable host mode */
315 tdi_reset(ehci);
316
317 /* Enable Port Power */
318 val = readl(&hw->port_status[0]);
319 val |= PORT_POWER;
320 writel(val, &hw->port_status[0]);
321 udelay(10);
322
323 /* Check if the phy resume from LP0. When the phy resume from LP0
324 * USB register will be reset. */
325 if (!readl(&hw->async_next)) {
326 /* Program the field PTC based on the saved speed mode */
327 val = readl(&hw->port_status[0]);
328 val &= ~PORT_TEST(~0);
329 if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH)
330 val |= PORT_TEST_FORCE;
331 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL)
332 val |= PORT_TEST(6);
333 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
334 val |= PORT_TEST(7);
335 writel(val, &hw->port_status[0]);
336 udelay(10);
337
338 /* Disable test mode by setting PTC field to NORMAL_OP */
339 val = readl(&hw->port_status[0]);
340 val &= ~PORT_TEST(~0);
341 writel(val, &hw->port_status[0]);
342 udelay(10);
343 }
344
345 /* Poll until CCS is enabled */
346 if (handshake(ehci, &hw->port_status[0], PORT_CONNECT,
347 PORT_CONNECT, 2000)) {
348 pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__);
349 goto restart;
350 }
351
352 /* Poll until PE is enabled */
353 if (handshake(ehci, &hw->port_status[0], PORT_PE,
354 PORT_PE, 2000)) {
355 pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__);
356 goto restart;
357 }
358
359 /* Clear the PCI status, to avoid an interrupt taken upon resume */
360 val = readl(&hw->status);
361 val |= STS_PCD;
362 writel(val, &hw->status);
363
364 /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */
365 val = readl(&hw->port_status[0]);
366 if ((val & PORT_POWER) && (val & PORT_PE)) {
367 val |= PORT_SUSPEND;
368 writel(val, &hw->port_status[0]);
369
370 /* Wait until port suspend completes */
371 if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND,
372 PORT_SUSPEND, 1000)) {
373 pr_err("%s: timeout waiting for PORT_SUSPEND\n",
374 __func__);
375 goto restart;
376 }
377 }
378
379 tegra_ehci_phy_restore_end(tegra->phy);
380 return 0;
381
382restart:
383 if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH)
384 tegra_ehci_phy_restore_end(tegra->phy);
385
386 tegra_ehci_restart(hcd);
387 return 0;
388}
389
390static void tegra_ehci_shutdown(struct usb_hcd *hcd) 264static void tegra_ehci_shutdown(struct usb_hcd *hcd)
391{ 265{
392 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller); 266 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
@@ -434,56 +308,23 @@ static int tegra_ehci_setup(struct usb_hcd *hcd)
434 return retval; 308 return retval;
435} 309}
436 310
437#ifdef CONFIG_PM 311struct dma_aligned_buffer {
438static int tegra_ehci_bus_suspend(struct usb_hcd *hcd)
439{
440 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
441 int error_status = 0;
442
443 error_status = ehci_bus_suspend(hcd);
444 if (!error_status && tegra->power_down_on_bus_suspend) {
445 tegra_usb_suspend(hcd);
446 tegra->bus_suspended = 1;
447 }
448
449 return error_status;
450}
451
452static int tegra_ehci_bus_resume(struct usb_hcd *hcd)
453{
454 struct tegra_ehci_hcd *tegra = dev_get_drvdata(hcd->self.controller);
455
456 if (tegra->bus_suspended && tegra->power_down_on_bus_suspend) {
457 tegra_usb_resume(hcd);
458 tegra->bus_suspended = 0;
459 }
460
461 tegra_usb_phy_preresume(tegra->phy);
462 tegra->port_resuming = 1;
463 return ehci_bus_resume(hcd);
464}
465#endif
466
467struct temp_buffer {
468 void *kmalloc_ptr; 312 void *kmalloc_ptr;
469 void *old_xfer_buffer; 313 void *old_xfer_buffer;
470 u8 data[0]; 314 u8 data[0];
471}; 315};
472 316
473static void free_temp_buffer(struct urb *urb) 317static void free_dma_aligned_buffer(struct urb *urb)
474{ 318{
475 enum dma_data_direction dir; 319 struct dma_aligned_buffer *temp;
476 struct temp_buffer *temp;
477 320
478 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER)) 321 if (!(urb->transfer_flags & URB_ALIGNED_TEMP_BUFFER))
479 return; 322 return;
480 323
481 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE; 324 temp = container_of(urb->transfer_buffer,
325 struct dma_aligned_buffer, data);
482 326
483 temp = container_of(urb->transfer_buffer, struct temp_buffer, 327 if (usb_urb_dir_in(urb))
484 data);
485
486 if (dir == DMA_FROM_DEVICE)
487 memcpy(temp->old_xfer_buffer, temp->data, 328 memcpy(temp->old_xfer_buffer, temp->data,
488 urb->transfer_buffer_length); 329 urb->transfer_buffer_length);
489 urb->transfer_buffer = temp->old_xfer_buffer; 330 urb->transfer_buffer = temp->old_xfer_buffer;
@@ -492,10 +333,9 @@ static void free_temp_buffer(struct urb *urb)
492 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER; 333 urb->transfer_flags &= ~URB_ALIGNED_TEMP_BUFFER;
493} 334}
494 335
495static int alloc_temp_buffer(struct urb *urb, gfp_t mem_flags) 336static int alloc_dma_aligned_buffer(struct urb *urb, gfp_t mem_flags)
496{ 337{
497 enum dma_data_direction dir; 338 struct dma_aligned_buffer *temp, *kmalloc_ptr;
498 struct temp_buffer *temp, *kmalloc_ptr;
499 size_t kmalloc_size; 339 size_t kmalloc_size;
500 340
501 if (urb->num_sgs || urb->sg || 341 if (urb->num_sgs || urb->sg ||
@@ -503,22 +343,19 @@ static int alloc_temp_buffer(struct urb *urb, gfp_t mem_flags)
503 !((uintptr_t)urb->transfer_buffer & (TEGRA_USB_DMA_ALIGN - 1))) 343 !((uintptr_t)urb->transfer_buffer & (TEGRA_USB_DMA_ALIGN - 1)))
504 return 0; 344 return 0;
505 345
506 dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
507
508 /* Allocate a buffer with enough padding for alignment */ 346 /* Allocate a buffer with enough padding for alignment */
509 kmalloc_size = urb->transfer_buffer_length + 347 kmalloc_size = urb->transfer_buffer_length +
510 sizeof(struct temp_buffer) + TEGRA_USB_DMA_ALIGN - 1; 348 sizeof(struct dma_aligned_buffer) + TEGRA_USB_DMA_ALIGN - 1;
511 349
512 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags); 350 kmalloc_ptr = kmalloc(kmalloc_size, mem_flags);
513 if (!kmalloc_ptr) 351 if (!kmalloc_ptr)
514 return -ENOMEM; 352 return -ENOMEM;
515 353
516 /* Position our struct temp_buffer such that data is aligned */ 354 /* Position our struct dma_aligned_buffer such that data is aligned */
517 temp = PTR_ALIGN(kmalloc_ptr + 1, TEGRA_USB_DMA_ALIGN) - 1; 355 temp = PTR_ALIGN(kmalloc_ptr + 1, TEGRA_USB_DMA_ALIGN) - 1;
518
519 temp->kmalloc_ptr = kmalloc_ptr; 356 temp->kmalloc_ptr = kmalloc_ptr;
520 temp->old_xfer_buffer = urb->transfer_buffer; 357 temp->old_xfer_buffer = urb->transfer_buffer;
521 if (dir == DMA_TO_DEVICE) 358 if (usb_urb_dir_out(urb))
522 memcpy(temp->data, urb->transfer_buffer, 359 memcpy(temp->data, urb->transfer_buffer,
523 urb->transfer_buffer_length); 360 urb->transfer_buffer_length);
524 urb->transfer_buffer = temp->data; 361 urb->transfer_buffer = temp->data;
@@ -533,13 +370,13 @@ static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
533{ 370{
534 int ret; 371 int ret;
535 372
536 ret = alloc_temp_buffer(urb, mem_flags); 373 ret = alloc_dma_aligned_buffer(urb, mem_flags);
537 if (ret) 374 if (ret)
538 return ret; 375 return ret;
539 376
540 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags); 377 ret = usb_hcd_map_urb_for_dma(hcd, urb, mem_flags);
541 if (ret) 378 if (ret)
542 free_temp_buffer(urb); 379 free_dma_aligned_buffer(urb);
543 380
544 return ret; 381 return ret;
545} 382}
@@ -547,49 +384,51 @@ static int tegra_ehci_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
547static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) 384static void tegra_ehci_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
548{ 385{
549 usb_hcd_unmap_urb_for_dma(hcd, urb); 386 usb_hcd_unmap_urb_for_dma(hcd, urb);
550 free_temp_buffer(urb); 387 free_dma_aligned_buffer(urb);
551} 388}
552 389
553static const struct hc_driver tegra_ehci_hc_driver = { 390static const struct hc_driver tegra_ehci_hc_driver = {
554 .description = hcd_name, 391 .description = hcd_name,
555 .product_desc = "Tegra EHCI Host Controller", 392 .product_desc = "Tegra EHCI Host Controller",
556 .hcd_priv_size = sizeof(struct ehci_hcd), 393 .hcd_priv_size = sizeof(struct ehci_hcd),
557
558 .flags = HCD_USB2 | HCD_MEMORY, 394 .flags = HCD_USB2 | HCD_MEMORY,
559 395
560 .reset = tegra_ehci_setup, 396 /* standard ehci functions */
561 .irq = ehci_irq, 397 .irq = ehci_irq,
562
563 .start = ehci_run, 398 .start = ehci_run,
564 .stop = ehci_stop, 399 .stop = ehci_stop,
565 .shutdown = tegra_ehci_shutdown,
566 .urb_enqueue = ehci_urb_enqueue, 400 .urb_enqueue = ehci_urb_enqueue,
567 .urb_dequeue = ehci_urb_dequeue, 401 .urb_dequeue = ehci_urb_dequeue,
568 .map_urb_for_dma = tegra_ehci_map_urb_for_dma,
569 .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma,
570 .endpoint_disable = ehci_endpoint_disable, 402 .endpoint_disable = ehci_endpoint_disable,
571 .endpoint_reset = ehci_endpoint_reset, 403 .endpoint_reset = ehci_endpoint_reset,
572 .get_frame_number = ehci_get_frame, 404 .get_frame_number = ehci_get_frame,
573 .hub_status_data = ehci_hub_status_data, 405 .hub_status_data = ehci_hub_status_data,
574 .hub_control = tegra_ehci_hub_control,
575 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, 406 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
576#ifdef CONFIG_PM
577 .bus_suspend = tegra_ehci_bus_suspend,
578 .bus_resume = tegra_ehci_bus_resume,
579#endif
580 .relinquish_port = ehci_relinquish_port, 407 .relinquish_port = ehci_relinquish_port,
581 .port_handed_over = ehci_port_handed_over, 408 .port_handed_over = ehci_port_handed_over,
409
410 /* modified ehci functions for tegra */
411 .reset = tegra_ehci_setup,
412 .shutdown = tegra_ehci_shutdown,
413 .map_urb_for_dma = tegra_ehci_map_urb_for_dma,
414 .unmap_urb_for_dma = tegra_ehci_unmap_urb_for_dma,
415 .hub_control = tegra_ehci_hub_control,
416#ifdef CONFIG_PM
417 .bus_suspend = ehci_bus_suspend,
418 .bus_resume = ehci_bus_resume,
419#endif
582}; 420};
583 421
584static int setup_vbus_gpio(struct platform_device *pdev) 422static int setup_vbus_gpio(struct platform_device *pdev,
423 struct tegra_ehci_platform_data *pdata)
585{ 424{
586 int err = 0; 425 int err = 0;
587 int gpio; 426 int gpio;
588 427
589 if (!pdev->dev.of_node) 428 gpio = pdata->vbus_gpio;
590 return 0; 429 if (!gpio_is_valid(gpio))
591 430 gpio = of_get_named_gpio(pdev->dev.of_node,
592 gpio = of_get_named_gpio(pdev->dev.of_node, "nvidia,vbus-gpio", 0); 431 "nvidia,vbus-gpio", 0);
593 if (!gpio_is_valid(gpio)) 432 if (!gpio_is_valid(gpio))
594 return 0; 433 return 0;
595 434
@@ -603,11 +442,187 @@ static int setup_vbus_gpio(struct platform_device *pdev)
603 dev_err(&pdev->dev, "can't enable vbus\n"); 442 dev_err(&pdev->dev, "can't enable vbus\n");
604 return err; 443 return err;
605 } 444 }
606 gpio_set_value(gpio, 1);
607 445
608 return err; 446 return err;
609} 447}
610 448
449#ifdef CONFIG_PM
450
451static int controller_suspend(struct device *dev)
452{
453 struct tegra_ehci_hcd *tegra =
454 platform_get_drvdata(to_platform_device(dev));
455 struct ehci_hcd *ehci = tegra->ehci;
456 struct usb_hcd *hcd = ehci_to_hcd(ehci);
457 struct ehci_regs __iomem *hw = ehci->regs;
458 unsigned long flags;
459
460 if (time_before(jiffies, ehci->next_statechange))
461 msleep(10);
462
463 spin_lock_irqsave(&ehci->lock, flags);
464
465 tegra->port_speed = (readl(&hw->port_status[0]) >> 26) & 0x3;
466 ehci_halt(ehci);
467 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
468
469 spin_unlock_irqrestore(&ehci->lock, flags);
470
471 tegra_ehci_power_down(hcd);
472 return 0;
473}
474
475static int controller_resume(struct device *dev)
476{
477 struct tegra_ehci_hcd *tegra =
478 platform_get_drvdata(to_platform_device(dev));
479 struct ehci_hcd *ehci = tegra->ehci;
480 struct usb_hcd *hcd = ehci_to_hcd(ehci);
481 struct ehci_regs __iomem *hw = ehci->regs;
482 unsigned long val;
483
484 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
485 tegra_ehci_power_up(hcd);
486
487 if (tegra->port_speed > TEGRA_USB_PHY_PORT_SPEED_HIGH) {
488 /* Wait for the phy to detect new devices
489 * before we restart the controller */
490 msleep(10);
491 goto restart;
492 }
493
494 /* Force the phy to keep data lines in suspend state */
495 tegra_ehci_phy_restore_start(tegra->phy, tegra->port_speed);
496
497 /* Enable host mode */
498 tdi_reset(ehci);
499
500 /* Enable Port Power */
501 val = readl(&hw->port_status[0]);
502 val |= PORT_POWER;
503 writel(val, &hw->port_status[0]);
504 udelay(10);
505
506 /* Check if the phy resume from LP0. When the phy resume from LP0
507 * USB register will be reset. */
508 if (!readl(&hw->async_next)) {
509 /* Program the field PTC based on the saved speed mode */
510 val = readl(&hw->port_status[0]);
511 val &= ~PORT_TEST(~0);
512 if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_HIGH)
513 val |= PORT_TEST_FORCE;
514 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_FULL)
515 val |= PORT_TEST(6);
516 else if (tegra->port_speed == TEGRA_USB_PHY_PORT_SPEED_LOW)
517 val |= PORT_TEST(7);
518 writel(val, &hw->port_status[0]);
519 udelay(10);
520
521 /* Disable test mode by setting PTC field to NORMAL_OP */
522 val = readl(&hw->port_status[0]);
523 val &= ~PORT_TEST(~0);
524 writel(val, &hw->port_status[0]);
525 udelay(10);
526 }
527
528 /* Poll until CCS is enabled */
529 if (handshake(ehci, &hw->port_status[0], PORT_CONNECT,
530 PORT_CONNECT, 2000)) {
531 pr_err("%s: timeout waiting for PORT_CONNECT\n", __func__);
532 goto restart;
533 }
534
535 /* Poll until PE is enabled */
536 if (handshake(ehci, &hw->port_status[0], PORT_PE,
537 PORT_PE, 2000)) {
538 pr_err("%s: timeout waiting for USB_PORTSC1_PE\n", __func__);
539 goto restart;
540 }
541
542 /* Clear the PCI status, to avoid an interrupt taken upon resume */
543 val = readl(&hw->status);
544 val |= STS_PCD;
545 writel(val, &hw->status);
546
547 /* Put controller in suspend mode by writing 1 to SUSP bit of PORTSC */
548 val = readl(&hw->port_status[0]);
549 if ((val & PORT_POWER) && (val & PORT_PE)) {
550 val |= PORT_SUSPEND;
551 writel(val, &hw->port_status[0]);
552
553 /* Wait until port suspend completes */
554 if (handshake(ehci, &hw->port_status[0], PORT_SUSPEND,
555 PORT_SUSPEND, 1000)) {
556 pr_err("%s: timeout waiting for PORT_SUSPEND\n",
557 __func__);
558 goto restart;
559 }
560 }
561
562 tegra_ehci_phy_restore_end(tegra->phy);
563 goto done;
564
565 restart:
566 if (tegra->port_speed <= TEGRA_USB_PHY_PORT_SPEED_HIGH)
567 tegra_ehci_phy_restore_end(tegra->phy);
568
569 tegra_ehci_restart(hcd);
570
571 done:
572 tegra_usb_phy_preresume(tegra->phy);
573 tegra->port_resuming = 1;
574 return 0;
575}
576
577static int tegra_ehci_suspend(struct device *dev)
578{
579 struct tegra_ehci_hcd *tegra =
580 platform_get_drvdata(to_platform_device(dev));
581 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
582 int rc = 0;
583
584 /*
585 * When system sleep is supported and USB controller wakeup is
586 * implemented: If the controller is runtime-suspended and the
587 * wakeup setting needs to be changed, call pm_runtime_resume().
588 */
589 if (HCD_HW_ACCESSIBLE(hcd))
590 rc = controller_suspend(dev);
591 return rc;
592}
593
594static int tegra_ehci_resume(struct device *dev)
595{
596 int rc;
597
598 rc = controller_resume(dev);
599 if (rc == 0) {
600 pm_runtime_disable(dev);
601 pm_runtime_set_active(dev);
602 pm_runtime_enable(dev);
603 }
604 return rc;
605}
606
607static int tegra_ehci_runtime_suspend(struct device *dev)
608{
609 return controller_suspend(dev);
610}
611
612static int tegra_ehci_runtime_resume(struct device *dev)
613{
614 return controller_resume(dev);
615}
616
617static const struct dev_pm_ops tegra_ehci_pm_ops = {
618 .suspend = tegra_ehci_suspend,
619 .resume = tegra_ehci_resume,
620 .runtime_suspend = tegra_ehci_runtime_suspend,
621 .runtime_resume = tegra_ehci_runtime_resume,
622};
623
624#endif
625
611static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32); 626static u64 tegra_ehci_dma_mask = DMA_BIT_MASK(32);
612 627
613static int tegra_ehci_probe(struct platform_device *pdev) 628static int tegra_ehci_probe(struct platform_device *pdev)
@@ -633,7 +648,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
633 if (!pdev->dev.dma_mask) 648 if (!pdev->dev.dma_mask)
634 pdev->dev.dma_mask = &tegra_ehci_dma_mask; 649 pdev->dev.dma_mask = &tegra_ehci_dma_mask;
635 650
636 setup_vbus_gpio(pdev); 651 setup_vbus_gpio(pdev, pdata);
637 652
638 tegra = kzalloc(sizeof(struct tegra_ehci_hcd), GFP_KERNEL); 653 tegra = kzalloc(sizeof(struct tegra_ehci_hcd), GFP_KERNEL);
639 if (!tegra) 654 if (!tegra)
@@ -722,7 +737,6 @@ static int tegra_ehci_probe(struct platform_device *pdev)
722 } 737 }
723 738
724 tegra->host_resumed = 1; 739 tegra->host_resumed = 1;
725 tegra->power_down_on_bus_suspend = pdata->power_down_on_bus_suspend;
726 tegra->ehci = hcd_to_ehci(hcd); 740 tegra->ehci = hcd_to_ehci(hcd);
727 741
728 irq = platform_get_irq(pdev, 0); 742 irq = platform_get_irq(pdev, 0);
@@ -731,7 +745,6 @@ static int tegra_ehci_probe(struct platform_device *pdev)
731 err = -ENODEV; 745 err = -ENODEV;
732 goto fail; 746 goto fail;
733 } 747 }
734 set_irq_flags(irq, IRQF_VALID);
735 748
736#ifdef CONFIG_USB_OTG_UTILS 749#ifdef CONFIG_USB_OTG_UTILS
737 if (pdata->operating_mode == TEGRA_USB_OTG) { 750 if (pdata->operating_mode == TEGRA_USB_OTG) {
@@ -747,6 +760,14 @@ static int tegra_ehci_probe(struct platform_device *pdev)
747 goto fail; 760 goto fail;
748 } 761 }
749 762
763 pm_runtime_set_active(&pdev->dev);
764 pm_runtime_get_noresume(&pdev->dev);
765
766 /* Don't skip the pm_runtime_forbid call if wakeup isn't working */
767 /* if (!pdata->power_down_on_bus_suspend) */
768 pm_runtime_forbid(&pdev->dev);
769 pm_runtime_enable(&pdev->dev);
770 pm_runtime_put_sync(&pdev->dev);
750 return err; 771 return err;
751 772
752fail: 773fail:
@@ -773,33 +794,6 @@ fail_hcd:
773 return err; 794 return err;
774} 795}
775 796
776#ifdef CONFIG_PM
777static int tegra_ehci_resume(struct platform_device *pdev)
778{
779 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
780 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
781
782 if (tegra->bus_suspended)
783 return 0;
784
785 return tegra_usb_resume(hcd);
786}
787
788static int tegra_ehci_suspend(struct platform_device *pdev, pm_message_t state)
789{
790 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
791 struct usb_hcd *hcd = ehci_to_hcd(tegra->ehci);
792
793 if (tegra->bus_suspended)
794 return 0;
795
796 if (time_before(jiffies, tegra->ehci->next_statechange))
797 msleep(10);
798
799 return tegra_usb_suspend(hcd);
800}
801#endif
802
803static int tegra_ehci_remove(struct platform_device *pdev) 797static int tegra_ehci_remove(struct platform_device *pdev)
804{ 798{
805 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev); 799 struct tegra_ehci_hcd *tegra = platform_get_drvdata(pdev);
@@ -808,6 +802,10 @@ static int tegra_ehci_remove(struct platform_device *pdev)
808 if (tegra == NULL || hcd == NULL) 802 if (tegra == NULL || hcd == NULL)
809 return -EINVAL; 803 return -EINVAL;
810 804
805 pm_runtime_get_sync(&pdev->dev);
806 pm_runtime_disable(&pdev->dev);
807 pm_runtime_put_noidle(&pdev->dev);
808
811#ifdef CONFIG_USB_OTG_UTILS 809#ifdef CONFIG_USB_OTG_UTILS
812 if (tegra->transceiver) { 810 if (tegra->transceiver) {
813 otg_set_host(tegra->transceiver->otg, NULL); 811 otg_set_host(tegra->transceiver->otg, NULL);
@@ -848,13 +846,12 @@ static struct of_device_id tegra_ehci_of_match[] __devinitdata = {
848static struct platform_driver tegra_ehci_driver = { 846static struct platform_driver tegra_ehci_driver = {
849 .probe = tegra_ehci_probe, 847 .probe = tegra_ehci_probe,
850 .remove = tegra_ehci_remove, 848 .remove = tegra_ehci_remove,
851#ifdef CONFIG_PM
852 .suspend = tegra_ehci_suspend,
853 .resume = tegra_ehci_resume,
854#endif
855 .shutdown = tegra_ehci_hcd_shutdown, 849 .shutdown = tegra_ehci_hcd_shutdown,
856 .driver = { 850 .driver = {
857 .name = "tegra-ehci", 851 .name = "tegra-ehci",
858 .of_match_table = tegra_ehci_of_match, 852 .of_match_table = tegra_ehci_of_match,
853#ifdef CONFIG_PM
854 .pm = &tegra_ehci_pm_ops,
855#endif
859 } 856 }
860}; 857};
diff --git a/drivers/usb/host/fhci-tds.c b/drivers/usb/host/fhci-tds.c
index 0ea577bfca2..c5ed8819929 100644
--- a/drivers/usb/host/fhci-tds.c
+++ b/drivers/usb/host/fhci-tds.c
@@ -155,7 +155,7 @@ u32 fhci_create_ep(struct fhci_usb *usb, enum fhci_mem_alloc data_mem,
155 struct endpoint *ep; 155 struct endpoint *ep;
156 struct usb_td __iomem *td; 156 struct usb_td __iomem *td;
157 unsigned long ep_offset; 157 unsigned long ep_offset;
158 char *err_for = "enpoint PRAM"; 158 char *err_for = "endpoint PRAM";
159 int ep_mem_size; 159 int ep_mem_size;
160 u32 i; 160 u32 i;
161 161
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index ab333ac6071..22ff6b3a676 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -119,6 +119,39 @@ error:
119 119
120static const struct of_device_id fsl_usb2_mph_dr_of_match[]; 120static const struct of_device_id fsl_usb2_mph_dr_of_match[];
121 121
122static int usb_get_ver_info(struct device_node *np)
123{
124 int ver = -1;
125
126 /*
127 * returns 1 for usb controller version 1.6
128 * returns 2 for usb controller version 2.2
129 * returns 0 otherwise
130 */
131 if (of_device_is_compatible(np, "fsl-usb2-dr")) {
132 if (of_device_is_compatible(np, "fsl-usb2-dr-v1.6"))
133 ver = FSL_USB_VER_1_6;
134 else if (of_device_is_compatible(np, "fsl-usb2-dr-v2.2"))
135 ver = FSL_USB_VER_2_2;
136 else /* for previous controller versions */
137 ver = FSL_USB_VER_OLD;
138
139 if (ver > -1)
140 return ver;
141 }
142
143 if (of_device_is_compatible(np, "fsl-usb2-mph")) {
144 if (of_device_is_compatible(np, "fsl-usb2-mph-v1.6"))
145 ver = FSL_USB_VER_1_6;
146 else if (of_device_is_compatible(np, "fsl-usb2-mph-v2.2"))
147 ver = FSL_USB_VER_2_2;
148 else /* for previous controller versions */
149 ver = FSL_USB_VER_OLD;
150 }
151
152 return ver;
153}
154
122static int __devinit fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev) 155static int __devinit fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev)
123{ 156{
124 struct device_node *np = ofdev->dev.of_node; 157 struct device_node *np = ofdev->dev.of_node;
@@ -166,6 +199,14 @@ static int __devinit fsl_usb2_mph_dr_of_probe(struct platform_device *ofdev)
166 199
167 prop = of_get_property(np, "phy_type", NULL); 200 prop = of_get_property(np, "phy_type", NULL);
168 pdata->phy_mode = determine_usb_phy(prop); 201 pdata->phy_mode = determine_usb_phy(prop);
202 pdata->controller_ver = usb_get_ver_info(np);
203
204 if (pdata->have_sysif_regs) {
205 if (pdata->controller_ver < 0) {
206 dev_warn(&ofdev->dev, "Could not get controller version\n");
207 return -ENODEV;
208 }
209 }
169 210
170 for (i = 0; i < ARRAY_SIZE(dev_data->drivers); i++) { 211 for (i = 0; i < ARRAY_SIZE(dev_data->drivers); i++) {
171 if (!dev_data->drivers[i]) 212 if (!dev_data->drivers[i])
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index fc72d44bf78..a35bbddf896 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -1562,11 +1562,14 @@ static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1562 1562
1563 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { 1563 if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
1564 retval = -ESHUTDOWN; 1564 retval = -ESHUTDOWN;
1565 qtd_list_free(&new_qtds);
1565 goto out; 1566 goto out;
1566 } 1567 }
1567 retval = usb_hcd_link_urb_to_ep(hcd, urb); 1568 retval = usb_hcd_link_urb_to_ep(hcd, urb);
1568 if (retval) 1569 if (retval) {
1570 qtd_list_free(&new_qtds);
1569 goto out; 1571 goto out;
1572 }
1570 1573
1571 qh = urb->ep->hcpriv; 1574 qh = urb->ep->hcpriv;
1572 if (qh) { 1575 if (qh) {
@@ -1584,6 +1587,7 @@ static int isp1760_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1584 if (!qh) { 1587 if (!qh) {
1585 retval = -ENOMEM; 1588 retval = -ENOMEM;
1586 usb_hcd_unlink_urb_from_ep(hcd, urb); 1589 usb_hcd_unlink_urb_from_ep(hcd, urb);
1590 qtd_list_free(&new_qtds);
1587 goto out; 1591 goto out;
1588 } 1592 }
1589 list_add_tail(&qh->qh_list, ep_queue); 1593 list_add_tail(&qh->qh_list, ep_queue);
@@ -1683,6 +1687,7 @@ static int isp1760_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1683 list_for_each_entry(qtd, &qh->qtd_list, qtd_list) 1687 list_for_each_entry(qtd, &qh->qtd_list, qtd_list)
1684 if (qtd->urb == urb) { 1688 if (qtd->urb == urb) {
1685 dequeue_urb_from_qtd(hcd, qh, qtd); 1689 dequeue_urb_from_qtd(hcd, qh, qtd);
1690 list_move(&qtd->qtd_list, &qh->qtd_list);
1686 break; 1691 break;
1687 } 1692 }
1688 1693
@@ -2176,7 +2181,7 @@ static const struct hc_driver isp1760_hc_driver = {
2176 2181
2177int __init init_kmem_once(void) 2182int __init init_kmem_once(void)
2178{ 2183{
2179 urb_listitem_cachep = kmem_cache_create("isp1760 urb_listitem", 2184 urb_listitem_cachep = kmem_cache_create("isp1760_urb_listitem",
2180 sizeof(struct urb_listitem), 0, SLAB_TEMPORARY | 2185 sizeof(struct urb_listitem), 0, SLAB_TEMPORARY |
2181 SLAB_MEM_SPREAD, NULL); 2186 SLAB_MEM_SPREAD, NULL);
2182 2187
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 4592dc17a9f..fff114fd546 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -398,6 +398,9 @@ static int __devinit isp1760_plat_probe(struct platform_device *pdev)
398 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, 398 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start,
399 irqflags, -ENOENT, 399 irqflags, -ENOENT,
400 &pdev->dev, dev_name(&pdev->dev), devflags); 400 &pdev->dev, dev_name(&pdev->dev), devflags);
401
402 dev_set_drvdata(&pdev->dev, hcd);
403
401 if (IS_ERR(hcd)) { 404 if (IS_ERR(hcd)) {
402 pr_warning("isp1760: Failed to register the HCD device\n"); 405 pr_warning("isp1760: Failed to register the HCD device\n");
403 ret = -ENODEV; 406 ret = -ENODEV;
@@ -417,11 +420,16 @@ static int __devexit isp1760_plat_remove(struct platform_device *pdev)
417{ 420{
418 struct resource *mem_res; 421 struct resource *mem_res;
419 resource_size_t mem_size; 422 resource_size_t mem_size;
423 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
424
425 usb_remove_hcd(hcd);
420 426
421 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 427 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
422 mem_size = resource_size(mem_res); 428 mem_size = resource_size(mem_res);
423 release_mem_region(mem_res->start, mem_size); 429 release_mem_region(mem_res->start, mem_size);
424 430
431 usb_put_hcd(hcd);
432
425 return 0; 433 return 0;
426} 434}
427 435
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 09f597ad6e0..a665b3eaa74 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -94,7 +94,7 @@ static void at91_stop_hc(struct platform_device *pdev)
94 94
95/*-------------------------------------------------------------------------*/ 95/*-------------------------------------------------------------------------*/
96 96
97static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *); 97static void __devexit usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
98 98
99/* configure so an HC device and id are always provided */ 99/* configure so an HC device and id are always provided */
100/* always called with process context; sleeping is OK */ 100/* always called with process context; sleeping is OK */
@@ -108,7 +108,7 @@ static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
108 * then invokes the start() method for the HCD associated with it 108 * then invokes the start() method for the HCD associated with it
109 * through the hotplug entry's driver_data. 109 * through the hotplug entry's driver_data.
110 */ 110 */
111static int usb_hcd_at91_probe(const struct hc_driver *driver, 111static int __devinit usb_hcd_at91_probe(const struct hc_driver *driver,
112 struct platform_device *pdev) 112 struct platform_device *pdev)
113{ 113{
114 int retval; 114 int retval;
@@ -129,7 +129,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
129 if (!hcd) 129 if (!hcd)
130 return -ENOMEM; 130 return -ENOMEM;
131 hcd->rsrc_start = pdev->resource[0].start; 131 hcd->rsrc_start = pdev->resource[0].start;
132 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; 132 hcd->rsrc_len = resource_size(&pdev->resource[0]);
133 133
134 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 134 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
135 pr_debug("request_mem_region failed\n"); 135 pr_debug("request_mem_region failed\n");
@@ -203,7 +203,7 @@ static int usb_hcd_at91_probe(const struct hc_driver *driver,
203 * context, "rmmod" or something similar. 203 * context, "rmmod" or something similar.
204 * 204 *
205 */ 205 */
206static void usb_hcd_at91_remove(struct usb_hcd *hcd, 206static void __devexit usb_hcd_at91_remove(struct usb_hcd *hcd,
207 struct platform_device *pdev) 207 struct platform_device *pdev)
208{ 208{
209 usb_remove_hcd(hcd); 209 usb_remove_hcd(hcd);
@@ -223,7 +223,7 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
223/*-------------------------------------------------------------------------*/ 223/*-------------------------------------------------------------------------*/
224 224
225static int __devinit 225static int __devinit
226ohci_at91_start (struct usb_hcd *hcd) 226ohci_at91_reset (struct usb_hcd *hcd)
227{ 227{
228 struct at91_usbh_data *board = hcd->self.controller->platform_data; 228 struct at91_usbh_data *board = hcd->self.controller->platform_data;
229 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 229 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
@@ -233,9 +233,18 @@ ohci_at91_start (struct usb_hcd *hcd)
233 return ret; 233 return ret;
234 234
235 ohci->num_ports = board->ports; 235 ohci->num_ports = board->ports;
236 return 0;
237}
238
239static int __devinit
240ohci_at91_start (struct usb_hcd *hcd)
241{
242 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
243 int ret;
236 244
237 if ((ret = ohci_run(ohci)) < 0) { 245 if ((ret = ohci_run(ohci)) < 0) {
238 err("can't start %s", hcd->self.bus_name); 246 dev_err(hcd->self.controller, "can't start %s\n",
247 hcd->self.bus_name);
239 ohci_stop(hcd); 248 ohci_stop(hcd);
240 return ret; 249 return ret;
241 } 250 }
@@ -418,6 +427,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
418 /* 427 /*
419 * basic lifecycle operations 428 * basic lifecycle operations
420 */ 429 */
430 .reset = ohci_at91_reset,
421 .start = ohci_at91_start, 431 .start = ohci_at91_start,
422 .stop = ohci_stop, 432 .stop = ohci_stop,
423 .shutdown = ohci_shutdown, 433 .shutdown = ohci_shutdown,
@@ -545,7 +555,7 @@ static int __devinit ohci_at91_of_init(struct platform_device *pdev)
545 555
546/*-------------------------------------------------------------------------*/ 556/*-------------------------------------------------------------------------*/
547 557
548static int ohci_hcd_at91_drv_probe(struct platform_device *pdev) 558static int __devinit ohci_hcd_at91_drv_probe(struct platform_device *pdev)
549{ 559{
550 struct at91_usbh_data *pdata; 560 struct at91_usbh_data *pdata;
551 int i; 561 int i;
@@ -620,7 +630,7 @@ static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
620 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev); 630 return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
621} 631}
622 632
623static int ohci_hcd_at91_drv_remove(struct platform_device *pdev) 633static int __devexit ohci_hcd_at91_drv_remove(struct platform_device *pdev)
624{ 634{
625 struct at91_usbh_data *pdata = pdev->dev.platform_data; 635 struct at91_usbh_data *pdata = pdev->dev.platform_data;
626 int i; 636 int i;
@@ -696,7 +706,7 @@ MODULE_ALIAS("platform:at91_ohci");
696 706
697static struct platform_driver ohci_hcd_at91_driver = { 707static struct platform_driver ohci_hcd_at91_driver = {
698 .probe = ohci_hcd_at91_drv_probe, 708 .probe = ohci_hcd_at91_drv_probe,
699 .remove = ohci_hcd_at91_drv_remove, 709 .remove = __devexit_p(ohci_hcd_at91_drv_remove),
700 .shutdown = usb_hcd_platform_shutdown, 710 .shutdown = usb_hcd_platform_shutdown,
701 .suspend = ohci_hcd_at91_drv_suspend, 711 .suspend = ohci_hcd_at91_drv_suspend,
702 .resume = ohci_hcd_at91_drv_resume, 712 .resume = ohci_hcd_at91_drv_resume,
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 4ea63b2cac4..c611699b4aa 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -37,7 +37,8 @@ static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
37 return ret; 37 return ret;
38 38
39 if ((ret = ohci_run(ohci)) < 0) { 39 if ((ret = ohci_run(ohci)) < 0) {
40 err ("can't start %s", hcd->self.bus_name); 40 dev_err(hcd->self.controller, "can't start %s",
41 hcd->self.bus_name);
41 ohci_stop(hcd); 42 ohci_stop(hcd);
42 return ret; 43 return ret;
43 } 44 }
diff --git a/drivers/usb/host/ohci-cns3xxx.c b/drivers/usb/host/ohci-cns3xxx.c
index 5a00a1e1c6c..2c9f233047b 100644
--- a/drivers/usb/host/ohci-cns3xxx.c
+++ b/drivers/usb/host/ohci-cns3xxx.c
@@ -41,7 +41,8 @@ cns3xxx_ohci_start(struct usb_hcd *hcd)
41 41
42 ret = ohci_run(ohci); 42 ret = ohci_run(ohci);
43 if (ret < 0) { 43 if (ret < 0) {
44 err("can't start %s", hcd->self.bus_name); 44 dev_err(hcd->self.controller, "can't start %s\n",
45 hcd->self.bus_name);
45 ohci_stop(hcd); 46 ohci_stop(hcd);
46 return ret; 47 return ret;
47 } 48 }
diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 843509778a3..269b1e0f769 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -454,3 +454,5 @@ static struct platform_driver ohci_hcd_da8xx_driver = {
454 .name = "ohci", 454 .name = "ohci",
455 }, 455 },
456}; 456};
457
458MODULE_ALIAS("platform:ohci");
diff --git a/drivers/usb/host/ohci-dbg.c b/drivers/usb/host/ohci-dbg.c
index e4bcb62b930..31b81f9eacd 100644
--- a/drivers/usb/host/ohci-dbg.c
+++ b/drivers/usb/host/ohci-dbg.c
@@ -29,14 +29,14 @@ urb_print(struct urb * urb, char * str, int small, int status)
29 unsigned int pipe= urb->pipe; 29 unsigned int pipe= urb->pipe;
30 30
31 if (!urb->dev || !urb->dev->bus) { 31 if (!urb->dev || !urb->dev->bus) {
32 dbg("%s URB: no dev", str); 32 printk(KERN_DEBUG "%s URB: no dev\n", str);
33 return; 33 return;
34 } 34 }
35 35
36#ifndef OHCI_VERBOSE_DEBUG 36#ifndef OHCI_VERBOSE_DEBUG
37 if (status != 0) 37 if (status != 0)
38#endif 38#endif
39 dbg("%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d", 39 printk(KERN_DEBUG "%s %p dev=%d ep=%d%s-%s flags=%x len=%d/%d stat=%d\n",
40 str, 40 str,
41 urb, 41 urb,
42 usb_pipedevice (pipe), 42 usb_pipedevice (pipe),
diff --git a/drivers/usb/host/ohci-ep93xx.c b/drivers/usb/host/ohci-ep93xx.c
index 3d63574d2c7..dbfbd1dfd2e 100644
--- a/drivers/usb/host/ohci-ep93xx.c
+++ b/drivers/usb/host/ohci-ep93xx.c
@@ -47,7 +47,7 @@ static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
47 struct usb_hcd *hcd; 47 struct usb_hcd *hcd;
48 48
49 if (pdev->resource[1].flags != IORESOURCE_IRQ) { 49 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
50 dbg("resource[1] is not IORESOURCE_IRQ"); 50 dev_dbg(&pdev->dev, "resource[1] is not IORESOURCE_IRQ\n");
51 return -ENOMEM; 51 return -ENOMEM;
52 } 52 }
53 53
@@ -65,14 +65,14 @@ static int usb_hcd_ep93xx_probe(const struct hc_driver *driver,
65 65
66 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); 66 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
67 if (hcd->regs == NULL) { 67 if (hcd->regs == NULL) {
68 dbg("ioremap failed"); 68 dev_dbg(&pdev->dev, "ioremap failed\n");
69 retval = -ENOMEM; 69 retval = -ENOMEM;
70 goto err2; 70 goto err2;
71 } 71 }
72 72
73 usb_host_clock = clk_get(&pdev->dev, NULL); 73 usb_host_clock = clk_get(&pdev->dev, NULL);
74 if (IS_ERR(usb_host_clock)) { 74 if (IS_ERR(usb_host_clock)) {
75 dbg("clk_get failed"); 75 dev_dbg(&pdev->dev, "clk_get failed\n");
76 retval = PTR_ERR(usb_host_clock); 76 retval = PTR_ERR(usb_host_clock);
77 goto err3; 77 goto err3;
78 } 78 }
@@ -116,7 +116,8 @@ static int __devinit ohci_ep93xx_start(struct usb_hcd *hcd)
116 return ret; 116 return ret;
117 117
118 if ((ret = ohci_run(ohci)) < 0) { 118 if ((ret = ohci_run(ohci)) < 0) {
119 err("can't start %s", hcd->self.bus_name); 119 dev_err(hcd->self.controller, "can't start %s\n",
120 hcd->self.bus_name);
120 ohci_stop(hcd); 121 ohci_stop(hcd);
121 return ret; 122 return ret;
122 } 123 }
diff --git a/drivers/usb/host/ohci-exynos.c b/drivers/usb/host/ohci-exynos.c
index 37bb20ebb6f..2909621ea19 100644
--- a/drivers/usb/host/ohci-exynos.c
+++ b/drivers/usb/host/ohci-exynos.c
@@ -35,7 +35,8 @@ static int ohci_exynos_start(struct usb_hcd *hcd)
35 35
36 ret = ohci_run(ohci); 36 ret = ohci_run(ohci);
37 if (ret < 0) { 37 if (ret < 0) {
38 err("can't start %s", hcd->self.bus_name); 38 dev_err(hcd->self.controller, "can't start %s\n",
39 hcd->self.bus_name);
39 ohci_stop(hcd); 40 ohci_stop(hcd);
40 return ret; 41 return ret;
41 } 42 }
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 235171f2946..e0adf5c0cf5 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -1080,11 +1080,6 @@ MODULE_LICENSE ("GPL");
1080#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver 1080#define PS3_SYSTEM_BUS_DRIVER ps3_ohci_driver
1081#endif 1081#endif
1082 1082
1083#ifdef CONFIG_USB_OHCI_HCD_SSB
1084#include "ohci-ssb.c"
1085#define SSB_OHCI_DRIVER ssb_ohci_driver
1086#endif
1087
1088#ifdef CONFIG_MFD_SM501 1083#ifdef CONFIG_MFD_SM501
1089#include "ohci-sm501.c" 1084#include "ohci-sm501.c"
1090#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver 1085#define SM501_OHCI_DRIVER ohci_hcd_sm501_driver
@@ -1128,8 +1123,7 @@ MODULE_LICENSE ("GPL");
1128 !defined(SA1111_DRIVER) && \ 1123 !defined(SA1111_DRIVER) && \
1129 !defined(PS3_SYSTEM_BUS_DRIVER) && \ 1124 !defined(PS3_SYSTEM_BUS_DRIVER) && \
1130 !defined(SM501_OHCI_DRIVER) && \ 1125 !defined(SM501_OHCI_DRIVER) && \
1131 !defined(TMIO_OHCI_DRIVER) && \ 1126 !defined(TMIO_OHCI_DRIVER)
1132 !defined(SSB_OHCI_DRIVER)
1133#error "missing bus glue for ohci-hcd" 1127#error "missing bus glue for ohci-hcd"
1134#endif 1128#endif
1135 1129
@@ -1195,12 +1189,6 @@ static int __init ohci_hcd_mod_init(void)
1195 goto error_pci; 1189 goto error_pci;
1196#endif 1190#endif
1197 1191
1198#ifdef SSB_OHCI_DRIVER
1199 retval = ssb_driver_register(&SSB_OHCI_DRIVER);
1200 if (retval)
1201 goto error_ssb;
1202#endif
1203
1204#ifdef SM501_OHCI_DRIVER 1192#ifdef SM501_OHCI_DRIVER
1205 retval = platform_driver_register(&SM501_OHCI_DRIVER); 1193 retval = platform_driver_register(&SM501_OHCI_DRIVER);
1206 if (retval < 0) 1194 if (retval < 0)
@@ -1224,10 +1212,6 @@ static int __init ohci_hcd_mod_init(void)
1224 platform_driver_unregister(&SM501_OHCI_DRIVER); 1212 platform_driver_unregister(&SM501_OHCI_DRIVER);
1225 error_sm501: 1213 error_sm501:
1226#endif 1214#endif
1227#ifdef SSB_OHCI_DRIVER
1228 ssb_driver_unregister(&SSB_OHCI_DRIVER);
1229 error_ssb:
1230#endif
1231#ifdef PCI_DRIVER 1215#ifdef PCI_DRIVER
1232 pci_unregister_driver(&PCI_DRIVER); 1216 pci_unregister_driver(&PCI_DRIVER);
1233 error_pci: 1217 error_pci:
@@ -1275,9 +1259,6 @@ static void __exit ohci_hcd_mod_exit(void)
1275#ifdef SM501_OHCI_DRIVER 1259#ifdef SM501_OHCI_DRIVER
1276 platform_driver_unregister(&SM501_OHCI_DRIVER); 1260 platform_driver_unregister(&SM501_OHCI_DRIVER);
1277#endif 1261#endif
1278#ifdef SSB_OHCI_DRIVER
1279 ssb_driver_unregister(&SSB_OHCI_DRIVER);
1280#endif
1281#ifdef PCI_DRIVER 1262#ifdef PCI_DRIVER
1282 pci_unregister_driver(&PCI_DRIVER); 1263 pci_unregister_driver(&PCI_DRIVER);
1283#endif 1264#endif
diff --git a/drivers/usb/host/ohci-nxp.c b/drivers/usb/host/ohci-nxp.c
index 6618de1d881..1e364ec962f 100644
--- a/drivers/usb/host/ohci-nxp.c
+++ b/drivers/usb/host/ohci-nxp.c
@@ -22,6 +22,8 @@
22#include <linux/clk.h> 22#include <linux/clk.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/of.h>
26#include <linux/usb/isp1301.h>
25 27
26#include <mach/hardware.h> 28#include <mach/hardware.h>
27#include <asm/mach-types.h> 29#include <asm/mach-types.h>
@@ -29,7 +31,6 @@
29 31
30#include <mach/platform.h> 32#include <mach/platform.h>
31#include <mach/irqs.h> 33#include <mach/irqs.h>
32#include <asm/gpio.h>
33 34
34#define USB_CONFIG_BASE 0x31020000 35#define USB_CONFIG_BASE 0x31020000
35#define PWRMAN_BASE 0x40004000 36#define PWRMAN_BASE 0x40004000
@@ -38,7 +39,9 @@
38 39
39/* USB_CTRL bit defines */ 40/* USB_CTRL bit defines */
40#define USB_SLAVE_HCLK_EN (1 << 24) 41#define USB_SLAVE_HCLK_EN (1 << 24)
42#define USB_DEV_NEED_CLK_EN (1 << 22)
41#define USB_HOST_NEED_CLK_EN (1 << 21) 43#define USB_HOST_NEED_CLK_EN (1 << 21)
44#define PAD_CONTROL_LAST_DRIVEN (1 << 19)
42 45
43#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4) 46#define USB_OTG_CLK_CTRL IO_ADDRESS(USB_CONFIG_BASE + 0xFF4)
44#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8) 47#define USB_OTG_CLK_STAT IO_ADDRESS(USB_CONFIG_BASE + 0xFF8)
@@ -56,54 +59,6 @@
56#define TRANSPARENT_I2C_EN (1 << 7) 59#define TRANSPARENT_I2C_EN (1 << 7)
57#define HOST_EN (1 << 0) 60#define HOST_EN (1 << 0)
58 61
59/* ISP1301 USB transceiver I2C registers */
60#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
61
62#define MC1_SPEED_REG (1 << 0)
63#define MC1_SUSPEND_REG (1 << 1)
64#define MC1_DAT_SE0 (1 << 2)
65#define MC1_TRANSPARENT (1 << 3)
66#define MC1_BDIS_ACON_EN (1 << 4)
67#define MC1_OE_INT_EN (1 << 5)
68#define MC1_UART_EN (1 << 6)
69#define MC1_MASK 0x7f
70
71#define ISP1301_MODE_CONTROL_2 0x12 /* u8 read, set, +1 clear */
72
73#define MC2_GLOBAL_PWR_DN (1 << 0)
74#define MC2_SPD_SUSP_CTRL (1 << 1)
75#define MC2_BI_DI (1 << 2)
76#define MC2_TRANSP_BDIR0 (1 << 3)
77#define MC2_TRANSP_BDIR1 (1 << 4)
78#define MC2_AUDIO_EN (1 << 5)
79#define MC2_PSW_EN (1 << 6)
80#define MC2_EN2V7 (1 << 7)
81
82#define ISP1301_OTG_CONTROL_1 0x06 /* u8 read, set, +1 clear */
83# define OTG1_DP_PULLUP (1 << 0)
84# define OTG1_DM_PULLUP (1 << 1)
85# define OTG1_DP_PULLDOWN (1 << 2)
86# define OTG1_DM_PULLDOWN (1 << 3)
87# define OTG1_ID_PULLDOWN (1 << 4)
88# define OTG1_VBUS_DRV (1 << 5)
89# define OTG1_VBUS_DISCHRG (1 << 6)
90# define OTG1_VBUS_CHRG (1 << 7)
91#define ISP1301_OTG_STATUS 0x10 /* u8 readonly */
92# define OTG_B_SESS_END (1 << 6)
93# define OTG_B_SESS_VLD (1 << 7)
94
95#define ISP1301_I2C_ADDR 0x2C
96
97#define ISP1301_I2C_MODE_CONTROL_1 0x4
98#define ISP1301_I2C_MODE_CONTROL_2 0x12
99#define ISP1301_I2C_OTG_CONTROL_1 0x6
100#define ISP1301_I2C_OTG_CONTROL_2 0x10
101#define ISP1301_I2C_INTERRUPT_SOURCE 0x8
102#define ISP1301_I2C_INTERRUPT_LATCH 0xA
103#define ISP1301_I2C_INTERRUPT_FALLING 0xC
104#define ISP1301_I2C_INTERRUPT_RISING 0xE
105#define ISP1301_I2C_REG_CLEAR_ADDR 1
106
107/* On LPC32xx, those are undefined */ 62/* On LPC32xx, those are undefined */
108#ifndef start_int_set_falling_edge 63#ifndef start_int_set_falling_edge
109#define start_int_set_falling_edge(irq) 64#define start_int_set_falling_edge(irq)
@@ -113,42 +68,12 @@
113#define start_int_umask(irq) 68#define start_int_umask(irq)
114#endif 69#endif
115 70
116static struct i2c_driver isp1301_driver;
117static struct i2c_client *isp1301_i2c_client; 71static struct i2c_client *isp1301_i2c_client;
118 72
119extern int usb_disabled(void); 73extern int usb_disabled(void);
120extern int ocpi_enable(void);
121 74
122static struct clk *usb_clk; 75static struct clk *usb_clk;
123 76
124static const unsigned short normal_i2c[] =
125 { ISP1301_I2C_ADDR, ISP1301_I2C_ADDR + 1, I2C_CLIENT_END };
126
127static int isp1301_probe(struct i2c_client *client,
128 const struct i2c_device_id *id)
129{
130 return 0;
131}
132
133static int isp1301_remove(struct i2c_client *client)
134{
135 return 0;
136}
137
138static const struct i2c_device_id isp1301_id[] = {
139 { "isp1301_nxp", 0 },
140 { }
141};
142
143static struct i2c_driver isp1301_driver = {
144 .driver = {
145 .name = "isp1301_nxp",
146 },
147 .probe = isp1301_probe,
148 .remove = isp1301_remove,
149 .id_table = isp1301_id,
150};
151
152static void isp1301_configure_pnx4008(void) 77static void isp1301_configure_pnx4008(void)
153{ 78{
154 /* PNX4008 only supports DAT_SE0 USB mode */ 79 /* PNX4008 only supports DAT_SE0 USB mode */
@@ -220,7 +145,7 @@ static void isp1301_configure_lpc32xx(void)
220 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0); 145 ISP1301_I2C_INTERRUPT_RISING | ISP1301_I2C_REG_CLEAR_ADDR, ~0);
221 146
222 /* Enable usb_need_clk clock after transceiver is initialized */ 147 /* Enable usb_need_clk clock after transceiver is initialized */
223 __raw_writel((__raw_readl(USB_CTRL) | (1 << 22)), USB_CTRL); 148 __raw_writel(__raw_readl(USB_CTRL) | USB_HOST_NEED_CLK_EN, USB_CTRL);
224 149
225 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n", 150 printk(KERN_INFO "ISP1301 Vendor ID : 0x%04x\n",
226 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00)); 151 i2c_smbus_read_word_data(isp1301_i2c_client, 0x00));
@@ -372,65 +297,55 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
372 struct usb_hcd *hcd = 0; 297 struct usb_hcd *hcd = 0;
373 struct ohci_hcd *ohci; 298 struct ohci_hcd *ohci;
374 const struct hc_driver *driver = &ohci_nxp_hc_driver; 299 const struct hc_driver *driver = &ohci_nxp_hc_driver;
375 struct i2c_adapter *i2c_adap; 300 struct resource *res;
376 struct i2c_board_info i2c_info;
377
378 int ret = 0, irq; 301 int ret = 0, irq;
302 struct device_node *isp1301_node;
379 303
380 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name); 304 if (pdev->dev.of_node) {
381 if (usb_disabled()) { 305 isp1301_node = of_parse_phandle(pdev->dev.of_node,
382 err("USB is disabled"); 306 "transceiver", 0);
383 ret = -ENODEV; 307 } else {
384 goto out; 308 isp1301_node = NULL;
385 } 309 }
386 310
387 if (pdev->num_resources != 2 311 isp1301_i2c_client = isp1301_get_client(isp1301_node);
388 || pdev->resource[0].flags != IORESOURCE_MEM 312 if (!isp1301_i2c_client) {
389 || pdev->resource[1].flags != IORESOURCE_IRQ) { 313 ret = -EPROBE_DEFER;
390 err("Invalid resource configuration");
391 ret = -ENODEV;
392 goto out; 314 goto out;
393 } 315 }
394 316
395 /* Enable AHB slave USB clock, needed for further USB clock control */ 317 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
396 __raw_writel(USB_SLAVE_HCLK_EN | (1 << 19), USB_CTRL); 318 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
397 319
398 ret = i2c_add_driver(&isp1301_driver); 320 dev_dbg(&pdev->dev, "%s: " DRIVER_DESC " (nxp)\n", hcd_name);
399 if (ret < 0) { 321 if (usb_disabled()) {
400 err("failed to add ISP1301 driver"); 322 dev_err(&pdev->dev, "USB is disabled\n");
401 goto out;
402 }
403 i2c_adap = i2c_get_adapter(2);
404 memset(&i2c_info, 0, sizeof(struct i2c_board_info));
405 strlcpy(i2c_info.type, "isp1301_nxp", I2C_NAME_SIZE);
406 isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
407 normal_i2c, NULL);
408 i2c_put_adapter(i2c_adap);
409 if (!isp1301_i2c_client) {
410 err("failed to connect I2C to ISP1301 USB Transceiver");
411 ret = -ENODEV; 323 ret = -ENODEV;
412 goto out_i2c_driver; 324 goto out;
413 } 325 }
414 326
327 /* Enable AHB slave USB clock, needed for further USB clock control */
328 __raw_writel(USB_SLAVE_HCLK_EN | PAD_CONTROL_LAST_DRIVEN, USB_CTRL);
329
415 isp1301_configure(); 330 isp1301_configure();
416 331
417 /* Enable USB PLL */ 332 /* Enable USB PLL */
418 usb_clk = clk_get(&pdev->dev, "ck_pll5"); 333 usb_clk = clk_get(&pdev->dev, "ck_pll5");
419 if (IS_ERR(usb_clk)) { 334 if (IS_ERR(usb_clk)) {
420 err("failed to acquire USB PLL"); 335 dev_err(&pdev->dev, "failed to acquire USB PLL\n");
421 ret = PTR_ERR(usb_clk); 336 ret = PTR_ERR(usb_clk);
422 goto out1; 337 goto out1;
423 } 338 }
424 339
425 ret = clk_enable(usb_clk); 340 ret = clk_enable(usb_clk);
426 if (ret < 0) { 341 if (ret < 0) {
427 err("failed to start USB PLL"); 342 dev_err(&pdev->dev, "failed to start USB PLL\n");
428 goto out2; 343 goto out2;
429 } 344 }
430 345
431 ret = clk_set_rate(usb_clk, 48000); 346 ret = clk_set_rate(usb_clk, 48000);
432 if (ret < 0) { 347 if (ret < 0) {
433 err("failed to set USB clock rate"); 348 dev_err(&pdev->dev, "failed to set USB clock rate\n");
434 goto out3; 349 goto out3;
435 } 350 }
436 351
@@ -442,9 +357,9 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
442 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) != 357 while ((__raw_readl(USB_OTG_CLK_STAT) & USB_CLOCK_MASK) !=
443 USB_CLOCK_MASK) ; 358 USB_CLOCK_MASK) ;
444 359
445 hcd = usb_create_hcd (driver, &pdev->dev, dev_name(&pdev->dev)); 360 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
446 if (!hcd) { 361 if (!hcd) {
447 err("Failed to allocate HC buffer"); 362 dev_err(&pdev->dev, "Failed to allocate HC buffer\n");
448 ret = -ENOMEM; 363 ret = -ENOMEM;
449 goto out3; 364 goto out3;
450 } 365 }
@@ -452,14 +367,21 @@ static int __devinit usb_hcd_nxp_probe(struct platform_device *pdev)
452 /* Set all USB bits in the Start Enable register */ 367 /* Set all USB bits in the Start Enable register */
453 nxp_set_usb_bits(); 368 nxp_set_usb_bits();
454 369
455 hcd->rsrc_start = pdev->resource[0].start; 370 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
456 hcd->rsrc_len = pdev->resource[0].end - pdev->resource[0].start + 1; 371 if (!res) {
457 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 372 dev_err(&pdev->dev, "Failed to get MEM resource\n");
458 dev_dbg(&pdev->dev, "request_mem_region failed\n"); 373 ret = -ENOMEM;
374 goto out4;
375 }
376
377 hcd->regs = devm_request_and_ioremap(&pdev->dev, res);
378 if (!hcd->regs) {
379 dev_err(&pdev->dev, "Failed to devm_request_and_ioremap\n");
459 ret = -ENOMEM; 380 ret = -ENOMEM;
460 goto out4; 381 goto out4;
461 } 382 }
462 hcd->regs = (void __iomem *)pdev->resource[0].start; 383 hcd->rsrc_start = res->start;
384 hcd->rsrc_len = resource_size(res);
463 385
464 irq = platform_get_irq(pdev, 0); 386 irq = platform_get_irq(pdev, 0);
465 if (irq < 0) { 387 if (irq < 0) {
@@ -486,10 +408,7 @@ out3:
486out2: 408out2:
487 clk_put(usb_clk); 409 clk_put(usb_clk);
488out1: 410out1:
489 i2c_unregister_device(isp1301_i2c_client);
490 isp1301_i2c_client = NULL; 411 isp1301_i2c_client = NULL;
491out_i2c_driver:
492 i2c_del_driver(&isp1301_driver);
493out: 412out:
494 return ret; 413 return ret;
495} 414}
@@ -507,7 +426,6 @@ static int usb_hcd_nxp_remove(struct platform_device *pdev)
507 clk_put(usb_clk); 426 clk_put(usb_clk);
508 i2c_unregister_device(isp1301_i2c_client); 427 i2c_unregister_device(isp1301_i2c_client);
509 isp1301_i2c_client = NULL; 428 isp1301_i2c_client = NULL;
510 i2c_del_driver(&isp1301_driver);
511 429
512 platform_set_drvdata(pdev, NULL); 430 platform_set_drvdata(pdev, NULL);
513 431
@@ -517,10 +435,19 @@ static int usb_hcd_nxp_remove(struct platform_device *pdev)
517/* work with hotplug and coldplug */ 435/* work with hotplug and coldplug */
518MODULE_ALIAS("platform:usb-ohci"); 436MODULE_ALIAS("platform:usb-ohci");
519 437
438#ifdef CONFIG_OF
439static const struct of_device_id usb_hcd_nxp_match[] = {
440 { .compatible = "nxp,ohci-nxp" },
441 {},
442};
443MODULE_DEVICE_TABLE(of, usb_hcd_nxp_match);
444#endif
445
520static struct platform_driver usb_hcd_nxp_driver = { 446static struct platform_driver usb_hcd_nxp_driver = {
521 .driver = { 447 .driver = {
522 .name = "usb-ohci", 448 .name = "usb-ohci",
523 .owner = THIS_MODULE, 449 .owner = THIS_MODULE,
450 .of_match_table = of_match_ptr(usb_hcd_nxp_match),
524 }, 451 },
525 .probe = usb_hcd_nxp_probe, 452 .probe = usb_hcd_nxp_probe,
526 .remove = usb_hcd_nxp_remove, 453 .remove = usb_hcd_nxp_remove,
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 96451e41ee8..9ce35d0d9d5 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -205,8 +205,9 @@ static int ohci_omap_init(struct usb_hcd *hcd)
205 need_transceiver = need_transceiver 205 need_transceiver = need_transceiver
206 || machine_is_omap_h2() || machine_is_omap_h3(); 206 || machine_is_omap_h2() || machine_is_omap_h3();
207 207
208 if (cpu_is_omap16xx()) 208 /* XXX OMAP16xx only */
209 ocpi_enable(); 209 if (config->ocpi_enable)
210 config->ocpi_enable();
210 211
211#ifdef CONFIG_USB_OTG 212#ifdef CONFIG_USB_OTG
212 if (need_transceiver) { 213 if (need_transceiver) {
@@ -217,8 +218,7 @@ static int ohci_omap_init(struct usb_hcd *hcd)
217 dev_dbg(hcd->self.controller, "init %s transceiver, status %d\n", 218 dev_dbg(hcd->self.controller, "init %s transceiver, status %d\n",
218 ohci->transceiver->label, status); 219 ohci->transceiver->label, status);
219 if (status) { 220 if (status) {
220 if (ohci->transceiver) 221 usb_put_transceiver(ohci->transceiver);
221 put_device(ohci->transceiver->dev);
222 return status; 222 return status;
223 } 223 }
224 } else { 224 } else {
@@ -405,7 +405,7 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
405 usb_remove_hcd(hcd); 405 usb_remove_hcd(hcd);
406 if (ohci->transceiver) { 406 if (ohci->transceiver) {
407 (void) otg_set_host(ohci->transceiver->otg, 0); 407 (void) otg_set_host(ohci->transceiver->otg, 0);
408 put_device(ohci->transceiver->dev); 408 usb_put_transceiver(ohci->transceiver);
409 } 409 }
410 if (machine_is_omap_osk()) 410 if (machine_is_omap_osk())
411 gpio_free(9); 411 gpio_free(9);
diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index ec5c6791c8b..670c7059c9a 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -93,13 +93,13 @@ static int __devinit ohci_platform_probe(struct platform_device *dev)
93 93
94 irq = platform_get_irq(dev, 0); 94 irq = platform_get_irq(dev, 0);
95 if (irq < 0) { 95 if (irq < 0) {
96 pr_err("no irq provieded"); 96 pr_err("no irq provided");
97 return irq; 97 return irq;
98 } 98 }
99 99
100 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); 100 res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
101 if (!res_mem) { 101 if (!res_mem) {
102 pr_err("no memory recourse provieded"); 102 pr_err("no memory recourse provided");
103 return -ENXIO; 103 return -ENXIO;
104 } 104 }
105 105
diff --git a/drivers/usb/host/ohci-pnx8550.c b/drivers/usb/host/ohci-pnx8550.c
index f13d08f94d6..148d27d6a67 100644
--- a/drivers/usb/host/ohci-pnx8550.c
+++ b/drivers/usb/host/ohci-pnx8550.c
@@ -157,7 +157,8 @@ ohci_pnx8550_start (struct usb_hcd *hcd)
157 return ret; 157 return ret;
158 158
159 if ((ret = ohci_run (ohci)) < 0) { 159 if ((ret = ohci_run (ohci)) < 0) {
160 err ("can't start %s", hcd->self.bus_name); 160 dev_err(hcd->self.controller, "can't start %s",
161 hcd->self.bus_name);
161 ohci_stop (hcd); 162 ohci_stop (hcd);
162 return ret; 163 return ret;
163 } 164 }
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index d24cc89de16..e27d5ae2b9e 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -29,7 +29,8 @@ ohci_ppc_of_start(struct usb_hcd *hcd)
29 return ret; 29 return ret;
30 30
31 if ((ret = ohci_run(ohci)) < 0) { 31 if ((ret = ohci_run(ohci)) < 0) {
32 err("can't start %s", ohci_to_hcd(ohci)->self.bus_name); 32 dev_err(hcd->self.controller, "can't start %s\n",
33 hcd->self.bus_name);
33 ohci_stop(hcd); 34 ohci_stop(hcd);
34 return ret; 35 return ret;
35 } 36 }
@@ -236,7 +237,7 @@ MODULE_DEVICE_TABLE(of, ohci_hcd_ppc_of_match);
236 237
237#if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \ 238#if !defined(CONFIG_USB_OHCI_HCD_PPC_OF_BE) && \
238 !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE) 239 !defined(CONFIG_USB_OHCI_HCD_PPC_OF_LE)
239#error "No endianess selected for ppc-of-ohci" 240#error "No endianness selected for ppc-of-ohci"
240#endif 241#endif
241 242
242 243
diff --git a/drivers/usb/host/ohci-ppc-soc.c b/drivers/usb/host/ohci-ppc-soc.c
index 1514b706747..185c39ed81b 100644
--- a/drivers/usb/host/ohci-ppc-soc.c
+++ b/drivers/usb/host/ohci-ppc-soc.c
@@ -130,7 +130,8 @@ ohci_ppc_soc_start(struct usb_hcd *hcd)
130 return ret; 130 return ret;
131 131
132 if ((ret = ohci_run(ohci)) < 0) { 132 if ((ret = ohci_run(ohci)) < 0) {
133 err("can't start %s", ohci_to_hcd(ohci)->self.bus_name); 133 dev_err(hcd->self.controller, "can't start %s\n",
134 hcd->self.bus_name);
134 ohci_stop(hcd); 135 ohci_stop(hcd);
135 return ret; 136 return ret;
136 } 137 }
diff --git a/drivers/usb/host/ohci-ps3.c b/drivers/usb/host/ohci-ps3.c
index 6fd4fa1f19b..2ee1d8d713d 100644
--- a/drivers/usb/host/ohci-ps3.c
+++ b/drivers/usb/host/ohci-ps3.c
@@ -45,7 +45,8 @@ static int __devinit ps3_ohci_hc_start(struct usb_hcd *hcd)
45 result = ohci_run(ohci); 45 result = ohci_run(ohci);
46 46
47 if (result < 0) { 47 if (result < 0) {
48 err("can't start %s", hcd->self.bus_name); 48 dev_err(hcd->self.controller, "can't start %s\n",
49 hcd->self.bus_name);
49 ohci_stop(hcd); 50 ohci_stop(hcd);
50 } 51 }
51 52
diff --git a/drivers/usb/host/ohci-pxa27x.c b/drivers/usb/host/ohci-pxa27x.c
index c31b2815be1..e1a3cc6d28d 100644
--- a/drivers/usb/host/ohci-pxa27x.c
+++ b/drivers/usb/host/ohci-pxa27x.c
@@ -419,7 +419,8 @@ ohci_pxa27x_start (struct usb_hcd *hcd)
419 return ret; 419 return ret;
420 420
421 if ((ret = ohci_run (ohci)) < 0) { 421 if ((ret = ohci_run (ohci)) < 0) {
422 err ("can't start %s", hcd->self.bus_name); 422 dev_err(hcd->self.controller, "can't start %s",
423 hcd->self.bus_name);
423 ohci_stop (hcd); 424 ohci_stop (hcd);
424 return ret; 425 return ret;
425 } 426 }
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index 56dcf069246..664c869eb09 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -420,7 +420,8 @@ ohci_s3c2410_start(struct usb_hcd *hcd)
420 420
421 ret = ohci_run(ohci); 421 ret = ohci_run(ohci);
422 if (ret < 0) { 422 if (ret < 0) {
423 err("can't start %s", hcd->self.bus_name); 423 dev_err(hcd->self.controller, "can't start %s\n",
424 hcd->self.bus_name);
424 ohci_stop(hcd); 425 ohci_stop(hcd);
425 return ret; 426 return ret;
426 } 427 }
diff --git a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c
index e1004fb37bd..b6cc9252092 100644
--- a/drivers/usb/host/ohci-sa1111.c
+++ b/drivers/usb/host/ohci-sa1111.c
@@ -46,7 +46,7 @@ static void dump_hci_status(struct usb_hcd *hcd, const char *label)
46{ 46{
47 unsigned long status = sa1111_readl(hcd->regs + USB_STATUS); 47 unsigned long status = sa1111_readl(hcd->regs + USB_STATUS);
48 48
49 dbg("%s USB_STATUS = { %s%s%s%s%s}", label, 49 printk(KERN_DEBUG "%s USB_STATUS = { %s%s%s%s%s}\n", label,
50 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""), 50 ((status & USB_STATUS_IRQHCIRMTWKUP) ? "IRQHCIRMTWKUP " : ""),
51 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""), 51 ((status & USB_STATUS_IRQHCIBUFFACC) ? "IRQHCIBUFFACC " : ""),
52 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "), 52 ((status & USB_STATUS_NIRQHCIM) ? "" : "IRQHCIM "),
@@ -193,7 +193,7 @@ static int ohci_hcd_sa1111_probe(struct sa1111_dev *dev)
193 hcd->rsrc_len = resource_size(&dev->res); 193 hcd->rsrc_len = resource_size(&dev->res);
194 194
195 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { 195 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
196 dbg("request_mem_region failed"); 196 dev_dbg(&dev->dev, "request_mem_region failed\n");
197 ret = -EBUSY; 197 ret = -EBUSY;
198 goto err1; 198 goto err1;
199 } 199 }
diff --git a/drivers/usb/host/ohci-sh.c b/drivers/usb/host/ohci-sh.c
index 84686d90805..76a20c27836 100644
--- a/drivers/usb/host/ohci-sh.c
+++ b/drivers/usb/host/ohci-sh.c
@@ -88,20 +88,20 @@ static int ohci_hcd_sh_probe(struct platform_device *pdev)
88 88
89 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 89 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
90 if (!res) { 90 if (!res) {
91 err("platform_get_resource error."); 91 dev_err(&pdev->dev, "platform_get_resource error.\n");
92 return -ENODEV; 92 return -ENODEV;
93 } 93 }
94 94
95 irq = platform_get_irq(pdev, 0); 95 irq = platform_get_irq(pdev, 0);
96 if (irq < 0) { 96 if (irq < 0) {
97 err("platform_get_irq error."); 97 dev_err(&pdev->dev, "platform_get_irq error.\n");
98 return -ENODEV; 98 return -ENODEV;
99 } 99 }
100 100
101 /* initialize hcd */ 101 /* initialize hcd */
102 hcd = usb_create_hcd(&ohci_sh_hc_driver, &pdev->dev, (char *)hcd_name); 102 hcd = usb_create_hcd(&ohci_sh_hc_driver, &pdev->dev, (char *)hcd_name);
103 if (!hcd) { 103 if (!hcd) {
104 err("Failed to create hcd"); 104 dev_err(&pdev->dev, "Failed to create hcd\n");
105 return -ENOMEM; 105 return -ENOMEM;
106 } 106 }
107 107
@@ -110,7 +110,7 @@ static int ohci_hcd_sh_probe(struct platform_device *pdev)
110 hcd->rsrc_len = resource_size(res); 110 hcd->rsrc_len = resource_size(res);
111 ret = usb_add_hcd(hcd, irq, IRQF_SHARED); 111 ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
112 if (ret != 0) { 112 if (ret != 0) {
113 err("Failed to add hcd"); 113 dev_err(&pdev->dev, "Failed to add hcd\n");
114 usb_put_hcd(hcd); 114 usb_put_hcd(hcd);
115 return ret; 115 return ret;
116 } 116 }
diff --git a/drivers/usb/host/ohci-spear.c b/drivers/usb/host/ohci-spear.c
index 95c16489e88..fc7305ee3c9 100644
--- a/drivers/usb/host/ohci-spear.c
+++ b/drivers/usb/host/ohci-spear.c
@@ -14,6 +14,7 @@
14#include <linux/signal.h> 14#include <linux/signal.h>
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/clk.h> 16#include <linux/clk.h>
17#include <linux/of.h>
17 18
18struct spear_ohci { 19struct spear_ohci {
19 struct ohci_hcd ohci; 20 struct ohci_hcd ohci;
@@ -24,12 +25,12 @@ struct spear_ohci {
24 25
25static void spear_start_ohci(struct spear_ohci *ohci) 26static void spear_start_ohci(struct spear_ohci *ohci)
26{ 27{
27 clk_enable(ohci->clk); 28 clk_prepare_enable(ohci->clk);
28} 29}
29 30
30static void spear_stop_ohci(struct spear_ohci *ohci) 31static void spear_stop_ohci(struct spear_ohci *ohci)
31{ 32{
32 clk_disable(ohci->clk); 33 clk_disable_unprepare(ohci->clk);
33} 34}
34 35
35static int __devinit ohci_spear_start(struct usb_hcd *hcd) 36static int __devinit ohci_spear_start(struct usb_hcd *hcd)
@@ -90,6 +91,8 @@ static const struct hc_driver ohci_spear_hc_driver = {
90 .start_port_reset = ohci_start_port_reset, 91 .start_port_reset = ohci_start_port_reset,
91}; 92};
92 93
94static u64 spear_ohci_dma_mask = DMA_BIT_MASK(32);
95
93static int spear_ohci_hcd_drv_probe(struct platform_device *pdev) 96static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
94{ 97{
95 const struct hc_driver *driver = &ohci_spear_hc_driver; 98 const struct hc_driver *driver = &ohci_spear_hc_driver;
@@ -98,11 +101,8 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
98 struct spear_ohci *ohci_p; 101 struct spear_ohci *ohci_p;
99 struct resource *res; 102 struct resource *res;
100 int retval, irq; 103 int retval, irq;
101 int *pdata = pdev->dev.platform_data;
102 char clk_name[20] = "usbh_clk"; 104 char clk_name[20] = "usbh_clk";
103 105 static int instance = -1;
104 if (pdata == NULL)
105 return -EFAULT;
106 106
107 irq = platform_get_irq(pdev, 0); 107 irq = platform_get_irq(pdev, 0);
108 if (irq < 0) { 108 if (irq < 0) {
@@ -110,8 +110,22 @@ static int spear_ohci_hcd_drv_probe(struct platform_device *pdev)
110 goto fail_irq_get; 110 goto fail_irq_get;
111 } 111 }
112 112
113 if (*pdata >= 0) 113 /*
114 sprintf(clk_name, "usbh.%01d_clk", *pdata); 114 * Right now device-tree probed devices don't get dma_mask set.
115 * Since shared usb code relies on it, set it here for now.
116 * Once we have dma capability bindings this can go away.
117 */
118 if (!pdev->dev.dma_mask)
119 pdev->dev.dma_mask = &spear_ohci_dma_mask;
120
121 /*
122 * Increment the device instance, when probing via device-tree
123 */
124 if (pdev->id < 0)
125 instance++;
126 else
127 instance = pdev->id;
128 sprintf(clk_name, "usbh.%01d_clk", instance);
115 129
116 usbh_clk = clk_get(NULL, clk_name); 130 usbh_clk = clk_get(NULL, clk_name);
117 if (IS_ERR(usbh_clk)) { 131 if (IS_ERR(usbh_clk)) {
@@ -222,6 +236,11 @@ static int spear_ohci_hcd_drv_resume(struct platform_device *dev)
222} 236}
223#endif 237#endif
224 238
239static struct of_device_id spear_ohci_id_table[] __devinitdata = {
240 { .compatible = "st,spear600-ohci", },
241 { },
242};
243
225/* Driver definition to register with the platform bus */ 244/* Driver definition to register with the platform bus */
226static struct platform_driver spear_ohci_hcd_driver = { 245static struct platform_driver spear_ohci_hcd_driver = {
227 .probe = spear_ohci_hcd_drv_probe, 246 .probe = spear_ohci_hcd_drv_probe,
@@ -233,6 +252,7 @@ static struct platform_driver spear_ohci_hcd_driver = {
233 .driver = { 252 .driver = {
234 .owner = THIS_MODULE, 253 .owner = THIS_MODULE,
235 .name = "spear-ohci", 254 .name = "spear-ohci",
255 .of_match_table = of_match_ptr(spear_ohci_id_table),
236 }, 256 },
237}; 257};
238 258
diff --git a/drivers/usb/host/ohci-ssb.c b/drivers/usb/host/ohci-ssb.c
deleted file mode 100644
index 5ba18595d6f..00000000000
--- a/drivers/usb/host/ohci-ssb.c
+++ /dev/null
@@ -1,260 +0,0 @@
1/*
2 * Sonics Silicon Backplane
3 * Broadcom USB-core OHCI driver
4 *
5 * Copyright 2007 Michael Buesch <m@bues.ch>
6 *
7 * Derived from the OHCI-PCI driver
8 * Copyright 1999 Roman Weissgaerber
9 * Copyright 2000-2002 David Brownell
10 * Copyright 1999 Linus Torvalds
11 * Copyright 1999 Gregory P. Smith
12 *
13 * Derived from the USBcore related parts of Broadcom-SB
14 * Copyright 2005 Broadcom Corporation
15 *
16 * Licensed under the GNU/GPL. See COPYING for details.
17 */
18#include <linux/ssb/ssb.h>
19
20
21#define SSB_OHCI_TMSLOW_HOSTMODE (1 << 29)
22
23struct ssb_ohci_device {
24 struct ohci_hcd ohci; /* _must_ be at the beginning. */
25
26 u32 enable_flags;
27};
28
29static inline
30struct ssb_ohci_device *hcd_to_ssb_ohci(struct usb_hcd *hcd)
31{
32 return (struct ssb_ohci_device *)(hcd->hcd_priv);
33}
34
35
36static int ssb_ohci_reset(struct usb_hcd *hcd)
37{
38 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
39 struct ohci_hcd *ohci = &ohcidev->ohci;
40 int err;
41
42 ohci_hcd_init(ohci);
43 err = ohci_init(ohci);
44
45 return err;
46}
47
48static int ssb_ohci_start(struct usb_hcd *hcd)
49{
50 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
51 struct ohci_hcd *ohci = &ohcidev->ohci;
52 int err;
53
54 err = ohci_run(ohci);
55 if (err < 0) {
56 ohci_err(ohci, "can't start\n");
57 ohci_stop(hcd);
58 }
59
60 return err;
61}
62
63static const struct hc_driver ssb_ohci_hc_driver = {
64 .description = "ssb-usb-ohci",
65 .product_desc = "SSB OHCI Controller",
66 .hcd_priv_size = sizeof(struct ssb_ohci_device),
67
68 .irq = ohci_irq,
69 .flags = HCD_MEMORY | HCD_USB11,
70
71 .reset = ssb_ohci_reset,
72 .start = ssb_ohci_start,
73 .stop = ohci_stop,
74 .shutdown = ohci_shutdown,
75
76 .urb_enqueue = ohci_urb_enqueue,
77 .urb_dequeue = ohci_urb_dequeue,
78 .endpoint_disable = ohci_endpoint_disable,
79
80 .get_frame_number = ohci_get_frame,
81
82 .hub_status_data = ohci_hub_status_data,
83 .hub_control = ohci_hub_control,
84#ifdef CONFIG_PM
85 .bus_suspend = ohci_bus_suspend,
86 .bus_resume = ohci_bus_resume,
87#endif
88
89 .start_port_reset = ohci_start_port_reset,
90};
91
92static void ssb_ohci_detach(struct ssb_device *dev)
93{
94 struct usb_hcd *hcd = ssb_get_drvdata(dev);
95
96 if (hcd->driver->shutdown)
97 hcd->driver->shutdown(hcd);
98 usb_remove_hcd(hcd);
99 iounmap(hcd->regs);
100 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
101 usb_put_hcd(hcd);
102 ssb_device_disable(dev, 0);
103}
104
105static int ssb_ohci_attach(struct ssb_device *dev)
106{
107 struct ssb_ohci_device *ohcidev;
108 struct usb_hcd *hcd;
109 int err = -ENOMEM;
110 u32 tmp, flags = 0;
111
112 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
113 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
114 return -EOPNOTSUPP;
115
116 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV) {
117 /* Put the device into host-mode. */
118 flags |= SSB_OHCI_TMSLOW_HOSTMODE;
119 ssb_device_enable(dev, flags);
120 } else if (dev->id.coreid == SSB_DEV_USB20_HOST) {
121 /*
122 * USB 2.0 special considerations:
123 *
124 * In addition to the standard SSB reset sequence, the Host
125 * Control Register must be programmed to bring the USB core
126 * and various phy components out of reset.
127 */
128 ssb_device_enable(dev, 0);
129 ssb_write32(dev, 0x200, 0x7ff);
130
131 /* Change Flush control reg */
132 tmp = ssb_read32(dev, 0x400);
133 tmp &= ~8;
134 ssb_write32(dev, 0x400, tmp);
135 tmp = ssb_read32(dev, 0x400);
136
137 /* Change Shim control reg */
138 tmp = ssb_read32(dev, 0x304);
139 tmp &= ~0x100;
140 ssb_write32(dev, 0x304, tmp);
141 tmp = ssb_read32(dev, 0x304);
142
143 udelay(1);
144
145 /* Work around for 5354 failures */
146 if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) {
147 /* Change syn01 reg */
148 tmp = 0x00fe00fe;
149 ssb_write32(dev, 0x894, tmp);
150
151 /* Change syn03 reg */
152 tmp = ssb_read32(dev, 0x89c);
153 tmp |= 0x1;
154 ssb_write32(dev, 0x89c, tmp);
155 }
156 } else
157 ssb_device_enable(dev, 0);
158
159 hcd = usb_create_hcd(&ssb_ohci_hc_driver, dev->dev,
160 dev_name(dev->dev));
161 if (!hcd)
162 goto err_dev_disable;
163 ohcidev = hcd_to_ssb_ohci(hcd);
164 ohcidev->enable_flags = flags;
165
166 tmp = ssb_read32(dev, SSB_ADMATCH0);
167 hcd->rsrc_start = ssb_admatch_base(tmp);
168 hcd->rsrc_len = ssb_admatch_size(tmp);
169 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
170 if (!hcd->regs)
171 goto err_put_hcd;
172 err = usb_add_hcd(hcd, dev->irq, IRQF_SHARED);
173 if (err)
174 goto err_iounmap;
175
176 ssb_set_drvdata(dev, hcd);
177
178 return err;
179
180err_iounmap:
181 iounmap(hcd->regs);
182err_put_hcd:
183 usb_put_hcd(hcd);
184err_dev_disable:
185 ssb_device_disable(dev, flags);
186 return err;
187}
188
189static int ssb_ohci_probe(struct ssb_device *dev,
190 const struct ssb_device_id *id)
191{
192 int err;
193 u16 chipid_top;
194
195 /* USBcores are only connected on embedded devices. */
196 chipid_top = (dev->bus->chip_id & 0xFF00);
197 if (chipid_top != 0x4700 && chipid_top != 0x5300)
198 return -ENODEV;
199
200 /* TODO: Probably need checks here; is the core connected? */
201
202 if (usb_disabled())
203 return -ENODEV;
204
205 /* We currently always attach SSB_DEV_USB11_HOSTDEV
206 * as HOST OHCI. If we want to attach it as Client device,
207 * we must branch here and call into the (yet to
208 * be written) Client mode driver. Same for remove(). */
209
210 err = ssb_ohci_attach(dev);
211
212 return err;
213}
214
215static void ssb_ohci_remove(struct ssb_device *dev)
216{
217 ssb_ohci_detach(dev);
218}
219
220#ifdef CONFIG_PM
221
222static int ssb_ohci_suspend(struct ssb_device *dev, pm_message_t state)
223{
224 ssb_device_disable(dev, 0);
225
226 return 0;
227}
228
229static int ssb_ohci_resume(struct ssb_device *dev)
230{
231 struct usb_hcd *hcd = ssb_get_drvdata(dev);
232 struct ssb_ohci_device *ohcidev = hcd_to_ssb_ohci(hcd);
233
234 ssb_device_enable(dev, ohcidev->enable_flags);
235
236 ohci_finish_controller_resume(hcd);
237 return 0;
238}
239
240#else /* !CONFIG_PM */
241#define ssb_ohci_suspend NULL
242#define ssb_ohci_resume NULL
243#endif /* CONFIG_PM */
244
245static const struct ssb_device_id ssb_ohci_table[] = {
246 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
247 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
248 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV),
249 SSB_DEVTABLE_END
250};
251MODULE_DEVICE_TABLE(ssb, ssb_ohci_table);
252
253static struct ssb_driver ssb_ohci_driver = {
254 .name = KBUILD_MODNAME,
255 .id_table = ssb_ohci_table,
256 .probe = ssb_ohci_probe,
257 .remove = ssb_ohci_remove,
258 .suspend = ssb_ohci_suspend,
259 .resume = ssb_ohci_resume,
260};
diff --git a/drivers/usb/host/ohci-tmio.c b/drivers/usb/host/ohci-tmio.c
index 120bfe6ede3..60c2b0722f2 100644
--- a/drivers/usb/host/ohci-tmio.c
+++ b/drivers/usb/host/ohci-tmio.c
@@ -140,7 +140,8 @@ static int ohci_tmio_start(struct usb_hcd *hcd)
140 return ret; 140 return ret;
141 141
142 if ((ret = ohci_run(ohci)) < 0) { 142 if ((ret = ohci_run(ohci)) < 0) {
143 err("can't start %s", hcd->self.bus_name); 143 dev_err(hcd->self.controller, "can't start %s\n",
144 hcd->self.bus_name);
144 ohci_stop(hcd); 145 ohci_stop(hcd);
145 return ret; 146 return ret;
146 } 147 }
diff --git a/drivers/usb/host/ohci-xls.c b/drivers/usb/host/ohci-xls.c
index a2247867af8..41e378f17c6 100644
--- a/drivers/usb/host/ohci-xls.c
+++ b/drivers/usb/host/ohci-xls.c
@@ -88,7 +88,8 @@ static int __devinit ohci_xls_start(struct usb_hcd *hcd)
88 ohci = hcd_to_ohci(hcd); 88 ohci = hcd_to_ohci(hcd);
89 ret = ohci_run(ohci); 89 ret = ohci_run(ohci);
90 if (ret < 0) { 90 if (ret < 0) {
91 err("can't start %s", hcd->self.bus_name); 91 dev_err(hcd->self.controller, "can't start %s\n",
92 hcd->self.bus_name);
92 ohci_stop(hcd); 93 ohci_stop(hcd);
93 return ret; 94 return ret;
94 } 95 }
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index 3b38030b02a..4f0f0339532 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -1399,8 +1399,8 @@ static struct ehci_qh *qh_make(struct oxu_hcd *oxu,
1399 * But interval 1 scheduling is simpler, and 1399 * But interval 1 scheduling is simpler, and
1400 * includes high bandwidth. 1400 * includes high bandwidth.
1401 */ 1401 */
1402 dbg("intr period %d uframes, NYET!", 1402 oxu_dbg(oxu, "intr period %d uframes, NYET!\n",
1403 urb->interval); 1403 urb->interval);
1404 goto done; 1404 goto done;
1405 } 1405 }
1406 } else { 1406 } else {
@@ -1471,7 +1471,7 @@ static struct ehci_qh *qh_make(struct oxu_hcd *oxu,
1471 } 1471 }
1472 break; 1472 break;
1473 default: 1473 default:
1474 dbg("bogus dev %p speed %d", urb->dev, urb->dev->speed); 1474 oxu_dbg(oxu, "bogus dev %p speed %d\n", urb->dev, urb->dev->speed);
1475done: 1475done:
1476 qh_put(qh); 1476 qh_put(qh);
1477 return NULL; 1477 return NULL;
@@ -2307,7 +2307,7 @@ restart:
2307 qh_put(temp.qh); 2307 qh_put(temp.qh);
2308 break; 2308 break;
2309 default: 2309 default:
2310 dbg("corrupt type %d frame %d shadow %p", 2310 oxu_dbg(oxu, "corrupt type %d frame %d shadow %p\n",
2311 type, frame, q.ptr); 2311 type, frame, q.ptr);
2312 q.ptr = NULL; 2312 q.ptr = NULL;
2313 } 2313 }
@@ -2991,8 +2991,9 @@ static int oxu_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2991 /* shouldn't happen often, but ... 2991 /* shouldn't happen often, but ...
2992 * FIXME kill those tds' urbs 2992 * FIXME kill those tds' urbs
2993 */ 2993 */
2994 err("can't reschedule qh %p, err %d", 2994 dev_err(hcd->self.controller,
2995 qh, status); 2995 "can't reschedule qh %p, err %d\n", qh,
2996 status);
2996 } 2997 }
2997 return status; 2998 return status;
2998 } 2999 }
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 32dada8c8b4..df0828cb2aa 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/kconfig.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/pci.h> 14#include <linux/pci.h>
14#include <linux/init.h> 15#include <linux/init.h>
@@ -712,12 +713,28 @@ static int handshake(void __iomem *ptr, u32 mask, u32 done,
712 return -ETIMEDOUT; 713 return -ETIMEDOUT;
713} 714}
714 715
715bool usb_is_intel_switchable_xhci(struct pci_dev *pdev) 716#define PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI 0x8C31
717
718bool usb_is_intel_ppt_switchable_xhci(struct pci_dev *pdev)
716{ 719{
717 return pdev->class == PCI_CLASS_SERIAL_USB_XHCI && 720 return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
718 pdev->vendor == PCI_VENDOR_ID_INTEL && 721 pdev->vendor == PCI_VENDOR_ID_INTEL &&
719 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI; 722 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI;
720} 723}
724
725/* The Intel Lynx Point chipset also has switchable ports. */
726bool usb_is_intel_lpt_switchable_xhci(struct pci_dev *pdev)
727{
728 return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
729 pdev->vendor == PCI_VENDOR_ID_INTEL &&
730 pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI;
731}
732
733bool usb_is_intel_switchable_xhci(struct pci_dev *pdev)
734{
735 return usb_is_intel_ppt_switchable_xhci(pdev) ||
736 usb_is_intel_lpt_switchable_xhci(pdev);
737}
721EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci); 738EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci);
722 739
723/* 740/*
@@ -742,6 +759,19 @@ void usb_enable_xhci_ports(struct pci_dev *xhci_pdev)
742{ 759{
743 u32 ports_available; 760 u32 ports_available;
744 761
762 /* Don't switchover the ports if the user hasn't compiled the xHCI
763 * driver. Otherwise they will see "dead" USB ports that don't power
764 * the devices.
765 */
766 if (!IS_ENABLED(CONFIG_USB_XHCI_HCD)) {
767 dev_warn(&xhci_pdev->dev,
768 "CONFIG_USB_XHCI_HCD is turned off, "
769 "defaulting to EHCI.\n");
770 dev_warn(&xhci_pdev->dev,
771 "USB 3.0 devices will work at USB 2.0 speeds.\n");
772 return;
773 }
774
745 ports_available = 0xffffffff; 775 ports_available = 0xffffffff;
746 /* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable 776 /* Write USB3_PSSEN, the USB 3.0 Port SuperSpeed Enable
747 * Register, to turn on SuperSpeed terminations for all 777 * Register, to turn on SuperSpeed terminations for all
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 2bf1320dc9c..c868be65e76 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -401,7 +401,7 @@ static u8 alloc_usb_address(struct r8a66597 *r8a66597, struct urb *urb)
401 if (r8a66597->address_map & (1 << addr)) 401 if (r8a66597->address_map & (1 << addr))
402 continue; 402 continue;
403 403
404 dbg("alloc_address: r8a66597_addr=%d", addr); 404 dev_dbg(&urb->dev->dev, "alloc_address: r8a66597_addr=%d\n", addr);
405 r8a66597->address_map |= 1 << addr; 405 r8a66597->address_map |= 1 << addr;
406 406
407 if (make_r8a66597_device(r8a66597, urb, addr) < 0) 407 if (make_r8a66597_device(r8a66597, urb, addr) < 0)
@@ -426,7 +426,7 @@ static void free_usb_address(struct r8a66597 *r8a66597,
426 if (!dev) 426 if (!dev)
427 return; 427 return;
428 428
429 dbg("free_addr: addr=%d", dev->address); 429 dev_dbg(&dev->udev->dev, "free_addr: addr=%d\n", dev->address);
430 430
431 dev->state = USB_STATE_DEFAULT; 431 dev->state = USB_STATE_DEFAULT;
432 r8a66597->address_map &= ~(1 << dev->address); 432 r8a66597->address_map &= ~(1 << dev->address);
@@ -819,7 +819,7 @@ static void enable_r8a66597_pipe(struct r8a66597 *r8a66597, struct urb *urb,
819 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb); 819 struct r8a66597_device *dev = get_urb_to_r8a66597_dev(r8a66597, urb);
820 struct r8a66597_pipe *pipe = hep->hcpriv; 820 struct r8a66597_pipe *pipe = hep->hcpriv;
821 821
822 dbg("enable_pipe:"); 822 dev_dbg(&dev->udev->dev, "enable_pipe:\n");
823 823
824 pipe->info = *info; 824 pipe->info = *info;
825 set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA); 825 set_pipe_reg_addr(pipe, R8A66597_PIPE_NO_DMA);
@@ -898,7 +898,7 @@ static void disable_r8a66597_pipe_all(struct r8a66597 *r8a66597,
898 force_dequeue(r8a66597, pipenum, dev->address); 898 force_dequeue(r8a66597, pipenum, dev->address);
899 } 899 }
900 900
901 dbg("disable_pipe"); 901 dev_dbg(&dev->udev->dev, "disable_pipe\n");
902 902
903 r8a66597->dma_map &= ~(dev->dma_map); 903 r8a66597->dma_map &= ~(dev->dma_map);
904 dev->dma_map = 0; 904 dev->dma_map = 0;
@@ -2264,7 +2264,7 @@ static int r8a66597_bus_suspend(struct usb_hcd *hcd)
2264 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 2264 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2265 int port; 2265 int port;
2266 2266
2267 dbg("%s", __func__); 2267 dev_dbg(&r8a66597->device0.udev->dev, "%s\n", __func__);
2268 2268
2269 for (port = 0; port < r8a66597->max_root_hub; port++) { 2269 for (port = 0; port < r8a66597->max_root_hub; port++) {
2270 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; 2270 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
@@ -2273,7 +2273,7 @@ static int r8a66597_bus_suspend(struct usb_hcd *hcd)
2273 if (!(rh->port & USB_PORT_STAT_ENABLE)) 2273 if (!(rh->port & USB_PORT_STAT_ENABLE))
2274 continue; 2274 continue;
2275 2275
2276 dbg("suspend port = %d", port); 2276 dev_dbg(&rh->dev->udev->dev, "suspend port = %d\n", port);
2277 r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */ 2277 r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */
2278 rh->port |= USB_PORT_STAT_SUSPEND; 2278 rh->port |= USB_PORT_STAT_SUSPEND;
2279 2279
@@ -2295,7 +2295,7 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd)
2295 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 2295 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2296 int port; 2296 int port;
2297 2297
2298 dbg("%s", __func__); 2298 dev_dbg(&r8a66597->device0.udev->dev, "%s\n", __func__);
2299 2299
2300 for (port = 0; port < r8a66597->max_root_hub; port++) { 2300 for (port = 0; port < r8a66597->max_root_hub; port++) {
2301 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port]; 2301 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
@@ -2304,7 +2304,7 @@ static int r8a66597_bus_resume(struct usb_hcd *hcd)
2304 if (!(rh->port & USB_PORT_STAT_SUSPEND)) 2304 if (!(rh->port & USB_PORT_STAT_SUSPEND))
2305 continue; 2305 continue;
2306 2306
2307 dbg("resume port = %d", port); 2307 dev_dbg(&rh->dev->udev->dev, "resume port = %d\n", port);
2308 rh->port &= ~USB_PORT_STAT_SUSPEND; 2308 rh->port &= ~USB_PORT_STAT_SUSPEND;
2309 rh->port |= USB_PORT_STAT_C_SUSPEND << 16; 2309 rh->port |= USB_PORT_STAT_C_SUSPEND << 16;
2310 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg); 2310 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg);
@@ -2360,7 +2360,7 @@ static int r8a66597_suspend(struct device *dev)
2360 struct r8a66597 *r8a66597 = dev_get_drvdata(dev); 2360 struct r8a66597 *r8a66597 = dev_get_drvdata(dev);
2361 int port; 2361 int port;
2362 2362
2363 dbg("%s", __func__); 2363 dev_dbg(dev, "%s\n", __func__);
2364 2364
2365 disable_controller(r8a66597); 2365 disable_controller(r8a66597);
2366 2366
@@ -2378,7 +2378,7 @@ static int r8a66597_resume(struct device *dev)
2378 struct r8a66597 *r8a66597 = dev_get_drvdata(dev); 2378 struct r8a66597 *r8a66597 = dev_get_drvdata(dev);
2379 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597); 2379 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
2380 2380
2381 dbg("%s", __func__); 2381 dev_dbg(dev, "%s\n", __func__);
2382 2382
2383 enable_controller(r8a66597); 2383 enable_controller(r8a66597);
2384 usb_root_hub_lost_power(hcd->self.root_hub); 2384 usb_root_hub_lost_power(hcd->self.root_hub);
diff --git a/drivers/usb/host/ssb-hcd.c b/drivers/usb/host/ssb-hcd.c
new file mode 100644
index 00000000000..c2a29faba07
--- /dev/null
+++ b/drivers/usb/host/ssb-hcd.c
@@ -0,0 +1,280 @@
1/*
2 * Sonics Silicon Backplane
3 * Broadcom USB-core driver (SSB bus glue)
4 *
5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
6 *
7 * Based on ssb-ohci driver
8 * Copyright 2007 Michael Buesch <m@bues.ch>
9 *
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
15 *
16 * Derived from the USBcore related parts of Broadcom-SB
17 * Copyright 2005-2011 Broadcom Corporation
18 *
19 * Licensed under the GNU/GPL. See COPYING for details.
20 */
21#include <linux/ssb/ssb.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>
28
29MODULE_AUTHOR("Hauke Mehrtens");
30MODULE_DESCRIPTION("Common USB driver for SSB Bus");
31MODULE_LICENSE("GPL");
32
33#define SSB_HCD_TMSLOW_HOSTMODE (1 << 29)
34
35struct ssb_hcd_device {
36 struct platform_device *ehci_dev;
37 struct platform_device *ohci_dev;
38
39 u32 enable_flags;
40};
41
42static void __devinit ssb_hcd_5354wa(struct ssb_device *dev)
43{
44#ifdef CONFIG_SSB_DRIVER_MIPS
45 /* Work around for 5354 failures */
46 if (dev->id.revision == 2 && dev->bus->chip_id == 0x5354) {
47 /* Change syn01 reg */
48 ssb_write32(dev, 0x894, 0x00fe00fe);
49
50 /* Change syn03 reg */
51 ssb_write32(dev, 0x89c, ssb_read32(dev, 0x89c) | 0x1);
52 }
53#endif
54}
55
56static void __devinit ssb_hcd_usb20wa(struct ssb_device *dev)
57{
58 if (dev->id.coreid == SSB_DEV_USB20_HOST) {
59 /*
60 * USB 2.0 special considerations:
61 *
62 * In addition to the standard SSB reset sequence, the Host
63 * Control Register must be programmed to bring the USB core
64 * and various phy components out of reset.
65 */
66 ssb_write32(dev, 0x200, 0x7ff);
67
68 /* Change Flush control reg */
69 ssb_write32(dev, 0x400, ssb_read32(dev, 0x400) & ~8);
70 ssb_read32(dev, 0x400);
71
72 /* Change Shim control reg */
73 ssb_write32(dev, 0x304, ssb_read32(dev, 0x304) & ~0x100);
74 ssb_read32(dev, 0x304);
75
76 udelay(1);
77
78 ssb_hcd_5354wa(dev);
79 }
80}
81
82/* based on arch/mips/brcm-boards/bcm947xx/pcibios.c */
83static u32 __devinit ssb_hcd_init_chip(struct ssb_device *dev)
84{
85 u32 flags = 0;
86
87 if (dev->id.coreid == SSB_DEV_USB11_HOSTDEV)
88 /* Put the device into host-mode. */
89 flags |= SSB_HCD_TMSLOW_HOSTMODE;
90
91 ssb_device_enable(dev, flags);
92
93 ssb_hcd_usb20wa(dev);
94
95 return flags;
96}
97
98static const struct usb_ehci_pdata ehci_pdata = {
99};
100
101static const struct usb_ohci_pdata ohci_pdata = {
102};
103
104static struct platform_device * __devinit
105ssb_hcd_create_pdev(struct ssb_device *dev, bool ohci, u32 addr, u32 len)
106{
107 struct platform_device *hci_dev;
108 struct resource hci_res[2];
109 int ret = -ENOMEM;
110
111 memset(hci_res, 0, sizeof(hci_res));
112
113 hci_res[0].start = addr;
114 hci_res[0].end = hci_res[0].start + len - 1;
115 hci_res[0].flags = IORESOURCE_MEM;
116
117 hci_res[1].start = dev->irq;
118 hci_res[1].flags = IORESOURCE_IRQ;
119
120 hci_dev = platform_device_alloc(ohci ? "ohci-platform" :
121 "ehci-platform" , 0);
122 if (!hci_dev)
123 return NULL;
124
125 hci_dev->dev.parent = dev->dev;
126 hci_dev->dev.dma_mask = &hci_dev->dev.coherent_dma_mask;
127
128 ret = platform_device_add_resources(hci_dev, hci_res,
129 ARRAY_SIZE(hci_res));
130 if (ret)
131 goto err_alloc;
132 if (ohci)
133 ret = platform_device_add_data(hci_dev, &ohci_pdata,
134 sizeof(ohci_pdata));
135 else
136 ret = platform_device_add_data(hci_dev, &ehci_pdata,
137 sizeof(ehci_pdata));
138 if (ret)
139 goto err_alloc;
140 ret = platform_device_add(hci_dev);
141 if (ret)
142 goto err_alloc;
143
144 return hci_dev;
145
146err_alloc:
147 platform_device_put(hci_dev);
148 return ERR_PTR(ret);
149}
150
151static int __devinit ssb_hcd_probe(struct ssb_device *dev,
152 const struct ssb_device_id *id)
153{
154 int err, tmp;
155 int start, len;
156 u16 chipid_top;
157 u16 coreid = dev->id.coreid;
158 struct ssb_hcd_device *usb_dev;
159
160 /* USBcores are only connected on embedded devices. */
161 chipid_top = (dev->bus->chip_id & 0xFF00);
162 if (chipid_top != 0x4700 && chipid_top != 0x5300)
163 return -ENODEV;
164
165 /* TODO: Probably need checks here; is the core connected? */
166
167 if (dma_set_mask(dev->dma_dev, DMA_BIT_MASK(32)) ||
168 dma_set_coherent_mask(dev->dma_dev, DMA_BIT_MASK(32)))
169 return -EOPNOTSUPP;
170
171 usb_dev = kzalloc(sizeof(struct ssb_hcd_device), GFP_KERNEL);
172 if (!usb_dev)
173 return -ENOMEM;
174
175 /* We currently always attach SSB_DEV_USB11_HOSTDEV
176 * as HOST OHCI. If we want to attach it as Client device,
177 * we must branch here and call into the (yet to
178 * be written) Client mode driver. Same for remove(). */
179 usb_dev->enable_flags = ssb_hcd_init_chip(dev);
180
181 tmp = ssb_read32(dev, SSB_ADMATCH0);
182
183 start = ssb_admatch_base(tmp);
184 len = (coreid == SSB_DEV_USB20_HOST) ? 0x800 : ssb_admatch_size(tmp);
185 usb_dev->ohci_dev = ssb_hcd_create_pdev(dev, true, start, len);
186 if (IS_ERR(usb_dev->ohci_dev)) {
187 err = PTR_ERR(usb_dev->ohci_dev);
188 goto err_free_usb_dev;
189 }
190
191 if (coreid == SSB_DEV_USB20_HOST) {
192 start = ssb_admatch_base(tmp) + 0x800; /* ehci core offset */
193 usb_dev->ehci_dev = ssb_hcd_create_pdev(dev, false, start, len);
194 if (IS_ERR(usb_dev->ehci_dev)) {
195 err = PTR_ERR(usb_dev->ehci_dev);
196 goto err_unregister_ohci_dev;
197 }
198 }
199
200 ssb_set_drvdata(dev, usb_dev);
201 return 0;
202
203err_unregister_ohci_dev:
204 platform_device_unregister(usb_dev->ohci_dev);
205err_free_usb_dev:
206 kfree(usb_dev);
207 return err;
208}
209
210static void __devexit ssb_hcd_remove(struct ssb_device *dev)
211{
212 struct ssb_hcd_device *usb_dev = ssb_get_drvdata(dev);
213 struct platform_device *ohci_dev = usb_dev->ohci_dev;
214 struct platform_device *ehci_dev = usb_dev->ehci_dev;
215
216 if (ohci_dev)
217 platform_device_unregister(ohci_dev);
218 if (ehci_dev)
219 platform_device_unregister(ehci_dev);
220
221 ssb_device_disable(dev, 0);
222}
223
224static void __devexit ssb_hcd_shutdown(struct ssb_device *dev)
225{
226 ssb_device_disable(dev, 0);
227}
228
229#ifdef CONFIG_PM
230
231static int ssb_hcd_suspend(struct ssb_device *dev, pm_message_t state)
232{
233 ssb_device_disable(dev, 0);
234
235 return 0;
236}
237
238static int ssb_hcd_resume(struct ssb_device *dev)
239{
240 struct ssb_hcd_device *usb_dev = ssb_get_drvdata(dev);
241
242 ssb_device_enable(dev, usb_dev->enable_flags);
243
244 return 0;
245}
246
247#else /* !CONFIG_PM */
248#define ssb_hcd_suspend NULL
249#define ssb_hcd_resume NULL
250#endif /* CONFIG_PM */
251
252static const struct ssb_device_id ssb_hcd_table[] __devinitconst = {
253 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOSTDEV, SSB_ANY_REV),
254 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB11_HOST, SSB_ANY_REV),
255 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_USB20_HOST, SSB_ANY_REV),
256 SSB_DEVTABLE_END
257};
258MODULE_DEVICE_TABLE(ssb, ssb_hcd_table);
259
260static struct ssb_driver ssb_hcd_driver = {
261 .name = KBUILD_MODNAME,
262 .id_table = ssb_hcd_table,
263 .probe = ssb_hcd_probe,
264 .remove = __devexit_p(ssb_hcd_remove),
265 .shutdown = ssb_hcd_shutdown,
266 .suspend = ssb_hcd_suspend,
267 .resume = ssb_hcd_resume,
268};
269
270static int __init ssb_hcd_init(void)
271{
272 return ssb_driver_register(&ssb_hcd_driver);
273}
274module_init(ssb_hcd_init);
275
276static void __exit ssb_hcd_exit(void)
277{
278 ssb_driver_unregister(&ssb_hcd_driver);
279}
280module_exit(ssb_hcd_exit);
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 673ad120c43..2732ef660c5 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -475,6 +475,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
475 struct xhci_bus_state *bus_state; 475 struct xhci_bus_state *bus_state;
476 u16 link_state = 0; 476 u16 link_state = 0;
477 u16 wake_mask = 0; 477 u16 wake_mask = 0;
478 u16 timeout = 0;
478 479
479 max_ports = xhci_get_ports(hcd, &port_array); 480 max_ports = xhci_get_ports(hcd, &port_array);
480 bus_state = &xhci->bus_state[hcd_index(hcd)]; 481 bus_state = &xhci->bus_state[hcd_index(hcd)];
@@ -558,6 +559,7 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
558 xhci_dbg(xhci, "Resume USB2 port %d\n", 559 xhci_dbg(xhci, "Resume USB2 port %d\n",
559 wIndex + 1); 560 wIndex + 1);
560 bus_state->resume_done[wIndex] = 0; 561 bus_state->resume_done[wIndex] = 0;
562 clear_bit(wIndex, &bus_state->resuming_ports);
561 xhci_set_link_state(xhci, port_array, wIndex, 563 xhci_set_link_state(xhci, port_array, wIndex,
562 XDEV_U0); 564 XDEV_U0);
563 xhci_dbg(xhci, "set port %d resume\n", 565 xhci_dbg(xhci, "set port %d resume\n",
@@ -622,6 +624,8 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
622 link_state = (wIndex & 0xff00) >> 3; 624 link_state = (wIndex & 0xff00) >> 3;
623 if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK) 625 if (wValue == USB_PORT_FEAT_REMOTE_WAKE_MASK)
624 wake_mask = wIndex & 0xff00; 626 wake_mask = wIndex & 0xff00;
627 /* The MSB of wIndex is the U1/U2 timeout */
628 timeout = (wIndex & 0xff00) >> 8;
625 wIndex &= 0xff; 629 wIndex &= 0xff;
626 if (!wIndex || wIndex > max_ports) 630 if (!wIndex || wIndex > max_ports)
627 goto error; 631 goto error;
@@ -746,6 +750,22 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
746 750
747 temp = xhci_readl(xhci, port_array[wIndex]); 751 temp = xhci_readl(xhci, port_array[wIndex]);
748 break; 752 break;
753 case USB_PORT_FEAT_U1_TIMEOUT:
754 if (hcd->speed != HCD_USB3)
755 goto error;
756 temp = xhci_readl(xhci, port_array[wIndex] + 1);
757 temp &= ~PORT_U1_TIMEOUT_MASK;
758 temp |= PORT_U1_TIMEOUT(timeout);
759 xhci_writel(xhci, temp, port_array[wIndex] + 1);
760 break;
761 case USB_PORT_FEAT_U2_TIMEOUT:
762 if (hcd->speed != HCD_USB3)
763 goto error;
764 temp = xhci_readl(xhci, port_array[wIndex] + 1);
765 temp &= ~PORT_U2_TIMEOUT_MASK;
766 temp |= PORT_U2_TIMEOUT(timeout);
767 xhci_writel(xhci, temp, port_array[wIndex] + 1);
768 break;
749 default: 769 default:
750 goto error; 770 goto error;
751 } 771 }
@@ -845,7 +865,12 @@ int xhci_hub_status_data(struct usb_hcd *hcd, char *buf)
845 /* Initial status is no changes */ 865 /* Initial status is no changes */
846 retval = (max_ports + 8) / 8; 866 retval = (max_ports + 8) / 8;
847 memset(buf, 0, retval); 867 memset(buf, 0, retval);
848 status = 0; 868
869 /*
870 * Inform the usbcore about resume-in-progress by returning
871 * a non-zero value even if there are no status changes.
872 */
873 status = bus_state->resuming_ports;
849 874
850 mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC | PORT_WRC; 875 mask = PORT_CSC | PORT_PEC | PORT_OCC | PORT_PLC | PORT_WRC;
851 876
@@ -885,15 +910,11 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
885 spin_lock_irqsave(&xhci->lock, flags); 910 spin_lock_irqsave(&xhci->lock, flags);
886 911
887 if (hcd->self.root_hub->do_remote_wakeup) { 912 if (hcd->self.root_hub->do_remote_wakeup) {
888 port_index = max_ports; 913 if (bus_state->resuming_ports) {
889 while (port_index--) { 914 spin_unlock_irqrestore(&xhci->lock, flags);
890 if (bus_state->resume_done[port_index] != 0) { 915 xhci_dbg(xhci, "suspend failed because "
891 spin_unlock_irqrestore(&xhci->lock, flags); 916 "a port is resuming\n");
892 xhci_dbg(xhci, "suspend failed because " 917 return -EBUSY;
893 "port %d is resuming\n",
894 port_index + 1);
895 return -EBUSY;
896 }
897 } 918 }
898 } 919 }
899 920
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 68eaa908ac8..ec4338eec82 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1791,6 +1791,14 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1791{ 1791{
1792 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller); 1792 struct pci_dev *pdev = to_pci_dev(xhci_to_hcd(xhci)->self.controller);
1793 struct dev_info *dev_info, *next; 1793 struct dev_info *dev_info, *next;
1794 struct list_head *tt_list_head;
1795 struct list_head *tt;
1796 struct list_head *endpoints;
1797 struct list_head *ep, *q;
1798 struct xhci_tt_bw_info *tt_info;
1799 struct xhci_interval_bw_table *bwt;
1800 struct xhci_virt_ep *virt_ep;
1801
1794 unsigned long flags; 1802 unsigned long flags;
1795 int size; 1803 int size;
1796 int i; 1804 int i;
@@ -1807,6 +1815,9 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1807 xhci->event_ring = NULL; 1815 xhci->event_ring = NULL;
1808 xhci_dbg(xhci, "Freed event ring\n"); 1816 xhci_dbg(xhci, "Freed event ring\n");
1809 1817
1818 if (xhci->lpm_command)
1819 xhci_free_command(xhci, xhci->lpm_command);
1820 xhci->cmd_ring_reserved_trbs = 0;
1810 if (xhci->cmd_ring) 1821 if (xhci->cmd_ring)
1811 xhci_ring_free(xhci, xhci->cmd_ring); 1822 xhci_ring_free(xhci, xhci->cmd_ring);
1812 xhci->cmd_ring = NULL; 1823 xhci->cmd_ring = NULL;
@@ -1849,8 +1860,26 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
1849 } 1860 }
1850 spin_unlock_irqrestore(&xhci->lock, flags); 1861 spin_unlock_irqrestore(&xhci->lock, flags);
1851 1862
1863 bwt = &xhci->rh_bw->bw_table;
1864 for (i = 0; i < XHCI_MAX_INTERVAL; i++) {
1865 endpoints = &bwt->interval_bw[i].endpoints;
1866 list_for_each_safe(ep, q, endpoints) {
1867 virt_ep = list_entry(ep, struct xhci_virt_ep, bw_endpoint_list);
1868 list_del(&virt_ep->bw_endpoint_list);
1869 kfree(virt_ep);
1870 }
1871 }
1872
1873 tt_list_head = &xhci->rh_bw->tts;
1874 list_for_each_safe(tt, q, tt_list_head) {
1875 tt_info = list_entry(tt, struct xhci_tt_bw_info, tt_list);
1876 list_del(tt);
1877 kfree(tt_info);
1878 }
1879
1852 xhci->num_usb2_ports = 0; 1880 xhci->num_usb2_ports = 0;
1853 xhci->num_usb3_ports = 0; 1881 xhci->num_usb3_ports = 0;
1882 xhci->num_active_eps = 0;
1854 kfree(xhci->usb2_ports); 1883 kfree(xhci->usb2_ports);
1855 kfree(xhci->usb3_ports); 1884 kfree(xhci->usb3_ports);
1856 kfree(xhci->port_array); 1885 kfree(xhci->port_array);
@@ -2350,6 +2379,16 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
2350 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring); 2379 xhci_write_64(xhci, val_64, &xhci->op_regs->cmd_ring);
2351 xhci_dbg_cmd_ptrs(xhci); 2380 xhci_dbg_cmd_ptrs(xhci);
2352 2381
2382 xhci->lpm_command = xhci_alloc_command(xhci, true, true, flags);
2383 if (!xhci->lpm_command)
2384 goto fail;
2385
2386 /* Reserve one command ring TRB for disabling LPM.
2387 * Since the USB core grabs the shared usb_bus bandwidth mutex before
2388 * disabling LPM, we only need to reserve one TRB for all devices.
2389 */
2390 xhci->cmd_ring_reserved_trbs++;
2391
2353 val = xhci_readl(xhci, &xhci->cap_regs->db_off); 2392 val = xhci_readl(xhci, &xhci->cap_regs->db_off);
2354 val &= DBOFF_MASK; 2393 val &= DBOFF_MASK;
2355 xhci_dbg(xhci, "// Doorbell array is located at offset 0x%x" 2394 xhci_dbg(xhci, "// Doorbell array is located at offset 0x%x"
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 7a856a767e7..18b231b0c5d 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -72,6 +72,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
72 xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u " 72 xhci_dbg(xhci, "QUIRK: Fresco Logic revision %u "
73 "has broken MSI implementation\n", 73 "has broken MSI implementation\n",
74 pdev->revision); 74 pdev->revision);
75 xhci->quirks |= XHCI_TRUST_TX_LENGTH;
75 } 76 }
76 77
77 if (pdev->vendor == PCI_VENDOR_ID_NEC) 78 if (pdev->vendor == PCI_VENDOR_ID_NEC)
@@ -83,6 +84,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
83 /* AMD PLL quirk */ 84 /* AMD PLL quirk */
84 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) 85 if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
85 xhci->quirks |= XHCI_AMD_PLL_FIX; 86 xhci->quirks |= XHCI_AMD_PLL_FIX;
87 if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
88 xhci->quirks |= XHCI_LPM_SUPPORT;
89 xhci->quirks |= XHCI_INTEL_HOST;
90 }
86 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 91 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
87 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) { 92 pdev->device == PCI_DEVICE_ID_INTEL_PANTHERPOINT_XHCI) {
88 xhci->quirks |= XHCI_SPURIOUS_SUCCESS; 93 xhci->quirks |= XHCI_SPURIOUS_SUCCESS;
@@ -169,6 +174,13 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
169 if (retval) 174 if (retval)
170 goto put_usb3_hcd; 175 goto put_usb3_hcd;
171 /* Roothub already marked as USB 3.0 speed */ 176 /* Roothub already marked as USB 3.0 speed */
177
178 /* We know the LPM timeout algorithms for this host, let the USB core
179 * enable and disable LPM for devices under the USB 3.0 roothub.
180 */
181 if (xhci->quirks & XHCI_LPM_SUPPORT)
182 hcd_to_bus(xhci->shared_hcd)->root_hub->lpm_capable = 1;
183
172 return 0; 184 return 0;
173 185
174put_usb3_hcd: 186put_usb3_hcd:
@@ -292,6 +304,8 @@ static const struct hc_driver xhci_pci_hc_driver = {
292 */ 304 */
293 .update_device = xhci_update_device, 305 .update_device = xhci_update_device,
294 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm, 306 .set_usb2_hw_lpm = xhci_set_usb2_hardware_lpm,
307 .enable_usb3_lpm_timeout = xhci_enable_usb3_lpm_timeout,
308 .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout,
295}; 309};
296 310
297/*-------------------------------------------------------------------------*/ 311/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 3d9422f16a2..23b4aefd103 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1377,6 +1377,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
1377 xhci_dbg(xhci, "resume HS port %d\n", port_id); 1377 xhci_dbg(xhci, "resume HS port %d\n", port_id);
1378 bus_state->resume_done[faked_port_index] = jiffies + 1378 bus_state->resume_done[faked_port_index] = jiffies +
1379 msecs_to_jiffies(20); 1379 msecs_to_jiffies(20);
1380 set_bit(faked_port_index, &bus_state->resuming_ports);
1380 mod_timer(&hcd->rh_timer, 1381 mod_timer(&hcd->rh_timer,
1381 bus_state->resume_done[faked_port_index]); 1382 bus_state->resume_done[faked_port_index]);
1382 /* Do the rest in GetPortStatus */ 1383 /* Do the rest in GetPortStatus */
@@ -1786,8 +1787,12 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1786 /* handle completion code */ 1787 /* handle completion code */
1787 switch (trb_comp_code) { 1788 switch (trb_comp_code) {
1788 case COMP_SUCCESS: 1789 case COMP_SUCCESS:
1789 frame->status = 0; 1790 if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0) {
1790 break; 1791 frame->status = 0;
1792 break;
1793 }
1794 if ((xhci->quirks & XHCI_TRUST_TX_LENGTH))
1795 trb_comp_code = COMP_SHORT_TX;
1791 case COMP_SHORT_TX: 1796 case COMP_SHORT_TX:
1792 frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ? 1797 frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ?
1793 -EREMOTEIO : 0; 1798 -EREMOTEIO : 0;
@@ -1803,6 +1808,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td,
1803 break; 1808 break;
1804 case COMP_DEV_ERR: 1809 case COMP_DEV_ERR:
1805 case COMP_STALL: 1810 case COMP_STALL:
1811 case COMP_TX_ERR:
1806 frame->status = -EPROTO; 1812 frame->status = -EPROTO;
1807 skip_td = true; 1813 skip_td = true;
1808 break; 1814 break;
@@ -1883,13 +1889,16 @@ static int process_bulk_intr_td(struct xhci_hcd *xhci, struct xhci_td *td,
1883 switch (trb_comp_code) { 1889 switch (trb_comp_code) {
1884 case COMP_SUCCESS: 1890 case COMP_SUCCESS:
1885 /* Double check that the HW transferred everything. */ 1891 /* Double check that the HW transferred everything. */
1886 if (event_trb != td->last_trb) { 1892 if (event_trb != td->last_trb ||
1893 TRB_LEN(le32_to_cpu(event->transfer_len)) != 0) {
1887 xhci_warn(xhci, "WARN Successful completion " 1894 xhci_warn(xhci, "WARN Successful completion "
1888 "on short TX\n"); 1895 "on short TX\n");
1889 if (td->urb->transfer_flags & URB_SHORT_NOT_OK) 1896 if (td->urb->transfer_flags & URB_SHORT_NOT_OK)
1890 *status = -EREMOTEIO; 1897 *status = -EREMOTEIO;
1891 else 1898 else
1892 *status = 0; 1899 *status = 0;
1900 if ((xhci->quirks & XHCI_TRUST_TX_LENGTH))
1901 trb_comp_code = COMP_SHORT_TX;
1893 } else { 1902 } else {
1894 *status = 0; 1903 *status = 0;
1895 } 1904 }
@@ -2048,6 +2057,13 @@ static int handle_tx_event(struct xhci_hcd *xhci,
2048 * transfer type 2057 * transfer type
2049 */ 2058 */
2050 case COMP_SUCCESS: 2059 case COMP_SUCCESS:
2060 if (TRB_LEN(le32_to_cpu(event->transfer_len)) == 0)
2061 break;
2062 if (xhci->quirks & XHCI_TRUST_TX_LENGTH)
2063 trb_comp_code = COMP_SHORT_TX;
2064 else
2065 xhci_warn(xhci, "WARN Successful completion on short TX: "
2066 "needs XHCI_TRUST_TX_LENGTH quirk?\n");
2051 case COMP_SHORT_TX: 2067 case COMP_SHORT_TX:
2052 break; 2068 break;
2053 case COMP_STOP: 2069 case COMP_STOP:
@@ -2270,7 +2286,7 @@ cleanup:
2270 (status != 0 && 2286 (status != 0 &&
2271 !usb_endpoint_xfer_isoc(&urb->ep->desc))) 2287 !usb_endpoint_xfer_isoc(&urb->ep->desc)))
2272 xhci_dbg(xhci, "Giveback URB %p, len = %d, " 2288 xhci_dbg(xhci, "Giveback URB %p, len = %d, "
2273 "expected = %x, status = %d\n", 2289 "expected = %d, status = %d\n",
2274 urb, urb->actual_length, 2290 urb, urb->actual_length,
2275 urb->transfer_buffer_length, 2291 urb->transfer_buffer_length,
2276 status); 2292 status);
@@ -3593,12 +3609,12 @@ int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
3593 3609
3594/* Queue an evaluate context command TRB */ 3610/* Queue an evaluate context command TRB */
3595int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 3611int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
3596 u32 slot_id) 3612 u32 slot_id, bool command_must_succeed)
3597{ 3613{
3598 return queue_command(xhci, lower_32_bits(in_ctx_ptr), 3614 return queue_command(xhci, lower_32_bits(in_ctx_ptr),
3599 upper_32_bits(in_ctx_ptr), 0, 3615 upper_32_bits(in_ctx_ptr), 0,
3600 TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id), 3616 TRB_TYPE(TRB_EVAL_CONTEXT) | SLOT_ID_FOR_TRB(slot_id),
3601 false); 3617 command_must_succeed);
3602} 3618}
3603 3619
3604/* 3620/*
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 36641a7f237..afdc73ee84a 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -152,7 +152,7 @@ int xhci_reset(struct xhci_hcd *xhci)
152{ 152{
153 u32 command; 153 u32 command;
154 u32 state; 154 u32 state;
155 int ret; 155 int ret, i;
156 156
157 state = xhci_readl(xhci, &xhci->op_regs->status); 157 state = xhci_readl(xhci, &xhci->op_regs->status);
158 if ((state & STS_HALT) == 0) { 158 if ((state & STS_HALT) == 0) {
@@ -175,7 +175,15 @@ int xhci_reset(struct xhci_hcd *xhci)
175 * xHCI cannot write to any doorbells or operational registers other 175 * xHCI cannot write to any doorbells or operational registers other
176 * than status until the "Controller Not Ready" flag is cleared. 176 * than status until the "Controller Not Ready" flag is cleared.
177 */ 177 */
178 return handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000); 178 ret = handshake(xhci, &xhci->op_regs->status, STS_CNR, 0, 250 * 1000);
179
180 for (i = 0; i < 2; ++i) {
181 xhci->bus_state[i].port_c_suspend = 0;
182 xhci->bus_state[i].suspended_ports = 0;
183 xhci->bus_state[i].resuming_ports = 0;
184 }
185
186 return ret;
179} 187}
180 188
181#ifdef CONFIG_PCI 189#ifdef CONFIG_PCI
@@ -2438,7 +2446,7 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci,
2438 udev->slot_id, must_succeed); 2446 udev->slot_id, must_succeed);
2439 else 2447 else
2440 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma, 2448 ret = xhci_queue_evaluate_context(xhci, in_ctx->dma,
2441 udev->slot_id); 2449 udev->slot_id, must_succeed);
2442 if (ret < 0) { 2450 if (ret < 0) {
2443 if (command) 2451 if (command)
2444 list_del(&command->cmd_list); 2452 list_del(&command->cmd_list);
@@ -3863,6 +3871,474 @@ int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev)
3863 3871
3864#endif /* CONFIG_USB_SUSPEND */ 3872#endif /* CONFIG_USB_SUSPEND */
3865 3873
3874/*---------------------- USB 3.0 Link PM functions ------------------------*/
3875
3876#ifdef CONFIG_PM
3877/* Service interval in nanoseconds = 2^(bInterval - 1) * 125us * 1000ns / 1us */
3878static unsigned long long xhci_service_interval_to_ns(
3879 struct usb_endpoint_descriptor *desc)
3880{
3881 return (1 << (desc->bInterval - 1)) * 125 * 1000;
3882}
3883
3884static u16 xhci_get_timeout_no_hub_lpm(struct usb_device *udev,
3885 enum usb3_link_state state)
3886{
3887 unsigned long long sel;
3888 unsigned long long pel;
3889 unsigned int max_sel_pel;
3890 char *state_name;
3891
3892 switch (state) {
3893 case USB3_LPM_U1:
3894 /* Convert SEL and PEL stored in nanoseconds to microseconds */
3895 sel = DIV_ROUND_UP(udev->u1_params.sel, 1000);
3896 pel = DIV_ROUND_UP(udev->u1_params.pel, 1000);
3897 max_sel_pel = USB3_LPM_MAX_U1_SEL_PEL;
3898 state_name = "U1";
3899 break;
3900 case USB3_LPM_U2:
3901 sel = DIV_ROUND_UP(udev->u2_params.sel, 1000);
3902 pel = DIV_ROUND_UP(udev->u2_params.pel, 1000);
3903 max_sel_pel = USB3_LPM_MAX_U2_SEL_PEL;
3904 state_name = "U2";
3905 break;
3906 default:
3907 dev_warn(&udev->dev, "%s: Can't get timeout for non-U1 or U2 state.\n",
3908 __func__);
3909 return -EINVAL;
3910 }
3911
3912 if (sel <= max_sel_pel && pel <= max_sel_pel)
3913 return USB3_LPM_DEVICE_INITIATED;
3914
3915 if (sel > max_sel_pel)
3916 dev_dbg(&udev->dev, "Device-initiated %s disabled "
3917 "due to long SEL %llu ms\n",
3918 state_name, sel);
3919 else
3920 dev_dbg(&udev->dev, "Device-initiated %s disabled "
3921 "due to long PEL %llu\n ms",
3922 state_name, pel);
3923 return USB3_LPM_DISABLED;
3924}
3925
3926/* Returns the hub-encoded U1 timeout value.
3927 * The U1 timeout should be the maximum of the following values:
3928 * - For control endpoints, U1 system exit latency (SEL) * 3
3929 * - For bulk endpoints, U1 SEL * 5
3930 * - For interrupt endpoints:
3931 * - Notification EPs, U1 SEL * 3
3932 * - Periodic EPs, max(105% of bInterval, U1 SEL * 2)
3933 * - For isochronous endpoints, max(105% of bInterval, U1 SEL * 2)
3934 */
3935static u16 xhci_calculate_intel_u1_timeout(struct usb_device *udev,
3936 struct usb_endpoint_descriptor *desc)
3937{
3938 unsigned long long timeout_ns;
3939 int ep_type;
3940 int intr_type;
3941
3942 ep_type = usb_endpoint_type(desc);
3943 switch (ep_type) {
3944 case USB_ENDPOINT_XFER_CONTROL:
3945 timeout_ns = udev->u1_params.sel * 3;
3946 break;
3947 case USB_ENDPOINT_XFER_BULK:
3948 timeout_ns = udev->u1_params.sel * 5;
3949 break;
3950 case USB_ENDPOINT_XFER_INT:
3951 intr_type = usb_endpoint_interrupt_type(desc);
3952 if (intr_type == USB_ENDPOINT_INTR_NOTIFICATION) {
3953 timeout_ns = udev->u1_params.sel * 3;
3954 break;
3955 }
3956 /* Otherwise the calculation is the same as isoc eps */
3957 case USB_ENDPOINT_XFER_ISOC:
3958 timeout_ns = xhci_service_interval_to_ns(desc);
3959 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns * 105, 100);
3960 if (timeout_ns < udev->u1_params.sel * 2)
3961 timeout_ns = udev->u1_params.sel * 2;
3962 break;
3963 default:
3964 return 0;
3965 }
3966
3967 /* The U1 timeout is encoded in 1us intervals. */
3968 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 1000);
3969 /* Don't return a timeout of zero, because that's USB3_LPM_DISABLED. */
3970 if (timeout_ns == USB3_LPM_DISABLED)
3971 timeout_ns++;
3972
3973 /* If the necessary timeout value is bigger than what we can set in the
3974 * USB 3.0 hub, we have to disable hub-initiated U1.
3975 */
3976 if (timeout_ns <= USB3_LPM_U1_MAX_TIMEOUT)
3977 return timeout_ns;
3978 dev_dbg(&udev->dev, "Hub-initiated U1 disabled "
3979 "due to long timeout %llu ms\n", timeout_ns);
3980 return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U1);
3981}
3982
3983/* Returns the hub-encoded U2 timeout value.
3984 * The U2 timeout should be the maximum of:
3985 * - 10 ms (to avoid the bandwidth impact on the scheduler)
3986 * - largest bInterval of any active periodic endpoint (to avoid going
3987 * into lower power link states between intervals).
3988 * - the U2 Exit Latency of the device
3989 */
3990static u16 xhci_calculate_intel_u2_timeout(struct usb_device *udev,
3991 struct usb_endpoint_descriptor *desc)
3992{
3993 unsigned long long timeout_ns;
3994 unsigned long long u2_del_ns;
3995
3996 timeout_ns = 10 * 1000 * 1000;
3997
3998 if ((usb_endpoint_xfer_int(desc) || usb_endpoint_xfer_isoc(desc)) &&
3999 (xhci_service_interval_to_ns(desc) > timeout_ns))
4000 timeout_ns = xhci_service_interval_to_ns(desc);
4001
4002 u2_del_ns = udev->bos->ss_cap->bU2DevExitLat * 1000;
4003 if (u2_del_ns > timeout_ns)
4004 timeout_ns = u2_del_ns;
4005
4006 /* The U2 timeout is encoded in 256us intervals */
4007 timeout_ns = DIV_ROUND_UP_ULL(timeout_ns, 256 * 1000);
4008 /* If the necessary timeout value is bigger than what we can set in the
4009 * USB 3.0 hub, we have to disable hub-initiated U2.
4010 */
4011 if (timeout_ns <= USB3_LPM_U2_MAX_TIMEOUT)
4012 return timeout_ns;
4013 dev_dbg(&udev->dev, "Hub-initiated U2 disabled "
4014 "due to long timeout %llu ms\n", timeout_ns);
4015 return xhci_get_timeout_no_hub_lpm(udev, USB3_LPM_U2);
4016}
4017
4018static u16 xhci_call_host_update_timeout_for_endpoint(struct xhci_hcd *xhci,
4019 struct usb_device *udev,
4020 struct usb_endpoint_descriptor *desc,
4021 enum usb3_link_state state,
4022 u16 *timeout)
4023{
4024 if (state == USB3_LPM_U1) {
4025 if (xhci->quirks & XHCI_INTEL_HOST)
4026 return xhci_calculate_intel_u1_timeout(udev, desc);
4027 } else {
4028 if (xhci->quirks & XHCI_INTEL_HOST)
4029 return xhci_calculate_intel_u2_timeout(udev, desc);
4030 }
4031
4032 return USB3_LPM_DISABLED;
4033}
4034
4035static int xhci_update_timeout_for_endpoint(struct xhci_hcd *xhci,
4036 struct usb_device *udev,
4037 struct usb_endpoint_descriptor *desc,
4038 enum usb3_link_state state,
4039 u16 *timeout)
4040{
4041 u16 alt_timeout;
4042
4043 alt_timeout = xhci_call_host_update_timeout_for_endpoint(xhci, udev,
4044 desc, state, timeout);
4045
4046 /* If we found we can't enable hub-initiated LPM, or
4047 * the U1 or U2 exit latency was too high to allow
4048 * device-initiated LPM as well, just stop searching.
4049 */
4050 if (alt_timeout == USB3_LPM_DISABLED ||
4051 alt_timeout == USB3_LPM_DEVICE_INITIATED) {
4052 *timeout = alt_timeout;
4053 return -E2BIG;
4054 }
4055 if (alt_timeout > *timeout)
4056 *timeout = alt_timeout;
4057 return 0;
4058}
4059
4060static int xhci_update_timeout_for_interface(struct xhci_hcd *xhci,
4061 struct usb_device *udev,
4062 struct usb_host_interface *alt,
4063 enum usb3_link_state state,
4064 u16 *timeout)
4065{
4066 int j;
4067
4068 for (j = 0; j < alt->desc.bNumEndpoints; j++) {
4069 if (xhci_update_timeout_for_endpoint(xhci, udev,
4070 &alt->endpoint[j].desc, state, timeout))
4071 return -E2BIG;
4072 continue;
4073 }
4074 return 0;
4075}
4076
4077static int xhci_check_intel_tier_policy(struct usb_device *udev,
4078 enum usb3_link_state state)
4079{
4080 struct usb_device *parent;
4081 unsigned int num_hubs;
4082
4083 if (state == USB3_LPM_U2)
4084 return 0;
4085
4086 /* Don't enable U1 if the device is on a 2nd tier hub or lower. */
4087 for (parent = udev->parent, num_hubs = 0; parent->parent;
4088 parent = parent->parent)
4089 num_hubs++;
4090
4091 if (num_hubs < 2)
4092 return 0;
4093
4094 dev_dbg(&udev->dev, "Disabling U1 link state for device"
4095 " below second-tier hub.\n");
4096 dev_dbg(&udev->dev, "Plug device into first-tier hub "
4097 "to decrease power consumption.\n");
4098 return -E2BIG;
4099}
4100
4101static int xhci_check_tier_policy(struct xhci_hcd *xhci,
4102 struct usb_device *udev,
4103 enum usb3_link_state state)
4104{
4105 if (xhci->quirks & XHCI_INTEL_HOST)
4106 return xhci_check_intel_tier_policy(udev, state);
4107 return -EINVAL;
4108}
4109
4110/* Returns the U1 or U2 timeout that should be enabled.
4111 * If the tier check or timeout setting functions return with a non-zero exit
4112 * code, that means the timeout value has been finalized and we shouldn't look
4113 * at any more endpoints.
4114 */
4115static u16 xhci_calculate_lpm_timeout(struct usb_hcd *hcd,
4116 struct usb_device *udev, enum usb3_link_state state)
4117{
4118 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
4119 struct usb_host_config *config;
4120 char *state_name;
4121 int i;
4122 u16 timeout = USB3_LPM_DISABLED;
4123
4124 if (state == USB3_LPM_U1)
4125 state_name = "U1";
4126 else if (state == USB3_LPM_U2)
4127 state_name = "U2";
4128 else {
4129 dev_warn(&udev->dev, "Can't enable unknown link state %i\n",
4130 state);
4131 return timeout;
4132 }
4133
4134 if (xhci_check_tier_policy(xhci, udev, state) < 0)
4135 return timeout;
4136
4137 /* Gather some information about the currently installed configuration
4138 * and alternate interface settings.
4139 */
4140 if (xhci_update_timeout_for_endpoint(xhci, udev, &udev->ep0.desc,
4141 state, &timeout))
4142 return timeout;
4143
4144 config = udev->actconfig;
4145 if (!config)
4146 return timeout;
4147
4148 for (i = 0; i < USB_MAXINTERFACES; i++) {
4149 struct usb_driver *driver;
4150 struct usb_interface *intf = config->interface[i];
4151
4152 if (!intf)
4153 continue;
4154
4155 /* Check if any currently bound drivers want hub-initiated LPM
4156 * disabled.
4157 */
4158 if (intf->dev.driver) {
4159 driver = to_usb_driver(intf->dev.driver);
4160 if (driver && driver->disable_hub_initiated_lpm) {
4161 dev_dbg(&udev->dev, "Hub-initiated %s disabled "
4162 "at request of driver %s\n",
4163 state_name, driver->name);
4164 return xhci_get_timeout_no_hub_lpm(udev, state);
4165 }
4166 }
4167
4168 /* Not sure how this could happen... */
4169 if (!intf->cur_altsetting)
4170 continue;
4171
4172 if (xhci_update_timeout_for_interface(xhci, udev,
4173 intf->cur_altsetting,
4174 state, &timeout))
4175 return timeout;
4176 }
4177 return timeout;
4178}
4179
4180/*
4181 * Issue an Evaluate Context command to change the Maximum Exit Latency in the
4182 * slot context. If that succeeds, store the new MEL in the xhci_virt_device.
4183 */
4184static int xhci_change_max_exit_latency(struct xhci_hcd *xhci,
4185 struct usb_device *udev, u16 max_exit_latency)
4186{
4187 struct xhci_virt_device *virt_dev;
4188 struct xhci_command *command;
4189 struct xhci_input_control_ctx *ctrl_ctx;
4190 struct xhci_slot_ctx *slot_ctx;
4191 unsigned long flags;
4192 int ret;
4193
4194 spin_lock_irqsave(&xhci->lock, flags);
4195 if (max_exit_latency == xhci->devs[udev->slot_id]->current_mel) {
4196 spin_unlock_irqrestore(&xhci->lock, flags);
4197 return 0;
4198 }
4199
4200 /* Attempt to issue an Evaluate Context command to change the MEL. */
4201 virt_dev = xhci->devs[udev->slot_id];
4202 command = xhci->lpm_command;
4203 xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx);
4204 spin_unlock_irqrestore(&xhci->lock, flags);
4205
4206 ctrl_ctx = xhci_get_input_control_ctx(xhci, command->in_ctx);
4207 ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
4208 slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx);
4209 slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT));
4210 slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency);
4211
4212 xhci_dbg(xhci, "Set up evaluate context for LPM MEL change.\n");
4213 xhci_dbg(xhci, "Slot %u Input Context:\n", udev->slot_id);
4214 xhci_dbg_ctx(xhci, command->in_ctx, 0);
4215
4216 /* Issue and wait for the evaluate context command. */
4217 ret = xhci_configure_endpoint(xhci, udev, command,
4218 true, true);
4219 xhci_dbg(xhci, "Slot %u Output Context:\n", udev->slot_id);
4220 xhci_dbg_ctx(xhci, virt_dev->out_ctx, 0);
4221
4222 if (!ret) {
4223 spin_lock_irqsave(&xhci->lock, flags);
4224 virt_dev->current_mel = max_exit_latency;
4225 spin_unlock_irqrestore(&xhci->lock, flags);
4226 }
4227 return ret;
4228}
4229
4230static int calculate_max_exit_latency(struct usb_device *udev,
4231 enum usb3_link_state state_changed,
4232 u16 hub_encoded_timeout)
4233{
4234 unsigned long long u1_mel_us = 0;
4235 unsigned long long u2_mel_us = 0;
4236 unsigned long long mel_us = 0;
4237 bool disabling_u1;
4238 bool disabling_u2;
4239 bool enabling_u1;
4240 bool enabling_u2;
4241
4242 disabling_u1 = (state_changed == USB3_LPM_U1 &&
4243 hub_encoded_timeout == USB3_LPM_DISABLED);
4244 disabling_u2 = (state_changed == USB3_LPM_U2 &&
4245 hub_encoded_timeout == USB3_LPM_DISABLED);
4246
4247 enabling_u1 = (state_changed == USB3_LPM_U1 &&
4248 hub_encoded_timeout != USB3_LPM_DISABLED);
4249 enabling_u2 = (state_changed == USB3_LPM_U2 &&
4250 hub_encoded_timeout != USB3_LPM_DISABLED);
4251
4252 /* If U1 was already enabled and we're not disabling it,
4253 * or we're going to enable U1, account for the U1 max exit latency.
4254 */
4255 if ((udev->u1_params.timeout != USB3_LPM_DISABLED && !disabling_u1) ||
4256 enabling_u1)
4257 u1_mel_us = DIV_ROUND_UP(udev->u1_params.mel, 1000);
4258 if ((udev->u2_params.timeout != USB3_LPM_DISABLED && !disabling_u2) ||
4259 enabling_u2)
4260 u2_mel_us = DIV_ROUND_UP(udev->u2_params.mel, 1000);
4261
4262 if (u1_mel_us > u2_mel_us)
4263 mel_us = u1_mel_us;
4264 else
4265 mel_us = u2_mel_us;
4266 /* xHCI host controller max exit latency field is only 16 bits wide. */
4267 if (mel_us > MAX_EXIT) {
4268 dev_warn(&udev->dev, "Link PM max exit latency of %lluus "
4269 "is too big.\n", mel_us);
4270 return -E2BIG;
4271 }
4272 return mel_us;
4273}
4274
4275/* Returns the USB3 hub-encoded value for the U1/U2 timeout. */
4276int xhci_enable_usb3_lpm_timeout(struct usb_hcd *hcd,
4277 struct usb_device *udev, enum usb3_link_state state)
4278{
4279 struct xhci_hcd *xhci;
4280 u16 hub_encoded_timeout;
4281 int mel;
4282 int ret;
4283
4284 xhci = hcd_to_xhci(hcd);
4285 /* The LPM timeout values are pretty host-controller specific, so don't
4286 * enable hub-initiated timeouts unless the vendor has provided
4287 * information about their timeout algorithm.
4288 */
4289 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) ||
4290 !xhci->devs[udev->slot_id])
4291 return USB3_LPM_DISABLED;
4292
4293 hub_encoded_timeout = xhci_calculate_lpm_timeout(hcd, udev, state);
4294 mel = calculate_max_exit_latency(udev, state, hub_encoded_timeout);
4295 if (mel < 0) {
4296 /* Max Exit Latency is too big, disable LPM. */
4297 hub_encoded_timeout = USB3_LPM_DISABLED;
4298 mel = 0;
4299 }
4300
4301 ret = xhci_change_max_exit_latency(xhci, udev, mel);
4302 if (ret)
4303 return ret;
4304 return hub_encoded_timeout;
4305}
4306
4307int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
4308 struct usb_device *udev, enum usb3_link_state state)
4309{
4310 struct xhci_hcd *xhci;
4311 u16 mel;
4312 int ret;
4313
4314 xhci = hcd_to_xhci(hcd);
4315 if (!xhci || !(xhci->quirks & XHCI_LPM_SUPPORT) ||
4316 !xhci->devs[udev->slot_id])
4317 return 0;
4318
4319 mel = calculate_max_exit_latency(udev, state, USB3_LPM_DISABLED);
4320 ret = xhci_change_max_exit_latency(xhci, udev, mel);
4321 if (ret)
4322 return ret;
4323 return 0;
4324}
4325#else /* CONFIG_PM */
4326
4327int xhci_enable_usb3_lpm_timeout(struct usb_hcd *hcd,
4328 struct usb_device *udev, enum usb3_link_state state)
4329{
4330 return USB3_LPM_DISABLED;
4331}
4332
4333int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
4334 struct usb_device *udev, enum usb3_link_state state)
4335{
4336 return 0;
4337}
4338#endif /* CONFIG_PM */
4339
4340/*-------------------------------------------------------------------------*/
4341
3866/* Once a hub descriptor is fetched for a device, we need to update the xHC's 4342/* Once a hub descriptor is fetched for a device, we need to update the xHC's
3867 * internal data structures for the device. 4343 * internal data structures for the device.
3868 */ 4344 */
@@ -4090,7 +4566,6 @@ static int __init xhci_hcd_init(void)
4090 BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8*32/8); 4566 BUILD_BUG_ON(sizeof(struct xhci_intr_reg) != 8*32/8);
4091 /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */ 4567 /* xhci_run_regs has eight fields and embeds 128 xhci_intr_regs */
4092 BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8); 4568 BUILD_BUG_ON(sizeof(struct xhci_run_regs) != (8+8*128)*32/8);
4093 BUILD_BUG_ON(sizeof(struct xhci_doorbell_array) != 256*32/8);
4094 return 0; 4569 return 0;
4095unreg_pci: 4570unreg_pci:
4096 xhci_unregister_pci(); 4571 xhci_unregister_pci();
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 3d69c4b2b54..de3d6e3e57b 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -362,8 +362,10 @@ struct xhci_op_regs {
362 * Timeout can be up to 127us. 0xFF means an infinite timeout. 362 * Timeout can be up to 127us. 0xFF means an infinite timeout.
363 */ 363 */
364#define PORT_U1_TIMEOUT(p) ((p) & 0xff) 364#define PORT_U1_TIMEOUT(p) ((p) & 0xff)
365#define PORT_U1_TIMEOUT_MASK 0xff
365/* Inactivity timer value for transitions into U2 */ 366/* Inactivity timer value for transitions into U2 */
366#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8) 367#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
368#define PORT_U2_TIMEOUT_MASK (0xff << 8)
367/* Bits 24:31 for port testing */ 369/* Bits 24:31 for port testing */
368 370
369/* USB2 Protocol PORTSPMSC */ 371/* USB2 Protocol PORTSPMSC */
@@ -914,6 +916,8 @@ struct xhci_virt_device {
914 u8 real_port; 916 u8 real_port;
915 struct xhci_interval_bw_table *bw_table; 917 struct xhci_interval_bw_table *bw_table;
916 struct xhci_tt_bw_info *tt_info; 918 struct xhci_tt_bw_info *tt_info;
919 /* The current max exit latency for the enabled USB3 link states. */
920 u16 current_mel;
917}; 921};
918 922
919/* 923/*
@@ -1362,6 +1366,8 @@ struct xhci_bus_state {
1362 u32 suspended_ports; 1366 u32 suspended_ports;
1363 u32 port_remote_wakeup; 1367 u32 port_remote_wakeup;
1364 unsigned long resume_done[USB_MAXCHILDREN]; 1368 unsigned long resume_done[USB_MAXCHILDREN];
1369 /* which ports have started to resume */
1370 unsigned long resuming_ports;
1365}; 1371};
1366 1372
1367static inline unsigned int hcd_index(struct usb_hcd *hcd) 1373static inline unsigned int hcd_index(struct usb_hcd *hcd)
@@ -1422,6 +1428,8 @@ struct xhci_hcd {
1422 /* slot enabling and address device helpers */ 1428 /* slot enabling and address device helpers */
1423 struct completion addr_dev; 1429 struct completion addr_dev;
1424 int slot_id; 1430 int slot_id;
1431 /* For USB 3.0 LPM enable/disable. */
1432 struct xhci_command *lpm_command;
1425 /* Internal mirror of the HW's dcbaa */ 1433 /* Internal mirror of the HW's dcbaa */
1426 struct xhci_virt_device *devs[MAX_HC_SLOTS]; 1434 struct xhci_virt_device *devs[MAX_HC_SLOTS];
1427 /* For keeping track of bandwidth domains per roothub. */ 1435 /* For keeping track of bandwidth domains per roothub. */
@@ -1479,6 +1487,9 @@ struct xhci_hcd {
1479#define XHCI_RESET_ON_RESUME (1 << 7) 1487#define XHCI_RESET_ON_RESUME (1 << 7)
1480#define XHCI_SW_BW_CHECKING (1 << 8) 1488#define XHCI_SW_BW_CHECKING (1 << 8)
1481#define XHCI_AMD_0x96_HOST (1 << 9) 1489#define XHCI_AMD_0x96_HOST (1 << 9)
1490#define XHCI_TRUST_TX_LENGTH (1 << 10)
1491#define XHCI_LPM_SUPPORT (1 << 11)
1492#define XHCI_INTEL_HOST (1 << 12)
1482 unsigned int num_active_eps; 1493 unsigned int num_active_eps;
1483 unsigned int limit_active_eps; 1494 unsigned int limit_active_eps;
1484 /* There are two roothubs to keep track of bus suspend info for */ 1495 /* There are two roothubs to keep track of bus suspend info for */
@@ -1752,7 +1763,7 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
1752int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1763int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1753 u32 slot_id, bool command_must_succeed); 1764 u32 slot_id, bool command_must_succeed);
1754int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr, 1765int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1755 u32 slot_id); 1766 u32 slot_id, bool command_must_succeed);
1756int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id, 1767int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1757 unsigned int ep_index); 1768 unsigned int ep_index);
1758int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id); 1769int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id);
@@ -1776,6 +1787,10 @@ void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1776/* xHCI roothub code */ 1787/* xHCI roothub code */
1777void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array, 1788void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1778 int port_id, u32 link_state); 1789 int port_id, u32 link_state);
1790int xhci_enable_usb3_lpm_timeout(struct usb_hcd *hcd,
1791 struct usb_device *udev, enum usb3_link_state state);
1792int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
1793 struct usb_device *udev, enum usb3_link_state state);
1779void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array, 1794void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1780 int port_id, u32 port_bit); 1795 int port_id, u32 port_bit);
1781int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, 1796int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,